Skip to content

Commit

Permalink
Added: InFine command "font" (handle) (font) specify the font to use …
Browse files Browse the repository at this point in the history
…by name.

Changed: InFine command "linehgt" - line height is now interpreted as a percentage of the actual height of font rather than a fixed 320x200 pixel offset.
  • Loading branch information
danij-deng committed May 31, 2010
1 parent d01154c commit be3b366
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 52 deletions.
3 changes: 2 additions & 1 deletion doomsday/engine/api/dd_compositefont.h
Expand Up @@ -38,7 +38,8 @@ typedef struct fontpatch_s {
char lumpName[9];
} fontpatch_t;

void R_NewCompositeFont(compositefontid_t fontid, const char name[9], const fontpatch_t* patches, size_t num);
void R_NewCompositeFont(compositefontid_t fontid, const char* name, const fontpatch_t* patches, size_t num);
compositefontid_t R_CompositeFontNumForName(const char* name);
void R_ResetTextTypeInTimer(void);

/**
Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/api/doomsday.def
Expand Up @@ -17,7 +17,6 @@ NAME "DOOMSDAY"
; 98 formerly R_TextureNameForNum
; 99 formerly R_MaterialSetTranslation
; 100 formerly R_SetTextureTranslation
; 131 formerly GL_DrawPSprite
; 144 formerly M_FRandom
; 238 formerly GL_Color2
; 255 formerly P_PointToBlock
Expand Down Expand Up @@ -398,10 +397,11 @@ EXPORTS
GL_SetFilterColor @441 NONAME

; Graphics: Text
R_NewCompositeFont @106 NONAME
R_ResetTextTypeInTimer @107 NONAME
R_NewCompositeFont @106 NONAME
R_ResetTextTypeInTimer @107 NONAME
R_CompositeFontNumForName @131 NONAME

GL_DrawText @108 NONAME
GL_DrawText @108 NONAME

GL_TextDimensions @112 NONAME
GL_TextWidth @113 NONAME
Expand Down
10 changes: 9 additions & 1 deletion doomsday/engine/portable/src/gl_drawcompositefont.c
Expand Up @@ -414,7 +414,7 @@ void R_SetCompositeFontChar(compositefontid_t fontId, unsigned char ch, const ch
Con_Message("R_SetCompositeFontChar: Warning, unknown font id %i.\n", (int) fontId);
}

void R_NewCompositeFont(compositefontid_t fontId, const char name[9], const fontpatch_t* patches, size_t num)
void R_NewCompositeFont(compositefontid_t fontId, const char* name, const fontpatch_t* patches, size_t num)
{
compositefont_t* font;
size_t i, len;
Expand Down Expand Up @@ -474,6 +474,14 @@ void R_NewCompositeFont(compositefontid_t fontId, const char name[9], const font
prepareCompositeFont(font);
}

compositefontid_t R_CompositeFontNumForName(const char* name)
{
compositefont_t* font;
if((font = fontForName(name)))
return font->id;
return 0;
}

void R_InitCompositeFonts(void)
{
if(inited)
Expand Down
88 changes: 42 additions & 46 deletions doomsday/plugins/common/src/f_infine.c
Expand Up @@ -40,8 +40,6 @@
# include "jheretic.h"
#elif __JHEXEN__
# include "jhexen.h"
#elif __JSTRIFE__
# include "jstrife.h"
#endif

#include "hu_log.h"
Expand Down Expand Up @@ -116,13 +114,13 @@ typedef struct fitext_s {
fiobj_t object;
struct fitextflags_s {
char centered:1;
char font_b:1;
char all_visible:1;
} flags;
int scrollWait, scrollTimer; // Automatic scrolling upwards.
int pos;
int wait, timer;
int lineheight;
float lineheight;
compositefontid_t font;
char* text;
} fitext_t;

Expand Down Expand Up @@ -231,6 +229,7 @@ void FIC_TextFromLump(void);
void FIC_SetText(void);
void FIC_SetTextDef(void);
void FIC_DeleteText(void);
void FIC_Font(void);
void FIC_FontA(void);
void FIC_FontB(void);
void FIC_TextColor(void);
Expand Down Expand Up @@ -353,6 +352,7 @@ static ficmd_t fiCommands[] = {
{"scroll", 2, FIC_TextScroll}, // scroll (handle) (speed)
{"pos", 2, FIC_TextPos}, // pos (handle) (pos)
{"rate", 2, FIC_TextRate}, // rate (handle) (rate)
{"font", 2, FIC_Font}, // font (handle) (font)
{"fonta", 1, FIC_FontA}, // fonta (handle)
{"fontb", 1, FIC_FontB}, // fontb (handle)
{"linehgt", 2, FIC_TextLineHeight}, // linehgt (hndl) (hgt)
Expand Down Expand Up @@ -1169,8 +1169,10 @@ fipic_t* FI_GetPic(const char* handle)

fitext_t* FI_GetText(char* handle)
{
int i;
fitext_t* unused = NULL;
#define LEADING (1.5f)

fitext_t* unused = NULL;
int i;

for(i = 0; i < MAX_TEXT; ++i)
{
Expand Down Expand Up @@ -1199,20 +1201,18 @@ fitext_t* FI_GetText(char* handle)
strncpy(unused->object.handle, handle, sizeof(unused->object.handle) - 1);
unused->object.used = true;
unused->wait = 3;
#if __JDOOM__
unused->lineheight = 11;
FI_InitValue(&unused->object.color[0], 1); // Red text by default.
#else
unused->lineheight = 9;
// White text.
unused->font = GF_FONTA;
unused->lineheight = LEADING;
// Red text by default.
for(i = 0; i < 3; ++i)
FI_InitValue(&unused->object.color[i], 1);
#endif
FI_InitValue(&unused->object.color[3], 1); // Opaque.
FI_InitValue(&unused->object.color[i], defFontRGB2[i]);
FI_InitValue(&unused->object.color[CA], 1); // Opaque.
for(i = 0; i < 2; ++i)
FI_InitValue(&unused->object.scale[i], 1);

return unused;

#undef LEADING
}

void FI_SetText(fitext_t* tex, char* str)
Expand Down Expand Up @@ -1485,14 +1485,13 @@ int FI_FilterChar(int ch)
return ch;
}

int FI_CharWidth(int ch, boolean fontb)
int FI_CharWidth(int ch, compositefontid_t font)
{
ch = FI_FilterChar(ch);

return GL_CharWidth(ch, fontb? GF_FONTB : GF_FONTA);
return GL_CharWidth(ch, font);
}

int FI_GetLineWidth(char* text, boolean fontb)
int FI_GetLineWidth(char* text, compositefontid_t font)
{
int width = 0;

Expand All @@ -1509,19 +1508,17 @@ int FI_GetLineWidth(char* text, boolean fontb)
if(*text == 'w' || *text == 'W' || *text == 'p' || *text == 'P')
continue;
}
width += FI_CharWidth(*text, fontb);
width += FI_CharWidth(*text, font);
}

return width;
}

int FI_DrawChar(int x, int y, int ch, boolean fontb)
int FI_DrawChar(int x, int y, int ch, compositefontid_t font)
{
ch = FI_FilterChar(ch);

GL_DrawChar2(ch, x, y, fontb? GF_FONTB : GF_FONTA);

return FI_CharWidth(ch, fontb);
GL_DrawChar2(ch, x, y, font);
return FI_CharWidth(ch, font);
}

void FI_UseColor(fivalue_t *color, int components)
Expand All @@ -1532,8 +1529,7 @@ void FI_UseColor(fivalue_t *color, int components)
}
else if(components == 4)
{
DGL_Color4f(color[0].value, color[1].value, color[2].value,
color[3].value);
DGL_Color4f(color[0].value, color[1].value, color[2].value, color[3].value);
}
}

Expand Down Expand Up @@ -1615,7 +1611,7 @@ void FI_DrawText(fitext_t *tex)
ptr++)
{
if(linew < 0)
linew = FI_GetLineWidth(ptr, tex->flags.font_b);
linew = FI_GetLineWidth(ptr, tex->font);

ch = *ptr;
if(*ptr == '\\') // Escape?
Expand Down Expand Up @@ -1649,7 +1645,7 @@ void FI_DrawText(fitext_t *tex)
if(*ptr == 'n' || *ptr == 'N') // Newline?
{
x = 0;
y += tex->lineheight;
y += GL_CharHeight('A', tex->font) * tex->lineheight;
linew = -1;
cnt++; // Include newlines in the wait count.
continue;
Expand All @@ -1664,8 +1660,7 @@ void FI_DrawText(fitext_t *tex)
-tex->object.scale[1].value * tex->lineheight &&
tex->object.scale[1].value * y + tex->object.y.value < 200)
{
x += FI_DrawChar(tex->flags.centered ? x - linew / 2 : x, y, ch,
tex->flags.font_b);
x += FI_DrawChar(tex->flags.centered ? x - linew / 2 : x, y, ch, tex->font);
}

cnt++; // Actual character drawn.
Expand Down Expand Up @@ -2754,31 +2749,32 @@ void FIC_TextRate(void)
void FIC_TextLineHeight(void)
{
fitext_t* tex = FI_GetText(FI_GetToken());
tex->lineheight = FI_GetInteger();
tex->lineheight = FI_GetFloat();
}

void FIC_Font(void)
{
fitext_t* tex = FI_GetText(FI_GetToken());
const char* fontName = FI_GetToken();
compositefontid_t font;
if((font = R_CompositeFontNumForName(fontName)))
{
tex->font = font;
return;
}
Con_Message("FIC_Font: Warning, unknown font '%s'.\n", fontName);
}

void FIC_FontA(void)
{
fitext_t* tex = FI_GetText(FI_GetToken());
tex->flags.font_b = false;
// Set line height to font A.
#if __JDOOM__
tex->lineheight = 11;
#else
tex->lineheight = 9;
#endif
tex->font = GF_FONTA;
}

void FIC_FontB(void)
{
fitext_t* tex = FI_GetText(FI_GetToken());

tex->flags.font_b = true;
#if __JDOOM__
tex->lineheight = 15;
#else
tex->lineheight = 20;
#endif
tex->font = GF_FONTB;
}

void FIC_NoMusic(void)
Expand Down

0 comments on commit be3b366

Please sign in to comment.