Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_style.c
| Show First 20 Lines • Show All 213 Lines • ▼ Show 20 Lines | void UI_fontstyle_draw(const uiFontStyle *fs, | ||||
| const uchar col[4], | const uchar col[4], | ||||
| const struct uiFontStyleDraw_Params *fs_params) | const struct uiFontStyleDraw_Params *fs_params) | ||||
| { | { | ||||
| int xofs, yofs; | int xofs, yofs; | ||||
| UI_fontstyle_draw_ex(fs, rect, str, col, fs_params, BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs, NULL); | UI_fontstyle_draw_ex(fs, rect, str, col, fs_params, BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs, NULL); | ||||
| } | } | ||||
| /* drawn same as above, but at 90 degree angle */ | |||||
| void UI_fontstyle_draw_rotated(const uiFontStyle *fs, | void UI_fontstyle_draw_rotated(const uiFontStyle *fs, | ||||
| const rcti *rect, | const rcti *rect, | ||||
| const char *str, | const char *str, | ||||
| const uchar col[4]) | const uchar col[4]) | ||||
| { | { | ||||
| float height; | float height; | ||||
| int xofs, yofs; | int xofs, yofs; | ||||
| float angle; | float angle; | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | void UI_fontstyle_draw_rotated(const uiFontStyle *fs, | ||||
| BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); | BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); | ||||
| BLF_disable(fs->uifont_id, BLF_ROTATION); | BLF_disable(fs->uifont_id, BLF_ROTATION); | ||||
| BLF_disable(fs->uifont_id, BLF_CLIPPING); | BLF_disable(fs->uifont_id, BLF_CLIPPING); | ||||
| if (fs->shadow) { | if (fs->shadow) { | ||||
| BLF_disable(fs->uifont_id, BLF_SHADOW); | BLF_disable(fs->uifont_id, BLF_SHADOW); | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * Similar to #UI_fontstyle_draw | |||||
| * but ignore alignment, shadow & no clipping rect. | |||||
| * | |||||
| * For drawing on-screen labels. | |||||
| */ | |||||
| void UI_fontstyle_draw_simple( | void UI_fontstyle_draw_simple( | ||||
| const uiFontStyle *fs, float x, float y, const char *str, const uchar col[4]) | const uiFontStyle *fs, float x, float y, const char *str, const uchar col[4]) | ||||
| { | { | ||||
| UI_fontstyle_set(fs); | UI_fontstyle_set(fs); | ||||
| BLF_position(fs->uifont_id, x, y, 0.0f); | BLF_position(fs->uifont_id, x, y, 0.0f); | ||||
| BLF_color4ubv(fs->uifont_id, col); | BLF_color4ubv(fs->uifont_id, col); | ||||
| BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); | BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); | ||||
| } | } | ||||
| /** | |||||
| * Same as #UI_fontstyle_draw but draw a colored backdrop. | |||||
| */ | |||||
| void UI_fontstyle_draw_simple_backdrop(const uiFontStyle *fs, | void UI_fontstyle_draw_simple_backdrop(const uiFontStyle *fs, | ||||
| float x, | float x, | ||||
| float y, | float y, | ||||
| const char *str, | const char *str, | ||||
| const float col_fg[4], | const float col_fg[4], | ||||
| const float col_bg[4]) | const float col_bg[4]) | ||||
| { | { | ||||
| UI_fontstyle_set(fs); | UI_fontstyle_set(fs); | ||||
| Show All 18 Lines | void UI_fontstyle_draw_simple_backdrop(const uiFontStyle *fs, | ||||
| } | } | ||||
| BLF_position(fs->uifont_id, x, y, 0.0f); | BLF_position(fs->uifont_id, x, y, 0.0f); | ||||
| BLF_color4fv(fs->uifont_id, col_fg); | BLF_color4fv(fs->uifont_id, col_fg); | ||||
| BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); | BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); | ||||
| } | } | ||||
| /* ************** helpers ************************ */ | /* ************** helpers ************************ */ | ||||
| /* XXX: read a style configure */ | |||||
| const uiStyle *UI_style_get(void) | const uiStyle *UI_style_get(void) | ||||
| { | { | ||||
| #if 0 | #if 0 | ||||
| uiStyle *style = NULL; | uiStyle *style = NULL; | ||||
| /* offset is two struct uiStyle pointers */ | /* offset is two struct uiStyle pointers */ | ||||
| style = BLI_findstring(&U.uistyles, "Unifont Style", sizeof(style) * 2); | style = BLI_findstring(&U.uistyles, "Unifont Style", sizeof(style) * 2); | ||||
| return (style != NULL) ? style : U.uistyles.first; | return (style != NULL) ? style : U.uistyles.first; | ||||
| #else | #else | ||||
| return U.uistyles.first; | return U.uistyles.first; | ||||
| #endif | #endif | ||||
| } | } | ||||
| /* for drawing, scaled with DPI setting */ | |||||
| const uiStyle *UI_style_get_dpi(void) | const uiStyle *UI_style_get_dpi(void) | ||||
| { | { | ||||
| const uiStyle *style = UI_style_get(); | const uiStyle *style = UI_style_get(); | ||||
| static uiStyle _style; | static uiStyle _style; | ||||
| _style = *style; | _style = *style; | ||||
| _style.paneltitle.shadx = (short)(UI_DPI_FAC * _style.paneltitle.shadx); | _style.paneltitle.shadx = (short)(UI_DPI_FAC * _style.paneltitle.shadx); | ||||
| Show All 15 Lines | |||||
| } | } | ||||
| int UI_fontstyle_string_width(const uiFontStyle *fs, const char *str) | int UI_fontstyle_string_width(const uiFontStyle *fs, const char *str) | ||||
| { | { | ||||
| UI_fontstyle_set(fs); | UI_fontstyle_set(fs); | ||||
| return (int)BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); | return (int)BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); | ||||
| } | } | ||||
| /** | |||||
| * Return the width of `str` with the spacing & kerning of `fs` with `aspect` | |||||
| * (representing #uiBlock.aspect) applied. | |||||
| * | |||||
| * When calculating text width, the UI layout logic calculate widths without scale, | |||||
| * only applying scale when drawing. This causes problems for fonts since kerning at | |||||
| * smaller sizes often makes them wider than a scaled down version of the larger text. | |||||
| * Resolve this by calculating the text at the on-screen size, | |||||
| * returning the result scaled back to 1:1. See T92361. | |||||
| */ | |||||
| int UI_fontstyle_string_width_with_block_aspect(const uiFontStyle *fs, | int UI_fontstyle_string_width_with_block_aspect(const uiFontStyle *fs, | ||||
| const char *str, | const char *str, | ||||
| const float aspect) | const float aspect) | ||||
| { | { | ||||
| uiFontStyle fs_buf; | uiFontStyle fs_buf; | ||||
| if (aspect != 1.0f) { | if (aspect != 1.0f) { | ||||
| fs_buf = *fs; | fs_buf = *fs; | ||||
| ui_fontscale(&fs_buf.points, aspect); | ui_fontscale(&fs_buf.points, aspect); | ||||
| Show All 13 Lines | |||||
| int UI_fontstyle_height_max(const uiFontStyle *fs) | int UI_fontstyle_height_max(const uiFontStyle *fs) | ||||
| { | { | ||||
| UI_fontstyle_set(fs); | UI_fontstyle_set(fs); | ||||
| return BLF_height_max(fs->uifont_id); | return BLF_height_max(fs->uifont_id); | ||||
| } | } | ||||
| /* ************** init exit ************************ */ | /* ************** init exit ************************ */ | ||||
| /* called on each startup.blend read */ | |||||
| /* reading without uifont will create one */ | |||||
| void uiStyleInit(void) | void uiStyleInit(void) | ||||
| { | { | ||||
| const uiStyle *style = U.uistyles.first; | const uiStyle *style = U.uistyles.first; | ||||
| /* recover from uninitialized dpi */ | /* recover from uninitialized dpi */ | ||||
| if (U.dpi == 0) { | if (U.dpi == 0) { | ||||
| U.dpi = 72; | U.dpi = 72; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 139 Lines • Show Last 20 Lines | |||||