[Bf-blender-cvs] [6f4515b] master: Fix for button selection offset
Campbell Barton
noreply at git.blender.org
Wed Dec 18 09:33:17 CET 2013
Commit: 6f4515b614ea7f667dcb4b0b5eea6f6d7b4c495f
Author: Campbell Barton
Date: Wed Dec 18 19:28:59 2013 +1100
http://developer.blender.org/rB6f4515b614ea7f667dcb4b0b5eea6f6d7b4c495f
Fix for button selection offset
Was using a different font size with selection and drawing,
But scaling both so they mostly matched.
This made selection shift noticeably when done on an interface zoomed in/out.
===================================================================
M source/blender/editors/interface/interface_handlers.c
===================================================================
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index f495d12..5e90884 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -1655,9 +1655,14 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con
{
uiStyle *style = UI_GetStyle(); // XXX pass on as arg
uiFontStyle *fstyle = &style->widget;
+ const float aspect = but->block->aspect;
+ const short fstyle_points_prev = fstyle->points;
+
float startx = but->rect.xmin;
char *origstr, password_str[UI_MAX_DRAW_STR];
+ ui_fontscale(&fstyle->points, aspect);
+
uiStyleFontSet(fstyle);
if (fstyle->kerning == 1) /* for BLF_width */
@@ -1671,7 +1676,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con
/* 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)));
+ startx += (int)(UI_TEXT_MARGIN_X * U.widget_unit);
}
else if (ELEM3(but->type, TEX, SEARCH_MENU, SEARCH_MENU_UNLINK)) {
if (but->flag & UI_HAS_ICON) {
@@ -1690,7 +1695,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, BLF_DRAW_STR_DUMMY_MAX) > (startx - x) * 0.25f) {
+ if (BLF_width(fstyle->uifont_id, origstr + i, BLF_DRAW_STR_DUMMY_MAX) * aspect > (startx - x) * 0.25f) {
break;
}
}
@@ -1712,7 +1717,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, BLF_DRAW_STR_DUMMY_MAX);
+ cdist = startx + BLF_width(fstyle->uifont_id, origstr + but->ofs, BLF_DRAW_STR_DUMMY_MAX) * aspect;
/* check if position is found */
if (cdist < x) {
@@ -1746,6 +1751,8 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con
ui_button_text_password_hide(password_str, but, TRUE);
MEM_freeN(origstr);
+
+ fstyle->points = fstyle_points_prev;
}
static void ui_textedit_set_cursor_select(uiBut *but, uiHandleButtonData *data, const float x)
More information about the Bf-blender-cvs
mailing list