[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21108] branches/blender2.5/blender/source /blender: Move shadow option (for text) from editor/interface to blenfont.
Diego Borghetti
bdiego at gmail.com
Tue Jun 23 18:27:35 CEST 2009
Revision: 21108
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21108
Author: bdiego
Date: 2009-06-23 18:27:35 +0200 (Tue, 23 Jun 2009)
Log Message:
-----------
Move shadow option (for text) from editor/interface to blenfont.
Two new function:
BLF_shadow: set the level (for blur) and the shadow color.
BLF_shadow_offset: set the x and y offset for shadow.
(this is the current position plus offset)
By default shadow is not enable in the font, so before draw the
text you need call BLF_enable(BLF_SHADOW), also remember disable
the option in the end.
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/blenfont/BLF_api.h
branches/blender2.5/blender/source/blender/blenfont/intern/blf.c
branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c
branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h
branches/blender2.5/blender/source/blender/editors/interface/interface_style.c
Modified: branches/blender2.5/blender/source/blender/blenfont/BLF_api.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/BLF_api.h 2009-06-23 13:34:45 UTC (rev 21107)
+++ branches/blender2.5/blender/source/blender/blenfont/BLF_api.h 2009-06-23 16:27:35 UTC (rev 21108)
@@ -91,6 +91,21 @@
void BLF_disable(int option);
/*
+ * Shadow options, level is the blur level, can be 3, 5 or 0 and
+ * the other argument are the rgba color.
+ * Take care that shadow need to be enable using BLF_enable!!.
+ */
+void BLF_shadow(int level, float r, float g, float b, float a);
+
+/*
+ * Set the offset for shadow text, this is the current cursor
+ * position plus this offset, don't need call BLF_position before
+ * this function, the current position is calculate only on
+ * BLF_draw, so it's safe call this whenever you like.
+ */
+void BLF_shadow_offset(int x, int y);
+
+/*
* Search the path directory to the locale files, this try all
* the case for Linux, Win and Mac.
*/
@@ -119,6 +134,7 @@
#define BLF_CLIPPING (1<<1)
#define BLF_FONT_KERNING (1<<2)
#define BLF_USER_KERNING (1<<3)
+#define BLF_SHADOW (1<<4)
/* font->mode. */
#define BLF_MODE_TEXTURE 0
Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf.c 2009-06-23 13:34:45 UTC (rev 21107)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf.c 2009-06-23 16:27:35 UTC (rev 21108)
@@ -500,3 +500,28 @@
if (font)
font->kerning= space;
}
+
+void BLF_shadow(int level, float r, float g, float b, float a)
+{
+ FontBLF *font;
+
+ font= global_font[global_font_cur];
+ if (font) {
+ font->shadow= level;
+ font->shadow_col[0]= r;
+ font->shadow_col[1]= g;
+ font->shadow_col[2]= b;
+ font->shadow_col[3]= a;
+ }
+}
+
+void BLF_shadow_offset(int x, int y)
+{
+ FontBLF *font;
+
+ font= global_font[global_font_cur];
+ if (font) {
+ font->shadow_x= x;
+ font->shadow_y= y;
+ }
+}
Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c 2009-06-23 13:34:45 UTC (rev 21107)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_glyph.c 2009-06-23 16:27:35 UTC (rev 21108)
@@ -496,8 +496,18 @@
GLint cur_tex;
float dx, dx1;
float y1, y2;
+ float xo, yo;
+ float color[4];
gt= g->tex_data;
+
+ if (font->flags & BLF_SHADOW) {
+ xo= x;
+ yo= y;
+ x += font->shadow_x;
+ y += font->shadow_y;
+ }
+
dx= floor(x + gt->pos_x);
dx1= dx + gt->width;
y1= y + gt->pos_y;
@@ -518,6 +528,27 @@
if (cur_tex != gt->tex)
glBindTexture(GL_TEXTURE_2D, gt->tex);
+ if (font->flags & BLF_SHADOW) {
+ glGetFloatv(GL_CURRENT_COLOR, color);
+ glColor4fv(font->shadow_col);
+
+ if (font->shadow == 3)
+ blf_texture3_draw(gt->uv, dx, y1, dx1, y2);
+ else if (font->shadow == 5)
+ blf_texture5_draw(gt->uv, dx, y1, dx1, y2);
+ else
+ blf_texture_draw(gt->uv, dx, y1, dx1, y2);
+
+ glColor4fv(color);
+ x= xo;
+ y= yo;
+
+ dx= floor(x + gt->pos_x);
+ dx1= dx + gt->width;
+ y1= y + gt->pos_y;
+ y2= y + gt->pos_y - gt->height;
+ }
+
if (font->blur==3)
blf_texture3_draw(gt->uv, dx, y1, dx1, y2);
else if (font->blur==5)
Modified: branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h 2009-06-23 13:34:45 UTC (rev 21107)
+++ branches/blender2.5/blender/source/blender/blenfont/intern/blf_internal_types.h 2009-06-23 16:27:35 UTC (rev 21108)
@@ -154,6 +154,16 @@
/* blur: 3 or 5 large kernel */
int blur;
+
+ /* shadow level. */
+ int shadow;
+
+ /* and shadow offset. */
+ int shadow_x;
+ int shadow_y;
+
+ /* shadow color. */
+ float shadow_col[4];
/* this is the matrix that we load before rotate/scale/translate. */
float mat[4][4];
Modified: branches/blender2.5/blender/source/blender/editors/interface/interface_style.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/interface_style.c 2009-06-23 13:34:45 UTC (rev 21107)
+++ branches/blender2.5/blender/source/blender/editors/interface/interface_style.c 2009-06-23 16:27:35 UTC (rev 21108)
@@ -145,22 +145,6 @@
/* *************** draw ************************ */
-static void ui_font_shadow_draw(uiFontStyle *fs, int x, int y, char *str)
-{
- float color[4];
-
- glGetFloatv(GL_CURRENT_COLOR, color);
-
- glColor4f(fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha);
-
- BLF_blur(fs->shadow);
- BLF_position(x+fs->shadx, y+fs->shady, 0.0f);
- BLF_draw(str);
- BLF_blur(0);
-
- glColor4fv(color);
-}
-
void uiStyleFontDraw(uiFontStyle *fs, rcti *rect, char *str)
{
float height;
@@ -179,14 +163,18 @@
/* clip is very strict, so we give it some space */
BLF_clipping(rect->xmin-1, rect->ymin-4, rect->xmax+1, rect->ymax+4);
BLF_enable(BLF_CLIPPING);
-
- if(fs->shadow)
- ui_font_shadow_draw(fs, rect->xmin+xofs, rect->ymin+yofs, str);
-
BLF_position(rect->xmin+xofs, rect->ymin+yofs, 0.0f);
- BLF_draw(str);
+ if (fs->shadow) {
+ BLF_enable(BLF_SHADOW);
+ BLF_shadow(fs->shadow, fs->shadowcolor, fs->shadowcolor, fs->shadowcolor, fs->shadowalpha);
+ BLF_shadow_offset(fs->shadx, fs->shady);
+ }
+
+ BLF_draw(str);
BLF_disable(BLF_CLIPPING);
+ if (fs->shadow)
+ BLF_disable(BLF_SHADOW);
}
/* ************** helpers ************************ */
More information about the Bf-blender-cvs
mailing list