Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_style.c
| Show First 20 Lines • Show All 139 Lines • ▼ Show 20 Lines | for (; font; font = font->next) { | ||||
| } | } | ||||
| } | } | ||||
| return U.uifonts.first; | return U.uifonts.first; | ||||
| } | } | ||||
| /* *************** draw ************************ */ | /* *************** draw ************************ */ | ||||
| void uiStyleFontDrawExt(uiFontStyle *fs, const rcti *rect, const char *str, | void UI_fontstyle_draw_ex(uiFontStyle *fs, const rcti *rect, const char *str, | ||||
| size_t len, float *r_xofs, float *r_yofs) | size_t len, float *r_xofs, float *r_yofs) | ||||
| { | { | ||||
| float height; | float height; | ||||
| int xofs = 0, yofs; | int xofs = 0, yofs; | ||||
| uiStyleFontSet(fs); | UI_fontstyle_set(fs); | ||||
| height = BLF_ascender(fs->uifont_id); | height = BLF_ascender(fs->uifont_id); | ||||
| yofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height)); | yofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height)); | ||||
| if (fs->align == UI_STYLE_TEXT_CENTER) { | if (fs->align == UI_STYLE_TEXT_CENTER) { | ||||
| xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len))); | xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len))); | ||||
| /* don't center text if it chops off the start of the text, 2 gives some margin */ | /* don't center text if it chops off the start of the text, 2 gives some margin */ | ||||
| if (xofs < 2) { | if (xofs < 2) { | ||||
| Show All 24 Lines | if (fs->shadow) | ||||
| BLF_disable(fs->uifont_id, BLF_SHADOW); | BLF_disable(fs->uifont_id, BLF_SHADOW); | ||||
| if (fs->kerning == 1) | if (fs->kerning == 1) | ||||
| BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT); | BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT); | ||||
| *r_xofs = xofs; | *r_xofs = xofs; | ||||
| *r_yofs = yofs; | *r_yofs = yofs; | ||||
| } | } | ||||
| void uiStyleFontDraw(uiFontStyle *fs, const rcti *rect, const char *str) | void UI_fontstyle_draw(uiFontStyle *fs, const rcti *rect, const char *str) | ||||
| { | { | ||||
| float xofs, yofs; | float xofs, yofs; | ||||
| uiStyleFontDrawExt(fs, rect, str, | UI_fontstyle_draw_ex(fs, rect, str, | ||||
| BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs); | BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs); | ||||
| } | } | ||||
| /* drawn same as above, but at 90 degree angle */ | /* drawn same as above, but at 90 degree angle */ | ||||
| void uiStyleFontDrawRotated(uiFontStyle *fs, const rcti *rect, const char *str) | void UI_fontstyle_draw_rotated(uiFontStyle *fs, const rcti *rect, const char *str) | ||||
| { | { | ||||
| float height; | float height; | ||||
| int xofs, yofs; | int xofs, yofs; | ||||
| float angle; | float angle; | ||||
| rcti txtrect; | rcti txtrect; | ||||
| uiStyleFontSet(fs); | UI_fontstyle_set(fs); | ||||
| height = BLF_ascender(fs->uifont_id); | height = BLF_ascender(fs->uifont_id); | ||||
| /* becomes x-offset when rotated */ | /* becomes x-offset when rotated */ | ||||
| xofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height)); | xofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height)); | ||||
| /* ignore UI_STYLE, always aligned to top */ | /* ignore UI_STYLE, always aligned to top */ | ||||
| /* rotate counter-clockwise for now (assumes left-to-right language)*/ | /* rotate counter-clockwise for now (assumes left-to-right language)*/ | ||||
| Show All 31 Lines | void UI_fontstyle_draw_rotated(uiFontStyle *fs, const rcti *rect, const char *str) | ||||
| if (fs->shadow) | if (fs->shadow) | ||||
| BLF_disable(fs->uifont_id, BLF_SHADOW); | BLF_disable(fs->uifont_id, BLF_SHADOW); | ||||
| if (fs->kerning == 1) | if (fs->kerning == 1) | ||||
| BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT); | BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT); | ||||
| } | } | ||||
| /* ************** helpers ************************ */ | /* ************** helpers ************************ */ | ||||
| /* XXX: read a style configure */ | /* XXX: read a style configure */ | ||||
| uiStyle *UI_GetStyle(void) | uiStyle *UI_style_get(void) | ||||
| { | { | ||||
| 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; | ||||
| } | } | ||||
| /* for drawing, scaled with DPI setting */ | /* for drawing, scaled with DPI setting */ | ||||
| uiStyle *UI_GetStyleDraw(void) | uiStyle *UI_style_get_dpi(void) | ||||
| { | { | ||||
| uiStyle *style = UI_GetStyle(); | 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); | ||||
| _style.paneltitle.shady = (short)(UI_DPI_FAC * _style.paneltitle.shady); | _style.paneltitle.shady = (short)(UI_DPI_FAC * _style.paneltitle.shady); | ||||
| _style.grouplabel.shadx = (short)(UI_DPI_FAC * _style.grouplabel.shadx); | _style.grouplabel.shadx = (short)(UI_DPI_FAC * _style.grouplabel.shadx); | ||||
| _style.grouplabel.shady = (short)(UI_DPI_FAC * _style.grouplabel.shady); | _style.grouplabel.shady = (short)(UI_DPI_FAC * _style.grouplabel.shady); | ||||
| _style.widgetlabel.shadx = (short)(UI_DPI_FAC * _style.widgetlabel.shadx); | _style.widgetlabel.shadx = (short)(UI_DPI_FAC * _style.widgetlabel.shadx); | ||||
| _style.widgetlabel.shady = (short)(UI_DPI_FAC * _style.widgetlabel.shady); | _style.widgetlabel.shady = (short)(UI_DPI_FAC * _style.widgetlabel.shady); | ||||
| _style.columnspace = (short)(UI_DPI_FAC * _style.columnspace); | _style.columnspace = (short)(UI_DPI_FAC * _style.columnspace); | ||||
| _style.templatespace = (short)(UI_DPI_FAC * _style.templatespace); | _style.templatespace = (short)(UI_DPI_FAC * _style.templatespace); | ||||
| _style.boxspace = (short)(UI_DPI_FAC * _style.boxspace); | _style.boxspace = (short)(UI_DPI_FAC * _style.boxspace); | ||||
| _style.buttonspacex = (short)(UI_DPI_FAC * _style.buttonspacex); | _style.buttonspacex = (short)(UI_DPI_FAC * _style.buttonspacex); | ||||
| _style.buttonspacey = (short)(UI_DPI_FAC * _style.buttonspacey); | _style.buttonspacey = (short)(UI_DPI_FAC * _style.buttonspacey); | ||||
| _style.panelspace = (short)(UI_DPI_FAC * _style.panelspace); | _style.panelspace = (short)(UI_DPI_FAC * _style.panelspace); | ||||
| _style.panelouter = (short)(UI_DPI_FAC * _style.panelouter); | _style.panelouter = (short)(UI_DPI_FAC * _style.panelouter); | ||||
| return &_style; | return &_style; | ||||
| } | } | ||||
| /* temporarily, does widget font */ | /* temporarily, does widget font */ | ||||
| int UI_GetStringWidth(const char *str) | int UI_fontstyle_string_width(const char *str) | ||||
| { | { | ||||
| uiStyle *style = UI_GetStyle(); | uiStyle *style = UI_style_get(); | ||||
| uiFontStyle *fstyle = &style->widget; | uiFontStyle *fstyle = &style->widget; | ||||
| int width; | int width; | ||||
| if (fstyle->kerning == 1) /* for BLF_width */ | if (fstyle->kerning == 1) /* for BLF_width */ | ||||
| BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | ||||
| uiStyleFontSet(fstyle); | UI_fontstyle_set(fstyle); | ||||
| width = BLF_width(fstyle->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); | width = BLF_width(fstyle->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); | ||||
| if (fstyle->kerning == 1) | if (fstyle->kerning == 1) | ||||
| BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); | ||||
| return width; | return width; | ||||
| } | } | ||||
| /* temporarily, does widget font */ | /* temporarily, does widget font */ | ||||
| void UI_DrawString(float x, float y, const char *str) | void UI_draw_string(float x, float y, const char *str) | ||||
| { | { | ||||
| uiStyle *style = UI_GetStyle(); | uiStyle *style = UI_style_get(); | ||||
| if (style->widget.kerning == 1) | if (style->widget.kerning == 1) | ||||
| BLF_enable(style->widget.uifont_id, BLF_KERNING_DEFAULT); | BLF_enable(style->widget.uifont_id, BLF_KERNING_DEFAULT); | ||||
| uiStyleFontSet(&style->widget); | UI_fontstyle_set(&style->widget); | ||||
| BLF_position(style->widget.uifont_id, x, y, 0.0f); | BLF_position(style->widget.uifont_id, x, y, 0.0f); | ||||
| BLF_draw(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); | BLF_draw(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); | ||||
| if (style->widget.kerning == 1) | if (style->widget.kerning == 1) | ||||
| BLF_disable(style->widget.uifont_id, BLF_KERNING_DEFAULT); | BLF_disable(style->widget.uifont_id, BLF_KERNING_DEFAULT); | ||||
| } | } | ||||
| /* ************** init exit ************************ */ | /* ************** init exit ************************ */ | ||||
| ▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | #endif | ||||
| /* second for rendering else we get threading problems */ | /* second for rendering else we get threading problems */ | ||||
| if (blf_mono_font_render == -1) | if (blf_mono_font_render == -1) | ||||
| blf_mono_font_render = BLF_load_mem_unique("monospace", monofont_ttf, monofont_size); | blf_mono_font_render = BLF_load_mem_unique("monospace", monofont_ttf, monofont_size); | ||||
| BLF_size(blf_mono_font_render, 12 * U.pixelsize, 72); | BLF_size(blf_mono_font_render, 12 * U.pixelsize, 72); | ||||
| } | } | ||||
| void uiStyleFontSet(uiFontStyle *fs) | void UI_fontstyle_set(uiFontStyle *fs) | ||||
| { | { | ||||
| uiFont *font = uifont_to_blfont(fs->uifont_id); | uiFont *font = uifont_to_blfont(fs->uifont_id); | ||||
| BLF_size(font->blf_id, fs->points * U.pixelsize, U.dpi); | BLF_size(font->blf_id, fs->points * U.pixelsize, U.dpi); | ||||
| } | } | ||||