diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-01-04 01:58:03 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-01-04 03:00:48 +0300 |
commit | 54a4c1cf359c369c8fc16ecf0ecaa92e6f650e2f (patch) | |
tree | 763437a793072d559095c6bb8d9cf23ca1c111f1 /source/blender/editors/interface | |
parent | 4431c5825bf26d314abe1f79646883fd746e495b (diff) |
UI: refactor layout vars out of uiFontStyle
Word wrap and alignment layout args only used by UI_fontstyle_draw
were vars in uiFontStyle.
These were written to before drawing, so better pass as an argument.
Pass uiFontStyle & uiWidgetColors as const args.
Diffstat (limited to 'source/blender/editors/interface')
7 files changed, 97 insertions, 78 deletions
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c index f1ada343faa..ac3acf5ac53 100644 --- a/source/blender/editors/interface/interface_draw.c +++ b/source/blender/editors/interface/interface_draw.c @@ -634,7 +634,7 @@ void ui_draw_but_TAB_outline(const rcti *rect, float rad, unsigned char highligh immUnbindProgram(); } -void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *rect) +void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, const uiWidgetColors *UNUSED(wcol), const rcti *rect) { #ifdef WITH_HEADLESS (void)rect; @@ -785,7 +785,7 @@ static void histogram_draw_one( #define HISTOGRAM_TOT_GRID_LINES 4 -void ui_draw_but_HISTOGRAM(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti) +void ui_draw_but_HISTOGRAM(ARegion *UNUSED(ar), uiBut *but, const uiWidgetColors *UNUSED(wcol), const rcti *recti) { Histogram *hist = (Histogram *)but->poin; int res = hist->x_resolution; @@ -886,7 +886,7 @@ static void waveform_draw_one(float *waveform, int nbr, const float col[3]) GPU_batch_discard(batch); } -void ui_draw_but_WAVEFORM(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti) +void ui_draw_but_WAVEFORM(ARegion *UNUSED(ar), uiBut *but, const uiWidgetColors *UNUSED(wcol), const rcti *recti) { Scopes *scopes = (Scopes *)but->poin; int scissor[4]; @@ -1174,7 +1174,7 @@ static void vectorscope_draw_target(unsigned int pos, float centerx, float cente immEnd(); } -void ui_draw_but_VECTORSCOPE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti) +void ui_draw_but_VECTORSCOPE(ARegion *UNUSED(ar), uiBut *but, const uiWidgetColors *UNUSED(wcol), const rcti *recti) { const float skin_rad = DEG2RADF(123.0f); /* angle in radians of the skin tone line */ Scopes *scopes = (Scopes *)but->poin; @@ -1402,7 +1402,7 @@ static void ui_draw_colorband_handle( ui_draw_colorband_handle_box(shdr_pos, x - (half_width - 2), y1 + 1, x + (half_width - 2), y1 + height - 2, true); } -void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *rect) +void ui_draw_but_COLORBAND(uiBut *but, const uiWidgetColors *UNUSED(wcol), const rcti *rect) { struct ColorManagedDisplay *display = ui_block_cm_display_get(but->block); uint pos_id, col_id; @@ -1527,7 +1527,7 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti immUnbindProgram(); } -void ui_draw_but_UNITVEC(uiBut *but, uiWidgetColors *wcol, const rcti *rect) +void ui_draw_but_UNITVEC(uiBut *but, const uiWidgetColors *wcol, const rcti *rect) { /* sphere color */ float diffuse[3] = {1.0f, 1.0f, 1.0f}; @@ -1619,7 +1619,7 @@ static void gl_shaded_color(unsigned char *col, int shade) col[2] - shade > 0 ? col[2] - shade : 0); } -void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, const rcti *rect) +void ui_draw_but_CURVE(ARegion *ar, uiBut *but, const uiWidgetColors *wcol, const rcti *rect) { CurveMapping *cumap; @@ -1867,7 +1867,7 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, const rcti immUnbindProgram(); } -void ui_draw_but_TRACKPREVIEW(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti) +void ui_draw_but_TRACKPREVIEW(ARegion *UNUSED(ar), uiBut *but, const uiWidgetColors *UNUSED(wcol), const rcti *recti) { bool ok = false; MovieClipScopes *scopes = (MovieClipScopes *)but->poin; @@ -2000,7 +2000,7 @@ void ui_draw_but_TRACKPREVIEW(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *U GPU_blend(false); } -void ui_draw_but_NODESOCKET(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti) +void ui_draw_but_NODESOCKET(ARegion *ar, uiBut *but, const uiWidgetColors *UNUSED(wcol), const rcti *recti) { static const float size = 5.0f; diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h index a99081d7683..98cda801c9d 100644 --- a/source/blender/editors/interface/interface_intern.h +++ b/source/blender/editors/interface/interface_intern.h @@ -680,15 +680,15 @@ void ui_draw_gradient(const rcti *rect, const float hsv[3], const int type, cons void ui_draw_but_TAB_outline(const rcti *rect, float rad, unsigned char highlight[3], unsigned char highlight_fade[3]); -void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, const rcti *rect); -void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, const rcti *rect); -void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, const rcti *rect); -void ui_draw_but_COLORBAND(uiBut *but, struct uiWidgetColors *wcol, const rcti *rect); -void ui_draw_but_UNITVEC(uiBut *but, struct uiWidgetColors *wcol, const rcti *rect); -void ui_draw_but_CURVE(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, const rcti *rect); -void ui_draw_but_IMAGE(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, const rcti *rect); -void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, const rcti *rect); -void ui_draw_but_NODESOCKET(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, const rcti *rect); +void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, const struct uiWidgetColors *wcol, const rcti *rect); +void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, const struct uiWidgetColors *wcol, const rcti *rect); +void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, const struct uiWidgetColors *wcol, const rcti *rect); +void ui_draw_but_COLORBAND(uiBut *but, const struct uiWidgetColors *wcol, const rcti *rect); +void ui_draw_but_UNITVEC(uiBut *but, const struct uiWidgetColors *wcol, const rcti *rect); +void ui_draw_but_CURVE(ARegion *ar, uiBut *but, const struct uiWidgetColors *wcol, const rcti *rect); +void ui_draw_but_IMAGE(ARegion *ar, uiBut *but, const struct uiWidgetColors *wcol, const rcti *rect); +void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, const struct uiWidgetColors *wcol, const rcti *rect); +void ui_draw_but_NODESOCKET(ARegion *ar, uiBut *but, const struct uiWidgetColors *wcol, const rcti *rect); /* interface_handlers.c */ PointerRNA *ui_handle_afterfunc_add_operator(struct wmOperatorType *ot, int opcontext, bool create_props); @@ -757,7 +757,7 @@ void ui_draw_anti_tria_rect(const rctf *rect, char dir, const float color[4]); void ui_draw_menu_back(struct uiStyle *style, uiBlock *block, rcti *rect); void ui_draw_popover_back(ARegion *ar, struct uiStyle *style, uiBlock *block, rcti *rect); void ui_draw_pie_center(uiBlock *block); -struct uiWidgetColors *ui_tooltip_get_theme(void); +const struct uiWidgetColors *ui_tooltip_get_theme(void); void ui_draw_widget_back_color( uiWidgetTypeEnum type, bool use_shadow, const rcti *rect, @@ -768,8 +768,8 @@ void ui_draw_tooltip_background(struct uiStyle *UNUSED(style), uiBlock *block, r extern void ui_draw_but(const struct bContext *C, ARegion *ar, struct uiStyle *style, uiBut *but, rcti *rect); -void ui_draw_menu_item(struct uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state, bool use_sep); -void ui_draw_preview_item(struct uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state); +void ui_draw_menu_item(const struct uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state, bool use_sep); +void ui_draw_preview_item(const struct uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state); #define UI_TEXT_MARGIN_X 0.4f #define UI_POPUP_MARGIN (UI_DPI_FAC * 12) diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c index 1e97cbc29d0..6c576e20ffb 100644 --- a/source/blender/editors/interface/interface_panel.c +++ b/source/blender/editors/interface/interface_panel.c @@ -658,7 +658,9 @@ static void ui_draw_aligned_panel_header( if (dir == 'h') { hrect.xmin = rect->xmin + pnl_icons; hrect.ymin += 2.0f / block->aspect; - UI_fontstyle_draw(fontstyle, &hrect, activename, col_title); + UI_fontstyle_draw( + fontstyle, &hrect, activename, col_title, + &(struct uiFontStyleDraw_Params) { .align = UI_STYLE_TEXT_LEFT, }); } else { /* ignore 'pnl_icons', otherwise the text gets offset horizontally diff --git a/source/blender/editors/interface/interface_region_search.c b/source/blender/editors/interface/interface_region_search.c index 48d59830c2a..d6e1fcdea24 100644 --- a/source/blender/editors/interface/interface_region_search.c +++ b/source/blender/editors/interface/interface_region_search.c @@ -516,7 +516,6 @@ ARegion *ui_searchbox_create_generic(bContext *C, ARegion *butregion, uiBut *but /* set font, get bb */ data->fstyle = style->widget; /* copy struct */ - data->fstyle.align = UI_STYLE_TEXT_CENTER; ui_fontscale(&data->fstyle.points, aspect); UI_fontstyle_set(&data->fstyle); diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c index 1a167b3fd72..f5575b4c7c2 100644 --- a/source/blender/editors/interface/interface_region_tooltip.c +++ b/source/blender/editors/interface/interface_region_tooltip.c @@ -167,7 +167,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar) { const float pad_px = UI_TIP_PADDING; uiTooltipData *data = ar->regiondata; - uiWidgetColors *theme = ui_tooltip_get_theme(); + const uiWidgetColors *theme = ui_tooltip_get_theme(); rcti bbox = data->bbox; float tip_colors[UI_TIP_LC_MAX][3]; unsigned char drawcol[4] = {0, 0, 0, 255}; /* to store color in while drawing (alpha is always 255) */ @@ -224,15 +224,14 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar) bbox.ymin = bbox.ymax - (data->lineh * field->geom.lines); if (field->format.style == UI_TIP_STYLE_HEADER) { + const struct uiFontStyleDraw_Params fs_params = { + .align = UI_STYLE_TEXT_LEFT, + .word_wrap = true, + }; /* draw header and active data (is done here to be able to change color) */ - uiFontStyle fstyle_header = data->fstyle; - - /* override text-style */ - fstyle_header.word_wrap = true; - rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_MAIN]); - UI_fontstyle_set(&fstyle_header); - UI_fontstyle_draw(&fstyle_header, &bbox, field->text, drawcol); + UI_fontstyle_set(&data->fstyle); + UI_fontstyle_draw(&data->fstyle, &bbox, field->text, drawcol, &fs_params); /* offset to the end of the last line */ if (field->text_suffix) { @@ -242,7 +241,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar) bbox.ymax -= yofs; rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_ACTIVE]); - UI_fontstyle_draw(&fstyle_header, &bbox, field->text_suffix, drawcol); + UI_fontstyle_draw(&data->fstyle, &bbox, field->text_suffix, drawcol, &fs_params); /* undo offset */ bbox.xmin -= xofs; @@ -250,25 +249,30 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar) } } else if (field->format.style == UI_TIP_STYLE_MONO) { + const struct uiFontStyleDraw_Params fs_params = { + .align = UI_STYLE_TEXT_LEFT, + .word_wrap = true, + }; uiFontStyle fstyle_mono = data->fstyle; fstyle_mono.uifont_id = blf_mono_font; - fstyle_mono.word_wrap = true; UI_fontstyle_set(&fstyle_mono); /* XXX, needed because we dont have mono in 'U.uifonts' */ BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.pixelsize, U.dpi); rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]); - UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, drawcol); + UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, drawcol, &fs_params); } else { - uiFontStyle fstyle_normal = data->fstyle; BLI_assert(field->format.style == UI_TIP_STYLE_NORMAL); - fstyle_normal.word_wrap = true; + const struct uiFontStyleDraw_Params fs_params = { + .align = UI_STYLE_TEXT_LEFT, + .word_wrap = true, + }; /* draw remaining data */ rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]); - UI_fontstyle_set(&fstyle_normal); - UI_fontstyle_draw(&fstyle_normal, &bbox, field->text, drawcol); + UI_fontstyle_set(&data->fstyle); + UI_fontstyle_draw(&data->fstyle, &bbox, field->text, drawcol, &fs_params); } bbox.ymax -= data->lineh * field->geom.lines; diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index d4f6933693e..d36786fed72 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -153,7 +153,8 @@ static uiFont *uifont_to_blfont(int id) void UI_fontstyle_draw_ex( - const uiFontStyle *fs, const rcti *rect, const char *str, const unsigned char col[4], + const uiFontStyle *fs, const rcti *rect, const char *str, const uchar col[4], + const struct uiFontStyleDraw_Params *fs_params, size_t len, float *r_xofs, float *r_yofs) { int xofs = 0, yofs; @@ -171,13 +172,13 @@ void UI_fontstyle_draw_ex( if (fs->kerning == 1) { font_flag |= BLF_KERNING_DEFAULT; } - if (fs->word_wrap == 1) { + if (fs_params->word_wrap == 1) { font_flag |= BLF_WORD_WRAP; } BLF_enable(fs->uifont_id, font_flag); - if (fs->word_wrap == 1) { + if (fs_params->word_wrap == 1) { /* draw from boundbox top */ yofs = BLI_rcti_size_y(rect) - BLF_height_max(fs->uifont_id); } @@ -187,14 +188,14 @@ void UI_fontstyle_draw_ex( yofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height)); } - if (fs->align == UI_STYLE_TEXT_CENTER) { + if (fs_params->align == UI_STYLE_TEXT_CENTER) { 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 */ if (xofs < 2) { xofs = 2; } } - else if (fs->align == UI_STYLE_TEXT_RIGHT) { + else if (fs_params->align == UI_STYLE_TEXT_RIGHT) { xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len) - 0.1f * U.widget_unit; } @@ -211,12 +212,14 @@ void UI_fontstyle_draw_ex( *r_yofs = yofs; } -void UI_fontstyle_draw(const uiFontStyle *fs, const rcti *rect, const char *str, const unsigned char col[4]) +void UI_fontstyle_draw( + const uiFontStyle *fs, const rcti *rect, const char *str, const uchar col[4], + const struct uiFontStyleDraw_Params *fs_params) { float xofs, yofs; UI_fontstyle_draw_ex( - fs, rect, str, col, + fs, rect, str, col, fs_params, BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs); } diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 47d74660fe3..7653e7e6017 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -140,7 +140,7 @@ typedef struct uiWidgetBase { typedef struct uiWidgetType { /* pointer to theme color definition */ - uiWidgetColors *wcol_theme; + const uiWidgetColors *wcol_theme; uiWidgetStateColors *wcol_state; /* converted colors for state */ @@ -149,7 +149,7 @@ typedef struct uiWidgetType { void (*state)(struct uiWidgetType *, int state, int drawflag); void (*draw)(uiWidgetColors *, rcti *, int state, int roundboxalign); void (*custom)(uiBut *, uiWidgetColors *, rcti *, int state, int roundboxalign); - void (*text)(uiFontStyle *, uiWidgetColors *, uiBut *, rcti *); + void (*text)(const uiFontStyle *, const uiWidgetColors *, uiBut *, rcti *); } uiWidgetType; @@ -1408,7 +1408,7 @@ static void ui_text_clip_give_next_off(uiBut *but, const char *str) * Return the length of modified (right-clipped + ellipsis) string. */ static void ui_text_clip_right_ex( - uiFontStyle *fstyle, char *str, const size_t max_len, const float okwidth, + const uiFontStyle *fstyle, char *str, const size_t max_len, const float okwidth, const char *sep, const int sep_len, const float sep_strwidth, size_t *r_final_len) { float tmp; @@ -1442,7 +1442,7 @@ static void ui_text_clip_right_ex( * for strings with shortcuts, like 'AVeryLongFooBarLabelForMenuEntry|Ctrl O' -> 'AVeryLong...MenuEntry|Ctrl O'). */ float UI_text_clip_middle_ex( - uiFontStyle *fstyle, char *str, float okwidth, const float minwidth, + const uiFontStyle *fstyle, char *str, float okwidth, const float minwidth, const size_t max_len, const char rpart_sep) { float strwidth; @@ -1562,7 +1562,7 @@ float UI_text_clip_middle_ex( /** * Wrapper around UI_text_clip_middle_ex. */ -static void ui_text_clip_middle(uiFontStyle *fstyle, uiBut *but, const rcti *rect) +static void ui_text_clip_middle(const uiFontStyle *fstyle, uiBut *but, const rcti *rect) { /* No margin for labels! */ const int border = ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_MENU, UI_BTYPE_POPOVER) ? 0 : (int)(UI_TEXT_CLIP_MARGIN + 0.5f); @@ -1578,7 +1578,7 @@ static void ui_text_clip_middle(uiFontStyle *fstyle, uiBut *but, const rcti *rec * Like ui_text_clip_middle(), but protect/preserve at all cost the right part of the string after sep. * Useful for strings with shortcuts (like 'AVeryLongFooBarLabelForMenuEntry|Ctrl O' -> 'AVeryLong...MenuEntry|Ctrl O'). */ -static void ui_text_clip_middle_protect_right(uiFontStyle *fstyle, uiBut *but, const rcti *rect, const char rsep) +static void ui_text_clip_middle_protect_right(const uiFontStyle *fstyle, uiBut *but, const rcti *rect, const char rsep) { /* No margin for labels! */ const int border = ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_MENU, UI_BTYPE_POPOVER) ? 0 : (int)(UI_TEXT_CLIP_MARGIN + 0.5f); @@ -1593,7 +1593,7 @@ static void ui_text_clip_middle_protect_right(uiFontStyle *fstyle, uiBut *but, c /** * Cut off the text, taking into account the cursor location (text display while editing). */ -static void ui_text_clip_cursor(uiFontStyle *fstyle, uiBut *but, const rcti *rect) +static void ui_text_clip_cursor(const uiFontStyle *fstyle, uiBut *but, const rcti *rect) { const int border = (int)(UI_TEXT_CLIP_MARGIN + 0.5f); const int okwidth = max_ii(BLI_rcti_size_x(rect) - border, 0); @@ -1655,7 +1655,7 @@ static void ui_text_clip_cursor(uiFontStyle *fstyle, uiBut *but, const rcti *rec * * \note deals with ': ' especially for number buttons */ -static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti *rect) +static void ui_text_clip_right_label(const uiFontStyle *fstyle, uiBut *but, const rcti *rect) { const int border = UI_TEXT_CLIP_MARGIN + 1; const int okwidth = max_ii(BLI_rcti_size_x(rect) - border, 0); @@ -1773,7 +1773,7 @@ static void widget_draw_text_ime_underline( } #endif /* WITH_INPUT_IME */ -static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect) +static void widget_draw_text(const uiFontStyle *fstyle, const uiWidgetColors *wcol, uiBut *but, rcti *rect) { int drawstr_left_len = UI_MAX_DRAW_STR; const char *drawstr = but->drawstr; @@ -1786,12 +1786,16 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b UI_fontstyle_set(fstyle); - if (but->editstr || (but->drawflag & UI_BUT_TEXT_LEFT)) - fstyle->align = UI_STYLE_TEXT_LEFT; - else if (but->drawflag & UI_BUT_TEXT_RIGHT) - fstyle->align = UI_STYLE_TEXT_RIGHT; - else - fstyle->align = UI_STYLE_TEXT_CENTER; + eFontStyle_Align align; + if (but->editstr || (but->drawflag & UI_BUT_TEXT_LEFT)) { + align = UI_STYLE_TEXT_LEFT; + } + else if (but->drawflag & UI_BUT_TEXT_RIGHT) { + align = UI_STYLE_TEXT_RIGHT; + } + else { + align = UI_STYLE_TEXT_CENTER; + } if (fstyle->kerning == 1) /* for BLF_width */ BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); @@ -1803,7 +1807,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b uiBut *but_edit = ui_but_drag_multi_edit_get(but); if (but_edit) { drawstr = but_edit->editstr; - fstyle->align = UI_STYLE_TEXT_LEFT; + align = UI_STYLE_TEXT_LEFT; } } else { @@ -1971,8 +1975,10 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b int drawlen = (drawstr_left_len == INT_MAX) ? strlen(drawstr + but->ofs) : (drawstr_left_len - but->ofs); if (drawlen > 0) { - UI_fontstyle_draw_ex(fstyle, rect, drawstr + but->ofs, (unsigned char *)wcol->text, - drawlen, &font_xofs, &font_yofs); + UI_fontstyle_draw_ex( + fstyle, rect, drawstr + but->ofs, (uchar *)wcol->text, + &(struct uiFontStyleDraw_Params) { .align = align, }, + drawlen, &font_xofs, &font_yofs); if (but->menu_key != '\0') { char fixedbuf[128]; @@ -2017,9 +2023,10 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b col[3] *= 0.5f; } - fstyle->align = UI_STYLE_TEXT_RIGHT; rect->xmax -= UI_TEXT_CLIP_MARGIN; - UI_fontstyle_draw(fstyle, rect, drawstr_right, (const uchar *)col); + UI_fontstyle_draw( + fstyle, rect, drawstr_right, (const uchar *)col, + &(struct uiFontStyleDraw_Params) { .align = UI_STYLE_TEXT_RIGHT, }); } } @@ -2039,7 +2046,7 @@ static BIFIconID widget_icon_id(uiBut *but) } /* draws text and icons for buttons */ -static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect) +static void widget_draw_text_icon(const uiFontStyle *fstyle, const uiWidgetColors *wcol, uiBut *but, rcti *rect) { const uiButExtraIconType extra_icon_type = ui_but_icon_extra_get(but); const bool show_menu_icon = ui_but_draw_menu_icon(but); @@ -2577,7 +2584,7 @@ void ui_hsvcircle_pos_from_vals(uiBut *but, const rcti *rect, float *hsv, float *ypos = centy + sinf(-ang) * radius; } -static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti *rect) +static void ui_draw_but_HSVCIRCLE(uiBut *but, const uiWidgetColors *wcol, const rcti *rect) { /* TODO(merwin): reimplement as shader for pixel-perfect colors */ @@ -2967,7 +2974,7 @@ static void ui_draw_roundbox(const rcti *rect, const float rad, const uiWidgetCo /* ************ separator, for menus etc ***************** */ -static void ui_draw_separator(const rcti *rect, uiWidgetColors *wcol) +static void ui_draw_separator(const rcti *rect, const uiWidgetColors *wcol) { int y = rect->ymin + BLI_rcti_size_y(rect) / 2 - 1; unsigned char col[4] = { @@ -4075,8 +4082,8 @@ static int widget_roundbox_set(uiBut *but, rcti *rect) void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rcti *rect) { bTheme *btheme = UI_GetTheme(); - ThemeUI *tui = &btheme->tui; - uiFontStyle *fstyle = &style->widget; + const ThemeUI *tui = &btheme->tui; + const uiFontStyle *fstyle = &style->widget; uiWidgetType *wt = NULL; #ifdef USE_UI_POPOVER_ONCE @@ -4619,7 +4626,7 @@ void ui_draw_pie_center(uiBlock *block) } -uiWidgetColors *ui_tooltip_get_theme(void) +const uiWidgetColors *ui_tooltip_get_theme(void) { uiWidgetType *wt = widget_type(UI_WTYPE_TOOLTIP); return wt->wcol_theme; @@ -4663,7 +4670,7 @@ void ui_draw_tooltip_background(uiStyle *UNUSED(style), uiBlock *UNUSED(block), /* helper call to draw a menu item without button */ /* state: UI_ACTIVE or 0 */ -void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state, bool use_sep) +void ui_draw_menu_item(const uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state, bool use_sep) { uiWidgetType *wt = widget_type(UI_WTYPE_MENU_ITEM); rcti _rect = *rect; @@ -4673,7 +4680,6 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int ic wt->draw(&wt->wcol, rect, 0, 0); UI_fontstyle_set(fstyle); - fstyle->align = UI_STYLE_TEXT_LEFT; /* text location offset */ rect->xmin += 0.25f * UI_UNIT_X; @@ -4711,15 +4717,18 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int ic UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, '\0'); } - UI_fontstyle_draw(fstyle, rect, drawstr, (unsigned char *)wt->wcol.text); + UI_fontstyle_draw( + fstyle, rect, drawstr, (uchar *)wt->wcol.text, + &(struct uiFontStyleDraw_Params) { .align = UI_STYLE_TEXT_LEFT, }); } /* part text right aligned */ if (use_sep) { if (cpoin) { - fstyle->align = UI_STYLE_TEXT_RIGHT; rect->xmax = _rect.xmax - 5; - UI_fontstyle_draw(fstyle, rect, cpoin + 1, (unsigned char *)wt->wcol.text); + UI_fontstyle_draw( + fstyle, rect, cpoin + 1, (uchar *)wt->wcol.text, + &(struct uiFontStyleDraw_Params) { .align = UI_STYLE_TEXT_RIGHT, }); *cpoin = UI_SEP_CHAR; } } @@ -4741,7 +4750,7 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int ic } } -void ui_draw_preview_item(uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state) +void ui_draw_preview_item(const uiFontStyle *fstyle, rcti *rect, const char *name, int iconid, int state) { rcti trect = *rect; const float text_size = UI_UNIT_Y; @@ -4777,7 +4786,9 @@ void ui_draw_preview_item(uiFontStyle *fstyle, rcti *rect, const char *name, int BLI_strncpy(drawstr, name, sizeof(drawstr)); UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, '\0'); - UI_fontstyle_draw(fstyle, &trect, drawstr, (unsigned char *)wt->wcol.text); + UI_fontstyle_draw( + fstyle, &trect, drawstr, (uchar *)wt->wcol.text, + &(struct uiFontStyleDraw_Params) { .align = UI_STYLE_TEXT_CENTER, }); } } |