From d620ff838053b58cc571913e6a1f68fa4f6a1d73 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 7 Dec 2010 07:02:47 +0000 Subject: 2D text drawing - with the NLA on a small strip text was drawn under the scroll bar, now draw with same alignment as rectangle constrained text. - single alloc per text item. - was using opengl context rather then passing color value. --- source/blender/editors/interface/view2d.c | 52 ++++++++++++++++++------------- 1 file changed, 30 insertions(+), 22 deletions(-) (limited to 'source/blender/editors/interface/view2d.c') diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index 0cd4518fe85..21146dc8cec 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -2006,42 +2006,48 @@ static ListBase strings= {NULL, NULL}; typedef struct View2DString { struct View2DString *next, *prev; - float col[4]; - char str[128]; + GLbyte col[4]; short mval[2]; rcti rect; } View2DString; -void UI_view2d_text_cache_add(View2D *v2d, float x, float y, char *str) +void UI_view2d_text_cache_add(View2D *v2d, float x, float y, const char *str, const char col[4]) { int mval[2]; UI_view2d_view_to_region(v2d, x, y, mval, mval+1); if(mval[0]!=V2D_IS_CLIPPED && mval[1]!=V2D_IS_CLIPPED) { + int len= strlen(str)+1; /* use calloc, rect has to be zeroe'd */ - View2DString *v2s= MEM_callocN(sizeof(View2DString), "View2DString"); - + View2DString *v2s= MEM_callocN(sizeof(View2DString)+len, "View2DString"); + char *v2s_str= (char *)(v2s+1); + memcpy(v2s_str, str, len); + BLI_addtail(&strings, v2s); - BLI_strncpy(v2s->str, str, 128); v2s->mval[0]= mval[0]; v2s->mval[1]= mval[1]; - glGetFloatv(GL_CURRENT_COLOR, v2s->col); + QUATCOPY(v2s->col, col); } } /* no clip (yet) */ -void UI_view2d_text_cache_rectf(View2D *v2d, rctf *rect, char *str) +void UI_view2d_text_cache_rectf(View2D *v2d, rctf *rect, const char *str, const char col[4]) { - View2DString *v2s= MEM_callocN(sizeof(View2DString), "View2DString"); - + int len= strlen(str)+1; + View2DString *v2s= MEM_callocN(sizeof(View2DString)+len, "View2DString"); + char *v2s_str= (char *)(v2s+1); + memcpy(v2s_str, str, len); + UI_view2d_to_region_no_clip(v2d, rect->xmin, rect->ymin, &v2s->rect.xmin, &v2s->rect.ymin); UI_view2d_to_region_no_clip(v2d, rect->xmax, rect->ymax, &v2s->rect.xmax, &v2s->rect.ymax); - + + v2s->mval[0]= v2s->rect.xmin; + v2s->mval[1]= v2s->rect.ymin; + BLI_addtail(&strings, v2s); - BLI_strncpy(v2s->str, str, 128); - glGetFloatv(GL_CURRENT_COLOR, v2s->col); + QUATCOPY(v2s->col, col); } @@ -2056,18 +2062,20 @@ void UI_view2d_text_cache_draw(ARegion *ar) ED_region_pixelspace(ar); for(v2s= strings.first; v2s; v2s= v2s->next) { - glColor3fv(v2s->col); - if(v2s->rect.xmin==v2s->rect.xmax) - BLF_draw_default((float)v2s->mval[0], (float)v2s->mval[1], 0.0, v2s->str, sizeof(v2s->str)-1); + const char *str= (const char *)(v2s+1); + int xofs=0, yofs; + + yofs= ceil( 0.5f*(v2s->rect.ymax - v2s->rect.ymin - BLF_height_default("28"))); + if(yofs<1) yofs= 1; + + glColor3bv(v2s->col); + + if(v2s->rect.xmin >= v2s->rect.xmax) + BLF_draw_default((float)v2s->mval[0]+xofs, (float)v2s->mval[1]+yofs, 0.0, str, 65535); else { - int xofs=0, yofs; - - yofs= ceil( 0.5f*(v2s->rect.ymax - v2s->rect.ymin - BLF_height_default("28"))); - if(yofs<1) yofs= 1; - BLF_clipping_default(v2s->rect.xmin-4, v2s->rect.ymin-4, v2s->rect.xmax+4, v2s->rect.ymax+4); BLF_enable_default(BLF_CLIPPING); - BLF_draw_default(v2s->rect.xmin+xofs, v2s->rect.ymin+yofs, 0.0f, v2s->str, sizeof(v2s->str)-1); + BLF_draw_default(v2s->rect.xmin+xofs, v2s->rect.ymin+yofs, 0.0f, str, 65535); BLF_disable_default(BLF_CLIPPING); } } -- cgit v1.2.3