[Bf-blender-cvs] [7447eb7e743] master: Cleanup: Miscellaneous improvements in wm directory
Hans Goudey
noreply at git.blender.org
Sat Oct 17 08:28:41 CEST 2020
Commit: 7447eb7e7430b924deab74b8541b3f56a540a6e9
Author: Hans Goudey
Date: Sat Oct 17 01:28:34 2020 -0500
Branches: master
https://developer.blender.org/rB7447eb7e7430b924deab74b8541b3f56a540a6e9
Cleanup: Miscellaneous improvements in wm directory
- Reduce variable scope.
- Use LISTBASE_FOREACH macros.
- Return early in some cases to reduce to reduce indentation.
===================================================================
M source/blender/windowmanager/intern/wm_dragdrop.c
M source/blender/windowmanager/intern/wm_draw.c
M source/blender/windowmanager/intern/wm_event_system.c
M source/blender/windowmanager/intern/wm_operators.c
M source/blender/windowmanager/intern/wm_panel_type.c
===================================================================
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
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list