Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2010-12-07 10:02:47 +0300
committerCampbell Barton <ideasman42@gmail.com>2010-12-07 10:02:47 +0300
commitd620ff838053b58cc571913e6a1f68fa4f6a1d73 (patch)
tree9b1fa155a0dccfd476ad275d3572ee1019ee2040 /source/blender/editors/interface/view2d.c
parent612936954ac67cacee8d13f48ed1bd8b5ff386c7 (diff)
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.
Diffstat (limited to 'source/blender/editors/interface/view2d.c')
-rw-r--r--source/blender/editors/interface/view2d.c52
1 files changed, 30 insertions, 22 deletions
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);
}
}