diff options
author | Harley Acheson <harley.acheson@gmail.com> | 2022-09-24 03:36:49 +0300 |
---|---|---|
committer | Harley Acheson <harley.acheson@gmail.com> | 2022-09-24 03:36:49 +0300 |
commit | cd1631b17dd0e25a8a398fb00a982ca5f0633558 (patch) | |
tree | ee8d9cdb560c815ea86d952ef2f053c6435865c1 /source/blender/windowmanager | |
parent | 88a602bc64fc2a86411d67881439a04486f95030 (diff) |
BLF: Refactor of DPI
Correction of U.dpi to hold actual monitor DPI. Simplify font sizing by
omitting DPI as API argument, always using 72 internally.
See D15961 for more details.
Differential Revision: https://developer.blender.org/D15961
Reviewed by Campbell Barton
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r-- | source/blender/windowmanager/intern/wm_operators.c | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_playanim.c | 2 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_window.c | 17 |
3 files changed, 8 insertions, 13 deletions
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 259730513be..09e64db6416 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -2521,7 +2521,7 @@ static void radial_control_paint_cursor(bContext *UNUSED(C), int x, int y, void immUnbindProgram(); - BLF_size(fontid, 1.75f * fstyle_points * U.pixelsize, U.dpi); + BLF_size(fontid, 1.75f * fstyle_points * U.dpi_fac); UI_GetThemeColor4fv(TH_TEXT_HI, text_color); BLF_color4fv(fontid, text_color); diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c index e768d18960b..73c7c0a2435 100644 --- a/source/blender/windowmanager/intern/wm_playanim.c +++ b/source/blender/windowmanager/intern/wm_playanim.c @@ -1556,7 +1556,7 @@ static char *wm_main_playanim_intern(int argc, const char **argv) BLF_init(); BLF_load_font_stack(); ps.fontid = BLF_load_mono_default(false); - BLF_size(ps.fontid, 11.0f, 72); + BLF_size(ps.fontid, 11.0f); ps.ibufx = ibuf->x; ps.ibufy = ibuf->y; diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index 8d091a02eb5..436087e1cf3 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -503,27 +503,22 @@ void WM_window_set_dpi(const wmWindow *win) * while Windows and Linux use DPI 96. GHOST assumes a default 96 so we * remap the DPI to Blender's convention. */ auto_dpi *= GHOST_GetNativePixelSize(win->ghostwin); - int dpi = auto_dpi * U.ui_scale * (72.0 / 96.0f); + U.dpi = auto_dpi * U.ui_scale * (72.0 / 96.0f); /* Automatically set larger pixel size for high DPI. */ - int pixelsize = max_ii(1, (int)(dpi / 64)); + int pixelsize = max_ii(1, (int)(U.dpi / 64)); /* User adjustment for pixel size. */ pixelsize = max_ii(1, pixelsize + U.ui_line_width); /* Set user preferences globals for drawing, and for forward compatibility. */ U.pixelsize = pixelsize; - U.dpi = dpi / pixelsize; U.virtual_pixel = (pixelsize == 1) ? VIRTUAL_PIXEL_NATIVE : VIRTUAL_PIXEL_DOUBLE; - U.dpi_fac = ((U.pixelsize * (float)U.dpi) / 72.0f); + U.dpi_fac = U.dpi / 72.0f; U.inv_dpi_fac = 1.0f / U.dpi_fac; - /* Set user preferences globals for drawing, and for forward compatibility. */ - U.widget_unit = (U.pixelsize * U.dpi * 20 + 36) / 72; - /* If line thickness differs from scaling factor then adjustments need to be made */ - U.widget_unit += 2 * ((int)U.pixelsize - (int)U.dpi_fac); - - /* update font drawing */ - BLF_default_dpi(U.pixelsize * U.dpi); + /* Widget unit is 20 pixels at 1X scale. This consists of 18 user-scaled units plus + * left and right borders of line-width (pixelsize). */ + U.widget_unit = (int)roundf(18.0f * U.dpi_fac) + (2 * pixelsize); } static void wm_window_update_eventstate(wmWindow *win) |