Fix T51248: user preferences window size not adapted to DPI.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 19 Apr 2017 22:17:42 +0000 (00:17 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Wed, 19 Apr 2017 23:19:47 +0000 (01:19 +0200)
source/blender/editors/include/UI_interface.h
source/blender/editors/render/render_view.c
source/blender/editors/screen/screen_ops.c
source/blender/editors/space_node/drawnode.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_operators.c
source/blender/windowmanager/intern/wm_window.c

index 4945406c57b1149aeeeeb8c64127955b618016a9..a9e94b05da49238f4e42585c4fb6ab45477f0f51 100644 (file)
@@ -217,7 +217,6 @@ enum {
 /* scale fixed button widths by this to account for DPI */
 
 #define UI_DPI_FAC ((U.pixelsize * (float)U.dpi) / 72.0f)
-#define UI_DPI_WINDOW_FAC (((float)U.dpi) / 72.0f)
 /* 16 to copy ICON_DEFAULT_HEIGHT */
 #define UI_DPI_ICON_SIZE ((float)16 * UI_DPI_FAC)
 
index 65f0fec50bcd2245c9f92970e4d9cdea933ebe1b..c4a9af79ec28fba82f987e400bd4c0381ce70c6d 100644 (file)
@@ -44,6 +44,7 @@
 #include "WM_types.h"
 
 #include "ED_screen.h"
+#include "UI_interface.h"
 
 #include "wm_window.h"
 
@@ -128,8 +129,8 @@ static ScrArea *find_area_image_empty(bContext *C)
 /* new window uses x,y to set position */
 ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports)
 {
-       wmWindow *win = CTX_wm_window(C);
        Scene *scene = CTX_data_scene(C);
+       wmWindow *win = NULL;
        ScrArea *sa = NULL;
        SpaceImage *sima;
        bool area_was_image = false;
@@ -138,25 +139,15 @@ ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports)
                return NULL;
        
        if (scene->r.displaymode == R_OUTPUT_WINDOW) {
-               rcti rect;
-               int sizex, sizey;
-
-               sizex = 10 + (scene->r.xsch * scene->r.size) / 100;
-               sizey = 40 + (scene->r.ysch * scene->r.size) / 100;
+               int sizex = 30 * UI_DPI_FAC + (scene->r.xsch * scene->r.size) / 100;
+               int sizey = 60 * UI_DPI_FAC + (scene->r.ysch * scene->r.size) / 100;
 
                /* arbitrary... miniature image window views don't make much sense */
                if (sizex < 320) sizex = 320;
                if (sizey < 256) sizey = 256;
 
-               /* some magic to calculate postition */
-               /* pixelsize: mouse coords are in U.pixelsize units :/ */
-               rect.xmin = (mx / U.pixelsize) + win->posx - sizex / 2;
-               rect.ymin = (my / U.pixelsize) + win->posy - sizey / 2;
-               rect.xmax = rect.xmin + sizex;
-               rect.ymax = rect.ymin + sizey;
-
                /* changes context! */
-               if (WM_window_open_temp(C, &rect, WM_WINDOW_RENDER) == NULL) {
+               if (WM_window_open_temp(C, mx, my, sizex, sizey, WM_WINDOW_RENDER) == NULL) {
                        BKE_report(reports, RPT_ERROR, "Failed to open window!");
                        return NULL;
                }
index c2e094fc161dbb82e38d4966ef4c63acef1c7e27..9dbc082c1193e8af75d6039ffc768f8186e9920e 100644 (file)
@@ -3883,22 +3883,11 @@ static void SCREEN_OT_back_to_previous(struct wmOperatorType *ot)
 
 static int userpref_show_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 {
-       wmWindow *win = CTX_wm_window(C);
-       rcti rect;
-       int sizex, sizey;
-       
-       sizex = 800 * UI_DPI_WINDOW_FAC;
-       sizey = 480 * UI_DPI_WINDOW_FAC;
-       
-       /* some magic to calculate postition */
-       /* pixelsize: mouse coords are in U.pixelsize units :/ */
-       rect.xmin = (event->x / U.pixelsize) + win->posx - sizex / 2;
-       rect.ymin = (event->y / U.pixelsize) + win->posy - sizey / 2;
-       rect.xmax = rect.xmin + sizex;
-       rect.ymax = rect.ymin + sizey;
+       int sizex = 800 * UI_DPI_FAC;
+       int sizey = 480 * UI_DPI_FAC;
        
        /* changes context! */
-       if (WM_window_open_temp(C, &rect, WM_WINDOW_USERPREFS) != NULL) {
+       if (WM_window_open_temp(C, event->x, event->y, sizex, sizey, WM_WINDOW_USERPREFS) != NULL) {
                return OPERATOR_FINISHED;
        }
        else {
index 8dba0e3952407242dec3a23b34816eeace1aeab7..2a63d09411690d0064c16bc93f861f00f2c55a9b 100644 (file)
@@ -3425,7 +3425,6 @@ void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link,
                /* store current linewidth */
                float linew;
                float arrow[2], arrow1[2], arrow2[2];
-               const float px_fac = UI_DPI_WINDOW_FAC;
                glGetFloatv(GL_LINE_WIDTH, &linew);
                
                /* we can reuse the dist variable here to increment the GL curve eval amount*/
@@ -3452,7 +3451,7 @@ void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link,
                }
                if (do_triple) {
                        UI_ThemeColorShadeAlpha(th_col3, -80, -120);
-                       glLineWidth(4.0f * px_fac);
+                       glLineWidth(4.0f);
                        
                        glBegin(GL_LINE_STRIP);
                        for (i = 0; i <= LINK_RESOL; i++) {
@@ -3472,7 +3471,7 @@ void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link,
                 * for Intel hardware, this breaks with GL_LINE_STRIP and
                 * changing color in begin/end blocks.
                 */
-               glLineWidth(1.5f * px_fac);
+               glLineWidth(1.5f);
                if (do_shaded) {
                        glBegin(GL_LINES);
                        for (i = 0; i < LINK_RESOL; i++) {
index 1cfd20defe0fb158dec687ced7e560c30ed78030..492dec2cc10d1ea34fe4813a39dff335e22611ab 100644 (file)
@@ -102,7 +102,7 @@ enum {
 };
 
 struct wmWindow        *WM_window_open(struct bContext *C, const struct rcti *rect);
-struct wmWindow *WM_window_open_temp(struct bContext *C, const struct rcti *rect_init, int type);
+struct wmWindow *WM_window_open_temp(struct bContext *C, int x, int y, int sizex, int sizey, int type);
                        
                        /* returns true if draw method is triple buffer */
 bool           WM_is_draw_triple(struct wmWindow *win);
index d827ccafda8c1c1fea34f4f57fb3927eab1b8275..d3ebd3e4d2ca71905640c87f1fbf3785f75c3186 100644 (file)
@@ -1799,13 +1799,13 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
        if (version_suffix != NULL && version_suffix[0]) {
                /* placed after the version number in the image,
                 * placing y is tricky to match baseline */
-               int x = 260 - (2 * UI_DPI_WINDOW_FAC);
-               int y = 242 + (4 * UI_DPI_WINDOW_FAC);
-               int w = 240;
+               int x = 260 * U.pixelsize - (2 * UI_DPI_FAC);
+               int y = 242 * U.pixelsize + (4 * UI_DPI_FAC);
+               int w = 240 * U.pixelsize;
 
                /* hack to have text draw 'text_sel' */
                UI_block_emboss_set(block, UI_EMBOSS_NONE);
-               but = uiDefBut(block, UI_BTYPE_LABEL, 0, version_suffix, x * U.pixelsize, y * U.pixelsize, w * U.pixelsize, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
+               but = uiDefBut(block, UI_BTYPE_LABEL, 0, version_suffix, x, y, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
                /* XXX, set internal flag - UI_SELECT */
                UI_but_flag_enable(but, 1);
                UI_block_emboss_set(block, UI_EMBOSS);
index aaf77946412cd2ddbcb9f320a5738e7e18678209..de169881bc4274b22be5130ce1e6b2d6eb21b20a 100644 (file)
@@ -642,14 +642,27 @@ wmWindow *WM_window_open(bContext *C, const rcti *rect)
  * \param type: WM_WINDOW_RENDER, WM_WINDOW_USERPREFS...
  * \return the window or NULL.
  */
-wmWindow *WM_window_open_temp(bContext *C, const rcti *rect_init, int type)
+wmWindow *WM_window_open_temp(bContext *C, int x, int y, int sizex, int sizey, int type)
 {
        wmWindow *win_prev = CTX_wm_window(C);
        wmWindow *win;
        ScrArea *sa;
        Scene *scene = CTX_data_scene(C);
        const char *title;
-       rcti rect = *rect_init;
+
+       /* convert to native OS window coordinates */
+       const float native_pixel_size = GHOST_GetNativePixelSize(win_prev->ghostwin);
+       x /= native_pixel_size;
+       y /= native_pixel_size;
+       sizex /= native_pixel_size;
+       sizey /= native_pixel_size;
+
+       /* calculate postition */
+       rcti rect;
+       rect.xmin = x + win_prev->posx - sizex / 2;
+       rect.ymin = y + win_prev->posy - sizey / 2;
+       rect.xmax = rect.xmin + sizex;
+       rect.ymax = rect.ymin + sizey;
 
        /* changes rect to fit within desktop */
        wm_window_check_position(&rect);