summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/widgets')
-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
79 files changed, 753 insertions, 899 deletions
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