summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-03-30 00:07:54 +0300
committerAndrei Karas <akaras@inbox.ru>2014-03-30 00:07:54 +0300
commita93d1e06f928f6e4e1c7f3c58ddb7ae3676c1c63 (patch)
tree2d85d112997176e9ab765e638b0e7f2e16677b83 /src
parent5c83a96b8ad85ad0562542b9720a0df6c5fb550c (diff)
parent8983700f6c8cc6496626ed3af235e1ec31fe5501 (diff)
downloadplus-a93d1e06f928f6e4e1c7f3c58ddb7ae3676c1c63.tar.gz
plus-a93d1e06f928f6e4e1c7f3c58ddb7ae3676c1c63.tar.bz2
plus-a93d1e06f928f6e4e1c7f3c58ddb7ae3676c1c63.tar.xz
plus-a93d1e06f928f6e4e1c7f3c58ddb7ae3676c1c63.zip
Merge branch 'master' into stable
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Makefile.am3
-rw-r--r--src/actormanager.cpp2
-rw-r--r--src/animatedsprite.cpp5
-rw-r--r--src/avatar.cpp37
-rw-r--r--src/avatar.h7
-rw-r--r--src/being/actorsprite.cpp17
-rw-r--r--src/being/actorsprite.h11
-rw-r--r--src/being/being.cpp65
-rw-r--r--src/being/compoundsprite.cpp12
-rw-r--r--src/being/localplayer.cpp20
-rw-r--r--src/being/localplayer.h1
-rw-r--r--src/being/playerinfo.cpp8
-rw-r--r--src/beingequipbackend.cpp12
-rw-r--r--src/client.cpp98
-rw-r--r--src/commands.cpp10
-rw-r--r--src/commands.h3
-rw-r--r--src/configuration.cpp4
-rw-r--r--src/defaults.cpp3
-rw-r--r--src/depricatedevent.cpp5
-rw-r--r--src/game.cpp92
-rw-r--r--src/gui/cliprect.cpp13
-rw-r--r--src/gui/color.cpp34
-rw-r--r--src/gui/color.h11
-rw-r--r--src/gui/focushandler.cpp45
-rw-r--r--src/gui/focushandler.h36
-rw-r--r--src/gui/font.cpp6
-rw-r--r--src/gui/font.h2
-rw-r--r--src/gui/gui.cpp315
-rw-r--r--src/gui/gui.h24
-rw-r--r--src/gui/palette.h4
-rw-r--r--src/gui/popups/itempopup.h2
-rw-r--r--src/gui/popups/popupmenu.cpp63
-rw-r--r--src/gui/popups/popupmenu.h2
-rw-r--r--src/gui/popups/speechbubble.h4
-rw-r--r--src/gui/popups/spellpopup.h2
-rw-r--r--src/gui/popups/textpopup.h2
-rw-r--r--src/gui/rect.cpp14
-rw-r--r--src/gui/rect.h13
-rw-r--r--src/gui/sdlinput.cpp19
-rw-r--r--src/gui/sdlinput.h6
-rw-r--r--src/gui/theme.cpp95
-rw-r--r--src/gui/theme.h67
-rw-r--r--src/gui/userpalette.cpp11
-rw-r--r--src/gui/userpalette.h2
-rw-r--r--src/gui/viewport.cpp88
-rw-r--r--src/gui/viewport.h44
-rw-r--r--src/gui/widgets/avatarlistbox.cpp16
-rw-r--r--src/gui/widgets/basiccontainer.cpp179
-rw-r--r--src/gui/widgets/basiccontainer.h38
-rw-r--r--src/gui/widgets/basiccontainer2.cpp5
-rw-r--r--src/gui/widgets/basiccontainer2.h11
-rw-r--r--src/gui/widgets/browserbox.cpp9
-rw-r--r--src/gui/widgets/browserbox.h2
-rw-r--r--src/gui/widgets/browserbox_unittest.cc2
-rw-r--r--src/gui/widgets/button.cpp53
-rw-r--r--src/gui/widgets/button.h14
-rw-r--r--src/gui/widgets/characterdisplay.cpp4
-rw-r--r--src/gui/widgets/checkbox.cpp28
-rw-r--r--src/gui/widgets/checkbox.h6
-rw-r--r--src/gui/widgets/desktop.cpp5
-rw-r--r--src/gui/widgets/dropdown.cpp53
-rw-r--r--src/gui/widgets/dropdown.h12
-rw-r--r--src/gui/widgets/dropshortcutcontainer.cpp8
-rw-r--r--src/gui/widgets/emotepage.cpp11
-rw-r--r--src/gui/widgets/emotepage.h2
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp1
-rw-r--r--src/gui/widgets/guitable.cpp64
-rw-r--r--src/gui/widgets/guitable.h12
-rw-r--r--src/gui/widgets/icon.cpp2
-rw-r--r--src/gui/widgets/itemcontainer.cpp16
-rw-r--r--src/gui/widgets/itemlinkhandler.cpp5
-rw-r--r--src/gui/widgets/itemshortcutcontainer.cpp10
-rw-r--r--src/gui/widgets/label.cpp3
-rw-r--r--src/gui/widgets/layout.cpp7
-rw-r--r--src/gui/widgets/listbox.cpp33
-rw-r--r--src/gui/widgets/listbox.h6
-rw-r--r--src/gui/widgets/playerbox.cpp2
-rw-r--r--src/gui/widgets/popup.cpp7
-rw-r--r--src/gui/widgets/popuplist.cpp13
-rw-r--r--src/gui/widgets/popuplist.h4
-rw-r--r--src/gui/widgets/progressbar.cpp9
-rw-r--r--src/gui/widgets/progressindicator.cpp5
-rw-r--r--src/gui/widgets/radiobutton.cpp20
-rw-r--r--src/gui/widgets/radiobutton.h6
-rw-r--r--src/gui/widgets/scrollarea.cpp40
-rw-r--r--src/gui/widgets/scrollarea.h4
-rw-r--r--src/gui/widgets/shoplistbox.cpp10
-rw-r--r--src/gui/widgets/shoplistbox.h4
-rw-r--r--src/gui/widgets/shortcutcontainer.cpp6
-rw-r--r--src/gui/widgets/skillinfo.h1
-rw-r--r--src/gui/widgets/slider.cpp48
-rw-r--r--src/gui/widgets/slider.h10
-rw-r--r--src/gui/widgets/sliderlist.cpp9
-rw-r--r--src/gui/widgets/sliderlist.h4
-rw-r--r--src/gui/widgets/spellshortcutcontainer.cpp7
-rw-r--r--src/gui/widgets/tabbedarea.cpp38
-rw-r--r--src/gui/widgets/tabbedarea.h4
-rw-r--r--src/gui/widgets/tabs/chattab.cpp7
-rw-r--r--src/gui/widgets/tabs/setup_audio.cpp8
-rw-r--r--src/gui/widgets/tabs/setup_colors.cpp11
-rw-r--r--src/gui/widgets/tabs/setup_input.cpp21
-rw-r--r--src/gui/widgets/tabs/setup_joystick.cpp4
-rw-r--r--src/gui/widgets/tabs/setup_other.cpp18
-rw-r--r--src/gui/widgets/tabs/setup_perfomance.cpp4
-rw-r--r--src/gui/widgets/tabs/setup_players.cpp2
-rw-r--r--src/gui/widgets/tabs/setup_relations.cpp14
-rw-r--r--src/gui/widgets/tabs/setup_theme.cpp28
-rw-r--r--src/gui/widgets/tabs/setup_touch.cpp10
-rw-r--r--src/gui/widgets/tabs/setup_video.cpp13
-rw-r--r--src/gui/widgets/tabs/setup_visual.cpp19
-rw-r--r--src/gui/widgets/tabs/setuptabscroll.cpp7
-rw-r--r--src/gui/widgets/tabs/tab.cpp18
-rw-r--r--src/gui/widgets/tabs/tab.h4
-rw-r--r--src/gui/widgets/tabstrip.cpp6
-rw-r--r--src/gui/widgets/textbox.cpp22
-rw-r--r--src/gui/widgets/textbox.h6
-rw-r--r--src/gui/widgets/textfield.cpp40
-rw-r--r--src/gui/widgets/textfield.h6
-rw-r--r--src/gui/widgets/textpreview.cpp5
-rw-r--r--src/gui/widgets/widget.cpp244
-rw-r--r--src/gui/widgets/widget.h187
-rw-r--r--src/gui/widgets/widget2.h8
-rw-r--r--src/gui/widgets/window.cpp35
-rw-r--r--src/gui/widgets/window.h3
-rw-r--r--src/gui/widgets/windowcontainer.cpp34
-rw-r--r--src/gui/windowmenu.cpp30
-rw-r--r--src/gui/windowmenu.h2
-rw-r--r--src/gui/windows/buydialog.cpp5
-rw-r--r--src/gui/windows/changeemaildialog.cpp4
-rw-r--r--src/gui/windows/changepassworddialog.cpp4
-rw-r--r--src/gui/windows/charcreatedialog.cpp18
-rw-r--r--src/gui/windows/charcreatedialog.h2
-rw-r--r--src/gui/windows/charselectdialog.cpp18
-rw-r--r--src/gui/windows/charselectdialog.h2
-rw-r--r--src/gui/windows/chatwindow.cpp22
-rw-r--r--src/gui/windows/chatwindow.h4
-rw-r--r--src/gui/windows/debugwindow.cpp10
-rw-r--r--src/gui/windows/editserverdialog.cpp6
-rw-r--r--src/gui/windows/editserverdialog.h2
-rw-r--r--src/gui/windows/emotewindow.cpp22
-rw-r--r--src/gui/windows/equipmentwindow.cpp38
-rw-r--r--src/gui/windows/equipmentwindow.h2
-rw-r--r--src/gui/windows/inventorywindow.cpp13
-rw-r--r--src/gui/windows/itemamountwindow.cpp6
-rw-r--r--src/gui/windows/itemamountwindow.h2
-rw-r--r--src/gui/windows/logindialog.cpp12
-rw-r--r--src/gui/windows/logindialog.h2
-rw-r--r--src/gui/windows/minimap.cpp4
-rw-r--r--src/gui/windows/ministatuswindow.cpp33
-rw-r--r--src/gui/windows/ministatuswindow.h6
-rw-r--r--src/gui/windows/npcdialog.cpp60
-rw-r--r--src/gui/windows/questswindow.cpp7
-rw-r--r--src/gui/windows/quitdialog.cpp16
-rw-r--r--src/gui/windows/quitdialog.h2
-rw-r--r--src/gui/windows/registerdialog.cpp10
-rw-r--r--src/gui/windows/registerdialog.h2
-rw-r--r--src/gui/windows/selldialog.cpp4
-rw-r--r--src/gui/windows/serverdialog.cpp36
-rw-r--r--src/gui/windows/serverdialog.h4
-rw-r--r--src/gui/windows/setupwindow.cpp4
-rw-r--r--src/gui/windows/shopwindow.cpp8
-rw-r--r--src/gui/windows/shortcutwindow.cpp8
-rw-r--r--src/gui/windows/skilldialog.cpp11
-rw-r--r--src/gui/windows/socialwindow.cpp83
-rw-r--r--src/gui/windows/statuswindow.cpp41
-rw-r--r--src/gui/windows/statuswindow.h6
-rw-r--r--src/gui/windows/textcommandeditor.cpp10
-rw-r--r--src/gui/windows/unregisterdialog.cpp4
-rw-r--r--src/gui/windows/updaterwindow.cpp8
-rw-r--r--src/gui/windows/updaterwindow.h2
-rw-r--r--src/gui/windows/worldselectdialog.cpp8
-rw-r--r--src/gui/windows/worldselectdialog.h2
-rw-r--r--src/guildmanager.cpp13
-rw-r--r--src/input/keyboarddata.h4
-rw-r--r--src/inventory.cpp4
-rw-r--r--src/item.cpp9
-rw-r--r--src/item.h4
-rw-r--r--src/listeners/keylistener.h8
-rw-r--r--src/listeners/mouselistener.h34
-rw-r--r--src/localconsts.h3
-rw-r--r--src/main.cpp4
-rw-r--r--src/main.h4
-rw-r--r--src/map.cpp17
-rw-r--r--src/maplayer.cpp6
-rw-r--r--src/net/charserverhandler.h5
-rw-r--r--src/net/ea/chathandler.cpp1
-rw-r--r--src/net/ea/guildhandler.cpp11
-rw-r--r--src/net/ea/inventoryhandler.cpp11
-rw-r--r--src/net/ea/partyhandler.cpp8
-rw-r--r--src/net/eathena/generalhandler.cpp10
-rw-r--r--src/net/eathena/network.cpp5
-rw-r--r--src/net/tmwa/generalhandler.cpp10
-rw-r--r--src/net/tmwa/network.cpp5
-rw-r--r--src/particle/animationparticle.cpp5
-rw-r--r--src/particle/particlecontainer.cpp7
-rw-r--r--src/particle/rotationalparticle.cpp5
-rw-r--r--src/particle/textparticle.cpp2
-rw-r--r--src/render/graphics.cpp10
-rw-r--r--src/render/graphics.h11
-rw-r--r--src/render/graphicsdef.hpp4
-rw-r--r--src/render/mobileopenglgraphics.cpp16
-rw-r--r--src/render/normalopenglgraphics.cpp22
-rw-r--r--src/render/nullopenglgraphics.cpp13
-rw-r--r--src/render/safeopenglgraphics.cpp4
-rw-r--r--src/render/sdl2graphics.cpp4
-rw-r--r--src/render/sdl2softwaregraphics.cpp4
-rw-r--r--src/render/sdlgraphics.cpp4
-rw-r--r--src/render/surfacegraphics.h4
-rw-r--r--src/resources/atlasmanager.cpp2
-rw-r--r--src/resources/beinginfo.cpp7
-rw-r--r--src/resources/db/itemdb.cpp4
-rw-r--r--src/resources/dye.cpp7
-rw-r--r--src/resources/mapreader.cpp13
-rw-r--r--src/resources/resourcemanager.cpp4
-rw-r--r--src/shopitem.cpp1
-rw-r--r--src/simpleanimation.cpp5
-rw-r--r--src/statuseffect.cpp13
-rw-r--r--src/statuseffect.h3
-rw-r--r--src/test/testmain.cpp4
-rw-r--r--src/text.cpp11
-rw-r--r--src/touchmanager.cpp14
-rw-r--r--src/utils/delete2.h30
-rw-r--r--src/utils/translation/translationmanager.cpp4
224 files changed, 1910 insertions, 2100 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 02a7240f1..961fb7abd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -552,6 +552,7 @@ SET(SRCS
utils/copynpaste.h
utils/cpu.cpp
utils/cpu.h
+ utils/delete2.h
utils/dtor.h
utils/files.cpp
utils/files.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 8483fa994..942ac7244 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -25,7 +25,7 @@ else
manaplus_SOURCES =
endif
-dyecmd_CXXFLAGS =
+dyecmd_CXXFLAGS = -DDYECMD
dyecmd_SOURCES = gui/cliprect.cpp \
gui/color.cpp \
gui/rect.cpp \
@@ -632,6 +632,7 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
utils/copynpaste.h \
utils/cpu.cpp \
utils/cpu.h \
+ utils/delete2.h \
utils/dtor.h \
utils/files.cpp \
utils/files.h \
diff --git a/src/actormanager.cpp b/src/actormanager.cpp
index bc325abe8..2d7c3a11b 100644
--- a/src/actormanager.cpp
+++ b/src/actormanager.cpp
@@ -812,9 +812,7 @@ void ActorManager::clear()
}
for_actors
- {
delete *it;
- }
mActors.clear();
mDeleteActors.clear();
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index 97424fbfb..930d7d61e 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -31,6 +31,8 @@
#include "resources/image.h"
#include "resources/resourcemanager.h"
+#include "utils/delete2.h"
+
#include "debug.h"
bool AnimatedSprite::mEnableCache = false;
@@ -108,8 +110,7 @@ AnimatedSprite::~AnimatedSprite()
{
mDelayLoad->clearSprite();
ResourceManager::removeDelayLoad(mDelayLoad);
- delete mDelayLoad;
- mDelayLoad = nullptr;
+ delete2(mDelayLoad);
}
}
diff --git a/src/avatar.cpp b/src/avatar.cpp
index 4c936ba7f..3e685f008 100644
--- a/src/avatar.cpp
+++ b/src/avatar.cpp
@@ -27,24 +27,25 @@
#include "debug.h"
Avatar::Avatar(const std::string &name):
- mId(0),
- mCharId(0),
- mName(name),
- mOriginalName(name),
- mHp(0),
- mMaxHp(0),
- mDamageHp(0),
- mLevel(1),
- mMap(),
- mX(-1),
- mY(-1),
- mType(AVATAR_PLAYER),
- mExp(0),
- mGender(GENDER_UNSPECIFIED),
- mRace(-1),
- mIp(),
- mOnline(false),
- mDisplayBold(false)
+ mId(0),
+ mCharId(0),
+ mName(name),
+ mOriginalName(name),
+ mHp(0),
+ mMaxHp(0),
+ mDamageHp(0),
+ mLevel(1),
+ mMap(),
+ mX(-1),
+ mY(-1),
+ mType(AVATAR_PLAYER),
+ mExp(0),
+ mGender(GENDER_UNSPECIFIED),
+ mRace(-1),
+ mIp(),
+ mOnline(false),
+ mDisplayBold(false),
+ mPoison(false)
{
}
diff --git a/src/avatar.h b/src/avatar.h
index 9804b318e..03050a06f 100644
--- a/src/avatar.h
+++ b/src/avatar.h
@@ -172,6 +172,12 @@ public:
void setIp(std::string ip)
{ mIp = ip; }
+ bool getPoison() const A_WARN_UNUSED
+ { return mPoison; }
+
+ void setPoison(const bool b)
+ { mPoison = b; }
+
protected:
int mId;
int mCharId;
@@ -191,6 +197,7 @@ protected:
std::string mIp;
bool mOnline;
bool mDisplayBold;
+ bool mPoison;
};
#endif // AVATAR_H
diff --git a/src/being/actorsprite.cpp b/src/being/actorsprite.cpp
index bbb016525..29fa1290c 100644
--- a/src/being/actorsprite.cpp
+++ b/src/being/actorsprite.cpp
@@ -37,6 +37,7 @@
#include "resources/resourcemanager.h"
#include "utils/checkutils.h"
+#include "utils/delete2.h"
#include "utils/timer.h"
#include "debug.h"
@@ -57,7 +58,8 @@ ActorSprite::ActorSprite(const int id) :
mActorSpriteListeners(),
mCursorPaddingX(0),
mCursorPaddingY(0),
- mMustResetParticles(false)
+ mMustResetParticles(false),
+ mPoison(false)
{
}
@@ -197,7 +199,13 @@ void ActorSprite::updateStunMode(const int oldMode, const int newMode)
void ActorSprite::updateStatusEffect(const int index, const bool newStatus)
{
- handleStatusEffect(StatusEffect::getStatusEffect(index, newStatus), index);
+ StatusEffect *const effect = StatusEffect::getStatusEffect(
+ index, newStatus);
+ if (!effect)
+ return;
+ if (effect->isPoison() && getType() == PLAYER)
+ setPoison(newStatus);
+ handleStatusEffect(effect, index);
}
void ActorSprite::handleStatusEffect(StatusEffect *const effect,
@@ -372,10 +380,7 @@ void ActorSprite::cleanupTargetCursors()
for (int type = TCT_NORMAL; type < NUM_TCT; type++)
{
if (targetCursor[type][size])
- {
- delete targetCursor[type][size];
- targetCursor[type][size] = nullptr;
- }
+ delete2(targetCursor[type][size])
}
}
}
diff --git a/src/being/actorsprite.h b/src/being/actorsprite.h
index 444232ddd..76e90182d 100644
--- a/src/being/actorsprite.h
+++ b/src/being/actorsprite.h
@@ -179,12 +179,18 @@ public:
*/
void removeActorSpriteListener(ActorSpriteListener *const listener);
- int getActorX() const
+ int getActorX() const A_WARN_UNUSED
{ return getPixelX() - mapTileSize / 2; }
- int getActorY() const
+ int getActorY() const A_WARN_UNUSED
{ return getPixelY() - mapTileSize; }
+ void setPoison(const bool b)
+ { mPoison = b; }
+
+ bool getPoison() const A_WARN_UNUSED
+ { return mPoison; }
+
protected:
/**
* Notify self that the stun mode has been updated. Invoked by
@@ -244,6 +250,7 @@ private:
/** Reset particle status effects on next redraw? */
bool mMustResetParticles;
+ bool mPoison;
};
#endif // BEING_ACTORSPRITE_H
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 41c3bc40c..be4d8b903 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -232,17 +232,11 @@ Being::~Being()
delete [] mSpriteDraw;
mSpriteDraw = nullptr;
- delete mSpeechBubble;
- mSpeechBubble = nullptr;
- delete mDispName;
- mDispName = nullptr;
- delete mText;
- mText = nullptr;
-
- delete mEmotionSprite;
- mEmotionSprite = nullptr;
- delete mAnimationEffect;
- mAnimationEffect = nullptr;
+ delete2(mSpeechBubble);
+ delete2(mDispName);
+ delete2(mText);
+ delete2(mEmotionSprite);
+ delete2(mAnimationEffect);
if (mOwner)
mOwner->unassignPet(this);
@@ -469,7 +463,6 @@ void Being::setSpeech(const std::string &text, const std::string &channel,
if (speech == TEXT_OVERHEAD && userPalette)
{
delete mText;
-
mText = new Text(mSpeech,
getPixelX(), getPixelY() - getHeight(),
Graphics::CENTER,
@@ -821,14 +814,9 @@ void Being::setShowName(const bool doShowName)
mShowName = doShowName;
if (doShowName)
- {
showName();
- }
else
- {
- delete mDispName;
- mDispName = nullptr;
- }
+ delete2(mDispName)
}
void Being::setGuildName(const std::string &name)
@@ -1365,10 +1353,7 @@ void Being::logic()
// Remove text and speechbubbles if speech boxes aren't being used
if (mSpeechTime == 0 && mText)
- {
- delete mText;
- mText = nullptr;
- }
+ delete2(mText)
const int time = tick_time * MILLISECONDS_IN_A_TICK;
if (mEmotionSprite)
@@ -1378,10 +1363,7 @@ void Being::logic()
{
mAnimationEffect->update(time);
if (mAnimationEffect->isTerminated())
- {
- delete mAnimationEffect;
- mAnimationEffect = nullptr;
- }
+ delete2(mAnimationEffect)
}
int frameCount = static_cast<int>(getFrameCount());
@@ -1453,10 +1435,7 @@ void Being::logic()
{
mEmotionTime--;
if (mEmotionTime == 0)
- {
- delete mEmotionSprite;
- mEmotionSprite = nullptr;
- }
+ delete2(mEmotionSprite)
}
ActorSprite::logic();
@@ -1695,8 +1674,7 @@ void Being::drawSpeech(const int offsetX, const int offsetY)
else if (mSpeechTime > 0 && (speech == NAME_IN_BUBBLE ||
speech == NO_NAME_IN_BUBBLE))
{
- delete mText;
- mText = nullptr;
+ delete2(mText)
mSpeechBubble->setPosition(px - (mSpeechBubble->getWidth() / 2),
py - getHeight() - (mSpeechBubble->getHeight()));
@@ -1710,16 +1688,14 @@ void Being::drawSpeech(const int offsetX, const int offsetY)
if (!mText && userPalette)
{
mText = new Text(mSpeech, getPixelX(), getPixelY() - getHeight(),
- Graphics::CENTER, &Theme::getThemeColor(
- Theme::BUBBLE_TEXT), true);
+ Graphics::CENTER, &theme->getColor(
+ Theme::BUBBLE_TEXT, 255), true);
}
}
else if (speech == NO_SPEECH)
{
mSpeechBubble->setVisible(false);
-
- delete mText;
- mText = nullptr;
+ delete2(mText)
}
}
@@ -1831,8 +1807,7 @@ void Being::showName()
if (mName.empty())
return;
- delete mDispName;
- mDispName = nullptr;
+ delete2(mDispName);
if (mHideErased && player_relations.getRelation(mName) ==
PlayerRelation::ERASED)
@@ -1901,11 +1876,11 @@ void Being::updateColors()
else if (this == player_node)
{
mNameColor = &userPalette->getColor(UserPalette::SELF);
- mTextColor = &Theme::getThemeColor(Theme::PLAYER);
+ mTextColor = &theme->getColor(Theme::PLAYER, 255);
}
else
{
- mTextColor = &Theme::getThemeColor(Theme::PLAYER);
+ mTextColor = &theme->getColor(Theme::PLAYER, 255);
if (player_relations.getRelation(mName) != PlayerRelation::ERASED)
mErased = false;
@@ -2967,8 +2942,7 @@ void Being::setEmote(const uint8_t emotion, const int emote_time)
const int emotionIndex = emotion - 1;
if (emotionIndex >= 0 && emotionIndex <= EmoteDB::getLast())
{
- delete mEmotionSprite;
- mEmotionSprite = nullptr;
+ delete2(mEmotionSprite)
const EmoteInfo *const info = EmoteDB::get2(emotionIndex, true);
if (info)
{
@@ -3076,8 +3050,7 @@ void Being::removeSpecialEffect()
mChildParticleEffects.removeLocally(mSpecialParticle);
mSpecialParticle = nullptr;
}
- delete mAnimationEffect;
- mAnimationEffect = nullptr;
+ delete2(mAnimationEffect);
}
void Being::updateAwayEffect()
@@ -3322,9 +3295,7 @@ void Being::setMap(Map *const map)
void Being::removeAllItemsParticles()
{
FOR_EACH (SpriteParticleInfoIter, it, mSpriteParticles)
- {
delete (*it).second;
- }
mSpriteParticles.clear();
}
diff --git a/src/being/compoundsprite.cpp b/src/being/compoundsprite.cpp
index ea4a2067f..6c159821d 100644
--- a/src/being/compoundsprite.cpp
+++ b/src/being/compoundsprite.cpp
@@ -36,6 +36,7 @@
#include "resources/image.h"
#include "resources/imagehelper.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/sdlcheckutils.h"
#include "utils/timer.h"
@@ -252,8 +253,7 @@ void CompoundSprite::removeSprite(const int layer)
if (!mSprites.at(layer))
return;
- delete mSprites.at(layer);
- mSprites.at(layer) = nullptr;
+ delete2(mSprites.at(layer));
mNeedsRedraw = true;
}
@@ -268,8 +268,7 @@ void CompoundSprite::clear()
mNeedsRedraw = true;
delete_all(imagesCache);
imagesCache.clear();
- delete mCacheItem;
- mCacheItem = nullptr;
+ delete2(mCacheItem);
}
void CompoundSprite::ensureSize(size_t layerCount)
@@ -337,7 +336,7 @@ void CompoundSprite::redraw() const
SurfaceGraphics *graphics = new SurfaceGraphics();
graphics->setBlitMode(SurfaceGraphics::BLIT_GFX);
graphics->setTarget(surface);
- graphics->_beginDraw();
+ graphics->beginDraw();
int tileX = mapTileSize / 2;
int tileY = mapTileSize;
@@ -361,8 +360,7 @@ void CompoundSprite::redraw() const
drawSpritesSDL(graphics, posX, posY);
- delete graphics;
- graphics = nullptr;
+ delete2(graphics);
SDL_Surface *const surfaceA = MSDL_CreateRGBSurface(SDL_HWSURFACE,
BUFFER_WIDTH, BUFFER_HEIGHT, 32, rmask, gmask, bmask, amask);
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index 889f2b906..c774b985b 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -69,6 +69,7 @@
#include "resources/db/emotedb.h"
#include "resources/db/weaponsdb.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/timer.h"
@@ -161,6 +162,7 @@ LocalPlayer::LocalPlayer(const int id, const int subtype) :
mAttackMoving(config.getBoolValue("attackMoving")),
mAttackNext(config.getBoolValue("attackNext")),
mShowJobExp(config.getBoolValue("showJobExp")),
+ mShowServerPos(config.getBoolValue("showserverpos")),
mNextStep(false),
mDisableCrazyMove(false),
mGoingToTarget(false),
@@ -178,7 +180,7 @@ LocalPlayer::LocalPlayer(const int id, const int subtype) :
mAttackRange = 0;
mLevel = 1;
mAdvanced = true;
- mTextColor = &Theme::getThemeColor(Theme::PLAYER);
+ mTextColor = &theme->getColor(Theme::PLAYER, 255);
if (userPalette)
mNameColor = &userPalette->getColor(UserPalette::SELF);
else
@@ -202,6 +204,7 @@ LocalPlayer::LocalPlayer(const int id, const int subtype) :
config.addListener("enableAdvert", this);
config.addListener("tradebot", this);
config.addListener("targetOnlyReachable", this);
+ config.addListener("showserverpos", this);
setShowName(config.getBoolValue("showownname"));
}
@@ -221,11 +224,9 @@ LocalPlayer::~LocalPlayer()
if (mAwayDialog)
{
soundManager.volumeRestore();
- delete mAwayDialog;
- mAwayDialog = nullptr;
+ delete2(mAwayDialog)
}
- delete mAwayListener;
- mAwayListener = nullptr;
+ delete2(mAwayListener);
}
void LocalPlayer::logic()
@@ -1019,6 +1020,8 @@ void LocalPlayer::optionChanged(const std::string &value)
mTradebot = config.getBoolValue("tradebot");
else if (value == "targetOnlyReachable")
mTargetOnlyReachable = config.getBoolValue("targetOnlyReachable");
+ else if (value == "showserverpos")
+ mShowServerPos = config.getBoolValue("showserverpos");
}
void LocalPlayer::processEvent(const Channels channel,
@@ -3552,14 +3555,15 @@ void LocalPlayer::setRealPos(const int x, const int y)
{
fixPos(1);
- if ((mCrossX || mCrossY) && layer->getTile(mCrossX, mCrossY)
+ if ((mCrossX || mCrossY)
+ && layer->getTile(mCrossX, mCrossY)
&& layer->getTile(mCrossX, mCrossY)->getType() == MapItem::CROSS)
{
layer->setTile(mCrossX, mCrossY, MapItem::EMPTY);
}
- if (!layer->getTile(x, y)
- || layer->getTile(x, y)->getType() == MapItem::EMPTY)
+ if (mShowServerPos && (!layer->getTile(x, y)
+ || layer->getTile(x, y)->getType() == MapItem::EMPTY))
{
if (getTileX() != x && getTileY() != y)
layer->setTile(x, y, MapItem::CROSS);
diff --git a/src/being/localplayer.h b/src/being/localplayer.h
index 5664b03b6..280e245cd 100644
--- a/src/being/localplayer.h
+++ b/src/being/localplayer.h
@@ -639,6 +639,7 @@ class LocalPlayer final : public Being,
bool mAttackMoving;
bool mAttackNext;
bool mShowJobExp;
+ bool mShowServerPos;
bool mNextStep;
// temporary disable crazy moves in moves
bool mDisableCrazyMove;
diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp
index 728fe786f..12ce1e6d3 100644
--- a/src/being/playerinfo.cpp
+++ b/src/being/playerinfo.cpp
@@ -37,6 +37,8 @@
#include "net/net.h"
#include "net/playerhandler.h"
+#include "utils/delete2.h"
+
#include "debug.h"
namespace PlayerInfo
@@ -422,10 +424,8 @@ bool isTalking()
void gameDestroyed()
{
- delete mInventory;
- mInventory = nullptr;
- delete mEquipment;
- mEquipment = nullptr;
+ delete2(mInventory);
+ delete2(mEquipment);
}
void stateChange(const int state)
diff --git a/src/beingequipbackend.cpp b/src/beingequipbackend.cpp
index 03d882665..3f5f627a8 100644
--- a/src/beingequipbackend.cpp
+++ b/src/beingequipbackend.cpp
@@ -25,6 +25,8 @@
#include "net/inventoryhandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
+
#include "debug.h"
BeingEquipBackend::BeingEquipBackend(Being *const being)
@@ -51,19 +53,13 @@ BeingEquipBackend::BeingEquipBackend(Being *const being)
BeingEquipBackend::~BeingEquipBackend()
{
for (int i = 0; i < EQUIPMENT_SIZE; i++)
- {
- delete mEquipment[i];
- mEquipment[i] = nullptr;
- }
+ delete2(mEquipment[i])
}
void BeingEquipBackend::clear()
{
for (int i = 0; i < EQUIPMENT_SIZE; i++)
- {
- delete mEquipment[i];
- mEquipment[i] = nullptr;
- }
+ delete2(mEquipment[i])
}
void BeingEquipBackend::setEquipment(const int index, Item *const item)
diff --git a/src/client.cpp b/src/client.cpp
index d8cd1f6f2..9aded7682 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -110,6 +110,7 @@
#include "utils/base64.h"
#include "utils/cpu.h"
+#include "utils/delete2.h"
#include "utils/files.h"
#include "utils/fuzzer.h"
#include "utils/gettext.h"
@@ -399,6 +400,7 @@ void Client::gameInit()
initTitle();
+ theme = new Theme;
Theme::selectSkin();
touchManager.init();
@@ -584,7 +586,7 @@ void Client::initGraphics()
applyGrabMode();
applyGamma();
- mainGraphics->_beginDraw();
+ mainGraphics->beginDraw();
}
void Client::initTitle()
@@ -820,12 +822,9 @@ void Client::gameClear()
eventsManager.shutdown();
- delete setupWindow;
- setupWindow = nullptr;
- delete helpWindow;
- helpWindow = nullptr;
- delete didYouKnowWindow;
- didYouKnowWindow = nullptr;
+ delete2(setupWindow);
+ delete2(helpWindow);
+ delete2(didYouKnowWindow);
stopTimers();
@@ -852,33 +851,24 @@ void Client::gameClear()
Net::getChatHandler()->clear();
#ifdef USE_MUMBLE
- delete mumbleManager;
- mumbleManager = nullptr;
+ delete2(mumbleManager);
#endif
PlayerInfo::deinit();
// Before config.write() since it writes the shortcuts to the config
for (unsigned f = 0; f < SHORTCUT_TABS; f ++)
- {
- delete itemShortcut[f];
- itemShortcut[f] = nullptr;
- }
- delete emoteShortcut;
- emoteShortcut = nullptr;
- delete dropShortcut;
- dropShortcut = nullptr;
+ delete2(itemShortcut[f])
+ delete2(emoteShortcut);
+ delete2(dropShortcut);
player_relations.store();
if (logger)
logger->log1("Quitting2");
- delete mCurrentDialog;
- mCurrentDialog = nullptr;
-
- delete gui;
- gui = nullptr;
+ delete2(mCurrentDialog);
+ delete2(gui);
if (Net::getInventoryHandler())
Net::getInventoryHandler()->clear();
@@ -886,14 +876,12 @@ void Client::gameClear()
if (logger)
logger->log1("Quitting3");
- delete mainGraphics;
- mainGraphics = nullptr;
+ delete2(mainGraphics);
if (imageHelper != surfaceImageHelper)
delete surfaceImageHelper;
surfaceImageHelper = nullptr;
- delete imageHelper;
- imageHelper = nullptr;
+ delete2(imageHelper);
if (logger)
logger->log1("Quitting4");
@@ -924,11 +912,8 @@ void Client::gameClear()
if (logger)
logger->log1("Quitting9");
- delete userPalette;
- userPalette = nullptr;
-
- delete joystick;
- joystick = nullptr;
+ delete2(userPalette);
+ delete2(joystick);
keyboard.deinit();
@@ -960,8 +945,7 @@ void Client::gameClear()
logger->log("textures left: %d", textures_count);
#endif
- delete chatLogger;
- chatLogger = nullptr;
+ delete2(chatLogger);
TranslationManager::close();
}
@@ -998,8 +982,7 @@ int Client::gameExec()
mumbleManager = new MumbleManager();
#endif
- if (Theme::instance())
- mSkin = Theme::instance()->load("windowmenu.xml", "");
+ mSkin = theme->load("windowmenu.xml", "");
if (mSkin)
{
mButtonPadding = mSkin->getPadding();
@@ -1174,8 +1157,7 @@ int Client::gameExec()
if (mOldState == STATE_GAME)
{
- delete mGame;
- mGame = nullptr;
+ delete2(mGame);
Game::clearInstance();
ResourceManager *const resman = ResourceManager::getInstance();
if (resman)
@@ -1198,8 +1180,7 @@ int Client::gameExec()
mOldState = mState;
// Get rid of the dialog of the previous state
- delete mCurrentDialog;
- mCurrentDialog = nullptr;
+ delete2(mCurrentDialog);
// State has changed, while the quitDialog was active, it might
// not be correct anymore
if (mQuitDialog)
@@ -1256,7 +1237,7 @@ int Client::gameExec()
{
// Don't allow an alpha opacity
// lower than the default value
- Theme::instance()->setMinimumOpacity(0.8F);
+ theme->setMinimumOpacity(0.8F);
mCurrentDialog = new ServerDialog(&mCurrentServer,
mConfigDir);
@@ -1298,7 +1279,7 @@ int Client::gameExec()
logger->log1("State: LOGIN");
// Don't allow an alpha opacity
// lower than the default value
- Theme::instance()->setMinimumOpacity(0.8F);
+ theme->setMinimumOpacity(0.8F);
loginData.updateType
= serverConfig.getValue("updateType", 1);
@@ -1505,7 +1486,7 @@ int Client::gameExec()
logger->log1("State: CHAR SELECT");
// Don't allow an alpha opacity
// lower than the default value
- Theme::instance()->setMinimumOpacity(0.8F);
+ theme->setMinimumOpacity(0.8F);
mCurrentDialog = new CharSelectDialog(&loginData);
mCurrentDialog->postInit();
@@ -1571,29 +1552,21 @@ int Client::gameExec()
soundManager.fadeOutMusic(1000);
// Allow any alpha opacity
- Theme::instance()->setMinimumOpacity(-1.0F);
+ theme->setMinimumOpacity(-1.0F);
if (chatLogger)
chatLogger->setServerName(mServerName);
#ifdef ANDROID
- delete mCloseButton;
- mCloseButton = nullptr;
-#endif
- delete mSetupButton;
- mSetupButton = nullptr;
- delete mVideoButton;
- mVideoButton = nullptr;
- delete mThemesButton;
- mThemesButton = nullptr;
- delete mAboutButton;
- mAboutButton = nullptr;
- delete mHelpButton;
- mHelpButton = nullptr;
- delete mPerfomanceButton;
- mPerfomanceButton = nullptr;
- delete mDesktop;
- mDesktop = nullptr;
+ delete2(mCloseButton);
+#endif
+ delete2(mSetupButton);
+ delete2(mVideoButton);
+ delete2(mThemesButton);
+ delete2(mAboutButton);
+ delete2(mHelpButton);
+ delete2(mPerfomanceButton);
+ delete2(mDesktop);
mCurrentDialog = nullptr;
@@ -2837,6 +2810,9 @@ void Client::resizeVideo(int actualWidth,
x -= mThemesButton->getWidth() + mButtonSpacing;
mThemesButton->setPosition(x, mButtonPadding);
+ x -= mAboutButton->getWidth() + mButtonSpacing;
+ mAboutButton->setPosition(x, mButtonPadding);
+
x -= mHelpButton->getWidth() + mButtonSpacing;
mHelpButton->setPosition(x, mButtonPadding);
#ifdef ANDROID
@@ -2984,7 +2960,7 @@ Window *Client::openErrorDialog(const std::string &header,
const std::string &message,
const bool modal)
{
- if (getSupportUrl().empty())
+ if (getSupportUrl().empty() || config.getBoolValue("hidesupport"))
{
return new OkDialog(header, message, DIALOG_ERROR, modal);
}
diff --git a/src/commands.cpp b/src/commands.cpp
index 0cc5cee8a..de4c03012 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -77,6 +77,7 @@
#include "resources/db/itemdb.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/process.h"
#include "utils/timer.h"
@@ -1270,6 +1271,10 @@ impHandler1(talkPet)
Net::getChatHandler()->talk(args, GENERAL_CHANNEL);
}
+impHandler1(gm)
+{
+ Net::getChatHandler()->talk("@wgm " + args, GENERAL_CHANNEL);
+}
struct UploadChatInfo
{
@@ -1315,8 +1320,7 @@ static int uploadUpdate(void *ptr,
}
}
}
- delete info->upload;
- info->upload = nullptr;
+ delete2(info->upload);
delete info;
return 0;
}
@@ -1375,7 +1379,7 @@ impHandler0(testsdlfont)
for (int f = 0; f < 300; f ++)
data.push_back("test " + toString(f) + "string");
- nullGraphics->_beginDraw();
+ nullGraphics->beginDraw();
clock_gettime(CLOCK_MONOTONIC, &time1);
for (int f = 0; f < 500; f ++)
diff --git a/src/commands.h b/src/commands.h
index e53d66559..6dd688a17 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -133,6 +133,7 @@ namespace Commands
decHandler(uploadConfig);
decHandler(uploadServerConfig);
decHandler(uploadLog);
+ decHandler(gm);
void replaceVars(std::string &str);
} // namespace Commands
@@ -233,6 +234,7 @@ enum
COMMAND_UPLOADCONFIG,
COMMAND_UPLOADSERVERCONFIG,
COMMAND_UPLOADLOG,
+ COMMAND_GM,
COMMAND_HACK,
END_COMMANDS
};
@@ -333,6 +335,7 @@ static const CommandInfo commands[] =
{"uploadconfig", &Commands::uploadConfig, -1, false},
{"uploadserverconfig", &Commands::uploadServerConfig, -1, false},
{"uploadlog", &Commands::uploadLog, -1, false},
+ {"gm", &Commands::gm, -1, true},
{"hack", &Commands::hack, -1, true}
};
diff --git a/src/configuration.cpp b/src/configuration.cpp
index 54420a9f3..550c61243 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -27,6 +27,7 @@
#include "listeners/configlistener.h"
+#include "utils/delete2.h"
#include "utils/paths.h"
#include "debug.h"
@@ -367,8 +368,7 @@ void Configuration::cleanDefaults()
delete (iter->second);
}
mDefaultsData->clear();
- delete mDefaultsData;
- mDefaultsData = nullptr;
+ delete2(mDefaultsData);
}
}
diff --git a/src/defaults.cpp b/src/defaults.cpp
index d5f907696..7e2e22769 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -361,6 +361,8 @@ DefaultsData* getConfigDefaults()
AddDEF("usepets", true);
AddDEF("scale", 1);
AddDEF("addwatermark", true);
+ AddDEF("hidesupport", false);
+ AddDEF("showserverpos", false);
return configData;
}
@@ -535,6 +537,7 @@ DefaultsData* getPathsDefaults()
AddDEF("deadMessagesFile", "deadmessages.xml");
AddDEF("deadMessagesPatchFile", "deadmessages_patch.xml");
AddDEF("deadMessagesPatchDir", "deadmessages.d");
+ AddDEF("poisonEffectName", "poison");
return configData;
}
diff --git a/src/depricatedevent.cpp b/src/depricatedevent.cpp
index fc499c47b..3f8abad00 100644
--- a/src/depricatedevent.cpp
+++ b/src/depricatedevent.cpp
@@ -25,6 +25,8 @@
#include "listeners/depricatedlistener.h"
+#include "utils/delete2.h"
+
#include "debug.h"
DepricatedListenMap DepricatedEvent::mBindings;
@@ -34,8 +36,7 @@ DepricatedEvent::~DepricatedEvent()
VariableMap::iterator it = mData.begin();
while (it != mData.end())
{
- delete it->second;
- it->second = nullptr;
+ delete2(it->second);
++it;
}
}
diff --git a/src/game.cpp b/src/game.cpp
index e30b7222e..33369bf97 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -98,6 +98,7 @@
#include "resources/db/mapdb.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/langs.h"
#include "utils/mkdir.h"
@@ -263,8 +264,7 @@ static void createGuiWindows()
killStats = new KillStats;
socialWindow = new SocialWindow;
socialWindow->postInit();
- if (serverVersion >= 6)
- questsWindow = new QuestsWindow;
+ questsWindow = new QuestsWindow;
// TRANSLATORS: chat tab header
localChatTab = new ChatTab(chatWindow, _("General"), GENERAL_CHANNEL);
@@ -324,8 +324,6 @@ static void createGuiWindows()
Net::getGeneralHandler()->gameStarted();
}
-#define del_0(X) { delete X; X = nullptr; }
-
/**
* Destroy all the globally accessible gui windows
*/
@@ -342,37 +340,37 @@ static void destroyGuiWindows()
if (guildManager)
guildManager->clear();
- del_0(windowMenu);
- del_0(localChatTab) // Need to do this first, so it can remove itself
- del_0(debugChatTab)
- del_0(tradeChatTab)
- del_0(battleChatTab)
- del_0(langChatTab)
- del_0(gmChatTab);
+ delete2(windowMenu);
+ delete2(localChatTab) // Need to do this first, so it can remove itself
+ delete2(debugChatTab)
+ delete2(tradeChatTab)
+ delete2(battleChatTab)
+ delete2(langChatTab)
+ delete2(gmChatTab);
logger->log("start deleting");
- del_0(emoteWindow);
- del_0(chatWindow)
+ delete2(emoteWindow);
+ delete2(chatWindow)
logger->log("end deleting");
- del_0(statusWindow)
- del_0(miniStatusWindow)
- del_0(inventoryWindow)
- del_0(shopWindow)
- del_0(skillDialog)
- del_0(minimap)
- del_0(equipmentWindow)
- del_0(beingEquipmentWindow)
- del_0(tradeWindow)
- del_0(debugWindow)
- del_0(itemShortcutWindow)
- del_0(emoteShortcutWindow)
- del_0(outfitWindow)
- del_0(socialWindow)
- del_0(dropShortcutWindow);
- del_0(spellShortcutWindow);
- del_0(botCheckerWindow);
- del_0(questsWindow);
- del_0(whoIsOnline);
- del_0(killStats);
+ delete2(statusWindow)
+ delete2(miniStatusWindow)
+ delete2(inventoryWindow)
+ delete2(shopWindow)
+ delete2(skillDialog)
+ delete2(minimap)
+ delete2(equipmentWindow)
+ delete2(beingEquipmentWindow)
+ delete2(tradeWindow)
+ delete2(debugWindow)
+ delete2(itemShortcutWindow)
+ delete2(emoteShortcutWindow)
+ delete2(outfitWindow)
+ delete2(socialWindow)
+ delete2(dropShortcutWindow);
+ delete2(spellShortcutWindow);
+ delete2(botCheckerWindow);
+ delete2(questsWindow);
+ delete2(whoIsOnline);
+ delete2(killStats);
if (auctionManager && AuctionManager::getEnableAuctionBot())
auctionManager->reload();
@@ -459,20 +457,20 @@ Game::~Game()
AnimatedSprite::setEnableCache(false);
- del_0(actorManager)
+ delete2(actorManager)
if (client->getState() != STATE_CHANGE_MAP)
- del_0(player_node)
- del_0(commandHandler)
- del_0(effectManager)
- del_0(particleEngine)
- del_0(viewport)
- del_0(mCurrentMap)
- del_0(spellManager)
- del_0(spellShortcut)
- del_0(auctionManager)
- del_0(guildManager)
+ delete2(player_node)
+ delete2(commandHandler)
+ delete2(effectManager)
+ delete2(particleEngine)
+ delete2(viewport)
+ delete2(mCurrentMap)
+ delete2(spellManager)
+ delete2(spellShortcut)
+ delete2(auctionManager)
+ delete2(guildManager)
#ifdef USE_MUMBLE
- del_0(mumbleManager)
+ delete2(mumbleManager)
#endif
Being::clearCache();
@@ -484,8 +482,8 @@ void Game::addWatermark()
{
if (!boldFont || !config.getBoolValue("addwatermark"))
return;
- mainGraphics->setColorAll(Theme::getThemeColor(Theme::TEXT),
- Theme::getThemeColor(Theme::TEXT_OUTLINE));
+ mainGraphics->setColorAll(theme->getColor(Theme::TEXT, 255),
+ theme->getColor(Theme::TEXT_OUTLINE, 255));
boldFont->drawString(mainGraphics, client->getServerName(), 100, 50);
}
diff --git a/src/gui/cliprect.cpp b/src/gui/cliprect.cpp
index 5255a4c98..5f71c8249 100644
--- a/src/gui/cliprect.cpp
+++ b/src/gui/cliprect.cpp
@@ -70,27 +70,19 @@
#include "debug.h"
ClipRect::ClipRect() :
- Rect(),
+ Rect(0, 0, 0, 0),
xOffset(0),
yOffset(0)
{
- x = 0;
- y = 0;
- width = 0;
- height = 0;
}
ClipRect::ClipRect(const int x0, const int y0,
const int width0, const int height0,
const int xOffset0, const int yOffset0) :
- Rect(),
+ Rect(x0, y0, width0, height0),
xOffset(xOffset0),
yOffset(yOffset0)
{
- x = x0;
- y = y0;
- width = width0;
- height = height0;
}
const ClipRect& ClipRect::operator=(const Rect& other)
@@ -99,6 +91,5 @@ const ClipRect& ClipRect::operator=(const Rect& other)
y = other.y;
width = other.width;
height = other.height;
-
return *this;
}
diff --git a/src/gui/color.cpp b/src/gui/color.cpp
index aa9ffe840..2536e2947 100644
--- a/src/gui/color.cpp
+++ b/src/gui/color.cpp
@@ -78,9 +78,9 @@ Color::Color() :
}
Color::Color(const unsigned int color) :
- r((color >> 16) & 0xFF),
- g((color >> 8) & 0xFF),
- b(color & 0xFF),
+ r((color >> 16) & 0xFFU),
+ g((color >> 8) & 0xFFU),
+ b(color & 0xFFU),
a(255U)
{
}
@@ -113,9 +113,9 @@ Color Color::operator+(const Color& color) const
Color Color::operator-(const Color& color) const
{
Color result(r - color.r,
- g - color.g,
- b - color.b,
- 255U);
+ g - color.g,
+ b - color.b,
+ 255U);
result.r = (result.r > 255U ? 255U : result.r);
result.g = (result.g > 255U ? 255U : result.g);
@@ -127,9 +127,9 @@ Color Color::operator-(const Color& color) const
Color Color::operator*(const float value) const
{
Color result(static_cast<int>(static_cast<float>(r) * value),
- static_cast<int>(static_cast<float>(g) * value),
- static_cast<int>(static_cast<float>(b) * value),
- a);
+ static_cast<int>(static_cast<float>(g) * value),
+ static_cast<int>(static_cast<float>(b) * value),
+ a);
result.r = (result.r > 255U ? 255U : result.r);
result.g = (result.g > 255U ? 255U : result.g);
@@ -147,19 +147,3 @@ bool Color::operator!=(const Color& color) const
{
return !(r == color.r && g == color.g && b == color.b && a == color.a);
}
-
-std::ostream& operator<<(std::ostream& out,
- const Color& color)
-{
- out << "Color [r = "
- << color.r
- << ", g = "
- << color.g
- << ", b = "
- << color.b
- << ", a = "
- << color.a
- << "]";
-
- return out;
-}
diff --git a/src/gui/color.h b/src/gui/color.h
index db8fda970..bfa66b796 100644
--- a/src/gui/color.h
+++ b/src/gui/color.h
@@ -64,8 +64,6 @@
#ifndef GUI_COLOR_H
#define GUI_COLOR_H
-#include <iostream>
-
#include "localconsts.h"
/**
@@ -160,15 +158,6 @@ class Color final
bool operator!=(const Color& color) const;
/**
- * Output operator for output.
- *
- * @param out The stream to output to.
- * @param color The color to output.
- */
- friend std::ostream& operator<<(std::ostream& out,
- const Color& Color);
-
- /**
* Holds the red color component (range 0-255).
*/
unsigned int r;
diff --git a/src/gui/focushandler.cpp b/src/gui/focushandler.cpp
index 928b3b72e..ced7c5f6e 100644
--- a/src/gui/focushandler.cpp
+++ b/src/gui/focushandler.cpp
@@ -87,7 +87,7 @@ FocusHandler::FocusHandler() :
{
}
-void FocusHandler::requestModalFocus(Widget *widget)
+void FocusHandler::requestModalFocus(Widget *const widget)
{
/* If there is another widget with modal focus, remove its modal focus
* and put it on the modal widget stack.
@@ -103,7 +103,7 @@ void FocusHandler::requestModalFocus(Widget *widget)
focusNone();
}
-void FocusHandler::releaseModalFocus(Widget *widget)
+void FocusHandler::releaseModalFocus(Widget *const widget)
{
mModalStack.remove(widget);
@@ -123,15 +123,14 @@ void FocusHandler::releaseModalFocus(Widget *widget)
}
}
-void FocusHandler::remove(Widget *widget)
+void FocusHandler::remove(Widget *const widget)
{
releaseModalFocus(widget);
if (isFocused(widget))
mFocusedWidget = nullptr;
- for (WidgetIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++iter)
+ FOR_EACH (WidgetIterator, iter, mWidgets)
{
if ((*iter) == widget)
{
@@ -342,7 +341,7 @@ void FocusHandler::distributeFocusGainedEvent(const Event &focusEvent)
Widget *const sourceWidget = focusEvent.getSource();
std::list<FocusListener*> focusListeners
- = sourceWidget->_getFocusListeners();
+ = sourceWidget->getFocusListeners();
// Send the event to all focus listeners of the widget.
for (std::list<FocusListener*>::const_iterator
@@ -354,14 +353,14 @@ void FocusHandler::distributeFocusGainedEvent(const Event &focusEvent)
}
}
-void FocusHandler::requestFocus(Widget* widget)
+void FocusHandler::requestFocus(Widget *const widget)
{
if (!widget || widget == mFocusedWidget)
return;
int toBeFocusedIndex = -1;
for (unsigned int i = 0, sz = static_cast<unsigned int>(
- mWidgets.size()); i < sz; ++i)
+ mWidgets.size()); i < sz; ++i)
{
if (mWidgets[i] == widget)
{
@@ -390,7 +389,7 @@ void FocusHandler::requestFocus(Widget* widget)
}
}
-void FocusHandler::requestModalMouseInputFocus(Widget* widget)
+void FocusHandler::requestModalMouseInputFocus(Widget *const widget)
{
if (mModalMouseInputFocusedWidget
&& mModalMouseInputFocusedWidget != widget)
@@ -401,7 +400,7 @@ void FocusHandler::requestModalMouseInputFocus(Widget* widget)
mModalMouseInputFocusedWidget = widget;
}
-void FocusHandler::releaseModalMouseInputFocus(Widget* widget)
+void FocusHandler::releaseModalMouseInputFocus(Widget *const widget)
{
if (mModalMouseInputFocusedWidget == widget)
mModalMouseInputFocusedWidget = nullptr;
@@ -527,12 +526,12 @@ void FocusHandler::focusPrevious()
}
}
-bool FocusHandler::isFocused(const Widget* widget) const
+bool FocusHandler::isFocused(const Widget *const widget) const
{
return mFocusedWidget == widget;
}
-void FocusHandler::add(Widget* widget)
+void FocusHandler::add(Widget *const widget)
{
mWidgets.push_back(widget);
}
@@ -554,7 +553,7 @@ void FocusHandler::distributeFocusLostEvent(const Event& focusEvent)
Widget *const sourceWidget = focusEvent.getSource();
std::list<FocusListener*> focusListeners
- = sourceWidget->_getFocusListeners();
+ = sourceWidget->getFocusListeners();
// Send the event to all focus listeners of the widget.
for (std::list<FocusListener*>::const_iterator
@@ -566,52 +565,52 @@ void FocusHandler::distributeFocusLostEvent(const Event& focusEvent)
}
}
-Widget* FocusHandler::getDraggedWidget()
+Widget* FocusHandler::getDraggedWidget() const
{
return mDraggedWidget;
}
-void FocusHandler::setDraggedWidget(Widget* draggedWidget)
+void FocusHandler::setDraggedWidget(Widget *const draggedWidget)
{
mDraggedWidget = draggedWidget;
}
-Widget* FocusHandler::getLastWidgetWithMouse()
+Widget* FocusHandler::getLastWidgetWithMouse() const
{
return mLastWidgetWithMouse;
}
-void FocusHandler::setLastWidgetWithMouse(Widget* lastWidgetWithMouse)
+void FocusHandler::setLastWidgetWithMouse(Widget *const lastWidgetWithMouse)
{
mLastWidgetWithMouse = lastWidgetWithMouse;
}
-Widget* FocusHandler::getLastWidgetWithModalFocus()
+Widget* FocusHandler::getLastWidgetWithModalFocus() const
{
return mLastWidgetWithModalFocus;
}
-void FocusHandler::setLastWidgetWithModalFocus(Widget* widget)
+void FocusHandler::setLastWidgetWithModalFocus(Widget *const widget)
{
mLastWidgetWithModalFocus = widget;
}
-Widget* FocusHandler::getLastWidgetWithModalMouseInputFocus()
+Widget* FocusHandler::getLastWidgetWithModalMouseInputFocus() const
{
return mLastWidgetWithModalMouseInputFocus;
}
-void FocusHandler::setLastWidgetWithModalMouseInputFocus(Widget* widget)
+void FocusHandler::setLastWidgetWithModalMouseInputFocus(Widget *const widget)
{
mLastWidgetWithModalMouseInputFocus = widget;
}
-Widget* FocusHandler::getLastWidgetPressed()
+Widget* FocusHandler::getLastWidgetPressed() const
{
return mLastWidgetPressed;
}
-void FocusHandler::setLastWidgetPressed(Widget* lastWidgetPressed)
+void FocusHandler::setLastWidgetPressed(Widget *const lastWidgetPressed)
{
mLastWidgetPressed = lastWidgetPressed;
}
diff --git a/src/gui/focushandler.h b/src/gui/focushandler.h
index f12819e75..58b317024 100644
--- a/src/gui/focushandler.h
+++ b/src/gui/focushandler.h
@@ -97,7 +97,7 @@ class FocusHandler final
* @param widget The widget to request focus for.
* @see isFocused, Widget::requestFocus
*/
- void requestFocus(Widget* widget);
+ void requestFocus(Widget *const widget);
/**
* Requests modal focus for a widget. Focus will only be granted
@@ -108,7 +108,7 @@ class FocusHandler final
* @throws Exception when another widget already has modal focus.
* @see releaseModalFocus, Widget::requestModalFocus
*/
- void requestModalFocus(Widget* widget);
+ void requestModalFocus(Widget *const widget);
/**
* Requests modal mouse input focus for a widget. Focus will only
@@ -125,7 +125,7 @@ class FocusHandler final
* focus.
* @see releaseModalMouseInputFocus, Widget::requestModalMouseInputFocus
*/
- void requestModalMouseInputFocus(Widget* widget);
+ void requestModalMouseInputFocus(Widget *const widget);
/**
* Releases modal focus if the widget has modal focus.
@@ -134,7 +134,7 @@ class FocusHandler final
* @param widget The widget to release modal focus for.
* @see reuqestModalFocus, Widget::releaseModalFocus
*/
- void releaseModalFocus(Widget* widget);
+ void releaseModalFocus(Widget *const widget);
/**
* Releases modal mouse input focus if the widget has modal mouse input
@@ -144,7 +144,7 @@ class FocusHandler final
* @param widget the widget to release modal mouse input focus for.
* @see requestModalMouseInputFocus, Widget::releaseModalMouseInputFocus
*/
- void releaseModalMouseInputFocus(Widget* widget);
+ void releaseModalMouseInputFocus(Widget *const widget);
/**
* Checks if a widget is focused.
@@ -153,7 +153,7 @@ class FocusHandler final
* @return True if the widget is focused, false otherwise.
* @see Widget::isFocused
*/
- bool isFocused(const Widget* widget) const;
+ bool isFocused(const Widget *const widget) const;
/**
* Gets the widget with focus.
@@ -204,7 +204,7 @@ class FocusHandler final
* @param widget The widget to add.
* @see remove
*/
- void add(Widget* widget);
+ void add(Widget *const widget);
/**
* Removes a widget from the focus handler.
@@ -212,7 +212,7 @@ class FocusHandler final
* @param widget The widget to remove.
* @see add
*/
- void remove(Widget* widget);
+ void remove(Widget *const widget);
/**
* Focuses nothing. A focus event will also be sent to the
@@ -243,7 +243,7 @@ class FocusHandler final
* @return the widget being dragged.
* @see setDraggedWidget
*/
- Widget* getDraggedWidget() A_WARN_UNUSED;
+ Widget* getDraggedWidget() const A_WARN_UNUSED;
/**
* Sets the widget being dragged. Used by the Gui class to
@@ -252,7 +252,7 @@ class FocusHandler final
* @param draggedWidget The widget being dragged.
* @see getDraggedWidget
*/
- void setDraggedWidget(Widget* draggedWidget);
+ void setDraggedWidget(Widget *const draggedWidget);
/**
* Gets the last widget with the mouse. Used by the Gui class
@@ -261,7 +261,7 @@ class FocusHandler final
* @return The last widget with the mouse.
* @see setLastWidgetWithMouse
*/
- Widget* getLastWidgetWithMouse() A_WARN_UNUSED;
+ Widget* getLastWidgetWithMouse() const A_WARN_UNUSED;
/**
* Sets the last widget with the mouse. Used by the Gui class
@@ -270,7 +270,7 @@ class FocusHandler final
* @param lastWidgetWithMouse The last widget with the mouse.
* @see getLastWidgetWithMouse
*/
- void setLastWidgetWithMouse(Widget* lastWidgetWithMouse);
+ void setLastWidgetWithMouse(Widget *const lastWidgetWithMouse);
/**
* Gets the last widget with modal focus.
@@ -278,7 +278,7 @@ class FocusHandler final
* @return The last widget with modal focus.
* @see setLastWidgetWithModalFocus
*/
- Widget* getLastWidgetWithModalFocus() A_WARN_UNUSED;
+ Widget* getLastWidgetWithModalFocus() const A_WARN_UNUSED;
/**
* Sets the last widget with modal focus.
@@ -286,7 +286,7 @@ class FocusHandler final
* @param widget The last widget with modal focus.
* @see getLastWidgetWithModalFocus
*/
- void setLastWidgetWithModalFocus(Widget* widget);
+ void setLastWidgetWithModalFocus(Widget *const widget);
/**
* Gets the last widget with modal mouse input focus.
@@ -294,7 +294,7 @@ class FocusHandler final
* @return The last widget with modal mouse input focus.
* @see setLastWidgetWithModalMouseInputFocus
*/
- Widget* getLastWidgetWithModalMouseInputFocus() A_WARN_UNUSED;
+ Widget* getLastWidgetWithModalMouseInputFocus() const A_WARN_UNUSED;
/**
* Sets the last widget with modal mouse input focus.
@@ -302,7 +302,7 @@ class FocusHandler final
* @param widget The last widget with modal mouse input focus.
* @see getLastWidgetWithModalMouseInputFocus
*/
- void setLastWidgetWithModalMouseInputFocus(Widget* widget);
+ void setLastWidgetWithModalMouseInputFocus(Widget *const widget);
/**
* Gets the last widget pressed. Used by the Gui class to keep track
@@ -311,7 +311,7 @@ class FocusHandler final
* @return The last widget pressed.
* @see setLastWidgetPressed
*/
- Widget* getLastWidgetPressed() A_WARN_UNUSED;
+ Widget* getLastWidgetPressed() const A_WARN_UNUSED;
/**
* Sets the last widget pressed. Used by the Gui class to keep track
@@ -320,7 +320,7 @@ class FocusHandler final
* @param lastWidgetPressed The last widget pressed.
* @see getLastWidgetPressed
*/
- void setLastWidgetPressed(Widget* lastWidgetPressed);
+ void setLastWidgetPressed(Widget *const lastWidgetPressed);
private:
/**
diff --git a/src/gui/font.cpp b/src/gui/font.cpp
index 8c022f99d..acc27d4ab 100644
--- a/src/gui/font.cpp
+++ b/src/gui/font.cpp
@@ -76,6 +76,7 @@
#include "resources/resourcemanager.h"
#include "resources/surfaceimagehelper.h"
+#include "utils/delete2.h"
#include "utils/paths.h"
#include "utils/sdlcheckutils.h"
#include "utils/stringutils.h"
@@ -163,8 +164,7 @@ SDLTextChunk::SDLTextChunk(const std::string &text0, const Color &color0,
SDLTextChunk::~SDLTextChunk()
{
- delete img;
- img = nullptr;
+ delete2(img);
#ifdef UNITTESTS
sdlTextChunkCnt --;
#endif
@@ -294,7 +294,7 @@ void TextChunkList::insertFirst(SDLTextChunk *const item)
searchWidth[item->text] = item;
}
-void TextChunkList::moveToFirst(SDLTextChunk *item)
+void TextChunkList::moveToFirst(SDLTextChunk *const item)
{
if (item == start)
return;
diff --git a/src/gui/font.h b/src/gui/font.h
index 12ba473d8..ee1742942 100644
--- a/src/gui/font.h
+++ b/src/gui/font.h
@@ -130,7 +130,7 @@ class TextChunkList final
void insertFirst(SDLTextChunk *const item);
- void moveToFirst(SDLTextChunk *item);
+ void moveToFirst(SDLTextChunk *const item);
void removeBack();
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index deed890ae..9a50583b9 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -95,6 +95,7 @@
#include "resources/imageset.h"
#include "resources/resourcemanager.h"
+#include "utils/delete2.h"
#include "utils/langs.h"
#include "utils/timer.h"
@@ -162,8 +163,8 @@ Gui::Gui() :
mLastMouseRealY(0),
#endif
mFocusListeners(),
- mForegroundColor(Theme::getThemeColor(Theme::TEXT)),
- mForegroundColor2(Theme::getThemeColor(Theme::TEXT_OUTLINE)),
+ mForegroundColor(theme->getColor(Theme::TEXT, 255)),
+ mForegroundColor2(theme->getColor(Theme::TEXT_OUTLINE, 255)),
mTime(0),
mCustomCursor(false),
mDoubleClick(true)
@@ -290,8 +291,7 @@ void Gui::postInit(Graphics *const graphics)
Gui::~Gui()
{
config.removeListeners(mConfigListener);
- delete mConfigListener;
- mConfigListener = nullptr;
+ delete2(mConfigListener);
if (mMouseCursors)
{
@@ -299,30 +299,22 @@ Gui::~Gui()
mMouseCursors = nullptr;
}
- delete mGuiFont;
- mGuiFont = nullptr;
- delete boldFont;
- boldFont = nullptr;
- delete mHelpFont;
- mHelpFont = nullptr;
- delete mSecureFont;
- mSecureFont = nullptr;
- delete mInfoParticleFont;
- mInfoParticleFont = nullptr;
- delete mNpcFont;
- mNpcFont = nullptr;
+ delete2(mGuiFont);
+ delete2(boldFont);
+ delete2(mHelpFont);
+ delete2(mSecureFont);
+ delete2(mInfoParticleFont);
+ delete2(mNpcFont);
delete getTop();
- delete guiInput;
- guiInput = nullptr;
+ delete2(guiInput);
- Theme::deleteInstance();
+ delete2(theme);
if (Widget::widgetExists(mTop))
setTop(nullptr);
- delete mFocusHandler;
- mFocusHandler = nullptr;
+ delete2(mFocusHandler);
}
void Gui::logic()
@@ -423,21 +415,21 @@ bool Gui::handleKeyInput()
{
const KeyInput keyInput = guiInput->dequeueKeyInput();
- KeyEvent keyEventToGlobalKeyListeners(nullptr,
+ KeyEvent eventToGlobalKeyListeners(nullptr,
keyInput.getType(),
keyInput.getActionId(), keyInput.getKey());
#ifdef USE_SDL2
if (!keyInput.getText().empty())
- keyEventToGlobalKeyListeners.setText(keyInput.getText());
+ eventToGlobalKeyListeners.setText(keyInput.getText());
#endif
distributeKeyEventToGlobalKeyListeners(
- keyEventToGlobalKeyListeners);
+ eventToGlobalKeyListeners);
// If a global key listener consumes the event it will not be
// sent further to the source of the event.
- if (keyEventToGlobalKeyListeners.isConsumed())
+ if (eventToGlobalKeyListeners.isConsumed())
{
consumed = true;
continue;
@@ -445,33 +437,33 @@ bool Gui::handleKeyInput()
if (mFocusHandler)
{
- bool keyEventConsumed = false;
+ bool eventConsumed = false;
// Send key inputs to the focused widgets
if (mFocusHandler->getFocused())
{
- KeyEvent keyEvent(getKeyEventSource(),
+ KeyEvent event(getKeyEventSource(),
keyInput.getType(),
keyInput.getActionId(), keyInput.getKey());
#ifdef USE_SDL2
if (!keyInput.getText().empty())
- keyEvent.setText(keyInput.getText());
+ event.setText(keyInput.getText());
#endif
if (!mFocusHandler->getFocused()->isFocusable())
mFocusHandler->focusNone();
else
- distributeKeyEvent(keyEvent);
+ distributeKeyEvent(event);
- keyEventConsumed = keyEvent.isConsumed();
- if (keyEventConsumed)
+ eventConsumed = event.isConsumed();
+ if (eventConsumed)
consumed = true;
}
// If the key event hasn't been consumed and
// tabbing is enable check for tab press and
// change focus.
- if (!keyEventConsumed && keyInput.getActionId()
+ if (!eventConsumed && keyInput.getActionId()
== static_cast<int>(Input::KEY_GUI_TAB)
&& keyInput.getType() == KeyInput::PRESSED)
{
@@ -493,7 +485,8 @@ void Gui::draw()
getTop()->draw(mGraphics);
touchManager.draw();
- int mouseX, mouseY;
+ int mouseX;
+ int mouseY;
const uint8_t button = getMouseState(&mouseX, &mouseY);
if ((client->getMouseFocused() || button & SDL_BUTTON(1))
@@ -609,6 +602,10 @@ void Gui::handleMouseMoved(const MouseInput &mouseInput)
return;
}
+ const int mouseX = mouseInput.getX();
+ const int mouseY = mouseInput.getY();
+ const int button = mouseInput.getButton();
+
// Check if there is a need to send mouse exited events by
// traversing the "widget with mouse" queue.
bool widgetWithMouseQueueCheckDone = mWidgetWithMouseQueue.empty();
@@ -631,20 +628,21 @@ void Gui::handleMouseMoved(const MouseInput &mouseInput)
}
else
{
- int x, y;
+ int x;
+ int y;
widget->getAbsolutePosition(x, y);
- if (x > mouseInput.getX()
- || y > mouseInput.getY()
- || x + widget->getWidth() <= mouseInput.getX()
- || y + widget->getHeight() <= mouseInput.getY()
+ if (x > mouseX
+ || y > mouseY
+ || x + widget->getWidth() <= mouseX
+ || y + widget->getHeight() <= mouseY
|| !widget->isVisible())
{
distributeMouseEvent(widget,
MouseEvent::EXITED,
- mouseInput.getButton(),
- mouseInput.getX(),
- mouseInput.getY(),
+ button,
+ mouseX,
+ mouseY,
true,
true);
mClickCount = 1;
@@ -665,8 +663,7 @@ void Gui::handleMouseMoved(const MouseInput &mouseInput)
// present in the "widget with mouse" queue. If a widget
// is not then it should be added and an entered event should
// be sent to it.
- Widget* parent = getMouseEventSource(
- mouseInput.getX(), mouseInput.getY());
+ Widget* parent = getMouseEventSource(mouseX, mouseY);
Widget* widget = parent;
// If a widget has modal mouse input focus then it will
@@ -682,9 +679,9 @@ void Gui::handleMouseMoved(const MouseInput &mouseInput)
int x, y;
widget->getAbsolutePosition(x, y);
- if (x > mouseInput.getX() || y > mouseInput.getY()
- || x + widget->getWidth() <= mouseInput.getX()
- || y + widget->getHeight() <= mouseInput.getY())
+ if (x > mouseX || y > mouseY
+ || x + widget->getWidth() <= mouseX
+ || y + widget->getHeight() <= mouseY)
{
parent = nullptr;
}
@@ -713,9 +710,9 @@ void Gui::handleMouseMoved(const MouseInput &mouseInput)
{
distributeMouseEvent(widget,
MouseEvent::ENTERED,
- mouseInput.getButton(),
- mouseInput.getX(),
- mouseInput.getY(),
+ button,
+ mouseX,
+ mouseY,
true,
true);
mWidgetWithMouseQueue.push_front(widget);
@@ -731,19 +728,17 @@ void Gui::handleMouseMoved(const MouseInput &mouseInput)
distributeMouseEvent(mFocusHandler->getDraggedWidget(),
MouseEvent::DRAGGED,
mLastMouseDragButton,
- mouseInput.getX(),
- mouseInput.getY());
+ mouseX,
+ mouseY);
}
else
{
- Widget *const sourceWidget = getMouseEventSource(
- mouseInput.getX(), mouseInput.getY());
-
+ Widget *const sourceWidget = getMouseEventSource(mouseX, mouseY);
distributeMouseEvent(sourceWidget,
MouseEvent::MOVED,
- mouseInput.getButton(),
- mouseInput.getX(),
- mouseInput.getY());
+ button,
+ mouseX,
+ mouseY);
}
mMouseInactivityTimer = 0;
}
@@ -760,7 +755,8 @@ void Gui::handleMousePressed(const MouseInput &mouseInput)
if (mFocusHandler->getDraggedWidget())
sourceWidget = mFocusHandler->getDraggedWidget();
- int sourceWidgetX, sourceWidgetY;
+ int sourceWidgetX;
+ int sourceWidgetY;
sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
if ((mFocusHandler->getModalFocused()
@@ -818,28 +814,33 @@ void Gui::updateFonts()
mNpcFont->loadFont(fontFile, npcFontSize);
}
-void Gui::distributeMouseEvent(Widget* source, int type, int button,
- int x, int y, bool force,
- bool toSourceOnly)
+void Gui::distributeMouseEvent(Widget *const source,
+ const int type,
+ const int button,
+ const int x, const int y,
+ const bool force,
+ const bool toSourceOnly)
{
if (!source || !mFocusHandler)
return;
- Widget* widget = source;
+ Widget *widget = source;
- if (!force && mFocusHandler->getModalFocused() != nullptr
- && !widget->isModalFocused())
+ if (!force)
{
- return;
- }
-
- if (!force && mFocusHandler->getModalMouseInputFocused() != nullptr
- && !widget->isModalMouseInputFocused())
- {
- return;
+ if (mFocusHandler->getModalFocused() != nullptr
+ && !widget->isModalFocused())
+ {
+ return;
+ }
+ if (mFocusHandler->getModalMouseInputFocused() != nullptr
+ && !widget->isModalMouseInputFocused())
+ {
+ return;
+ }
}
- MouseEvent mouseEvent(source,
+ MouseEvent event(source,
type, button,
x, y, mClickCount);
@@ -855,49 +856,50 @@ void Gui::distributeMouseEvent(Widget* source, int type, int button,
if (widget->isEnabled() || force)
{
- int widgetX, widgetY;
+ int widgetX;
+ int widgetY;
widget->getAbsolutePosition(widgetX, widgetY);
- mouseEvent.setX(x - widgetX);
- mouseEvent.setY(y - widgetY);
+ event.setX(x - widgetX);
+ event.setY(y - widgetY);
std::list<MouseListener*> mouseListeners
- = widget->_getMouseListeners();
+ = widget->getMouseListeners();
+ unsigned int mouseType = event.getType();
// Send the event to all mouse listeners of the widget.
- for (std::list<MouseListener*>::const_iterator
- it = mouseListeners.begin();
- it != mouseListeners.end(); ++ it)
+ FOR_EACH (std::list<MouseListener*>::const_iterator,
+ it, mouseListeners)
{
- switch (mouseEvent.getType())
+ switch (mouseType)
{
case MouseEvent::ENTERED:
- (*it)->mouseEntered(mouseEvent);
+ (*it)->mouseEntered(event);
break;
case MouseEvent::EXITED:
- (*it)->mouseExited(mouseEvent);
+ (*it)->mouseExited(event);
break;
case MouseEvent::MOVED:
- (*it)->mouseMoved(mouseEvent);
+ (*it)->mouseMoved(event);
break;
case MouseEvent::PRESSED:
- (*it)->mousePressed(mouseEvent);
+ (*it)->mousePressed(event);
break;
case MouseEvent::RELEASED:
case 100: // manual hack for release on target after drag
- (*it)->mouseReleased(mouseEvent);
+ (*it)->mouseReleased(event);
break;
case MouseEvent::WHEEL_MOVED_UP:
- (*it)->mouseWheelMovedUp(mouseEvent);
+ (*it)->mouseWheelMovedUp(event);
break;
case MouseEvent::WHEEL_MOVED_DOWN:
- (*it)->mouseWheelMovedDown(mouseEvent);
+ (*it)->mouseWheelMovedDown(event);
break;
case MouseEvent::DRAGGED:
- (*it)->mouseDragged(mouseEvent);
+ (*it)->mouseDragged(event);
break;
case MouseEvent::CLICKED:
- (*it)->mouseClicked(mouseEvent);
+ (*it)->mouseClicked(event);
break;
default:
break;
@@ -915,6 +917,9 @@ void Gui::distributeMouseEvent(Widget* source, int type, int button,
if (type == MouseEvent::RELEASED)
dragDrop.clear();
+ if (event.isConsumed())
+ break;
+
// If a non modal focused widget has been reach
// and we have modal focus cancel the distribution.
if (mFocusHandler->getModalFocused()
@@ -954,7 +959,8 @@ MouseEvent *Gui::createMouseEvent(Window *const widget)
return new MouseEvent(widget,
0, 0,
- mouseX - x, mouseY - y, mClickCount);
+ mouseX - x, mouseY - y,
+ mClickCount);
}
void Gui::getAbsolutePosition(Widget *restrict widget,
@@ -1026,13 +1032,14 @@ void Gui::handleMouseReleased(const MouseInput &mouseInput)
Widget *sourceWidget = getMouseEventSource(
mouseInput.getX(), mouseInput.getY());
- int sourceWidgetX, sourceWidgetY;
+ int sourceWidgetX;
+ int sourceWidgetY;
if (mFocusHandler->getDraggedWidget())
{
if (sourceWidget != mFocusHandler->getLastWidgetPressed())
mFocusHandler->setLastWidgetPressed(nullptr);
- Widget *oldWidget = sourceWidget;
+ Widget *const oldWidget = sourceWidget;
sourceWidget = mFocusHandler->getDraggedWidget();
if (oldWidget != sourceWidget)
{
@@ -1114,9 +1121,9 @@ uint32_t Gui::getMouseState(int *const x, int *const y)
void Gui::setTop(Widget *const top)
{
if (mTop)
- mTop->_setFocusHandler(nullptr);
+ mTop->setFocusHandler(nullptr);
if (top)
- top->_setFocusHandler(mFocusHandler);
+ top->setFocusHandler(mFocusHandler);
mTop = top;
}
@@ -1188,7 +1195,7 @@ void Gui::handleMouseWheelMovedUp(const MouseInput& mouseInput)
mouseInput.getY());
}
-Widget* Gui::getWidgetAt(int x, int y)
+Widget* Gui::getWidgetAt(const int x, const int y) const
{
// If the widget's parent has no child then we have found the widget..
Widget* parent = mTop;
@@ -1206,7 +1213,7 @@ Widget* Gui::getWidgetAt(int x, int y)
return parent;
}
-Widget* Gui::getMouseEventSource(int x, int y)
+Widget* Gui::getMouseEventSource(const int x, const int y) const
{
Widget *const widget = getWidgetAt(x, y);
if (!widget)
@@ -1221,29 +1228,26 @@ Widget* Gui::getMouseEventSource(int x, int y)
return widget;
}
-Widget* Gui::getKeyEventSource()
+Widget* Gui::getKeyEventSource() const
{
Widget* widget = mFocusHandler->getFocused();
- while (widget && widget->_getInternalFocusHandler()
- && widget->_getInternalFocusHandler()->getFocused())
+ while (widget && widget->getInternalFocusHandler()
+ && widget->getInternalFocusHandler()->getFocused())
{
- widget = widget->_getInternalFocusHandler()->getFocused();
+ widget = widget->getInternalFocusHandler()->getFocused();
}
return widget;
}
-void Gui::distributeKeyEvent(KeyEvent& keyEvent) const
+void Gui::distributeKeyEvent(KeyEvent &event) const
{
- Widget* parent = keyEvent.getSource();
- Widget* widget = keyEvent.getSource();
+ Widget* parent = event.getSource();
+ Widget* widget = event.getSource();
- if (mFocusHandler->getModalFocused()
- && !widget->isModalFocused())
- {
+ if (mFocusHandler->getModalFocused() && !widget->isModalFocused())
return;
- }
if (mFocusHandler->getModalMouseInputFocused()
&& !widget->isModalMouseInputFocused())
@@ -1263,21 +1267,20 @@ void Gui::distributeKeyEvent(KeyEvent& keyEvent) const
if (widget->isEnabled())
{
std::list<KeyListener*> keyListeners
- = widget->_getKeyListeners();
+ = widget->getKeyListeners();
+ const unsigned int eventType = event.getType();
// Send the event to all key listeners of the source widget.
- for (std::list<KeyListener*>::const_iterator
- it = keyListeners.begin();
- it != keyListeners.end();
- ++ it)
+ FOR_EACH (std::list<KeyListener*>::const_iterator,
+ it, keyListeners)
{
- switch (keyEvent.getType())
+ switch (eventType)
{
case KeyEvent::PRESSED:
- (*it)->keyPressed(keyEvent);
+ (*it)->keyPressed(event);
break;
case KeyEvent::RELEASED:
- (*it)->keyReleased(keyEvent);
+ (*it)->keyReleased(event);
break;
default:
break;
@@ -1291,32 +1294,29 @@ void Gui::distributeKeyEvent(KeyEvent& keyEvent) const
// If a non modal focused widget has been reach
// and we have modal focus cancel the distribution.
- if (mFocusHandler->getModalFocused()
- && !widget->isModalFocused())
- {
+ if (mFocusHandler->getModalFocused() && !widget->isModalFocused())
break;
- }
}
}
-void Gui::distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent)
+void Gui::distributeKeyEventToGlobalKeyListeners(KeyEvent& event)
{
- for (KeyListenerListIterator it = mKeyListeners.begin();
- it != mKeyListeners.end(); ++ it)
+ const unsigned int eventType = event.getType();
+ FOR_EACH (KeyListenerListIterator, it, mKeyListeners)
{
- switch (keyEvent.getType())
+ switch (eventType)
{
case KeyEvent::PRESSED:
- (*it)->keyPressed(keyEvent);
+ (*it)->keyPressed(event);
break;
case KeyEvent::RELEASED:
- (*it)->keyReleased(keyEvent);
+ (*it)->keyReleased(event);
break;
default:
break;
}
- if (keyEvent.isConsumed())
+ if (event.isConsumed())
break;
}
}
@@ -1324,22 +1324,23 @@ void Gui::distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent)
void Gui::handleModalMouseInputFocus()
{
BLOCK_START("Gui::handleModalMouseInputFocus")
- // Check if modal mouse input focus has been gained by a widget.
- if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus()
- != mFocusHandler->getModalMouseInputFocused())
- && (!mFocusHandler->getLastWidgetWithModalMouseInputFocus()))
- {
- handleModalFocusGained();
- mFocusHandler->setLastWidgetWithModalMouseInputFocus(
- mFocusHandler->getModalMouseInputFocused());
- }
- // Check if modal mouse input focus has been released.
- else if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus()
- != mFocusHandler->getModalMouseInputFocused())
- && (mFocusHandler->getLastWidgetWithModalMouseInputFocus()))
+ Widget *const lastModalWidget
+ = mFocusHandler->getLastWidgetWithModalMouseInputFocus();
+ Widget *const modalWidget = mFocusHandler->getModalMouseInputFocused();
+ if (lastModalWidget != modalWidget)
{
- handleModalFocusReleased();
- mFocusHandler->setLastWidgetWithModalMouseInputFocus(nullptr);
+ // Check if modal mouse input focus has been gained by a widget.
+ if (!lastModalWidget)
+ {
+ handleModalFocusGained();
+ mFocusHandler->setLastWidgetWithModalMouseInputFocus(modalWidget);
+ }
+ // Check if modal mouse input focus has been released.
+ else
+ {
+ handleModalFocusReleased();
+ mFocusHandler->setLastWidgetWithModalMouseInputFocus(nullptr);
+ }
}
BLOCK_END("Gui::handleModalMouseInputFocus")
}
@@ -1347,22 +1348,24 @@ void Gui::handleModalMouseInputFocus()
void Gui::handleModalFocus()
{
BLOCK_START("Gui::handleModalFocus")
- // Check if modal focus has been gained by a widget.
- if ((mFocusHandler->getLastWidgetWithModalFocus()
- != mFocusHandler->getModalFocused())
- && (!mFocusHandler->getLastWidgetWithModalFocus()))
- {
- handleModalFocusGained();
- mFocusHandler->setLastWidgetWithModalFocus(
- mFocusHandler->getModalFocused());
- }
- // Check if modal focus has been released.
- else if ((mFocusHandler->getLastWidgetWithModalFocus()
- != mFocusHandler->getModalFocused())
- && (mFocusHandler->getLastWidgetWithModalFocus()))
+ Widget *const lastModalWidget
+ = mFocusHandler->getLastWidgetWithModalFocus();
+ Widget *const modalWidget = mFocusHandler->getModalFocused();
+
+ if (lastModalWidget != modalWidget)
{
- handleModalFocusReleased();
- mFocusHandler->setLastWidgetWithModalFocus(nullptr);
+ // Check if modal focus has been gained by a widget.
+ if (!lastModalWidget)
+ {
+ handleModalFocusGained();
+ mFocusHandler->setLastWidgetWithModalFocus(modalWidget);
+ }
+ // Check if modal focus has been released.
+ else
+ {
+ handleModalFocusReleased();
+ mFocusHandler->setLastWidgetWithModalFocus(nullptr);
+ }
}
BLOCK_END("Gui::handleModalFocus")
}
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 8805f2518..723c653ca 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -316,9 +316,12 @@ class Gui final
void handleMouseInput();
- void distributeMouseEvent(Widget* source, int type, int button,
- int x, int y, bool force = false,
- bool toSourceOnly = false);
+ void distributeMouseEvent(Widget *const source,
+ const int type,
+ const int button,
+ const int x, const int y,
+ const bool force = false,
+ const bool toSourceOnly = false);
/**
*
@@ -343,7 +346,7 @@ class Gui final
* @return The widget at a certain position.
* @since 0.6.0
*/
- Widget* getWidgetAt(int x, int y) A_WARN_UNUSED;
+ Widget* getWidgetAt(const int x, const int y) const A_WARN_UNUSED;
/**
* Gets the source of the mouse event.
@@ -351,7 +354,8 @@ class Gui final
* @return The source widget of the mouse event.
* @since 0.6.0
*/
- Widget* getMouseEventSource(int x, int y) A_WARN_UNUSED;
+ Widget* getMouseEventSource(const int x,
+ const int y) const A_WARN_UNUSED;
/**
* Gets the source of the key event.
@@ -359,25 +363,25 @@ class Gui final
* @return The source widget of the key event.
* @since 0.6.0
*/
- Widget* getKeyEventSource() A_WARN_UNUSED;
+ Widget* getKeyEventSource() const A_WARN_UNUSED;
/**
* Distributes a key event.
*
- * @param keyEvent The key event to distribute.
+ * @param event The key event to distribute.
* @since 0.6.0
*/
- void distributeKeyEvent(KeyEvent& keyEvent) const;
+ void distributeKeyEvent(KeyEvent &event) const;
/**
* Distributes a key event to the global key listeners.
*
- * @param keyEvent The key event to distribute.
+ * @param event The key event to distribute.
*
* @since 0.6.0
*/
- void distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent);
+ void distributeKeyEventToGlobalKeyListeners(KeyEvent& event);
/**
* Handles modal mouse input focus. Modal mouse input focus needs
diff --git a/src/gui/palette.h b/src/gui/palette.h
index 0dbb5d3ad..eaee3e141 100644
--- a/src/gui/palette.h
+++ b/src/gui/palette.h
@@ -101,7 +101,7 @@ class Palette
inline const Color &getColorWithAlpha(const int type) A_WARN_UNUSED
{
- Color* col = &mColors[type].color;
+ Color *const col = &mColors[type].color;
col->a = mColors[type].delay;
return *col;
}
@@ -113,7 +113,7 @@ class Palette
*
* @return the gradient type of the color with the given index
*/
- inline GradientType getGradientType(int type) const A_WARN_UNUSED
+ inline GradientType getGradientType(const int type) const A_WARN_UNUSED
{ return mColors[type].grad; }
/**
diff --git a/src/gui/popups/itempopup.h b/src/gui/popups/itempopup.h
index f1cedf046..73129eaea 100644
--- a/src/gui/popups/itempopup.h
+++ b/src/gui/popups/itempopup.h
@@ -61,7 +61,7 @@ class ItemPopup final : public Popup
void setItem(const Item *const item, const bool showImage = false);
- void mouseMoved(MouseEvent &mouseEvent) override final;
+ void mouseMoved(MouseEvent &event) override final;
private:
Label *mItemName;
diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp
index 3905d91e6..330df1a6c 100644
--- a/src/gui/popups/popupmenu.cpp
+++ b/src/gui/popups/popupmenu.cpp
@@ -840,6 +840,47 @@ void PopupMenu::showChangePos(const int x, const int y)
}
}
+void PopupMenu::showWindowPopup(Window *const window,
+ const int x, const int y)
+{
+ if (!window)
+ return;
+
+ mWindow = window;
+ mBrowserBox->clearRows();
+ // TRANSLATORS: popup menu header
+ mBrowserBox->addRow(_("window"));
+
+ if (window->getCloseButton())
+ {
+ // TRANSLATORS: popup menu item
+ // TRANSLATORS: close window
+ mBrowserBox->addRow("window close", _("Close"));
+ }
+
+ if (window->isStickyButtonLock())
+ {
+ if (window->isSticky())
+ {
+ // TRANSLATORS: popup menu item
+ // TRANSLATORS: unlock window
+ mBrowserBox->addRow("window unlock", _("Unlock"));
+ }
+ else
+ {
+ // TRANSLATORS: popup menu item
+ // TRANSLATORS: lock window
+ mBrowserBox->addRow("window lock", _("Lock"));
+ }
+ }
+
+ // TRANSLATORS: popup menu item
+ // TRANSLATORS: close menu
+ mBrowserBox->addRow("cancel", _("Cancel"));
+
+ showPopup(x, y);
+}
+
void PopupMenu::handleLink(const std::string &link,
MouseEvent *event A_UNUSED)
{
@@ -1196,8 +1237,11 @@ void PopupMenu::handleLink(const std::string &link,
}
else if (link == "retrieve" && mItem)
{
- ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove,
- mWindow, mItem);
+ if (Widget::widgetExists(mWindow))
+ {
+ ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove,
+ mWindow, mItem);
+ }
}
else if (link == "retrieve 10" && mItem)
{
@@ -1748,6 +1792,21 @@ void PopupMenu::handleLink(const std::string &link,
showGMPopup();
return;
}
+ else if (link == "window close" && mWindow)
+ {
+ if (Widget::widgetExists(mWindow))
+ mWindow->close();
+ }
+ else if (link == "window unlock" && mWindow)
+ {
+ if (Widget::widgetExists(mWindow))
+ mWindow->setSticky(false);
+ }
+ else if (link == "window lock" && mWindow)
+ {
+ if (Widget::widgetExists(mWindow))
+ mWindow->setSticky(true);
+ }
else if (!link.compare(0, 10, "guild-pos-"))
{
if (player_node)
diff --git a/src/gui/popups/popupmenu.h b/src/gui/popups/popupmenu.h
index 7eb38dc15..8bdbd3b1b 100644
--- a/src/gui/popups/popupmenu.h
+++ b/src/gui/popups/popupmenu.h
@@ -182,6 +182,8 @@ class PopupMenu final : public Popup, public LinkHandler
void showNpcDialogPopup(const int npcId, const int x, const int y);
+ void showWindowPopup(Window *const window, const int x, const int y);
+
/**
* Handles link action.
*/
diff --git a/src/gui/popups/speechbubble.h b/src/gui/popups/speechbubble.h
index 1bc5385a4..fe5cf1bfc 100644
--- a/src/gui/popups/speechbubble.h
+++ b/src/gui/popups/speechbubble.h
@@ -48,9 +48,9 @@ class SpeechBubble final : public Popup
*/
void setCaption(const std::string &name,
const Color *const color1 =
- &Theme::getThemeColor(Theme::BUBBLE_NAME),
+ &theme->getColor(Theme::BUBBLE_NAME, 255),
const Color *const color2 =
- &Theme::getThemeColor(Theme::BUBBLE_NAME_OUTLINE));
+ &theme->getColor(Theme::BUBBLE_NAME_OUTLINE, 255));
/**
* Sets the text to be displayed.
diff --git a/src/gui/popups/spellpopup.h b/src/gui/popups/spellpopup.h
index cbbd53703..0352161fc 100644
--- a/src/gui/popups/spellpopup.h
+++ b/src/gui/popups/spellpopup.h
@@ -59,7 +59,7 @@ class SpellPopup final : public Popup
*/
void view(const int x, const int y);
- void mouseMoved(MouseEvent &mouseEvent) override final;
+ void mouseMoved(MouseEvent &event) override final;
private:
Label *mItemName;
diff --git a/src/gui/popups/textpopup.h b/src/gui/popups/textpopup.h
index eb29cba61..e1dcb95b8 100644
--- a/src/gui/popups/textpopup.h
+++ b/src/gui/popups/textpopup.h
@@ -72,7 +72,7 @@ class TextPopup final : public Popup
void show(const int x, const int y, const std::string &str1,
const std::string &str2, const std::string &str3);
- void mouseMoved(MouseEvent &mouseEvent) override final;
+ void mouseMoved(MouseEvent &event) override final;
private:
Label *mText[TEXTPOPUPCOUNT];
diff --git a/src/gui/rect.cpp b/src/gui/rect.cpp
index 5f9d2bf0f..3f59d94cb 100644
--- a/src/gui/rect.cpp
+++ b/src/gui/rect.cpp
@@ -135,22 +135,10 @@ bool Rect::isIntersecting(const Rect& rectangle) const
return true;
}
-bool Rect::isPointInRect(int x_, int y_) const
+bool Rect::isPointInRect(const int x_, const int y_) const
{
return x_ >= x
&& y_ >= y
&& x_ < x + width
&& y_ < y + height;
}
-
-std::ostream& operator<<(std::ostream& out,
- const Rect& rectangle)
-{
- out << "Rect [x = " << rectangle.x
- << ", y = " << rectangle.y
- << ", width = " << rectangle.width
- << ", height = " << rectangle.height
- << "]";
-
- return out;
-}
diff --git a/src/gui/rect.h b/src/gui/rect.h
index 69c0120ca..8aee82c9f 100644
--- a/src/gui/rect.h
+++ b/src/gui/rect.h
@@ -64,8 +64,6 @@
#ifndef GUI_RECT_H
#define GUI_RECT_H
-#include <iostream>
-
#include "localconsts.h"
/**
@@ -127,16 +125,7 @@ class Rect
* @return True if the point is inside the rectangle.
* @since 0.1.0
*/
- bool isPointInRect(int x, int y) const A_WARN_UNUSED;
-
- /**
- * Output operator for output.
- *
- * @param out The stream to output to.
- * @param rectangle The rectangle to output.
- */
- friend std::ostream& operator<<(std::ostream& out,
- const Rect& rectangle);
+ bool isPointInRect(const int x, const int y) const A_WARN_UNUSED;
/**
* Holds the x coordinate of the rectangle.
diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp
index c1e02e9b2..0bc23a849 100644
--- a/src/gui/sdlinput.cpp
+++ b/src/gui/sdlinput.cpp
@@ -98,11 +98,6 @@ SDLInput::SDLInput() :
{
}
-bool SDLInput::isKeyQueueEmpty() const
-{
- return mKeyInputQueue.empty();
-}
-
KeyInput SDLInput::dequeueKeyInput()
{
if (mKeyInputQueue.empty())
@@ -114,11 +109,6 @@ KeyInput SDLInput::dequeueKeyInput()
return keyInput;
}
-bool SDLInput::isMouseQueueEmpty() const
-{
- return mMouseInputQueue.empty();
-}
-
MouseInput SDLInput::dequeueMouseInput()
{
MouseInput mouseInput;
@@ -165,7 +155,6 @@ void SDLInput::pushInput(const SDL_Event &event)
case SDL_MOUSEWHEEL:
{
-// const int x = event.wheel.x;
const int y = event.wheel.y;
if (y)
{
@@ -273,8 +262,7 @@ void SDLInput::pushInput(const SDL_Event &event)
* This occurs when the mouse leaves the window and the Gui-chan
* application loses its mousefocus.
*/
- if ((event.active.state & SDL_APPMOUSEFOCUS)
- && !event.active.gain)
+ if ((event.active.state & SDL_APPMOUSEFOCUS) && !event.active.gain)
{
mMouseInWindow = false;
@@ -288,11 +276,8 @@ void SDLInput::pushInput(const SDL_Event &event)
}
}
- if ((event.active.state & SDL_APPMOUSEFOCUS)
- && event.active.gain)
- {
+ if ((event.active.state & SDL_APPMOUSEFOCUS) && event.active.gain)
mMouseInWindow = true;
- }
break;
#endif
default:
diff --git a/src/gui/sdlinput.h b/src/gui/sdlinput.h
index 6102de743..9e7cbccb9 100644
--- a/src/gui/sdlinput.h
+++ b/src/gui/sdlinput.h
@@ -111,9 +111,11 @@ public:
// Inherited from SDLInput
- bool isKeyQueueEmpty() const A_WARN_UNUSED;
+ bool isKeyQueueEmpty() const A_WARN_UNUSED
+ { return mKeyInputQueue.empty(); }
- bool isMouseQueueEmpty() const A_WARN_UNUSED;
+ bool isMouseQueueEmpty() const A_WARN_UNUSED
+ { return mMouseInputQueue.empty(); }
MouseInput dequeueMouseInput() A_WARN_UNUSED;
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index 1a504f680..6fa007e06 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -32,6 +32,7 @@
#include "resources/image.h"
#include "resources/resourcemanager.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/files.h"
#include "utils/physfstools.h"
@@ -46,7 +47,7 @@ std::string Theme::mThemePath;
std::string Theme::mThemeName;
std::string Theme::mScreenDensity;
-Theme *Theme::mInstance = nullptr;
+Theme *theme = nullptr;
// Set the theme path...
static void initDefaultThemePath()
@@ -61,7 +62,8 @@ static void initDefaultThemePath()
defaultThemePath = "themes/";
}
-Skin::Skin(ImageRect *restrict skin, const ImageRect *restrict images,
+Skin::Skin(ImageRect *const restrict skin,
+ const ImageRect *const restrict images,
const std::string &filePath, const std::string &name,
const int padding, const int titlePadding,
std::map<std::string, int> *restrict const options):
@@ -120,10 +122,8 @@ Skin::~Skin()
mStickyImageDown = nullptr;
}
- delete mOptions;
- mOptions = nullptr;
- delete mBorder;
- mBorder = nullptr;
+ delete2(mOptions);
+ delete2(mBorder);
}
void Skin::updateAlpha(const float minimumOpacityAllowed)
@@ -245,27 +245,13 @@ Theme::~Theme()
delete_all(mProgressColors);
}
-Theme *Theme::instance()
-{
- if (!mInstance)
- mInstance = new Theme;
-
- return mInstance;
-}
-
-void Theme::deleteInstance()
-{
- delete mInstance;
- mInstance = nullptr;
-}
-
Color Theme::getProgressColor(const int type, const float progress)
{
int color[3] = {0, 0, 0};
- if (mInstance)
+ if (theme)
{
- const DyePalette *const dye = mInstance->mProgressColors[type];
+ const DyePalette *const dye = theme->mProgressColors[type];
if (dye)
dye->getColor(progress, color);
@@ -276,8 +262,10 @@ Color Theme::getProgressColor(const int type, const float progress)
return Color(color[0], color[1], color[2]);
}
-Skin *Theme::load(const std::string &filename, const std::string &filename2,
- const bool full, const std::string &restrict defaultPath)
+Skin *Theme::load(const std::string &filename,
+ const std::string &filename2,
+ const bool full,
+ const std::string &restrict defaultPath)
{
// Check if this skin was already loaded
@@ -380,8 +368,9 @@ void Theme::updateAlpha()
{
FOR_EACH (SkinIterator, iter, mSkins)
{
- if (iter->second)
- iter->second->updateAlpha(mMinimumOpacity);
+ Skin *const skin = iter->second;
+ if (skin)
+ skin->updateAlpha(mMinimumOpacity);
}
}
@@ -474,9 +463,10 @@ struct SkinHelper final
{
for (unsigned f = 0; f < size; f ++)
{
- if (partType == params[f].name)
+ const SkinParameter &param = params[f];
+ if (partType == param.name)
{
- rect->grid[params[f].index] = resman->getSubImage(
+ rect->grid[param.index] = resman->getSubImage(
image, xPos, yPos, width, height);
return true;
}
@@ -639,8 +629,8 @@ bool Theme::tryThemePath(const std::string &themeName)
{
mThemePath = path;
mThemeName = themeName;
- if (instance())
- instance()->loadColors("");
+ if (theme)
+ theme->loadColors("");
return true;
}
}
@@ -703,7 +693,7 @@ void Theme::prepareThemePath()
if (mThemePath.empty())
mThemePath = "graphics/gui";
- instance()->loadColors(mThemePath);
+ theme->loadColors(mThemePath);
logger->log("Selected Theme: " + mThemePath);
}
@@ -1040,6 +1030,7 @@ static int readProgressType(const std::string &type)
static const std::string colors[Theme::THEME_PROG_END] =
{
"HP",
+ "HP_POISON",
"MP",
"NO_MP",
"EXP",
@@ -1082,16 +1073,12 @@ void Theme::loadColors(std::string file)
logger->log("Loading colors file: %s", file.c_str());
- int type;
- std::string temp;
- Color color;
- GradientType grad;
-
for_each_xml_child_node(paletteNode, root)
{
if (xmlNameEqual(paletteNode, "progressbar"))
{
- type = readProgressType(XML::getProperty(paletteNode, "id", ""));
+ const int type = readProgressType(XML::getProperty(
+ paletteNode, "id", ""));
if (type < 0)
continue;
@@ -1112,16 +1099,17 @@ void Theme::loadColors(std::string file)
if (xmlNameEqual(node, "color"))
{
const std::string id = XML::getProperty(node, "id", "");
- type = readColorType(id);
+ const int type = readColorType(id);
if (type < 0)
continue;
- temp = XML::getProperty(node, "color", "");
+ const std::string temp = XML::getProperty(node, "color", "");
if (temp.empty())
continue;
- color = readColor(temp);
- grad = readColorGradient(XML::getProperty(node, "effect", ""));
+ const Color color = readColor(temp);
+ const GradientType grad = readColorGradient(
+ XML::getProperty(node, "effect", ""));
mColors[paletteId * THEME_COLORS_END + type].set(
type, color, grad, 10);
@@ -1138,9 +1126,11 @@ void Theme::loadColors(std::string file)
}
}
-void Theme::loadRect(ImageRect &image, const std::string &name,
+void Theme::loadRect(ImageRect &image,
+ const std::string &name,
const std::string &name2,
- const int start, const int end)
+ const int start,
+ const int end)
{
Skin *const skin = load(name, name2, false);
if (skin)
@@ -1158,8 +1148,10 @@ void Theme::loadRect(ImageRect &image, const std::string &name,
}
}
-Skin *Theme::loadSkinRect(ImageRect &image, const std::string &name,
- const std::string &name2, const int start,
+Skin *Theme::loadSkinRect(ImageRect &image,
+ const std::string &name,
+ const std::string &name2,
+ const int start,
const int end)
{
Skin *const skin = load(name, name2);
@@ -1178,7 +1170,8 @@ Skin *Theme::loadSkinRect(ImageRect &image, const std::string &name,
return skin;
}
-void Theme::unloadRect(const ImageRect &rect, const int start,
+void Theme::unloadRect(const ImageRect &rect,
+ const int start,
const int end)
{
for (int f = start; f <= end; f ++)
@@ -1191,7 +1184,9 @@ void Theme::unloadRect(const ImageRect &rect, const int start,
Image *Theme::getImageFromThemeXml(const std::string &name,
const std::string &name2)
{
- Theme *const theme = Theme::instance();
+ if (!theme)
+ return nullptr;
+
Skin *const skin = theme->load(name, name2, false);
if (skin)
{
@@ -1212,7 +1207,9 @@ ImageSet *Theme::getImageSetFromThemeXml(const std::string &name,
const std::string &name2,
const int w, const int h)
{
- Theme *const theme = Theme::instance();
+ if (!theme)
+ return nullptr;
+
Skin *const skin = theme->load(name, name2, false);
if (skin)
{
@@ -1265,7 +1262,7 @@ ThemeInfo *Theme::loadInfo(const std::string &themeName)
if (!rootNode || !xmlNameEqual(rootNode, "info"))
return nullptr;
- ThemeInfo *info = new ThemeInfo();
+ ThemeInfo *const info = new ThemeInfo();
const std::string fontSize2("fontSize_" + mScreenDensity);
const std::string npcfontSize2("npcfontSize_" + mScreenDensity);
diff --git a/src/gui/theme.h b/src/gui/theme.h
index 86543ea64..023918cf0 100644
--- a/src/gui/theme.h
+++ b/src/gui/theme.h
@@ -40,9 +40,12 @@
class DyePalette;
class Image;
class ImageSet;
+class Theme;
const int THEME_PALETTES = 5;
+extern Theme *theme;
+
struct ThemeInfo final
{
ThemeInfo() :
@@ -79,9 +82,12 @@ struct ThemeInfo final
class Skin final
{
public:
- Skin(ImageRect *restrict skin, const ImageRect *restrict images,
- const std::string &filePath, const std::string &name = "",
- const int padding = 3, const int titlePadding = 4,
+ Skin(ImageRect *const restrict skin,
+ const ImageRect *const restrict images,
+ const std::string &filePath,
+ const std::string &name = "",
+ const int padding = 3,
+ const int titlePadding = 4,
std::map<std::string, int> *restrict const options = nullptr);
A_DELETE_COPY(Skin)
@@ -173,14 +179,15 @@ class Skin final
std::map<std::string, int> *mOptions;
};
-class Theme final : public Palette, public ConfigListener
+class Theme final : public Palette,
+ public ConfigListener
{
public:
- A_DELETE_COPY(Theme)
+ Theme();
- static Theme *instance() A_WARN_UNUSED;
+ ~Theme();
- static void deleteInstance();
+ A_DELETE_COPY(Theme)
static void prepareThemePath();
@@ -428,6 +435,7 @@ class Theme final : public Palette, public ConfigListener
enum ProgressPalette
{
PROG_HP = 0,
+ PROG_HP_POISON,
PROG_MP,
PROG_NO_MP,
PROG_EXP,
@@ -441,40 +449,22 @@ class Theme final : public Palette, public ConfigListener
THEME_PROG_END
};
- /**
- * Gets the color associated with the type. Sets the alpha channel
- * before returning.
- *
- * @param type the color type requested
- * @param alpha alpha channel to use
- *
- * @return the requested color
- */
- inline static const Color &getThemeColor(const int type,
- const int alpha = 255)
- A_WARN_UNUSED
- { return mInstance->getColor(type, alpha); }
-
- static const Color &getThemeCharColor(const signed char c,
- bool &valid) A_WARN_UNUSED
- { return mInstance->getCharColor(c, valid); }
-
- static int getThemeIdByChar(const signed char c,
- bool &valid) A_WARN_UNUSED
- { return mInstance->getIdByChar(c, valid); }
-
static Color getProgressColor(const int type,
const float progress) A_WARN_UNUSED;
/**
* Loads a skin.
*/
- Skin *load(const std::string &filename, const std::string &filename2,
- const bool full = true, const std::string
+ Skin *load(const std::string &filename,
+ const std::string &filename2,
+ const bool full = true,
+ const std::string
&restrict defaultPath = getThemePath()) A_WARN_UNUSED;
- Skin *loadSkinRect(ImageRect &image, const std::string &name,
- const std::string &name2, const int start = 0,
+ Skin *loadSkinRect(ImageRect &image,
+ const std::string &name,
+ const std::string &name2,
+ const int start = 0,
const int end = 8) A_WARN_UNUSED;
void unload(Skin *const skin);
@@ -498,8 +488,10 @@ class Theme final : public Palette, public ConfigListener
void optionChanged(const std::string &) override final;
- void loadRect(ImageRect &image, const std::string &name,
- const std::string &name2, const int start = 0,
+ void loadRect(ImageRect &image,
+ const std::string &name,
+ const std::string &name2,
+ const int start = 0,
const int end = 8);
static void unloadRect(const ImageRect &rect,
@@ -513,10 +505,6 @@ class Theme final : public Palette, public ConfigListener
static ThemeInfo *loadInfo(const std::string &themeName) A_WARN_UNUSED;
private:
- Theme();
-
- ~Theme();
-
Skin *readSkin(const std::string &filename0,
const bool full) A_WARN_UNUSED;
@@ -529,7 +517,6 @@ class Theme final : public Palette, public ConfigListener
static std::string mThemePath;
static std::string mThemeName;
static std::string mScreenDensity;
- static Theme *mInstance;
static bool tryThemePath(const std::string &themePath) A_WARN_UNUSED;
diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp
index 74d47203f..d6fb35192 100644
--- a/src/gui/userpalette.cpp
+++ b/src/gui/userpalette.cpp
@@ -234,8 +234,10 @@ UserPalette::~UserPalette()
}
}
-void UserPalette::setColor(const int type, const int r,
- const int g, const int b)
+void UserPalette::setColor(const int type,
+ const int r,
+ const int g,
+ const int b)
{
Color &color = mColors[type].color;
color.r = r;
@@ -311,7 +313,7 @@ void UserPalette::rollback()
}
}
-int UserPalette::getColorTypeAt(int i)
+int UserPalette::getColorTypeAt(const int i)
{
if (i < 0 || i >= getNumberOfElements())
return BEING;
@@ -319,7 +321,8 @@ int UserPalette::getColorTypeAt(int i)
return mColors[i].type;
}
-void UserPalette::addColor(const unsigned type, const unsigned rgb,
+void UserPalette::addColor(const unsigned type,
+ const unsigned rgb,
Palette::GradientType grad,
const std::string &text,
int delay)
diff --git a/src/gui/userpalette.h b/src/gui/userpalette.h
index 7bab5bed9..da8252340 100644
--- a/src/gui/userpalette.h
+++ b/src/gui/userpalette.h
@@ -186,7 +186,7 @@ class UserPalette final : public Palette, public ListModel
*
* @return the color type of the color with the given index
*/
- int getColorTypeAt(int i) A_WARN_UNUSED;
+ int getColorTypeAt(const int i) A_WARN_UNUSED;
private:
/**
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index c2000b562..df97a5673 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -35,6 +35,7 @@
#include "input/inputmanager.h"
#include "gui/gui.h"
+#include "gui/font.h"
#include "gui/popups/beingpopup.h"
#include "gui/popups/popupmenu.h"
@@ -42,7 +43,7 @@
#include "gui/windows/ministatuswindow.h"
-#include "gui/font.h"
+#include "utils/delete2.h"
#include "debug.h"
@@ -104,12 +105,9 @@ Viewport::~Viewport()
{
config.removeListeners(this);
CHECKLISTENERS
- delete mPopupMenu;
- mPopupMenu = nullptr;
- delete mBeingPopup;
- mBeingPopup = nullptr;
- delete mTextPopup;
- mTextPopup = nullptr;
+ delete2(mPopupMenu);
+ delete2(mBeingPopup);
+ delete2(mTextPopup);
}
void Viewport::setMap(Map *const map)
@@ -235,7 +233,7 @@ void Viewport::draw(Graphics *graphics)
mMap->drawCollision(graphics, mPixelViewX,
mPixelViewY, mShowDebugPath);
if (mShowDebugPath == Map::MAP_DEBUG)
- _drawDebugPath(graphics);
+ drawDebugPath(graphics);
}
if (player_node->getCheckNameSetting())
@@ -272,11 +270,11 @@ void Viewport::logic()
BLOCK_START("Viewport::logic")
// Make the player follow the mouse position
// if the mouse is dragged elsewhere than in a window.
- _followMouse();
+ followMouse();
BLOCK_END("Viewport::logic")
}
-void Viewport::_followMouse()
+void Viewport::followMouse()
{
if (!gui)
return;
@@ -285,18 +283,18 @@ void Viewport::_followMouse()
if (mPlayerFollowMouse && (button & SDL_BUTTON(1)))
{
// We create a mouse event and send it to mouseDragged.
- MouseEvent mouseEvent(nullptr,
+ MouseEvent event(nullptr,
MouseEvent::DRAGGED,
MouseEvent::LEFT,
mMouseX,
mMouseY,
0);
- walkByMouse(mouseEvent);
+ walkByMouse(event);
}
}
-void Viewport::_drawDebugPath(Graphics *const graphics)
+void Viewport::drawDebugPath(Graphics *const graphics)
{
if (!player_node || !userPalette || !actorManager || !mMap || !gui)
return;
@@ -322,7 +320,7 @@ void Viewport::_drawDebugPath(Graphics *const graphics)
500);
lastMouseDestination = mouseDestination;
}
- _drawPath(graphics, debugPath, userPalette->getColorWithAlpha(
+ drawPath(graphics, debugPath, userPalette->getColorWithAlpha(
UserPalette::ROAD_POINT));
const ActorSprites &actors = actorManager->getAll();
@@ -332,14 +330,15 @@ void Viewport::_drawDebugPath(Graphics *const graphics)
if (being && being != player_node)
{
const Path &beingPath = being->getPath();
- _drawPath(graphics, beingPath, userPalette->getColorWithAlpha(
+ drawPath(graphics, beingPath, userPalette->getColorWithAlpha(
UserPalette::ROAD_POINT));
}
}
}
-void Viewport::_drawPath(Graphics *const graphics, const Path &path,
- const Color &color) const
+void Viewport::drawPath(Graphics *const graphics,
+ const Path &path,
+ const Color &color) const
{
graphics->setColor(color);
Font *const font = getFont();
@@ -477,7 +476,7 @@ bool Viewport::leftMouseAction()
mPlayerFollowMouse = true;
// Make the player go to the mouse position
- _followMouse();
+ followMouse();
}
return false;
}
@@ -547,9 +546,9 @@ void Viewport::walkByMouse(const MouseEvent &event)
{
if (!mMap || !player_node)
return;
- if (mPlayerFollowMouse && !inputManager.isActionActive(
- Input::KEY_STOP_ATTACK) && !inputManager.isActionActive(
- Input::KEY_UNTARGET))
+ if (mPlayerFollowMouse
+ && !inputManager.isActionActive(Input::KEY_STOP_ATTACK)
+ && !inputManager.isActionActive(Input::KEY_UNTARGET))
{
if (!mMouseDirectionMove)
mPlayerFollowMouse = false;
@@ -712,8 +711,10 @@ void Viewport::mouseReleased(MouseEvent &event)
}
}
-void Viewport::showPopup(Window *const parent, const int x, const int y,
- Item *const item, const bool isInventory)
+void Viewport::showPopup(Window *const parent,
+ const int x, const int y,
+ Item *const item,
+ const bool isInventory)
{
mPopupMenu->showPopup(parent, x, y, item, isInventory);
}
@@ -723,7 +724,8 @@ void Viewport::showPopup(MapItem *const item)
mPopupMenu->showPopup(mMouseX, mMouseY, item);
}
-void Viewport::showPopup(Window *const parent, Item *const item,
+void Viewport::showPopup(Window *const parent,
+ Item *const item,
const bool isInventory)
{
mPopupMenu->showPopup(parent, mMouseX, mMouseY, item, isInventory);
@@ -734,7 +736,8 @@ void Viewport::showItemPopup(Item *const item)
mPopupMenu->showItemPopup(mMouseX, mMouseY, item);
}
-void Viewport::showItemPopup(const int itemId, const unsigned char color)
+void Viewport::showItemPopup(const int itemId,
+ const unsigned char color)
{
mPopupMenu->showItemPopup(mMouseX, mMouseY, itemId, color);
}
@@ -759,7 +762,8 @@ void Viewport::showSpellPopup(TextCommand *const cmd)
mPopupMenu->showSpellPopup(mMouseX, mMouseY, cmd);
}
-void Viewport::showChatPopup(const int x, const int y, ChatTab *const tab)
+void Viewport::showChatPopup(const int x, const int y,
+ ChatTab *const tab)
{
mPopupMenu->showChatPopup(x, y, tab);
}
@@ -769,7 +773,8 @@ void Viewport::showChatPopup(ChatTab *const tab)
mPopupMenu->showChatPopup(mMouseX, mMouseY, tab);
}
-void Viewport::showPopup(const int x, const int y, const Being *const being)
+void Viewport::showPopup(const int x, const int y,
+ const Being *const being)
{
mPopupMenu->showPopup(x, y, being);
}
@@ -784,7 +789,8 @@ void Viewport::showPlayerPopup(const std::string &nick)
mPopupMenu->showPlayerPopup(mMouseX, mMouseY, nick);
}
-void Viewport::showPopup(const int x, const int y, Button *const button)
+void Viewport::showPopup(const int x, const int y,
+ Button *const button)
{
mPopupMenu->showPopup(x, y, button);
}
@@ -795,7 +801,8 @@ void Viewport::showPopup(const int x, const int y,
mPopupMenu->showPopup(x, y, bar);
}
-void Viewport::showAttackMonsterPopup(const std::string &name, const int type)
+void Viewport::showAttackMonsterPopup(const std::string &name,
+ const int type)
{
mPopupMenu->showAttackMonsterPopup(mMouseX, mMouseY, name, type);
}
@@ -806,7 +813,8 @@ void Viewport::showPickupItemPopup(const std::string &name)
}
void Viewport::showUndressPopup(const int x, const int y,
- const Being *const being, Item *const item)
+ const Being *const being,
+ Item *const item)
{
mPopupMenu->showUndressPopup(x, y, being, item);
}
@@ -836,6 +844,11 @@ void Viewport::showNpcDialogPopup(const int npcId)
mPopupMenu->showNpcDialogPopup(npcId, mMouseX, mMouseY);
}
+void Viewport::showWindowPopup(Window *const window)
+{
+ mPopupMenu->showWindowPopup(window, mMouseX, mMouseY);
+}
+
void Viewport::closePopupMenu()
{
if (mPopupMenu)
@@ -869,10 +882,14 @@ void Viewport::mouseMoved(MouseEvent &event A_UNUSED)
const int x = mMouseX + mPixelViewX;
const int y = mMouseY + mPixelViewY;
+ ActorSprite::Type type = ActorSprite::UNKNOWN;
+ if (mHoverBeing)
+ type = mHoverBeing->getType();
mHoverBeing = actorManager->findBeingByPixel(x, y, true);
- if (mHoverBeing && (mHoverBeing->getType() == Being::PLAYER
- || mHoverBeing->getType() == Being::NPC
- || mHoverBeing->getType() == Being::PET))
+ if (mHoverBeing
+ && (type == Being::PLAYER
+ || type == Being::NPC
+ || type == Being::PET))
{
mTextPopup->setVisible(false);
if (mShowBeingPopup)
@@ -920,7 +937,7 @@ void Viewport::mouseMoved(MouseEvent &event A_UNUSED)
if (mHoverBeing)
{
- switch (mHoverBeing->getType())
+ switch (type)
{
case ActorSprite::NPC:
gui->setCursorType(mHoverBeing->getHoverCursor());
@@ -1013,7 +1030,8 @@ bool Viewport::isPopupMenuVisible() const
return mPopupMenu ? mPopupMenu->isPopupVisible() : false;
}
-void Viewport::moveCameraToActor(const int actorId, const int x, const int y)
+void Viewport::moveCameraToActor(const int actorId,
+ const int x, const int y)
{
if (!player_node || !actorManager)
return;
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index c98350744..d401a3af4 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -124,32 +124,39 @@ class Viewport final : public WindowContainer,
* Shows a popup for an item.
* TODO Find some way to get rid of Item here
*/
- void showPopup(Window *const parent, const int x, const int y,
- Item *const item, const bool isInventory = true);
+ void showPopup(Window *const parent,
+ const int x, const int y,
+ Item *const item,
+ const bool isInventory = true);
/**
* Shows a popup for an item.
* TODO Find some way to get rid of Item here
*/
- void showPopup(Window *const parent, Item *const item,
+ void showPopup(Window *const parent,
+ Item *const item,
const bool isInventory = true);
- void showPopup(const int x, const int y, Button *const button);
+ void showPopup(const int x, const int y,
+ Button *const button);
- void showPopup(const int x, const int y, const ProgressBar *const bar);
+ void showPopup(const int x, const int y,
+ const ProgressBar *const bar);
void showPopup(MapItem *const item);
void showItemPopup(Item *const item);
- void showItemPopup(const int itemId, const unsigned char color = 1);
+ void showItemPopup(const int itemId,
+ const unsigned char color = 1);
void showDropPopup(Item *const item);
/**
* Shows a popup for being.
*/
- void showPopup(const int x, const int y, const Being *const being);
+ void showPopup(const int x, const int y,
+ const Being *const being);
void showPopup(const Being *const being);
@@ -161,7 +168,8 @@ class Viewport final : public WindowContainer,
void showSpellPopup(TextCommand *const cmd);
- void showAttackMonsterPopup(const std::string &name, const int type);
+ void showAttackMonsterPopup(const std::string &name,
+ const int type);
void showPickupItemPopup(const std::string &name);
@@ -169,7 +177,8 @@ class Viewport final : public WindowContainer,
* Shows the related popup menu when right click on the chat
* at the specified mouse coordinates.
*/
- void showChatPopup(const int x, const int y, ChatTab *const tab);
+ void showChatPopup(const int x, const int y,
+ ChatTab *const tab);
/**
* Shows the related popup menu when right click on the chat
@@ -177,7 +186,8 @@ class Viewport final : public WindowContainer,
void showChatPopup(ChatTab *const tab);
void showUndressPopup(const int x, const int y,
- const Being *const being, Item *const item);
+ const Being *const being,
+ Item *const item);
void showMapPopup(const int x, const int y);
@@ -189,6 +199,8 @@ class Viewport final : public WindowContainer,
void showNpcDialogPopup(const int npcId);
+ void showWindowPopup(Window *const window);
+
/**
* Closes the popup menu. Needed for when the player dies or switching
* maps.
@@ -268,7 +280,8 @@ class Viewport final : public WindowContainer,
bool isPopupMenuVisible() const A_WARN_UNUSED;
- void moveCameraToActor(const int actorId, const int x = 0,
+ void moveCameraToActor(const int actorId,
+ const int x = 0,
const int y = 0);
void moveCameraToPosition(const int x, const int y);
@@ -292,13 +305,14 @@ class Viewport final : public WindowContainer,
* Finds a path from the player to the mouse, and draws it. This is for
* debug purposes.
*/
- void _drawDebugPath(Graphics *const graphics);
+ void drawDebugPath(Graphics *const graphics);
/**
* Draws the given path.
*/
- void _drawPath(Graphics *const graphics, const Path &path,
- const Color &color = Color(255, 0, 0)) const;
+ void drawPath(Graphics *const graphics,
+ const Path &path,
+ const Color &color = Color(255, 0, 0)) const;
bool leftMouseAction();
@@ -309,7 +323,7 @@ class Viewport final : public WindowContainer,
/**
* Make the player go to the mouse position.
*/
- void _followMouse();
+ void followMouse();
Map *mMap; /**< The current map. */
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
index 01126f8ac..9411c2249 100644
--- a/src/gui/widgets/avatarlistbox.cpp
+++ b/src/gui/widgets/avatarlistbox.cpp
@@ -154,14 +154,16 @@ void AvatarListBox::draw(Graphics *graphics)
text = strprintf("%s %d/%d", a->getComplexName().c_str(),
a->getHp(), a->getMaxHp());
}
- if (parent && a->getMaxHp())
+ const bool isPoison = a->getPoison();
+ if (a->getMaxHp() && (isPoison || parent))
{
+ const int themeColor = (isPoison
+ ? Theme::PROG_HP_POISON : Theme::PROG_HP);
Color color = Theme::getProgressColor(
- Theme::PROG_HP, static_cast<float>(a->getHp())
- / static_cast<float>(a->getMaxHp()));
+ themeColor, static_cast<float>(a->getHp())
+ / static_cast<float>(a->getMaxHp()));
color.a = 80;
graphics->setColor(color);
-
graphics->fillRectangle(Rect(mPadding, y + mPadding,
parent->getWidth() * a->getHp() / a->getMaxHp()
- 2 * mPadding, fontHeight));
@@ -182,8 +184,9 @@ void AvatarListBox::draw(Graphics *graphics)
if (parent)
{
- Color color = Theme::getProgressColor(Theme::PROG_HP, 1);
-
+ const int themeColor = (a->getPoison()
+ ? Theme::PROG_HP_POISON : Theme::PROG_HP);
+ Color color = Theme::getProgressColor(themeColor, 1);
color.a = 80;
graphics->setColor(color);
graphics->fillRectangle(Rect(mPadding, y + mPadding,
@@ -332,6 +335,7 @@ void AvatarListBox::mousePressed(MouseEvent &event)
if (!ava)
return;
+ event.consume();
const unsigned int eventButton = event.getButton();
if (eventButton == MouseEvent::LEFT)
{
diff --git a/src/gui/widgets/basiccontainer.cpp b/src/gui/widgets/basiccontainer.cpp
index d3dd62fc7..00386a725 100644
--- a/src/gui/widgets/basiccontainer.cpp
+++ b/src/gui/widgets/basiccontainer.cpp
@@ -74,13 +74,21 @@ BasicContainer::~BasicContainer()
void BasicContainer::moveToTop(Widget* widget)
{
- for (WidgetListIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
+ FOR_EACH (WidgetListIterator, iter, mWidgets)
{
if (*iter == widget)
{
mWidgets.erase(iter);
mWidgets.push_back(widget);
+ break;
+ }
+ }
+ FOR_EACH (WidgetListIterator, iter, mLogicWidgets)
+ {
+ if (*iter == widget)
+ {
+ mLogicWidgets.erase(iter);
+ mLogicWidgets.push_back(widget);
return;
}
}
@@ -88,30 +96,39 @@ void BasicContainer::moveToTop(Widget* widget)
void BasicContainer::moveToBottom(Widget* widget)
{
- WidgetListIterator iter;
- iter = std::find(mWidgets.begin(), mWidgets.end(), widget);
-
- if (iter == mWidgets.end())
- return;
+ WidgetListIterator iter = std::find(mWidgets.begin(),
+ mWidgets.end(), widget);
+ if (iter != mWidgets.end())
+ {
+ mWidgets.erase(iter);
+ mWidgets.insert(mWidgets.begin(), widget);
+ }
- mWidgets.erase(iter);
- mWidgets.insert(mWidgets.begin(), widget);
+ WidgetListIterator iter2 = std::find(mLogicWidgets.begin(),
+ mLogicWidgets.end(), widget);
+ if (iter2 != mLogicWidgets.end())
+ {
+ mLogicWidgets.erase(iter2);
+ mLogicWidgets.insert(mLogicWidgets.begin(), widget);
+ }
}
-void BasicContainer::death(const Event& event)
+void BasicContainer::death(const Event &event)
{
- WidgetListIterator iter;
- iter = std::find(mWidgets.begin(), mWidgets.end(), event.getSource());
-
- if (iter == mWidgets.end())
- return;
-
- mWidgets.erase(iter);
+ WidgetListIterator iter = std::find(mWidgets.begin(),
+ mWidgets.end(), event.getSource());
+ if (iter != mWidgets.end())
+ mWidgets.erase(iter);
+
+ WidgetListIterator iter2 = std::find(mLogicWidgets.begin(),
+ mLogicWidgets.end(), event.getSource());
+ if (iter2 != mLogicWidgets.end())
+ mLogicWidgets.erase(iter2);
}
Rect BasicContainer::getChildrenArea()
{
- return Rect(0, 0, getWidth(), getHeight());
+ return Rect(0, 0, mDimension.width, mDimension.height);
}
void BasicContainer::focusNext()
@@ -185,12 +202,13 @@ Widget *BasicContainer::getWidgetAt(int x, int y)
y -= r.y;
for (WidgetListReverseIterator it = mWidgets.rbegin();
- it != mWidgets.rend(); ++ it)
+ it != mWidgets.rend(); ++ it)
{
- if ((*it)->isVisible() && (*it)->getDimension()
+ const Widget *const widget = *it;
+ if (widget->isVisible() && widget->getDimension()
.isPointInRect(x, y))
{
- return (*it);
+ return *it;
}
}
@@ -200,48 +218,59 @@ Widget *BasicContainer::getWidgetAt(int x, int y)
void BasicContainer::logic()
{
BLOCK_START("BasicContainer::logic")
+ if (!mVisible)
+ {
+ BLOCK_END("BasicContainer::logic")
+ return;
+ }
logicChildren();
BLOCK_END("BasicContainer::logic")
}
-void BasicContainer::_setFocusHandler(FocusHandler* focusHandler)
+void BasicContainer::setFocusHandler(FocusHandler *const focusHandler)
{
- Widget::_setFocusHandler(focusHandler);
+ Widget::setFocusHandler(focusHandler);
if (mInternalFocusHandler)
return;
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
- {
- (*iter)->_setFocusHandler(focusHandler);
- }
+ FOR_EACH (WidgetListConstIterator, iter, mWidgets)
+ (*iter)->setFocusHandler(focusHandler);
}
-void BasicContainer::add(Widget* widget)
+void BasicContainer::add(Widget *const widget)
{
mWidgets.push_back(widget);
+ if (widget->isAllowLogic())
+ mLogicWidgets.push_back(widget);
if (!mInternalFocusHandler)
- widget->_setFocusHandler(_getFocusHandler());
+ widget->setFocusHandler(getFocusHandler());
else
- widget->_setFocusHandler(mInternalFocusHandler);
+ widget->setFocusHandler(mInternalFocusHandler);
- widget->_setParent(this);
+ widget->setParent(this);
widget->addDeathListener(this);
}
void BasicContainer::remove(Widget* widget)
{
- for (WidgetListIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
+ FOR_EACH (WidgetListIterator, iter, mWidgets)
{
if (*iter == widget)
{
mWidgets.erase(iter);
- widget->_setFocusHandler(nullptr);
- widget->_setParent(nullptr);
+ widget->setFocusHandler(nullptr);
+ widget->setParent(nullptr);
widget->removeDeathListener(this);
+ break;
+ }
+ }
+ FOR_EACH (WidgetListIterator, iter, mLogicWidgets)
+ {
+ if (*iter == widget)
+ {
+ mLogicWidgets.erase(iter);
return;
}
}
@@ -249,35 +278,34 @@ void BasicContainer::remove(Widget* widget)
void BasicContainer::clear()
{
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
+ FOR_EACH (WidgetListConstIterator, iter, mWidgets)
{
- (*iter)->_setFocusHandler(nullptr);
- (*iter)->_setParent(nullptr);
- (*iter)->removeDeathListener(this);
+ Widget *const widget = *iter;
+ widget->setFocusHandler(nullptr);
+ widget->setParent(nullptr);
+ widget->removeDeathListener(this);
}
mWidgets.clear();
+ mLogicWidgets.clear();
}
void BasicContainer::drawChildren(Graphics* graphics)
{
BLOCK_START("BasicContainer::drawChildren")
-
graphics->pushClipArea(getChildrenArea());
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
+ FOR_EACH (WidgetListConstIterator, iter, mWidgets)
{
Widget *const widget = *iter;
if (widget->isVisible())
{
// If the widget has a frame,
// draw it before drawing the widget
- if (widget->getFrameSize() > 0)
+ if (widget->mFrameSize > 0)
{
- Rect rec = widget->getDimension();
- const int frame = widget->getFrameSize();
+ Rect rec = widget->mDimension;
+ const int frame = widget->mFrameSize;
const int frame2 = frame * 2;
rec.x -= frame;
rec.y -= frame;
@@ -290,7 +318,7 @@ void BasicContainer::drawChildren(Graphics* graphics)
graphics->popClipArea();
}
- graphics->pushClipArea(widget->getDimension());
+ graphics->pushClipArea(widget->mDimension);
BLOCK_START("BasicContainer::drawChildren 2")
widget->draw(graphics);
BLOCK_END("BasicContainer::drawChildren 2")
@@ -305,11 +333,8 @@ void BasicContainer::drawChildren(Graphics* graphics)
void BasicContainer::logicChildren()
{
BLOCK_START("BasicContainer::logicChildren")
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
- {
+ FOR_EACH (WidgetListConstIterator, iter, mLogicWidgets)
(*iter)->logic();
- }
BLOCK_END("BasicContainer::logicChildren")
}
@@ -317,61 +342,33 @@ void BasicContainer::showWidgetPart(Widget *const widget, Rect area)
{
const Rect widgetArea = getChildrenArea();
- area.x += widget->getX();
- area.y += widget->getY();
+ const int x = widget->mDimension.x;
+ const int y = widget->mDimension.y;
+ area.x += x;
+ area.y += y;
if (area.x + area.width > widgetArea.width)
- {
- widget->setX(widget->getX() - area.x
- - area.width + widgetArea.width);
- }
+ widget->setX(x - area.x - area.width + widgetArea.width);
if (area.y + area.height > widgetArea.height)
- {
- widget->setY(widget->getY() - area.y
- - area.height + widgetArea.height);
- }
+ widget->setY(y - area.y - area.height + widgetArea.height);
if (area.x < 0)
- widget->setX(widget->getX() - area.x);
+ widget->setX(x - area.x);
if (area.y < 0)
- widget->setY(widget->getY() - area.y);
+ widget->setY(y - area.y);
}
void BasicContainer::setInternalFocusHandler(FocusHandler* focusHandler)
{
Widget::setInternalFocusHandler(focusHandler);
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
+ FOR_EACH (WidgetListConstIterator, iter, mWidgets)
{
if (!mInternalFocusHandler)
- (*iter)->_setFocusHandler(_getFocusHandler());
+ (*iter)->setFocusHandler(getFocusHandler());
else
- (*iter)->_setFocusHandler(mInternalFocusHandler);
+ (*iter)->setFocusHandler(mInternalFocusHandler);
}
}
-
-Widget* BasicContainer::findWidgetById(const std::string& id)
-{
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++ iter)
- {
- if ((*iter)->getId() == id)
- return (*iter);
-
- BasicContainer *const basicContainer
- = dynamic_cast<BasicContainer *const>(*iter);
-
- if (basicContainer)
- {
- Widget *const widget = basicContainer->findWidgetById(id);
-
- if (widget)
- return widget;
- }
- }
-
- return nullptr;
-}
diff --git a/src/gui/widgets/basiccontainer.h b/src/gui/widgets/basiccontainer.h
index 6e753a445..8a5d7b9a4 100644
--- a/src/gui/widgets/basiccontainer.h
+++ b/src/gui/widgets/basiccontainer.h
@@ -85,7 +85,8 @@ class BasicContainer : public Widget,
explicit BasicContainer(const Widget2 *const widget) :
Widget(widget),
DeathListener(),
- mWidgets()
+ mWidgets(),
+ mLogicWidgets()
{ }
A_DELETE_COPY(BasicContainer)
@@ -110,28 +111,28 @@ class BasicContainer : public Widget,
// Inherited from Widget
- virtual void moveToTop(Widget* widget);
+ virtual void moveToTop(Widget* widget) override;
- virtual void moveToBottom(Widget* widget);
+ virtual void moveToBottom(Widget* widget) override;
- virtual Rect getChildrenArea() A_WARN_UNUSED;
+ virtual Rect getChildrenArea() override A_WARN_UNUSED;
- virtual void focusNext();
+ virtual void focusNext() override;
- virtual void focusPrevious();
+ virtual void focusPrevious() override;
- virtual void logic();
+ virtual void logic() override;
- virtual void _setFocusHandler(FocusHandler* focusHandler);
+ virtual void setFocusHandler(FocusHandler *const focusHandler)
+ override;
void setInternalFocusHandler(FocusHandler* focusHandler);
- virtual Widget *getWidgetAt(int x, int y) A_WARN_UNUSED;
-
+ virtual Widget *getWidgetAt(int x, int y) override A_WARN_UNUSED;
// Inherited from DeathListener
- virtual void death(const Event& event);
+ virtual void death(const Event& event) override;
protected:
/**
@@ -140,7 +141,7 @@ class BasicContainer : public Widget,
* @param widget The widget to add.
* @see remove, clear
*/
- void add(Widget* widget);
+ void add(Widget *const widget);
/**
* Removes a widget from the basic container.
@@ -171,17 +172,6 @@ class BasicContainer : public Widget,
virtual void logicChildren();
/**
- * Finds a widget given an id. This function can be useful
- * when implementing a GUI generator for Guichan, such as
- * the ability to create a Guichan GUI from an XML file.
- *
- * @param id The id to find a widget by.
- * @return The widget with the corrosponding id,
- NULL of no widget is found.
- */
- virtual Widget* findWidgetById(const std::string& id) A_WARN_UNUSED;
-
- /**
* Typedef.
*/
typedef std::vector<Widget *> WidgetList;
@@ -210,6 +200,8 @@ class BasicContainer : public Widget,
* Holds all widgets of the basic container.
*/
WidgetList mWidgets;
+
+ WidgetList mLogicWidgets;
};
#endif // GUI_WIDGETS_BASICCONTAINER_H
diff --git a/src/gui/widgets/basiccontainer2.cpp b/src/gui/widgets/basiccontainer2.cpp
index 9bd4d1593..8e6d62a67 100644
--- a/src/gui/widgets/basiccontainer2.cpp
+++ b/src/gui/widgets/basiccontainer2.cpp
@@ -122,8 +122,3 @@ void BasicContainer2::clear()
{
BasicContainer::clear();
}
-
-Widget* BasicContainer2::findWidgetById(const std::string &id)
-{
- return BasicContainer::findWidgetById(id);
-}
diff --git a/src/gui/widgets/basiccontainer2.h b/src/gui/widgets/basiccontainer2.h
index c6f1d996b..7d65d0cdf 100644
--- a/src/gui/widgets/basiccontainer2.h
+++ b/src/gui/widgets/basiccontainer2.h
@@ -149,17 +149,6 @@ class BasicContainer2: public BasicContainer
*/
virtual void clear();
- /**
- * Finds a widget given an id.
- *
- * @param id The id to find a widget by.
- * @return A widget with a corrosponding id, NULL if no widget
- * is found.
- * @see Widget::setId
- */
- virtual Widget* findWidgetById(const std::string &id);
-
-
// Inherited from Widget
virtual void draw(Graphics* graphics);
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index 100281d94..4d4a51ca4 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -83,12 +83,13 @@ BrowserBox::BrowserBox(const Widget2 *const widget,
mEnableKeys(false),
mEnableTabs(false)
{
+ mAllowLogic = false;
+
setFocusable(true);
addMouseListener(this);
mBackgroundColor = getThemeColor(Theme::BACKGROUND);
- Theme *const theme = Theme::instance();
if (theme)
mSkin = theme->load(skin, "browserbox.xml");
if (mInstances == 0)
@@ -140,7 +141,6 @@ BrowserBox::~BrowserBox()
if (gui)
gui->removeDragged(this);
- Theme *const theme = Theme::instance();
if (theme)
{
theme->unload(mSkin);
@@ -445,6 +445,11 @@ void BrowserBox::mouseMoved(MouseEvent &event)
? static_cast<int>(i - mLinks.begin()) : -1;
}
+void BrowserBox::mouseExited(MouseEvent &event A_UNUSED)
+{
+ mSelectedLink = -1;
+}
+
void BrowserBox::draw(Graphics *graphics)
{
BLOCK_START("BrowserBox::draw")
diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h
index 8202fa548..55f0163cd 100644
--- a/src/gui/widgets/browserbox.h
+++ b/src/gui/widgets/browserbox.h
@@ -160,6 +160,8 @@ class BrowserBox final : public Widget,
void mouseMoved(MouseEvent &event) override final;
+ void mouseExited(MouseEvent& event) override final;
+
/**
* Draws the browser box.
*/
diff --git a/src/gui/widgets/browserbox_unittest.cc b/src/gui/widgets/browserbox_unittest.cc
index 2acc5f5d3..f8b5e149e 100644
--- a/src/gui/widgets/browserbox_unittest.cc
+++ b/src/gui/widgets/browserbox_unittest.cc
@@ -50,7 +50,7 @@ TEST(browserbox, test1)
logger = new Logger();
imageHelper = new SDLImageHelper();
- Theme *theme = Theme::instance();
+ theme = new Theme;
Widget::setGlobalFont(new Font("/usr/share/fonts/truetype/"
"ttf-dejavu/DejaVuSans-Oblique.ttf", 18));
BrowserBox *box = new BrowserBox(nullptr, BrowserBox::AUTO_WRAP, true, "");
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index 308c75413..054a338aa 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -77,9 +77,10 @@
#include "gui/font.h"
#include "gui/gui.h"
-
#include "gui/rect.h"
+#include "utils/delete2.h"
+
#include "debug.h"
int Button::mInstances = 0;
@@ -327,6 +328,7 @@ Button::Button(const Widget2 *const widget,
void Button::init()
{
+ mAllowLogic = false;
addMouseListener(this);
addKeyListener(this);
addFocusListener(this);
@@ -337,13 +339,10 @@ void Button::init()
if (mInstances == 0)
{
- if (Theme::instance())
+ if (theme)
{
for (int mode = 0; mode < BUTTON_COUNT; mode ++)
- {
- button[mode] = Theme::instance()->load(
- data[mode], "button.xml");
- }
+ button[mode] = theme->load(data[mode], "button.xml");
}
updateAlpha();
@@ -359,14 +358,12 @@ Button::~Button()
mInstances--;
- if (mInstances == 0 && Theme::instance())
+ if (mInstances == 0 && theme)
{
- Theme *const theme = Theme::instance();
for (int mode = 0; mode < BUTTON_COUNT; mode ++)
theme->unload(button[mode]);
}
- delete mVertexes2;
- mVertexes2 = nullptr;
+ delete2(mVertexes2);
if (mImageSet)
{
mImageSet->decRef();
@@ -420,7 +417,7 @@ void Button::loadImageSet(const std::string &imageName)
void Button::updateAlpha()
{
const float alpha = std::max(client->getGuiAlpha(),
- Theme::instance()->getMinimumOpacity());
+ theme->getMinimumOpacity());
if (mAlpha != alpha)
{
@@ -616,9 +613,9 @@ void Button::draw(Graphics *graphics)
BLOCK_END("Button::draw")
}
-void Button::mouseReleased(MouseEvent& mouseEvent)
+void Button::mouseReleased(MouseEvent& event)
{
- if (mouseEvent.getButton() == MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
if (mStick)
mPressed = !mPressed;
@@ -626,7 +623,7 @@ void Button::mouseReleased(MouseEvent& mouseEvent)
if (mMousePressed && mHasMouse)
{
mMousePressed = false;
- mClickCount = mouseEvent.getClickCount();
+ mClickCount = event.getClickCount();
distributeActionEvent();
}
else
@@ -634,7 +631,7 @@ void Button::mouseReleased(MouseEvent& mouseEvent)
mMousePressed = false;
mClickCount = 0;
}
- mouseEvent.consume();
+ event.consume();
}
}
@@ -676,20 +673,20 @@ void Button::adjustSize()
}
}
-void Button::keyPressed(KeyEvent& keyEvent)
+void Button::keyPressed(KeyEvent& event)
{
- const int action = keyEvent.getActionId();
+ const int action = event.getActionId();
if (action == Input::KEY_GUI_SELECT)
{
mKeyPressed = true;
- keyEvent.consume();
+ event.consume();
}
}
-void Button::keyReleased(KeyEvent& keyEvent)
+void Button::keyReleased(KeyEvent& event)
{
- const int action = keyEvent.getActionId();
+ const int action = event.getActionId();
if (action == Input::KEY_GUI_SELECT && mKeyPressed)
{
@@ -697,7 +694,7 @@ void Button::keyReleased(KeyEvent& keyEvent)
if (mStick)
mPressed = !mPressed;
distributeActionEvent();
- keyEvent.consume();
+ event.consume();
}
}
@@ -720,26 +717,26 @@ void Button::focusLost(const Event& event A_UNUSED)
mKeyPressed = false;
}
-void Button::mousePressed(MouseEvent& mouseEvent)
+void Button::mousePressed(MouseEvent& event)
{
- if (mouseEvent.getButton() == MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
mMousePressed = true;
- mouseEvent.consume();
+ event.consume();
}
}
-void Button::mouseEntered(MouseEvent& mouseEvent A_UNUSED)
+void Button::mouseEntered(MouseEvent& event A_UNUSED)
{
mHasMouse = true;
}
-void Button::mouseExited(MouseEvent& mouseEvent A_UNUSED)
+void Button::mouseExited(MouseEvent& event A_UNUSED)
{
mHasMouse = false;
}
-void Button::mouseDragged(MouseEvent& mouseEvent)
+void Button::mouseDragged(MouseEvent& event)
{
- mouseEvent.consume();
+ event.consume();
}
diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h
index 6eba9b3c0..57a024195 100644
--- a/src/gui/widgets/button.h
+++ b/src/gui/widgets/button.h
@@ -156,7 +156,7 @@ class Button final : public Widget,
*/
static void updateAlpha();
- void mouseReleased(MouseEvent& mouseEvent) override final;
+ void mouseReleased(MouseEvent& event) override final;
void setDescription(std::string text)
{ mDescription = text; }
@@ -189,9 +189,9 @@ class Button final : public Widget,
void adjustSize();
- void keyPressed(KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &event) override final;
- void keyReleased(KeyEvent &keyEvent) override final;
+ void keyReleased(KeyEvent &event) override final;
bool isPressed2() const A_WARN_UNUSED;
@@ -254,13 +254,13 @@ class Button final : public Widget,
void focusLost(const Event& event) override final;
- void mousePressed(MouseEvent& mouseEvent) override final;
+ void mousePressed(MouseEvent& event) override final;
- void mouseEntered(MouseEvent& mouseEvent) override final;
+ void mouseEntered(MouseEvent& event) override final;
- void mouseExited(MouseEvent& mouseEvent) override final;
+ void mouseExited(MouseEvent& event) override final;
- void mouseDragged(MouseEvent& mouseEvent) override final;
+ void mouseDragged(MouseEvent& event) override final;
enum
{
diff --git a/src/gui/widgets/characterdisplay.cpp b/src/gui/widgets/characterdisplay.cpp
index 7bfc938de..a5cf2379e 100644
--- a/src/gui/widgets/characterdisplay.cpp
+++ b/src/gui/widgets/characterdisplay.cpp
@@ -77,8 +77,7 @@ CharacterDisplay::CharacterDisplay(const Widget2 *const widget,
CharacterDisplay::~CharacterDisplay()
{
- delete mPopup;
- mPopup = nullptr;
+ delete2(mPopup);
}
void CharacterDisplay::setCharacter(Net::Character *const character)
@@ -145,6 +144,7 @@ void CharacterDisplay::mouseMoved(MouseEvent &event A_UNUSED)
void CharacterDisplay::mousePressed(MouseEvent &event)
{
+ event.consume();
if (event.getClickCount() == 2)
distributeActionEvent();
}
diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp
index f01495bcf..06dcecab0 100644
--- a/src/gui/widgets/checkbox.cpp
+++ b/src/gui/widgets/checkbox.cpp
@@ -98,6 +98,7 @@ CheckBox::CheckBox(const Widget2 *const widget,
mDrawBox(true)
{
setCaption(caption);
+ mAllowLogic = false;
setFocusable(true);
addMouseListener(this);
@@ -106,9 +107,9 @@ CheckBox::CheckBox(const Widget2 *const widget,
mForegroundColor2 = getThemeColor(Theme::CHECKBOX_OUTLINE);
if (instances == 0)
{
- if (Theme::instance())
+ if (theme)
{
- mSkin = Theme::instance()->load("checkbox.xml", "");
+ mSkin = theme->load("checkbox.xml", "");
updateAlpha();
}
}
@@ -142,8 +143,8 @@ CheckBox::~CheckBox()
if (instances == 0)
{
- if (Theme::instance())
- Theme::instance()->unload(mSkin);
+ if (theme)
+ theme->unload(mSkin);
}
}
@@ -162,7 +163,7 @@ void CheckBox::draw(Graphics *const graphics)
void CheckBox::updateAlpha()
{
const float alpha = std::max(client->getGuiAlpha(),
- Theme::instance()->getMinimumOpacity());
+ theme->getMinimumOpacity());
if (mAlpha != alpha)
{
@@ -234,14 +235,14 @@ void CheckBox::mouseExited(MouseEvent& event A_UNUSED)
mHasMouse = false;
}
-void CheckBox::keyPressed(KeyEvent& keyEvent)
+void CheckBox::keyPressed(KeyEvent& event)
{
- const int action = keyEvent.getActionId();
+ const int action = event.getActionId();
if (action == Input::KEY_GUI_SELECT)
{
toggleSelected();
- keyEvent.consume();
+ event.consume();
}
}
@@ -252,15 +253,18 @@ void CheckBox::adjustSize()
+ getFont()->getWidth(mCaption) + mPadding);
}
-void CheckBox::mouseClicked(MouseEvent& mouseEvent)
+void CheckBox::mouseClicked(MouseEvent& event)
{
- if (mouseEvent.getButton() == MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
+ {
toggleSelected();
+ event.consume();
+ }
}
-void CheckBox::mouseDragged(MouseEvent& mouseEvent)
+void CheckBox::mouseDragged(MouseEvent& event)
{
- mouseEvent.consume();
+ event.consume();
}
void CheckBox::toggleSelected()
diff --git a/src/gui/widgets/checkbox.h b/src/gui/widgets/checkbox.h
index 5711e766f..41f168048 100644
--- a/src/gui/widgets/checkbox.h
+++ b/src/gui/widgets/checkbox.h
@@ -126,7 +126,7 @@ class CheckBox final : public Widget,
*/
void mouseExited(MouseEvent& event) override final;
- void keyPressed(KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& event) override final;
void adjustSize();
@@ -168,9 +168,9 @@ class CheckBox final : public Widget,
void setCaption(const std::string& caption)
{ mCaption = caption; }
- void mouseClicked(MouseEvent& mouseEvent) override final;
+ void mouseClicked(MouseEvent& event) override final;
- void mouseDragged(MouseEvent& mouseEvent) override final;
+ void mouseDragged(MouseEvent& event) override final;
private:
void toggleSelected();
diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp
index 0ff1b17c9..6ae892c81 100644
--- a/src/gui/widgets/desktop.cpp
+++ b/src/gui/widgets/desktop.cpp
@@ -51,7 +51,6 @@ Desktop::Desktop(const Widget2 *const widget) :
Wallpaper::loadWallpapers();
- Theme *const theme = Theme::instance();
if (theme)
mSkin = theme->load("desktop.xml", "");
@@ -80,8 +79,8 @@ Desktop::~Desktop()
mWallpaper->decRef();
mWallpaper = nullptr;
}
- if (Theme::instance())
- Theme::instance()->unload(mSkin);
+ if (theme)
+ theme->unload(mSkin);
}
void Desktop::postInit()
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index b1a3c4ac1..8b636c04d 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -78,6 +78,7 @@ DropDown::DropDown(const Widget2 *const widget,
mPushed(false),
mIsDragged(false)
{
+ mAllowLogic = false;
mPopup->postInit();
mFrameSize = 2;
mForegroundColor2 = getThemeColor(Theme::DROPDOWN_OUTLINE);
@@ -85,13 +86,12 @@ DropDown::DropDown(const Widget2 *const widget,
mPopup->setHeight(100);
// Initialize graphics
- if (instances == 0)
+ if (instances == 0 && theme)
{
// Load the background skin
for (int i = 0; i < 2; i ++)
{
- Skin *const skin = Theme::instance()->load(
- dropdownFiles[i], "dropdown.xml");
+ Skin *const skin = theme->load(dropdownFiles[i], "dropdown.xml");
if (skin)
{
if (!i)
@@ -111,7 +111,7 @@ DropDown::DropDown(const Widget2 *const widget,
}
}
if (i)
- Theme::instance()->unload(skin);
+ theme->unload(skin);
}
else
{
@@ -121,11 +121,8 @@ DropDown::DropDown(const Widget2 *const widget,
}
// get the border skin
- if (Theme::instance())
- {
- Theme::instance()->loadRect(skinRect,
- "dropdown_background.xml", "");
- }
+ if (theme)
+ theme->loadRect(skinRect, "dropdown_background.xml", "");
}
instances++;
@@ -181,7 +178,6 @@ DropDown::~DropDown()
buttons[f][i]->decRef();
}
}
- Theme *const theme = Theme::instance();
if (theme)
{
theme->unload(mSkin);
@@ -193,7 +189,7 @@ DropDown::~DropDown()
void DropDown::updateAlpha()
{
const float alpha = std::max(client->getGuiAlpha(),
- Theme::instance()->getMinimumOpacity());
+ theme->getMinimumOpacity());
if (mAlpha != alpha)
{
@@ -311,12 +307,12 @@ void DropDown::drawButton(Graphics *graphics)
}
}
-void DropDown::keyPressed(KeyEvent& keyEvent)
+void DropDown::keyPressed(KeyEvent& event)
{
- if (keyEvent.isConsumed())
+ if (event.isConsumed())
return;
- const int actionId = keyEvent.getActionId();
+ const int actionId = event.getActionId();
switch (actionId)
{
case Input::KEY_GUI_SELECT:
@@ -348,7 +344,7 @@ void DropDown::keyPressed(KeyEvent& keyEvent)
return;
}
- keyEvent.consume();
+ event.consume();
}
void DropDown::hideDrop(bool event)
@@ -358,11 +354,12 @@ void DropDown::hideDrop(bool event)
mPopup->setVisible(false);
}
-void DropDown::mousePressed(MouseEvent& mouseEvent)
+void DropDown::mousePressed(MouseEvent& event)
{
+ event.consume();
// If we have a mouse press on the widget.
- if (mouseEvent.getButton() == MouseEvent::LEFT
- && !mDroppedDown && mouseEvent.getSource() == this)
+ if (event.getButton() == MouseEvent::LEFT
+ && !mDroppedDown && event.getSource() == this)
{
mPushed = true;
dropDown();
@@ -375,14 +372,14 @@ void DropDown::mousePressed(MouseEvent& mouseEvent)
}
}
-void DropDown::mouseReleased(MouseEvent &mouseEvent)
+void DropDown::mouseReleased(MouseEvent &event)
{
if (mIsDragged)
mPushed = false;
- const int button = mouseEvent.getButton();
- const int x = mouseEvent.getX();
- const int y = mouseEvent.getY();
+ const int button = event.getButton();
+ const int x = event.getX();
+ const int y = event.getY();
// Released outside of widget. Can happen when we have modal
// input focus.
if ((0 > y || y >= mDimension.height || x < 0 || x >= mDimension.width)
@@ -399,22 +396,22 @@ void DropDown::mouseReleased(MouseEvent &mouseEvent)
mIsDragged = false;
}
-void DropDown::mouseDragged(MouseEvent &mouseEvent)
+void DropDown::mouseDragged(MouseEvent &event)
{
mIsDragged = true;
- mouseEvent.consume();
+ event.consume();
}
-void DropDown::mouseWheelMovedUp(MouseEvent& mouseEvent)
+void DropDown::mouseWheelMovedUp(MouseEvent& event)
{
setSelected(getSelected() - 1);
- mouseEvent.consume();
+ event.consume();
}
-void DropDown::mouseWheelMovedDown(MouseEvent& mouseEvent)
+void DropDown::mouseWheelMovedDown(MouseEvent& event)
{
setSelected(getSelected() + 1);
- mouseEvent.consume();
+ event.consume();
}
void DropDown::setSelectedString(const std::string &str)
diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h
index 2208880b3..cf42cce11 100644
--- a/src/gui/widgets/dropdown.h
+++ b/src/gui/widgets/dropdown.h
@@ -83,19 +83,19 @@ class DropDown final : public ActionListener,
// Inherited from KeyListener
- void keyPressed(KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& event) override final;
// Inherited from MouseListener
- void mousePressed(MouseEvent& mouseEvent) override final;
+ void mousePressed(MouseEvent& event) override final;
- void mouseReleased(MouseEvent& mouseEvent) override final;
+ void mouseReleased(MouseEvent& event) override final;
- void mouseDragged(MouseEvent& mouseEvent) override final;
+ void mouseDragged(MouseEvent& event) override final;
- void mouseWheelMovedUp(MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedUp(MouseEvent& event) override final;
- void mouseWheelMovedDown(MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedDown(MouseEvent& event) override final;
void setSelectedString(const std::string &str);
diff --git a/src/gui/widgets/dropshortcutcontainer.cpp b/src/gui/widgets/dropshortcutcontainer.cpp
index c8e4bc2d9..67e027a96 100644
--- a/src/gui/widgets/dropshortcutcontainer.cpp
+++ b/src/gui/widgets/dropshortcutcontainer.cpp
@@ -28,6 +28,7 @@
#include "being/playerinfo.h"
+#include "gui/font.h"
#include "gui/viewport.h"
#include "gui/popups/itempopup.h"
@@ -36,7 +37,7 @@
#include "resources/image.h"
-#include "gui/font.h"
+#include "utils/delete2.h"
#include "debug.h"
@@ -81,8 +82,7 @@ DropShortcutContainer::~DropShortcutContainer()
mBackgroundImg->decRef();
mBackgroundImg = nullptr;
}
- delete mItemPopup;
- mItemPopup = nullptr;
+ delete2(mItemPopup);
}
void DropShortcutContainer::setWidget2(const Widget2 *const widget)
@@ -206,6 +206,8 @@ void DropShortcutContainer::mousePressed(MouseEvent &event)
if (index == -1)
return;
+ event.consume();
+
const int eventButton = event.getButton();
if (eventButton == MouseEvent::LEFT)
{
diff --git a/src/gui/widgets/emotepage.cpp b/src/gui/widgets/emotepage.cpp
index 139082815..789d3e1aa 100644
--- a/src/gui/widgets/emotepage.cpp
+++ b/src/gui/widgets/emotepage.cpp
@@ -25,6 +25,8 @@
#include "resources/imageset.h"
#include "resources/resourcemanager.h"
+#include "utils/delete2.h"
+
#include "debug.h"
namespace
@@ -45,6 +47,7 @@ EmotePage::EmotePage(const Widget2 *const widget) :
{
addMouseListener(this);
addWidgetListener(this);
+ mAllowLogic = false;
}
EmotePage::~EmotePage()
@@ -54,8 +57,7 @@ EmotePage::~EmotePage()
mEmotes->decRef();
mEmotes = nullptr;
}
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
}
void EmotePage::draw(Graphics *graphics)
@@ -115,9 +117,10 @@ void EmotePage::draw(Graphics *graphics)
BLOCK_END("EmotePage::draw")
}
-void EmotePage::mousePressed(MouseEvent &mouseEvent)
+void EmotePage::mousePressed(MouseEvent &event)
{
- mSelectedIndex = getIndexFromGrid(mouseEvent.getX(), mouseEvent.getY());
+ mSelectedIndex = getIndexFromGrid(event.getX(), event.getY());
+ event.consume();
distributeActionEvent();
}
diff --git a/src/gui/widgets/emotepage.h b/src/gui/widgets/emotepage.h
index 2ce50f1fc..769e004bc 100644
--- a/src/gui/widgets/emotepage.h
+++ b/src/gui/widgets/emotepage.h
@@ -41,7 +41,7 @@ class EmotePage final : public Widget,
void draw(Graphics *graphics) override final;
- void mousePressed(MouseEvent &mouseEvent) override final;
+ void mousePressed(MouseEvent &event) override final;
int getIndexFromGrid(const int x, const int y) const;
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
index 296f21126..c731e86d8 100644
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ b/src/gui/widgets/emoteshortcutcontainer.cpp
@@ -163,6 +163,7 @@ void EmoteShortcutContainer::mousePressed(MouseEvent &event)
if (index == -1)
return;
+ event.consume();
// Stores the selected emote if there is one.
if (emoteShortcut->isEmoteSelected())
{
diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp
index 128281fe9..6feed2b12 100644
--- a/src/gui/widgets/guitable.cpp
+++ b/src/gui/widgets/guitable.cpp
@@ -30,12 +30,13 @@
#include "input/keydata.h"
-#include "utils/dtor.h"
-
#include "listeners/actionlistener.h"
#include "render/graphics.h"
+#include "utils/delete2.h"
+#include "utils/dtor.h"
+
#include "debug.h"
float GuiTable::mAlpha = 1.0;
@@ -73,7 +74,7 @@ GuiTableActionListener::GuiTableActionListener(GuiTable *restrict table,
if (widget)
{
widget->addActionListener(this);
- widget->_setParent(table);
+ widget->setParent(table);
}
}
@@ -82,7 +83,7 @@ GuiTableActionListener::~GuiTableActionListener()
if (mWidget)
{
mWidget->removeActionListener(this);
- mWidget->_setParent(nullptr);
+ mWidget->setParent(nullptr);
}
}
@@ -110,6 +111,7 @@ GuiTable::GuiTable(const Widget2 *const widget,
mOpaque(opacity),
mSelectable(true)
{
+ mAllowLogic = false;
mBackgroundColor = getThemeColor(Theme::BACKGROUND);
setModel(initial_model);
@@ -125,8 +127,7 @@ GuiTable::~GuiTable()
gui->removeDragged(this);
uninstallActionListeners();
- delete mModel;
- mModel = nullptr;
+ delete2(mModel);
}
const TableModel *GuiTable::getModel() const
@@ -291,7 +292,7 @@ void GuiTable::installActionListeners()
}
}
- _setFocusHandler(_getFocusHandler());
+ setFocusHandler(getFocusHandler());
}
// -- widget ops
@@ -420,99 +421,100 @@ Rect GuiTable::getChildrenArea()
}
// -- KeyListener notifications
-void GuiTable::keyPressed(KeyEvent& keyEvent)
+void GuiTable::keyPressed(KeyEvent& event)
{
- const int action = keyEvent.getActionId();
+ const int action = event.getActionId();
if (action == Input::KEY_GUI_SELECT)
{
distributeActionEvent();
- keyEvent.consume();
+ event.consume();
}
else if (action == Input::KEY_GUI_UP)
{
setSelectedRow(mSelectedRow - 1);
- keyEvent.consume();
+ event.consume();
}
else if (action == Input::KEY_GUI_DOWN)
{
setSelectedRow(mSelectedRow + 1);
- keyEvent.consume();
+ event.consume();
}
else if (action == Input::KEY_GUI_LEFT)
{
setSelectedColumn(mSelectedColumn - 1);
- keyEvent.consume();
+ event.consume();
}
else if (action == Input::KEY_GUI_RIGHT)
{
setSelectedColumn(mSelectedColumn + 1);
- keyEvent.consume();
+ event.consume();
}
else if (action == Input::KEY_GUI_HOME)
{
setSelectedRow(0);
setSelectedColumn(0);
- keyEvent.consume();
+ event.consume();
}
else if (action == Input::KEY_GUI_END && mModel)
{
setSelectedRow(mModel->getRows() - 1);
setSelectedColumn(mModel->getColumns() - 1);
- keyEvent.consume();
+ event.consume();
}
}
// -- MouseListener notifications
-void GuiTable::mousePressed(MouseEvent& mouseEvent)
+void GuiTable::mousePressed(MouseEvent& event)
{
if (!mModel || !mSelectable)
return;
- if (mouseEvent.getButton() == MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
- const int row = getRowForY(mouseEvent.getY());
- const int column = getColumnForX(mouseEvent.getX());
+ const int row = getRowForY(event.getY());
+ const int column = getColumnForX(event.getX());
if (row > -1 && column > -1 &&
row < mModel->getRows() && column < mModel->getColumns())
{
mSelectedColumn = column;
mSelectedRow = row;
+ event.consume();
}
distributeActionEvent();
}
}
-void GuiTable::mouseWheelMovedUp(MouseEvent& mouseEvent)
+void GuiTable::mouseWheelMovedUp(MouseEvent& event)
{
if (isFocused())
{
const int selRow = getSelectedRow();
if (selRow > 0 || (selRow == 0 && mWrappingEnabled))
setSelectedRow(selRow - 1);
- mouseEvent.consume();
+ event.consume();
}
}
-void GuiTable::mouseWheelMovedDown(MouseEvent& mouseEvent)
+void GuiTable::mouseWheelMovedDown(MouseEvent& event)
{
if (isFocused())
{
setSelectedRow(getSelectedRow() + 1);
- mouseEvent.consume();
+ event.consume();
}
}
-void GuiTable::mouseDragged(MouseEvent& mouseEvent)
+void GuiTable::mouseDragged(MouseEvent& event)
{
- if (mouseEvent.getButton() != MouseEvent::LEFT)
+ if (event.getButton() != MouseEvent::LEFT)
return;
// Make table selection update on drag
- const int x = std::max(0, mouseEvent.getX());
- const int y = std::max(0, mouseEvent.getY());
+ const int x = std::max(0, event.getX());
+ const int y = std::max(0, event.getY());
setSelectedRow(getRowForY(y));
setSelectedColumn(getColumnForX(x));
@@ -588,14 +590,14 @@ int GuiTable::getColumnForX(int x) const
return column;
}
-void GuiTable::_setFocusHandler(FocusHandler* focusHandler)
+void GuiTable::setFocusHandler(FocusHandler *const focusHandler)
{
// add check for focusHandler. may be need remove it?
if (!mModel || !focusHandler)
return;
- Widget::_setFocusHandler(focusHandler);
+ Widget::setFocusHandler(focusHandler);
const int rows = mModel->getRows();
const int cols = mModel->getColumns();
@@ -605,7 +607,7 @@ void GuiTable::_setFocusHandler(FocusHandler* focusHandler)
{
Widget *const w = mModel->getElementAt(r, c);
if (w)
- w->_setFocusHandler(focusHandler);
+ w->setFocusHandler(focusHandler);
}
}
}
diff --git a/src/gui/widgets/guitable.h b/src/gui/widgets/guitable.h
index 7cec854a8..64e0adae4 100644
--- a/src/gui/widgets/guitable.h
+++ b/src/gui/widgets/guitable.h
@@ -120,10 +120,10 @@ public:
void moveToBottom(Widget *child) override final;
- void _setFocusHandler(FocusHandler* focusHandler) override final;
+ void setFocusHandler(FocusHandler *const focusHandler) override final;
// Inherited from KeyListener
- void keyPressed(KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& event) override final;
/**
* Sets the table to be opaque, that is sets the table
@@ -144,13 +144,13 @@ public:
{ return mOpaque; }
// Inherited from MouseListener
- void mousePressed(MouseEvent& mouseEvent) override final;
+ void mousePressed(MouseEvent& event) override final;
- void mouseWheelMovedUp(MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedUp(MouseEvent& event) override final;
- void mouseWheelMovedDown(MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedDown(MouseEvent& event) override final;
- void mouseDragged(MouseEvent& mouseEvent) override final;
+ void mouseDragged(MouseEvent& event) override final;
// Constraints inherited from TableModelListener
void modelUpdated(const bool completed) override final;
diff --git a/src/gui/widgets/icon.cpp b/src/gui/widgets/icon.cpp
index 9a86fc9bf..3ffac4a7d 100644
--- a/src/gui/widgets/icon.cpp
+++ b/src/gui/widgets/icon.cpp
@@ -39,6 +39,7 @@ Icon::Icon(const Widget2 *const widget,
const SDL_Rect &bounds = mImage->mBounds;
setSize(bounds.w, bounds.h);
}
+ mAllowLogic = false;
}
Icon::Icon(const Widget2 *const widget,
@@ -51,6 +52,7 @@ Icon::Icon(const Widget2 *const widget,
const SDL_Rect &bounds = mImage->mBounds;
setSize(bounds.w, bounds.h);
}
+ mAllowLogic = false;
}
Icon::~Icon()
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index fe666e6f7..ee2e35920 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -29,6 +29,7 @@
#include "being/playerinfo.h"
+#include "gui/font.h"
#include "gui/gui.h"
#include "gui/viewport.h"
@@ -46,9 +47,10 @@
#include "resources/image.h"
-#include "gui/font.h"
#include "listeners/selectionlistener.h"
+#include "utils/delete2.h"
+
#include <algorithm>
#include "debug.h"
@@ -168,8 +170,7 @@ ItemContainer::ItemContainer(const Widget2 *const widget,
mName(),
mItemPopup(new ItemPopup),
mShowMatrix(nullptr),
- mSkin(Theme::instance() ? Theme::instance()->load(
- "itemcontainer.xml", "") : nullptr),
+ mSkin(theme ? theme->load("itemcontainer.xml", "") : nullptr),
mEquipedColor(getThemeColor(Theme::ITEM_EQUIPPED)),
mEquipedColor2(getThemeColor(Theme::ITEM_EQUIPPED_OUTLINE)),
mUnEquipedColor(getThemeColor(Theme::ITEM_NOT_EQUIPPED)),
@@ -197,6 +198,7 @@ ItemContainer::ItemContainer(const Widget2 *const widget,
addKeyListener(this);
addMouseListener(this);
addWidgetListener(this);
+ mAllowLogic = false;
}
ItemContainer::~ItemContainer()
@@ -215,11 +217,10 @@ ItemContainer::~ItemContainer()
mProtectedImg = nullptr;
}
- if (Theme::instance())
- Theme::instance()->unload(mSkin);
+ if (theme)
+ theme->unload(mSkin);
- delete mItemPopup;
- mItemPopup = nullptr;
+ delete2(mItemPopup);
delete []mShowMatrix;
}
@@ -403,6 +404,7 @@ void ItemContainer::mousePressed(MouseEvent &event)
if (button == MouseEvent::LEFT || button == MouseEvent::RIGHT)
{
+ event.consume();
const int index = getSlotIndex(event.getX(), event.getY());
if (index == Inventory::NO_SLOT_INDEX)
return;
diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp
index 2cf27ae30..efc6ef175 100644
--- a/src/gui/widgets/itemlinkhandler.cpp
+++ b/src/gui/widgets/itemlinkhandler.cpp
@@ -39,6 +39,8 @@
#include "input/mouseinput.h"
+#include "utils/delete2.h"
+
#include <string>
#include "debug.h"
@@ -74,8 +76,7 @@ ItemLinkHandler::ItemLinkHandler() :
ItemLinkHandler::~ItemLinkHandler()
{
- delete mItemPopup;
- mItemPopup = nullptr;
+ delete2(mItemPopup);
}
void ItemLinkHandler::handleLink(const std::string &link, MouseEvent *event)
diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp
index b9dc3bec8..420eb5578 100644
--- a/src/gui/widgets/itemshortcutcontainer.cpp
+++ b/src/gui/widgets/itemshortcutcontainer.cpp
@@ -46,6 +46,8 @@
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
ItemShortcutContainer::ItemShortcutContainer(Widget2 *const widget,
@@ -95,10 +97,8 @@ ItemShortcutContainer::~ItemShortcutContainer()
mBackgroundImg->decRef();
mBackgroundImg = nullptr;
}
- delete mItemPopup;
- mItemPopup = nullptr;
- delete mSpellPopup;
- mSpellPopup = nullptr;
+ delete2(mItemPopup);
+ delete2(mSpellPopup);
}
void ItemShortcutContainer::setWidget2(const Widget2 *const widget)
@@ -334,6 +334,7 @@ void ItemShortcutContainer::mousePressed(MouseEvent &event)
if (event.getButton() == MouseEvent::LEFT)
{
+ event.consume();
// Stores the selected item if theirs one.
if (selShortcut->isItemSelected() && inventoryWindow &&
(inventoryWindow->isWindowVisible()
@@ -352,6 +353,7 @@ void ItemShortcutContainer::mousePressed(MouseEvent &event)
}
else if (event.getButton() == MouseEvent::RIGHT)
{
+ event.consume();
if (viewport && selShortcut)
{
viewport->showItemPopup(selShortcut->getItem(index),
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp
index b500ec7bb..c37308a1e 100644
--- a/src/gui/widgets/label.cpp
+++ b/src/gui/widgets/label.cpp
@@ -105,7 +105,6 @@ Label::~Label()
mInstances --;
if (mInstances == 0)
{
- Theme *const theme = Theme::instance();
if (theme)
theme->unload(mSkin);
}
@@ -113,11 +112,11 @@ Label::~Label()
void Label::init()
{
+ mAllowLogic = false;
mForegroundColor = getThemeColor(Theme::LABEL);
mForegroundColor2 = getThemeColor(Theme::LABEL_OUTLINE);
if (mInstances == 0)
{
- Theme *const theme = Theme::instance();
if (theme)
mSkin = theme->load("label.xml", "");
}
diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp
index 668334fd5..410c8188e 100644
--- a/src/gui/widgets/layout.cpp
+++ b/src/gui/widgets/layout.cpp
@@ -26,6 +26,8 @@
#include "gui/widgets/basiccontainer2.h"
+#include "utils/delete2.h"
+
#include <cassert>
#include "debug.h"
@@ -45,10 +47,7 @@ LayoutCell &ContainerPlacer::operator()
LayoutCell::~LayoutCell()
{
if (mType == ARRAY)
- {
- delete mArray;
- mArray = nullptr;
- }
+ delete2(mArray)
}
LayoutArray &LayoutCell::getArray()
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp
index 6f0c192c6..c41e32854 100644
--- a/src/gui/widgets/listbox.cpp
+++ b/src/gui/widgets/listbox.cpp
@@ -111,7 +111,6 @@ ListBox::ListBox(const Widget2 *const widget,
mForegroundColor = getThemeColor(Theme::LISTBOX);
mForegroundColor2 = getThemeColor(Theme::LISTBOX_OUTLINE);
- Theme *const theme = Theme::instance();
if (theme)
mSkin = theme->load(skin, "listbox.xml");
@@ -138,14 +137,14 @@ ListBox::~ListBox()
if (gui)
gui->removeDragged(this);
- if (Theme::instance())
- Theme::instance()->unload(mSkin);
+ if (theme)
+ theme->unload(mSkin);
}
void ListBox::updateAlpha()
{
const float alpha = std::max(client->getGuiAlpha(),
- Theme::instance()->getMinimumOpacity());
+ theme->getMinimumOpacity());
if (mAlpha != alpha)
mAlpha = alpha;
@@ -226,13 +225,13 @@ void ListBox::draw(Graphics *graphics)
BLOCK_END("ListBox::draw")
}
-void ListBox::keyPressed(KeyEvent &keyEvent)
+void ListBox::keyPressed(KeyEvent &event)
{
- const int action = keyEvent.getActionId();
+ const int action = event.getActionId();
if (action == Input::KEY_GUI_SELECT)
{
distributeActionEvent();
- keyEvent.consume();
+ event.consume();
}
else if (action == Input::KEY_GUI_UP)
{
@@ -240,7 +239,7 @@ void ListBox::keyPressed(KeyEvent &keyEvent)
setSelected(mSelected - 1);
else if (mSelected == 0 && mWrappingEnabled && getListModel())
setSelected(getListModel()->getNumberOfElements() - 1);
- keyEvent.consume();
+ event.consume();
}
else if (action == Input::KEY_GUI_DOWN)
{
@@ -249,33 +248,35 @@ void ListBox::keyPressed(KeyEvent &keyEvent)
setSelected(mSelected + 1);
else if (mSelected == num && mWrappingEnabled)
setSelected(0);
- keyEvent.consume();
+ event.consume();
}
else if (action == Input::KEY_GUI_HOME)
{
setSelected(0);
- keyEvent.consume();
+ event.consume();
}
else if (action == Input::KEY_GUI_END && getListModel())
{
setSelected(getListModel()->getNumberOfElements() - 1);
- keyEvent.consume();
+ event.consume();
}
}
// Don't do anything on scrollwheel. ScrollArea will deal with that.
-void ListBox::mouseWheelMovedUp(MouseEvent &mouseEvent A_UNUSED)
+void ListBox::mouseWheelMovedUp(MouseEvent &event A_UNUSED)
{
}
-void ListBox::mouseWheelMovedDown(MouseEvent &mouseEvent A_UNUSED)
+void ListBox::mouseWheelMovedDown(MouseEvent &event A_UNUSED)
{
}
void ListBox::mousePressed(MouseEvent &event)
{
mPressedIndex = getSelectionByMouse(event.getY());
+ if (mPressedIndex != -1)
+ event.consume();
}
void ListBox::mouseReleased(MouseEvent &event)
@@ -313,11 +314,11 @@ void ListBox::mouseReleased(MouseEvent &event)
mPressedIndex = -2;
}
-void ListBox::mouseReleased1(const MouseEvent &mouseEvent)
+void ListBox::mouseReleased1(const MouseEvent &event)
{
- if (mouseEvent.getButton() == MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
- setSelected(std::max(0, getSelectionByMouse(mouseEvent.getY())));
+ setSelected(std::max(0, getSelectionByMouse(event.getY())));
distributeActionEvent();
}
}
diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h
index f784b3237..e425b48ca 100644
--- a/src/gui/widgets/listbox.h
+++ b/src/gui/widgets/listbox.h
@@ -119,13 +119,13 @@ class ListBox : public Widget,
// Inherited from KeyListener
- void keyPressed(KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& event) override final;
// Inherited from MouseListener
- void mouseWheelMovedUp(MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedUp(MouseEvent& event) override final;
- void mouseWheelMovedDown(MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedDown(MouseEvent& event) override final;
void mousePressed(MouseEvent &event) override;
diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp
index 2ba452620..6a0fbd607 100644
--- a/src/gui/widgets/playerbox.cpp
+++ b/src/gui/widgets/playerbox.cpp
@@ -83,10 +83,10 @@ PlayerBox::~PlayerBox()
void PlayerBox::init(std::string name, std::string selectedName)
{
+ mAllowLogic = false;
setFrameSize(2);
addMouseListener(this);
- Theme *const theme = Theme::instance();
if (theme)
{
if (name.empty())
diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp
index 1114b4a5e..2116de113 100644
--- a/src/gui/widgets/popup.cpp
+++ b/src/gui/widgets/popup.cpp
@@ -27,6 +27,8 @@
#include "gui/viewport.h"
+#include "utils/delete2.h"
+
#include "debug.h"
Popup::Popup(const std::string &name,
@@ -51,7 +53,6 @@ Popup::Popup(const std::string &name,
if (skin == "")
skin = "popup.xml";
- Theme *const theme = Theme::instance();
if (theme)
{
mSkin = theme->load(skin, "popup.xml");
@@ -73,12 +74,10 @@ Popup::~Popup()
{
logger->log("Popup::~Popup(\"%s\")", mPopupName.c_str());
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
if (mSkin)
{
- Theme *const theme = Theme::instance();
if (theme)
theme->unload(mSkin);
mSkin = nullptr;
diff --git a/src/gui/widgets/popuplist.cpp b/src/gui/widgets/popuplist.cpp
index cfb973384..fa0616fd2 100644
--- a/src/gui/widgets/popuplist.cpp
+++ b/src/gui/widgets/popuplist.cpp
@@ -43,7 +43,7 @@ PopupList::PopupList(DropDown *const widget,
mModal(modal)
{
mListBox->postInit();
-
+ mAllowLogic = false;
setFocusable(true);
mListBox->setDistributeMousePressed(true);
@@ -129,23 +129,24 @@ void PopupList::adjustSize()
mListBox->setWidth(width);
}
-void PopupList::mousePressed(MouseEvent& mouseEvent)
+void PopupList::mousePressed(MouseEvent& event)
{
mPressedIndex = mListBox->getSelectionByMouse(
- mouseEvent.getY() + mPadding);
+ event.getY() + mPadding);
+ event.consume();
}
-void PopupList::mouseReleased(MouseEvent& mouseEvent)
+void PopupList::mouseReleased(MouseEvent& event)
{
if (mPressedIndex != mListBox->getSelectionByMouse(
- mouseEvent.getY() + mPadding))
+ event.getY() + mPadding))
{
mPressedIndex = -2;
return;
}
mPressedIndex = -2;
- if (mouseEvent.getSource() == mScrollArea)
+ if (event.getSource() == mScrollArea)
return;
if (mDropDown)
mDropDown->updateSelection();
diff --git a/src/gui/widgets/popuplist.h b/src/gui/widgets/popuplist.h
index 32a9dfc47..b60e93b7f 100644
--- a/src/gui/widgets/popuplist.h
+++ b/src/gui/widgets/popuplist.h
@@ -65,9 +65,9 @@ class PopupList final : public Popup,
void focusLost(const Event& event A_UNUSED) override final;
- void mousePressed(MouseEvent& mouseEvent) override final;
+ void mousePressed(MouseEvent& event) override final;
- void mouseReleased(MouseEvent& mouseEvent) override final;
+ void mouseReleased(MouseEvent& event) override final;
private:
ListModel *mListModel;
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp
index 5bccd61ca..ea4ef11bd 100644
--- a/src/gui/widgets/progressbar.cpp
+++ b/src/gui/widgets/progressbar.cpp
@@ -28,6 +28,8 @@
#include "gui/font.h"
#include "gui/gui.h"
+#include "utils/delete2.h"
+
#include "debug.h"
int ProgressBar::mInstances = 0;
@@ -70,7 +72,6 @@ ProgressBar::ProgressBar(const Widget2 *const widget,
addWidgetListener(this);
setSize(width, height);
- Theme *const theme = Theme::instance();
if (theme)
{
mSkin = theme->load(skin, "progressbar.xml");
@@ -94,7 +95,6 @@ ProgressBar::~ProgressBar()
gui->removeDragged(this);
mInstances--;
- Theme *const theme = Theme::instance();
if (mSkin)
{
if (theme)
@@ -102,8 +102,7 @@ ProgressBar::~ProgressBar()
mSkin = nullptr;
}
Theme::unloadRect(mFillRect);
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
}
void ProgressBar::logic()
@@ -142,7 +141,7 @@ void ProgressBar::logic()
void ProgressBar::updateAlpha()
{
const float alpha = std::max(client->getGuiAlpha(),
- Theme::instance()->getMinimumOpacity());
+ theme->getMinimumOpacity());
mAlpha = alpha;
}
diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp
index 8e86417bd..c960ad075 100644
--- a/src/gui/widgets/progressindicator.cpp
+++ b/src/gui/widgets/progressindicator.cpp
@@ -28,6 +28,8 @@
#include "resources/animation.h"
#include "resources/imageset.h"
+#include "utils/delete2.h"
+
#include "debug.h"
ProgressIndicator::ProgressIndicator(Widget2 *const widget) :
@@ -54,8 +56,7 @@ ProgressIndicator::~ProgressIndicator()
if (gui)
gui->removeDragged(this);
- delete mIndicator;
- mIndicator = nullptr;
+ delete2(mIndicator);
}
void ProgressIndicator::logic()
diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp
index 411216455..643517f77 100644
--- a/src/gui/widgets/radiobutton.cpp
+++ b/src/gui/widgets/radiobutton.cpp
@@ -98,6 +98,7 @@ RadioButton::RadioButton(const Widget2 *const widget,
mSpacing(2),
mHasMouse(false)
{
+ mAllowLogic = false;
setCaption(caption);
setGroup(group);
setSelected(marked);
@@ -110,7 +111,6 @@ RadioButton::RadioButton(const Widget2 *const widget,
mForegroundColor2 = getThemeColor(Theme::RADIOBUTTON_OUTLINE);
if (instances == 0)
{
- Theme *const theme = Theme::instance();
if (theme)
{
mSkin = theme->load("radio.xml", "");
@@ -142,7 +142,6 @@ RadioButton::~RadioButton()
if (instances == 0)
{
- Theme *const theme = Theme::instance();
if (theme)
theme->unload(mSkin);
}
@@ -151,7 +150,7 @@ RadioButton::~RadioButton()
void RadioButton::updateAlpha()
{
const float alpha = std::max(client->getGuiAlpha(),
- Theme::instance()->getMinimumOpacity());
+ theme->getMinimumOpacity());
if (mAlpha != alpha)
{
@@ -236,14 +235,14 @@ void RadioButton::mouseExited(MouseEvent& event A_UNUSED)
mHasMouse = false;
}
-void RadioButton::keyPressed(KeyEvent& keyEvent)
+void RadioButton::keyPressed(KeyEvent& event)
{
- const int action = keyEvent.getActionId();
+ const int action = event.getActionId();
if (action == Input::KEY_GUI_SELECT)
{
setSelected(true);
distributeActionEvent();
- keyEvent.consume();
+ event.consume();
}
}
@@ -272,18 +271,19 @@ void RadioButton::setSelected(const bool selected)
mSelected = selected;
}
-void RadioButton::mouseClicked(MouseEvent& mouseEvent)
+void RadioButton::mouseClicked(MouseEvent& event)
{
- if (mouseEvent.getButton() == MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
setSelected(true);
+ event.consume();
distributeActionEvent();
}
}
-void RadioButton::mouseDragged(MouseEvent& mouseEvent)
+void RadioButton::mouseDragged(MouseEvent& event)
{
- mouseEvent.consume();
+ event.consume();
}
void RadioButton::setGroup(const std::string &group)
diff --git a/src/gui/widgets/radiobutton.h b/src/gui/widgets/radiobutton.h
index 5aa0d9289..ec1450f66 100644
--- a/src/gui/widgets/radiobutton.h
+++ b/src/gui/widgets/radiobutton.h
@@ -120,7 +120,7 @@ class RadioButton final : public Widget,
*/
void mouseExited(MouseEvent& event) override final;
- void keyPressed(KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& event) override final;
void updateAlpha();
@@ -164,9 +164,9 @@ class RadioButton final : public Widget,
void setCaption(const std::string &caption)
{ mCaption = caption; }
- void mouseClicked(MouseEvent& mouseEvent) override final;
+ void mouseClicked(MouseEvent& event) override final;
- void mouseDragged(MouseEvent& mouseEvent) override final;
+ void mouseDragged(MouseEvent& event) override final;
/**
* Sets the group the radio button should belong to. Note that
diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp
index 47b8b0985..2efa144c9 100644
--- a/src/gui/widgets/scrollarea.cpp
+++ b/src/gui/widgets/scrollarea.cpp
@@ -72,6 +72,8 @@
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
int ScrollArea::instances = 0;
@@ -164,10 +166,8 @@ ScrollArea::~ScrollArea()
}
}
- delete mVertexes;
- mVertexes = nullptr;
- delete mVertexes2;
- mVertexes2 = nullptr;
+ delete2(mVertexes);
+ delete2(mVertexes2);
setContent(nullptr);
}
@@ -195,7 +195,6 @@ void ScrollArea::init(std::string skinName)
// +++ here probably need move background from static
if (skinName == "")
skinName = "scroll_background.xml";
- Theme *const theme = Theme::instance();
if (theme)
{
theme->loadRect(background, skinName, "scroll_background.xml");
@@ -207,8 +206,9 @@ void ScrollArea::init(std::string skinName)
for (int i = 0; i < 2; i ++)
{
- Skin *const skin = Theme::instance()->load(
- buttonFiles[i], "scrollbuttons.xml");
+ Skin *skin = nullptr;
+ if (theme)
+ skin = theme->load(buttonFiles[i], "scrollbuttons.xml");
if (skin)
{
const ImageRect &rect = skin->getBorder();
@@ -230,7 +230,8 @@ void ScrollArea::init(std::string skinName)
for (int f = UP; f < BUTTONS_DIR; f ++)
buttons[f][i] = nullptr;
}
- Theme::instance()->unload(skin);
+ if (theme)
+ theme->unload(skin);
}
}
mScrollbarWidth = mScrollbarSize;
@@ -290,7 +291,7 @@ void ScrollArea::logic()
void ScrollArea::updateAlpha()
{
const float alpha = std::max(client->getGuiAlpha(),
- Theme::instance()->getMinimumOpacity());
+ theme->getMinimumOpacity());
if (alpha != mAlpha)
{
@@ -738,24 +739,28 @@ void ScrollArea::mousePressed(MouseEvent& event)
setVerticalScrollAmount(mVScroll
- mUpButtonScrollAmount);
mUpButtonPressed = true;
+ event.consume();
}
else if (getDownButtonDimension().isPointInRect(x, y))
{
setVerticalScrollAmount(mVScroll
+ mDownButtonScrollAmount);
mDownButtonPressed = true;
+ event.consume();
}
else if (getLeftButtonDimension().isPointInRect(x, y))
{
setHorizontalScrollAmount(mHScroll
- mLeftButtonScrollAmount);
mLeftButtonPressed = true;
+ event.consume();
}
else if (getRightButtonDimension().isPointInRect(x, y))
{
setHorizontalScrollAmount(mHScroll
+ mRightButtonScrollAmount);
mRightButtonPressed = true;
+ event.consume();
}
else if (getVerticalMarkerDimension().isPointInRect(x, y))
{
@@ -763,6 +768,7 @@ void ScrollArea::mousePressed(MouseEvent& event)
mIsVerticalMarkerDragged = true;
mVerticalMarkerDragOffset = y - getVerticalMarkerDimension().y;
+ event.consume();
}
else if (getVerticalBarDimension().isPointInRect(x, y))
{
@@ -776,13 +782,14 @@ void ScrollArea::mousePressed(MouseEvent& event)
setVerticalScrollAmount(mVScroll
+ static_cast<int>(getChildrenArea().height * 0.95));
}
+ event.consume();
}
else if (getHorizontalMarkerDimension().isPointInRect(x, y))
{
mIsHorizontalMarkerDragged = true;
mIsVerticalMarkerDragged = false;
-
mHorizontalMarkerDragOffset = x - getHorizontalMarkerDimension().x;
+ event.consume();
}
else if (getHorizontalBarDimension().isPointInRect(x, y))
{
@@ -796,6 +803,7 @@ void ScrollArea::mousePressed(MouseEvent& event)
setHorizontalScrollAmount(mHScroll
+ static_cast<int>(getChildrenArea().width * 0.95));
}
+ event.consume();
}
if (event.getButton() == MouseEvent::LEFT)
@@ -1301,26 +1309,26 @@ void ScrollArea::setDimension(const Rect& dimension)
checkPolicies();
}
-void ScrollArea::mouseWheelMovedUp(MouseEvent& mouseEvent)
+void ScrollArea::mouseWheelMovedUp(MouseEvent& event)
{
- if (mouseEvent.isConsumed())
+ if (event.isConsumed())
return;
setVerticalScrollAmount(getVerticalScrollAmount()
- getChildrenArea().height / 8);
- mouseEvent.consume();
+ event.consume();
}
-void ScrollArea::mouseWheelMovedDown(MouseEvent& mouseEvent)
+void ScrollArea::mouseWheelMovedDown(MouseEvent& event)
{
- if (mouseEvent.isConsumed())
+ if (event.isConsumed())
return;
setVerticalScrollAmount(getVerticalScrollAmount()
+ getChildrenArea().height / 8);
- mouseEvent.consume();
+ event.consume();
}
void ScrollArea::checkPolicies()
diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h
index 0b0cae2c3..d3d71b65a 100644
--- a/src/gui/widgets/scrollarea.h
+++ b/src/gui/widgets/scrollarea.h
@@ -420,9 +420,9 @@ class ScrollArea final : public BasicContainer,
void setDimension(const Rect& dimension);
- void mouseWheelMovedUp(MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedUp(MouseEvent& event) override final;
- void mouseWheelMovedDown(MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedDown(MouseEvent& event) override final;
protected:
enum BUTTON_DIR
diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp
index 007dc6442..ce2aa5aae 100644
--- a/src/gui/widgets/shoplistbox.cpp
+++ b/src/gui/widgets/shoplistbox.cpp
@@ -221,12 +221,12 @@ void ShopListBox::mouseMoved(MouseEvent &event)
}
}
-void ShopListBox::mouseReleased(MouseEvent& mouseEvent)
+void ShopListBox::mouseReleased(MouseEvent& event)
{
- ListBox::mouseReleased(mouseEvent);
- if (mouseEvent.getButton() == MouseEvent::RIGHT)
+ ListBox::mouseReleased(event);
+ if (event.getButton() == MouseEvent::RIGHT)
{
- setSelected(std::max(0, getSelectionByMouse(mouseEvent.getY())));
+ setSelected(std::max(0, getSelectionByMouse(event.getY())));
if (mSelected < 0 || mSelected >= mShopItems->getNumberOfElements())
return;
@@ -236,7 +236,7 @@ void ShopListBox::mouseReleased(MouseEvent& mouseEvent)
}
}
-void ShopListBox::mouseExited(MouseEvent& mouseEvent A_UNUSED)
+void ShopListBox::mouseExited(MouseEvent& event A_UNUSED)
{
if (!mItemPopup)
return;
diff --git a/src/gui/widgets/shoplistbox.h b/src/gui/widgets/shoplistbox.h
index 17c1ed4d5..ddb4407c7 100644
--- a/src/gui/widgets/shoplistbox.h
+++ b/src/gui/widgets/shoplistbox.h
@@ -76,9 +76,9 @@ class ShopListBox final : public ListBox
void mouseMoved(MouseEvent &event) override final;
- void mouseReleased(MouseEvent& mouseEvent) override final;
+ void mouseReleased(MouseEvent& event) override final;
- void mouseExited(MouseEvent& mouseEvent) override final;
+ void mouseExited(MouseEvent& event) override final;
void setProtectItems(bool p)
{ mProtectItems = p; }
diff --git a/src/gui/widgets/shortcutcontainer.cpp b/src/gui/widgets/shortcutcontainer.cpp
index 0d9aa64a6..49be84b88 100644
--- a/src/gui/widgets/shortcutcontainer.cpp
+++ b/src/gui/widgets/shortcutcontainer.cpp
@@ -26,6 +26,8 @@
#include "gui/gui.h"
+#include "utils/delete2.h"
+
#include "debug.h"
float ShortcutContainer::mAlpha = 1.0;
@@ -43,6 +45,7 @@ ShortcutContainer::ShortcutContainer(Widget2 *const widget) :
mVertexes(new ImageCollection),
mRedraw(true)
{
+ mAllowLogic = false;
}
ShortcutContainer::~ShortcutContainer()
@@ -50,8 +53,7 @@ ShortcutContainer::~ShortcutContainer()
if (gui)
gui->removeDragged(this);
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
}
void ShortcutContainer::widgetResized(const Event &event A_UNUSED)
diff --git a/src/gui/widgets/skillinfo.h b/src/gui/widgets/skillinfo.h
index f9baec6cc..06e3b3583 100644
--- a/src/gui/widgets/skillinfo.h
+++ b/src/gui/widgets/skillinfo.h
@@ -27,6 +27,7 @@
#include <vector>
#include <map>
+#include <string>
#include "localconsts.h"
diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp
index 700d31416..e440631ad 100644
--- a/src/gui/widgets/slider.cpp
+++ b/src/gui/widgets/slider.cpp
@@ -76,6 +76,8 @@
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
ImageRect Slider::buttons[2];
@@ -130,10 +132,9 @@ Slider::~Slider()
if (gui)
gui->removeDragged(this);
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
mInstances--;
- if (mInstances == 0 && Theme::instance())
+ if (mInstances == 0)
{
for (int mode = 0; mode < 2; mode ++)
Theme::unloadRect(buttons[mode]);
@@ -142,6 +143,7 @@ Slider::~Slider()
void Slider::init()
{
+ mAllowLogic = false;
setFocusable(true);
setFrameSize(1);
@@ -153,7 +155,6 @@ void Slider::init()
// Load resources
if (mInstances == 0)
{
- Theme *const theme = Theme::instance();
if (theme)
{
for (int mode = 0; mode < 2; mode ++)
@@ -171,7 +172,7 @@ void Slider::init()
void Slider::updateAlpha()
{
const float alpha = std::max(client->getGuiAlpha(),
- Theme::instance()->getMinimumOpacity());
+ theme->getMinimumOpacity());
if (alpha != mAlpha)
{
@@ -352,16 +353,17 @@ void Slider::mouseExited(MouseEvent& event A_UNUSED)
mRedraw = true;
}
-void Slider::mousePressed(MouseEvent &mouseEvent)
+void Slider::mousePressed(MouseEvent &event)
{
- const int x = mouseEvent.getX();
- const int y = mouseEvent.getY();
+ const int x = event.getX();
+ const int y = event.getY();
const int width = mDimension.width;
const int height = mDimension.height;
- if (mouseEvent.getButton() == MouseEvent::LEFT
+ if (event.getButton() == MouseEvent::LEFT
&& x >= 0 && x <= width && y >= 0 && y <= height)
{
+ event.consume();
if (mOrientation == HORIZONTAL)
setValue(markerPositionToValue(x - mMarkerLength / 2));
else
@@ -371,40 +373,40 @@ void Slider::mousePressed(MouseEvent &mouseEvent)
}
}
-void Slider::mouseDragged(MouseEvent &mouseEvent)
+void Slider::mouseDragged(MouseEvent &event)
{
if (mOrientation == HORIZONTAL)
{
- setValue(markerPositionToValue(mouseEvent.getX() - mMarkerLength / 2));
+ setValue(markerPositionToValue(event.getX() - mMarkerLength / 2));
}
else
{
setValue(markerPositionToValue(
- mDimension.height - mouseEvent.getY() - mMarkerLength / 2));
+ mDimension.height - event.getY() - mMarkerLength / 2));
}
distributeActionEvent();
- mouseEvent.consume();
+ event.consume();
}
-void Slider::mouseWheelMovedUp(MouseEvent &mouseEvent)
+void Slider::mouseWheelMovedUp(MouseEvent &event)
{
setValue(mValue + mStepLength);
distributeActionEvent();
- mouseEvent.consume();
+ event.consume();
}
-void Slider::mouseWheelMovedDown(MouseEvent &mouseEvent)
+void Slider::mouseWheelMovedDown(MouseEvent &event)
{
setValue(mValue - mStepLength);
distributeActionEvent();
- mouseEvent.consume();
+ event.consume();
}
-void Slider::keyPressed(KeyEvent& keyEvent)
+void Slider::keyPressed(KeyEvent& event)
{
- const int action = keyEvent.getActionId();
+ const int action = event.getActionId();
if (mOrientation == HORIZONTAL)
{
@@ -412,13 +414,13 @@ void Slider::keyPressed(KeyEvent& keyEvent)
{
setValue(mValue + mStepLength);
distributeActionEvent();
- keyEvent.consume();
+ event.consume();
}
else if (action == Input::KEY_GUI_LEFT)
{
setValue(mValue - mStepLength);
distributeActionEvent();
- keyEvent.consume();
+ event.consume();
}
}
else
@@ -427,13 +429,13 @@ void Slider::keyPressed(KeyEvent& keyEvent)
{
setValue(mValue + mStepLength);
distributeActionEvent();
- keyEvent.consume();
+ event.consume();
}
else if (action == Input::KEY_GUI_DOWN)
{
setValue(mValue - mStepLength);
distributeActionEvent();
- keyEvent.consume();
+ event.consume();
}
}
}
diff --git a/src/gui/widgets/slider.h b/src/gui/widgets/slider.h
index 23d06de48..164048020 100644
--- a/src/gui/widgets/slider.h
+++ b/src/gui/widgets/slider.h
@@ -135,15 +135,15 @@ class Slider final : public Widget,
*/
void mouseExited(MouseEvent& event) override final;
- void mousePressed(MouseEvent &mouseEvent) override final;
+ void mousePressed(MouseEvent &event) override final;
- void mouseDragged(MouseEvent &mouseEvent) override final;
+ void mouseDragged(MouseEvent &event) override final;
- void mouseWheelMovedUp(MouseEvent &mouseEvent) override final;
+ void mouseWheelMovedUp(MouseEvent &event) override final;
- void mouseWheelMovedDown(MouseEvent &mouseEvent) override final;
+ void mouseWheelMovedDown(MouseEvent &event) override final;
- void keyPressed(KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& event) override final;
/**
* Sets the scale of the slider.
diff --git a/src/gui/widgets/sliderlist.cpp b/src/gui/widgets/sliderlist.cpp
index 03f0c4ed2..76e6b54c3 100644
--- a/src/gui/widgets/sliderlist.cpp
+++ b/src/gui/widgets/sliderlist.cpp
@@ -46,6 +46,7 @@ SliderList::SliderList(const Widget2 *const widget,
mOldWidth(0),
mSelectedIndex(0)
{
+ mAllowLogic = false;
setHeight(sliderHeight);
}
@@ -81,16 +82,16 @@ void SliderList::updateAlpha()
Button::updateAlpha();
}
-void SliderList::mouseWheelMovedUp(MouseEvent& mouseEvent)
+void SliderList::mouseWheelMovedUp(MouseEvent& event)
{
setSelected(mSelectedIndex - 1);
- mouseEvent.consume();
+ event.consume();
}
-void SliderList::mouseWheelMovedDown(MouseEvent& mouseEvent)
+void SliderList::mouseWheelMovedDown(MouseEvent& event)
{
setSelected(mSelectedIndex + 1);
- mouseEvent.consume();
+ event.consume();
}
void SliderList::resize()
diff --git a/src/gui/widgets/sliderlist.h b/src/gui/widgets/sliderlist.h
index 84f96ebe4..dac7beabd 100644
--- a/src/gui/widgets/sliderlist.h
+++ b/src/gui/widgets/sliderlist.h
@@ -49,9 +49,9 @@ class SliderList final : public Container,
void updateAlpha();
- void mouseWheelMovedUp(MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedUp(MouseEvent& event) override final;
- void mouseWheelMovedDown(MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedDown(MouseEvent& event) override final;
void resize();
diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp
index ed92b62e1..e86376812 100644
--- a/src/gui/widgets/spellshortcutcontainer.cpp
+++ b/src/gui/widgets/spellshortcutcontainer.cpp
@@ -36,6 +36,8 @@
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
SpellShortcutContainer::SpellShortcutContainer(Widget2 *const widget,
@@ -78,8 +80,7 @@ SpellShortcutContainer::~SpellShortcutContainer()
if (mBackgroundImg)
mBackgroundImg->decRef();
mBackgroundImg = nullptr;
- delete mSpellPopup;
- mSpellPopup = nullptr;
+ delete2(mSpellPopup);
}
void SpellShortcutContainer::setWidget2(const Widget2 *const widget)
@@ -189,6 +190,7 @@ void SpellShortcutContainer::mousePressed(MouseEvent &event)
const int itemId = getItemByIndex(index);
if (itemId > 0)
mSpellClicked = true;
+ event.consume();
}
else if (eventButton == MouseEvent::RIGHT)
{
@@ -198,6 +200,7 @@ void SpellShortcutContainer::mousePressed(MouseEvent &event)
if (!spellShortcut || !spellManager)
return;
+ event.consume();
const int itemId = getItemByIndex(index);
spellManager->invoke(itemId);
}
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index 445f17982..cf55fa10b 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -75,6 +75,8 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/tabs/tab.h"
+#include "utils/delete2.h"
+
#include "debug.h"
TabbedArea::TabbedArea(const Widget2 *const widget) :
@@ -127,21 +129,14 @@ TabbedArea::~TabbedArea()
remove(mTabContainer);
remove(mWidgetContainer);
- delete mTabContainer;
- mTabContainer = nullptr;
- delete mWidgetContainer;
- mWidgetContainer = nullptr;
+ delete2(mTabContainer);
+ delete2(mWidgetContainer);
for (size_t i = 0, sz = mTabsToDelete.size(); i < sz; i++)
- {
- delete mTabsToDelete[i];
- mTabsToDelete[i] = nullptr;
- }
+ delete2(mTabsToDelete[i])
- delete mArrowButton[0];
- mArrowButton[0] = nullptr;
- delete mArrowButton[1];
- mArrowButton[1] = nullptr;
+ delete2(mArrowButton[0]);
+ delete2(mArrowButton[1]);
}
void TabbedArea::enableScrollButtons(const bool enable)
@@ -366,19 +361,20 @@ void TabbedArea::logic()
BLOCK_END("TabbedArea::logic")
}
-void TabbedArea::mousePressed(MouseEvent &mouseEvent)
+void TabbedArea::mousePressed(MouseEvent &event)
{
- if (mouseEvent.isConsumed())
+ if (event.isConsumed())
return;
- if (mouseEvent.getButton() == MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
Widget *const widget = mTabContainer->getWidgetAt(
- mouseEvent.getX(), mouseEvent.getY());
+ event.getX(), event.getY());
Tab *const tab = dynamic_cast<Tab *const>(widget);
if (tab)
{
+ event.consume();
setSelectedTab(tab);
requestFocus();
}
@@ -726,12 +722,12 @@ void TabbedArea::setDimension(const Rect &dimension)
adjustSize();
}
-void TabbedArea::keyPressed(KeyEvent& keyEvent)
+void TabbedArea::keyPressed(KeyEvent& event)
{
- if (mBlockSwitching || keyEvent.isConsumed() || !isFocused())
+ if (mBlockSwitching || event.isConsumed() || !isFocused())
return;
- const int actionId = keyEvent.getActionId();
+ const int actionId = event.getActionId();
if (actionId == Input::KEY_GUI_LEFT)
{
@@ -743,7 +739,7 @@ void TabbedArea::keyPressed(KeyEvent& keyEvent)
else
setSelectedTab(mTabs[index].first);
- keyEvent.consume();
+ event.consume();
}
else if (actionId == Input::KEY_GUI_RIGHT)
{
@@ -755,7 +751,7 @@ void TabbedArea::keyPressed(KeyEvent& keyEvent)
else
setSelectedTab(mTabs[index].first);
- keyEvent.consume();
+ event.consume();
}
}
diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h
index 0e7a032f0..578128abf 100644
--- a/src/gui/widgets/tabbedarea.h
+++ b/src/gui/widgets/tabbedarea.h
@@ -195,7 +195,7 @@ class TabbedArea final : public ActionListener,
// Inherited from MouseListener
- void mousePressed(MouseEvent &mouseEvent) override final;
+ void mousePressed(MouseEvent &event) override final;
void enableScrollButtons(const bool enable);
@@ -211,7 +211,7 @@ class TabbedArea final : public ActionListener,
bool getFollowDownScroll() const A_WARN_UNUSED
{ return mFollowDownScroll; }
- void keyPressed(KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& event) override final;
void setBlockSwitching(const bool b)
{ mBlockSwitching = b; }
diff --git a/src/gui/widgets/tabs/chattab.cpp b/src/gui/widgets/tabs/chattab.cpp
index 8fe9d707b..e52f935b3 100644
--- a/src/gui/widgets/tabs/chattab.cpp
+++ b/src/gui/widgets/tabs/chattab.cpp
@@ -45,6 +45,7 @@
#include "resources/db/itemdb.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -85,10 +86,8 @@ ChatTab::~ChatTab()
if (chatWindow)
chatWindow->removeTab(this);
- delete mTextOutput;
- mTextOutput = nullptr;
- delete mScrollArea;
- mScrollArea = nullptr;
+ delete2(mTextOutput);
+ delete2(mScrollArea);
}
void ChatTab::chatLog(std::string line, Own own,
diff --git a/src/gui/widgets/tabs/setup_audio.cpp b/src/gui/widgets/tabs/setup_audio.cpp
index 6cf675635..89a9594c1 100644
--- a/src/gui/widgets/tabs/setup_audio.cpp
+++ b/src/gui/widgets/tabs/setup_audio.cpp
@@ -35,6 +35,7 @@
#include "gui/widgets/layouthelper.h"
#include "gui/widgets/scrollarea.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -160,11 +161,8 @@ Setup_Audio::Setup_Audio(const Widget2 *const widget) :
Setup_Audio::~Setup_Audio()
{
- delete mSoundModel;
- mSoundModel = nullptr;
-
- delete mChannelsList;
- mChannelsList = nullptr;
+ delete2(mSoundModel);
+ delete2(mChannelsList);
}
void Setup_Audio::apply()
diff --git a/src/gui/widgets/tabs/setup_colors.cpp b/src/gui/widgets/tabs/setup_colors.cpp
index eb7e695f4..00537ad05 100644
--- a/src/gui/widgets/tabs/setup_colors.cpp
+++ b/src/gui/widgets/tabs/setup_colors.cpp
@@ -34,6 +34,7 @@
#include "gui/widgets/textfield.h"
#include "gui/widgets/textpreview.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
@@ -198,15 +199,9 @@ Setup_Colors::Setup_Colors(const Widget2 *const widget) :
Setup_Colors::~Setup_Colors()
{
if (mPreviewBox && mPreviewBox->getContent() == mPreview)
- {
- delete mTextPreview;
- mTextPreview = nullptr;
- }
+ delete2(mTextPreview)
else
- {
- delete mPreview;
- mPreview = nullptr;
- }
+ delete2(mPreview)
}
void Setup_Colors::action(const ActionEvent &event)
diff --git a/src/gui/widgets/tabs/setup_input.cpp b/src/gui/widgets/tabs/setup_input.cpp
index b04937881..a29e0d797 100644
--- a/src/gui/widgets/tabs/setup_input.cpp
+++ b/src/gui/widgets/tabs/setup_input.cpp
@@ -41,6 +41,8 @@
#include "gui/models/listmodel.h"
+#include "utils/delete2.h"
+
#include "debug.h"
static int selectedData = 0;
@@ -169,21 +171,14 @@ Setup_Input::Setup_Input(const Widget2 *const widget) :
Setup_Input::~Setup_Input()
{
- delete mKeyList;
- mKeyList = nullptr;
- delete mKeyListModel;
- mKeyListModel = nullptr;
-
- delete mAssignKeyButton;
- mAssignKeyButton = nullptr;
- delete mUnassignKeyButton;
- mUnassignKeyButton = nullptr;
- delete mResetKeysButton;
- mResetKeysButton = nullptr;
+ delete2(mKeyList);
+ delete2(mKeyListModel);
+ delete2(mAssignKeyButton);
+ delete2(mUnassignKeyButton);
+ delete2(mResetKeysButton);
delete [] mActionDataSize;
mActionDataSize = nullptr;
- delete mScrollArea;
- mScrollArea = nullptr;
+ delete2(mScrollArea);
}
void Setup_Input::apply()
diff --git a/src/gui/widgets/tabs/setup_joystick.cpp b/src/gui/widgets/tabs/setup_joystick.cpp
index b3d7b78b9..4d2845656 100644
--- a/src/gui/widgets/tabs/setup_joystick.cpp
+++ b/src/gui/widgets/tabs/setup_joystick.cpp
@@ -34,6 +34,7 @@
#include "gui/widgets/label.h"
#include "gui/widgets/layouthelper.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -99,8 +100,7 @@ Setup_Joystick::Setup_Joystick(const Widget2 *const widget) :
Setup_Joystick::~Setup_Joystick()
{
- delete mNamesModel;
- mNamesModel = nullptr;
+ delete2(mNamesModel);
}
void Setup_Joystick::action(const ActionEvent &event)
diff --git a/src/gui/widgets/tabs/setup_other.cpp b/src/gui/widgets/tabs/setup_other.cpp
index e4801506c..ed8ba11ad 100644
--- a/src/gui/widgets/tabs/setup_other.cpp
+++ b/src/gui/widgets/tabs/setup_other.cpp
@@ -31,6 +31,7 @@
#include "configuration.h"
#include "map.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -182,6 +183,10 @@ Setup_Other::Setup_Other(const Widget2 *const widget) :
"autofixPos", this, "autofixPosEvent");
// TRANSLATORS: settings option
+ new SetupItemCheckBox(_("Show server side position"), "",
+ "showserverpos", this, "showserverposEvent");
+
+ // TRANSLATORS: settings option
new SetupItemCheckBox(_("Attack while moving"), "",
"attackMoving", this, "attackMovingEvent");
@@ -334,6 +339,10 @@ Setup_Other::Setup_Other(const Widget2 *const widget) :
"serverAttack", this, "serverAttackEvent");
// TRANSLATORS: settings option
+ new SetupItemCheckBox(_("Hide support page link on error"), "",
+ "hidesupport", this, "hidesupportEvent");
+
+ // TRANSLATORS: settings option
new SetupItemCheckBox(_("Enable double clicks"), "",
"doubleClick", this, "doubleClickEvent");
@@ -396,12 +405,9 @@ Setup_Other::Setup_Other(const Widget2 *const widget) :
Setup_Other::~Setup_Other()
{
- delete mProxyTypeList;
- mProxyTypeList = nullptr;
- delete mShortcutsList;
- mShortcutsList = nullptr;
- delete mDensityList;
- mDensityList = nullptr;
+ delete2(mProxyTypeList);
+ delete2(mShortcutsList);
+ delete2(mDensityList);
}
void Setup_Other::apply()
diff --git a/src/gui/widgets/tabs/setup_perfomance.cpp b/src/gui/widgets/tabs/setup_perfomance.cpp
index 5a0566ec2..dad054e83 100644
--- a/src/gui/widgets/tabs/setup_perfomance.cpp
+++ b/src/gui/widgets/tabs/setup_perfomance.cpp
@@ -28,6 +28,7 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/setupitem.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -159,6 +160,5 @@ Setup_Perfomance::Setup_Perfomance(const Widget2 *const widget) :
Setup_Perfomance::~Setup_Perfomance()
{
- delete mTexturesList;
- mTexturesList = nullptr;
+ delete2(mTexturesList);
}
diff --git a/src/gui/widgets/tabs/setup_players.cpp b/src/gui/widgets/tabs/setup_players.cpp
index b04a25e22..441ebba58 100644
--- a/src/gui/widgets/tabs/setup_players.cpp
+++ b/src/gui/widgets/tabs/setup_players.cpp
@@ -102,7 +102,7 @@ Setup_Players::Setup_Players(const Widget2 *const widget) :
// TRANSLATORS: settings option
new SetupItemCheckBox(_("Emulate right mouse button by long mouse click"
- " (usefull for touch interfaces)"),
+ " (useful for touch interfaces)"),
"", "longmouseclick", this, "longmouseclickEvent");
setDimension(Rect(0, 0, 550, 350));
diff --git a/src/gui/widgets/tabs/setup_relations.cpp b/src/gui/widgets/tabs/setup_relations.cpp
index ca060477f..77a758cb4 100644
--- a/src/gui/widgets/tabs/setup_relations.cpp
+++ b/src/gui/widgets/tabs/setup_relations.cpp
@@ -37,6 +37,7 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/guitable.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -81,10 +82,8 @@ public:
~PlayerTableModel()
{
freeWidgets();
- delete mListModel;
- mListModel = nullptr;
- delete mPlayers;
- mPlayers = nullptr;
+ delete2(mListModel)
+ delete2(mPlayers)
}
int getRows() const override final
@@ -159,9 +158,7 @@ public:
void freeWidgets()
{
- delete mPlayers;
- mPlayers = nullptr;
-
+ delete2(mPlayers)
delete_all(mWidgets);
mWidgets.clear();
}
@@ -266,8 +263,7 @@ Setup_Relations::Setup_Relations(const Widget2 *const widget) :
Setup_Relations::~Setup_Relations()
{
player_relations.removeListener(this);
- delete mIgnoreActionChoicesModel;
- mIgnoreActionChoicesModel = nullptr;
+ delete2(mIgnoreActionChoicesModel);
}
diff --git a/src/gui/widgets/tabs/setup_theme.cpp b/src/gui/widgets/tabs/setup_theme.cpp
index 424828694..9b23fc3c3 100644
--- a/src/gui/widgets/tabs/setup_theme.cpp
+++ b/src/gui/widgets/tabs/setup_theme.cpp
@@ -37,6 +37,7 @@
#include "configuration.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "resources/resourcemanager.h"
@@ -371,26 +372,13 @@ Setup_Theme::Setup_Theme(const Widget2 *const widget) :
Setup_Theme::~Setup_Theme()
{
- delete mInfo;
- mInfo = nullptr;
-
- delete mThemesModel;
- mThemesModel = nullptr;
-
- delete mFontsModel;
- mFontsModel = nullptr;
-
- delete mFontSizeListModel;
- mFontSizeListModel = nullptr;
-
- delete mNpcFontSizeListModel;
- mNpcFontSizeListModel = nullptr;
-
- delete mLangListModel;
- mLangListModel = nullptr;
-
- delete mInfo;
- mInfo = nullptr;
+ delete2(mInfo);
+ delete2(mThemesModel);
+ delete2(mFontsModel);
+ delete2(mFontSizeListModel);
+ delete2(mNpcFontSizeListModel);
+ delete2(mLangListModel);
+ delete2(mInfo);
}
void Setup_Theme::updateInfo()
diff --git a/src/gui/widgets/tabs/setup_touch.cpp b/src/gui/widgets/tabs/setup_touch.cpp
index fb50ab4d5..eab39ccb0 100644
--- a/src/gui/widgets/tabs/setup_touch.cpp
+++ b/src/gui/widgets/tabs/setup_touch.cpp
@@ -27,6 +27,7 @@
#include "gui/widgets/setuptouchitem.h"
#include "gui/widgets/scrollarea.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
@@ -126,10 +127,7 @@ Setup_Touch::Setup_Touch(const Widget2 *const widget) :
Setup_Touch::~Setup_Touch()
{
- delete mSizeList;
- mSizeList = nullptr;
- delete mFormatList;
- mFormatList = nullptr;
- delete mActionsList;
- mActionsList = nullptr;
+ delete2(mSizeList);
+ delete2(mFormatList);
+ delete2(mActionsList);
}
diff --git a/src/gui/widgets/tabs/setup_video.cpp b/src/gui/widgets/tabs/setup_video.cpp
index 416ae8c3c..dfe14fa2c 100644
--- a/src/gui/widgets/tabs/setup_video.cpp
+++ b/src/gui/widgets/tabs/setup_video.cpp
@@ -41,6 +41,7 @@
#include "render/rendererslistsdl.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/sdlhelper.h"
@@ -309,14 +310,10 @@ Setup_Video::Setup_Video(const Widget2 *const widget) :
Setup_Video::~Setup_Video()
{
- delete mModeListModel;
- mModeListModel = nullptr;
- delete mModeList;
- mModeList = nullptr;
- delete mOpenGLListModel;
- mOpenGLListModel = nullptr;
- delete mDialog;
- mDialog = nullptr;
+ delete2(mModeListModel);
+ delete2(mModeList);
+ delete2(mOpenGLListModel);
+ delete2(mDialog);
}
void Setup_Video::apply()
diff --git a/src/gui/widgets/tabs/setup_visual.cpp b/src/gui/widgets/tabs/setup_visual.cpp
index 860b1d516..eb6591f9f 100644
--- a/src/gui/widgets/tabs/setup_visual.cpp
+++ b/src/gui/widgets/tabs/setup_visual.cpp
@@ -28,6 +28,7 @@
#include "client.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -215,18 +216,12 @@ Setup_Visual::Setup_Visual(const Widget2 *const widget) :
Setup_Visual::~Setup_Visual()
{
- delete mSpeachList;
- mSpeachList = nullptr;
- delete mAmbientFxList;
- mAmbientFxList = nullptr;
- delete mParticleList;
- mParticleList = nullptr;
- delete mParticleTypeList;
- mParticleTypeList = nullptr;
- delete mVSyncList;
- mVSyncList = nullptr;
- delete mScaleList;
- mScaleList = nullptr;
+ delete2(mSpeachList);
+ delete2(mAmbientFxList);
+ delete2(mParticleList);
+ delete2(mParticleTypeList);
+ delete2(mVSyncList);
+ delete2(mScaleList);
}
void Setup_Visual::apply()
diff --git a/src/gui/widgets/tabs/setuptabscroll.cpp b/src/gui/widgets/tabs/setuptabscroll.cpp
index 9c185b2bb..cd169e0bf 100644
--- a/src/gui/widgets/tabs/setuptabscroll.cpp
+++ b/src/gui/widgets/tabs/setuptabscroll.cpp
@@ -24,6 +24,8 @@
#include "gui/widgets/setupitem.h"
#include "gui/widgets/vertcontainer.h"
+#include "utils/delete2.h"
+
#include "debug.h"
SetupTabScroll::SetupTabScroll(const Widget2 *const widget) :
@@ -41,10 +43,7 @@ SetupTabScroll::SetupTabScroll(const Widget2 *const widget) :
SetupTabScroll::~SetupTabScroll()
{
mScroll = nullptr;
-
- delete mContainer;
- mContainer = nullptr;
-
+ delete2(mContainer);
removeItems();
}
diff --git a/src/gui/widgets/tabs/tab.cpp b/src/gui/widgets/tabs/tab.cpp
index ede69619e..c2a6c0207 100644
--- a/src/gui/widgets/tabs/tab.cpp
+++ b/src/gui/widgets/tabs/tab.cpp
@@ -75,6 +75,8 @@
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
int Tab::mInstances = 0;
@@ -123,23 +125,20 @@ Tab::~Tab()
gui->removeDragged(this);
mInstances--;
- if (mInstances == 0 && Theme::instance())
+ if (mInstances == 0 && theme)
{
- Theme *const theme = Theme::instance();
for (int mode = 0; mode < TAB_COUNT; mode ++)
theme->unload(tabImg[mode]);
}
- delete mLabel;
- mLabel = nullptr;
+ delete2(mLabel);
if (mImage)
{
mImage->decRef();
mImage = nullptr;
}
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
}
void Tab::init()
@@ -154,7 +153,6 @@ void Tab::init()
if (mInstances == 0)
{
// Load the skin
- Theme *const theme = Theme::instance();
if (theme)
{
for (int mode = 0; mode < TAB_COUNT; mode ++)
@@ -177,7 +175,7 @@ void Tab::init()
void Tab::updateAlpha()
{
const float alpha = std::max(client->getGuiAlpha(),
- Theme::instance()->getMinimumOpacity());
+ theme->getMinimumOpacity());
if (alpha != mAlpha)
{
@@ -373,12 +371,12 @@ const std::string &Tab::getCaption() const
return mLabel->getCaption();
}
-void Tab::mouseEntered(MouseEvent& mouseEvent A_UNUSED)
+void Tab::mouseEntered(MouseEvent& event A_UNUSED)
{
mHasMouse = true;
}
-void Tab::mouseExited(MouseEvent& mouseEvent A_UNUSED)
+void Tab::mouseExited(MouseEvent& event A_UNUSED)
{
mHasMouse = false;
}
diff --git a/src/gui/widgets/tabs/tab.h b/src/gui/widgets/tabs/tab.h
index 246d90650..a0afa6fcd 100644
--- a/src/gui/widgets/tabs/tab.h
+++ b/src/gui/widgets/tabs/tab.h
@@ -189,9 +189,9 @@ class Tab : public BasicContainer,
const std::string &getCaption() const A_WARN_UNUSED;
- void mouseEntered(MouseEvent &mouseEvent) override final;
+ void mouseEntered(MouseEvent &event) override final;
- void mouseExited(MouseEvent &mouseEvent) override final;
+ void mouseExited(MouseEvent &event) override final;
void setImage(Image *const image);
diff --git a/src/gui/widgets/tabstrip.cpp b/src/gui/widgets/tabstrip.cpp
index 57520afce..e6459a103 100644
--- a/src/gui/widgets/tabstrip.cpp
+++ b/src/gui/widgets/tabstrip.cpp
@@ -30,6 +30,7 @@ TabStrip::TabStrip(const Widget2 *const widget,
const int spacing) :
WidgetGroup(widget, group, height, spacing)
{
+ mAllowLogic = false;
}
TabStrip::TabStrip(const Widget2 *const widget,
@@ -37,6 +38,7 @@ TabStrip::TabStrip(const Widget2 *const widget,
const int spacing) :
WidgetGroup(widget, "", height, spacing)
{
+ mAllowLogic = false;
}
Widget *TabStrip::createWidget(const std::string &text) const
@@ -55,8 +57,8 @@ void TabStrip::action(const ActionEvent &event)
WidgetGroup::action(event);
if (event.getSource())
{
- Widget *const widget = event.getSource();
- if (static_cast<Button*>(widget)->isPressed2())
+ const Widget *const widget = event.getSource();
+ if (static_cast<const Button*>(widget)->isPressed2())
{
FOR_EACH (WidgetListConstIterator, iter, mWidgets)
{
diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp
index 5f565259b..b1849e801 100644
--- a/src/gui/widgets/textbox.cpp
+++ b/src/gui/widgets/textbox.cpp
@@ -85,6 +85,7 @@ TextBox::TextBox(const Widget2 *const widget) :
mEditable(true),
mOpaque(true)
{
+ mAllowLogic = false;
setText("");
setFocusable(true);
@@ -247,10 +248,10 @@ void TextBox::setText(const std::string& text)
adjustSize();
}
-void TextBox::keyPressed(KeyEvent& keyEvent)
+void TextBox::keyPressed(KeyEvent& event)
{
- const Key &key = keyEvent.getKey();
- const int action = keyEvent.getActionId();
+ const Key &key = event.getKey();
+ const int action = event.getActionId();
switch (action)
{
@@ -429,7 +430,7 @@ void TextBox::keyPressed(KeyEvent& keyEvent)
adjustSize();
scrollToCaret();
- keyEvent.consume();
+ event.consume();
}
void TextBox::draw(Graphics* graphics)
@@ -581,28 +582,29 @@ void TextBox::addRow(const std::string &row)
adjustSize();
}
-void TextBox::mousePressed(MouseEvent& mouseEvent)
+void TextBox::mousePressed(MouseEvent& event)
{
- if (mouseEvent.getButton() == MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
const int height = getFont()->getHeight();
if (!height)
return;
- mCaretRow = mouseEvent.getY() / height;
+ event.consume();
+ mCaretRow = event.getY() / height;
const int sz = static_cast<int>(mTextRows.size());
if (mCaretRow >= sz)
mCaretRow = sz - 1;
mCaretColumn = getFont()->getStringIndexAt(
- mTextRows[mCaretRow], mouseEvent.getX());
+ mTextRows[mCaretRow], event.getX());
}
}
-void TextBox::mouseDragged(MouseEvent& mouseEvent)
+void TextBox::mouseDragged(MouseEvent& event)
{
- mouseEvent.consume();
+ event.consume();
}
void TextBox::drawCaret(Graphics *const graphics, const int x, const int y)
diff --git a/src/gui/widgets/textbox.h b/src/gui/widgets/textbox.h
index e5cfbc7c9..e8c1d3840 100644
--- a/src/gui/widgets/textbox.h
+++ b/src/gui/widgets/textbox.h
@@ -105,7 +105,7 @@ class TextBox final : public Widget,
int getMinWidth() const A_WARN_UNUSED
{ return mMinWidth; }
- void keyPressed(KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& event) override final;
void draw(Graphics* graphics) override final;
@@ -272,9 +272,9 @@ class TextBox final : public Widget,
void fontChanged() override final
{ adjustSize(); }
- void mousePressed(MouseEvent& mouseEvent) override final;
+ void mousePressed(MouseEvent& event) override final;
- void mouseDragged(MouseEvent& mouseEvent) override final;
+ void mouseDragged(MouseEvent& event) override final;
private:
/**
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index 7fe8c1bf3..f89d2ead2 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -78,6 +78,7 @@
#include "resources/image.h"
#include "utils/copynpaste.h"
+#include "utils/delete2.h"
#include "utils/timer.h"
#undef DELETE // Win32 compatibility hack
@@ -113,6 +114,7 @@ TextField::TextField(const Widget2 *restrict const widget,
mAllowSpecialActions(true),
mSendAlwaysEvents(sendAlwaysEvents)
{
+ mAllowLogic = false;
setFocusable(true);
addMouseListener(this);
addKeyListener(this);
@@ -125,7 +127,6 @@ TextField::TextField(const Widget2 *restrict const widget,
if (instances == 0)
{
- Theme *const theme = Theme::instance();
if (theme)
{
mSkin = theme->loadSkinRect(skin, "textfield.xml",
@@ -154,13 +155,11 @@ TextField::~TextField()
if (gui)
gui->removeDragged(this);
- delete mPopupMenu;
- mPopupMenu = nullptr;
+ delete2(mPopupMenu);
instances--;
if (instances == 0)
{
- Theme *const theme = Theme::instance();
if (theme)
{
theme->unload(mSkin);
@@ -172,7 +171,7 @@ TextField::~TextField()
void TextField::updateAlpha()
{
const float alpha = std::max(client->getGuiAlpha(),
- Theme::instance()->getMinimumOpacity());
+ theme->getMinimumOpacity());
if (alpha != mAlpha)
{
@@ -246,16 +245,16 @@ int TextField::getValue() const
return value;
}
-void TextField::keyPressed(KeyEvent &keyEvent)
+void TextField::keyPressed(KeyEvent &event)
{
- const int val = keyEvent.getKey().getValue();
+ const int val = event.getKey().getValue();
#ifdef USE_SDL2
if (val == Key::TEXTINPUT)
{
- std::string str = keyEvent.getText();
+ std::string str = event.getText();
mText.insert(mCaretPosition, str);
mCaretPosition += str.size();
- keyEvent.consume();
+ event.consume();
fixScroll();
if (mSendAlwaysEvents)
distributeActionEvent();
@@ -274,7 +273,7 @@ void TextField::keyPressed(KeyEvent &keyEvent)
buf[1] = 0;
mText.insert(mCaretPosition, std::string(buf));
mCaretPosition += 1;
- keyEvent.consume();
+ event.consume();
fixScroll();
if (mSendAlwaysEvents)
distributeActionEvent();
@@ -306,7 +305,7 @@ void TextField::keyPressed(KeyEvent &keyEvent)
mText.insert(mCaretPosition, std::string(buf, buf + len));
mCaretPosition += len;
- keyEvent.consume();
+ event.consume();
fixScroll();
if (mSendAlwaysEvents)
distributeActionEvent();
@@ -324,14 +323,14 @@ void TextField::keyPressed(KeyEvent &keyEvent)
bool consumed(false);
#endif
- const int action = keyEvent.getActionId();
+ const int action = event.getActionId();
if (!inputManager.isActionActive(static_cast<int>(
Input::KEY_GUI_CTRL)))
{
if (!handleNormalKeys(action, consumed))
{
if (consumed)
- keyEvent.consume();
+ event.consume();
return;
}
}
@@ -344,7 +343,7 @@ void TextField::keyPressed(KeyEvent &keyEvent)
distributeActionEvent();
if (consumed)
- keyEvent.consume();
+ event.consume();
fixScroll();
}
@@ -694,13 +693,14 @@ void TextField::fontChanged()
fixScroll();
}
-void TextField::mousePressed(MouseEvent &mouseEvent)
+void TextField::mousePressed(MouseEvent &event)
{
#ifdef ANDROID
if (!client->isKeyboardVisible())
inputManager.executeAction(Input::KEY_SHOW_KEYBOARD);
#endif
- if (mouseEvent.getButton() == MouseEvent::RIGHT)
+ event.consume();
+ if (event.getButton() == MouseEvent::RIGHT)
{
if (viewport)
{
@@ -722,10 +722,10 @@ void TextField::mousePressed(MouseEvent &mouseEvent)
}
}
}
- else if (mouseEvent.getButton() == MouseEvent::LEFT)
+ else if (event.getButton() == MouseEvent::LEFT)
{
mCaretPosition = getFont()->getStringIndexAt(
- mText, mouseEvent.getX() + mXScroll);
+ mText, event.getX() + mXScroll);
fixScroll();
}
}
@@ -750,7 +750,7 @@ void TextField::setText(const std::string& text)
mText = text;
}
-void TextField::mouseDragged(MouseEvent& mouseEvent)
+void TextField::mouseDragged(MouseEvent& event)
{
- mouseEvent.consume();
+ event.consume();
}
diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h
index 93ae155be..1af5978b1 100644
--- a/src/gui/widgets/textfield.h
+++ b/src/gui/widgets/textfield.h
@@ -134,7 +134,7 @@ class TextField : public Widget,
/**
* Processes one keypress.
*/
- void keyPressed(KeyEvent &keyEvent) override;
+ void keyPressed(KeyEvent &event) override;
/**
* Set the minimum value for a range
@@ -162,7 +162,7 @@ class TextField : public Widget,
void setCaretPosition(unsigned int position);
- void mousePressed(MouseEvent &mouseEvent) override final;
+ void mousePressed(MouseEvent &event) override final;
void handlePaste();
@@ -219,7 +219,7 @@ class TextField : public Widget,
unsigned int getCaretPosition() const
{ return mCaretPosition; }
- void mouseDragged(MouseEvent& mouseEvent) override final;
+ void mouseDragged(MouseEvent& event) override final;
protected:
void drawCaret(Graphics* graphics, int x);
diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp
index 10bd936c6..6f358e956 100644
--- a/src/gui/widgets/textpreview.cpp
+++ b/src/gui/widgets/textpreview.cpp
@@ -48,9 +48,9 @@ TextPreview::TextPreview(const Widget2 *const widget,
mShadow(false),
mOutline(false)
{
+ mAllowLogic = false;
if (instances == 0)
{
- Theme *const theme = Theme::instance();
if (theme)
mSkin = theme->load("textpreview.xml", "");
}
@@ -72,7 +72,6 @@ TextPreview::~TextPreview()
if (instances == 0)
{
- Theme *const theme = Theme::instance();
if (theme)
theme->unload(mSkin);
}
@@ -118,7 +117,7 @@ void TextPreview::draw(Graphics* graphics)
Color(mTextColor2->r, mTextColor2->g, mTextColor2->b, alpha));
if (mOutline && mTextColor != mTextColor2)
- graphics->setColor2(Theme::getThemeColor(Theme::OUTLINE));
+ graphics->setColor2(getThemeColor(Theme::OUTLINE, 255));
mFont->drawString(graphics, mText, mPadding + 1, mPadding + 1);
BLOCK_END("TextPreview::draw")
diff --git a/src/gui/widgets/widget.cpp b/src/gui/widgets/widget.cpp
index 5b2024b1f..aa3e6254b 100644
--- a/src/gui/widgets/widget.cpp
+++ b/src/gui/widgets/widget.cpp
@@ -77,8 +77,6 @@
#include "listeners/deathlistener.h"
#include "listeners/widgetlistener.h"
-#include "render/graphics.h"
-
#include "debug.h"
Font* Widget::mGlobalFont = nullptr;
@@ -96,20 +94,20 @@ Widget::Widget(const Widget2 *const widget) :
mForegroundColor(0x000000),
mBackgroundColor(0xffffff),
mBaseColor(0x808090),
- mSelectionColor(0xc3d9ff),
+ mDimension(),
+ mActionEventId(),
+ mId(),
mFocusHandler(nullptr),
mInternalFocusHandler(nullptr),
mParent(nullptr),
- mDimension(),
+ mCurrentFont(nullptr),
mFrameSize(0),
- mActionEventId(),
mFocusable(false),
mVisible(true),
mTabIn(true),
mTabOut(true),
mEnabled(true),
- mId(),
- mCurrentFont(nullptr)
+ mAllowLogic(true)
{
mWidgets.push_back(this);
mWidgetsSet.insert(this);
@@ -117,87 +115,51 @@ Widget::Widget(const Widget2 *const widget) :
Widget::~Widget()
{
- for (DeathListenerIterator iter = mDeathListeners.begin();
- iter != mDeathListeners.end();
- ++iter)
+ FOR_EACH (DeathListenerIterator, iter, mDeathListeners)
{
Event event(this);
(*iter)->death(event);
}
- _setFocusHandler(nullptr);
+ setFocusHandler(nullptr);
mWidgets.remove(this);
mWidgetsSet.erase(this);
}
-void Widget::drawFrame(Graphics* graphics)
-{
- BLOCK_START("Widget::drawFrame")
- const Color &faceColor = getBaseColor();
- Color highlightColor = faceColor + Color(0x303030);
- Color shadowColor = faceColor - Color(0x303030);
- const int alpha = getBaseColor().a;
- const int width = getWidth() + getFrameSize() * 2 - 1;
- const int height = getHeight() + getFrameSize() * 2 - 1;
- highlightColor.a = alpha;
- shadowColor.a = alpha;
-
- for (unsigned int i = 0; i < getFrameSize(); ++i)
- {
- graphics->setColor(shadowColor);
- graphics->drawLine(i, i, width - i, i);
- graphics->drawLine(i, i + 1, i, height - i - 1);
- graphics->setColor(highlightColor);
- graphics->drawLine(width - i, i + 1, width - i, height - i);
- graphics->drawLine(i, height - i, width - i - 1, height - i);
- }
- BLOCK_END("Widget::drawFrame")
-}
-
-void Widget::_setParent(Widget* parent)
-{
- mParent = parent;
-}
-
-void Widget::setWidth(int width)
+void Widget::setWidth(const int width)
{
Rect newDimension = mDimension;
newDimension.width = width;
-
setDimension(newDimension);
}
-void Widget::setHeight(int height)
+void Widget::setHeight(const int height)
{
Rect newDimension = mDimension;
newDimension.height = height;
-
setDimension(newDimension);
}
-void Widget::setX(int x)
+void Widget::setX(const int x)
{
Rect newDimension = mDimension;
newDimension.x = x;
-
setDimension(newDimension);
}
-void Widget::setY(int y)
+void Widget::setY(const int y)
{
Rect newDimension = mDimension;
newDimension.y = y;
-
setDimension(newDimension);
}
-void Widget::setPosition(int x, int y)
+void Widget::setPosition(const int x, const int y)
{
Rect newDimension = mDimension;
newDimension.x = x;
newDimension.y = y;
-
setDimension(newDimension);
}
@@ -212,36 +174,8 @@ void Widget::setDimension(const Rect& dimension)
distributeResizedEvent();
}
- if (mDimension.x != oldDimension.x
- || mDimension.y != oldDimension.y)
- {
+ if (mDimension.x != oldDimension.x || mDimension.y != oldDimension.y)
distributeMovedEvent();
- }
-}
-
-void Widget::setFrameSize(unsigned int frameSize)
-{
- mFrameSize = frameSize;
-}
-
-unsigned int Widget::getFrameSize() const
-{
- return mFrameSize;
-}
-
-const Rect& Widget::getDimension() const
-{
- return mDimension;
-}
-
-const std::string& Widget::getActionEventId() const
-{
- return mActionEventId;
-}
-
-void Widget::setActionEventId(const std::string& actionEventId)
-{
- mActionEventId = actionEventId;
}
bool Widget::isFocused() const
@@ -252,13 +186,10 @@ bool Widget::isFocused() const
return (mFocusHandler->isFocused(this));
}
-void Widget::setFocusable(bool focusable)
+void Widget::setFocusable(const bool focusable)
{
if (!focusable && isFocused())
- {
mFocusHandler->focusNone();
- }
-
mFocusable = focusable;
}
@@ -301,47 +232,7 @@ void Widget::setVisible(bool visible)
mVisible = visible;
}
-void Widget::setBaseColor(const Color& color)
-{
- mBaseColor = color;
-}
-
-const Color& Widget::getBaseColor() const
-{
- return mBaseColor;
-}
-
-void Widget::setForegroundColor(const Color& color)
-{
- mForegroundColor = color;
-}
-
-const Color& Widget::getForegroundColor() const
-{
- return mForegroundColor;
-}
-
-void Widget::setBackgroundColor(const Color& color)
-{
- mBackgroundColor = color;
-}
-
-const Color& Widget::getBackgroundColor() const
-{
- return mBackgroundColor;
-}
-
-void Widget::setSelectionColor(const Color& color)
-{
- mSelectionColor = color;
-}
-
-const Color& Widget::getSelectionColor() const
-{
- return mSelectionColor;
-}
-
-void Widget::_setFocusHandler(FocusHandler* focusHandler)
+void Widget::setFocusHandler(FocusHandler *const focusHandler)
{
if (mFocusHandler)
{
@@ -355,67 +246,62 @@ void Widget::_setFocusHandler(FocusHandler* focusHandler)
mFocusHandler = focusHandler;
}
-FocusHandler* Widget::_getFocusHandler()
-{
- return mFocusHandler;
-}
-
-void Widget::addActionListener(ActionListener* actionListener)
+void Widget::addActionListener(ActionListener *const actionListener)
{
mActionListeners.push_back(actionListener);
}
-void Widget::removeActionListener(ActionListener* actionListener)
+void Widget::removeActionListener(ActionListener *const actionListener)
{
mActionListeners.remove(actionListener);
}
-void Widget::addDeathListener(DeathListener* deathListener)
+void Widget::addDeathListener(DeathListener *const deathListener)
{
mDeathListeners.push_back(deathListener);
}
-void Widget::removeDeathListener(DeathListener* deathListener)
+void Widget::removeDeathListener(DeathListener *const deathListener)
{
mDeathListeners.remove(deathListener);
}
-void Widget::addKeyListener(KeyListener* keyListener)
+void Widget::addKeyListener(KeyListener *const keyListener)
{
mKeyListeners.push_back(keyListener);
}
-void Widget::removeKeyListener(KeyListener* keyListener)
+void Widget::removeKeyListener(KeyListener *const keyListener)
{
mKeyListeners.remove(keyListener);
}
-void Widget::addFocusListener(FocusListener* focusListener)
+void Widget::addFocusListener(FocusListener *const focusListener)
{
mFocusListeners.push_back(focusListener);
}
-void Widget::removeFocusListener(FocusListener* focusListener)
+void Widget::removeFocusListener(FocusListener *const focusListener)
{
mFocusListeners.remove(focusListener);
}
-void Widget::addMouseListener(MouseListener* mouseListener)
+void Widget::addMouseListener(MouseListener *const mouseListener)
{
mMouseListeners.push_back(mouseListener);
}
-void Widget::removeMouseListener(MouseListener* mouseListener)
+void Widget::removeMouseListener(MouseListener *const mouseListener)
{
mMouseListeners.remove(mouseListener);
}
-void Widget::addWidgetListener(WidgetListener* widgetListener)
+void Widget::addWidgetListener(WidgetListener *const widgetListener)
{
mWidgetListeners.push_back(widgetListener);
}
-void Widget::removeWidgetListener(WidgetListener* widgetListener)
+void Widget::removeWidgetListener(WidgetListener *const widgetListener)
{
mWidgetListeners.remove(widgetListener);
}
@@ -446,19 +332,18 @@ Font* Widget::getFont() const
return mCurrentFont;
}
-void Widget::setGlobalFont(Font* font)
+void Widget::setGlobalFont(Font *const font)
{
mGlobalFont = font;
- for (std::list<Widget*>::const_iterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++iter)
+ FOR_EACH (std::list<Widget*>::const_iterator, iter, mWidgets)
{
if (!(*iter)->mCurrentFont)
(*iter)->fontChanged();
}
}
-void Widget::setFont(Font* font)
+void Widget::setFont(Font *const font)
{
mCurrentFont = font;
fontChanged();
@@ -470,40 +355,14 @@ bool Widget::widgetExists(const Widget* widget)
!= mWidgetsSet.end();
}
-bool Widget::isTabInEnabled() const
-{
- return mTabIn;
-}
-
-void Widget::setTabInEnabled(bool enabled)
-{
- mTabIn = enabled;
-}
-
-bool Widget::isTabOutEnabled() const
-{
- return mTabOut;
-}
-
-void Widget::setTabOutEnabled(bool enabled)
-{
- mTabOut = enabled;
-}
-
-void Widget::setSize(int width, int height)
+void Widget::setSize(const int width, const int height)
{
Rect newDimension = mDimension;
newDimension.width = width;
newDimension.height = height;
-
setDimension(newDimension);
}
-void Widget::setEnabled(bool enabled)
-{
- mEnabled = enabled;
-}
-
bool Widget::isEnabled() const
{
return mEnabled && isVisible();
@@ -513,7 +372,6 @@ void Widget::requestModalFocus()
{
if (!mFocusHandler)
return;
-
mFocusHandler->requestModalFocus(this);
}
@@ -521,7 +379,6 @@ void Widget::requestModalMouseInputFocus()
{
if (!mFocusHandler)
return;
-
mFocusHandler->requestModalMouseInputFocus(this);
}
@@ -529,7 +386,6 @@ void Widget::releaseModalFocus()
{
if (!mFocusHandler)
return;
-
mFocusHandler->releaseModalFocus(this);
}
@@ -537,7 +393,6 @@ void Widget::releaseModalMouseInputFocus()
{
if (!mFocusHandler)
return;
-
mFocusHandler->releaseModalMouseInputFocus(this);
}
@@ -569,22 +424,17 @@ bool Widget::isModalMouseInputFocused() const
return mFocusHandler->getModalMouseInputFocused() == this;
}
-Widget *Widget::getWidgetAt(int x A_UNUSED, int y A_UNUSED)
-{
- return nullptr;
-}
-
-const std::list<MouseListener*>& Widget::_getMouseListeners()
+const std::list<MouseListener*>& Widget::getMouseListeners()
{
return mMouseListeners;
}
-const std::list<KeyListener*>& Widget::_getKeyListeners()
+const std::list<KeyListener*>& Widget::getKeyListeners()
{
return mKeyListeners;
}
-const std::list<FocusListener*>& Widget::_getFocusListeners()
+const std::list<FocusListener*>& Widget::getFocusListeners()
{
return mFocusListeners;
}
@@ -594,21 +444,19 @@ Rect Widget::getChildrenArea()
return Rect(0, 0, 0, 0);
}
-FocusHandler* Widget::_getInternalFocusHandler()
+FocusHandler* Widget::getInternalFocusHandler()
{
return mInternalFocusHandler;
}
-void Widget::setInternalFocusHandler(FocusHandler* focusHandler)
+void Widget::setInternalFocusHandler(FocusHandler *const focusHandler)
{
mInternalFocusHandler = focusHandler;
}
void Widget::distributeResizedEvent()
{
- for (WidgetListenerIterator iter = mWidgetListeners.begin();
- iter != mWidgetListeners.end();
- ++ iter)
+ FOR_EACH (WidgetListenerIterator, iter, mWidgetListeners)
{
Event event(this);
(*iter)->widgetResized(event);
@@ -617,9 +465,7 @@ void Widget::distributeResizedEvent()
void Widget::distributeMovedEvent()
{
- for (WidgetListenerIterator iter = mWidgetListeners.begin();
- iter != mWidgetListeners.end();
- ++ iter)
+ FOR_EACH (WidgetListenerIterator, iter, mWidgetListeners)
{
Event event(this);
(*iter)->widgetMoved(event);
@@ -628,9 +474,7 @@ void Widget::distributeMovedEvent()
void Widget::distributeHiddenEvent()
{
- for (WidgetListenerIterator iter = mWidgetListeners.begin();
- iter != mWidgetListeners.end();
- ++ iter)
+ FOR_EACH (WidgetListenerIterator, iter, mWidgetListeners)
{
Event event(this);
(*iter)->widgetHidden(event);
@@ -639,9 +483,7 @@ void Widget::distributeHiddenEvent()
void Widget::distributeActionEvent()
{
- for (ActionListenerIterator iter = mActionListeners.begin();
- iter != mActionListeners.end();
- ++iter)
+ FOR_EACH (ActionListenerIterator, iter, mActionListeners)
{
ActionEvent actionEvent(this, mActionEventId);
(*iter)->action(actionEvent);
@@ -650,16 +492,14 @@ void Widget::distributeActionEvent()
void Widget::distributeShownEvent()
{
- for (WidgetListenerIterator iter = mWidgetListeners.begin();
- iter != mWidgetListeners.end();
- ++iter)
+ FOR_EACH (WidgetListenerIterator, iter, mWidgetListeners)
{
Event event(this);
(*iter)->widgetShown(event);
}
}
-void Widget::showPart(Rect rectangle)
+void Widget::showPart(const Rect &rectangle)
{
if (mParent)
mParent->showWidgetPart(this, rectangle);
diff --git a/src/gui/widgets/widget.h b/src/gui/widgets/widget.h
index 3af00d247..de5a79502 100644
--- a/src/gui/widgets/widget.h
+++ b/src/gui/widgets/widget.h
@@ -99,6 +99,8 @@ class WidgetListener;
class Widget : public Widget2
{
public:
+ friend class BasicContainer;
+
/**
* Constructor. Resets member variables. Noteable, a widget is not
* focusable as default, therefore, widgets that are supposed to be
@@ -145,7 +147,8 @@ class Widget : public Widget2
* @see setFrameSize, getFrameSize
* @since 0.8.0
*/
- virtual void drawFrame(Graphics* graphics);
+ virtual void drawFrame(Graphics* graphics A_UNUSED)
+ { }
/**
* Sets the size of the widget's frame. The frame is not considered a part of
@@ -161,7 +164,8 @@ class Widget : public Widget2
* @see getFrameSize, drawFrame
* @since 0.8.0
*/
- void setFrameSize(unsigned int frameSize);
+ void setFrameSize(const unsigned int frameSize)
+ { mFrameSize = frameSize; }
/**
* Gets the size of the widget's frame. The frame is not considered a part of
@@ -177,7 +181,8 @@ class Widget : public Widget2
* @see setFrameSize, drawFrame
* @since 0.8.0
*/
- unsigned int getFrameSize() const A_WARN_UNUSED;
+ unsigned int getFrameSize() const A_WARN_UNUSED
+ { return mFrameSize; }
/**
* Called for all widgets in the gui each time Gui::logic is called.
@@ -207,7 +212,7 @@ class Widget : public Widget2
* setDimension, getDimensi
* @since 0.1.0
*/
- void setWidth(int width);
+ void setWidth(const int width);
/**
* Gets the width of the widget.
@@ -228,7 +233,7 @@ class Widget : public Widget2
* setDimension, getDimension
* @since 0.1.0
*/
- void setHeight(int height);
+ void setHeight(const int height);
/**
* Gets the height of the widget.
@@ -250,7 +255,7 @@ class Widget : public Widget2
* setDimension, getDimension
* @since 0.1.0
*/
- void setSize(int width, int height);
+ void setSize(const int width, const int height);
/**
* Sets the x coordinate of the widget. The coordinate is
@@ -260,7 +265,7 @@ class Widget : public Widget2
* @see getX, setY, getY, setPosition, setDimension, getDimension
* @since 0.1.0
*/
- void setX(int x);
+ void setX(const int x);
/**
* Gets the x coordinate of the widget. The coordinate is
@@ -281,7 +286,7 @@ class Widget : public Widget2
* @see setY, setX, getX, setPosition, setDimension, getDimension
* @since 0.1.0
*/
- void setY(int y);
+ void setY(const int y);
/**
* Gets the y coordinate of the widget. The coordinate is
@@ -303,7 +308,7 @@ class Widget : public Widget2
* @see setX, getX, setY, getY, setDimension, getDimension
* @since 0.1.0
*/
- void setPosition(int x, int y);
+ void setPosition(const int x, const int y);
/**
* Sets the dimension of the widget. The dimension is
@@ -323,7 +328,8 @@ class Widget : public Widget2
* @see getDimension, setX, getX, setY, getY, setPosition
* @since 0.1.0
*/
- const Rect& getDimension() const A_WARN_UNUSED;
+ const Rect& getDimension() const A_WARN_UNUSED
+ { return mDimension; }
/**
* Sets the widget to be fosusable, or not.
@@ -333,7 +339,7 @@ class Widget : public Widget2
* @see isFocusable
* @since 0.1.0
*/
- void setFocusable(bool focusable);
+ void setFocusable(const bool focusable);
/**
* Checks if a widget is focsable.
@@ -361,7 +367,8 @@ class Widget : public Widget2
* @see isEnabled
* @since 0.1.0
*/
- void setEnabled(bool enabled);
+ void setEnabled(const bool enabled)
+ { mEnabled = enabled; }
/**
* Checks if the widget is enabled. A disabled
@@ -399,7 +406,8 @@ class Widget : public Widget2
* @see getBaseColor
* @since 0.1.0
*/
- void setBaseColor(const Color& color);
+ void setBaseColor(const Color& color)
+ { mBaseColor = color; }
/**
* Gets the base color.
@@ -408,7 +416,8 @@ class Widget : public Widget2
* @see setBaseColor
* @since 0.1.0
*/
- const Color& getBaseColor() const A_WARN_UNUSED;
+ const Color& getBaseColor() const A_WARN_UNUSED
+ { return mBaseColor; }
/**
* Sets the foreground color.
@@ -417,7 +426,8 @@ class Widget : public Widget2
* @see getForegroundColor
* @since 0.1.0
*/
- void setForegroundColor(const Color& color);
+ void setForegroundColor(const Color& color)
+ { mForegroundColor = color; }
/**
* Gets the foreground color.
@@ -425,7 +435,8 @@ class Widget : public Widget2
* @see setForegroundColor
* @since 0.1.0
*/
- const Color& getForegroundColor() const A_WARN_UNUSED;
+ const Color& getForegroundColor() const A_WARN_UNUSED
+ { return mForegroundColor; }
/**
* Sets the background color.
@@ -434,7 +445,8 @@ class Widget : public Widget2
* @see setBackgroundColor
* @since 0.1.0
*/
- void setBackgroundColor(const Color& color);
+ void setBackgroundColor(const Color& color)
+ { mBackgroundColor = color; }
/**
* Gets the background color.
@@ -442,25 +454,8 @@ class Widget : public Widget2
* @see setBackgroundColor
* @since 0.1.0
*/
- const Color& getBackgroundColor() const A_WARN_UNUSED;
-
- /**
- * Sets the selection color.
- *
- * @param color The selection color.
- * @see getSelectionColor
- * @since 0.6.0
- */
- void setSelectionColor(const Color& color);
-
- /**
- * Gets the selection color.
- *
- * @return The selection color.
- * @see setSelectionColor
- * @since 0.6.0
- */
- const Color& getSelectionColor() const A_WARN_UNUSED;
+ const Color& getBackgroundColor() const A_WARN_UNUSED
+ { return mBackgroundColor; }
/**
* Requests focus for the widget. A widget will only recieve focus
@@ -486,10 +481,10 @@ class Widget : public Widget2
* are doing.
*
* @param focusHandler The focus handler to use.
- * @see _getFocusHandler
+ * @see getFocusHandler
* @since 0.1.0
*/
- virtual void _setFocusHandler(FocusHandler* focusHandler);
+ virtual void setFocusHandler(FocusHandler *const focusHandler);
/**
* Gets the focus handler used.
@@ -499,10 +494,11 @@ class Widget : public Widget2
* are doing.
*
* @return The focus handler used.
- * @see _setFocusHandler
+ * @see setFocusHandler
* @since 0.1.0
*/
- virtual FocusHandler* _getFocusHandler() A_WARN_UNUSED;
+ virtual FocusHandler* getFocusHandler() A_WARN_UNUSED
+ { return mFocusHandler; }
/**
* Adds an action listener to the widget. When an action event
@@ -513,7 +509,7 @@ class Widget : public Widget2
* @see removeActionListener
* @since 0.1.0
*/
- void addActionListener(ActionListener* actionListener);
+ void addActionListener(ActionListener *const actionListener);
/**
* Removes an added action listener from the widget.
@@ -522,7 +518,7 @@ class Widget : public Widget2
* @see addActionListener
* @since 0.1.0
*/
- void removeActionListener(ActionListener* actionListener);
+ void removeActionListener(ActionListener *const actionListener);
/**
* Adds a death listener to the widget. When a death event is
@@ -533,7 +529,7 @@ class Widget : public Widget2
* @see removeDeathListener
* @since 0.1.0
*/
- void addDeathListener(DeathListener* deathListener);
+ void addDeathListener(DeathListener *const deathListener);
/**
* Removes an added death listener from the widget.
@@ -542,7 +538,7 @@ class Widget : public Widget2
* @see addDeathListener
* @since 0.1.0
*/
- void removeDeathListener(DeathListener* deathListener);
+ void removeDeathListener(DeathListener *const deathListener);
/**
* Adds a mouse listener to the widget. When a mouse event is
@@ -553,7 +549,7 @@ class Widget : public Widget2
* @see removeMouseListener
* @since 0.1.0
*/
- void addMouseListener(MouseListener* mouseListener);
+ void addMouseListener(MouseListener *const mouseListener);
/**
* Removes an added mouse listener from the widget.
@@ -562,7 +558,7 @@ class Widget : public Widget2
* @see addMouseListener
* @since 0.1.0
*/
- void removeMouseListener(MouseListener* mouseListener);
+ void removeMouseListener(MouseListener *const mouseListener);
/**
* Adds a key listener to the widget. When a key event is
@@ -573,7 +569,7 @@ class Widget : public Widget2
* @see removeKeyListener
* @since 0.1.0
*/
- void addKeyListener(KeyListener* keyListener);
+ void addKeyListener(KeyListener *const keyListener);
/**
* Removes an added key listener from the widget.
@@ -582,7 +578,7 @@ class Widget : public Widget2
* @see addKeyListener
* @since 0.1.0
*/
- void removeKeyListener(KeyListener* keyListener);
+ void removeKeyListener(KeyListener *const keyListener);
/**
* Adds a focus listener to the widget. When a focus event is
@@ -593,7 +589,7 @@ class Widget : public Widget2
* @see removeFocusListener
* @since 0.7.0
*/
- void addFocusListener(FocusListener* focusListener);
+ void addFocusListener(FocusListener *const focusListener);
/**
* Removes an added focus listener from the widget.
@@ -602,7 +598,7 @@ class Widget : public Widget2
* @see addFocusListener
* @since 0.7.0
*/
- void removeFocusListener(FocusListener* focusListener);
+ void removeFocusListener(FocusListener *const focusListener);
/**
* Adds a widget listener to the widget. When a widget event is
@@ -613,7 +609,7 @@ class Widget : public Widget2
* @see removeWidgetListener
* @since 0.8.0
*/
- void addWidgetListener(WidgetListener* widgetListener);
+ void addWidgetListener(WidgetListener *const widgetListener);
/**
* Removes an added widget listener from the widget.
@@ -622,7 +618,7 @@ class Widget : public Widget2
* @see addWidgetListener
* @since 0.8.0
*/
- void removeWidgetListener(WidgetListener* widgetListener);
+ void removeWidgetListener(WidgetListener *const widgetListener);
/**
* Sets the action event identifier of the widget. The identifier is
@@ -636,7 +632,8 @@ class Widget : public Widget2
* @see getActionEventId
* @since 0.6.0
*/
- void setActionEventId(const std::string& actionEventId);
+ void setActionEventId(const std::string& actionEventId)
+ { mActionEventId = actionEventId; }
/**
* Gets the action event identifier of the widget.
@@ -645,7 +642,8 @@ class Widget : public Widget2
* @see setActionEventId
* @since 0.6.0
*/
- const std::string& getActionEventId() const;
+ const std::string& getActionEventId() const
+ { return mActionEventId; }
/**
* Gets the absolute position on the screen for the widget.
@@ -667,7 +665,8 @@ class Widget : public Widget2
* @see getParent
* @since 0.1.0
*/
- virtual void _setParent(Widget* parent);
+ virtual void setParent(Widget* parent)
+ { mParent = parent; }
/**
* Gets the font set for the widget. If no font has been set,
@@ -687,7 +686,7 @@ class Widget : public Widget2
* @see getGlobalFont
* @since 0.1.0
*/
- static void setGlobalFont(Font* font);
+ static void setGlobalFont(Font *const font);
/**
* Sets the font for the widget. If NULL is passed, the global font
@@ -697,7 +696,7 @@ class Widget : public Widget2
* @see getFont
* @since 0.1.0
*/
- void setFont(Font* font);
+ void setFont(Font *const font);
/**
* Called when the font has changed. If the change is global,
@@ -729,7 +728,8 @@ class Widget : public Widget2
* @see setTabInEnabled
* @since 0.1.0
*/
- bool isTabInEnabled() const A_WARN_UNUSED;
+ bool isTabInEnabled() const A_WARN_UNUSED
+ { return mTabIn; }
/**
* Sets tab in enabled, or not. Tab in means that you can set focus
@@ -741,7 +741,8 @@ class Widget : public Widget2
* @see isTabInEnabled
* @since 0.1.0
*/
- void setTabInEnabled(bool enabled);
+ void setTabInEnabled(const bool enabled)
+ { mTabIn = enabled; }
/**
* Checks if tab out is enabled. Tab out means that you can lose
@@ -753,7 +754,8 @@ class Widget : public Widget2
* @see setTabOutEnabled
* @since 0.1.0
*/
- bool isTabOutEnabled() const A_WARN_UNUSED;
+ bool isTabOutEnabled() const A_WARN_UNUSED
+ { return mTabOut; }
/**
* Sets tab out enabled. Tab out means that you can lose
@@ -765,7 +767,8 @@ class Widget : public Widget2
* @see isTabOutEnabled
* @since 0.1.0
*/
- void setTabOutEnabled(bool enabled);
+ void setTabOutEnabled(const bool enabled)
+ { mTabOut = enabled; }
/**
* Requests modal focus. When a widget has modal focus, only that
@@ -839,7 +842,9 @@ class Widget : public Widget2
* if no widget is found.
* @since 0.6.0
*/
- virtual Widget *getWidgetAt(int x, int y) A_WARN_UNUSED;
+ virtual Widget *getWidgetAt(int x A_UNUSED,
+ int y A_UNUSED) A_WARN_UNUSED
+ { return nullptr; }
/**
* Gets the mouse listeners of the widget.
@@ -847,8 +852,8 @@ class Widget : public Widget2
* @return The mouse listeners of the widget.
* @since 0.6.0
*/
- virtual const std::list<MouseListener*>& _getMouseListeners()
- A_WARN_UNUSED;
+ virtual const std::list<MouseListener*>& getMouseListeners()
+ A_WARN_UNUSED;
/**
* Gets the key listeners of the widget.
@@ -856,8 +861,8 @@ class Widget : public Widget2
* @return The key listeners of the widget.
* @since 0.6.0
*/
- virtual const std::list<KeyListener*>& _getKeyListeners()
- A_WARN_UNUSED;
+ virtual const std::list<KeyListener*>& getKeyListeners()
+ A_WARN_UNUSED;
/**
* Gets the focus listeners of the widget.
@@ -865,8 +870,8 @@ class Widget : public Widget2
* @return The focus listeners of the widget.
* @since 0.7.0
*/
- virtual const std::list<FocusListener*>& _getFocusListeners()
- A_WARN_UNUSED;
+ virtual const std::list<FocusListener*>& getFocusListeners()
+ A_WARN_UNUSED;
/**
* Gets the area of the widget occupied by the widget's children.
@@ -898,7 +903,7 @@ class Widget : public Widget2
* @see setInternalFocusHandler
* @since 0.1.0
*/
- virtual FocusHandler* _getInternalFocusHandler() A_WARN_UNUSED;
+ virtual FocusHandler* getInternalFocusHandler() A_WARN_UNUSED;
/**
* Sets the internal focus handler. An internal focus handler is
@@ -909,7 +914,7 @@ class Widget : public Widget2
* @see getInternalFocusHandler
* @since 0.1.0
*/
- void setInternalFocusHandler(FocusHandler* internalFocusHandler);
+ void setInternalFocusHandler(FocusHandler *const internalFocusHandler);
/**
* Moves a widget to the top of this widget. The moved widget will be
@@ -970,7 +975,7 @@ class Widget : public Widget2
* has an id.
*
* @param id The id to set to the widget.
- * @see getId, BasicContainer::findWidgetById
+ * @see getId
* @since 0.8.0
*/
void setId(const std::string& id)
@@ -983,7 +988,7 @@ class Widget : public Widget2
* has an id.
*
* @param id The id to set to the widget.
- * @see setId, BasicContainer::findWidgetById
+ * @see setId
* @since 0.8.0
*/
const std::string& getId() const A_WARN_UNUSED
@@ -999,7 +1004,10 @@ class Widget : public Widget2
* @param rectangle The rectangle to be shown.
* @since 0.8.0
*/
- virtual void showPart(Rect rectangle);
+ virtual void showPart(const Rect &rectangle);
+
+ bool isAllowLogic() const
+ { return mAllowLogic; }
protected:
/**
@@ -1143,9 +1151,19 @@ class Widget : public Widget2
Color mBaseColor;
/**
- * Holds the selection color of the widget.
+ * Holds the dimension of the widget.
*/
- Color mSelectionColor;
+ Rect mDimension;
+
+ /**
+ * Holds the action event of the widget.
+ */
+ std::string mActionEventId;
+
+ /**
+ * Holds the id of the widget.
+ */
+ std::string mId;
/**
* Holds the focus handler used by the widget.
@@ -1165,9 +1183,9 @@ class Widget : public Widget2
Widget* mParent;
/**
- * Holds the dimension of the widget.
+ * Holds the font used by the widget.
*/
- Rect mDimension;
+ Font* mCurrentFont;
/**
* Holds the frame size of the widget.
@@ -1175,11 +1193,6 @@ class Widget : public Widget2
unsigned int mFrameSize;
/**
- * Holds the action event of the widget.
- */
- std::string mActionEventId;
-
- /**
* True if the widget focusable, false otherwise.
*/
bool mFocusable;
@@ -1204,15 +1217,7 @@ class Widget : public Widget2
*/
bool mEnabled;
- /**
- * Holds the id of the widget.
- */
- std::string mId;
-
- /**
- * Holds the font used by the widget.
- */
- Font* mCurrentFont;
+ bool mAllowLogic;
/**
* Holds the global font used by the widget.
diff --git a/src/gui/widgets/widget2.h b/src/gui/widgets/widget2.h
index ff565815f..7890fd648 100644
--- a/src/gui/widgets/widget2.h
+++ b/src/gui/widgets/widget2.h
@@ -36,16 +36,18 @@ class Widget2
const int alpha = 255)
const A_WARN_UNUSED
{
- return Theme::getThemeColor(mPaletteOffset + type, alpha);
+ return theme->getColor(mPaletteOffset + type, alpha);
}
inline const Color &getThemeCharColor(const signed char c,
bool &valid)
const A_WARN_UNUSED
{
- const int colorId = Theme::getThemeIdByChar(c, valid);
+ if (!theme)
+ return Palette::BLACK;
+ const int colorId = theme->getIdByChar(c, valid);
if (valid)
- return Theme::getThemeColor(mPaletteOffset + colorId);
+ return theme->getColor(mPaletteOffset + colorId, 255);
else
return Palette::BLACK;
}
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 5a636013b..9e032f75b 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -82,6 +82,8 @@
#include "resources/cursor.h"
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
const int resizeMask = 8 + 4 + 2 + 1;
@@ -155,7 +157,6 @@ Window::Window(const std::string &caption, const bool modal,
int childPalette = 1;
// Loads the skin
- Theme *const theme = Theme::instance();
if (theme)
{
mSkin = theme->load(skin, "window.xml");
@@ -220,8 +221,7 @@ Window::~Window()
saveWindowState();
- delete mLayout;
- mLayout = nullptr;
+ delete2(mLayout);
while (!mWidgets.empty())
delete mWidgets.front();
@@ -229,14 +229,12 @@ Window::~Window()
mWidgets.clear();
removeWidgetListener(this);
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
windowInstances--;
if (mSkin)
{
- Theme *const theme = Theme::instance();
if (theme)
theme->unload(mSkin);
mSkin = nullptr;
@@ -643,6 +641,7 @@ void Window::setStickyButton(const bool flag)
void Window::setSticky(const bool sticky)
{
mSticky = sticky;
+ mRedraw = true;
}
void Window::setStickyButtonLock(const bool lock)
@@ -706,6 +705,9 @@ void Window::scheduleDelete()
void Window::mousePressed(MouseEvent &event)
{
+ if (event.isConsumed())
+ return;
+
if (event.getSource() == this)
{
if (getParent())
@@ -716,7 +718,8 @@ void Window::mousePressed(MouseEvent &event)
mMoved = event.getY() <= static_cast<int>(mTitleBarHeight);
}
- if (event.getButton() == MouseEvent::LEFT)
+ const unsigned int button = event.getButton();
+ if (button == MouseEvent::LEFT)
{
const int x = event.getX();
const int y = event.getY();
@@ -726,6 +729,7 @@ void Window::mousePressed(MouseEvent &event)
{
mouseResize = 0;
mMoved = 0;
+ event.consume();
close();
return;
}
@@ -736,17 +740,27 @@ void Window::mousePressed(MouseEvent &event)
setSticky(!isSticky());
mouseResize = 0;
mMoved = 0;
- mRedraw = true;
+ event.consume();
return;
}
// Handle window resizing
mouseResize = getResizeHandles(event) & resizeMask;
+ if (mouseResize != 0)
+ event.consume();
if (canMove())
mMoved = !mouseResize;
else
mMoved = false;
}
+ else if (button == MouseEvent::RIGHT)
+ {
+ if (viewport)
+ {
+ event.consume();
+ viewport->showWindowPopup(this);
+ }
+ }
}
void Window::close()
@@ -1207,7 +1221,7 @@ bool Window::isResizeAllowed(const MouseEvent &event) const
int Window::getGuiAlpha() const
{
const float alpha = std::max(client->getGuiAlpha(),
- Theme::instance()->getMinimumOpacity());
+ theme->getMinimumOpacity());
return static_cast<int>(alpha * 255.0F);
}
@@ -1248,8 +1262,7 @@ void Window::reflowLayout(int w, int h)
return;
mLayout->reflow(w, h);
- delete mLayout;
- mLayout = nullptr;
+ delete2(mLayout);
setContentSize(w, h);
}
diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h
index 2c4ee5e5f..dfd1f63b7 100644
--- a/src/gui/widgets/window.h
+++ b/src/gui/widgets/window.h
@@ -170,6 +170,9 @@ class Window : public BasicContainer2,
*/
void setCloseButton(const bool flag);
+ bool getCloseButton() const A_WARN_UNUSED
+ { return mCloseWindowButton; }
+
/**
* Returns whether the window can be resized.
*/
diff --git a/src/gui/widgets/windowcontainer.cpp b/src/gui/widgets/windowcontainer.cpp
index a9b556410..20c3328a7 100644
--- a/src/gui/widgets/windowcontainer.cpp
+++ b/src/gui/widgets/windowcontainer.cpp
@@ -64,18 +64,34 @@ void WindowContainer::moveWidgetAfter(Widget *const after,
const WidgetListIterator widgetIter = std::find(
mWidgets.begin(), mWidgets.end(), widget);
- if (widgetIter == mWidgets.end())
- return;
+ if (widgetIter != mWidgets.end())
+ {
+ WidgetListIterator afterIter = std::find(
+ mWidgets.begin(), mWidgets.end(), after);
- WidgetListIterator afterIter = std::find(
- mWidgets.begin(), mWidgets.end(), after);
+ if (afterIter != mWidgets.end())
+ {
+ ++ afterIter;
+ mWidgets.erase(widgetIter);
+ mWidgets.insert(afterIter, widget);
+ }
+ }
- if (afterIter == mWidgets.end())
- return;
+ const WidgetListIterator widgetIter2 = std::find(
+ mLogicWidgets.begin(), mLogicWidgets.end(), widget);
- ++ afterIter;
- mWidgets.erase(widgetIter);
- mWidgets.insert(afterIter, widget);
+ if (widgetIter2 != mLogicWidgets.end())
+ {
+ WidgetListIterator afterIter = std::find(
+ mLogicWidgets.begin(), mLogicWidgets.end(), after);
+
+ if (afterIter != mLogicWidgets.end())
+ {
+ ++ afterIter;
+ mLogicWidgets.erase(widgetIter2);
+ mLogicWidgets.insert(afterIter, widget);
+ }
+ }
}
#ifdef USE_PROFILER
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index 795f2ad5a..910bba705 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -34,6 +34,7 @@
#include "gui/widgets/button.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -46,8 +47,7 @@ WindowMenu::WindowMenu(const Widget2 *const widget) :
ActionListener(),
SelectionListener(),
MouseListener(),
- mSkin(Theme::instance() ? Theme::instance()->load("windowmenu.xml", "")
- : nullptr),
+ mSkin(theme ? theme->load("windowmenu.xml", "") : nullptr),
mPadding(mSkin ? mSkin->getPadding() : 1),
mSpacing(mSkin ? mSkin->getOption("spacing", 3) : 3),
mTextPopup(new TextPopup),
@@ -172,8 +172,7 @@ WindowMenu::~WindowMenu()
config.removeListener("autohideButtons", this);
CHECKLISTENERS
- delete mTextPopup;
- mTextPopup = nullptr;
+ delete2(mTextPopup);
for (std::map <std::string, ButtonInfo*>::iterator
it = mButtonNames.begin(),
it_end = mButtonNames.end(); it != it_end; ++it)
@@ -181,22 +180,18 @@ WindowMenu::~WindowMenu()
delete (*it).second;
}
mButtonNames.clear();
- for (std::vector <Button*>::iterator it = mButtons.begin(),
- it_end = mButtons.end(); it != it_end; ++it)
+ FOR_EACH (std::vector <Button*>::iterator, it, mButtons)
{
Button *const btn = dynamic_cast<Button*>(*it);
if (!btn)
continue;
if (!btn->isVisible())
- {
delete btn;
- }
}
delete_all(mButtonTexts);
mButtonTexts.clear();
if (mSkin)
{
- Theme *const theme = Theme::instance();
if (theme)
theme->unload(mSkin);
mSkin = nullptr;
@@ -206,7 +201,6 @@ WindowMenu::~WindowMenu()
void WindowMenu::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
-
const std::map <std::string, ButtonInfo*>::iterator
it = mButtonNames.find(eventId);
if (it == mButtonNames.end())
@@ -221,7 +215,9 @@ void WindowMenu::action(const ActionEvent &event)
void WindowMenu::addButton(const char *const text,
const std::string &description,
- int &restrict x, int &restrict h, const int key,
+ int &restrict x,
+ int &restrict h,
+ const int key,
const bool visible)
{
Button *const btn = new Button(this, gettext(text), text, this);
@@ -243,8 +239,12 @@ void WindowMenu::mousePressed(MouseEvent &event)
if (!viewport)
return;
- if (!mSmallWindow && event.getButton() == MouseEvent::RIGHT)
+ if (event.getButton() == MouseEvent::RIGHT)
{
+ if (mSmallWindow)
+ return;
+
+ event.consume();
Button *const btn = dynamic_cast<Button*>(event.getSource());
if (!btn)
return;
@@ -295,7 +295,7 @@ void WindowMenu::mouseMoved(MouseEvent &event)
}
}
-void WindowMenu::mouseExited(MouseEvent& mouseEvent A_UNUSED)
+void WindowMenu::mouseExited(MouseEvent& event A_UNUSED)
{
mHaveMouse = false;
if (!mTextPopup)
@@ -393,9 +393,7 @@ void WindowMenu::loadButtons()
void WindowMenu::saveButtons() const
{
int i = 0;
- for (std::vector <Button*>::const_iterator it = mButtons.begin(),
- it_end = mButtons.end();
- it != it_end; ++it)
+ FOR_EACH (std::vector <Button*>::const_iterator, it, mButtons)
{
const Button *const btn = dynamic_cast<const Button *const>(*it);
if (btn && !btn->isVisible())
diff --git a/src/gui/windowmenu.h b/src/gui/windowmenu.h
index a1ed66a7d..9eb520bff 100644
--- a/src/gui/windowmenu.h
+++ b/src/gui/windowmenu.h
@@ -94,7 +94,7 @@ class WindowMenu final : public Container,
void mouseMoved(MouseEvent &event) override final;
- void mouseExited(MouseEvent& mouseEvent A_UNUSED) override final;
+ void mouseExited(MouseEvent& event A_UNUSED) override final;
std::map <std::string, ButtonInfo*> &getButtonNames() A_WARN_UNUSED
{ return mButtonNames; }
diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp
index 86e819121..8bece77ef 100644
--- a/src/gui/windows/buydialog.cpp
+++ b/src/gui/windows/buydialog.cpp
@@ -47,6 +47,7 @@
#include "resources/iteminfo.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include <algorithm>
@@ -302,9 +303,7 @@ void BuyDialog::init()
BuyDialog::~BuyDialog()
{
- delete mShopItems;
- mShopItems = nullptr;
-
+ delete2(mShopItems);
instances.remove(this);
}
diff --git a/src/gui/windows/changeemaildialog.cpp b/src/gui/windows/changeemaildialog.cpp
index b8f9c1fd2..ce9ec84e8 100644
--- a/src/gui/windows/changeemaildialog.cpp
+++ b/src/gui/windows/changeemaildialog.cpp
@@ -35,6 +35,7 @@
#include "net/loginhandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include <string>
@@ -105,8 +106,7 @@ ChangeEmailDialog::ChangeEmailDialog(LoginData *const data):
ChangeEmailDialog::~ChangeEmailDialog()
{
- delete mWrongDataNoticeListener;
- mWrongDataNoticeListener = nullptr;
+ delete2(mWrongDataNoticeListener);
}
void ChangeEmailDialog::action(const ActionEvent &event)
diff --git a/src/gui/windows/changepassworddialog.cpp b/src/gui/windows/changepassworddialog.cpp
index 05c7a9309..051fa6434 100644
--- a/src/gui/windows/changepassworddialog.cpp
+++ b/src/gui/windows/changepassworddialog.cpp
@@ -36,6 +36,7 @@
#include "net/loginhandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include <string>
@@ -84,8 +85,7 @@ ChangePasswordDialog::ChangePasswordDialog(LoginData *const data):
ChangePasswordDialog::~ChangePasswordDialog()
{
- delete mWrongDataNoticeListener;
- mWrongDataNoticeListener = nullptr;
+ delete2(mWrongDataNoticeListener);
}
void ChangePasswordDialog::action(const ActionEvent &event)
diff --git a/src/gui/windows/charcreatedialog.cpp b/src/gui/windows/charcreatedialog.cpp
index 1df282189..42bbb4b88 100644
--- a/src/gui/windows/charcreatedialog.cpp
+++ b/src/gui/windows/charcreatedialog.cpp
@@ -313,8 +313,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent,
CharCreateDialog::~CharCreateDialog()
{
- delete mPlayer;
- mPlayer = nullptr;
+ delete2(mPlayer);
if (Net::getCharServerHandler())
Net::getCharServerHandler()->setCharCreateDialog(nullptr);
@@ -491,14 +490,11 @@ void CharCreateDialog::setAttributes(const StringVect &labels,
for (unsigned i = 0; i < mAttributeLabel.size(); i++)
{
remove(mAttributeLabel[i]);
- delete mAttributeLabel[i];
- mAttributeLabel[i] = nullptr;
+ delete2(mAttributeLabel[i])
remove(mAttributeSlider[i]);
- delete mAttributeSlider[i];
- mAttributeSlider[i] = nullptr;
+ delete2(mAttributeSlider[i])
remove(mAttributeValue[i]);
- delete mAttributeValue[i];
- mAttributeValue[i] = nullptr;
+ delete2(mAttributeValue[i])
}
mAttributeLabel.resize(labels.size());
@@ -655,13 +651,13 @@ void CharCreateDialog::updatePlayer()
}
}
-void CharCreateDialog::keyPressed(KeyEvent &keyEvent)
+void CharCreateDialog::keyPressed(KeyEvent &event)
{
- const int actionId = keyEvent.getActionId();
+ const int actionId = event.getActionId();
switch (actionId)
{
case Input::KEY_GUI_CANCEL:
- keyEvent.consume();
+ event.consume();
action(ActionEvent(mCancelButton,
mCancelButton->getActionEventId()));
break;
diff --git a/src/gui/windows/charcreatedialog.h b/src/gui/windows/charcreatedialog.h
index 6342450ec..652254776 100644
--- a/src/gui/windows/charcreatedialog.h
+++ b/src/gui/windows/charcreatedialog.h
@@ -78,7 +78,7 @@ class CharCreateDialog final : public Window,
void updatePlayer();
- void keyPressed(KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &event) override final;
private:
int getDistributedPoints() const A_WARN_UNUSED;
diff --git a/src/gui/windows/charselectdialog.cpp b/src/gui/windows/charselectdialog.cpp
index 4480f06af..887937232 100644
--- a/src/gui/windows/charselectdialog.cpp
+++ b/src/gui/windows/charselectdialog.cpp
@@ -317,20 +317,20 @@ void CharSelectDialog::use(const int selected)
}
}
-void CharSelectDialog::keyPressed(KeyEvent &keyEvent)
+void CharSelectDialog::keyPressed(KeyEvent &event)
{
- const int actionId = keyEvent.getActionId();
+ const int actionId = event.getActionId();
switch (actionId)
{
case Input::KEY_GUI_CANCEL:
- keyEvent.consume();
+ event.consume();
action(ActionEvent(mSwitchLoginButton,
mSwitchLoginButton->getActionEventId()));
break;
case Input::KEY_GUI_RIGHT:
{
- keyEvent.consume();
+ event.consume();
int idx = mCharacterView->getSelected();
if (idx >= 0)
{
@@ -345,7 +345,7 @@ void CharSelectDialog::keyPressed(KeyEvent &keyEvent)
case Input::KEY_GUI_LEFT:
{
- keyEvent.consume();
+ event.consume();
int idx = mCharacterView->getSelected();
if (idx >= 0)
{
@@ -360,7 +360,7 @@ void CharSelectDialog::keyPressed(KeyEvent &keyEvent)
case Input::KEY_GUI_UP:
{
- keyEvent.consume();
+ event.consume();
int idx = mCharacterView->getSelected();
if (idx >= 0)
{
@@ -375,7 +375,7 @@ void CharSelectDialog::keyPressed(KeyEvent &keyEvent)
case Input::KEY_GUI_DOWN:
{
- keyEvent.consume();
+ event.consume();
int idx = mCharacterView->getSelected();
if (idx >= 0)
{
@@ -390,7 +390,7 @@ void CharSelectDialog::keyPressed(KeyEvent &keyEvent)
case Input::KEY_GUI_DELETE:
{
- keyEvent.consume();
+ event.consume();
const int idx = mCharacterView->getSelected();
if (idx >= 0 && mCharacterEntries[idx]
&& mCharacterEntries[idx]->getCharacter())
@@ -402,7 +402,7 @@ void CharSelectDialog::keyPressed(KeyEvent &keyEvent)
case Input::KEY_GUI_SELECT:
{
- keyEvent.consume();
+ event.consume();
use(mCharacterView->getSelected());
break;
}
diff --git a/src/gui/windows/charselectdialog.h b/src/gui/windows/charselectdialog.h
index 38c307f30..cf44f30b9 100644
--- a/src/gui/windows/charselectdialog.h
+++ b/src/gui/windows/charselectdialog.h
@@ -62,7 +62,7 @@ class CharSelectDialog final : public Window,
void action(const ActionEvent &event) override final;
- void keyPressed(KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &event) override final;
enum SelectAction
{
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp
index 5698973f3..8d1d3e046 100644
--- a/src/gui/windows/chatwindow.cpp
+++ b/src/gui/windows/chatwindow.cpp
@@ -67,6 +67,7 @@
#include "net/net.h"
#include "utils/copynpaste.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "resources/resourcemanager.h"
@@ -266,12 +267,9 @@ ChatWindow::~ChatWindow()
saveState();
config.setValue("ReturnToggles", mReturnToggles);
removeAllWhispers();
- delete mItemLinkHandler;
- mItemLinkHandler = nullptr;
- delete mColorPicker;
- mColorPicker = nullptr;
- delete mColorListModel;
- mColorListModel = nullptr;
+ delete2(mItemLinkHandler);
+ delete2(mColorPicker);
+ delete2(mColorListModel);
}
void ChatWindow::postInit()
@@ -646,8 +644,7 @@ void ChatWindow::ignoreAllWhispers()
PlayerRelation::IGNORED);
}
- delete (iter->second);
- iter->second = nullptr;
+ delete2(iter->second)
}
}
@@ -732,6 +729,7 @@ void ChatWindow::mousePressed(MouseEvent &event)
Tab *const tab = mChatTabs->getSelectedTab();
if (tab)
{
+ event.consume();
if (inputManager.isActionActive(static_cast<int>(
Input::KEY_CHAT_MOD)))
{
@@ -1857,16 +1855,16 @@ void ChatWindow::mouseMoved(MouseEvent &event)
Window::mouseMoved(event);
}
-void ChatWindow::mouseEntered(MouseEvent& mouseEvent)
+void ChatWindow::mouseEntered(MouseEvent& event)
{
mHaveMouse = true;
- Window::mouseEntered(mouseEvent);
+ Window::mouseEntered(event);
}
-void ChatWindow::mouseExited(MouseEvent& mouseEvent)
+void ChatWindow::mouseExited(MouseEvent& event)
{
updateVisibility();
- Window::mouseExited(mouseEvent);
+ Window::mouseExited(event);
}
void ChatWindow::draw(Graphics* graphics)
diff --git a/src/gui/windows/chatwindow.h b/src/gui/windows/chatwindow.h
index bd5374c56..e755e43f2 100644
--- a/src/gui/windows/chatwindow.h
+++ b/src/gui/windows/chatwindow.h
@@ -274,11 +274,11 @@ class ChatWindow final : public Window,
void optionChanged(const std::string &name) override final;
- void mouseEntered(MouseEvent& mouseEvent) override final;
+ void mouseEntered(MouseEvent& event) override final;
void mouseMoved(MouseEvent &event) override final;
- void mouseExited(MouseEvent& mouseEvent A_UNUSED) override final;
+ void mouseExited(MouseEvent& event A_UNUSED) override final;
void draw(Graphics* graphics) override final;
diff --git a/src/gui/windows/debugwindow.cpp b/src/gui/windows/debugwindow.cpp
index 50dc5dbe5..438103f0a 100644
--- a/src/gui/windows/debugwindow.cpp
+++ b/src/gui/windows/debugwindow.cpp
@@ -42,6 +42,7 @@
#include "net/packetcounters.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
#include "utils/timer.h"
@@ -88,12 +89,9 @@ DebugWindow::DebugWindow() :
DebugWindow::~DebugWindow()
{
- delete mMapWidget;
- mMapWidget = nullptr;
- delete mTargetWidget;
- mTargetWidget = nullptr;
- delete mNetWidget;
- mNetWidget = nullptr;
+ delete2(mMapWidget);
+ delete2(mTargetWidget);
+ delete2(mNetWidget);
}
void DebugWindow::postInit()
diff --git a/src/gui/windows/editserverdialog.cpp b/src/gui/windows/editserverdialog.cpp
index 316a7051b..6a25a2d77 100644
--- a/src/gui/windows/editserverdialog.cpp
+++ b/src/gui/windows/editserverdialog.cpp
@@ -242,12 +242,12 @@ void EditServerDialog::action(const ActionEvent &event)
}
}
-void EditServerDialog::keyPressed(KeyEvent &keyEvent)
+void EditServerDialog::keyPressed(KeyEvent &event)
{
- if (keyEvent.isConsumed())
+ if (event.isConsumed())
return;
- const int actionId = keyEvent.getActionId();
+ const int actionId = event.getActionId();
if (actionId == static_cast<int>(Input::KEY_GUI_CANCEL))
{
diff --git a/src/gui/windows/editserverdialog.h b/src/gui/windows/editserverdialog.h
index b70d1031b..98f5e07fd 100644
--- a/src/gui/windows/editserverdialog.h
+++ b/src/gui/windows/editserverdialog.h
@@ -59,7 +59,7 @@ class EditServerDialog final : public Window,
*/
void action(const ActionEvent &event) override final;
- void keyPressed(KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &event) override final;
private:
TextField *mServerAddressField;
diff --git a/src/gui/windows/emotewindow.cpp b/src/gui/windows/emotewindow.cpp
index 3a7141533..0f286b145 100644
--- a/src/gui/windows/emotewindow.cpp
+++ b/src/gui/windows/emotewindow.cpp
@@ -28,6 +28,7 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/tabbedarea.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "resources/image.h"
@@ -121,20 +122,13 @@ EmoteWindow::~EmoteWindow()
{
mTabs->removeAll(false);
mTabs->removeTab(mTabs->getTabByIndex(0));
- delete mEmotePage;
- mEmotePage = nullptr;
- delete mColorPage;
- mColorPage = nullptr;
- delete mColorModel;
- mColorModel = nullptr;
- delete mScrollColorPage;
- mScrollColorPage = nullptr;
- delete mFontPage;
- mFontPage = nullptr;
- delete mFontModel;
- mFontModel = nullptr;
- delete mScrollFontPage;
- mScrollFontPage = nullptr;
+ delete2(mEmotePage);
+ delete2(mColorPage);
+ delete2(mColorModel);
+ delete2(mScrollColorPage);
+ delete2(mFontPage);
+ delete2(mFontModel);
+ delete2(mScrollFontPage);
if (mImageSet)
{
mImageSet->decRef();
diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp
index c45595dff..4c026281b 100644
--- a/src/gui/windows/equipmentwindow.cpp
+++ b/src/gui/windows/equipmentwindow.cpp
@@ -44,6 +44,7 @@
#include "resources/imageset.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -122,7 +123,7 @@ void EquipmentWindow::postInit()
mUnequip->setEnabled(false);
ImageRect rect;
- Theme::instance()->loadRect(rect, "equipment_background.xml", "", 0, 1);
+ theme->loadRect(rect, "equipment_background.xml", "", 0, 1);
mSlotBackground = rect.grid[0];
mSlotHighlightedBackground = rect.grid[1];
add(mPlayerBox);
@@ -132,14 +133,12 @@ void EquipmentWindow::postInit()
EquipmentWindow::~EquipmentWindow()
{
- delete mItemPopup;
- mItemPopup = nullptr;
+ delete2(mItemPopup);
if (this == beingEquipmentWindow)
{
if (mEquipment)
delete mEquipment->getBackend();
- delete mEquipment;
- mEquipment = nullptr;
+ delete2(mEquipment)
}
delete_all(mBoxes);
mBoxes.clear();
@@ -152,8 +151,7 @@ EquipmentWindow::~EquipmentWindow()
mSlotBackground->decRef();
if (mSlotHighlightedBackground)
mSlotHighlightedBackground->decRef();
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
}
void EquipmentWindow::draw(Graphics *graphics)
@@ -295,22 +293,22 @@ Item *EquipmentWindow::getItem(const int x, const int y) const
return nullptr;
}
-void EquipmentWindow::mousePressed(MouseEvent& mouseEvent)
+void EquipmentWindow::mousePressed(MouseEvent& event)
{
if (!mEquipment)
{
- Window::mousePressed(mouseEvent);
+ Window::mousePressed(event);
return;
}
- const int x = mouseEvent.getX();
- const int y = mouseEvent.getY();
+ const int x = event.getX();
+ const int y = event.getY();
- if (mouseEvent.getButton() == MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
if (mForing)
{
- Window::mousePressed(mouseEvent);
+ Window::mousePressed(event);
return;
}
// Checks if any of the presses were in the equip boxes.
@@ -332,6 +330,7 @@ void EquipmentWindow::mousePressed(MouseEvent& mouseEvent)
inBox = true;
if (item)
{
+ event.consume();
setSelected(i);
dragDrop.dragItem(item, DRAGDROP_SOURCE_EQUIPMENT);
return;
@@ -341,7 +340,7 @@ void EquipmentWindow::mousePressed(MouseEvent& mouseEvent)
return;
}
}
- else if (mouseEvent.getButton() == MouseEvent::RIGHT)
+ else if (event.getButton() == MouseEvent::RIGHT)
{
if (Item *const item = getItem(x, y))
{
@@ -355,6 +354,7 @@ void EquipmentWindow::mousePressed(MouseEvent& mouseEvent)
const int my = y + getY();
if (viewport)
{
+ event.consume();
if (mForing)
viewport->showUndressPopup(mx, my, mBeing, item);
else
@@ -363,12 +363,12 @@ void EquipmentWindow::mousePressed(MouseEvent& mouseEvent)
}
}
}
- Window::mousePressed(mouseEvent);
+ Window::mousePressed(event);
}
-void EquipmentWindow::mouseReleased(MouseEvent &mouseEvent)
+void EquipmentWindow::mouseReleased(MouseEvent &event)
{
- Window::mouseReleased(mouseEvent);
+ Window::mouseReleased(event);
const DragDropSource src = dragDrop.getSource();
if (dragDrop.isEmpty() || (src != DRAGDROP_SOURCE_INVENTORY
&& src != DRAGDROP_SOURCE_EQUIPMENT))
@@ -397,8 +397,8 @@ void EquipmentWindow::mouseReleased(MouseEvent &mouseEvent)
{
if (item->isEquipment())
{
- const int x = mouseEvent.getX();
- const int y = mouseEvent.getY();
+ const int x = event.getX();
+ const int y = event.getY();
for (std::vector<EquipmentBox*>::const_iterator
it = mBoxes.begin(), it_end = mBoxes.end();
it != it_end; ++ it)
diff --git a/src/gui/windows/equipmentwindow.h b/src/gui/windows/equipmentwindow.h
index 245328b8e..45d4246e3 100644
--- a/src/gui/windows/equipmentwindow.h
+++ b/src/gui/windows/equipmentwindow.h
@@ -86,7 +86,7 @@ class EquipmentWindow final : public Window,
void action(const ActionEvent &event) override final;
- void mousePressed(MouseEvent& mouseEvent) override final;
+ void mousePressed(MouseEvent& event) override final;
const Item* getEquipment(const int i) const A_WARN_UNUSED
{ return mEquipment ? mEquipment->getEquipment(i) : nullptr; }
diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp
index 92b21dfd1..c2a4b4636 100644
--- a/src/gui/windows/inventorywindow.cpp
+++ b/src/gui/windows/inventorywindow.cpp
@@ -59,6 +59,8 @@
#include "net/inventoryhandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
+
#include <string>
#include "debug.h"
@@ -98,8 +100,8 @@ InventoryWindow::InventoryWindow(Inventory *const inventory):
mCompactMode(false)
{
mTextPopup->postInit();
- mSlotsBar->setColor(Theme::getThemeColor(Theme::SLOTS_BAR),
- Theme::getThemeColor(Theme::SLOTS_BAR_OUTLINE));
+ mSlotsBar->setColor(getThemeColor(Theme::SLOTS_BAR),
+ getThemeColor(Theme::SLOTS_BAR_OUTLINE));
if (inventory)
{
@@ -194,8 +196,8 @@ InventoryWindow::InventoryWindow(Inventory *const inventory):
mEquipmentButton = new Button(this, _("Equipment"), "equipment", this);
mWeightBar = new ProgressBar(this, 0.0F, 100, 0, Theme::PROG_WEIGHT,
"weightprogressbar.xml", "weightprogressbar_fill.xml");
- mWeightBar->setColor(Theme::getThemeColor(Theme::WEIGHT_BAR),
- Theme::getThemeColor(Theme::WEIGHT_BAR_OUTLINE));
+ mWeightBar->setColor(getThemeColor(Theme::WEIGHT_BAR),
+ getThemeColor(Theme::WEIGHT_BAR_OUTLINE));
place(0, 0, mWeightBar, 4);
mSlotsBarCell = &place(4, 0, mSlotsBar, 5);
@@ -274,8 +276,7 @@ InventoryWindow::~InventoryWindow()
invInstances.front()->updateDropButton();
mSortDropDown->hideDrop(false);
- delete mSortModel;
- mSortModel = nullptr;
+ delete2(mSortModel);
mTextPopup = nullptr;
}
diff --git a/src/gui/windows/itemamountwindow.cpp b/src/gui/windows/itemamountwindow.cpp
index ec581a96e..472057060 100644
--- a/src/gui/windows/itemamountwindow.cpp
+++ b/src/gui/windows/itemamountwindow.cpp
@@ -48,6 +48,7 @@
#include "gui/widgets/label.h"
#include "gui/widgets/slider.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -261,8 +262,7 @@ void ItemAmountWindow::postInit()
ItemAmountWindow::~ItemAmountWindow()
{
- delete mItemPopup;
- mItemPopup = nullptr;
+ delete2(mItemPopup);
}
// Show ItemTooltip
@@ -388,7 +388,7 @@ void ItemAmountWindow::close()
scheduleDelete();
}
-void ItemAmountWindow::keyReleased(KeyEvent &keyEvent A_UNUSED)
+void ItemAmountWindow::keyReleased(KeyEvent &event A_UNUSED)
{
mItemAmountSlide->setValue(mItemAmountTextField->getValue());
}
diff --git a/src/gui/windows/itemamountwindow.h b/src/gui/windows/itemamountwindow.h
index 2a414bb24..d2dca064e 100644
--- a/src/gui/windows/itemamountwindow.h
+++ b/src/gui/windows/itemamountwindow.h
@@ -82,7 +82,7 @@ class ItemAmountWindow final : public Window,
*/
void close();
- void keyReleased(KeyEvent &keyEvent) override final;
+ void keyReleased(KeyEvent &event) override final;
/**
* Creates the dialog, or bypass it if there aren't enough items.
diff --git a/src/gui/windows/logindialog.cpp b/src/gui/windows/logindialog.cpp
index 71abf153a..b2242d3f6 100644
--- a/src/gui/windows/logindialog.cpp
+++ b/src/gui/windows/logindialog.cpp
@@ -208,10 +208,8 @@ void LoginDialog::postInit()
LoginDialog::~LoginDialog()
{
- delete mUpdateTypeModel;
- mUpdateTypeModel = nullptr;
- delete mUpdateListModel;
- mUpdateListModel = nullptr;
+ delete2(mUpdateTypeModel);
+ delete2(mUpdateListModel);
}
void LoginDialog::action(const ActionEvent &event)
@@ -256,15 +254,15 @@ void LoginDialog::action(const ActionEvent &event)
}
}
-void LoginDialog::keyPressed(KeyEvent &keyEvent)
+void LoginDialog::keyPressed(KeyEvent &event)
{
- if (keyEvent.isConsumed())
+ if (event.isConsumed())
{
mLoginButton->setEnabled(canSubmit());
return;
}
- const int actionId = keyEvent.getActionId();
+ const int actionId = event.getActionId();
if (actionId == static_cast<int>(Input::KEY_GUI_CANCEL))
{
action(ActionEvent(nullptr, mServerButton->getActionEventId()));
diff --git a/src/gui/windows/logindialog.h b/src/gui/windows/logindialog.h
index 7150b62c1..1813e1817 100644
--- a/src/gui/windows/logindialog.h
+++ b/src/gui/windows/logindialog.h
@@ -71,7 +71,7 @@ class LoginDialog final : public Window,
/**
* Called when a key is pressed in one of the text fields.
*/
- void keyPressed(KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &event) override final;
void close() override final;
diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp
index 583a37746..9be6d7304 100644
--- a/src/gui/windows/minimap.cpp
+++ b/src/gui/windows/minimap.cpp
@@ -39,6 +39,7 @@
#include "resources/imagehelper.h"
#include "resources/resourcemanager.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/sdlcheckutils.h"
@@ -97,8 +98,7 @@ Minimap::~Minimap()
mMapImage->decRef();
mMapImage = nullptr;
}
- delete mTextPopup;
- mTextPopup = nullptr;
+ delete2(mTextPopup);
}
void Minimap::setMap(const Map *const map)
diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp
index 226132652..885ea619b 100644
--- a/src/gui/windows/ministatuswindow.cpp
+++ b/src/gui/windows/ministatuswindow.cpp
@@ -42,6 +42,7 @@
#include "net/playerhandler.h"
#include "net/gamehandler.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -52,7 +53,7 @@ extern volatile int tick_time;
typedef std::vector <ProgressBar*>::const_iterator ProgressBarVectorCIter;
MiniStatusWindow::MiniStatusWindow() :
- Popup("MiniStatus", "ministatus.xml"),
+ Window("MiniStatus", false, nullptr, "ministatus.xml"),
InventoryListener(),
mBars(),
mBarNames(),
@@ -114,8 +115,8 @@ MiniStatusWindow::MiniStatusWindow() :
StatusWindow::updateHPBar(mHpBar);
- if (Net::getGameHandler()->canUseMagicBar())
- StatusWindow::updateMPBar(mMpBar);
+ if (Net::getGameHandler()->canUseMagicBar() && statusWindow)
+ statusWindow->updateMPBar(mMpBar);
const int job = Net::getPlayerHandler()->getJobLocation()
&& serverConfig.getValueBool("showJob", true);
@@ -134,7 +135,7 @@ MiniStatusWindow::MiniStatusWindow() :
loadBars();
updateBars();
- setVisible(config.getValueBool(getPopupName() + "Visible", true));
+ setVisible(true);
addMouseListener(this);
Inventory *const inv = PlayerInfo::getInventory();
if (inv)
@@ -147,10 +148,8 @@ MiniStatusWindow::MiniStatusWindow() :
MiniStatusWindow::~MiniStatusWindow()
{
- delete mTextPopup;
- mTextPopup = nullptr;
- delete mStatusPopup;
- mStatusPopup = nullptr;
+ delete2(mTextPopup);
+ delete2(mStatusPopup);
delete_all(mIcons);
mIcons.clear();
@@ -183,8 +182,7 @@ ProgressBar *MiniStatusWindow::createBar(const float progress,
progress, width, height, backColor, skin, skinFill);
bar->setActionEventId(name);
bar->setId(description);
- bar->setColor(Theme::getThemeColor(textColor),
- Theme::getThemeColor(textColor + 1));
+ bar->setColor(getThemeColor(textColor), getThemeColor(textColor + 1));
mBars.push_back(bar);
mBarNames[name] = bar;
return bar;
@@ -195,7 +193,7 @@ void MiniStatusWindow::updateBars()
int x = 0;
const ProgressBar *lastBar = nullptr;
FOR_EACH (ProgressBarVectorCIter, it, mBars)
- safeRemove(*it);
+ remove(*it);
FOR_EACH (ProgressBarVectorCIter, it, mBars)
{
@@ -264,7 +262,7 @@ void MiniStatusWindow::processEvent(const Channels channel A_UNUSED,
}
else if (id == PlayerInfo::MP || id == PlayerInfo::MAX_MP)
{
- StatusWindow::updateMPBar(mMpBar);
+ statusWindow->updateMPBar(mMpBar);
}
else if (id == PlayerInfo::EXP || id == PlayerInfo::EXP_NEEDED)
{
@@ -282,14 +280,14 @@ void MiniStatusWindow::processEvent(const Channels channel A_UNUSED,
}
else if (event.getName() == EVENT_UPDATESTAT)
{
- StatusWindow::updateMPBar(mMpBar);
+ statusWindow->updateMPBar(mMpBar);
StatusWindow::updateJobBar(mJobBar);
}
}
void MiniStatusWindow::updateStatus()
{
- StatusWindow::updateStatusBar(mStatusBar);
+ statusWindow->updateStatusBar(mStatusBar);
if (mStatusPopup && mStatusPopup->isPopupVisible())
mStatusPopup->update();
}
@@ -297,7 +295,7 @@ void MiniStatusWindow::updateStatus()
void MiniStatusWindow::logic()
{
BLOCK_START("MiniStatusWindow::logic")
- Popup::logic();
+ Window::logic();
for (size_t i = 0, sz = mIcons.size(); i < sz; i++)
{
@@ -317,7 +315,7 @@ void MiniStatusWindow::draw(Graphics *graphics)
void MiniStatusWindow::mouseMoved(MouseEvent &event)
{
- Popup::mouseMoved(event);
+ Window::mouseMoved(event);
const int x = event.getX();
const int y = event.getY();
@@ -444,6 +442,7 @@ void MiniStatusWindow::mousePressed(MouseEvent &event)
event.getSource());
if (!bar)
return;
+ event.consume();
if (viewport)
{
viewport->showPopup(getX() + event.getX(),
@@ -454,7 +453,7 @@ void MiniStatusWindow::mousePressed(MouseEvent &event)
void MiniStatusWindow::mouseExited(MouseEvent &event)
{
- Popup::mouseExited(event);
+ Window::mouseExited(event);
mTextPopup->hide();
mStatusPopup->hide();
diff --git a/src/gui/windows/ministatuswindow.h b/src/gui/windows/ministatuswindow.h
index ee20ef69b..6939f8f54 100644
--- a/src/gui/windows/ministatuswindow.h
+++ b/src/gui/windows/ministatuswindow.h
@@ -27,7 +27,7 @@
#include "listeners/depricatedlistener.h"
-#include "gui/widgets/popup.h"
+#include "gui/widgets/window.h"
#include <vector>
@@ -42,7 +42,7 @@ class TextPopup;
*
* \ingroup Interface
*/
-class MiniStatusWindow final : public Popup,
+class MiniStatusWindow final : public Window,
public InventoryListener,
public DepricatedListener
{
@@ -71,7 +71,7 @@ class MiniStatusWindow final : public Popup,
void draw(Graphics *graphics) override final;
- void mouseMoved(MouseEvent &mouseEvent) override final;
+ void mouseMoved(MouseEvent &event) override final;
void mousePressed(MouseEvent &event) override final;
diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp
index 17454b6ab..56306a90f 100644
--- a/src/gui/windows/npcdialog.cpp
+++ b/src/gui/windows/npcdialog.cpp
@@ -57,6 +57,7 @@
#include "net/npchandler.h"
#include "utils/copynpaste.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -216,44 +217,23 @@ NpcDialog::~NpcDialog()
delete mPlayerBox;
}
- delete mTextBox;
- mTextBox = nullptr;
- delete mClearButton;
- mClearButton = nullptr;
- delete mButton;
- mButton = nullptr;
- delete mButton2;
- mButton2 = nullptr;
- delete mButton3;
- mButton3 = nullptr;
-
- // These might not actually be in the layout, so lets be safe
- delete mScrollArea;
- mScrollArea = nullptr;
- delete mItemList;
- mItemList = nullptr;
- delete mTextField;
- mTextField = nullptr;
- delete mIntField;
- mIntField = nullptr;
- delete mResetButton;
- mResetButton = nullptr;
- delete mPlusButton;
- mPlusButton = nullptr;
- delete mMinusButton;
- mMinusButton = nullptr;
- delete mItemLinkHandler;
- mItemLinkHandler = nullptr;
-
- delete mItemContainer;
- mItemContainer = nullptr;
- delete mInventory;
- mInventory = nullptr;
- delete mItemScrollArea;
- mItemScrollArea = nullptr;
-
- delete mListScrollArea;
- mListScrollArea = nullptr;
+ delete2(mTextBox);
+ delete2(mClearButton);
+ delete2(mButton);
+ delete2(mButton2);
+ delete2(mButton3);
+ delete2(mScrollArea);
+ delete2(mItemList);
+ delete2(mTextField);
+ delete2(mIntField);
+ delete2(mResetButton);
+ delete2(mPlusButton);
+ delete2(mMinusButton);
+ delete2(mItemLinkHandler);
+ delete2(mItemContainer);
+ delete2(mInventory);
+ delete2(mItemScrollArea);
+ delete2(mListScrollArea);
FOR_EACH (ImageVectorIter, it, mImages)
{
@@ -896,8 +876,7 @@ void NpcDialog::showAvatar(const uint16_t avatarId)
}
else
{
- delete mAvatarBeing;
- mAvatarBeing = nullptr;
+ delete2(mAvatarBeing)
mPlayerBox->setPlayer(nullptr);
}
if (needShow != mShowAvatar)
@@ -969,6 +948,7 @@ void NpcDialog::mousePressed(MouseEvent &event)
if (event.getButton() == MouseEvent::RIGHT
&& event.getSource() == mTextBox)
{
+ event.consume();
if (viewport)
viewport->showNpcDialogPopup(mNpcId);
}
diff --git a/src/gui/windows/questswindow.cpp b/src/gui/windows/questswindow.cpp
index 8d4eae9c8..b57ed9bd7 100644
--- a/src/gui/windows/questswindow.cpp
+++ b/src/gui/windows/questswindow.cpp
@@ -38,6 +38,7 @@
#include "gui/widgets/itemlinkhandler.h"
#include "gui/widgets/scrollarea.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -178,8 +179,7 @@ QuestsWindow::QuestsWindow() :
QuestsWindow::~QuestsWindow()
{
- delete mQuestsModel;
- mQuestsModel = nullptr;
+ delete2(mQuestsModel);
for (std::map<int, std::vector<QuestItem*> >::iterator it
= mQuests.begin(), it_end = mQuests.end(); it != it_end; ++ it)
@@ -194,8 +194,7 @@ QuestsWindow::~QuestsWindow()
delete_all(mAllEffects);
mAllEffects.clear();
- delete mItemLinkHandler;
- mItemLinkHandler = nullptr;
+ delete2(mItemLinkHandler);
mQuests.clear();
mQuestLinks.clear();
if (mCompleteIcon)
diff --git a/src/gui/windows/quitdialog.cpp b/src/gui/windows/quitdialog.cpp
index 98aa70c70..a1add2711 100644
--- a/src/gui/windows/quitdialog.cpp
+++ b/src/gui/windows/quitdialog.cpp
@@ -131,14 +131,10 @@ QuitDialog::~QuitDialog()
{
if (mMyPointer)
*mMyPointer = nullptr;
- delete mForceQuit;
- mForceQuit = nullptr;
- delete mLogoutQuit;
- mLogoutQuit = nullptr;
- delete mSwitchAccountServer;
- mSwitchAccountServer = nullptr;
- delete mSwitchCharacter;
- mSwitchCharacter = nullptr;
+ delete2(mForceQuit);
+ delete2(mLogoutQuit);
+ delete2(mSwitchAccountServer);
+ delete2(mSwitchCharacter);
}
void QuitDialog::placeOption(ContainerPlacer &placer,
@@ -203,9 +199,9 @@ void QuitDialog::action(const ActionEvent &event)
scheduleDelete();
}
-void QuitDialog::keyPressed(KeyEvent &keyEvent)
+void QuitDialog::keyPressed(KeyEvent &event)
{
- const int actionId = keyEvent.getActionId();
+ const int actionId = event.getActionId();
int dir = 0;
switch (actionId)
diff --git a/src/gui/windows/quitdialog.h b/src/gui/windows/quitdialog.h
index 8ce60d06c..ffcea4122 100644
--- a/src/gui/windows/quitdialog.h
+++ b/src/gui/windows/quitdialog.h
@@ -64,7 +64,7 @@ class QuitDialog final : public Window,
*/
void action(const ActionEvent &event) override final;
- void keyPressed(KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &event) override final;
private:
void placeOption(ContainerPlacer &placer,
diff --git a/src/gui/windows/registerdialog.cpp b/src/gui/windows/registerdialog.cpp
index 50344f223..55a328fa8 100644
--- a/src/gui/windows/registerdialog.cpp
+++ b/src/gui/windows/registerdialog.cpp
@@ -40,6 +40,7 @@
#include "net/loginhandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -169,8 +170,7 @@ void RegisterDialog::postInit()
RegisterDialog::~RegisterDialog()
{
- delete mWrongDataNoticeListener;
- mWrongDataNoticeListener = nullptr;
+ delete2(mWrongDataNoticeListener);
}
void RegisterDialog::action(const ActionEvent &event)
@@ -282,14 +282,14 @@ void RegisterDialog::action(const ActionEvent &event)
}
}
-void RegisterDialog::keyPressed(KeyEvent &keyEvent)
+void RegisterDialog::keyPressed(KeyEvent &event)
{
- if (keyEvent.isConsumed())
+ if (event.isConsumed())
{
mRegisterButton->setEnabled(canSubmit());
return;
}
- const int actionId = keyEvent.getActionId();
+ const int actionId = event.getActionId();
if (actionId == static_cast<int>(Input::KEY_GUI_CANCEL))
{
action(ActionEvent(nullptr, mCancelButton->getActionEventId()));
diff --git a/src/gui/windows/registerdialog.h b/src/gui/windows/registerdialog.h
index 1d5b5e48b..90087b5e2 100644
--- a/src/gui/windows/registerdialog.h
+++ b/src/gui/windows/registerdialog.h
@@ -87,7 +87,7 @@ class RegisterDialog final : public Window,
/**
* Called when a key is pressed in one of the text fields.
*/
- void keyPressed(KeyEvent &keyEvent) override;
+ void keyPressed(KeyEvent &event) override;
void close() override;
diff --git a/src/gui/windows/selldialog.cpp b/src/gui/windows/selldialog.cpp
index ebee65d1e..604caa72e 100644
--- a/src/gui/windows/selldialog.cpp
+++ b/src/gui/windows/selldialog.cpp
@@ -45,6 +45,7 @@
#include "resources/iteminfo.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -162,8 +163,7 @@ void SellDialog::init()
SellDialog::~SellDialog()
{
- delete mShopItems;
- mShopItems = nullptr;
+ delete2(mShopItems);
instances.remove(this);
}
diff --git a/src/gui/windows/serverdialog.cpp b/src/gui/windows/serverdialog.cpp
index 112d1588d..9e85f5c89 100644
--- a/src/gui/windows/serverdialog.cpp
+++ b/src/gui/windows/serverdialog.cpp
@@ -46,6 +46,7 @@
#include "gui/widgets/listbox.h"
#include "gui/widgets/scrollarea.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/langs.h"
@@ -295,11 +296,9 @@ ServerDialog::~ServerDialog()
if (mDownload)
{
mDownload->cancel();
- delete mDownload;
- mDownload = nullptr;
+ delete2(mDownload)
}
- delete mServersListModel;
- mServersListModel = nullptr;
+ delete2(mServersListModel);
}
void ServerDialog::connectToSelectedServer()
@@ -389,18 +388,18 @@ void ServerDialog::action(const ActionEvent &event)
}
}
-void ServerDialog::keyPressed(KeyEvent &keyEvent)
+void ServerDialog::keyPressed(KeyEvent &event)
{
- switch (keyEvent.getActionId())
+ switch (event.getActionId())
{
case Input::KEY_GUI_CANCEL:
- keyEvent.consume();
+ event.consume();
client->setState(STATE_EXIT);
return;
case Input::KEY_GUI_SELECT:
case Input::KEY_GUI_SELECT2:
- keyEvent.consume();
+ event.consume();
action(ActionEvent(nullptr,
mConnectButton->getActionEventId()));
return;
@@ -435,8 +434,8 @@ void ServerDialog::keyPressed(KeyEvent &keyEvent)
default:
break;
}
- if (!keyEvent.isConsumed())
- mServersList->keyPressed(keyEvent);
+ if (!event.isConsumed())
+ mServersList->keyPressed(event);
}
void ServerDialog::valueChanged(const SelectionEvent &)
@@ -450,13 +449,17 @@ void ServerDialog::valueChanged(const SelectionEvent &)
mDeleteButton->setEnabled(true);
}
-void ServerDialog::mouseClicked(MouseEvent &mouseEvent)
+void ServerDialog::mouseClicked(MouseEvent &event)
{
- if (mouseEvent.getClickCount() == 2 &&
- mouseEvent.getSource() == mServersList)
+ if (event.getButton() == MouseEvent::LEFT)
{
- action(ActionEvent(mConnectButton,
- mConnectButton->getActionEventId()));
+ event.consume();
+ if (event.getClickCount() == 2 &&
+ event.getSource() == mServersList)
+ {
+ action(ActionEvent(mConnectButton,
+ mConnectButton->getActionEventId()));
+ }
}
}
@@ -513,8 +516,7 @@ void ServerDialog::downloadServerList()
if (mDownload)
{
mDownload->cancel();
- delete mDownload;
- mDownload = nullptr;
+ delete2(mDownload)
}
mDownload = new Net::Download(this, listFile,
diff --git a/src/gui/windows/serverdialog.h b/src/gui/windows/serverdialog.h
index 7c3a05ab3..88b6a7caf 100644
--- a/src/gui/windows/serverdialog.h
+++ b/src/gui/windows/serverdialog.h
@@ -74,14 +74,14 @@ class ServerDialog final : public Window,
*/
void action(const ActionEvent &event) override final;
- void keyPressed(KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &event) override final;
/**
* Called when the selected value changed in the servers list box.
*/
void valueChanged(const SelectionEvent &event) override final;
- void mouseClicked(MouseEvent &mouseEvent) override final;
+ void mouseClicked(MouseEvent &event) override final;
void logic() override final;
diff --git a/src/gui/windows/setupwindow.cpp b/src/gui/windows/setupwindow.cpp
index 1760d00bd..7239061ff 100644
--- a/src/gui/windows/setupwindow.cpp
+++ b/src/gui/windows/setupwindow.cpp
@@ -48,6 +48,7 @@
#include "gui/widgets/label.h"
#include "gui/widgets/tabbedarea.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -223,8 +224,7 @@ void SetupWindow::unloadModTab()
mTabs.remove(mModsTab);
Tab *const tab = mPanel->getTab(mModsTab->getName());
mPanel->removeTab(tab);
- delete mModsTab;
- mModsTab = nullptr;
+ delete2(mModsTab)
}
}
diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp
index 923511baa..b44dcc19e 100644
--- a/src/gui/windows/shopwindow.cpp
+++ b/src/gui/windows/shopwindow.cpp
@@ -58,6 +58,7 @@
#include "resources/iteminfo.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include <sstream>
@@ -197,11 +198,8 @@ ShopWindow::~ShopWindow()
{
saveList();
- delete mBuyShopItems;
- mBuyShopItems = nullptr;
-
- delete mSellShopItems;
- mSellShopItems = nullptr;
+ delete2(mBuyShopItems);
+ delete2(mSellShopItems);
instances.remove(this);
}
diff --git a/src/gui/windows/shortcutwindow.cpp b/src/gui/windows/shortcutwindow.cpp
index 6ec442cd5..8387d7e91 100644
--- a/src/gui/windows/shortcutwindow.cpp
+++ b/src/gui/windows/shortcutwindow.cpp
@@ -30,6 +30,8 @@
#include "gui/widgets/shortcutcontainer.h"
#include "gui/widgets/tabs/tab.h"
+#include "utils/delete2.h"
+
#include "debug.h"
static const int SCROLL_PADDING = 0;
@@ -152,10 +154,8 @@ ShortcutWindow::~ShortcutWindow()
{
if (mTabs)
mTabs->removeAll();
- delete mTabs;
- mTabs = nullptr;
- delete mItems;
- mItems = nullptr;
+ delete2(mTabs);
+ delete2(mItems);
}
void ShortcutWindow::addTab(const std::string &name,
diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp
index 21cc009bc..f077341bf 100644
--- a/src/gui/windows/skilldialog.cpp
+++ b/src/gui/windows/skilldialog.cpp
@@ -50,6 +50,7 @@
#include "net/playerhandler.h"
#include "net/skillhandler.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -83,10 +84,8 @@ class SkillListBox final : public ListBox
~SkillListBox()
{
- delete mModel;
- mModel = nullptr;
- delete mPopup;
- mPopup = nullptr;
+ delete2(mModel)
+ delete2(mPopup)
}
SkillInfo *getSelectedInfo() const
@@ -215,6 +214,7 @@ class SkillListBox final : public ListBox
const SkillInfo *const skill = getSkillByEvent(event);
if (!skill)
return;
+ event.consume();
mSkillClicked = true;
}
}
@@ -255,8 +255,7 @@ class SkillTab final : public Tab
~SkillTab()
{
- delete mListBox;
- mListBox = nullptr;
+ delete2(mListBox)
}
SkillInfo *getSelectedInfo() const
diff --git a/src/gui/windows/socialwindow.cpp b/src/gui/windows/socialwindow.cpp
index 8e6becca1..3f6fe663d 100644
--- a/src/gui/windows/socialwindow.cpp
+++ b/src/gui/windows/socialwindow.cpp
@@ -57,6 +57,7 @@
#include "net/guildhandler.h"
#include "net/partyhandler.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -206,10 +207,8 @@ public:
~SocialGuildTab()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
+ delete2(mList)
+ delete2(mScroll)
}
void action(const ActionEvent &event) override final
@@ -342,10 +341,8 @@ public:
~SocialGuildTab2()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
+ delete2(mList)
+ delete2(mScroll)
}
void action(const ActionEvent &event A_UNUSED) override final
@@ -411,10 +408,8 @@ public:
~SocialPartyTab()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
+ delete2(mList)
+ delete2(mScroll)
}
void action(const ActionEvent &event) override final
@@ -530,12 +525,9 @@ public:
~SocialPlayersTab()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
- delete mBeings;
- mBeings = nullptr;
+ delete2(mList)
+ delete2(mScroll)
+ delete2(mBeings)
}
void updateList() override final
@@ -568,6 +560,7 @@ public:
avatar->setLevel(being->getLevel());
avatar->setGender(being->getGender());
avatar->setIp(being->getIp());
+ avatar->setPoison(being->getPoison());
}
}
@@ -696,12 +689,9 @@ public:
~SocialNavigationTab()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
- delete mBeings;
- mBeings = nullptr;
+ delete2(mList)
+ delete2(mScroll)
+ delete2(mBeings)
}
void updateList() override final
@@ -1025,12 +1015,9 @@ public:
~SocialAttackTab()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
- delete mBeings;
- mBeings = nullptr;
+ delete2(mList)
+ delete2(mScroll)
+ delete2(mBeings)
}
void updateList() override final
@@ -1072,12 +1059,9 @@ public:
~SocialPickupTab()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
- delete mBeings;
- mBeings = nullptr;
+ delete2(mList)
+ delete2(mScroll)
+ delete2(mBeings)
}
void updateList() override final
@@ -1119,12 +1103,9 @@ public:
~SocialFriendsTab()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
- delete mBeings;
- mBeings = nullptr;
+ delete2(mList)
+ delete2(mScroll)
+ delete2(mBeings)
}
void updateList() override final
@@ -1370,18 +1351,12 @@ SocialWindow::~SocialWindow()
mPartyInviter.clear();
}
- delete mCreatePopup;
- mCreatePopup = nullptr;
- delete mPlayers;
- mPlayers = nullptr;
- delete mNavigation;
- mNavigation = nullptr;
- delete mAttackFilter;
- mAttackFilter = nullptr;
- delete mPickupFilter;
- mPickupFilter = nullptr;
- delete mFriends;
- mFriends = nullptr;
+ delete2(mCreatePopup);
+ delete2(mPlayers);
+ delete2(mNavigation);
+ delete2(mAttackFilter);
+ delete2(mPickupFilter);
+ delete2(mFriends);
}
bool SocialWindow::addTab(Guild *const guild)
diff --git a/src/gui/windows/statuswindow.cpp b/src/gui/windows/statuswindow.cpp
index 05172c9b3..98d3ea82e 100644
--- a/src/gui/windows/statuswindow.cpp
+++ b/src/gui/windows/statuswindow.cpp
@@ -49,6 +49,7 @@
#include "net/playerhandler.h"
#include "net/gamehandler.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include <SDL_timer.h>
@@ -193,16 +194,16 @@ StatusWindow::StatusWindow() :
mHpBar = new ProgressBar(this, static_cast<float>(PlayerInfo::getAttribute(
PlayerInfo::HP)) / static_cast<float>(max), 80, 0, Theme::PROG_HP,
"hpprogressbar.xml", "hpprogressbar_fill.xml");
- mHpBar->setColor(Theme::getThemeColor(Theme::HP_BAR),
- Theme::getThemeColor(Theme::HP_BAR_OUTLINE));
+ mHpBar->setColor(getThemeColor(Theme::HP_BAR),
+ getThemeColor(Theme::HP_BAR_OUTLINE));
max = PlayerInfo::getAttribute(PlayerInfo::EXP_NEEDED);
mXpBar = new ProgressBar(this, max ?
static_cast<float>(PlayerInfo::getAttribute(PlayerInfo::EXP))
/ static_cast<float>(max) : static_cast<float>(0), 80, 0,
Theme::PROG_EXP, "xpprogressbar.xml", "xpprogressbar_fill.xml");
- mXpBar->setColor(Theme::getThemeColor(Theme::XP_BAR),
- Theme::getThemeColor(Theme::XP_BAR_OUTLINE));
+ mXpBar->setColor(getThemeColor(Theme::XP_BAR),
+ getThemeColor(Theme::XP_BAR_OUTLINE));
const bool magicBar = Net::getGameHandler()->canUseMagicBar();
const int job = Net::getPlayerHandler()->getJobLocation()
@@ -222,13 +223,13 @@ StatusWindow::StatusWindow() :
useMagic ? "mpprogressbar_fill.xml" : "nompprogressbar_fill.xml");
if (useMagic)
{
- mMpBar->setColor(Theme::getThemeColor(Theme::MP_BAR),
- Theme::getThemeColor(Theme::MP_BAR_OUTLINE));
+ mMpBar->setColor(getThemeColor(Theme::MP_BAR),
+ getThemeColor(Theme::MP_BAR_OUTLINE));
}
else
{
- mMpBar->setColor(Theme::getThemeColor(Theme::NO_MP_BAR),
- Theme::getThemeColor(Theme::NO_MP_BAR_OUTLINE));
+ mMpBar->setColor(getThemeColor(Theme::NO_MP_BAR),
+ getThemeColor(Theme::NO_MP_BAR_OUTLINE));
}
}
else
@@ -260,8 +261,8 @@ StatusWindow::StatusWindow() :
mJobLabel = new Label(this, _("Job:"));
mJobBar = new ProgressBar(this, 0.0F, 80, 0, Theme::PROG_JOB,
"jobprogressbar.xml", "jobprogressbar_fill.xml");
- mJobBar->setColor(Theme::getThemeColor(Theme::JOB_BAR),
- Theme::getThemeColor(Theme::JOB_BAR_OUTLINE));
+ mJobBar->setColor(getThemeColor(Theme::JOB_BAR),
+ getThemeColor(Theme::JOB_BAR_OUTLINE));
place(3, 0, mJobLvlLabel, 3);
place(5, 2, mJobLabel).setPadding(3);
@@ -524,7 +525,8 @@ void StatusWindow::updateHPBar(ProgressBar *const bar, const bool showMax)
bar->setProgress(prog);
}
-void StatusWindow::updateMPBar(ProgressBar *const bar, const bool showMax)
+void StatusWindow::updateMPBar(ProgressBar *const bar,
+ const bool showMax) const
{
if (!bar)
return;
@@ -542,14 +544,14 @@ void StatusWindow::updateMPBar(ProgressBar *const bar, const bool showMax)
if (Net::getPlayerHandler()->canUseMagic())
{
- bar->setColor(Theme::getThemeColor(Theme::MP_BAR),
- Theme::getThemeColor(Theme::MP_BAR_OUTLINE));
+ bar->setColor(getThemeColor(Theme::MP_BAR),
+ getThemeColor(Theme::MP_BAR_OUTLINE));
bar->setProgressPalette(Theme::PROG_MP);
}
else
{
- bar->setColor(Theme::getThemeColor(Theme::NO_MP_BAR),
- Theme::getThemeColor(Theme::NO_MP_BAR_OUTLINE));
+ bar->setColor(getThemeColor(Theme::NO_MP_BAR),
+ getThemeColor(Theme::NO_MP_BAR_OUTLINE));
bar->setProgressPalette(Theme::PROG_NO_MP);
}
@@ -715,7 +717,7 @@ std::string StatusWindow::translateLetter2(std::string letters)
}
void StatusWindow::updateStatusBar(ProgressBar *const bar,
- const bool percent A_UNUSED)
+ const bool percent A_UNUSED) const
{
if (!player_node || !viewport)
return;
@@ -741,9 +743,9 @@ void StatusWindow::updateStatusBar(ProgressBar *const bar,
bar->setProgress(50);
if (player_node->getDisableGameModifiers())
- bar->setBackgroundColor(Theme::getThemeColor(Theme::STATUSBAR_ON));
+ bar->setBackgroundColor(getThemeColor(Theme::STATUSBAR_ON));
else
- bar->setBackgroundColor(Theme::getThemeColor(Theme::STATUSBAR_OFF));
+ bar->setBackgroundColor(getThemeColor(Theme::STATUSBAR_OFF));
}
void StatusWindow::action(const ActionEvent &event)
@@ -790,8 +792,7 @@ AttrDisplay::AttrDisplay(const Widget2 *const widget,
AttrDisplay::~AttrDisplay()
{
- delete mLayout;
- mLayout = nullptr;
+ delete2(mLayout);
}
std::string AttrDisplay::update()
diff --git a/src/gui/windows/statuswindow.h b/src/gui/windows/statuswindow.h
index 3b171a25e..35bba74cd 100644
--- a/src/gui/windows/statuswindow.h
+++ b/src/gui/windows/statuswindow.h
@@ -66,7 +66,7 @@ class StatusWindow final : public Window,
static void updateHPBar(ProgressBar *const bar,
const bool showMax = false);
- static void updateMPBar(ProgressBar *bar, const bool showMax = false);
+ void updateMPBar(ProgressBar *bar, const bool showMax = false) const;
static void updateJobBar(ProgressBar *const bar,
const bool percent = true);
static void updateXPBar(ProgressBar *const bar,
@@ -75,8 +75,8 @@ class StatusWindow final : public Window,
static void updateInvSlotsBar(ProgressBar *const bar);
static void updateMoneyBar(ProgressBar *const bar);
static void updateArrowsBar(ProgressBar *const bar);
- static void updateStatusBar(ProgressBar *const bar,
- const bool percent = true);
+ void updateStatusBar(ProgressBar *const bar,
+ const bool percent = true) const;
static void updateProgressBar(ProgressBar *const bar, const int value,
const int max, const bool percent);
static void updateProgressBar(ProgressBar *const bar,
diff --git a/src/gui/windows/textcommandeditor.cpp b/src/gui/windows/textcommandeditor.cpp
index dead469bc..2eccb255d 100644
--- a/src/gui/windows/textcommandeditor.cpp
+++ b/src/gui/windows/textcommandeditor.cpp
@@ -38,6 +38,7 @@
#include "gui/widgets/layout.h"
#include "gui/widgets/radiobutton.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -191,12 +192,9 @@ void TextCommandEditor::postInit()
TextCommandEditor::~TextCommandEditor()
{
- delete mIconsModel;
- mIconsModel = nullptr;
- delete mTargetTypeModel;
- mTargetTypeModel = nullptr;
- delete mMagicSchoolModel;
- mMagicSchoolModel = nullptr;
+ delete2(mIconsModel);
+ delete2(mTargetTypeModel);
+ delete2(mMagicSchoolModel);
}
void TextCommandEditor::action(const ActionEvent &event)
diff --git a/src/gui/windows/unregisterdialog.cpp b/src/gui/windows/unregisterdialog.cpp
index 3326ca2bb..bb309c6f1 100644
--- a/src/gui/windows/unregisterdialog.cpp
+++ b/src/gui/windows/unregisterdialog.cpp
@@ -35,6 +35,7 @@
#include "net/loginhandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include <string>
@@ -97,8 +98,7 @@ void UnRegisterDialog::postInit()
UnRegisterDialog::~UnRegisterDialog()
{
- delete mWrongDataNoticeListener;
- mWrongDataNoticeListener = nullptr;
+ delete2(mWrongDataNoticeListener);
}
void UnRegisterDialog::action(const ActionEvent &event)
diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp
index 247ef8707..cd0e7e0d8 100644
--- a/src/gui/windows/updaterwindow.cpp
+++ b/src/gui/windows/updaterwindow.cpp
@@ -42,6 +42,7 @@
#include "resources/db/moddb.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/mkdir.h"
#include "utils/paths.h"
@@ -242,8 +243,7 @@ UpdaterWindow::~UpdaterWindow()
{
mDownload->cancel();
- delete mDownload;
- mDownload = nullptr;
+ delete2(mDownload)
}
free(mMemoryBuffer);
}
@@ -292,9 +292,9 @@ void UpdaterWindow::action(const ActionEvent &event)
}
}
-void UpdaterWindow::keyPressed(KeyEvent &keyEvent)
+void UpdaterWindow::keyPressed(KeyEvent &event)
{
- const int actionId = keyEvent.getActionId();
+ const int actionId = event.getActionId();
if (actionId == static_cast<int>(Input::KEY_GUI_CANCEL))
{
action(ActionEvent(nullptr, mCancelButton->getActionEventId()));
diff --git a/src/gui/windows/updaterwindow.h b/src/gui/windows/updaterwindow.h
index 39e1e84f3..4874ba8ba 100644
--- a/src/gui/windows/updaterwindow.h
+++ b/src/gui/windows/updaterwindow.h
@@ -121,7 +121,7 @@ class UpdaterWindow final : public Window,
void action(const ActionEvent &event) override final;
- void keyPressed(KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &event) override final;
void logic() override final;
diff --git a/src/gui/windows/worldselectdialog.cpp b/src/gui/windows/worldselectdialog.cpp
index 58c1aaee8..5cd0a3b2f 100644
--- a/src/gui/windows/worldselectdialog.cpp
+++ b/src/gui/windows/worldselectdialog.cpp
@@ -38,6 +38,7 @@
#include "net/loginhandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -95,8 +96,7 @@ void WorldSelectDialog::postInit()
WorldSelectDialog::~WorldSelectDialog()
{
- delete mWorldListModel;
- mWorldListModel = nullptr;
+ delete2(mWorldListModel);
}
void WorldSelectDialog::action(const ActionEvent &event)
@@ -118,9 +118,9 @@ void WorldSelectDialog::action(const ActionEvent &event)
}
}
-void WorldSelectDialog::keyPressed(KeyEvent &keyEvent)
+void WorldSelectDialog::keyPressed(KeyEvent &event)
{
- const int actionId = keyEvent.getActionId();
+ const int actionId = event.getActionId();
if (actionId == static_cast<int>(Input::KEY_GUI_CANCEL))
{
diff --git a/src/gui/windows/worldselectdialog.h b/src/gui/windows/worldselectdialog.h
index 9d06ac25e..b91beeece 100644
--- a/src/gui/windows/worldselectdialog.h
+++ b/src/gui/windows/worldselectdialog.h
@@ -65,7 +65,7 @@ class WorldSelectDialog final : public Window,
*/
void action(const ActionEvent &event) override final;
- void keyPressed(KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &event) override final;
private:
WorldListModel *mWorldListModel;
diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp
index a1fab3b1e..48485e9b4 100644
--- a/src/guildmanager.cpp
+++ b/src/guildmanager.cpp
@@ -36,6 +36,7 @@
#include "net/chathandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
#include "utils/timer.h"
#include "debug.h"
@@ -60,8 +61,7 @@ GuildManager::GuildManager() :
GuildManager::~GuildManager()
{
- delete mTab;
- mTab = nullptr;
+ delete2(mTab);
}
void GuildManager::init()
@@ -85,8 +85,7 @@ void GuildManager::init()
}
else if (guildManager)
{
- delete guildManager;
- guildManager = nullptr;
+ delete2(guildManager);
}
}
@@ -108,8 +107,7 @@ void GuildManager::reload()
if (guild && socialWindow)
socialWindow->removeTab(guild);
}
- delete mTab;
- mTab = nullptr;
+ delete2(mTab);
}
void GuildManager::send(const std::string &msg)
@@ -520,8 +518,7 @@ bool GuildManager::afterRemove()
player_node->clearGuilds();
}
NotifyManager::notify(NotifyManager::GUILD_LEFT);
- delete mTab;
- mTab = nullptr;
+ delete2(mTab);
if (socialWindow)
socialWindow->removeTab(guild);
diff --git a/src/input/keyboarddata.h b/src/input/keyboarddata.h
index 37a36b45f..c099e573e 100644
--- a/src/input/keyboarddata.h
+++ b/src/input/keyboarddata.h
@@ -63,14 +63,14 @@ static const KeyData keyData[Input::KEY_TOTAL] = {
Input::KEY_NO_VALUE, 50,
COND_ARROWKEYS},
{"keyAttack",
- INPUT_KEYBOARD, SDLK_LCTRL,
+ INPUT_KEYBOARD, SDLK_x,
INPUT_UNKNOWN, Input::KEY_NO_VALUE,
Input::GRP_DEFAULT | Input::GRP_REPEAT,
&ActionManager::attack,
Input::KEY_NO_VALUE, 50,
COND_GAME | COND_NOFOLLOW | COND_VALIDSPEED},
{"keyTargetAttack",
- INPUT_KEYBOARD, SDLK_x,
+ INPUT_KEYBOARD, SDLK_LCTRL,
INPUT_JOYSTICK, 0,
Input::GRP_DEFAULT,
&ActionManager::targetAttack,
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 90fd1c94a..6213b44c9 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -30,6 +30,7 @@
#include "resources/iteminfo.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include <algorithm>
@@ -153,8 +154,7 @@ void Inventory::removeItem(const int id)
void Inventory::removeItemAt(const int index)
{
- delete mItems[index];
- mItems[index] = nullptr;
+ delete2(mItems[index]);
mUsed--;
if (mUsed < 0) // Already at 0, no need to distribute event
mUsed = 0;
diff --git a/src/item.cpp b/src/item.cpp
index fe2fcaa92..02c5d0c16 100644
--- a/src/item.cpp
+++ b/src/item.cpp
@@ -92,11 +92,12 @@ void Item::setId(const int id, const unsigned char color)
}
}
-bool Item::isHaveTag(const int tagId)
+bool Item::isHaveTag(const int tagId) const
{
- if (mTags.find(tagId) == mTags.end())
+ const std::map <int, int>::const_iterator it = mTags.find(tagId);
+ if (it == mTags.end())
return false;
- return mTags[tagId] > 0;
+ return (*it).second > 0;
}
Image *Item::getImage(const int id, const unsigned char color)
@@ -112,7 +113,7 @@ Image *Item::getImage(const int id, const unsigned char color)
return image;
}
-std::string Item::getName()
+std::string Item::getName() const
{
const ItemInfo &info = ItemDB::get(mId);
if (serverVersion > 0)
diff --git a/src/item.h b/src/item.h
index adb6ec03e..dc4600d8b 100644
--- a/src/item.h
+++ b/src/item.h
@@ -153,12 +153,12 @@ class Item
const ItemInfo &getInfo() const A_WARN_UNUSED
{ return ItemDB::get(mId); }
- std::string getName() A_WARN_UNUSED;
+ std::string getName() const A_WARN_UNUSED;
static Image *getImage(const int id,
const unsigned char color) A_WARN_UNUSED;
- bool isHaveTag(const int tagId) A_WARN_UNUSED;
+ bool isHaveTag(const int tagId) const A_WARN_UNUSED;
unsigned char getColor() const A_WARN_UNUSED
{ return mColor; }
diff --git a/src/listeners/keylistener.h b/src/listeners/keylistener.h
index efc387300..7a2bdd2c9 100644
--- a/src/listeners/keylistener.h
+++ b/src/listeners/keylistener.h
@@ -89,17 +89,17 @@ class KeyListener
* If a key is held down the widget will generate multiple key
* presses.
*
- * @param keyEvent Discribes the event.
+ * @param event Discribes the event.
*/
- virtual void keyPressed(KeyEvent &keyEvent A_UNUSED)
+ virtual void keyPressed(KeyEvent &event A_UNUSED)
{ }
/**
* Called if a key is released when the widget has keyboard focus.
*
- * @param keyEvent Discribes the event.
+ * @param event Discribes the event.
*/
- virtual void keyReleased(KeyEvent &keyEvent A_UNUSED)
+ virtual void keyReleased(KeyEvent &event A_UNUSED)
{ }
protected:
diff --git a/src/listeners/mouselistener.h b/src/listeners/mouselistener.h
index 9a2a4ef04..e3c7c7ccb 100644
--- a/src/listeners/mouselistener.h
+++ b/src/listeners/mouselistener.h
@@ -86,20 +86,20 @@ class MouseListener
/**
* Called when the mouse has entered into the widget area.
*
- * @param mouseEvent Describes the event.
+ * @param event Describes the event.
* @since 0.6.0
*/
- virtual void mouseEntered(MouseEvent &mouseEvent A_UNUSED)
+ virtual void mouseEntered(MouseEvent &event A_UNUSED)
{
}
/**
* Called when the mouse has exited the widget area.
*
- * @param mouseEvent Describes the event.
+ * @param event Describes the event.
* @since 0.6.0
*/
- virtual void mouseExited(MouseEvent &mouseEvent A_UNUSED)
+ virtual void mouseExited(MouseEvent &event A_UNUSED)
{
}
@@ -109,20 +109,20 @@ class MouseListener
* NOTE: A mouse press is NOT equal to a mouse click.
* Use mouseClickMessage to check for mouse clicks.
*
- * @param mouseEvent Describes the event.
+ * @param event Describes the event.
* @since 0.6.0
*/
- virtual void mousePressed(MouseEvent &mouseEvent A_UNUSED)
+ virtual void mousePressed(MouseEvent &event A_UNUSED)
{
}
/**
* Called when a mouse button has been released on the widget area.
*
- * @param mouseEvent Describes the event.
+ * @param event Describes the event.
* @since 0.6.0
*/
- virtual void mouseReleased(MouseEvent &mouseEvent A_UNUSED)
+ virtual void mouseReleased(MouseEvent &event A_UNUSED)
{
}
@@ -130,20 +130,20 @@ class MouseListener
* Called when a mouse button is pressed and released (clicked) on
* the widget area.
*
- * @param mouseEvent Describes the event.
+ * @param event Describes the event.
* @since 0.6.0
*/
- virtual void mouseClicked(MouseEvent &mouseEvent A_UNUSED)
+ virtual void mouseClicked(MouseEvent &event A_UNUSED)
{
}
/**
* Called when the mouse wheel has moved up on the widget area.
*
- * @param mouseEvent Describes the event.
+ * @param event Describes the event.
* @since 0.6.0
*/
- virtual void mouseWheelMovedUp(MouseEvent &mouseEvent A_UNUSED)
+ virtual void mouseWheelMovedUp(MouseEvent &event A_UNUSED)
{
}
@@ -153,7 +153,7 @@ class MouseListener
* @param mousEvent Describes the event.
* @since 0.6.0
*/
- virtual void mouseWheelMovedDown(MouseEvent &mouseEvent A_UNUSED)
+ virtual void mouseWheelMovedDown(MouseEvent &event A_UNUSED)
{
}
@@ -161,10 +161,10 @@ class MouseListener
* Called when the mouse has moved in the widget area and no mouse button
* has been pressed (i.e no widget is being dragged).
*
- * @param mouseEvent Describes the event.
+ * @param event Describes the event.
* @since 0.6.0
*/
- virtual void mouseMoved(MouseEvent &mouseEvent A_UNUSED)
+ virtual void mouseMoved(MouseEvent &event A_UNUSED)
{
}
@@ -172,10 +172,10 @@ class MouseListener
* Called when the mouse has moved and the mouse has previously been
* pressed on the widget.
*
- * @param mouseEvent Describes the event.
+ * @param event Describes the event.
* @since 0.6.0
*/
- virtual void mouseDragged(MouseEvent &mouseEvent A_UNUSED)
+ virtual void mouseDragged(MouseEvent &event A_UNUSED)
{
}
diff --git a/src/localconsts.h b/src/localconsts.h
index 92c36d92a..d71126c11 100644
--- a/src/localconsts.h
+++ b/src/localconsts.h
@@ -112,4 +112,7 @@
// use file access fuzzer
// #define USE_FUZZER 1
+#ifdef DYECMD
+#undef USE_FUZZER
+#endif
#include "utils/perfomance.h"
diff --git a/src/main.cpp b/src/main.cpp
index 75305233f..35a5570ea 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -29,6 +29,7 @@
#include <iostream>
#include <unistd.h>
+#include "utils/delete2.h"
#include "utils/gettext.h"
#ifdef ANDROID
#include "utils/mkdir.h"
@@ -320,8 +321,7 @@ int main(int argc, char *argv[])
client->testsInit();
ret = client->testsExec();
}
- delete client;
- client = nullptr;
+ delete2(client);
#if SDL_MIXER_VERSION_ATLEAST(1, 2, 11)
Mix_Quit();
diff --git a/src/main.h b/src/main.h
index b0f793360..60ecfb981 100644
--- a/src/main.h
+++ b/src/main.h
@@ -45,8 +45,8 @@
* different interfaces, which have different implementations for each server.
*/
-#define SMALL_VERSION "1.4.3.15"
-#define CHECK_VERSION "01.04.03.15"
+#define SMALL_VERSION "1.4.3.29"
+#define CHECK_VERSION "01.04.03.29"
#ifdef HAVE_CONFIG_H
#include "../config.h"
diff --git a/src/map.cpp b/src/map.cpp
index c86c51bce..b4112231d 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -42,6 +42,7 @@
#include "resources/resourcemanager.h"
#include "resources/subimage.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/mkdir.h"
#include "utils/physfstools.h"
@@ -98,8 +99,7 @@ TileAnimation::TileAnimation(Animation *const ani):
TileAnimation::~TileAnimation()
{
- delete mAnimation;
- mAnimation = nullptr;
+ delete2(mAnimation);
}
bool TileAnimation::update(const int ticks)
@@ -202,7 +202,6 @@ Map::~Map()
config.removeListeners(this);
CHECKLISTENERS
- // delete metadata, layers, tilesets and overlays
delete [] mMetaTiles;
for (int i = 0; i < NB_BLOCKTYPES; i++)
delete [] mOccupation[i];
@@ -218,20 +217,16 @@ Map::~Map()
delete_all(mForegrounds);
delete_all(mBackgrounds);
delete_all(mTileAnimations);
- delete mSpecialLayer;
- mSpecialLayer = nullptr;
- delete mTempLayer;
- mTempLayer = nullptr;
- delete mObjects;
- mObjects = nullptr;
+ delete2(mSpecialLayer);
+ delete2(mTempLayer);
+ delete2(mObjects);
delete_all(mMapPortals);
if (mAtlas)
{
mAtlas->decRef();
mAtlas = nullptr;
}
- delete mHeights;
- mHeights = nullptr;
+ delete2(mHeights);
}
void Map::optionChanged(const std::string &value)
diff --git a/src/maplayer.cpp b/src/maplayer.cpp
index 701fa9958..2db140d67 100644
--- a/src/maplayer.cpp
+++ b/src/maplayer.cpp
@@ -39,6 +39,7 @@
#include "gui/font.h"
#include "gui/gui.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "debug.h"
@@ -586,10 +587,7 @@ SpecialLayer::SpecialLayer(const int width, const int height) :
SpecialLayer::~SpecialLayer()
{
for (int f = 0; f < mWidth * mHeight; f ++)
- {
- delete mTiles[f];
- mTiles[f] = nullptr;
- }
+ delete2(mTiles[f])
delete [] mTiles;
}
diff --git a/src/net/charserverhandler.h b/src/net/charserverhandler.h
index 625bf57fc..095558cec 100644
--- a/src/net/charserverhandler.h
+++ b/src/net/charserverhandler.h
@@ -26,6 +26,8 @@
#include "being/localplayer.h"
#include "being/playerinfo.h"
+#include "utils/delete2.h"
+
#include <string>
#include <vector>
@@ -51,8 +53,7 @@ struct Character final
~Character()
{
- delete dummy;
- dummy = nullptr;
+ delete2(dummy);
}
int slot; /**< The index in the list of characters */
diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp
index 997e4bfc1..4ae292860 100644
--- a/src/net/ea/chathandler.cpp
+++ b/src/net/ea/chathandler.cpp
@@ -389,6 +389,7 @@ void ChatHandler::processChat(Net::MessageIn &msg, const bool normalChat,
mMotdTime = cur_time + 1;
else if (mMotdTime == cur_time || mMotdTime < cur_time)
mSkipping = false;
+ BLOCK_END("ChatHandler::processChat")
return;
}
diff --git a/src/net/ea/guildhandler.cpp b/src/net/ea/guildhandler.cpp
index 1e56ac75b..fc1ef8def 100644
--- a/src/net/ea/guildhandler.cpp
+++ b/src/net/ea/guildhandler.cpp
@@ -34,6 +34,8 @@
#include "net/ea/gui/guildtab.h"
+#include "utils/delete2.h"
+
#include "debug.h"
namespace Ea
@@ -48,8 +50,7 @@ GuildHandler::GuildHandler() :
GuildHandler::~GuildHandler()
{
- delete guildTab;
- guildTab = nullptr;
+ delete2(guildTab);
}
void GuildHandler::requestAlliance(const int guildId A_UNUSED,
@@ -462,8 +463,7 @@ void GuildHandler::processGuildLeave(Net::MessageIn &msg) const
taGuild->clearMembers();
}
NotifyManager::notify(NotifyManager::GUILD_LEFT);
- delete guildTab;
- guildTab = nullptr;
+ delete2(guildTab)
if (socialWindow && taGuild)
socialWindow->removeTab(taGuild);
@@ -506,8 +506,7 @@ void GuildHandler::processGuildExpulsion(Net::MessageIn &msg) const
taGuild->clearMembers();
}
NotifyManager::notify(NotifyManager::GUILD_KICKED);
- delete guildTab;
- guildTab = nullptr;
+ delete2(guildTab)
if (socialWindow && taGuild)
socialWindow->removeTab(taGuild);
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp
index 2262a79f9..f3c8040e1 100644
--- a/src/net/ea/inventoryhandler.cpp
+++ b/src/net/ea/inventoryhandler.cpp
@@ -33,6 +33,8 @@
#include "net/ea/eaprotocol.h"
+#include "utils/delete2.h"
+
#include "debug.h"
extern int serverVersion;
@@ -95,14 +97,12 @@ InventoryHandler::~InventoryHandler()
mStorageWindow = nullptr;
}
- delete mStorage;
- mStorage = nullptr;
+ delete2(mStorage);
}
void InventoryHandler::clear()
{
- delete mStorage;
- mStorage = nullptr;
+ delete2(mStorage);
}
bool InventoryHandler::canSplit(const Item *const item A_UNUSED) const
@@ -491,8 +491,7 @@ void InventoryHandler::processPlayerStorageClose(Net::MessageIn &msg A_UNUSED)
if (mStorage)
mStorage->clear();
- delete mStorage;
- mStorage = nullptr;
+ delete2(mStorage);
}
void InventoryHandler::processPlayerEquipment(Net::MessageIn &msg)
diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp
index 4e4cac3df..32b08046e 100644
--- a/src/net/ea/partyhandler.cpp
+++ b/src/net/ea/partyhandler.cpp
@@ -35,6 +35,8 @@
#include "net/ea/gui/partytab.h"
+#include "utils/delete2.h"
+
#include "debug.h"
namespace Ea
@@ -52,8 +54,7 @@ PartyHandler::PartyHandler() :
PartyHandler::~PartyHandler()
{
- delete partyTab;
- partyTab = nullptr;
+ delete2(partyTab);
}
void PartyHandler::join(const int partyId A_UNUSED) const
@@ -347,8 +348,7 @@ void PartyHandler::processPartyLeave(Net::MessageIn &msg) const
Ea::taParty->clearMembers();
}
NotifyManager::notify(NotifyManager::PARTY_LEFT);
- delete Ea::partyTab;
- Ea::partyTab = nullptr;
+ delete2(Ea::partyTab)
if (socialWindow && Ea::taParty)
socialWindow->removeTab(Ea::taParty);
diff --git a/src/net/eathena/generalhandler.cpp b/src/net/eathena/generalhandler.cpp
index 3a18dede9..92afd945c 100644
--- a/src/net/eathena/generalhandler.cpp
+++ b/src/net/eathena/generalhandler.cpp
@@ -105,8 +105,7 @@ GeneralHandler::GeneralHandler() :
GeneralHandler::~GeneralHandler()
{
- delete mNetwork;
- mNetwork = nullptr;
+ delete2(mNetwork);
}
void GeneralHandler::handleMessage(Net::MessageIn &msg)
@@ -272,11 +271,8 @@ void GeneralHandler::gameEnded() const
socialWindow->removeTab(Ea::taParty);
}
- delete Ea::guildTab;
- Ea::guildTab = nullptr;
-
- delete Ea::partyTab;
- Ea::partyTab = nullptr;
+ delete2(Ea::guildTab);
+ delete2(Ea::partyTab);
}
} // namespace EAthena
diff --git a/src/net/eathena/network.cpp b/src/net/eathena/network.cpp
index 0162d82e8..87d5d4b5a 100644
--- a/src/net/eathena/network.cpp
+++ b/src/net/eathena/network.cpp
@@ -28,6 +28,8 @@
#include "net/eathena/messagein.h"
#include "net/eathena/protocol.h"
+#include "utils/delete2.h"
+
#include "debug.h"
namespace EAthena
@@ -120,8 +122,7 @@ Network::Network() :
Network::~Network()
{
clearHandlers();
- delete mMessageHandlers;
- mMessageHandlers = nullptr;
+ delete2(mMessageHandlers);
mInstance = nullptr;
}
diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp
index 46d1d490f..eef89324e 100644
--- a/src/net/tmwa/generalhandler.cpp
+++ b/src/net/tmwa/generalhandler.cpp
@@ -115,8 +115,7 @@ GeneralHandler::GeneralHandler() :
GeneralHandler::~GeneralHandler()
{
- delete mNetwork;
- mNetwork = nullptr;
+ delete2(mNetwork);
}
void GeneralHandler::handleMessage(Net::MessageIn &msg)
@@ -320,11 +319,8 @@ void GeneralHandler::gameEnded() const
socialWindow->removeTab(Ea::taParty);
}
- delete Ea::guildTab;
- Ea::guildTab = nullptr;
-
- delete Ea::partyTab;
- Ea::partyTab = nullptr;
+ delete2(Ea::guildTab);
+ delete2(Ea::partyTab);
}
} // namespace TmwAthena
diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp
index cc94b6161..b778d6b31 100644
--- a/src/net/tmwa/network.cpp
+++ b/src/net/tmwa/network.cpp
@@ -28,6 +28,8 @@
#include "net/tmwa/messagein.h"
#include "net/tmwa/protocol.h"
+#include "utils/delete2.h"
+
#include "debug.h"
namespace TmwAthena
@@ -98,8 +100,7 @@ Network::Network() :
Network::~Network()
{
clearHandlers();
- delete mMessageHandlers;
- mMessageHandlers = nullptr;
+ delete2(mMessageHandlers);
mInstance = nullptr;
}
diff --git a/src/particle/animationparticle.cpp b/src/particle/animationparticle.cpp
index 4381ceb8a..dccd3d037 100644
--- a/src/particle/animationparticle.cpp
+++ b/src/particle/animationparticle.cpp
@@ -24,6 +24,8 @@
#include "simpleanimation.h"
+#include "utils/delete2.h"
+
#include "debug.h"
AnimationParticle::AnimationParticle(Animation *const animation) :
@@ -41,8 +43,7 @@ AnimationParticle::AnimationParticle(XmlNodePtrConst animationNode,
AnimationParticle::~AnimationParticle()
{
- delete mAnimation;
- mAnimation = nullptr;
+ delete2(mAnimation);
mImage = nullptr;
}
diff --git a/src/particle/particlecontainer.cpp b/src/particle/particlecontainer.cpp
index 0c73d2762..07eb36dc4 100644
--- a/src/particle/particlecontainer.cpp
+++ b/src/particle/particlecontainer.cpp
@@ -23,6 +23,8 @@
#include "particle/particle.h"
#include "particle/particlecontainer.h"
+#include "utils/delete2.h"
+
#include "debug.h"
typedef std::list<Particle *>::iterator ParticleListIter;
@@ -40,10 +42,7 @@ ParticleContainer::~ParticleContainer()
// +++ call virtul method in destructor
clearLocally();
if (mDelParent)
- {
- delete mNext;
- mNext = nullptr;
- }
+ delete2(mNext)
}
void ParticleContainer::clear()
diff --git a/src/particle/rotationalparticle.cpp b/src/particle/rotationalparticle.cpp
index 2a1fe7904..976234f83 100644
--- a/src/particle/rotationalparticle.cpp
+++ b/src/particle/rotationalparticle.cpp
@@ -24,6 +24,8 @@
#include "simpleanimation.h"
+#include "utils/delete2.h"
+
#include <cmath>
#include "debug.h"
@@ -46,8 +48,7 @@ RotationalParticle::RotationalParticle(const XmlNodePtr animationNode,
RotationalParticle::~RotationalParticle()
{
- delete mAnimation;
- mAnimation = nullptr;
+ delete2(mAnimation);
mImage = nullptr;
}
diff --git a/src/particle/textparticle.cpp b/src/particle/textparticle.cpp
index 41ea683f6..9d37ca73d 100644
--- a/src/particle/textparticle.cpp
+++ b/src/particle/textparticle.cpp
@@ -80,7 +80,7 @@ void TextParticle::draw(Graphics *const graphics,
graphics->setColor(color);
if (mOutline)
{
- graphics->setColor2(Theme::getThemeColor(
+ graphics->setColor2(theme->getColor(
Theme::OUTLINE, static_cast<int>(alpha)));
}
mTextFont->drawString(graphics, mText, screenX - mTextWidth, screenY);
diff --git a/src/render/graphics.cpp b/src/render/graphics.cpp
index 17f444eb8..3a423aac2 100644
--- a/src/render/graphics.cpp
+++ b/src/render/graphics.cpp
@@ -129,7 +129,7 @@ Graphics::Graphics() :
Graphics::~Graphics()
{
- _endDraw();
+ endDraw();
#ifdef USE_SDL2
if (mRenderer)
{
@@ -470,7 +470,7 @@ bool Graphics::setFullscreen(const bool fs)
bool Graphics::resizeScreen(const int width, const int height)
{
#ifdef USE_SDL2
- _endDraw();
+ endDraw();
mRect.w = width / mScale;
mRect.h = height / mScale;
@@ -488,14 +488,14 @@ bool Graphics::resizeScreen(const int width, const int height)
// +++ need impliment resize in soft mode
#endif // USE_OPENGL
- _beginDraw();
+ beginDraw();
return true;
#else
const int prevWidth = mWidth;
const int prevHeight = mHeight;
- _endDraw();
+ endDraw();
const bool success = setVideoMode(width, height, mScale, mBpp,
mFullscreen, mHWAccel, mEnableResize, mNoFrame);
@@ -511,7 +511,7 @@ bool Graphics::resizeScreen(const int width, const int height)
}
}
- _beginDraw();
+ beginDraw();
return success;
#endif // USE_SDL2
diff --git a/src/render/graphics.h b/src/render/graphics.h
index 75b26a241..49080f4de 100644
--- a/src/render/graphics.h
+++ b/src/render/graphics.h
@@ -81,6 +81,7 @@
#endif
#include <stack>
+#include <string>
#include "localconsts.h"
@@ -461,21 +462,21 @@ class Graphics
* NOTE: You will never need to call this function yourself, unless
* you use a Graphics object outside of Guichan.
*
- * @see _endDraw, Gui::draw
+ * @see endDraw, Gui::draw
*/
- virtual void _beginDraw()
+ virtual void beginDraw()
{ }
/**
* Deinitializes drawing. Called by the Gui when a Gui::draw() is done.
- * done. It should reset any state changes made by _beginDraw().
+ * done. It should reset any state changes made by beginDraw().
*
* NOTE: You will never need to call this function yourself, unless
* you use a Graphics object outside of Guichan.
*
- * @see _beginDraw, Gui::draw
+ * @see beginDraw, Gui::draw
*/
- virtual void _endDraw()
+ virtual void endDraw()
{ }
int mWidth;
diff --git a/src/render/graphicsdef.hpp b/src/render/graphicsdef.hpp
index 80d3c7cf8..b11f88249 100644
--- a/src/render/graphicsdef.hpp
+++ b/src/render/graphicsdef.hpp
@@ -33,9 +33,9 @@ public:
const int x2, const int y2,
const int width, const int height) override final;
- void _beginDraw();
+ void beginDraw();
- void _endDraw();
+ void endDraw();
bool pushClipArea(Rect area) override final;
diff --git a/src/render/mobileopenglgraphics.cpp b/src/render/mobileopenglgraphics.cpp
index 86707fac8..0ad5bfeb7 100644
--- a/src/render/mobileopenglgraphics.cpp
+++ b/src/render/mobileopenglgraphics.cpp
@@ -113,10 +113,14 @@ void MobileOpenGLGraphics::initArrays()
// need alocate small size, after if limit reached reallocate to double size
const int sz = mMaxVertices * 4 + 30;
vertexBufSize = mMaxVertices;
- mFloatTexArray = new GLfloat[sz];
- mShortVertArray = new GLshort[sz];
- mFloatTexArrayCached = new GLfloat[sz];
- mShortVertArrayCached = new GLshort[sz];
+ if (!mFloatTexArray)
+ mFloatTexArray = new GLfloat[sz];
+ if (!mShortVertArray)
+ mShortVertArray = new GLshort[sz];
+ if (!mFloatTexArrayCached)
+ mFloatTexArrayCached = new GLfloat[sz];
+ if (!mShortVertArrayCached)
+ mShortVertArrayCached = new GLshort[sz];
}
bool MobileOpenGLGraphics::setVideoMode(const int w, const int h,
@@ -835,7 +839,7 @@ void MobileOpenGLGraphics::updateScreen()
BLOCK_END("Graphics::updateScreen")
}
-void MobileOpenGLGraphics::_beginDraw()
+void MobileOpenGLGraphics::beginDraw()
{
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
@@ -887,7 +891,7 @@ void MobileOpenGLGraphics::_beginDraw()
pushClipArea(Rect(0, 0, mRect.w, mRect.h));
}
-void MobileOpenGLGraphics::_endDraw()
+void MobileOpenGLGraphics::endDraw()
{
popClipArea();
}
diff --git a/src/render/normalopenglgraphics.cpp b/src/render/normalopenglgraphics.cpp
index 6bc25be32..72fbd8a99 100644
--- a/src/render/normalopenglgraphics.cpp
+++ b/src/render/normalopenglgraphics.cpp
@@ -131,12 +131,18 @@ void NormalOpenGLGraphics::initArrays()
// need alocate small size, after if limit reached reallocate to double size
vertexBufSize = mMaxVertices;
const int sz = mMaxVertices * 4 + 30;
- mFloatTexArray = new GLfloat[sz];
- mIntTexArray = new GLint[sz];
- mIntVertArray = new GLint[sz];
- mFloatTexArrayCached = new GLfloat[sz];
- mIntTexArrayCached = new GLint[sz];
- mIntVertArrayCached = new GLint[sz];
+ if (!mFloatTexArray)
+ mFloatTexArray = new GLfloat[sz];
+ if (!mIntTexArray)
+ mIntTexArray = new GLint[sz];
+ if (!mIntVertArray)
+ mIntVertArray = new GLint[sz];
+ if (!mFloatTexArrayCached)
+ mFloatTexArrayCached = new GLfloat[sz];
+ if (!mIntTexArrayCached)
+ mIntTexArrayCached = new GLint[sz];
+ if (!mIntVertArrayCached)
+ mIntVertArrayCached = new GLint[sz];
}
bool NormalOpenGLGraphics::setVideoMode(const int w, const int h,
@@ -1094,7 +1100,7 @@ void NormalOpenGLGraphics::updateScreen()
BLOCK_END("Graphics::updateScreen")
}
-void NormalOpenGLGraphics::_beginDraw()
+void NormalOpenGLGraphics::beginDraw()
{
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
@@ -1148,7 +1154,7 @@ void NormalOpenGLGraphics::_beginDraw()
pushClipArea(Rect(0, 0, w, h));
}
-void NormalOpenGLGraphics::_endDraw()
+void NormalOpenGLGraphics::endDraw()
{
popClipArea();
}
diff --git a/src/render/nullopenglgraphics.cpp b/src/render/nullopenglgraphics.cpp
index d09d7b13b..919b43c10 100644
--- a/src/render/nullopenglgraphics.cpp
+++ b/src/render/nullopenglgraphics.cpp
@@ -77,9 +77,12 @@ void NullOpenGLGraphics::initArrays()
// need alocate small size, after if limit reached reallocate to double size
vertexBufSize = mMaxVertices;
const int sz = mMaxVertices * 4 + 30;
- mFloatTexArray = new GLfloat[sz];
- mIntTexArray = new GLint[sz];
- mIntVertArray = new GLint[sz];
+ if (!mFloatTexArray)
+ mFloatTexArray = new GLfloat[sz];
+ if (!mIntTexArray)
+ mIntTexArray = new GLint[sz];
+ if (!mIntVertArray)
+ mIntVertArray = new GLint[sz];
}
bool NullOpenGLGraphics::setVideoMode(const int w, const int h,
@@ -916,12 +919,12 @@ void NullOpenGLGraphics::updateScreen()
BLOCK_END("Graphics::updateScreen")
}
-void NullOpenGLGraphics::_beginDraw()
+void NullOpenGLGraphics::beginDraw()
{
pushClipArea(Rect(0, 0, 640, 480));
}
-void NullOpenGLGraphics::_endDraw()
+void NullOpenGLGraphics::endDraw()
{
popClipArea();
}
diff --git a/src/render/safeopenglgraphics.cpp b/src/render/safeopenglgraphics.cpp
index faf2de76e..a191142b5 100644
--- a/src/render/safeopenglgraphics.cpp
+++ b/src/render/safeopenglgraphics.cpp
@@ -431,7 +431,7 @@ void SafeOpenGLGraphics::calcWindow(ImageCollection *const vertCol A_UNUSED,
{
}
-void SafeOpenGLGraphics::_beginDraw()
+void SafeOpenGLGraphics::beginDraw()
{
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
@@ -462,7 +462,7 @@ void SafeOpenGLGraphics::_beginDraw()
pushClipArea(Rect(0, 0, mRect.w, mRect.h));
}
-void SafeOpenGLGraphics::_endDraw()
+void SafeOpenGLGraphics::endDraw()
{
popClipArea();
}
diff --git a/src/render/sdl2graphics.cpp b/src/render/sdl2graphics.cpp
index 8c78c8cdd..c93622920 100644
--- a/src/render/sdl2graphics.cpp
+++ b/src/render/sdl2graphics.cpp
@@ -653,12 +653,12 @@ void SDLGraphics::fillRectangle(const Rect &rectangle)
SDL_RenderFillRects(mRenderer, &rect, 1);
}
-void SDLGraphics::_beginDraw()
+void SDLGraphics::beginDraw()
{
pushClipArea(Rect(0, 0, mRect.w, mRect.h));
}
-void SDLGraphics::_endDraw()
+void SDLGraphics::endDraw()
{
popClipArea();
}
diff --git a/src/render/sdl2softwaregraphics.cpp b/src/render/sdl2softwaregraphics.cpp
index 0844cd52e..54cd010a8 100644
--- a/src/render/sdl2softwaregraphics.cpp
+++ b/src/render/sdl2softwaregraphics.cpp
@@ -1115,12 +1115,12 @@ void SDL2SoftwareGraphics::fillRectangle(const Rect &rectangle)
}
}
-void SDL2SoftwareGraphics::_beginDraw()
+void SDL2SoftwareGraphics::beginDraw()
{
pushClipArea(Rect(0, 0, mRect.w, mRect.h));
}
-void SDL2SoftwareGraphics::_endDraw()
+void SDL2SoftwareGraphics::endDraw()
{
popClipArea();
}
diff --git a/src/render/sdlgraphics.cpp b/src/render/sdlgraphics.cpp
index 44dcc426d..cbd3f0689 100644
--- a/src/render/sdlgraphics.cpp
+++ b/src/render/sdlgraphics.cpp
@@ -1112,12 +1112,12 @@ void SDLGraphics::fillRectangle(const Rect& rectangle)
}
}
-void SDLGraphics::_beginDraw()
+void SDLGraphics::beginDraw()
{
pushClipArea(Rect(0, 0, mRect.w, mRect.h));
}
-void SDLGraphics::_endDraw()
+void SDLGraphics::endDraw()
{
popClipArea();
}
diff --git a/src/render/surfacegraphics.h b/src/render/surfacegraphics.h
index 8e85356da..44c2691ae 100644
--- a/src/render/surfacegraphics.h
+++ b/src/render/surfacegraphics.h
@@ -57,10 +57,10 @@ class SurfaceGraphics final : public Graphics
SDL_Surface *getTarget() const
{ return mTarget; }
- void _beginDraw() override final
+ void beginDraw() override final
{ }
- void _endDraw() override final
+ void endDraw() override final
{ }
bool pushClipArea(Rect rect A_UNUSED) override final
diff --git a/src/resources/atlasmanager.cpp b/src/resources/atlasmanager.cpp
index 870de40a9..90aea108d 100644
--- a/src/resources/atlasmanager.cpp
+++ b/src/resources/atlasmanager.cpp
@@ -231,7 +231,7 @@ SDL_Surface *AtlasManager::createSDLAtlas(TextureAtlas *const atlas)
SurfaceGraphics *const graphics = new SurfaceGraphics();
graphics->setTarget(surface);
- graphics->_beginDraw();
+ graphics->beginDraw();
// drawing SDL images to surface
FOR_EACH (std::vector<AtlasItem*>::iterator, it, atlas->items)
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp
index 40ea7af1a..8b76d7e2a 100644
--- a/src/resources/beinginfo.cpp
+++ b/src/resources/beinginfo.cpp
@@ -25,6 +25,7 @@
#include "configuration.h"
#include "logger.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -168,10 +169,8 @@ void BeingInfo::addAttack(const int id, std::string action,
void BeingInfo::clear()
{
- delete unknown;
- unknown = nullptr;
- delete empty;
- empty = nullptr;
+ delete2(unknown);
+ delete2(empty);
}
void BeingInfo::init()
diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp
index 931377639..09a5ce08f 100644
--- a/src/resources/db/itemdb.cpp
+++ b/src/resources/db/itemdb.cpp
@@ -28,6 +28,7 @@
#include "resources/beingcommon.h"
#include "resources/iteminfo.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -543,8 +544,7 @@ void ItemDB::unload()
{
logger->log1("Unloading item database...");
- delete mUnknown;
- mUnknown = nullptr;
+ delete2(mUnknown);
delete_all(mItemInfos);
mItemInfos.clear();
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp
index 4f9e8a738..7e6692c50 100644
--- a/src/resources/dye.cpp
+++ b/src/resources/dye.cpp
@@ -26,6 +26,8 @@
#include "resources/db/palettedb.h"
+#include "utils/delete2.h"
+
#include <cmath>
#include <sstream>
@@ -442,10 +444,7 @@ Dye::Dye(const std::string &description)
Dye::~Dye()
{
for (int i = 0; i < dyePalateSize; ++i)
- {
- delete mDyePalettes[i];
- mDyePalettes[i] = nullptr;
- }
+ delete2(mDyePalettes[i])
}
void Dye::instantiate(std::string &restrict target,
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 4da901b09..baabbeaec 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -37,6 +37,7 @@
#include "resources/db/mapdb.h"
#include "utils/base64.h"
+#include "utils/delete2.h"
#include <iostream>
#include <zlib.h>
@@ -202,6 +203,7 @@ void MapReader::addLayerToList(const std::string &fileName)
return;
}
+ int cnt = 0;
for_each_xml_child_node(childNode, node)
{
if (!xmlNameEqual(childNode, "layer"))
@@ -213,8 +215,10 @@ void MapReader::addLayerToList(const std::string &fileName)
logger->log("found patch layer: " + name);
mKnownLayers[name] = childNode;
mKnownDocs.insert(doc);
+ cnt ++;
}
- delete doc;
+ if (!cnt)
+ delete doc;
}
Map *MapReader::readMap(const std::string &restrict filename,
@@ -974,14 +978,9 @@ Tileset *MapReader::readTileset(XmlNodePtr node,
}
if (ani->getLength() > 0)
- {
map->addAnimation(tileGID, new TileAnimation(ani));
- }
else
- {
- delete ani;
- ani = nullptr;
- }
+ delete2(ani)
}
}
}
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 954930b64..4eca5552e 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -37,6 +37,7 @@
#include "resources/soundeffect.h"
#include "resources/spritedef.h"
+#include "utils/delete2.h"
#include "utils/mkdir.h"
#include "utils/paths.h"
#include "utils/physfscheckutils.h"
@@ -953,8 +954,7 @@ void ResourceManager::deleteInstance()
}
}
#endif
- delete instance;
- instance = nullptr;
+ delete2(instance);
}
void *ResourceManager::loadFile(const std::string &fileName, int &fileSize)
diff --git a/src/shopitem.cpp b/src/shopitem.cpp
index 8ee8da670..45ab60e05 100644
--- a/src/shopitem.cpp
+++ b/src/shopitem.cpp
@@ -138,7 +138,6 @@ int ShopItem::sellCurrentDuplicate(const int quantity)
if (dupl->quantity == 0)
{
delete dupl;
- dupl = nullptr;
mDuplicates.pop();
}
return sellCount;
diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp
index 075c98c06..a2c765cb8 100644
--- a/src/simpleanimation.cpp
+++ b/src/simpleanimation.cpp
@@ -32,6 +32,8 @@
#include "resources/imageset.h"
#include "resources/resourcemanager.h"
+#include "utils/delete2.h"
+
#include "debug.h"
SimpleAnimation::SimpleAnimation(Animation *const animation) :
@@ -62,8 +64,7 @@ SimpleAnimation::SimpleAnimation(const XmlNodePtr animationNode,
SimpleAnimation::~SimpleAnimation()
{
- delete mAnimation;
- mAnimation = nullptr;
+ delete2(mAnimation);
if (mImageSet)
{
mImageSet->decRef();
diff --git a/src/statuseffect.cpp b/src/statuseffect.cpp
index 647c6dd99..fd9f60851 100644
--- a/src/statuseffect.cpp
+++ b/src/statuseffect.cpp
@@ -47,7 +47,8 @@ StatusEffect::StatusEffect() :
mParticleEffect(),
mIcon(),
mAction(),
- mPersistentParticleEffect(false)
+ mPersistentParticleEffect(false),
+ mIsPoison(false)
{
}
@@ -153,9 +154,9 @@ void StatusEffect::loadXmlFile(const std::string &fileName)
{
if (xmlNameEqual(node, "include"))
{
- const std::string name = XML::getProperty(node, "name", "");
- if (!name.empty())
- loadXmlFile(name);
+ const std::string incName = XML::getProperty(node, "name", "");
+ if (!incName.empty())
+ loadXmlFile(incName);
continue;
}
@@ -181,11 +182,14 @@ void StatusEffect::loadXmlFile(const std::string &fileName)
{
StatusEffect *startEffect = (*the_map)[1][index];
StatusEffect *endEffect = (*the_map)[0][index];
+ const std::string name = XML::getProperty(node, "name", "");
if (!startEffect)
startEffect = new StatusEffect;
if (!endEffect)
endEffect = new StatusEffect;
+ startEffect->mIsPoison =
+ (name == paths.getStringValue("poisonEffectName"));
startEffect->mMessage = XML::getProperty(
node, "start-message", "");
startEffect->mSFXEffect = XML::getProperty(
@@ -198,6 +202,7 @@ void StatusEffect::loadXmlFile(const std::string &fileName)
startEffect->mPersistentParticleEffect = (XML::getProperty(
node, "persistent-particle-effect", "no")) != "no";
+ endEffect->mIsPoison = startEffect->mIsPoison;
endEffect->mMessage = XML::getProperty(node, "end-message", "");
endEffect->mSFXEffect = XML::getProperty(node, "end-audio", "");
endEffect->mParticleEffect = XML::getProperty(
diff --git a/src/statuseffect.h b/src/statuseffect.h
index 8bb164820..e30d9d1bd 100644
--- a/src/statuseffect.h
+++ b/src/statuseffect.h
@@ -73,6 +73,8 @@ public:
bool particleEffectIsPersistent() const A_WARN_UNUSED
{ return mPersistentParticleEffect; }
+ bool isPoison() const A_WARN_UNUSED
+ { return mIsPoison; }
/**
* Retrieves a status effect.
@@ -118,6 +120,7 @@ private:
std::string mIcon;
std::string mAction;
bool mPersistentParticleEffect;
+ bool mIsPoison;
};
#endif // STATUSEFFECT_H
diff --git a/src/test/testmain.cpp b/src/test/testmain.cpp
index fadeb206e..fbd7588ef 100644
--- a/src/test/testmain.cpp
+++ b/src/test/testmain.cpp
@@ -25,6 +25,7 @@
#include "client.h"
+#include "utils/delete2.h"
#include "utils/paths.h"
#include "utils/process.h"
@@ -46,8 +47,7 @@ TestMain::TestMain() :
TestMain::~TestMain()
{
- delete log;
- log = nullptr;
+ delete2(log);
}
void TestMain::initConfig()
diff --git a/src/text.cpp b/src/text.cpp
index 27d794d33..542dc60d9 100644
--- a/src/text.cpp
+++ b/src/text.cpp
@@ -32,6 +32,8 @@
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
int Text::mInstances = 0;
@@ -49,15 +51,15 @@ Text::Text(const std::string &text, const int x, const int y,
mXOffset(0),
mText(text),
mColor(color),
- mOutlineColor(Theme::getThemeColor(Theme::OUTLINE)),
+ mOutlineColor(theme->getColor(Theme::OUTLINE, 255)),
mIsSpeech(isSpeech)
{
if (!textManager)
{
textManager = new TextManager;
- if (Theme::instance())
+ if (theme)
{
- Theme::instance()->loadRect(mBubble, "bubble.xml", "");
+ theme->loadRect(mBubble, "bubble.xml", "");
}
else
{
@@ -99,8 +101,7 @@ Text::~Text()
textManager->removeText(this);
if (--mInstances == 0)
{
- delete textManager;
- textManager = nullptr;
+ delete2(textManager);
for (int f = 0; f < 9; f ++)
{
if (mBubble.grid[f])
diff --git a/src/touchmanager.cpp b/src/touchmanager.cpp
index b1ed41fdc..d1c29999c 100644
--- a/src/touchmanager.cpp
+++ b/src/touchmanager.cpp
@@ -37,6 +37,8 @@
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
TouchManager touchManager;
@@ -70,8 +72,7 @@ TouchManager::TouchManager() :
TouchManager::~TouchManager()
{
clear();
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
CHECKLISTENERS
}
@@ -122,7 +123,6 @@ void TouchManager::loadTouchItem(TouchItem **item, const std::string &name,
const TouchFuncPtr fOut)
{
*item = nullptr;
- Theme *const theme = Theme::instance();
if (!theme)
return;
ImageRect *images = new ImageRect;
@@ -243,8 +243,8 @@ void TouchManager::draw()
return;
Font *const font = boldFont;
- mainGraphics->setColorAll(Theme::getThemeColor(Theme::TEXT),
- Theme::getThemeColor(Theme::TEXT_OUTLINE));
+ mainGraphics->setColorAll(theme->getColor(Theme::TEXT, 255),
+ theme->getColor(Theme::TEXT_OUTLINE, 255));
FOR_EACH (TouchItemVectorCIter, it, mObjects)
{
const TouchItem *const item = *it;
@@ -358,8 +358,7 @@ void TouchManager::unload(TouchItem *const item)
if (item->images)
{
Theme::unloadRect(*item->images);
- delete item->images;
- item->images = nullptr;
+ delete2(item->images);
if (item->icon)
{
item->icon->decRef();
@@ -394,7 +393,6 @@ void TouchManager::loadPad()
void TouchManager::loadButtons()
{
const int sz = (mButtonsSize + 1) * 50;
- Theme *const theme = Theme::instance();
if (!theme)
return;
Skin *const skin = theme->load("dbutton.xml", "");
diff --git a/src/utils/delete2.h b/src/utils/delete2.h
new file mode 100644
index 000000000..104f6fa60
--- /dev/null
+++ b/src/utils/delete2.h
@@ -0,0 +1,30 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * 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
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UTILS_DELETE2_H
+#define UTILS_DELETE2_H
+
+#define delete2(var) \
+ {\
+ delete var;\
+ var = nullptr;\
+ }
+
+#endif // UTILS_DELETE2_H
diff --git a/src/utils/translation/translationmanager.cpp b/src/utils/translation/translationmanager.cpp
index 893e4d33f..9bbdec810 100644
--- a/src/utils/translation/translationmanager.cpp
+++ b/src/utils/translation/translationmanager.cpp
@@ -20,6 +20,7 @@
#include "utils/translation/translationmanager.h"
+#include "utils/delete2.h"
#include "utils/stringutils.h"
#include "utils/translation/podict.h"
@@ -46,8 +47,7 @@ void TranslationManager::loadCurrentLang()
void TranslationManager::close()
{
- delete translator;
- translator = nullptr;
+ delete2(translator);
}
PoDict *TranslationManager::loadLang(const LangVect &lang,