From 20276e4b00a228ab2ef80e58cc0171cec811015a Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Fri, 16 Oct 2020 20:49:47 -0500 Subject: Cleanup: Reduce variable scope in area.c --- source/blender/editors/screen/area.c | 141 +++++++++++++++-------------------- 1 file changed, 60 insertions(+), 81 deletions(-) (limited to 'source/blender/editors/screen') diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index b77d3d1100d..10d269151ce 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -85,13 +85,11 @@ enum RegionEmbossSide { static void region_draw_emboss(const ARegion *region, const rcti *scirct, int sides) { - rcti rect; - /* translate scissor rect to region space */ - rect.xmin = scirct->xmin - region->winrct.xmin; - rect.ymin = scirct->ymin - region->winrct.ymin; - rect.xmax = scirct->xmax - region->winrct.xmin; - rect.ymax = scirct->ymax - region->winrct.ymin; + const rcti rect = {.xmin = scirct->xmin - region->winrct.xmin, + .xmax = scirct->xmax - region->winrct.xmin, + .ymin = scirct->ymin - region->winrct.ymin, + .ymax = scirct->ymax - region->winrct.ymin}; /* set transp line */ GPU_blend(GPU_BLEND_ALPHA); @@ -851,8 +849,6 @@ void ED_workspace_status_text(bContext *C, const char *str) static void area_azone_init(wmWindow *win, const bScreen *screen, ScrArea *area) { - AZone *az; - /* reinitialize entirely, regions and fullscreen add azones too */ BLI_freelistN(&area->actionzones); @@ -908,7 +904,7 @@ static void area_azone_init(wmWindow *win, const bScreen *screen, ScrArea *area) #endif /* set area action zones */ - az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone"); + AZone *az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone"); BLI_addtail(&(area->actionzones), az); az->type = AZONE_AREA; az->x1 = coords[i][0]; @@ -921,13 +917,11 @@ static void area_azone_init(wmWindow *win, const bScreen *screen, ScrArea *area) static void fullscreen_azone_init(ScrArea *area, ARegion *region) { - AZone *az; - if (ED_area_is_global(area) || (region->regiontype != RGN_TYPE_WINDOW)) { return; } - az = (AZone *)MEM_callocN(sizeof(AZone), "fullscreen action zone"); + AZone *az = (AZone *)MEM_callocN(sizeof(AZone), "fullscreen action zone"); BLI_addtail(&(area->actionzones), az); az->type = AZONE_FULLSCREEN; az->region = region; @@ -984,13 +978,11 @@ static void region_azone_edge(AZone *az, ARegion *region) /* region already made zero sized, in shape of edge */ static void region_azone_tab_plus(ScrArea *area, AZone *az, ARegion *region) { - int tot = 0, add; - /* Edge offset multiplied by the */ - float edge_offset = 1.0f; const float tab_size_x = 0.7f * U.widget_unit; const float tab_size_y = 0.4f * U.widget_unit; + int tot = 0; LISTBASE_FOREACH (AZone *, azt, &area->actionzones) { if (azt->edge == az->edge) { tot++; @@ -998,13 +990,14 @@ static void region_azone_tab_plus(ScrArea *area, AZone *az, ARegion *region) } switch (az->edge) { - case AE_TOP_TO_BOTTOMRIGHT: - add = (region->winrct.ymax == area->totrct.ymin) ? 1 : 0; + case AE_TOP_TO_BOTTOMRIGHT: { + int add = (region->winrct.ymax == area->totrct.ymin) ? 1 : 0; az->x1 = region->winrct.xmax - ((edge_offset + 1.0f) * tab_size_x); az->y1 = region->winrct.ymax - add; az->x2 = region->winrct.xmax - (edge_offset * tab_size_x); az->y2 = region->winrct.ymax - add + tab_size_y; break; + } case AE_BOTTOM_TO_TOPLEFT: az->x1 = region->winrct.xmax - ((edge_offset + 1.0f) * tab_size_x); az->y1 = region->winrct.ymin - tab_size_y; @@ -1047,14 +1040,13 @@ static void region_azone_edge_init(ScrArea *area, AZEdge edge, const bool is_fullscreen) { - AZone *az = NULL; const bool is_hidden = (region->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)); if (!region_azone_edge_poll(region, is_fullscreen)) { return; } - az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone"); + AZone *az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone"); BLI_addtail(&(area->actionzones), az); az->type = AZONE_REGION; az->region = region; @@ -1173,11 +1165,10 @@ static int rct_fits(const rcti *rect, char dir, int size) /* function checks if some overlapping region was defined before - on same place */ static void region_overlap_fix(ScrArea *area, ARegion *region) { + /* find overlapping previous region on same place */ ARegion *ar1; - const int align = RGN_ALIGN_ENUM_FROM_MASK(region->alignment); int align1 = 0; - - /* find overlapping previous region on same place */ + const int align = RGN_ALIGN_ENUM_FROM_MASK(region->alignment); for (ar1 = region->prev; ar1; ar1 = ar1->prev) { if (ar1->flag & RGN_FLAG_HIDDEN) { continue; @@ -1846,20 +1837,18 @@ static void ed_default_handlers( void ED_area_update_region_sizes(wmWindowManager *wm, wmWindow *win, ScrArea *area) { - rcti rect, overlap_rect; - rcti window_rect; - if (!(area->flag & AREA_FLAG_REGION_SIZE_UPDATE)) { return; } const bScreen *screen = WM_window_get_active_screen(win); + rcti window_rect; WM_window_rect_calc(win, &window_rect); area_calc_totrct(area, &window_rect); /* region rect sizes */ - rect = area->totrct; - overlap_rect = rect; + rcti rect = area->totrct; + rcti overlap_rect = rect; region_rect_recursive(area, area->regionbase.first, &rect, &overlap_rect, 0); /* Dynamically sized regions may have changed region sizes, so we have to force azone update. */ @@ -1887,12 +1876,12 @@ void ED_area_init(wmWindowManager *wm, wmWindow *win, ScrArea *area) WorkSpace *workspace = WM_window_get_active_workspace(win); const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook); ViewLayer *view_layer = WM_window_get_active_view_layer(win); - rcti rect, overlap_rect; - rcti window_rect; if (ED_area_is_global(area) && (area->global->flag & GLOBAL_AREA_IS_HIDDEN)) { return; } + + rcti window_rect; WM_window_rect_calc(win, &window_rect); /* set typedefinitions */ @@ -1911,8 +1900,8 @@ void ED_area_init(wmWindowManager *wm, wmWindow *win, ScrArea *area) area_calc_totrct(area, &window_rect); /* region rect sizes */ - rect = area->totrct; - overlap_rect = rect; + rcti rect = area->totrct; + rcti overlap_rect = rect; region_rect_recursive(area, area->regionbase.first, &rect, &overlap_rect, 0); area->flag &= ~AREA_FLAG_REGION_SIZE_UPDATE; @@ -2045,7 +2034,6 @@ void ED_region_toggle_hidden(bContext *C, ARegion *region) */ void ED_area_data_copy(ScrArea *area_dst, ScrArea *area_src, const bool do_free) { - SpaceType *st; const char spacetype = area_dst->spacetype; const short flag_copy = HEADER_NO_PULLDOWN; @@ -2064,13 +2052,13 @@ void ED_area_data_copy(ScrArea *area_dst, ScrArea *area_src, const bool do_free) /* regions */ if (do_free) { - st = BKE_spacetype_from_id(spacetype); + SpaceType *st = BKE_spacetype_from_id(spacetype); LISTBASE_FOREACH (ARegion *, region, &area_dst->regionbase) { BKE_area_region_free(st, region); } BLI_freelistN(&area_dst->regionbase); } - st = BKE_spacetype_from_id(area_src->spacetype); + SpaceType *st = BKE_spacetype_from_id(area_src->spacetype); LISTBASE_FOREACH (ARegion *, region, &area_src->regionbase) { ARegion *newar = BKE_area_region_copy(st, region); BLI_addtail(&area_dst->regionbase, newar); @@ -2357,7 +2345,6 @@ void ED_area_newspace(bContext *C, ScrArea *area, int type, const bool skip_regi wmWindow *win = CTX_wm_window(C); if (area->spacetype != type) { - SpaceType *st; SpaceLink *slold = area->spacedata.first; /* store area->type->exit callback */ void *area_exit = area->type ? area->type->exit : NULL; @@ -2392,7 +2379,7 @@ void ED_area_newspace(bContext *C, ScrArea *area, int type, const bool skip_regi area->type->exit = area_exit; } - st = BKE_spacetype_from_id(type); + SpaceType *st = BKE_spacetype_from_id(type); area->spacetype = type; area->type = st; @@ -2853,7 +2840,6 @@ void ED_region_panels_layout_ex(const bContext *C, ScrArea *area = CTX_wm_area(C); View2D *v2d = ®ion->v2d; - int x, y, w, em; bool use_category_tabs = (category_override == NULL) && region_uses_category_tabs(area, region); /* offset panels for small vertical tab area */ @@ -2877,11 +2863,11 @@ void ED_region_panels_layout_ex(const bContext *C, margin_x = category_tabs_width; } - w = BLI_rctf_size_x(&v2d->cur); - em = (region->type->prefsizex) ? 10 : 20; /* works out to 10*UI_UNIT_X or 20*UI_UNIT_X */ + const int w = BLI_rctf_size_x(&v2d->cur) - margin_x; + /* Works out to 10 * UI_UNIT_X or 20 * UI_UNIT_X. */ + const int em = (region->type->prefsizex) ? 10 : 20; - w -= margin_x; - int w_box_panel = w - UI_PANEL_BOX_STYLE_MARGIN * 2.0f; + const int w_box_panel = w - UI_PANEL_BOX_STYLE_MARGIN * 2.0f; /* create panels */ UI_panels_begin(C, region); @@ -2960,6 +2946,7 @@ void ED_region_panels_layout_ex(const bContext *C, } /* align panels and return size */ + int x, y; UI_panels_end(C, region, &x, &y); /* before setting the view */ @@ -3044,9 +3031,9 @@ void ED_region_panels_draw(const bContext *C, ARegion *region) /* scrollers */ const rcti *mask = NULL; - rcti mask_buf; if (region->runtime.category && (RGN_ALIGN_ENUM_FROM_MASK(region->alignment) == RGN_ALIGN_RIGHT)) { + rcti mask_buf; UI_view2d_mask_from_win(v2d, &mask_buf); mask_buf.xmax -= UI_PANEL_CATEGORY_MARGIN_WIDTH; mask = &mask_buf; @@ -3070,11 +3057,9 @@ void ED_region_panels(const bContext *C, ARegion *region) void ED_region_panels_init(wmWindowManager *wm, ARegion *region) { - wmKeyMap *keymap; - UI_view2d_region_reinit(®ion->v2d, V2D_COMMONVIEW_PANELS_UI, region->winx, region->winy); - keymap = WM_keymap_ensure(wm->defaultconf, "View2D Buttons List", 0, 0); + wmKeyMap *keymap = WM_keymap_ensure(wm->defaultconf, "View2D Buttons List", 0, 0); WM_event_add_keymap_handler(®ion->handlers, keymap); } @@ -3224,9 +3209,6 @@ bool ED_region_property_search(const bContext *C, void ED_region_header_layout(const bContext *C, ARegion *region) { const uiStyle *style = UI_style_get_dpi(); - uiBlock *block; - uiLayout *layout; - Header header = {NULL}; bool region_layout_based = region->flag & RGN_FLAG_DYNAMIC_SIZE; /* Height of buttons and scaling needed to achieve it. */ @@ -3253,14 +3235,15 @@ void ED_region_header_layout(const bContext *C, ARegion *region) continue; } - block = UI_block_begin(C, region, ht->idname, UI_EMBOSS); - layout = UI_block_layout( + uiBlock *block = UI_block_begin(C, region, ht->idname, UI_EMBOSS); + uiLayout *layout = UI_block_layout( block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER, xco, yco, buttony, 1, 0, style); if (buttony_scale != 1.0f) { uiLayoutSetScaleY(layout, buttony_scale); } + Header header = {NULL}; if (ht->draw) { header.type = ht; header.layout = layout; @@ -3390,17 +3373,17 @@ ScrArea *ED_screen_areas_iter_first(const wmWindow *win, const bScreen *screen) } ScrArea *ED_screen_areas_iter_next(const bScreen *screen, const ScrArea *area) { - if (area->global) { - for (ScrArea *area_iter = area->next; area_iter; area_iter = area_iter->next) { - if ((area_iter->global->flag & GLOBAL_AREA_IS_HIDDEN) == 0) { - return area_iter; - } - } - /* No visible next global area found, start iterating over layout areas. */ - return screen->areabase.first; + if (area->global == NULL) { + return area->next; } - return area->next; + for (ScrArea *area_iter = area->next; area_iter; area_iter = area_iter->next) { + if ((area_iter->global->flag & GLOBAL_AREA_IS_HIDDEN) == 0) { + return area_iter; + } + } + /* No visible next global area found, start iterating over layout areas. */ + return screen->areabase.first; } /** @@ -3557,9 +3540,7 @@ static void metadata_custom_draw_fields(const char *field, const char *value, vo static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const bool is_top) { char temp_str[MAX_METADATA_STR]; - int line_width; int ofs_y = 0; - int len; const float height = BLF_height_max(fontid); const float margin = height / 8; const float vertical_offset = (height + margin); @@ -3576,7 +3557,7 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const /* first line */ if (i == 0) { bool do_newline = false; - len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[0]); + int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[0]); if (metadata_is_valid(ibuf, temp_str, 0, len)) { BLF_position(fontid, xmin, ymax - vertical_offset, 0.0f); BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); @@ -3585,7 +3566,7 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[1]); if (metadata_is_valid(ibuf, temp_str, 1, len)) { - line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + int line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); BLF_position(fontid, xmax - line_width, ymax - vertical_offset, 0.0f); BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); do_newline = true; @@ -3596,7 +3577,7 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const } } /* Strip */ else if (i == 1 || i == 2) { - len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); + int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { BLF_position(fontid, xmin, ymax - vertical_offset - ofs_y, 0.0f); BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); @@ -3604,7 +3585,7 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const } } /* Note (wrapped) */ else if (i == 3) { - len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); + int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { struct ResultBLF info; BLF_enable(fontid, BLF_WORD_WRAP); @@ -3617,9 +3598,9 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const } } else { - len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); + int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i + 1]); if (metadata_is_valid(ibuf, temp_str, i + 1, len)) { - line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); + int line_width = BLF_width(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); BLF_position(fontid, xmax - line_width, ymax - vertical_offset - ofs_y, 0.0f); BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); ofs_y += vertical_offset; @@ -3638,7 +3619,7 @@ static void metadata_draw_imbuf(ImBuf *ibuf, const rctf *rect, int fontid, const int ofs_x = 0; ofs_y = ctx.current_y; for (int i = 5; i < 10; i++) { - len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i]); + int len = BLI_snprintf_rlen(temp_str, MAX_METADATA_STR, "%s: ", meta_data_list[i]); if (metadata_is_valid(ibuf, temp_str, i, len)) { BLF_position(fontid, xmin + ofs_x, ymin + ofs_y, 0.0f); BLF_draw(fontid, temp_str, BLF_DRAW_STR_DUMMY_MAX); @@ -3667,13 +3648,13 @@ static float metadata_box_height_get(ImBuf *ibuf, int fontid, const bool is_top) const float height = BLF_height_max(fontid); const float margin = (height / 8); char str[MAX_METADATA_STR] = ""; - short i, count = 0; + short count = 0; if (is_top) { if (metadata_is_valid(ibuf, str, 0, 0) || metadata_is_valid(ibuf, str, 1, 0)) { count++; } - for (i = 2; i < 5; i++) { + for (int i = 2; i < 5; i++) { if (metadata_is_valid(ibuf, str, i, 0)) { if (i == 4) { struct { @@ -3696,7 +3677,7 @@ static float metadata_box_height_get(ImBuf *ibuf, int fontid, const bool is_top) } } else { - for (i = 5; i < 10; i++) { + for (int i = 5; i < 10; i++) { if (metadata_is_valid(ibuf, str, i, 0)) { count = 1; break; @@ -3720,8 +3701,6 @@ static float metadata_box_height_get(ImBuf *ibuf, int fontid, const bool is_top) void ED_region_image_metadata_draw( int x, int y, ImBuf *ibuf, const rctf *frame, float zoomx, float zoomy) { - float box_y; - rctf rect; const uiStyle *style = UI_style_get_dpi(); if (!ibuf->metadata) { @@ -3740,10 +3719,11 @@ void ED_region_image_metadata_draw( /* *** upper box*** */ /* get needed box height */ - box_y = metadata_box_height_get(ibuf, blf_mono_font, true); + float box_y = metadata_box_height_get(ibuf, blf_mono_font, true); if (box_y) { /* set up rect */ + rctf rect; BLI_rctf_init(&rect, frame->xmin, frame->xmax, frame->ymax, frame->ymax + box_y); /* draw top box */ GPUVertFormat *format = immVertexFormat(); @@ -3768,6 +3748,7 @@ void ED_region_image_metadata_draw( if (box_y) { /* set up box rect */ + rctf rect; BLI_rctf_init(&rect, frame->xmin, frame->xmax, frame->ymin - box_y, frame->ymin); /* draw top box */ GPUVertFormat *format = immVertexFormat(); @@ -3810,11 +3791,8 @@ void ED_region_image_metadata_panel_draw(ImBuf *ibuf, uiLayout *layout) void ED_region_grid_draw(ARegion *region, float zoomx, float zoomy, float x0, float y0) { - float gridsize, gridstep = 1.0f / 32.0f; - float fac, blendfac; - int x1, y1, x2, y2; - /* the image is located inside (x0, y0), (x0+1, y0+1) as set by view2d */ + int x1, y1, x2, y2; UI_view2d_view_to_region(®ion->v2d, x0, y0, &x1, &y1); UI_view2d_view_to_region(®ion->v2d, x0 + 1.0f, y0 + 1.0f, &x2, &y2); @@ -3831,7 +3809,8 @@ void ED_region_grid_draw(ARegion *region, float zoomx, float zoomy, float x0, fl immUnbindProgram(); /* gridsize adapted to zoom level */ - gridsize = 0.5f * (zoomx + zoomy); + float gridsize = 0.5f * (zoomx + zoomy); + float gridstep = 1.0f / 32.0f; if (gridsize <= 0.0f) { return; } @@ -3849,7 +3828,7 @@ void ED_region_grid_draw(ARegion *region, float zoomx, float zoomy, float x0, fl } } - blendfac = 0.25f * gridsize - floorf(0.25f * gridsize); + float blendfac = 0.25f * gridsize - floorf(0.25f * gridsize); CLAMP(blendfac, 0.0f, 1.0f); int count_fine = 1.0f / gridstep; @@ -3865,7 +3844,7 @@ void ED_region_grid_draw(ARegion *region, float zoomx, float zoomy, float x0, fl float theme_color[3]; UI_GetThemeColorShade3fv(TH_GRID, (int)(20.0f * (1.0f - blendfac)), theme_color); - fac = 0.0f; + float fac = 0.0f; /* the fine resolution level */ for (int i = 0; i < count_fine; i++) { -- cgit v1.2.3