diff options
author | Jacques Lucke <jacques@blender.org> | 2020-09-09 19:41:07 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-09-09 19:41:07 +0300 |
commit | 63916f5941b443dfc8566682bb75374e5abd553f (patch) | |
tree | fb0704701f1d4d9acbddf4a6fbc62c819d8d4c36 /source/blender/editors/interface | |
parent | 0cff2c944f9c2cd3ac873fe826c4399fc2f32159 (diff) |
Cleanup: reduce variable scope
Diffstat (limited to 'source/blender/editors/interface')
9 files changed, 36 insertions, 45 deletions
diff --git a/source/blender/editors/interface/interface_align.c b/source/blender/editors/interface/interface_align.c index e92adc8a2ec..d626c57b121 100644 --- a/source/blender/editors/interface/interface_align.c +++ b/source/blender/editors/interface/interface_align.c @@ -393,7 +393,6 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region) ButAlign *butal_array; ButAlign *butal, *butal_other; int side; - int i, j; /* First loop: we count number of buttons belonging to an align group, * and clear their align flag. @@ -452,9 +451,11 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region) /* Third loop: for each pair of buttons in the same align group, * we compute their potential proximity. Note that each pair is checked only once, and that we * break early in case we know all remaining pairs will always be too far away. */ + int i; for (i = 0, butal = butal_array; i < num_buttons; i++, butal++) { const short alignnr = butal->but->alignnr; + int j; for (j = i + 1, butal_other = &butal_array[i + 1]; j < num_buttons; j++, butal_other++) { const float max_delta = MAX_DELTA; diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index 4d53018cd32..bcb8a10be02 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -2162,7 +2162,6 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, const uiWidgetColors *wcol, const rcti *rect) { - uint i; float fx, fy; uiButCurveProfile *but_profile = (uiButCurveProfile *)but; @@ -2241,7 +2240,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, /* Create array of the positions of the table's points. */ float(*table_coords)[2] = MEM_mallocN(sizeof(*table_coords) * tot_points, "table x coords"); - for (i = 0; i < (uint)PROF_TABLE_LEN(profile->path_len); + for (uint i = 0; i < (uint)PROF_TABLE_LEN(profile->path_len); i++) { /* Only add the points from the table here. */ table_coords[i][0] = pts[i].x; table_coords[i][1] = pts[i].y; @@ -2284,7 +2283,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, GPU_blend(GPU_BLEND_ALPHA); GPU_polygon_smooth(false); immBegin(GPU_PRIM_TRIS, 3 * tot_triangles); - for (i = 0; i < tot_triangles; i++) { + for (uint i = 0; i < tot_triangles; i++) { for (uint j = 0; j < 3; j++) { uint *tri = tri_indices[i]; fx = rect->xmin + zoomx * (table_coords[tri[j]][0] - offsx); @@ -2301,7 +2300,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, immUniformColor3ubvAlpha((const uchar *)wcol->item, 255); GPU_line_smooth(true); immBegin(GPU_PRIM_LINE_STRIP, tot_points - 1); - for (i = 0; i < tot_points - 1; i++) { + for (uint i = 0; i < tot_points - 1; i++) { fx = rect->xmin + zoomx * (table_coords[i][0] - offsx); fy = rect->ymin + zoomy * (table_coords[i][1] - offsy); immVertex2f(pos, fx, fy); @@ -2313,7 +2312,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, pts = profile->path; tot_points = (uint)profile->path_len; int selected_free_points = 0; - for (i = 0; i < tot_points; i++) { + for (uint i = 0; i < tot_points; i++) { if (point_draw_handles(&pts[i])) { selected_free_points++; } @@ -2325,7 +2324,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, GPU_line_smooth(true); immBegin(GPU_PRIM_LINES, selected_free_points * 4); float ptx, pty; - for (i = 0; i < tot_points; i++) { + for (uint i = 0; i < tot_points; i++) { if (point_draw_handles(&pts[i])) { ptx = rect->xmin + zoomx * (pts[i].x - offsx); pty = rect->ymin + zoomy * (pts[i].y - offsy); @@ -2372,7 +2371,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, GPU_blend(GPU_BLEND_NONE); GPU_point_size(max_ff(3.0f, min_ff(UI_DPI_FAC / but->block->aspect * 5.0f, 5.0f))); immBegin(GPU_PRIM_POINTS, tot_points); - for (i = 0; i < tot_points; i++) { + for (uint i = 0; i < tot_points; i++) { fx = rect->xmin + zoomx * (pts[i].x - offsx); fy = rect->ymin + zoomy * (pts[i].y - offsy); immAttr4fv(col, (pts[i].flag & PROF_SELECT) ? color_vert_select : color_vert); @@ -2386,7 +2385,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, GPU_blend(GPU_BLEND_NONE); GPU_point_size(max_ff(2.0f, min_ff(UI_DPI_FAC / but->block->aspect * 4.0f, 4.0f))); immBegin(GPU_PRIM_POINTS, selected_free_points * 2); - for (i = 0; i < tot_points; i++) { + for (uint i = 0; i < tot_points; i++) { if (point_draw_handles(&pts[i])) { fx = rect->xmin + zoomx * (pts[i].h1_loc[0] - offsx); fy = rect->ymin + zoomy * (pts[i].h1_loc[1] - offsy); @@ -2408,7 +2407,7 @@ void ui_draw_but_CURVEPROFILE(ARegion *region, if (tot_points > 0 && pts) { GPU_point_size(max_ff(2.0f, min_ff(UI_DPI_FAC / but->block->aspect * 3.0f, 3.0f))); immBegin(GPU_PRIM_POINTS, tot_points); - for (i = 0; i < tot_points; i++) { + for (uint i = 0; i < tot_points; i++) { fx = rect->xmin + zoomx * (pts[i].x - offsx); fy = rect->ymin + zoomy * (pts[i].y - offsy); immAttr4fv(col, color_sample); diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index cadc2264bf4..b5f902adfb5 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -975,7 +975,7 @@ static void init_iconfile_list(struct ListBase *list) { IconFile *ifile; struct direntry *dir; - int totfile, i, index = 1; + int index = 1; const char *icondir; BLI_listbase_clear(list); @@ -985,9 +985,9 @@ static void init_iconfile_list(struct ListBase *list) return; } - totfile = BLI_filelist_dir_contents(icondir, &dir); + int totfile = BLI_filelist_dir_contents(icondir, &dir); - for (i = 0; i < totfile; i++) { + for (int i = 0; i < totfile; i++) { if ((dir[i].type & S_IFREG)) { const char *filename = dir[i].relname; diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index da3ab7556ed..62321cb1e73 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -457,14 +457,14 @@ static void ui_layer_but_cb(bContext *C, void *arg_but, void *arg_index) uiBut *but = arg_but; PointerRNA *ptr = &but->rnapoin; PropertyRNA *prop = but->rnaprop; - int i, index = POINTER_AS_INT(arg_index); + int index = POINTER_AS_INT(arg_index); const int shift = win->eventstate->shift; const int len = RNA_property_array_length(ptr, prop); if (!shift) { RNA_property_boolean_set_index(ptr, prop, index, true); - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { if (i != index) { RNA_property_boolean_set_index(ptr, prop, i, 0); } @@ -2584,14 +2584,14 @@ void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname } const EnumPropertyItem *item; - int totitem, i; + int totitem; bool free; uiLayout *split = uiLayoutSplit(layout, 0.0f, false); uiLayout *column = uiLayoutColumn(split, false); RNA_property_enum_items_gettexted(block->evil_C, ptr, prop, &item, &totitem, &free); - for (i = 0; i < totitem; i++) { + for (int i = 0; i < totitem; i++) { if (item[i].identifier[0]) { uiItemEnumR_prop(column, item[i].name, item[i].icon, ptr, prop, item[i].value); ui_but_tip_from_enum_item(block->buttons.last, &item[i]); diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 5c4877534f6..6e2229ce3e3 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -1636,8 +1636,6 @@ static void align_sub_panels(Panel *panel) /* returns 1 when it did something */ static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag) { - int i; - /* count active, not tabbed panels */ int tot = 0; LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { @@ -1666,6 +1664,7 @@ static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag) /* While we are dragging, we sort on location and update #Panel.sortorder. */ qsort(panelsort, tot, sizeof(PanelSort), find_highest_panel); + int i; for (ps = panelsort, i = 0; i < tot; i++, ps++) { ps->orig->sortorder = i; } @@ -1682,7 +1681,7 @@ 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 (i = 0; i < tot - 1; i++, ps++) { + for (int i = 0; i < tot - 1; i++, ps++) { PanelSort *psnext = ps + 1; const bool use_box = ps->panel->type && ps->panel->type->flag & PNL_DRAW_BOX; @@ -1704,7 +1703,7 @@ static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag) /* we interpolate */ bool changed = false; ps = panelsort; - for (i = 0; i < tot; i++, ps++) { + for (int 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 + @@ -1726,6 +1725,7 @@ static bool uiAlignPanelStep(ARegion *region, const float fac, const bool drag) } /* Free `panelsort` array. */ + int i; for (ps = panelsort, i = 0; i < tot; i++, ps++) { MEM_freeN(ps->panel); } diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index f472c56e280..0edc755902a 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -167,7 +167,6 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region float background_color[3]; float tone_bg; - int i; wmOrtho2_region_pixelspace(region); @@ -204,7 +203,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *region bbox.xmin += 0.5f * pad_px; /* add padding to the text */ bbox.ymax -= 0.25f * pad_px; - for (i = 0; i < data->fields_len; i++) { + for (int i = 0; i < data->fields_len; i++) { const uiTooltipField *field = &data->fields[i]; const uiTooltipField *field_next = (i + 1) != data->fields_len ? &data->fields[i + 1] : NULL; diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 08d3ad0f23c..77a9d9f549a 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -4255,7 +4255,7 @@ static void curvemap_buttons_layout(uiLayout *layout, uiBut *bt; const float dx = UI_UNIT_X; int icon, size; - int bg = -1, i; + int bg = -1; block = uiLayoutGetBlock(layout); @@ -4464,7 +4464,7 @@ static void curvemap_buttons_layout(uiLayout *layout, curve_but->gradient_type = bg; /* sliders for selected point */ - for (i = 0; i < cm->totpoint; i++) { + for (int i = 0; i < cm->totpoint; i++) { if (cm->curve[i].flag & CUMA_SELECT) { cmp = &cm->curve[i]; break; diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index ab0f6d90caa..0cbb8f268a2 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -5002,12 +5002,7 @@ static void draw_disk_shaded(float start, bool shaded) { const float radius_ext_scale = (0.5f / radius_ext); /* 1 / (2 * radius_ext) */ - int i; - float s, c; - float y1, y2; - float fac; - uchar r_col[4]; uint pos, col; GPUVertFormat *format = immVertexFormat(); @@ -5022,24 +5017,24 @@ static void draw_disk_shaded(float start, } immBegin(GPU_PRIM_TRI_STRIP, subd * 2); - for (i = 0; i < subd; i++) { - float a; - - a = start + ((i) / (float)(subd - 1)) * angle; - s = sinf(a); - c = cosf(a); - y1 = s * radius_int; - y2 = s * radius_ext; + for (int i = 0; i < subd; i++) { + float a = start + ((i) / (float)(subd - 1)) * angle; + float s = sinf(a); + float c = cosf(a); + float y1 = s * radius_int; + float y2 = s * radius_ext; if (shaded) { - fac = (y1 + radius_ext) * radius_ext_scale; + uchar r_col[4]; + float fac = (y1 + radius_ext) * radius_ext_scale; color_blend_v4_v4v4(r_col, col1, col2, fac); immAttr4ubv(col, r_col); } immVertex2f(pos, c * radius_int, s * radius_int); if (shaded) { - fac = (y2 + radius_ext) * radius_ext_scale; + uchar r_col[4]; + float fac = (y2 + radius_ext) * radius_ext_scale; color_blend_v4_v4v4(r_col, col1, col2, fac); immAttr4ubv(col, r_col); } diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c index c6b29f79137..32caf043119 100644 --- a/source/blender/editors/interface/view2d_ops.c +++ b/source/blender/editors/interface/view2d_ops.c @@ -1723,13 +1723,10 @@ static float smooth_view_rect_to_fac(const rctf *rect_a, const rctf *rect_b) const float cent_b[2] = {BLI_rctf_cent_x(rect_b), BLI_rctf_cent_y(rect_b)}; float fac_max = 0.0f; - float tfac; - int i; - - for (i = 0; i < 2; i++) { + for (int i = 0; i < 2; i++) { /* axis translation normalized to scale */ - tfac = fabsf(cent_a[i] - cent_b[i]) / min_ff(size_a[i], size_b[i]); + float tfac = fabsf(cent_a[i] - cent_b[i]) / min_ff(size_a[i], size_b[i]); fac_max = max_ff(fac_max, tfac); if (fac_max >= 1.0f) { break; |