Fix #19427, problem in blenfont not computing the width of text correct,
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 21 Sep 2009 21:26:04 +0000 (21:26 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 21 Sep 2009 21:26:04 +0000 (21:26 +0000)
particularly text including spaces. This gave some problems with placing
the cursor and selection, and clipping text inside buttons.

source/blender/blenfont/intern/blf_font.c
source/blender/editors/interface/interface_widgets.c

index 0a3dd259f6c4585acdeb066b8128d0b2d7709fa2..8721e49f06b23b53d537ac538f0713db05644411 100644 (file)
@@ -353,8 +353,8 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box)
                                pen_x += delta.x >> 6;
                }
 
-               gbox.xmin= g->box.xmin + pen_x;
-               gbox.xmax= g->box.xmax + pen_x;
+               gbox.xmin= pen_x;
+               gbox.xmax= pen_x + g->advance;
                gbox.ymin= g->box.ymin + pen_y;
                gbox.ymax= g->box.ymax + pen_y;
 
index 90b2c920613406bb5b7581443ad9146f2a25e0bf..ac8750f84e6600c8a7af1c48bea4da316bc1ef8d 100644 (file)
@@ -773,7 +773,8 @@ static void widget_draw_icon(uiBut *but, BIFIconID icon, int blend, rcti *rect)
 /* sets but->ofs to make sure text is correctly visible */
 static void ui_text_leftclip(uiFontStyle *fstyle, uiBut *but, rcti *rect)
 {
-       int okwidth= rect->xmax-rect->xmin;
+       int border= (but->flag & UI_BUT_ALIGN_RIGHT)? 8: 10;
+       int okwidth= rect->xmax-rect->xmin - border;
        
        /* need to set this first */
        uiStyleFontSet(fstyle);
@@ -842,11 +843,8 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
                                
                                but->drawstr[selend_tmp]= ch;
 
-                               /* if at pos 0, leave a bit more to the left */
-                               t= (pos == 0)? 0: 1;
-                               
                                glColor3ubv((unsigned char*)wcol->item);
-                               glRects(rect->xmin+selsta_draw+1, rect->ymin+2, rect->xmin+selwidth_draw+1, rect->ymax-2);
+                               glRects(rect->xmin+selsta_draw, rect->ymin+2, rect->xmin+selwidth_draw, rect->ymax-2);
                        }
                } else {
                        /* text cursor */
@@ -861,9 +859,6 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
                                        but->drawstr[pos]= ch;
                                }
 
-                               /* if at pos 0, leave a bit more to the left */
-                               t += (pos == 0)? 0: 1;
-                               
                                glColor3ub(255,0,0);
                                glRects(rect->xmin+t, rect->ymin+2, rect->xmin+t+2, rect->ymax-2);
                        }