diff options
author | Julian Eisel <eiseljulian@gmail.com> | 2018-04-13 22:43:57 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-04-16 16:18:48 +0300 |
commit | 57c651d248298e9fe95de19154fcc5b3e854699e (patch) | |
tree | 4aa003a4436dd730f32a6471384c204dcf176c9b /source/blender/blenkernel/intern | |
parent | 1b6fddb9683e9dfb7b65d8ff2f30c302d67817a2 (diff) |
Cleanup: move some screen utility functions, from topbar branch.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/screen.c | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index c1b3a4ae0c8..35055a59243 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -451,6 +451,174 @@ unsigned int BKE_screen_visible_layers(bScreen *screen, Scene *scene) return layer; } + +/* ***************** Screen edges & verts ***************** */ + +ScrEdge *BKE_screen_find_edge(bScreen *sc, ScrVert *v1, ScrVert *v2) +{ + ScrEdge *se; + + BKE_screen_sort_scrvert(&v1, &v2); + for (se = sc->edgebase.first; se; se = se->next) { + if (se->v1 == v1 && se->v2 == v2) { + return se; + } + } + + return NULL; +} + +void BKE_screen_sort_scrvert(ScrVert **v1, ScrVert **v2) +{ + ScrVert *tmp; + + if (*v1 > *v2) { + tmp = *v1; + *v1 = *v2; + *v2 = tmp; + } +} + +void BKE_screen_remove_double_scrverts(bScreen *sc) +{ + ScrVert *v1, *verg; + ScrEdge *se; + ScrArea *sa; + + verg = sc->vertbase.first; + while (verg) { + if (verg->newv == NULL) { /* !!! */ + v1 = verg->next; + while (v1) { + if (v1->newv == NULL) { /* !?! */ + if (v1->vec.x == verg->vec.x && v1->vec.y == verg->vec.y) { + /* printf("doublevert\n"); */ + v1->newv = verg; + } + } + v1 = v1->next; + } + } + verg = verg->next; + } + + /* replace pointers in edges and faces */ + se = sc->edgebase.first; + while (se) { + if (se->v1->newv) se->v1 = se->v1->newv; + if (se->v2->newv) se->v2 = se->v2->newv; + /* edges changed: so.... */ + BKE_screen_sort_scrvert(&(se->v1), &(se->v2)); + se = se->next; + } + sa = sc->areabase.first; + while (sa) { + if (sa->v1->newv) sa->v1 = sa->v1->newv; + if (sa->v2->newv) sa->v2 = sa->v2->newv; + if (sa->v3->newv) sa->v3 = sa->v3->newv; + if (sa->v4->newv) sa->v4 = sa->v4->newv; + sa = sa->next; + } + + /* remove */ + verg = sc->vertbase.first; + while (verg) { + v1 = verg->next; + if (verg->newv) { + BLI_remlink(&sc->vertbase, verg); + MEM_freeN(verg); + } + verg = v1; + } + +} + +void BKE_screen_remove_double_scredges(bScreen *sc) +{ + ScrEdge *verg, *se, *sn; + + /* compare */ + verg = sc->edgebase.first; + while (verg) { + se = verg->next; + while (se) { + sn = se->next; + if (verg->v1 == se->v1 && verg->v2 == se->v2) { + BLI_remlink(&sc->edgebase, se); + MEM_freeN(se); + } + se = sn; + } + verg = verg->next; + } +} + +void BKE_screen_remove_unused_scredges(bScreen *sc) +{ + ScrEdge *se, *sen; + ScrArea *sa; + int a = 0; + + /* sets flags when edge is used in area */ + sa = sc->areabase.first; + while (sa) { + se = BKE_screen_find_edge(sc, sa->v1, sa->v2); + if (se == NULL) printf("error: area %d edge 1 doesn't exist\n", a); + else se->flag = 1; + se = BKE_screen_find_edge(sc, sa->v2, sa->v3); + if (se == NULL) printf("error: area %d edge 2 doesn't exist\n", a); + else se->flag = 1; + se = BKE_screen_find_edge(sc, sa->v3, sa->v4); + if (se == NULL) printf("error: area %d edge 3 doesn't exist\n", a); + else se->flag = 1; + se = BKE_screen_find_edge(sc, sa->v4, sa->v1); + if (se == NULL) printf("error: area %d edge 4 doesn't exist\n", a); + else se->flag = 1; + sa = sa->next; + a++; + } + se = sc->edgebase.first; + while (se) { + sen = se->next; + if (se->flag == 0) { + BLI_remlink(&sc->edgebase, se); + MEM_freeN(se); + } + else { + se->flag = 0; + } + se = sen; + } +} + +void BKE_screen_remove_unused_scrverts(bScreen *sc) +{ + ScrVert *sv, *svn; + ScrEdge *se; + + /* we assume edges are ok */ + + se = sc->edgebase.first; + while (se) { + se->v1->flag = 1; + se->v2->flag = 1; + se = se->next; + } + + sv = sc->vertbase.first; + while (sv) { + svn = sv->next; + if (sv->flag == 0) { + BLI_remlink(&sc->vertbase, sv); + MEM_freeN(sv); + } + else { + sv->flag = 0; + } + sv = svn; + } +} + /* ***************** Utilities ********************** */ /* Find a region of the specified type from the given area */ |