Skip to content

Commit

Permalink
Completed the next phase of the game-side 2D drawing cleanup; impleme…
Browse files Browse the repository at this point in the history
…nted vertical alignment/positioning flags for Patches and text strings. Also began removing game-side global copies of patchinfo_t, which are no longer needed.

Todo: Implement proper alignment calculations for paramaterized Patch replacement strings. The current algorithm for this is naive to per fragment-string offsets.
  • Loading branch information
danij-deng committed May 16, 2010
1 parent d4f686f commit 923d383
Show file tree
Hide file tree
Showing 24 changed files with 339 additions and 301 deletions.
57 changes: 30 additions & 27 deletions doomsday/plugins/common/include/hu_stuff.h
Expand Up @@ -56,19 +56,18 @@ typedef struct gamefont_s {
} chars[256];
} gamefont_t;

extern patchinfo_t m_pause; // Paused graphic.
extern patchinfo_t* mapNamePatches; // Name graphics of each map.
extern patchid_t* mapNamePatches; // Name graphics of each map.
#if __JDOOM__ || __JDOOM64__
extern patchinfo_t skillModeNames[NUM_SKILL_MODES]; // Name graphics of each skill mode.
extern patchid_t skillModeNames[NUM_SKILL_MODES]; // Name graphics of each skill mode.
#endif
#if __JDOOM__
extern patchinfo_t* episodeNamePatches; // Name graphics of each episode.
extern patchid_t* episodeNamePatches; // Name graphics of each episode.
#endif
#if __JHERETIC__ || __JHEXEN__
extern patchinfo_t dpInvItemBox;
extern patchinfo_t dpInvSelectBox;
extern patchinfo_t dpInvPageLeft[2];
extern patchinfo_t dpInvPageRight[2];
extern patchid_t dpInvItemBox;
extern patchid_t dpInvSelectBox;
extern patchid_t dpInvPageLeft[2];
extern patchid_t dpInvPageRight[2];
#endif

extern const char shiftXForm[];
Expand Down Expand Up @@ -112,20 +111,22 @@ void Draw_EndZoom(void);
* @defGroup drawTextFlags Draw Text Flags
*/
/*@{*/
#define DTF_ALIGN_LEFT 0x1
#define DTF_ALIGN_RIGHT 0x2
#define DTF_NO_TYPEIN 0x4
#define DTF_NO_SHADOW 0x8
#define DTF_ALIGN_LEFT 0x0001
#define DTF_ALIGN_RIGHT 0x0002
#define DTF_ALIGN_BOTTOM 0x0004
#define DTF_ALIGN_TOP 0x0008
#define DTF_NO_TYPEIN 0x0010
#define DTF_NO_SHADOW 0x0020
#define DTF_NO_EFFECTS (DTF_NO_TYPEIN|DTF_NO_SHADOW)
/*@}*/

void M_DrawText(const char* string, int x, int y);
void M_DrawText2(const char* string, int x, int y, gamefontid_t font);
void M_DrawText3(const char* string, int x, int y, gamefontid_t font, byte flags);
void M_DrawText4(const char* string, int x, int y, gamefontid_t font, byte flags, float red, float green, float blue, float alpha);
void M_DrawText5(const char* string, int x, int y, gamefontid_t font, byte flags, float red, float green, float blue, float alpha, int initialCount);
void M_DrawText3(const char* string, int x, int y, gamefontid_t font, short flags);
void M_DrawText4(const char* string, int x, int y, gamefontid_t font, short flags, float red, float green, float blue, float alpha);
void M_DrawText5(const char* string, int x, int y, gamefontid_t font, short flags, float red, float green, float blue, float alpha, int initialCount);

void WI_DrawParamText(const char* string, int x, int y, gamefontid_t font, byte flags, float defRed, float defGreen, float defBlue, float defAlpha, boolean defCase);
void WI_DrawParamText(const char* string, int x, int y, gamefontid_t font, short flags, float defRed, float defGreen, float defBlue, float defAlpha, boolean defCase);

// Utility routines:
int M_TextWidth(const char* string, gamefontid_t font);
Expand All @@ -136,11 +137,11 @@ int M_TextHeight(const char* string, gamefontid_t font);
*/
void M_DrawChar(unsigned char ch, int x, int y);
void M_DrawChar2(unsigned char ch, int x, int y, gamefontid_t font);
void M_DrawChar3(unsigned char ch, int x, int y, gamefontid_t font, byte flags);
void M_DrawChar3(unsigned char ch, int x, int y, gamefontid_t font, short flags);

void M_DrawShadowedChar(unsigned char ch, int x, int y);
void M_DrawShadowedChar2(unsigned char ch, int x, int y, gamefontid_t font);
void M_DrawShadowedChar3(unsigned char ch, int x, int y, gamefontid_t font, byte flags, float r, float g, float b, float a);
void M_DrawShadowedChar3(unsigned char ch, int x, int y, gamefontid_t font, short flags, float r, float g, float b, float a);

// Utility routines:
int M_CharWidth(unsigned char ch, gamefontid_t font);
Expand All @@ -165,24 +166,26 @@ void IN_DrawNumber(int val, int x, int y, int digits, float r, float
* @defGroup drawPatchFlags Draw Patch Flags.
*/
/*@{*/
#define DPF_ALIGN_LEFT 0x1
#define DPF_ALIGN_RIGHT 0x2
#define DPF_NO_OFFSETX 0x4
#define DPF_NO_OFFSETY 0x8
#define DPF_ALIGN_LEFT 0x0001
#define DPF_ALIGN_RIGHT 0x0002
#define DPF_ALIGN_BOTTOM 0x0004
#define DPF_ALIGN_TOP 0x0008
#define DPF_NO_OFFSETX 0x0010
#define DPF_NO_OFFSETY 0x0020
#define DPF_NO_OFFSET (DPF_NO_OFFSETX | DPF_NO_OFFSETY)
/*@}*/

void M_DrawPatch(patchid_t id, int x, int y);
void M_DrawPatch2(patchid_t id, int x, int y, byte flags);
void M_DrawPatch2(patchid_t id, int x, int y, short flags);

void M_DrawShadowedPatch(patchid_t id, int x, int y);
void M_DrawShadowedPatch2(patchid_t id, int x, int y, byte flags);
void M_DrawShadowedPatch3(patchid_t id, int x, int y, byte flags, float r, float g, float b, float a);
void M_DrawShadowedPatch2(patchid_t id, int x, int y, short flags);
void M_DrawShadowedPatch3(patchid_t id, int x, int y, short flags, float r, float g, float b, float a);

// Implements patch replacement.
void WI_DrawPatch(patchid_t id, int x, int y, const char* altstring, boolean builtin);
void WI_DrawPatch2(patchid_t id, int x, int y, const char* altstring, boolean builtin, byte flags);
void WI_DrawPatch3(patchid_t id, int x, int y, const char* altstring, boolean builtin, byte flags, float r, float g, float b, float a);
void WI_DrawPatch2(patchid_t id, int x, int y, const char* altstring, boolean builtin, short flags);
void WI_DrawPatch3(patchid_t id, int x, int y, const char* altstring, boolean builtin, short flags, float r, float g, float b, float a);

/**
* Misc specialised elements:
Expand Down
2 changes: 1 addition & 1 deletion doomsday/plugins/common/include/m_defs.h
Expand Up @@ -48,7 +48,7 @@ typedef struct {
const char* text;
void (*func) (int option, void *data);
int option;
patchinfo_t* patch;
patchid_t* patch;
void* data;
} menuitem_t;

Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/am_map.c
Expand Up @@ -1759,9 +1759,9 @@ void M_DrawMapMenu(void)
DGL_Color4f(1, 1, 1, Hu_MenuAlpha());

// Draw the page arrows.
token = dpInvPageLeft[!menu->firstItem || (menuTime & 8)].id;
token = dpInvPageLeft[!menu->firstItem || (menuTime & 8)];
M_DrawPatch(token, menu->x, menu->y - 22);
token = dpInvPageRight[menu->firstItem + menu->numVisItems >= menu->itemCount || (menuTime & 8)].id;
token = dpInvPageRight[menu->firstItem + menu->numVisItems >= menu->itemCount || (menuTime & 8)];
M_DrawPatch(token, 312 - menu->x, menu->y - 22);
#endif

Expand Down
14 changes: 7 additions & 7 deletions doomsday/plugins/common/src/hu_inventory.c
Expand Up @@ -368,7 +368,7 @@ Draw_BeginZoom(invScale, x, y + ST_INVENTORYHEIGHT);
a = i == selected? .5f : light / 2;

DGL_Color4f(light, light, light, a * iconAlpha);
M_DrawPatch(dpInvItemBox.id, x + slot * ST_INVSLOTWIDTH + ST_INVSLOTOFFX, y);
M_DrawPatch(dpInvItemBox, x + slot * ST_INVSLOTWIDTH + ST_INVSLOTOFFX, y);

if(i >= startSlot && i < endSlot)
{
Expand Down Expand Up @@ -396,7 +396,7 @@ Draw_BeginZoom(invScale, x, y + ST_INVENTORYHEIGHT);
}

DGL_Color4f(1, 1, 1, iconAlpha);
M_DrawPatch(dpInvSelectBox.id, x + selected * ST_INVSLOTWIDTH, y + ST_INVSELECTOFFY - BORDER);
M_DrawPatch(dpInvSelectBox, x + selected * ST_INVSLOTWIDTH, y + ST_INVSELECTOFFY - BORDER);

if(inv->numUsedSlots > maxVisSlots)
{
Expand All @@ -406,13 +406,13 @@ Draw_BeginZoom(invScale, x, y + ST_INVENTORYHEIGHT);
if(cfg.inventoryWrap || first != 0)
{
DGL_Color4f(1, 1, 1, iconAlpha);
M_DrawPatch(dpInvPageLeft[!(mapTime & 4)? 1 : 0].id, x - dpInvPageLeft[0].width - ARROW_RELXOFF, y + ARROW_YOFFSET);
M_DrawPatch2(dpInvPageLeft[!(mapTime & 4)? 1 : 0], x - ARROW_RELXOFF, y + ARROW_YOFFSET, DPF_ALIGN_RIGHT|DPF_ALIGN_TOP);
}

if(cfg.inventoryWrap || inv->numUsedSlots - first > numVisSlots)
{
DGL_Color4f(1, 1, 1, iconAlpha);
M_DrawPatch(dpInvPageRight[!(mapTime & 4)? 1 : 0].id, x + numVisSlots * ST_INVSLOTWIDTH + ARROW_RELXOFF + 1, y + ARROW_YOFFSET);
M_DrawPatch(dpInvPageRight[!(mapTime & 4)? 1 : 0], x + numVisSlots * ST_INVSLOTWIDTH + ARROW_RELXOFF + 1, y + ARROW_YOFFSET);
}

#undef ARROW_XOFFSET
Expand Down Expand Up @@ -478,15 +478,15 @@ void Hu_InventoryDraw2(int player, int x, int y, float alpha)
}

DGL_Color4f(1, 1, 1, alpha);
M_DrawPatch(dpInvSelectBox.id, x + cursor * ST_INVSLOTWIDTH, y + ST_INVSELECTOFFY - BORDER);
M_DrawPatch(dpInvSelectBox, x + cursor * ST_INVSLOTWIDTH, y + ST_INVSELECTOFFY - BORDER);

if(inv->numUsedSlots > NUMVISINVSLOTS)
{
// Draw more left indicator.
if(cfg.inventoryWrap || first != 0)
{
DGL_Color4f(1, 1, 1, alpha);
M_DrawPatch(dpInvPageLeft[!(mapTime & 4)? 1 : 0].id,
M_DrawPatch(dpInvPageLeft[!(mapTime & 4)? 1 : 0],
#if __JHEXEN__
42, 163
#else
Expand All @@ -499,7 +499,7 @@ void Hu_InventoryDraw2(int player, int x, int y, float alpha)
if(cfg.inventoryWrap || inv->numUsedSlots - first > NUMVISINVSLOTS)
{
DGL_Color4f(1, 1, 1, alpha);
M_DrawPatch(dpInvPageRight[!(mapTime & 4)? 1 : 0].id, 269,
M_DrawPatch(dpInvPageRight[!(mapTime & 4)? 1 : 0], 269,
#if __JHEXEN__
163
#else
Expand Down
4 changes: 2 additions & 2 deletions doomsday/plugins/common/src/hu_log.c
Expand Up @@ -370,7 +370,7 @@ void Hu_LogDrawer(int player, float textAlpha, float iconAlpha,
DGL_MatrixMode(DGL_PROJECTION);
DGL_Translatef(0, yOffset, 0);

textFlags = DTF_NO_EFFECTS | ((cfg.msgAlign == 0)? DTF_ALIGN_LEFT : (cfg.msgAlign == 2)? DTF_ALIGN_RIGHT : 0);
textFlags = DTF_ALIGN_TOP|DTF_NO_EFFECTS | ((cfg.msgAlign == 0)? DTF_ALIGN_LEFT : (cfg.msgAlign == 2)? DTF_ALIGN_RIGHT : 0);
y = 0;
for(i = 0; i < numVisible; ++i)
{
Expand Down Expand Up @@ -854,7 +854,7 @@ void Chat_Drawer(int player, float textAlpha, float iconAlpha,
if(cfg.msgAlign == 2)
xOffset = -M_CharWidth('_', GF_FONTA);
}
textFlags = DTF_NO_EFFECTS | ((cfg.msgAlign == 0)? DTF_ALIGN_LEFT : (cfg.msgAlign == 2)? DTF_ALIGN_RIGHT : 0);
textFlags = DTF_ALIGN_TOP|DTF_NO_EFFECTS | ((cfg.msgAlign == 0)? DTF_ALIGN_LEFT : (cfg.msgAlign == 2)? DTF_ALIGN_RIGHT : 0);
WI_DrawParamText(str, xOffset, 0, GF_FONTA, textFlags, cfg.hudColor[CR], cfg.hudColor[CG], cfg.hudColor[CB], textAlpha, false);
*drawnWidth = M_TextWidth(chat->buffer.l.l, GF_FONTA) + M_CharWidth('_', GF_FONTA);
*drawnHeight = MAX_OF(M_TextHeight(chat->buffer.l.l, GF_FONTA), M_CharHeight('_', GF_FONTA));
Expand Down

0 comments on commit 923d383

Please sign in to comment.