diff options
-rw-r--r-- | source/blender/blenkernel/intern/screen.c | 217 |
1 files changed, 70 insertions, 147 deletions
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index f43bf3182c5..97bef99944a 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -67,11 +67,10 @@ static void screen_free_data(ID *id) { bScreen *screen = (bScreen *)id; - ARegion *region; /* No animdata here. */ - for (region = screen->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &screen->regionbase) { BKE_area_region_free(NULL, region); } @@ -325,14 +324,10 @@ static ListBase spacetypes = {NULL, NULL}; /* not SpaceType itself */ static void spacetype_free(SpaceType *st) { - ARegionType *art; - PanelType *pt; - HeaderType *ht; - - for (art = st->regiontypes.first; art; art = art->next) { + LISTBASE_FOREACH (ARegionType *, art, &st->regiontypes) { BLI_freelistN(&art->drawcalls); - for (pt = art->paneltypes.first; pt; pt = pt->next) { + LISTBASE_FOREACH (PanelType *, pt, &art->paneltypes) { if (pt->rna_ext.free) { pt->rna_ext.free(pt->rna_ext.data); } @@ -340,7 +335,7 @@ static void spacetype_free(SpaceType *st) BLI_freelistN(&pt->children); } - for (ht = art->headertypes.first; ht; ht = ht->next) { + LISTBASE_FOREACH (HeaderType *, ht, &art->headertypes) { if (ht->rna_ext.free) { ht->rna_ext.free(ht->rna_ext.data); } @@ -355,9 +350,7 @@ static void spacetype_free(SpaceType *st) void BKE_spacetypes_free(void) { - SpaceType *st; - - for (st = spacetypes.first; st; st = st->next) { + LISTBASE_FOREACH (SpaceType *, st, &spacetypes) { spacetype_free(st); } @@ -366,9 +359,7 @@ void BKE_spacetypes_free(void) SpaceType *BKE_spacetype_from_id(int spaceid) { - SpaceType *st; - - for (st = spacetypes.first; st; st = st->next) { + LISTBASE_FOREACH (SpaceType *, st, &spacetypes) { if (st->spaceid == spaceid) { return st; } @@ -378,9 +369,7 @@ SpaceType *BKE_spacetype_from_id(int spaceid) ARegionType *BKE_regiontype_from_id_or_first(const SpaceType *st, int regionid) { - ARegionType *art; - - for (art = st->regiontypes.first; art; art = art->next) { + LISTBASE_FOREACH (ARegionType *, art, &st->regiontypes) { if (art->regionid == regionid) { return art; } @@ -393,9 +382,7 @@ ARegionType *BKE_regiontype_from_id_or_first(const SpaceType *st, int regionid) ARegionType *BKE_regiontype_from_id(const SpaceType *st, int regionid) { - ARegionType *art; - - for (art = st->regiontypes.first; art; art = art->next) { + LISTBASE_FOREACH (ARegionType *, art, &st->regiontypes) { if (art->regionid == regionid) { return art; } @@ -410,10 +397,8 @@ const ListBase *BKE_spacetypes_list(void) void BKE_spacetype_register(SpaceType *st) { - SpaceType *stype; - /* sanity check */ - stype = BKE_spacetype_from_id(st->spaceid); + SpaceType *stype = BKE_spacetype_from_id(st->spaceid); if (stype) { printf("error: redefinition of spacetype %s\n", stype->name); spacetype_free(stype); @@ -432,14 +417,11 @@ bool BKE_spacetype_exists(int spaceid) void BKE_spacedata_freelist(ListBase *lb) { - SpaceLink *sl; - ARegion *region; - - for (sl = lb->first; sl; sl = sl->next) { + LISTBASE_FOREACH (SpaceLink *, sl, lb) { SpaceType *st = BKE_spacetype_from_id(sl->spacetype); /* free regions for pushed spaces */ - for (region = sl->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &sl->regionbase) { BKE_area_region_free(st, region); } @@ -510,12 +492,10 @@ ARegion *BKE_area_region_copy(const SpaceType *st, const ARegion *region) /* from lb2 to lb1, lb1 is supposed to be freed */ static void region_copylist(SpaceType *st, ListBase *lb1, ListBase *lb2) { - ARegion *region; - /* to be sure */ BLI_listbase_clear(lb1); - for (region = lb2->first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, lb2) { ARegion *region_new = BKE_area_region_copy(st, region); BLI_addtail(lb1, region_new); } @@ -524,11 +504,9 @@ static void region_copylist(SpaceType *st, ListBase *lb1, ListBase *lb2) /* lb1 should be empty */ void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2) { - SpaceLink *sl; - BLI_listbase_clear(lb1); /* to be sure */ - for (sl = lb2->first; sl; sl = sl->next) { + LISTBASE_FOREACH (SpaceLink *, sl, lb2) { SpaceType *st = BKE_spacetype_from_id(sl->spacetype); if (st && st->duplicate) { @@ -546,12 +524,8 @@ void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2) /* should be replaced in future by better local data handling for threads */ void BKE_spacedata_draw_locks(int set) { - SpaceType *st; - - for (st = spacetypes.first; st; st = st->next) { - ARegionType *art; - - for (art = st->regiontypes.first; art; art = art->next) { + LISTBASE_FOREACH (SpaceType *, st, &spacetypes) { + LISTBASE_FOREACH (ARegionType *, art, &st->regiontypes) { if (set) { art->do_lock = art->lock; } @@ -575,8 +549,10 @@ ARegion *BKE_spacedata_find_region_type(const SpaceLink *slink, ARegion *region = NULL; BLI_assert(BLI_findindex(&area->spacedata, slink) != -1); - for (region = regionbase->first; region; region = region->next) { - if (region->regiontype == region_type) { + + LISTBASE_FOREACH (ARegion *, region_iter, regionbase) { + if (region_iter->regiontype == region_type) { + region = region_iter; break; } } @@ -621,10 +597,8 @@ void BKE_screen_gizmo_tag_refresh(struct bScreen *screen) return; } - ScrArea *area; - ARegion *region; - for (area = screen->areabase.first; area; area = area->next) { - for (region = area->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { if (region->gizmo_map != NULL) { region_refresh_tag_gizmomap_callback(region->gizmo_map); } @@ -666,8 +640,6 @@ void BKE_area_region_panels_free(ListBase *panels) /* not region itself */ void BKE_area_region_free(SpaceType *st, ARegion *region) { - uiList *uilst; - if (st) { ARegionType *art = BKE_regiontype_from_id(st, region->regiontype); @@ -685,7 +657,7 @@ void BKE_area_region_free(SpaceType *st, ARegion *region) BKE_area_region_panels_free(®ion->panels); - for (uilst = region->ui_lists.first; uilst; uilst = uilst->next) { + LISTBASE_FOREACH (uiList *, uilst, ®ion->ui_lists) { if (uilst->dyn_data) { uiListDyn *dyn_data = uilst->dyn_data; if (dyn_data->items_filter_flags) { @@ -715,9 +687,8 @@ void BKE_area_region_free(SpaceType *st, ARegion *region) void BKE_screen_area_free(ScrArea *area) { SpaceType *st = BKE_spacetype_from_id(area->spacetype); - ARegion *region; - for (region = area->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { BKE_area_region_free(st, region); } @@ -731,8 +702,7 @@ void BKE_screen_area_free(ScrArea *area) void BKE_screen_area_map_free(ScrAreaMap *area_map) { - for (ScrArea *area = area_map->areabase.first, *area_next; area; area = area_next) { - area_next = area->next; + LISTBASE_FOREACH_MUTABLE (ScrArea *, area, &area_map->areabase) { BKE_screen_area_free(area); } @@ -751,10 +721,8 @@ void BKE_screen_free(bScreen *screen) ScrEdge *BKE_screen_find_edge(const bScreen *screen, ScrVert *v1, ScrVert *v2) { - ScrEdge *se; - BKE_screen_sort_scrvert(&v1, &v2); - for (se = screen->edgebase.first; se; se = se->next) { + LISTBASE_FOREACH (ScrEdge *, se, &screen->edgebase) { if (se->v1 == v1 && se->v2 == v2) { return se; } @@ -765,10 +733,8 @@ ScrEdge *BKE_screen_find_edge(const bScreen *screen, ScrVert *v1, ScrVert *v2) void BKE_screen_sort_scrvert(ScrVert **v1, ScrVert **v2) { - ScrVert *tmp; - if (*v1 > *v2) { - tmp = *v1; + ScrVert *tmp = *v1; *v1 = *v2; *v2 = tmp; } @@ -776,14 +742,9 @@ void BKE_screen_sort_scrvert(ScrVert **v1, ScrVert **v2) void BKE_screen_remove_double_scrverts(bScreen *screen) { - ScrVert *v1, *verg; - ScrEdge *se; - ScrArea *area; - - verg = screen->vertbase.first; - while (verg) { + LISTBASE_FOREACH (ScrVert *, verg, &screen->vertbase) { if (verg->newv == NULL) { /* !!! */ - v1 = verg->next; + ScrVert *v1 = verg->next; while (v1) { if (v1->newv == NULL) { /* !?! */ if (v1->vec.x == verg->vec.x && v1->vec.y == verg->vec.y) { @@ -794,12 +755,10 @@ void BKE_screen_remove_double_scrverts(bScreen *screen) v1 = v1->next; } } - verg = verg->next; } /* replace pointers in edges and faces */ - se = screen->edgebase.first; - while (se) { + LISTBASE_FOREACH (ScrEdge *, se, &screen->edgebase) { if (se->v1->newv) { se->v1 = se->v1->newv; } @@ -808,10 +767,8 @@ void BKE_screen_remove_double_scrverts(bScreen *screen) } /* edges changed: so.... */ BKE_screen_sort_scrvert(&(se->v1), &(se->v2)); - se = se->next; } - area = screen->areabase.first; - while (area) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { if (area->v1->newv) { area->v1 = area->v1->newv; } @@ -824,51 +781,39 @@ void BKE_screen_remove_double_scrverts(bScreen *screen) if (area->v4->newv) { area->v4 = area->v4->newv; } - area = area->next; } /* remove */ - verg = screen->vertbase.first; - while (verg) { - v1 = verg->next; + LISTBASE_FOREACH_MUTABLE (ScrVert *, verg, &screen->vertbase) { if (verg->newv) { BLI_remlink(&screen->vertbase, verg); MEM_freeN(verg); } - verg = v1; } } void BKE_screen_remove_double_scredges(bScreen *screen) { - ScrEdge *verg, *se, *sn; - /* compare */ - verg = screen->edgebase.first; - while (verg) { - se = verg->next; + LISTBASE_FOREACH (ScrEdge *, verg, &screen->edgebase) { + ScrEdge *se = verg->next; while (se) { - sn = se->next; + ScrEdge *sn = se->next; if (verg->v1 == se->v1 && verg->v2 == se->v2) { BLI_remlink(&screen->edgebase, se); MEM_freeN(se); } se = sn; } - verg = verg->next; } } void BKE_screen_remove_unused_scredges(bScreen *screen) { - ScrEdge *se, *sen; - ScrArea *area; - int a = 0; - /* sets flags when edge is used in area */ - area = screen->areabase.first; - while (area) { - se = BKE_screen_find_edge(screen, area->v1, area->v2); + int a = 0; + LISTBASE_FOREACH_INDEX (ScrArea *, area, &screen->areabase, a) { + ScrEdge *se = BKE_screen_find_edge(screen, area->v1, area->v2); if (se == NULL) { printf("error: area %d edge 1 doesn't exist\n", a); } @@ -896,12 +841,8 @@ void BKE_screen_remove_unused_scredges(bScreen *screen) else { se->flag = 1; } - area = area->next; - a++; } - se = screen->edgebase.first; - while (se) { - sen = se->next; + LISTBASE_FOREACH_MUTABLE (ScrEdge *, se, &screen->edgebase) { if (se->flag == 0) { BLI_remlink(&screen->edgebase, se); MEM_freeN(se); @@ -909,27 +850,18 @@ void BKE_screen_remove_unused_scredges(bScreen *screen) else { se->flag = 0; } - se = sen; } } void BKE_screen_remove_unused_scrverts(bScreen *screen) { - ScrVert *sv, *svn; - ScrEdge *se; - /* we assume edges are ok */ - - se = screen->edgebase.first; - while (se) { + LISTBASE_FOREACH (ScrEdge *, se, &screen->edgebase) { se->v1->flag = 1; se->v2->flag = 1; - se = se->next; } - sv = screen->vertbase.first; - while (sv) { - svn = sv->next; + LISTBASE_FOREACH_MUTABLE (ScrVert *, sv, &screen->vertbase) { if (sv->flag == 0) { BLI_remlink(&screen->vertbase, sv); MEM_freeN(sv); @@ -937,7 +869,6 @@ void BKE_screen_remove_unused_scrverts(bScreen *screen) else { sv->flag = 0; } - sv = svn; } } @@ -964,33 +895,33 @@ ARegion *BKE_area_find_region_type(const ScrArea *area, int region_type) ARegion *BKE_area_find_region_active_win(ScrArea *area) { - if (area) { - ARegion *region = BLI_findlink(&area->regionbase, area->region_active_win); - if (region && (region->regiontype == RGN_TYPE_WINDOW)) { - return region; - } + if (area == NULL) { + return NULL; + } - /* fallback to any */ - return BKE_area_find_region_type(area, RGN_TYPE_WINDOW); + ARegion *region = BLI_findlink(&area->regionbase, area->region_active_win); + if (region && (region->regiontype == RGN_TYPE_WINDOW)) { + return region; } - return NULL; + + /* fallback to any */ + return BKE_area_find_region_type(area, RGN_TYPE_WINDOW); } ARegion *BKE_area_find_region_xy(ScrArea *area, const int regiontype, int x, int y) { - ARegion *region_found = NULL; - if (area) { - ARegion *region; - for (region = area->regionbase.first; region; region = region->next) { - if (ELEM(regiontype, RGN_TYPE_ANY, region->regiontype)) { - if (BLI_rcti_isect_pt(®ion->winrct, x, y)) { - region_found = region; - break; - } + if (area == NULL) { + return NULL; + } + + LISTBASE_FOREACH (ARegion *, region, &area->regionbase) { + if (ELEM(regiontype, RGN_TYPE_ANY, region->regiontype)) { + if (BLI_rcti_isect_pt(®ion->winrct, x, y)) { + return region; } } } - return region_found; + return NULL; } /** @@ -998,16 +929,14 @@ ARegion *BKE_area_find_region_xy(ScrArea *area, const int regiontype, int x, int */ ARegion *BKE_screen_find_region_xy(bScreen *screen, const int regiontype, int x, int y) { - ARegion *region_found = NULL; LISTBASE_FOREACH (ARegion *, region, &screen->regionbase) { if (ELEM(regiontype, RGN_TYPE_ANY, region->regiontype)) { if (BLI_rcti_isect_pt(®ion->winrct, x, y)) { - region_found = region; - break; + return region; } } } - return region_found; + return NULL; } /** @@ -1016,15 +945,13 @@ ARegion *BKE_screen_find_region_xy(bScreen *screen, const int regiontype, int x, */ ScrArea *BKE_screen_find_area_from_space(struct bScreen *screen, SpaceLink *sl) { - ScrArea *area; - - for (area = screen->areabase.first; area; area = area->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { if (BLI_findindex(&area->spacedata, sl) != -1) { - break; + return area; } } - return area; + return NULL; } /** @@ -1033,13 +960,13 @@ ScrArea *BKE_screen_find_area_from_space(struct bScreen *screen, SpaceLink *sl) */ ScrArea *BKE_screen_find_big_area(bScreen *screen, const int spacetype, const short min) { - ScrArea *area, *big = NULL; - int size, maxsize = 0; + ScrArea *big = NULL; + int maxsize = 0; - for (area = screen->areabase.first; area; area = area->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { if (ELEM(spacetype, SPACE_TYPE_ANY, area->spacetype)) { if (min <= area->winx && min <= area->winy) { - size = area->winx * area->winy; + int size = area->winx * area->winy; if (size > maxsize) { maxsize = size; big = area; @@ -1077,9 +1004,7 @@ void BKE_screen_view3d_sync(View3D *v3d, struct Scene *scene) v3d->camera = scene->camera; if (v3d->camera == NULL) { - ARegion *region; - - for (region = v3d->regionbase.first; region; region = region->next) { + LISTBASE_FOREACH (ARegion *, region, &v3d->regionbase) { if (region->regiontype == RGN_TYPE_WINDOW) { RegionView3D *rv3d = region->regiondata; if (rv3d->persp == RV3D_CAMOB) { @@ -1094,10 +1019,8 @@ void BKE_screen_view3d_sync(View3D *v3d, struct Scene *scene) void BKE_screen_view3d_scene_sync(bScreen *screen, Scene *scene) { /* are there cameras in the views that are not in the scene? */ - ScrArea *area; - for (area = screen->areabase.first; area; area = area->next) { - SpaceLink *sl; - for (sl = area->spacedata.first; sl; sl = sl->next) { + LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { + LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) { if (sl->spacetype == SPACE_VIEW3D) { View3D *v3d = (View3D *)sl; BKE_screen_view3d_sync(v3d, scene); |