Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/interface')
-rw-r--r--source/blender/editors/interface/interface.c2
-rw-r--r--source/blender/editors/interface/interface_handlers.c11
-rw-r--r--source/blender/editors/interface/interface_regions.c2
-rw-r--r--source/blender/editors/interface/interface_style.c12
-rw-r--r--source/blender/editors/interface/interface_templates.c2
-rw-r--r--source/blender/editors/interface/interface_widgets.c54
-rw-r--r--source/blender/editors/interface/view2d.c2
7 files changed, 35 insertions, 50 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index c82026eace6..46ee1700a06 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -218,7 +218,7 @@ static void ui_text_bounds_block(uiBlock *block, float offset)
for (bt = block->buttons.first; bt; bt = bt->next) {
if (bt->type != SEPR) {
- j = BLF_width(style->widget.uifont_id, bt->drawstr);
+ j = BLF_width(style->widget.uifont_id, bt->drawstr, sizeof(bt->drawstr));
if (j > i) i = j;
}
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index ee6663d7954..1ed0c128a20 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -1616,8 +1616,7 @@ void ui_button_text_password_hide(char password_str[UI_MAX_DRAW_STR], uiBut *but
/* save original string */
BLI_strncpy(password_str, but->drawstr, UI_MAX_DRAW_STR);
- for (i = 0; i < len; i++)
- but->drawstr[i] = '*';
+ memset(but->drawstr, '*', len);
but->drawstr[i] = '\0';
}
}
@@ -1656,9 +1655,9 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con
ui_button_text_password_hide(password_str, but, FALSE);
origstr = MEM_mallocN(sizeof(char) * data->maxlen, "ui_textedit origstr");
-
+
BLI_strncpy(origstr, but->drawstr, data->maxlen);
-
+
/* XXX solve generic, see: #widget_draw_text_icon */
if (but->type == NUM || but->type == NUMSLI) {
startx += (int)(0.5f * (BLI_rctf_size_y(&but->rect)));
@@ -1680,7 +1679,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con
while (i > 0) {
if (BLI_str_cursor_step_prev_utf8(origstr, but->ofs, &i)) {
/* 0.25 == scale factor for less sensitivity */
- if (BLF_width(fstyle->uifont_id, origstr + i) > (startx - x) * 0.25f) {
+ if (BLF_width(fstyle->uifont_id, origstr + i, BLF_DRAW_STR_DUMMY_MAX) > (startx - x) * 0.25f) {
break;
}
}
@@ -1702,7 +1701,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con
but->pos = pos_prev = strlen(origstr) - but->ofs;
while (true) {
- cdist = startx + BLF_width(fstyle->uifont_id, origstr + but->ofs);
+ cdist = startx + BLF_width(fstyle->uifont_id, origstr + but->ofs, BLF_DRAW_STR_DUMMY_MAX);
/* check if position is found */
if (cdist < x) {
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index a6216b486ad..2f37d8e6e98 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -660,7 +660,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
h = BLF_height_max(data->fstyle.uifont_id);
for (a = 0, fontw = 0, fonth = 0; a < data->totline; a++) {
- w = BLF_width(data->fstyle.uifont_id, data->lines[a]);
+ w = BLF_width(data->fstyle.uifont_id, data->lines[a], sizeof(data->lines[a]));
fontw = max_ff(fontw, (float)w);
fonth += (a == 0) ? h : h + TIP_MARGIN_Y;
}
diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c
index 1c6263c9dd5..38d9f4fcc12 100644
--- a/source/blender/editors/interface/interface_style.c
+++ b/source/blender/editors/interface/interface_style.c
@@ -144,7 +144,7 @@ static uiFont *uifont_to_blfont(int id)
void uiStyleFontDrawExt(uiFontStyle *fs, const rcti *rect, const char *str,
- float *r_xofs, float *r_yofs)
+ size_t len, float *r_xofs, float *r_yofs)
{
float height;
int xofs = 0, yofs;
@@ -155,14 +155,14 @@ void uiStyleFontDrawExt(uiFontStyle *fs, const rcti *rect, const char *str,
yofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height));
if (fs->align == UI_STYLE_TEXT_CENTER) {
- xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str)));
+ 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) - 0.1f * U.widget_unit;
+ 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 */
@@ -194,7 +194,7 @@ void uiStyleFontDraw(uiFontStyle *fs, rcti *rect, const char *str)
{
float xofs, yofs;
uiStyleFontDrawExt(fs, rect, str,
- &xofs, &yofs);
+ BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs);
}
/* drawn same as above, but at 90 degree angle */
@@ -215,7 +215,7 @@ void uiStyleFontDrawRotated(uiFontStyle *fs, rcti *rect, const char *str)
/* rotate counter-clockwise for now (assumes left-to-right language)*/
xofs += height;
- yofs = BLF_width(fs->uifont_id, str) + 5;
+ yofs = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX) + 5;
angle = (float)M_PI / 2.0f;
/* translate rect to vertical */
@@ -298,7 +298,7 @@ int UI_GetStringWidth(const char *str)
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
uiStyleFontSet(fstyle);
- width = BLF_width(fstyle->uifont_id, str);
+ width = BLF_width(fstyle->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
if (fstyle->kerning == 1)
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 8926a16481d..6bb6081d135 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -3299,7 +3299,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
ui_abs = uiLayoutAbsolute(layout, FALSE);
block = uiLayoutGetBlock(ui_abs);
- width = BLF_width(style->widget.uifont_id, report->message);
+ width = BLF_width(style->widget.uifont_id, report->message, report->len);
width = min_ii((int)(rti->widthfac * width), width);
width = max_ii(width, 10);
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 0691eb4a9b8..27f16a6fd5c 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -967,11 +967,11 @@ static void ui_text_clip_left(uiFontStyle *fstyle, uiBut *but, const rcti *rect)
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
but->ofs = 0;
- but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr);
+ but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr, sizeof(but->drawstr));
while (but->strwidth > okwidth) {
ui_text_clip_give_next_off(but);
- but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
+ but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs);
if (but->strwidth < 10) break;
}
@@ -1001,10 +1001,10 @@ static void ui_text_clip_cursor(uiFontStyle *fstyle, uiBut *but, const rcti *rec
if (but->ofs > but->pos)
but->ofs = but->pos;
- if (BLF_width(fstyle->uifont_id, but->drawstr) <= okwidth)
+ if (BLF_width(fstyle->uifont_id, but->drawstr, sizeof(but->drawstr)) <= okwidth)
but->ofs = 0;
- but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
+ but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs);
while (but->strwidth > okwidth) {
float width;
@@ -1014,7 +1014,7 @@ static void ui_text_clip_cursor(uiFontStyle *fstyle, uiBut *but, const rcti *rec
BLI_strncpy_utf8(buf, but->drawstr, sizeof(buf));
/* string position of cursor */
buf[but->pos] = 0;
- width = BLF_width(fstyle->uifont_id, buf + but->ofs);
+ width = BLF_width(fstyle->uifont_id, buf + but->ofs, sizeof(buf) - but->ofs);
/* if cursor is at 20 pixels of right side button we clip left */
if (width > okwidth - 20) {
@@ -1032,7 +1032,7 @@ static void ui_text_clip_cursor(uiFontStyle *fstyle, uiBut *but, const rcti *rec
but->drawstr[len - bytes] = 0;
}
- but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
+ but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs);
if (but->strwidth < 10) break;
}
@@ -1061,7 +1061,7 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti
if (fstyle->kerning == 1) /* for BLF_width */
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr);
+ but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr, sizeof(but->drawstr));
but->ofs = 0;
@@ -1089,7 +1089,7 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti
drawstr_len -= bytes;
// BLI_assert(strlen(but->drawstr) == drawstr_len);
- but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
+ but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs);
if (but->strwidth < 10) break;
}
@@ -1097,7 +1097,7 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti
/* after the leading text is gone, chop off the : and following space, with ofs */
while ((but->strwidth > okwidth) && (but->ofs < 2)) {
ui_text_clip_give_next_off(but);
- but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
+ but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs);
if (but->strwidth < 10) break;
}
@@ -1115,7 +1115,7 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti
but->drawstr[drawstr_len] = 0;
// BLI_assert(strlen(but->drawstr) == drawstr_len);
- but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
+ but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs);
if (but->strwidth < 10) break;
}
@@ -1146,7 +1146,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
/* text button selection and cursor */
if (but->editstr && but->pos != -1) {
- short t = 0, pos = 0, ch;
+ short t = 0, pos = 0;
short selsta_tmp, selend_tmp, selsta_draw, selwidth_draw;
if ((but->selend - but->selsta) > 0) {
@@ -1157,23 +1157,13 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
if (but->drawstr[0] != 0) {
if (but->selsta >= but->ofs) {
- ch = but->drawstr[selsta_tmp];
- but->drawstr[selsta_tmp] = 0;
-
- selsta_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
-
- but->drawstr[selsta_tmp] = ch;
+ selsta_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, selsta_tmp - but->ofs);
}
else {
selsta_draw = 0;
}
-
- ch = but->drawstr[selend_tmp];
- but->drawstr[selend_tmp] = 0;
-
- selwidth_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
-
- but->drawstr[selend_tmp] = ch;
+
+ selwidth_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, selend_tmp - but->ofs);
glColor4ubv((unsigned char *)wcol->item);
glRects(rect->xmin + selsta_draw, rect->ymin + 2, rect->xmin + selwidth_draw, rect->ymax - 2);
@@ -1184,12 +1174,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
pos = but->pos;
if (pos >= but->ofs) {
if (but->drawstr[0] != 0) {
- ch = but->drawstr[pos];
- but->drawstr[pos] = 0;
-
- t = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs) / but->aspect;
-
- but->drawstr[pos] = ch;
+ t = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, pos - but->ofs) / but->aspect;
}
glColor3f(0.20, 0.6, 0.9);
@@ -1216,7 +1201,8 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
glColor4ubv((unsigned char *)wcol->text);
- uiStyleFontDrawExt(fstyle, rect, but->drawstr + but->ofs, &font_xofs, &font_yofs);
+ uiStyleFontDrawExt(fstyle, rect, but->drawstr + but->ofs,
+ sizeof(but->drawstr) - but->ofs, &font_xofs, &font_yofs);
if (but->menu_key != '\0') {
char fixedbuf[128];
@@ -1239,7 +1225,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
}
fixedbuf[ul_index] = '\0';
- ul_advance = BLF_width(fstyle->uifont_id, fixedbuf);
+ ul_advance = BLF_width(fstyle->uifont_id, fixedbuf, ul_index);
BLF_position(fstyle->uifont_id, rect->xmin + font_xofs + ul_advance, rect->ymin + font_yofs, 0.0f);
BLF_draw(fstyle->uifont_id, "_", 2);
@@ -3528,7 +3514,7 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int ic
cpoin = strchr(name, UI_SEP_CHAR);
if (cpoin) {
*cpoin = 0;
- rect->xmax -= BLF_width(fstyle->uifont_id, cpoin + 1) + 10;
+ rect->xmax -= BLF_width(fstyle->uifont_id, cpoin + 1, INT_MAX) + 10;
}
}
@@ -3574,7 +3560,7 @@ void ui_draw_preview_item(uiFontStyle *fstyle, rcti *rect, const char *name, int
widget_draw_preview(iconid, 1.0f, rect);
- BLF_width_and_height(fstyle->uifont_id, name, &font_dims[0], &font_dims[1]);
+ BLF_width_and_height(fstyle->uifont_id, name, BLF_DRAW_STR_DUMMY_MAX, &font_dims[0], &font_dims[1]);
/* text rect */
trect.xmin += 0;
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index e3787789165..6bb623155a5 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -2196,7 +2196,7 @@ void UI_view2d_text_cache_draw(ARegion *ar)
int col_pack_prev = 0;
/* investigate using BLF_ascender() */
- const float default_height = strings.first ? BLF_height_default("28") : 0.0f;
+ const float default_height = strings.first ? BLF_height_default("28", 3) : 0.0f;
// glMatrixMode(GL_PROJECTION);
// glPushMatrix();