Commit: 4ed8bd88d99da51e42577869a4618ee0b3374608
Author: Hans Goudey
Date:   Thu Aug 20 23:38:39 2020 -0400
Branches: master
https://developer.blender.org/rB4ed8bd88d99da51e42577869a4618ee0b3374608

UI: Cleanup in interface_panel.c

- Use const in some places where applicable
- Use consistent variable names in some places
- Use "r_" prefix for return arguments
- Declare variables in smaller scope where they are used

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

M       source/blender/editors/interface/interface_intern.h
M       source/blender/editors/interface/interface_panel.c

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

diff --git a/source/blender/editors/interface/interface_intern.h 
b/source/blender/editors/interface/interface_intern.h
index eb1bd1ba42e..87be3745f87 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -794,8 +794,8 @@ extern int ui_handler_panel_region(struct bContext *C,
                                    const struct wmEvent *event,
                                    struct ARegion *region,
                                    const uiBut *active_but);
-extern void ui_draw_aligned_panel(struct uiStyle *style,
-                                  uiBlock *block,
+extern void ui_draw_aligned_panel(const struct uiStyle *style,
+                                  const uiBlock *block,
                                   const rcti *rect,
                                   const bool show_pin,
                                   const bool show_background);
diff --git a/source/blender/editors/interface/interface_panel.c 
b/source/blender/editors/interface/interface_panel.c
index 4982a27316c..57a170d602c 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -134,7 +134,9 @@ static void panel_title_color_get(bool show_background, 
uchar color[4])
   }
 }
 
-static bool panel_active_animation_changed(ListBase *lb, Panel **pa_animation, 
bool *no_animation)
+static bool panel_active_animation_changed(ListBase *lb,
+                                           Panel **r_panel_animation,
+                                           bool *r_no_animation)
 {
   LISTBASE_FOREACH (Panel *, panel, lb) {
     /* Detect panel active flag changes. */
@@ -148,7 +150,7 @@ static bool panel_active_animation_changed(ListBase *lb, 
Panel **pa_animation, b
     }
 
     if ((panel->runtime_flag & PNL_ACTIVE) && !(panel->flag & PNL_CLOSED)) {
-      if (panel_active_animation_changed(&panel->children, pa_animation, 
no_animation)) {
+      if (panel_active_animation_changed(&panel->children, r_panel_animation, 
r_no_animation)) {
         return true;
       }
     }
@@ -157,15 +159,15 @@ static bool panel_active_animation_changed(ListBase *lb, 
Panel **pa_animation, b
     if (panel->activedata) {
       uiHandlePanelData *data = panel->activedata;
       if (data->state == PANEL_STATE_ANIMATION) {
-        *pa_animation = panel;
+        *r_panel_animation = panel;
       }
       else {
         /* Don't animate while handling other interaction. */
-        *no_animation = true;
+        *r_no_animation = true;
       }
     }
-    if ((panel->runtime_flag & PNL_ANIM_ALIGN) && !(*pa_animation)) {
-      *pa_animation = panel;
+    if ((panel->runtime_flag & PNL_ANIM_ALIGN) && !(*r_panel_animation)) {
+      *r_panel_animation = panel;
     }
   }
 
@@ -842,54 +844,43 @@ void UI_panel_label_offset(uiBlock *block, int *r_x, int 
*r_y)
   }
 }
 
-static void ui_draw_aligned_panel_header(
-    uiStyle *style, uiBlock *block, const rcti *rect, char dir, const bool 
show_background)
+static void ui_draw_aligned_panel_header(const uiStyle *style,
+                                         const uiBlock *block,
+                                         const rcti *rect,
+                                         const bool show_background)
 {
-  Panel *panel = block->panel;
-  rcti hrect;
-  int pnl_icons;
-  const char *activename = panel->drawname;
+  const Panel *panel = block->panel;
   const bool is_subpanel = (panel->type && panel->type->parent);
-  uiFontStyle *fontstyle = (is_subpanel) ? &style->widgetlabel : 
&style->paneltitle;
-  uchar col_title[4];
+  const uiFontStyle *fontstyle = (is_subpanel) ? &style->widgetlabel : 
&style->paneltitle;
 
   /* + 0.001f to avoid flirting with float inaccuracy */
-  pnl_icons = (panel->labelofs + (1.1f * PNL_ICON)) / block->aspect + 0.001f;
+  int pnl_icons = (panel->labelofs + (1.1f * PNL_ICON)) / block->aspect + 
0.001f;
 
   /* draw text label */
+  uchar col_title[4];
   panel_title_color_get(show_background, col_title);
   col_title[3] = 255;
 
-  hrect = *rect;
-  if (dir == 'h') {
-    hrect.xmin = rect->xmin + pnl_icons;
-    hrect.ymin -= 2.0f / block->aspect;
-    UI_fontstyle_draw(fontstyle,
-                      &hrect,
-                      activename,
-                      col_title,
-                      &(struct uiFontStyleDraw_Params){
-                          .align = UI_STYLE_TEXT_LEFT,
-                      });
-  }
-  else {
-    /* ignore 'pnl_icons', otherwise the text gets offset horizontally
-     * + 0.001f to avoid flirting with float inaccuracy
-     */
-    hrect.xmin = rect->xmin + (PNL_ICON + 5) / block->aspect + 0.001f;
-    UI_fontstyle_draw_rotated(fontstyle, &hrect, activename, col_title);
-  }
+  rcti hrect = *rect;
+  hrect.xmin = rect->xmin + pnl_icons;
+  hrect.ymin -= 2.0f / block->aspect;
+  UI_fontstyle_draw(fontstyle,
+                    &hrect,
+                    panel->drawname,
+                    col_title,
+                    &(struct uiFontStyleDraw_Params){
+                        .align = UI_STYLE_TEXT_LEFT,
+                    });
 }
 
 /* panel integrated in buttonswindow, tool/property lists etc */
-void ui_draw_aligned_panel(uiStyle *style,
-                           uiBlock *block,
+void ui_draw_aligned_panel(const uiStyle *style,
+                           const uiBlock *block,
                            const rcti *rect,
                            const bool show_pin,
                            const bool show_background)
 {
-  Panel *panel = block->panel;
-  rctf itemrect;
+  const Panel *panel = block->panel;
   float color[4];
   const bool is_subpanel = (panel->type && panel->type->parent);
   const bool show_drag = (!is_subpanel &&
@@ -1005,11 +996,12 @@ void ui_draw_aligned_panel(uiStyle *style,
   if (is_subpanel) {
     titlerect.xmin += (0.7f * UI_UNIT_X) / block->aspect + 0.001f;
   }
-  ui_draw_aligned_panel_header(style, block, &titlerect, 'h', show_background);
+  ui_draw_aligned_panel_header(style, block, &titlerect, show_background);
 
   if (show_drag) {
     /* itemrect smaller */
     const float scale = 0.7;
+    rctf itemrect;
     itemrect.xmax = headrect.xmax - (0.2f * UI_UNIT_X);
     itemrect.xmin = itemrect.xmax - BLI_rcti_size_y(&headrect);
     itemrect.ymin = headrect.ymin;
@@ -1090,20 +1082,16 @@ void ui_draw_aligned_panel(uiStyle *style,
     immUnbindProgram();
   }
 
-  uchar col_title[4];
-  panel_title_color_get(show_background, col_title);
-
   /* draw collapse icon */
-
-  /* itemrect smaller */
-  itemrect.xmin = titlerect.xmin;
-  itemrect.xmax = itemrect.xmin + BLI_rcti_size_y(&titlerect);
-  itemrect.ymin = titlerect.ymin;
-  itemrect.ymax = titlerect.ymax;
-
-  BLI_rctf_scale(&itemrect, 0.25f);
-
   {
+    rctf itemrect = {.xmin = titlerect.xmin,
+                     .xmax = itemrect.xmin + BLI_rcti_size_y(&titlerect),
+                     .ymin = titlerect.ymin,
+                     .ymax = titlerect.ymax};
+    BLI_rctf_scale(&itemrect, 0.25f);
+
+    uchar col_title[4];
+    panel_title_color_get(show_background, col_title);
     float tria_color[4];
     rgb_uchar_to_float(tria_color, col_title);
     tria_color[3] = 1.0f;
@@ -1240,11 +1228,10 @@ static void align_sub_panels(Panel *panel)
 /* returns 1 when it did something */
 static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag)
 {
-  PanelSort *ps, *panelsort, *psnext;
-  int a, tot = 0;
-  bool done;
+  int i;
 
   /* count active, not tabbed panels */
+  int tot = 0;
   LISTBASE_FOREACH (Panel *, panel, &region->panels) {
     if (panel->runtime_flag & PNL_ACTIVE) {
       tot++;
@@ -1256,9 +1243,9 @@ static bool uiAlignPanelStep(ARegion *region, const float 
fac, const bool drag)
   }
 
   /* sort panels */
-  panelsort = MEM_callocN(tot * sizeof(PanelSort), "panelsort");
+  PanelSort *panelsort = MEM_callocN(tot * sizeof(PanelSort), "panelsort");
 
-  ps = panelsort;
+  PanelSort *ps = panelsort;
   LISTBASE_FOREACH (Panel *, panel, &region->panels) {
     if (panel->runtime_flag & PNL_ACTIVE) {
       ps->panel = MEM_dupallocN(panel);
@@ -1271,8 +1258,8 @@ static bool uiAlignPanelStep(ARegion *region, const float 
fac, const bool drag)
     /* while we are dragging, we sort on location and update sortorder */
     qsort(panelsort, tot, sizeof(PanelSort), find_highest_panel);
 
-    for (ps = panelsort, a = 0; a < tot; a++, ps++) {
-      ps->orig->sortorder = a;
+    for (ps = panelsort, i = 0; i < tot; i++, ps++) {
+      ps->orig->sortorder = i;
     }
   }
   else {
@@ -1287,8 +1274,8 @@ static bool uiAlignPanelStep(ARegion *region, const float 
fac, const bool drag)
   ps->panel->ofsy = -get_panel_size_y(ps->panel);
   ps->panel->ofsx += ps->panel->runtime.region_ofsx;
 
-  for (a = 0; a < tot - 1; a++, ps++) {
-    psnext = ps + 1;
+  for (i = 0; i < tot - 1; i++, ps++) {
+    PanelSort *psnext = ps + 1;
 
     bool use_box = ps->panel->type && ps->panel->type->flag & PNL_DRAW_BOX;
     bool use_box_next = psnext->panel->type && psnext->panel->type->flag & 
PNL_DRAW_BOX;
@@ -1307,16 +1294,16 @@ static bool uiAlignPanelStep(ARegion *region, const 
float fac, const bool drag)
   }
 
   /* we interpolate */
-  done = false;
+  bool changed = false;
   ps = panelsort;
-  for (a = 0; a < tot; a++, ps++) {
+  for (i = 0; i < tot; i++, ps++) {
     if ((ps->panel->flag & PNL_SELECT) == 0) {
       if ((ps->orig->ofsx != ps->panel->ofsx) || (ps->orig->ofsy != 
ps->panel->ofsy)) {
         ps->orig->ofsx = round_fl_to_int(fac * (float)ps->panel->ofsx +
                                          (1.0f - fac) * (float)ps->orig->ofsx);
         ps->orig->ofsy = round_fl_to_int(fac * (float)ps->panel->ofsy +
                                          (1.0f - fac) * (float)ps->orig->ofsy);
-        done = true;
+        changed = true;
       }
     }
   }
@@ -1331,12 +1318,12 @@ static bool uiAlignPanelStep(ARegion *region, const 
float fac, const bool drag)
   }
 
   /* free panelsort array */
-  for (ps = panelsort, a = 0; a < tot; a++, ps++) {
+  for (ps = panelsort, i = 0; i < tot; i++, ps++) {
     MEM_freeN(ps->panel);
   }
   MEM_freeN(panelsort);
 
-  return done;
+  return changed;
 }
 
 static void ui_pan

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to