diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-04-28 21:39:18 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-04-28 21:49:46 +0300 |
commit | b5d3fcc9f5c80c459cce2b895f3d6091a59d0571 (patch) | |
tree | be348452f2f062e7a4e901f56c108cd61748a4ea /source | |
parent | e87dd9aa006ff8816c5c5258a91061cec299f446 (diff) |
Python/UI: add more convenient API for drawing based on DPI.
system.ui_scale: size multiplier to use when drawing custom UI elements.
system.ui_line_width: suggested line thickness and point size in pixels.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/include/UI_interface.h | 2 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_userdef_types.h | 14 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_userdef.c | 23 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_window.c | 1 |
4 files changed, 25 insertions, 15 deletions
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 9f41f9175c4..7fd48ce081c 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -230,7 +230,7 @@ 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_FAC (U.dpi_fac) /* 16 to copy ICON_DEFAULT_HEIGHT */ #define UI_DPI_ICON_SIZE ((float)16 * UI_DPI_FAC) diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h index 7b2ad060e61..88cbd848387 100644 --- a/source/blender/makesdna/DNA_userdef_types.h +++ b/source/blender/makesdna/DNA_userdef_types.h @@ -487,12 +487,16 @@ typedef struct UserDef { int audioformat; int audiochannels; + float ui_scale; /* setting for UI scale */ + int ui_line_width; /* setting for UI line width */ + int dpi; /* runtime, full DPI divided by pixelsize */ + float dpi_fac; /* runtime, multiplier to scale UI elements based on DPI */ + float pixelsize; /* runtime, line width and point size based on DPI */ + int virtual_pixel; /* deprecated, for forward compatibility */ + int scrollback; /* console scrollback limit */ - int dpi; /* range 48-128? */ - float ui_scale; /* interface scale */ - int ui_line_width; /* interface line width */ char node_margin; /* node insert offset (aka auto-offset) margin, but might be useful for later stuff as well */ - char pad2; + char pad2[5]; short transopts; /* eUserpref_Translation_Flags */ short menuthreshold1, menuthreshold2; @@ -583,8 +587,6 @@ typedef struct UserDef { int compute_device_id; float fcu_inactive_alpha; /* opacity of inactive F-Curves in F-Curve Editor */ - float pixelsize; /* private, set by GHOST, to multiply DPI with */ - int virtual_pixel; /* virtual pixelsize mode */ short pie_interaction_type; /* if keeping a pie menu spawn button pressed after this time, it turns into * a drag/release pie menu */ diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 03034522d30..c50d09746ad 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -3957,20 +3957,27 @@ static void rna_def_userdef_system(BlenderRNA *brna) RNA_def_property_ui_text(prop, "International Fonts", "Use international fonts"); RNA_def_property_update(prop, NC_WINDOW, "rna_userdef_language_update"); + prop = RNA_def_property(srna, "ui_scale", PROP_FLOAT, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_float_sdna(prop, NULL, "dpi_fac"); + RNA_def_property_ui_text(prop, "UI Scale", + "Size multiplier to use when drawing custom user interface elements, so that " + "they are scaled correctly on screens with different DPI. This value is based " + "on operating system DPI settings and Blender display scale"); + + prop = RNA_def_property(srna, "ui_line_width", PROP_FLOAT, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_float_sdna(prop, NULL, "pixelsize"); + RNA_def_property_ui_text(prop, "UI Line Width", + "Suggested line thickness and point size in pixels, for add-ons drawing custom " + "user interface elements, based on operating system settings and Blender UI scale"); + prop = RNA_def_property(srna, "dpi", PROP_INT, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); - RNA_def_property_ui_text(prop, "DPI", - "DPI for add-ons to use when drawing custom user interface elements, controlled by " - "operating system settings and Blender UI scale, with a reference value of 72 DPI " - "(note that since this value includes a user defined scale, it is not always the " - "actual monitor DPI)"); prop = RNA_def_property(srna, "pixel_size", PROP_FLOAT, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_float_sdna(prop, NULL, "pixelsize"); - RNA_def_property_ui_text(prop, "Pixel Size", - "Suggested line thickness and point size in pixels, for add-ons drawing custom user " - "interface elements, controlled by operating system settings and Blender UI scale"); prop = RNA_def_property(srna, "font_path_ui", PROP_STRING, PROP_FILEPATH); RNA_def_property_string_sdna(prop, NULL, "font_path_ui"); diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index e0a1f0f14ad..2d94cc1dae7 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -602,6 +602,7 @@ void WM_window_set_dpi(wmWindow *win) U.dpi = dpi / pixelsize; U.virtual_pixel = (pixelsize == 1) ? VIRTUAL_PIXEL_NATIVE : VIRTUAL_PIXEL_DOUBLE; U.widget_unit = (U.pixelsize * U.dpi * 20 + 36) / 72; + U.dpi_fac = ((U.pixelsize * (float)U.dpi) / 72.0f); /* update font drawing */ BLF_default_dpi(U.pixelsize * U.dpi); |