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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2014-06-14 22:06:44 +0400
committerCampbell Barton <ideasman42@gmail.com>2014-06-14 22:32:41 +0400
commitfa17e3b14c102e11887292536f62967388cbcba1 (patch)
tree23abd1dd2e91a544e6a94eefd58cdff6a9795770 /source
parent9c1728457b3f2c3e6a575bd806aaaf7a118c82cc (diff)
UI: refactor text cache to use zero length arrays
also correct some bad casts
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/interface/view2d.c14
-rw-r--r--source/blender/editors/space_view3d/drawobject.c14
2 files changed, 16 insertions, 12 deletions
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index 982e8f1a9fe..45dd47097f5 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -2277,6 +2277,9 @@ typedef struct View2DString {
} col;
rcti rect;
int mval[2];
+
+ /* str is allocated past the end */
+ char str[0];
} View2DString;
/* assumes caches are used correctly, so for time being no local storage in v2d */
@@ -2309,7 +2312,7 @@ void UI_view2d_text_cache_add(View2D *v2d, float x, float y,
v2s->mval[0] = mval[0];
v2s->mval[1] = mval[1];
- memcpy(v2s + 1, str, alloc_len);
+ memcpy(v2s->str, str, alloc_len);
}
}
@@ -2340,7 +2343,7 @@ void UI_view2d_text_cache_add_rectf(View2D *v2d, const rctf *rect_view,
v2s->mval[0] = v2s->rect.xmin;
v2s->mval[1] = v2s->rect.ymin;
- memcpy(v2s + 1, str, alloc_len);
+ memcpy(v2s->str, str, alloc_len);
}
}
@@ -2360,7 +2363,6 @@ void UI_view2d_text_cache_draw(ARegion *ar)
ED_region_pixelspace(ar);
for (v2s = g_v2d_strings; v2s; v2s = v2s->next) {
- const char *str = (const char *)(v2s + 1);
int xofs = 0, yofs;
yofs = ceil(0.5f * (BLI_rcti_size_y(&v2s->rect) - default_height));
@@ -2372,11 +2374,13 @@ void UI_view2d_text_cache_draw(ARegion *ar)
}
if (v2s->rect.xmin >= v2s->rect.xmax)
- BLF_draw_default((float)v2s->mval[0] + xofs, (float)v2s->mval[1] + yofs, 0.0, str, BLF_DRAW_STR_DUMMY_MAX);
+ BLF_draw_default((float)(v2s->mval[0] + xofs), (float)(v2s->mval[1] + yofs), 0.0,
+ v2s->str, BLF_DRAW_STR_DUMMY_MAX);
else {
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, str, BLF_DRAW_STR_DUMMY_MAX);
+ BLF_draw_default(v2s->rect.xmin + xofs, v2s->rect.ymin + yofs, 0.0f,
+ v2s->str, BLF_DRAW_STR_DUMMY_MAX);
BLF_disable_default(BLF_CLIPPING);
}
}
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 0510ecda70b..3393cf7f99c 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -763,8 +763,10 @@ typedef struct ViewCachedString {
short sco[2];
short xoffs;
short flag;
- int str_len, pad;
+ int str_len;
+
/* str is allocated past the end */
+ char str[0];
} ViewCachedString;
/* one arena for all 3 string lists */
@@ -809,7 +811,7 @@ void view3d_cached_text_draw_add(const float co[3],
vos->str_len = str_len;
/* allocate past the end */
- memcpy(vos + 1, str, alloc_len);
+ memcpy(vos->str, str, alloc_len);
}
void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, bool depth_write, float mat[4][4])
@@ -868,8 +870,6 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, bool depth_write, flo
for (vos = g_v3d_strings[g_v3d_string_level]; vos; vos = vos->next) {
if (vos->sco[0] != IS_CLIPPED) {
- const char *str = (char *)(vos + 1);
-
if (col_pack_prev != vos->col.pack) {
glColor3ubv(vos->col.ub);
col_pack_prev = vos->col.pack;
@@ -878,10 +878,10 @@ void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, bool depth_write, flo
((vos->flag & V3D_CACHE_TEXT_ASCII) ?
BLF_draw_default_ascii :
BLF_draw_default
- )( (float)vos->sco[0] + vos->xoffs,
- (float)vos->sco[1],
+ )((float)(vos->sco[0] + vos->xoffs),
+ (float)(vos->sco[1]),
(depth_write) ? 0.0f : 2.0f,
- str,
+ vos->str,
vos->str_len);
}
}