Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Refactor|libcommon: Replaced WI_DrawPatch*() with a single C++ function
  • Loading branch information
danij-deng committed Jul 10, 2014
1 parent 60ede52 commit 479430d
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 251 deletions.
38 changes: 17 additions & 21 deletions doomsday/plugins/common/include/hu_stuff.h
Expand Up @@ -27,6 +27,10 @@
#include "doomsday.h"
#include "gl_drawpatch.h"

#ifdef __cplusplus
# include <de/Vector>
#endif

DENG_EXTERN_C patchid_t *pMapNames; // Name graphics of each map.
DENG_EXTERN_C uint pMapNamesSize;

Expand Down Expand Up @@ -164,6 +168,15 @@ const char* Hu_FindPatchReplacementString(patchid_t patchId, int flags);
const char* Hu_ChoosePatchReplacement2(patchreplacemode_t replaceMode, patchid_t patchId, const char* text);
const char* Hu_ChoosePatchReplacement(patchreplacemode_t replaceMode, patchid_t patchId);

/**
* Misc specialised elements:
*/

void M_DrawGlowBar(const float a[2], const float b[2], float thickness, dd_bool left, dd_bool right, dd_bool caps, float red, float green, float blue, float alpha);

#ifdef __cplusplus
} // extern "C"

/**
* Implements patch replacement.
*
Expand All @@ -175,25 +188,8 @@ const char* Hu_ChoosePatchReplacement(patchreplacemode_t replaceMode, patchid_t
* @param patchFlags @ref drawPatchFlags
* @param textFlags @ref drawTextFlags
*/
void WI_DrawPatch3(patchid_t patchId, const char* replacement, const Point2Raw* origin, int alignFlags, int patchFlags, short textFlags);
void WI_DrawPatch2(patchid_t patchId, const char* replacement, const Point2Raw* origin, int alignFlags);
void WI_DrawPatch(patchid_t patchId, const char* replacement, const Point2Raw* origin);

/**
* Same as @a WI_DrawPatch except origin is specified with separate xy coordinates.
*/
void WI_DrawPatchXY3(patchid_t patchId, const char* replacement, int x, int y, int alignFlags, int patchFlags, short textFlags);
void WI_DrawPatchXY2(patchid_t patchId, const char* replacement, int x, int y, int alignFlags);
void WI_DrawPatchXY(patchid_t patchId, const char* replacement, int x, int y);

/**
* Misc specialised elements:
*/

void M_DrawGlowBar(const float a[2], const float b[2], float thickness, dd_bool left, dd_bool right, dd_bool caps, float red, float green, float blue, float alpha);

#ifdef __cplusplus
} // extern "C"
#endif
void WI_DrawPatch(patchid_t patchId, char const *replacement, de::Vector2i const &origin = de::Vector2i(0, 0),
int alignFlags = ALIGN_TOPLEFT, int patchFlags = 0, short textFlags = 0);

#endif /* LIBCOMMON_HU_STUFF_H */
#endif // __cplusplus
#endif // LIBCOMMON_HU_STUFF_H
6 changes: 4 additions & 2 deletions doomsday/plugins/common/src/hu_lib.cpp
Expand Up @@ -1784,7 +1784,8 @@ void MNText_Drawer(mn_object_t *ob, Point2Raw const *origin)
}

DGL_Enable(DGL_TEXTURE_2D);
WI_DrawPatch3(*txt->patch, replacement, origin, ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));
WI_DrawPatch(*txt->patch, replacement, de::Vector2i(origin->x, origin->y),
ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));
DGL_Disable(DGL_TEXTURE_2D);

return;
Expand Down Expand Up @@ -2579,7 +2580,8 @@ void MNButton_Drawer(mn_object_t *ob, Point2Raw const *origin)
}

DGL_Enable(DGL_TEXTURE_2D);
WI_DrawPatch3(*btn->patch, replacement, origin, ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));
WI_DrawPatch(*btn->patch, replacement, de::Vector2i(origin->x, origin->y),
ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));
DGL_Disable(DGL_TEXTURE_2D);

return;
Expand Down
28 changes: 14 additions & 14 deletions doomsday/plugins/common/src/hu_menu.cpp
Expand Up @@ -5510,8 +5510,8 @@ void Hu_MenuDrawMainPage(mn_page_t * /*page*/, Point2Raw const *origin)
FR_SetFont(FID(GF_FONTB));
FR_SetColorAndAlpha(1, 1, 1, mnRendState->pageAlpha);

WI_DrawPatchXY3(pMainTitle, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.menuPatchReplaceMode), pMainTitle),
origin->x + TITLEOFFSET_X, origin->y + TITLEOFFSET_Y, ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));
WI_DrawPatch(pMainTitle, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.menuPatchReplaceMode), pMainTitle),
de::Vector2i(origin->x + TITLEOFFSET_X, origin->y + TITLEOFFSET_Y), ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));
#if __JHEXEN__
GL_DrawPatchXY(pBullWithFire[(frame + 2) % 7], origin->x - 73, origin->y + 24);
GL_DrawPatchXY(pBullWithFire[frame], origin->x + 168, origin->y + 24);
Expand Down Expand Up @@ -5672,8 +5672,8 @@ void Hu_MenuDrawEpisodePage(mn_page_t *page, Point2Raw const *origin)
FR_SetColorv(cfg.menuTextColors[0]);
FR_SetAlpha(mnRendState->pageAlpha);

WI_DrawPatchXY3(pEpisode, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.menuPatchReplaceMode), pEpisode),
origin->x + 7, origin->y - 25, ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));
WI_DrawPatch(pEpisode, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.menuPatchReplaceMode), pEpisode),
de::Vector2i(origin->x + 7, origin->y - 25), ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));

DGL_Disable(DGL_TEXTURE_2D);
#endif
Expand All @@ -5688,10 +5688,10 @@ void Hu_MenuDrawSkillPage(mn_page_t * /*page*/, Point2Raw const *origin)
FR_SetFont(FID(GF_FONTB));
FR_SetColorAndAlpha(cfg.menuTextColors[0][CR], cfg.menuTextColors[0][CG], cfg.menuTextColors[0][CB], mnRendState->pageAlpha);

WI_DrawPatchXY3(pNewGame, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.menuPatchReplaceMode), pNewGame),
origin->x + 48, origin->y - 49, ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));
WI_DrawPatchXY3(pSkill, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.menuPatchReplaceMode), pSkill),
origin->x + 6, origin->y - 25, ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));
WI_DrawPatch(pNewGame, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.menuPatchReplaceMode), pNewGame),
de::Vector2i(origin->x + 48, origin->y - 49), ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));
WI_DrawPatch(pSkill, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.menuPatchReplaceMode), pSkill),
de::Vector2i(origin->x + 6, origin->y - 25), ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));

DGL_Disable(DGL_TEXTURE_2D);
#elif __JHEXEN__
Expand Down Expand Up @@ -5940,8 +5940,8 @@ void Hu_MenuDrawLoadGamePage(mn_page_t * /*page*/, Point2Raw const *origin)
#if __JHERETIC__ || __JHEXEN__
FR_DrawTextXY3("Load Game", SCREENWIDTH/2, origin->y-20, ALIGN_TOP, MN_MergeMenuEffectWithDrawTextFlags(0));
#else
WI_DrawPatchXY3(pLoadGame, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.menuPatchReplaceMode), pLoadGame),
origin->x - 8, origin->y - 26, ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));
WI_DrawPatch(pLoadGame, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.menuPatchReplaceMode), pLoadGame),
de::Vector2i(origin->x - 8, origin->y - 26), ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));
#endif
DGL_Disable(DGL_TEXTURE_2D);

Expand All @@ -5961,8 +5961,8 @@ void Hu_MenuDrawSaveGamePage(mn_page_t * /*page*/, Point2Raw const *origin)
FR_SetFont(FID(GF_FONTB));
FR_SetColorAndAlpha(cfg.menuTextColors[0][CR], cfg.menuTextColors[0][CG], cfg.menuTextColors[0][CB], mnRendState->pageAlpha);

WI_DrawPatchXY3(pSaveGame, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.menuPatchReplaceMode), pSaveGame),
origin->x - 8, origin->y - 26, ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));
WI_DrawPatch(pSaveGame, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.menuPatchReplaceMode), pSaveGame),
de::Vector2i(origin->x - 8, origin->y - 26), ALIGN_TOPLEFT, 0, MN_MergeMenuEffectWithDrawTextFlags(0));

DGL_Disable(DGL_TEXTURE_2D);
#endif
Expand Down Expand Up @@ -5992,8 +5992,8 @@ void Hu_MenuDrawOptionsPage(mn_page_t * /*page*/, Point2Raw const *origin)
FR_SetFont(FID(GF_FONTB));
FR_SetColorAndAlpha(cfg.menuTextColors[0][CR], cfg.menuTextColors[0][CG], cfg.menuTextColors[0][CB], mnRendState->pageAlpha);

WI_DrawPatchXY3(pOptionsTitle, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.menuPatchReplaceMode), pOptionsTitle),
origin->x + 42, origin->y - 20, ALIGN_TOP, 0, MN_MergeMenuEffectWithDrawTextFlags(0));
WI_DrawPatch(pOptionsTitle, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.menuPatchReplaceMode), pOptionsTitle),
de::Vector2i(origin->x + 42, origin->y - 20), ALIGN_TOP, 0, MN_MergeMenuEffectWithDrawTextFlags(0));

DGL_Disable(DGL_TEXTURE_2D);
#endif
Expand Down
43 changes: 8 additions & 35 deletions doomsday/plugins/common/src/hu_stuff.cpp
Expand Up @@ -1186,46 +1186,18 @@ const char* Hu_ChoosePatchReplacement(patchreplacemode_t mode, patchid_t patchId
return Hu_ChoosePatchReplacement2(mode, patchId, NULL);
}

void WI_DrawPatch3(patchid_t patchId, const char* replacement, const Point2Raw* origin,
void WI_DrawPatch(patchid_t patchId, char const *replacement, de::Vector2i const &origin,
int alignFlags, int patchFlags, short textFlags)
{
Point2Raw const originAsPoint2Raw(origin.x, origin.y);
if(replacement && replacement[0])
{
// Use the replacement string.
FR_DrawText3(replacement, origin, alignFlags, textFlags);
FR_DrawText3(replacement, &originAsPoint2Raw, alignFlags, textFlags);
return;
}
// Use the original patch.
GL_DrawPatch3(patchId, origin, alignFlags, patchFlags);
}

void WI_DrawPatch2(patchid_t patchId, const char* replacement, const Point2Raw* origin, int alignFlags)
{
WI_DrawPatch3(patchId, replacement, origin, alignFlags, 0, 0);
}

void WI_DrawPatch(patchid_t patchId, const char* replacement, const Point2Raw* origin)
{
WI_DrawPatch2(patchId, replacement, origin, ALIGN_TOPLEFT);
}

void WI_DrawPatchXY3(patchid_t patchId, const char* replacement, int x, int y, int alignFlags,
int patchFlags, short textFlags)
{
Point2Raw origin;
origin.x = x;
origin.y = y;
WI_DrawPatch3(patchId, replacement, &origin, alignFlags, patchFlags, textFlags);
}

void WI_DrawPatchXY2(patchid_t patchId, const char* replacement, int x, int y, int alignFlags)
{
WI_DrawPatchXY3(patchId, replacement, x, y, alignFlags, 0, 0);
}

void WI_DrawPatchXY(patchid_t patchId, const char* replacement, int x, int y)
{
WI_DrawPatchXY2(patchId, replacement, x, y, ALIGN_TOPLEFT);
GL_DrawPatch3(patchId, &originAsPoint2Raw, alignFlags, patchFlags);
}

void Draw_BeginZoom(float s, float originX, float originY)
Expand Down Expand Up @@ -1419,7 +1391,8 @@ void Hu_Drawer(void)
FR_LoadDefaultAttrib();
FR_SetLeading(0);

WI_DrawPatchXY3(m_pause, Hu_ChoosePatchReplacement(PRM_ALLOW_TEXT, m_pause), 0, 0, ALIGN_TOP, DPF_NO_OFFSET, 0);
WI_DrawPatch(m_pause, Hu_ChoosePatchReplacement(PRM_ALLOW_TEXT, m_pause),
de::Vector2i(), ALIGN_TOP, DPF_NO_OFFSET, 0);

DGL_Disable(DGL_TEXTURE_2D);

Expand Down Expand Up @@ -1514,8 +1487,8 @@ void Hu_DrawMapTitle(float alpha, dd_bool mapIdInsteadOfAuthor)

#if __JDOOM__ || __JDOOM64__
patchid_t patchId = G_MapTitlePatch(); // current map
WI_DrawPatchXY3(patchId, Hu_ChoosePatchReplacement2(PRM_ALLOW_TEXT, patchId, title.toUtf8().constData()),
0, 0, ALIGN_TOP, 0, DTF_ONLY_SHADOW);
WI_DrawPatch(patchId, Hu_ChoosePatchReplacement2(PRM_ALLOW_TEXT, patchId, title.toUtf8().constData()),
de::Vector2i(), ALIGN_TOP, 0, DTF_ONLY_SHADOW);

// Following line of text placed according to patch height.
y += Hu_MapTitleFirstLineHeight();
Expand Down
22 changes: 12 additions & 10 deletions doomsday/plugins/doom/src/st_stuff.cpp
Expand Up @@ -46,6 +46,8 @@
#include "r_common.h"
#include "am_map.h"

using namespace de;

// N/256*100% probability
// that the normal face state will change
#define ST_FACEPROBABILITY (96)
Expand Down Expand Up @@ -1493,16 +1495,16 @@ void WeaponSlot_Drawer(uiwidget_t *ob, Point2Raw const *offset)
#define ORIGINX (-ST_WIDTH/2)
#define ORIGINY (-ST_HEIGHT)

static Point2Raw const elements[] = {
Point2Raw( ORIGINX+ST_ARMSX, ORIGINY+ST_ARMSY ),
Point2Raw( ORIGINX+ST_ARMSX + ST_ARMSXSPACE, ORIGINY+ST_ARMSY ),
Point2Raw( ORIGINX+ST_ARMSX + ST_ARMSXSPACE*2, ORIGINY+ST_ARMSY ),
Point2Raw( ORIGINX+ST_ARMSX, ORIGINY+ST_ARMSY + ST_ARMSYSPACE ),
Point2Raw( ORIGINX+ST_ARMSX + ST_ARMSXSPACE, ORIGINY+ST_ARMSY + ST_ARMSYSPACE ),
Point2Raw( ORIGINX+ST_ARMSX + ST_ARMSXSPACE*2, ORIGINY+ST_ARMSY + ST_ARMSYSPACE ),
static Vector2i const elements[] = {
Vector2i( ORIGINX+ST_ARMSX, ORIGINY+ST_ARMSY ),
Vector2i( ORIGINX+ST_ARMSX + ST_ARMSXSPACE, ORIGINY+ST_ARMSY ),
Vector2i( ORIGINX+ST_ARMSX + ST_ARMSXSPACE*2, ORIGINY+ST_ARMSY ),
Vector2i( ORIGINX+ST_ARMSX, ORIGINY+ST_ARMSY + ST_ARMSYSPACE ),
Vector2i( ORIGINX+ST_ARMSX + ST_ARMSXSPACE, ORIGINY+ST_ARMSY + ST_ARMSYSPACE ),
Vector2i( ORIGINX+ST_ARMSX + ST_ARMSXSPACE*2, ORIGINY+ST_ARMSY + ST_ARMSYSPACE ),
};
guidata_weaponslot_t *wpns = (guidata_weaponslot_t *)ob->typedata;
Point2Raw const *element = &elements[wpns->slot-1];
Vector2i const &element = elements[wpns->slot-1];
hudstate_t const *hud = &hudStates[ob->player];
int yOffset = ST_HEIGHT * (1 - hud->showBar);
int fullscreen = headupDisplayMode(ob->player);
Expand Down Expand Up @@ -1531,8 +1533,8 @@ void WeaponSlot_Drawer(uiwidget_t *ob, Point2Raw const *offset)
{
FR_SetColorAndAlpha(defFontRGB2[CR], defFontRGB2[CG], defFontRGB2[CB], textAlpha);
}
WI_DrawPatch3(wpns->patchId, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.hudPatchReplaceMode), wpns->patchId),
element, ALIGN_TOPLEFT, 0, DTF_NO_EFFECTS);
WI_DrawPatch(wpns->patchId, Hu_ChoosePatchReplacement(patchreplacemode_t(cfg.hudPatchReplaceMode), wpns->patchId),
element, ALIGN_TOPLEFT, 0, DTF_NO_EFFECTS);

DGL_Disable(DGL_TEXTURE_2D);
DGL_MatrixMode(DGL_MODELVIEW);
Expand Down

0 comments on commit 479430d

Please sign in to comment.