[Bf-blender-cvs] [6d630219ce3] master: Cleanup: Declare variables where initialized

Hans Goudey noreply at git.blender.org
Mon Oct 5 05:44:25 CEST 2020


Commit: 6d630219ce39e8c1022b2d6732e188675a8d7eee
Author: Hans Goudey
Date:   Sun Oct 4 22:44:19 2020 -0500
Branches: master
https://developer.blender.org/rB6d630219ce39e8c1022b2d6732e188675a8d7eee

Cleanup: Declare variables where initialized

Declaring variables where they are initialized and used makes their
scope much more explicit and it aids readility since types are visible.
This commit doesn't touch the ID template code since there is an
active patch in that area.

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

M	source/blender/editors/interface/interface_templates.c

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

diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 26231a0f069..f61941cd2bc 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -114,9 +114,7 @@ void UI_template_fix_linking(void)
 
 void uiTemplateHeader(uiLayout *layout, bContext *C)
 {
-  uiBlock *block;
-
-  block = uiLayoutAbsoluteBlock(layout);
+  uiBlock *block = uiLayoutAbsoluteBlock(layout);
   ED_area_header_switchbutton(C, block, 0);
 }
 
@@ -215,13 +213,12 @@ static uiBlock *template_common_search_menu(const bContext *C,
 {
   static char search[256];
   wmWindow *win = CTX_wm_window(C);
-  uiBlock *block;
   uiBut *but;
 
   /* clear initial search string, then all items show */
   search[0] = 0;
 
-  block = UI_block_begin(C, region, "_popup", UI_EMBOSS);
+  uiBlock *block = UI_block_begin(C, region, "_popup", UI_EMBOSS);
   UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_SEARCH_MENU);
   UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP);
 
@@ -1619,12 +1616,11 @@ static void template_search_exec_fn(bContext *C, void *arg_template, void *item)
 static uiBlock *template_search_menu(bContext *C, ARegion *region, void *arg_template)
 {
   static TemplateSearch template_search;
-  PointerRNA active_ptr;
 
   /* arg_template is malloced, can be freed by parent button */
   template_search = *((TemplateSearch *)arg_template);
-  active_ptr = RNA_property_pointer_get(&template_search.search_data.target_ptr,
-                                        template_search.search_data.target_prop);
+  PointerRNA active_ptr = RNA_property_pointer_get(&template_search.search_data.target_ptr,
+                                                   template_search.search_data.target_prop);
 
   return template_common_search_menu(C,
                                      region,
@@ -2348,10 +2344,10 @@ static eAutoPropButsReturn template_operator_property_buts_draw_single(
   }
   else {
     wmWindowManager *wm = CTX_wm_manager(C);
-    PointerRNA ptr;
     uiTemplateOperatorPropertyPollParam user_data = {.C = C, .op = op, .flag = layout_flags};
     const bool use_prop_split = (layout_flags & UI_TEMPLATE_OP_PROPS_NO_SPLIT_LAYOUT) == 0;
 
+    PointerRNA ptr;
     RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
 
     uiLayoutSetPropSep(layout, use_prop_split);
@@ -2568,9 +2564,6 @@ static void constraint_active_func(bContext *UNUSED(C), void *ob_v, void *con_v)
 static void draw_constraint_header(uiLayout *layout, Object *ob, bConstraint *con)
 {
   bPoseChannel *pchan = BKE_pose_channel_active(ob);
-  uiBlock *block;
-  uiLayout *sub;
-  PointerRNA ptr;
   short proxy_protected, xco = 0, yco = 0;
   // int rb_col; // UNUSED
 
@@ -2583,15 +2576,16 @@ static void draw_constraint_header(uiLayout *layout, Object *ob, bConstraint *co
   }
 
   /* unless button has own callback, it adds this callback to button */
-  block = uiLayoutGetBlock(layout);
+  uiBlock *block = uiLayoutGetBlock(layout);
   UI_block_func_set(block, constraint_active_func, ob, con);
 
+  PointerRNA ptr;
   RNA_pointer_create(&ob->id, &RNA_Constraint, con, &ptr);
 
   uiLayoutSetContextPointer(layout, "constraint", &ptr);
 
   /* Constraint type icon. */
-  sub = uiLayoutRow(layout, false);
+  uiLayout *sub = uiLayoutRow(layout, false);
   uiLayoutSetEmboss(sub, false);
   uiLayoutSetRedAlert(sub, (con->flag & CONSTRAINT_DISABLE));
   uiItemL(sub, "", RNA_struct_ui_icon(ptr.type));
@@ -2670,17 +2664,14 @@ static void draw_constraint_header(uiLayout *layout, Object *ob, bConstraint *co
 
 void uiTemplateConstraintHeader(uiLayout *layout, PointerRNA *ptr)
 {
-  Object *ob;
-  bConstraint *con;
-
   /* verify we have valid data */
   if (!RNA_struct_is_a(ptr->type, &RNA_Constraint)) {
     RNA_warning("Expected constraint on object");
     return;
   }
 
-  ob = (Object *)ptr->owner_id;
-  con = ptr->data;
+  Object *ob = (Object *)ptr->owner_id;
+  bConstraint *con = ptr->data;
 
   if (!ob || !(GS(ob->id.name) == ID_OB)) {
     RNA_warning("Expected constraint on object");
@@ -2721,14 +2712,8 @@ void uiTemplatePreview(uiLayout *layout,
                        MTex *slot,
                        const char *preview_id)
 {
-  uiLayout *row, *col;
-  uiBlock *block;
-  uiPreview *ui_preview = NULL;
-  ARegion *region;
-
   Material *ma = NULL;
   Tex *tex = (Tex *)id;
-  ID *pid, *pparent;
   short *pr_texture = NULL;
   PointerRNA material_ptr;
   PointerRNA texture_ptr;
@@ -2741,8 +2726,8 @@ void uiTemplatePreview(uiLayout *layout,
   }
 
   /* decide what to render */
-  pid = id;
-  pparent = NULL;
+  ID *pid = id;
+  ID *pparent = NULL;
 
   if (id && (GS(id->name) == ID_TE)) {
     if (parent && (GS(parent->name) == ID_MA)) {
@@ -2776,8 +2761,9 @@ void uiTemplatePreview(uiLayout *layout,
   }
 
   /* Find or add the uiPreview to the current Region. */
-  region = CTX_wm_region(C);
-  ui_preview = BLI_findstring(&region->ui_previews, preview_id, offsetof(uiPreview, preview_id));
+  ARegion *region = CTX_wm_region(C);
+  uiPreview *ui_preview = BLI_findstring(
+      &region->ui_previews, preview_id, offsetof(uiPreview, preview_id));
 
   if (!ui_preview) {
     ui_preview = MEM_callocN(sizeof(uiPreview), "uiPreview");
@@ -2794,9 +2780,9 @@ void uiTemplatePreview(uiLayout *layout,
   }
 
   /* layout */
-  block = uiLayoutGetBlock(layout);
-  row = uiLayoutRow(layout, false);
-  col = uiLayoutColumn(row, false);
+  uiBlock *block = uiLayoutGetBlock(layout);
+  uiLayout *row = uiLayoutRow(layout, false);
+  uiLayout *col = uiLayoutColumn(row, false);
   uiLayoutSetKeepAspect(col, true);
 
   /* add preview */
@@ -2996,12 +2982,10 @@ static void colorband_flip_cb(bContext *C, ColorBand *coba)
 {
   CBData data_tmp[MAXCOLORBAND];
 
-  int a;
-
-  for (a = 0; a < coba->tot; a++) {
+  for (int a = 0; a < coba->tot; a++) {
     data_tmp[a] = coba->data[coba->tot - (a + 1)];
   }
-  for (a = 0; a < coba->tot; a++) {
+  for (int a = 0; a < coba->tot; a++) {
     data_tmp[a].pos = 1.0f - data_tmp[a].pos;
     coba->data[a] = data_tmp[a];
   }
@@ -3015,11 +2999,10 @@ static void colorband_flip_cb(bContext *C, ColorBand *coba)
 static void colorband_distribute_cb(bContext *C, ColorBand *coba, bool evenly)
 {
   if (coba->tot > 1) {
-    int a;
     const int tot = evenly ? coba->tot - 1 : coba->tot;
     const float gap = 1.0f / tot;
     float pos = 0.0f;
-    for (a = 0; a < coba->tot; a++) {
+    for (int a = 0; a < coba->tot; a++) {
       coba->data[a].pos = pos;
       pos += gap;
     }
@@ -3053,10 +3036,10 @@ static uiBlock *colorband_tools_func(bContext *C, ARegion *region, void *coba_v)
 {
   const uiStyle *style = UI_style_get_dpi();
   ColorBand *coba = coba_v;
-  uiBlock *block;
-  short yco = 0, menuwidth = 10 * UI_UNIT_X;
+  short yco = 0;
+  short menuwidth = 10 * UI_UNIT_X;
 
-  block = UI_block_begin(C, region, __func__, UI_EMBOSS_PULLDOWN);
+  uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS_PULLDOWN);
   UI_block_func_butmenu_set(block, colorband_tools_dofunc, coba);
 
   uiLayout *layout = UI_block_layout(block,
@@ -3197,20 +3180,19 @@ static void colorband_buttons_layout(uiLayout *layout,
                                      RNAUpdateCb *cb,
                                      int expand)
 {
-  uiLayout *row, *split, *subsplit;
   uiBut *bt;
   const float unit = BLI_rctf_size_x(butr) / 14.0f;
   const float xs = butr->xmin;
   const float ys = butr->ymin;
-  PointerRNA ptr;
 
+  PointerRNA ptr;
   RNA_pointer_create(cb->ptr.owner_id, &RNA_ColorRamp, coba, &ptr);
 
-  split = uiLayoutSplit(layout, 0.4f, false);
+  uiLayout *split = uiLayoutSplit(layout, 0.4f, false);
 
   UI_block_emboss_set(block, UI_EMBOSS_NONE);
   UI_block_align_begin(block);
-  row = uiLayoutRow(split, false);
+  uiLayout *row = uiLayoutRow(split, false);
 
   bt = uiDefIconTextBut(block,
                         UI_BTYPE_BUT,
@@ -3331,7 +3313,7 @@ static void colorband_buttons_layout(uiLayout *layout,
     }
     else {
       split = uiLayoutSplit(layout, 0.5f, false);
-      subsplit = uiLayoutSplit(split, 0.35f, false);
+      uiLayout *subsplit = uiLayoutSplit(split, 0.35f, false);
 
       row = uiLayoutRow(subsplit, false);
       bt = uiDefButS(block,
@@ -3367,33 +3349,29 @@ static void colorband_buttons_layout(uiLayout *layout,
 void uiTemplateColorRamp(uiLayout *layout, PointerRNA *ptr, const char *propname, bool expand)
 {
   PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
-  PointerRNA cptr;
-  RNAUpdateCb *cb;
-  uiBlock *block;
-  ID *id;
-  rctf rect;
 
   if (!prop || RNA_property_type(prop) != PROP_POINTER) {
     return;
   }
 
-  cptr = RNA_property_pointer_get(ptr, prop);
+  PointerRNA cptr = RNA_property_pointer_get(ptr, prop);
   if (!cptr.data || !RNA_struct_is_a(cptr.type, &RNA_ColorRamp)) {
     return;
   }
 
-  cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
+  RNAUpdateCb *cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
   cb->ptr = *ptr;
   cb->prop = prop;
 
+  rctf rect;
   rect.xmin = 0;
   rect.xmax = 10.0f * UI_UNIT_X;
   rect.ymin = 0;
   rect.ymax = 19.5f * UI_UNIT_X;
 
-  block = uiLayoutAbsoluteBlock(layout);
+  uiBlock *block = uiLayoutAbsoluteBlock(layout);
 
-  id = cptr.owner_id;
+  ID *id = cptr.owner_id;
   UI_block_lock_set(block, (id && ID_IS_LINKED(id)), ERROR_LIBDATA_MESSAGE);
 
   colorband_buttons_layout(layout, block, cptr.data, &rect, cb, expand);
@@ -3414,24 +3392,21 @@ void uiTemplateColorRamp(uiLayout *layout, PointerRNA *ptr, const char *propname
  */
 void uiTemplateIcon(uiLayout *layout, int icon_value, float icon_scale)
 {
-  uiBlock *block;
-  uiBut *but;
-
-  block = uiLayoutAbsoluteBlock(layout);
-  but = uiDefIconBut(block,
-                     UI_BTYPE_LABEL,
-                     0,
-                     ICON_X,
-                     0,
-                     0,
-                     UI_UNIT_X * icon_scale,
-                     UI_UNIT_Y * icon_scale,
-                     NULL,
-                     0.0,
-                     0.0,
-                     0.0,
-                     0.0,
-                     "");
+  uiBlock *block = uiLayoutAbsoluteBlock(layout)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list