Add clipping text option to blenfont also add an enable/disable

function for aspect and rotation (and the new clipping).

Update source/Makefile to point to the new libed_sculpt_paint.
This commit is contained in:
Diego Borghetti 2009-02-20 05:42:44 +00:00
parent 72e99d9182
commit 8145489a7d
7 changed files with 114 additions and 24 deletions

View File

@ -242,7 +242,7 @@ PULIB += $(OCGDIR)/blender/ed_object/libed_object.a
PULIB += $(OCGDIR)/blender/ed_curve/libed_curve.a
PULIB += $(OCGDIR)/blender/ed_armature/libed_armature.a
PULIB += $(OCGDIR)/blender/ed_mesh/libed_mesh.a
PULIB += $(OCGDIR)/blender/ed_sculpt/libed_sculpt.a
PULIB += $(OCGDIR)/blender/ed_sculpt_paint/libed_sculpt_paint.a
PULIB += $(OCGDIR)/blender/ed_physics/libed_physics.a
PULIB += $(OCGDIR)/blender/ed_animation/libed_animation.a
PULIB += $(OCGDIR)/blender/ed_transform/libed_transform.a

View File

@ -45,6 +45,10 @@ void BLF_boundbox(char *str, rctf *box);
float BLF_width(char *str);
float BLF_height(char *str);
void BLF_rotation(float angle);
void BLF_clipping(float xmin, float ymin, float xmax, float ymax);
void BLF_enable(int option);
void BLF_disable(int option);
/* Read the .Blanguages file, return 1 on success or 0 if fails. */
int BLF_lang_init(void);
@ -78,4 +82,9 @@ char **BLF_dir_get(int *ndir);
/* Free the data return by BLF_dir_get. */
void BLF_dir_free(char **dirs, int count);
/* font->flags. */
#define BLF_ASPECT (1<<0)
#define BLF_ROTATION (1<<1)
#define BLF_CLIPPING (1<<2)
#endif /* BLF_API_H */

View File

@ -53,11 +53,11 @@
#include "BIF_gl.h"
#include "BIF_glutil.h"
#include "BLF_api.h"
#include "blf_internal_types.h"
#include "blf_internal.h"
#ifdef WITH_FREETYPE2
/* Max number of font in memory.
@ -215,6 +215,28 @@ void BLF_set(int fontid)
#endif
}
void BLF_enable(int option)
{
#ifdef WITH_FREETYPE2
FontBLF *font;
font= global_font[global_font_cur];
if (font)
font->flags |= option;
#endif
}
void BLF_disable(int option)
{
#ifdef WITH_FREETYPE2
FontBLF *font;
font= global_font[global_font_cur];
if (font)
font->flags &= ~option;
#endif
}
void BLF_aspect(float aspect)
{
#ifdef WITH_FREETYPE2
@ -230,24 +252,29 @@ void BLF_position(float x, float y, float z)
{
#ifdef WITH_FREETYPE2
FontBLF *font;
float remainder;
float remainder, aspect;
font= global_font[global_font_cur];
if (font) {
if (font->flags & BLF_ASPECT)
aspect= font->aspect;
else
aspect= 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 * aspect;
else
x += 0.1 * font->aspect;
x += 0.1 * aspect;
}
remainder= y - floor(y);
if (remainder > 0.4 && remainder < 0.6) {
if (remainder < 0.5)
y -= 0.1 * font->aspect;
y -= 0.1 * aspect;
else
y += 0.1 * font->aspect;
y += 0.1 * aspect;
}
font->pos[0]= x;
@ -281,8 +308,12 @@ void BLF_draw(char *str)
glPushMatrix();
glTranslatef(font->pos[0], font->pos[1], font->pos[2]);
glScalef(font->aspect, font->aspect, 1.0);
glRotatef(font->angle, 0.0f, 0.0f, 1.0f);
if (font->flags & BLF_ASPECT)
glScalef(font->aspect, font->aspect, 1.0);
if (font->flags & BLF_ROTATION)
glRotatef(font->angle, 0.0f, 0.0f, 1.0f);
blf_font_draw(font, str);
@ -338,3 +369,18 @@ void BLF_rotation(float angle)
font->angle= angle;
#endif
}
void BLF_clipping(float xmin, float ymin, float xmax, float ymax)
{
#ifdef WITH_FREETYPE2
FontBLF *font;
font= global_font[global_font_cur];
if (font) {
font->clip_rec.xmin= xmin;
font->clip_rec.ymin= ymin;
font->clip_rec.xmax= xmax;
font->clip_rec.ymax= ymax;
}
#endif
}

View File

@ -52,6 +52,7 @@
#include "BLI_arithb.h"
#include "BIF_gl.h"
#include "BLF_api.h"
#include "blf_internal_types.h"
#include "blf_internal.h"
@ -84,7 +85,7 @@ void blf_font_fill(FontBLF *font)
font->clip_rec.xmax= 0.0f;
font->clip_rec.ymin= 0.0f;
font->clip_rec.ymax= 0.0f;
font->clip_mode= BLF_CLIP_DISABLE;
font->flags= 0;
font->dpi= 0;
font->size= 0;
font->cache.first= NULL;
@ -209,7 +210,10 @@ void blf_font_draw(FontBLF *font, char *str)
pen_x += delta.x >> 6;
}
blf_glyph_render(g, (float)pen_x, (float)pen_y);
/* This only return zero if the clipping is enable and the glyph is out of the clip rctf. */
if (blf_glyph_render(font, g, (float)pen_x, (float)pen_y) == 0)
break;
pen_x += g->advance;
g_prev= g;
}
@ -287,18 +291,30 @@ void blf_font_boundbox(FontBLF *font, char *str, rctf *box)
float blf_font_width(FontBLF *font, char *str)
{
float aspect;
rctf box;
if (font->flags & BLF_ASPECT)
aspect= font->aspect;
else
aspect= 1.0f;
blf_font_boundbox(font, str, &box);
return((box.xmax - box.xmin) * font->aspect);
return((box.xmax - box.xmin) * aspect);
}
float blf_font_height(FontBLF *font, char *str)
{
float aspect;
rctf box;
if (font->flags & BLF_ASPECT)
aspect= font->aspect;
else
aspect= 1.0f;
blf_font_boundbox(font, str, &box);
return((box.ymax - box.ymin) * font->aspect);
return((box.ymax - box.ymin) * aspect);
}
void blf_font_free(FontBLF *font)

View File

@ -53,6 +53,7 @@
#include "BLI_string.h"
#include "BIF_gl.h"
#include "BLF_api.h"
#include "blf_internal_types.h"
#include "blf_internal.h"
@ -293,29 +294,47 @@ void blf_glyph_free(GlyphBLF *g)
MEM_freeN(g);
}
void blf_glyph_render(GlyphBLF *g, float x, float y)
int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
{
GLint cur_tex;
float dx;
float dx, dx1;
float y1, y2;
dx= floor(x + g->pos_x);
dx1= dx + g->width;
y1= y + g->pos_y;
y2= y + g->pos_y - g->height;
if (font->flags & BLF_CLIPPING) {
if (!BLI_in_rctf(&font->clip_rec, dx + font->pos[0], y1 + font->pos[1]))
return(0);
if (!BLI_in_rctf(&font->clip_rec, dx + font->pos[0], y2 + font->pos[1]))
return(0);
if (!BLI_in_rctf(&font->clip_rec, dx1 + font->pos[0], y2 + font->pos[1]))
return(0);
if (!BLI_in_rctf(&font->clip_rec, dx1 + font->pos[0], y1 + font->pos[1]))
return(0);
}
glGetIntegerv(GL_TEXTURE_2D_BINDING_EXT, &cur_tex);
if (cur_tex != g->tex)
glBindTexture(GL_TEXTURE_2D, g->tex);
dx= floor(x + g->pos_x);
glBegin(GL_QUADS);
glTexCoord2f(g->uv[0][0], g->uv[0][1]);
glVertex2f(dx, y + g->pos_y);
glVertex2f(dx, y1);
glTexCoord2f(g->uv[0][0], g->uv[1][1]);
glVertex2f(dx, y + g->pos_y - g->height);
glVertex2f(dx, y2);
glTexCoord2f(g->uv[1][0], g->uv[1][1]);
glVertex2f(dx + g->width, y + g->pos_y - g->height);
glVertex2f(dx1, y2);
glTexCoord2f(g->uv[1][0], g->uv[0][1]);
glVertex2f(dx + g->width, y + g->pos_y);
glVertex2f(dx1, y1);
glEnd();
return(1);
}
#endif /* WITH_FREETYPE2 */

View File

@ -58,7 +58,7 @@ GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, FT_UInt idx);
GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c);
void blf_glyph_free(GlyphBLF *g);
void blf_glyph_render(GlyphBLF *g, float x, float y);
int blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y);
#endif /* WITH_FREETYPE2 */
#endif /* BLF_INTERNAL_H */

View File

@ -151,9 +151,6 @@ typedef struct FontBLF {
/* clipping rectangle. */
rctf clip_rec;
/* and clipping mode. */
int clip_mode;
/* font dpi (default 72). */
int dpi;
@ -163,6 +160,9 @@ typedef struct FontBLF {
/* max texture size. */
int max_tex_size;
/* font options. */
int flags;
/* freetype2 face. */
FT_Face face;