[Bf-blender-cvs] [0eb096f4060] master: Cleanup: Declare variables where initialized

Hans Goudey noreply at git.blender.org
Sat Nov 21 03:54:58 CET 2020


Commit: 0eb096f4060538d6b8db506ec6099137704ed8a7
Author: Hans Goudey
Date:   Fri Nov 20 21:54:52 2020 -0500
Branches: master
https://developer.blender.org/rB0eb096f4060538d6b8db506ec6099137704ed8a7

Cleanup: Declare variables where initialized

Reduce variable scope, and in a few cases, use bool instead of int.

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

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

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

diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index e2c835ac461..6d7e3ec1d8d 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -519,8 +519,8 @@ void UI_draw_anti_tria(
     float x1, float y1, float x2, float y2, float x3, float y3, const float color[4])
 {
   const float tri_arr[3][2] = {{x1, y1}, {x2, y2}, {x3, y3}};
-  float draw_color[4];
 
+  float draw_color[4];
   copy_v4_v4(draw_color, color);
   /* Note: This won't give back the original color. */
   draw_color[3] *= 1.0f / WIDGET_AA_JITTER;
@@ -645,8 +645,7 @@ static int round_box_shadow_edges(
     float (*vert)[2], const rcti *rect, float rad, int roundboxalign, float step)
 {
   float vec[WIDGET_CURVE_RESOLU][2];
-  float minx, miny, maxx, maxy;
-  int a, tot = 0;
+  int tot = 0;
 
   rad += step;
 
@@ -654,65 +653,65 @@ static int round_box_shadow_edges(
     rad = 0.5f * BLI_rcti_size_y(rect);
   }
 
-  minx = rect->xmin - step;
-  miny = rect->ymin - step;
-  maxx = rect->xmax + step;
-  maxy = rect->ymax + step;
+  const float minx = rect->xmin - step;
+  const float miny = rect->ymin - step;
+  const float maxx = rect->xmax + step;
+  const float maxy = rect->ymax + step;
 
   /* mult */
-  for (a = 0; a < WIDGET_CURVE_RESOLU; a++) {
+  for (int a = 0; a < WIDGET_CURVE_RESOLU; a++) {
     vec[a][0] = rad * cornervec[a][0];
     vec[a][1] = rad * cornervec[a][1];
   }
 
   /* start with left-top, anti clockwise */
   if (roundboxalign & UI_CNR_TOP_LEFT) {
-    for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
+    for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
       vert[tot][0] = minx + rad - vec[a][0];
       vert[tot][1] = maxy - vec[a][1];
     }
   }
   else {
-    for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
+    for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
       vert[tot][0] = minx;
       vert[tot][1] = maxy;
     }
   }
 
   if (roundboxalign & UI_CNR_BOTTOM_LEFT) {
-    for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
+    for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
       vert[tot][0] = minx + vec[a][1];
       vert[tot][1] = miny + rad - vec[a][0];
     }
   }
   else {
-    for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
+    for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
       vert[tot][0] = minx;
       vert[tot][1] = miny;
     }
   }
 
   if (roundboxalign & UI_CNR_BOTTOM_RIGHT) {
-    for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
+    for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
       vert[tot][0] = maxx - rad + vec[a][0];
       vert[tot][1] = miny + vec[a][1];
     }
   }
   else {
-    for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
+    for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
       vert[tot][0] = maxx;
       vert[tot][1] = miny;
     }
   }
 
   if (roundboxalign & UI_CNR_TOP_RIGHT) {
-    for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
+    for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
       vert[tot][0] = maxx - vec[a][1];
       vert[tot][1] = maxy - rad + vec[a][0];
     }
   }
   else {
-    for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
+    for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
       vert[tot][0] = maxx;
       vert[tot][1] = maxy;
     }
@@ -733,7 +732,7 @@ static void round_box__edges(
   /* for uv, can divide by zero */
   const float facxi = (maxxi != minxi) ? 1.0f / (maxxi - minxi) : 0.0f;
   const float facyi = (maxyi != minyi) ? 1.0f / (maxyi - minyi) : 0.0f;
-  int a, tot = 0, minsize;
+  int tot = 0;
   const int hnum = ((roundboxalign & (UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT)) ==
                         (UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT) ||
                     (roundboxalign & (UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT)) ==
@@ -747,7 +746,7 @@ static void round_box__edges(
                        1 :
                        2;
 
-  minsize = min_ii(BLI_rcti_size_x(rect) * hnum, BLI_rcti_size_y(rect) * vnum);
+  int minsize = min_ii(BLI_rcti_size_x(rect) * hnum, BLI_rcti_size_y(rect) * vnum);
 
   if (2.0f * rad > minsize) {
     rad = 0.5f * minsize;
@@ -769,7 +768,7 @@ static void round_box__edges(
   BLI_rctf_init(&wt->uniform_params.recti, minxi, maxxi, minyi, maxyi);
 
   /* mult */
-  for (a = 0; a < WIDGET_CURVE_RESOLU; a++) {
+  for (int a = 0; a < WIDGET_CURVE_RESOLU; a++) {
     veci[a][0] = radi * cornervec[a][0];
     veci[a][1] = radi * cornervec[a][1];
     vec[a][0] = rad * cornervec[a][0];
@@ -778,8 +777,7 @@ static void round_box__edges(
 
   /* corner left-bottom */
   if (roundboxalign & UI_CNR_BOTTOM_LEFT) {
-
-    for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
+    for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
       wt->inner_v[tot][0] = minxi + veci[a][1];
       wt->inner_v[tot][1] = minyi + radi - veci[a][0];
 
@@ -805,8 +803,7 @@ static void round_box__edges(
 
   /* corner right-bottom */
   if (roundboxalign & UI_CNR_BOTTOM_RIGHT) {
-
-    for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
+    for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
       wt->inner_v[tot][0] = maxxi - radi + veci[a][0];
       wt->inner_v[tot][1] = minyi + veci[a][1];
 
@@ -834,8 +831,7 @@ static void round_box__edges(
 
   /* corner right-top */
   if (roundboxalign & UI_CNR_TOP_RIGHT) {
-
-    for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
+    for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
       wt->inner_v[tot][0] = maxxi - veci[a][1];
       wt->inner_v[tot][1] = maxyi - radi + veci[a][0];
 
@@ -861,8 +857,7 @@ static void round_box__edges(
 
   /* corner left-top */
   if (roundboxalign & UI_CNR_TOP_LEFT) {
-
-    for (a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
+    for (int a = 0; a < WIDGET_CURVE_RESOLU; a++, tot++) {
       wt->inner_v[tot][0] = minxi + radi - veci[a][0];
       wt->inner_v[tot][1] = maxyi - veci[a][1];
 
@@ -874,7 +869,6 @@ static void round_box__edges(
     }
   }
   else {
-
     wt->inner_v[tot][0] = minxi;
     wt->inner_v[tot][1] = maxyi;
 
@@ -914,19 +908,14 @@ static void shape_preset_init_trias_ex(uiWidgetTrias *tria,
                                        const uint tris[][3],
                                        const int tris_tot)
 {
-  float centx, centy, sizex, sizey, minsize;
-  int a, i1 = 0, i2 = 1;
+  float sizex, sizey;
+  int i1 = 0, i2 = 1;
 
-  if (ELEM(where, 'r', 'l')) {
-    minsize = BLI_rcti_size_y(rect);
-  }
-  else {
-    minsize = BLI_rcti_size_x(rect);
-  }
+  float minsize = ELEM(where, 'r', 'l') ? BLI_rcti_size_y(rect) : BLI_rcti_size_x(rect);
 
   /* center position and size */
-  centx = (float)rect->xmin + 0.4f * minsize;
-  centy = (float)rect->ymin + 0.5f * minsize;
+  float centx = (float)rect->xmin + 0.4f * minsize;
+  float centy = (float)rect->ymin + 0.5f * minsize;
   tria->size = sizex = sizey = -0.5f * triasize * minsize;
 
   if (where == 'r') {
@@ -947,7 +936,7 @@ static void shape_preset_init_trias_ex(uiWidgetTrias *tria,
     i1 = 1;
   }
 
-  for (a = 0; a < verts_tot; a++) {
+  for (int a = 0; a < verts_tot; a++) {
     tria->vec[a][0] = sizex * verts[a][i1] + centx;
     tria->vec[a][1] = sizey * verts[a][i2] + centy;
   }
@@ -1367,16 +1356,13 @@ static float widget_alpha_factor(const int state)
 
 static void widget_draw_preview(BIFIconID icon, float alpha, const rcti *rect)
 {
-  int w, h, size;
-
   if (icon == ICON_NONE) {
     return;
   }
 
-  w = BLI_rcti_size_x(rect);
-  h = BLI_rcti_size_y(rect);
-  size = MIN2(w, h);
-  size -= PREVIEW_PAD * 2; /* padding */
+  const int w = BLI_rcti_size_x(rect);
+  const int h = BLI_rcti_size_y(rect);
+  const int size = MIN2(w, h) - PREVIEW_PAD * 2;
 
   if (size > 0) {
     const int x = rect->xmin + w / 2 - size / 2;
@@ -1397,7 +1383,6 @@ static void widget_draw_icon(
     const uiBut *but, BIFIconID icon, float alpha, const rcti *rect, const uchar mono_color[4])
 {
   float xs = 0.0f, ys = 0.0f;
-  float aspect, height;
 
   if (but->flag & UI_BUT_ICON_PREVIEW) {
     GPU_blend(GPU_BLEND_ALPHA);
@@ -1411,8 +1396,8 @@ static void widget_draw_icon(
     return;
   }
 
-  aspect = but->block->aspect * U.inv_dpi_fac;
-  height = ICON_DEFAULT_HEIGHT / aspect;
+  float aspect = but->block->aspect * U.inv_dpi_fac;
+  float height = ICON_DEFAULT_HEIGHT / aspect;
 
   /* calculate blend color */
   if (ELEM(but->type, UI_BTYPE_TOGGLE, UI_BTYPE_ROW, UI_BTYPE_TOGGLE_N, UI_BTYPE_LISTROW)) {
@@ -1501,12 +1486,12 @@ static void widget_draw_submenu_tria(const uiBut *but,
   const int tria_width = (int)(ICON_DEFAULT_WIDTH / aspect) - 2 * U.pixelsize;
   const int xs = rect->xmax - tria_width;
   const int ys = (rect->ymin + rect->ymax - tria_height) / 2.0f;
-  float col[4];
-  rctf tria_rect;
 
+  float col[4];
   rgba_uchar_to_float(col, wcol->text);
   col[3] *= 0.8f;
 
+  rctf tria_rect;
   BLI_rctf_init(&tria_rect, xs, xs + tria_width, ys, ys + tria_height);
   BLI_rctf_scale(&tria_rect, 0.4f);
 
@@ -1546,9 +1531,6 @@ static void ui_text_clip_right_ex(const uiFontStyle *fstyle,
                                   const float sep_strwidth,
                                   size_t *r_final_len)
 {
-  float tmp;
-  int l_end;
-
   BLI_assert(str[0]);
 
   /* If the trailing ellipsis takes more than 20% of all available width, just cut the string
@@ -1556,14 +1538,17 @@ static void ui_text_clip_right_ex(const uiFontStyle *fstyle,
    * already!).
    */
   if (sep_strwidth / okwidth > 0.2f) {
-    l_end = BLF_width_to_strlen(fstyle->uifont_id, str, max_len, okwidth, &tmp);
+    float tmp;
+    const int l_end = BLF_width_to_strlen(fstyle->uifont_id, str, max_len, okwidth, &tmp);
     str[l_end] = '\0';
     if (r_final_len) {
       *r_final_len = (size_t)l_end;
     }
   }
   else {
-    l_end = BLF_width_to_strlen(fstyle->uifont_id, str, max_len, okwidth - sep_strwidth, &tmp);
+    float tmp;
+    const int l_end = BLF_width_to_strlen(
+        fstyle->uifont_id, str, max_len, okwidth - sep_strwidth, &tmp);
     memcpy(str + l_end, sep, sep_len + 1); /* +1 for trailing '\0'. */
     if (r_final_len) {
       *r_final_len = (size_t)(l_end) + sep_len;
@@ -1589,8 +1574,6 @@ float UI_text_clip_middle_ex(const uiFontSt

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list