Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / screen / screen_edit.c
index 06f45fa..06735eb 100644 (file)
@@ -81,7 +81,7 @@ static ScrVert *screen_addvert_ex(ScrAreaMap *area_map, short x, short y)
        ScrVert *sv = MEM_callocN(sizeof(ScrVert), "addscrvert");
        sv->vec.x = x;
        sv->vec.y = y;
-       
+
        BLI_addtail(&area_map->vertbase, sv);
        return sv;
 }
@@ -129,7 +129,7 @@ ScrEdge *screen_area_map_find_active_scredge(
                                short min, max;
                                min = MIN2(se->v1->vec.x, se->v2->vec.x);
                                max = MAX2(se->v1->vec.x, se->v2->vec.x);
-                               
+
                                if (abs(my - se->v1->vec.y) <= safety && mx >= min && mx <= max)
                                        return se;
                        }
@@ -139,7 +139,7 @@ ScrEdge *screen_area_map_find_active_scredge(
                                short min, max;
                                min = MIN2(se->v1->vec.y, se->v2->vec.y);
                                max = MAX2(se->v1->vec.y, se->v2->vec.y);
-                               
+
                                if (abs(mx - se->v1->vec.x) <= safety && my >= min && my <= max)
                                        return se;
                        }
@@ -201,11 +201,11 @@ static ScrArea *screen_addarea(
 
 static void screen_delarea(bContext *C, bScreen *sc, ScrArea *sa)
 {
-       
+
        ED_area_exit(C, sa);
-       
+
        BKE_screen_area_free(sa);
-       
+
        BLI_remlink(&sc->areabase, sa);
        MEM_freeN(sa);
 }
@@ -217,14 +217,14 @@ static short testsplitpoint(ScrArea *sa, char dir, float fac)
        short x, y;
        const short area_min_x = AREAMINX;
        const short area_min_y = ED_area_headersize();
-       
+
        // area big enough?
        if (dir == 'v' && (sa->v4->vec.x - sa->v1->vec.x <= 2 * area_min_x)) return 0;
        if (dir == 'h' && (sa->v2->vec.y - sa->v1->vec.y <= 2 * area_min_y)) return 0;
-       
+
        // to be sure
        CLAMP(fac, 0.0f, 1.0f);
-       
+
        if (dir == 'h') {
                y = sa->v1->vec.y +
                        round_fl_to_short(fac * (float)(sa->v2->vec.y - sa->v1->vec.y));
@@ -254,12 +254,12 @@ ScrArea *area_split(bScreen *sc, ScrArea *sa, char dir, float fac, int merge)
        ScrArea *newa = NULL;
        ScrVert *sv1, *sv2;
        short split;
-       
+
        if (sa == NULL) return NULL;
-       
+
        split = testsplitpoint(sa, dir, fac);
        if (split == 0) return NULL;
-       
+
        /* note regarding (fac > 0.5f) checks below.
         * normally it shouldn't matter which is used since the copy should match the original
         * however with viewport rendering and python console this isn't the case. - campbell */
@@ -268,14 +268,14 @@ ScrArea *area_split(bScreen *sc, ScrArea *sa, char dir, float fac, int merge)
                /* new vertices */
                sv1 = screen_addvert(sc, sa->v1->vec.x, split);
                sv2 = screen_addvert(sc, sa->v4->vec.x, split);
-               
+
                /* new edges */
                screen_addedge(sc, sa->v1, sv1);
                screen_addedge(sc, sv1, sa->v2);
                screen_addedge(sc, sa->v3, sv2);
                screen_addedge(sc, sv2, sa->v4);
                screen_addedge(sc, sv1, sv2);
-               
+
                if (fac > 0.5f) {
                        /* new areas: top */
                        newa = screen_addarea(sc, sv1, sa->v2, sa->v3, sv2, sa->spacetype);
@@ -294,20 +294,20 @@ ScrArea *area_split(bScreen *sc, ScrArea *sa, char dir, float fac, int merge)
                }
 
                ED_area_data_copy(newa, sa, true);
-               
+
        }
        else {
                /* new vertices */
                sv1 = screen_addvert(sc, split, sa->v1->vec.y);
                sv2 = screen_addvert(sc, split, sa->v2->vec.y);
-               
+
                /* new edges */
                screen_addedge(sc, sa->v1, sv1);
                screen_addedge(sc, sv1, sa->v4);
                screen_addedge(sc, sa->v2, sv2);
                screen_addedge(sc, sv2, sa->v3);
                screen_addedge(sc, sv1, sv2);
-               
+
                if (fac > 0.5f) {
                        /* new areas: right */
                        newa = screen_addarea(sc, sv1, sv2, sa->v3, sa->v4, sa->spacetype);
@@ -327,13 +327,13 @@ ScrArea *area_split(bScreen *sc, ScrArea *sa, char dir, float fac, int merge)
 
                ED_area_data_copy(newa, sa, true);
        }
-       
+
        /* remove double vertices en edges */
        if (merge)
                BKE_screen_remove_double_scrverts(sc);
        BKE_screen_remove_double_scredges(sc);
        BKE_screen_remove_unused_scredges(sc);
-       
+
        return newa;
 }
 
@@ -344,7 +344,7 @@ bScreen *screen_add(const char *name, const rcti *rect)
 {
        bScreen *sc;
        ScrVert *sv1, *sv2, *sv3, *sv4;
-       
+
        sc = BKE_libblock_alloc(G.main, ID_SCR, name, 0);
        sc->do_refresh = true;
        sc->redraws_flag = TIME_ALL_3D_WIN | TIME_ALL_ANIM_WIN;
@@ -353,15 +353,15 @@ bScreen *screen_add(const char *name, const rcti *rect)
        sv2 = screen_addvert(sc, rect->xmin,     rect->ymax - 1);
        sv3 = screen_addvert(sc, rect->xmax - 1, rect->ymax - 1);
        sv4 = screen_addvert(sc, rect->xmax - 1, rect->ymin);
-       
+
        screen_addedge(sc, sv1, sv2);
        screen_addedge(sc, sv2, sv3);
        screen_addedge(sc, sv3, sv4);
        screen_addedge(sc, sv4, sv1);
-       
+
        /* dummy type, no spacedata */
        screen_addarea(sc, sv1, sv2, sv3, sv4, SPACE_EMPTY);
-               
+
        return sc;
 }
 
@@ -370,26 +370,26 @@ void screen_data_copy(bScreen *to, bScreen *from)
        ScrVert *s1, *s2;
        ScrEdge *se;
        ScrArea *sa, *saf;
-       
+
        /* free contents of 'to', is from blenkernel screen.c */
        BKE_screen_free(to);
-       
+
        BLI_duplicatelist(&to->vertbase, &from->vertbase);
        BLI_duplicatelist(&to->edgebase, &from->edgebase);
        BLI_duplicatelist(&to->areabase, &from->areabase);
        BLI_listbase_clear(&to->regionbase);
-       
+
        s2 = to->vertbase.first;
        for (s1 = from->vertbase.first; s1; s1 = s1->next, s2 = s2->next) {
                s1->newv = s2;
        }
-       
+
        for (se = to->edgebase.first; se; se = se->next) {
                se->v1 = se->v1->newv;
                se->v2 = se->v2->newv;
                BKE_screen_sort_scrvert(&(se->v1), &(se->v2));
        }
-       
+
        saf = from->areabase.first;
        for (sa = to->areabase.first; sa; sa = sa->next, saf = saf->next) {
                sa->v1 = sa->v1->newv;
@@ -401,10 +401,10 @@ void screen_data_copy(bScreen *to, bScreen *from)
                BLI_listbase_clear(&sa->regionbase);
                BLI_listbase_clear(&sa->actionzones);
                BLI_listbase_clear(&sa->handlers);
-               
+
                ED_area_data_copy(sa, saf, true);
        }
-       
+
        /* put at zero (needed?) */
        for (s1 = from->vertbase.first; s1; s1 = s1->next)
                s1->newv = NULL;
@@ -439,7 +439,7 @@ int area_getorientation(ScrArea *sa, ScrArea *sb)
        sbv2 = sb->v2;
        sbv3 = sb->v3;
        sbv4 = sb->v4;
-       
+
        if (sav1 == sbv4 && sav2 == sbv3) { /* sa to right of sb = W */
                return 0;
        }
@@ -452,7 +452,7 @@ int area_getorientation(ScrArea *sa, ScrArea *sb)
        else if (sav1 == sbv2 && sav4 == sbv3) { /* sa on top of sb = S*/
                return 3;
        }
-       
+
        return -1;
 }
 
@@ -462,14 +462,14 @@ int area_getorientation(ScrArea *sa, ScrArea *sb)
 int screen_area_join(bContext *C, bScreen *scr, ScrArea *sa1, ScrArea *sa2)
 {
        int dir;
-       
+
        dir = area_getorientation(sa1, sa2);
        /*printf("dir is : %i\n", dir);*/
-       
+
        if (dir == -1) {
                return 0;
        }
-       
+
        if (dir == 0) {
                sa1->v1 = sa2->v1;
                sa1->v2 = sa2->v2;
@@ -494,7 +494,7 @@ int screen_area_join(bContext *C, bScreen *scr, ScrArea *sa1, ScrArea *sa2)
                screen_addedge(scr, sa1->v1, sa1->v2);
                screen_addedge(scr, sa1->v3, sa1->v4);
        }
-       
+
        screen_delarea(C, scr, sa2);
        BKE_screen_remove_double_scrverts(scr);
        /* Update preview thumbnail */
@@ -509,20 +509,20 @@ void select_connected_scredge(const wmWindow *win, ScrEdge *edge)
        ScrEdge *se;
        int oneselected;
        char dir;
-       
+
        /* select connected, only in the right direction */
        /* 'dir' is the direction of EDGE */
-       
+
        if (edge->v1->vec.x == edge->v2->vec.x) dir = 'v';
        else dir = 'h';
-       
+
        ED_screen_verts_iter(win, sc, sv) {
                sv->flag = 0;
        }
 
        edge->v1->flag = 1;
        edge->v2->flag = 1;
-       
+
        oneselected = 1;
        while (oneselected) {
                se = sc->edgebase.first;
@@ -675,7 +675,7 @@ static void screen_vertices_scale(
 
        /* test for collapsed areas. This could happen in some blender version... */
        /* ton: removed option now, it needs Context... */
-       
+
        /* make each window at least ED_area_headersize() high */
        for (sa = sc->areabase.first; sa; sa = sa->next) {
                int headery = headery_init;
@@ -784,7 +784,7 @@ static void screen_refresh_headersizes(void)
 {
        const ListBase *lb = BKE_spacetypes_list();
        SpaceType *st;
-       
+
        for (st = lb->first; st; st = st->next) {
                ARegionType *art = BKE_regiontype_from_id(st, RGN_TYPE_HEADER);
                if (art) art->prefsizey = ED_area_headersize();
@@ -815,7 +815,7 @@ void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
                        /* sets subwindows for regions, adds handlers */
                        ED_area_initialize(wm, win, area);
                }
-       
+
                /* wake up animtimer */
                if (screen->animtimer)
                        WM_event_timer_sleep(wm, win, screen->animtimer, false);
@@ -835,7 +835,7 @@ void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
 void ED_screens_initialize(wmWindowManager *wm)
 {
        wmWindow *win;
-       
+
        for (win = wm->windows.first; win; win = win->next) {
                if (WM_window_get_active_workspace(win) == NULL) {
                        WM_window_set_active_workspace(win, G.main->workspaces.first);
@@ -875,12 +875,12 @@ void ED_region_exit(bContext *C, ARegion *ar)
        WM_event_remove_handlers(C, &ar->handlers);
        WM_event_modal_handler_region_replace(win, ar, NULL);
        WM_draw_region_free(ar);
-       
+
        if (ar->headerstr) {
                MEM_freeN(ar->headerstr);
                ar->headerstr = NULL;
        }
-       
+
        if (ar->regiontimer) {
                WM_event_remove_timer(wm, win, ar->regiontimer);
                ar->regiontimer = NULL;
@@ -918,14 +918,14 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
        wmWindow *prevwin = CTX_wm_window(C);
 
        CTX_wm_window_set(C, window);
-       
+
        if (screen->animtimer)
                WM_event_remove_timer(wm, window, screen->animtimer);
        screen->animtimer = NULL;
        screen->scrubbing = false;
 
        screen->active_region = NULL;
-       
+
        for (ARegion *ar = screen->regionbase.first; ar; ar = ar->next) {
                ED_region_exit(C, ar);
        }
@@ -939,7 +939,7 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
 
        /* mark it available for use for other windows */
        screen->winid = 0;
-       
+
        if (!WM_window_is_temp_screen(prevwin)) {
                /* use previous window if possible */
                CTX_wm_window_set(C, prevwin);
@@ -948,7 +948,7 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
                /* none otherwise */
                CTX_wm_window_set(C, NULL);
        }
-       
+
 }
 
 /* *********************************** */
@@ -959,11 +959,11 @@ static void screen_cursor_set(wmWindow *win, const int xy[2])
        const bScreen *screen = WM_window_get_active_screen(win);
        AZone *az = NULL;
        ScrArea *sa;
-       
+
        for (sa = screen->areabase.first; sa; sa = sa->next)
                if ((az = is_in_area_actionzone(sa, xy)))
                        break;
-       
+
        if (sa) {
                if (az->type == AZONE_AREA)
                        WM_cursor_set(win, CURSOR_EDIT);
@@ -1021,19 +1021,19 @@ void ED_screen_set_active_region(bContext *C, wmWindow *win, const int xy[2])
                }
                else
                        scr->active_region = NULL;
-               
+
                /* check for redraw headers */
                if (old_ar != scr->active_region) {
 
                        ED_screen_areas_iter(win, scr, area_iter) {
                                bool do_draw = false;
-                               
+
                                for (ar = area_iter->regionbase.first; ar; ar = ar->next) {
                                        if (ar == old_ar || ar == scr->active_region) {
                                                do_draw = true;
                                        }
                                }
-                               
+
                                if (do_draw) {
                                        for (ar = area_iter->regionbase.first; ar; ar = ar->next) {
                                                if (ar->regiontype == RGN_TYPE_HEADER) {
@@ -1043,7 +1043,7 @@ void ED_screen_set_active_region(bContext *C, wmWindow *win, const int xy[2])
                                }
                        }
                }
-               
+
                /* cursors, for time being set always on edges, otherwise aregion doesnt switch */
                if (scr->active_region == NULL) {
                        screen_cursor_set(win, xy);
@@ -1075,10 +1075,10 @@ int ED_screen_area_active(const bContext *C)
        if (win && sc && sa) {
                AZone *az = is_in_area_actionzone(sa, &win->eventstate->x);
                ARegion *ar;
-               
+
                if (az && az->type == AZONE_REGION)
                        return 1;
-               
+
                for (ar = sa->regionbase.first; ar; ar = ar->next)
                        if (ar == sc->active_region)
                                return 1;
@@ -1277,13 +1277,13 @@ static void screen_set_3dview_camera(Scene *scene, ViewLayer *view_layer, ScrAre
                if (!v3d->camera) {
                        ARegion *ar;
                        ListBase *regionbase;
-                       
+
                        /* regionbase is in different place depending if space is active */
                        if (v3d == sa->spacedata.first)
                                regionbase = &sa->regionbase;
                        else
                                regionbase = &v3d->regionbase;
-                               
+
                        for (ar = regionbase->first; ar; ar = ar->next) {
                                if (ar->regiontype == RGN_TYPE_WINDOW) {
                                        RegionView3D *rv3d = ar->regiondata;
@@ -1316,7 +1316,7 @@ ScrArea *ED_screen_full_newspace(bContext *C, ScrArea *sa, int type)
        if (!sa || sa->full == NULL) {
                newsa = ED_screen_state_toggle(C, win, sa, SCREENMAXIMIZED);
        }
-       
+
        if (!newsa) {
                newsa = sa;
        }
@@ -1373,10 +1373,10 @@ void ED_screen_full_restore(bContext *C, ScrArea *sa)
        SpaceLink *sl = sa->spacedata.first;
        bScreen *screen = CTX_wm_screen(C);
        short state = (screen ? screen->state : SCREENMAXIMIZED);
-       
+
        /* if fullscreen area has a temporary space (such as a file browser or fullscreen render
         * overlaid on top of an existing setup) then return to the previous space */
-       
+
        if (sl->next) {
                if (sa->flag & AREA_FLAG_TEMP_TYPE) {
                        ED_screen_full_prevspace(C, sa);
@@ -1544,15 +1544,15 @@ void ED_refresh_viewport_fps(bContext *C)
 {
        wmTimer *animtimer = CTX_wm_screen(C)->animtimer;
        Scene *scene = CTX_data_scene(C);
-       
+
        /* is anim playback running? */
        if (animtimer && (U.uiflag & USER_SHOW_FPS)) {
                ScreenFrameRateInfo *fpsi = scene->fps_info;
-               
+
                /* if there isn't any info, init it first */
                if (fpsi == NULL)
                        fpsi = scene->fps_info = MEM_callocN(sizeof(ScreenFrameRateInfo), "refresh_viewport_fps fps_info");
-               
+
                /* update the values */
                fpsi->redrawtime = fpsi->lredrawtime;
                fpsi->lredrawtime = animtimer->ltime;
@@ -1565,7 +1565,7 @@ void ED_refresh_viewport_fps(bContext *C)
        }
 }
 
-/* redraws: uses defines from stime->redraws 
+/* redraws: uses defines from stime->redraws
  * enable: 1 - forward on, -1 - backwards on, 0 - off
  */
 void ED_screen_animation_timer(bContext *C, int redraws, int refresh, int sync, int enable)
@@ -1575,17 +1575,17 @@ void ED_screen_animation_timer(bContext *C, int redraws, int refresh, int sync,
        wmWindow *win = CTX_wm_window(C);
        Scene *scene = CTX_data_scene(C);
        bScreen *stopscreen = ED_screen_animation_playing(wm);
-       
+
        if (stopscreen) {
                WM_event_remove_timer(wm, win, stopscreen->animtimer);
                stopscreen->animtimer = NULL;
        }
-       
+
        if (enable) {
                ScreenAnimData *sad = MEM_callocN(sizeof(ScreenAnimData), "ScreenAnimData");
-               
+
                screen->animtimer = WM_event_add_timer(wm, win, TIMER0, (1.0 / FPS));
-               
+
                sad->ar = CTX_wm_region(C);
                /* if startframe is larger than current frame, we put currentframe on startframe.
                 * note: first frame then is not drawn! (ton) */
@@ -1620,7 +1620,7 @@ void ED_screen_animation_timer(bContext *C, int redraws, int refresh, int sync,
                sad->from_anim_edit = (ELEM(spacetype, SPACE_IPO, SPACE_ACTION, SPACE_NLA));
 
                screen->animtimer->customdata = sad;
-               
+
        }
 
        /* notifier catched by top header, for button */
@@ -1633,7 +1633,7 @@ static ARegion *time_top_left_3dwindow(bScreen *screen)
        ARegion *aret = NULL;
        ScrArea *sa;
        int min = 10000;
-       
+
        for (sa = screen->areabase.first; sa; sa = sa->next) {
                if (sa->spacetype == SPACE_VIEW3D) {
                        ARegion *ar;
@@ -1656,7 +1656,7 @@ void ED_screen_animation_timer_update(bScreen *screen, int redraws, int refresh)
        if (screen && screen->animtimer) {
                wmTimer *wt = screen->animtimer;
                ScreenAnimData *sad = wt->customdata;
-               
+
                sad->redraws = redraws;
                sad->refresh = refresh;
                sad->ar = NULL;
@@ -1681,7 +1681,7 @@ void ED_update_for_newframe(Main *bmain, Depsgraph *depsgraph)
                }
        }
 #endif
-       
+
        ED_clip_update_frame(bmain, scene->r.cfra);
 
        /* this function applies the changes too */
@@ -1690,7 +1690,7 @@ void ED_update_for_newframe(Main *bmain, Depsgraph *depsgraph)
        /* composite */
        if (scene->use_nodes && scene->nodetree)
                ntreeCompositTagAnimated(scene->nodetree);
-       
+
        /* update animated texture nodes */
        {
                Tex *tex;
@@ -1700,7 +1700,7 @@ void ED_update_for_newframe(Main *bmain, Depsgraph *depsgraph)
                        }
                }
        }
-       
+
 }
 
 /*