Added experimental option to use GL textured interface fonts.

Set preferred method in userprefs->language & font.
Kinda requested by Kaito, i'm sure he regrets after seeing
my code changes.

This commit includes a patch provided by Jacques Baurain,
which seemed nescessary to handle font sizing properly.
Thank you !
This commit is contained in:
2005-01-19 13:53:43 +00:00
parent 731c69d6ed
commit 9fddd2bdec
16 changed files with 252 additions and 58 deletions

View File

@@ -148,6 +148,10 @@ FTF_EXPORT void FTF_SetLanguage(char* str);
*/
FTF_EXPORT void FTF_SetEncoding(char* str);
FTF_EXPORT void FTF_SetPosition(float x, float y);
FTF_EXPORT void FTF_SetMode(int mode);
FTF_EXPORT void FTF_SetScale(float fsize);
FTF_EXPORT void FTF_End(void);
#ifdef __cplusplus

View File

@@ -43,5 +43,7 @@
#define FTF_INPUT_SYSTEM_ENCODING FTF_BIT(1)
#define FTF_USE_GETTEXT FTF_BIT(2)
#define FTF_INPUT_UTF8 FTF_BIT(3)
#define FTF_PIXMAPFONT 0
#define FTF_TEXTUREFONT 1
#endif /* __FTF_SETTINGS_H */

View File

@@ -155,11 +155,22 @@ FTF_EXPORT void FTF_SetLanguage(char* str)
_FTF_GetFont()->SetLanguage(str);
}
/**
* added by phase
*
*/
FTF_EXPORT void FTF_SetEncoding(char* str)
{
_FTF_GetFont()->SetEncoding(str);
}
FTF_EXPORT void FTF_SetPosition(float x, float y)
{
_FTF_GetFont()->SetPosition(x, y);
}
FTF_EXPORT void FTF_SetMode(int mode)
{
_FTF_GetFont()->SetMode(mode);
}
FTF_EXPORT void FTF_SetScale(float fsize)
{
_FTF_GetFont()->SetScale(fsize);
}

View File

@@ -51,6 +51,7 @@
#define FTF_MAX_STR_SIZE 512
int utf8towchar(wchar_t *w, char *c)
{
int len=0;
@@ -102,6 +103,8 @@ FTF_TTFont::FTF_TTFont(void)
font=NULL;
fontm= fonts= fontl= NULL;
font_size=FONT_SIZE_DEFAULT;
mode = FTF_PIXMAPFONT;
fsize = 1.0;
strcpy(encoding_name, SYSTEM_ENCODING_DEFAULT);
//set messagepath directory
@@ -153,10 +156,13 @@ FTF_TTFont::~FTF_TTFont(void)
void FTF_TTFont::SetFontSize(char size)
{
if(mode == FTF_PIXMAPFONT) {
if(size=='s') font=fonts;
else if(size=='l') font=fontl;
else font=fontm;
} else if(mode == FTF_TEXTUREFONT) {
font=fontl;
}
}
int FTF_TTFont::SetFont(const unsigned char* str, int datasize, int fontsize)
@@ -171,6 +177,8 @@ int FTF_TTFont::SetFont(const unsigned char* str, int datasize, int fontsize)
fontm= NULL;
fontl= NULL;
if(mode == FTF_PIXMAPFONT) {
if(datasize) font = new FTGLPixmapFont(str, datasize);
else font = new FTGLPixmapFont( (char *)str);
@@ -200,6 +208,30 @@ int FTF_TTFont::SetFont(const unsigned char* str, int datasize, int fontsize)
return 1;
}
} else if(mode == FTF_TEXTUREFONT) {
if(datasize) font = new FTGLTextureFont(str, datasize);
else font = new FTGLTextureFont( (char *)str);
err = font->Error();
if(err) {
printf("Failed to open font %s\n", str);
return 0;
} else {
fontl= font;
success = fontl->FaceSize(fontsize);
if(!success) return 0;
success = fontl->CharMap(ft_encoding_unicode);
if(!success) return 0;
return 1;
}
}
}
void FTF_TTFont::SetLanguage(char* str)
@@ -242,9 +274,13 @@ void FTF_TTFont::SetEncoding(char* str)
void FTF_TTFont::SetSize(int size)
{
if(mode == FTF_PIXMAPFONT) {
fonts->FaceSize(size-2<8?8:size-2);
fontm->FaceSize(size-1<8?8:size-1);
fontl->FaceSize(size);
} else if(mode == FTF_TEXTUREFONT) {
fontl->FaceSize(size);
}
font_size = size;
}
@@ -284,6 +320,8 @@ float FTF_TTFont::DrawString(char* str, unsigned int flag)
glGetFloatv(GL_CURRENT_COLOR, color);
if(mode == FTF_PIXMAPFONT) {
glPixelTransferf(GL_RED_SCALE, color[0]);
glPixelTransferf(GL_GREEN_SCALE, color[1]);
glPixelTransferf(GL_BLUE_SCALE, color[2]);
@@ -294,6 +332,22 @@ float FTF_TTFont::DrawString(char* str, unsigned int flag)
glPixelTransferf(GL_GREEN_SCALE, 1.0);
glPixelTransferf(GL_BLUE_SCALE, 1.0);
} else if(mode == FTF_TEXTUREFONT) {
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glPushMatrix();
glTranslatef(pen_x, pen_y, 0.0);
glScalef(fsize, fsize, 1.0);
font->Render(wstr);
glPopMatrix();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
}
return font->Advance(wstr);
}
@@ -308,7 +362,11 @@ float FTF_TTFont::GetStringWidth(char* str, unsigned int flag)
else
len=utf8towchar(wstr,str);
if(mode == FTF_PIXMAPFONT) {
return font->Advance(wstr);
} else if(mode == FTF_TEXTUREFONT) {
return font->Advance(wstr) * fsize;
}
}
@@ -324,3 +382,24 @@ void FTF_TTFont::GetBoundingBox(char* str, float *llx, float *lly, float *llz, f
font->BBox(wstr, *llx, *lly, *llz, *urx, *ury, *urz);
}
void FTF_TTFont::SetPosition(float x, float y)
{
pen_x = x;
pen_y = y;
}
void FTF_TTFont::SetMode(int m)
{
mode = m;
}
void FTF_TTFont::SetScale(float size)
{
fsize = size;
}

View File

@@ -38,6 +38,7 @@
#define __FTF_TRUETYPE_FONT_H
#include "FTGLPixmapFont.h"
#include "FTGLTextureFont.h"
#include <stdio.h>
//#include <iconv.h>
@@ -91,6 +92,13 @@ public:
void SetEncoding(char* str);
/**
* functions to communicate with blender ui rasterpos
*/
void SetPosition(float x, float y);
void SetMode(int mode);
void SetScale(float fsize);
protected:
char messagepath[1024];
@@ -99,6 +107,10 @@ protected:
char font_name[128];
int font_size;
int mode; // 0 = pixmap, 1 = texture
float pen_x, pen_y; //rasterpos
float fsize;
/** FTGL's */
FTFont* font; /* active */

View File

@@ -48,5 +48,8 @@ char *fontsize_pup(void);
int BIF_DrawString(struct BMF_Font* font, char *str, int translate);
float BIF_GetStringWidth(struct BMF_Font* font, char *str, int translate);
void BIF_RasterPos(float x, float y);
void refresh_interface_font(void);
#endif /* BIF_LANGUAGE_H */

View File

@@ -257,6 +257,8 @@
#define B_SETTRANSBUTS 315
#define B_DOLANGUIFONT 316
#define B_RESTOREFONT 317
#define B_USETEXTUREFONT 318
#define B_SCALETEXTUREFONT 319
#define B_UITHEMECHANGED 320
#define B_UITHEMECOLORMOD 321

View File

@@ -204,6 +204,7 @@ extern UserDef U; /* from usiblender.c !!!! */
#define USER_TR_FILESELECT 8
#define USER_TR_TEXTEDIT 16
#define USER_DOTRANSLATE 32
#define USER_USETEXTUREFONT 64
/* dupflag */

View File

@@ -898,6 +898,7 @@ static void do_info_filemenu(void *arg, int event)
BKE_reset_undo();
BKE_write_undo("original"); /* save current state */
refresh_interface_font();
}
break;
case 31: /* save default settings */
@@ -1820,11 +1821,13 @@ static void info_text(int x, int y)
glColor3ub(0, 0, 0);
glRasterPos2i(x, y);
BIF_RasterPos(x, y);
BIF_DrawString(G.font, headerstr, (U.transopts & USER_TR_MENUS));
hsize= BIF_GetStringWidth(G.font, headerstr, (U.transopts & USER_TR_BUTTONS));
glRasterPos2i(x+hsize+10, y);
BIF_RasterPos(x+hsize+10, y);
BIF_DrawString(G.font, infostr, (U.transopts & USER_TR_MENUS));
}

View File

@@ -1575,6 +1575,7 @@ void do_global_buttons(unsigned short event)
break;
case B_SETFONTSIZE: /* is button from space.c *info* */
refresh_interface_font();
FTF_SetSize(U.fontsize);
allqueue(REDRAWALL, 0);
break;
@@ -1584,9 +1585,35 @@ void do_global_buttons(unsigned short event)
break;
case B_RESTOREFONT: /* is button from space.c *info* */
{
extern float lang_texsize;
lang_texsize = 1.0;
FTF_SetScale(lang_texsize);
U.fontsize= 0;
start_interface_font();
allqueue(REDRAWALL, 0);
}
break;
case B_USETEXTUREFONT: /* is button from space.c *info* */
if(U.transopts & USER_USETEXTUREFONT)
FTF_SetMode(FTF_TEXTUREFONT);
else
FTF_SetMode(FTF_PIXMAPFONT);
refresh_interface_font();
allqueue(REDRAWALL, 0);
break;
case B_SCALETEXTUREFONT: /* is button from space.c *info* */
{
extern float lang_texsize;
FTF_SetScale(lang_texsize);
allqueue(REDRAWALL, 0);
}
break;
case B_DOLANGUIFONT: /* is button from space.c *info* */

View File

@@ -3454,6 +3454,8 @@ static uiOverDraw *ui_draw_but_tip(uiBut *but)
#ifdef INTERNATIONAL
extern float lang_texsize;
if(G.ui_international == TRUE) {
float llx,lly,llz,urx,ury,urz; //for FTF_GetBoundingBox()
@@ -3462,11 +3464,15 @@ static uiOverDraw *ui_draw_but_tip(uiBut *but)
x1= (but->x1+but->x2)/2; x2= 10+x1+ but->aspect*FTF_GetStringWidth(but->tip, FTF_USE_GETTEXT | FTF_INPUT_UTF8); //BMF_GetStringWidth(but->font, but->tip);
y1= but->y1-(ury+FTF_GetSize())-12; y2= but->y1-12;
y1 *= lang_texsize;
y2 *= lang_texsize;
} else {
FTF_GetBoundingBox(but->tip, &llx,&lly,&llz,&urx,&ury,&urz, FTF_NO_TRANSCONV | FTF_INPUT_UTF8);
x1= (but->x1+but->x2)/2; x2= 10+x1+ but->aspect*FTF_GetStringWidth(but->tip, FTF_NO_TRANSCONV | FTF_INPUT_UTF8); //BMF_GetStringWidth(but->font, but->tip);
y1= but->y1-(ury+FTF_GetSize())-12; y2= but->y1-12;
y1 *= lang_texsize;
y2 *= lang_texsize;
}
} else {
x1= (but->x1+but->x2)/2; x2= 10+x1+ but->aspect*BMF_GetStringWidth(but->font, but->tip);

View File

@@ -115,6 +115,8 @@ void ui_rasterpos_safe(float x, float y, float aspect)
}
if(doit) glRasterPos2f(x, y);
BIF_RasterPos(x, y);
}
/* ************** generic embossed rect, for window sliders etc ************* */

View File

@@ -28,6 +28,10 @@
*/
#ifdef WIN32
#include "BLI_winstuff.h"
#endif
#include <string.h>
#include <stdlib.h>
@@ -40,6 +44,7 @@
#include "BLI_blenlib.h"
#include "BLI_linklist.h" /* linknode */
#include "BIF_gl.h"
#include "BIF_language.h"
#include "BIF_space.h" /* allqueue() */
#include "BIF_toolbox.h" /* error() */
@@ -66,20 +71,51 @@ struct _LANGMenuEntry {
static LANGMenuEntry *langmenu= 0;
static int tot_lang = 0;
float lang_texsize = 1.0;
#endif // INTERNATIONAL
void BIF_RasterPos(float x, float y)
{
#ifdef INTERNATIONAL
FTF_SetPosition(x, y);
#endif // INTERNATIONAL
}
void refresh_interface_font(void)
{
#ifdef INTERNATIONAL
if(U.transopts & USER_DOTRANSLATE)
start_interface_font();
else
G.ui_international = FALSE;
#else // INTERNATIONAL
G.ui_international = FALSE;
#endif
}
int BIF_DrawString(BMF_Font* font, char *str, int translate)
{
#ifdef INTERNATIONAL
if(G.ui_international == TRUE)
if(G.ui_international == TRUE) {
if(translate)
return FTF_DrawString(str, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
else
return FTF_DrawString(str, FTF_NO_TRANSCONV | FTF_INPUT_UTF8);
else
} else {
return BMF_DrawString(font, str);
/*
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
BMF_GetFontTexture(font);??
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
BMF_DrawStringTexture(font, str, pen_x, pen_y, 0.0);
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
return 0;
*/
}
#else
return BMF_DrawString(font, str);
#endif

View File

@@ -1992,6 +1992,7 @@ static void outliner_draw_tree_element(SpaceOops *soops, TreeElement *te, int st
if(active==1) BIF_ThemeColor(TH_TEXT_HI);
else BIF_ThemeColor(TH_TEXT);
glRasterPos2i(startx+offsx, *starty+5);
BIF_RasterPos(startx+offsx, *starty+5);
BIF_DrawString(G.font, te->name, 0);
offsx+= OL_X + BIF_GetStringWidth(G.font, te->name, 0);

View File

@@ -2538,12 +2538,19 @@ void drawinfospace(ScrArea *sa, void *spacedata)
(xpos+edgsp+(2.2*mpref)+(3*midsp)),y2,mpref+(0.5*mpref)+3,buth,
&U.language, 0, 0, 0, 0, "Select interface language");
/* uiDefButBitS(block, TOG, USER_TR_TEXTEDIT, B_SETTRANSBUTS, "FTF All windows",
(xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
uiDefButBitS(block, TOG, USER_USETEXTUREFONT, B_USETEXTUREFONT, "Use Textured Fonts",
(xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,
&(U.transopts), 0, 0, 0, 0,
"Use FTF drawing for fileselect and textwindow "
"(under construction)");
*/
"Use Textured Fonts");
if(U.transopts & USER_USETEXTUREFONT) {
extern float lang_texsize;
uiDefButF(block, NUM, B_SCALETEXTUREFONT, "Scale Factor",
(xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
&lang_texsize, 0.2, 2.0, 100, 2, "Tweak scaling for textured font");
}
}
/* end of INTERNATIONAL */

View File

@@ -215,10 +215,7 @@ static void init_userdef_file(void)
#ifdef INTERNATIONAL
read_languagefile();
if(U.transopts & USER_DOTRANSLATE)
start_interface_font();
else
G.ui_international = FALSE;
refresh_interface_font();
#endif // INTERNATIONAL
}
@@ -248,6 +245,7 @@ void BIF_read_file(char *name)
undo_editmode_clear();
BKE_reset_undo();
BKE_write_undo("original"); /* save current state */
refresh_interface_font();
}
else BIF_undo_push("Import file");
}