diff options
author | Hans Goudey <h.goudey@me.com> | 2020-10-17 09:28:34 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2020-10-17 09:28:34 +0300 |
commit | 7447eb7e7430b924deab74b8541b3f56a540a6e9 (patch) | |
tree | fe09abf4876d3ea80c94cc95626433160a64e3d9 /source/blender | |
parent | 2c14a950a718b2a82d6f9da29bad038a2c91ec74 (diff) |
Cleanup: Miscellaneous improvements in wm directory
- Reduce variable scope.
- Use LISTBASE_FOREACH macros.
- Return early in some cases to reduce to reduce indentation.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/windowmanager/intern/wm_dragdrop.c | 26 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_draw.c | 62 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_event_system.c | 194 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 197 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_panel_type.c | 10 |
5 files changed, 201 insertions, 288 deletions
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c index b1a469d1365..373360c7b92 100644 --- a/source/blender/windowmanager/intern/wm_dragdrop.c +++ b/source/blender/windowmanager/intern/wm_dragdrop.c @@ -74,9 +74,7 @@ typedef struct wmDropBoxMap { /* spaceid/regionid is zero for window drop maps */ ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid) { - wmDropBoxMap *dm; - - for (dm = dropboxes.first; dm; dm = dm->next) { + LISTBASE_FOREACH (wmDropBoxMap *, dm, &dropboxes) { if (dm->spaceid == spaceid && dm->regionid == regionid) { if (STREQLEN(idname, dm->idname, KMAP_MAX_NAME)) { return &dm->dropboxes; @@ -84,7 +82,7 @@ ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid) } } - dm = MEM_callocN(sizeof(struct wmDropBoxMap), "dropmap list"); + wmDropBoxMap *dm = MEM_callocN(sizeof(struct wmDropBoxMap), "dropmap list"); BLI_strncpy(dm->idname, idname, KMAP_MAX_NAME); dm->spaceid = spaceid; dm->regionid = regionid; @@ -99,7 +97,6 @@ wmDropBox *WM_dropbox_add(ListBase *lb, void (*copy)(wmDrag *, wmDropBox *)) { wmDropBox *drop = MEM_callocN(sizeof(wmDropBox), "wmDropBox"); - drop->poll = poll; drop->copy = copy; drop->ot = WM_operatortype_find(idname, 0); @@ -119,12 +116,9 @@ wmDropBox *WM_dropbox_add(ListBase *lb, void wm_dropbox_free(void) { - wmDropBoxMap *dm; - - for (dm = dropboxes.first; dm; dm = dm->next) { - wmDropBox *drop; - for (drop = dm->dropboxes.first; drop; drop = drop->next) { + LISTBASE_FOREACH (wmDropBoxMap *, dm, &dropboxes) { + LISTBASE_FOREACH (wmDropBox *, drop, &dm->dropboxes) { if (drop->ptr) { WM_operator_properties_free(drop->ptr); MEM_freeN(drop->ptr); @@ -277,9 +271,8 @@ static void wm_drop_operator_options(bContext *C, wmDrag *drag, const wmEvent *e void wm_drags_check_ops(bContext *C, const wmEvent *event) { wmWindowManager *wm = CTX_wm_manager(C); - wmDrag *drag; - for (drag = wm->drags.first; drag; drag = drag->next) { + LISTBASE_FOREACH (wmDrag *, drag, &wm->drags) { wm_drop_operator_options(C, drag, event); } } @@ -389,12 +382,10 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect) { const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; wmWindowManager *wm = CTX_wm_manager(C); - wmDrag *drag; const int winsize_y = WM_window_pixels_y(win); - int cursorx, cursory, x, y; - cursorx = win->eventstate->x; - cursory = win->eventstate->y; + int cursorx = win->eventstate->x; + int cursory = win->eventstate->y; if (rect) { rect->xmin = rect->xmax = cursorx; rect->ymin = rect->ymax = cursory; @@ -402,12 +393,13 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect) /* Should we support multi-line drag draws? Maybe not, more types mixed wont work well. */ GPU_blend(GPU_BLEND_ALPHA); - for (drag = wm->drags.first; drag; drag = drag->next) { + LISTBASE_FOREACH (wmDrag *, drag, &wm->drags) { const uchar text_col[] = {255, 255, 255, 255}; int iconsize = UI_DPI_ICON_SIZE; int padding = 4 * UI_DPI_FAC; /* image or icon */ + int x, y; if (drag->imb) { x = cursorx - drag->sx / 2; y = cursory - drag->sy / 2; diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index a805e00e0a2..3449c6974f5 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -86,7 +86,6 @@ static void wm_paintcursor_draw(bContext *C, ScrArea *area, ARegion *region) wmWindowManager *wm = CTX_wm_manager(C); wmWindow *win = CTX_wm_window(C); bScreen *screen = WM_window_get_active_screen(win); - wmPaintCursor *pc; /* Don't draw paint cursors with locked interface. Painting is not possible * then, and cursor drawing can use scene data that another thread may be @@ -95,36 +94,37 @@ static void wm_paintcursor_draw(bContext *C, ScrArea *area, ARegion *region) return; } - if (region->visible && region == screen->active_region) { - for (pc = wm->paintcursors.first; pc; pc = pc->next) { - - if ((pc->space_type != SPACE_TYPE_ANY) && (area->spacetype != pc->space_type)) { - continue; - } + if (!region->visible || region != screen->active_region) { + return; + } - if ((pc->region_type != RGN_TYPE_ANY) && (region->regiontype != pc->region_type)) { - continue; - } + LISTBASE_FOREACH (wmPaintCursor *, pc, &wm->paintcursors) { + if ((pc->space_type != SPACE_TYPE_ANY) && (area->spacetype != pc->space_type)) { + continue; + } - if (pc->poll == NULL || pc->poll(C)) { - /* Prevent drawing outside region. */ - GPU_scissor_test(true); - GPU_scissor(region->winrct.xmin, - region->winrct.ymin, - BLI_rcti_size_x(®ion->winrct) + 1, - BLI_rcti_size_y(®ion->winrct) + 1); - - if (ELEM(win->grabcursor, GHOST_kGrabWrap, GHOST_kGrabHide)) { - int x = 0, y = 0; - wm_get_cursor_position(win, &x, &y); - pc->draw(C, x, y, pc->customdata); - } - else { - pc->draw(C, win->eventstate->x, win->eventstate->y, pc->customdata); - } + if ((pc->region_type != RGN_TYPE_ANY) && (region->regiontype != pc->region_type)) { + continue; + } - GPU_scissor_test(false); + if (pc->poll == NULL || pc->poll(C)) { + /* Prevent drawing outside region. */ + GPU_scissor_test(true); + GPU_scissor(region->winrct.xmin, + region->winrct.ymin, + BLI_rcti_size_x(®ion->winrct) + 1, + BLI_rcti_size_y(®ion->winrct) + 1); + + if (ELEM(win->grabcursor, GHOST_kGrabWrap, GHOST_kGrabHide)) { + int x = 0, y = 0; + wm_get_cursor_position(win, &x, &y); + pc->draw(C, x, y, pc->customdata); + } + else { + pc->draw(C, win->eventstate->x, win->eventstate->y, pc->customdata); } + + GPU_scissor_test(false); } } } @@ -960,10 +960,9 @@ static bool wm_draw_update_test_window(Main *bmain, bContext *C, wmWindow *win) ViewLayer *view_layer = WM_window_get_active_view_layer(win); struct Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer); bScreen *screen = WM_window_get_active_screen(win); - ARegion *region; bool do_draw = false; - for (region = screen->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &screen->regionbase) { if (region->do_draw_paintcursor) { screen->do_draw_paintcursor = true; region->do_draw_paintcursor = false; @@ -974,7 +973,7 @@ static bool wm_draw_update_test_window(Main *bmain, bContext *C, wmWindow *win) } ED_screen_areas_iter (win, screen, area) { - for (region = area->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { wm_region_test_gizmo_do_draw(C, area, region, true); wm_region_test_render_do_draw(scene, depsgraph, area, region); #ifdef WITH_XR_OPENXR @@ -1043,12 +1042,11 @@ void wm_draw_update(bContext *C) { Main *bmain = CTX_data_main(C); wmWindowManager *wm = CTX_wm_manager(C); - wmWindow *win; GPU_context_main_lock(); BKE_image_free_unused_gpu_textures(); - for (win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { #ifdef WIN32 GHOST_TWindowState state = GHOST_GetWindowState(win->ghostwin); diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 2a8b102a369..07d5ffa1b82 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -174,7 +174,6 @@ void wm_event_free(wmEvent *event) void wm_event_free_all(wmWindow *win) { wmEvent *event; - while ((event = BLI_pophead(&win->queue))) { wm_event_free(event); } @@ -205,13 +204,11 @@ static bool wm_test_duplicate_notifier(const wmWindowManager *wm, uint type, voi void WM_event_add_notifier_ex(wmWindowManager *wm, const wmWindow *win, uint type, void *reference) { - wmNotifier *note; - if (wm_test_duplicate_notifier(wm, type, reference)) { return; } - note = MEM_callocN(sizeof(wmNotifier), "notifier"); + wmNotifier *note = MEM_callocN(sizeof(wmNotifier), "notifier"); BLI_addtail(&wm->queue, note); @@ -235,13 +232,12 @@ void WM_main_add_notifier(unsigned int type, void *reference) { Main *bmain = G_MAIN; wmWindowManager *wm = bmain->wm.first; - wmNotifier *note; if (!wm || wm_test_duplicate_notifier(wm, type, reference)) { return; } - note = MEM_callocN(sizeof(wmNotifier), "notifier"); + wmNotifier *note = MEM_callocN(sizeof(wmNotifier), "notifier"); BLI_addtail(&wm->queue, note); @@ -262,11 +258,7 @@ void WM_main_remove_notifier_reference(const void *reference) wmWindowManager *wm = bmain->wm.first; if (wm) { - wmNotifier *note, *note_next; - - for (note = wm->queue.first; note; note = note_next) { - note_next = note->next; - + LISTBASE_FOREACH_MUTABLE (wmNotifier *, note, &wm->queue) { if (note->reference == reference) { /* Don't remove because this causes problems for #wm_event_do_notifiers * which may be looping on the data (deleting screens). */ @@ -286,15 +278,10 @@ void WM_main_remove_notifier_reference(const void *reference) void WM_main_remap_editor_id_reference(ID *old_id, ID *new_id) { Main *bmain = G_MAIN; - bScreen *screen; - - for (screen = bmain->screens.first; screen; screen = screen->id.next) { - ScrArea *area; - for (area = screen->areabase.first; area; area = area->next) { - SpaceLink *sl; - - for (sl = area->spacedata.first; sl; sl = sl->next) { + LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { ED_spacedata_id_remap(area, sl, old_id, new_id); } } @@ -406,9 +393,6 @@ static void wm_event_execute_timers(bContext *C) /* Called in mainloop. */ void wm_event_do_notifiers(bContext *C) { - wmNotifier *note, *next; - wmWindow *win; - /* Run the timer before assigning 'wm' in the unlikely case a timer loads a file, see T80028. */ wm_event_execute_timers(C); @@ -420,15 +404,13 @@ void wm_event_do_notifiers(bContext *C) /* Disable? - Keep for now since its used for window level notifiers. */ #if 1 /* Cache & catch WM level notifiers, such as frame change, scene/screen set. */ - for (win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { Scene *scene = WM_window_get_active_scene(win); bool do_anim = false; CTX_wm_window_set(C, win); - for (note = wm->queue.first; note; note = next) { - next = note->next; - + LISTBASE_FOREACH_MUTABLE (wmNotifier *, note, &wm->queue) { if (note->category == NC_WM) { if (ELEM(note->data, ND_FILEREAD, ND_FILESAVE)) { wm->file_saved = 1; @@ -510,8 +492,9 @@ void wm_event_do_notifiers(bContext *C) } /* The notifiers are sent without context, to keep it clean. */ + wmNotifier *note; while ((note = BLI_pophead(&wm->queue))) { - for (win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { Scene *scene = WM_window_get_active_scene(win); bScreen *screen = WM_window_get_active_screen(win); WorkSpace *workspace = WM_window_get_active_workspace(win); @@ -557,7 +540,7 @@ void wm_event_do_notifiers(bContext *C) /* Handle message bus. */ { - for (win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { CTX_wm_window_set(C, win); WM_msgbus_handle(wm->message_bus, C); } @@ -568,7 +551,7 @@ void wm_event_do_notifiers(bContext *C) /* Status bar */ if (wm->winactive) { - win = wm->winactive; + wmWindow *win = wm->winactive; CTX_wm_window_set(C, win); WM_window_cursor_keymap_status_refresh(C, win); CTX_wm_window_set(C, NULL); @@ -600,7 +583,6 @@ static int wm_handler_ui_call(bContext *C, ARegion *menu = CTX_wm_menu(C); static bool do_wheel_ui = true; const bool is_wheel = ELEM(event->type, WHEELUPMOUSE, WHEELDOWNMOUSE, MOUSEPAN); - int retval; /* UI code doesn't handle return values - it just always returns break. * to make the DBL_CLICK conversion work, we just don't send this to UI, except mouse clicks. */ @@ -637,7 +619,7 @@ static int wm_handler_ui_call(bContext *C, CTX_wm_menu_set(C, handler->context.menu); } - retval = handler->handle_fn(C, event, handler->user_data); + int retval = handler->handle_fn(C, event, handler->user_data); /* putting back screen context */ if ((retval != WM_UI_HANDLER_BREAK) || always_pass) { @@ -708,7 +690,6 @@ void WM_report_banner_show(void) { wmWindowManager *wm = G_MAIN->wm.first; ReportList *wm_reports = &wm->reports; - ReportTimerInfo *rti; /* After adding reports to the global list, reset the report timer. */ WM_event_remove_timer(wm, NULL, wm_reports->reporttimer); @@ -716,7 +697,7 @@ void WM_report_banner_show(void) /* Records time since last report was added */ wm_reports->reporttimer = WM_event_add_timer(wm, wm->winactive, TIMERREPORT, 0.05); - rti = MEM_callocN(sizeof(ReportTimerInfo), "ReportTimerInfo"); + ReportTimerInfo *rti = MEM_callocN(sizeof(ReportTimerInfo), "ReportTimerInfo"); wm_reports->reporttimer->customdata = rti; } @@ -753,7 +734,6 @@ static void wm_add_reports(ReportList *reports) void WM_report(ReportType type, const char *message) { ReportList reports; - BKE_reports_init(&reports, RPT_STORE); BKE_report(&reports, type, message); @@ -764,10 +744,9 @@ void WM_report(ReportType type, const char *message) void WM_reportf(ReportType type, const char *format, ...) { - DynStr *ds; va_list args; - ds = BLI_dynstr_new(); + DynStr *ds = BLI_dynstr_new(); va_start(args, format); BLI_dynstr_vappendf(ds, format, args); va_end(args); @@ -787,10 +766,9 @@ void WM_reportf(ReportType type, const char *format, ...) bool WM_operator_poll(bContext *C, wmOperatorType *ot) { - wmOperatorTypeMacro *otmacro; - for (otmacro = ot->macro.first; otmacro; otmacro = otmacro->next) { - wmOperatorType *ot_macro = WM_operatortype_find(otmacro->idname, 0); + LISTBASE_FOREACH (wmOperatorTypeMacro *, macro, &ot->macro) { + wmOperatorType *ot_macro = WM_operatortype_find(macro->idname, 0); if (0 == WM_operator_poll(C, ot_macro)) { return 0; @@ -818,9 +796,8 @@ bool WM_operator_check_ui_empty(wmOperatorType *ot) { if (ot->macro.first != NULL) { /* For macros, check all have exec() we can call. */ - wmOperatorTypeMacro *otmacro; - for (otmacro = ot->macro.first; otmacro; otmacro = otmacro->next) { - wmOperatorType *otm = WM_operatortype_find(otmacro->idname, 0); + LISTBASE_FOREACH (wmOperatorTypeMacro *, macro, &ot->macro) { + wmOperatorType *otm = WM_operatortype_find(macro->idname, 0); if (otm && !WM_operator_check_ui_empty(otm)) { return false; } @@ -1116,9 +1093,8 @@ bool WM_operator_repeat_check(const bContext *UNUSED(C), wmOperator *op) } if (op->opm) { /* for macros, check all have exec() we can call */ - wmOperatorTypeMacro *otmacro; - for (otmacro = op->opm->type->macro.first; otmacro; otmacro = otmacro->next) { - wmOperatorType *otm = WM_operatortype_find(otmacro->idname, 0); + LISTBASE_FOREACH (wmOperatorTypeMacro *, macro, &op->opm->type->macro) { + wmOperatorType *otm = WM_operatortype_find(macro->idname, 0); if (otm && otm->exec == NULL) { return false; } @@ -1178,7 +1154,6 @@ static wmOperator *wm_operator_create(wmWindowManager *wm, /* Recursive filling of operator macro list. */ if (ot->macro.first) { static wmOperator *motherop = NULL; - wmOperatorTypeMacro *otmacro; int root = 0; /* Ensure all ops are in execution order in 1 list. */ @@ -1189,7 +1164,7 @@ static wmOperator *wm_operator_create(wmWindowManager *wm, /* If properties exist, it will contain everything needed. */ if (properties) { - otmacro = ot->macro.first; + wmOperatorTypeMacro *otmacro = ot->macro.first; RNA_STRUCT_BEGIN (properties, prop) { @@ -1214,9 +1189,9 @@ static wmOperator *wm_operator_create(wmWindowManager *wm, RNA_STRUCT_END; } else { - for (otmacro = ot->macro.first; otmacro; otmacro = otmacro->next) { - wmOperatorType *otm = WM_operatortype_find(otmacro->idname, 0); - wmOperator *opm = wm_operator_create(wm, otm, otmacro->ptr, NULL); + LISTBASE_FOREACH (wmOperatorTypeMacro *, macro, &op->opm->type->macro) { + wmOperatorType *otm = WM_operatortype_find(macro->idname, 0); + wmOperator *opm = wm_operator_create(wm, otm, macro->ptr, NULL); BLI_addtail(&motherop->macro, opm); opm->opm = motherop; /* Pointer to mom, for modal(). */ @@ -1678,56 +1653,58 @@ static void wm_handler_op_context(bContext *C, wmEventHandler_Op *handler, const * possible. */ bScreen *screen = handler->context.win ? WM_window_get_active_screen(win) : CTX_wm_screen(C); - if (screen && handler->op) { - if (handler->context.area == NULL) { - CTX_wm_area_set(C, NULL); + if (screen == NULL || handler->op == NULL) { + return; + } + + if (handler->context.area == NULL) { + CTX_wm_area_set(C, NULL); + } + else { + ScrArea *area = NULL; + + ED_screen_areas_iter (win, screen, area_iter) { + if (area_iter == handler->context.area) { + area = area_iter; + break; + } } - else { - ScrArea *area = NULL; - ED_screen_areas_iter (win, screen, area_iter) { - if (area_iter == handler->context.area) { - area = area_iter; - break; - } + if (area == NULL) { + /* When changing screen layouts with running modal handlers (like render display), this + * is not an error to print. */ + if (handler->op == NULL) { + CLOG_ERROR(WM_LOG_HANDLERS, + "internal error: handler (%s) has invalid area", + handler->op->type->idname); } + } + else { + ARegion *region; + wmOperator *op = handler->op ? (handler->op->opm ? handler->op->opm : handler->op) : NULL; + CTX_wm_area_set(C, area); - if (area == NULL) { - /* When changing screen layouts with running modal handlers (like render display), this - * is not an error to print. */ - if (handler->op == NULL) { - CLOG_ERROR(WM_LOG_HANDLERS, - "internal error: handler (%s) has invalid area", - handler->op->type->idname); + if (op && (op->flag & OP_IS_MODAL_CURSOR_REGION)) { + region = BKE_area_find_region_xy(area, handler->context.region_type, event->x, event->y); + if (region) { + handler->context.region = region; } } else { - ARegion *region; - wmOperator *op = handler->op ? (handler->op->opm ? handler->op->opm : handler->op) : NULL; - CTX_wm_area_set(C, area); - - if (op && (op->flag & OP_IS_MODAL_CURSOR_REGION)) { - region = BKE_area_find_region_xy(area, handler->context.region_type, event->x, event->y); - if (region) { - handler->context.region = region; - } - } - else { - region = NULL; - } + region = NULL; + } - if (region == NULL) { - for (region = area->regionbase.first; region; region = region->next) { - if (region == handler->context.region) { - break; - } + if (region == NULL) { + for (region = area->regionbase.first; region; region = region->next) { + if (region == handler->context.region) { + break; } } + } - /* XXX no warning print here, after full-area and back regions are remade. */ - if (region) { - CTX_wm_region_set(C, region); - } + /* XXX no warning print here, after full-area and back regions are remade. */ + if (region) { + CTX_wm_region_set(C, region); } } } @@ -1736,10 +1713,10 @@ static void wm_handler_op_context(bContext *C, wmEventHandler_Op *handler, const /* Called on exit or remove area, only here call cancel callback. */ void WM_event_remove_handlers(bContext *C, ListBase *handlers) { - wmEventHandler *handler_base; wmWindowManager *wm = CTX_wm_manager(C); /* C is zero on freeing database, modal handlers then already were freed */ + wmEventHandler *handler_base; while ((handler_base = BLI_pophead(handlers))) { BLI_assert(handler_base->type != 0); if (handler_base->type == WM_HANDLER_TYPE_OP) { @@ -2759,14 +2736,11 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers else if (handler_base->type == WM_HANDLER_TYPE_DROPBOX) { wmEventHandler_Dropbox *handler = (wmEventHandler_Dropbox *)handler_base; if (!wm->is_interface_locked && event->type == EVT_DROP) { - wmDropBox *drop = handler->dropboxes->first; - for (; drop; drop = drop->next) { + LISTBASE_FOREACH (wmDropBox *, drop, handler->dropboxes) { /* Other drop custom types allowed. */ if (event->custom == EVT_DATA_DRAGDROP) { ListBase *lb = (ListBase *)event->customdata; - wmDrag *drag; - - for (drag = lb->first; drag; drag = drag->next) { + LISTBASE_FOREACH (wmDrag *, drag, lb) { const char *tooltip = NULL; if (drop->poll(C, drag, event, &tooltip)) { /* Optionally copy drag information to operator properties. */ @@ -2861,7 +2835,7 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers #undef PRINT -/* Yhis calls handlers twice - to solve (double-)click events. */ +/* This calls handlers twice - to solve (double-)click events. */ static int wm_handlers_do(bContext *C, wmEvent *event, ListBase *handlers) { int action = wm_handlers_do_intern(C, event, handlers); @@ -3041,10 +3015,9 @@ static ARegion *region_event_inside(bContext *C, const int xy[2]) { bScreen *screen = CTX_wm_screen(C); ScrArea *area = CTX_wm_area(C); - ARegion *region; if (screen && area) { - for (region = area->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { if (BLI_rcti_isect_pt_v(®ion->winrct, xy)) { return region; } @@ -3176,15 +3149,13 @@ static void wm_event_free_and_remove_from_queue_if_valid(wmEvent *event) void wm_event_do_handlers(bContext *C) { wmWindowManager *wm = CTX_wm_manager(C); - wmWindow *win; /* Update key configuration before handling events. */ WM_keyconfig_update(wm); WM_gizmoconfig_update(CTX_data_main(C)); - for (win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { bScreen *screen = WM_window_get_active_screen(win); - wmEvent *event; /* Some safety checks - these should always be set! */ BLI_assert(WM_window_get_active_scene(win)); @@ -3244,6 +3215,7 @@ void wm_event_do_handlers(bContext *C) } } + wmEvent *event; while ((event = win->queue.first)) { int action = WM_HANDLER_CONTINUE; @@ -3312,8 +3284,6 @@ void wm_event_do_handlers(bContext *C) wm_tweakevent_test(C, event, action); if ((action & WM_HANDLER_BREAK) == 0) { - ARegion *region; - /* Note: setting subwin active should be done here, after modal handlers have been done */ if (event->type == MOUSEMOVE) { /* State variables in screen, cursors. @@ -3347,7 +3317,7 @@ void wm_event_do_handlers(bContext *C) CTX_wm_area_set(C, area); if ((action & WM_HANDLER_BREAK) == 0) { - for (region = area->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { if (wm_event_inside_region(event, region)) { CTX_wm_region_set(C, region); @@ -3452,9 +3422,7 @@ void wm_event_do_handlers(bContext *C) void WM_event_fileselect_event(wmWindowManager *wm, void *ophandle, int eventval) { /* Add to all windows! */ - wmWindow *win; - - for (win = wm->windows.first; win; win = win->next) { + LISTBASE_FOREACH (wmWindow *, win, &wm->windows) { wmEvent event = *win->eventstate; event.type = EVT_FILESELECT; @@ -4267,18 +4235,16 @@ static wmWindow *wm_event_cursor_other_windows(wmWindowManager *wm, wmWindow *wi /* check if outside, include top window bar... */ if (mval[0] < 0 || mval[1] < 0 || mval[0] > WM_window_pixels_x(win) || mval[1] > WM_window_pixels_y(win) + 30) { - wmWindow *owin; - wmEventHandler *handler; - /* Let's skip windows having modal handlers now */ /* potential XXX ugly... I wouldn't have added a modalhandlers list * (introduced in rev 23331, ton). */ - for (handler = win->modalhandlers.first; handler; handler = handler->next) { + LISTBASE_FOREACH (wmEventHandler *, handler, &win->modalhandlers) { if (ELEM(handler->type, WM_HANDLER_TYPE_UI, WM_HANDLER_TYPE_OP)) { return NULL; } } + wmWindow *owin; if (WM_window_find_under_cursor(wm, win, win, mval, &owin, mval)) { event->x = mval[0]; event->y = mval[1]; @@ -4329,8 +4295,6 @@ static wmEvent *wm_event_add_mousemove(wmWindow *win, const wmEvent *event) /* Time is in 1000s of seconds, from Ghost. */ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void *customdata) { - wmWindow *owin; - if (UNLIKELY(G.f & G_FLAG_EVENT_SIMULATE)) { return; } @@ -4371,7 +4335,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void /* Also add to other window if event is there, this makes overdraws disappear nicely. */ /* It remaps mousecoord to other window in event. */ - owin = wm_event_cursor_other_windows(wm, win, &event); + wmWindow *owin = wm_event_cursor_other_windows(wm, win, &event); if (owin) { wmEvent oevent, *oevt = owin->eventstate; @@ -4476,7 +4440,7 @@ void wm_event_add_ghostevent(wmWindowManager *wm, wmWindow *win, int type, void } /* Add to other window if event is there (not to both!). */ - owin = wm_event_cursor_other_windows(wm, win, &event); + wmWindow *owin = wm_event_cursor_other_windows(wm, win, &event); if (owin) { wmEvent oevent = *(owin->eventstate); diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index f802b8f9746..c51086c5f0a 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -235,8 +235,6 @@ char *WM_operator_pystring_ex(bContext *C, /* for building the string */ DynStr *dynstr = BLI_dynstr_new(); - char *cstring; - char *cstring_args; /* arbitrary, but can get huge string with stroke painting otherwise */ int max_prop_length = 10; @@ -259,7 +257,7 @@ char *WM_operator_pystring_ex(bContext *C, opmptr = &opmptr_default; } - cstring_args = RNA_pointer_as_string_id(C, opmptr); + char *cstring_args = RNA_pointer_as_string_id(C, opmptr); if (first_op) { BLI_dynstr_appendf(dynstr, "%s=%s", opm->type->idname, cstring_args); first_op = false; @@ -284,7 +282,7 @@ char *WM_operator_pystring_ex(bContext *C, opptr = &opptr_default; } - cstring_args = RNA_pointer_as_string_keywords( + char *cstring_args = RNA_pointer_as_string_keywords( C, opptr, false, all_args, macro_args_test, max_prop_length); BLI_dynstr_append(dynstr, cstring_args); MEM_freeN(cstring_args); @@ -296,7 +294,7 @@ char *WM_operator_pystring_ex(bContext *C, BLI_dynstr_append(dynstr, ")"); - cstring = BLI_dynstr_get_cstring(dynstr); + char *cstring = BLI_dynstr_get_cstring(dynstr); BLI_dynstr_free(dynstr); return cstring; } @@ -559,9 +557,7 @@ const char *WM_context_member_from_ptr(bContext *C, const PointerRNA *ptr) char *WM_prop_pystring_assign(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index) { - char *lhs, *rhs, *ret; - - lhs = C ? wm_prop_pystring_from_context(C, ptr, prop, index) : NULL; + char *lhs = C ? wm_prop_pystring_from_context(C, ptr, prop, index) : NULL; if (lhs == NULL) { /* fallback to bpy.data.foo[id] if we dont find in the context */ @@ -572,13 +568,13 @@ char *WM_prop_pystring_assign(bContext *C, PointerRNA *ptr, PropertyRNA *prop, i return NULL; } - rhs = RNA_property_as_string(C, ptr, prop, index, INT_MAX); + char *rhs = RNA_property_as_string(C, ptr, prop, index, INT_MAX); if (!rhs) { MEM_freeN(lhs); return NULL; } - ret = BLI_sprintfN("%s = %s", lhs, rhs); + char *ret = BLI_sprintfN("%s = %s", lhs, rhs); MEM_freeN(lhs); MEM_freeN(rhs); return ret; @@ -686,8 +682,7 @@ bool WM_operator_properties_default(PointerRNA *ptr, const bool do_update) void WM_operator_properties_reset(wmOperator *op) { if (op->ptr->data) { - PropertyRNA *iterprop; - iterprop = RNA_struct_iterator_property(op->type->srna); + PropertyRNA *iterprop = RNA_struct_iterator_property(op->type->srna); RNA_PROP_BEGIN (op->ptr, itemptr, iterprop) { PropertyRNA *prop = itemptr.data; @@ -733,11 +728,10 @@ static bool operator_last_properties_init_impl(wmOperator *op, IDProperty *last_ bool changed = false; IDPropertyTemplate val = {0}; IDProperty *replaceprops = IDP_New(IDP_GROUP, &val, "wmOperatorProperties"); - PropertyRNA *iterprop; CLOG_INFO(WM_LOG_OPERATORS, 1, "loading previous properties for '%s'", op->type->idname); - iterprop = RNA_struct_iterator_property(op->type->srna); + PropertyRNA *iterprop = RNA_struct_iterator_property(op->type->srna); RNA_PROP_BEGIN (op->ptr, itemptr, iterprop) { PropertyRNA *prop = itemptr.data; @@ -846,9 +840,7 @@ int WM_generic_select_modal(bContext *C, wmOperator *op, const wmEvent *event) int ret_value = 0; /* get settings from RNA properties for operator */ - int mval[2]; - mval[0] = RNA_int_get(op->ptr, "mouse_x"); - mval[1] = RNA_int_get(op->ptr, "mouse_y"); + const int mval[2] = {RNA_int_get(op->ptr, "mouse_x"), RNA_int_get(op->ptr, "mouse_y")}; if (init_event_type == 0) { if (event->val == KM_PRESS) { @@ -955,8 +947,6 @@ int WM_operator_smooth_viewtx_get(const wmOperator *op) int WM_menu_invoke_ex(bContext *C, wmOperator *op, int opcontext) { PropertyRNA *prop = op->type->prop; - uiPopupMenu *pup; - uiLayout *layout; if (prop == NULL) { CLOG_ERROR(WM_LOG_OPERATORS, "'%s' has no enum property set", op->type->idname); @@ -973,8 +963,8 @@ int WM_menu_invoke_ex(bContext *C, wmOperator *op, int opcontext) return retval; } else { - pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE); - layout = UI_popup_menu_layout(pup); + uiPopupMenu *pup = UI_popup_menu_begin(C, WM_operatortype_name(op->type, op->ptr), ICON_NONE); + uiLayout *layout = UI_popup_menu_layout(pup); /* set this so the default execution context is the same as submenus */ uiLayoutSetOperatorContext(layout, opcontext); uiItemsFullEnumO( @@ -1011,10 +1001,8 @@ static uiBlock *wm_enum_search_menu(bContext *C, ARegion *region, void *arg) const int height = search_menu->use_previews ? 5 * U.widget_unit * search_menu->prv_rows : UI_searchbox_size_y(); static char search[256] = ""; - uiBlock *block; - uiBut *but; - 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_MOVEMOUSE_QUIT | UI_BLOCK_SEARCH_MENU); UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); @@ -1037,20 +1025,20 @@ static uiBlock *wm_enum_search_menu(bContext *C, ARegion *region, void *arg) 0, ""); #endif - but = uiDefSearchButO_ptr(block, - op->type, - op->ptr->data, - search, - 0, - ICON_VIEWZOOM, - sizeof(search), - 10, - 10, - width, - UI_UNIT_Y, - search_menu->prv_rows, - search_menu->prv_cols, - ""); + uiBut *but = uiDefSearchButO_ptr(block, + op->type, + op->ptr->data, + search, + 0, + ICON_VIEWZOOM, + sizeof(search), + 10, + 10, + width, + UI_UNIT_Y, + search_menu->prv_rows, + search_menu->prv_cols, + ""); /* fake button, it holds space for search items */ uiDefBut(block, @@ -1110,8 +1098,6 @@ int WM_operator_confirm_message_ex(bContext *C, const char *message, const short opcontext) { - uiPopupMenu *pup; - uiLayout *layout; IDProperty *properties = op->ptr->data; if (properties && properties->len) { @@ -1121,8 +1107,8 @@ int WM_operator_confirm_message_ex(bContext *C, properties = NULL; } - pup = UI_popup_menu_begin(C, title, icon); - layout = UI_popup_menu_layout(pup); + uiPopupMenu *pup = UI_popup_menu_begin(C, title, icon); + uiLayout *layout = UI_popup_menu_layout(pup); uiItemFullO_ptr(layout, op->type, message, ICON_NONE, properties, opcontext, 0, NULL); UI_popup_menu_end(C, pup); @@ -1161,10 +1147,9 @@ int WM_operator_filesel(bContext *C, wmOperator *op, const wmEvent *UNUSED(event bool WM_operator_filesel_ensure_ext_imtype(wmOperator *op, const struct ImageFormatData *im_format) { - PropertyRNA *prop; char filepath[FILE_MAX]; /* dont NULL check prop, this can only run on ops with a 'filepath' */ - prop = RNA_struct_find_property(op->ptr, "filepath"); + PropertyRNA *prop = RNA_struct_find_property(op->ptr, "filepath"); RNA_property_string_get(op->ptr, prop, filepath); if (BKE_image_path_ensure_ext_from_imformat(filepath, im_format)) { RNA_property_string_set(op->ptr, prop, filepath); @@ -1196,16 +1181,15 @@ bool WM_operator_check_ui_enabled(const bContext *C, const char *idname) wmOperator *WM_operator_last_redo(const bContext *C) { wmWindowManager *wm = CTX_wm_manager(C); - wmOperator *op; /* only for operators that are registered and did an undo push */ - for (op = wm->operators.last; op; op = op->prev) { + LISTBASE_FOREACH_BACKWARD (wmOperator *, op, &wm->operators) { if ((op->type->flag & OPTYPE_REGISTER) && (op->type->flag & OPTYPE_UNDO)) { - break; + return op; } } - return op; + return NULL; } IDProperty *WM_operator_last_properties_ensure_idprops(wmOperatorType *ot) @@ -1313,12 +1297,10 @@ static void wm_block_redo_cancel_cb(bContext *C, void *arg_op) static uiBlock *wm_block_create_redo(bContext *C, ARegion *region, void *arg_op) { wmOperator *op = arg_op; - uiBlock *block; - uiLayout *layout; const uiStyle *style = UI_style_get_dpi(); int width = 15 * UI_UNIT_X; - block = UI_block_begin(C, region, __func__, UI_EMBOSS); + uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS); UI_block_flag_disable(block, UI_BLOCK_LOOP); UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_REGULAR); @@ -1330,7 +1312,7 @@ static uiBlock *wm_block_create_redo(bContext *C, ARegion *region, void *arg_op) BLI_assert(op->type->flag & OPTYPE_REGISTER); UI_block_func_handle_set(block, wm_block_redo_cb, arg_op); - layout = UI_block_layout( + uiLayout *layout = UI_block_layout( block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, width, UI_UNIT_Y, 0, style); if (op == WM_operator_last_redo(C)) { @@ -1386,11 +1368,9 @@ static uiBlock *wm_block_dialog_create(bContext *C, ARegion *region, void *userD { wmOpPopUp *data = userData; wmOperator *op = data->op; - uiBlock *block; - uiLayout *layout; const uiStyle *style = UI_style_get_dpi(); - block = UI_block_begin(C, region, __func__, UI_EMBOSS); + uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS); UI_block_flag_disable(block, UI_BLOCK_LOOP); UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_REGULAR); @@ -1398,7 +1378,7 @@ static uiBlock *wm_block_dialog_create(bContext *C, ARegion *region, void *userD * where quitting by accident is very annoying */ UI_block_flag_enable(block, UI_BLOCK_KEEP_OPEN | UI_BLOCK_NUMSELECT); - layout = UI_block_layout( + uiLayout *layout = UI_block_layout( block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, data->width, data->height, 0, style); uiTemplateOperatorPropertyButs( @@ -1409,17 +1389,13 @@ static uiBlock *wm_block_dialog_create(bContext *C, ARegion *region, void *userD /* new column so as not to interfere with custom layouts T26436. */ { - uiBlock *col_block; - uiLayout *col; - uiBut *btn; - - col = uiLayoutColumn(layout, false); - col_block = uiLayoutGetBlock(col); + uiLayout *col = uiLayoutColumn(layout, false); + uiBlock *col_block = uiLayoutGetBlock(col); /* Create OK button, the callback of which will execute op */ - btn = uiDefBut( + uiBut *but = uiDefBut( col_block, UI_BTYPE_BUT, 0, IFACE_("OK"), 0, -30, 0, UI_UNIT_Y, NULL, 0, 0, 0, 0, ""); - UI_but_flag_enable(btn, UI_BUT_ACTIVE_DEFAULT); - UI_but_func_set(btn, dialog_exec_cb, data, col_block); + UI_but_flag_enable(but, UI_BUT_ACTIVE_DEFAULT); + UI_but_func_set(but, dialog_exec_cb, data, col_block); } /* center around the mouse */ @@ -1435,16 +1411,14 @@ static uiBlock *wm_operator_ui_create(bContext *C, ARegion *region, void *userDa { wmOpPopUp *data = userData; wmOperator *op = data->op; - uiBlock *block; - uiLayout *layout; const uiStyle *style = UI_style_get_dpi(); - block = UI_block_begin(C, region, __func__, UI_EMBOSS); + uiBlock *block = UI_block_begin(C, region, __func__, UI_EMBOSS); UI_block_flag_disable(block, UI_BLOCK_LOOP); UI_block_flag_enable(block, UI_BLOCK_KEEP_OPEN | UI_BLOCK_MOVEMOUSE_QUIT); UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_REGULAR); - layout = UI_block_layout( + uiLayout *layout = UI_block_layout( block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, data->width, data->height, 0, style); /* since ui is defined the auto-layout args are not used */ @@ -1689,25 +1663,23 @@ static uiBlock *wm_block_search_menu(bContext *C, ARegion *region, void *userdat { const struct SearchPopupInit_Data *init_data = userdata; static char search[256] = ""; - uiBlock *block; - uiBut *but; - 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_MOVEMOUSE_QUIT | UI_BLOCK_SEARCH_MENU); UI_block_theme_style_set(block, UI_BLOCK_THEME_STYLE_POPUP); - but = uiDefSearchBut(block, - search, - 0, - ICON_VIEWZOOM, - sizeof(search), - 10, - 10, - init_data->size[0], - UI_UNIT_Y, - 0, - 0, - ""); + uiBut *but = uiDefSearchBut(block, + search, + 0, + ICON_VIEWZOOM, + sizeof(search), + 10, + 10, + init_data->size[0], + UI_UNIT_Y, + 0, + 0, + ""); if (init_data->search_type == SEARCH_TYPE_OPERATOR) { UI_but_func_operator_search(but); @@ -2233,10 +2205,9 @@ static void radial_control_set_tex(RadialControl *rc) static void radial_control_paint_tex(RadialControl *rc, float radius, float alpha) { - float col[3] = {0, 0, 0}; - float rot; /* set fill color */ + float col[3] = {0, 0, 0}; if (rc->fill_col_prop) { PointerRNA *fill_ptr; PropertyRNA *fill_prop; @@ -2262,7 +2233,7 @@ static void radial_control_paint_tex(RadialControl *rc, float radius, float alph /* set up rotation if available */ if (rc->rot_prop) { - rot = RNA_property_float_get(&rc->rot_ptr, rc->rot_prop); + float rot = RNA_property_float_get(&rc->rot_ptr, rc->rot_prop); GPU_matrix_push(); GPU_matrix_rotate_2d(RAD2DEGF(rot)); } @@ -2493,8 +2464,6 @@ static int radial_control_get_path(PointerRNA *ctx_ptr, RCPropFlags flags) { PropertyRNA *unused_prop; - int len; - char *str; /* check flags */ if ((flags & RC_PROP_REQUIRE_BOOL) && (flags & RC_PROP_REQUIRE_FLOAT)) { @@ -2503,6 +2472,7 @@ static int radial_control_get_path(PointerRNA *ctx_ptr, } /* get an rna string path from the operator's properties */ + char *str; if (!(str = RNA_string_get_alloc(op->ptr, name, NULL, 0))) { return 1; } @@ -2542,6 +2512,7 @@ static int radial_control_get_path(PointerRNA *ctx_ptr, } /* check property's array length */ + int len; if (*r_prop && (len = RNA_property_array_length(r_ptr, *r_prop)) != req_length) { MEM_freeN(str); BKE_reportf(op->reports, @@ -2562,13 +2533,13 @@ static int radial_control_get_path(PointerRNA *ctx_ptr, static int radial_control_get_properties(bContext *C, wmOperator *op) { RadialControl *rc = op->customdata; - PointerRNA ctx_ptr, use_secondary_ptr; - PropertyRNA *use_secondary_prop = NULL; - const char *data_path; + PointerRNA ctx_ptr; RNA_pointer_create(NULL, &RNA_Context, C, &ctx_ptr); /* check if we use primary or secondary path */ + PointerRNA use_secondary_ptr; + PropertyRNA *use_secondary_prop = NULL; if (!radial_control_get_path(&ctx_ptr, op, "use_secondary", @@ -2579,6 +2550,7 @@ static int radial_control_get_properties(bContext *C, wmOperator *op) return 0; } + const char *data_path; if (use_secondary_prop && RNA_property_boolean_get(&use_secondary_ptr, use_secondary_prop)) { data_path = "data_path_secondary"; } @@ -2798,14 +2770,13 @@ static int radial_control_modal(bContext *C, wmOperator *op, const wmEvent *even float new_value, dist = 0.0f, zoom[2]; float delta[2]; int ret = OPERATOR_RUNNING_MODAL; - bool snap; float angle_precision = 0.0f; const bool has_numInput = hasNumInput(&rc->num_input); bool handled = false; float numValue; /* TODO: fix hardcoded events */ - snap = event->ctrl != 0; + bool snap = event->ctrl != 0; /* Modal numinput active, try to handle numeric inputs first... */ if (event->val == KM_PRESS && has_numInput && handleNumInput(C, &rc->num_input, event)) { @@ -3115,10 +3086,11 @@ static void WM_OT_radial_control(wmOperatorType *ot) static void redraw_timer_window_swap(bContext *C) { wmWindow *win = CTX_wm_window(C); - ScrArea *area; + bScreen *screen = CTX_wm_screen(C); + CTX_wm_menu_set(C, NULL); - for (area = CTX_wm_screen(C)->areabase.first; area; area = area->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { ED_area_tag_redraw(area); } wm_draw_update(C); @@ -3171,16 +3143,12 @@ static void redraw_timer_step(bContext *C, } else if (type == eRTDrawWindow) { bScreen *screen = WM_window_get_active_screen(win); - ScrArea *area_iter; CTX_wm_menu_set(C, NULL); - for (area_iter = screen->areabase.first; area_iter; area_iter = area_iter->next) { - ARegion *region_iter; + LISTBASE_FOREACH (ScrArea *, area_iter, &screen->areabase) { CTX_wm_area_set(C, area_iter); - - for (region_iter = area_iter->regionbase.first; region_iter; - region_iter = region_iter->next) { + LISTBASE_FOREACH (ARegion *, region_iter, &area_iter->regionbase) { if (region_iter->visible) { CTX_wm_region_set(C, region_iter); wm_draw_region_test(C, area_iter, region_iter); @@ -3232,12 +3200,10 @@ static int redraw_timer_exec(bContext *C, wmOperator *op) ScrArea *area = CTX_wm_area(C); ARegion *region = CTX_wm_region(C); wmWindowManager *wm = CTX_wm_manager(C); - double time_start, time_delta; const int type = RNA_enum_get(op->ptr, "type"); const int iter = RNA_int_get(op->ptr, "iterations"); const double time_limit = (double)RNA_float_get(op->ptr, "time_limit"); const int cfra = scene->r.cfra; - int a, iter_steps = 0; const char *infostr = ""; /* NOTE: Depsgraph is used to update scene for a new state, so no need to ensure evaluation here. @@ -3246,11 +3212,12 @@ static int redraw_timer_exec(bContext *C, wmOperator *op) WM_cursor_wait(1); - time_start = PIL_check_seconds_timer(); + double time_start = PIL_check_seconds_timer(); wm_window_make_drawable(wm, win); - for (a = 0; a < iter; a++) { + int iter_steps = 0; + for (int a = 0; a < iter; a++) { redraw_timer_step(C, scene, depsgraph, win, area, region, type, cfra); iter_steps += 1; @@ -3262,7 +3229,7 @@ static int redraw_timer_exec(bContext *C, wmOperator *op) } } - time_delta = (PIL_check_seconds_timer() - time_start) * 1000; + double time_delta = (PIL_check_seconds_timer() - time_start) * 1000; RNA_enum_description(redraw_timer_type_items, type, &infostr); @@ -3377,20 +3344,17 @@ static int previews_ensure_exec(bContext *C, wmOperator *UNUSED(op)) ListBase *lb[] = { &bmain->materials, &bmain->textures, &bmain->images, &bmain->worlds, &bmain->lights, NULL}; PreviewsIDEnsureData preview_id_data; - Scene *scene; - ID *id; - int i; /* We use LIB_TAG_DOIT to check whether we have already handled a given ID or not. */ BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false); - for (i = 0; lb[i]; i++) { + for (int i = 0; lb[i]; i++) { BKE_main_id_tag_listbase(lb[i], LIB_TAG_DOIT, true); } preview_id_data.C = C; - for (scene = bmain->scenes.first; scene; scene = scene->id.next) { + LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { preview_id_data.scene = scene; - id = (ID *)scene; + ID *id = (ID *)scene; BKE_library_foreach_ID_link( NULL, id, previews_id_ensure_callback, &preview_id_data, IDWALK_RECURSE); @@ -3398,8 +3362,8 @@ static int previews_ensure_exec(bContext *C, wmOperator *UNUSED(op)) /* Check a last time for ID not used (fake users only, in theory), and * do our best for those, using current scene... */ - for (i = 0; lb[i]; i++) { - for (id = lb[i]->first; id; id = id->next) { + for (int i = 0; lb[i]; i++) { + LISTBASE_FOREACH (ID *, id, lb[i]) { if (id->tag & LIB_TAG_DOIT) { previews_id_ensure(C, NULL, id); id->tag &= ~LIB_TAG_DOIT; @@ -3512,11 +3476,10 @@ static int previews_clear_exec(bContext *C, wmOperator *op) &bmain->images, NULL, }; - int i; const int id_filters = preview_filter_to_idfilter(RNA_enum_get(op->ptr, "id_type")); - for (i = 0; lb[i]; i++) { + for (int i = 0; lb[i]; i++) { ID *id = lb[i]->first; if (!id) { continue; diff --git a/source/blender/windowmanager/intern/wm_panel_type.c b/source/blender/windowmanager/intern/wm_panel_type.c index 1d2fecd0de6..24508c377a6 100644 --- a/source/blender/windowmanager/intern/wm_panel_type.c +++ b/source/blender/windowmanager/intern/wm_panel_type.c @@ -41,10 +41,8 @@ static GHash *g_paneltypes_hash = NULL; PanelType *WM_paneltype_find(const char *idname, bool quiet) { - PanelType *pt; - if (idname[0]) { - pt = BLI_ghash_lookup(g_paneltypes_hash, idname); + PanelType *pt = BLI_ghash_lookup(g_paneltypes_hash, idname); if (pt) { return pt; } @@ -65,12 +63,10 @@ bool WM_paneltype_add(PanelType *pt) void WM_paneltype_remove(PanelType *pt) { - bool ok; - - ok = BLI_ghash_remove(g_paneltypes_hash, pt->idname, NULL, NULL); + const bool ok = BLI_ghash_remove(g_paneltypes_hash, pt->idname, NULL, NULL); BLI_assert(ok); - (void)ok; + UNUSED_VARS_NDEBUG(ok); } /* called on initialize WM_init() */ |