[Bf-blender-cvs] [0c41d61008f] blender2.8: WM: snap to fractions when resizing areas
Campbell Barton
noreply at git.blender.org
Thu Jul 12 16:57:42 CEST 2018
Commit: 0c41d61008f1cfb58b160d8459d8ffdb652871d8
Author: Campbell Barton
Date: Thu Jul 12 16:55:16 2018 +0200
Branches: blender2.8
https://developer.blender.org/rB0c41d61008f1cfb58b160d8459d8ffdb652871d8
WM: snap to fractions when resizing areas
Snap to fractions in 1/(2,3,4,8),
Nice for less arbitrary layouts.
===================================================================
M source/blender/editors/screen/screen_ops.c
===================================================================
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 09bd7625eac..cd5bdf07c6c 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -1372,10 +1372,29 @@ static int area_snap_calc_location(
int snap_dist;
int dist;
{
- /* Test the snap to middle. */
- int middle = origval + (bigger - smaller) / 2;
- snap_dist = abs(m_loc - middle);
- final_loc = middle;
+ const float div_array[] = {
+ /* Middle. */
+ 1.0f / 2.0f,
+ /* Thirds. */
+ 1.0f / 3.0f, 2.0f / 3.0f,
+ /* Quaters. */
+ 1.0f / 4.0f, 3.0f / 4.0f,
+ /* Eighth. */
+ 1.0f / 8.0f, 3.0f / 8.0f,
+ 5.0f / 8.0f, 7.0f / 8.0f,
+ };
+ /* Test the snap to the best division. */
+ const int axis_min = origval - smaller;
+ const float axis_span_fl = (float)(bigger + smaller);
+ int snap_dist_best = INT_MAX;
+ for (int i = 0; i < ARRAY_SIZE(div_array); i++) {
+ const int value = axis_min + round_fl_to_int(axis_span_fl * div_array[i]);
+ snap_dist = abs(m_loc - value);
+ if (snap_dist < snap_dist_best) {
+ snap_dist_best = snap_dist;
+ final_loc = value;
+ }
+ }
}
for (const ScrVert *v1 = sc->vertbase.first; v1; v1 = v1->next) {
More information about the Bf-blender-cvs
mailing list