diff options
author | Matt Ebb <matt@mke3.net> | 2010-04-02 15:15:37 +0400 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2010-04-02 15:15:37 +0400 |
commit | 5d155868fbb6ffd40f01d47d1867dc482282da21 (patch) | |
tree | f44287117ea825134b7028aba3380d93f226a36d /source | |
parent | d03d42fe72b1326d575dd0e1a0402501a358a836 (diff) |
Fix [#21694] text input box last character not editable
Font kerning needs to be set in order to get accurate results out of BLF_width().
Would be nice if this was more automatic, I've added it to a few other places that
seem like they need this though it's a little unclear due to the globals etc. Also
some other minor tweaks when editing text fields.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/editors/interface/interface_handlers.c | 13 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_style.c | 14 | ||||
-rw-r--r-- | source/blender/editors/interface/interface_widgets.c | 24 |
3 files changed, 45 insertions, 6 deletions
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index 54296b7cd6a..2869009aa1a 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1142,11 +1142,15 @@ static int ui_textedit_delete_selection(uiBut *but, uiHandleButtonData *data) static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, short x) { uiStyle *style= U.uistyles.first; // XXX pass on as arg + uiFontStyle *fstyle = &style->widget; int startx= but->x1; char *origstr; - uiStyleFontSet(&style->widget); + uiStyleFontSet(fstyle); + if (fstyle->kerning==1) /* for BLF_width */ + BLF_enable(BLF_KERNING_DEFAULT); + origstr= MEM_callocN(sizeof(char)*data->maxlen, "ui_textedit origstr"); BLI_strncpy(origstr, but->drawstr, data->maxlen); @@ -1187,6 +1191,9 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, sho if(but->pos<0) but->pos= 0; } + if (fstyle->kerning == 1) + BLF_disable(BLF_KERNING_DEFAULT); + MEM_freeN(origstr); } @@ -1518,6 +1525,8 @@ static void ui_textedit_begin(bContext *C, uiBut *but, uiHandleButtonData *data) } ui_check_but(but); + + WM_cursor_modal(CTX_wm_window(C), BC_TEXTEDITCURSOR); } static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data) @@ -1534,6 +1543,8 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data) but->editstr= NULL; but->pos= -1; } + + WM_cursor_restore(CTX_wm_window(C)); } static void ui_textedit_next_but(uiBlock *block, uiBut *actbut, uiHandleButtonData *data) diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index ae149cad480..aaebdf5693a 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -237,9 +237,19 @@ void uiStyleFontDrawRotated(uiFontStyle *fs, rcti *rect, char *str) int UI_GetStringWidth(char *str) { uiStyle *style= U.uistyles.first; + uiFontStyle *fstyle= &style->widget; + int width; - uiStyleFontSet(&style->widget); - return BLF_width(str); + if (fstyle->kerning==1) /* for BLF_width */ + BLF_enable(BLF_KERNING_DEFAULT); + + uiStyleFontSet(fstyle); + width= BLF_width(str); + + if (fstyle->kerning==1) + BLF_disable(BLF_KERNING_DEFAULT); + + return width; } /* temporarily, does widget font */ diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 465a58fe5b8..1c75a05e084 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -811,6 +811,9 @@ static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) /* need to set this first */ uiStyleFontSet(fstyle); + + if (fstyle->kerning==1) /* for BLF_width */ + BLF_enable(BLF_KERNING_DEFAULT); but->strwidth= BLF_width(but->drawstr); but->ofs= 0; @@ -837,6 +840,9 @@ static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) if(but->strwidth < 10) break; } + + if (fstyle->kerning==1) + BLF_disable(BLF_KERNING_DEFAULT); } static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) @@ -849,6 +855,9 @@ static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) /* need to set this first */ uiStyleFontSet(fstyle); + if (fstyle->kerning==1) /* for BLF_width */ + BLF_enable(BLF_KERNING_DEFAULT); + but->strwidth= BLF_width(but->drawstr); but->ofs= 0; @@ -890,6 +899,8 @@ static void ui_text_label_rightclip(uiFontStyle *fstyle, uiBut *but, rcti *rect) if(but->strwidth < 10) break; } + if (fstyle->kerning==1) + BLF_disable(BLF_KERNING_DEFAULT); } @@ -904,7 +915,10 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b fstyle->align= UI_STYLE_TEXT_LEFT; else fstyle->align= UI_STYLE_TEXT_CENTER; - + + if (fstyle->kerning==1) /* for BLF_width */ + BLF_enable(BLF_KERNING_DEFAULT); + /* text button selection and cursor */ if(but->editstr && but->pos != -1) { short t=0, pos=0, ch; @@ -945,16 +959,20 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b ch= but->drawstr[pos]; but->drawstr[pos]= 0; - t= BLF_width(but->drawstr+but->ofs); + t= BLF_width(but->drawstr+but->ofs) / but->aspect; but->drawstr[pos]= ch; } - glColor3ub(255,0,0); + glColor3f(0.20, 0.6, 0.9); glRects(rect->xmin+t, rect->ymin+2, rect->xmin+t+2, rect->ymax-2); } } } + + if (fstyle->kerning == 1) + BLF_disable(BLF_KERNING_DEFAULT); + // ui_rasterpos_safe(x, y, but->aspect); // if(but->type==IDPOIN) transopts= 0; // no translation, of course! // else transopts= ui_translate_buttons(); |