[Bf-blender-cvs] [f45c2a9] temp-ui-widget-refactor: Aaaand finally: Use new pipeline for text drawing as well
Julian Eisel
noreply at git.blender.org
Thu Jul 16 21:56:35 CEST 2015
Commit: f45c2a9cb5b37222a40e417a4d8291a480b5843d
Author: Julian Eisel
Date: Thu Jul 16 19:09:51 2015 +0200
Branches: temp-ui-widget-refactor
https://developer.blender.org/rBf45c2a9cb5b37222a40e417a4d8291a480b5843d
Aaaand finally: Use new pipeline for text drawing as well
===================================================================
M source/blender/editors/interface/CMakeLists.txt
M source/blender/editors/interface/interface_widgets.c
M source/blender/editors/interface/widgets/widgets.h
M source/blender/editors/interface/widgets/widgets_draw/drawstyle_classic.c
M source/blender/editors/interface/widgets/widgets_draw/widgets_draw_intern.h
A source/blender/editors/interface/widgets/widgets_draw/widgets_draw_text.c
===================================================================
diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt
index 356c071..68ebb30 100644
--- a/source/blender/editors/interface/CMakeLists.txt
+++ b/source/blender/editors/interface/CMakeLists.txt
@@ -60,6 +60,7 @@ set(SRC
widgets/widgets.c
widgets/widgets_draw/drawstyle_classic.c
widgets/widgets_draw/widgets_draw.c
+ widgets/widgets_draw/widgets_draw_text.c
interface_intern.h
widgets/widgets.h
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 4a57b1c..390e3bf 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -202,830 +202,6 @@ static void widgetbase_outline(uiWidgetBase *wtb)
glDisableClientState(GL_VERTEX_ARRAY);
}
-/* *********************** text/icon ************************************** */
-
-#define UI_TEXT_CLIP_MARGIN (0.25f * U.widget_unit / but->block->aspect)
-
-#define PREVIEW_PAD 4
-
-static void widget_draw_preview(BIFIconID icon, float alpha, const rcti *rect)
-{
- int w, h, size;
-
- if (icon == ICON_NONE)
- return;
-
- w = BLI_rcti_size_x(rect);
- h = BLI_rcti_size_y(rect);
- size = MIN2(w, h);
- size -= PREVIEW_PAD * 2; /* padding */
-
- if (size > 0) {
- int x = rect->xmin + w / 2 - size / 2;
- int y = rect->ymin + h / 2 - size / 2;
-
- UI_icon_draw_preview_aspect_size(x, y, icon, 1.0f, alpha, size);
- }
-}
-
-
-static int ui_but_draw_menu_icon(const uiBut *but)
-{
- return (but->flag & UI_BUT_ICON_SUBMENU) && (but->dt == UI_EMBOSS_PULLDOWN);
-}
-
-/* icons have been standardized... and this call draws in untransformed coordinates */
-
-static void widget_draw_icon(
- const uiBut *but, BIFIconID icon, float alpha, const rcti *rect,
- const bool show_menu_icon)
-{
- float xs = 0.0f, ys = 0.0f;
- float aspect, height;
-
- if (but->flag & UI_BUT_ICON_PREVIEW) {
- glEnable(GL_BLEND);
- widget_draw_preview(icon, alpha, rect);
- glDisable(GL_BLEND);
- return;
- }
-
- /* this icon doesn't need draw... */
- if (icon == ICON_BLANK1 && (but->flag & UI_BUT_ICON_SUBMENU) == 0) return;
-
- aspect = but->block->aspect / UI_DPI_FAC;
- height = ICON_DEFAULT_HEIGHT / aspect;
-
- /* calculate blend color */
- if (ELEM(but->type, UI_BTYPE_TOGGLE, UI_BTYPE_ROW, UI_BTYPE_TOGGLE_N, UI_BTYPE_LISTROW)) {
- if (but->flag & UI_SELECT) {}
- else if (but->flag & UI_ACTIVE) {}
- else alpha = 0.5f;
- }
-
- /* extra feature allows more alpha blending */
- if ((but->type == UI_BTYPE_LABEL) && but->a1 == 1.0f)
- alpha *= but->a2;
-
- glEnable(GL_BLEND);
-
- if (icon && icon != ICON_BLANK1) {
- float ofs = 1.0f / aspect;
-
- if (but->drawflag & UI_BUT_ICON_LEFT) {
- if (but->block->flag & UI_BLOCK_LOOP) {
- if (but->type == UI_BTYPE_SEARCH_MENU)
- xs = rect->xmin + 4.0f * ofs;
- else
- xs = rect->xmin + ofs;
- }
- else {
- xs = rect->xmin + 4.0f * ofs;
- }
- ys = (rect->ymin + rect->ymax - height) / 2.0f;
- }
- else {
- xs = (rect->xmin + rect->xmax - height) / 2.0f;
- ys = (rect->ymin + rect->ymax - height) / 2.0f;
- }
-
- /* force positions to integers, for zoom levels near 1. draws icons crisp. */
- if (aspect > 0.95f && aspect < 1.05f) {
- xs = (int)(xs + 0.1f);
- ys = (int)(ys + 0.1f);
- }
-
- /* to indicate draggable */
- if (but->dragpoin && (but->flag & UI_ACTIVE)) {
- float rgb[3] = {1.25f, 1.25f, 1.25f};
- UI_icon_draw_aspect_color(xs, ys, icon, aspect, rgb);
- }
- else
- UI_icon_draw_aspect(xs, ys, icon, aspect, alpha);
- }
-
- if (show_menu_icon) {
- xs = rect->xmax - UI_DPI_ICON_SIZE - aspect;
- ys = (rect->ymin + rect->ymax - height) / 2.0f;
-
- UI_icon_draw_aspect(xs, ys, ICON_RIGHTARROW_THIN, aspect, alpha);
- }
-
- glDisable(GL_BLEND);
-}
-
-static void ui_text_clip_give_prev_off(uiBut *but, const char *str)
-{
- const char *prev_utf8 = BLI_str_find_prev_char_utf8(str, str + but->ofs);
- int bytes = str + but->ofs - prev_utf8;
-
- but->ofs -= bytes;
-}
-
-static void ui_text_clip_give_next_off(uiBut *but, const char *str)
-{
- const char *next_utf8 = BLI_str_find_next_char_utf8(str + but->ofs, NULL);
- int bytes = next_utf8 - (str + but->ofs);
-
- but->ofs += bytes;
-}
-
-/**
- * Helper.
- * This func assumes things like kerning handling have already been handled!
- * 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 char *sep, const int sep_len, const float sep_strwidth, size_t *r_final_len)
-{
- float tmp;
- int l_end;
-
- BLI_assert(str[0]);
-
- /* If the trailing ellipsis takes more than 20% of all available width, just cut the string
- * (as using the ellipsis would remove even more useful chars, and we cannot show much already!).
- */
- if (sep_strwidth / okwidth > 0.2f) {
- l_end = BLF_width_to_strlen(fstyle->uifont_id, str, max_len, okwidth, &tmp);
- str[l_end] = '\0';
- if (r_final_len) {
- *r_final_len = (size_t)l_end;
- }
- }
- else {
- l_end = BLF_width_to_strlen(fstyle->uifont_id, str, max_len, okwidth - sep_strwidth, &tmp);
- memcpy(str + l_end, sep, sep_len + 1); /* +1 for trailing '\0'. */
- if (r_final_len) {
- *r_final_len = (size_t)(l_end + sep_len);
- }
- }
-}
-
-/**
- * Cut off the middle of the text to fit into the given width.
- * Note in case this middle clipping would just remove a few chars, it rather clips right, which is more readable.
- * If rpart_sep is not Null, the part of str starting to first occurrence of rpart_sep is preserved at all cost (useful
- * 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 size_t max_len, const char rpart_sep)
-{
- float strwidth;
-
- /* Add some epsilon to OK width, avoids 'ellipsing' text that nearly fits!
- * Better to have a small piece of the last char cut out, than two remaining chars replaced by an allipsis... */
- okwidth += 1.0f + UI_DPI_FAC;
-
- BLI_assert(str[0]);
-
- /* need to set this first */
- UI_fontstyle_set(fstyle);
-
- if (fstyle->kerning == 1) { /* for BLF_width */
- BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
-
- strwidth = BLF_width(fstyle->uifont_id, str, max_len);
-
- if ((okwidth > 0.0f) && (strwidth > okwidth)) {
- /* utf8 ellipsis '...', some compilers complain */
- const char sep[] = {0xe2, 0x80, 0xa6, 0x0};
- const int sep_len = sizeof(sep) - 1;
- const float sep_strwidth = BLF_width(fstyle->uifont_id, sep, sep_len + 1);
- float parts_strwidth;
- size_t l_end;
-
- char *rpart = NULL, rpart_buf[UI_MAX_DRAW_STR];
- float rpart_width = 0.0f;
- size_t rpart_len = 0;
- size_t final_lpart_len;
-
- if (rpart_sep) {
- rpart = strrchr(str, rpart_sep);
-
- if (rpart) {
- rpart_len = strlen(rpart);
- rpart_width = BLF_width(fstyle->uifont_id, rpart, rpart_len);
- okwidth -= rpart_width;
- strwidth -= rpart_width;
-
- if (okwidth < 0.0f) {
- /* Not enough place for actual label, just display protected right part.
- * Here just for safety, should never happen in real life! */
- memmove(str, rpart, rpart_len + 1);
- rpart = NULL;
- okwidth += rpart_width;
- strwidth = rpart_width;
- }
- }
- }
-
- parts_strwidth = (okwidth - sep_strwidth) / 2.0f;
-
- if (rpart) {
- strcpy(rpart_buf, rpart);
- *rpart = '\0';
- rpart = rpart_buf;
- }
-
- l_end = BLF_width_to_strlen(fstyle->uifont_id, str, max_len, parts_strwidth, &rpart_width);
- if (l_end < 10 || min_ff(parts_strwidth, strwidth - okwidth) < minwidth) {
- /* If we really have no place, or we would clip a very small piece of string in the middle,
- * only show start of string.
- */
- ui_text_clip_right_ex(fstyle, str, max_len, okwidth, sep, sep_len, sep_strwidth, &final_lpart_len);
- }
- else {
- size_t r_offset, r_len;
-
- r_offset = BLF_width_to_rstrlen(fstyle->uifont_id, str, max_len, parts_strwidth, &rpart_width);
- r_len = strlen(str + r_offset) + 1; /* +1 for the trailing '\0'. */
-
- if (l_end + sep_len + r_len + rpart_len > max_len) {
- /* Corner case, the str already takes all available mem, and the ellipsis chars would actually
- * add more chars...
- * Better to just trim one or two letters to the right in this case...
- * Note: with a single-char ellipsis, this should never happen! But better be safe here...
- */
- ui_text_clip_right_ex(fstyle, str, max_len, okwidth, sep, sep_len, sep_strwidth, &final_lpart_len);
- }
- else {
- memmove(str + l_end + sep_len, str + r_offset, r_len);
- memcpy(str + l_end, sep, sep_len);
- final_lpart_len = (size_t)(l_end + sep_len + r_len - 1); /* -1 to remove trailing '\0'! */
- }
- }
-
- if (rpart) {
- /* Add back preserved right part to our shorten str. */
- memcpy(str + final_lpart_len, rpart, rpart_len + 1); /* +1 for trailing '\0'. */
- }
-
- strwidth = BLF_width(fstyle->uifont_id, str, max_len);
- }
-
- if (fstyle->kerning == 1) {
- BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
-
- return strwidth;
-}
-
-/**
- * Wrapper around UI_text_clip_middle_ex.
- */
-static void ui_text_clip_middle(uiFontStyle *fstyle, uiBut *but, const rcti *rect)
-{
- /* No margin for labels! */
- const int border = ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_MENU) ? 0 : (int)(UI_TEXT_CLIP_MARGIN + 0.5f);
- const float okwidth = (float)max_ii(BLI_rcti_size_x(rect) - border, 0);
- const size_t max_len = sizeof(but->drawstr);
- const float minwidth = (float)(UI_DPI_ICON_SIZE) / but->block->aspect * 2.0f;
-
- but->ofs = 0;
- but->strwidth = UI_text_clip_middle_ex(fstyle, but->drawstr, okwidth, minwidth, max_len, '\0');
-}
-
-/**
- * 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 rse
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list