summaryrefslogtreecommitdiff
path: root/src/gui/widgets
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-10-10 22:14:45 +0300
committerAndrei Karas <akaras@inbox.ru>2017-10-10 22:15:57 +0300
commitaa3f63fd497558a02feb3ddbc44f31eac091f39b (patch)
tree0e28b9b1f0501dd8be9e1a38db4ec1777fa3fbfa /src/gui/widgets
parent7c10a6b61e9d06a4ae9cc9f942dfacb6fcfd9d3d (diff)
downloadmanaverse-aa3f63fd497558a02feb3ddbc44f31eac091f39b.tar.gz
manaverse-aa3f63fd497558a02feb3ddbc44f31eac091f39b.tar.bz2
manaverse-aa3f63fd497558a02feb3ddbc44f31eac091f39b.tar.xz
manaverse-aa3f63fd497558a02feb3ddbc44f31eac091f39b.zip
Remove most unused files.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r--src/gui/widgets/attrs/attrdisplay.cpp67
-rw-r--r--src/gui/widgets/attrs/attrdisplay.h82
-rw-r--r--src/gui/widgets/attrs/changedisplay.cpp119
-rw-r--r--src/gui/widgets/attrs/changedisplay.h61
-rw-r--r--src/gui/widgets/attrs/derdisplay.cpp40
-rw-r--r--src/gui/widgets/attrs/derdisplay.h44
-rw-r--r--src/gui/widgets/avatarlistbox.cpp740
-rw-r--r--src/gui/widgets/avatarlistbox.h64
-rw-r--r--src/gui/widgets/basiccontainer.cpp439
-rw-r--r--src/gui/widgets/basiccontainer.h213
-rw-r--r--src/gui/widgets/basiccontainer2.cpp128
-rw-r--r--src/gui/widgets/basiccontainer2.h153
-rw-r--r--src/gui/widgets/browserbox.cpp936
-rw-r--r--src/gui/widgets/browserbox.h210
-rw-r--r--src/gui/widgets/browserbox.inc30
-rw-r--r--src/gui/widgets/button.cpp934
-rw-r--r--src/gui/widgets/button.h347
-rw-r--r--src/gui/widgets/characterdisplay.cpp160
-rw-r--r--src/gui/widgets/characterdisplay.h93
-rw-r--r--src/gui/widgets/characterviewbase.h63
-rw-r--r--src/gui/widgets/characterviewnormal.cpp121
-rw-r--r--src/gui/widgets/characterviewnormal.h50
-rw-r--r--src/gui/widgets/characterviewsmall.cpp136
-rw-r--r--src/gui/widgets/characterviewsmall.h54
-rw-r--r--src/gui/widgets/chatinput.h105
-rw-r--r--src/gui/widgets/checkbox.cpp338
-rw-r--r--src/gui/widgets/checkbox.h216
-rw-r--r--src/gui/widgets/colorpage.cpp124
-rw-r--r--src/gui/widgets/colorpage.h48
-rw-r--r--src/gui/widgets/container.cpp60
-rw-r--r--src/gui/widgets/container.h51
-rw-r--r--src/gui/widgets/containerplacer.cpp44
-rw-r--r--src/gui/widgets/containerplacer.h73
-rw-r--r--src/gui/widgets/createwidget.h41
-rw-r--r--src/gui/widgets/desktop.cpp229
-rw-r--r--src/gui/widgets/desktop.h88
-rw-r--r--src/gui/widgets/dropdown.cpp580
-rw-r--r--src/gui/widgets/dropdown.h166
-rw-r--r--src/gui/widgets/emotepage.cpp167
-rw-r--r--src/gui/widgets/emotepage.h67
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp297
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.h92
-rw-r--r--src/gui/widgets/equipmentbox.h41
-rw-r--r--src/gui/widgets/equipmentpage.h53
-rw-r--r--src/gui/widgets/extendedlistbox.cpp257
-rw-r--r--src/gui/widgets/extendedlistbox.h61
-rw-r--r--src/gui/widgets/extendedlistboxitem.h49
-rw-r--r--src/gui/widgets/flowcontainer.cpp97
-rw-r--r--src/gui/widgets/flowcontainer.h75
-rw-r--r--src/gui/widgets/guitable.cpp675
-rw-r--r--src/gui/widgets/guitable.h207
-rw-r--r--src/gui/widgets/horizontcontainer.cpp66
-rw-r--r--src/gui/widgets/horizontcontainer.h62
-rw-r--r--src/gui/widgets/icon.cpp105
-rw-r--r--src/gui/widgets/icon.h83
-rw-r--r--src/gui/widgets/inttextfield.cpp148
-rw-r--r--src/gui/widgets/inttextfield.h85
-rw-r--r--src/gui/widgets/itemcontainer.cpp1322
-rw-r--r--src/gui/widgets/itemcontainer.h223
-rw-r--r--src/gui/widgets/itemlinkhandler.cpp223
-rw-r--r--src/gui/widgets/itemlinkhandler.h61
-rw-r--r--src/gui/widgets/itemshortcutcontainer.cpp650
-rw-r--r--src/gui/widgets/itemshortcutcontainer.h89
-rw-r--r--src/gui/widgets/label.cpp292
-rw-r--r--src/gui/widgets/label.h195
-rw-r--r--src/gui/widgets/layout.cpp46
-rw-r--r--src/gui/widgets/layout.h66
-rw-r--r--src/gui/widgets/layoutarray.cpp313
-rw-r--r--src/gui/widgets/layoutarray.h127
-rw-r--r--src/gui/widgets/layoutcell.cpp136
-rw-r--r--src/gui/widgets/layoutcell.h196
-rw-r--r--src/gui/widgets/layouthelper.cpp79
-rw-r--r--src/gui/widgets/layouthelper.h91
-rw-r--r--src/gui/widgets/linepart.cpp33
-rw-r--r--src/gui/widgets/linepart.h102
-rw-r--r--src/gui/widgets/linkhandler.h49
-rw-r--r--src/gui/widgets/listbox.cpp446
-rw-r--r--src/gui/widgets/listbox.h296
-rw-r--r--src/gui/widgets/passwordfield.cpp55
-rw-r--r--src/gui/widgets/passwordfield.h55
-rw-r--r--src/gui/widgets/playerbox.cpp190
-rw-r--r--src/gui/widgets/playerbox.h112
-rw-r--r--src/gui/widgets/popup.cpp273
-rw-r--r--src/gui/widgets/popup.h193
-rw-r--r--src/gui/widgets/popuplist.cpp188
-rw-r--r--src/gui/widgets/popuplist.h84
-rw-r--r--src/gui/widgets/progressbar.cpp376
-rw-r--r--src/gui/widgets/progressbar.h166
-rw-r--r--src/gui/widgets/progressindicator.cpp98
-rw-r--r--src/gui/widgets/progressindicator.h54
-rw-r--r--src/gui/widgets/radiobutton.cpp373
-rw-r--r--src/gui/widgets/radiobutton.h247
-rw-r--r--src/gui/widgets/radiogroup.cpp41
-rw-r--r--src/gui/widgets/radiogroup.h41
-rw-r--r--src/gui/widgets/scrollarea.cpp1460
-rw-r--r--src/gui/widgets/scrollarea.h598
-rw-r--r--src/gui/widgets/selldialog.cpp397
-rw-r--r--src/gui/widgets/selldialog.h156
-rw-r--r--src/gui/widgets/serverslistbox.h159
-rw-r--r--src/gui/widgets/setupbuttonitem.cpp95
-rw-r--r--src/gui/widgets/setupbuttonitem.h69
-rw-r--r--src/gui/widgets/setupitem.cpp1338
-rw-r--r--src/gui/widgets/setupitem.h613
-rw-r--r--src/gui/widgets/setupquickitem.cpp117
-rw-r--r--src/gui/widgets/setupquickitem.h80
-rw-r--r--src/gui/widgets/setuptouchitem.cpp132
-rw-r--r--src/gui/widgets/setuptouchitem.h67
-rw-r--r--src/gui/widgets/shoplistbox.cpp310
-rw-r--r--src/gui/widgets/shoplistbox.h113
-rw-r--r--src/gui/widgets/shortcutcontainer.cpp159
-rw-r--r--src/gui/widgets/shortcutcontainer.h120
-rw-r--r--src/gui/widgets/skilllistbox.h290
-rw-r--r--src/gui/widgets/skillrectanglelistbox.h418
-rw-r--r--src/gui/widgets/slider.cpp517
-rw-r--r--src/gui/widgets/slider.h337
-rw-r--r--src/gui/widgets/sliderlist.cpp240
-rw-r--r--src/gui/widgets/sliderlist.h89
-rw-r--r--src/gui/widgets/spellshortcutcontainer.cpp371
-rw-r--r--src/gui/widgets/spellshortcutcontainer.h86
-rw-r--r--src/gui/widgets/staticbrowserbox.cpp781
-rw-r--r--src/gui/widgets/staticbrowserbox.h194
-rw-r--r--src/gui/widgets/statspage.cpp88
-rw-r--r--src/gui/widgets/statspage.h61
-rw-r--r--src/gui/widgets/statspagebasic.cpp163
-rw-r--r--src/gui/widgets/statspagebasic.h67
-rw-r--r--src/gui/widgets/tabbedarea.cpp827
-rw-r--r--src/gui/widgets/tabbedarea.h299
-rw-r--r--src/gui/widgets/tabs/chat/battletab.cpp44
-rw-r--r--src/gui/widgets/tabs/chat/battletab.h43
-rw-r--r--src/gui/widgets/tabs/chat/channeltab.cpp77
-rw-r--r--src/gui/widgets/tabs/chat/channeltab.h51
-rw-r--r--src/gui/widgets/tabs/chat/chattab.cpp563
-rw-r--r--src/gui/widgets/tabs/chat/chattab.h216
-rw-r--r--src/gui/widgets/tabs/chat/emulateguildtab.cpp108
-rw-r--r--src/gui/widgets/tabs/chat/emulateguildtab.h59
-rw-r--r--src/gui/widgets/tabs/chat/gmtab.cpp57
-rw-r--r--src/gui/widgets/tabs/chat/gmtab.h49
-rw-r--r--src/gui/widgets/tabs/chat/guildtab.cpp125
-rw-r--r--src/gui/widgets/tabs/chat/guildtab.h56
-rw-r--r--src/gui/widgets/tabs/chat/langtab.cpp38
-rw-r--r--src/gui/widgets/tabs/chat/langtab.h39
-rw-r--r--src/gui/widgets/tabs/chat/partytab.cpp151
-rw-r--r--src/gui/widgets/tabs/chat/partytab.h58
-rw-r--r--src/gui/widgets/tabs/chat/tradetab.cpp50
-rw-r--r--src/gui/widgets/tabs/chat/tradetab.h46
-rw-r--r--src/gui/widgets/tabs/chat/whispertab.cpp130
-rw-r--r--src/gui/widgets/tabs/chat/whispertab.h73
-rw-r--r--src/gui/widgets/tabs/debugwindowtabs.cpp492
-rw-r--r--src/gui/widgets/tabs/debugwindowtabs.h129
-rw-r--r--src/gui/widgets/tabs/setup_audio.cpp214
-rw-r--r--src/gui/widgets/tabs/setup_audio.h47
-rw-r--r--src/gui/widgets/tabs/setup_chat.cpp347
-rw-r--r--src/gui/widgets/tabs/setup_chat.h40
-rw-r--r--src/gui/widgets/tabs/setup_colors.cpp491
-rw-r--r--src/gui/widgets/tabs/setup_colors.h91
-rw-r--r--src/gui/widgets/tabs/setup_input.cpp399
-rw-r--r--src/gui/widgets/tabs/setup_input.h105
-rw-r--r--src/gui/widgets/tabs/setup_joystick.cpp184
-rw-r--r--src/gui/widgets/tabs/setup_joystick.h62
-rw-r--r--src/gui/widgets/tabs/setup_misc.cpp518
-rw-r--r--src/gui/widgets/tabs/setup_misc.h52
-rw-r--r--src/gui/widgets/tabs/setup_mods.cpp129
-rw-r--r--src/gui/widgets/tabs/setup_mods.h50
-rw-r--r--src/gui/widgets/tabs/setup_perfomance.cpp209
-rw-r--r--src/gui/widgets/tabs/setup_perfomance.h46
-rw-r--r--src/gui/widgets/tabs/setup_players.cpp211
-rw-r--r--src/gui/widgets/tabs/setup_players.h49
-rw-r--r--src/gui/widgets/tabs/setup_quick.cpp118
-rw-r--r--src/gui/widgets/tabs/setup_quick.h45
-rw-r--r--src/gui/widgets/tabs/setup_relations.cpp266
-rw-r--r--src/gui/widgets/tabs/setup_relations.h79
-rw-r--r--src/gui/widgets/tabs/setup_theme.cpp415
-rw-r--r--src/gui/widgets/tabs/setup_theme.h113
-rw-r--r--src/gui/widgets/tabs/setup_touch.cpp134
-rw-r--r--src/gui/widgets/tabs/setup_touch.h44
-rw-r--r--src/gui/widgets/tabs/setup_video.cpp534
-rw-r--r--src/gui/widgets/tabs/setup_video.h88
-rw-r--r--src/gui/widgets/tabs/setup_visual.cpp252
-rw-r--r--src/gui/widgets/tabs/setup_visual.h51
-rw-r--r--src/gui/widgets/tabs/setuptab.cpp44
-rw-r--r--src/gui/widgets/tabs/setuptab.h74
-rw-r--r--src/gui/widgets/tabs/setuptabscroll.cpp163
-rw-r--r--src/gui/widgets/tabs/setuptabscroll.h81
-rw-r--r--src/gui/widgets/tabs/shortcuttab.h47
-rw-r--r--src/gui/widgets/tabs/skilltab.h88
-rw-r--r--src/gui/widgets/tabs/socialattacktab.h77
-rw-r--r--src/gui/widgets/tabs/socialfriendsfunctor.h59
-rw-r--r--src/gui/widgets/tabs/socialfriendstab.h127
-rw-r--r--src/gui/widgets/tabs/socialguildtab.h179
-rw-r--r--src/gui/widgets/tabs/socialguildtab2.h106
-rw-r--r--src/gui/widgets/tabs/socialnavigationtab.h308
-rw-r--r--src/gui/widgets/tabs/socialpartytab.h171
-rw-r--r--src/gui/widgets/tabs/socialpickuptab.h75
-rw-r--r--src/gui/widgets/tabs/socialplayerstab.h198
-rw-r--r--src/gui/widgets/tabs/socialtab.h143
-rw-r--r--src/gui/widgets/tabs/socialtabbase.h84
-rw-r--r--src/gui/widgets/tabs/tab.cpp488
-rw-r--r--src/gui/widgets/tabs/tab.h245
-rw-r--r--src/gui/widgets/tabstrip.cpp124
-rw-r--r--src/gui/widgets/tabstrip.h57
-rw-r--r--src/gui/widgets/textbox.cpp647
-rw-r--r--src/gui/widgets/textbox.h329
-rw-r--r--src/gui/widgets/textfield.cpp837
-rw-r--r--src/gui/widgets/textfield.h293
-rw-r--r--src/gui/widgets/textpreview.cpp151
-rw-r--r--src/gui/widgets/textpreview.h144
-rw-r--r--src/gui/widgets/vertcontainer.cpp89
-rw-r--r--src/gui/widgets/vertcontainer.h66
-rw-r--r--src/gui/widgets/virtshortcutcontainer.cpp383
-rw-r--r--src/gui/widgets/virtshortcutcontainer.h92
-rw-r--r--src/gui/widgets/widget.cpp526
-rw-r--r--src/gui/widgets/widget.h1181
-rw-r--r--src/gui/widgets/widget2.h117
-rw-r--r--src/gui/widgets/widgetgroup.cpp87
-rw-r--r--src/gui/widgets/widgetgroup.h69
-rw-r--r--src/gui/widgets/window.cpp1499
-rw-r--r--src/gui/widgets/window.h725
-rw-r--r--src/gui/widgets/windowcontainer.cpp105
-rw-r--r--src/gui/widgets/windowcontainer.h74
219 files changed, 0 insertions, 46915 deletions
diff --git a/src/gui/widgets/attrs/attrdisplay.cpp b/src/gui/widgets/attrs/attrdisplay.cpp
deleted file mode 100644
index 3b91fef9d..000000000
--- a/src/gui/widgets/attrs/attrdisplay.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/attrs/attrdisplay.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/widgets/layouthelper.h"
-
-#include "utils/delete2.h"
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-AttrDisplay::AttrDisplay(const Widget2 *const widget,
- const AttributesT id,
- const std::string &restrict name,
- const std::string &restrict shortName) :
- Container(widget),
- mId(id),
- mName(name),
- mShortName(shortName),
- mLayout(new LayoutHelper(this)),
- mLabel(new Label(this, name)),
- mValue(new Label(this, "1 "))
-{
- setSize(100, 32);
-
- setSelectable(false);
- mLabel->setAlignment(Graphics::CENTER);
- mValue->setAlignment(Graphics::CENTER);
-}
-
-AttrDisplay::~AttrDisplay()
-{
- delete2(mLayout);
-}
-
-std::string AttrDisplay::update()
-{
- const int base = PlayerInfo::getStatBase(mId);
- const int bonus = PlayerInfo::getStatMod(mId);
- std::string value = toString(base + bonus);
- if (bonus != 0)
- value.append(strprintf("=%d%+d", base, bonus));
- mValue->setCaption(value);
- return mName;
-}
diff --git a/src/gui/widgets/attrs/attrdisplay.h b/src/gui/widgets/attrs/attrdisplay.h
deleted file mode 100644
index f682e41f5..000000000
--- a/src/gui/widgets/attrs/attrdisplay.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_ATTRS_ATTRDISPLAY_H
-#define GUI_WIDGETS_ATTRS_ATTRDISPLAY_H
-
-#include "enums/being/attributes.h"
-
-#include "gui/widgets/container.h"
-
-#include "gui/widgets/label.h"
-
-#include "localconsts.h"
-
-class LayoutHelper;
-
-class AttrDisplay notfinal : public Container
-{
- public:
- enum Type
- {
- DERIVED = 0,
- CHANGEABLE,
- UNKNOWN
- };
-
- A_DELETE_COPY(AttrDisplay)
-
- virtual ~AttrDisplay();
-
- virtual std::string update();
-
- virtual Type getType() const
- { return UNKNOWN; }
-
- std::string getValue() const
- {
- if (mValue == nullptr)
- return "-";
- return mValue->getCaption();
- }
-
- const std::string &getShortName() const
- { return mShortName; }
-
- protected:
- AttrDisplay(const Widget2 *const widget,
- const AttributesT id,
- const std::string &restrict name,
- const std::string &restrict shortName);
-
- const AttributesT mId;
- const std::string mName;
- const std::string mShortName;
-
- LayoutHelper *mLayout;
- Label *mLabel;
- Label *mValue;
-};
-
-typedef std::map<AttributesT, AttrDisplay*> Attrs;
-
-#endif // GUI_WIDGETS_ATTRS_ATTRDISPLAY_H
diff --git a/src/gui/widgets/attrs/changedisplay.cpp b/src/gui/widgets/attrs/changedisplay.cpp
deleted file mode 100644
index e1af1eb76..000000000
--- a/src/gui/widgets/attrs/changedisplay.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/attrs/changedisplay.h"
-
-#include "configuration.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-
-#include "net/net.h"
-#include "net/playerhandler.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-ChangeDisplay::ChangeDisplay(const Widget2 *const widget,
- const AttributesT id,
- const std::string &restrict name,
- const std::string &restrict shortName) :
- AttrDisplay(widget, id, name, shortName),
- ActionListener(),
- mNeeded(1),
- // TRANSLATORS: status window label
- mPoints(new Label(this, _("Max"))),
- // TRANSLATORS: status window label (plus sign)
- mInc(new Button(this, _("+"), "inc", this))
-{
- // Do the layout
- ContainerPlacer place = mLayout->getPlacer(0, 0);
-
- place(0, 0, mLabel, 3);
- place(4, 0, mValue, 2);
- place(6, 0, mInc);
- place(7, 0, mPoints);
-}
-
-std::string ChangeDisplay::update()
-{
- if (mNeeded > 0)
- {
- mPoints->setCaption(toString(mNeeded));
- }
- else
- {
- // TRANSLATORS: status bar label
- mPoints->setCaption(_("Max"));
- }
-
- mInc->setEnabled(PlayerInfo::getAttribute(Attributes::PLAYER_CHAR_POINTS)
- >= mNeeded && mNeeded > 0);
-
- return AttrDisplay::update();
-}
-
-void ChangeDisplay::setPointsNeeded(const int needed)
-{
- mNeeded = needed;
- update();
-}
-
-void ChangeDisplay::action(const ActionEvent &event)
-{
- if (event.getSource() == mInc)
- {
- int cnt = 1;
- if (config.getBoolValue("quickStats"))
- {
- cnt = mInc->getClickCount();
- if (cnt > 10)
- cnt = 10;
- }
-
- const int newpoints = PlayerInfo::getAttribute(
- Attributes::PLAYER_CHAR_POINTS) - cnt;
- PlayerInfo::setAttribute(Attributes::PLAYER_CHAR_POINTS,
- newpoints);
-
- const int newbase = PlayerInfo::getStatBase(mId) + cnt;
- PlayerInfo::setStatBase(mId, newbase);
-
- if (Net::getNetworkType() != ServerType::TMWATHENA)
- {
- playerHandler->increaseAttribute(mId, cnt);
- }
- else
- {
- for (int f = 0; f < cnt; f ++)
- {
- playerHandler->increaseAttribute(mId, 1);
- if (cnt != 1)
- SDL_Delay(100);
- }
- }
- }
-}
diff --git a/src/gui/widgets/attrs/changedisplay.h b/src/gui/widgets/attrs/changedisplay.h
deleted file mode 100644
index 4e9d1076d..000000000
--- a/src/gui/widgets/attrs/changedisplay.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_ATTRS_CHANGEDISPLAY_H
-#define GUI_WIDGETS_ATTRS_CHANGEDISPLAY_H
-
-#include "gui/widgets/attrs/attrdisplay.h"
-
-#include "listeners/actionlistener.h"
-
-#include "localconsts.h"
-
-class Button;
-
-class ChangeDisplay final : public AttrDisplay,
- public ActionListener
-{
- public:
- ChangeDisplay(const Widget2 *const widget,
- const AttributesT id,
- const std::string &restrict name,
- const std::string &restrict shortName);
-
- A_DELETE_COPY(ChangeDisplay)
-
- std::string update() override final;
-
- Type getType() const override final
- { return CHANGEABLE; }
-
- void setPointsNeeded(const int needed);
-
- void action(const ActionEvent &event) override final;
-
- private:
- int mNeeded;
-
- Label *mPoints;
- Button *mInc;
-};
-
-#endif // GUI_WIDGETS_ATTRS_CHANGEDISPLAY_H
diff --git a/src/gui/widgets/attrs/derdisplay.cpp b/src/gui/widgets/attrs/derdisplay.cpp
deleted file mode 100644
index 2c20c3713..000000000
--- a/src/gui/widgets/attrs/derdisplay.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/attrs/derdisplay.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-
-#include "debug.h"
-
-DerDisplay::DerDisplay(const Widget2 *const widget,
- const AttributesT id,
- const std::string &restrict name,
- const std::string &restrict shortName) :
- AttrDisplay(widget, id, name, shortName)
-{
- ContainerPlacer place = mLayout->getPlacer(0, 0);
-
- place(0, 0, mLabel, 3);
- place(3, 0, mValue, 2);
-}
diff --git a/src/gui/widgets/attrs/derdisplay.h b/src/gui/widgets/attrs/derdisplay.h
deleted file mode 100644
index 8b841694e..000000000
--- a/src/gui/widgets/attrs/derdisplay.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_ATTRS_DERDISPLAY_H
-#define GUI_WIDGETS_ATTRS_DERDISPLAY_H
-
-#include "gui/widgets/attrs/attrdisplay.h"
-
-#include "localconsts.h"
-
-class DerDisplay final : public AttrDisplay
-{
- public:
- DerDisplay(const Widget2 *const widget,
- const AttributesT id,
- const std::string &restrict name,
- const std::string &restrict shortName);
-
- A_DELETE_COPY(DerDisplay)
-
- Type getType() const override final
- { return DERIVED; }
-};
-
-#endif // GUI_WIDGETS_ATTRS_DERDISPLAY_H
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
deleted file mode 100644
index 383efb397..000000000
--- a/src/gui/widgets/avatarlistbox.cpp
+++ /dev/null
@@ -1,740 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/avatarlistbox.h"
-
-#include "actormanager.h"
-#include "configuration.h"
-
-#include "being/localplayer.h"
-
-#include "enums/resources/map/mapitemtype.h"
-
-#include "gui/gui.h"
-#include "gui/popupmanager.h"
-#include "gui/skin.h"
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/popups/popupmenu.h"
-
-#include "gui/models/avatarlistmodel.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "resources/image/image.h"
-
-#include "resources/map/map.h"
-
-#include "debug.h"
-
-int AvatarListBox::instances = 0;
-Image *AvatarListBox::onlineIcon = nullptr;
-Image *AvatarListBox::offlineIcon = nullptr;
-
-AvatarListBox::AvatarListBox(const Widget2 *const widget,
- AvatarListModel *const model) :
- ListBox(widget, model, "avatarlistbox.xml"),
- mImagePadding(mSkin != nullptr ? mSkin->getOption("imagePadding") : 0),
- mShowGender(config.getBoolValue("showgender")),
- mShowLevel(config.getBoolValue("showlevel"))
-{
- instances++;
-
- if (instances == 1)
- {
- onlineIcon = Theme::getImageFromThemeXml("circle-on.xml", "");
- offlineIcon = Theme::getImageFromThemeXml("circle-off.xml", "");
- }
-
- setWidth(200);
-
- config.addListener("showgender", this);
- config.addListener("showlevel", this);
-
- mForegroundColor = getThemeColor(ThemeColorId::TEXT);
- mForegroundColor2 = getThemeColor(ThemeColorId::TEXT_OUTLINE);
-}
-
-AvatarListBox::~AvatarListBox()
-{
- config.removeListeners(this);
- CHECKLISTENERS
-
- instances--;
-
- if (instances == 0)
- {
- if (onlineIcon != nullptr)
- {
- onlineIcon->decRef();
- onlineIcon = nullptr;
- }
- if (offlineIcon != nullptr)
- {
- offlineIcon->decRef();
- offlineIcon = nullptr;
- }
- }
-}
-
-void AvatarListBox::draw(Graphics *const graphics)
-{
- BLOCK_START("AvatarListBox::draw")
- if ((mListModel == nullptr) || (localPlayer == nullptr))
- {
- BLOCK_END("AvatarListBox::draw")
- return;
- }
-
- const Widget *const parent = mParent;
- if (parent == nullptr)
- return;
-
- AvatarListModel *const model = static_cast<AvatarListModel *>(
- mListModel);
- updateAlpha();
-
- Font *const font = getFont();
- const int fontHeight = font->getHeight();
- const int parentWidth = parent->getWidth();
- const std::string &name = localPlayer->getName();
-
- // Draw the list elements
- ImageCollection vertexes;
- const int num = model->getNumberOfElements();
- for (int i = 0, y = 0;
- i < num;
- ++i, y += fontHeight)
- {
- const Avatar *const a = model->getAvatarAt(i);
- if (a == nullptr)
- continue;
-
- const MapItemType::Type type = static_cast<MapItemType::Type>(
- a->getType());
- if (type != MapItemType::SEPARATOR)
- {
- // Draw online status
- const Image *const icon = a->getOnline()
- ? onlineIcon : offlineIcon;
- if (icon != nullptr)
- {
- graphics->calcTileCollection(&vertexes, icon,
- mImagePadding, y + mPadding);
- }
- }
- }
-
- graphics->finalize(&vertexes);
- graphics->drawTileCollection(&vertexes);
-
- for (int i = 0, y = 0;
- i < num;
- ++i, y += fontHeight)
- {
- const Avatar *const a = model->getAvatarAt(i);
- if (a == nullptr)
- continue;
-
- const MapItemType::Type type = static_cast<MapItemType::Type>(
- a->getType());
- std::string text;
-
- if (a->getMaxHp() > 0)
- {
- if (mShowLevel && a->getLevel() > 1)
- {
- text = strprintf("%s %d/%d (%d)", a->getComplexName().c_str(),
- a->getHp(), a->getMaxHp(), a->getLevel());
- }
- else
- {
- text = strprintf("%s %d/%d", a->getComplexName().c_str(),
- a->getHp(), a->getMaxHp());
- }
- const bool isPoison = a->getPoison();
- if (a->getMaxHp() != 0)
- {
- const ProgressColorIdT themeColor = (isPoison
- ? ProgressColorId::PROG_HP_POISON
- : ProgressColorId::PROG_HP);
- Color color = Theme::getProgressColor(
- themeColor, static_cast<float>(a->getHp())
- / static_cast<float>(a->getMaxHp()));
- color.a = 80;
- graphics->setColor(color);
- graphics->fillRectangle(Rect(mPadding, y + mPadding,
- parentWidth * a->getHp() / a->getMaxHp()
- - 2 * mPadding, fontHeight));
- }
- }
- else if (a->getDamageHp() != 0 && a->getName() != name)
- {
- if (mShowLevel && a->getLevel() > 1)
- {
- text = strprintf("%s -%d (%d)", a->getComplexName().c_str(),
- a->getDamageHp(), a->getLevel());
- }
- else
- {
- text = strprintf("%s -%d", a->getComplexName().c_str(),
- a->getDamageHp());
- }
-
- const ProgressColorIdT themeColor = (a->getPoison()
- ? ProgressColorId::PROG_HP_POISON : ProgressColorId::PROG_HP);
- Color color = Theme::getProgressColor(themeColor, 1);
- color.a = 80;
- graphics->setColor(color);
- graphics->fillRectangle(Rect(mPadding, y + mPadding,
- parentWidth * a->getDamageHp() / 1024
- - 2 * mPadding, fontHeight));
-
- if (a->getLevel() > 1)
- {
- graphics->setColor(mForegroundColor);
- int minHp = 40 + ((a->getLevel() - 1) * 5);
- if (minHp < 0)
- minHp = 40;
-
- graphics->drawLine(parentWidth * minHp / 1024
- + mPadding, y + mPadding,
- parentWidth * minHp / 1024, y + fontHeight);
- }
- }
- else
- {
- if (mShowLevel && a->getLevel() > 1)
- {
- text = strprintf("%s (%d)", a->getComplexName().c_str(),
- a->getLevel());
- }
- else
- {
- text = a->getComplexName();
- }
- }
-
- if (!a->getMap().empty())
- {
- if (a->getX() != -1)
- {
- text.append(strprintf(" [%d,%d %s]", a->getX(), a->getY(),
- a->getMap().c_str()));
- }
- else
- {
- text.append(strprintf(" [%s]", a->getMap().c_str()));
- }
- }
-
- if (graphics->getSecure())
- {
- if (mShowGender)
- {
- switch (a->getGender())
- {
- case Gender::FEMALE:
- text.append(" \u2640 ");
- break;
- case Gender::MALE:
- text.append(" \u2642 ");
- break;
- default:
- case Gender::UNSPECIFIED:
- case Gender::OTHER:
- break;
- }
- }
- }
- else
- {
- if (mShowGender)
- {
- switch (a->getGender())
- {
- case Gender::FEMALE:
- text.append(strprintf(" \u2640 %s",
- a->getAdditionString().c_str()));
- break;
- case Gender::MALE:
- text.append(strprintf(" \u2642 %s",
- a->getAdditionString().c_str()));
- break;
- default:
- case Gender::UNSPECIFIED:
- case Gender::OTHER:
- break;
- }
- }
- else
- {
- text.append(a->getAdditionString());
- }
- }
-
- // Draw Name
- if (a->getDisplayBold())
- {
- if (type == MapItemType::SEPARATOR)
- {
- boldFont->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- mImagePadding + mPadding,
- y + mPadding);
- }
- else
- {
- boldFont->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- 15 + mImagePadding + mPadding,
- y + mPadding);
- }
- }
- else
- {
- if (type == MapItemType::SEPARATOR)
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- mImagePadding + mPadding,
- y + mPadding);
- }
- else
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- 15 + mImagePadding + mPadding,
- y + mPadding);
- }
- }
- }
-
- setWidth(parentWidth - 10);
- BLOCK_END("AvatarListBox::draw")
-}
-
-void AvatarListBox::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("AvatarListBox::draw")
- if ((mListModel == nullptr) || (localPlayer == nullptr))
- {
- BLOCK_END("AvatarListBox::draw")
- return;
- }
-
- const Widget *const parent = mParent;
- if (parent == nullptr)
- return;
-
- AvatarListModel *const model = static_cast<AvatarListModel *>(
- mListModel);
- updateAlpha();
-
- Font *const font = getFont();
- const int fontHeight = font->getHeight();
- const int parentWidth = parent->getWidth();
- const std::string &name = localPlayer->getName();
-
- // Draw the list elements
- const int num = model->getNumberOfElements();
- for (int i = 0, y = 0;
- i < num;
- ++i, y += fontHeight)
- {
- const Avatar *const a = model->getAvatarAt(i);
- if (a == nullptr)
- continue;
-
- const MapItemType::Type type = static_cast<MapItemType::Type>(
- a->getType());
- if (type != MapItemType::SEPARATOR)
- {
- // Draw online status
- const Image *const icon = a->getOnline()
- ? onlineIcon : offlineIcon;
- if (icon != nullptr)
- graphics->drawImage(icon, mImagePadding, y + mPadding);
- }
- }
-
- for (int i = 0, y = 0;
- i < model->getNumberOfElements();
- ++i, y += fontHeight)
- {
- const Avatar *const a = model->getAvatarAt(i);
- if (a == nullptr)
- continue;
-
- const MapItemType::Type type = static_cast<MapItemType::Type>(
- a->getType());
- std::string text;
-
- if (a->getMaxHp() > 0)
- {
- if (mShowLevel && a->getLevel() > 1)
- {
- text = strprintf("%s %d/%d (%d)", a->getComplexName().c_str(),
- a->getHp(), a->getMaxHp(), a->getLevel());
- }
- else
- {
- text = strprintf("%s %d/%d", a->getComplexName().c_str(),
- a->getHp(), a->getMaxHp());
- }
- const bool isPoison = a->getPoison();
- if (a->getMaxHp() != 0)
- {
- const ProgressColorIdT themeColor = (isPoison
- ? ProgressColorId::PROG_HP_POISON
- : ProgressColorId::PROG_HP);
- Color color = Theme::getProgressColor(
- themeColor, static_cast<float>(a->getHp())
- / static_cast<float>(a->getMaxHp()));
- color.a = 80;
- graphics->setColor(color);
- graphics->fillRectangle(Rect(mPadding, y + mPadding,
- parentWidth * a->getHp() / a->getMaxHp()
- - 2 * mPadding, fontHeight));
- }
- }
- else if (a->getDamageHp() != 0 && a->getName() != name)
- {
- if (mShowLevel && a->getLevel() > 1)
- {
- text = strprintf("%s -%d (%d)", a->getComplexName().c_str(),
- a->getDamageHp(), a->getLevel());
- }
- else
- {
- text = strprintf("%s -%d", a->getComplexName().c_str(),
- a->getDamageHp());
- }
-
- const ProgressColorIdT themeColor = (a->getPoison()
- ? ProgressColorId::PROG_HP_POISON : ProgressColorId::PROG_HP);
- Color color = Theme::getProgressColor(themeColor, 1);
- color.a = 80;
- graphics->setColor(color);
- graphics->fillRectangle(Rect(mPadding, y + mPadding,
- parentWidth * a->getDamageHp() / 1024
- - 2 * mPadding, fontHeight));
-
- if (a->getLevel() > 1)
- {
- graphics->setColor(mForegroundColor);
- int minHp = 40 + ((a->getLevel() - 1) * 5);
- if (minHp < 0)
- minHp = 40;
-
- graphics->drawLine(parentWidth * minHp / 1024
- + mPadding, y + mPadding,
- parentWidth * minHp / 1024, y + fontHeight);
- }
- }
- else
- {
- if (mShowLevel && a->getLevel() > 1)
- {
- text = strprintf("%s (%d)", a->getComplexName().c_str(),
- a->getLevel());
- }
- else
- {
- text = a->getComplexName();
- }
- }
-
- if (!a->getMap().empty())
- {
- if (a->getX() != -1)
- {
- text.append(strprintf(" [%d,%d %s]", a->getX(), a->getY(),
- a->getMap().c_str()));
- }
- else
- {
- text.append(strprintf(" [%s]", a->getMap().c_str()));
- }
- }
-
- if (graphics->getSecure())
- {
- if (mShowGender)
- {
- switch (a->getGender())
- {
- case Gender::FEMALE:
- text.append(" \u2640 ");
- break;
- case Gender::MALE:
- text.append(" \u2642 ");
- break;
- default:
- case Gender::UNSPECIFIED:
- case Gender::OTHER:
- break;
- }
- }
- }
- else
- {
- if (mShowGender)
- {
- switch (a->getGender())
- {
- case Gender::FEMALE:
- text.append(strprintf(" \u2640 %s",
- a->getAdditionString().c_str()));
- break;
- case Gender::MALE:
- text.append(strprintf(" \u2642 %s",
- a->getAdditionString().c_str()));
- break;
- default:
- case Gender::UNSPECIFIED:
- case Gender::OTHER:
- break;
- }
- }
- else
- {
- text.append(a->getAdditionString());
- }
- }
-
- // Draw Name
- if (a->getDisplayBold())
- {
- if (type == MapItemType::SEPARATOR)
- {
- boldFont->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- mImagePadding + mPadding,
- y + mPadding);
- }
- else
- {
- boldFont->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- 15 + mImagePadding + mPadding,
- y + mPadding);
- }
- }
- else
- {
- if (type == MapItemType::SEPARATOR)
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- mImagePadding + mPadding,
- y + mPadding);
- }
- else
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- text,
- 15 + mImagePadding + mPadding,
- y + mPadding);
- }
- }
- }
-
- setWidth(parentWidth - 10);
- BLOCK_END("AvatarListBox::draw")
-}
-
-void AvatarListBox::mousePressed(MouseEvent &event)
-{
- if (actorManager == nullptr ||
- localPlayer == nullptr ||
- popupManager == nullptr)
- {
- return;
- }
-
- const int height = getFont()->getHeight();
- if (height == 0)
- return;
-
- const int y = (event.getY() - mPadding) / height;
- if ((mListModel == nullptr) || y > mListModel->getNumberOfElements())
- return;
-
- setSelected(y);
- distributeActionEvent();
- const int selected = getSelected();
- AvatarListModel *const model = static_cast<AvatarListModel *>(
- mListModel);
- if (model == nullptr)
- return;
- const Avatar *ava = model->getAvatarAt(selected);
- if (ava == nullptr)
- return;
-
- const MapItemType::Type type = static_cast<MapItemType::Type>(
- ava->getType());
-
- event.consume();
- const MouseButtonT eventButton = event.getButton();
- if (eventButton == MouseButton::LEFT)
- {
-#ifdef TMWA_SUPPORT
- if (type == MapItemType::EMPTY)
- {
- const Being *const being = actorManager->findBeingByName(
- ava->getName(), ActorType::Player);
- if (being != nullptr)
- actorManager->heal(being);
- }
- else
-#endif // TMWA_SUPPORT
- {
- localPlayer->navigateTo(ava->getX(), ava->getY());
- }
- }
- else if (eventButton == MouseButton::RIGHT)
- {
- switch (type)
- {
- case MapItemType::EMPTY:
- {
- const Avatar *const avatar = model->getAvatarAt(selected);
- if (avatar != nullptr)
- {
- const Being *const being = actorManager->findBeingByName(
- avatar->getName(), ActorType::Player);
- if (being != nullptr)
- {
- popupMenu->showPopup(viewport->mMouseX,
- viewport->mMouseY,
- being);
- }
- else
- {
- popupMenu->showPlayerPopup(avatar->getName());
- }
- }
- break;
- }
- case MapItemType::ATTACK:
- case MapItemType::PRIORITY:
- case MapItemType::IGNORE_:
- {
- std::string name;
- if (model->getAvatarAt(selected)->getLevel() == 0)
- name.clear();
- else
- name = model->getAvatarAt(selected)->getName();
-
- popupMenu->showAttackMonsterPopup(viewport->mMouseX,
- viewport->mMouseY,
- name,
- model->getAvatarAt(selected)->getType());
- break;
- }
- case MapItemType::PICKUP:
- case MapItemType::NOPICKUP:
- {
- std::string name;
- if (model->getAvatarAt(selected)->getLevel() == 0)
- name.clear();
- else
- name = model->getAvatarAt(selected)->getName();
-
- popupMenu->showPickupItemPopup(viewport->mMouseX,
- viewport->mMouseY,
- name);
- break;
- }
- case MapItemType::HOME:
- case MapItemType::ROAD:
- case MapItemType::CROSS:
- case MapItemType::ARROW_UP:
- case MapItemType::ARROW_DOWN:
- case MapItemType::ARROW_LEFT:
- case MapItemType::ARROW_RIGHT:
- case MapItemType::PORTAL:
- case MapItemType::MUSIC:
- case MapItemType::SEPARATOR:
- {
- break;
- }
- default:
- {
- const Map *const map = viewport->getMap();
- ava = model->getAvatarAt(selected);
- if ((map != nullptr) && (ava != nullptr))
- {
- MapItem *const mapItem = map->findPortalXY(
- ava->getX(), ava->getY());
- popupMenu->showPopup(viewport->mMouseX,
- viewport->mMouseY,
- mapItem);
- }
- break;
- }
- }
- }
- else if (eventButton == MouseButton::MIDDLE)
- {
- if (type == MapItemType::EMPTY && (chatWindow != nullptr))
- {
- const std::string &name = model->getAvatarAt(selected)->getName();
- const WhisperTab *const tab = chatWindow->addWhisperTab(
- name, name, true);
- if (tab != nullptr)
- chatWindow->saveState();
- }
- }
-}
-
-void AvatarListBox::mouseReleased(MouseEvent &event A_UNUSED)
-{
-}
-
-void AvatarListBox::optionChanged(const std::string &value)
-{
- if (value == "showgender")
- mShowGender = config.getBoolValue("showgender");
- else if (value == "showlevel")
- mShowLevel = config.getBoolValue("showlevel");
-}
diff --git a/src/gui/widgets/avatarlistbox.h b/src/gui/widgets/avatarlistbox.h
deleted file mode 100644
index 8af27256b..000000000
--- a/src/gui/widgets/avatarlistbox.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_AVATARLISTBOX_H
-#define GUI_WIDGETS_AVATARLISTBOX_H
-
-#include "gui/widgets/listbox.h"
-
-class AvatarListModel;
-class Image;
-
-class AvatarListBox final : public ListBox,
- public ConfigListener
-{
- public:
- AvatarListBox(const Widget2 *const widget,
- AvatarListModel *const model);
-
- A_DELETE_COPY(AvatarListBox)
-
- ~AvatarListBox();
-
- /**
- * Draws the list box.
- */
- void draw(Graphics *gcnGraphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *gcnGraphics) override final A_NONNULL(2);
-
- void mousePressed(MouseEvent &event) override final;
-
- void mouseReleased(MouseEvent &event A_UNUSED) override final A_CONST;
-
- void optionChanged(const std::string &value) override final;
-
- private:
- int mImagePadding;
- bool mShowGender;
- bool mShowLevel;
-
- static int instances;
- static Image *onlineIcon;
- static Image *offlineIcon;
-};
-
-#endif // GUI_WIDGETS_AVATARLISTBOX_H
diff --git a/src/gui/widgets/basiccontainer.cpp b/src/gui/widgets/basiccontainer.cpp
deleted file mode 100644
index 768733ae5..000000000
--- a/src/gui/widgets/basiccontainer.cpp
+++ /dev/null
@@ -1,439 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/basiccontainer.h"
-
-#include "utils/foreach.h"
-
-#include "render/graphics.h"
-
-#include <algorithm>
-
-#include "debug.h"
-
-BasicContainer::~BasicContainer()
-{
- clear();
-}
-
-void BasicContainer::moveToTop(Widget *const widget) restrict2
-{
- 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;
- }
- }
-}
-
-void BasicContainer::moveToBottom(Widget *const widget) restrict2
-{
- const WidgetListIterator iter = std::find(mWidgets.begin(),
- mWidgets.end(), widget);
- if (iter != mWidgets.end())
- {
- mWidgets.erase(iter);
- mWidgets.insert(mWidgets.begin(), widget);
- }
-
- const 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 &restrict event) restrict2
-{
- const WidgetListIterator iter = std::find(mWidgets.begin(),
- mWidgets.end(), event.getSource());
- if (iter != mWidgets.end())
- mWidgets.erase(iter);
-
- const WidgetListIterator iter2 = std::find(mLogicWidgets.begin(),
- mLogicWidgets.end(), event.getSource());
- if (iter2 != mLogicWidgets.end())
- mLogicWidgets.erase(iter2);
-}
-
-Rect BasicContainer::getChildrenArea() restrict2
-{
- return Rect(0, 0, mDimension.width, mDimension.height);
-}
-
-void BasicContainer::focusNext() restrict2
-{
- WidgetListConstIterator it;
-
- for (it = mWidgets.begin(); it != mWidgets.end(); ++ it)
- {
- if ((*it)->isFocused())
- break;
- }
-
- const WidgetListConstIterator end = it;
-
- if (it == mWidgets.end())
- it = mWidgets.begin();
-
- ++ it;
-
- for ( ; it != end; ++ it)
- {
- if (it == mWidgets.end())
- it = mWidgets.begin();
-
- if ((*it)->isFocusable())
- {
- (*it)->requestFocus();
- return;
- }
- }
-}
-
-void BasicContainer::focusPrevious() restrict2
-{
- WidgetListReverseIterator it;
-
- for (it = mWidgets.rbegin(); it != mWidgets.rend(); ++ it)
- {
- if ((*it)->isFocused())
- break;
- }
-
- const WidgetListReverseIterator end = it;
-
- ++ it;
-
- if (it == mWidgets.rend())
- it = mWidgets.rbegin();
-
- for ( ; it != end; ++ it)
- {
- if (it == mWidgets.rend())
- it = mWidgets.rbegin();
-
- if ((*it)->isFocusable())
- {
- (*it)->requestFocus();
- return;
- }
- }
-}
-
-Widget *BasicContainer::getWidgetAt(int x, int y) restrict2
-{
- const Rect r = getChildrenArea();
-
- if (!r.isPointInRect(x, y))
- return nullptr;
-
- x -= r.x;
- y -= r.y;
-
- for (WidgetListReverseIterator it = mWidgets.rbegin();
- it != mWidgets.rend(); ++ it)
- {
- const Widget *restrict const widget = *it;
- if (widget->isVisible() &&
- widget->getDimension().isPointInRect(x, y))
- {
- return *it;
- }
- }
-
- return nullptr;
-}
-
-void BasicContainer::logic() restrict2
-{
- BLOCK_START("BasicContainer::logic")
- if (mVisible == Visible_false)
- {
- BLOCK_END("BasicContainer::logic")
- return;
- }
- logicChildren();
- BLOCK_END("BasicContainer::logic")
-}
-
-void BasicContainer::setFocusHandler(FocusHandler *restrict2 const
- focusHandler) restrict2
-{
- Widget::setFocusHandler(focusHandler);
-
- if (mInternalFocusHandler != nullptr)
- return;
-
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- (*iter)->setFocusHandler(focusHandler);
-}
-
-void BasicContainer::add(Widget *const widget) restrict2
-{
- if (widget == nullptr)
- return;
- mWidgets.push_back(widget);
- if (widget->isAllowLogic())
- mLogicWidgets.push_back(widget);
-
- if (mInternalFocusHandler == nullptr)
- widget->setFocusHandler(getFocusHandler());
- else
- widget->setFocusHandler(mInternalFocusHandler);
-
- widget->setParent(this);
- widget->addDeathListener(this);
-}
-
-void BasicContainer::remove(Widget *const restrict widget) restrict2
-{
- if (widget == nullptr)
- return;
- FOR_EACH (WidgetListIterator, iter, mWidgets)
- {
- if (*iter == widget)
- {
- mWidgets.erase(iter);
- widget->setFocusHandler(nullptr);
- widget->setWindow(nullptr);
- widget->setParent(nullptr);
- widget->removeDeathListener(this);
- break;
- }
- }
- FOR_EACH (WidgetListIterator, iter, mLogicWidgets)
- {
- if (*iter == widget)
- {
- mLogicWidgets.erase(iter);
- return;
- }
- }
-}
-
-void BasicContainer::clear() restrict2
-{
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- {
- Widget *restrict const widget = *iter;
- widget->setFocusHandler(nullptr);
- widget->setWindow(nullptr);
- widget->setParent(nullptr);
- widget->removeDeathListener(this);
- }
-
- mWidgets.clear();
- mLogicWidgets.clear();
-}
-
-void BasicContainer::drawChildren(Graphics *const restrict graphics) restrict2
-{
- BLOCK_START("BasicContainer::drawChildren")
- graphics->pushClipArea(getChildrenArea());
-
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- {
- Widget *restrict const widget = *iter;
- if (widget->mVisible == Visible_true)
- {
- // If the widget has a frame,
- // draw it before drawing the widget
- if (widget->mFrameSize > 0)
- {
- Rect rec = widget->mDimension;
- const int frame = CAST_S32(widget->mFrameSize);
- const int frame2 = frame * 2;
- rec.x -= frame;
- rec.y -= frame;
- rec.width += frame2;
- rec.height += frame2;
- graphics->pushClipArea(rec);
- BLOCK_START("BasicContainer::drawChildren 1")
- widget->drawFrame(graphics);
- BLOCK_END("BasicContainer::drawChildren 1")
- graphics->popClipArea();
- }
-
- graphics->pushClipArea(widget->mDimension);
- BLOCK_START("BasicContainer::drawChildren 2")
- widget->draw(graphics);
- BLOCK_END("BasicContainer::drawChildren 2")
- graphics->popClipArea();
- }
- }
-
- graphics->popClipArea();
- BLOCK_END("BasicContainer::drawChildren")
-}
-
-void BasicContainer::safeDrawChildren(Graphics *const restrict graphics)
- restrict2
-{
- BLOCK_START("BasicContainer::drawChildren")
- graphics->pushClipArea(getChildrenArea());
-
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- {
- Widget *restrict const widget = *iter;
- if (widget->mVisible == Visible_true)
- {
- // If the widget has a frame,
- // draw it before drawing the widget
- if (widget->mFrameSize > 0)
- {
- Rect rec = widget->mDimension;
- const int frame = CAST_S32(widget->mFrameSize);
- const int frame2 = frame * 2;
- rec.x -= frame;
- rec.y -= frame;
- rec.width += frame2;
- rec.height += frame2;
- graphics->pushClipArea(rec);
- BLOCK_START("BasicContainer::drawChildren 1")
- widget->safeDrawFrame(graphics);
- BLOCK_END("BasicContainer::drawChildren 1")
- graphics->popClipArea();
- }
-
- graphics->pushClipArea(widget->mDimension);
- BLOCK_START("BasicContainer::drawChildren 2")
- widget->safeDraw(graphics);
- BLOCK_END("BasicContainer::drawChildren 2")
- graphics->popClipArea();
- }
- }
-
- graphics->popClipArea();
- BLOCK_END("BasicContainer::drawChildren")
-}
-
-void BasicContainer::logicChildren() restrict2
-{
- BLOCK_START("BasicContainer::logicChildren")
- FOR_EACH (WidgetListConstIterator, iter, mLogicWidgets)
- (*iter)->logic();
- BLOCK_END("BasicContainer::logicChildren")
-}
-
-void BasicContainer::showWidgetPart(Widget *restrict const widget,
- const Rect &restrict area) restrict2
-{
- if (widget == nullptr)
- return;
-
- const Rect widgetArea = getChildrenArea();
-
- const int x = widget->mDimension.x;
- const int y = widget->mDimension.y;
- const int ax = area.x + x;
- const int ay = area.y + y;
-
- if (ax < 0)
- widget->setX(-area.x);
- else if (ax + area.width > widgetArea.width)
- widget->setX(widgetArea.width - area.x - area.width);
-
- if (ay < 0)
- widget->setY(-area.y);
- else if (ay + area.height > widgetArea.height)
- widget->setY(widgetArea.height - area.y - area.height);
-}
-
-void BasicContainer::setInternalFocusHandler(FocusHandler *const restrict
- focusHandler) restrict2
-{
- Widget::setInternalFocusHandler(focusHandler);
-
- FocusHandler *const restrict handler = mInternalFocusHandler != nullptr ?
- mInternalFocusHandler : getFocusHandler();
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- {
- (*iter)->setFocusHandler(handler);
- }
-}
-
-Widget *BasicContainer::findFirstWidget(const std::set<Widget*> &restrict list)
- restrict2
-{
- FOR_EACHR (WidgetListReverseIterator, iter, mWidgets)
- {
- if (list.find(*iter) != list.end())
- return *iter;
- }
- return nullptr;
-}
diff --git a/src/gui/widgets/basiccontainer.h b/src/gui/widgets/basiccontainer.h
deleted file mode 100644
index 9ab658a76..000000000
--- a/src/gui/widgets/basiccontainer.h
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_BASICCONTAINER_H
-#define GUI_WIDGETS_BASICCONTAINER_H
-
-#include "gui/widgets/widget.h"
-
-#include "listeners/widgetdeathlistener.h"
-
-/**
- * A base class for containers. The class implements the most
- * common things for a container. If you are implementing a
- * container, consider inheriting from this class.
- *
- * @see Container
- */
-class BasicContainer notfinal : public Widget,
- public WidgetDeathListener
-{
- public:
- explicit BasicContainer(const Widget2 *restrict const widget) :
- Widget(widget),
- WidgetDeathListener(),
- mWidgets(),
- mLogicWidgets()
- { }
-
- A_DELETE_COPY(BasicContainer)
-
- /**
- * Destructor
- */
- virtual ~BasicContainer();
-
- /**
- * Shows a certain part of a widget in the basic container.
- * Used when widgets want a specific part to be visible in
- * its parent. An example is a TextArea that wants a specific
- * part of its text to be visible when a TextArea is a child
- * of a ScrollArea.
- *
- * @param widget The widget whom wants a specific part of
- * itself to be visible.
- * @param area The rectangle to be visible.
- */
- void showWidgetPart(Widget *restrict const widget,
- const Rect &restrict area) restrict2 override;
-
- // Inherited from Widget
-
- void moveToTop(Widget *const widget) restrict2 override;
-
- void moveToBottom(Widget *const widget) restrict2 override;
-
- Rect getChildrenArea() restrict2 override A_WARN_UNUSED;
-
- void focusNext() restrict2 override;
-
- void focusPrevious() restrict2 override;
-
- void logic() restrict2 override;
-
- void setFocusHandler(FocusHandler *restrict const focusHandler)
- restrict2 override;
-
- void setInternalFocusHandler(FocusHandler *const restrict focusHandler)
- restrict2;
-
- Widget *getWidgetAt(int x, int y) restrict2 override A_WARN_UNUSED;
-
- // Inherited from WidgetDeathListener
-
- void death(const Event &restrict event) restrict2 override;
-
- Widget *findFirstWidget(const std::set<Widget*> &restrict list)
- restrict2;
-
- /**
- * Adds a widget to the basic container.
- *
- * @param widget The widget to add.
- * @see remove, clear
- */
- void add(Widget *const widget) restrict2;
-
- /**
- * Removes a widget from the basic container.
- *
- * @param widget The widget to remove.
- * @see add, clear
- */
- virtual void remove(Widget *const restrict widget) restrict2;
-
- /**
- * Clears the basic container from all widgets.
- *
- * @see remove, clear
- */
- virtual void clear() restrict2;
-
- protected:
- /**
- * Draws the children widgets of the basic container.
- *
- * @param graphics A graphics object to draw with.
- */
- virtual void drawChildren(Graphics *const restrict graphics)
- restrict2 A_NONNULL(2);
-
- virtual void safeDrawChildren(Graphics *const restrict graphics)
- restrict2 A_NONNULL(2);
-
- /**
- * Calls logic for the children widgets of the basic
- * container.
- */
- virtual void logicChildren() restrict2;
-
- /**
- * Typedef.
- */
- typedef STD_VECTOR<Widget *> WidgetList;
-
- /**
- * Typedef.
- */
- typedef WidgetList::iterator WidgetListIterator;
-
- /**
- * Typedef.
- */
- typedef WidgetList::const_iterator WidgetListConstIterator;
-
- /**
- * Typedef.
- */
- typedef WidgetList::reverse_iterator WidgetListReverseIterator;
-
- /**
- * Typedef.
- */
- typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator;
-
- /**
- * 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
deleted file mode 100644
index ad143010d..000000000
--- a/src/gui/widgets/basiccontainer2.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * For comments regarding functions please see the header file.
- */
-
-#include "gui/widgets/basiccontainer2.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-BasicContainer2::BasicContainer2(const Widget2 *const widget) :
- BasicContainer(widget),
- mOpaque(Opaque_true)
-{
-}
-
-BasicContainer2::~BasicContainer2()
-{
-}
-
-void BasicContainer2::draw(Graphics *const graphics)
-{
- BLOCK_START("BasicContainer2::draw")
- if (mOpaque == Opaque_true)
- {
- graphics->setColor(mBaseColor);
- graphics->fillRectangle(Rect(0, 0,
- mDimension.width, mDimension.height));
- }
-
- drawChildren(graphics);
- BLOCK_END("BasicContainer2::draw")
-}
-
-void BasicContainer2::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("BasicContainer2::draw")
- if (mOpaque == Opaque_true)
- {
- graphics->setColor(mBaseColor);
- graphics->fillRectangle(Rect(0, 0,
- mDimension.width, mDimension.height));
- }
-
- safeDrawChildren(graphics);
- BLOCK_END("BasicContainer2::draw")
-}
-
-void BasicContainer2::add(Widget *const widget)
-{
- // +++ need move all add() calls from constructors
- // and after this method can be deleted
- // and virtual moved to basiccontainer
- BasicContainer::add(widget);
-}
-
-void BasicContainer2::addXY(Widget *const widget,
- const int x,
- const int y)
-{
- if (widget == nullptr)
- return;
- widget->setPosition(x, y);
- BasicContainer::add(widget);
-}
diff --git a/src/gui/widgets/basiccontainer2.h b/src/gui/widgets/basiccontainer2.h
deleted file mode 100644
index e26923d74..000000000
--- a/src/gui/widgets/basiccontainer2.h
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_BASICCONTAINER2_H
-#define GUI_WIDGETS_BASICCONTAINER2_H
-
-#include "gui/widgets/basiccontainer.h"
-
-#include "enums/simpletypes/opaque.h"
-
-/**
- * An implementation of a container able to contain other widgets. A widget's
- * position in the container is relative to the container itself and not the screen.
- * A container is the most common widget to use as the Gui's top widget as makes the Gui
- * able to contain more than one widget.
- *
- * @see Gui::setTop
- */
-class BasicContainer2: public BasicContainer
-{
- public:
- /**
- * Constructor. A container is opauqe as default, if you want a
- * none opaque container call setQpaque(false).
- *
- * @see setOpaque, isOpaque
- */
- explicit BasicContainer2(const Widget2 *const widget);
-
- /**
- * Destructor.
- */
- virtual ~BasicContainer2();
-
- /**
- * Sets the container to be opaque or not. If the container
- * is opaque its background will be drawn, if it's not opaque
- * its background will not be drawn, and thus making the container
- * completely transparent.
- *
- * NOTE: This is not the same as to set visibility. A non visible
- * container will not itself nor will it draw its content.
- *
- * @param opaque True if the container should be opaque, false otherwise.
- * @see isOpaque
- */
- void setOpaque(Opaque opaque)
- { mOpaque = opaque; }
-
- /**
- * Checks if the container is opaque or not.
- *
- * @return True if the container is opaque, false otherwise.
- * @see setOpaque
- */
- bool isOpaque() const
- { return mOpaque == Opaque_true; }
-
- /**
- * Adds a widget to the container.
- *
- * @param widget The widget to add.
- * @see remove, clear
- */
- virtual void add(Widget *const widget);
-
- /**
- * Adds a widget to the container and also specifies the widget's
- * position in the container. The position is relative to the container
- * and not relative to the screen.
- *
- * @param widget The widget to add.
- * @param x The x coordinate for the widget.
- * @param y The y coordinate for the widget.
- * @see remove, clear
- */
- void addXY(Widget *const widget,
- const int x, const int y);
-
- // Inherited from Widget
-
- void draw(Graphics *const graphics) override A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override A_NONNULL(2);
-
- protected:
- /**
- * True if the container is opaque, false otherwise.
- */
- Opaque mOpaque;
-};
-
-#endif // GUI_WIDGETS_BASICCONTAINER2_H
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
deleted file mode 100644
index 6d65a11cb..000000000
--- a/src/gui/widgets/browserbox.cpp
+++ /dev/null
@@ -1,936 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- * Copyright (C) 2009 Aethyra Development Team
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/browserbox.h"
-
-#include "enums/gui/linkhighlightmode.h"
-
-#include "gui/gui.h"
-#include "gui/mouseoverlink.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/widgets/browserbox.inc"
-#include "gui/widgets/linkhandler.h"
-
-#include "render/graphics.h"
-
-#include "resources/imageset.h"
-
-#include "resources/image/image.h"
-
-#include "resources/loaders/imageloader.h"
-#include "resources/loaders/imagesetloader.h"
-
-#include "utils/browserboxtools.h"
-#include "utils/checkutils.h"
-#include "utils/foreach.h"
-#include "utils/stringutils.h"
-#include "utils/timer.h"
-#include "utils/translation/podict.h"
-
-#include <algorithm>
-
-#include "debug.h"
-
-ImageSet *BrowserBox::mEmotes = nullptr;
-int BrowserBox::mInstances = 0;
-
-BrowserBox::BrowserBox(const Widget2 *const widget,
- const Opaque opaque,
- const std::string &skin) :
- Widget(widget),
- MouseListener(),
- WidgetListener(),
- mTextRows(),
- mTextRowLinksCount(),
- mLineParts(),
- mLinks(),
- mLinkHandler(nullptr),
- mSkin(nullptr),
- mHighlightMode(0),
- mSelectedLink(-1),
- mMaxRows(0),
- mHeight(0),
- mWidth(0),
- mYStart(0),
- mUpdateTime(-1),
- mPadding(0),
- mNewLinePadding(15U),
- mItemPadding(0),
- mDataWidth(0),
- mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT)),
- mHyperLinkColor(getThemeColor(ThemeColorId::HYPERLINK)),
- mOpaque(opaque),
- mUseLinksAndUserColors(true),
- mUseEmotes(true),
- mAlwaysUpdate(true),
- mProcessVars(false),
- mEnableImages(false),
- mEnableKeys(false),
- mEnableTabs(false)
-{
- mAllowLogic = false;
-
- setFocusable(true);
- addMouseListener(this);
- addWidgetListener(this);
-
- mBackgroundColor = getThemeColor(ThemeColorId::BACKGROUND);
-
- if (theme != nullptr)
- mSkin = theme->load(skin, "browserbox.xml");
- if (mInstances == 0)
- {
- mEmotes = Loader::getImageSet(
- "graphics/sprites/chatemotes.png", 17, 18);
- }
- mInstances ++;
-
- if (mSkin != nullptr)
- {
- mPadding = mSkin->getPadding();
- mNewLinePadding = CAST_U32(
- mSkin->getOption("newLinePadding", 15));
- mItemPadding = mSkin->getOption("itemPadding");
- if (mSkin->getOption("highlightBackground") != 0)
- mHighlightMode |= LinkHighlightMode::BACKGROUND;
- if (mSkin->getOption("highlightUnderline") != 0)
- mHighlightMode |= LinkHighlightMode::UNDERLINE;
- }
-
- readColor(BLACK);
- readColor(RED);
- readColor(GREEN);
- readColor(BLUE);
- readColor(ORANGE);
- readColor(YELLOW);
- readColor(PINK);
- readColor(PURPLE);
- readColor(GRAY);
- readColor(BROWN);
-
- mForegroundColor = getThemeColor(ThemeColorId::BROWSERBOX);
- mForegroundColor2 = getThemeColor(ThemeColorId::BROWSERBOX_OUTLINE);
-}
-
-BrowserBox::~BrowserBox()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- if (theme != nullptr)
- {
- theme->unload(mSkin);
- mSkin = nullptr;
- }
-
- mInstances --;
- if (mInstances == 0)
- {
- if (mEmotes != nullptr)
- {
- mEmotes->decRef();
- mEmotes = nullptr;
- }
- }
-}
-
-void BrowserBox::setLinkHandler(LinkHandler* linkHandler)
-{
- mLinkHandler = linkHandler;
-}
-
-void BrowserBox::addRow(const std::string &row, const bool atTop)
-{
- std::string tmp = row;
- std::string newRow;
- const Font *const font = getFont();
- int linksCount = 0;
-
- if (getWidth() < 0)
- return;
-
- if (mProcessVars)
- {
- BrowserBoxTools::replaceVars(tmp);
- }
-
- // Use links and user defined colors
- if (mUseLinksAndUserColors)
- {
- BrowserLink bLink;
-
- // Check for links in format "@@link|Caption@@"
- const uint32_t sz = CAST_U32(mTextRows.size());
-
- if (mEnableKeys)
- {
- BrowserBoxTools::replaceKeys(tmp);
- }
-
- size_t idx1 = tmp.find("@@");
- while (idx1 != std::string::npos)
- {
- const size_t idx2 = tmp.find('|', idx1);
- const size_t idx3 = tmp.find("@@", idx2);
-
- if (idx2 == std::string::npos || idx3 == std::string::npos)
- break;
- bLink.link = tmp.substr(idx1 + 2, idx2 - (idx1 + 2));
- bLink.caption = tmp.substr(idx2 + 1, idx3 - (idx2 + 1));
- bLink.y1 = CAST_S32(sz) * font->getHeight();
- bLink.y2 = bLink.y1 + font->getHeight();
- if (bLink.caption.empty())
- {
- bLink.caption = BrowserBoxTools::replaceLinkCommands(
- bLink.link);
- if (translator != nullptr)
- bLink.caption = translator->getStr(bLink.caption);
- }
-
- newRow.append(tmp.substr(0, idx1));
-
- std::string tmp2 = newRow;
- idx1 = tmp2.find("##");
- while (idx1 != std::string::npos)
- {
- tmp2.erase(idx1, 3);
- idx1 = tmp2.find("##");
- }
- bLink.x1 = font->getWidth(tmp2) - 1;
- bLink.x2 = bLink.x1 + font->getWidth(bLink.caption) + 1;
-
- if (atTop)
- mLinks.insert(mLinks.begin(), bLink);
- else
- mLinks.push_back(bLink);
- linksCount ++;
-
- newRow.append("##<").append(bLink.caption);
-
- tmp.erase(0, idx3 + 2);
- if (!tmp.empty())
- newRow.append("##>");
-
- idx1 = tmp.find("@@");
- }
-
- newRow.append(tmp);
- }
- // Don't use links and user defined colors
- else
- {
- newRow = row;
- }
-
- if (mEnableTabs)
- {
- BrowserBoxTools::replaceTabs(newRow);
- }
-
- if (atTop)
- {
- mTextRows.push_front(newRow);
- mTextRowLinksCount.push_front(linksCount);
- }
- else
- {
- mTextRows.push_back(newRow);
- mTextRowLinksCount.push_back(linksCount);
- }
-
- // discard older rows when a row limit has been set
- if (mMaxRows > 0 && !mTextRows.empty())
- {
- while (mTextRows.size() > CAST_SIZE(mMaxRows))
- {
- mTextRows.pop_front();
- int cnt = mTextRowLinksCount.front();
- mTextRowLinksCount.pop_front();
-
- while ((cnt != 0) && !mLinks.empty())
- {
- mLinks.erase(mLinks.begin());
- cnt --;
- }
- }
- }
-
- const int fontHeight = font->getHeight();
- unsigned int y = 0;
- unsigned int nextChar;
- const char *const hyphen = "~";
- const unsigned int hyphenWidth = CAST_U32(
- font->getWidth(hyphen));
- unsigned int x = 0;
-
- FOR_EACH (TextRowCIter, i, mTextRows)
- {
- std::string tempRow = *i;
- for (uint32_t j = 0, sz = CAST_U32(tempRow.size());
- j < sz;
- j++)
- {
- const std::string character = tempRow.substr(j, 1);
- x += CAST_U32(font->getWidth(character));
- nextChar = j + 1;
-
- // Wraping between words (at blank spaces)
- if (nextChar < sz && tempRow.at(nextChar) == ' ')
- {
- int nextSpacePos = CAST_U32(
- tempRow.find(' ', (nextChar + 1)));
- if (nextSpacePos <= 0)
- nextSpacePos = CAST_U32(sz) - 1U;
-
- const unsigned int nextWordWidth =
- CAST_U32(font->getWidth(
- tempRow.substr(nextChar,
- (CAST_U32(nextSpacePos) - nextChar))));
-
- if ((x + nextWordWidth + 10)
- > CAST_U32(getWidth()))
- {
- x = mNewLinePadding; // Ident in new line
- y += 1;
- j ++;
- }
- }
- // Wrapping looong lines (brutal force)
- else if ((x + 2 * hyphenWidth)
- > CAST_U32(getWidth()))
- {
- x = mNewLinePadding; // Ident in new line
- y += 1;
- }
- }
- }
-
- setHeight(fontHeight * (CAST_S32(
- CAST_U32(mTextRows.size()) + y)));
- mUpdateTime = 0;
- updateHeight();
-}
-
-void BrowserBox::addRow(const std::string &cmd, const char *const text)
-{
- addRow(strprintf("@@%s|%s@@", encodeLinkText(cmd).c_str(),
- encodeLinkText(text).c_str()));
-}
-
-void BrowserBox::addImage(const std::string &path)
-{
- if (!mEnableImages)
- return;
-
- mTextRows.push_back("~~~" + path);
- mTextRowLinksCount.push_back(0);
-}
-
-void BrowserBox::clearRows()
-{
- mTextRows.clear();
- mTextRowLinksCount.clear();
- mLinks.clear();
- setWidth(0);
- setHeight(0);
- mSelectedLink = -1;
- mUpdateTime = 0;
- mDataWidth = 0;
- updateHeight();
-}
-
-void BrowserBox::mousePressed(MouseEvent &event)
-{
- if (mLinkHandler == nullptr)
- return;
-
- const LinkIterator i = std::find_if(mLinks.begin(), mLinks.end(),
- MouseOverLink(event.getX(), event.getY()));
-
- if (i != mLinks.end())
- {
- mLinkHandler->handleLink(i->link, &event);
- event.consume();
- }
-}
-
-void BrowserBox::mouseMoved(MouseEvent &event)
-{
- const LinkIterator i = std::find_if(mLinks.begin(), mLinks.end(),
- MouseOverLink(event.getX(), event.getY()));
-
- mSelectedLink = (i != mLinks.end())
- ? CAST_S32(i - mLinks.begin()) : -1;
-}
-
-void BrowserBox::mouseExited(MouseEvent &event A_UNUSED)
-{
- mSelectedLink = -1;
-}
-
-void BrowserBox::draw(Graphics *const graphics)
-{
- BLOCK_START("BrowserBox::draw")
- const ClipRect &cr = graphics->getTopClip();
- mYStart = cr.y - cr.yOffset;
- const int yEnd = mYStart + cr.height;
- if (mYStart < 0)
- mYStart = 0;
-
- if (mDimension.width != mWidth)
- {
- mWidth = mDimension.width;
- mHeight = calcHeight();
- setHeight(mHeight);
- mUpdateTime = cur_time;
- if (mDimension.width != mWidth)
- reportAlways("browserbox resize in draw");
- }
-
- if (mOpaque == Opaque_true)
- {
- graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(Rect(0, 0,
- mDimension.width, mDimension.height));
- }
-
- if (mSelectedLink >= 0 &&
- mSelectedLink < CAST_S32(mLinks.size()))
- {
- if ((mHighlightMode & LinkHighlightMode::BACKGROUND) != 0u)
- {
- BrowserLink &link = mLinks[CAST_SIZE(mSelectedLink)];
- graphics->setColor(mHighlightColor);
- graphics->fillRectangle(Rect(
- link.x1,
- link.y1,
- link.x2 - link.x1,
- link.y2 - link.y1));
- }
-
- if ((mHighlightMode & LinkHighlightMode::UNDERLINE) != 0u)
- {
- BrowserLink &link = mLinks[CAST_SIZE(mSelectedLink)];
- graphics->setColor(mHyperLinkColor);
- graphics->drawLine(
- link.x1,
- link.y2,
- link.x2,
- link.y2);
- }
- }
-
- Font *const font = getFont();
-
- FOR_EACH (LinePartCIter, i, mLineParts)
- {
- const LinePart &part = *i;
- if (part.mY + 50 < mYStart)
- continue;
- if (part.mY > yEnd)
- break;
- if (part.mType == 0u)
- {
- if (part.mBold)
- {
- boldFont->drawString(graphics,
- part.mColor,
- part.mColor2,
- part.mText,
- part.mX, part.mY);
- }
- else
- {
- font->drawString(graphics,
- part.mColor,
- part.mColor2,
- part.mText,
- part.mX, part.mY);
- }
- }
- else if (part.mImage != nullptr)
- {
- graphics->drawImage(part.mImage, part.mX, part.mY);
- }
- }
-
- BLOCK_END("BrowserBox::draw")
-}
-
-void BrowserBox::safeDraw(Graphics *const graphics)
-{
- BrowserBox::draw(graphics);
-}
-
-int BrowserBox::calcHeight()
-{
- unsigned int y = CAST_U32(mPadding);
- int wrappedLines = 0;
- int moreHeight = 0;
- int maxWidth = mDimension.width - mPadding;
- int link = 0;
- bool bold = false;
- unsigned int wWidth = CAST_U32(maxWidth);
-
- if (maxWidth < 0)
- return 1;
-
- const Font *const font = getFont();
- const int fontHeight = font->getHeight() + 2 * mItemPadding;
- const int fontWidthMinus = font->getWidth("-");
- const char *const hyphen = "~";
- const int hyphenWidth = font->getWidth(hyphen);
-
- Color selColor[2] = {mForegroundColor, mForegroundColor2};
- const Color textColor[2] = {mForegroundColor, mForegroundColor2};
- mLineParts.clear();
-
- FOR_EACH (TextRowCIter, i, mTextRows)
- {
- unsigned int x = CAST_U32(mPadding);
- const std::string row = *(i);
- bool wrapped = false;
- int objects = 0;
-
- // Check for separator lines
- if (row.find("---", 0) == 0)
- {
- const int dashWidth = fontWidthMinus;
- for (x = CAST_U32(mPadding); x < wWidth; x ++)
- {
- mLineParts.push_back(LinePart(CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], "-", false));
- x += CAST_U32(CAST_S32(
- dashWidth) - 2);
- }
-
- y += CAST_U32(fontHeight);
- continue;
- }
- else if (mEnableImages && row.find("~~~", 0) == 0)
- {
- std::string str = row.substr(3);
- const size_t sz = str.size();
- if (sz > 2 && str.substr(sz - 1) == "~")
- str = str.substr(0, sz - 1);
- Image *const img = Loader::getImage(str);
- if (img != nullptr)
- {
- img->incRef();
- mLineParts.push_back(LinePart(CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], img));
- y += CAST_U32(img->getHeight() + 2);
- moreHeight += img->getHeight();
- if (img->getWidth() > maxWidth)
- maxWidth = img->getWidth() + 2;
- }
- continue;
- }
-
- Color prevColor[2];
- prevColor[0] = selColor[0];
- prevColor[1] = selColor[1];
- bold = false;
-
- const int xPadding = CAST_S32(mNewLinePadding) + mPadding;
-
- for (size_t start = 0, end = std::string::npos;
- start != std::string::npos;
- start = end, end = std::string::npos)
- {
- bool processed(false);
-
- // Wrapped line continuation shall be indented
- if (wrapped)
- {
- y += CAST_U32(fontHeight);
- x = CAST_U32(xPadding);
- wrapped = false;
- }
-
- size_t idx1 = end;
- size_t idx2 = end;
-
- // "Tokenize" the string at control sequences
- if (mUseLinksAndUserColors)
- idx1 = row.find("##", start + 1);
- if (start == 0 || mUseLinksAndUserColors)
- {
- // Check for color change in format "##x", x = [L,P,0..9]
- if (row.find("##", start) == start && row.size() > start + 2)
- {
- const signed char c = row.at(start + 2);
-
- bool valid(false);
- const Color col[2] =
- {
- getThemeCharColor(c, valid),
- getThemeCharColor(CAST_S8(
- c | 0x80), valid)
- };
-
- if (c == '>')
- {
- selColor[0] = prevColor[0];
- selColor[1] = prevColor[1];
- }
- else if (c == '<')
- {
- prevColor[0] = selColor[0];
- prevColor[1] = selColor[1];
- selColor[0] = col[0];
- selColor[1] = col[1];
- }
- else if (c == 'B')
- {
- bold = true;
- }
- else if (c == 'b')
- {
- bold = false;
- }
- else if (valid)
- {
- selColor[0] = col[0];
- selColor[1] = col[1];
- }
- else
- {
- switch (c)
- {
- case '0':
- selColor[0] = mColors[0][ColorName::BLACK];
- selColor[1] = mColors[1][ColorName::BLACK];
- break;
- case '1':
- selColor[0] = mColors[0][ColorName::RED];
- selColor[1] = mColors[1][ColorName::RED];
- break;
- case '2':
- selColor[0] = mColors[0][ColorName::GREEN];
- selColor[1] = mColors[1][ColorName::GREEN];
- break;
- case '3':
- selColor[0] = mColors[0][ColorName::BLUE];
- selColor[1] = mColors[1][ColorName::BLUE];
- break;
- case '4':
- selColor[0] = mColors[0][ColorName::ORANGE];
- selColor[1] = mColors[1][ColorName::ORANGE];
- break;
- case '5':
- selColor[0] = mColors[0][ColorName::YELLOW];
- selColor[1] = mColors[1][ColorName::YELLOW];
- break;
- case '6':
- selColor[0] = mColors[0][ColorName::PINK];
- selColor[1] = mColors[1][ColorName::PINK];
- break;
- case '7':
- selColor[0] = mColors[0][ColorName::PURPLE];
- selColor[1] = mColors[1][ColorName::PURPLE];
- break;
- case '8':
- selColor[0] = mColors[0][ColorName::GRAY];
- selColor[1] = mColors[1][ColorName::GRAY];
- break;
- case '9':
- selColor[0] = mColors[0][ColorName::BROWN];
- selColor[1] = mColors[1][ColorName::BROWN];
- break;
- default:
- selColor[0] = textColor[0];
- selColor[1] = textColor[1];
- break;
- }
- }
-
- if (c == '<' && link < CAST_S32(mLinks.size()))
- {
- int size;
- if (bold)
- {
- size = boldFont->getWidth(
- mLinks[CAST_SIZE(link)].caption) + 1;
- }
- else
- {
- size = font->getWidth(
- mLinks[CAST_SIZE(link)].caption) + 1;
- }
-
- BrowserLink &linkRef = mLinks[CAST_SIZE(
- link)];
- linkRef.x1 = CAST_S32(x);
- linkRef.y1 = CAST_S32(y);
- linkRef.x2 = linkRef.x1 + size;
- linkRef.y2 = CAST_S32(y) + fontHeight - 1;
- link++;
- }
-
- processed = true;
- start += 3;
- if (start == row.size())
- break;
- }
- }
- if (mUseEmotes)
- idx2 = row.find("%%", start + 1);
- if (idx1 < idx2)
- end = idx1;
- else
- end = idx2;
- if (mUseEmotes)
- {
- // check for emote icons
- if (row.size() > start + 2 && row.substr(start, 2) == "%%")
- {
- if (objects < 5)
- {
- const int cid = row.at(start + 2) - '0';
- if (cid >= 0)
- {
- if (mEmotes != nullptr)
- {
- const size_t sz = mEmotes->size();
- if (CAST_SIZE(cid) < sz)
- {
- Image *const img = mEmotes->get(
- CAST_SIZE(cid));
- if (img != nullptr)
- {
- mLineParts.push_back(LinePart(
- CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], img));
- x += 18;
- }
- }
- }
- }
- objects ++;
- processed = true;
- }
-
- start += 3;
- if (start == row.size())
- {
- if (x > mDataWidth)
- mDataWidth = x;
- break;
- }
- }
- }
- const size_t len = (end == std::string::npos) ? end : end - start;
-
- if (start >= row.length())
- break;
-
- std::string part = row.substr(start, len);
- int width = 0;
- if (bold)
- width = boldFont->getWidth(part);
- else
- width = font->getWidth(part);
-
- // Auto wrap mode
- if (wWidth > 0 &&
- width > 0 &&
- (x + CAST_U32(width) + 10) > wWidth)
- {
- bool forced = false;
-
- /* FIXME: This code layout makes it easy to crash remote
- clients by talking garbage. Forged long utf-8 characters
- will cause either a buffer underflow in substr or an
- infinite loop in the main loop. */
- do
- {
- if (!forced)
- end = row.rfind(' ', end);
-
- // Check if we have to (stupidly) force-wrap
- if (end == std::string::npos || end <= start)
- {
- forced = true;
- end = row.size();
- x += CAST_U32(hyphenWidth);
- continue;
- }
-
- // Skip to the start of the current character
- while ((row[end] & 192) == 128)
- end--;
- end--; // And then to the last byte of the previous one
-
- part = row.substr(start, end - start + 1);
- if (bold)
- width = boldFont->getWidth(part);
- else
- width = font->getWidth(part);
- }
- while (end > start &&
- width > 0 &&
- (x + CAST_U32(width) + 10) > wWidth);
-
- if (forced)
- {
- x -= CAST_U32(hyphenWidth);
- mLineParts.push_back(LinePart(
- CAST_S32(wWidth) - hyphenWidth,
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], hyphen, bold));
- end++; // Skip to the next character
- }
- else
- {
- end += 2; // Skip to after the space
- }
-
- wrapped = true;
- wrappedLines++;
- }
-
- mLineParts.push_back(LinePart(CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], part.c_str(), bold));
-
- if (bold)
- width = boldFont->getWidth(part);
- else
- width = font->getWidth(part);
-
- if (width == 0 && !processed)
- break;
-
- x += CAST_U32(width);
- if (x > mDataWidth)
- mDataWidth = x;
- }
- y += CAST_U32(fontHeight);
- }
- if (CAST_S32(wWidth) != maxWidth)
- setWidth(maxWidth);
-
- return (CAST_S32(mTextRows.size()) + wrappedLines)
- * fontHeight + moreHeight + 2 * mPadding;
-}
-
-void BrowserBox::updateHeight()
-{
- if (mAlwaysUpdate || mUpdateTime != cur_time
- || mTextRows.size() < 3 || (mUpdateTime == 0))
- {
- mWidth = mDimension.width;
- mHeight = calcHeight();
- setHeight(mHeight);
- mUpdateTime = cur_time;
- }
-}
-
-void BrowserBox::updateSize(const bool always)
-{
- if (always)
- mUpdateTime = 0;
- updateHeight();
-}
-
-std::string BrowserBox::getTextAtPos(const int x, const int y) const
-{
- int textX = 0;
- int textY = 0;
-
- getAbsolutePosition(textX, textY);
- if (x < textX || y < textY)
- return std::string();
-
- textY = y - textY;
- std::string str;
- int lastY = 0;
-
- FOR_EACH (LinePartCIter, i, mLineParts)
- {
- const LinePart &part = *i;
- if (part.mY + 50 < mYStart)
- continue;
- if (part.mY > textY)
- break;
-
- if (part.mY > lastY)
- {
- str = part.mText;
- lastY = part.mY;
- }
- else
- {
- str.append(part.mText);
- }
- }
-
- return str;
-}
-
-void BrowserBox::setForegroundColorAll(const Color &color1,
- const Color &color2)
-{
- mForegroundColor = color1;
- mForegroundColor2 = color2;
-}
-
-void BrowserBox::moveSelectionUp()
-{
- if (mSelectedLink <= 0)
- mSelectedLink = CAST_S32(mLinks.size()) - 1;
- else
- mSelectedLink --;
-}
-
-void BrowserBox::moveSelectionDown()
-{
- mSelectedLink ++;
- if (mSelectedLink >= static_cast<signed int>(mLinks.size()))
- mSelectedLink = 0;
-}
-
-void BrowserBox::selectSelection()
-{
- if ((mLinkHandler == nullptr) ||
- mSelectedLink < 0 ||
- mSelectedLink >= static_cast<signed int>(mLinks.size()))
- {
- return;
- }
-
- mLinkHandler->handleLink(mLinks[CAST_SIZE(mSelectedLink)].link,
- nullptr);
-}
-
-void BrowserBox::widgetResized(const Event &event A_UNUSED)
-{
- updateHeight();
-}
diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h
deleted file mode 100644
index 45502ba5a..000000000
--- a/src/gui/widgets/browserbox.h
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- * Copyright (C) 2009 Aethyra Development Team
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_BROWSERBOX_H
-#define GUI_WIDGETS_BROWSERBOX_H
-
-#include "enums/simpletypes/opaque.h"
-
-#include "enums/gui/colorname.h"
-
-#include "gui/browserlink.h"
-
-#include "gui/widgets/linepart.h"
-#include "gui/widgets/widget.h"
-
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-class LinkHandler;
-
-/**
- * A simple browser box able to handle links and forward events to the
- * parent conteiner.
- */
-class BrowserBox final : public Widget,
- public MouseListener,
- public WidgetListener
-{
- public:
- /**
- * Constructor.
- */
- BrowserBox(const Widget2 *const widget,
- const Opaque opaque,
- const std::string &skin);
-
- A_DELETE_COPY(BrowserBox)
-
- /**
- * Destructor.
- */
- ~BrowserBox();
-
- /**
- * Sets the handler for links.
- */
- void setLinkHandler(LinkHandler *linkHandler);
-
- /**
- * Sets the BrowserBox opacity.
- */
- void setOpaque(Opaque opaque)
- { mOpaque = opaque; }
-
- /**
- * Sets the maximum numbers of rows in the browser box. 0 = no limit.
- */
- void setMaxRow(unsigned max)
- { mMaxRows = max; }
-
- /**
- * Adds a text row to the browser.
- */
- void addRow(const std::string &row, const bool atTop = false);
-
- /**
- * Adds a menu line to the browser.
- */
- void addRow(const std::string &cmd, const char *const text);
-
- void addImage(const std::string &path);
-
- /**
- * Remove all rows.
- */
- void clearRows();
-
- /**
- * Handles mouse actions.
- */
- void mousePressed(MouseEvent &event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void mouseExited(MouseEvent& event) override final;
-
- /**
- * Draws the browser box.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void updateHeight();
-
- void updateSize(const bool always);
-
- typedef std::list<std::string> TextRows;
-
- TextRows &getRows() noexcept2 A_WARN_UNUSED
- { return mTextRows; }
-
- bool hasRows() const noexcept2 A_WARN_UNUSED
- { return !mTextRows.empty(); }
-
- void setAlwaysUpdate(const bool n) noexcept2
- { mAlwaysUpdate = n; }
-
- void setProcessVars(const bool n) noexcept2
- { mProcessVars = n; }
-
- void setEnableImages(const bool n) noexcept2
- { mEnableImages = n; }
-
- void setEnableKeys(const bool n) noexcept2
- { mEnableKeys = n; }
-
- void setEnableTabs(const bool n) noexcept2
- { mEnableTabs = n; }
-
- std::string getTextAtPos(const int x, const int y) const A_WARN_UNUSED;
-
- int getPadding() const noexcept2 A_WARN_UNUSED
- { return mPadding; }
-
- void setForegroundColorAll(const Color &color1,
- const Color &color2);
-
- unsigned int getDataWidth() const noexcept2 A_WARN_UNUSED
- { return mDataWidth; }
-
- void moveSelectionUp();
-
- void moveSelectionDown();
-
- void selectSelection();
-
- void widgetResized(const Event &event) override final;
-
- private:
- int calcHeight() A_WARN_UNUSED;
-
- typedef TextRows::iterator TextRowIterator;
- typedef TextRows::const_iterator TextRowCIter;
- TextRows mTextRows;
- std::list<int> mTextRowLinksCount;
-
- typedef STD_VECTOR<LinePart> LinePartList;
- typedef LinePartList::iterator LinePartIterator;
- typedef LinePartList::const_iterator LinePartCIter;
- LinePartList mLineParts;
-
- typedef STD_VECTOR<BrowserLink> Links;
- typedef Links::iterator LinkIterator;
- Links mLinks;
-
- LinkHandler *mLinkHandler;
- Skin *mSkin;
- unsigned int mHighlightMode;
- int mSelectedLink;
- unsigned int mMaxRows;
- int mHeight;
- int mWidth;
- int mYStart;
- time_t mUpdateTime;
- int mPadding;
- unsigned int mNewLinePadding;
- int mItemPadding;
- unsigned int mDataWidth;
-
- Color mHighlightColor;
- Color mHyperLinkColor;
- Color mColors[2][ColorName::COLORS_MAX];
-
- Opaque mOpaque;
- bool mUseLinksAndUserColors;
- bool mUseEmotes;
- bool mAlwaysUpdate;
- bool mProcessVars;
- bool mEnableImages;
- bool mEnableKeys;
- bool mEnableTabs;
-
- static ImageSet *mEmotes;
- static int mInstances;
-};
-
-#endif // GUI_WIDGETS_BROWSERBOX_H
diff --git a/src/gui/widgets/browserbox.inc b/src/gui/widgets/browserbox.inc
deleted file mode 100644
index 25c8744c0..000000000
--- a/src/gui/widgets/browserbox.inc
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_BROWSERBOX_INC
-#define GUI_WIDGETS_BROWSERBOX_INC
-
-#define readColor(color) \
- mColors[0][ColorName::color] = getThemeColor(ThemeColorId::color); \
- mColors[1][ColorName::color] = getThemeColor(ThemeColorId::color##_OUTLINE)
-
-#endif // GUI_WIDGETS_BROWSERBOX_INC
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
deleted file mode 100644
index 0c2600583..000000000
--- a/src/gui/widgets/button.cpp
+++ /dev/null
@@ -1,934 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/button.h"
-
-#include "settings.h"
-
-#include "resources/imageset.h"
-#include "resources/imagerect.h"
-
-#include "resources/image/image.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "render/renderers.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-int Button::mInstances = 0;
-float Button::mAlpha = 1.0;
-
-static std::string const data[Button::BUTTON_COUNT] =
-{
- "button.xml",
- "button_highlighted.xml",
- "button_pressed.xml",
- "button_disabled.xml"
-};
-
-Skin *Button::button[BUTTON_COUNT];
-
-Button::Button(const Widget2 *const widget) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- FocusListener(),
- WidgetListener(),
- mCaption(),
- mDescription(),
- mTextChunk(),
- mVertexes2(new ImageCollection),
- mEnabledColor(getThemeColor(ThemeColorId::BUTTON)),
- mEnabledColor2(getThemeColor(ThemeColorId::BUTTON_OUTLINE)),
- mDisabledColor(getThemeColor(ThemeColorId::BUTTON_DISABLED)),
- mDisabledColor2(getThemeColor(ThemeColorId::BUTTON_DISABLED_OUTLINE)),
- mHighlightedColor(getThemeColor(ThemeColorId::BUTTON_HIGHLIGHTED)),
- mHighlightedColor2(getThemeColor(
- ThemeColorId::BUTTON_HIGHLIGHTED_OUTLINE)),
- mPressedColor(getThemeColor(ThemeColorId::BUTTON_PRESSED)),
- mPressedColor2(getThemeColor(ThemeColorId::BUTTON_PRESSED_OUTLINE)),
- mImages(nullptr),
- mImageSet(nullptr),
- mAlignment(Graphics::CENTER),
- mClickCount(0),
- mSpacing(),
- mTag(0),
- mMode(0),
- mXOffset(0),
- mYOffset(0),
- mImageWidth(0),
- mImageHeight(0),
- mHasMouse(false),
- mKeyPressed(false),
- mMousePressed(false),
- mStick(false),
- mPressed(false),
- mTextChanged(true)
-{
- init();
- adjustSize();
-}
-
-Button::Button(const Widget2 *const widget,
- const std::string &restrict caption,
- const std::string &restrict actionEventId,
- ActionListener *const listener) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- FocusListener(),
- WidgetListener(),
- mCaption(caption),
- mDescription(),
- mTextChunk(),
- mVertexes2(new ImageCollection),
- mEnabledColor(getThemeColor(ThemeColorId::BUTTON)),
- mEnabledColor2(getThemeColor(ThemeColorId::BUTTON_OUTLINE)),
- mDisabledColor(getThemeColor(ThemeColorId::BUTTON_DISABLED)),
- mDisabledColor2(getThemeColor(ThemeColorId::BUTTON_DISABLED_OUTLINE)),
- mHighlightedColor(getThemeColor(ThemeColorId::BUTTON_HIGHLIGHTED)),
- mHighlightedColor2(getThemeColor(
- ThemeColorId::BUTTON_HIGHLIGHTED_OUTLINE)),
- mPressedColor(getThemeColor(ThemeColorId::BUTTON_PRESSED)),
- mPressedColor2(getThemeColor(ThemeColorId::BUTTON_PRESSED_OUTLINE)),
- mImages(nullptr),
- mImageSet(nullptr),
- mAlignment(Graphics::CENTER),
- mClickCount(0),
- mSpacing(),
- mTag(0),
- mMode(0),
- mXOffset(0),
- mYOffset(0),
- mImageWidth(0),
- mImageHeight(0),
- mHasMouse(false),
- mKeyPressed(false),
- mMousePressed(false),
- mStick(false),
- mPressed(false),
- mTextChanged(true)
-{
- init();
- adjustSize();
- setActionEventId(actionEventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-}
-
-Button::Button(const Widget2 *const widget,
- const std::string &restrict caption,
- const std::string &restrict imageName,
- const int imageWidth, const int imageHeight,
- const std::string &restrict actionEventId,
- ActionListener *const listener) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- FocusListener(),
- WidgetListener(),
- mCaption(caption),
- mDescription(),
- mTextChunk(),
- mVertexes2(new ImageCollection),
- mEnabledColor(getThemeColor(ThemeColorId::BUTTON)),
- mEnabledColor2(getThemeColor(ThemeColorId::BUTTON_OUTLINE)),
- mDisabledColor(getThemeColor(ThemeColorId::BUTTON_DISABLED)),
- mDisabledColor2(getThemeColor(ThemeColorId::BUTTON_DISABLED_OUTLINE)),
- mHighlightedColor(getThemeColor(ThemeColorId::BUTTON_HIGHLIGHTED)),
- mHighlightedColor2(getThemeColor(
- ThemeColorId::BUTTON_HIGHLIGHTED_OUTLINE)),
- mPressedColor(getThemeColor(ThemeColorId::BUTTON_PRESSED)),
- mPressedColor2(getThemeColor(ThemeColorId::BUTTON_PRESSED_OUTLINE)),
- mImages(nullptr),
- mImageSet(nullptr),
- mAlignment(Graphics::CENTER),
- mClickCount(0),
- mSpacing(),
- mTag(0),
- mMode(0),
- mXOffset(0),
- mYOffset(0),
- mImageWidth(imageWidth),
- mImageHeight(imageHeight),
- mHasMouse(false),
- mKeyPressed(false),
- mMousePressed(false),
- mStick(false),
- mPressed(false),
- mTextChanged(true)
-{
- init();
- loadImageSet(imageName);
- adjustSize();
- setActionEventId(actionEventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-}
-
-Button::Button(const Widget2 *const widget,
- const std::string &restrict imageName,
- const int imageWidth, const int imageHeight,
- const std::string &restrict actionEventId,
- ActionListener *const listener) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- FocusListener(),
- WidgetListener(),
- mCaption(),
- mDescription(),
- mTextChunk(),
- mVertexes2(new ImageCollection),
- mEnabledColor(getThemeColor(ThemeColorId::BUTTON)),
- mEnabledColor2(getThemeColor(ThemeColorId::BUTTON_OUTLINE)),
- mDisabledColor(getThemeColor(ThemeColorId::BUTTON_DISABLED)),
- mDisabledColor2(getThemeColor(ThemeColorId::BUTTON_DISABLED_OUTLINE)),
- mHighlightedColor(getThemeColor(ThemeColorId::BUTTON_HIGHLIGHTED)),
- mHighlightedColor2(getThemeColor(
- ThemeColorId::BUTTON_HIGHLIGHTED_OUTLINE)),
- mPressedColor(getThemeColor(ThemeColorId::BUTTON_PRESSED)),
- mPressedColor2(getThemeColor(ThemeColorId::BUTTON_PRESSED_OUTLINE)),
- mImages(nullptr),
- mImageSet(nullptr),
- mAlignment(Graphics::CENTER),
- mClickCount(0),
- mSpacing(),
- mTag(0),
- mMode(0),
- mXOffset(0),
- mYOffset(0),
- mImageWidth(imageWidth),
- mImageHeight(imageHeight),
- mHasMouse(false),
- mKeyPressed(false),
- mMousePressed(false),
- mStick(false),
- mPressed(false),
- mTextChanged(true)
-{
- init();
- loadImageSet(imageName);
- adjustSize();
- setActionEventId(actionEventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-}
-
-Button::Button(const Widget2 *const widget,
- const std::string &restrict caption,
- const std::string &restrict imageName,
- const std::string &restrict actionEventId,
- ActionListener *const listener) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- FocusListener(),
- WidgetListener(),
- mCaption(caption),
- mDescription(),
- mTextChunk(),
- mVertexes2(new ImageCollection),
- mEnabledColor(getThemeColor(ThemeColorId::BUTTON)),
- mEnabledColor2(getThemeColor(ThemeColorId::BUTTON_OUTLINE)),
- mDisabledColor(getThemeColor(ThemeColorId::BUTTON_DISABLED)),
- mDisabledColor2(getThemeColor(ThemeColorId::BUTTON_DISABLED_OUTLINE)),
- mHighlightedColor(getThemeColor(ThemeColorId::BUTTON_HIGHLIGHTED)),
- mHighlightedColor2(getThemeColor(
- ThemeColorId::BUTTON_HIGHLIGHTED_OUTLINE)),
- mPressedColor(getThemeColor(ThemeColorId::BUTTON_PRESSED)),
- mPressedColor2(getThemeColor(ThemeColorId::BUTTON_PRESSED_OUTLINE)),
- mImages(nullptr),
- mImageSet(nullptr),
- mAlignment(Graphics::CENTER),
- mClickCount(0),
- mSpacing(),
- mTag(0),
- mMode(0),
- mXOffset(0),
- mYOffset(0),
- mImageWidth(0),
- mImageHeight(0),
- mHasMouse(false),
- mKeyPressed(false),
- mMousePressed(false),
- mStick(false),
- mPressed(false),
- mTextChanged(true)
-{
- init();
- loadImage(imageName);
- adjustSize();
- setActionEventId(actionEventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-}
-
-void Button::init()
-{
- mAllowLogic = false;
- addMouseListener(this);
- addKeyListener(this);
- addFocusListener(this);
- addWidgetListener(this);
-
- setFocusable(true);
- setFrameSize(0);
-
- if (mInstances == 0)
- {
- if (theme != nullptr)
- {
- for (int mode = 0; mode < BUTTON_COUNT; mode ++)
- {
- Skin *const skin = theme->load(data[mode], "button.xml");
- if (skin != nullptr)
- {
- button[mode] = skin;
- mSpacing[mode] = skin->getOption("spacing");
- }
- }
- }
-
- updateAlpha();
- }
-
- mInstances++;
-}
-
-Button::~Button()
-{
- if (mWindow != nullptr)
- mWindow->removeWidgetListener(this);
-
- if (gui != nullptr)
- gui->removeDragged(this);
-
- mInstances--;
-
- if (mInstances == 0 && (theme != nullptr))
- {
- for (int mode = 0; mode < BUTTON_COUNT; mode ++)
- theme->unload(button[mode]);
- }
- delete2(mVertexes2);
- if (mImageSet != nullptr)
- {
- mImageSet->decRef();
- mImageSet = nullptr;
- }
- if (mImages != nullptr)
- {
- for (int f = 0; f < BUTTON_COUNT; f ++)
- mImages[f] = nullptr;
- delete [] mImages;
- mImages = nullptr;
- }
- mTextChunk.deleteImage();
-}
-
-void Button::loadImage(const std::string &imageName)
-{
- if (mImageSet != nullptr)
- {
- mImageSet->decRef();
- mImageSet = nullptr;
- }
- Image *const image = Theme::getImageFromThemeXml(imageName, "");
- mImages = new Image*[BUTTON_COUNT];
- for (int f = 0; f < BUTTON_COUNT; f ++)
- mImages[f] = image;
-}
-
-void Button::loadImageSet(const std::string &imageName)
-{
- if (mImageSet != nullptr)
- {
- mImageSet->decRef();
- mImageSet = nullptr;
- }
- mImageSet = Theme::getImageSetFromTheme(imageName,
- mImageWidth, mImageHeight);
- if (mImageSet == nullptr)
- return;
- mImages = new Image*[BUTTON_COUNT];
- mImages[0] = nullptr;
- for (size_t f = 0; f < BUTTON_COUNT; f ++)
- {
- Image *const img = mImageSet->get(f);
- if (img != nullptr)
- mImages[f] = img;
- else
- mImages[f] = mImages[0];
- }
-}
-
-void Button::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (mAlpha != alpha)
- {
- mAlpha = alpha;
- for (int mode = 0; mode < BUTTON_COUNT; mode ++)
- {
- for (int a = 0; a < 9; a ++)
- {
- Skin *const skin = button[mode];
- if (skin != nullptr)
- {
- const ImageRect &rect = skin->getBorder();
- Image *const image = rect.grid[a];
- if (image != nullptr)
- image->setAlpha(mAlpha);
- }
- }
- }
- }
-}
-
-void Button::draw(Graphics *const graphics)
-{
- BLOCK_START("Button::draw")
- int mode;
-
- if (!isEnabled())
- mode = BUTTON_DISABLED;
- else if (isPressed2())
- mode = BUTTON_PRESSED;
- else if (mHasMouse)
- mode = BUTTON_HIGHLIGHTED;
- else
- mode = BUTTON_STANDARD;
-
- const Skin *const skin = button[mode];
- if (skin == nullptr)
- {
- BLOCK_END("Button::draw")
- return;
- }
-
- updateAlpha();
-
- bool recalc = false;
- if (mRedraw)
- {
- recalc = true;
- }
- else
- {
- // because we don't know where parent windows was moved,
- // need recalc vertexes
- ClipRect &rect = graphics->getTopClip();
- if (rect.xOffset != mXOffset || rect.yOffset != mYOffset)
- {
- recalc = true;
- mXOffset = rect.xOffset;
- mYOffset = rect.yOffset;
- }
- else if (mMode != mode)
- {
- recalc = true;
- mMode = mode;
- }
- else if (graphics->getRedraw())
- {
- recalc = true;
- }
- }
-
- const int padding = skin->getPadding();
- const int spacing = mSpacing[mode];
-
- if (recalc)
- mTextChanged = true;
-
- int imageX = 0;
- int imageY = 0;
- int textX = 0;
- const Rect &rect = mDimension;
- const int width = rect.width;
- const int height = rect.height;
- Font *const font = getFont();
- int textY = height / 2 - font->getHeight() / 2;
- if (mImages != nullptr)
- imageY = height / 2 - mImageHeight / 2;
-
-// need move calculation from draw!!!
-
- switch (mAlignment)
- {
- default:
- case Graphics::LEFT:
- {
- if (mImages != nullptr)
- {
- imageX = padding;
- textX = padding + mImageWidth + spacing;
- }
- else
- {
- textX = padding;
- }
- break;
- }
- case Graphics::CENTER:
- {
- const int width1 = font->getWidth(mCaption);
- if (mImages != nullptr)
- {
- const int w = width1 + mImageWidth + spacing;
- imageX = (width - w) / 2;
- textX = imageX + mImageWidth + spacing - width1 / 2;
- }
- else
- {
- textX = (width - width1) / 2;
- }
- break;
- }
- case Graphics::RIGHT:
- {
- const int width1 = font->getWidth(mCaption);
- textX = width - width1 - padding;
- imageX = textX - width1 - spacing;
- break;
- }
- }
-
- if (recalc)
- {
- mRedraw = false;
- mMode = mode;
- mVertexes2->clear();
- graphics->calcWindow(mVertexes2,
- 0, 0,
- width, height,
- skin->getBorder());
-
- if (mImages != nullptr)
- {
- if (isPressed())
- {
- graphics->calcTileCollection(mVertexes2,
- mImages[mode],
- imageX + 1, imageY + 1);
- }
- else
- {
- graphics->calcTileCollection(mVertexes2,
- mImages[mode],
- imageX, imageY);
- }
- }
- graphics->finalize(mVertexes2);
- }
- graphics->drawTileCollection(mVertexes2);
-
- if (isPressed())
- {
- textX ++;
- textY ++;
- }
-
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mCaption;
- switch (mode)
- {
- case BUTTON_DISABLED:
- mTextChunk.color = mDisabledColor;
- mTextChunk.color2 = mDisabledColor2;
- break;
- case BUTTON_PRESSED:
- mTextChunk.color = mPressedColor;
- mTextChunk.color2 = mPressedColor2;
- break;
- case BUTTON_HIGHLIGHTED:
- mTextChunk.color = mHighlightedColor;
- mTextChunk.color2 = mHighlightedColor2;
- break;
- default:
- mTextChunk.color = mEnabledColor;
- mTextChunk.color2 = mEnabledColor2;
- break;
- }
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, textX, textY);
-
- BLOCK_END("Button::draw")
-}
-
-void Button::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("Button::safeDraw")
- int mode;
-
- if (!isEnabled())
- mode = BUTTON_DISABLED;
- else if (isPressed2())
- mode = BUTTON_PRESSED;
- else if (mHasMouse || isFocused())
- mode = BUTTON_HIGHLIGHTED;
- else
- mode = BUTTON_STANDARD;
-
- const Skin *const skin = button[mode];
- if (skin == nullptr)
- {
- BLOCK_END("Button::safeDraw")
- return;
- }
-
- updateAlpha();
-
- if (mMode != mode)
- {
- mTextChanged = true;
- mMode = mode;
- }
-
- const int padding = skin->getPadding();
- const int spacing = mSpacing[mode];
-
- int imageX = 0;
- int imageY = 0;
- int textX = 0;
- const Rect &rect = mDimension;
- const int width = rect.width;
- const int height = rect.height;
- Font *const font = getFont();
- int textY = height / 2 - font->getHeight() / 2;
- if (mImages != nullptr)
- imageY = height / 2 - mImageHeight / 2;
-
-// need move calculation from draw!!!
-
- switch (mAlignment)
- {
- default:
- case Graphics::LEFT:
- {
- if (mImages != nullptr)
- {
- imageX = padding;
- textX = padding + mImageWidth + spacing;
- }
- else
- {
- textX = padding;
- }
- break;
- }
- case Graphics::CENTER:
- {
- const int width1 = font->getWidth(mCaption);
- if (mImages != nullptr)
- {
- const int w = width1 + mImageWidth + spacing;
- imageX = (width - w) / 2;
- textX = imageX + mImageWidth + spacing - width1 / 2;
- }
- else
- {
- textX = (width - width1) / 2;
- }
- break;
- }
- case Graphics::RIGHT:
- {
- const int width1 = font->getWidth(mCaption);
- textX = width - width1 - padding;
- imageX = textX - width1 - spacing;
- break;
- }
- }
-
- graphics->drawImageRect(0, 0, width, height, skin->getBorder());
-
- if (mImages != nullptr)
- {
- if (isPressed())
- graphics->drawImage(mImages[mode], imageX + 1, imageY + 1);
- else
- graphics->drawImage(mImages[mode], imageX, imageY);
- }
-
- if (isPressed())
- {
- textX ++;
- textY ++;
- }
-
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mCaption;
- switch (mode)
- {
- case BUTTON_DISABLED:
- mTextChunk.color = mDisabledColor;
- mTextChunk.color2 = mDisabledColor2;
- break;
- case BUTTON_PRESSED:
- mTextChunk.color = mPressedColor;
- mTextChunk.color2 = mPressedColor2;
- break;
- case BUTTON_HIGHLIGHTED:
- mTextChunk.color = mHighlightedColor;
- mTextChunk.color2 = mHighlightedColor2;
- break;
- default:
- mTextChunk.color = mEnabledColor;
- mTextChunk.color2 = mEnabledColor2;
- break;
- }
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, textX, textY);
-
- BLOCK_END("Button::safeDraw")
-}
-
-void Button::mouseReleased(MouseEvent& event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- if (mStick)
- mPressed = !mPressed;
-
- if (mMousePressed && mHasMouse)
- {
- mMousePressed = false;
- mClickCount = event.getClickCount();
- distributeActionEvent();
- }
- else
- {
- mMousePressed = false;
- mClickCount = 0;
- }
- event.consume();
- }
-}
-
-void Button::widgetResized(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void Button::widgetMoved(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void Button::widgetHidden(const Event &event A_UNUSED)
-{
- if (isBatchDrawRenders(openGLMode))
- mVertexes2->clear();
- mTextChunk.deleteImage();
- mRedraw = true;
- mTextChanged = true;
-}
-
-void Button::adjustSize()
-{
- const Font *const font = getFont();
- const Skin *const skin = button[BUTTON_STANDARD];
- if (skin == nullptr)
- return;
- const int padding = skin->getPadding();
-
- if (mImages != nullptr)
- {
- const int spacing = mSpacing[BUTTON_STANDARD];
- const int width = font->getWidth(mCaption);
- if (width != 0)
- setWidth(width + mImageWidth + spacing + 2 * padding);
- else
- setWidth(mImageWidth + 2 * padding);
- int height = font->getHeight();
- if (height < mImageHeight)
- height = mImageHeight;
- setHeight(height + 2 * padding);
- }
- else
- {
- setWidth(font->getWidth(mCaption) + 2 * padding);
- setHeight(font->getHeight() + 2 * padding);
- }
-}
-
-void Button::keyPressed(KeyEvent& event)
-{
- const InputActionT action = event.getActionId();
-
- if (action == InputAction::GUI_SELECT)
- {
- mKeyPressed = true;
- event.consume();
- }
-}
-
-void Button::keyReleased(KeyEvent& event)
-{
- const InputActionT action = event.getActionId();
-
- if (action == InputAction::GUI_SELECT && mKeyPressed)
- {
- mKeyPressed = false;
- if (mStick)
- mPressed = !mPressed;
- distributeActionEvent();
- event.consume();
- }
-}
-
-bool Button::isPressed2() const
-{
- return mPressed || isPressed();
-}
-
-bool Button::isPressed() const
-{
- if (mMousePressed)
- return mHasMouse;
- return mKeyPressed;
-}
-
-void Button::focusLost(const Event& event A_UNUSED)
-{
- mMousePressed = false;
- mKeyPressed = false;
-}
-
-void Button::mousePressed(MouseEvent& event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- mMousePressed = true;
- event.consume();
- }
-}
-
-void Button::mouseEntered(MouseEvent& event A_UNUSED)
-{
- mHasMouse = true;
-}
-
-void Button::mouseExited(MouseEvent& event A_UNUSED)
-{
- mHasMouse = false;
-}
-
-void Button::mouseDragged(MouseEvent& event)
-{
- event.consume();
-}
-
-void Button::setParent(Widget *widget)
-{
- if (mWindow != nullptr)
- mWindow->addWidgetListener(this);
- Widget::setParent(widget);
-}
-
-void Button::setWindow(Widget *const widget)
-{
- if ((widget == nullptr) && (mWindow != nullptr))
- {
- mWindow->removeWidgetListener(this);
- mWindow = nullptr;
- }
- else
- {
- Widget2::setWindow(widget);
- }
-}
diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h
deleted file mode 100644
index 4e6b5ba16..000000000
--- a/src/gui/widgets/button.h
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_BUTTON_H
-#define GUI_WIDGETS_BUTTON_H
-
-#include "gui/fonts/textchunk.h"
-
-#include "gui/widgets/widget.h"
-
-#include "listeners/focuslistener.h"
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "render/graphics.h"
-
-#include "localconsts.h"
-
-class Image;
-class ImageCollection;
-class ImageSet;
-class Skin;
-
-const std::string BUTTON_PLAY = "buttonplay.png";
-
-/**
- * Button widget. Same as the Guichan button but with custom look.
- *
- * \ingroup GUI
- */
-class Button final : public Widget,
- public MouseListener,
- public KeyListener,
- public FocusListener,
- public WidgetListener
-{
- public:
- /**
- * Default constructor.
- */
- explicit Button(const Widget2 *const widget);
-
- /**
- * Constructor, sets the caption of the button to the given string and
- * adds the given action listener.
- */
- Button(const Widget2 *const widget,
- const std::string &restrict caption,
- const std::string &restrict actionEventId,
- ActionListener *const listener);
-
- /**
- * Constructor, sets the caption of the button to the given string and
- * adds the given action listener.
- */
- Button(const Widget2 *const widget,
- const std::string &restrict caption,
- const std::string &restrict imageName,
- const int imageWidth, const int imageHeight,
- const std::string &actionEventId,
- ActionListener *const listener);
-
- /**
- * Constructor, sets the caption of the button to the given string and
- * adds the given action listener.
- */
- Button(const Widget2 *const widget,
- const std::string &restrict imageName,
- const int imageWidth, const int imageHeight,
- const std::string &restrict actionEventId,
- ActionListener *const listener);
-
- /**
- * Constructor, sets the caption of the button to the given string and
- * adds the given action listener.
- */
- Button(const Widget2 *const widget,
- const std::string &restrict imageName,
- const std::string &restrict caption,
- const std::string &restrict actionEventId,
- ActionListener *const listener);
-
- A_DELETE_COPY(Button)
-
- /**
- * Destructor.
- */
- ~Button();
-
- /**
- * Draws the button.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Update the alpha value to the button components.
- */
- static void updateAlpha();
-
- void mouseReleased(MouseEvent& event) override final;
-
- void setDescription(const std::string &text)
- { mDescription = text; }
-
- std::string getDescription() const noexcept2 A_WARN_UNUSED
- { return mDescription; }
-
- int getClickCount() const noexcept2 A_WARN_UNUSED
- { return mClickCount; }
-
- void setTag(int tag)
- { mTag = tag; }
-
- int getTag() const noexcept2 A_WARN_UNUSED
- { return mTag; }
-
- void setStick(bool b)
- { mStick = b; }
-
- void setPressed(bool b)
- { mPressed = b; }
-
- void widgetResized(const Event &event) override final;
-
- void widgetMoved(const Event &event) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void loadImage(const std::string &imageName);
-
- void loadImageSet(const std::string &imageName);
-
- void adjustSize();
-
- void keyPressed(KeyEvent &event) override final;
-
- void keyReleased(KeyEvent &event) override final;
-
- bool isPressed2() const A_WARN_UNUSED;
-
- /**
- * Sets the caption of the button. It's advisable to call
- * adjustSize after setting of the caption to adjust the
- * button's size to fit the caption.
- *
- * @param caption The caption of the button.
- * @see getCaption, adjustSize
- */
- void setCaption(const std::string& caption)
- { mCaption = caption; mTextChanged = true; }
-
- /**
- * Gets the caption of the button.
- *
- * @return The caption of the button.
- */
- const std::string& getCaption() const noexcept2 A_WARN_UNUSED
- { return mCaption; }
-
- /**
- * Sets the alignment of the caption. The alignment is relative
- * to the center of the button.
- *
- * @param alignment The alignment of the caption.
- * @see getAlignment, Graphics
- */
- void setAlignment(Graphics::Alignment alignment) noexcept2
- { mAlignment = alignment; }
-
- /**
- * Gets the alignment of the caption.
- *
- * @return The alignment of the caption.
- * @see setAlignment, Graphics
- */
- Graphics::Alignment getAlignment() const noexcept2 A_WARN_UNUSED
- { return mAlignment; }
-
- void focusLost(const Event& event) override final;
-
- void mousePressed(MouseEvent& event) override final;
-
- void mouseEntered(MouseEvent& event) override final;
-
- void mouseExited(MouseEvent& event) override final;
-
- void mouseDragged(MouseEvent& event) override final;
-
- void setParent(Widget *widget) override final;
-
- void setWindow(Widget *const widget) override final;
-
- void setImageWidth(const int width) noexcept2
- { mImageWidth = width; }
-
- void setImageHeight(const int height) noexcept2
- { mImageHeight = height; }
-
- enum
- {
- BUTTON_STANDARD = 0, // 0
- BUTTON_HIGHLIGHTED, // 1
- BUTTON_PRESSED, // 2
- BUTTON_DISABLED, // 3
- BUTTON_COUNT // 4 - Must be last.
- };
-
- private:
- /**
- * Checks if the button is pressed. Convenient method to use
- * when overloading the draw method of the button.
- *
- * @return True if the button is pressed, false otherwise.
- */
- bool isPressed() const;
-
- void init();
-
- static Skin *button[BUTTON_COUNT]; /**< Button state graphics */
- static int mInstances; /**< Number of button instances */
- static float mAlpha;
-
- /**
- * Holds the caption of the button.
- */
- std::string mCaption;
-
- std::string mDescription;
-
- TextChunk mTextChunk;
-
- ImageCollection *mVertexes2 A_NONNULLPOINTER;
- Color mEnabledColor;
- Color mEnabledColor2;
- Color mDisabledColor;
- Color mDisabledColor2;
- Color mHighlightedColor;
- Color mHighlightedColor2;
- Color mPressedColor;
- Color mPressedColor2;
- Image **mImages;
- ImageSet *mImageSet;
-
- /**
- * Holds the alignment of the caption.
- */
- Graphics::Alignment mAlignment;
-
- int mClickCount;
-
- /**
- * Holds the spacing between the border and the caption.
- */
- int mSpacing[BUTTON_COUNT];
-
- int mTag;
- int mMode;
- int mXOffset;
- int mYOffset;
- int mImageWidth;
- int mImageHeight;
- /**
- * True if the mouse is ontop of the button, false otherwise.
- */
- bool mHasMouse;
-
- /**
- * True if a key has been pressed, false otherwise.
- */
- bool mKeyPressed;
-
- /**
- * True if a mouse has been pressed, false otherwise.
- */
- bool mMousePressed;
-
- bool mStick;
- bool mPressed;
- bool mTextChanged;
-};
-
-#endif // GUI_WIDGETS_BUTTON_H
diff --git a/src/gui/widgets/characterdisplay.cpp b/src/gui/widgets/characterdisplay.cpp
deleted file mode 100644
index e5743615a..000000000
--- a/src/gui/widgets/characterdisplay.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/characterdisplay.h"
-
-#include "gui/gui.h"
-
-#include "gui/windows/charselectdialog.h"
-
-#include "gui/popups/textpopup.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layouthelper.h"
-
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "resources/db/unitsdb.h"
-
-#include "net/character.h"
-
-#include "debug.h"
-
-CharacterDisplay::CharacterDisplay(const Widget2 *const widget,
- CharSelectDialog *const charSelectDialog) :
- Container(widget),
- MouseListener(),
- WidgetListener(),
- mCharacter(nullptr),
- mPlayerBox(new PlayerBox(nullptr)),
- mName(new Label(this, "wwwwwwwwwwwwwwwwwwwwwwww"))
-{
- mPlayerBox->setActionEventId("select");
- mPlayerBox->addActionListener(charSelectDialog);
- setActionEventId("use");
- addActionListener(charSelectDialog);
-
- LayoutHelper h(this);
- ContainerPlacer placer = h.getPlacer(0, 0);
-
- placer(0, 0, mPlayerBox, 3, 5);
- placer(0, 5, mName, 3);
-
- update();
-
- mName->setAlignment(Graphics::CENTER);
- mName->adjustSize();
-
- if (mainGraphics->getWidth() > 800)
- setWidth(120);
- else
- setWidth(80);
- setHeight(120);
- addMouseListener(this);
- addWidgetListener(this);
-}
-
-CharacterDisplay::~CharacterDisplay()
-{
-}
-
-void CharacterDisplay::setCharacter(Net::Character *const character)
-{
- if (mCharacter == character)
- return;
-
- mCharacter = character;
- mPlayerBox->setPlayer(character != nullptr ? character->dummy : nullptr);
- update();
-}
-
-void CharacterDisplay::requestFocus()
-{
-}
-
-void CharacterDisplay::setActive(const bool active A_UNUSED)
-{
-}
-
-void CharacterDisplay::update()
-{
- if (mCharacter != nullptr)
- mName->setCaption(mCharacter->dummy->getName());
- else
- mName->setCaption("");
- const int width = mPlayerBox->getWidth();
- mName->resizeTo(width, width);
-
- distributeResizedEvent();
-}
-
-void CharacterDisplay::widgetHidden(const Event &event A_UNUSED)
-{
- if (textPopup != nullptr)
- textPopup->setVisible(Visible_false);
-}
-
-void CharacterDisplay::mouseExited(MouseEvent &event A_UNUSED)
-{
- if (textPopup != nullptr)
- textPopup->setVisible(Visible_false);
-}
-
-void CharacterDisplay::mouseMoved(MouseEvent &event A_UNUSED)
-{
- if (gui == nullptr ||
- textPopup == nullptr ||
- mCharacter == nullptr)
- {
- return;
- }
-
- int mouseX = 0;
- int mouseY = 0;
- Gui::getMouseState(mouseX, mouseY);
- const std::string &name = mName->getCaption();
- if (!name.empty())
- {
- textPopup->show(mouseX, mouseY,
- name,
- // TRANSLATORS: character level
- strprintf(_("Level: %u"),
- CAST_U32(
- mCharacter->data.mAttributes[Attributes::PLAYER_BASE_LEVEL])),
- // TRANSLATORS: character money
- strprintf(_("Money: %s"), UnitsDb::formatCurrency64(
- mCharacter->data.mAttributes[Attributes::MONEY]).c_str()));
- }
- else
- {
- textPopup->setVisible(Visible_false);
- }
-}
-
-void CharacterDisplay::mousePressed(MouseEvent &event)
-{
- event.consume();
- if (event.getClickCount() == 2)
- distributeActionEvent();
-}
diff --git a/src/gui/widgets/characterdisplay.h b/src/gui/widgets/characterdisplay.h
deleted file mode 100644
index def986b2d..000000000
--- a/src/gui/widgets/characterdisplay.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CHARACTERDISPLAY_H
-#define GUI_WIDGETS_CHARACTERDISPLAY_H
-
-#include "gui/widgets/container.h"
-#include "gui/widgets/playerbox.h"
-
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-class CharSelectDialog;
-class Label;
-
-namespace Net
-{
- struct Character;
-} // namespace Net
-
-class CharacterDisplay final : public Container,
- public MouseListener,
- public WidgetListener
-{
- public:
- CharacterDisplay(const Widget2 *const widget,
- CharSelectDialog *const charSelectDialog);
-
- A_DELETE_COPY(CharacterDisplay)
-
- ~CharacterDisplay();
-
- void setCharacter(Net::Character *const character);
-
- Net::Character *getCharacter() const
- { return mCharacter; }
-
- void requestFocus() override final A_CONST;
-
- void setActive(const bool active) A_CONST;
-
- bool isSelectFocused() const
- { return false; }
-
- bool isDeleteFocused() const
- { return false; }
-
- void focusSelect()
- { }
-
- void focusDelete()
- { }
-
- void setSelect(bool b)
- { mPlayerBox->setSelected(b); }
-
- void widgetHidden(const Event &event) override final;
-
- void mouseExited(MouseEvent &event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void mousePressed(MouseEvent &event) override final;
-
- void update();
-
- private:
- Net::Character *mCharacter;
- PlayerBox *mPlayerBox A_NONNULLPOINTER;
- Label *mName A_NONNULLPOINTER;
-};
-
-#endif // GUI_WIDGETS_CHARACTERDISPLAY_H
diff --git a/src/gui/widgets/characterviewbase.h b/src/gui/widgets/characterviewbase.h
deleted file mode 100644
index ad12efb26..000000000
--- a/src/gui/widgets/characterviewbase.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CHARACTERVIEWBASE_H
-#define GUI_WIDGETS_CHARACTERVIEWBASE_H
-
-#include "gui/windows/charselectdialog.h"
-
-#include "gui/widgets/container.h"
-
-#include "localconsts.h"
-
-class CharacterViewBase notfinal : public Container,
- public ActionListener
-{
- public:
- A_DELETE_COPY(CharacterViewBase)
-
- virtual ~CharacterViewBase()
- { }
-
- virtual void show(const int i) = 0;
-
- virtual void resize() = 0;
-
- int getSelected() const
- {
- return mSelected;
- }
-
- protected:
- CharacterViewBase(CharSelectDialog *const widget, const int padding) :
- Container(widget),
- ActionListener(),
- mParent(widget),
- mPadding(padding),
- mSelected(0)
- {
- }
-
- CharSelectDialog *mParent;
- int mPadding;
- int mSelected;
-};
-
-#endif // GUI_WIDGETS_CHARACTERVIEWBASE_H
diff --git a/src/gui/widgets/characterviewnormal.cpp b/src/gui/widgets/characterviewnormal.cpp
deleted file mode 100644
index c52616b85..000000000
--- a/src/gui/widgets/characterviewnormal.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/characterviewnormal.h"
-
-#include "configuration.h"
-
-#include "gui/widgets/characterdisplay.h"
-
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-namespace
-{
- int perRowCount = 5;
-} // namespace
-
-CharacterViewNormal::CharacterViewNormal(CharSelectDialog *const widget,
- STD_VECTOR<CharacterDisplay*>
- *const entries,
- const int padding) :
- CharacterViewBase(widget, padding),
- mCharacterEntries(entries),
- mRows(2)
-{
- addKeyListener(widget);
- if (entries != nullptr)
- {
- FOR_EACHP (STD_VECTOR<CharacterDisplay*>::iterator,
- it, entries)
- {
- CharacterDisplay *const character = *it;
- add(character);
- character->setVisible(Visible_true);
- }
- const size_t sz = mCharacterEntries->size();
- if (mSelected >= 0 && mSelected < CAST_S32(sz))
- {
- CharacterDisplay *const display = (*mCharacterEntries)[mSelected];
- if (display != nullptr)
- display->setSelect(false);
- }
- if (sz > 0)
- {
- mSelected = 0;
- CharacterDisplay *const display = (*mCharacterEntries)[0];
- display->setSelect(true);
- setWidth(display->getWidth() * perRowCount + mPadding * 2);
- }
- else
- {
- mSelected = -1;
- }
- mRows = CAST_S32(sz / perRowCount);
-
- if (mRows * perRowCount != CAST_S32(sz))
- mRows ++;
- }
-
- setHeight((105 + config.getIntValue("fontSize")) * mRows);
-}
-
-CharacterViewNormal::~CharacterViewNormal()
-{
- removeKeyListener(mParent);
-}
-
-void CharacterViewNormal::show(const int i)
-{
- const int sz = CAST_S32(mCharacterEntries->size());
- if (i >= 0 && i < sz)
- {
- if (mSelected >= 0)
- (*mCharacterEntries)[mSelected]->setSelect(false);
- mSelected = i;
- (*mCharacterEntries)[i]->setSelect(true);
- }
-}
-
-void CharacterViewNormal::resize()
-{
- const size_t sz = mCharacterEntries->size();
- if (sz == 0)
- return;
- const CharacterDisplay *const firtChar = (*mCharacterEntries)[0];
- int y = 0;
- const int width = firtChar->getWidth();
- const int height = firtChar->getHeight();
- int x = 0;
- for (size_t f = 0; f < sz; f ++, x ++)
- {
- if (x >= perRowCount)
- {
- x = 0;
- y += height;
- }
- (*mCharacterEntries)[f]->setPosition(x * width, y);
- }
-}
-
-void CharacterViewNormal::action(const ActionEvent &event A_UNUSED)
-{
-}
diff --git a/src/gui/widgets/characterviewnormal.h b/src/gui/widgets/characterviewnormal.h
deleted file mode 100644
index 344549092..000000000
--- a/src/gui/widgets/characterviewnormal.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CHARACTERVIEWNORMAL_H
-#define GUI_WIDGETS_CHARACTERVIEWNORMAL_H
-
-#include "gui/widgets/characterviewbase.h"
-
-#include "localconsts.h"
-
-class CharacterViewNormal final : public CharacterViewBase
-{
- public:
- CharacterViewNormal(CharSelectDialog *const widget,
- STD_VECTOR<CharacterDisplay*> *const entries,
- const int padding);
-
- A_DELETE_COPY(CharacterViewNormal)
-
- ~CharacterViewNormal();
-
- void show(const int i) override final;
-
- void resize() override;
-
- void action(const ActionEvent &event A_UNUSED) override final A_CONST;
-
- private:
- STD_VECTOR<CharacterDisplay*> *mCharacterEntries;
- int mRows;
-};
-
-#endif // GUI_WIDGETS_CHARACTERVIEWNORMAL_H
diff --git a/src/gui/widgets/characterviewsmall.cpp b/src/gui/widgets/characterviewsmall.cpp
deleted file mode 100644
index a2fbdc8d4..000000000
--- a/src/gui/widgets/characterviewsmall.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/characterviewsmall.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/characterdisplay.h"
-#include "gui/widgets/label.h"
-
-#include "utils/foreach.h"
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-CharacterViewSmall::CharacterViewSmall(CharSelectDialog *const widget,
- STD_VECTOR<CharacterDisplay*>
- *const entries,
- const int padding) :
- CharacterViewBase(widget, padding),
- mSelectedEntry(nullptr),
- mPrevious(new Button(this, "<", "prev", this)),
- mNext(new Button(this, ">", "next", this)),
- mNumber(new Label(this, "??")),
- mCharacterEntries(entries)
-{
- addKeyListener(widget);
- if (entries != nullptr)
- {
- FOR_EACHP (STD_VECTOR<CharacterDisplay*>::iterator,
- it, entries)
- {
- add(*it);
- }
- const int sz = CAST_S32(mCharacterEntries->size());
- if (sz > 0)
- {
- mSelected = 0;
- mSelectedEntry = (*mCharacterEntries)[mSelected];
- mSelectedEntry->setVisible(Visible_true);
- mNumber->setCaption(strprintf("%d / %d", mSelected + 1, sz));
- mNumber->adjustSize();
- }
- else
- {
- mSelected = -1;
- mSelectedEntry = nullptr;
- mNumber->setCaption("0 / 0");
- mNumber->adjustSize();
- }
- }
- add(mPrevious);
- add(mNext);
- add(mNumber);
-
- setHeight(200);
-}
-
-CharacterViewSmall::~CharacterViewSmall()
-{
- removeKeyListener(mParent);
-}
-
-void CharacterViewSmall::show(const int i)
-{
- const int sz = CAST_S32(mCharacterEntries->size());
- if (sz <= 0)
- return;
- if (mSelectedEntry != nullptr)
- mSelectedEntry->setVisible(Visible_false);
- if (i >= sz)
- mSelected = 0;
- else if (i < 0)
- mSelected = sz - 1;
- else
- mSelected = i;
- mSelectedEntry = (*mCharacterEntries)[mSelected];
- mSelectedEntry->setVisible(Visible_true);
- mNumber->setCaption(strprintf("%d / %d", mSelected + 1, sz));
- mNumber->adjustSize();
-}
-
-void CharacterViewSmall::resize()
-{
- const int sz = CAST_S32(mCharacterEntries->size());
- if (sz <= 0)
- return;
- const CharacterDisplay *const firtChar = (*mCharacterEntries)[0];
- const int w = mDimension.width;
- const int h = mDimension.height;
- const int x = (w - firtChar->getWidth()) / 2;
- const int y = (h - firtChar->getHeight()) / 2;
- FOR_EACHP (STD_VECTOR<CharacterDisplay*>::iterator,
- it, mCharacterEntries)
- {
- (*it)->setPosition(x, y);
- }
- const int y2 = (h - mPrevious->getHeight()) / 2;
- const int y3 = y2 - 55;
- mPrevious->setPosition(x - mPrevious->getWidth() - 10, y3);
- mNext->setPosition(w - x + 10, y3);
- mNumber->setPosition(10, y2);
-}
-
-void CharacterViewSmall::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "next")
- {
- mSelected ++;
- show(mSelected);
- mParent->updateState();
- }
- else if (eventId == "prev")
- {
- mSelected --;
- show(mSelected);
- mParent->updateState();
- }
-}
diff --git a/src/gui/widgets/characterviewsmall.h b/src/gui/widgets/characterviewsmall.h
deleted file mode 100644
index f363c608e..000000000
--- a/src/gui/widgets/characterviewsmall.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CHARACTERVIEWSMALL_H
-#define GUI_WIDGETS_CHARACTERVIEWSMALL_H
-
-#include "gui/widgets/characterviewbase.h"
-
-#include "localconsts.h"
-
-class Label;
-
-class CharacterViewSmall final : public CharacterViewBase
-{
- public:
- CharacterViewSmall(CharSelectDialog *const widget,
- STD_VECTOR<CharacterDisplay*> *const entries,
- const int padding);
- A_DELETE_COPY(CharacterViewSmall)
-
- ~CharacterViewSmall();
-
- void show(const int i) override final;
-
- void resize() override final;
-
- void action(const ActionEvent &event) override final;
-
- private:
- CharacterDisplay *mSelectedEntry;
- Button *mPrevious;
- Button *mNext;
- Label *mNumber;
- STD_VECTOR<CharacterDisplay*> *mCharacterEntries;
-};
-
-#endif // GUI_WIDGETS_CHARACTERVIEWSMALL_H
diff --git a/src/gui/widgets/chatinput.h b/src/gui/widgets/chatinput.h
deleted file mode 100644
index 92c7dc341..000000000
--- a/src/gui/widgets/chatinput.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CHATINPUT_H
-#define GUI_WIDGETS_CHATINPUT_H
-
-#include "gui/windows/chatwindow.h"
-
-#include "configuration.h"
-
-#include "gui/windows/emotewindow.h"
-
-#include "gui/widgets/textfield.h"
-
-#include "localconsts.h"
-
-/**
- * The chat input hides when it loses focus. It is also invisible by default.
- */
-class ChatInput final : public TextField
-{
- public:
- explicit ChatInput(ChatWindow *const window) :
- TextField(window, "", LoseFocusOnTab_false),
- mWindow(window),
- mFocusGaining(false)
- {
- setVisible(Visible_false);
- addFocusListener(this);
- }
-
- A_DELETE_COPY(ChatInput)
-
- /**
- * Called if the chat input loses focus. It will set itself to
- * invisible as result.
- */
- void focusLost(const Event &event) override final
- {
- TextField::focusLost(event);
- if (mFocusGaining || !config.getBoolValue("protectChatFocus"))
- {
- processVisible(Visible_false);
- if (chatWindow != nullptr)
- chatWindow->updateVisibility();
- mFocusGaining = false;
- return;
- }
- mFocusGaining = true;
- requestFocus();
- mFocusGaining = false;
- }
-
- void processVisible(const Visible n)
- {
- if (mWindow == nullptr || isVisible() == (n == Visible_true))
- return;
-
- if (n == Visible_false)
- mFocusGaining = true;
- setVisible(n);
- if (config.getBoolValue("hideChatInput")
- || config.getBoolValue("showEmotesButton"))
- {
- mWindow->adjustTabSize();
- }
- if (emoteWindow != nullptr)
- {
- emoteWindow->hide();
- }
- }
-
- void unprotectFocus()
- { mFocusGaining = true; }
-
- void setVisible(Visible visible)
- {
- TextField::setVisible(visible);
- }
-
- private:
- ChatWindow *mWindow;
- bool mFocusGaining;
-};
-
-#endif // GUI_WIDGETS_CHATINPUT_H
diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp
deleted file mode 100644
index ab1227b08..000000000
--- a/src/gui/widgets/checkbox.cpp
+++ /dev/null
@@ -1,338 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/checkbox.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "render/graphics.h"
-
-#include "resources/imagerect.h"
-
-#include "resources/image/image.h"
-
-#include "debug.h"
-
-int CheckBox::instances = 0;
-Skin *CheckBox::mSkin = nullptr;
-float CheckBox::mAlpha = 1.0;
-
-CheckBox::CheckBox(const Widget2 *const widget,
- const std::string &restrict caption,
- const bool selected,
- ActionListener *const listener,
- const std::string &restrict eventId) :
- Widget(widget),
- ToolTipListener(),
- KeyListener(),
- WidgetListener(),
- mSelected(selected),
- mCaption(),
- mTextChunk(),
- mPadding(0),
- mImagePadding(0),
- mImageSize(9),
- mSpacing(2),
- mTextX(0 + 9 + 2),
- mHasMouse(false),
- mDrawBox(true),
- mTextChanged(true)
-{
- setCaption(caption);
- mAllowLogic = false;
-
- setFocusable(true);
- addMouseListener(this);
- addKeyListener(this);
-
- mForegroundColor2 = getThemeColor(ThemeColorId::CHECKBOX_OUTLINE);
- if (instances == 0)
- {
- if (theme != nullptr)
- {
- mSkin = theme->load("checkbox.xml", "");
- updateAlpha();
- }
- }
-
- instances++;
-
- if (!eventId.empty())
- setActionEventId(eventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-
- mForegroundColor = getThemeColor(ThemeColorId::CHECKBOX);
- if (mSkin != nullptr)
- {
- mPadding = mSkin->getPadding();
- mImagePadding = mSkin->getOption("imagePadding");
- mImageSize = mSkin->getOption("imageSize");
- mSpacing = mSkin->getOption("spacing");
- mDrawBox = (mSkin->getOption("drawBox", 1) != 0);
- mTextX = mPadding + mImageSize + mSpacing;
- }
- adjustSize();
-}
-
-CheckBox::~CheckBox()
-{
- if (mWindow != nullptr)
- mWindow->removeWidgetListener(this);
-
- if (gui != nullptr)
- gui->removeDragged(this);
-
- instances--;
-
- if (instances == 0)
- {
- if (theme != nullptr)
- theme->unload(mSkin);
- }
-}
-
-void CheckBox::draw(Graphics *const graphics)
-{
- BLOCK_START("CheckBox::draw")
- drawBox(graphics);
-
- Font *const font = getFont();
-
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mCaption;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, mTextX, mPadding);
-
- BLOCK_END("CheckBox::draw")
-}
-
-void CheckBox::safeDraw(Graphics *const graphics)
-{
- CheckBox::draw(graphics);
-}
-
-void CheckBox::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (mAlpha != alpha)
- {
- mAlpha = alpha;
- if (mSkin != nullptr)
- {
- const ImageRect &rect = mSkin->getBorder();
- for (int a = 0; a < 6; a ++)
- {
- Image *const image = rect.grid[a];
- if (image != nullptr)
- image->setAlpha(mAlpha);
- }
- }
- }
-}
-
-void CheckBox::drawBox(Graphics *const graphics)
-{
- if ((mSkin == nullptr) || !mDrawBox)
- return;
-
- const ImageRect &rect = mSkin->getBorder();
- int index = 0;
-
- if (mEnabled && mVisible == Visible_true)
- {
- if (mSelected)
- {
- if (mHasMouse)
- index = 5;
- else
- index = 1;
- }
- else
- {
- if (mHasMouse)
- index = 4;
- else
- index = 0;
- }
- }
- else
- {
- if (mSelected)
- index = 3;
- else
- index = 2;
- }
- const Image *const box = rect.grid[index];
-
- updateAlpha();
-
- if (box != nullptr)
- {
- graphics->drawImage(box,
- mImagePadding,
- (getHeight() - mImageSize) / 2);
- }
-}
-
-void CheckBox::mouseEntered(MouseEvent& event A_UNUSED)
-{
- mHasMouse = true;
-}
-
-void CheckBox::mouseExited(MouseEvent& event)
-{
- mHasMouse = false;
- ToolTipListener::mouseExited(event);
-}
-
-void CheckBox::keyPressed(KeyEvent& event)
-{
- const InputActionT action = event.getActionId();
-
- if (action == InputAction::GUI_SELECT)
- {
- toggleSelected();
- event.consume();
- }
-}
-
-void CheckBox::adjustSize()
-{
- setHeight(getFont()->getHeight() + 2 * mPadding);
- setWidth(mImagePadding + mImageSize + mSpacing
- + getFont()->getWidth(mCaption) + mPadding);
-}
-
-void CheckBox::mouseClicked(MouseEvent& event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- toggleSelected();
- event.consume();
- }
-}
-
-void CheckBox::mouseDragged(MouseEvent& event)
-{
- event.consume();
-}
-
-void CheckBox::toggleSelected()
-{
- mSelected = !mSelected;
- distributeActionEvent();
-}
-
-void CheckBox::setCaption(const std::string& caption)
-{
- if (caption != mCaption)
- mTextChanged = true;
- mCaption = caption;
-}
-
-void CheckBox::setParent(Widget *widget)
-{
- if (mWindow != nullptr)
- mWindow->addWidgetListener(this);
- Widget::setParent(widget);
-}
-
-void CheckBox::widgetHidden(const Event &event A_UNUSED)
-{
- mTextChanged = true;
- mTextChunk.deleteImage();
-}
-
-void CheckBox::setWindow(Widget *const widget)
-{
- if ((widget == nullptr) && (mWindow != nullptr))
- {
- mWindow->removeWidgetListener(this);
- mWindow = nullptr;
- }
- else
- {
- Widget2::setWindow(widget);
- }
-}
diff --git a/src/gui/widgets/checkbox.h b/src/gui/widgets/checkbox.h
deleted file mode 100644
index 27e0a118b..000000000
--- a/src/gui/widgets/checkbox.h
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_CHECKBOX_H
-#define GUI_WIDGETS_CHECKBOX_H
-
-#include "listeners/keylistener.h"
-#include "listeners/tooltiplistener.h"
-
-#include "listeners/widgetlistener.h"
-
-#include "gui/fonts/textchunk.h"
-
-#include "gui/widgets/widget.h"
-
-#include "localconsts.h"
-
-class Skin;
-
-/**
- * Check box widget. Same as the Guichan check box but with custom look.
- *
- * \ingroup GUI
- */
-class CheckBox final : public Widget,
- public ToolTipListener,
- public KeyListener,
- public WidgetListener
-{
- public:
- /**
- * Constructor.
- */
- CheckBox(const Widget2 *const widget,
- const std::string &restrict caption,
- const bool selected = false,
- ActionListener *const listener = nullptr,
- const std::string &restrict eventId = "");
-
- A_DELETE_COPY(CheckBox)
-
- /**
- * Destructor.
- */
- ~CheckBox();
-
- /**
- * Draws the caption, then calls drawBox to draw the check box.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Update the alpha value to the checkbox components.
- */
- void updateAlpha();
-
- /**
- * Draws the check box, not the caption.
- */
- void drawBox(Graphics *const graphics) A_NONNULL(2);
-
- /**
- * Called when the mouse enteres the widget area.
- */
- void mouseEntered(MouseEvent& event) override final;
-
- /**
- * Called when the mouse leaves the widget area.
- */
- void mouseExited(MouseEvent& event) override final;
-
- void keyPressed(KeyEvent& event) override final;
-
- void adjustSize();
-
- /**
- * Checks if the check box is selected.
- *
- * @return True if the check box is selected, false otherwise.
- * @see setSelected
- */
- bool isSelected() const
- { return mSelected; }
-
- /**
- * Sets the check box to be selected or not.
- *
- * @param selected True if the check box should be set as selected.
- * @see isSelected
- */
- void setSelected(const bool selected)
- { mSelected = selected; }
-
- /**
- * Gets the caption of the check box.
- *
- * @return The caption of the check box.
- * @see setCaption
- */
- const std::string &getCaption() const
- { return mCaption; }
-
- /**
- * Sets the caption of the check box. It's advisable to call
- * adjustSize after setting of the caption to adjust the
- * check box's size to fit the caption.
- *
- * @param caption The caption of the check box.
- * @see getCaption, adjustSize
- */
- void setCaption(const std::string& caption);
-
- void mouseClicked(MouseEvent& event) override final;
-
- void mouseDragged(MouseEvent& event) override final;
-
- void setParent(Widget *widget) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void setWindow(Widget *const widget) override final;
-
- private:
- void toggleSelected();
-
- /**
- * True if the check box is selected, false otherwise.
- */
- bool mSelected;
-
- /**
- * Holds the caption of the check box.
- */
- std::string mCaption;
-
- TextChunk mTextChunk;
-
- int mPadding;
- int mImagePadding;
- int mImageSize;
- int mSpacing;
- int mTextX;
- bool mHasMouse;
- bool mDrawBox;
- bool mTextChanged;
-
- static int instances;
- static Skin *mSkin;
- static float mAlpha;
-};
-
-#endif // GUI_WIDGETS_CHECKBOX_H
diff --git a/src/gui/widgets/colorpage.cpp b/src/gui/widgets/colorpage.cpp
deleted file mode 100644
index fa3099c2c..000000000
--- a/src/gui/widgets/colorpage.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/colorpage.h"
-
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/colormodel.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-ColorPage::ColorPage(const Widget2 *const widget,
- ListModel *const listModel,
- const std::string &skin) :
- ListBox(widget, listModel, skin)
-{
- mItemPadding = mSkin != nullptr ? mSkin->getOption("itemPadding") : 1;
- const Font *const font = getFont();
- mRowHeight = CAST_U32(font->getHeight() +
- 2 * mItemPadding);
- if (mListModel != nullptr)
- {
- setHeight(CAST_S32(getRowHeight()) *
- mListModel->getNumberOfElements()
- + 2 * mPadding + 20);
- }
-}
-
-ColorPage::~ColorPage()
-{
-}
-
-void ColorPage::draw(Graphics *const graphics)
-{
- BLOCK_START("ColorPage::draw")
-
- const ColorModel *const model = static_cast<const ColorModel*>(
- mListModel);
-
- mHighlightColor.a = CAST_U32(mAlpha * 255.0F);
- updateAlpha();
- Font *const font = getFont();
-
- const int rowHeight = CAST_S32(getRowHeight());
- const int width = mDimension.width;
-
- if (mSelected >= 0)
- {
- graphics->setColor(mHighlightColor);
- graphics->fillRectangle(Rect(mPadding,
- rowHeight * mSelected + mPadding,
- mDimension.width - 2 * mPadding, rowHeight));
-
- const ColorPair *const colors = model->getColorAt(mSelected);
- const std::string str = mListModel->getElementAt(mSelected);
- font->drawString(graphics,
- *colors->color1,
- *colors->color2,
- str,
- (width - font->getWidth(str)) / 2,
- mSelected * rowHeight + mPadding);
- }
-
- const int sz = mListModel->getNumberOfElements();
- for (int i = 0, y = mPadding; i < sz; ++i, y += rowHeight)
- {
- if (i != mSelected)
- {
- const ColorPair *const colors = model->getColorAt(i);
- const std::string str = mListModel->getElementAt(i);
- font->drawString(graphics,
- *colors->color1,
- *colors->color2,
- str,
- (width - font->getWidth(str)) / 2,
- y);
- }
- }
-
- BLOCK_END("ColorPage::draw")
-}
-
-void ColorPage::safeDraw(Graphics *const graphics)
-{
- ColorPage::draw(graphics);
-}
-
-void ColorPage::resetAction()
-{
- setSelected(-1);
-}
-
-void ColorPage::adjustSize()
-{
- BLOCK_START("ColorPage::adjustSize")
- if (mListModel != nullptr)
- {
- setHeight(CAST_S32(getRowHeight()) *
- mListModel->getNumberOfElements() +
- 2 * mPadding + 20);
- }
- BLOCK_END("ColorPage::adjustSize")
-}
diff --git a/src/gui/widgets/colorpage.h b/src/gui/widgets/colorpage.h
deleted file mode 100644
index 6b0d4122b..000000000
--- a/src/gui/widgets/colorpage.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_COLORPAGE_H
-#define GUI_WIDGETS_COLORPAGE_H
-
-#include "gui/widgets/listbox.h"
-
-#include "localconsts.h"
-
-class ColorPage final : public ListBox
-{
- public:
- ColorPage(const Widget2 *const widget,
- ListModel *const listModel,
- const std::string &skin);
-
- A_DELETE_COPY(ColorPage)
-
- ~ColorPage();
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void resetAction();
-
- void adjustSize() override final;
-};
-
-#endif // GUI_WIDGETS_COLORPAGE_H
diff --git a/src/gui/widgets/container.cpp b/src/gui/widgets/container.cpp
deleted file mode 100644
index 2da444728..000000000
--- a/src/gui/widgets/container.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/container.h"
-
-#include "gui/gui.h"
-
-#include "debug.h"
-
-Container::Container(const Widget2 *const widget) :
- BasicContainer2(widget)
-{
- setOpaque(Opaque_false);
-}
-
-Container::~Container()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
- removeControls();
-}
-
-void Container::removeControls()
-{
- while (!mWidgets.empty())
- delete mWidgets.front();
-}
-
-bool Container::safeRemove(Widget *const widget)
-{
- for (WidgetListConstIterator iter = mWidgets.begin();
- iter != mWidgets.end(); ++iter)
- {
- if (*iter == widget)
- {
- remove(widget);
- return true;
- }
- }
- return false;
-}
diff --git a/src/gui/widgets/container.h b/src/gui/widgets/container.h
deleted file mode 100644
index 2d6e59001..000000000
--- a/src/gui/widgets/container.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CONTAINER_H
-#define GUI_WIDGETS_CONTAINER_H
-
-#include "gui/widgets/basiccontainer2.h"
-
-/**
- * A widget container.
- *
- * The main difference between the standard Guichan container and this one is
- * that childs added to this container are automatically deleted when the
- * container is deleted.
- *
- * This container is also non-opaque by default.
- */
-class Container notfinal : public BasicContainer2
-{
- public:
- explicit Container(const Widget2 *const widget);
-
- A_DELETE_COPY(Container)
-
- virtual ~Container();
-
- bool safeRemove(Widget *const widget);
-
- void removeControls();
-};
-
-#endif // GUI_WIDGETS_CONTAINER_H
diff --git a/src/gui/widgets/containerplacer.cpp b/src/gui/widgets/containerplacer.cpp
deleted file mode 100644
index 634a87fcd..000000000
--- a/src/gui/widgets/containerplacer.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/containerplacer.h"
-
-#include "gui/widgets/basiccontainer2.h"
-#include "gui/widgets/layoutcell.h"
-
-#include "debug.h"
-
-ContainerPlacer ContainerPlacer::at(const int x, const int y)
-{
- return ContainerPlacer(mContainer,
- mCell != nullptr ? &mCell->at(x, y) : nullptr);
-}
-
-LayoutCell &ContainerPlacer::operator()
- (const int x, const int y, Widget *const wg, const int w, const int h)
-{
- if (mContainer != nullptr)
- mContainer->add(wg);
- if (mCell != nullptr)
- return mCell->place(wg, x, y, w, h);
- return LayoutCell::emptyCell;
-}
diff --git a/src/gui/widgets/containerplacer.h b/src/gui/widgets/containerplacer.h
deleted file mode 100644
index cd1e0221e..000000000
--- a/src/gui/widgets/containerplacer.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CONTAINERPLACER_H
-#define GUI_WIDGETS_CONTAINERPLACER_H
-
-#include "localconsts.h"
-
-class BasicContainer2;
-class LayoutCell;
-class Widget;
-
-/**
- * This class is a helper for adding widgets to nested tables in a window.
- */
-class ContainerPlacer final
-{
- public:
- explicit ContainerPlacer(BasicContainer2 *const c = nullptr,
- LayoutCell *const lc = nullptr) :
- mContainer(c),
- mCell(lc)
- {}
-
- A_DEFAULT_COPY(ContainerPlacer)
-
- /**
- * Gets the pointed cell.
- */
- LayoutCell &getCell() A_WARN_UNUSED
- { return *mCell; }
-
- /**
- * Returns a placer for the same container but to an inner cell.
- */
- ContainerPlacer at(const int x,
- const int y) A_WARN_UNUSED;
-
- /**
- * Adds the given widget to the container and places it in the layout.
- * @see LayoutArray::place
- */
- LayoutCell &operator()(const int x,
- const int y,
- Widget *const wg,
- const int w = 1,
- const int h = 1);
-
- private:
- BasicContainer2 *mContainer;
- LayoutCell *mCell;
-};
-
-#endif // GUI_WIDGETS_CONTAINERPLACER_H
diff --git a/src/gui/widgets/createwidget.h b/src/gui/widgets/createwidget.h
deleted file mode 100644
index 5f5579d24..000000000
--- a/src/gui/widgets/createwidget.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2015-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_CREATEWIDGET_H
-#define GUI_WIDGETS_CREATEWIDGET_H
-
-#define CREATEWIDGETV(var, type, ...) \
- var = new type(__VA_ARGS__); \
- var->postInit()
-
-#define CREATEWIDGET(type, ...) \
- (new type(__VA_ARGS__))->postInit()
-
-#define CREATEWIDGETV0(var, type) \
- var = new type; \
- var->postInit()
-
-#define CREATEWIDGETR(type, ...) \
- static_cast<type*>(Widget::callPostInit(new type(__VA_ARGS__)))
-
-#define CREATEWIDGETR0(type) \
- static_cast<type*>(Widget::callPostInit(new type))
-
-#endif // GUI_WIDGETS_CREATEWIDGET_H
diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp
deleted file mode 100644
index 87eb14c48..000000000
--- a/src/gui/widgets/desktop.cpp
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana World Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/desktop.h"
-
-#include "configuration.h"
-#include "main.h"
-
-#include "gui/skin.h"
-
-#include "gui/widgets/staticbrowserbox.h"
-
-#include "input/inputmanager.h"
-
-#include "render/opengl/opengldebug.h"
-
-#include "resources/imagehelper.h"
-#include "resources/wallpaper.h"
-
-#include "resources/image/image.h"
-
-#include "resources/loaders/rescaledloader.h"
-
-#include "resources/resourcemanager/resourcemanager.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-Desktop *desktop = nullptr;
-
-Desktop::Desktop(const Widget2 *const widget) :
- Container(widget),
- LinkHandler(),
- WidgetListener(),
- mWallpaper(nullptr),
- mVersionLabel(new StaticBrowserBox(this, Opaque_false,
- "browserbox.xml")),
- mSkin(nullptr),
- mBackgroundGrayColor(getThemeColor(ThemeColorId::BACKGROUND_GRAY)),
- mShowBackground(true)
-{
- mBackgroundColor = getThemeColor(ThemeColorId::BACKGROUND, 128);
-
- addWidgetListener(this);
-
- Wallpaper::loadWallpapers();
-
- if (theme != nullptr)
- mSkin = theme->load("desktop.xml", "");
-
- if (mSkin != nullptr)
- mShowBackground = (mSkin->getOption("showBackground") != 0);
-
- const std::string appName = branding.getValue("appName", std::string());
- if (appName.empty())
- {
- mVersionLabel->addRow(FULL_VERSION);
- }
- else
- {
- mVersionLabel->addRow(strprintf("%s (%s)", FULL_VERSION,
- appName.c_str()));
- }
- mVersionLabel->addRow("copyright",
- "(C) ManaPlus developers, http://manaplus.org");
- mVersionLabel->setLinkHandler(this);
- mVersionLabel->updateHeight();
-}
-
-Desktop::~Desktop()
-{
- if (mWallpaper != nullptr)
- {
- mWallpaper->decRef();
- mWallpaper = nullptr;
- }
- if (theme != nullptr)
- theme->unload(mSkin);
-}
-
-void Desktop::postInit()
-{
- if (mSkin != nullptr)
- {
- addXY(mVersionLabel,
- mSkin->getOption("versionX", 25),
- mSkin->getOption("versionY", 2));
- }
- else
- {
- addXY(mVersionLabel, 25, 2);
- }
-}
-
-void Desktop::reloadWallpaper()
-{
- Wallpaper::loadWallpapers();
- setBestFittingWallpaper();
-}
-
-void Desktop::widgetResized(const Event &event A_UNUSED)
-{
- mVersionLabel->setSize(getWidth(), getHeight());
- mVersionLabel->updateHeight();
- setBestFittingWallpaper();
-}
-
-void Desktop::draw(Graphics *const graphics)
-{
- BLOCK_START("Desktop::draw")
- GLDEBUG_START("Desktop::draw")
-
- const Rect &rect = mDimension;
- const int width = rect.width;
- const int height = rect.height;
- if (mWallpaper != nullptr)
- {
- const int wallpWidth = mWallpaper->getWidth();
- const int wallpHeight = mWallpaper->getHeight();
-
- if (width > wallpWidth || height > wallpHeight)
- {
- graphics->setColor(mBackgroundGrayColor);
- graphics->fillRectangle(Rect(0, 0, width, height));
- }
-
- if (imageHelper->useOpenGL() == RENDER_SOFTWARE)
- {
- graphics->drawImage(mWallpaper,
- (width - wallpWidth) / 2,
- (height - wallpHeight) / 2);
- }
- else
- {
- graphics->drawRescaledImage(mWallpaper, 0, 0, width, height);
- }
- }
- else
- {
- graphics->setColor(mBackgroundGrayColor);
- graphics->fillRectangle(Rect(0, 0, width, height));
- }
-
- Container::draw(graphics);
- GLDEBUG_END()
- BLOCK_END("Desktop::draw")
-}
-
-void Desktop::safeDraw(Graphics *const graphics)
-{
- Desktop::draw(graphics);
-}
-
-void Desktop::setBestFittingWallpaper()
-{
- if (!mShowBackground || !config.getBoolValue("showBackground"))
- return;
-
- const std::string wallpaperName =
- Wallpaper::getWallpaper(getWidth(), getHeight());
-
- Image *const nWallPaper = Theme::getImageFromTheme(wallpaperName);
-
- if (nWallPaper != nullptr)
- {
- if (mWallpaper != nullptr)
- {
- ResourceManager::decRefDelete(mWallpaper);
- mWallpaper = nullptr;
- }
-
- const Rect &rect = mDimension;
- const int width = rect.width;
- const int height = rect.height;
-
- if (imageHelper->useOpenGL() == RENDER_SOFTWARE &&
- (nWallPaper->getWidth() != width ||
- nWallPaper->getHeight() != height))
- {
- // We rescale to obtain a fullscreen wallpaper...
- Image *const newRsclWlPpr = Loader::getRescaled(
- nWallPaper, width, height);
-
- if (newRsclWlPpr != nullptr)
- {
- ResourceManager::decRefDelete(nWallPaper);
- // We replace the resource in the resource manager
- mWallpaper = newRsclWlPpr;
- }
- else
- {
- mWallpaper = nWallPaper;
- }
- }
- else
- {
- mWallpaper = nWallPaper;
- }
- }
- else
- {
- logger->log("Couldn't load %s as wallpaper", wallpaperName.c_str());
- }
-}
-
-void Desktop::handleLink(const std::string &link, MouseEvent *event A_UNUSED)
-{
- if (link == "copyright")
- inputManager.executeAction(InputAction::WINDOW_ABOUT);
-}
diff --git a/src/gui/widgets/desktop.h b/src/gui/widgets/desktop.h
deleted file mode 100644
index 8a655892d..000000000
--- a/src/gui/widgets/desktop.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana World Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_DESKTOP_H
-#define GUI_WIDGETS_DESKTOP_H
-
-#include "gui/widgets/container.h"
-
-#include "gui/widgets/linkhandler.h"
-
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-class StaticBrowserBox;
-class Image;
-class Skin;
-
-/**
- * Desktop widget, for drawing a background image and color.
- *
- * It picks the best fitting background image. If the image doesn't fit, a
- * background color is drawn and the image is centered.
- *
- * When the desktop widget is resized, the background image is automatically
- * updated.
- *
- * The desktop also displays the client version in the top-right corner.
- *
- * \ingroup GUI
- */
-class Desktop final : public Container,
- public LinkHandler,
- public WidgetListener
-{
- public:
- explicit Desktop(const Widget2 *const widget);
-
- A_DELETE_COPY(Desktop)
-
- ~Desktop();
-
- /**
- * Has to be called after updates have been loaded.
- */
- void reloadWallpaper();
-
- void widgetResized(const Event &event) override final;
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void postInit() override final;
-
- void handleLink(const std::string &link,
- MouseEvent *event) override final;
- private:
- void setBestFittingWallpaper();
-
- Image *mWallpaper;
- StaticBrowserBox *mVersionLabel;
- Skin *mSkin;
- Color mBackgroundGrayColor;
- bool mShowBackground;
-};
-
-extern Desktop *desktop;
-
-#endif // GUI_WIDGETS_DESKTOP_H
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
deleted file mode 100644
index cb9eef73d..000000000
--- a/src/gui/widgets/dropdown.cpp
+++ /dev/null
@@ -1,580 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2006-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/dropdown.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/extendedlistmodel.h"
-
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/popuplist.h"
-
-#include "render/graphics.h"
-
-#include "resources/imagerect.h"
-
-#include "debug.h"
-
-int DropDown::instances = 0;
-Image *DropDown::buttons[2][2];
-ImageRect DropDown::skinRect;
-float DropDown::mAlpha = 1.0;
-Skin *DropDown::mSkin = nullptr;
-
-static std::string const dropdownFiles[2] =
-{
- "dropdown.xml",
- "dropdown_pressed.xml"
-};
-
-DropDown::DropDown(const Widget2 *const widget,
- ListModel *const listModel,
- const bool extended,
- const Modal modal,
- ActionListener *const listener,
- const std::string &eventId) :
- ActionListener(),
- BasicContainer(widget),
- KeyListener(),
- MouseListener(),
- FocusListener(),
- SelectionListener(),
- mPopup(CREATEWIDGETR(PopupList, this, listModel, extended, modal)),
- mShadowColor(getThemeColor(ThemeColorId::DROPDOWN_SHADOW)),
- mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT)),
- mPadding(1),
- mImagePadding(2),
- mSpacing(0),
- mFoldedUpHeight(0),
- mSelectionListeners(),
- mExtended(extended),
- mDroppedDown(false),
- mPushed(false),
- mIsDragged(false)
-{
- mAllowLogic = false;
- mFrameSize = 2;
- mForegroundColor2 = getThemeColor(ThemeColorId::DROPDOWN_OUTLINE);
-
- mPopup->setHeight(100);
-
- // Initialize graphics
- if (instances == 0 && (theme != nullptr))
- {
- // Load the background skin
- for (int i = 0; i < 2; i ++)
- {
- Skin *const skin = theme->load(dropdownFiles[i], "dropdown.xml");
- if (skin != nullptr)
- {
- if (i == 0)
- mSkin = skin;
- const ImageRect &rect = skin->getBorder();
- for (int f = 0; f < 2; f ++)
- {
- if (rect.grid[f] != nullptr)
- {
- rect.grid[f]->incRef();
- buttons[f][i] = rect.grid[f];
- buttons[f][i]->setAlpha(mAlpha);
- }
- else
- {
- buttons[f][i] = nullptr;
- }
- }
- if (i != 0)
- theme->unload(skin);
- }
- else
- {
- for (int f = 0; f < 2; f ++)
- buttons[f][i] = nullptr;
- }
- }
-
- // get the border skin
- theme->loadRect(skinRect, "dropdown_background.xml", "");
- }
-
- instances++;
-
- setWidth(100);
- setFocusable(true);
- setListModel(listModel);
-
- if (mPopup->getSelected() < 0)
- mPopup->setSelected(0);
-
- addMouseListener(this);
- addKeyListener(this);
- addFocusListener(this);
-
- adjustHeight();
-// mPopup->setForegroundColorAll(getThemeColor(ThemeColorId::DROPDOWN),
-// getThemeColor(ThemeColorId::DROPDOWN_OUTLINE));
- mForegroundColor = getThemeColor(ThemeColorId::DROPDOWN);
- mForegroundColor2 = getThemeColor(ThemeColorId::DROPDOWN_OUTLINE);
-
- if (!eventId.empty())
- setActionEventId(eventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-
- mPopup->adjustSize();
-
- if (mSkin != nullptr)
- {
- mSpacing = mSkin->getOption("spacing");
- mFrameSize = CAST_U32(mSkin->getOption("frameSize"));
- mPadding = mSkin->getPadding();
- mImagePadding = mSkin->getOption("imagePadding");
- }
- adjustHeight();
-}
-
-DropDown::~DropDown()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- instances--;
- if (instances == 0)
- {
- for (int f = 0; f < 2; f ++)
- {
- for (int i = 0; i < 2; i ++)
- {
- if (buttons[f][i] != nullptr)
- buttons[f][i]->decRef();
- }
- }
- if (theme != nullptr)
- {
- theme->unload(mSkin);
- Theme::unloadRect(skinRect);
- }
- }
-}
-
-void DropDown::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (mAlpha != alpha)
- {
- mAlpha = alpha;
-
- if (buttons[0][0] != nullptr)
- buttons[0][0]->setAlpha(mAlpha);
- if (buttons[0][1] != nullptr)
- buttons[0][1]->setAlpha(mAlpha);
- if (buttons[1][0] != nullptr)
- buttons[1][0]->setAlpha(mAlpha);
- if (buttons[1][1] != nullptr)
- buttons[1][1]->setAlpha(mAlpha);
-
- for (int a = 0; a < 9; a++)
- {
- if (skinRect.grid[a] != nullptr)
- skinRect.grid[a]->setAlpha(mAlpha);
- }
- }
-}
-
-void DropDown::draw(Graphics *const graphics)
-{
- BLOCK_START("DropDown::draw")
- int h;
-
- if (mDroppedDown)
- h = mFoldedUpHeight;
- else
- h = mDimension.height;
-
- updateAlpha();
-
- const unsigned int alpha = CAST_U32(mAlpha * 255.0F);
- const int pad = 2 * mPadding;
- mHighlightColor.a = alpha;
- mShadowColor.a = alpha;
-
- ListModel *const model = mPopup->getListModel();
- if ((model != nullptr) && mPopup->getSelected() >= 0)
- {
- Font *const font = getFont();
- if (mExtended)
- {
- const int sel = mPopup->getSelected();
- ExtendedListModel *const model2
- = static_cast<ExtendedListModel *>(model);
- const Image *const image = model2->getImageAt(sel);
- if (image == nullptr)
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- model->getElementAt(sel),
- mPadding, mPadding);
- }
- else
- {
- graphics->drawImage(image,
- mImagePadding,
- (mDimension.height - image->getHeight()) / 2 + mPadding);
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- model->getElementAt(sel),
- image->getWidth() + mImagePadding + mSpacing, mPadding);
- }
- }
- else
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- model->getElementAt(mPopup->getSelected()),
- mPadding, mPadding);
- }
- }
-
- if (isFocused())
- {
- graphics->setColor(mHighlightColor);
- graphics->drawRectangle(Rect(mPadding, mPadding,
- mDimension.width - h - pad, h - pad));
- }
-
- drawButton(graphics);
-
- if (mDroppedDown)
- {
- // Draw two lines separating the ListBox with selected
- // element view.
- const int w = mDimension.width;
- graphics->setColor(mHighlightColor);
- graphics->drawLine(0, h, w, h);
- graphics->setColor(mShadowColor);
- graphics->drawLine(0, h + 1, w, h + 1);
- }
- BLOCK_END("DropDown::draw")
-}
-
-void DropDown::safeDraw(Graphics *const graphics)
-{
- DropDown::draw(graphics);
-}
-
-void DropDown::drawFrame(Graphics *const graphics)
-{
- BLOCK_START("DropDown::drawFrame")
- const int bs2 = CAST_S32(getFrameSize());
- const Rect &rect = mDimension;
- graphics->drawImageRect(0, 0,
- rect.width + bs2, rect.height + bs2,
- skinRect);
- BLOCK_END("DropDown::drawFrame")
-}
-
-void DropDown::safeDrawFrame(Graphics *const graphics)
-{
- BLOCK_START("DropDown::drawFrame")
- const int bs2 = CAST_S32(getFrameSize());
- const Rect &rect = mDimension;
- graphics->drawImageRect(0, 0,
- rect.width + bs2, rect.height + bs2,
- skinRect);
- BLOCK_END("DropDown::drawFrame")
-}
-
-void DropDown::drawButton(Graphics *const graphics)
-{
- const int height = mDroppedDown ? mFoldedUpHeight : mDimension.height;
-
- Image *image = buttons[mDroppedDown][mPushed];
- if (image != nullptr)
- {
- graphics->drawImage(image,
- mDimension.width - image->getWidth() - mImagePadding,
- (height - image->getHeight()) / 2);
- }
-}
-
-void DropDown::keyPressed(KeyEvent& event)
-{
- if (event.isConsumed())
- return;
-
- const InputActionT actionId = event.getActionId();
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (actionId)
- {
- case InputAction::GUI_SELECT:
- case InputAction::GUI_SELECT2:
- dropDown();
- break;
-
- case InputAction::GUI_UP:
- setSelected(getSelected() - 1);
- break;
-
- case InputAction::GUI_DOWN:
- setSelected(getSelected() + 1);
- break;
-
- case InputAction::GUI_HOME:
- setSelected(0);
- break;
-
- case InputAction::GUI_END:
- if (mPopup->getListModel() != nullptr)
- {
- setSelected(mPopup->getListModel()->
- getNumberOfElements() - 1);
- }
- break;
-
- default:
- return;
- }
- PRAGMA45(GCC diagnostic pop)
-
- event.consume();
-}
-
-void DropDown::hideDrop(bool event)
-{
- if (event)
- distributeActionEvent();
- mPopup->setVisible(Visible_false);
-}
-
-void DropDown::mousePressed(MouseEvent& event)
-{
- event.consume();
- // If we have a mouse press on the widget.
- if (event.getButton() == MouseButton::LEFT
- && !mDroppedDown && event.getSource() == this)
- {
- mPushed = true;
- dropDown();
- }
- else
- {
- mPushed = false;
- foldUp();
- hideDrop();
- }
-}
-
-void DropDown::mouseReleased(MouseEvent &event)
-{
- if (mIsDragged)
- mPushed = false;
-
- const MouseButtonT 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)
- && button == MouseButton::LEFT)
- {
- if (mIsDragged)
- foldUp();
- }
- else if (button == MouseButton::LEFT)
- {
- mPushed = false;
- }
-
- mIsDragged = false;
-}
-
-void DropDown::mouseDragged(MouseEvent &event)
-{
- mIsDragged = true;
- event.consume();
-}
-
-void DropDown::mouseWheelMovedUp(MouseEvent& event)
-{
- setSelected(getSelected() - 1);
- event.consume();
-}
-
-void DropDown::mouseWheelMovedDown(MouseEvent& event)
-{
- setSelected(getSelected() + 1);
- event.consume();
-}
-
-void DropDown::setSelectedString(const std::string &str)
-{
- ListModel *const listModel = mPopup->getListModel();
- if (listModel == nullptr)
- return;
-
- for (int f = 0; f < listModel->getNumberOfElements(); f ++)
- {
- if (listModel->getElementAt(f) == str)
- {
- setSelected(f);
- break;
- }
- }
-}
-
-std::string DropDown::getSelectedString() const
-{
- ListModel *const listModel = mPopup->getListModel();
- if (listModel == nullptr)
- return "";
-
- return listModel->getElementAt(getSelected());
-}
-
-void DropDown::adjustHeight()
-{
- setHeight(getFont()->getHeight() + 2 * mPadding);
-}
-
-void DropDown::dropDown()
-{
- if (!mDroppedDown)
- {
- if (mParent == nullptr)
- return;
- mDroppedDown = true;
- mFoldedUpHeight = getHeight();
- adjustHeight();
-
- int x = 0;
- int y = 0;
- getAbsolutePosition(x, y);
- const int frame = CAST_S32(mParent->getFrameSize());
- const int pad = mPopup->getPadding();
- const int pad2 = pad * 2;
-
- // here width should be adjusted on some other parameters
- mPopup->setWidth(mDimension.width - pad2 + 8);
- mPopup->show(x - mPadding - frame - 1, y + mDimension.height);
- mPopup->requestMoveToTop();
- mPopup->requestFocus();
- }
-}
-
-void DropDown::foldUp()
-{
- if (mDroppedDown)
- {
- mDroppedDown = false;
- adjustHeight();
- }
-}
-
-int DropDown::getSelected() const
-{
- return mPopup->getSelected();
-}
-
-void DropDown::setSelected(int selected)
-{
- if (selected >= 0)
- mPopup->setSelected(selected);
-}
-
-void DropDown::setListModel(ListModel *const listModel)
-{
- mPopup->setListModel(listModel);
-
- if (mPopup->getSelected() < 0)
- mPopup->setSelected(0);
-
- adjustHeight();
-}
-
-ListModel *DropDown::getListModel()
-{
- return mPopup->getListModel();
-}
-
-void DropDown::action(const ActionEvent &actionEvent A_UNUSED)
-{
- foldUp();
- distributeActionEvent();
-}
-
-Rect DropDown::getChildrenArea()
-{
- if (mDroppedDown)
- {
- // Calculate the children area (with the one pixel border in mind)
- return Rect(1, mFoldedUpHeight + 1,
- mDimension.width - 2, mDimension.height - mFoldedUpHeight - 2);
- }
-
- return Rect();
-}
-
-void DropDown::valueChanged(const SelectionEvent& event A_UNUSED)
-{
-}
-
-void DropDown::updateSelection()
-{
- mDroppedDown = false;
- mPushed = false;
- distributeActionEvent();
- distributeValueChangedEvent();
-}
-
-void DropDown::addSelectionListener(SelectionListener* selectionListener)
-{
- mSelectionListeners.push_back(selectionListener);
-}
-
-void DropDown::removeSelectionListener(SelectionListener* listener)
-{
- mSelectionListeners.remove(listener);
-}
-
-void DropDown::distributeValueChangedEvent()
-{
- for (SelectionListenerIterator iter = mSelectionListeners.begin();
- iter != mSelectionListeners.end();
- ++iter)
- {
- SelectionEvent event(this);
- (*iter)->valueChanged(event);
- }
-}
diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h
deleted file mode 100644
index 029850766..000000000
--- a/src/gui/widgets/dropdown.h
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2006-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_DROPDOWN_H
-#define GUI_WIDGETS_DROPDOWN_H
-
-#include "enums/simpletypes/modal.h"
-
-#include "gui/widgets/basiccontainer.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/focuslistener.h"
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-#include "listeners/selectionlistener.h"
-
-#include "localconsts.h"
-
-class Image;
-class ListModel;
-class PopupList;
-class Skin;
-
-/**
- * A drop down box from which you can select different values.
- *
- * A ListModel provides the contents of the drop down. To be able to use
- * DropDown you must give DropDown an implemented ListModel which represents
- * your list.
- */
-class DropDown final : public ActionListener,
- public BasicContainer,
- public KeyListener,
- public MouseListener,
- public FocusListener,
- public SelectionListener
-{
- public:
- DropDown(const Widget2 *const widget,
- ListModel *const listModel,
- const bool extended = false,
- const Modal modal = Modal_false,
- ActionListener *const listener = nullptr,
- const std::string &eventId = "");
-
- A_DELETE_COPY(DropDown)
-
- ~DropDown();
-
- /**
- * Update the alpha value to the graphic components.
- */
- void updateAlpha();
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void drawFrame(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDrawFrame(Graphics *const graphics) override final
- A_NONNULL(2);
-
- // Inherited from KeyListener
-
- void keyPressed(KeyEvent& event) override final;
-
- // Inherited from MouseListener
-
- void mousePressed(MouseEvent& event) override final;
-
- void mouseReleased(MouseEvent& event) override final;
-
- void mouseDragged(MouseEvent& event) override final;
-
- void mouseWheelMovedUp(MouseEvent& event) override final;
-
- void mouseWheelMovedDown(MouseEvent& event) override final;
-
- void setSelectedString(const std::string &str);
-
- std::string getSelectedString() const A_WARN_UNUSED;
-
- void valueChanged(const SelectionEvent& event) override final A_CONST;
-
- void updateSelection();
-
- void adjustHeight();
-
- void dropDown();
-
- void foldUp();
-
- void hideDrop(bool event = true);
-
- int getSelected() const;
-
- void setSelected(int selected);
-
- void setListModel(ListModel *const listModel);
-
- ListModel *getListModel();
-
- void addSelectionListener(SelectionListener* listener);
-
- void removeSelectionListener(SelectionListener* selectionListener);
-
- Rect getChildrenArea() override;
-
- void action(const ActionEvent &actionEvent) override;
-
- void distributeValueChangedEvent();
-
- protected:
- /**
- * Draws the button with the little down arrow.
- *
- * @param graphics a Graphics object to draw with.
- */
- void drawButton(Graphics *const graphics) A_NONNULL(2);
-
- PopupList *mPopup A_NONNULLPOINTER;
- Color mShadowColor;
- Color mHighlightColor;
- int mPadding;
- int mImagePadding;
- int mSpacing;
- int mFoldedUpHeight;
-
- typedef std::list<SelectionListener*> SelectionListenerList;
- SelectionListenerList mSelectionListeners;
- typedef SelectionListenerList::iterator SelectionListenerIterator;
-
- bool mExtended;
- bool mDroppedDown;
- bool mPushed;
- bool mIsDragged;
-
- // Add own Images.
- static int instances;
- static Image *buttons[2][2];
- static ImageRect skinRect;
- static float mAlpha;
- static Skin *mSkin;
-};
-
-#endif // GUI_WIDGETS_DROPDOWN_H
diff --git a/src/gui/widgets/emotepage.cpp b/src/gui/widgets/emotepage.cpp
deleted file mode 100644
index 27721a86c..000000000
--- a/src/gui/widgets/emotepage.cpp
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/emotepage.h"
-
-#include "render/graphics.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "resources/imageset.h"
-
-#include "resources/loaders/imagesetloader.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-namespace
-{
- const unsigned int emoteWidth = 17;
- const unsigned int emoteHeight = 18;
-} // namespace
-
-EmotePage::EmotePage(const Widget2 *const widget) :
- Widget(widget),
- MouseListener(),
- WidgetListener(),
- mEmotes(Loader::getImageSet(
- "graphics/sprites/chatemotes.png", emoteWidth, emoteHeight)),
- mVertexes(new ImageCollection),
- mSelectedIndex(-1)
-{
- addMouseListener(this);
- addWidgetListener(this);
- mAllowLogic = false;
-}
-
-EmotePage::~EmotePage()
-{
- if (mEmotes != nullptr)
- {
- mEmotes->decRef();
- mEmotes = nullptr;
- }
- delete2(mVertexes);
-}
-
-void EmotePage::draw(Graphics *const graphics)
-{
- BLOCK_START("EmotePage::draw")
-
- if (mRedraw)
- {
- if (mEmotes == nullptr)
- return;
-
- const STD_VECTOR<Image*> &images = mEmotes->getImages();
-
- const unsigned int width = mDimension.width;
- unsigned int x = 0;
- unsigned int y = 0;
-
- mRedraw = false;
- mVertexes->clear();
- FOR_EACH (STD_VECTOR<Image*>::const_iterator, it, images)
- {
- const Image *const image = *it;
- if (image != nullptr)
- {
- graphics->calcTileCollection(mVertexes, image, x, y);
- x += emoteWidth;
- if (x + emoteWidth > width)
- {
- x = 0;
- y += emoteHeight;
- }
- }
- }
- graphics->finalize(mVertexes);
- }
- graphics->drawTileCollection(mVertexes);
-
- BLOCK_END("EmotePage::draw")
-}
-
-void EmotePage::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("EmotePage::safeDraw")
-
- if (mEmotes == nullptr)
- return;
-
- const STD_VECTOR<Image*> &images = mEmotes->getImages();
-
- const unsigned int width = mDimension.width;
- unsigned int x = 0;
- unsigned int y = 0;
-
- FOR_EACH (STD_VECTOR<Image*>::const_iterator, it, images)
- {
- const Image *const image = *it;
- if (image != nullptr)
- {
- graphics->drawImage(image, x, y);
- x += emoteWidth;
- if (x + emoteWidth > width)
- {
- x = 0;
- y += emoteHeight;
- }
- }
- }
-
- BLOCK_END("EmotePage::safeDraw")
-}
-
-void EmotePage::mousePressed(MouseEvent &event)
-{
- mSelectedIndex = getIndexFromGrid(event.getX(), event.getY());
- event.consume();
- distributeActionEvent();
-}
-
-int EmotePage::getIndexFromGrid(const int x, const int y) const
-{
- const int width = mDimension.width;
- if (x < 0 || x > width || y < 0 || y > mDimension.height)
- return -1;
- const int cols = width / emoteWidth;
- const int index = (y / emoteHeight) * cols + (x / emoteWidth);
- if (index >= CAST_S32(mEmotes->size()))
- return -1;
- return index;
-}
-
-void EmotePage::resetAction()
-{
- mSelectedIndex = -1;
-}
-
-void EmotePage::widgetResized(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void EmotePage::widgetMoved(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
diff --git a/src/gui/widgets/emotepage.h b/src/gui/widgets/emotepage.h
deleted file mode 100644
index a833e569f..000000000
--- a/src/gui/widgets/emotepage.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_EMOTEPAGE_H
-#define GUI_WIDGETS_EMOTEPAGE_H
-
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "gui/widgets/widget.h"
-
-#include "localconsts.h"
-
-class ImageCollection;
-
-class EmotePage final : public Widget,
- public MouseListener,
- public WidgetListener
-{
- public:
- explicit EmotePage(const Widget2 *const widget);
-
- A_DELETE_COPY(EmotePage)
-
- ~EmotePage();
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void mousePressed(MouseEvent &event) override final;
-
- int getIndexFromGrid(const int x, const int y) const;
-
- void widgetResized(const Event &event A_UNUSED) override final;
-
- void widgetMoved(const Event &event A_UNUSED) override final;
-
- void resetAction();
-
- int getSelectedIndex() const
- { return mSelectedIndex; }
-
- private:
- ImageSet *mEmotes;
- ImageCollection *mVertexes;
- int mSelectedIndex;
-};
-
-#endif // GUI_WIDGETS_EMOTEPAGE_H
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
deleted file mode 100644
index 37acf7263..000000000
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/emoteshortcutcontainer.h"
-
-#include "settings.h"
-
-#include "input/inputmanager.h"
-
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/shortcut/emoteshortcut.h"
-
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/textpopup.h"
-
-#include "input/inputactionoperators.h"
-
-#include "resources/emotesprite.h"
-
-#include "resources/db/emotedb.h"
-
-#include "resources/image/image.h"
-
-#include "resources/sprite/animatedsprite.h"
-
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-static const int MAX_ITEMS = 48;
-
-EmoteShortcutContainer::EmoteShortcutContainer(Widget2 *restrict const
- widget) :
- ShortcutContainer(widget),
- mEmoteImg(),
- mEmoteClicked(false),
- mEmoteMoved(0)
-{
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(settings.guiAlpha);
-
- // Setup emote sprites
- for (int i = 0; i <= EmoteDB::getLast(); i++)
- {
- const EmoteSprite *const sprite = EmoteDB::getSprite(i, true);
- if ((sprite != nullptr) && (sprite->sprite != nullptr))
- mEmoteImg.push_back(sprite);
- }
-
- mMaxItems = MAX_ITEMS;
-}
-
-EmoteShortcutContainer::~EmoteShortcutContainer()
-{
-}
-
-void EmoteShortcutContainer::setWidget2(const Widget2 *restrict const widget)
- restrict2
-{
- Widget2::setWidget2(widget);
- mForegroundColor = getThemeColor(ThemeColorId::TEXT);
- mForegroundColor2 = getThemeColor(ThemeColorId::TEXT_OUTLINE);
-}
-
-void EmoteShortcutContainer::draw(Graphics *restrict graphics) restrict2
-{
- if (emoteShortcut == nullptr)
- return;
-
- BLOCK_START("EmoteShortcutContainer::draw")
- if (settings.guiAlpha != mAlpha)
- {
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- mAlpha = settings.guiAlpha;
- }
-
- Font *const font = getFont();
- drawBackground(graphics);
-
- unsigned sz = CAST_U32(mEmoteImg.size());
- if (sz > mMaxItems)
- sz = mMaxItems;
- for (unsigned i = 0; i < sz; i++)
- {
- const EmoteSprite *restrict const emoteImg = mEmoteImg[i];
- if (emoteImg != nullptr)
- {
- const AnimatedSprite *restrict const sprite = emoteImg->sprite;
- if (sprite != nullptr)
- {
- sprite->draw(graphics,
- (i % mGridWidth) * mBoxWidth + 2,
- (i / mGridWidth) * mBoxHeight + 10);
- }
- }
- }
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int emoteX = (i % mGridWidth) * mBoxWidth;
- const int emoteY = (i / mGridWidth) * mBoxHeight;
-
- // Draw emote keyboard shortcut.
- const std::string key = inputManager.getKeyValueString(
- InputAction::EMOTE_1 + i);
-
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- key,
- emoteX + 2, emoteY + 2);
- }
-
- BLOCK_END("EmoteShortcutContainer::draw")
-}
-
-void EmoteShortcutContainer::safeDraw(Graphics *restrict graphics) restrict2
-{
- if (emoteShortcut == nullptr)
- return;
-
- BLOCK_START("EmoteShortcutContainer::draw")
- if (settings.guiAlpha != mAlpha)
- {
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- mAlpha = settings.guiAlpha;
- }
-
- Font *const font = getFont();
- safeDrawBackground(graphics);
-
- unsigned sz = CAST_U32(mEmoteImg.size());
- if (sz > mMaxItems)
- sz = mMaxItems;
- for (unsigned i = 0; i < sz; i++)
- {
- const EmoteSprite *restrict const emoteImg = mEmoteImg[i];
- if (emoteImg != nullptr)
- {
- const AnimatedSprite *restrict const sprite = emoteImg->sprite;
- if (sprite != nullptr)
- {
- sprite->draw(graphics,
- (i % mGridWidth) * mBoxWidth + 2,
- (i / mGridWidth) * mBoxHeight + 10);
- }
- }
- }
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int emoteX = (i % mGridWidth) * mBoxWidth;
- const int emoteY = (i / mGridWidth) * mBoxHeight;
-
- // Draw emote keyboard shortcut.
- const std::string key = inputManager.getKeyValueString(
- InputAction::EMOTE_1 + i);
-
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- key,
- emoteX + 2, emoteY + 2);
- }
-
- BLOCK_END("EmoteShortcutContainer::draw")
-}
-
-void EmoteShortcutContainer::mouseDragged(MouseEvent &restrict event A_UNUSED)
- restrict2
-{
-}
-
-void EmoteShortcutContainer::mousePressed(MouseEvent &restrict event) restrict2
-{
- if (event.isConsumed())
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- if (emoteShortcut == nullptr)
- return;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- event.consume();
- // Stores the selected emote if there is one.
- if (emoteShortcut->isEmoteSelected())
- {
- emoteShortcut->setEmote(index);
- emoteShortcut->setEmoteSelected(0);
- }
- else if (emoteShortcut->getEmote(index) != 0u)
- {
- mEmoteClicked = true;
- }
- }
- else if (event.getButton() == MouseButton::RIGHT)
- {
- if (popupMenu != nullptr)
- {
- event.consume();
- popupMenu->showEmoteType();
- }
- }
-}
-
-void EmoteShortcutContainer::mouseReleased(MouseEvent &restrict event)
- restrict2
-{
- if (emoteShortcut == nullptr)
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (emoteShortcut->isEmoteSelected())
- emoteShortcut->setEmoteSelected(0);
-
- if (index == -1)
- {
- mEmoteMoved = 0;
- return;
- }
-
- if (mEmoteMoved != 0u)
- {
- emoteShortcut->setEmotes(index, mEmoteMoved);
- mEmoteMoved = 0;
- }
- else if ((emoteShortcut->getEmote(index) != 0u) && mEmoteClicked)
- {
- emoteShortcut->useEmote(index + 1);
- }
-
- mEmoteClicked = false;
- }
-}
-
-void EmoteShortcutContainer::mouseMoved(MouseEvent &restrict event) restrict2
-{
- if ((emoteShortcut == nullptr) || (textPopup == nullptr))
- return;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- textPopup->setVisible(Visible_false);
-
- if (CAST_SIZE(index) < mEmoteImg.size() && (mEmoteImg[index] != nullptr))
- {
- const EmoteSprite *restrict const sprite = mEmoteImg[index];
- textPopup->show(viewport->mMouseX, viewport->mMouseY,
- strprintf("%s, %d", sprite->name.c_str(), sprite->id));
- }
-}
-
-void EmoteShortcutContainer::mouseExited(MouseEvent &restrict event A_UNUSED)
- restrict2
-{
- if (textPopup != nullptr)
- textPopup->setVisible(Visible_false);
-}
-
-void EmoteShortcutContainer::widgetHidden(const Event &restrict event A_UNUSED)
- restrict2
-{
- if (textPopup != nullptr)
- textPopup->setVisible(Visible_false);
-}
diff --git a/src/gui/widgets/emoteshortcutcontainer.h b/src/gui/widgets/emoteshortcutcontainer.h
deleted file mode 100644
index 14895d7a0..000000000
--- a/src/gui/widgets/emoteshortcutcontainer.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_EMOTESHORTCUTCONTAINER_H
-#define GUI_WIDGETS_EMOTESHORTCUTCONTAINER_H
-
-#include "gui/widgets/shortcutcontainer.h"
-
-struct EmoteSprite;
-
-/**
- * An emote shortcut container. Used to quickly use emoticons.
- *
- * \ingroup GUI
- */
-class EmoteShortcutContainer final : public ShortcutContainer
-{
- public:
- /**
- * Constructor. Initializes the graphic.
- */
- explicit EmoteShortcutContainer(Widget2 *restrict const widget);
-
- A_DELETE_COPY(EmoteShortcutContainer)
-
- /**
- * Destructor.
- */
- ~EmoteShortcutContainer();
-
- /**
- * Draws the items.
- */
- void draw(Graphics *restrict graphics)
- restrict2 override final A_NONNULL(2);
-
- void safeDraw(Graphics *restrict graphics)
- restrict2 override final A_NONNULL(2);
-
- /**
- * Handles mouse when dragged.
- */
- void mouseDragged(MouseEvent &restrict event)
- restrict2 override final A_CONST;
-
- /**
- * Handles mouse when pressed.
- */
- void mousePressed(MouseEvent &restrict event) restrict2 override final;
-
- /**
- * Handles mouse release.
- */
- void mouseReleased(MouseEvent &restrict event)
- restrict2 override final;
-
- void mouseMoved(MouseEvent &restrict event) restrict2 override final;
-
- void mouseExited(MouseEvent &restrict event) restrict2 override final;
-
- void widgetHidden(const Event &restrict event)
- restrict2 override final;
-
- void setWidget2(const Widget2 *restrict const widget)
- restrict2 override final;
-
- private:
- STD_VECTOR<const EmoteSprite*> mEmoteImg;
-
- bool mEmoteClicked;
- unsigned char mEmoteMoved;
-};
-
-#endif // GUI_WIDGETS_EMOTESHORTCUTCONTAINER_H
diff --git a/src/gui/widgets/equipmentbox.h b/src/gui/widgets/equipmentbox.h
deleted file mode 100644
index 055332b2b..000000000
--- a/src/gui/widgets/equipmentbox.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_EQUIPMENTBOX_H
-#define GUI_WIDGETS_EQUIPMENTBOX_H
-
-#include "localconsts.h"
-
-class Image;
-
-struct EquipmentBox final
-{
- EquipmentBox(const int x0, const int y0, Image *const img) :
- x(x0), y(y0), image(img)
- { }
-
- A_DELETE_COPY(EquipmentBox)
-
- int x;
- int y;
- Image *image;
-};
-
-#endif // GUI_WIDGETS_EQUIPMENTBOX_H
diff --git a/src/gui/widgets/equipmentpage.h b/src/gui/widgets/equipmentpage.h
deleted file mode 100644
index f868478fb..000000000
--- a/src/gui/widgets/equipmentpage.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_EQUIPMENTPAGE_H
-#define GUI_WIDGETS_EQUIPMENTPAGE_H
-
-#include "utils/vector.h"
-
-#include "localconsts.h"
-
-class PlayerBox;
-
-struct EquipmentBox;
-
-struct EquipmentPage final
-{
- EquipmentPage() :
- boxes(),
- x(0),
- y(0),
- width(0),
- height(0),
- showPlayerBox(true)
- { }
-
- A_DELETE_COPY(EquipmentPage)
-
- STD_VECTOR<EquipmentBox*> boxes;
- int x;
- int y;
- int width;
- int height;
- bool showPlayerBox;
-};
-
-#endif // GUI_WIDGETS_EQUIPMENTPAGE_H
diff --git a/src/gui/widgets/extendedlistbox.cpp b/src/gui/widgets/extendedlistbox.cpp
deleted file mode 100644
index 271160726..000000000
--- a/src/gui/widgets/extendedlistbox.cpp
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/extendedlistbox.h"
-
-#include "gui/models/extendedlistmodel.h"
-
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-ExtendedListBox::ExtendedListBox(const Widget2 *const widget,
- ListModel *const listModel,
- const std::string &skin,
- const unsigned int rowHeight) :
- ListBox(widget, listModel, skin),
- mImagePadding(mSkin != nullptr ? mSkin->getOption("imagePadding") : 0),
- mSpacing(mSkin != nullptr ? mSkin->getOption("spacing") : 0),
- mHeight(0),
- mListItems(),
- mSelectedItems()
-{
- if (rowHeight != 0u)
- mRowHeight = rowHeight;
-}
-
-ExtendedListBox::~ExtendedListBox()
-{
-}
-
-void ExtendedListBox::draw(Graphics *const graphics)
-{
- if (mListModel == nullptr)
- return;
-
- BLOCK_START("ExtendedListBox::draw")
- ExtendedListModel *const model = static_cast<ExtendedListModel *>(
- mListModel);
-
- updateAlpha();
- Font *const font = getFont();
-
- const int height = CAST_S32(mRowHeight);
- const int pad2 = 2 + mPadding;
- const int width = mDimension.width;
- int textPos = (height - font->getHeight()) / 2 + mPadding;
- if (textPos < 0)
- textPos = 0;
-
- const int sz = mListModel->getNumberOfElements();
- mListItems.clear();
- mSelectedItems.clear();
- int y = 0;
- const int insideWidth = width - pad2;
- for (int f = 0; f < sz; f ++)
- {
- int row = f;
- bool useImage = true;
- std::string str = mListModel->getElementAt(f);
- int strWidth = font->getWidth(str) + 8;
-
- const Image *const image = model->getImageAt(row);
- if (image != nullptr)
- strWidth += image->getWidth() + mImagePadding;
-
- STD_VECTOR<ExtendedListBoxItem> &list =
- row == mSelected ? mSelectedItems : mListItems;
-
- if (insideWidth < strWidth)
- {
- const size_t strSize = str.size();
- size_t divPos = strSize / 2;
- if (divPos > 0 && CAST_U8(
- str[divPos - 1]) >= 0xc0)
- {
- divPos --;
- }
- for (size_t d = divPos; d > 10; d --)
- {
- if (str[d] == 32)
- {
- divPos = d + 1;
- break;
- }
- }
- list.push_back(ExtendedListBoxItem(row,
- str.substr(0, divPos), useImage, y));
- str = str.substr(divPos);
- y += height;
- useImage = false;
- }
- list.push_back(ExtendedListBoxItem(row, str, useImage, y));
-
- y += height;
- }
- mHeight = y + height;
-
- const size_t itemsSz = mListItems.size();
- const size_t selSz = mSelectedItems.size();
- int minY = -1;
- int maxY = -1;
- for (size_t f = 0; f < selSz; f ++)
- {
- const ExtendedListBoxItem &item = mSelectedItems[f];
- const int y1 = item.y;
- if (minY == -1)
- minY = y1;
- if (maxY < y1)
- maxY = y1;
- }
-
- if (minY != -1)
- {
- mHighlightColor.a = CAST_U32(mAlpha * 255.0F);
- graphics->setColor(mHighlightColor);
- graphics->fillRectangle(Rect(mPadding, minY + mPadding,
- width - pad2, maxY - minY + height));
- }
-
- for (size_t f = 0; f < itemsSz; ++f)
- {
- const ExtendedListBoxItem &item = mListItems[f];
- const int row1 = item.row;
- if (item.image)
- {
- const Image *const image = model->getImageAt(row1);
- if (image != nullptr)
- {
- graphics->drawImage(image,
- mImagePadding,
- item.y + (height - image->getHeight()) / 2 + mPadding);
- }
- }
- }
-
- for (size_t f = 0; f < itemsSz; ++f)
- {
- const ExtendedListBoxItem &item = mListItems[f];
- const int row1 = item.row;
- const int y1 = item.y;
- const Image *const image = model->getImageAt(row1);
- if ((image == nullptr) || !item.image)
- {
- font->drawString(graphics,
- mForegroundColor, mForegroundColor2,
- item.text,
- mPadding, y1 + textPos);
- }
- else
- {
- font->drawString(graphics,
- mForegroundColor, mForegroundColor2,
- item.text,
- image->getWidth() + mImagePadding + mSpacing, y1 + textPos);
- }
- }
-
- for (size_t f = 0; f < selSz; ++f)
- {
- const ExtendedListBoxItem &item = mSelectedItems[f];
- const int row1 = item.row;
- const int y1 = item.y;
- const Image *const image = model->getImageAt(row1);
- if ((image == nullptr) || !item.image)
- {
- font->drawString(graphics,
- mForegroundSelectedColor, mForegroundSelectedColor2,
- item.text,
- mPadding, y1 + textPos);
- }
- else
- {
- font->drawString(graphics,
- mForegroundSelectedColor, mForegroundSelectedColor2,
- item.text,
- image->getWidth() + mImagePadding + mSpacing, y1 + textPos);
- }
- }
-
- for (size_t f = 0; f < selSz; ++f)
- {
- const ExtendedListBoxItem &item = mSelectedItems[f];
- const int row1 = item.row;
- if (item.image)
- {
- const Image *const image = model->getImageAt(row1);
- if (image != nullptr)
- {
- graphics->drawImage(image,
- mImagePadding,
- item.y + (height - image->getHeight()) / 2 + mPadding);
- }
- }
- }
-
- BLOCK_END("ExtendedListBox::draw")
-}
-
-void ExtendedListBox::safeDraw(Graphics *const graphics)
-{
- ExtendedListBox::draw(graphics);
-}
-
-void ExtendedListBox::adjustSize()
-{
- if (mHeight != 0)
- setHeight(mHeight + 2 * mPadding);
- else
- ListBox::adjustSize();
-}
-
-int ExtendedListBox::getSelectionByMouse(const int y) const
-{
- if (mListItems.empty() && mSelectedItems.empty())
- return ListBox::getSelectionByMouse(y);
-
- const int height = CAST_S32(mRowHeight);
- const size_t itemsSz = mListItems.size();
- for (size_t f = 0; f < itemsSz; f ++)
- {
- const ExtendedListBoxItem &item = mListItems[f];
- const int y2 = item.y + mPadding;
- if (y2 <= y && y2 + height > y)
- return item.row;
- }
-
- const size_t selSz = mSelectedItems.size();
- for (size_t f = 0; f < selSz; f ++)
- {
- const ExtendedListBoxItem &item = mSelectedItems[f];
- const int y2 = item.y + mPadding;
- if (y2 <= y && y2 + height > y)
- return item.row;
- }
- return 0;
-}
diff --git a/src/gui/widgets/extendedlistbox.h b/src/gui/widgets/extendedlistbox.h
deleted file mode 100644
index 6d97ee6d3..000000000
--- a/src/gui/widgets/extendedlistbox.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_EXTENDEDLISTBOX_H
-#define GUI_WIDGETS_EXTENDEDLISTBOX_H
-
-#include "gui/widgets/extendedlistboxitem.h"
-#include "gui/widgets/listbox.h"
-
-class ExtendedListBox final : public ListBox
-{
- public:
- /**
- * Constructor.
- */
- ExtendedListBox(const Widget2 *const widget,
- ListModel *const listModel,
- const std::string &skin,
- const unsigned int rowHeight = 13);
-
- A_DELETE_COPY(ExtendedListBox)
-
- ~ExtendedListBox();
-
- /**
- * Draws the list box.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void adjustSize() override;
-
- int getSelectionByMouse(const int y) const override final;
-
- protected:
- int mImagePadding;
- int mSpacing;
- int mHeight;
- STD_VECTOR<ExtendedListBoxItem> mListItems;
- STD_VECTOR<ExtendedListBoxItem> mSelectedItems;
-};
-
-#endif // GUI_WIDGETS_EXTENDEDLISTBOX_H
diff --git a/src/gui/widgets/extendedlistboxitem.h b/src/gui/widgets/extendedlistboxitem.h
deleted file mode 100644
index dc2d8b459..000000000
--- a/src/gui/widgets/extendedlistboxitem.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_EXTENDEDLISTBOXITEM_H
-#define GUI_WIDGETS_EXTENDEDLISTBOXITEM_H
-
-#include <string>
-
-#include "localconsts.h"
-
-struct ExtendedListBoxItem final
-{
- ExtendedListBoxItem(const int row0,
- const std::string &text0,
- const bool image0,
- const int y0) :
- row(row0),
- text(text0),
- image(image0),
- y(y0)
- {
- }
-
- A_DEFAULT_COPY(ExtendedListBoxItem)
-
- int row;
- std::string text;
- bool image;
- int y;
-};
-
-#endif // GUI_WIDGETS_EXTENDEDLISTBOXITEM_H
diff --git a/src/gui/widgets/flowcontainer.cpp b/src/gui/widgets/flowcontainer.cpp
deleted file mode 100644
index ee3181636..000000000
--- a/src/gui/widgets/flowcontainer.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/flowcontainer.h"
-
-#include "debug.h"
-
-FlowContainer::FlowContainer(const Widget2 *const widget,
- const int boxWidth,
- const int boxHeight) :
- Container(widget),
- WidgetListener(),
- mBoxWidth(boxWidth),
- mBoxHeight(boxHeight),
- mGridWidth(1),
- mGridHeight(1)
-{
- addWidgetListener(this);
- if (mBoxWidth == 0)
- mBoxWidth = 1;
- if (mBoxHeight == 0)
- mBoxHeight = 1;
-}
-
-void FlowContainer::widgetResized(const Event &event A_UNUSED)
-{
- if (getWidth() < mBoxWidth)
- {
- setWidth(mBoxWidth);
- return;
- }
-
- const int itemCount = CAST_S32(mWidgets.size());
-
- if (mBoxWidth == 0)
- mGridWidth = getWidth();
- else
- mGridWidth = getWidth() / mBoxWidth;
-
- if (mGridWidth < 1)
- mGridWidth = 1;
-
- mGridHeight = itemCount / mGridWidth;
-
- if (itemCount % mGridWidth != 0 || mGridHeight < 1)
- ++mGridHeight;
-
- int height = mGridHeight * mBoxHeight;
-
- if (getHeight() != height)
- {
- setHeight(height);
- return;
- }
-
- int i = 0;
- height = 0;
- for (WidgetList::const_iterator it = mWidgets.begin();
- it != mWidgets.end(); ++it)
- {
- const int x = i % mGridWidth * mBoxWidth;
- (*it)->setPosition(x, height);
-
- i++;
-
- if (i % mGridWidth == 0)
- height += mBoxHeight;
- }
-}
-
-void FlowContainer::add(Widget *const widget)
-{
- if (widget == nullptr)
- return;
-
- Container::add(widget);
- widget->setSize(mBoxWidth, mBoxHeight);
- widgetResized(Event(nullptr));
-}
diff --git a/src/gui/widgets/flowcontainer.h b/src/gui/widgets/flowcontainer.h
deleted file mode 100644
index be91853a6..000000000
--- a/src/gui/widgets/flowcontainer.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_FLOWCONTAINER_H
-#define GUI_WIDGETS_FLOWCONTAINER_H
-
-#include "gui/widgets/container.h"
-
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-/**
- * A container that arranges its contents like words on a page.
- *
- * \ingroup GUI
- */
-class FlowContainer final : public Container,
- public WidgetListener
-{
- public:
- /**
- * Constructor. Initializes the shortcut container.
- */
- FlowContainer(const Widget2 *const widget,
- const int boxWidth,
- const int boxHeight);
-
- A_DELETE_COPY(FlowContainer)
-
- /**
- * Destructor.
- */
- ~FlowContainer()
- { }
-
- /**
- * Invoked when a widget changes its size. This is used to determine
- * the new height of the container.
- */
- void widgetResized(const Event &event) override final;
-
- int getBoxWidth() const noexcept2 A_WARN_UNUSED
- { return mBoxWidth; }
-
- int getBoxHeight() const noexcept2 A_WARN_UNUSED
- { return mBoxHeight; }
-
- void add(Widget *const widget) override final;
-
- private:
- int mBoxWidth;
- int mBoxHeight;
- int mGridWidth, mGridHeight;
-};
-
-#endif // GUI_WIDGETS_FLOWCONTAINER_H
diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp
deleted file mode 100644
index 4a0f88246..000000000
--- a/src/gui/widgets/guitable.cpp
+++ /dev/null
@@ -1,675 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/guitable.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-
-#include "gui/models/tablemodel.h"
-
-#include "listeners/guitableactionlistener.h"
-
-#include "render/graphics.h"
-
-#include "utils/delete2.h"
-#include "utils/dtor.h"
-
-#include "debug.h"
-
-float GuiTable::mAlpha = 1.0;
-
-GuiTable::GuiTable(const Widget2 *const widget,
- TableModel *const initial_model,
- const Opaque opacity) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- TableModelListener(),
- mModel(nullptr),
- mTopWidget(nullptr),
- mActionListeners2(),
- mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT)),
- mSelectedRow(-1),
- mSelectedColumn(-1),
- mLinewiseMode(false),
- mWrappingEnabled(false),
- mOpaque(opacity),
- mSelectableGui(true)
-{
- mAllowLogic = false;
- mBackgroundColor = getThemeColor(ThemeColorId::BACKGROUND);
-
- setModel(initial_model);
- setFocusable(true);
-
- addMouseListener(this);
- addKeyListener(this);
-}
-
-GuiTable::~GuiTable()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- uninstallActionListeners();
- delete2(mModel);
-}
-
-const TableModel *GuiTable::getModel() const
-{
- return mModel;
-}
-
-void GuiTable::setModel(TableModel *const new_model)
-{
- if (mModel != nullptr)
- {
- uninstallActionListeners();
- mModel->removeListener(this);
- }
-
- mModel = new_model;
- installActionListeners();
-
- new_model->installListener(this);
- recomputeDimensions();
-}
-
-void GuiTable::recomputeDimensions()
-{
- if (mModel == nullptr)
- return;
-
- const int rows_nr = mModel->getRows();
- const int columns_nr = mModel->getColumns();
- int width = 0;
-
- if (mSelectableGui)
- {
- if (mSelectedRow >= rows_nr)
- mSelectedRow = rows_nr - 1;
-
- if (mSelectedColumn >= columns_nr)
- mSelectedColumn = columns_nr - 1;
- }
-
- for (int i = 0; i < columns_nr; i++)
- width += getColumnWidth(i);
-
- setWidth(width);
- setHeight(getRowHeight() * rows_nr);
-}
-
-void GuiTable::setSelected(const int row, const int column)
-{
- mSelectedColumn = column;
- mSelectedRow = row;
-}
-
-int GuiTable::getSelectedRow() const
-{
- return mSelectedRow;
-}
-
-int GuiTable::getSelectedColumn() const
-{
- return mSelectedColumn;
-}
-
-int GuiTable::getRowHeight() const
-{
- return mModel->getRowHeight() + 4; // border
-}
-
-int GuiTable::getColumnWidth(const int i) const
-{
- return mModel->getColumnWidth(i) + 4; // border
-}
-
-void GuiTable::setSelectedRow(const int selected)
-{
- if (!mSelectableGui)
- {
- mSelectedRow = -1;
- }
- else
- {
- const int rows = mModel->getRows();
- if (selected < 0 && !mWrappingEnabled)
- {
- mSelectedRow = -1;
- }
- else if (selected >= rows && mWrappingEnabled)
- {
- mSelectedRow = 0;
- }
- else if ((selected >= rows && !mWrappingEnabled) ||
- (selected < 0 && mWrappingEnabled))
- {
- mSelectedRow = rows - 1;
- }
- else
- {
- mSelectedRow = selected;
- }
- }
-}
-
-void GuiTable::setSelectedColumn(const int selected)
-{
- const int columns = mModel->getColumns();
- if ((selected >= columns && mWrappingEnabled) ||
- (selected < 0 && !mWrappingEnabled))
- {
- mSelectedColumn = 0;
- }
- else if ((selected >= columns && !mWrappingEnabled) ||
- (selected < 0 && mWrappingEnabled))
- {
- mSelectedColumn = columns - 1;
- }
- else
- {
- mSelectedColumn = selected;
- }
-}
-
-void GuiTable::uninstallActionListeners()
-{
- delete_all(mActionListeners2);
- mActionListeners2.clear();
-}
-
-void GuiTable::installActionListeners()
-{
- const int rows = mModel->getRows();
- const int columns = mModel->getColumns();
-
- for (int row = 0; row < rows; ++row)
- {
- for (int column = 0; column < columns; ++column)
- {
- Widget *const widget = mModel->getElementAt(row, column);
- if (widget != nullptr)
- {
- mActionListeners2.push_back(new GuiTableActionListener(
- this, widget, row, column));
- }
- }
- }
-
- setFocusHandler(getFocusHandler());
-}
-
-// -- widget ops
-void GuiTable::draw(Graphics *const graphics)
-{
- if (getRowHeight() == 0)
- return;
-
- BLOCK_START("GuiTable::draw")
- if (settings.guiAlpha != mAlpha)
- mAlpha = settings.guiAlpha;
-
- const Rect &rect = mDimension;
- const int width = rect.width;
- const int height = rect.height;
- const int y = rect.y;
- if (mOpaque == Opaque_true)
- {
- mBackgroundColor.a = CAST_U32(mAlpha * 255.0F);
- graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(Rect(0, 0, width, height));
- }
-
- // First, determine how many rows we need to draw,
- // and where we should start.
- int rHeight = getRowHeight();
- if (rHeight == 0)
- rHeight = 1;
- int first_row = -(y / rHeight);
-
- if (first_row < 0)
- first_row = 0;
-
- unsigned int rows_nr = CAST_U32(1 +
- height / rHeight); // May overestimate by one.
- unsigned int max_rows_nr;
- if (mModel->getRows() < first_row)
- {
- max_rows_nr = 0U;
- }
- else
- {
- max_rows_nr = CAST_U32(
- mModel->getRows() - first_row); // clip if neccessary:
- }
- if (max_rows_nr < rows_nr)
- rows_nr = max_rows_nr;
-
- // Now determine the first and last column
- // Take the easy way out; these are usually bounded and all visible.
- const unsigned first_column = 0;
- const unsigned last_column1 = CAST_U32(
- mModel->getColumns());
-
- int y_offset = first_row * rHeight;
-
- for (unsigned int r = CAST_U32(first_row);
- r < CAST_U32(first_row) + rows_nr;
- ++r)
- {
- int x_offset = 0;
-
- for (unsigned c = first_column; c + 1 <= last_column1; ++c)
- {
- Widget *const widget = mModel->getElementAt(CAST_S32(r),
- CAST_S32(c));
- const int cWidth = CAST_S32(getColumnWidth(
- CAST_S32(c)));
- if (widget != nullptr)
- {
- Rect bounds(x_offset, y_offset, cWidth, rHeight);
-
- if (widget == mTopWidget)
- {
- bounds.height = widget->getHeight();
- bounds.width = widget->getWidth();
- }
-
- widget->setDimension(bounds);
-
- if (mSelectedRow > -1)
- {
- mHighlightColor.a = CAST_U32(
- mAlpha * 255.0F);
- graphics->setColor(mHighlightColor);
-
- if (mLinewiseMode && r == CAST_U32(
- mSelectedRow) && c == 0)
- {
- graphics->fillRectangle(Rect(0, y_offset,
- width, rHeight));
- }
- else if (!mLinewiseMode && mSelectedColumn > 0
- && c == CAST_U32(mSelectedColumn)
- && r == CAST_U32(mSelectedRow))
- {
- graphics->fillRectangle(Rect(
- x_offset, y_offset, cWidth, rHeight));
- }
- }
- graphics->pushClipArea(bounds);
- widget->draw(graphics);
- graphics->popClipArea();
- }
-
- x_offset += cWidth;
- }
-
- y_offset += rHeight;
- }
-
- if (mTopWidget != nullptr)
- {
- const Rect &bounds = mTopWidget->getDimension();
- graphics->pushClipArea(bounds);
- mTopWidget->draw(graphics);
- graphics->popClipArea();
- }
- BLOCK_END("GuiTable::draw")
-}
-
-void GuiTable::safeDraw(Graphics *const graphics)
-{
- if (getRowHeight() == 0)
- return;
-
- BLOCK_START("GuiTable::draw")
- if (settings.guiAlpha != mAlpha)
- mAlpha = settings.guiAlpha;
-
- const Rect &rect = mDimension;
- const int width = rect.width;
- const int height = rect.height;
- const int y = rect.y;
- if (mOpaque == Opaque_true)
- {
- mBackgroundColor.a = CAST_U32(mAlpha * 255.0F);
- graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(Rect(0, 0, width, height));
- }
-
- // First, determine how many rows we need to draw,
- // and where we should start.
- int rHeight = getRowHeight();
- if (rHeight == 0)
- rHeight = 1;
- int first_row = -(y / rHeight);
-
- if (first_row < 0)
- first_row = 0;
-
- unsigned int rows_nr = CAST_U32(
- 1 + height / rHeight); // May overestimate by one.
- unsigned int max_rows_nr;
- if (mModel->getRows() < first_row)
- {
- max_rows_nr = 0;
- }
- else
- {
- max_rows_nr = CAST_U32(
- mModel->getRows() - first_row); // clip if neccessary:
- }
- if (max_rows_nr < rows_nr)
- rows_nr = max_rows_nr;
-
- // Now determine the first and last column
- // Take the easy way out; these are usually bounded and all visible.
- const unsigned int first_column = 0;
- const unsigned int last_column1 = CAST_U32(
- mModel->getColumns());
-
- int y_offset = first_row * rHeight;
-
- for (unsigned int r = CAST_U32(first_row);
- r < CAST_U32(first_row + CAST_S32(rows_nr));
- ++r)
- {
- int x_offset = 0;
-
- for (unsigned c = first_column; c + 1 <= last_column1; ++c)
- {
- Widget *const widget = mModel->getElementAt(CAST_S32(r),
- CAST_S32(c));
- const int cWidth = CAST_S32(getColumnWidth(
- CAST_S32(c)));
- if (widget != nullptr)
- {
- Rect bounds(x_offset, y_offset, cWidth, rHeight);
-
- if (widget == mTopWidget)
- {
- bounds.height = widget->getHeight();
- bounds.width = widget->getWidth();
- }
-
- widget->setDimension(bounds);
-
- if (mSelectedRow > -1)
- {
- mHighlightColor.a = CAST_U32(
- mAlpha * 255.0F);
- graphics->setColor(mHighlightColor);
-
- if (mLinewiseMode && r == CAST_U32(
- mSelectedRow) && c == 0)
- {
- graphics->fillRectangle(Rect(0, y_offset,
- width, rHeight));
- }
- else if (!mLinewiseMode && mSelectedColumn > 0
- && c == CAST_U32(mSelectedColumn)
- && r == CAST_U32(mSelectedRow))
- {
- graphics->fillRectangle(Rect(
- x_offset, y_offset, cWidth, rHeight));
- }
- }
- graphics->pushClipArea(bounds);
- widget->safeDraw(graphics);
- graphics->popClipArea();
- }
-
- x_offset += cWidth;
- }
-
- y_offset += rHeight;
- }
-
- if (mTopWidget != nullptr)
- {
- const Rect &bounds = mTopWidget->getDimension();
- graphics->pushClipArea(bounds);
- mTopWidget->safeDraw(graphics);
- graphics->popClipArea();
- }
- BLOCK_END("GuiTable::draw")
-}
-
-void GuiTable::moveToTop(Widget *const widget)
-{
- Widget::moveToTop(widget);
- mTopWidget = widget;
-}
-
-void GuiTable::moveToBottom(Widget *const widget)
-{
- Widget::moveToBottom(widget);
- if (widget == mTopWidget)
- mTopWidget = nullptr;
-}
-
-Rect GuiTable::getChildrenArea()
-{
- return Rect(0, 0, mDimension.width, mDimension.height);
-}
-
-// -- KeyListener notifications
-void GuiTable::keyPressed(KeyEvent& event)
-{
- const InputActionT action = event.getActionId();
-
- if (action == InputAction::GUI_SELECT)
- {
- distributeActionEvent();
- event.consume();
- }
- else if (action == InputAction::GUI_UP)
- {
- setSelectedRow(mSelectedRow - 1);
- event.consume();
- }
- else if (action == InputAction::GUI_DOWN)
- {
- setSelectedRow(mSelectedRow + 1);
- event.consume();
- }
- else if (action == InputAction::GUI_LEFT)
- {
- setSelectedColumn(mSelectedColumn - 1);
- event.consume();
- }
- else if (action == InputAction::GUI_RIGHT)
- {
- setSelectedColumn(mSelectedColumn + 1);
- event.consume();
- }
- else if (action == InputAction::GUI_HOME)
- {
- setSelectedRow(0);
- setSelectedColumn(0);
- event.consume();
- }
- else if (action == InputAction::GUI_END && (mModel != nullptr))
- {
- setSelectedRow(mModel->getRows() - 1);
- setSelectedColumn(mModel->getColumns() - 1);
- event.consume();
- }
-}
-
-// -- MouseListener notifications
-void GuiTable::mousePressed(MouseEvent& event)
-{
- if (!mSelectableGui)
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- 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& event)
-{
- if (isFocused())
- {
- const int selRow = getSelectedRow();
- if (selRow > 0 || (selRow == 0 && mWrappingEnabled))
- setSelectedRow(selRow - 1);
- event.consume();
- }
-}
-
-void GuiTable::mouseWheelMovedDown(MouseEvent& event)
-{
- if (isFocused())
- {
- setSelectedRow(getSelectedRow() + 1);
- event.consume();
- }
-}
-
-void GuiTable::mouseDragged(MouseEvent& event)
-{
- if (event.getButton() != MouseButton::LEFT)
- return;
-
- // Make table selection update on drag
- const int x = std::max(0, event.getX());
- const int y = std::max(0, event.getY());
-
- setSelectedRow(getRowForY(y));
- setSelectedColumn(getColumnForX(x));
-}
-
-void GuiTable::modelUpdated(const bool completed)
-{
- if (completed)
- {
- recomputeDimensions();
- installActionListeners();
- }
- else
- { // before the update?
- mTopWidget = nullptr; // No longer valid in general
- uninstallActionListeners();
- }
-}
-
-Widget *GuiTable::getWidgetAt(int x, int y)
-{
- if (mModel == nullptr)
- return nullptr;
-
- const int row = getRowForY(y);
- const int column = getColumnForX(x);
-
- if (mTopWidget != nullptr &&
- mTopWidget->getDimension().isPointInRect(x, y))
- {
- return mTopWidget;
- }
-
- if (row > -1 && column > -1)
- {
- Widget *const w = mModel->getElementAt(row, column);
- if (w != nullptr && w->isFocusable())
- return w;
- }
- return nullptr;
-}
-
-int GuiTable::getRowForY(const int y) const
-{
- int row = -1;
-
- const int rowHeight = getRowHeight();
- if (rowHeight > 0)
- row = y / rowHeight;
-
- if (row < 0 || row >= mModel->getRows())
- return -1;
- return row;
-}
-
-int GuiTable::getColumnForX(const int x) const
-{
- int column;
- int delta = 0;
-
- const int colnum = mModel->getColumns();
- for (column = 0; column < colnum; column ++)
- {
- delta += getColumnWidth(column);
- if (x <= delta)
- break;
- }
-
- if (column < 0 || column >= colnum)
- return -1;
- return column;
-}
-
-void GuiTable::setFocusHandler(FocusHandler *const focusHandler)
-{
- // add check for focusHandler. may be need remove it?
-
- if (focusHandler == nullptr)
- return;
-
- Widget::setFocusHandler(focusHandler);
-
- const int rows = mModel->getRows();
- const int cols = mModel->getColumns();
- for (int r = 0; r < rows; ++r)
- {
- for (int c = 0; c < cols ; ++c)
- {
- Widget *const w = mModel->getElementAt(r, c);
- if (w != nullptr)
- w->setFocusHandler(focusHandler);
- }
- }
-}
-
-void GuiTable::requestFocus()
-{
- if (mFocusHandler == nullptr)
- return;
- Widget::requestFocus();
-}
diff --git a/src/gui/widgets/guitable.h b/src/gui/widgets/guitable.h
deleted file mode 100644
index 30eb73523..000000000
--- a/src/gui/widgets/guitable.h
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_GUITABLE_H
-#define GUI_WIDGETS_GUITABLE_H
-
-#include "localconsts.h"
-
-#include "enums/simpletypes/opaque.h"
-
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-#include "listeners/tablemodellistener.h"
-
-#include "gui/widgets/widget.h"
-
-class GuiTableActionListener;
-class TableModel;
-
-/**
- * A table, with rows and columns made out of sub-widgets. Largely inspired by
- * (and can be thought of as a generalisation of) the guichan listbox
- * implementation.
- *
- * Normally you want this within a ScrollArea.
- *
- * \ingroup GUI
- */
-class GuiTable final : public Widget,
- public MouseListener,
- public KeyListener,
- public TableModelListener
-{
- // so that the action listener can call distributeActionEvent
- friend class GuiTableActionListener;
-
- public:
- GuiTable(const Widget2 *const widget,
- TableModel *const initial_model,
- const Opaque opacity = Opaque_true);
-
- A_DELETE_COPY(GuiTable)
-
- ~GuiTable();
-
- /**
- * Sets the table model
- *
- * Note that actions issued by widgets returned from the model will
- * update the table selection, but only AFTER any event handlers
- * installed within the widget have been triggered. To be notified
- * after such an update, add an action listener to the table instead.
- */
- void setModel(TableModel *const m);
-
- /**
- * Retrieves the active table model
- */
- const TableModel *getModel() const A_WARN_UNUSED RETURNS_NONNULL;
-
- void setSelected(const int row, const int column);
-
- int getSelectedRow() const A_WARN_UNUSED;
-
- int getSelectedColumn() const A_WARN_UNUSED;
-
- void setSelectedRow(const int selected);
-
- void setSelectedColumn(const int selected);
-
- bool isWrappingEnabled() const noexcept2 A_WARN_UNUSED
- { return mWrappingEnabled; }
-
- void setWrappingEnabled(bool wrappingEnabled)
- { mWrappingEnabled = wrappingEnabled; }
-
- Rect getChildrenArea() override final A_WARN_UNUSED;
-
- /**
- * Toggle whether to use linewise selection mode, in which the table
- * selects an entire line at a time, rather than a single cell.
- *
- * Note that column information is tracked even in linewise selection
- * mode;
- *
- * this mode therefore only affects visualisation.
- *
- * Disabled by default.
- *
- * \param linewise: Whether to enable linewise selection mode
- */
- void setLinewiseSelection(bool linewise)
- { mLinewiseMode = linewise; }
-
- // Inherited from Widget
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- Widget *getWidgetAt(int x, int y) override final A_WARN_UNUSED;
-
- void moveToTop(Widget *const widget) override final;
-
- void moveToBottom(Widget *const widget) override final;
-
- void setFocusHandler(FocusHandler *const focusHandler) override final;
-
- // Inherited from KeyListener
- void keyPressed(KeyEvent& event) override final;
-
- /**
- * Sets the table to be opaque, that is sets the table
- * to display its background.
- *
- * @param opaque True if the table should be opaque, false otherwise.
- */
- void setOpaque(Opaque opaque)
- { mOpaque = opaque; }
-
- /**
- * Checks if the table is opaque, that is if the table area displays
- * its background.
- *
- * @return True if the table is opaque, false otherwise.
- */
- bool isOpaque() const noexcept2 A_WARN_UNUSED
- { return mOpaque == Opaque_true; }
-
- // Inherited from MouseListener
- void mousePressed(MouseEvent& event) override final;
-
- void mouseWheelMovedUp(MouseEvent& event) override final;
-
- void mouseWheelMovedDown(MouseEvent& event) override final;
-
- void mouseDragged(MouseEvent& event) override final;
-
- // Constraints inherited from TableModelListener
- void modelUpdated(const bool completed) override final;
-
- void requestFocus() override;
-
- void setSelectableGui(bool b)
- { mSelectableGui = b; }
-
- protected:
- /** Frees all action listeners on inner widgets. */
- void uninstallActionListeners();
-
- /** Installs all action listeners on inner widgets. */
- void installActionListeners();
-
- int getRowHeight() const A_WARN_UNUSED;
-
- int getColumnWidth(const int i) const A_WARN_UNUSED;
-
- private:
- int getRowForY(const int y) const A_WARN_UNUSED; // -1 on error
-
- int getColumnForX(const int x) const A_WARN_UNUSED; // -1 on error
-
- void recomputeDimensions();
-
- static float mAlpha;
-
- TableModel *mModel A_NONNULLPOINTER;
-
- /** If someone moves a fresh widget to the top, we must display it. */
- Widget *mTopWidget;
-
- /** Vector for compactness; used as a list in practice. */
- STD_VECTOR<GuiTableActionListener *> mActionListeners2;
-
- /**
- * Holds the background color of the table.
- */
- Color mHighlightColor;
-
- int mSelectedRow;
- int mSelectedColumn;
-
- bool mLinewiseMode;
- bool mWrappingEnabled;
- Opaque mOpaque;
- bool mSelectableGui;
-};
-
-#endif // GUI_WIDGETS_GUITABLE_H
diff --git a/src/gui/widgets/horizontcontainer.cpp b/src/gui/widgets/horizontcontainer.cpp
deleted file mode 100644
index 8a026329a..000000000
--- a/src/gui/widgets/horizontcontainer.cpp
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/horizontcontainer.h"
-
-#include "debug.h"
-
-HorizontContainer::HorizontContainer(const Widget2 *const widget,
- const int height,
- const int spacing) :
- Container(widget),
- WidgetListener(),
- ToolTipListener(),
- mSpacing(spacing),
- mCount(0),
- mLastX(spacing)
-{
- setHeight(height);
- addWidgetListener(this);
- addMouseListener(this);
-}
-
-void HorizontContainer::add(Widget *const widget)
-{
- add(widget, mSpacing);
-}
-
-void HorizontContainer::add(Widget *const widget, const int spacing)
-{
- if (widget == nullptr)
- return;
-
- Container::add(widget);
- widget->setPosition(mLastX, spacing);
- mCount++;
- mLastX += widget->getWidth() + 2 * mSpacing;
-}
-
-void HorizontContainer::clear()
-{
- Container::clear();
-
- mCount = 0;
-}
-
-void HorizontContainer::widgetResized(const Event &event A_UNUSED)
-{
-}
diff --git a/src/gui/widgets/horizontcontainer.h b/src/gui/widgets/horizontcontainer.h
deleted file mode 100644
index a010f172e..000000000
--- a/src/gui/widgets/horizontcontainer.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_HORIZONTCONTAINER_H
-#define GUI_WIDGETS_HORIZONTCONTAINER_H
-
-#include "gui/widgets/container.h"
-
-#include "listeners/tooltiplistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-/**
- * A widget container.
- *
- * This container places it's contents veritcally.
- */
-class HorizontContainer final : public Container,
- public WidgetListener,
- public ToolTipListener
-{
- public:
- HorizontContainer(const Widget2 *const widget,
- const int height,
- const int spacing);
-
- A_DELETE_COPY(HorizontContainer)
-
- void add(Widget *const widget) override final;
-
- void add(Widget *const widget, const int spacing);
-
- void clear() override;
-
- void widgetResized(const Event &event) override final A_CONST;
-
- protected:
- int mSpacing;
- int mCount;
- int mLastX;
-};
-
-#endif // GUI_WIDGETS_HORIZONTCONTAINER_H
diff --git a/src/gui/widgets/icon.cpp b/src/gui/widgets/icon.cpp
deleted file mode 100644
index dbe46a21a..000000000
--- a/src/gui/widgets/icon.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/icon.h"
-
-#include "gui/gui.h"
-
-#include "render/graphics.h"
-
-#include "resources/image/image.h"
-
-#include "resources/loaders/imageloader.h"
-
-#include "debug.h"
-
-Icon::Icon(const Widget2 *const widget,
- const std::string &file,
- const AutoRelease autoRelease) :
- Widget(widget),
- mImage(Loader::getImage(file)),
- mAutoRelease(autoRelease)
-{
- if (mImage != nullptr)
- {
- const SDL_Rect &bounds = mImage->mBounds;
- setSize(bounds.w, bounds.h);
- }
- mAllowLogic = false;
-}
-
-Icon::Icon(const Widget2 *const widget,
- Image *const image,
- const AutoRelease autoRelease) :
- Widget(widget),
- mImage(image),
- mAutoRelease(autoRelease)
-{
- if (mImage != nullptr)
- {
- const SDL_Rect &bounds = mImage->mBounds;
- setSize(bounds.w, bounds.h);
- }
- mAllowLogic = false;
-}
-
-Icon::~Icon()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
- if ((mImage != nullptr) && mAutoRelease == AutoRelease_true)
- mImage->decRef();
-}
-
-void Icon::setImage(Image *const image)
-{
- mImage = image;
- if (mImage != nullptr)
- {
- const SDL_Rect &bounds = mImage->mBounds;
- setSize(bounds.w, bounds.h);
- }
-}
-
-void Icon::draw(Graphics *const graphics)
-{
- BLOCK_START("Icon::draw")
- if (mImage != nullptr)
- {
- graphics->drawImage(mImage,
- (mDimension.width - mImage->mBounds.w) / 2,
- (mDimension.height - mImage->mBounds.h) / 2);
- }
- BLOCK_END("Icon::draw")
-}
-
-void Icon::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("Icon::draw")
- if (mImage != nullptr)
- {
- graphics->drawImage(mImage,
- (mDimension.width - mImage->mBounds.w) / 2,
- (mDimension.height - mImage->mBounds.h) / 2);
- }
- BLOCK_END("Icon::draw")
-}
diff --git a/src/gui/widgets/icon.h b/src/gui/widgets/icon.h
deleted file mode 100644
index f0849d505..000000000
--- a/src/gui/widgets/icon.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_ICON_H
-#define GUI_WIDGETS_ICON_H
-
-#include "gui/widgets/widget.h"
-
-#include "enums/simpletypes/autorelease.h"
-
-#include "localconsts.h"
-
-class Image;
-
-/**
- * An icon.
- *
- * \ingroup GUI
- */
-class Icon final : public Widget
-{
- public:
- /**
- * Constructor.
- */
- Icon(const Widget2 *const widget,
- const std::string &filename,
- const AutoRelease autoRelease = AutoRelease_false);
-
- /**
- * Constructor, uses an existing Image.
- */
- Icon(const Widget2 *const widget,
- Image *const image,
- const AutoRelease autoRelease = AutoRelease_false);
-
- A_DELETE_COPY(Icon)
-
- ~Icon();
-
- /**
- * Gets the current Image.
- */
- Image *getImage() const noexcept2 A_WARN_UNUSED
- { return mImage; }
-
- /**
- * Sets the image to display.
- */
- void setImage(Image *const image);
-
- /**
- * Draws the Icon.
- */
- void draw(Graphics *const g) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const g) override final A_NONNULL(2);
-
- private:
- Image *mImage;
- AutoRelease mAutoRelease;
-};
-
-#endif // GUI_WIDGETS_ICON_H
diff --git a/src/gui/widgets/inttextfield.cpp b/src/gui/widgets/inttextfield.cpp
deleted file mode 100644
index 41436d310..000000000
--- a/src/gui/widgets/inttextfield.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/inttextfield.h"
-
-#ifdef USE_SDL2
-#include "enums/input/keyvalue.h"
-#endif // USE_SDL2
-
-#include "utils/stringutils.h"
-
-#include <sstream>
-
-#include "debug.h"
-
-IntTextField::IntTextField(const Widget2 *const widget,
- const int def,
- const int min,
- const int max,
- const Enable enabled,
- const int width) :
- TextField(widget, toString(def)),
- mMin(0),
- mMax(0),
- mDefault(def),
- mValue(def)
-{
- if (min != 0 || max != 0)
- setRange(min, max);
-
- setEnabled(enabled == Enable_true);
- if (width != 0)
- setWidth(width);
-}
-
-void IntTextField::keyPressed(KeyEvent &event)
-{
- const InputActionT action = event.getActionId();
-
- if (action == InputAction::GUI_DELETE
- || action == InputAction::GUI_BACKSPACE)
- {
- setText(std::string());
- if (mSendAlwaysEvents)
- distributeActionEvent();
-
- event.consume();
- }
-
-#ifdef USE_SDL2
- const int val = event.getKey().getValue();
- if (val != KeyValue::TEXTINPUT)
- return;
-
- const std::string str = event.getText();
- if (str.empty())
- return;
- const size_t sz = str.size();
- for (size_t f = 0; f < sz; f ++)
- {
- const char chr = str[f];
- if (chr < '0' || chr > '9')
- return;
- }
-#else // USE_SDL2
-
- if (!event.getKey().isNumber())
- return;
-#endif // USE_SDL2
-
- TextField::keyPressed(event);
-
- std::istringstream s(getText());
- int i;
- s >> i;
- setValue(i);
- if (mSendAlwaysEvents)
- distributeActionEvent();
-}
-
-void IntTextField::setRange(const int min, const int max)
-{
- mMin = min;
- mMax = max;
-
- if (mValue < mMin)
- mValue = mMin;
- else if (mValue > mMax)
- mValue = mMax;
-
- if (mDefault < mMin)
- mDefault = mMin;
- else if (mDefault > mMax)
- mDefault = mMax;
-}
-
-int IntTextField::getValue() const
-{
- return getText().empty() ? mMin : mValue;
-}
-
-void IntTextField::setValue(const int i)
-{
- if (i < mMin)
- mValue = mMin;
- else if (i > mMax)
- mValue = mMax;
- else
- mValue = i;
-
- const std::string valStr = toString(mValue);
- setText(valStr);
- setCaretPosition(CAST_U32(valStr.length()) + 1);
-}
-
-void IntTextField::setDefaultValue(const int value)
-{
- if (value < mMin)
- mDefault = mMin;
- else if (value > mMax)
- mDefault = mMax;
- else
- mDefault = value;
-}
-
-void IntTextField::reset()
-{
- setValue(mDefault);
-}
diff --git a/src/gui/widgets/inttextfield.h b/src/gui/widgets/inttextfield.h
deleted file mode 100644
index b8ac8564f..000000000
--- a/src/gui/widgets/inttextfield.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_INTTEXTFIELD_H
-#define GUI_WIDGETS_INTTEXTFIELD_H
-
-#include "enums/simpletypes/enable.h"
-
-#include "gui/widgets/textfield.h"
-
-/**
- * TextBox which only accepts numbers as input.
- */
-class IntTextField final : public TextField
-{
- public:
- /**
- * Constructor, sets default value.
- */
- explicit IntTextField(const Widget2 *const widget,
- const int def = 0,
- const int min = 0,
- const int max = 0,
- const Enable enabled = Enable_true,
- const int width = 0);
-
- A_DELETE_COPY(IntTextField)
-
- /**
- * Sets the minimum and maximum values of the text box.
- */
- void setRange(const int minimum, const int maximum);
-
- /**
- * Returns the value in the text box.
- */
- int getValue() const A_WARN_UNUSED;
-
- /**
- * Reset the field to the default value.
- */
- void reset();
-
- /**
- * Set the value of the text box to the specified value.
- */
- void setValue(const int value);
-
- /**
- * Set the default value of the text box to the specified value.
- */
- void setDefaultValue(const int value);
-
- /**
- * Responds to key presses.
- */
- void keyPressed(KeyEvent &event) override final;
-
- private:
- int mMin; /**< Minimum value */
- int mMax; /**< Maximum value */
- int mDefault; /**< Default value */
- int mValue; /**< Current value */
-};
-
-#endif // GUI_WIDGETS_INTTEXTFIELD_H
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
deleted file mode 100644
index b6ac3cff3..000000000
--- a/src/gui/widgets/itemcontainer.cpp
+++ /dev/null
@@ -1,1322 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/itemcontainer.h"
-
-#include "dragdrop.h"
-#include "settings.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/shortcut/itemshortcut.h"
-
-#include "gui/popups/itempopup.h"
-
-#include "gui/windows/chatwindow.h"
-#include "gui/windows/inventorywindow.h"
-#include "gui/windows/shopwindow.h"
-#include "gui/windows/shortcutwindow.h"
-#include "gui/windows/itemamountwindow.h"
-#include "gui/windows/maileditwindow.h"
-#include "gui/windows/npcdialog.h"
-
-#include "input/inputmanager.h"
-
-#include "net/inventoryhandler.h"
-#include "net/net.h"
-#include "net/mail2handler.h"
-#include "net/npchandler.h"
-#include "net/tradehandler.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "resources/iteminfo.h"
-
-#include <algorithm>
-
-#include "debug.h"
-
-namespace
-{
- class ItemIdPair final
- {
- public:
- A_DELETE_COPY(ItemIdPair)
-
- ItemIdPair(const int id, Item *const item) :
- mId(id), mItem(item)
- {
- }
-
- int mId;
- Item* mItem;
- };
-
- class SortItemAlphaFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemAlphaFunctor)
-
- bool operator() (const ItemIdPair *const pair1,
- const ItemIdPair *const pair2) const
- {
- const Item *const item1 = pair1->mItem;
- const Item *const item2 = pair2->mItem;
- if ((item1 == nullptr) || (item2 == nullptr))
- return false;
-
- const std::string name1 = item1->getInfo().getName(
- item1->getColor());
- const std::string name2 = item2->getInfo().getName(
- item2->getColor());
- if (name1 == name2)
- {
- return item1->getInvIndex() <
- item2->getInvIndex();
- }
- return name1 < name2;
- }
- } itemAlphaInvSorter;
-
- class SortItemIdFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemIdFunctor)
-
- bool operator() (const ItemIdPair *const pair1,
- const ItemIdPair *const pair2) const
- {
- if ((pair1->mItem == nullptr) || (pair2->mItem == nullptr))
- return false;
-
- const int id1 = pair1->mItem->getId();
- const int id2 = pair2->mItem->getId();
- if (id1 == id2)
- {
- return pair1->mItem->getInvIndex() <
- pair2->mItem->getInvIndex();
- }
- return id1 < id2;
- }
- } itemIdInvSorter;
-
- class SortItemWeightFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemWeightFunctor)
-
- bool operator() (const ItemIdPair *const pair1,
- const ItemIdPair *const pair2) const
- {
- if ((pair1->mItem == nullptr) || (pair2->mItem == nullptr))
- return false;
-
- const int w1 = pair1->mItem->getInfo().getWeight();
- const int w2 = pair2->mItem->getInfo().getWeight();
- if (w1 == w2)
- {
- const std::string name1 =
- pair1->mItem->getInfo().getName();
- const std::string name2 =
- pair2->mItem->getInfo().getName();
- if (name1 == name2)
- {
- return pair1->mItem->getInvIndex() <
- pair2->mItem->getInvIndex();
- }
- return name1 < name2;
- }
- return w1 < w2;
- }
- } itemWeightInvSorter;
-
- class SortItemAmountFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemAmountFunctor)
-
- bool operator() (const ItemIdPair *const pair1,
- const ItemIdPair *const pair2) const
- {
- if ((pair1->mItem == nullptr) || (pair2->mItem == nullptr))
- return false;
-
- const int c1 = pair1->mItem->getQuantity();
- const int c2 = pair2->mItem->getQuantity();
- if (c1 == c2)
- {
- const std::string name1 =
- pair1->mItem->getInfo().getName();
- const std::string name2 =
- pair2->mItem->getInfo().getName();
- if (name1 == name2)
- {
- return pair1->mItem->getInvIndex() <
- pair2->mItem->getInvIndex();
- }
- return name1 < name2;
- }
- return c1 < c2;
- }
- } itemAmountInvSorter;
-
- class SortItemTypeFunctor final
- {
- public:
- A_DEFAULT_COPY(SortItemTypeFunctor)
-
- bool operator() (const ItemIdPair *const pair1,
- const ItemIdPair *const pair2) const
- {
- if ((pair1->mItem == nullptr) || (pair2->mItem == nullptr))
- return false;
-
- const ItemInfo &info1 = pair1->mItem->getInfo();
- const ItemInfo &info2 = pair2->mItem->getInfo();
- const ItemDbTypeT t1 = info1.getType();
- const ItemDbTypeT t2 = info2.getType();
- if (t1 == t2)
- {
- const std::string &name1 = info1.getName();
- const std::string &name2 = info2.getName();
- if (name1 == name2)
- {
- return pair1->mItem->getInvIndex() <
- pair2->mItem->getInvIndex();
- }
- return name1 < name2;
- }
- return t1 < t2;
- }
- } itemTypeInvSorter;
-} // namespace
-
-ItemContainer::ItemContainer(const Widget2 *const widget,
- Inventory *const inventory,
- const int maxColumns,
- const ShowEmptyRows showEmptyRows,
- const ForceQuantity forceQuantity) :
- Widget(widget),
- KeyListener(),
- MouseListener(),
- WidgetListener(),
- mInventory(inventory),
- mSelImg(Theme::getImageFromThemeXml("item_selection.xml", "")),
- mProtectedImg(Theme::getImageFromTheme("lock.png")),
- mCellBackgroundImg(Theme::getImageFromThemeXml("inventory_cell.xml", "")),
- mName(),
- mShowMatrix(nullptr),
- mSkin(theme != nullptr ? theme->load("itemcontainer.xml", "") : nullptr),
- mVertexes(new ImageCollection),
- mEquipedColor(getThemeColor(ThemeColorId::ITEM_EQUIPPED)),
- mEquipedColor2(getThemeColor(ThemeColorId::ITEM_EQUIPPED_OUTLINE)),
- mUnEquipedColor(getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED)),
- mUnEquipedColor2(getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED_OUTLINE)),
- mSelectionListeners(),
- mGridColumns(1),
- mGridRows(1),
- mDrawRows(1),
- mSelectedIndex(-1),
- mLastUsedSlot(-1),
- mTag(0),
- mSortType(0),
- mClicks(1),
- mBoxWidth(mSkin != nullptr ? mSkin->getOption("boxWidth", 35) : 35),
- mBoxHeight(mSkin != nullptr ? mSkin->getOption("boxHeight", 43) : 43),
- mEquippedTextPadding(mSkin != nullptr ? mSkin->getOption(
- "equippedTextPadding", 29) : 29),
- mPaddingItemX(mSkin != nullptr ? mSkin->getOption("paddingItemX", 0) : 0),
- mPaddingItemY(mSkin != nullptr ? mSkin->getOption("paddingItemY", 0) : 0),
- mMaxColumns(maxColumns),
- mSelectionStatus(SEL_NONE),
- mForceQuantity(forceQuantity),
- mShowEmptyRows(showEmptyRows),
- mDescItems(false)
-{
- setFocusable(true);
- addKeyListener(this);
- addMouseListener(this);
- addWidgetListener(this);
- mAllowLogic = false;
-}
-
-ItemContainer::~ItemContainer()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- if (mSelImg != nullptr)
- {
- mSelImg->decRef();
- mSelImg = nullptr;
- }
- if (mProtectedImg != nullptr)
- {
- mProtectedImg->decRef();
- mProtectedImg = nullptr;
- }
- if (mCellBackgroundImg != nullptr)
- {
- mCellBackgroundImg->decRef();
- mCellBackgroundImg = nullptr;
- }
-
- if (theme != nullptr)
- theme->unload(mSkin);
-
- delete []mShowMatrix;
- delete2(mVertexes);
-}
-
-void ItemContainer::logic()
-{
- BLOCK_START("ItemContainer::logic")
- Widget::logic();
-
- if (mInventory == nullptr)
- {
- BLOCK_END("ItemContainer::logic")
- return;
- }
-
- const int lastUsedSlot = mInventory->getLastUsedSlot();
-
- if (lastUsedSlot != mLastUsedSlot)
- {
- mLastUsedSlot = lastUsedSlot;
- adjustHeight();
- }
- BLOCK_END("ItemContainer::logic")
-}
-
-void ItemContainer::draw(Graphics *const graphics)
-{
- if ((mInventory == nullptr) || (mShowMatrix == nullptr))
- return;
-
- BLOCK_START("ItemContainer::draw")
- Font *const font = getFont();
-
- if (mCellBackgroundImg != nullptr)
- {
- if (mRedraw || graphics->getRedraw())
- {
- mRedraw = false;
- mVertexes->clear();
-
- const int invSize = mInventory->getSize();
- const int maxRows = mShowEmptyRows == ShowEmptyRows_true ?
- std::max(invSize / mGridColumns, mGridRows) : mGridRows;
- const int maxColumns = mGridColumns > invSize ?
- invSize : mGridColumns;
- for (int j = 0; j < maxRows; j++)
- {
- const int intY0 = j * mBoxHeight;
- for (int i = 0; i < maxColumns; i++)
- {
- int itemX = i * mBoxWidth;
- int itemY = intY0;
- graphics->calcTileCollection(mVertexes,
- mCellBackgroundImg,
- itemX + mPaddingItemX,
- itemY + mPaddingItemY);
- }
- }
- graphics->finalize(mVertexes);
- }
- graphics->drawTileCollection(mVertexes);
- }
-
- for (int j = 0; j < mDrawRows; j++)
- {
- const int intY0 = j * mBoxHeight;
- int itemIndex = j * mGridColumns - 1;
- for (int i = 0; i < mGridColumns; i++)
- {
- int itemX = i * mBoxWidth;
- int itemY = intY0;
- itemIndex ++;
- if (mShowMatrix[itemIndex] < 0)
- continue;
-
- const Item *const item = mInventory->getItem(
- mShowMatrix[itemIndex]);
-
- if ((item == nullptr) || item->getId() == 0)
- continue;
-
- Image *const image = item->getImage();
- if (image != nullptr)
- {
- if (mShowMatrix[itemIndex] == mSelectedIndex)
- {
- if (mSelImg != nullptr)
- graphics->drawImage(mSelImg, itemX, itemY);
- }
- image->setAlpha(1.0F); // ensure the image if fully drawn...
- graphics->drawImage(image,
- itemX + mPaddingItemX,
- itemY + mPaddingItemY);
- if ((mProtectedImg != nullptr) && PlayerInfo::isItemProtected(
- item->getId()))
- {
- graphics->drawImage(mProtectedImg,
- itemX + mPaddingItemX,
- itemY + mPaddingItemY);
- }
- }
- }
- }
-
- for (int j = 0; j < mDrawRows; j++)
- {
- const int intY0 = j * mBoxHeight;
- int itemIndex = j * mGridColumns - 1;
- for (int i = 0; i < mGridColumns; i++)
- {
- int itemX = i * mBoxWidth;
- int itemY = intY0;
- itemIndex ++;
- if (mShowMatrix[itemIndex] < 0)
- continue;
-
- const Item *const item = mInventory->getItem(
- mShowMatrix[itemIndex]);
-
- if ((item == nullptr) || item->getId() == 0)
- continue;
-
- // Draw item caption
- std::string caption;
- if (item->getQuantity() > 1 ||
- mForceQuantity == ForceQuantity_true)
- {
- caption = toString(item->getQuantity());
- }
- else if (item->isEquipped() == Equipped_true)
- {
- // TRANSLATORS: Text under equipped items (should be small)
- caption = _("Eq.");
- }
-
- if (item->isEquipped() == Equipped_true)
- {
- font->drawString(graphics,
- mEquipedColor, mEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mEquippedTextPadding);
- }
- else
- {
- font->drawString(graphics,
- mUnEquipedColor, mUnEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mEquippedTextPadding);
- }
- }
- }
- BLOCK_END("ItemContainer::draw")
-}
-
-void ItemContainer::safeDraw(Graphics *const graphics)
-{
- if ((mInventory == nullptr) || (mShowMatrix == nullptr))
- return;
-
- BLOCK_START("ItemContainer::draw")
- Font *const font = getFont();
-
- if (mCellBackgroundImg != nullptr)
- {
- const int invSize = mInventory->getSize();
- const int maxRows = mShowEmptyRows == ShowEmptyRows_true ?
- std::max(invSize / mGridColumns, mGridRows) : mGridRows;
- const int maxColumns = mGridColumns > invSize ?
- invSize : mGridColumns;
- for (int j = 0; j < maxRows; j++)
- {
- const int intY0 = j * mBoxHeight;
- for (int i = 0; i < maxColumns; i++)
- {
- int itemX = i * mBoxWidth;
- int itemY = intY0;
- graphics->drawImage(mCellBackgroundImg,
- itemX + mPaddingItemX,
- itemY + mPaddingItemY);
- }
- }
- }
-
- for (int j = 0; j < mDrawRows; j++)
- {
- const int intY0 = j * mBoxHeight;
- int itemIndex = j * mGridColumns - 1;
- for (int i = 0; i < mGridColumns; i++)
- {
- int itemX = i * mBoxWidth;
- int itemY = intY0;
- itemIndex ++;
- if (mShowMatrix[itemIndex] < 0)
- continue;
-
- const Item *const item = mInventory->getItem(
- mShowMatrix[itemIndex]);
-
- if ((item == nullptr) || item->getId() == 0)
- continue;
-
- Image *const image = item->getImage();
- if (image != nullptr)
- {
- if (mShowMatrix[itemIndex] == mSelectedIndex)
- {
- if (mSelImg != nullptr)
- graphics->drawImage(mSelImg, itemX, itemY);
- }
- image->setAlpha(1.0F); // ensure the image if fully drawn...
- graphics->drawImage(image,
- itemX + mPaddingItemX,
- itemY + mPaddingItemY);
- if ((mProtectedImg != nullptr) && PlayerInfo::isItemProtected(
- item->getId()))
- {
- graphics->drawImage(mProtectedImg,
- itemX + mPaddingItemX,
- itemY + mPaddingItemY);
- }
- }
- }
- }
-
- for (int j = 0; j < mDrawRows; j++)
- {
- const int intY0 = j * mBoxHeight;
- int itemIndex = j * mGridColumns - 1;
- for (int i = 0; i < mGridColumns; i++)
- {
- int itemX = i * mBoxWidth;
- int itemY = intY0;
- itemIndex ++;
- if (mShowMatrix[itemIndex] < 0)
- continue;
-
- const Item *const item = mInventory->getItem(
- mShowMatrix[itemIndex]);
-
- if ((item == nullptr) || item->getId() == 0)
- continue;
-
- // Draw item caption
- std::string caption;
- if (item->getQuantity() > 1 ||
- mForceQuantity == ForceQuantity_true)
- {
- caption = toString(item->getQuantity());
- }
- else if (item->isEquipped() == Equipped_true)
- {
- // TRANSLATORS: Text under equipped items (should be small)
- caption = _("Eq.");
- }
-
- if (item->isEquipped() == Equipped_true)
- {
- font->drawString(graphics,
- mEquipedColor, mEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mEquippedTextPadding);
- }
- else
- {
- font->drawString(graphics,
- mUnEquipedColor, mUnEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mEquippedTextPadding);
- }
- }
- }
- BLOCK_END("ItemContainer::draw")
-}
-
-void ItemContainer::selectNone()
-{
- dragDrop.clear();
-
- setSelectedIndex(-1);
- mSelectionStatus = SEL_NONE;
-/*
- if (outfitWindow)
- outfitWindow->setItemSelected(-1);
- if (shopWindow)
- shopWindow->setItemSelected(-1);
-*/
-}
-
-void ItemContainer::setSelectedIndex(const int newIndex)
-{
- if (mSelectedIndex != newIndex)
- {
- mSelectedIndex = newIndex;
- distributeValueChangedEvent();
- }
-}
-
-Item *ItemContainer::getSelectedItem() const
-{
- if (mInventory != nullptr)
- return mInventory->getItem(mSelectedIndex);
- return nullptr;
-}
-
-void ItemContainer::distributeValueChangedEvent()
-{
- FOR_EACH (SelectionListenerIterator, i, mSelectionListeners)
- {
- if (*i != nullptr)
- {
- SelectionEvent event(this);
- (*i)->valueChanged(event);
- }
- }
-}
-
-void ItemContainer::keyPressed(KeyEvent &event A_UNUSED)
-{
-}
-
-void ItemContainer::keyReleased(KeyEvent &event A_UNUSED)
-{
-}
-
-void ItemContainer::mousePressed(MouseEvent &event)
-{
- if (mInventory == nullptr)
- return;
-
- const MouseButtonT button = event.getButton();
- mClicks = event.getClickCount();
-
- if (button == MouseButton::LEFT || button == MouseButton::RIGHT)
- {
- event.consume();
- const int index = getSlotIndex(event.getX(), event.getY());
- if (index == Inventory::NO_SLOT_INDEX)
- return;
-
- Item *const item = mInventory->getItem(index);
-
- // put item name into chat window
- if ((item != nullptr) && mDescItems && (chatWindow != nullptr))
- chatWindow->addItemText(item->getInfo().getName());
-
- DragDropSourceT src = DragDropSource::Empty;
- switch (mInventory->getType())
- {
- case InventoryType::Inventory:
- src = DragDropSource::Inventory;
- break;
- case InventoryType::Storage:
- src = DragDropSource::Storage;
- break;
- case InventoryType::Trade:
- src = DragDropSource::Trade;
- break;
- case InventoryType::Npc:
- src = DragDropSource::Npc;
- break;
- case InventoryType::Cart:
- src = DragDropSource::Cart;
- break;
- case InventoryType::MailEdit:
- src = DragDropSource::MailEdit;
- break;
- case InventoryType::MailView:
- src = DragDropSource::MailView;
- break;
- case InventoryType::Craft:
- src = DragDropSource::Craft;
- break;
- default:
- case InventoryType::Vending:
- case InventoryType::TypeEnd:
- break;
- }
- if (src == DragDropSource::MailView)
- return;
- if (mSelectedIndex == index && mClicks != 2)
- {
- dragDrop.dragItem(item, src, index);
- dragDrop.select(item);
- mSelectionStatus = SEL_DESELECTING;
- }
- else if ((item != nullptr) && (item->getId() != 0))
- {
- if (index >= 0)
- {
- dragDrop.dragItem(item, src, index);
- dragDrop.select(item);
- setSelectedIndex(index);
- mSelectionStatus = SEL_SELECTING;
-
- if (itemShortcutWindow != nullptr)
- {
- const int num = itemShortcutWindow->getTabIndex();
- if (num >= 0 && num < CAST_S32(SHORTCUT_TABS))
- {
- if (itemShortcut[num] != nullptr)
- itemShortcut[num]->setItemSelected(item);
- }
- }
- if (shopWindow != nullptr)
- shopWindow->setItemSelected(item->getId());
- }
- }
- else
- {
- dragDrop.deselect();
- selectNone();
- }
- }
-}
-
-void ItemContainer::mouseDragged(MouseEvent &event A_UNUSED)
-{
- if (mSelectionStatus != SEL_NONE)
- mSelectionStatus = SEL_DRAGGING;
-}
-
-void ItemContainer::mouseReleased(MouseEvent &event)
-{
- if (mClicks == 2 ||
- inventoryHandler == nullptr ||
- tradeHandler == nullptr)
- {
- return;
- }
-
- switch (mSelectionStatus)
- {
- case SEL_SELECTING:
- mSelectionStatus = SEL_SELECTED;
- break;
- case SEL_DESELECTING:
- selectNone();
- break;
- case SEL_DRAGGING:
- mSelectionStatus = SEL_SELECTED;
- break;
- case SEL_NONE:
- case SEL_SELECTED:
- default:
- break;
- };
-
- if (dragDrop.isEmpty())
- {
- const int index = getSlotIndex(event.getX(), event.getY());
- if (index == Inventory::NO_SLOT_INDEX)
- return;
- if (index == mSelectedIndex || mSelectedIndex == -1)
- return;
- inventoryHandler->moveItem(mSelectedIndex, index);
- selectNone();
- }
- else if (mInventory != nullptr)
- {
- const DragDropSourceT src = dragDrop.getSource();
- DragDropSourceT dst = DragDropSource::Empty;
- switch (mInventory->getType())
- {
- case InventoryType::Inventory:
- dst = DragDropSource::Inventory;
- break;
- case InventoryType::Storage:
- dst = DragDropSource::Storage;
- break;
- case InventoryType::Trade:
- dst = DragDropSource::Trade;
- break;
- case InventoryType::Npc:
- dst = DragDropSource::Npc;
- break;
- case InventoryType::MailEdit:
- dst = DragDropSource::MailEdit;
- break;
- case InventoryType::MailView:
- dst = DragDropSource::MailView;
- break;
- case InventoryType::Cart:
- dst = DragDropSource::Cart;
- break;
- case InventoryType::Craft:
- dst = DragDropSource::Craft;
- break;
- default:
- case InventoryType::Vending:
- case InventoryType::TypeEnd:
- break;
- }
- InventoryTypeT srcContainer = InventoryType::TypeEnd;
- InventoryTypeT dstContainer = InventoryType::TypeEnd;
- bool checkProtection(false);
- Inventory *inventory = nullptr;
- if (src == DragDropSource::Inventory
- && dst == DragDropSource::Storage)
- {
- srcContainer = InventoryType::Inventory;
- dstContainer = InventoryType::Storage;
- inventory = PlayerInfo::getInventory();
- }
- else if (src == DragDropSource::Storage
- && dst == DragDropSource::Inventory)
- {
- srcContainer = InventoryType::Storage;
- dstContainer = InventoryType::Inventory;
- inventory = PlayerInfo::getStorageInventory();
- }
- if (src == DragDropSource::Inventory
- && dst == DragDropSource::Cart)
- {
- srcContainer = InventoryType::Inventory;
- dstContainer = InventoryType::Cart;
- inventory = PlayerInfo::getInventory();
- }
- if (src == DragDropSource::Inventory
- && dst == DragDropSource::Inventory)
- {
- if (Net::getNetworkType() == ServerType::TMWATHENA)
- return;
- const int index = getSlotIndex(event.getX(), event.getY());
- if (index == Inventory::NO_SLOT_INDEX)
- return;
- if (index == mSelectedIndex || mSelectedIndex == -1)
- return;
- if (inventoryWindow != nullptr)
- inventoryWindow->combineItems(index, mSelectedIndex);
- return;
- }
- else if (src == DragDropSource::Cart
- && dst == DragDropSource::Inventory)
- {
- srcContainer = InventoryType::Cart;
- dstContainer = InventoryType::Inventory;
- inventory = PlayerInfo::getCartInventory();
- }
- else if (src == DragDropSource::Cart
- && dst == DragDropSource::Storage)
- {
- srcContainer = InventoryType::Cart;
- dstContainer = InventoryType::Storage;
- inventory = PlayerInfo::getCartInventory();
- }
- else if (src == DragDropSource::Storage
- && dst == DragDropSource::Cart)
- {
- srcContainer = InventoryType::Storage;
- dstContainer = InventoryType::Cart;
- inventory = PlayerInfo::getStorageInventory();
- }
- if (src == DragDropSource::Inventory
- && dst == DragDropSource::Trade)
- {
- checkProtection = true;
- inventory = PlayerInfo::getInventory();
- }
- else if (src == DragDropSource::Inventory &&
- dst == DragDropSource::Npc)
- {
- inventory = PlayerInfo::getInventory();
- if (inventory != nullptr)
- {
- Item *const item = inventory->getItem(dragDrop.getTag());
- if (mInventory->addVirtualItem(
- item,
- getSlotByXY(event.getX(), event.getY()),
- 1))
- {
- inventory->virtualRemove(item, 1);
- }
- }
- return;
- }
- else if (src == DragDropSource::Inventory &&
- dst == DragDropSource::MailEdit)
- {
- inventory = PlayerInfo::getInventory();
- if (inventory == nullptr)
- return;
- Item *const item = inventory->getItem(dragDrop.getTag());
- if (item == nullptr)
- return;
- if (settings.enableNewMailSystem)
- {
- if (item->getQuantity() > 1
- && !inputManager.isActionActive(InputAction::STOP_ATTACK))
- {
- ItemAmountWindow::showWindow(
- ItemAmountWindowUsage::MailAdd,
- mailEditWindow,
- item);
- }
- else
- {
- mail2Handler->addItem(item, 1);
- }
- }
- else
- {
- if (mInventory->addVirtualItem(
- item,
- getSlotByXY(event.getX(), event.getY()),
- 1))
- {
- inventory->virtualRemove(item, 1);
- }
- }
- return;
- }
- else if (src == DragDropSource::Npc)
- {
- inventory = PlayerInfo::getInventory();
- if (dst == DragDropSource::Npc)
- {
- const Item *const item = mInventory->getItem(
- dragDrop.getTag());
- const int index = getSlotByXY(event.getX(), event.getY());
- if (index == Inventory::NO_SLOT_INDEX)
- {
- if (inventory != nullptr)
- inventory->virtualRestore(item, 1);
- mInventory->removeItemAt(dragDrop.getTag());
- return;
- }
- mInventory->removeItemAt(index);
- mInventory->setItem(index,
- item->getId(),
- item->getType(),
- 1,
- 1,
- item->getColor(),
- item->getIdentified(),
- item->getDamaged(),
- item->getFavorite(),
- Equipm_false,
- Equipped_false);
- Item *const item2 = mInventory->getItem(index);
- if (item2 != nullptr)
- item2->setTag(item->getTag());
- mInventory->removeItemAt(dragDrop.getTag());
- }
- else
- {
- if (inventory != nullptr)
- {
- const Item *const item = inventory->getItem(
- dragDrop.getTag());
- if (item != nullptr)
- {
- inventory->virtualRestore(item, 1);
- mInventory->removeItemAt(dragDrop.getTag());
- }
- }
- return;
- }
- }
- else if (src == DragDropSource::Inventory &&
- dst == DragDropSource::Craft)
- {
- inventory = PlayerInfo::getInventory();
- if (inventory != nullptr)
- {
- Item *const item = inventory->getItem(dragDrop.getTag());
- if ((item == nullptr) || item->isEquipped() == Equipped_true)
- return;
- const int slot = getSlotByXY(event.getX(), event.getY());
- if (item->getQuantity() > 1
- && !inputManager.isActionActive(InputAction::STOP_ATTACK))
- {
- ItemAmountWindow::showWindow(
- ItemAmountWindowUsage::CraftAdd,
- npcHandler->getCurrentNpcDialog(),
- item,
- 0,
- slot);
- }
- else
- {
- if (mInventory->addVirtualItem(
- item,
- slot,
- 1))
- {
- inventory->virtualRemove(item, 1);
- }
- }
- }
- return;
- }
- else if (src == DragDropSource::Craft)
- {
- inventory = PlayerInfo::getInventory();
- if (dst == DragDropSource::Craft)
- {
- const Item *const item = mInventory->getItem(
- dragDrop.getTag());
- const int index = getSlotByXY(event.getX(), event.getY());
- if (index == Inventory::NO_SLOT_INDEX)
- {
- if (inventory != nullptr)
- {
- inventory->virtualRestore(item,
- item->getQuantity());
- mInventory->removeItemAt(dragDrop.getTag());
- }
- return;
- }
- mInventory->moveItem(index, dragDrop.getTag());
- }
- else
- {
- if (inventory != nullptr)
- {
- const Item *const item = inventory->getItem(
- dragDrop.getTag());
- if (item != nullptr)
- {
- inventory->virtualRestore(item,
- item->getQuantity());
- mInventory->removeItemAt(dragDrop.getTag());
- }
- }
- return;
- }
- }
- else if (src == DragDropSource::MailEdit)
- {
- if (event.getType() == MouseEventType::RELEASED2)
- return;
- if (settings.enableNewMailSystem)
- {
- if (mailEditWindow == nullptr)
- return;
- inventory = mailEditWindow->getInventory();
- if (inventory == nullptr)
- return;
- const Item *const item = inventory->getItem(dragDrop.getTag());
- if (item == nullptr)
- return;
- mail2Handler->removeItem(item->getTag(),
- item->getQuantity());
- }
- else
- {
- inventory = PlayerInfo::getInventory();
- if (inventory == nullptr)
- return;
- const Item *const item = inventory->getItem(dragDrop.getTag());
- if (item == nullptr)
- return;
- mInventory->removeItemAt(dragDrop.getTag());
- }
- return;
- }
-
- if (inventory != nullptr)
- {
- const Item *const item = inventory->getItem(dragDrop.getTag());
- if (item != nullptr)
- {
- if (srcContainer != InventoryType::TypeEnd)
- { // inventory <--> storage, cart
- inventoryHandler->moveItem2(srcContainer,
- item->getInvIndex(),
- item->getQuantity(),
- dstContainer);
- }
- else
- { // inventory --> trade
- if (!checkProtection || !PlayerInfo::isItemProtected(
- item->getId()))
- {
- tradeHandler->addItem(item, item->getQuantity());
- }
- }
- }
- }
- }
-}
-
-void ItemContainer::mouseMoved(MouseEvent &event)
-{
- if (mInventory == nullptr)
- return;
-
- const Item *const item = mInventory->getItem(
- getSlotIndex(event.getX(), event.getY()));
-
- if ((item != nullptr) && (viewport != nullptr))
- {
- itemPopup->setItem(item, false);
- itemPopup->position(viewport->mMouseX, viewport->mMouseY);
- }
- else
- {
- itemPopup->setVisible(Visible_false);
- }
-}
-
-void ItemContainer::mouseExited(MouseEvent &event A_UNUSED)
-{
- itemPopup->setVisible(Visible_false);
-}
-
-void ItemContainer::widgetResized(const Event &event A_UNUSED)
-{
- updateSize();
-}
-
-void ItemContainer::updateSize()
-{
- mGridColumns = std::min(mMaxColumns,
- std::max(1, mDimension.width / mBoxWidth));
- if (mGridColumns > mMaxColumns)
- mGridColumns = mMaxColumns;
- adjustHeight();
- mRedraw = true;
-}
-
-void ItemContainer::widgetMoved(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void ItemContainer::adjustHeight()
-{
- if (mGridColumns == 0)
- return;
-
- mGridRows = (mLastUsedSlot + 1) / mGridColumns;
- if (mGridRows == 0 || (mLastUsedSlot + 1) % mGridColumns > 0)
- ++mGridRows;
-
- const int invSize = mInventory->getSize();
- int maxRows = mShowEmptyRows == ShowEmptyRows_true ?
- std::max(invSize / mGridColumns, mGridRows) : mGridRows;
-
- if (mShowEmptyRows == ShowEmptyRows_true)
- {
- if (mGridColumns * maxRows < invSize)
- maxRows ++;
- mGridRows = maxRows;
- }
-
- const int num = updateMatrix();
- if (mShowEmptyRows == ShowEmptyRows_false)
- {
- mDrawRows = num / mGridColumns;
- if (mDrawRows == 0 || num % mGridColumns > 0)
- ++mDrawRows;
-
- maxRows = mDrawRows;
- }
- else
- {
- mDrawRows = mGridRows;
- }
- setHeight(maxRows * mBoxHeight);
-}
-
-int ItemContainer::updateMatrix()
-{
- if (mInventory == nullptr)
- return 0;
-
- mRedraw = true;
- delete []mShowMatrix;
- mShowMatrix = new int[CAST_SIZE(mGridRows * mGridColumns)];
-
- STD_VECTOR<ItemIdPair*> sortedItems;
- int i = 0;
- int j = 0;
-
- std::string temp = mName;
- toLower(temp);
-
- const unsigned int invSize = mInventory->getSize();
- for (unsigned int idx = 0; idx < invSize; idx ++)
- {
- Item *const item = mInventory->getItem(idx);
-
- if (item == nullptr ||
- item->getId() == 0 ||
- !item->isHaveTag(mTag) ||
- item->getQuantity() == 0)
- {
- if (mShowEmptyRows == ShowEmptyRows_true)
- sortedItems.push_back(new ItemIdPair(idx, nullptr));
- continue;
- }
-
- if (!item->isHaveTag(mTag))
- continue;
-
- if (mName.empty())
- {
- sortedItems.push_back(new ItemIdPair(idx, item));
- continue;
- }
- std::string name = item->getInfo().getName();
- toLower(name);
- if (name.find(temp) != std::string::npos)
- sortedItems.push_back(new ItemIdPair(idx, item));
- }
-
- switch (mSortType)
- {
- case 0:
- default:
- break;
- case 1:
- std::sort(sortedItems.begin(), sortedItems.end(),
- itemAlphaInvSorter);
- break;
- case 2:
- std::sort(sortedItems.begin(), sortedItems.end(), itemIdInvSorter);
- break;
- case 3:
- std::sort(sortedItems.begin(), sortedItems.end(),
- itemWeightInvSorter);
- break;
- case 4:
- std::sort(sortedItems.begin(), sortedItems.end(),
- itemAmountInvSorter);
- break;
- case 5:
- std::sort(sortedItems.begin(), sortedItems.end(),
- itemTypeInvSorter);
- break;
- }
-
- int jMult = j * mGridColumns;
- const int maxSize = mGridRows * mGridColumns;
- FOR_EACH (STD_VECTOR<ItemIdPair*>::const_iterator, iter, sortedItems)
- {
- if (jMult >= maxSize)
- break;
-
- mShowMatrix[jMult + i] = (*iter)->mId;
-
- i ++;
- if (i >= mGridColumns)
- {
- i = 0;
- j ++;
- jMult += mGridColumns;
- }
- }
-
- for (int idx = j * mGridColumns + i; idx < maxSize; idx ++)
- mShowMatrix[idx] = -1;
-
- const int num = CAST_S32(sortedItems.size());
- for (size_t idx = 0, sz = num; idx < sz; idx ++)
- delete sortedItems[idx];
- return num;
-}
-
-int ItemContainer::getSlotIndex(int x, int y) const
-{
- if (mShowMatrix == nullptr)
- return Inventory::NO_SLOT_INDEX;
-
- if (x < mDimension.width && y < mDimension.height && x >= 0 && y >= 0)
- {
- if (x > mBoxWidth * mGridColumns)
- return Inventory::NO_SLOT_INDEX;
- const int idx = (y / mBoxHeight) * mGridColumns + (x / mBoxWidth);
- if (idx >= 0 && idx < mGridRows * mGridColumns
- && mShowMatrix[idx] >= 0)
- {
- return mShowMatrix[idx];
- }
- }
-
- return Inventory::NO_SLOT_INDEX;
-}
-
-int ItemContainer::getSlotByXY(int x, int y) const
-{
- if (mShowMatrix == nullptr)
- return Inventory::NO_SLOT_INDEX;
-
- if (x < mDimension.width && y < mDimension.height && x >= 0 && y >= 0)
- {
- if (x > mBoxWidth * mGridColumns)
- return Inventory::NO_SLOT_INDEX;
- const int idx = (y / mBoxHeight) * mGridColumns + (x / mBoxWidth);
- if (idx >= 0 && idx < mGridRows * mGridColumns)
- return idx;
- }
-
- return Inventory::NO_SLOT_INDEX;
-}
-
-void ItemContainer::setFilter(const int tag)
-{
- mTag = tag;
- adjustHeight();
-}
-
-void ItemContainer::setSortType(const int sortType)
-{
- mSortType = sortType;
- updateMatrix();
-}
-
-void ItemContainer::setCellBackgroundImage(const std::string &xmlName)
-{
- if (mCellBackgroundImg != nullptr)
- mCellBackgroundImg->decRef();
- mCellBackgroundImg = Theme::getImageFromThemeXml(xmlName, "");
- mRedraw = true;
-}
-
-void ItemContainer::setMaxColumns(const int maxColumns)
-{
- mMaxColumns = maxColumns;
- updateSize();
-}
diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h
deleted file mode 100644
index c992c43f5..000000000
--- a/src/gui/widgets/itemcontainer.h
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_ITEMCONTAINER_H
-#define GUI_WIDGETS_ITEMCONTAINER_H
-
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "enums/simpletypes/forcequantity.h"
-#include "enums/simpletypes/showemptyrows.h"
-
-#include "gui/widgets/widget.h"
-
-#include "localconsts.h"
-
-class Image;
-class ImageCollection;
-class Inventory;
-class Item;
-class SelectionListener;
-
-/**
- * An item container. Used to show items in inventory and trade dialog.
- *
- * \ingroup GUI
- */
-class ItemContainer final : public Widget,
- public KeyListener,
- public MouseListener,
- public WidgetListener
-{
- public:
- ItemContainer(const Widget2 *const widget,
- Inventory *const inventory,
- const int maxColumns = 100000,
- const ShowEmptyRows showEmptyRows = ShowEmptyRows_false,
- const ForceQuantity forceQuantity = ForceQuantity_false);
-
- A_DELETE_COPY(ItemContainer)
-
- /**
- * Destructor.
- */
- ~ItemContainer();
-
- /**
- * Necessary for checking how full the inventory is.
- */
- void logic() override final;
-
- /**
- * Draws the items.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- // KeyListener
- void keyPressed(KeyEvent &event) override final A_CONST;
- void keyReleased(KeyEvent &event) override final A_CONST;
-
- // MouseListener
- void mousePressed(MouseEvent &event) override final;
- void mouseDragged(MouseEvent &event) override final;
- void mouseReleased(MouseEvent &event) override final;
- void mouseMoved(MouseEvent &event) override final;
- void mouseExited(MouseEvent &event) override final;
-
- // WidgetListener
- void widgetResized(const Event &event) override final;
-
- void widgetMoved(const Event &event) override final;
-
- /**
- * Returns the selected item.
- */
- Item *getSelectedItem() const A_WARN_UNUSED;
-
- /**
- * Sets selected item to NULL.
- */
- void selectNone();
-
- /**
- * Adds a listener to the list that's notified each time a change to
- * the selection occurs.
- */
- void addSelectionListener(SelectionListener *listener)
- { mSelectionListeners.push_back(listener); }
-
- /**
- * Removes a listener from the list that's notified each time a change
- * to the selection occurs.
- */
- void removeSelectionListener(SelectionListener *listener)
- { mSelectionListeners.remove(listener); }
-
- void setFilter(const int tag);
-
- void setSortType(const int sortType);
-
- void setName(const std::string &str)
- { mName = str; }
-
- int updateMatrix();
-
- bool getClickCount() const noexcept2 A_WARN_UNUSED
- { return mClicks != 0; }
-
- void unsetInventory() noexcept2
- { mInventory = nullptr; }
-
- void setInventory(Inventory *const inventory) noexcept2
- { mInventory = inventory; }
-
- void setCellBackgroundImage(const std::string &xmlName);
-
- void setMaxColumns(const int maxColumns);
-
- private:
- enum Direction
- {
- Left = 0,
- Right,
- Up,
- Down
- };
-
- enum SelectionState
- {
- SEL_NONE = 0,
- SEL_SELECTED,
- SEL_SELECTING,
- SEL_DESELECTING,
- SEL_DRAGGING
- };
-
- /**
- * Sets the currently selected item.
- */
- void setSelectedIndex(const int index);
-
- /**
- * Determine and set the height of the container.
- */
- void adjustHeight();
-
- /**
- * Sends out selection events to the list of selection listeners.
- */
- void distributeValueChangedEvent();
-
- void updateSize();
-
- /**
- * Gets the inventory slot index based on the cursor position.
- *
- * @param x The X coordinate position.
- * @param y The Y coordinate position.
- * @return The slot index on success, -1 on failure.
- */
- int getSlotIndex(int x, int y) const;
-
- int getSlotByXY(int x, int y) const;
-
- Inventory *mInventory;
- Image *mSelImg;
- Image *mProtectedImg;
- Image *mCellBackgroundImg;
- std::string mName;
-
- int *mShowMatrix;
- Skin *mSkin;
- ImageCollection *mVertexes;
- Color mEquipedColor;
- Color mEquipedColor2;
- Color mUnEquipedColor;
- Color mUnEquipedColor2;
- typedef std::list<SelectionListener*> SelectionListenerList;
- typedef SelectionListenerList::iterator SelectionListenerIterator;
- SelectionListenerList mSelectionListeners;
- int mGridColumns;
- int mGridRows;
- int mDrawRows;
- int mSelectedIndex;
- int mLastUsedSlot;
- int mTag;
- int mSortType;
- int mClicks;
- int mBoxWidth;
- int mBoxHeight;
- int mEquippedTextPadding;
- int mPaddingItemX;
- int mPaddingItemY;
- int mMaxColumns;
- SelectionState mSelectionStatus;
- ForceQuantity mForceQuantity;
- ShowEmptyRows mShowEmptyRows;
- bool mDescItems;
-};
-
-#endif // GUI_WIDGETS_ITEMCONTAINER_H
diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp
deleted file mode 100644
index 403573daf..000000000
--- a/src/gui/widgets/itemlinkhandler.cpp
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/itemlinkhandler.h"
-
-#include "itemcolormanager.h"
-#include "settings.h"
-
-#include "gui/viewport.h"
-
-#include "gui/popups/itempopup.h"
-#include "gui/popups/popupmenu.h"
-
-#include "gui/widgets/createwidget.h"
-
-#include "gui/windows/confirmdialog.h"
-#include "gui/windows/helpwindow.h"
-#include "gui/windows/questswindow.h"
-
-#include "input/inputmanager.h"
-
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "resources/db/itemdb.h"
-
-#include "listeners/inputactionremotelistener.h"
-#include "listeners/openurllistener.h"
-
-#include "debug.h"
-
-namespace
-{
- OpenUrlListener listener;
-} // namespace
-
-ItemLinkHandler::ItemLinkHandler() :
- LinkHandler(),
- mAllowCommands(true)
-{
-}
-
-ItemLinkHandler::~ItemLinkHandler()
-{
-}
-
-void ItemLinkHandler::handleCommandLink(const std::string &link,
- const std::string &prefix)
-{
- std::string cmd;
- std::string args;
-
- const std::string cmdStr = link.substr(prefix.size());
- if (!parse2Str(cmdStr, cmd, args))
- {
- cmd = cmdStr;
- args.clear();
- }
- if (mAllowCommands)
- {
- inputManager.executeRemoteChatCommand(cmd, args, nullptr);
- }
- else
- {
- inputActionRemoteListener.setCommand(cmd, args);
- ConfirmDialog *const confirmDlg = CREATEWIDGETR(ConfirmDialog,
- // TRANSLATORS: dialog message
- _("Run command"),
- strprintf("/%s %s", cmd.c_str(), args.c_str()),
- SOUND_REQUEST,
- false,
- Modal_true);
- confirmDlg->addActionListener(&inputActionRemoteListener);
- }
-}
-
-void ItemLinkHandler::handleHelpLink(const std::string &link)
-{
- if (helpWindow != nullptr)
- {
- helpWindow->loadHelp(link.substr(7));
- helpWindow->requestMoveToTop();
- }
-}
-
-void ItemLinkHandler::handleHttpLink(const std::string &link,
- const MouseEvent *const event)
-{
- if (event == nullptr)
- return;
- std::string url = link;
- replaceAll(url, " ", "");
- listener.url = url;
- const MouseButtonT button = event->getButton();
- if (button == MouseButton::LEFT)
- {
- ConfirmDialog *const confirmDlg = CREATEWIDGETR(ConfirmDialog,
- // TRANSLATORS: dialog message
- _("Open url"),
- url,
- SOUND_REQUEST,
- false,
- Modal_true);
- confirmDlg->addActionListener(&listener);
- }
- else if (button == MouseButton::RIGHT)
- {
- if (popupMenu != nullptr)
- popupMenu->showLinkPopup(url);
- }
-}
-
-void ItemLinkHandler::handleItemLink(const std::string &link)
-{
- if ((itemPopup == nullptr) || link.empty())
- return;
-
- const char ch = link[0];
- if (ch < '0' || ch > '9')
- return;
-
- STD_VECTOR<int> str;
- splitToIntVector(str, link, ',');
- if (str.empty())
- return;
-
- const int id = str[0];
-
- if (id > 0)
- {
- str.erase(str.begin());
- while (str.size() < maxCards)
- str.push_back(0);
- const ItemColor color =
- ItemColorManager::getColorFromCards(&str[0]);
-
- const ItemInfo &itemInfo = ItemDB::get(id);
- // +++ need add support for options.
- itemPopup->setItem(itemInfo, color, true, -1, &str[0], nullptr);
- if (itemPopup->isPopupVisible())
- {
- itemPopup->setVisible(Visible_false);
- }
- else if (viewport != nullptr)
- {
- itemPopup->position(viewport->mMouseX,
- viewport->mMouseY);
- }
- }
-}
-
-void ItemLinkHandler::handleSearchLink(const std::string &link)
-{
- if (helpWindow != nullptr)
- {
- helpWindow->search(link.substr(1));
- helpWindow->requestMoveToTop();
- }
-}
-
-void ItemLinkHandler::handleLink(const std::string &link,
- MouseEvent *const event)
-{
- if (link.empty())
- return;
-
- if (strStartWith(link, "http://") || strStartWith(link, "https://"))
- {
- handleHttpLink(link, event);
- }
- else if (link[0] == '?')
- {
- handleSearchLink(link);
- }
- else if (strStartWith(link, "help://"))
- {
- handleHelpLink(link);
- }
- else if (strStartWith(link, settings.linkCommandSymbol))
- {
- handleCommandLink(link, settings.linkCommandSymbol);
- }
- else if (strStartWith(link, "="))
- {
- handleCommandLink(link, "=");
- }
- else if (link == "news")
- {
- if (helpWindow != nullptr)
- helpWindow->loadHelpSimple("news");
- }
- else if (link == "copyright")
- {
- inputManager.executeAction(InputAction::WINDOW_ABOUT);
- }
- else if (link[0] == 'q')
- {
- questsWindow->selectQuest(atoi(link.substr(1).c_str()));
- }
- else
- {
- handleItemLink(link);
- }
-}
diff --git a/src/gui/widgets/itemlinkhandler.h b/src/gui/widgets/itemlinkhandler.h
deleted file mode 100644
index bc90f71d1..000000000
--- a/src/gui/widgets/itemlinkhandler.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_ITEMLINKHANDLER_H
-#define GUI_WIDGETS_ITEMLINKHANDLER_H
-
-#include "gui/widgets/linkhandler.h"
-
-#include "localconsts.h"
-
-class ItemLinkHandler final : public LinkHandler
-{
- public:
- ItemLinkHandler();
-
- A_DELETE_COPY(ItemLinkHandler)
-
- ~ItemLinkHandler();
-
- void handleLink(const std::string &link,
- MouseEvent *event) override final;
-
- void setAllowCommands(const bool b)
- { mAllowCommands = b; }
-
- private:
- void handleCommandLink(const std::string &link,
- const std::string &prefix);
-
- static void handleHelpLink(const std::string &link);
-
- static void handleHttpLink(const std::string &link,
- const MouseEvent *const event);
-
- static void handleItemLink(const std::string &link);
-
- static void handleSearchLink(const std::string &link);
-
- bool mAllowCommands;
-};
-
-#endif // GUI_WIDGETS_ITEMLINKHANDLER_H
diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp
deleted file mode 100644
index 9f667caba..000000000
--- a/src/gui/widgets/itemshortcutcontainer.cpp
+++ /dev/null
@@ -1,650 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/itemshortcutcontainer.h"
-
-#include "dragdrop.h"
-#include "settings.h"
-#include "spellmanager.h"
-
-#include "being/playerinfo.h"
-
-#include "input/inputmanager.h"
-
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/shortcut/itemshortcut.h"
-#include "gui/shortcut/spellshortcut.h"
-
-#include "gui/popups/itempopup.h"
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/skillpopup.h"
-#include "gui/popups/spellpopup.h"
-
-#include "gui/windows/inventorywindow.h"
-#include "gui/windows/skilldialog.h"
-
-#include "input/inputactionoperators.h"
-
-#include "const/resources/skill.h"
-
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-ItemShortcutContainer::ItemShortcutContainer(Widget2 *const widget,
- const unsigned number) :
- ShortcutContainer(widget),
- mItemClicked(false),
- mNumber(number),
- mEquipedColor(getThemeColor(ThemeColorId::ITEM_EQUIPPED)),
- mEquipedColor2(getThemeColor(ThemeColorId::ITEM_EQUIPPED_OUTLINE)),
- mUnEquipedColor(getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED)),
- mUnEquipedColor2(getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED_OUTLINE))
-{
- mMaxItems = ItemShortcut::getItemCount();
-}
-
-ItemShortcutContainer::~ItemShortcutContainer()
-{
-}
-
-void ItemShortcutContainer::setWidget2(const Widget2 *const widget)
-{
- Widget2::setWidget2(widget);
- mEquipedColor = getThemeColor(ThemeColorId::ITEM_EQUIPPED);
- mEquipedColor2 = getThemeColor(ThemeColorId::ITEM_EQUIPPED_OUTLINE);
- mUnEquipedColor = getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED);
- mUnEquipedColor2 = getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED_OUTLINE);
- mForegroundColor = getThemeColor(ThemeColorId::TEXT);
- mForegroundColor2 = getThemeColor(ThemeColorId::TEXT_OUTLINE);
-}
-
-void ItemShortcutContainer::draw(Graphics *const graphics)
-{
- BLOCK_START("ItemShortcutContainer::draw")
- const ItemShortcut *const selShortcut = itemShortcut[mNumber];
- if (selShortcut == nullptr)
- {
- BLOCK_END("ItemShortcutContainer::draw")
- return;
- }
-
- if (settings.guiAlpha != mAlpha)
- {
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- mAlpha = settings.guiAlpha;
- }
-
- Font *const font = getFont();
- drawBackground(graphics);
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- {
- BLOCK_END("ItemShortcutContainer::draw")
- return;
- }
-
- // +++ for future usage need reorder drawing images before text or back
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int itemX = (i % mGridWidth) * mBoxWidth;
- const int itemY = (i / mGridWidth) * mBoxHeight;
-
- // Draw item keyboard shortcut.
- const std::string key = inputManager.getKeyValueString(
- InputAction::SHORTCUT_1 + i);
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- key,
- itemX + 2, itemY + 2);
-
- const int itemId = selShortcut->getItem(i);
- const ItemColor itemColor = selShortcut->getItemColor(i);
-
- if (itemId < 0)
- continue;
-
- // this is item
- if (itemId < SPELL_MIN_ID)
- {
- const Item *const item = inv->findItem(itemId, itemColor);
- if (item != nullptr)
- {
- // Draw item icon.
- Image *const image = item->getImage();
- if (image != nullptr)
- {
- std::string caption;
- if (item->getQuantity() > 1)
- caption = toString(item->getQuantity());
- else if (item->isEquipped() == Equipped_true)
- caption = "Eq.";
-
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- if (item->isEquipped() == Equipped_true)
- {
- font->drawString(graphics,
- mEquipedColor,
- mEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- else
- {
- font->drawString(graphics,
- mUnEquipedColor,
- mUnEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- }
- }
- }
- else if (itemId < SKILL_MIN_ID && (spellManager != nullptr))
- { // this is magic shortcut
- const TextCommand *const spell = spellManager
- ->getSpellByItem(itemId);
- if (spell != nullptr)
- {
- if (!spell->isEmpty())
- {
- Image *const image = spell->getImage();
-
- if (image != nullptr)
- {
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- }
- }
-
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- spell->getSymbol(),
- itemX + 2, itemY + mBoxHeight / 2);
- }
- }
- else if (skillDialog != nullptr)
- {
- const SkillInfo *const skill = skillDialog->getSkill(
- itemId - SKILL_MIN_ID);
- if (skill != nullptr)
- {
- Image *const image = skill->data->icon;
-
- if (image != nullptr)
- {
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- }
- if (!skill->data->haveIcon)
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- skill->data->shortName,
- itemX + 2,
- itemY + mBoxHeight / 2);
- }
- }
- }
- }
- BLOCK_END("ItemShortcutContainer::draw")
-}
-
-void ItemShortcutContainer::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("ItemShortcutContainer::draw")
- const ItemShortcut *const selShortcut = itemShortcut[mNumber];
- if (selShortcut == nullptr)
- {
- BLOCK_END("ItemShortcutContainer::draw")
- return;
- }
-
- if (settings.guiAlpha != mAlpha)
- {
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- mAlpha = settings.guiAlpha;
- }
-
- Font *const font = getFont();
- safeDrawBackground(graphics);
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- {
- BLOCK_END("ItemShortcutContainer::draw")
- return;
- }
-
- // +++ for future usage need reorder drawing images before text or back
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int itemX = (i % mGridWidth) * mBoxWidth;
- const int itemY = (i / mGridWidth) * mBoxHeight;
-
- // Draw item keyboard shortcut.
- const std::string key = inputManager.getKeyValueString(
- InputAction::SHORTCUT_1 + i);
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- key,
- itemX + 2, itemY + 2);
-
- const int itemId = selShortcut->getItem(i);
- const ItemColor itemColor = selShortcut->getItemColor(i);
-
- if (itemId < 0)
- continue;
-
- // this is item
- if (itemId < SPELL_MIN_ID)
- {
- const Item *const item = inv->findItem(itemId, itemColor);
- if (item != nullptr)
- {
- // Draw item icon.
- Image *const image = item->getImage();
- if (image != nullptr)
- {
- std::string caption;
- if (item->getQuantity() > 1)
- caption = toString(item->getQuantity());
- else if (item->isEquipped() == Equipped_true)
- caption = "Eq.";
-
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- if (item->isEquipped() == Equipped_true)
- {
- font->drawString(graphics,
- mEquipedColor,
- mEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- else
- {
- font->drawString(graphics,
- mUnEquipedColor,
- mUnEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- }
- }
- }
- else if (itemId < SKILL_MIN_ID && (spellManager != nullptr))
- { // this is magic shortcut
- const TextCommand *const spell = spellManager
- ->getSpellByItem(itemId);
- if (spell != nullptr)
- {
- if (!spell->isEmpty())
- {
- Image *const image = spell->getImage();
-
- if (image != nullptr)
- {
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- }
- }
-
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- spell->getSymbol(),
- itemX + 2, itemY + mBoxHeight / 2);
- }
- }
- else if (skillDialog != nullptr)
- {
- const SkillInfo *const skill = skillDialog->getSkill(
- itemId - SKILL_MIN_ID);
- if (skill != nullptr)
- {
- Image *const image = skill->data->icon;
-
- if (image != nullptr)
- {
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- }
- if (!skill->data->haveIcon)
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor,
- skill->data->shortName,
- itemX + 2,
- itemY + mBoxHeight / 2);
- }
- }
- }
- }
- BLOCK_END("ItemShortcutContainer::draw")
-}
-
-void ItemShortcutContainer::mouseDragged(MouseEvent &event)
-{
- if (mNumber == SHORTCUT_AUTO_TAB)
- return;
- ItemShortcut *const selShortcut = itemShortcut[mNumber];
- if (selShortcut == nullptr)
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- if (dragDrop.isEmpty() && mItemClicked)
- {
- mItemClicked = false;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
- if (index == -1)
- return;
-
- const int itemId = selShortcut->getItem(index);
- const ItemColor itemColor = selShortcut->getItemColor(index);
-
- if (itemId < 0)
- return;
-
- event.consume();
- if (itemId < SPELL_MIN_ID)
- { // items
- if (PlayerInfo::getInventory() == nullptr)
- return;
-
- const Item *const item = PlayerInfo::getInventory()->findItem(
- itemId, itemColor);
-
- if (item != nullptr)
- {
- selShortcut->removeItem(index);
- dragDrop.dragItem(item, DragDropSource::Shortcuts, index);
- }
- else
- {
- dragDrop.clear();
- }
- }
- else if (itemId < SKILL_MIN_ID)
- { // spells/commands
- if (spellManager == nullptr)
- {
- dragDrop.clear();
- return;
- }
-
- const TextCommand *const spell = spellManager->getSpellByItem(
- itemId);
- if (spell != nullptr)
- {
- selShortcut->removeItem(index);
- dragDrop.dragCommand(spell,
- DragDropSource::Shortcuts, index);
- dragDrop.setItem(itemId);
- }
- else
- {
- dragDrop.clear();
- }
- }
- else
- { // skills
- if (skillDialog == nullptr)
- {
- dragDrop.clear();
- return;
- }
- const SkillInfo *const skill
- = skillDialog->getSkillByItem(itemId);
- if (skill != nullptr)
- {
- const std::string itemData = selShortcut->getItemData(
- index);
- selShortcut->removeItem(index);
- dragDrop.dragSkill(skill,
- DragDropSource::Shortcuts,
- index);
- dragDrop.setItem(itemId);
- dragDrop.setItemColor(itemColor);
- dragDrop.setItemData(itemData);
- }
- else
- {
- dragDrop.clear();
- }
- }
- }
- }
-}
-
-void ItemShortcutContainer::mousePressed(MouseEvent &event)
-{
- ItemShortcut *const selShortcut = itemShortcut[mNumber];
- if (selShortcut == nullptr)
- return;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- event.consume();
- // Stores the selected item if theirs one.
- if (selShortcut->isItemSelected() && (inventoryWindow != nullptr) &&
- (inventoryWindow->isWindowVisible()
- || selShortcut->getSelectedItem() >= SPELL_MIN_ID))
- {
- selShortcut->setItem(index);
- selShortcut->setItemSelected(-1);
- if (spellShortcut != nullptr)
- spellShortcut->setItemSelected(-1);
- inventoryWindow->unselectItem();
- }
- else if (selShortcut->getItem(index) != 0)
- {
- mItemClicked = true;
- }
- }
- else if (event.getButton() == MouseButton::RIGHT)
- {
- event.consume();
- if (popupMenu != nullptr &&
- viewport != nullptr)
- {
- popupMenu->showItemPopup(viewport->mMouseX,
- viewport->mMouseY,
- selShortcut->getItem(index),
- selShortcut->getItemColor(index));
- }
- }
-}
-
-void ItemShortcutContainer::mouseReleased(MouseEvent &event)
-{
- ItemShortcut *const selShortcut = itemShortcut[mNumber];
- if (selShortcut == nullptr)
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- if (selShortcut->isItemSelected())
- selShortcut->setItemSelected(-1);
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
- if (index == -1)
- return;
-
- if (dragDrop.isEmpty())
- {
- if ((selShortcut->getItem(index) != 0) && mItemClicked)
- selShortcut->useItem(index);
- }
- else
- {
- if (dragDrop.getSource() == DragDropSource::Shortcuts)
- {
- const int oldIndex = dragDrop.getTag();
- selShortcut->setItem(oldIndex, dragDrop.getItem(),
- dragDrop.getItemColor());
- selShortcut->swap(oldIndex, index);
- }
- else
- {
- selShortcut->setItemData(index,
- dragDrop.getItemData());
- selShortcut->setItem(index, dragDrop.getItem(),
- dragDrop.getItemColor());
- }
- dragDrop.clear();
- dragDrop.deselect();
- }
-
- mItemClicked = false;
- }
-}
-
-void ItemShortcutContainer::mouseMoved(MouseEvent &event)
-{
- const ItemShortcut *const selShortcut = itemShortcut[mNumber];
- if (selShortcut == nullptr)
- return;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- const int itemId = selShortcut->getItem(index);
- const ItemColor itemColor = selShortcut->getItemColor(index);
-
- if (itemId < 0)
- return;
-
- if (itemId < SPELL_MIN_ID)
- {
- skillPopup->setVisible(Visible_false);
- spellPopup->setVisible(Visible_false);
-
- Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- const Item *const item = inv->findItem(itemId, itemColor);
- if ((item != nullptr) && (viewport != nullptr))
- {
- itemPopup->setItem(item, false);
- itemPopup->position(viewport->mMouseX, viewport->mMouseY);
- }
- else
- {
- itemPopup->setVisible(Visible_false);
- }
- }
- else if (itemId < SKILL_MIN_ID && (spellManager != nullptr))
- {
- skillPopup->setVisible(Visible_false);
- itemPopup->setVisible(Visible_false);
- const TextCommand *const spell = spellManager->getSpellByItem(itemId);
- if ((spell != nullptr) && (viewport != nullptr))
- {
- spellPopup->setItem(spell);
- spellPopup->view(viewport->mMouseX,
- viewport->mMouseY);
- }
- else
- {
- spellPopup->setVisible(Visible_false);
- }
- }
- else if (skillDialog != nullptr)
- {
- itemPopup->setVisible(Visible_false);
- spellPopup->setVisible(Visible_false);
- const SkillInfo *const skill = skillDialog->getSkillByItem(itemId);
- if (skill == nullptr)
- return;
-
- const std::string data = selShortcut->getItemData(index);
- CastTypeT castType = CastType::Default;
- int offsetX = 0;
- int offsetY = 0;
- if (!data.empty())
- {
- STD_VECTOR<int> vect;
- splitToIntVector(vect, data, ' ');
- const size_t sz = vect.size();
- if (sz > 0)
- castType = static_cast<CastTypeT>(vect[0]);
- if (sz > 2)
- {
- offsetX = vect[1];
- offsetY = vect[2];
- }
- }
- skillPopup->show(skill,
- toInt(itemColor, int),
- castType,
- offsetX,
- offsetY);
- skillPopup->position(viewport->mMouseX,
- viewport->mMouseY);
- }
-}
-
-// Hide ItemTooltip
-void ItemShortcutContainer::mouseExited(MouseEvent &event A_UNUSED)
-{
- if (itemPopup != nullptr)
- itemPopup->setVisible(Visible_false);
- if (spellPopup != nullptr)
- spellPopup->setVisible(Visible_false);
- if (skillPopup != nullptr)
- skillPopup->setVisible(Visible_false);
-}
-
-void ItemShortcutContainer::widgetHidden(const Event &event A_UNUSED)
-{
- if (itemPopup != nullptr)
- itemPopup->setVisible(Visible_false);
- if (spellPopup != nullptr)
- spellPopup->setVisible(Visible_false);
-}
diff --git a/src/gui/widgets/itemshortcutcontainer.h b/src/gui/widgets/itemshortcutcontainer.h
deleted file mode 100644
index 146834f4d..000000000
--- a/src/gui/widgets/itemshortcutcontainer.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_ITEMSHORTCUTCONTAINER_H
-#define GUI_WIDGETS_ITEMSHORTCUTCONTAINER_H
-
-#include "gui/widgets/shortcutcontainer.h"
-
-/**
- * An item shortcut container. Used to quickly use items.
- *
- * \ingroup GUI
- */
-class ItemShortcutContainer final : public ShortcutContainer
-{
- public:
- /**
- * Constructor. Initializes the graphic.
- */
- ItemShortcutContainer(Widget2 *const widget,
- const unsigned number);
-
- A_DELETE_COPY(ItemShortcutContainer)
-
- /**
- * Destructor.
- */
- ~ItemShortcutContainer();
-
- /**
- * Draws the items.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Handles mouse when dragged.
- */
- void mouseDragged(MouseEvent &event) override final;
-
- /**
- * Handles mouse when pressed.
- */
- void mousePressed(MouseEvent &event) override final;
-
- /**
- * Handles mouse release.
- */
- void mouseReleased(MouseEvent &event) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void mouseExited(MouseEvent &event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void setWidget2(const Widget2 *const widget) override final;
-
- private:
- bool mItemClicked;
- unsigned mNumber;
-
- Color mEquipedColor;
- Color mEquipedColor2;
- Color mUnEquipedColor;
- Color mUnEquipedColor2;
-};
-
-#endif // GUI_WIDGETS_ITEMSHORTCUTCONTAINER_H
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp
deleted file mode 100644
index aeacddbdb..000000000
--- a/src/gui/widgets/label.cpp
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/label.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "debug.h"
-
-Skin *Label::mSkin = nullptr;
-int Label::mInstances = 0;
-
-Label::Label(const Widget2 *const widget) :
- Widget(widget),
- WidgetListener(),
- ToolTipListener(),
- mCaption(),
- mTextChunk(),
- mAlignment(Graphics::LEFT),
- mPadding(0),
- mTextChanged(true)
-{
- init();
-}
-
-Label::Label(const Widget2 *const widget,
- const std::string &caption) :
- Widget(widget),
- WidgetListener(),
- ToolTipListener(),
- mCaption(caption),
- mTextChunk(),
- mAlignment(Graphics::LEFT),
- mPadding(0),
- mTextChanged(true)
-{
- const Font *const font = getFont();
- setWidth(font->getWidth(caption));
- setHeight(font->getHeight());
- init();
-}
-
-Label::~Label()
-{
- if (mWindow != nullptr)
- mWindow->removeWidgetListener(this);
-
- if (gui != nullptr)
- gui->removeDragged(this);
-
- mInstances --;
- if (mInstances == 0)
- {
- if (theme != nullptr)
- theme->unload(mSkin);
- }
- removeMouseListener(this);
- mTextChunk.deleteImage();
-}
-
-void Label::init()
-{
- addMouseListener(this);
- mAllowLogic = false;
- mForegroundColor = getThemeColor(ThemeColorId::LABEL);
- mForegroundColor2 = getThemeColor(ThemeColorId::LABEL_OUTLINE);
- if (mInstances == 0)
- {
- if (theme != nullptr)
- mSkin = theme->load("label.xml", "");
- }
- mInstances ++;
-
- if (mSkin != nullptr)
- mPadding = mSkin->getPadding();
- else
- mPadding = 0;
- setSelectable(false);
-}
-
-void Label::draw(Graphics *const graphics)
-{
- BLOCK_START("Label::draw")
- int textX;
- const Rect &rect = mDimension;
- const int textY = rect.height / 2 - getFont()->getHeight() / 2;
- Font *const font = getFont();
-
- switch (mAlignment)
- {
- case Graphics::LEFT:
- default:
- textX = mPadding;
- break;
- case Graphics::CENTER:
- textX = (rect.width - font->getWidth(mCaption)) / 2;
- break;
- case Graphics::RIGHT:
- if (rect.width > mPadding)
- textX = rect.width - mPadding - font->getWidth(mCaption);
- else
- textX = 0;
- break;
- }
-
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mCaption;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, textX, textY);
- BLOCK_END("Label::draw")
-}
-
-void Label::safeDraw(Graphics *const graphics)
-{
- Label::draw(graphics);
-}
-
-void Label::adjustSize()
-{
- const Font *const font = getFont();
- const int pad2 = 2 * mPadding;
- setWidth(font->getWidth(mCaption) + pad2);
- setHeight(font->getHeight() + pad2);
-}
-
-void Label::setForegroundColor(const Color &color)
-{
- if (mForegroundColor != color || mForegroundColor2 != color)
- mTextChanged = true;
-// logger->log("Label::setForegroundColor: " + mCaption);
- mForegroundColor = color;
- mForegroundColor2 = color;
-}
-
-void Label::setForegroundColorAll(const Color &color1,
- const Color &color2)
-{
- if (mForegroundColor != color1 || mForegroundColor2 != color2)
- mTextChanged = true;
-// logger->log("Label::setForegroundColorAll: " + mCaption);
- mForegroundColor = color1;
- mForegroundColor2 = color2;
-}
-
-void Label::resizeTo(const int maxSize, const int minSize)
-{
- const Font *const font = getFont();
- const int pad2 = 2 * mPadding;
- setHeight(font->getHeight() + pad2);
-
- if (font->getWidth(mCaption) + pad2 > maxSize)
- {
- const int dots = font->getWidth("...");
- if (dots > maxSize)
- {
- setWidth(maxSize);
- return;
- }
- const size_t szChars = mCaption.size();
- for (size_t f = 1; f < szChars - 1; f ++)
- {
- const std::string text = mCaption.substr(0, szChars - f);
- const int width = font->getWidth(text) + dots + pad2;
- if (width <= maxSize)
- {
- setCaption(text + "...");
- setWidth(width);
- return;
- }
- }
- setWidth(maxSize);
- }
- else
- {
- int sz = font->getWidth(mCaption) + pad2;
- if (sz < minSize)
- sz = minSize;
- setWidth(sz);
- }
-}
-
-void Label::setCaption(const std::string& caption)
-{
- if (caption != mCaption)
- mTextChanged = true;
- mCaption = caption;
-}
-
-void Label::setParent(Widget *const widget)
-{
- if (mWindow != nullptr)
- mWindow->addWidgetListener(this);
- Widget::setParent(widget);
-}
-
-void Label::setWindow(Widget *const widget)
-{
- if ((widget == nullptr) && (mWindow != nullptr))
- {
- mWindow->removeWidgetListener(this);
- mWindow = nullptr;
- }
- else
- {
- Widget2::setWindow(widget);
- }
-}
-
-void Label::widgetHidden(const Event &event A_UNUSED)
-{
- mTextChanged = true;
- mTextChunk.deleteImage();
-}
-
-void Label::finalCleanup()
-{
- mSkin = nullptr;
-}
diff --git a/src/gui/widgets/label.h b/src/gui/widgets/label.h
deleted file mode 100644
index 26790258c..000000000
--- a/src/gui/widgets/label.h
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_LABEL_H
-#define GUI_WIDGETS_LABEL_H
-
-#include "gui/fonts/textchunk.h"
-
-#include "gui/widgets/widget.h"
-
-#include "listeners/tooltiplistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "render/graphics.h"
-
-#include "localconsts.h"
-
-class Skin;
-
-/**
- * Label widget. Same as the Guichan label but modified to use the palette
- * system.
- *
- * \ingroup GUI
- */
-class Label final : public Widget,
- public WidgetListener,
- public ToolTipListener
-{
- public:
- /**
- * Constructor.
- */
- explicit Label(const Widget2 *const widget);
-
- /**
- * Constructor. This version of the constructor sets the label with an
- * inintialization string.
- */
- Label(const Widget2 *const widget,
- const std::string &caption);
-
- A_DELETE_COPY(Label)
-
- ~Label();
-
- void init();
-
- /**
- * Draws the label.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void adjustSize();
-
- void setForegroundColor(const Color &color);
-
- void setForegroundColorAll(const Color &color1,
- const Color &color2);
-
- void resizeTo(const int maxSize, const int minSize);
-
- /**
- * Gets the caption of the label.
- *
- * @return The caption of the label.
- * @see setCaption
- */
- const std::string &getCaption() const
- { return mCaption; }
-
- /**
- * Sets the caption of the label. It's advisable to call
- * adjustSize after setting of the caption to adjust the
- * label's size to fit the caption.
- *
- * @param caption The caption of the label.
- * @see getCaption, adjustSize
- */
- void setCaption(const std::string& caption);
-
- /**
- * Sets the alignment of the caption. The alignment is relative
- * to the center of the label.
- *
- * @param alignment The alignment of the caption of the label.
- * @see getAlignment, Graphics
- */
- void setAlignment(Graphics::Alignment alignment)
- { mAlignment = alignment; }
-
- /**
- * Gets the alignment of the caption. The alignment is relative to
- * the center of the label.
- *
- * @return The alignment of caption of the label.
- * @see setAlignmentm Graphics
- */
- Graphics::Alignment getAlignment() const
- { return mAlignment; }
-
- void setParent(Widget *const widget) override final;
-
- void setWindow(Widget *const widget) override final;
-
- void widgetHidden(const Event &event) override final;
-
- static Skin *mSkin;
-
- static int mInstances;
-
- static void finalCleanup();
-
- private:
- /**
- * Holds the caption of the label.
- */
- std::string mCaption;
-
- TextChunk mTextChunk;
-
- /**
- * Holds the alignment of the caption.
- */
- Graphics::Alignment mAlignment;
-
- int mPadding;
-
- bool mTextChanged;
-};
-
-#endif // GUI_WIDGETS_LABEL_H
diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp
deleted file mode 100644
index 0a9464dd2..000000000
--- a/src/gui/widgets/layout.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/layout.h"
-
-#include "debug.h"
-
-Layout::Layout() :
- LayoutCell(),
- mComputed(false)
-{
- getArray();
- setPadding(6);
-}
-
-void Layout::reflow(int &restrict nw, int &restrict nh)
-{
- if (!mComputed)
- {
- computeSizes();
- mComputed = true;
- }
-
- nw = (nw == 0 ? mSize[0] + 2 * mHPadding : nw);
- nh = (nh == 0 ? mSize[1] + 2 * mVPadding : nh);
- LayoutCell::reflow(0, 0, nw, nh);
-}
diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h
deleted file mode 100644
index 4e9c8f8c3..000000000
--- a/src/gui/widgets/layout.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_LAYOUT_H
-#define GUI_WIDGETS_LAYOUT_H
-
-#include "gui/widgets/layoutcell.h"
-
-#include "localconsts.h"
-
-/**
- * This class is an helper for setting the position of widgets. They are
- * positioned along the cells of some rectangular tables. The layout may either
- * be a single table or a tree of nested tables.
- *
- * The size of a given table column can either be set manually or be chosen
- * from the widest widget of the column. An empty column has a AUTO_DEF width,
- * which means it will be extended so that the layout fits its minimum width.
- *
- * The process is similar for table rows. By default, there is a spacing of 4
- * pixels between rows and between columns, and a margin of 6 pixels around the
- * whole layout.
- */
-class Layout final : public LayoutCell
-{
- public:
- Layout();
-
- A_DELETE_COPY(Layout)
-
- /**
- * Sets the margin around the layout.
- */
- void setMargin(int m)
- { setPadding(m); }
-
- /**
- * Sets the positions of all the widgets.
- * @see LayoutArray::reflow
- */
- void reflow(int &restrict nW, int &restrict nH);
-
- private:
- bool mComputed;
-};
-
-#endif // GUI_WIDGETS_LAYOUT_H
diff --git a/src/gui/widgets/layoutarray.cpp b/src/gui/widgets/layoutarray.cpp
deleted file mode 100644
index 6269d8b5b..000000000
--- a/src/gui/widgets/layoutarray.cpp
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/layoutarray.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "gui/widgets/layoutcell.h"
-#include "gui/widgets/widget.h"
-
-#include <cassert>
-
-#include "debug.h"
-
-LayoutArray::LayoutArray() :
- mCells(),
- mSpacing(4)
-{
-}
-
-LayoutArray::~LayoutArray()
-{
- STD_VECTOR <STD_VECTOR <LayoutCell *> >::iterator
- i = mCells.begin();
- const STD_VECTOR <STD_VECTOR <LayoutCell *> >::iterator
- i_end = mCells.end();
- while (i != i_end)
- {
- STD_VECTOR< LayoutCell * >::iterator j = i->begin();
- const STD_VECTOR< LayoutCell * >::iterator j_end = i->end();
- while (j != j_end)
- {
- delete *j;
- ++j;
- }
- ++i;
- }
-}
-
-LayoutCell &LayoutArray::at(const int x, const int y,
- const int w, const int h)
-{
- resizeGrid(x + w, y + h);
- LayoutCell *&cell = mCells[CAST_SIZE(y)][static_cast<size_t>(x)];
- if (cell == nullptr)
- cell = new LayoutCell;
- return *cell;
-}
-
-void LayoutArray::resizeGrid(int w, const int h)
-{
- const bool extW = (w != 0) && w > CAST_S32(mSizes[0].size());
- const bool extH = (h != 0) && h > CAST_S32(mSizes[1].size());
-
- if (!extW && !extH)
- return;
-
- if (extH)
- {
- mSizes[1].resize(CAST_SIZE(h), LayoutType::DEF);
- mCells.resize(CAST_SIZE(h));
- if (!extW)
- w = CAST_S32(mSizes[0].size());
- }
-
- if (extW)
- mSizes[0].resize(CAST_SIZE(w), LayoutType::DEF);
-
- STD_VECTOR <STD_VECTOR <LayoutCell *> >::iterator
- i = mCells.begin();
- const STD_VECTOR <STD_VECTOR <LayoutCell *> >::iterator
- i_end = mCells.end();
- while (i != i_end)
- {
- i->resize(CAST_SIZE(w), nullptr);
- ++i;
- }
-}
-
-void LayoutArray::setColWidth(const int n, const int w)
-{
- resizeGrid(n + 1, 0);
- mSizes[0U][CAST_SIZE(n)] = w;
-}
-
-void LayoutArray::setRowHeight(const int n, const int h)
-{
- resizeGrid(0, n + 1);
- mSizes[1][CAST_SIZE(n)] = h;
-}
-
-void LayoutArray::matchColWidth(const int n1, const int n2)
-{
- resizeGrid(std::max(n1, n2) + 1, 0);
- const STD_VECTOR<int> widths = getSizes(0, LayoutType::DEF);
- const int s = std::max(widths[CAST_SIZE(n1)],
- widths[CAST_SIZE(n2)]);
- mSizes[0][CAST_SIZE(n1)] = s;
- mSizes[0][CAST_SIZE(n2)] = s;
-}
-
-void LayoutArray::extend(const int x, const int y, const int w, const int h)
-{
- LayoutCell &cell = at(x, y, w, h);
- cell.mExtent[0] = w;
- cell.mExtent[1] = h;
-}
-
-LayoutCell &LayoutArray::place(Widget *const widget, const int x,
- const int y, const int w, const int h)
-{
- LayoutCell &cell = at(x, y, w, h);
- assert(cell.mType == LayoutCell::NONE);
- cell.mType = LayoutCell::WIDGET;
- cell.mWidget = widget;
- if (widget != nullptr)
- {
- cell.mSize[0] = w == 1 ? widget->getWidth() : 0;
- cell.mSize[1] = h == 1 ? widget->getHeight() : 0;
- }
- else
- {
- cell.mSize[0] = 1;
- cell.mSize[1] = 1;
- }
- cell.mExtent[0] = w;
- cell.mExtent[1] = h;
- cell.mHPadding = 0;
- cell.mVPadding = 0;
- cell.mAlign[0] = LayoutCell::FILL;
- cell.mAlign[1] = LayoutCell::FILL;
- int &cs = mSizes[0][CAST_SIZE(x)];
- int &rs = mSizes[1][CAST_SIZE(y)];
- if (cs == LayoutType::DEF && w == 1)
- cs = 0;
- if (rs == LayoutType::DEF && h == 1)
- rs = 0;
- return cell;
-}
-
-void LayoutArray::align(int &restrict pos, int &restrict size, const int dim,
- LayoutCell const &restrict cell,
- const int *restrict const sizes,
- const int sizeCount) const
-{
- if (dim < 0 || dim >= 2)
- return;
- int size_max = sizes[0];
- int cnt = cell.mExtent[dim];
- if ((sizeCount != 0) && cell.mExtent[dim] > sizeCount)
- cnt = sizeCount;
-
- for (int i = 1; i < cnt; ++i)
- size_max += sizes[i] + mSpacing;
- size = std::min<int>(cell.mSize[dim], size_max);
-
- switch (cell.mAlign[dim])
- {
- case LayoutCell::LEFT:
- return;
- case LayoutCell::RIGHT:
- pos += size_max - size;
- return;
- case LayoutCell::CENTER:
- pos += (size_max - size) / 2;
- return;
- case LayoutCell::FILL:
- size = size_max;
- return;
- default:
- logger->log1("LayoutArray::align unknown layout");
- return;
- }
-}
-
-STD_VECTOR<int> LayoutArray::getSizes(const int dim, int upp) const
-{
- if (dim < 0 || dim >= 2)
- return mSizes[1];
-
- const int gridW = CAST_S32(mSizes[0].size());
- const int gridH = CAST_S32(mSizes[1].size());
- STD_VECTOR<int> sizes = mSizes[dim];
-
- // Compute minimum sizes.
- for (int gridY = 0; gridY < gridH; ++gridY)
- {
- for (int gridX = 0; gridX < gridW; ++gridX)
- {
- const LayoutCell *const cell = mCells[CAST_SIZE(gridY)]
- [CAST_SIZE(gridX)];
- if ((cell == nullptr) || cell->mType == LayoutCell::NONE)
- continue;
-
- if (cell->mExtent[dim] == 1)
- {
- const int n = (dim == 0 ? gridX : gridY);
- const int s = cell->mSize[dim] + cell->mVPadding * 2;
- if (s > sizes[CAST_SIZE(n)])
- sizes[CAST_SIZE(n)] = s;
- }
- }
- }
-
- if (upp == LayoutType::DEF)
- return sizes;
-
- // Compute the FILL sizes.
- const int nb = CAST_S32(sizes.size());
- int nbFill = 0;
- for (int i = 0; i < nb; ++i)
- {
- if (mSizes[CAST_SIZE(dim)][static_cast<size_t>(i)]
- <= LayoutType::DEF)
- {
- ++nbFill;
- if (mSizes[CAST_SIZE(dim)][static_cast<size_t>(i)] ==
- LayoutType::SET ||
- sizes[CAST_SIZE(i)] <= LayoutType::DEF)
- {
- sizes[CAST_SIZE(i)] = 0;
- }
- }
- upp -= sizes[CAST_SIZE(i)] + mSpacing;
- }
- upp = upp + mSpacing;
-
- if (nbFill == 0)
- return sizes;
-
- for (int i = 0; i < nb; ++i)
- {
- if (mSizes[CAST_SIZE(dim)][static_cast<size_t>(i)] >
- LayoutType::DEF)
- {
- continue;
- }
-
- const int s = upp / nbFill;
- sizes[CAST_SIZE(i)] += s;
- upp -= s;
- --nbFill;
- }
-
- return sizes;
-}
-
-int LayoutArray::getSize(const int dim) const
-{
- STD_VECTOR<int> sizes = getSizes(dim, LayoutType::DEF);
- int size = 0;
- const int nb = CAST_S32(sizes.size());
- for (int i = 0; i < nb; ++i)
- {
- if (sizes[CAST_SIZE(i)] > LayoutType::DEF)
- size += sizes[CAST_SIZE(i)];
- size += mSpacing;
- }
- return size - mSpacing;
-}
-
-void LayoutArray::reflow(const int nx, const int ny,
- const int nw, const int nh)
-{
- const int gridW = CAST_S32(mSizes[0].size());
- const int gridH = CAST_S32(mSizes[1].size());
-
- STD_VECTOR<int> widths = getSizes(0, nw);
- STD_VECTOR<int> heights = getSizes(1, nh);
-
- const int szW = CAST_S32(widths.size());
- const int szH = CAST_S32(heights.size());
- int y = ny;
- for (int gridY = 0; gridY < gridH; ++gridY)
- {
- int x = nx;
- for (int gridX = 0; gridX < gridW; ++gridX)
- {
- LayoutCell *const cell = mCells[CAST_SIZE(gridY)]
- [CAST_SIZE(gridX)];
- if ((cell != nullptr) && cell->mType != LayoutCell::NONE)
- {
- int dx = x, dy = y, dw = 0, dh = 0;
- align(dx, dw, 0, *cell,
- &widths[CAST_SIZE(gridX)], szW - gridX);
- align(dy, dh, 1, *cell,
- &heights[CAST_SIZE(gridY)], szH - gridY);
- cell->reflow(dx, dy, dw, dh);
- }
- x += widths[CAST_SIZE(gridX)] + mSpacing;
- }
- y += heights[CAST_SIZE(gridY)] + mSpacing;
- }
-}
diff --git a/src/gui/widgets/layoutarray.h b/src/gui/widgets/layoutarray.h
deleted file mode 100644
index cca05e091..000000000
--- a/src/gui/widgets/layoutarray.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_LAYOUTARRAY_H
-#define GUI_WIDGETS_LAYOUTARRAY_H
-
-#include "utils/vector.h"
-
-#include "localconsts.h"
-
-class LayoutCell;
-class Widget;
-
-/**
- * This class contains a rectangular array of cells.
- */
-class LayoutArray final
-{
- friend class LayoutCell;
-
- public:
- LayoutArray();
-
- A_DEFAULT_COPY(LayoutArray)
-
- ~LayoutArray();
-
- /**
- * Returns a reference on the cell at given position.
- */
- LayoutCell &at(const int x, const int y,
- const int w = 1, const int h = 1) A_WARN_UNUSED;
-
- /**
- * Places a widget in a given cell.
- * @param w number of columns the widget spawns.
- * @param h number of rows the widget spawns.
- * @note When @a w is 1, the width of column @a x is reset to zero if
- * it was AUTO_DEF. Similarly for @a h.
- */
- LayoutCell &place(Widget *const widget, const int x, const int y,
- const int w = 1, const int h = 1);
-
- /**
- * Sets the minimum width of a column.
- */
- void setColWidth(const int n, const int w);
-
- /**
- * Sets the minimum height of a row.
- */
- void setRowHeight(const int n, const int h);
-
- /**
- * Sets the widths of two columns to the maximum of their widths.
- */
- void matchColWidth(const int n1, const int n2);
-
- /**
- * Spawns a cell over several columns/rows.
- */
- void extend(const int x, const int y, const int w, const int h);
-
- /**
- * Computes and sets the positions of all the widgets.
- * @param nW width of the array, used to resize the AUTO_ columns.
- * @param nH height of the array, used to resize the AUTO_ rows.
- */
- void reflow(const int nX, const int nY, const int nW, const int nH);
-
- private:
- // Copy not allowed, as the array owns all its cells.
- explicit LayoutArray(LayoutArray const &);
- LayoutArray &operator=(LayoutArray const &);
-
- /**
- * Gets the position and size of a widget along a given axis
- */
- void align(int &restrict pos,
- int &restrict size,
- const int dim,
- LayoutCell const &restrict cell,
- const int *restrict const sizes,
- const int sizeCount) const A_NONNULL(6);
-
- /**
- * Ensures the private vectors are large enough.
- */
- void resizeGrid(int w, const int h);
-
- /**
- * Gets the column/row sizes along a given axis.
- * @param upp target size for the array. Ignored if AUTO_DEF.
- */
- STD_VECTOR<int> getSizes(const int dim, int upp) const A_WARN_UNUSED;
-
- /**
- * Gets the total size along a given axis.
- */
- int getSize(const int dim) const A_WARN_UNUSED;
-
- STD_VECTOR<int> mSizes[2];
- STD_VECTOR< STD_VECTOR < LayoutCell * > > mCells;
-
- int mSpacing;
-};
-
-#endif // GUI_WIDGETS_LAYOUTARRAY_H
diff --git a/src/gui/widgets/layoutcell.cpp b/src/gui/widgets/layoutcell.cpp
deleted file mode 100644
index 7db5d0783..000000000
--- a/src/gui/widgets/layoutcell.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/layoutcell.h"
-
-#include "gui/widgets/layoutarray.h"
-#include "gui/widgets/widget.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-static LayoutArray tempArray;
-LayoutCell LayoutCell::emptyCell;
-
-LayoutCell::~LayoutCell()
-{
- if (mType == ARRAY)
- delete2(mArray)
-}
-
-LayoutArray &LayoutCell::getArray()
-{
- if (mType == WIDGET)
- return tempArray;
- if (mType == ARRAY)
- {
- if (mArray == nullptr)
- return tempArray;
- return *mArray;
- }
-
- mArray = new LayoutArray;
- mType = ARRAY;
- mExtent[0] = 1;
- mExtent[1] = 1;
- mHPadding = 0;
- mVPadding = 0;
- mAlign[0] = FILL;
- mAlign[1] = FILL;
- return *mArray;
-}
-
-void LayoutCell::reflow(int nx, int ny, int nw, int nh)
-{
- if (mType == NONE)
- return;
-
- nx += mHPadding;
- ny += mVPadding;
- nw -= 2 * mHPadding;
- nh -= 2 * mVPadding;
- if (mType == ARRAY)
- mArray->reflow(nx, ny, nw, nh);
- else
- mWidget->setDimension(Rect(nx, ny, nw, nh));
-}
-
-void LayoutCell::computeSizes()
-{
- if (mType != ARRAY)
- return;
-
- STD_VECTOR <STD_VECTOR <LayoutCell *> >::const_iterator
- i = mArray->mCells.begin();
- const STD_VECTOR <STD_VECTOR <LayoutCell *> >::const_iterator
- i_end = mArray->mCells.end();
- while (i != i_end)
- {
- STD_VECTOR <LayoutCell *>::const_iterator j = i->begin();
- while (j != i->end())
- {
- LayoutCell *const cell = *j;
- if ((cell != nullptr) && cell->mType == ARRAY)
- cell->computeSizes();
-
- ++j;
- }
- ++i;
- }
-
- mSize[0] = mArray->getSize(0);
- mSize[1] = mArray->getSize(1);
-}
-
-LayoutCell &LayoutCell::at(const int x, const int y)
-{
- return getArray().at(x, y);
-}
-
-LayoutCell &LayoutCell::place(Widget *const wg,
- const int x, const int y,
- const int w, const int h)
-{
- return getArray().place(wg, x, y, w, h);
-}
-
-void LayoutCell::matchColWidth(const int n1, const int n2)
-{
- getArray().matchColWidth(n1, n2);
-}
-
-void LayoutCell::setColWidth(const int n, const int w)
-{
- getArray().setColWidth(n, w);
-}
-
-void LayoutCell::setRowHeight(const int n, const int h)
-{
- getArray().setRowHeight(n, h);
-}
-
-void LayoutCell::extend(const int x, const int y,
- const int w, const int h)
-{
- getArray().extend(x, y, w, h);
-}
diff --git a/src/gui/widgets/layoutcell.h b/src/gui/widgets/layoutcell.h
deleted file mode 100644
index e6404cfde..000000000
--- a/src/gui/widgets/layoutcell.h
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_LAYOUTCELL_H
-#define GUI_WIDGETS_LAYOUTCELL_H
-
-#include "localconsts.h"
-
-class LayoutArray;
-class Widget;
-
-/**
- * This class describes the formatting of a widget in the cell of a layout
- * table. Horizontally, a widget can either fill the width of the cell (minus
- * the cell padding), or it can retain its size and be flushed left, or flush
- * right, or centered in the cell. The process is similar for the vertical
- * alignment, except that top is represented by LEFT and bottom by RIGHT.
- */
-class LayoutCell notfinal
-{
- friend class Layout;
- friend class LayoutArray;
-
- public:
- A_DEFAULT_COPY(LayoutCell)
-
- enum Alignment
- {
- LEFT = 0,
- RIGHT,
- CENTER,
- FILL
- };
-
- virtual ~LayoutCell();
-
- /**
- * Sets the padding around the cell content.
- */
- LayoutCell &setPadding(int p)
- { mHPadding = p; mVPadding = p; return *this; }
-
- /**
- * Sets the vertical padding around the cell content.
- */
- LayoutCell &setVPadding(int p)
- { mVPadding = p; return *this; }
-
- /**
- * Sets the horisontal padding around the cell content.
- */
- LayoutCell &setHPadding(int p)
- { mHPadding = p; return *this; }
-
- /**
- * Sets the horizontal alignment of the cell content.
- */
- LayoutCell &setHAlign(const Alignment a)
- { mAlign[0] = a; return *this; }
-
- /**
- * Sets the vertical alignment of the cell content.
- */
- LayoutCell &setVAlign(const Alignment a)
- { mAlign[1] = a; return *this; }
-
- /**
- * @see LayoutArray::at
- */
- LayoutCell &at(const int x, const int y) A_WARN_UNUSED;
-
- /**
- * @see LayoutArray::place
- */
- LayoutCell &place(Widget *const wg,
- const int x, const int y,
- const int w = 1, const int h = 1);
-
- /**
- * @see LayoutArray::matchColWidth
- */
- void matchColWidth(const int n1, const int n2);
-
- /**
- * @see LayoutArray::setColWidth
- */
- void setColWidth(const int n, const int w);
-
- /**
- * @see LayoutArray::setRowHeight
- */
- void setRowHeight(const int n, const int h);
-
- /**
- * @see LayoutArray::extend.
- */
- void extend(const int x, const int y,
- const int w, const int h);
-
- /**
- * Sets the minimum widths and heights of this cell and of all the
- * inner cells.
- */
- void computeSizes();
-
- void setType(int t)
- { mType = t; }
-
- int getWidth() const noexcept2 A_WARN_UNUSED
- { return mExtent[0]; }
-
- int getHeight() const noexcept2 A_WARN_UNUSED
- { return mExtent[1]; }
-
- void setWidth(const int w) noexcept2
- { mExtent[0] = w; }
-
- void setHeight(const int h) noexcept2
- { mExtent[1] = h; }
-
- enum
- {
- NONE = 0,
- WIDGET,
- ARRAY
- };
-
- static LayoutCell emptyCell;
-
- private:
- LayoutCell() :
- mWidget(nullptr),
- mHPadding(0),
- mVPadding(0),
- mType(NONE)
- {
- mExtent[0] = 0;
- mExtent[1] = 0;
- mAlign[0] = LEFT;
- mAlign[1] = LEFT;
- mNbFill[0] = 0;
- mNbFill[1] = 0;
- mSize[0] = 0;
- mSize[1] = 0;
- }
-
- // Copy not allowed, as the cell may own an array.
- explicit LayoutCell(LayoutCell const &);
- LayoutCell &operator=(LayoutCell const &);
-
- union
- {
- Widget *mWidget;
- LayoutArray *mArray;
- };
-
- /**
- * Returns the embedded array. Creates it if the cell does not contain
- * anything yet. Aborts if it contains a widget.
- */
- LayoutArray &getArray();
-
- /**
- * @see LayoutArray::reflow
- */
- void reflow(int nx, int ny, int nw, int nh);
-
- int mSize[2];
- int mHPadding;
- int mVPadding;
- int mExtent[2];
- Alignment mAlign[2];
- int mNbFill[2];
- int mType;
-};
-
-#endif // GUI_WIDGETS_LAYOUTCELL_H
diff --git a/src/gui/widgets/layouthelper.cpp b/src/gui/widgets/layouthelper.cpp
deleted file mode 100644
index 19114c1ae..000000000
--- a/src/gui/widgets/layouthelper.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/layouthelper.h"
-
-#include "gui/widgets/basiccontainer2.h"
-#include "gui/widgets/containerplacer.h"
-
-#include "debug.h"
-
-LayoutHelper::LayoutHelper(BasicContainer2 *const container) :
- WidgetListener(),
- mLayout(),
- mContainer(container)
-{
- if (mContainer != nullptr)
- mContainer->addWidgetListener(this);
-}
-
-LayoutHelper::~LayoutHelper()
-{
- if (mContainer != nullptr)
- mContainer->removeWidgetListener(this);
-}
-
-const Layout &LayoutHelper::getLayout() const
-{
- return mLayout;
-}
-
-LayoutCell &LayoutHelper::place(const int x, const int y,
- Widget *const wg,
- const int w, const int h)
-{
- if (mContainer != nullptr)
- mContainer->add(wg);
- return mLayout.place(wg, x, y, w, h);
-}
-
-ContainerPlacer LayoutHelper::getPlacer(const int x, const int y)
-{
- return ContainerPlacer(mContainer, &mLayout.at(x, y));
-}
-
-void LayoutHelper::reflowLayout(int w, int h)
-{
- mLayout.reflow(w, h);
- if (mContainer != nullptr)
- mContainer->setSize(w, h);
-}
-
-void LayoutHelper::widgetResized(const Event &event A_UNUSED)
-{
- if (mContainer == nullptr)
- return;
- const Rect area = mContainer->getChildrenArea();
- int w = area.width;
- int h = area.height;
- mLayout.reflow(w, h);
-}
diff --git a/src/gui/widgets/layouthelper.h b/src/gui/widgets/layouthelper.h
deleted file mode 100644
index 0f84e280c..000000000
--- a/src/gui/widgets/layouthelper.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_LAYOUTHELPER_H
-#define GUI_WIDGETS_LAYOUTHELPER_H
-
-#include "gui/widgets/layout.h"
-
-#include "listeners/widgetlistener.h"
-
-class BasicContainer2;
-class ContainerPlacer;
-
-/**
- * A helper class for adding a layout to a Guichan container widget. The layout
- * will register itself as a widget listener and relayout the widgets in the
- * container dynamically on resize.
- */
-class LayoutHelper final : public WidgetListener
-{
- public:
- /**
- * Constructor.
- */
- explicit LayoutHelper(BasicContainer2 *const container);
-
- A_DELETE_COPY(LayoutHelper)
-
- /**
- * Destructor.
- */
- ~LayoutHelper();
-
- /**
- * Gets the layout handler.
- */
- const Layout &getLayout() const A_WARN_UNUSED A_CONST;
-
- /**
- * Computes the position of the widgets according to the current
- * layout. Resizes the managed container so that the layout fits.
- *
- * @note This function is meant to be called with fixed-size
- * containers.
- *
- * @param w if non-zero, force the container to this width.
- * @param h if non-zero, force the container to this height.
- */
- void reflowLayout(int w = 0, int h = 0);
-
- /**
- * Adds a widget to the container and sets it at given cell.
- */
- LayoutCell &place(const int x, const int y, Widget *const wg,
- const int w = 1, const int h = 1);
-
- /**
- * Returns a proxy for adding widgets in an inner table of the layout.
- */
- ContainerPlacer getPlacer(const int x, const int y) A_WARN_UNUSED;
-
- /**
- * Called whenever the managed container changes size.
- */
- void widgetResized(const Event &event) override final;
-
- private:
- Layout mLayout; /**< Layout handler */
- BasicContainer2 *mContainer; /**< Managed container */
-};
-
-#endif // GUI_WIDGETS_LAYOUTHELPER_H
diff --git a/src/gui/widgets/linepart.cpp b/src/gui/widgets/linepart.cpp
deleted file mode 100644
index 2e1cab392..000000000
--- a/src/gui/widgets/linepart.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/linepart.h"
-
-#include "resources/image/image.h"
-
-#include "debug.h"
-
-LinePart::~LinePart()
-{
- if (mImage != nullptr)
- mImage->decRef();
- mImage = nullptr;
-}
diff --git a/src/gui/widgets/linepart.h b/src/gui/widgets/linepart.h
deleted file mode 100644
index d88a6543e..000000000
--- a/src/gui/widgets/linepart.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 Aethyra Development Team
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_LINEPART_H
-#define GUI_WIDGETS_LINEPART_H
-
-#include "gui/color.h"
-
-#include <string>
-
-#include "localconsts.h"
-
-class Image;
-
-class LinePart final
-{
- public:
- LinePart(const int x, const int y, const Color &color,
- const Color &color2, const std::string &text,
- const bool bold) :
- mX(x),
- mY(y),
- mColor(color),
- mColor2(color2),
- mText(text),
- mType(0),
- mImage(nullptr),
- mBold(bold)
- {
- }
-
- LinePart(const int x, const int y, const Color &color,
- const Color &color2, Image *const image) :
- mX(x),
- mY(y),
- mColor(color),
- mColor2(color2),
- mText(),
- mType(1),
- mImage(image),
- mBold(false)
- {
- }
-
- LinePart(const LinePart &l) :
- mX(l.mX),
- mY(l.mY),
- mColor(l.mColor),
- mColor2(l.mColor2),
- mText(l.mText),
- mType(l.mType),
- mImage(l.mImage),
- mBold(l.mBold)
- {
- }
-
- LinePart &operator=(const LinePart &l)
- {
- mX = l.mX;
- mY = l.mY;
- mColor = l.mColor;
- mColor2 = l.mColor2;
- mText = l.mText;
- mType = l.mType;
- mImage = l.mImage;
- mBold = l.mBold;
- return *this;
- }
-
- A_DEFAULT_COPY(LinePart)
-
- ~LinePart();
-
- int mX;
- int mY;
- Color mColor;
- Color mColor2;
- std::string mText;
- unsigned char mType;
- Image *mImage;
- bool mBold;
-};
-
-#endif // GUI_WIDGETS_LINEPART_H
diff --git a/src/gui/widgets/linkhandler.h b/src/gui/widgets/linkhandler.h
deleted file mode 100644
index 3b46e9fd3..000000000
--- a/src/gui/widgets/linkhandler.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_LINKHANDLER_H
-#define GUI_WIDGETS_LINKHANDLER_H
-
-#include <string>
-
-#include "listeners/mouselistener.h"
-
-/**
- * A simple interface to windows that need to handle links from BrowserBox
- * widget.
- */
-class LinkHandler notfinal
-{
- public:
- LinkHandler()
- { }
-
- A_DELETE_COPY(LinkHandler)
-
- virtual ~LinkHandler()
- { }
-
- virtual void handleLink(const std::string &link,
- MouseEvent *event) = 0;
-};
-
-#endif // GUI_WIDGETS_LINKHANDLER_H
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp
deleted file mode 100644
index 0bf590f6b..000000000
--- a/src/gui/widgets/listbox.cpp
+++ /dev/null
@@ -1,446 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/listbox.h"
-
-#include "settings.h"
-
-#include "gui/focushandler.h"
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/listmodel.h"
-
-#include "listeners/selectionlistener.h"
-
-#include "utils/foreach.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-float ListBox::mAlpha = 1.0;
-
-ListBox::ListBox(const Widget2 *const widget,
- ListModel *const listModel,
- const std::string &skin) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- mSelected(-1),
- mListModel(listModel),
- mWrappingEnabled(false),
- mSelectionListeners(),
- mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT)),
- mForegroundSelectedColor(getThemeColor(ThemeColorId::LISTBOX_SELECTED)),
- mForegroundSelectedColor2(getThemeColor(
- ThemeColorId::LISTBOX_SELECTED_OUTLINE)),
- mOldSelected(-1),
- mPadding(0),
- mPressedIndex(-2),
- mRowHeight(0),
- mItemPadding(1),
- mSkin(nullptr),
- mDistributeMousePressed(true),
- mCenterText(false)
-{
- setWidth(100);
- setFocusable(true);
- addMouseListener(this);
- addKeyListener(this);
-
- mForegroundColor = getThemeColor(ThemeColorId::LISTBOX);
- mForegroundColor2 = getThemeColor(ThemeColorId::LISTBOX_OUTLINE);
-
- if (theme != nullptr)
- mSkin = theme->load(skin, "listbox.xml");
-
- if (mSkin != nullptr)
- {
- mPadding = mSkin->getPadding();
- mItemPadding = mSkin->getOption("itemPadding");
- }
-
- const Font *const font = getFont();
- mRowHeight = CAST_U32(
- font->getHeight() + 2 * mItemPadding);
-}
-
-void ListBox::postInit()
-{
- adjustSize();
-}
-
-ListBox::~ListBox()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- if (theme != nullptr)
- theme->unload(mSkin);
-}
-
-void ListBox::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (mAlpha != alpha)
- mAlpha = alpha;
-}
-
-void ListBox::draw(Graphics *const graphics)
-{
- if (mListModel == nullptr)
- return;
-
- BLOCK_START("ListBox::draw")
- updateAlpha();
-
- mHighlightColor.a = CAST_U32(mAlpha * 255.0F);
- graphics->setColor(mHighlightColor);
- Font *const font = getFont();
- const int rowHeight = CAST_S32(getRowHeight());
- const int width = mDimension.width;
-
- if (mCenterText)
- {
- // Draw filled rectangle around the selected list element
- if (mSelected >= 0)
- {
- graphics->fillRectangle(Rect(mPadding,
- rowHeight * mSelected + mPadding,
- mDimension.width - 2 * mPadding, rowHeight));
-
- const std::string str = mListModel->getElementAt(mSelected);
- font->drawString(graphics,
- mForegroundSelectedColor,
- mForegroundSelectedColor2,
- str,
- (width - font->getWidth(str)) / 2,
- mSelected * rowHeight + mPadding + mItemPadding);
- }
- // Draw the list elements
- const int sz = mListModel->getNumberOfElements();
- for (int i = 0, y = mPadding + mItemPadding;
- i < sz; ++i, y += rowHeight)
- {
- if (i != mSelected)
- {
- const std::string str = mListModel->getElementAt(i);
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- str,
- (width - font->getWidth(str)) / 2, y);
- }
- }
- }
- else
- {
- // Draw filled rectangle around the selected list element
- if (mSelected >= 0)
- {
- graphics->fillRectangle(Rect(mPadding,
- rowHeight * mSelected + mPadding,
- mDimension.width - 2 * mPadding, rowHeight));
-
- const std::string str = mListModel->getElementAt(mSelected);
- font->drawString(graphics,
- mForegroundSelectedColor,
- mForegroundSelectedColor2,
- str,
- mPadding,
- mSelected * rowHeight + mPadding + mItemPadding);
- }
- // Draw the list elements
- const int sz = mListModel->getNumberOfElements();
- for (int i = 0, y = mPadding + mItemPadding; i < sz;
- ++i, y += rowHeight)
- {
- if (i != mSelected)
- {
- const std::string str = mListModel->getElementAt(i);
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- str,
- mPadding, y);
- }
- }
- }
- BLOCK_END("ListBox::draw")
-}
-
-void ListBox::keyPressed(KeyEvent &event)
-{
- const InputActionT action = event.getActionId();
- if (action == InputAction::GUI_SELECT)
- {
- distributeActionEvent();
- event.consume();
- }
- else if (action == InputAction::GUI_UP)
- {
- if (mSelected > 0)
- {
- setSelected(mSelected - 1);
- }
- else if (mSelected == 0 &&
- mWrappingEnabled &&
- getListModel() != nullptr)
- {
- setSelected(getListModel()->getNumberOfElements() - 1);
- }
- event.consume();
- }
- else if (action == InputAction::GUI_DOWN)
- {
- const int num = getListModel()->getNumberOfElements() - 1;
- if (mSelected < num)
- setSelected(mSelected + 1);
- else if (mSelected == num && mWrappingEnabled)
- setSelected(0);
- event.consume();
- }
- else if (action == InputAction::GUI_HOME)
- {
- setSelected(0);
- event.consume();
- }
- else if (action == InputAction::GUI_END && (getListModel() != nullptr))
- {
- setSelected(getListModel()->getNumberOfElements() - 1);
- event.consume();
- }
-}
-
-void ListBox::safeDraw(Graphics *const graphics)
-{
- ListBox::draw(graphics);
-}
-
-// Don't do anything on scrollwheel. ScrollArea will deal with that.
-
-void ListBox::mouseWheelMovedUp(MouseEvent &event A_UNUSED)
-{
-}
-
-void ListBox::mouseWheelMovedDown(MouseEvent &event A_UNUSED)
-{
-}
-
-void ListBox::mousePressed(MouseEvent &event)
-{
- mPressedIndex = getSelectionByMouse(event.getY());
- if (mMouseConsume && mPressedIndex != -1)
- event.consume();
-}
-
-void ListBox::mouseReleased(MouseEvent &event)
-{
- if (mPressedIndex != getSelectionByMouse(event.getY()))
- return;
-
- if (mDistributeMousePressed)
- {
- mouseReleased1(event);
- }
- else
- {
- switch (event.getClickCount())
- {
- case 1:
- mouseDragged(event);
- mOldSelected = mSelected;
- break;
- case 2:
- if (gui != nullptr)
- gui->resetClickCount();
- if (mOldSelected == mSelected)
- mouseReleased1(event);
- else
- mouseDragged(event);
- mOldSelected = mSelected;
- break;
- default:
- mouseDragged(event);
- mOldSelected = mSelected;
- break;
- }
- }
- mPressedIndex = -2;
-}
-
-void ListBox::mouseReleased1(const MouseEvent &event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- setSelected(std::max(0, getSelectionByMouse(event.getY())));
- distributeActionEvent();
- }
-}
-
-void ListBox::mouseDragged(MouseEvent &event)
-{
- if (event.getButton() != MouseButton::LEFT || getRowHeight() == 0)
- return;
-
- // Make list selection update on drag, but guard against negative y
- if (getRowHeight() != 0u)
- setSelected(std::max(0, getSelectionByMouse(event.getY())));
-}
-
-void ListBox::refocus()
-{
- if (mFocusHandler == nullptr)
- return;
-
- if (isFocusable())
- mFocusHandler->requestFocus(this);
-}
-
-void ListBox::adjustSize()
-{
- BLOCK_START("ListBox::adjustSize")
- if (mListModel != nullptr)
- {
- setHeight(CAST_S32(getRowHeight()) *
- mListModel->getNumberOfElements() + 2 * mPadding);
- }
- BLOCK_END("ListBox::adjustSize")
-}
-
-void ListBox::logic()
-{
- BLOCK_START("ListBox::logic")
- adjustSize();
- BLOCK_END("ListBox::logic")
-}
-
-int ListBox::getSelectionByMouse(const int y) const
-{
- if (y < mPadding)
- return -1;
- return (y - mPadding) / CAST_S32(getRowHeight());
-}
-
-void ListBox::setSelected(const int selected)
-{
- if (mListModel == nullptr)
- {
- mSelected = -1;
- }
- else
- {
- if (selected < 0)
- mSelected = -1;
- else if (selected >= mListModel->getNumberOfElements())
- mSelected = mListModel->getNumberOfElements() - 1;
- else
- mSelected = selected;
- }
-
- Rect scroll;
-
- if (mSelected < 0)
- scroll.y = 0;
- else
- scroll.y = CAST_S32(getRowHeight()) * mSelected;
-
- scroll.height = CAST_S32(getRowHeight());
- showPart(scroll);
-
- distributeValueChangedEvent();
-}
-
-void ListBox::setListModel(ListModel *const listModel)
-{
- mSelected = -1;
- mListModel = listModel;
- adjustSize();
-}
-
-void ListBox::addSelectionListener(SelectionListener *const selectionListener)
-{
- mSelectionListeners.push_back(selectionListener);
-}
-
-void ListBox::removeSelectionListener(SelectionListener *const
- selectionListener)
-{
- mSelectionListeners.remove(selectionListener);
-}
-
-void ListBox::distributeValueChangedEvent()
-{
- FOR_EACH (SelectionListenerIterator, iter, mSelectionListeners)
- {
- SelectionEvent event(this);
- (*iter)->valueChanged(event);
- }
-}
diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h
deleted file mode 100644
index 5c90058a8..000000000
--- a/src/gui/widgets/listbox.h
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_LISTBOX_H
-#define GUI_WIDGETS_LISTBOX_H
-
-#include "gui/widgets/widget.h"
-
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-
-#include "localconsts.h"
-
-class Skin;
-class KeyEvent;
-class ListModel;
-class MouseEvent;
-class SelectionListener;
-class Widget2;
-
-/**
- * A list box, meant to be used inside a scroll area. Same as the Guichan list
- * box except this one doesn't have a background, instead completely relying
- * on the scroll area. It also adds selection listener functionality.
- *
- * \ingroup GUI
- */
-class ListBox notfinal : public Widget,
- public MouseListener,
- public KeyListener
-{
- public:
- /**
- * Constructor.
- */
- ListBox(const Widget2 *const widget,
- ListModel *const listModel,
- const std::string &skin);
-
- A_DELETE_COPY(ListBox)
-
- virtual ~ListBox();
-
- void postInit() override;
-
- /**
- * Draws the list box.
- */
- void draw(Graphics *const graphics) override A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override A_NONNULL(2);
-
- /**
- * Update the alpha value to the graphic components.
- */
- void updateAlpha();
-
- // Inherited from KeyListener
-
- void keyPressed(KeyEvent& event) override final;
-
- // Inherited from MouseListener
-
- void mouseWheelMovedUp(MouseEvent& event) override final A_CONST;
-
- void mouseWheelMovedDown(MouseEvent& event) override final A_CONST;
-
- void mousePressed(MouseEvent &event) override;
-
- void mouseReleased(MouseEvent &event) override;
-
- void mouseReleased1(const MouseEvent &event);
-
- void mouseDragged(MouseEvent &event) override;
-
- void refocus();
-
- void setDistributeMousePressed(const bool b) noexcept2
- { mDistributeMousePressed = b; }
-
- virtual void adjustSize();
-
- void logic() override final;
-
- virtual int getSelectionByMouse(const int y) const;
-
- void setCenter(const bool b) noexcept2
- { mCenterText = b; }
-
- int getPressedIndex() const noexcept2 A_WARN_UNUSED
- { return mPressedIndex; }
-
- virtual unsigned int getRowHeight() const A_WARN_UNUSED
- { return mRowHeight; }
-
- void setRowHeight(unsigned int n) noexcept2
- { mRowHeight = n; }
-
- /**
- * Gets the selected item as an index in the list model.
- *
- * @return the selected item as an index in the list model.
- * @see setSelected
- */
- int getSelected() const noexcept2 A_WARN_UNUSED
- { return mSelected; }
-
- /**
- * Sets the selected item. The selected item is represented by
- * an index from the list model.
- *
- * @param selected the selected item as an index from the list model.
- * @see getSelected
- */
- void setSelected(const int selected);
-
- /**
- * Sets the list model to use.
- *
- * @param listModel the list model to use.
- * @see getListModel
- */
- void setListModel(ListModel *listModel);
-
- /**
- * Gets the list model used.
- *
- * @return the list model used.
- * @see setListModel
- */
- ListModel *getListModel() const noexcept2 A_WARN_UNUSED
- { return mListModel; }
-
- /**
- * Checks whether the list box wraps when selecting items with a
- * keyboard.
- *
- * Wrapping means that the selection of items will be wrapped. That is,
- * if the first item is selected and up is pressed, the last item will
- * get selected. If the last item is selected and down is pressed, the
- * first item will get selected.
- *
- * @return true if wrapping is enabled, fasle otherwise.
- * @see setWrappingEnabled
- */
- bool isWrappingEnabled() const noexcept2 A_WARN_UNUSED
- { return mWrappingEnabled; }
-
- /**
- * Sets the list box to wrap or not when selecting items with a
- * keyboard.
- *
- * Wrapping means that the selection of items will be wrapped. That is,
- * if the first item is selected and up is pressed, the last item will
- * get selected. If the last item is selected and down is pressed, the
- * first item will get selected.
- *
- * @see isWrappingEnabled
- */
- void setWrappingEnabled(const bool wrappingEnabled) noexcept2
- { mWrappingEnabled = wrappingEnabled; }
-
- /**
- * Adds a selection listener to the list box. When the selection
- * changes an event will be sent to all selection listeners of the
- * list box.
- *
- * If you delete your selection listener, be sure to also remove it
- * using removeSelectionListener().
- *
- * @param selectionListener The selection listener to add.
- */
- void addSelectionListener(SelectionListener *const selectionListener);
-
- /**
- * Removes a selection listener from the list box.
- *
- * @param selectionListener The selection listener to remove.
- */
- void removeSelectionListener(SelectionListener *const
- selectionListener);
-
- /**
- * Distributes a value changed event to all selection listeners
- * of the list box.
- */
- void distributeValueChangedEvent();
-
- protected:
- /**
- * The selected item as an index in the list model.
- */
- int mSelected;
-
- /**
- * The list model to use.
- */
- ListModel *mListModel;
-
- /**
- * True if wrapping is enabled, false otherwise.
- */
- bool mWrappingEnabled;
-
- /**
- * Typdef.
- */
- typedef std::list<SelectionListener*> SelectionListenerList;
-
- /**
- * The selection listeners of the list box.
- */
- SelectionListenerList mSelectionListeners;
-
- /**
- * Typedef.
- */
- typedef SelectionListenerList::iterator SelectionListenerIterator;
-
- Color mHighlightColor;
- Color mForegroundSelectedColor;
- Color mForegroundSelectedColor2;
- int mOldSelected;
- int mPadding;
- int mPressedIndex;
- unsigned int mRowHeight;
- int mItemPadding;
- Skin *mSkin;
- static float mAlpha;
- bool mDistributeMousePressed;
- bool mCenterText;
-};
-
-#endif // GUI_WIDGETS_LISTBOX_H
diff --git a/src/gui/widgets/passwordfield.cpp b/src/gui/widgets/passwordfield.cpp
deleted file mode 100644
index bc2ca4827..000000000
--- a/src/gui/widgets/passwordfield.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/passwordfield.h"
-
-#include "gui/skin.h"
-
-#include "debug.h"
-
-PasswordField::PasswordField(const Widget2 *const widget,
- const std::string &text) :
- TextField(widget, text),
- mPasswordChar(mSkin != nullptr ? CAST_8(
- mSkin->getOption("passwordChar", 42))
- : CAST_8(42))
-{
-}
-
-void PasswordField::draw(Graphics *const graphics)
-{
- BLOCK_START("PasswordField::draw")
- // std::string uses cow, thus cheap copy
- const std::string original = mText;
- if (mPasswordChar != 0)
- mText.assign(mText.length(), mPasswordChar);
- else
- mText.clear();
- TextField::draw(graphics);
- mText = original;
- BLOCK_END("PasswordField::draw")
-}
-
-void PasswordField::safeDraw(Graphics *const graphics)
-{
- PasswordField::draw(graphics);
-}
diff --git a/src/gui/widgets/passwordfield.h b/src/gui/widgets/passwordfield.h
deleted file mode 100644
index 93dded8d5..000000000
--- a/src/gui/widgets/passwordfield.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_PASSWORDFIELD_H
-#define GUI_WIDGETS_PASSWORDFIELD_H
-
-#include "gui/widgets/textfield.h"
-
-/**
- * A password field.
- *
- * \ingroup GUI
- */
-class PasswordField final : public TextField
-{
- public:
- /**
- * Constructor, initializes the password field with the given string.
- */
- explicit PasswordField(const Widget2 *const widget,
- const std::string &text = "");
-
- A_DELETE_COPY(PasswordField)
-
- /**
- * Draws the password field.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- protected:
- char mPasswordChar;
-};
-
-#endif // GUI_WIDGETS_PASSWORDFIELD_H
diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp
deleted file mode 100644
index b6217383f..000000000
--- a/src/gui/widgets/playerbox.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/playerbox.h"
-
-#include "settings.h"
-
-#include "being/being.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "render/graphics.h"
-
-#include "resources/image/image.h"
-
-#include "debug.h"
-
-PlayerBox::PlayerBox(Widget2 *const widget,
- Being *const being,
- const std::string &skin,
- const std::string &selectedSkin) :
- Widget(widget),
- MouseListener(),
- mBeing(being),
- mAlpha(1.0),
- mBackground(),
- mSelectedBackground(),
- mSkin(nullptr),
- mSelectedSkin(nullptr),
- mOffsetX(-mapTileSize / 2),
- mOffsetY(-mapTileSize),
- mDrawBackground(false),
- mSelected(false)
-{
- init(skin, selectedSkin);
-}
-
-PlayerBox::PlayerBox(Widget2 *const widget,
- const std::string &skin,
- const std::string &selectedSkin) :
- Widget(widget),
- MouseListener(),
- mBeing(nullptr),
- mAlpha(1.0),
- mBackground(),
- mSelectedBackground(),
- mSkin(nullptr),
- mSelectedSkin(nullptr),
- mOffsetX(-mapTileSize / 2),
- mOffsetY(-mapTileSize),
- mDrawBackground(false),
- mSelected(false)
-{
- init(skin, selectedSkin);
-}
-
-PlayerBox::~PlayerBox()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- Theme::unloadRect(mBackground);
- Theme::unloadRect(mSelectedBackground);
- mBeing = nullptr;
-}
-
-void PlayerBox::init(std::string name, std::string selectedName)
-{
- mAllowLogic = false;
- setFrameSize(2);
- addMouseListener(this);
-
- if (theme != nullptr)
- {
- if (name.empty())
- name = "playerbox.xml";
- mSkin = theme->loadSkinRect(mBackground,
- name, "playerbox_background.xml");
- if (mSkin != nullptr)
- {
- mDrawBackground = (mSkin->getOption("drawbackground") != 0);
- mOffsetX = mSkin->getOption("offsetX", -mapTileSize / 2);
- mOffsetY = mSkin->getOption("offsetY", -mapTileSize);
- mFrameSize = mSkin->getOption("frameSize", 2);
- }
- if (selectedName.empty())
- selectedName = "playerboxselected.xml";
- mSelectedSkin = theme->loadSkinRect(mSelectedBackground,
- selectedName, "playerbox_background.xml");
- }
- else
- {
- for (int f = 0; f < 9; f ++)
- mBackground.grid[f] = nullptr;
- for (int f = 0; f < 9; f ++)
- mSelectedBackground.grid[f] = nullptr;
- }
-}
-
-void PlayerBox::draw(Graphics *const graphics)
-{
- BLOCK_START("PlayerBox::draw")
- if (mBeing != nullptr)
- {
- const int bs = mFrameSize;
- const int x = mDimension.width / 2 + bs + mOffsetX;
- const int y = mDimension.height - bs + mOffsetY;
- mBeing->drawBasic(graphics, x, y);
- }
-
- if (settings.guiAlpha != mAlpha)
- {
- const float alpha = settings.guiAlpha;
- for (int a = 0; a < 9; a++)
- {
- if (mBackground.grid[a] != nullptr)
- mBackground.grid[a]->setAlpha(alpha);
- }
- }
- BLOCK_END("PlayerBox::draw")
-}
-
-void PlayerBox::safeDraw(Graphics *const graphics)
-{
- PlayerBox::draw(graphics);
-}
-
-void PlayerBox::drawFrame(Graphics *const graphics)
-{
- BLOCK_START("PlayerBox::drawFrame")
- if (mDrawBackground)
- {
- const int bs = mFrameSize * 2;
- const int w = mDimension.width + bs;
- const int h = mDimension.height + bs;
-
- if (!mSelected)
- graphics->drawImageRect(0, 0, w, h, mBackground);
- else
- graphics->drawImageRect(0, 0, w, h, mSelectedBackground);
- }
- BLOCK_END("PlayerBox::drawFrame")
-}
-
-void PlayerBox::safeDrawFrame(Graphics *const graphics)
-{
- BLOCK_START("PlayerBox::drawFrame")
- if (mDrawBackground)
- {
- const int bs = mFrameSize * 2;
- const int w = mDimension.width + bs;
- const int h = mDimension.height + bs;
-
- if (!mSelected)
- graphics->drawImageRect(0, 0, w, h, mBackground);
- else
- graphics->drawImageRect(0, 0, w, h, mSelectedBackground);
- }
- BLOCK_END("PlayerBox::drawFrame")
-}
-
-void PlayerBox::mouseReleased(MouseEvent& event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- if (!mActionEventId.empty())
- distributeActionEvent();
- event.consume();
- }
-}
diff --git a/src/gui/widgets/playerbox.h b/src/gui/widgets/playerbox.h
deleted file mode 100644
index b223f1dcb..000000000
--- a/src/gui/widgets/playerbox.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_PLAYERBOX_H
-#define GUI_WIDGETS_PLAYERBOX_H
-
-#include "gui/widgets/widget.h"
-
-#include "listeners/mouselistener.h"
-
-#include "resources/imagerect.h"
-
-#include "localconsts.h"
-
-class Being;
-class Skin;
-
-/**
- * A box showing a player character.
- *
- * \ingroup GUI
- */
-class PlayerBox final : public Widget,
- public MouseListener
-{
- public:
- /**
- * Constructor. Takes the initial player character that this box should
- * display, which defaults to <code>NULL</code>.
- */
- PlayerBox(Widget2 *const widget,
- Being *const being,
- const std::string &skin = "",
- const std::string &selectedSkin = "");
-
- explicit PlayerBox(Widget2 *const widget,
- const std::string &skin = "",
- const std::string &selectedSkin = "");
-
- A_DELETE_COPY(PlayerBox)
-
- /**
- * Destructor.
- */
- ~PlayerBox();
-
- void init(std::string name, std::string selectedName);
-
- /**
- * Sets a new player character to be displayed by this box. Setting the
- * player to <code>NULL</code> causes the box not to draw any
- * character.
- */
- void setPlayer(Being *being)
- { mBeing = being; }
-
- /**
- * Draws the scroll area.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Draws the background and border of the scroll area.
- */
- void drawFrame(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDrawFrame(Graphics *const graphics) override final
- A_NONNULL(2);
-
- Being *getBeing() A_WARN_UNUSED
- { return mBeing; }
-
- void setSelected(bool b)
- { mSelected = b; }
-
- void mouseReleased(MouseEvent& event) override final;
-
- private:
- Being *mBeing;
- float mAlpha;
- ImageRect mBackground;
- ImageRect mSelectedBackground;
- Skin *mSkin;
- Skin *mSelectedSkin;
- int mOffsetX;
- int mOffsetY;
- bool mDrawBackground;
- bool mSelected;
-};
-
-#endif // GUI_WIDGETS_PLAYERBOX_H
diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp
deleted file mode 100644
index 0f5c5a31a..000000000
--- a/src/gui/widgets/popup.cpp
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- * Copyright (C) 2009 Aethyra Development Team
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/popup.h"
-
-#include "gui/popupmanager.h"
-#include "gui/skin.h"
-
-#include "gui/widgets/windowcontainer.h"
-
-#include "utils/delete2.h"
-
-#include "render/graphics.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "debug.h"
-
-Popup::Popup(const std::string &name,
- std::string skin) :
- Container(nullptr),
- MouseListener(),
- WidgetListener(),
- mPadding(3),
- mSkin(nullptr),
- mPopupName(name),
- mVertexes(new ImageCollection),
- mMinWidth(100),
- mMinHeight(40),
- mMaxWidth(mainGraphics->mWidth),
- mMaxHeight(mainGraphics->mHeight),
- mInit(false)
-{
- logger->log("Popup::Popup(\"%s\")", name.c_str());
-
- mWindow = this;
-
- addWidgetListener(this);
-
- if (skin.empty())
- skin = "popup.xml";
-
- if (theme != nullptr)
- {
- mSkin = theme->load(skin, "popup.xml");
- if (mSkin != nullptr)
- {
- setPadding(mSkin->getPadding());
- setPalette(mSkin->getOption("palette"));
- }
- }
-
- if (windowContainer != nullptr)
- windowContainer->add(this);
-
- // Popups are invisible by default
- setVisible(Visible_false);
-}
-
-Popup::~Popup()
-{
- logger->log("Popup::~Popup(\"%s\")", mPopupName.c_str());
-
- delete2(mVertexes);
-
- if (mSkin != nullptr)
- {
- if (theme != nullptr)
- theme->unload(mSkin);
- mSkin = nullptr;
- }
-
- if (!mInit)
- {
- logger->log("error: Popup created without calling postInit(): "
- + mPopupName);
- }
-}
-
-void Popup::setWindowContainer(WindowContainer *const wc)
-{
- windowContainer = wc;
-}
-
-void Popup::draw(Graphics *const graphics)
-{
- BLOCK_START("Popup::draw")
-
- if (mSkin != nullptr)
- {
- if (mRedraw)
- {
- mRedraw = false;
- mVertexes->clear();
- graphics->calcWindow(mVertexes,
- 0, 0,
- mDimension.width, mDimension.height,
- mSkin->getBorder());
- }
- // need cache or remove calc call.
- graphics->finalize(mVertexes);
- graphics->drawTileCollection(mVertexes);
- }
-
- drawChildren(graphics);
- BLOCK_END("Popup::draw")
-}
-
-void Popup::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("Popup::safeDraw")
-
- if (mSkin != nullptr)
- {
- graphics->drawImageRect(0, 0,
- mDimension.width, mDimension.height,
- mSkin->getBorder());
- }
-
- safeDrawChildren(graphics);
- BLOCK_END("Popup::safeDraw")
-}
-
-Rect Popup::getChildrenArea()
-{
- const int pad2 = mPadding * 2;
- return Rect(mPadding, mPadding,
- mDimension.width - pad2, mDimension.height - pad2);
-}
-
-void Popup::setContentSize(int width, int height)
-{
- const int pad2 = mPadding * 2;
- width += pad2;
- height += pad2;
-
- if (mMinWidth > width)
- width = mMinWidth;
- else if (mMaxWidth < width)
- width = mMaxWidth;
- if (mMinHeight > height)
- height = mMinHeight;
- else if (mMaxHeight < height)
- height = mMaxHeight;
-
- setSize(width, height);
- mRedraw = true;
-}
-
-void Popup::setLocationRelativeTo(const Widget *const widget)
-{
- if (widget == nullptr)
- return;
-
- int wx, wy;
- int x, y;
-
- widget->getAbsolutePosition(wx, wy);
- getAbsolutePosition(x, y);
-
- setPosition(mDimension.x + (wx + (widget->getWidth()
- - mDimension.width) / 2 - x),
- mDimension.y + (wy + (widget->getHeight()
- - mDimension.height) / 2 - y));
- mRedraw = true;
-}
-
-void Popup::setMinWidth(const int width)
-{
- if (mSkin != nullptr)
- {
- mMinWidth = width > mSkin->getMinWidth()
- ? width : mSkin->getMinWidth();
- }
- else
- {
- mMinWidth = width;
- }
-}
-
-void Popup::setMinHeight(const int height)
-{
- if (mSkin != nullptr)
- {
- mMinHeight = height > mSkin->getMinHeight() ?
- height : mSkin->getMinHeight();
- }
- else
- {
- mMinHeight = height;
- }
-}
-
-void Popup::setMaxWidth(const int width)
-{
- mMaxWidth = width;
-}
-
-void Popup::setMaxHeight(const int height)
-{
- mMaxHeight = height;
-}
-
-void Popup::scheduleDelete()
-{
- windowContainer->scheduleDelete(this);
-}
-
-void Popup::position(const int x, const int y)
-{
- const int distance = 20;
-
- const int width = mDimension.width;
- const int height = mDimension.height;
- int posX = std::max(0, x - width / 2);
- int posY = y + distance;
-
- if (posX + width > mainGraphics->mWidth)
- posX = mainGraphics->mWidth - width;
- if (posY + height > mainGraphics->mHeight)
- posY = y - height - distance;
-
- setPosition(posX, posY);
- setVisible(Visible_true);
- requestMoveToTop();
- mRedraw = true;
-}
-
-void Popup::mouseMoved(MouseEvent &event A_UNUSED)
-{
- if (popupManager != nullptr)
- {
- PopupManager::hideBeingPopup();
- PopupManager::hideTextPopup();
- }
- mRedraw = true;
-}
-
-void Popup::hide()
-{
- setVisible(Visible_false);
- mRedraw = true;
-}
-
-void Popup::widgetResized(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void Popup::widgetMoved(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h
deleted file mode 100644
index 92fbaf78a..000000000
--- a/src/gui/widgets/popup.h
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- * Copyright (C) 2009 Aethyra Development Team
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_POPUP_H
-#define GUI_WIDGETS_POPUP_H
-
-#include "gui/widgets/container.h"
-
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-class ImageCollection;
-class Skin;
-class WindowContainer;
-
-/**
- * A light version of the Window class. Particularly suited for popup type
- * functionality that doesn't need to be resized or moved around by the mouse
- * once created, but only needs to display some simple content, like a static
- * message.
- *
- * Popups, in general, shouldn't also need to update their content once
- * created, although this is not an explicit requirement to use the popup
- * class.
- *
- * \ingroup GUI
- */
-class Popup notfinal : public Container,
- public MouseListener,
- public WidgetListener
-{
- public:
- /**
- * Constructor. Initializes the title to the given text and hooks
- * itself into the popup container.
- *
- * @param name A human readable name for the popup. Only useful for
- * debugging purposes.
- * @param skin The location where the Popup's skin XML can be found.
- */
- explicit Popup(const std::string &name = "",
- std::string skin = "");
-
- A_DELETE_COPY(Popup)
-
- /**
- * Destructor. Deletes all the added widgets.
- */
- virtual ~Popup();
-
- /**
- * Sets the window container to be used by new popups.
- */
- static void setWindowContainer(WindowContainer *const windowContainer);
-
- /**
- * Draws the popup.
- */
- void draw(Graphics *const graphics) override A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override A_NONNULL(2);
-
- /**
- * Sets the size of this popup.
- */
- void setContentSize(int width, int height);
-
- /**
- * Sets the location relative to the given widget.
- */
- void setLocationRelativeTo(const Widget *const widget);
-
- void mouseMoved(MouseEvent &event) override;
-
- /**
- * Sets the minimum width of the popup.
- */
- void setMinWidth(const int width);
-
- int getMinWidth() const noexcept2 A_WARN_UNUSED
- { return mMinWidth; }
-
- /**
- * Sets the minimum height of the popup.
- */
- void setMinHeight(const int height);
-
- int getMinHeight() const noexcept2 A_WARN_UNUSED
- { return mMinHeight; }
-
- /**
- * Sets the maximum width of the popup.
- */
- void setMaxWidth(const int width);
-
- int getMaxWidth() const noexcept2 A_WARN_UNUSED
- { return mMaxWidth; }
-
- /**
- * Sets the minimum height of the popup.
- */
- void setMaxHeight(const int height);
-
- int getMaxHeight() const noexcept2 A_WARN_UNUSED
- { return mMaxHeight; }
-
- /**
- * Gets the padding of the popup. The padding is the distance between
- * the popup border and the content.
- *
- * @return The padding of the popup.
- * @see setPadding
- */
- int getPadding() const noexcept2 A_WARN_UNUSED
- { return mPadding; }
-
- void setPadding(int padding) noexcept2
- { mPadding = padding; }
-
- /**
- * Sets the name of the popup. This is only useful for debug purposes.
- */
- void setPopupName(const std::string &name) noexcept2
- { mPopupName = name; }
-
- const std::string &getPopupName() const noexcept2
- { return mPopupName; }
-
- /**
- * Schedule this popup for deletion. It will be deleted at the start
- * of the next logic update.
- */
- void scheduleDelete();
-
- // Inherited from BasicContainer
-
- Rect getChildrenArea() override;
-
- /**
- * Sets the location to display the popup. Tries to horizontally center
- * the popup and provide a vertical buffer between the given point and
- * the popup. Prevents the popup from extending off-screen, if
- * possible.
- */
- void position(const int x, const int y);
-
- void hide();
-
- void widgetResized(const Event &event) override;
-
- void widgetMoved(const Event &event) override final;
-
- bool isPopupVisible() const noexcept2
- { return mVisible == Visible_true; }
-
- void postInit() override
- { mInit = true; }
-
- protected:
- int mPadding; /**< Holds the padding of the popup. */
- Skin *mSkin; /**< Skin in use by this popup */
-
- private:
- std::string mPopupName; /**< Name of the popup */
- ImageCollection *mVertexes A_NONNULLPOINTER;
- int mMinWidth; /**< Minimum popup width */
- int mMinHeight; /**< Minimum popup height */
- int mMaxWidth; /**< Maximum popup width */
- int mMaxHeight; /**< Maximum popup height */
- bool mInit;
-};
-
-#endif // GUI_WIDGETS_POPUP_H
diff --git a/src/gui/widgets/popuplist.cpp b/src/gui/widgets/popuplist.cpp
deleted file mode 100644
index 0260945ce..000000000
--- a/src/gui/widgets/popuplist.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/popuplist.h"
-
-#include "gui/gui.h"
-
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/extendedlistbox.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-PopupList::PopupList(DropDown *const widget,
- ListModel *const listModel,
- const bool extended,
- const Modal modal) :
- Popup("PopupList", "popuplist.xml"),
- FocusListener(),
- mListModel(listModel),
- mListBox(extended ? CREATEWIDGETR(ExtendedListBox,
- widget, listModel, "extendedlistbox.xml", 0) :
- CREATEWIDGETR(ListBox,
- widget, listModel, "popuplistbox.xml")),
- mScrollArea(new ScrollArea(this, mListBox, Opaque_false)),
- mDropDown(widget),
- mPressedIndex(-2),
- mModal(modal)
-{
- mListBox->setMouseConsume(false);
- mScrollArea->setMouseConsume(false);
- mAllowLogic = false;
- setFocusable(true);
-
- mListBox->setDistributeMousePressed(true);
- mScrollArea->setPosition(mPadding, mPadding);
-}
-
-void PopupList::postInit()
-{
- Popup::postInit();
- add(mScrollArea);
-
- if (gui != nullptr)
- gui->addGlobalFocusListener(this);
-
- addKeyListener(mDropDown);
- addMouseListener(this);
- adjustSize();
-}
-
-PopupList::~PopupList()
-{
- if (mParent != nullptr)
- mParent->removeFocusListener(this);
- if (gui != nullptr)
- gui->removeGlobalFocusListener(this);
- removeKeyListener(mDropDown);
-}
-
-void PopupList::show(int x, int y)
-{
- int len = mListBox->getHeight() + 8;
- if (len > 250)
- len = 250;
- setContentSize(mListBox->getWidth() + 8, len);
- const int width = mDimension.width;
- const int height = mDimension.height;
- if (mainGraphics->mWidth < (x + width + 5))
- x = mainGraphics->mWidth - width;
- if (mainGraphics->mHeight < (y + height + 5))
- y = mainGraphics->mHeight - height;
- setPosition(x, y);
- setVisible(Visible_true);
- requestMoveToTop();
- if (mModal == Modal_true)
- requestModalFocus();
-}
-
-void PopupList::widgetResized(const Event &event)
-{
- Popup::widgetResized(event);
- adjustSize();
-}
-
-void PopupList::setSelected(const int selected)
-{
- if (mListBox == nullptr)
- return;
-
- mListBox->setSelected(selected);
-}
-
-int PopupList::getSelected() const
-{
- if (mListBox == nullptr)
- return -1;
-
- return mListBox->getSelected();
-}
-
-void PopupList::setListModel(ListModel *const model)
-{
- if (mListBox != nullptr)
- mListBox->setListModel(model);
- mListModel = model;
-}
-
-void PopupList::adjustSize()
-{
- const int pad2 = 2 * mPadding;
- const int width = mDimension.width - pad2;
- mScrollArea->setWidth(width);
- mScrollArea->setHeight(mDimension.height - pad2);
- mListBox->adjustSize();
- mListBox->setWidth(width);
-}
-
-void PopupList::mousePressed(MouseEvent& event)
-{
- mPressedIndex = mListBox->getSelectionByMouse(
- event.getY() + mPadding);
- event.consume();
-}
-
-void PopupList::mouseReleased(MouseEvent& event)
-{
- if (mPressedIndex != mListBox->getSelectionByMouse(
- event.getY() + mPadding))
- {
- mPressedIndex = -2;
- return;
- }
-
- mPressedIndex = -2;
- if (event.getSource() == mScrollArea)
- return;
- if (mDropDown != nullptr)
- mDropDown->updateSelection();
- setVisible(Visible_false);
- if (mModal == Modal_true)
- releaseModalFocus();
-}
-
-void PopupList::focusGained(const Event& event)
-{
- const Widget *const source = event.getSource();
- if (mVisible == Visible_false ||
- source == this ||
- source == mListBox ||
- source == mScrollArea ||
- source == mDropDown)
- {
- return;
- }
-
- if (mDropDown != nullptr)
- mDropDown->updateSelection();
- setVisible(Visible_false);
- if (mModal == Modal_true)
- releaseModalFocus();
-}
-
-void PopupList::focusLost(const Event& event A_UNUSED)
-{
- if (mDropDown != nullptr)
- mDropDown->updateSelection();
-}
diff --git a/src/gui/widgets/popuplist.h b/src/gui/widgets/popuplist.h
deleted file mode 100644
index 02c38b4ed..000000000
--- a/src/gui/widgets/popuplist.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_POPUPLIST_H
-#define GUI_WIDGETS_POPUPLIST_H
-
-#include "enums/simpletypes/modal.h"
-
-#include "gui/widgets/popup.h"
-
-#include "listeners/focuslistener.h"
-
-#include "localconsts.h"
-
-class DropDown;
-class ListBox;
-class ListModel;
-class ScrollArea;
-
-class PopupList final : public Popup,
- public FocusListener
-{
- public:
- PopupList(DropDown *const widget,
- ListModel *const listModel,
- const bool extended,
- const Modal modal = Modal_false);
-
- ~PopupList();
-
- A_DELETE_COPY(PopupList)
-
- void postInit() override final;
-
- void show(int x, int y);
-
- void widgetResized(const Event &event) override final;
-
- void setSelected(const int selected);
-
- int getSelected() const;
-
- void setListModel(ListModel *const model);
-
- ListModel *getListModel() const
- { return mListModel; }
-
- void adjustSize();
-
- void focusGained(const Event& event A_UNUSED) override final;
-
- void focusLost(const Event& event A_UNUSED) override final;
-
- void mousePressed(MouseEvent& event) override final;
-
- void mouseReleased(MouseEvent& event) override final;
-
- private:
- ListModel *mListModel;
- ListBox *mListBox A_NONNULLPOINTER;
- ScrollArea *mScrollArea A_NONNULLPOINTER;
- DropDown *mDropDown;
- int mPressedIndex;
- Modal mModal;
-};
-
-#endif // GUI_WIDGETS_POPUPLIST_H
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp
deleted file mode 100644
index 7299140c6..000000000
--- a/src/gui/widgets/progressbar.cpp
+++ /dev/null
@@ -1,376 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/progressbar.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "utils/delete2.h"
-
-#include "render/graphics.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "debug.h"
-
-int ProgressBar::mInstances = 0;
-float ProgressBar::mAlpha = 1.0;
-
-ProgressBar::ProgressBar(const Widget2 *const widget,
- float progress,
- const int width,
- const int height,
- const ProgressColorIdT backColor,
- const std::string &skin,
- const std::string &skinFill) :
- Widget(widget),
- WidgetListener(),
- mFillRect(),
- mTextChunk(),
- mSkin(nullptr),
- mProgress(progress),
- mProgressToGo(progress),
- mBackgroundColorToGo(),
- mText(),
- mVertexes(new ImageCollection),
- mProgressPalette(backColor),
- mPadding(2),
- mFillPadding(3),
- mFillImage(false),
- mSmoothProgress(true),
- mSmoothColorChange(true),
- mTextChanged(true)
-{
- mBackgroundColor = Theme::getProgressColor(
- backColor >= ProgressColorId::PROG_HP
- ? backColor : ProgressColorId::PROG_HP,
- mProgress);
- mBackgroundColorToGo = mBackgroundColor;
- mForegroundColor2 = getThemeColor(ThemeColorId::PROGRESS_BAR_OUTLINE);
-
- // The progress value is directly set at load time:
- if (mProgress > 1.0F || mProgress < 0.0F)
- mProgress = 1.0F;
-
- mForegroundColor = getThemeColor(ThemeColorId::PROGRESS_BAR);
- addWidgetListener(this);
- setSize(width, height);
-
- if (theme != nullptr)
- {
- mSkin = theme->load(skin, "progressbar.xml");
- if (mSkin != nullptr)
- {
- setPadding(mSkin->getPadding());
- mFillPadding = mSkin->getOption("fillPadding");
- mFillImage = mSkin->getOption("fillImage") != 0;
- if (mFillImage)
- theme->loadRect(mFillRect, skinFill, "progressbar_fill.xml");
- }
- setHeight(2 * mPadding + getFont()->getHeight() + 2);
- }
-
- mInstances++;
-}
-
-ProgressBar::~ProgressBar()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- mInstances--;
- if (mSkin != nullptr)
- {
- if (theme != nullptr)
- theme->unload(mSkin);
- mSkin = nullptr;
- }
- Theme::unloadRect(mFillRect);
- delete2(mVertexes);
- mTextChunk.deleteImage();
-}
-
-void ProgressBar::logic()
-{
- BLOCK_START("ProgressBar::logic")
- if (mSmoothColorChange && mBackgroundColorToGo != mBackgroundColor)
- {
- // Smoothly changing the color for a nicer effect.
- if (mBackgroundColorToGo.r > mBackgroundColor.r)
- mBackgroundColor.r++;
- if (mBackgroundColorToGo.g > mBackgroundColor.g)
- mBackgroundColor.g++;
- if (mBackgroundColorToGo.b > mBackgroundColor.b)
- mBackgroundColor.b++;
- if (mBackgroundColorToGo.r < mBackgroundColor.r)
- mBackgroundColor.r--;
- if (mBackgroundColorToGo.g < mBackgroundColor.g)
- mBackgroundColor.g--;
- if (mBackgroundColorToGo.b < mBackgroundColor.b)
- mBackgroundColor.b--;
- mRedraw = true;
- }
-
- if (mSmoothProgress && mProgressToGo != mProgress)
- {
- // Smoothly showing the progressbar changes.
- if (mProgressToGo > mProgress)
- mProgress = std::min(1.0F, mProgress + 0.005F);
- if (mProgressToGo < mProgress)
- mProgress = std::max(0.0F, mProgress - 0.005F);
- mRedraw = true;
- }
- BLOCK_END("ProgressBar::logic")
-}
-
-void ProgressBar::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
- mAlpha = alpha;
-}
-
-void ProgressBar::draw(Graphics *const graphics)
-{
- BLOCK_START("ProgressBar::draw")
- if (mSkin == nullptr)
- {
- BLOCK_END("ProgressBar::draw")
- return;
- }
-
- updateAlpha();
- mBackgroundColor.a = CAST_U32(mAlpha * 255);
-
- if (mRedraw || graphics->getRedraw())
- {
- mRedraw = false;
- mVertexes->clear();
- graphics->calcWindow(mVertexes, 0, 0,
- mDimension.width, mDimension.height, mSkin->getBorder());
- if (mFillImage)
- {
- const unsigned int pad = 2 * mFillPadding;
- const int maxWidth = mDimension.width - pad;
- int width = CAST_S32(mProgress
- * static_cast<float>(maxWidth));
- if (width > 0)
- {
- if (width > maxWidth)
- width = maxWidth;
- graphics->calcWindow(mVertexes, mFillPadding, mFillPadding,
- width, mDimension.height - pad, mFillRect);
- }
- }
- graphics->finalize(mVertexes);
- }
-
- graphics->drawTileCollection(mVertexes);
-
- // The bar
- if (!mFillImage && mProgress > 0)
- {
- graphics->setColor(mBackgroundColor);
- const unsigned int pad = 2 * mFillPadding;
- const int maxWidth = mDimension.width - pad;
- int width = CAST_S32(mProgress * static_cast<float>(maxWidth));
- if (width > 0)
- {
- if (width > maxWidth)
- width = maxWidth;
- graphics->fillRectangle(Rect(mFillPadding, mFillPadding,
- width, mDimension.height - pad));
- }
- }
-
- // The label
- if (!mText.empty())
- {
- Font *const font = gui->getFont();
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mText;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- {
- const int textX = (mDimension.width - font->getWidth(mText)) / 2;
- const int textY = (mDimension.height - font->getHeight()) / 2;
- graphics->drawImage(image, textX, textY);
- }
- }
- BLOCK_END("ProgressBar::draw")
-}
-
-void ProgressBar::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("ProgressBar::safeDraw")
- if (mSkin == nullptr)
- {
- BLOCK_END("ProgressBar::safeDraw")
- return;
- }
-
- updateAlpha();
- mBackgroundColor.a = CAST_U32(mAlpha * 255);
-
- graphics->drawImageRect(0, 0, mDimension.width, mDimension.height,
- mSkin->getBorder());
- if (mFillImage)
- {
- const unsigned int pad = 2 * mFillPadding;
- const int maxWidth = mDimension.width - pad;
- int width = CAST_S32(mProgress
- * static_cast<float>(maxWidth));
- if (width > 0)
- {
- if (width > maxWidth)
- width = maxWidth;
- graphics->drawImageRect(mFillPadding, mFillPadding,
- width, mDimension.height - pad, mFillRect);
- }
- }
-
- // The bar
- if (!mFillImage && mProgress > 0)
- {
- graphics->setColor(mBackgroundColor);
- const unsigned int pad = 2 * mFillPadding;
- const int maxWidth = mDimension.width - pad;
- int width = CAST_S32(mProgress * static_cast<float>(maxWidth));
- if (width > 0)
- {
- if (width > maxWidth)
- width = maxWidth;
- graphics->fillRectangle(Rect(mFillPadding, mFillPadding,
- width, mDimension.height - pad));
- }
- }
-
- // The label
- if (!mText.empty())
- {
- Font *const font = gui->getFont();
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mText;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- {
- const int textX = (mDimension.width - font->getWidth(mText)) / 2;
- const int textY = (mDimension.height - font->getHeight()) / 2;
- graphics->drawImage(image, textX, textY);
- }
- }
- BLOCK_END("ProgressBar::safeDraw")
-}
-
-void ProgressBar::setProgress(const float progress)
-{
- const float p = std::min(1.0F, std::max(0.0F, progress));
- mProgressToGo = p;
- mRedraw = true;
-
- if (!mSmoothProgress)
- mProgress = p;
-
- if (mProgressPalette >= ProgressColorId::PROG_HP)
- {
- mBackgroundColorToGo = Theme::getProgressColor(
- mProgressPalette, progress);
- }
-}
-
-void ProgressBar::setProgressPalette(const ProgressColorIdT progressPalette)
-{
- const ProgressColorIdT oldPalette = mProgressPalette;
- mProgressPalette = progressPalette;
- mRedraw = true;
-
- if (mProgressPalette != oldPalette &&
- mProgressPalette >= ProgressColorId::PROG_HP)
- {
- mBackgroundColorToGo = Theme::getProgressColor(
- mProgressPalette, mProgressToGo);
- }
-}
-
-void ProgressBar::setBackgroundColor(const Color &color)
-{
- mRedraw = true;
- mBackgroundColorToGo = color;
-
- if (!mSmoothColorChange)
- mBackgroundColor = color;
-}
-
-void ProgressBar::setColor(const Color &color1, const Color &color2)
-{
- mForegroundColor = color1;
- mForegroundColor2 = color2;
- mTextChanged = true;
-}
-
-void ProgressBar::widgetResized(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void ProgressBar::widgetMoved(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void ProgressBar::setText(const std::string &str)
-{
- if (mText != str)
- {
- mText = str;
- mTextChanged = true;
- }
-}
-
-void ProgressBar::widgetHidden(const Event &event A_UNUSED)
-{
- mTextChanged = true;
- mTextChunk.deleteImage();
-}
diff --git a/src/gui/widgets/progressbar.h b/src/gui/widgets/progressbar.h
deleted file mode 100644
index 466f067b4..000000000
--- a/src/gui/widgets/progressbar.h
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_PROGRESSBAR_H
-#define GUI_WIDGETS_PROGRESSBAR_H
-
-#include "gui/fonts/textchunk.h"
-
-#include "gui/widgets/widget.h"
-
-#include "listeners/widgetlistener.h"
-
-#include "resources/imagerect.h"
-
-#include "localconsts.h"
-
-class ImageCollection;
-class Skin;
-
-/**
- * A progress bar.
- *
- * \ingroup GUI
- */
-class ProgressBar final : public Widget,
- public WidgetListener
-{
- public:
- /**
- * Constructor, initializes the progress with the given value.
- */
- ProgressBar(const Widget2 *const widget,
- float progress,
- const int width,
- const int height,
- const ProgressColorIdT backColor,
- const std::string &skin,
- const std::string &skinFill);
-
- A_DELETE_COPY(ProgressBar)
-
- ~ProgressBar();
-
- /**
- * Performs progress bar logic (fading colors)
- */
- void logic() override final;
-
- /**
- * Update the alpha value to the graphic components.
- */
- void updateAlpha();
-
- /**
- * Draws the progress bar.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Sets the current progress.
- */
- void setProgress(const float progress);
-
- /**
- * Returns the current progress.
- */
- float getProgress() const noexcept2 A_WARN_UNUSED
- { return mProgress; }
-
- /**
- * Change the ProgressPalette for this ProgressBar to follow or -1 to
- * disable this and manage color manually.
- */
- void setProgressPalette(const ProgressColorIdT progressPalette);
-
- /**
- * Change the color of the progress bar.
- */
- void setBackgroundColor(const Color &color);
-
- void setColor(const Color &color1, const Color &color2);
-
- /**
- * Returns the color of the progress bar.
- */
- const Color &getBackgroundColor() const noexcept2 A_WARN_UNUSED
- { return mBackgroundColor; }
-
- /**
- * Sets the text shown on the progress bar.
- */
- void setText(const std::string &str);
-
- /**
- * Returns the text shown on the progress bar.
- */
- const std::string &text() const noexcept2 A_WARN_UNUSED
- { return mText; }
-
- /**
- * Set whether the progress is moved smoothly.
- */
- void setSmoothProgress(bool smoothProgress) noexcept2
- { mSmoothProgress = smoothProgress; }
-
- /**
- * Set whether the color changing is made smoothly.
- */
- void setSmoothColorChange(bool smoothColorChange) noexcept2
- { mSmoothColorChange = smoothColorChange; }
-
- void widgetResized(const Event &event) override final;
-
- void widgetMoved(const Event &event) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void setPadding(unsigned int padding) noexcept2
- { mPadding = padding; }
-
- private:
- ImageRect mFillRect;
- TextChunk mTextChunk;
- Skin *mSkin;
- float mProgress;
- float mProgressToGo;
-
- Color mBackgroundColorToGo;
-
- std::string mText;
- ImageCollection *mVertexes A_NONNULLPOINTER;
- ProgressColorIdT mProgressPalette;
- unsigned int mPadding;
- unsigned int mFillPadding;
-
- static int mInstances;
- static float mAlpha;
-
- bool mFillImage;
- bool mSmoothProgress;
- bool mSmoothColorChange;
- bool mTextChanged;
-};
-
-#endif // GUI_WIDGETS_PROGRESSBAR_H
diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp
deleted file mode 100644
index abeee678c..000000000
--- a/src/gui/widgets/progressindicator.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/progressindicator.h"
-
-#include "gui/gui.h"
-
-#include "resources/imageset.h"
-
-#include "resources/animation/animation.h"
-#include "resources/animation/simpleanimation.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-ProgressIndicator::ProgressIndicator(const Widget2 *const widget) :
- Widget(widget),
- mIndicator(nullptr)
-{
- ImageSet *const images = Theme::getImageSetFromTheme(
- "progress-indicator.png", 32, 32);
-
- if (images != nullptr)
- {
- Animation *const anim = new Animation("progress indicator");
- for (ImageSet::size_type i = 0, fsz = images->size();
- i < fsz;
- ++i)
- {
- anim->addFrame(images->get(i), 100, 0, 0, 100);
- }
- mIndicator = new SimpleAnimation(anim);
- images->decRef();
- }
-
- setSize(32, 32);
-}
-
-ProgressIndicator::~ProgressIndicator()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- delete2(mIndicator);
-}
-
-void ProgressIndicator::logic()
-{
- BLOCK_START("ProgressIndicator::logic")
- if (mIndicator != nullptr)
- mIndicator->update(10);
- BLOCK_END("ProgressIndicator::logic")
-}
-
-void ProgressIndicator::draw(Graphics *const graphics)
-{
- BLOCK_START("ProgressIndicator::draw")
- if (mIndicator != nullptr)
- {
- // Draw the indicator centered on the widget
- const int x = (mDimension.width - 32) / 2;
- const int y = (mDimension.height - 32) / 2;
- mIndicator->draw(graphics, x, y);
- }
- BLOCK_END("ProgressIndicator::draw")
-}
-
-void ProgressIndicator::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("ProgressIndicator::draw")
- if (mIndicator != nullptr)
- {
- // Draw the indicator centered on the widget
- const int x = (mDimension.width - 32) / 2;
- const int y = (mDimension.height - 32) / 2;
- mIndicator->draw(graphics, x, y);
- }
- BLOCK_END("ProgressIndicator::draw")
-}
diff --git a/src/gui/widgets/progressindicator.h b/src/gui/widgets/progressindicator.h
deleted file mode 100644
index 6220a57c4..000000000
--- a/src/gui/widgets/progressindicator.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_PROGRESSINDICATOR_H
-#define GUI_WIDGETS_PROGRESSINDICATOR_H
-
-#include "gui/widgets/widget.h"
-
-#include "localconsts.h"
-
-class SimpleAnimation;
-
-/**
- * A widget that indicates progress. Suitable to use instead of a progress bar
- * in cases where it is unknown how long something is going to take.
- */
-class ProgressIndicator final : public Widget
-{
- public:
- explicit ProgressIndicator(const Widget2 *const widget);
-
- A_DELETE_COPY(ProgressIndicator)
-
- ~ProgressIndicator();
-
- void logic() override final;
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- private:
- SimpleAnimation *mIndicator;
-};
-
-#endif // GUI_WIDGETS_PROGRESSINDICATOR_H
diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp
deleted file mode 100644
index 71b7171ae..000000000
--- a/src/gui/widgets/radiobutton.cpp
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/radiobutton.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "render/graphics.h"
-
-#include "resources/imagerect.h"
-
-#include "resources/image/image.h"
-
-#include "debug.h"
-
-int RadioButton::instances = 0;
-Skin *RadioButton::mSkin = nullptr;
-float RadioButton::mAlpha = 1.0;
-
-RadioButton::GroupMap RadioButton::mGroupMap;
-
-RadioButton::RadioButton(const Widget2 *const widget,
- const std::string &restrict caption,
- const std::string &restrict group,
- const bool marked) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- WidgetListener(),
- mSelected(false),
- mCaption(),
- mGroup(),
- mTextChunk(),
- mPadding(0),
- mImagePadding(0),
- mImageSize(9),
- mSpacing(2),
- mTextX(0 + 9 + 2),
- mHasMouse(false),
- mTextChanged(true)
-{
- mAllowLogic = false;
- setCaption(caption);
- setGroup(group);
- setSelected(marked);
-
- setFocusable(true);
- addMouseListener(this);
- addKeyListener(this);
-
- mForegroundColor = getThemeColor(ThemeColorId::RADIOBUTTON);
- mForegroundColor2 = getThemeColor(ThemeColorId::RADIOBUTTON_OUTLINE);
- if (instances == 0)
- {
- if (theme != nullptr)
- {
- mSkin = theme->load("radio.xml", "");
- updateAlpha();
- }
- }
-
- instances++;
-
- if (mSkin != nullptr)
- {
- mPadding = mSkin->getPadding();
- mImagePadding = mSkin->getOption("imagePadding");
- mImageSize = mSkin->getOption("imageSize");
- mSpacing = mSkin->getOption("spacing");
- mTextX = mPadding + mImageSize + mSpacing;
- }
-
- adjustSize();
-}
-
-RadioButton::~RadioButton()
-{
- if (mWindow != nullptr)
- mWindow->removeWidgetListener(this);
-
- setGroup(std::string());
-
- if (gui != nullptr)
- gui->removeDragged(this);
-
- instances--;
-
- if (instances == 0)
- {
- if (theme != nullptr)
- theme->unload(mSkin);
- }
-}
-
-void RadioButton::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (mAlpha != alpha)
- {
- mAlpha = alpha;
- if (mSkin != nullptr)
- {
- const ImageRect &rect = mSkin->getBorder();
- for (int a = 0; a < 4; a ++)
- {
- Image *const image = rect.grid[a];
- if (image != nullptr)
- image->setAlpha(mAlpha);
- }
- }
- }
-}
-
-void RadioButton::drawBox(Graphics *const graphics)
-{
- if (mSkin == nullptr)
- return;
-
- const ImageRect &rect = mSkin->getBorder();
- int index = 0;
-
- if (mEnabled && mVisible == Visible_true)
- {
- if (mSelected)
- {
- if (mHasMouse)
- index = 1;
- else
- index = 0;
- }
- else
- {
- if (mHasMouse)
- index = 3;
- else
- index = 2;
- }
- }
- else
- {
- if (mSelected)
- index = 0;
- else
- index = 2;
- }
-
- const Image *const box = rect.grid[index];
-
- updateAlpha();
-
- if (box != nullptr)
- {
- graphics->drawImage(box,
- mImagePadding,
- (getHeight() - mImageSize) / 2);
- }
-}
-
-void RadioButton::draw(Graphics *const graphics)
-{
- BLOCK_START("RadioButton::draw")
- drawBox(graphics);
-
- Font *const font = getFont();
-
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mCaption;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, mTextX, mPadding);
-
- BLOCK_END("RadioButton::draw")
-}
-
-void RadioButton::safeDraw(Graphics *const graphics)
-{
- RadioButton::draw(graphics);
-}
-
-void RadioButton::mouseEntered(MouseEvent& event A_UNUSED)
-{
- mHasMouse = true;
-}
-
-void RadioButton::mouseExited(MouseEvent& event A_UNUSED)
-{
- mHasMouse = false;
-}
-
-void RadioButton::keyPressed(KeyEvent& event)
-{
- const InputActionT action = event.getActionId();
- if (action == InputAction::GUI_SELECT)
- {
- setSelected(true);
- distributeActionEvent();
- event.consume();
- }
-}
-
-void RadioButton::adjustSize()
-{
- Font *const font = getFont();
- setHeight(font->getHeight() + 2 * mPadding);
- setWidth(mImagePadding + mImageSize + mSpacing
- + font->getWidth(mCaption) + mPadding);
-}
-
-void RadioButton::setSelected(const bool selected)
-{
- if (selected && !mGroup.empty())
- {
- for (GroupIterator iter = mGroupMap.lower_bound(mGroup),
- iterEnd = mGroupMap.upper_bound(mGroup);
- iter != iterEnd;
- ++ iter)
- {
- if ((iter->second != nullptr) && iter->second->isSelected())
- iter->second->setSelected(false);
- }
- }
-
- mSelected = selected;
-}
-
-void RadioButton::mouseClicked(MouseEvent& event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- setSelected(true);
- event.consume();
- distributeActionEvent();
- }
-}
-
-void RadioButton::mouseDragged(MouseEvent& event)
-{
- event.consume();
-}
-
-void RadioButton::setGroup(const std::string &group)
-{
- if (!mGroup.empty())
- {
- for (GroupIterator iter = mGroupMap.lower_bound(mGroup),
- iterEnd = mGroupMap.upper_bound(mGroup);
- iter != iterEnd;
- ++ iter)
- {
- if (iter->second == this)
- {
- mGroupMap.erase(iter);
- break;
- }
- }
- }
-
- if (!group.empty())
- mGroupMap.insert(std::pair<std::string, RadioButton *>(group, this));
-
- mGroup = group;
-}
-
-void RadioButton::setCaption(const std::string& caption)
-{
- if (caption != mCaption)
- mTextChanged = true;
- mCaption = caption;
-}
-
-void RadioButton::setParent(Widget *widget)
-{
- if (mWindow != nullptr)
- mWindow->addWidgetListener(this);
- Widget::setParent(widget);
-}
-
-void RadioButton::widgetHidden(const Event &event A_UNUSED)
-{
- mTextChanged = true;
- mTextChunk.deleteImage();
-}
-
-void RadioButton::setWindow(Widget *const widget)
-{
- if ((widget == nullptr) && (mWindow != nullptr))
- {
- mWindow->removeWidgetListener(this);
- mWindow = nullptr;
- }
- else
- {
- Widget2::setWindow(widget);
- }
-}
diff --git a/src/gui/widgets/radiobutton.h b/src/gui/widgets/radiobutton.h
deleted file mode 100644
index 37bafab29..000000000
--- a/src/gui/widgets/radiobutton.h
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_RADIOBUTTON_H
-#define GUI_WIDGETS_RADIOBUTTON_H
-
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "gui/fonts/textchunk.h"
-
-#include "gui/widgets/widget.h"
-
-#include "localconsts.h"
-
-class Skin;
-
-/**
- * Guichan based RadioButton with custom look
- */
-class RadioButton final : public Widget,
- public MouseListener,
- public KeyListener,
- public WidgetListener
-
-{
- public:
- /**
- * Constructor.
- */
- RadioButton(const Widget2 *const widget,
- const std::string &restrict caption,
- const std::string &restrict group,
- const bool marked = false);
-
- A_DELETE_COPY(RadioButton)
-
- /**
- * Destructor.
- */
- ~RadioButton();
-
- /**
- * Draws the radiobutton, not the caption.
- */
- void drawBox(Graphics *const graphics) A_NONNULL(2);
-
- /**
- * Implementation of the draw methods.
- * Thus, avoiding the rhomb around the radio button.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Called when the mouse enteres the widget area.
- */
- void mouseEntered(MouseEvent& event) override final;
-
- /**
- * Called when the mouse leaves the widget area.
- */
- void mouseExited(MouseEvent& event) override final;
-
- void keyPressed(KeyEvent& event) override final;
-
- void updateAlpha();
-
- void adjustSize();
-
- /**
- * Checks if the radio button is selected.
- *
- * @return True if the radio button is selecte, false otherwise.
- * @see setSelected
- */
- bool isSelected() const
- { return mSelected; }
-
- /**
- * Sets the radio button to selected or not.
- *
- * @param selected True if the radio button should be selected,
- * false otherwise.
- * @see isSelected
- */
- void setSelected(const bool selected);
-
- /**
- * Gets the caption of the radio button.
- *
- * @return The caption of the radio button.
- * @see setCaption
- */
- const std::string &getCaption() const
- { return mCaption; }
-
- /**
- * Sets the caption of the radio button. It's advisable to call
- * adjustSize after setting of the caption to adjust the
- * radio button's size to fit the caption.
- *
- * @param caption The caption of the radio button.
- * @see getCaption, adjustSize
- */
- void setCaption(const std::string &caption);
-
- void mouseClicked(MouseEvent& event) override final;
-
- void mouseDragged(MouseEvent& event) override final;
-
- /**
- * Sets the group the radio button should belong to. Note that
- * a radio button group is unique per application, not per Gui object
- * as the group is stored in a static map.
- *
- * @param group The name of the group.
- * @see getGroup
- */
- void setGroup(const std::string &group);
-
- /**
- * Gets the group the radio button belongs to.
- *
- * @return The group the radio button belongs to.
- * @see setGroup
- */
- const std::string &getGroup() const
- { return mGroup; }
-
- void setParent(Widget *widget) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void setWindow(Widget *const widget) override final;
-
- private:
- static int instances;
- static Skin *mSkin;
- static float mAlpha;
-
- /**
- * True if the radio button is selected, false otherwise.
- */
- bool mSelected;
-
- /**
- * Holds the caption of the radio button.
- */
- std::string mCaption;
-
- /**
- * Holds the group of the radio button.
- */
- std::string mGroup;
-
- TextChunk mTextChunk;
-
- /**
- * Typdef.
- */
- typedef std::multimap<std::string, RadioButton *> GroupMap;
-
- /**
- * Typdef.
- */
- typedef GroupMap::iterator GroupIterator;
-
- /**
- * Holds all available radio button groups.
- */
- static GroupMap mGroupMap;
-
- int mPadding;
- int mImagePadding;
- int mImageSize;
- int mSpacing;
- int mTextX;
- bool mHasMouse;
- bool mTextChanged;
-};
-
-#endif // GUI_WIDGETS_RADIOBUTTON_H
diff --git a/src/gui/widgets/radiogroup.cpp b/src/gui/widgets/radiogroup.cpp
deleted file mode 100644
index 5e500c18f..000000000
--- a/src/gui/widgets/radiogroup.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/radiogroup.h"
-
-#include "gui/widgets/radiobutton.h"
-
-#include "debug.h"
-
-RadioGroup::RadioGroup(const Widget2 *const widget,
- const std::string &group, const int height,
- const int spacing) :
- WidgetGroup(widget, group, height, spacing)
-{
-}
-
-Widget *RadioGroup::createWidget(const std::string &text,
- const bool pressed A_UNUSED) const
-{
- RadioButton *const widget = new RadioButton(
- this, text, mGroup, mCount == 0);
- widget->adjustSize();
- return widget;
-}
diff --git a/src/gui/widgets/radiogroup.h b/src/gui/widgets/radiogroup.h
deleted file mode 100644
index 346efc754..000000000
--- a/src/gui/widgets/radiogroup.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_RADIOGROUP_H
-#define GUI_WIDGETS_RADIOGROUP_H
-
-#include "gui/widgets/widgetgroup.h"
-
-class RadioGroup final : public WidgetGroup
-{
- public:
- RadioGroup(const Widget2 *const widget,
- const std::string &group,
- const int height,
- const int spacing);
-
- A_DELETE_COPY(RadioGroup)
-
- Widget *createWidget(const std::string &name,
- const bool pressed)
- const override final A_WARN_UNUSED;
-};
-
-#endif // GUI_WIDGETS_RADIOGROUP_H
diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp
deleted file mode 100644
index e22ecdcf3..000000000
--- a/src/gui/widgets/scrollarea.cpp
+++ /dev/null
@@ -1,1460 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/scrollarea.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "utils/delete2.h"
-#include "utils/stringutils.h"
-
-#include "render/graphics.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "resources/imagerect.h"
-
-#include "resources/image/image.h"
-
-#include "debug.h"
-
-int ScrollArea::instances = 0;
-float ScrollArea::mAlpha = 1.0;
-bool ScrollArea::mShowButtons = true;
-int ScrollArea::mMarkerSize = 0;
-int ScrollArea::mScrollbarSize = 12;
-ImageRect ScrollArea::background;
-ImageRect ScrollArea::vMarker;
-ImageRect ScrollArea::vMarkerHi;
-ImageRect ScrollArea::vBackground;
-ImageRect ScrollArea::hBackground;
-Image *ScrollArea::buttons[4][2];
-
-static std::string const buttonFiles[2] =
-{
- "scrollbuttons.xml",
- "scrollbuttons_pressed.xml"
-};
-
-ScrollArea::ScrollArea(Widget2 *const widget2,
- Widget *const widget,
- const Opaque opaque,
- const std::string &skin) :
- BasicContainer(widget2),
- MouseListener(),
- WidgetListener(),
- mVertexes(new ImageCollection),
- mVertexes2(new ImageCollection),
- mHPolicy(SHOW_AUTO),
- mVPolicy(SHOW_AUTO),
- mVScroll(0),
- mHScroll(0),
- mScrollbarWidth(12),
- mUpButtonScrollAmount(10),
- mDownButtonScrollAmount(10),
- mLeftButtonScrollAmount(10),
- mRightButtonScrollAmount(10),
- mHorizontalMarkerDragOffset(0),
- mVerticalMarkerDragOffset(0),
- mX(0),
- mY(0),
- mClickX(0),
- mClickY(0),
- mXOffset(0),
- mYOffset(0),
- mDrawWidth(0),
- mDrawHeight(0),
- mVBarVisible(false),
- mHBarVisible(false),
- mUpButtonPressed(false),
- mDownButtonPressed(false),
- mLeftButtonPressed(false),
- mRightButtonPressed(false),
- mIsVerticalMarkerDragged(false),
- mIsHorizontalMarkerDragged(false),
- mOpaque(Opaque_true),
- mHasMouse(false)
-{
- setContent(widget);
- addMouseListener(this);
- mOpaque = opaque;
- init(skin);
-}
-
-ScrollArea::~ScrollArea()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- // Garbage collection
- delete getContent();
-
- instances--;
- if (instances == 0)
- {
- Theme::unloadRect(background);
- Theme::unloadRect(vMarker);
- Theme::unloadRect(vMarkerHi);
- Theme::unloadRect(vBackground);
- Theme::unloadRect(hBackground);
- for (int i = 0; i < 2; i ++)
- {
- for (int f = UP; f < BUTTONS_DIR; f ++)
- {
- if (buttons[f][i] != nullptr)
- buttons[f][i]->decRef();
- }
- }
- }
-
- delete2(mVertexes);
- delete2(mVertexes2);
-
- setContent(nullptr);
-}
-
-void ScrollArea::init(std::string skinName)
-{
- setOpaque(mOpaque);
-
- setUpButtonScrollAmount(2);
- setDownButtonScrollAmount(2);
- setLeftButtonScrollAmount(2);
- setRightButtonScrollAmount(2);
-
- if (instances == 0)
- {
- for (int f = 0; f < 9; f ++)
- {
- background.grid[f] = nullptr;
- vMarker.grid[f] = nullptr;
- vMarkerHi.grid[f] = nullptr;
- vBackground.grid[f] = nullptr;
- hBackground.grid[f] = nullptr;
- }
-
- // +++ here probably need move background from static
- if (skinName.empty())
- skinName = "scroll_background.xml";
- if (theme != nullptr)
- {
- theme->loadRect(background, skinName, "scroll_background.xml");
- theme->loadRect(vMarker, "scroll.xml", "");
- theme->loadRect(vMarkerHi, "scroll_highlighted.xml", "scroll.xml");
- theme->loadRect(vBackground, "scroll_vbackground.xml", "");
- theme->loadRect(hBackground, "scroll_hbackground.xml", "");
- }
-
- for (int i = 0; i < 2; i ++)
- {
- Skin *skin = nullptr;
- if (theme != nullptr)
- skin = theme->load(buttonFiles[i], "scrollbuttons.xml");
- if (skin != nullptr)
- {
- const ImageRect &rect = skin->getBorder();
- for (int f = UP; f < BUTTONS_DIR; f ++)
- {
- if (rect.grid[f] != nullptr)
- rect.grid[f]->incRef();
- buttons[f][i] = rect.grid[f];
- }
- if (i == 0)
- {
- mShowButtons = (skin->getOption("showbuttons", 1) == 1);
- mMarkerSize = skin->getOption("markersize", 0);
- mScrollbarSize = skin->getOption("scrollbarsize", 12);
- }
- }
- else
- {
- for (int f = UP; f < BUTTONS_DIR; f ++)
- buttons[f][i] = nullptr;
- }
- if (theme != nullptr)
- theme->unload(skin);
- }
- }
- mScrollbarWidth = mScrollbarSize;
- instances++;
-}
-
-void ScrollArea::logic()
-{
- BLOCK_START("ScrollArea::logic")
- if (!isVisible())
- {
- BLOCK_END("ScrollArea::logic")
- return;
- }
-
- checkPolicies();
-
- setVerticalScrollAmount(mVScroll);
- setHorizontalScrollAmount(mHScroll);
-
- Widget *const content = getContent();
- if (content != nullptr)
- {
- unsigned int frameSize = content->getFrameSize();
- content->setPosition(-mHScroll + frameSize, -mVScroll + frameSize);
- content->logic();
-
- // When no scrollbar in a certain direction,
- // adapt content size to match the content dimension exactly.
- frameSize = 2 * content->getFrameSize();
- if (mHPolicy == ScrollArea::SHOW_NEVER)
- {
- content->setWidth((mVBarVisible ? (mDimension.width
- - mScrollbarWidth) : mDimension.width) - frameSize);
- }
- if (mVPolicy == ScrollArea::SHOW_NEVER)
- {
- content->setHeight((mHBarVisible ? (mDimension.height
- - mScrollbarWidth) : mDimension.height) - frameSize);
- }
- }
-
- if (mUpButtonPressed)
- setVerticalScrollAmount(mVScroll - mUpButtonScrollAmount);
- else if (mDownButtonPressed)
- setVerticalScrollAmount(mVScroll + mDownButtonScrollAmount);
- else if (mLeftButtonPressed)
- setHorizontalScrollAmount(mHScroll - mLeftButtonScrollAmount);
- else if (mRightButtonPressed)
- setHorizontalScrollAmount(mHScroll + mRightButtonScrollAmount);
- BLOCK_END("ScrollArea::logic")
-}
-
-void ScrollArea::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (alpha != mAlpha)
- {
- mAlpha = alpha;
- for (int a = 0; a < 9; a++)
- {
- if (background.grid[a] != nullptr)
- background.grid[a]->setAlpha(mAlpha);
- if (hBackground.grid[a] != nullptr)
- hBackground.grid[a]->setAlpha(mAlpha);
- if (vBackground.grid[a] != nullptr)
- vBackground.grid[a]->setAlpha(mAlpha);
- if (vMarker.grid[a] != nullptr)
- vMarker.grid[a]->setAlpha(mAlpha);
- if (vMarkerHi.grid[a] != nullptr)
- vMarkerHi.grid[a]->setAlpha(mAlpha);
- }
- }
-}
-
-void ScrollArea::draw(Graphics *const graphics)
-{
- BLOCK_START("ScrollArea::draw")
- if (mVBarVisible || mHBarVisible)
- {
- if (mOpaque == Opaque_false)
- updateCalcFlag(graphics);
- // need add caching or remove calc calls.
-// if (mRedraw)
- {
- mVertexes->clear();
- if (mVBarVisible)
- {
- if (mShowButtons)
- {
- calcButton(graphics, UP);
- calcButton(graphics, DOWN);
- }
- calcVBar(graphics);
- calcVMarker(graphics);
- }
-
- if (mHBarVisible)
- {
- if (mShowButtons)
- {
- calcButton(graphics, LEFT);
- calcButton(graphics, RIGHT);
- }
- calcHBar(graphics);
- calcHMarker(graphics);
- }
- graphics->finalize(mVertexes);
- }
- graphics->drawTileCollection(mVertexes);
- }
-
- updateAlpha();
-
- if (mRedraw)
- {
- const bool redraw = graphics->getRedraw();
- graphics->setRedraw(true);
- drawChildren(graphics);
- graphics->setRedraw(redraw);
- }
- else
- {
- drawChildren(graphics);
- }
- mRedraw = false;
- BLOCK_END("ScrollArea::draw")
-}
-
-void ScrollArea::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("ScrollArea::draw")
- if (mVBarVisible)
- {
- if (mShowButtons)
- {
- drawButton(graphics, UP);
- drawButton(graphics, DOWN);
- }
- drawVBar(graphics);
- drawVMarker(graphics);
- }
-
- if (mHBarVisible)
- {
- if (mShowButtons)
- {
- drawButton(graphics, LEFT);
- drawButton(graphics, RIGHT);
- }
- drawHBar(graphics);
- drawHMarker(graphics);
- }
-
- updateAlpha();
-
- safeDrawChildren(graphics);
- mRedraw = false;
- BLOCK_END("ScrollArea::draw")
-}
-
-void ScrollArea::updateCalcFlag(const Graphics *const graphics)
-{
- if (!mRedraw)
- {
- // because we don't know where parent windows was moved,
- // need recalc vertexes
- const ClipRect &rect = graphics->getTopClip();
- if (rect.xOffset != mXOffset || rect.yOffset != mYOffset)
- {
- mRedraw = true;
- mXOffset = rect.xOffset;
- mYOffset = rect.yOffset;
- }
- else if (rect.width != mDrawWidth || rect.height != mDrawHeight)
- {
- mRedraw = true;
- mDrawWidth = rect.width;
- mDrawHeight = rect.height;
- }
- else if (graphics->getRedraw())
- {
- mRedraw = true;
- }
- }
-}
-
-void ScrollArea::drawFrame(Graphics *const graphics)
-{
- BLOCK_START("ScrollArea::drawFrame")
- if (mOpaque == Opaque_true)
- {
- const int bs = mFrameSize * 2;
- const int w = mDimension.width + bs;
- const int h = mDimension.height + bs;
-
- updateCalcFlag(graphics);
-
- if (mRedraw)
- {
- mVertexes2->clear();
- graphics->calcWindow(mVertexes2,
- 0, 0,
- w, h,
- background);
- graphics->finalize(mVertexes2);
- }
- graphics->drawTileCollection(mVertexes2);
- }
- BLOCK_END("ScrollArea::drawFrame")
-}
-
-void ScrollArea::safeDrawFrame(Graphics *const graphics)
-{
- BLOCK_START("ScrollArea::drawFrame")
- if (mOpaque == Opaque_true)
- {
- const int bs = mFrameSize * 2;
- const int w = mDimension.width + bs;
- const int h = mDimension.height + bs;
-
- updateCalcFlag(graphics);
- graphics->drawImageRect(0, 0,
- w, h,
- background);
- }
- BLOCK_END("ScrollArea::drawFrame")
-}
-
-void ScrollArea::setOpaque(Opaque opaque)
-{
- mOpaque = opaque;
- setFrameSize(mOpaque == Opaque_true ? 2 : 0);
-}
-
-Image *ScrollArea::getImageByState(Rect &dim, const BUTTON_DIR dir)
-{
- int state = 0;
-
- switch (dir)
- {
- case UP:
- state = mUpButtonPressed ? 1 : 0;
- dim = getUpButtonDimension();
- break;
- case DOWN:
- state = mDownButtonPressed ? 1 : 0;
- dim = getDownButtonDimension();
- break;
- case LEFT:
- state = mLeftButtonPressed ? 1 : 0;
- dim = getLeftButtonDimension();
- break;
- case RIGHT:
- state = mRightButtonPressed ? 1 : 0;
- dim = getRightButtonDimension();
- break;
- case BUTTONS_DIR:
- default:
- logger->log("ScrollArea::drawButton unknown dir: "
- + toString(CAST_U32(dir)));
- return nullptr;
- }
- return buttons[CAST_SIZE(dir)][state];
-}
-
-void ScrollArea::drawButton(Graphics *const graphics,
- const BUTTON_DIR dir)
-{
- Rect dim;
- const Image *const image = getImageByState(dim, dir);
-
- if (image != nullptr)
- graphics->drawImage(image, dim.x, dim.y);
-}
-
-void ScrollArea::calcButton(Graphics *const graphics,
- const BUTTON_DIR dir)
-{
- Rect dim;
- const Image *const image = getImageByState(dim, dir);
-
- if (image != nullptr)
- {
- static_cast<Graphics*>(graphics)->calcTileCollection(
- mVertexes, image, dim.x, dim.y);
- }
-}
-
-void ScrollArea::drawVBar(Graphics *const graphics) const
-{
- const Rect &dim = getVerticalBarDimension();
-
- if (vBackground.grid[4] != nullptr)
- {
- graphics->drawPattern(vBackground.grid[4],
- dim.x, dim.y, dim.width, dim.height);
- }
- if (vBackground.grid[1] != nullptr)
- {
- graphics->drawPattern(vBackground.grid[1],
- dim.x, dim.y,
- dim.width, vBackground.grid[1]->getHeight());
- }
- if (vBackground.grid[7] != nullptr)
- {
- graphics->drawPattern(vBackground.grid[7],
- dim.x, dim.height - vBackground.grid[7]->getHeight() + dim.y,
- dim.width, vBackground.grid[7]->getHeight());
- }
-}
-
-void ScrollArea::calcVBar(const Graphics *const graphics)
-{
- const Rect &dim = getVerticalBarDimension();
-
- if (vBackground.grid[4] != nullptr)
- {
- graphics->calcPattern(mVertexes,
- vBackground.grid[4],
- dim.x, dim.y,
- dim.width, dim.height);
- }
- if (vBackground.grid[1] != nullptr)
- {
- graphics->calcPattern(mVertexes,
- vBackground.grid[1],
- dim.x, dim.y,
- dim.width, vBackground.grid[1]->getHeight());
- }
- if (vBackground.grid[7] != nullptr)
- {
- graphics->calcPattern(mVertexes,
- vBackground.grid[7],
- dim.x, dim.height - vBackground.grid[7]->getHeight() + dim.y,
- dim.width, vBackground.grid[7]->getHeight());
- }
-}
-
-void ScrollArea::drawHBar(Graphics *const graphics) const
-{
- const Rect &dim = getHorizontalBarDimension();
-
- if (hBackground.grid[4] != nullptr)
- {
- graphics->drawPattern(hBackground.grid[4],
- dim.x, dim.y,
- dim.width, dim.height);
- }
-
- if (hBackground.grid[3] != nullptr)
- {
- graphics->drawPattern(hBackground.grid[3],
- dim.x, dim.y,
- hBackground.grid[3]->getWidth(), dim.height);
- }
-
- if (hBackground.grid[5] != nullptr)
- {
- graphics->drawPattern(hBackground.grid[5],
- dim.x + dim.width - hBackground.grid[5]->getWidth(),
- dim.y,
- hBackground.grid[5]->getWidth(),
- dim.height);
- }
-}
-
-void ScrollArea::calcHBar(const Graphics *const graphics)
-{
- const Rect &dim = getHorizontalBarDimension();
-
- if (hBackground.grid[4] != nullptr)
- {
- graphics->calcPattern(mVertexes,
- hBackground.grid[4],
- dim.x, dim.y,
- dim.width, dim.height);
- }
-
- if (hBackground.grid[3] != nullptr)
- {
- graphics->calcPattern(mVertexes,
- hBackground.grid[3],
- dim.x, dim.y,
- hBackground.grid[3]->getWidth(), dim.height);
- }
-
- if (hBackground.grid[5] != nullptr)
- {
- graphics->calcPattern(mVertexes,
- hBackground.grid[5],
- dim.x + dim.width - hBackground.grid[5]->getWidth(),
- dim.y,
- hBackground.grid[5]->getWidth(),
- dim.height);
- }
-}
-
-void ScrollArea::drawVMarker(Graphics *const graphics)
-{
- const Rect &dim = getVerticalMarkerDimension();
-
- if ((mHasMouse) && (mX > (mDimension.width - mScrollbarWidth)))
- {
- graphics->drawImageRect(dim.x, dim.y,
- dim.width, dim.height,
- vMarkerHi);
- }
- else
- {
- graphics->drawImageRect(dim.x, dim.y,
- dim.width, dim.height,
- vMarker);
- }
-}
-
-void ScrollArea::calcVMarker(Graphics *const graphics)
-{
- const Rect &dim = getVerticalMarkerDimension();
-
- if ((mHasMouse) && (mX > (mDimension.width - mScrollbarWidth)))
- {
- graphics->calcWindow(mVertexes,
- dim.x, dim.y,
- dim.width, dim.height,
- vMarkerHi);
- }
- else
- {
- graphics->calcWindow(mVertexes,
- dim.x, dim.y,
- dim.width, dim.height,
- vMarker);
- }
-}
-
-void ScrollArea::drawHMarker(Graphics *const graphics)
-{
- const Rect dim = getHorizontalMarkerDimension();
-
- if ((mHasMouse) && (mY > (mDimension.height - mScrollbarWidth)))
- {
- graphics->drawImageRect(dim.x, dim.y,
- dim.width, dim.height,
- vMarkerHi);
- }
- else
- {
- graphics->drawImageRect(
- dim.x, dim.y,
- dim.width, dim.height,
- vMarker);
- }
-}
-
-void ScrollArea::calcHMarker(Graphics *const graphics)
-{
- const Rect dim = getHorizontalMarkerDimension();
-
- if ((mHasMouse) && (mY > (mDimension.height - mScrollbarWidth)))
- {
- graphics->calcWindow(mVertexes,
- dim.x, dim.y,
- dim.width, dim.height,
- vMarkerHi);
- }
- else
- {
- graphics->calcWindow(mVertexes,
- dim.x, dim.y,
- dim.width, dim.height,
- vMarker);
- }
-}
-
-void ScrollArea::mouseMoved(MouseEvent& event)
-{
- mX = event.getX();
- mY = event.getY();
-}
-
-void ScrollArea::mouseEntered(MouseEvent& event A_UNUSED)
-{
- mHasMouse = true;
-}
-
-void ScrollArea::mouseExited(MouseEvent& event A_UNUSED)
-{
- mHasMouse = false;
-}
-
-void ScrollArea::widgetResized(const Event &event A_UNUSED)
-{
- mRedraw = true;
- const unsigned int frameSize = 2 * mFrameSize;
- Widget *const content = getContent();
- if (content != nullptr)
- {
- content->setSize(mDimension.width - frameSize,
- mDimension.height - frameSize);
- }
-}
-
-void ScrollArea::widgetMoved(const Event& event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void ScrollArea::mousePressed(MouseEvent& event)
-{
- const int x = event.getX();
- const int y = event.getY();
-
- if (getUpButtonDimension().isPointInRect(x, y))
- {
- 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))
- {
- mIsHorizontalMarkerDragged = false;
- mIsVerticalMarkerDragged = true;
-
- mVerticalMarkerDragOffset = y - getVerticalMarkerDimension().y;
- event.consume();
- }
- else if (getVerticalBarDimension().isPointInRect(x, y))
- {
- if (y < getVerticalMarkerDimension().y)
- {
- setVerticalScrollAmount(mVScroll
- - CAST_S32(getChildrenArea().height * 0.1));
- }
- else
- {
- setVerticalScrollAmount(mVScroll
- + CAST_S32(getChildrenArea().height * 0.1));
- }
- event.consume();
- }
- else if (getHorizontalMarkerDimension().isPointInRect(x, y))
- {
- mIsHorizontalMarkerDragged = true;
- mIsVerticalMarkerDragged = false;
- mHorizontalMarkerDragOffset = x - getHorizontalMarkerDimension().x;
- event.consume();
- }
- else if (getHorizontalBarDimension().isPointInRect(x, y))
- {
- if (x < getHorizontalMarkerDimension().x)
- {
- setHorizontalScrollAmount(mHScroll
- - CAST_S32(getChildrenArea().width * 0.1));
- }
- else
- {
- setHorizontalScrollAmount(mHScroll
- + CAST_S32(getChildrenArea().width * 0.1));
- }
- event.consume();
- }
-
- if (event.getButton() == MouseButton::LEFT &&
- !event.isConsumed())
- {
- mClickX = event.getX();
- mClickY = event.getY();
- }
-}
-
-void ScrollArea::mouseReleased(MouseEvent& event)
-{
- if (event.getButton() == MouseButton::LEFT &&
- mClickX != 0 &&
- mClickY != 0)
- {
- if (!event.isConsumed())
- {
-#ifdef ANDROID
- int dx = mClickX - event.getX();
- int dy = mClickY - event.getY();
-#else // ANDROID
-
- int dx = event.getX() - mClickX;
- int dy = event.getY() - mClickY;
-#endif // ANDROID
-
- if ((dx < 20 && dx > 0) || (dx > -20 && dx < 0))
- dx = 0;
-
- if ((dy < 20 && dy > 0) || (dy > -20 && dy < 0))
- dy = 0;
-
- if (abs(dx) > abs(dy))
- {
- int s = mHScroll + dx;
- if (s < 0)
- {
- s = 0;
- }
- else
- {
- const int maxH = getHorizontalMaxScroll();
- if (s > maxH)
- s = maxH;
- }
-
- setHorizontalScrollAmount(s);
- }
- else if (dy != 0)
- {
- int s = mVScroll + dy;
- if (s < 0)
- {
- s = 0;
- }
- else
- {
- const int maxV = getVerticalMaxScroll();
- if (s > maxV)
- s = maxV;
- }
-
- setVerticalScrollAmount(s);
- }
- mClickX = 0;
- mClickY = 0;
- if (mMouseConsume && ((dx != 0) || (dy != 0)))
- event.consume();
- }
- }
- mUpButtonPressed = false;
- mDownButtonPressed = false;
- mLeftButtonPressed = false;
- mRightButtonPressed = false;
- mIsHorizontalMarkerDragged = false;
- mIsVerticalMarkerDragged = false;
- if (mMouseConsume)
- event.consume();
- mRedraw = true;
-}
-
-void ScrollArea::mouseDragged(MouseEvent &event)
-{
- if (mIsVerticalMarkerDragged)
- {
- const Rect barDim = getVerticalBarDimension();
-
- const int pos = event.getY() - barDim.y
- - mVerticalMarkerDragOffset;
- const int length = getVerticalMarkerDimension().height;
-
- if ((barDim.height - length) > 0)
- {
- setVerticalScrollAmount((getVerticalMaxScroll() * pos)
- / (barDim.height - length));
- }
- else
- {
- setVerticalScrollAmount(0);
- }
- }
-
- if (mIsHorizontalMarkerDragged)
- {
- const Rect barDim = getHorizontalBarDimension();
-
- const int pos = event.getX() - barDim.x
- - mHorizontalMarkerDragOffset;
- const int length = getHorizontalMarkerDimension().width;
-
- if ((barDim.width - length) > 0)
- {
- setHorizontalScrollAmount((getHorizontalMaxScroll() * pos)
- / (barDim.width - length));
- }
- else
- {
- setHorizontalScrollAmount(0);
- }
- }
-
- event.consume();
- mRedraw = true;
-}
-
-Rect ScrollArea::getVerticalBarDimension() const
-{
- if (!mVBarVisible)
- return Rect(0, 0, 0, 0);
-
- const int height = mShowButtons ? mScrollbarWidth : 0;
- if (mHBarVisible)
- {
- return Rect(mDimension.width - mScrollbarWidth,
- height,
- mScrollbarWidth,
- mDimension.height - 2 * height - mScrollbarWidth);
- }
-
- return Rect(mDimension.width - mScrollbarWidth,
- height,
- mScrollbarWidth,
- mDimension.height - 2 * height);
-}
-
-Rect ScrollArea::getHorizontalBarDimension() const
-{
- if (!mHBarVisible)
- return Rect(0, 0, 0, 0);
-
- const int width = mShowButtons ? mScrollbarWidth : 0;
- if (mVBarVisible)
- {
- return Rect(width,
- mDimension.height - mScrollbarWidth,
- mDimension.width - 2 * width - mScrollbarWidth,
- mScrollbarWidth);
- }
-
- return Rect(width,
- mDimension.height - mScrollbarWidth,
- mDimension.width - 2 * width,
- mScrollbarWidth);
-}
-
-Rect ScrollArea::getVerticalMarkerDimension()
-{
- if (!mVBarVisible)
- return Rect(0, 0, 0, 0);
-
- int length, pos;
- int height;
- const int h2 = mShowButtons
- ? mScrollbarWidth : mMarkerSize / 2;
- const Widget *content;
- if (!mWidgets.empty())
- content = *mWidgets.begin();
- else
- content = nullptr;
-
- if (mHBarVisible)
- height = mDimension.height - 2 * h2 - mScrollbarWidth;
- else
- height = mDimension.height - 2 * h2;
-
- const int maxV = getVerticalMaxScroll();
- if ((mMarkerSize != 0) && (maxV != 0))
- {
- pos = (mVScroll * height / maxV - mMarkerSize / 2);
- length = mMarkerSize;
- }
- else
- {
- if (content != nullptr)
- {
- const int h3 = content->getHeight();
- if (h3 != 0)
- length = (height * getChildrenArea().height) / h3;
- else
- length = height;
- }
- else
- {
- length = height;
- }
-
- if (length < mScrollbarWidth)
- length = mScrollbarWidth;
-
- if (length > height)
- length = height;
-
- const int maxScroll = getVerticalMaxScroll();
- if (maxScroll != 0)
- pos = ((height - length) * mVScroll) / maxScroll;
- else
- pos = 0;
- }
-
- return Rect(mDimension.width - mScrollbarWidth, h2 + pos,
- mScrollbarWidth, length);
-}
-
-Rect ScrollArea::getHorizontalMarkerDimension()
-{
- if (!mHBarVisible)
- return Rect(0, 0, 0, 0);
-
- int length, pos;
- int width;
- const int w2 = mShowButtons
- ? mScrollbarWidth : mMarkerSize / 2;
- const Widget *content;
- if (!mWidgets.empty())
- content = *mWidgets.begin();
- else
- content = nullptr;
-
- if (mVBarVisible)
- width = mDimension.width - 2 * w2 - mScrollbarWidth;
- else
- width = mDimension.width - w2 - mScrollbarWidth;
-
- const int maxH = getHorizontalMaxScroll();
- if ((mMarkerSize != 0) && (maxH != 0))
- {
- pos = (mHScroll * width / maxH - mMarkerSize / 2);
- length = mMarkerSize;
- }
- else
- {
- if (content != nullptr)
- {
- const int w3 = content->getWidth();
- if (w3 != 0)
- length = (width * getChildrenArea().width) / w3;
- else
- length = width;
- }
- else
- {
- length = width;
- }
-
- if (length < mScrollbarWidth)
- length = mScrollbarWidth;
-
- if (length > width)
- length = width;
-
- if (getHorizontalMaxScroll() != 0)
- {
- pos = ((width - length) * mHScroll)
- / getHorizontalMaxScroll();
- }
- else
- {
- pos = 0;
- }
- }
-
- return Rect(w2 + pos, mDimension.height - mScrollbarWidth,
- length, mScrollbarWidth);
-}
-
-Rect ScrollArea::getUpButtonDimension() const
-{
- if (!mVBarVisible || !mShowButtons)
- return Rect(0, 0, 0, 0);
-
- return Rect(mDimension.width - mScrollbarWidth, 0,
- mScrollbarWidth, mScrollbarWidth);
-}
-
-Rect ScrollArea::getDownButtonDimension() const
-{
- if (!mVBarVisible || !mShowButtons)
- return Rect(0, 0, 0, 0);
-
- if (mHBarVisible)
- {
- return Rect(mDimension.width - mScrollbarWidth,
- mDimension.height - mScrollbarWidth * 2,
- mScrollbarWidth,
- mScrollbarWidth);
- }
-
- return Rect(mDimension.width - mScrollbarWidth,
- mDimension.height - mScrollbarWidth,
- mScrollbarWidth,
- mScrollbarWidth);
-}
-
-Rect ScrollArea::getLeftButtonDimension() const
-{
- if (!mHBarVisible || !mShowButtons)
- return Rect(0, 0, 0, 0);
-
- return Rect(0, mDimension.height - mScrollbarWidth,
- mScrollbarWidth, mScrollbarWidth);
-}
-
-Rect ScrollArea::getRightButtonDimension() const
-{
- if (!mHBarVisible || !mShowButtons)
- return Rect(0, 0, 0, 0);
-
- if (mVBarVisible)
- {
- return Rect(mDimension.width - mScrollbarWidth*2,
- mDimension.height - mScrollbarWidth,
- mScrollbarWidth,
- mScrollbarWidth);
- }
-
- return Rect(mDimension.width - mScrollbarWidth,
- mDimension.height - mScrollbarWidth,
- mScrollbarWidth,
- mScrollbarWidth);
-}
-
-void ScrollArea::setContent(Widget* widget)
-{
- if (widget != nullptr)
- {
- clear();
- add(widget);
- widget->setPosition(0, 0);
- }
- else
- {
- clear();
- }
-
- checkPolicies();
-}
-
-Widget* ScrollArea::getContent()
-{
- if (!mWidgets.empty())
- return *mWidgets.begin();
-
- return nullptr;
-}
-
-void ScrollArea::setHorizontalScrollPolicy(const ScrollPolicy hPolicy)
-{
- mHPolicy = hPolicy;
- checkPolicies();
-}
-
-void ScrollArea::setVerticalScrollPolicy(const ScrollPolicy vPolicy)
-{
- mVPolicy = vPolicy;
- checkPolicies();
-}
-
-void ScrollArea::setScrollPolicy(const ScrollPolicy hPolicy,
- const ScrollPolicy vPolicy)
-{
- mHPolicy = hPolicy;
- mVPolicy = vPolicy;
- checkPolicies();
-}
-
-void ScrollArea::setVerticalScrollAmount(const int vScroll)
-{
- const int max = getVerticalMaxScroll();
-
- mVScroll = vScroll;
-
- if (vScroll > max)
- mVScroll = max;
-
- if (vScroll < 0)
- mVScroll = 0;
-}
-
-void ScrollArea::setHorizontalScrollAmount(int hScroll)
-{
- const int max = getHorizontalMaxScroll();
-
- mHScroll = hScroll;
-
- if (hScroll > max)
- mHScroll = max;
- else if (hScroll < 0)
- mHScroll = 0;
-}
-
-void ScrollArea::setScrollAmount(const int hScroll, const int vScroll)
-{
- setHorizontalScrollAmount(hScroll);
- setVerticalScrollAmount(vScroll);
-}
-
-int ScrollArea::getHorizontalMaxScroll()
-{
- checkPolicies();
-
- const Widget *const content = getContent();
- if (content == nullptr)
- return 0;
-
- const int value = content->getWidth() - getChildrenArea().width +
- 2 * content->getFrameSize();
-
- if (value < 0)
- return 0;
-
- return value;
-}
-
-int ScrollArea::getVerticalMaxScroll()
-{
- checkPolicies();
-
- const Widget *const content = getContent();
- if (content == nullptr)
- return 0;
-
- int value;
-
- value = content->getHeight() - getChildrenArea().height +
- 2 * content->getFrameSize();
-
- if (value < 0)
- return 0;
-
- return value;
-}
-
-void ScrollArea::setScrollbarWidth(const int width)
-{
- if (width > 0)
- mScrollbarWidth = width;
-}
-
-void ScrollArea::showWidgetPart(Widget *const widget, const Rect &area)
-{
- const Widget *const content = getContent();
- if (widget != content || (content == nullptr))
- return;
-
- BasicContainer::showWidgetPart(widget, area);
-
- setHorizontalScrollAmount(content->getFrameSize()
- - content->getX());
- setVerticalScrollAmount(content->getFrameSize()
- - content->getY());
-}
-
-Rect ScrollArea::getChildrenArea()
-{
- const Rect area = Rect(0, 0,
- mVBarVisible ? (getWidth() - mScrollbarWidth) : getWidth(),
- mHBarVisible ? (getHeight() - mScrollbarWidth) : getHeight());
-
- if (area.width < 0 || area.height < 0)
- return Rect();
-
- return area;
-}
-
-Widget *ScrollArea::getWidgetAt(int x, int y)
-{
- if (getChildrenArea().isPointInRect(x, y))
- return getContent();
-
- return nullptr;
-}
-
-void ScrollArea::setWidth(int width)
-{
- Widget::setWidth(width);
- checkPolicies();
-}
-
-void ScrollArea::setHeight(int height)
-{
- Widget::setHeight(height);
- checkPolicies();
-}
-
-void ScrollArea::setDimension(const Rect& dimension)
-{
- Widget::setDimension(dimension);
- checkPolicies();
-}
-
-void ScrollArea::mouseWheelMovedUp(MouseEvent& event)
-{
- if (event.isConsumed())
- return;
-
- setVerticalScrollAmount(mVScroll
- - getChildrenArea().height / 8);
-
- event.consume();
-}
-
-void ScrollArea::mouseWheelMovedDown(MouseEvent& event)
-{
- if (event.isConsumed())
- return;
-
- setVerticalScrollAmount(mVScroll
- + getChildrenArea().height / 8);
-
- event.consume();
-}
-
-void ScrollArea::checkPolicies()
-{
- const int w = getWidth();
- const int h = getHeight();
-
- mHBarVisible = false;
- mVBarVisible = false;
-
- const Widget *const content = getContent();
- if (content == nullptr)
- {
- mHBarVisible = (mHPolicy == SHOW_ALWAYS);
- mVBarVisible = (mVPolicy == SHOW_ALWAYS);
- return;
- }
-
- if (mHPolicy == SHOW_AUTO &&
- mVPolicy == SHOW_AUTO)
- {
- if (content->getWidth() <= w
- && content->getHeight() <= h)
- {
- mHBarVisible = false;
- mVBarVisible = false;
- }
-
- if (content->getWidth() > w)
- {
- mHBarVisible = true;
- }
-
- if ((content->getHeight() > h)
- || (mHBarVisible && content->getHeight()
- > h - mScrollbarWidth))
- {
- mVBarVisible = true;
- }
-
- if (mVBarVisible && content->getWidth() > w - mScrollbarWidth)
- mHBarVisible = true;
-
- return;
- }
-
- switch (mHPolicy)
- {
- case SHOW_NEVER:
- mHBarVisible = false;
- break;
-
- case SHOW_ALWAYS:
- mHBarVisible = true;
- break;
-
- case SHOW_AUTO:
- if (mVPolicy == SHOW_NEVER)
- {
- mHBarVisible = (content->getWidth() > w);
- }
- else // (mVPolicy == SHOW_ALWAYS)
- {
- mHBarVisible = (content->getWidth()
- > w - mScrollbarWidth);
- }
- break;
-
- default:
- break;
- }
-
- switch (mVPolicy)
- {
- case SHOW_NEVER:
- mVBarVisible = false;
- break;
-
- case SHOW_ALWAYS:
- mVBarVisible = true;
- break;
-
- case SHOW_AUTO:
- if (mHPolicy == SHOW_NEVER)
- {
- mVBarVisible = (content->getHeight() > h);
- }
- else // (mHPolicy == SHOW_ALWAYS)
- {
- mVBarVisible = (content->getHeight()
- > h - mScrollbarWidth);
- }
- break;
- default:
- break;
- }
-}
-
-bool ScrollArea::isSelectable() const noexcept2
-{
- if (mVBarVisible || mHBarVisible)
- return true;
- return Widget::isSelectable();
-}
diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h
deleted file mode 100644
index 50b194d28..000000000
--- a/src/gui/widgets/scrollarea.h
+++ /dev/null
@@ -1,598 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_SCROLLAREA_H
-#define GUI_WIDGETS_SCROLLAREA_H
-
-#include "gui/widgets/basiccontainer.h"
-
-#include "enums/simpletypes/opaque.h"
-
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-class Image;
-class ImageCollection;
-
-/**
- * A scroll area.
- *
- * Contrary to Guichan's scroll area, this scroll area takes ownership over its
- * content. However, it won't delete a previously set content widget when
- * setContent is called!
- *
- * \ingroup GUI
- */
-class ScrollArea final : public BasicContainer,
- public MouseListener,
- public WidgetListener
-{
- public:
- /**
- * Scrollpolicies for the horizontal and vertical scrollbar.
- * The policies are:
- *
- * SHOW_ALWAYS - Always show the scrollbars no matter what.
- * SHOW_NEVER - Never show the scrollbars no matter waht.
- * SHOW_AUTO - Show the scrollbars only when needed. That is if the
- * content grows larger then the ScrollArea.
- */
- enum ScrollPolicy
- {
- SHOW_ALWAYS = 0,
- SHOW_NEVER,
- SHOW_AUTO
- };
-
- ScrollArea(Widget2 *const widget2,
- Widget *const widget,
- const Opaque opaque = Opaque_true,
- const std::string &skin = "");
-
- A_DELETE_COPY(ScrollArea)
-
- /**
- * Destructor. Also deletes the content.
- */
- ~ScrollArea();
-
- /**
- * Logic function optionally adapts width or height of contents. This
- * depends on the scrollbar settings.
- */
- void logic() override final;
-
- /**
- * Update the alpha value to the graphic components.
- */
- void updateAlpha();
-
- /**
- * Draws the scroll area.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Draws the background and border of the scroll area.
- */
- void drawFrame(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDrawFrame(Graphics *const graphics) override final
- A_NONNULL(2);
-
- /**
- * Sets whether the widget should draw its background or not.
- */
- void setOpaque(Opaque opaque);
-
- /**
- * Returns whether the widget draws its background or not.
- */
- bool isOpaque() const noexcept2 A_WARN_UNUSED
- { return mOpaque == Opaque_true; }
-
- /**
- * Called when the mouse moves in the widget area.
- */
- void mouseMoved(MouseEvent& event) override final;
-
- /**
- * Called when the mouse enteres the widget area.
- */
- void mouseEntered(MouseEvent& event) override final;
-
- /**
- * Called when the mouse leaves the widget area.
- */
- void mouseExited(MouseEvent& event) override final;
-
- void mousePressed(MouseEvent& event) override final;
-
- void mouseReleased(MouseEvent& event) override final;
-
- void mouseDragged(MouseEvent &event) override final;
-
- void widgetResized(const Event &event) override final;
-
- void widgetMoved(const Event &event) override final;
-
- Rect getVerticalBarDimension() const;
-
- Rect getHorizontalBarDimension() const;
-
- Rect getVerticalMarkerDimension();
-
- Rect getHorizontalMarkerDimension();
-
- Rect getUpButtonDimension() const;
-
- Rect getDownButtonDimension() const;
-
- Rect getLeftButtonDimension() const;
-
- Rect getRightButtonDimension() const;
-
- /**
- * Sets the content.
- *
- * @param widget The content of the scroll area.
- */
- void setContent(Widget* widget);
-
- /**
- * Gets the content.
- *
- * @return The content of the scroll area.
- */
- Widget* getContent();
-
- /**
- * Sets the horizontal scrollbar policy. See enum with policies.
- *
- * @param hPolicy The policy for the horizontal scrollbar.
- * @see getHorizontalScrollPolicy
- */
- void setHorizontalScrollPolicy(const ScrollPolicy hPolicy);
-
- /**
- * Gets the horizontal scrollbar policy. See enum with policies.
- *
- * @return The policy for the horizontal scrollbar policy.
- * @see setHorizontalScrollPolicy, setScrollPolicy
- */
- ScrollPolicy getHorizontalScrollPolicy() const
- { return mHPolicy; }
-
- /**
- * Sets the vertical scrollbar policy. See enum with policies.
- *
- * @param vPolicy The policy for the vertical scrollbar.
- * @see getVerticalScrollPolicy
- */
- void setVerticalScrollPolicy(const ScrollPolicy vPolicy);
-
- /**
- * Gets the vertical scrollbar policy. See enum with policies.
- *
- * @return The policy for the vertical scrollbar.
- * @see setVerticalScrollPolicy, setScrollPolicy
- */
- ScrollPolicy getVerticalScrollPolicy() const
- { return mVPolicy; }
-
- /**
- * Sets the horizontal and vertical scrollbar policy.
- *
- * @param hPolicy The policy for the horizontal scrollbar.
- * @param vPolicy The policy for the vertical scrollbar.
- * @see getVerticalScrollPolicy, getHorizontalScrollPolicy
- */
- void setScrollPolicy(const ScrollPolicy hPolicy,
- const ScrollPolicy vPolicy);
-
- /**
- * Sets the amount to scroll vertically.
- *
- * @param vScroll The amount to scroll.
- * @see getVerticalScrollAmount
- */
- void setVerticalScrollAmount(const int vScroll);
-
- /**
- * Gets the amount that is scrolled vertically.
- *
- * @return The scroll amount on vertical scroll.
- * @see setVerticalScrollAmount, setScrollAmount
- */
- int getVerticalScrollAmount() const
- { return mVScroll; }
-
- /**
- * Sets the amount to scroll horizontally.
- *
- * @param hScroll The amount to scroll.
- * @see getHorizontalScrollAmount
- */
- void setHorizontalScrollAmount(int hScroll);
-
- /**
- * Gets the amount that is scrolled horizontally.
- *
- * @return The scroll amount on horizontal scroll.
- * @see setHorizontalScrollAmount, setScrollAmount
- */
- int getHorizontalScrollAmount() const
- { return mHScroll; }
-
- /**
- * Sets the amount to scroll horizontally and vertically.
- *
- * @param hScroll The amount to scroll on horizontal scroll.
- * @param vScroll The amount to scroll on vertical scroll.
- * @see getHorizontalScrollAmount, getVerticalScrollAmount
- */
- void setScrollAmount(const int hScroll, const int vScroll);
-
- /**
- * Gets the maximum amount of horizontal scroll.
- *
- * @return The horizontal max scroll.
- */
- int getHorizontalMaxScroll();
-
- /**
- * Gets the maximum amount of vertical scroll.
- *
- * @return The vertical max scroll.
- */
- int getVerticalMaxScroll();
-
- /**
- * Sets the width of the scroll bars.
- *
- * @param width The width of the scroll bars.
- * @see getScrollbarWidth
- */
- void setScrollbarWidth(const int width);
-
- /**
- * Gets the width of the scroll bars.
- *
- * @return the width of the ScrollBar.
- * @see setScrollbarWidth
- */
- int getScrollbarWidth() const
- { return mScrollbarWidth; }
-
- /**
- * Sets the amount to scroll in pixels when the left scroll button is
- * pushed.
- *
- * @param amount The amount to scroll in pixels.
- * @see getLeftButtonScrollAmount
- */
- void setLeftButtonScrollAmount(const int amount)
- { mLeftButtonScrollAmount = amount; }
-
- /**
- * Sets the amount to scroll in pixels when the right scroll button is
- * pushed.
- *
- * @param amount The amount to scroll in pixels.
- * @see getRightButtonScrollAmount
- */
- void setRightButtonScrollAmount(const int amount)
- { mRightButtonScrollAmount = amount; }
-
- /**
- * Sets the amount to scroll in pixels when the up scroll button is
- * pushed.
- *
- * @param amount The amount to scroll in pixels.
- * @see getUpButtonScrollAmount
- */
- void setUpButtonScrollAmount(const int amount)
- { mUpButtonScrollAmount = amount; }
-
- /**
- * Sets the amount to scroll in pixels when the down scroll button is
- * pushed.
- *
- * @param amount The amount to scroll in pixels.
- * @see getDownButtonScrollAmount
- */
- void setDownButtonScrollAmount(const int amount)
- { mDownButtonScrollAmount = amount; }
-
- /**
- * Gets the amount to scroll in pixels when the left scroll button is
- * pushed.
- *
- * @return The amount to scroll in pixels.
- * @see setLeftButtonScrollAmount
- */
- int getLeftButtonScrollAmount() const
- { return mLeftButtonScrollAmount; }
-
- /**
- * Gets the amount to scroll in pixels when the right scroll button is
- * pushed.
- *
- * @return The amount to scroll in pixels.
- * @see setRightButtonScrollAmount
- */
- int getRightButtonScrollAmount() const
- { return mRightButtonScrollAmount; }
-
- /**
- * Gets the amount to scroll in pixels when the up scroll button is
- * pushed.
- *
- * @return The amount to scroll in pixels.
- * @see setUpButtonScrollAmount
- */
- int getUpButtonScrollAmount() const
- { return mUpButtonScrollAmount; }
-
- /**
- * Gets the amount to scroll in pixels when the down scroll button is
- * pushed.
- *
- * @return The amount to scroll in pixels.
- * @see setDownButtonScrollAmount
- */
- int getDownButtonScrollAmount() const
- { return mDownButtonScrollAmount; }
-
- void showWidgetPart(Widget *const widget,
- const Rect &area) override final;
-
- Rect getChildrenArea() override final;
-
- Widget *getWidgetAt(int x, int y) override final;
-
- void setWidth(int width);
-
- void setHeight(int height);
-
- void setDimension(const Rect& dimension);
-
- void mouseWheelMovedUp(MouseEvent& event) override final;
-
- void mouseWheelMovedDown(MouseEvent& event) override final;
-
- bool isSelectable() const noexcept2 override final A_WARN_UNUSED;
-
- protected:
- enum BUTTON_DIR
- {
- UP = 0,
- DOWN,
- LEFT,
- RIGHT,
- BUTTONS_DIR
- };
-
- /**
- * Initializes the scroll area.
- */
- void init(std::string skinName);
-
- /**
- * Checks the policies for the scroll bars.
- */
- void checkPolicies();
-
- void drawButton(Graphics *const graphics,
- const BUTTON_DIR dir) A_NONNULL(2);
- void calcButton(Graphics *const graphics,
- const BUTTON_DIR dir) A_NONNULL(2);
- void drawVBar(Graphics *const graphics) const A_NONNULL(2);
- void drawHBar(Graphics *const graphics) const A_NONNULL(2);
- void drawVMarker(Graphics *const graphics) A_NONNULL(2);
- void drawHMarker(Graphics *const graphics) A_NONNULL(2);
-
- void calcVBar(const Graphics *const graphics) A_NONNULL(2);
- void calcHBar(const Graphics *const graphics) A_NONNULL(2);
- void calcVMarker(Graphics *const graphics) A_NONNULL(2);
- void calcHMarker(Graphics *const graphics) A_NONNULL(2);
-
- Image *getImageByState(Rect &dim, const BUTTON_DIR dir);
-
- void updateCalcFlag(const Graphics *const graphics) A_NONNULL(2);
-
- static int instances;
- static float mAlpha;
- static bool mShowButtons;
- static int mMarkerSize;
- static int mScrollbarSize;
- static ImageRect background;
- static ImageRect vMarker;
- static ImageRect vMarkerHi;
- static ImageRect vBackground;
- static ImageRect hBackground;
- static Image *buttons[4][2];
-
- ImageCollection *mVertexes A_NONNULLPOINTER;
- ImageCollection *mVertexes2 A_NONNULLPOINTER;
-
- /**
- * Holds the horizontal scroll bar policy.
- */
- ScrollPolicy mHPolicy;
-
- /**
- * Holds the vertical scroll bar policy.
- */
- ScrollPolicy mVPolicy;
-
- /**
- * Holds the vertical scroll amount.
- */
- int mVScroll;
-
- /**
- * Holds the horizontal scroll amount.
- */
- int mHScroll;
-
- /**
- * Holds the width of the scroll bars.
- */
- int mScrollbarWidth;
-
- /**
- * Holds the up button scroll amount.
- */
- int mUpButtonScrollAmount;
-
- /**
- * Holds the down button scroll amount.
- */
- int mDownButtonScrollAmount;
-
- /**
- * Holds the left button scroll amount.
- */
- int mLeftButtonScrollAmount;
-
- /**
- * Holds the right button scroll amount.
- */
- int mRightButtonScrollAmount;
-
- /**
- * Holds the horizontal markers drag offset.
- */
- int mHorizontalMarkerDragOffset;
-
- /**
- * Holds the vertical markers drag offset.
- */
- int mVerticalMarkerDragOffset;
-
- int mX;
- int mY;
- int mClickX;
- int mClickY;
- int mXOffset;
- int mYOffset;
- int mDrawWidth;
- int mDrawHeight;
-
- /**
- * True if the vertical scroll bar is visible, false otherwise.
- */
- bool mVBarVisible;
-
- /**
- * True if the horizontal scroll bar is visible, false otherwise.
- */
- bool mHBarVisible;
-
- /**
- * True if the up button is pressed, false otherwise.
- */
- bool mUpButtonPressed;
-
- /**
- * True if the down button is pressed, false otherwise.
- */
- bool mDownButtonPressed;
-
- /**
- * True if the left button is pressed, false otherwise.
- */
- bool mLeftButtonPressed;
-
- /**
- * True if the right button is pressed, false otherwise.
- */
- bool mRightButtonPressed;
-
- /**
- * True if the vertical marked is dragged.
- */
- bool mIsVerticalMarkerDragged;
-
- /**
- * True if the horizontal marked is dragged.
- */
- bool mIsHorizontalMarkerDragged;
-
- /**
- * True if the scroll area should be opaque (that is
- * display its background), false otherwise.
- */
- Opaque mOpaque;
-
- bool mHasMouse;
-};
-
-#endif // GUI_WIDGETS_SCROLLAREA_H
diff --git a/src/gui/widgets/selldialog.cpp b/src/gui/widgets/selldialog.cpp
deleted file mode 100644
index 68b9a039f..000000000
--- a/src/gui/widgets/selldialog.cpp
+++ /dev/null
@@ -1,397 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/selldialog.h"
-
-#include "const/resources/currency.h"
-
-#include "enums/gui/layouttype.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "gui/models/shopitems.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layout.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/shoplistbox.h"
-#include "gui/widgets/slider.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "resources/db/unitsdb.h"
-
-#include "resources/item/shopitem.h"
-
-#include "debug.h"
-
-SellDialog::DialogList SellDialog::instances;
-
-SellDialog::SellDialog(const IsSell isSell,
- const Advanced advanced) :
- // TRANSLATORS: sell dialog name
- Window(_("Sell"), Modal_false, nullptr, "sell.xml"),
- ActionListener(),
- SelectionListener(),
- mSellButton(nullptr),
- mQuitButton(nullptr),
- mConfirmButton(nullptr),
- mAddMaxButton(nullptr),
- mIncreaseButton(nullptr),
- mDecreaseButton(nullptr),
- mShopItemList(nullptr),
- mScrollArea(nullptr),
- mMoneyLabel(nullptr),
- mQuantityLabel(nullptr),
- mSlider(nullptr),
- mShopItems(nullptr),
- mPlayerMoney(0),
- mMaxItems(0),
- mAmountItems(0),
- mIsSell(isSell),
- mAdvanced(advanced)
-{
-}
-
-void SellDialog::postInit()
-{
- Window::postInit();
- setWindowName("Sell");
- setResizable(true);
- setCloseButton(true);
- setStickyButtonLock(true);
- setMinWidth(260);
- setMinHeight(220);
- setDefaultSize(260, 230, ImagePosition::CENTER);
-
- if (setupWindow != nullptr)
- setupWindow->registerWindowForReset(this);
-
- // Create a ShopItems instance, that is aware of duplicate entries.
- mShopItems = new ShopItems(true,
- DEFAULT_CURRENCY);
-
- if (mAdvanced == Advanced_true)
- mShopItems->setMergeDuplicates(false);
-
- mShopItemList = CREATEWIDGETR(ShopListBox,
- this,
- mShopItems,
- mShopItems,
- ShopListBoxType::Unknown);
- mShopItemList->setProtectItems(true);
- mScrollArea = new ScrollArea(this, mShopItemList,
- fromBool(getOptionBool("showbackground"), Opaque),
- "sell_background.xml");
- mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- mSellButton = new Button(this,
- // TRANSLATORS: sell dialog button
- mAdvanced == Advanced_true ? _("Add") : _("Sell"),
- "presell",
- this);
- // TRANSLATORS: sell dialog button
- mQuitButton = new Button(this, _("Quit"), "quit", this);
-
- initButtons();
-
- mSellButton->setEnabled(false);
-
- mShopItemList->setDistributeMousePressed(false);
- mShopItemList->setPriceCheck(false);
- mShopItemList->addSelectionListener(this);
- mShopItemList->setActionEventId("sell");
- mShopItemList->addActionListener(this);
-
- ContainerPlacer placer;
- placer = getPlacer(0, 0);
-
- if (mIsSell == IsSell_true)
- {
- // TRANSLATORS: sell dialog button
- mIncreaseButton = new Button(this, _("+"), "inc", this);
- // TRANSLATORS: sell dialog button
- mDecreaseButton = new Button(this, _("-"), "dec", this);
- // TRANSLATORS: sell dialog button
- mAddMaxButton = new Button(this, _("Max"), "max", this);
- mSlider = new Slider(this, 1.0, 1.0);
-
- mQuantityLabel = new Label(this, strprintf(
- "%d / %d", mAmountItems, mMaxItems));
- mQuantityLabel->setAlignment(Graphics::CENTER);
- // TRANSLATORS: sell dialog label
- mMoneyLabel = new Label(this, strprintf(_("Price: %s / Total: %s"),
- "", ""));
- if (mAdvanced == Advanced_true)
- {
- // TRANSLATORS: sell dialog button
- mConfirmButton = new Button(this, _("Sell"), "confirm", this);
- mConfirmButton->setEnabled(false);
- }
-
- mDecreaseButton->adjustSize();
- mDecreaseButton->setWidth(mIncreaseButton->getWidth());
- mIncreaseButton->setEnabled(false);
- mDecreaseButton->setEnabled(false);
- mSlider->setEnabled(false);
- mSlider->setActionEventId("slider");
- mSlider->addActionListener(this);
-
- placer(0, 0, mScrollArea, 8, 5).setPadding(3);
- placer(0, 5, mDecreaseButton);
- placer(1, 5, mSlider, 3);
- placer(4, 5, mIncreaseButton);
- placer(5, 5, mQuantityLabel, 2);
- placer(7, 5, mAddMaxButton);
- placer(0, 6, mMoneyLabel, 8);
- if (mAdvanced == Advanced_true)
- {
- placer(5, 7, mSellButton);
- placer(6, 7, mConfirmButton);
- }
- else
- {
- placer(6, 7, mSellButton);
- }
- placer(7, 7, mQuitButton);
- }
- else
- {
- placer(0, 0, mScrollArea, 8, 5).setPadding(3);
- placer(6, 5, mSellButton);
- placer(7, 5, mQuitButton);
- }
-
- Layout &layout = getLayout();
- layout.setRowHeight(0, LayoutType::SET);
-
- center();
- loadWindowState();
-
- instances.push_back(this);
- setVisible(Visible_true);
- enableVisibleSound(true);
-}
-
-SellDialog::~SellDialog()
-{
- delete2(mShopItems);
- instances.remove(this);
-}
-
-void SellDialog::reset()
-{
- mShopItems->clear();
- if (mSlider != nullptr)
- mSlider->setValue(0);
- mShopItemList->setSelected(-1);
- updateButtonsAndLabels();
-}
-
-void SellDialog::addItem(const Item *const item, const int price)
-{
- if (item == nullptr)
- return;
-
- mShopItems->addItem2(item->getInvIndex(),
- item->getId(),
- item->getType(),
- item->getColor(),
- item->getQuantity(),
- price);
-
- mShopItemList->adjustSize();
-}
-
-ShopItem *SellDialog::addItem(const int id,
- const ItemTypeT type,
- const ItemColor color,
- const int amount,
- const int price)
-{
- ShopItem *const item = mShopItems->addItem(id,
- type,
- color,
- amount,
- price);
- mShopItemList->adjustSize();
- return item;
-}
-
-
-void SellDialog::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
-
- if (eventId == "quit")
- {
- close();
- return;
- }
-
- const int selectedItem = mShopItemList->getSelected();
-
- // The following actions require a valid item selection
- if (selectedItem == -1
- || selectedItem >= mShopItems->getNumberOfElements())
- {
- return;
- }
-
- if (eventId == "slider")
- {
- if (mSlider != nullptr)
- {
- mAmountItems = CAST_S32(mSlider->getValue());
- updateButtonsAndLabels();
- }
- }
- else if (eventId == "inc" &&
- mSlider != nullptr &&
- mAmountItems < mMaxItems)
- {
- mAmountItems++;
- mSlider->setValue(mAmountItems);
- updateButtonsAndLabels();
- }
- else if (eventId == "dec" &&
- mSlider != nullptr &&
- mAmountItems > 1)
- {
- mAmountItems--;
- mSlider->setValue(mAmountItems);
- updateButtonsAndLabels();
- }
- else if (eventId == "max" &&
- mSlider != nullptr)
- {
- mAmountItems = mMaxItems;
- mSlider->setValue(mAmountItems);
- updateButtonsAndLabels();
- }
- else if (eventId == "presell" ||
- eventId == "sell" ||
- eventId == "yes" ||
- eventId == "confirm")
- {
- sellAction(event);
- }
-}
-
-void SellDialog::valueChanged(const SelectionEvent &event A_UNUSED)
-{
- // Reset amount of items and update labels
- mAmountItems = 1;
- if (mSlider != nullptr)
- {
- mSlider->setValue(0);
- mSlider->setScale(1, mMaxItems);
- }
- updateButtonsAndLabels();
-}
-
-void SellDialog::setMoney(const int amount)
-{
- mPlayerMoney = amount;
- mShopItemList->setPlayersMoney(amount);
-}
-
-void SellDialog::updateButtonsAndLabels()
-{
- const int selectedItem = mShopItemList->getSelected();
- int income = 0;
- ShopItem *item = nullptr;
-
- if (selectedItem > -1 && (mShopItems->at(selectedItem) != nullptr))
- {
- item = mShopItems->at(selectedItem);
- if (item != nullptr)
- {
- mMaxItems = item->getQuantity();
- if (mAmountItems > mMaxItems)
- mAmountItems = mMaxItems;
- income = mAmountItems * mShopItems->at(selectedItem)->getPrice();
- }
- else
- {
- mMaxItems = 0;
- mAmountItems = 0;
- }
- }
- else
- {
- mMaxItems = 0;
- mAmountItems = 0;
- }
-
- // Update Buttons and slider
- mSellButton->setEnabled(mAmountItems > 0);
- if (mDecreaseButton != nullptr)
- mDecreaseButton->setEnabled(mAmountItems > 1);
- if (mIncreaseButton != nullptr)
- mIncreaseButton->setEnabled(mAmountItems < mMaxItems);
- if (mSlider != nullptr)
- mSlider->setEnabled(mMaxItems > 1);
-
- if (mQuantityLabel != nullptr)
- {
- // Update the quantity and money labels
- mQuantityLabel->setCaption(strprintf("%d / %d",
- mAmountItems, mMaxItems));
- }
- if (mMoneyLabel != nullptr)
- {
- // TRANSLATORS: sell dialog label
- mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"),
- UnitsDb::formatCurrency(income).c_str(),
- UnitsDb::formatCurrency(mPlayerMoney + income).c_str()));
- }
- if (item != nullptr)
- item->update();
-}
-
-void SellDialog::setVisible(Visible visible)
-{
- Window::setVisible(visible);
-
- if (visible == Visible_true)
- {
- if (mShopItemList != nullptr)
- mShopItemList->requestFocus();
- }
- else
- {
- scheduleDelete();
- }
-}
-
-void SellDialog::closeAll()
-{
- FOR_EACH (DialogList::const_iterator, it, instances)
- (*it)->close();
-}
diff --git a/src/gui/widgets/selldialog.h b/src/gui/widgets/selldialog.h
deleted file mode 100644
index e17d3116a..000000000
--- a/src/gui/widgets/selldialog.h
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SELLDIALOG_H
-#define GUI_WIDGETS_SELLDIALOG_H
-
-#include "enums/resources/item/itemtype.h"
-
-#include "enums/simpletypes/advanced.h"
-#include "enums/simpletypes/issell.h"
-#include "enums/simpletypes/itemcolor.h"
-
-#include "gui/widgets/window.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/selectionlistener.h"
-
-class Button;
-class Item;
-class Label;
-class ScrollArea;
-class ShopItem;
-class ShopItems;
-class ShopListBox;
-class Slider;
-
-/**
- * The sell dialog.
- *
- * \ingroup Interface
- */
-class SellDialog notfinal : public Window,
- public ActionListener,
- private SelectionListener
-{
- public:
- /**
- * Constructor.
- */
- SellDialog(const IsSell isSell,
- const Advanced advanced);
-
- A_DELETE_COPY(SellDialog)
-
- /**
- * Destructor
- */
- ~SellDialog();
-
- /**
- * Resets the dialog, clearing inventory.
- */
- void reset();
-
- /**
- * Adds an item to the inventory.
- */
- void addItem(const Item *const item,
- const int price);
-
- /**
- * Called when receiving actions from the widgets.
- */
- void action(const ActionEvent &event) override final;
-
- /**
- * Updates labels according to selected item.
- *
- * @see SelectionListener::selectionChanged
- */
- void valueChanged(const SelectionEvent &event) override final;
-
- /**
- * Gives Player's Money amount
- */
- void setMoney(const int amount);
-
- /**
- * Sets the visibility of this window.
- */
- void setVisible(Visible visible) override final;
-
- ShopItem *addItem(const int id,
- const ItemTypeT type,
- const ItemColor color,
- const int amount,
- const int price);
-
- /**
- * Returns true if any instances exist.
- */
- static bool isActive() A_WARN_UNUSED
- { return !instances.empty(); }
-
- /**
- * Closes all instances.
- */
- static void closeAll();
-
- void postInit() override;
-
- protected:
- typedef std::list<SellDialog*> DialogList;
- static DialogList instances;
-
- /**
- * Updates the state of buttons and labels.
- */
- void updateButtonsAndLabels();
-
- virtual void sellAction(const ActionEvent &event) = 0;
-
- virtual void initButtons()
- { }
-
- Button *mSellButton A_NONNULLPOINTER;
- Button *mQuitButton A_NONNULLPOINTER;
- Button *mConfirmButton A_NONNULLPOINTER;
- Button *mAddMaxButton;
- Button *mIncreaseButton;
- Button *mDecreaseButton;
- ShopListBox *mShopItemList A_NONNULLPOINTER;
- ScrollArea *mScrollArea A_NONNULLPOINTER;
- Label *mMoneyLabel;
- Label *mQuantityLabel;
- Slider *mSlider;
- ShopItems *mShopItems A_NONNULLPOINTER;
-
- int mPlayerMoney;
- int mMaxItems;
- int mAmountItems;
-
- IsSell mIsSell;
- Advanced mAdvanced;
-};
-
-#endif // GUI_WIDGETS_SELLDIALOG_H
diff --git a/src/gui/widgets/serverslistbox.h b/src/gui/widgets/serverslistbox.h
deleted file mode 100644
index 20d019f8d..000000000
--- a/src/gui/widgets/serverslistbox.h
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SERVERSLISTBOX_H
-#define GUI_WIDGETS_SERVERSLISTBOX_H
-
-#include "gui/widgets/listbox.h"
-
-#include "gui/models/serverslistmodel.h"
-
-#include "localconsts.h"
-
-class ServersListBox final : public ListBox
-{
- public:
- ServersListBox(const Widget2 *const widget,
- ServersListModel *const model) :
- ListBox(widget, model, "serverslistbox.xml"),
- mNotSupportedColor(getThemeColor(
- ThemeColorId::SERVER_VERSION_NOT_SUPPORTED)),
- mNotSupportedColor2(getThemeColor(
- ThemeColorId::SERVER_VERSION_NOT_SUPPORTED_OUTLINE))
- {
- mHighlightColor = getThemeColor(ThemeColorId::HIGHLIGHT);
- }
-
- A_DELETE_COPY(ServersListBox)
-
- void draw(Graphics *const graphics) override final A_NONNULL(2)
- {
- if (mListModel == nullptr)
- return;
-
- ServersListModel *const model
- = static_cast<ServersListModel *>(mListModel);
-
- updateAlpha();
-
- mHighlightColor.a = CAST_S32(mAlpha * 255.0F);
- graphics->setColor(mHighlightColor);
-
- const int height = getRowHeight();
- mNotSupportedColor.a = CAST_S32(mAlpha * 255.0F);
-
- // Draw filled rectangle around the selected list element
- if (mSelected >= 0)
- {
- graphics->fillRectangle(Rect(mPadding,
- height * mSelected + mPadding,
- getWidth() - 2 * mPadding,
- height));
- }
-
- Font *const font1 = boldFont;
- Font *const font2 = getFont();
- const int fontHeight = font1->getHeight();
- const int pad1 = fontHeight + mPadding;
- const int pad2 = height / 4 + mPadding;
- const int width = getWidth();
- // Draw the list elements
- for (int i = 0, y = 0; i < model->getNumberOfElements();
- ++i, y += height)
- {
- const ServerInfo &info = model->getServer(i);
-
- const Color *color1;
- const Color *color2;
- if (mSelected == i)
- {
- color1 = &mForegroundSelectedColor;
- color2 = &mForegroundSelectedColor2;
- }
- else
- {
- color1 = &mForegroundColor;
- color2 = &mForegroundColor2;
- }
-
- int top;
- int x = mPadding;
-
- if (!info.name.empty())
- {
- x += font1->getWidth(info.name) + 15;
- font1->drawString(graphics,
- *color1,
- *color2,
- info.name,
- mPadding,
- y + mPadding);
- top = y + pad1;
- }
- else
- {
- top = y + pad2;
- }
-
- if (!info.description.empty())
- {
- font2->drawString(graphics,
- *color1,
- *color2,
- info.description,
- x,
- y + mPadding);
- }
- font2->drawString(graphics,
- *color1,
- *color2,
- model->getElementAt(i),
- mPadding,
- top);
-
- if (info.version.first > 0)
- {
- font2->drawString(graphics,
- mNotSupportedColor,
- mNotSupportedColor2,
- info.version.second,
- width - info.version.first - mPadding,
- top);
- }
- }
- }
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2)
- {
- ServersListBox::draw(graphics);
- }
-
- unsigned int getRowHeight() const override final
- {
- return 2 * getFont()->getHeight() + 5;
- }
- private:
- Color mNotSupportedColor;
- Color mNotSupportedColor2;
-};
-
-#endif // GUI_WIDGETS_SERVERSLISTBOX_H
diff --git a/src/gui/widgets/setupbuttonitem.cpp b/src/gui/widgets/setupbuttonitem.cpp
deleted file mode 100644
index 07612f08c..000000000
--- a/src/gui/widgets/setupbuttonitem.cpp
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/setupbuttonitem.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/horizontcontainer.h"
-#include "gui/widgets/vertcontainer.h"
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-#include "debug.h"
-
-SetupButtonItem::SetupButtonItem(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict actionEventId,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ActionListener *const listener) :
- SetupItem(text, description, "", parent, eventName, MainConfig_false),
- mHorizont(nullptr),
- mButton(nullptr)
-{
- mValueType = VSTR;
- mWidget = new Button(this, text, actionEventId, listener);
- createControls();
-}
-
-SetupButtonItem::~SetupButtonItem()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mButton = nullptr;
-}
-
-void SetupButtonItem::save()
-{
-}
-
-void SetupButtonItem::cancel(const std::string &eventName A_UNUSED)
-{
-}
-
-void SetupButtonItem::externalUpdated(const std::string &eventName A_UNUSED)
-{
-}
-
-void SetupButtonItem::rereadValue()
-{
-}
-
-void SetupButtonItem::createControls()
-{
- mHorizont = new HorizontContainer(this, 32, 2);
-
- // TRANSLATORS: setup item button
- mHorizont->add(mWidget);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
-// mWidget->addActionListener(this);
-}
-
-void SetupButtonItem::fromWidget()
-{
-}
-
-void SetupButtonItem::toWidget()
-{
-}
-
-void SetupButtonItem::action(const ActionEvent &event A_UNUSED)
-{
-}
-
-void SetupButtonItem::apply(const std::string &eventName A_UNUSED)
-{
-}
diff --git a/src/gui/widgets/setupbuttonitem.h b/src/gui/widgets/setupbuttonitem.h
deleted file mode 100644
index b4f99328b..000000000
--- a/src/gui/widgets/setupbuttonitem.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SETUPBUTTONITEM_H
-#define GUI_WIDGETS_SETUPBUTTONITEM_H
-
-#include "gui/widgets/setupitem.h"
-
-class Button;
-class HorizontContainer;
-class SetupTabScroll;
-
-class SetupButtonItem final : public SetupItem
-{
- public:
- SetupButtonItem(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict actionEventId,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ActionListener *const listener);
-
- A_DELETE_COPY(SetupButtonItem)
-
- ~SetupButtonItem();
-
- void createControls();
-
- void fromWidget() override final A_CONST;
-
- void toWidget() override final A_CONST;
-
- void action(const ActionEvent &event) override final A_CONST;
-
- void apply(const std::string &eventName) override final A_CONST;
-
- void cancel(const std::string &eventName A_UNUSED)
- override final A_CONST;
-
- void externalUpdated(const std::string &eventName A_UNUSED)
- override final A_CONST;
-
- void rereadValue() override final A_CONST;
-
- void save() override final A_CONST;
-
- protected:
- HorizontContainer *mHorizont;
- Button *mButton;
-};
-
-#endif // GUI_WIDGETS_SETUPBUTTONITEM_H
diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp
deleted file mode 100644
index cc6ded02e..000000000
--- a/src/gui/widgets/setupitem.cpp
+++ /dev/null
@@ -1,1338 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/setupitem.h"
-
-#include "configuration.h"
-#include "soundmanager.h"
-
-#include "gui/gui.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/listmodel.h"
-
-#include "gui/windows/editdialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/checkbox.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/horizontcontainer.h"
-#include "gui/widgets/inttextfield.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/slider.h"
-#include "gui/widgets/sliderlist.h"
-#include "gui/widgets/vertcontainer.h"
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-#include "utils/base64.h"
-#include "utils/gettext.h"
-#include "utils/stdmove.h"
-#include "utils/mathutils.h"
-
-#include "debug.h"
-
-SetupItem::SetupItem(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const MainConfig mainConfig) :
- ActionListener(),
- Widget2(parent),
- mText(text),
- mDescription(description),
- mKeyName(keyName),
- mParent(parent),
- mEventName(eventName),
- mValue(),
- mDefault(),
- mWidget(nullptr),
- mTempWidgets(),
- mValueType(VBOOL),
- mMainConfig(mainConfig),
- mUseDefault(false)
-{
-}
-
-SetupItem::SetupItem(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const std::string &restrict def,
- const MainConfig mainConfig) :
- ActionListener(),
- Widget2(parent),
- mText(text),
- mDescription(description),
- mKeyName(keyName),
- mParent(parent),
- mEventName(eventName),
- mValue(),
- mDefault(def),
- mWidget(nullptr),
- mTempWidgets(),
- mValueType(VBOOL),
- mMainConfig(mainConfig),
- mUseDefault(true)
-{
-}
-
-SetupItem::~SetupItem()
-{
-}
-
-Configuration *SetupItem::getConfig() const
-{
- if (mMainConfig == MainConfig_true)
- return &config;
- return &serverConfig;
-}
-
-void SetupItem::load()
-{
- if (mKeyName.empty())
- return;
-
- const Configuration *const cfg = getConfig();
- if (mUseDefault)
- {
- mValue = cfg->getValue(mKeyName, mDefault);
- }
- else
- {
- switch (mValueType)
- {
- case VBOOL:
- if (cfg->getBoolValue(mKeyName))
- mValue = "1";
- else
- mValue = "0";
- break;
- case VSTR:
- default:
- mValue = cfg->getStringValue(mKeyName);
- break;
- case VINT:
- mValue = toString(cfg->getIntValue(mKeyName));
- break;
- case VNONE:
- break;
- }
- }
-}
-
-void SetupItem::save()
-{
- if (mKeyName.empty())
- return;
-
- Configuration *const cfg = getConfig();
- cfg->setValue(mKeyName, mValue);
-}
-
-std::string SetupItem::getActionEventId() const
-{
- if (mWidget == nullptr)
- return std::string();
-
- return mWidget->getActionEventId();
-}
-
-void SetupItem::action(const ActionEvent &event)
-{
- if (mWidget == nullptr)
- return;
-
- if (event.getId() == mWidget->getActionEventId())
- doAction();
-}
-
-void SetupItem::doAction()
-{
- fromWidget();
-}
-
-void SetupItem::apply(const std::string &eventName A_UNUSED)
-{
- save();
-}
-
-void SetupItem::cancel(const std::string &eventName A_UNUSED)
-{
- load();
- toWidget();
-}
-
-void SetupItem::externalUpdated(const std::string &eventName A_UNUSED)
-{
- load();
- toWidget();
-}
-
-void SetupItem::externalUnloaded(const std::string &eventName A_UNUSED)
-{
-}
-
-void SetupItem::fixFirstItemSize(Widget *const widget)
-{
- if (widget == nullptr)
- return;
- const int maxSize = mParent->getPreferredFirstItemSize();
- if (widget->getWidth() < maxSize)
- widget->setWidth(maxSize);
-}
-
-void SetupItem::rereadValue()
-{
- load();
- toWidget();
-}
-
-SetupItemCheckBox::SetupItemCheckBox(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mCheckBox(nullptr)
-{
- createControls();
-}
-
-SetupItemCheckBox::SetupItemCheckBox(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const std::string &restrict def,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mCheckBox(nullptr)
-{
- createControls();
-}
-
-SetupItemCheckBox::~SetupItemCheckBox()
-{
- mWidget = nullptr;
-}
-
-void SetupItemCheckBox::createControls()
-{
- load();
- mCheckBox = new CheckBox(this, mText, mValue != "0", mParent, mEventName);
- mCheckBox->setToolTip(mDescription);
- mWidget = mCheckBox;
- mParent->getContainer()->add1(mWidget);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
-}
-
-void SetupItemCheckBox::fromWidget()
-{
- if (mCheckBox == nullptr)
- return;
-
- if (mCheckBox->isSelected())
- mValue = "1";
- else
- mValue = "0";
-}
-
-void SetupItemCheckBox::toWidget()
-{
- if (mCheckBox == nullptr)
- return;
-
- mCheckBox->setSelected(mValue != "0");
-}
-
-
-SetupItemTextField::SetupItemTextField(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const MainConfig mainConfig,
- const UseBase64 useBase64) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mTextField(nullptr),
- mButton(nullptr),
- mEditDialog(nullptr),
- mUseBase64(useBase64)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemTextField::SetupItemTextField(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const std::string &restrict def,
- const MainConfig mainConfig,
- const UseBase64 useBase64) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mTextField(nullptr),
- mButton(nullptr),
- mEditDialog(nullptr),
- mUseBase64(useBase64)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemTextField::~SetupItemTextField()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mTextField = nullptr;
- mLabel = nullptr;
- mButton = nullptr;
-}
-
-void SetupItemTextField::save()
-{
- if (mUseBase64 == UseBase64_true)
- {
- std::string normalValue = mValue;
- mValue = encodeBase64String(mValue);
- SetupItem::save();
- mValue = STD_MOVE(normalValue);
- }
- else
- {
- SetupItem::save();
- }
-}
-
-void SetupItemTextField::cancel(const std::string &eventName A_UNUSED)
-{
- load();
- if (mUseBase64 == UseBase64_true)
- mValue = decodeBase64String(mValue);
- toWidget();
-}
-
-void SetupItemTextField::externalUpdated(const std::string &eventName A_UNUSED)
-{
- load();
- if (mUseBase64 == UseBase64_true)
- mValue = decodeBase64String(mValue);
- toWidget();
-}
-
-void SetupItemTextField::rereadValue()
-{
- load();
- if (mUseBase64 == UseBase64_true)
- mValue = decodeBase64String(mValue);
- toWidget();
-}
-
-void SetupItemTextField::createControls()
-{
- load();
- if (mUseBase64 == UseBase64_true)
- mValue = decodeBase64String(mValue);
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mTextField = new TextField(this,
- mValue,
- LoseFocusOnTab_true,
- mParent,
- mEventName);
- // TRANSLATORS: setup item button
- mButton = new Button(this, _("Edit"), mEventName + "_EDIT", mParent);
- mWidget = mTextField;
- mTextField->setWidth(200);
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel);
- mHorizont->add(mTextField);
- mHorizont->add(mButton);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addControl(this, mEventName + "_EDIT");
- mParent->addControl(this, mEventName + "_EDIT_OK");
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
- mButton->addActionListener(this);
-}
-
-void SetupItemTextField::fromWidget()
-{
- if (mTextField == nullptr)
- return;
-
- mValue = mTextField->getText();
-}
-
-void SetupItemTextField::toWidget()
-{
- if (mTextField == nullptr)
- return;
-
- mTextField->setText(mValue);
-}
-
-void SetupItemTextField::action(const ActionEvent &event)
-{
- if (mTextField == nullptr)
- return;
-
- const std::string &eventId = event.getId();
- if ((mWidget != nullptr) && eventId == mWidget->getActionEventId())
- {
- fromWidget();
- }
- else if (eventId == mEventName + "_EDIT")
- {
- mEditDialog = CREATEWIDGETR(EditDialog,
- mText,
- mTextField->getText(),
- mEventName + "_EDIT_OK");
- mEditDialog->addActionListener(this);
- }
- else if (eventId == mEventName + "_EDIT_OK")
- {
- mTextField->setText(mEditDialog->getMsg());
- mEditDialog = nullptr;
- }
-}
-
-void SetupItemTextField::apply(const std::string &eventName)
-{
- if (eventName != mEventName)
- return;
-
- fromWidget();
- save();
-}
-
-SetupItemIntTextField::SetupItemIntTextField(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict
- keyName,
- SetupTabScroll *restrict
- const parent,
- const std::string &restrict
- eventName,
- const int min, const int max,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mTextField(nullptr),
- mButton(nullptr),
- mEditDialog(nullptr),
- mMin(min),
- mMax(max)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemIntTextField::SetupItemIntTextField(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict
- keyName,
- SetupTabScroll *restrict
- const parent,
- const std::string &restrict
- eventName,
- const int min, const int max,
- const std::string &restrict def,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mTextField(nullptr),
- mButton(nullptr),
- mEditDialog(nullptr),
- mMin(min),
- mMax(max)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemIntTextField::~SetupItemIntTextField()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mTextField = nullptr;
- mLabel = nullptr;
- mButton = nullptr;
-}
-
-void SetupItemIntTextField::createControls()
-{
- load();
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mTextField = new IntTextField(this, atoi(mValue.c_str()),
- mMin, mMax, Enable_true, 30);
- mTextField->setActionEventId(mEventName);
- mTextField->addActionListener(mParent);
-
- // TRANSLATORS: setup item button
- mButton = new Button(this, _("Edit"), mEventName + "_EDIT", mParent);
- mWidget = mTextField;
- mTextField->setWidth(50);
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel);
- mHorizont->add(mTextField);
- mHorizont->add(mButton);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addControl(this, mEventName + "_EDIT");
- mParent->addControl(this, mEventName + "_EDIT_OK");
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
- mButton->addActionListener(this);
-}
-
-void SetupItemIntTextField::fromWidget()
-{
- if (mTextField == nullptr)
- return;
-
- mValue = mTextField->getText();
-}
-
-void SetupItemIntTextField::toWidget()
-{
- if (mTextField == nullptr)
- return;
-
- mTextField->setText(mValue);
-}
-
-void SetupItemIntTextField::action(const ActionEvent &event)
-{
- if (mTextField == nullptr)
- return;
-
- const std::string &eventId = event.getId();
- if ((mWidget != nullptr) && eventId == mWidget->getActionEventId())
- {
- fromWidget();
- }
- else if (eventId == mEventName + "_EDIT")
- {
- mEditDialog = CREATEWIDGETR(EditDialog,
- mText,
- mTextField->getText(),
- mEventName + "_EDIT_OK");
- mEditDialog->addActionListener(this);
- }
- else if (eventId == mEventName + "_EDIT_OK")
- {
- mTextField->setValue(atoi(mEditDialog->getMsg().c_str()));
- mEditDialog = nullptr;
- }
-}
-
-void SetupItemIntTextField::apply(const std::string &eventName)
-{
- if (eventName != mEventName)
- return;
-
- fromWidget();
- save();
-}
-
-
-SetupItemLabel::SetupItemLabel(const std::string &restrict text,
- const std::string &restrict description,
- SetupTabScroll *restrict const parent,
- const Separator separator) :
- SetupItem(text, description, "", parent, "", "", MainConfig_true),
- mLabel(nullptr),
- mIsSeparator(separator)
-{
- mValueType = VNONE;
- createControls();
-}
-
-SetupItemLabel::~SetupItemLabel()
-{
- mWidget = nullptr;
- mLabel = nullptr;
-}
-
-void SetupItemLabel::createControls()
-{
- if (mIsSeparator == Separator_true)
- {
- const std::string str(" \342\200\225\342\200\225\342\200\225"
- "\342\200\225\342\200\225 ");
- mLabel = new Label(this, std::string(str).append(mText).append(str));
- }
- else
- {
- mLabel = new Label(this, mText);
- }
- mLabel->setToolTip(mDescription);
-
- mWidget = mLabel;
- mParent->getContainer()->add1(mWidget);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
-}
-
-void SetupItemLabel::fromWidget()
-{
-}
-
-void SetupItemLabel::toWidget()
-{
-}
-
-void SetupItemLabel::action(const ActionEvent &event A_UNUSED)
-{
-}
-
-void SetupItemLabel::apply(const std::string &eventName A_UNUSED)
-{
-}
-
-
-SetupItemDropDown::SetupItemDropDown(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mModel(model),
- mDropDown(nullptr),
- mWidth(width)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemDropDown::SetupItemDropDown(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const std::string &restrict def,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mModel(model),
- mDropDown(nullptr),
- mWidth(width)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemDropDown::~SetupItemDropDown()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mModel = nullptr;
- mDropDown = nullptr;
- mLabel = nullptr;
-}
-
-void SetupItemDropDown::createControls()
-{
- load();
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mDropDown = new DropDown(this, mModel);
- mDropDown->setActionEventId(mEventName);
- mDropDown->addActionListener(mParent);
- mDropDown->setWidth(mWidth);
- mDropDown->setSelected(selectionByValue());
-
- mWidget = mDropDown;
- if (!mText.empty())
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel);
- mHorizont->add(mDropDown);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
-}
-
-int SetupItemDropDown::selectionByValue()
-{
- return atoi(mValue.c_str());
-}
-
-void SetupItemDropDown::fromWidget()
-{
- if (mDropDown == nullptr)
- return;
-
- mValue = toString(mDropDown->getSelected());
-}
-
-void SetupItemDropDown::toWidget()
-{
- if (mDropDown == nullptr)
- return;
-
- mDropDown->setSelected(selectionByValue());
-}
-
-
-SetupItemDropDownStr::SetupItemDropDownStr(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const
- parent,
- const std::string &restrict
- eventName,
- ListModel *restrict const model,
- const int width,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mModel(model),
- mDropDown(nullptr),
- mWidth(width)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemDropDownStr::SetupItemDropDownStr(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const
- parent,
- const std::string &restrict
- eventName,
- ListModel *restrict const model,
- const int width,
- const std::string &restrict def,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mModel(model),
- mDropDown(nullptr),
- mWidth(width)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemDropDownStr::~SetupItemDropDownStr()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mModel = nullptr;
- mDropDown = nullptr;
- mLabel = nullptr;
-}
-
-void SetupItemDropDownStr::createControls()
-{
- load();
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mDropDown = new DropDown(this, mModel);
- mDropDown->setActionEventId(mEventName);
- mDropDown->addActionListener(mParent);
- mDropDown->setWidth(mWidth);
- mDropDown->setSelected(selectionByValue());
-
- mWidget = mDropDown;
- if (!mText.empty())
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel);
- mHorizont->add(mDropDown);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
-}
-
-int SetupItemDropDownStr::selectionByValue()
-{
- const int sz = mModel->getNumberOfElements();
- for (int f = 0; f < sz; f ++)
- {
- if (mModel->getElementAt(f) == mValue)
- {
- return f;
- }
- }
- return 0;
-}
-
-void SetupItemDropDownStr::fromWidget()
-{
- if (mDropDown == nullptr)
- return;
-
- const int sel = mDropDown->getSelected();
- // use first element in model as empty string
- if (sel == 0 || sel >= mModel->getNumberOfElements())
- mValue.clear();
- else
- mValue = mModel->getElementAt(sel);
-}
-
-void SetupItemDropDownStr::toWidget()
-{
- if (mDropDown == nullptr)
- return;
-
- mDropDown->setSelected(selectionByValue());
-}
-
-
-SetupItemSlider::SetupItemSlider(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const double min,
- const double max,
- const double step,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mSlider(nullptr),
- mMin(min),
- mMax(max),
- mStep(step),
- mWidth(width),
- mOnTheFly(onTheFly)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemSlider::SetupItemSlider(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const double min,
- const double max,
- const double step,
- const std::string &restrict def,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mSlider(nullptr),
- mMin(min),
- mMax(max),
- mStep(step),
- mWidth(width),
- mOnTheFly(onTheFly)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemSlider::~SetupItemSlider()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mSlider = nullptr;
- mLabel = nullptr;
-}
-
-void SetupItemSlider::createControls()
-{
- load();
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mSlider = new Slider(this, mMin, mMax, mStep);
- mSlider->setActionEventId(mEventName);
- mSlider->addActionListener(mParent);
- mSlider->setValue(atof(mValue.c_str()));
- mSlider->setHeight(30);
-
- mWidget = mSlider;
- mSlider->setWidth(mWidth);
- mSlider->setHeight(40);
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel);
- mHorizont->add(mSlider, -10);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
-}
-
-void SetupItemSlider::fromWidget()
-{
- if (mSlider == nullptr)
- return;
-
- mValue = toString(mSlider->getValue());
-}
-
-void SetupItemSlider::toWidget()
-{
- if (mSlider == nullptr)
- return;
-
- mSlider->setValue(atof(mValue.c_str()));
-}
-
-void SetupItemSlider::action(const ActionEvent &event A_UNUSED)
-{
- fromWidget();
- if (mOnTheFly == OnTheFly_true)
- save();
-}
-
-void SetupItemSlider::apply(const std::string &eventName)
-{
- if (eventName != mEventName)
- return;
-
- fromWidget();
- save();
-}
-
-
-SetupItemSlider2::SetupItemSlider2(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const int min,
- const int max,
- const int step,
- SetupItemNames *restrict const values,
- const OnTheFly onTheFly,
- const MainConfig mainConfig,
- const DoNotAlign doNotAlign) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mLabel2(nullptr),
- mSlider(nullptr),
- mValues(values),
- mMin(min),
- mMax(max),
- mStep(step),
- mInvertValue(0),
- mInvert(false),
- mOnTheFly(onTheFly),
- mDoNotAlign(doNotAlign)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemSlider2::SetupItemSlider2(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const int min,
- const int max,
- const int step,
- SetupItemNames *restrict const values,
- const std::string &restrict def,
- const OnTheFly onTheFly,
- const MainConfig mainConfig,
- const DoNotAlign doNotAlign) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mLabel2(nullptr),
- mSlider(nullptr),
- mValues(values),
- mMin(min),
- mMax(max),
- mStep(step),
- mInvertValue(0),
- mInvert(false),
- mOnTheFly(onTheFly),
- mDoNotAlign(doNotAlign)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupItemSlider2::~SetupItemSlider2()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mSlider = nullptr;
- mLabel = nullptr;
-}
-
-void SetupItemSlider2::createControls()
-{
- load();
- mHorizont = new HorizontContainer(this, 32, 2);
-
- const int width = getMaxWidth();
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mLabel2 = new Label(this, "");
- mLabel2->setWidth(width);
- mSlider = new Slider(this, mMin, mMax, mStep);
- mSlider->setActionEventId(mEventName);
- mSlider->addActionListener(mParent);
- mSlider->setValue(atof(mValue.c_str()));
- mSlider->setHeight(30);
-
- mWidget = mSlider;
- mSlider->setWidth(150);
- mSlider->setHeight(40);
- if (mDoNotAlign == DoNotAlign_false)
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel);
- mHorizont->add(mSlider, -10);
- mHorizont->add(mLabel2);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
- updateLabel();
-}
-
-int SetupItemSlider2::getMaxWidth()
-{
- if ((mValues == nullptr) || (gui == nullptr))
- return 1;
-
- int maxWidth = 0;
- SetupItemNamesConstIter it = mValues->begin();
- const SetupItemNamesConstIter it_end = mValues->end();
- const Font *const font = gui->getFont();
-
- while (it != it_end)
- {
- const int w = font->getWidth(*it);
- if (w > maxWidth)
- maxWidth = w;
-
- ++ it;
- }
- return maxWidth;
-}
-
-void SetupItemSlider2::fromWidget()
-{
- if (mSlider == nullptr)
- return;
-
- int val = roundDouble(mSlider->getValue());
- if (mInvert)
- val = mInvertValue - val;
- mValue = toString(val);
-}
-
-void SetupItemSlider2::toWidget()
-{
- if (mSlider == nullptr)
- return;
-
- int val = roundDouble(atof(mValue.c_str()));
- if (mInvert)
- val = mInvertValue - val;
- mSlider->setValue(val);
- updateLabel();
-}
-
-void SetupItemSlider2::action(const ActionEvent &event A_UNUSED)
-{
- fromWidget();
- updateLabel();
- if (mOnTheFly == OnTheFly_true)
- save();
-}
-
-void SetupItemSlider2::updateLabel()
-{
- int val = CAST_S32(mSlider->getValue()) - mMin;
- if (val < 0)
- {
- val = 0;
- }
- else
- {
- const int sz = CAST_S32(mValues->size());
- if (val >= sz)
- val = sz - 1;
- }
- std::string str = mValues->at(val);
- mLabel2->setCaption(str);
-}
-
-void SetupItemSlider2::apply(const std::string &eventName)
-{
- if (eventName != mEventName)
- return;
-
- fromWidget();
- save();
-}
-
-void SetupItemSlider2::setInvertValue(const int v)
-{
- mInvert = true;
- mInvertValue = v;
- toWidget();
-}
-
-
-SetupItemSliderList::SetupItemSliderList(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mSlider(nullptr),
- mModel(model),
- mWidth(width),
- mOnTheFly(onTheFly)
-{
- mValueType = VSTR;
-}
-
-SetupItemSliderList::SetupItemSliderList(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const std::string &restrict def,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mSlider(nullptr),
- mModel(model),
- mWidth(width),
- mOnTheFly(onTheFly)
-{
- mValueType = VSTR;
-}
-
-SetupItemSliderList::~SetupItemSliderList()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mSlider = nullptr;
- mLabel = nullptr;
-}
-
-void SetupItemSliderList::createControls()
-{
- load();
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mSlider = new SliderList(this, mModel);
- mSlider->postInit2(mParent, mEventName);
- mSlider->setSelectedString(mValue);
- mSlider->adjustSize();
-
- mWidget = mSlider;
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel, 5);
- mHorizont->add(mSlider);
-
- addMoreControls();
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
-}
-
-void SetupItemSliderList::fromWidget()
-{
- if (mSlider == nullptr)
- return;
-
- mValue = mSlider->getSelectedString();
-}
-
-void SetupItemSliderList::toWidget()
-{
- if (mSlider == nullptr)
- return;
-
- mSlider->setSelectedString(mValue);
-}
-
-void SetupItemSliderList::action(const ActionEvent &event A_UNUSED)
-{
- fromWidget();
- if (mOnTheFly == OnTheFly_true)
- save();
-}
-
-void SetupItemSliderList::apply(const std::string &eventName)
-{
- if (eventName != mEventName)
- return;
-
- fromWidget();
- save();
-}
-
-SetupItemSound::SetupItemSound(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig) :
- SetupItemSliderList(text, description, keyName, parent, eventName,
- model, width, onTheFly, mainConfig),
- mButton(nullptr)
-{
- createControls();
-}
-
-void SetupItemSound::addMoreControls()
-{
- mButton = new Button(this, BUTTON_PLAY, 16, 16,
- mEventName + "_PLAY", this);
- if (mHorizont != nullptr)
- mHorizont->add(mButton);
-}
-
-void SetupItemSound::action(const ActionEvent &event)
-{
- if (event.getId() == mEventName + "_PLAY")
- {
- if ((mSlider != nullptr) && (mSlider->getSelected() != 0))
- {
- soundManager.playGuiSfx(pathJoin(branding.getStringValue(
- "systemsounds"),
- mSlider->getSelectedString()).append(".ogg"));
- }
- }
- else
- {
- SetupItemSliderList::action(event);
- }
-}
-
-SetupItemSliderInt::SetupItemSliderInt(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int min,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig) :
- SetupItemSliderList(text, description, keyName, parent, eventName,
- model, width, onTheFly, mainConfig),
- mMin(min)
-{
- createControls();
-}
-
-void SetupItemSliderInt::addMoreControls()
-{
- toWidget();
-}
-
-void SetupItemSliderInt::fromWidget()
-{
- if (mSlider == nullptr)
- return;
-
- mValue = toString(mSlider->getSelected() + mMin);
-}
-
-void SetupItemSliderInt::toWidget()
-{
- if (mSlider == nullptr)
- return;
-
- mSlider->setSelected(atoi(mValue.c_str()) - mMin);
-}
diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h
deleted file mode 100644
index eec63a4bc..000000000
--- a/src/gui/widgets/setupitem.h
+++ /dev/null
@@ -1,613 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SETUPITEM_H
-#define GUI_WIDGETS_SETUPITEM_H
-
-#include "enums/simpletypes/donotalign.h"
-#include "enums/simpletypes/mainconfig.h"
-#include "enums/simpletypes/onthefly.h"
-#include "enums/simpletypes/usebase64.h"
-#include "enums/simpletypes/separator.h"
-
-#include "gui/widgets/widget2.h"
-
-#include "listeners/actionlistener.h"
-
-#include <list>
-
-class Button;
-class CheckBox;
-class Configuration;
-class DropDown;
-class EditDialog;
-class HorizontContainer;
-class IntTextField;
-class Label;
-class ListModel;
-class SetupTabScroll;
-class Slider;
-class SliderList;
-class TextField;
-
-class SetupItem notfinal : public ActionListener,
- public Widget2
-{
- public:
- enum
- {
- VBOOL = 0,
- VSTR,
- VINT,
- VNONE
- };
-
- A_DELETE_COPY(SetupItem)
-
- virtual ~SetupItem();
-
- void load();
-
- virtual void save();
-
- virtual void fromWidget() = 0;
-
- virtual void toWidget() = 0;
-
- void setWidget(Widget *widget)
- { mWidget = widget; }
-
- Widget *getWidget() const noexcept2 A_WARN_UNUSED
- { return mWidget; }
-
- Configuration *getConfig() const RETURNS_NONNULL A_WARN_UNUSED;
-
- virtual std::string getActionEventId() const A_WARN_UNUSED;
-
- void action(const ActionEvent &event) override;
-
- virtual void doAction();
-
- virtual void apply(const std::string &eventName);
-
- virtual void cancel(const std::string &eventName);
-
- virtual void externalUpdated(const std::string &eventName);
-
- virtual void externalUnloaded(const std::string &eventName) A_CONST;
-
- MainConfig isMainConfig() const noexcept2 A_WARN_UNUSED
- { return mMainConfig; }
-
- void fixFirstItemSize(Widget *const widget);
-
- virtual void rereadValue();
-
- void setValue(const std::string &str) noexcept2
- { mValue = str; }
-
- std::string getValue() const noexcept2
- { return mValue; }
-
- std::string getEventName() const noexcept2
- { return mEventName; }
-
- protected:
- SetupItem(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const MainConfig mainConfig);
-
- SetupItem(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const std::string &def,
- const MainConfig mainConfig);
-
- std::string mText;
-
- std::string mDescription;
-
- std::string mKeyName;
-
- SetupTabScroll *mParent;
-
- std::string mEventName;
-
- std::string mValue;
-
- std::string mDefault;
-
- Widget *mWidget;
-
- std::list<Widget*> mTempWidgets;
-
- int mValueType;
-
- MainConfig mMainConfig;
-
- bool mUseDefault;
-};
-
-class SetupItemCheckBox final : public SetupItem
-{
- public:
- SetupItemCheckBox(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const MainConfig mainConfig = MainConfig_true);
-
- SetupItemCheckBox(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const std::string &restrict def,
- const MainConfig mainConfig = MainConfig_true);
-
- A_DELETE_COPY(SetupItemCheckBox)
-
- ~SetupItemCheckBox();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- protected:
- CheckBox *mCheckBox;
-};
-
-class SetupItemTextField final : public SetupItem
-{
- public:
- SetupItemTextField(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const MainConfig mainConfig = MainConfig_true,
- const UseBase64 useBase64 = UseBase64_false);
-
- SetupItemTextField(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const std::string &restrict def,
- const MainConfig mainConfig = MainConfig_true,
- const UseBase64 useBase64 = UseBase64_false);
-
- A_DELETE_COPY(SetupItemTextField)
-
- ~SetupItemTextField();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- void action(const ActionEvent &event) override final;
-
- void apply(const std::string &eventName) override final;
-
- void cancel(const std::string &eventName A_UNUSED) override final;
-
- void externalUpdated(const std::string &eventName A_UNUSED)
- override final;
-
- void rereadValue() override final;
-
- void save() override final;
-
- void setUseBase64(const UseBase64 b)
- { mUseBase64 = b; }
-
- protected:
- HorizontContainer *mHorizont;
- Label *mLabel;
- TextField *mTextField;
- Button *mButton;
- EditDialog *mEditDialog;
- UseBase64 mUseBase64;
-};
-
-class SetupItemIntTextField final : public SetupItem
-{
- public:
- SetupItemIntTextField(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const int min, const int max,
- const MainConfig mainConfig = MainConfig_true);
-
- SetupItemIntTextField(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const int min, const int max,
- const std::string &restrict def,
- const MainConfig mainConfig = MainConfig_true);
-
- A_DELETE_COPY(SetupItemIntTextField)
-
- ~SetupItemIntTextField();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- void action(const ActionEvent &event) override final;
-
- void apply(const std::string &eventName) override final;
-
- protected:
- HorizontContainer *mHorizont;
- Label *mLabel;
- IntTextField *mTextField;
- Button *mButton;
- EditDialog *mEditDialog;
- int mMin;
- int mMax;
-};
-
-class SetupItemLabel final : public SetupItem
-{
- public:
- SetupItemLabel(const std::string &restrict text,
- const std::string &restrict description,
- SetupTabScroll *restrict const parent,
- const Separator separator = Separator_true);
-
- A_DELETE_COPY(SetupItemLabel)
-
- ~SetupItemLabel();
-
- void createControls();
-
- void fromWidget() override final A_CONST;
-
- void toWidget() override final A_CONST;
-
- void action(const ActionEvent &event) override final A_CONST;
-
- void apply(const std::string &eventName) override final A_CONST;
-
- protected:
- Label *mLabel;
- Separator mIsSeparator;
-};
-
-class SetupItemDropDown final : public SetupItem
-{
- public:
- SetupItemDropDown(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const MainConfig mainConfig = MainConfig_true);
-
- SetupItemDropDown(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const std::string &restrict def,
- const MainConfig mainConfig = MainConfig_true);
-
- A_DELETE_COPY(SetupItemDropDown)
-
- ~SetupItemDropDown();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- int selectionByValue();
-
- protected:
- HorizontContainer *mHorizont;
- Label *mLabel;
- ListModel *mModel;
- DropDown *mDropDown;
- int mWidth;
-};
-
-class SetupItemDropDownStr final : public SetupItem
-{
- public:
- SetupItemDropDownStr(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const MainConfig mainConfig = MainConfig_true);
-
- SetupItemDropDownStr(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width,
- const std::string &restrict def,
- const MainConfig mainConfig = MainConfig_true);
-
- A_DELETE_COPY(SetupItemDropDownStr)
-
- ~SetupItemDropDownStr();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- int selectionByValue();
-
- protected:
- HorizontContainer *mHorizont;
- Label *mLabel;
- ListModel *mModel;
- DropDown *mDropDown;
- int mWidth;
-};
-
-class SetupItemSlider final : public SetupItem
-{
- public:
- SetupItemSlider(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const double min,
- const double max,
- const double step,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig);
-
- SetupItemSlider(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const double min,
- const double max,
- const double step,
- const std::string &restrict def,
- const int width,
- const OnTheFly onTheFly,
- const MainConfig mainConfig);
-
- A_DELETE_COPY(SetupItemSlider)
-
- ~SetupItemSlider();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- void action(const ActionEvent &event) override final;
-
- void apply(const std::string &eventName) override final;
-
- void updateLabel();
-
- protected:
- HorizontContainer *mHorizont;
- Label *mLabel;
- Slider *mSlider;
- double mMin;
- double mMax;
- double mStep;
- int mWidth;
- OnTheFly mOnTheFly;
-};
-
-typedef STD_VECTOR<std::string> SetupItemNames;
-typedef SetupItemNames::iterator SetupItemNamesIter;
-typedef SetupItemNames::const_iterator SetupItemNamesConstIter;
-
-class SetupItemSlider2 final : public SetupItem
-{
- public:
- SetupItemSlider2(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const int min, const int max, const int step,
- SetupItemNames *restrict const values,
- const OnTheFly onTheFly,
- const MainConfig mainConfig,
- const DoNotAlign doNotAlign);
-
- SetupItemSlider2(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const int min, const int max, const int step,
- SetupItemNames *restrict const values,
- const std::string &restrict def,
- const OnTheFly onTheFly,
- const MainConfig mainConfig,
- const DoNotAlign doNotAlign);
-
- A_DELETE_COPY(SetupItemSlider2)
-
- ~SetupItemSlider2();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- void action(const ActionEvent &event) override final;
-
- void apply(const std::string &eventName) override final;
-
- void setInvertValue(const int v);
-
- protected:
- void updateLabel();
-
- int getMaxWidth();
-
- HorizontContainer *mHorizont;
- Label *mLabel;
- Label *mLabel2;
- Slider *mSlider;
- SetupItemNames *mValues;
- int mMin;
- int mMax;
- int mStep;
- int mInvertValue;
- bool mInvert;
- OnTheFly mOnTheFly;
- DoNotAlign mDoNotAlign;
-};
-
-class SetupItemSliderList notfinal : public SetupItem
-{
- public:
- A_DELETE_COPY(SetupItemSliderList)
-
- virtual ~SetupItemSliderList();
-
- void createControls();
-
- void fromWidget() override;
-
- void toWidget() override;
-
- void action(const ActionEvent &event) override;
-
- void apply(const std::string &eventName) override final;
-
- virtual void addMoreControls() = 0;
-
- protected:
- SetupItemSliderList(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width = 150,
- const OnTheFly onTheFly = OnTheFly_false,
- const MainConfig mainConfig = MainConfig_true);
-
- SetupItemSliderList(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const std::string &restrict def,
- const int width = 150,
- const OnTheFly onTheFly = OnTheFly_false,
- const MainConfig mainConfig = MainConfig_true);
-
- HorizontContainer *mHorizont;
- Label *mLabel;
- SliderList *mSlider;
- ListModel *mModel;
- int mWidth;
- OnTheFly mOnTheFly;
-};
-
-class SetupItemSound final : public SetupItemSliderList
-{
- public:
- SetupItemSound(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int width = 150,
- const OnTheFly onTheFly = OnTheFly_false,
- const MainConfig mainConfig = MainConfig_true);
-
- A_DELETE_COPY(SetupItemSound)
-
- void action(const ActionEvent &event) override final;
-
- void addMoreControls() override final;
-
- protected:
- Button *mButton;
-};
-
-class SetupItemSliderInt final : public SetupItemSliderList
-{
- public:
- SetupItemSliderInt(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ListModel *restrict const model,
- const int min,
- const int width = 150,
- const OnTheFly onTheFly = OnTheFly_false,
- const MainConfig mainConfig = MainConfig_true);
-
- A_DELETE_COPY(SetupItemSliderInt)
-
- void addMoreControls() override final;
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- protected:
- int mMin;
-};
-
-#endif // GUI_WIDGETS_SETUPITEM_H
diff --git a/src/gui/widgets/setupquickitem.cpp b/src/gui/widgets/setupquickitem.cpp
deleted file mode 100644
index 238a8a213..000000000
--- a/src/gui/widgets/setupquickitem.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/setupquickitem.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/horizontcontainer.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/vertcontainer.h"
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-#include "debug.h"
-
-SetupQuickItem::SetupQuickItem(const std::string &restrict description,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- const ModifierGetFuncPtr getFunc,
- const ModifierChangeFuncPtr changeFunc) :
- SetupItem("", description, "", parent, eventName, MainConfig_false),
- GameModifierListener(),
- mHorizont(nullptr),
- mButton(nullptr),
- mLabel(nullptr),
- mGetFunc(getFunc),
- mChangeFunc(changeFunc)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupQuickItem::~SetupQuickItem()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mButton = nullptr;
-}
-
-void SetupQuickItem::save()
-{
-}
-
-void SetupQuickItem::cancel(const std::string &eventName A_UNUSED)
-{
-}
-
-void SetupQuickItem::externalUpdated(const std::string &eventName A_UNUSED)
-{
-}
-
-void SetupQuickItem::rereadValue()
-{
-}
-
-void SetupQuickItem::createControls()
-{
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mWidget = new Button(this, ">", mEventName + "_CHANGE", nullptr);
- mLabel = new Label(this, std::string());
- mLabel->setToolTip(mDescription);
- mLabel->adjustSize();
-
- mHorizont->add(mWidget, 5);
- mHorizont->add(mLabel);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mWidget->addActionListener(this);
- toWidget();
-}
-
-void SetupQuickItem::fromWidget()
-{
-}
-
-void SetupQuickItem::toWidget()
-{
- mLabel->setCaption(mGetFunc());
- mLabel->adjustSize();
-}
-
-void SetupQuickItem::action(const ActionEvent &event)
-{
- if (event.getId() == mEventName + "_CHANGE")
- {
- // need change game modifier
- mChangeFunc(true);
- toWidget();
- }
-}
-
-void SetupQuickItem::apply(const std::string &eventName A_UNUSED)
-{
-}
-
-void SetupQuickItem::gameModifiersChanged()
-{
- toWidget();
-}
diff --git a/src/gui/widgets/setupquickitem.h b/src/gui/widgets/setupquickitem.h
deleted file mode 100644
index 24a9507a4..000000000
--- a/src/gui/widgets/setupquickitem.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SETUPQUICKITEM_H
-#define GUI_WIDGETS_SETUPQUICKITEM_H
-
-#include "gui/widgets/setupitem.h"
-
-#include "listeners/gamemodifierlistener.h"
-
-class Button;
-class HorizontContainer;
-class Label;
-class SetupTabScroll;
-
-typedef std::string (*ModifierGetFuncPtr)();
-typedef void (*ModifierChangeFuncPtr)(const bool forward);
-
-class SetupQuickItem final : public SetupItem,
- public GameModifierListener
-{
- public:
- SetupQuickItem(const std::string &restrict description,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- ModifierGetFuncPtr getFunc,
- ModifierChangeFuncPtr changeFunc);
-
- A_DELETE_COPY(SetupQuickItem)
-
- ~SetupQuickItem();
-
- void createControls();
-
- void fromWidget() override final A_CONST;
-
- void toWidget() override final;
-
- void action(const ActionEvent &event) override final;
-
- void apply(const std::string &eventName) override final A_CONST;
-
- void cancel(const std::string &eventName A_UNUSED) override final
- A_CONST;
-
- void externalUpdated(const std::string &eventName A_UNUSED)
- override final A_CONST;
-
- void rereadValue() override final A_CONST;
-
- void save() override final A_CONST;
-
- void gameModifiersChanged() override final;
-
- protected:
- HorizontContainer *mHorizont;
- Button *mButton;
- Label *mLabel;
- ModifierGetFuncPtr mGetFunc;
- ModifierChangeFuncPtr mChangeFunc;
-};
-
-#endif // GUI_WIDGETS_SETUPQUICKITEM_H
diff --git a/src/gui/widgets/setuptouchitem.cpp b/src/gui/widgets/setuptouchitem.cpp
deleted file mode 100644
index 122853c7e..000000000
--- a/src/gui/widgets/setuptouchitem.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/setuptouchitem.h"
-
-#include "gui/models/touchactionmodel.h"
-
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/horizontcontainer.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/vertcontainer.h"
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-SetupActionDropDown::SetupActionDropDown(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- TouchActionsModel *restrict
- const model,
- const int width,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mModel(model),
- mDropDown(nullptr),
- mWidth(width)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupActionDropDown::SetupActionDropDown(const std::string &restrict text,
- const std::string &restrict
- description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- TouchActionsModel *restrict
- const model,
- const int width,
- const std::string &restrict def,
- const MainConfig mainConfig) :
- SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
- mHorizont(nullptr),
- mLabel(nullptr),
- mModel(model),
- mDropDown(nullptr),
- mWidth(width)
-{
- mValueType = VSTR;
- createControls();
-}
-
-SetupActionDropDown::~SetupActionDropDown()
-{
- mHorizont = nullptr;
- mWidget = nullptr;
- mModel = nullptr;
- mDropDown = nullptr;
- mLabel = nullptr;
-}
-
-void SetupActionDropDown::createControls()
-{
- if (mModel == nullptr)
- return;
-
- load();
- mHorizont = new HorizontContainer(this, 32, 2);
-
- mLabel = new Label(this, mText);
- mLabel->setToolTip(mDescription);
- mDropDown = new DropDown(this, mModel);
- mDropDown->setActionEventId(mEventName);
- mDropDown->addActionListener(mParent);
- mDropDown->setWidth(mWidth);
- mDropDown->setSelected(mModel->getSelectionFromAction(
- static_cast<InputActionT>(atoi(mValue.c_str()))));
-
- mWidget = mDropDown;
- fixFirstItemSize(mLabel);
- mHorizont->add(mLabel);
- mHorizont->add(mDropDown);
-
- mParent->getContainer()->add2(mHorizont, true, 4);
- mParent->addControl(this);
- mParent->addActionListener(this);
- mWidget->addActionListener(this);
-}
-
-void SetupActionDropDown::fromWidget()
-{
- if ((mDropDown == nullptr) || (mModel == nullptr))
- return;
-
- mValue = toString(CAST_S32(mModel->getActionFromSelection(
- mDropDown->getSelected())));
-}
-
-void SetupActionDropDown::toWidget()
-{
- if ((mDropDown == nullptr) || (mModel == nullptr))
- return;
-
- mDropDown->setSelected(mModel->getSelectionFromAction(
- static_cast<InputActionT>(atoi(mValue.c_str()))));
-}
diff --git a/src/gui/widgets/setuptouchitem.h b/src/gui/widgets/setuptouchitem.h
deleted file mode 100644
index 55521b684..000000000
--- a/src/gui/widgets/setuptouchitem.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SETUPTOUCHITEM_H
-#define GUI_WIDGETS_SETUPTOUCHITEM_H
-
-#include "gui/widgets/setupitem.h"
-
-class TouchActionsModel;
-
-class SetupActionDropDown final : public SetupItem
-{
- public:
- SetupActionDropDown(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- TouchActionsModel *restrict const model,
- const int width,
- const MainConfig mainConfig = MainConfig_true);
-
- SetupActionDropDown(const std::string &restrict text,
- const std::string &restrict description,
- const std::string &restrict keyName,
- SetupTabScroll *restrict const parent,
- const std::string &restrict eventName,
- TouchActionsModel *restrict const model,
- const int width, const std::string &def,
- const MainConfig mainConfig = MainConfig_true);
-
- A_DELETE_COPY(SetupActionDropDown)
-
- ~SetupActionDropDown();
-
- void createControls();
-
- void fromWidget() override final;
-
- void toWidget() override final;
-
- protected:
- HorizontContainer *mHorizont;
- Label *mLabel;
- TouchActionsModel *mModel;
- DropDown *mDropDown;
- int mWidth;
-};
-
-#endif // GUI_WIDGETS_SETUPTOUCHITEM_H
diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp
deleted file mode 100644
index 3df46b854..000000000
--- a/src/gui/widgets/shoplistbox.cpp
+++ /dev/null
@@ -1,310 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/shoplistbox.h"
-
-#include "dragdrop.h"
-#include "settings.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/popups/itempopup.h"
-#include "gui/popups/popupmenu.h"
-
-#include "gui/models/shopitems.h"
-
-#include "gui/windows/itemamountwindow.h"
-
-#include "net/net.h"
-
-#include "resources/inventory/inventory.h"
-
-#include "resources/item/shopitem.h"
-
-#include "debug.h"
-
-const int ITEM_ICON_SIZE = 32;
-
-ShopListBox::ShopListBox(const Widget2 *const widget,
- ListModel *const listModel,
- const ShopListBoxTypeT type) :
- ListBox(widget, listModel, "shoplistbox.xml"),
- mPlayerMoney(0),
- mShopItems(nullptr),
- mWarningColor(getThemeColor(ThemeColorId::SHOP_WARNING)),
- mType(type),
- mPriceCheck(true),
- mProtectItems(false)
-{
- mRowHeight = getFont()->getHeight();
- mHighlightColor = getThemeColor(ThemeColorId::HIGHLIGHT);
- mForegroundColor = getThemeColor(ThemeColorId::LISTBOX);
- mBackgroundColor = getThemeColor(ThemeColorId::BACKGROUND);
-}
-
-ShopListBox::ShopListBox(const Widget2 *const widget,
- ListModel *const listModel,
- ShopItems *const shopListModel,
- const ShopListBoxTypeT type) :
- ListBox(widget, listModel, "shoplistbox.xml"),
- mPlayerMoney(0),
- mShopItems(shopListModel),
- mWarningColor(getThemeColor(ThemeColorId::SHOP_WARNING)),
- mType(type),
- mPriceCheck(true),
- mProtectItems(false)
-{
- mRowHeight = std::max(getFont()->getHeight(), ITEM_ICON_SIZE);
- mHighlightColor = getThemeColor(ThemeColorId::HIGHLIGHT);
- mForegroundColor = getThemeColor(ThemeColorId::LISTBOX);
- mBackgroundColor = getThemeColor(ThemeColorId::BACKGROUND);
-}
-
-void ShopListBox::setPlayersMoney(const int money)
-{
- mPlayerMoney = money;
-}
-
-void ShopListBox::draw(Graphics *const graphics)
-{
- BLOCK_START("ShopListBox::draw")
- if ((mListModel == nullptr) || (mShopItems == nullptr))
- {
- BLOCK_END("ShopListBox::draw")
- return;
- }
-
- if (settings.guiAlpha != mAlpha)
- mAlpha = settings.guiAlpha;
-
- const unsigned int alpha = CAST_U32(mAlpha * 255.0F);
- Font *const font = getFont();
-
- const int sz = mListModel->getNumberOfElements();
- const int fontHeigh = getFont()->getHeight();
- const int width = mDimension.width - 2 * mPadding;
- // Draw the list elements
- for (int i = 0, y = 0;
- i < sz;
- ++i, y += mRowHeight)
- {
- bool needDraw(false);
- Color temp;
- Color* backgroundColor = &mBackgroundColor;
-
- ShopItem *const item = mShopItems->at(i);
- if ((item != nullptr) &&
- (item->getDisabled() ||
- (mPlayerMoney < item->getPrice() && mPriceCheck) ||
- (mProtectItems && PlayerInfo::isItemProtected(item->getId()))))
- {
- if (i != mSelected)
- {
- backgroundColor = &mWarningColor;
- backgroundColor->a = alpha;
- }
- else
- {
- temp = mWarningColor;
- temp.r = (temp.r + mHighlightColor.r) / 2;
- temp.g = (temp.g + mHighlightColor.g) / 2;
- temp.b = (temp.b + mHighlightColor.b) / 2;
- temp.a = alpha;
- backgroundColor = &temp;
- }
- needDraw = true;
- }
- else if (i == mSelected)
- {
- mHighlightColor.a = alpha;
- backgroundColor = &mHighlightColor;
- needDraw = true;
- }
- else
- {
- mBackgroundColor.a = alpha;
- }
-
- if (needDraw)
- {
- graphics->setColor(*backgroundColor);
- graphics->fillRectangle(Rect(mPadding, y + mPadding,
- width, mRowHeight));
- }
-
- if ((mShopItems != nullptr) && (item != nullptr))
- {
- Image *const icon = item->getImage();
- if (icon != nullptr)
- {
- icon->setAlpha(1.0F);
- graphics->drawImage(icon, mPadding, y + mPadding);
- }
- }
- if (mSelected == i)
- {
- font->drawString(graphics,
- mForegroundSelectedColor,
- mForegroundSelectedColor2,
- mListModel->getElementAt(i),
- ITEM_ICON_SIZE + mPadding,
- y + (ITEM_ICON_SIZE - fontHeigh) / 2 + mPadding);
- }
- else
- {
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- mListModel->getElementAt(i),
- ITEM_ICON_SIZE + mPadding,
- y + (ITEM_ICON_SIZE - fontHeigh) / 2 + mPadding);
- }
- }
- BLOCK_END("ShopListBox::draw")
-}
-
-void ShopListBox::safeDraw(Graphics *const graphics)
-{
- ShopListBox::draw(graphics);
-}
-
-void ShopListBox::adjustSize()
-{
- BLOCK_START("ShopListBox::adjustSize")
- if (mListModel != nullptr)
- {
- setHeight(mRowHeight * mListModel->getNumberOfElements()
- + 2 * mPadding);
- }
- BLOCK_END("ShopListBox::adjustSize")
-}
-
-void ShopListBox::setPriceCheck(const bool check)
-{
- mPriceCheck = check;
-}
-
-void ShopListBox::mouseMoved(MouseEvent &event)
-{
- if ((itemPopup == nullptr) || (mRowHeight == 0u))
- return;
-
- if (mShopItems == nullptr)
- {
- itemPopup->hide();
- return;
- }
-
- const int index = (event.getY() - mPadding) / mRowHeight;
-
- if (index < 0 || index >= mShopItems->getNumberOfElements())
- {
- itemPopup->hide();
- }
- else
- {
- const Item *const item = mShopItems->at(index);
- if (item != nullptr)
- {
- itemPopup->setItem(item, false);
- itemPopup->position(viewport->mMouseX, viewport->mMouseY);
- }
- else
- {
- itemPopup->setVisible(Visible_false);
- }
- }
-}
-
-void ShopListBox::mouseReleased(MouseEvent& event)
-{
- ListBox::mouseReleased(event);
- if (event.getType() == MouseEventType::RELEASED2)
- {
- if (dragDrop.isEmpty())
- return;
- const DragDropSourceT src = dragDrop.getSource();
- if (mType != ShopListBoxType::SellShop &&
- mType != ShopListBoxType::BuyShop)
- {
- return;
- }
- if (mType == ShopListBoxType::SellShop &&
- Net::getNetworkType() != ServerType::TMWATHENA &&
- src != DragDropSource::Cart)
- {
- return;
- }
- Inventory *inventory;
- if (src == DragDropSource::Inventory)
- inventory = PlayerInfo::getInventory();
- else if (src == DragDropSource::Cart)
- inventory = PlayerInfo::getCartInventory();
- else
- return;
- if (inventory == nullptr)
- return;
- Item *const item = inventory->getItem(dragDrop.getTag());
- if (mType == ShopListBoxType::BuyShop)
- {
- ItemAmountWindow::showWindow(
- ItemAmountWindowUsage::ShopBuyAdd,
- nullptr,
- item);
- }
- else
- {
- ItemAmountWindow::showWindow(
- ItemAmountWindowUsage::ShopSellAdd,
- nullptr,
- item);
- }
- }
-
- if (event.getButton() == MouseButton::RIGHT)
- {
- setSelected(std::max(0, getSelectionByMouse(event.getY())));
-
- if (mSelected < 0 || mSelected >= mShopItems->getNumberOfElements())
- return;
-
- Item *const item = mShopItems->at(mSelected);
- if ((popupMenu != nullptr) && (viewport != nullptr))
- {
- popupMenu->showItemPopup(viewport->mMouseX,
- viewport->mMouseY,
- item);
- }
- }
-}
-
-void ShopListBox::mouseExited(MouseEvent& event A_UNUSED)
-{
- if (itemPopup == nullptr)
- return;
-
- itemPopup->hide();
-}
diff --git a/src/gui/widgets/shoplistbox.h b/src/gui/widgets/shoplistbox.h
deleted file mode 100644
index 2e79d16bb..000000000
--- a/src/gui/widgets/shoplistbox.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SHOPLISTBOX_H
-#define GUI_WIDGETS_SHOPLISTBOX_H
-
-#include "gui/widgets/listbox.h"
-
-#include "enums/gui/shoplistboxtype.h"
-
-class ShopItems;
-
-/**
- * A list box, meant to be used inside a scroll area. Same as the Guichan list
- * box except this one doesn't have a background, instead completely relying
- * on the scroll area. It also adds selection listener functionality.
- *
- * \ingroup GUI
- */
-class ShopListBox final : public ListBox
-{
- public:
- /**
- * Constructor.
- */
- ShopListBox(const Widget2 *const widget,
- ListModel *const listModel,
- const ShopListBoxTypeT type);
-
- /**
- * Constructor with shopitems
- */
- ShopListBox(const Widget2 *const widget,
- ListModel *const listModel,
- ShopItems *const shopListModel,
- const ShopListBoxTypeT type);
-
- A_DELETE_COPY(ShopListBox)
-
- /**
- * Draws the list box.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * gives information about the current player's money
- */
- void setPlayersMoney(const int money);
-
- /**
- * Adjust List draw size
- */
- void adjustSize() override final;
-
- /**
- * Set on/off the disabling of too expensive items.
- * (Good for selling mode.)
- */
- void setPriceCheck(const bool check);
-
- void mouseMoved(MouseEvent &event) override final;
-
- void mouseReleased(MouseEvent& event) override final;
-
- void mouseExited(MouseEvent& event) override final;
-
- void setProtectItems(bool p)
- { mProtectItems = p; }
-
- void setType(const ShopListBoxTypeT type)
- { mType = type; }
-
- ShopListBoxTypeT getType() const
- { return mType; }
-
- private:
- int mPlayerMoney;
-
- /**
- * Keeps another pointer to the same listModel, permitting to
- * use the ShopItems specific functions.
- */
- ShopItems *mShopItems;
-
- Color mWarningColor;
- ShopListBoxTypeT mType;
-
- bool mPriceCheck;
- bool mProtectItems;
-};
-
-#endif // GUI_WIDGETS_SHOPLISTBOX_H
diff --git a/src/gui/widgets/shortcutcontainer.cpp b/src/gui/widgets/shortcutcontainer.cpp
deleted file mode 100644
index a2b90514d..000000000
--- a/src/gui/widgets/shortcutcontainer.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/shortcutcontainer.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-
-#include "utils/delete2.h"
-
-#include "resources/image/image.h"
-
-#include "render/graphics.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "debug.h"
-
-float ShortcutContainer::mAlpha = 1.0;
-
-ShortcutContainer::ShortcutContainer(Widget2 *const widget) :
- Widget(widget),
- WidgetListener(),
- MouseListener(),
- mBackgroundImg(nullptr),
- mMaxItems(0),
- mBoxWidth(1),
- mBoxHeight(1),
- mGridWidth(1),
- mGridHeight(1),
- mVertexes(new ImageCollection)
-{
- mAllowLogic = false;
-
- addMouseListener(this);
- addWidgetListener(this);
-
- mForegroundColor = getThemeColor(ThemeColorId::TEXT);
- mForegroundColor2 = getThemeColor(ThemeColorId::TEXT_OUTLINE);
-
- mBackgroundImg = Theme::getImageFromThemeXml(
- "item_shortcut_background.xml", "background.xml");
-
- if (mBackgroundImg != nullptr)
- {
- mBackgroundImg->setAlpha(settings.guiAlpha);
- mBoxHeight = mBackgroundImg->getHeight();
- mBoxWidth = mBackgroundImg->getWidth();
- }
- else
- {
- mBoxHeight = 1;
- mBoxWidth = 1;
- }
-}
-
-ShortcutContainer::~ShortcutContainer()
-{
- if (mBackgroundImg != nullptr)
- {
- mBackgroundImg->decRef();
- mBackgroundImg = nullptr;
- }
-
- if (gui != nullptr)
- gui->removeDragged(this);
-
- delete2(mVertexes);
-}
-
-void ShortcutContainer::widgetResized(const Event &event A_UNUSED)
-{
- mGridWidth = mDimension.width / mBoxWidth;
-
- if (mGridWidth < 1)
- mGridWidth = 1;
-
- mGridHeight = mMaxItems / CAST_U32(mGridWidth);
-
- if (mMaxItems % mGridWidth != 0 || mGridHeight < 1)
- ++mGridHeight;
-
- setHeight(mGridHeight * mBoxHeight);
- mRedraw = true;
-}
-
-int ShortcutContainer::getIndexFromGrid(const int pointX,
- const int pointY) const
-{
- const Rect tRect = Rect(0, 0,
- mGridWidth * mBoxWidth, mGridHeight * mBoxHeight);
-
- int index = ((pointY / mBoxHeight) * mGridWidth) + pointX / mBoxWidth;
-
- if (!tRect.isPointInRect(pointX, pointY) ||
- index >= CAST_S32(mMaxItems) || index < 0)
- {
- index = -1;
- }
-
- return index;
-}
-
-void ShortcutContainer::drawBackground(Graphics *const g)
-{
- if (mBackgroundImg != nullptr)
- {
- if (mRedraw)
- {
- mRedraw = false;
- mVertexes->clear();
- for (unsigned i = 0; i < mMaxItems; i ++)
- {
- g->calcTileCollection(mVertexes, mBackgroundImg,
- (i % mGridWidth) * mBoxWidth,
- (i / mGridWidth) * mBoxHeight);
- }
- g->finalize(mVertexes);
- }
- g->drawTileCollection(mVertexes);
- }
-}
-
-void ShortcutContainer::safeDrawBackground(Graphics *const g)
-{
- if (mBackgroundImg != nullptr)
- {
- for (unsigned i = 0; i < mMaxItems; i ++)
- {
- g->drawImage(mBackgroundImg, (i % mGridWidth) * mBoxWidth,
- (i / mGridWidth) * mBoxHeight);
- }
- }
-}
-
-void ShortcutContainer::widgetMoved(const Event& event A_UNUSED)
-{
- mRedraw = true;
-}
diff --git a/src/gui/widgets/shortcutcontainer.h b/src/gui/widgets/shortcutcontainer.h
deleted file mode 100644
index b7076dfc2..000000000
--- a/src/gui/widgets/shortcutcontainer.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SHORTCUTCONTAINER_H
-#define GUI_WIDGETS_SHORTCUTCONTAINER_H
-
-#include "gui/widgets/widget.h"
-
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-class Image;
-class ImageCollection;
-
-/**
- * A generic shortcut container.
- *
- * \ingroup GUI
- */
-class ShortcutContainer notfinal : public Widget,
- public WidgetListener,
- public MouseListener
-{
- public:
- A_DELETE_COPY(ShortcutContainer)
-
- /**
- * Destructor.
- */
- virtual ~ShortcutContainer();
-
- /**
- * Invoked when a widget changes its size. This is used to determine
- * the new height of the container.
- */
- void widgetResized(const Event &event) override final;
-
- void widgetMoved(const Event& event) override final;
-
- /**
- * Handles mouse when dragged.
- */
- void mouseDragged(MouseEvent &event A_UNUSED) override
- {
- }
-
- /**
- * Handles mouse when pressed.
- */
- void mousePressed(MouseEvent &event A_UNUSED) override
- {
- }
-
- /**
- * Handles mouse release.
- */
- void mouseReleased(MouseEvent &event A_UNUSED) override
- {
- }
-
- int getMaxItems() const noexcept2 A_WARN_UNUSED
- { return mMaxItems; }
-
- int getBoxWidth() const noexcept2 A_WARN_UNUSED
- { return mBoxWidth; }
-
- int getBoxHeight() const noexcept2 A_WARN_UNUSED
- { return mBoxHeight; }
-
- void drawBackground(Graphics *const g) A_NONNULL(2);
-
- void safeDrawBackground(Graphics *const g) A_NONNULL(2);
-
- protected:
- /**
- * Constructor. Initializes the shortcut container.
- */
- explicit ShortcutContainer(Widget2 *const widget);
-
- /**
- * Gets the index from the grid provided the point is in an item box.
- *
- * @param pointX X coordinate of the point.
- * @param pointY Y coordinate of the point.
- * @return index on success, -1 on failure.
- */
- int getIndexFromGrid(const int pointX,
- const int pointY) const A_WARN_UNUSED;
-
- Image *mBackgroundImg;
- static float mAlpha;
-
- unsigned mMaxItems;
- int mBoxWidth;
- int mBoxHeight;
- int mGridWidth;
- int mGridHeight;
- ImageCollection *mVertexes;
-};
-
-#endif // GUI_WIDGETS_SHORTCUTCONTAINER_H
diff --git a/src/gui/widgets/skilllistbox.h b/src/gui/widgets/skilllistbox.h
deleted file mode 100644
index 4f7e2a61b..000000000
--- a/src/gui/widgets/skilllistbox.h
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SKILLLISTBOX_H
-#define GUI_WIDGETS_SKILLLISTBOX_H
-
-#include "const/resources/skill.h"
-
-#include "dragdrop.h"
-
-#include "gui/skin.h"
-#include "gui/viewport.h"
-
-#include "gui/widgets/listbox.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/skillmodel.h"
-
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/skillpopup.h"
-
-#include "utils/delete2.h"
-
-#include "render/graphics.h"
-
-#include "localconsts.h"
-
-class SkillModel;
-
-class SkillListBox final : public ListBox
-{
- public:
- SkillListBox(const Widget2 *const widget,
- SkillModel *const model) :
- ListBox(widget, model, "skilllistbox.xml"),
- mModel(model),
- mTextColor(getThemeColor(ThemeColorId::TEXT)),
- mTextColor2(getThemeColor(ThemeColorId::TEXT_OUTLINE)),
- mCooldownColor(getThemeColor(ThemeColorId::SKILL_COOLDOWN)),
- mTextPadding(mSkin != nullptr ?
- mSkin->getOption("textPadding", 34) : 34),
- mSpacing(mSkin != nullptr ? mSkin->getOption("spacing", 0) : 0),
- mSkillClicked(false)
- {
- mRowHeight = getFont()->getHeight() * 2 + mSpacing + 2 * mPadding;
- mHighlightColor = getThemeColor(ThemeColorId::HIGHLIGHT);
-
- if (mRowHeight < 34)
- mRowHeight = 34;
- }
-
- A_DELETE_COPY(SkillListBox)
-
- ~SkillListBox()
- {
- delete2(mModel)
- }
-
- SkillInfo *getSelectedInfo() const
- {
- const int selected = getSelected();
- if ((mListModel == nullptr) || selected < 0
- || selected > mListModel->getNumberOfElements())
- {
- return nullptr;
- }
-
- return static_cast<SkillModel*>(mListModel)->getSkillAt(selected);
- }
-
- void draw(Graphics *const graphics) override final A_NONNULL(2)
- {
- if (mListModel == nullptr)
- return;
-
- SkillModel *const model = static_cast<SkillModel*>(mListModel);
- updateAlpha();
-
- mHighlightColor.a = CAST_S32(mAlpha * 255.0F);
- graphics->setColor(mHighlightColor);
-
- const int width1 = getWidth();
- const int usableWidth = width1 - 2 * mPadding;
-
- // Draw filled rectangle around the selected list element
- if (mSelected >= 0)
- {
- graphics->fillRectangle(Rect(mPadding, getRowHeight()
- * mSelected + mPadding, usableWidth,
- getRowHeight()));
- }
-
- // Draw the list elements
- Font *const font = getFont();
- const int space = font->getHeight() + mSpacing;
- const int width2 = width1 - mPadding;
-
- graphics->setColor(mCooldownColor);
- for (int i = 0, y = 1 + mPadding;
- i < model->getNumberOfElements();
- ++i, y += getRowHeight())
- {
- SkillInfo *const e = model->getSkillAt(i);
- if (e != nullptr)
- {
- if (e->cooldown != 0)
- {
- graphics->fillRectangle(Rect(mPadding, y,
- usableWidth * 100 / e->cooldown, 10));
- }
- }
- }
-
- for (int i = 0, y = 1 + mPadding;
- i < model->getNumberOfElements();
- ++i, y += getRowHeight())
- {
- SkillInfo *const e = model->getSkillAt(i);
- if (e != nullptr)
- {
- const SkillData *const data = e->data;
- const std::string &description = data->description;
- graphics->drawImage(data->icon, mPadding, y);
- font->drawString(graphics,
- mTextColor,
- mTextColor2,
- data->name,
- mTextPadding, y);
- if (!description.empty())
- {
- font->drawString(graphics,
- mTextColor,
- mTextColor2,
- description,
- mTextPadding,
- y + space);
- }
-
- if (e->skillLevelWidth < 0)
- {
- // Add one for padding
- e->skillLevelWidth = font->getWidth(e->skillLevel) + 1;
- }
-
- font->drawString(graphics,
- mTextColor,
- mTextColor2,
- e->skillLevel,
- width2 - e->skillLevelWidth,
- y);
- }
- }
- }
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2)
- {
- SkillListBox::draw(graphics);
- }
-
- unsigned int getRowHeight() const override final
- { return mRowHeight; }
-
- const SkillInfo *getSkillByEvent(const MouseEvent &event) const
- {
- const int y = (event.getY() + mPadding) / getRowHeight();
- if (mModel == nullptr || y >= mModel->getNumberOfElements())
- return nullptr;
- const SkillInfo *const skill = mModel->getSkillAt(y);
- if (skill == nullptr)
- return nullptr;
- return skill;
- }
-
- void mouseMoved(MouseEvent &event) override final
- {
- ListBox::mouseMoved(event);
- if ((viewport == nullptr) || !dragDrop.isEmpty())
- return;
-
- const SkillInfo *const skill = getSkillByEvent(event);
- if (skill == nullptr)
- return;
- skillPopup->show(skill,
- skill->customSelectedLevel,
- skill->customCastType,
- skill->customOffsetX,
- skill->customOffsetY);
- skillPopup->position(viewport->mMouseX,
- viewport->mMouseY);
- }
-
- void mouseDragged(MouseEvent &event) override final
- {
- if (event.getButton() == MouseButton::LEFT)
- {
- if (dragDrop.isEmpty())
- {
- if (mSkillClicked)
- {
- mSkillClicked = false;
- const SkillInfo *const skill = getSkillByEvent(event);
- if (skill == nullptr)
- return;
- dragDrop.dragSkill(skill, DragDropSource::Skills);
- dragDrop.setItem(skill->id + SKILL_MIN_ID);
- dragDrop.setItemData(skill->toDataStr());
- }
- ListBox::mouseDragged(event);
- }
- }
- else
- {
- ListBox::mouseDragged(event);
- }
- }
-
- void mousePressed(MouseEvent &event) override final
- {
- ListBox::mousePressed(event);
- const MouseButtonT button = event.getButton();
- if (button == MouseButton::LEFT ||
- button == MouseButton::RIGHT)
- {
- const SkillInfo *const skill = getSkillByEvent(event);
- if (skill == nullptr)
- return;
- event.consume();
- mSkillClicked = true;
- SkillModel *const model = static_cast<SkillModel*>(
- mListModel);
- if ((model != nullptr) &&
- mSelected >= 0 &&
- model->getSkillAt(mSelected) == skill)
- {
- skillPopup->hide();
- if (button == MouseButton::LEFT &&
- event.getX() >
- getWidth() - mPadding - skill->skillLevelWidth)
- {
- popupMenu->showSkillLevelPopup(skill);
- }
- else if (button == MouseButton::RIGHT)
- {
- popupMenu->showSkillPopup(skill);
- }
- }
- }
- }
-
- void mouseReleased(MouseEvent &event) override final
- {
- ListBox::mouseReleased(event);
- }
-
- void mouseExited(MouseEvent &event A_UNUSED) override final
- {
- skillPopup->hide();
- }
-
- private:
- SkillModel *mModel;
- Color mTextColor;
- Color mTextColor2;
- Color mCooldownColor;
- int mTextPadding;
- int mSpacing;
- bool mSkillClicked;
-};
-
-#endif // GUI_WIDGETS_SKILLLISTBOX_H
diff --git a/src/gui/widgets/skillrectanglelistbox.h b/src/gui/widgets/skillrectanglelistbox.h
deleted file mode 100644
index a3139260c..000000000
--- a/src/gui/widgets/skillrectanglelistbox.h
+++ /dev/null
@@ -1,418 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SKILLRECTANGLELISTBOX_H
-#define GUI_WIDGETS_SKILLRECTANGLELISTBOX_H
-
-#include "const/resources/skill.h"
-
-#include "dragdrop.h"
-#include "settings.h"
-
-#include "gui/skin.h"
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/skillmodel.h"
-
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/skillpopup.h"
-
-#include "utils/delete2.h"
-
-#include "render/graphics.h"
-
-#include "localconsts.h"
-
-class SkillModel;
-
-class SkillRectangleListBox final : public Widget,
- public MouseListener
-{
- public:
- SkillRectangleListBox(const Widget2 *const widget,
- SkillModel *const model) :
- Widget(widget),
- MouseListener(),
- mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT)),
- mTextColor(getThemeColor(ThemeColorId::TEXT)),
- mTextColor2(getThemeColor(ThemeColorId::TEXT_OUTLINE)),
- mCooldownColor(getThemeColor(ThemeColorId::SKILL_COOLDOWN)),
- mForegroundSelectedColor(getThemeColor(
- ThemeColorId::LISTBOX_SELECTED)),
- mForegroundSelectedColor2(getThemeColor(
- ThemeColorId::LISTBOX_SELECTED_OUTLINE)),
- mModel(model),
- mSkin(nullptr),
- mSelected(-1),
- mPadding(2),
- mBoxWidth(80),
- mBoxHeight(70),
- mIconXOffset(24),
- mIconYOffset(10),
- mTextXOffset(0),
- mTextYOffset(44),
- mSkillClicked(false)
- {
- if (theme != nullptr)
- {
- mSkin = theme->load("skillrectanglelistbox.xml",
- "listbox.xml");
- }
-
- if (mSkin != nullptr)
- {
- mPadding = mSkin->getPadding();
- mBoxWidth = mSkin->getOption("boxWidth", 80);
- mBoxHeight = mSkin->getOption("boxHeight", 70);
- mIconXOffset = mSkin->getOption("iconXOffset", 24);
- mIconYOffset = mSkin->getOption("iconYOffset", 10);
- mTextXOffset = mSkin->getOption("textXOffset", 0);
- mTextYOffset = mSkin->getOption("textYOffset", 44);
- }
- Font *const font = getFont();
- int minWidth = font->getWidth("Lvl: 10/10") + mTextXOffset + 2;
- int minHeight = font->getHeight() + mTextYOffset + 2;
- if (mBoxWidth < minWidth)
- mBoxWidth = minWidth;
- if (mBoxHeight < minHeight)
- mBoxHeight = minHeight;
- int maxX = 0;
- int maxY = 0;
- for (int i = 0;
- i < model->getNumberOfElements();
- ++i)
- {
- SkillInfo *const e = model->getSkillAt(i);
- if (e != nullptr)
- {
- if (e->x > maxX)
- maxX = e->x;
- if (e->y > maxY)
- maxY = e->y;
- }
- }
- maxX ++;
- maxY ++;
- setWidth(maxX * mBoxWidth);
- setHeight(maxY * mBoxHeight);
- addMouseListener(this);
- }
-
- A_DELETE_COPY(SkillRectangleListBox)
-
- ~SkillRectangleListBox()
- {
- delete2(mModel)
- }
-
- SkillInfo *getSelectedInfo() const
- {
- if (mModel == nullptr)
- return nullptr;
- const int selected = mSelected;
- if (selected < 0 ||
- selected > mModel->getNumberOfElements())
- {
- return nullptr;
- }
-
- return mModel->getSkillAt(selected);
- }
-
- void draw(Graphics *const graphics) override final A_NONNULL(2)
- {
- if (mModel == nullptr)
- return;
-
- SkillModel *const model = mModel;
- updateAlpha();
-
- int maxX = 0;
- int maxY = 0;
- mHighlightColor.a = CAST_S32(mAlpha * 255.0F);
- graphics->setColor(mHighlightColor);
- Font *const font = getFont();
- if (mSelected >= 0)
- {
- SkillInfo *const e = model->getSkillAt(mSelected);
- if (e != nullptr)
- {
- const int x = e->x * mBoxWidth + mPadding;
- const int y = e->y * mBoxHeight + mPadding;
-
- graphics->fillRectangle(Rect(x, y,
- mBoxWidth, mBoxHeight));
-
- const int xOffset = (mBoxWidth -
- font->getWidth(e->skillLevel)) / 2;
- font->drawString(graphics,
- mForegroundSelectedColor,
- mForegroundSelectedColor,
- e->skillLevel,
- x + mTextXOffset + xOffset,
- y + mTextYOffset);
- }
- }
-
- // +++ need split drawing icons and text
- for (int i = 0;
- i < model->getNumberOfElements();
- ++i)
- {
- SkillInfo *const e = model->getSkillAt(i);
- if (e != nullptr)
- {
- if (e->x > maxX)
- maxX = e->x;
- if (e->y > maxY)
- maxY = e->y;
- const SkillData *const data = e->data;
- const int x = e->x * mBoxWidth + mPadding;
- const int y = e->y * mBoxHeight + mPadding;
-
- graphics->drawImage(data->icon,
- x + mIconXOffset,
- y + mIconYOffset);
-
- if (i != mSelected)
- {
- const int width1 = font->getWidth(e->skillLevel);
- const int xOffset = (mBoxWidth -
- width1) / 2;
- font->drawString(graphics,
- mTextColor,
- mTextColor2,
- e->skillLevel,
- x + mTextXOffset + xOffset,
- y + mTextYOffset);
- if (e->skillLevelWidth < 0)
- {
- // Add one for padding
- e->skillLevelWidth = width1 + 1;
- }
- }
- else
- {
- if (e->skillLevelWidth < 0)
- {
- // Add one for padding
- e->skillLevelWidth = font->getWidth(
- e->skillLevel) + 1;
- }
- }
- }
- }
- maxX ++;
- maxY ++;
- setWidth(maxX * mBoxWidth);
- setHeight(maxY * mBoxHeight);
- }
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2)
- {
- SkillRectangleListBox::draw(graphics);
- }
-
- const SkillInfo *getSkillByEvent(const MouseEvent &event) const
- {
- if (mModel == nullptr)
- return nullptr;
- const int posX = (event.getX() - mPadding) / mBoxWidth;
- const int posY = (event.getY() - mPadding) / mBoxHeight;
- for (int i = 0;
- i < mModel->getNumberOfElements();
- ++i)
- {
- SkillInfo *const e = mModel->getSkillAt(i);
- if (e != nullptr)
- {
- if (posX == e->x && posY == e->y)
- return e;
- }
- }
- return nullptr;
- }
-
- int getSelectionByEvent(const MouseEvent &event) const
- {
- if (mModel == nullptr)
- return -1;
- const int posX = (event.getX() - mPadding) / mBoxWidth;
- const int posY = (event.getY() - mPadding) / mBoxHeight;
- for (int i = 0;
- i < mModel->getNumberOfElements();
- ++i)
- {
- SkillInfo *const e = mModel->getSkillAt(i);
- if (e != nullptr)
- {
- if (posX == e->x && posY == e->y)
- return i;
- }
- }
- return -1;
- }
-
- void mouseMoved(MouseEvent &event) override final
- {
- if ((viewport == nullptr) || !dragDrop.isEmpty())
- return;
-
- const SkillInfo *const skill = getSkillByEvent(event);
- if (skill == nullptr)
- return;
- skillPopup->show(skill,
- skill->customSelectedLevel,
- skill->customCastType,
- skill->customOffsetX,
- skill->customOffsetY);
- skillPopup->position(viewport->mMouseX,
- viewport->mMouseY);
- }
-
- void mouseDragged(MouseEvent &event) override final
- {
- if (event.getButton() != MouseButton::LEFT)
- return;
- setSelected(std::max(0, getSelectionByEvent(event)));
-
- if (dragDrop.isEmpty())
- {
- if (mSkillClicked)
- {
- mSkillClicked = false;
- const SkillInfo *const skill = getSkillByEvent(event);
- if (skill == nullptr)
- return;
- dragDrop.dragSkill(skill, DragDropSource::Skills);
- dragDrop.setItem(skill->id + SKILL_MIN_ID);
- dragDrop.setItemData(skill->toDataStr());
- }
- }
- }
-
- void mousePressed(MouseEvent &event) override final
- {
- const MouseButtonT button = event.getButton();
- if (button == MouseButton::LEFT ||
- button == MouseButton::RIGHT)
- {
- const SkillInfo *const skill = getSkillByEvent(event);
- if (skill == nullptr)
- return;
- event.consume();
- mSkillClicked = true;
- SkillModel *const model = mModel;
- if ((model != nullptr) &&
- mSelected >= 0 &&
- model->getSkillAt(mSelected) == skill)
- {
- skillPopup->hide();
-
- const int x = skill->x * mBoxWidth + mPadding;
- const int y = skill->y * mBoxHeight + mPadding;
- Font *const font = getFont();
- const int height = font->getHeight();
- const int eventX = event.getX();
- const int eventY = event.getY() - mTextYOffset;
- if (button == MouseButton::LEFT)
- {
- if (eventX >= x + mTextXOffset &&
- eventX <= x + mBoxWidth - mTextXOffset &&
- eventY >= y &&
- eventY <= y + height)
- {
- popupMenu->showSkillLevelPopup(skill);
- }
- }
- else if (button == MouseButton::RIGHT)
- {
- popupMenu->showSkillPopup(skill);
- }
- }
- }
- }
-
- void mouseReleased(MouseEvent &event) override final
- {
- if (event.getButton() == MouseButton::LEFT)
- {
- setSelected(std::max(0, getSelectionByEvent(event)));
- distributeActionEvent();
- }
- }
-
- void mouseExited(MouseEvent &event A_UNUSED) override final
- {
- skillPopup->hide();
- }
-
- void updateAlpha()
- {
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (mAlpha != alpha)
- mAlpha = alpha;
- }
-
- void setSelected(const int selected)
- {
- if (mModel == nullptr)
- {
- mSelected = -1;
- }
- else
- {
- if (selected < 0)
- mSelected = -1;
- else if (selected >= mModel->getNumberOfElements())
- mSelected = mModel->getNumberOfElements() - 1;
- else
- mSelected = selected;
- }
- }
-
- private:
- Color mHighlightColor;
- Color mTextColor;
- Color mTextColor2;
- Color mCooldownColor;
- Color mForegroundSelectedColor;
- Color mForegroundSelectedColor2;
- SkillModel *mModel;
- Skin *mSkin;
- int mSelected;
- int mPadding;
- int mBoxWidth;
- int mBoxHeight;
- int mIconXOffset;
- int mIconYOffset;
- int mTextXOffset;
- int mTextYOffset;
- bool mSkillClicked;
- static float mAlpha;
-};
-
-float SkillRectangleListBox::mAlpha = 1.0;
-
-#endif // GUI_WIDGETS_SKILLRECTANGLELISTBOX_H
diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp
deleted file mode 100644
index 0d25ad2c5..000000000
--- a/src/gui/widgets/slider.cpp
+++ /dev/null
@@ -1,517 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/slider.h"
-
-#include "settings.h"
-
-#include "enums/gui/slidergrid.h"
-
-#include "gui/gui.h"
-
-#include "utils/delete2.h"
-
-#include "resources/imagerect.h"
-
-#include "resources/image/image.h"
-
-#include "render/graphics.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "debug.h"
-
-ImageRect Slider::buttons[2];
-float Slider::mAlpha = 1.0;
-int Slider::mInstances = 0;
-
-static std::string const data[2] =
-{
- "slider.xml",
- "slider_highlighted.xml"
-};
-
-Slider::Slider(Widget2 *const widget,
- const double scaleEnd,
- const double stepLength) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- mValue(0),
- mStepLength(stepLength),
- mScaleStart(0),
- mScaleEnd(scaleEnd),
- mOrientation(Orientation::HORIZONTAL),
- mVertexes(new ImageCollection),
- mMarkerLength(10),
- mHasMouse(false)
-{
- init();
-}
-
-Slider::Slider(Widget2 *const widget,
- const double scaleStart,
- const double scaleEnd,
- const double stepLength) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- mValue(scaleStart),
- mStepLength(stepLength),
- mScaleStart(scaleStart),
- mScaleEnd(scaleEnd),
- mOrientation(Orientation::HORIZONTAL),
- mVertexes(new ImageCollection),
- mMarkerLength(10),
- mHasMouse(false)
-{
- init();
-}
-
-Slider::~Slider()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- delete2(mVertexes);
- mInstances--;
- if (mInstances == 0)
- {
- for (int mode = 0; mode < 2; mode ++)
- Theme::unloadRect(buttons[mode]);
- }
-}
-
-void Slider::init()
-{
- mAllowLogic = false;
- setFocusable(true);
- setFrameSize(1);
-
- addMouseListener(this);
- addKeyListener(this);
-
- setFrameSize(0);
-
- // Load resources
- if (mInstances == 0)
- {
- if (theme != nullptr)
- {
- for (int mode = 0; mode < 2; mode ++)
- theme->loadRect(buttons[mode], data[mode], "slider.xml", 0, 8);
- }
- updateAlpha();
- }
-
- mInstances++;
-
- if (buttons[0].grid[SliderGrid::HGRIP] != nullptr)
- setMarkerLength(buttons[0].grid[SliderGrid::HGRIP]->getWidth());
-}
-
-void Slider::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (alpha != mAlpha)
- {
- mAlpha = alpha;
- for (int f = 0; f < 2; f ++)
- {
- for (int d = 0; d < SliderGrid::SLIDER_MAX; d ++)
- {
- if (buttons[f].grid[d] != nullptr)
- buttons[f].grid[d]->setAlpha(mAlpha);
- }
- }
- }
-}
-
-void Slider::draw(Graphics *const graphics)
-{
- BLOCK_START("Slider::draw")
- if ((buttons[0].grid[SliderGrid::HSTART] == nullptr) ||
- (buttons[1].grid[SliderGrid::HSTART] == nullptr) ||
- (buttons[0].grid[SliderGrid::HEND] == nullptr))
- {
- BLOCK_END("Slider::draw")
- return;
- }
-
- int w = getWidth();
- const int h = getHeight();
- const int y = mHasMouse ?
- (h - buttons[1].grid[SliderGrid::HSTART]->getHeight()) / 2 :
- (h - buttons[0].grid[SliderGrid::HSTART]->getHeight()) / 2;
-
- updateAlpha();
-
- if (mRedraw || graphics->getRedraw())
- {
- int x = 0;
- mRedraw = false;
- mVertexes->clear();
- if (!mHasMouse)
- {
- graphics->calcTileCollection(mVertexes,
- buttons[0].grid[SliderGrid::HSTART],
- x, y);
-
- const int width = buttons[0].grid[SliderGrid::HSTART]->getWidth();
- w -= width + buttons[0].grid[SliderGrid::HEND]->getWidth();
- x += width;
-
- if (buttons[0].grid[SliderGrid::HMID] != nullptr)
- {
- const Image *const hMid = buttons[0].grid[SliderGrid::HMID];
- graphics->calcPattern(mVertexes,
- hMid,
- x, y,
- w, hMid->getHeight());
- }
-
- x += w;
- graphics->calcTileCollection(mVertexes,
- buttons[0].grid[SliderGrid::HEND],
- x, y);
-
- const Image *const img = buttons[0].grid[SliderGrid::HGRIP];
- if (img != nullptr)
- {
- graphics->calcTileCollection(mVertexes,
- img,
- getMarkerPosition(),
- (mDimension.height - img->getHeight()) / 2);
- }
- }
- else
- {
- graphics->calcTileCollection(mVertexes,
- buttons[1].grid[SliderGrid::HSTART],
- x, y);
-
- const int width = buttons[1].grid[SliderGrid::HSTART]->getWidth();
- w -= width;
- if (buttons[1].grid[SliderGrid::HEND] != nullptr)
- w -= buttons[1].grid[SliderGrid::HEND]->getWidth();
- x += width;
-
- if (buttons[1].grid[SliderGrid::HMID] != nullptr)
- {
- const Image *const hMid = buttons[1].grid[SliderGrid::HMID];
- graphics->calcPattern(mVertexes,
- hMid,
- x, y,
- w, hMid->getHeight());
- }
-
- x += w;
- if (buttons[1].grid[SliderGrid::HEND] != nullptr)
- {
- graphics->calcTileCollection(mVertexes,
- buttons[1].grid[SliderGrid::HEND], x, y);
- }
-
- const Image *const img = buttons[1].grid[SliderGrid::HGRIP];
- if (img != nullptr)
- {
- graphics->calcTileCollection(mVertexes,
- img,
- getMarkerPosition(),
- (mDimension.height - img->getHeight()) / 2);
- }
- }
- graphics->finalize(mVertexes);
- }
- graphics->drawTileCollection(mVertexes);
-
- BLOCK_END("Slider::draw")
-}
-
-void Slider::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("Slider::draw")
- if ((buttons[0].grid[SliderGrid::HSTART] == nullptr) ||
- (buttons[1].grid[SliderGrid::HSTART] == nullptr) ||
- (buttons[0].grid[SliderGrid::HEND] == nullptr))
- {
- BLOCK_END("Slider::draw")
- return;
- }
-
- int w = getWidth();
- const int h = getHeight();
- int x = 0;
- const int y = mHasMouse ?
- (h - buttons[1].grid[SliderGrid::HSTART]->getHeight()) / 2 :
- (h - buttons[0].grid[SliderGrid::HSTART]->getHeight()) / 2;
-
- updateAlpha();
-
- if (!mHasMouse)
- {
- graphics->drawImage(buttons[0].grid[SliderGrid::HSTART], x, y);
- const int width = buttons[0].grid[SliderGrid::HSTART]->getWidth();
- w -= width + buttons[0].grid[SliderGrid::HEND]->getWidth();
- x += width;
-
- if (buttons[0].grid[SliderGrid::HMID] != nullptr)
- {
- const Image *const hMid = buttons[0].grid[SliderGrid::HMID];
- graphics->drawPattern(hMid, x, y, w, hMid->getHeight());
- }
-
- x += w;
- graphics->drawImage(buttons[0].grid[SliderGrid::HEND], x, y);
-
- const Image *const img = buttons[0].grid[SliderGrid::HGRIP];
- if (img != nullptr)
- {
- graphics->drawImage(img, getMarkerPosition(),
- (mDimension.height - img->getHeight()) / 2);
- }
- }
- else
- {
- graphics->drawImage(buttons[1].grid[SliderGrid::HSTART], x, y);
-
- const int width = buttons[1].grid[SliderGrid::HSTART]->getWidth();
- w -= width;
- if (buttons[1].grid[SliderGrid::HEND] != nullptr)
- w -= buttons[1].grid[SliderGrid::HEND]->getWidth();
- x += width;
-
- if (buttons[1].grid[SliderGrid::HMID] != nullptr)
- {
- const Image *const hMid = buttons[1].grid[SliderGrid::HMID];
- graphics->drawPattern(hMid, x, y, w, hMid->getHeight());
- }
-
- x += w;
- if (buttons[1].grid[SliderGrid::HEND] != nullptr)
- graphics->drawImage(buttons[1].grid[SliderGrid::HEND], x, y);
-
- const Image *const img = buttons[1].grid[SliderGrid::HGRIP];
- if (img != nullptr)
- {
- graphics->drawImage(img, getMarkerPosition(),
- (mDimension.height - img->getHeight()) / 2);
- }
- }
-
- BLOCK_END("Slider::draw")
-}
-
-void Slider::mouseEntered(MouseEvent& event A_UNUSED)
-{
- mHasMouse = true;
- mRedraw = true;
-}
-
-void Slider::mouseExited(MouseEvent& event A_UNUSED)
-{
- mHasMouse = false;
- mRedraw = true;
-}
-
-void Slider::mousePressed(MouseEvent &event)
-{
- const int x = event.getX();
- const int y = event.getY();
- const int width = mDimension.width;
- const int height = mDimension.height;
-
- if (event.getButton() == MouseButton::LEFT
- && x >= 0 && x <= width && y >= 0 && y <= height)
- {
- event.consume();
- if (mOrientation == Orientation::HORIZONTAL)
- setValue(markerPositionToValue(x - mMarkerLength / 2));
- else
- setValue(markerPositionToValue(height - y - mMarkerLength / 2));
- distributeActionEvent();
- }
-}
-
-void Slider::mouseDragged(MouseEvent &event)
-{
- if (mOrientation == Orientation::HORIZONTAL)
- {
- setValue(markerPositionToValue(event.getX() - mMarkerLength / 2));
- }
- else
- {
- setValue(markerPositionToValue(
- mDimension.height - event.getY() - mMarkerLength / 2));
- }
-
- distributeActionEvent();
-
- event.consume();
-}
-
-void Slider::mouseWheelMovedUp(MouseEvent &event)
-{
- setValue(mValue + mStepLength);
- distributeActionEvent();
- event.consume();
-}
-
-void Slider::mouseWheelMovedDown(MouseEvent &event)
-{
- setValue(mValue - mStepLength);
- distributeActionEvent();
- event.consume();
-}
-
-void Slider::keyPressed(KeyEvent& event)
-{
- const InputActionT action = event.getActionId();
-
- if (mOrientation == Orientation::HORIZONTAL)
- {
- if (action == InputAction::GUI_RIGHT)
- {
- setValue(mValue + mStepLength);
- distributeActionEvent();
- event.consume();
- }
- else if (action == InputAction::GUI_LEFT)
- {
- setValue(mValue - mStepLength);
- distributeActionEvent();
- event.consume();
- }
- }
- else
- {
- if (action == InputAction::GUI_UP)
- {
- setValue(mValue + mStepLength);
- distributeActionEvent();
- event.consume();
- }
- else if (action == InputAction::GUI_DOWN)
- {
- setValue(mValue - mStepLength);
- distributeActionEvent();
- event.consume();
- }
- }
-}
-
-void Slider::setScale(const double scaleStart, const double scaleEnd)
-{
- mScaleStart = scaleStart;
- mScaleEnd = scaleEnd;
-}
-
-void Slider::setValue(const double value)
-{
- mRedraw = true;
- if (value > mScaleEnd)
- mValue = mScaleEnd;
- else if (value < mScaleStart)
- mValue = mScaleStart;
- else
- mValue = value;
- mValue = CAST_S32((mValue - mScaleStart) / mStepLength)
- * mStepLength + mScaleStart;
-}
-
-double Slider::markerPositionToValue(const int v) const
-{
- int w;
- if (mOrientation == Orientation::HORIZONTAL)
- w = mDimension.width;
- else
- w = mDimension.height;
-
- const double pos = v / (static_cast<double>(w) - mMarkerLength);
- return (1.0 - pos) * mScaleStart + pos * mScaleEnd;
-}
-
-int Slider::valueToMarkerPosition(const double value) const
-{
- int v;
- if (mOrientation == Orientation::HORIZONTAL)
- v = mDimension.width;
- else
- v = mDimension.height;
-
- const int w = CAST_S32((v - mMarkerLength)
- * (value - mScaleStart)
- / (mScaleEnd - mScaleStart));
-
- if (w < 0)
- return 0;
-
- if (w > v - mMarkerLength)
- return v - mMarkerLength;
-
- return w;
-}
diff --git a/src/gui/widgets/slider.h b/src/gui/widgets/slider.h
deleted file mode 100644
index 49acafc28..000000000
--- a/src/gui/widgets/slider.h
+++ /dev/null
@@ -1,337 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_SLIDER_H
-#define GUI_WIDGETS_SLIDER_H
-
-#include "enums/gui/orientation.h"
-
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-
-#include "gui/widgets/widget.h"
-
-#include "localconsts.h"
-
-class ImageCollection;
-
-/**
- * Slider widget. Same as the Guichan slider but with custom look.
- *
- * \ingroup GUI
- */
-class Slider final : public Widget,
- public MouseListener,
- public KeyListener
-{
- public:
- /**
- * Constructor with scale start equal to 0.
- */
- Slider(Widget2 *const widget,
- const double scaleEnd,
- const double stepLength);
-
- /**
- * Constructor.
- */
- Slider(Widget2 *const widget,
- const double scaleStart,
- const double scaleEnd,
- const double stepLength);
-
- A_DELETE_COPY(Slider)
-
- /**
- * Destructor.
- */
- ~Slider();
-
- /**
- * Update the alpha value to the graphic components.
- */
- void updateAlpha();
-
- /**
- * Draws the slider.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Called when the mouse enteres the widget area.
- */
- void mouseEntered(MouseEvent& event) override final;
-
- /**
- * Called when the mouse leaves the widget area.
- */
- void mouseExited(MouseEvent& event) override final;
-
- void mousePressed(MouseEvent &event) override final;
-
- void mouseDragged(MouseEvent &event) override final;
-
- void mouseWheelMovedUp(MouseEvent &event) override final;
-
- void mouseWheelMovedDown(MouseEvent &event) override final;
-
- void keyPressed(KeyEvent& event) override final;
-
- /**
- * Sets the scale of the slider.
- *
- * @param scaleStart The start value of the scale.
- * @param scaleEnd tThe end of value the scale.
- * @see getScaleStart, getScaleEnd
- */
- void setScale(const double scaleStart, const double scaleEnd);
-
- /**
- * Gets the start value of the scale.
- *
- * @return The start value of the scale.
- * @see setScaleStart, setScale
- */
- double getScaleStart() const
- { return mScaleStart; }
-
- /**
- * Sets the start value of the scale.
- *
- * @param scaleStart The start value of the scale.
- * @see getScaleStart
- */
- void setScaleStart(const double scaleStart)
- { mScaleStart = scaleStart; }
-
- /**
- * Gets the end value of the scale.
- *
- * @return The end value of the scale.
- * @see setScaleEnd, setScale
- */
- double getScaleEnd() const
- { return mScaleEnd; }
-
- /**
- * Sets the end value of the scale.
- *
- * @param scaleEnd The end value of the scale.
- * @see getScaleEnd
- */
- void setScaleEnd(const double scaleEnd)
- { mScaleEnd = scaleEnd; }
-
- /**
- * Sets the current selected value.
- *
- * @param value The current selected value.
- * @see getValue
- */
- void setValue(const double value);
-
- /**
- * Gets the current selected value.
- *
- * @return The current selected value.
- * @see setValue
- */
- double getValue() const
- { return mValue; }
-
- /**
- * Gets the length of the marker.
- *
- * @return The length of the marker.
- * @see setMarkerLength
- */
- int getMarkerLength() const
- { return mMarkerLength; }
-
- /**
- * Sets the length of the marker.
- *
- * @param length The length for the marker.
- * @see getMarkerLength
- */
- void setMarkerLength(const int length)
- { mMarkerLength = length; }
-
- /**
- * Sets the orientation of the slider. A slider can be drawn vertically
- * or horizontally.
- *
- * @param orientation The orientation of the slider.
- * @see getOrientation
- */
- void setOrientation(const OrientationT orientation)
- { mOrientation = orientation; }
-
- /**
- * Gets the orientation of the slider. A slider can be drawn vertically
- * or horizontally.
- *
- * @return The orientation of the slider.
- * @see setOrientation
- */
- OrientationT getOrientation() const
- { return mOrientation; }
-
- /**
- * Sets the step length. The step length is used when the keys LEFT
- * and RIGHT are pressed to step in the scale.
- *
- * @param length The step length.
- * @see getStepLength
- */
- void setStepLength(const double length)
- { mStepLength = length; }
-
- /**
- * Gets the step length. The step length is used when the keys LEFT
- * and RIGHT are pressed to step in the scale.
- *
- * @return the step length.
- * @see setStepLength
- */
- double getStepLength() const
- { return mStepLength; }
-
- private:
- /**
- * Used to initialize instances.
- */
- void init();
-
- /**
- * Converts a marker position to a value in the scale.
- *
- * @param position The position to convert.
- * @return A scale value corresponding to the position.
- * @see valueToMarkerPosition
- */
- double markerPositionToValue(const int position) const;
-
- /**
- * Converts a value to a marker position.
- *
- * @param value The value to convert.
- * @return A marker position corresponding to the value.
- * @see markerPositionToValue
- */
- int valueToMarkerPosition(const double value) const;
-
- /**
- * Gets the marker position of the current selected value.
- *
- * @return The marker position of the current selected value.
- */
- int getMarkerPosition() const
- { return valueToMarkerPosition(getValue()); }
-
- static ImageRect buttons[2];
- static float mAlpha;
- static int mInstances;
-
- /**
- * Holds the current selected value.
- */
- double mValue;
-
- /**
- * Holds the step length. The step length is used when the keys LEFT
- * and RIGHT are pressed to step in the scale.
- */
- double mStepLength;
-
- /**
- * Holds the start value of the scale.
- */
- double mScaleStart;
-
- /**
- * Holds the end value of the scale.
- */
- double mScaleEnd;
-
- /**
- * Holds the orientation of the slider. A slider can be drawn
- * vertically or horizontally.
- */
- OrientationT mOrientation;
-
- ImageCollection *mVertexes A_NONNULLPOINTER;
-
- /**
- * Holds the length of the marker.
- */
- int mMarkerLength;
-
- bool mHasMouse;
-};
-
-#endif // GUI_WIDGETS_SLIDER_H
diff --git a/src/gui/widgets/sliderlist.cpp b/src/gui/widgets/sliderlist.cpp
deleted file mode 100644
index edce0cf02..000000000
--- a/src/gui/widgets/sliderlist.cpp
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/sliderlist.h"
-
-#include "gui/gui.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/models/listmodel.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/label.h"
-
-#include "debug.h"
-
-static const int buttonWidth = 27;
-static const int buttonSpace = 30;
-static const int sliderHeight = 30;
-
-SliderList::SliderList(const Widget2 *const widget,
- ListModel *const listModel) :
- Container(widget),
- ActionListener(),
- MouseListener(),
- mButtons(),
- mLabel(new Label(this)),
- mListModel(listModel),
- mPrevEventId(),
- mNextEventId(),
- mOldWidth(0),
- mSelectedIndex(0)
-{
- mAllowLogic = false;
- setHeight(sliderHeight);
-}
-
-void SliderList::postInit2(ActionListener *const listener,
- const std::string &eventId)
-{
- mPrevEventId = eventId + "_prev";
- mNextEventId = eventId + "_next";
-
- mButtons[0] = new Button(this, "<", mPrevEventId, this);
- mButtons[1] = new Button(this, ">", mNextEventId, this);
-
- add(mButtons[0]);
- add(mLabel);
- add(mButtons[1]);
-
- if (!eventId.empty())
- setActionEventId(eventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-
- updateLabel();
- addMouseListener(this);
-}
-
-SliderList::~SliderList()
-{
-}
-
-void SliderList::updateAlpha()
-{
- Button::updateAlpha();
-}
-
-void SliderList::mouseWheelMovedUp(MouseEvent& event)
-{
- setSelected(mSelectedIndex - 1);
- event.consume();
-}
-
-void SliderList::mouseWheelMovedDown(MouseEvent& event)
-{
- setSelected(mSelectedIndex + 1);
- event.consume();
-}
-
-void SliderList::resize()
-{
- const int width = getWidth();
-
- mButtons[0]->setWidth(buttonWidth);
- mLabel->setWidth(width - buttonSpace * 2);
- mButtons[1]->setPosition(width - buttonSpace + 3, 0);
- mButtons[1]->setWidth(buttonWidth);
- updateLabel();
-}
-
-void SliderList::draw(Graphics *const graphics)
-{
- BLOCK_START("SliderList::draw")
- const int width = mDimension.width;
- if (mOldWidth != width)
- {
- resize();
- mOldWidth = width;
- }
- Container::draw(graphics);
- BLOCK_END("SliderList::draw")
-}
-
-void SliderList::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("SliderList::draw")
- const int width = mDimension.width;
- if (mOldWidth != width)
- {
- resize();
- mOldWidth = width;
- }
- Container::draw(graphics);
- BLOCK_END("SliderList::draw")
-}
-
-void SliderList::updateLabel()
-{
- if ((mListModel == nullptr) || mSelectedIndex < 0
- || mSelectedIndex >= mListModel->getNumberOfElements())
- {
- return;
- }
-
- mLabel->setCaption(mListModel->getElementAt(mSelectedIndex));
- mLabel->adjustSize();
- const int space = mDimension.width - buttonSpace * 2;
- const int labelWidth = mLabel->getWidth();
- int labelY = (mDimension.height - mLabel->getHeight()) / 2;
- if (labelY < 0)
- labelY = 0;
-
- if (space < 0 || space < labelWidth)
- mLabel->setPosition(buttonSpace, labelY);
- else
- mLabel->setPosition(buttonSpace + (space - labelWidth) / 2, labelY);
-}
-
-void SliderList::action(const ActionEvent &event)
-{
- if (mListModel == nullptr)
- return;
-
- const std::string &eventId = event.getId();
- if (eventId == mPrevEventId)
- {
- mSelectedIndex --;
- if (mSelectedIndex < 0)
- mSelectedIndex = mListModel->getNumberOfElements() - 1;
- }
- else if (eventId == mNextEventId)
- {
- mSelectedIndex ++;
- if (mSelectedIndex >= mListModel->getNumberOfElements())
- mSelectedIndex = 0;
- }
- updateLabel();
- distributeActionEvent();
-}
-
-void SliderList::setSelectedString(const std::string &str)
-{
- if (mListModel == nullptr)
- return;
-
- for (int f = 0; f < mListModel->getNumberOfElements(); f ++)
- {
- if (mListModel->getElementAt(f) == str)
- {
- setSelected(f);
- break;
- }
- }
-}
-
-std::string SliderList::getSelectedString() const
-{
- if (mListModel == nullptr)
- return std::string();
-
- return mListModel->getElementAt(mSelectedIndex);
-}
-
-void SliderList::setSelected(const int idx)
-{
- if (mListModel == nullptr)
- return;
-
- mSelectedIndex = idx;
- const int num = mListModel->getNumberOfElements();
- if (mSelectedIndex >= num)
- mSelectedIndex = 0;
- if (mSelectedIndex < 0)
- mSelectedIndex = num - 1;
- updateLabel();
-}
-
-void SliderList::adjustSize()
-{
- setWidth(getMaxLabelWidth() + 60);
- updateLabel();
-}
-
-int SliderList::getMaxLabelWidth() const
-{
- if ((mListModel == nullptr) || (gui == nullptr))
- return 1;
-
- int maxWidth = 0;
- const Font *const font = getFont();
-
- const int num = mListModel->getNumberOfElements();
- for (int f = 0; f < num; f ++)
- {
- const int w = font->getWidth(mListModel->getElementAt(f));
- if (w > maxWidth)
- maxWidth = w;
- }
-
- return maxWidth;
-}
diff --git a/src/gui/widgets/sliderlist.h b/src/gui/widgets/sliderlist.h
deleted file mode 100644
index 6f4336531..000000000
--- a/src/gui/widgets/sliderlist.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SLIDERLIST_H
-#define GUI_WIDGETS_SLIDERLIST_H
-
-#include "listeners/actionlistener.h"
-#include "listeners/mouselistener.h"
-
-#include "gui/widgets/container.h"
-
-#include "localconsts.h"
-
-class Button;
-class Label;
-class ListModel;
-
-class SliderList final : public Container,
- public ActionListener,
- public MouseListener
-{
- public:
- SliderList(const Widget2 *const widget,
- ListModel *const listModel);
-
- A_DELETE_COPY(SliderList)
-
- ~SliderList();
-
- void postInit2(ActionListener *const listener,
- const std::string &eventId);
-
- void updateAlpha();
-
- void mouseWheelMovedUp(MouseEvent& event) override final;
-
- void mouseWheelMovedDown(MouseEvent& event) override final;
-
- void resize();
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void action(const ActionEvent &event) override final;
-
- void setSelectedString(const std::string &str);
-
- std::string getSelectedString() const A_WARN_UNUSED;
-
- void setSelected(const int idx);
-
- void adjustSize();
-
- int getSelected() const noexcept2 A_WARN_UNUSED
- { return mSelectedIndex; }
-
- protected:
- void updateLabel();
-
- int getMaxLabelWidth() const A_WARN_UNUSED;
-
- Button *mButtons[2] A_NONNULLPOINTER;
- Label *mLabel A_NONNULLPOINTER;
- ListModel *mListModel;
- std::string mPrevEventId;
- std::string mNextEventId;
- int mOldWidth;
- int mSelectedIndex;
-};
-
-#endif // GUI_WIDGETS_SLIDERLIST_H
diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp
deleted file mode 100644
index ffa23ffa1..000000000
--- a/src/gui/widgets/spellshortcutcontainer.cpp
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/spellshortcutcontainer.h"
-
-#include "dragdrop.h"
-#include "settings.h"
-#include "spellmanager.h"
-
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/shortcut/itemshortcut.h"
-#include "gui/shortcut/spellshortcut.h"
-
-#include "gui/popups/popupmenu.h"
-#include "gui/popups/spellpopup.h"
-
-#include "gui/windows/shortcutwindow.h"
-
-#include "debug.h"
-
-SpellShortcutContainer::SpellShortcutContainer(Widget2 *const widget,
- const unsigned number) :
- ShortcutContainer(widget),
- mNumber(number),
- mSpellClicked(false)
-{
- if (spellShortcut != nullptr)
- mMaxItems = spellShortcut->getSpellsCount();
- else
- mMaxItems = 0;
-}
-
-SpellShortcutContainer::~SpellShortcutContainer()
-{
-}
-
-void SpellShortcutContainer::setWidget2(const Widget2 *const widget)
-{
- Widget2::setWidget2(widget);
- mForegroundColor = getThemeColor(ThemeColorId::TEXT);
- mForegroundColor2 = getThemeColor(ThemeColorId::TEXT_OUTLINE);
-}
-
-void SpellShortcutContainer::draw(Graphics *const graphics)
-{
- if (spellShortcut == nullptr)
- return;
-
- BLOCK_START("SpellShortcutContainer::draw")
- if (settings.guiAlpha != mAlpha)
- {
- mAlpha = settings.guiAlpha;
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- }
-
- Font *const font = getFont();
-
- const int selectedId = spellShortcut->getSelectedItem();
- graphics->setColor(mForegroundColor);
- drawBackground(graphics);
-
- // +++ in future need reorder images and string drawing.
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int itemX = (i % mGridWidth) * mBoxWidth;
- const int itemY = (i / mGridWidth) * mBoxHeight;
-
- const int itemId = getItemByIndex(i);
- if (selectedId >= 0 && itemId == selectedId)
- {
- graphics->drawRectangle(Rect(itemX + 1, itemY + 1,
- mBoxWidth - 1, mBoxHeight - 1));
- }
-
- if (spellManager == nullptr)
- continue;
-
- const TextCommand *const spell = spellManager->getSpell(itemId);
- if (spell != nullptr)
- {
- if (!spell->isEmpty())
- {
- Image *const image = spell->getImage();
-
- if (image != nullptr)
- {
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- }
- }
-
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- spell->getSymbol(),
- itemX + 2, itemY + mBoxHeight / 2);
- }
- }
-
- BLOCK_END("SpellShortcutContainer::draw")
-}
-
-void SpellShortcutContainer::safeDraw(Graphics *const graphics)
-{
- if (spellShortcut == nullptr)
- return;
-
- BLOCK_START("SpellShortcutContainer::draw")
- if (settings.guiAlpha != mAlpha)
- {
- mAlpha = settings.guiAlpha;
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- }
-
- Font *const font = getFont();
-
- const int selectedId = spellShortcut->getSelectedItem();
- graphics->setColor(mForegroundColor);
- safeDrawBackground(graphics);
-
- // +++ in future need reorder images and string drawing.
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int itemX = (i % mGridWidth) * mBoxWidth;
- const int itemY = (i / mGridWidth) * mBoxHeight;
-
- const int itemId = getItemByIndex(i);
- if (selectedId >= 0 && itemId == selectedId)
- {
- graphics->drawRectangle(Rect(itemX + 1, itemY + 1,
- mBoxWidth - 1, mBoxHeight - 1));
- }
-
- if (spellManager == nullptr)
- continue;
-
- const TextCommand *const spell = spellManager->getSpell(itemId);
- if (spell != nullptr)
- {
- if (!spell->isEmpty())
- {
- Image *const image = spell->getImage();
-
- if (image != nullptr)
- {
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- }
- }
-
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- spell->getSymbol(),
- itemX + 2, itemY + mBoxHeight / 2);
- }
- }
-
- BLOCK_END("SpellShortcutContainer::draw")
-}
-
-void SpellShortcutContainer::mouseDragged(MouseEvent &event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- if (dragDrop.isEmpty() && mSpellClicked)
- {
- mSpellClicked = false;
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- const int itemId = getItemByIndex(index);
- if (itemId < 0)
- return;
- event.consume();
- TextCommand *const spell = spellManager->getSpell(itemId);
- if (spell != nullptr)
- {
- dragDrop.dragCommand(spell, DragDropSource::Spells, index);
- dragDrop.setItem(spell->getId() + SPELL_MIN_ID);
- }
- else
- {
- dragDrop.clear();
- mSpellClicked = false;
- }
- }
- }
-}
-
-void SpellShortcutContainer::mousePressed(MouseEvent &event)
-{
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- const MouseButtonT eventButton = event.getButton();
- if (eventButton == MouseButton::LEFT)
- {
- const int itemId = getItemByIndex(index);
- if (itemId > 0)
- mSpellClicked = true;
- event.consume();
- }
- else if (eventButton == MouseButton::MIDDLE)
- {
- if ((spellShortcut == nullptr) || (spellManager == nullptr))
- return;
-
- event.consume();
- const int itemId = getItemByIndex(index);
- spellManager->invoke(itemId);
- }
-}
-
-void SpellShortcutContainer::mouseReleased(MouseEvent &event)
-{
- if ((spellShortcut == nullptr) || (spellManager == nullptr))
- return;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- {
- dragDrop.clear();
- return;
- }
-
- const int itemId = getItemByIndex(index);
- const MouseButtonT eventButton = event.getButton();
-
- if (eventButton == MouseButton::LEFT)
- {
- mSpellClicked = false;
-
- if (itemId < 0)
- return;
-
- const int selectedId = spellShortcut->getSelectedItem();
- event.consume();
-
- if (!dragDrop.isEmpty())
- {
- if (dragDrop.getSource() == DragDropSource::Spells)
- {
- const int oldIndex = dragDrop.getTag();
- const int idx = mNumber * SPELL_SHORTCUT_ITEMS;
- spellManager->swap(idx + index, idx + oldIndex);
- spellManager->save();
- dragDrop.clear();
- dragDrop.deselect();
- }
- }
- else
- {
- if (selectedId != itemId)
- {
- const TextCommand *const
- spell = spellManager->getSpell(itemId);
- if ((spell != nullptr) && !spell->isEmpty())
- {
- const int num = itemShortcutWindow->getTabIndex();
- if (num >= 0 && num < CAST_S32(SHORTCUT_TABS)
- && (itemShortcut[num] != nullptr))
- {
- itemShortcut[num]->setItemSelected(
- spell->getId() + SPELL_MIN_ID);
- }
- spellShortcut->setItemSelected(spell->getId());
- }
- }
- else
- {
- const int num = itemShortcutWindow->getTabIndex();
- if (num >= 0 && num < CAST_S32(SHORTCUT_TABS)
- && (itemShortcut[num] != nullptr))
- {
- itemShortcut[num]->setItemSelected(-1);
- }
- spellShortcut->setItemSelected(-1);
- }
- }
- }
- else if (eventButton == MouseButton::RIGHT)
- {
- TextCommand *spell = nullptr;
- if (itemId >= 0)
- spell = spellManager->getSpell(itemId);
-
- if ((spell != nullptr) && (popupMenu != nullptr))
- {
- popupMenu->showSpellPopup(viewport->mMouseX,
- viewport->mMouseY,
- spell);
- }
- }
-}
-
-// Show ItemTooltip
-void SpellShortcutContainer::mouseMoved(MouseEvent &event)
-{
- if (spellPopup == nullptr ||
- spellShortcut == nullptr ||
- spellManager == nullptr)
- {
- return;
- }
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- const int itemId = getItemByIndex(index);
- spellPopup->setVisible(Visible_false);
- const TextCommand *const spell = spellManager->getSpell(itemId);
- if ((spell != nullptr) && !spell->isEmpty())
- {
- spellPopup->setItem(spell);
- spellPopup->view(viewport->mMouseX, viewport->mMouseY);
- }
- else
- {
- spellPopup->setVisible(Visible_false);
- }
-}
-
-void SpellShortcutContainer::mouseExited(MouseEvent &event A_UNUSED)
-{
- if (spellPopup != nullptr)
- spellPopup->setVisible(Visible_false);
-}
-
-void SpellShortcutContainer::widgetHidden(const Event &event A_UNUSED)
-{
- if (spellPopup != nullptr)
- spellPopup->setVisible(Visible_false);
-}
-
-int SpellShortcutContainer::getItemByIndex(const int index) const
-{
- return spellShortcut->getItem(
- (mNumber * SPELL_SHORTCUT_ITEMS) + index);
-}
diff --git a/src/gui/widgets/spellshortcutcontainer.h b/src/gui/widgets/spellshortcutcontainer.h
deleted file mode 100644
index 872ca5e1a..000000000
--- a/src/gui/widgets/spellshortcutcontainer.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_SPELLSHORTCUTCONTAINER_H
-#define GUI_WIDGETS_SPELLSHORTCUTCONTAINER_H
-
-#include "gui/widgets/shortcutcontainer.h"
-
-/**
- * An item shortcut container. Used to quickly use items.
- *
- * \ingroup GUI
- */
-class SpellShortcutContainer final : public ShortcutContainer
-{
- public:
- /**
- * Constructor. Initializes the graphic.
- */
- SpellShortcutContainer(Widget2 *const widget,
- const unsigned number);
-
- A_DELETE_COPY(SpellShortcutContainer)
-
- /**
- * Destructor.
- */
- ~SpellShortcutContainer();
-
- /**
- * Draws the items.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Handles mouse when dragged.
- */
- void mouseDragged(MouseEvent &event) override final;
-
- /**
- * Handles mouse when pressed.
- */
- void mousePressed(MouseEvent &event) override final;
-
- /**
- * Handles mouse release.
- */
- void mouseReleased(MouseEvent &event) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void mouseExited(MouseEvent &event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void setWidget2(const Widget2 *const widget) override final;
-
- int getItemByIndex(const int index) const A_WARN_UNUSED;
-
- private:
- unsigned int mNumber;
- bool mSpellClicked;
-};
-
-#endif // GUI_WIDGETS_SPELLSHORTCUTCONTAINER_H
diff --git a/src/gui/widgets/staticbrowserbox.cpp b/src/gui/widgets/staticbrowserbox.cpp
deleted file mode 100644
index de0d787a7..000000000
--- a/src/gui/widgets/staticbrowserbox.cpp
+++ /dev/null
@@ -1,781 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- * Copyright (C) 2009 Aethyra Development Team
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/staticbrowserbox.h"
-
-#include "enums/gui/linkhighlightmode.h"
-
-#include "gui/gui.h"
-#include "gui/mouseoverlink.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/widgets/browserbox.inc"
-#include "gui/widgets/linkhandler.h"
-
-#include "render/graphics.h"
-
-#include "resources/imageset.h"
-
-#include "resources/image/image.h"
-
-#include "resources/loaders/imageloader.h"
-#include "resources/loaders/imagesetloader.h"
-
-#include "utils/browserboxtools.h"
-#include "utils/checkutils.h"
-#include "utils/foreach.h"
-#include "utils/stdmove.h"
-#include "utils/stringutils.h"
-#include "utils/translation/podict.h"
-
-#include <algorithm>
-
-#include "debug.h"
-
-ImageSet *StaticBrowserBox::mEmotes = nullptr;
-int StaticBrowserBox::mInstances = 0;
-
-StaticBrowserBox::StaticBrowserBox(const Widget2 *const widget,
- const Opaque opaque,
- const std::string &skin) :
- Widget(widget),
- MouseListener(),
- mTextRows(),
- mTextRowLinksCount(),
- mLineParts(),
- mLinks(),
- mLinkHandler(nullptr),
- mSkin(nullptr),
- mHighlightMode(0),
- mSelectedLink(-1),
- mHeight(0),
- mWidth(0),
- mYStart(0),
- mPadding(0),
- mNewLinePadding(15U),
- mItemPadding(0),
- mHighlightColor(getThemeColor(ThemeColorId::HIGHLIGHT)),
- mHyperLinkColor(getThemeColor(ThemeColorId::HYPERLINK)),
- mOpaque(opaque),
- mUseLinksAndUserColors(true),
- mUseEmotes(true),
- mProcessVars(false),
- mEnableImages(false),
- mEnableKeys(false),
- mEnableTabs(false),
- mSeparator(false)
-{
- mAllowLogic = false;
-
- setFocusable(true);
- addMouseListener(this);
-
- mBackgroundColor = getThemeColor(ThemeColorId::BACKGROUND);
-
- if (theme != nullptr)
- mSkin = theme->load(skin, "browserbox.xml");
- if (mInstances == 0)
- {
- mEmotes = Loader::getImageSet(
- "graphics/sprites/chatemotes.png", 17, 18);
- }
- mInstances ++;
-
- if (mSkin != nullptr)
- {
- mPadding = mSkin->getPadding();
- mNewLinePadding = CAST_U32(
- mSkin->getOption("newLinePadding", 15));
- mItemPadding = mSkin->getOption("itemPadding");
- if (mSkin->getOption("highlightBackground") != 0)
- mHighlightMode |= LinkHighlightMode::BACKGROUND;
- if (mSkin->getOption("highlightUnderline") != 0)
- mHighlightMode |= LinkHighlightMode::UNDERLINE;
- }
-
- readColor(BLACK);
- readColor(RED);
- readColor(GREEN);
- readColor(BLUE);
- readColor(ORANGE);
- readColor(YELLOW);
- readColor(PINK);
- readColor(PURPLE);
- readColor(GRAY);
- readColor(BROWN);
-
- mForegroundColor = getThemeColor(ThemeColorId::BROWSERBOX);
- mForegroundColor2 = getThemeColor(ThemeColorId::BROWSERBOX_OUTLINE);
-}
-
-StaticBrowserBox::~StaticBrowserBox()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- if (theme != nullptr)
- {
- theme->unload(mSkin);
- mSkin = nullptr;
- }
-
- mInstances --;
- if (mInstances == 0)
- {
- if (mEmotes != nullptr)
- {
- mEmotes->decRef();
- mEmotes = nullptr;
- }
- }
-}
-
-void StaticBrowserBox::setLinkHandler(LinkHandler* linkHandler)
-{
- mLinkHandler = linkHandler;
-}
-
-void StaticBrowserBox::addSeparator(const std::string &row)
-{
- if (mSeparator)
- return;
- addRow(row, false);
- mSeparator = true;
-}
-
-void StaticBrowserBox::addRow(const std::string &row,
- const bool atTop)
-{
- std::string tmp = row;
- std::string newRow;
- size_t idx1;
- const Font *const font = getFont();
- int linksCount = 0;
-
- if (getWidth() < 0)
- return;
-
- mSeparator = false;
-
- if (mProcessVars)
- {
- BrowserBoxTools::replaceVars(tmp);
- }
-
- // Use links and user defined colors
- if (mUseLinksAndUserColors)
- {
- BrowserLink bLink;
-
- // Check for links in format "@@link|Caption@@"
- const uint32_t sz = CAST_U32(mTextRows.size());
-
- if (mEnableKeys)
- {
- BrowserBoxTools::replaceKeys(tmp);
- }
-
- idx1 = tmp.find("@@");
- while (idx1 != std::string::npos)
- {
- const size_t idx2 = tmp.find('|', idx1);
- const size_t idx3 = tmp.find("@@", idx2);
-
- if (idx2 == std::string::npos || idx3 == std::string::npos)
- break;
- bLink.link = tmp.substr(idx1 + 2, idx2 - (idx1 + 2));
- bLink.caption = tmp.substr(idx2 + 1, idx3 - (idx2 + 1));
- bLink.y1 = CAST_S32(sz) * font->getHeight();
- bLink.y2 = bLink.y1 + font->getHeight();
- if (bLink.caption.empty())
- {
- bLink.caption = BrowserBoxTools::replaceLinkCommands(
- bLink.link);
- if (translator != nullptr)
- bLink.caption = translator->getStr(bLink.caption);
- }
-
- newRow.append(tmp.substr(0, idx1));
-
- std::string tmp2 = newRow;
- idx1 = tmp2.find("##");
- while (idx1 != std::string::npos)
- {
- tmp2.erase(idx1, 3);
- idx1 = tmp2.find("##");
- }
- bLink.x1 = font->getWidth(tmp2) - 1;
- bLink.x2 = bLink.x1 + font->getWidth(bLink.caption) + 1;
-
- if (atTop)
- mLinks.insert(mLinks.begin(), bLink);
- else
- mLinks.push_back(bLink);
- linksCount ++;
-
- newRow.append("##<").append(bLink.caption);
-
- tmp.erase(0, idx3 + 2);
- if (!tmp.empty())
- newRow.append("##>");
-
- idx1 = tmp.find("@@");
- }
-
- newRow.append(tmp);
- }
- // Don't use links and user defined colors
- else
- {
- newRow = row;
- }
-
- if (mEnableTabs)
- {
- BrowserBoxTools::replaceTabs(newRow);
- }
-
- if (atTop)
- {
- mTextRows.push_front(newRow);
- mTextRowLinksCount.push_front(linksCount);
- }
- else
- {
- mTextRows.push_back(newRow);
- mTextRowLinksCount.push_back(linksCount);
- }
-
- std::string plain = STD_MOVE(newRow);
- // workaround if used only one string started from bold
- // width for this string can be calculated wrong
- // this workaround fix width if string start from bold sign
- const bool startBold = (plain.find("##B") == 0);
- for (idx1 = plain.find("##");
- idx1 != std::string::npos;
- idx1 = plain.find("##"))
- {
- plain.erase(idx1, 3);
- }
-
- // Adjust the StaticBrowserBox size. This need only for implementing "---"
- const int w = startBold ?
- boldFont->getWidth(plain) : font->getWidth(plain) + 2 * mPadding;
- if (w > getWidth())
- setWidth(w);
-}
-
-void StaticBrowserBox::addRow(const std::string &cmd,
- const char *const text)
-{
- addRow(strprintf("@@%s|%s@@", encodeLinkText(cmd).c_str(),
- encodeLinkText(text).c_str()));
-}
-
-void StaticBrowserBox::addImage(const std::string &path)
-{
- if (!mEnableImages)
- return;
-
- mTextRows.push_back("~~~" + path);
- mTextRowLinksCount.push_back(0);
-}
-
-void StaticBrowserBox::clearRows()
-{
- mTextRows.clear();
- mTextRowLinksCount.clear();
- mLinks.clear();
- setWidth(0);
- setHeight(0);
- mSelectedLink = -1;
-}
-
-void StaticBrowserBox::mousePressed(MouseEvent &event)
-{
- if (mLinkHandler == nullptr)
- return;
-
- const LinkIterator i = std::find_if(mLinks.begin(), mLinks.end(),
- MouseOverLink(event.getX(), event.getY()));
-
- if (i != mLinks.end())
- {
- mLinkHandler->handleLink(i->link, &event);
- event.consume();
- }
-}
-
-void StaticBrowserBox::mouseMoved(MouseEvent &event)
-{
- const LinkIterator i = std::find_if(mLinks.begin(), mLinks.end(),
- MouseOverLink(event.getX(), event.getY()));
-
- mSelectedLink = (i != mLinks.end())
- ? CAST_S32(i - mLinks.begin()) : -1;
-}
-
-void StaticBrowserBox::mouseExited(MouseEvent &event A_UNUSED)
-{
- mSelectedLink = -1;
-}
-
-void StaticBrowserBox::draw(Graphics *const graphics)
-{
- BLOCK_START("StaticBrowserBox::draw")
- const ClipRect &cr = graphics->getTopClip();
- mYStart = cr.y - cr.yOffset;
- const int yEnd = mYStart + cr.height;
- if (mYStart < 0)
- mYStart = 0;
-
- if (mDimension.width != mWidth)
- {
- updateHeight();
- reportAlways("browserbox resize in draw: %d, %d",
- mDimension.width,
- mWidth);
- }
-
- if (mOpaque == Opaque_true)
- {
- graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(Rect(0, 0,
- mDimension.width, mDimension.height));
- }
-
- if (mSelectedLink >= 0 &&
- mSelectedLink < CAST_S32(mLinks.size()))
- {
- if ((mHighlightMode & LinkHighlightMode::BACKGROUND) != 0u)
- {
- BrowserLink &link = mLinks[CAST_SIZE(mSelectedLink)];
- graphics->setColor(mHighlightColor);
- graphics->fillRectangle(Rect(
- link.x1,
- link.y1,
- link.x2 - link.x1,
- link.y2 - link.y1));
- }
-
- if ((mHighlightMode & LinkHighlightMode::UNDERLINE) != 0u)
- {
- BrowserLink &link = mLinks[CAST_SIZE(mSelectedLink)];
- graphics->setColor(mHyperLinkColor);
- graphics->drawLine(
- link.x1,
- link.y2,
- link.x2,
- link.y2);
- }
- }
-
- Font *const font = getFont();
-
- FOR_EACH (LinePartCIter, i, mLineParts)
- {
- const LinePart &part = *i;
- if (part.mY + 50 < mYStart)
- continue;
- if (part.mY > yEnd)
- break;
- if (part.mType == 0u)
- {
- if (part.mBold)
- {
- boldFont->drawString(graphics,
- part.mColor,
- part.mColor2,
- part.mText,
- part.mX, part.mY);
- }
- else
- {
- font->drawString(graphics,
- part.mColor,
- part.mColor2,
- part.mText,
- part.mX, part.mY);
- }
- }
- else if (part.mImage != nullptr)
- {
- graphics->drawImage(part.mImage, part.mX, part.mY);
- }
- }
-
- BLOCK_END("StaticBrowserBox::draw")
-}
-
-void StaticBrowserBox::safeDraw(Graphics *const graphics)
-{
- StaticBrowserBox::draw(graphics);
-}
-
-void StaticBrowserBox::updateHeight()
-{
- unsigned int y = CAST_U32(mPadding);
- int moreHeight = 0;
- int link = 0;
- bool bold = false;
- const unsigned int wWidth = CAST_U32(mDimension.width - mPadding);
- const Font *const font = getFont();
- const int fontHeight = font->getHeight() + 2 * mItemPadding;
- const int fontWidthMinus = font->getWidth("-");
-
- Color selColor[2] = {mForegroundColor, mForegroundColor2};
- const Color textColor[2] = {mForegroundColor, mForegroundColor2};
- mLineParts.clear();
- uint32_t dataWidth = 0;
-
- if (mSeparator)
- {
- mSeparator = false;
- mTextRows.pop_back();
- }
-
- FOR_EACH (TextRowCIter, i, mTextRows)
- {
- unsigned int x = CAST_U32(mPadding);
- const std::string row = *(i);
- int objects = 0;
-
- // Check for separator lines
- if (row.find("---", 0) == 0)
- {
- const int dashWidth = fontWidthMinus;
- for (x = CAST_U32(mPadding); x < wWidth; x ++)
- {
- mLineParts.push_back(LinePart(CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], "-", false));
- x += CAST_U32(CAST_S32(
- dashWidth) - 2);
- }
-
- y += CAST_U32(fontHeight);
- continue;
- }
- else if (mEnableImages && row.find("~~~", 0) == 0)
- {
- std::string str = row.substr(3);
- const size_t sz = str.size();
- if (sz > 2 && str.substr(sz - 1) == "~")
- str = str.substr(0, sz - 1);
- Image *const img = Loader::getImage(str);
- if (img != nullptr)
- {
- img->incRef();
- mLineParts.push_back(LinePart(CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], img));
- y += CAST_U32(img->getHeight() + 2);
- moreHeight += img->getHeight();
- if (img->getWidth() + mPadding + 2 > CAST_S32(dataWidth))
- dataWidth = img->getWidth() + 2 + mPadding;
- }
- continue;
- }
-
- Color prevColor[2];
- prevColor[0] = selColor[0];
- prevColor[1] = selColor[1];
- bold = false;
-
- for (size_t start = 0, end = std::string::npos;
- start != std::string::npos;
- start = end, end = std::string::npos)
- {
- size_t idx1 = end;
- size_t idx2 = end;
-
- // "Tokenize" the string at control sequences
- if (mUseLinksAndUserColors)
- idx1 = row.find("##", start + 1);
- if (start == 0 || mUseLinksAndUserColors)
- {
- // Check for color change in format "##x", x = [L,P,0..9]
- if (row.find("##", start) == start && row.size() > start + 2)
- {
- const signed char c = row.at(start + 2);
-
- bool valid(false);
- const Color col[2] =
- {
- getThemeCharColor(c, valid),
- getThemeCharColor(CAST_S8(
- c | 0x80), valid)
- };
-
- if (c == '>')
- {
- selColor[0] = prevColor[0];
- selColor[1] = prevColor[1];
- }
- else if (c == '<')
- {
- prevColor[0] = selColor[0];
- prevColor[1] = selColor[1];
- selColor[0] = col[0];
- selColor[1] = col[1];
- }
- else if (c == 'B')
- {
- bold = true;
- }
- else if (c == 'b')
- {
- bold = false;
- }
- else if (valid)
- {
- selColor[0] = col[0];
- selColor[1] = col[1];
- }
- else
- {
- switch (c)
- {
- case '0':
- selColor[0] = mColors[0][ColorName::BLACK];
- selColor[1] = mColors[1][ColorName::BLACK];
- break;
- case '1':
- selColor[0] = mColors[0][ColorName::RED];
- selColor[1] = mColors[1][ColorName::RED];
- break;
- case '2':
- selColor[0] = mColors[0][ColorName::GREEN];
- selColor[1] = mColors[1][ColorName::GREEN];
- break;
- case '3':
- selColor[0] = mColors[0][ColorName::BLUE];
- selColor[1] = mColors[1][ColorName::BLUE];
- break;
- case '4':
- selColor[0] = mColors[0][ColorName::ORANGE];
- selColor[1] = mColors[1][ColorName::ORANGE];
- break;
- case '5':
- selColor[0] = mColors[0][ColorName::YELLOW];
- selColor[1] = mColors[1][ColorName::YELLOW];
- break;
- case '6':
- selColor[0] = mColors[0][ColorName::PINK];
- selColor[1] = mColors[1][ColorName::PINK];
- break;
- case '7':
- selColor[0] = mColors[0][ColorName::PURPLE];
- selColor[1] = mColors[1][ColorName::PURPLE];
- break;
- case '8':
- selColor[0] = mColors[0][ColorName::GRAY];
- selColor[1] = mColors[1][ColorName::GRAY];
- break;
- case '9':
- selColor[0] = mColors[0][ColorName::BROWN];
- selColor[1] = mColors[1][ColorName::BROWN];
- break;
- default:
- selColor[0] = textColor[0];
- selColor[1] = textColor[1];
- break;
- }
- }
-
- if (c == '<' && link < CAST_S32(mLinks.size()))
- {
- int size;
- if (bold)
- {
- size = boldFont->getWidth(
- mLinks[CAST_SIZE(link)].caption) + 1;
- }
- else
- {
- size = font->getWidth(
- mLinks[CAST_SIZE(link)].caption) + 1;
- }
-
- BrowserLink &linkRef = mLinks[CAST_SIZE(
- link)];
- linkRef.x1 = CAST_S32(x);
- linkRef.y1 = CAST_S32(y);
- linkRef.x2 = linkRef.x1 + size;
- linkRef.y2 = CAST_S32(y) + fontHeight - 1;
- link++;
- }
-
- start += 3;
- if (start == row.size())
- break;
- }
- }
- if (mUseEmotes)
- idx2 = row.find("%%", start + 1);
- if (idx1 < idx2)
- end = idx1;
- else
- end = idx2;
- if (mUseEmotes)
- {
- // check for emote icons
- if (row.size() > start + 2 && row.substr(start, 2) == "%%")
- {
- if (objects < 5)
- {
- const int cid = row.at(start + 2) - '0';
- if (cid >= 0)
- {
- if (mEmotes != nullptr)
- {
- const size_t sz = mEmotes->size();
- if (CAST_SIZE(cid) < sz)
- {
- Image *const img = mEmotes->get(
- CAST_SIZE(cid));
- if (img != nullptr)
- {
- mLineParts.push_back(LinePart(
- CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], img));
- x += 18;
- }
- }
- }
- }
- objects ++;
- }
-
- start += 3;
- if (start == row.size())
- {
- if (x > dataWidth)
- dataWidth = x;
- break;
- }
- }
- }
- const size_t len = (end == std::string::npos) ? end : end - start;
-
- if (start >= row.length())
- break;
-
- std::string part = row.substr(start, len);
-
- mLineParts.push_back(LinePart(CAST_S32(x),
- CAST_S32(y) + mItemPadding,
- selColor[0], selColor[1], part.c_str(), bold));
-
- int width = 0;
- if (bold)
- width = boldFont->getWidth(part);
- else
- width = font->getWidth(part);
-
- x += CAST_U32(width);
- if (x > dataWidth)
- dataWidth = x;
- }
- y += CAST_U32(fontHeight);
- }
- mWidth = dataWidth + mPadding;
- mHeight = CAST_S32(mTextRows.size())
- * fontHeight + moreHeight + 2 * mPadding;
- setSize(mWidth,
- mHeight);
-}
-
-std::string StaticBrowserBox::getTextAtPos(const int x,
- const int y) const
-{
- int textX = 0;
- int textY = 0;
-
- getAbsolutePosition(textX, textY);
- if (x < textX || y < textY)
- return std::string();
-
- textY = y - textY;
- std::string str;
- int lastY = 0;
-
- FOR_EACH (LinePartCIter, i, mLineParts)
- {
- const LinePart &part = *i;
- if (part.mY + 50 < mYStart)
- continue;
- if (part.mY > textY)
- break;
-
- if (part.mY > lastY)
- {
- str = part.mText;
- lastY = part.mY;
- }
- else
- {
- str.append(part.mText);
- }
- }
-
- return str;
-}
-
-void StaticBrowserBox::setForegroundColorAll(const Color &color1,
- const Color &color2)
-{
- mForegroundColor = color1;
- mForegroundColor2 = color2;
-}
-
-void StaticBrowserBox::moveSelectionUp()
-{
- if (mSelectedLink <= 0)
- mSelectedLink = CAST_S32(mLinks.size()) - 1;
- else
- mSelectedLink --;
-}
-
-void StaticBrowserBox::moveSelectionDown()
-{
- mSelectedLink ++;
- if (mSelectedLink >= static_cast<signed int>(mLinks.size()))
- mSelectedLink = 0;
-}
-
-void StaticBrowserBox::selectSelection()
-{
- if ((mLinkHandler == nullptr) ||
- mSelectedLink < 0 ||
- mSelectedLink >= static_cast<signed int>(mLinks.size()))
- {
- return;
- }
-
- mLinkHandler->handleLink(mLinks[CAST_SIZE(mSelectedLink)].link,
- nullptr);
-}
diff --git a/src/gui/widgets/staticbrowserbox.h b/src/gui/widgets/staticbrowserbox.h
deleted file mode 100644
index ff5862577..000000000
--- a/src/gui/widgets/staticbrowserbox.h
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- * Copyright (C) 2009 Aethyra Development Team
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_STATICBROWSERBOX_H
-#define GUI_WIDGETS_STATICBROWSERBOX_H
-
-#include "enums/simpletypes/opaque.h"
-
-#include "enums/gui/colorname.h"
-
-#include "gui/browserlink.h"
-
-#include "gui/widgets/linepart.h"
-#include "gui/widgets/widget.h"
-
-#include "listeners/mouselistener.h"
-
-#include "localconsts.h"
-
-class LinkHandler;
-
-/**
- * A simple browser box able to handle links and forward events to the
- * parent conteiner.
- */
-class StaticBrowserBox final : public Widget,
- public MouseListener
-{
- public:
- /**
- * Constructor.
- */
- StaticBrowserBox(const Widget2 *const widget,
- const Opaque opaque,
- const std::string &skin);
-
- A_DELETE_COPY(StaticBrowserBox)
-
- /**
- * Destructor.
- */
- ~StaticBrowserBox();
-
- /**
- * Sets the handler for links.
- */
- void setLinkHandler(LinkHandler *linkHandler);
-
- /**
- * Sets the StaticBrowserBox opacity.
- */
- void setOpaque(Opaque opaque)
- { mOpaque = opaque; }
-
- void addSeparator(const std::string &row);
-
- /**
- * Adds a text row to the browser.
- */
- void addRow(const std::string &row,
- const bool atTop = false);
-
- /**
- * Adds a menu line to the browser.
- */
- void addRow(const std::string &cmd,
- const char *const text);
-
- void addImage(const std::string &path);
-
- /**
- * Remove all rows.
- */
- void clearRows();
-
- /**
- * Handles mouse actions.
- */
- void mousePressed(MouseEvent &event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void mouseExited(MouseEvent& event) override final;
-
- /**
- * Draws the browser box.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void updateHeight();
-
- void updateSize();
-
- typedef std::list<std::string> TextRows;
-
- TextRows &getRows() noexcept2 A_WARN_UNUSED
- { return mTextRows; }
-
- bool hasRows() const noexcept2 A_WARN_UNUSED
- { return !mTextRows.empty(); }
-
- void setProcessVars(const bool n) noexcept2
- { mProcessVars = n; }
-
- void setEnableImages(const bool n) noexcept2
- { mEnableImages = n; }
-
- void setEnableKeys(const bool n) noexcept2
- { mEnableKeys = n; }
-
- void setEnableTabs(const bool n) noexcept2
- { mEnableTabs = n; }
-
- std::string getTextAtPos(const int x,
- const int y) const A_WARN_UNUSED;
-
- int getPadding() const noexcept2 A_WARN_UNUSED
- { return mPadding; }
-
- void setForegroundColorAll(const Color &color1,
- const Color &color2);
-
- void moveSelectionUp();
-
- void moveSelectionDown();
-
- void selectSelection();
-
- private:
- typedef TextRows::iterator TextRowIterator;
- typedef TextRows::const_iterator TextRowCIter;
- TextRows mTextRows;
- std::list<int> mTextRowLinksCount;
-
- typedef STD_VECTOR<LinePart> LinePartList;
- typedef LinePartList::iterator LinePartIterator;
- typedef LinePartList::const_iterator LinePartCIter;
- LinePartList mLineParts;
-
- typedef STD_VECTOR<BrowserLink> Links;
- typedef Links::iterator LinkIterator;
- Links mLinks;
-
- LinkHandler *mLinkHandler;
- Skin *mSkin;
- unsigned int mHighlightMode;
- int mSelectedLink;
- int mHeight;
- int mWidth;
- int mYStart;
- int mPadding;
- unsigned int mNewLinePadding;
- int mItemPadding;
-
- Color mHighlightColor;
- Color mHyperLinkColor;
- Color mColors[2][ColorName::COLORS_MAX];
-
- Opaque mOpaque;
- bool mUseLinksAndUserColors;
- bool mUseEmotes;
- bool mProcessVars;
- bool mEnableImages;
- bool mEnableKeys;
- bool mEnableTabs;
- bool mSeparator;
-
- static ImageSet *mEmotes;
- static int mInstances;
-};
-
-#endif // GUI_WIDGETS_STATICBROWSERBOX_H
diff --git a/src/gui/widgets/statspage.cpp b/src/gui/widgets/statspage.cpp
deleted file mode 100644
index 0540b1a24..000000000
--- a/src/gui/widgets/statspage.cpp
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/statspage.h"
-
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/vertcontainer.h"
-
-#include "gui/widgets/attrs/derdisplay.h"
-
-#include "utils/foreach.h"
-
-#include "resources/db/statdb.h"
-
-#include "debug.h"
-
-StatsPage::StatsPage(const Widget2 *const widget,
- const std::string &page) :
- Container(widget),
- WidgetListener(),
- AttributeListener(),
- StatListener(),
- mAttrs(),
- mAttrCont(new VertContainer(this, 32)),
- mAttrScroll(new ScrollArea(this, mAttrCont, Opaque_false))
-{
- addWidgetListener(this);
- setSelectable(false);
-
- mAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
- mAttrScroll->setSelectable(false);
- mAttrCont->setSelectable(false);
-
- add(mAttrScroll);
- const STD_VECTOR<BasicStat> &basicStats = StatDb::getStats(page);
- FOR_EACH (STD_VECTOR<BasicStat>::const_iterator, it, basicStats)
- {
- const BasicStat &stat = *it;
- AttrDisplay *disp = new DerDisplay(this,
- stat.attr,
- stat.name,
- stat.tag);
- disp->update();
- mAttrCont->add2(disp, true);
- mAttrs[stat.attr] = disp;
- }
-}
-
-void StatsPage::widgetResized(const Event &event A_UNUSED)
-{
- mAttrScroll->setSize(getWidth(), getHeight());
-}
-
-void StatsPage::attributeChanged(const AttributesT id,
- const int64_t oldVal A_UNUSED,
- const int64_t newVal A_UNUSED)
-{
- const Attrs::const_iterator it = mAttrs.find(id);
- if (it != mAttrs.end() && (it->second != nullptr))
- it->second->update();
-}
-
-void StatsPage::statChanged(const AttributesT id,
- const int oldVal1 A_UNUSED,
- const int oldVal2 A_UNUSED)
-{
- const Attrs::const_iterator it = mAttrs.find(id);
- if (it != mAttrs.end() && (it->second != nullptr))
- it->second->update();
-}
diff --git a/src/gui/widgets/statspage.h b/src/gui/widgets/statspage.h
deleted file mode 100644
index ad62aebeb..000000000
--- a/src/gui/widgets/statspage.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_STATSPAGE_H
-#define GUI_WIDGETS_STATSPAGE_H
-
-#include "gui/widgets/attrs/attrdisplay.h"
-
-#include "listeners/attributelistener.h"
-#include "listeners/statlistener.h"
-
-#include "localconsts.h"
-
-class ScrollArea;
-class VertContainer;
-
-class StatsPage final : public Container,
- public WidgetListener,
- public AttributeListener,
- public StatListener
-{
- public:
- StatsPage(const Widget2 *const widget,
- const std::string &page);
-
- A_DELETE_COPY(StatsPage)
-
- void widgetResized(const Event &event) override final;
-
- void attributeChanged(const AttributesT id,
- const int64_t oldVal,
- const int64_t newVal) override final;
-
- void statChanged(const AttributesT id,
- const int oldVal1,
- const int oldVal2) override final;
-
- private:
- Attrs mAttrs;
- VertContainer *mAttrCont A_NONNULLPOINTER;
- ScrollArea *mAttrScroll A_NONNULLPOINTER;
-};
-
-#endif // GUI_WIDGETS_STATSPAGE_H
diff --git a/src/gui/widgets/statspagebasic.cpp b/src/gui/widgets/statspagebasic.cpp
deleted file mode 100644
index 249d4f337..000000000
--- a/src/gui/widgets/statspagebasic.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/statspagebasic.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/vertcontainer.h"
-
-#include "gui/widgets/attrs/changedisplay.h"
-
-#include "utils/gettext.h"
-#include "utils/foreach.h"
-#include "utils/stringutils.h"
-
-#include "resources/db/statdb.h"
-
-#include "debug.h"
-
-StatsPageBasic::StatsPageBasic(const Widget2 *const widget) :
- Container(widget),
- WidgetListener(),
- AttributeListener(),
- StatListener(),
- mAttrs(),
- mAttrCont(new VertContainer(this, 32)),
- mAttrScroll(new ScrollArea(this, mAttrCont, Opaque_false)),
- mCharacterPointsLabel(new Label(this, "C"))
-{
- addWidgetListener(this);
- setSelectable(false);
-
- mAttrScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mAttrScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
- mAttrScroll->setSelectable(false);
- mAttrCont->setSelectable(false);
-
- add(mAttrScroll);
- const STD_VECTOR<BasicStat> &basicStats = StatDb::getBasicStats();
- FOR_EACH (STD_VECTOR<BasicStat>::const_iterator, it, basicStats)
- {
- const BasicStat &stat = *it;
- AttrDisplay *disp = new ChangeDisplay(this,
- stat.attr,
- stat.name,
- stat.tag);
- disp->update();
- mAttrCont->add2(disp, true);
- mAttrs[stat.attr] = disp;
- }
-
- // TRANSLATORS: status window label
- mCharacterPointsLabel->setCaption(strprintf(_("Character points: %d"),
- PlayerInfo::getAttribute(Attributes::PLAYER_CHAR_POINTS)));
- mCharacterPointsLabel->adjustSize();
- mAttrCont->add1(mCharacterPointsLabel);
-}
-
-void StatsPageBasic::widgetResized(const Event &event A_UNUSED)
-{
- mAttrScroll->setSize(getWidth(), getHeight());
-}
-
-void StatsPageBasic::statChanged(const AttributesT id,
- const int oldVal1 A_UNUSED,
- const int oldVal2 A_UNUSED)
-{
- const Attrs::const_iterator it = mAttrs.find(id);
- if (it != mAttrs.end() && (it->second != nullptr))
- it->second->update();
-}
-
-void StatsPageBasic::attributeChanged(const AttributesT id,
- const int64_t oldVal A_UNUSED,
- const int64_t newVal)
-{
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (id)
- {
- case Attributes::PLAYER_CHAR_POINTS:
- mCharacterPointsLabel->setCaption(strprintf(
- // TRANSLATORS: status window label
- _("Character points: %d"), CAST_S32(newVal)));
-
- mCharacterPointsLabel->adjustSize();
- // Update all attributes
- for (Attrs::const_iterator it = mAttrs.begin();
- it != mAttrs.end(); ++it)
- {
- if (it->second != nullptr)
- it->second->update();
- }
- return;
-
- case Attributes::PLAYER_CORR_POINTS:
- // Update all attributes
- for (Attrs::const_iterator it = mAttrs.begin();
- it != mAttrs.end(); ++it)
- {
- if (it->second != nullptr)
- it->second->update();
- }
- return;
-
- default:
- break;
- }
- PRAGMA45(GCC diagnostic pop)
- const Attrs::const_iterator it = mAttrs.find(id);
- if (it != mAttrs.end() && (it->second != nullptr))
- it->second->update();
-}
-
-void StatsPageBasic::setPointsNeeded(const AttributesT id,
- const int needed)
-{
- const Attrs::const_iterator it = mAttrs.find(id);
-
- if (it != mAttrs.end())
- {
- AttrDisplay *const disp = it->second;
- if ((disp != nullptr) && disp->getType() == AttrDisplay::CHANGEABLE)
- static_cast<ChangeDisplay*>(disp)->setPointsNeeded(needed);
- }
-}
-
-std::string StatsPageBasic::getStatsStr() const
-{
- Attrs::const_iterator it = mAttrs.begin();
- const Attrs::const_iterator it_end = mAttrs.end();
- std::string str;
- while (it != it_end)
- {
- const ChangeDisplay *const attr = dynamic_cast<ChangeDisplay*>(
- (*it).second);
- if (attr != nullptr)
- {
- str.append(strprintf("%s:%s ", attr->getShortName().c_str(),
- attr->getValue().c_str()));
- }
- ++ it;
- }
- return str;
-}
diff --git a/src/gui/widgets/statspagebasic.h b/src/gui/widgets/statspagebasic.h
deleted file mode 100644
index d56b8aeff..000000000
--- a/src/gui/widgets/statspagebasic.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_STATSPAGEBASIC_H
-#define GUI_WIDGETS_STATSPAGEBASIC_H
-
-#include "gui/widgets/attrs/attrdisplay.h"
-
-#include "listeners/attributelistener.h"
-#include "listeners/statlistener.h"
-
-#include "localconsts.h"
-
-class Label;
-class ScrollArea;
-class VertContainer;
-
-class StatsPageBasic final : public Container,
- public WidgetListener,
- public AttributeListener,
- public StatListener
-{
- public:
- explicit StatsPageBasic(const Widget2 *const widget);
-
- A_DELETE_COPY(StatsPageBasic)
-
- void widgetResized(const Event &event) override final;
-
- void attributeChanged(const AttributesT id,
- const int64_t oldVal,
- const int64_t newVal) override final;
-
- void statChanged(const AttributesT id,
- const int oldVal1,
- const int oldVal2) override final;
-
- void setPointsNeeded(const AttributesT id,
- const int needed);
-
- std::string getStatsStr() const;
-
- private:
- Attrs mAttrs;
- VertContainer *mAttrCont A_NONNULLPOINTER;
- ScrollArea *mAttrScroll A_NONNULLPOINTER;
- Label *mCharacterPointsLabel A_NONNULLPOINTER;
-};
-
-#endif // GUI_WIDGETS_STATSPAGEBASIC_H
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
deleted file mode 100644
index e89f60418..000000000
--- a/src/gui/widgets/tabbedarea.cpp
+++ /dev/null
@@ -1,827 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/tabbedarea.h"
-
-#include "gui/gui.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/tabs/tab.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-TabbedArea::TabbedArea(const Widget2 *const widget) :
- ActionListener(),
- BasicContainer(widget),
- KeyListener(),
- MouseListener(),
- WidgetListener(),
- mArrowButton(),
- mSelectedTab(nullptr),
- mTabContainer(new BasicContainer2(widget)),
- mWidgetContainer(new BasicContainer2(widget)),
- mTabsToDelete(),
- mTabs(),
- mTabsWidth(0),
- mVisibleTabsWidth(0),
- mTabScrollIndex(0),
- mRightMargin(0),
- mOpaque(Opaque_false),
- mEnableScrollButtons(false),
- mFollowDownScroll(false),
- mBlockSwitching(true),
- mResizeHeight(true)
-{
- setFocusable(true);
- addKeyListener(this);
- addMouseListener(this);
-}
-
-void TabbedArea::postInit()
-{
- mTabContainer->setOpaque(Opaque_false);
-
- add(mTabContainer);
- add(mWidgetContainer);
-
- mWidgetContainer->setOpaque(Opaque_false);
- addWidgetListener(this);
-
- mArrowButton[0] = new Button(this, "<", "shift_left", this);
- mArrowButton[1] = new Button(this, ">", "shift_right", this);
-
- widgetResized(Event(nullptr));
-}
-
-TabbedArea::~TabbedArea()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- // +++ virtual method calls
- remove(mTabContainer);
- remove(mWidgetContainer);
-
- delete2(mTabContainer);
- delete2(mWidgetContainer);
-
- for (size_t i = 0, sz = mTabsToDelete.size(); i < sz; i++)
- delete2(mTabsToDelete[i])
-
- delete2(mArrowButton[0]);
- delete2(mArrowButton[1]);
-}
-
-void TabbedArea::enableScrollButtons(const bool enable)
-{
- if (mEnableScrollButtons && !enable)
- {
- if (mArrowButton[0] != nullptr)
- remove(mArrowButton[0]);
- if (mArrowButton[1] != nullptr)
- remove(mArrowButton[1]);
- }
- else if (!mEnableScrollButtons && enable)
- {
- if (mArrowButton[0] != nullptr)
- add(mArrowButton[0]);
- if (mArrowButton[1] != nullptr)
- add(mArrowButton[1]);
- }
- mEnableScrollButtons = enable;
-}
-
-int TabbedArea::getNumberOfTabs() const
-{
- return CAST_S32(mTabs.size());
-}
-
-Tab *TabbedArea::getTab(const std::string &name) const
-{
- TabContainer::const_iterator itr = mTabs.begin();
- const TabContainer::const_iterator itr_end = mTabs.end();
- while (itr != itr_end)
- {
- if ((*itr).first->getCaption() == name)
- return static_cast<Tab*>((*itr).first);
-
- ++itr;
- }
- return nullptr;
-}
-
-void TabbedArea::draw(Graphics *const graphics)
-{
- BLOCK_START("TabbedArea::draw")
- if (mTabs.empty())
- {
- BLOCK_END("TabbedArea::draw")
- return;
- }
-
- drawChildren(graphics);
- BLOCK_END("TabbedArea::draw")
-}
-
-void TabbedArea::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("TabbedArea::draw")
- if (mTabs.empty())
- {
- BLOCK_END("TabbedArea::draw")
- return;
- }
-
- safeDrawChildren(graphics);
- BLOCK_END("TabbedArea::draw")
-}
-
-Widget *TabbedArea::getWidget(const std::string &name) const
-{
- TabContainer::const_iterator itr = mTabs.begin();
- const TabContainer::const_iterator itr_end = mTabs.end();
- while (itr != itr_end)
- {
- if ((*itr).first->getCaption() == name)
- return (*itr).second;
-
- ++itr;
- }
-
- return nullptr;
-}
-
-Widget *TabbedArea::getCurrentWidget() const
-{
- const Tab *const tab = getSelectedTab();
-
- if (tab != nullptr)
- return getWidget(tab->getCaption());
- return nullptr;
-}
-
-void TabbedArea::addTab(Tab *const tab,
- Widget *const widget)
-{
- if ((tab == nullptr) || (widget == nullptr))
- return;
-
- tab->setTabbedArea(this);
- tab->addActionListener(this);
-
- mTabContainer->add(tab);
- mTabs.push_back(std::pair<Tab*, Widget*>(tab, widget));
-
- if ((mSelectedTab == nullptr) && tab->mVisible == Visible_true)
- setSelectedTab(tab);
-
- adjustTabPositions();
- adjustSize();
-
- const int frameSize = 2 * mFrameSize;
- widget->setSize(getWidth() - frameSize,
- getHeight() - frameSize - mTabContainer->getHeight());
-
- widgetResized(Event(nullptr));
- updateTabsWidth();
- updateArrowEnableState();
-}
-
-void TabbedArea::adjustWidget(Widget *const widget) const
-{
- if (widget == nullptr)
- return;
- const int frameSize = 2 * mFrameSize;
- widget->setSize(getWidth() - frameSize,
- getHeight() - frameSize - mTabContainer->getHeight());
-}
-
-void TabbedArea::addTab(const std::string &caption, Widget *const widget)
-{
- Tab *const tab = new Tab(this);
- tab->setCaption(caption);
- mTabsToDelete.push_back(tab);
-
- addTab(tab, widget);
-}
-
-void TabbedArea::addTab(Image *const image, Widget *const widget)
-{
- Tab *const tab = new Tab(this);
- tab->setImage(image);
- mTabsToDelete.push_back(tab);
-
- addTab(tab, widget);
-}
-
-bool TabbedArea::isTabSelected(const size_t index) const
-{
- if (index >= mTabs.size())
- return false;
-
- return mSelectedTab == mTabs[index].first;
-}
-
-bool TabbedArea::isTabPresent(const Tab *const tab) const
-{
- FOR_EACH (TabContainer::const_iterator, it, mTabs)
- {
- if ((*it).first == tab || (*it).second == tab)
- return true;
- }
- return false;
-}
-
-bool TabbedArea::isTabSelected(const Tab *const tab) const
-{
- return mSelectedTab == tab;
-}
-
-void TabbedArea::setSelectedTabByIndex(const size_t index)
-{
- if (index >= mTabs.size())
- return;
-
- setSelectedTab(mTabs[index].first);
-}
-
-void TabbedArea::removeTab(Tab *const tab)
-{
- int tabIndexToBeSelected = -1;
-
- if (tab == mSelectedTab)
- {
- const int index = getSelectedTabIndex();
- const size_t sz = mTabs.size();
- if (index == CAST_S32(sz) - 1 && sz == 1)
- tabIndexToBeSelected = -1;
- else
- tabIndexToBeSelected = index - 1;
- }
-
- for (TabContainer::iterator iter = mTabs.begin();
- iter != mTabs.end(); ++iter)
- {
- if (iter->first == tab)
- {
- mTabContainer->remove(tab);
- mTabs.erase(iter);
- break;
- }
- }
-
- for (STD_VECTOR<Tab*>::iterator iter2 = mTabsToDelete.begin();
- iter2 != mTabsToDelete.end(); ++iter2)
- {
- if (*iter2 == tab)
- {
- mTabsToDelete.erase(iter2);
- delete tab;
- break;
- }
- }
-
- const int tabsSize = CAST_S32(mTabs.size());
- if (tabIndexToBeSelected >= tabsSize)
- tabIndexToBeSelected = tabsSize - 1;
- if (tabIndexToBeSelected < -1)
- tabIndexToBeSelected = -1;
-
- if (tabIndexToBeSelected == -1)
- {
- mSelectedTab = nullptr;
- mWidgetContainer->clear();
- }
- else
- {
- setSelectedTabByIndex(tabIndexToBeSelected);
- }
-
- adjustSize();
- updateTabsWidth();
- widgetResized(Event(nullptr));
-}
-
-void TabbedArea::logic()
-{
- BLOCK_START("TabbedArea::logic")
- logicChildren();
- BLOCK_END("TabbedArea::logic")
-}
-
-void TabbedArea::mousePressed(MouseEvent &event)
-{
- if (event.isConsumed())
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- Widget *const widget = mTabContainer->getWidgetAt(
- event.getX(), event.getY());
- Tab *const tab = dynamic_cast<Tab *>(widget);
-
- if (tab != nullptr)
- {
- event.consume();
- setSelectedTab(tab);
- requestFocus();
- }
- }
-}
-
-void TabbedArea::setSelectedTab(Tab *const tab)
-{
- for (size_t i = 0; i < mTabs.size(); i++)
- {
- if (mTabs[i].first == mSelectedTab)
- mWidgetContainer->remove(mTabs[i].second);
- }
-
- for (size_t i = 0; i < mTabs.size(); i++)
- {
- if (mTabs[i].first == tab)
- {
- mSelectedTab = tab;
- mWidgetContainer->add(mTabs[i].second);
- }
- }
-
- Tab *const newTab = tab;
-
- if (newTab != nullptr)
- newTab->setCurrent();
-
- widgetResized(Event(nullptr));
-}
-
-void TabbedArea::setSelectedTabDefault()
-{
- if (mSelectedTab == nullptr ||
- mSelectedTab->mVisible == Visible_false)
- {
- for (size_t i = 0; i < mTabs.size(); i++)
- {
- Tab *const tab = mTabs[i].first;
- if ((tab != nullptr) && tab->mVisible == Visible_true)
- {
- setSelectedTab(tab);
- return;
- }
- }
- }
-}
-
-int TabbedArea::getSelectedTabIndex() const
-{
- for (unsigned int i = 0, fsz = CAST_U32(mTabs.size());
- i < fsz;
- i++)
- {
- if (mTabs[i].first == mSelectedTab)
- return i;
- }
-
- return -1;
-}
-
-void TabbedArea::setSelectedTabByName(const std::string &name)
-{
- FOR_EACH (TabContainer::const_iterator, itr, mTabs)
- {
- if (((*itr).first != nullptr) && (*itr).first->getCaption() == name)
- {
- setSelectedTab((*itr).first);
- return;
- }
- }
-}
-
-void TabbedArea::widgetResized(const Event &event A_UNUSED)
-{
- adjustSize();
-
- const int frameSize = 2 * mFrameSize;
- const int widgetFrameSize = 2 * mWidgetContainer->getFrameSize();
- const int w1 = mDimension.width;
- const int h1 = mDimension.height;
- const int width = w1 - frameSize - widgetFrameSize;
- const int height = h1 - frameSize
- - mWidgetContainer->getY() - widgetFrameSize;
-
- Widget *const w = getCurrentWidget();
- ScrollArea *const scr = dynamic_cast<ScrollArea *>(w);
- if (scr != nullptr)
- {
- if (mFollowDownScroll && height != 0)
- {
- const Rect &rect = w->getDimension();
- if (rect.height != 0 && rect.height > height + 2)
- {
- if (scr->getVerticalScrollAmount()
- >= scr->getVerticalMaxScroll() - 2
- && scr->getVerticalScrollAmount()
- <= scr->getVerticalMaxScroll() + 2)
- {
- const int newScroll = scr->getVerticalScrollAmount()
- + rect.height - height;
- w->setSize(mWidgetContainer->getWidth() - frameSize,
- mWidgetContainer->getHeight() - frameSize);
- if (newScroll != 0)
- scr->setVerticalScrollAmount(newScroll);
- }
- }
- }
- }
-
- if (mArrowButton[1] != nullptr)
- {
- // Check whether there is room to show more tabs now.
- int innerWidth = w1 - 4 - mArrowButton[0]->getWidth()
- - mArrowButton[1]->getWidth() - mRightMargin;
- if (innerWidth < 0)
- innerWidth = 0;
-
- int newWidth = mVisibleTabsWidth;
- while ((mTabScrollIndex != 0u) && newWidth < innerWidth)
- {
- Tab *const tab = mTabs[mTabScrollIndex - 1].first;
- if ((tab != nullptr) && tab->mVisible == Visible_true)
- {
- newWidth += tab->getWidth();
- if (newWidth < innerWidth)
- --mTabScrollIndex;
- }
- }
-
- if (mArrowButton[1] != nullptr)
- {
- // Move the right arrow to fit the windows content.
- newWidth = width - mArrowButton[1]->getWidth() - mRightMargin;
- if (newWidth < 0)
- newWidth = 0;
- mArrowButton[1]->setPosition(newWidth, 0);
- }
- }
-
- updateArrowEnableState();
- adjustTabPositions();
-}
-
-void TabbedArea::updateTabsWidth()
-{
- mTabsWidth = 0;
- FOR_EACH (TabContainer::const_iterator, itr, mTabs)
- {
- Tab *const tab = (*itr).first;
- if ((tab != nullptr) && tab->mVisible == Visible_true)
- mTabsWidth += tab->getWidth();
- }
- updateVisibleTabsWidth();
-}
-
-void TabbedArea::updateVisibleTabsWidth()
-{
- mVisibleTabsWidth = 0;
- for (size_t i = mTabScrollIndex, sz = mTabs.size(); i < sz; ++i)
- {
- Tab *const tab = mTabs[i].first;
- if ((tab != nullptr) && tab->mVisible == Visible_true)
- mVisibleTabsWidth += CAST_S32(tab->getWidth());
- }
-}
-
-void TabbedArea::adjustSize()
-{
- int maxTabHeight = 0;
-
- const int width = mDimension.width;
- const int height = mDimension.height;
-
- for (size_t i = 0, sz = mTabs.size(); i < sz; i++)
- {
- if (mTabs[i].first->getHeight() > maxTabHeight)
- maxTabHeight = mTabs[i].first->getHeight();
- }
-
- mTabContainer->setSize(width - mRightMargin, maxTabHeight);
-
- mWidgetContainer->setPosition(0, maxTabHeight);
- mWidgetContainer->setSize(width, height - maxTabHeight);
- Widget *const w = getCurrentWidget();
- if (w != nullptr)
- {
- const int wFrameSize = w->getFrameSize();
- const int frame2 = 2 * wFrameSize;
-
- w->setPosition(wFrameSize, wFrameSize);
- if (mResizeHeight)
- {
- w->setSize(mWidgetContainer->getWidth() - frame2,
- mWidgetContainer->getHeight() - frame2);
- }
- else
- {
- w->setSize(mWidgetContainer->getWidth() - frame2,
- w->getHeight());
- }
- }
-}
-
-void TabbedArea::adjustTabPositions()
-{
- int maxTabHeight = 0;
- const size_t sz = mTabs.size();
- for (size_t i = 0; i < sz; ++i)
- {
- const Tab *const tab = mTabs[i].first;
- if ((tab != nullptr) &&
- tab->mVisible == Visible_true &&
- tab->getHeight() > maxTabHeight)
- {
- maxTabHeight = tab->getHeight();
- }
- }
-
- int x = (mEnableScrollButtons && mArrowButton[0]->mVisible == Visible_true)
- ? mArrowButton[0]->getWidth() : 0;
- for (size_t i = mTabScrollIndex; i < sz; ++i)
- {
- Tab *const tab = mTabs[i].first;
- if ((tab == nullptr) || tab->mVisible == Visible_false)
- continue;
- tab->setPosition(x, maxTabHeight - tab->getHeight());
- x += tab->getWidth();
- }
-
- // If the tabs are scrolled, we hide them away.
- if (mTabScrollIndex > 0)
- {
- x = 0;
- for (unsigned i = 0; i < mTabScrollIndex; ++i)
- {
- Tab *const tab = mTabs[i].first;
- if ((tab != nullptr) && tab->mVisible == Visible_true)
- {
- x -= tab->getWidth();
- tab->setPosition(x, maxTabHeight - tab->getHeight());
- }
- }
- }
-}
-
-void TabbedArea::action(const ActionEvent& actionEvent)
-{
- Widget *const source = actionEvent.getSource();
- Tab *const tab = dynamic_cast<Tab *>(source);
-
- if (tab != nullptr)
- {
- setSelectedTab(tab);
- }
- else
- {
- const std::string &eventId = actionEvent.getId();
- if (eventId == "shift_left")
- {
- if (mTabScrollIndex != 0u)
- --mTabScrollIndex;
- }
- else if (eventId == "shift_right")
- {
- if (CAST_SIZE(mTabScrollIndex) < mTabs.size() - 1)
- ++mTabScrollIndex;
- }
- adjustTabPositions();
- updateArrowEnableState();
- }
-}
-
-void TabbedArea::updateArrowEnableState()
-{
- updateTabsWidth();
- if ((mArrowButton[0] == nullptr) || (mArrowButton[1] == nullptr))
- return;
-
- const int width = mDimension.width;
- if (mTabsWidth > width - 4
- - mArrowButton[0]->getWidth()
- - mArrowButton[1]->getWidth() - mRightMargin)
- {
- mArrowButton[0]->setVisible(Visible_true);
- mArrowButton[1]->setVisible(Visible_true);
- }
- else
- {
- mArrowButton[0]->setVisible(Visible_false);
- mArrowButton[1]->setVisible(Visible_false);
- mTabScrollIndex = 0;
- }
-
- // Left arrow consistency check
- if (mTabScrollIndex == 0u)
- mArrowButton[0]->setEnabled(false);
- else
- mArrowButton[0]->setEnabled(true);
-
- // Right arrow consistency check
- if (mVisibleTabsWidth < width - 4
- - mArrowButton[0]->getWidth()
- - mArrowButton[1]->getWidth() - mRightMargin)
- {
- mArrowButton[1]->setEnabled(false);
- }
- else
- {
- mArrowButton[1]->setEnabled(true);
- }
-}
-
-Tab *TabbedArea::getTabByIndex(const int index) const
-{
- if (index < 0 || index >= CAST_S32(mTabs.size()))
- return nullptr;
- return static_cast<Tab*>(mTabs[index].first);
-}
-
-Widget *TabbedArea::getWidgetByIndex(const int index) const
-{
- if (index < 0 || index >= CAST_S32(mTabs.size()))
- return nullptr;
- return mTabs[index].second;
-}
-
-void TabbedArea::removeAll(const bool del)
-{
- if (getSelectedTabIndex() != -1)
- {
- setSelectedTabByIndex(CAST_U32(0));
- }
- while (getNumberOfTabs() > 0)
- {
- const int idx = getNumberOfTabs() - 1;
- Tab *tab = mTabs[idx].first;
- Widget *widget = mTabs[idx].second;
- removeTab(tab);
- if (del)
- {
- delete tab;
- delete widget;
- }
- }
-}
-
-void TabbedArea::setWidth(int width)
-{
- // +++ need use virtual
- Widget::setWidth(width);
- adjustSize();
-}
-
-void TabbedArea::setHeight(int height)
-{
- // +++ need use virtual
- Widget::setHeight(height);
- adjustSize();
-}
-
-void TabbedArea::setSize(int width, int height)
-{
- // +++ need use virtual
- Widget::setSize(width, height);
- adjustSize();
-}
-
-void TabbedArea::setDimension(const Rect &dimension)
-{
- // +++ need use virtual
- Widget::setDimension(dimension);
- adjustSize();
-}
-
-void TabbedArea::keyPressed(KeyEvent& event)
-{
- if (mBlockSwitching || event.isConsumed() || !isFocused())
- return;
-
- const InputActionT actionId = event.getActionId();
-
- if (actionId == InputAction::GUI_LEFT)
- {
- int index = getSelectedTabIndex();
- index--;
-
- if (index < 0)
- return;
-
- setSelectedTab(mTabs[index].first);
- event.consume();
- }
- else if (actionId == InputAction::GUI_RIGHT)
- {
- int index = getSelectedTabIndex();
- index++;
-
- if (index >= CAST_S32(mTabs.size()))
- return;
-
- setSelectedTab(mTabs[index].first);
- event.consume();
- }
-}
-
-void TabbedArea::death(const Event &event)
-{
- Tab *const tab = dynamic_cast<Tab*>(event.getSource());
-
- if (tab != nullptr)
- removeTab(tab);
- else
- BasicContainer::death(event);
-}
-
-void TabbedArea::selectNextTab()
-{
- int tab = getSelectedTabIndex();
- tab++;
- if (tab == CAST_S32(mTabs.size()))
- tab = 0;
- setSelectedTab(mTabs[tab].first);
-}
-
-void TabbedArea::selectPrevTab()
-{
- int tab = getSelectedTabIndex();
-
- if (tab == 0)
- tab = CAST_S32(mTabs.size());
- if (tab < 0)
- return;
- tab--;
- setSelectedTab(mTabs[tab].first);
-}
diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h
deleted file mode 100644
index c971da391..000000000
--- a/src/gui/widgets/tabbedarea.h
+++ /dev/null
@@ -1,299 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_TABBEDAREA_H
-#define GUI_WIDGETS_TABBEDAREA_H
-
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "gui/widgets/basiccontainer2.h"
-
-#include "listeners/actionlistener.h"
-
-class Button;
-class Image;
-class Tab;
-
-/**
- * A tabbed area, the same as the guichan tabbed area in 0.8, but extended
- */
-class TabbedArea final : public ActionListener,
- public BasicContainer,
- public KeyListener,
- public MouseListener,
- public WidgetListener
-{
- public:
- /**
- * Constructor.
- */
- explicit TabbedArea(const Widget2 *const widget);
-
- A_DELETE_COPY(TabbedArea)
-
- ~TabbedArea();
-
- void postInit() override final;
-
- /**
- * Draw the tabbed area.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Return how many tabs have been created.
- */
- int getNumberOfTabs() const A_WARN_UNUSED;
-
- /**
- * Return tab with specified name as caption.
- */
- Tab *getTab(const std::string &name) const A_WARN_UNUSED;
-
- Tab *getTabByIndex(const int index) const A_WARN_UNUSED;
-
- Widget *getWidgetByIndex(const int index) const A_WARN_UNUSED;
-
- /**
- * Returns the widget with the tab that has specified caption
- */
- Widget *getWidget(const std::string &name) const A_WARN_UNUSED;
-
- /**
- * Returns the widget for the current tab
- */
- Widget *getCurrentWidget() const A_WARN_UNUSED;
-
- /**
- * Add a tab. Overridden since it needs to size the widget.
- *
- * @param tab The tab widget for the tab.
- * @param widget The widget to view when the tab is selected.
- */
- void addTab(Tab *const tab, Widget *const widget);
-
- void addTab(const std::string &caption, Widget *const widget);
-
- void addTab(Image *const image, Widget *const widget);
-
- bool isTabSelected(const size_t index) const A_WARN_UNUSED;
-
- bool isTabSelected(const Tab *const tab) const A_WARN_UNUSED;
-
- bool isTabPresent(const Tab *const tab) const A_WARN_UNUSED;
-
- /**
- * Overload the remove tab function as it's broken in guichan 0.8.
- */
- void removeTab(Tab *const tab);
-
- void removeAll(const bool del = true);
-
- /**
- * Overload the logic function since it's broken in guichan 0.8.
- */
- void logic() override final;
-
- int getContainerHeight() const noexcept2 A_WARN_UNUSED
- { return mWidgetContainer->getHeight(); }
-
- void setSelectedTab(Tab *const tab);
-
- void setSelectedTabDefault();
-
- void setSelectedTabByIndex(const size_t index);
-
- int getSelectedTabIndex() const A_WARN_UNUSED;
-
- Tab* getSelectedTab() const noexcept2 A_WARN_UNUSED
- { return mSelectedTab; }
-
- void setOpaque(const Opaque opaque)
- { mOpaque = opaque; }
-
- bool isOpaque() const noexcept2 A_WARN_UNUSED
- { return mOpaque == Opaque_true; }
-
- void adjustSize();
-
- void setSelectedTabByName(const std::string &name);
-
- void widgetResized(const Event &event) override final;
-
-/*
- void moveLeft(Tab *tab);
-
- void moveRight(Tab *tab);
-*/
- void adjustTabPositions();
-
- void action(const ActionEvent& actionEvent) override final;
-
- // Inherited from MouseListener
-
- void mousePressed(MouseEvent &event) override final;
-
- void enableScrollButtons(const bool enable);
-
- void setRightMargin(const int n) noexcept2
- { mRightMargin = n; }
-
- int getRightMargin() const noexcept2 A_WARN_UNUSED
- { return mRightMargin; }
-
- void setFollowDownScroll(const bool n) noexcept2
- { mFollowDownScroll = n; }
-
- bool getFollowDownScroll() const noexcept2 A_WARN_UNUSED
- { return mFollowDownScroll; }
-
- void keyPressed(KeyEvent& event) override final;
-
- void setBlockSwitching(const bool b) noexcept2
- { mBlockSwitching = b; }
-
- void setWidth(int width);
-
- void setHeight(int height);
-
- void setSize(int width, int height);
-
- void setDimension(const Rect &dimension);
-
- void death(const Event &event) override final;
-
- void setResizeHeight(bool b) noexcept2
- { mResizeHeight = b; }
-
- void adjustWidget(Widget *const widget) const;
-
- void selectNextTab();
-
- void selectPrevTab();
-
- Widget *getTabContainer() const noexcept2 A_WARN_UNUSED
- { return mTabContainer; }
-
- Widget *getWidgetContainer() const noexcept2 A_WARN_UNUSED
- { return mWidgetContainer; }
-
- private:
- typedef STD_VECTOR <std::pair<Tab*, Widget*> > TabContainer;
-
- /** The tab arrows */
- Button *mArrowButton[2] A_NONNULLPOINTER;
-
- /** Check whether the arrow should be clickable */
- void updateArrowEnableState();
-
- /**
- * Update the overall width of all tab. Used to know whether the arrows
- * have to be drawn or not.
- */
- void updateTabsWidth();
-
- Tab* mSelectedTab;
- BasicContainer2* mTabContainer A_NONNULLPOINTER;
- BasicContainer2* mWidgetContainer A_NONNULLPOINTER;
- STD_VECTOR<Tab*> mTabsToDelete;
- TabContainer mTabs;
-
- /**
- * The overall width of all tab.
- */
- int mTabsWidth;
-
- /**
- * Update the overall width of visible tab. Used to know whether
- * the arrows have to be enable or not.
- */
- void updateVisibleTabsWidth();
-
- /**
- * The overall width of visible tab.
- */
- int mVisibleTabsWidth;
-
- /**
- * The tab scroll index. When scrolling with the arrows, the tabs
- * must be displayed according to the current index.
- * So the first tab displayed may not be the first in the list.
- * @note the index must start at 0.
- */
- unsigned int mTabScrollIndex;
- int mRightMargin;
-
- Opaque mOpaque;
- bool mEnableScrollButtons;
- bool mFollowDownScroll;
- bool mBlockSwitching;
- bool mResizeHeight;
-};
-
-#endif // GUI_WIDGETS_TABBEDAREA_H
diff --git a/src/gui/widgets/tabs/chat/battletab.cpp b/src/gui/widgets/tabs/chat/battletab.cpp
deleted file mode 100644
index fc45fd5e1..000000000
--- a/src/gui/widgets/tabs/chat/battletab.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/battletab.h"
-
-#include "configuration.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-BattleTab *battleChatTab = nullptr;
-
-BattleTab::BattleTab(const Widget2 *const widget) :
- // TRANSLATORS: battle chat tab name
- ChatTab(widget, _("Battle"), "", "#Battle", ChatTabType::BATTLE)
-{
- setTabColors(ThemeColorId::BATTLE_CHAT_TAB);
- if (config.getBoolValue("showChatHistory"))
- loadFromLogFile("#Battle");
-}
-
-BattleTab::~BattleTab()
-{
-}
diff --git a/src/gui/widgets/tabs/chat/battletab.h b/src/gui/widgets/tabs/chat/battletab.h
deleted file mode 100644
index 24f69c8b9..000000000
--- a/src/gui/widgets/tabs/chat/battletab.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_BATTLETAB_H
-#define GUI_WIDGETS_TABS_CHAT_BATTLETAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * A tab for a party chat channel.
- */
-class BattleTab final : public ChatTab
-{
- public:
- explicit BattleTab(const Widget2 *const widget);
-
- A_DELETE_COPY(BattleTab)
-
- ~BattleTab();
-};
-
-extern BattleTab *battleChatTab;
-
-#endif // GUI_WIDGETS_TABS_CHAT_BATTLETAB_H
diff --git a/src/gui/widgets/tabs/chat/channeltab.cpp b/src/gui/widgets/tabs/chat/channeltab.cpp
deleted file mode 100644
index 37e6237a0..000000000
--- a/src/gui/widgets/tabs/chat/channeltab.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/channeltab.h"
-
-#include "gui/widgets/windowcontainer.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "net/chathandler.h"
-
-#include "debug.h"
-
-ChannelTab::ChannelTab(const Widget2 *const widget,
- const std::string &channel) :
- ChatTab(widget, channel, channel, channel, ChatTabType::CHANNEL)
-{
- setTabColors(ThemeColorId::CHANNEL_CHAT_TAB);
-}
-
-ChannelTab::~ChannelTab()
-{
- if (chatWindow != nullptr)
- chatWindow->removeChannel(mChannelName);
-}
-
-void ChannelTab::handleInput(const std::string &msg)
-{
- std::string newMsg;
- newMsg = ChatWindow::doReplace(msg);
- chatHandler->channelMessage(mChannelName, newMsg);
-}
-
-bool ChannelTab::handleCommand(const std::string &restrict type,
- const std::string &restrict args A_UNUSED)
-{
- if (type == "close")
- {
- if (windowContainer != nullptr)
- windowContainer->scheduleDelete(this);
- else
- delete this;
- if (chatWindow != nullptr)
- chatWindow->defaultTab();
- }
- else
- {
- return false;
- }
-
- return true;
-}
-
-void ChannelTab::getAutoCompleteCommands(StringVect& commands) const
-{
- commands.push_back("/close");
- commands.push_back(mChannelName);
-}
diff --git a/src/gui/widgets/tabs/chat/channeltab.h b/src/gui/widgets/tabs/chat/channeltab.h
deleted file mode 100644
index 3ac51e59d..000000000
--- a/src/gui/widgets/tabs/chat/channeltab.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_CHANNELTAB_H
-#define GUI_WIDGETS_TABS_CHAT_CHANNELTAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * A tab for a chat channel.
- */
-class ChannelTab final : public ChatTab
-{
- public:
- ChannelTab(const Widget2 *const widget,
- const std::string &channel);
-
- A_DELETE_COPY(ChannelTab)
-
- ~ChannelTab();
-
- protected:
- void handleInput(const std::string &msg) override final;
-
- bool handleCommand(const std::string &restrict type,
- const std::string &restrict args) override final;
-
- void getAutoCompleteCommands(StringVect& commands)
- const override final;
-};
-
-#endif // GUI_WIDGETS_TABS_CHAT_CHANNELTAB_H
diff --git a/src/gui/widgets/tabs/chat/chattab.cpp b/src/gui/widgets/tabs/chat/chattab.cpp
deleted file mode 100644
index e4f6d751a..000000000
--- a/src/gui/widgets/tabs/chat/chattab.cpp
+++ /dev/null
@@ -1,563 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-#include "chatlogger.h"
-#include "configuration.h"
-#include "settings.h"
-#include "soundmanager.h"
-
-#include "being/localplayer.h"
-
-#include "const/sound.h"
-
-#include "gui/chatlog.h"
-#include "gui/windowmanager.h"
-
-#include "gui/windows/chatwindow.h"
-#include "gui/windows/helpwindow.h"
-
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/itemlinkhandler.h"
-#include "gui/widgets/tabbedarea.h"
-
-#include "input/inputmanager.h"
-
-#include "net/chathandler.h"
-#include "net/net.h"
-
-#include "utils/chatutils.h"
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#ifdef WIN32
-#include <sys/time.h>
-#endif // WIN32
-
-#include <sstream>
-
-#include "debug.h"
-
-ChatTab *localChatTab = nullptr;
-ChatTab *debugChatTab = nullptr;
-
-static const unsigned int MAX_WORD_SIZE = 50;
-
-ChatTab::ChatTab(const Widget2 *const widget,
- const std::string &name,
- const std::string &channel,
- const std::string &logName,
- const ChatTabTypeT &type) :
- Tab(widget),
- mTextOutput(new BrowserBox(this, Opaque_true,
- "browserbox.xml")),
- mScrollArea(new ScrollArea(this, mTextOutput, Opaque_false)),
- mChannelName(channel),
- mLogName(logName),
- mType(type),
- mAllowHightlight(true),
- mRemoveNames(false),
- mNoAway(false),
- mShowOnline(false)
-{
- setCaption(name);
-
- mTextOutput->setOpaque(Opaque_false);
- mTextOutput->setMaxRow(config.getIntValue("ChatLogLength"));
- if (chatWindow != nullptr)
- mTextOutput->setLinkHandler(chatWindow->mItemLinkHandler);
- mTextOutput->setAlwaysUpdate(false);
-
- mScrollArea->setScrollPolicy(ScrollArea::SHOW_NEVER,
- ScrollArea::SHOW_ALWAYS);
- mScrollArea->setScrollAmount(0, 1);
-
- if (chatWindow != nullptr)
- chatWindow->addTab(this);
- mTextOutput->updateSize(true);
-}
-
-ChatTab::~ChatTab()
-{
- if (chatWindow != nullptr)
- chatWindow->removeTab(this);
-
- delete2(mTextOutput);
- delete2(mScrollArea);
-}
-
-void ChatTab::chatLog(std::string line,
- ChatMsgTypeT own,
- const IgnoreRecord ignoreRecord,
- const TryRemoveColors tryRemoveColors)
-{
- // Trim whitespace
- trim(line);
-
- if (line.empty())
- return;
-
- if (tryRemoveColors == TryRemoveColors_true &&
- own == ChatMsgType::BY_OTHER &&
- config.getBoolValue("removeColors"))
- {
- line = removeColors(line);
- if (line.empty())
- return;
- }
-
- const unsigned lineLim = config.getIntValue("chatMaxCharLimit");
- if (lineLim > 0 && line.length() > lineLim)
- line = line.substr(0, lineLim);
-
- if (line.empty())
- return;
-
- CHATLOG tmp;
- tmp.own = own;
- tmp.nick.clear();
- tmp.text = line;
-
- const size_t pos = line.find(" : ");
- if (pos != std::string::npos)
- {
- if (line.length() <= pos + 3)
- return;
-
- tmp.nick = line.substr(0, pos);
- tmp.text = line.substr(pos + 3);
- }
- else
- {
- // Fix the owner of welcome message.
- if (line.length() > 7 && line.substr(0, 7) == "Welcome")
- own = ChatMsgType::BY_SERVER;
- }
-
- // *implements actions in a backwards compatible way*
- if ((own == ChatMsgType::BY_PLAYER || own == ChatMsgType::BY_OTHER) &&
- tmp.text.at(0) == '*' &&
- tmp.text.at(tmp.text.length()-1) == '*')
- {
- tmp.text[0] = ' ';
- tmp.text.erase(tmp.text.length() - 1);
- own = ChatMsgType::ACT_IS;
- }
-
- std::string lineColor("##C");
- switch (own)
- {
- case ChatMsgType::BY_GM:
- if (tmp.nick.empty())
- {
- // TRANSLATORS: chat message
- tmp.nick = std::string(_("Global announcement:")).append(" ");
- lineColor = "##G";
- }
- else
- {
- // TRANSLATORS: chat message
- tmp.nick = strprintf(_("Global announcement from %s:"),
- tmp.nick.c_str()).append(" ");
- lineColor = "##g"; // Equiv. to BrowserBox::RED
- }
- break;
- case ChatMsgType::BY_PLAYER:
- tmp.nick.append(": ");
- lineColor = "##Y";
- break;
- case ChatMsgType::BY_OTHER:
- case ChatMsgType::BY_UNKNOWN:
- tmp.nick.append(": ");
- lineColor = "##C";
- break;
- case ChatMsgType::BY_SERVER:
- // TRANSLATORS: chat message
- tmp.nick.clear();
- tmp.text = line;
- lineColor = "##S";
- break;
- case ChatMsgType::BY_CHANNEL:
- tmp.nick.clear();
- lineColor = "##2"; // Equiv. to BrowserBox::GREEN
- break;
- case ChatMsgType::ACT_WHISPER:
- // TRANSLATORS: chat message
- tmp.nick = strprintf(_("%s whispers: %s"), tmp.nick.c_str(), "");
- lineColor = "##W";
- break;
- case ChatMsgType::ACT_IS:
- lineColor = "##I";
- break;
- case ChatMsgType::BY_LOGGER:
- tmp.nick.clear();
- tmp.text = line;
- lineColor = "##L";
- break;
- default:
- break;
- }
-
- if (tmp.nick == ": ")
- {
- tmp.nick.clear();
- lineColor = "##S";
- }
-
- // if configured, move magic messages log to debug chat tab
- if (Net::getNetworkType() == ServerType::TMWATHENA
- && (localChatTab != nullptr) && this == localChatTab
- && ((config.getBoolValue("showMagicInDebug")
- && own == ChatMsgType::BY_PLAYER
- && tmp.text.length() > 1
- && tmp.text.at(0) == '#'
- && tmp.text.at(1) != '#')
- || (config.getBoolValue("serverMsgInDebug")
- && (own == ChatMsgType::BY_SERVER
- || tmp.nick.empty()))))
- {
- if (debugChatTab != nullptr)
- debugChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors);
- return;
- }
-
- // Get the current system time
- time_t t;
- time(&t);
-
- if (config.getBoolValue("useLocalTime"))
- {
- const tm *const timeInfo = localtime(&t);
- if (timeInfo != nullptr)
- {
- line = strprintf("%s[%02d:%02d] %s%s", lineColor.c_str(),
- timeInfo->tm_hour, timeInfo->tm_min, tmp.nick.c_str(),
- tmp.text.c_str());
- }
- else
- {
- line = strprintf("%s %s%s", lineColor.c_str(),
- tmp.nick.c_str(), tmp.text.c_str());
- }
- }
- else
- {
- // Format the time string properly
- std::stringstream timeStr;
- timeStr << "[" << ((((t / 60) / 60) % 24 < 10) ? "0" : "")
- << CAST_S32(((t / 60) / 60) % 24)
- << ":" << (((t / 60) % 60 < 10) ? "0" : "")
- << CAST_S32((t / 60) % 60)
- << "] ";
- line = std::string(lineColor).append(timeStr.str()).append(
- tmp.nick).append(tmp.text);
- }
-
- if (config.getBoolValue("enableChatLog"))
- saveToLogFile(line);
-
- mTextOutput->setMaxRow(config.getIntValue("chatMaxLinesLimit"));
-
- // We look if the Vertical Scroll Bar is set at the max before
- // adding a row, otherwise the max will always be a row higher
- // at comparison.
- if (mScrollArea->getVerticalScrollAmount() + 2 >=
- mScrollArea->getVerticalMaxScroll())
- {
- addRow(line);
- mScrollArea->setVerticalScrollAmount(
- mScrollArea->getVerticalMaxScroll());
- }
- else
- {
- addRow(line);
- }
-
- if ((chatWindow != nullptr) && this == localChatTab)
- chatWindow->addToAwayLog(line);
-
- mScrollArea->logic();
- if (own != ChatMsgType::BY_PLAYER)
- {
- if (own == ChatMsgType::BY_SERVER &&
- (getType() == ChatTabType::PARTY ||
- getType() == ChatTabType::CHANNEL ||
- getType() == ChatTabType::GUILD))
- {
- return;
- }
-
- const TabbedArea *const tabArea = getTabbedArea();
- if (tabArea == nullptr)
- return;
-
- const bool notFocused = WindowManager::getIsMinimized() ||
- (!settings.mouseFocused &&
- settings.inputFocused == KeyboardFocus::Unfocused);
-
- if (this != tabArea->getSelectedTab() || notFocused)
- {
- if (getFlash() == 0)
- {
- if (chatWindow != nullptr &&
- chatWindow->findHighlight(tmp.text))
- {
- setFlash(2);
- soundManager.playGuiSound(SOUND_HIGHLIGHT);
- }
- else
- {
- setFlash(1);
- }
- }
- else if (getFlash() == 2)
- {
- if (chatWindow != nullptr &&
- chatWindow->findHighlight(tmp.text))
- {
- soundManager.playGuiSound(SOUND_HIGHLIGHT);
- }
- }
- }
-
- if ((getAllowHighlight() ||
- own == ChatMsgType::BY_GM) &&
- (this != tabArea->getSelectedTab() ||
- notFocused))
- {
- if (own == ChatMsgType::BY_GM)
- {
- if (chatWindow != nullptr)
- chatWindow->unHideWindow();
- soundManager.playGuiSound(SOUND_GLOBAL);
- }
- else if (own != ChatMsgType::BY_SERVER)
- {
- if (chatWindow != nullptr)
- chatWindow->unHideWindow();
- playNewMessageSound();
- }
- WindowManager::newChatMessage();
- }
- }
-}
-
-void ChatTab::chatLog(const std::string &nick, std::string msg)
-{
- if (localPlayer == nullptr)
- return;
-
- const ChatMsgTypeT byWho = (nick == localPlayer->getName()
- ? ChatMsgType::BY_PLAYER : ChatMsgType::BY_OTHER);
- if (byWho == ChatMsgType::BY_OTHER && config.getBoolValue("removeColors"))
- msg = removeColors(msg);
- chatLog(std::string(nick).append(" : ").append(msg),
- byWho,
- IgnoreRecord_false,
- TryRemoveColors_false);
-}
-
-void ChatTab::chatInput(const std::string &message)
-{
- std::string msg = message;
- trim(msg);
-
- if (msg.empty())
- return;
-
- replaceItemLinks(msg);
- replaceVars(msg);
-
- switch (msg[0])
- {
- case '/':
- handleCommandStr(std::string(msg, 1));
- break;
- case '?':
- if (msg.size() > 1 &&
- msg[1] != '!' &&
- msg[1] != '?' &&
- msg[1] != '.' &&
- msg[1] != ' ' &&
- msg[1] != ',')
- {
- handleHelp(std::string(msg, 1));
- }
- else
- {
- handleInput(msg);
- }
- break;
- default:
- handleInput(msg);
- break;
- }
-}
-
-void ChatTab::scroll(const int amount)
-{
- const int range = mScrollArea->getHeight() / 8 * amount;
- Rect scr;
- scr.y = mScrollArea->getVerticalScrollAmount() + range;
- scr.height = abs(range);
- mTextOutput->showPart(scr);
-}
-
-void ChatTab::clearText()
-{
- mTextOutput->clearRows();
-}
-
-void ChatTab::handleInput(const std::string &msg)
-{
- if (chatHandler)
- {
- chatHandler->talk(ChatWindow::doReplace(msg),
- mChannelName);
- }
-}
-
-void ChatTab::handleCommandStr(const std::string &msg)
-{
- const size_t pos = msg.find(' ');
- const std::string type(msg, 0, pos);
- std::string args(msg, pos == std::string::npos ? msg.size() : pos + 1);
-
- args = trim(args);
- if (!handleCommand(type, args))
- inputManager.executeChatCommand(type, args, this);
-}
-
-void ChatTab::handleHelp(const std::string &msg)
-{
- if (helpWindow != nullptr)
- {
- helpWindow->search(msg);
- helpWindow->requestMoveToTop();
- }
-}
-
-bool ChatTab::handleCommands(const std::string &type, const std::string &args)
-{
- // need split to commands and call each
-
- return handleCommand(type, args);
-}
-
-void ChatTab::saveToLogFile(const std::string &msg) const
-{
- if (chatLogger != nullptr)
- {
- if (getType() == ChatTabType::INPUT)
- {
- chatLogger->log(msg);
- }
- else if (getType() == ChatTabType::DEBUG)
- {
- if (config.getBoolValue("enableDebugLog"))
- chatLogger->log("#Debug", msg);
- }
- else if (!mLogName.empty())
- {
- chatLogger->log(mLogName, msg);
- }
- }
-}
-
-void ChatTab::addRow(std::string &line)
-{
- if (line.find("[@@http") == std::string::npos)
- {
- size_t idx = 0;
- for (size_t f = 0; f < line.length(); f++)
- {
- if (line.at(f) == ' ')
- {
- idx = f;
- }
- else if (f - idx > MAX_WORD_SIZE)
- {
- line.insert(f, " ");
- idx = f;
- }
- }
- }
- mTextOutput->addRow(line);
-}
-
-void ChatTab::loadFromLogFile(const std::string &name)
-{
- if (chatLogger != nullptr)
- {
- std::list<std::string> list;
- chatLogger->loadLast(name, list, 5);
- std::list<std::string>::const_iterator i = list.begin();
- while (i != list.end())
- {
- std::string line("##o" + *i);
- addRow(line);
- ++i;
- }
- }
-}
-
-void ChatTab::addNewRow(std::string &line)
-{
- if (mScrollArea->getVerticalScrollAmount() >=
- mScrollArea->getVerticalMaxScroll())
- {
- addRow(line);
- mScrollArea->setVerticalScrollAmount(
- mScrollArea->getVerticalMaxScroll());
- }
- else
- {
- addRow(line);
- }
- mScrollArea->logic();
-}
-
-void ChatTab::playNewMessageSound() const
-{
- soundManager.playGuiSound(SOUND_WHISPER);
-}
-
-void ChatTab::showOnline(const std::string &nick,
- const Online online)
-{
- if (!mShowOnline)
- return;
-
- if (online == Online_true)
- {
- // TRANSLATORS: chat message
- chatLog(strprintf(_("%s is now Online."), nick.c_str()),
- ChatMsgType::BY_SERVER);
- }
- else
- {
- // TRANSLATORS: chat message
- chatLog(strprintf(_("%s is now Offline."), nick.c_str()),
- ChatMsgType::BY_SERVER);
- }
-}
diff --git a/src/gui/widgets/tabs/chat/chattab.h b/src/gui/widgets/tabs/chat/chattab.h
deleted file mode 100644
index 440501af4..000000000
--- a/src/gui/widgets/tabs/chat/chattab.h
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_CHATTAB_H
-#define GUI_WIDGETS_TABS_CHAT_CHATTAB_H
-
-#include "enums/gui/chatmsgtype.h"
-#include "enums/gui/chattabtype.h"
-
-#include "enums/simpletypes/ignorerecord.h"
-#include "enums/simpletypes/online.h"
-#include "enums/simpletypes/tryremovecolors.h"
-
-#include "gui/widgets/browserbox.h"
-
-#include "gui/widgets/tabs/tab.h"
-
-#include "localconsts.h"
-
-class ScrollArea;
-
-#define debugMsg(str) \
- if (debugChatTab) \
- debugChatTab->chatLog(str, ChatMsgType::BY_SERVER);
-
-#define setTabColors(name) \
- setTabColor(&getThemeColor(name), \
- &getThemeColor(name##_OUTLINE)); \
- setHighlightedTabColor(&getThemeColor(name##_HIGHLIGHTED), \
- &getThemeColor(name##_HIGHLIGHTED_OUTLINE)); \
- setSelectedTabColor(&getThemeColor(name##_SELECTED), \
- &getThemeColor(name##_SELECTED_OUTLINE))
-
-/**
- * A tab for the chat window. This is special to ease chat handling.
- */
-class ChatTab notfinal : public Tab
-{
- public:
- /**
- * Constructor.
- */
- ChatTab(const Widget2 *const widget,
- const std::string &name,
- const std::string &channel,
- const std::string &logName,
- const ChatTabTypeT &type);
-
- A_DELETE_COPY(ChatTab)
-
- virtual ~ChatTab();
-
- /**
- * Adds a line of text to our message list. Parameters:
- *
- * @param line Text message.
- * @param own Type of message (usually the owner-type).
- * @param ignoreRecord should this not be recorded?
- * @param tryRemoveColors try remove color if configured
- */
- void chatLog(std::string line,
- ChatMsgTypeT own,
- const IgnoreRecord ignoreRecord = IgnoreRecord_false,
- const TryRemoveColors tryRemoveColors
- = TryRemoveColors_true);
-
- /**
- * Adds the text to the message list
- *
- * @param msg The message text which is to be sent.
- */
- void chatLog(const std::string &nick, std::string msg);
-
- /**
- * Determines whether the message is a command or message, then
- * sends the given message to the game server to be said, or to the
- * command handler
- *
- * @param msg The message text which is to be sent.
- */
- void chatInput(const std::string &msg);
-
- /**
- * Scrolls the chat window
- *
- * @param amount direction and amount to scroll. Negative numbers scroll
- * up, positive numbers scroll down. The absolute amount indicates the
- * amount of 1/8ths of chat window real estate that should be scrolled.
- */
- void scroll(const int amount);
-
- /**
- * Clears the text from the tab
- */
- void clearText();
-
- /**
- * Handle special commands. Allows a tab to handle commands it
- * defines itself.
- *
- * @returns true if the command was handled
- * false if the command was not handled
- */
- virtual bool handleCommand(const std::string &restrict type A_UNUSED,
- const std::string &restrict args A_UNUSED)
- { return false; }
-
- /**
- * Handle special commands. Allows a tab to handle commands it
- * defines itself.
- *
- * @returns true if the command was handled
- * false if the command was not handled
- */
- virtual bool handleCommands(const std::string &type,
- const std::string &args);
-
- /**
- * Returns type of the being.
- */
- ChatTabTypeT getType() const noexcept2 A_WARN_UNUSED
- { return mType; }
-
- void saveToLogFile(const std::string &msg) const;
-
- const std::list<std::string> &getRows() const A_WARN_UNUSED
- { return mTextOutput->getRows(); }
-
- bool hasRows() const A_WARN_UNUSED
- { return mTextOutput->hasRows(); }
-
- void loadFromLogFile(const std::string &name);
-
- bool getAllowHighlight() const noexcept2 A_WARN_UNUSED
- { return mAllowHightlight; }
-
- void setAllowHighlight(const bool n) noexcept2
- { mAllowHightlight = n; }
-
- bool getRemoveNames() const noexcept2 A_WARN_UNUSED
- { return mRemoveNames; }
-
- void setRemoveNames(const bool n) noexcept2
- { mRemoveNames = n; }
-
- bool getNoAway() const noexcept2 A_WARN_UNUSED
- { return mNoAway; }
-
- void setNoAway(const bool n) noexcept2
- { mNoAway = n; }
-
- void addNewRow(std::string &line);
-
- void showOnline(const std::string &nick,
- const Online online);
-
- virtual void playNewMessageSound() const;
-
- const std::string &getChannelName() const
- { return mChannelName; }
-
- protected:
- friend class ChatWindow;
- friend class WhisperWindow;
-
- void setCurrent() override final
- { setFlash(0); }
-
- virtual void handleInput(const std::string &msg);
-
- virtual void handleCommandStr(const std::string &msg);
-
- virtual void handleHelp(const std::string &msg);
-
- virtual void getAutoCompleteList(StringVect &names A_UNUSED) const
- {}
-
- virtual void getAutoCompleteCommands(StringVect &names A_UNUSED) const
- {}
-
- void addRow(std::string &line);
-
- BrowserBox *mTextOutput A_NONNULLPOINTER;
- ScrollArea *mScrollArea;
- std::string mChannelName;
- std::string mLogName;
- ChatTabTypeT mType;
- bool mAllowHightlight;
- bool mRemoveNames;
- bool mNoAway;
- bool mShowOnline;
-};
-
-extern ChatTab *localChatTab;
-extern ChatTab *debugChatTab;
-
-#endif // GUI_WIDGETS_TABS_CHAT_CHATTAB_H
diff --git a/src/gui/widgets/tabs/chat/emulateguildtab.cpp b/src/gui/widgets/tabs/chat/emulateguildtab.cpp
deleted file mode 100644
index 4e94bf11d..000000000
--- a/src/gui/widgets/tabs/chat/emulateguildtab.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifdef TMWA_SUPPORT
-
-#include "gui/widgets/tabs/chat/emulateguildtab.h"
-
-#include "configuration.h"
-#include "soundmanager.h"
-
-#include "const/sound.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "utils/gettext.h"
-
-#include "net/tmwa/guildmanager.h"
-
-#include "debug.h"
-
-EmulateGuildTab::EmulateGuildTab(const Widget2 *const widget) :
- // TRANSLATORS: guild chat tab name
- ChatTab(widget, _("Guild"), "", "#Guild", ChatTabType::GUILD),
- ConfigListener()
-{
- setTabColors(ThemeColorId::GUILD_CHAT_TAB);
- mShowOnline = config.getBoolValue("showGuildOnline");
- config.addListener("showGuildOnline", this);
-}
-
-EmulateGuildTab::~EmulateGuildTab()
-{
- config.removeListeners(this);
- CHECKLISTENERS
-}
-
-bool EmulateGuildTab::handleCommand(const std::string &restrict type,
- const std::string &restrict args)
-{
- if (type == "invite")
- GuildManager::invite(args);
- else if (type == "leave")
- GuildManager::leave();
- else if (type == "kick")
- GuildManager::kick(args);
- else if (type == "notice")
- GuildManager::notice(args);
- else
- return false;
-
- return true;
-}
-
-void EmulateGuildTab::handleInput(const std::string &msg)
-{
- if (guildManager == nullptr)
- return;
- guildManager->chat(ChatWindow::doReplace(msg));
-}
-
-void EmulateGuildTab::getAutoCompleteList(StringVect &names) const
-{
- if (guildManager == nullptr)
- return;
-
- guildManager->getNames(names);
-}
-
-void EmulateGuildTab::getAutoCompleteCommands(StringVect &names) const
-{
- names.push_back("/help");
- names.push_back("/invite ");
- names.push_back("/leave");
- names.push_back("/kick ");
- names.push_back("/notice ");
-}
-
-void EmulateGuildTab::playNewMessageSound() const
-{
- soundManager.playGuiSound(SOUND_GUILD);
-}
-
-void EmulateGuildTab::optionChanged(const std::string &value)
-{
- if (value == "showGuildOnline")
- mShowOnline = config.getBoolValue("showGuildOnline");
-}
-
-#endif // TMWA_SUPPORT
diff --git a/src/gui/widgets/tabs/chat/emulateguildtab.h b/src/gui/widgets/tabs/chat/emulateguildtab.h
deleted file mode 100644
index 3cf3a0e59..000000000
--- a/src/gui/widgets/tabs/chat/emulateguildtab.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_EMULATEGUILDTAB_H
-#define GUI_WIDGETS_TABS_CHAT_EMULATEGUILDTAB_H
-
-#ifdef TMWA_SUPPORT
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * Emulate guild tab, because server not support normal guilds.
- */
-class EmulateGuildTab final : public ChatTab,
- public ConfigListener
-{
- public:
- explicit EmulateGuildTab(const Widget2 *const widget);
-
- A_DELETE_COPY(EmulateGuildTab)
-
- ~EmulateGuildTab();
-
- bool handleCommand(const std::string &restrict type,
- const std::string &restrict args) override final;
-
- void playNewMessageSound() const override final;
-
- void optionChanged(const std::string &value) override final;
-
- protected:
- void handleInput(const std::string &msg) override final;
-
- void getAutoCompleteList(StringVect &names) const override final;
-
- void getAutoCompleteCommands(StringVect &names) const override final;
-};
-
-#endif // TMWA_SUPPORT
-#endif // GUI_WIDGETS_TABS_CHAT_EMULATEGUILDTAB_H
diff --git a/src/gui/widgets/tabs/chat/gmtab.cpp b/src/gui/widgets/tabs/chat/gmtab.cpp
deleted file mode 100644
index 3a63cbd2d..000000000
--- a/src/gui/widgets/tabs/chat/gmtab.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/gmtab.h"
-
-#include "const/gui/chat.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "utils/gettext.h"
-
-#include "net/chathandler.h"
-
-#include "debug.h"
-
-GmTab *gmChatTab = nullptr;
-
-GmTab::GmTab(const Widget2 *const widget) :
- // TRANSLATORS: gb tab name
- ChatTab(widget, _("GM"), GM_CHANNEL, "#GM", ChatTabType::GM)
-{
- setTabColors(ThemeColorId::GM_CHAT_TAB);
-}
-
-GmTab::~GmTab()
-{
-}
-
-void GmTab::handleInput(const std::string &msg)
-{
- chatHandler->channelMessage(mChannelName, ChatWindow::doReplace(msg));
-}
-
-void GmTab::handleCommandStr(const std::string &msg A_UNUSED)
-{
-}
-
-void GmTab::getAutoCompleteList(StringVect &names A_UNUSED) const
-{
-}
diff --git a/src/gui/widgets/tabs/chat/gmtab.h b/src/gui/widgets/tabs/chat/gmtab.h
deleted file mode 100644
index a8dd46fd3..000000000
--- a/src/gui/widgets/tabs/chat/gmtab.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2013-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_GMTAB_H
-#define GUI_WIDGETS_TABS_CHAT_GMTAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * A tab for whispers from a single player.
- */
-class GmTab final : public ChatTab
-{
- public:
- explicit GmTab(const Widget2 *const widget);
-
- A_DELETE_COPY(GmTab)
-
- ~GmTab();
-
- protected:
- void getAutoCompleteList(StringVect &names) const
- override final A_CONST;
-
- void handleInput(const std::string &msg) override final;
-
- void handleCommandStr(const std::string &msg) override final A_CONST;
-};
-
-extern GmTab *gmChatTab;
-
-#endif // GUI_WIDGETS_TABS_CHAT_GMTAB_H
diff --git a/src/gui/widgets/tabs/chat/guildtab.cpp b/src/gui/widgets/tabs/chat/guildtab.cpp
deleted file mode 100644
index 51416b8ef..000000000
--- a/src/gui/widgets/tabs/chat/guildtab.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/guildtab.h"
-
-#include "configuration.h"
-#include "soundmanager.h"
-
-#include "const/sound.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "input/inputmanager.h"
-
-#include "net/guildhandler.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-namespace EAthena
-{
- extern Guild *taGuild;
-} // namespace EAthena
-
-GuildTab::GuildTab(const Widget2 *const widget) :
- // TRANSLATORS: guild chat tab name
- ChatTab(widget, _("Guild"), "", "#Guild", ChatTabType::GUILD)
-{
- setTabColors(ThemeColorId::GUILD_CHAT_TAB);
- mShowOnline = config.getBoolValue("showGuildOnline");
- config.addListener("showGuildOnline", this);
-}
-
-GuildTab::~GuildTab()
-{
- config.removeListeners(this);
- CHECKLISTENERS
-}
-
-bool GuildTab::handleCommand(const std::string &restrict type,
- const std::string &restrict args)
-{
- if (type == "invite" && (EAthena::taGuild != nullptr))
- {
- guildHandler->invite(args);
- }
- else if (type == "leave" && (EAthena::taGuild != nullptr))
- {
- inputManager.executeChatCommand(InputAction::LEAVE_GUILD,
- std::string(),
- this);
- }
- else if (type == "kick" && (EAthena::taGuild != nullptr))
- {
- inputManager.executeChatCommand(InputAction::KICK_GUILD,
- args,
- this);
- }
- else if (type == "notice" && (EAthena::taGuild != nullptr))
- {
- inputManager.executeChatCommand(InputAction::GUILD_NOTICE,
- args,
- this);
- }
- else
- {
- return false;
- }
-
- return true;
-}
-
-void GuildTab::handleInput(const std::string &msg)
-{
- if (EAthena::taGuild == nullptr)
- return;
-
- guildHandler->chat(ChatWindow::doReplace(msg));
-}
-
-void GuildTab::getAutoCompleteList(StringVect &names) const
-{
- if (EAthena::taGuild != nullptr)
- EAthena::taGuild->getNames(names);
-}
-
-void GuildTab::getAutoCompleteCommands(StringVect &names) const
-{
- names.push_back("/help");
- names.push_back("/invite ");
- names.push_back("/kick ");
- names.push_back("/notice ");
- names.push_back("/leave");
-}
-
-void GuildTab::playNewMessageSound() const
-{
- soundManager.playGuiSound(SOUND_GUILD);
-}
-
-void GuildTab::optionChanged(const std::string &value)
-{
- if (value == "showGuildOnline")
- mShowOnline = config.getBoolValue("showGuildOnline");
-}
diff --git a/src/gui/widgets/tabs/chat/guildtab.h b/src/gui/widgets/tabs/chat/guildtab.h
deleted file mode 100644
index 5aa540ecb..000000000
--- a/src/gui/widgets/tabs/chat/guildtab.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_GUILDTAB_H
-#define GUI_WIDGETS_TABS_CHAT_GUILDTAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * A tab for a guild chat channel.
- */
-class GuildTab notfinal : public ChatTab,
- public ConfigListener
-{
- public:
- explicit GuildTab(const Widget2 *const widget);
-
- A_DELETE_COPY(GuildTab)
-
- virtual ~GuildTab();
-
- bool handleCommand(const std::string &restrict type,
- const std::string &restrict args) override final;
-
- void playNewMessageSound() const override final;
-
- void optionChanged(const std::string &value) override final;
-
- protected:
- void handleInput(const std::string &msg) override final;
-
- void getAutoCompleteList(StringVect &names) const override final;
-
- void getAutoCompleteCommands(StringVect &names) const override final;
-};
-
-#endif // GUI_WIDGETS_TABS_CHAT_GUILDTAB_H
diff --git a/src/gui/widgets/tabs/chat/langtab.cpp b/src/gui/widgets/tabs/chat/langtab.cpp
deleted file mode 100644
index ba1e21711..000000000
--- a/src/gui/widgets/tabs/chat/langtab.cpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/langtab.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-LangTab *langChatTab = nullptr;
-
-LangTab::LangTab(const Widget2 *const widget,
- const std::string &lang) :
- // TRANSLATORS: lang chat tab name
- ChatTab(widget, _("Lang"), lang + " ", "#Lang", ChatTabType::LANG)
-{
-}
-
-LangTab::~LangTab()
-{
-}
diff --git a/src/gui/widgets/tabs/chat/langtab.h b/src/gui/widgets/tabs/chat/langtab.h
deleted file mode 100644
index 773431e85..000000000
--- a/src/gui/widgets/tabs/chat/langtab.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_LANGTAB_H
-#define GUI_WIDGETS_TABS_CHAT_LANGTAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-class LangTab final : public ChatTab
-{
- public:
- LangTab(const Widget2 *const widget,
- const std::string &lang);
-
- A_DELETE_COPY(LangTab)
-
- ~LangTab();
-};
-
-extern LangTab *langChatTab;
-
-#endif // GUI_WIDGETS_TABS_CHAT_LANGTAB_H
diff --git a/src/gui/widgets/tabs/chat/partytab.cpp b/src/gui/widgets/tabs/chat/partytab.cpp
deleted file mode 100644
index befbb0393..000000000
--- a/src/gui/widgets/tabs/chat/partytab.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/partytab.h"
-
-#include "configuration.h"
-#include "party.h"
-#include "soundmanager.h"
-
-#include "being/localplayer.h"
-
-#include "const/sound.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "input/inputmanager.h"
-
-#include "net/net.h"
-#include "net/partyhandler.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-PartyTab *partyTab = nullptr;
-
-PartyTab::PartyTab(const Widget2 *const widget) :
- // TRANSLATORS: party chat tab name
- ChatTab(widget, _("Party"), "", "#Party", ChatTabType::PARTY)
-{
- setTabColors(ThemeColorId::PARTY_CHAT_TAB);
- mShowOnline = config.getBoolValue("showPartyOnline");
- config.addListener("showPartyOnline", this);
-}
-
-PartyTab::~PartyTab()
-{
- config.removeListeners(this);
- CHECKLISTENERS
-}
-
-void PartyTab::handleInput(const std::string &msg)
-{
- partyHandler->chat(ChatWindow::doReplace(msg));
-}
-
-bool PartyTab::handleCommand(const std::string &restrict type,
- const std::string &restrict args)
-{
- if (type == "invite")
- {
- partyHandler->invite(args);
- }
- else if (type == "leave")
- {
- inputManager.executeChatCommand(InputAction::LEAVE_PARTY,
- args,
- this);
- }
- else if (type == "kick")
- {
- inputManager.executeChatCommand(InputAction::KICK_PARTY,
- args,
- this);
- }
- else if (type == "item")
- {
- inputManager.executeChatCommand(InputAction::PARTY_ITEM_SHARE,
- args,
- this);
- }
- else if (type == "autoitem")
- {
- inputManager.executeChatCommand(InputAction::PARTY_AUTO_ITEM_SHARE,
- args,
- this);
- }
- else if (type == "exp")
- {
- inputManager.executeChatCommand(InputAction::PARTY_EXP_SHARE,
- args,
- this);
- }
- else if (type == "setleader" &&
- Net::getNetworkType() != ServerType::TMWATHENA)
- {
- inputManager.executeChatCommand(
- InputAction::COMMAND_CHANGE_PARTY_LEADER,
- args,
- this);
- }
- else
- {
- return false;
- }
-
- return true;
-}
-
-void PartyTab::getAutoCompleteList(StringVect &names) const
-{
- if (localPlayer == nullptr)
- return;
-
- const Party *const p = localPlayer->getParty();
-
- if (p != nullptr)
- p->getNames(names);
-}
-
-void PartyTab::getAutoCompleteCommands(StringVect &names) const
-{
- names.push_back("/help");
- names.push_back("/invite ");
- names.push_back("/leave");
- names.push_back("/kick ");
- names.push_back("/item");
- names.push_back("/exp");
- if (Net::getNetworkType() != ServerType::TMWATHENA)
- names.push_back("/setleader ");
-}
-
-void PartyTab::playNewMessageSound() const
-{
- soundManager.playGuiSound(SOUND_GUILD);
-}
-
-void PartyTab::optionChanged(const std::string &value)
-{
- if (value == "showPartyOnline")
- mShowOnline = config.getBoolValue("showPartyOnline");
-}
diff --git a/src/gui/widgets/tabs/chat/partytab.h b/src/gui/widgets/tabs/chat/partytab.h
deleted file mode 100644
index a987c9362..000000000
--- a/src/gui/widgets/tabs/chat/partytab.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_PARTYTAB_H
-#define GUI_WIDGETS_TABS_CHAT_PARTYTAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * A tab for a party chat channel.
- */
-class PartyTab notfinal : public ChatTab,
- public ConfigListener
-{
- public:
- explicit PartyTab(const Widget2 *const widget);
-
- A_DELETE_COPY(PartyTab)
-
- virtual ~PartyTab();
-
- bool handleCommand(const std::string &restrict type,
- const std::string &restrict args) override final;
-
- void playNewMessageSound() const override final;
-
- void optionChanged(const std::string &value) override final;
-
- protected:
- void handleInput(const std::string &msg) override final;
-
- void getAutoCompleteList(StringVect &names) const override final;
-
- void getAutoCompleteCommands(StringVect &names) const override final;
-};
-
-extern PartyTab *partyTab;
-
-#endif // GUI_WIDGETS_TABS_CHAT_PARTYTAB_H
diff --git a/src/gui/widgets/tabs/chat/tradetab.cpp b/src/gui/widgets/tabs/chat/tradetab.cpp
deleted file mode 100644
index e16e5c08b..000000000
--- a/src/gui/widgets/tabs/chat/tradetab.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/tradetab.h"
-
-#include "const/gui/chat.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "net/chathandler.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-TradeTab *tradeChatTab = nullptr;
-
-TradeTab::TradeTab(const Widget2 *const widget) :
- // TRANSLATORS: trade chat tab name
- ChatTab(widget, _("Trade"), TRADE_CHANNEL, "#Trade", ChatTabType::TRADE)
-{
-}
-
-TradeTab::~TradeTab()
-{
-}
-
-void TradeTab::handleInput(const std::string &msg)
-{
- chatHandler->channelMessage(mChannelName, ChatWindow::doReplace(msg));
-}
diff --git a/src/gui/widgets/tabs/chat/tradetab.h b/src/gui/widgets/tabs/chat/tradetab.h
deleted file mode 100644
index 26c9bf8f6..000000000
--- a/src/gui/widgets/tabs/chat/tradetab.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_TRADETAB_H
-#define GUI_WIDGETS_TABS_CHAT_TRADETAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * A tab for a party chat channel.
- */
-class TradeTab final : public ChatTab
-{
- public:
- explicit TradeTab(const Widget2 *const widget);
-
- A_DELETE_COPY(TradeTab)
-
- ~TradeTab();
-
- protected:
- void handleInput(const std::string &msg) override final;
-};
-
-extern TradeTab *tradeChatTab;
-
-#endif // GUI_WIDGETS_TABS_CHAT_TRADETAB_H
diff --git a/src/gui/widgets/tabs/chat/whispertab.cpp b/src/gui/widgets/tabs/chat/whispertab.cpp
deleted file mode 100644
index 73b73a17c..000000000
--- a/src/gui/widgets/tabs/chat/whispertab.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/chat/whispertab.h"
-
-#include "being/localplayer.h"
-
-#include "net/chathandler.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "gui/widgets/windowcontainer.h"
-
-#include "utils/chatutils.h"
-
-#include "debug.h"
-
-WhisperTab::WhisperTab(const Widget2 *const widget,
- const std::string &caption,
- const std::string &nick) :
- ChatTab(widget, caption, nick, nick, ChatTabType::WHISPER),
- mNick(nick)
-{
- setWhisperTabColors();
-}
-
-WhisperTab::~WhisperTab()
-{
- if (chatWindow != nullptr)
- chatWindow->removeWhisper(mNick);
-}
-
-void WhisperTab::handleInput(const std::string &msg)
-{
- std::string newMsg;
- newMsg = ChatWindow::doReplace(msg);
- chatHandler->privateMessage(mNick, newMsg);
-
- if (localPlayer != nullptr)
- chatLog(localPlayer->getName(), newMsg);
- else
- chatLog("?", newMsg);
-}
-
-void WhisperTab::handleCommandStr(const std::string &msg)
-{
- if (msg == "close")
- {
- delete this;
- return;
- }
-
- const size_t pos = msg.find(' ');
- const std::string type(msg, 0, pos);
-
- if (type == "me")
- {
- const std::string args(msg, pos == std::string::npos
- ? msg.size() : pos + 1);
- std::string str = textToMe(args);
- chatHandler->privateMessage(mNick, str);
- if (localPlayer != nullptr)
- chatLog(localPlayer->getName(), str);
- else
- chatLog("?", str);
- }
- else
- {
- ChatTab::handleCommandStr(msg);
- }
-}
-
-bool WhisperTab::handleCommand(const std::string &restrict type,
- const std::string &restrict args A_UNUSED)
-{
- if (type == "close")
- {
- if (windowContainer != nullptr)
- windowContainer->scheduleDelete(this);
- else
- delete this;
- if (chatWindow != nullptr)
- chatWindow->defaultTab();
- }
- else
- {
- return false;
- }
-
- return true;
-}
-
-void WhisperTab::getAutoCompleteList(StringVect &names) const
-{
- names.push_back(mNick);
-}
-
-void WhisperTab::getAutoCompleteCommands(StringVect& commands) const
-{
- commands.push_back("/close");
-}
-
-void WhisperTab::setWhisperTabColors()
-{
- setTabColors(ThemeColorId::WHISPER_TAB);
-}
-
-void WhisperTab::setWhisperTabOfflineColors()
-{
- setTabColors(ThemeColorId::WHISPER_TAB_OFFLINE);
-}
diff --git a/src/gui/widgets/tabs/chat/whispertab.h b/src/gui/widgets/tabs/chat/whispertab.h
deleted file mode 100644
index 1d3c03857..000000000
--- a/src/gui/widgets/tabs/chat/whispertab.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_CHAT_WHISPERTAB_H
-#define GUI_WIDGETS_TABS_CHAT_WHISPERTAB_H
-
-#include "gui/widgets/tabs/chat/chattab.h"
-
-/**
- * A tab for whispers from a single player.
- */
-class WhisperTab final : public ChatTab
-{
- public:
- A_DELETE_COPY(WhisperTab)
-
- const std::string &getNick() const noexcept2 A_WARN_UNUSED
- { return mNick; }
-
- bool handleCommand(const std::string &restrict type,
- const std::string &restrict args) override final;
-
- void setWhisperTabColors();
-
- void setWhisperTabOfflineColors();
-
- protected:
- friend class ChatWindow;
-
- void getAutoCompleteList(StringVect &names) const override final;
-
- void getAutoCompleteCommands(StringVect& commands)
- const override final;
-
- /**
- * Constructor.
- *
- * @param nick the name of the player this tab is whispering to
- */
- WhisperTab(const Widget2 *const widget,
- const std::string &caption,
- const std::string &nick);
-
- ~WhisperTab();
-
- void handleInput(const std::string &msg) override final;
-
- void handleCommandStr(const std::string &msg) override final;
-
- private:
- std::string mNick;
-};
-
-#endif // GUI_WIDGETS_TABS_CHAT_WHISPERTAB_H
diff --git a/src/gui/widgets/tabs/debugwindowtabs.cpp b/src/gui/widgets/tabs/debugwindowtabs.cpp
deleted file mode 100644
index 321c3bcad..000000000
--- a/src/gui/widgets/tabs/debugwindowtabs.cpp
+++ /dev/null
@@ -1,492 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/debugwindowtabs.h"
-
-#include "game.h"
-
-#include "being/localplayer.h"
-
-#include "particle/particleengine.h"
-
-#include "gui/viewport.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layouthelper.h"
-
-#ifdef USE_OPENGL
-#include "resources/imagehelper.h"
-#endif // USE_OPENGL
-
-#include "resources/map/map.h"
-
-#include "net/packetcounters.h"
-
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-#include "utils/timer.h"
-
-#include "debug.h"
-
-MapDebugTab::MapDebugTab(const Widget2 *const widget) :
- DebugTab(widget),
- // TRANSLATORS: debug window label
- mMusicFileLabel(new Label(this, _("Music:"))),
- // TRANSLATORS: debug window label
- mMapLabel(new Label(this, _("Map:"))),
- // TRANSLATORS: debug window label
- mMapNameLabel(new Label(this, _("Map name:"))),
- // TRANSLATORS: debug window label
- mMinimapLabel(new Label(this, _("Minimap:"))),
- mTileMouseLabel(new Label(this, strprintf("%s (%d, %d)",
- // TRANSLATORS: debug window label
- _("Cursor:"), 0, 0))),
- mParticleCountLabel(new Label(this, strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Particle count:"), 88888))),
- mMapActorCountLabel(new Label(this, strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Map actors count:"), 88888))),
- // TRANSLATORS: debug window label
- mXYLabel(new Label(this, strprintf("%s (?,?)", _("Player Position:")))),
- mTexturesLabel(nullptr),
- mUpdateTime(0),
-#ifdef DEBUG_DRAW_CALLS
- mDrawCallsLabel(new Label(this, strprintf("%s %s",
- // TRANSLATORS: debug window label
- _("Draw calls:"), "?"))),
-#endif // DEBUG_DRAW_CALLS
-#ifdef DEBUG_BIND_TEXTURE
- mBindsLabel(new Label(this, strprintf("%s %s",
- // TRANSLATORS: debug window label
- _("Texture binds:"), "?"))),
-#endif // DEBUG_BIND_TEXTURE
- // TRANSLATORS: debug window label, frames per second
- mFPSLabel(new Label(this, strprintf(_("%d FPS"), 0))),
- // TRANSLATORS: debug window label, logic per second
- mLPSLabel(new Label(this, strprintf(_("%d LPS"), 0))),
- mFPSText()
-{
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
-#ifdef USE_OPENGL
- switch (imageHelper->useOpenGL())
- {
- case RENDER_SOFTWARE:
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (Software)");
- break;
- case RENDER_NORMAL_OPENGL:
- case RENDER_NULL:
- case RENDER_LAST:
- default:
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (normal OpenGL)");
- break;
- case RENDER_SAFE_OPENGL:
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (safe OpenGL)");
- break;
- case RENDER_GLES_OPENGL:
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (mobile OpenGL ES)");
- break;
- case RENDER_GLES2_OPENGL:
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (mobile OpenGL ES 2)");
- break;
- case RENDER_MODERN_OPENGL:
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (modern OpenGL)");
- break;
- case RENDER_SDL2_DEFAULT:
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (SDL2 default)");
- break;
- };
-#else // USE_OPENGL
-
- // TRANSLATORS: debug window label
- mFPSText = _("%d FPS (Software)");
-#endif // USE_OPENGL
-
- place(0, 0, mFPSLabel, 2);
- place(0, 1, mLPSLabel, 2);
- place(0, 2, mMusicFileLabel, 2);
- place(0, 3, mMapLabel, 2);
- place(0, 4, mMapNameLabel, 2);
- place(0, 5, mMinimapLabel, 2);
- place(0, 6, mXYLabel, 2);
- place(0, 7, mTileMouseLabel, 2);
- place(0, 8, mParticleCountLabel, 2);
- place(0, 9, mMapActorCountLabel, 2);
-#ifdef USE_OPENGL
-#if defined (DEBUG_OPENGL_LEAKS) || defined(DEBUG_DRAW_CALLS) \
- || defined(DEBUG_BIND_TEXTURE)
- int n = 10;
-#endif // defined (DEBUG_OPENGL_LEAKS) || defined(DEBUG_DRAW_CALLS)
- // || defined(DEBUG_BIND_TEXTURE)
-#ifdef DEBUG_OPENGL_LEAKS
- mTexturesLabel = new Label(this, strprintf("%s %s",
- // TRANSLATORS: debug window label
- _("Textures count:"), "?"));
- place(0, n, mTexturesLabel, 2);
- n ++;
-#endif // DEBUG_OPENGL_LEAKS
-#ifdef DEBUG_DRAW_CALLS
- place(0, n, mDrawCallsLabel, 2);
- n ++;
-#endif // DEBUG_DRAW_CALLS
-#ifdef DEBUG_BIND_TEXTURE
- place(0, n, mBindsLabel, 2);
-#endif // DEBUG_BIND_TEXTURE
-#endif // USE_OPENGL
-
- place.getCell().matchColWidth(0, 0);
- place = h.getPlacer(0, 1);
- setDimension(Rect(0, 0, 600, 300));
-}
-
-void MapDebugTab::logic()
-{
- BLOCK_START("MapDebugTab::logic")
- if (localPlayer != nullptr)
- {
- // TRANSLATORS: debug window label
- mXYLabel->setCaption(strprintf("%s (%d, %d)", _("Player Position:"),
- localPlayer->getTileX(), localPlayer->getTileY()));
- }
- else
- {
- // TRANSLATORS: debug window label
- mXYLabel->setCaption(strprintf("%s (?, ?)", _("Player Position:")));
- }
-
- Game *const game = Game::instance();
- const Map *const map = game != nullptr ? game->getCurrentMap() : nullptr;
- if (map != nullptr &&
- viewport != nullptr)
- {
- // Get the current mouse position
- const int mouseTileX = (viewport->mMouseX + viewport->getCameraX())
- / map->getTileWidth();
- const int mouseTileY = (viewport->mMouseY + viewport->getCameraY())
- / map->getTileHeight();
- mTileMouseLabel->setCaption(strprintf("%s (%d, %d)",
- // TRANSLATORS: debug window label
- _("Cursor:"), mouseTileX, mouseTileY));
-
- // TRANSLATORS: debug window label
- mMusicFileLabel->setCaption(strprintf("%s %s", _("Music:"),
- map->getProperty("music").c_str()));
- // TRANSLATORS: debug window label
- mMinimapLabel->setCaption(strprintf("%s %s", _("Minimap:"),
- map->getProperty("minimap").c_str()));
- // TRANSLATORS: debug window label
- mMapLabel->setCaption(strprintf("%s %s", _("Map:"),
- map->getProperty("_realfilename").c_str()));
- // TRANSLATORS: debug window label
- mMapNameLabel->setCaption(strprintf("%s %s", _("Map name:"),
- map->getProperty("name").c_str()));
-
- if (mUpdateTime != cur_time)
- {
- mUpdateTime = cur_time;
- // TRANSLATORS: debug window label
- mParticleCountLabel->setCaption(strprintf(_("Particle count: %d"),
- ParticleEngine::particleCount));
-
- mMapActorCountLabel->setCaption(
- // TRANSLATORS: debug window label
- strprintf("%s %d", _("Map actors count:"),
- map->getActorsCount()));
-#ifdef USE_OPENGL
-#ifdef DEBUG_OPENGL_LEAKS
- mTexturesLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Textures count:"), textures_count));
-#endif // DEBUG_OPENGL_LEAKS
-#ifdef DEBUG_DRAW_CALLS
- if (mainGraphics)
- {
- mDrawCallsLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Draw calls:"), mainGraphics->getDrawCalls()));
- }
-#endif // DEBUG_DRAW_CALLS
-#ifdef DEBUG_BIND_TEXTURE
- if (mainGraphics)
- {
- mBindsLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Texture binds:"), mainGraphics->getBinds()));
- }
-#endif // DEBUG_BIND_TEXTURE
-#endif // USE_OPENGL
- }
- }
- else
- {
- // TRANSLATORS: debug window label
- mTileMouseLabel->setCaption(strprintf("%s (?, ?)", _("Cursor:")));
- // TRANSLATORS: debug window label
- mMusicFileLabel->setCaption(strprintf("%s ?", _("Music:")));
- // TRANSLATORS: debug window label
- mMinimapLabel->setCaption(strprintf("%s ?", _("Minimap:")));
- // TRANSLATORS: debug window label
- mMapLabel->setCaption(strprintf("%s ?", _("Map:")));
- // TRANSLATORS: debug window label
- mMapNameLabel->setCaption(strprintf("%s ?", _("Map name:")));
-
- mMapActorCountLabel->setCaption(
- // TRANSLATORS: debug window label
- strprintf("%s ?", _("Map actors count:")));
- }
-
- mMapActorCountLabel->adjustSize();
- mParticleCountLabel->adjustSize();
-
- mFPSLabel->setCaption(strprintf(mFPSText.c_str(), fps));
- // TRANSLATORS: debug window label, logic per second
- mLPSLabel->setCaption(strprintf(_("%d LPS"), lps));
- BLOCK_END("MapDebugTab::logic")
-}
-
-TargetDebugTab::TargetDebugTab(const Widget2 *const widget) :
- DebugTab(widget),
- // TRANSLATORS: debug window label
- mTargetLabel(new Label(this, strprintf("%s ?", _("Target:")))),
- // TRANSLATORS: debug window label
- mTargetIdLabel(new Label(this, strprintf("%s ? ", _("Target Id:")))),
- mTargetTypeLabel(new Label(this, strprintf(
- // TRANSLATORS: debug window label
- "%s ? ", _("Target type:")))),
- // TRANSLATORS: debug window label
- mTargetLevelLabel(new Label(this, strprintf("%s ?", _("Target level:")))),
- // TRANSLATORS: debug window label
- mTargetRaceLabel(new Label(this, strprintf("%s ?", _("Target race:")))),
- // TRANSLATORS: debug window label
- mTargetPartyLabel(new Label(this, strprintf("%s ?", _("Target party:")))),
- // TRANSLATORS: debug window label
- mTargetGuildLabel(new Label(this, strprintf("%s ?", _("Target guild:")))),
- // TRANSLATORS: debug window label
- mAttackDelayLabel(new Label(this, strprintf("%s ?", _("Attack delay:")))),
- // TRANSLATORS: debug window label
- mMinHitLabel(new Label(this, strprintf("%s ?", _("Minimal hit:")))),
- // TRANSLATORS: debug window label
- mMaxHitLabel(new Label(this, strprintf("%s ?", _("Maximum hit:")))),
- // TRANSLATORS: debug window label
- mCriticalHitLabel(new Label(this, strprintf("%s ?", _("Critical hit:")))),
- // TRANSLATORS: debug window label
- mKarmaLabel(new Label(this, strprintf("%s ?", _("Karma:")))),
- // TRANSLATORS: debug window label
- mMannerLabel(new Label(this, strprintf("%s ?", _("Manner:")))),
- // TRANSLATORS: debug window label
- mEffectsLabel(new Label(this, strprintf("%s ?", _("Effects:"))))
-{
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, mTargetLabel, 2);
- place(0, 1, mTargetIdLabel, 2);
- place(0, 2, mTargetTypeLabel, 2);
- place(0, 3, mTargetLevelLabel, 2);
- place(0, 4, mTargetRaceLabel, 2);
- place(0, 5, mAttackDelayLabel, 2);
- place(0, 6, mTargetPartyLabel, 2);
- place(0, 7, mTargetGuildLabel, 2);
- place(0, 8, mMinHitLabel, 2);
- place(0, 9, mMaxHitLabel, 2);
- place(0, 10, mCriticalHitLabel, 2);
- place(0, 11, mKarmaLabel, 2);
- place(0, 12, mMannerLabel, 2);
- place(0, 13, mEffectsLabel, 2);
-
- place.getCell().matchColWidth(0, 0);
- place = h.getPlacer(0, 1);
- setDimension(Rect(0, 0, 600, 300));
-}
-
-void TargetDebugTab::logic()
-{
- BLOCK_START("TargetDebugTab::logic")
- if ((localPlayer != nullptr) && (localPlayer->getTarget() != nullptr))
- {
- const Being *const target = localPlayer->getTarget();
-
- // TRANSLATORS: debug window label
- mTargetLabel->setCaption(strprintf("%s %s (%d, %d)", _("Target:"),
- target->getName().c_str(), target->getTileX(),
- target->getTileY()));
-
- mTargetIdLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Target Id:"), toInt(target->getId(), int)));
- mTargetTypeLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Target type:"), toInt(target->getSubType(), int)));
- if (target->getLevel() != 0)
- {
- mTargetLevelLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Target Level:"), target->getLevel()));
- }
- else
- {
- mTargetLevelLabel->setCaption(strprintf("%s ?",
- // TRANSLATORS: debug window label
- _("Target Level:")));
- }
-
- mTargetRaceLabel->setCaption(strprintf("%s %s",
- // TRANSLATORS: debug window label
- _("Target race:"), target->getRaceName().c_str()));
-
- // TRANSLATORS: debug window label
- mTargetPartyLabel->setCaption(strprintf("%s %s", _("Target Party:"),
- target->getPartyName().c_str()));
-
- // TRANSLATORS: debug window label
- mTargetGuildLabel->setCaption(strprintf("%s %s", _("Target Guild:"),
- target->getGuildName().c_str()));
-
- mMinHitLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Minimal hit:"), target->getMinHit()));
- mMaxHitLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Maximum hit:"), target->getMaxHit()));
- mCriticalHitLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Critical hit:"), target->getCriticalHit()));
- mKarmaLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Karma:"), target->getKarma()));
- mMannerLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Manner:"), target->getManner()));
- mEffectsLabel->setCaption(strprintf("%s %s",
- // TRANSLATORS: debug window label
- _("Effects:"), target->getStatusEffectsString().c_str()));
-
- const int delay = target->getAttackDelay();
- if (delay != 0)
- {
- mAttackDelayLabel->setCaption(strprintf("%s %d",
- // TRANSLATORS: debug window label
- _("Attack delay:"), delay));
- }
- else
- {
- mAttackDelayLabel->setCaption(strprintf(
- // TRANSLATORS: debug window label
- "%s ?", _("Attack delay:")));
- }
- }
- else
- {
- // TRANSLATORS: debug window label
- mTargetLabel->setCaption(strprintf("%s ?", _("Target:")));
- // TRANSLATORS: debug window label
- mTargetIdLabel->setCaption(strprintf("%s ?", _("Target Id:")));
- // TRANSLATORS: debug window label
- mTargetTypeLabel->setCaption(strprintf("%s ?", _("Target type:")));
- // TRANSLATORS: debug window label
- mTargetLevelLabel->setCaption(strprintf("%s ?", _("Target Level:")));
- // TRANSLATORS: debug window label
- mTargetPartyLabel->setCaption(strprintf("%s ?", _("Target Party:")));
- // TRANSLATORS: debug window label
- mTargetGuildLabel->setCaption(strprintf("%s ?", _("Target Guild:")));
- // TRANSLATORS: debug window label
- mAttackDelayLabel->setCaption(strprintf("%s ?", _("Attack delay:")));
- // TRANSLATORS: debug window label
- mMinHitLabel->setCaption(strprintf("%s ?", _("Minimal hit:")));
- // TRANSLATORS: debug window label
- mMaxHitLabel->setCaption(strprintf("%s ?", _("Maximum hit:")));
- // TRANSLATORS: debug window label
- mCriticalHitLabel->setCaption(strprintf("%s ?", _("Critical hit:")));
- // TRANSLATORS: debug window label
- mKarmaLabel->setCaption(strprintf("%s ?", _("Karma:")));
- // TRANSLATORS: debug window label
- mMannerLabel->setCaption(strprintf("%s ?", _("Manner:")));
- // TRANSLATORS: debug window label
- mEffectsLabel->setCaption(strprintf("%s ?", _("Effects:")));
- }
-
- mTargetLabel->adjustSize();
- mTargetIdLabel->adjustSize();
- mTargetTypeLabel->adjustSize();
- mTargetLevelLabel->adjustSize();
- mTargetPartyLabel->adjustSize();
- mTargetGuildLabel->adjustSize();
- mAttackDelayLabel->adjustSize();
- mMinHitLabel->adjustSize();
- mMaxHitLabel->adjustSize();
- mCriticalHitLabel->adjustSize();
- mKarmaLabel->adjustSize();
- mMannerLabel->adjustSize();
- mEffectsLabel->adjustSize();
- BLOCK_END("TargetDebugTab::logic")
-}
-
-NetDebugTab::NetDebugTab(const Widget2 *const widget) :
- DebugTab(widget),
- mPingLabel(new Label(this, " ")),
- mInPackets1Label(new Label(this, " ")),
- mOutPackets1Label(new Label(this, " "))
-{
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, mPingLabel, 2);
- place(0, 1, mInPackets1Label, 2);
- place(0, 2, mOutPackets1Label, 2);
-
- place.getCell().matchColWidth(0, 0);
- place = h.getPlacer(0, 1);
- setDimension(Rect(0, 0, 600, 300));
-}
-
-void NetDebugTab::logic()
-{
- BLOCK_START("NetDebugTab::logic")
- if (localPlayer != nullptr)
- {
- // TRANSLATORS: debug window label
- mPingLabel->setCaption(strprintf(_("Ping: %s ms"),
- localPlayer->getPingTime().c_str()));
- }
- else
- {
- // TRANSLATORS: debug window label
- mPingLabel->setCaption(strprintf(_("Ping: %s ms"), "0"));
- }
- // TRANSLATORS: debug window label
- mInPackets1Label->setCaption(strprintf(_("In: %d bytes/s"),
- PacketCounters::getInBytes()));
- // TRANSLATORS: debug window label
- mOutPackets1Label->setCaption(strprintf(_("Out: %d bytes/s"),
- PacketCounters::getOutBytes()));
- BLOCK_END("NetDebugTab::logic")
-}
diff --git a/src/gui/widgets/tabs/debugwindowtabs.h b/src/gui/widgets/tabs/debugwindowtabs.h
deleted file mode 100644
index 566987cd0..000000000
--- a/src/gui/widgets/tabs/debugwindowtabs.h
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_DEBUGWINDOWTABS_H
-#define GUI_WIDGETS_TABS_DEBUGWINDOWTABS_H
-
-#include "gui/widgets/container.h"
-
-class Label;
-
-class DebugTab notfinal : public Container
-{
- friend class DebugWindow;
-
- public:
- A_DELETE_COPY(DebugTab)
-
- void logic() override
- {
- }
-
- void resize(const int x, const int y)
- { setDimension(Rect(0, 0, x, y)); }
-
- protected:
- explicit DebugTab(const Widget2 *const widget) :
- Container(widget)
- { setSelectable(false); }
-};
-
-class MapDebugTab final : public DebugTab
-{
- friend class DebugWindow;
-
- public:
- explicit MapDebugTab(const Widget2 *const widget);
-
- A_DELETE_COPY(MapDebugTab)
-
- void logic() override final;
-
- private:
- Label *mMusicFileLabel A_NONNULLPOINTER;
- Label *mMapLabel A_NONNULLPOINTER;
- Label *mMapNameLabel A_NONNULLPOINTER;
- Label *mMinimapLabel A_NONNULLPOINTER;
- Label *mTileMouseLabel A_NONNULLPOINTER;
- Label *mParticleCountLabel A_NONNULLPOINTER;
- Label *mMapActorCountLabel A_NONNULLPOINTER;
- Label *mXYLabel A_NONNULLPOINTER;
- Label *mTexturesLabel A_NONNULLPOINTER;
- time_t mUpdateTime;
-#ifdef DEBUG_DRAW_CALLS
- Label *mDrawCallsLabel A_NONNULLPOINTER;
-#endif // DEBUG_DRAW_CALLS
-#ifdef DEBUG_BIND_TEXTURE
- Label *mBindsLabel A_NONNULLPOINTER;
-#endif // DEBUG_BIND_TEXTURE
-
- Label *mFPSLabel A_NONNULLPOINTER;
- Label *mLPSLabel A_NONNULLPOINTER;
- std::string mFPSText;
-};
-
-class TargetDebugTab final : public DebugTab
-{
- friend class DebugWindow;
-
- public:
- explicit TargetDebugTab(const Widget2 *const widget);
-
- A_DELETE_COPY(TargetDebugTab)
-
- void logic() override final;
-
- private:
- Label *mTargetLabel A_NONNULLPOINTER;
- Label *mTargetIdLabel A_NONNULLPOINTER;
- Label *mTargetTypeLabel A_NONNULLPOINTER;
- Label *mTargetLevelLabel A_NONNULLPOINTER;
- Label *mTargetRaceLabel A_NONNULLPOINTER;
- Label *mTargetPartyLabel A_NONNULLPOINTER;
- Label *mTargetGuildLabel A_NONNULLPOINTER;
- Label *mAttackDelayLabel A_NONNULLPOINTER;
- Label *mMinHitLabel A_NONNULLPOINTER;
- Label *mMaxHitLabel A_NONNULLPOINTER;
- Label *mCriticalHitLabel A_NONNULLPOINTER;
- Label *mKarmaLabel A_NONNULLPOINTER;
- Label *mMannerLabel A_NONNULLPOINTER;
- Label *mEffectsLabel A_NONNULLPOINTER;
-};
-
-class NetDebugTab final : public DebugTab
-{
- friend class DebugWindow;
-
- public:
- explicit NetDebugTab(const Widget2 *const widget);
-
- A_DELETE_COPY(NetDebugTab)
-
- void logic() override final;
-
- private:
- Label *mPingLabel A_NONNULLPOINTER;
- Label *mInPackets1Label A_NONNULLPOINTER;
- Label *mOutPackets1Label A_NONNULLPOINTER;
-};
-
-#endif // GUI_WIDGETS_TABS_DEBUGWINDOWTABS_H
diff --git a/src/gui/widgets/tabs/setup_audio.cpp b/src/gui/widgets/tabs/setup_audio.cpp
deleted file mode 100644
index 6275ff59a..000000000
--- a/src/gui/widgets/tabs/setup_audio.cpp
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_audio.h"
-
-#include "resources/map/map.h"
-
-#include "configuration.h"
-#include "soundmanager.h"
-
-#include "gui/viewport.h"
-
-#include "gui/models/soundsmodel.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-Setup_Audio::Setup_Audio(const Widget2 *const widget) :
- SetupTabScroll(widget),
- mSoundModel(new SoundsModel),
- mChannelsList(new SetupItemNames)
-{
- // TRANSLATORS: audio tab in settings
- setName(_("Audio"));
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Basic settings"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable Audio"), "", "sound", this, "soundEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable music"), "",
- "playMusic", this, "playMusicEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable game sfx"), "",
- "playBattleSound", this, "playBattleSoundEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable gui sfx"), "",
- "playGuiSound", this, "playGuiSoundEvent");
-
- // TRANSLATORS: settings option
- new SetupItemSlider(_("Sfx volume"), "", "sfxVolume",
- this, "sfxVolumeEvent", 0, SoundManager::getMaxVolume(), 1,
- 150,
- OnTheFly_true,
- MainConfig_true);
-
- // TRANSLATORS: settings option
- new SetupItemSlider(_("Music volume"), "", "musicVolume",
- this, "musicVolumeEvent", 0, SoundManager::getMaxVolume(), 1,
- 150,
- OnTheFly_true,
- MainConfig_true);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable music fade out"), "",
- "fadeoutmusic", this, "fadeoutmusicEvent");
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Audio frequency"), "",
- "audioFrequency", this, "audioFrequencyEvent", 14000, 192000);
-
- // TRANSLATORS: audio type
- mChannelsList->push_back(_("mono"));
- // TRANSLATORS: audio type
- mChannelsList->push_back(_("stereo"));
- // TRANSLATORS: audio type
- mChannelsList->push_back(_("surround"));
- // TRANSLATORS: audio type
- mChannelsList->push_back(_("surround+center+lfe"));
- // TRANSLATORS: settings option
- new SetupItemSlider2(_("Audio channels"), "", "audioChannels", this,
- "audioChannels", 1, 4, 1, mChannelsList,
- OnTheFly_false,
- MainConfig_true,
- DoNotAlign_false);
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Parallel number of sounds"), "",
- "parallelAudioChannels", this, "parallelAudioChannelsEvent", 1, 1000);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Sound effects"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Information dialog sound"), "",
- "soundinfo", this, "soundinfoEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Request dialog sound"), "",
- "soundrequest", this, "soundrequestEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Whisper message sound"), "",
- "soundwhisper", this, "soundwhisperEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Guild / Party message sound"), "",
- "soundguild", this, "soundguildEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Highlight message sound"), "",
- "soundhighlight", this, "soundhighlightEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Global message sound"), "",
- "soundglobal", this, "soundglobalEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Error message sound"), "",
- "sounderror", this, "sounderrorEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Trade request sound"), "",
- "soundtrade", this, "soundtradeEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Show window sound"), "",
- "soundshowwindow", this, "soundshowwindowEvent", mSoundModel);
-
- // TRANSLATORS: settings option
- new SetupItemSound(_("Hide window sound"), "",
- "soundhidewindow", this, "soundhidewindowEvent", mSoundModel);
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Other"), "", this);
-
-#ifdef USE_MUMBLE
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable mumble voice chat"), "",
- "enableMumble", this, "enableMumbleEvent");
-#endif // USE_MUMBLE
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Download music"), "",
- "download-music", this, "download-musicEvent");
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Audio::~Setup_Audio()
-{
- delete2(mSoundModel);
- delete2(mChannelsList);
-}
-
-void Setup_Audio::apply()
-{
- SetupTabScroll::apply();
- if (config.getBoolValue("sound"))
- {
- soundManager.init();
- if (config.getBoolValue("playMusic"))
- {
- if (viewport != nullptr)
- { // in game
- const Map *const map = viewport->getMap();
- if (map != nullptr)
- {
- soundManager.playMusic(map->getMusicFile(),
- SkipError_false);
- }
- }
- else
- { // not in game
- soundManager.playMusic(branding.getValue(
- "loginMusic",
- "keprohm.ogg"),
- SkipError_true);
- }
- }
- else
- {
- soundManager.stopMusic();
- }
- }
- else
- {
- soundManager.close();
- }
-}
diff --git a/src/gui/widgets/tabs/setup_audio.h b/src/gui/widgets/tabs/setup_audio.h
deleted file mode 100644
index d76add16c..000000000
--- a/src/gui/widgets/tabs/setup_audio.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_AUDIO_H
-#define GUI_WIDGETS_TABS_SETUP_AUDIO_H
-
-#include "gui/widgets/setupitem.h"
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class Setup_Audio final : public SetupTabScroll
-{
- public:
- explicit Setup_Audio(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Audio)
-
- ~Setup_Audio();
-
- void apply() override final;
-
- private:
- ListModel *mSoundModel;
-
- SetupItemNames *mChannelsList;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_AUDIO_H
diff --git a/src/gui/widgets/tabs/setup_chat.cpp b/src/gui/widgets/tabs/setup_chat.cpp
deleted file mode 100644
index b27e1ec53..000000000
--- a/src/gui/widgets/tabs/setup_chat.cpp
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_chat.h"
-
-#include "gui/windows/chatwindow.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/setupitem.h"
-
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-Setup_Chat::Setup_Chat(const Widget2 *const widget) :
- SetupTabScroll(widget)
-{
- // TRANSLATORS: settings tab name
- setName(_("Chat"));
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Window"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Auto hide chat window"),
- // TRANSLATORS: settings description
- _("Chat window will be automatically hidden when not in use.\n\n"
- "Hit Enter or hover mouse to show chat again."),
- "autohideChat", this, "autohideChatEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Protect chat focus"),
- // TRANSLATORS: settings description
- _("Enables aggressive protection of input focus in chat window.\n\n"
- "Note: no other text inputs will be allowed to receive text input "
- "when you typing in chat window."),
- "protectChatFocus", this, "protectChatFocusEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Colors"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Remove colors from received chat messages"),
- // TRANSLATORS: settings description
- _("Enable this setting to strip colors from incoming chat messages. "
- "All messages will use default chat text color if this enabled."),
- "removeColors", this, "removeColorsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show chat colors list"),
- // TRANSLATORS: settings description
- _("Enable this setting to show color selection drop-down in chat "
- "window. Chat window will display color selection drop-down.\n\n"
- "It allows one to select default color of outgoing chat messages "
- "easily, but also occupies some space in chat window."),
- "showChatColorsList", this, "showChatColorsListEvent");
-
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Commands"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Allow magic and GM commands in all chat tabs"),
- // TRANSLATORS: settings description
- _("Enable this setting to be able to type spells and GM commands in "
- "any tab."),
- "allowCommandsInChatTabs", this, "allowCommandsInChatTabsEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Limits"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Limit max chars in chat line"),
- // TRANSLATORS: settings description
- _("Limits how many characters will be shown in longest lines "
- "of text displayed in chat.\n\n"
- "Note: long lines can make client slower. Lines longer than this "
- "limit will be truncated."),
- "chatMaxCharLimit", this, "chatMaxCharLimitEvent", 0, 500);
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Limit max lines in chat"),
- // TRANSLATORS: settings description
- _("Limits how many lines chat will keep in scrollback buffer. Chat "
- "keeps specified number of last lines of text. Oldest lines exceeding "
- "this limit are discarded from scrollback buffer.\n\n"
- "Note: keeping too many lines in scroll buffer can slow client down."),
- "chatMaxLinesLimit", this, "chatMaxLinesLimitEvent", 0, 500);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Logs"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable chat Log"),
- // TRANSLATORS: settings description
- _("If you enable this setting, chat logs will be written to disk.\n\n"
- "Note: chat logs can take noticeable amount of disk space over time."),
- "enableChatLog", this, "enableChatLogEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable debug chat Log"),
- // TRANSLATORS: settings description
- _("If you enable this, debug chat tab also will be logged to disk."),
- "enableDebugLog", this, "enableDebugLogEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show chat history"),
- // TRANSLATORS: settings description
- _("If this setting enabled, client will load old chat tabs content "
- "from logs on startup instead of starting with empty chat tabs."),
- "showChatHistory", this, "showChatHistoryEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show party online messages"),
- // TRANSLATORS: settings description
- _("If this setting is enabled, online status changes of party members"
- " will be shown in party tab of chat.\n\nThis adds some extra noise "
- "to chat, but allows one to see when your buddies are coming online."),
- "showPartyOnline", this, "showPartyOnlineEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show guild online messages"),
- // TRANSLATORS: settings description
- _("If this setting is enabled, online status changes of guild members"
- " will be shown in guild tab of chat.\n\nThis adds some extra noise "
- "to chat, but allows one to see when your buddies are coming online."),
- "showGuildOnline", this, "showGuildOnlineEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Messages"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Hide shop messages"),
- // TRANSLATORS: settings description
- _("If this setting enabled, no messages related to built-in ManaPlus "
- "shop will be displayed in chat. Disable this setting if you want "
- "to see shop-related messages.\n\nNote: technically, ManaPlus shop "
- "implemented as usual private messages with special content. If you "
- "disable this setting, you will be able to see these messages and get "
- "idea when other players are looking at your shop."),
- "hideShopMessages", this, "hideShopMessagesEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show MVP messages"),
- // TRANSLATORS: settings description
- _("Enable this setting to see MVP messages from server.\n\n"
- "Note: MVP messages are not used on TMW/Evol/etc servers, so this "
- "feature usually makes little difference."),
- "showMVP", this, "showMVPEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Tabs"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Put all whispers in tabs"),
- // TRANSLATORS: settings description
- _("If this setting enabled, all whispers (private messages) will "
- "be placed in separate tabs, separate tab for each player. If this "
- "setting disabled, all whispers will appear in General tab.\n\n"
- "Note: putting all whispers to single General tab is known to be "
- "confusing. Think twice before disabling this feature."),
- "whispertab", this, "whispertabEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Log magic messages in debug tab"),
- // TRANSLATORS: settings description
- _("If this setting is enabled, spell invocation will be shown in "
- "Debug tab. If disabled, it will be shown in General tab instead.\n\n"
- "Note: it does not affects server replies related to spells."),
- "showMagicInDebug", this, "showMagicInDebugEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show server messages in debug tab"),
- // TRANSLATORS: settings description
- _("If this setting is enabled, server messages will be shown in "
- "Debug tab of chat. If disabled, server messages will appear in "
- "General chat instead.\n\nNote: according to 4144, disabling this "
- "could also make you to lose some debug messages from client in "
- "Debug tab since these are fake server messages."),
- "serverMsgInDebug", this, "serverMsgInDebugEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable trade tab"),
- // TRANSLATORS: settings description
- _("Enables trade tab. Trade tab is basically some filter. Messages "
- "containing words typical for trades will go to Trade tab. This "
- "will make General tab less noisy. If this setting is disabled, all "
- "trade related players messages will stay in General tab."),
- "enableTradeTab", this, "enableTradeTabEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable gm tab"),
- // TRANSLATORS: settings description
- _("If enabled, GM tab will appear in chat. It displays text related "
- "GM activity.\n\nNote: this setting only makes difference for "
- "GMs (Game Masters) since this tab only appears for GMs."),
- "enableGmTab", this, "enableGmTabEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable language tab"),
- // TRANSLATORS: settings description
- _("If this feature enabled, language tab will appear if server "
- "supports this feature.\n\nNote: only supported by Evol server yet."),
- "enableLangTab", this, "enableLangTabEvent",
- MainConfig_false);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show all languages messages"),
- // TRANSLATORS: settings description
- _("If this setting enabled and server supports different chats "
- "for different languages, you will see messages for all languages, "
- "regardless of your language preferences.\n\nNote: it only works "
- "on servers supporting language tabs feature, like Evol."),
- "showAllLang", this, "showAllLangEvent",
- MainConfig_false);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable battle tab"),
- // TRANSLATORS: settings description
- _("If this setting enabled, Battle tab will appear in chat. This "
- "tab will contain messages related to battles, like damage and "
- "experience gain, if battle messages are enabled.\n\n"
- "Note: client restart required to take effect."),
- "enableBattleTab", this, "enableBattleTabEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show battle events"),
- // TRANSLATORS: settings description
- _("If this setting enabled, messages related to battle like damage "
- "or experience gain will be displayed in Debug or Battle tab. If "
- "disabled, no battle messages will be displayed."),
- "showBattleEvents", this, "showBattleEventsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Resize chat tabs if need"),
- // TRANSLATORS: settings description
- _("If this feature enabled, text in chat will be automatically "
- "adjusted to adapt to appearance of chat input field when you "
- "typing message and when input field of chat disappears. If disabled, "
- "chat input area will always occupy its place, which could be "
- "otherwise usable for text.\n\n"
- "Note: its mostly about jumpy attitude vs "
- "less usable space for text."),
- "hideChatInput", this, "hideChatInputEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable trade spam filter"),
- "", "enableTradeFilter", this, "enableTradeFilterEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Time"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Use local time"),
- // TRANSLATORS: settings description
- _("If this feature enabled, timestamps in chat will use local times. "
- "If disabled, server time will be used (often it is GMT+0)."),
- "useLocalTime", this, "useLocalTimeEvent");
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Other"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Highlight words (separated by comma)"),
- // TRANSLATORS: settings description
- _("Here you can specify some extra words which will also cause "
- "highlighting. Use comma to separate words.\n\nNote: frequent "
- "highlights are annoying - use it with caution."),
- "highlightWords", this, "highlightWordsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Globals ignore names (separated by comma)"),
- // TRANSLATORS: settings description
- _("This setting allows you to ignore some global messages if "
- "particular sender (NPC, GM) annoys you too much. Global will be "
- "moved to Debug instead.\n\nNote: careless use of this feature can "
- "make you to miss important announces!"),
- "globalsFilter", this, "globalsFilterEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show emotes button in chat"),
- // TRANSLATORS: settings description
- _("If this setting enabled, button will appear near text input "
- "field. This button allows one to invoke composing window, which "
- "allows one to insert smiles and text formatting easily.\n\n"
- "Note: same window can also be invoked by hotkey when typing, usually "
- "F1 by default."),
- "showEmotesButton", this, "showEmotesButtonEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show motd server message on start"),
- // TRANSLATORS: settings description
- _("If this setting enabled, client will display server MOTD (message"
- " of the day) once you connect to server. Disable it to hide MOTD."),
- "showmotd", this, "showmotdEvent");
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-void Setup_Chat::apply()
-{
- SetupTabScroll::apply();
-
- if (chatWindow != nullptr)
- {
- chatWindow->adjustTabSize();
- chatWindow->parseHighlights();
- }
-}
-
-void Setup_Chat::externalUpdated()
-{
- reread("enableLangTab");
- reread("showAllLang");
-}
diff --git a/src/gui/widgets/tabs/setup_chat.h b/src/gui/widgets/tabs/setup_chat.h
deleted file mode 100644
index 2b18b0489..000000000
--- a/src/gui/widgets/tabs/setup_chat.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_CHAT_H
-#define GUI_WIDGETS_TABS_SETUP_CHAT_H
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class Setup_Chat final : public SetupTabScroll
-{
- public:
- explicit Setup_Chat(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Chat)
-
- void apply() override final;
-
- void externalUpdated() override final;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_CHAT_H
diff --git a/src/gui/widgets/tabs/setup_colors.cpp b/src/gui/widgets/tabs/setup_colors.cpp
deleted file mode 100644
index 4f2b35113..000000000
--- a/src/gui/widgets/tabs/setup_colors.cpp
+++ /dev/null
@@ -1,491 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net>
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_colors.h"
-
-#include "gui/gui.h"
-#include "gui/userpalette.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/widgets/browserbox.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/listbox.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/slider.h"
-#include "gui/widgets/textfield.h"
-#include "gui/widgets/textpreview.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include <cmath>
-
-#include "debug.h"
-
-const char *const Setup_Colors::rawmsg =
- // TRANSLATORS: color selection preview message
- N_("This is what the color looks like");
-
-Setup_Colors::Setup_Colors(const Widget2 *const widget) :
- SetupTab(widget),
- SelectionListener(),
- mColorBox(CREATEWIDGETR(ListBox, this, userPalette, "")),
- mScroll(new ScrollArea(this, mColorBox,
- Opaque_true, "setup_colors_background.xml")),
- mPreview(new BrowserBox(this, Opaque_true,
- "browserbox.xml")),
- mTextPreview(new TextPreview(this, gettext(rawmsg))),
- mPreviewBox(new ScrollArea(this, mPreview, Opaque_true,
- "setup_colors_preview_background.xml")),
- mSelected(-1),
- // TRANSLATORS: colors tab. label.
- mGradTypeLabel(new Label(this, _("Type:"))),
- mGradTypeSlider(new Slider(this, 0.0, 3.0, 1.0)),
- mGradTypeText(new Label(this)),
- // TRANSLATORS: colors tab. label.
- mGradDelayLabel(new Label(this, _("Delay:"))),
- mGradDelaySlider(new Slider(this, 20.0, 100.0, 1.0)),
- mGradDelayText(new TextField(this)),
- // TRANSLATORS: colors tab. label.
- mRedLabel(new Label(this, _("Red:"))),
- mRedSlider(new Slider(this, 0.0, 255.0, 1.0)),
- mRedText(new TextField(this)),
- // TRANSLATORS: colors tab. label.
- mGreenLabel(new Label(this, _("Green:"))),
- mGreenSlider(new Slider(this, 0.0, 255.0, 1.0)),
- mGreenText(new TextField(this)),
- // TRANSLATORS: colors tab. label.
- mBlueLabel(new Label(this, _("Blue:"))),
- mBlueSlider(new Slider(this, 0.0, 255.0, 1.0)),
- mBlueText(new TextField(this))
-{
- // TRANSLATORS: settings colors tab name
- setName(_("Colors"));
- mColorBox->addSelectionListener(this);
- mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mPreview->setOpaque(Opaque_false);
-
- // don't do anything with links
- mPreview->setLinkHandler(nullptr);
-
- mPreviewBox->setHeight(20);
- mPreviewBox->setScrollPolicy(ScrollArea::SHOW_NEVER,
- ScrollArea::SHOW_NEVER);
-
- mGradTypeSlider->setWidth(180);
- mGradTypeSlider->setActionEventId("slider_grad");
- mGradTypeSlider->setValue(0);
- mGradTypeSlider->addActionListener(this);
- mGradTypeSlider->setEnabled(false);
-
- // TRANSLATORS: color type
- std::string longText = _("Static");
-
- const Font *const font = getFont();
- // TRANSLATORS: color type
- if (getFont()->getWidth(_("Pulse")) > font->getWidth(longText))
- {
- // TRANSLATORS: color type
- longText = _("Pulse");
- }
- // TRANSLATORS: color type
- if (getFont()->getWidth(_("Rainbow")) > font->getWidth(longText))
- {
- // TRANSLATORS: color type
- longText = _("Rainbow");
- }
- // TRANSLATORS: color type
- if (getFont()->getWidth(_("Spectrum")) > font->getWidth(longText))
- {
- // TRANSLATORS: color type
- longText = _("Spectrum");
- }
-
- mGradTypeText->setCaption(longText);
-
- mGradDelayText->setWidth(40);
- mGradDelayText->setRange(20, 100);
- mGradDelayText->setNumeric(true);
- mGradDelayText->setEnabled(false);
-
- mGradDelaySlider->setWidth(180);
- mGradDelaySlider->setValue(mGradDelayText->getValue());
- mGradDelaySlider->setActionEventId("slider_graddelay");
- mGradDelaySlider->addActionListener(this);
- mGradDelaySlider->setEnabled(false);
-
- mRedText->setWidth(40);
- mRedText->setRange(0, 255);
- mRedText->setNumeric(true);
- mRedText->setEnabled(false);
-
- mRedSlider->setWidth(180);
- mRedSlider->setValue(mRedText->getValue());
- mRedSlider->setActionEventId("slider_red");
- mRedSlider->addActionListener(this);
- mRedSlider->setEnabled(false);
-
- mGreenText->setWidth(40);
- mGreenText->setRange(0, 255);
- mGreenText->setNumeric(true);
- mGreenText->setEnabled(false);
-
- mGreenSlider->setWidth(180);
- mGreenSlider->setValue(mGreenText->getValue());
- mGreenSlider->setActionEventId("slider_green");
- mGreenSlider->addActionListener(this);
- mGreenSlider->setEnabled(false);
-
- mBlueText->setWidth(40);
- mBlueText->setRange(0, 255);
- mBlueText->setNumeric(true);
- mBlueText->setEnabled(false);
-
- mBlueSlider->setWidth(180);
- mBlueSlider->setValue(mBlueText->getValue());
- mBlueSlider->setActionEventId("slider_blue");
- mBlueSlider->addActionListener(this);
- mBlueSlider->setEnabled(false);
-
- setOpaque(Opaque_false);
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, mScroll, 6, 6).setPadding(2);
- place(0, 6, mPreviewBox, 6).setPadding(2);
- place(0, 7, mGradTypeLabel, 3);
- place(3, 7, mGradTypeSlider);
- place(4, 7, mGradTypeText, 2).setPadding(1);
- place(0, 8, mRedLabel, 3);
- place(3, 8, mRedSlider);
- place(5, 8, mRedText).setPadding(1);
- place(0, 9, mGreenLabel, 3);
- place(3, 9, mGreenSlider);
- place(5, 9, mGreenText).setPadding(1);
- place(0, 10, mBlueLabel, 3);
- place(3, 10, mBlueSlider);
- place(5, 10, mBlueText).setPadding(1);
- place(0, 11, mGradDelayLabel, 3);
- place(3, 11, mGradDelaySlider);
- place(5, 11, mGradDelayText).setPadding(1);
-
- mGradTypeText->setCaption("");
-
- setDimension(Rect(0, 0, 365, 350));
-}
-
-Setup_Colors::~Setup_Colors()
-{
- if ((mPreviewBox != nullptr) && mPreviewBox->getContent() == mPreview)
- delete2(mTextPreview)
- else
- delete2(mPreview)
-}
-
-void Setup_Colors::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == "slider_grad")
- {
- updateGradType();
- updateColor();
- return;
- }
-
- if (eventId == "slider_graddelay")
- {
- mGradDelayText->setText(toString(
- std::floor(mGradDelaySlider->getValue())));
- updateColor();
- return;
- }
- if (eventId == "slider_red")
- {
- mRedText->setText(toString(std::floor(mRedSlider->getValue())));
- updateColor();
- return;
- }
- if (eventId == "slider_green")
- {
- mGreenText->setText(toString(std::floor(mGreenSlider->getValue())));
- updateColor();
- return;
- }
- if (eventId == "slider_blue")
- {
- mBlueText->setText(toString(std::floor(mBlueSlider->getValue())));
- updateColor();
- return;
- }
-}
-
-void Setup_Colors::valueChanged(const SelectionEvent &event A_UNUSED)
-{
- if (userPalette == nullptr)
- return;
-
- mSelected = mColorBox->getSelected();
- const UserColorIdT type = static_cast<UserColorIdT>(
- userPalette->getColorTypeAt(mSelected));
- const Color *col = &userPalette->getColor(type);
- const GradientTypeT grad = userPalette->getGradientType(type);
- const int delay = userPalette->getGradientDelay(type);
- const Visible showControls = fromBool(grad != GradientType::LABEL,
- Visible);
- mPreview->setVisible(showControls);
- mPreviewBox->setVisible(showControls);
- mTextPreview->setVisible(showControls);
- mGradTypeLabel->setVisible(showControls);
- mGradTypeSlider->setVisible(showControls);
- mGradTypeText->setVisible(showControls);
- mGradDelayLabel->setVisible(showControls);
- mGradDelaySlider->setVisible(showControls);
- mGradDelayText->setVisible(showControls);
- mRedLabel->setVisible(showControls);
- mRedSlider->setVisible(showControls);
- mRedText->setVisible(showControls);
- mGreenLabel->setVisible(showControls);
- mGreenSlider->setVisible(showControls);
- mGreenText->setVisible(showControls);
- mBlueLabel->setVisible(showControls);
- mBlueSlider->setVisible(showControls);
- mBlueText->setVisible(showControls);
-
- mPreview->clearRows();
- mPreviewBox->setContent(mTextPreview);
- mTextPreview->setFont(boldFont);
- mTextPreview->setTextColor(col);
- mTextPreview->setTextBGColor(nullptr);
- mTextPreview->setOpaque(Opaque_false);
- mTextPreview->setShadow(true);
- mTextPreview->setOutline(true);
- mTextPreview->useTextAlpha(false);
-
-// probably need combite both switches and add all mssing color ids.
-
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (type)
- {
- case UserColorId::AIR_COLLISION_HIGHLIGHT:
- case UserColorId::WATER_COLLISION_HIGHLIGHT:
- case UserColorId::MONSTER_COLLISION_HIGHLIGHT:
- case UserColorId::GROUNDTOP_COLLISION_HIGHLIGHT:
- case UserColorId::COLLISION_HIGHLIGHT:
- case UserColorId::PORTAL_HIGHLIGHT:
- case UserColorId::HOME_PLACE:
- case UserColorId::ROAD_POINT:
- case UserColorId::NET:
- mTextPreview->setBGColor(col);
- mTextPreview->setOpaque(Opaque_true);
- mTextPreview->setOutline(false);
- mTextPreview->setShadow(false);
- break;
- case UserColorId::ATTACK_RANGE_BORDER:
- case UserColorId::HOME_PLACE_BORDER:
- if (gui != nullptr)
- mTextPreview->setFont(gui->getFont());
- mTextPreview->setTextColor(col);
- mTextPreview->setOutline(false);
- mTextPreview->setShadow(false);
- break;
- case UserColorId::PARTICLE:
- case UserColorId::EXP_INFO:
- case UserColorId::PICKUP_INFO:
- case UserColorId::HIT_PLAYER_MONSTER:
- case UserColorId::HIT_MONSTER_PLAYER:
- case UserColorId::HIT_CRITICAL:
- case UserColorId::MISS:
- case UserColorId::HIT_LOCAL_PLAYER_MONSTER:
- case UserColorId::HIT_LOCAL_PLAYER_CRITICAL:
- case UserColorId::HIT_LOCAL_PLAYER_MISS:
- case UserColorId::ATTACK_RANGE:
- case UserColorId::MONSTER_ATTACK_RANGE:
- case UserColorId::FLOOR_ITEM_TEXT:
- case UserColorId::SKILL_ATTACK_RANGE:
- mTextPreview->setShadow(false);
- break;
- default:
- break;
- }
-
- switch (type)
- {
- case UserColorId::PORTAL_HIGHLIGHT:
- case UserColorId::ATTACK_RANGE:
- case UserColorId::ATTACK_RANGE_BORDER:
- case UserColorId::MONSTER_ATTACK_RANGE:
- case UserColorId::SKILL_ATTACK_RANGE:
- case UserColorId::HOME_PLACE:
- case UserColorId::HOME_PLACE_BORDER:
- case UserColorId::AIR_COLLISION_HIGHLIGHT:
- case UserColorId::WATER_COLLISION_HIGHLIGHT:
- case UserColorId::MONSTER_COLLISION_HIGHLIGHT:
- case UserColorId::GROUNDTOP_COLLISION_HIGHLIGHT:
- case UserColorId::COLLISION_HIGHLIGHT:
- case UserColorId::WALKABLE_HIGHLIGHT:
- case UserColorId::ROAD_POINT:
- case UserColorId::MONSTER_HP:
- case UserColorId::MONSTER_HP2:
- case UserColorId::HOMUN_HP:
- case UserColorId::HOMUN_HP2:
- case UserColorId::MERC_HP:
- case UserColorId::MERC_HP2:
- case UserColorId::ELEMENTAL_HP:
- case UserColorId::ELEMENTAL_HP2:
- case UserColorId::PLAYER_HP:
- case UserColorId::PLAYER_HP2:
- case UserColorId::FLOOR_ITEM_TEXT:
- case UserColorId::NET:
- // TRANSLATORS: colors tab. label.
- mGradDelayLabel->setCaption(_("Alpha:"));
- mGradDelayText->setRange(0, 255);
- mGradDelaySlider->setScale(0, 255);
- break;
- default:
- // TRANSLATORS: colors tab. label.
- mGradDelayLabel->setCaption(_("Delay:"));
- mGradDelayText->setRange(20, 100);
- mGradDelaySlider->setScale(20, 100);
- break;
- }
- PRAGMA45(GCC diagnostic pop)
- if (grad != GradientType::STATIC && grad != GradientType::PULSE)
- { // If nonstatic color, don't display the current, but the committed
- // color at the sliders
- col = &userPalette->getCommittedColor(type);
- }
- else if (grad == GradientType::PULSE)
- {
- col = &userPalette->getTestColor(type);
- }
-
- setEntry(mGradDelaySlider, mGradDelayText, delay);
- setEntry(mRedSlider, mRedText, col->r);
- setEntry(mGreenSlider, mGreenText, col->g);
- setEntry(mBlueSlider, mBlueText, col->b);
-
- mGradTypeSlider->setValue(CAST_S32(grad));
- updateGradType();
- mGradTypeSlider->setEnabled(true);
-}
-
-void Setup_Colors::setEntry(Slider *const s, TextField *const t,
- const int value)
-{
- if (s != nullptr)
- s->setValue(value);
- if (t != nullptr)
- t->setText(toString(value));
-}
-
-void Setup_Colors::apply()
-{
- if (userPalette != nullptr)
- userPalette->commit();
-}
-
-void Setup_Colors::cancel()
-{
- if (userPalette == nullptr)
- return;
-
- userPalette->rollback();
- const UserColorIdT type = static_cast<UserColorIdT>(
- userPalette->getColorTypeAt(mSelected));
- const Color *const col = &userPalette->getColor(type);
- mGradTypeSlider->setValue(CAST_S32(
- userPalette->getGradientType(type)));
- const int delay = userPalette->getGradientDelay(type);
- setEntry(mGradDelaySlider, mGradDelayText, delay);
- setEntry(mRedSlider, mRedText, col->r);
- setEntry(mGreenSlider, mGreenText, col->g);
- setEntry(mBlueSlider, mBlueText, col->b);
-}
-
-void Setup_Colors::updateGradType()
-{
- if (mSelected == -1 || (userPalette == nullptr))
- return;
-
- mSelected = mColorBox->getSelected();
- const UserColorIdT type = static_cast<UserColorIdT>(
- userPalette->getColorTypeAt(mSelected));
- const GradientTypeT grad = userPalette->getGradientType(type);
-
- mGradTypeText->setCaption(
- // TRANSLATORS: color type
- (grad == GradientType::STATIC) ? _("Static") :
- // TRANSLATORS: color type
- (grad == GradientType::PULSE) ? _("Pulse") :
- // TRANSLATORS: color type
- (grad == GradientType::RAINBOW) ? _("Rainbow") : _("Spectrum"));
-
- const bool enable = (grad == GradientType::STATIC ||
- grad == GradientType::PULSE);
- const bool delayEnable = true;
-
- mGradDelayText->setEnabled(delayEnable);
- mGradDelaySlider->setEnabled(delayEnable);
-
- mRedText->setEnabled(enable);
- mRedSlider->setEnabled(enable);
- mGreenText->setEnabled(enable);
- mGreenSlider->setEnabled(enable);
- mBlueText->setEnabled(enable);
- mBlueSlider->setEnabled(enable);
-}
-
-void Setup_Colors::updateColor() const
-{
- if (mSelected == -1 || (userPalette == nullptr))
- return;
-
- const UserColorIdT type = static_cast<UserColorIdT>(
- userPalette->getColorTypeAt(mSelected));
- const GradientTypeT grad = static_cast<GradientTypeT>(
- CAST_S32(mGradTypeSlider->getValue()));
- const int delay = CAST_S32(mGradDelaySlider->getValue());
- userPalette->setGradient(type, grad);
- userPalette->setGradientDelay(type, delay);
-
- if (grad == GradientType::STATIC)
- {
- userPalette->setColor(type,
- CAST_S32(mRedSlider->getValue()),
- CAST_S32(mGreenSlider->getValue()),
- CAST_S32(mBlueSlider->getValue()));
- }
- else if (grad == GradientType::PULSE)
- {
- userPalette->setTestColor(type, Color(
- CAST_S32(mRedSlider->getValue()),
- CAST_S32(mGreenSlider->getValue()),
- CAST_S32(mBlueSlider->getValue())));
- }
-}
diff --git a/src/gui/widgets/tabs/setup_colors.h b/src/gui/widgets/tabs/setup_colors.h
deleted file mode 100644
index 1ba74f340..000000000
--- a/src/gui/widgets/tabs/setup_colors.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008 Douglas Boffey <dougaboffey@netscape.net>
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_COLORS_H
-#define GUI_WIDGETS_TABS_SETUP_COLORS_H
-
-#include "gui/widgets/tabs/setuptab.h"
-
-#include "listeners/selectionlistener.h"
-
-class BrowserBox;
-class Label;
-class ListBox;
-class ScrollArea;
-class Slider;
-class TextField;
-class TextPreview;
-
-class Setup_Colors final : public SetupTab,
- public SelectionListener
-{
- public:
- explicit Setup_Colors(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Colors)
-
- ~Setup_Colors();
-
- void apply() override final;
-
- void cancel() override final;
-
- void action(const ActionEvent &event) override final;
-
- void valueChanged(const SelectionEvent &event) override final;
-
- private:
- static const char *const rawmsg;
-
- ListBox *mColorBox A_NONNULLPOINTER;
- ScrollArea *mScroll A_NONNULLPOINTER;
- BrowserBox *mPreview A_NONNULLPOINTER;
- TextPreview *mTextPreview A_NONNULLPOINTER;
- ScrollArea *mPreviewBox A_NONNULLPOINTER;
- int mSelected;
-
- Label *mGradTypeLabel A_NONNULLPOINTER;
- Slider *mGradTypeSlider A_NONNULLPOINTER;
- Label *mGradTypeText A_NONNULLPOINTER;
-
- Label *mGradDelayLabel A_NONNULLPOINTER;
- Slider *mGradDelaySlider A_NONNULLPOINTER;
- TextField *mGradDelayText A_NONNULLPOINTER;
-
- Label *mRedLabel A_NONNULLPOINTER;
- Slider *mRedSlider A_NONNULLPOINTER;
- TextField *mRedText A_NONNULLPOINTER;
-
- Label *mGreenLabel A_NONNULLPOINTER;
- Slider *mGreenSlider A_NONNULLPOINTER;
- TextField *mGreenText A_NONNULLPOINTER;
-
- Label *mBlueLabel A_NONNULLPOINTER;
- Slider *mBlueSlider A_NONNULLPOINTER;
- TextField *mBlueText A_NONNULLPOINTER;
-
- static void setEntry(Slider *const s, TextField *const t,
- const int value);
- void updateColor() const;
- void updateGradType();
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_COLORS_H
diff --git a/src/gui/widgets/tabs/setup_input.cpp b/src/gui/widgets/tabs/setup_input.cpp
deleted file mode 100644
index dc1e531f8..000000000
--- a/src/gui/widgets/tabs/setup_input.cpp
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007 Joshua Langley <joshlangley@optusnet.com.au>
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_input.h"
-
-#include "configuration.h"
-
-#include "const/gui/pages.h"
-
-#include "input/inputactionoperators.h"
-#include "input/inputmanager.h"
-#include "input/keyboardconfig.h"
-
-#include "input/pages/craft.h"
-#include "input/pages/emotes.h"
-#include "input/pages/move.h"
-#include "input/pages/outfits.h"
-#include "input/pages/shortcuts.h"
-
-#include "gui/gui.h"
-#include "gui/setupinputpages.h"
-
-#include "gui/windows/okdialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/listbox.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/tabstrip.h"
-
-#include "gui/models/keylistmodel.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-Setup_Input::Setup_Input(const Widget2 *const widget) :
- SetupTab(widget),
- mKeyListModel(new KeyListModel),
- mKeyList(CREATEWIDGETR(ListBox, this, mKeyListModel, "")),
- // TRANSLATORS: button in input settings tab
- mAssignKeyButton(new Button(this, _("Assign"), "assign", this)),
- // TRANSLATORS: button in input settings tab
- mUnassignKeyButton(new Button(this, _("Unassign"), "unassign", this)),
- // TRANSLATORS: button in input settings tab
- mDefaultButton(new Button(this, _("Default"), "default", this)),
- // TRANSLATORS: button in input settings tab
- mResetKeysButton(new Button(this, _("Reset all keys"), "resetkeys", this)),
- mTabs(new TabStrip(this, config.getIntValue("fontSize") + 10)),
- mScrollArea(new ScrollArea(this, mKeyList,
- Opaque_true, "setup_input_background.xml")),
- mKeySetting(false),
- mActionDataSize(new int [SETUP_PAGES])
-{
- inputManager.setSetupInput(this);
- // TRANSLATORS: setting tab name
- setName(_("Input"));
-
- mKeyListModel->setSelectedData(0);
-
- for (int f = 0; f < SETUP_PAGES; f ++)
- {
- int cnt = 0;
- while (!setupActionData[f][cnt].name.empty())
- cnt ++;
- mActionDataSize[f] = cnt;
- }
-
- mKeyListModel->setSize(mActionDataSize[0]);
- refreshKeys();
- if (gui != nullptr)
- mKeyList->setFont(gui->getHelpFont());
- mKeyList->addActionListener(this);
-
- mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mAssignKeyButton->addActionListener(this);
- mAssignKeyButton->setEnabled(false);
- mUnassignKeyButton->addActionListener(this);
- mUnassignKeyButton->setEnabled(false);
- mResetKeysButton->addActionListener(this);
- mDefaultButton->addActionListener(this);
-
- mTabs->addActionListener(this);
- mTabs->setActionEventId("tabs_");
- int k = 0;
- while (pages[k] != nullptr)
- {
- mTabs->addButton(gettext(pages[k]), pages[k], false);
- k ++;
- }
-
- fixTranslations();
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, mTabs, 5);
- place(0, 1, mScrollArea, 5, 5).setPadding(2);
- place(0, 6, mResetKeysButton);
- place(2, 6, mAssignKeyButton);
- place(3, 6, mUnassignKeyButton);
- place(4, 6, mDefaultButton);
-
- int width = 600;
- if (config.getIntValue("screenwidth") >= 730)
- width += 100;
-
- setDimension(Rect(0, 0, width, 350));
-}
-
-Setup_Input::~Setup_Input()
-{
- delete2(mKeyList);
- delete2(mKeyListModel);
- delete2(mAssignKeyButton);
- delete2(mUnassignKeyButton);
- delete2(mResetKeysButton);
- delete [] mActionDataSize;
- mActionDataSize = nullptr;
- delete2(mScrollArea);
-}
-
-void Setup_Input::apply()
-{
- keyUnresolved();
- InputActionT key1, key2;
-
- if (inputManager.hasConflicts(key1, key2))
- {
- const std::string str1 = keyToString(key1);
- const std::string str2 = keyToString(key2);
-
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: input settings error header
- _("Key Conflict(s) Detected."),
- // TRANSLATORS: input settings error
- strprintf(_("Conflict \"%s\" and \"%s\" keys. "
- "Resolve them, or gameplay may result in strange behaviour."),
- gettext(str1.c_str()), gettext(str2.c_str())),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::ERROR,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- }
- keyboard.setEnabled(true);
- inputManager.store();
-}
-
-void Setup_Input::cancel()
-{
- keyUnresolved();
- inputManager.retrieve();
- keyboard.setEnabled(true);
- refreshKeys();
-}
-
-void Setup_Input::action(const ActionEvent &event)
-{
- const std::string &id = event.getId();
- const int selectedData = mKeyListModel->getSelectedData();
-
- if (event.getSource() == mKeyList)
- {
- if (!mKeySetting)
- {
- const int i(mKeyList->getSelected());
- if (i >= 0 && i < mActionDataSize[selectedData])
- {
- if (setupActionData[selectedData][i].actionId
- == InputAction::NO_VALUE)
- {
- mAssignKeyButton->setEnabled(false);
- mUnassignKeyButton->setEnabled(false);
- }
- else
- {
- mAssignKeyButton->setEnabled(true);
- mUnassignKeyButton->setEnabled(true);
- }
- }
- }
- }
- else if (id == "assign")
- {
- mKeySetting = true;
- mAssignKeyButton->setEnabled(false);
- keyboard.setEnabled(false);
- const int i(mKeyList->getSelected());
- if (i >= 0 && i < mActionDataSize[selectedData])
- {
- const SetupActionData &key = setupActionData[selectedData][i];
- const InputActionT ik = key.actionId;
- inputManager.setNewKeyIndex(ik);
- mKeyListModel->setElementAt(i, std::string(
- gettext(key.name.c_str())).append(": ?"));
- }
- }
- else if (id == "unassign")
- {
- const int i(mKeyList->getSelected());
- if (i >= 0 && i < mActionDataSize[selectedData])
- {
- const SetupActionData &key = setupActionData[selectedData][i];
- const InputActionT ik = key.actionId;
- inputManager.setNewKeyIndex(ik);
- refreshAssignedKey(mKeyList->getSelected());
- inputManager.unassignKey();
- inputManager.setNewKeyIndex(InputAction::NO_VALUE);
- }
- mAssignKeyButton->setEnabled(true);
- }
- else if (id == "resetkeys")
- {
- inputManager.resetKeys();
- InputManager::update();
- refreshKeys();
- }
- else if (id == "default")
- {
- const int i(mKeyList->getSelected());
- if (i >= 0 && i < mActionDataSize[selectedData])
- {
- const SetupActionData &key = setupActionData[selectedData][i];
- const InputActionT ik = key.actionId;
- inputManager.makeDefault(ik);
- refreshKeys();
- }
- }
- else if (strStartWith(id, "tabs_"))
- {
- int k = 0;
- std::string str("tabs_");
- while (pages[k] != nullptr)
- {
- if (str + pages[k] == id)
- break;
- k ++;
- }
- if ((pages[k] != nullptr) && str + pages[k] == id)
- {
- mKeyListModel->setSelectedData(k);
- mKeyListModel->setSize(mActionDataSize[k]);
- refreshKeys();
- mKeyList->setSelected(0);
- }
- }
-}
-
-void Setup_Input::refreshAssignedKey(const int index)
-{
- const int selectedData = mKeyListModel->getSelectedData();
- const SetupActionData &key = setupActionData[selectedData][index];
- if (key.actionId == InputAction::NO_VALUE)
- {
- const std::string str(" \342\200\225\342\200\225\342\200\225"
- "\342\200\225\342\200\225 ");
- mKeyListModel->setElementAt(index,
- str + gettext(key.name.c_str()) + str);
- }
- else
- {
- std::string str = gettext(key.name.c_str());
- unsigned int sz = 20;
- if (mainGraphics->mWidth > 800)
- sz = 30;
- while (str.size() < sz)
- str.append(" ");
- mKeyListModel->setElementAt(index, strprintf("%s: %s", str.c_str(),
- inputManager.getKeyStringLong(key.actionId).c_str()));
- }
-}
-
-void Setup_Input::newKeyCallback(const InputActionT index)
-{
- mKeySetting = false;
- const int i = keyToSetupData(index);
- if (i >= 0)
- refreshAssignedKey(i);
- mAssignKeyButton->setEnabled(true);
-}
-
-int Setup_Input::keyToSetupData(const InputActionT index) const
-{
- const int selectedData = mKeyListModel->getSelectedData();
- for (int i = 0; i < mActionDataSize[selectedData]; i++)
- {
- const SetupActionData &key = setupActionData[selectedData][i];
- if (key.actionId == index)
- return i;
- }
- return -1;
-}
-
-std::string Setup_Input::keyToString(const InputActionT index) const
-{
- for (int f = 0; f < SETUP_PAGES; f ++)
- {
- for (int i = 0; i < mActionDataSize[f]; i++)
- {
- const SetupActionData &key = setupActionData[f][i];
- if (key.actionId == index)
- return key.name;
- }
- }
- // TRANSLATORS: unknown key name
- return _("unknown");
-}
-
-void Setup_Input::refreshKeys()
-{
- const int selectedData = mKeyListModel->getSelectedData();
- for (int i = 0; i < mActionDataSize[selectedData]; i++)
- refreshAssignedKey(i);
-}
-
-void Setup_Input::keyUnresolved()
-{
- if (mKeySetting)
- {
- newKeyCallback(inputManager.getNewKeyIndex());
- inputManager.setNewKeyIndex(InputAction::NO_VALUE);
- }
-}
-
-void Setup_Input::fixTranslation(SetupActionData *const actionDatas,
- const InputActionT actionStart,
- const InputActionT actionEnd,
- const std::string &text)
-{
- int k = 0;
-
- while (!actionDatas[k].name.empty())
- {
- SetupActionData &data = actionDatas[k];
-
- const InputActionT actionId = data.actionId;
- if (actionId >= actionStart && actionId <= actionEnd)
- {
- data.name = strprintf(gettext(text.c_str()),
- actionId - actionStart + 1);
- }
- k ++;
- }
-}
-
-void Setup_Input::fixTranslations()
-{
- fixTranslation(setupActionDataShortcuts,
- InputAction::SHORTCUT_1,
- InputAction::SHORTCUT_20,
- "Item Shortcut %d");
-
- fixTranslation(setupActionDataEmotes,
- InputAction::EMOTE_1,
- InputAction::EMOTE_48,
- "Emote Shortcut %d");
-
- fixTranslation(setupActionDataCraft,
- InputAction::CRAFT_1,
- InputAction::CRAFT_9,
- "Craft shortcut %d");
-
- fixTranslation(setupActionDataOutfits,
- InputAction::OUTFIT_1,
- InputAction::OUTFIT_48,
- "Outfit Shortcut %d");
-
- fixTranslation(setupActionDataMove,
- InputAction::MOVE_TO_POINT_1,
- InputAction::MOVE_TO_POINT_48,
- "Move to point Shortcut %d");
-}
diff --git a/src/gui/widgets/tabs/setup_input.h b/src/gui/widgets/tabs/setup_input.h
deleted file mode 100644
index 2da411b2c..000000000
--- a/src/gui/widgets/tabs/setup_input.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2007 Joshua Langley <joshlangley@optusnet.com.au>
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_INPUT_H
-#define GUI_WIDGETS_TABS_SETUP_INPUT_H
-
-#include "enums/input/inputaction.h"
-
-#include "gui/widgets/tabs/setuptab.h"
-
-class Button;
-class ListBox;
-class KeyListModel;
-class ScrollArea;
-class TabStrip;
-
-struct SetupActionData;
-
-class Setup_Input final : public SetupTab
-{
- public:
- /**
- * Constructor
- */
- explicit Setup_Input(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Input)
-
- /**
- * Destructor
- */
- ~Setup_Input();
-
- void apply() override final;
-
- void cancel() override final;
-
- void action(const ActionEvent &event) override final;
-
- /**
- * Get an update on the assigned key.
- */
- void refreshAssignedKey(const int index);
-
- /**
- * The callback function when a new key has been pressed.
- */
- void newKeyCallback(const InputActionT index);
-
- /**
- * Shorthand method to update all the keys.
- */
- void refreshKeys();
-
- /**
- * If a key function is unresolved, then this reverts it.
- */
- void keyUnresolved();
-
- int keyToSetupData(const InputActionT index) const A_WARN_UNUSED;
-
- std::string keyToString(const InputActionT index) const A_WARN_UNUSED;
-
- private:
- static void fixTranslations();
-
- static void fixTranslation(SetupActionData *const actionDatas,
- const InputActionT actionStart,
- const InputActionT actionEnd,
- const std::string &text) A_NONNULL(1);
-
- KeyListModel *mKeyListModel;
- ListBox *mKeyList;
-
- Button *mAssignKeyButton;
- Button *mUnassignKeyButton;
- Button *mDefaultButton;
- Button *mResetKeysButton;
- TabStrip *mTabs;
- ScrollArea *mScrollArea;
- bool mKeySetting; /**< flag to check if key being set. */
- int *mActionDataSize;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_INPUT_H
diff --git a/src/gui/widgets/tabs/setup_joystick.cpp b/src/gui/widgets/tabs/setup_joystick.cpp
deleted file mode 100644
index 84cd60521..000000000
--- a/src/gui/widgets/tabs/setup_joystick.cpp
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_joystick.h"
-
-#include "configuration.h"
-
-#include "input/joystick.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/checkbox.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layouthelper.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-Setup_Joystick::Setup_Joystick(const Widget2 *const widget) :
- SetupTab(widget),
- mCalibrateLabel(new Label(this,
- // TRANSLATORS: joystick settings tab label
- _("Press the button to start calibration"))),
- // TRANSLATORS: joystick settings tab button
- mCalibrateButton(new Button(this, _("Calibrate"), "calibrate", this)),
- // TRANSLATORS: joystick settings tab button
- mDetectButton(new Button(this, _("Detect joysticks"), "detect", this)),
- // TRANSLATORS: joystick settings tab checkbox
- mJoystickEnabled(new CheckBox(this, _("Enable joystick"))),
- mNamesModel(new NamesModel),
- mNamesDropDown(new DropDown(this, mNamesModel)),
- // TRANSLATORS: joystick settings tab checkbox
- mUseInactiveCheckBox(new CheckBox(this, _("Use joystick if client "
- "window inactive"), config.getBoolValue("useInactiveJoystick"))),
- mOriginalJoystickEnabled(config.getBoolValue("joystickEnabled"))
-{
- // TRANSLATORS: joystick settings tab name
- setName(_("Joystick"));
-
- Joystick::getNames(mNamesModel->getNames());
-
- mJoystickEnabled->setSelected(mOriginalJoystickEnabled);
- mJoystickEnabled->setActionEventId("joystick");
- mJoystickEnabled->addActionListener(this);
- mCalibrateButton->setEnabled(mOriginalJoystickEnabled);
-
- mNamesDropDown->setActionEventId("name");
- mNamesDropDown->addActionListener(this);
-
- if (joystick != nullptr)
- {
- mNamesDropDown->setSelected(joystick->getNumber());
- }
- else
- {
- unsigned int sel = config.getIntValue("selectedJoystick");
- if (sel >= CAST_U32(mNamesModel->size()))
- sel = 0;
- mNamesDropDown->setSelected(sel);
- }
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, mJoystickEnabled);
- place(0, 1, mNamesDropDown);
- place(0, 2, mUseInactiveCheckBox);
- place(0, 3, mDetectButton);
- place(0, 4, mCalibrateLabel);
- place(0, 5, mCalibrateButton);
-
- setDimension(Rect(0, 0, 365, 75));
-}
-
-Setup_Joystick::~Setup_Joystick()
-{
- delete2(mNamesModel);
-}
-
-void Setup_Joystick::action(const ActionEvent &event)
-{
- const Widget *const source = event.getSource();
- if (source == mJoystickEnabled)
- {
- setTempEnabled(mJoystickEnabled->isSelected());
- }
- else if (source == mNamesDropDown)
- {
- if (joystick != nullptr)
- joystick->setNumber(mNamesDropDown->getSelected());
- }
- else if (source == mDetectButton)
- {
- if (joystick != nullptr)
- {
- joystick->reload();
- Joystick::getNames(mNamesModel->getNames());
- mNamesDropDown->setSelected(joystick->getNumber());
- }
- }
- else
- {
- if (joystick == nullptr)
- return;
-
- if (joystick->isCalibrating())
- {
- // TRANSLATORS: joystick settings tab button
- mCalibrateButton->setCaption(_("Calibrate"));
- mCalibrateLabel->setCaption
- // TRANSLATORS: joystick settings tab label
- (_("Press the button to start calibration"));
- joystick->finishCalibration();
- }
- else
- {
- // TRANSLATORS: joystick settings tab button
- mCalibrateButton->setCaption(_("Stop"));
- mCalibrateLabel->setCaption(
- // TRANSLATORS: joystick settings tab label
- _("Rotate the stick and don't press buttons"));
- joystick->startCalibration();
- }
- }
-}
-
-void Setup_Joystick::setTempEnabled(const bool sel)
-{
- Joystick::setEnabled(sel);
- mCalibrateButton->setEnabled(sel);
- if (joystick != nullptr)
- {
- if (sel)
- joystick->open();
- else
- joystick->close();
- }
-}
-
-void Setup_Joystick::cancel()
-{
- Joystick::setEnabled(mOriginalJoystickEnabled);
-
- if (mOriginalJoystickEnabled != mJoystickEnabled->isSelected())
- setTempEnabled(mOriginalJoystickEnabled);
-
- mJoystickEnabled->setSelected(mOriginalJoystickEnabled);
-}
-
-void Setup_Joystick::apply()
-{
- if (joystick == nullptr)
- return;
-
- config.setValue("joystickEnabled", Joystick::isEnabled());
-
- config.setValue("useInactiveJoystick", mUseInactiveCheckBox->isSelected());
- joystick->setUseInactive(mUseInactiveCheckBox->isSelected());
-}
diff --git a/src/gui/widgets/tabs/setup_joystick.h b/src/gui/widgets/tabs/setup_joystick.h
deleted file mode 100644
index c66ab8687..000000000
--- a/src/gui/widgets/tabs/setup_joystick.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_JOYSTICK_H
-#define GUI_WIDGETS_TABS_SETUP_JOYSTICK_H
-
-#include "gui/widgets/tabs/setuptab.h"
-
-class Button;
-class CheckBox;
-class DropDown;
-class Label;
-class NamesModel;
-
-class Setup_Joystick final : public SetupTab
-{
- public:
- explicit Setup_Joystick(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Joystick)
-
- ~Setup_Joystick();
-
- void apply() override final;
-
- void cancel() override final;
-
- void action(const ActionEvent &event) override final;
-
- void setTempEnabled(const bool sel);
-
- private:
- Label *mCalibrateLabel A_NONNULLPOINTER;
- Button *mCalibrateButton A_NONNULLPOINTER;
- Button *mDetectButton A_NONNULLPOINTER;
- CheckBox *mJoystickEnabled A_NONNULLPOINTER;
- NamesModel *mNamesModel A_NONNULLPOINTER;
- DropDown *mNamesDropDown A_NONNULLPOINTER;
- CheckBox *mUseInactiveCheckBox A_NONNULLPOINTER;
- bool mOriginalJoystickEnabled A_NONNULLPOINTER;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_JOYSTICK_H
diff --git a/src/gui/widgets/tabs/setup_misc.cpp b/src/gui/widgets/tabs/setup_misc.cpp
deleted file mode 100644
index 07b4c5193..000000000
--- a/src/gui/widgets/tabs/setup_misc.cpp
+++ /dev/null
@@ -1,518 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_misc.h"
-
-#include "configuration.h"
-
-#include "const/resources/map/map.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/setupbuttonitem.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "listeners/uploadlistener.h"
-
-#include "net/net.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-static const int shortcutsListSize = 3;
-
-static const char *const shortcutsList[] =
-{
- // TRANSLATORS: show buttons at top right corner type
- N_("Always show"),
- // TRANSLATORS: show buttons at top right corner type
- N_("Auto hide in small resolution"),
- // TRANSLATORS: show buttons at top right corner type
- N_("Always auto hide")
-};
-
-static const int proxyTypeListSize = 8;
-
-static const char *const proxyTypeList[] =
-{
- // TRANSLATORS: Proxy type selection
- N_("System proxy"),
- // TRANSLATORS: Proxy type selection
- N_("Direct connection"),
- "HTTP",
- "HTTP 1.0",
- "SOCKS4",
- "SOCKS4A",
- "SOCKS5",
- // TRANSLATORS: Proxy type selection
- N_("SOCKS5 hostname")
-};
-
-static const int densityListSize = 7;
-
-static const char *const densityList[] =
-{
- // TRANSLATORS: screen density type
- N_("default"),
- // TRANSLATORS: screen density type
- N_("low"),
- // TRANSLATORS: screen density type
- N_("medium"),
- // TRANSLATORS: screen density type
- N_("tv"),
- // TRANSLATORS: screen density type
- N_("high"),
- // TRANSLATORS: screen density type
- N_("xhigh"),
- // TRANSLATORS: screen density type
- N_("xxhigh")
-};
-
-#ifdef USE_SDL2
-static const int sdlLogListSize = 7;
-
-static const char *const sdlLogList[] =
-{
- // TRANSLATORS: sdl2 log level
- N_("default"),
- // TRANSLATORS: sdl2 log level
- N_("verbose"),
- // TRANSLATORS: sdl2 log level
- N_("debug"),
- // TRANSLATORS: sdl2 log level
- N_("info"),
- // TRANSLATORS: sdl2 log level
- N_("warn"),
- // TRANSLATORS: sdl2 log level
- N_("error"),
- // TRANSLATORS: sdl2 log level
- N_("critical")
-};
-#endif // USE_SDL2
-
-Setup_Misc::Setup_Misc(const Widget2 *const widget) :
- SetupTabScroll(widget),
- mProxyTypeList(new NamesModel),
- mShortcutsList(new NamesModel),
-#ifdef USE_SDL2
- mSdlLogList(new NamesModel),
-#endif // USE_SDL2
- mDensityList(new NamesModel)
-{
- // TRANSLATORS: misc tab in settings
- setName(_("Misc"));
-
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Monsters"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show damage inflicted to monsters"), "",
- "showMonstersTakedDamage", this, "showMonstersTakedDamageEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Auto target only reachable monsters"), "",
- "targetOnlyReachable", this, "targetOnlyReachableEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Select auto target for attack skills"), "",
- "skillAutotarget", this, "skillAutotargetEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Highlight monster attack range"), "",
- "highlightMonsterAttackRange", this,
- "highlightMonsterAttackRangeEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show monster hp bar"), "",
- "showMobHP", this, "showMobHPEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Cycle monster targets"), "",
- "cycleMonsters", this, "cycleMonstersEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Map"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show warps particles"), "",
- "warpParticle", this, "warpParticleEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Highlight map portals"), "",
- "highlightMapPortals", this, "highlightMapPortalsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Highlight floor items"), "",
- "floorItemsHighlight", this, "floorItemsHighlightEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Highlight player attack range"), "",
- "highlightAttackRange", this, "highlightAttackRangeEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show extended minimaps"), "",
- "showExtMinimaps", this, "showExtMinimapsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Draw path"), "", "drawPath",
- this, "drawPathEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Draw hotkeys on map"), "", "drawHotKeys",
- this, "drawHotKeysEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable lazy scrolling"), "",
- "enableLazyScrolling", this, "enableLazyScrollingEvent");
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Scroll laziness"), "", "ScrollLaziness",
- this, "ScrollLazinessEvent", 1, 160);
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Scroll radius"), "", "ScrollRadius",
- this, "ScrollRadiusEvent", 0, mapTileSize);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Auto resize minimaps"), "", "autoresizeminimaps",
- this, "autoresizeminimapsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Play map animations"), "", "playMapAnimations",
- this, "playMapAnimationsEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Moving"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Auto fix position"), "",
- "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");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Attack next target"), "",
- "attackNext", this, "attackNextEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Sync player move"), "", "syncPlayerMove",
- this, "syncPlayerMoveEvent");
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Sync player move distance"), "",
- "syncPlayerMoveDistance",
- this, "syncPlayerMoveDistanceEvent", 1, 30);
-
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Crazy move A program"), "",
- "crazyMoveProgram", this, "crazyMoveProgramEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Mouse relative moves "
- "(good for touch interfaces)"), "", "mouseDirectionMove",
- this, "mouseDirectionMoveEvent");
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Player"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show own hp bar"), "",
- "showOwnHP", this, "showOwnHPEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable quick stats"), "",
- "quickStats", this, "quickStatsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Cycle player targets"), "",
- "cyclePlayers", this, "cyclePlayersEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show job exp messages"), "",
- "showJobExp", this, "showJobExpEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show players popups"), "",
- "showBeingPopup", this, "showBeingPopupEvent");
-
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Afk message"), "",
- "afkMessage", this, "afkMessageEvent",
- MainConfig_false);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show job"), "", "showJob",
- this, "showJobEvent",
- MainConfig_false);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable attack filter"), "",
- "enableAttackFilter", this, "enableAttackFilterEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable pickup filter"), "",
- "enablePickupFilter", this, "enablePickupFilterEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable advert protocol"), "",
- "enableAdvert", this, "enableAdvertEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enabled pets support"),
- "", "usepets", this, "usepetsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable weight notifications"), "",
- "weightMsg", this, "weightMsgEvent");
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Shop"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Accept sell/buy requests"), "",
- "autoShop", this, "autoShopEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable shop mode"), "",
- "tradebot", this, "tradebotEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("NPC"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Cycle npc targets"), "",
- "cycleNPC", this, "cycleNPCEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Log NPC dialogue"), "", "logNpcInGui",
- this, "logNpcInGuiEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Bots support"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable guild bot support and disable native "
- "guild support"), "", "enableGuildBot", this,
- "enableGuildBotEvent",
- "0",
- MainConfig_false);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable manamarket bot support"),
- "", "enableManaMarketBot", this,
- "enableManaMarketBotEvent",
- "0",
- MainConfig_false);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Keyboard"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Repeat delay"), "",
- "repeateDelay", this, "repeateDelayEvent", 0, 10000);
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Repeat interval"), "",
- "repeateInterval", this, "repeateIntervalEvent", 0, 10000);
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Custom repeat interval"), "",
- "repeateInterval2", this, "repeateInterval2Event", 0, 10000);
-
-#ifdef USE_SDL2
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable alt-tab workaround"), "",
- "blockAltTab", this, "blockAltTabEvent");
-#endif // USE_SDL2
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Windows"), "", this);
-
- mShortcutsList->fillFromArray(&shortcutsList[0], shortcutsListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Shortcut buttons"), "", "autohideButtons", this,
- "autohideButtonsEvent", mShortcutsList, 200);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Proxy server"), "", this);
-
- mProxyTypeList->fillFromArray(&proxyTypeList[0], proxyTypeListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Proxy type"), "", "downloadProxyType", this,
- "downloadProxyTypeEvent", mProxyTypeList, 200);
-
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Proxy address:port"), "",
- "downloadProxy", this, "downloadProxyEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Tunnel through HTTP proxy"), "",
- "downloadProxyTunnel", this, "downloadProxyTunnelEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Logging"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable OpenGL version check "
- "(do not disable)"), "", "checkOpenGLVersion", this,
- "checkOpenGLVersionEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable debug log"), "",
- "debugLog", this, "debugLogEvent");
-
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Ignore logging packets"), "",
- "ignorelogpackets", this, "ignorelogpacketsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Log unimplemented packets"), "",
- "unimplimentedLog", this, "unimplimentedLogEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable OpenGL log"), "",
- "debugOpenGL", this, "debugOpenGLEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable input log"), "",
- "logInput", this, "logInputEvent");
-
-#ifdef USE_SDL2
- mSdlLogList->fillFromArray(&sdlLogList[0], sdlLogListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("SDL logging level"), "",
- "sdlLogLevel", this, "sdlLogLevelEvent", mSdlLogList, 100);
-#endif // USE_SDL2
-
- // TRANSLATORS: settings option
- new SetupButtonItem(_("Upload log file"), "", "upload",
- this, "uploadLog", &uploadListener);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Other"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable server side attack"), "",
- "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");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable bot checker"), "",
- "enableBotCheker", this, "enableBotChekerEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable buggy servers protection "
- "(do not disable)"), "", "enableBuggyServers", this,
- "enableBuggyServersEvent",
- MainConfig_false);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Low traffic mode"), "", "lowTraffic",
- this, "lowTrafficEvent");
-
-#ifndef ANDROID
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Use FBO for screenshots (only for opengl)"),
- "", "usefbo", this, "usefboEvent");
-#endif // ANDROID
-
-#ifndef WIN32
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Screenshot directory"), "",
- "screenshotDirectory3", this, "screenshotDirectory3Event",
- MainConfig_true,
- UseBase64_true);
-#endif // WIN32
-
- // TRANSLATORS: settings option
- new SetupItemIntTextField(_("Network delay between sub servers"),
- "", "networksleep", this, "networksleepEvent", 0, 10000);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show background"), "", "showBackground",
- this, "showBackgroundEvent");
-
- mDensityList->fillFromArray(&densityList[0], densityListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Screen density override"), "",
- "screenDensity", this, "screenDensityEvent", mDensityList, 100);
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Misc::~Setup_Misc()
-{
- delete2(mProxyTypeList);
- delete2(mShortcutsList);
- delete2(mDensityList);
-#ifdef USE_SDL2
- delete2(mSdlLogList);
-#endif // USE_SDL2
-}
-
-void Setup_Misc::apply()
-{
- SetupTabScroll::apply();
-
- logger->setDebugLog(config.getBoolValue("debugLog"));
- logger->setReportUnimplemented(config.getBoolValue("unimplimentedLog"));
- Net::loadIgnorePackets();
-}
-
-void Setup_Misc::externalUpdated()
-{
- reread("showJob");
- reread("enableGuildBot");
- reread("enableManaMarketBot");
- reread("enableBuggyServers");
- reread("afkMessage");
-}
diff --git a/src/gui/widgets/tabs/setup_misc.h b/src/gui/widgets/tabs/setup_misc.h
deleted file mode 100644
index 787f4c181..000000000
--- a/src/gui/widgets/tabs/setup_misc.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_MISC_H
-#define GUI_WIDGETS_TABS_SETUP_MISC_H
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class NamesModel;
-
-class Setup_Misc final : public SetupTabScroll
-{
- public:
- explicit Setup_Misc(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Misc)
-
- ~Setup_Misc();
-
- void apply() override final;
-
- void externalUpdated() override final;
-
- protected:
- NamesModel *mProxyTypeList;
- NamesModel *mShortcutsList;
-#ifdef USE_SDL2
- NamesModel *mSdlLogList;
-#endif // USE_SDL2
- NamesModel *mDensityList;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_MISC_H
diff --git a/src/gui/widgets/tabs/setup_mods.cpp b/src/gui/widgets/tabs/setup_mods.cpp
deleted file mode 100644
index c3ca23245..000000000
--- a/src/gui/widgets/tabs/setup_mods.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_mods.h"
-
-#include "configuration.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/setupitem.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "resources/db/moddb.h"
-
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-Setup_Mods::Setup_Mods(const Widget2 *const widget) :
- SetupTabScroll(widget)
-{
- // TRANSLATORS: mods tab in settings
- setName(_("Mods"));
-
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Mods::~Setup_Mods()
-{
-}
-
-void Setup_Mods::apply()
-{
- SetupTabScroll::apply();
- saveMods();
-}
-
-void Setup_Mods::externalUpdated()
-{
- clear();
- loadMods();
-}
-
-void Setup_Mods::loadMods()
-{
- std::string modsString = serverConfig.getValue("mods", "");
- std::set<std::string> modsList;
- splitToStringSet(modsList, modsString, '|');
-
- const ModInfos &mods = ModDB::getAll();
- if (mods.empty())
- {
- // TRANSLATORS: settings label
- new SetupItemLabel(_("No mods present"), "", this,
- Separator_false);
- return;
- }
-
- FOR_EACH (ModInfoCIterator, it, mods)
- {
- const ModInfo *const info = (*it).second;
- if (info == nullptr)
- continue;
-
- std::string name = info->getName();
- replaceAll(name, "|", "");
- SetupItem *const item = new SetupItemCheckBox(
- info->getDescription(), "", "", this, name);
- if (modsList.find(name) != modsList.end())
- item->setValue("1");
- else
- item->setValue("0");
- item->toWidget();
- }
-}
-
-void Setup_Mods::saveMods() const
-{
- const ModInfos &mods = ModDB::getAll();
- if (mods.empty())
- return;
-
- std::string modsString;
- const std::set<SetupItem*> &modsList = getAllItems();
- FOR_EACH (std::set<SetupItem*>::const_iterator, it, modsList)
- {
- const SetupItem *const item = *it;
- if (item == nullptr)
- continue;
- const std::string val = item->getValue();
- if (val == "1")
- {
- const std::string key = item->getEventName();
- if (!modsString.empty())
- modsString.append("|");
- modsString.append(key);
- }
- }
- serverConfig.setValue("mods", modsString);
-}
-
-void Setup_Mods::externalUnloaded()
-{
- clear();
-}
diff --git a/src/gui/widgets/tabs/setup_mods.h b/src/gui/widgets/tabs/setup_mods.h
deleted file mode 100644
index 488915d31..000000000
--- a/src/gui/widgets/tabs/setup_mods.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_MODS_H
-#define GUI_WIDGETS_TABS_SETUP_MODS_H
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class Setup_Mods final : public SetupTabScroll
-{
- public:
- explicit Setup_Mods(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Mods)
-
- ~Setup_Mods();
-
- void apply() override final;
-
- void externalUpdated() override final;
-
- void externalUnloaded() override final;
-
- void loadMods();
-
- void saveMods() const;
-
- protected:
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_MODS_H
diff --git a/src/gui/widgets/tabs/setup_perfomance.cpp b/src/gui/widgets/tabs/setup_perfomance.cpp
deleted file mode 100644
index e12bd2872..000000000
--- a/src/gui/widgets/tabs/setup_perfomance.cpp
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_perfomance.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/setupitem.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-#ifdef USE_SDL2
-#include "configuration.h"
-#include "utils/sdlhelper.h"
-#endif // USE_SDL2
-
-#include "debug.h"
-
-static const int texturesListSize = 5;
-
-static const char *const texturesList[] =
-{
- // TRANSLATORS: texture compression type
- N_("No"),
- "s3tc",
- "fxt1",
- "ARB",
- "bptc"
-};
-
-Setup_Perfomance::Setup_Perfomance(const Widget2 *const widget) :
- SetupTabScroll(widget),
-#ifdef USE_SDL2
- mSdlDriversList(new NamesModel),
-#endif // USE_SDL2
- mTexturesList(new NamesModel)
-{
- // TRANSLATORS: settings tab name
- setName(_("Performance"));
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
-#ifdef USE_SDL2
- StringVect sdlDriversList;
- SDL::getRenderers(sdlDriversList,
- config.getStringValue("sdlDriver"));
- sdlDriversList.insert(sdlDriversList.begin(),
- // TRANSLATORS: sdl driver name
- N_("default"));
-#endif // USE_SDL2
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Better performance (enable for better performance)"),
- "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Auto adjust performance"), "",
- "adjustPerfomance", this, "adjustPerfomanceEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Hw acceleration"), "",
- "hwaccel", this, "hwaccelEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable opacity cache (Software, can "
- "use much memory)"), "", "alphaCache", this, "alphaCacheEvent");
-
-#ifndef USE_SDL2
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable map reduce (Software)"), "",
- "enableMapReduce", this, "enableMapReduceEvent");
-#endif // USE_SDL2
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable compound sprite delay (Software)"), "",
- "enableCompoundSpriteDelay", this, "enableCompoundSpriteDelayEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable delayed images load (OpenGL)"), "",
- "enableDelayedAnimations", this, "enableDelayedAnimationsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable texture sampler (OpenGL)"), "",
- "useTextureSampler", this, "useTextureSamplerEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable OpenGL context creation"),
- "", "openglContext", this, "openglContextEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable OpenGL direct state access"),
- "", "enableDSA", this, "enableDSAEvent");
-
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Better quality (disable for better performance)"),
- "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable alpha channel fix (Software, can "
- "be very slow)"), "Can slow down drawing", "enableAlphaFix",
- this, "enableAlphaFixEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show beings transparency"), "",
- "beingopacity", this, "beingopacityEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable reorder sprites (need for mods support)."),
- "", "enableReorderSprites", this, "enableReorderSpritesEvent");
-
-
-#ifndef USE_SDL2
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Small memory (enable for lower memory usage)"),
- "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Disable advanced beings caching (Software)"), "",
- "disableAdvBeingCaching", this, "disableAdvBeingCachingEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Disable beings caching (Software)"), "",
- "disableBeingCaching", this, "disableBeingCachingEvent");
-#endif // USE_SDL2
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Different options (enable or disable can "
- "improve performance)"), "", this);
-
-#ifdef USE_SDL2
- mSdlDriversList->fillFromVector(sdlDriversList);
- new SetupItemDropDownStr(
- // TRANSLATORS: settings option
- _("Try first sdl driver (only for SDL2 default mode)"),
- "", "sdlDriver", this, "sdlDriverEvent", mSdlDriversList, 100);
-#endif // USE_SDL2
-
- mTexturesList->fillFromArray(&texturesList[0], texturesListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Enable texture compression (OpenGL)"), "",
- "compresstextures", this, "compresstexturesEvent", mTexturesList, 100);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable rectangular texture extension (OpenGL)"),
- "", "rectangulartextures", this, "rectangulartexturesEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Use new texture internal format (OpenGL)"),
- "", "newtextures", this, "newtexturesEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable texture atlases (OpenGL)"), "",
- "useAtlases", this, "useAtlasesEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Cache all sprites per map (can use "
- "additional memory)"), "", "uselonglivesprites", this,
- "uselonglivespritesEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Cache all sounds (can use additional memory)"),
- "", "uselonglivesounds", this,
- "uselonglivesoundsEvent");
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Critical options (DO NOT change if you don't "
- "know what you're doing)"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Disable logging in game (do not enable)"),
- "", "disableLoggingInGame", this, "disableLoggingInGameEvent");
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Perfomance::~Setup_Perfomance()
-{
- delete2(mTexturesList);
-#ifdef USE_SDL2
- delete2(mSdlDriversList);
-#endif // USE_SDL2
-}
diff --git a/src/gui/widgets/tabs/setup_perfomance.h b/src/gui/widgets/tabs/setup_perfomance.h
deleted file mode 100644
index 95030a8e5..000000000
--- a/src/gui/widgets/tabs/setup_perfomance.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_PERFOMANCE_H
-#define GUI_WIDGETS_TABS_SETUP_PERFOMANCE_H
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class NamesModel;
-
-class Setup_Perfomance final : public SetupTabScroll
-{
- public:
- explicit Setup_Perfomance(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Perfomance)
-
- ~Setup_Perfomance();
-
- private:
-#ifdef USE_SDL2
- NamesModel *mSdlDriversList;
-#endif // USE_SDL2
- NamesModel *mTexturesList;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_PERFOMANCE_H
diff --git a/src/gui/widgets/tabs/setup_players.cpp b/src/gui/widgets/tabs/setup_players.cpp
deleted file mode 100644
index 6d964799d..000000000
--- a/src/gui/widgets/tabs/setup_players.cpp
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_players.h"
-
-#include "configuration.h"
-#include "settings.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/setupitem.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-static const int badgesListSize = 4;
-
-static const char *const badgesList[] =
-{
- // TRANSLATORS: screen badges type
- N_("hide"),
- // TRANSLATORS: screen badges type
- N_("show at top"),
- // TRANSLATORS: screen badges type
- N_("show at right"),
- // TRANSLATORS: screen badges type
- N_("show at bottom"),
-};
-
-static const int visibleNamesListSize = 3;
-
-static const char *const visibleNamesList[] =
-{
- // TRANSLATORS: visible name type
- N_("hide"),
- // TRANSLATORS: visible name type
- N_("show"),
- // TRANSLATORS: visible name type
- N_("show on selection")
-};
-
-static const int topDownListSize = 2;
-
-static const char *const topDownList[] =
-{
- // TRANSLATORS: show on top or down
- N_("top"),
- // TRANSLATORS: show on top or down
- N_("bottom")
-};
-
-Setup_Players::Setup_Players(const Widget2 *const widget) :
- SetupTabScroll(widget),
- mBadgesList(new NamesModel),
- mVisibleNamesList(new NamesModel),
- mVisibleNamesPosList(new NamesModel)
-{
- // TRANSLATORS: settings tab name
- setName(_("Players"));
-
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show gender"), "",
- "showgender", this, "showgenderEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show level"), "",
- "showlevel", this, "showlevelEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show own name"), "",
- "showownname", this, "showownnameEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable extended mouse targeting"), "",
- "extMouseTargeting", this, "extMouseTargetingEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Target dead players"), "",
- "targetDeadPlayers", this, "targetDeadPlayersEvent");
-
- mVisibleNamesList->fillFromArray(&visibleNamesList[0],
- visibleNamesListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Show player names"), "",
- "visiblenames", this, "visiblenamesEvent",
- mVisibleNamesList, 150);
-
- mVisibleNamesPosList->fillFromArray(&topDownList[0],
- topDownListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Show player names at"), "",
- "visiblenamespos", this, "visiblenamesposEvent",
- mVisibleNamesPosList, 150);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Auto move names"), "",
- "moveNames", this, "moveNamesEvent");
-
- mBadgesList->fillFromArray(&badgesList[0], badgesListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Badges"), "",
- "showBadges", this, "showBadgesEvent", mBadgesList, 150);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Secure trades"), "",
- "securetrades", this, "securetradesEvent");
-
- // TRANSLATORS: settings option
- new SetupItemTextField(_("Unsecure chars in names"), "",
- "unsecureChars", this, "unsecureCharsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show statuses"), "",
- "showPlayersStatus", this, "showPlayersStatusEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show ip addresses on screenshots"), "",
- "showip", this, "showipEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Allow self heal with mouse click"), "",
- "selfMouseHeal", this, "selfMouseHealEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Group friends in who is online window"), "",
- "groupFriends", this, "groupFriendsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Hide erased players nicks"), "",
- "hideErased", this, "hideErasedEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Collect players id and seen log"),
- "", "enableIdCollecting", this, "enableIdCollectingEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Use special diagonal speed in players moving"),
- "", "useDiagonalSpeed", this, "useDiagonalSpeedEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Log players actions (for GM)"),
- "", "logPlayerActions", this, "logPlayerActionsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Create screenshots for each complete trades"),
- "", "tradescreenshot", this, "tradescreenshotEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Emulate right mouse button by long mouse click"
- " (useful for touch interfaces)"),
- "", "longmouseclick", this, "longmouseclickEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable remote commands"),
- "", "enableRemoteCommands", this, "enableRemoteCommandsEvent",
- "1",
- MainConfig_false);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Allow move character by mouse"),
- "", "allowMoveByMouse", this, "allowMoveByMouseEvent");
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Players::~Setup_Players()
-{
- delete2(mBadgesList);
- delete2(mVisibleNamesList);
- delete2(mVisibleNamesPosList);
-}
-
-void Setup_Players::externalUpdated()
-{
- reread("enableRemoteCommands");
-}
-
-void Setup_Players::apply()
-{
- SetupTabScroll::apply();
- settings.enableRemoteCommands = (serverConfig.getValue(
- "enableRemoteCommands", 1) != 0);
-}
diff --git a/src/gui/widgets/tabs/setup_players.h b/src/gui/widgets/tabs/setup_players.h
deleted file mode 100644
index d29d41781..000000000
--- a/src/gui/widgets/tabs/setup_players.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_PLAYERS_H
-#define GUI_WIDGETS_TABS_SETUP_PLAYERS_H
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class NamesModel;
-
-class Setup_Players final : public SetupTabScroll
-{
- public:
- explicit Setup_Players(const Widget2 *const widget);
-
- ~Setup_Players();
-
- A_DELETE_COPY(Setup_Players)
-
- void apply() override final;
-
- void externalUpdated() override final;
-
- private:
- NamesModel *mBadgesList;
- NamesModel *mVisibleNamesList;
- NamesModel *mVisibleNamesPosList;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_PLAYERS_H
diff --git a/src/gui/widgets/tabs/setup_quick.cpp b/src/gui/widgets/tabs/setup_quick.cpp
deleted file mode 100644
index f86707fe1..000000000
--- a/src/gui/widgets/tabs/setup_quick.cpp
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_quick.h"
-
-#include "gamemodifiers.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/setupquickitem.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "debug.h"
-
-Setup_Quick::Setup_Quick(const Widget2 *const widget) :
- SetupTabScroll(widget),
- mMoveTypeList(new NamesModel),
- mCrazyMoveTypeList(new NamesModel)
-{
- // TRANSLATORS: quick tab in settings
- setName(_("Quick"));
-
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
- new SetupQuickItem("", this, "moveTypeEvent",
- &GameModifiers::getMoveTypeString,
- &GameModifiers::changeMoveType);
-
- new SetupQuickItem("", this, "crazyMoveTypeEvent",
- &GameModifiers::getCrazyMoveTypeString,
- &GameModifiers::changeCrazyMoveType);
-
- new SetupQuickItem("", this, "moveToTargetTypeEvent",
- &GameModifiers::getMoveToTargetTypeString,
- &GameModifiers::changeMoveToTargetType);
-
- new SetupQuickItem("", this, "followModeEvent",
- &GameModifiers::getFollowModeString,
- &GameModifiers::changeFollowMode);
-
- new SetupQuickItem("", this, "attackWeaponTypeEvent",
- &GameModifiers::getAttackWeaponTypeString,
- &GameModifiers::changeAttackWeaponType);
-
- new SetupQuickItem("", this, "attackTypeEvent",
- &GameModifiers::getAttackTypeString,
- &GameModifiers::changeAttackType);
-
- new SetupQuickItem("", this, "magicAttackTypeEvent",
- &GameModifiers::getMagicAttackTypeString,
- &GameModifiers::changeMagicAttackType);
-
- new SetupQuickItem("", this, "pvpAttackTypeEvent",
- &GameModifiers::getPvpAttackTypeString,
- &GameModifiers::changePvpAttackType);
-
- new SetupQuickItem("", this, "quickDropCounterEvent",
- &GameModifiers::getQuickDropCounterString,
- &GameModifiers::changeQuickDropCounter);
-
- new SetupQuickItem("", this, "pickUpTypeEvent",
- &GameModifiers::getPickUpTypeString,
- &GameModifiers::changePickUpType);
-
- new SetupQuickItem("", this, "mapDrawTypeEvent",
- &GameModifiers::getMapDrawTypeString,
- &GameModifiers::changeMapDrawType);
-
- new SetupQuickItem("", this, "imitationModeEvent",
- &GameModifiers::getImitationModeString,
- &GameModifiers::changeImitationMode);
-
- new SetupQuickItem("", this, "CameraModeEvent",
- &GameModifiers::getCameraModeString,
- &GameModifiers::changeCameraMode);
-
- new SetupQuickItem("", this, "awayModeEvent",
- &GameModifiers::getAwayModeString,
- &GameModifiers::changeAwayMode);
-
- new SetupQuickItem("", this, "targetingTypeEvent",
- &GameModifiers::getTargetingTypeString,
- &GameModifiers::changeTargetingType);
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Quick::~Setup_Quick()
-{
- delete2(mMoveTypeList);
- delete2(mCrazyMoveTypeList);
-}
diff --git a/src/gui/widgets/tabs/setup_quick.h b/src/gui/widgets/tabs/setup_quick.h
deleted file mode 100644
index f174153ee..000000000
--- a/src/gui/widgets/tabs/setup_quick.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_QUICK_H
-#define GUI_WIDGETS_TABS_SETUP_QUICK_H
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class NamesModel;
-
-class Setup_Quick final : public SetupTabScroll
-{
- public:
- explicit Setup_Quick(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Quick)
-
- ~Setup_Quick();
-
- protected:
- NamesModel *mMoveTypeList;
-
- NamesModel *mCrazyMoveTypeList;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_QUICK_H
diff --git a/src/gui/widgets/tabs/setup_relations.cpp b/src/gui/widgets/tabs/setup_relations.cpp
deleted file mode 100644
index 4cc81a300..000000000
--- a/src/gui/widgets/tabs/setup_relations.cpp
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_relations.h"
-
-#include "actormanager.h"
-
-#include "being/localplayer.h"
-
-#include "gui/models/ignorechoiceslistmodel.h"
-#include "gui/models/playertablemodel.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/checkbox.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/guitable.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-static const int COLUMNS_NR = 2; // name plus listbox
-static const int NAME_COLUMN = 0;
-static const unsigned int NAME_COLUMN_WIDTH = 230;
-static const unsigned int RELATION_CHOICE_COLUMN = 1;
-static const unsigned int RELATION_CHOICE_COLUMN_WIDTH = 80;
-
-static const std::string ACTION_DELETE("delete");
-static const std::string ACTION_TABLE("table");
-static const std::string ACTION_STRATEGY("strategy");
-
-static const char *const table_titles[COLUMNS_NR] =
-{
- // TRANSLATORS: relations table header
- N_("Name"),
- // TRANSLATORS: relations table header
- N_("Relation")
-};
-
-Setup_Relations::Setup_Relations(const Widget2 *const widget) :
- SetupTab(widget),
- PlayerRelationsListener(),
- mPlayerTableTitleModel(new StaticTableModel(1, COLUMNS_NR)),
- mPlayerTableModel(new PlayerTableModel(this)),
- mPlayerTable(new GuiTable(this, mPlayerTableModel)),
- mPlayerTitleTable(new GuiTable(this, mPlayerTableTitleModel)),
- mPlayerScrollArea(new ScrollArea(this, mPlayerTable)),
- // TRANSLATORS: relation dialog button
- mDefaultTrading(new CheckBox(this, _("Allow trading"),
- (playerRelations.getDefault() & PlayerRelation::TRADE) != 0u)),
- // TRANSLATORS: relation dialog button
- mDefaultWhisper(new CheckBox(this, _("Allow whispers"),
- (playerRelations.getDefault() & PlayerRelation::WHISPER) != 0u)),
- // TRANSLATORS: relation dialog button
- mDeleteButton(new Button(this, _("Delete"), ACTION_DELETE, this)),
- mIgnoreActionChoicesModel(new IgnoreChoicesListModel),
- mIgnoreActionChoicesBox(new DropDown(widget, mIgnoreActionChoicesModel))
-{
- // TRANSLATORS: relation dialog name
- setName(_("Relations"));
-
- mPlayerTable->setOpaque(Opaque_false);
-
- mPlayerTableTitleModel->fixColumnWidth(NAME_COLUMN, NAME_COLUMN_WIDTH);
- mPlayerTableTitleModel->fixColumnWidth(RELATION_CHOICE_COLUMN,
- RELATION_CHOICE_COLUMN_WIDTH);
- mPlayerTitleTable->setBackgroundColor(getThemeColor(
- ThemeColorId::TABLE_BACKGROUND));
- mPlayerTitleTable->setSelectableGui(false);
-
- for (int i = 0; i < COLUMNS_NR; i++)
- {
- mPlayerTableTitleModel->set(0, i, new Label(
- this, gettext(table_titles[i])));
- }
-
- mPlayerTitleTable->setLinewiseSelection(true);
-
- mPlayerScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mPlayerTable->setActionEventId(ACTION_TABLE);
- mPlayerTable->setLinewiseSelection(true);
- mPlayerTable->addActionListener(this);
-
- // TRANSLATORS: relation dialog label
- Label *const ignore_action_label = new Label(this, _("When ignoring:"));
-
- mIgnoreActionChoicesBox->setActionEventId(ACTION_STRATEGY);
- mIgnoreActionChoicesBox->addActionListener(this);
-
- int ignore_strategy_index = 0; // safe default
-
- if (playerRelations.getPlayerIgnoreStrategy() != nullptr)
- {
- ignore_strategy_index = playerRelations.getPlayerIgnoreStrategyIndex(
- playerRelations.getPlayerIgnoreStrategy()->mShortName);
- if (ignore_strategy_index < 0)
- ignore_strategy_index = 0;
- }
- mIgnoreActionChoicesBox->setSelected(ignore_strategy_index);
- mIgnoreActionChoicesBox->adjustHeight();
-
- reset();
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, mPlayerTitleTable, 6);
- place(0, 1, mPlayerScrollArea, 6, 4).setPadding(2);
- place(0, 5, mDeleteButton);
- place(3, 5, ignore_action_label, 1);
- place(4, 5, mIgnoreActionChoicesBox, 2).setPadding(2);
- place(3, 6, mDefaultTrading, 3);
- place(3, 7, mDefaultWhisper, 3);
-
- playerRelations.addListener(this);
-
- setDimension(Rect(0, 0, 500, 350));
-}
-
-Setup_Relations::~Setup_Relations()
-{
- playerRelations.removeListener(this);
- delete2(mIgnoreActionChoicesModel);
-}
-
-
-void Setup_Relations::reset()
-{
- // We now have to search through the list of ignore choices to find the
- // current selection. We could use an index into the table of config
- // options in playerRelations instead of strategies to sidestep this.
- int selection = 0;
- for (size_t i = 0, sz = playerRelations.getPlayerIgnoreStrategies()
- ->size(); i < sz; ++ i)
- {
- if ((*playerRelations.getPlayerIgnoreStrategies())[i] ==
- playerRelations.getPlayerIgnoreStrategy())
- {
- selection = CAST_S32(i);
- break;
- }
- }
- mIgnoreActionChoicesBox->setSelected(selection);
-}
-
-void Setup_Relations::apply()
-{
- playerRelations.store();
-
- const unsigned int old_default_relations = playerRelations.getDefault() &
- ~(PlayerRelation::TRADE | PlayerRelation::WHISPER);
- playerRelations.setDefault(old_default_relations
- | (mDefaultTrading->isSelected() ? PlayerRelation::TRADE : 0)
- | (mDefaultWhisper->isSelected() ? PlayerRelation::WHISPER : 0));
-
- if (actorManager != nullptr)
- actorManager->updatePlayerNames();
-
- if (localPlayer != nullptr)
- localPlayer->setCheckNameSetting(true);
-}
-
-void Setup_Relations::cancel()
-{
-}
-
-void Setup_Relations::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == ACTION_TABLE)
- {
- // temporarily eliminate ourselves: we are fully aware of this change,
- // so there is no need for asynchronous updates. (In fact, thouse
- // might destroy the widet that triggered them, which would be rather
- // embarrassing.)
- playerRelations.removeListener(this);
-
- const int row = mPlayerTable->getSelectedRow();
- if (row >= 0)
- mPlayerTableModel->updateModelInRow(row);
-
- playerRelations.addListener(this);
- }
- else if (eventId == ACTION_DELETE)
- {
- const int player_index = mPlayerTable->getSelectedRow();
-
- if (player_index < 0)
- return;
-
- playerRelations.removePlayer(mPlayerTableModel->getPlayerAt(
- player_index));
- }
- else if (eventId == ACTION_STRATEGY)
- {
- const int sel = mIgnoreActionChoicesBox->getSelected();
- if (sel < 0)
- return;
- PlayerIgnoreStrategy *const s =
- (*playerRelations.getPlayerIgnoreStrategies())[sel];
-
- playerRelations.setPlayerIgnoreStrategy(s);
- }
-}
-
-void Setup_Relations::updatedPlayer(const std::string &name A_UNUSED)
-{
- mPlayerTableModel->playerRelationsUpdated();
- mDefaultTrading->setSelected(
- (playerRelations.getDefault() & PlayerRelation::TRADE) != 0u);
- mDefaultWhisper->setSelected(
- (playerRelations.getDefault() & PlayerRelation::WHISPER) != 0u);
- if (localPlayer != nullptr)
- localPlayer->updateName();
-}
-
-void Setup_Relations::updateAll()
-{
- PlayerTableModel *const model = new PlayerTableModel(this);
- mPlayerTable->setModel(model);
- delete mPlayerTableModel;
- mPlayerTableModel = model;
- int ignore_strategy_index = 0; // safe default
-
- if (playerRelations.getPlayerIgnoreStrategy() != nullptr)
- {
- ignore_strategy_index = playerRelations.getPlayerIgnoreStrategyIndex(
- playerRelations.getPlayerIgnoreStrategy()->mShortName);
- if (ignore_strategy_index < 0)
- ignore_strategy_index = 0;
- }
- mIgnoreActionChoicesBox->setSelected(ignore_strategy_index);
- mIgnoreActionChoicesBox->adjustHeight();
- reset();
-}
-void Setup_Relations::externalUpdated()
-{
- mDefaultTrading->setSelected(
- (playerRelations.getDefault() & PlayerRelation::TRADE) != 0u);
- mDefaultWhisper->setSelected(
- (playerRelations.getDefault() & PlayerRelation::WHISPER) != 0u);
-}
diff --git a/src/gui/widgets/tabs/setup_relations.h b/src/gui/widgets/tabs/setup_relations.h
deleted file mode 100644
index 879450891..000000000
--- a/src/gui/widgets/tabs/setup_relations.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_RELATIONS_H
-#define GUI_WIDGETS_TABS_SETUP_RELATIONS_H
-
-#include "gui/widgets/tabs/setuptab.h"
-
-#include "listeners/playerrelationslistener.h"
-
-class Button;
-class CheckBox;
-class DropDown;
-class GuiTable;
-class ListModel;
-class PlayerTableModel;
-class ScrollArea;
-class StaticTableModel;
-
-class Setup_Relations final : public SetupTab,
- public PlayerRelationsListener
-{
- public:
- explicit Setup_Relations(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Relations)
-
- ~Setup_Relations();
-
- void apply() override final;
-
- void cancel() override final A_CONST;
-
- void reset();
-
- void action(const ActionEvent &event) override final;
-
- void updatedPlayer(const std::string &name) override final;
-
- void updateAll() override final;
-
- void externalUpdated() override final;
-
- private:
- StaticTableModel *mPlayerTableTitleModel;
- PlayerTableModel *mPlayerTableModel;
- GuiTable *mPlayerTable;
- GuiTable *mPlayerTitleTable;
- ScrollArea *mPlayerScrollArea;
-
- CheckBox *mDefaultTrading;
- CheckBox *mDefaultWhisper;
-
- Button *mDeleteButton;
-
- ListModel *mIgnoreActionChoicesModel;
- DropDown *mIgnoreActionChoicesBox;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_RELATIONS_H
diff --git a/src/gui/widgets/tabs/setup_theme.cpp b/src/gui/widgets/tabs/setup_theme.cpp
deleted file mode 100644
index 47cbb2b92..000000000
--- a/src/gui/widgets/tabs/setup_theme.cpp
+++ /dev/null
@@ -1,415 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_theme.h"
-
-#include "gui/gui.h"
-#include "gui/themeinfo.h"
-
-#include "gui/windows/okdialog.h"
-
-#include "gui/models/fontsizechoicelistmodel.h"
-#include "gui/models/fontsmodel.h"
-#include "gui/models/langlistmodel.h"
-#include "gui/models/themesmodel.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/dropdown.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layouthelper.h"
-
-#include "configuration.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-const char* ACTION_THEME = "theme";
-const char* ACTION_FONT = "font";
-const char* ACTION_LANG = "lang";
-const char* ACTION_BOLD_FONT = "bold font";
-const char* ACTION_PARTICLE_FONT = "particle font";
-const char* ACTION_HELP_FONT = "help font";
-const char* ACTION_SECURE_FONT = "secure font";
-const char* ACTION_NPC_FONT = "npc font";
-const char* ACTION_JAPAN_FONT = "japanese font";
-const char* ACTION_CHINA_FONT = "chinese font";
-const char* ACTION_INFO = "info";
-
-Setup_Theme::Setup_Theme(const Widget2 *const widget) :
- SetupTab(widget),
- // TRANSLATORS: theme settings label
- mThemeLabel(new Label(this, _("Gui theme"))),
- mThemesModel(new ThemesModel),
- mThemeDropDown(new DropDown(this, mThemesModel)),
- mTheme(config.getStringValue("theme")),
- mInfo(Theme::loadInfo(mTheme)),
- mFontsModel(new FontsModel),
- // TRANSLATORS: theme settings label
- mFontLabel(new Label(this, _("Main Font"))),
- mFontDropDown(new DropDown(this, mFontsModel)),
- mFont(config.getStringValue("font")),
- mLangListModel(new LangListModel),
- // TRANSLATORS: theme settings label
- mLangLabel(new Label(this, _("Language"))),
- mLangDropDown(new DropDown(this, mLangListModel, true)),
- mLang(config.getStringValue("lang")),
- // TRANSLATORS: theme settings label
- mBoldFontLabel(new Label(this, _("Bold font"))),
- mBoldFontDropDown(new DropDown(this, mFontsModel)),
- mBoldFont(config.getStringValue("boldFont")),
- // TRANSLATORS: theme settings label
- mParticleFontLabel(new Label(this, _("Particle font"))),
- mParticleFontDropDown(new DropDown(this, mFontsModel)),
- mParticleFont(config.getStringValue("particleFont")),
- // TRANSLATORS: theme settings label
- mHelpFontLabel(new Label(this, _("Help font"))),
- mHelpFontDropDown(new DropDown(this, mFontsModel)),
- mHelpFont(config.getStringValue("helpFont")),
- // TRANSLATORS: theme settings label
- mSecureFontLabel(new Label(this, _("Secure font"))),
- mSecureFontDropDown(new DropDown(this, mFontsModel)),
- mSecureFont(config.getStringValue("secureFont")),
- // TRANSLATORS: theme settings label
- mNpcFontLabel(new Label(this, _("Npc font"))),
- mNpcFontDropDown(new DropDown(this, mFontsModel)),
- mNpcFont(config.getStringValue("npcFont")),
- // TRANSLATORS: theme settings label
- mJapanFontLabel(new Label(this, _("Japanese font"))),
- mJapanFontDropDown(new DropDown(this, mFontsModel)),
- mJapanFont(config.getStringValue("japanFont")),
- // TRANSLATORS: theme settings label
- mChinaFontLabel(new Label(this, _("Chinese font"))),
- mChinaFontDropDown(new DropDown(this, mFontsModel)),
- mChinaFont(config.getStringValue("chinaFont")),
- mFontSizeListModel(new FontSizeChoiceListModel),
- // TRANSLATORS: theme settings label
- mFontSizeLabel(new Label(this, _("Font size"))),
- mFontSize(config.getIntValue("fontSize")),
- mFontSizeDropDown(new DropDown(this, mFontSizeListModel)),
- mNpcFontSizeListModel(new FontSizeChoiceListModel),
- // TRANSLATORS: theme settings label
- mNpcFontSizeLabel(new Label(this, _("Npc font size"))),
- mNpcFontSize(config.getIntValue("npcfontSize")),
- mNpcFontSizeDropDown(new DropDown(this, mNpcFontSizeListModel)),
- // TRANSLATORS: button name with information about selected theme
- mInfoButton(new Button(this, _("i"), ACTION_INFO, this)),
- mThemeInfo()
-{
- // TRANSLATORS: theme settings tab name
- setName(_("Theme"));
-
- mThemeDropDown->setActionEventId(ACTION_THEME);
- mThemeDropDown->addActionListener(this);
- mFontDropDown->setActionEventId(ACTION_FONT);
- mFontDropDown->addActionListener(this);
- mLangDropDown->setActionEventId(ACTION_LANG);
- mLangDropDown->addActionListener(this);
- mBoldFontDropDown->setActionEventId(ACTION_BOLD_FONT);
- mBoldFontDropDown->addActionListener(this);
- mParticleFontDropDown->setActionEventId(ACTION_PARTICLE_FONT);
- mParticleFontDropDown->addActionListener(this);
- mHelpFontDropDown->setActionEventId(ACTION_HELP_FONT);
- mHelpFontDropDown->addActionListener(this);
- mSecureFontDropDown->setActionEventId(ACTION_SECURE_FONT);
- mSecureFontDropDown->addActionListener(this);
- mNpcFontDropDown->setActionEventId(ACTION_NPC_FONT);
- mNpcFontDropDown->addActionListener(this);
- mJapanFontDropDown->setActionEventId(ACTION_JAPAN_FONT);
- mJapanFontDropDown->addActionListener(this);
- mChinaFontDropDown->setActionEventId(ACTION_CHINA_FONT);
- mChinaFontDropDown->addActionListener(this);
- mFontSizeDropDown->setSelected(mFontSize - 9);
- mFontSizeDropDown->adjustHeight();
- mNpcFontSizeDropDown->setSelected(mNpcFontSize - 9);
- mNpcFontSizeDropDown->adjustHeight();
-
- const std::string skin = Theme::getThemeName();
- if (!skin.empty())
- mThemeDropDown->setSelectedString(skin);
- else
- mThemeDropDown->setSelected(0);
-
- const std::string str = config.getStringValue("lang");
- for (int f = 0; f < langs_count; f ++)
- {
- if (LANG_NAME[f].value == str)
- {
- mLangDropDown->setSelected(f);
- break;
- }
- }
-
- mFontDropDown->setSelectedString(getFileName(
- config.getStringValue("font")));
- mBoldFontDropDown->setSelectedString(getFileName(
- config.getStringValue("boldFont")));
- mParticleFontDropDown->setSelectedString(getFileName(
- config.getStringValue("particleFont")));
- mHelpFontDropDown->setSelectedString(getFileName(
- config.getStringValue("helpFont")));
- mSecureFontDropDown->setSelectedString(getFileName(
- config.getStringValue("secureFont")));
- mNpcFontDropDown->setSelectedString(getFileName(
- config.getStringValue("npcFont")));
- mJapanFontDropDown->setSelectedString(getFileName(
- config.getStringValue("japanFont")));
- mChinaFontDropDown->setSelectedString(getFileName(
- config.getStringValue("chinaFont")));
-
- updateInfo();
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, mThemeLabel, 5);
- place(0, 1, mLangLabel, 5);
- place(0, 2, mFontSizeLabel, 5);
- place(0, 3, mNpcFontSizeLabel, 5);
- place(0, 4, mFontLabel, 5);
- place(0, 5, mBoldFontLabel, 5);
- place(0, 6, mParticleFontLabel, 5);
- place(0, 7, mHelpFontLabel, 5);
- place(0, 8, mSecureFontLabel, 5);
- place(0, 9, mNpcFontLabel, 5);
- place(0, 10, mJapanFontLabel, 5);
- place(0, 11, mChinaFontLabel, 5);
-
- place(6, 0, mThemeDropDown, 10);
- place(6, 1, mLangDropDown, 10);
- place(6, 2, mFontSizeDropDown, 10);
- place(6, 3, mNpcFontSizeDropDown, 10);
- place(6, 4, mFontDropDown, 10);
- place(6, 5, mBoldFontDropDown, 10);
- place(6, 6, mParticleFontDropDown, 10);
- place(6, 7, mHelpFontDropDown, 10);
- place(6, 8, mSecureFontDropDown, 10);
- place(6, 9, mNpcFontDropDown, 10);
- place(6, 10, mJapanFontDropDown, 10);
- place(6, 11, mChinaFontDropDown, 10);
-
- place(17, 0, mInfoButton, 1);
-
- int size = mainGraphics->mWidth - 10;
- const int maxWidth = mFontSize * 30 + 290;
- if (size < 465)
- size = 465;
- else if (size > maxWidth)
- size = maxWidth;
-
- setDimension(Rect(0, 0, size, 500));
-}
-
-Setup_Theme::~Setup_Theme()
-{
- delete2(mInfo);
- delete2(mThemesModel);
- delete2(mFontsModel);
- delete2(mFontSizeListModel);
- delete2(mNpcFontSizeListModel);
- delete2(mLangListModel);
- delete2(mInfo);
-}
-
-void Setup_Theme::updateInfo()
-{
- delete mInfo;
- mInfo = Theme::loadInfo(mTheme);
- if (mInfo != nullptr)
- {
- // TRANSLATORS: theme name
- mThemeInfo = std::string(_("Name: ")).append(mInfo->name)
- // TRANSLATORS: theme copyright
- .append("\n").append(_("Copyright:")).append("\n")
- .append(mInfo->copyright);
- }
- else
- {
- mThemeInfo.clear();
- }
- replaceAll(mThemeInfo, "\\n", "\n");
- mInfoButton->setEnabled(!mThemeInfo.empty());
-}
-
-void Setup_Theme::action(const ActionEvent &event)
-{
- const std::string &eventId = event.getId();
- if (eventId == ACTION_THEME)
- {
- if (mThemeDropDown->getSelected() == 0)
- mTheme.clear();
- else
- mTheme = mThemeDropDown->getSelectedString();
- updateInfo();
- }
- else if (eventId == ACTION_FONT)
- {
- mFont = mFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_LANG)
- {
- const int id = mLangDropDown->getSelected();
- if (id < 0 || id >= langs_count)
- mLang.clear();
- else
- mLang = LANG_NAME[id].value;
- }
- else if (eventId == ACTION_BOLD_FONT)
- {
- mBoldFont = mBoldFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_PARTICLE_FONT)
- {
- mParticleFont = mParticleFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_HELP_FONT)
- {
- mHelpFont = mHelpFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_SECURE_FONT)
- {
- mSecureFont = mSecureFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_NPC_FONT)
- {
- mNpcFont = mNpcFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_JAPAN_FONT)
- {
- mJapanFont = mJapanFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_CHINA_FONT)
- {
- mChinaFont = mChinaFontDropDown->getSelectedString();
- }
- else if (eventId == ACTION_INFO)
- {
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: theme info dialog header
- _("Theme info"),
- mThemeInfo,
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::OK,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 600);
- }
-}
-
-void Setup_Theme::cancel()
-{
- mTheme = config.getStringValue("theme");
- mLang = config.getStringValue("lang");
- mFont = getFileName(config.getStringValue("font"));
- mBoldFont = getFileName(config.getStringValue("boldFont"));
- mParticleFont = getFileName(config.getStringValue("particleFont"));
- mHelpFont = getFileName(config.getStringValue("helpFont"));
- mSecureFont = getFileName(config.getStringValue("secureFont"));
- mNpcFont = getFileName(config.getStringValue("npcFont"));
- mJapanFont = getFileName(config.getStringValue("japanFont"));
- mChinaFont = getFileName(config.getStringValue("chinaFont"));
-}
-
-#define updateField(name1, name2) if (!mInfo->name1.empty()) \
- name2 = mInfo->name1;
-
-void Setup_Theme::apply()
-{
- if (config.getStringValue("theme") != mTheme)
- {
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: theme message dialog
- _("Theme Changed"),
- // TRANSLATORS: ok dialog message
- _("Restart your client for the change to take effect."),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::OK,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- }
-
- config.setValue("selectedSkin", "");
- if (config.getStringValue("theme") != mTheme && (mInfo != nullptr))
- {
- updateField(font, mFont);
- updateField(boldFont, mBoldFont);
- updateField(particleFont, mParticleFont);
- updateField(helpFont, mHelpFont);
- updateField(secureFont, mSecureFont);
- updateField(npcFont, mNpcFont);
- updateField(japanFont, mJapanFont);
- updateField(chinaFont, mChinaFont);
- if (mInfo->fontSize != 0)
- {
- const int size = mInfo->fontSize - 9;
- if (size >= 0)
- mFontSizeDropDown->setSelected(size);
- }
- if (mInfo->npcfontSize != 0)
- {
- const int size = mInfo->npcfontSize - 9;
- if (size >= 0)
- mNpcFontSizeDropDown->setSelected(size);
- }
- if (mInfo->guiAlpha > 0.01F)
- config.setValue("guialpha", mInfo->guiAlpha);
- }
- config.setValue("theme", mTheme);
- config.setValue("lang", mLang);
- if (config.getValue("font", "dejavusans.ttf") != mFont
- || config.getValue("boldFont", "dejavusans-bold.ttf") != mBoldFont
- || config.getValue("particleFont", "dejavusans.ttf") != mParticleFont
- || config.getValue("helpFont", "dejavusansmono.ttf") != mHelpFont
- || config.getValue("secureFont", "dejavusansmono.ttf") != mSecureFont
- || config.getValue("npcFont", "dejavusans.ttf") != mNpcFont
- || config.getValue("japanFont", "mplus-1p-regular.ttf") != mJapanFont
- || config.getValue("chinaFont", "fonts/wqy-microhei.ttf")
- != mChinaFont
- || config.getIntValue("fontSize")
- != CAST_S32(mFontSizeDropDown->getSelected()) + 9
- || config.getIntValue("npcfontSize")
- != CAST_S32(mNpcFontSizeDropDown->getSelected()) + 9)
- {
- config.setValue("font", "fonts/" + getFileName(mFont));
- config.setValue("boldFont", "fonts/" + getFileName(mBoldFont));
- config.setValue("particleFont", "fonts/" + getFileName(mParticleFont));
- config.setValue("helpFont", "fonts/" + getFileName(mHelpFont));
- config.setValue("secureFont", "fonts/" + getFileName(mSecureFont));
- config.setValue("npcFont", "fonts/" + getFileName(mNpcFont));
- config.setValue("japanFont", "fonts/" + getFileName(mJapanFont));
- config.setValue("chinaFont", "fonts/" + getFileName(mChinaFont));
- config.setValue("fontSize", mFontSizeDropDown->getSelected() + 9);
- config.setValue("npcfontSize",
- mNpcFontSizeDropDown->getSelected() + 9);
- gui->updateFonts();
- }
-}
-
-#undef updateField
diff --git a/src/gui/widgets/tabs/setup_theme.h b/src/gui/widgets/tabs/setup_theme.h
deleted file mode 100644
index 57798f243..000000000
--- a/src/gui/widgets/tabs/setup_theme.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_THEME_H
-#define GUI_WIDGETS_TABS_SETUP_THEME_H
-
-#include "gui/widgets/tabs/setuptab.h"
-
-class Button;
-class DropDown;
-class FontsModel;
-class FontSizeChoiceListModel;
-class Label;
-class LangListModel;
-class ThemesModel;
-
-class Setup_Theme final : public SetupTab
-{
- public:
- explicit Setup_Theme(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Theme)
-
- ~Setup_Theme();
-
- void apply() override final;
-
- void cancel() override final;
-
- void action(const ActionEvent &event) override final;
-
- void updateInfo();
-
- private:
- Label *mThemeLabel;
- ThemesModel *mThemesModel A_NONNULLPOINTER;
- DropDown *mThemeDropDown;
- std::string mTheme;
- ThemeInfo *mInfo;
-
- FontsModel *mFontsModel A_NONNULLPOINTER;
- Label *mFontLabel A_NONNULLPOINTER;
- DropDown *mFontDropDown A_NONNULLPOINTER;
- std::string mFont;
-
- LangListModel *mLangListModel A_NONNULLPOINTER;
-
- Label *mLangLabel A_NONNULLPOINTER;
- DropDown *mLangDropDown A_NONNULLPOINTER;
- std::string mLang;
-
- Label *mBoldFontLabel A_NONNULLPOINTER;
- DropDown *mBoldFontDropDown A_NONNULLPOINTER;
- std::string mBoldFont;
-
- Label *mParticleFontLabel A_NONNULLPOINTER;
- DropDown *mParticleFontDropDown A_NONNULLPOINTER;
- std::string mParticleFont;
-
- Label *mHelpFontLabel A_NONNULLPOINTER;
- DropDown *mHelpFontDropDown A_NONNULLPOINTER;
- std::string mHelpFont;
-
- Label *mSecureFontLabel A_NONNULLPOINTER;
- DropDown *mSecureFontDropDown A_NONNULLPOINTER;
- std::string mSecureFont;
-
- Label *mNpcFontLabel A_NONNULLPOINTER;
- DropDown *mNpcFontDropDown A_NONNULLPOINTER;
- std::string mNpcFont;
-
- Label *mJapanFontLabel A_NONNULLPOINTER;
- DropDown *mJapanFontDropDown A_NONNULLPOINTER;
- std::string mJapanFont;
-
- Label *mChinaFontLabel A_NONNULLPOINTER;
- DropDown *mChinaFontDropDown A_NONNULLPOINTER;
- std::string mChinaFont;
-
- FontSizeChoiceListModel *mFontSizeListModel A_NONNULLPOINTER;
- Label *mFontSizeLabel;
- int mFontSize;
- DropDown *mFontSizeDropDown;
-
- FontSizeChoiceListModel *mNpcFontSizeListModel A_NONNULLPOINTER;
- Label *mNpcFontSizeLabel;
- int mNpcFontSize;
- DropDown *mNpcFontSizeDropDown A_NONNULLPOINTER;
-
- Button *mInfoButton A_NONNULLPOINTER;
- std::string mThemeInfo;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_THEME_H
diff --git a/src/gui/widgets/tabs/setup_touch.cpp b/src/gui/widgets/tabs/setup_touch.cpp
deleted file mode 100644
index c8558fef9..000000000
--- a/src/gui/widgets/tabs/setup_touch.cpp
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_touch.h"
-
-#include "gui/models/touchactionmodel.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/setuptouchitem.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-static const int sizeListSize = 4;
-
-static const char *const sizeList[] =
-{
- // TRANSLATORS: onscreen button size
- N_("Small"),
- // TRANSLATORS: onscreen button size
- N_("Normal"),
- // TRANSLATORS: onscreen button size
- N_("Medium"),
- // TRANSLATORS: onscreen button size
- N_("Large")
-};
-
-static const int formatListSize = 6;
-
-static const char *const formatList[] =
-{
- "2x1",
- "2x2",
- "3x3",
- "4x2",
- "4x3",
- "3x2"
-};
-
-Setup_Touch::Setup_Touch(const Widget2 *const widget) :
- SetupTabScroll(widget),
- mSizeList(new NamesModel),
- mFormatList(new NamesModel),
- mActionsList(new TouchActionsModel)
-{
- // TRANSLATORS: touch settings tab
- setName(_("Touch"));
-
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
- mSizeList->fillFromArray(&sizeList[0], sizeListSize);
- mFormatList->fillFromArray(&formatList[0], formatListSize);
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Onscreen keyboard"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show onscreen keyboard icon"), "",
- "showScreenKeyboard", this, "showScreenKeyboardEvent");
-
- // TRANSLATORS: settings option
- new SetupActionDropDown(_("Keyboard icon action"), "",
- "screenActionKeyboard", this, "screenActionKeyboardEvent",
- mActionsList, 250);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Onscreen joystick"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show onscreen joystick"), "",
- "showScreenJoystick", this, "showScreenJoystickEvent");
-
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Joystick size"), "", "screenJoystickSize", this,
- "screenJoystickEvent", mSizeList, 100);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Onscreen buttons"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show onscreen buttons"), "",
- "showScreenButtons", this, "showScreenButtonsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Buttons format"), "", "screenButtonsFormat", this,
- "screenButtonsFormatEvent", mFormatList, 100);
-
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Buttons size"), "", "screenButtonsSize", this,
- "screenButtonsSizeEvent", mSizeList, 100);
-
- for (unsigned int f = 0; f < 12; f ++)
- {
- std::string key = strprintf("screenActionButton%u", f);
- std::string event = strprintf("screenActionButton%uEvent", f);
- // TRANSLATORS: settings option
- new SetupActionDropDown(strprintf(_("Button %u action"), f + 1), "",
- key, this, event, mActionsList, 250);
- }
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Touch::~Setup_Touch()
-{
- delete2(mSizeList);
- delete2(mFormatList);
- delete2(mActionsList);
-}
diff --git a/src/gui/widgets/tabs/setup_touch.h b/src/gui/widgets/tabs/setup_touch.h
deleted file mode 100644
index a87a46c77..000000000
--- a/src/gui/widgets/tabs/setup_touch.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_TOUCH_H
-#define GUI_WIDGETS_TABS_SETUP_TOUCH_H
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class NamesModel;
-class TouchActionsModel;
-
-class Setup_Touch final : public SetupTabScroll
-{
- public:
- explicit Setup_Touch(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Touch)
-
- ~Setup_Touch();
-
- protected:
- NamesModel *mSizeList;
- NamesModel *mFormatList;
- TouchActionsModel *mActionsList;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_TOUCH_H
diff --git a/src/gui/widgets/tabs/setup_video.cpp b/src/gui/widgets/tabs/setup_video.cpp
deleted file mode 100644
index b5b74e2b9..000000000
--- a/src/gui/widgets/tabs/setup_video.cpp
+++ /dev/null
@@ -1,534 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_video.h"
-
-#include "gui/windowmanager.h"
-
-#include "gui/windows/okdialog.h"
-#include "gui/windows/textdialog.h"
-
-#include "gui/widgets/button.h"
-#include "gui/widgets/checkbox.h"
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/label.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/listbox.h"
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/slider.h"
-#include "gui/widgets/dropdown.h"
-
-#include "utils/delete2.h"
-
-#if defined(USE_OPENGL) && !defined(ANDROID) && !defined(__APPLE__)
-#include "graphicsmanager.h"
-
-#include "test/testmain.h"
-#endif // defined(USE_OPENGL) && !defined(ANDROID) && !defined(__APPLE__)
-
-#if defined(ANDROID) || defined(__APPLE__) || !defined(USE_OPENGL)
-#include "configuration.h"
-#endif // defined(ANDROID) || defined(__APPLE__) || !defined(USE_OPENGL)
-
-#if defined(ANDROID) || defined(__APPLE__)
-#include "utils/stringutils.h"
-#endif // defined(ANDROID) || defined(__APPLE__)
-
-#include "gui/models/modelistmodel.h"
-#include "gui/models/opengllistmodel.h"
-
-#include <sstream>
-
-#include "debug.h"
-
-Setup_Video::Setup_Video(const Widget2 *const widget) :
- SetupTab(widget),
- KeyListener(),
- mFullScreenEnabled(config.getBoolValue("screen")),
- mOpenGLEnabled(intToRenderType(config.getIntValue("opengl"))),
- mFps(config.getIntValue("fpslimit")),
- mAltFps(config.getIntValue("altfpslimit")),
- mModeListModel(new ModeListModel),
- mOpenGLListModel(new OpenGLListModel),
- mModeList(CREATEWIDGETR(ListBox, widget, mModeListModel, "")),
- // TRANSLATORS: video settings checkbox
- mFsCheckBox(new CheckBox(this, _("Full screen"), mFullScreenEnabled)),
- mOpenGLDropDown(new DropDown(widget, mOpenGLListModel)),
- // TRANSLATORS: video settings checkbox
- mFpsCheckBox(new CheckBox(this, _("FPS limit:"))),
- mFpsSlider(new Slider(this, 2.0, 160.0, 1.0)),
- mFpsLabel(new Label(this)),
- mAltFpsSlider(new Slider(this, 2.0, 160.0, 1.0)),
- // TRANSLATORS: video settings label
- mAltFpsLabel(new Label(this, _("Alt FPS limit: "))),
-#if !defined(ANDROID) && !defined(__APPLE__) && !defined(__native_client__)
- // TRANSLATORS: video settings button
- mDetectButton(new Button(this, _("Detect best mode"), "detect", this)),
-#endif // !defined(ANDROID) && !defined(__APPLE__) &&
- // !defined(__native_client__)
- mDialog(nullptr),
- mCustomCursorEnabled(config.getBoolValue("customcursor")),
- mEnableResize(config.getBoolValue("enableresize")),
- mNoFrame(config.getBoolValue("noframe")),
-#ifdef USE_SDL2
- mAllowHighDPI(config.getBoolValue("allowHighDPI")),
- // TRANSLATORS: video settings checkbox
- mAllowHighDPICheckBox(new CheckBox(this, _("High DPI"), mAllowHighDPI)),
-#endif // USE_SDL2
- mCustomCursorCheckBox(new CheckBox(this,
-#ifdef ANDROID
- // TRANSLATORS: video settings checkbox
- _("Show cursor"),
-#else // ANDROID
- // TRANSLATORS: video settings checkbox
- _("Custom cursor"),
-#endif // ANDROID
- mCustomCursorEnabled)),
- // TRANSLATORS: video settings checkbox
- mEnableResizeCheckBox(new CheckBox(this, _("Enable resize"),
- mEnableResize)),
- // TRANSLATORS: video settings checkbox
- mNoFrameCheckBox(new CheckBox(this, _("No frame"), mNoFrame))
-{
- // TRANSLATORS: video settings tab name
- setName(_("Video"));
-
- ScrollArea *const scrollArea = new ScrollArea(this, mModeList,
- Opaque_true, "setup_video_background.xml");
- scrollArea->setWidth(150);
- scrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
-
- mOpenGLDropDown->setSelected(renderToIndex[mOpenGLEnabled]);
-
- mModeList->setEnabled(true);
-
- // TRANSLATORS: video settings label
- mFpsLabel->setCaption(mFps > 0 ? toString(mFps) : _("None"));
- mFpsLabel->setWidth(60);
- // TRANSLATORS: video settings label
- mAltFpsLabel->setCaption(_("Alt FPS limit: ") + (mAltFps > 0 ?
- // TRANSLATORS: video settings label value
- toString(mAltFps) : _("None")));
- mAltFpsLabel->setWidth(150);
- mFpsSlider->setEnabled(mFps > 0);
- mFpsSlider->setValue(mFps);
- mAltFpsSlider->setEnabled(mAltFps > 0);
- mAltFpsSlider->setValue(mAltFps);
- mFpsCheckBox->setSelected(mFps > 0);
-
- // Pre-select the current video mode.
- const std::string videoMode = toString(
- mainGraphics->mActualWidth).append("x").append(
- toString(mainGraphics->mActualHeight));
- mModeList->setSelected(mModeListModel->getIndexOf(videoMode));
-
- mModeList->setActionEventId("videomode");
- mCustomCursorCheckBox->setActionEventId("customcursor");
- mFpsCheckBox->setActionEventId("fpslimitcheckbox");
- mFpsSlider->setActionEventId("fpslimitslider");
- mAltFpsSlider->setActionEventId("altfpslimitslider");
- mOpenGLDropDown->setActionEventId("opengl");
- mEnableResizeCheckBox->setActionEventId("enableresize");
- mNoFrameCheckBox->setActionEventId("noframe");
-#ifdef USE_SDL2
- mAllowHighDPICheckBox->setActionEventId("allowHighDPI");
- mAllowHighDPICheckBox->addActionListener(this);
-#endif // USE_SDL2
-
- mModeList->addActionListener(this);
- mCustomCursorCheckBox->addActionListener(this);
- mFpsCheckBox->addActionListener(this);
- mFpsSlider->addActionListener(this);
- mAltFpsSlider->addActionListener(this);
- mOpenGLDropDown->addActionListener(this);
- mEnableResizeCheckBox->addActionListener(this);
- mNoFrameCheckBox->addActionListener(this);
-
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
-
- place(0, 0, scrollArea, 1, 5).setPadding(2);
- place(0, 5, mOpenGLDropDown, 1);
-
- place(1, 0, mFsCheckBox, 2);
-
- place(1, 1, mCustomCursorCheckBox, 3);
-
- place(1, 2, mEnableResizeCheckBox, 2);
- place(1, 3, mNoFrameCheckBox, 2);
-#ifdef USE_SDL2
- place(1, 4, mAllowHighDPICheckBox, 2);
-#endif // USE_SDL2
-
- place(0, 6, mFpsSlider);
- place(1, 6, mFpsCheckBox).setPadding(3);
- place(2, 6, mFpsLabel).setPadding(1);
-
- place(0, 7, mAltFpsSlider);
- place(1, 7, mAltFpsLabel).setPadding(3);
-
-#if !defined(ANDROID) && !defined(__APPLE__) && !defined(__native_client__)
- place(0, 8, mDetectButton);
-#else // !defined(ANDROID) && !defined(__APPLE__) &&
- // !defined(__native_client__)
- mNoFrameCheckBox->setEnabled(false);
- mEnableResizeCheckBox->setEnabled(false);
-#ifndef __native_client__
- mFsCheckBox->setEnabled(false);
-#endif // __native_client__
-#endif // !defined(ANDROID) && !defined(__APPLE__) &&
- // !defined(__native_client__)
-
- int width = 600;
-
- if (config.getIntValue("screenwidth") >= 730)
- width += 100;
-
- setDimension(Rect(0, 0, width, 300));
-}
-
-Setup_Video::~Setup_Video()
-{
- delete2(mModeListModel);
- delete2(mModeList);
- delete2(mOpenGLListModel);
- delete2(mDialog);
-}
-
-void Setup_Video::apply()
-{
- // Full screen changes
- bool fullscreen = mFsCheckBox->isSelected();
- if (fullscreen != config.getBoolValue("screen"))
- {
- /* The OpenGL test is only necessary on Windows, since switching
- * to/from full screen works fine on Linux. On Windows we'd have to
- * reinitialize the OpenGL state and reload all textures.
- *
- * See http://libsdl.org/cgi/docwiki.cgi/SDL_SetVideoMode
- */
-
-#if defined(WIN32) || defined(__APPLE__) || defined(ANDROID)
- // checks for opengl usage
- if (intToRenderType(config.getIntValue("opengl")) == RENDER_SOFTWARE)
- {
-#endif // defined(WIN32) || defined(__APPLE__) || defined(ANDROID)
- if (!WindowManager::setFullScreen(fullscreen))
- {
- fullscreen = !fullscreen;
- if (!WindowManager::setFullScreen(fullscreen))
- {
- std::stringstream errorMsg;
- if (fullscreen)
- {
- // TRANSLATORS: video error message
- errorMsg << _("Failed to switch to windowed mode "
- "and restoration of old mode also "
- "failed!") << std::endl;
- }
- else
- {
- // TRANSLATORS: video error message
- errorMsg << _("Failed to switch to fullscreen mode"
- " and restoration of old mode also "
- "failed!") << std::endl;
- }
- logger->safeError(errorMsg.str());
- }
- }
-#if defined(WIN32) || defined(__APPLE__) || defined(ANDROID)
- }
- else
- {
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: video settings warning
- _("Switching to Full Screen"),
- // TRANSLATORS: video settings warning
- _("Restart needed for changes to take effect."),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::OK,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- }
-#endif // defined(WIN32) || defined(__APPLE__) || defined(ANDROID)
-
- config.setValue("screen", fullscreen);
- }
-
- const int sel = mOpenGLDropDown->getSelected();
- RenderType mode = RENDER_SOFTWARE;
- if (sel >= 0 && CAST_U32(sel) < sizeof(indexToRender))
- mode = indexToRender[mOpenGLDropDown->getSelected()];
-
- // OpenGL change
- if (mode != mOpenGLEnabled)
- {
- config.setValue("opengl", CAST_S32(mode));
-
- // OpenGL can currently only be changed by restarting, notify user.
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: video settings warning
- _("Changing to OpenGL"),
- // TRANSLATORS: video settings warning
- _("Applying change to OpenGL requires restart."),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::OK,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- }
-
- mFps = mFpsCheckBox->isSelected() ?
- CAST_S32(mFpsSlider->getValue()) : 0;
-
- mAltFps = CAST_S32(mAltFpsSlider->getValue());
-
- mFpsSlider->setEnabled(mFps > 0);
-
- mAltFpsSlider->setEnabled(mAltFps > 0);
-
- // FPS change
- config.setValue("fpslimit", mFps);
- config.setValue("altfpslimit", mAltFps);
-
- // We sync old and new values at apply time
- mFullScreenEnabled = config.getBoolValue("screen");
- mCustomCursorEnabled = config.getBoolValue("customcursor");
-
- mOpenGLEnabled = intToRenderType(config.getIntValue("opengl"));
- mEnableResize = config.getBoolValue("enableresize");
- mNoFrame = config.getBoolValue("noframe");
-#ifdef USE_SDL2
- mAllowHighDPI = config.getBoolValue("allowHighDPI");
-#endif // USE_SDL2
-}
-
-void Setup_Video::cancel()
-{
- mFpsCheckBox->setSelected(mFps > 0);
- mFsCheckBox->setSelected(mFullScreenEnabled);
- mOpenGLDropDown->setSelected(renderToIndex[mOpenGLEnabled]);
- mCustomCursorCheckBox->setSelected(mCustomCursorEnabled);
- mFpsSlider->setEnabled(mFps > 0);
- mFpsSlider->setValue(mFps);
- mAltFpsSlider->setEnabled(mAltFps > 0);
- mAltFpsSlider->setValue(mAltFps);
- mFpsLabel->setCaption(mFpsCheckBox->isSelected()
- // TRANSLATORS: video settings label
- ? toString(mFps) : _("None"));
- // TRANSLATORS: video settings label
- mAltFpsLabel->setCaption(_("Alt FPS limit: ") + toString(mAltFps));
- mEnableResizeCheckBox->setSelected(mEnableResize);
- mNoFrameCheckBox->setSelected(mNoFrame);
-#ifdef USE_SDL2
- mAllowHighDPICheckBox->setSelected(mAllowHighDPI);
-#endif // USE_SDL2
-
- config.setValue("screen", mFullScreenEnabled);
-
- // Set back to the current video mode.
- std::string videoMode = toString(mainGraphics->mActualWidth).append("x")
- .append(toString(mainGraphics->mActualHeight));
- mModeList->setSelected(mModeListModel->getIndexOf(videoMode));
- config.setValue("screenwidth", mainGraphics->mActualWidth);
- config.setValue("screenheight", mainGraphics->mActualHeight);
-
- config.setValue("customcursor", mCustomCursorEnabled);
- config.setValue("opengl", CAST_S32(mOpenGLEnabled));
- config.setValue("enableresize", mEnableResize);
-#ifdef USE_SDL2
- config.setValue("allowHighDPI", mAllowHighDPI);
-#endif // USE_SDL2
-}
-
-void Setup_Video::action(const ActionEvent &event)
-{
- const std::string &id = event.getId();
-
- if (id == "videomode")
- {
- std::string mode = mModeListModel->getElementAt(
- mModeList->getSelected());
-
- if (mode == "custom")
- {
- if (mDialog != nullptr)
- {
- mode = mDialog->getText();
- mDialog = nullptr;
- }
- else
- {
- CREATEWIDGETV(mDialog, TextDialog,
- // TRANSLATORS: resolution question dialog
- _("Custom resolution (example: 1024x768)"),
- // TRANSLATORS: resolution question dialog
- _("Enter new resolution: "));
- mDialog->setActionEventId("videomode");
- mDialog->addActionListener(this);
- return;
- }
- }
- const int width = atoi(mode.substr(0, mode.find('x')).c_str());
- const int height = atoi(mode.substr(mode.find('x') + 1).c_str());
- if ((width == 0) || (height == 0))
- return;
-
- if (width != mainGraphics->mActualWidth
- || height != mainGraphics->mActualHeight)
- {
-#if defined(WIN32) || defined(__APPLE__) || defined(ANDROID)
- if (intToRenderType(config.getIntValue("opengl"))
- == RENDER_SOFTWARE)
- {
- WindowManager::doResizeVideo(width, height, false);
- }
- else
- {
- if (width < mainGraphics->mActualWidth
- || height < mainGraphics->mActualHeight)
- {
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: video settings warning
- _("Screen Resolution Changed"),
- // TRANSLATORS: video settings warning
- _("Restart your client for the change to take effect.")
- // TRANSLATORS: video settings warning
- + std::string("\n") + _("Some windows may be moved to "
- "fit the lowered resolution."),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::OK,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- }
- else
- {
- CREATEWIDGET(OkDialog,
- // TRANSLATORS: video settings warning
- _("Screen Resolution Changed"),
- // TRANSLATORS: video settings warning
- _("Restart your client for the change"
- " to take effect."),
- // TRANSLATORS: ok dialog button
- _("OK"),
- DialogType::OK,
- Modal_true,
- ShowCenter_true,
- nullptr,
- 260);
- }
- }
-#else // defined(WIN32) || defined(__APPLE__) || defined(ANDROID)
-
- mainGraphics->setWindowSize(width, height);
- WindowManager::doResizeVideo(width, height, false);
-#endif // defined(WIN32) || defined(__APPLE__) || defined(ANDROID)
- }
-
- config.setValue("oldscreen", config.getBoolValue("screen"));
- config.setValue("oldscreenwidth", mainGraphics->mActualWidth);
- config.setValue("oldscreenheight", mainGraphics->mActualHeight);
- config.setValue("screenwidth", width);
- config.setValue("screenheight", height);
- }
- if (id == "~videomode")
- {
- mDialog = nullptr;
- }
- else if (id == "customcursor")
- {
- config.setValue("customcursor", mCustomCursorCheckBox->isSelected());
- }
- else if (id == "fpslimitcheckbox" || id == "fpslimitslider")
- {
- int tempFps = CAST_S32(mFpsSlider->getValue());
- if (id == "fpslimitcheckbox" && !mFpsSlider->isEnabled())
- tempFps = 60;
- else
- tempFps = tempFps > 0 ? tempFps : 60;
- mFps = mFpsCheckBox->isSelected() ? tempFps : 0;
- // TRANSLATORS: video settings label
- const std::string text = mFps > 0 ? toString(mFps) : _("None");
-
- mFpsLabel->setCaption(text);
- mFpsSlider->setEnabled(mFps > 0);
- mFpsSlider->setValue(mFps);
- }
- else if (id == "altfpslimitslider")
- {
- int tempFps = CAST_S32(mAltFpsSlider->getValue());
- tempFps = tempFps > 0 ? tempFps : CAST_S32(
- mAltFpsSlider->getScaleStart());
- mAltFps = tempFps;
- // TRANSLATORS: video settings label
- const std::string text = mAltFps > 0 ? toString(mAltFps) : _("None");
-
- // TRANSLATORS: video settings label
- mAltFpsLabel->setCaption(_("Alt FPS limit: ") + text);
- mAltFpsSlider->setEnabled(mAltFps > 0);
- mAltFpsSlider->setValue(mAltFps);
- }
- else if (id == "enableresize")
- {
- config.setValue("enableresize", mEnableResizeCheckBox->isSelected());
- }
- else if (id == "noframe")
- {
- config.setValue("noframe", mNoFrameCheckBox->isSelected());
- }
-#ifdef USE_SDL2
- else if (id == "allowHighDPI")
- {
- config.setValue("allowHighDPI", mAllowHighDPICheckBox->isSelected());
- }
-#endif // USE_SDL2
-#if defined(USE_OPENGL) && !defined(ANDROID) && !defined(__APPLE__)
- else if (id == "detect")
- {
- TestMain *test = graphicsManager.startDetection();
- if (test != nullptr)
- {
- Configuration &conf = test->getConfig();
- const int val = conf.getValueInt("opengl", -1);
- if (val >= 0 && CAST_U32(val)
- < sizeof(renderToIndex) / sizeof(int))
- {
- mOpenGLDropDown->setSelected(renderToIndex[val]);
- }
- config.setValue("textureSize",
- conf.getValue("textureSize", "1024,1024,1024,1024,1024,1024"));
- config.setValue("testInfo", conf.getValue("testInfo", ""));
- delete test;
- }
- }
-#endif // defined(USE_OPENGL) && !defined(ANDROID) && !defined(__APPLE__)
-}
diff --git a/src/gui/widgets/tabs/setup_video.h b/src/gui/widgets/tabs/setup_video.h
deleted file mode 100644
index e327a29d8..000000000
--- a/src/gui/widgets/tabs/setup_video.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_VIDEO_H
-#define GUI_WIDGETS_TABS_SETUP_VIDEO_H
-
-#include "gui/widgets/tabs/setuptab.h"
-
-#include "listeners/keylistener.h"
-
-class Button;
-class CheckBox;
-class DropDown;
-class Label;
-class ListBox;
-class ModeListModel;
-class OpenGLListModel;
-class Slider;
-class TextDialog;
-
-class Setup_Video final : public SetupTab,
- public KeyListener
-{
- public:
- explicit Setup_Video(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Video)
-
- ~Setup_Video();
-
- void apply() override final;
-
- void cancel() override final;
-
- void action(const ActionEvent &event) override final;
-
- private:
- bool mFullScreenEnabled;
- RenderType mOpenGLEnabled;
- int mFps;
- int mAltFps;
- ModeListModel *mModeListModel;
- OpenGLListModel *mOpenGLListModel;
- ListBox *mModeList;
- CheckBox *mFsCheckBox;
- DropDown *mOpenGLDropDown;
- CheckBox *mFpsCheckBox;
- Slider *mFpsSlider;
- Label *mFpsLabel;
- Slider *mAltFpsSlider;
- Label *mAltFpsLabel;
-#if !defined(ANDROID) && !defined(__APPLE__) && !defined(__native_client__)
- Button *mDetectButton;
-#endif // !defined(ANDROID) && !defined(__APPLE__) &&
- // !defined(__native_client__)
- TextDialog *mDialog;
- bool mCustomCursorEnabled;
- bool mEnableResize;
- bool mNoFrame;
-#ifdef USE_SDL2
- bool mAllowHighDPI;
- CheckBox *mAllowHighDPICheckBox;
-#endif // USE_SDL2
- CheckBox *mCustomCursorCheckBox;
- CheckBox *mEnableResizeCheckBox;
- CheckBox *mNoFrameCheckBox;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_VIDEO_H
diff --git a/src/gui/widgets/tabs/setup_visual.cpp b/src/gui/widgets/tabs/setup_visual.cpp
deleted file mode 100644
index de5cc8b3b..000000000
--- a/src/gui/widgets/tabs/setup_visual.cpp
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setup_visual.h"
-
-#include "gui/windowmanager.h"
-
-#include "gui/models/namesmodel.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-static const int speachListSize = 4;
-
-static const char *const speachList[] =
-{
- // TRANSLATORS: speach type
- N_("No text"),
- // TRANSLATORS: speach type
- N_("Text"),
- // TRANSLATORS: speach type
- N_("Bubbles, no names"),
- // TRANSLATORS: speach type
- N_("Bubbles with names")
-};
-
-static const int ambientFxListSize = 3;
-
-static const char *const ambientFxList[] =
-{
- // TRANSLATORS: ambient effect type
- N_("off"),
- // TRANSLATORS: ambient effect type
- N_("low"),
- // TRANSLATORS: ambient effect type
- N_("high")
-};
-
-static const int particleTypeListSize = 3;
-
-static const char *const particleTypeList[] =
-{
- // TRANSLATORS: patricle effects type
- N_("best quality"),
- // TRANSLATORS: patricle effects type
- N_("normal"),
- // TRANSLATORS: patricle effects type
- N_("best performance")
-};
-
-static const int vSyncListSize = 3;
-
-static const char *const vSyncList[] =
-{
- // TRANSLATORS: vsync type
- N_("default"),
- // TRANSLATORS: vsync type
- N_("off"),
- // TRANSLATORS: vsync type
- N_("on")
-};
-
-Setup_Visual::Setup_Visual(const Widget2 *const widget) :
- SetupTabScroll(widget),
- mSpeachList(new NamesModel),
- mAmbientFxList(new NamesModel),
- mParticleList(new SetupItemNames),
- mParticleTypeList(new NamesModel),
- mVSyncList(new NamesModel),
- mScaleList(new NamesModel)
-{
- // TRANSLATORS: settings tab name
- setName(_("Visual"));
- // Do the layout
- LayoutHelper h(this);
- ContainerPlacer place = h.getPlacer(0, 0);
- place(0, 0, mScroll, 10, 10);
-
- mPreferredFirstItemSize = 150;
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Scale"), "", this);
-
- for (int f = 1; f <= 7; f ++)
- {
- // TRANSLATORS: particle details
- mScaleList->add(toString(f) + "x");
- }
- // TRANSLATORS: settings option
- new SetupItemSliderInt(_("Scale"), "",
- "scale", this, "scaleEvent", mScaleList, 1);
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Notifications"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show pickup notifications in chat"), "",
- "showpickupchat", this, "showpickupchatEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show pickup notifications as particle effects"),
- "", "showpickupparticle", this, "showpickupparticleEvent");
-
- // TRANSLATORS: settings option
- new SetupItemLabel(_("Effects"), "", this);
-
-#ifndef ANDROID
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Grab mouse and keyboard input"),
- "", "grabinput", this, "grabinputEvent");
-#endif // ANDROID
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Blurring textures (OpenGL)"),
- "", "blur", this, "blurEvent");
-
- // TRANSLATORS: settings option
- new SetupItemSlider(_("Gui opacity"), "", "guialpha",
- this, "guialphaEvent", 0.1, 1.01, 0.1, 150,
- OnTheFly_true,
- MainConfig_true);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable gui opacity"),
- "", "enableGuiOpacity", this, "enableGuiOpacityEvent");
-
- mSpeachList->fillFromArray(&speachList[0], speachListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Overhead text"), "", "speech", this,
- "speechEvent", mSpeachList, 200);
-
- mAmbientFxList->fillFromArray(&ambientFxList[0], ambientFxListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Ambient FX"), "", "OverlayDetail", this,
- "OverlayDetailEvent", mAmbientFxList, 100);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show particle effects"), "",
- "particleeffects", this, "particleeffectsEvent");
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Show particle effects from maps"), "",
- "mapparticleeffects", this, "mapparticleeffectsEvent");
-
- // TRANSLATORS: particle details
- mParticleList->push_back(_("low"));
- // TRANSLATORS: particle details
- mParticleList->push_back(_("medium"));
- // TRANSLATORS: particle details
- mParticleList->push_back(_("high"));
- // TRANSLATORS: particle details
- mParticleList->push_back(_("max"));
- // TRANSLATORS: settings option
- (new SetupItemSlider2(_("Particle detail"), "", "particleEmitterSkip",
- this, "particleEmitterSkipEvent", 0, 3, 1, mParticleList,
- OnTheFly_true,
- MainConfig_true,
- DoNotAlign_false))->setInvertValue(3);
-
- mParticleTypeList->fillFromArray(&particleTypeList[0],
- particleTypeListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Particle physics"), "", "particleFastPhysics",
- this, "particleFastPhysicsEvent", mParticleTypeList, 200);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Gamma"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Enable gamma control"),
- "", "enableGamma", this, "enableGammaEvent");
-
- // TRANSLATORS: settings option
- new SetupItemSlider(_("Gamma"), "", "gamma",
- this, "gammeEvent", 1, 20, 1, 350,
- OnTheFly_true,
- MainConfig_true);
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Other"), "", this);
-
- mVSyncList->fillFromArray(&vSyncList[0], vSyncListSize);
- // TRANSLATORS: settings option
- new SetupItemDropDown(_("Vsync"), "", "vsync", this,
- "vsyncEvent", mVSyncList, 100);
-
-#if defined(WIN32) || defined(__APPLE__)
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Center game window"),
- "", "centerwindow", this, "centerwindowEvent");
-#endif // defined(WIN32) || defined(__APPLE__)
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Allow screensaver to run"),
- "", "allowscreensaver", this, "allowscreensaverEvent");
-
-
- // TRANSLATORS: settings group
- new SetupItemLabel(_("Screenshots"), "", this);
-
- // TRANSLATORS: settings option
- new SetupItemCheckBox(_("Add water mark into screenshots"),
- "", "addwatermark", this, "addwatermarkEvent");
-
- setDimension(Rect(0, 0, 550, 350));
-}
-
-Setup_Visual::~Setup_Visual()
-{
- delete2(mSpeachList);
- delete2(mAmbientFxList);
- delete2(mParticleList);
- delete2(mParticleTypeList);
- delete2(mVSyncList);
- delete2(mScaleList);
-}
-
-void Setup_Visual::apply()
-{
- SetupTabScroll::apply();
- WindowManager::applyGrabMode();
-#ifndef WIN32
- WindowManager::applyScale();
-#endif // WIN32
-}
diff --git a/src/gui/widgets/tabs/setup_visual.h b/src/gui/widgets/tabs/setup_visual.h
deleted file mode 100644
index 08d1c7848..000000000
--- a/src/gui/widgets/tabs/setup_visual.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUP_VISUAL_H
-#define GUI_WIDGETS_TABS_SETUP_VISUAL_H
-
-#include "gui/widgets/setupitem.h"
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-class NamesModel;
-
-class Setup_Visual final : public SetupTabScroll
-{
- public:
- explicit Setup_Visual(const Widget2 *const widget);
-
- A_DELETE_COPY(Setup_Visual)
-
- ~Setup_Visual();
-
- void apply() override final;
-
- private:
- NamesModel *mSpeachList;
- NamesModel *mAmbientFxList;
- SetupItemNames *mParticleList;
- NamesModel *mParticleTypeList;
- NamesModel *mVSyncList;
- NamesModel *mScaleList;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUP_VISUAL_H
diff --git a/src/gui/widgets/tabs/setuptab.cpp b/src/gui/widgets/tabs/setuptab.cpp
deleted file mode 100644
index d5f43b4b8..000000000
--- a/src/gui/widgets/tabs/setuptab.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setuptab.h"
-
-#include "debug.h"
-
-SetupTab::SetupTab(const Widget2 *const widget) :
- Container(widget),
- ActionListener(),
- WidgetListener(),
- mName()
-{
- setOpaque(Opaque_false);
- addWidgetListener(this);
- setSelectable(false);
-}
-
-void SetupTab::externalUpdated()
-{
-}
-
-void SetupTab::externalUnloaded()
-{
-}
diff --git a/src/gui/widgets/tabs/setuptab.h b/src/gui/widgets/tabs/setuptab.h
deleted file mode 100644
index 6b1082088..000000000
--- a/src/gui/widgets/tabs/setuptab.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUPTAB_H
-#define GUI_WIDGETS_TABS_SETUPTAB_H
-
-#include "gui/widgets/container.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-/**
- * A container for the contents of a tab in the setup window.
- */
-class SetupTab notfinal : public Container,
- public ActionListener,
- public WidgetListener
-{
- public:
- A_DELETE_COPY(SetupTab)
-
- const std::string &getName() const noexcept2 A_WARN_UNUSED
- { return mName; }
-
- /**
- * Called when the Apply button is pressed in the setup window.
- */
- virtual void apply() = 0;
-
- /**
- * Called when the Cancel button is pressed in the setup window.
- */
- virtual void cancel() = 0;
-
- virtual void externalUpdated() A_CONST;
-
- virtual void externalUnloaded() A_CONST;
-
- protected:
- explicit SetupTab(const Widget2 *const widget);
-
- /**
- * Sets the name displayed on the tab. Should be set in the
- * constructor of a subclass.
- */
- void setName(const std::string &name) noexcept2
- { mName = name; }
-
- private:
- std::string mName;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUPTAB_H
diff --git a/src/gui/widgets/tabs/setuptabscroll.cpp b/src/gui/widgets/tabs/setuptabscroll.cpp
deleted file mode 100644
index 0cb623687..000000000
--- a/src/gui/widgets/tabs/setuptabscroll.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabs/setuptabscroll.h"
-
-#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/setupitem.h"
-#include "gui/widgets/vertcontainer.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-SetupTabScroll::SetupTabScroll(const Widget2 *const widget) :
- SetupTab(widget),
- mContainer(new VertContainer(this, 25, false, 8)),
- mScroll(new ScrollArea(this, mContainer, Opaque_false)),
- mItems(),
- mAllItems(),
- mPreferredFirstItemSize(200)
-{
- mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
- mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
- mScroll->setSelectable(false);
- mContainer->setSelectable(false);
-}
-
-SetupTabScroll::~SetupTabScroll()
-{
- mScroll = nullptr;
- delete2(mContainer);
- removeItems();
-}
-
-void SetupTabScroll::removeItems()
-{
- std::set<SetupItem*>::iterator it = mAllItems.begin();
- const std::set<SetupItem*>::iterator it_end = mAllItems.end();
- while (it != it_end)
- {
- delete *it;
- ++ it;
- }
- mAllItems.clear();
-
- mItems.clear();
-}
-
-void SetupTabScroll::clear()
-{
- removeItems();
- mContainer->removeControls();
- mContainer->clear();
-}
-
-void SetupTabScroll::addControl(SetupItem *const widget)
-{
- if (widget == nullptr)
- return;
- const std::string actionId = widget->getActionEventId();
- if (!actionId.empty())
- {
- const std::map<std::string, SetupItem*>::iterator iter
- = mItems.find(actionId);
- if (iter != mItems.end())
- {
- delete (*iter).second;
- mItems.erase(iter);
- }
- mItems[actionId] = widget;
- }
- mAllItems.insert(widget);
-}
-
-void SetupTabScroll::addControl(SetupItem *const widget,
- const std::string &event)
-{
- const std::map<std::string, SetupItem*>::iterator iter
- = mItems.find(event);
- if (iter != mItems.end())
- {
- delete (*iter).second;
- mItems.erase(iter);
- }
- mItems[event] = widget;
- mAllItems.insert(widget);
-}
-
-void SetupTabScroll::apply()
-{
- for (std::map<std::string, SetupItem*>::const_iterator
- iter = mItems.begin(), iter_end = mItems.end();
- iter != iter_end; ++ iter)
- {
- if ((*iter).second != nullptr)
- (*iter).second->apply((*iter).first);
- }
-}
-
-void SetupTabScroll::cancel()
-{
- for (std::map<std::string, SetupItem*>::const_iterator
- iter = mItems.begin(), iter_end = mItems.end();
- iter != iter_end; ++ iter)
- {
- if ((*iter).second != nullptr)
- (*iter).second->cancel((*iter).first);
- }
-}
-
-void SetupTabScroll::externalUpdated()
-{
- for (std::map<std::string, SetupItem*>::const_iterator
- iter = mItems.begin(), iter_end = mItems.end();
- iter != iter_end; ++ iter)
- {
- SetupItem *const widget = (*iter).second;
- if ((widget != nullptr) && widget->isMainConfig() == MainConfig_false)
- widget->externalUpdated((*iter).first);
- }
-}
-
-void SetupTabScroll::externalUnloaded()
-{
- for (std::map<std::string, SetupItem*>::const_iterator
- iter = mItems.begin(), iter_end = mItems.end();
- iter != iter_end; ++ iter)
- {
- SetupItem *const widget = (*iter).second;
- if ((widget != nullptr) && widget->isMainConfig() == MainConfig_false)
- widget->externalUnloaded((*iter).first);
- }
-}
-
-void SetupTabScroll::widgetResized(const Event &event A_UNUSED)
-{
- mScroll->setWidth(getWidth() - 12);
- mScroll->setHeight(getHeight() - 12 - 12);
-}
-
-void SetupTabScroll::reread(const std::string &name)
-{
- SetupItem *const item = mItems[name + "Event"];
- if (item != nullptr)
- item->rereadValue();
-}
diff --git a/src/gui/widgets/tabs/setuptabscroll.h b/src/gui/widgets/tabs/setuptabscroll.h
deleted file mode 100644
index 655b98c85..000000000
--- a/src/gui/widgets/tabs/setuptabscroll.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SETUPTABSCROLL_H
-#define GUI_WIDGETS_TABS_SETUPTABSCROLL_H
-
-#include "gui/widgets/tabs/setuptab.h"
-
-#include "localconsts.h"
-
-class SetupItem;
-class ScrollArea;
-class VertContainer;
-
-class SetupTabScroll notfinal : public SetupTab
-{
- public:
- explicit SetupTabScroll(const Widget2 *const widget);
-
- A_DELETE_COPY(SetupTabScroll)
-
- virtual ~SetupTabScroll();
-
- void addControl(SetupItem *const widget);
-
- void addControl(SetupItem *const widget, const std::string &event);
-
- VertContainer *getContainer() const noexcept2 A_WARN_UNUSED
- { return mContainer; }
-
- void apply() override;
-
- void cancel() override final;
-
- void externalUpdated() override;
-
- void externalUnloaded() override;
-
- void action(const ActionEvent &event A_UNUSED) override final
- { }
-
- int getPreferredFirstItemSize() const noexcept2 A_WARN_UNUSED
- { return mPreferredFirstItemSize; }
-
- void widgetResized(const Event &event) override final;
-
- void reread(const std::string &name);
-
- void clear() override final;
-
- const std::set<SetupItem*> &getAllItems() const noexcept2
- { return mAllItems; }
-
- protected:
- void removeItems();
-
- VertContainer *mContainer;
- ScrollArea *mScroll;
- std::map<std::string, SetupItem*> mItems;
- std::set<SetupItem*> mAllItems;
- int mPreferredFirstItemSize;
-};
-
-#endif // GUI_WIDGETS_TABS_SETUPTABSCROLL_H
diff --git a/src/gui/widgets/tabs/shortcuttab.h b/src/gui/widgets/tabs/shortcuttab.h
deleted file mode 100644
index 61652777f..000000000
--- a/src/gui/widgets/tabs/shortcuttab.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SHORTCUTTAB_H
-#define GUI_WIDGETS_TABS_SHORTCUTTAB_H
-
-#include "gui/widgets/tabs/tab.h"
-
-#include "localconsts.h"
-
-class ShortcutContainer;
-
-class ShortcutTab final : public Tab
-{
- public:
- ShortcutTab(const Widget2 *const widget,
- const std::string &name,
- ShortcutContainer *const content) :
- Tab(widget),
- mContent(content)
- {
- setCaption(name);
- }
-
- A_DELETE_COPY(ShortcutTab)
-
- ShortcutContainer* mContent;
-};
-
-#endif // GUI_WIDGETS_TABS_SHORTCUTTAB_H
diff --git a/src/gui/widgets/tabs/skilltab.h b/src/gui/widgets/tabs/skilltab.h
deleted file mode 100644
index 9086a4d0c..000000000
--- a/src/gui/widgets/tabs/skilltab.h
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SKILLTAB_H
-#define GUI_WIDGETS_TABS_SKILLTAB_H
-
-#include "gui/windows/skilldialog.h"
-
-#include "gui/widgets/skilllistbox.h"
-#include "gui/widgets/skillrectanglelistbox.h"
-
-#include "gui/widgets/tabs/tab.h"
-
-#include "localconsts.h"
-
-class SkillTab final : public Tab
-{
- public:
- SkillTab(const Widget2 *const widget,
- const std::string &name,
- SkillListBox *const listBox) :
- Tab(widget),
- mListBox(listBox),
- mRectangleListBox(nullptr)
- {
- setCaption(name);
- }
-
- SkillTab(const Widget2 *const widget,
- const std::string &name,
- SkillRectangleListBox *const listBox) :
- Tab(widget),
- mListBox(nullptr),
- mRectangleListBox(listBox)
- {
- setCaption(name);
- }
-
- A_DELETE_COPY(SkillTab)
-
- ~SkillTab()
- {
- delete2(mListBox)
- delete2(mRectangleListBox)
- }
-
- SkillInfo *getSelectedInfo() const
- {
- if (mListBox != nullptr)
- return mListBox->getSelectedInfo();
- else if (mRectangleListBox != nullptr)
- return mRectangleListBox->getSelectedInfo();
- else
- return nullptr;
- }
-
- protected:
- void setCurrent() override
- {
- if (skillDialog != nullptr)
- skillDialog->updateTabSelection();
- }
-
- private:
- SkillListBox *mListBox;
- SkillRectangleListBox *mRectangleListBox;
-};
-
-#endif // GUI_WIDGETS_TABS_SKILLTAB_H
diff --git a/src/gui/widgets/tabs/socialattacktab.h b/src/gui/widgets/tabs/socialattacktab.h
deleted file mode 100644
index e876a60ae..000000000
--- a/src/gui/widgets/tabs/socialattacktab.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALATTACKTAB_H
-#define GUI_WIDGETS_TABS_SOCIALATTACKTAB_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "being/localplayer.h"
-
-#include "gui/models/beingslistmodel.h"
-
-#include "gui/widgets/tabs/socialtabbase.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "localconsts.h"
-
-class SocialAttackTab final : public SocialTab
-{
- public:
- SocialAttackTab(const Widget2 *const widget,
- const Opaque showBackground) :
- SocialTab(widget),
- mBeings(new BeingsListModel)
- {
- createControls(mBeings, showBackground);
-
- // TRANSLATORS: Attack filter tab name in social window.
- // TRANSLATORS: Should be small
- setCaption(_("Atk"));
- mMenuAction = "attack";
- }
-
- A_DELETE_COPY(SocialAttackTab)
-
- ~SocialAttackTab()
- {
- delete2(mList)
- delete2(mScroll)
- delete2(mBeings)
- }
-
- void updateList() override final
- {
- updateAtkListStart();
- // TRANSLATORS: mobs group name in social window
- addAvatars(PriorityAttackMob, _("Priority mobs"), PRIORITY);
- // TRANSLATORS: mobs group name in social window
- addAvatars(AttackMob, _("Attack mobs"), ATTACK);
- // TRANSLATORS: mobs group name in social window
- addAvatars(IgnoreAttackMob, _("Ignore mobs"), IGNORE_);
- }
-
- private:
- BeingsListModel *mBeings;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALATTACKTAB_H
diff --git a/src/gui/widgets/tabs/socialfriendsfunctor.h b/src/gui/widgets/tabs/socialfriendsfunctor.h
deleted file mode 100644
index e68647a77..000000000
--- a/src/gui/widgets/tabs/socialfriendsfunctor.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALFRIENDSFUNCTOR_H
-#define GUI_WIDGETS_TABS_SOCIALFRIENDSFUNCTOR_H
-
-#include "avatar.h"
-
-#include "utils/stringutils.h"
-
-#include "localconsts.h"
-
-class SortFriendsFunctor final
-{
- public:
- A_DEFAULT_COPY(SortFriendsFunctor)
-
- bool operator() (const Avatar *const m1,
- const Avatar *const m2) const
- {
- if ((m1 == nullptr) || (m2 == nullptr))
- return false;
-
- if (m1->getOnline() != m2->getOnline())
- {
- return static_cast<int>(m1->getOnline()) >
- static_cast<int>(m2->getOnline());
- }
-
- if (m1->getName() != m2->getName())
- {
- std::string s1 = m1->getName();
- std::string s2 = m2->getName();
- toLower(s1);
- toLower(s2);
- return s1 < s2;
- }
- return false;
- }
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALFRIENDSFUNCTOR_H
diff --git a/src/gui/widgets/tabs/socialfriendstab.h b/src/gui/widgets/tabs/socialfriendstab.h
deleted file mode 100644
index d1cd942cd..000000000
--- a/src/gui/widgets/tabs/socialfriendstab.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALFRIENDSTAB_H
-#define GUI_WIDGETS_TABS_SOCIALFRIENDSTAB_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "actormanager.h"
-
-#include "being/playerrelations.h"
-
-#include "gui/models/beingslistmodel.h"
-
-#include "gui/windows/whoisonline.h"
-
-#include "gui/widgets/tabs/socialfriendsfunctor.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-
-#include "localconsts.h"
-
-class SocialFriendsTab final : public SocialTab
-{
- public:
- SocialFriendsTab(const Widget2 *const widget,
- const std::string &name,
- const Opaque showBackground) :
- SocialTab(widget),
- mBeings(new BeingsListModel),
- mFriendSorter()
- {
- createControls(mBeings, showBackground);
-
- getPlayersAvatars();
- setCaption(name);
- mMenuAction = "friends";
- }
-
- A_DELETE_COPY(SocialFriendsTab)
-
- ~SocialFriendsTab()
- {
- delete2(mList)
- delete2(mScroll)
- delete2(mBeings)
- }
-
- void updateList() override final
- {
- getPlayersAvatars();
- }
-
- void getPlayersAvatars()
- {
- if (actorManager == nullptr)
- return;
-
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
-
- STD_VECTOR<Avatar*>::iterator ia = avatars->begin();
- while (ia != avatars->end())
- {
- delete *ia;
- ++ ia;
- }
- avatars->clear();
-
- const StringVect *const players
- = playerRelations.getPlayersByRelation(Relation::FRIEND);
-
- const std::set<std::string> &players2
- = whoIsOnline->getOnlineNicks();
-
- if (players == nullptr)
- return;
-
- int online = 0;
- int total = 0;
-
- FOR_EACHP (StringVectCIter, it, players)
- {
- Avatar *const ava = new Avatar(*it);
- if (actorManager->findBeingByName(*it, ActorType::Player) !=
- nullptr || players2.find(*it) != players2.end())
- {
- ava->setOnline(true);
- online ++;
- }
- total ++;
- avatars->push_back(ava);
- }
- std::sort(avatars->begin(), avatars->end(), mFriendSorter);
- delete players;
-
- // TRANSLATORS: social window label
- mCounterString = strprintf(_("Friends: %u/%u"),
- CAST_U32(online),
- CAST_U32(total));
- updateCounter();
- }
-
- private:
- BeingsListModel *mBeings;
- SortFriendsFunctor mFriendSorter;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALFRIENDSTAB_H
diff --git a/src/gui/widgets/tabs/socialguildtab.h b/src/gui/widgets/tabs/socialguildtab.h
deleted file mode 100644
index 8652a54fe..000000000
--- a/src/gui/widgets/tabs/socialguildtab.h
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALGUILDTAB_H
-#define GUI_WIDGETS_TABS_SOCIALGUILDTAB_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "being/localplayer.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "net/guildhandler.h"
-
-#include "localconsts.h"
-
-class SocialGuildTab final : public SocialTab,
- public ActionListener
-{
- public:
- SocialGuildTab(const Widget2 *const widget,
- Guild *const guild,
- const Opaque showBackground) :
- SocialTab(widget),
- ActionListener(),
- mGuild(guild)
- {
- // TRANSLATORS: tab in social window
- setCaption(_("Guild"));
-
- setTabColor(&getThemeColor(ThemeColorId::GUILD_SOCIAL_TAB),
- &getThemeColor(ThemeColorId::GUILD_SOCIAL_TAB_OUTLINE));
- setHighlightedTabColor(&getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_HIGHLIGHTED), &getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_HIGHLIGHTED_OUTLINE));
- setSelectedTabColor(&getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_SELECTED),
- &getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_SELECTED_OUTLINE));
-
- createControls(guild, showBackground);
- mMenuAction = "guild";
- }
-
- A_DELETE_COPY(SocialGuildTab)
-
- ~SocialGuildTab()
- {
- delete2(mList)
- delete2(mScroll)
- }
-
- void action(const ActionEvent &event) override final
- {
- const std::string &eventId = event.getId();
- if (eventId == "do invite")
- {
- const std::string name = mInviteDialog->getText();
- guildHandler->invite(name);
-
- if (localChatTab != nullptr)
- {
- localChatTab->chatLog(strprintf(
- // TRANSLATORS: chat message
- _("Invited user %s to guild %s."),
- name.c_str(),
- mGuild->getName().c_str()),
- ChatMsgType::BY_SERVER);
- }
- mInviteDialog = nullptr;
- }
- else if (eventId == "~do invite")
- {
- mInviteDialog = nullptr;
- }
- else if (eventId == "yes")
- {
- guildHandler->leave(mGuild->getId());
- if (localChatTab != nullptr)
- {
- localChatTab->chatLog(strprintf(
- // TRANSLATORS: chat message
- _("Guild %s quit requested."),
- mGuild->getName().c_str()),
- ChatMsgType::BY_SERVER);
- }
- mConfirmDialog = nullptr;
- }
- else if (eventId == "~yes")
- {
- mConfirmDialog = nullptr;
- }
- }
-
- void invite() override final
- {
- CREATEWIDGETV(mInviteDialog, TextDialog,
- // TRANSLATORS: guild invite message
- _("Member Invite to Guild"),
- // TRANSLATORS: guild invite message
- strprintf(_("Who would you like to invite to guild %s?"),
- mGuild->getName().c_str()), socialWindow);
- mInviteDialog->setActionEventId("do invite");
- mInviteDialog->addActionListener(this);
- }
-
- void leave() override final
- {
- CREATEWIDGETV(mConfirmDialog, ConfirmDialog,
- // TRANSLATORS: guild leave message
- _("Leave Guild?"),
- // TRANSLATORS: guild leave message
- strprintf(_("Are you sure you want to leave guild %s?"),
- mGuild->getName().c_str()), SOUND_REQUEST, socialWindow);
- mConfirmDialog->addActionListener(this);
- }
-
- void buildCounter(const int online0, const int total0) override final
- {
- if ((online0 != 0) || (total0 != 0))
- {
- // TRANSLATORS: social window label
- mCounterString = strprintf(_("Members: %u/%u"),
- CAST_U32(online0),
- CAST_U32(total0));
- }
- else
- {
- if (localPlayer == nullptr)
- return;
-
- const Guild *const guild = localPlayer->getGuild();
- if (guild == nullptr)
- return;
-
- const Guild::MemberList *const members = guild->getMembers();
- int online = 0;
- int total = 0;
- FOR_EACHP (Guild::MemberList::const_iterator, it, members)
- {
- if ((*it)->getOnline())
- online ++;
- total ++;
- }
-
- // TRANSLATORS: social window label
- mCounterString = strprintf(_("Players: %u/%u"),
- CAST_U32(online),
- CAST_U32(total));
- }
- updateCounter();
- }
-
- private:
- Guild *mGuild;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALGUILDTAB_H
diff --git a/src/gui/widgets/tabs/socialguildtab2.h b/src/gui/widgets/tabs/socialguildtab2.h
deleted file mode 100644
index ff8544232..000000000
--- a/src/gui/widgets/tabs/socialguildtab2.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALGUILDTAB2_H
-#define GUI_WIDGETS_TABS_SOCIALGUILDTAB2_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "guild.h"
-
-#include "being/localplayer.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "localconsts.h"
-
-class SocialGuildTab2 final : public SocialTab,
- public ActionListener
-{
- public:
- SocialGuildTab2(const Widget2 *const widget,
- Guild *const guild,
- const Opaque showBackground) :
- SocialTab(widget),
- ActionListener()
- {
- // TRANSLATORS: tab in social window
- setCaption(_("Guild"));
-
- setTabColor(&getThemeColor(ThemeColorId::GUILD_SOCIAL_TAB),
- &getThemeColor(ThemeColorId::GUILD_SOCIAL_TAB_OUTLINE));
- setHighlightedTabColor(&getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_HIGHLIGHTED),
- &getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_HIGHLIGHTED_OUTLINE));
- setSelectedTabColor(&getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_SELECTED),
- &getThemeColor(
- ThemeColorId::GUILD_SOCIAL_TAB_SELECTED_OUTLINE));
-
- createControls(guild, showBackground);
- mMenuAction = "guild";
- }
-
- A_DELETE_COPY(SocialGuildTab2)
-
- ~SocialGuildTab2()
- {
- delete2(mList)
- delete2(mScroll)
- }
-
- void action(const ActionEvent &event A_UNUSED) override final
- {
- }
-
- void buildCounter(const int online0 A_UNUSED,
- const int total0 A_UNUSED) override final
- {
- if (localPlayer == nullptr)
- return;
-
- const Guild *const guild = localPlayer->getGuild();
- if (guild == nullptr)
- return;
-
- const Guild::MemberList *const members = guild->getMembers();
- int online = 0;
- int total = 0;
- FOR_EACHP (Guild::MemberList::const_iterator, it, members)
- {
- if ((*it)->getOnline())
- online ++;
- total ++;
- }
-
- // TRANSLATORS: social window label
- mCounterString = strprintf(_("Players: %u/%u"),
- CAST_U32(online),
- CAST_U32(total));
- updateCounter();
- }
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALGUILDTAB2_H
diff --git a/src/gui/widgets/tabs/socialnavigationtab.h b/src/gui/widgets/tabs/socialnavigationtab.h
deleted file mode 100644
index 1b049f055..000000000
--- a/src/gui/widgets/tabs/socialnavigationtab.h
+++ /dev/null
@@ -1,308 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALNAVIGATIONTAB_H
-#define GUI_WIDGETS_TABS_SOCIALNAVIGATIONTAB_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "actormanager.h"
-#include "configuration.h"
-
-#include "gui/models/beingslistmodel.h"
-
-#include "gui/windows/outfitwindow.h"
-
-#include "being/localplayer.h"
-
-#include "input/keyboardconfig.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "resources/map/map.h"
-#include "resources/map/mapitem.h"
-#include "resources/map/speciallayer.h"
-
-#include "localconsts.h"
-
-class Avatar;
-
-class SocialNavigationTab final : public SocialTab
-{
- public:
- SocialNavigationTab(const Widget2 *const widget,
- const Opaque showBackground) :
- SocialTab(widget),
- mBeings(new BeingsListModel)
- {
- createControls(mBeings, showBackground);
-
- // TRANSLATORS: Navigation tab name in social window.
- // TRANSLATORS: Should be small
- setCaption(_("Nav"));
- mMenuAction = "navigation";
- }
-
- A_DELETE_COPY(SocialNavigationTab)
-
- ~SocialNavigationTab()
- {
- delete2(mList)
- delete2(mScroll)
- delete2(mBeings)
- }
-
- void updateList() override final
- {
- if ((socialWindow == nullptr) || (localPlayer == nullptr))
- return;
-
- const Map *const map = socialWindow->getMap();
- if ((map == nullptr) || map->empty())
- return;
-
- if (socialWindow->getProcessedPortals())
- return;
-
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
- STD_VECTOR<MapItem*> portals = map->getPortals();
-
- STD_VECTOR<MapItem*>::const_iterator i = portals.begin();
- const SpecialLayer *const specialLayer = map->getSpecialLayer();
-
- STD_VECTOR<Avatar*>::iterator ia = avatars->begin();
-
- while (ia != avatars->end())
- {
- delete *ia;
- ++ ia;
- }
-
- avatars->clear();
-
- int online = 0;
- int total = 0;
-
- int idx = 0;
- while (i != portals.end())
- {
- MapItem *portal = *i;
- if (portal == nullptr)
- continue;
-
- const int x = portal->getX();
- const int y = portal->getY();
-
- const std::string name = strprintf("%s [%d %d]",
- portal->getComment().c_str(), x, y);
-
- Avatar *const ava = new Avatar(name);
- if (localPlayer != nullptr)
- ava->setOnline(localPlayer->isReachable(x, y, true));
- else
- ava->setOnline(false);
- ava->setLevel(-1);
- ava->setType(portal->getType());
- ava->setX(x);
- ava->setY(y);
- avatars->push_back(ava);
-
- if (ava->getOnline())
- online ++;
- total ++;
-
- if (config.getBoolValue("drawHotKeys")
- && idx < 80 && (outfitWindow != nullptr))
- {
- Being *const being = actorManager
- ->findPortalByTile(x, y);
- if (being != nullptr)
- {
- being->setName(KeyboardConfig::getKeyShortString(
- OutfitWindow::keyName(idx)));
- }
-
- if (specialLayer != nullptr)
- {
- portal = specialLayer->getTile(
- ava->getX(), ava->getY());
- if (portal != nullptr)
- {
- portal->setName(KeyboardConfig::getKeyShortString(
- OutfitWindow::keyName(idx)));
- }
- }
- }
-
- ++i;
- idx ++;
- }
- if (socialWindow != nullptr)
- socialWindow->setProcessedPortals(true);
-
- // TRANSLATORS: social window label
- mCounterString = strprintf(_("Portals: %u/%u"),
- CAST_U32(online),
- CAST_U32(total));
- updateCounter();
- }
-
- void selectIndex(const unsigned num) override final
- {
- if (localPlayer == nullptr)
- return;
-
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
- if (avatars->size() <= CAST_SIZE(num))
- return;
-
- const Avatar *const ava = avatars->at(num);
- if ((ava != nullptr) && (localPlayer != nullptr))
- localPlayer->navigateTo(ava->getX(), ava->getY());
- }
-
- void updateNames()
- {
- if (socialWindow == nullptr)
- return;
-
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
-
- const Map *const map = socialWindow->getMap();
- if (map == nullptr)
- return;
-
- STD_VECTOR<Avatar*>::const_iterator i = avatars->begin();
- const STD_VECTOR<Avatar*>::const_iterator i_end = avatars->end();
- while (i != i_end)
- {
- Avatar *const ava = *i;
- if (ava == nullptr)
- break;
-
- const MapItem *const item = map->findPortalXY(
- ava->getX(), ava->getY());
- if (item != nullptr)
- {
- const std::string name = strprintf("%s [%d %d]",
- item->getComment().c_str(),
- item->getX(), item->getY());
- ava->setName(name);
- ava->setOriginalName(name);
- }
-
- ++i;
- }
- }
-
- int getPortalIndex(const int x, const int y)
- {
- if (socialWindow == nullptr)
- return -1;
-
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
- const Map *const map = socialWindow->getMap();
- if (map == nullptr)
- return -1;
-
- STD_VECTOR<Avatar*>::const_iterator i = avatars->begin();
- const STD_VECTOR<Avatar*>::const_iterator i_end = avatars->end();
- unsigned num = 0;
- while (i != i_end)
- {
- const Avatar *const ava = *i;
- if (ava == nullptr)
- break;
-
- if (ava->getX() == x && ava->getY() == y)
- return num;
-
- ++i;
- num ++;
- }
- return -1;
- }
-
- void addPortal(const int x, const int y)
- {
- if ((socialWindow == nullptr) || (localPlayer == nullptr))
- return;
-
- const Map *const map = socialWindow->getMap();
- if (map == nullptr)
- return;
-
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
- const MapItem *const portal = map->findPortalXY(x, y);
- if (portal == nullptr)
- return;
-
- const std::string name = strprintf("%s [%d %d]",
- portal->getComment().c_str(), x, y);
-
- Avatar *const ava = new Avatar(name);
- if (localPlayer != nullptr)
- ava->setOnline(localPlayer->isReachable(x, y, true));
- else
- ava->setOnline(false);
- ava->setLevel(-1);
- ava->setType(portal->getType());
- ava->setX(x);
- ava->setY(y);
- avatars->push_back(ava);
- }
-
- void removePortal(const int x, const int y)
- {
- if ((socialWindow == nullptr) || (localPlayer == nullptr))
- return;
-
- const Map *const map = socialWindow->getMap();
- if (map == nullptr)
- return;
-
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
- STD_VECTOR<Avatar*>::iterator i = avatars->begin();
- const STD_VECTOR<Avatar*>::iterator i_end = avatars->end();
-
- while (i != i_end)
- {
- Avatar *ava = (*i);
-
- if (ava == nullptr)
- break;
-
- if (ava->getX() == x && ava->getY() == y)
- {
- delete ava;
- avatars->erase(i);
- return;
- }
-
- ++ i;
- }
- }
-
- private:
- BeingsListModel *mBeings;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALNAVIGATIONTAB_H
diff --git a/src/gui/widgets/tabs/socialpartytab.h b/src/gui/widgets/tabs/socialpartytab.h
deleted file mode 100644
index d7f22c1f7..000000000
--- a/src/gui/widgets/tabs/socialpartytab.h
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALPARTYTAB_H
-#define GUI_WIDGETS_TABS_SOCIALPARTYTAB_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "party.h"
-
-#include "being/localplayer.h"
-
-#include "net/partyhandler.h"
-
-#include "utils/delete2.h"
-#include "utils/foreach.h"
-#include "utils/gettext.h"
-#include "utils/stringutils.h"
-
-#include "localconsts.h"
-
-class SocialPartyTab final : public SocialTab,
- public ActionListener
-{
- public:
- SocialPartyTab(const Widget2 *const widget,
- Party *const party,
- const Opaque showBackground) :
- SocialTab(widget),
- ActionListener(),
- mParty(party)
- {
- // TRANSLATORS: tab in social window
- setCaption(_("Party"));
-
- setTabColor(&getThemeColor(ThemeColorId::PARTY_SOCIAL_TAB),
- &getThemeColor(ThemeColorId::PARTY_SOCIAL_TAB_OUTLINE));
- setHighlightedTabColor(&getThemeColor(
- ThemeColorId::PARTY_SOCIAL_TAB_HIGHLIGHTED), &getThemeColor(
- ThemeColorId::PARTY_SOCIAL_TAB_HIGHLIGHTED_OUTLINE));
- setSelectedTabColor(&getThemeColor(
- ThemeColorId::PARTY_SOCIAL_TAB_SELECTED),
- &getThemeColor(
- ThemeColorId::PARTY_SOCIAL_TAB_SELECTED_OUTLINE));
-
- createControls(party, showBackground);
- mMenuAction = "party";
- }
-
- A_DELETE_COPY(SocialPartyTab)
-
- ~SocialPartyTab()
- {
- delete2(mList)
- delete2(mScroll)
- }
-
- void action(const ActionEvent &event) override final
- {
- const std::string &eventId = event.getId();
- if (eventId == "do invite")
- {
- const std::string name = mInviteDialog->getText();
- partyHandler->invite(name);
-
- if (localChatTab != nullptr)
- {
- localChatTab->chatLog(strprintf(
- // TRANSLATORS: chat message
- _("Invited user %s to party."),
- name.c_str()),
- ChatMsgType::BY_SERVER);
- }
- mInviteDialog = nullptr;
- }
- else if (eventId == "~do invite")
- {
- mInviteDialog = nullptr;
- }
- else if (eventId == "yes")
- {
- partyHandler->leave();
- if (localChatTab != nullptr)
- {
- localChatTab->chatLog(strprintf(
- // TRANSLATORS: tab in social window
- _("Party %s quit requested."),
- mParty->getName().c_str()),
- ChatMsgType::BY_SERVER);
- }
- mConfirmDialog = nullptr;
- }
- else if (eventId == "~yes")
- {
- mConfirmDialog = nullptr;
- }
- }
-
- void invite() override final
- {
- CREATEWIDGETV(mInviteDialog, TextDialog,
- // TRANSLATORS: party invite message
- _("Member Invite to Party"),
- // TRANSLATORS: party invite message
- strprintf(_("Who would you like to invite to party %s?"),
- mParty->getName().c_str()), socialWindow);
- mInviteDialog->setActionEventId("do invite");
- mInviteDialog->addActionListener(this);
- }
-
- void leave() override final
- {
- CREATEWIDGETV(mConfirmDialog, ConfirmDialog,
- // TRANSLATORS: party leave message
- _("Leave Party?"),
- // TRANSLATORS: party leave message
- strprintf(_("Are you sure you want to leave party %s?"),
- mParty->getName().c_str()), SOUND_REQUEST, socialWindow);
- mConfirmDialog->addActionListener(this);
- }
-
- void buildCounter(const int online0 A_UNUSED,
- const int total0 A_UNUSED) override final
- {
- if (localPlayer == nullptr)
- return;
-
- const Party *const party = localPlayer->getParty();
- if (party == nullptr)
- return;
-
- const Party::MemberList *const members = party->getMembers();
- int online = 0;
- int total = 0;
- FOR_EACHP (Party::MemberList::const_iterator, it, members)
- {
- if ((*it)->getOnline())
- online ++;
- total ++;
- }
-
- // TRANSLATORS: social window label
- mCounterString = strprintf(_("Players: %u/%u"),
- CAST_U32(online),
- CAST_U32(total));
- updateCounter();
- }
-
- private:
- Party *mParty;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALPARTYTAB_H
diff --git a/src/gui/widgets/tabs/socialpickuptab.h b/src/gui/widgets/tabs/socialpickuptab.h
deleted file mode 100644
index 93d00e81a..000000000
--- a/src/gui/widgets/tabs/socialpickuptab.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALPICKUPTAB_H
-#define GUI_WIDGETS_TABS_SOCIALPICKUPTAB_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "being/localplayer.h"
-
-#include "gui/models/beingslistmodel.h"
-
-#include "gui/widgets/tabs/socialtabbase.h"
-
-#include "utils/delete2.h"
-#include "utils/gettext.h"
-
-#include "localconsts.h"
-
-class SocialPickupTab final : public SocialTab
-{
- public:
- SocialPickupTab(const Widget2 *const widget,
- const Opaque showBackground) :
- SocialTab(widget),
- mBeings(new BeingsListModel)
- {
- createControls(mBeings, showBackground);
-
- // TRANSLATORS: Pickup filter tab name in social window.
- // TRANSLATORS: Should be small
- setCaption(_("Pik"));
- mMenuAction = "pickup";
- }
-
- A_DELETE_COPY(SocialPickupTab)
-
- ~SocialPickupTab()
- {
- delete2(mList)
- delete2(mScroll)
- delete2(mBeings)
- }
-
- void updateList() override final
- {
- updateAtkListStart();
- // TRANSLATORS: items group name in social window
- addAvatars(PickupItem, _("Pickup items"), PICKUP);
- // TRANSLATORS: items group name in social window
- addAvatars(IgnorePickupItem, _("Ignore items"), NOPICKUP);
- }
-
- private:
- BeingsListModel *mBeings;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALPICKUPTAB_H
diff --git a/src/gui/widgets/tabs/socialplayerstab.h b/src/gui/widgets/tabs/socialplayerstab.h
deleted file mode 100644
index c43093fca..000000000
--- a/src/gui/widgets/tabs/socialplayerstab.h
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALPLAYERSTAB_H
-#define GUI_WIDGETS_TABS_SOCIALPLAYERSTAB_H
-
-#include "gui/widgets/tabs/socialtab.h"
-
-#include "actormanager.h"
-#include "party.h"
-
-#include "being/being.h"
-
-#include "gui/models/beingslistmodel.h"
-
-#include "utils/gettext.h"
-#include "utils/delete2.h"
-#include "utils/stringutils.h"
-
-#include "localconsts.h"
-
-class Avatar;
-class Being;
-
-class SocialPlayersTab final : public SocialTab
-{
- public:
- SocialPlayersTab(const Widget2 *const widget,
- const std::string &name,
- const Opaque showBackground) :
- SocialTab(widget),
- mBeings(new BeingsListModel)
- {
- createControls(mBeings, showBackground);
-
- getPlayersAvatars();
- setCaption(name);
- mMenuAction = "players";
- }
-
- A_DELETE_COPY(SocialPlayersTab)
-
- ~SocialPlayersTab()
- {
- delete2(mList)
- delete2(mScroll)
- delete2(mBeings)
- }
-
- void updateList() override final
- {
- getPlayersAvatars();
- }
-
- void updateAvatar(const std::string &name) override final
- {
- if (actorManager == nullptr)
- return;
-
- BLOCK_START("SocialPlayersTab::updateAvatar")
- Avatar *const avatar = findAvatarbyName(name);
- if (avatar == nullptr)
- return;
- if (Party::getParty(1) != nullptr)
- {
- const PartyMember *const
- pm = Party::getParty(1)->getMember(name);
- if ((pm != nullptr) && pm->getMaxHp() > 0)
- {
- avatar->setMaxHp(pm->getMaxHp());
- avatar->setHp(pm->getHp());
- }
- }
- const Being *const being = actorManager->findBeingByName(
- name, ActorType::Player);
- if (being != nullptr)
- {
- avatar->setDamageHp(being->getDamageTaken());
- avatar->setLevel(being->getLevel());
- avatar->setGender(being->getGender());
- avatar->setIp(being->getIp());
- avatar->setPoison(being->getPoison());
- }
- BLOCK_END("SocialPlayersTab::updateAvatar")
- }
-
- void resetDamage(const std::string &name) override final
- {
- if (actorManager == nullptr)
- return;
-
- Avatar *const avatar = findAvatarbyName(name);
- if (avatar == nullptr)
- return;
- avatar->setDamageHp(0);
- Being *const being = actorManager->findBeingByName(
- name, ActorType::Player);
-
- if (being != nullptr)
- being->setDamageTaken(0);
- }
-
- Avatar* findAvatarbyName(const std::string &name)
- {
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
- Avatar *ava = nullptr;
- STD_VECTOR<Avatar*>::const_iterator i = avatars->begin();
- const STD_VECTOR<Avatar*>::const_iterator i_end = avatars->end();
- while (i != i_end)
- {
- ava = (*i);
- if ((ava != nullptr) && ava->getName() == name)
- return ava;
- ++i;
- }
- ava = new Avatar(name);
- ava->setOnline(true);
- avatars->push_back(ava);
- return ava;
- }
-
- void getPlayersAvatars()
- {
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();
- if (actorManager != nullptr)
- {
- StringVect names;
- actorManager->getPlayerNames(names, NpcNames_false);
-
- STD_VECTOR<Avatar*>::iterator ai = avatars->begin();
- while (ai != avatars->end())
- {
- bool finded = false;
- const Avatar *const ava = (*ai);
- if (ava == nullptr)
- break;
-
- StringVectCIter i = names.begin();
- const StringVectCIter i_end = names.end();
- while (i != i_end)
- {
- if (ava->getName() == (*i) && !(*i).empty())
- {
- finded = true;
- break;
- }
- ++i;
- }
-
- if (!finded)
- {
- delete *ai;
- ai = avatars->erase(ai);
- }
- else
- {
- ++ai;
- }
- }
-
- StringVectCIter i = names.begin();
- const StringVectCIter i_end = names.end();
-
- while (i != i_end)
- {
- if (!(*i).empty())
- updateAvatar(*i);
- ++i;
- }
- }
- // TRANSLATORS: social window label
- mCounterString = strprintf(_("Visible players: %d"),
- CAST_S32(avatars->size()));
- updateCounter();
- }
-
- private:
- BeingsListModel *mBeings;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALPLAYERSTAB_H
diff --git a/src/gui/widgets/tabs/socialtab.h b/src/gui/widgets/tabs/socialtab.h
deleted file mode 100644
index 1c94aaede..000000000
--- a/src/gui/widgets/tabs/socialtab.h
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALTAB_H
-#define GUI_WIDGETS_TABS_SOCIALTAB_H
-
-#include "gui/windows/socialwindow.h"
-
-#include "gui/windows/confirmdialog.h"
-#include "gui/windows/textdialog.h"
-
-#include "gui/widgets/avatarlistbox.h"
-#include "gui/widgets/createwidget.h"
-#include "gui/widgets/scrollarea.h"
-
-#include "gui/widgets/tabs/tab.h"
-
-#include "localconsts.h"
-
-class AvatarListModel;
-
-class SocialTab notfinal : public Tab
-{
- public:
- A_DELETE_COPY(SocialTab)
-
- virtual void invite()
- {
- }
-
- virtual void leave()
- {
- }
-
- virtual void updateList()
- {
- }
-
- virtual void updateAvatar(const std::string &name A_UNUSED)
- {
- }
-
- virtual void resetDamage(const std::string &name A_UNUSED)
- {
- }
-
- virtual void selectIndex(const unsigned num A_UNUSED)
- {
- }
-
- virtual void buildCounter(const int online A_UNUSED,
- const int total A_UNUSED)
- {
- }
-
- protected:
- friend class SocialWindow;
-
- explicit SocialTab(const Widget2 *const widget) :
- Tab(widget),
- mInviteDialog(nullptr),
- mConfirmDialog(nullptr),
- mScroll(nullptr),
- mList(nullptr),
- mCounterString(),
- mMenuAction("menu")
- {
- }
-
- virtual ~SocialTab()
- {
- // Cleanup dialogs
- if (mInviteDialog != nullptr)
- {
- mInviteDialog->close();
- mInviteDialog->scheduleDelete();
- mInviteDialog = nullptr;
- }
-
- if (mConfirmDialog != nullptr)
- {
- mConfirmDialog->close();
- mConfirmDialog->scheduleDelete();
- mConfirmDialog = nullptr;
- }
- }
-
- void createControls(AvatarListModel *const listModel,
- const Opaque showBackground)
- {
- CREATEWIDGETV(mList, AvatarListBox, this, listModel);
- mScroll = new ScrollArea(this, mList, showBackground,
- "social_background.xml");
-
- mScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_AUTO);
- mScroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
- }
-
- void setCurrent() override final
- {
- updateCounter();
- updateMenu();
- }
-
- void updateCounter() const
- {
- if (socialWindow != nullptr)
- socialWindow->updateCounter(this, mCounterString);
- }
-
- void updateMenu() const
- {
- if (socialWindow != nullptr)
- socialWindow->updateMenu(this, mMenuAction);
- }
-
- TextDialog *mInviteDialog;
- ConfirmDialog *mConfirmDialog;
- ScrollArea *mScroll;
- AvatarListBox *mList;
- std::string mCounterString;
- std::string mMenuAction;
-};
-
-#endif // GUI_WIDGETS_TABS_SOCIALTAB_H
diff --git a/src/gui/widgets/tabs/socialtabbase.h b/src/gui/widgets/tabs/socialtabbase.h
deleted file mode 100644
index 03a02bb1f..000000000
--- a/src/gui/widgets/tabs/socialtabbase.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABS_SOCIALTABBASE_H
-#define GUI_WIDGETS_TABS_SOCIALTABBASE_H
-
-#include "actormanager.h"
-
-ACTORMANAGER_H
-
-#include "enums/resources/map/mapitemtype.h"
-
-ENUMS_RESOURCES_MAP_MAPITEMTYPE_H
-
-#define addAvatars(mob, str, type) \
-{\
- ava = new Avatar(str);\
- ava->setOnline(false);\
- ava->setLevel(-1);\
- ava->setType(MapItemType::SEPARATOR);\
- ava->setX(0);\
- ava->setY(0);\
- avatars->push_back(ava);\
- mobs = actorManager->get##mob##s();\
- i = mobs.begin();\
- i_end = mobs.end();\
- while (i != i_end)\
- {\
- std::string name;\
- int level = -1;\
- if ((*i).empty())\
- {\
- name = _("(default)");\
- level = 0;\
- }\
- else\
- {\
- name = *i;\
- }\
- ava = new Avatar(name);\
- ava->setOnline(true);\
- ava->setLevel(level);\
- ava->setType(MapItemType::type);\
- ava->setX(0);\
- ava->setY(0);\
- avatars->push_back(ava);\
- ++ i;\
- }\
-}
-
-#define updateAtkListStart() \
- if (!socialWindow || !localPlayer || !actorManager)\
- return;\
- STD_VECTOR<Avatar*> *const avatars = mBeings->getMembers();\
- STD_VECTOR<Avatar*>::iterator ia = avatars->begin();\
- while (ia != avatars->end())\
- {\
- delete *ia;\
- ++ ia;\
- }\
- avatars->clear();\
- Avatar *ava = nullptr;\
- std::list<std::string> mobs;\
- std::list<std::string>::const_iterator i;\
- std::list<std::string>::const_iterator i_end;
-
-#endif // GUI_WIDGETS_TABS_SOCIALTABBASE_H
diff --git a/src/gui/widgets/tabs/tab.cpp b/src/gui/widgets/tabs/tab.cpp
deleted file mode 100644
index 36c2a3f40..000000000
--- a/src/gui/widgets/tabs/tab.cpp
+++ /dev/null
@@ -1,488 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/tabs/tab.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/widgets/label.h"
-#include "gui/widgets/tabbedarea.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "resources/imagerect.h"
-
-#include "resources/image/image.h"
-
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-int Tab::mInstances = 0;
-float Tab::mAlpha = 1.0;
-
-namespace
-{
- std::string const data[Tab::TAB_COUNT] =
- {
- "tab.xml",
- "tab_highlighted.xml",
- "tab_selected.xml",
- "tab_unused.xml"
- };
-} // namespace
-
-Skin *Tab::tabImg[Tab::TAB_COUNT];
-
-Tab::Tab(const Widget2 *const widget) :
- BasicContainer(widget),
- MouseListener(),
- WidgetListener(),
- mLabel(new Label(this)),
- mTabbedArea(nullptr),
- mTabColor(&getThemeColor(ThemeColorId::TAB)),
- mTabOutlineColor(&getThemeColor(ThemeColorId::TAB_OUTLINE)),
- mTabHighlightedColor(&getThemeColor(ThemeColorId::TAB_HIGHLIGHTED)),
- mTabHighlightedOutlineColor(&getThemeColor(
- ThemeColorId::TAB_HIGHLIGHTED_OUTLINE)),
- mTabSelectedColor(&getThemeColor(ThemeColorId::TAB_SELECTED)),
- mTabSelectedOutlineColor(&getThemeColor(
- ThemeColorId::TAB_SELECTED_OUTLINE)),
- mFlashColor(&getThemeColor(ThemeColorId::TAB_FLASH)),
- mFlashOutlineColor(&getThemeColor(ThemeColorId::TAB_FLASH_OUTLINE)),
- mPlayerFlashColor(&getThemeColor(ThemeColorId::TAB_PLAYER_FLASH)),
- mPlayerFlashOutlineColor(&getThemeColor(
- ThemeColorId::TAB_PLAYER_FLASH_OUTLINE)),
- mFlash(0),
- mVertexes(new ImageCollection),
- mImage(nullptr),
- mMode(0),
- mLabelMode(-1),
- mHasMouse(false)
-{
- init();
-}
-
-Tab::~Tab()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- mInstances--;
- if (mInstances == 0 && (theme != nullptr))
- {
- for (int mode = 0; mode < TAB_COUNT; mode ++)
- theme->unload(tabImg[mode]);
- }
-
- delete2(mLabel);
-
- if (mImage != nullptr)
- {
- mImage->decRef();
- mImage = nullptr;
- }
- delete2(mVertexes);
-}
-
-void Tab::init()
-{
- addMouseListener(this);
- setFocusable(false);
- setFrameSize(0);
- mFlash = 0;
-
- addWidgetListener(this);
-
- if (mInstances == 0)
- {
- // Load the skin
- if (theme != nullptr)
- {
- for (int mode = 0; mode < TAB_COUNT; mode ++)
- tabImg[mode] = theme->load(data[mode], "tab.xml");
- }
- updateAlpha();
- }
- mInstances++;
-
- add(mLabel);
-
- const Skin *const skin = tabImg[TAB_STANDARD];
- if (skin == nullptr)
- return;
- const int padding = skin->getPadding();
-
- mLabel->setPosition(padding, padding);
-}
-
-void Tab::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (alpha != mAlpha)
- {
- mAlpha = alpha;
- for (int a = 0; a < 9; a++)
- {
- for (int t = 0; t < TAB_COUNT; t++)
- {
- Skin *const skin = tabImg[t];
- if (skin != nullptr)
- {
- const ImageRect &rect = skin->getBorder();
- Image *const image = rect.grid[a];
- if (image != nullptr)
- image->setAlpha(mAlpha);
- }
- }
- }
- }
-}
-
-void Tab::draw(Graphics *const graphics)
-{
- BLOCK_START("Tab::draw")
- int mode = TAB_STANDARD;
-
- // check which type of tab to draw
- if (mTabbedArea != nullptr)
- {
- int labelMode = mFlash;
-
- if (mTabbedArea->isTabSelected(this))
- {
- labelMode = 3;
- mode = TAB_SELECTED;
- // if tab is selected, it doesnt need to highlight activity
- mFlash = 0;
- }
- else if (labelMode == 0)
- {
- if (mHasMouse)
- {
- labelMode = 4;
- mode = TAB_HIGHLIGHTED;
- }
- }
- else if (mHasMouse)
- {
- mode = TAB_HIGHLIGHTED;
- }
-
- // mRedraw need here because no other way to say label to change color
- // +++ text from label must be moved to tab itself
- if (labelMode != mLabelMode || mRedraw)
- {
- mLabelMode = labelMode;
- switch (labelMode)
- {
- case 0: // default state
- default:
- mLabel->setForegroundColorAll(*mTabColor,
- *mTabOutlineColor);
- break;
- case 1: // mFlash == 1
- mLabel->setForegroundColorAll(*mFlashColor,
- *mFlashOutlineColor);
- break;
- case 2: // mFlash == 2
- mLabel->setForegroundColorAll(*mPlayerFlashColor,
- *mPlayerFlashOutlineColor);
- break;
- case 3: // mTabbedArea->isTabSelected(this)
- mLabel->setForegroundColorAll(*mTabSelectedColor,
- *mTabSelectedOutlineColor);
- break;
- case 4: // mHasMouse
- mLabel->setForegroundColorAll(*mTabHighlightedColor,
- *mTabHighlightedOutlineColor);
- break;
- }
- }
- }
-
- const Skin *const skin = tabImg[mode];
- if (skin == nullptr)
- {
- BLOCK_END("Tab::draw")
- return;
- }
-
- updateAlpha();
-
- const ImageRect &rect = skin->getBorder();
- if (mRedraw || mode != mMode || graphics->getRedraw())
- {
- mMode = mode;
- mRedraw = false;
- mVertexes->clear();
- graphics->calcWindow(mVertexes,
- 0, 0,
- mDimension.width, mDimension.height,
- rect);
-
- if (mImage != nullptr)
- {
- const Skin *const skin1 = tabImg[TAB_STANDARD];
- if (skin1 != nullptr)
- {
- const int padding = skin1->getPadding();
- graphics->calcTileCollection(mVertexes,
- mImage,
- padding,
- padding);
- }
- }
- graphics->finalize(mVertexes);
- }
-
- graphics->drawTileCollection(mVertexes);
-
- drawChildren(graphics);
- BLOCK_END("Tab::draw")
-}
-
-void Tab::safeDraw(Graphics *const graphics)
-{
- BLOCK_START("Tab::draw")
- int mode = TAB_STANDARD;
-
- // check which type of tab to draw
- if (mTabbedArea != nullptr)
- {
- int labelMode = mFlash;
-
- if (mTabbedArea->isTabSelected(this))
- {
- labelMode = 3;
- mode = TAB_SELECTED;
- // if tab is selected, it doesnt need to highlight activity
- mFlash = 0;
- }
- else if (labelMode == 0)
- {
- if (mHasMouse)
- {
- labelMode = 4;
- mode = TAB_HIGHLIGHTED;
- }
- }
- else if (mHasMouse)
- {
- mode = TAB_HIGHLIGHTED;
- }
-
- if (labelMode != mLabelMode)
- {
- mLabelMode = labelMode;
- switch (labelMode)
- {
- case 0: // default state
- default:
- mLabel->setForegroundColorAll(*mTabColor,
- *mTabOutlineColor);
- break;
- case 1: // mFlash == 1
- mLabel->setForegroundColorAll(*mFlashColor,
- *mFlashOutlineColor);
- break;
- case 2: // mFlash == 2
- mLabel->setForegroundColorAll(*mPlayerFlashColor,
- *mPlayerFlashOutlineColor);
- break;
- case 3: // mTabbedArea->isTabSelected(this)
- mLabel->setForegroundColorAll(*mTabSelectedColor,
- *mTabSelectedOutlineColor);
- break;
- case 4: // mHasMouse
- mLabel->setForegroundColorAll(*mTabHighlightedColor,
- *mTabHighlightedOutlineColor);
- break;
- }
- }
- }
-
- const Skin *const skin = tabImg[mode];
- if (skin == nullptr)
- {
- BLOCK_END("Tab::draw")
- return;
- }
-
- updateAlpha();
-
- graphics->drawImageRect(0, 0,
- mDimension.width, mDimension.height,
- skin->getBorder());
- if (mImage != nullptr)
- {
- const Skin *const skin1 = tabImg[TAB_STANDARD];
- if (skin1 != nullptr)
- {
- const int padding = skin1->getPadding();
- graphics->drawImage(mImage, padding, padding);
- }
- }
-
- safeDrawChildren(graphics);
- BLOCK_END("Tab::draw")
-}
-
-void Tab::widgetResized(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void Tab::widgetMoved(const Event &event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void Tab::setLabelFont(Font *const font)
-{
- if (mLabel == nullptr)
- return;
-
- mLabel->setFont(font);
- mLabel->adjustSize();
- adjustSize();
- mRedraw = true;
-}
-
-
-void Tab::adjustSize()
-{
- const Skin *const skin = tabImg[TAB_STANDARD];
- if (skin == nullptr)
- return;
- const int pad2 = skin->getPadding() * 2;
-
- if (mImage != nullptr)
- {
- const SDL_Rect &rect = mImage->mBounds;
- setSize(rect.w + pad2, rect.h + pad2);
- }
- else
- {
- setSize(mLabel->getWidth() + pad2,
- mLabel->getHeight() + pad2);
- }
-
- if (mTabbedArea != nullptr)
- mTabbedArea->adjustTabPositions();
-}
-
-void Tab::setTabbedArea(TabbedArea* tabbedArea)
-{
- mTabbedArea = tabbedArea;
-}
-
-TabbedArea* Tab::getTabbedArea() const
-{
- return mTabbedArea;
-}
-
-void Tab::setCaption(const std::string &caption)
-{
- mLabel->setCaption(caption);
- mLabel->adjustSize();
- adjustSize();
-}
-
-void Tab::setImage(Image *const image)
-{
- if (mImage != nullptr)
- mImage->decRef();
- mImage = image;
- adjustSize();
-}
-
-const std::string &Tab::getCaption() const
-{
- return mLabel->getCaption();
-}
-
-void Tab::mouseEntered(MouseEvent& event A_UNUSED)
-{
- mHasMouse = true;
-}
-
-void Tab::mouseExited(MouseEvent& event A_UNUSED)
-{
- mHasMouse = false;
-}
-
-void Tab::finalCleanup()
-{
- for (int f = 0; f < TAB_COUNT; f ++)
- {
- tabImg[f] = nullptr;
- }
-}
diff --git a/src/gui/widgets/tabs/tab.h b/src/gui/widgets/tabs/tab.h
deleted file mode 100644
index e6a816072..000000000
--- a/src/gui/widgets/tabs/tab.h
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2008-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_TABS_TAB_H
-#define GUI_WIDGETS_TABS_TAB_H
-
-#include "gui/widgets/basiccontainer.h"
-
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-class ImageCollection;
-class Label;
-class Skin;
-class TabbedArea;
-
-/**
- * A tab, the same as the Guichan tab in 0.8, but extended
- */
-class Tab notfinal : public BasicContainer,
- public MouseListener,
- public WidgetListener
-{
- public:
- explicit Tab(const Widget2 *const widget);
-
- A_DELETE_COPY(Tab)
-
- virtual ~Tab();
-
- enum
- {
- TAB_STANDARD = 0,
- TAB_HIGHLIGHTED = 1,
- TAB_SELECTED = 2,
- TAB_UNUSED = 3,
- TAB_COUNT = 4 // Must be last
- };
-
- /**
- * Update the alpha value to the graphic components.
- */
- void updateAlpha();
-
- /**
- * Draw the tabbed area.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Set the normal color for the tab's text.
- */
- void setTabColor(const Color *const color1,
- const Color *const color2)
- {
- mTabColor = color1;
- mTabOutlineColor = color2;
- mRedraw = true;
- }
-
- /**
- * Set the highlighted color for the tab's text.
- */
- void setHighlightedTabColor(const Color *const color1,
- const Color *const color2)
- {
- mTabHighlightedColor = color1;
- mTabHighlightedOutlineColor = color2;
- mRedraw = true;
- }
-
- /**
- * Set the selected color for the tab's text.
- */
- void setSelectedTabColor(const Color *const color1,
- const Color *const color2)
- {
- mTabSelectedColor = color1;
- mTabSelectedOutlineColor = color2;
- mRedraw = true;
- }
-
- /**
- * Set the flash color for the tab's text.
- */
- void setFlashTabColor(const Color *const color1,
- const Color *const color2)
- {
- mFlashColor = color1;
- mFlashOutlineColor = color2;
- mRedraw = true;
- }
-
- /**
- * Set the player flash color for the tab's text.
- */
- void setPlayerFlashTabColor(const Color *const color1,
- const Color *const color2)
- {
- mPlayerFlashColor = color1;
- mPlayerFlashOutlineColor = color2;
- mRedraw = true;
- }
-
- /**
- * Set tab flashing state
- */
- void setFlash(const int flash)
- { mFlash = flash; mRedraw = true; }
-
- int getFlash() const noexcept2 A_WARN_UNUSED
- { return mFlash; }
-
- void widgetResized(const Event &event) override final;
-
- void widgetMoved(const Event &event) override final;
-
- void setLabelFont(Font *const font);
-
- Label *getLabel() const noexcept2 A_WARN_UNUSED
- { return mLabel; }
-
- void adjustSize();
-
- void setTabbedArea(TabbedArea* tabbedArea);
-
- TabbedArea* getTabbedArea() const A_WARN_UNUSED;
-
- void setCaption(const std::string& caption);
-
- const std::string &getCaption() const A_WARN_UNUSED;
-
- void mouseEntered(MouseEvent &event) override final;
-
- void mouseExited(MouseEvent &event) override final;
-
- void setImage(Image *const image);
-
- static void finalCleanup();
-
- protected:
- friend class TabbedArea;
-
- virtual void setCurrent()
- { }
-
- Label* mLabel A_NONNULLPOINTER;
-
- TabbedArea* mTabbedArea;
-
- private:
- /** Load images if no other instances exist yet */
- void init();
-
- static Skin *tabImg[TAB_COUNT]; /**< Tab state graphics */
- static int mInstances; /**< Number of tab instances */
- static float mAlpha;
-
- const Color *mTabColor;
- const Color *mTabOutlineColor;
- const Color *mTabHighlightedColor;
- const Color *mTabHighlightedOutlineColor;
- const Color *mTabSelectedColor;
- const Color *mTabSelectedOutlineColor;
- const Color *mFlashColor;
- const Color *mFlashOutlineColor;
- const Color *mPlayerFlashColor;
- const Color *mPlayerFlashOutlineColor;
- int mFlash;
- ImageCollection *mVertexes A_NONNULLPOINTER;
- Image *mImage;
- int mMode;
- int mLabelMode;
-
- protected:
- bool mHasMouse;
-};
-
-#endif // GUI_WIDGETS_TABS_TAB_H
diff --git a/src/gui/widgets/tabstrip.cpp b/src/gui/widgets/tabstrip.cpp
deleted file mode 100644
index 6b3dbe417..000000000
--- a/src/gui/widgets/tabstrip.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/tabstrip.h"
-
-#include "gui/widgets/button.h"
-
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-TabStrip::TabStrip(const Widget2 *const widget,
- const std::string &group,
- const int height,
- const int spacing) :
- WidgetGroup(widget, group, height, spacing),
- mPressFirst(true)
-{
- mAllowLogic = false;
-}
-
-TabStrip::TabStrip(const Widget2 *const widget,
- const int height,
- const int spacing) :
- WidgetGroup(widget, "", height, spacing),
- mPressFirst(true)
-{
- mAllowLogic = false;
-}
-
-Widget *TabStrip::createWidget(const std::string &text,
- const bool pressed) const
-{
- Button *const widget = new Button(this);
- widget->setStick(true);
- widget->setCaption(text);
- widget->adjustSize();
- if (((mCount == 0) && mPressFirst) || pressed)
- widget->setPressed(true);
- widget->setTag(CAST_S32(mWidgets.size()));
- return widget;
-}
-
-void TabStrip::action(const ActionEvent &event)
-{
- WidgetGroup::action(event);
- if (event.getSource() != nullptr)
- {
- Widget *const widget = event.getSource();
- Button *const button = static_cast<Button*>(widget);
- if (button == nullptr)
- return;
- if (button->isPressed2())
- {
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- {
- if (*iter != widget)
- {
- Button *const button2 = static_cast<Button*>(*iter);
- button2->setPressed(false);
- }
- }
- }
- else
- {
- button->setPressed(true);
- }
- }
-}
-
-void TabStrip::nextTab()
-{
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- {
- Button *button = static_cast<Button*>(*iter);
- if (button->isPressed2())
- {
- button->setPressed(false);
- ++iter;
- if (iter == mWidgets.end())
- iter = mWidgets.begin();
- button = static_cast<Button*>(*iter);
- action(ActionEvent(button, button->getActionEventId()));
- return;
- }
- }
-}
-
-void TabStrip::prevTab()
-{
- FOR_EACH (WidgetListConstIterator, iter, mWidgets)
- {
- Button *button = static_cast<Button*>(*iter);
- if (button->isPressed2())
- {
- button->setPressed(false);
- if (iter == mWidgets.begin())
- iter = mWidgets.end();
- if (iter == mWidgets.begin())
- return;
- --iter;
- button = static_cast<Button*>(*iter);
- action(ActionEvent(button, button->getActionEventId()));
- return;
- }
- }
-}
diff --git a/src/gui/widgets/tabstrip.h b/src/gui/widgets/tabstrip.h
deleted file mode 100644
index e1e4ca486..000000000
--- a/src/gui/widgets/tabstrip.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TABSTRIP_H
-#define GUI_WIDGETS_TABSTRIP_H
-
-#include "gui/widgets/widgetgroup.h"
-
-class TabStrip final : public WidgetGroup
-{
- public:
- TabStrip(const Widget2 *const widget,
- const std::string &group,
- const int height,
- const int spacing = 0);
-
- TabStrip(const Widget2 *const widget,
- const int height,
- const int spacing = 0);
-
- A_DELETE_COPY(TabStrip)
-
- Widget *createWidget(const std::string &name,
- const bool pressed)
- const override final A_WARN_UNUSED;
-
- void action(const ActionEvent &event) override final;
-
- void nextTab();
-
- void prevTab();
-
- void setPressFirst(const bool press)
- { mPressFirst = press; }
-
- protected:
- bool mPressFirst;
-};
-
-#endif // GUI_WIDGETS_TABSTRIP_H
diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp
deleted file mode 100644
index 5d1696835..000000000
--- a/src/gui/widgets/textbox.cpp
+++ /dev/null
@@ -1,647 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/textbox.h"
-
-#include "gui/gui.h"
-
-#include "gui/fonts/font.h"
-
-#include "render/graphics.h"
-
-#include <sstream>
-
-#include "debug.h"
-
-TextBox::TextBox(const Widget2 *const widget) :
- Widget(widget),
- MouseListener(),
- KeyListener(),
- mTextRows(),
- mCaretColumn(0),
- mCaretRow(0),
- mMinWidth(getWidth()),
- mEditable(true),
- mOpaque(Opaque_true)
-{
- mAllowLogic = false;
- setText("");
- setFocusable(true);
-
- addMouseListener(this);
- addKeyListener(this);
- adjustSize();
-
- mForegroundColor = getThemeColor(ThemeColorId::TEXTBOX);
- setOpaque(Opaque_false);
- setFrameSize(0);
-}
-
-TextBox::~TextBox()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-}
-
-void TextBox::setTextWrapped(const std::string &text, const int minDimension)
-{
- // Make sure parent scroll area sets width of this widget
- if (getParent() != nullptr)
- getParent()->logic();
-
- // Take the supplied minimum dimension as a starting
- // point and try to beat it
- mMinWidth = minDimension;
-
- const size_t textSize = text.size();
- size_t spacePos = text.rfind(' ', textSize);
-
- if (spacePos != std::string::npos)
- {
- const std::string word = text.substr(spacePos + 1);
- const int length = getFont()->getWidth(word);
-
- if (length > mMinWidth)
- mMinWidth = length;
- }
-
- std::stringstream wrappedStream;
- size_t newlinePos;
- size_t lastNewlinePos = 0;
- int minWidth = 0;
- int xpos;
-
- do
- {
- // Determine next piece of string to wrap
- newlinePos = text.find('\n', lastNewlinePos);
-
- if (newlinePos == std::string::npos)
- newlinePos = textSize;
-
- std::string line =
- text.substr(lastNewlinePos, newlinePos - lastNewlinePos);
- size_t lastSpacePos = 0;
- xpos = 0;
- const Font *const font = getFont();
- const int spaceWidth = font->getWidth(" ");
- size_t sz = line.size();
-
- do
- {
- spacePos = line.find(' ', lastSpacePos);
-
- if (spacePos == std::string::npos)
- spacePos = sz;
-
- const std::string word =
- line.substr(lastSpacePos, spacePos - lastSpacePos);
-
- const int width = font->getWidth(word);
-
- if (xpos == 0 && width > mMinWidth)
- {
- mMinWidth = width;
- xpos = width;
- wrappedStream << word;
- }
- else if (xpos != 0 && xpos + spaceWidth + width <=
- mMinWidth)
- {
- xpos += spaceWidth + width;
- wrappedStream << " " << word;
- }
- else if (lastSpacePos == 0)
- {
- xpos += width;
- wrappedStream << word;
- }
- else
- {
- if (xpos > minWidth)
- minWidth = xpos;
-
- // The window wasn't big enough. Resize it and try again.
- if (minWidth > mMinWidth)
- {
- mMinWidth = minWidth;
- wrappedStream.clear();
- wrappedStream.str("");
- lastNewlinePos = 0;
- newlinePos = text.find('\n', lastNewlinePos);
- if (newlinePos == std::string::npos)
- newlinePos = textSize;
- line = text.substr(lastNewlinePos, newlinePos -
- lastNewlinePos);
- sz = line.size();
- break;
- }
- else
- {
- wrappedStream << "\n" << word;
- }
- xpos = width;
- }
- lastSpacePos = spacePos + 1;
- }
- while (spacePos != sz);
-
- if (text.find('\n', lastNewlinePos) != std::string::npos)
- wrappedStream << "\n";
-
- lastNewlinePos = newlinePos + 1;
- }
- while (newlinePos != textSize);
-
- if (xpos > minWidth)
- minWidth = xpos;
-
- mMinWidth = minWidth;
-
- setText(wrappedStream.str());
-}
-
-void TextBox::setText(const std::string& text)
-{
- mCaretColumn = 0;
- mCaretRow = 0;
-
- mTextRows.clear();
- if (text.empty())
- {
- adjustSize();
- return;
- }
-
- size_t pos;
- size_t lastPos = 0;
- int length;
- do
- {
- pos = text.find('\n', lastPos);
-
- if (pos != std::string::npos)
- length = CAST_S32(pos - lastPos);
- else
- length = CAST_S32(text.size() - lastPos);
- std::string sub = text.substr(lastPos, length);
- mTextRows.push_back(sub);
- lastPos = pos + 1;
- } while (pos != std::string::npos);
-
- adjustSize();
-}
-
-void TextBox::keyPressed(KeyEvent& event)
-{
- const Key &key = event.getKey();
- const InputActionT action = event.getActionId();
-
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (action)
- {
- case InputAction::GUI_LEFT:
- {
- --mCaretColumn;
- if (mCaretColumn < 0)
- {
- --mCaretRow;
-
- if (mCaretRow < 0)
- {
- mCaretRow = 0;
- mCaretColumn = 0;
- }
- else
- {
- mCaretColumn = CAST_S32(
- mTextRows[mCaretRow].size());
- }
- }
- break;
- }
-
- case InputAction::GUI_RIGHT:
- {
- ++mCaretColumn;
- if (mCaretColumn > CAST_S32(mTextRows[mCaretRow].size()))
- {
- ++ mCaretRow;
-
- const int sz = CAST_S32(mTextRows.size());
- if (mCaretRow >= sz)
- {
- mCaretRow = sz - 1;
- if (mCaretRow < 0)
- mCaretRow = 0;
-
- mCaretColumn = CAST_S32(
- mTextRows[mCaretRow].size());
- }
- else
- {
- mCaretColumn = 0;
- }
- }
- break;
- }
-
- case InputAction::GUI_DOWN:
- {
- setCaretRow(mCaretRow + 1);
- break;
- }
- case InputAction::GUI_UP:
- {
- setCaretRow(mCaretRow - 1);
- break;
- }
- case InputAction::GUI_HOME:
- {
- mCaretColumn = 0;
- break;
- }
- case InputAction::GUI_END:
- {
- mCaretColumn = CAST_S32(mTextRows[mCaretRow].size());
- break;
- }
-
- case InputAction::GUI_SELECT2:
- {
- if (mEditable)
- {
- mTextRows.insert(mTextRows.begin() + mCaretRow + 1,
- mTextRows[mCaretRow].substr(mCaretColumn,
- mTextRows[mCaretRow].size() - mCaretColumn));
- mTextRows[mCaretRow].resize(mCaretColumn);
- ++mCaretRow;
- mCaretColumn = 0;
- }
- break;
- }
-
- case InputAction::GUI_BACKSPACE:
- {
- if (mCaretColumn != 0 && mEditable)
- {
- mTextRows[mCaretRow].erase(mCaretColumn - 1, 1);
- --mCaretColumn;
- }
- else if (mCaretColumn == 0 && mCaretRow != 0 && mEditable)
- {
- mCaretColumn = CAST_S32(
- mTextRows[mCaretRow - 1].size());
- mTextRows[mCaretRow - 1] += mTextRows[mCaretRow];
- mTextRows.erase(mTextRows.begin() + mCaretRow);
- --mCaretRow;
- }
- break;
- }
-
- case InputAction::GUI_DELETE:
- {
- if (mCaretColumn < CAST_S32(
- mTextRows[mCaretRow].size()) && mEditable)
- {
- mTextRows[mCaretRow].erase(mCaretColumn, 1);
- }
- else if (mCaretColumn == CAST_S32(
- mTextRows[mCaretRow].size()) &&
- mCaretRow < (CAST_S32(mTextRows.size()) - 1) &&
- mEditable)
- {
- mTextRows[mCaretRow] += mTextRows[mCaretRow + 1];
- mTextRows.erase(mTextRows.begin() + mCaretRow + 1);
- }
- break;
- }
-
- case InputAction::GUI_PAGE_UP:
- {
- Widget *const par = getParent();
-
- if (par != nullptr)
- {
- const int rowsPerPage = par->getChildrenArea().height
- / getFont()->getHeight();
- mCaretRow -= rowsPerPage;
-
- if (mCaretRow < 0)
- mCaretRow = 0;
- }
- break;
- }
-
- case InputAction::GUI_PAGE_DOWN:
- {
- Widget *const par = getParent();
-
- if (par != nullptr)
- {
- const int rowsPerPage = par->getChildrenArea().height
- / getFont()->getHeight();
- mCaretRow += rowsPerPage;
-
- const int sz = CAST_S32(mTextRows.size());
- if (mCaretRow >= sz)
- mCaretRow = sz - 1;
- }
- break;
- }
-
- case InputAction::GUI_TAB:
- {
- if (mEditable)
- {
- mTextRows[mCaretRow].insert(mCaretColumn, std::string(" "));
- mCaretColumn += 4;
- }
- break;
- }
-
- default:
- {
- if (key.isCharacter() && mEditable)
- {
- mTextRows[mCaretRow].insert(mCaretColumn,
- std::string(1, CAST_S8(key.getValue())));
- ++ mCaretColumn;
- }
- break;
- }
- }
- PRAGMA45(GCC diagnostic pop)
-
- adjustSize();
- scrollToCaret();
-
- event.consume();
-}
-
-void TextBox::draw(Graphics *const graphics)
-{
- BLOCK_START("TextBox::draw")
- if (mOpaque == Opaque_true)
- {
- graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(Rect(0, 0, getWidth(), getHeight()));
- }
-
- Font *const font = getFont();
- if (isFocused() && isEditable())
- {
- drawCaret(graphics, font->getWidth(
- mTextRows[mCaretRow].substr(0, mCaretColumn)),
- mCaretRow * font->getHeight());
- }
-
- const int fontHeight = font->getHeight();
-
- for (size_t i = 0, sz = mTextRows.size(); i < sz; i++)
- {
- // Move the text one pixel so we can have a caret before a letter.
- font->drawString(graphics,
- mForegroundColor,
- mForegroundColor2,
- mTextRows[i], 1,
- CAST_S32(i * CAST_SIZE(fontHeight)));
- }
- BLOCK_END("TextBox::draw")
-}
-
-void TextBox::safeDraw(Graphics *const graphics)
-{
- TextBox::draw(graphics);
-}
-
-void TextBox::setForegroundColor(const Color &color)
-{
- mForegroundColor = color;
- mForegroundColor2 = color;
-}
-
-void TextBox::setForegroundColorAll(const Color &color1,
- const Color &color2)
-{
- mForegroundColor = color1;
- mForegroundColor2 = color2;
-}
-
-std::string TextBox::getText() const
-{
- if (mTextRows.empty())
- return std::string();
-
- int i;
- std::string text;
-
- const int sz = CAST_S32(mTextRows.size());
- for (i = 0; i < sz - 1; ++ i)
- text.append(mTextRows[i]).append("\n");
- text.append(mTextRows[i]);
-
- return text;
-}
-
-void TextBox::setTextRow(const int row, const std::string& text)
-{
- mTextRows[row] = text;
-
- if (mCaretRow == row)
- setCaretColumn(mCaretColumn);
-
- adjustSize();
-}
-
-void TextBox::setCaretPosition(unsigned int position)
-{
- for (int row = 0, fsz = CAST_S32(mTextRows.size());
- row < fsz;
- row ++)
- {
- if (position <= mTextRows[row].size())
- {
- mCaretRow = row;
- mCaretColumn = position;
- return; // we are done
- }
-
- position--;
- }
-
- // position beyond end of text
- mCaretRow = CAST_S32(mTextRows.size() - 1);
- mCaretColumn = CAST_S32(mTextRows[mCaretRow].size());
-}
-
-void TextBox::setCaretRow(const int row)
-{
- mCaretRow = row;
-
- const int sz = CAST_S32(mTextRows.size());
- if (mCaretRow >= sz)
- mCaretRow = sz - 1;
-
- if (mCaretRow < 0)
- mCaretRow = 0;
-
- setCaretColumn(mCaretColumn);
-}
-
-unsigned int TextBox::getCaretPosition() const
-{
- int pos = 0, row;
-
- for (row = 0; row < mCaretRow; row++)
- pos += CAST_S32(mTextRows[row].size());
-
- return pos + mCaretColumn;
-}
-
-void TextBox::setCaretColumn(const int column)
-{
- mCaretColumn = column;
-
- const int sz = CAST_S32(mTextRows[mCaretRow].size());
- if (mCaretColumn > sz)
- mCaretColumn = sz;
-
- if (mCaretColumn < 0)
- mCaretColumn = 0;
-}
-
-void TextBox::setCaretRowColumn(const int row, const int column)
-{
- setCaretRow(row);
- setCaretColumn(column);
-}
-
-void TextBox::scrollToCaret()
-{
- const Font *const font = getFont();
- Rect scroll;
- scroll.x = font->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn));
- scroll.y = font->getHeight() * mCaretRow;
- scroll.width = font->getWidth(" ");
- // add 2 for some extra space
- scroll.height = font->getHeight() + 2;
- showPart(scroll);
-}
-
-void TextBox::addRow(const std::string &row)
-{
- mTextRows.push_back(row);
- adjustSize();
-}
-
-void TextBox::mousePressed(MouseEvent& event)
-{
- if (event.getButton() == MouseButton::LEFT)
- {
- const int height = getFont()->getHeight();
- if (height == 0)
- return;
-
- event.consume();
- mCaretRow = event.getY() / height;
-
- const int sz = CAST_S32(mTextRows.size());
- if (mCaretRow >= sz)
- mCaretRow = sz - 1;
-
- mCaretColumn = getFont()->getStringIndexAt(
- mTextRows[mCaretRow], event.getX());
- }
-}
-
-void TextBox::mouseDragged(MouseEvent& event)
-{
- event.consume();
-}
-
-void TextBox::drawCaret(Graphics *const graphics,
- const int x,
- const int y) const
-{
- graphics->setColor(mForegroundColor);
- graphics->drawLine(x, getFont()->getHeight() + y, x, y);
-}
-
-void TextBox::adjustSize()
-{
- int width = 0;
- const Font *const font = getFont();
- for (size_t i = 0, sz = mTextRows.size(); i < sz; ++i)
- {
- const int w = font->getWidth(mTextRows[i]);
- if (width < w)
- width = w;
- }
-
- setWidth(width + 1);
- setHeight(font->getHeight() * CAST_S32(mTextRows.size()));
-}
diff --git a/src/gui/widgets/textbox.h b/src/gui/widgets/textbox.h
deleted file mode 100644
index 6ce28ed4b..000000000
--- a/src/gui/widgets/textbox.h
+++ /dev/null
@@ -1,329 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_TEXTBOX_H
-#define GUI_WIDGETS_TEXTBOX_H
-
-#include "gui/widgets/widget.h"
-
-#include "enums/simpletypes/opaque.h"
-
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-
-#include "localconsts.h"
-
-/**
- * A text box, meant to be used inside a scroll area. Same as the Guichan text
- * box except this one doesn't have a background or border, instead completely
- * relying on the scroll area.
- *
- * \ingroup GUI
- */
-class TextBox final : public Widget,
- public MouseListener,
- public KeyListener
-{
- public:
- /**
- * Constructor.
- */
- explicit TextBox(const Widget2 *const widget);
-
- A_DELETE_COPY(TextBox)
-
- ~TextBox();
-
- /**
- * Sets the text after wrapping it to the current width of the widget.
- */
- void setTextWrapped(const std::string &text, const int minDimension);
-
- /**
- * Get the minimum text width for the text box.
- */
- int getMinWidth() const noexcept2 A_WARN_UNUSED
- { return mMinWidth; }
-
- void keyPressed(KeyEvent& event) override final;
-
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- void setForegroundColor(const Color &color);
-
- void setForegroundColorAll(const Color &color1,
- const Color &color2);
-
- /**
- * Sets the text of the text box.
- *
- * @param text The text of the text box.
- * @see getText
- */
- void setText(const std::string& text);
-
- /**
- * Gets the text of the text box.
- *
- * @return The text of the text box.
- * @see setText
- */
- std::string getText() const;
-
- /**
- * Gets a certain row from the text.
- *
- * @param row The number of the row to get from the text.
- * @return A row from the text of the text box.
- * @see setTextRow
- */
- const std::string& getTextRow(const int row) const
- { return mTextRows[row]; }
-
- /**
- * Sets the text of a certain row of the text.
- *
- * @param row The number of the row to set in the text.
- * @param text The text to set in the given row number.
- * @see getTextRow
- */
- void setTextRow(const int row, const std::string& text);
-
- /**
- * Gets the number of rows in the text.
- *
- * @return The number of rows in the text.
- */
- unsigned int getNumberOfRows() const
- { return CAST_S32(mTextRows.size()); }
-
- /**
- * Gets the caret position in the text.
- *
- * @return The caret position in the text.
- * @see setCaretPosition
- */
- unsigned int getCaretPosition() const;
-
- /**
- * Sets the position of the caret in the text.
- *
- * @param position the positon of the caret.
- * @see getCaretPosition
- */
- void setCaretPosition(unsigned int position);
-
- /**
- * Gets the row number where the caret is currently located.
- *
- * @return The row number where the caret is currently located.
- * @see setCaretRow
- */
- unsigned int getCaretRow() const
- { return mCaretRow; }
-
- /**
- * Sets the row where the caret should be currently located.
- *
- * @param The row where the caret should be currently located.
- * @see getCaretRow
- */
- void setCaretRow(const int row);
-
- /**
- * Gets the column where the caret is currently located.
- *
- * @return The column where the caret is currently located.
- * @see setCaretColumn
- */
- unsigned int getCaretColumn() const;
-
- /**
- * Sets the column where the caret should be currently located.
- *
- * @param The column where the caret should be currently located.
- * @see getCaretColumn
- */
- void setCaretColumn(const int column);
-
- /**
- * Sets the row and the column where the caret should be curretly
- * located.
- *
- * @param row The row where the caret should be currently located.
- * @param column The column where the caret should be currently located.
- * @see getCaretRow, getCaretColumn
- */
- void setCaretRowColumn(const int row, const int column);
-
- /**
- * Scrolls the text to the caret if the text box is in a scroll area.
- *
- * @see ScrollArea
- */
- void scrollToCaret();
-
- /**
- * Checks if the text box is editable.
- *
- * @return True it the text box is editable, false otherwise.
- * @see setEditable
- */
- bool isEditable() const
- { return mEditable; }
-
- /**
- * Sets the text box to be editable or not.
- *
- * @param editable True if the text box should be editable, false otherwise.
- */
- void setEditable(const bool editable)
- { mEditable = editable; }
-
- /**
- * Adds a row of text to the end of the text.
- *
- * @param row The row to add.
- */
- void addRow(const std::string &row);
-
- /**
- * Checks if the text box is opaque. An opaque text box will draw
- * it's background and it's text. A non opaque text box only draw it's
- * text making it transparent.
- *
- * @return True if the text box is opaque, false otherwise.
- * @see setOpaque
- */
- bool isOpaque() const noexcept2
- { return mOpaque == Opaque_true; }
-
- /**
- * Sets the text box to be opaque or not. An opaque text box will draw
- * it's background and it's text. A non opaque text box only draw it's
- * text making it transparent.
- *
- * @param opaque True if the text box should be opaque, false otherwise.
- * @see isOpaque
- */
- void setOpaque(const Opaque opaque) noexcept2
- { mOpaque = opaque; }
-
- void fontChanged() override final
- { adjustSize(); }
-
- void mousePressed(MouseEvent& event) override final;
-
- void mouseDragged(MouseEvent& event) override final;
-
- private:
- /**
- * Draws the caret. Overloaded this method if you want to
- * change the style of the caret.
- *
- * @param graphics a Graphics object to draw with.
- * @param x the x position.
- * @param y the y position.
- */
- void drawCaret(Graphics *const graphics,
- const int x,
- const int y) const A_NONNULL(2);
-
- /**
- * Adjusts the text box's size to fit the text.
- */
- void adjustSize();
-
- /**
- * Holds all the rows of the text.
- */
- STD_VECTOR<std::string> mTextRows;
-
- /**
- * Holds the current column of the caret.
- */
- int mCaretColumn;
-
- /**
- * Holds the current row of the caret.
- */
- int mCaretRow;
-
- int mMinWidth;
-
- /**
- * True if the text box is editable, false otherwise.
- */
- bool mEditable;
-
- /**
- * True if the text box is editable, false otherwise.
- */
- Opaque mOpaque;
-};
-
-#endif // GUI_WIDGETS_TEXTBOX_H
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
deleted file mode 100644
index e536b5b13..000000000
--- a/src/gui/widgets/textfield.cpp
+++ /dev/null
@@ -1,837 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/textfield.h"
-
-#include "settings.h"
-
-#ifdef USE_SDL2
-#include "enums/input/keyvalue.h"
-#endif // USE_SDL2
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-#ifdef ANDROID
-#include "gui/windowmanager.h"
-#endif // ANDROID
-
-#include "gui/fonts/font.h"
-
-#include "gui/popups/popupmenu.h"
-
-#include "input/inputmanager.h"
-
-#include "utils/copynpaste.h"
-#include "utils/stringutils.h"
-
-#ifndef USE_SDL2
-#include "utils/timer.h"
-#endif // USE_SDL2
-
-#include "render/graphics.h"
-
-#include "resources/imagerect.h"
-
-#include "resources/image/image.h"
-
-#undef DELETE // Win32 compatibility hack
-
-#include "debug.h"
-
-Skin *TextField::mSkin;
-int TextField::instances = 0;
-float TextField::mAlpha = 1.0;
-ImageRect TextField::skin;
-
-TextField::TextField(const Widget2 *restrict const widget,
- const std::string &restrict text,
- const LoseFocusOnTab loseFocusOnTab,
- ActionListener *restrict const listener,
- const std::string &restrict eventId,
- const bool sendAlwaysEvents) :
- Widget(widget),
- FocusListener(),
- KeyListener(),
- MouseListener(),
- WidgetListener(),
- mText(text),
- mTextChunk(),
- mCaretPosition(0),
- mXScroll(0),
- mCaretColor(&getThemeColor(ThemeColorId::CARET)),
- mMinimum(0),
- mMaximum(0),
- mLastEventPaste(0),
- mPadding(1),
- mNumeric(false),
- mLoseFocusOnTab(loseFocusOnTab),
- mAllowSpecialActions(true),
- mSendAlwaysEvents(sendAlwaysEvents),
- mTextChanged(true)
-{
- mAllowLogic = false;
- setFocusable(true);
- addMouseListener(this);
- addKeyListener(this);
-
- setFrameSize(2);
- mForegroundColor = getThemeColor(ThemeColorId::TEXTFIELD);
- mForegroundColor2 = getThemeColor(ThemeColorId::TEXTFIELD_OUTLINE);
-
- addFocusListener(this);
-
- if (instances == 0)
- {
- if (theme != nullptr)
- {
- mSkin = theme->loadSkinRect(skin, "textfield.xml",
- "textfield_background.xml");
- }
- }
-
- instances++;
-
- if (mSkin != nullptr)
- {
- mPadding = mSkin->getPadding();
- mFrameSize = mSkin->getOption("frameSize", 2);
- }
-
- adjustSize();
- if (!eventId.empty())
- setActionEventId(eventId);
-
- if (listener != nullptr)
- addActionListener(listener);
-}
-
-TextField::~TextField()
-{
- if (mWindow != nullptr)
- mWindow->removeWidgetListener(this);
-
- if (gui != nullptr)
- gui->removeDragged(this);
-
- instances--;
- if (instances == 0)
- {
- if (theme != nullptr)
- {
- theme->unload(mSkin);
- Theme::unloadRect(skin);
- }
- }
- mTextChunk.deleteImage();
-}
-
-void TextField::updateAlpha()
-{
- const float alpha = std::max(settings.guiAlpha,
- theme->getMinimumOpacity());
-
- if (alpha != mAlpha)
- {
- mAlpha = alpha;
- for (int a = 0; a < 9; a++)
- {
- if (skin.grid[a] != nullptr)
- skin.grid[a]->setAlpha(mAlpha);
- }
- }
-}
-
-void TextField::draw(Graphics *const graphics)
-{
- BLOCK_START("TextField::draw")
- updateAlpha();
-
- Font *const font = getFont();
- if (isFocused())
- {
- drawCaret(graphics,
- font->getWidth(mText.substr(0, mCaretPosition)) - mXScroll);
- }
-
- if (mTextChanged)
- {
- mTextChunk.textFont = font;
- mTextChunk.deleteImage();
- mTextChunk.text = mText;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- font->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, mPadding - mXScroll, mPadding);
-
- BLOCK_END("TextField::draw")
-}
-
-void TextField::safeDraw(Graphics *const graphics)
-{
- TextField::draw(graphics);
-}
-
-void TextField::drawFrame(Graphics *const graphics)
-{
- BLOCK_START("TextField::drawFrame")
- const int bs = 2 * mFrameSize;
- graphics->drawImageRect(0,
- 0,
- mDimension.width + bs,
- mDimension.height + bs,
- skin);
- BLOCK_END("TextField::drawFrame")
-}
-
-void TextField::safeDrawFrame(Graphics *const graphics)
-{
- BLOCK_START("TextField::drawFrame")
- const int bs = 2 * mFrameSize;
- graphics->drawImageRect(0,
- 0,
- mDimension.width + bs,
- mDimension.height + bs,
- skin);
- BLOCK_END("TextField::drawFrame")
-}
-
-void TextField::setNumeric(const bool numeric)
-{
- mNumeric = numeric;
- if (!numeric)
- return;
-
- const char *const text = mText.c_str();
- for (const char *textPtr = text; *textPtr != 0; ++textPtr)
- {
- if (*textPtr < '0' || *textPtr > '9')
- {
- setText(mText.substr(0, textPtr - text));
- return;
- }
- }
-}
-
-int TextField::getValue() const
-{
- if (!mNumeric)
- return 0;
-
- const int value = atoi(mText.c_str());
- if (value < mMinimum)
- return mMinimum;
-
- if (value > mMaximum)
- return mMaximum;
-
- return value;
-}
-
-void TextField::keyPressed(KeyEvent &event)
-{
- const int val = event.getKey().getValue();
-
-#ifdef USE_SDL2
- if (val == KeyValue::TEXTINPUT)
- {
- std::string str = event.getText();
- mText.insert(mCaretPosition, str);
- mTextChanged = true;
- mCaretPosition += CAST_U32(str.size());
- event.consume();
- fixScroll();
- if (mSendAlwaysEvents)
- distributeActionEvent();
- return;
- }
- bool consumed(false);
-#else // USE_SDL2
-
- if (val >= 32)
- {
- if (mNumeric)
- {
- if ((val >= '0' && val <= '9') ||
- (val == '-' && mCaretPosition == 0u))
- {
- char buf[2];
- buf[0] = CAST_8(val);
- buf[1] = 0;
- mText.insert(mCaretPosition, std::string(buf));
- mTextChanged = true;
- mCaretPosition += 1;
- event.consume();
- fixScroll();
- if (mSendAlwaysEvents)
- distributeActionEvent();
- return;
- }
- }
- else if ((mMaximum == 0) ||
- CAST_S32(mText.size()) < mMaximum)
- {
- int len;
- if (val < 128)
- len = 1; // 0xxxxxxx
- else if (val < 0x800)
- len = 2; // 110xxxxx 10xxxxxx
- else if (val < 0x10000)
- len = 3; // 1110xxxx 10xxxxxx 10xxxxxx
- else
- len = 4; // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
-
- char buf[4];
- for (int i = 0; i < len; ++ i)
- {
- buf[i] = CAST_8(val >> (6 * (len - i - 1)));
- if (i > 0)
- buf[i] = CAST_8((buf[i] & 63) | 128);
- }
-
- if (len > 1)
- buf[0] |= CAST_8(255U << (8 - len));
-
- mText.insert(mCaretPosition, std::string(buf, buf + len));
- mCaretPosition += len;
- mTextChanged = true;
- event.consume();
- fixScroll();
- if (mSendAlwaysEvents)
- distributeActionEvent();
- return;
- }
- }
-
- /* In UTF-8, 10xxxxxx is only used for inner parts of characters. So skip
- them when processing key presses. */
-
- // unblock past key
- if (val != 22)
- mLastEventPaste = 0;
-
- bool consumed(false);
-#endif // USE_SDL2
-
- const InputActionT action = event.getActionId();
- if (!inputManager.isActionActive(InputAction::GUI_CTRL))
- {
- if (!handleNormalKeys(action, consumed))
- {
- if (consumed)
- event.consume();
- return;
- }
- }
- else
- {
- handleCtrlKeys(action, consumed);
- }
-
- if (mSendAlwaysEvents)
- distributeActionEvent();
-
- if (consumed)
- event.consume();
- fixScroll();
-}
-
-bool TextField::handleNormalKeys(const InputActionT action, bool &consumed)
-{
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (action)
- {
- case InputAction::GUI_LEFT:
- {
- consumed = true;
- while (mCaretPosition > 0)
- {
- --mCaretPosition;
- if ((mText[mCaretPosition] & 192) != 128)
- break;
- }
- break;
- }
-
- case InputAction::GUI_RIGHT:
- {
- consumed = true;
- const unsigned sz = CAST_U32(mText.size());
- while (mCaretPosition < sz)
- {
- ++mCaretPosition;
- if (mCaretPosition == sz ||
- (mText[mCaretPosition] & 192) != 128)
- {
- break;
- }
- }
- break;
- }
-
- case InputAction::GUI_DELETE:
- {
- consumed = true;
- unsigned sz = CAST_U32(mText.size());
- while (mCaretPosition < sz)
- {
- --sz;
- mText.erase(mCaretPosition, 1);
- mTextChanged = true;
- if (mCaretPosition == sz ||
- (mText[mCaretPosition] & 192) != 128)
- {
- break;
- }
- }
- break;
- }
-
- case InputAction::GUI_BACKSPACE:
- consumed = true;
- deleteCharLeft(mText, &mCaretPosition);
- mTextChanged = true;
- break;
-
- case InputAction::GUI_SELECT2:
- distributeActionEvent();
- consumed = true;
- fixScroll();
- return false;
-
- case InputAction::GUI_HOME:
- mCaretPosition = 0;
- consumed = true;
- break;
-
- case InputAction::GUI_END:
- mCaretPosition = CAST_U32(mText.size());
- consumed = true;
- break;
-
- case InputAction::GUI_TAB:
- if (mLoseFocusOnTab == LoseFocusOnTab_true)
- return false;
- consumed = true;
- break;
-
- default:
- break;
- }
- PRAGMA45(GCC diagnostic pop)
- return true;
-}
-
-void TextField::handleCtrlKeys(const InputActionT action, bool &consumed)
-{
- PRAGMA45(GCC diagnostic push)
- PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
- switch (action)
- {
- case InputAction::GUI_LEFT:
- {
- moveCaretWordBack();
- consumed = true;
- break;
- }
- case InputAction::GUI_RIGHT:
- {
- moveCaretWordForward();
- consumed = true;
- break;
- }
- case InputAction::GUI_B:
- {
- if (mAllowSpecialActions)
- {
- moveCaretBack();
- consumed = true;
- }
- break;
- }
- case InputAction::GUI_F:
- {
- moveCaretForward();
- consumed = true;
- break;
- }
- case InputAction::GUI_D:
- {
- caretDelete();
- consumed = true;
- break;
- }
- case InputAction::GUI_E:
- {
- mCaretPosition = CAST_S32(mText.size());
- consumed = true;
- break;
- }
- case InputAction::GUI_H:
- {
- deleteCharLeft(mText, &mCaretPosition);
- mTextChanged = true;
- consumed = true;
- break;
- }
- case InputAction::GUI_K:
- {
- mText = mText.substr(0, mCaretPosition);
- mTextChanged = true;
- consumed = true;
- break;
- }
- case InputAction::GUI_U:
- {
- caretDeleteToStart();
- consumed = true;
- break;
- }
- case InputAction::GUI_C:
- {
- handleCopy();
- consumed = true;
- break;
- }
- case InputAction::GUI_V:
- {
-#ifdef USE_SDL2
- handlePaste();
-#else // USE_SDL2
-
- // hack to prevent paste key sticking
- if ((mLastEventPaste != 0) && mLastEventPaste > cur_time)
- break;
- handlePaste();
- mLastEventPaste = cur_time + 2;
-#endif // USE_SDL2
-
- consumed = true;
- break;
- }
- case InputAction::GUI_W:
- {
- caretDeleteWord();
- consumed = true;
- break;
- }
- default:
- break;
- }
- PRAGMA45(GCC diagnostic pop)
-}
-
-void TextField::moveCaretBack()
-{
- while (mCaretPosition > 0)
- {
- --mCaretPosition;
- if ((mText[mCaretPosition] & 192) != 128)
- break;
- }
-}
-
-void TextField::moveCaretForward()
-{
- const unsigned sz = CAST_U32(mText.size());
- while (mCaretPosition < sz)
- {
- ++mCaretPosition;
- if (mCaretPosition == sz || (mText[mCaretPosition] & 192) != 128)
- break;
- }
-}
-
-void TextField::caretDelete()
-{
- unsigned sz = CAST_U32(mText.size());
- while (mCaretPosition < sz)
- {
- --sz;
- mText.erase(mCaretPosition, 1);
- if (mCaretPosition == sz || (mText[mCaretPosition] & 192) != 128)
- break;
- }
- mTextChanged = true;
-}
-
-void TextField::handlePaste()
-{
- std::string text = getText();
- size_t caretPos = CAST_SIZE(getCaretPosition());
-
- if (retrieveBuffer(text, caretPos))
- {
- setText(text);
- setCaretPosition(CAST_U32(caretPos));
- }
-}
-
-void TextField::caretDeleteToStart()
-{
- if (mCaretPosition > 0)
- {
- mText = mText.substr(mCaretPosition);
- mCaretPosition = 0;
- }
- mTextChanged = true;
-}
-
-void TextField::moveCaretWordBack()
-{
- const unsigned int oldCaret = mCaretPosition;
- while (mCaretPosition > 0)
- {
- if (!isWordSeparator(mText[mCaretPosition - 1]))
- break;
- mCaretPosition --;
- }
- if (oldCaret != mCaretPosition)
- return;
- while (mCaretPosition > 0)
- {
- if (isWordSeparator(mText[mCaretPosition - 1]))
- break;
- mCaretPosition --;
- }
-}
-
-void TextField::moveCaretWordForward()
-{
- const unsigned sz = CAST_U32(mText.size());
- const unsigned int oldCaret = mCaretPosition;
- while (mCaretPosition < sz)
- {
- if (!isWordSeparator(mText[mCaretPosition]))
- break;
- mCaretPosition ++;
- }
- if (oldCaret != mCaretPosition)
- return;
- while (mCaretPosition < sz)
- {
- if (isWordSeparator(mText[mCaretPosition]))
- break;
- mCaretPosition ++;
- }
-}
-
-void TextField::caretDeleteWord()
-{
- while (mCaretPosition > 0)
- {
- deleteCharLeft(mText, &mCaretPosition);
- if (mCaretPosition > 0 && isWordSeparator(mText[mCaretPosition - 1]))
- break;
- }
- mTextChanged = true;
-}
-
-void TextField::handleCopy() const
-{
- std::string text = getText();
- sendBuffer(text);
-}
-
-void TextField::drawCaret(Graphics* graphics, int x)
-{
- const ClipRect &clipArea = graphics->getTopClip();
-
- graphics->setColor(*mCaretColor);
- graphics->drawLine(x + mPadding, clipArea.height - mPadding,
- x + mPadding, mPadding);
-}
-
-void TextField::adjustSize()
-{
- setWidth(getFont()->getWidth(mText) + 2 * mPadding + 1);
- adjustHeight();
-
- fixScroll();
-}
-
-void TextField::adjustHeight()
-{
- setHeight(getFont()->getHeight() + 2 * mPadding);
-}
-
-void TextField::fixScroll()
-{
- if (isFocused())
- {
- const int caretX = getFont()->getWidth(
- mText.substr(0, mCaretPosition));
-
- const int width = mDimension.width;
- const int pad = 2 * mPadding;
- if (caretX - mXScroll >= width - pad)
- {
- mXScroll = caretX - width + pad;
- }
- else if (caretX - mXScroll <= 0)
- {
- mXScroll = caretX - width / 2;
-
- if (mXScroll < 0)
- mXScroll = 0;
- }
- }
-}
-
-void TextField::setCaretPosition(unsigned int position)
-{
- const unsigned int sz = CAST_U32(mText.size());
- if (position > sz)
- mCaretPosition = CAST_S32(sz);
- else
- mCaretPosition = position;
-
- fixScroll();
-}
-
-void TextField::fontChanged()
-{
- fixScroll();
-}
-
-void TextField::mousePressed(MouseEvent &event)
-{
-#ifdef ANDROID
- if (!WindowManager::isKeyboardVisible())
- inputManager.executeAction(InputAction::SHOW_KEYBOARD);
-#endif // ANDROID
-
- event.consume();
- if (event.getButton() == MouseButton::RIGHT)
- {
-#ifndef DYECMD
- if (popupMenu != nullptr)
- popupMenu->showTextFieldPopup(this);
-#endif // DYECMD
- }
- else if (event.getButton() == MouseButton::LEFT)
- {
- mCaretPosition = getFont()->getStringIndexAt(
- mText, event.getX() + mXScroll);
- fixScroll();
- }
-}
-
-void TextField::focusGained(const Event &event A_UNUSED)
-{
-#ifdef ANDROID
- if (!WindowManager::isKeyboardVisible())
- inputManager.executeAction(InputAction::SHOW_KEYBOARD);
-#endif // ANDROID
-}
-
-void TextField::focusLost(const Event &event A_UNUSED)
-{
-}
-
-void TextField::setText(const std::string& text)
-{
- const unsigned int sz = CAST_U32(text.size());
- if (sz < mCaretPosition)
- mCaretPosition = sz;
- mText = text;
- mTextChanged = true;
-}
-
-void TextField::mouseDragged(MouseEvent& event)
-{
- event.consume();
-}
-
-void TextField::widgetHidden(const Event &event A_UNUSED)
-{
- mTextChanged = true;
- mTextChunk.deleteImage();
-}
-
-void TextField::setParent(Widget *widget)
-{
- if (mWindow != nullptr)
- mWindow->addWidgetListener(this);
- Widget::setParent(widget);
-}
-
-void TextField::setWindow(Widget *const widget)
-{
- if ((widget == nullptr) && (mWindow != nullptr))
- {
- mWindow->removeWidgetListener(this);
- mWindow = nullptr;
- }
- else
- {
- Widget2::setWindow(widget);
- }
-}
diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h
deleted file mode 100644
index 8001008a1..000000000
--- a/src/gui/widgets/textfield.h
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_TEXTFIELD_H
-#define GUI_WIDGETS_TEXTFIELD_H
-
-#include "listeners/focuslistener.h"
-#include "listeners/keylistener.h"
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "enums/simpletypes/losefocusontab.h"
-
-#include "gui/fonts/textchunk.h"
-
-#include "gui/widgets/widget.h"
-
-#include "localconsts.h"
-
-/**
- * A text field.
- *
- * \ingroup GUI
- */
-class TextField notfinal : public Widget,
- public FocusListener,
- public KeyListener,
- public MouseListener,
- public WidgetListener
-{
- public:
- /**
- * Constructor, initializes the text field with the given string.
- */
- explicit TextField(const Widget2 *restrict const widget,
- const std::string &restrict text = "",
- const LoseFocusOnTab loseFocusOnTab =
- LoseFocusOnTab_true,
- ActionListener *restrict
- const listener = nullptr,
- const std::string &restrict eventId = "",
- const bool sendAlwaysEvents = false);
-
- A_DELETE_COPY(TextField)
-
- virtual ~TextField();
-
- /**
- * Draws the text field.
- */
- void draw(Graphics *const graphics) override A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override A_NONNULL(2);
-
- /**
- * Update the alpha value to the graphic components.
- */
- void updateAlpha();
-
- /**
- * Draws the background and border.
- */
- void drawFrame(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDrawFrame(Graphics *const graphics) override final
- A_NONNULL(2);
-
- /**
- * Determine whether the field should be numeric or not
- */
- void setNumeric(const bool numeric);
-
- /**
- * Set the range on the field if it is numeric
- */
- void setRange(const int min,
- const int max)
- {
- mMinimum = min;
- mMaximum = max;
- }
-
- /**
- * Processes one keypress.
- */
- void keyPressed(KeyEvent &event) override;
-
- /**
- * Set the minimum value for a range
- */
- void setMinimum(const int min)
- { mMinimum = min; }
-
- /**
- * Set the maximum value for a range
- */
- void setMaximum(const int max)
- { mMaximum = max; }
-
- /**
- * Return the value for a numeric field
- */
- int getValue() const A_WARN_UNUSED;
-
- void setSendAlwaysEvents(const bool b) noexcept2
- { mSendAlwaysEvents = b; }
-
- void adjustSize();
-
- void adjustHeight();
-
- void setCaretPosition(unsigned int position);
-
- void mousePressed(MouseEvent &event) override final;
-
- void handlePaste();
-
- void handleCopy() const;
-
-#ifdef ANDROID
- void focusGained(const Event &event) override final;
-#else // ANDROID
-
- void focusGained(const Event &event) override final A_CONST;
-#endif // ANDROID
-
- void focusLost(const Event &event) override A_CONST;
-
- void moveCaretBack();
-
- void moveCaretForward();
-
- void moveCaretWordBack();
-
- void moveCaretWordForward();
-
- void caretDelete();
-
- void caretDeleteToStart();
-
- void caretDeleteWord();
-
- void setAllowSpecialActions(const bool b)
- { mAllowSpecialActions = b; }
-
- std::string getTextBeforeCaret() const
- { return mText.substr(0, mCaretPosition); }
-
- /**
- * Sets the text of the text field.
- *
- * @param text The text of the text field.
- * @see getText
- */
- void setText(const std::string& text);
-
- /**
- * Gets the text of the text field.
- *
- * @return The text of the text field.
- * @see setText
- */
- const std::string& getText() const
- { return mText; }
-
- /**
- * Gets the caret position. As there is only one line of text
- * in a text field the position is the caret's x coordinate.
- *
- * @return The caret position.
- * @see setCaretPosition
- */
- unsigned int getCaretPosition() const
- { return mCaretPosition; }
-
- void mouseDragged(MouseEvent& event) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void setParent(Widget *widget) override final;
-
- void setWindow(Widget *const widget) override final;
-
- protected:
- void drawCaret(Graphics* graphics, int x) A_NONNULL(2);
-
- void fixScroll();
-
- void fontChanged() override;
-
- bool handleNormalKeys(const InputActionT action, bool &consumed);
-
- void handleCtrlKeys(const InputActionT action, bool &consumed);
-
- static Skin *mSkin;
-
- /**
- * Holds the text of the text box.
- */
- std::string mText;
-
- TextChunk mTextChunk;
-
- /**
- * Holds the caret position.
- */
- unsigned int mCaretPosition;
-
- /**
- * Holds the amount scrolled in x. If a user types more characters than
- * the text field can display, due to the text field being to small, the
- * text needs to scroll in order to show the last type character.
- */
- int mXScroll;
-
- const Color *mCaretColor;
- static int instances;
- static float mAlpha;
- static ImageRect skin;
- int mMinimum;
- int mMaximum;
- time_t mLastEventPaste;
- int mPadding;
- bool mNumeric;
- LoseFocusOnTab mLoseFocusOnTab;
- bool mAllowSpecialActions;
- bool mSendAlwaysEvents;
- bool mTextChanged;
-};
-
-#endif // GUI_WIDGETS_TEXTFIELD_H
diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp
deleted file mode 100644
index 53f84badc..000000000
--- a/src/gui/widgets/textpreview.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2006-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/textpreview.h"
-
-#include "settings.h"
-
-#include "gui/gui.h"
-#include "gui/skin.h"
-
-#include "gui/fonts/font.h"
-
-#include "render/graphics.h"
-
-#include "debug.h"
-
-int TextPreview::instances = 0;
-float TextPreview::mAlpha = 1.0;
-Skin *TextPreview::mSkin = nullptr;
-
-TextPreview::TextPreview(const Widget2 *const widget,
- const std::string &text) :
- Widget(widget),
- mFont(gui->getFont()),
- mText(text),
- mTextColor(&getThemeColor(ThemeColorId::TEXT)),
- mTextColor2(&getThemeColor(ThemeColorId::TEXT_OUTLINE)),
- mBGColor(&getThemeColor(ThemeColorId::BACKGROUND)),
- mTextBGColor(nullptr),
- mPadding(0),
- mTextAlpha(false),
- mOpaque(Opaque_false),
- mShadow(false),
- mOutline(false)
-{
- mAllowLogic = false;
- if (instances == 0)
- {
- if (theme != nullptr)
- mSkin = theme->load("textpreview.xml", "");
- }
-
- instances++;
-
- if (mSkin != nullptr)
- mPadding = mSkin->getOption("padding", 0);
-
- adjustSize();
-}
-
-TextPreview::~TextPreview()
-{
- if (gui != nullptr)
- gui->removeDragged(this);
-
- instances--;
-
- if (instances == 0)
- {
- if (theme != nullptr)
- theme->unload(mSkin);
- }
-}
-
-void TextPreview::draw(Graphics *const graphics)
-{
- if (mFont == nullptr)
- return;
-
- BLOCK_START("TextPreview::draw")
- if (settings.guiAlpha != mAlpha)
- mAlpha = settings.guiAlpha;
-
- const int intAlpha = CAST_S32(mAlpha * 255.0F);
- const int alpha = mTextAlpha ? intAlpha : 255;
-
- if (mOpaque == Opaque_true)
- {
- graphics->setColor(Color(CAST_S32(mBGColor->r),
- CAST_S32(mBGColor->g),
- CAST_S32(mBGColor->b),
- CAST_S32(mAlpha * 255.0F)));
- graphics->fillRectangle(Rect(0, 0,
- mDimension.width, mDimension.height));
- }
-
- if (mTextBGColor != nullptr)
- {
- const int x = mFont->getWidth(mText) + 1
- + 2 * ((mOutline || mShadow) ? 1 :0);
- const int y = mFont->getHeight() + 1
- + 2 * ((mOutline || mShadow) ? 1 : 0);
- graphics->setColor(Color(CAST_S32(mTextBGColor->r),
- CAST_S32(mTextBGColor->g),
- CAST_S32(mTextBGColor->b),
- intAlpha));
- graphics->fillRectangle(Rect(mPadding, mPadding, x, y));
- }
-
- Color color1(mTextColor->r, mTextColor->g, mTextColor->b, alpha);
-
- if (mOutline && mTextColor != mTextColor2)
- {
- const Color &color2 = getThemeColor(ThemeColorId::OUTLINE, 255);
- mFont->drawString(graphics,
- color1,
- color2,
- mText,
- mPadding + 1, mPadding + 1);
- }
- else
- {
- Color color2(mTextColor2->r, mTextColor2->g, mTextColor2->b, alpha);
- mFont->drawString(graphics,
- color1,
- color2,
- mText,
- mPadding + 1, mPadding + 1);
- }
-
- BLOCK_END("TextPreview::draw")
-}
-
-void TextPreview::safeDraw(Graphics *const graphics)
-{
- TextPreview::draw(graphics);
-}
-
-void TextPreview::adjustSize()
-{
- setHeight(getFont()->getHeight() + 2 * mPadding);
-}
diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h
deleted file mode 100644
index 7f4a5e873..000000000
--- a/src/gui/widgets/textpreview.h
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2006-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_TEXTPREVIEW_H
-#define GUI_WIDGETS_TEXTPREVIEW_H
-
-#include "gui/widgets/widget.h"
-
-#include "enums/simpletypes/opaque.h"
-
-#include "localconsts.h"
-
-/**
- * Preview widget for particle colors, etc.
- */
-class TextPreview final : public Widget
-{
- public:
- TextPreview(const Widget2 *const widget,
- const std::string &text);
-
- A_DELETE_COPY(TextPreview)
-
- ~TextPreview();
-
- inline void setTextColor(const Color *color)
- { mTextColor = color; adjustSize(); }
-
- inline void setTextColor2(const Color *color)
- { mTextColor2 = color; adjustSize(); }
-
- /**
- * Sets the text to use the set alpha value.
- *
- * @param alpha whether to use alpha values for the text or not
- */
- inline void useTextAlpha(const bool alpha)
- { mTextAlpha = alpha; }
-
- /**
- * Sets the color the text background is drawn in. This is only the
- * rectangle directly behind the text, not to full widget.
- *
- * @param color the color to set
- */
- inline void setTextBGColor(const Color *color)
- { mTextBGColor = color; }
-
- /**
- * Sets the background color of the widget.
- *
- * @param color the color to set
- */
- inline void setBGColor(const Color *color)
- { mBGColor = color; }
-
- /**
- * Sets the font to render the text in.
- *
- * @param font the font to use.
- */
- inline void setFont(Font *const font)
- { mFont = font; }
-
- /**
- * Sets whether to use a shadow while rendering.
- *
- * @param shadow true, if a shadow is wanted, false else
- */
- inline void setShadow(const bool shadow)
- { mShadow = shadow; }
-
- /**
- * Sets whether to use an outline while rendering.
- *
- * @param outline true, if an outline is wanted, false else
- */
- inline void setOutline(const bool outline)
- { mOutline = outline; }
-
- /**
- * Widget's draw method. Does the actual job.
- *
- * @param graphics graphics to draw into
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Set opacity for this widget (whether or not to show the background
- * color)
- *
- * @param opaque Whether the widget should be opaque or not
- */
- void setOpaque(const Opaque opaque) noexcept2
- { mOpaque = opaque; }
-
- /**
- * Gets opacity for this widget (whether or not the background color
- * is shown below the widget)
- */
- bool isOpaque() const noexcept2 A_WARN_UNUSED
- { return mOpaque == Opaque_true; }
-
- void adjustSize();
-
- private:
- Font *mFont;
- std::string mText;
- const Color *mTextColor;
- const Color *mTextColor2;
- const Color *mBGColor;
- const Color *mTextBGColor;
- int mPadding;
- static int instances;
- static float mAlpha;
- static Skin *mSkin;
- bool mTextAlpha;
- Opaque mOpaque;
- bool mShadow;
- bool mOutline;
-};
-
-#endif // GUI_WIDGETS_TEXTPREVIEW_H
diff --git a/src/gui/widgets/vertcontainer.cpp b/src/gui/widgets/vertcontainer.cpp
deleted file mode 100644
index 53e082501..000000000
--- a/src/gui/widgets/vertcontainer.cpp
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/vertcontainer.h"
-
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-VertContainer::VertContainer(const Widget2 *const widget,
- const int verticalItemSize,
- const bool resizable,
- const int leftSpacing) :
- Container(widget),
- WidgetListener(),
- mResizableWidgets(),
- mVerticalItemSize(verticalItemSize),
- mCount(0),
- mNextY(0),
- mLeftSpacing(leftSpacing),
- mVerticalSpacing(0),
- mResizable(resizable)
-{
- addWidgetListener(this);
-}
-
-void VertContainer::add1(Widget *const widget, const int spacing)
-{
- add2(widget, mResizable, spacing);
-}
-
-void VertContainer::add2(Widget *const widget, const bool resizable,
- const int spacing)
-{
- if (widget == nullptr)
- return;
-
- Container::add(widget);
- widget->setPosition(mLeftSpacing, mNextY);
- if (resizable)
- {
- widget->setSize(mDimension.width - mLeftSpacing,
- mVerticalItemSize * 5);
- mResizableWidgets.push_back(widget);
- }
- else if (widget->getHeight() > mVerticalItemSize)
- {
- widget->setSize(widget->getWidth(), mVerticalItemSize);
- }
-
- if (spacing == -1)
- mNextY += mVerticalItemSize + (mVerticalSpacing * 2);
- else
- mNextY += mVerticalItemSize + (spacing * 2);
- setHeight(mNextY);
-}
-
-void VertContainer::clear()
-{
- Container::clear();
-
- mCount = 0;
- mNextY = 0;
- mResizableWidgets.clear();
-}
-
-void VertContainer::widgetResized(const Event &event A_UNUSED)
-{
- FOR_EACH (STD_VECTOR<Widget*>::const_iterator, it, mResizableWidgets)
- (*it)->setWidth(getWidth());
-}
diff --git a/src/gui/widgets/vertcontainer.h b/src/gui/widgets/vertcontainer.h
deleted file mode 100644
index c0dd118cf..000000000
--- a/src/gui/widgets/vertcontainer.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_VERTCONTAINER_H
-#define GUI_WIDGETS_VERTCONTAINER_H
-
-#include "gui/widgets/container.h"
-
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-/**
- * A widget container.
- *
- * This container places it's contents veritcally.
- */
-class VertContainer final : public Container,
- public WidgetListener
-{
- public:
- VertContainer(const Widget2 *const widget,
- const int verticalItemSize,
- const bool resizable = true,
- const int leftSpacing = 0);
-
- A_DELETE_COPY(VertContainer)
-
- void add2(Widget *const widget, const bool resizable,
- const int spacing = -1);
-
- void add1(Widget *const widget, const int spacing = -1);
-
- void clear() override final;
-
- void widgetResized(const Event &event) override final;
-
- private:
- STD_VECTOR<Widget*> mResizableWidgets;
- int mVerticalItemSize;
- int mCount;
- int mNextY;
- int mLeftSpacing;
- int mVerticalSpacing;
- bool mResizable;
-};
-
-#endif // GUI_WIDGETS_VERTCONTAINER_H
diff --git a/src/gui/widgets/virtshortcutcontainer.cpp b/src/gui/widgets/virtshortcutcontainer.cpp
deleted file mode 100644
index 6b7642a3d..000000000
--- a/src/gui/widgets/virtshortcutcontainer.cpp
+++ /dev/null
@@ -1,383 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/virtshortcutcontainer.h"
-
-#include "dragdrop.h"
-#include "settings.h"
-
-#include "being/playerinfo.h"
-
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/shortcut/shortcutbase.h"
-
-#include "gui/popups/itempopup.h"
-#include "gui/popups/popupmenu.h"
-
-#include "gui/windows/inventorywindow.h"
-
-#include "utils/stringutils.h"
-
-#include "debug.h"
-
-VirtShortcutContainer::VirtShortcutContainer(Widget2 *const widget,
- ShortcutBase *const shortcut) :
- ShortcutContainer(widget),
- mItemClicked(false),
- mEquipedColor(getThemeColor(ThemeColorId::ITEM_EQUIPPED)),
- mEquipedColor2(getThemeColor(ThemeColorId::ITEM_EQUIPPED_OUTLINE)),
- mUnEquipedColor(getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED)),
- mUnEquipedColor2(getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED_OUTLINE)),
- mShortcut(shortcut)
-{
- if (mShortcut != nullptr)
- mMaxItems = mShortcut->getItemCount();
- else
- mMaxItems = 0;
-}
-
-VirtShortcutContainer::~VirtShortcutContainer()
-{
-}
-
-void VirtShortcutContainer::setWidget2(const Widget2 *const widget)
-{
- Widget2::setWidget2(widget);
- mEquipedColor = getThemeColor(ThemeColorId::ITEM_EQUIPPED);
- mEquipedColor2 = getThemeColor(ThemeColorId::ITEM_EQUIPPED_OUTLINE);
- mUnEquipedColor = getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED);
- mUnEquipedColor2 = getThemeColor(ThemeColorId::ITEM_NOT_EQUIPPED_OUTLINE);
-}
-
-void VirtShortcutContainer::draw(Graphics *const graphics)
-{
- if (mShortcut == nullptr)
- return;
-
- BLOCK_START("VirtShortcutContainer::draw")
- if (settings.guiAlpha != mAlpha)
- {
- mAlpha = settings.guiAlpha;
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- }
-
- drawBackground(graphics);
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- {
- BLOCK_END("VirtShortcutContainer::draw")
- return;
- }
-
- Font *const font = getFont();
-
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int itemX = (i % mGridWidth) * mBoxWidth;
- const int itemY = (i / mGridWidth) * mBoxHeight;
-
- if (mShortcut->getItem(i) < 0)
- continue;
-
- const Item *const item = inv->findItem(mShortcut->getItem(i),
- mShortcut->getItemColor(i));
-
- if (item != nullptr)
- {
- // Draw item icon.
- Image *const image = item->getImage();
-
- if (image != nullptr)
- {
- std::string caption;
- if (item->getQuantity() > 1)
- caption = toString(item->getQuantity());
- else if (item->isEquipped() == Equipped_true)
- caption = "Eq.";
-
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- if (item->isEquipped() == Equipped_true)
- {
- font->drawString(graphics,
- mEquipedColor,
- mEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- else
- {
- font->drawString(graphics,
- mUnEquipedColor,
- mUnEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- }
- }
- }
- BLOCK_END("VirtShortcutContainer::draw")
-}
-
-void VirtShortcutContainer::safeDraw(Graphics *const graphics)
-{
- if (mShortcut == nullptr)
- return;
-
- BLOCK_START("VirtShortcutContainer::safeDraw")
- if (settings.guiAlpha != mAlpha)
- {
- mAlpha = settings.guiAlpha;
- if (mBackgroundImg != nullptr)
- mBackgroundImg->setAlpha(mAlpha);
- }
-
- safeDrawBackground(graphics);
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- {
- BLOCK_END("VirtShortcutContainer::safeDraw")
- return;
- }
-
- Font *const font = getFont();
-
- for (unsigned i = 0; i < mMaxItems; i++)
- {
- const int itemX = (i % mGridWidth) * mBoxWidth;
- const int itemY = (i / mGridWidth) * mBoxHeight;
-
- if (mShortcut->getItem(i) < 0)
- continue;
-
- const Item *const item = inv->findItem(mShortcut->getItem(i),
- mShortcut->getItemColor(i));
-
- if (item != nullptr)
- {
- // Draw item icon.
- Image *const image = item->getImage();
-
- if (image != nullptr)
- {
- std::string caption;
- if (item->getQuantity() > 1)
- caption = toString(item->getQuantity());
- else if (item->isEquipped() == Equipped_true)
- caption = "Eq.";
-
- image->setAlpha(1.0F);
- graphics->drawImage(image, itemX, itemY);
- if (item->isEquipped() == Equipped_true)
- {
- font->drawString(graphics,
- mEquipedColor,
- mEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- else
- {
- font->drawString(graphics,
- mUnEquipedColor,
- mUnEquipedColor2,
- caption,
- itemX + (mBoxWidth - font->getWidth(caption)) / 2,
- itemY + mBoxHeight - 14);
- }
- }
- }
- }
- BLOCK_END("VirtShortcutContainer::safeDraw")
-}
-
-void VirtShortcutContainer::mouseDragged(MouseEvent &event)
-{
- if (mShortcut == nullptr)
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- if (dragDrop.isEmpty() && mItemClicked)
- {
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- const int itemId = mShortcut->getItem(index);
- const ItemColor itemColor = mShortcut->getItemColor(index);
-
- if (itemId < 0)
- return;
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- Item *const item = inv->findItem(itemId, itemColor);
-
- if (item != nullptr)
- {
- dragDrop.dragItem(item, DragDropSource::Drop);
- mShortcut->removeItem(index);
- }
- else
- {
- dragDrop.clear();
- }
- }
- }
-}
-
-void VirtShortcutContainer::mousePressed(MouseEvent &event)
-{
- if ((mShortcut == nullptr) || (inventoryWindow == nullptr))
- return;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- event.consume();
-
- const MouseButtonT eventButton = event.getButton();
- if (eventButton == MouseButton::LEFT)
- {
- if (mShortcut->getItem(index) > 0)
- {
- mItemClicked = true;
- }
- else
- {
- if (dragDrop.isSelected())
- {
- mShortcut->setItems(index, dragDrop.getSelected(),
- dragDrop.getSelectedColor());
- dragDrop.deselect();
- }
- }
- }
- else if (eventButton == MouseButton::RIGHT)
- {
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- Item *const item = inv->findItem(mShortcut->getItem(index),
- mShortcut->getItemColor(index));
-
- if (popupMenu != nullptr)
- {
- popupMenu->showDropPopup(viewport->mMouseX,
- viewport->mMouseY,
- item);
- }
- }
-}
-
-void VirtShortcutContainer::mouseReleased(MouseEvent &event)
-{
- if (mShortcut == nullptr)
- return;
-
- if (event.getButton() == MouseButton::LEFT)
- {
- if (mShortcut->isItemSelected())
- mShortcut->setItemSelected(-1);
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
- if (index == -1)
- {
- dragDrop.clear();
- return;
- }
- if (!dragDrop.isEmpty())
- {
- if (dragDrop.isSourceItemContainer())
- {
- mShortcut->setItems(index, dragDrop.getItem(),
- dragDrop.getItemColor());
- dragDrop.clear();
- dragDrop.deselect();
- }
- }
-
- mItemClicked = false;
- }
-}
-
-// Show ItemTooltip
-void VirtShortcutContainer::mouseMoved(MouseEvent &event)
-{
- if (mShortcut == nullptr)
- return;
-
- const int index = getIndexFromGrid(event.getX(), event.getY());
-
- if (index == -1)
- return;
-
- const int itemId = mShortcut->getItem(index);
- const ItemColor itemColor = mShortcut->getItemColor(index);
-
- if (itemId < 0)
- return;
-
- const Inventory *const inv = PlayerInfo::getInventory();
- if (inv == nullptr)
- return;
-
- const Item *const item = inv->findItem(itemId, itemColor);
-
- if ((item != nullptr) && (viewport != nullptr))
- {
- itemPopup->setItem(item, false);
- itemPopup->position(viewport->mMouseX, viewport->mMouseY);
- }
- else
- {
- itemPopup->setVisible(Visible_false);
- }
-}
-
-void VirtShortcutContainer::mouseExited(MouseEvent &event A_UNUSED)
-{
- if (itemPopup != nullptr)
- itemPopup->setVisible(Visible_false);
-}
-
-void VirtShortcutContainer::widgetHidden(const Event &event A_UNUSED)
-{
- if (itemPopup != nullptr)
- itemPopup->setVisible(Visible_false);
-}
diff --git a/src/gui/widgets/virtshortcutcontainer.h b/src/gui/widgets/virtshortcutcontainer.h
deleted file mode 100644
index 989a6c8d7..000000000
--- a/src/gui/widgets/virtshortcutcontainer.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2009 The Mana World Development Team
- * Copyright (C) 2009-2010 Andrei Karas
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_VIRTSHORTCUTCONTAINER_H
-#define GUI_WIDGETS_VIRTSHORTCUTCONTAINER_H
-
-#include "gui/widgets/shortcutcontainer.h"
-
-class ShortcutBase;
-
-/**
- * An item shortcut container. Used to quickly use items.
- *
- * \ingroup GUI
- */
-class VirtShortcutContainer final : public ShortcutContainer
-{
- public:
- /**
- * Constructor. Initializes the graphic.
- */
- VirtShortcutContainer(Widget2 *const widget,
- ShortcutBase *const shortcut);
-
- A_DELETE_COPY(VirtShortcutContainer)
-
- /**
- * Destructor.
- */
- ~VirtShortcutContainer();
-
- /**
- * Draws the items.
- */
- void draw(Graphics *const graphics) override final A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
-
- /**
- * Handles mouse when dragged.
- */
- void mouseDragged(MouseEvent &event) override final;
-
- /**
- * Handles mouse when pressed.
- */
- void mousePressed(MouseEvent &event) override final;
-
- /**
- * Handles mouse release.
- */
- void mouseReleased(MouseEvent &event) override final;
-
- void widgetHidden(const Event &event) override final;
-
- void mouseExited(MouseEvent &event) override final;
-
- void mouseMoved(MouseEvent &event) override final;
-
- void setWidget2(const Widget2 *const widget) override final;
-
- private:
- bool mItemClicked;
-
- Color mEquipedColor;
- Color mEquipedColor2;
- Color mUnEquipedColor;
- Color mUnEquipedColor2;
-
- ShortcutBase *mShortcut;
-};
-
-#endif // GUI_WIDGETS_VIRTSHORTCUTCONTAINER_H
diff --git a/src/gui/widgets/widget.cpp b/src/gui/widgets/widget.cpp
deleted file mode 100644
index 47bca1fb3..000000000
--- a/src/gui/widgets/widget.cpp
+++ /dev/null
@@ -1,526 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * For comments regarding functions please see the header file.
- */
-
-#include "gui/widgets/widget.h"
-
-#include "gui/focushandler.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/widgetdeathlistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-Font* Widget::mGlobalFont = nullptr;
-std::list<Widget*> Widget::mAllWidgets;
-std::set<Widget*> Widget::mAllWidgetsSet;
-
-Widget::Widget(const Widget2 *const widget) :
- Widget2(widget),
- mVisible(Visible_true),
- mMouseListeners(),
- mKeyListeners(),
- mActionListeners(),
- mDeathListeners(),
- mFocusListeners(),
- mWidgetListeners(),
- mForegroundColor(0x000000),
- mBackgroundColor(0xffffff),
- mBaseColor(0x808090),
- mDimension(),
- mActionEventId(),
- mId(),
- mFocusHandler(nullptr),
- mInternalFocusHandler(nullptr),
- mParent(nullptr),
- mCurrentFont(nullptr),
- mFrameSize(0),
- mFocusable(false),
- mTabIn(true),
- mTabOut(true),
- mEnabled(true),
- mAllowLogic(true),
- mMouseConsume(true),
- mRedraw(true),
- mSelectable(true)
-{
- mAllWidgets.push_back(this);
- mAllWidgetsSet.insert(this);
-}
-
-Widget::~Widget()
-{
- FOR_EACH (WidgetDeathListenerIterator, iter, mDeathListeners)
- {
- Event event(this);
- (*iter)->death(event);
- }
-
- // +++ call to virtual member
- setFocusHandler(nullptr);
-
- mAllWidgets.remove(this);
- mAllWidgetsSet.erase(this);
-}
-
-void Widget::setWidth(const int width)
-{
- Rect newDimension = mDimension;
- newDimension.width = width;
- setDimension(newDimension);
-}
-
-void Widget::setHeight(const int height)
-{
- Rect newDimension = mDimension;
- newDimension.height = height;
- setDimension(newDimension);
-}
-
-void Widget::setX(const int x)
-{
- Rect newDimension = mDimension;
- newDimension.x = x;
- setDimension(newDimension);
-}
-
-void Widget::setY(const int y)
-{
- Rect newDimension = mDimension;
- newDimension.y = y;
- setDimension(newDimension);
-}
-
-void Widget::setPosition(const int x, const int y)
-{
- Rect newDimension = mDimension;
- newDimension.x = x;
- newDimension.y = y;
- setDimension(newDimension);
-}
-
-void Widget::setDimension(const Rect& dimension)
-{
- const Rect oldDimension = mDimension;
- mDimension = dimension;
-
- if (mDimension.width != oldDimension.width
- || mDimension.height != oldDimension.height)
- {
- distributeResizedEvent();
- }
-
- if (mDimension.x != oldDimension.x || mDimension.y != oldDimension.y)
- distributeMovedEvent();
-}
-
-bool Widget::isFocused() const
-{
- if (mFocusHandler == nullptr)
- return false;
-
- return mFocusHandler->isFocused(this);
-}
-
-void Widget::setFocusable(const bool focusable)
-{
- if (!focusable && isFocused() && (mFocusHandler != nullptr))
- mFocusHandler->focusNone();
- mFocusable = focusable;
-}
-
-bool Widget::isFocusable() const
-{
- return mFocusable && isVisible() && isEnabled();
-}
-
-void Widget::requestFocus()
-{
- if (mFocusHandler == nullptr)
- return;
-
- if (isFocusable())
- mFocusHandler->requestFocus(this);
-}
-
-void Widget::requestMoveToTop()
-{
- if (mParent != nullptr)
- mParent->moveToTop(this);
-}
-
-void Widget::requestMoveToBottom()
-{
- if (mParent != nullptr)
- mParent->moveToBottom(this);
-}
-
-void Widget::setVisible(Visible visible)
-{
- if (visible == Visible_false && isFocused() && (mFocusHandler != nullptr))
- mFocusHandler->focusNone();
-
- if (visible == Visible_true)
- distributeShownEvent();
- else
- distributeHiddenEvent();
-
- mVisible = visible;
-}
-
-void Widget::setFocusHandler(FocusHandler *const focusHandler)
-{
- if (mFocusHandler != nullptr)
- {
- releaseModalFocus();
- mFocusHandler->remove(this);
- }
-
- if (focusHandler != nullptr)
- focusHandler->add(this);
-
- mFocusHandler = focusHandler;
-}
-
-void Widget::addActionListener(ActionListener *const actionListener)
-{
- mActionListeners.push_back(actionListener);
-}
-
-void Widget::removeActionListener(ActionListener *const actionListener)
-{
- mActionListeners.remove(actionListener);
-}
-
-void Widget::addDeathListener(WidgetDeathListener *const deathListener)
-{
- mDeathListeners.push_back(deathListener);
-}
-
-void Widget::removeDeathListener(WidgetDeathListener *const deathListener)
-{
- mDeathListeners.remove(deathListener);
-}
-
-void Widget::addKeyListener(KeyListener *const keyListener)
-{
- mKeyListeners.push_back(keyListener);
-}
-
-void Widget::removeKeyListener(KeyListener *const keyListener)
-{
- mKeyListeners.remove(keyListener);
-}
-
-void Widget::addFocusListener(FocusListener *const focusListener)
-{
- mFocusListeners.push_back(focusListener);
-}
-
-void Widget::removeFocusListener(FocusListener *const focusListener)
-{
- mFocusListeners.remove(focusListener);
-}
-
-void Widget::addMouseListener(MouseListener *const mouseListener)
-{
- mMouseListeners.push_back(mouseListener);
-}
-
-void Widget::removeMouseListener(MouseListener *const mouseListener)
-{
- mMouseListeners.remove(mouseListener);
-}
-
-void Widget::addWidgetListener(WidgetListener *const widgetListener)
-{
- mWidgetListeners.push_back(widgetListener);
-}
-
-void Widget::removeWidgetListener(WidgetListener *const widgetListener)
-{
- mWidgetListeners.remove(widgetListener);
-}
-
-void Widget::getAbsolutePosition(int& x, int& y) const
-{
- if (mParent == nullptr)
- {
- x = mDimension.x;
- y = mDimension.y;
- return;
- }
-
- int parentX;
- int parentY;
-
- mParent->getAbsolutePosition(parentX, parentY);
-
- const Rect &rect = mParent->getChildrenArea();
- x = parentX + mDimension.x + rect.x;
- y = parentY + mDimension.y + rect.y;
-}
-
-Font* Widget::getFont() const
-{
- if (mCurrentFont == nullptr)
- return mGlobalFont;
- return mCurrentFont;
-}
-
-void Widget::setGlobalFont(Font *const font)
-{
- mGlobalFont = font;
-
- FOR_EACH (std::list<Widget*>::const_iterator, iter, mAllWidgets)
- {
- if ((*iter)->mCurrentFont == nullptr)
- (*iter)->fontChanged();
- }
-}
-
-void Widget::setFont(Font *const font)
-{
- mCurrentFont = font;
- fontChanged();
-}
-
-void Widget::distributeWindowResizeEvent()
-{
- FOR_EACH (std::list<Widget*>::const_iterator, iter, mAllWidgets)
- (*iter)->windowResized();
-}
-
-bool Widget::widgetExists(const Widget *const widget)
-{
- return mAllWidgetsSet.find(const_cast<Widget*>(widget))
- != mAllWidgetsSet.end();
-}
-
-void Widget::setSize(const int width, const int height)
-{
- Rect newDimension = mDimension;
- newDimension.width = width;
- newDimension.height = height;
- setDimension(newDimension);
-}
-
-bool Widget::isEnabled() const
-{
- return mEnabled && isVisible();
-}
-
-void Widget::requestModalFocus()
-{
- if (mFocusHandler == nullptr)
- return;
- mFocusHandler->requestModalFocus(this);
-}
-
-void Widget::requestModalMouseInputFocus()
-{
- if (mFocusHandler == nullptr)
- return;
- mFocusHandler->requestModalMouseInputFocus(this);
-}
-
-void Widget::releaseModalFocus()
-{
- if (mFocusHandler == nullptr)
- return;
- mFocusHandler->releaseModalFocus(this);
-}
-
-void Widget::releaseModalMouseInputFocus()
-{
- if (mFocusHandler == nullptr)
- return;
- mFocusHandler->releaseModalMouseInputFocus(this);
-}
-
-bool Widget::isModalFocused() const
-{
- if (mFocusHandler == nullptr)
- return false;
-
- if (mParent != nullptr)
- {
- return (mFocusHandler->getModalFocused() == this)
- || mParent->isModalFocused();
- }
-
- return mFocusHandler->getModalFocused() == this;
-}
-
-bool Widget::isModalMouseInputFocused() const
-{
- if (mFocusHandler == nullptr)
- return false;
-
- if (mParent != nullptr)
- {
- return (mFocusHandler->getModalMouseInputFocused() == this)
- || mParent->isModalMouseInputFocused();
- }
-
- return mFocusHandler->getModalMouseInputFocused() == this;
-}
-
-const std::list<MouseListener*> &Widget::getMouseListeners() const
-{
- return mMouseListeners;
-}
-
-const std::list<KeyListener*> &Widget::getKeyListeners() const
-{
- return mKeyListeners;
-}
-
-const std::list<FocusListener*> &Widget::getFocusListeners() const
-{
- return mFocusListeners;
-}
-
-Rect Widget::getChildrenArea()
-{
- return Rect(0, 0, 0, 0);
-}
-
-FocusHandler* Widget::getInternalFocusHandler()
-{
- return mInternalFocusHandler;
-}
-
-void Widget::setInternalFocusHandler(FocusHandler *const focusHandler)
-{
- mInternalFocusHandler = focusHandler;
-}
-
-void Widget::distributeResizedEvent()
-{
- FOR_EACH (WidgetListenerIterator, iter, mWidgetListeners)
- {
- Event event(this);
- (*iter)->widgetResized(event);
- }
-}
-
-void Widget::distributeMovedEvent()
-{
- FOR_EACH (WidgetListenerIterator, iter, mWidgetListeners)
- {
- Event event(this);
- (*iter)->widgetMoved(event);
- }
-}
-
-void Widget::distributeHiddenEvent()
-{
- FOR_EACH (WidgetListenerIterator, iter, mWidgetListeners)
- {
- Event event(this);
- (*iter)->widgetHidden(event);
- }
-}
-
-void Widget::distributeActionEvent()
-{
- FOR_EACH (ActionListenerIterator, iter, mActionListeners)
- {
- ActionEvent actionEvent(this, mActionEventId);
- (*iter)->action(actionEvent);
- }
-}
-
-void Widget::distributeShownEvent()
-{
- FOR_EACH (WidgetListenerIterator, iter, mWidgetListeners)
- {
- Event event(this);
- (*iter)->widgetShown(event);
- }
-}
-
-void Widget::showPart(const Rect &rectangle)
-{
- if (mParent != nullptr)
- mParent->showWidgetPart(this, rectangle);
-}
-
-void Widget::windowResized()
-{
- mRedraw = true;
-}
-
-Widget *Widget::callPostInit(Widget *const widget)
-{
- if (widget != nullptr)
- widget->postInit();
- return widget;
-}
diff --git a/src/gui/widgets/widget.h b/src/gui/widgets/widget.h
deleted file mode 100644
index bb41054d2..000000000
--- a/src/gui/widgets/widget.h
+++ /dev/null
@@ -1,1181 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_WIDGET_H
-#define GUI_WIDGETS_WIDGET_H
-
-#include "enums/simpletypes/visible.h"
-
-#include "gui/rect.h"
-
-#include "gui/widgets/widget2.h"
-
-#include <list>
-
-#include "localconsts.h"
-
-class ActionListener;
-class WidgetDeathListener;
-class FocusHandler;
-class FocusListener;
-class Font;
-class Graphics;
-class KeyListener;
-class MouseListener;
-class WidgetListener;
-
-/**
- * Abstract class for widgets of Guichan. It contains basic functions
- * every widget should have.
- *
- * NOTE: Functions begining with underscore "_" should not
- * be overloaded unless you know what you are doing
- *
- * @author Olof Naessén
- * @author Per Larsson.
- */
-class Widget notfinal : 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
- * focusable should overide this default in their own constructor.
- */
- explicit Widget(const Widget2 *const widget);
-
- A_DELETE_COPY(Widget)
-
- /**
- * Default destructor.
- */
- virtual ~Widget();
-
- /**
- * Draws the widget. It is called by the parent widget when it is time
- * for the widget to draw itself. The graphics object is set up so
- * that all drawing is relative to the widget, i.e coordinate (0,0) is
- * the top left corner of the widget. It is not possible to draw
- * outside of a widget's dimension.
- *
- * @param graphics aA graphics object to draw with.
- */
- virtual void draw(Graphics *const graphics) A_NONNULL(2) = 0;
-
- virtual void safeDraw(Graphics *const graphics) A_NONNULL(2) = 0;
-
- /**
- * Called when a widget is given a chance to draw a frame around itself.
- * The frame is not considered a part of the widget, it only allows a frame
- * to be drawn around the widget, thus a frame will never be included when
- * calculating if a widget should receive events from user input. Also
- * a widget's frame will never be included when calculating a widget's
- * position.
- *
- * The size of the frame is calculated using the widget's frame size.
- * If a widget has a frame size of 10 pixels than the area the drawFrame
- * function can draw to will be the size of the widget with an additional
- * extension of 10 pixels in each direction.
- *
- * An example when drawFrame is a useful function is if a widget needs
- * a glow around itself.
- *
- * @param graphics A graphics object to draw with.
- * @see setFrameSize, getFrameSize
- */
- virtual void drawFrame(Graphics* graphics A_UNUSED) A_NONNULL(2)
- { }
-
- virtual void safeDrawFrame(Graphics* graphics A_UNUSED) A_NONNULL(2)
- { }
-
- /**
- * Sets the size of the widget's frame. The frame is not considered a part of
- * the widget, it only allows a frame to be drawn around the widget, thus a frame
- * will never be included when calculating if a widget should receive events
- * from user input. Also a widget's frame will never be included when calculating
- * a widget's position.
- *
- * A frame size of 0 means that the widget has no frame. The default frame size
- * is 0.
- *
- * @param frameSize The size of the widget's frame.
- * @see getFrameSize, drawFrame
- */
- void setFrameSize(const unsigned int frameSize) noexcept2
- { mFrameSize = frameSize; }
-
- /**
- * Gets the size of the widget's frame. The frame is not considered a part of
- * the widget, it only allows a frame to be drawn around the widget, thus a frame
- * will never be included when calculating if a widget should receive events
- * from user input. Also a widget's frame will never be included when calculating
- * a widget's position.
- *
- * A frame size of 0 means that the widget has no frame. The default frame size
- * is 0.
- *
- * @return The size of the widget's frame.
- * @see setFrameSize, drawFrame
- */
- unsigned int getFrameSize() const noexcept2 A_WARN_UNUSED
- { return mFrameSize; }
-
- /**
- * Called for all widgets in the gui each time Gui::logic is called.
- * You can do logic stuff here like playing an animation.
- *
- * @see Gui::logic
- */
- virtual void logic()
- { }
-
- /**
- * Gets the widget's parent container.
- *
- * @return The widget's parent container. NULL if the widget
- * has no parent.
- */
- Widget* getParent() const noexcept2 A_WARN_UNUSED
- { return mParent; }
-
- /**
- * Sets the width of the widget.
- *
- * @param width The width of the widget.
- * @see getWidth, setHeight, getHeight, setSize,
- * setDimension, getDimensi
- */
- void setWidth(const int width);
-
- /**
- * Gets the width of the widget.
- *
- * @return The width of the widget.
- * @see setWidth, setHeight, getHeight, setSize,
- * setDimension, getDimension
- */
- int getWidth() const noexcept2 A_WARN_UNUSED
- { return mDimension.width; }
-
- /**
- * Sets the height of the widget.
- *
- * @param height The height of the widget.
- * @see getHeight, setWidth, getWidth, setSize,
- * setDimension, getDimension
- */
- void setHeight(const int height);
-
- /**
- * Gets the height of the widget.
- *
- * @return The height of the widget.
- * @see setHeight, setWidth, getWidth, setSize,
- * setDimension, getDimension
- */
- int getHeight() const noexcept2 A_WARN_UNUSED
- { return mDimension.height; }
-
- /**
- * Sets the size of the widget.
- *
- * @param width The width of the widget.
- * @param height The height of the widget.
- * @see setWidth, setHeight, getWidth, getHeight,
- * setDimension, getDimension
- */
- void setSize(const int width, const int height);
-
- /**
- * Sets the x coordinate of the widget. The coordinate is
- * relateive to the widget's parent.
- *
- * @param x The x coordinate of the widget.
- * @see getX, setY, getY, setPosition, setDimension, getDimension
- */
- void setX(const int x);
-
- /**
- * Gets the x coordinate of the widget. The coordinate is
- * relative to the widget's parent.
- *
- * @return The x coordinate of the widget.
- * @see setX, setY, getY, setPosition, setDimension, getDimension
- */
- int getX() const noexcept2 A_WARN_UNUSED
- { return mDimension.x; }
-
- /**
- * Sets the y coordinate of the widget. The coordinate is
- * relative to the widget's parent.
- *
- * @param y The y coordinate of the widget.
- * @see setY, setX, getX, setPosition, setDimension, getDimension
- */
- void setY(const int y);
-
- /**
- * Gets the y coordinate of the widget. The coordinate is
- * relative to the widget's parent.
- *
- * @return The y coordinate of the widget.
- * @see setY, setX, getX, setPosition, setDimension, getDimension
- */
- int getY() const noexcept2 A_WARN_UNUSED
- { return mDimension.y; }
-
- /**
- * Sets position of the widget. The position is relative
- * to the widget's parent.
- *
- * @param x The x coordinate of the widget.
- * @param y The y coordinate of the widget.
- * @see setX, getX, setY, getY, setDimension, getDimension
- */
- void setPosition(const int x, const int y);
-
- /**
- * Sets the dimension of the widget. The dimension is
- * relative to the widget's parent.
- *
- * @param dimension The dimension of the widget.
- * @see getDimension, setX, getX, setY, getY, setPosition
- */
- void setDimension(const Rect& dimension);
-
- /**
- * Gets the dimension of the widget. The dimension is
- * relative to the widget's parent.
- *
- * @return The dimension of the widget.
- * @see getDimension, setX, getX, setY, getY, setPosition
- */
- const Rect& getDimension() const noexcept2 A_WARN_UNUSED
- { return mDimension; }
-
- /**
- * Sets the widget to be fosusable, or not.
- *
- * @param focusable True if the widget should be focusable,
- * false otherwise.
- * @see isFocusable
- */
- void setFocusable(const bool focusable);
-
- /**
- * Checks if a widget is focsable.
- *
- * @return True if the widget should be focusable, false otherwise.
- * @see setFocusable
- */
- bool isFocusable() const A_WARN_UNUSED;
-
- /**
- * Checks if the widget is focused.
- *
- * @return True if the widget is focused, false otherwise.
- */
- virtual bool isFocused() const A_WARN_UNUSED;
-
- /**
- * Sets the widget to enabled, or not. A disabled
- * widget will never recieve mouse or key events.
- *
- * @param enabled True if widget should be enabled,
- * false otherwise.
- * @see isEnabled
- */
- void setEnabled(const bool enabled) noexcept2
- { mEnabled = enabled; }
-
- /**
- * Checks if the widget is enabled. A disabled
- * widget will never recieve mouse or key events.
- *
- * @return True if widget is enabled, false otherwise.
- * @see setEnabled
- */
- bool isEnabled() const A_WARN_UNUSED;
-
- /**
- * Sets the widget to be visible, or not.
- *
- * @param visible True if widget should be visible, false otherwise.
- * @see isVisible
- */
- void setVisible(Visible visible);
-
- /**
- * Checks if the widget is visible.
- *
- * @return True if widget is be visible, false otherwise.
- * @see setVisible
- */
- bool isVisible() const A_WARN_UNUSED
- {
- return mVisible == Visible_true &&
- ((mParent == nullptr) || mParent->isVisible());
- }
-
- /**
- * Sets the base color of the widget.
- *
- * @param color The baseground color.
- * @see getBaseColor
- */
- void setBaseColor(const Color& color) noexcept2
- { mBaseColor = color; }
-
- /**
- * Gets the base color.
- *
- * @return The base color.
- * @see setBaseColor
- */
- const Color& getBaseColor() const noexcept2 A_WARN_UNUSED
- { return mBaseColor; }
-
- /**
- * Sets the foreground color.
- *
- * @param color The foreground color.
- * @see getForegroundColor
- */
- void setForegroundColor(const Color& color) noexcept2
- { mForegroundColor = color; }
-
- /**
- * Gets the foreground color.
- *
- * @see setForegroundColor
- */
- const Color& getForegroundColor() const noexcept2 A_WARN_UNUSED
- { return mForegroundColor; }
-
- /**
- * Sets the background color.
- *
- * @param color The background Color.
- * @see setBackgroundColor
- */
- void setBackgroundColor(const Color &color) noexcept2
- { mBackgroundColor = color; }
-
- /**
- * Gets the background color.
- *
- * @see setBackgroundColor
- */
- const Color &getBackgroundColor() const noexcept2 A_WARN_UNUSED
- { return mBackgroundColor; }
-
- /**
- * Requests focus for the widget. A widget will only recieve focus
- * if it is focusable.
- */
- virtual void requestFocus();
-
- /**
- * Requests a move to the top in the parent widget.
- */
- virtual void requestMoveToTop();
-
- /**
- * Requests a move to the bottom in the parent widget.
- */
- virtual void requestMoveToBottom();
-
- /**
- * Sets the focus handler to be used.
- *
- * WARNING: This function is used internally and should not
- * be called or overloaded unless you know what you
- * are doing.
- *
- * @param focusHandler The focus handler to use.
- * @see getFocusHandler
- */
- virtual void setFocusHandler(FocusHandler *const focusHandler);
-
- /**
- * Gets the focus handler used.
- *
- * WARNING: This function is used internally and should not
- * be called or overloaded unless you know what you
- * are doing.
- *
- * @return The focus handler used.
- * @see setFocusHandler
- */
- FocusHandler* getFocusHandler() noexcept2 A_WARN_UNUSED
- { return mFocusHandler; }
-
- /**
- * Adds an action listener to the widget. When an action event
- * is fired by the widget the action listeners of the widget
- * will get notified.
- *
- * @param actionListener The action listener to add.
- * @see removeActionListener
- */
- void addActionListener(ActionListener *const actionListener);
-
- /**
- * Removes an added action listener from the widget.
- *
- * @param actionListener The action listener to remove.
- * @see addActionListener
- */
- void removeActionListener(ActionListener *const actionListener);
-
- /**
- * Adds a death listener to the widget. When a death event is
- * fired by the widget the death listeners of the widget will
- * get notified.
- *
- * @param deathListener The death listener to add.
- * @see removeDeathListener
- */
- void addDeathListener(WidgetDeathListener *const deathListener);
-
- /**
- * Removes an added death listener from the widget.
- *
- * @param deathListener The death listener to remove.
- * @see addDeathListener
- */
- void removeDeathListener(WidgetDeathListener *const deathListener);
-
- /**
- * Adds a mouse listener to the widget. When a mouse event is
- * fired by the widget the mouse listeners of the widget will
- * get notified.
- *
- * @param mouseListener The mouse listener to add.
- * @see removeMouseListener
- */
- void addMouseListener(MouseListener *const mouseListener);
-
- /**
- * Removes an added mouse listener from the widget.
- *
- * @param mouseListener The mouse listener to remove.
- * @see addMouseListener
- */
- void removeMouseListener(MouseListener *const mouseListener);
-
- /**
- * Adds a key listener to the widget. When a key event is
- * fired by the widget the key listeners of the widget will
- * get notified.
- *
- * @param keyListener The key listener to add.
- * @see removeKeyListener
- */
- void addKeyListener(KeyListener *const keyListener);
-
- /**
- * Removes an added key listener from the widget.
- *
- * @param keyListener The key listener to remove.
- * @see addKeyListener
- */
- void removeKeyListener(KeyListener *const keyListener);
-
- /**
- * Adds a focus listener to the widget. When a focus event is
- * fired by the widget the key listeners of the widget will
- * get notified.
- *
- * @param focusListener The focus listener to add.
- * @see removeFocusListener
- */
- void addFocusListener(FocusListener *const focusListener);
-
- /**
- * Removes an added focus listener from the widget.
- *
- * @param focusListener The focus listener to remove.
- * @see addFocusListener
- */
- void removeFocusListener(FocusListener *const focusListener);
-
- /**
- * Adds a widget listener to the widget. When a widget event is
- * fired by the widget the key listeners of the widget will
- * get notified.
- *
- * @param widgetListener The widget listener to add.
- * @see removeWidgetListener
- */
- void addWidgetListener(WidgetListener *const widgetListener);
-
- /**
- * Removes an added widget listener from the widget.
- *
- * @param widgetListener The widget listener to remove.
- * @see addWidgetListener
- */
- void removeWidgetListener(WidgetListener *const widgetListener);
-
- /**
- * Sets the action event identifier of the widget. The identifier is
- * used to be able to identify which action has occured.
- *
- * NOTE: An action event identifier should not be used to identify a
- * certain widget but rather a certain event in your application.
- * Several widgets can have the same action event identifer.
- *
- * @param actionEventId The action event identifier.
- * @see getActionEventId
- */
- void setActionEventId(const std::string &actionEventId) noexcept2
- { mActionEventId = actionEventId; }
-
- /**
- * Gets the action event identifier of the widget.
- *
- * @return The action event identifier of the widget.
- * @see setActionEventId
- */
- const std::string &getActionEventId() const noexcept2
- { return mActionEventId; }
-
- /**
- * Gets the absolute position on the screen for the widget.
- *
- * @param x The absolute x coordinate will be stored in this parameter.
- * @param y The absolute y coordinate will be stored in this parameter.
- */
- virtual void getAbsolutePosition(int& x, int& y) const;
-
- /**
- * Sets the parent of the widget. A parent must be a BasicContainer.
- *
- * WARNING: This function is used internally and should not
- * be called or overloaded unless you know what you
- * are doing.
- *
- * @param parent The parent of the widget.
- * @see getParent
- */
- virtual void setParent(Widget* parent)
- { mParent = parent; }
-
- /**
- * Gets the font set for the widget. If no font has been set,
- * the global font will be returned. If no global font has been set,
- * the default font will be returend.
- *
- * @return The font set for the widget.
- * @see setFont, setGlobalFont
- */
- Font *getFont() const RETURNS_NONNULL A_WARN_UNUSED;
-
- /**
- * Sets the global font to be used by default for all widgets.
- *
- * @param font The global font.
- * @see getGlobalFont
- */
- static void setGlobalFont(Font *const font);
-
- static Font *getGloablFont()
- { return mGlobalFont; }
-
- static void cleanGlobalFont()
- { mGlobalFont = nullptr; }
-
- /**
- * Sets the font for the widget. If NULL is passed, the global font
- * will be used.
- *
- * @param font The font to set for the widget.
- * @see getFont
- */
- void setFont(Font *const font);
-
- /**
- * Called when the font has changed. If the change is global,
- * this function will only be called if the widget doesn't have a
- * font already set.
- */
- virtual void fontChanged()
- { }
-
- /**
- * Checks if a widget exists or not, that is if it still exists
- * an instance of the object.
- *
- * @param widget The widget to check.
- * @return True if an instance of the widget exists, false otherwise.
- */
- static bool widgetExists(const Widget *const widget) A_WARN_UNUSED;
-
- /**
- * Checks if tab in is enabled. Tab in means that you can set focus
- * to this widget by pressing the tab button. If tab in is disabled
- * then the focus handler will skip this widget and focus the next
- * in its focus order.
- *
- * @return True if tab in is enabled, false otherwise.
- * @see setTabInEnabled
- */
- bool isTabInEnabled() const noexcept2 A_WARN_UNUSED
- { return mTabIn; }
-
- /**
- * Sets tab in enabled, or not. Tab in means that you can set focus
- * to this widget by pressing the tab button. If tab in is disabled
- * then the FocusHandler will skip this widget and focus the next
- * in its focus order.
- *
- * @param enabled True if tab in should be enabled, false otherwise.
- * @see isTabInEnabled
- */
- void setTabInEnabled(const bool enabled) noexcept2
- { mTabIn = enabled; }
-
- /**
- * Checks if tab out is enabled. Tab out means that you can lose
- * focus to this widget by pressing the tab button. If tab out is
- * disabled then the FocusHandler ignores tabbing and focus will
- * stay with this widget.
- *
- * @return True if tab out is enabled, false otherwise.
- * @see setTabOutEnabled
- */
- bool isTabOutEnabled() const noexcept2 A_WARN_UNUSED
- { return mTabOut; }
-
- /**
- * Sets tab out enabled. Tab out means that you can lose
- * focus to this widget by pressing the tab button. If tab out is
- * disabled then the FocusHandler ignores tabbing and focus will
- * stay with this widget.
- *
- * @param enabled True if tab out should be enabled, false otherwise.
- * @see isTabOutEnabled
- */
- void setTabOutEnabled(const bool enabled) noexcept2
- { mTabOut = enabled; }
-
- /**
- * Requests modal focus. When a widget has modal focus, only that
- * widget and it's children may recieve input.
- *
- * @throws Exception if another widget already has modal focus.
- * @see releaseModalFocus, isModalFocused
- */
- void requestModalFocus();
-
- /**
- * Requests modal mouse input focus. When a widget has modal input focus
- * that widget will be the only widget receiving input even if the input
- * occurs outside of the widget and no matter what the input is.
- *
- * @throws Exception if another widget already has modal focus.
- * @see releaseModalMouseInputFocus, isModalMouseInputFocused
- */
- virtual void requestModalMouseInputFocus();
-
- /**
- * Releases modal focus. Modal focus will only be released if the
- * widget has modal focus.
- *
- * @see requestModalFocus, isModalFocused
- */
- virtual void releaseModalFocus();
-
- /**
- * Releases modal mouse input focus. Modal mouse input focus will only
- * be released if the widget has modal mouse input focus.
- *
- * @see requestModalMouseInputFocus, isModalMouseInputFocused
- */
- virtual void releaseModalMouseInputFocus();
-
- /**
- * Checks if the widget or it's parent has modal focus.
- *
- * @return True if the widget has modal focus, false otherwise.
- * @see requestModalFocus, releaseModalFocus
- */
- virtual bool isModalFocused() const A_WARN_UNUSED;
-
- /**
- * Checks if the widget or it's parent has modal mouse input focus.
- *
- * @return True if the widget has modal mouse input focus, false
- * otherwise.
- * @see requestModalMouseInputFocus, releaseModalMouseInputFocus
- */
- virtual bool isModalMouseInputFocused() const A_WARN_UNUSED;
-
- /**
- * Gets a widget from a certain position in the widget.
- * This function is used to decide which gets mouse input,
- * thus it can be overloaded to change that behaviour.
- *
- * NOTE: This always returns NULL if the widget is not
- * a container.
- *
- * @param x The x coordinate of the widget to get.
- * @param y The y coordinate of the widget to get.
- * @return The widget at the specified coodinate, NULL
- * if no widget is found.
- */
- virtual Widget *getWidgetAt(int x A_UNUSED,
- int y A_UNUSED) A_WARN_UNUSED
- { return nullptr; }
-
- /**
- * Gets the mouse listeners of the widget.
- *
- * @return The mouse listeners of the widget.
- */
- const std::list<MouseListener*>& getMouseListeners() const
- A_CONST A_WARN_UNUSED;
-
- /**
- * Gets the key listeners of the widget.
- *
- * @return The key listeners of the widget.
- */
- const std::list<KeyListener*>& getKeyListeners() const
- A_CONST A_WARN_UNUSED;
-
- /**
- * Gets the focus listeners of the widget.
- *
- * @return The focus listeners of the widget.
- */
- const std::list<FocusListener*>& getFocusListeners() const
- A_CONST A_WARN_UNUSED;
-
- /**
- * Gets the area of the widget occupied by the widget's children.
- * By default this method returns an empty rectangle as not all
- * widgets are containers. If you want to make a container this
- * method should return the area where the children resides. This
- * method is used when drawing children of a widget when computing
- * clip rectangles for the children.
- *
- * An example of a widget that overloads this method is ScrollArea.
- * A ScrollArea has a view of its contant and that view is the
- * children area. The size of a ScrollArea's children area might
- * vary depending on if the scroll bars of the ScrollArea is shown
- * or not.
- *
- * @return The area of the widget occupied by the widget's children.
- * @see BasicContainer
- * @see BasicContainer::getChildrenArea
- * @see BasicContainer::drawChildren
- */
- virtual Rect getChildrenArea() A_WARN_UNUSED;
-
- /**
- * Gets the internal focus handler used.
- *
- * @return the internalFocusHandler used. If no internal focus handler
- * is used, NULL will be returned.
- * @see setInternalFocusHandler
- */
- virtual FocusHandler* getInternalFocusHandler() A_WARN_UNUSED;
-
- /**
- * Sets the internal focus handler. An internal focus handler is
- * needed if both a widget in the widget and the widget itself
- * should be foucsed at the same time.
- *
- * @param focusHandler The internal focus handler to be used.
- * @see getInternalFocusHandler
- */
- void setInternalFocusHandler(FocusHandler *const internalFocusHandler);
-
- /**
- * Moves a widget to the top of this widget. The moved widget will be
- * drawn above all other widgets in this widget.
- *
- * @param widget The widget to move to the top.
- * @see moveToBottom
- */
- virtual void moveToTop(Widget* widget A_UNUSED)
- { }
-
- /**
- * Moves a widget in this widget to the bottom of this widget.
- * The moved widget will be drawn below all other widgets in this widget.
- *
- * @param widget The widget to move to the bottom.
- * @see moveToTop
- */
- virtual void moveToBottom(Widget* widget A_UNUSED)
- { }
-
- /**
- * Focuses the next widget in the widget.
- *
- * @see moveToBottom
- */
- virtual void focusNext()
- { }
-
- /**
- * Focuses the previous widget in the widget.
- *
- * @see moveToBottom
- */
- virtual void focusPrevious()
- { }
-
- /**
- * Tries to show a specific part of a widget by moving it. Used if the
- * widget should act as a container.
- *
- * @param widget The target widget.
- * @param area The area to show.
- */
- virtual void showWidgetPart(Widget *const widget A_UNUSED,
- const Rect &area A_UNUSED)
- { }
-
- /**
- * Sets an id of a widget. An id can be useful if a widget needs to be
- * identified in a container. For example, if widgets are created by an
- * XML document, a certain widget can be retrieved given that the widget
- * has an id.
- *
- * @param id The id to set to the widget.
- * @see getId
- */
- void setId(const std::string& id)
- { mId = id; }
-
- const std::string& getId() const noexcept2 A_WARN_UNUSED
- { return mId; }
-
- /**
- * Shows a certain part of a widget in the widget's parent.
- * Used when widgets want a specific part to be visible in
- * its parent. An example is a TextArea that wants a specific
- * part of its text to be visible when a TextArea is a child
- * of a ScrollArea.
- *
- * @param rectangle The rectangle to be shown.
- */
- virtual void showPart(const Rect &rectangle);
-
- bool isAllowLogic() const noexcept2 A_WARN_UNUSED
- { return mAllowLogic; }
-
- void setMouseConsume(const bool b) noexcept2
- { mMouseConsume = b; }
-
- bool isMouseConsume() const noexcept2 A_WARN_UNUSED
- { return mMouseConsume; }
-
- void setRedraw(const bool b) noexcept2
- { mRedraw = b; }
-
- virtual bool isSelectable() const noexcept2 A_WARN_UNUSED
- { return mSelectable; }
-
- void setSelectable(const bool selectable) noexcept2
- { mSelectable = selectable; }
-
- static void distributeWindowResizeEvent();
-
- void windowResized();
-
- static Widget *callPostInit(Widget *const widget) RETURNS_NONNULL;
-
- virtual void postInit()
- { }
-
- /**
- * True if the widget visible, false otherwise.
- */
- Visible mVisible;
-
- protected:
- /**
- * Distributes an action event to all action listeners
- * of the widget.
- */
- void distributeActionEvent();
-
- /**
- * Distributes resized events to all of the widget's listeners.
- */
- void distributeResizedEvent();
-
- /**
- * Distributes moved events to all of the widget's listeners.
- */
- void distributeMovedEvent();
-
- /**
- * Distributes hidden events to all of the widget's listeners.
- *
- * @author Olof Naessén
- */
- void distributeHiddenEvent();
-
- /**
- * Distributes shown events to all of the widget's listeners.
- *
- * @author Olof Naessén
- */
- void distributeShownEvent();
-
- /**
- * Typdef.
- */
- typedef std::list<MouseListener*> MouseListenerList;
-
- /**
- * Typdef.
- */
- typedef MouseListenerList::iterator MouseListenerIterator;
-
- /**
- * Holds the mouse listeners of the widget.
- */
- MouseListenerList mMouseListeners;
-
- /**
- * Typdef.
- */
- typedef std::list<KeyListener*> KeyListenerList;
-
- /**
- * Holds the key listeners of the widget.
- */
- KeyListenerList mKeyListeners;
-
- /**
- * Typdef.
- */
- typedef KeyListenerList::iterator KeyListenerIterator;
-
- /**
- * Typdef.
- */
- typedef std::list<ActionListener*> ActionListenerList;
-
- /**
- * Holds the action listeners of the widget.
- */
- ActionListenerList mActionListeners;
-
- /**
- * Typdef.
- */
- typedef ActionListenerList::iterator ActionListenerIterator;
-
- /**
- * Typdef.
- */
- typedef std::list<WidgetDeathListener*> WidgetDeathListenerList;
-
- /**
- * Holds the death listeners of the widget.
- */
- WidgetDeathListenerList mDeathListeners;
-
- /**
- * Typdef.
- */
- typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator;
-
- /**
- * Typdef.
- */
- typedef std::list<FocusListener*> FocusListenerList;
-
- /**
- * Holds the focus listeners of the widget.
- */
- FocusListenerList mFocusListeners;
-
- /**
- * Typdef.
- */
- typedef FocusListenerList::iterator FocusListenerIterator;
-
- typedef std::list<WidgetListener*> WidgetListenerList;
-
- /**
- * Holds the widget listeners of the widget.
- */
- WidgetListenerList mWidgetListeners;
-
- /**
- * Typdef.
- */
- typedef WidgetListenerList::iterator WidgetListenerIterator;
-
- /**
- * Holds the foreground color of the widget.
- */
- Color mForegroundColor;
-
- /**
- * Holds the background color of the widget.
- */
- Color mBackgroundColor;
-
- /**
- * Holds the base color of the widget.
- */
- Color mBaseColor;
-
- /**
- * Holds the dimension of the widget.
- */
- 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.
- */
- FocusHandler* mFocusHandler;
-
- /**
- * Holds the focus handler used by the widget. NULL
- * if no internal focus handler is used.
- */
- FocusHandler* mInternalFocusHandler;
-
- /**
- * Holds the parent of the widget. NULL if the widget
- * has no parent.
- */
- Widget* mParent;
-
- /**
- * Holds the font used by the widget.
- */
- Font* mCurrentFont;
-
- /**
- * Holds the frame size of the widget.
- */
- unsigned int mFrameSize;
-
- /**
- * True if the widget focusable, false otherwise.
- */
- bool mFocusable;
-
- /**
- * True if the widget has tab in enabled, false otherwise.
- */
- bool mTabIn;
-
- /**
- * True if the widget has tab in enabled, false otherwise.
- */
- bool mTabOut;
-
- /**
- * True if the widget is enabled, false otherwise.
- */
- bool mEnabled;
-
- bool mAllowLogic;
-
- bool mMouseConsume;
-
- bool mRedraw;
-
- bool mSelectable;
-
- /**
- * Holds the global font used by the widget.
- */
- static Font* mGlobalFont;
-
- private:
- /**
- * Holds a list of all instances of widgets.
- */
- static std::list<Widget*> mAllWidgets;
-
- static std::set<Widget*> mAllWidgetsSet;
-};
-
-#endif // GUI_WIDGETS_WIDGET_H
diff --git a/src/gui/widgets/widget2.h b/src/gui/widgets/widget2.h
deleted file mode 100644
index 12103e317..000000000
--- a/src/gui/widgets/widget2.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_WIDGET2_H
-#define GUI_WIDGETS_WIDGET2_H
-
-#include "const/gui/theme.h"
-
-#include "enums/render/rendertype.h"
-
-#include "gui/themecolorsidoperators.h"
-#include "gui/theme.h"
-
-#include "localconsts.h"
-
-class Widget;
-
-class Widget2 notfinal
-{
- public:
- A_DEFAULT_COPY(Widget2)
-
- virtual ~Widget2()
- {
- }
-
- inline const Color &getThemeColor(const ThemeColorIdT type,
- const unsigned int alpha = 255U)
- const A_WARN_UNUSED A_INLINE
- {
- return theme->getColor(type + mPaletteOffset, alpha);
- }
-
- inline const Color &getThemeCharColor(const signed char c,
- bool &valid)
- const A_WARN_UNUSED A_INLINE
- {
- if (theme == nullptr)
- return Palette::BLACK;
- const ThemeColorIdT colorId = theme->getIdByChar(c, valid);
- if (valid)
- return theme->getColor(colorId + mPaletteOffset, 255U);
- return Palette::BLACK;
- }
-
- virtual void setWidget2(const Widget2 *const widget)
- {
- mPaletteOffset = widget != nullptr ? widget->mPaletteOffset : 0;
- }
-
- void setPalette(int palette)
- {
- mPaletteOffset = palette * CAST_S32(
- ThemeColorId::THEME_COLORS_END);
- checkPalette();
- setWidget2(this);
- }
-
- void checkPalette()
- {
- if (mPaletteOffset < 0 ||
- mPaletteOffset >= THEME_PALETTES * CAST_S32(
- ThemeColorId::THEME_COLORS_END))
- {
- mPaletteOffset = 0;
- }
- }
-
- void setForegroundColor2(const Color &color) noexcept2
- {
- mForegroundColor2 = color;
- }
-
- Widget* getWindow() const noexcept2 A_WARN_UNUSED
- {
- return mWindow;
- }
-
- virtual void setWindow(Widget *const window)
- {
- mWindow = window;
- }
-
- protected:
- explicit Widget2(const Widget2 *const widget) :
- mPaletteOffset(widget != nullptr ? widget->mPaletteOffset : 0),
- mWindow(widget != nullptr ? widget->getWindow() : nullptr),
- mForegroundColor2()
- {
- checkPalette();
- }
-
- int mPaletteOffset;
- Widget *mWindow;
- Color mForegroundColor2;
-};
-
-extern RenderType openGLMode;
-
-#endif // GUI_WIDGETS_WIDGET2_H
diff --git a/src/gui/widgets/widgetgroup.cpp b/src/gui/widgets/widgetgroup.cpp
deleted file mode 100644
index 72524b07c..000000000
--- a/src/gui/widgets/widgetgroup.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/widgetgroup.h"
-
-#include "debug.h"
-
-WidgetGroup::WidgetGroup(const Widget2 *const widget,
- const std::string &group,
- const int height,
- const int spacing) :
- Container(widget),
- WidgetListener(),
- ActionListener(),
- mSpacing(spacing),
- mCount(0),
- mGroup(group),
- mLastX(spacing)
-{
- setHeight(height);
- addWidgetListener(this);
-}
-
-void WidgetGroup::addButton(const std::string &restrict text,
- const std::string &restrict tag,
- const bool pressed)
-{
- if (text.empty() || tag.empty())
- return;
-
- Widget *const widget = createWidget(text, pressed);
- if (widget != nullptr)
- {
- widget->setActionEventId(mActionEventId + tag);
- widget->addActionListener(this);
- addWidget(widget, mSpacing);
- }
-}
-
-void WidgetGroup::action(const ActionEvent &event)
-{
- for (ActionListenerIterator iter = mActionListeners.begin();
- iter != mActionListeners.end(); ++iter)
- {
- (*iter)->action(event);
- }
-}
-
-void WidgetGroup::addWidget(Widget *const widget,
- const int spacing)
-{
- if (widget == nullptr)
- return;
-
- Container::add(widget);
- widget->setPosition(mLastX, spacing);
- mCount++;
- mLastX += widget->getWidth() + 2 * mSpacing;
-}
-
-void WidgetGroup::clear()
-{
- Container::clear();
-
- mCount = 0;
-}
-
-void WidgetGroup::widgetResized(const Event &event A_UNUSED)
-{
-}
diff --git a/src/gui/widgets/widgetgroup.h b/src/gui/widgets/widgetgroup.h
deleted file mode 100644
index 129581ebc..000000000
--- a/src/gui/widgets/widgetgroup.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2012-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_WIDGETGROUP_H
-#define GUI_WIDGETS_WIDGETGROUP_H
-
-#include "gui/widgets/container.h"
-
-#include "listeners/actionlistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "localconsts.h"
-
-class WidgetGroup notfinal : public Container,
- public WidgetListener,
- public ActionListener
-{
- public:
- A_DELETE_COPY(WidgetGroup)
-
- virtual void addButton(const std::string &restrict text,
- const std::string &restrict tag,
- const bool pressed);
-
- void action(const ActionEvent &event) override;
-
- virtual void addWidget(Widget *const widget,
- const int spacing);
-
- void clear() override final;
-
- void widgetResized(const Event &event) override final A_CONST;
-
- virtual Widget *createWidget(const std::string &name,
- const bool pressed)
- const A_WARN_UNUSED = 0;
-
- protected:
- WidgetGroup(const Widget2 *const widget,
- const std::string &group,
- const int height,
- const int spacing);
-
- int mSpacing;
- int mCount;
- std::string mGroup;
-
- private:
- int mLastX;
-};
-
-#endif // GUI_WIDGETS_WIDGETGROUP_H
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
deleted file mode 100644
index b192bad35..000000000
--- a/src/gui/widgets/window.cpp
+++ /dev/null
@@ -1,1499 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "gui/widgets/window.h"
-
-#include "client.h"
-#include "configuration.h"
-#ifndef DYECMD
-#include "dragdrop.h"
-#else // DYECMD
-#include "resources/image/image.h"
-#endif // DYECMD
-#include "soundmanager.h"
-
-#include "const/sound.h"
-
-#include "gui/focushandler.h"
-#include "gui/gui.h"
-#include "gui/popupmanager.h"
-#include "gui/skin.h"
-#include "gui/viewport.h"
-
-#include "gui/fonts/font.h"
-
-#include "gui/popups/popupmenu.h"
-
-#include "gui/windows/setupwindow.h"
-
-#include "gui/widgets/containerplacer.h"
-#include "gui/widgets/layout.h"
-
-#include "render/renderers.h"
-
-#include "render/vertexes/imagecollection.h"
-
-#include "utils/checkutils.h"
-#include "utils/delete2.h"
-
-#include "debug.h"
-
-const int resizeMask = 8 + 4 + 2 + 1;
-
-int Window::windowInstances = 0;
-int Window::mouseResize = 0;
-
-Window::Window(const std::string &caption,
- const Modal modal,
- Window *const parent,
- std::string skin) :
- BasicContainer2(nullptr),
- MouseListener(),
- WidgetListener(),
- mCaption(caption),
- mAlignment(Graphics::CENTER),
- mPadding(2),
- mTitleBarHeight(16),
- mMovable(Move_true),
- mDragOffsetX(0),
- mDragOffsetY(0),
- mMoved(false),
- mSkin(nullptr),
- mDefaultX(0),
- mDefaultY(0),
- mDefaultWidth(0),
- mDefaultHeight(0),
- mCaptionOffsetX(7),
- mCaptionOffsetY(5),
- mShowTitle(true),
- mLastRedraw(true),
- mGrip(nullptr),
- mParentWindow(parent),
- mLayout(nullptr),
- mCloseRect(),
- mStickyRect(),
- mGripRect(),
- mTextChunk(),
- mWindowName("window"),
- mMinWinWidth(100),
- mMinWinHeight(40),
- mMaxWinWidth(mainGraphics->mWidth),
- mMaxWinHeight(mainGraphics->mHeight),
- mVertexes(new ImageCollection),
- mCaptionAlign(Graphics::LEFT),
- mTitlePadding(4),
- mGripPadding(2),
- mResizeHandles(-1),
- mOldResizeHandles(-1),
- mClosePadding(0),
- mStickySpacing(0),
- mStickyPadding(0),
- mCaptionFont(getFont()),
- mModal(modal),
- mCloseWindowButton(false),
- mDefaultVisible(false),
- mSaveVisible(false),
- mStickyButton(false),
- mSticky(false),
- mStickyButtonLock(false),
- mPlayVisibleSound(false),
- mInit(false),
- mTextChanged(true),
- mAllowClose(false)
-{
- logger->log("Window::Window(\"%s\")", caption.c_str());
-
- mWindow = this;
-
- windowInstances++;
-
-// mFrameSize = 1;
- addMouseListener(this);
-
- setFrameSize(0);
- setPadding(3);
- setTitleBarHeight(20);
-
- if (skin.empty())
- skin = "window.xml";
-
- int childPalette = 1;
- // Loads the skin
- if (theme != nullptr)
- {
- mSkin = theme->load(skin, "window.xml");
- if (mSkin != nullptr)
- {
- setPadding(mSkin->getPadding());
- if (getOptionBool("titlebarBold"))
- mCaptionFont = boldFont;
- mTitlePadding = mSkin->getTitlePadding();
- mGripPadding = getOption("resizePadding");
- mCaptionOffsetX = getOption("captionoffsetx");
- if (mCaptionOffsetX == 0)
- mCaptionOffsetX = 7;
- mCaptionOffsetY = getOption("captionoffsety");
- if (mCaptionOffsetY == 0)
- mCaptionOffsetY = 5;
- mCaptionAlign = static_cast<Graphics::Alignment>(
- getOption("captionalign"));
- if (mCaptionAlign < Graphics::LEFT
- || mCaptionAlign > Graphics::RIGHT)
- {
- mCaptionAlign = Graphics::LEFT;
- }
- setTitleBarHeight(CAST_U32(
- getOption("titlebarHeight")));
- if (mTitleBarHeight == 0u)
- mTitleBarHeight = mCaptionFont->getHeight() + mPadding;
-
- mTitleBarHeight += getOption("titlebarHeightRelative");
- setPalette(getOption("palette"));
- childPalette = getOption("childPalette");
- mShowTitle = getOptionBool("showTitle", true);
- mClosePadding = getOption("closePadding");
- mStickySpacing = getOption("stickySpacing");
- mStickyPadding = getOption("stickyPadding");
- }
- }
-
- // Add this window to the window container
- if (windowContainer != nullptr)
- windowContainer->add(this);
-
- if (mModal == Modal_true)
- {
- gui->setCursorType(Cursor::CURSOR_POINTER);
- requestModalFocus();
- }
-
- // Windows are invisible by default
- setVisible(Visible_false, false);
-
- addWidgetListener(this);
- mForegroundColor = getThemeColor(ThemeColorId::WINDOW);
- mForegroundColor2 = getThemeColor(ThemeColorId::WINDOW_OUTLINE);
- setPalette(childPalette);
-}
-
-void Window::postInit()
-{
- if (mInit)
- {
- reportAlways("error: Window created with calling postInit() "
- "more than once: %s",
- mWindowName.c_str());
- }
- mInit = true;
-}
-
-Window::~Window()
-{
- logger->log("Window::~Window(\"%s\")", getCaption().c_str());
-
- if (gui != nullptr)
- gui->removeDragged(this);
-
-#ifndef DYECMD
- if (setupWindow != nullptr)
- setupWindow->unregisterWindowForReset(this);
-#endif // DYECMD
-
- client->windowRemoved(this);
-
- saveWindowState();
-
- delete2(mLayout);
-
- while (!mWidgets.empty())
- delete mWidgets.front();
-
- mWidgets.clear();
-
- removeWidgetListener(this);
- delete2(mVertexes);
-
- windowInstances--;
-
- if (mSkin != nullptr)
- {
- if (theme != nullptr)
- theme->unload(mSkin);
- mSkin = nullptr;
- }
- if (mGrip != nullptr)
- {
- mGrip->decRef();
- mGrip = nullptr;
- }
- if (!mInit)
- {
- reportAlways("error: Window created without calling postInit(): %s",
- mWindowName.c_str());
- }
-}
-
-void Window::setWindowContainer(WindowContainer *const wc)
-{
- windowContainer = wc;
-}
-
-void Window::draw(Graphics *const graphics)
-{
- if (mSkin == nullptr)
- return;
-
- BLOCK_START("Window::draw")
- bool update = false;
-
- if (mResizeHandles != mOldResizeHandles)
- {
- mRedraw = true;
- mOldResizeHandles = mResizeHandles;
- }
- if (mRedraw)
- {
- mLastRedraw = true;
- mRedraw = false;
- update = true;
- mVertexes->clear();
- graphics->calcWindow(mVertexes,
- 0, 0,
- mDimension.width,
- mDimension.height,
- mSkin->getBorder());
-
- // Draw Close Button
- if (mCloseWindowButton)
- {
- const Image *const button = mSkin->getCloseImage(
- mResizeHandles == CLOSE);
- if (button != nullptr)
- {
- graphics->calcTileCollection(mVertexes,
- button,
- mCloseRect.x,
- mCloseRect.y);
- }
- }
- // Draw Sticky Button
- if (mStickyButton)
- {
- const Image *const button = mSkin->getStickyImage(mSticky);
- if (button != nullptr)
- {
- graphics->calcTileCollection(mVertexes,
- button,
- mStickyRect.x,
- mStickyRect.y);
- }
- }
-
- if (mGrip != nullptr)
- {
- graphics->calcTileCollection(mVertexes,
- mGrip,
- mGripRect.x,
- mGripRect.y);
- }
- graphics->finalize(mVertexes);
- }
- else
- {
- mLastRedraw = false;
- }
- graphics->drawTileCollection(mVertexes);
-
- // Draw title
- if (mShowTitle)
- {
- int x;
- switch (mCaptionAlign)
- {
- case Graphics::LEFT:
- default:
- x = mCaptionOffsetX;
- break;
- case Graphics::CENTER:
- x = mCaptionOffsetX - mCaptionFont->getWidth(mCaption) / 2;
- break;
- case Graphics::RIGHT:
- x = mCaptionOffsetX - mCaptionFont->getWidth(mCaption);
- break;
- }
- if (mTextChanged)
- {
- mTextChunk.textFont = mCaptionFont;
- mTextChunk.deleteImage();
- mTextChunk.text = mCaption;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- mCaptionFont->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, x, mCaptionOffsetY);
- }
-
- if (update)
- {
- graphics->setRedraw(update);
- drawChildren(graphics);
- graphics->setRedraw(false);
- }
- else
- {
- drawChildren(graphics);
- }
- BLOCK_END("Window::draw")
-}
-
-void Window::safeDraw(Graphics *const graphics)
-{
- if (mSkin == nullptr)
- return;
-
- BLOCK_START("Window::safeDraw")
-
- graphics->drawImageRect(0, 0,
- mDimension.width,
- mDimension.height,
- mSkin->getBorder());
-
- // Draw Close Button
- if (mCloseWindowButton)
- {
- const Image *const button = mSkin->getCloseImage(
- mResizeHandles == CLOSE);
- if (button != nullptr)
- graphics->drawImage(button, mCloseRect.x, mCloseRect.y);
- }
- // Draw Sticky Button
- if (mStickyButton)
- {
- const Image *const button = mSkin->getStickyImage(mSticky);
- if (button != nullptr)
- graphics->drawImage(button, mStickyRect.x, mStickyRect.y);
- }
-
- if (mGrip != nullptr)
- graphics->drawImage(mGrip, mGripRect.x, mGripRect.y);
-
- // Draw title
- if (mShowTitle)
- {
- int x;
- switch (mCaptionAlign)
- {
- case Graphics::LEFT:
- default:
- x = mCaptionOffsetX;
- break;
- case Graphics::CENTER:
- x = mCaptionOffsetX - mCaptionFont->getWidth(mCaption) / 2;
- break;
- case Graphics::RIGHT:
- x = mCaptionOffsetX - mCaptionFont->getWidth(mCaption);
- break;
- }
- if (mTextChanged)
- {
- mTextChunk.textFont = mCaptionFont;
- mTextChunk.deleteImage();
- mTextChunk.text = mCaption;
- mTextChunk.color = mForegroundColor;
- mTextChunk.color2 = mForegroundColor2;
- mCaptionFont->generate(mTextChunk);
- mTextChanged = false;
- }
-
- const Image *const image = mTextChunk.img;
- if (image != nullptr)
- graphics->drawImage(image, x, mCaptionOffsetY);
- }
-
- safeDrawChildren(graphics);
-
- BLOCK_END("Window::safeDraw")
-}
-
-void Window::setContentSize(int width, int height)
-{
- width = width + 2 * mPadding;
- height = height + mPadding + mTitleBarHeight;
-
- if (mMinWinWidth > width)
- width = mMinWinWidth;
- else if (mMaxWinWidth < width)
- width = mMaxWinWidth;
- if (mMinWinHeight > height)
- height = mMinWinHeight;
- else if (mMaxWinHeight < height)
- height = mMaxWinHeight;
-
- setSize(width, height);
-}
-
-void Window::setLocationRelativeTo(const Widget *const widget)
-{
- if (widget == nullptr)
- return;
-
- int wx, wy;
- int x, y;
-
- widget->getAbsolutePosition(wx, wy);
- getAbsolutePosition(x, y);
-
- setPosition(mDimension.x + (wx + (widget->getWidth()
- - mDimension.width) / 2 - x),
- mDimension.y + (wy + (widget->getHeight()
- - mDimension.height) / 2 - y));
-}
-
-void Window::setLocationHorisontallyRelativeTo(const Widget *const widget)
-{
- if (widget == nullptr)
- return;
-
- int wx, wy;
- int x, y;
-
- widget->getAbsolutePosition(wx, wy);
- getAbsolutePosition(x, y);
-
- setPosition(mDimension.x + (wx + (widget->getWidth()
- - mDimension.width) / 2 - x), 0);
-}
-
-void Window::setLocationRelativeTo(const ImagePosition::Type &position,
- int offsetX, int offsetY)
-{
- if (position == ImagePosition::UPPER_LEFT)
- {
- }
- else if (position == ImagePosition::UPPER_CENTER)
- {
- offsetX += (mainGraphics->mWidth - mDimension.width) / 2;
- }
- else if (position == ImagePosition::UPPER_RIGHT)
- {
- offsetX += mainGraphics->mWidth - mDimension.width;
- }
- else if (position == ImagePosition::LEFT)
- {
- offsetY += (mainGraphics->mHeight - mDimension.height) / 2;
- }
- else if (position == ImagePosition::CENTER)
- {
- offsetX += (mainGraphics->mWidth - mDimension.width) / 2;
- offsetY += (mainGraphics->mHeight - mDimension.height) / 2;
- }
- else if (position == ImagePosition::RIGHT)
- {
- offsetX += mainGraphics->mWidth - mDimension.width;
- offsetY += (mainGraphics->mHeight - mDimension.height) / 2;
- }
- else if (position == ImagePosition::LOWER_LEFT)
- {
- offsetY += mainGraphics->mHeight - mDimension.height;
- }
- else if (position == ImagePosition::LOWER_CENTER)
- {
- offsetX += (mainGraphics->mWidth - mDimension.width) / 2;
- offsetY += mainGraphics->mHeight - mDimension.height;
- }
- else if (position == ImagePosition::LOWER_RIGHT)
- {
- offsetX += mainGraphics->mWidth - mDimension.width;
- offsetY += mainGraphics->mHeight - mDimension.height;
- }
-
- setPosition(offsetX, offsetY);
-}
-
-void Window::setMinWidth(const int width)
-{
- if (mSkin != nullptr)
- {
- mMinWinWidth = width > mSkin->getMinWidth()
- ? width : mSkin->getMinWidth();
- }
- else
- {
- mMinWinWidth = width;
- }
-}
-
-void Window::setMinHeight(const int height)
-{
- if (mSkin != nullptr)
- {
- mMinWinHeight = height > mSkin->getMinHeight()
- ? height : mSkin->getMinHeight();
- }
- else
- {
- mMinWinHeight = height;
- }
-}
-
-void Window::setMaxWidth(const int width)
-{
- mMaxWinWidth = width;
-}
-
-void Window::setMaxHeight(const int height)
-{
- mMaxWinHeight = height;
-}
-
-void Window::setResizable(const bool r)
-{
- if ((mGrip != nullptr) == r)
- return;
-
- if (mGrip != nullptr)
- mGrip->decRef();
- if (r)
- {
- mGrip = Theme::getImageFromThemeXml("resize.xml", "");
- if (mGrip != nullptr)
- {
- mGripRect.x = mDimension.width - mGrip->getWidth() - mGripPadding;
- mGripRect.y = mDimension.height - mGrip->getHeight()
- - mGripPadding;
- }
- else
- {
- mGripRect.x = 0;
- mGripRect.y = 0;
- }
- }
- else
- {
- mGrip = nullptr;
- }
-}
-
-void Window::widgetResized(const Event &event A_UNUSED)
-{
- if (mGrip != nullptr)
- {
- mGripRect.x = mDimension.width - mGrip->getWidth() - mGripPadding;
- mGripRect.y = mDimension.height - mGrip->getHeight() - mGripPadding;
- }
-
- if (mLayout != nullptr)
- {
- const Rect area = getChildrenArea();
- int w = area.width;
- int h = area.height;
- mLayout->reflow(w, h);
- }
- if (mSkin != nullptr)
- {
- const bool showClose = mCloseWindowButton
- && (mSkin->getCloseImage(false) != nullptr);
- if (showClose)
- {
- const Image *const button = mSkin->getCloseImage(false);
- if (button != nullptr)
- {
- const int buttonWidth = button->getWidth();
- mCloseRect.x = mDimension.width - buttonWidth - mClosePadding;
- mCloseRect.y = mClosePadding;
- mCloseRect.width = buttonWidth;
- mCloseRect.height = button->getHeight();
- }
- }
- if (mStickyButton)
- {
- const Image *const button = mSkin->getStickyImage(mSticky);
- if (button != nullptr)
- {
- const int buttonWidth = button->getWidth();
- int x = mDimension.width - buttonWidth
- - mStickySpacing - mClosePadding;
-
- if (showClose)
- x -= mSkin->getCloseImage(false)->getWidth();
-
- mStickyRect.x = x;
- mStickyRect.y = mStickyPadding;
- mStickyRect.width = buttonWidth;
- mStickyRect.height = button->getHeight();
- }
- }
- }
- else
- {
- mCloseRect.x = 0;
- mCloseRect.y = 0;
- mCloseRect.width = 0;
- mCloseRect.height = 0;
- mStickyRect.x = 0;
- mStickyRect.y = 0;
- mStickyRect.width = 0;
- mStickyRect.height = 0;
- }
-
- mRedraw = true;
-}
-
-void Window::widgetMoved(const Event& event A_UNUSED)
-{
- mRedraw = true;
-}
-
-void Window::widgetHidden(const Event &event A_UNUSED)
-{
- if (isBatchDrawRenders(openGLMode))
- mVertexes->clear();
-
- mTextChunk.deleteImage();
-
- mTextChanged = true;
- mRedraw = true;
-
- if (gui != nullptr)
- gui->setCursorType(Cursor::CURSOR_POINTER);
-
- if (mFocusHandler == nullptr)
- return;
-
- for (WidgetListConstIterator it = mWidgets.begin();
- it != mWidgets.end(); ++ it)
- {
- if (mFocusHandler->isFocused(*it))
- mFocusHandler->focusNone();
- }
-}
-
-void Window::setCloseButton(const bool flag)
-{
- mCloseWindowButton = flag;
- if (flag)
- mAllowClose = true;
-}
-
-bool Window::isResizable() const
-{
- return mGrip != nullptr;
-}
-
-void Window::setStickyButton(const bool flag)
-{
- mStickyButton = flag;
-}
-
-void Window::setSticky(const bool sticky)
-{
- mSticky = sticky;
- mRedraw = true;
-}
-
-void Window::setStickyButtonLock(const bool lock)
-{
- mStickyButtonLock = lock;
- mStickyButton = lock;
-}
-
-void Window::setVisible(Visible visible)
-{
- setVisible(visible, false);
-}
-
-void Window::setVisible(const Visible visible, const bool forceSticky)
-{
- if (visible == mVisible)
- return;
-
- // Check if the window is off screen...
- if (visible == Visible_true)
- ensureOnScreen();
- else
- mResizeHandles = 0;
-
- if (mStickyButtonLock)
- {
- BasicContainer2::setVisible(visible);
- }
- else
- {
- BasicContainer2::setVisible(fromBool((!forceSticky && mSticky) ||
- visible == Visible_true, Visible));
- }
- if (visible == Visible_true)
- {
- if (mPlayVisibleSound)
- soundManager.playGuiSound(SOUND_SHOW_WINDOW);
- if (gui != nullptr)
- {
- MouseEvent *const event = reinterpret_cast<MouseEvent*>(
- gui->createMouseEvent(this));
- if (event != nullptr)
- {
- const int x = event->getX();
- const int y = event->getY();
- if (x >= 0 && x <= mDimension.width
- && y >= 0 && y <= mDimension.height)
- {
- mouseMoved(*event);
- }
- delete event;
- }
- }
- }
- else
- {
- if (mPlayVisibleSound)
- soundManager.playGuiSound(SOUND_HIDE_WINDOW);
- }
-}
-
-void Window::scheduleDelete()
-{
- windowContainer->scheduleDelete(this);
-}
-
-void Window::mousePressed(MouseEvent &event)
-{
- if (event.isConsumed())
- return;
-
- if (event.getSource() == this)
- {
- if (getParent() != nullptr)
- getParent()->moveToTop(this);
-
- mDragOffsetX = event.getX();
- mDragOffsetY = event.getY();
- mMoved = event.getY() <= CAST_S32(mTitleBarHeight);
- }
-
- const MouseButtonT button = event.getButton();
- if (button == MouseButton::LEFT)
- {
- const int x = event.getX();
- const int y = event.getY();
-
- // Handle close button
- if (mCloseWindowButton &&
- mSkin != nullptr &&
- mCloseRect.isPointInRect(x, y))
- {
- mouseResize = 0;
- mMoved = false;
- event.consume();
- close();
- return;
- }
-
- // Handle sticky button
- if (mStickyButton &&
- mSkin != nullptr &&
- mStickyRect.isPointInRect(x, y))
- {
- setSticky(!isSticky());
- mouseResize = 0;
- mMoved = false;
- event.consume();
- return;
- }
-
- // Handle window resizing
- mouseResize = getResizeHandles(event) & resizeMask;
- if (mouseResize != 0)
- event.consume();
- if (canMove())
- mMoved = (mouseResize == 0);
- else
- mMoved = false;
- }
-#ifndef DYECMD
- else if (button == MouseButton::RIGHT)
- {
- if (popupMenu != nullptr)
- {
- event.consume();
- popupMenu->showWindowPopup(this);
- }
- }
-#endif // DYECMD
-}
-
-void Window::close()
-{
- setVisible(Visible_false);
-}
-
-void Window::mouseReleased(MouseEvent &event A_UNUSED)
-{
- if ((mGrip != nullptr) && (mouseResize != 0))
- {
- mouseResize = 0;
- if (gui != nullptr)
- gui->setCursorType(Cursor::CURSOR_POINTER);
- }
-
- mMoved = false;
-}
-
-void Window::mouseEntered(MouseEvent &event)
-{
- updateResizeHandler(event);
-}
-
-void Window::mouseExited(MouseEvent &event A_UNUSED)
-{
- if ((mGrip != nullptr) && (mouseResize == 0) && (gui != nullptr))
- gui->setCursorType(Cursor::CURSOR_POINTER);
-}
-
-void Window::updateResizeHandler(MouseEvent &event)
-{
- if (gui == nullptr)
- return;
-
-#ifndef DYECMD
- if (!dragDrop.isEmpty())
- return;
-#endif // DYECMD
-
- mResizeHandles = getResizeHandles(event);
-
- // Changes the custom mouse cursor based on it's current position.
- switch (mResizeHandles & resizeMask)
- {
- case BOTTOM | RIGHT:
- case TOP | LEFT:
- gui->setCursorType(Cursor::CURSOR_RESIZE_DOWN_RIGHT);
- break;
- case TOP | RIGHT:
- case BOTTOM | LEFT:
- gui->setCursorType(Cursor::CURSOR_RESIZE_DOWN_LEFT);
- break;
- case BOTTOM:
- case TOP:
- gui->setCursorType(Cursor::CURSOR_RESIZE_DOWN);
- break;
- case RIGHT:
- case LEFT:
- gui->setCursorType(Cursor::CURSOR_RESIZE_ACROSS);
- break;
- default:
- gui->setCursorType(Cursor::CURSOR_POINTER);
- break;
- }
-}
-
-void Window::mouseMoved(MouseEvent &event)
-{
- updateResizeHandler(event);
- if ((popupManager != nullptr) && !event.isConsumed())
- {
- PopupManager::hideBeingPopup();
- PopupManager::hideTextPopup();
- }
-}
-
-bool Window::canMove() const
-{
- return !mStickyButtonLock || !mSticky;
-}
-
-void Window::mouseDragged(MouseEvent &event)
-{
- if (canMove())
- {
- if (!event.isConsumed() && event.getSource() == this)
- {
- if (isMovable() && mMoved)
- {
- setPosition(event.getX() - mDragOffsetX + getX(),
- event.getY() - mDragOffsetY + getY());
- }
-
- event.consume();
- }
- }
- else
- {
- if (!event.isConsumed() && event.getSource() == this)
- event.consume();
- return;
- }
-
- // Keep guichan window inside screen when it may be moved
- if (isMovable() && mMoved)
- {
- setPosition(std::min(mainGraphics->mWidth - mDimension.width,
- std::max(0, mDimension.x)),
- std::min(mainGraphics->mHeight - mDimension.height,
- std::max(0, mDimension.y)));
- }
-
- if ((mouseResize != 0) && !mMoved)
- {
- const int dx = event.getX() - mDragOffsetX;
- const int dy = event.getY() - mDragOffsetY;
- Rect newDim = getDimension();
-
- if ((mouseResize & (TOP | BOTTOM)) != 0)
- {
- const int newHeight = newDim.height
- + ((mouseResize & TOP) != 0 ? -dy : dy);
- newDim.height = std::min(mMaxWinHeight,
- std::max(mMinWinHeight, newHeight));
-
- if ((mouseResize & TOP) != 0)
- newDim.y -= newDim.height - getHeight();
- }
-
- if ((mouseResize & (LEFT | RIGHT)) != 0)
- {
- const int newWidth = newDim.width
- + ((mouseResize & LEFT) != 0 ? -dx : dx);
- newDim.width = std::min(mMaxWinWidth,
- std::max(mMinWinWidth, newWidth));
-
- if ((mouseResize & LEFT) != 0)
- newDim.x -= newDim.width - mDimension.width;
- }
-
- // Keep guichan window inside screen (supports resizing any side)
- if (newDim.x < 0)
- {
- newDim.width += newDim.x;
- newDim.x = 0;
- }
- if (newDim.y < 0)
- {
- newDim.height += newDim.y;
- newDim.y = 0;
- }
- if (newDim.x + newDim.width > mainGraphics->mWidth)
- newDim.width = mainGraphics->mWidth - newDim.x;
- if (newDim.y + newDim.height > mainGraphics->mHeight)
- newDim.height = mainGraphics->mHeight - newDim.y;
-
- // Update mouse offset when dragging bottom or right border
- if ((mouseResize & BOTTOM) != 0)
- mDragOffsetY += newDim.height - mDimension.height;
-
- if ((mouseResize & RIGHT) != 0)
- mDragOffsetX += newDim.width - mDimension.width;
-
- // Set the new window and content dimensions
- setDimension(newDim);
- }
-}
-
-void Window::setModal(const Modal modal)
-{
- if (mModal != modal)
- {
- mModal = modal;
- if (mModal == Modal_true)
- {
- if (gui != nullptr)
- gui->setCursorType(Cursor::CURSOR_POINTER);
- requestModalFocus();
- }
- else
- {
- releaseModalFocus();
- }
- }
-}
-
-void Window::loadWindowState()
-{
- const std::string &name = mWindowName;
- if (name.empty())
- return;
-
- setPosition(config.getValueInt(name + "WinX", mDefaultX),
- config.getValueInt(name + "WinY", mDefaultY));
-
- if (mSaveVisible)
- {
- setVisible(fromBool(config.getValueBool(name
- + "Visible", mDefaultVisible), Visible));
- }
-
- if (mStickyButton)
- {
- setSticky(config.getValueBool(name
- + "Sticky", isSticky()));
- }
-
- if (mGrip != nullptr)
- {
- int width = config.getValueInt(name + "WinWidth", mDefaultWidth);
- int height = config.getValueInt(name + "WinHeight", mDefaultHeight);
-
- if (getMinWidth() > width)
- width = getMinWidth();
- else if (getMaxWidth() < width)
- width = getMaxWidth();
- if (getMinHeight() > height)
- height = getMinHeight();
- else if (getMaxHeight() < height)
- height = getMaxHeight();
-
- setSize(width, height);
- }
- else
- {
- setSize(mDefaultWidth, mDefaultHeight);
- }
-
- // Check if the window is off screen...
- ensureOnScreen();
-
- if (viewport != nullptr)
- {
- int width = mDimension.width;
- int height = mDimension.height;
-
- if (mDimension.x + width > viewport->getWidth())
- width = viewport->getWidth() - mDimension.x;
- if (mDimension.y + height > viewport->getHeight())
- height = viewport->getHeight() - mDimension.y;
- if (width < 0)
- width = 0;
- if (height < 0)
- height = 0;
- setSize(width, height);
- }
-}
-
-void Window::saveWindowState()
-{
- // Saving X, Y and Width and Height for resizables in the config
- if (!mWindowName.empty() && mWindowName != "window")
- {
- config.setValue(mWindowName + "WinX", mDimension.x);
- config.setValue(mWindowName + "WinY", mDimension.y);
-
- if (mSaveVisible)
- config.setValue(mWindowName + "Visible", isWindowVisible());
-
- if (mStickyButton)
- config.setValue(mWindowName + "Sticky", isSticky());
-
- if (mGrip != nullptr)
- {
- if (getMinWidth() > mDimension.width)
- setWidth(getMinWidth());
- else if (getMaxWidth() < mDimension.width)
- setWidth(getMaxWidth());
- if (getMinHeight() > mDimension.height)
- setHeight(getMinHeight());
- else if (getMaxHeight() < mDimension.height)
- setHeight(getMaxHeight());
-
- config.setValue(mWindowName + "WinWidth", mDimension.width);
- config.setValue(mWindowName + "WinHeight", mDimension.height);
- }
- }
-}
-
-void Window::setDefaultSize(const int defaultX, const int defaultY,
- int defaultWidth, int defaultHeight)
-{
- if (mMinWinWidth > defaultWidth)
- defaultWidth = mMinWinWidth;
- else if (mMaxWinWidth < defaultWidth)
- defaultWidth = mMaxWinWidth;
- if (mMinWinHeight > defaultHeight)
- defaultHeight = mMinWinHeight;
- else if (mMaxWinHeight < defaultHeight)
- defaultHeight = mMaxWinHeight;
-
- mDefaultX = defaultX;
- mDefaultY = defaultY;
- mDefaultWidth = defaultWidth;
- mDefaultHeight = defaultHeight;
-}
-
-void Window::setDefaultSize()
-{
- mDefaultX = mDimension.x;
- mDefaultY = mDimension.y;
- mDefaultWidth = mDimension.width;
- mDefaultHeight = mDimension.height;
-}
-
-void Window::setDefaultSize(const int defaultWidth, const int defaultHeight,
- const ImagePosition::Type &position,
- const int offsetX, const int offsetY)
-{
- int x = 0;
- int y = 0;
-
- if (position == ImagePosition::UPPER_LEFT)
- {
- }
- else if (position == ImagePosition::UPPER_CENTER)
- {
- x = (mainGraphics->mWidth - defaultWidth) / 2;
- }
- else if (position == ImagePosition::UPPER_RIGHT)
- {
- x = mainGraphics->mWidth - defaultWidth;
- }
- else if (position == ImagePosition::LEFT)
- {
- y = (mainGraphics->mHeight - defaultHeight) / 2;
- }
- else if (position == ImagePosition::CENTER)
- {
- x = (mainGraphics->mWidth - defaultWidth) / 2;
- y = (mainGraphics->mHeight - defaultHeight) / 2;
- }
- else if (position == ImagePosition::RIGHT)
- {
- x = mainGraphics->mWidth - defaultWidth;
- y = (mainGraphics->mHeight - defaultHeight) / 2;
- }
- else if (position == ImagePosition::LOWER_LEFT)
- {
- y = mainGraphics->mHeight - defaultHeight;
- }
- else if (position == ImagePosition::LOWER_CENTER)
- {
- x = (mainGraphics->mWidth - defaultWidth) / 2;
- y = mainGraphics->mHeight - defaultHeight;
- }
- else if (position == ImagePosition::LOWER_RIGHT)
- {
- x = mainGraphics->mWidth - defaultWidth;
- y = mainGraphics->mHeight - defaultHeight;
- }
-
- mDefaultX = x - offsetX;
- mDefaultY = y - offsetY;
- mDefaultWidth = defaultWidth;
- mDefaultHeight = defaultHeight;
-}
-
-void Window::resetToDefaultSize()
-{
- setPosition(mDefaultX, mDefaultY);
- setSize(mDefaultWidth, mDefaultHeight);
- saveWindowState();
-}
-
-void Window::adjustPositionAfterResize(const int oldScreenWidth,
- const int oldScreenHeight)
-{
- // If window was aligned to the right or bottom, keep it there
- const int rightMargin = oldScreenWidth - (mDimension.x + mDimension.width);
- const int bottomMargin = oldScreenHeight
- - (mDimension.y + mDimension.height);
- if (mDimension.x > 0 && mDimension.x > rightMargin)
- mDimension.x = mainGraphics->mWidth - rightMargin - mDimension.width;
- if (mDimension.y > 0 && mDimension.y > bottomMargin)
- {
- mDimension.y = mainGraphics->mHeight
- - bottomMargin - mDimension.height;
- }
-
- ensureOnScreen();
- adjustSizeToScreen();
-}
-
-void Window::adjustSizeToScreen()
-{
- if (mGrip == nullptr)
- return;
-
- const int screenWidth = mainGraphics->mWidth;
- const int screenHeight = mainGraphics->mHeight;
- const int oldWidth = mDimension.width;
- const int oldHeight = mDimension.height;
- if (oldWidth + mDimension.x > screenWidth)
- mDimension.x = 0;
- if (oldHeight + mDimension.y > screenHeight)
- mDimension.x = 0;
- if (mDimension.width > screenWidth)
- mDimension.width = screenWidth;
- if (mDimension.height > screenHeight)
- mDimension.height = screenHeight;
- if (oldWidth != mDimension.width || oldHeight != mDimension.height)
- widgetResized(Event(this));
-}
-
-int Window::getResizeHandles(const MouseEvent &event)
-{
- if (event.getX() < 0 || event.getY() < 0)
- return 0;
-
- int resizeHandles = 0;
- const unsigned y = event.getY();
- const unsigned x = event.getX();
- if (mCloseRect.isPointInRect(x, y))
- return CLOSE;
-
- if (!mStickyButtonLock || !mSticky)
- {
- if ((mGrip != nullptr) &&
- (y > mTitleBarHeight ||
- (CAST_S32(y) < mPadding &&
- CAST_S32(mTitleBarHeight) > mPadding)))
- {
- if (!getWindowArea().isPointInRect(x, y)
- && event.getSource() == this)
- {
- resizeHandles |= (x > mDimension.width - resizeBorderWidth)
- ? RIGHT : (x < resizeBorderWidth) ? LEFT : 0;
- resizeHandles |= (y > mDimension.height - resizeBorderWidth)
- ? BOTTOM : (y < resizeBorderWidth) ? TOP : 0;
- }
- if (x >= CAST_U32(mGripRect.x)
- && y >= CAST_U32(mGripRect.y))
- {
- mDragOffsetX = x;
- mDragOffsetY = y;
- resizeHandles |= BOTTOM | RIGHT;
- }
- }
- }
-
- return resizeHandles;
-}
-
-bool Window::isResizeAllowed(const MouseEvent &event) const
-{
- const int y = event.getY();
-
- if ((mGrip != nullptr) &&
- (y > CAST_S32(mTitleBarHeight) ||
- y < mPadding))
- {
- const int x = event.getX();
-
- if (!getWindowArea().isPointInRect(x, y) && event.getSource() == this)
- return true;
-
- if (x >= mGripRect.x && y >= mGripRect.y)
- return true;
- }
-
- return false;
-}
-
-Layout &Window::getLayout()
-{
- if (mLayout == nullptr)
- mLayout = new Layout;
- return *mLayout;
-}
-
-void Window::clearLayout()
-{
- clear();
-
- // Recreate layout instance when one is present
- if (mLayout != nullptr)
- {
- delete mLayout;
- mLayout = new Layout;
- }
-}
-
-LayoutCell &Window::place(const int x, const int y, Widget *const wg,
- const int w, const int h)
-{
- add(wg);
- return getLayout().place(wg, x, y, w, h);
-}
-
-ContainerPlacer Window::getPlacer(const int x, const int y)
-{
- return ContainerPlacer(this, &getLayout().at(x, y));
-}
-
-void Window::reflowLayout(int w, int h)
-{
- if (mLayout == nullptr)
- return;
-
- mLayout->reflow(w, h);
- delete2(mLayout);
- setContentSize(w, h);
-}
-
-void Window::redraw()
-{
- if (mLayout != nullptr)
- {
- const Rect area = getChildrenArea();
- int w = area.width;
- int h = area.height;
- mLayout->reflow(w, h);
- }
-}
-
-void Window::center()
-{
- setLocationRelativeTo(getParent());
-}
-
-void Window::centerHorisontally()
-{
- setLocationHorisontallyRelativeTo(getParent());
-}
-
-void Window::ensureOnScreen()
-{
- // Skip when a window hasn't got any size initialized yet
- if (mDimension.width == 0 && mDimension.height == 0)
- return;
-
- // Check the left and bottom screen boundaries
- if (mDimension.x + mDimension.width > mainGraphics->mWidth)
- mDimension.x = mainGraphics->mWidth - mDimension.width;
- if (mDimension.y + mDimension.height > mainGraphics->mHeight)
- mDimension.y = mainGraphics->mHeight - mDimension.height;
-
- // But never allow the windows to disappear in to the right and top
- if (mDimension.x < 0)
- mDimension.x = 0;
- if (mDimension.y < 0)
- mDimension.y = 0;
-}
-
-Rect Window::getWindowArea() const
-{
- return Rect(mPadding,
- mPadding,
- mDimension.width - mPadding * 2,
- mDimension.height - mPadding * 2);
-}
-
-int Window::getOption(const std::string &name, const int def) const
-{
- if (mSkin != nullptr)
- {
- const int val = mSkin->getOption(name);
- if (val != 0)
- return val;
- return def;
- }
- return def;
-}
-
-bool Window::getOptionBool(const std::string &name, const bool def) const
-{
- if (mSkin != nullptr)
- return mSkin->getOption(name, static_cast<int>(def)) != 0;
- return def;
-}
-
-Rect Window::getChildrenArea()
-{
- return Rect(mPadding,
- mTitleBarHeight,
- mDimension.width - mPadding * 2,
- mDimension.height - mPadding - mTitleBarHeight);
-}
-
-void Window::resizeToContent()
-{
- int w = 0;
- int h = 0;
- for (WidgetListConstIterator it = mWidgets.begin();
- it != mWidgets.end(); ++ it)
- {
- const Widget *const widget = *it;
- const int x = widget->getX();
- const int y = widget->getY();
- const int width = widget->getWidth();
- const int height = widget->getHeight();
- if (x + width > w)
- w = x + width;
-
- if (y + height > h)
- h = y + height;
- }
-
- setSize(w + 2 * mPadding,
- h + mPadding + mTitleBarHeight);
-}
-
-#ifdef USE_PROFILER
-void Window::logic()
-{
- BLOCK_START("Window::logic")
- logicChildren();
- BLOCK_END("Window::logic")
-}
-#endif // USE_PROFILER
diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h
deleted file mode 100644
index d089680af..000000000
--- a/src/gui/widgets/window.h
+++ /dev/null
@@ -1,725 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* _______ __ __ __ ______ __ __ _______ __ __
- * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
- * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
- * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
- * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
- * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
- * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
- *
- * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
- *
- *
- * Per Larsson a.k.a finalman
- * Olof Naessén a.k.a jansem/yakslem
- *
- * Visit: http://guichan.sourceforge.net
- *
- * License: (BSD)
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name of Guichan nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
- * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef GUI_WIDGETS_WINDOW_H
-#define GUI_WIDGETS_WINDOW_H
-
-#include "enums/simpletypes/modal.h"
-#include "enums/simpletypes/move.h"
-
-#include "enums/resources/imageposition.h"
-
-#include "gui/fonts/textchunk.h"
-
-#include "gui/widgets/basiccontainer2.h"
-
-#include "listeners/mouselistener.h"
-#include "listeners/widgetlistener.h"
-
-#include "render/graphics.h"
-
-#include "localconsts.h"
-
-class ContainerPlacer;
-class ImageCollection;
-class Layout;
-class LayoutCell;
-class Skin;
-class WindowContainer;
-
-/**
- * A window. This window can be dragged around and has a title bar. Windows are
- * invisible by default.
- *
- * \ingroup GUI
- */
-class Window notfinal : public BasicContainer2,
- public MouseListener,
- public WidgetListener
-{
- public:
- /**
- * Constructor. Initializes the title to the given text and hooks
- * itself into the window container.
- *
- * @param caption The initial window title, "Window" by default.
- * @param modal Block input to other windows.
- * @param parent The parent window. This is the window standing above
- * this one in the window hiearchy. When reordering,
- * a window will never go below its parent window.
- * @param skin The location where the window's skin XML can be found.
- */
- explicit Window(const std::string &caption = "Window",
- const Modal modal = Modal_false,
- Window *const parent = nullptr,
- std::string skin = "");
-
- A_DELETE_COPY(Window)
-
- /**
- * Destructor. Deletes all the added widgets.
- */
- virtual ~Window();
-
- /**
- * Sets the window container to be used by new windows.
- */
- static void setWindowContainer(WindowContainer *const windowContainer);
-
- /**
- * Draws the window.
- */
- void draw(Graphics *const graphics) override A_NONNULL(2);
-
- void safeDraw(Graphics *const graphics) override A_NONNULL(2);
-
- /**
- * Sets the size of this window.
- */
- void setContentSize(int width, int height);
-
- /**
- * Sets the location relative to the given widget.
- */
- void setLocationRelativeTo(const Widget *const widget);
-
- /**
- * Sets the location relative to the given widget (only horisontally)
- */
- void setLocationHorisontallyRelativeTo(const Widget
- *const widget);
-
- /**
- * Sets the location relative to the given enumerated position.
- */
- void setLocationRelativeTo(const ImagePosition::Type &position,
- int offsetX = 0, int offsetY = 0);
-
- /**
- * Sets whether or not the window can be resized.
- */
- void setResizable(const bool resize);
-
- void redraw();
-
- /**
- * Called whenever the widget changes size.
- */
- void widgetResized(const Event &event) override;
-
- void widgetMoved(const Event& event) override;
-
- /**
- * Called whenever the widget is hidden.
- */
- void widgetHidden(const Event &event) override;
-
- /**
- * Sets whether or not the window has a close button.
- */
- void setCloseButton(const bool flag);
-
- bool getCloseButton() const noexcept2 A_WARN_UNUSED
- { return mCloseWindowButton; }
-
- void setAllowClose(const bool b)
- { mAllowClose = b; }
-
- bool getAlowClose() const noexcept2 A_WARN_UNUSED
- { return mCloseWindowButton || mAllowClose; }
-
- /**
- * Returns whether the window can be resized.
- */
- bool isResizable() const A_WARN_UNUSED;
-
- /**
- * Sets the minimum width of the window.
- */
- void setMinWidth(const int width);
-
- int getMinWidth() const noexcept2 A_WARN_UNUSED
- { return mMinWinWidth; }
-
- /**
- * Sets the minimum height of the window.
- */
- void setMinHeight(const int height);
-
- int getMinHeight() const noexcept2 A_WARN_UNUSED
- { return mMinWinHeight; }
-
- /**
- * Sets the maximum width of the window.
- */
- void setMaxWidth(const int width);
-
- int getMaxWidth() const noexcept2 A_WARN_UNUSED
- { return mMaxWinWidth; }
-
- /**
- * Sets the minimum height of the window.
- */
- void setMaxHeight(const int height);
-
- int getMaxHeight() const noexcept2 A_WARN_UNUSED
- { return mMaxWinHeight; }
-
- /**
- * Sets flag to show a title or not.
- */
- void setShowTitle(bool flag)
- { mShowTitle = flag; }
-
- /**
- * Sets whether or not the window has a sticky button.
- */
- void setStickyButton(const bool flag);
-
- /**
- * Sets whether the window is sticky. A sticky window will not have
- * its visibility set to false on a general setVisible(false) call.
- * Use this to set the default before you call loadWindowState().
- */
- void setSticky(const bool sticky);
-
- /**
- * Returns whether the window is sticky.
- */
- bool isSticky() const noexcept2 A_WARN_UNUSED
- { return mSticky; }
-
- /**
- * Sets whether the window sticky mean window locked or not.
- */
- void setStickyButtonLock(const bool sticky);
-
- /**
- * Returns whether the window sticky locking window.
- */
- bool isStickyButtonLock() const noexcept2 A_WARN_UNUSED
- { return mStickyButtonLock; }
-
- /**
- * Overloads window setVisible by Guichan to allow sticky window
- * handling.
- */
- virtual void setVisible(Visible visible);
-
- /**
- * Overloads window setVisible by Guichan to allow sticky window
- * handling, or not, if you force the sticky state.
- */
- void setVisible(const Visible visible, const bool forceSticky);
-
- /**
- * Returns whether the window is visible by default.
- */
- bool isDefaultVisible() const noexcept2 A_WARN_UNUSED
- { return mDefaultVisible; }
-
- /**
- * Sets whether the window is visible by default.
- */
- void setDefaultVisible(const bool save)
- { mDefaultVisible = save; }
-
- /**
- * Returns whether the window will save it's visibility.
- */
- bool willSaveVisible() const
- { return mSaveVisible; }
-
- /**
- * Sets whether the window will save it's visibility.
- */
- void setSaveVisible(const bool save)
- { mSaveVisible = save; }
-
- void postInit() override;
-
- /**
- * Returns the parent window.
- *
- * @return The parent window or <code>NULL</code> if there is none.
- */
- Window *getParentWindow() const
- { return mParentWindow; }
-
- /**
- * Schedule this window for deletion. It will be deleted at the start
- * of the next logic update.
- */
- virtual void scheduleDelete();
-
- /**
- * Starts window resizing when appropriate.
- */
- void mousePressed(MouseEvent &event) override;
-
- /**
- * Implements window resizing and makes sure the window is not
- * dragged/resized outside of the screen.
- */
- void mouseDragged(MouseEvent &event) override;
-
- /**
- * Implements custom cursor image changing context, based on mouse
- * relative position.
- */
- void mouseMoved(MouseEvent &event) override;
-
- /**
- * When the mouse button has been let go, this ensures that the mouse
- * custom cursor is restored back to it's standard image.
- */
- void mouseReleased(MouseEvent &event) override;
-
- /**
- * When the mouse leaves the window this ensures that the custom cursor
- * is restored back to it's standard image.
- */
- void mouseExited(MouseEvent &event) override;
-
- void mouseEntered(MouseEvent &event) override;
-
- void updateResizeHandler(MouseEvent &event);
-
- /**
- * Sets the name of the window. This is not the window title.
- */
- void setWindowName(const std::string &name)
- { mWindowName = name; }
-
- /**
- * Returns the name of the window. This is not the window title.
- */
- const std::string &getWindowName() const noexcept2 A_WARN_UNUSED
- { return mWindowName; }
-
- /**
- * Reads the position (and the size for resizable windows) in the
- * configuration based on the given string.
- * Uses the default values when config values are missing.
- * Don't forget to set these default values and resizable before
- * calling this function.
- */
- void loadWindowState();
-
- /**
- * Saves the window state so that when the window is reloaded, it'll
- * maintain its previous state and location.
- */
- void saveWindowState();
-
- /**
- * Set the default win pos and size.
- * (which can be different of the actual ones.)
- */
- void setDefaultSize(const int defaultX, const int defaultY,
- int defaultWidth, int defaultHeight);
-
- /**
- * Set the default win pos and size to the current ones.
- */
- void setDefaultSize();
-
- /**
- * Set the default win pos and size.
- * (which can be different of the actual ones.)
- * This version of setDefaultSize sets the window's position based
- * on a relative enumerated position, rather than a coordinate position.
- */
- void setDefaultSize(const int defaultWidth, const int defaultHeight,
- const ImagePosition::Type &position,
- const int offsetx = 0, const int offsetY = 0);
-
- /**
- * Reset the win pos and size to default. Don't forget to set defaults
- * first.
- */
- virtual void resetToDefaultSize();
-
- /**
- * Adjusts the window position after the application window has been
- * resized.
- */
- void adjustPositionAfterResize(const int oldScreenWidth,
- const int oldScreenHeight);
-
- /**
- * Gets the layout handler for this window.
- */
- Layout &getLayout() A_WARN_UNUSED;
-
- /**
- * Clears the window's layout (useful for redesigning the window). Does
- * not delete the widgets!
- */
- void clearLayout();
-
- /**
- * Computes the position of the widgets according to the current
- * layout. Resizes the window so that the layout fits. Deletes the
- * layout.
- * @param w if non-zero, force the window to this width.
- * @param h if non-zero, force the window to this height.
- * @note This function is meant to be called with fixed-size windows.
- */
- void reflowLayout(int w = 0, int h = 0);
-
- /**
- * Adds a widget to the window and sets it at given cell.
- */
- LayoutCell &place(const int x, const int y, Widget *const wg,
- const int w = 1, const int h = 1);
-
- /**
- * Returns a proxy for adding widgets in an inner table of the layout.
- */
- ContainerPlacer getPlacer(const int x, const int y) A_WARN_UNUSED;
-
- /**
- * Positions the window in the center of it's parent.
- */
- void center();
-
- /**
- * Positions the window in the horisontal center of it's parent.
- */
- void centerHorisontally();
-
- /**
- * Overrideable functionality for when the window is to close. This
- * allows for class implementations to clean up or do certain actions
- * on window close they couldn't do otherwise.
- */
- virtual void close();
-
- /**
- * Allows the windows modal status to change
- */
- void setModal(const Modal modal);
-
- Rect getWindowArea() const A_WARN_UNUSED;
-
- bool isResizeAllowed(const MouseEvent &event) const A_WARN_UNUSED;
-
- void setCaptionFont(Font *font)
- { mCaptionFont = font; }
-
- void enableVisibleSound(bool b)
- { mPlayVisibleSound = b; }
-
- bool isWindowVisible() const noexcept2 A_WARN_UNUSED
- { return mVisible == Visible_true; }
-
- /**
- * Sets the padding of the window. The padding is the distance between the
- * window border and the content.
- *
- * @param padding The padding of the window.
- * @see getPadding
- */
- void setPadding(int padding)
- { mPadding = padding; }
-
- /**
- * Gets the padding of the window. The padding is the distance between the
- * window border and the content.
- *
- * @return The padding of the window.
- * @see setPadding
- */
- int getPadding() const
- { return mPadding; }
-
- /**
- * Sets the title bar height.
- *
- * @param height The title height value.
- * @see getTitleBarHeight
- */
- void setTitleBarHeight(unsigned int height)
- { mTitleBarHeight = height; }
-
- /**
- * Gets the title bar height.
- *
- * @return The title bar height.
- * @see setTitleBarHeight
- */
- unsigned int getTitleBarHeight() const
- { return mTitleBarHeight; }
-
- /**
- * Sets the caption of the window.
- *
- * @param caption The caption of the window.
- * @see getCaption
- */
- void setCaption(const std::string& caption)
- { mCaption = caption; mTextChanged = true; }
-
- /**
- * Gets the caption of the window.
- *
- * @return the caption of the window.
- * @see setCaption
- */
- const std::string& getCaption() const
- { return mCaption; }
-
- /**
- * Sets the alignment of the caption.
- *
- * @param alignment The alignment of the caption.
- * @see getAlignment, Graphics
- */
- void setAlignment(Graphics::Alignment alignment)
- { mAlignment = alignment; }
-
- /**
- * Gets the alignment of the caption.
- *
- * @return The alignment of caption.
- * @see setAlignment, Graphics
- */
- Graphics::Alignment getAlignment() const
- { return mAlignment; }
-
- /**
- * Sets the window to be moveble or not.
- *
- * @param movable True if the window should be movable, false otherwise.
- * @see isMovable
- */
- void setMovable(Move movable)
- { mMovable = movable; }
-
- /**
- * Checks if the window is movable.
- *
- * @return True if the window is movable, false otherwise.
- * @see setMovable
- */
- bool isMovable() const
- { return mMovable == Move_true; }
-
- Rect getChildrenArea() override;
-
- /**
- * Resizes the window to fit the content.
- */
- virtual void resizeToContent();
-
-#ifdef USE_PROFILER
- virtual void logic();
-#endif // USE_PROFILER
-
- protected:
- bool canMove() const A_WARN_UNUSED;
-
- int getOption(const std::string &name,
- const int def = 0) const A_WARN_UNUSED;
-
- bool getOptionBool(const std::string &name,
- const bool def = false) const A_WARN_UNUSED;
-
- void setTitlePadding(const int p) noexcept2
- { mTitlePadding = p; }
-
- int getTitlePadding() const noexcept2 A_WARN_UNUSED
- { return mTitlePadding; }
-
- /**
- * Holds the caption of the window.
- */
- std::string mCaption;
-
- /**
- * Holds the alignment of the caption.
- */
- Graphics::Alignment mAlignment;
-
- /**
- * Holds the padding of the window.
- */
- int mPadding;
-
- /**
- * Holds the title bar height of the window.
- */
- unsigned int mTitleBarHeight;
-
- /**
- * True if the window is movable, false otherwise.
- */
- Move mMovable;
-
- /**
- * Holds a drag offset as an x coordinate where the drag of the window
- * started if the window is being dragged. It's used to move the window
- * correctly when dragged.
- */
- int mDragOffsetX;
-
- /**
- * Holds a drag offset as an y coordinate where the drag of the window
- * started if the window is being dragged. It's used to move the window
- * correctly when dragged.
- */
- int mDragOffsetY;
-
- /**
- * True if the window is being moved, false otherwise.
- */
- bool mMoved;
-
- Skin *mSkin; /**< Skin in use by this window */
- int mDefaultX; /**< Default window X position */
- int mDefaultY; /**< Default window Y position */
- int mDefaultWidth; /**< Default window width */
- int mDefaultHeight; /**< Default window height */
- int mCaptionOffsetX;
- int mCaptionOffsetY;
- bool mShowTitle; /**< Window has a title bar */
- bool mLastRedraw;
-
- private:
- enum ResizeHandles
- {
- TOP = 0x01,
- RIGHT = 0x02,
- BOTTOM = 0x04,
- LEFT = 0x08,
- CLOSE = 0x10
- };
-
- /**
- * Ensures the window is on the screen, moving it if necessary. This is
- * used by loadWindowState and setVisible(true), and when the screen
- * is resized.
- */
- void ensureOnScreen();
-
- void adjustSizeToScreen();
-
- /**
- * Determines if the mouse is in a resize area and returns appropriate
- * resize handles. Also initializes drag offset in case the resize
- * grip is used.
- *
- * @see ResizeHandles
- */
- int getResizeHandles(const MouseEvent &event) A_WARN_UNUSED;
-
- Image *mGrip; /**< Resize grip */
- Window *mParentWindow; /**< The parent window */
- Layout *mLayout; /**< Layout handler */
- Rect mCloseRect; /**< Close button rectangle */
- Rect mStickyRect; /**< Sticky button rectangle */
- Rect mGripRect; /**< Resize grip rectangle */
- TextChunk mTextChunk;
- std::string mWindowName; /**< Name of the window */
- int mMinWinWidth; /**< Minimum window width */
- int mMinWinHeight; /**< Minimum window height */
- int mMaxWinWidth; /**< Maximum window width */
- int mMaxWinHeight; /**< Maximum window height */
-
- static int mouseResize; /**< Active resize handles */
- static int windowInstances; /**< Number of Window instances */
-
-
- /**
- * The width of the resize border. Is independent of the actual window
- * border width, and determines mostly the size of the corner area
- * where two borders are moved at the same time.
- */
- static const unsigned resizeBorderWidth = 10;
- ImageCollection *mVertexes A_NONNULLPOINTER;
- Graphics::Alignment mCaptionAlign;
- int mTitlePadding;
- int mGripPadding;
- int mResizeHandles;
- int mOldResizeHandles;
- int mClosePadding;
- int mStickySpacing;
- int mStickyPadding;
- Font *mCaptionFont A_NONNULLPOINTER;
- Modal mModal; /**< Window is modal */
- bool mCloseWindowButton; /**< Window has a close button */
- bool mDefaultVisible; /**< Window's default visibility */
- bool mSaveVisible; /**< Window will save visibility */
- bool mStickyButton; /**< Window has a sticky button */
- bool mSticky; /**< Window resists hiding*/
- bool mStickyButtonLock; /**< Window locked if sticky enabled*/
- bool mPlayVisibleSound;
- bool mInit;
- bool mTextChanged;
- bool mAllowClose;
-};
-
-#endif // GUI_WIDGETS_WINDOW_H
diff --git a/src/gui/widgets/windowcontainer.cpp b/src/gui/widgets/windowcontainer.cpp
deleted file mode 100644
index e054e27ad..000000000
--- a/src/gui/widgets/windowcontainer.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "gui/widgets/windowcontainer.h"
-
-#include "gui/widgets/window.h"
-
-#include "utils/dtor.h"
-#include "utils/foreach.h"
-
-#include "debug.h"
-
-WindowContainer *windowContainer = nullptr;
-
-WindowContainer::WindowContainer(const Widget2 *const widget) :
- Container(widget),
- mDeathList()
-{
-}
-
-void WindowContainer::slowLogic()
-{
- delete_all(mDeathList);
- mDeathList.clear();
-}
-
-void WindowContainer::scheduleDelete(Widget *const widget)
-{
- if (widget != nullptr)
- mDeathList.push_back(widget);
-}
-
-void WindowContainer::adjustAfterResize(const int oldScreenWidth,
- const int oldScreenHeight)
-{
- FOR_EACH (WidgetListIterator, i, mWidgets)
- {
- if (Window *const window = dynamic_cast<Window*>(*i))
- window->adjustPositionAfterResize(oldScreenWidth, oldScreenHeight);
- }
-}
-
-void WindowContainer::moveWidgetAfter(Widget *const after,
- Widget *const widget)
-{
- const WidgetListIterator widgetIter = std::find(
- mWidgets.begin(), mWidgets.end(), widget);
-
- if (widgetIter != mWidgets.end())
- {
- WidgetListIterator afterIter = std::find(
- mWidgets.begin(), mWidgets.end(), after);
-
- if (afterIter != mWidgets.end())
- {
- ++ afterIter;
- mWidgets.erase(widgetIter);
- mWidgets.insert(afterIter, widget);
- }
- }
-
- const WidgetListIterator widgetIter2 = std::find(
- mLogicWidgets.begin(), mLogicWidgets.end(), 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
-void WindowContainer::draw(Graphics *const graphics)
-{
- BLOCK_START("WindowContainer::draw")
- Container::draw(graphics);
- BLOCK_END("WindowContainer::draw")
-}
-#endif // USE_PROFILER
diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h
deleted file mode 100644
index 98a62ac28..000000000
--- a/src/gui/widgets/windowcontainer.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * The ManaPlus Client
- * Copyright (C) 2004-2009 The Mana World Development Team
- * Copyright (C) 2009-2010 The Mana Developers
- * Copyright (C) 2011-2017 The ManaPlus Developers
- *
- * This file is part of The ManaPlus Client.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GUI_WIDGETS_WINDOWCONTAINER_H
-#define GUI_WIDGETS_WINDOWCONTAINER_H
-
-#include "gui/widgets/container.h"
-
-/**
- * A window container. This container adds functionality for more convenient
- * widget (windows in particular) destruction.
- *
- * \ingroup GUI
- */
-class WindowContainer notfinal : public Container
-{
- public:
- explicit WindowContainer(const Widget2 *const widget);
-
- A_DELETE_COPY(WindowContainer)
-
- void slowLogic();
-
- /**
- * Schedule a widget for deletion. It will be deleted at the start of
- * the next logic update.
- */
- void scheduleDelete(Widget *const widget);
-
- /**
- * Ensures that all visible windows are on the screen after the screen
- * has been resized.
- */
- void adjustAfterResize(const int oldScreenWidth,
- const int oldScreenHeight);
-
- void moveWidgetAfter(Widget *const before,
- Widget *const widget);
-
-#ifdef USE_PROFILER
- void draw(Graphics *const graphics) override A_NONNULL(2);
-#endif // UNITTESTS
-
- private:
- /**
- * List of widgets that are scheduled to be deleted.
- */
- typedef STD_VECTOR<Widget*> Widgets;
- typedef Widgets::iterator WidgetIterator;
- Widgets mDeathList;
-};
-
-extern WindowContainer *windowContainer;
-
-#endif // GUI_WIDGETS_WINDOWCONTAINER_H