diff options
author | Hans Goudey <h.goudey@me.com> | 2021-01-19 02:28:47 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-01-19 02:28:47 +0300 |
commit | 09c7c638905230a608a9b0204b68c775cf71bf67 (patch) | |
tree | 4b21efd9b23283ef236e756f46e3f75f5d2e6c61 /source/blender/editors/screen/area.c | |
parent | 4b4aec288458dd24721fdd61af38d3c316c2520b (diff) |
UI Code Quality: Use "params" struct for area and region callbacks
These functions with many arguments can be unwieldy. Aside from the obvious issues
with rewriting the list of arguments and the opportunities for error and frustration
that presents, the long list of arguments make these systems hard to change. So when
an argument should be added, someone might skip that and add some hack instead.
So, as proposed in T73586#1037210, this patch instead uses a "params" struct for
each of these callbacks.
- Use param argument for `ARegionType.listener`
- Remove unused window field in region listener
- Use param argument for `SpaceType.listener`
- Use params struct for `ARegionType.message_subscribe`
Differential Revision: https://developer.blender.org/D9750
Diffstat (limited to 'source/blender/editors/screen/area.c')
-rw-r--r-- | source/blender/editors/screen/area.c | 72 |
1 files changed, 37 insertions, 35 deletions
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 581169d823e..24773ccbbee 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -141,13 +141,15 @@ void ED_region_pixelspace(ARegion *region) } /* only exported for WM */ -void ED_region_do_listen( - wmWindow *win, ScrArea *area, ARegion *region, wmNotifier *note, const Scene *scene) +void ED_region_do_listen(wmRegionListenerParams *params) { + ARegion *region = params->region; + wmNotifier *notifier = params->notifier; + /* generic notes first */ - switch (note->category) { + switch (notifier->category) { case NC_WM: - if (note->data == ND_FILEREAD) { + if (notifier->data == ND_FILEREAD) { ED_region_tag_redraw(region); } break; @@ -157,16 +159,16 @@ void ED_region_do_listen( } if (region->type && region->type->listener) { - region->type->listener(win, area, region, note, scene); + region->type->listener(params); } } /* only exported for WM */ -void ED_area_do_listen(wmWindow *win, ScrArea *area, wmNotifier *note, Scene *scene) +void ED_area_do_listen(wmSpaceTypeListenerParams *params) { /* no generic notes? */ - if (area->type && area->type->listener) { - area->type->listener(win, area, note, scene); + if (params->area->type && params->area->type->listener) { + params->area->type->listener(params); } } @@ -418,16 +420,13 @@ void ED_area_do_msg_notify_tag_refresh( ED_area_tag_refresh(area); } -void ED_area_do_mgs_subscribe_for_tool_header( - /* Follow ARegionType.message_subscribe */ - const struct bContext *UNUSED(C), - struct WorkSpace *workspace, - struct Scene *UNUSED(scene), - struct bScreen *UNUSED(screen), - struct ScrArea *UNUSED(area), - struct ARegion *region, - struct wmMsgBus *mbus) +/* Follow ARegionType.message_subscribe */ +void ED_area_do_mgs_subscribe_for_tool_header(wmRegionMessageSubscribeParams *params) { + struct wmMsgBus *mbus = params->message_bus; + WorkSpace *workspace = params->workspace; + ARegion *region = params->region; + BLI_assert(region->regiontype == RGN_TYPE_TOOL_HEADER); wmMsgSubscribeValue msg_sub_value_region_tag_redraw = { .owner = region, @@ -438,16 +437,12 @@ void ED_area_do_mgs_subscribe_for_tool_header( mbus, &workspace->id, workspace, WorkSpace, tools, &msg_sub_value_region_tag_redraw); } -void ED_area_do_mgs_subscribe_for_tool_ui( - /* Follow ARegionType.message_subscribe */ - const struct bContext *UNUSED(C), - struct WorkSpace *workspace, - struct Scene *UNUSED(scene), - struct bScreen *UNUSED(screen), - struct ScrArea *UNUSED(area), - struct ARegion *region, - struct wmMsgBus *mbus) +void ED_area_do_mgs_subscribe_for_tool_ui(wmRegionMessageSubscribeParams *params) { + struct wmMsgBus *mbus = params->message_bus; + WorkSpace *workspace = params->workspace; + ARegion *region = params->region; + BLI_assert(region->regiontype == RGN_TYPE_UI); const char *panel_category_tool = "Tool"; const char *category = UI_panel_category_active_get(region, false); @@ -634,7 +629,16 @@ void ED_region_do_draw(bContext *C, ARegion *region) WM_msg_subscribe_rna(mbus, &ptr, NULL, &msg_sub_value_region_tag_redraw, __func__); } - ED_region_message_subscribe(C, workspace, scene, screen, area, region, mbus); + wmRegionMessageSubscribeParams message_subscribe_params = { + .context = C, + .message_bus = mbus, + .workspace = workspace, + .scene = scene, + .screen = screen, + .area = area, + .region = region, + }; + ED_region_message_subscribe(&message_subscribe_params); } } @@ -4027,14 +4031,12 @@ void ED_region_cache_draw_cached_segments( /** * Generate subscriptions for this region. */ -void ED_region_message_subscribe(bContext *C, - struct WorkSpace *workspace, - struct Scene *scene, - struct bScreen *screen, - struct ScrArea *area, - struct ARegion *region, - struct wmMsgBus *mbus) +void ED_region_message_subscribe(wmRegionMessageSubscribeParams *params) { + ARegion *region = params->region; + const bContext *C = params->context; + struct wmMsgBus *mbus = params->message_bus; + if (region->gizmo_map != NULL) { WM_gizmomap_message_subscribe(C, region->gizmo_map, region, mbus); } @@ -4044,7 +4046,7 @@ void ED_region_message_subscribe(bContext *C, } if (region->type->message_subscribe != NULL) { - region->type->message_subscribe(C, workspace, scene, screen, area, region, mbus); + region->type->message_subscribe(params); } } |