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:
authorDiego Borghetti <bdiego@gmail.com>2010-12-10 01:27:55 +0300
committerDiego Borghetti <bdiego@gmail.com>2010-12-10 01:27:55 +0300
commit545cc4803e8e9e7418aba98b2c1bec72fa629146 (patch)
tree3b3fb952f7ef2b6926bb3d990574c5f7f6a603e7 /source/blender
parent3ee53d7b5f8e4371607467cff69c3f35662abdc4 (diff)
Change the BLF_aspect function to handle 3d text.
This is need to properly handle 3d text (dalai work on GE), before the BLF_aspect only take one argument, and the result was a call to: glScalef(aspect, aspect, 1.0) Now the three value are store in the font (x, y and z) and also need to be enable using BLF_enable(BLF_ASPECT). By default all the code that don't have BLF_ASPECT enable work with a scale of 1.0 (so nothing change to the current UI). I also remove all the call of BLF_aspect(fontid, 1.0) found in the editors, because is disable by default, so no need any more. Campbell the only thing to check is the python api, right now I modify the api to from: BLF_aspect(fontid, aspect) to: BLF_aspect(fontid, aspect, aspect, 1.0) This is to avoid break the api, but now you need add the BLF_ASPECT option to the function py_blf_enable and in some point change py_blf_aspect to take 3 arguments.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenfont/BLF_api.h3
-rw-r--r--source/blender/blenfont/intern/blf.c44
-rw-r--r--source/blender/blenfont/intern/blf_font.c34
-rw-r--r--source/blender/blenfont/intern/blf_internal_types.h2
-rw-r--r--source/blender/blenkernel/intern/image.c1
-rw-r--r--source/blender/blenkernel/intern/image_gen.c1
-rw-r--r--source/blender/editors/interface/interface_style.c2
-rw-r--r--source/blender/editors/space_image/image_draw.c1
-rw-r--r--source/blender/editors/space_info/textview.c1
-rw-r--r--source/blender/editors/space_text/text_draw.c1
-rw-r--r--source/blender/python/generic/blf_py_api.c2
11 files changed, 68 insertions, 24 deletions
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h
index 84086742b15..b696c64023d 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -45,7 +45,7 @@ int BLF_load_mem_unique(const char *name, unsigned char *mem, int mem_size);
/* Attach a file with metrics information from memory. */
void BLF_metrics_attach(int fontid, unsigned char *mem, int mem_size);
-void BLF_aspect(int fontid, float aspect);
+void BLF_aspect(int fontid, float x, float y, float z);
void BLF_position(int fontid, float x, float y, float z);
void BLF_size(int fontid, int size, int dpi);
@@ -195,6 +195,7 @@ void BLF_dir_free(char **dirs, int count);
#define BLF_SHADOW (1<<2)
#define BLF_KERNING_DEFAULT (1<<3)
#define BLF_MATRIX (1<<4)
+#define BLF_ASPECT (1<<5)
// XXX, bad design
extern int blf_mono_font;
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index d9a02b09336..3ac0b8449b0 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -321,13 +321,16 @@ void BLF_disable_default(int option)
font->flags &= ~option;
}
-void BLF_aspect(int fontid, float aspect)
+void BLF_aspect(int fontid, float x, float y, float z)
{
FontBLF *font;
font= BLF_get(fontid);
- if (font)
- font->aspect= aspect;
+ if (font) {
+ font->aspect[0]= x;
+ font->aspect[1]= y;
+ font->aspect[2]= z;
+ }
}
void BLF_matrix(int fontid, double *m)
@@ -346,23 +349,43 @@ void BLF_position(int fontid, float x, float y, float z)
{
FontBLF *font;
float remainder;
+ float xa, ya, za;
font= BLF_get(fontid);
if (font) {
+ if (font->flags & BLF_ASPECT) {
+ xa= font->aspect[0];
+ ya= font->aspect[1];
+ za= font->aspect[2];
+ }
+ else {
+ xa= 1.0f;
+ ya= 1.0f;
+ za= 1.0f;
+ }
+
remainder= x - floor(x);
if (remainder > 0.4 && remainder < 0.6) {
if (remainder < 0.5)
- x -= 0.1 * font->aspect;
+ x -= 0.1 * xa;
else
- x += 0.1 * font->aspect;
+ x += 0.1 * xa;
}
remainder= y - floor(y);
if (remainder > 0.4 && remainder < 0.6) {
if (remainder < 0.5)
- y -= 0.1 * font->aspect;
+ y -= 0.1 * ya;
else
- y += 0.1 * font->aspect;
+ y += 0.1 * ya;
+ }
+
+ remainder= z - floor(z);
+ if (remainder > 0.4 && remainder < 0.6) {
+ if (remainder < 0.5)
+ z -= 0.1 * za;
+ else
+ z += 0.1 * za;
}
font->pos[0]= x;
@@ -406,6 +429,7 @@ void BLF_draw_default(float x, float y, float z, const char *str, size_t len)
BLF_position(global_font_default, x, y, z);
BLF_draw(global_font_default, str, len);
}
+
/* same as above but call 'BLF_draw_ascii' */
void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t len)
{
@@ -434,7 +458,6 @@ void BLF_rotation_default(float angle)
font->angle= angle;
}
-
static void blf_draw__start(FontBLF *font)
{
/*
@@ -452,11 +475,14 @@ static void blf_draw__start(FontBLF *font)
glMultMatrixd((GLdouble *)&font->m);
glTranslatef(font->pos[0], font->pos[1], font->pos[2]);
- glScalef(font->aspect, font->aspect, 1.0);
+
+ if (font->flags & BLF_ASPECT)
+ glScalef(font->aspect[0], font->aspect[1], font->aspect[2]);
if (font->flags & BLF_ROTATION)
glRotatef(font->angle, 0.0f, 0.0f, 1.0f);
}
+
static void blf_draw__end(void)
{
glPopMatrix();
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index 3adda7bb6f1..d1dcf7aa9b3 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -420,35 +420,57 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box)
void blf_font_width_and_height(FontBLF *font, const char *str, float *width, float *height)
{
+ float xa, ya;
rctf box;
if (font->glyph_cache) {
+ if (font->flags & BLF_ASPECT) {
+ xa= font->aspect[0];
+ ya= font->aspect[1];
+ }
+ else {
+ xa= 1.0f;
+ ya= 1.0f;
+ }
+
blf_font_boundbox(font, str, &box);
- *width= ((box.xmax - box.xmin) * font->aspect);
- *height= ((box.ymax - box.ymin) * font->aspect);
+ *width= ((box.xmax - box.xmin) * xa);
+ *height= ((box.ymax - box.ymin) * ya);
}
}
float blf_font_width(FontBLF *font, const char *str)
{
+ float xa;
rctf box;
if (!font->glyph_cache)
return(0.0f);
+ if (font->flags & BLF_ASPECT)
+ xa= font->aspect[0];
+ else
+ xa= 1.0f;
+
blf_font_boundbox(font, str, &box);
- return((box.xmax - box.xmin) * font->aspect);
+ return((box.xmax - box.xmin) * xa);
}
float blf_font_height(FontBLF *font, const char *str)
{
+ float ya;
rctf box;
if (!font->glyph_cache)
return(0.0f);
+ if (font->flags & BLF_ASPECT)
+ ya= font->aspect[1];
+ else
+ ya= 1.0f;
+
blf_font_boundbox(font, str, &box);
- return((box.ymax - box.ymin) * font->aspect);
+ return((box.ymax - box.ymin) * ya);
}
float blf_font_fixed_width(FontBLF *font)
@@ -495,7 +517,9 @@ static void blf_font_fill(FontBLF *font)
{
int i;
- font->aspect= 1.0f;
+ font->aspect[0]= 1.0f;
+ font->aspect[1]= 1.0f;
+ font->aspect[2]= 1.0f;
font->pos[0]= 0.0f;
font->pos[1]= 0.0f;
font->angle= 0.0f;
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index 04afaeb2e97..d7c023fc415 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -133,7 +133,7 @@ typedef struct FontBLF {
char *filename;
/* aspect ratio or scale. */
- float aspect;
+ float aspect[3];
/* initial position for draw the text. */
float pos[3];
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 6cd0c89157a..efa8a824663 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -1009,7 +1009,6 @@ void BKE_stamp_buf(Scene *scene, unsigned char *rect, float *rectf, int width, i
scene->r.stamp_font_id= 12;
/* set before return */
- BLF_aspect(mono, 1.0);
BLF_size(mono, scene->r.stamp_font_id, 72);
BLF_buffer(mono, rectf, rect, width, height, channels);
diff --git a/source/blender/blenkernel/intern/image_gen.c b/source/blender/blenkernel/intern/image_gen.c
index b765cf29a3d..a2d41920217 100644
--- a/source/blender/blenkernel/intern/image_gen.c
+++ b/source/blender/blenkernel/intern/image_gen.c
@@ -306,7 +306,6 @@ static void checker_board_text(unsigned char *rect, float *rect_float, int width
char text[3]= {'A', '1', '\0'};
const int mono= blf_mono_font;
- BLF_aspect(mono, 1.0);
BLF_size(mono, 54, 72); /* hard coded size! */
BLF_buffer(mono, rect_float, rect, width, height, 4);
diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c
index 51a54315d66..ec9ac300ca2 100644
--- a/source/blender/editors/interface/interface_style.c
+++ b/source/blender/editors/interface/interface_style.c
@@ -319,14 +319,12 @@ void uiStyleInit(void)
if (blf_mono_font == -1)
blf_mono_font= BLF_load_mem_unique("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
- BLF_aspect(blf_mono_font, 1.0);
BLF_size(blf_mono_font, 12, 72);
/* second for rendering else we get threading problems */
if (blf_mono_font_render == -1)
blf_mono_font_render= BLF_load_mem_unique("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
- BLF_aspect(blf_mono_font_render, 1.0);
BLF_size(blf_mono_font_render, 12, 72);
}
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c
index b781544c05b..55f27cbca62 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -157,7 +157,6 @@ void draw_image_info(ARegion *ar, int channels, int x, int y, char *cp, float *f
glColor3ub(255, 255, 255);
// UI_DrawString(6, 6, str); // works ok but fixed width is nicer.
- BLF_aspect(blf_mono_font, 1.0);
BLF_size(blf_mono_font, 11, 72);
BLF_position(blf_mono_font, 6, 6, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
diff --git a/source/blender/editors/space_info/textview.c b/source/blender/editors/space_info/textview.c
index 53751884bec..a8452731d68 100644
--- a/source/blender/editors/space_info/textview.c
+++ b/source/blender/editors/space_info/textview.c
@@ -41,7 +41,6 @@
static void console_font_begin(TextViewContext *sc)
{
- BLF_aspect(blf_mono_font, 1.0);
BLF_size(blf_mono_font, sc->lheight-2, 72);
}
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c
index c5037d1226f..93581056c98 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -61,7 +61,6 @@
static void text_font_begin(SpaceText *st)
{
- BLF_aspect(mono, 1.0);
BLF_size(mono, st->lheight, 72);
}
diff --git a/source/blender/python/generic/blf_py_api.c b/source/blender/python/generic/blf_py_api.c
index 8821aa6d6e7..bd8512ff2d7 100644
--- a/source/blender/python/generic/blf_py_api.c
+++ b/source/blender/python/generic/blf_py_api.c
@@ -99,7 +99,7 @@ static PyObject *py_blf_aspect(PyObject *UNUSED(self), PyObject *args)
if (!PyArg_ParseTuple(args, "if:blf.aspect", &fontid, &aspect))
return NULL;
- BLF_aspect(fontid, aspect);
+ BLF_aspect(fontid, aspect, aspect, 1.0);
Py_RETURN_NONE;
}