Commit: f05bad92bffe54ca8d39cf7021f82683469d7553
Author: Julian Eisel
Date:   Sat Oct 7 16:31:19 2017 +0200
Branches: topbar
https://developer.blender.org/rBf05bad92bffe54ca8d39cf7021f82683469d7553

Fix small jumps of area rectangles and contents

Should also fix some glitches/jumping on HiDPI screens.

Most of this is related cleanup, actual fix is rather small (check
changes in screen_vertices_scale and WM_window_screen_pixels_y)

===================================================================

M       source/blender/editors/screen/area.c
M       source/blender/editors/screen/screen_edit.c
M       source/blender/makesdna/DNA_screen_types.h
M       source/blender/windowmanager/intern/wm_subwindow.c
M       source/blender/windowmanager/intern/wm_window.c

===================================================================

diff --git a/source/blender/editors/screen/area.c 
b/source/blender/editors/screen/area.c
index 7b8300f24f3..cdbe13a300d 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -1373,20 +1373,33 @@ static void region_rect_recursive(wmWindow *win, 
ScrArea *sa, ARegion *ar, rcti
        region_rect_recursive(win, sa, ar->next, remainder, quad, add_azones);
 }
 
-static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
+static void area_calc_totrct(ScrArea *sa, int window_size_x, int window_size_y)
 {
-       short rt = (short) U.pixelsize;
+       short px = (short)U.pixelsize;
+
+       sa->totrct.xmin = sa->v1->vec.x;
+       sa->totrct.xmax = sa->v4->vec.x;
+       sa->totrct.ymin = sa->v1->vec.y;
+       sa->totrct.ymax = sa->v2->vec.y;
+
+       /* scale down totrct by 1 pixel on all sides not matching window 
borders */
+       if (sa->totrct.xmin > 0) {
+               sa->totrct.xmin += px;
+       }
+       if (sa->totrct.xmax < (window_size_x - 1)) {
+               sa->totrct.xmax -= px;
+       }
+       if (sa->totrct.ymin > 0) {
+               sa->totrct.ymin += px;
+       }
+       if (sa->totrct.ymax < (window_size_y - 1)) {
+               sa->totrct.ymax -= px;
+       }
+       BLI_assert(sa->totrct.xmin >= 0);
+       BLI_assert(sa->totrct.xmax >= 0);
+       BLI_assert(sa->totrct.ymin >= 0);
+       BLI_assert(sa->totrct.ymax >= 0);
 
-       if (sa->v1->vec.x > 0) sa->totrct.xmin = sa->v1->vec.x + rt;
-       else sa->totrct.xmin = sa->v1->vec.x;
-       if (sa->v4->vec.x < sizex - 1) sa->totrct.xmax = sa->v4->vec.x - rt;
-       else sa->totrct.xmax = sa->v4->vec.x;
-       
-       if (sa->v1->vec.y > 0) sa->totrct.ymin = sa->v1->vec.y + rt;
-       else sa->totrct.ymin = sa->v1->vec.y;
-       if (sa->v2->vec.y < sizey - 1) sa->totrct.ymax = sa->v2->vec.y - rt;
-       else sa->totrct.ymax = sa->v2->vec.y;
-       
        /* for speedup */
        sa->winx = BLI_rcti_size_x(&sa->totrct) + 1;
        sa->winy = BLI_rcti_size_y(&sa->totrct) + 1;
@@ -1509,8 +1522,8 @@ void screen_area_update_region_sizes(wmWindowManager *wm, 
wmWindow *win, ScrArea
 void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
 {
        const bScreen *screen = WM_window_get_active_screen(win);
-       const int screen_size_x = WM_window_screen_pixels_x(win);
-       const int screen_size_y = WM_window_screen_pixels_y(win);
+       const int window_size_x = WM_window_pixels_x(win);
+       const int window_size_y = WM_window_pixels_y(win);
        ARegion *ar;
        rcti rect;
        
@@ -1526,7 +1539,7 @@ void ED_area_initialize(wmWindowManager *wm, wmWindow 
*win, ScrArea *sa)
                ar->type = BKE_regiontype_from_id(sa->type, ar->regiontype);
 
        /* area sizes */
-       area_calc_totrct(sa, screen_size_x, screen_size_y);
+       area_calc_totrct(sa, window_size_x, window_size_y);
 
        /* clear all azones, add the area triange widgets */
        area_azone_initialize(win, screen, sa);
diff --git a/source/blender/editors/screen/screen_edit.c 
b/source/blender/editors/screen/screen_edit.c
index 4331ec2bb07..a552fb4c108 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -508,8 +508,13 @@ void select_connected_scredge(bScreen *sc, ScrEdge *edge)
        }
 }
 
-/* test if screen vertices should be scaled */
-static void screen_test_scale(const wmWindow *win, bScreen *sc, int winsize_x, 
int winsize_y)
+/**
+ * Test if screen vertices should be scaled and do if needed.
+ */
+static void screen_vertices_scale(
+        const wmWindow *win, bScreen *sc,
+        int window_size_x, int window_size_y,
+        int screen_size_x, int screen_size_y)
 {
        /* clamp Y size of header sized areas when expanding windows
         * avoids annoying empty space around file menu */
@@ -545,7 +550,7 @@ static void screen_test_scale(const wmWindow *win, bScreen 
*sc, int winsize_x, i
 #define TEMP_TOP 2
 
        /* if the window's Y axis grows, clamp header sized areas */
-       if (winsize_y_prev < winsize_y) {  /* growing? */
+       if (winsize_y_prev < screen_size_y) {  /* growing? */
                const int headery_margin_max = headery_init + 4;
                for (sa = sc->areabase.first; sa; sa = sa->next) {
                        ARegion *ar = BKE_area_find_region_type(sa, 
RGN_TYPE_HEADER);
@@ -568,9 +573,9 @@ static void screen_test_scale(const wmWindow *win, bScreen 
*sc, int winsize_x, i
 #endif
 
 
-       if (winsize_x_prev != winsize_x || winsize_y_prev != winsize_y) {
-               facx = ((float)winsize_x - 1) / ((float)winsize_x_prev - 1);
-               facy = ((float)winsize_y - 1) / ((float)winsize_y_prev - 1);
+       if (winsize_x_prev != screen_size_x || winsize_y_prev != screen_size_y) 
{
+               facx = ((float)screen_size_x - 1) / ((float)winsize_x_prev - 1);
+               facy = ((float)screen_size_y - 1) / ((float)winsize_y_prev - 1);
                
                /* make sure it fits! */
                for (sv = sc->vertbase.first; sv; sv = sv->next) {
@@ -581,20 +586,20 @@ static void screen_test_scale(const wmWindow *win, 
bScreen *sc, int winsize_x, i
                        //sv->vec.x += AREAGRID - 1;
                        //sv->vec.x -=  (sv->vec.x % AREAGRID);
 
-                       CLAMP(sv->vec.x, 0, winsize_x - 1);
+                       CLAMP(sv->vec.x, 0, screen_size_x - 1);
                        
                        tempf = ((float)sv->vec.y) * facy;
                        sv->vec.y = (short)(tempf + 0.5f);
                        //sv->vec.y += AREAGRID - 1;
                        //sv->vec.y -=  (sv->vec.y % AREAGRID);
 
-                       CLAMP(sv->vec.y, 0, winsize_y - 1);
+                       CLAMP(sv->vec.y, 0, screen_size_y - 1);
                }
        }
 
 
 #ifdef USE_HEADER_SIZE_CLAMP
-       if (winsize_y_prev < winsize_y) {  /* growing? */
+       if (winsize_y_prev < screen_size_y) {  /* growing? */
                for (sa = sc->areabase.first; sa; sa = sa->next) {
                        ScrEdge *se = NULL;
 
@@ -654,7 +659,7 @@ static void screen_test_scale(const wmWindow *win, bScreen 
*sc, int winsize_x, i
                /* adjust headery if verts are along the edge of window */
                if (sa->v1->vec.y > 0)
                        headery += U.pixelsize;
-               if (sa->v2->vec.y < winsize_y - 1)
+               if (sa->v2->vec.y < screen_size_y - 1)
                        headery += U.pixelsize;
                
                if (sa->v2->vec.y - sa->v1->vec.y + 1 < headery) {
@@ -679,16 +684,15 @@ static void screen_test_scale(const wmWindow *win, 
bScreen *sc, int winsize_x, i
                }
        }
 
-       /* Global areas have a fixed size that only changes with the DPI. Here 
we ensure that exactly this size is set. */
+       /* Global areas have a fixed size that only changes with the DPI. Here 
we ensure that exactly this size is set.
+        * TODO Assumes global area to be top-aligned. Should be made more 
generic */
        for (ScrArea *area = win->global_areas.first; area; area = area->next) {
-               short px = (short)U.pixelsize;
-
                /* width */
                area->v1->vec.x = area->v2->vec.x = 0;
-               area->v3->vec.x = area->v4->vec.x = win->sizex;
+               area->v3->vec.x = area->v4->vec.x = window_size_x;
                /* height */
-               area->v1->vec.y = area->v4->vec.y = win->sizey - 
ED_area_global_size_y(win, area);
-               area->v2->vec.y = area->v3->vec.y = win->sizey - px;
+               area->v1->vec.y = area->v4->vec.y = window_size_y - 
ED_area_global_size_y(win, area) - U.pixelsize;
+               area->v2->vec.y = area->v3->vec.y = window_size_y;
        }
 }
 
@@ -778,7 +782,7 @@ void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
                WM_window_set_dpi(win);
                screen_refresh_headersizes();
 
-               screen_test_scale(win, screen, screen_size_x, screen_size_y);
+               screen_vertices_scale(win, screen, window_size_x, 
window_size_y, screen_size_x, screen_size_y);
 
                if (screen->mainwin == 0) {
                        screen->mainwin = wm_subwindow_open(win, &window_rect, 
false);
@@ -831,11 +835,13 @@ void ED_screen_ensure_updated(wmWindowManager *wm, 
wmWindow *win, bScreen *scree
                ED_screen_refresh(wm, win);
        }
        else {
+               const int window_size_x = WM_window_pixels_x(win);
+               const int window_size_y = WM_window_pixels_y(win);
                const int screen_size_x = WM_window_screen_pixels_x(win);
                const int screen_size_y = WM_window_screen_pixels_y(win);
                bool has_updated = false;
 
-               screen_test_scale(win, screen, screen_size_x, screen_size_y);
+               screen_vertices_scale(win, screen, window_size_x, 
window_size_y, screen_size_x, screen_size_y);
 
                ED_screen_areas_iter(win, screen, area) {
                        if (area->flag & AREA_FLAG_REGION_SIZE_UPDATE) {
diff --git a/source/blender/makesdna/DNA_screen_types.h 
b/source/blender/makesdna/DNA_screen_types.h
index 127966340f2..54cd4082d9d 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -70,7 +70,8 @@ typedef struct bScreen {
        char skip_handling;                                     /* set to delay 
screen handling after switching back from maximized area */
        char scrubbing;                                         /* set when 
scrubbing to avoid some costly updates */
        char pad[6];
-       
+
+       /* XXX mainwin is actually entire window content now, including global 
bars. Should be moved out of bScreen. */
        short mainwin;                                          /* screensize 
subwindow, for screenedges and global menus */
        short subwinactive;                                     /* active 
subwindow */
 
diff --git a/source/blender/windowmanager/intern/wm_subwindow.c 
b/source/blender/windowmanager/intern/wm_subwindow.c
index d80486998bd..57085d4f4bd 100644
--- a/source/blender/windowmanager/intern/wm_subwindow.c
+++ b/source/blender/windowmanager/intern/wm_subwindow.c
@@ -245,8 +245,8 @@ void wm_subwindow_position(wmWindow *win, int swinid, const 
rcti *winrct, bool a
        wmSubWindow *swin = swin_from_swinid(win, swinid);
        
        if (swin) {
-               const int screen_size_x = WM_window_pixels_x(win);
-               const int screen_size_y = WM_window_pixels_y(win);
+               const int window_size_x = WM_window_pixels_x(win);
+               const int window_size_y = WM_window_pixels_y(win);
 
                int width, height;
                
@@ -265,10 +265,10 @@ void wm_subwindow_position(wmWindow *win, int swinid, 
const rcti *winrct, bool a
                 * fixed it). - zr  (2001!)
                 */
                
-               if (swin->winrct.xmax > screen_size_x)
-                       swin->winrct.xmax = screen_size_x;
-               if (swin->winrct.ymax > screen_size_y)
-                       swin->winrct.ymax = screen_size_y;
+               if (swin->winrct.xmax > window_size_x)
+                       swin->winrct.xmax = window_size_x;
+               if (swin->winrct.ymax > window_size_y)
+                       swin->winrct.ymax = window_size_y;
                
                if (activate) {
                        /* extra service */
diff --git a/source/blender/windowmanager/intern/wm_window.c 
b/source/blender/windowmanager/intern/wm_window.c
index d82c3f4cf97..978e247b701 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -1934,7 +1934,7 @@ int WM_window_screen_pixels_y(const wmWindow *win)
        short screen_size_y = WM_window_pixels_y(win);
 
        for (ScrArea *sa = win->global_areas.first; sa; sa = sa->next) {
-               screen_size_y -= sa->winy;
+               screen_size_y 

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to