Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Before *iconwidget can be in libcommon, serious refactoring is needed
- Loading branch information
1 parent
8e23100
commit 0ab9473
Showing
8 changed files
with
288 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
51 changes: 51 additions & 0 deletions
51
doomsday/apps/plugins/doom64/include/hud/widgets/armoriconwidget.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** @file armoriconwidget.h GUI widget for -. | ||
* | ||
* @authors Copyright © 2005-2014 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* @authors Copyright © 2005-2015 Daniel Swanson <danij@dengine.net> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA</small> | ||
*/ | ||
|
||
#if defined(__JHEXEN__) || defined(__JHERETIC__) | ||
# define LIBCOMMON_UI_ARMORICONWIDGET_H | ||
#endif | ||
|
||
#ifndef LIBCOMMON_UI_ARMORICONWIDGET_H | ||
#define LIBCOMMON_UI_ARMORICONWIDGET_H | ||
|
||
#include "hud/hudwidget.h" | ||
|
||
/** | ||
* @ingroup ui | ||
*/ | ||
class guidata_armoricon_t : public HudWidget | ||
{ | ||
public: | ||
guidata_armoricon_t(de::dint player, int sprite1, int sprite2); | ||
virtual ~guidata_armoricon_t(); | ||
|
||
void reset(); | ||
|
||
void tick(timespan_t elapsed); | ||
void updateGeometry(); | ||
void draw(de::Vector2i const &offset = de::Vector2i()) const; | ||
|
||
private: | ||
de::dint currentSprite = 0; | ||
int armorSprite1 = 0; | ||
int armorSprite2 = 0; | ||
}; | ||
|
||
#endif // LIBCOMMON_UI_ARMORICONWIDGET_H |
45 changes: 45 additions & 0 deletions
45
doomsday/apps/plugins/doom64/include/hud/widgets/healthiconwidget.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** @file healthiconwidget.h GUI widget for -. | ||
* | ||
* @authors Copyright © 2005-2014 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* @authors Copyright © 2005-2015 Daniel Swanson <danij@dengine.net> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA</small> | ||
*/ | ||
|
||
#ifndef LIBCOMMON_UI_HEALTHICONWIDGET_H | ||
#define LIBCOMMON_UI_HEALTHICONWIDGET_H | ||
|
||
#include "hud/hudwidget.h" | ||
|
||
/** | ||
* @ingroup ui | ||
*/ | ||
class guidata_healthicon_t : public HudWidget | ||
{ | ||
private: | ||
int iconSpriteId; | ||
|
||
public: | ||
guidata_healthicon_t(de::dint player, int sprite); | ||
virtual ~guidata_healthicon_t(); | ||
|
||
void reset(); | ||
|
||
void tick(timespan_t elapsed); | ||
void updateGeometry(); | ||
void draw(de::Vector2i const &offset = de::Vector2i()) const; | ||
}; | ||
|
||
#endif // LIBCOMMON_UI_HEALTHICONWIDGET_H |
100 changes: 100 additions & 0 deletions
100
doomsday/apps/plugins/doom64/src/hud/widgets/armoriconwidget.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** @file armoriconwidget.cpp GUI widget for -. | ||
* | ||
* @authors Copyright © 2005-2014 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* @authors Copyright © 2005-2015 Daniel Swanson <danij@dengine.net> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA</small> | ||
*/ | ||
|
||
#include "hud/widgets/armoriconwidget.h" | ||
|
||
#include "player.h" | ||
|
||
using namespace de; | ||
|
||
static void ArmorIcon_Draw(guidata_armoricon_t *icon, Point2Raw const *offset) | ||
{ | ||
DENG2_ASSERT(icon); | ||
icon->draw(offset? Vector2i(offset->xy) : Vector2i()); | ||
} | ||
|
||
static void ArmorIcon_UpdateGeometry(guidata_armoricon_t *icon) | ||
{ | ||
DENG2_ASSERT(icon); | ||
icon->updateGeometry(); | ||
} | ||
|
||
guidata_armoricon_t::guidata_armoricon_t(dint player, int sprite1, int sprite2) | ||
: HudWidget(function_cast<UpdateGeometryFunc>(ArmorIcon_UpdateGeometry), | ||
function_cast<DrawFunc>(ArmorIcon_Draw), | ||
player) | ||
{ | ||
this->armorSprite1 = sprite1; | ||
this->armorSprite2 = sprite2; | ||
} | ||
|
||
guidata_armoricon_t::~guidata_armoricon_t() | ||
{} | ||
|
||
void guidata_armoricon_t::reset() | ||
{ | ||
currentSprite = -1; | ||
} | ||
|
||
void guidata_armoricon_t::tick(timespan_t /*elapsed*/) | ||
{ | ||
if(Pause_IsPaused() || !DD_IsSharpTick()) return; | ||
|
||
player_t const *plr = &players[player()]; | ||
currentSprite = (plr->armorType == 2 ? this->armorSprite2 : this->armorSprite1); | ||
} | ||
|
||
void guidata_armoricon_t::draw(Vector2i const &offset) const | ||
{ | ||
dfloat const iconOpacity = uiRendState->pageAlpha * cfg.common.hudIconAlpha; | ||
|
||
if(!cfg.hudShown[HUD_ARMOR]) return; | ||
if(ST_AutomapIsOpen(player()) && cfg.common.automapHudDisplay == 0) return; | ||
if(P_MobjIsCamera(players[player()].plr->mo) && Get(DD_PLAYBACK)) return; | ||
|
||
if(currentSprite < 0) return; | ||
|
||
DGL_MatrixMode(DGL_MODELVIEW); | ||
DGL_PushMatrix(); | ||
DGL_Translatef(offset.x, offset.y, 0); | ||
DGL_Scalef(cfg.common.hudScale, cfg.common.hudScale, 1); | ||
|
||
GUI_DrawSprite(currentSprite, 0, 0, HOT_TLEFT, 1, iconOpacity, false, nullptr, nullptr); | ||
|
||
DGL_MatrixMode(DGL_MODELVIEW); | ||
DGL_PopMatrix(); | ||
} | ||
|
||
void guidata_armoricon_t::updateGeometry() | ||
{ | ||
Rect_SetWidthHeight(&geometry(), 0, 0); | ||
|
||
if(!cfg.hudShown[HUD_ARMOR]) return; | ||
if(ST_AutomapIsOpen(player()) && cfg.common.automapHudDisplay == 0) return; | ||
if(P_MobjIsCamera(players[player()].plr->mo) && Get(DD_PLAYBACK)) return; | ||
|
||
if(currentSprite < 0) return; | ||
|
||
Size2Raw iconSize; | ||
GUI_SpriteSize(currentSprite, 1, &iconSize.width, &iconSize.height); | ||
iconSize.width *= cfg.common.hudScale; | ||
iconSize.height *= cfg.common.hudScale; | ||
Rect_SetWidthHeight(&geometry(), iconSize.width, iconSize.height); | ||
} |
88 changes: 88 additions & 0 deletions
88
doomsday/apps/plugins/doom64/src/hud/widgets/healthiconwidget.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/** @file healthiconwidget.cpp GUI widget for -. | ||
* | ||
* @authors Copyright © 2005-2014 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* @authors Copyright © 2005-2015 Daniel Swanson <danij@dengine.net> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. This program is distributed in the hope that it | ||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty | ||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | ||
* Public License for more details. You should have received a copy of the GNU | ||
* General Public License along with this program; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA</small> | ||
*/ | ||
|
||
#include "hud/widgets/healthiconwidget.h" | ||
|
||
#include "common.h" | ||
#include "p_actor.h" | ||
|
||
using namespace de; | ||
|
||
static void HealthIconWidget_Draw(guidata_healthicon_t *icon, Point2Raw const *offset) | ||
{ | ||
DENG2_ASSERT(icon); | ||
icon->draw(offset? Vector2i(offset->xy) : Vector2i()); | ||
} | ||
|
||
static void HealthIconWidget_UpdateGeometry(guidata_healthicon_t *icon) | ||
{ | ||
DENG2_ASSERT(icon); | ||
icon->updateGeometry(); | ||
} | ||
|
||
guidata_healthicon_t::guidata_healthicon_t(dint player, int sprite) | ||
: HudWidget(function_cast<UpdateGeometryFunc>(HealthIconWidget_UpdateGeometry), | ||
function_cast<DrawFunc>(HealthIconWidget_Draw), | ||
player) | ||
{ | ||
this->iconSpriteId = sprite; | ||
} | ||
|
||
guidata_healthicon_t::~guidata_healthicon_t() | ||
{} | ||
|
||
void guidata_healthicon_t::tick(timespan_t /*elapsed*/) | ||
{ | ||
// Nothing to do. | ||
} | ||
|
||
void guidata_healthicon_t::draw(Vector2i const &offset) const | ||
{ | ||
dfloat const iconOpacity = ::uiRendState->pageAlpha * ::cfg.common.hudIconAlpha; | ||
|
||
if(!::cfg.hudShown[HUD_HEALTH]) return; | ||
if(ST_AutomapIsOpen(player()) && ::cfg.common.automapHudDisplay == 0) return; | ||
if(P_MobjIsCamera(::players[player()].plr->mo) && Get(DD_PLAYBACK)) return; | ||
|
||
DGL_MatrixMode(DGL_MODELVIEW); | ||
DGL_PushMatrix(); | ||
DGL_Translatef(offset.x, offset.y, 0); | ||
DGL_Scalef(::cfg.common.hudScale, ::cfg.common.hudScale, 1); | ||
|
||
GUI_DrawSprite(this->iconSpriteId, 0, 0, HOT_TLEFT, 1, iconOpacity, false, nullptr, nullptr); | ||
|
||
DGL_MatrixMode(DGL_MODELVIEW); | ||
DGL_PopMatrix(); | ||
} | ||
|
||
void guidata_healthicon_t::updateGeometry() | ||
{ | ||
Rect_SetWidthHeight(&geometry(), 0, 0); | ||
|
||
if(!::cfg.hudShown[HUD_HEALTH]) return; | ||
if(ST_AutomapIsOpen(player()) && ::cfg.common.automapHudDisplay == 0) return; | ||
if(P_MobjIsCamera(::players[player()].plr->mo) && Get(DD_PLAYBACK)) return; | ||
|
||
Size2Raw iconSize; | ||
GUI_SpriteSize(this->iconSpriteId, 1, &iconSize.width, &iconSize.height); | ||
iconSize.width *= ::cfg.common.hudScale; | ||
iconSize.height *= ::cfg.common.hudScale; | ||
Rect_SetWidthHeight(&geometry(), iconSize.width, iconSize.height); | ||
} |