void UI_fontstyle_draw_ex( const uiFontStyle *fs, const rcti *rect, const char *str, size_t len, float *r_xofs, float *r_yofs) { int xofs = 0, yofs; int font_flag = BLF_CLIPPING; UI_fontstyle_set(fs); /* set the flag */ if (fs->shadow) { font_flag |= BLF_SHADOW; const float shadow_color[4] = {fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha}; BLF_shadow(fs->uifont_id, fs->shadow, shadow_color); BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady); } if (fs->kerning == 1) { font_flag |= BLF_KERNING_DEFAULT; } if (fs->word_wrap == 1) { font_flag |= BLF_WORD_WRAP; } BLF_enable(fs->uifont_id, font_flag); if (fs->word_wrap == 1) { /* draw from boundbox top */ yofs = BLI_rcti_size_y(rect) - BLF_height_max(fs->uifont_id); } else { /* draw from boundbox center */ yofs = ceil(0.5f * (BLI_rcti_size_y(rect) - BLF_ascender(fs->uifont_id))); } if (fs->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) { xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len) - 0.1f * U.widget_unit; } /* clip is very strict, so we give it some space */ BLF_clipping(fs->uifont_id, rect->xmin - 2, rect->ymin - 4, rect->xmax + 1, rect->ymax + 4); BLF_position(fs->uifont_id, rect->xmin + xofs, rect->ymin + yofs, 0.0f); BLF_draw(fs->uifont_id, str, len); BLF_disable(fs->uifont_id, font_flag); *r_xofs = xofs; *r_yofs = yofs; }
/** * 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 float col_fg[4], const float col_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 */ float color[4] = {col_bg[0], col_bg[1], col_bg[2], 0.5f}; UI_draw_roundbox_corner_set(UI_CNR_ALL); UI_draw_roundbox_aa(true, x - margin, (y + decent) - margin, x + width + margin, (y + decent) + height + margin, margin, color); } BLF_position(fs->uifont_id, x, y, 0.0f); BLF_color4fv(fs->uifont_id, col_fg); BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); if (fs->kerning == 1) { 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); }
static void draw_marker_texts(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker, const float marker_pos[2], int act, int width, int height, float zoomx, float zoomy) { char str[128] = {0}, state[64] = {0}; float dx = 0.0f, dy = 0.0f, fontsize, pos[3]; uiStyle *style = U.uistyles.first; int fontid = style->widget.uifont_id; if (!TRACK_VIEW_SELECTED(sc, track)) return; BLF_size(fontid, 11.0f * U.pixelsize, U.dpi); fontsize = BLF_height_max(fontid); if (marker->flag & MARKER_DISABLED) { if (act) UI_ThemeColor(TH_ACT_MARKER); else UI_ThemeColorShade(TH_DIS_MARKER, 128); } else { if (act) UI_ThemeColor(TH_ACT_MARKER); else UI_ThemeColor(TH_SEL_MARKER); } if ((sc->flag & SC_SHOW_MARKER_SEARCH) && ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) { dx = marker->search_min[0]; dy = marker->search_min[1]; } else if (sc->flag & SC_SHOW_MARKER_PATTERN) { float pat_min[2], pat_max[2]; BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max); dx = pat_min[0]; dy = pat_min[1]; } pos[0] = (marker_pos[0] + dx) * width; pos[1] = (marker_pos[1] + dy) * height; pos[2] = 0.0f; mul_m4_v3(sc->stabmat, pos); pos[0] = pos[0] * zoomx; pos[1] = pos[1] * zoomy - fontsize; if (marker->flag & MARKER_DISABLED) strcpy(state, "disabled"); else if (marker->framenr != ED_space_clip_get_clip_frame_number(sc)) strcpy(state, "estimated"); else if (marker->flag & MARKER_TRACKED) strcpy(state, "tracked"); else strcpy(state, "keyframed"); if (state[0]) BLI_snprintf(str, sizeof(str), "%s: %s", track->name, state); else BLI_strncpy(str, track->name, sizeof(str)); BLF_position(fontid, pos[0], pos[1], 0.0f); BLF_draw(fontid, str, sizeof(str)); pos[1] -= fontsize; if (track->flag & TRACK_HAS_BUNDLE) { BLI_snprintf(str, sizeof(str), "Average error: %.3f", track->error); BLF_position(fontid, pos[0], pos[1], 0.0f); BLF_draw(fontid, str, sizeof(str)); pos[1] -= fontsize; } if (track->flag & TRACK_LOCKED) { BLF_position(fontid, pos[0], pos[1], 0.0f); BLF_draw(fontid, "locked", 6); } }
int UI_fontstyle_height_max(const uiFontStyle *fs) { UI_fontstyle_set(fs); return BLF_height_max(fs->uifont_id); }
void UI_fontstyle_draw_ex(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; int font_flag = BLF_CLIPPING; UI_fontstyle_set(fs); /* set the flag */ if (fs->shadow) { font_flag |= BLF_SHADOW; const float shadow_color[4] = { fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha}; BLF_shadow(fs->uifont_id, fs->shadow, shadow_color); BLF_shadow_offset(fs->uifont_id, fs->shadx, fs->shady); } if (fs->kerning == 1) { font_flag |= BLF_KERNING_DEFAULT; } if (fs_params->word_wrap == 1) { font_flag |= BLF_WORD_WRAP; } BLF_enable(fs->uifont_id, font_flag); if (fs_params->word_wrap == 1) { /* draw from boundbox top */ yofs = BLI_rcti_size_y(rect) - BLF_height_max(fs->uifont_id); } else { /* draw from boundbox center */ float height = BLF_ascender(fs->uifont_id) + BLF_descender(fs->uifont_id); yofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height)); } if (fs_params->align == UI_STYLE_TEXT_CENTER) { xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len))); } else if (fs_params->align == UI_STYLE_TEXT_RIGHT) { xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len); } yofs = MAX2(0, yofs); xofs = MAX2(0, xofs); BLF_clipping(fs->uifont_id, rect->xmin, rect->ymin, rect->xmax, rect->ymax); BLF_position(fs->uifont_id, rect->xmin + xofs, rect->ymin + yofs, 0.0f); BLF_color4ubv(fs->uifont_id, col); BLF_draw(fs->uifont_id, str, len); BLF_disable(fs->uifont_id, font_flag); *r_xofs = xofs; *r_yofs = yofs; }