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.
This commit is contained in:
parent
3ee53d7b5f
commit
545cc4803e
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,6 @@
|
|||
|
||||
static void text_font_begin(SpaceText *st)
|
||||
{
|
||||
BLF_aspect(mono, 1.0);
|
||||
BLF_size(mono, st->lheight, 72);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue