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:
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c70
-rw-r--r--source/blender/blenfont/intern/blf_internal.h2
-rw-r--r--source/blender/blenlib/BLI_rect.h4
-rw-r--r--source/blender/blenlib/intern/rct.c19
4 files changed, 51 insertions, 44 deletions
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index d683378c7ce..4812f8f23f7 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -371,14 +371,20 @@ static void blf_texture3_draw(const float shadow_col[4], float uv[2][2], float x
glColor4fv(color);
}
-int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
+static void blf_glyph_calc_rect(rctf *rect, GlyphBLF *g, float x, float y)
{
- float dx, dx1;
- float y1, y2;
- float xo, yo;
+ rect->xmin = floor(x + g->pos_x);
+ rect->xmax = rect->xmin + g->width;
+ rect->ymin = y + g->pos_y;
+ rect->ymax = y + g->pos_y - g->height;
+}
+
+void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
+{
+ rctf rect;
if ((!g->width) || (!g->height))
- return 1;
+ return;
if (g->build_tex == 0) {
GlyphCacheBLF *gc = font->glyph_cache;
@@ -440,30 +446,16 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
g->build_tex = 1;
}
- xo = 0.0f;
- yo = 0.0f;
-
- if (font->flags & BLF_SHADOW) {
- xo = x;
- yo = y;
- x += font->shadow_x;
- y += font->shadow_y;
- }
-
- dx = floor(x + g->pos_x);
- dx1 = dx + g->width;
- y1 = y + g->pos_y;
- y2 = y + g->pos_y - g->height;
+ blf_glyph_calc_rect(&rect, g, x, y);
if (font->flags & BLF_CLIPPING) {
- if (!BLI_rctf_isect_pt(&font->clip_rec, dx + font->pos[0], y1 + font->pos[1]))
- return 0;
- if (!BLI_rctf_isect_pt(&font->clip_rec, dx + font->pos[0], y2 + font->pos[1]))
- return 0;
- if (!BLI_rctf_isect_pt(&font->clip_rec, dx1 + font->pos[0], y2 + font->pos[1]))
- return 0;
- if (!BLI_rctf_isect_pt(&font->clip_rec, dx1 + font->pos[0], y1 + font->pos[1]))
- return 0;
+ /* intentionally check clipping without shadow offset */
+ rctf rect_test = rect;
+ BLI_rctf_translate(&rect_test, font->pos[0], font->pos[1]);
+
+ if (!BLI_rctf_inside_rctf(&font->clip_rec, &rect_test)) {
+ return;
+ }
}
if (font->tex_bind_state != g->tex) {
@@ -471,42 +463,36 @@ int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
}
if (font->flags & BLF_SHADOW) {
+ rctf rect_ofs;
+ blf_glyph_calc_rect(&rect_ofs, g, x + font->shadow_x, y + font->shadow_y);
switch (font->shadow) {
case 3:
- blf_texture3_draw(font->shadow_col, g->uv, dx, y1, dx1, y2);
+ blf_texture3_draw(font->shadow_col, g->uv, rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
break;
case 5:
- blf_texture5_draw(font->shadow_col, g->uv, dx, y1, dx1, y2);
+ blf_texture5_draw(font->shadow_col, g->uv, rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
break;
default:
glColor4fv(font->shadow_col);
- blf_texture_draw(g->uv, dx, y1, dx1, y2);
+ blf_texture_draw(g->uv, rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
break;
}
glColor4fv(font->orig_col);
-
- x = xo;
- y = yo;
-
- dx = floor(x + g->pos_x);
- dx1 = dx + g->width;
- y1 = y + g->pos_y;
- y2 = y + g->pos_y - g->height;
}
switch (font->blur) {
case 3:
- blf_texture3_draw(font->orig_col, g->uv, dx, y1, dx1, y2);
+ blf_texture3_draw(font->orig_col, g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
break;
case 5:
- blf_texture5_draw(font->orig_col, g->uv, dx, y1, dx1, y2);
+ blf_texture5_draw(font->orig_col, g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
break;
default:
- blf_texture_draw(g->uv, dx, y1, dx1, y2);
+ blf_texture_draw(g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
break;
}
- return 1;
+ return;
}
diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h
index 2cb453cdf55..7d4b39dd337 100644
--- a/source/blender/blenfont/intern/blf_internal.h
+++ b/source/blender/blenfont/intern/blf_internal.h
@@ -71,6 +71,6 @@ struct GlyphBLF *blf_glyph_search(struct GlyphCacheBLF *gc, unsigned int c);
struct GlyphBLF *blf_glyph_add(struct FontBLF *font, unsigned int index, unsigned int c);
void blf_glyph_free(struct GlyphBLF *g);
-int blf_glyph_render(struct FontBLF *font, struct GlyphBLF *g, float x, float y);
+void blf_glyph_render(struct FontBLF *font, struct GlyphBLF *g, float x, float y);
#endif /* __BLF_INTERNAL_H__ */
diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h
index ac0ae22c656..f8b9088fe3d 100644
--- a/source/blender/blenlib/BLI_rect.h
+++ b/source/blender/blenlib/BLI_rect.h
@@ -74,8 +74,10 @@ bool BLI_rctf_isect_pt(const struct rctf *rect, const float x, const float y);
bool BLI_rctf_isect_pt_v(const struct rctf *rect, const float xy[2]);
bool BLI_rcti_isect_segment(const struct rcti *rect, const int s1[2], const int s2[2]);
bool BLI_rctf_isect_segment(const struct rctf *rect, const float s1[2], const float s2[2]);
-void BLI_rctf_union(struct rctf *rctf1, const struct rctf *rctf2);
+bool BLI_rcti_inside_rcti(rcti *rct_a, const rcti *rct_b);
+bool BLI_rctf_inside_rctf(rctf *rct_a, const rctf *rct_b);
void BLI_rcti_union(struct rcti *rcti1, const struct rcti *rcti2);
+void BLI_rctf_union(struct rctf *rctf1, const struct rctf *rctf2);
void BLI_rcti_rctf_copy(struct rcti *dst, const struct rctf *src);
void BLI_rctf_rcti_copy(struct rctf *dst, const struct rcti *src);
diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c
index 91fcb5a5b83..02525e25dda 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -101,6 +101,25 @@ bool BLI_rctf_isect_pt_v(const rctf *rect, const float xy[2])
return true;
}
+/**
+ * is \a rct_b inside \a rct_a
+ */
+bool BLI_rctf_inside_rctf(rctf *rct_a, const rctf *rct_b)
+{
+ return ((rct_a->xmin <= rct_b->xmin) &&
+ (rct_a->xmax >= rct_b->xmax) &&
+ (rct_a->ymin <= rct_b->ymin) &&
+ (rct_a->ymax >= rct_b->ymax));
+}
+bool BLI_rcti_inside_rcti(rcti *rct_a, const rcti *rct_b)
+{
+ return ((rct_a->xmin <= rct_b->xmin) &&
+ (rct_a->xmax >= rct_b->xmax) &&
+ (rct_a->ymin <= rct_b->ymin) &&
+ (rct_a->ymax >= rct_b->ymax));
+}
+
+
/* based closely on 'isect_line_line_v2_int', but in modified so corner cases are treated as intersections */
static int isect_segments_i(const int v1[2], const int v2[2], const int v3[2], const int v4[2])
{