Commit: 53c539cca4a42accf6729135bdcd568ec3496f15
Author: Bastien Montagne
Date:   Tue Oct 20 12:56:26 2015 +0200
Branches: ui-align-rework
https://developer.blender.org/rB53c539cca4a42accf6729135bdcd568ec3496f15

Refactor of new 'align compute' code.

Much, much shorter now.

===================================================================

M       release/scripts/startup/bl_ui/properties_render.py
M       source/blender/editors/interface/interface.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_render.py 
b/release/scripts/startup/bl_ui/properties_render.py
index 1f1802a..1192fa8 100644
--- a/release/scripts/startup/bl_ui/properties_render.py
+++ b/release/scripts/startup/bl_ui/properties_render.py
@@ -131,16 +131,17 @@ class RENDER_PT_dimensions(RenderButtonsPanel, Panel):
         scene = context.scene
         rd = scene.render
 
-        row = layout.row(align=True)
+        col_a = layout.column(align=True)
+
+        row = col_a.row(align=True)
         row.menu("RENDER_MT_presets", 
text=bpy.types.RENDER_MT_presets.bl_label)
         row.operator("render.preset_add", text="", icon='ZOOMIN')
         row.operator("render.preset_add", text="", 
icon='ZOOMOUT').remove_active = True
 
-        split = layout.split()
+        split = col_a.split(align=True)
 
-        col = split.column()
+        col = split.column(align=True)
         sub = col.column(align=True)
-        sub.label(text="Resolution:")
         sub.prop(rd, "resolution_x", text="X")
         sub.prop(rd, "resolution_y", text="Y")
         sub.prop(rd, "resolution_percentage", text="")
@@ -149,17 +150,17 @@ class RENDER_PT_dimensions(RenderButtonsPanel, Panel):
         sub.prop(rd, "pixel_aspect_x", text="X")
         sub.prop(rd, "pixel_aspect_y", text="Y")
 
-        row = col.row()
+        row = col.row(align=True)
         row.prop(rd, "use_border", text="Border")
-        sub = row.row()
+        sub = row.row(align=True)
         sub.active = rd.use_border
         sub.prop(rd, "use_crop_to_border", text="Crop")
 
-        col = split.column()
+        col = split.column(align=True)
         sub = col.column(align=True)
-        sub.label(text="Frame Range:")
         sub.prop(scene, "frame_start")
-        sub.prop(scene, "frame_end")
+        #~ sub.prop(scene, "frame_end")
+        sub.label("")
         sub.prop(scene, "frame_step")
 
         sub.label(text="Frame Rate:")
@@ -172,6 +173,8 @@ class RENDER_PT_dimensions(RenderButtonsPanel, Panel):
         subrow.prop(rd, "frame_map_old", text="Old")
         subrow.prop(rd, "frame_map_new", text="New")
 
+        col_a.prop(scene, "frame_end")
+
 
 class RENDER_PT_antialiasing(RenderButtonsPanel, Panel):
     bl_label = "Anti-Aliasing"
diff --git a/source/blender/editors/interface/interface.c 
b/source/blender/editors/interface/interface.c
index f0e25a8..dfde112 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1251,7 +1251,8 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, 
const int xy[2])
                UI_block_layout_resolve(block, NULL, NULL);
        }
 
-       TIMEIT_BENCH(ui_block_align_calc(block), ui_block_align_calc);
+//     TIMEIT_BENCH(ui_block_align_calc(block), ui_block_align_calc);
+       ui_block_align_calc(block);
 
        if ((block->flag & UI_BLOCK_LOOP) && (block->flag & 
UI_BLOCK_NUMSELECT)) {
                ui_menu_block_set_keyaccels(block); /* could use a different 
flag to check */
@@ -2939,116 +2940,144 @@ void UI_block_align_end(uiBlock *block)
 #if 1
 typedef struct uiButAlign {
        uiBut *but;
-       struct uiButAlign *left, *top, *right, *down;
-       float dleft, dtop, dright, ddown;
-       int flag;
+
+       /* Neighbor buttons */
+       struct uiButAlign *neighbors[4];
+
+       /* Pointers to coordinates (rctf values) of the button. */
+       float *borders[4];
+
+       /* Distances to the neighbors. */
+       float dists[4];
+
+       /* Flags, used to mark whether we should 'stitch' the corners of this 
button with its neighbors' ones. */
+       char flags[4];
 } uiButAlign;
 
 enum {
-       ALIGN_STITCH_LEFT_DOWN  = 1 << 0,
-       ALIGN_STITCH_LEFT_TOP   = 1 << 1,
-       ALIGN_STITCH_TOP_LEFT   = 1 << 2,
-       ALIGN_STITCH_TOP_RIGHT  = 1 << 3,
-       ALIGN_STITCH_RIGHT_TOP  = 1 << 4,
-       ALIGN_STITCH_RIGHT_DOWN = 1 << 5,
-       ALIGN_STITCH_DOWN_RIGHT = 1 << 6,
-       ALIGN_STITCH_DOWN_LEFT  = 1 << 7,
+       LEFT         = 0,
+       TOP          = 1,
+       RIGHT        = 2,
+       DOWN         = 3,
+
+       STITCH_LEFT  = 1 << 4,
+       STITCH_TOP   = 1 << 5,
+       STITCH_RIGHT = 1 << 6,
+       STITCH_DOWN  = 1 << 7,
 };
 
+#define OPPOSITE(_s) (((_s) + 2) % 4)
+#define SIDE1(_s) (((_s) + 1) % 4)
+#define SIDE2(_s) (((_s) + 3) % 4)
+
+#define STITCH(_s) (1 << ((_s) + 4))
+
 bool ui_but_can_align(uiBut *but)
 {
        return !ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_CHECKBOX, 
UI_BTYPE_CHECKBOX_N, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE);
 }
 
-static bool buts_touching_vertical(uiBut *but1, uiBut *but2)
-{
-       return !((but1->rect.ymin >= but2->rect.ymax) || (but1->rect.ymax <= 
but2->rect.ymin));
-}
-
-static bool buts_touching_horizontal(uiBut *but1, uiBut *but2)
-{
-       return !((but1->rect.xmin >= but2->rect.xmax) || (but1->rect.xmax <= 
but2->rect.xmin));
+static int get_but_align_flag(const int i) {
+       switch (i) {
+               case LEFT:
+                       return UI_BUT_ALIGN_LEFT;
+               case TOP:
+                       return UI_BUT_ALIGN_TOP;
+               case RIGHT:
+                       return UI_BUT_ALIGN_RIGHT;
+               case DOWN:
+                       return UI_BUT_ALIGN_DOWN;
+               default:
+                       BLI_assert(0);
+                       return 0;
+       }
 }
 
 /* Only the shortest diff (if below acceptable limits) is set, other pointers 
are set to NULL. */
-static int buts_proximity(
-        uiBut *but1, uiBut *but2, float *r_dleft, float *r_dtop, float 
*r_dright, float *r_ddown, int *r_corners)
+static void buts_proximity_compute(uiButAlign *but1, uiButAlign *but2)
 {
-       const float max_delta_y = 0.5f * UI_UNIT_Y;
-       const float max_delta_x = 0.5f * UI_UNIT_X;
+       const float max_delta = 0.5f * max_ii(UI_UNIT_Y, UI_UNIT_X);
        float delta;
-       int ret = 0;
+       int i;
 
-       *r_corners = 0;
+       const bool buts_share[2] = {
+           /* Sharing same line? */
+           !((*but1->borders[DOWN] >= *but2->borders[TOP]) || 
(*but1->borders[TOP] <= *but2->borders[DOWN])),
+           /* Sharing same column? */
+           !((*but1->borders[LEFT] >= *but2->borders[RIGHT]) || 
(*but1->borders[RIGHT] <= *but2->borders[LEFT])),
+       };
 
-       if (buts_touching_vertical(but1, but2)) {
-               delta = fabsf(but1->rect.xmax - but2->rect.xmin);
-               if (delta < max_delta_x ) {
-                       *r_dright = delta;
-                       ret |= UI_BUT_ALIGN_RIGHT;
+       for (i = 0; i < 4; i++) {
+               const int i_share = i % 2;
 
-                       delta = fabsf(but1->rect.ymin - but2->rect.ymin);
-                       if (delta < max_delta_y) {
-                               *r_corners |= ALIGN_STITCH_RIGHT_DOWN;
-                       }
-                       delta = fabsf(but1->rect.ymax - but2->rect.ymax);
-                       if (delta < max_delta_y) {
-                               *r_corners |= ALIGN_STITCH_RIGHT_TOP;
-                       }
-               }
-               else {
-                       delta = fabsf(but1->rect.xmin - but2->rect.xmax);
-                       if (delta < max_delta_x) {
-                               *r_dleft = delta;
-                               ret |= UI_BUT_ALIGN_LEFT;
-
-                               delta = fabsf(but1->rect.ymin - 
but2->rect.ymin);
-                               if (delta < max_delta_y) {
-                                       *r_corners |= ALIGN_STITCH_LEFT_DOWN;
-                               }
-                               delta = fabsf(but1->rect.ymax - 
but2->rect.ymax);
-                               if (delta < max_delta_y) {
-                                       *r_corners |= ALIGN_STITCH_LEFT_TOP;
+               if (buts_share[i_share]) {
+                       const int i_opp = OPPOSITE(i);
+
+                       delta = fabsf(*but1->borders[i] - 
*but2->borders[i_opp]);
+                       if (delta < max_delta) {
+                               if (delta <= but1->dists[i]) {
+                                       if (delta < but1->dists[i]) {
+                                               but1->neighbors[i] = but2;
+                                               but2->neighbors[i_opp] = but1;
+                                               but1->dists[i] = 
but2->dists[i_opp] = delta;
+                                       }
+                                       {
+                                               const int i_s1 = SIDE1(i);
+                                               const int i_s2 = SIDE2(i);
+
+                                               const int stitch = STITCH(i);
+                                               const int stitch_opp = 
STITCH(i_opp);
+
+                                               delta = 
fabsf(*but1->borders[i_s1] - *but2->borders[i_s1]);
+                                               if (delta < max_delta) {
+                                                       but1->flags[i_s1] |= 
stitch;
+                                                       but2->flags[i_s1] |= 
stitch_opp;
+                                               }
+                                               delta = 
fabsf(*but1->borders[i_s2] - *but2->borders[i_s2]);
+                                               if (delta < max_delta) {
+                                                       but1->flags[i_s2] |= 
stitch;
+                                                       but2->flags[i_s2] |= 
stitch_opp;
+                                               }
+                                       }
                                }
+                               return;
                        }
                }
        }
-       else if (buts_touching_horizontal(but1, but2)) {
-               delta = fabsf(but1->rect.ymin - but2->rect.ymax);
-               if (delta < max_delta_y) {
-                       *r_ddown = delta;
-                       ret |= UI_BUT_ALIGN_DOWN;
+}
 
-                       delta = fabsf(but1->rect.xmin - but2->rect.xmin);
-                       if (delta < max_delta_x) {
-                               *r_corners |= ALIGN_STITCH_DOWN_LEFT;
-                       }
-                       delta = fabsf(but1->rect.xmax - but2->rect.xmax);
-                       if (delta < max_delta_x) {
-                               *r_corners |= ALIGN_STITCH_DOWN_RIGHT;
-                       }
+static void align_stitch_neighbors(
+        uiButAlign *butal,
+        const int i, const int i_opp, const int i_s1, const int i_s2,
+        const int align, const int align_opp, const float co)
+{
+       uiButAlign *butal_neighbor;
+
+       printf("%s\n", butal->but->str);
+       if (STREQ(butal->but->str, "Frame Step:")) {
+               printf("%s: main side %d, stride side %d: %f\n", 
butal->but->str, i, i_s1, butal->dists[i]);
+       }
+
+       while ((butal->flags[i] & STITCH(i_s1)) &&
+              (butal = butal->neighbors[i_s1]) &&
+              (butal->flags[i] & STITCH(i_s2)))
+       {
+               if (STREQ(butal->but->str, "Frame Step:")) {
+                       printf("%s: main side %d, stride side %d: %f\n", 
butal->but->str, i, i_s1, butal->dists[i]);
                }
-               else {
-                       delta = fabsf(but1->rect.ymax - but2->rect.ymin);
-                       if (delta < max_delta_y) {
-                               *r_dtop = delta;
-                               ret |= UI_BUT_ALIGN_TOP;
-
-                               delta = fabsf(but1->rect.xmin - 
but2->rect.xmin);
-                               if (delta < max_delta_x) {
-                                       *r_corners |= ALIGN_STITCH_TOP_LEFT;
-                               }
-                               delta = fabsf(but1->rect.xmax - 
but2->rect.xmax);
-                               if (delta < max_delta_x) {
-                                       *r_corners |= ALIGN_STITCH_TOP_RIGHT;
-                               }
+               if (butal->dists[i]) {
+                       butal_neighbor = butal->neighbors[i];
+
+                       if (butal_neighbor) {
+                               butal->but->drawflag |= align;
+                               butal_neighbor->but->drawflag |= align_opp;
+                               *butal_neighbor->borders[i_opp] = co;
+                               butal_neighbor->dists[i_opp] = 0.0f;
                        }
+                       *butal->borders[i] = co;
+                       butal->dists[i] = 0.0f;
                }
        }
-
-       BLI_assert(ELEM(ret, 0, UI_BUT_ALIGN_LEFT, UI_BUT_ALIGN_TOP, 
UI_BUT_ALIGN_RIGHT, UI_BUT_ALIGN_DOWN));
-
-       return ret;
 }
 
 void ui_block_align_calc(uiBlock *block)
@@ -3082,7 +3111,11 @@ void ui_block_align_calc(uiBlock *block)
                }
 
                but_align->but = but;
-               copy_v4_fl(&but_align->dleft, FLT_MAX);
+               but_align->borders[LEFT] = &but->rect.xmin;
+               but_align->borders[RIGHT] = &but->rect.xmax;
+               but_align->borders[DOWN] = &but->rect.ymin;
+               but_align->borders[TOP] = &but->rect.ymax;
+               copy_v4_fl(but_align->dists, FLT_MAX);
                but_align++;
        }
 
@@ -3090,88 +3123,11 @@ void ui_block_align_calc(uiBlock *block)
                const short alignnr = but_a

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to