Skip to content

Commit

Permalink
Refactor: Turned the caseScale argument for FR_DrawText into a
Browse files Browse the repository at this point in the history
font renderer state attribute.
  • Loading branch information
danij-deng committed Jun 12, 2011
1 parent d9cfd2b commit da19811
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 29 deletions.
7 changes: 6 additions & 1 deletion doomsday/engine/api/dd_fontrenderer.h
Expand Up @@ -97,10 +97,15 @@ float FR_GlitterStrength(void);

void FR_SetGlitterStrength(float value);

/// @return Current case scale.
boolean FR_CaseScale(void);

void FR_SetCaseScale(boolean value);

/**
* Text: A block of possibly formatted and/or multi-line text.
*/
void FR_DrawText(const char* string, int x, int y, int defAlignFlags, short defFlags, boolean defCase);
void FR_DrawText(const char* string, int x, int y, int alignFlags, short flags);

// Utility routines:
void FR_TextDimensions(int* width, int* height, const char* string);
Expand Down
32 changes: 17 additions & 15 deletions doomsday/engine/api/doomsday.def
@@ -1,6 +1,6 @@
; Doomsday Engine API (Routines exported from Doomsday.exe).
;
; Highest ordinal is currently: --> 518 <--
; Highest ordinal is currently: --> 520 <--
; Other free ordinals: 65

NAME "DOOMSDAY"
Expand Down Expand Up @@ -512,26 +512,28 @@ EXPORTS
FR_SetShadowStrength @131 NONAME
FR_GlitterStrength @197 NONAME
FR_SetGlitterStrength @198 NONAME
FR_CaseScale @199 NONAME
FR_SetCaseScale @200 NONAME

FR_TextDimensions @199 NONAME
FR_TextWidth @200 NONAME
FR_TextHeight @201 NONAME
FR_TextDimensions @201 NONAME
FR_TextWidth @202 NONAME
FR_TextHeight @203 NONAME

FR_DrawText @202 NONAME
FR_DrawText @204 NONAME

FR_TextFragmentDimensions @203 NONAME
FR_TextFragmentWidth @204 NONAME
FR_TextFragmentHeight @205 NONAME
FR_TextFragmentDimensions @205 NONAME
FR_TextFragmentWidth @206 NONAME
FR_TextFragmentHeight @513 NONAME

FR_DrawTextFragment @206 NONAME
FR_DrawTextFragment2 @513 NONAME
FR_DrawTextFragment @514 NONAME
FR_DrawTextFragment2 @515 NONAME

FR_DrawChar @514 NONAME
FR_DrawChar2 @515 NONAME
FR_DrawChar @516 NONAME
FR_DrawChar2 @517 NONAME

FR_CharDimensions @516 NONAME
FR_CharWidth @517 NONAME
FR_CharHeight @518 NONAME
FR_CharDimensions @518 NONAME
FR_CharWidth @519 NONAME
FR_CharHeight @520 NONAME

; Audio.
S_MapChange @225 NONAME
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/portable/include/gl_font.h
Expand Up @@ -38,6 +38,7 @@
#define DEFAULT_SHADOW_STRENGTH (.5)
#define DEFAULT_SHADOW_XOFFSET (2)
#define DEFAULT_SHADOW_YOFFSET (2)
#define DEFAULT_CASE_SCALE (false)

#define DEFAULT_ALIGNFLAGS (ALIGN_TOPLEFT)
#define DEFAULT_DRAWFLAGS (DTF_NO_EFFECTS)
Expand Down
33 changes: 26 additions & 7 deletions doomsday/engine/portable/src/gl_font.c
Expand Up @@ -49,6 +49,7 @@ typedef struct fr_state_attributes_s {
int shadowOffsetX, shadowOffsetY;
float shadowStrength;
float glitterStrength;
boolean caseScale;
} fr_state_attributes_t;

typedef struct {
Expand Down Expand Up @@ -424,6 +425,7 @@ void FR_LoadDefaultAttrib(void)
sat->shadowOffsetX = DEFAULT_SHADOW_XOFFSET;
sat->shadowOffsetY = DEFAULT_SHADOW_YOFFSET;
sat->glitterStrength = DEFAULT_GLITTER_STRENGTH;
sat->caseScale = DEFAULT_CASE_SCALE;
}

void FR_PushAttrib(void)
Expand Down Expand Up @@ -533,6 +535,22 @@ void FR_SetGlitterStrength(float value)
sat->glitterStrength = MINMAX_OF(0, value, 1);
}

boolean FR_CaseScale(void)
{
fr_state_attributes_t* sat = currentAttributes();
if(!inited)
Con_Error("FR_CaseScale: Font renderer has not yet been initialized.");
return sat->caseScale;
}

void FR_SetCaseScale(boolean value)
{
fr_state_attributes_t* sat = currentAttributes();
if(!inited)
Con_Error("FR_SetCaseScale: Font renderer has not yet been initialized.");
sat->caseScale = value;
}

void FR_CharDimensions(int* width, int* height, unsigned char ch)
{
if(!inited)
Expand Down Expand Up @@ -1212,12 +1230,12 @@ static void initDrawTextState(drawtextstate_t* state)
state->shadowOffsetX = sat->shadowOffsetX;
state->shadowOffsetY = sat->shadowOffsetY;
state->leading = sat->leading;
state->caseScale = sat->caseScale;

state->scaleX = state->scaleY = 1;
state->offX = state->offY = 0;
state->angle = 0;
state->typeIn = true;
state->caseScale = false;
state->caseMod[0].scale = 1;
state->caseMod[0].offset = 3;
state->caseMod[1].scale = 1.25f;
Expand All @@ -1227,8 +1245,7 @@ static void initDrawTextState(drawtextstate_t* state)
/**
* Draw a string of text controlled by parameter blocks.
*/
void FR_DrawText(const char* inString, int x, int y, int alignFlags,
short textFlags, boolean defCase)
void FR_DrawText(const char* inString, int x, int y, int alignFlags, short textFlags)
{
#define SMALLBUFF_SIZE (80)
#define MAX_FRAGMENTLENGTH (256)
Expand Down Expand Up @@ -1267,7 +1284,6 @@ void FR_DrawText(const char* inString, int x, int y, int alignFlags,
memcpy(origColor, state.color, sizeof(origColor));
// Apply defaults:
state.typeIn = (textFlags & DTF_NO_TYPEIN) == 0;
state.caseScale = defCase;

FR_PushAttrib();

Expand All @@ -1283,6 +1299,7 @@ void FR_DrawText(const char* inString, int x, int y, int alignFlags,
float lastLeading = state.leading;
float lastShadowStrength = state.shadowStrength;
float lastGlitterStrength = state.glitterStrength;
boolean lastCaseScale = state.caseScale;
int numBreaks = 0;

parseParamaterBlock(&string, &state, &numBreaks);
Expand All @@ -1306,6 +1323,8 @@ void FR_DrawText(const char* inString, int x, int y, int alignFlags,
FR_SetShadowStrength(state.shadowStrength);
if(state.glitterStrength != lastGlitterStrength)
FR_SetGlitterStrength(state.glitterStrength);
if(state.caseScale != lastCaseScale)
FR_SetCaseScale(state.caseScale);
}

for(end = string; *end && *end != '{';)
Expand All @@ -1315,7 +1334,7 @@ void FR_DrawText(const char* inString, int x, int y, int alignFlags,
float alignx = 0;

// Find the end of the next fragment.
if(state.caseScale)
if(FR_CaseScale())
{
curCase = -1;
// Select a substring with characters of the same case (or whitespace).
Expand Down Expand Up @@ -1378,8 +1397,8 @@ void FR_DrawText(const char* inString, int x, int y, int alignFlags,
glTranslatef(-(float)x, -(float)y, 0);
}

glTranslatef(cx + state.offX + alignx, cy + state.offY + (state.caseScale ? state.caseMod[curCase].offset : 0), 0);
extraScale = (state.caseScale ? state.caseMod[curCase].scale : 1);
glTranslatef(cx + state.offX + alignx, cy + state.offY + (FR_CaseScale() ? state.caseMod[curCase].offset : 0), 0);
extraScale = (FR_CaseScale() ? state.caseMod[curCase].scale : 1);
glScalef(state.scaleX, state.scaleY * extraScale, 1);

// Draw it.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/hu_chat.c
Expand Up @@ -385,7 +385,7 @@ void UIChat_Drawer(uiwidget_t* obj, int x, int y)

DGL_Enable(DGL_TEXTURE_2D);
DGL_Color4f(cfg.hudColor[CR], cfg.hudColor[CG], cfg.hudColor[CB], textAlpha);
FR_DrawText(text, xOffset, 0, alignFlags, textFlags, false);
FR_DrawText(text, xOffset, 0, alignFlags, textFlags);
if(actualMapTime & 12)
{
FR_DrawChar('_', xOffset + textWidth, 0);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/hu_log.c
Expand Up @@ -423,7 +423,7 @@ void UILog_Drawer(uiwidget_t* obj, int xOrigin, int yOrigin)
}

DGL_Color4f(col[CR], col[CG], col[CB], col[CA]);
FR_DrawText(msg->text, 0, y, alignFlags, textFlags, false);
FR_DrawText(msg->text, 0, y, alignFlags, textFlags);

++drawnMsgCount;
y += lineHeight;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/hu_msg.c
Expand Up @@ -210,7 +210,7 @@ static void drawMessage(void)
FR_SetShadowStrength(cfg.menuTextGlitter);
FR_SetGlitterStrength(cfg.menuShadow);

FR_DrawText(msgText, x, y, ALIGN_TOP, textFlags, false);
FR_DrawText(msgText, x, y, ALIGN_TOP, textFlags);
y += FR_TextHeight(msgText);
// An additional blank line between the message and response prompt.
y += FR_CharHeight('A') * (1+LEADING);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/src/hu_stuff.c
Expand Up @@ -1218,7 +1218,7 @@ void WI_DrawPatch5(patchid_t patchId, const char* replacement, int x, int y, int
FR_SetTracking(0);
FR_SetGlitterStrength(glitter);
FR_SetShadowStrength(shadow);
FR_DrawText(replacement, x, y, alignFlags, textFlags, false);
FR_DrawText(replacement, x, y, alignFlags, textFlags);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/jheretic/src/st_stuff.c
Expand Up @@ -2733,7 +2733,7 @@ void MapName_Drawer(uiwidget_t* obj, int x, int y)
DGL_Enable(DGL_TEXTURE_2D);
DGL_Color4f(cfg.hudColor[0], cfg.hudColor[1], cfg.hudColor[2], textAlpha);
FR_SetFont(obj->fontId);
FR_DrawText(text, 0, 0, ALIGN_BOTTOMLEFT, DTF_NO_EFFECTS, false);
FR_DrawText(text, 0, 0, ALIGN_BOTTOMLEFT, DTF_NO_EFFECTS);
DGL_Disable(DGL_TEXTURE_2D);

DGL_MatrixMode(DGL_MODELVIEW);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/jhexen/src/st_stuff.c
Expand Up @@ -3133,7 +3133,7 @@ void MapName_Drawer(uiwidget_t* obj, int x, int y)
DGL_Enable(DGL_TEXTURE_2D);
DGL_Color4f(cfg.hudColor[0], cfg.hudColor[1], cfg.hudColor[2], textAlpha);
FR_SetFont(obj->fontId);
FR_DrawText(text, 0, 0, ALIGN_BOTTOMLEFT, DTF_NO_EFFECTS, false);
FR_DrawText(text, 0, 0, ALIGN_BOTTOMLEFT, DTF_NO_EFFECTS);
DGL_Disable(DGL_TEXTURE_2D);

DGL_MatrixMode(DGL_MODELVIEW);
Expand Down

0 comments on commit da19811

Please sign in to comment.