Skip to content

Commit

Permalink
Refactor: Removed distinction between text blocks and text fragments
Browse files Browse the repository at this point in the history
at font renderer API level. This distinction need only exist within
the engine.
  • Loading branch information
danij-deng committed Jun 13, 2011
1 parent a046e70 commit e239f4b
Show file tree
Hide file tree
Showing 26 changed files with 219 additions and 342 deletions.
22 changes: 0 additions & 22 deletions doomsday/engine/api/dd_fontrenderer.h
Expand Up @@ -159,28 +159,6 @@ void FR_TextDimensions(int* width, int* height, const char* text);
int FR_TextWidth(const char* text);
int FR_TextHeight(const char* text);

/**
* Text fragments (a single line of unformatted text):
*/

/**
* Draw a text fragment.
*
* @param fragment Fragment of text to be drawn.
* @param x X origin/offset at which to begin drawing.
* @param y Y origin/offset at which to begin drawing.
* @param alignFlags @see alignmentFlags
* @param flags @see drawTextFlags
*/
void FR_DrawTextFragment3(const char* fragment, int x, int y, int alignFlags, short flags);
void FR_DrawTextFragment2(const char* fragment, int x, int y, int alignFlags);
void FR_DrawTextFragment(const char* fragment, int x, int y);

// Utility routines:
void FR_TextFragmentDimensions(int* width, int* height, const char* fragment);
int FR_TextFragmentWidth(const char* fragment);
int FR_TextFragmentHeight(const char* fragment);

/**
* Single characters:
*/
Expand Down
22 changes: 7 additions & 15 deletions doomsday/engine/api/doomsday.def
@@ -1,6 +1,6 @@
; Doomsday Engine API (Routines exported from Doomsday.exe).
;
; Highest ordinal is currently: --> 524 <--
; Highest ordinal is currently: --> 518 <--
; Other free ordinals: 65

NAME "DOOMSDAY"
Expand Down Expand Up @@ -523,21 +523,13 @@ EXPORTS
FR_DrawText2 @205 NONAME
FR_DrawText3 @206 NONAME

FR_TextFragmentDimensions @513 NONAME
FR_TextFragmentWidth @514 NONAME
FR_TextFragmentHeight @515 NONAME
FR_DrawChar @513 NONAME
FR_DrawChar2 @514 NONAME
FR_DrawChar3 @515 NONAME

FR_DrawTextFragment @516 NONAME
FR_DrawTextFragment2 @517 NONAME
FR_DrawTextFragment3 @518 NONAME

FR_DrawChar @519 NONAME
FR_DrawChar2 @520 NONAME
FR_DrawChar3 @521 NONAME

FR_CharDimensions @522 NONAME
FR_CharWidth @523 NONAME
FR_CharHeight @524 NONAME
FR_CharDimensions @516 NONAME
FR_CharWidth @517 NONAME
FR_CharHeight @518 NONAME

; Audio.
S_MapChange @225 NONAME
Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/portable/src/con_busy.c
Expand Up @@ -281,7 +281,7 @@ static void Con_BusyLoadTextures(void)
if(0 != (busyFont = FR_LoadSystemFont(fonts[fontIdx].name, fonts[fontIdx].path)))
{
FR_SetFont(busyFont);
busyFontHgt = FR_TextFragmentHeight("A");
busyFontHgt = FR_TextHeight("A");
}
}
}
Expand Down Expand Up @@ -507,7 +507,7 @@ static void Con_BusyDrawIndicator(float x, float y, float radius, float pos)
FR_SetFont(busyFont);
FR_LoadDefaultAttrib();
glColor4f(1.f, 1.f, 1.f, .66f);
FR_DrawTextFragment3(busyTaskName, x+radius, y, ALIGN_LEFT, DTF_ONLY_SHADOW);
FR_DrawText3(busyTaskName, x+radius, y, ALIGN_LEFT, DTF_ONLY_SHADOW);
}

glDisable(GL_TEXTURE_2D);
Expand Down Expand Up @@ -636,7 +636,7 @@ void Con_BusyDrawConsoleOutput(void)
color = 1 - (color - LINE_COUNT);

glColor4f(1.f, 1.f, 1.f, color);
FR_DrawTextFragment3(line->text, theWindow->width/2, y, ALIGN_TOP, DTF_ONLY_SHADOW);
FR_DrawText3(line->text, theWindow->width/2, y, ALIGN_TOP, DTF_ONLY_SHADOW);
}

glDisable(GL_TEXTURE_2D);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/con_main.c
Expand Up @@ -231,7 +231,7 @@ static void resizeHistoryBuffer(void)
FR_SetFont(consoleFont);
FR_LoadDefaultAttrib();
// Do we need to update the console history buffer max line length?
if(0 != (cw = FR_TextFragmentWidth("A")))
if(0 != (cw = FR_TextWidth("A")))
{
maxLength = MIN_OF(theWindow->width / cw - 2, 250);
}
Expand Down
12 changes: 6 additions & 6 deletions doomsday/engine/portable/src/edit_bias.c
Expand Up @@ -664,8 +664,8 @@ static void SBE_InfoBox(source_t* s, int rightX, char* title, float alpha)

FR_SetFont(glFontFixed);
FR_LoadDefaultAttrib();
w = 16 + FR_TextFragmentWidth("R:0.000 G:0.000 B:0.000");
th = FR_TextFragmentHeight("Info");
w = 16 + FR_TextWidth("R:0.000 G:0.000 B:0.000");
th = FR_TextHeight("Info");
h = 16 + th * 6;

x = theWindow->width - 10 - w - rightX;
Expand Down Expand Up @@ -757,7 +757,7 @@ static void SBE_DrawLevelGauge(int x, int y, int height)
FR_LoadDefaultAttrib();
FR_SetShadowOffset(UI_SHADOW_OFFSET, UI_SHADOW_OFFSET);
FR_SetShadowStrength(UI_SHADOW_STRENGTH);
off = FR_TextFragmentWidth("000");
off = FR_TextWidth("000");

glBegin(GL_LINES);
glColor4f(1, 1, 1, .5f);
Expand Down Expand Up @@ -834,8 +834,8 @@ void SBE_DrawHUD(void)
FR_LoadDefaultAttrib();
FR_SetShadowOffset(UI_SHADOW_OFFSET, UI_SHADOW_OFFSET);
FR_SetShadowStrength(UI_SHADOW_STRENGTH);
w = FR_TextFragmentWidth(buf) + 16;
h = FR_TextFragmentHeight(buf) + 16;
w = FR_TextWidth(buf) + 16;
h = FR_TextHeight(buf) + 16;
y = theWindow->height - 10 - h;
SBE_DrawBox(10, y, w, h, 0);
UI_TextOutEx2(buf, 18, y + h / 2, UI_Color(UIC_TITLE), alpha, ALIGN_LEFT, DTF_ONLY_SHADOW);
Expand All @@ -854,7 +854,7 @@ void SBE_DrawHUD(void)
{
int x;
FR_SetFont(glFontFixed);
x = FR_TextFragmentWidth("0") * 26;
x = FR_TextWidth("0") * 26;
SBE_InfoBox(s, x, "Grabbed", alpha);
}

Expand Down
107 changes: 7 additions & 100 deletions doomsday/engine/portable/src/gl_font.c
Expand Up @@ -580,68 +580,6 @@ int FR_CharHeight(unsigned char ch)
return 0;
}

void FR_TextFragmentDimensions(int* width, int* height, const char* text)
{
if(!inited)
Con_Error("FR_TextFragmentDimensions: Font renderer has not yet been initialized.");
if(!width && !height)
return;
if(width)
*width = FR_TextFragmentWidth(text);
if(height)
*height = FR_TextFragmentHeight(text);
}

int FR_TextFragmentWidth(const char* text)
{
size_t i, len;
int width = 0;
const char* ch;
unsigned char c;

if(!inited)
Con_Error("FR_TextFragmentWidth: Font renderer has not yet been initialized.");

if(fr.fontIdx == -1 || !text)
return 0;

// Just add them together.
len = strlen(text);
i = 0;
ch = text;
while(i++ < len && (c = *ch++) != 0 && c != '\n')
width += FR_CharWidth(c);

return (int) (width + currentAttributes()->tracking * (len-1));
}

int FR_TextFragmentHeight(const char* text)
{
const char* ch;
unsigned char c;
int height = 0;
size_t len;
uint i;

if(!inited)
Con_Error("FR_TextFragmentHeight: Font renderer has not yet been initialized.");

if(fr.fontIdx == -1 || !text)
return 0;

// Find the greatest height.
i = 0;
height = 0;
len = strlen(text);
ch = text;
while(i++ < len && (c = *ch++) != 0 && c != '\n')
{
height = MAX_OF(height, FR_CharHeight(c));
}

return topToAscent(fonts[fr.fontIdx]) + height;
}

int FR_SingleLineHeight(const char* text)
{
if(!inited)
Expand Down Expand Up @@ -687,14 +625,14 @@ static void drawTextFragment(const char* string, int x, int y, int alignFlags,
const char* ch;

if(alignFlags & ALIGN_RIGHT)
x -= FR_TextFragmentWidth(string);
x -= FR_TextWidth(string);
else if(!(alignFlags & ALIGN_LEFT))
x -= FR_TextFragmentWidth(string)/2;
x -= FR_TextWidth(string)/2;

if(alignFlags & ALIGN_BOTTOM)
y -= FR_TextFragmentHeight(string);
y -= FR_TextHeight(string);
else if(!(alignFlags & ALIGN_TOP))
y -= FR_TextFragmentHeight(string)/2;
y -= FR_TextHeight(string)/2;

if(!(noTypein && noShadow && noGlitter))
glGetFloatv(GL_CURRENT_COLOR, origColor);
Expand Down Expand Up @@ -854,37 +792,6 @@ static void drawTextFragment(const char* string, int x, int y, int alignFlags,
}
}

void FR_DrawTextFragment3(const char* string, int x, int y, int alignFlags, short textFlags)
{
if(!inited)
Con_Error("Bitmap font system not yet initialized.");
if(!string || !string[0])
{
/*#if _DEBUG
Con_Message("Warning: Attempt drawTextFragment with invalid/empty string.\n");
#endif*/
return;
}
if(fr.fontIdx == -1)
{
#if _DEBUG
Con_Message("Warning: Attempt drawTextFragment without a current font.\n");
#endif
return;
}
drawTextFragment(string, x, y, alignFlags, textFlags, DEFAULT_INITIALCOUNT);
}

void FR_DrawTextFragment2(const char* string, int x, int y, int alignFlags)
{
FR_DrawTextFragment3(string, x, y, alignFlags, DEFAULT_DRAWFLAGS);
}

void FR_DrawTextFragment(const char* string, int x, int y)
{
FR_DrawTextFragment2(string, x, y, DEFAULT_ALIGNFLAGS);
}

void FR_DrawChar3(unsigned char ch, int x, int y, int alignFlags, short textFlags)
{
bitmapfont_t* cf;
Expand Down Expand Up @@ -1393,7 +1300,7 @@ void FR_DrawText3(const char* text, int x, int y, int alignFlags, short textFlag
// We'll take care of horizontal positioning of the fragment so align left.
fragmentAlignFlags = (alignFlags & ~(ALIGN_RIGHT)) | ALIGN_LEFT;
if(alignFlags & ALIGN_RIGHT)
alignx = -FR_TextFragmentWidth(fragment) * state.scaleX;
alignx = -FR_TextWidth(fragment) * state.scaleX;
}

// Setup the scaling.
Expand Down Expand Up @@ -1426,12 +1333,12 @@ void FR_DrawText3(const char* text, int x, int y, int alignFlags, short textFlag
// Advance the current position?
if(!newline)
{
cx += (float) FR_TextFragmentWidth(fragment) * state.scaleX;
cx += (float) FR_TextWidth(fragment) * state.scaleX;
}
else
{
if(strlen(fragment) > 0)
lastLineHeight = FR_TextFragmentHeight(fragment);
lastLineHeight = FR_TextHeight(fragment);

cx = (float) x;
cy += (float) lastLineHeight * (1+FR_Leading());
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/net_main.c
Expand Up @@ -903,7 +903,7 @@ void Net_DrawDemoOverlay(void)
FR_SetFont(glFontFixed);
FR_LoadDefaultAttrib();
glColor3f(1, 1, 1);
FR_DrawTextFragment3(buf, x, y, ALIGN_TOPRIGHT, DTF_NO_EFFECTS);
FR_DrawText3(buf, x, y, ALIGN_TOPRIGHT, DTF_NO_EFFECTS);

glDisable(GL_TEXTURE_2D);

Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/portable/src/p_bmap.c
Expand Up @@ -1155,8 +1155,8 @@ static void drawInfoBox(int x, int y, long blockIdx, uint blockX,
FR_LoadDefaultAttrib();
FR_SetShadowOffset(UI_SHADOW_OFFSET, UI_SHADOW_OFFSET);
FR_SetShadowStrength(UI_SHADOW_STRENGTH);
w = FR_TextFragmentWidth(buf) + 16;
h = FR_TextFragmentHeight(buf) + 16;
w = FR_TextWidth(buf) + 16;
h = FR_TextHeight(buf) + 16;
x -= w / 2;
UI_GradientEx(x, y, w, h, 6, UI_Color(UIC_BG_MEDIUM), UI_Color(UIC_BG_LIGHT), .5f, .5f);
UI_DrawRectEx(x, y, w, h, 6, false, UI_Color(UIC_BRD_HI), NULL, .5f, -1);
Expand All @@ -1174,8 +1174,8 @@ static void drawInfoBox2(float minX, float minY, float maxX, float maxY,
FR_LoadDefaultAttrib();
FR_SetShadowOffset(UI_SHADOW_OFFSET, UI_SHADOW_OFFSET);
FR_SetShadowStrength(UI_SHADOW_STRENGTH);
w = 16 + FR_TextFragmentWidth("(+000.0,+000.0)(+000.0,+000.0)");
th = FR_TextFragmentHeight("a");
w = 16 + FR_TextWidth("(+000.0,+000.0)(+000.0,+000.0)");
th = FR_TextHeight("a");
h = th * 4 + 16;

x = theWindow->width - 10 - w;
Expand Down
12 changes: 6 additions & 6 deletions doomsday/engine/portable/src/rend_console.c
Expand Up @@ -425,7 +425,7 @@ void Rend_ConsoleFPS(int x, int y)
FR_LoadDefaultAttrib();
FR_SetShadowOffset(UI_SHADOW_OFFSET, UI_SHADOW_OFFSET);
FR_SetShadowStrength(UI_SHADOW_STRENGTH);
w = FR_TextFragmentWidth(buf) + 16;
w = FR_TextWidth(buf) + 16;
h = FR_SingleLineHeight(buf) + 16;

glEnable(GL_TEXTURE_2D);
Expand Down Expand Up @@ -468,7 +468,7 @@ static void drawConsoleTitleBar(float alpha)
UI_TextOutEx2(consoleTitle, border, height / 2, UI_Color(UIC_TITLE), alpha, ALIGN_LEFT, DTF_ONLY_SHADOW);
if(secondaryTitleText[0])
{
width = FR_TextFragmentWidth(consoleTitle) + FR_TextFragmentWidth(" ");
width = FR_TextWidth(consoleTitle) + FR_TextWidth(" ");
FR_SetFont(glFontVariable[GLFS_LIGHT]);
UI_TextOutEx2(secondaryTitleText, border + width, height / 2, UI_Color(UIC_TEXT), .33f * alpha,
ALIGN_LEFT, DTF_ONLY_SHADOW);
Expand Down Expand Up @@ -567,7 +567,7 @@ static void drawSideText(const char* text, int line, float alpha)
}

glColor4f(CcolYellow[0], CcolYellow[1], CcolYellow[2], alpha * .75f);
FR_DrawTextFragment3(text, ssw - 3, y / scale[1], ALIGN_TOPRIGHT, DTF_NO_TYPEIN|DTF_NO_GLITTER|(!consoleTextShadow?DTF_NO_SHADOW:0));
FR_DrawText3(text, ssw - 3, y / scale[1], ALIGN_TOPRIGHT, DTF_NO_TYPEIN|DTF_NO_GLITTER|(!consoleTextShadow?DTF_NO_SHADOW:0));
}
}
}
Expand Down Expand Up @@ -691,7 +691,7 @@ static void drawConsole(float consoleAlpha)
// Set the color.
if(BitmapFont_Flags(cfont) & BFF_IS_MONOCHROME)
consoleSetColor(line->flags, consoleAlpha);
FR_DrawTextFragment3(buff, XORIGIN + PADDING + xOffset,
FR_DrawText3(buff, XORIGIN + PADDING + xOffset,
YORIGIN + y / scale[1], alignFlags, textFlags);
}

Expand Down Expand Up @@ -719,7 +719,7 @@ static void drawConsole(float consoleAlpha)
else
glColor4f(1, 1, 1, consoleAlpha);

FR_DrawTextFragment3(buff, XORIGIN + PADDING, YORIGIN + y / scale[1], ALIGN_TOPLEFT, DTF_NO_TYPEIN|DTF_NO_GLITTER|(!consoleTextShadow?DTF_NO_SHADOW:0));
FR_DrawText3(buff, XORIGIN + PADDING, YORIGIN + y / scale[1], ALIGN_TOPLEFT, DTF_NO_TYPEIN|DTF_NO_GLITTER|(!consoleTextShadow?DTF_NO_SHADOW:0));

glDisable(GL_TEXTURE_2D);

Expand All @@ -733,7 +733,7 @@ static void drawConsole(float consoleAlpha)
// Where is the cursor?
memset(temp, 0, sizeof(temp));
strncpy(temp, buff, MIN_OF(LOCALBUFFSIZE -1/*prompt length*/ -1/*vis clamp*/, cmdCursor+1));
xOffset = FR_TextFragmentWidth(temp);
xOffset = FR_TextWidth(temp);
if(Con_InputMode())
{
height = fontScaledY;
Expand Down

0 comments on commit e239f4b

Please sign in to comment.