diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-01-20 06:25:39 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-01-20 07:50:20 +0300 |
commit | 09eec627ed730532905b45d409f9009023623437 (patch) | |
tree | 0b352ce642e5cf54b2ccf83c4f11485e50bdadef /source/blender | |
parent | f8c52402d6c76392444a9dd9ab90d2f48b1a03fe (diff) |
UI: cleanup UI_fontstyle_string_width, UI_draw_string
Both were maked as temp, but used often.
Now pass uiFontStyle to both, rename UI_draw_string to UI_fontstyle_draw_simple,
since its a variant of UI_fontstyle_draw that skips shadow, align... etc.
Diffstat (limited to 'source/blender')
12 files changed, 92 insertions, 71 deletions
diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c index d76eba93640..7b29414c763 100644 --- a/source/blender/editors/animation/anim_channels_defines.c +++ b/source/blender/editors/animation/anim_channels_defines.c @@ -3519,6 +3519,7 @@ void ANIM_channel_draw(bAnimContext *ac, bAnimListElem *ale, float yminc, float /* step 5) draw name ............................................... */ /* TODO: when renaming, we might not want to draw this, especially if name happens to be longer than channel */ if (acf->name) { + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; char name[ANIM_CHAN_NAME_SIZE]; /* hopefully this will be enough! */ /* set text color */ @@ -3532,7 +3533,7 @@ void ANIM_channel_draw(bAnimContext *ac, bAnimListElem *ale, float yminc, float acf->name(ale, name); offset += 3; - UI_draw_string(offset, ytext, name); + UI_fontstyle_draw_simple(fstyle, offset, ytext, name); /* draw red underline if channel is disabled */ if ((ale->type == ANIMTYPE_FCURVE) && (ale->flag & FCURVE_DISABLED)) { diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c index 2d7656642d3..0e052279796 100644 --- a/source/blender/editors/animation/anim_draw.c +++ b/source/blender/editors/animation/anim_draw.c @@ -59,6 +59,7 @@ /* Draw current frame number in a little green box beside the current frame indicator */ static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const bool time) { + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; float xscale, yscale, x, y; char numstr[32] = " t"; /* t is the character to start replacing from */ int slen; @@ -78,7 +79,8 @@ static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const else { BLI_timecode_string_from_time_simple(&numstr[4], sizeof(numstr) - 4, 1, cfra); } - slen = UI_fontstyle_string_width(numstr) - 1; + + slen = UI_fontstyle_string_width(fstyle, numstr) - 1; /* get starting coordinates for drawing */ x = cfra * xscale; @@ -90,7 +92,7 @@ static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const /* draw current frame number - black text */ UI_ThemeColor(TH_TEXT); - UI_draw_string(x - 0.25f * U.widget_unit, y + 0.15f * U.widget_unit, numstr); + UI_fontstyle_draw_simple(fstyle, x - 0.25f * U.widget_unit, y + 0.15f * U.widget_unit, numstr); /* restore view transform */ glScalef(xscale, 1.0, 1.0); diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c index b6c7a4aa5a0..d778b06cf5f 100644 --- a/source/blender/editors/animation/anim_markers.c +++ b/source/blender/editors/animation/anim_markers.c @@ -317,7 +317,7 @@ void debug_markers_print_list(ListBase *markers) /* function to draw markers */ static void draw_marker( - View2D *v2d, TimeMarker *marker, int cfra, int flag, + View2D *v2d, const uiFontStyle *fstyle, TimeMarker *marker, int cfra, int flag, /* avoid re-calculating each time */ const float ypixels, const float xscale, const float yscale) { @@ -399,13 +399,14 @@ static void draw_marker( } #endif - UI_draw_string(x, y, marker->name); + UI_fontstyle_draw_simple(fstyle, x, y, marker->name); } } /* Draw Scene-Markers in time window */ void ED_markers_draw(const bContext *C, int flag) { + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; ListBase *markers = ED_context_get_markers(C); View2D *v2d; TimeMarker *marker; @@ -455,7 +456,7 @@ void ED_markers_draw(const bContext *C, int flag) if ((marker->frame >= v2d_clip_range_x[0]) && (marker->frame <= v2d_clip_range_x[1])) { - draw_marker(v2d, marker, scene->r.cfra, flag, + draw_marker(v2d, fstyle, marker, scene->r.cfra, flag, ypixels, xscale, yscale); } } diff --git a/source/blender/editors/animation/fmodifier_ui.c b/source/blender/editors/animation/fmodifier_ui.c index 8ede1a0ad76..bcdad1c93ad 100644 --- a/source/blender/editors/animation/fmodifier_ui.c +++ b/source/blender/editors/animation/fmodifier_ui.c @@ -130,6 +130,7 @@ static void draw_modifier__generator(uiLayout *layout, ID *id, FModifier *fcm, s switch (data->mode) { case FCM_GENERATOR_POLYNOMIAL: /* polynomial expression */ { + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; float *cp = NULL; char xval[32]; unsigned int i; @@ -147,11 +148,12 @@ static void draw_modifier__generator(uiLayout *layout, ID *id, FModifier *fcm, s /* calculate maximum width of label for "x^n" labels */ if (data->arraysize > 2) { BLI_snprintf(xval, sizeof(xval), "x^%u", data->arraysize); - maxXWidth = UI_fontstyle_string_width(xval) + 0.5 * UI_UNIT_X; /* XXX: UI_fontstyle_string_width is not accurate */ + /* XXX: UI_fontstyle_string_width is not accurate */ + maxXWidth = UI_fontstyle_string_width(fstyle, xval) + 0.5 * UI_UNIT_X; } else { /* basic size (just "x") */ - maxXWidth = UI_fontstyle_string_width("x") + 0.5 * UI_UNIT_X; + maxXWidth = UI_fontstyle_string_width(fstyle, "x") + 0.5 * UI_UNIT_X; } /* draw controls for each coefficient and a + sign at end of row */ diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 159fda89f59..da857c27435 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -974,15 +974,15 @@ void UI_context_active_but_prop_get_filebrowser(const struct bContext *C, struct void UI_context_active_but_prop_get_templateID(struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA **prop); /* Styled text draw */ -void UI_fontstyle_set(struct uiFontStyle *fs); +void UI_fontstyle_set(const struct uiFontStyle *fs); void UI_fontstyle_draw_ex( - struct uiFontStyle *fs, const struct rcti *rect, const char *str, + const struct uiFontStyle *fs, const struct rcti *rect, const char *str, size_t len, float *r_xofs, float *r_yofs); -void UI_fontstyle_draw(struct uiFontStyle *fs, const struct rcti *rect, const char *str); -void UI_fontstyle_draw_rotated(struct uiFontStyle *fs, const struct rcti *rect, const char *str); +void UI_fontstyle_draw(const struct uiFontStyle *fs, const struct rcti *rect, const char *str); +void UI_fontstyle_draw_rotated(const struct uiFontStyle *fs, const struct rcti *rect, const char *str); +void UI_fontstyle_draw_simple(const struct uiFontStyle *fs, float x, float y, const char *str); -int UI_fontstyle_string_width(const char *str); // XXX temp -void UI_draw_string(float x, float y, const char *str); // XXX temp +int UI_fontstyle_string_width(const struct uiFontStyle *fs, const char *str); void UI_draw_icon_tri(float x, float y, char dir); uiStyle *UI_style_get(void); /* use for fonts etc */ @@ -1013,6 +1013,9 @@ void UI_butstore_unregister(uiButStore *bs_handle, uiBut **but_p); /* Float precision helpers */ #define UI_PRECISION_FLOAT_MAX 7 +/* Typical UI text */ +#define UI_FSTYLE_WIDGET (const uiFontStyle *)&(UI_style_get()->widget) + int UI_calc_float_precision(int prec, double value); #endif /* __UI_INTERFACE_H__ */ diff --git a/source/blender/editors/interface/interface_eyedropper.c b/source/blender/editors/interface/interface_eyedropper.c index 9b5d067e9be..dfcafd7e46e 100644 --- a/source/blender/editors/interface/interface_eyedropper.c +++ b/source/blender/editors/interface/interface_eyedropper.c @@ -73,10 +73,11 @@ static void eyedropper_draw_cursor_text(const struct bContext *C, ARegion *ar, const char *name) { - int width; + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; wmWindow *win = CTX_wm_window(C); int x = win->eventstate->x; int y = win->eventstate->y; + int width; if ((name[0] == '\0') || (BLI_rcti_isect_pt(&ar->winrct, x, y) == false)) @@ -84,7 +85,7 @@ static void eyedropper_draw_cursor_text(const struct bContext *C, ARegion *ar, c return; } - width = UI_fontstyle_string_width(name); + width = UI_fontstyle_string_width(fstyle, name); x = x - ar->winrct.xmin; y = y - ar->winrct.ymin; @@ -96,7 +97,7 @@ static void eyedropper_draw_cursor_text(const struct bContext *C, ARegion *ar, c UI_draw_roundbox(x, y, x + width + 8, y + 15, 4); glColor4ub(255, 255, 255, 255); - UI_draw_string(x + 4, y + 4, name); + UI_fontstyle_draw_simple(fstyle, x + 4, y + 4, name); } /** \} */ diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c index f02c6a234a9..9d1b312dc24 100644 --- a/source/blender/editors/interface/interface_layout.c +++ b/source/blender/editors/interface/interface_layout.c @@ -235,9 +235,10 @@ static int ui_text_icon_width(uiLayout *layout, const char *name, int icon, bool variable = (ui_layout_vary_direction(layout) == UI_ITEM_VARY_X); if (variable) { + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; /* it may seem odd that the icon only adds (UI_UNIT_X / 4) * but taking margins into account its fine */ - return (UI_fontstyle_string_width(name) + + return (UI_fontstyle_string_width(fstyle, name) + (UI_UNIT_X * ((compact ? 1.25f : 1.50f) + (icon ? 0.25f : 0.0f)))); } @@ -639,7 +640,7 @@ static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, const char *n if (name[0]) { /* XXX UI_fontstyle_string_width is not accurate */ #if 0 - labelw = UI_fontstyle_string_width(name); + labelw = UI_fontstyle_string_width(fstyle, name); CLAMP(labelw, w / 4, 3 * w / 4); #endif labelw = w / 3; diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index 0ec59e4e4cd..21e7b8eef97 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -2726,7 +2726,8 @@ static uiBlock *ui_block_func_PIE(bContext *UNUSED(C), uiPopupBlockHandle *handl static float ui_pie_menu_title_width(const char *name, int icon) { - return (UI_fontstyle_string_width(name) + + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; + return (UI_fontstyle_string_width(fstyle, name) + (UI_UNIT_X * (1.50f + (icon ? 0.25f : 0.0f)))); } diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index dda4220bf18..2fe44b2a9b6 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -147,8 +147,9 @@ static uiFont *uifont_to_blfont(int id) /* *************** draw ************************ */ -void UI_fontstyle_draw_ex(uiFontStyle *fs, const rcti *rect, const char *str, - size_t len, float *r_xofs, float *r_yofs) +void UI_fontstyle_draw_ex( + const uiFontStyle *fs, const rcti *rect, const char *str, + size_t len, float *r_xofs, float *r_yofs) { float height; int xofs = 0, yofs; @@ -194,15 +195,17 @@ void UI_fontstyle_draw_ex(uiFontStyle *fs, const rcti *rect, const char *str, *r_yofs = yofs; } -void UI_fontstyle_draw(uiFontStyle *fs, const rcti *rect, const char *str) +void UI_fontstyle_draw(const uiFontStyle *fs, const rcti *rect, const char *str) { float xofs, yofs; - UI_fontstyle_draw_ex(fs, rect, str, - BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs); + + UI_fontstyle_draw_ex( + fs, rect, str, + BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs); } /* drawn same as above, but at 90 degree angle */ -void UI_fontstyle_draw_rotated(uiFontStyle *fs, const rcti *rect, const char *str) +void UI_fontstyle_draw_rotated(const uiFontStyle *fs, const rcti *rect, const char *str) { float height; int xofs, yofs; @@ -255,6 +258,25 @@ void UI_fontstyle_draw_rotated(uiFontStyle *fs, const rcti *rect, const char *st BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT); } +/** + * Similar to #UI_fontstyle_draw + * but ignore alignment, shadow & no clipping rect. + * + * For drawing on-screen labels. + */ +void UI_fontstyle_draw_simple(const uiFontStyle *fs, float x, float y, const char *str) +{ + if (fs->kerning == 1) + BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT); + + UI_fontstyle_set(fs); + 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) @@ -291,41 +313,22 @@ uiStyle *UI_style_get_dpi(void) return &_style; } -/* temporarily, does widget font */ -int UI_fontstyle_string_width(const char *str) +int UI_fontstyle_string_width(const uiFontStyle *fs, const char *str) { - uiStyle *style = UI_style_get(); - uiFontStyle *fstyle = &style->widget; int width; - if (fstyle->kerning == 1) /* for BLF_width */ - BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); + if (fs->kerning == 1) /* for BLF_width */ + BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT); - UI_fontstyle_set(fstyle); - width = BLF_width(fstyle->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); + UI_fontstyle_set(fs); + width = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); - if (fstyle->kerning == 1) - BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); + if (fs->kerning == 1) + BLF_disable(fs->uifont_id, BLF_KERNING_DEFAULT); return width; } -/* temporarily, does widget font */ -void UI_draw_string(float x, float y, const char *str) -{ - uiStyle *style = UI_style_get(); - - if (style->widget.kerning == 1) - BLF_enable(style->widget.uifont_id, BLF_KERNING_DEFAULT); - - UI_fontstyle_set(&style->widget); - BLF_position(style->widget.uifont_id, x, y, 0.0f); - BLF_draw(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); - - if (style->widget.kerning == 1) - BLF_disable(style->widget.uifont_id, BLF_KERNING_DEFAULT); -} - /* ************** init exit ************************ */ /* called on each startup.blend read */ @@ -452,7 +455,7 @@ void uiStyleInit(void) BLF_size(blf_mono_font_render, 12 * U.pixelsize, 72); } -void UI_fontstyle_set(uiFontStyle *fs) +void UI_fontstyle_set(const uiFontStyle *fs) { uiFont *font = uifont_to_blfont(fs->uifont_id); diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c index 3f3c14d3a7d..a2e8eeaa058 100644 --- a/source/blender/editors/space_file/file_draw.c +++ b/source/blender/editors/space_file/file_draw.c @@ -133,7 +133,8 @@ void file_draw_buttons(const bContext *C, ARegion *ar) loadbutton = 0; } else { - loadbutton = UI_fontstyle_string_width(params->title) + btn_margin; + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; + loadbutton = UI_fontstyle_string_width(fstyle, params->title) + btn_margin; CLAMP_MIN(loadbutton, btn_minw); if (available_w <= loadbutton + separator + input_minw) { loadbutton = 0; diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c index a963f422cb7..ab6e371072e 100644 --- a/source/blender/editors/space_outliner/outliner_draw.c +++ b/source/blender/editors/space_outliner/outliner_draw.c @@ -1248,8 +1248,9 @@ static void outliner_set_coord_tree_element(SpaceOops *soops, TreeElement *te, i } -static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, - TreeElement *te, int startx, int *starty, TreeElement **te_edit) +static void outliner_draw_tree_element( + bContext *C, uiBlock *block, const uiFontStyle *fstyle, Scene *scene, ARegion *ar, SpaceOops *soops, + TreeElement *te, int startx, int *starty, TreeElement **te_edit) { TreeElement *ten; TreeStoreElem *tselem; @@ -1408,9 +1409,9 @@ static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene else if (ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.75f); else UI_ThemeColor(TH_TEXT); - UI_draw_string(startx + offsx, *starty + 5 * ufac, te->name); + UI_fontstyle_draw_simple(fstyle, startx + offsx, *starty + 5 * ufac, te->name); - offsx += (int)(UI_UNIT_X + UI_fontstyle_string_width(te->name)); + offsx += (int)(UI_UNIT_X + UI_fontstyle_string_width(fstyle, te->name)); /* closed item, we draw the icons, not when it's a scene, or master-server list though */ if (!TSELEM_OPEN(tselem, soops)) { @@ -1448,13 +1449,15 @@ static void outliner_draw_tree_element(bContext *C, uiBlock *block, Scene *scene if (TSELEM_OPEN(tselem, soops)) { *starty -= UI_UNIT_Y; - - for (ten = te->subtree.first; ten; ten = ten->next) - outliner_draw_tree_element(C, block, scene, ar, soops, ten, startx + UI_UNIT_X, starty, te_edit); + + for (ten = te->subtree.first; ten; ten = ten->next) { + outliner_draw_tree_element(C, block, fstyle, scene, ar, soops, ten, startx + UI_UNIT_X, starty, te_edit); + } } else { - for (ten = te->subtree.first; ten; ten = ten->next) + for (ten = te->subtree.first; ten; ten = ten->next) { outliner_set_coord_tree_element(soops, ten, startx, *starty); + } *starty -= UI_UNIT_Y; } @@ -1537,6 +1540,7 @@ static void outliner_draw_selection(ARegion *ar, SpaceOops *soops, ListBase *lb, static void outliner_draw_tree(bContext *C, uiBlock *block, Scene *scene, ARegion *ar, SpaceOops *soops, TreeElement **te_edit) { + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; TreeElement *te; int starty, startx; float col[3]; @@ -1567,7 +1571,7 @@ static void outliner_draw_tree(bContext *C, uiBlock *block, Scene *scene, ARegio starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET; startx = 0; for (te = soops->tree.first; te; te = te->next) { - outliner_draw_tree_element(C, block, scene, ar, soops, te, startx, &starty, te_edit); + outliner_draw_tree_element(C, block, fstyle, scene, ar, soops, te, startx, &starty, te_edit); } } diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c index 68592b44845..0056474edf9 100644 --- a/source/blender/windowmanager/intern/wm_dragdrop.c +++ b/source/blender/windowmanager/intern/wm_dragdrop.c @@ -267,7 +267,8 @@ void wm_drags_check_ops(bContext *C, wmEvent *event) static void wm_drop_operator_draw(const char *name, int x, int y) { - int width = UI_fontstyle_string_width(name); + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; + int width = UI_fontstyle_string_width(fstyle, name); int padding = 4 * UI_DPI_FAC; glColor4ub(0, 0, 0, 50); @@ -276,7 +277,7 @@ static void wm_drop_operator_draw(const char *name, int x, int y) UI_draw_roundbox(x, y, x + width + 2 * padding, y + 4 * padding, padding); glColor4ub(255, 255, 255, 255); - UI_draw_string(x + padding, y + padding, name); + UI_fontstyle_draw_simple(fstyle, x + padding, y + padding, name); } static const char *wm_drag_name(wmDrag *drag) @@ -284,13 +285,12 @@ static const char *wm_drag_name(wmDrag *drag) switch (drag->type) { case WM_DRAG_ID: { - ID *id = (ID *)drag->poin; + ID *id = drag->poin; return id->name + 2; } case WM_DRAG_PATH: - return drag->path; case WM_DRAG_NAME: - return (char *)drag->path; + return drag->path; } return ""; } @@ -311,6 +311,7 @@ static void drag_rect_minmax(rcti *rect, int x1, int y1, int x2, int y2) /* if rect set, do not draw */ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect) { + const uiFontStyle *fstyle = UI_FSTYLE_WIDGET; wmWindowManager *wm = CTX_wm_manager(C); wmDrag *drag; const int winsize_y = WM_window_pixels_y(win); @@ -362,12 +363,12 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect) } if (rect) { - int w = UI_fontstyle_string_width(wm_drag_name(drag)); + int w = UI_fontstyle_string_width(fstyle, wm_drag_name(drag)); drag_rect_minmax(rect, x, y, x + w, y + iconsize); } else { glColor4ub(255, 255, 255, 255); - UI_draw_string(x, y, wm_drag_name(drag)); + UI_fontstyle_draw_simple(fstyle, x, y, wm_drag_name(drag)); } /* operator name with roundbox */ @@ -390,7 +391,7 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect) } if (rect) { - int w = UI_fontstyle_string_width(wm_drag_name(drag)); + int w = UI_fontstyle_string_width(fstyle, wm_drag_name(drag)); drag_rect_minmax(rect, x, y, x + w, y + iconsize); } else |