Skip to content

Commit

Permalink
Refactor: Removed alignment flags from drawTextFlags and replaced their
Browse files Browse the repository at this point in the history
usage with the general purpose alignmentFlags defined in dd_share.h
  • Loading branch information
danij-deng committed Jun 12, 2011
1 parent df9171f commit 3e97cfa
Show file tree
Hide file tree
Showing 33 changed files with 259 additions and 268 deletions.
21 changes: 6 additions & 15 deletions doomsday/engine/api/dd_bitmapfont.h
Expand Up @@ -57,18 +57,9 @@ void FR_ResetTypeInTimer(void);
* @defGroup drawTextFlags Draw Text Flags
*/
/*@{*/
#define DTF_ALIGN_LEFT 0x0001
#define DTF_ALIGN_RIGHT 0x0002
#define DTF_ALIGN_TOP 0x0004
#define DTF_ALIGN_BOTTOM 0x0008
#define DTF_NO_TYPEIN 0x0010
#define DTF_NO_SHADOW 0x0020
#define DTF_NO_GLITTER 0x0040

#define DTF_ALIGN_TOPLEFT (DTF_ALIGN_TOP|DTF_ALIGN_LEFT)
#define DTF_ALIGN_BOTTOMLEFT (DTF_ALIGN_BOTTOM|DTF_ALIGN_LEFT)
#define DTF_ALIGN_TOPRIGHT (DTF_ALIGN_TOP|DTF_ALIGN_RIGHT)
#define DTF_ALIGN_BOTTOMRIGHT (DTF_ALIGN_BOTTOM|DTF_ALIGN_RIGHT)
#define DTF_NO_TYPEIN 0x0001
#define DTF_NO_SHADOW 0x0002
#define DTF_NO_GLITTER 0x0004

#define DTF_NO_EFFECTS (DTF_NO_TYPEIN|DTF_NO_SHADOW|DTF_NO_GLITTER)
#define DTF_ONLY_SHADOW (DTF_NO_TYPEIN|DTF_NO_GLITTER)
Expand Down Expand Up @@ -105,7 +96,7 @@ int FR_Tracking(void);
/**
* Text: A block of possibly formatted and/or multi-line text.
*/
void FR_DrawText(const char* string, int x, int y, fontid_t defFont, short defFlags, float defLeading, int defTracking, float defRed, float defGreen, float defBlue, float defAlpha, float defGlitter, float defShadow, boolean defCase);
void FR_DrawText(const char* string, int x, int y, fontid_t defFont, int defAlignFlags, short defFlags, float defLeading, int defTracking, float defRed, float defGreen, float defBlue, float defAlpha, float defGlitter, float defShadow, boolean defCase);

// Utility routines:
void FR_TextDimensions(int* width, int* height, const char* string, fontid_t defFont);
Expand All @@ -116,7 +107,7 @@ int FR_TextHeight(const char* string, fontid_t defFont);
* Text fragments: A single line of unformatted text.
*/
void FR_DrawTextFragment(const char* string, int x, int y);
void FR_DrawTextFragment2(const char* string, int x, int y, short flags);
void FR_DrawTextFragment2(const char* string, int x, int y, int alignFlags, short flags);

// Utility routines:
void FR_TextFragmentDimensions(int* width, int* height, const char* string);
Expand All @@ -127,7 +118,7 @@ int FR_TextFragmentHeight(const char* string);
* Single character.
*/
void FR_DrawChar(unsigned char ch, int x, int y);
void FR_DrawChar2(unsigned char ch, int x, int y, short flags);
void FR_DrawChar2(unsigned char ch, int x, int y, int alignFlags, short flags);

// Utility routines:
void FR_CharDimensions(int* width, int* height, unsigned char ch);
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/api/dd_ui.h
Expand Up @@ -253,6 +253,7 @@ void FIData_PicClearAnimation(struct fi_object_s* pic);
typedef struct fidata_text_s {
FIOBJECT_BASE_ELEMENTS()
animatorvector4_t color;
int alignFlags; /// @see alignmentFlags
short textFlags; /// @see drawTextFlags
int scrollWait, scrollTimer; /// Automatic scrolling upwards.
size_t cursorPos;
Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/portable/include/gl_font.h
Expand Up @@ -39,7 +39,8 @@
#define DEFAULT_SHADOW_XOFFSET (2)
#define DEFAULT_SHADOW_YOFFSET (2)

#define DEFAULT_DRAWFLAGS (DTF_ALIGN_TOPLEFT|DTF_NO_EFFECTS)
#define DEFAULT_ALIGNFLAGS (ALIGN_TOPLEFT)
#define DEFAULT_DRAWFLAGS (DTF_NO_EFFECTS)

/**
* Initialize the font renderer.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/ui_main.h
Expand Up @@ -350,7 +350,7 @@ void UI_DrawButton(int x, int y, int w, int h, int brd, float alpha, ui_color_t*

/// Draw shadowed text.
void UI_TextOutEx(const char* text, int x, int y, ui_color_t* color, float alpha);
void UI_TextOutEx2(const char* text, int x, int y, ui_color_t* color, float alpha, short flags);
void UI_TextOutEx2(const char* text, int x, int y, ui_color_t* color, float alpha, int alignFlags, short textFlags);
int UI_TextOutWrap(const char* text, int x, int y, int w, int h);

/**
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/con_busy.c
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_DrawTextFragment2(busyTaskName, x+radius, y, DTF_ALIGN_LEFT|DTF_ONLY_SHADOW);
FR_DrawTextFragment2(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_DrawTextFragment2(line->text, theWindow->width/2, y, DTF_ALIGN_TOP|DTF_ONLY_SHADOW);
FR_DrawTextFragment2(line->text, theWindow->width/2, y, ALIGN_TOP, DTF_ONLY_SHADOW);
}

glDisable(GL_TEXTURE_2D);
Expand Down
22 changes: 11 additions & 11 deletions doomsday/engine/portable/src/edit_bias.c
Expand Up @@ -693,30 +693,30 @@ static void SBE_InfoBox(source_t* s, int rightX, char* title, float alpha)
FR_SetFont(glFontFixed);
FR_SetShadowOffset(UI_SHADOW_OFFSET, UI_SHADOW_OFFSET);
FR_SetShadowStrength(UI_SHADOW_STRENGTH);
UI_TextOutEx2(title, x, y, UI_Color(UIC_TITLE), alpha, DTF_ALIGN_LEFT|DTF_ONLY_SHADOW);
UI_TextOutEx2(title, x, y, UI_Color(UIC_TITLE), alpha, ALIGN_LEFT, DTF_ONLY_SHADOW);
y += th;

sprintf(buf, "# %03i %s", SB_ToIndex(s), (s->flags & BLF_LOCKED ? "(lock)" : ""));
UI_TextOutEx2(buf, x, y, UI_Color(UIC_TEXT), alpha, DTF_ALIGN_LEFT|DTF_ONLY_SHADOW);
UI_TextOutEx2(buf, x, y, UI_Color(UIC_TEXT), alpha, ALIGN_LEFT, DTF_ONLY_SHADOW);
y += th;

sprintf(buf, "(%+06.0f,%+06.0f,%+06.0f)", s->pos[0], s->pos[1], s->pos[2]);
UI_TextOutEx2(buf, x, y, UI_Color(UIC_TEXT), alpha, DTF_ALIGN_LEFT|DTF_ONLY_SHADOW);
UI_TextOutEx2(buf, x, y, UI_Color(UIC_TEXT), alpha, ALIGN_LEFT, DTF_ONLY_SHADOW);
y += th;

sprintf(buf, "Distance:%-.0f", M_Distance(eye, s->pos));
UI_TextOutEx2(buf, x, y, UI_Color(UIC_TEXT), alpha, DTF_ALIGN_LEFT|DTF_ONLY_SHADOW);
UI_TextOutEx2(buf, x, y, UI_Color(UIC_TEXT), alpha, ALIGN_LEFT, DTF_ONLY_SHADOW);
y += th;

sprintf(buf, "Intens:%-5.0f L:%3i/%3i", s->primaryIntensity,
(int) (255.0f * s->sectorLevel[0]),
(int) (255.0f * s->sectorLevel[1]));

UI_TextOutEx2(buf, x, y, UI_Color(UIC_TEXT), alpha, DTF_ALIGN_LEFT|DTF_ONLY_SHADOW);
UI_TextOutEx2(buf, x, y, UI_Color(UIC_TEXT), alpha, ALIGN_LEFT, DTF_ONLY_SHADOW);
y += th;

sprintf(buf, "R:%.3f G:%.3f B:%.3f", s->color[0], s->color[1], s->color[2]);
UI_TextOutEx2(buf, x, y, UI_Color(UIC_TEXT), alpha, DTF_ALIGN_LEFT|DTF_ONLY_SHADOW);
UI_TextOutEx2(buf, x, y, UI_Color(UIC_TEXT), alpha, ALIGN_LEFT, DTF_ONLY_SHADOW);
y += th;
}

Expand Down Expand Up @@ -797,13 +797,13 @@ static void SBE_DrawLevelGauge(int x, int y, int height)

// The number values.
sprintf(buf, "%03i", (short) (255.0f * sector->lightLevel));
UI_TextOutEx2(buf, x, secY, UI_Color(UIC_TITLE), .7f, DTF_ONLY_SHADOW);
UI_TextOutEx2(buf, x, secY, UI_Color(UIC_TITLE), .7f, 0, DTF_ONLY_SHADOW);
if(maxLevel != minLevel)
{
sprintf(buf, "%03i", (short) (255.0f * maxLevel));
UI_TextOutEx2(buf, x + 2*off, maxY, UI_Color(UIC_TEXT), .7f, DTF_ONLY_SHADOW);
UI_TextOutEx2(buf, x + 2*off, maxY, UI_Color(UIC_TEXT), .7f, 0, DTF_ONLY_SHADOW);
sprintf(buf, "%03i", (short) (255.0f * minLevel));
UI_TextOutEx2(buf, x + 2*off, minY, UI_Color(UIC_TEXT), .7f, DTF_ONLY_SHADOW);
UI_TextOutEx2(buf, x + 2*off, minY, UI_Color(UIC_TEXT), .7f, 0, DTF_ONLY_SHADOW);
}

glDisable(GL_TEXTURE_2D);
Expand Down Expand Up @@ -838,10 +838,10 @@ void SBE_DrawHUD(void)
h = FR_TextFragmentHeight(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, DTF_ALIGN_LEFT|DTF_ONLY_SHADOW);
UI_TextOutEx2(buf, 18, y + h / 2, UI_Color(UIC_TITLE), alpha, ALIGN_LEFT, DTF_ONLY_SHADOW);

// The map ID.
UI_TextOutEx2(P_GetUniqueMapID(map), 18, y - h/2, UI_Color(UIC_TITLE), alpha, DTF_ALIGN_LEFT|DTF_ONLY_SHADOW);
UI_TextOutEx2(P_GetUniqueMapID(map), 18, y - h/2, UI_Color(UIC_TITLE), alpha, ALIGN_LEFT, DTF_ONLY_SHADOW);

// Stats for nearest & grabbed:
if(numSources)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/finaleinterpreter.c
Expand Up @@ -2004,13 +2004,13 @@ DEFFC(TextOffY)
DEFFC(TextCenter)
{
fi_object_t* obj = getObject(fi, FI_TEXT, OP_CSTRING(0));
((fidata_text_t*)obj)->textFlags &= ~(DTF_ALIGN_LEFT|DTF_ALIGN_RIGHT);
((fidata_text_t*)obj)->alignFlags &= ~(ALIGN_LEFT|ALIGN_RIGHT);
}

DEFFC(TextNoCenter)
{
fi_object_t* obj = getObject(fi, FI_TEXT, OP_CSTRING(0));
((fidata_text_t*)obj)->textFlags |= DTF_ALIGN_LEFT;
((fidata_text_t*)obj)->alignFlags |= ALIGN_LEFT;
}

DEFFC(TextScroll)
Expand Down
65 changes: 33 additions & 32 deletions doomsday/engine/portable/src/gl_font.c
Expand Up @@ -78,7 +78,7 @@ typedef struct {
static __inline fr_state_attributes_t* currentAttributes(void);
static int topToAscent(bitmapfont_t* font);
static int lineHeight(bitmapfont_t* font, unsigned char ch);
static void drawChar(unsigned char ch, int posX, int posY, bitmapfont_t* font, short flags);
static void drawChar(unsigned char ch, int posX, int posY, bitmapfont_t* font, int alignFlags, short textFlags);
static void drawFlash(int x, int y, int w, int h, int bright);

static int inited = false;
Expand Down Expand Up @@ -611,16 +611,16 @@ int FR_GlyphTopToAscent(const char* text)
return lineHeight - BitmapFont_Ascent(fonts[fr.fontIdx]);
}

static void drawTextFragment(const char* string, int x, int y, short flags,
int initialCount)
static void drawTextFragment(const char* string, int x, int y, int alignFlags,
short textFlags, int initialCount)
{
assert(inited && string && string[0] && fr.fontIdx != -1);
{
bitmapfont_t* cf = fonts[fr.fontIdx];
fr_state_attributes_t* sat = currentAttributes();
boolean noTypein = (flags & DTF_NO_TYPEIN) != 0;
boolean noGlitter = (sat->glitterStrength <= 0 || (flags & DTF_NO_GLITTER) != 0);
boolean noShadow = (sat->shadowStrength <= 0 || (flags & DTF_NO_SHADOW) != 0 ||
boolean noTypein = (textFlags & DTF_NO_TYPEIN) != 0;
boolean noGlitter = (sat->glitterStrength <= 0 || (textFlags & DTF_NO_GLITTER) != 0);
boolean noShadow = (sat->shadowStrength <= 0 || (textFlags & DTF_NO_SHADOW) != 0 ||
(BitmapFont_Flags(cf) & BFF_HAS_EMBEDDEDSHADOW) != 0);
float glitter = (noGlitter? 0 : sat->glitterStrength), glitterMul;
float shadow = (noShadow ? 0 : sat->shadowStrength), shadowMul;
Expand All @@ -629,14 +629,14 @@ static void drawTextFragment(const char* string, int x, int y, short flags,
unsigned char c;
const char* ch;

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

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

if(!(noTypein && noShadow && noGlitter))
Expand Down Expand Up @@ -767,7 +767,7 @@ static void drawTextFragment(const char* string, int x, int y, short flags,
if(pass)
{
// The character itself.
drawChar(c, cx, cy + yoff, cf, DEFAULT_DRAWFLAGS);
drawChar(c, cx, cy + yoff, cf, ALIGN_TOPLEFT, DTF_NO_EFFECTS);

if(!noGlitter && glitter > 0)
{ // Do something flashy.
Expand Down Expand Up @@ -797,7 +797,7 @@ static void drawTextFragment(const char* string, int x, int y, short flags,
}
}

void FR_DrawTextFragment2(const char* string, int x, int y, short flags)
void FR_DrawTextFragment2(const char* string, int x, int y, int alignFlags, short textFlags)
{
if(!inited)
Con_Error("Bitmap font system not yet initialized.");
Expand All @@ -815,15 +815,15 @@ void FR_DrawTextFragment2(const char* string, int x, int y, short flags)
#endif
return;
}
drawTextFragment(string, x, y, flags, DEFAULT_INITIALCOUNT);
drawTextFragment(string, x, y, alignFlags, textFlags, DEFAULT_INITIALCOUNT);
}

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

void FR_DrawChar2(unsigned char ch, int x, int y, short flags)
void FR_DrawChar2(unsigned char ch, int x, int y, int alignFlags, short textFlags)
{
bitmapfont_t* cf;
if(fr.fontIdx == -1)
Expand All @@ -838,7 +838,7 @@ void FR_DrawChar2(unsigned char ch, int x, int y, short flags)
glScalef(1.f / BitmapFont_TextureWidth(cf),
1.f / BitmapFont_TextureHeight(cf), 1.f);
}
drawChar(ch, x, y, cf, flags);
drawChar(ch, x, y, cf, alignFlags, textFlags);
if(0 != BitmapFont_GLTextureName(cf))
{
glMatrixMode(GL_TEXTURE);
Expand All @@ -848,22 +848,23 @@ void FR_DrawChar2(unsigned char ch, int x, int y, short flags)

void FR_DrawChar(unsigned char ch, int x, int y)
{
FR_DrawChar2(ch, x, y, DEFAULT_DRAWFLAGS);
FR_DrawChar2(ch, x, y, DEFAULT_ALIGNFLAGS, DEFAULT_DRAWFLAGS);
}

static void drawChar(unsigned char ch, int posX, int posY, bitmapfont_t* font, short flags)
static void drawChar(unsigned char ch, int posX, int posY, bitmapfont_t* font,
int alignFlags, short textFlags)
{
float x = (float) posX, y = (float) posY;
DGLuint tex;

if(flags & DTF_ALIGN_RIGHT)
if(alignFlags & ALIGN_RIGHT)
x -= BitmapFont_CharWidth(font, ch);
else if(!(flags & DTF_ALIGN_LEFT))
else if(!(alignFlags & ALIGN_LEFT))
x -= BitmapFont_CharWidth(font, ch) / 2;

if(flags & DTF_ALIGN_BOTTOM)
if(alignFlags & ALIGN_BOTTOM)
y -= topToAscent(font) + lineHeight(font, ch);
else if(!(flags & DTF_ALIGN_TOP))
else if(!(alignFlags & ALIGN_TOP))
y -= (topToAscent(font) + lineHeight(font, ch))/2;

if(renderWireframe)
Expand Down Expand Up @@ -1190,9 +1191,9 @@ 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, fontid_t defFont,
short flags, float defLeading, int defTracking, float defRed, float defGreen, float defBlue, float defAlpha,
float defGlitter, float defShadow, boolean defCase)
void FR_DrawText(const char* inString, int x, int y, fontid_t defFont, int alignFlags,
short textFlags, float defLeading, int defTracking, float defRed, float defGreen,
float defBlue, float defAlpha, float defGlitter, float defShadow, boolean defCase)
{
#define SMALLBUFF_SIZE (80)
#define MAX_FRAGMENTLENGTH (256)
Expand Down Expand Up @@ -1229,7 +1230,7 @@ void FR_DrawText(const char* inString, int x, int y, fontid_t defFont,
initDrawTextState(&state);
// Apply defaults:
state.font = defFont;
state.typeIn = (flags & DTF_NO_TYPEIN) == 0;
state.typeIn = (textFlags & DTF_NO_TYPEIN) == 0;
state.color[CR] = defRed;
state.color[CG] = defGreen;
state.color[CB] = defBlue;
Expand Down Expand Up @@ -1286,7 +1287,7 @@ void FR_DrawText(const char* inString, int x, int y, fontid_t defFont,
for(end = string; *end && *end != '{';)
{
boolean newline = false;
short fragmentFlags;
int fragmentAlignFlags;
float alignx = 0;

// Find the end of the next fragment.
Expand Down Expand Up @@ -1324,15 +1325,15 @@ void FR_DrawText(const char* inString, int x, int y, fontid_t defFont,
// Continue from here.
string = end;

if(!(flags & (DTF_ALIGN_LEFT|DTF_ALIGN_RIGHT)))
if(!(alignFlags & (ALIGN_LEFT|ALIGN_RIGHT)))
{
fragmentFlags = flags;
fragmentAlignFlags = alignFlags;
}
else
{
// We'll take care of horizontal positioning of the fragment so align left.
fragmentFlags = (flags & ~(DTF_ALIGN_RIGHT)) | DTF_ALIGN_LEFT;
if(flags & DTF_ALIGN_RIGHT)
fragmentAlignFlags = (alignFlags & ~(ALIGN_RIGHT)) | ALIGN_LEFT;
if(alignFlags & ALIGN_RIGHT)
alignx = -FR_TextFragmentWidth(temp) * state.scaleX;
}

Expand All @@ -1359,7 +1360,7 @@ void FR_DrawText(const char* inString, int x, int y, fontid_t defFont,

// Draw it.
glColor4fv(state.color);
drawTextFragment(temp, 0, 0, fragmentFlags, state.typeIn ? (int) charCount : DEFAULT_INITIALCOUNT);
drawTextFragment(temp, 0, 0, fragmentAlignFlags, textFlags, state.typeIn ? (int) charCount : DEFAULT_INITIALCOUNT);
charCount += strlen(temp);

// Advance the current position?
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_DrawTextFragment2(buf, x, y, DTF_ALIGN_TOPRIGHT|DTF_NO_EFFECTS);
FR_DrawTextFragment2(buf, x, y, ALIGN_TOPRIGHT, DTF_NO_EFFECTS);

glDisable(GL_TEXTURE_2D);

Expand Down

0 comments on commit 3e97cfa

Please sign in to comment.