diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-01-20 07:48:40 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-01-20 07:50:20 +0300 |
commit | 289960787ea70b1d1acd528bee71e8f8439bf369 (patch) | |
tree | d6479b09269c5e22f9a2cfa3086205a378a9019c /source/blender/editors/interface | |
parent | 09eec627ed730532905b45d409f9009023623437 (diff) |
Fix UI glitches drawing text at different sizes
Font height was ignoring DPI in some cases (camera-name & eyedropper).
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r-- | source/blender/editors/interface/interface_eyedropper.c | 15 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_style.c | 49 |
2 files changed, 54 insertions, 10 deletions
diff --git a/source/blender/editors/interface/interface_eyedropper.c b/source/blender/editors/interface/interface_eyedropper.c index dfcafd7e46e..ec1234a82be 100644 --- a/source/blender/editors/interface/interface_eyedropper.c +++ b/source/blender/editors/interface/interface_eyedropper.c @@ -77,7 +77,9 @@ static void eyedropper_draw_cursor_text(const struct bContext *C, ARegion *ar, c wmWindow *win = CTX_wm_window(C); int x = win->eventstate->x; int y = win->eventstate->y; - int width; + const unsigned char fg[4] = {255, 255, 255, 255}; + const unsigned char bg[4] = {0, 0, 0, 50}; + if ((name[0] == '\0') || (BLI_rcti_isect_pt(&ar->winrct, x, y) == false)) @@ -85,19 +87,12 @@ static void eyedropper_draw_cursor_text(const struct bContext *C, ARegion *ar, c return; } - width = UI_fontstyle_string_width(fstyle, name); x = x - ar->winrct.xmin; y = y - ar->winrct.ymin; - y += 20; - - glColor4ub(0, 0, 0, 50); - - UI_draw_roundbox_corner_set(UI_CNR_ALL | UI_RB_ALPHA); - UI_draw_roundbox(x, y, x + width + 8, y + 15, 4); + y += U.widget_unit; - glColor4ub(255, 255, 255, 255); - UI_fontstyle_draw_simple(fstyle, x + 4, y + 4, name); + UI_fontstyle_draw_simple_backdrop(fstyle, x, y, name, fg, bg); } /** \} */ diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 2fe44b2a9b6..c42c911cd5c 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -45,6 +45,7 @@ #include "BKE_global.h" +#include "BIF_gl.h" #include "BLF_api.h" #ifdef WITH_INTERNATIONAL @@ -277,6 +278,47 @@ void UI_fontstyle_draw_simple(const uiFontStyle *fs, float x, float y, const cha BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT); } +/** + * Same as #UI_fontstyle_draw but draw a colored backdrop. + */ +void UI_fontstyle_draw_simple_backdrop( + const uiFontStyle *fs, float x, float y, const char *str, + const unsigned char fg[4], const unsigned char bg[4]) +{ + if (fs->kerning == 1) + BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT); + + UI_fontstyle_set(fs); + + { + const float width = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); + const float height = BLF_height_max(fs->uifont_id); + const float decent = BLF_descender(fs->uifont_id); + const float margin = height / 4.0f; + + /* backdrop */ + glColor4ubv(bg); + + UI_draw_roundbox_corner_set(UI_CNR_ALL | UI_RB_ALPHA); + UI_draw_roundbox( + x - margin, + (y + decent) - margin, + x + width + margin, + (y + decent) + height + margin, + margin); + + glColor4ubv(fg); + } + + + BLF_position(fs->uifont_id, x, y, 0.0f); + BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); + + if (fs->kerning == 1) + BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT); +} + + /* ************** helpers ************************ */ /* XXX: read a style configure */ uiStyle *UI_style_get(void) @@ -329,6 +371,13 @@ int UI_fontstyle_string_width(const uiFontStyle *fs, const char *str) return width; } +int UI_fontstyle_height_max(const uiFontStyle *fs) +{ + UI_fontstyle_set(fs); + return BLF_height_max(fs->uifont_id); +} + + /* ************** init exit ************************ */ /* called on each startup.blend read */ |