Interface: avoid setting \0 to drawstr in widget_draw_text

This commit is contained in:
2013-12-11 20:33:17 +11:00
parent c0b717b046
commit 8e94d3685a
2 changed files with 12 additions and 10 deletions

View File

@@ -179,7 +179,7 @@ void uiStyleFontDrawExt(uiFontStyle *fs, const rcti *rect, const char *str,
if (fs->kerning == 1)
BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
BLF_draw(fs->uifont_id, str, len);
BLF_disable(fs->uifont_id, BLF_CLIPPING);
if (fs->shadow)
BLF_disable(fs->uifont_id, BLF_SHADOW);

View File

@@ -1122,8 +1122,8 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti
static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *but, rcti *rect)
{
//int transopts; // UNUSED
char *cpoin = NULL;
int drawstr_left_len = UI_MAX_DRAW_STR;
char *drawstr_right = NULL;
/* for underline drawing */
float font_xofs, font_yofs;
@@ -1190,21 +1190,24 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
/* cut string in 2 parts - only for menu entries */
if ((but->block->flag & UI_BLOCK_LOOP)) {
if (ELEM3(but->type, NUM, TEX, NUMSLI) == 0) {
cpoin = strchr(but->drawstr, UI_SEP_CHAR);
if (cpoin) *cpoin = 0;
drawstr_right = strchr(but->drawstr, UI_SEP_CHAR);
if (drawstr_right) {
drawstr_left_len = (drawstr_right - but->drawstr);
drawstr_right++;
}
}
}
glColor4ubv((unsigned char *)wcol->text);
uiStyleFontDrawExt(fstyle, rect, but->drawstr + but->ofs,
sizeof(but->drawstr) - but->ofs, &font_xofs, &font_yofs);
drawstr_left_len - but->ofs, &font_xofs, &font_yofs);
if (but->menu_key != '\0') {
char fixedbuf[128];
char *str;
BLI_strncpy(fixedbuf, but->drawstr + but->ofs, sizeof(fixedbuf));
BLI_strncpy(fixedbuf, but->drawstr + but->ofs, min_ii(sizeof(fixedbuf), drawstr_left_len));
str = strchr(fixedbuf, but->menu_key - 32); /* upper case */
if (str == NULL)
@@ -1233,11 +1236,10 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
}
/* part text right aligned */
if (cpoin) {
if (drawstr_right) {
fstyle->align = UI_STYLE_TEXT_RIGHT;
rect->xmax -= ui_but_draw_menu_icon(but) ? UI_DPI_ICON_SIZE : 0.25f * U.widget_unit;
uiStyleFontDraw(fstyle, rect, cpoin + 1);
*cpoin = UI_SEP_CHAR;
uiStyleFontDraw(fstyle, rect, drawstr_right);
}
}