[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [27953] trunk/blender/source/blender/ editors/interface: Fix [#21694] text input box last character not editable

Matt Ebb matt at mke3.net
Fri Apr 2 13:15:37 CEST 2010


Revision: 27953
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=27953
Author:   broken
Date:     2010-04-02 13:15:37 +0200 (Fri, 02 Apr 2010)

Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/editors/interface/interface_style.c
    trunk/blender/source/blender/editors/interface/interface_widgets.c

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2010-04-02 10:32:58 UTC (rev 27952)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2010-04-02 11:15:37 UTC (rev 27953)
@@ -1142,11 +1142,15 @@
 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 @@
 		if(but->pos<0) but->pos= 0;
 	}
 	
+	if (fstyle->kerning == 1)
+		BLF_disable(BLF_KERNING_DEFAULT);
+	
 	MEM_freeN(origstr);
 }
 
@@ -1518,6 +1525,8 @@
 	}
 	
 	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 @@
 		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)

Modified: trunk/blender/source/blender/editors/interface/interface_style.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_style.c	2010-04-02 10:32:58 UTC (rev 27952)
+++ trunk/blender/source/blender/editors/interface/interface_style.c	2010-04-02 11:15:37 UTC (rev 27953)
@@ -237,9 +237,19 @@
 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 */

Modified: trunk/blender/source/blender/editors/interface/interface_widgets.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_widgets.c	2010-04-02 10:32:58 UTC (rev 27952)
+++ trunk/blender/source/blender/editors/interface/interface_widgets.c	2010-04-02 11:15:37 UTC (rev 27953)
@@ -811,6 +811,9 @@
 	
 	/* 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 @@
 		
 		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 @@
 	/* 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 @@
 		if(but->strwidth < 10) break;
 	}
 	
+	if (fstyle->kerning==1)
+		BLF_disable(BLF_KERNING_DEFAULT);
 }
 
 
@@ -904,7 +915,10 @@
 		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 @@
 					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();





More information about the Bf-blender-cvs mailing list