summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/base/basiccontainer.cpp384
-rw-r--r--src/gui/base/basiccontainer.hpp218
-rw-r--r--src/gui/base/gui.cpp763
-rw-r--r--src/gui/base/gui.hpp515
-rw-r--r--src/gui/base/widgets/button.cpp192
-rw-r--r--src/gui/base/widgets/button.hpp222
-rw-r--r--src/gui/base/widgets/checkbox.cpp151
-rw-r--r--src/gui/base/widgets/checkbox.hpp183
-rw-r--r--src/gui/base/widgets/container.cpp136
-rw-r--r--src/gui/base/widgets/container.hpp177
-rw-r--r--src/gui/base/widgets/label.cpp122
-rw-r--r--src/gui/base/widgets/label.hpp156
-rw-r--r--src/gui/base/widgets/listbox.cpp240
-rw-r--r--src/gui/base/widgets/listbox.hpp277
-rw-r--r--src/gui/base/widgets/radiobutton.cpp203
-rw-r--r--src/gui/base/widgets/radiobutton.hpp228
-rw-r--r--src/gui/base/widgets/scrollarea.cpp597
-rw-r--r--src/gui/base/widgets/scrollarea.hpp549
-rw-r--r--src/gui/base/widgets/slider.cpp230
-rw-r--r--src/gui/base/widgets/slider.hpp297
-rw-r--r--src/gui/base/widgets/textbox.cpp344
-rw-r--r--src/gui/base/widgets/textbox.hpp311
-rw-r--r--src/gui/base/widgets/textfield.cpp163
-rw-r--r--src/gui/base/widgets/textfield.hpp192
-rw-r--r--src/gui/cliprect.cpp104
-rw-r--r--src/gui/cliprect.h126
-rw-r--r--src/gui/color.cpp165
-rw-r--r--src/gui/color.h193
-rw-r--r--src/gui/focushandler.cpp530
-rw-r--r--src/gui/focushandler.h377
-rw-r--r--src/gui/font.cpp (renamed from src/gui/sdlfont.cpp)136
-rw-r--r--src/gui/font.h (renamed from src/gui/sdlfont.h)94
-rw-r--r--src/gui/gui.cpp163
-rw-r--r--src/gui/gui.h57
-rw-r--r--src/gui/models/avatarlistmodel.h40
-rw-r--r--src/gui/models/beingslistmodel.h62
-rw-r--r--src/gui/models/colorlistmodel.h81
-rw-r--r--src/gui/models/colormodel.cpp (renamed from src/gui/widgets/colormodel.cpp)6
-rw-r--r--src/gui/models/colormodel.h (renamed from src/gui/widgets/colormodel.h)22
-rw-r--r--src/gui/models/extendedlistmodel.h (renamed from src/gui/widgets/extendedlistmodel.h)10
-rw-r--r--src/gui/models/extendednamesmodel.cpp (renamed from src/gui/widgets/extendednamesmodel.cpp)2
-rw-r--r--src/gui/models/extendednamesmodel.h (renamed from src/gui/widgets/extendednamesmodel.h)8
-rw-r--r--src/gui/models/fontsmodel.h42
-rw-r--r--src/gui/models/iconsmodel.h84
-rw-r--r--src/gui/models/ignorechoiceslistmodel.h55
-rw-r--r--src/gui/models/itemsmodel.h86
-rw-r--r--src/gui/models/listmodel.h103
-rw-r--r--src/gui/models/magicschoolmodel.h67
-rw-r--r--src/gui/models/namesmodel.cpp (renamed from src/gui/widgets/namesmodel.cpp)2
-rw-r--r--src/gui/models/namesmodel.h (renamed from src/gui/widgets/namesmodel.h)10
-rw-r--r--src/gui/models/playerrelationlistmodel.h67
-rw-r--r--src/gui/models/questsmodel.h40
-rw-r--r--src/gui/models/serverslistmodel.h109
-rw-r--r--src/gui/models/shopitems.cpp (renamed from src/gui/widgets/shopitems.cpp)2
-rw-r--r--src/gui/models/shopitems.h (renamed from src/gui/widgets/shopitems.h)10
-rw-r--r--src/gui/models/skillmodel.cpp (renamed from src/gui/widgets/skillmodel.cpp)2
-rw-r--r--src/gui/models/skillmodel.h (renamed from src/gui/widgets/skillmodel.h)10
-rw-r--r--src/gui/models/sortlistmodelbuy.h65
-rw-r--r--src/gui/models/sortlistmodelinv.h65
-rw-r--r--src/gui/models/soundsmodel.h (renamed from src/gui/widgets/mouseevent.h)35
-rw-r--r--src/gui/models/tablemodel.cpp (renamed from src/gui/widgets/tablemodel.cpp)10
-rw-r--r--src/gui/models/tablemodel.h (renamed from src/gui/widgets/tablemodel.h)22
-rw-r--r--src/gui/models/targettypemodel.h58
-rw-r--r--src/gui/models/themesmodel.h47
-rw-r--r--src/gui/models/touchactionmodel.cpp84
-rw-r--r--src/gui/models/touchactionmodel.h47
-rw-r--r--src/gui/models/typelistmodel.h65
-rw-r--r--src/gui/models/updatelistmodel.h66
-rw-r--r--src/gui/models/updatetypemodel.h63
-rw-r--r--src/gui/models/worldlistmodel.h68
-rw-r--r--src/gui/palette.cpp30
-rw-r--r--src/gui/palette.h29
-rw-r--r--src/gui/popups/beingpopup.cpp5
-rw-r--r--src/gui/popups/itempopup.cpp7
-rw-r--r--src/gui/popups/itempopup.h3
-rw-r--r--src/gui/popups/popupmenu.cpp16
-rw-r--r--src/gui/popups/popupmenu.h19
-rw-r--r--src/gui/popups/speechbubble.cpp10
-rw-r--r--src/gui/popups/speechbubble.h4
-rw-r--r--src/gui/popups/spellpopup.cpp8
-rw-r--r--src/gui/popups/spellpopup.h5
-rw-r--r--src/gui/popups/statuspopup.cpp2
-rw-r--r--src/gui/popups/textpopup.cpp6
-rw-r--r--src/gui/popups/textpopup.h2
-rw-r--r--src/gui/rect.cpp156
-rw-r--r--src/gui/rect.h162
-rw-r--r--src/gui/sdlfont_unittest.cc92
-rw-r--r--src/gui/sdlinput.cpp62
-rw-r--r--src/gui/sdlinput.h85
-rw-r--r--src/gui/theme.cpp12
-rw-r--r--src/gui/theme.h16
-rw-r--r--src/gui/userpalette.cpp8
-rw-r--r--src/gui/userpalette.h13
-rw-r--r--src/gui/viewport.cpp282
-rw-r--r--src/gui/viewport.h19
-rw-r--r--src/gui/widgets/avatarlistbox.cpp35
-rw-r--r--src/gui/widgets/avatarlistbox.h26
-rw-r--r--src/gui/widgets/browserbox.cpp54
-rw-r--r--src/gui/widgets/browserbox.h38
-rw-r--r--src/gui/widgets/browserbox_unittest.cc4
-rw-r--r--src/gui/widgets/button.cpp112
-rw-r--r--src/gui/widgets/button.h45
-rw-r--r--src/gui/widgets/characterdisplay.cpp17
-rw-r--r--src/gui/widgets/characterdisplay.h22
-rw-r--r--src/gui/widgets/characterviewbase.h6
-rw-r--r--src/gui/widgets/characterviewnormal.cpp3
-rw-r--r--src/gui/widgets/characterviewnormal.h2
-rw-r--r--src/gui/widgets/characterviewsmall.cpp4
-rw-r--r--src/gui/widgets/characterviewsmall.h4
-rw-r--r--src/gui/widgets/checkbox.cpp37
-rw-r--r--src/gui/widgets/checkbox.h19
-rw-r--r--src/gui/widgets/colorpage.cpp21
-rw-r--r--src/gui/widgets/colorpage.h4
-rw-r--r--src/gui/widgets/container.cpp7
-rw-r--r--src/gui/widgets/container.h13
-rw-r--r--src/gui/widgets/desktop.cpp27
-rw-r--r--src/gui/widgets/desktop.h13
-rw-r--r--src/gui/widgets/dropdown.cpp96
-rw-r--r--src/gui/widgets/dropdown.h65
-rw-r--r--src/gui/widgets/dropshortcutcontainer.cpp41
-rw-r--r--src/gui/widgets/dropshortcutcontainer.h24
-rw-r--r--src/gui/widgets/emotepage.cpp22
-rw-r--r--src/gui/widgets/emotepage.h22
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp35
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.h20
-rw-r--r--src/gui/widgets/extendedlistbox.cpp33
-rw-r--r--src/gui/widgets/extendedlistbox.h4
-rw-r--r--src/gui/widgets/flowcontainer.cpp11
-rw-r--r--src/gui/widgets/flowcontainer.h11
-rw-r--r--src/gui/widgets/guitable.cpp94
-rw-r--r--src/gui/widgets/guitable.h43
-rw-r--r--src/gui/widgets/horizontcontainer.cpp11
-rw-r--r--src/gui/widgets/horizontcontainer.h14
-rw-r--r--src/gui/widgets/icon.cpp19
-rw-r--r--src/gui/widgets/icon.h15
-rw-r--r--src/gui/widgets/inttextfield.cpp18
-rw-r--r--src/gui/widgets/inttextfield.h11
-rw-r--r--src/gui/widgets/itemcontainer.cpp56
-rw-r--r--src/gui/widgets/itemcontainer.h56
-rw-r--r--src/gui/widgets/itemlinkhandler.cpp20
-rw-r--r--src/gui/widgets/itemlinkhandler.h2
-rw-r--r--src/gui/widgets/itemshortcutcontainer.cpp60
-rw-r--r--src/gui/widgets/itemshortcutcontainer.h25
-rw-r--r--src/gui/widgets/label.cpp31
-rw-r--r--src/gui/widgets/label.h17
-rw-r--r--src/gui/widgets/layout.cpp8
-rw-r--r--src/gui/widgets/layout.h17
-rw-r--r--src/gui/widgets/layouthelper.cpp10
-rw-r--r--src/gui/widgets/layouthelper.h8
-rw-r--r--src/gui/widgets/linkhandler.h4
-rw-r--r--src/gui/widgets/listbox.cpp56
-rw-r--r--src/gui/widgets/listbox.h35
-rw-r--r--src/gui/widgets/passwordfield.cpp2
-rw-r--r--src/gui/widgets/passwordfield.h2
-rw-r--r--src/gui/widgets/playerbox.cpp34
-rw-r--r--src/gui/widgets/playerbox.h20
-rw-r--r--src/gui/widgets/popup.cpp35
-rw-r--r--src/gui/widgets/popup.h21
-rw-r--r--src/gui/widgets/popuplist.cpp20
-rw-r--r--src/gui/widgets/popuplist.h24
-rw-r--r--src/gui/widgets/progressbar.cpp36
-rw-r--r--src/gui/widgets/progressbar.h33
-rw-r--r--src/gui/widgets/progressindicator.cpp11
-rw-r--r--src/gui/widgets/progressindicator.h11
-rw-r--r--src/gui/widgets/radiobutton.cpp34
-rw-r--r--src/gui/widgets/radiobutton.h17
-rw-r--r--src/gui/widgets/radiogroup.cpp2
-rw-r--r--src/gui/widgets/radiogroup.h9
-rw-r--r--src/gui/widgets/scrollarea.cpp312
-rw-r--r--src/gui/widgets/scrollarea.h80
-rw-r--r--src/gui/widgets/setupitem.cpp52
-rw-r--r--src/gui/widgets/setupitem.h59
-rw-r--r--src/gui/widgets/setuptouchitem.cpp64
-rw-r--r--src/gui/widgets/setuptouchitem.h20
-rw-r--r--src/gui/widgets/shoplistbox.cpp31
-rw-r--r--src/gui/widgets/shoplistbox.h16
-rw-r--r--src/gui/widgets/shortcutcontainer.cpp21
-rw-r--r--src/gui/widgets/shortcutcontainer.h28
-rw-r--r--src/gui/widgets/skillinfo.cpp3
-rw-r--r--src/gui/widgets/skillinfo.h4
-rw-r--r--src/gui/widgets/slider.cpp88
-rw-r--r--src/gui/widgets/slider.h30
-rw-r--r--src/gui/widgets/sliderlist.cpp23
-rw-r--r--src/gui/widgets/sliderlist.h24
-rw-r--r--src/gui/widgets/spellshortcutcontainer.cpp48
-rw-r--r--src/gui/widgets/spellshortcutcontainer.h17
-rw-r--r--src/gui/widgets/tabbedarea.cpp123
-rw-r--r--src/gui/widgets/tabbedarea.h94
-rw-r--r--src/gui/widgets/tabs/chattab.cpp8
-rw-r--r--src/gui/widgets/tabs/chattab.h3
-rw-r--r--src/gui/widgets/tabs/guildchattab.h3
-rw-r--r--src/gui/widgets/tabs/langtab.cpp3
-rw-r--r--src/gui/widgets/tabs/langtab.h3
-rw-r--r--src/gui/widgets/tabs/setup_audio.cpp19
-rw-r--r--src/gui/widgets/tabs/setup_audio.h4
-rw-r--r--src/gui/widgets/tabs/setup_chat.cpp2
-rw-r--r--src/gui/widgets/tabs/setup_colors.cpp34
-rw-r--r--src/gui/widgets/tabs/setup_colors.h10
-rw-r--r--src/gui/widgets/tabs/setup_input.cpp14
-rw-r--r--src/gui/widgets/tabs/setup_input.h2
-rw-r--r--src/gui/widgets/tabs/setup_joystick.cpp9
-rw-r--r--src/gui/widgets/tabs/setup_joystick.h2
-rw-r--r--src/gui/widgets/tabs/setup_mods.cpp2
-rw-r--r--src/gui/widgets/tabs/setup_other.cpp5
-rw-r--r--src/gui/widgets/tabs/setup_perfomance.cpp5
-rw-r--r--src/gui/widgets/tabs/setup_players.cpp2
-rw-r--r--src/gui/widgets/tabs/setup_relations.cpp77
-rw-r--r--src/gui/widgets/tabs/setup_relations.h12
-rw-r--r--src/gui/widgets/tabs/setup_theme.cpp39
-rw-r--r--src/gui/widgets/tabs/setup_theme.h2
-rw-r--r--src/gui/widgets/tabs/setup_touch.cpp6
-rw-r--r--src/gui/widgets/tabs/setup_touch.h5
-rw-r--r--src/gui/widgets/tabs/setup_video.cpp18
-rw-r--r--src/gui/widgets/tabs/setup_video.h7
-rw-r--r--src/gui/widgets/tabs/setup_visual.cpp5
-rw-r--r--src/gui/widgets/tabs/setup_visual.h2
-rw-r--r--src/gui/widgets/tabs/setuptab.cpp4
-rw-r--r--src/gui/widgets/tabs/setuptab.h8
-rw-r--r--src/gui/widgets/tabs/setuptabscroll.cpp4
-rw-r--r--src/gui/widgets/tabs/setuptabscroll.h4
-rw-r--r--src/gui/widgets/tabs/tab.cpp91
-rw-r--r--src/gui/widgets/tabs/tab.h107
-rw-r--r--src/gui/widgets/tabs/whispertab.cpp3
-rw-r--r--src/gui/widgets/tabs/whispertab.h3
-rw-r--r--src/gui/widgets/tabstrip.cpp12
-rw-r--r--src/gui/widgets/tabstrip.h14
-rw-r--r--src/gui/widgets/textbox.cpp36
-rw-r--r--src/gui/widgets/textbox.h17
-rw-r--r--src/gui/widgets/textfield.cpp55
-rw-r--r--src/gui/widgets/textfield.h26
-rw-r--r--src/gui/widgets/textpreview.cpp45
-rw-r--r--src/gui/widgets/textpreview.h32
-rw-r--r--src/gui/widgets/vertcontainer.cpp13
-rw-r--r--src/gui/widgets/vertcontainer.h16
-rw-r--r--src/gui/widgets/widget.cpp666
-rw-r--r--src/gui/widgets/widget.h1230
-rw-r--r--src/gui/widgets/widget2.h23
-rw-r--r--src/gui/widgets/widgetgroup.cpp13
-rw-r--r--src/gui/widgets/widgetgroup.h17
-rw-r--r--src/gui/widgets/window.cpp254
-rw-r--r--src/gui/widgets/window.h245
-rw-r--r--src/gui/widgets/windowcontainer.cpp8
-rw-r--r--src/gui/widgets/windowcontainer.h10
-rw-r--r--src/gui/windowmenu.cpp38
-rw-r--r--src/gui/windowmenu.h26
-rw-r--r--src/gui/windows/botcheckerwindow.cpp24
-rw-r--r--src/gui/windows/botcheckerwindow.h10
-rw-r--r--src/gui/windows/buydialog.cpp61
-rw-r--r--src/gui/windows/buydialog.h13
-rw-r--r--src/gui/windows/buyselldialog.cpp6
-rw-r--r--src/gui/windows/buyselldialog.h7
-rw-r--r--src/gui/windows/changeemaildialog.cpp4
-rw-r--r--src/gui/windows/changeemaildialog.h7
-rw-r--r--src/gui/windows/changepassworddialog.cpp4
-rw-r--r--src/gui/windows/changepassworddialog.h7
-rw-r--r--src/gui/windows/charcreatedialog.cpp39
-rw-r--r--src/gui/windows/charcreatedialog.h16
-rw-r--r--src/gui/windows/charselectdialog.cpp30
-rw-r--r--src/gui/windows/charselectdialog.h15
-rw-r--r--src/gui/windows/chatwindow.cpp97
-rw-r--r--src/gui/windows/chatwindow.h30
-rw-r--r--src/gui/windows/confirmdialog.cpp6
-rw-r--r--src/gui/windows/confirmdialog.h7
-rw-r--r--src/gui/windows/connectiondialog.cpp8
-rw-r--r--src/gui/windows/connectiondialog.h9
-rw-r--r--src/gui/windows/debugwindow.cpp17
-rw-r--r--src/gui/windows/debugwindow.h6
-rw-r--r--src/gui/windows/didyouknowwindow.cpp15
-rw-r--r--src/gui/windows/didyouknowwindow.h8
-rw-r--r--src/gui/windows/editdialog.cpp4
-rw-r--r--src/gui/windows/editdialog.h7
-rw-r--r--src/gui/windows/editserverdialog.cpp63
-rw-r--r--src/gui/windows/editserverdialog.h48
-rw-r--r--src/gui/windows/emotewindow.cpp15
-rw-r--r--src/gui/windows/emotewindow.h6
-rw-r--r--src/gui/windows/equipmentwindow.cpp68
-rw-r--r--src/gui/windows/equipmentwindow.h25
-rw-r--r--src/gui/windows/helpwindow.cpp16
-rw-r--r--src/gui/windows/helpwindow.h11
-rw-r--r--src/gui/windows/inventorywindow.cpp100
-rw-r--r--src/gui/windows/inventorywindow.h34
-rw-r--r--src/gui/windows/itemamountwindow.cpp67
-rw-r--r--src/gui/windows/itemamountwindow.h16
-rw-r--r--src/gui/windows/killstats.cpp4
-rw-r--r--src/gui/windows/killstats.h9
-rw-r--r--src/gui/windows/logindialog.cpp93
-rw-r--r--src/gui/windows/logindialog.h13
-rw-r--r--src/gui/windows/minimap.cpp34
-rw-r--r--src/gui/windows/minimap.h8
-rw-r--r--src/gui/windows/ministatuswindow.cpp18
-rw-r--r--src/gui/windows/ministatuswindow.h13
-rw-r--r--src/gui/windows/npcdialog.cpp20
-rw-r--r--src/gui/windows/npcdialog.h14
-rw-r--r--src/gui/windows/npcpostdialog.cpp8
-rw-r--r--src/gui/windows/npcpostdialog.h6
-rw-r--r--src/gui/windows/okdialog.cpp6
-rw-r--r--src/gui/windows/okdialog.h6
-rw-r--r--src/gui/windows/outfitwindow.cpp35
-rw-r--r--src/gui/windows/outfitwindow.h18
-rw-r--r--src/gui/windows/questswindow.cpp30
-rw-r--r--src/gui/windows/questswindow.h6
-rw-r--r--src/gui/windows/quitdialog.cpp18
-rw-r--r--src/gui/windows/quitdialog.h13
-rw-r--r--src/gui/windows/registerdialog.cpp22
-rw-r--r--src/gui/windows/registerdialog.h16
-rw-r--r--src/gui/windows/selldialog.cpp33
-rw-r--r--src/gui/windows/selldialog.h12
-rw-r--r--src/gui/windows/serverdialog.cpp118
-rw-r--r--src/gui/windows/serverdialog.h67
-rw-r--r--src/gui/windows/setupwindow.cpp15
-rw-r--r--src/gui/windows/setupwindow.h8
-rw-r--r--src/gui/windows/shopwindow.cpp15
-rw-r--r--src/gui/windows/shopwindow.h12
-rw-r--r--src/gui/windows/shortcutwindow.cpp17
-rw-r--r--src/gui/windows/shortcutwindow.h8
-rw-r--r--src/gui/windows/skilldialog.cpp50
-rw-r--r--src/gui/windows/skilldialog.h9
-rw-r--r--src/gui/windows/socialwindow.cpp130
-rw-r--r--src/gui/windows/socialwindow.h11
-rw-r--r--src/gui/windows/statuswindow.cpp16
-rw-r--r--src/gui/windows/statuswindow.h8
-rw-r--r--src/gui/windows/textcommandeditor.cpp135
-rw-r--r--src/gui/windows/textcommandeditor.h11
-rw-r--r--src/gui/windows/textdialog.cpp8
-rw-r--r--src/gui/windows/textdialog.h7
-rw-r--r--src/gui/windows/tradewindow.cpp23
-rw-r--r--src/gui/windows/tradewindow.h12
-rw-r--r--src/gui/windows/unregisterdialog.cpp4
-rw-r--r--src/gui/windows/unregisterdialog.h7
-rw-r--r--src/gui/windows/updaterwindow.cpp25
-rw-r--r--src/gui/windows/updaterwindow.h14
-rw-r--r--src/gui/windows/whoisonline.cpp20
-rw-r--r--src/gui/windows/whoisonline.h12
-rw-r--r--src/gui/windows/worldselectdialog.cpp60
-rw-r--r--src/gui/windows/worldselectdialog.h13
335 files changed, 15771 insertions, 4206 deletions
diff --git a/src/gui/base/basiccontainer.cpp b/src/gui/base/basiccontainer.cpp
new file mode 100644
index 000000000..f323366ad
--- /dev/null
+++ b/src/gui/base/basiccontainer.cpp
@@ -0,0 +1,384 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/base/basiccontainer.hpp"
+
+#include <algorithm>
+
+#include "debug.h"
+
+namespace gcn
+{
+ BasicContainer::~BasicContainer()
+ {
+ clear();
+ }
+
+ void BasicContainer::moveToTop(Widget* widget)
+ {
+ for (WidgetListIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
+ if (*iter == widget)
+ {
+ mWidgets.erase(iter);
+ mWidgets.push_back(widget);
+ return;
+ }
+ }
+ }
+
+ void BasicContainer::moveToBottom(Widget* widget)
+ {
+ WidgetListIterator iter;
+ iter = std::find(mWidgets.begin(), mWidgets.end(), widget);
+
+ if (iter == mWidgets.end())
+ return;
+
+ mWidgets.erase(iter);
+ mWidgets.insert(mWidgets.begin(), widget);
+ }
+
+ void BasicContainer::death(const Event& event)
+ {
+ WidgetListIterator iter;
+ iter = std::find(mWidgets.begin(), mWidgets.end(), event.getSource());
+
+ if (iter == mWidgets.end())
+ return;
+
+ mWidgets.erase(iter);
+ }
+
+ Rect BasicContainer::getChildrenArea()
+ {
+ return Rect(0, 0, getWidth(), getHeight());
+ }
+
+ void BasicContainer::focusNext()
+ {
+ WidgetListConstIterator it;
+
+ for (it = mWidgets.begin(); it != mWidgets.end(); ++ it)
+ {
+ if ((*it)->isFocused())
+ break;
+ }
+
+ 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()
+ {
+ 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)
+ {
+ 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)
+ {
+ if ((*it)->isVisible() && (*it)->getDimension()
+ .isPointInRect(x, y))
+ {
+ return (*it);
+ }
+ }
+
+ return nullptr;
+ }
+
+ void BasicContainer::logic()
+ {
+ BLOCK_START("BasicContainer::logic")
+ logicChildren();
+ BLOCK_END("BasicContainer::logic")
+ }
+
+ void BasicContainer::_setFocusHandler(FocusHandler* focusHandler)
+ {
+ Widget::_setFocusHandler(focusHandler);
+
+ if (mInternalFocusHandler)
+ return;
+
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
+ (*iter)->_setFocusHandler(focusHandler);
+ }
+ }
+
+ void BasicContainer::add(Widget* widget)
+ {
+ mWidgets.push_back(widget);
+
+ if (!mInternalFocusHandler)
+ widget->_setFocusHandler(_getFocusHandler());
+ else
+ widget->_setFocusHandler(mInternalFocusHandler);
+
+ widget->_setParent(this);
+ widget->addDeathListener(this);
+ }
+
+ void BasicContainer::remove(Widget* widget)
+ {
+ for (WidgetListIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
+ if (*iter == widget)
+ {
+ mWidgets.erase(iter);
+ widget->_setFocusHandler(nullptr);
+ widget->_setParent(nullptr);
+ widget->removeDeathListener(this);
+ return;
+ }
+ }
+ }
+
+ void BasicContainer::clear()
+ {
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
+ (*iter)->_setFocusHandler(nullptr);
+ (*iter)->_setParent(nullptr);
+ (*iter)->removeDeathListener(this);
+ }
+
+ mWidgets.clear();
+ }
+
+ void BasicContainer::drawChildren(Graphics* graphics)
+ {
+ BLOCK_START("BasicContainer::drawChildren")
+
+ graphics->pushClipArea(getChildrenArea());
+
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
+ Widget *const widget = *iter;
+ if (widget->isVisible())
+ {
+ // If the widget has a frame,
+ // draw it before drawing the widget
+ if (widget->getFrameSize() > 0)
+ {
+ Rect rec = widget->getDimension();
+ const int frame = widget->getFrameSize();
+ 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->getDimension());
+ BLOCK_START("BasicContainer::drawChildren 2")
+ widget->draw(graphics);
+ BLOCK_END("BasicContainer::drawChildren 2")
+ graphics->popClipArea();
+ }
+ }
+
+ graphics->popClipArea();
+ BLOCK_END("BasicContainer::drawChildren")
+ }
+
+ void BasicContainer::logicChildren()
+ {
+ BLOCK_START("BasicContainer::logicChildren")
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
+ (*iter)->logic();
+ }
+ BLOCK_END("BasicContainer::logicChildren")
+ }
+
+ void BasicContainer::showWidgetPart(Widget* widget, Rect area)
+ {
+ const Rect widgetArea = getChildrenArea();
+
+ area.x += widget->getX();
+ area.y += widget->getY();
+
+ if (area.x + area.width > widgetArea.width)
+ {
+ widget->setX(widget->getX() - area.x
+ - area.width + widgetArea.width);
+ }
+
+ if (area.y + area.height > widgetArea.height)
+ {
+ widget->setY(widget->getY() - area.y
+ - area.height + widgetArea.height);
+ }
+
+ if (area.x < 0)
+ widget->setX(widget->getX() - area.x);
+
+ if (area.y < 0)
+ widget->setY(widget->getY() - area.y);
+ }
+
+ void BasicContainer::setInternalFocusHandler(FocusHandler* focusHandler)
+ {
+ Widget::setInternalFocusHandler(focusHandler);
+
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
+ if (!mInternalFocusHandler)
+ (*iter)->_setFocusHandler(_getFocusHandler());
+ else
+ (*iter)->_setFocusHandler(mInternalFocusHandler);
+ }
+ }
+
+ Widget* BasicContainer::findWidgetById(const std::string& id)
+ {
+ for (WidgetListConstIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++ iter)
+ {
+ if ((*iter)->getId() == id)
+ return (*iter);
+
+ BasicContainer *const basicContainer
+ = dynamic_cast<BasicContainer *const>(*iter);
+
+ if (basicContainer)
+ {
+ Widget *const widget = basicContainer->findWidgetById(id);
+
+ if (widget)
+ return widget;
+ }
+ }
+
+ return nullptr;
+ }
+} // namespace gcn
diff --git a/src/gui/base/basiccontainer.hpp b/src/gui/base/basiccontainer.hpp
new file mode 100644
index 000000000..e1947c652
--- /dev/null
+++ b/src/gui/base/basiccontainer.hpp
@@ -0,0 +1,218 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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 GCN_BASICCONTAINER_HPP
+#define GCN_BASICCONTAINER_HPP
+
+#include <vector>
+
+#include "gui/widgets/widget.h"
+
+#include "listeners/deathlistener.h"
+
+namespace gcn
+{
+ /**
+ * 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
+ * @since 0.6.0
+ */
+ class BasicContainer : public Widget,
+ public DeathListener
+ {
+ public:
+ explicit BasicContainer(const Widget2 *const widget) :
+ Widget(widget),
+ DeathListener(),
+ mWidgets()
+ { }
+
+ 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 rectangle The rectangle to be visible.
+ */
+ virtual void showWidgetPart(Widget* widget, Rect area);
+
+ // Inherited from Widget
+
+ virtual void moveToTop(Widget* widget);
+
+ virtual void moveToBottom(Widget* widget);
+
+ virtual Rect getChildrenArea() A_WARN_UNUSED;
+
+ virtual void focusNext();
+
+ virtual void focusPrevious();
+
+ virtual void logic();
+
+ virtual void _setFocusHandler(FocusHandler* focusHandler);
+
+ void setInternalFocusHandler(FocusHandler* focusHandler);
+
+ virtual Widget *getWidgetAt(int x, int y) A_WARN_UNUSED;
+
+
+ // Inherited from DeathListener
+
+ virtual void death(const Event& event);
+
+ protected:
+ /**
+ * Adds a widget to the basic container.
+ *
+ * @param widget The widget to add.
+ * @see remove, clear
+ */
+ void add(Widget* widget);
+
+ /**
+ * Removes a widget from the basic container.
+ *
+ * @param widget The widget to remove.
+ * @see add, clear
+ */
+ virtual void remove(Widget* widget);
+
+ /**
+ * Clears the basic container from all widgets.
+ *
+ * @see remove, clear
+ */
+ virtual void clear();
+
+ /**
+ * Draws the children widgets of the basic container.
+ *
+ * @param graphics A graphics object to draw with.
+ */
+ virtual void drawChildren(Graphics* graphics);
+
+ /**
+ * Calls logic for the children widgets of the basic
+ * container.
+ */
+ virtual void logicChildren();
+
+ /**
+ * Finds a widget given an id. This function can be useful
+ * when implementing a GUI generator for Guichan, such as
+ * the ability to create a Guichan GUI from an XML file.
+ *
+ * @param id The id to find a widget by.
+ * @return The widget with the corrosponding id,
+ NULL of no widget is found.
+ */
+ virtual Widget* findWidgetById(const std::string& id) A_WARN_UNUSED;
+
+ /**
+ * Typedef.
+ */
+ typedef std::vector<Widget *> WidgetList;
+
+ /**
+ * 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;
+ };
+} // namespace gcn
+
+#endif // end GCN_BASICCONTAINER_HPP
diff --git a/src/gui/base/gui.cpp b/src/gui/base/gui.cpp
new file mode 100644
index 000000000..8985ec062
--- /dev/null
+++ b/src/gui/base/gui.cpp
@@ -0,0 +1,763 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/base/gui.hpp"
+
+#include "gui/widgets/widget.h"
+
+#include "gui/focushandler.h"
+
+#include "input/mouseinput.h"
+
+#include "listeners/keylistener.h"
+#include "listeners/mouselistener.h"
+
+#include "debug.h"
+
+namespace gcn
+{
+ Gui::Gui() :
+ mTop(nullptr),
+ mGraphics(nullptr),
+ mInput(nullptr),
+ mFocusHandler(new FocusHandler),
+ mTabbing(true),
+ mKeyListeners(),
+ mShiftPressed(false),
+ mMetaPressed(false),
+ mControlPressed(false),
+ mAltPressed(false),
+ mLastMousePressButton(0),
+ mLastMousePressTimeStamp(0),
+ mLastMouseX(0),
+ mLastMouseY(0),
+ mClickCount(1),
+ mLastMouseDragButton(0),
+ mWidgetWithMouseQueue()
+ {
+ }
+
+ Gui::~Gui()
+ {
+ if (Widget::widgetExists(mTop))
+ setTop(nullptr);
+
+ delete mFocusHandler;
+ mFocusHandler = nullptr;
+ }
+
+ void Gui::setTop(Widget* top)
+ {
+ if (mTop)
+ mTop->_setFocusHandler(nullptr);
+ if (top)
+ top->_setFocusHandler(mFocusHandler);
+
+ mTop = top;
+ }
+
+ Widget* Gui::getTop() const
+ {
+ return mTop;
+ }
+
+ void Gui::setGraphics(Graphics* graphics)
+ {
+ mGraphics = graphics;
+ }
+
+ Graphics* Gui::getGraphics() const
+ {
+ return mGraphics;
+ }
+
+ void Gui::setInput(SDLInput* input)
+ {
+ mInput = input;
+ }
+
+ SDLInput* Gui::getInput() const
+ {
+ return mInput;
+ }
+
+ void Gui::logic()
+ {
+ }
+
+ void Gui::draw()
+ {
+ }
+
+ void Gui::focusNone()
+ {
+ mFocusHandler->focusNone();
+ }
+
+ void Gui::setTabbingEnabled(bool tabbing)
+ {
+ mTabbing = tabbing;
+ }
+
+ bool Gui::isTabbingEnabled()
+ {
+ return mTabbing;
+ }
+
+ void Gui::addGlobalKeyListener(KeyListener* keyListener)
+ {
+ mKeyListeners.push_back(keyListener);
+ }
+
+ void Gui::removeGlobalKeyListener(KeyListener* keyListener)
+ {
+ mKeyListeners.remove(keyListener);
+ }
+
+ void Gui::handleMouseInput()
+ {
+ }
+
+ void Gui::handleKeyInput()
+ {
+ }
+
+ void Gui::handleMouseMoved(const MouseInput& mouseInput)
+ {
+ // Check if the mouse leaves the application window.
+ if (!mWidgetWithMouseQueue.empty() && (mouseInput.getX() < 0
+ || mouseInput.getY() < 0 || !mTop->getDimension().isPointInRect(
+ mouseInput.getX(), mouseInput.getY())))
+ {
+ // Distribute an event to all widgets in the
+ // "widget with mouse" queue.
+ while (!mWidgetWithMouseQueue.empty())
+ {
+ Widget *const widget = mWidgetWithMouseQueue.front();
+
+ if (Widget::widgetExists(widget))
+ {
+ distributeMouseEvent(widget,
+ MouseEvent::EXITED,
+ mouseInput.getButton(),
+ mouseInput.getX(),
+ mouseInput.getY(),
+ true,
+ true);
+ }
+
+ mWidgetWithMouseQueue.pop_front();
+ }
+
+ return;
+ }
+
+ // Check if there is a need to send mouse exited events by
+ // traversing the "widget with mouse" queue.
+ bool widgetWithMouseQueueCheckDone = mWidgetWithMouseQueue.empty();
+ while (!widgetWithMouseQueueCheckDone)
+ {
+ unsigned int iterations = 0;
+ for (std::deque<Widget*>::iterator
+ iter = mWidgetWithMouseQueue.begin();
+ iter != mWidgetWithMouseQueue.end();
+ ++ iter)
+ {
+ Widget *const widget = *iter;
+
+ // If a widget in the "widget with mouse queue" doesn't
+ // exists anymore it should be removed from the queue.
+ if (!Widget::widgetExists(widget))
+ {
+ mWidgetWithMouseQueue.erase(iter);
+ break;
+ }
+ else
+ {
+ int x, y;
+ widget->getAbsolutePosition(x, y);
+
+ if (x > mouseInput.getX()
+ || y > mouseInput.getY()
+ || x + widget->getWidth() <= mouseInput.getX()
+ || y + widget->getHeight() <= mouseInput.getY()
+ || !widget->isVisible())
+ {
+ distributeMouseEvent(widget,
+ MouseEvent::EXITED,
+ mouseInput.getButton(),
+ mouseInput.getX(),
+ mouseInput.getY(),
+ true,
+ true);
+ mClickCount = 1;
+ mLastMousePressTimeStamp = 0;
+ mWidgetWithMouseQueue.erase(iter);
+ break;
+ }
+ }
+
+ iterations++;
+ }
+
+ widgetWithMouseQueueCheckDone =
+ (iterations == mWidgetWithMouseQueue.size());
+ }
+
+ // Check all widgets below the mouse to see if they are
+ // present in the "widget with mouse" queue. If a widget
+ // is not then it should be added and an entered event should
+ // be sent to it.
+ Widget* parent = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
+ Widget* widget = parent;
+
+ // If a widget has modal mouse input focus then it will
+ // always be returned from getMouseEventSource, but we only wan't to
+ // send mouse entered events if the mouse has actually entered the
+ // widget with modal mouse input focus, hence we need to check if
+ // that's the case. If it's not we should simply ignore to send any
+ // mouse entered events.
+ if (mFocusHandler->getModalMouseInputFocused()
+ && widget == mFocusHandler->getModalMouseInputFocused()
+ && Widget::widgetExists(widget))
+ {
+ int x, y;
+ widget->getAbsolutePosition(x, y);
+
+ if (x > mouseInput.getX() || y > mouseInput.getY()
+ || x + widget->getWidth() <= mouseInput.getX()
+ || y + widget->getHeight() <= mouseInput.getY())
+ {
+ parent = nullptr;
+ }
+ }
+
+ while (parent)
+ {
+ parent = widget->getParent();
+
+ // Check if the widget is present in the "widget with mouse" queue.
+ bool widgetIsPresentInQueue = false;
+ FOR_EACH (std::deque<Widget*>::const_iterator,
+ iter, mWidgetWithMouseQueue)
+ {
+ if (*iter == widget)
+ {
+ widgetIsPresentInQueue = true;
+ break;
+ }
+ }
+
+ // Widget is not present, send an entered event and add
+ // it to the "widget with mouse" queue.
+ if (!widgetIsPresentInQueue
+ && Widget::widgetExists(widget))
+ {
+ distributeMouseEvent(widget,
+ MouseEvent::ENTERED,
+ mouseInput.getButton(),
+ mouseInput.getX(),
+ mouseInput.getY(),
+ true,
+ true);
+ mWidgetWithMouseQueue.push_front(widget);
+ }
+
+ const Widget *const swap = widget;
+ widget = parent;
+ parent = swap->getParent();
+ }
+
+ if (mFocusHandler->getDraggedWidget())
+ {
+ distributeMouseEvent(mFocusHandler->getDraggedWidget(),
+ MouseEvent::DRAGGED,
+ mLastMouseDragButton,
+ mouseInput.getX(),
+ mouseInput.getY());
+ }
+ else
+ {
+ Widget *const sourceWidget = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
+
+ distributeMouseEvent(sourceWidget,
+ MouseEvent::MOVED,
+ mouseInput.getButton(),
+ mouseInput.getX(),
+ mouseInput.getY());
+ }
+ }
+
+ void Gui::handleMouseWheelMovedDown(const MouseInput& mouseInput)
+ {
+ Widget* sourceWidget = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
+
+ if (mFocusHandler->getDraggedWidget())
+ sourceWidget = mFocusHandler->getDraggedWidget();
+
+ int sourceWidgetX, sourceWidgetY;
+ sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
+
+ distributeMouseEvent(sourceWidget,
+ MouseEvent::WHEEL_MOVED_DOWN,
+ mouseInput.getButton(),
+ mouseInput.getX(),
+ mouseInput.getY());
+ }
+
+ void Gui::handleMouseWheelMovedUp(const MouseInput& mouseInput)
+ {
+ Widget* sourceWidget = getMouseEventSource(
+ mouseInput.getX(), mouseInput.getY());
+
+ if (mFocusHandler->getDraggedWidget())
+ sourceWidget = mFocusHandler->getDraggedWidget();
+
+ int sourceWidgetX, sourceWidgetY;
+ sourceWidget->getAbsolutePosition(sourceWidgetX, sourceWidgetY);
+
+ distributeMouseEvent(sourceWidget,
+ MouseEvent::WHEEL_MOVED_UP,
+ mouseInput.getButton(),
+ mouseInput.getX(),
+ mouseInput.getY());
+ }
+
+ Widget* Gui::getWidgetAt(int x, int y)
+ {
+ // If the widget's parent has no child then we have found the widget..
+ Widget* parent = mTop;
+ Widget* child = mTop;
+
+ while (child)
+ {
+ Widget *const swap = child;
+ int parentX, parentY;
+ parent->getAbsolutePosition(parentX, parentY);
+ child = parent->getWidgetAt(x - parentX, y - parentY);
+ parent = swap;
+ }
+
+ return parent;
+ }
+
+ Widget* Gui::getMouseEventSource(int x, int y)
+ {
+ Widget *const widget = getWidgetAt(x, y);
+
+ // +++ possible nullpointer
+ if (mFocusHandler->getModalMouseInputFocused()
+ && !widget->isModalMouseInputFocused())
+ {
+ return mFocusHandler->getModalMouseInputFocused();
+ }
+
+ return widget;
+ }
+
+ Widget* Gui::getKeyEventSource()
+ {
+ Widget* widget = mFocusHandler->getFocused();
+
+ // +++ possible nullpointer
+ while (widget->_getInternalFocusHandler()
+ && widget->_getInternalFocusHandler()->getFocused())
+ {
+ widget = widget->_getInternalFocusHandler()->getFocused();
+ }
+
+ return widget;
+ }
+
+ void Gui::distributeMouseEvent(Widget* source,
+ int type,
+ int button,
+ int x,
+ int y,
+ bool force,
+ bool toSourceOnly)
+ {
+ Widget* parent = source;
+ Widget* widget = source;
+
+ if (mFocusHandler->getModalFocused()
+ && !widget->isModalFocused()
+ && !force)
+ {
+ return;
+ }
+
+ if (mFocusHandler->getModalMouseInputFocused()
+ && !widget->isModalMouseInputFocused()
+ && !force)
+ {
+ return;
+ }
+
+ MouseEvent mouseEvent(source,
+ mShiftPressed,
+ mControlPressed,
+ mAltPressed,
+ mMetaPressed,
+ type,
+ button,
+ x,
+ y,
+ mClickCount);
+
+ while (parent)
+ {
+ // If the widget has been removed due to input
+ // cancel the distribution.
+ if (!Widget::widgetExists(widget))
+ break;
+
+ parent = widget->getParent();
+
+ if (widget->isEnabled() || force)
+ {
+ int widgetX, widgetY;
+ widget->getAbsolutePosition(widgetX, widgetY);
+
+ mouseEvent.mX = x - widgetX;
+ mouseEvent.mY = y - widgetY;
+
+ std::list<MouseListener*> mouseListeners
+ = widget->_getMouseListeners();
+
+ // Send the event to all mouse listeners of the widget.
+ for (std::list<MouseListener*>::const_iterator
+ it = mouseListeners.begin();
+ it != mouseListeners.end();
+ ++it)
+ {
+ switch (mouseEvent.getType())
+ {
+ case MouseEvent::ENTERED:
+ (*it)->mouseEntered(mouseEvent);
+ break;
+ case MouseEvent::EXITED:
+ (*it)->mouseExited(mouseEvent);
+ break;
+ case MouseEvent::MOVED:
+ (*it)->mouseMoved(mouseEvent);
+ break;
+ case MouseEvent::PRESSED:
+ (*it)->mousePressed(mouseEvent);
+ break;
+ case MouseEvent::RELEASED:
+ (*it)->mouseReleased(mouseEvent);
+ break;
+ case MouseEvent::WHEEL_MOVED_UP:
+ (*it)->mouseWheelMovedUp(mouseEvent);
+ break;
+ case MouseEvent::WHEEL_MOVED_DOWN:
+ (*it)->mouseWheelMovedDown(mouseEvent);
+ break;
+ case MouseEvent::DRAGGED:
+ (*it)->mouseDragged(mouseEvent);
+ break;
+ case MouseEvent::CLICKED:
+ (*it)->mouseClicked(mouseEvent);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (toSourceOnly)
+ break;
+ }
+
+ const Widget *const swap = widget;
+ widget = parent;
+ parent = swap->getParent();
+
+ // If a non modal focused widget has been reach
+ // and we have modal focus cancel the distribution.
+ if (mFocusHandler->getModalFocused()
+ && !widget->isModalFocused())
+ {
+ break;
+ }
+
+ // If a non modal mouse input focused widget has been reach
+ // and we have modal mouse input focus cancel the distribution.
+ if (mFocusHandler->getModalMouseInputFocused()
+ && !widget->isModalMouseInputFocused())
+ {
+ break;
+ }
+ }
+ }
+
+ void Gui::distributeKeyEvent(KeyEvent& keyEvent)
+ {
+ Widget* parent = keyEvent.getSource();
+ Widget* widget = keyEvent.getSource();
+
+ if (mFocusHandler->getModalFocused()
+ && !widget->isModalFocused())
+ {
+ return;
+ }
+
+ if (mFocusHandler->getModalMouseInputFocused()
+ && !widget->isModalMouseInputFocused())
+ {
+ return;
+ }
+
+ while (parent)
+ {
+ // If the widget has been removed due to input
+ // cancel the distribution.
+ if (!Widget::widgetExists(widget))
+ break;
+
+ parent = widget->getParent();
+
+ if (widget->isEnabled())
+ {
+ std::list<KeyListener*> keyListeners
+ = widget->_getKeyListeners();
+
+ // Send the event to all key listeners of the source widget.
+ for (std::list<KeyListener*>::const_iterator
+ it = keyListeners.begin();
+ it != keyListeners.end();
+ ++it)
+ {
+ switch (keyEvent.getType())
+ {
+ case KeyEvent::PRESSED:
+ (*it)->keyPressed(keyEvent);
+ break;
+ case KeyEvent::RELEASED:
+ (*it)->keyReleased(keyEvent);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ const Widget *const swap = widget;
+ widget = parent;
+ parent = swap->getParent();
+
+ // If a non modal focused widget has been reach
+ // and we have modal focus cancel the distribution.
+ if (mFocusHandler->getModalFocused()
+ && !widget->isModalFocused())
+ {
+ break;
+ }
+ }
+ }
+
+ void Gui::distributeKeyEventToGlobalKeyListeners(KeyEvent& keyEvent)
+ {
+ for (KeyListenerListIterator it = mKeyListeners.begin();
+ it != mKeyListeners.end(); ++ it)
+ {
+ switch (keyEvent.getType())
+ {
+ case KeyEvent::PRESSED:
+ (*it)->keyPressed(keyEvent);
+ break;
+ case KeyEvent::RELEASED:
+ (*it)->keyReleased(keyEvent);
+ break;
+ default:
+ break;
+ }
+
+ if (keyEvent.isConsumed())
+ break;
+ }
+ }
+
+ void Gui::handleModalMouseInputFocus()
+ {
+ BLOCK_START("Gui::handleModalMouseInputFocus")
+ // Check if modal mouse input focus has been gained by a widget.
+ if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus()
+ != mFocusHandler->getModalMouseInputFocused())
+ && (!mFocusHandler->getLastWidgetWithModalMouseInputFocus()))
+ {
+ handleModalFocusGained();
+ mFocusHandler->setLastWidgetWithModalMouseInputFocus(
+ mFocusHandler->getModalMouseInputFocused());
+ }
+ // Check if modal mouse input focus has been released.
+ else if ((mFocusHandler->getLastWidgetWithModalMouseInputFocus()
+ != mFocusHandler->getModalMouseInputFocused())
+ && (mFocusHandler->getLastWidgetWithModalMouseInputFocus()))
+ {
+ handleModalFocusReleased();
+ mFocusHandler->setLastWidgetWithModalMouseInputFocus(nullptr);
+ }
+ BLOCK_END("Gui::handleModalMouseInputFocus")
+ }
+
+ void Gui::handleModalFocus()
+ {
+ BLOCK_START("Gui::handleModalFocus")
+ // Check if modal focus has been gained by a widget.
+ if ((mFocusHandler->getLastWidgetWithModalFocus()
+ != mFocusHandler->getModalFocused())
+ && (!mFocusHandler->getLastWidgetWithModalFocus()))
+ {
+ handleModalFocusGained();
+ mFocusHandler->setLastWidgetWithModalFocus(
+ mFocusHandler->getModalFocused());
+ }
+ // Check if modal focus has been released.
+ else if ((mFocusHandler->getLastWidgetWithModalFocus()
+ != mFocusHandler->getModalFocused())
+ && (mFocusHandler->getLastWidgetWithModalFocus()))
+ {
+ handleModalFocusReleased();
+ mFocusHandler->setLastWidgetWithModalFocus(nullptr);
+ }
+ BLOCK_END("Gui::handleModalFocus")
+ }
+
+ void Gui::handleModalFocusGained()
+ {
+ // Distribute an event to all widgets in the "widget with mouse" queue.
+ while (!mWidgetWithMouseQueue.empty())
+ {
+ Widget *const widget = mWidgetWithMouseQueue.front();
+
+ if (Widget::widgetExists(widget))
+ {
+ distributeMouseEvent(widget,
+ MouseEvent::EXITED,
+ mLastMousePressButton,
+ mLastMouseX,
+ mLastMouseY,
+ true,
+ true);
+ }
+
+ mWidgetWithMouseQueue.pop_front();
+ }
+
+ mFocusHandler->setLastWidgetWithModalMouseInputFocus(
+ mFocusHandler->getModalMouseInputFocused());
+ }
+
+ void Gui::handleModalFocusReleased()
+ {
+ // Check all widgets below the mouse to see if they are
+ // present in the "widget with mouse" queue. If a widget
+ // is not then it should be added and an entered event should
+ // be sent to it.
+ Widget* widget = getMouseEventSource(mLastMouseX, mLastMouseY);
+ Widget* parent = widget;
+
+ while (parent)
+ {
+ parent = widget->getParent();
+
+ // Check if the widget is present in the "widget with mouse" queue.
+ bool widgetIsPresentInQueue = false;
+ FOR_EACH (std::deque<Widget*>::const_iterator,
+ iter, mWidgetWithMouseQueue)
+ {
+ if (*iter == widget)
+ {
+ widgetIsPresentInQueue = true;
+ break;
+ }
+ }
+
+ // Widget is not present, send an entered event and add
+ // it to the "widget with mouse" queue.
+ if (!widgetIsPresentInQueue && Widget::widgetExists(widget))
+ {
+ distributeMouseEvent(widget,
+ MouseEvent::ENTERED,
+ mLastMousePressButton,
+ mLastMouseX,
+ mLastMouseY,
+ false,
+ true);
+ mWidgetWithMouseQueue.push_front(widget);
+ }
+
+ const Widget *const swap = widget;
+ widget = parent;
+ parent = swap->getParent();
+ }
+ }
+} // namespace gcn
diff --git a/src/gui/base/gui.hpp b/src/gui/base/gui.hpp
new file mode 100644
index 000000000..4ea923400
--- /dev/null
+++ b/src/gui/base/gui.hpp
@@ -0,0 +1,515 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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 GCN_GUI_HPP
+#define GCN_GUI_HPP
+
+#include <list>
+#include <deque>
+
+#include "localconsts.h"
+
+class Event;
+class FocusHandler;
+class Graphics;
+class KeyEvent;
+class KeyListener;
+class MouseInput;
+class SDLInput;
+class Widget;
+
+namespace gcn
+{
+ // The following comment will appear in the doxygen main page.
+ /**
+ * @mainpage
+ * @section Introduction
+ * This documentation is mostly intended as a reference to the API.
+ * If you want to get started with Guichan, we suggest you check out
+ * the programs in the examples directory of the Guichan release.
+ * @n
+ * @n
+ * This documentation is, and will always be, work in progress.
+ * If you find any errors, typos or inconsistencies, or if you feel
+ * something needs to be explained in more detail - don't hesitate to
+ * tell us.
+ */
+
+ /**
+ * Contains a Guichan GUI. This is the core class of Guichan to which
+ * implementations of back ends are passed, to make Guichan work with
+ * a specific library, and to where the top widget (root widget of GUI)
+ * is added. If you want to be able to have more then one widget in your
+ * GUI, the top widget should be a container.
+ *
+ * A Gui object cannot work properly without passing back end
+ * implementations to it. A Gui object must have an implementation of a
+ * Graphics and an implementation of Input.
+ *
+ * NOTE: A complete GUI also must have the ability to load images.
+ * Images are loaded with the Image class, so to make Guichan
+ * able to load images an implementation of ImageLoader must be
+ * passed to Image.
+ *
+ * @see Graphics, Input, Image
+ */
+ class Gui
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ Gui();
+
+ A_DELETE_COPY(Gui)
+
+ /**
+ * Destructor.
+ */
+ virtual ~Gui();
+
+ /**
+ * Sets the top widget. The top widget is the root widget
+ * of the GUI. If you want a GUI to be able to contain more
+ * than one widget the top widget should be a container.
+ *
+ * @param top The top widget.
+ * @see Container
+ * @since 0.1.0
+ */
+ virtual void setTop(Widget* top);
+
+ /**
+ * Gets the top widget. The top widget is the root widget
+ * of the GUI.
+ *
+ * @return The top widget. NULL if no top widget has been set.
+ * @since 0.1.0
+ */
+ virtual Widget* getTop() const A_WARN_UNUSED;
+
+ /**
+ * Sets the graphics object to use for drawing.
+ *
+ * @param graphics The graphics object to use for drawing.
+ * @see getGraphics, AllegroGraphics, HGEGraphics,
+ * OpenLayerGraphics, OpenGLGraphics, SDLGraphics
+ * @since 0.1.0
+ */
+ virtual void setGraphics(Graphics* graphics);
+
+ /**
+ * Gets the graphics object used for drawing.
+ *
+ * @return The graphics object used for drawing. NULL if no
+ * graphics object has been set.
+ * @see setGraphics, AllegroGraphics, HGEGraphics,
+ * OpenLayerGraphics, OpenGLGraphics, SDLGraphics
+ * @since 0.1.0
+ */
+ virtual Graphics* getGraphics() const A_WARN_UNUSED;
+
+ /**
+ * Sets the input object to use for input handling.
+ *
+ * @param input The input object to use for input handling.
+ * @see getInput, AllegroInput, HGEInput, OpenLayerInput,
+ * SDLInput
+ * @since 0.1.0
+ */
+ virtual void setInput(SDLInput* input);
+
+ /**
+ * Gets the input object being used for input handling.
+ *
+ * @return The input object used for handling input. NULL if no
+ * input object has been set.
+ * @see setInput, AllegroInput, HGEInput, OpenLayerInput,
+ * SDLInput
+ * @since 0.1.0
+ */
+ virtual SDLInput* getInput() const A_WARN_UNUSED;
+
+ /**
+ * Performs logic of the GUI. By calling this function all logic
+ * functions down in the GUI heirarchy will be called. When logic
+ * is called for Gui, user input will be handled.
+ *
+ * @see Widget::logic
+ * @since 0.1.0
+ */
+ virtual void logic();
+
+ /**
+ * Draws the GUI. By calling this funcion all draw functions
+ * down in the GUI hierarchy will be called. When draw is called
+ * the used Graphics object will be initialised and drawing of
+ * the top widget will commence.
+ *
+ * @see Widget::draw
+ * @since 0.1.0
+ */
+ virtual void draw();
+
+ /**
+ * Focuses none of the widgets in the Gui.
+ *
+ * @since 0.1.0
+ */
+ virtual void focusNone();
+
+ /**
+ * Sets tabbing enabled, or not. Tabbing is the usage of
+ * changing focus by utilising the tab key.
+ *
+ * @param tabbing True if tabbing should be enabled, false
+ * otherwise.
+ * @see isTabbingEnabled
+ * @since 0.1.0
+ */
+ virtual void setTabbingEnabled(bool tabbing);
+
+ /**
+ * Checks if tabbing is enabled.
+ *
+ * @return True if tabbing is enabled, false otherwise.
+ * @see setTabbingEnabled
+ * @since 0.1.0
+ */
+ virtual bool isTabbingEnabled();
+
+ /**
+ * Adds a global key listener to the Gui. A global key listener
+ * will receive all key events generated from the GUI and global
+ * key listeners will receive the events before key listeners
+ * of widgets.
+ *
+ * @param keyListener The key listener to add.
+ * @see removeGlobalKeyListener
+ * @since 0.5.0
+ */
+ virtual void addGlobalKeyListener(KeyListener* keyListener);
+
+ /**
+ * Removes global key listener from the Gui.
+ *
+ * @param keyListener The key listener to remove.
+ * @throws Exception if the key listener hasn't been added.
+ * @see addGlobalKeyListener
+ * @since 0.5.0
+ */
+ virtual void removeGlobalKeyListener(KeyListener* keyListener);
+
+ protected:
+ /**
+ * Handles all mouse input.
+ *
+ * @since 0.6.0
+ */
+ virtual void handleMouseInput();
+
+ /**
+ * Handles key input.
+ *
+ * @since 0.6.0
+ */
+ virtual void handleKeyInput();
+
+ /**
+ * Handles mouse moved input.
+ *
+ * @param mouseInput The mouse input to handle.
+ * @since 0.6.0
+ */
+ virtual void handleMouseMoved(const MouseInput& mouseInput);
+
+ /**
+ *
+ * Handles mouse wheel moved down input.
+ *
+ * @param mouseInput The mouse input to handle.
+ * @since 0.6.0
+ */
+ virtual void handleMouseWheelMovedDown(const MouseInput& mouseInput);
+
+ /**
+ * Handles mouse wheel moved up input.
+ *
+ * @param mouseInput The mouse input to handle.
+ * @since 0.6.0
+ */
+ virtual void handleMouseWheelMovedUp(const MouseInput& mouseInput);
+
+ /**
+ * Handles modal focus. Modal focus needs to be checked at
+ * each logic iteration as it might be necessary to distribute
+ * mouse entered or mouse exited events.
+ *
+ * @since 0.8.0
+ */
+ virtual void handleModalFocus();
+
+ /**
+ * Handles modal mouse input focus. Modal mouse input focus needs
+ * to be checked at each logic iteration as it might be necessary to
+ * distribute mouse entered or mouse exited events.
+ *
+ * @since 0.8.0
+ */
+ virtual void handleModalMouseInputFocus();
+
+ /**
+ * Handles modal focus gained. If modal focus has been gained it might
+ * be necessary to distribute mouse entered or mouse exited events.
+ *
+ * @since 0.8.0
+ */
+ virtual void handleModalFocusGained();
+
+ /**
+ * Handles modal mouse input focus gained. If modal focus has been
+ * gained it might be necessary to distribute mouse entered or mouse
+ * exited events.
+ *
+ * @since 0.8.0
+ */
+ virtual void handleModalFocusReleased();
+
+ /**
+ * Distributes a mouse event.
+ *
+ * @param type The type of the event to distribute,
+ * @param button The button of the event (if any used) to distribute.
+ * @param x The x coordinate of the event.
+ * @param y The y coordinate of the event.
+ * @param fource indicates whether the distribution should be forced or not.
+ * A forced distribution distributes the event even if a widget
+ * is not enabled, not visible, another widget has modal
+ * focus or another widget has modal mouse input focus.
+ * Default value is false.
+ * @param toSourceOnly indicates whether the distribution should be to the
+ * source widget only or to it's parent's mouse listeners
+ * as well.
+ *
+ * @since 0.6.0
+ */
+ virtual void distributeMouseEvent(Widget* source,
+ int type,
+ int button,
+ int x,
+ int y,
+ bool force = false,
+ bool toSourceOnly = false);
+
+ /**
+ * Distributes a key event.
+ *
+ * @param keyEvent The key event to distribute.
+
+ * @since 0.6.0
+ */
+ virtual void distributeKeyEvent(KeyEvent& keyEvent);
+
+ /**
+ * Distributes a key event to the global key listeners.
+ *
+ * @param keyEvent The key event to distribute.
+ *
+ * @since 0.6.0
+ */
+ virtual void distributeKeyEventToGlobalKeyListeners(KeyEvent&
+ keyEvent);
+
+ /**
+ * Gets the widget at a certain position.
+ *
+ * @return The widget at a certain position.
+ * @since 0.6.0
+ */
+ virtual Widget* getWidgetAt(int x, int y) A_WARN_UNUSED;
+
+ /**
+ * Gets the source of the mouse event.
+ *
+ * @return The source widget of the mouse event.
+ * @since 0.6.0
+ */
+ virtual Widget* getMouseEventSource(int x, int y) A_WARN_UNUSED;
+
+ /**
+ * Gets the source of the key event.
+ *
+ * @return The source widget of the key event.
+ * @since 0.6.0
+ */
+ virtual Widget* getKeyEventSource() A_WARN_UNUSED;
+
+ /**
+ * Holds the top widget.
+ */
+ Widget* mTop;
+
+ /**
+ * Holds the graphics implementation used.
+ */
+ Graphics* mGraphics;
+
+ /**
+ * Holds the input implementation used.
+ */
+ SDLInput* mInput;
+
+ /**
+ * Holds the focus handler for the Gui.
+ */
+ FocusHandler* mFocusHandler;
+
+ /**
+ * True if tabbing is enabled, false otherwise.
+ */
+ bool mTabbing;
+
+ /**
+ * Typedef.
+ */
+ typedef std::list<KeyListener*> KeyListenerList;
+
+ /**
+ * Typedef.
+ */
+ typedef KeyListenerList::iterator KeyListenerListIterator;
+
+ /**
+ * Holds the global key listeners of the Gui.
+ */
+ KeyListenerList mKeyListeners;
+
+ /**
+ * True if shift is pressed, false otherwise.
+ */
+ bool mShiftPressed;
+
+ /**
+ * True if meta is pressed, false otherwise.
+ */
+ bool mMetaPressed;
+
+ /**
+ * True if control is pressed, false otherwise.
+ */
+ bool mControlPressed;
+
+ /**
+ * True if alt is pressed, false otherwise.
+ */
+ bool mAltPressed;
+
+ /**
+ * Holds the last mouse button pressed.
+ */
+ unsigned int mLastMousePressButton;
+
+ /**
+ * Holds the last mouse press time stamp.
+ */
+ int mLastMousePressTimeStamp;
+
+ /**
+ * Holds the last mouse x coordinate.
+ */
+ int mLastMouseX;
+
+ /**
+ * Holds the last mouse y coordinate.
+ */
+ int mLastMouseY;
+
+ /**
+ * Holds the current click count. Used to keep track
+ * of clicks for a the last pressed button.
+ */
+ int mClickCount;
+
+ /**
+ * Holds the last button used when a drag of a widget
+ * was initiated. Used to be able to release a drag
+ * when the same button is released.
+ */
+ int mLastMouseDragButton;
+
+ /**
+ * Holds a stack with all the widgets with the mouse.
+ * Used to properly distribute mouse events.
+ */
+ std::deque<Widget*> mWidgetWithMouseQueue;
+ };
+} // namespace gcn
+
+#endif // end GCN_GUI_HPP
+
+/* yakslem - "Women, it's a constant struggle."
+ * finalman - "Yes, but sometimes they succeed with their guesses."
+ * yaklsem - "...eh...I was talking about love."
+ * finalman - "Oh...ok..."
+ * An awkward silence followed.
+ */
diff --git a/src/gui/base/widgets/button.cpp b/src/gui/base/widgets/button.cpp
new file mode 100644
index 000000000..2d6afa672
--- /dev/null
+++ b/src/gui/base/widgets/button.cpp
@@ -0,0 +1,192 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/base/widgets/button.hpp"
+
+#include "events/mouseevent.h"
+
+#include "render/graphics.h"
+
+#include "debug.h"
+
+namespace gcn
+{
+ Button::Button(const Widget2 *const widget) :
+ Widget(widget),
+ MouseListener(),
+ KeyListener(),
+ FocusListener(),
+ mCaption(),
+ mHasMouse(false),
+ mKeyPressed(false),
+ mMousePressed(false),
+ mAlignment(Graphics::CENTER),
+ mSpacing(4)
+ {
+ setFocusable(true);
+ adjustSize();
+ setFrameSize(1);
+
+ addMouseListener(this);
+ addKeyListener(this);
+ addFocusListener(this);
+ }
+
+ Button::Button(const Widget2 *const widget,
+ const std::string& caption) :
+ Widget(widget),
+ MouseListener(),
+ KeyListener(),
+ FocusListener(),
+ mCaption(caption),
+ mHasMouse(false),
+ mKeyPressed(false),
+ mMousePressed(false),
+ mAlignment(Graphics::CENTER),
+ mSpacing(4)
+ {
+ setFocusable(true);
+ adjustSize();
+ setFrameSize(1);
+
+ addMouseListener(this);
+ addKeyListener(this);
+ addFocusListener(this);
+ }
+
+ void Button::setCaption(const std::string& caption)
+ {
+ mCaption = caption;
+ }
+
+ const std::string& Button::getCaption() const
+ {
+ return mCaption;
+ }
+
+ void Button::setAlignment(Graphics::Alignment alignment)
+ {
+ mAlignment = alignment;
+ }
+
+ Graphics::Alignment Button::getAlignment() const
+ {
+ return mAlignment;
+ }
+
+ void Button::setSpacing(unsigned int spacing)
+ {
+ mSpacing = spacing;
+ }
+
+ unsigned int Button::getSpacing() const
+ {
+ return mSpacing;
+ }
+
+ void Button::adjustSize()
+ {
+ }
+
+ bool Button::isPressed() const
+ {
+ if (mMousePressed)
+ return mHasMouse;
+ else
+ return mKeyPressed;
+ }
+
+ void Button::mousePressed(MouseEvent& mouseEvent)
+ {
+ if (mouseEvent.getButton() == MouseEvent::LEFT)
+ {
+ mMousePressed = true;
+ mouseEvent.consume();
+ }
+ }
+
+ void Button::mouseExited(MouseEvent& mouseEvent A_UNUSED)
+ {
+ mHasMouse = false;
+ }
+
+ void Button::mouseEntered(MouseEvent& mouseEvent A_UNUSED)
+ {
+ mHasMouse = true;
+ }
+
+ void Button::mouseDragged(MouseEvent& mouseEvent)
+ {
+ mouseEvent.consume();
+ }
+
+ void Button::focusLost(const Event& event A_UNUSED)
+ {
+ mMousePressed = false;
+ mKeyPressed = false;
+ }
+} // namespace gcn
diff --git a/src/gui/base/widgets/button.hpp b/src/gui/base/widgets/button.hpp
new file mode 100644
index 000000000..99e5db4f4
--- /dev/null
+++ b/src/gui/base/widgets/button.hpp
@@ -0,0 +1,222 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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 GCN_BUTTON_HPP
+#define GCN_BUTTON_HPP
+
+#include <string>
+
+#include "listeners/focuslistener.h"
+#include "listeners/keylistener.h"
+#include "listeners/mouselistener.h"
+
+#include "gui/widgets/widget.h"
+
+#include "render/graphics.h"
+
+namespace gcn
+{
+ /**
+ * An implementation of a regular clickable button. A button is capable of
+ * displaying a caption.
+ *
+ * If a button is clicked an action event will be sent to all action listener's
+ * of the button.
+ *
+ * @see ImageButton
+ */
+ class Button : public Widget,
+ public MouseListener,
+ public KeyListener,
+ public FocusListener
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ explicit Button(const Widget2 *const widget);
+
+ /**
+ * Constructor. The button will be automatically resized
+ * to fit the caption.
+ *
+ * @param caption The caption of the button.
+ */
+ Button(const Widget2 *const widget,
+ const std::string& caption);
+
+ A_DELETE_COPY(Button)
+
+ /**
+ * 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);
+
+ /**
+ * Gets the caption of the button.
+ *
+ * @return The caption of the button.
+ */
+ const std::string& getCaption() const;
+
+ /**
+ * 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);
+
+ /**
+ * Gets the alignment of the caption.
+ *
+ * @return The alignment of the caption.
+ * @see setAlignment, Graphics
+ */
+ Graphics::Alignment getAlignment() const;
+
+ /**
+ * Sets the spacing between the border of the button and its caption.
+ *
+ * @param spacing The default value for spacing is 4 and can be changed
+ * using this method.
+ * @see getSpacing
+ */
+ void setSpacing(unsigned int spacing);
+
+ /**
+ * Gets the spacing between the border of the button and its caption.
+ *
+ * @return spacing.
+ * @see setSpacing
+ */
+ unsigned int getSpacing() const;
+
+ /**
+ * Adjusts the button's size to fit the caption.
+ */
+ void adjustSize();
+
+
+ // Inherited from FocusListener
+
+ virtual void focusLost(const Event& event);
+
+ // Inherited from MouseListener
+
+ virtual void mousePressed(MouseEvent& mouseEvent) override;
+
+ virtual void mouseEntered(MouseEvent& mouseEvent) override;
+
+ virtual void mouseExited(MouseEvent& mouseEvent) override;
+
+ virtual void mouseDragged(MouseEvent& mouseEvent) override;
+
+ protected:
+ /**
+ * 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;
+
+ /**
+ * Holds the caption of the button.
+ */
+ std::string mCaption;
+
+ /**
+ * 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;
+
+ /**
+ * Holds the alignment of the caption.
+ */
+ Graphics::Alignment mAlignment;
+
+ /**
+ * Holds the spacing between the border and the caption.
+ */
+ unsigned int mSpacing;
+ };
+} // namespace gcn
+
+#endif // end GCN_BUTTON_HPP
diff --git a/src/gui/base/widgets/checkbox.cpp b/src/gui/base/widgets/checkbox.cpp
new file mode 100644
index 000000000..476fb3c6b
--- /dev/null
+++ b/src/gui/base/widgets/checkbox.cpp
@@ -0,0 +1,151 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/base/widgets/checkbox.hpp"
+
+#include "debug.h"
+
+namespace gcn
+{
+
+ CheckBox::CheckBox(const Widget2 *const widget) :
+ Widget(widget),
+ MouseListener(),
+ KeyListener(),
+ mSelected(false),
+ mCaption()
+ {
+ setFocusable(true);
+ addMouseListener(this);
+ addKeyListener(this);
+ }
+
+ CheckBox::CheckBox(const Widget2 *const widget,
+ const std::string &caption,
+ bool selected) :
+ Widget(widget),
+ MouseListener(),
+ KeyListener(),
+ mSelected(selected),
+ mCaption()
+ {
+ setCaption(caption);
+
+ setFocusable(true);
+ addMouseListener(this);
+ addKeyListener(this);
+
+ adjustSize();
+ }
+
+ bool CheckBox::isSelected() const
+ {
+ return mSelected;
+ }
+
+ void CheckBox::setSelected(bool selected)
+ {
+ mSelected = selected;
+ }
+
+ const std::string &CheckBox::getCaption() const
+ {
+ return mCaption;
+ }
+
+ void CheckBox::setCaption(const std::string& caption)
+ {
+ mCaption = caption;
+ }
+
+ void CheckBox::keyPressed(KeyEvent& keyEvent A_UNUSED)
+ {
+ }
+
+ void CheckBox::mouseClicked(MouseEvent& mouseEvent)
+ {
+ if (mouseEvent.getButton() == MouseEvent::LEFT)
+ {
+ toggleSelected();
+ }
+ }
+
+ void CheckBox::mouseDragged(MouseEvent& mouseEvent)
+ {
+ mouseEvent.consume();
+ }
+
+ void CheckBox::adjustSize()
+ {
+ }
+
+ void CheckBox::toggleSelected()
+ {
+ mSelected = !mSelected;
+ distributeActionEvent();
+ }
+} // namespace gcn
diff --git a/src/gui/base/widgets/checkbox.hpp b/src/gui/base/widgets/checkbox.hpp
new file mode 100644
index 000000000..6fcb04767
--- /dev/null
+++ b/src/gui/base/widgets/checkbox.hpp
@@ -0,0 +1,183 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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 GCN_CHECKBOX_HPP
+#define GCN_CHECKBOX_HPP
+
+#include <string>
+
+#include "listeners/keylistener.h"
+#include "listeners/mouselistener.h"
+
+#include "gui/widgets/widget.h"
+
+namespace gcn
+{
+ /**
+ * An implementation of a check box where a user can select or deselect
+ * the check box and where the status of the check box is displayed to the user.
+ * A check box is capable of displaying a caption.
+ *
+ * If a check box's state changes an action event will be sent to all action
+ * listeners of the check box.
+ */
+ class CheckBox :
+ public Widget,
+ public MouseListener,
+ public KeyListener
+ {
+ public:
+ /**
+ * Contructor.
+ */
+ explicit CheckBox(const Widget2 *const widget);
+
+ /**
+ * Constructor. The check box will be automatically resized
+ * to fit the caption.
+ *
+ * @param caption The caption of the check box.
+ * @param marked True if the check box is selected, false otherwise.
+ */
+ CheckBox(const Widget2 *const widget,
+ const std::string &caption,
+ bool selected = false);
+
+ A_DELETE_COPY(CheckBox)
+
+ /**
+ * Destructor.
+ */
+ virtual ~CheckBox()
+ { }
+
+ /**
+ * Checks if the check box is selected.
+ *
+ * @return True if the check box is selected, false otherwise.
+ * @see setSelected
+ */
+ bool isSelected() const;
+
+ /**
+ * 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(bool selected);
+
+ /**
+ * Gets the caption of the check box.
+ *
+ * @return The caption of the check box.
+ * @see setCaption
+ */
+ const std::string &getCaption() const;
+
+ /**
+ * 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);
+
+ /**
+ * Adjusts the check box's size to fit the caption.
+ */
+ void adjustSize();
+
+ // Inherited from KeyListener
+
+ virtual void keyPressed(KeyEvent& keyEvent) override;
+
+ // Inherited from MouseListener
+
+ virtual void mouseClicked(MouseEvent& mouseEvent) override;
+
+ virtual void mouseDragged(MouseEvent& mouseEvent) override;
+
+
+ protected:
+ /**
+ * Toggles the check box between being selected and
+ * not being selected.
+ */
+ virtual void toggleSelected();
+
+ /**
+ * True if the check box is selected, false otherwise.
+ */
+ bool mSelected;
+
+ /**
+ * Holds the caption of the check box.
+ */
+ std::string mCaption;
+ };
+} // namespace gcn
+
+#endif // end GCN_CHECKBOX_HPP
diff --git a/src/gui/base/widgets/container.cpp b/src/gui/base/widgets/container.cpp
new file mode 100644
index 000000000..53a900ec4
--- /dev/null
+++ b/src/gui/base/widgets/container.cpp
@@ -0,0 +1,136 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/base/widgets/container.hpp"
+
+
+#include "render/graphics.h"
+
+#include "debug.h"
+
+namespace gcn
+{
+
+ Container::Container(const Widget2 *const widget) :
+ BasicContainer(widget),
+ mOpaque(true)
+ {
+ }
+
+ Container::~Container()
+ {
+ }
+
+ void Container::draw(Graphics* graphics)
+ {
+ BLOCK_START("Container::draw")
+ if (isOpaque())
+ {
+ graphics->setColor(getBaseColor());
+ graphics->fillRectangle(Rect(0, 0, getWidth(), getHeight()));
+ }
+
+ drawChildren(graphics);
+ BLOCK_END("Container::draw")
+ }
+
+ void Container::setOpaque(bool opaque)
+ {
+ mOpaque = opaque;
+ }
+
+ bool Container::isOpaque() const
+ {
+ return mOpaque;
+ }
+
+ void Container::add(Widget* widget)
+ {
+ BasicContainer::add(widget);
+ }
+
+ void Container::add(Widget* widget, int x, int y)
+ {
+ widget->setPosition(x, y);
+ BasicContainer::add(widget);
+ }
+
+ void Container::remove(Widget* widget)
+ {
+ BasicContainer::remove(widget);
+ }
+
+ void Container::clear()
+ {
+ BasicContainer::clear();
+ }
+
+ Widget* Container::findWidgetById(const std::string &id)
+ {
+ return BasicContainer::findWidgetById(id);
+ }
+} // namespace gcn
diff --git a/src/gui/base/widgets/container.hpp b/src/gui/base/widgets/container.hpp
new file mode 100644
index 000000000..3e6c0a587
--- /dev/null
+++ b/src/gui/base/widgets/container.hpp
@@ -0,0 +1,177 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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 GCN_CONTAINER_HPP
+#define GCN_CONTAINER_HPP
+
+#include "gui/base/basiccontainer.hpp"
+
+namespace gcn
+{
+ /**
+ * 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 Container: public BasicContainer
+ {
+ public:
+ /**
+ * Constructor. A container is opauqe as default, if you want a
+ * none opaque container call setQpaque(false).
+ *
+ * @see setOpaque, isOpaque
+ */
+ explicit Container(const Widget2 *const widget);
+
+ /**
+ * Destructor.
+ */
+ virtual ~Container();
+
+ /**
+ * 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(bool opaque);
+
+ /**
+ * Checks if the container is opaque or not.
+ *
+ * @return True if the container is opaque, false otherwise.
+ * @see setOpaque
+ */
+ bool isOpaque() const;
+
+ /**
+ * Adds a widget to the container.
+ *
+ * @param widget The widget to add.
+ * @see remove, clear
+ */
+ virtual void add(Widget* 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
+ */
+ virtual void add(Widget* widget, int x, int y);
+
+ /**
+ * Removes a widget from the Container.
+ *
+ * @param widget The widget to remove.
+ * @throws Exception when the widget has not been added to the
+ * container.
+ * @see add, clear
+ */
+ virtual void remove(Widget* widget);
+
+ /**
+ * Clears the container of all widgets.
+ *
+ * @see add, remove
+ */
+ virtual void clear();
+
+ /**
+ * Finds a widget given an id.
+ *
+ * @param id The id to find a widget by.
+ * @return A widget with a corrosponding id, NULL if no widget
+ * is found.
+ * @see Widget::setId
+ */
+ virtual Widget* findWidgetById(const std::string &id);
+
+
+ // Inherited from Widget
+
+ virtual void draw(Graphics* graphics);
+
+ protected:
+ /**
+ * True if the container is opaque, false otherwise.
+ */
+ bool mOpaque;
+ };
+} // namespace gcn
+
+#endif // end GCN_CONTAINER_HPP
diff --git a/src/gui/base/widgets/label.cpp b/src/gui/base/widgets/label.cpp
new file mode 100644
index 000000000..d2293a957
--- /dev/null
+++ b/src/gui/base/widgets/label.cpp
@@ -0,0 +1,122 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/base/widgets/label.hpp"
+
+#include "gui/font.h"
+
+#include "render/graphics.h"
+
+#include "debug.h"
+
+namespace gcn
+{
+ Label::Label(const Widget2 *const widget) :
+ Widget(widget),
+ mCaption(),
+ mAlignment(Graphics::LEFT)
+ {
+ }
+
+ Label::Label(const Widget2 *const widget,
+ const std::string& caption) :
+ Widget(widget),
+ mCaption(caption),
+ mAlignment(Graphics::LEFT)
+ {
+ setWidth(getFont()->getWidth(caption));
+ setHeight(getFont()->getHeight());
+ }
+
+ const std::string &Label::getCaption() const
+ {
+ return mCaption;
+ }
+
+ void Label::setCaption(const std::string& caption)
+ {
+ mCaption = caption;
+ }
+
+ void Label::setAlignment(Graphics::Alignment alignment)
+ {
+ mAlignment = alignment;
+ }
+
+ Graphics::Alignment Label::getAlignment() const
+ {
+ return mAlignment;
+ }
+
+ void Label::draw(Graphics* graphics A_UNUSED)
+ {
+ }
+
+ void Label::adjustSize()
+ {
+ }
+} // namespace gcn
diff --git a/src/gui/base/widgets/label.hpp b/src/gui/base/widgets/label.hpp
new file mode 100644
index 000000000..fd0d54f8e
--- /dev/null
+++ b/src/gui/base/widgets/label.hpp
@@ -0,0 +1,156 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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 GCN_LABEL_HPP
+#define GCN_LABEL_HPP
+
+#include <string>
+
+#include "gui/widgets/widget.h"
+
+#include "render/graphics.h"
+
+namespace gcn
+{
+ /**
+ * Implementation of a label capable of displaying a caption.
+ */
+ class Label: public Widget
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ explicit Label(const Widget2 *const widget);
+
+ /**
+ * Constructor. The label will be automatically resized
+ * to fit the caption.
+ *
+ * @param caption The caption of the label.
+ */
+ Label(const Widget2 *const widget,
+ const std::string& caption);
+
+ A_DELETE_COPY(Label)
+
+ /**
+ * Gets the caption of the label.
+ *
+ * @return The caption of the label.
+ * @see setCaption
+ */
+ const std::string &getCaption() const;
+
+ /**
+ * 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 alignemnt The alignment of the caption of the label.
+ * @see getAlignment, Graphics
+ */
+ void setAlignment(Graphics::Alignment 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;
+
+ /**
+ * Adjusts the label's size to fit the caption.
+ */
+ void adjustSize();
+
+
+ // Inherited from Widget
+
+ virtual void draw(Graphics* graphics);
+
+ protected:
+ /**
+ * Holds the caption of the label.
+ */
+ std::string mCaption;
+
+ /**
+ * Holds the alignment of the caption.
+ */
+ Graphics::Alignment mAlignment;
+ };
+} // namespace gcn
+
+#endif // end GCN_LABEL_HPP
diff --git a/src/gui/base/widgets/listbox.cpp b/src/gui/base/widgets/listbox.cpp
new file mode 100644
index 000000000..2e9606f0a
--- /dev/null
+++ b/src/gui/base/widgets/listbox.cpp
@@ -0,0 +1,240 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/base/widgets/listbox.hpp"
+
+#include "gui/font.h"
+
+#include "gui/models/listmodel.h"
+
+#include "listeners/selectionlistener.h"
+
+#include "debug.h"
+
+namespace gcn
+{
+ ListBox::ListBox(const Widget2 *const widget) :
+ Widget(widget),
+ MouseListener(),
+ KeyListener(),
+ mSelected(-1),
+ mListModel(nullptr),
+ mWrappingEnabled(false),
+ mSelectionListeners()
+ {
+ setWidth(100);
+ setFocusable(true);
+
+ addMouseListener(this);
+ addKeyListener(this);
+ }
+
+ ListBox::ListBox(const Widget2 *const widget,
+ ListModel *listModel) :
+ Widget(widget),
+ MouseListener(),
+ KeyListener(),
+ mSelected(-1),
+ mListModel(listModel),
+ mWrappingEnabled(false),
+ mSelectionListeners()
+ {
+ setWidth(100);
+ adjustSize();
+ setFocusable(true);
+ addMouseListener(this);
+ addKeyListener(this);
+ }
+
+ void ListBox::draw(Graphics* graphics A_UNUSED)
+ {
+ }
+
+ void ListBox::logic()
+ {
+ }
+
+ int ListBox::getSelected() const
+ {
+ return mSelected;
+ }
+
+ void ListBox::setSelected(int selected)
+ {
+ if (!mListModel)
+ {
+ 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 = getRowHeight() * mSelected;
+
+ scroll.height = getRowHeight();
+ showPart(scroll);
+
+ distributeValueChangedEvent();
+ }
+
+ void ListBox::keyPressed(KeyEvent &keyEvent A_UNUSED)
+ {
+ }
+
+ void ListBox::mousePressed(MouseEvent &mouseEvent A_UNUSED)
+ {
+ }
+
+ void ListBox::mouseWheelMovedUp(MouseEvent& mouseEvent)
+ {
+ if (isFocused())
+ {
+ if (getSelected() > 0 )
+ setSelected(getSelected() - 1);
+
+ mouseEvent.consume();
+ }
+ }
+
+ void ListBox::mouseWheelMovedDown(MouseEvent& mouseEvent)
+ {
+ if (isFocused())
+ {
+ setSelected(getSelected() + 1);
+
+ mouseEvent.consume();
+ }
+ }
+
+ void ListBox::mouseDragged(MouseEvent& mouseEvent)
+ {
+ mouseEvent.consume();
+ }
+
+ void ListBox::setListModel(ListModel *listModel)
+ {
+ mSelected = -1;
+ mListModel = listModel;
+ adjustSize();
+ }
+
+ ListModel* ListBox::getListModel()
+ {
+ return mListModel;
+ }
+
+ void ListBox::adjustSize()
+ {
+ }
+
+ bool ListBox::isWrappingEnabled() const
+ {
+ return mWrappingEnabled;
+ }
+
+ void ListBox::setWrappingEnabled(bool wrappingEnabled)
+ {
+ mWrappingEnabled = wrappingEnabled;
+ }
+
+ void ListBox::addSelectionListener(SelectionListener* selectionListener)
+ {
+ mSelectionListeners.push_back(selectionListener);
+ }
+
+ void ListBox::removeSelectionListener(SelectionListener* selectionListener)
+ {
+ mSelectionListeners.remove(selectionListener);
+ }
+
+ void ListBox::distributeValueChangedEvent()
+ {
+ for (SelectionListenerIterator iter = mSelectionListeners.begin();
+ iter != mSelectionListeners.end();
+ ++ iter)
+ {
+ SelectionEvent event(this);
+ (*iter)->valueChanged(event);
+ }
+ }
+
+ unsigned int ListBox::getRowHeight() const
+ {
+ return getFont()->getHeight();
+ }
+} // namespace gcn
diff --git a/src/gui/base/widgets/listbox.hpp b/src/gui/base/widgets/listbox.hpp
new file mode 100644
index 000000000..079e5a7d5
--- /dev/null
+++ b/src/gui/base/widgets/listbox.hpp
@@ -0,0 +1,277 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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 GCN_LISTBOX_HPP
+#define GCN_LISTBOX_HPP
+
+#include <list>
+
+#include "gui/widgets/widget.h"
+
+#include "listeners/keylistener.h"
+#include "listeners/mouselistener.h"
+
+class ListModel;
+class SelectionListener;
+
+namespace gcn
+{
+ /**
+ * An implementation of a list box where an item can be selected.
+ *
+ * To be able display a list the list box uses a user provided list model.
+ * A list model can be any class that implements the ListModel interface.
+ *
+ * If an item is selected in the list box a select event will be sent to
+ * all selection listeners of the list box. If an item is selected by using
+ * a mouse click or by using the enter or space key an action event will be
+ * sent to all action listeners of the list box.
+ */
+ class ListBox :
+ public Widget,
+ public MouseListener,
+ public KeyListener
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ explicit ListBox(const Widget2 *const widget);
+
+ /**
+ * Constructor.
+ *
+ * @param listModel the list model to use.
+ */
+ ListBox(const Widget2 *const widget,
+ ListModel *listModel);
+
+ A_DELETE_COPY(ListBox)
+
+ /**
+ * Destructor.
+ */
+ virtual ~ListBox()
+ { }
+
+ /**
+ * 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;
+
+ /**
+ * 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(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();
+
+ /**
+ * Adjusts the size of the list box to fit it's list model.
+ */
+ void adjustSize();
+
+ /**
+ * 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;
+
+ /**
+ * 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(bool 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.
+ * @since 0.8.0
+ */
+ void addSelectionListener(SelectionListener* selectionListener);
+
+ /**
+ * Removes a selection listener from the list box.
+ *
+ * @param selectionListener The selection listener to remove.
+ * @since 0.8.0
+ */
+ void removeSelectionListener(SelectionListener* selectionListener);
+
+ /**
+ * Gets the height of a row. Should be overridden if another row
+ * height than the font height is preferred.
+ *
+ * @return The height of a row.
+ * @since 0.8.0
+ */
+ virtual unsigned int getRowHeight() const;
+
+
+ // Inherited from Widget
+
+ virtual void draw(Graphics* graphics);
+
+ virtual void logic();
+
+
+ // Inherited from KeyListener
+
+ virtual void keyPressed(KeyEvent& keyEvent) override;
+
+
+ // Inherited from MouseListener
+
+ virtual void mousePressed(MouseEvent& mouseEvent) override;
+
+ virtual void mouseWheelMovedUp(MouseEvent& mouseEvent) override;
+
+ virtual void mouseWheelMovedDown(MouseEvent& mouseEvent) override;
+
+ virtual void mouseDragged(MouseEvent& mouseEvent) override;
+
+
+ protected:
+ /**
+ * Distributes a value changed event to all selection listeners
+ * of the list box.
+ *
+ * @since 0.8.0
+ */
+ void distributeValueChangedEvent();
+
+ /**
+ * 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;
+ };
+} // namespace gcn
+
+#endif // end GCN_LISTBOX_HPP
diff --git a/src/gui/base/widgets/radiobutton.cpp b/src/gui/base/widgets/radiobutton.cpp
new file mode 100644
index 000000000..f9d68555a
--- /dev/null
+++ b/src/gui/base/widgets/radiobutton.cpp
@@ -0,0 +1,203 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/base/widgets/radiobutton.hpp"
+
+#include "debug.h"
+
+namespace gcn
+{
+ RadioButton::GroupMap RadioButton::mGroupMap;
+
+ RadioButton::RadioButton(const Widget2 *const widget) :
+ Widget(widget),
+ MouseListener(),
+ KeyListener(),
+ mSelected(false),
+ mCaption(),
+ mGroup()
+ {
+ setSelected(false);
+
+ setFocusable(true);
+ addMouseListener(this);
+ addKeyListener(this);
+ }
+
+ RadioButton::RadioButton(const Widget2 *const widget,
+ const std::string &caption,
+ const std::string &group,
+ bool selected) :
+ Widget(widget),
+ MouseListener(),
+ KeyListener(),
+ mSelected(false),
+ mCaption(),
+ mGroup()
+ {
+ setCaption(caption);
+ setGroup(group);
+ setSelected(selected);
+
+ setFocusable(true);
+ addMouseListener(this);
+ addKeyListener(this);
+
+ adjustSize();
+ }
+
+ RadioButton::~RadioButton()
+ {
+ // Remove us from the group list
+ setGroup("");
+ }
+
+ bool RadioButton::isSelected() const
+ {
+ return mSelected;
+ }
+
+ void RadioButton::setSelected(bool selected)
+ {
+ if (selected && mGroup != "")
+ {
+ for (GroupIterator iter = mGroupMap.lower_bound(mGroup),
+ iterEnd = mGroupMap.upper_bound(mGroup);
+ iter != iterEnd;
+ ++ iter)
+ {
+ if (iter->second->isSelected())
+ iter->second->setSelected(false);
+ }
+ }
+
+ mSelected = selected;
+ }
+
+ const std::string &RadioButton::getCaption() const
+ {
+ return mCaption;
+ }
+
+ void RadioButton::setCaption(const std::string &caption)
+ {
+ mCaption = caption;
+ }
+
+ void RadioButton::keyPressed(KeyEvent& keyEvent A_UNUSED)
+ {
+ }
+
+ void RadioButton::mouseClicked(MouseEvent& mouseEvent)
+ {
+ if (mouseEvent.getButton() == MouseEvent::LEFT)
+ {
+ setSelected(true);
+ distributeActionEvent();
+ }
+ }
+
+ void RadioButton::mouseDragged(MouseEvent& mouseEvent)
+ {
+ mouseEvent.consume();
+ }
+
+ void RadioButton::setGroup(const std::string &group)
+ {
+ if (mGroup != "")
+ {
+ 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 != "")
+ {
+ mGroupMap.insert(
+ std::pair<std::string, RadioButton *>(group, this));
+ }
+
+ mGroup = group;
+ }
+
+ const std::string &RadioButton::getGroup() const
+ {
+ return mGroup;
+ }
+
+ void RadioButton::adjustSize()
+ {
+ }
+} // namespace gcn
diff --git a/src/gui/base/widgets/radiobutton.hpp b/src/gui/base/widgets/radiobutton.hpp
new file mode 100644
index 000000000..a86a4eed3
--- /dev/null
+++ b/src/gui/base/widgets/radiobutton.hpp
@@ -0,0 +1,228 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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 GCN_RADIOBUTTON_HPP
+#define GCN_RADIOBUTTON_HPP
+
+#include <map>
+#include <string>
+
+#include "listeners/keylistener.h"
+#include "listeners/mouselistener.h"
+
+#include "gui/widgets/widget.h"
+
+namespace gcn
+{
+ /**
+ * An implementation of a radio button where a user can select or deselect
+ * the radio button and where the status of the radio button is displayed to the user.
+ * A radio button can belong to a group and when a radio button belongs to a
+ * group only one radio button can be selected in the group. A radio button is
+ * capable of displaying a caption.
+ *
+ * If a radio button's state changes an action event will be sent to all action
+ * listeners of the check box.
+ */
+ class RadioButton :
+ public Widget,
+ public MouseListener,
+ public KeyListener
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ explicit RadioButton(const Widget2 *const widget);
+
+ /**
+ * Constructor. The radio button will be automatically resized
+ * to fit the caption.
+ *
+ * @param caption The caption of the radio button.
+ * @param group The group the radio button should belong to.
+ * @param selected True if the radio button should be selected.
+ */
+ RadioButton(const Widget2 *const widget,
+ const std::string &caption,
+ const std::string &group,
+ bool selected = false);
+
+ A_DELETE_COPY(RadioButton)
+
+ /**
+ * Destructor.
+ */
+ virtual ~RadioButton();
+
+ /**
+ * Checks if the radio button is selected.
+ *
+ * @return True if the radio button is selecte, false otherwise.
+ * @see setSelected
+ */
+ bool isSelected() const;
+
+ /**
+ * Sets the radio button to selected or not.
+ *
+ * @param selected True if the radio button should be selected,
+ * false otherwise.
+ * @see isSelected
+ */
+ void setSelected(bool selected);
+
+ /**
+ * Gets the caption of the radio button.
+ *
+ * @return The caption of the radio button.
+ * @see setCaption
+ */
+ const std::string &getCaption() const;
+
+ /**
+ * 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);
+
+ /**
+ * 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;
+
+ /**
+ * Adjusts the radio button's size to fit the caption.
+ */
+ void adjustSize();
+
+
+ // Inherited from KeyListener
+
+ virtual void keyPressed(KeyEvent& keyEvent) override;
+
+
+ // Inherited from MouseListener
+
+ virtual void mouseClicked(MouseEvent& mouseEvent) override;
+
+ virtual void mouseDragged(MouseEvent& mouseEvent) override;
+
+ protected:
+ /**
+ * Draws the box.
+ *
+ * @param graphics a Graphics object to draw with.
+ */
+ virtual void drawBox(Graphics *graphics) = 0;
+
+ /**
+ * 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;
+
+ /**
+ * Typdef.
+ */
+ typedef std::multimap<std::string, RadioButton *> GroupMap;
+
+ /**
+ * Typdef.
+ */
+ typedef GroupMap::iterator GroupIterator;
+
+ /**
+ * Holds all available radio button groups.
+ */
+ static GroupMap mGroupMap;
+ };
+} // namespace gcn
+
+#endif // end GCN_RADIOBUTTON_HPP
diff --git a/src/gui/base/widgets/scrollarea.cpp b/src/gui/base/widgets/scrollarea.cpp
new file mode 100644
index 000000000..665830ce4
--- /dev/null
+++ b/src/gui/base/widgets/scrollarea.cpp
@@ -0,0 +1,597 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/base/widgets/scrollarea.hpp"
+
+#include "debug.h"
+
+namespace gcn
+{
+ ScrollArea::ScrollArea(const Widget2 *const widget) :
+ gcn::BasicContainer(widget),
+ MouseListener(),
+ mVScroll(0),
+ mHScroll(0),
+ mScrollbarWidth(12),
+ mHPolicy(SHOW_AUTO),
+ mVPolicy(SHOW_AUTO),
+ mVBarVisible(false),
+ mHBarVisible(false),
+ mUpButtonPressed(false),
+ mDownButtonPressed(false),
+ mLeftButtonPressed(false),
+ mRightButtonPressed(false),
+ mUpButtonScrollAmount(10),
+ mDownButtonScrollAmount(10),
+ mLeftButtonScrollAmount(10),
+ mRightButtonScrollAmount(10),
+ mIsVerticalMarkerDragged(false),
+ mIsHorizontalMarkerDragged(false),
+ mHorizontalMarkerDragOffset(0),
+ mVerticalMarkerDragOffset(0),
+ mOpaque(true)
+ {
+ addMouseListener(this);
+ }
+
+ ScrollArea::ScrollArea(const Widget2 *const widget,
+ Widget *const content) :
+ gcn::BasicContainer(widget),
+ MouseListener(),
+ mVScroll(0),
+ mHScroll(0),
+ mScrollbarWidth(12),
+ mHPolicy(SHOW_AUTO),
+ mVPolicy(SHOW_AUTO),
+ mVBarVisible(false),
+ mHBarVisible(false),
+ mUpButtonPressed(false),
+ mDownButtonPressed(false),
+ mLeftButtonPressed(false),
+ mRightButtonPressed(false),
+ mUpButtonScrollAmount(10),
+ mDownButtonScrollAmount(10),
+ mLeftButtonScrollAmount(10),
+ mRightButtonScrollAmount(10),
+ mIsVerticalMarkerDragged(false),
+ mIsHorizontalMarkerDragged(false),
+ mHorizontalMarkerDragOffset(0),
+ mVerticalMarkerDragOffset(0),
+ mOpaque(true)
+ {
+ setContent(content);
+ addMouseListener(this);
+ }
+
+ ScrollArea::ScrollArea(const Widget2 *const widget,
+ Widget *content,
+ ScrollPolicy hPolicy,
+ ScrollPolicy vPolicy) :
+ gcn::BasicContainer(widget),
+ MouseListener(),
+ mVScroll(0),
+ mHScroll(0),
+ mScrollbarWidth(12),
+ mHPolicy(hPolicy),
+ mVPolicy(vPolicy),
+ mVBarVisible(false),
+ mHBarVisible(false),
+ mUpButtonPressed(false),
+ mDownButtonPressed(false),
+ mLeftButtonPressed(false),
+ mRightButtonPressed(false),
+ mUpButtonScrollAmount(10),
+ mDownButtonScrollAmount(10),
+ mLeftButtonScrollAmount(10),
+ mRightButtonScrollAmount(10),
+ mIsVerticalMarkerDragged(false),
+ mIsHorizontalMarkerDragged(false),
+ mHorizontalMarkerDragOffset(0),
+ mVerticalMarkerDragOffset(0),
+ mOpaque(true)
+ {
+ setContent(content);
+ addMouseListener(this);
+ }
+
+ ScrollArea::~ScrollArea()
+ {
+ setContent(nullptr);
+ }
+
+ void ScrollArea::setContent(Widget* widget)
+ {
+ if (widget)
+ {
+ clear();
+ add(widget);
+ widget->setPosition(0, 0);
+ }
+ else
+ {
+ clear();
+ }
+
+ checkPolicies();
+ }
+
+ Widget* ScrollArea::getContent()
+ {
+ if (!mWidgets.empty())
+ return *mWidgets.begin();
+
+ return nullptr;
+ }
+
+ void ScrollArea::setHorizontalScrollPolicy(ScrollPolicy hPolicy)
+ {
+ mHPolicy = hPolicy;
+ checkPolicies();
+ }
+
+ ScrollArea::ScrollPolicy ScrollArea::getHorizontalScrollPolicy() const
+ {
+ return mHPolicy;
+ }
+
+ void ScrollArea::setVerticalScrollPolicy(ScrollPolicy vPolicy)
+ {
+ mVPolicy = vPolicy;
+ checkPolicies();
+ }
+
+ ScrollArea::ScrollPolicy ScrollArea::getVerticalScrollPolicy() const
+ {
+ return mVPolicy;
+ }
+
+ void ScrollArea::setScrollPolicy(ScrollPolicy hPolicy,
+ ScrollPolicy vPolicy)
+ {
+ mHPolicy = hPolicy;
+ mVPolicy = vPolicy;
+ checkPolicies();
+ }
+
+ void ScrollArea::setVerticalScrollAmount(int vScroll)
+ {
+ const int max = getVerticalMaxScroll();
+
+ mVScroll = vScroll;
+
+ if (vScroll > max)
+ mVScroll = max;
+
+ if (vScroll < 0)
+ mVScroll = 0;
+ }
+
+ int ScrollArea::getVerticalScrollAmount() const
+ {
+ return mVScroll;
+ }
+
+ void ScrollArea::setHorizontalScrollAmount(int hScroll)
+ {
+ const int max = getHorizontalMaxScroll();
+
+ mHScroll = hScroll;
+
+ if (hScroll > max)
+ mHScroll = max;
+ else if (hScroll < 0)
+ mHScroll = 0;
+ }
+
+ int ScrollArea::getHorizontalScrollAmount() const
+ {
+ return mHScroll;
+ }
+
+ void ScrollArea::setScrollAmount(int hScroll, int vScroll)
+ {
+ setHorizontalScrollAmount(hScroll);
+ setVerticalScrollAmount(vScroll);
+ }
+
+ int ScrollArea::getHorizontalMaxScroll()
+ {
+ checkPolicies();
+
+ const Widget *const content = getContent();
+ if (!content)
+ 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)
+ return 0;
+
+ int value;
+
+ value = content->getHeight() - getChildrenArea().height +
+ 2 * content->getFrameSize();
+
+ if (value < 0)
+ return 0;
+
+ return value;
+ }
+
+ void ScrollArea::setScrollbarWidth(int width)
+ {
+ if (width > 0)
+ mScrollbarWidth = width;
+ }
+
+ int ScrollArea::getScrollbarWidth() const
+ {
+ return mScrollbarWidth;
+ }
+
+ void ScrollArea::mouseReleased(MouseEvent& mouseEvent)
+ {
+ mUpButtonPressed = false;
+ mDownButtonPressed = false;
+ mLeftButtonPressed = false;
+ mRightButtonPressed = false;
+ mIsHorizontalMarkerDragged = false;
+ mIsVerticalMarkerDragged = false;
+
+ mouseEvent.consume();
+ }
+
+ void ScrollArea::draw(Graphics *graphics A_UNUSED)
+ {
+ }
+
+ void ScrollArea::drawHBar(Graphics* graphics A_UNUSED)
+ {
+ }
+
+ void ScrollArea::drawVBar(Graphics* graphics A_UNUSED)
+ {
+ }
+
+ void ScrollArea::drawBackground(Graphics *graphics A_UNUSED)
+ {
+ }
+
+ void ScrollArea::drawUpButton(Graphics* graphics A_UNUSED)
+ {
+ }
+
+ void ScrollArea::drawDownButton(Graphics* graphics A_UNUSED)
+ {
+ }
+
+ void ScrollArea::drawLeftButton(Graphics* graphics A_UNUSED)
+ {
+ }
+
+ void ScrollArea::drawRightButton(Graphics* graphics A_UNUSED)
+ {
+ }
+
+ void ScrollArea::drawVMarker(Graphics* graphics A_UNUSED)
+ {
+ }
+
+ void ScrollArea::drawHMarker(Graphics* graphics A_UNUSED)
+ {
+ }
+
+ void ScrollArea::logic()
+ {
+ BLOCK_START("ScrollArea::logic")
+ checkPolicies();
+
+ setVerticalScrollAmount(getVerticalScrollAmount());
+ setHorizontalScrollAmount(getHorizontalScrollAmount());
+
+ Widget *const content = getContent();
+ if (content)
+ {
+ const int frameSize = content->getFrameSize();
+ content->setPosition(-mHScroll + frameSize, -mVScroll + frameSize);
+ content->logic();
+ }
+ BLOCK_END("ScrollArea::logic")
+ }
+
+ void ScrollArea::checkPolicies()
+ {
+ const int w = getWidth();
+ const int h = getHeight();
+
+ mHBarVisible = false;
+ mVBarVisible = false;
+
+ const Widget *const content = getContent();
+ if (!content)
+ {
+ 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;
+ }
+ }
+
+ 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;
+ }
+
+ void ScrollArea::showWidgetPart(Widget* widget, Rect area)
+ {
+ const Widget *const content = getContent();
+ if (widget != content)
+ return;
+
+ BasicContainer::showWidgetPart(widget, area);
+
+ setHorizontalScrollAmount(content->getFrameSize()
+ - content->getX());
+ setVerticalScrollAmount(content->getFrameSize()
+ - content->getY());
+ }
+
+ Widget *ScrollArea::getWidgetAt(int x, int y)
+ {
+ if (getChildrenArea().isPointInRect(x, y))
+ return getContent();
+
+ return nullptr;
+ }
+
+ void ScrollArea::mouseWheelMovedUp(MouseEvent& mouseEvent)
+ {
+ if (mouseEvent.isConsumed())
+ return;
+
+ setVerticalScrollAmount(getVerticalScrollAmount()
+ - getChildrenArea().height / 8);
+
+ mouseEvent.consume();
+ }
+
+ void ScrollArea::mouseWheelMovedDown(MouseEvent& mouseEvent)
+ {
+ if (mouseEvent.isConsumed())
+ return;
+
+ setVerticalScrollAmount(getVerticalScrollAmount()
+ + getChildrenArea().height / 8);
+
+ mouseEvent.consume();
+ }
+
+ 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::setLeftButtonScrollAmount(int amount)
+ {
+ mLeftButtonScrollAmount = amount;
+ }
+
+ void ScrollArea::setRightButtonScrollAmount(int amount)
+ {
+ mRightButtonScrollAmount = amount;
+ }
+
+ void ScrollArea::setUpButtonScrollAmount(int amount)
+ {
+ mUpButtonScrollAmount = amount;
+ }
+
+ void ScrollArea::setDownButtonScrollAmount(int amount)
+ {
+ mDownButtonScrollAmount = amount;
+ }
+
+ int ScrollArea::getLeftButtonScrollAmount() const
+ {
+ return mLeftButtonScrollAmount;
+ }
+
+ int ScrollArea::getRightButtonScrollAmount() const
+ {
+ return mRightButtonScrollAmount;
+ }
+
+ int ScrollArea::getUpButtonScrollAmount() const
+ {
+ return mUpButtonScrollAmount;
+ }
+
+ int ScrollArea::getDownButtonScrollAmount() const
+ {
+ return mDownButtonScrollAmount;
+ }
+
+ void ScrollArea::setOpaque(bool opaque)
+ {
+ mOpaque = opaque;
+ }
+
+ bool ScrollArea::isOpaque() const
+ {
+ return mOpaque;
+ }
+} // namespace gcn
diff --git a/src/gui/base/widgets/scrollarea.hpp b/src/gui/base/widgets/scrollarea.hpp
new file mode 100644
index 000000000..879792019
--- /dev/null
+++ b/src/gui/base/widgets/scrollarea.hpp
@@ -0,0 +1,549 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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 GCN_SCROLLAREA_HPP
+#define GCN_SCROLLAREA_HPP
+
+#include "gui/base/basiccontainer.hpp"
+#include "listeners/mouselistener.h"
+
+namespace gcn
+{
+ /**
+ * Implementation if a scrollable area used to view widgets larger than the scroll area.
+ * A scroll area can be customized to always show scroll bars or to show them only when
+ * necessary.
+ */
+ class ScrollArea:
+ public BasicContainer,
+ public MouseListener
+ {
+ 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
+ };
+
+ /**
+ * Constructor.
+ */
+ explicit ScrollArea(const Widget2 *const widget);
+
+ /**
+ * Constructor.
+ *
+ * @param content The content of the scroll area.
+ */
+ ScrollArea(const Widget2 *const widget,
+ Widget *const content);
+
+ /**
+ * Constructor.
+ *
+ * @param content The content of the scroll area.
+ * @param hPolicy The policy for the horizontal scrollbar. See enum with
+ * policies.
+ * @param vPolicy The policy for the vertical scrollbar. See enum with
+ * policies.
+ */
+ ScrollArea(const Widget2 *const widget,
+ Widget *content,
+ ScrollPolicy hPolicy,
+ ScrollPolicy vPolicy);
+
+ A_DELETE_COPY(ScrollArea)
+
+ /**
+ * Destructor.
+ */
+ virtual ~ScrollArea();
+
+ /**
+ * 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(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;
+
+ /**
+ * Sets the vertical scrollbar policy. See enum with policies.
+ *
+ * @param vPolicy The policy for the vertical scrollbar.
+ * @see getVerticalScrollPolicy
+ */
+ void setVerticalScrollPolicy(ScrollPolicy vPolicy);
+
+ /**
+ * Gets the vertical scrollbar policy. See enum with policies.
+ *
+ * @return The policy for the vertical scrollbar.
+ * @see setVerticalScrollPolicy, setScrollPolicy
+ */
+ ScrollPolicy getVerticalScrollPolicy() const;
+
+ /**
+ * 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(ScrollPolicy hPolicy, ScrollPolicy vPolicy);
+
+ /**
+ * Sets the amount to scroll vertically.
+ *
+ * @param vScroll The amount to scroll.
+ * @see getVerticalScrollAmount
+ */
+ void setVerticalScrollAmount(int vScroll);
+
+ /**
+ * Gets the amount that is scrolled vertically.
+ *
+ * @return The scroll amount on vertical scroll.
+ * @see setVerticalScrollAmount, setScrollAmount
+ */
+ int getVerticalScrollAmount() const;
+
+ /**
+ * 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;
+
+ /**
+ * 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(int hScroll, 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(int width);
+
+ /**
+ * Gets the width of the scroll bars.
+ *
+ * @return the width of the ScrollBar.
+ * @see setScrollbarWidth
+ */
+ int getScrollbarWidth() const;
+
+ /**
+ * 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(int 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(int 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(int 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(int 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;
+
+ /**
+ * 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;
+
+ /**
+ * 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;
+
+ /**
+ * 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;
+
+ /**
+ * Sets the scroll area to be opaque, that is sets the scoll area
+ * to display its background.
+ *
+ * @param opaque True if the scoll area should be opaque, false otherwise.
+ */
+ void setOpaque(bool opaque);
+
+ /**
+ * Checks if the scroll area is opaque, that is if the scroll area
+ * displays its background.
+ *
+ * @return True if the scroll area is opaque, false otherwise.
+ */
+ bool isOpaque() const;
+
+ // Inherited from BasicContainer
+
+ virtual void showWidgetPart(Widget* widget, Rect area);
+
+ virtual Rect getChildrenArea();
+
+ virtual Widget *getWidgetAt(int x, int y);
+
+
+ // Inherited from Widget
+
+ virtual void draw(Graphics *graphics);
+
+ virtual void logic();
+
+ void setWidth(int width);
+
+ void setHeight(int height);
+
+ void setDimension(const Rect& dimension);
+
+
+ // Inherited from MouseListener
+
+ virtual void mouseReleased(MouseEvent& mouseEvent) override;
+
+ virtual void mouseWheelMovedUp(MouseEvent& mouseEvent) override;
+
+ virtual void mouseWheelMovedDown(MouseEvent& mouseEvent) override;
+
+ protected:
+ /**
+ * Draws the background of the scroll area, that is
+ * the area behind the content.
+ *
+ * @param graphics a Graphics object to draw with.
+ */
+ virtual void drawBackground(Graphics *graphics);
+
+ /**
+ * Draws the up button.
+ *
+ * @param graphics a Graphics object to draw with.
+ */
+ virtual void drawUpButton(Graphics *graphics);
+
+ /**
+ * Draws the down button.
+ *
+ * @param graphics a Graphics object to draw with.
+ */
+ virtual void drawDownButton(Graphics *graphics);
+
+ /**
+ * Draws the left button.
+ *
+ * @param graphics a Graphics object to draw with.
+ */
+ virtual void drawLeftButton(Graphics *graphics);
+
+ /**
+ * Draws the right button.
+ *
+ * @param graphics a Graphics object to draw with.
+ */
+ virtual void drawRightButton(Graphics *graphics);
+
+ /**
+ * Draws the vertical scroll bar.
+ *
+ * @param graphics a Graphics object to draw with.
+ */
+ virtual void drawVBar(Graphics* graphics);
+
+ /**
+ * Draws the horizontal scroll bar.
+ *
+ * @param graphics a Graphics object to draw with.
+ */
+ virtual void drawHBar(Graphics* graphics);
+
+ /**
+ * Draws the vertical marker.
+ *
+ * @param graphics a Graphics object to draw with.
+ */
+ virtual void drawVMarker(Graphics* graphics);
+
+ /**
+ * Draws the horizontal marker.
+ *
+ * @param graphics a Graphics object to draw with.
+ */
+ virtual void drawHMarker(Graphics* graphics);
+
+ /**
+ * Checks the policies for the scroll bars.
+ */
+ virtual void checkPolicies();
+
+ /**
+ * 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 horizontal scroll bar policy.
+ */
+ ScrollPolicy mHPolicy;
+
+ /**
+ * Holds the vertical scroll bar policy.
+ */
+ ScrollPolicy mVPolicy;
+
+ /**
+ * 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;
+
+ /**
+ * 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;
+
+ /**
+ * True if the vertical marked is dragged.
+ */
+ bool mIsVerticalMarkerDragged;
+
+ /**
+ * True if the horizontal marked is dragged.
+ */
+ bool mIsHorizontalMarkerDragged;
+
+ /**
+ * Holds the horizontal markers drag offset.
+ */
+ int mHorizontalMarkerDragOffset;
+
+ /**
+ * Holds the vertical markers drag offset.
+ */
+ int mVerticalMarkerDragOffset;
+
+ /**
+ * True if the scroll area should be opaque (that is
+ * display its background), false otherwise.
+ */
+ bool mOpaque;
+ };
+} // namespace gcn
+
+#endif // end GCN_SCROLLAREA_HPP
diff --git a/src/gui/base/widgets/slider.cpp b/src/gui/base/widgets/slider.cpp
new file mode 100644
index 000000000..40c73ceb5
--- /dev/null
+++ b/src/gui/base/widgets/slider.cpp
@@ -0,0 +1,230 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/base/widgets/slider.hpp"
+
+#include "debug.h"
+
+namespace gcn
+{
+ Slider::Slider(const Widget2 *const widget,
+ const double scaleEnd) :
+ Widget(widget),
+ MouseListener(),
+ KeyListener(),
+ mDragged(false),
+ mValue(0),
+ mStepLength(scaleEnd / 10),
+ mMarkerLength(10),
+ mScaleStart(0),
+ mScaleEnd(scaleEnd),
+ mOrientation(HORIZONTAL)
+ {
+ setFocusable(true);
+ setFrameSize(1);
+
+ addMouseListener(this);
+ addKeyListener(this);
+ }
+
+ Slider::Slider(const Widget2 *const widget,
+ const double scaleStart,
+ const double scaleEnd) :
+ Widget(widget),
+ MouseListener(),
+ KeyListener(),
+ mDragged(false),
+ mValue(scaleStart),
+ mStepLength((scaleEnd - scaleStart) / 10),
+ mMarkerLength(10),
+ mScaleStart(scaleStart),
+ mScaleEnd(scaleEnd),
+ mOrientation(HORIZONTAL)
+ {
+ setFocusable(true);
+ setFrameSize(1);
+
+ addMouseListener(this);
+ addKeyListener(this);
+ }
+
+ void Slider::setScale(double scaleStart, double scaleEnd)
+ {
+ mScaleStart = scaleStart;
+ mScaleEnd = scaleEnd;
+ }
+
+ double Slider::getScaleStart() const
+ {
+ return mScaleStart;
+ }
+
+ void Slider::setScaleStart(double scaleStart)
+ {
+ mScaleStart = scaleStart;
+ }
+
+ double Slider::getScaleEnd() const
+ {
+ return mScaleEnd;
+ }
+
+ void Slider::setScaleEnd(double scaleEnd)
+ {
+ mScaleEnd = scaleEnd;
+ }
+
+ void Slider::setValue(double value)
+ {
+ if (value > getScaleEnd())
+ {
+ mValue = getScaleEnd();
+ return;
+ }
+
+ if (value < getScaleStart())
+ {
+ mValue = getScaleStart();
+ return;
+ }
+
+ mValue = value;
+ }
+
+ double Slider::getValue() const
+ {
+ return mValue;
+ }
+
+ int Slider::getMarkerLength() const
+ {
+ return mMarkerLength;
+ }
+
+ void Slider::setMarkerLength(int length)
+ {
+ mMarkerLength = length;
+ }
+
+ void Slider::setOrientation(Slider::Orientation orientation)
+ {
+ mOrientation = orientation;
+ }
+
+ Slider::Orientation Slider::getOrientation() const
+ {
+ return mOrientation;
+ }
+
+ double Slider::markerPositionToValue(int v) const
+ {
+ int w;
+ if (getOrientation() == HORIZONTAL)
+ w = getWidth();
+ else
+ w = getHeight();
+
+ const double pos = v / (static_cast<double>(w) - getMarkerLength());
+ return (1.0 - pos) * getScaleStart() + pos * getScaleEnd();
+ }
+
+ int Slider::valueToMarkerPosition(double value) const
+ {
+ int v;
+ if (getOrientation() == HORIZONTAL)
+ v = getWidth();
+ else
+ v = getHeight();
+
+ const int w = static_cast<int>((v - getMarkerLength())
+ * (value - getScaleStart())
+ / (getScaleEnd() - getScaleStart()));
+
+ if (w < 0)
+ return 0;
+
+ if (w > v - getMarkerLength())
+ return v - getMarkerLength();
+
+ return w;
+ }
+
+ void Slider::setStepLength(double length)
+ {
+ mStepLength = length;
+ }
+
+ double Slider::getStepLength() const
+ {
+ return mStepLength;
+ }
+
+ int Slider::getMarkerPosition() const
+ {
+ return valueToMarkerPosition(getValue());
+ }
+} // namespace gcn
diff --git a/src/gui/base/widgets/slider.hpp b/src/gui/base/widgets/slider.hpp
new file mode 100644
index 000000000..9d5adc6d8
--- /dev/null
+++ b/src/gui/base/widgets/slider.hpp
@@ -0,0 +1,297 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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 GCN_SLIDER_HPP
+#define GCN_SLIDER_HPP
+
+#include "listeners/keylistener.h"
+#include "listeners/mouselistener.h"
+
+#include "gui/widgets/widget.h"
+
+namespace gcn
+{
+ /**
+ * An implementation of a slider where a user can select different values by
+ * sliding between a start value and an end value of a scale.
+ *
+ * If the selected value is changed an action event will be sent to all
+ * action listeners of the slider.
+ */
+ class Slider :
+ public Widget,
+ public MouseListener,
+ public KeyListener
+ {
+ public:
+ /**
+ * Draw orientations for the slider. A slider can be drawn vertically or
+ * horizontally.
+ */
+ enum Orientation
+ {
+ HORIZONTAL = 0,
+ VERTICAL
+ };
+
+ /**
+ * Constructor. The default start value of the slider scale is zero.
+ *
+ * @param scaleEnd The end value of the slider scale.
+ */
+ explicit Slider(const Widget2 *const widget,
+ const double scaleEnd = 1.0);
+
+ /**
+ * Constructor.
+ *
+ * @param scaleStart The start value of the slider scale.
+ * @param scaleEnd The end value of the slider scale.
+ */
+ Slider(const Widget2 *const widget,
+ const double scaleStart,
+ const double scaleEnd);
+
+ A_DELETE_COPY(Slider)
+
+ /**
+ * Destructor.
+ */
+ virtual ~Slider()
+ { }
+
+ /**
+ * 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(double scaleStart, double scaleEnd);
+
+ /**
+ * Gets the start value of the scale.
+ *
+ * @return The start value of the scale.
+ * @see setScaleStart, setScale
+ */
+ double getScaleStart() const;
+
+ /**
+ * Sets the start value of the scale.
+ *
+ * @param scaleStart The start value of the scale.
+ * @see getScaleStart
+ */
+ void setScaleStart(double scaleStart);
+
+ /**
+ * Gets the end value of the scale.
+ *
+ * @return The end value of the scale.
+ * @see setScaleEnd, setScale
+ */
+ double getScaleEnd() const;
+
+ /**
+ * Sets the end value of the scale.
+ *
+ * @param scaleEnd The end value of the scale.
+ * @see getScaleEnd
+ */
+ void setScaleEnd(double scaleEnd);
+
+ /**
+ * Gets the current selected value.
+ *
+ * @return The current selected value.
+ * @see setValue
+ */
+ double getValue() const;
+
+ /**
+ * Sets the current selected value.
+ *
+ * @param value The current selected value.
+ * @see getValue
+ */
+ void setValue(double value);
+
+ /**
+ * Sets the length of the marker.
+ *
+ * @param length The length for the marker.
+ * @see getMarkerLength
+ */
+ void setMarkerLength(int length);
+
+ /**
+ * Gets the length of the marker.
+ *
+ * @return The length of the marker.
+ * @see setMarkerLength
+ */
+ int getMarkerLength() const;
+
+ /**
+ * 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(Orientation orientation);
+
+ /**
+ * Gets the orientation of the slider. A slider can be drawn vertically
+ * or horizontally.
+ *
+ * @return The orientation of the slider.
+ * @see setOrientation
+ */
+ Orientation getOrientation() const;
+
+ /**
+ * 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(double 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;
+
+ protected:
+ /**
+ * 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
+ */
+ virtual double markerPositionToValue(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
+ */
+ virtual int valueToMarkerPosition(double value) const;
+
+ /**
+ * Gets the marker position of the current selected value.
+ *
+ * @return The marker position of the current selected value.
+ */
+ virtual int getMarkerPosition() const;
+
+ /**
+ * True if the slider is dragged, false otherwise.
+ */
+ bool mDragged;
+
+ /**
+ * 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 length of the marker.
+ */
+ int mMarkerLength;
+
+ /**
+ * 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.
+ */
+ Orientation mOrientation;
+ };
+} // namespace gcn
+
+#endif // end GCN_SLIDER_HPP
diff --git a/src/gui/base/widgets/textbox.cpp b/src/gui/base/widgets/textbox.cpp
new file mode 100644
index 000000000..f74db9a29
--- /dev/null
+++ b/src/gui/base/widgets/textbox.cpp
@@ -0,0 +1,344 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/base/widgets/textbox.hpp"
+
+#include "gui/font.h"
+
+#include "render/graphics.h"
+
+#include "debug.h"
+
+namespace gcn
+{
+ TextBox::TextBox(const Widget2 *const widget) :
+ Widget(widget),
+ MouseListener(),
+ KeyListener(),
+ mTextRows(),
+ mCaretColumn(0),
+ mCaretRow(0),
+ mEditable(true),
+ mOpaque(true)
+ {
+ setText("");
+ setFocusable(true);
+
+ addMouseListener(this);
+ addKeyListener(this);
+ adjustSize();
+ }
+
+ TextBox::TextBox(const Widget2 *const widget,
+ const std::string& text) :
+ Widget(widget),
+ MouseListener(),
+ KeyListener(),
+ mTextRows(),
+ mCaretColumn(0),
+ mCaretRow(0),
+ mEditable(true),
+ mOpaque(true)
+ {
+ setText(text);
+ setFocusable(true);
+
+ addMouseListener(this);
+ addKeyListener(this);
+ adjustSize();
+ }
+
+ void TextBox::setText(const std::string& text)
+ {
+ mCaretColumn = 0;
+ mCaretRow = 0;
+
+ mTextRows.clear();
+
+ size_t pos, lastPos = 0;
+ int length;
+ do
+ {
+ pos = text.find("\n", lastPos);
+
+ if (pos != std::string::npos)
+ length = static_cast<int>(pos - lastPos);
+ else
+ length = static_cast<int>(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::draw(Graphics* graphics)
+ {
+ }
+*/
+
+ void TextBox::drawCaret(Graphics* graphics, int x, int y)
+ {
+ graphics->setColor(mForegroundColor);
+ graphics->drawLine(x, getFont()->getHeight() + y, x, y);
+ }
+
+ void TextBox::mousePressed(MouseEvent& mouseEvent)
+ {
+ if (mouseEvent.getButton() == MouseEvent::LEFT)
+ {
+ mCaretRow = mouseEvent.getY() / getFont()->getHeight();
+
+ const int sz = static_cast<int>(mTextRows.size());
+ if (mCaretRow >= sz)
+ mCaretRow = sz - 1;
+
+ mCaretColumn = getFont()->getStringIndexAt(
+ mTextRows[mCaretRow], mouseEvent.getX());
+ }
+ }
+
+ void TextBox::mouseDragged(MouseEvent& mouseEvent)
+ {
+ mouseEvent.consume();
+ }
+
+ void TextBox::keyPressed(KeyEvent& keyEvent A_UNUSED)
+ {
+ }
+
+ void TextBox::adjustSize()
+ {
+ int width = 0;
+ for (size_t i = 0, sz = mTextRows.size(); i < sz; ++i)
+ {
+ const int w = getFont()->getWidth(mTextRows[i]);
+ if (width < w)
+ width = w;
+ }
+
+ setWidth(width + 1);
+ setHeight(static_cast<int>(getFont()->getHeight() * mTextRows.size()));
+ }
+
+ void TextBox::setCaretPosition(unsigned int position)
+ {
+ for (int row = 0, sz = static_cast<int>(mTextRows.size());
+ row < sz; row ++)
+ {
+ if (position <= mTextRows[row].size())
+ {
+ mCaretRow = row;
+ mCaretColumn = position;
+ return; // we are done
+ }
+ else
+ {
+ position--;
+ }
+ }
+
+ // position beyond end of text
+ mCaretRow = static_cast<int>(mTextRows.size() - 1);
+ mCaretColumn = static_cast<int>(mTextRows[mCaretRow].size());
+ }
+
+ unsigned int TextBox::getCaretPosition() const
+ {
+ int pos = 0, row;
+
+ for (row = 0; row < mCaretRow; row++)
+ pos += static_cast<int>(mTextRows[row].size());
+
+ return pos + mCaretColumn;
+ }
+
+ void TextBox::setCaretRowColumn(int row, int column)
+ {
+ setCaretRow(row);
+ setCaretColumn(column);
+ }
+
+ void TextBox::setCaretRow(int row)
+ {
+ mCaretRow = row;
+
+ const int sz = static_cast<int>(mTextRows.size());
+ if (mCaretRow >= sz)
+ mCaretRow = sz - 1;
+
+ if (mCaretRow < 0)
+ mCaretRow = 0;
+
+ setCaretColumn(mCaretColumn);
+ }
+
+ unsigned int TextBox::getCaretRow() const
+ {
+ return mCaretRow;
+ }
+
+ void TextBox::setCaretColumn(int column)
+ {
+ mCaretColumn = column;
+
+ const int sz = static_cast<int>(mTextRows[mCaretRow].size());
+ if (mCaretColumn > sz)
+ mCaretColumn = sz;
+
+ if (mCaretColumn < 0)
+ mCaretColumn = 0;
+ }
+
+ unsigned int TextBox::getCaretColumn() const
+ {
+ return mCaretColumn;
+ }
+
+ const std::string& TextBox::getTextRow(int row) const
+ {
+ return mTextRows[row];
+ }
+
+ void TextBox::setTextRow(int row, const std::string& text)
+ {
+ mTextRows[row] = text;
+
+ if (mCaretRow == row)
+ setCaretColumn(mCaretColumn);
+
+ adjustSize();
+ }
+
+ unsigned int TextBox::getNumberOfRows() const
+ {
+ return static_cast<int>(mTextRows.size());
+ }
+
+ std::string TextBox::getText() const
+ {
+ if (mTextRows.empty())
+ return std::string("");
+
+ int i;
+ std::string text;
+
+ const int sz = static_cast<int>(mTextRows.size());
+ for (i = 0; i < sz - 1; ++ i)
+ text.append(mTextRows[i]).append("\n");
+ text.append(mTextRows[i]);
+
+ return text;
+ }
+
+ void TextBox::fontChanged()
+ {
+ adjustSize();
+ }
+
+ void TextBox::scrollToCaret()
+ {
+ Rect scroll;
+ scroll.x = getFont()->getWidth(
+ mTextRows[mCaretRow].substr(0, mCaretColumn));
+ scroll.y = getFont()->getHeight() * mCaretRow;
+ scroll.width = getFont()->getWidth(" ");
+
+ // add 2 for some extra space
+ scroll.height = getFont()->getHeight() + 2;
+
+ showPart(scroll);
+ }
+
+ void TextBox::setEditable(bool editable)
+ {
+ mEditable = editable;
+ }
+
+ bool TextBox::isEditable() const
+ {
+ return mEditable;
+ }
+
+ void TextBox::addRow(const std::string &row)
+ {
+ mTextRows.push_back(row);
+ adjustSize();
+ }
+
+ bool TextBox::isOpaque()
+ {
+ return mOpaque;
+ }
+
+ void TextBox::setOpaque(bool opaque)
+ {
+ mOpaque = opaque;
+ }
+} // namespace gcn
diff --git a/src/gui/base/widgets/textbox.hpp b/src/gui/base/widgets/textbox.hpp
new file mode 100644
index 000000000..148b4f007
--- /dev/null
+++ b/src/gui/base/widgets/textbox.hpp
@@ -0,0 +1,311 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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 GCN_TEXTBOX_HPP
+#define GCN_TEXTBOX_HPP
+
+#include <string>
+#include <vector>
+
+#include "listeners/keylistener.h"
+#include "listeners/mouselistener.h"
+
+#include "gui/widgets/widget.h"
+
+namespace gcn
+{
+ /**
+ * An implementation of a text box where a user can enter text that contains of many lines.
+ */
+ class TextBox:
+ public Widget,
+ public MouseListener,
+ public KeyListener
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ explicit TextBox(const Widget2 *const widget);
+
+ /**
+ * Constructor.
+ *
+ * @param text The default text of the text box.
+ */
+ TextBox(const Widget2 *const widget,
+ const std::string& text);
+
+ A_DELETE_COPY(TextBox)
+
+ /**
+ * 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(int row) const;
+
+ /**
+ * 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(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;
+
+ /**
+ * 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;
+
+ /**
+ * Sets the row where the caret should be currently located.
+ *
+ * @param The row where the caret should be currently located.
+ * @see getCaretRow
+ */
+ void setCaretRow(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(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(int row, int column);
+
+ /**
+ * Scrolls the text to the caret if the text box is in a scroll area.
+ *
+ * @see ScrollArea
+ */
+ virtual void scrollToCaret();
+
+ /**
+ * Checks if the text box is editable.
+ *
+ * @return True it the text box is editable, false otherwise.
+ * @see setEditable
+ */
+ bool isEditable() const;
+
+ /**
+ * Sets the text box to be editable or not.
+ *
+ * @param editable True if the text box should be editable, false otherwise.
+ */
+ void setEditable(bool editable);
+
+ /**
+ * Adds a row of text to the end of the text.
+ *
+ * @param row The row to add.
+ */
+ virtual 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();
+
+ /**
+ * 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(bool opaque);
+
+
+ // Inherited from Widget
+
+// virtual void draw(Graphics* graphics);
+
+ virtual void fontChanged();
+
+
+ // Inherited from KeyListener
+
+ virtual void keyPressed(KeyEvent& keyEvent) override;
+
+
+ // Inherited from MouseListener
+
+ virtual void mousePressed(MouseEvent& mouseEvent) override;
+
+ virtual void mouseDragged(MouseEvent& mouseEvent) override;
+
+ protected:
+ /**
+ * 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.
+ */
+ virtual void drawCaret(Graphics* graphics, int x, int y);
+
+ /**
+ * Adjusts the text box's size to fit the text.
+ */
+ virtual 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;
+
+ /**
+ * True if the text box is editable, false otherwise.
+ */
+ bool mEditable;
+
+ /**
+ * True if the text box is editable, false otherwise.
+ */
+ bool mOpaque;
+ };
+} // namespace gcn
+
+#endif // end GCN_TEXTBOX_HPP
diff --git a/src/gui/base/widgets/textfield.cpp b/src/gui/base/widgets/textfield.cpp
new file mode 100644
index 000000000..c2cead500
--- /dev/null
+++ b/src/gui/base/widgets/textfield.cpp
@@ -0,0 +1,163 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/base/widgets/textfield.hpp"
+
+#include "gui/font.h"
+
+#include "debug.h"
+
+namespace gcn
+{
+ TextField::TextField(const Widget2 *const widget) :
+ Widget(widget),
+ MouseListener(),
+ KeyListener(),
+ mText(),
+ mCaretPosition(0),
+ mXScroll(0)
+ {
+ setFocusable(true);
+
+ addMouseListener(this);
+ addKeyListener(this);
+ }
+
+ TextField::TextField(const Widget2 *const widget,
+ const std::string& text) :
+ Widget(widget),
+ MouseListener(),
+ KeyListener(),
+ mText(text),
+ mCaretPosition(0),
+ mXScroll(0)
+ {
+ adjustSize();
+
+ setFocusable(true);
+
+ addMouseListener(this);
+ addKeyListener(this);
+ }
+
+ void TextField::setText(const std::string& text)
+ {
+ const size_t sz = text.size();
+ if (sz < mCaretPosition)
+ mCaretPosition = sz;
+ mText = text;
+ }
+
+ void TextField::drawCaret(Graphics* graphics A_UNUSED, int x A_UNUSED)
+ {
+ }
+
+ void TextField::mousePressed(MouseEvent& mouseEvent)
+ {
+ if (mouseEvent.getButton() == MouseEvent::LEFT)
+ {
+ mCaretPosition = getFont()->getStringIndexAt(
+ mText, mouseEvent.getX() + mXScroll);
+ fixScroll();
+ }
+ }
+
+ void TextField::mouseDragged(MouseEvent& mouseEvent)
+ {
+ mouseEvent.consume();
+ }
+
+ void TextField::adjustSize()
+ {
+ }
+
+ void TextField::adjustHeight()
+ {
+ }
+
+ void TextField::fixScroll()
+ {
+ }
+
+ void TextField::setCaretPosition(unsigned int position A_UNUSED)
+ {
+ }
+
+ unsigned int TextField::getCaretPosition() const
+ {
+ return mCaretPosition;
+ }
+
+ const std::string& TextField::getText() const
+ {
+ return mText;
+ }
+
+ void TextField::fontChanged()
+ {
+ }
+} // namespace gcn
diff --git a/src/gui/base/widgets/textfield.hpp b/src/gui/base/widgets/textfield.hpp
new file mode 100644
index 000000000..e9df238ba
--- /dev/null
+++ b/src/gui/base/widgets/textfield.hpp
@@ -0,0 +1,192 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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 GCN_TEXTFIELD_HPP
+#define GCN_TEXTFIELD_HPP
+
+#include "listeners/keylistener.h"
+#include "listeners/mouselistener.h"
+
+#include "gui/widgets/widget.h"
+
+#include <string>
+
+namespace gcn
+{
+ /**
+ * An implementation of a text field where a user can enter a line of text.
+ */
+ class TextField:
+ public Widget,
+ public MouseListener,
+ public KeyListener
+ {
+ public:
+ /**
+ * Constructor.
+ */
+ explicit TextField(const Widget2 *const widget);
+
+ /**
+ * Constructor. The text field will be automatically resized
+ * to fit the text.
+ *
+ * @param text The default text of the text field.
+ */
+ TextField(const Widget2 *const widget,
+ const std::string& text);
+
+ A_DELETE_COPY(TextField)
+
+ /**
+ * 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;
+
+ /**
+ * Adjusts the size of the text field to fit the text.
+ */
+ void adjustSize();
+
+ /**
+ * Adjusts the height of the text field to fit caption.
+ */
+ void adjustHeight();
+
+ /**
+ * Sets the caret position. As there is only one line of text
+ * in a text field the position is the caret's x coordinate.
+ *
+ * @param position The caret position.
+ * @see getCaretPosition
+ */
+ void setCaretPosition(unsigned int position);
+
+ /**
+ * 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;
+
+
+ // Inherited from Widget
+
+ virtual void fontChanged();
+
+ // Inherited from MouseListener
+
+ virtual void mousePressed(MouseEvent& mouseEvent) override;
+
+ virtual void mouseDragged(MouseEvent& mouseEvent) override;
+
+ protected:
+ /**
+ * Draws the caret. Overloaded this method if you want to
+ * change the style of the caret.
+ *
+ * @param graphics the Graphics object to draw with.
+ * @param x the caret's x-position.
+ */
+ virtual void drawCaret(Graphics* graphics, int x);
+
+ /**
+ * Scrolls the text horizontally so that the caret shows if needed.
+ * The method is used any time a user types in the text field so the
+ * caret always will be shown.
+ */
+ void fixScroll();
+
+ /**
+ * Holds the text of the text box.
+ */
+ std::string mText;
+
+ /**
+ * 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;
+ };
+} // namespace gcn
+
+#endif // end GCN_TEXTFIELD_HPP
diff --git a/src/gui/cliprect.cpp b/src/gui/cliprect.cpp
new file mode 100644
index 000000000..5255a4c98
--- /dev/null
+++ b/src/gui/cliprect.cpp
@@ -0,0 +1,104 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/cliprect.h"
+
+#include "debug.h"
+
+ClipRect::ClipRect() :
+ Rect(),
+ xOffset(0),
+ yOffset(0)
+{
+ x = 0;
+ y = 0;
+ width = 0;
+ height = 0;
+}
+
+ClipRect::ClipRect(const int x0, const int y0,
+ const int width0, const int height0,
+ const int xOffset0, const int yOffset0) :
+ Rect(),
+ xOffset(xOffset0),
+ yOffset(yOffset0)
+{
+ x = x0;
+ y = y0;
+ width = width0;
+ height = height0;
+}
+
+const ClipRect& ClipRect::operator=(const Rect& other)
+{
+ x = other.x;
+ y = other.y;
+ width = other.width;
+ height = other.height;
+
+ return *this;
+}
diff --git a/src/gui/cliprect.h b/src/gui/cliprect.h
new file mode 100644
index 000000000..88a7ab5a4
--- /dev/null
+++ b/src/gui/cliprect.h
@@ -0,0 +1,126 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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_CLIPRECT_H
+#define GUI_CLIPRECT_H
+
+#include "gui/rect.h"
+
+#include "localconsts.h"
+
+/**
+ * A rectangle used when dealing with clipping. A clip rectangle is
+ * a regular rectangle extended with variables for x offsets and y
+ * offsets. The offsets are used for calculations from relative
+ * screen coordinates to actual screen coordinates.
+ */
+class ClipRect final : public Rect
+{
+ public:
+ /**
+ * Constructor.
+ */
+ ClipRect();
+
+ /**
+ * Constructor.
+ *
+ * @param x0 The rectangle x coordinate.
+ * @param y0 The rectangle y coordinate.
+ * @param width0 The rectangle width.
+ * @param height0 The rectangle height.
+ * @param xOffset0 The offset of the x coordinate. Used to for
+ * calculating the actual screen coordinate from
+ * the relative screen coordinate.
+ * @param yOffset0 The offset of the y coordinate. Used to for
+ * calculating the actual screen coordinate from
+ * the relative screen coordinate.
+ */
+ ClipRect(const int x0,
+ const int y0,
+ const int width0,
+ const int height0,
+ const int xOffset0,
+ const int yOffset0);
+
+ /**
+ * Copy constructor. Copies x, y, width and height
+ * field from a rectangle to a clip rectangle.
+ *
+ * @param other The rectangle to copy data from.
+ * @returns A clip rectangle with data copyied from a rectangle.
+ */
+ const ClipRect& operator=(const Rect& other);
+
+ /**
+ * Holds the x offset of the x coordinate.
+ */
+ int xOffset;
+
+ /**
+ * Holds the y offset of the y coordinate.
+ */
+ int yOffset;
+};
+
+#endif // GUI_CLIPRECT_H
diff --git a/src/gui/color.cpp b/src/gui/color.cpp
new file mode 100644
index 000000000..aa9ffe840
--- /dev/null
+++ b/src/gui/color.cpp
@@ -0,0 +1,165 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/color.h"
+
+#include "debug.h"
+
+Color::Color() :
+ r(0U),
+ g(0U),
+ b(0U),
+ a(255U)
+{
+}
+
+Color::Color(const unsigned int color) :
+ r((color >> 16) & 0xFF),
+ g((color >> 8) & 0xFF),
+ b(color & 0xFF),
+ a(255U)
+{
+}
+
+Color::Color(const unsigned int ar,
+ const unsigned int ag,
+ const unsigned int ab,
+ const unsigned int aa) :
+ r(ar),
+ g(ag),
+ b(ab),
+ a(aa)
+{
+}
+
+Color Color::operator+(const Color& color) const
+{
+ Color result(r + color.r,
+ g + color.g,
+ b + color.b,
+ 255U);
+
+ result.r = (result.r > 255U ? 255U : result.r);
+ result.g = (result.g > 255U ? 255U : result.g);
+ result.b = (result.b > 255U ? 255U : result.b);
+
+ return result;
+}
+
+Color Color::operator-(const Color& color) const
+{
+ Color result(r - color.r,
+ g - color.g,
+ b - color.b,
+ 255U);
+
+ result.r = (result.r > 255U ? 255U : result.r);
+ result.g = (result.g > 255U ? 255U : result.g);
+ result.b = (result.b > 255U ? 255U : result.b);
+
+ return result;
+}
+
+Color Color::operator*(const float value) const
+{
+ Color result(static_cast<int>(static_cast<float>(r) * value),
+ static_cast<int>(static_cast<float>(g) * value),
+ static_cast<int>(static_cast<float>(b) * value),
+ a);
+
+ result.r = (result.r > 255U ? 255U : result.r);
+ result.g = (result.g > 255U ? 255U : result.g);
+ result.b = (result.b > 255U ? 255U : result.b);
+
+ return result;
+}
+
+bool Color::operator==(const Color& color) const
+{
+ return r == color.r && g == color.g && b == color.b && a == color.a;
+}
+
+bool Color::operator!=(const Color& color) const
+{
+ return !(r == color.r && g == color.g && b == color.b && a == color.a);
+}
+
+std::ostream& operator<<(std::ostream& out,
+ const Color& color)
+{
+ out << "Color [r = "
+ << color.r
+ << ", g = "
+ << color.g
+ << ", b = "
+ << color.b
+ << ", a = "
+ << color.a
+ << "]";
+
+ return out;
+}
diff --git a/src/gui/color.h b/src/gui/color.h
new file mode 100644
index 000000000..db8fda970
--- /dev/null
+++ b/src/gui/color.h
@@ -0,0 +1,193 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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_COLOR_H
+#define GUI_COLOR_H
+
+#include <iostream>
+
+#include "localconsts.h"
+
+/**
+ * Represents a color with red, green, blue and alpha components.
+ */
+class Color final
+{
+ public:
+ /**
+ * Constructor. Initializes the color to black.
+ */
+ Color();
+
+ /**
+ * Constructor. Constructs a color from the bytes in an integer.
+ * Call it with a hexadecimal constant for HTML-style color
+ * representation.
+ * The alpha component is 255 by default.
+ *
+ * EXAMPLE: Color(0xff50a0) constructs a very nice pinkish color.
+ *
+ * NOTE: Because of this constructor, integers will be automatically
+ * casted to a color by your compiler.
+ *
+ * @param color The color to initialise the object with.
+ */
+ explicit Color(const unsigned int color);
+
+ /**
+ * Constructor. The default alpha value is 255.
+ *
+ * @param r Red color component (range 0-255).
+ * @param g Green color component (range 0-255).
+ * @param b Blue color component (range 0-255).
+ * @param a Alpha, used for transparency. A value of 0 means
+ * totaly transparent, 255 is totaly opaque.
+ */
+ Color(const unsigned int r,
+ const unsigned int g,
+ const unsigned int b,
+ const unsigned int a = 255);
+
+ /**
+ * Adds the RGB values of two colors together. The values will be
+ * clamped if they go out of range.
+ *
+ * WARNING: This function will reset the alpha value of the
+ * returned color to 255.
+ *
+ * @param color A color to add to this color.
+ * @return The added colors with an alpha value set to 255.
+ */
+ Color operator+(const Color& color) const;
+
+ /**
+ * Subtracts the RGB values of one color from another.
+ * The values will be clamped if they go out of range.
+ *
+ * WARNING: This function will reset the alpha value of the
+ * returned color to 255.
+ *
+ * @param color A color to subtract from this color.
+ * @return The subtracted colors with an alpha value set to 255.
+ */
+ Color operator-(const Color& color) const;
+
+ /**
+ * Multiplies the RGB values of a color with a float value.
+ * The values will be clamped if they go out of range.
+ *
+ * @param value The value to multiply the color with.
+ * @return The multiplied colors. The alpha value will, unlike
+ * the add and subtract operations, be multiplied as
+ * well.
+ */
+ Color operator*(const float value) const;
+
+ /**
+ * Compares two colors.
+ *
+ * @return True if the two colors have the same RGBA components
+ * false otherwise.
+ */
+ bool operator==(const Color& color) const;
+
+ /**
+ * Compares two colors.
+ *
+ * @return True if the two colors have different RGBA components,
+ * false otherwise.
+ */
+ bool operator!=(const Color& color) const;
+
+ /**
+ * Output operator for output.
+ *
+ * @param out The stream to output to.
+ * @param color The color to output.
+ */
+ friend std::ostream& operator<<(std::ostream& out,
+ const Color& Color);
+
+ /**
+ * Holds the red color component (range 0-255).
+ */
+ unsigned int r;
+
+ /**
+ * Holds the green color component (range 0-255).
+ */
+ unsigned int g;
+
+ /**
+ * Holds the blue color component (range 0-255).
+ */
+ unsigned int b;
+
+ /**
+ * Holds the alpha color component. A value of 0 means totally
+ * transparent while a value of 255 is considered opaque.
+ */
+ unsigned int a;
+};
+
+#endif // GUI_COLOR_H
diff --git a/src/gui/focushandler.cpp b/src/gui/focushandler.cpp
index cd780e12d..928b3b72e 100644
--- a/src/gui/focushandler.cpp
+++ b/src/gui/focushandler.cpp
@@ -20,15 +20,74 @@
* 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/focushandler.h"
#include "gui/gui.h"
#include "gui/widgets/window.h"
+#include "listeners/focuslistener.h"
+
#include "debug.h"
-void FocusHandler::requestModalFocus(gcn::Widget *widget)
+FocusHandler::FocusHandler() :
+ mWidgets(),
+ mFocusedWidget(nullptr),
+ mModalFocusedWidget(nullptr),
+ mModalMouseInputFocusedWidget(nullptr),
+ mDraggedWidget(nullptr),
+ mLastWidgetWithMouse(nullptr),
+ mLastWidgetWithModalFocus(nullptr),
+ mLastWidgetWithModalMouseInputFocus(nullptr),
+ mLastWidgetPressed(nullptr),
+ mModalStack()
+{
+}
+
+void FocusHandler::requestModalFocus(Widget *widget)
{
/* If there is another widget with modal focus, remove its modal focus
* and put it on the modal widget stack.
@@ -39,45 +98,217 @@ void FocusHandler::requestModalFocus(gcn::Widget *widget)
mModalFocusedWidget = nullptr;
}
- gcn::FocusHandler::requestModalFocus(widget);
+ mModalFocusedWidget = widget;
+ if (mFocusedWidget && !mFocusedWidget->isModalFocused())
+ focusNone();
}
-void FocusHandler::releaseModalFocus(gcn::Widget *widget)
+void FocusHandler::releaseModalFocus(Widget *widget)
{
mModalStack.remove(widget);
if (mModalFocusedWidget == widget)
{
- gcn::FocusHandler::releaseModalFocus(widget);
+ if (mModalFocusedWidget == widget)
+ mModalFocusedWidget = nullptr;
/* Check if there were any previously modal widgets that'd still like
* to regain their modal focus.
*/
if (!mModalStack.empty())
{
- gcn::FocusHandler::requestModalFocus(mModalStack.front());
+ requestModalFocus(mModalStack.front());
mModalStack.pop_front();
}
}
}
-void FocusHandler::remove(gcn::Widget *widget)
+void FocusHandler::remove(Widget *widget)
{
releaseModalFocus(widget);
- gcn::FocusHandler::remove(widget);
+ if (isFocused(widget))
+ mFocusedWidget = nullptr;
+
+ for (WidgetIterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++iter)
+ {
+ if ((*iter) == widget)
+ {
+ mWidgets.erase(iter);
+ break;
+ }
+ }
+
+ if (mDraggedWidget == widget)
+ {
+ mDraggedWidget = nullptr;
+ return;
+ }
+
+ if (mLastWidgetWithMouse == widget)
+ {
+ mLastWidgetWithMouse = nullptr;
+ return;
+ }
+
+ if (mLastWidgetWithModalFocus == widget)
+ {
+ mLastWidgetWithModalFocus = nullptr;
+ return;
+ }
+
+ if (mLastWidgetWithModalMouseInputFocus == widget)
+ {
+ mLastWidgetWithModalMouseInputFocus = nullptr;
+ return;
+ }
+
+ if (mLastWidgetPressed == widget)
+ {
+ mLastWidgetPressed = nullptr;
+ return;
+ }
}
void FocusHandler::tabNext()
{
- gcn::FocusHandler::tabNext();
+ if (mFocusedWidget)
+ {
+ if (!mFocusedWidget->isTabOutEnabled())
+ return;
+ }
+
+ if (mWidgets.empty())
+ {
+ mFocusedWidget = nullptr;
+ return;
+ }
+
+ int i;
+ int focusedWidget = -1;
+ const int sz = static_cast<int>(mWidgets.size());
+ for (i = 0; i < sz; ++ i)
+ {
+ if (mWidgets[i] == mFocusedWidget)
+ focusedWidget = i;
+ }
+ const int focused = focusedWidget;
+ bool done = false;
+
+ // i is a counter that ensures that the following loop
+ // won't get stuck in an infinite loop
+ i = sz;
+ do
+ {
+ ++ focusedWidget;
+
+ if (i == 0)
+ {
+ focusedWidget = -1;
+ break;
+ }
+
+ -- i;
+
+ if (focusedWidget >= sz)
+ focusedWidget = 0;
+
+ if (focusedWidget == focused)
+ return;
+
+ const Widget *const widget = mWidgets.at(focusedWidget);
+ if (widget->isFocusable() && widget->isTabInEnabled() &&
+ (!mModalFocusedWidget || widget->isModalFocused()))
+ {
+ done = true;
+ }
+ }
+ while (!done);
+
+ if (focusedWidget >= 0)
+ {
+ mFocusedWidget = mWidgets.at(focusedWidget);
+ Event focusEvent(mFocusedWidget);
+ distributeFocusGainedEvent(focusEvent);
+ }
+
+ if (focused >= 0)
+ {
+ Event focusEvent(mWidgets.at(focused));
+ distributeFocusLostEvent(focusEvent);
+ }
checkForWindow();
}
void FocusHandler::tabPrevious()
{
- gcn::FocusHandler::tabPrevious();
+ if (mFocusedWidget)
+ {
+ if (!mFocusedWidget->isTabOutEnabled())
+ return;
+ }
+
+ if (mWidgets.empty())
+ {
+ mFocusedWidget = nullptr;
+ return;
+ }
+
+ int i;
+ int focusedWidget = -1;
+ const int sz = static_cast<int>(mWidgets.size());
+ for (i = 0; i < sz; ++ i)
+ {
+ if (mWidgets[i] == mFocusedWidget)
+ focusedWidget = i;
+ }
+ const int focused = focusedWidget;
+ bool done = false;
+
+ // i is a counter that ensures that the following loop
+ // won't get stuck in an infinite loop
+ i = sz;
+ do
+ {
+ -- focusedWidget;
+
+ if (i == 0)
+ {
+ focusedWidget = -1;
+ break;
+ }
+
+ -- i;
+
+ if (focusedWidget <= 0)
+ focusedWidget = sz - 1;
+
+ if (focusedWidget == focused)
+ return;
+
+ const Widget *const widget = mWidgets.at(focusedWidget);
+ if (widget->isFocusable() && widget->isTabInEnabled() &&
+ (!mModalFocusedWidget || widget->isModalFocused()))
+ {
+ done = true;
+ }
+ }
+ while (!done);
+
+ if (focusedWidget >= 0)
+ {
+ mFocusedWidget = mWidgets.at(focusedWidget);
+ Event focusEvent(mFocusedWidget);
+ distributeFocusGainedEvent(focusEvent);
+ }
+
+ if (focused >= 0)
+ {
+ Event focusEvent(mWidgets.at(focused));
+ distributeFocusLostEvent(focusEvent);
+ }
checkForWindow();
}
@@ -86,7 +317,7 @@ void FocusHandler::checkForWindow() const
{
if (mFocusedWidget)
{
- gcn::Widget *widget = mFocusedWidget->getParent();
+ Widget *widget = mFocusedWidget->getParent();
while (widget)
{
@@ -103,9 +334,284 @@ void FocusHandler::checkForWindow() const
}
}
-void FocusHandler::distributeFocusGainedEvent(const gcn::Event &focusEvent)
+void FocusHandler::distributeFocusGainedEvent(const Event &focusEvent)
{
if (gui)
gui->distributeGlobalFocusGainedEvent(focusEvent);
- gcn::FocusHandler::distributeFocusGainedEvent(focusEvent);
+
+ Widget *const sourceWidget = focusEvent.getSource();
+
+ std::list<FocusListener*> focusListeners
+ = sourceWidget->_getFocusListeners();
+
+ // Send the event to all focus listeners of the widget.
+ for (std::list<FocusListener*>::const_iterator
+ it = focusListeners.begin();
+ it != focusListeners.end();
+ ++ it)
+ {
+ (*it)->focusGained(focusEvent);
+ }
+}
+
+void FocusHandler::requestFocus(Widget* widget)
+{
+ if (!widget || widget == mFocusedWidget)
+ return;
+
+ int toBeFocusedIndex = -1;
+ for (unsigned int i = 0, sz = static_cast<unsigned int>(
+ mWidgets.size()); i < sz; ++i)
+ {
+ if (mWidgets[i] == widget)
+ {
+ toBeFocusedIndex = i;
+ break;
+ }
+ }
+
+ if (toBeFocusedIndex < 0)
+ return;
+
+ Widget *const oldFocused = mFocusedWidget;
+
+ if (oldFocused != widget)
+ {
+ mFocusedWidget = mWidgets.at(toBeFocusedIndex);
+
+ if (oldFocused)
+ {
+ Event focusEvent(oldFocused);
+ distributeFocusLostEvent(focusEvent);
+ }
+
+ Event focusEvent(mWidgets.at(toBeFocusedIndex));
+ distributeFocusGainedEvent(focusEvent);
+ }
+}
+
+void FocusHandler::requestModalMouseInputFocus(Widget* widget)
+{
+ if (mModalMouseInputFocusedWidget
+ && mModalMouseInputFocusedWidget != widget)
+ {
+ return;
+ }
+
+ mModalMouseInputFocusedWidget = widget;
+}
+
+void FocusHandler::releaseModalMouseInputFocus(Widget* widget)
+{
+ if (mModalMouseInputFocusedWidget == widget)
+ mModalMouseInputFocusedWidget = nullptr;
+}
+
+Widget* FocusHandler::getFocused() const
+{
+ return mFocusedWidget;
+}
+
+Widget* FocusHandler::getModalFocused() const
+{
+ return mModalFocusedWidget;
+}
+
+Widget* FocusHandler::getModalMouseInputFocused() const
+{
+ return mModalMouseInputFocusedWidget;
+}
+
+void FocusHandler::focusNext()
+{
+ int i;
+ int focusedWidget = -1;
+ const int sz = static_cast<int>(mWidgets.size());
+ for (i = 0; i < sz; ++i)
+ {
+ if (mWidgets[i] == mFocusedWidget)
+ focusedWidget = i;
+ }
+ const int focused = focusedWidget;
+
+ // i is a counter that ensures that the following loop
+ // won't get stuck in an infinite loop
+ i = sz;
+ do
+ {
+ ++ focusedWidget;
+
+ if (i == 0)
+ {
+ focusedWidget = -1;
+ break;
+ }
+
+ -- i;
+
+ if (focusedWidget >= sz)
+ focusedWidget = 0;
+
+ if (focusedWidget == focused)
+ return;
+ }
+ while (!mWidgets.at(focusedWidget)->isFocusable());
+
+ if (focusedWidget >= 0)
+ {
+ mFocusedWidget = mWidgets.at(focusedWidget);
+
+ Event focusEvent(mFocusedWidget);
+ distributeFocusGainedEvent(focusEvent);
+ }
+
+ if (focused >= 0)
+ {
+ Event focusEvent(mWidgets.at(focused));
+ distributeFocusLostEvent(focusEvent);
+ }
+}
+
+void FocusHandler::focusPrevious()
+{
+ if (mWidgets.empty())
+ {
+ mFocusedWidget = nullptr;
+ return;
+ }
+
+ int i;
+ int focusedWidget = -1;
+ const int sz = static_cast<int>(mWidgets.size());
+ for (i = 0; i < sz; ++ i)
+ {
+ if (mWidgets[i] == mFocusedWidget)
+ focusedWidget = i;
+ }
+ const int focused = focusedWidget;
+
+ // i is a counter that ensures that the following loop
+ // won't get stuck in an infinite loop
+ i = sz;
+ do
+ {
+ -- focusedWidget;
+
+ if (i == 0)
+ {
+ focusedWidget = -1;
+ break;
+ }
+
+ -- i;
+
+ if (focusedWidget <= 0)
+ focusedWidget = sz - 1;
+
+ if (focusedWidget == focused)
+ return;
+ }
+ while (!mWidgets.at(focusedWidget)->isFocusable());
+
+ if (focusedWidget >= 0)
+ {
+ mFocusedWidget = mWidgets.at(focusedWidget);
+ Event focusEvent(mFocusedWidget);
+ distributeFocusGainedEvent(focusEvent);
+ }
+
+ if (focused >= 0)
+ {
+ Event focusEvent(mWidgets.at(focused));
+ distributeFocusLostEvent(focusEvent);
+ }
+}
+
+bool FocusHandler::isFocused(const Widget* widget) const
+{
+ return mFocusedWidget == widget;
+}
+
+void FocusHandler::add(Widget* widget)
+{
+ mWidgets.push_back(widget);
+}
+
+void FocusHandler::focusNone()
+{
+ if (mFocusedWidget)
+ {
+ Widget *const focused = mFocusedWidget;
+ mFocusedWidget = nullptr;
+
+ Event focusEvent(focused);
+ distributeFocusLostEvent(focusEvent);
+ }
+}
+
+void FocusHandler::distributeFocusLostEvent(const Event& focusEvent)
+{
+ Widget *const sourceWidget = focusEvent.getSource();
+
+ std::list<FocusListener*> focusListeners
+ = sourceWidget->_getFocusListeners();
+
+ // Send the event to all focus listeners of the widget.
+ for (std::list<FocusListener*>::const_iterator
+ it = focusListeners.begin();
+ it != focusListeners.end();
+ ++ it)
+ {
+ (*it)->focusLost(focusEvent);
+ }
+}
+
+Widget* FocusHandler::getDraggedWidget()
+{
+ return mDraggedWidget;
+}
+
+void FocusHandler::setDraggedWidget(Widget* draggedWidget)
+{
+ mDraggedWidget = draggedWidget;
+}
+
+Widget* FocusHandler::getLastWidgetWithMouse()
+{
+ return mLastWidgetWithMouse;
+}
+
+void FocusHandler::setLastWidgetWithMouse(Widget* lastWidgetWithMouse)
+{
+ mLastWidgetWithMouse = lastWidgetWithMouse;
+}
+
+Widget* FocusHandler::getLastWidgetWithModalFocus()
+{
+ return mLastWidgetWithModalFocus;
+}
+
+void FocusHandler::setLastWidgetWithModalFocus(Widget* widget)
+{
+ mLastWidgetWithModalFocus = widget;
+}
+
+Widget* FocusHandler::getLastWidgetWithModalMouseInputFocus()
+{
+ return mLastWidgetWithModalMouseInputFocus;
+}
+
+void FocusHandler::setLastWidgetWithModalMouseInputFocus(Widget* widget)
+{
+ mLastWidgetWithModalMouseInputFocus = widget;
+}
+
+Widget* FocusHandler::getLastWidgetPressed()
+{
+ return mLastWidgetPressed;
+}
+
+void FocusHandler::setLastWidgetPressed(Widget* lastWidgetPressed)
+{
+ mLastWidgetPressed = lastWidgetPressed;
}
diff --git a/src/gui/focushandler.h b/src/gui/focushandler.h
index e32b9afa1..f12819e75 100644
--- a/src/gui/focushandler.h
+++ b/src/gui/focushandler.h
@@ -20,59 +20,307 @@
* 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_FOCUSHANDLER_H
#define GUI_FOCUSHANDLER_H
-#include <guichan/focushandler.hpp>
+#include "gui/focushandler.h"
#include <list>
+#include <vector>
#include "localconsts.h"
+class Event;
+class Widget;
+
/**
* The focus handler. This focus handler does exactly the same as the Guichan
* focus handler, but keeps a stack of modal widgets to be able to handle
* multiple modal focus requests.
*/
-class FocusHandler final : public gcn::FocusHandler
+class FocusHandler final
{
public:
- FocusHandler() :
- mModalStack()
- { }
+ FocusHandler();
A_DELETE_COPY(FocusHandler)
/**
- * Sets modal focus to a widget. When there is already a modal widget
- * then that widget loses modal focus and will regain it after this
- * widget releases his modal focus.
- */
- void requestModalFocus(gcn::Widget *widget) override final;
+ * Requests focus for a widget. Focus will only be granted to a widget
+ * if it's focusable and if no other widget has modal focus.
+ * If a widget receives focus a focus event will be sent to the
+ * focus listeners of the widget.
+ *
+ * @param widget The widget to request focus for.
+ * @see isFocused, Widget::requestFocus
+ */
+ void requestFocus(Widget* widget);
/**
- * Releases modal focus of a widget. When this widget had modal focus
- * and there are other widgets that had also requested modal focus,
- * then modal focus will be transfered to the last of those.
- */
- void releaseModalFocus(gcn::Widget *widget) override final;
+ * Requests modal focus for a widget. Focus will only be granted
+ * to a widget if it's focusable and if no other widget has modal
+ * focus.
+ *
+ * @param widget The widget to request modal focus for.
+ * @throws Exception when another widget already has modal focus.
+ * @see releaseModalFocus, Widget::requestModalFocus
+ */
+ void requestModalFocus(Widget* widget);
/**
- * Removes a widget from the focus handler. Also makes sure no dangling
- * pointers remain in modal focus stack.
- */
- void remove(gcn::Widget *widget) override final;
+ * Requests modal mouse input focus for a widget. Focus will only
+ * be granted to a widget if it's focusable and if no other widget
+ * has modal mouse input focus.
+ *
+ * Modal mouse input focus means no other widget then the widget with
+ * modal mouse input focus will receive mouse input. The widget with
+ * modal mouse input focus will also receive mouse input no matter what
+ * the mouse input is or where the mouse input occurs.
+ *
+ * @param widget The widget to focus for modal mouse input focus.
+ * @throws Exception when another widget already has modal mouse input
+ * focus.
+ * @see releaseModalMouseInputFocus, Widget::requestModalMouseInputFocus
+ */
+ void requestModalMouseInputFocus(Widget* widget);
/**
- * Overloaded to allow windows to move to the top when one of their
- * widgets is tabbed to when tabbing through focusable elements.
- */
- void tabNext() override final;
+ * Releases modal focus if the widget has modal focus.
+ * If the widget doesn't have modal focus no relase will occur.
+ *
+ * @param widget The widget to release modal focus for.
+ * @see reuqestModalFocus, Widget::releaseModalFocus
+ */
+ void releaseModalFocus(Widget* widget);
+
+ /**
+ * Releases modal mouse input focus if the widget has modal mouse input
+ * focus. If the widget doesn't have modal mouse input focus no relase
+ * will occur.
+ *
+ * @param widget the widget to release modal mouse input focus for.
+ * @see requestModalMouseInputFocus, Widget::releaseModalMouseInputFocus
+ */
+ void releaseModalMouseInputFocus(Widget* widget);
+
+ /**
+ * Checks if a widget is focused.
+ *
+ * @param widget The widget to check.
+ * @return True if the widget is focused, false otherwise.
+ * @see Widget::isFocused
+ */
+ bool isFocused(const Widget* widget) const;
+
+ /**
+ * Gets the widget with focus.
+ *
+ * @return The widget with focus. NULL if no widget has focus.
+ */
+ Widget* getFocused() const A_WARN_UNUSED;
+
+ /**
+ * Gets the widget with modal focus.
+ *
+ * @return The widget with modal focus. NULL if no widget has
+ * modal focus.
+ */
+ Widget* getModalFocused() const A_WARN_UNUSED;
+
+ /**
+ * Gets the widget with modal mouse input focus.
+ *
+ * @return The widget with modal mouse input focus. NULL if
+ * no widget has modal mouse input focus.
+ */
+ Widget* getModalMouseInputFocused() const A_WARN_UNUSED;
+
+ /**
+ * Focuses the next widget added to a conainer.
+ * If no widget has focus the first widget gets focus. The order
+ * in which the widgets are focused is determined by the order
+ * they were added to a container.
+ *
+ * @see focusPrevious
+ */
+ void focusNext();
+
+ /**
+ * Focuses the previous widget added to a contaienr.
+ * If no widget has focus the first widget gets focus. The order
+ * in which the widgets are focused is determined by the order
+ * they were added to a container.
+ *
+ * @see focusNext
+ */
+ void focusPrevious();
+
+ /**
+ * Adds a widget to by handles by the focus handler.
+ *
+ * @param widget The widget to add.
+ * @see remove
+ */
+ void add(Widget* widget);
+
+ /**
+ * Removes a widget from the focus handler.
+ *
+ * @param widget The widget to remove.
+ * @see add
+ */
+ void remove(Widget* widget);
+
+ /**
+ * Focuses nothing. A focus event will also be sent to the
+ * focused widget's focus listeners if a widget has focus.
+ */
+ void focusNone();
+
+ /**
+ * Focuses the next widget which allows tabbing in unless
+ * the current focused Widget disallows tabbing out.
+ *
+ * @see tabPrevious
+ */
+ void tabNext();
+
+ /**
+ * Focuses the previous widget which allows tabbing in unless
+ * current focused widget disallows tabbing out.
+ *
+ * @see tabNext
+ */
+ void tabPrevious();
+
+ /**
+ * Gets the widget being dragged. Used by the Gui class to
+ * keep track of the dragged widget.
+ *
+ * @return the widget being dragged.
+ * @see setDraggedWidget
+ */
+ Widget* getDraggedWidget() A_WARN_UNUSED;
+
+ /**
+ * Sets the widget being dragged. Used by the Gui class to
+ * keep track of the dragged widget.
+ *
+ * @param draggedWidget The widget being dragged.
+ * @see getDraggedWidget
+ */
+ void setDraggedWidget(Widget* draggedWidget);
+
+ /**
+ * Gets the last widget with the mouse. Used by the Gui class
+ * to keep track the last widget with the mouse.
+ *
+ * @return The last widget with the mouse.
+ * @see setLastWidgetWithMouse
+ */
+ Widget* getLastWidgetWithMouse() A_WARN_UNUSED;
+
+ /**
+ * Sets the last widget with the mouse. Used by the Gui class
+ * to keep track the last widget with the mouse.
+ *
+ * @param lastWidgetWithMouse The last widget with the mouse.
+ * @see getLastWidgetWithMouse
+ */
+ void setLastWidgetWithMouse(Widget* lastWidgetWithMouse);
+
+ /**
+ * Gets the last widget with modal focus.
+ *
+ * @return The last widget with modal focus.
+ * @see setLastWidgetWithModalFocus
+ */
+ Widget* getLastWidgetWithModalFocus() A_WARN_UNUSED;
- void tabPrevious() override final;
+ /**
+ * Sets the last widget with modal focus.
+ *
+ * @param widget The last widget with modal focus.
+ * @see getLastWidgetWithModalFocus
+ */
+ void setLastWidgetWithModalFocus(Widget* widget);
+
+ /**
+ * Gets the last widget with modal mouse input focus.
+ *
+ * @return The last widget with modal mouse input focus.
+ * @see setLastWidgetWithModalMouseInputFocus
+ */
+ Widget* getLastWidgetWithModalMouseInputFocus() A_WARN_UNUSED;
+
+ /**
+ * Sets the last widget with modal mouse input focus.
+ *
+ * @param widget The last widget with modal mouse input focus.
+ * @see getLastWidgetWithModalMouseInputFocus
+ */
+ void setLastWidgetWithModalMouseInputFocus(Widget* widget);
+
+ /**
+ * Gets the last widget pressed. Used by the Gui class to keep track
+ * of pressed widgets.
+ *
+ * @return The last widget pressed.
+ * @see setLastWidgetPressed
+ */
+ Widget* getLastWidgetPressed() A_WARN_UNUSED;
- void distributeFocusGainedEvent(const gcn::Event &focusEvent)
- override final;
+ /**
+ * Sets the last widget pressed. Used by the Gui class to keep track
+ * of pressed widgets.
+ *
+ * @param lastWidgetPressed The last widget pressed.
+ * @see getLastWidgetPressed
+ */
+ void setLastWidgetPressed(Widget* lastWidgetPressed);
private:
/**
@@ -82,9 +330,84 @@ class FocusHandler final : public gcn::FocusHandler
void checkForWindow() const;
/**
+ * Distributes a focus lost event.
+ *
+ * @param focusEvent the event to distribute.
+ * @since 0.7.0
+ */
+ static void distributeFocusLostEvent(const Event& focusEvent);
+
+ /**
+ * Distributes a focus gained event.
+ *
+ * @param focusEvent the event to distribute.
+ * @since 0.7.0
+ */
+ static void distributeFocusGainedEvent(const Event& focusEvent);
+
+ /**
+ * Typedef.
+ */
+ typedef std::vector<Widget*> WidgetVector;
+
+ /**
+ * Typedef.
+ */
+ typedef WidgetVector::iterator WidgetIterator;
+
+ /**
+ * Holds the widgets currently being handled by the
+ * focus handler.
+ */
+ WidgetVector mWidgets;
+
+ /**
+ * Holds the focused widget. NULL if no widget has focus.
+ */
+ Widget* mFocusedWidget;
+
+ /**
+ * Holds the modal focused widget. NULL if no widget has
+ * modal focused.
+ */
+ Widget* mModalFocusedWidget;
+
+ /**
+ * Holds the modal mouse input focused widget. NULL if no widget
+ * is being dragged.
+ */
+ Widget* mModalMouseInputFocusedWidget;
+
+ /**
+ * Holds the dragged widget. NULL if no widget is
+ * being dragged.
+ */
+ Widget* mDraggedWidget;
+
+ /**
+ * Holds the last widget with the mouse.
+ */
+ Widget* mLastWidgetWithMouse;
+
+ /**
+ * Holds the last widget with modal focus.
+ */
+ Widget* mLastWidgetWithModalFocus;
+
+ /**
+ * Holds the last widget with modal mouse input focus.
+ */
+ Widget* mLastWidgetWithModalMouseInputFocus;
+
+ /**
+ * Holds the last widget pressed.
+ */
+ Widget* mLastWidgetPressed;
+
+ /**
* Stack of widgets that have requested modal forcus.
*/
- std::list<gcn::Widget*> mModalStack;
+ std::list<Widget*> mModalStack;
};
#endif // GUI_FOCUSHANDLER_H
diff --git a/src/gui/sdlfont.cpp b/src/gui/font.cpp
index f97970a26..8c022f99d 100644
--- a/src/gui/sdlfont.cpp
+++ b/src/gui/font.cpp
@@ -21,7 +21,50 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "gui/sdlfont.h"
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/font.h"
#include "logger.h"
#include "main.h"
@@ -34,13 +77,10 @@
#include "resources/surfaceimagehelper.h"
#include "utils/paths.h"
-#include "utils/physfsrwops.h"
#include "utils/sdlcheckutils.h"
#include "utils/stringutils.h"
#include "utils/timer.h"
-#include <guichan/exception.hpp>
-
#include "debug.h"
const unsigned int CACHE_SIZE = 256;
@@ -50,7 +90,7 @@ const unsigned int CACHE_SIZE_SMALL3 = 170;
const unsigned int CLEAN_TIME = 7;
const int OUTLINE_SIZE = 1;
-bool SDLFont::mSoftMode(false);
+bool Font::mSoftMode(false);
char *strBuf = nullptr;
@@ -59,8 +99,8 @@ int sdlTextChunkCnt = 0;
#endif
SDLTextChunkSmall::SDLTextChunkSmall(const std::string &text0,
- const gcn::Color &color0,
- const gcn::Color &color1) :
+ const Color &color0,
+ const Color &color1) :
text(text0),
color(color0),
color2(color1)
@@ -85,7 +125,7 @@ bool SDLTextChunkSmall::operator<(const SDLTextChunkSmall &chunk) const
if (chunk.text != text)
return chunk.text > text;
- const gcn::Color &c = chunk.color;
+ const Color &c = chunk.color;
if (c.r != color.r)
return c.r > color.r;
if (c.g != color.g)
@@ -93,7 +133,7 @@ bool SDLTextChunkSmall::operator<(const SDLTextChunkSmall &chunk) const
if (c.b != color.b)
return c.b > color.b;
- const gcn::Color &c2 = chunk.color2;
+ const Color &c2 = chunk.color2;
if (c2.r != color2.r)
return c2.r > color2.r;
if (c2.g != color2.g)
@@ -101,14 +141,14 @@ bool SDLTextChunkSmall::operator<(const SDLTextChunkSmall &chunk) const
if (c2.b != color2.b)
return c2.b > color2.b;
- if (c.a != color.a && SDLFont::mSoftMode)
+ if (c.a != color.a && Font::mSoftMode)
return c.a > color.a;
return false;
}
-SDLTextChunk::SDLTextChunk(const std::string &text0, const gcn::Color &color0,
- const gcn::Color &color1) :
+SDLTextChunk::SDLTextChunk(const std::string &text0, const Color &color0,
+ const Color &color1) :
img(nullptr),
text(text0),
color(color0),
@@ -337,9 +377,9 @@ void TextChunkList::clear()
static int fontCounter;
-SDLFont::SDLFont(std::string filename,
- const int size,
- const int style) :
+Font::Font(std::string filename,
+ const int size,
+ const int style) :
mFont(nullptr),
mCreateCounter(0),
mDeleteCounter(0),
@@ -350,7 +390,7 @@ SDLFont::SDLFont(std::string filename,
mSoftMode = imageHelper->useOpenGL() == RENDER_SOFTWARE;
if (TTF_Init() == -1)
{
- throw GCN_EXCEPTION("Unable to initialize SDL_ttf: " +
+ logger->error("Unable to initialize SDL_ttf: " +
std::string(TTF_GetError()));
}
}
@@ -373,15 +413,15 @@ SDLFont::SDLFont(std::string filename,
mFont = openFont(fixDirSeparators(backFile).c_str(), size);
if (!mFont)
{
- throw GCN_EXCEPTION("SDLSDLFont::SDLSDLFont: " +
- std::string(TTF_GetError()));
+ logger->error("Font::Font: " +
+ std::string(TTF_GetError()));
}
}
TTF_SetFontStyle(mFont, style);
}
-SDLFont::~SDLFont()
+Font::~Font()
{
TTF_CloseFont(mFont);
mFont = nullptr;
@@ -395,7 +435,7 @@ SDLFont::~SDLFont()
}
}
-TTF_Font *SDLFont::openFont(const char *const name, const int size)
+TTF_Font *Font::openFont(const char *const name, const int size)
{
// disabled for now because some systems like gentoo cant use it
// #ifdef USE_SDL2
@@ -409,9 +449,9 @@ TTF_Font *SDLFont::openFont(const char *const name, const int size)
// #endif
}
-void SDLFont::loadFont(std::string filename,
- const int size,
- const int style)
+void Font::loadFont(std::string filename,
+ const int size,
+ const int style)
{
if (fontCounter == 0 && TTF_Init() == -1)
{
@@ -425,7 +465,7 @@ void SDLFont::loadFont(std::string filename,
if (!font)
{
- logger->log("SDLSDLFont::SDLSDLFont: " +
+ logger->log("Font::Font: " +
std::string(TTF_GetError()));
return;
}
@@ -438,20 +478,20 @@ void SDLFont::loadFont(std::string filename,
clear();
}
-void SDLFont::clear()
+void Font::clear()
{
for (size_t f = 0; f < CACHES_NUMBER; f ++)
mCache[f].clear();
}
-void SDLFont::drawString(gcn::Graphics *const graphics,
- const std::string &text,
- const int x, const int y)
+void Font::drawString(Graphics *const graphics,
+ const std::string &text,
+ const int x, const int y)
{
- BLOCK_START("SDLFont::drawString")
+ BLOCK_START("Font::drawString")
if (text.empty())
{
- BLOCK_END("SDLFont::drawString")
+ BLOCK_END("Font::drawString")
return;
}
@@ -459,8 +499,8 @@ void SDLFont::drawString(gcn::Graphics *const graphics,
if (!g)
return;
- gcn::Color col = g->getColor();
- const gcn::Color &col2 = g->getColor2();
+ Color col = g->getColor();
+ const Color &col2 = g->getColor2();
const float alpha = static_cast<float>(col.a) / 255.0F;
/* The alpha value is ignored at string generation so avoid caching the
@@ -482,7 +522,7 @@ void SDLFont::drawString(gcn::Graphics *const graphics,
if (image)
{
image->setAlpha(alpha);
- g->drawImage2(image, x, y);
+ g->drawImage(image, x, y);
}
}
else
@@ -504,14 +544,14 @@ void SDLFont::drawString(gcn::Graphics *const graphics,
const Image *const image = chunk2->img;
if (image)
- g->drawImage2(image, x, y);
+ g->drawImage(image, x, y);
}
- BLOCK_END("SDLFont::drawString")
+ BLOCK_END("Font::drawString")
}
-void SDLFont::slowLogic(const int rnd)
+void Font::slowLogic(const int rnd)
{
- BLOCK_START("SDLFont::slowLogic")
+ BLOCK_START("Font::slowLogic")
if (!mCleanTime)
{
mCleanTime = cur_time + CLEAN_TIME + rnd;
@@ -521,10 +561,10 @@ void SDLFont::slowLogic(const int rnd)
doClean();
mCleanTime = cur_time + CLEAN_TIME + rnd;
}
- BLOCK_END("SDLFont::slowLogic")
+ BLOCK_END("Font::slowLogic")
}
-int SDLFont::getWidth(const std::string &text) const
+int Font::getWidth(const std::string &text) const
{
if (text.empty())
return 0;
@@ -552,12 +592,12 @@ int SDLFont::getWidth(const std::string &text) const
return w;
}
-int SDLFont::getHeight() const
+int Font::getHeight() const
{
return TTF_FontHeight(mFont);
}
-void SDLFont::doClean()
+void Font::doClean()
{
for (unsigned int f = 0; f < CACHES_NUMBER; f ++)
{
@@ -599,7 +639,19 @@ void SDLFont::doClean()
}
}
-const TextChunkList *SDLFont::getCache() const
+int Font::getStringIndexAt(const std::string& text, const int x) const
+{
+ const size_t sz = text.size();
+ for (size_t i = 0; i < sz; ++i)
+ {
+ if (getWidth(text.substr(0, i)) > x)
+ return i;
+ }
+
+ return static_cast<int>(sz);
+}
+
+const TextChunkList *Font::getCache() const
{
return mCache;
}
diff --git a/src/gui/sdlfont.h b/src/gui/font.h
index b2638f835..12ba473d8 100644
--- a/src/gui/sdlfont.h
+++ b/src/gui/font.h
@@ -21,11 +21,53 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef GUI_SDLFONT_H
-#define GUI_SDLFONT_H
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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 <guichan/color.hpp>
-#include <guichan/font.hpp>
+#ifndef GUI_FONT_H
+#define GUI_FONT_H
+
+#include "gui/color.h"
#include <SDL_ttf.h>
@@ -34,6 +76,8 @@
#include "localconsts.h"
+class Color;
+class Graphics;
class Image;
const unsigned int CACHES_NUMBER = 256;
@@ -41,8 +85,8 @@ const unsigned int CACHES_NUMBER = 256;
class SDLTextChunkSmall
{
public:
- SDLTextChunkSmall(const std::string &text0, const gcn::Color &color0,
- const gcn::Color &color1);
+ SDLTextChunkSmall(const std::string &text0, const Color &color0,
+ const Color &color1);
SDLTextChunkSmall(const SDLTextChunkSmall &old);
@@ -50,15 +94,15 @@ class SDLTextChunkSmall
bool operator<(const SDLTextChunkSmall &chunk) const;
std::string text;
- gcn::Color color;
- gcn::Color color2;
+ Color color;
+ Color color2;
};
class SDLTextChunk final
{
public:
- SDLTextChunk(const std::string &text0, const gcn::Color &color0,
- const gcn::Color &color1);
+ SDLTextChunk(const std::string &text0, const Color &color0,
+ const Color &color1);
A_DELETE_COPY(SDLTextChunk)
@@ -70,8 +114,8 @@ class SDLTextChunk final
Image *img;
std::string text;
- gcn::Color color;
- gcn::Color color2;
+ Color color;
+ Color color2;
SDLTextChunk *prev;
SDLTextChunk *next;
};
@@ -106,34 +150,33 @@ class TextChunkList final
*
* <b>NOTE:</b> This class initializes SDL_ttf as necessary.
*/
-class SDLFont final : public gcn::Font
+class Font final
{
public:
- SDLFont(std::string filename,
- const int size,
- const int style = 0);
+ Font(std::string filename,
+ const int size,
+ const int style = 0);
- A_DELETE_COPY(SDLFont)
+ A_DELETE_COPY(Font)
- ~SDLFont();
+ ~Font();
void loadFont(std::string filename,
const int size,
const int style = 0);
- int getWidth(const std::string &text) const override
- final A_WARN_UNUSED;
+ int getWidth(const std::string &text) const A_WARN_UNUSED;
- int getHeight() const override final A_WARN_UNUSED;
+ int getHeight() const A_WARN_UNUSED;
const TextChunkList *getCache() const A_WARN_UNUSED;
/**
* @see Font::drawString
*/
- void drawString(gcn::Graphics *const graphics,
+ void drawString(Graphics *const graphics,
const std::string &text,
- const int x, const int y) override final;
+ const int x, const int y);
void clear();
@@ -147,6 +190,9 @@ class SDLFont final : public gcn::Font
int getDeleteCounter() const A_WARN_UNUSED
{ return mDeleteCounter; }
+ int getStringIndexAt(const std::string& text,
+ const int x) const A_WARN_UNUSED;
+
static bool mSoftMode;
private:
@@ -165,4 +211,4 @@ class SDLFont final : public gcn::Font
extern int sdlTextChunkCnt;
#endif
-#endif // GUI_SDLFONT_H
+#endif // GUI_FONT_H
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 126fc9a3b..5914e43d9 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -20,18 +20,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "mouseinput.h"
-
#include "gui/gui.h"
#include "gui/focushandler.h"
+#include "gui/font.h"
#include "gui/palette.h"
-#include "gui/sdlfont.h"
#include "gui/sdlinput.h"
#include "gui/theme.h"
#include "gui/viewport.h"
-#include "gui/widgets/mouseevent.h"
+#include "events/mouseevent.h"
+
#include "gui/widgets/window.h"
#include "client.h"
@@ -39,9 +38,13 @@
#include "dragdrop.h"
#include "touchmanager.h"
+#include "events/keyevent.h"
+
+#include "listeners/focuslistener.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
#include "input/keyinput.h"
+#include "input/mouseinput.h"
#include "resources/cursor.h"
#include "resources/image.h"
@@ -51,8 +54,6 @@
#include "utils/langs.h"
#include "utils/timer.h"
-#include <guichan/exception.hpp>
-
#include "debug.h"
// Guichan stuff
@@ -60,7 +61,7 @@ Gui *gui = nullptr;
SDLInput *guiInput = nullptr;
// Bolded font
-SDLFont *boldFont = nullptr;
+Font *boldFont = nullptr;
class GuiConfigListener final : public ConfigListener
{
@@ -160,16 +161,7 @@ void Gui::postInit(Graphics *const graphics)
if (fontFile.empty())
fontFile = branding.getStringValue("font");
- try
- {
- mGuiFont = new SDLFont(fontFile, fontSize);
- }
- catch (const gcn::Exception &e)
- {
- logger->error(std::string("Unable to load '").append(fontFile)
- .append("': ").append(e.getMessage()));
- }
-
+ mGuiFont = new Font(fontFile, fontSize);
// Set particle font
fontFile = config.getValue("particleFont", "");
@@ -188,65 +180,28 @@ void Gui::postInit(Graphics *const graphics)
if (fontFile.empty())
fontFile = branding.getStringValue("particleFont");
- try
- {
- mInfoParticleFont = new SDLFont(
- fontFile, fontSize, TTF_STYLE_BOLD);
- }
- catch (const gcn::Exception &e)
- {
- logger->error(std::string("Unable to load '").append(fontFile)
- .append("': ").append(e.getMessage()));
- }
-
+ mInfoParticleFont = new Font(fontFile, fontSize, TTF_STYLE_BOLD);
// Set bold font
fontFile = config.getValue("boldFont", "");
if (fontFile.empty())
fontFile = branding.getStringValue("boldFont");
- try
- {
- boldFont = new SDLFont(fontFile, fontSize);
- }
- catch (const gcn::Exception &e)
- {
- logger->error(std::string("Unable to load '").append(fontFile)
- .append("': ").append(e.getMessage()));
- }
-
+ boldFont = new Font(fontFile, fontSize);
// Set help font
fontFile = config.getValue("helpFont", "");
if (fontFile.empty())
fontFile = branding.getStringValue("helpFont");
- try
- {
- mHelpFont = new SDLFont(fontFile, fontSize);
- }
- catch (const gcn::Exception &e)
- {
- logger->error(std::string("Unable to load '").append(fontFile)
- .append("': ").append(e.getMessage()));
- }
-
+ mHelpFont = new Font(fontFile, fontSize);
// Set secure font
fontFile = config.getValue("secureFont", "");
if (fontFile.empty())
fontFile = branding.getStringValue("secureFont");
- try
- {
- mSecureFont = new SDLFont(fontFile, fontSize);
- }
- catch (const gcn::Exception &e)
- {
- logger->error(std::string("Unable to load '").append(fontFile)
- .append("': ").append(e.getMessage()));
- }
-
+ mSecureFont = new Font(fontFile, fontSize);
// Set npc font
const int npcFontSize = config.getIntValue("npcfontSize");
@@ -266,17 +221,9 @@ void Gui::postInit(Graphics *const graphics)
if (fontFile.empty())
fontFile = branding.getStringValue("npcFont");
- try
- {
- mNpcFont = new SDLFont(fontFile, npcFontSize);
- }
- catch (const gcn::Exception &e)
- {
- logger->error(std::string("Unable to load '").append(fontFile)
- .append("': ").append(e.getMessage()));
- }
+ mNpcFont = new Font(fontFile, npcFontSize);
- gcn::Widget::setGlobalFont(mGuiFont);
+ Widget::setGlobalFont(mGuiFont);
// Initialize mouse cursor and listen for changes to the option
setUseCustomCursor(config.getBoolValue("customcursor"));
@@ -473,7 +420,7 @@ bool Gui::handleKeyInput2()
// change focus.
if (!keyEventConsumed && mTabbing && keyInput.getActionId()
== static_cast<int>(Input::KEY_GUI_TAB)
- && keyInput.getType() == gcn::KeyInput::PRESSED)
+ && keyInput.getType() == KeyInput::PRESSED)
{
if (keyInput.isShiftPressed())
mFocusHandler->tabPrevious();
@@ -499,13 +446,12 @@ void Gui::draw()
if ((client->getMouseFocused() || button & SDL_BUTTON(1))
&& mMouseCursors && mCustomCursor && mMouseCursorAlpha > 0.0F)
{
- Graphics *g2 = static_cast<Graphics*>(mGraphics);
const Image *const image = dragDrop.getItemImage();
if (image)
{
const int posX = mouseX - (image->mBounds.w / 2);
const int posY = mouseY - (image->mBounds.h / 2);
- g2->drawImage2(image, posX, posY);
+ mGraphics->drawImage(image, posX, posY);
}
if (mGuiFont)
{
@@ -514,8 +460,8 @@ void Gui::draw()
{
const int posX = mouseX - mGuiFont->getWidth(str) / 2;
const int posY = mouseY + (image ? image->mBounds.h / 2 : 0);
- g2->setColorAll(mForegroundColor, mForegroundColor2);
- mGuiFont->drawString(g2, str, posX, posY);
+ mGraphics->setColorAll(mForegroundColor, mForegroundColor2);
+ mGuiFont->drawString(mGraphics, str, posX, posY);
}
}
@@ -523,7 +469,7 @@ void Gui::draw()
if (mouseCursor)
{
mouseCursor->setAlpha(mMouseCursorAlpha);
- g2->drawImage2(mouseCursor, mouseX - 15, mouseY - 17);
+ mGraphics->drawImage(mouseCursor, mouseX - 15, mouseY - 17);
}
}
@@ -579,20 +525,20 @@ void Gui::setUseCustomCursor(const bool customCursor)
}
}
-void Gui::handleMouseMoved(const gcn::MouseInput &mouseInput)
+void Gui::handleMouseMoved(const MouseInput &mouseInput)
{
gcn::Gui::handleMouseMoved(mouseInput);
mMouseInactivityTimer = 0;
}
-void Gui::handleMousePressed(const gcn::MouseInput &mouseInput)
+void Gui::handleMousePressed(const MouseInput &mouseInput)
{
const int x = mouseInput.getX();
const int y = mouseInput.getY();
const unsigned int button = mouseInput.getButton();
const int timeStamp = mouseInput.getTimeStamp();
- gcn::Widget *sourceWidget = getMouseEventSource(x, y);
+ Widget *sourceWidget = getMouseEventSource(x, y);
if (mFocusHandler->getDraggedWidget())
sourceWidget = mFocusHandler->getDraggedWidget();
@@ -655,14 +601,14 @@ void Gui::updateFonts()
mNpcFont->loadFont(fontFile, npcFontSize);
}
-void Gui::distributeMouseEvent(gcn::Widget* source, int type, int button,
+void Gui::distributeMouseEvent(Widget* source, int type, int button,
int x, int y, bool force,
bool toSourceOnly)
{
if (!source || !mFocusHandler)
return;
- gcn::Widget* widget = source;
+ Widget* widget = source;
if (!force && mFocusHandler->getModalFocused() != nullptr
&& !widget->isModalFocused())
@@ -680,12 +626,12 @@ void Gui::distributeMouseEvent(gcn::Widget* source, int type, int button,
mAltPressed, mMetaPressed, type, button,
x, y, mClickCount);
- gcn::Widget* parent = source;
+ Widget* parent = source;
while (parent)
{
// If the widget has been removed due to input
// cancel the distribution.
- if (!gcn::Widget::widgetExists(widget))
+ if (!Widget::widgetExists(widget))
break;
parent = widget->getParent();
@@ -698,42 +644,42 @@ void Gui::distributeMouseEvent(gcn::Widget* source, int type, int button,
mouseEvent.setX(x - widgetX);
mouseEvent.setY(y - widgetY);
- std::list<gcn::MouseListener*> mouseListeners
+ std::list<MouseListener*> mouseListeners
= widget->_getMouseListeners();
// Send the event to all mouse listeners of the widget.
- for (std::list<gcn::MouseListener*>::const_iterator
+ for (std::list<MouseListener*>::const_iterator
it = mouseListeners.begin();
it != mouseListeners.end(); ++ it)
{
switch (mouseEvent.getType())
{
- case gcn::MouseEvent::ENTERED:
+ case MouseEvent::ENTERED:
(*it)->mouseEntered(mouseEvent);
break;
- case gcn::MouseEvent::EXITED:
+ case MouseEvent::EXITED:
(*it)->mouseExited(mouseEvent);
break;
- case gcn::MouseEvent::MOVED:
+ case MouseEvent::MOVED:
(*it)->mouseMoved(mouseEvent);
break;
- case gcn::MouseEvent::PRESSED:
+ case MouseEvent::PRESSED:
(*it)->mousePressed(mouseEvent);
break;
- case gcn::MouseEvent::RELEASED:
+ case MouseEvent::RELEASED:
case 100: // manual hack for release on target after drag
(*it)->mouseReleased(mouseEvent);
break;
- case gcn::MouseEvent::WHEEL_MOVED_UP:
+ case MouseEvent::WHEEL_MOVED_UP:
(*it)->mouseWheelMovedUp(mouseEvent);
break;
- case gcn::MouseEvent::WHEEL_MOVED_DOWN:
+ case MouseEvent::WHEEL_MOVED_DOWN:
(*it)->mouseWheelMovedDown(mouseEvent);
break;
- case gcn::MouseEvent::DRAGGED:
+ case MouseEvent::DRAGGED:
(*it)->mouseDragged(mouseEvent);
break;
- case gcn::MouseEvent::CLICKED:
+ case MouseEvent::CLICKED:
(*it)->mouseClicked(mouseEvent);
break;
default:
@@ -745,11 +691,11 @@ void Gui::distributeMouseEvent(gcn::Widget* source, int type, int button,
break;
}
- const gcn::Widget *const swap = widget;
+ const Widget *const swap = widget;
widget = parent;
parent = swap->getParent();
- if (type == gcn::MouseEvent::RELEASED)
+ if (type == MouseEvent::RELEASED)
dragDrop.clear();
// If a non modal focused widget has been reach
@@ -794,7 +740,7 @@ MouseEvent *Gui::createMouseEvent(Window *const widget)
mouseX - x, mouseY - y, mClickCount);
}
-void Gui::getAbsolutePosition(gcn::Widget *restrict widget,
+void Gui::getAbsolutePosition(Widget *restrict widget,
int &restrict x, int &restrict y)
{
x = 0;
@@ -836,32 +782,31 @@ void Gui::handleMouseInput()
#endif
switch (mouseInput.getType())
{
- case gcn::MouseInput::PRESSED:
+ case MouseInput::PRESSED:
handleMousePressed(mouseInput);
break;
- case gcn::MouseInput::RELEASED:
+ case MouseInput::RELEASED:
handleMouseReleased(mouseInput);
break;
- case gcn::MouseInput::MOVED:
+ case MouseInput::MOVED:
handleMouseMoved(mouseInput);
break;
- case gcn::MouseInput::WHEEL_MOVED_DOWN:
+ case MouseInput::WHEEL_MOVED_DOWN:
handleMouseWheelMovedDown(mouseInput);
break;
- case gcn::MouseInput::WHEEL_MOVED_UP:
+ case MouseInput::WHEEL_MOVED_UP:
handleMouseWheelMovedUp(mouseInput);
break;
default:
- throw GCN_EXCEPTION("Unknown mouse input type.");
break;
}
}
BLOCK_END("Gui::handleMouseInput")
}
-void Gui::handleMouseReleased(const gcn::MouseInput &mouseInput)
+void Gui::handleMouseReleased(const MouseInput &mouseInput)
{
- gcn::Widget *sourceWidget = getMouseEventSource(
+ Widget *sourceWidget = getMouseEventSource(
mouseInput.getX(), mouseInput.getY());
int sourceWidgetX, sourceWidgetY;
@@ -870,7 +815,7 @@ void Gui::handleMouseReleased(const gcn::MouseInput &mouseInput)
if (sourceWidget != mFocusHandler->getLastWidgetPressed())
mFocusHandler->setLastWidgetPressed(nullptr);
- gcn::Widget *oldWidget = sourceWidget;
+ Widget *oldWidget = sourceWidget;
sourceWidget = mFocusHandler->getDraggedWidget();
if (oldWidget != sourceWidget)
{
@@ -911,17 +856,17 @@ void Gui::handleMouseReleased(const gcn::MouseInput &mouseInput)
mFocusHandler->setDraggedWidget(nullptr);
}
-void Gui::addGlobalFocusListener(gcn::FocusListener* focusListener)
+void Gui::addGlobalFocusListener(FocusListener* focusListener)
{
mFocusListeners.push_back(focusListener);
}
-void Gui::removeGlobalFocusListener(gcn::FocusListener* focusListener)
+void Gui::removeGlobalFocusListener(FocusListener* focusListener)
{
mFocusListeners.remove(focusListener);
}
-void Gui::distributeGlobalFocusGainedEvent(const gcn::Event &focusEvent)
+void Gui::distributeGlobalFocusGainedEvent(const Event &focusEvent)
{
for (FocusListenerIterator iter = mFocusListeners.begin();
iter != mFocusListeners.end();
@@ -931,7 +876,7 @@ void Gui::distributeGlobalFocusGainedEvent(const gcn::Event &focusEvent)
}
}
-void Gui::removeDragged(gcn::Widget *widget)
+void Gui::removeDragged(Widget *widget)
{
if (!mFocusHandler)
return;
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 5fddc7df7..4038bbec4 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -23,18 +23,19 @@
#ifndef GUI_GUI_H
#define GUI_GUI_H
-#include <guichan/color.hpp>
-#include <guichan/focuslistener.hpp>
-#include <guichan/gui.hpp>
+#include "gui/color.h"
+
+#include "gui/base/gui.hpp"
#include "localconsts.h"
+class FocusListener;
class Graphics;
class GuiConfigListener;
class ImageSet;
class MouseEvent;
class MouseInput;
-class SDLFont;
+class Font;
class SDLInput;
class Window;
@@ -89,38 +90,38 @@ class Gui final : public gcn::Gui
*/
void videoResized() const;
- gcn::FocusHandler *getFocusHandler() const A_WARN_UNUSED
+ FocusHandler *getFocusHandler() const A_WARN_UNUSED
{ return mFocusHandler; }
/**
* Return game font.
*/
- SDLFont *getFont() const A_WARN_UNUSED
+ Font *getFont() const A_WARN_UNUSED
{ return mGuiFont; }
/**
* Return help font.
*/
- SDLFont *getHelpFont() const A_WARN_UNUSED
+ Font *getHelpFont() const A_WARN_UNUSED
{ return mHelpFont; }
/**
* Return secure font.
*/
- SDLFont *getSecureFont() const A_WARN_UNUSED
+ Font *getSecureFont() const A_WARN_UNUSED
{ return mSecureFont; }
/**
* Return npc font.
*/
- SDLFont *getNpcFont() const A_WARN_UNUSED
+ Font *getNpcFont() const A_WARN_UNUSED
{ return mNpcFont; }
/**
* Return the Font used for "Info Particles", i.e. ones showing, what
* you picked up, etc.
*/
- SDLFont *getInfoParticleFont() const A_WARN_UNUSED
+ Font *getInfoParticleFont() const A_WARN_UNUSED
{ return mInfoParticleFont; }
/**
@@ -147,17 +148,17 @@ class Gui final : public gcn::Gui
MouseEvent *createMouseEvent(Window *const widget) A_WARN_UNUSED;
- static void getAbsolutePosition(gcn::Widget *restrict widget,
+ static void getAbsolutePosition(Widget *restrict widget,
int &restrict x,
int &restrict y);
- void addGlobalFocusListener(gcn::FocusListener* focusListener);
+ void addGlobalFocusListener(FocusListener* focusListener);
- void removeGlobalFocusListener(gcn::FocusListener* focusListener);
+ void removeGlobalFocusListener(FocusListener* focusListener);
- void distributeGlobalFocusGainedEvent(const gcn::Event &focusEvent);
+ void distributeGlobalFocusGainedEvent(const Event &focusEvent);
- void removeDragged(gcn::Widget *widget);
+ void removeDragged(Widget *widget);
int getLastMouseX() const
{ return mLastMouseX; }
@@ -168,25 +169,25 @@ class Gui final : public gcn::Gui
static uint32_t getMouseState(int *const x, int *const y);
protected:
- void handleMouseMoved(const gcn::MouseInput &mouseInput);
+ void handleMouseMoved(const MouseInput &mouseInput);
- void handleMouseReleased(const gcn::MouseInput &mouseInput);
+ void handleMouseReleased(const MouseInput &mouseInput);
- void handleMousePressed(const gcn::MouseInput &mouseInput);
+ void handleMousePressed(const MouseInput &mouseInput);
void handleMouseInput();
- void distributeMouseEvent(gcn::Widget* source, int type, int button,
+ void distributeMouseEvent(Widget* source, int type, int button,
int x, int y, bool force = false,
bool toSourceOnly = false);
private:
GuiConfigListener *mConfigListener;
- SDLFont *mGuiFont; /**< The global GUI font */
- SDLFont *mInfoParticleFont; /**< Font for Info Particles */
- SDLFont *mHelpFont; /**< Font for Help Window */
- SDLFont *mSecureFont; /**< Font for secure labels */
- SDLFont *mNpcFont; /**< Font for npc text */
+ Font *mGuiFont; /**< The global GUI font */
+ Font *mInfoParticleFont; /**< Font for Info Particles */
+ Font *mHelpFont; /**< Font for Help Window */
+ Font *mSecureFont; /**< Font for secure labels */
+ Font *mNpcFont; /**< Font for npc text */
ImageSet *mMouseCursors; /**< Mouse cursor images */
float mMouseCursorAlpha;
int mMouseInactivityTimer;
@@ -195,11 +196,11 @@ class Gui final : public gcn::Gui
uint16_t mLastMouseRealX;
uint16_t mLastMouseRealY;
#endif
- typedef std::list<gcn::FocusListener*> FocusListenerList;
+ typedef std::list<FocusListener*> FocusListenerList;
typedef FocusListenerList::iterator FocusListenerIterator;
FocusListenerList mFocusListeners;
- gcn::Color mForegroundColor;
- gcn::Color mForegroundColor2;
+ Color mForegroundColor;
+ Color mForegroundColor2;
int mTime;
bool mCustomCursor; /**< Show custom cursor */
bool mDoubleClick;
@@ -211,6 +212,6 @@ extern SDLInput *guiInput; /**< GUI input */
/**
* Bolded text font
*/
-extern SDLFont *boldFont;
+extern Font *boldFont;
#endif // GUI_GUI_H
diff --git a/src/gui/models/avatarlistmodel.h b/src/gui/models/avatarlistmodel.h
new file mode 100644
index 000000000..2bbd64878
--- /dev/null
+++ b/src/gui/models/avatarlistmodel.h
@@ -0,0 +1,40 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_AVATARLISTMODEL_H
+#define GUI_MODELS_AVATARLISTMODEL_H
+
+#include "avatar.h"
+
+#include "gui/models/listmodel.h"
+
+#include <string>
+
+class AvatarListModel : public ListModel
+{
+ public:
+ virtual Avatar *getAvatarAt(const int i) A_WARN_UNUSED = 0;
+
+ std::string getElementAt(int i) override final A_WARN_UNUSED
+ { return getAvatarAt(i)->getName(); }
+};
+
+#endif // GUI_MODELS_AVATARLISTMODEL_H
diff --git a/src/gui/models/beingslistmodel.h b/src/gui/models/beingslistmodel.h
new file mode 100644
index 000000000..9f3c48bcc
--- /dev/null
+++ b/src/gui/models/beingslistmodel.h
@@ -0,0 +1,62 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_BEINGSLISTMODEL_H
+#define GUI_MODELS_BEINGSLISTMODEL_H
+
+#include "gui/models/avatarlistmodel.h"
+
+class BeingsListModel final : public AvatarListModel
+{
+ public:
+ BeingsListModel() :
+ AvatarListModel(),
+ mMembers()
+ {
+ }
+
+ A_DELETE_COPY(BeingsListModel)
+
+ ~BeingsListModel()
+ {
+ delete_all(mMembers);
+ mMembers.clear();
+ }
+
+ std::vector<Avatar*> *getMembers()
+ {
+ return &mMembers;
+ }
+
+ Avatar *getAvatarAt(int index) override final
+ {
+ return mMembers[index];
+ }
+
+ int getNumberOfElements() override final
+ {
+ return static_cast<int>(mMembers.size());
+ }
+
+ std::vector<Avatar*> mMembers;
+};
+
+#endif // GUI_MODELS_BEINGSLISTMODEL_H
diff --git a/src/gui/models/colorlistmodel.h b/src/gui/models/colorlistmodel.h
new file mode 100644
index 000000000..d4b2e4237
--- /dev/null
+++ b/src/gui/models/colorlistmodel.h
@@ -0,0 +1,81 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_COLORLISTMODEL_H
+#define GUI_MODELS_COLORLISTMODEL_H
+
+#include "gui/models/listmodel.h"
+
+#include "utils/gettext.h"
+
+const char *COLOR_NAME[14] =
+{
+ // TRANSLATORS: chat color
+ N_("default"),
+ // TRANSLATORS: chat color
+ N_("black"),
+ // TRANSLATORS: chat color
+ N_("red"),
+ // TRANSLATORS: chat color
+ N_("green"),
+ // TRANSLATORS: chat color
+ N_("blue"),
+ // TRANSLATORS: chat color
+ N_("gold"),
+ // TRANSLATORS: chat color
+ N_("yellow"),
+ // TRANSLATORS: chat color
+ N_("pink"),
+ // TRANSLATORS: chat color
+ N_("purple"),
+ // TRANSLATORS: chat color
+ N_("grey"),
+ // TRANSLATORS: chat color
+ N_("brown"),
+ // TRANSLATORS: chat color
+ N_("rainbow 1"),
+ // TRANSLATORS: chat color
+ N_("rainbow 2"),
+ // TRANSLATORS: chat color
+ N_("rainbow 3"),
+};
+
+class ColorListModel final : public ListModel
+{
+ public:
+ ~ColorListModel()
+ { }
+
+ int getNumberOfElements()
+ {
+ return 14;
+ }
+
+ std::string getElementAt(int i)
+ {
+ if (i >= getNumberOfElements() || i < 0)
+ return "???";
+ return gettext(COLOR_NAME[i]);
+ }
+};
+
+#endif // GUI_MODELS_COLORLISTMODEL_H
diff --git a/src/gui/widgets/colormodel.cpp b/src/gui/models/colormodel.cpp
index 7e59553e3..47486d735 100644
--- a/src/gui/widgets/colormodel.cpp
+++ b/src/gui/models/colormodel.cpp
@@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "gui/widgets/colormodel.h"
+#include "gui/models/colormodel.h"
#include "gui/widgets/widget2.h"
@@ -56,8 +56,8 @@ const ColorPair *ColorModel::getColorAt(const int i) const
return &mColors[i];
}
-void ColorModel::add(const std::string &name, const gcn::Color *const color1,
- const gcn::Color *const color2)
+void ColorModel::add(const std::string &name, const Color *const color1,
+ const Color *const color2)
{
mNames.push_back(name);
mColors.push_back(ColorPair(color1, color2));
diff --git a/src/gui/widgets/colormodel.h b/src/gui/models/colormodel.h
index 8b9226159..f3d6f3617 100644
--- a/src/gui/widgets/colormodel.h
+++ b/src/gui/models/colormodel.h
@@ -18,31 +18,31 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef GUI_WIDGETS_COLORMODEL_H
-#define GUI_WIDGETS_COLORMODEL_H
+#ifndef GUI_MODELS_COLORMODEL_H
+#define GUI_MODELS_COLORMODEL_H
#include "utils/stringvector.h"
-#include <guichan/color.hpp>
-#include <guichan/listmodel.hpp>
+#include "gui/models/listmodel.h"
#include "localconsts.h"
+class Color;
class Widget2;
struct ColorPair
{
- ColorPair(const gcn::Color* c1, const gcn::Color* c2) :
+ ColorPair(const Color* c1, const Color* c2) :
color1(c1),
color2(c2)
{
}
- const gcn::Color* color1;
- const gcn::Color* color2;
+ const Color* color1;
+ const Color* color2;
};
-class ColorModel : public gcn::ListModel
+class ColorModel : public ListModel
{
public:
ColorModel();
@@ -63,8 +63,8 @@ class ColorModel : public gcn::ListModel
size_t size() A_WARN_UNUSED
{ return mNames.size(); }
- void add(const std::string &name, const gcn::Color *const color1,
- const gcn::Color *const color2);
+ void add(const std::string &name, const Color *const color1,
+ const Color *const color2);
static ColorModel *createDefault(const Widget2 *const widget);
@@ -73,4 +73,4 @@ class ColorModel : public gcn::ListModel
std::vector<ColorPair> mColors;
};
-#endif // GUI_WIDGETS_COLORMODEL_H
+#endif // GUI_MODELS_COLORMODEL_H
diff --git a/src/gui/widgets/extendedlistmodel.h b/src/gui/models/extendedlistmodel.h
index 0299ef7ed..5d859e781 100644
--- a/src/gui/widgets/extendedlistmodel.h
+++ b/src/gui/models/extendedlistmodel.h
@@ -18,17 +18,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef GUI_WIDGETS_EXTENDEDLISTMODEL_H
-#define GUI_WIDGETS_EXTENDEDLISTMODEL_H
+#ifndef GUI_MODELS_EXTENDEDLISTMODEL_H
+#define GUI_MODELS_EXTENDEDLISTMODEL_H
#include "resources/image.h"
-#include <guichan/listmodel.hpp>
+#include "gui/models/listmodel.h"
-class ExtendedListModel : public gcn::ListModel
+class ExtendedListModel : public ListModel
{
public:
virtual const Image *getImageAt(int i) A_WARN_UNUSED = 0;
};
-#endif // GUI_WIDGETS_EXTENDEDLISTMODEL_H
+#endif // GUI_MODELS_EXTENDEDLISTMODEL_H
diff --git a/src/gui/widgets/extendednamesmodel.cpp b/src/gui/models/extendednamesmodel.cpp
index a8a21d98d..c986085db 100644
--- a/src/gui/widgets/extendednamesmodel.cpp
+++ b/src/gui/models/extendednamesmodel.cpp
@@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "gui/widgets/extendednamesmodel.h"
+#include "gui/models/extendednamesmodel.h"
#include "debug.h"
diff --git a/src/gui/widgets/extendednamesmodel.h b/src/gui/models/extendednamesmodel.h
index 93e87cfa0..383a93951 100644
--- a/src/gui/widgets/extendednamesmodel.h
+++ b/src/gui/models/extendednamesmodel.h
@@ -18,12 +18,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef GUI_WIDGETS_EXTENDEDNAMESMODEL_H
-#define GUI_WIDGETS_EXTENDEDNAMESMODEL_H
+#ifndef GUI_MODELS_EXTENDEDNAMESMODEL_H
+#define GUI_MODELS_EXTENDEDNAMESMODEL_H
#include "utils/stringvector.h"
-#include "gui/widgets/extendedlistmodel.h"
+#include "gui/models/extendedlistmodel.h"
class ExtendedNamesModel : public ExtendedListModel
{
@@ -56,4 +56,4 @@ class ExtendedNamesModel : public ExtendedListModel
std::vector<Image*> mImages;
};
-#endif // GUI_WIDGETS_EXTENDEDNAMESMODEL_H
+#endif // GUI_MODELS_EXTENDEDNAMESMODEL_H
diff --git a/src/gui/models/fontsmodel.h b/src/gui/models/fontsmodel.h
new file mode 100644
index 000000000..036e3f9c4
--- /dev/null
+++ b/src/gui/models/fontsmodel.h
@@ -0,0 +1,42 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2009-2010 Andrei Karas
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_FONTSMODEL_H
+#define GUI_MODELS_FONTSMODEL_H
+
+#include "gui/theme.h"
+
+#include "gui/models/namesmodel.h"
+
+#include "localconsts.h"
+
+class FontsModel final : public NamesModel
+{
+ public:
+ FontsModel() :
+ NamesModel()
+ { Theme::fillFontsList(mNames); }
+
+ ~FontsModel()
+ { }
+};
+
+#endif // GUI_MODELS_FONTSMODEL_H
diff --git a/src/gui/models/iconsmodel.h b/src/gui/models/iconsmodel.h
new file mode 100644
index 000000000..c3031169c
--- /dev/null
+++ b/src/gui/models/iconsmodel.h
@@ -0,0 +1,84 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 Andrei Karas
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_ICONSMODEL_H
+#define GUI_MODELS_ICONSMODEL_H
+
+#include "gui/models/listmodel.h"
+
+#include "resources/iteminfo.h"
+
+#include "resources/db/itemdb.h"
+
+#include "localconsts.h"
+
+class IconsModel final : public ListModel
+{
+ public:
+ IconsModel() :
+ mStrings()
+ {
+ const std::map<int, ItemInfo*> &items = ItemDB::getItemInfos();
+ std::list<std::string> tempStrings;
+
+ for (std::map<int, ItemInfo*>::const_iterator
+ i = items.begin(), i_end = items.end();
+ i != i_end; ++i)
+ {
+ if (i->first < 0)
+ continue;
+
+ const ItemInfo &info = (*i->second);
+ const std::string name = info.getName();
+ if (name != "unnamed" && !info.getName().empty()
+ && info.getName() != "unnamed")
+ {
+ tempStrings.push_back(name);
+ }
+ }
+ tempStrings.sort();
+ mStrings.push_back("");
+ FOR_EACH (std::list<std::string>::const_iterator, i, tempStrings)
+ mStrings.push_back(*i);
+ }
+
+ A_DELETE_COPY(IconsModel)
+
+ ~IconsModel()
+ { }
+
+ int getNumberOfElements() override final
+ {
+ return static_cast<int>(mStrings.size());
+ }
+
+ std::string getElementAt(int i) override final
+ {
+ if (i < 0 || i >= getNumberOfElements())
+ return "???";
+ return mStrings.at(i);
+ }
+ private:
+ StringVect mStrings;
+};
+
+#endif // GUI_MODELS_ICONSMODEL_H
diff --git a/src/gui/models/ignorechoiceslistmodel.h b/src/gui/models/ignorechoiceslistmodel.h
new file mode 100644
index 000000000..8ba3eadb1
--- /dev/null
+++ b/src/gui/models/ignorechoiceslistmodel.h
@@ -0,0 +1,55 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2008-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_IGNORECHOICESLISTMODEL_H
+#define GUI_MODELS_IGNORECHOICESLISTMODEL_H
+
+#include "being/playerrelations.h"
+
+#include "gui/models/playerrelationlistmodel.h"
+
+/**
+ * Class for choosing one of the various `what to do when ignoring a player' options
+ */
+class IgnoreChoicesListModel final : public ListModel
+{
+ public:
+ ~IgnoreChoicesListModel()
+ { }
+
+ int getNumberOfElements() override final
+ {
+ return static_cast<int>(player_relations.
+ getPlayerIgnoreStrategies()->size());
+ }
+
+ std::string getElementAt(int i) override final
+ {
+ if (i >= getNumberOfElements() || i < 0)
+ return "???";
+
+ return (*player_relations.getPlayerIgnoreStrategies())
+ [i]->mDescription;
+ }
+};
+
+#endif // GUI_MODELS_IGNORECHOICESLISTMODEL_H
diff --git a/src/gui/models/itemsmodel.h b/src/gui/models/itemsmodel.h
new file mode 100644
index 000000000..808ae0f04
--- /dev/null
+++ b/src/gui/models/itemsmodel.h
@@ -0,0 +1,86 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_ITEMSMODEL_H
+#define GUI_MODELS_ITEMSMODEL_H
+
+#include "gui/models/listmodel.h"
+
+#include "resources/iteminfo.h"
+
+#include "resources/db/itemdb.h"
+
+#include "utils/gettext.h"
+
+#include "localconsts.h"
+
+class ItemsModal final : public ListModel
+{
+ public:
+ ItemsModal() :
+ mStrings()
+ {
+ const std::map<int, ItemInfo*> &items = ItemDB::getItemInfos();
+ std::list<std::string> tempStrings;
+
+ for (std::map<int, ItemInfo*>::const_iterator
+ i = items.begin(), i_end = items.end();
+ i != i_end; ++i)
+ {
+ if (i->first < 0)
+ continue;
+
+ const ItemInfo &info = *i->second;
+ const std::string name = info.getName();
+ if (name != "unnamed" && !info.getName().empty()
+ && info.getName() != "unnamed")
+ {
+ tempStrings.push_back(name);
+ }
+ }
+ tempStrings.sort();
+ FOR_EACH (std::list<std::string>::const_iterator, i, tempStrings)
+ mStrings.push_back(*i);
+ }
+
+ A_DELETE_COPY(ItemsModal)
+
+ ~ItemsModal()
+ { }
+
+ int getNumberOfElements() override final
+ {
+ return static_cast<int>(mStrings.size());
+ }
+
+ std::string getElementAt(int i) override final
+ {
+ if (i < 0 || i >= getNumberOfElements())
+ return "???";
+ return mStrings.at(i);
+ }
+
+ private:
+ StringVect mStrings;
+};
+
+#endif // GUI_MODELS_ITEMSMODEL_H
diff --git a/src/gui/models/listmodel.h b/src/gui/models/listmodel.h
new file mode 100644
index 000000000..dfce6d4d5
--- /dev/null
+++ b/src/gui/models/listmodel.h
@@ -0,0 +1,103 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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_MODELS_LISTMODEL_H
+#define GUI_MODELS_LISTMODEL_H
+
+#include <string>
+
+#include "localconsts.h"
+
+/**
+ * An interface for a model that represents a list. It is
+ * used in certain widgets, like the ListBox, to handle a
+ * lists with string elements. If you want to use widgets
+ * like ListBox, make a derived class from this class that
+ * represents your list.
+ */
+class ListModel
+{
+ public:
+ /**
+ * Destructor.
+ */
+ virtual ~ListModel()
+ { }
+
+ /**
+ * Gets the number of elements in the list.
+ *
+ * @return The number of elements in the list
+ */
+ virtual int getNumberOfElements() A_WARN_UNUSED = 0;
+
+ /**
+ * Gets an element at a certain index in the list.
+ *
+ * @param i An index in the list.
+ * @return An element as a string at the a certain index.
+ */
+ virtual std::string getElementAt(int i) A_WARN_UNUSED = 0;
+};
+
+#endif // GUI_MODELS_LISTMODEL_H
diff --git a/src/gui/models/magicschoolmodel.h b/src/gui/models/magicschoolmodel.h
new file mode 100644
index 000000000..1f7c4f0f7
--- /dev/null
+++ b/src/gui/models/magicschoolmodel.h
@@ -0,0 +1,67 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 Andrei Karas
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_MAGICSCHOOLMODEL_H
+#define GUI_MODELS_MAGICSCHOOLMODEL_H
+
+#include "gui/models/listmodel.h"
+
+#include "utils/gettext.h"
+
+#include "localconsts.h"
+
+const char *MAGIC_SCHOOL_TEXT[6] =
+{
+ // TRANSLATORS: magic school
+ N_("General Magic"),
+ // TRANSLATORS: magic school
+ N_("Life Magic"),
+ // TRANSLATORS: magic school
+ N_("War Magic"),
+ // TRANSLATORS: magic school
+ N_("Transmute Magic"),
+ // TRANSLATORS: magic school
+ N_("Nature Magic"),
+ // TRANSLATORS: magic school
+ N_("Astral Magic")
+};
+
+class MagicSchoolModel final : public ListModel
+{
+ public:
+ ~MagicSchoolModel()
+ { }
+
+ int getNumberOfElements() override final
+ {
+ return 6;
+ }
+
+ std::string getElementAt(int i) override final
+ {
+ if (i >= getNumberOfElements() || i < 0)
+ return "???";
+ return MAGIC_SCHOOL_TEXT[i];
+ }
+};
+
+#endif // GUI_MODELS_MAGICSCHOOLMODEL_H
diff --git a/src/gui/widgets/namesmodel.cpp b/src/gui/models/namesmodel.cpp
index 339f835d5..54a10c2cf 100644
--- a/src/gui/widgets/namesmodel.cpp
+++ b/src/gui/models/namesmodel.cpp
@@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "gui/widgets/namesmodel.h"
+#include "gui/models/namesmodel.h"
#include "utils/gettext.h"
diff --git a/src/gui/widgets/namesmodel.h b/src/gui/models/namesmodel.h
index f70dd2571..96d16de36 100644
--- a/src/gui/widgets/namesmodel.h
+++ b/src/gui/models/namesmodel.h
@@ -18,16 +18,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef GUI_WIDGETS_NAMESMODEL_H
-#define GUI_WIDGETS_NAMESMODEL_H
+#ifndef GUI_MODELS_NAMESMODEL_H
+#define GUI_MODELS_NAMESMODEL_H
#include "utils/stringvector.h"
-#include <guichan/listmodel.hpp>
+#include "gui/models/listmodel.h"
#include "localconsts.h"
-class NamesModel : public gcn::ListModel
+class NamesModel : public ListModel
{
public:
NamesModel();
@@ -58,4 +58,4 @@ class NamesModel : public gcn::ListModel
StringVect mNames;
};
-#endif // GUI_WIDGETS_NAMESMODEL_H
+#endif // GUI_MODELS_NAMESMODEL_H
diff --git a/src/gui/models/playerrelationlistmodel.h b/src/gui/models/playerrelationlistmodel.h
new file mode 100644
index 000000000..bc343de02
--- /dev/null
+++ b/src/gui/models/playerrelationlistmodel.h
@@ -0,0 +1,67 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2008-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_PLAYERRELATIONLISTMODEL_H
+#define GUI_MODELS_PLAYERRELATIONLISTMODEL_H
+
+#include "being/playerrelations.h"
+
+#include "utils/gettext.h"
+
+static const char *const RELATION_NAMES[PlayerRelation::RELATIONS_NR] =
+{
+ // TRANSLATORS: relation type
+ N_("Neutral"),
+ // TRANSLATORS: relation type
+ N_("Friend"),
+ // TRANSLATORS: relation type
+ N_("Disregarded"),
+ // TRANSLATORS: relation type
+ N_("Ignored"),
+ // TRANSLATORS: relation type
+ N_("Erased"),
+ // TRANSLATORS: relation type
+ N_("Blacklisted"),
+ // TRANSLATORS: relation type
+ N_("Enemy")
+};
+
+class PlayerRelationListModel final : public ListModel
+{
+ public:
+ ~PlayerRelationListModel()
+ { }
+
+ int getNumberOfElements() override final
+ {
+ return PlayerRelation::RELATIONS_NR;
+ }
+
+ std::string getElementAt(int i) override final
+ {
+ if (i >= getNumberOfElements() || i < 0)
+ return "";
+ return gettext(RELATION_NAMES[i]);
+ }
+};
+
+#endif // GUI_MODELS_PLAYERRELATIONLISTMODEL_H
diff --git a/src/gui/models/questsmodel.h b/src/gui/models/questsmodel.h
new file mode 100644
index 000000000..d9421f402
--- /dev/null
+++ b/src/gui/models/questsmodel.h
@@ -0,0 +1,40 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_QUESTSMODEL_H
+#define GUI_MODELS_QUESTSMODEL_H
+
+#include "gui/models/extendednamesmodel.h"
+
+class QuestsModel final : public ExtendedNamesModel
+{
+ public:
+ QuestsModel() :
+ ExtendedNamesModel()
+ {
+ }
+
+ A_DELETE_COPY(QuestsModel)
+
+ ~QuestsModel()
+ { }
+};
+
+#endif // GUI_MODELS_QUESTSMODEL_H
diff --git a/src/gui/models/serverslistmodel.h b/src/gui/models/serverslistmodel.h
new file mode 100644
index 000000000..630d9664e
--- /dev/null
+++ b/src/gui/models/serverslistmodel.h
@@ -0,0 +1,109 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_SERVERSLISTMODEL_H
+#define GUI_MODELS_SERVERSLISTMODEL_H
+
+#include "net/serverinfo.h"
+
+#include "utils/mutex.h"
+
+#include "gui/models/listmodel.h"
+
+#include "net/serverinfo.h"
+
+#include <string>
+#include <vector>
+
+class ServerDialog;
+
+/**
+ * Server and Port List Model
+ */
+class ServersListModel final : public ListModel
+{
+ public:
+ typedef std::pair<int, std::string> VersionString;
+
+ ServersListModel(ServerInfos *const servers,
+ ServerDialog *const parent) :
+ mServers(servers),
+ mVersionStrings(servers->size(), VersionString(0, "")),
+ mParent(parent)
+ {
+ }
+
+ A_DELETE_COPY(ServersListModel)
+
+ /**
+ * Used to get number of line in the list
+ */
+ int getNumberOfElements() override final A_WARN_UNUSED
+ {
+ MutexLocker lock = mParent->lock();
+ return static_cast<int>(mServers->size());
+ }
+
+ /**
+ * Used to get an element from the list
+ */
+ std::string getElementAt(int elementIndex)
+ override final A_WARN_UNUSED
+ {
+ MutexLocker lock = mParent->lock();
+ const ServerInfo &server = mServers->at(elementIndex);
+ std::string myServer;
+ myServer.append(server.hostname);
+ return myServer;
+ }
+
+ /**
+ * Used to get the corresponding Server struct
+ */
+ const ServerInfo &getServer(const int elementIndex) const A_WARN_UNUSED
+ { return mServers->at(elementIndex); }
+
+ void setVersionString(const int index, const std::string &version)
+ {
+ if (index < 0 || index >= static_cast<int>(mVersionStrings.size()))
+ return;
+
+ if (version.empty() || !gui)
+ {
+ mVersionStrings[index] = VersionString(0, "");
+ }
+ else
+ {
+ mVersionStrings[index] = VersionString(
+ gui->getFont()->getWidth(version), version);
+ }
+ }
+
+ private:
+ typedef std::vector<VersionString> VersionStrings;
+
+ ServerInfos *mServers;
+ VersionStrings mVersionStrings;
+ ServerDialog *mParent;
+};
+
+#endif // GUI_MODELS_SERVERSLISTMODEL_H
diff --git a/src/gui/widgets/shopitems.cpp b/src/gui/models/shopitems.cpp
index 2ac65253d..492409e76 100644
--- a/src/gui/widgets/shopitems.cpp
+++ b/src/gui/models/shopitems.cpp
@@ -20,7 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "gui/widgets/shopitems.h"
+#include "gui/models/shopitems.h"
#include "shopitem.h"
diff --git a/src/gui/widgets/shopitems.h b/src/gui/models/shopitems.h
index 4803d6fed..925354960 100644
--- a/src/gui/widgets/shopitems.h
+++ b/src/gui/models/shopitems.h
@@ -20,10 +20,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef GUI_WIDGETS_SHOPITEMS_H
-#define GUI_WIDGETS_SHOPITEMS_H
+#ifndef GUI_MODELS_SHOPITEMS_H
+#define GUI_MODELS_SHOPITEMS_H
-#include <guichan/listmodel.hpp>
+#include "gui/models/listmodel.h"
#include <string>
#include <vector>
@@ -41,7 +41,7 @@ class ShopItem;
*
* This functionality can be enabled in the constructor.
*/
-class ShopItems final : public gcn::ListModel
+class ShopItems final : public ListModel
{
public:
/**
@@ -138,4 +138,4 @@ class ShopItems final : public gcn::ListModel
bool mMergeDuplicates;
};
-#endif // GUI_WIDGETS_SHOPITEMS_H
+#endif // GUI_MODELS_SHOPITEMS_H
diff --git a/src/gui/widgets/skillmodel.cpp b/src/gui/models/skillmodel.cpp
index 3244feec4..706bbdee2 100644
--- a/src/gui/widgets/skillmodel.cpp
+++ b/src/gui/models/skillmodel.cpp
@@ -20,7 +20,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "gui/widgets/skillmodel.h"
+#include "gui/models/skillmodel.h"
#include "gui/widgets/skilldata.h"
diff --git a/src/gui/widgets/skillmodel.h b/src/gui/models/skillmodel.h
index 0f77dccfe..11746118e 100644
--- a/src/gui/widgets/skillmodel.h
+++ b/src/gui/models/skillmodel.h
@@ -20,17 +20,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef GUI_WIDGETS_SKILLMODEL_H
-#define GUI_WIDGETS_SKILLMODEL_H
+#ifndef GUI_MODELS_SKILLMODEL_H
+#define GUI_MODELS_SKILLMODEL_H
#include "gui/widgets/skillinfo.h"
-#include <guichan/listmodel.hpp>
+#include "gui/models/listmodel.h"
#include <string>
#include "localconsts.h"
-class SkillModel final : public gcn::ListModel
+class SkillModel final : public ListModel
{
public:
SkillModel();
@@ -52,4 +52,4 @@ class SkillModel final : public gcn::ListModel
SkillList mVisibleSkills;
};
-#endif // GUI_WIDGETS_SKILLMODEL_H
+#endif // GUI_MODELS_SKILLMODEL_H
diff --git a/src/gui/models/sortlistmodelbuy.h b/src/gui/models/sortlistmodelbuy.h
new file mode 100644
index 000000000..1647ae822
--- /dev/null
+++ b/src/gui/models/sortlistmodelbuy.h
@@ -0,0 +1,65 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_SORTLISTMODELBUY_H
+#define GUI_MODELS_SORTLISTMODELBUY_H
+
+#include "gui/models/listmodel.h"
+
+#include "utils/gettext.h"
+
+static const char *const SORT_NAME_BUY[7] =
+{
+ // TRANSLATORS: buy dialog sort type.
+ N_("unsorted"),
+ // TRANSLATORS: buy dialog sort type.
+ N_("by price"),
+ // TRANSLATORS: buy dialog sort type.
+ N_("by name"),
+ // TRANSLATORS: buy dialog sort type.
+ N_("by id"),
+ // TRANSLATORS: buy dialog sort type.
+ N_("by weight"),
+ // TRANSLATORS: buy dialog sort type.
+ N_("by amount"),
+ // TRANSLATORS: buy dialog sort type.
+ N_("by type")
+};
+
+class SortListModelBuy final : public ListModel
+{
+ public:
+ ~SortListModelBuy()
+ { }
+
+ int getNumberOfElements()
+ { return 7; }
+
+ std::string getElementAt(int i)
+ {
+ if (i >= getNumberOfElements() || i < 0)
+ return "???";
+ return gettext(SORT_NAME_BUY[i]);
+ }
+};
+
+#endif // GUI_MODELS_SORTLISTMODELBUY_H
diff --git a/src/gui/models/sortlistmodelinv.h b/src/gui/models/sortlistmodelinv.h
new file mode 100644
index 000000000..ae0982af6
--- /dev/null
+++ b/src/gui/models/sortlistmodelinv.h
@@ -0,0 +1,65 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_SORTLISTMODELINV_H
+#define GUI_MODELS_SORTLISTMODELINV_H
+
+#include "gui/models/listmodel.h"
+
+#include "utils/gettext.h"
+
+#include <string>
+
+static const char *const SORT_NAME_INVENTORY[6] =
+{
+ // TRANSLATORS: inventory sort mode
+ N_("default"),
+ // TRANSLATORS: inventory sort mode
+ N_("by name"),
+ // TRANSLATORS: inventory sort mode
+ N_("by id"),
+ // TRANSLATORS: inventory sort mode
+ N_("by weight"),
+ // TRANSLATORS: inventory sort mode
+ N_("by amount"),
+ // TRANSLATORS: inventory sort mode
+ N_("by type")
+};
+
+class SortListModelInv final : public ListModel
+{
+ public:
+ ~SortListModelInv()
+ { }
+
+ int getNumberOfElements() override final
+ { return 6; }
+
+ std::string getElementAt(int i) override final
+ {
+ if (i >= getNumberOfElements() || i < 0)
+ return "???";
+
+ return gettext(SORT_NAME_INVENTORY[i]);
+ }
+};
+
+#endif // GUI_MODELS_SORTLISTMODELINV_H
diff --git a/src/gui/widgets/mouseevent.h b/src/gui/models/soundsmodel.h
index b7c0cc94c..3ac679d37 100644
--- a/src/gui/widgets/mouseevent.h
+++ b/src/gui/models/soundsmodel.h
@@ -19,30 +19,29 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef GUI_WIDGETS_MOUSEEVENT_H
-#define GUI_WIDGETS_MOUSEEVENT_H
+#ifndef GUI_MODELS_SOUNDSMODEL_H
+#define GUI_MODELS_SOUNDSMODEL_H
-#include <guichan/mouseevent.hpp>
-#include <guichan/widget.hpp>
+#include "gui/theme.h"
-class MouseEvent final : public gcn::MouseEvent
+#include "gui/models/namesmodel.h"
+
+#include "utils/gettext.h"
+
+#include "localconsts.h"
+
+class SoundsModel final : public NamesModel
{
public:
- MouseEvent(gcn::Widget* source, bool shiftPressed,
- bool controlPressed, bool altPressed,
- bool metaPressed, unsigned int type, unsigned int button,
- int x, int y, int clickCount) :
- gcn::MouseEvent(source, shiftPressed, controlPressed,
- altPressed, metaPressed, type, button, x, y,
- clickCount)
+ SoundsModel() :
+ NamesModel()
{
+ mNames.push_back(gettext("(no sound)"));
+ Theme::fillSoundsList(mNames);
}
- void setX(int n)
- { mX = n; }
-
- void setY(int n)
- { mY = n; }
+ ~SoundsModel()
+ { }
};
-#endif // GUI_WIDGETS_MOUSEEVENT_H
+#endif // GUI_MODELS_SOUNDSMODEL_H
diff --git a/src/gui/widgets/tablemodel.cpp b/src/gui/models/tablemodel.cpp
index f244f51f4..aad66a6ad 100644
--- a/src/gui/widgets/tablemodel.cpp
+++ b/src/gui/models/tablemodel.cpp
@@ -20,11 +20,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "gui/widgets/tablemodel.h"
+#include "gui/models/tablemodel.h"
#include "utils/dtor.h"
-#include <guichan/widget.hpp>
+#include "gui/widgets/widget.h"
#include "debug.h"
@@ -89,7 +89,7 @@ void StaticTableModel::resize()
}
void StaticTableModel::set(const int row, const int column,
- gcn::Widget *const widget)
+ Widget *const widget)
{
if (!widget || row >= mRows || row < 0
|| column >= mColumns || column < 0)
@@ -119,8 +119,8 @@ void StaticTableModel::set(const int row, const int column,
signalAfterUpdate();
}
-gcn::Widget *StaticTableModel::getElementAt(const int row,
- const int column) const
+Widget *StaticTableModel::getElementAt(const int row,
+ const int column) const
{
return mTableModel[WIDGET_AT(row, column)];
}
diff --git a/src/gui/widgets/tablemodel.h b/src/gui/models/tablemodel.h
index 1273c6873..032facadd 100644
--- a/src/gui/widgets/tablemodel.h
+++ b/src/gui/models/tablemodel.h
@@ -20,18 +20,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef GUI_WIDGETS_TABLEMODEL_H
-#define GUI_WIDGETS_TABLEMODEL_H
+#ifndef GUI_MODELS_TABLEMODEL_H
+#define GUI_MODELS_TABLEMODEL_H
#include <set>
#include <vector>
#include "localconsts.h"
-namespace gcn
-{
- class Widget;
-}
+class Widget;
class TableModelListener
{
@@ -83,7 +80,7 @@ public:
/**
* Retrieves the widget stored at the specified location within the table.
*/
- virtual gcn::Widget *getElementAt(const int row, const int column)
+ virtual Widget *getElementAt(const int row, const int column)
const A_WARN_UNUSED = 0;
virtual void installListener(TableModelListener *const listener);
@@ -125,7 +122,7 @@ public:
* The model is resized to accomodate the widget's width and height,
* unless column width / row height have been fixed.
*/
- void set(const int row, const int column, gcn::Widget *const widget);
+ void set(const int row, const int column, Widget *const widget);
/**
* Fixes the column width for a given column; this overrides dynamic width
@@ -153,15 +150,14 @@ public:
int getWidth() const A_WARN_UNUSED;
int getHeight() const A_WARN_UNUSED;
int getColumnWidth(const int index) const override final A_WARN_UNUSED;
- gcn::Widget *getElementAt(const int row,
- const int column) const
- override final A_WARN_UNUSED;
+ Widget *getElementAt(const int row,
+ const int column) const override final A_WARN_UNUSED;
protected:
int mRows, mColumns;
int mHeight;
- std::vector<gcn::Widget *> mTableModel;
+ std::vector<Widget *> mTableModel;
std::vector<int> mWidths;
};
-#endif // GUI_WIDGETS_TABLEMODEL_H
+#endif // GUI_MODELS_TABLEMODEL_H
diff --git a/src/gui/models/targettypemodel.h b/src/gui/models/targettypemodel.h
new file mode 100644
index 000000000..d049585a5
--- /dev/null
+++ b/src/gui/models/targettypemodel.h
@@ -0,0 +1,58 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2009-2010 Andrei Karas
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_TARGETTYPEMODEL_H
+#define GUI_MODELS_TARGETTYPEMODEL_H
+
+#include "gui/models/listmodel.h"
+
+#include "utils/gettext.h"
+
+const char *TARGET_TYPE_TEXT[3] =
+{
+ // TRANSLATORS: target type
+ N_("No Target"),
+ // TRANSLATORS: target type
+ N_("Allow Target"),
+ // TRANSLATORS: target type
+ N_("Need Target")
+};
+
+class TargetTypeModel final : public ListModel
+{
+ public:
+ ~TargetTypeModel()
+ { }
+
+ int getNumberOfElements() override final
+ {
+ return 3;
+ }
+
+ std::string getElementAt(int i) override final
+ {
+ if (i >= getNumberOfElements() || i < 0)
+ return "???";
+ return TARGET_TYPE_TEXT[i];
+ }
+};
+
+#endif // GUI_MODELS_TARGETTYPEMODEL_H
diff --git a/src/gui/models/themesmodel.h b/src/gui/models/themesmodel.h
new file mode 100644
index 000000000..7f76534f0
--- /dev/null
+++ b/src/gui/models/themesmodel.h
@@ -0,0 +1,47 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2009-2010 Andrei Karas
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_THEMESMODEL_H
+#define GUI_MODELS_THEMESMODEL_H
+
+#include "gui/theme.h"
+
+#include "gui/models/namesmodel.h"
+
+#include "utils/gettext.h"
+
+#include "localconsts.h"
+
+class ThemesModel final : public NamesModel
+{
+ public:
+ ThemesModel() :
+ NamesModel()
+ {
+ mNames.push_back(gettext("(default)"));
+ Theme::fillSkinsList(mNames);
+ }
+
+ ~ThemesModel()
+ { }
+};
+
+#endif // GUI_MODELS_THEMESMODEL_H
diff --git a/src/gui/models/touchactionmodel.cpp b/src/gui/models/touchactionmodel.cpp
new file mode 100644
index 000000000..b32d1479f
--- /dev/null
+++ b/src/gui/models/touchactionmodel.cpp
@@ -0,0 +1,84 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/setupactiondata.h"
+
+#include "gui/models/touchactionmodel.h"
+
+#include <algorithm>
+
+#include "debug.h"
+
+static class SortTouchActionFunctor final
+{
+ public:
+ bool operator() (const SetupActionData *const data1,
+ const SetupActionData *const data2) const
+ {
+ if (!data1 || !data2)
+ return false;
+ return data1->name < data2->name;
+ }
+} touchActionSorter;
+
+TouchActionsModel::TouchActionsModel() :
+ NamesModel(),
+ mActionId(),
+ mActionToSelection()
+{
+ std::vector<SetupActionData*> data;
+
+ for (int f = 0, sz = touchActionDataSize; f < sz; f ++)
+ {
+ int k = 0;
+ while (!touchActionData[f][k].name.empty())
+ {
+ data.push_back(&touchActionData[f][k]);
+ k ++;
+ }
+ }
+
+ std::sort(data.begin(), data.end(), touchActionSorter);
+ int cnt = 0;
+ FOR_EACH (std::vector<SetupActionData*>::iterator, it, data)
+ {
+ const SetupActionData *const data1 = *it;
+ mNames.push_back(data1->name);
+ mActionId.push_back(data1->actionId);
+ mActionToSelection[data1->actionId] = cnt;
+ cnt ++;
+ }
+}
+
+int TouchActionsModel::getActionFromSelection(const int sel) const
+{
+ if (sel < 0 || sel > static_cast<signed int>(mActionId.size()))
+ return -1;
+ return mActionId[sel];
+}
+
+int TouchActionsModel::getSelectionFromAction(const int action) const
+{
+ const std::map<int, int>::const_iterator it
+ = mActionToSelection.find(action);
+ if (it == mActionToSelection.end())
+ return 0;
+ return (*it).second;
+}
diff --git a/src/gui/models/touchactionmodel.h b/src/gui/models/touchactionmodel.h
new file mode 100644
index 000000000..00abe89e2
--- /dev/null
+++ b/src/gui/models/touchactionmodel.h
@@ -0,0 +1,47 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2012-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_TOUCHACTIONMODEL_H
+#define GUI_MODELS_TOUCHACTIONMODEL_H
+
+#include "gui/models/namesmodel.h"
+
+#include "gui/widgets/setupitem.h"
+
+class TouchActionsModel final : public NamesModel
+{
+ public:
+ TouchActionsModel();
+
+ A_DELETE_COPY(TouchActionsModel)
+
+ ~TouchActionsModel()
+ { }
+
+ int getActionFromSelection(const int sel) const;
+
+ int getSelectionFromAction(const int action) const;
+
+ private:
+ std::vector<int> mActionId;
+ std::map<int, int> mActionToSelection;
+};
+
+#endif // GUI_MODELS_TOUCHACTIONMODEL_H
diff --git a/src/gui/models/typelistmodel.h b/src/gui/models/typelistmodel.h
new file mode 100644
index 000000000..f9c005f8f
--- /dev/null
+++ b/src/gui/models/typelistmodel.h
@@ -0,0 +1,65 @@
+/*
+ * The Mana Client
+ * Copyright (C) 2011-2012 The Mana Developers
+ * Copyright (C) 2012-2014 The ManaPlus Developers
+ *
+ * This file is part of The Mana 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_MODELS_TYPELISTMODEL_H
+#define GUI_MODELS_TYPELISTMODEL_H
+
+#include "gui/models/listmodel.h"
+
+/**
+ * Server Type List Model
+ */
+class TypeListModel : public ListModel
+{
+ public:
+ TypeListModel()
+ { }
+
+ /**
+ * Used to get number of line in the list
+ */
+ int getNumberOfElements() override final A_WARN_UNUSED
+#ifdef EATHENA_SUPPORT
+ { return 3; }
+#else
+ { return 2; }
+#endif
+
+ /**
+ * Used to get an element from the list
+ */
+ std::string getElementAt(int elementIndex)
+ override final A_WARN_UNUSED
+ {
+ if (elementIndex == 0)
+ return "TmwAthena";
+ else if (elementIndex == 1)
+ return "Evol";
+#ifdef EATHENA_SUPPORT
+ else if (elementIndex == 2)
+ return "eAthena";
+#endif
+ else
+ return "Unknown";
+ }
+};
+
+#endif // GUI_MODELS_TYPELISTMODEL_H
diff --git a/src/gui/models/updatelistmodel.h b/src/gui/models/updatelistmodel.h
new file mode 100644
index 000000000..2e1d2a7d5
--- /dev/null
+++ b/src/gui/models/updatelistmodel.h
@@ -0,0 +1,66 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_UPDATELISTMODEL_H
+#define GUI_MODELS_UPDATELISTMODEL_H
+
+#include "gui/models/listmodel.h"
+
+#include "net/logindata.h"
+
+#include "utils/gettext.h"
+
+#include "localconsts.h"
+
+class UpdateListModel final : public ListModel
+{
+ public:
+ explicit UpdateListModel(LoginData *const data) :
+ ListModel(),
+ mLoginData(data)
+ {
+ }
+
+ A_DELETE_COPY(UpdateListModel)
+
+ ~UpdateListModel()
+ { }
+
+ int getNumberOfElements() override final
+ {
+ if (!mLoginData)
+ return 0;
+ return static_cast<int>(mLoginData->updateHosts.size());
+ }
+
+ std::string getElementAt(int i) override final
+ {
+ if (!mLoginData || i >= getNumberOfElements() || i < 0)
+ return "???";
+ return mLoginData->updateHosts[i];
+ }
+
+ protected:
+ LoginData *mLoginData;
+};
+
+#endif // GUI_MODELS_UPDATELISTMODEL_H
diff --git a/src/gui/models/updatetypemodel.h b/src/gui/models/updatetypemodel.h
new file mode 100644
index 000000000..f96c11e87
--- /dev/null
+++ b/src/gui/models/updatetypemodel.h
@@ -0,0 +1,63 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_UPDATETYPEMODEL_H
+#define GUI_MODELS_UPDATETYPEMODEL_H
+
+#include "utils/gettext.h"
+
+#include "gui/models/listmodel.h"
+
+const char *UPDATE_TYPE_TEXT[3] =
+{
+ // TRANSLATORS: update type
+ N_("Normal"),
+ // TRANSLATORS: update type
+ N_("Auto Close"),
+ // TRANSLATORS: update type
+ N_("Skip"),
+};
+
+class UpdateTypeModel final : public ListModel
+{
+ public:
+ UpdateTypeModel()
+ { }
+
+ A_DELETE_COPY(UpdateTypeModel)
+
+ ~UpdateTypeModel()
+ { }
+
+ int getNumberOfElements() override final
+ {
+ return 3;
+ }
+
+ std::string getElementAt(int i) override final
+ {
+ if (i >= getNumberOfElements() || i < 0)
+ return "???";
+ return gettext(UPDATE_TYPE_TEXT[i]);
+ }
+};
+
+#endif // GUI_MODELS_UPDATETYPEMODEL_H
diff --git a/src/gui/models/worldlistmodel.h b/src/gui/models/worldlistmodel.h
new file mode 100644
index 000000000..7d9dc322c
--- /dev/null
+++ b/src/gui/models/worldlistmodel.h
@@ -0,0 +1,68 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_MODELS_WORLDLISTMODEL_H
+#define GUI_MODELS_WORLDLISTMODEL_H
+
+#include "gui/models/listmodel.h"
+
+#include "net/worldinfo.h"
+
+/**
+ * The list model for the server list.
+ */
+class WorldListModel final : public ListModel
+{
+ public:
+ explicit WorldListModel(Worlds worlds) :
+ mWorlds(worlds)
+ {
+ }
+
+ A_DELETE_COPY(WorldListModel)
+
+ ~WorldListModel()
+ { }
+
+ int getNumberOfElements() override final
+ {
+ return static_cast<int>(mWorlds.size());
+ }
+
+ std::string getElementAt(int i) override final
+ {
+ const WorldInfo *const si = mWorlds[i];
+ if (si)
+ {
+ return std::string(si->name).append(" (").append(
+ toString(si->online_users)).append(")");
+ }
+ else
+ {
+ return "???";
+ }
+ }
+ private:
+ Worlds mWorlds;
+};
+
+#endif // GUI_MODELS_WORLDLISTMODEL_H
diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp
index 9d6c19095..21e027d82 100644
--- a/src/gui/palette.cpp
+++ b/src/gui/palette.cpp
@@ -29,18 +29,18 @@
#include "debug.h"
-const gcn::Color Palette::BLACK = gcn::Color(0, 0, 0);
+const Color Palette::BLACK = Color(0, 0, 0);
Palette::Palettes Palette::mInstances;
-const gcn::Color Palette::RAINBOW_COLORS[7] =
+const Color Palette::RAINBOW_COLORS[7] =
{
- gcn::Color(255, 0, 0),
- gcn::Color(255, 153, 0),
- gcn::Color(255, 255, 0),
- gcn::Color(0, 153, 0),
- gcn::Color(0, 204, 204),
- gcn::Color(51, 0, 153),
- gcn::Color(153, 0, 153)
+ Color(255, 0, 0),
+ Color(255, 153, 0),
+ Color(255, 255, 0),
+ Color(0, 153, 0),
+ Color(0, 204, 204),
+ Color(51, 0, 153),
+ Color(153, 0, 153)
};
const int Palette::RAINBOW_COLOR_COUNT = 7;
@@ -59,7 +59,7 @@ Palette::~Palette()
mInstances.erase(this);
}
-const gcn::Color& Palette::getCharColor(const signed char c, bool &valid) const
+const Color& Palette::getCharColor(const signed char c, bool &valid) const
{
const CharColors::const_iterator it = mCharColors.find(c);
if (it != mCharColors.end())
@@ -128,7 +128,7 @@ void Palette::advanceGradient()
else
colIndex = gradIndex;
- gcn::Color &color = elem->color;
+ Color &color = elem->color;
int colVal;
if (grad == PULSE)
@@ -136,7 +136,7 @@ void Palette::advanceGradient()
colVal = static_cast<int>(255.0 *
sin(M_PI * colIndex / numOfColors));
- const gcn::Color &col = elem->testColor;
+ const Color &col = elem->testColor;
color.r = ((colVal * col.r) / 255) % (col.r + 1);
color.g = ((colVal * col.g) / 255) % (col.g + 1);
@@ -180,9 +180,9 @@ void Palette::advanceGradient()
}
else if (elem->grad == RAINBOW)
{
- const gcn::Color &startCol = RAINBOW_COLORS[colIndex];
- const gcn::Color &destCol =
- RAINBOW_COLORS[(colIndex + 1) % numOfColors];
+ const Color &startCol = RAINBOW_COLORS[colIndex];
+ const Color &destCol
+ = RAINBOW_COLORS[(colIndex + 1) % numOfColors];
double startColVal;
double destColVal;
diff --git a/src/gui/palette.h b/src/gui/palette.h
index 26ea6817c..0dbb5d3ad 100644
--- a/src/gui/palette.h
+++ b/src/gui/palette.h
@@ -26,7 +26,7 @@
#include "logger.h"
-#include <guichan/color.hpp>
+#include "gui/color.h"
#if defined __native_client__
#include <stdlib.h>
@@ -49,7 +49,7 @@ class Palette
{
public:
/** Black Color Constant */
- static const gcn::Color BLACK;
+ static const Color BLACK;
/** Colors can be static or can alter over time. */
enum GradientType
@@ -71,8 +71,8 @@ class Palette
*
* @return the requested color or Palette::BLACK
*/
- const gcn::Color &getCharColor(const signed char c,
- bool &valid) const A_WARN_UNUSED;
+ const Color &getCharColor(const signed char c,
+ bool &valid) const A_WARN_UNUSED;
int getIdByChar(const signed char c, bool &valid) const A_WARN_UNUSED;
@@ -85,8 +85,8 @@ class Palette
*
* @return the requested color
*/
- inline const gcn::Color &getColor(int type,
- const int alpha = 255) A_WARN_UNUSED
+ inline const Color &getColor(int type,
+ const int alpha = 255) A_WARN_UNUSED
{
if (type >= static_cast<signed>(mColors.size()) || type < 0)
{
@@ -94,15 +94,14 @@ class Palette
type, static_cast<unsigned int>(mColors.size()));
type = 0;
}
- gcn::Color* col = &mColors[type].color;
+ Color* col = &mColors[type].color;
col->a = alpha;
return *col;
}
- inline const gcn::Color &getColorWithAlpha(const int type)
- A_WARN_UNUSED
+ inline const Color &getColorWithAlpha(const int type) A_WARN_UNUSED
{
- gcn::Color* col = &mColors[type].color;
+ Color* col = &mColors[type].color;
col->a = mColors[type].delay;
return *col;
}
@@ -144,7 +143,7 @@ class Palette
protected:
/** Colors used for the rainbow gradient */
- static const gcn::Color RAINBOW_COLORS[7];
+ static const Color RAINBOW_COLORS[7];
static const int RAINBOW_COLOR_COUNT;
/** Time tick, that gradient-type colors were updated the last time. */
@@ -183,9 +182,9 @@ class Palette
}
int type;
- gcn::Color color;
- gcn::Color testColor;
- gcn::Color committedColor;
+ Color color;
+ Color testColor;
+ Color committedColor;
std::string text;
signed char ch;
GradientType grad;
@@ -194,7 +193,7 @@ class Palette
int delay;
int committedDelay;
- void set(const int type0, const gcn::Color &color0,
+ void set(const int type0, const Color &color0,
const GradientType grad0, const int delay0)
{
type = type0;
diff --git a/src/gui/popups/beingpopup.cpp b/src/gui/popups/beingpopup.cpp
index 6d3077130..07d4b064a 100644
--- a/src/gui/popups/beingpopup.cpp
+++ b/src/gui/popups/beingpopup.cpp
@@ -24,15 +24,14 @@
#include "being/being.h"
#include "being/playerrelations.h"
-#include "gui/sdlfont.h"
+#include "gui/font.h"
+#include "gui/gui.h"
#include "gui/widgets/label.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
-#include <guichan/font.hpp>
-
#include "debug.h"
BeingPopup::BeingPopup() :
diff --git a/src/gui/popups/itempopup.cpp b/src/gui/popups/itempopup.cpp
index 1fd496dec..0a65ce3bc 100644
--- a/src/gui/popups/itempopup.cpp
+++ b/src/gui/popups/itempopup.cpp
@@ -27,7 +27,8 @@
#include "item.h"
#include "units.h"
-#include "gui/sdlfont.h"
+#include "gui/font.h"
+#include "gui/gui.h"
#include "gui/widgets/icon.h"
#include "gui/widgets/label.h"
@@ -38,8 +39,6 @@
#include "resources/image.h"
#include "resources/resourcemanager.h"
-#include <guichan/font.hpp>
-
#include "debug.h"
extern int serverVersion;
@@ -265,7 +264,7 @@ void ItemPopup::setLabelColor(Label *label, const ItemType type) const
}
#undef caseSetColor
-void ItemPopup::mouseMoved(gcn::MouseEvent &event)
+void ItemPopup::mouseMoved(MouseEvent &event)
{
Popup::mouseMoved(event);
diff --git a/src/gui/popups/itempopup.h b/src/gui/popups/itempopup.h
index ac4683938..f1cedf046 100644
--- a/src/gui/popups/itempopup.h
+++ b/src/gui/popups/itempopup.h
@@ -29,6 +29,7 @@
#include "resources/iteminfo.h"
class Icon;
+class Item;
class Label;
class TextBox;
@@ -60,7 +61,7 @@ class ItemPopup final : public Popup
void setItem(const Item *const item, const bool showImage = false);
- void mouseMoved(gcn::MouseEvent &mouseEvent) override final;
+ void mouseMoved(MouseEvent &mouseEvent) override final;
private:
Label *mItemName;
diff --git a/src/gui/popups/popupmenu.cpp b/src/gui/popups/popupmenu.cpp
index 52cf1d5d6..3905d91e6 100644
--- a/src/gui/popups/popupmenu.cpp
+++ b/src/gui/popups/popupmenu.cpp
@@ -23,6 +23,7 @@
#include "gui/popups/popupmenu.h"
#include "actormanager.h"
+#include "commands.h"
#include "commandhandler.h"
#include "configuration.h"
#include "dropshortcut.h"
@@ -56,6 +57,7 @@
#include "gui/viewport.h"
+#include "gui/widgets/button.h"
#include "gui/widgets/browserbox.h"
#include "gui/widgets/tabs/chattab.h"
#include "gui/widgets/progressbar.h"
@@ -79,7 +81,7 @@
#include "utils/gettext.h"
#include "utils/process.h"
-#include <guichan/listmodel.hpp>
+#include "gui/models/listmodel.h"
#include "debug.h"
@@ -118,7 +120,7 @@ PopupMenu::PopupMenu() :
mPlayerListener.setNick("");
mPlayerListener.setDialog(nullptr);
mPlayerListener.setType(static_cast<int>(Being::UNKNOWN));
- mScrollArea = new ScrollArea(mBrowserBox, false);
+ mScrollArea = new ScrollArea(this, mBrowserBox, false);
mScrollArea->setVerticalScrollPolicy(ScrollArea::SHOW_AUTO);
}
@@ -839,7 +841,7 @@ void PopupMenu::showChangePos(const int x, const int y)
}
void PopupMenu::handleLink(const std::string &link,
- gcn::MouseEvent *event A_UNUSED)
+ MouseEvent *event A_UNUSED)
{
Being *being = nullptr;
if (actorManager)
@@ -2683,7 +2685,7 @@ void PopupMenu::addPickupFilter(const std::string &name)
}
void PopupMenu::showPopup(const int x, const int y,
- gcn::ListModel *const model)
+ ListModel *const model)
{
if (!model)
return;
@@ -2838,7 +2840,7 @@ void PopupMenu::showGMPopup()
}
RenameListener::RenameListener() :
- gcn::ActionListener(),
+ ActionListener(),
mMapItemX(0),
mMapItemY(0),
mDialog(nullptr)
@@ -2859,7 +2861,7 @@ void RenameListener::setMapItem(MapItem *const mapItem)
}
}
-void RenameListener::action(const gcn::ActionEvent &event)
+void RenameListener::action(const ActionEvent &event)
{
if (event.getId() == "ok" && viewport && mDialog)
{
@@ -2893,7 +2895,7 @@ PlayerListener::PlayerListener() :
{
}
-void PlayerListener::action(const gcn::ActionEvent &event)
+void PlayerListener::action(const ActionEvent &event)
{
if (event.getId() == "ok" && !mNick.empty() && mDialog)
{
diff --git a/src/gui/popups/popupmenu.h b/src/gui/popups/popupmenu.h
index 0970f34b6..7eb38dc15 100644
--- a/src/gui/popups/popupmenu.h
+++ b/src/gui/popups/popupmenu.h
@@ -26,19 +26,18 @@
#include "gui/widgets/linkhandler.h"
#include "gui/widgets/popup.h"
-#include "being/actorsprite.h"
-
-#include <guichan/actionlistener.hpp>
-#include <guichan/listmodel.hpp>
+#include "listeners/actionlistener.h"
#include "localconsts.h"
+class ActorSprite;
class Being;
class BrowserBox;
class Button;
class ChatTab;
class FloorItem;
class Item;
+class ListModel;
class MapItem;
class ScrollArea;
class TextCommand;
@@ -47,14 +46,14 @@ class TextField;
class ProgressBar;
class Window;
-class RenameListener final : public gcn::ActionListener
+class RenameListener final : public ActionListener
{
public:
RenameListener();
A_DELETE_COPY(RenameListener)
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void setMapItem(MapItem *const mapItem);
@@ -67,14 +66,14 @@ class RenameListener final : public gcn::ActionListener
TextDialog *mDialog;
};
-class PlayerListener : public gcn::ActionListener
+class PlayerListener : public ActionListener
{
public:
PlayerListener();
A_DELETE_COPY(PlayerListener)
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void setNick(std::string name)
{ mNick = name; }
@@ -173,7 +172,7 @@ class PopupMenu final : public Popup, public LinkHandler
void showChangePos(const int x, const int y);
- void showPopup(const int x, const int y, gcn::ListModel *const model);
+ void showPopup(const int x, const int y, ListModel *const model);
void showTextFieldPopup(int x, int y, TextField *const input);
@@ -187,7 +186,7 @@ class PopupMenu final : public Popup, public LinkHandler
* Handles link action.
*/
void handleLink(const std::string &link,
- gcn::MouseEvent *event A_UNUSED) override final;
+ MouseEvent *event A_UNUSED) override final;
void clear();
diff --git a/src/gui/popups/speechbubble.cpp b/src/gui/popups/speechbubble.cpp
index e32a6bb4d..3d0250a78 100644
--- a/src/gui/popups/speechbubble.cpp
+++ b/src/gui/popups/speechbubble.cpp
@@ -23,14 +23,12 @@
#include "gui/popups/speechbubble.h"
-#include "gui/sdlfont.h"
+#include "gui/font.h"
+#include "gui/gui.h"
#include "gui/viewport.h"
#include "gui/widgets/browserbox.h"
#include "gui/widgets/label.h"
-#include "gui/widgets/textbox.h"
-
-#include <guichan/font.hpp>
#include "debug.h"
@@ -59,8 +57,8 @@ void SpeechBubble::postInit()
}
void SpeechBubble::setCaption(const std::string &name,
- const gcn::Color *const color1,
- const gcn::Color *const color2)
+ const Color *const color1,
+ const Color *const color2)
{
mCaption->setCaption(name);
mCaption->adjustSize();
diff --git a/src/gui/popups/speechbubble.h b/src/gui/popups/speechbubble.h
index 62da9b146..1bc5385a4 100644
--- a/src/gui/popups/speechbubble.h
+++ b/src/gui/popups/speechbubble.h
@@ -47,9 +47,9 @@ class SpeechBubble final : public Popup
* Sets the name displayed for the speech bubble, and in what color.
*/
void setCaption(const std::string &name,
- const gcn::Color *const color1 =
+ const Color *const color1 =
&Theme::getThemeColor(Theme::BUBBLE_NAME),
- const gcn::Color *const color2 =
+ const Color *const color2 =
&Theme::getThemeColor(Theme::BUBBLE_NAME_OUTLINE));
/**
diff --git a/src/gui/popups/spellpopup.cpp b/src/gui/popups/spellpopup.cpp
index df25739f2..bf6ea1799 100644
--- a/src/gui/popups/spellpopup.cpp
+++ b/src/gui/popups/spellpopup.cpp
@@ -23,7 +23,9 @@
#include "gui/popups/spellpopup.h"
-#include "gui/sdlfont.h"
+#include "textcommand.h"
+
+#include "gui/gui.h"
#include "gui/widgets/label.h"
@@ -88,7 +90,7 @@ void SpellPopup::view(const int x, const int y)
int posX = std::max(0, x - getWidth() / 2);
int posY = y + distance;
- const gcn::Rectangle &rect = mDimension;
+ const Rect &rect = mDimension;
const int w = rect.width;
const int h = rect.height;
if (posX + w > mainGraphics->mWidth)
@@ -109,7 +111,7 @@ void SpellPopup::view(const int x, const int y)
requestMoveToTop();
}
-void SpellPopup::mouseMoved(gcn::MouseEvent &event)
+void SpellPopup::mouseMoved(MouseEvent &event)
{
Popup::mouseMoved(event);
diff --git a/src/gui/popups/spellpopup.h b/src/gui/popups/spellpopup.h
index c8123a4ce..cbbd53703 100644
--- a/src/gui/popups/spellpopup.h
+++ b/src/gui/popups/spellpopup.h
@@ -26,9 +26,8 @@
#include "gui/widgets/popup.h"
-#include "textcommand.h"
-
class Label;
+class TextCommand;
/**
* A popup that displays information about an item.
@@ -60,7 +59,7 @@ class SpellPopup final : public Popup
*/
void view(const int x, const int y);
- void mouseMoved(gcn::MouseEvent &mouseEvent) override final;
+ void mouseMoved(MouseEvent &mouseEvent) override final;
private:
Label *mItemName;
diff --git a/src/gui/popups/statuspopup.cpp b/src/gui/popups/statuspopup.cpp
index 1d696fe82..7dd3c3634 100644
--- a/src/gui/popups/statuspopup.cpp
+++ b/src/gui/popups/statuspopup.cpp
@@ -33,7 +33,7 @@
#include "utils/stringutils.h"
-#include <guichan/font.hpp>
+#include "gui/font.h"
#include "debug.h"
diff --git a/src/gui/popups/textpopup.cpp b/src/gui/popups/textpopup.cpp
index 9a7f1d3e4..d5cc918d3 100644
--- a/src/gui/popups/textpopup.cpp
+++ b/src/gui/popups/textpopup.cpp
@@ -25,7 +25,7 @@
#include "gui/widgets/label.h"
-#include <guichan/font.hpp>
+#include "gui/font.h"
#include "debug.h"
@@ -86,7 +86,7 @@ void TextPopup::show(const int x, const int y, const std::string &str1,
setHeight(pad2 + mText[0]->getFont()->getHeight() * cnt);
const int distance = 20;
- const gcn::Rectangle &rect = mDimension;
+ const Rect &rect = mDimension;
int posX = std::max(0, x - rect.width / 2);
int posY = y + distance;
@@ -100,7 +100,7 @@ void TextPopup::show(const int x, const int y, const std::string &str1,
requestMoveToTop();
}
-void TextPopup::mouseMoved(gcn::MouseEvent &event)
+void TextPopup::mouseMoved(MouseEvent &event)
{
Popup::mouseMoved(event);
diff --git a/src/gui/popups/textpopup.h b/src/gui/popups/textpopup.h
index 131921b7b..eb29cba61 100644
--- a/src/gui/popups/textpopup.h
+++ b/src/gui/popups/textpopup.h
@@ -72,7 +72,7 @@ class TextPopup final : public Popup
void show(const int x, const int y, const std::string &str1,
const std::string &str2, const std::string &str3);
- void mouseMoved(gcn::MouseEvent &mouseEvent) override final;
+ void mouseMoved(MouseEvent &mouseEvent) override final;
private:
Label *mText[TEXTPOPUPCOUNT];
diff --git a/src/gui/rect.cpp b/src/gui/rect.cpp
new file mode 100644
index 000000000..5f9d2bf0f
--- /dev/null
+++ b/src/gui/rect.cpp
@@ -0,0 +1,156 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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/rect.h"
+
+#include "debug.h"
+
+Rect::Rect() :
+ x(0),
+ y(0),
+ width(0),
+ height(0)
+{
+}
+
+Rect::Rect(const int x_, const int y_,
+ const int width_, const int height_) :
+ x(x_),
+ y(y_),
+ width(width_),
+ height(height_)
+{
+}
+
+void Rect::setAll(const int x0,
+ const int y0,
+ const int width0,
+ const int height0)
+{
+ x = x0;
+ y = y0;
+ width = width0;
+ height = height0;
+}
+
+bool Rect::isIntersecting(const Rect& rectangle) const
+{
+ int x_ = x;
+ int y_ = y;
+ int width_ = width;
+ int height_ = height;
+
+ x_ -= rectangle.x;
+ y_ -= rectangle.y;
+
+ if (x_ < 0)
+ {
+ width_ += x_;
+// x_ = 0;
+ }
+ else if (x_ + width_ > rectangle.width)
+ {
+ width_ = rectangle.width - x_;
+ }
+
+ if (y_ < 0)
+ {
+ height_ += y_;
+// y_ = 0;
+ }
+ else if (y_ + height_ > rectangle.height)
+ {
+ height_ = rectangle.height - y_;
+ }
+
+ if (width_ <= 0 || height_ <= 0)
+ {
+ return false;
+ }
+
+ return true;
+}
+
+bool Rect::isPointInRect(int x_, int y_) const
+{
+ return x_ >= x
+ && y_ >= y
+ && x_ < x + width
+ && y_ < y + height;
+}
+
+std::ostream& operator<<(std::ostream& out,
+ const Rect& rectangle)
+{
+ out << "Rect [x = " << rectangle.x
+ << ", y = " << rectangle.y
+ << ", width = " << rectangle.width
+ << ", height = " << rectangle.height
+ << "]";
+
+ return out;
+}
diff --git a/src/gui/rect.h b/src/gui/rect.h
new file mode 100644
index 000000000..69c0120ca
--- /dev/null
+++ b/src/gui/rect.h
@@ -0,0 +1,162 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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_RECT_H
+#define GUI_RECT_H
+
+#include <iostream>
+
+#include "localconsts.h"
+
+/**
+ * Represents a rectangle.
+ *
+ * @since 0.1.0
+ */
+class Rect
+{
+ public:
+ /**
+ * Constructor. The default rectangle is an empty rectangle
+ * at the coordinates (0,0).
+ */
+ Rect();
+
+ /**
+ * Constructor.
+ *
+ * @param x The x coordinate of the rectangle.
+ * @param y The y coordinate of the rectangle.
+ * @param width The width of the rectangle.
+ * @param height The height of the rectangle.
+ * @since 0.1.0
+ */
+ Rect(const int x, const int y, const int width, const int height);
+
+ virtual ~Rect()
+ { }
+
+ /**
+ * Sets the dimension of a rectangle.
+ *
+ * @param x The x coordinate of the rectangle.
+ * @param y The y coordinate of the rectangle.
+ * @param width The width of the rectangle.
+ * @param height The height of the rectangle.
+ * @since 0.1.0
+ */
+ void setAll(const int x,
+ const int y,
+ const int width0,
+ const int height0);
+
+ /**
+ * Checks if another rectangle intersects with the rectangle.
+ *
+ * @param rectangle Another rectangle to check for intersection.
+ * @return True if the rectangles intersect, false otherwise.
+ * @since 0.1.0
+ */
+ bool isIntersecting(const Rect& rectangle) const A_WARN_UNUSED;
+
+ /**
+ * Checks if a point is inside the rectangle
+ *
+ * @param x The x coordinate of the point.
+ * @param y The y coordinate of the point.
+ * @return True if the point is inside the rectangle.
+ * @since 0.1.0
+ */
+ bool isPointInRect(int x, int y) const A_WARN_UNUSED;
+
+ /**
+ * Output operator for output.
+ *
+ * @param out The stream to output to.
+ * @param rectangle The rectangle to output.
+ */
+ friend std::ostream& operator<<(std::ostream& out,
+ const Rect& rectangle);
+
+ /**
+ * Holds the x coordinate of the rectangle.
+ */
+ int x;
+
+ /**
+ * Holds the x coordinate of the rectangle.
+ */
+ int y;
+
+ /**
+ * Holds the width of the rectangle.
+ */
+ int width;
+
+ /**
+ * Holds the height of the rectangle.
+ */
+ int height;
+};
+
+#endif // GUI_RECT_H
diff --git a/src/gui/sdlfont_unittest.cc b/src/gui/sdlfont_unittest.cc
index eab4d2994..e0f536c01 100644
--- a/src/gui/sdlfont_unittest.cc
+++ b/src/gui/sdlfont_unittest.cc
@@ -20,7 +20,7 @@
#include "logger.h"
-#include "gui/sdlfont.h"
+#include "gui/font.h"
#include "gui/theme.h"
#include "gtest/gtest.h"
@@ -43,7 +43,7 @@ TEST(TextChunkList, add1)
TextChunkList list;
SDLTextChunk *chunk = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(2, 3, 4));
+ Color(1, 2, 3), Color(2, 3, 4));
list.insertFirst(chunk);
@@ -66,9 +66,9 @@ TEST(TextChunkList, add2)
TextChunkList list;
SDLTextChunk *chunk1 = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(3, 4, 5));
+ Color(1, 2, 3), Color(3, 4, 5));
SDLTextChunk *chunk2 = new SDLTextChunk("test",
- gcn::Color(2, 3, 4), gcn::Color(4, 5, 6));
+ Color(2, 3, 4), Color(4, 5, 6));
list.insertFirst(chunk2);
list.insertFirst(chunk1);
@@ -96,7 +96,7 @@ TEST(TextChunkList, addRemoveBack1)
TextChunkList list;
SDLTextChunk *chunk = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 3));
+ Color(1, 2, 3), Color(1, 2, 3));
list.insertFirst(chunk);
list.removeBack();
@@ -113,9 +113,9 @@ TEST(TextChunkList, addRemoveBack2)
TextChunkList list;
SDLTextChunk *chunk1 = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 3));
+ Color(1, 2, 3), Color(1, 2, 3));
SDLTextChunk *chunk2 = new SDLTextChunk("test2",
- gcn::Color(1, 2, 4), gcn::Color(1, 2, 5));
+ Color(1, 2, 4), Color(1, 2, 5));
list.insertFirst(chunk2);
list.insertFirst(chunk1);
@@ -140,9 +140,9 @@ TEST(TextChunkList, addRemoveBack3)
TextChunkList list;
SDLTextChunk *chunk1 = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 3));
+ Color(1, 2, 3), Color(1, 2, 3));
SDLTextChunk *chunk2 = new SDLTextChunk("test2",
- gcn::Color(2, 3, 4), gcn::Color(2, 3, 4));
+ Color(2, 3, 4), Color(2, 3, 4));
list.insertFirst(chunk2);
list.insertFirst(chunk1);
@@ -161,11 +161,11 @@ TEST(TextChunkList, addRemoveBack4)
TextChunkList list;
SDLTextChunk *chunk1 = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 3));
+ Color(1, 2, 3), Color(1, 2, 3));
SDLTextChunk *chunk2 = new SDLTextChunk("test2",
- gcn::Color(2, 3, 4), gcn::Color(2, 3, 4));
+ Color(2, 3, 4), Color(2, 3, 4));
SDLTextChunk *chunk3 = new SDLTextChunk("test",
- gcn::Color(3, 4, 5), gcn::Color(3, 4, 5));
+ Color(3, 4, 5), Color(3, 4, 5));
list.insertFirst(chunk3);
list.insertFirst(chunk2);
@@ -191,7 +191,7 @@ TEST(TextChunkList, moveToFirst1)
TextChunkList list;
SDLTextChunk *chunk = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(2, 3, 4));
+ Color(1, 2, 3), Color(2, 3, 4));
list.insertFirst(chunk);
list.moveToFirst(chunk);
@@ -208,9 +208,9 @@ TEST(TextChunkList, moveToFirst2)
TextChunkList list;
SDLTextChunk *chunk1 = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 3));
+ Color(1, 2, 3), Color(1, 2, 3));
SDLTextChunk *chunk2 = new SDLTextChunk("test",
- gcn::Color(2, 3, 4), gcn::Color(1, 2, 3));
+ Color(2, 3, 4), Color(1, 2, 3));
list.insertFirst(chunk1);
list.insertFirst(chunk2);
@@ -230,11 +230,11 @@ TEST(TextChunkList, moveToFirst3)
TextChunkList list;
SDLTextChunk *chunk1 = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 3));
+ Color(1, 2, 3), Color(1, 2, 3));
SDLTextChunk *chunk2 = new SDLTextChunk("test",
- gcn::Color(1, 2, 4), gcn::Color(1, 2, 3));
+ Color(1, 2, 4), Color(1, 2, 3));
SDLTextChunk *chunk3 = new SDLTextChunk("test",
- gcn::Color(1, 2, 5), gcn::Color(1, 2, 3));
+ Color(1, 2, 5), Color(1, 2, 3));
list.insertFirst(chunk3);
list.insertFirst(chunk1);
@@ -257,11 +257,11 @@ TEST(TextChunkList, moveToFirst4)
TextChunkList list;
SDLTextChunk *chunk1 = new SDLTextChunk("test",
- gcn::Color(), gcn::Color());
+ Color(), Color());
SDLTextChunk *chunk2 = new SDLTextChunk("test2",
- gcn::Color(), gcn::Color());
+ Color(), Color());
SDLTextChunk *chunk3 = new SDLTextChunk("test3",
- gcn::Color(), gcn::Color());
+ Color(), Color());
list.insertFirst(chunk1);
list.insertFirst(chunk3);
@@ -284,7 +284,7 @@ TEST(TextChunkList, clear1)
TextChunkList list;
int chunksLeft = sdlTextChunkCnt;
- SDLTextChunk *chunk = new SDLTextChunk("test", gcn::Color(), gcn::Color());
+ SDLTextChunk *chunk = new SDLTextChunk("test", Color(), Color());
list.insertFirst(chunk);
list.clear();
@@ -303,11 +303,11 @@ TEST(TextChunkList, clear2)
int chunksLeft = sdlTextChunkCnt;
SDLTextChunk *chunk1 = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(2, 0, 0));
+ Color(1, 2, 3), Color(2, 0, 0));
SDLTextChunk *chunk2 = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(2, 0, 1));
+ Color(1, 2, 3), Color(2, 0, 1));
SDLTextChunk *chunk3 = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(2, 0, 2));
+ Color(1, 2, 3), Color(2, 0, 2));
list.insertFirst(chunk1);
list.insertFirst(chunk2);
@@ -328,11 +328,11 @@ TEST(TextChunkList, clear3)
int chunksLeft = sdlTextChunkCnt;
SDLTextChunk *chunk1 = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(2, 0, 0));
+ Color(1, 2, 3), Color(2, 0, 0));
SDLTextChunk *chunk2 = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(2, 0, 1));
+ Color(1, 2, 3), Color(2, 0, 1));
SDLTextChunk *chunk3 = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(2, 0, 2));
+ Color(1, 2, 3), Color(2, 0, 2));
list.insertFirst(chunk1);
list.insertFirst(chunk2);
@@ -359,11 +359,11 @@ TEST(TextChunkList, clear4)
int chunksLeft = sdlTextChunkCnt;
SDLTextChunk *chunk1 = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(2, 0, 0));
+ Color(1, 2, 3), Color(2, 0, 0));
SDLTextChunk *chunk2 = new SDLTextChunk("test",
- gcn::Color(1, 2, 3), gcn::Color(2, 0, 1));
+ Color(1, 2, 3), Color(2, 0, 1));
SDLTextChunk *chunk3 = new SDLTextChunk("test3",
- gcn::Color(1, 2, 3), gcn::Color(2, 0, 2));
+ Color(1, 2, 3), Color(2, 0, 2));
list.insertFirst(chunk1);
list.insertFirst(chunk2);
@@ -387,11 +387,11 @@ TEST(TextChunkList, clear4)
TEST(TextChunkList, sort1)
{
SDLTextChunkSmall item1("test line1",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 3));
+ Color(1, 2, 3), Color(1, 2, 3));
SDLTextChunkSmall item2("test line1",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 3));
+ Color(1, 2, 3), Color(1, 2, 3));
SDLTextChunkSmall item3("test line2",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 3));
+ Color(1, 2, 3), Color(1, 2, 3));
EXPECT_EQ(false, item1 < item2);
EXPECT_EQ(false, item2 < item1);
EXPECT_EQ(true, item1 < item3);
@@ -401,9 +401,9 @@ TEST(TextChunkList, sort1)
TEST(TextChunkList, sort2)
{
SDLTextChunkSmall item1("test line1",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 3));
+ Color(1, 2, 3), Color(1, 2, 3));
SDLTextChunkSmall item2("test line1",
- gcn::Color(2, 3, 4), gcn::Color(1, 2, 3));
+ Color(2, 3, 4), Color(1, 2, 3));
EXPECT_EQ(true, item1 < item2);
EXPECT_EQ(false, item2 < item1);
}
@@ -411,9 +411,9 @@ TEST(TextChunkList, sort2)
TEST(TextChunkList, sort3)
{
SDLTextChunkSmall item1("test line1",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 3));
+ Color(1, 2, 3), Color(1, 2, 3));
SDLTextChunkSmall item2("test line1",
- gcn::Color(1, 3, 4), gcn::Color(1, 2, 3));
+ Color(1, 3, 4), Color(1, 2, 3));
EXPECT_EQ(true, item1 < item2);
EXPECT_EQ(false, item2 < item1);
}
@@ -421,9 +421,9 @@ TEST(TextChunkList, sort3)
TEST(TextChunkList, sort4)
{
SDLTextChunkSmall item1("test line1",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 3));
+ Color(1, 2, 3), Color(1, 2, 3));
SDLTextChunkSmall item2("test line1",
- gcn::Color(1, 2, 4), gcn::Color(1, 2, 3));
+ Color(1, 2, 4), Color(1, 2, 3));
EXPECT_EQ(true, item1 < item2);
EXPECT_EQ(false, item2 < item1);
}
@@ -431,9 +431,9 @@ TEST(TextChunkList, sort4)
TEST(TextChunkList, sort5)
{
SDLTextChunkSmall item1("test line1",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 3));
+ Color(1, 2, 3), Color(1, 2, 3));
SDLTextChunkSmall item2("test line1",
- gcn::Color(1, 2, 3), gcn::Color(2, 2, 3));
+ Color(1, 2, 3), Color(2, 2, 3));
EXPECT_EQ(true, item1 < item2);
EXPECT_EQ(false, item2 < item1);
}
@@ -441,9 +441,9 @@ TEST(TextChunkList, sort5)
TEST(TextChunkList, sort6)
{
SDLTextChunkSmall item1("test line1",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 3));
+ Color(1, 2, 3), Color(1, 2, 3));
SDLTextChunkSmall item2("test line1",
- gcn::Color(1, 2, 3), gcn::Color(1, 3, 3));
+ Color(1, 2, 3), Color(1, 3, 3));
EXPECT_EQ(true, item1 < item2);
EXPECT_EQ(false, item2 < item1);
}
@@ -451,9 +451,9 @@ TEST(TextChunkList, sort6)
TEST(TextChunkList, sort7)
{
SDLTextChunkSmall item1("test line1",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 3));
+ Color(1, 2, 3), Color(1, 2, 3));
SDLTextChunkSmall item2("test line1",
- gcn::Color(1, 2, 3), gcn::Color(1, 2, 4));
+ Color(1, 2, 3), Color(1, 2, 4));
EXPECT_EQ(true, item1 < item2);
EXPECT_EQ(false, item2 < item1);
}
diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp
index 193a35dfe..ffb90a883 100644
--- a/src/gui/sdlinput.cpp
+++ b/src/gui/sdlinput.cpp
@@ -75,12 +75,12 @@
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "gui/sdlinput.h"
-
#include "sdlshared.h"
#include "input/inputmanager.h"
+#include "gui/sdlinput.h"
+
#include "render/graphics.h"
#ifdef USE_SDL2
@@ -90,8 +90,6 @@
#include <SDL_keyboard.h>
#include <SDL_timer.h>
-#include <guichan/exception.hpp>
-
SDLInput::SDLInput() :
mKeyInputQueue(),
mMouseInputQueue(),
@@ -100,7 +98,7 @@ SDLInput::SDLInput() :
{
}
-bool SDLInput::isKeyQueueEmpty()
+bool SDLInput::isKeyQueueEmpty() const
{
return mKeyInputQueue.empty();
}
@@ -108,9 +106,7 @@ bool SDLInput::isKeyQueueEmpty()
KeyInput SDLInput::dequeueKeyInput2()
{
if (mKeyInputQueue.empty())
- {
- throw GCN_EXCEPTION("The queue is empty.");
- }
+ return KeyInput();
KeyInput keyInput = mKeyInputQueue.front();
mKeyInputQueue.pop();
@@ -118,17 +114,17 @@ KeyInput SDLInput::dequeueKeyInput2()
return keyInput;
}
-bool SDLInput::isMouseQueueEmpty()
+bool SDLInput::isMouseQueueEmpty() const
{
return mMouseInputQueue.empty();
}
-gcn::MouseInput SDLInput::dequeueMouseInput()
+MouseInput SDLInput::dequeueMouseInput()
{
- gcn::MouseInput mouseInput;
+ MouseInput mouseInput;
if (mMouseInputQueue.empty())
- throw GCN_EXCEPTION("The queue is empty.");
+ return MouseInput();
mouseInput = mMouseInputQueue.front();
mMouseInputQueue.pop();
@@ -141,7 +137,7 @@ MouseInput SDLInput::dequeueMouseInput2()
MouseInput mouseInput;
if (mMouseInputQueue.empty())
- throw GCN_EXCEPTION("The queue is empty.");
+ return MouseInput();
mouseInput = mMouseInputQueue.front();
mMouseInputQueue.pop();
@@ -158,7 +154,7 @@ void SDLInput::pushInput(const SDL_Event &event)
{
case SDL_KEYDOWN:
{
- keyInput.setType(gcn::KeyInput::PRESSED);
+ keyInput.setType(KeyInput::PRESSED);
convertKeyEventToKey(event, keyInput);
mKeyInputQueue.push(keyInput);
break;
@@ -166,7 +162,7 @@ void SDLInput::pushInput(const SDL_Event &event)
case SDL_KEYUP:
{
- keyInput.setType(gcn::KeyInput::RELEASED);
+ keyInput.setType(KeyInput::RELEASED);
convertKeyEventToKey(event, keyInput);
mKeyInputQueue.push(keyInput);
break;
@@ -174,8 +170,8 @@ void SDLInput::pushInput(const SDL_Event &event)
#ifdef USE_SDL2
case SDL_TEXTINPUT:
- keyInput.setType(gcn::KeyInput::PRESSED);
- keyInput.setKey(gcn::Key(Key::TEXTINPUT));
+ keyInput.setType(KeyInput::PRESSED);
+ keyInput.setKey(Key(Key::TEXTINPUT));
keyInput.setText(event.text.text);
mKeyInputQueue.push(keyInput);
break;
@@ -193,9 +189,9 @@ void SDLInput::pushInput(const SDL_Event &event)
#endif
mouseInput.setButton(-1);
if (y > 0)
- mouseInput.setType(gcn::MouseInput::WHEEL_MOVED_UP);
+ mouseInput.setType(MouseInput::WHEEL_MOVED_UP);
else
- mouseInput.setType(gcn::MouseInput::WHEEL_MOVED_DOWN);
+ mouseInput.setType(MouseInput::WHEEL_MOVED_DOWN);
mouseInput.setTimeStamp(SDL_GetTicks());
mMouseInputQueue.push(mouseInput);
}
@@ -231,12 +227,12 @@ void SDLInput::pushInput(const SDL_Event &event)
#ifndef USE_SDL2
if (event.button.button == SDL_BUTTON_WHEELDOWN)
- mouseInput.setType(gcn::MouseInput::WHEEL_MOVED_DOWN);
+ mouseInput.setType(MouseInput::WHEEL_MOVED_DOWN);
else if (event.button.button == SDL_BUTTON_WHEELUP)
- mouseInput.setType(gcn::MouseInput::WHEEL_MOVED_UP);
+ mouseInput.setType(MouseInput::WHEEL_MOVED_UP);
else
#endif
- mouseInput.setType(gcn::MouseInput::PRESSED);
+ mouseInput.setType(MouseInput::PRESSED);
mouseInput.setTimeStamp(SDL_GetTicks());
mMouseInputQueue.push(mouseInput);
break;
@@ -258,7 +254,7 @@ void SDLInput::pushInput(const SDL_Event &event)
#endif
#endif
mouseInput.setButton(convertMouseButton(event.button.button));
- mouseInput.setType(gcn::MouseInput::RELEASED);
+ mouseInput.setType(MouseInput::RELEASED);
mouseInput.setTimeStamp(SDL_GetTicks());
mMouseInputQueue.push(mouseInput);
break;
@@ -278,8 +274,8 @@ void SDLInput::pushInput(const SDL_Event &event)
event.motion.realy / scale);
#endif
#endif
- mouseInput.setButton(gcn::MouseInput::EMPTY);
- mouseInput.setType(gcn::MouseInput::MOVED);
+ mouseInput.setButton(MouseInput::EMPTY);
+ mouseInput.setType(MouseInput::MOVED);
mouseInput.setTimeStamp(SDL_GetTicks());
mMouseInputQueue.push(mouseInput);
break;
@@ -299,8 +295,8 @@ void SDLInput::pushInput(const SDL_Event &event)
{
mouseInput.setX(-1);
mouseInput.setY(-1);
- mouseInput.setButton(gcn::MouseInput::EMPTY);
- mouseInput.setType(gcn::MouseInput::MOVED);
+ mouseInput.setButton(MouseInput::EMPTY);
+ mouseInput.setType(MouseInput::MOVED);
mMouseInputQueue.push(mouseInput);
}
}
@@ -319,7 +315,7 @@ void SDLInput::pushInput(const SDL_Event &event)
void SDLInput::convertKeyEventToKey(const SDL_Event &event, KeyInput &keyInput)
{
- keyInput.setKey(gcn::Key(convertKeyCharacter(event)));
+ keyInput.setKey(Key(convertKeyCharacter(event)));
keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT);
keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL);
keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT);
@@ -342,11 +338,11 @@ int SDLInput::convertMouseButton(const int button)
switch (button)
{
case SDL_BUTTON_LEFT:
- return gcn::MouseInput::LEFT;
+ return MouseInput::LEFT;
case SDL_BUTTON_RIGHT:
- return gcn::MouseInput::RIGHT;
+ return MouseInput::RIGHT;
case SDL_BUTTON_MIDDLE:
- return gcn::MouseInput::MIDDLE;
+ return MouseInput::MIDDLE;
default:
// We have an unknown mouse type which is ignored.
return button;
@@ -573,10 +569,10 @@ void SDLInput::simulateMouseClick(const int x, const int y,
mouseInput.setY(y);
mouseInput.setReal(x, y);
mouseInput.setButton(button);
- mouseInput.setType(gcn::MouseInput::PRESSED);
+ mouseInput.setType(MouseInput::PRESSED);
mouseInput.setTimeStamp(SDL_GetTicks());
mMouseInputQueue.push(mouseInput);
- mouseInput.setType(gcn::MouseInput::RELEASED);
+ mouseInput.setType(MouseInput::RELEASED);
mouseInput.setTimeStamp(SDL_GetTicks());
mMouseInputQueue.push(mouseInput);
}
diff --git a/src/gui/sdlinput.h b/src/gui/sdlinput.h
index b07a57a00..8197aa110 100644
--- a/src/gui/sdlinput.h
+++ b/src/gui/sdlinput.h
@@ -80,75 +80,16 @@
#include "input/keyinput.h"
-#include "mouseinput.h"
-
#include <SDL_events.h>
-#include <guichan/input.hpp>
-#include <guichan/keyinput.hpp>
-#include <guichan/mouseinput.hpp>
+#include "input/mouseinput.h"
#include <queue>
-namespace Key
-{
- enum
- {
- SPACE = ' ',
- TAB = '\t',
- ENTER = '\n',
- // Negative values, to avoid conflicts with higher character codes.
- LEFT_ALT = -1000,
- RIGHT_ALT,
- LEFT_SHIFT,
- RIGHT_SHIFT,
- LEFT_CONTROL,
- RIGHT_CONTROL,
- LEFT_META,
- RIGHT_META,
- LEFT_SUPER,
- RIGHT_SUPER,
- INSERT,
- HOME,
- PAGE_UP,
- DELETE_,
- END,
- PAGE_DOWN,
- ESCAPE,
- CAPS_LOCK,
- BACKSPACE,
- F1,
- F2,
- F3,
- F4,
- F5,
- F6,
- F7,
- F8,
- F9,
- F10,
- F11,
- F12,
- F13,
- F14,
- F15,
- PRINT_SCREEN,
- SCROLL_LOCK,
- PAUSE,
- NUM_LOCK,
- ALT_GR,
- LEFT,
- RIGHT,
- UP,
- DOWN,
- TEXTINPUT
- };
-} // namespace Key
-
/**
- * SDL implementation of Input.
+ * SDL implementation of SDLInput.
*/
-class SDLInput final : public gcn::Input
+class SDLInput final
{
public:
/**
@@ -166,26 +107,18 @@ public:
*/
void pushInput(const SDL_Event &event);
- /**
- * Polls all input. It exists for input driver compatibility. If you
- * only use SDL and plan sticking with SDL you can safely ignore this
- * function as it in the SDL case does nothing.
- */
- void _pollInput() override final
- { }
-
KeyInput dequeueKeyInput2() A_WARN_UNUSED;
- gcn::KeyInput dequeueKeyInput() override final A_WARN_UNUSED
- { return gcn::KeyInput(); }
+ KeyInput dequeueKeyInput() A_WARN_UNUSED
+ { return KeyInput(); }
- // Inherited from Input
+ // Inherited from SDLInput
- bool isKeyQueueEmpty() override final A_WARN_UNUSED;
+ bool isKeyQueueEmpty() const A_WARN_UNUSED;
- bool isMouseQueueEmpty() override final A_WARN_UNUSED;
+ bool isMouseQueueEmpty() const A_WARN_UNUSED;
- gcn::MouseInput dequeueMouseInput() override final A_WARN_UNUSED;
+ MouseInput dequeueMouseInput() A_WARN_UNUSED;
MouseInput dequeueMouseInput2() A_WARN_UNUSED;
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index 4218aff7c..1a504f680 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -259,7 +259,7 @@ void Theme::deleteInstance()
mInstance = nullptr;
}
-gcn::Color Theme::getProgressColor(const int type, const float progress)
+Color Theme::getProgressColor(const int type, const float progress)
{
int color[3] = {0, 0, 0};
@@ -273,7 +273,7 @@ gcn::Color Theme::getProgressColor(const int type, const float progress)
logger->log("color not found: " + toString(type));
}
- return gcn::Color(color[0], color[1], color[2]);
+ return Color(color[0], color[1], color[2]);
}
Skin *Theme::load(const std::string &filename, const std::string &filename2,
@@ -972,7 +972,7 @@ static int readColorType(const std::string &type)
return -1;
}
-static gcn::Color readColor(const std::string &description)
+static Color readColor(const std::string &description)
{
const int size = static_cast<const int>(description.length());
if (size < 7 || description[0] != '#')
@@ -982,7 +982,7 @@ static gcn::Color readColor(const std::string &description)
return Palette::BLACK;
}
- int v = 0;
+ unsigned int v = 0;
for (int i = 1; i < 7; ++i)
{
signed const char c = description[i];
@@ -1010,7 +1010,7 @@ static gcn::Color readColor(const std::string &description)
v = (v << 4) | n;
}
- return gcn::Color(v);
+ return Color(v);
}
static Palette::GradientType readColorGradient(const std::string &grad)
@@ -1084,7 +1084,7 @@ void Theme::loadColors(std::string file)
int type;
std::string temp;
- gcn::Color color;
+ Color color;
GradientType grad;
for_each_xml_child_node(paletteNode, root)
diff --git a/src/gui/theme.h b/src/gui/theme.h
index b40be2881..86543ea64 100644
--- a/src/gui/theme.h
+++ b/src/gui/theme.h
@@ -25,7 +25,7 @@
#ifndef GUI_THEME_H
#define GUI_THEME_H
-#include "configlistener.h"
+#include "listeners/configlistener.h"
#include "render/graphics.h"
@@ -450,21 +450,21 @@ class Theme final : public Palette, public ConfigListener
*
* @return the requested color
*/
- inline static const gcn::Color &getThemeColor(const int type,
- const int alpha = 255)
- A_WARN_UNUSED
+ inline static const Color &getThemeColor(const int type,
+ const int alpha = 255)
+ A_WARN_UNUSED
{ return mInstance->getColor(type, alpha); }
- static const gcn::Color &getThemeCharColor(const signed char c,
- bool &valid) A_WARN_UNUSED
+ static const Color &getThemeCharColor(const signed char c,
+ bool &valid) A_WARN_UNUSED
{ return mInstance->getCharColor(c, valid); }
static int getThemeIdByChar(const signed char c,
bool &valid) A_WARN_UNUSED
{ return mInstance->getIdByChar(c, valid); }
- static gcn::Color getProgressColor(const int type,
- const float progress) A_WARN_UNUSED;
+ static Color getProgressColor(const int type,
+ const float progress) A_WARN_UNUSED;
/**
* Loads a skin.
diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp
index 69125f8e2..74d47203f 100644
--- a/src/gui/userpalette.cpp
+++ b/src/gui/userpalette.cpp
@@ -237,7 +237,7 @@ UserPalette::~UserPalette()
void UserPalette::setColor(const int type, const int r,
const int g, const int b)
{
- gcn::Color &color = mColors[type].color;
+ Color &color = mColors[type].color;
color.r = r;
color.g = g;
color.b = b;
@@ -296,14 +296,14 @@ void UserPalette::rollback()
if (i->grad != i->committedGrad)
setGradient(i->type, i->committedGrad);
- const gcn::Color &committedColor = i->committedColor;
+ const Color &committedColor = i->committedColor;
setGradientDelay(i->type, i->committedDelay);
setColor(i->type, committedColor.r,
committedColor.g, committedColor.b);
if (i->grad == PULSE)
{
- gcn::Color &testColor = i->testColor;
+ Color &testColor = i->testColor;
testColor.r = committedColor.r;
testColor.g = committedColor.g;
testColor.b = committedColor.b;
@@ -342,7 +342,7 @@ void UserPalette::addColor(const unsigned type, const unsigned rgb,
rgbValue = atox(rgbString);
else
rgbValue = atoi(rgbString.c_str());
- const gcn::Color &trueCol = gcn::Color(rgbValue);
+ const Color &trueCol = Color(rgbValue);
grad = static_cast<GradientType>(config.getValue(configName + "Gradient",
static_cast<int>(grad)));
delay = config.getValueInt(configName + "Delay", delay);
diff --git a/src/gui/userpalette.h b/src/gui/userpalette.h
index 18fe1cbe2..7bab5bed9 100644
--- a/src/gui/userpalette.h
+++ b/src/gui/userpalette.h
@@ -26,12 +26,12 @@
#include "gui/palette.h"
-#include <guichan/listmodel.hpp>
+#include "gui/models/listmodel.h"
/**
* Class controlling the game's color palette.
*/
-class UserPalette final : public Palette, public gcn::ListModel
+class UserPalette final : public Palette, public ListModel
{
public:
/** List of all colors that are configurable. */
@@ -100,8 +100,8 @@ class UserPalette final : public Palette, public gcn::ListModel
*
* @return the requested committed color
*/
- inline const gcn::Color &getCommittedColor(const int type)
- const A_WARN_UNUSED
+ inline const Color &getCommittedColor(const int type)
+ const A_WARN_UNUSED
{
return mColors[type].committedColor;
}
@@ -113,8 +113,7 @@ class UserPalette final : public Palette, public gcn::ListModel
*
* @return the requested test color
*/
- inline const gcn::Color &getTestColor(const int type)
- const A_WARN_UNUSED
+ inline const Color &getTestColor(const int type) const A_WARN_UNUSED
{ return mColors[type].testColor; }
/**
@@ -123,7 +122,7 @@ class UserPalette final : public Palette, public gcn::ListModel
* @param type the color type requested
* @param color the color that should be tested
*/
- inline void setTestColor(const int type, const gcn::Color &color)
+ inline void setTestColor(const int type, const Color &color)
{ mColors[type].testColor = color; }
/**
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index 341af1f0b..96760f8c7 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -42,7 +42,7 @@
#include "gui/windows/ministatuswindow.h"
-#include <guichan/font.hpp>
+#include "gui/font.h"
#include "debug.h"
@@ -51,7 +51,7 @@ extern MiniStatusWindow *miniStatusWindow;
Viewport::Viewport() :
WindowContainer(nullptr),
- gcn::MouseListener(),
+ MouseListener(),
mMap(nullptr),
mScrollRadius(config.getIntValue("ScrollRadius")),
mScrollLaziness(config.getIntValue("ScrollLaziness")),
@@ -114,22 +114,20 @@ void Viewport::setMap(Map *const map)
mMap = map;
}
-void Viewport::draw(gcn::Graphics *gcnGraphics)
+void Viewport::draw(Graphics *graphics)
{
BLOCK_START("Viewport::draw 1")
static int lastTick = tick_time;
if (!mMap || !player_node)
{
- gcnGraphics->setColor(gcn::Color(64, 64, 64));
- gcnGraphics->fillRectangle(
- gcn::Rectangle(0, 0, getWidth(), getHeight()));
+ graphics->setColor(Color(64, 64, 64));
+ graphics->fillRectangle(
+ Rect(0, 0, getWidth(), getHeight()));
BLOCK_END("Viewport::draw 1")
return;
}
- Graphics *const graphics = static_cast<Graphics* const>(gcnGraphics);
-
// Avoid freaking out when tick_time overflows
if (tick_time < lastTick)
lastTick = tick_time;
@@ -260,7 +258,7 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
miniStatusWindow->drawIcons(graphics);
// Draw contained widgets
- WindowContainer::draw(gcnGraphics);
+ WindowContainer::draw(graphics);
BLOCK_END("Viewport::draw 1")
}
@@ -282,13 +280,13 @@ void Viewport::_followMouse()
if (mPlayerFollowMouse && (button & SDL_BUTTON(1)))
{
// We create a mouse event and send it to mouseDragged.
- gcn::MouseEvent mouseEvent(nullptr,
+ MouseEvent mouseEvent(nullptr,
0,
false,
false,
false,
- gcn::MouseEvent::DRAGGED,
- gcn::MouseEvent::LEFT,
+ MouseEvent::DRAGGED,
+ MouseEvent::LEFT,
mMouseX,
mMouseY,
0);
@@ -340,54 +338,29 @@ void Viewport::_drawDebugPath(Graphics *const graphics)
}
void Viewport::_drawPath(Graphics *const graphics, const Path &path,
- const gcn::Color &color) const
+ const Color &color) const
{
graphics->setColor(color);
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
-#ifdef MANASERV_SUPPORT
- if (Net::getNetworkType() != ServerInfo::MANASERV)
-#endif
+ int cnt = 1;
+ FOR_EACH (Path::const_iterator, i, path)
{
- int cnt = 1;
- FOR_EACH (Path::const_iterator, i, path)
- {
- const int squareX = i->x * mapTileSize - mPixelViewX + 12;
- const int squareY = i->y * mapTileSize - mPixelViewY + 12;
+ const int squareX = i->x * mapTileSize - mPixelViewX + 12;
+ const int squareY = i->y * mapTileSize - mPixelViewY + 12;
- graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8));
- if (mMap)
- {
- const std::string str = toString(cnt);
- font->drawString(graphics, str, squareX + 4
- - font->getWidth(str) / 2, squareY + 12);
- }
- cnt ++;
- }
- }
-#ifdef MANASERV_SUPPORT
- else if (Net::getNetworkType() == ServerInfo::MANASERV)
- {
- FOR_EACH (Path::const_iterator, i, path)
+ graphics->fillRectangle(Rect(squareX, squareY, 8, 8));
+ if (mMap)
{
- const int squareX = i->x - mPixelViewX;
- const int squareY = i->y - mPixelViewY;
-
- graphics->fillRectangle(gcn::Rectangle(squareX - 4, squareY - 4,
- 8, 8));
- if (mMap)
- {
- const std::string str = toString(mMap->getMetaTile(
- i->x / mapTileSize, i->y / mapTileSize)->Gcost);
- font->drawString(graphics, str,
- squareX + 4 - font->getWidth(text) / 2, squareY + 12);
- }
+ const std::string str = toString(cnt);
+ font->drawString(graphics, str, squareX + 4
+ - font->getWidth(str) / 2, squareY + 12);
}
+ cnt ++;
}
-#endif
}
-void Viewport::mousePressed(gcn::MouseEvent &event)
+void Viewport::mousePressed(MouseEvent &event)
{
if (event.getSource() != this)
return;
@@ -408,7 +381,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
const int pixelY = eventY + mPixelViewY;
// Right click might open a popup
- if (eventButton == gcn::MouseEvent::RIGHT)
+ if (eventButton == MouseEvent::RIGHT)
{
mPlayerFollowMouse = false;
if (mHoverBeing)
@@ -462,7 +435,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
}
// Left click can cause different actions
- if (eventButton == gcn::MouseEvent::LEFT)
+ if (eventButton == MouseEvent::LEFT)
{
// Interact with some being
if (mHoverBeing)
@@ -534,7 +507,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
_followMouse();
}
}
- else if (eventButton == gcn::MouseEvent::MIDDLE)
+ else if (eventButton == MouseEvent::MIDDLE)
{
mPlayerFollowMouse = false;
validateSpeed();
@@ -550,7 +523,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
}
}
-void Viewport::mouseDragged(gcn::MouseEvent &event)
+void Viewport::mouseDragged(MouseEvent &event)
{
if (!mMap || !player_node)
return;
@@ -559,127 +532,111 @@ void Viewport::mouseDragged(gcn::MouseEvent &event)
Input::KEY_STOP_ATTACK) && !inputManager.isActionActive(
Input::KEY_UNTARGET))
{
-#ifdef MANASERV_SUPPORT
- if (Net::getNetworkType() == ServerInfo::MANASERV)
+ if (mLocalWalkTime != player_node->getActionTime())
{
- if (get_elapsed_time(mLocalWalkTime) >= walkingMouseDelay)
+ mLocalWalkTime = cur_time;
+ player_node->unSetPickUpTarget();
+ int playerX = player_node->getTileX();
+ int playerY = player_node->getTileY();
+ if (mMouseDirectionMove)
{
- mLocalWalkTime = tick_time;
- player_node->unSetPickUpTarget();
- player_node->setDestination(event.getX() + mPixelViewX,
- event.getY() + mPixelViewY);
- player_node->pathSetByMouse();
- }
- }
- else
-#endif
- {
- if (mLocalWalkTime != player_node->getActionTime())
- {
- mLocalWalkTime = cur_time;
- player_node->unSetPickUpTarget();
- int playerX = player_node->getTileX();
- int playerY = player_node->getTileY();
- if (mMouseDirectionMove)
+ const int width = mainGraphics->mWidth / 2;
+ const int height = mainGraphics->mHeight / 2;
+ const float wh = static_cast<float>(width)
+ / static_cast<float>(height);
+ int x = event.getX() - width;
+ int y = event.getY() - height;
+ if (!x && !y)
+ return;
+ const int x2 = abs(x);
+ const int y2 = abs(y);
+ const float diff = 2;
+ int dx = 0;
+ int dy = 0;
+ if (x2 > y2)
{
- const int width = mainGraphics->mWidth / 2;
- const int height = mainGraphics->mHeight / 2;
- const float wh = static_cast<float>(width)
- / static_cast<float>(height);
- int x = event.getX() - width;
- int y = event.getY() - height;
- if (!x && !y)
- return;
- const int x2 = abs(x);
- const int y2 = abs(y);
- const float diff = 2;
- int dx = 0;
- int dy = 0;
- if (x2 > y2)
- {
- if (y2 && x2 / y2 / wh > diff)
- y = 0;
- }
- else
- {
- if (x2 && y2 * wh / x2 > diff)
- x = 0;
- }
- if (x > 0)
- dx = 1;
- else if (x < 0)
- dx = -1;
- if (y > 0)
- dy = 1;
- else if (y < 0)
- dy = -1;
-
- if (mMap->getWalk(playerX + dx, playerY + dy))
+ if (y2 && x2 / y2 / wh > diff)
+ y = 0;
+ }
+ else
+ {
+ if (x2 && y2 * wh / x2 > diff)
+ x = 0;
+ }
+ if (x > 0)
+ dx = 1;
+ else if (x < 0)
+ dx = -1;
+ if (y > 0)
+ dy = 1;
+ else if (y < 0)
+ dy = -1;
+
+ if (mMap->getWalk(playerX + dx, playerY + dy))
+ {
+ player_node->navigateTo(playerX + dx, playerY + dy);
+ }
+ else
+ {
+ if (dx && dy)
{
- player_node->navigateTo(playerX + dx, playerY + dy);
+ // try avoid diagonal collision
+ if (x2 > y2)
+ {
+ if (mMap->getWalk(playerX + dx, playerY))
+ dy = 0;
+ else
+ dx = 0;
+ }
+ else
+ {
+ if (mMap->getWalk(playerX, playerY + dy))
+ dx = 0;
+ else
+ dy = 0;
+ }
}
else
{
- if (dx && dy)
+ // try avoid vertical or horisontal collision
+ if (!dx)
{
- // try avoid diagonal collision
- if (x2 > y2)
- {
- if (mMap->getWalk(playerX + dx, playerY))
- dy = 0;
- else
- dx = 0;
- }
- else
- {
- if (mMap->getWalk(playerX, playerY + dy))
- dx = 0;
- else
- dy = 0;
- }
+ if (mMap->getWalk(playerX + 1, playerY + dy))
+ dx = 1;
+ if (mMap->getWalk(playerX - 1, playerY + dy))
+ dx = -1;
}
- else
+ if (!dy)
{
- // try avoid vertical or horisontal collision
- if (!dx)
- {
- if (mMap->getWalk(playerX + 1, playerY + dy))
- dx = 1;
- if (mMap->getWalk(playerX - 1, playerY + dy))
- dx = -1;
- }
- if (!dy)
- {
- if (mMap->getWalk(playerX + dx, playerY + 1))
- dy = 1;
- if (mMap->getWalk(playerX + dx, playerY - 1))
- dy = -1;
- }
+ if (mMap->getWalk(playerX + dx, playerY + 1))
+ dy = 1;
+ if (mMap->getWalk(playerX + dx, playerY - 1))
+ dy = -1;
}
- player_node->navigateTo(playerX + dx, playerY + dy);
}
+ player_node->navigateTo(playerX + dx, playerY + dy);
}
- else
+ }
+ else
+ {
+ const int destX = (event.getX() + mPixelViewX)
+ / static_cast<float>(mMap->getTileWidth());
+ const int destY = (event.getY() + mPixelViewY)
+ / static_cast<float>(mMap->getTileHeight());
+ if (playerX != destX || playerY != destY)
{
- const int destX = (event.getX() + mPixelViewX)
- / static_cast<float>(mMap->getTileWidth());
- const int destY = (event.getY() + mPixelViewY)
- / static_cast<float>(mMap->getTileHeight());
- if (playerX != destX || playerY != destY)
+ if (!player_node->navigateTo(destX, destY))
{
- if (!player_node->navigateTo(destX, destY))
- {
- if (playerX > destX)
- playerX --;
- else if (playerX < destX)
- playerX ++;
- if (playerY > destY)
- playerY --;
- else if (playerY < destY)
- playerY ++;
- if (mMap->getWalk(playerX, playerY, 0))
- player_node->navigateTo(playerX, playerY);
- }
+ if (playerX > destX)
+ playerX --;
+ else if (playerX < destX)
+ playerX ++;
+ if (playerY > destY)
+ playerY --;
+ else if (playerY < destY)
+ playerY ++;
+ if (mMap->getWalk(playerX, playerY, 0))
+ player_node->navigateTo(playerX, playerY);
}
}
}
@@ -687,10 +644,9 @@ void Viewport::mouseDragged(gcn::MouseEvent &event)
}
}
-void Viewport::mouseReleased(gcn::MouseEvent &event A_UNUSED)
+void Viewport::mouseReleased(MouseEvent &event A_UNUSED)
{
mPlayerFollowMouse = false;
- // Only useful for eAthena but doesn't hurt under ManaServ
mLocalWalkTime = -1;
}
@@ -840,7 +796,7 @@ void Viewport::optionChanged(const std::string &name)
mMouseDirectionMove = config.getBoolValue("mouseDirectionMove");
}
-void Viewport::mouseMoved(gcn::MouseEvent &event A_UNUSED)
+void Viewport::mouseMoved(MouseEvent &event A_UNUSED)
{
// Check if we are on the map
if (!mMap || !player_node || !actorManager)
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index dcddc003c..16d0e4e34 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -23,12 +23,13 @@
#ifndef GUI_VIEWPORT_H
#define GUI_VIEWPORT_H
-#include "configlistener.h"
#include "position.h"
+#include "listeners/configlistener.h"
+
#include "gui/widgets/windowcontainer.h"
-#include <guichan/mouselistener.hpp>
+#include "listeners/mouselistener.h"
class ActorSprite;
class Button;
@@ -59,7 +60,7 @@ const int walkingMouseDelay = 500;
* coordinates.
*/
class Viewport final : public WindowContainer,
- public gcn::MouseListener,
+ public MouseListener,
public ConfigListener
{
public:
@@ -83,7 +84,7 @@ class Viewport final : public WindowContainer,
/**
* Draws the viewport.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
/**
* Implements player to keep following mouse.
@@ -102,22 +103,22 @@ class Viewport final : public WindowContainer,
/**
* Handles mouse press on map.
*/
- void mousePressed(gcn::MouseEvent &event) override final;
+ void mousePressed(MouseEvent &event) override final;
/**
* Handles mouse move on map
*/
- void mouseDragged(gcn::MouseEvent &event) override final;
+ void mouseDragged(MouseEvent &event) override final;
/**
* Handles mouse button release on map.
*/
- void mouseReleased(gcn::MouseEvent &event) override final;
+ void mouseReleased(MouseEvent &event) override final;
/**
* Handles mouse move on map.
*/
- void mouseMoved(gcn::MouseEvent &event) override final;
+ void mouseMoved(MouseEvent &event) override final;
/**
* Shows a popup for an item.
@@ -297,7 +298,7 @@ class Viewport final : public WindowContainer,
* Draws the given path.
*/
void _drawPath(Graphics *const graphics, const Path &path,
- const gcn::Color &color = gcn::Color(255, 0, 0)) const;
+ const Color &color = Color(255, 0, 0)) const;
/**
* Make the player go to the mouse position.
diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp
index b676a7e94..01126f8ac 100644
--- a/src/gui/widgets/avatarlistbox.cpp
+++ b/src/gui/widgets/avatarlistbox.cpp
@@ -28,16 +28,16 @@
#include "being/localplayer.h"
+#include "gui/font.h"
#include "gui/gui.h"
-#include "gui/sdlfont.h"
#include "gui/viewport.h"
+#include "gui/models/avatarlistmodel.h"
+
#include "gui/windows/chatwindow.h"
#include "resources/image.h"
-#include <guichan/font.hpp>
-
#include "debug.h"
int AvatarListBox::instances = 0;
@@ -90,7 +90,7 @@ AvatarListBox::~AvatarListBox()
}
}
-void AvatarListBox::draw(gcn::Graphics *gcnGraphics)
+void AvatarListBox::draw(Graphics *graphics)
{
BLOCK_START("AvatarListBox::draw")
if (!mListModel || !player_node)
@@ -102,12 +102,10 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics)
AvatarListModel *const model = static_cast<AvatarListModel *const>(
mListModel);
updateAlpha();
- Graphics *const graphics = static_cast<Graphics *const>(gcnGraphics);
-
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
const int fontHeight = getFont()->getHeight();
- const gcn::Widget *const parent = mParent;
+ const Widget *const parent = mParent;
const std::string name = player_node->getName();
// Draw the list elements
@@ -137,7 +135,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics)
}
else
{
- graphics->drawImage2(icon, mImagePadding, y + mPadding);
+ graphics->drawImage(icon, mImagePadding, y + mPadding);
}
}
}
@@ -158,13 +156,13 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics)
}
if (parent && a->getMaxHp())
{
- gcn::Color color = Theme::getProgressColor(
+ Color color = Theme::getProgressColor(
Theme::PROG_HP, static_cast<float>(a->getHp())
/ static_cast<float>(a->getMaxHp()));
color.a = 80;
graphics->setColor(color);
- graphics->fillRectangle(gcn::Rectangle(mPadding, y + mPadding,
+ graphics->fillRectangle(Rect(mPadding, y + mPadding,
parent->getWidth() * a->getHp() / a->getMaxHp()
- 2 * mPadding, fontHeight));
}
@@ -184,12 +182,11 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics)
if (parent)
{
- gcn::Color color = Theme::getProgressColor(Theme::PROG_HP,
- 1);
+ Color color = Theme::getProgressColor(Theme::PROG_HP, 1);
color.a = 80;
graphics->setColor(color);
- graphics->fillRectangle(gcn::Rectangle(mPadding, y + mPadding,
+ graphics->fillRectangle(Rect(mPadding, y + mPadding,
parent->getWidth() * a->getDamageHp() / 1024
- 2 * mPadding, fontHeight));
@@ -312,7 +309,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics)
BLOCK_END("AvatarListBox::draw")
}
-void AvatarListBox::mousePressed(gcn::MouseEvent &event)
+void AvatarListBox::mousePressed(MouseEvent &event)
{
if (!actorManager || !player_node || !viewport
|| !getFont()->getHeight())
@@ -336,7 +333,7 @@ void AvatarListBox::mousePressed(gcn::MouseEvent &event)
return;
const unsigned int eventButton = event.getButton();
- if (eventButton == gcn::MouseEvent::LEFT)
+ if (eventButton == MouseEvent::LEFT)
{
if (ava->getType() == AVATAR_PLAYER)
{
@@ -350,7 +347,7 @@ void AvatarListBox::mousePressed(gcn::MouseEvent &event)
player_node->navigateTo(ava->getX(), ava->getY());
}
}
- else if (eventButton == gcn::MouseEvent::RIGHT)
+ else if (eventButton == MouseEvent::RIGHT)
{
switch (ava->getType())
{
@@ -409,7 +406,7 @@ void AvatarListBox::mousePressed(gcn::MouseEvent &event)
}
}
}
- else if (eventButton == gcn::MouseEvent::MIDDLE)
+ else if (eventButton == MouseEvent::MIDDLE)
{
if (ava->getType() == AVATAR_PLAYER && chatWindow)
{
@@ -421,7 +418,7 @@ void AvatarListBox::mousePressed(gcn::MouseEvent &event)
}
}
-void AvatarListBox::mouseReleased(gcn::MouseEvent &event A_UNUSED)
+void AvatarListBox::mouseReleased(MouseEvent &event A_UNUSED)
{
}
diff --git a/src/gui/widgets/avatarlistbox.h b/src/gui/widgets/avatarlistbox.h
index 99c1132b2..e0711a7b7 100644
--- a/src/gui/widgets/avatarlistbox.h
+++ b/src/gui/widgets/avatarlistbox.h
@@ -22,29 +22,21 @@
#ifndef GUI_WIDGETS_AVATARLISTBOX_H
#define GUI_WIDGETS_AVATARLISTBOX_H
-#include "avatar.h"
-
-#include "configlistener.h"
+#include "listeners/configlistener.h"
#include "gui/widgets/listbox.h"
#include <string>
+class AvatarListModel;
class Image;
-class AvatarListModel : public gcn::ListModel
-{
-public:
- virtual Avatar *getAvatarAt(const int i) A_WARN_UNUSED = 0;
-
- std::string getElementAt(int i) override final A_WARN_UNUSED
- { return getAvatarAt(i)->getName(); }
-};
-
-class AvatarListBox final : public ListBox, public ConfigListener
+class AvatarListBox final : public ListBox,
+ public ConfigListener
{
public:
- AvatarListBox(const Widget2 *const widget, AvatarListModel *const model);
+ AvatarListBox(const Widget2 *const widget,
+ AvatarListModel *const model);
A_DELETE_COPY(AvatarListBox)
@@ -53,11 +45,11 @@ public:
/**
* Draws the list box.
*/
- void draw(gcn::Graphics *gcnGraphics) override final;
+ void draw(Graphics *gcnGraphics) override final;
- void mousePressed(gcn::MouseEvent &event) override final;
+ void mousePressed(MouseEvent &event) override final;
- void mouseReleased(gcn::MouseEvent &event A_UNUSED) override final;
+ void mouseReleased(MouseEvent &event A_UNUSED) override final;
void optionChanged(const std::string &value) override final;
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index b91c095b7..100281d94 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -25,8 +25,8 @@
#include "input/inputmanager.h"
+#include "gui/font.h"
#include "gui/gui.h"
-#include "gui/sdlfont.h"
#include "gui/widgets/linkhandler.h"
@@ -37,9 +37,9 @@
#include "utils/stringutils.h"
#include "utils/timer.h"
-#include <guichan/graphics.hpp>
-#include <guichan/font.hpp>
-#include <guichan/cliprectangle.hpp>
+#include "gui/cliprect.h"
+
+#include "render/graphics.h"
#include <algorithm>
@@ -52,9 +52,8 @@ BrowserBox::BrowserBox(const Widget2 *const widget,
const unsigned int mode,
const bool opaque,
const std::string &skin) :
- gcn::Widget(),
- Widget2(widget),
- gcn::MouseListener(),
+ Widget(widget),
+ MouseListener(),
mTextRows(),
mTextRowLinksCount(),
mLineParts(),
@@ -174,7 +173,7 @@ void BrowserBox::addRow(const std::string &row, const bool atTop)
std::string tmp = row;
std::string newRow;
size_t idx1;
- const gcn::Font *const font = getFont();
+ const Font *const font = getFont();
int linksCount = 0;
if (getWidth() < 0)
@@ -422,7 +421,7 @@ struct MouseOverLink
int mX, mY;
};
-void BrowserBox::mousePressed(gcn::MouseEvent &event)
+void BrowserBox::mousePressed(MouseEvent &event)
{
if (!mLinkHandler)
return;
@@ -437,7 +436,7 @@ void BrowserBox::mousePressed(gcn::MouseEvent &event)
}
}
-void BrowserBox::mouseMoved(gcn::MouseEvent &event)
+void BrowserBox::mouseMoved(MouseEvent &event)
{
const LinkIterator i = std::find_if(mLinks.begin(), mLinks.end(),
MouseOverLink(event.getX(), event.getY()));
@@ -446,13 +445,14 @@ void BrowserBox::mouseMoved(gcn::MouseEvent &event)
? static_cast<int>(i - mLinks.begin()) : -1;
}
-void BrowserBox::draw(gcn::Graphics *graphics)
+void BrowserBox::draw(Graphics *graphics)
{
BLOCK_START("BrowserBox::draw")
- const gcn::ClipRectangle &cr = graphics->getCurrentClipArea();
- Graphics *const graphics2 = static_cast<Graphics *const>(graphics);
- mYStart = cr.y - cr.yOffset;
- const int yEnd = mYStart + cr.height;
+ const ClipRect *const cr = graphics->getCurrentClipArea();
+ if (!cr)
+ return;
+ mYStart = cr->y - cr->yOffset;
+ const int yEnd = mYStart + cr->height;
if (mYStart < 0)
mYStart = 0;
@@ -462,7 +462,7 @@ void BrowserBox::draw(gcn::Graphics *graphics)
if (mOpaque)
{
graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
+ graphics->fillRectangle(Rect(0, 0, getWidth(), getHeight()));
}
if (mSelectedLink >= 0 && mSelectedLink
@@ -471,7 +471,7 @@ void BrowserBox::draw(gcn::Graphics *graphics)
if ((mHighMode & BACKGROUND))
{
graphics->setColor(mHighlightColor);
- graphics->fillRectangle(gcn::Rectangle(
+ graphics->fillRectangle(Rect(
mLinks[mSelectedLink].x1,
mLinks[mSelectedLink].y1,
mLinks[mSelectedLink].x2 - mLinks[mSelectedLink].x1,
@@ -489,7 +489,7 @@ void BrowserBox::draw(gcn::Graphics *graphics)
}
}
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
FOR_EACH (LinePartCIter, i, mLineParts)
{
@@ -500,7 +500,7 @@ void BrowserBox::draw(gcn::Graphics *graphics)
break;
if (!part.mType)
{
- graphics2->setColorAll(part.mColor, part.mColor2);
+ graphics->setColorAll(part.mColor, part.mColor2);
if (part.mBold)
boldFont->drawString(graphics, part.mText, part.mX, part.mY);
else
@@ -508,7 +508,7 @@ void BrowserBox::draw(gcn::Graphics *graphics)
}
else if (part.mImage)
{
- graphics2->drawImage2(part.mImage, part.mX, part.mY);
+ graphics->drawImage(part.mImage, part.mX, part.mY);
}
}
@@ -528,14 +528,14 @@ int BrowserBox::calcHeight()
if (maxWidth < 0)
return 1;
- const gcn::Font *const font = getFont();
+ 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);
- gcn::Color selColor[2] = {mForegroundColor, mForegroundColor2};
- const gcn::Color textColor[2] = {mForegroundColor, mForegroundColor2};
+ Color selColor[2] = {mForegroundColor, mForegroundColor2};
+ const Color textColor[2] = {mForegroundColor, mForegroundColor2};
ResourceManager *const resman = ResourceManager::getInstance();
mLineParts.clear();
@@ -581,7 +581,7 @@ int BrowserBox::calcHeight()
continue;
}
- gcn::Color prevColor[2];
+ Color prevColor[2];
prevColor[0] = selColor[0];
prevColor[1] = selColor[1];
bold = false;
@@ -621,7 +621,7 @@ int BrowserBox::calcHeight()
const signed char c = row.at(start + 2);
bool valid(false);
- const gcn::Color col[2] =
+ const Color col[2] =
{
getThemeCharColor(c, valid),
getThemeCharColor(c | 0x80, valid)
@@ -897,8 +897,8 @@ std::string BrowserBox::getTextAtPos(const int x, const int y) const
return str;
}
-void BrowserBox::setForegroundColorAll(const gcn::Color &color1,
- const gcn::Color &color2)
+void BrowserBox::setForegroundColorAll(const Color &color1,
+ const Color &color2)
{
mForegroundColor = color1;
mForegroundColor2 = color2;
diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h
index 09f06bc39..8202fa548 100644
--- a/src/gui/widgets/browserbox.h
+++ b/src/gui/widgets/browserbox.h
@@ -24,10 +24,9 @@
#ifndef GUI_WIDGETS_BROWSERBOX_H
#define GUI_WIDGETS_BROWSERBOX_H
-#include "gui/widgets/widget2.h"
+#include "listeners/mouselistener.h"
-#include <guichan/mouselistener.hpp>
-#include <guichan/widget.hpp>
+#include "gui/widgets/widget.h"
#include <list>
#include <vector>
@@ -60,8 +59,8 @@ struct BrowserLink final
class LinePart final
{
public:
- LinePart(const int x, const int y, const gcn::Color &color,
- const gcn::Color &color2, const std::string &text,
+ LinePart(const int x, const int y, const Color &color,
+ const Color &color2, const std::string &text,
const bool bold) :
mX(x),
mY(y),
@@ -74,8 +73,8 @@ class LinePart final
{
}
- LinePart(const int x, const int y, const gcn::Color &color,
- const gcn::Color &color2, Image *const image) :
+ LinePart(const int x, const int y, const Color &color,
+ const Color &color2, Image *const image) :
mX(x),
mY(y),
mColor(color),
@@ -90,8 +89,8 @@ class LinePart final
~LinePart();
int mX, mY;
- gcn::Color mColor;
- gcn::Color mColor2;
+ Color mColor;
+ Color mColor2;
std::string mText;
unsigned char mType;
Image *mImage;
@@ -102,9 +101,8 @@ class LinePart final
* A simple browser box able to handle links and forward events to the
* parent conteiner.
*/
-class BrowserBox final : public gcn::Widget,
- public Widget2,
- public gcn::MouseListener
+class BrowserBox final : public Widget,
+ public MouseListener
{
public:
/**
@@ -158,14 +156,14 @@ class BrowserBox final : public gcn::Widget,
/**
* Handles mouse actions.
*/
- void mousePressed(gcn::MouseEvent &event) override final;
+ void mousePressed(MouseEvent &event) override final;
- void mouseMoved(gcn::MouseEvent &event) override final;
+ void mouseMoved(MouseEvent &event) override final;
/**
* Draws the browser box.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
void updateHeight();
@@ -231,8 +229,8 @@ class BrowserBox final : public gcn::Widget,
int getPadding() const A_WARN_UNUSED
{ return mPadding; }
- void setForegroundColorAll(const gcn::Color &color1,
- const gcn::Color &color2);
+ void setForegroundColorAll(const Color &color1,
+ const Color &color2);
int getDataWidth() const
{ return mDataWidth; }
@@ -269,9 +267,9 @@ class BrowserBox final : public gcn::Widget,
int mItemPadding;
unsigned int mDataWidth;
- gcn::Color mHighlightColor;
- gcn::Color mHyperLinkColor;
- gcn::Color mColors[2][COLORS_MAX];
+ Color mHighlightColor;
+ Color mHyperLinkColor;
+ Color mColors[2][COLORS_MAX];
bool mOpaque;
bool mUseLinksAndUserColors;
diff --git a/src/gui/widgets/browserbox_unittest.cc b/src/gui/widgets/browserbox_unittest.cc
index 87d31e900..2acc5f5d3 100644
--- a/src/gui/widgets/browserbox_unittest.cc
+++ b/src/gui/widgets/browserbox_unittest.cc
@@ -22,7 +22,7 @@
#include "client.h"
-#include "gui/sdlfont.h"
+#include "gui/font.h"
#include "gui/theme.h"
#include "gui/widgets/browserbox.h"
@@ -51,7 +51,7 @@ TEST(browserbox, test1)
logger = new Logger();
imageHelper = new SDLImageHelper();
Theme *theme = Theme::instance();
- gcn::Widget::setGlobalFont(new SDLFont("/usr/share/fonts/truetype/"
+ Widget::setGlobalFont(new Font("/usr/share/fonts/truetype/"
"ttf-dejavu/DejaVuSans-Oblique.ttf", 18));
BrowserBox *box = new BrowserBox(nullptr, BrowserBox::AUTO_WRAP, true, "");
box->setWidth(100);
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index 0042b07e3..3cb6d823d 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -25,12 +25,17 @@
#include "client.h"
#include "graphicsvertexes.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
+#include "resources/image.h"
#include "resources/imageset.h"
-#include <guichan/font.hpp>
+#include "gui/font.h"
+#include "gui/gui.h"
+
+#include "gui/rect.h"
#include "debug.h"
@@ -48,9 +53,8 @@ static std::string const data[Button::BUTTON_COUNT] =
Skin *Button::button[BUTTON_COUNT];
Button::Button(const Widget2 *const widget) :
- gcn::Button(),
- Widget2(widget),
- gcn::WidgetListener(),
+ gcn::Button(widget),
+ WidgetListener(),
mDescription(),
mVertexes2(new ImageCollection),
mEnabledColor(getThemeColor(Theme::BUTTON)),
@@ -81,10 +85,9 @@ Button::Button(const Widget2 *const widget) :
Button::Button(const Widget2 *const widget,
const std::string &restrict caption,
const std::string &restrict actionEventId,
- gcn::ActionListener *const listener) :
- gcn::Button(caption),
- Widget2(widget),
- gcn::WidgetListener(),
+ ActionListener *const listener) :
+ gcn::Button(widget, caption),
+ WidgetListener(),
mDescription(),
mVertexes2(new ImageCollection),
mEnabledColor(getThemeColor(Theme::BUTTON)),
@@ -121,10 +124,9 @@ Button::Button(const Widget2 *const widget,
const std::string &restrict imageName,
const int imageWidth, const int imageHeight,
const std::string &restrict actionEventId,
- gcn::ActionListener *const listener) :
- gcn::Button(caption),
- Widget2(widget),
- gcn::WidgetListener(),
+ ActionListener *const listener) :
+ gcn::Button(widget, caption),
+ WidgetListener(),
mDescription(),
mVertexes2(new ImageCollection),
mEnabledColor(getThemeColor(Theme::BUTTON)),
@@ -161,10 +163,9 @@ Button::Button(const Widget2 *const widget,
const std::string &restrict imageName,
const int imageWidth, const int imageHeight,
const std::string &restrict actionEventId,
- gcn::ActionListener *const listener) :
- gcn::Button(),
- Widget2(widget),
- gcn::WidgetListener(),
+ ActionListener *const listener) :
+ gcn::Button(widget),
+ WidgetListener(),
mDescription(),
mVertexes2(new ImageCollection),
mEnabledColor(getThemeColor(Theme::BUTTON)),
@@ -201,10 +202,9 @@ Button::Button(const Widget2 *const widget,
const std::string &restrict caption,
const std::string &restrict imageName,
const std::string &restrict actionEventId,
- gcn::ActionListener *const listener) :
- gcn::Button(caption),
- Widget2(widget),
- gcn::WidgetListener(),
+ ActionListener *const listener) :
+ gcn::Button(widget, caption),
+ WidgetListener(),
mDescription(),
mVertexes2(new ImageCollection),
mEnabledColor(getThemeColor(Theme::BUTTON)),
@@ -350,7 +350,7 @@ void Button::updateAlpha()
}
}
-void Button::draw(gcn::Graphics *graphics)
+void Button::draw(Graphics *graphics)
{
BLOCK_START("Button::draw")
int mode;
@@ -373,8 +373,6 @@ void Button::draw(gcn::Graphics *graphics)
updateAlpha();
- Graphics *const g2 = static_cast<Graphics *const>(graphics);
-
bool recalc = false;
if (mRedraw)
{
@@ -384,7 +382,7 @@ void Button::draw(gcn::Graphics *graphics)
{
// because we don't know where parent windows was moved,
// need recalc vertexes
- gcn::ClipRectangle &rect = g2->getTopClip();
+ ClipRect &rect = graphics->getTopClip();
if (rect.xOffset != mXOffset || rect.yOffset != mYOffset)
{
recalc = true;
@@ -396,7 +394,7 @@ void Button::draw(gcn::Graphics *graphics)
recalc = true;
mMode = mode;
}
- else if (g2->getRedraw())
+ else if (graphics->getRedraw())
{
recalc = true;
}
@@ -408,26 +406,26 @@ void Button::draw(gcn::Graphics *graphics)
switch (mode)
{
case BUTTON_DISABLED:
- g2->setColorAll(mDisabledColor, mDisabledColor2);
+ graphics->setColorAll(mDisabledColor, mDisabledColor2);
break;
case BUTTON_PRESSED:
- g2->setColorAll(mPressedColor, mPressedColor2);
+ graphics->setColorAll(mPressedColor, mPressedColor2);
break;
case BUTTON_HIGHLIGHTED:
- g2->setColorAll(mHighlightedColor, mHighlightedColor2);
+ graphics->setColorAll(mHighlightedColor, mHighlightedColor2);
break;
default:
- g2->setColorAll(mEnabledColor, mEnabledColor2);
+ graphics->setColorAll(mEnabledColor, mEnabledColor2);
break;
}
int imageX = 0;
int imageY = 0;
int textX = 0;
- const gcn::Rectangle &rect = mDimension;
+ const Rect &rect = mDimension;
const int width = rect.width;
const int height = rect.height;
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
int textY = height / 2 - font->getHeight() / 2;
if (mImages)
imageY = height / 2 - mImageHeight / 2;
@@ -437,7 +435,7 @@ void Button::draw(gcn::Graphics *graphics)
switch (mAlignment)
{
default:
- case gcn::Graphics::LEFT:
+ case Graphics::LEFT:
{
if (mImages)
{
@@ -450,7 +448,7 @@ void Button::draw(gcn::Graphics *graphics)
}
break;
}
- case gcn::Graphics::CENTER:
+ case Graphics::CENTER:
{
const int width1 = font->getWidth(mCaption);
if (mImages)
@@ -465,7 +463,7 @@ void Button::draw(gcn::Graphics *graphics)
}
break;
}
- case gcn::Graphics::RIGHT:
+ case Graphics::RIGHT:
{
const int width1 = font->getWidth(mCaption);
textX = width - width1 - padding;
@@ -481,39 +479,39 @@ void Button::draw(gcn::Graphics *graphics)
mRedraw = false;
mMode = mode;
mVertexes2->clear();
- g2->calcWindow(mVertexes2, 0, 0, width, height,
+ graphics->calcWindow(mVertexes2,
+ 0, 0,
+ width, height,
skin->getBorder());
if (mImages)
{
if (isPressed())
{
- g2->calcTileCollection(mVertexes2, mImages[mode],
+ graphics->calcTileCollection(mVertexes2,
+ mImages[mode],
imageX + 1, imageY + 1);
}
else
{
- g2->calcTileCollection(mVertexes2,
- mImages[mode], imageX, imageY);
+ graphics->calcTileCollection(mVertexes2,
+ mImages[mode],
+ imageX, imageY);
}
}
}
- g2->drawTileCollection(mVertexes2);
+ graphics->drawTileCollection(mVertexes2);
}
else
{
- g2->drawImageRect(0, 0, width, height, skin->getBorder());
+ graphics->drawImageRect(0, 0, width, height, skin->getBorder());
if (mImages)
{
if (isPressed())
- {
- g2->drawImage2(mImages[mode], imageX + 1, imageY + 1);
- }
+ graphics->drawImage(mImages[mode], imageX + 1, imageY + 1);
else
- {
- g2->drawImage2(mImages[mode], imageX, imageY);
- }
+ graphics->drawImage(mImages[mode], imageX, imageY);
}
}
@@ -522,13 +520,13 @@ void Button::draw(gcn::Graphics *graphics)
textX ++;
textY ++;
}
- font->drawString(g2, mCaption, textX, textY);
+ font->drawString(graphics, mCaption, textX, textY);
BLOCK_END("Button::draw")
}
-void Button::mouseReleased(gcn::MouseEvent& mouseEvent)
+void Button::mouseReleased(MouseEvent& mouseEvent)
{
- if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
+ if (mouseEvent.getButton() == MouseEvent::LEFT)
{
if (mStick)
mPressed = !mPressed;
@@ -548,19 +546,19 @@ void Button::mouseReleased(gcn::MouseEvent& mouseEvent)
}
}
-void Button::widgetResized(const gcn::Event &event A_UNUSED)
+void Button::widgetResized(const Event &event A_UNUSED)
{
mRedraw = true;
}
-void Button::widgetMoved(const gcn::Event &event A_UNUSED)
+void Button::widgetMoved(const Event &event A_UNUSED)
{
mRedraw = true;
}
void Button::adjustSize()
{
- const gcn::Font *const font = getFont();
+ const Font *const font = getFont();
const Skin *const skin = button[BUTTON_STANDARD];
if (!skin)
return;
@@ -591,9 +589,9 @@ void Button::setCaption(const std::string& caption)
mCaption = caption;
}
-void Button::keyPressed(gcn::KeyEvent& keyEvent)
+void Button::keyPressed(KeyEvent& keyEvent)
{
- const int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int action = keyEvent.getActionId();
if (action == Input::KEY_GUI_SELECT)
{
@@ -602,9 +600,9 @@ void Button::keyPressed(gcn::KeyEvent& keyEvent)
}
}
-void Button::keyReleased(gcn::KeyEvent& keyEvent)
+void Button::keyReleased(KeyEvent& keyEvent)
{
- const int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int action = keyEvent.getActionId();
if (action == Input::KEY_GUI_SELECT && mKeyPressed)
{
diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h
index 3dd783e52..039475150 100644
--- a/src/gui/widgets/button.h
+++ b/src/gui/widgets/button.h
@@ -23,10 +23,8 @@
#ifndef GUI_WIDGETS_BUTTON_H
#define GUI_WIDGETS_BUTTON_H
-#include "gui/widgets/widget2.h"
-
-#include <guichan/widgets/button.hpp>
-#include <guichan/widgetlistener.hpp>
+#include "gui/base/widgets/button.hpp"
+#include "listeners/widgetlistener.h"
#include "localconsts.h"
@@ -43,8 +41,7 @@ const std::string BUTTON_PLAY = "buttonplay.png";
* \ingroup GUI
*/
class Button final : public gcn::Button,
- public Widget2,
- public gcn::WidgetListener
+ public WidgetListener
{
public:
/**
@@ -59,7 +56,7 @@ class Button final : public gcn::Button,
Button(const Widget2 *const widget,
const std::string &restrict caption,
const std::string &restrict actionEventId,
- gcn::ActionListener *const listener);
+ ActionListener *const listener);
/**
* Constructor, sets the caption of the button to the given string and
@@ -70,7 +67,7 @@ class Button final : public gcn::Button,
const std::string &restrict imageName,
const int imageWidth, const int imageHeight,
const std::string &actionEventId,
- gcn::ActionListener *const listener);
+ ActionListener *const listener);
/**
* Constructor, sets the caption of the button to the given string and
@@ -80,7 +77,7 @@ class Button final : public gcn::Button,
const std::string &restrict imageName,
const int imageWidth, const int imageHeight,
const std::string &restrict actionEventId,
- gcn::ActionListener *const listener);
+ ActionListener *const listener);
/**
* Constructor, sets the caption of the button to the given string and
@@ -90,7 +87,7 @@ class Button final : public gcn::Button,
const std::string &restrict imageName,
const std::string &restrict caption,
const std::string &restrict actionEventId,
- gcn::ActionListener *const listener);
+ ActionListener *const listener);
A_DELETE_COPY(Button)
@@ -102,14 +99,14 @@ class Button final : public gcn::Button,
/**
* Draws the button.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
/**
* Update the alpha value to the button components.
*/
static void updateAlpha();
- void mouseReleased(gcn::MouseEvent& mouseEvent) override final;
+ void mouseReleased(MouseEvent& mouseEvent) override final;
void setDescription(std::string text)
{ mDescription = text; }
@@ -132,9 +129,9 @@ class Button final : public gcn::Button,
void setPressed(bool b)
{ mPressed = b; }
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
- void widgetMoved(const gcn::Event &event) override final;
+ void widgetMoved(const Event &event) override final;
void loadImage(const std::string &imageName);
@@ -144,9 +141,9 @@ class Button final : public gcn::Button,
void setCaption(const std::string& caption);
- void keyPressed(gcn::KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &keyEvent) override final;
- void keyReleased(gcn::KeyEvent &keyEvent) override final;
+ void keyReleased(KeyEvent &keyEvent) override final;
bool isPressed2() const A_WARN_UNUSED;
@@ -168,14 +165,14 @@ class Button final : public gcn::Button,
std::string mDescription;
ImageCollection *mVertexes2;
- gcn::Color mEnabledColor;
- gcn::Color mEnabledColor2;
- gcn::Color mDisabledColor;
- gcn::Color mDisabledColor2;
- gcn::Color mHighlightedColor;
- gcn::Color mHighlightedColor2;
- gcn::Color mPressedColor;
- gcn::Color mPressedColor2;
+ Color mEnabledColor;
+ Color mEnabledColor2;
+ Color mDisabledColor;
+ Color mDisabledColor2;
+ Color mHighlightedColor;
+ Color mHighlightedColor2;
+ Color mPressedColor;
+ Color mPressedColor2;
Image **mImages;
ImageSet *mImageSet;
unsigned mClickCount;
diff --git a/src/gui/widgets/characterdisplay.cpp b/src/gui/widgets/characterdisplay.cpp
index 5ae4e2f5b..7bfc938de 100644
--- a/src/gui/widgets/characterdisplay.cpp
+++ b/src/gui/widgets/characterdisplay.cpp
@@ -24,6 +24,8 @@
#include "units.h"
+#include "gui/gui.h"
+
#include "gui/windows/charselectdialog.h"
#include "gui/popups/textpopup.h"
@@ -32,16 +34,15 @@
#include "gui/widgets/layouthelper.h"
#include "utils/gettext.h"
-
-#include <SDL_mouse.h>
+#include "utils/stringutils.h"
#include "debug.h"
CharacterDisplay::CharacterDisplay(const Widget2 *const widget,
CharSelectDialog *const charSelectDialog) :
Container(widget),
- gcn::MouseListener(),
- gcn::WidgetListener(),
+ MouseListener(),
+ WidgetListener(),
mCharacter(nullptr),
mPlayerBox(new PlayerBox(nullptr)),
mName(new Label(this, "wwwwwwwwwwwwwwwwwwwwwwww")),
@@ -110,17 +111,17 @@ void CharacterDisplay::update()
distributeResizedEvent();
}
-void CharacterDisplay::widgetHidden(const gcn::Event &event A_UNUSED)
+void CharacterDisplay::widgetHidden(const Event &event A_UNUSED)
{
mPopup->setVisible(false);
}
-void CharacterDisplay::mouseExited(gcn::MouseEvent &event A_UNUSED)
+void CharacterDisplay::mouseExited(MouseEvent &event A_UNUSED)
{
mPopup->setVisible(false);
}
-void CharacterDisplay::mouseMoved(gcn::MouseEvent &event A_UNUSED)
+void CharacterDisplay::mouseMoved(MouseEvent &event A_UNUSED)
{
if (!gui)
return;
@@ -142,7 +143,7 @@ void CharacterDisplay::mouseMoved(gcn::MouseEvent &event A_UNUSED)
}
}
-void CharacterDisplay::mousePressed(gcn::MouseEvent &event)
+void CharacterDisplay::mousePressed(MouseEvent &event)
{
if (event.getClickCount() == 2)
distributeActionEvent();
diff --git a/src/gui/widgets/characterdisplay.h b/src/gui/widgets/characterdisplay.h
index eb5ec6dfc..8f9acf462 100644
--- a/src/gui/widgets/characterdisplay.h
+++ b/src/gui/widgets/characterdisplay.h
@@ -26,10 +26,7 @@
#include "gui/widgets/container.h"
#include "gui/widgets/playerbox.h"
-#include "net/charserverhandler.h"
-#include "net/net.h"
-
-#include <guichan/widgetlistener.hpp>
+#include "listeners/widgetlistener.h"
#include "localconsts.h"
@@ -37,9 +34,14 @@ class CharSelectDialog;
class Label;
class TextPopup;
+namespace Net
+{
+ struct Character;
+}
+
class CharacterDisplay final : public Container,
- public gcn::MouseListener,
- public gcn::WidgetListener
+ public MouseListener,
+ public WidgetListener
{
public:
CharacterDisplay(const Widget2 *const widget,
@@ -73,13 +75,13 @@ class CharacterDisplay final : public Container,
void setSelect(bool b)
{ mPlayerBox->setSelected(b); }
- void widgetHidden(const gcn::Event &event) override final;
+ void widgetHidden(const Event &event) override final;
- void mouseExited(gcn::MouseEvent &event) override final;
+ void mouseExited(MouseEvent &event) override final;
- void mouseMoved(gcn::MouseEvent &event) override final;
+ void mouseMoved(MouseEvent &event) override final;
- void mousePressed(gcn::MouseEvent &event) override final;
+ void mousePressed(MouseEvent &event) override final;
private:
void update();
diff --git a/src/gui/widgets/characterviewbase.h b/src/gui/widgets/characterviewbase.h
index a7c9d2240..16b6c3e0d 100644
--- a/src/gui/widgets/characterviewbase.h
+++ b/src/gui/widgets/characterviewbase.h
@@ -25,12 +25,12 @@
#include "gui/widgets/container.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
#include "localconsts.h"
class CharacterViewBase : public Container,
- public gcn::ActionListener
+ public ActionListener
{
public:
A_DELETE_COPY(CharacterViewBase)
@@ -50,7 +50,7 @@ class CharacterViewBase : public Container,
protected:
CharacterViewBase(CharSelectDialog *const widget, const int padding) :
Container(widget),
- gcn::ActionListener(),
+ ActionListener(),
mParent(widget),
mPadding(padding),
mSelected(0)
diff --git a/src/gui/widgets/characterviewnormal.cpp b/src/gui/widgets/characterviewnormal.cpp
index 78c538b8c..1df98d85e 100644
--- a/src/gui/widgets/characterviewnormal.cpp
+++ b/src/gui/widgets/characterviewnormal.cpp
@@ -23,7 +23,6 @@
#include "configuration.h"
#include "gui/widgets/characterdisplay.h"
-#include "gui/widgets/characterviewsmall.h"
#include "debug.h"
@@ -87,6 +86,6 @@ void CharacterViewNormal::resize()
(*mCharacterEntries)[f]->setPosition((f - 5) * width, y);
}
-void CharacterViewNormal::action(const gcn::ActionEvent &event A_UNUSED)
+void CharacterViewNormal::action(const ActionEvent &event A_UNUSED)
{
}
diff --git a/src/gui/widgets/characterviewnormal.h b/src/gui/widgets/characterviewnormal.h
index 50001a61d..4ef1500b0 100644
--- a/src/gui/widgets/characterviewnormal.h
+++ b/src/gui/widgets/characterviewnormal.h
@@ -40,7 +40,7 @@ class CharacterViewNormal final : public CharacterViewBase
void resize() override;
- void action(const gcn::ActionEvent &event A_UNUSED) override final;
+ void action(const ActionEvent &event A_UNUSED) override final;
private:
std::vector<CharacterDisplay*> *mCharacterEntries;
diff --git a/src/gui/widgets/characterviewsmall.cpp b/src/gui/widgets/characterviewsmall.cpp
index ce218646b..4d2c93b48 100644
--- a/src/gui/widgets/characterviewsmall.cpp
+++ b/src/gui/widgets/characterviewsmall.cpp
@@ -24,6 +24,8 @@
#include "gui/widgets/characterdisplay.h"
#include "gui/widgets/label.h"
+#include "utils/stringutils.h"
+
#include "debug.h"
CharacterViewSmall::CharacterViewSmall(CharSelectDialog *const widget,
@@ -98,7 +100,7 @@ void CharacterViewSmall::resize()
mNumber->setPosition(10, y2);
}
-void CharacterViewSmall::action(const gcn::ActionEvent &event)
+void CharacterViewSmall::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "next")
diff --git a/src/gui/widgets/characterviewsmall.h b/src/gui/widgets/characterviewsmall.h
index 3a326134b..a9f6d7f9b 100644
--- a/src/gui/widgets/characterviewsmall.h
+++ b/src/gui/widgets/characterviewsmall.h
@@ -25,6 +25,8 @@
#include "localconsts.h"
+class Label;
+
class CharacterViewSmall final : public CharacterViewBase
{
public:
@@ -39,7 +41,7 @@ class CharacterViewSmall final : public CharacterViewBase
void resize() override final;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
private:
CharacterDisplay *mSelectedEntry;
diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp
index 47d9f2b57..9fb63b2e8 100644
--- a/src/gui/widgets/checkbox.cpp
+++ b/src/gui/widgets/checkbox.cpp
@@ -24,12 +24,14 @@
#include "client.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
#include "resources/image.h"
-#include <guichan/font.hpp>
+#include "gui/font.h"
+#include "gui/gui.h"
#include "debug.h"
@@ -38,11 +40,11 @@ Skin *CheckBox::mSkin = nullptr;
float CheckBox::mAlpha = 1.0;
CheckBox::CheckBox(const Widget2 *const widget,
- const std::string &restrict caption, const bool selected,
- gcn::ActionListener *const listener,
+ const std::string &restrict caption,
+ const bool selected,
+ ActionListener *const listener,
const std::string &restrict eventId) :
- gcn::CheckBox(caption, selected),
- Widget2(widget),
+ gcn::CheckBox(widget, caption, selected),
mPadding(0),
mImagePadding(0),
mImageSize(9),
@@ -94,15 +96,13 @@ CheckBox::~CheckBox()
}
}
-void CheckBox::draw(gcn::Graphics *const graphics)
+void CheckBox::draw(Graphics *const graphics)
{
BLOCK_START("CheckBox::draw")
drawBox(graphics);
- gcn::Font *const font = getFont();
- static_cast<Graphics *const>(graphics)->setColorAll(
- mForegroundColor, mForegroundColor2);
-
+ Font *const font = getFont();
+ graphics->setColorAll(mForegroundColor, mForegroundColor2);
font->drawString(graphics, mCaption, mPadding + mImageSize + mSpacing,
mPadding);
BLOCK_END("CheckBox::draw")
@@ -129,7 +129,7 @@ void CheckBox::updateAlpha()
}
}
-void CheckBox::drawBox(gcn::Graphics *const graphics)
+void CheckBox::drawBox(Graphics *const graphics)
{
if (!mSkin || !mDrawBox)
return;
@@ -167,24 +167,25 @@ void CheckBox::drawBox(gcn::Graphics *const graphics)
if (box)
{
- static_cast<Graphics*>(graphics)->drawImage2(
- box, mImagePadding, (getHeight() - mImageSize) / 2);
+ graphics->drawImage(box,
+ mImagePadding,
+ (getHeight() - mImageSize) / 2);
}
}
-void CheckBox::mouseEntered(gcn::MouseEvent& event A_UNUSED)
+void CheckBox::mouseEntered(MouseEvent& event A_UNUSED)
{
mHasMouse = true;
}
-void CheckBox::mouseExited(gcn::MouseEvent& event A_UNUSED)
+void CheckBox::mouseExited(MouseEvent& event A_UNUSED)
{
mHasMouse = false;
}
-void CheckBox::keyPressed(gcn::KeyEvent& keyEvent)
+void CheckBox::keyPressed(KeyEvent& keyEvent)
{
- const int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int action = keyEvent.getActionId();
if (action == Input::KEY_GUI_SELECT)
{
diff --git a/src/gui/widgets/checkbox.h b/src/gui/widgets/checkbox.h
index 2d4581327..28eadb75c 100644
--- a/src/gui/widgets/checkbox.h
+++ b/src/gui/widgets/checkbox.h
@@ -23,9 +23,7 @@
#ifndef GUI_WIDGETS_CHECKBOX_H
#define GUI_WIDGETS_CHECKBOX_H
-#include "gui/widgets/widget2.h"
-
-#include <guichan/widgets/checkbox.hpp>
+#include "gui/base/widgets/checkbox.hpp"
#include "localconsts.h"
@@ -36,8 +34,7 @@ class Skin;
*
* \ingroup GUI
*/
-class CheckBox final : public gcn::CheckBox,
- public Widget2
+class CheckBox final : public gcn::CheckBox
{
public:
/**
@@ -46,7 +43,7 @@ class CheckBox final : public gcn::CheckBox,
CheckBox(const Widget2 *const widget,
const std::string &restrict caption,
const bool selected = false,
- gcn::ActionListener *const listener = nullptr,
+ ActionListener *const listener = nullptr,
const std::string &restrict eventId = "");
A_DELETE_COPY(CheckBox)
@@ -59,7 +56,7 @@ class CheckBox final : public gcn::CheckBox,
/**
* Draws the caption, then calls drawBox to draw the check box.
*/
- void draw(gcn::Graphics *const graphics) override final;
+ void draw(Graphics *const graphics) override final;
/**
* Update the alpha value to the checkbox components.
@@ -69,19 +66,19 @@ class CheckBox final : public gcn::CheckBox,
/**
* Draws the check box, not the caption.
*/
- void drawBox(gcn::Graphics *const graphics);
+ void drawBox(Graphics *const graphics);
/**
* Called when the mouse enteres the widget area.
*/
- void mouseEntered(gcn::MouseEvent& event) override final;
+ void mouseEntered(MouseEvent& event) override final;
/**
* Called when the mouse leaves the widget area.
*/
- void mouseExited(gcn::MouseEvent& event) override final;
+ void mouseExited(MouseEvent& event) override final;
- void keyPressed(gcn::KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& keyEvent) override final;
void adjustSize();
diff --git a/src/gui/widgets/colorpage.cpp b/src/gui/widgets/colorpage.cpp
index 11dd1f07e..501b3dea7 100644
--- a/src/gui/widgets/colorpage.cpp
+++ b/src/gui/widgets/colorpage.cpp
@@ -20,20 +20,20 @@
#include "gui/widgets/colorpage.h"
-#include "gui/widgets/colormodel.h"
+#include "gui/models/colormodel.h"
-#include <guichan/font.hpp>
+#include "gui/font.h"
#include "debug.h"
ColorPage::ColorPage(const Widget2 *const widget,
- gcn::ListModel *const listModel,
+ ListModel *const listModel,
const std::string &skin) :
ListBox(widget, listModel, skin)
{
mItemPadding = mSkin ? mSkin->getOption("itemPadding") : 1;
mRowHeight = 13;
- const gcn::Font *const font = getFont();
+ const Font *const font = getFont();
if (font)
mRowHeight = font->getHeight() + 2 * mItemPadding;
if (mListModel)
@@ -47,43 +47,42 @@ ColorPage::~ColorPage()
{
}
-void ColorPage::draw(gcn::Graphics *graphics)
+void ColorPage::draw(Graphics *graphics)
{
BLOCK_START("ColorPage::draw")
const ColorModel *const model = static_cast<ColorModel* const>(
mListModel);
- Graphics *const g = static_cast<Graphics *const>(graphics);
mHighlightColor.a = static_cast<int>(mAlpha * 255.0F);
graphics->setColor(mHighlightColor);
updateAlpha();
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
const int rowHeight = getRowHeight();
const int width = mDimension.width;
if (mSelected >= 0)
{
- graphics->fillRectangle(gcn::Rectangle(mPadding,
+ graphics->fillRectangle(Rect(mPadding,
rowHeight * mSelected + mPadding,
mDimension.width - 2 * mPadding, rowHeight));
const ColorPair *const colors = model->getColorAt(mSelected);
- g->setColorAll(*colors->color1, *colors->color2);
+ graphics->setColorAll(*colors->color1, *colors->color2);
const std::string str = mListModel->getElementAt(mSelected);
font->drawString(graphics, str, (width - font->getWidth(str)) / 2,
mSelected * rowHeight + mPadding);
}
- g->setColorAll(mForegroundColor, mForegroundColor2);
+ graphics->setColorAll(mForegroundColor, mForegroundColor2);
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);
- g->setColorAll(*colors->color1, *colors->color2);
+ graphics->setColorAll(*colors->color1, *colors->color2);
const std::string str = mListModel->getElementAt(i);
font->drawString(graphics, str, (width - font->getWidth(str)) / 2,
y);
diff --git a/src/gui/widgets/colorpage.h b/src/gui/widgets/colorpage.h
index c1c90eddf..88182e4f2 100644
--- a/src/gui/widgets/colorpage.h
+++ b/src/gui/widgets/colorpage.h
@@ -29,14 +29,14 @@ class ColorPage final : public ListBox
{
public:
ColorPage(const Widget2 *const widget,
- gcn::ListModel *const listModel,
+ ListModel *const listModel,
const std::string &skin);
A_DELETE_COPY(ColorPage)
~ColorPage();
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
void resetAction();
diff --git a/src/gui/widgets/container.cpp b/src/gui/widgets/container.cpp
index e37bd5103..93d74dc8d 100644
--- a/src/gui/widgets/container.cpp
+++ b/src/gui/widgets/container.cpp
@@ -22,11 +22,12 @@
#include "gui/widgets/container.h"
+#include "gui/gui.h"
+
#include "debug.h"
Container::Container(const Widget2 *const widget) :
- gcn::Container(),
- Widget2(widget)
+ gcn::Container(widget)
{
setOpaque(false);
}
@@ -44,7 +45,7 @@ void Container::removeControls()
delete mWidgets.front();
}
-bool Container::safeRemove(gcn::Widget *const widget)
+bool Container::safeRemove(Widget *const widget)
{
for (WidgetListConstIterator iter = mWidgets.begin();
iter != mWidgets.end(); ++iter)
diff --git a/src/gui/widgets/container.h b/src/gui/widgets/container.h
index 2983a7433..17d6b2af4 100644
--- a/src/gui/widgets/container.h
+++ b/src/gui/widgets/container.h
@@ -23,13 +23,7 @@
#ifndef GUI_WIDGETS_CONTAINER_H
#define GUI_WIDGETS_CONTAINER_H
-#include "gui/widgets/widget2.h"
-
-#include <guichan/widgets/container.hpp>
-
-#if !defined USE_INTERNALGUICHAN
-typedef std::list<gcn::Widget *>::const_iterator WidgetListConstIterator;
-#endif
+#include "gui/base/widgets/container.hpp"
/**
* A widget container.
@@ -40,15 +34,14 @@ typedef std::list<gcn::Widget *>::const_iterator WidgetListConstIterator;
*
* This container is also non-opaque by default.
*/
-class Container : public gcn::Container,
- public Widget2
+class Container : public gcn::Container
{
public:
explicit Container(const Widget2 *const widget);
virtual ~Container();
- bool safeRemove(gcn::Widget *const widget);
+ bool safeRemove(Widget *const widget);
void removeControls();
};
diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp
index 32c8a4988..a77516c62 100644
--- a/src/gui/widgets/desktop.cpp
+++ b/src/gui/widgets/desktop.cpp
@@ -35,7 +35,7 @@
Desktop::Desktop(const Widget2 *const widget) :
Container(widget),
- gcn::WidgetListener(),
+ WidgetListener(),
mWallpaper(nullptr),
mVersionLabel(nullptr),
mSkin(nullptr),
@@ -98,17 +98,16 @@ void Desktop::reloadWallpaper()
setBestFittingWallpaper();
}
-void Desktop::widgetResized(const gcn::Event &event A_UNUSED)
+void Desktop::widgetResized(const Event &event A_UNUSED)
{
setBestFittingWallpaper();
}
-void Desktop::draw(gcn::Graphics *graphics)
+void Desktop::draw(Graphics *graphics)
{
BLOCK_START("Desktop::draw")
- Graphics *const g = static_cast<Graphics *const>(graphics);
- const gcn::Rectangle &rect = mDimension;
+ const Rect &rect = mDimension;
const int width = rect.width;
const int height = rect.height;
if (mWallpaper)
@@ -118,30 +117,30 @@ void Desktop::draw(gcn::Graphics *graphics)
if (width > wallpWidth || height > wallpHeight)
{
- g->setColor(mBackgroundGrayColor);
- g->fillRectangle(gcn::Rectangle(0, 0, width, height));
+ graphics->setColor(mBackgroundGrayColor);
+ graphics->fillRectangle(Rect(0, 0, width, height));
}
if (imageHelper->useOpenGL() == RENDER_SOFTWARE)
{
- g->drawImage2(mWallpaper,
+ graphics->drawImage(mWallpaper,
(width - wallpWidth) / 2,
(height - wallpHeight) / 2);
}
else
{
- g->drawRescaledImage(mWallpaper, 0, 0, width, height);
+ graphics->drawRescaledImage(mWallpaper, 0, 0, width, height);
}
}
else
{
- g->setColor(mBackgroundGrayColor);
- g->fillRectangle(gcn::Rectangle(0, 0, width, height));
+ graphics->setColor(mBackgroundGrayColor);
+ graphics->fillRectangle(Rect(0, 0, width, height));
}
// Draw a thin border under the application version...
- g->setColor(mBackgroundColor);
- g->fillRectangle(gcn::Rectangle(mVersionLabel->getDimension()));
+ graphics->setColor(mBackgroundColor);
+ graphics->fillRectangle(Rect(mVersionLabel->getDimension()));
Container::draw(graphics);
BLOCK_END("Desktop::draw")
@@ -166,7 +165,7 @@ void Desktop::setBestFittingWallpaper()
mWallpaper = nullptr;
}
- const gcn::Rectangle &rect = mDimension;
+ const Rect &rect = mDimension;
const int width = rect.width;
const int height = rect.height;
diff --git a/src/gui/widgets/desktop.h b/src/gui/widgets/desktop.h
index b62ae96ef..f0fd500ea 100644
--- a/src/gui/widgets/desktop.h
+++ b/src/gui/widgets/desktop.h
@@ -24,7 +24,7 @@
#include "gui/widgets/container.h"
-#include <guichan/widgetlistener.hpp>
+#include "listeners/widgetlistener.h"
#include "localconsts.h"
@@ -45,7 +45,8 @@ class Skin;
*
* \ingroup GUI
*/
-class Desktop final : public Container, private gcn::WidgetListener
+class Desktop final : public Container,
+ private WidgetListener
{
public:
explicit Desktop(const Widget2 *const widget);
@@ -59,9 +60,9 @@ class Desktop final : public Container, private gcn::WidgetListener
*/
void reloadWallpaper();
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
void postInit();
@@ -71,8 +72,8 @@ class Desktop final : public Container, private gcn::WidgetListener
Image *mWallpaper;
Label *mVersionLabel;
Skin *mSkin;
- gcn::Color mBackgroundColor;
- gcn::Color mBackgroundGrayColor;
+ Color mBackgroundColor;
+ Color mBackgroundGrayColor;
bool mShowBackground;
};
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index 59cdec6fb..dfc17e17b 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -24,15 +24,18 @@
#include "client.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
-#include "gui/widgets/extendedlistmodel.h"
+#include "gui/models/extendedlistmodel.h"
+
#include "gui/widgets/popuplist.h"
#include "resources/image.h"
-#include <guichan/font.hpp>
+#include "gui/font.h"
+#include "gui/gui.h"
#include <algorithm>
@@ -51,18 +54,17 @@ static std::string const dropdownFiles[2] =
};
DropDown::DropDown(const Widget2 *const widget,
- gcn::ListModel *const listModel,
+ ListModel *const listModel,
const bool extended,
const bool modal,
- gcn::ActionListener *const listener,
+ ActionListener *const listener,
const std::string &eventId):
- gcn::ActionListener(),
- gcn::BasicContainer(),
- gcn::KeyListener(),
- gcn::MouseListener(),
- gcn::FocusListener(),
- gcn::SelectionListener(),
- Widget2(widget),
+ ActionListener(),
+ gcn::BasicContainer(widget),
+ KeyListener(),
+ MouseListener(),
+ FocusListener(),
+ SelectionListener(),
mPopup(new PopupList(this, listModel, extended, modal)),
mShadowColor(getThemeColor(Theme::DROPDOWN_SHADOW)),
mHighlightColor(getThemeColor(Theme::HIGHLIGHT)),
@@ -214,7 +216,7 @@ void DropDown::updateAlpha()
}
}
-void DropDown::draw(gcn::Graphics* graphics)
+void DropDown::draw(Graphics* graphics)
{
BLOCK_START("DropDown::draw")
int h;
@@ -231,12 +233,11 @@ void DropDown::draw(gcn::Graphics* graphics)
mHighlightColor.a = alpha;
mShadowColor.a = alpha;
- gcn::ListModel *const model = mPopup->getListModel();
+ ListModel *const model = mPopup->getListModel();
if (model && mPopup->getSelected() >= 0)
{
- gcn::Font *const font = getFont();
- static_cast<Graphics *const>(graphics)->setColorAll(
- mForegroundColor, mForegroundColor2);
+ Font *const font = getFont();
+ graphics->setColorAll(mForegroundColor, mForegroundColor2);
if (mExtended)
{
const int sel = mPopup->getSelected();
@@ -250,9 +251,9 @@ void DropDown::draw(gcn::Graphics* graphics)
}
else
{
- static_cast<Graphics*>(graphics)->drawImage2(
- image, mImagePadding, (mDimension.height
- - image->getHeight()) / 2 + mPadding);
+ graphics->drawImage(image,
+ mImagePadding,
+ (mDimension.height - image->getHeight()) / 2 + mPadding);
font->drawString(graphics, model->getElementAt(sel),
image->getWidth() + mImagePadding + mSpacing, mPadding);
}
@@ -267,7 +268,7 @@ void DropDown::draw(gcn::Graphics* graphics)
if (isFocused())
{
graphics->setColor(mHighlightColor);
- graphics->drawRectangle(gcn::Rectangle(mPadding, mPadding,
+ graphics->drawRectangle(Rect(mPadding, mPadding,
mDimension.width - h - pad, h - pad));
}
@@ -286,35 +287,36 @@ void DropDown::draw(gcn::Graphics* graphics)
BLOCK_END("DropDown::draw")
}
-void DropDown::drawFrame(gcn::Graphics *graphics)
+void DropDown::drawFrame(Graphics *graphics)
{
BLOCK_START("DropDown::drawFrame")
const int bs2 = getFrameSize();
- const gcn::Rectangle &rect = mDimension;
- static_cast<Graphics*>(graphics)->drawImageRect(
- 0, 0, rect.width + bs2, rect.height + bs2, skinRect);
+ const Rect &rect = mDimension;
+ graphics->drawImageRect(0, 0,
+ rect.width + bs2, rect.height + bs2,
+ skinRect);
BLOCK_END("DropDown::drawFrame")
}
-void DropDown::drawButton(gcn::Graphics *graphics)
+void DropDown::drawButton(Graphics *graphics)
{
const int height = mDroppedDown ? mFoldedUpHeight : mDimension.height;
Image *image = buttons[mDroppedDown][mPushed];
if (image)
{
- static_cast<Graphics*>(graphics)->drawImage2(image,
+ graphics->drawImage(image,
mDimension.width - image->getWidth() - mImagePadding,
(height - image->getHeight()) / 2);
}
}
-void DropDown::keyPressed(gcn::KeyEvent& keyEvent)
+void DropDown::keyPressed(KeyEvent& keyEvent)
{
if (keyEvent.isConsumed())
return;
- const int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int actionId = keyEvent.getActionId();
switch (actionId)
{
case Input::KEY_GUI_SELECT:
@@ -356,10 +358,10 @@ void DropDown::hideDrop(bool event)
mPopup->setVisible(false);
}
-void DropDown::mousePressed(gcn::MouseEvent& mouseEvent)
+void DropDown::mousePressed(MouseEvent& mouseEvent)
{
// If we have a mouse press on the widget.
- if (mouseEvent.getButton() == gcn::MouseEvent::LEFT
+ if (mouseEvent.getButton() == MouseEvent::LEFT
&& !mDroppedDown && mouseEvent.getSource() == this)
{
mPushed = true;
@@ -373,7 +375,7 @@ void DropDown::mousePressed(gcn::MouseEvent& mouseEvent)
}
}
-void DropDown::mouseReleased(gcn::MouseEvent &mouseEvent)
+void DropDown::mouseReleased(MouseEvent &mouseEvent)
{
if (mIsDragged)
mPushed = false;
@@ -384,12 +386,12 @@ void DropDown::mouseReleased(gcn::MouseEvent &mouseEvent)
// Released outside of widget. Can happen when we have modal
// input focus.
if ((0 > y || y >= mDimension.height || x < 0 || x >= mDimension.width)
- && button == gcn::MouseEvent::LEFT)
+ && button == MouseEvent::LEFT)
{
if (mIsDragged)
foldUp();
}
- else if (button == gcn::MouseEvent::LEFT)
+ else if (button == MouseEvent::LEFT)
{
mPushed = false;
}
@@ -397,19 +399,19 @@ void DropDown::mouseReleased(gcn::MouseEvent &mouseEvent)
mIsDragged = false;
}
-void DropDown::mouseDragged(gcn::MouseEvent &mouseEvent)
+void DropDown::mouseDragged(MouseEvent &mouseEvent)
{
mIsDragged = true;
mouseEvent.consume();
}
-void DropDown::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent)
+void DropDown::mouseWheelMovedUp(MouseEvent& mouseEvent)
{
setSelected(getSelected() - 1);
mouseEvent.consume();
}
-void DropDown::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent)
+void DropDown::mouseWheelMovedDown(MouseEvent& mouseEvent)
{
setSelected(getSelected() + 1);
mouseEvent.consume();
@@ -417,7 +419,7 @@ void DropDown::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent)
void DropDown::setSelectedString(const std::string &str)
{
- gcn::ListModel *const listModel = mPopup->getListModel();
+ ListModel *const listModel = mPopup->getListModel();
if (!listModel)
return;
@@ -433,7 +435,7 @@ void DropDown::setSelectedString(const std::string &str)
std::string DropDown::getSelectedString() const
{
- gcn::ListModel *const listModel = mPopup->getListModel();
+ ListModel *const listModel = mPopup->getListModel();
if (!listModel)
return "";
@@ -490,7 +492,7 @@ void DropDown::setSelected(int selected)
mPopup->setSelected(selected);
}
-void DropDown::setListModel(gcn::ListModel *const listModel)
+void DropDown::setListModel(ListModel *const listModel)
{
mPopup->setListModel(listModel);
@@ -500,30 +502,30 @@ void DropDown::setListModel(gcn::ListModel *const listModel)
adjustHeight();
}
-gcn::ListModel *DropDown::getListModel()
+ListModel *DropDown::getListModel()
{
return mPopup->getListModel();
}
-void DropDown::action(const gcn::ActionEvent &actionEvent A_UNUSED)
+void DropDown::action(const ActionEvent &actionEvent A_UNUSED)
{
foldUp();
distributeActionEvent();
}
-gcn::Rectangle DropDown::getChildrenArea()
+Rect DropDown::getChildrenArea()
{
if (mDroppedDown)
{
// Calculate the children area (with the one pixel border in mind)
- return gcn::Rectangle(1, mFoldedUpHeight + 1,
+ return Rect(1, mFoldedUpHeight + 1,
mDimension.width - 2, mDimension.height - mFoldedUpHeight - 2);
}
- return gcn::Rectangle();
+ return Rect();
}
-void DropDown::valueChanged(const gcn::SelectionEvent& event A_UNUSED)
+void DropDown::valueChanged(const SelectionEvent& event A_UNUSED)
{
}
@@ -551,7 +553,7 @@ void DropDown::distributeValueChangedEvent()
iter != mSelectionListeners.end();
++iter)
{
- gcn::SelectionEvent event(this);
+ SelectionEvent event(this);
(*iter)->valueChanged(event);
}
}
diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h
index ed93dc358..8e463a2c1 100644
--- a/src/gui/widgets/dropdown.h
+++ b/src/gui/widgets/dropdown.h
@@ -23,23 +23,19 @@
#ifndef GUI_WIDGETS_DROPDOWN_H
#define GUI_WIDGETS_DROPDOWN_H
-#include "gui/widgets/widget2.h"
+#include "gui/base/basiccontainer.hpp"
-#include <guichan/actionlistener.hpp>
-#include <guichan/basiccontainer.hpp>
-#include <guichan/focuslistener.hpp>
-#include <guichan/keylistener.hpp>
-#include <guichan/listmodel.hpp>
-#include <guichan/mouselistener.hpp>
-#include <guichan/selectionlistener.hpp>
+#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 ImageRect;
-class ListBox;
+class ListModel;
class PopupList;
-class ScrollArea;
class Skin;
/**
@@ -49,13 +45,12 @@ class Skin;
* DropDown you must give DropDown an implemented ListModel which represents
* your list.
*/
-class DropDown final : public gcn::ActionListener,
+class DropDown final : public ActionListener,
public gcn::BasicContainer,
- public gcn::KeyListener,
- public gcn::MouseListener,
- public gcn::FocusListener,
- public gcn::SelectionListener,
- public Widget2
+ public KeyListener,
+ public MouseListener,
+ public FocusListener,
+ public SelectionListener
{
public:
/**
@@ -67,10 +62,10 @@ class DropDown final : public gcn::ActionListener,
* @see ListModel, ScrollArea, ListBox.
*/
DropDown(const Widget2 *const widget,
- gcn::ListModel *const listModel,
+ ListModel *const listModel,
const bool extended = false,
const bool modal = false,
- gcn::ActionListener *const listener = nullptr,
+ ActionListener *const listener = nullptr,
const std::string &eventId = "");
A_DELETE_COPY(DropDown)
@@ -82,31 +77,31 @@ class DropDown final : public gcn::ActionListener,
*/
void updateAlpha();
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
- void drawFrame(gcn::Graphics *graphics) override final;
+ void drawFrame(Graphics *graphics) override final;
// Inherited from KeyListener
- void keyPressed(gcn::KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& keyEvent) override final;
// Inherited from MouseListener
- void mousePressed(gcn::MouseEvent& mouseEvent) override final;
+ void mousePressed(MouseEvent& mouseEvent) override final;
- void mouseReleased(gcn::MouseEvent& mouseEvent) override final;
+ void mouseReleased(MouseEvent& mouseEvent) override final;
- void mouseDragged(gcn::MouseEvent& mouseEvent) override final;
+ void mouseDragged(MouseEvent& mouseEvent) override final;
- void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedUp(MouseEvent& mouseEvent) override final;
- void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedDown(MouseEvent& mouseEvent) override final;
void setSelectedString(const std::string &str);
std::string getSelectedString() const A_WARN_UNUSED;
- void valueChanged(const gcn::SelectionEvent& event) override final;
+ void valueChanged(const SelectionEvent& event) override final;
void updateSelection();
@@ -122,17 +117,17 @@ class DropDown final : public gcn::ActionListener,
void setSelected(int selected);
- void setListModel(gcn::ListModel *const listModel);
+ void setListModel(ListModel *const listModel);
- gcn::ListModel *getListModel();
+ ListModel *getListModel();
void addSelectionListener(SelectionListener* listener);
void removeSelectionListener(SelectionListener* selectionListener);
- gcn::Rectangle getChildrenArea() override;
+ Rect getChildrenArea() override;
- void action(const gcn::ActionEvent &actionEvent) override;
+ void action(const ActionEvent &actionEvent) override;
void distributeValueChangedEvent();
@@ -142,11 +137,11 @@ class DropDown final : public gcn::ActionListener,
*
* @param graphics a Graphics object to draw with.
*/
- void drawButton(gcn::Graphics *graphics);
+ void drawButton(Graphics *graphics);
PopupList *mPopup;
- gcn::Color mShadowColor;
- gcn::Color mHighlightColor;
+ Color mShadowColor;
+ Color mHighlightColor;
int mPadding;
int mImagePadding;
int mSpacing;
diff --git a/src/gui/widgets/dropshortcutcontainer.cpp b/src/gui/widgets/dropshortcutcontainer.cpp
index 73547b770..c8e4bc2d9 100644
--- a/src/gui/widgets/dropshortcutcontainer.cpp
+++ b/src/gui/widgets/dropshortcutcontainer.cpp
@@ -36,12 +36,12 @@
#include "resources/image.h"
-#include <guichan/font.hpp>
+#include "gui/font.h"
#include "debug.h"
-DropShortcutContainer::DropShortcutContainer():
- ShortcutContainer(),
+DropShortcutContainer::DropShortcutContainer(Widget2 *const widget):
+ ShortcutContainer(widget),
mItemClicked(false),
mItemPopup(new ItemPopup),
mEquipedColor(getThemeColor(Theme::ITEM_EQUIPPED)),
@@ -94,7 +94,7 @@ void DropShortcutContainer::setWidget2(const Widget2 *const widget)
mUnEquipedColor2 = getThemeColor(Theme::ITEM_NOT_EQUIPPED_OUTLINE);
}
-void DropShortcutContainer::draw(gcn::Graphics *graphics)
+void DropShortcutContainer::draw(Graphics *graphics)
{
if (!dropShortcut)
return;
@@ -107,8 +107,7 @@ void DropShortcutContainer::draw(gcn::Graphics *graphics)
mBackgroundImg->setAlpha(mAlpha);
}
- Graphics *const g = static_cast<Graphics*>(graphics);
- drawBackground(g);
+ drawBackground(graphics);
const Inventory *const inv = PlayerInfo::getInventory();
if (!inv)
@@ -117,7 +116,7 @@ void DropShortcutContainer::draw(gcn::Graphics *graphics)
return;
}
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
for (unsigned i = 0; i < mMaxItems; i++)
{
@@ -144,12 +143,12 @@ void DropShortcutContainer::draw(gcn::Graphics *graphics)
caption = "Eq.";
image->setAlpha(1.0F);
- g->drawImage2(image, itemX, itemY);
+ graphics->drawImage(image, itemX, itemY);
if (item->isEquipped())
- g->setColorAll(mEquipedColor, mEquipedColor2);
+ graphics->setColorAll(mEquipedColor, mEquipedColor2);
else
- g->setColorAll(mUnEquipedColor, mUnEquipedColor2);
- font->drawString(g, caption,
+ graphics->setColorAll(mUnEquipedColor, mUnEquipedColor2);
+ font->drawString(graphics, caption,
itemX + (mBoxWidth - font->getWidth(caption)) / 2,
itemY + mBoxHeight - 14);
}
@@ -158,12 +157,12 @@ void DropShortcutContainer::draw(gcn::Graphics *graphics)
BLOCK_END("DropShortcutContainer::draw")
}
-void DropShortcutContainer::mouseDragged(gcn::MouseEvent &event)
+void DropShortcutContainer::mouseDragged(MouseEvent &event)
{
if (!dropShortcut)
return;
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
if (dragDrop.isEmpty() && mItemClicked)
{
@@ -197,7 +196,7 @@ void DropShortcutContainer::mouseDragged(gcn::MouseEvent &event)
}
}
-void DropShortcutContainer::mousePressed(gcn::MouseEvent &event)
+void DropShortcutContainer::mousePressed(MouseEvent &event)
{
if (!dropShortcut || !inventoryWindow)
return;
@@ -208,7 +207,7 @@ void DropShortcutContainer::mousePressed(gcn::MouseEvent &event)
return;
const int eventButton = event.getButton();
- if (eventButton == gcn::MouseEvent::LEFT)
+ if (eventButton == MouseEvent::LEFT)
{
if (dropShortcut->getItem(index) > 0)
{
@@ -224,7 +223,7 @@ void DropShortcutContainer::mousePressed(gcn::MouseEvent &event)
}
}
}
- else if (eventButton == gcn::MouseEvent::RIGHT)
+ else if (eventButton == MouseEvent::RIGHT)
{
const Inventory *const inv = PlayerInfo::getInventory();
if (!inv)
@@ -238,12 +237,12 @@ void DropShortcutContainer::mousePressed(gcn::MouseEvent &event)
}
}
-void DropShortcutContainer::mouseReleased(gcn::MouseEvent &event)
+void DropShortcutContainer::mouseReleased(MouseEvent &event)
{
if (!dropShortcut)
return;
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
if (dropShortcut->isItemSelected())
dropShortcut->setItemSelected(-1);
@@ -270,7 +269,7 @@ void DropShortcutContainer::mouseReleased(gcn::MouseEvent &event)
}
// Show ItemTooltip
-void DropShortcutContainer::mouseMoved(gcn::MouseEvent &event)
+void DropShortcutContainer::mouseMoved(MouseEvent &event)
{
if (!dropShortcut)
return;
@@ -303,13 +302,13 @@ void DropShortcutContainer::mouseMoved(gcn::MouseEvent &event)
}
}
-void DropShortcutContainer::mouseExited(gcn::MouseEvent &event A_UNUSED)
+void DropShortcutContainer::mouseExited(MouseEvent &event A_UNUSED)
{
if (mItemPopup)
mItemPopup->setVisible(false);
}
-void DropShortcutContainer::widgetHidden(const gcn::Event &event A_UNUSED)
+void DropShortcutContainer::widgetHidden(const Event &event A_UNUSED)
{
if (mItemPopup)
mItemPopup->setVisible(false);
diff --git a/src/gui/widgets/dropshortcutcontainer.h b/src/gui/widgets/dropshortcutcontainer.h
index b5a144cba..1888292de 100644
--- a/src/gui/widgets/dropshortcutcontainer.h
+++ b/src/gui/widgets/dropshortcutcontainer.h
@@ -38,7 +38,7 @@ class DropShortcutContainer final : public ShortcutContainer
/**
* Constructor. Initializes the graphic.
*/
- DropShortcutContainer();
+ explicit DropShortcutContainer(Widget2 *const widget);
A_DELETE_COPY(DropShortcutContainer)
@@ -50,28 +50,28 @@ class DropShortcutContainer final : public ShortcutContainer
/**
* Draws the items.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
/**
* Handles mouse when dragged.
*/
- void mouseDragged(gcn::MouseEvent &event) override final;
+ void mouseDragged(MouseEvent &event) override final;
/**
* Handles mouse when pressed.
*/
- void mousePressed(gcn::MouseEvent &event) override final;
+ void mousePressed(MouseEvent &event) override final;
/**
* Handles mouse release.
*/
- void mouseReleased(gcn::MouseEvent &event) override final;
+ void mouseReleased(MouseEvent &event) override final;
- void widgetHidden(const gcn::Event &event) override final;
+ void widgetHidden(const Event &event) override final;
- void mouseExited(gcn::MouseEvent &event) override final;
+ void mouseExited(MouseEvent &event) override final;
- void mouseMoved(gcn::MouseEvent &event) override final;
+ void mouseMoved(MouseEvent &event) override final;
void setWidget2(const Widget2 *const widget) override final;
@@ -79,10 +79,10 @@ class DropShortcutContainer final : public ShortcutContainer
bool mItemClicked;
ItemPopup *mItemPopup;
- gcn::Color mEquipedColor;
- gcn::Color mEquipedColor2;
- gcn::Color mUnEquipedColor;
- gcn::Color mUnEquipedColor2;
+ Color mEquipedColor;
+ Color mEquipedColor2;
+ Color mUnEquipedColor;
+ Color mUnEquipedColor2;
};
#endif // GUI_WIDGETS_DROPSHORTCUTCONTAINER_H
diff --git a/src/gui/widgets/emotepage.cpp b/src/gui/widgets/emotepage.cpp
index f2f84ed56..139082815 100644
--- a/src/gui/widgets/emotepage.cpp
+++ b/src/gui/widgets/emotepage.cpp
@@ -34,10 +34,9 @@ namespace
} // namespace
EmotePage::EmotePage(const Widget2 *const widget) :
- gcn::Widget(),
- Widget2(widget),
- gcn::MouseListener(),
- gcn::WidgetListener(),
+ Widget(widget),
+ MouseListener(),
+ WidgetListener(),
mEmotes(ResourceManager::getInstance()->getImageSet(
"graphics/sprites/chatemotes.png", emoteWidth, emoteHeight)),
mVertexes(new ImageCollection),
@@ -59,7 +58,7 @@ EmotePage::~EmotePage()
mVertexes = nullptr;
}
-void EmotePage::draw(gcn::Graphics *graphics)
+void EmotePage::draw(Graphics *graphics)
{
BLOCK_START("EmotePage::draw")
@@ -68,7 +67,6 @@ void EmotePage::draw(gcn::Graphics *graphics)
const std::vector<Image*> &images = mEmotes->getImages();
- Graphics *const g = static_cast<Graphics*>(graphics);
const unsigned int width = mDimension.width;
unsigned int x = 0;
unsigned int y = 0;
@@ -84,7 +82,7 @@ void EmotePage::draw(gcn::Graphics *graphics)
const Image *const image = *it;
if (image)
{
- g->calcTileCollection(mVertexes, image, x, y);
+ graphics->calcTileCollection(mVertexes, image, x, y);
x += emoteWidth;
if (x + emoteWidth > width)
{
@@ -94,7 +92,7 @@ void EmotePage::draw(gcn::Graphics *graphics)
}
}
}
- g->drawTileCollection(mVertexes);
+ graphics->drawTileCollection(mVertexes);
}
else
{
@@ -103,7 +101,7 @@ void EmotePage::draw(gcn::Graphics *graphics)
const Image *const image = *it;
if (image)
{
- g->drawImage2(image, x, y);
+ graphics->drawImage(image, x, y);
x += emoteWidth;
if (x + emoteWidth > width)
{
@@ -117,7 +115,7 @@ void EmotePage::draw(gcn::Graphics *graphics)
BLOCK_END("EmotePage::draw")
}
-void EmotePage::mousePressed(gcn::MouseEvent &mouseEvent)
+void EmotePage::mousePressed(MouseEvent &mouseEvent)
{
mSelectedIndex = getIndexFromGrid(mouseEvent.getX(), mouseEvent.getY());
distributeActionEvent();
@@ -140,12 +138,12 @@ void EmotePage::resetAction()
mSelectedIndex = -1;
}
-void EmotePage::widgetResized(const gcn::Event &event A_UNUSED)
+void EmotePage::widgetResized(const Event &event A_UNUSED)
{
mRedraw = true;
}
-void EmotePage::widgetMoved(const gcn::Event &event A_UNUSED)
+void EmotePage::widgetMoved(const Event &event A_UNUSED)
{
mRedraw = true;
}
diff --git a/src/gui/widgets/emotepage.h b/src/gui/widgets/emotepage.h
index 132cfb8e9..2ce50f1fc 100644
--- a/src/gui/widgets/emotepage.h
+++ b/src/gui/widgets/emotepage.h
@@ -21,18 +21,16 @@
#ifndef GUI_WIDGETS_EMOTEPAGE_H
#define GUI_WIDGETS_EMOTEPAGE_H
-#include "gui/widgets/widget2.h"
+#include "listeners/mouselistener.h"
+#include "listeners/widgetlistener.h"
-#include <guichan/mouselistener.hpp>
-#include <guichan/widget.hpp>
-#include <guichan/widgetlistener.hpp>
+#include "gui/widgets/widget.h"
#include "localconsts.h"
-class EmotePage final : public gcn::Widget,
- public Widget2,
- public gcn::MouseListener,
- public gcn::WidgetListener
+class EmotePage final : public Widget,
+ public MouseListener,
+ public WidgetListener
{
public:
explicit EmotePage(const Widget2 *const widget);
@@ -41,15 +39,15 @@ class EmotePage final : public gcn::Widget,
~EmotePage();
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
- void mousePressed(gcn::MouseEvent &mouseEvent) override final;
+ void mousePressed(MouseEvent &mouseEvent) override final;
int getIndexFromGrid(const int x, const int y) const;
- void widgetResized(const gcn::Event &event A_UNUSED) override final;
+ void widgetResized(const Event &event A_UNUSED) override final;
- void widgetMoved(const gcn::Event &event A_UNUSED) override final;
+ void widgetMoved(const Event &event A_UNUSED) override final;
void resetAction();
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
index d080a6072..296f21126 100644
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ b/src/gui/widgets/emoteshortcutcontainer.cpp
@@ -27,20 +27,21 @@
#include "input/inputmanager.h"
+#include "gui/font.h"
#include "gui/viewport.h"
#include "gui/popups/textpopup.h"
#include "resources/image.h"
-#include <guichan/font.hpp>
+#include "resources/db/emotedb.h"
#include "debug.h"
static const int MAX_ITEMS = 48;
-EmoteShortcutContainer::EmoteShortcutContainer():
- ShortcutContainer(),
+EmoteShortcutContainer::EmoteShortcutContainer(Widget2 *const widget) :
+ ShortcutContainer(widget),
mEmoteImg(),
mEmotePopup(new TextPopup),
mEmoteClicked(false),
@@ -99,7 +100,7 @@ void EmoteShortcutContainer::setWidget2(const Widget2 *const widget)
mForegroundColor2 = getThemeColor(Theme::TEXT_OUTLINE);
}
-void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
+void EmoteShortcutContainer::draw(Graphics *graphics)
{
if (!emoteShortcut)
return;
@@ -112,11 +113,10 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
mAlpha = client->getGuiAlpha();
}
- Graphics *const g = static_cast<Graphics *const>(graphics);
- gcn::Font *const font = getFont();
- drawBackground(g);
+ Font *const font = getFont();
+ drawBackground(graphics);
- g->setColorAll(mForegroundColor, mForegroundColor2);
+ graphics->setColorAll(mForegroundColor, mForegroundColor2);
for (unsigned i = 0; i < mMaxItems; i++)
{
const int emoteX = (i % mGridWidth) * mBoxWidth;
@@ -126,7 +126,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
const std::string key = inputManager.getKeyValueString(
Input::KEY_EMOTE_1 + i);
- font->drawString(g, key, emoteX + 2, emoteY + 2);
+ font->drawString(graphics, key, emoteX + 2, emoteY + 2);
}
unsigned sz = static_cast<unsigned>(mEmoteImg.size());
if (sz > mMaxItems)
@@ -139,7 +139,8 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
const AnimatedSprite *const sprite = emoteImg->sprite;
if (sprite)
{
- sprite->draw(g, (i % mGridWidth) * mBoxWidth + 2,
+ sprite->draw(graphics,
+ (i % mGridWidth) * mBoxWidth + 2,
(i / mGridWidth) * mBoxHeight + 10);
}
}
@@ -148,11 +149,11 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
BLOCK_END("EmoteShortcutContainer::draw")
}
-void EmoteShortcutContainer::mouseDragged(gcn::MouseEvent &event A_UNUSED)
+void EmoteShortcutContainer::mouseDragged(MouseEvent &event A_UNUSED)
{
}
-void EmoteShortcutContainer::mousePressed(gcn::MouseEvent &event)
+void EmoteShortcutContainer::mousePressed(MouseEvent &event)
{
if (!emoteShortcut)
return;
@@ -174,12 +175,12 @@ void EmoteShortcutContainer::mousePressed(gcn::MouseEvent &event)
}
}
-void EmoteShortcutContainer::mouseReleased(gcn::MouseEvent &event)
+void EmoteShortcutContainer::mouseReleased(MouseEvent &event)
{
if (!emoteShortcut)
return;
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
const int index = getIndexFromGrid(event.getX(), event.getY());
@@ -206,7 +207,7 @@ void EmoteShortcutContainer::mouseReleased(gcn::MouseEvent &event)
}
}
-void EmoteShortcutContainer::mouseMoved(gcn::MouseEvent &event)
+void EmoteShortcutContainer::mouseMoved(MouseEvent &event)
{
if (!emoteShortcut || !mEmotePopup)
return;
@@ -226,13 +227,13 @@ void EmoteShortcutContainer::mouseMoved(gcn::MouseEvent &event)
}
}
-void EmoteShortcutContainer::mouseExited(gcn::MouseEvent &event A_UNUSED)
+void EmoteShortcutContainer::mouseExited(MouseEvent &event A_UNUSED)
{
if (mEmotePopup)
mEmotePopup->setVisible(false);
}
-void EmoteShortcutContainer::widgetHidden(const gcn::Event &event A_UNUSED)
+void EmoteShortcutContainer::widgetHidden(const Event &event A_UNUSED)
{
if (mEmotePopup)
mEmotePopup->setVisible(false);
diff --git a/src/gui/widgets/emoteshortcutcontainer.h b/src/gui/widgets/emoteshortcutcontainer.h
index 2c99aaf87..a3061441f 100644
--- a/src/gui/widgets/emoteshortcutcontainer.h
+++ b/src/gui/widgets/emoteshortcutcontainer.h
@@ -24,12 +24,12 @@
#include "gui/widgets/shortcutcontainer.h"
-#include "resources/db/emotedb.h"
-
#include <vector>
class TextPopup;
+struct EmoteSprite;
+
/**
* An emote shortcut container. Used to quickly use emoticons.
*
@@ -41,7 +41,7 @@ class EmoteShortcutContainer final : public ShortcutContainer
/**
* Constructor. Initializes the graphic.
*/
- EmoteShortcutContainer();
+ explicit EmoteShortcutContainer(Widget2 *const widget);
A_DELETE_COPY(EmoteShortcutContainer)
@@ -53,28 +53,28 @@ class EmoteShortcutContainer final : public ShortcutContainer
/**
* Draws the items.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
/**
* Handles mouse when dragged.
*/
- void mouseDragged(gcn::MouseEvent &event) override final;
+ void mouseDragged(MouseEvent &event) override final;
/**
* Handles mouse when pressed.
*/
- void mousePressed(gcn::MouseEvent &event) override final;
+ void mousePressed(MouseEvent &event) override final;
/**
* Handles mouse release.
*/
- void mouseReleased(gcn::MouseEvent &event) override final;
+ void mouseReleased(MouseEvent &event) override final;
- void mouseMoved(gcn::MouseEvent &event) override final;
+ void mouseMoved(MouseEvent &event) override final;
- void mouseExited(gcn::MouseEvent &event) override final;
+ void mouseExited(MouseEvent &event) override final;
- void widgetHidden(const gcn::Event &event) override final;
+ void widgetHidden(const Event &event) override final;
void setWidget2(const Widget2 *const widget) override final;
diff --git a/src/gui/widgets/extendedlistbox.cpp b/src/gui/widgets/extendedlistbox.cpp
index bd3a35964..7245ddd19 100644
--- a/src/gui/widgets/extendedlistbox.cpp
+++ b/src/gui/widgets/extendedlistbox.cpp
@@ -20,16 +20,18 @@
#include "gui/widgets/extendedlistbox.h"
-#include "gui/widgets/extendedlistmodel.h"
+#include "gui/models/extendedlistmodel.h"
-#include <guichan/font.hpp>
-#include <guichan/graphics.hpp>
-#include <guichan/listmodel.hpp>
+#include "gui/font.h"
+
+#include "gui/models/listmodel.h"
+
+#include "render/graphics.h"
#include "debug.h"
ExtendedListBox::ExtendedListBox(const Widget2 *const widget,
- gcn::ListModel *const listModel,
+ ListModel *const listModel,
const std::string &skin,
const int rowHeight) :
ListBox(widget, listModel, skin),
@@ -47,7 +49,7 @@ ExtendedListBox::~ExtendedListBox()
{
}
-void ExtendedListBox::draw(gcn::Graphics *graphics)
+void ExtendedListBox::draw(Graphics *graphics)
{
if (!mListModel)
return;
@@ -55,10 +57,9 @@ void ExtendedListBox::draw(gcn::Graphics *graphics)
BLOCK_START("ExtendedListBox::draw")
ExtendedListModel *const model = static_cast<ExtendedListModel* const>(
mListModel);
- Graphics *const g = static_cast<Graphics *const>(graphics);
updateAlpha();
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
const int height = mRowHeight;
const int pad2 = 2 + mPadding;
@@ -133,7 +134,7 @@ void ExtendedListBox::draw(gcn::Graphics *graphics)
{
mHighlightColor.a = static_cast<int>(mAlpha * 255.0F);
graphics->setColor(mHighlightColor);
- graphics->fillRectangle(gcn::Rectangle(mPadding, minY + mPadding,
+ graphics->fillRectangle(Rect(mPadding, minY + mPadding,
width - pad2, maxY - minY + height));
}
@@ -146,13 +147,14 @@ void ExtendedListBox::draw(gcn::Graphics *graphics)
const Image *const image = model->getImageAt(row1);
if (image)
{
- g->drawImage2(image, mImagePadding, item.y + (height
- - image->getHeight()) / 2 + mPadding);
+ graphics->drawImage(image,
+ mImagePadding,
+ item.y + (height - image->getHeight()) / 2 + mPadding);
}
}
}
- g->setColorAll(mForegroundColor, mForegroundColor2);
+ graphics->setColorAll(mForegroundColor, mForegroundColor2);
for (int f = 0; f < itemsSz; ++f)
{
@@ -180,13 +182,14 @@ void ExtendedListBox::draw(gcn::Graphics *graphics)
const Image *const image = model->getImageAt(row1);
if (image)
{
- g->drawImage2(image, mImagePadding, item.y + (height
- - image->getHeight()) / 2 + mPadding);
+ graphics->drawImage(image,
+ mImagePadding,
+ item.y + (height - image->getHeight()) / 2 + mPadding);
}
}
}
- g->setColorAll(mForegroundSelectedColor, mForegroundSelectedColor2);
+ graphics->setColorAll(mForegroundSelectedColor, mForegroundSelectedColor2);
for (int f = 0; f < selSz; ++f)
{
diff --git a/src/gui/widgets/extendedlistbox.h b/src/gui/widgets/extendedlistbox.h
index 30e7a32fb..ae94cde02 100644
--- a/src/gui/widgets/extendedlistbox.h
+++ b/src/gui/widgets/extendedlistbox.h
@@ -48,7 +48,7 @@ class ExtendedListBox final : public ListBox
* Constructor.
*/
ExtendedListBox(const Widget2 *const widget,
- gcn::ListModel *const listModel,
+ ListModel *const listModel,
const std::string &skin,
const int rowHeight = 13);
@@ -59,7 +59,7 @@ class ExtendedListBox final : public ListBox
/**
* Draws the list box.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
void adjustSize() override;
diff --git a/src/gui/widgets/flowcontainer.cpp b/src/gui/widgets/flowcontainer.cpp
index d39a7124a..e9b5c1e0c 100644
--- a/src/gui/widgets/flowcontainer.cpp
+++ b/src/gui/widgets/flowcontainer.cpp
@@ -24,9 +24,10 @@
#include "debug.h"
FlowContainer::FlowContainer(const Widget2 *const widget,
- const int boxWidth, const int boxHeight) :
+ const int boxWidth,
+ const int boxHeight) :
Container(widget),
- gcn::WidgetListener(),
+ WidgetListener(),
mBoxWidth(boxWidth),
mBoxHeight(boxHeight),
mGridWidth(1),
@@ -39,7 +40,7 @@ FlowContainer::FlowContainer(const Widget2 *const widget,
mBoxHeight = 1;
}
-void FlowContainer::widgetResized(const gcn::Event &event A_UNUSED)
+void FlowContainer::widgetResized(const Event &event A_UNUSED)
{
if (getWidth() < mBoxWidth)
{
@@ -85,12 +86,12 @@ void FlowContainer::widgetResized(const gcn::Event &event A_UNUSED)
}
}
-void FlowContainer::add(gcn::Widget *widget)
+void FlowContainer::add(Widget *widget)
{
if (!widget)
return;
Container::add(widget);
widget->setSize(mBoxWidth, mBoxHeight);
- widgetResized(gcn::Event(nullptr));
+ widgetResized(Event(nullptr));
}
diff --git a/src/gui/widgets/flowcontainer.h b/src/gui/widgets/flowcontainer.h
index 81043b450..7266bb06a 100644
--- a/src/gui/widgets/flowcontainer.h
+++ b/src/gui/widgets/flowcontainer.h
@@ -24,7 +24,7 @@
#include "gui/widgets/container.h"
-#include <guichan/widgetlistener.hpp>
+#include "listeners/widgetlistener.h"
#include "localconsts.h"
@@ -34,14 +34,15 @@
* \ingroup GUI
*/
class FlowContainer final : public Container,
- public gcn::WidgetListener
+ public WidgetListener
{
public:
/**
* Constructor. Initializes the shortcut container.
*/
FlowContainer(const Widget2 *const widget,
- const int boxWidth, const int boxHeight);
+ const int boxWidth,
+ const int boxHeight);
A_DELETE_COPY(FlowContainer)
@@ -55,7 +56,7 @@ class FlowContainer final : public Container,
* Invoked when a widget changes its size. This is used to determine
* the new height of the container.
*/
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
int getBoxWidth() const A_WARN_UNUSED
{ return mBoxWidth; }
@@ -63,7 +64,7 @@ class FlowContainer final : public Container,
int getBoxHeight() const A_WARN_UNUSED
{ return mBoxHeight; }
- void add(gcn::Widget *widget) override final;
+ void add(Widget *widget) override final;
private:
int mBoxWidth;
diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp
index ae0dd14c5..70ebb77d6 100644
--- a/src/gui/widgets/guitable.cpp
+++ b/src/gui/widgets/guitable.cpp
@@ -24,44 +24,47 @@
#include "client.h"
-#include "input/keyevent.h"
+#include "gui/gui.h"
+
+#include "events/keyevent.h"
+
#include "input/keydata.h"
#include "utils/dtor.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/graphics.hpp>
-#include <guichan/key.hpp>
+#include "listeners/actionlistener.h"
+
+#include "render/graphics.h"
#include "debug.h"
float GuiTable::mAlpha = 1.0;
-class GuiTableActionListener final : public gcn::ActionListener
+class GuiTableActionListener final : public ActionListener
{
public:
GuiTableActionListener(GuiTable *restrict _table,
- gcn::Widget *restrict _widget,
+ Widget *restrict _widget,
int _row, int _column);
A_DELETE_COPY(GuiTableActionListener)
~GuiTableActionListener();
- void action(const gcn::ActionEvent& actionEvent) override final;
+ void action(const ActionEvent& actionEvent) override final;
protected:
GuiTable *mTable;
int mRow;
int mColumn;
- gcn::Widget *mWidget;
+ Widget *mWidget;
};
GuiTableActionListener::GuiTableActionListener(GuiTable *restrict table,
- gcn::Widget *restrict widget,
+ Widget *restrict widget,
int row, int column) :
- gcn::ActionListener(),
+ ActionListener(),
mTable(table),
mRow(row),
mColumn(column),
@@ -83,8 +86,7 @@ GuiTableActionListener::~GuiTableActionListener()
}
}
-void GuiTableActionListener::action(const gcn::ActionEvent
- &actionEvent A_UNUSED)
+void GuiTableActionListener::action(const ActionEvent &actionEvent A_UNUSED)
{
mTable->setSelected(mRow, mColumn);
mTable->distributeActionEvent();
@@ -92,11 +94,11 @@ void GuiTableActionListener::action(const gcn::ActionEvent
GuiTable::GuiTable(const Widget2 *const widget,
- TableModel *const initial_model, const bool opacity) :
- gcn::Widget(),
- Widget2(widget),
- gcn::MouseListener(),
- gcn::KeyListener(),
+ TableModel *const initial_model,
+ const bool opacity) :
+ Widget(widget),
+ MouseListener(),
+ KeyListener(),
mModel(nullptr),
mTopWidget(nullptr),
mActionListeners(),
@@ -280,7 +282,7 @@ void GuiTable::installActionListeners()
{
for (int column = 0; column < columns; ++column)
{
- gcn::Widget *const widget = mModel->getElementAt(row, column);
+ Widget *const widget = mModel->getElementAt(row, column);
if (widget)
{
mActionListeners.push_back(new GuiTableActionListener(
@@ -293,7 +295,7 @@ void GuiTable::installActionListeners()
}
// -- widget ops
-void GuiTable::draw(gcn::Graphics* graphics)
+void GuiTable::draw(Graphics* graphics)
{
if (!mModel || !getRowHeight())
return;
@@ -302,7 +304,7 @@ void GuiTable::draw(gcn::Graphics* graphics)
if (client->getGuiAlpha() != mAlpha)
mAlpha = client->getGuiAlpha();
- const gcn::Rectangle &rect = mDimension;
+ const Rect &rect = mDimension;
const int width = rect.width;
const int height = rect.height;
const int y = rect.y;
@@ -310,7 +312,7 @@ void GuiTable::draw(gcn::Graphics* graphics)
{
mBackgroundColor.a = static_cast<int>(mAlpha * 255.0F);
graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(gcn::Rectangle(0, 0, width, height));
+ graphics->fillRectangle(Rect(0, 0, width, height));
}
// First, determine how many rows we need to draw,
@@ -345,11 +347,11 @@ void GuiTable::draw(gcn::Graphics* graphics)
for (unsigned c = first_column; c + 1 <= last_column1; ++c)
{
- gcn::Widget *const widget = mModel->getElementAt(r, c);
+ Widget *const widget = mModel->getElementAt(r, c);
const int cWidth = getColumnWidth(c);
if (widget)
{
- gcn::Rectangle bounds(x_offset, y_offset, cWidth, rHeight);
+ Rect bounds(x_offset, y_offset, cWidth, rHeight);
if (widget == mTopWidget)
{
@@ -367,14 +369,14 @@ void GuiTable::draw(gcn::Graphics* graphics)
if (mLinewiseMode && r == static_cast<unsigned>(
mSelectedRow) && c == 0)
{
- graphics->fillRectangle(gcn::Rectangle(0, y_offset,
+ graphics->fillRectangle(Rect(0, y_offset,
width, rHeight));
}
else if (!mLinewiseMode && mSelectedColumn > 0
&& c == static_cast<unsigned>(mSelectedColumn)
&& r == static_cast<unsigned>(mSelectedRow))
{
- graphics->fillRectangle(gcn::Rectangle(
+ graphics->fillRectangle(Rect(
x_offset, y_offset, cWidth, rHeight));
}
}
@@ -391,7 +393,7 @@ void GuiTable::draw(gcn::Graphics* graphics)
if (mTopWidget)
{
- const gcn::Rectangle &bounds = mTopWidget->getDimension();
+ const Rect &bounds = mTopWidget->getDimension();
graphics->pushClipArea(bounds);
mTopWidget->draw(graphics);
graphics->popClipArea();
@@ -399,28 +401,28 @@ void GuiTable::draw(gcn::Graphics* graphics)
BLOCK_END("GuiTable::draw")
}
-void GuiTable::moveToTop(gcn::Widget *widget)
+void GuiTable::moveToTop(Widget *widget)
{
- gcn::Widget::moveToTop(widget);
+ Widget::moveToTop(widget);
mTopWidget = widget;
}
-void GuiTable::moveToBottom(gcn::Widget *widget)
+void GuiTable::moveToBottom(Widget *widget)
{
- gcn::Widget::moveToBottom(widget);
+ Widget::moveToBottom(widget);
if (widget == mTopWidget)
mTopWidget = nullptr;
}
-gcn::Rectangle GuiTable::getChildrenArea()
+Rect GuiTable::getChildrenArea()
{
- return gcn::Rectangle(0, 0, mDimension.width, mDimension.height);
+ return Rect(0, 0, mDimension.width, mDimension.height);
}
// -- KeyListener notifications
-void GuiTable::keyPressed(gcn::KeyEvent& keyEvent)
+void GuiTable::keyPressed(KeyEvent& keyEvent)
{
- const int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int action = keyEvent.getActionId();
if (action == Input::KEY_GUI_SELECT)
{
@@ -462,12 +464,12 @@ void GuiTable::keyPressed(gcn::KeyEvent& keyEvent)
}
// -- MouseListener notifications
-void GuiTable::mousePressed(gcn::MouseEvent& mouseEvent)
+void GuiTable::mousePressed(MouseEvent& mouseEvent)
{
if (!mModel || !mSelectable)
return;
- if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
+ if (mouseEvent.getButton() == MouseEvent::LEFT)
{
const int row = getRowForY(mouseEvent.getY());
const int column = getColumnForX(mouseEvent.getX());
@@ -483,7 +485,7 @@ void GuiTable::mousePressed(gcn::MouseEvent& mouseEvent)
}
}
-void GuiTable::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent)
+void GuiTable::mouseWheelMovedUp(MouseEvent& mouseEvent)
{
if (isFocused())
{
@@ -494,7 +496,7 @@ void GuiTable::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent)
}
}
-void GuiTable::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent)
+void GuiTable::mouseWheelMovedDown(MouseEvent& mouseEvent)
{
if (isFocused())
{
@@ -503,9 +505,9 @@ void GuiTable::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent)
}
}
-void GuiTable::mouseDragged(gcn::MouseEvent& mouseEvent)
+void GuiTable::mouseDragged(MouseEvent& mouseEvent)
{
- if (mouseEvent.getButton() != gcn::MouseEvent::LEFT)
+ if (mouseEvent.getButton() != MouseEvent::LEFT)
return;
// Make table selection update on drag
@@ -530,7 +532,7 @@ void GuiTable::modelUpdated(const bool completed)
}
}
-gcn::Widget *GuiTable::getWidgetAt(int x, int y)
+Widget *GuiTable::getWidgetAt(int x, int y)
{
const int row = getRowForY(y);
const int column = getColumnForX(x);
@@ -540,7 +542,7 @@ gcn::Widget *GuiTable::getWidgetAt(int x, int y)
if (mModel && row > -1 && column > -1)
{
- gcn::Widget *const w = mModel->getElementAt(row, column);
+ Widget *const w = mModel->getElementAt(row, column);
if (w && w->isFocusable())
return w;
else
@@ -586,14 +588,14 @@ int GuiTable::getColumnForX(int x) const
return column;
}
-void GuiTable::_setFocusHandler(gcn::FocusHandler* focusHandler)
+void GuiTable::_setFocusHandler(FocusHandler* focusHandler)
{
// add check for focusHandler. may be need remove it?
if (!mModel || !focusHandler)
return;
- gcn::Widget::_setFocusHandler(focusHandler);
+ Widget::_setFocusHandler(focusHandler);
const int rows = mModel->getRows();
const int cols = mModel->getColumns();
@@ -601,7 +603,7 @@ void GuiTable::_setFocusHandler(gcn::FocusHandler* focusHandler)
{
for (int c = 0; c < cols ; ++c)
{
- gcn::Widget *const w = mModel->getElementAt(r, c);
+ Widget *const w = mModel->getElementAt(r, c);
if (w)
w->_setFocusHandler(focusHandler);
}
@@ -612,5 +614,5 @@ void GuiTable::requestFocus()
{
if (!mFocusHandler)
return;
- gcn::Widget::requestFocus();
+ Widget::requestFocus();
}
diff --git a/src/gui/widgets/guitable.h b/src/gui/widgets/guitable.h
index 5529ce842..fb0c34784 100644
--- a/src/gui/widgets/guitable.h
+++ b/src/gui/widgets/guitable.h
@@ -25,12 +25,12 @@
#include "localconsts.h"
-#include "gui/widgets/tablemodel.h"
-#include "gui/widgets/widget2.h"
+#include "gui/models/tablemodel.h"
-#include <guichan/keylistener.hpp>
-#include <guichan/mouselistener.hpp>
-#include <guichan/widget.hpp>
+#include "listeners/keylistener.h"
+#include "listeners/mouselistener.h"
+
+#include "gui/widgets/widget.h"
#include <vector>
@@ -45,10 +45,9 @@ class GuiTableActionListener;
*
* \ingroup GUI
*/
-class GuiTable final : public gcn::Widget,
- public Widget2,
- public gcn::MouseListener,
- public gcn::KeyListener,
+class GuiTable final : public Widget,
+ public MouseListener,
+ public KeyListener,
public TableModelListener
{
// so that the action listener can call distributeActionEvent
@@ -94,7 +93,7 @@ public:
void setWrappingEnabled(bool wrappingEnabled)
{ mWrappingEnabled = wrappingEnabled; }
- gcn::Rectangle getChildrenArea() override final A_WARN_UNUSED;
+ Rect getChildrenArea() override final A_WARN_UNUSED;
/**
* Toggle whether to use linewise selection mode, in which the table selects
@@ -113,18 +112,18 @@ public:
}
// Inherited from Widget
- void draw(gcn::Graphics* graphics) override final;
+ void draw(Graphics* graphics) override final;
- gcn::Widget *getWidgetAt(int x, int y) override final A_WARN_UNUSED;
+ Widget *getWidgetAt(int x, int y) override final A_WARN_UNUSED;
- void moveToTop(gcn::Widget *child) override final;
+ void moveToTop(Widget *child) override final;
- void moveToBottom(gcn::Widget *child) override final;
+ void moveToBottom(Widget *child) override final;
- void _setFocusHandler(gcn::FocusHandler* focusHandler) override final;
+ void _setFocusHandler(FocusHandler* focusHandler) override final;
// Inherited from KeyListener
- void keyPressed(gcn::KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& keyEvent) override final;
/**
* Sets the table to be opaque, that is sets the table
@@ -145,13 +144,13 @@ public:
{ return mOpaque; }
// Inherited from MouseListener
- void mousePressed(gcn::MouseEvent& mouseEvent) override final;
+ void mousePressed(MouseEvent& mouseEvent) override final;
- void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedUp(MouseEvent& mouseEvent) override final;
- void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedDown(MouseEvent& mouseEvent) override final;
- void mouseDragged(gcn::MouseEvent& mouseEvent) override final;
+ void mouseDragged(MouseEvent& mouseEvent) override final;
// Constraints inherited from TableModelListener
void modelUpdated(const bool completed) override final;
@@ -181,7 +180,7 @@ private:
TableModel *mModel;
/** If someone moves a fresh widget to the top, we must display it. */
- gcn::Widget *mTopWidget;
+ Widget *mTopWidget;
/** Vector for compactness; used as a list in practice. */
std::vector<GuiTableActionListener *> mActionListeners;
@@ -189,7 +188,7 @@ private:
/**
* Holds the background color of the table.
*/
- gcn::Color mHighlightColor;
+ Color mHighlightColor;
int mSelectedRow;
int mSelectedColumn;
diff --git a/src/gui/widgets/horizontcontainer.cpp b/src/gui/widgets/horizontcontainer.cpp
index a4c95169a..8e3be9662 100644
--- a/src/gui/widgets/horizontcontainer.cpp
+++ b/src/gui/widgets/horizontcontainer.cpp
@@ -24,9 +24,10 @@
#include "debug.h"
HorizontContainer::HorizontContainer(const Widget2 *const widget,
- const int height, const int spacing) :
+ const int height,
+ const int spacing) :
Container(widget),
- gcn::WidgetListener(),
+ WidgetListener(),
mSpacing(spacing),
mCount(0),
mLastX(spacing)
@@ -35,12 +36,12 @@ HorizontContainer::HorizontContainer(const Widget2 *const widget,
addWidgetListener(this);
}
-void HorizontContainer::add(gcn::Widget *widget)
+void HorizontContainer::add(Widget *widget)
{
add(widget, mSpacing);
}
-void HorizontContainer::add(gcn::Widget *const widget, const int spacing)
+void HorizontContainer::add(Widget *const widget, const int spacing)
{
if (!widget)
return;
@@ -58,6 +59,6 @@ void HorizontContainer::clear()
mCount = 0;
}
-void HorizontContainer::widgetResized(const gcn::Event &event A_UNUSED)
+void HorizontContainer::widgetResized(const Event &event A_UNUSED)
{
}
diff --git a/src/gui/widgets/horizontcontainer.h b/src/gui/widgets/horizontcontainer.h
index be30220e8..bef3d0b00 100644
--- a/src/gui/widgets/horizontcontainer.h
+++ b/src/gui/widgets/horizontcontainer.h
@@ -24,7 +24,7 @@
#include "gui/widgets/container.h"
-#include <guichan/widgetlistener.hpp>
+#include "listeners/widgetlistener.h"
#include "localconsts.h"
@@ -33,21 +33,23 @@
*
* This container places it's contents veritcally.
*/
-class HorizontContainer final : public Container, public gcn::WidgetListener
+class HorizontContainer final : public Container,
+ public WidgetListener
{
public:
HorizontContainer(const Widget2 *const widget,
- const int height, const int spacing);
+ const int height,
+ const int spacing);
A_DELETE_COPY(HorizontContainer)
- void add(gcn::Widget *widget) override final;
+ void add(Widget *widget) override final;
- void add(gcn::Widget *const widget, const int spacing);
+ void add(Widget *const widget, const int spacing);
void clear() override;
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
protected:
int mSpacing;
diff --git a/src/gui/widgets/icon.cpp b/src/gui/widgets/icon.cpp
index 4fb511c85..9a86fc9bf 100644
--- a/src/gui/widgets/icon.cpp
+++ b/src/gui/widgets/icon.cpp
@@ -22,14 +22,16 @@
#include "gui/widgets/icon.h"
+#include "gui/gui.h"
+
#include "resources/image.h"
#include "resources/resourcemanager.h"
#include "debug.h"
-Icon::Icon(const Widget2 *const widget, const std::string &file) :
- gcn::Widget(),
- Widget2(widget),
+Icon::Icon(const Widget2 *const widget,
+ const std::string &file) :
+ Widget(widget),
mImage(ResourceManager::getInstance()->getImage(file))
{
if (mImage)
@@ -39,9 +41,9 @@ Icon::Icon(const Widget2 *const widget, const std::string &file) :
}
}
-Icon::Icon(const Widget2 *const widget, Image *const image) :
- gcn::Widget(),
- Widget2(widget),
+Icon::Icon(const Widget2 *const widget,
+ Image *const image) :
+ Widget(widget),
mImage(image)
{
if (mImage)
@@ -67,13 +69,12 @@ void Icon::setImage(Image *const image)
}
}
-void Icon::draw(gcn::Graphics *g)
+void Icon::draw(Graphics *graphics)
{
BLOCK_START("Icon::draw")
if (mImage)
{
- Graphics *const graphics = static_cast<Graphics*>(g);
- graphics->drawImage2(mImage,
+ graphics->drawImage(mImage,
(mDimension.width - mImage->mBounds.w) / 2,
(mDimension.height - mImage->mBounds.h) / 2);
}
diff --git a/src/gui/widgets/icon.h b/src/gui/widgets/icon.h
index 1cbd3158c..1e015f8e6 100644
--- a/src/gui/widgets/icon.h
+++ b/src/gui/widgets/icon.h
@@ -23,9 +23,7 @@
#ifndef GUI_WIDGETS_ICON_H
#define GUI_WIDGETS_ICON_H
-#include "gui/widgets/widget2.h"
-
-#include <guichan/widget.hpp>
+#include "gui/widgets/widget.h"
#include "localconsts.h"
@@ -36,19 +34,20 @@ class Image;
*
* \ingroup GUI
*/
-class Icon final : public gcn::Widget,
- public Widget2
+class Icon final : public Widget
{
public:
/**
* Constructor.
*/
- Icon(const Widget2 *const widget, const std::string &filename);
+ Icon(const Widget2 *const widget,
+ const std::string &filename);
/**
* Constructor, uses an existing Image.
*/
- Icon(const Widget2 *const widget, Image *const image);
+ Icon(const Widget2 *const widget,
+ Image *const image);
A_DELETE_COPY(Icon)
@@ -68,7 +67,7 @@ class Icon final : public gcn::Widget,
/**
* Draws the Icon.
*/
- void draw(gcn::Graphics *g) override final;
+ void draw(Graphics *g) override final;
private:
Image *mImage;
diff --git a/src/gui/widgets/inttextfield.cpp b/src/gui/widgets/inttextfield.cpp
index e50bd232b..160cfe5de 100644
--- a/src/gui/widgets/inttextfield.cpp
+++ b/src/gui/widgets/inttextfield.cpp
@@ -26,15 +26,19 @@
#include "gui/sdlinput.h"
#endif
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
#include "utils/stringutils.h"
#include "debug.h"
-IntTextField::IntTextField(const Widget2 *const widget, const int def,
- const int min, const int max,
- const bool enabled, const int width) :
+IntTextField::IntTextField(const Widget2 *const widget,
+ const int def,
+ const int min,
+ const int max,
+ const bool enabled,
+ const int width) :
TextField(widget, toString(def)),
mMin(0),
mMax(0),
@@ -49,9 +53,9 @@ IntTextField::IntTextField(const Widget2 *const widget, const int def,
setWidth(width);
}
-void IntTextField::keyPressed(gcn::KeyEvent &event)
+void IntTextField::keyPressed(KeyEvent &event)
{
- const int action = static_cast<KeyEvent*>(&event)->getActionId();
+ const int action = event.getActionId();
if (action == Input::KEY_GUI_DELETE || action == Input::KEY_GUI_BACKSPACE)
{
@@ -67,7 +71,7 @@ void IntTextField::keyPressed(gcn::KeyEvent &event)
if (val != Key::TEXTINPUT)
return;
- const std::string str = static_cast<KeyEvent*>(&event)->getText();
+ const std::string str = event.getText();
if (str.empty())
return;
const size_t sz = str.size();
diff --git a/src/gui/widgets/inttextfield.h b/src/gui/widgets/inttextfield.h
index 3493cf52b..91b076e30 100644
--- a/src/gui/widgets/inttextfield.h
+++ b/src/gui/widgets/inttextfield.h
@@ -34,9 +34,12 @@ class IntTextField final : public TextField
/**
* Constructor, sets default value.
*/
- explicit IntTextField(const Widget2 *const widget, const int def = 0,
- const int min = 0, const int max = 0,
- const bool enabled = true, const int width = 0);
+ explicit IntTextField(const Widget2 *const widget,
+ const int def = 0,
+ const int min = 0,
+ const int max = 0,
+ const bool enabled = true,
+ const int width = 0);
A_DELETE_COPY(IntTextField)
@@ -68,7 +71,7 @@ class IntTextField final : public TextField
/**
* Responds to key presses.
*/
- void keyPressed(gcn::KeyEvent &event) override final;
+ void keyPressed(KeyEvent &event) override final;
private:
int mMin; /**< Minimum value */
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 2014d3ffe..fe666e6f7 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -46,8 +46,8 @@
#include "resources/image.h"
-#include <guichan/font.hpp>
-#include <guichan/selectionlistener.hpp>
+#include "gui/font.h"
+#include "listeners/selectionlistener.h"
#include <algorithm>
@@ -158,11 +158,10 @@ namespace
ItemContainer::ItemContainer(const Widget2 *const widget,
Inventory *const inventory,
const bool forceQuantity) :
- gcn::Widget(),
- Widget2(widget),
- gcn::KeyListener(),
- gcn::MouseListener(),
- gcn::WidgetListener(),
+ Widget(widget),
+ KeyListener(),
+ MouseListener(),
+ WidgetListener(),
mInventory(inventory),
mSelImg(Theme::getImageFromThemeXml("item_selection.xml", "")),
mProtectedImg(Theme::getImageFromTheme("lock.png")),
@@ -227,7 +226,7 @@ ItemContainer::~ItemContainer()
void ItemContainer::logic()
{
BLOCK_START("ItemContainer::logic")
- gcn::Widget::logic();
+ Widget::logic();
if (!mInventory)
{
@@ -245,14 +244,13 @@ void ItemContainer::logic()
BLOCK_END("ItemContainer::logic")
}
-void ItemContainer::draw(gcn::Graphics *graphics)
+void ItemContainer::draw(Graphics *graphics)
{
if (!mInventory || !mShowMatrix)
return;
BLOCK_START("ItemContainer::draw")
- Graphics *const g = static_cast<Graphics *const>(graphics);
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
for (int j = 0; j < mGridRows; j++)
{
@@ -278,16 +276,18 @@ void ItemContainer::draw(gcn::Graphics *graphics)
if (mShowMatrix[itemIndex] == mSelectedIndex)
{
if (mSelImg)
- g->drawImage2(mSelImg, itemX, itemY);
+ graphics->drawImage(mSelImg, itemX, itemY);
}
image->setAlpha(1.0F); // ensure the image if fully drawn...
- g->drawImage2(image, itemX + mPaddingItemX,
+ graphics->drawImage(image,
+ itemX + mPaddingItemX,
itemY + mPaddingItemY);
if (mProtectedImg && PlayerInfo::isItemProtected(
item->getId()))
{
- g->drawImage2(mProtectedImg,
- itemX + mPaddingItemX, itemY + mPaddingItemY);
+ graphics->drawImage(mProtectedImg,
+ itemX + mPaddingItemX,
+ itemY + mPaddingItemY);
}
}
}
@@ -324,11 +324,11 @@ void ItemContainer::draw(gcn::Graphics *graphics)
}
if (item->isEquipped())
- g->setColorAll(mEquipedColor, mEquipedColor2);
+ graphics->setColorAll(mEquipedColor, mEquipedColor2);
else
- g->setColorAll(mUnEquipedColor, mUnEquipedColor2);
+ graphics->setColorAll(mUnEquipedColor, mUnEquipedColor2);
- font->drawString(g, caption,
+ font->drawString(graphics, caption,
itemX + (mBoxWidth - font->getWidth(caption)) / 2,
itemY + mEquippedTextPadding);
}
@@ -373,7 +373,7 @@ void ItemContainer::distributeValueChangedEvent()
{
if (*i)
{
- gcn::SelectionEvent event(this);
+ SelectionEvent event(this);
(*i)->valueChanged(event);
}
}
@@ -385,15 +385,15 @@ void ItemContainer::hidePopup()
mItemPopup->setVisible(false);
}
-void ItemContainer::keyPressed(gcn::KeyEvent &event A_UNUSED)
+void ItemContainer::keyPressed(KeyEvent &event A_UNUSED)
{
}
-void ItemContainer::keyReleased(gcn::KeyEvent &event A_UNUSED)
+void ItemContainer::keyReleased(KeyEvent &event A_UNUSED)
{
}
-void ItemContainer::mousePressed(gcn::MouseEvent &event)
+void ItemContainer::mousePressed(MouseEvent &event)
{
if (!mInventory)
return;
@@ -401,7 +401,7 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
const int button = event.getButton();
mClicks = event.getClickCount();
- if (button == gcn::MouseEvent::LEFT || button == gcn::MouseEvent::RIGHT)
+ if (button == MouseEvent::LEFT || button == MouseEvent::RIGHT)
{
const int index = getSlotIndex(event.getX(), event.getY());
if (index == Inventory::NO_SLOT_INDEX)
@@ -467,13 +467,13 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event)
}
}
-void ItemContainer::mouseDragged(gcn::MouseEvent &event A_UNUSED)
+void ItemContainer::mouseDragged(MouseEvent &event A_UNUSED)
{
if (mSelectionStatus != SEL_NONE)
mSelectionStatus = SEL_DRAGGING;
}
-void ItemContainer::mouseReleased(gcn::MouseEvent &event)
+void ItemContainer::mouseReleased(MouseEvent &event)
{
if (mClicks == 2)
return;
@@ -593,7 +593,7 @@ void ItemContainer::mouseReleased(gcn::MouseEvent &event)
}
}
-void ItemContainer::mouseMoved(gcn::MouseEvent &event)
+void ItemContainer::mouseMoved(MouseEvent &event)
{
if (!mInventory)
return;
@@ -612,12 +612,12 @@ void ItemContainer::mouseMoved(gcn::MouseEvent &event)
}
}
-void ItemContainer::mouseExited(gcn::MouseEvent &event A_UNUSED)
+void ItemContainer::mouseExited(MouseEvent &event A_UNUSED)
{
mItemPopup->setVisible(false);
}
-void ItemContainer::widgetResized(const gcn::Event &event A_UNUSED)
+void ItemContainer::widgetResized(const Event &event A_UNUSED)
{
mGridColumns = std::max(1, mDimension.width / mBoxWidth);
adjustHeight();
diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h
index f4a73af9f..f7bc44849 100644
--- a/src/gui/widgets/itemcontainer.h
+++ b/src/gui/widgets/itemcontainer.h
@@ -23,12 +23,11 @@
#ifndef GUI_WIDGETS_ITEMCONTAINER_H
#define GUI_WIDGETS_ITEMCONTAINER_H
-#include "gui/widgets/widget2.h"
+#include "listeners/keylistener.h"
+#include "listeners/mouselistener.h"
+#include "listeners/widgetlistener.h"
-#include <guichan/keylistener.hpp>
-#include <guichan/mouselistener.hpp>
-#include <guichan/widget.hpp>
-#include <guichan/widgetlistener.hpp>
+#include "gui/widgets/widget.h"
#include <list>
@@ -38,22 +37,17 @@ class Image;
class Inventory;
class Item;
class ItemPopup;
-
-namespace gcn
-{
- class SelectionListener;
-}
+class SelectionListener;
/**
* An item container. Used to show items in inventory and trade dialog.
*
* \ingroup GUI
*/
-class ItemContainer final : public gcn::Widget,
- public Widget2,
- public gcn::KeyListener,
- public gcn::MouseListener,
- public gcn::WidgetListener
+class ItemContainer final : public Widget,
+ public KeyListener,
+ public MouseListener,
+ public WidgetListener
{
public:
/**
@@ -85,21 +79,21 @@ class ItemContainer final : public gcn::Widget,
/**
* Draws the items.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
// KeyListener
- void keyPressed(gcn::KeyEvent &event) override final;
- void keyReleased(gcn::KeyEvent &event) override final;
+ void keyPressed(KeyEvent &event) override final;
+ void keyReleased(KeyEvent &event) override final;
// MouseListener
- void mousePressed(gcn::MouseEvent &event) override final;
- void mouseDragged(gcn::MouseEvent &event) override final;
- void mouseReleased(gcn::MouseEvent &event) override final;
- void mouseMoved(gcn::MouseEvent &event) override final;
- void mouseExited(gcn::MouseEvent &event) override final;
+ 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 gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
/**
* Returns the selected item.
@@ -115,14 +109,14 @@ class ItemContainer final : public gcn::Widget,
* Adds a listener to the list that's notified each time a change to
* the selection occurs.
*/
- void addSelectionListener(gcn::SelectionListener *listener)
+ 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(gcn::SelectionListener *listener)
+ void removeSelectionListener(SelectionListener *listener)
{ mSelectionListeners.remove(listener); }
void setFilter(const int tag);
@@ -187,11 +181,11 @@ class ItemContainer final : public gcn::Widget,
ItemPopup *mItemPopup;
int *mShowMatrix;
Skin *mSkin;
- gcn::Color mEquipedColor;
- gcn::Color mEquipedColor2;
- gcn::Color mUnEquipedColor;
- gcn::Color mUnEquipedColor2;
- typedef std::list<gcn::SelectionListener*> SelectionListenerList;
+ Color mEquipedColor;
+ Color mEquipedColor2;
+ Color mUnEquipedColor;
+ Color mUnEquipedColor2;
+ typedef std::list<SelectionListener*> SelectionListenerList;
typedef SelectionListenerList::iterator SelectionListenerIterator;
SelectionListenerList mSelectionListeners;
int mGridColumns;
diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp
index cb74a658b..2cf27ae30 100644
--- a/src/gui/widgets/itemlinkhandler.cpp
+++ b/src/gui/widgets/itemlinkhandler.cpp
@@ -35,25 +35,27 @@
#include "resources/db/itemdb.h"
-#include <string>
+#include "listeners/actionlistener.h"
+
+#include "input/mouseinput.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/mouseinput.hpp>
+#include <string>
#include "debug.h"
namespace
{
- struct OpenUrlListener : public gcn::ActionListener
+ struct OpenUrlListener : public ActionListener
{
OpenUrlListener() :
+ ActionListener(),
url()
{
}
A_DELETE_COPY(OpenUrlListener)
- void action(const gcn::ActionEvent &event) override final
+ void action(const ActionEvent &event) override final
{
if (event.getId() == "yes")
openBrowser(url);
@@ -64,6 +66,7 @@ namespace
} // namespace
ItemLinkHandler::ItemLinkHandler() :
+ LinkHandler(),
mItemPopup(new ItemPopup)
{
mItemPopup->postInit();
@@ -75,8 +78,7 @@ ItemLinkHandler::~ItemLinkHandler()
mItemPopup = nullptr;
}
-void ItemLinkHandler::handleLink(const std::string &link,
- gcn::MouseEvent *event)
+void ItemLinkHandler::handleLink(const std::string &link, MouseEvent *event)
{
if (strStartWith(link, "http://") || strStartWith(link, "https://"))
{
@@ -86,7 +88,7 @@ void ItemLinkHandler::handleLink(const std::string &link,
replaceAll(url, " ", "");
listener.url = url;
const int button = event->getButton();
- if (button == gcn::MouseInput::LEFT)
+ if (button == MouseInput::LEFT)
{
ConfirmDialog *const confirmDlg = new ConfirmDialog(
// TRANSLATORS: dialog message
@@ -94,7 +96,7 @@ void ItemLinkHandler::handleLink(const std::string &link,
confirmDlg->postInit();
confirmDlg->addActionListener(&listener);
}
- else if (button == gcn::MouseInput::RIGHT)
+ else if (button == MouseInput::RIGHT)
{
if (viewport)
viewport->showLinkPopup(url);
diff --git a/src/gui/widgets/itemlinkhandler.h b/src/gui/widgets/itemlinkhandler.h
index 4e55a8f72..39e811721 100644
--- a/src/gui/widgets/itemlinkhandler.h
+++ b/src/gui/widgets/itemlinkhandler.h
@@ -39,7 +39,7 @@ class ItemLinkHandler final : public LinkHandler
~ItemLinkHandler();
void handleLink(const std::string &link,
- gcn::MouseEvent *event) override final;
+ MouseEvent *event) override final;
private:
ItemPopup *mItemPopup;
diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp
index cdeb83af7..b9dc3bec8 100644
--- a/src/gui/widgets/itemshortcutcontainer.cpp
+++ b/src/gui/widgets/itemshortcutcontainer.cpp
@@ -33,6 +33,7 @@
#include "input/inputmanager.h"
+#include "gui/font.h"
#include "gui/viewport.h"
#include "gui/popups/itempopup.h"
@@ -45,12 +46,11 @@
#include "resources/image.h"
-#include <guichan/font.hpp>
-
#include "debug.h"
-ItemShortcutContainer::ItemShortcutContainer(const unsigned number) :
- ShortcutContainer(),
+ItemShortcutContainer::ItemShortcutContainer(Widget2 *const widget,
+ const unsigned number) :
+ ShortcutContainer(widget),
mItemClicked(false),
mNumber(number),
mItemPopup(new ItemPopup),
@@ -112,7 +112,7 @@ void ItemShortcutContainer::setWidget2(const Widget2 *const widget)
mForegroundColor2 = getThemeColor(Theme::TEXT_OUTLINE);
}
-void ItemShortcutContainer::draw(gcn::Graphics *graphics)
+void ItemShortcutContainer::draw(Graphics *graphics)
{
BLOCK_START("ItemShortcutContainer::draw")
const ItemShortcut *const selShortcut = itemShortcut[mNumber];
@@ -129,9 +129,8 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
mAlpha = client->getGuiAlpha();
}
- Graphics *const g = static_cast<Graphics*>(graphics);
- gcn::Font *const font = getFont();
- drawBackground(g);
+ Font *const font = getFont();
+ drawBackground(graphics);
const Inventory *const inv = PlayerInfo::getInventory();
if (!inv)
@@ -149,8 +148,8 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
// Draw item keyboard shortcut.
const std::string key = inputManager.getKeyValueString(
Input::KEY_SHORTCUT_1 + i);
- g->setColorAll(mForegroundColor, mForegroundColor);
- font->drawString(g, key, itemX + 2, itemY + 2);
+ graphics->setColorAll(mForegroundColor, mForegroundColor);
+ font->drawString(graphics, key, itemX + 2, itemY + 2);
const int itemId = selShortcut->getItem(i);
const unsigned char itemColor = selShortcut->getItemColor(i);
@@ -175,12 +174,17 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
caption = "Eq.";
image->setAlpha(1.0F);
- g->drawImage2(image, itemX, itemY);
+ graphics->drawImage(image, itemX, itemY);
if (item->isEquipped())
- g->setColorAll(mEquipedColor, mEquipedColor2);
+ {
+ graphics->setColorAll(mEquipedColor, mEquipedColor2);
+ }
else
- g->setColorAll(mUnEquipedColor, mUnEquipedColor2);
- font->drawString(g, caption,
+ {
+ graphics->setColorAll(mUnEquipedColor,
+ mUnEquipedColor2);
+ }
+ font->drawString(graphics, caption,
itemX + (mBoxWidth - font->getWidth(caption)) / 2,
itemY + mBoxHeight - 14);
}
@@ -199,11 +203,11 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
if (image)
{
image->setAlpha(1.0F);
- g->drawImage2(image, itemX, itemY);
+ graphics->drawImage(image, itemX, itemY);
}
}
- font->drawString(g, spell->getSymbol(),
+ font->drawString(graphics, spell->getSymbol(),
itemX + 2, itemY + mBoxHeight / 2);
}
}
@@ -218,10 +222,10 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
if (image)
{
image->setAlpha(1.0F);
- g->drawImage2(image, itemX, itemY);
+ graphics->drawImage(image, itemX, itemY);
}
- font->drawString(g, skill->data->shortName, itemX + 2,
+ font->drawString(graphics, skill->data->shortName, itemX + 2,
itemY + mBoxHeight / 2);
}
}
@@ -229,13 +233,13 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
BLOCK_END("ItemShortcutContainer::draw")
}
-void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event)
+void ItemShortcutContainer::mouseDragged(MouseEvent &event)
{
ItemShortcut *const selShortcut = itemShortcut[mNumber];
if (!selShortcut)
return;
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
if (dragDrop.isEmpty() && mItemClicked)
{
@@ -317,7 +321,7 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event)
}
}
-void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event)
+void ItemShortcutContainer::mousePressed(MouseEvent &event)
{
ItemShortcut *const selShortcut = itemShortcut[mNumber];
if (!selShortcut)
@@ -328,7 +332,7 @@ void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event)
if (index == -1)
return;
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
// Stores the selected item if theirs one.
if (selShortcut->isItemSelected() && inventoryWindow &&
@@ -346,7 +350,7 @@ void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event)
mItemClicked = true;
}
}
- else if (event.getButton() == gcn::MouseEvent::RIGHT)
+ else if (event.getButton() == MouseEvent::RIGHT)
{
if (viewport && selShortcut)
{
@@ -356,13 +360,13 @@ void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event)
}
}
-void ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event)
+void ItemShortcutContainer::mouseReleased(MouseEvent &event)
{
ItemShortcut *const selShortcut = itemShortcut[mNumber];
if (!selShortcut)
return;
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
if (selShortcut->isItemSelected())
selShortcut->setItemSelected(-1);
@@ -398,7 +402,7 @@ void ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event)
}
}
-void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event)
+void ItemShortcutContainer::mouseMoved(MouseEvent &event)
{
const ItemShortcut *const selShortcut = itemShortcut[mNumber];
if (!selShortcut)
@@ -455,7 +459,7 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event)
}
// Hide ItemTooltip
-void ItemShortcutContainer::mouseExited(gcn::MouseEvent &event A_UNUSED)
+void ItemShortcutContainer::mouseExited(MouseEvent &event A_UNUSED)
{
if (mItemPopup)
mItemPopup->setVisible(false);
@@ -463,7 +467,7 @@ void ItemShortcutContainer::mouseExited(gcn::MouseEvent &event A_UNUSED)
mSpellPopup->setVisible(false);
}
-void ItemShortcutContainer::widgetHidden(const gcn::Event &event A_UNUSED)
+void ItemShortcutContainer::widgetHidden(const Event &event A_UNUSED)
{
if (mItemPopup)
mItemPopup->setVisible(false);
diff --git a/src/gui/widgets/itemshortcutcontainer.h b/src/gui/widgets/itemshortcutcontainer.h
index f9ec24589..07c3ef822 100644
--- a/src/gui/widgets/itemshortcutcontainer.h
+++ b/src/gui/widgets/itemshortcutcontainer.h
@@ -39,7 +39,8 @@ class ItemShortcutContainer final : public ShortcutContainer
/**
* Constructor. Initializes the graphic.
*/
- explicit ItemShortcutContainer(const unsigned number);
+ ItemShortcutContainer(Widget2 *const widget,
+ const unsigned number);
A_DELETE_COPY(ItemShortcutContainer)
@@ -51,28 +52,28 @@ class ItemShortcutContainer final : public ShortcutContainer
/**
* Draws the items.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
/**
* Handles mouse when dragged.
*/
- void mouseDragged(gcn::MouseEvent &event) override final;
+ void mouseDragged(MouseEvent &event) override final;
/**
* Handles mouse when pressed.
*/
- void mousePressed(gcn::MouseEvent &event) override final;
+ void mousePressed(MouseEvent &event) override final;
/**
* Handles mouse release.
*/
- void mouseReleased(gcn::MouseEvent &event) override final;
+ void mouseReleased(MouseEvent &event) override final;
- void widgetHidden(const gcn::Event &event) override final;
+ void widgetHidden(const Event &event) override final;
- void mouseExited(gcn::MouseEvent &event) override final;
+ void mouseExited(MouseEvent &event) override final;
- void mouseMoved(gcn::MouseEvent &event) override final;
+ void mouseMoved(MouseEvent &event) override final;
void setWidget2(const Widget2 *const widget);
@@ -82,10 +83,10 @@ class ItemShortcutContainer final : public ShortcutContainer
ItemPopup *mItemPopup;
SpellPopup *mSpellPopup;
- gcn::Color mEquipedColor;
- gcn::Color mEquipedColor2;
- gcn::Color mUnEquipedColor;
- gcn::Color mUnEquipedColor2;
+ 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
index 7a16b800c..56c949964 100644
--- a/src/gui/widgets/label.cpp
+++ b/src/gui/widgets/label.cpp
@@ -21,7 +21,8 @@
#include "gui/widgets/label.h"
-#include <guichan/font.hpp>
+#include "gui/font.h"
+#include "gui/gui.h"
#include "debug.h"
@@ -29,16 +30,15 @@ Skin *Label::mSkin = nullptr;
int Label::mInstances = 0;
Label::Label(const Widget2 *const widget) :
- gcn::Label(),
- Widget2(widget),
+ gcn::Label(widget),
mPadding(0)
{
init();
}
-Label::Label(const Widget2 *const widget, const std::string &caption) :
- gcn::Label(caption),
- Widget2(widget),
+Label::Label(const Widget2 *const widget,
+ const std::string &caption) :
+ gcn::Label(widget, caption),
mPadding(0)
{
init();
@@ -76,13 +76,13 @@ void Label::init()
mPadding = 0;
}
-void Label::draw(gcn::Graphics* graphics)
+void Label::draw(Graphics* graphics)
{
BLOCK_START("Label::draw")
int textX;
- const gcn::Rectangle &rect = mDimension;
+ const Rect &rect = mDimension;
const int textY = rect.height / 2 - getFont()->getHeight() / 2;
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
switch (mAlignment)
{
@@ -101,28 +101,27 @@ void Label::draw(gcn::Graphics* graphics)
break;
}
- static_cast<Graphics*>(graphics)->setColorAll(
- mForegroundColor, mForegroundColor2);
+ graphics->setColorAll(mForegroundColor, mForegroundColor2);
font->drawString(graphics, mCaption, textX, textY);
BLOCK_END("Label::draw")
}
void Label::adjustSize()
{
- const gcn::Font *const font = getFont();
+ const Font *const font = getFont();
const int pad2 = 2 * mPadding;
setWidth(font->getWidth(mCaption) + pad2);
setHeight(font->getHeight() + pad2);
}
-void Label::setForegroundColor(const gcn::Color &color)
+void Label::setForegroundColor(const Color &color)
{
mForegroundColor = color;
mForegroundColor2 = color;
}
-void Label::setForegroundColorAll(const gcn::Color &color1,
- const gcn::Color &color2)
+void Label::setForegroundColorAll(const Color &color1,
+ const Color &color2)
{
mForegroundColor = color1;
mForegroundColor2 = color2;
@@ -130,7 +129,7 @@ void Label::setForegroundColorAll(const gcn::Color &color1,
void Label::resizeTo(const int maxSize, const int minSize)
{
- const gcn::Font *const font = getFont();
+ const Font *const font = getFont();
const int pad2 = 2 * mPadding;
setHeight(font->getHeight() + pad2);
diff --git a/src/gui/widgets/label.h b/src/gui/widgets/label.h
index 3546f17b4..616f6cc79 100644
--- a/src/gui/widgets/label.h
+++ b/src/gui/widgets/label.h
@@ -22,9 +22,7 @@
#ifndef GUI_WIDGETS_LABEL_H
#define GUI_WIDGETS_LABEL_H
-#include "gui/widgets/widget2.h"
-
-#include <guichan/widgets/label.hpp>
+#include "gui/base/widgets/label.hpp"
#include "localconsts.h"
@@ -36,7 +34,7 @@ class Skin;
*
* \ingroup GUI
*/
-class Label final : public gcn::Label, public Widget2
+class Label final : public gcn::Label
{
public:
/**
@@ -48,7 +46,8 @@ class Label final : public gcn::Label, public Widget2
* Constructor. This version of the constructor sets the label with an
* inintialization string.
*/
- Label(const Widget2 *const widget, const std::string &caption);
+ Label(const Widget2 *const widget,
+ const std::string &caption);
A_DELETE_COPY(Label)
@@ -59,14 +58,14 @@ class Label final : public gcn::Label, public Widget2
/**
* Draws the label.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
void adjustSize();
- void setForegroundColor(const gcn::Color &color);
+ void setForegroundColor(const Color &color);
- void setForegroundColorAll(const gcn::Color &color1,
- const gcn::Color &color2);
+ void setForegroundColorAll(const Color &color1,
+ const Color &color2);
void resizeTo(const int maxSize, const int minSize);
diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp
index d9a818e0f..24722510b 100644
--- a/src/gui/widgets/layout.cpp
+++ b/src/gui/widgets/layout.cpp
@@ -24,6 +24,8 @@
#include "logger.h"
+#include "gui/base/widgets/container.hpp"
+
#include <cassert>
#include "debug.h"
@@ -34,7 +36,7 @@ ContainerPlacer ContainerPlacer::at(const int x, const int y)
}
LayoutCell &ContainerPlacer::operator()
- (const int x, const int y, gcn::Widget *const wg, const int w, const int h)
+ (const int x, const int y, Widget *const wg, const int w, const int h)
{
mContainer->add(wg);
return mCell->place(wg, x, y, w, h);
@@ -78,7 +80,7 @@ void LayoutCell::reflow(int nx, int ny, int nw, int nh)
if (mType == ARRAY)
mArray->reflow(nx, ny, nw, nh);
else
- mWidget->setDimension(gcn::Rectangle(nx, ny, nw, nh));
+ mWidget->setDimension(Rect(nx, ny, nw, nh));
}
void LayoutCell::computeSizes()
@@ -201,7 +203,7 @@ void LayoutArray::extend(const int x, const int y, const int w, const int h)
cell.mExtent[1] = h;
}
-LayoutCell &LayoutArray::place(gcn::Widget *const widget, const int x,
+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);
diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h
index b03c10c1f..288c282a0 100644
--- a/src/gui/widgets/layout.h
+++ b/src/gui/widgets/layout.h
@@ -25,12 +25,17 @@
#include "localconsts.h"
-#include <guichan/widgets/container.hpp>
-
#include <vector>
class LayoutCell;
+namespace gcn
+{
+ class Container;
+}
+
+class Widget;
+
/**
* This class is a helper for adding widgets to nested tables in a window.
*/
@@ -57,7 +62,7 @@ class ContainerPlacer final
* Adds the given widget to the container and places it in the layout.
* @see LayoutArray::place
*/
- LayoutCell &operator()(const int x, const int y, gcn::Widget *const wg,
+ LayoutCell &operator()(const int x, const int y, Widget *const wg,
const int w = 1, const int h = 1);
private:
@@ -90,7 +95,7 @@ class LayoutArray final
* @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(gcn::Widget *const widget, const int x, const int y,
+ LayoutCell &place(Widget *const widget, const int x, const int y,
const int w = 1, const int h = 1);
/**
@@ -216,7 +221,7 @@ class LayoutCell
/**
* @see LayoutArray::place
*/
- LayoutCell &place(gcn::Widget *wg, int x, int y, int w = 1, int h = 1)
+ LayoutCell &place(Widget *wg, int x, int y, int w = 1, int h = 1)
{ return getArray().place(wg, x, y, w, h); }
/**
@@ -294,7 +299,7 @@ class LayoutCell
union
{
- gcn::Widget *mWidget;
+ Widget *mWidget;
LayoutArray *mArray;
};
diff --git a/src/gui/widgets/layouthelper.cpp b/src/gui/widgets/layouthelper.cpp
index b0fb75adc..c225c7543 100644
--- a/src/gui/widgets/layouthelper.cpp
+++ b/src/gui/widgets/layouthelper.cpp
@@ -22,10 +22,12 @@
#include "gui/widgets/layouthelper.h"
+#include "gui/base/widgets/container.hpp"
+
#include "debug.h"
LayoutHelper::LayoutHelper(gcn::Container *const container) :
- gcn::WidgetListener(),
+ WidgetListener(),
mLayout(),
mContainer(container)
{
@@ -43,7 +45,7 @@ const Layout &LayoutHelper::getLayout() const
}
LayoutCell &LayoutHelper::place(const int x, const int y,
- gcn::Widget *const wg,
+ Widget *const wg,
const int w, const int h)
{
mContainer->add(wg);
@@ -61,9 +63,9 @@ void LayoutHelper::reflowLayout(int w, int h)
mContainer->setSize(w, h);
}
-void LayoutHelper::widgetResized(const gcn::Event &event A_UNUSED)
+void LayoutHelper::widgetResized(const Event &event A_UNUSED)
{
- const gcn::Rectangle area = mContainer->getChildrenArea();
+ 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
index 4f8ed8708..32e3d9e34 100644
--- a/src/gui/widgets/layouthelper.h
+++ b/src/gui/widgets/layouthelper.h
@@ -25,14 +25,14 @@
#include "gui/widgets/layout.h"
-#include <guichan/widgetlistener.hpp>
+#include "listeners/widgetlistener.h"
/**
* 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 gcn::WidgetListener
+class LayoutHelper final : public WidgetListener
{
public:
/**
@@ -67,7 +67,7 @@ class LayoutHelper final : public gcn::WidgetListener
/**
* Adds a widget to the container and sets it at given cell.
*/
- LayoutCell &place(const int x, const int y, gcn::Widget *const wg,
+ LayoutCell &place(const int x, const int y, Widget *const wg,
const int w = 1, const int h = 1);
/**
@@ -78,7 +78,7 @@ class LayoutHelper final : public gcn::WidgetListener
/**
* Called whenever the managed container changes size.
*/
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
private:
Layout mLayout; /**< Layout handler */
diff --git a/src/gui/widgets/linkhandler.h b/src/gui/widgets/linkhandler.h
index 744ff0b29..b373162a3 100644
--- a/src/gui/widgets/linkhandler.h
+++ b/src/gui/widgets/linkhandler.h
@@ -25,7 +25,7 @@
#include <string>
-#include <guichan/mouselistener.hpp>
+#include "listeners/mouselistener.h"
/**
* A simple interface to windows that need to handle links from BrowserBox
@@ -38,7 +38,7 @@ class LinkHandler
{ }
virtual void handleLink(const std::string &link,
- gcn::MouseEvent *event) = 0;
+ MouseEvent *event) = 0;
};
#endif // GUI_WIDGETS_LINKHANDLER_H
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp
index 9a1a074b3..c6e431634 100644
--- a/src/gui/widgets/listbox.cpp
+++ b/src/gui/widgets/listbox.cpp
@@ -24,25 +24,26 @@
#include "client.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
+#include "gui/focushandler.h"
+#include "gui/font.h"
#include "gui/gui.h"
-#include <guichan/focushandler.hpp>
-#include <guichan/font.hpp>
-#include <guichan/graphics.hpp>
-#include <guichan/listmodel.hpp>
+#include "gui/models/listmodel.h"
+
+#include "render/graphics.h"
#include "debug.h"
float ListBox::mAlpha = 1.0;
ListBox::ListBox(const Widget2 *const widget,
- gcn::ListModel *const listModel,
+ ListModel *const listModel,
const std::string &skin) :
- gcn::ListBox(listModel),
- Widget2(widget),
+ gcn::ListBox(widget, listModel),
mHighlightColor(getThemeColor(Theme::HIGHLIGHT)),
mForegroundSelectedColor(getThemeColor(Theme::LISTBOX_SELECTED)),
mForegroundSelectedColor2(getThemeColor(Theme::LISTBOX_SELECTED_OUTLINE)),
@@ -68,7 +69,7 @@ ListBox::ListBox(const Widget2 *const widget,
mItemPadding = mSkin->getOption("itemPadding");
}
- const gcn::Font *const font = getFont();
+ const Font *const font = getFont();
if (font)
mRowHeight = font->getHeight() + 2 * mItemPadding;
else
@@ -98,18 +99,17 @@ void ListBox::updateAlpha()
mAlpha = alpha;
}
-void ListBox::draw(gcn::Graphics *graphics)
+void ListBox::draw(Graphics *graphics)
{
if (!mListModel)
return;
BLOCK_START("ListBox::draw")
updateAlpha();
- Graphics *const g = static_cast<Graphics*>(graphics);
mHighlightColor.a = static_cast<int>(mAlpha * 255.0F);
graphics->setColor(mHighlightColor);
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
const int rowHeight = getRowHeight();
const int width = mDimension.width;
@@ -118,11 +118,11 @@ void ListBox::draw(gcn::Graphics *graphics)
// Draw filled rectangle around the selected list element
if (mSelected >= 0)
{
- graphics->fillRectangle(gcn::Rectangle(mPadding,
+ graphics->fillRectangle(Rect(mPadding,
rowHeight * mSelected + mPadding,
mDimension.width - 2 * mPadding, rowHeight));
- g->setColorAll(mForegroundSelectedColor,
+ graphics->setColorAll(mForegroundSelectedColor,
mForegroundSelectedColor2);
const std::string str = mListModel->getElementAt(mSelected);
font->drawString(graphics, str,
@@ -130,7 +130,7 @@ void ListBox::draw(gcn::Graphics *graphics)
mSelected * rowHeight + mPadding + mItemPadding);
}
// Draw the list elements
- g->setColorAll(mForegroundColor, mForegroundColor2);
+ graphics->setColorAll(mForegroundColor, mForegroundColor2);
const int sz = mListModel->getNumberOfElements();
for (int i = 0, y = mPadding + mItemPadding;
i < sz; ++i, y += rowHeight)
@@ -148,18 +148,18 @@ void ListBox::draw(gcn::Graphics *graphics)
// Draw filled rectangle around the selected list element
if (mSelected >= 0)
{
- graphics->fillRectangle(gcn::Rectangle(mPadding,
+ graphics->fillRectangle(Rect(mPadding,
rowHeight * mSelected + mPadding,
mDimension.width - 2 * mPadding, rowHeight));
- g->setColorAll(mForegroundSelectedColor,
+ graphics->setColorAll(mForegroundSelectedColor,
mForegroundSelectedColor2);
const std::string str = mListModel->getElementAt(mSelected);
font->drawString(graphics, str, mPadding,
mSelected * rowHeight + mPadding + mItemPadding);
}
// Draw the list elements
- g->setColorAll(mForegroundColor, mForegroundColor2);
+ graphics->setColorAll(mForegroundColor, mForegroundColor2);
const int sz = mListModel->getNumberOfElements();
for (int i = 0, y = mPadding + mItemPadding; i < sz;
++i, y += rowHeight)
@@ -174,9 +174,9 @@ void ListBox::draw(gcn::Graphics *graphics)
BLOCK_END("ListBox::draw")
}
-void ListBox::keyPressed(gcn::KeyEvent &keyEvent)
+void ListBox::keyPressed(KeyEvent &keyEvent)
{
- const int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int action = keyEvent.getActionId();
if (action == Input::KEY_GUI_SELECT)
{
distributeActionEvent();
@@ -213,20 +213,20 @@ void ListBox::keyPressed(gcn::KeyEvent &keyEvent)
// Don't do anything on scrollwheel. ScrollArea will deal with that.
-void ListBox::mouseWheelMovedUp(gcn::MouseEvent &mouseEvent A_UNUSED)
+void ListBox::mouseWheelMovedUp(MouseEvent &mouseEvent A_UNUSED)
{
}
-void ListBox::mouseWheelMovedDown(gcn::MouseEvent &mouseEvent A_UNUSED)
+void ListBox::mouseWheelMovedDown(MouseEvent &mouseEvent A_UNUSED)
{
}
-void ListBox::mousePressed(gcn::MouseEvent &event)
+void ListBox::mousePressed(MouseEvent &event)
{
mPressedIndex = getSelectionByMouse(event.getY());
}
-void ListBox::mouseReleased(gcn::MouseEvent &event)
+void ListBox::mouseReleased(MouseEvent &event)
{
if (mPressedIndex != getSelectionByMouse(event.getY()))
return;
@@ -261,18 +261,18 @@ void ListBox::mouseReleased(gcn::MouseEvent &event)
mPressedIndex = -2;
}
-void ListBox::mouseReleased1(const gcn::MouseEvent &mouseEvent)
+void ListBox::mouseReleased1(const MouseEvent &mouseEvent)
{
- if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
+ if (mouseEvent.getButton() == MouseEvent::LEFT)
{
setSelected(std::max(0, getSelectionByMouse(mouseEvent.getY())));
distributeActionEvent();
}
}
-void ListBox::mouseDragged(gcn::MouseEvent &event)
+void ListBox::mouseDragged(MouseEvent &event)
{
- if (event.getButton() != gcn::MouseEvent::LEFT || getRowHeight() == 0)
+ if (event.getButton() != MouseEvent::LEFT || getRowHeight() == 0)
return;
// Make list selection update on drag, but guard against negative y
diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h
index b1a2f0da5..64faa6eb5 100644
--- a/src/gui/widgets/listbox.h
+++ b/src/gui/widgets/listbox.h
@@ -23,13 +23,17 @@
#ifndef GUI_WIDGETS_LISTBOX_H
#define GUI_WIDGETS_LISTBOX_H
-#include "gui/widgets/widget2.h"
+#include "gui/color.h"
-#include <guichan/widgets/listbox.hpp>
+#include "gui/base/widgets/listbox.hpp"
#include "localconsts.h"
class Skin;
+class KeyEvent;
+class ListModel;
+class MouseEvent;
+class Widget2;
/**
* A list box, meant to be used inside a scroll area. Same as the Guichan list
@@ -38,15 +42,14 @@ class Skin;
*
* \ingroup GUI
*/
-class ListBox : public gcn::ListBox,
- public Widget2
+class ListBox : public gcn::ListBox
{
public:
/**
* Constructor.
*/
ListBox(const Widget2 *const widget,
- gcn::ListModel *const listModel,
+ ListModel *const listModel,
const std::string &skin);
A_DELETE_COPY(ListBox)
@@ -58,7 +61,7 @@ class ListBox : public gcn::ListBox,
/**
* Draws the list box.
*/
- void draw(gcn::Graphics *graphics) override;
+ void draw(Graphics *graphics) override;
/**
* Update the alpha value to the graphic components.
@@ -67,21 +70,21 @@ class ListBox : public gcn::ListBox,
// Inherited from KeyListener
- void keyPressed(gcn::KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& keyEvent) override final;
// Inherited from MouseListener
- void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedUp(MouseEvent& mouseEvent) override final;
- void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedDown(MouseEvent& mouseEvent) override final;
- void mousePressed(gcn::MouseEvent &event) override;
+ void mousePressed(MouseEvent &event) override;
- void mouseReleased(gcn::MouseEvent &event) override;
+ void mouseReleased(MouseEvent &event) override;
- void mouseReleased1(const gcn::MouseEvent &event);
+ void mouseReleased1(const MouseEvent &event);
- void mouseDragged(gcn::MouseEvent &event) override;
+ void mouseDragged(MouseEvent &event) override;
void refocus();
@@ -107,9 +110,9 @@ class ListBox : public gcn::ListBox,
{ mRowHeight = n; }
protected:
- gcn::Color mHighlightColor;
- gcn::Color mForegroundSelectedColor;
- gcn::Color mForegroundSelectedColor2;
+ Color mHighlightColor;
+ Color mForegroundSelectedColor;
+ Color mForegroundSelectedColor2;
int mOldSelected;
int mPadding;
int mPressedIndex;
diff --git a/src/gui/widgets/passwordfield.cpp b/src/gui/widgets/passwordfield.cpp
index b2ee6ccad..1b562b7f0 100644
--- a/src/gui/widgets/passwordfield.cpp
+++ b/src/gui/widgets/passwordfield.cpp
@@ -31,7 +31,7 @@ PasswordField::PasswordField(const Widget2 *const widget,
{
}
-void PasswordField::draw(gcn::Graphics *graphics)
+void PasswordField::draw(Graphics *graphics)
{
BLOCK_START("PasswordField::draw")
// std::string uses cow, thus cheap copy
diff --git a/src/gui/widgets/passwordfield.h b/src/gui/widgets/passwordfield.h
index 322d71b8b..f72350763 100644
--- a/src/gui/widgets/passwordfield.h
+++ b/src/gui/widgets/passwordfield.h
@@ -44,7 +44,7 @@ class PasswordField final : public TextField
/**
* Draws the password field.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
protected:
int mPasswordChar;
diff --git a/src/gui/widgets/playerbox.cpp b/src/gui/widgets/playerbox.cpp
index 6fda932bf..7ef543511 100644
--- a/src/gui/widgets/playerbox.cpp
+++ b/src/gui/widgets/playerbox.cpp
@@ -26,14 +26,17 @@
#include "being/being.h"
+#include "gui/gui.h"
+
#include "resources/image.h"
#include "debug.h"
-PlayerBox::PlayerBox(Being *const being, const std::string &skin,
+PlayerBox::PlayerBox(Widget2 *const widget,
+ Being *const being,
+ const std::string &skin,
const std::string &selectedSkin) :
- Widget2(),
- ScrollArea(),
+ ScrollArea(widget),
mBeing(being),
mAlpha(1.0),
mBackground(),
@@ -48,9 +51,10 @@ PlayerBox::PlayerBox(Being *const being, const std::string &skin,
init(skin, selectedSkin);
}
-PlayerBox::PlayerBox(const std::string &skin,
+PlayerBox::PlayerBox(Widget2 *const widget,
+ const std::string &skin,
const std::string &selectedSkin) :
- ScrollArea(),
+ ScrollArea(widget),
mBeing(nullptr),
mAlpha(1.0),
mBackground(),
@@ -107,7 +111,7 @@ void PlayerBox::init(std::string name, std::string selectedName)
}
}
-void PlayerBox::draw(gcn::Graphics *graphics)
+void PlayerBox::draw(Graphics *graphics)
{
BLOCK_START("PlayerBox::draw")
if (mBeing)
@@ -115,7 +119,7 @@ void PlayerBox::draw(gcn::Graphics *graphics)
const int bs = mFrameSize;
const int x = mDimension.width / 2 + bs + mOffsetX;
const int y = mDimension.height - bs + mOffsetY;
- mBeing->drawSpriteAt(static_cast<Graphics*>(graphics), x, y);
+ mBeing->drawSpriteAt(graphics, x, y);
}
if (client->getGuiAlpha() != mAlpha)
@@ -130,7 +134,7 @@ void PlayerBox::draw(gcn::Graphics *graphics)
BLOCK_END("PlayerBox::draw")
}
-void PlayerBox::drawFrame(gcn::Graphics *graphics)
+void PlayerBox::drawFrame(Graphics *graphics)
{
BLOCK_START("PlayerBox::drawFrame")
if (mDrawBackground)
@@ -140,23 +144,17 @@ void PlayerBox::drawFrame(gcn::Graphics *graphics)
const int h = mDimension.height + bs;
if (!mSelected)
- {
- static_cast<Graphics*>(graphics)->drawImageRect(
- 0, 0, w, h, mBackground);
- }
+ graphics->drawImageRect(0, 0, w, h, mBackground);
else
- {
- static_cast<Graphics*>(graphics)->drawImageRect(
- 0, 0, w, h, mSelectedBackground);
- }
+ graphics->drawImageRect(0, 0, w, h, mSelectedBackground);
}
BLOCK_END("PlayerBox::drawFrame")
}
-void PlayerBox::mouseReleased(gcn::MouseEvent& event)
+void PlayerBox::mouseReleased(MouseEvent& event)
{
ScrollArea::mouseReleased(event);
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
if (!mActionEventId.empty())
distributeActionEvent();
diff --git a/src/gui/widgets/playerbox.h b/src/gui/widgets/playerbox.h
index 3ebae9be4..7481dc9db 100644
--- a/src/gui/widgets/playerbox.h
+++ b/src/gui/widgets/playerbox.h
@@ -23,9 +23,7 @@
#ifndef GUI_WIDGETS_PLAYERBOX_H
#define GUI_WIDGETS_PLAYERBOX_H
-#include "gui/widgets/widget2.h"
-
-#include <guichan/widgets/scrollarea.hpp>
+#include "gui/base/widgets/scrollarea.hpp"
#include "localconsts.h"
@@ -37,18 +35,20 @@ class Skin;
*
* \ingroup GUI
*/
-class PlayerBox final : public Widget2,
- public gcn::ScrollArea
+class PlayerBox final : public gcn::ScrollArea
{
public:
/**
* Constructor. Takes the initial player character that this box should
* display, which defaults to <code>NULL</code>.
*/
- explicit PlayerBox(Being *const being, const std::string &skin = "",
+ explicit PlayerBox(Widget2 *const widget,
+ Being *const being,
+ const std::string &skin = "",
const std::string &selectedSkin = "");
- explicit PlayerBox(const std::string &skin = "",
+ explicit PlayerBox(Widget2 *const widget,
+ const std::string &skin = "",
const std::string &selectedSkin = "");
A_DELETE_COPY(PlayerBox)
@@ -71,12 +71,12 @@ class PlayerBox final : public Widget2,
/**
* Draws the scroll area.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
/**
* Draws the background and border of the scroll area.
*/
- void drawFrame(gcn::Graphics *graphics) override final;
+ void drawFrame(Graphics *graphics) override final;
Being *getBeing() A_WARN_UNUSED
{ return mBeing; }
@@ -84,7 +84,7 @@ class PlayerBox final : public Widget2,
void setSelected(bool b)
{ mSelected = b; }
- void mouseReleased(gcn::MouseEvent& event) override final;
+ void mouseReleased(MouseEvent& event) override final;
private:
Being *mBeing;
diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp
index 1ba4083cd..1114b4a5e 100644
--- a/src/gui/widgets/popup.cpp
+++ b/src/gui/widgets/popup.cpp
@@ -27,15 +27,13 @@
#include "gui/viewport.h"
-#include <guichan/exception.hpp>
-
#include "debug.h"
Popup::Popup(const std::string &name,
std::string skin) :
Container(nullptr),
- gcn::MouseListener(),
- gcn::WidgetListener(),
+ MouseListener(),
+ WidgetListener(),
mPadding(3),
mSkin(nullptr),
mPopupName(name),
@@ -48,9 +46,6 @@ Popup::Popup(const std::string &name,
{
logger->log("Popup::Popup(\"%s\")", name.c_str());
- if (!windowContainer)
- throw GCN_EXCEPTION("Popup::Popup(): no windowContainer set");
-
addWidgetListener(this);
if (skin == "")
@@ -67,7 +62,8 @@ Popup::Popup(const std::string &name,
}
}
- windowContainer->add(this);
+ if (windowContainer)
+ windowContainer->add(this);
// Popups are invisible by default
setVisible(false);
@@ -94,10 +90,9 @@ void Popup::setWindowContainer(WindowContainer *const wc)
windowContainer = wc;
}
-void Popup::draw(gcn::Graphics *graphics)
+void Popup::draw(Graphics *graphics)
{
BLOCK_START("Popup::draw")
- Graphics *const g = static_cast<Graphics*>(graphics);
if (mSkin)
{
@@ -107,16 +102,18 @@ void Popup::draw(gcn::Graphics *graphics)
{
mRedraw = false;
mVertexes->clear();
- g->calcWindow(mVertexes, 0, 0,
+ graphics->calcWindow(mVertexes,
+ 0, 0,
mDimension.width, mDimension.height,
mSkin->getBorder());
}
- g->drawTileCollection(mVertexes);
+ graphics->drawTileCollection(mVertexes);
}
else
{
- g->drawImageRect(0, 0, mDimension.width, mDimension.height,
+ graphics->drawImageRect(0, 0,
+ mDimension.width, mDimension.height,
mSkin->getBorder());
}
}
@@ -125,10 +122,10 @@ void Popup::draw(gcn::Graphics *graphics)
BLOCK_END("Popup::draw")
}
-gcn::Rectangle Popup::getChildrenArea()
+Rect Popup::getChildrenArea()
{
const int pad2 = mPadding * 2;
- return gcn::Rectangle(mPadding, mPadding,
+ return Rect(mPadding, mPadding,
mDimension.width - pad2, mDimension.height - pad2);
}
@@ -151,7 +148,7 @@ void Popup::setContentSize(int width, int height)
mRedraw = true;
}
-void Popup::setLocationRelativeTo(const gcn::Widget *const widget)
+void Popup::setLocationRelativeTo(const Widget *const widget)
{
if (!widget)
return;
@@ -230,7 +227,7 @@ void Popup::position(const int x, const int y)
mRedraw = true;
}
-void Popup::mouseMoved(gcn::MouseEvent &event A_UNUSED)
+void Popup::mouseMoved(MouseEvent &event A_UNUSED)
{
if (viewport)
viewport->hideBeingPopup();
@@ -243,12 +240,12 @@ void Popup::hide()
mRedraw = true;
}
-void Popup::widgetResized(const gcn::Event &event A_UNUSED)
+void Popup::widgetResized(const Event &event A_UNUSED)
{
mRedraw = true;
}
-void Popup::widgetMoved(const gcn::Event &event A_UNUSED)
+void Popup::widgetMoved(const Event &event A_UNUSED)
{
mRedraw = true;
}
diff --git a/src/gui/widgets/popup.h b/src/gui/widgets/popup.h
index 711ac97b7..01247cf61 100644
--- a/src/gui/widgets/popup.h
+++ b/src/gui/widgets/popup.h
@@ -26,8 +26,8 @@
#include "gui/widgets/container.h"
-#include <guichan/mouselistener.hpp>
-#include <guichan/widgetlistener.hpp>
+#include "listeners/mouselistener.h"
+#include "listeners/widgetlistener.h"
class ImageCollection;
class Skin;
@@ -45,8 +45,9 @@ class WindowContainer;
*
* \ingroup GUI
*/
-class Popup : public Container, public gcn::MouseListener,
- public gcn::WidgetListener
+class Popup : public Container,
+ public MouseListener,
+ public WidgetListener
{
public:
/**
@@ -75,7 +76,7 @@ class Popup : public Container, public gcn::MouseListener,
/**
* Draws the popup.
*/
- void draw(gcn::Graphics *graphics) override;
+ void draw(Graphics *graphics) override;
/**
* Sets the size of this popup.
@@ -85,9 +86,9 @@ class Popup : public Container, public gcn::MouseListener,
/**
* Sets the location relative to the given widget.
*/
- void setLocationRelativeTo(const gcn::Widget *const widget);
+ void setLocationRelativeTo(const Widget *const widget);
- void mouseMoved(gcn::MouseEvent &event) override;
+ void mouseMoved(MouseEvent &event) override;
/**
* Sets the minimum width of the popup.
@@ -151,7 +152,7 @@ class Popup : public Container, public gcn::MouseListener,
// Inherited from BasicContainer
- virtual gcn::Rectangle getChildrenArea() override;
+ virtual Rect getChildrenArea() override;
/**
* Sets the location to display the popup. Tries to horizontally center
@@ -163,9 +164,9 @@ class Popup : public Container, public gcn::MouseListener,
void hide();
- void widgetResized(const gcn::Event &event) override;
+ void widgetResized(const Event &event) override;
- void widgetMoved(const gcn::Event &event) override final;
+ void widgetMoved(const Event &event) override final;
bool isPopupVisible() const
{ return mVisible; }
diff --git a/src/gui/widgets/popuplist.cpp b/src/gui/widgets/popuplist.cpp
index f7f8afc66..cfb973384 100644
--- a/src/gui/widgets/popuplist.cpp
+++ b/src/gui/widgets/popuplist.cpp
@@ -29,15 +29,15 @@
#include "debug.h"
PopupList::PopupList(DropDown *const widget,
- gcn::ListModel *const listModel,
+ ListModel *const listModel,
bool extended, bool modal):
Popup("PopupList", "popuplist.xml"),
- gcn::FocusListener(),
+ FocusListener(),
mListModel(listModel),
mListBox(extended ? new ExtendedListBox(
widget, listModel, "extendedlistbox.xml", 0) :
new ListBox(widget, listModel, "popuplistbox.xml")),
- mScrollArea(new ScrollArea(mListBox, false)),
+ mScrollArea(new ScrollArea(this, mListBox, false)),
mDropDown(widget),
mPressedIndex(-2),
mModal(modal)
@@ -90,7 +90,7 @@ void PopupList::show(int x, int y)
requestModalFocus();
}
-void PopupList::widgetResized(const gcn::Event &event)
+void PopupList::widgetResized(const Event &event)
{
Popup::widgetResized(event);
adjustSize();
@@ -112,7 +112,7 @@ int PopupList::getSelected() const
return mListBox->getSelected();
}
-void PopupList::setListModel(gcn::ListModel *const model)
+void PopupList::setListModel(ListModel *const model)
{
if (mListBox)
mListBox->setListModel(model);
@@ -129,13 +129,13 @@ void PopupList::adjustSize()
mListBox->setWidth(width);
}
-void PopupList::mousePressed(gcn::MouseEvent& mouseEvent)
+void PopupList::mousePressed(MouseEvent& mouseEvent)
{
mPressedIndex = mListBox->getSelectionByMouse(
mouseEvent.getY() + mPadding);
}
-void PopupList::mouseReleased(gcn::MouseEvent& mouseEvent)
+void PopupList::mouseReleased(MouseEvent& mouseEvent)
{
if (mPressedIndex != mListBox->getSelectionByMouse(
mouseEvent.getY() + mPadding))
@@ -154,9 +154,9 @@ void PopupList::mouseReleased(gcn::MouseEvent& mouseEvent)
releaseModalFocus();
}
-void PopupList::focusGained(const gcn::Event& event)
+void PopupList::focusGained(const Event& event)
{
- const gcn::Widget *const source = event.getSource();
+ const Widget *const source = event.getSource();
if (!mVisible || source == this || source == mListBox
|| source == mScrollArea || source == mDropDown)
{
@@ -170,7 +170,7 @@ void PopupList::focusGained(const gcn::Event& event)
releaseModalFocus();
}
-void PopupList::focusLost(const gcn::Event& event A_UNUSED)
+void PopupList::focusLost(const Event& event A_UNUSED)
{
if (mDropDown)
mDropDown->updateSelection();
diff --git a/src/gui/widgets/popuplist.h b/src/gui/widgets/popuplist.h
index f41b9f631..32a9dfc47 100644
--- a/src/gui/widgets/popuplist.h
+++ b/src/gui/widgets/popuplist.h
@@ -23,21 +23,21 @@
#include "gui/widgets/popup.h"
-#include <guichan/focuslistener.hpp>
-#include <guichan/listmodel.hpp>
+#include "listeners/focuslistener.h"
#include "localconsts.h"
class DropDown;
class ListBox;
+class ListModel;
class ScrollArea;
class PopupList final : public Popup,
- public gcn::FocusListener
+ public FocusListener
{
public:
PopupList(DropDown *const widget,
- gcn::ListModel *const listModel, bool extended,
+ ListModel *const listModel, bool extended,
bool modal = false);
~PopupList();
@@ -48,29 +48,29 @@ class PopupList final : public Popup,
void show(int x, int y);
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
void setSelected(int selected);
int getSelected() const;
- void setListModel(gcn::ListModel *const model);
+ void setListModel(ListModel *const model);
- gcn::ListModel *getListModel() const
+ ListModel *getListModel() const
{ return mListModel; }
void adjustSize();
- void focusGained(const gcn::Event& event A_UNUSED) override final;
+ void focusGained(const Event& event A_UNUSED) override final;
- void focusLost(const gcn::Event& event A_UNUSED) override final;
+ void focusLost(const Event& event A_UNUSED) override final;
- void mousePressed(gcn::MouseEvent& mouseEvent) override final;
+ void mousePressed(MouseEvent& mouseEvent) override final;
- void mouseReleased(gcn::MouseEvent& mouseEvent) override final;
+ void mouseReleased(MouseEvent& mouseEvent) override final;
private:
- gcn::ListModel *mListModel;
+ ListModel *mListModel;
ListBox *mListBox;
ScrollArea *mScrollArea;
DropDown *mDropDown;
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp
index 38257e0a8..5bccd61ca 100644
--- a/src/gui/widgets/progressbar.cpp
+++ b/src/gui/widgets/progressbar.cpp
@@ -25,23 +25,23 @@
#include "client.h"
#include "graphicsvertexes.h"
+#include "gui/font.h"
#include "gui/gui.h"
-#include "gui/sdlfont.h"
-
-#include <guichan/font.hpp>
#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,
+ProgressBar::ProgressBar(const Widget2 *const widget,
+ float progress,
+ const int width,
+ const int height,
const int backColor,
- const std::string &skin, const std::string &skinFill):
- gcn::Widget(),
- Widget2(widget),
- gcn::WidgetListener(),
+ const std::string &skin,
+ const std::string &skinFill):
+ Widget(widget),
+ WidgetListener(),
mFillRect(),
mSkin(nullptr),
mProgress(progress),
@@ -146,12 +146,12 @@ void ProgressBar::updateAlpha()
mAlpha = alpha;
}
-void ProgressBar::draw(gcn::Graphics *graphics)
+void ProgressBar::draw(Graphics *graphics)
{
BLOCK_START("ProgressBar::draw")
updateAlpha();
mBackgroundColor.a = static_cast<int>(mAlpha * 255);
- render(static_cast<Graphics*>(graphics));
+ render(graphics);
BLOCK_END("ProgressBar::draw")
}
@@ -184,7 +184,7 @@ void ProgressBar::setProgressPalette(const int progressPalette)
}
}
-void ProgressBar::setBackgroundColor(const gcn::Color &color)
+void ProgressBar::setBackgroundColor(const Color &color)
{
mRedraw = true;
mBackgroundColorToGo = color;
@@ -193,7 +193,7 @@ void ProgressBar::setBackgroundColor(const gcn::Color &color)
mBackgroundColor = color;
}
-void ProgressBar::setColor(const gcn::Color &color1, const gcn::Color &color2)
+void ProgressBar::setColor(const Color &color1, const Color &color2)
{
mForegroundColor = color1;
mForegroundColor2 = color2;
@@ -261,7 +261,7 @@ void ProgressBar::render(Graphics *graphics)
{
if (width > maxWidth)
width = maxWidth;
- graphics->fillRectangle(gcn::Rectangle(mFillPadding, mFillPadding,
+ graphics->fillRectangle(Rect(mFillPadding, mFillPadding,
width, mDimension.height - pad));
}
}
@@ -269,9 +269,9 @@ void ProgressBar::render(Graphics *graphics)
// The label
if (!mText.empty())
{
- const gcn::Color oldColor = graphics->getColor();
+ const Color oldColor = graphics->getColor();
- gcn::Font *const font = gui->getFont();
+ Font *const font = gui->getFont();
const int textX = mDimension.width / 2;
const int textY = (mDimension.height - font->getHeight()) / 2;
@@ -283,12 +283,12 @@ void ProgressBar::render(Graphics *graphics)
}
}
-void ProgressBar::widgetResized(const gcn::Event &event A_UNUSED)
+void ProgressBar::widgetResized(const Event &event A_UNUSED)
{
mRedraw = true;
}
-void ProgressBar::widgetMoved(const gcn::Event &event A_UNUSED)
+void ProgressBar::widgetMoved(const Event &event A_UNUSED)
{
mRedraw = true;
}
diff --git a/src/gui/widgets/progressbar.h b/src/gui/widgets/progressbar.h
index eefabe83a..fef9bf11d 100644
--- a/src/gui/widgets/progressbar.h
+++ b/src/gui/widgets/progressbar.h
@@ -23,10 +23,9 @@
#ifndef GUI_WIDGETS_PROGRESSBAR_H
#define GUI_WIDGETS_PROGRESSBAR_H
-#include "gui/widgets/widget2.h"
+#include "gui/widgets/widget.h"
-#include <guichan/widget.hpp>
-#include <guichan/widgetlistener.hpp>
+#include "listeners/widgetlistener.h"
#include <string>
@@ -40,18 +39,20 @@ class Skin;
*
* \ingroup GUI
*/
-class ProgressBar final : public gcn::Widget,
- public Widget2,
- public gcn::WidgetListener
+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,
+ ProgressBar(const Widget2 *const widget,
+ float progress,
+ const int width,
+ const int height,
const int backColor,
- const std::string &skin, const std::string &skinFill);
+ const std::string &skin,
+ const std::string &skinFill);
A_DELETE_COPY(ProgressBar)
@@ -70,7 +71,7 @@ class ProgressBar final : public gcn::Widget,
/**
* Draws the progress bar.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
/**
* Sets the current progress.
@@ -92,14 +93,14 @@ class ProgressBar final : public gcn::Widget,
/**
* Change the color of the progress bar.
*/
- void setBackgroundColor(const gcn::Color &color);
+ void setBackgroundColor(const Color &color);
- void setColor(const gcn::Color &color1, const gcn::Color &color2);
+ void setColor(const Color &color1, const Color &color2);
/**
* Returns the color of the progress bar.
*/
- const gcn::Color &getBackgroundColor() const A_WARN_UNUSED
+ const Color &getBackgroundColor() const A_WARN_UNUSED
{ return mBackgroundColor; }
/**
@@ -131,9 +132,9 @@ class ProgressBar final : public gcn::Widget,
*/
void render(Graphics *graphics);
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
- void widgetMoved(const gcn::Event &event) override final;
+ void widgetMoved(const Event &event) override final;
void setPadding(unsigned int padding)
{ mPadding = padding; }
@@ -144,7 +145,7 @@ class ProgressBar final : public gcn::Widget,
float mProgress;
float mProgressToGo;
- gcn::Color mBackgroundColorToGo;
+ Color mBackgroundColorToGo;
std::string mText;
ImageCollection *mVertexes;
diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp
index d89ff7f2a..8e86417bd 100644
--- a/src/gui/widgets/progressindicator.cpp
+++ b/src/gui/widgets/progressindicator.cpp
@@ -23,14 +23,15 @@
#include "simpleanimation.h"
+#include "gui/gui.h"
+
#include "resources/animation.h"
#include "resources/imageset.h"
#include "debug.h"
-ProgressIndicator::ProgressIndicator() :
- gcn::Widget(),
- Widget2(),
+ProgressIndicator::ProgressIndicator(Widget2 *const widget) :
+ Widget(widget),
mIndicator(nullptr)
{
ImageSet *const images = Theme::getImageSetFromTheme(
@@ -65,7 +66,7 @@ void ProgressIndicator::logic()
BLOCK_END("ProgressIndicator::logic")
}
-void ProgressIndicator::draw(gcn::Graphics *graphics)
+void ProgressIndicator::draw(Graphics *graphics)
{
BLOCK_START("ProgressIndicator::draw")
if (mIndicator)
@@ -73,7 +74,7 @@ void ProgressIndicator::draw(gcn::Graphics *graphics)
// Draw the indicator centered on the widget
const int x = (mDimension.width - 32) / 2;
const int y = (mDimension.height - 32) / 2;
- mIndicator->draw(static_cast<Graphics*>(graphics), x, y);
+ mIndicator->draw(graphics, x, y);
}
BLOCK_END("ProgressIndicator::draw")
}
diff --git a/src/gui/widgets/progressindicator.h b/src/gui/widgets/progressindicator.h
index 61a72dd67..447c3d4e4 100644
--- a/src/gui/widgets/progressindicator.h
+++ b/src/gui/widgets/progressindicator.h
@@ -22,9 +22,7 @@
#ifndef GUI_WIDGETS_PROGRESSINDICATOR_H
#define GUI_WIDGETS_PROGRESSINDICATOR_H
-#include "gui/widgets/widget2.h"
-
-#include <guichan/widget.hpp>
+#include "gui/widgets/widget.h"
#include "localconsts.h"
@@ -34,11 +32,10 @@ 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 gcn::Widget,
- public Widget2
+class ProgressIndicator final : public Widget
{
public:
- ProgressIndicator();
+ explicit ProgressIndicator(Widget2 *const widget);
A_DELETE_COPY(ProgressIndicator)
@@ -46,7 +43,7 @@ class ProgressIndicator final : public gcn::Widget,
void logic() override final;
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
private:
SimpleAnimation *mIndicator;
diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp
index e0643a8ac..bb9ae46f9 100644
--- a/src/gui/widgets/radiobutton.cpp
+++ b/src/gui/widgets/radiobutton.cpp
@@ -24,12 +24,14 @@
#include "client.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
#include "resources/image.h"
-#include <guichan/font.hpp>
+#include "gui/font.h"
+#include "gui/gui.h"
#include "debug.h"
@@ -41,8 +43,7 @@ RadioButton::RadioButton(const Widget2 *const widget,
const std::string &restrict caption,
const std::string &restrict group,
const bool marked):
- gcn::RadioButton(caption, group, marked),
- Widget2(widget),
+ gcn::RadioButton(widget, caption, group, marked),
mPadding(0),
mImagePadding(0),
mImageSize(9),
@@ -110,7 +111,7 @@ void RadioButton::updateAlpha()
}
}
-void RadioButton::drawBox(gcn::Graphics* graphics)
+void RadioButton::drawBox(Graphics* graphics)
{
if (!mSkin)
return;
@@ -149,38 +150,37 @@ void RadioButton::drawBox(gcn::Graphics* graphics)
if (box)
{
- static_cast<Graphics*>(graphics)->drawImage2(
- box, mImagePadding, (getHeight() - mImageSize) / 2);
+ graphics->drawImage(box,
+ mImagePadding,
+ (getHeight() - mImageSize) / 2);
}
}
-void RadioButton::draw(gcn::Graphics* graphics)
+void RadioButton::draw(Graphics* graphics)
{
BLOCK_START("RadioButton::draw")
drawBox(graphics);
- gcn::Font *const font = getFont();
- static_cast<Graphics *const>(graphics)->setColorAll(
- mForegroundColor, mForegroundColor2);
-
+ Font *const font = getFont();
+ graphics->setColorAll(mForegroundColor, mForegroundColor2);
font->drawString(graphics, mCaption, mPadding + mImageSize + mSpacing,
mPadding);
BLOCK_END("RadioButton::draw")
}
-void RadioButton::mouseEntered(gcn::MouseEvent& event A_UNUSED)
+void RadioButton::mouseEntered(MouseEvent& event A_UNUSED)
{
mHasMouse = true;
}
-void RadioButton::mouseExited(gcn::MouseEvent& event A_UNUSED)
+void RadioButton::mouseExited(MouseEvent& event A_UNUSED)
{
mHasMouse = false;
}
-void RadioButton::keyPressed(gcn::KeyEvent& keyEvent)
+void RadioButton::keyPressed(KeyEvent& keyEvent)
{
- const int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int action = keyEvent.getActionId();
if (action == Input::KEY_GUI_SELECT)
{
setSelected(true);
@@ -191,7 +191,7 @@ void RadioButton::keyPressed(gcn::KeyEvent& keyEvent)
void RadioButton::adjustSize()
{
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
setHeight(font->getHeight() + 2 * mPadding);
setWidth(mImagePadding + mImageSize + mSpacing
+ font->getWidth(mCaption) + mPadding);
diff --git a/src/gui/widgets/radiobutton.h b/src/gui/widgets/radiobutton.h
index f5ff43f4c..2deb9a772 100644
--- a/src/gui/widgets/radiobutton.h
+++ b/src/gui/widgets/radiobutton.h
@@ -23,9 +23,7 @@
#ifndef GUI_WIDGETS_RADIOBUTTON_H
#define GUI_WIDGETS_RADIOBUTTON_H
-#include "gui/widgets/widget2.h"
-
-#include <guichan/widgets/radiobutton.hpp>
+#include "gui/base/widgets/radiobutton.hpp"
#include "localconsts.h"
@@ -34,8 +32,7 @@ class Skin;
/**
* Guichan based RadioButton with custom look
*/
-class RadioButton final : public gcn::RadioButton,
- public Widget2
+class RadioButton final : public gcn::RadioButton
{
public:
/**
@@ -56,25 +53,25 @@ class RadioButton final : public gcn::RadioButton,
/**
* Draws the radiobutton, not the caption.
*/
- void drawBox(gcn::Graphics* graphics) override final;
+ void drawBox(Graphics* graphics) override final;
/**
* Implementation of the draw methods.
* Thus, avoiding the rhomb around the radio button.
*/
- void draw(gcn::Graphics* graphics) override final;
+ void draw(Graphics* graphics) override final;
/**
* Called when the mouse enteres the widget area.
*/
- void mouseEntered(gcn::MouseEvent& event) override final;
+ void mouseEntered(MouseEvent& event) override final;
/**
* Called when the mouse leaves the widget area.
*/
- void mouseExited(gcn::MouseEvent& event) override final;
+ void mouseExited(MouseEvent& event) override final;
- void keyPressed(gcn::KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& keyEvent) override final;
void updateAlpha();
diff --git a/src/gui/widgets/radiogroup.cpp b/src/gui/widgets/radiogroup.cpp
index d2f130c1b..9bb4f40c5 100644
--- a/src/gui/widgets/radiogroup.cpp
+++ b/src/gui/widgets/radiogroup.cpp
@@ -31,7 +31,7 @@ RadioGroup::RadioGroup(const Widget2 *const widget,
{
}
-gcn::Widget *RadioGroup::createWidget(const std::string &text) const
+Widget *RadioGroup::createWidget(const std::string &text) const
{
RadioButton *const widget = new RadioButton(
this, text, mGroup, mCount == 0);
diff --git a/src/gui/widgets/radiogroup.h b/src/gui/widgets/radiogroup.h
index 1863a348c..41193b3d6 100644
--- a/src/gui/widgets/radiogroup.h
+++ b/src/gui/widgets/radiogroup.h
@@ -23,19 +23,18 @@
#include "gui/widgets/widgetgroup.h"
-#include <guichan/widget.hpp>
-
class RadioGroup final : public WidgetGroup
{
public:
RadioGroup(const Widget2 *const widget,
- const std::string &group, const int height,
+ const std::string &group,
+ const int height,
const int spacing);
A_DELETE_COPY(RadioGroup)
- gcn::Widget *createWidget(const std::string &name)
- const override final A_WARN_UNUSED;
+ Widget *createWidget(const std::string &name)
+ 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
index a260142a1..dcc3a871b 100644
--- a/src/gui/widgets/scrollarea.cpp
+++ b/src/gui/widgets/scrollarea.cpp
@@ -25,6 +25,10 @@
#include "client.h"
#include "graphicsvertexes.h"
+#include "gui/gui.h"
+
+#include "resources/image.h"
+
#include "debug.h"
int ScrollArea::instances = 0;
@@ -45,31 +49,12 @@ static std::string const buttonFiles[2] =
"scrollbuttons_pressed.xml"
};
-ScrollArea::ScrollArea(const bool opaque, const std::string &skin) :
- gcn::ScrollArea(),
- gcn::WidgetListener(),
- mX(0),
- mY(0),
- mClickX(0),
- mClickY(0),
- mVertexes(new ImageCollection),
- mVertexes2(new ImageCollection),
- mXOffset(0),
- mYOffset(0),
- mDrawWidth(0),
- mDrawHeight(0),
- mHasMouse(false),
- mRedraw(true)
-{
- mOpaque = opaque;
- addWidgetListener(this);
- init(skin);
-}
-
-ScrollArea::ScrollArea(gcn::Widget *const widget, const bool opaque,
+ScrollArea::ScrollArea(Widget2 *const widget2,
+ Widget *const widget,
+ const bool opaque,
const std::string &skin) :
- gcn::ScrollArea(widget),
- gcn::WidgetListener(),
+ gcn::ScrollArea(widget2, widget),
+ WidgetListener(),
mX(0),
mY(0),
mClickX(0),
@@ -194,7 +179,7 @@ void ScrollArea::logic()
}
gcn::ScrollArea::logic();
- gcn::Widget *const content = getContent();
+ Widget *const content = getContent();
// When no scrollbar in a certain direction, adapt content size to match
// the content dimension exactly.
@@ -248,7 +233,7 @@ void ScrollArea::updateAlpha()
}
}
-void ScrollArea::draw(gcn::Graphics *graphics)
+void ScrollArea::draw(Graphics *graphics)
{
BLOCK_START("ScrollArea::draw")
if (mVBarVisible || mHBarVisible)
@@ -282,8 +267,7 @@ void ScrollArea::draw(gcn::Graphics *graphics)
calcHMarker(graphics);
}
}
- static_cast<Graphics *const>(graphics)->drawTileCollection(
- mVertexes);
+ graphics->drawTileCollection(mVertexes);
}
else
{
@@ -315,11 +299,10 @@ void ScrollArea::draw(gcn::Graphics *graphics)
if (mRedraw)
{
- Graphics *g = static_cast<Graphics *const>(graphics);
- const bool redraw = g->getRedraw();
- g->setRedraw(true);
+ const bool redraw = graphics->getRedraw();
+ graphics->setRedraw(true);
drawChildren(graphics);
- g->setRedraw(redraw);
+ graphics->setRedraw(redraw);
}
else
{
@@ -329,14 +312,13 @@ void ScrollArea::draw(gcn::Graphics *graphics)
BLOCK_END("ScrollArea::draw")
}
-void ScrollArea::updateCalcFlag(gcn::Graphics *const graphics)
+void ScrollArea::updateCalcFlag(Graphics *const graphics)
{
if (!mRedraw)
{
// because we don't know where parent windows was moved,
// need recalc vertexes
- const gcn::ClipRectangle &rect = static_cast<Graphics*>(
- graphics)->getTopClip();
+ const ClipRect &rect = graphics->getTopClip();
if (rect.xOffset != mXOffset || rect.yOffset != mYOffset)
{
mRedraw = true;
@@ -349,14 +331,14 @@ void ScrollArea::updateCalcFlag(gcn::Graphics *const graphics)
mDrawWidth = rect.width;
mDrawHeight = rect.height;
}
- else if (static_cast<Graphics*>(graphics)->getRedraw())
+ else if (graphics->getRedraw())
{
mRedraw = true;
}
}
}
-void ScrollArea::drawFrame(gcn::Graphics *graphics)
+void ScrollArea::drawFrame(Graphics *graphics)
{
BLOCK_START("ScrollArea::drawFrame")
if (mOpaque)
@@ -372,15 +354,18 @@ void ScrollArea::drawFrame(gcn::Graphics *graphics)
if (mRedraw)
{
mVertexes2->clear();
- static_cast<Graphics*>(graphics)->calcWindow(
- mVertexes2, 0, 0, w, h, background);
+ graphics->calcWindow(mVertexes2,
+ 0, 0,
+ w, h,
+ background);
}
- static_cast<Graphics*>(graphics)->drawTileCollection(mVertexes2);
+ graphics->drawTileCollection(mVertexes2);
}
else
{
- static_cast<Graphics*>(graphics)->drawImageRect(
- 0, 0, w, h, background);
+ graphics->drawImageRect(0, 0,
+ w, h,
+ background);
}
}
BLOCK_END("ScrollArea::drawFrame")
@@ -392,11 +377,11 @@ void ScrollArea::setOpaque(bool opaque)
setFrameSize(mOpaque ? 2 : 0);
}
-void ScrollArea::drawButton(gcn::Graphics *const graphics,
+void ScrollArea::drawButton(Graphics *const graphics,
const BUTTON_DIR dir)
{
int state = 0;
- gcn::Rectangle dim;
+ Rect dim;
switch (dir)
{
@@ -424,17 +409,14 @@ void ScrollArea::drawButton(gcn::Graphics *const graphics,
}
if (buttons[dir][state])
- {
- static_cast<Graphics*>(graphics)->drawImage2(
- buttons[dir][state], dim.x, dim.y);
- }
+ graphics->drawImage(buttons[dir][state], dim.x, dim.y);
}
-void ScrollArea::calcButton(gcn::Graphics *const graphics,
+void ScrollArea::calcButton(Graphics *const graphics,
const BUTTON_DIR dir)
{
int state = 0;
- gcn::Rectangle dim;
+ Rect dim;
switch (dir)
{
@@ -468,187 +450,213 @@ void ScrollArea::calcButton(gcn::Graphics *const graphics,
}
}
-void ScrollArea::drawVBar(gcn::Graphics *const graphics)
+void ScrollArea::drawVBar(Graphics *const graphics)
{
- const gcn::Rectangle &dim = getVerticalBarDimension();
- Graphics *const g = static_cast<Graphics*>(graphics);
+ const Rect &dim = getVerticalBarDimension();
if (vBackground.grid[4])
{
- g->drawPattern(vBackground.grid[4],
+ graphics->drawPattern(vBackground.grid[4],
dim.x, dim.y, dim.width, dim.height);
}
if (vBackground.grid[1])
{
- g->drawPattern(vBackground.grid[1],
- dim.x, dim.y, dim.width, vBackground.grid[1]->getHeight());
+ graphics->drawPattern(vBackground.grid[1],
+ dim.x, dim.y,
+ dim.width, vBackground.grid[1]->getHeight());
}
if (vBackground.grid[7])
{
- g->drawPattern(vBackground.grid[7],
+ graphics->drawPattern(vBackground.grid[7],
dim.x, dim.height - vBackground.grid[7]->getHeight() + dim.y,
dim.width, vBackground.grid[7]->getHeight());
}
}
-void ScrollArea::calcVBar(gcn::Graphics *const graphics)
+void ScrollArea::calcVBar(Graphics *const graphics)
{
- const gcn::Rectangle &dim = getVerticalBarDimension();
- Graphics *const g = static_cast<Graphics *const>(graphics);
+ const Rect &dim = getVerticalBarDimension();
if (vBackground.grid[4])
{
- g->calcPattern(mVertexes, vBackground.grid[4],
- dim.x, dim.y, dim.width, dim.height);
+ graphics->calcPattern(mVertexes,
+ vBackground.grid[4],
+ dim.x, dim.y,
+ dim.width, dim.height);
}
if (vBackground.grid[1])
{
- g->calcPattern(mVertexes, vBackground.grid[1],
- dim.x, dim.y, dim.width, vBackground.grid[1]->getHeight());
+ graphics->calcPattern(mVertexes,
+ vBackground.grid[1],
+ dim.x, dim.y,
+ dim.width, vBackground.grid[1]->getHeight());
}
if (vBackground.grid[7])
{
- g->calcPattern(mVertexes, vBackground.grid[7],
+ 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(gcn::Graphics *const graphics)
+void ScrollArea::drawHBar(Graphics *const graphics)
{
- const gcn::Rectangle &dim = getHorizontalBarDimension();
- Graphics *const g = static_cast<Graphics*>(graphics);
+ const Rect &dim = getHorizontalBarDimension();
if (hBackground.grid[4])
{
- g->drawPattern(hBackground.grid[4],
- dim.x, dim.y, dim.width, dim.height);
+ graphics->drawPattern(hBackground.grid[4],
+ dim.x, dim.y,
+ dim.width, dim.height);
}
if (hBackground.grid[3])
{
- g->drawPattern(hBackground.grid[3],
- dim.x, dim.y, hBackground.grid[3]->getWidth(), dim.height);
+ graphics->drawPattern(hBackground.grid[3],
+ dim.x, dim.y,
+ hBackground.grid[3]->getWidth(), dim.height);
}
if (hBackground.grid[5])
{
- g->drawPattern(hBackground.grid[5],
- dim.x + dim.width - hBackground.grid[5]->getWidth(), dim.y,
- hBackground.grid[5]->getWidth(), dim.height);
+ graphics->drawPattern(hBackground.grid[5],
+ dim.x + dim.width - hBackground.grid[5]->getWidth(),
+ dim.y,
+ hBackground.grid[5]->getWidth(),
+ dim.height);
}
}
-void ScrollArea::calcHBar(gcn::Graphics *const graphics)
+void ScrollArea::calcHBar(Graphics *const graphics)
{
- const gcn::Rectangle &dim = getHorizontalBarDimension();
- Graphics *const g = static_cast<Graphics*>(graphics);
+ const Rect &dim = getHorizontalBarDimension();
if (hBackground.grid[4])
{
- g->calcPattern(mVertexes, hBackground.grid[4],
- dim.x, dim.y, dim.width, dim.height);
+ graphics->calcPattern(mVertexes,
+ hBackground.grid[4],
+ dim.x, dim.y,
+ dim.width, dim.height);
}
if (hBackground.grid[3])
{
- g->calcPattern(mVertexes, hBackground.grid[3],
- dim.x, dim.y, hBackground.grid[3]->getWidth(), dim.height);
+ graphics->calcPattern(mVertexes,
+ hBackground.grid[3],
+ dim.x, dim.y,
+ hBackground.grid[3]->getWidth(), dim.height);
}
if (hBackground.grid[5])
{
- g->calcPattern(mVertexes, hBackground.grid[5],
- dim.x + dim.width - hBackground.grid[5]->getWidth(), dim.y,
- hBackground.grid[5]->getWidth(), dim.height);
+ 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(gcn::Graphics *const graphics)
+void ScrollArea::drawVMarker(Graphics *const graphics)
{
- const gcn::Rectangle &dim = getVerticalMarkerDimension();
+ const Rect &dim = getVerticalMarkerDimension();
if ((mHasMouse) && (mX > (mDimension.width - mScrollbarWidth)))
{
- static_cast<Graphics*>(graphics)->
- drawImageRect(dim.x, dim.y, dim.width, dim.height, vMarkerHi);
+ graphics->drawImageRect(dim.x, dim.y,
+ dim.width, dim.height,
+ vMarkerHi);
}
else
{
- static_cast<Graphics*>(graphics)->
- drawImageRect(dim.x, dim.y, dim.width, dim.height, vMarker);
+ graphics->drawImageRect(dim.x, dim.y,
+ dim.width, dim.height,
+ vMarker);
}
}
-void ScrollArea::calcVMarker(gcn::Graphics *const graphics)
+void ScrollArea::calcVMarker(Graphics *const graphics)
{
- const gcn::Rectangle &dim = getVerticalMarkerDimension();
+ const Rect &dim = getVerticalMarkerDimension();
if ((mHasMouse) && (mX > (mDimension.width - mScrollbarWidth)))
{
- static_cast<Graphics*>(graphics)->calcWindow(
- mVertexes, dim.x, dim.y, dim.width, dim.height, vMarkerHi);
+ graphics->calcWindow(mVertexes,
+ dim.x, dim.y,
+ dim.width, dim.height,
+ vMarkerHi);
}
else
{
- static_cast<Graphics*>(graphics)->calcWindow(
- mVertexes, dim.x, dim.y, dim.width, dim.height, vMarker);
+ graphics->calcWindow(mVertexes,
+ dim.x, dim.y,
+ dim.width, dim.height,
+ vMarker);
}
}
-void ScrollArea::drawHMarker(gcn::Graphics *const graphics)
+void ScrollArea::drawHMarker(Graphics *const graphics)
{
- const gcn::Rectangle dim = getHorizontalMarkerDimension();
+ const Rect dim = getHorizontalMarkerDimension();
if ((mHasMouse) && (mY > (mDimension.height - mScrollbarWidth)))
{
- static_cast<Graphics*>(graphics)->
- drawImageRect(dim.x, dim.y, dim.width, dim.height, vMarkerHi);
+ graphics->drawImageRect(dim.x, dim.y,
+ dim.width, dim.height,
+ vMarkerHi);
}
else
{
- static_cast<Graphics*>(graphics)->
- drawImageRect(dim.x, dim.y, dim.width, dim.height, vMarker);
+ graphics->drawImageRect(
+ dim.x, dim.y,
+ dim.width, dim.height,
+ vMarker);
}
}
-void ScrollArea::calcHMarker(gcn::Graphics *const graphics)
+void ScrollArea::calcHMarker(Graphics *const graphics)
{
- const gcn::Rectangle dim = getHorizontalMarkerDimension();
+ const Rect dim = getHorizontalMarkerDimension();
if ((mHasMouse) && (mY > (mDimension.height - mScrollbarWidth)))
{
- static_cast<Graphics*>(graphics)->calcWindow(
- mVertexes, dim.x, dim.y, dim.width, dim.height, vMarkerHi);
+ graphics->calcWindow(mVertexes,
+ dim.x, dim.y,
+ dim.width, dim.height,
+ vMarkerHi);
}
else
{
- static_cast<Graphics*>(graphics)->calcWindow(
- mVertexes, dim.x, dim.y, dim.width, dim.height, vMarker);
+ graphics->calcWindow(mVertexes,
+ dim.x, dim.y,
+ dim.width, dim.height,
+ vMarker);
}
}
-void ScrollArea::mouseMoved(gcn::MouseEvent& event)
+void ScrollArea::mouseMoved(MouseEvent& event)
{
mX = event.getX();
mY = event.getY();
}
-void ScrollArea::mouseEntered(gcn::MouseEvent& event A_UNUSED)
+void ScrollArea::mouseEntered(MouseEvent& event A_UNUSED)
{
mHasMouse = true;
}
-void ScrollArea::mouseExited(gcn::MouseEvent& event A_UNUSED)
+void ScrollArea::mouseExited(MouseEvent& event A_UNUSED)
{
mHasMouse = false;
}
-void ScrollArea::widgetResized(const gcn::Event &event A_UNUSED)
+void ScrollArea::widgetResized(const Event &event A_UNUSED)
{
mRedraw = true;
const unsigned int frameSize = 2 * mFrameSize;
- gcn::Widget *const content = getContent();
+ Widget *const content = getContent();
if (content)
{
content->setSize(mDimension.width - frameSize,
@@ -656,12 +664,12 @@ void ScrollArea::widgetResized(const gcn::Event &event A_UNUSED)
}
}
-void ScrollArea::widgetMoved(const gcn::Event& event A_UNUSED)
+void ScrollArea::widgetMoved(const Event& event A_UNUSED)
{
mRedraw = true;
}
-void ScrollArea::mousePressed(gcn::MouseEvent& event)
+void ScrollArea::mousePressed(MouseEvent& event)
{
const int x = event.getX();
const int y = event.getY();
@@ -731,16 +739,16 @@ void ScrollArea::mousePressed(gcn::MouseEvent& event)
}
}
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
mClickX = event.getX();
mClickY = event.getY();
}
}
-void ScrollArea::mouseReleased(gcn::MouseEvent& event)
+void ScrollArea::mouseReleased(MouseEvent& event)
{
- if (event.getButton() == gcn::MouseEvent::LEFT && mClickX && mClickY)
+ if (event.getButton() == MouseEvent::LEFT && mClickX && mClickY)
{
if (!event.isConsumed())
{
@@ -799,11 +807,11 @@ void ScrollArea::mouseReleased(gcn::MouseEvent& event)
mRedraw = true;
}
-void ScrollArea::mouseDragged(gcn::MouseEvent &event)
+void ScrollArea::mouseDragged(MouseEvent &event)
{
if (mIsVerticalMarkerDragged)
{
- const gcn::Rectangle barDim = getVerticalBarDimension();
+ const Rect barDim = getVerticalBarDimension();
const int pos = event.getY() - barDim.y
- mVerticalMarkerDragOffset;
@@ -822,7 +830,7 @@ void ScrollArea::mouseDragged(gcn::MouseEvent &event)
if (mIsHorizontalMarkerDragged)
{
- const gcn::Rectangle barDim = getHorizontalBarDimension();
+ const Rect barDim = getHorizontalBarDimension();
const int pos = event.getX() - barDim.x
- mHorizontalMarkerDragOffset;
@@ -843,56 +851,56 @@ void ScrollArea::mouseDragged(gcn::MouseEvent &event)
mRedraw = true;
}
-gcn::Rectangle ScrollArea::getVerticalBarDimension() const
+Rect ScrollArea::getVerticalBarDimension() const
{
if (!mVBarVisible)
- return gcn::Rectangle(0, 0, 0, 0);
+ return Rect(0, 0, 0, 0);
const int height = (mVBarVisible && mShowButtons) ? mScrollbarWidth : 0;
if (mHBarVisible)
{
- return gcn::Rectangle(mDimension.width - mScrollbarWidth,
+ return Rect(mDimension.width - mScrollbarWidth,
height,
mScrollbarWidth,
mDimension.height - 2 * height - mScrollbarWidth);
}
- return gcn::Rectangle(mDimension.width - mScrollbarWidth,
+ return Rect(mDimension.width - mScrollbarWidth,
height,
mScrollbarWidth,
mDimension.height - 2 * height);
}
-gcn::Rectangle ScrollArea::getHorizontalBarDimension() const
+Rect ScrollArea::getHorizontalBarDimension() const
{
if (!mHBarVisible)
- return gcn::Rectangle(0, 0, 0, 0);
+ return Rect(0, 0, 0, 0);
const int width = mShowButtons ? mScrollbarWidth : 0;
if (mVBarVisible)
{
- return gcn::Rectangle(width,
+ return Rect(width,
mDimension.height - mScrollbarWidth,
mDimension.width - 2 * width - mScrollbarWidth,
mScrollbarWidth);
}
- return gcn::Rectangle(width,
+ return Rect(width,
mDimension.height - mScrollbarWidth,
mDimension.width - 2 * width,
mScrollbarWidth);
}
-gcn::Rectangle ScrollArea::getVerticalMarkerDimension()
+Rect ScrollArea::getVerticalMarkerDimension()
{
if (!mVBarVisible)
- return gcn::Rectangle(0, 0, 0, 0);
+ return Rect(0, 0, 0, 0);
int length, pos;
int height;
const int h2 = mShowButtons
? mScrollbarWidth : mMarkerSize / 2;
- const gcn::Widget *content;
+ const Widget *content;
if (!mWidgets.empty())
content = *mWidgets.begin();
else
@@ -937,20 +945,20 @@ gcn::Rectangle ScrollArea::getVerticalMarkerDimension()
pos = 0;
}
- return gcn::Rectangle(mDimension.width - mScrollbarWidth, h2 + pos,
+ return Rect(mDimension.width - mScrollbarWidth, h2 + pos,
mScrollbarWidth, length);
}
-gcn::Rectangle ScrollArea::getHorizontalMarkerDimension()
+Rect ScrollArea::getHorizontalMarkerDimension()
{
if (!mHBarVisible)
- return gcn::Rectangle(0, 0, 0, 0);
+ return Rect(0, 0, 0, 0);
int length, pos;
int width;
const int w2 = mShowButtons
? mScrollbarWidth : mMarkerSize / 2;
- const gcn::Widget *content;
+ const Widget *content;
if (!mWidgets.empty())
content = *mWidgets.begin();
else
@@ -999,61 +1007,61 @@ gcn::Rectangle ScrollArea::getHorizontalMarkerDimension()
}
}
- return gcn::Rectangle(w2 + pos, mDimension.height - mScrollbarWidth,
+ return Rect(w2 + pos, mDimension.height - mScrollbarWidth,
length, mScrollbarWidth);
}
-gcn::Rectangle ScrollArea::getUpButtonDimension() const
+Rect ScrollArea::getUpButtonDimension() const
{
if (!mVBarVisible || !mShowButtons)
- return gcn::Rectangle(0, 0, 0, 0);
+ return Rect(0, 0, 0, 0);
- return gcn::Rectangle(mDimension.width - mScrollbarWidth, 0,
+ return Rect(mDimension.width - mScrollbarWidth, 0,
mScrollbarWidth, mScrollbarWidth);
}
-gcn::Rectangle ScrollArea::getDownButtonDimension() const
+Rect ScrollArea::getDownButtonDimension() const
{
if (!mVBarVisible || !mShowButtons)
- return gcn::Rectangle(0, 0, 0, 0);
+ return Rect(0, 0, 0, 0);
if (mVBarVisible && mHBarVisible)
{
- return gcn::Rectangle(mDimension.width - mScrollbarWidth,
+ return Rect(mDimension.width - mScrollbarWidth,
mDimension.height - mScrollbarWidth*2,
mScrollbarWidth,
mScrollbarWidth);
}
- return gcn::Rectangle(mDimension.width - mScrollbarWidth,
+ return Rect(mDimension.width - mScrollbarWidth,
mDimension.height - mScrollbarWidth,
mScrollbarWidth,
mScrollbarWidth);
}
-gcn::Rectangle ScrollArea::getLeftButtonDimension() const
+Rect ScrollArea::getLeftButtonDimension() const
{
if (!mHBarVisible || !mShowButtons)
- return gcn::Rectangle(0, 0, 0, 0);
+ return Rect(0, 0, 0, 0);
- return gcn::Rectangle(0, mDimension.height - mScrollbarWidth,
+ return Rect(0, mDimension.height - mScrollbarWidth,
mScrollbarWidth, mScrollbarWidth);
}
-gcn::Rectangle ScrollArea::getRightButtonDimension() const
+Rect ScrollArea::getRightButtonDimension() const
{
if (!mHBarVisible || !mShowButtons)
- return gcn::Rectangle(0, 0, 0, 0);
+ return Rect(0, 0, 0, 0);
if (mVBarVisible && mHBarVisible)
{
- return gcn::Rectangle(mDimension.width - mScrollbarWidth*2,
+ return Rect(mDimension.width - mScrollbarWidth*2,
mDimension.height - mScrollbarWidth,
mScrollbarWidth,
mScrollbarWidth);
}
- return gcn::Rectangle(mDimension.width - mScrollbarWidth,
+ return Rect(mDimension.width - mScrollbarWidth,
mDimension.height - mScrollbarWidth,
mScrollbarWidth,
mScrollbarWidth);
diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h
index 13e5e3665..7d2b39a96 100644
--- a/src/gui/widgets/scrollarea.h
+++ b/src/gui/widgets/scrollarea.h
@@ -23,10 +23,9 @@
#ifndef GUI_WIDGETS_SCROLLAREA_H
#define GUI_WIDGETS_SCROLLAREA_H
-#include "gui/widgets/widget2.h"
+#include "gui/base/widgets/scrollarea.hpp"
-#include <guichan/widgets/scrollarea.hpp>
-#include <guichan/widgetlistener.hpp>
+#include "listeners/widgetlistener.h"
#include "localconsts.h"
@@ -43,25 +42,18 @@ class ImageCollection;
* \ingroup GUI
*/
class ScrollArea final : public gcn::ScrollArea,
- public Widget2,
- public gcn::WidgetListener
+ public WidgetListener
{
public:
/**
- * Constructor that takes no content. Needed for use with the DropDown
- * class.
- */
- explicit ScrollArea(const bool opaque = true,
- const std::string &skin = "");
-
- /**
* Constructor.
*
* @param content the initial content to show in the scroll area
*/
- explicit ScrollArea(gcn::Widget *const widget,
- const bool opaque = true,
- const std::string &skin = "");
+ ScrollArea(Widget2 *const widget2,
+ Widget *const widget,
+ const bool opaque = true,
+ const std::string &skin = "");
A_DELETE_COPY(ScrollArea)
@@ -84,12 +76,12 @@ class ScrollArea final : public gcn::ScrollArea,
/**
* Draws the scroll area.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
/**
* Draws the background and border of the scroll area.
*/
- void drawFrame(gcn::Graphics *graphics) override final;
+ void drawFrame(Graphics *graphics) override final;
/**
* Sets whether the widget should draw its background or not.
@@ -105,43 +97,43 @@ class ScrollArea final : public gcn::ScrollArea,
/**
* Called when the mouse moves in the widget area.
*/
- void mouseMoved(gcn::MouseEvent& event) override final;
+ void mouseMoved(MouseEvent& event) override final;
/**
* Called when the mouse enteres the widget area.
*/
- void mouseEntered(gcn::MouseEvent& event) override final;
+ void mouseEntered(MouseEvent& event) override final;
/**
* Called when the mouse leaves the widget area.
*/
- void mouseExited(gcn::MouseEvent& event) override final;
+ void mouseExited(MouseEvent& event) override final;
- void mousePressed(gcn::MouseEvent& event) override final;
+ void mousePressed(MouseEvent& event) override final;
- void mouseReleased(gcn::MouseEvent& event) override final;
+ void mouseReleased(MouseEvent& event) override final;
- void mouseDragged(gcn::MouseEvent &event) override final;
+ void mouseDragged(MouseEvent &event) override final;
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
- void widgetMoved(const gcn::Event &event) override final;
+ void widgetMoved(const Event &event) override final;
- gcn::Rectangle getVerticalBarDimension() const;
+ Rect getVerticalBarDimension() const;
- gcn::Rectangle getHorizontalBarDimension() const;
+ Rect getHorizontalBarDimension() const;
- gcn::Rectangle getVerticalMarkerDimension();
+ Rect getVerticalMarkerDimension();
- gcn::Rectangle getHorizontalMarkerDimension();
+ Rect getHorizontalMarkerDimension();
- gcn::Rectangle getUpButtonDimension() const;
+ Rect getUpButtonDimension() const;
- gcn::Rectangle getDownButtonDimension() const;
+ Rect getDownButtonDimension() const;
- gcn::Rectangle getLeftButtonDimension() const;
+ Rect getLeftButtonDimension() const;
- gcn::Rectangle getRightButtonDimension() const;
+ Rect getRightButtonDimension() const;
protected:
enum BUTTON_DIR
@@ -158,19 +150,19 @@ class ScrollArea final : public gcn::ScrollArea,
*/
void init(std::string skinName);
- void drawButton(gcn::Graphics *const graphics, const BUTTON_DIR dir);
- void calcButton(gcn::Graphics *const graphics, const BUTTON_DIR dir);
- void drawVBar(gcn::Graphics *const graphics) override final;
- void drawHBar(gcn::Graphics *const graphics) override final;
- void drawVMarker(gcn::Graphics *const graphics) override final;
- void drawHMarker(gcn::Graphics *const graphics) override final;
+ void drawButton(Graphics *const graphics, const BUTTON_DIR dir);
+ void calcButton(Graphics *const graphics, const BUTTON_DIR dir);
+ void drawVBar(Graphics *const graphics) override final;
+ void drawHBar(Graphics *const graphics) override final;
+ void drawVMarker(Graphics *const graphics) override final;
+ void drawHMarker(Graphics *const graphics) override final;
- void calcVBar(gcn::Graphics *const graphics);
- void calcHBar(gcn::Graphics *const graphics);
- void calcVMarker(gcn::Graphics *const graphics);
- void calcHMarker(gcn::Graphics *const graphics);
+ void calcVBar(Graphics *const graphics);
+ void calcHBar(Graphics *const graphics);
+ void calcVMarker(Graphics *const graphics);
+ void calcHMarker(Graphics *const graphics);
- void updateCalcFlag(gcn::Graphics *const graphics);
+ void updateCalcFlag(Graphics *const graphics);
static int instances;
static float mAlpha;
diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp
index 2cb7f60d1..218efe8a2 100644
--- a/src/gui/widgets/setupitem.cpp
+++ b/src/gui/widgets/setupitem.cpp
@@ -24,10 +24,12 @@
#include "main.h"
#include "soundmanager.h"
-#include "gui/sdlfont.h"
+#include "gui/font.h"
+#include "gui/gui.h"
#include "gui/windows/editdialog.h"
+#include "gui/widgets/button.h"
#include "gui/widgets/checkbox.h"
#include "gui/widgets/dropdown.h"
#include "gui/widgets/horizontcontainer.h"
@@ -37,12 +39,12 @@
#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/mathutils.h"
-#include <guichan/font.hpp>
-
#include "debug.h"
SetupItem::SetupItem(const std::string &restrict text,
@@ -51,8 +53,8 @@ SetupItem::SetupItem(const std::string &restrict text,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
const bool mainConfig) :
- gcn::ActionListener(),
- Widget2(),
+ ActionListener(),
+ Widget2(parent),
mText(text),
mDescription(description),
mKeyName(keyName),
@@ -75,8 +77,8 @@ SetupItem::SetupItem(const std::string &restrict text,
const std::string &restrict eventName,
const std::string &restrict def,
const bool mainConfig) :
- gcn::ActionListener(),
- Widget2(),
+ ActionListener(),
+ Widget2(parent),
mText(text),
mDescription(description),
mKeyName(keyName),
@@ -154,7 +156,7 @@ std::string SetupItem::getActionEventId() const
return mWidget->getActionEventId();
}
-void SetupItem::action(const gcn::ActionEvent &event)
+void SetupItem::action(const ActionEvent &event)
{
if (!mWidget)
return;
@@ -189,7 +191,7 @@ void SetupItem::externalUnloaded(const std::string &eventName A_UNUSED)
{
}
-void SetupItem::fixFirstItemSize(gcn::Widget *const widget)
+void SetupItem::fixFirstItemSize(Widget *const widget)
{
const int maxSize = mParent->getPreferredFirstItemSize();
if (widget->getWidth() < maxSize)
@@ -393,7 +395,7 @@ void SetupItemTextField::toWidget()
mTextField->setText(mValue);
}
-void SetupItemTextField::action(const gcn::ActionEvent &event)
+void SetupItemTextField::action(const ActionEvent &event)
{
if (!mTextField)
return;
@@ -529,7 +531,7 @@ void SetupItemIntTextField::toWidget()
mTextField->setText(mValue);
}
-void SetupItemIntTextField::action(const gcn::ActionEvent &event)
+void SetupItemIntTextField::action(const ActionEvent &event)
{
if (!mTextField)
return;
@@ -609,7 +611,7 @@ void SetupItemLabel::toWidget()
{
}
-void SetupItemLabel::action(const gcn::ActionEvent &event A_UNUSED)
+void SetupItemLabel::action(const ActionEvent &event A_UNUSED)
{
}
@@ -623,7 +625,7 @@ SetupItemDropDown::SetupItemDropDown(const std::string &restrict text,
const std::string &restrict keyName,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
- gcn::ListModel *restrict const model,
+ ListModel *restrict const model,
const int width,
const bool mainConfig) :
SetupItem(text, description, keyName, parent, eventName, mainConfig),
@@ -642,7 +644,7 @@ SetupItemDropDown::SetupItemDropDown(const std::string &restrict text,
const std::string &restrict keyName,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
- gcn::ListModel *restrict const model,
+ ListModel *restrict const model,
const int width,
const std::string &restrict def,
const bool mainConfig) :
@@ -764,7 +766,7 @@ void SetupItemSlider::createControls()
mHorizont = new HorizontContainer(this, 32, 2);
mLabel = new Label(this, mText);
- mSlider = new Slider(mMin, mMax);
+ mSlider = new Slider(this, mMin, mMax);
mSlider->setActionEventId(mEventName);
mSlider->addActionListener(mParent);
mSlider->setValue2(atof(mValue.c_str()));
@@ -799,7 +801,7 @@ void SetupItemSlider::toWidget()
mSlider->setValue2(atof(mValue.c_str()));
}
-void SetupItemSlider::action(const gcn::ActionEvent &event A_UNUSED)
+void SetupItemSlider::action(const ActionEvent &event A_UNUSED)
{
fromWidget();
if (mOnTheFly)
@@ -888,7 +890,7 @@ void SetupItemSlider2::createControls()
mLabel = new Label(this, mText);
mLabel2 = new Label(this, "");
mLabel2->setWidth(width);
- mSlider = new Slider(mMin, mMax);
+ mSlider = new Slider(this, mMin, mMax);
mSlider->setActionEventId(mEventName);
mSlider->addActionListener(mParent);
mSlider->setValue2(atof(mValue.c_str()));
@@ -918,7 +920,7 @@ int SetupItemSlider2::getMaxWidth()
int maxWidth = 0;
SetupItemNamesConstIter it = mValues->begin();
const SetupItemNamesConstIter it_end = mValues->end();
- const gcn::Font *const font = gui->getFont();
+ const Font *const font = gui->getFont();
while (it != it_end)
{
@@ -954,7 +956,7 @@ void SetupItemSlider2::toWidget()
updateLabel();
}
-void SetupItemSlider2::action(const gcn::ActionEvent &event A_UNUSED)
+void SetupItemSlider2::action(const ActionEvent &event A_UNUSED)
{
fromWidget();
updateLabel();
@@ -1002,7 +1004,7 @@ SetupItemSliderList::SetupItemSliderList(const std::string &restrict text,
const std::string &restrict keyName,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
- gcn::ListModel *restrict const model,
+ ListModel *restrict const model,
const int width, const bool onTheFly,
const bool mainConfig) :
SetupItem(text, description, keyName, parent, eventName, mainConfig),
@@ -1022,7 +1024,7 @@ SetupItemSliderList::SetupItemSliderList(const std::string &restrict text,
const std::string &restrict keyName,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
- gcn::ListModel *restrict const model,
+ ListModel *restrict const model,
const std::string &restrict def,
const int width,
const bool onTheFly,
@@ -1086,7 +1088,7 @@ void SetupItemSliderList::toWidget()
mSlider->setSelectedString(mValue);
}
-void SetupItemSliderList::action(const gcn::ActionEvent &event A_UNUSED)
+void SetupItemSliderList::action(const ActionEvent &event A_UNUSED)
{
fromWidget();
if (mOnTheFly)
@@ -1107,7 +1109,7 @@ SetupItemSound::SetupItemSound(const std::string &restrict text,
const std::string &restrict keyName,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
- gcn::ListModel *restrict const model,
+ ListModel *restrict const model,
const int width, const bool onTheFly,
const bool mainConfig) :
SetupItemSliderList(text, description, keyName, parent, eventName,
@@ -1124,7 +1126,7 @@ void SetupItemSound::addMoreControls()
mHorizont->add(mButton);
}
-void SetupItemSound::action(const gcn::ActionEvent &event)
+void SetupItemSound::action(const ActionEvent &event)
{
if (event.getId() == mEventName + "_PLAY")
{
@@ -1145,7 +1147,7 @@ SetupItemSliderInt::SetupItemSliderInt(const std::string &restrict text,
const std::string &restrict keyName,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
- gcn::ListModel *restrict const model,
+ ListModel *restrict const model,
const int min,
const int width,
const bool onTheFly,
diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h
index c72bb39ef..7dee860be 100644
--- a/src/gui/widgets/setupitem.h
+++ b/src/gui/widgets/setupitem.h
@@ -21,14 +21,14 @@
#ifndef GUI_WIDGETS_SETUPITEM_H
#define GUI_WIDGETS_SETUPITEM_H
-#include "gui/widgets/button.h"
-#include "gui/widgets/tabs/setuptabscroll.h"
+#include "gui/widgets/widget2.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
#include <list>
#include <vector>
+class Button;
class CheckBox;
class Configuration;
class DropDown;
@@ -36,16 +36,13 @@ class EditDialog;
class HorizontContainer;
class IntTextField;
class Label;
+class ListModel;
+class SetupTabScroll;
class Slider;
class SliderList;
class TextField;
-namespace gcn
-{
- class ListModel;
-}
-
-class SetupItem : public gcn::ActionListener,
+class SetupItem : public ActionListener,
public Widget2
{
public:
@@ -69,17 +66,17 @@ class SetupItem : public gcn::ActionListener,
virtual void toWidget() = 0;
- void setWidget(gcn::Widget *widget)
+ void setWidget(Widget *widget)
{ mWidget = widget; }
- gcn::Widget *getWidget() const A_WARN_UNUSED
+ Widget *getWidget() const A_WARN_UNUSED
{ return mWidget; }
Configuration *getConfig() const A_WARN_UNUSED;
virtual std::string getActionEventId() const A_WARN_UNUSED;
- virtual void action(const gcn::ActionEvent &event) override;
+ virtual void action(const ActionEvent &event) override;
virtual void action();
@@ -94,11 +91,11 @@ class SetupItem : public gcn::ActionListener,
bool isMainConfig() const A_WARN_UNUSED
{ return mMainConfig; }
- void fixFirstItemSize(gcn::Widget *const widget);
+ void fixFirstItemSize(Widget *const widget);
virtual void rereadValue();
- void setValue(const std::string str)
+ void setValue(const std::string &str)
{ mValue = str; }
std::string getValue() const
@@ -137,9 +134,9 @@ class SetupItem : public gcn::ActionListener,
std::string mDefault;
- gcn::Widget *mWidget;
+ Widget *mWidget;
- std::list<gcn::Widget*> mTempWidgets;
+ std::list<Widget*> mTempWidgets;
int mValueType;
@@ -210,7 +207,7 @@ class SetupItemTextField final : public SetupItem
void toWidget() override final;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void apply(const std::string &eventName) override final;
@@ -265,7 +262,7 @@ class SetupItemIntTextField final : public SetupItem
void toWidget() override final;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void apply(const std::string &eventName) override final;
@@ -297,7 +294,7 @@ class SetupItemLabel final : public SetupItem
void toWidget() override final;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void apply(const std::string &eventName) override final;
@@ -314,7 +311,7 @@ class SetupItemDropDown final : public SetupItem
const std::string &restrict keyName,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
- gcn::ListModel *restrict const model,
+ ListModel *restrict const model,
const int width, const bool mainConfig = true);
SetupItemDropDown(const std::string &restrict text,
@@ -322,7 +319,7 @@ class SetupItemDropDown final : public SetupItem
const std::string &restrict keyName,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
- gcn::ListModel *restrict const model,
+ ListModel *restrict const model,
const int width,
const std::string &restrict def,
const bool mainConfig = true);
@@ -340,7 +337,7 @@ class SetupItemDropDown final : public SetupItem
protected:
HorizontContainer *mHorizont;
Label *mLabel;
- gcn::ListModel *mModel;
+ ListModel *mModel;
DropDown *mDropDown;
int mWidth;
};
@@ -377,7 +374,7 @@ class SetupItemSlider final : public SetupItem
void toWidget() override final;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void apply(const std::string &eventName) override final;
@@ -433,7 +430,7 @@ class SetupItemSlider2 final : public SetupItem
void toWidget() override final;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void apply(const std::string &eventName) override final;
@@ -470,7 +467,7 @@ class SetupItemSliderList : public SetupItem
void toWidget() override;
- virtual void action(const gcn::ActionEvent &event) override;
+ virtual void action(const ActionEvent &event) override;
void apply(const std::string &eventName) override final;
@@ -482,7 +479,7 @@ class SetupItemSliderList : public SetupItem
const std::string &restrict keyName,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
- gcn::ListModel *restrict const model,
+ ListModel *restrict const model,
const int width = 150, const bool onTheFly = false,
const bool mainConfig = true);
@@ -491,7 +488,7 @@ class SetupItemSliderList : public SetupItem
const std::string &restrict keyName,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
- gcn::ListModel *restrict const model,
+ ListModel *restrict const model,
const std::string &restrict def,
const int width = 150,
const bool onTheFly = false,
@@ -500,7 +497,7 @@ class SetupItemSliderList : public SetupItem
HorizontContainer *mHorizont;
Label *mLabel;
SliderList *mSlider;
- gcn::ListModel *mModel;
+ ListModel *mModel;
int mWidth;
bool mOnTheFly;
};
@@ -513,14 +510,14 @@ class SetupItemSound final : public SetupItemSliderList
const std::string &restrict keyName,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
- gcn::ListModel *restrict const model,
+ ListModel *restrict const model,
const int width = 150,
const bool onTheFly = false,
const bool mainConfig = true);
A_DELETE_COPY(SetupItemSound)
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void addMoreControls() override final;
@@ -536,7 +533,7 @@ class SetupItemSliderInt final : public SetupItemSliderList
const std::string &restrict keyName,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
- gcn::ListModel *restrict const model,
+ ListModel *restrict const model,
const int min,
const int width = 150,
const bool onTheFly = false,
diff --git a/src/gui/widgets/setuptouchitem.cpp b/src/gui/widgets/setuptouchitem.cpp
index b080de428..3c8238fd0 100644
--- a/src/gui/widgets/setuptouchitem.cpp
+++ b/src/gui/widgets/setuptouchitem.cpp
@@ -20,74 +20,18 @@
#include "gui/widgets/setuptouchitem.h"
-#include "gui/setupactiondata.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 <algorithm>
+#include "gui/widgets/tabs/setuptabscroll.h"
-#include "debug.h"
-
-static class SortTouchActionFunctor final
-{
- public:
- bool operator() (const SetupActionData *const data1,
- const SetupActionData *const data2) const
- {
- if (!data1 || !data2)
- return false;
- return data1->name < data2->name;
- }
-} touchActionSorter;
-
-TouchActionsModel::TouchActionsModel() :
- NamesModel(),
- mActionId(),
- mActionToSelection()
-{
- std::vector<SetupActionData*> data;
-
- for (int f = 0, sz = touchActionDataSize; f < sz; f ++)
- {
- int k = 0;
- while (!touchActionData[f][k].name.empty())
- {
- data.push_back(&touchActionData[f][k]);
- k ++;
- }
- }
-
- std::sort(data.begin(), data.end(), touchActionSorter);
- int cnt = 0;
- FOR_EACH (std::vector<SetupActionData*>::iterator, it, data)
- {
- const SetupActionData *const data1 = *it;
- mNames.push_back(data1->name);
- mActionId.push_back(data1->actionId);
- mActionToSelection[data1->actionId] = cnt;
- cnt ++;
- }
-}
-
-int TouchActionsModel::getActionFromSelection(const int sel) const
-{
- if (sel < 0 || sel > static_cast<signed int>(mActionId.size()))
- return -1;
- return mActionId[sel];
-}
-
-int TouchActionsModel::getSelectionFromAction(const int action) const
-{
- const std::map<int, int>::const_iterator it
- = mActionToSelection.find(action);
- if (it == mActionToSelection.end())
- return 0;
- return (*it).second;
-}
+#include "utils/stringutils.h"
+#include "debug.h"
SetupActionDropDown::SetupActionDropDown(const std::string &restrict text,
const std::string &restrict
diff --git a/src/gui/widgets/setuptouchitem.h b/src/gui/widgets/setuptouchitem.h
index f15c0d43d..f7bbf2691 100644
--- a/src/gui/widgets/setuptouchitem.h
+++ b/src/gui/widgets/setuptouchitem.h
@@ -21,27 +21,9 @@
#ifndef GUI_WIDGETS_SETUPTOUCHITEM_H
#define GUI_WIDGETS_SETUPTOUCHITEM_H
-#include "gui/widgets/namesmodel.h"
#include "gui/widgets/setupitem.h"
-class TouchActionsModel final : public NamesModel
-{
- public:
- TouchActionsModel();
-
- A_DELETE_COPY(TouchActionsModel)
-
- ~TouchActionsModel()
- { }
-
- int getActionFromSelection(const int sel) const;
-
- int getSelectionFromAction(const int action) const;
-
- private:
- std::vector<int> mActionId;
- std::map<int, int> mActionToSelection;
-};
+class TouchActionsModel;
class SetupActionDropDown final : public SetupItem
{
diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp
index 58f9ec8eb..007dc6442 100644
--- a/src/gui/widgets/shoplistbox.cpp
+++ b/src/gui/widgets/shoplistbox.cpp
@@ -27,23 +27,23 @@
#include "being/playerinfo.h"
+#include "gui/font.h"
#include "gui/viewport.h"
#include "gui/popups/itempopup.h"
-#include "gui/widgets/shopitems.h"
+#include "gui/models/shopitems.h"
#include "resources/image.h"
-#include <guichan/font.hpp>
-#include <guichan/listmodel.hpp>
+#include "gui/models/listmodel.h"
#include "debug.h"
const int ITEM_ICON_SIZE = 32;
ShopListBox::ShopListBox(const Widget2 *const widget,
- gcn::ListModel *const listModel) :
+ ListModel *const listModel) :
ListBox(widget, listModel, "shoplistbox.xml"),
mPlayerMoney(0),
mShopItems(nullptr),
@@ -60,7 +60,7 @@ ShopListBox::ShopListBox(const Widget2 *const widget,
}
ShopListBox::ShopListBox(const Widget2 *const widget,
- gcn::ListModel *const listModel,
+ ListModel *const listModel,
ShopItems *const shopListModel) :
ListBox(widget, listModel, "shoplistbox.xml"),
mPlayerMoney(0),
@@ -82,7 +82,7 @@ void ShopListBox::setPlayersMoney(const int money)
mPlayerMoney = money;
}
-void ShopListBox::draw(gcn::Graphics *gcnGraphics)
+void ShopListBox::draw(Graphics *graphics)
{
BLOCK_START("ShopListBox::draw")
if (!mListModel || !mShopItems)
@@ -95,8 +95,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
mAlpha = client->getGuiAlpha();
const int alpha = static_cast<int>(mAlpha * 255.0F);
- Graphics *graphics = static_cast<Graphics*>(gcnGraphics);
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
const int sz = mListModel->getNumberOfElements();
const int fontHeigh = getFont()->getHeight();
@@ -107,8 +106,8 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
++i, y += mRowHeight)
{
bool needDraw(false);
- gcn::Color temp;
- gcn::Color* backgroundColor = &mBackgroundColor;
+ Color temp;
+ Color* backgroundColor = &mBackgroundColor;
ShopItem *const item = mShopItems->at(i);
if (item && ((mShopItems && mPlayerMoney < item->getPrice()
@@ -145,7 +144,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
if (needDraw)
{
graphics->setColor(*backgroundColor);
- graphics->fillRectangle(gcn::Rectangle(mPadding, y + mPadding,
+ graphics->fillRectangle(Rect(mPadding, y + mPadding,
width, mRowHeight));
}
@@ -155,7 +154,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics)
if (icon)
{
icon->setAlpha(1.0F);
- graphics->drawImage2(icon, mPadding, y + mPadding);
+ graphics->drawImage(icon, mPadding, y + mPadding);
}
}
if (mSelected == i)
@@ -190,7 +189,7 @@ void ShopListBox::setPriceCheck(const bool check)
mPriceCheck = check;
}
-void ShopListBox::mouseMoved(gcn::MouseEvent &event)
+void ShopListBox::mouseMoved(MouseEvent &event)
{
if (!mItemPopup || !mRowHeight)
return;
@@ -222,10 +221,10 @@ void ShopListBox::mouseMoved(gcn::MouseEvent &event)
}
}
-void ShopListBox::mouseReleased(gcn::MouseEvent& mouseEvent)
+void ShopListBox::mouseReleased(MouseEvent& mouseEvent)
{
ListBox::mouseReleased(mouseEvent);
- if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT)
+ if (mouseEvent.getButton() == MouseEvent::RIGHT)
{
setSelected(std::max(0, getSelectionByMouse(mouseEvent.getY())));
@@ -237,7 +236,7 @@ void ShopListBox::mouseReleased(gcn::MouseEvent& mouseEvent)
}
}
-void ShopListBox::mouseExited(gcn::MouseEvent& mouseEvent A_UNUSED)
+void ShopListBox::mouseExited(MouseEvent& mouseEvent A_UNUSED)
{
if (!mItemPopup)
return;
diff --git a/src/gui/widgets/shoplistbox.h b/src/gui/widgets/shoplistbox.h
index 095d187eb..17c1ed4d5 100644
--- a/src/gui/widgets/shoplistbox.h
+++ b/src/gui/widgets/shoplistbox.h
@@ -42,13 +42,13 @@ class ShopListBox final : public ListBox
* Constructor.
*/
ShopListBox(const Widget2 *const widget,
- gcn::ListModel *const listModel);
+ ListModel *const listModel);
/**
* Constructor with shopitems
*/
ShopListBox(const Widget2 *const widget,
- gcn::ListModel *const listModel,
+ ListModel *const listModel,
ShopItems *const shopListModel);
A_DELETE_COPY(ShopListBox)
@@ -56,7 +56,7 @@ class ShopListBox final : public ListBox
/**
* Draws the list box.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
/**
* gives information about the current player's money
@@ -74,11 +74,11 @@ class ShopListBox final : public ListBox
*/
void setPriceCheck(const bool check);
- void mouseMoved(gcn::MouseEvent &event) override final;
+ void mouseMoved(MouseEvent &event) override final;
- void mouseReleased(gcn::MouseEvent& mouseEvent) override final;
+ void mouseReleased(MouseEvent& mouseEvent) override final;
- void mouseExited(gcn::MouseEvent& mouseEvent) override final;
+ void mouseExited(MouseEvent& mouseEvent) override final;
void setProtectItems(bool p)
{ mProtectItems = p; }
@@ -94,8 +94,8 @@ class ShopListBox final : public ListBox
ItemPopup *mItemPopup;
- gcn::Color mBackgroundColor;
- gcn::Color mWarningColor;
+ Color mBackgroundColor;
+ Color mWarningColor;
bool mPriceCheck;
bool mProtectItems;
diff --git a/src/gui/widgets/shortcutcontainer.cpp b/src/gui/widgets/shortcutcontainer.cpp
index a3030b035..0d9aa64a6 100644
--- a/src/gui/widgets/shortcutcontainer.cpp
+++ b/src/gui/widgets/shortcutcontainer.cpp
@@ -24,15 +24,16 @@
#include "graphicsvertexes.h"
+#include "gui/gui.h"
+
#include "debug.h"
float ShortcutContainer::mAlpha = 1.0;
-ShortcutContainer::ShortcutContainer() :
- gcn::Widget(),
- Widget2(),
- gcn::WidgetListener(),
- gcn::MouseListener(),
+ShortcutContainer::ShortcutContainer(Widget2 *const widget) :
+ Widget(widget),
+ WidgetListener(),
+ MouseListener(),
mBackgroundImg(nullptr),
mMaxItems(0),
mBoxWidth(1),
@@ -53,14 +54,14 @@ ShortcutContainer::~ShortcutContainer()
mVertexes = nullptr;
}
-void ShortcutContainer::widgetResized(const gcn::Event &event A_UNUSED)
+void ShortcutContainer::widgetResized(const Event &event A_UNUSED)
{
mGridWidth = mDimension.width / mBoxWidth;
if (mGridWidth < 1)
mGridWidth = 1;
- mGridHeight = mMaxItems / mGridWidth;
+ mGridHeight = mMaxItems / static_cast<unsigned int>(mGridWidth);
if (mMaxItems % mGridWidth != 0 || mGridHeight < 1)
++mGridHeight;
@@ -72,7 +73,7 @@ void ShortcutContainer::widgetResized(const gcn::Event &event A_UNUSED)
int ShortcutContainer::getIndexFromGrid(const int pointX,
const int pointY) const
{
- const gcn::Rectangle tRect = gcn::Rectangle(0, 0,
+ const Rect tRect = Rect(0, 0,
mGridWidth * mBoxWidth, mGridHeight * mBoxHeight);
int index = ((pointY / mBoxHeight) * mGridWidth) + pointX / mBoxWidth;
@@ -109,14 +110,14 @@ void ShortcutContainer::drawBackground(Graphics *g)
{
for (unsigned i = 0; i < mMaxItems; i ++)
{
- g->drawImage2(mBackgroundImg, (i % mGridWidth) * mBoxWidth,
+ g->drawImage(mBackgroundImg, (i % mGridWidth) * mBoxWidth,
(i / mGridWidth) * mBoxHeight);
}
}
}
}
-void ShortcutContainer::widgetMoved(const gcn::Event& event A_UNUSED)
+void ShortcutContainer::widgetMoved(const Event& event A_UNUSED)
{
mRedraw = true;
}
diff --git a/src/gui/widgets/shortcutcontainer.h b/src/gui/widgets/shortcutcontainer.h
index 8bd84758d..81392097b 100644
--- a/src/gui/widgets/shortcutcontainer.h
+++ b/src/gui/widgets/shortcutcontainer.h
@@ -23,11 +23,10 @@
#ifndef GUI_WIDGETS_SHORTCUTCONTAINER_H
#define GUI_WIDGETS_SHORTCUTCONTAINER_H
-#include "gui/widgets/widget2.h"
+#include "gui/widgets/widget.h"
-#include <guichan/mouselistener.hpp>
-#include <guichan/widget.hpp>
-#include <guichan/widgetlistener.hpp>
+#include "listeners/mouselistener.h"
+#include "listeners/widgetlistener.h"
class Image;
class ImageCollection;
@@ -37,10 +36,9 @@ class ImageCollection;
*
* \ingroup GUI
*/
-class ShortcutContainer : public gcn::Widget,
- public Widget2,
- public gcn::WidgetListener,
- public gcn::MouseListener
+class ShortcutContainer : public Widget,
+ public WidgetListener,
+ public MouseListener
{
public:
A_DELETE_COPY(ShortcutContainer)
@@ -53,34 +51,34 @@ class ShortcutContainer : public gcn::Widget,
/**
* Draws the shortcuts
*/
- virtual void draw(gcn::Graphics *graphics) override = 0;
+ virtual void draw(Graphics *graphics) override = 0;
/**
* Invoked when a widget changes its size. This is used to determine
* the new height of the container.
*/
- virtual void widgetResized(const gcn::Event &event) override final;
+ virtual void widgetResized(const Event &event) override final;
- virtual void widgetMoved(const gcn::Event& event) override final;
+ virtual void widgetMoved(const Event& event) override final;
/**
* Handles mouse when dragged.
*/
- virtual void mouseDragged(gcn::MouseEvent &event A_UNUSED) override
+ virtual void mouseDragged(MouseEvent &event A_UNUSED) override
{
}
/**
* Handles mouse when pressed.
*/
- virtual void mousePressed(gcn::MouseEvent &event A_UNUSED) override
+ virtual void mousePressed(MouseEvent &event A_UNUSED) override
{
}
/**
* Handles mouse release.
*/
- virtual void mouseReleased(gcn::MouseEvent &event A_UNUSED) override
+ virtual void mouseReleased(MouseEvent &event A_UNUSED) override
{
}
@@ -102,7 +100,7 @@ class ShortcutContainer : public gcn::Widget,
/**
* Constructor. Initializes the shortcut container.
*/
- explicit ShortcutContainer();
+ explicit ShortcutContainer(Widget2 *const widget);
/**
* Gets the index from the grid provided the point is in an item box.
diff --git a/src/gui/widgets/skillinfo.cpp b/src/gui/widgets/skillinfo.cpp
index 46a3f425f..a009d623a 100644
--- a/src/gui/widgets/skillinfo.cpp
+++ b/src/gui/widgets/skillinfo.cpp
@@ -27,7 +27,8 @@
#include "gui/theme.h"
#include "gui/widgets/skilldata.h"
-#include "gui/widgets/skillmodel.h"
+
+#include "gui/models/skillmodel.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
diff --git a/src/gui/widgets/skillinfo.h b/src/gui/widgets/skillinfo.h
index d268b3438..f9baec6cc 100644
--- a/src/gui/widgets/skillinfo.h
+++ b/src/gui/widgets/skillinfo.h
@@ -23,7 +23,7 @@
#ifndef GUI_WIDGETS_SKILLINFO_H
#define GUI_WIDGETS_SKILLINFO_H
-#include <guichan/color.hpp>
+#include "gui/color.h"
#include <vector>
#include <map>
@@ -43,7 +43,7 @@ struct SkillInfo final
std::string skillLevel;
std::string skillExp;
float progress;
- gcn::Color color;
+ Color color;
SkillDataMap dataMap;
SkillModel *model;
SkillData *data;
diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp
index 750b58528..7a9b38050 100644
--- a/src/gui/widgets/slider.cpp
+++ b/src/gui/widgets/slider.cpp
@@ -25,8 +25,11 @@
#include "client.h"
#include "graphicsvertexes.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
+
+#include "gui/gui.h"
#include "resources/image.h"
@@ -42,9 +45,9 @@ static std::string const data[2] =
"slider_highlighted.xml"
};
-Slider::Slider(const double scaleEnd) :
- gcn::Slider(scaleEnd),
- Widget2(),
+Slider::Slider(Widget2 *const widget,
+ const double scaleEnd) :
+ gcn::Slider(widget, scaleEnd),
mVertexes(new ImageCollection),
mHasMouse(false),
mRedraw(true)
@@ -52,9 +55,10 @@ Slider::Slider(const double scaleEnd) :
init();
}
-Slider::Slider(const double scaleStart, const double scaleEnd) :
- gcn::Slider(scaleStart, scaleEnd),
- Widget2(),
+Slider::Slider(Widget2 *const widget,
+ const double scaleStart,
+ const double scaleEnd) :
+ gcn::Slider(widget, scaleStart, scaleEnd),
mVertexes(new ImageCollection),
mHasMouse(false),
mRedraw(true)
@@ -118,7 +122,7 @@ void Slider::updateAlpha()
}
}
-void Slider::draw(gcn::Graphics *graphics)
+void Slider::draw(Graphics *graphics)
{
BLOCK_START("Slider::draw")
if (!buttons[0].grid[HSTART] || !buttons[1].grid[HSTART]
@@ -133,19 +137,18 @@ void Slider::draw(gcn::Graphics *graphics)
int x = 0;
const int y = mHasMouse ? (h - buttons[1].grid[HSTART]->getHeight()) / 2 :
(h - buttons[0].grid[HSTART]->getHeight()) / 2;
- Graphics *const g = static_cast<Graphics*>(graphics);
updateAlpha();
if (isBatchDrawRenders(openGLMode))
{
- if (mRedraw || g->getRedraw())
+ if (mRedraw || graphics->getRedraw())
{
mRedraw = false;
mVertexes->clear();
if (!mHasMouse)
{
- g->calcTileCollection(mVertexes,
+ graphics->calcTileCollection(mVertexes,
buttons[0].grid[HSTART], x, y);
const int width = buttons[0].grid[HSTART]->getWidth();
@@ -155,24 +158,31 @@ void Slider::draw(gcn::Graphics *graphics)
if (buttons[0].grid[HMID])
{
const Image *const hMid = buttons[0].grid[HMID];
- g->calcPattern(mVertexes, hMid, x, y,
+ graphics->calcPattern(mVertexes,
+ hMid,
+ x, y,
w, hMid->getHeight());
}
x += w;
- g->calcTileCollection(mVertexes, buttons[0].grid[HEND], x, y);
+ graphics->calcTileCollection(mVertexes,
+ buttons[0].grid[HEND],
+ x, y);
const Image *const img = buttons[0].grid[HGRIP];
if (img)
{
- g->calcTileCollection(mVertexes, img, getMarkerPosition(),
+ graphics->calcTileCollection(mVertexes,
+ img,
+ getMarkerPosition(),
(mDimension.height - img->getHeight()) / 2);
}
}
else
{
- g->calcTileCollection(mVertexes,
- buttons[1].grid[HSTART], x, y);
+ graphics->calcTileCollection(mVertexes,
+ buttons[1].grid[HSTART],
+ x, y);
const int width = buttons[1].grid[HSTART]->getWidth();
w -= width;
@@ -183,32 +193,36 @@ void Slider::draw(gcn::Graphics *graphics)
if (buttons[1].grid[HMID])
{
const Image *const hMid = buttons[1].grid[HMID];
- g->calcPattern(mVertexes, hMid, x, y,
+ graphics->calcPattern(mVertexes,
+ hMid,
+ x, y,
w, hMid->getHeight());
}
x += w;
if (buttons[1].grid[HEND])
{
- g->calcTileCollection(mVertexes,
+ graphics->calcTileCollection(mVertexes,
buttons[1].grid[HEND], x, y);
}
const Image *const img = buttons[1].grid[HGRIP];
if (img)
{
- g->calcTileCollection(mVertexes, img, getMarkerPosition(),
+ graphics->calcTileCollection(mVertexes,
+ img,
+ getMarkerPosition(),
(mDimension.height - img->getHeight()) / 2);
}
}
}
- g->drawTileCollection(mVertexes);
+ graphics->drawTileCollection(mVertexes);
}
else
{
if (!mHasMouse)
{
- g->drawImage2(buttons[0].grid[HSTART], x, y);
+ graphics->drawImage(buttons[0].grid[HSTART], x, y);
const int width = buttons[0].grid[HSTART]->getWidth();
w -= width + buttons[0].grid[HEND]->getWidth();
x += width;
@@ -216,22 +230,22 @@ void Slider::draw(gcn::Graphics *graphics)
if (buttons[0].grid[HMID])
{
const Image *const hMid = buttons[0].grid[HMID];
- g->drawPattern(hMid, x, y, w, hMid->getHeight());
+ graphics->drawPattern(hMid, x, y, w, hMid->getHeight());
}
x += w;
- g->drawImage2(buttons[0].grid[HEND], x, y);
+ graphics->drawImage(buttons[0].grid[HEND], x, y);
const Image *const img = buttons[0].grid[HGRIP];
if (img)
{
- g->drawImage2(img, getMarkerPosition(),
+ graphics->drawImage(img, getMarkerPosition(),
(mDimension.height - img->getHeight()) / 2);
}
}
else
{
- g->drawImage2(buttons[1].grid[HSTART], x, y);
+ graphics->drawImage(buttons[1].grid[HSTART], x, y);
const int width = buttons[1].grid[HSTART]->getWidth();
w -= width;
@@ -242,17 +256,17 @@ void Slider::draw(gcn::Graphics *graphics)
if (buttons[1].grid[HMID])
{
const Image *const hMid = buttons[1].grid[HMID];
- g->drawPattern(hMid, x, y, w, hMid->getHeight());
+ graphics->drawPattern(hMid, x, y, w, hMid->getHeight());
}
x += w;
if (buttons[1].grid[HEND])
- g->drawImage2(buttons[1].grid[HEND], x, y);
+ graphics->drawImage(buttons[1].grid[HEND], x, y);
const Image *const img = buttons[1].grid[HGRIP];
if (img)
{
- g->drawImage2(img, getMarkerPosition(),
+ graphics->drawImage(img, getMarkerPosition(),
(mDimension.height - img->getHeight()) / 2);
}
}
@@ -261,21 +275,21 @@ void Slider::draw(gcn::Graphics *graphics)
BLOCK_END("Slider::draw")
}
-void Slider::mouseEntered(gcn::MouseEvent& event A_UNUSED)
+void Slider::mouseEntered(MouseEvent& event A_UNUSED)
{
mHasMouse = true;
mRedraw = true;
}
-void Slider::mouseExited(gcn::MouseEvent& event A_UNUSED)
+void Slider::mouseExited(MouseEvent& event A_UNUSED)
{
mHasMouse = false;
mRedraw = true;
}
-void Slider::mousePressed(gcn::MouseEvent &mouseEvent)
+void Slider::mousePressed(MouseEvent &mouseEvent)
{
- if (mouseEvent.getButton() == gcn::MouseEvent::LEFT
+ if (mouseEvent.getButton() == MouseEvent::LEFT
&& mouseEvent.getX() >= 0
&& mouseEvent.getX() <= getWidth()
&& mouseEvent.getY() >= 0
@@ -296,7 +310,7 @@ void Slider::mousePressed(gcn::MouseEvent &mouseEvent)
}
}
-void Slider::mouseDragged(gcn::MouseEvent &mouseEvent)
+void Slider::mouseDragged(MouseEvent &mouseEvent)
{
if (getOrientation() == HORIZONTAL)
{
@@ -314,7 +328,7 @@ void Slider::mouseDragged(gcn::MouseEvent &mouseEvent)
mouseEvent.consume();
}
-void Slider::mouseWheelMovedUp(gcn::MouseEvent &mouseEvent)
+void Slider::mouseWheelMovedUp(MouseEvent &mouseEvent)
{
setValue2(getValue() + getStepLength());
distributeActionEvent();
@@ -322,7 +336,7 @@ void Slider::mouseWheelMovedUp(gcn::MouseEvent &mouseEvent)
mouseEvent.consume();
}
-void Slider::mouseWheelMovedDown(gcn::MouseEvent &mouseEvent)
+void Slider::mouseWheelMovedDown(MouseEvent &mouseEvent)
{
setValue2(getValue() - getStepLength());
distributeActionEvent();
@@ -330,9 +344,9 @@ void Slider::mouseWheelMovedDown(gcn::MouseEvent &mouseEvent)
mouseEvent.consume();
}
-void Slider::keyPressed(gcn::KeyEvent& keyEvent)
+void Slider::keyPressed(KeyEvent& keyEvent)
{
- const int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int action = keyEvent.getActionId();
if (getOrientation() == HORIZONTAL)
{
diff --git a/src/gui/widgets/slider.h b/src/gui/widgets/slider.h
index a0f7829ac..2f21127d1 100644
--- a/src/gui/widgets/slider.h
+++ b/src/gui/widgets/slider.h
@@ -23,9 +23,7 @@
#ifndef GUI_WIDGETS_SLIDER_H
#define GUI_WIDGETS_SLIDER_H
-#include "gui/widgets/widget2.h"
-
-#include <guichan/widgets/slider.hpp>
+#include "gui/base/widgets/slider.hpp"
#include "localconsts.h"
@@ -36,19 +34,21 @@ class ImageCollection;
*
* \ingroup GUI
*/
-class Slider final : public gcn::Slider,
- public Widget2
+class Slider final : public gcn::Slider
{
public:
/**
* Constructor with scale start equal to 0.
*/
- explicit Slider(const double scaleEnd = 1.0);
+ explicit Slider(Widget2 *const widget,
+ const double scaleEnd = 1.0);
/**
* Constructor.
*/
- Slider(const double scaleStart, const double scaleEnd);
+ Slider(Widget2 *const widget,
+ const double scaleStart,
+ const double scaleEnd);
A_DELETE_COPY(Slider)
@@ -65,27 +65,27 @@ class Slider final : public gcn::Slider,
/**
* Draws the slider.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
/**
* Called when the mouse enteres the widget area.
*/
- void mouseEntered(gcn::MouseEvent& event) override final;
+ void mouseEntered(MouseEvent& event) override final;
/**
* Called when the mouse leaves the widget area.
*/
- void mouseExited(gcn::MouseEvent& event) override final;
+ void mouseExited(MouseEvent& event) override final;
- void mousePressed(gcn::MouseEvent &mouseEvent) override final;
+ void mousePressed(MouseEvent &mouseEvent) override final;
- void mouseDragged(gcn::MouseEvent &mouseEvent) override final;
+ void mouseDragged(MouseEvent &mouseEvent) override final;
- void mouseWheelMovedUp(gcn::MouseEvent &mouseEvent) override final;
+ void mouseWheelMovedUp(MouseEvent &mouseEvent) override final;
- void mouseWheelMovedDown(gcn::MouseEvent &mouseEvent) override final;
+ void mouseWheelMovedDown(MouseEvent &mouseEvent) override final;
- void keyPressed(gcn::KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& keyEvent) override final;
void setValue2(const double value);
diff --git a/src/gui/widgets/sliderlist.cpp b/src/gui/widgets/sliderlist.cpp
index 60d7926d1..03f0c4ed2 100644
--- a/src/gui/widgets/sliderlist.cpp
+++ b/src/gui/widgets/sliderlist.cpp
@@ -20,13 +20,14 @@
#include "gui/widgets/sliderlist.h"
+#include "gui/font.h"
#include "gui/gui.h"
+#include "gui/models/listmodel.h"
+
#include "gui/widgets/button.h"
#include "gui/widgets/label.h"
-#include <guichan/font.hpp>
-
#include "debug.h"
static const int buttonWidth = 27;
@@ -34,10 +35,10 @@ static const int buttonSpace = 30;
static const int sliderHeight = 30;
SliderList::SliderList(const Widget2 *const widget,
- gcn::ListModel *const listModel) :
+ ListModel *const listModel) :
Container(widget),
- gcn::ActionListener(),
- gcn::MouseListener(),
+ ActionListener(),
+ MouseListener(),
mLabel(new Label(this)),
mListModel(listModel),
mPrevEventId(),
@@ -48,7 +49,7 @@ SliderList::SliderList(const Widget2 *const widget,
setHeight(sliderHeight);
}
-void SliderList::postInit(gcn::ActionListener *const listener,
+void SliderList::postInit(ActionListener *const listener,
const std::string &eventId)
{
mPrevEventId = eventId + "_prev";
@@ -80,13 +81,13 @@ void SliderList::updateAlpha()
Button::updateAlpha();
}
-void SliderList::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent)
+void SliderList::mouseWheelMovedUp(MouseEvent& mouseEvent)
{
setSelected(mSelectedIndex - 1);
mouseEvent.consume();
}
-void SliderList::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent)
+void SliderList::mouseWheelMovedDown(MouseEvent& mouseEvent)
{
setSelected(mSelectedIndex + 1);
mouseEvent.consume();
@@ -103,7 +104,7 @@ void SliderList::resize()
updateLabel();
}
-void SliderList::draw(gcn::Graphics *graphics)
+void SliderList::draw(Graphics *graphics)
{
BLOCK_START("SliderList::draw")
const int width = mDimension.width;
@@ -138,7 +139,7 @@ void SliderList::updateLabel()
mLabel->setPosition(buttonSpace + (space - labelWidth) / 2, labelY);
}
-void SliderList::action(const gcn::ActionEvent &event)
+void SliderList::action(const ActionEvent &event)
{
if (!mListModel)
return;
@@ -209,7 +210,7 @@ int SliderList::getMaxLabelWidth() const
return 1;
int maxWidth = 0;
- const gcn::Font *const font = getFont();
+ const Font *const font = getFont();
const int num = mListModel->getNumberOfElements();
for (int f = 0; f < num; f ++)
diff --git a/src/gui/widgets/sliderlist.h b/src/gui/widgets/sliderlist.h
index 73f8c6f5c..84f96ebe4 100644
--- a/src/gui/widgets/sliderlist.h
+++ b/src/gui/widgets/sliderlist.h
@@ -21,9 +21,8 @@
#ifndef GUI_WIDGETS_SLIDERLIST_H
#define GUI_WIDGETS_SLIDERLIST_H
-#include <guichan/actionlistener.hpp>
-#include <guichan/listmodel.hpp>
-#include <guichan/mouselistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/mouselistener.h"
#include "gui/widgets/container.h"
@@ -31,33 +30,34 @@
class Button;
class Label;
+class ListModel;
class SliderList final : public Container,
- public gcn::ActionListener,
- public gcn::MouseListener
+ public ActionListener,
+ public MouseListener
{
public:
SliderList(const Widget2 *const widget,
- gcn::ListModel *const listModel);
+ ListModel *const listModel);
A_DELETE_COPY(SliderList)
~SliderList();
- void postInit(gcn::ActionListener *const listener,
+ void postInit(ActionListener *const listener,
const std::string &eventId);
void updateAlpha();
- void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedUp(MouseEvent& mouseEvent) override final;
- void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent) override final;
+ void mouseWheelMovedDown(MouseEvent& mouseEvent) override final;
void resize();
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void setSelectedString(const std::string &str);
@@ -77,7 +77,7 @@ class SliderList final : public Container,
Button *mButtons[2];
Label *mLabel;
- gcn::ListModel *mListModel;
+ ListModel *mListModel;
std::string mPrevEventId;
std::string mNextEventId;
int mOldWidth;
diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp
index bf14f21fe..ed92b62e1 100644
--- a/src/gui/widgets/spellshortcutcontainer.cpp
+++ b/src/gui/widgets/spellshortcutcontainer.cpp
@@ -27,21 +27,20 @@
#include "itemshortcut.h"
#include "spellshortcut.h"
+#include "gui/font.h"
#include "gui/viewport.h"
#include "gui/popups/spellpopup.h"
-#include "gui/windows/inventorywindow.h"
#include "gui/windows/shortcutwindow.h"
#include "resources/image.h"
-#include <guichan/font.hpp>
-
#include "debug.h"
-SpellShortcutContainer::SpellShortcutContainer(const unsigned number) :
- ShortcutContainer(),
+SpellShortcutContainer::SpellShortcutContainer(Widget2 *const widget,
+ const unsigned number) :
+ ShortcutContainer(widget),
mSpellPopup(new SpellPopup),
mNumber(number),
mSpellClicked(false)
@@ -90,7 +89,7 @@ void SpellShortcutContainer::setWidget2(const Widget2 *const widget)
mForegroundColor2 = getThemeColor(Theme::TEXT_OUTLINE);
}
-void SpellShortcutContainer::draw(gcn::Graphics *graphics)
+void SpellShortcutContainer::draw(Graphics *graphics)
{
if (!spellShortcut)
return;
@@ -103,12 +102,11 @@ void SpellShortcutContainer::draw(gcn::Graphics *graphics)
mBackgroundImg->setAlpha(mAlpha);
}
- Graphics *const g = static_cast<Graphics *const>(graphics);
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
const int selectedId = spellShortcut->getSelectedItem();
- g->setColorAll(mForegroundColor, mForegroundColor2);
- drawBackground(g);
+ graphics->setColorAll(mForegroundColor, mForegroundColor2);
+ drawBackground(graphics);
for (unsigned i = 0; i < mMaxItems; i++)
{
@@ -118,7 +116,7 @@ void SpellShortcutContainer::draw(gcn::Graphics *graphics)
const int itemId = getItemByIndex(i);
if (selectedId >= 0 && itemId == selectedId)
{
- g->drawRectangle(gcn::Rectangle(itemX + 1, itemY + 1,
+ graphics->drawRectangle(Rect(itemX + 1, itemY + 1,
mBoxWidth - 1, mBoxHeight - 1));
}
@@ -135,11 +133,11 @@ void SpellShortcutContainer::draw(gcn::Graphics *graphics)
if (image)
{
image->setAlpha(1.0F);
- g->drawImage2(image, itemX, itemY);
+ graphics->drawImage(image, itemX, itemY);
}
}
- font->drawString(g, spell->getSymbol(),
+ font->drawString(graphics, spell->getSymbol(),
itemX + 2, itemY + mBoxHeight / 2);
}
}
@@ -147,9 +145,9 @@ void SpellShortcutContainer::draw(gcn::Graphics *graphics)
BLOCK_END("SpellShortcutContainer::draw")
}
-void SpellShortcutContainer::mouseDragged(gcn::MouseEvent &event)
+void SpellShortcutContainer::mouseDragged(MouseEvent &event)
{
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
if (dragDrop.isEmpty() && mSpellClicked)
{
@@ -178,7 +176,7 @@ void SpellShortcutContainer::mouseDragged(gcn::MouseEvent &event)
}
}
-void SpellShortcutContainer::mousePressed(gcn::MouseEvent &event)
+void SpellShortcutContainer::mousePressed(MouseEvent &event)
{
const int index = getIndexFromGrid(event.getX(), event.getY());
@@ -186,16 +184,16 @@ void SpellShortcutContainer::mousePressed(gcn::MouseEvent &event)
return;
const unsigned int eventButton = event.getButton();
- if (eventButton == gcn::MouseEvent::LEFT)
+ if (eventButton == MouseEvent::LEFT)
{
const int itemId = getItemByIndex(index);
if (itemId > 0)
mSpellClicked = true;
}
- else if (eventButton == gcn::MouseEvent::RIGHT)
+ else if (eventButton == MouseEvent::RIGHT)
{
}
- else if (eventButton == gcn::MouseEvent::MIDDLE)
+ else if (eventButton == MouseEvent::MIDDLE)
{
if (!spellShortcut || !spellManager)
return;
@@ -205,7 +203,7 @@ void SpellShortcutContainer::mousePressed(gcn::MouseEvent &event)
}
}
-void SpellShortcutContainer::mouseReleased(gcn::MouseEvent &event)
+void SpellShortcutContainer::mouseReleased(MouseEvent &event)
{
if (!spellShortcut || !spellManager)
return;
@@ -221,7 +219,7 @@ void SpellShortcutContainer::mouseReleased(gcn::MouseEvent &event)
const int itemId = getItemByIndex(index);
const unsigned int eventButton = event.getButton();
- if (eventButton == gcn::MouseEvent::LEFT)
+ if (eventButton == MouseEvent::LEFT)
{
mSpellClicked = false;
@@ -273,7 +271,7 @@ void SpellShortcutContainer::mouseReleased(gcn::MouseEvent &event)
}
}
}
- else if (eventButton == gcn::MouseEvent::RIGHT)
+ else if (eventButton == MouseEvent::RIGHT)
{
TextCommand *spell = nullptr;
if (itemId >= 0)
@@ -285,7 +283,7 @@ void SpellShortcutContainer::mouseReleased(gcn::MouseEvent &event)
}
// Show ItemTooltip
-void SpellShortcutContainer::mouseMoved(gcn::MouseEvent &event)
+void SpellShortcutContainer::mouseMoved(MouseEvent &event)
{
if (!mSpellPopup || !spellShortcut || !spellManager)
return;
@@ -309,13 +307,13 @@ void SpellShortcutContainer::mouseMoved(gcn::MouseEvent &event)
}
}
-void SpellShortcutContainer::mouseExited(gcn::MouseEvent &event A_UNUSED)
+void SpellShortcutContainer::mouseExited(MouseEvent &event A_UNUSED)
{
if (mSpellPopup)
mSpellPopup->setVisible(false);
}
-void SpellShortcutContainer::widgetHidden(const gcn::Event &event A_UNUSED)
+void SpellShortcutContainer::widgetHidden(const Event &event A_UNUSED)
{
if (mSpellPopup)
mSpellPopup->setVisible(false);
diff --git a/src/gui/widgets/spellshortcutcontainer.h b/src/gui/widgets/spellshortcutcontainer.h
index 37e7b5660..afff6dcf9 100644
--- a/src/gui/widgets/spellshortcutcontainer.h
+++ b/src/gui/widgets/spellshortcutcontainer.h
@@ -38,7 +38,8 @@ class SpellShortcutContainer final : public ShortcutContainer
/**
* Constructor. Initializes the graphic.
*/
- explicit SpellShortcutContainer(const unsigned number);
+ explicit SpellShortcutContainer(Widget2 *const widget,
+ const unsigned number);
A_DELETE_COPY(SpellShortcutContainer)
@@ -50,28 +51,28 @@ class SpellShortcutContainer final : public ShortcutContainer
/**
* Draws the items.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
/**
* Handles mouse when dragged.
*/
- void mouseDragged(gcn::MouseEvent &event) override final;
+ void mouseDragged(MouseEvent &event) override final;
/**
* Handles mouse when pressed.
*/
- void mousePressed(gcn::MouseEvent &event) override final;
+ void mousePressed(MouseEvent &event) override final;
/**
* Handles mouse release.
*/
- void mouseReleased(gcn::MouseEvent &event) override final;
+ void mouseReleased(MouseEvent &event) override final;
- void widgetHidden(const gcn::Event &event) override final;
+ void widgetHidden(const Event &event) override final;
- void mouseExited(gcn::MouseEvent &event) override final;
+ void mouseExited(MouseEvent &event) override final;
- void mouseMoved(gcn::MouseEvent &event) override final;
+ void mouseMoved(MouseEvent &event) override final;
void setWidget2(const Widget2 *const widget) override final;
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index 3b0cf1db5..d2bb24720 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -20,29 +20,74 @@
* 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 "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
+
+#include "gui/gui.h"
#include "gui/widgets/button.h"
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/tabs/tab.h"
-#include <guichan/widgets/container.hpp>
+#include "gui/base/widgets/container.hpp"
#include "debug.h"
TabbedArea::TabbedArea(const Widget2 *const widget) :
- Widget2(widget),
- gcn::ActionListener(),
- gcn::BasicContainer(),
- gcn::KeyListener(),
- gcn::MouseListener(),
- gcn::WidgetListener(),
+ ActionListener(),
+ gcn::BasicContainer(widget),
+ KeyListener(),
+ MouseListener(),
+ WidgetListener(),
mSelectedTab(nullptr),
- mTabContainer(new gcn::Container()),
- mWidgetContainer(new gcn::Container()),
+ mTabContainer(new gcn::Container(widget)),
+ mWidgetContainer(new gcn::Container(widget)),
mTabsToDelete(),
mTabs(),
mTabsWidth(0),
@@ -72,7 +117,7 @@ TabbedArea::TabbedArea(const Widget2 *const widget) :
void TabbedArea::postInit()
{
- widgetResized(gcn::Event(nullptr));
+ widgetResized(Event(nullptr));
}
TabbedArea::~TabbedArea()
@@ -139,7 +184,7 @@ Tab *TabbedArea::getTab(const std::string &name) const
return nullptr;
}
-void TabbedArea::draw(gcn::Graphics *graphics)
+void TabbedArea::draw(Graphics *graphics)
{
BLOCK_START("TabbedArea::draw")
if (mTabs.empty())
@@ -152,7 +197,7 @@ void TabbedArea::draw(gcn::Graphics *graphics)
BLOCK_END("TabbedArea::draw")
}
-gcn::Widget *TabbedArea::getWidget(const std::string &name) const
+Widget *TabbedArea::getWidget(const std::string &name) const
{
TabContainer::const_iterator itr = mTabs.begin();
const TabContainer::const_iterator itr_end = mTabs.end();
@@ -167,7 +212,7 @@ gcn::Widget *TabbedArea::getWidget(const std::string &name) const
return nullptr;
}
-gcn::Widget *TabbedArea::getCurrentWidget() const
+Widget *TabbedArea::getCurrentWidget() const
{
const Tab *const tab = getSelectedTab();
@@ -178,7 +223,7 @@ gcn::Widget *TabbedArea::getCurrentWidget() const
}
void TabbedArea::addTab(Tab *const tab,
- gcn::Widget *const widget)
+ Widget *const widget)
{
if (!tab || !widget)
return;
@@ -187,7 +232,7 @@ void TabbedArea::addTab(Tab *const tab,
tab->addActionListener(this);
mTabContainer->add(tab);
- mTabs.push_back(std::pair<Tab*, gcn::Widget*>(tab, widget));
+ mTabs.push_back(std::pair<Tab*, Widget*>(tab, widget));
if (!mSelectedTab)
setSelectedTab(tab);
@@ -203,14 +248,14 @@ void TabbedArea::addTab(Tab *const tab,
updateArrowEnableState();
}
-void TabbedArea::adjustWidget(gcn::Widget *const widget) const
+void TabbedArea::adjustWidget(Widget *const widget) const
{
const int frameSize = 2 * mFrameSize;
widget->setSize(getWidth() - frameSize,
getHeight() - frameSize - mTabContainer->getHeight());
}
-void TabbedArea::addTab(const std::string &caption, gcn::Widget *const widget)
+void TabbedArea::addTab(const std::string &caption, Widget *const widget)
{
Tab *const tab = new Tab(this);
tab->setCaption(caption);
@@ -219,7 +264,7 @@ void TabbedArea::addTab(const std::string &caption, gcn::Widget *const widget)
addTab(tab, widget);
}
-void TabbedArea::addTab(Image *const image, gcn::Widget *const widget)
+void TabbedArea::addTab(Image *const image, Widget *const widget)
{
Tab *const tab = new Tab(this);
tab->setImage(image);
@@ -323,14 +368,14 @@ void TabbedArea::logic()
BLOCK_END("TabbedArea::logic")
}
-void TabbedArea::mousePressed(gcn::MouseEvent &mouseEvent)
+void TabbedArea::mousePressed(MouseEvent &mouseEvent)
{
if (mouseEvent.isConsumed())
return;
- if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
+ if (mouseEvent.getButton() == MouseEvent::LEFT)
{
- gcn::Widget *const widget = mTabContainer->getWidgetAt(
+ Widget *const widget = mTabContainer->getWidgetAt(
mouseEvent.getX(), mouseEvent.getY());
Tab *const tab = dynamic_cast<Tab *const>(widget);
@@ -365,7 +410,7 @@ void TabbedArea::setSelectedTab(Tab *const tab)
if (newTab)
newTab->setCurrent();
- widgetResized(gcn::Event(nullptr));
+ widgetResized(Event(nullptr));
}
int TabbedArea::getSelectedTabIndex() const
@@ -392,7 +437,7 @@ void TabbedArea::setSelectedTabByName(const std::string &name)
}
}
-void TabbedArea::widgetResized(const gcn::Event &event A_UNUSED)
+void TabbedArea::widgetResized(const Event &event A_UNUSED)
{
adjustSize();
@@ -404,7 +449,7 @@ void TabbedArea::widgetResized(const gcn::Event &event A_UNUSED)
const int height = h1 - frameSize
- mWidgetContainer->getY() - widgetFrameSize;
- gcn::Widget *const w = getCurrentWidget();
+ Widget *const w = getCurrentWidget();
if (w)
{
ScrollArea *const scr = dynamic_cast<ScrollArea *const>(w);
@@ -412,7 +457,7 @@ void TabbedArea::widgetResized(const gcn::Event &event A_UNUSED)
{
if (mFollowDownScroll && height != 0)
{
- const gcn::Rectangle &rect = w->getDimension();
+ const Rect &rect = w->getDimension();
if (rect.height != 0 && rect.height > height + 2)
{
if (scr->getVerticalScrollAmount()
@@ -500,7 +545,7 @@ void TabbedArea::adjustSize()
mWidgetContainer->setPosition(0, maxTabHeight);
mWidgetContainer->setSize(width, height - maxTabHeight);
- gcn::Widget *const w = getCurrentWidget();
+ Widget *const w = getCurrentWidget();
if (w)
{
const int wFrameSize = w->getFrameSize();
@@ -558,9 +603,9 @@ void TabbedArea::adjustTabPositions()
}
}
-void TabbedArea::action(const gcn::ActionEvent& actionEvent)
+void TabbedArea::action(const ActionEvent& actionEvent)
{
- gcn::Widget *const source = actionEvent.getSource();
+ Widget *const source = actionEvent.getSource();
Tab *const tab = dynamic_cast<Tab *const>(source);
if (tab)
@@ -632,7 +677,7 @@ Tab *TabbedArea::getTabByIndex(const int index) const
return static_cast<Tab*>(mTabs[index].first);
}
-gcn::Widget *TabbedArea::getWidgetByIndex(const int index) const
+Widget *TabbedArea::getWidgetByIndex(const int index) const
{
if (index < 0 || index >= static_cast<int>(mTabs.size()))
return nullptr;
@@ -649,7 +694,7 @@ void TabbedArea::removeAll(const bool del)
{
const int idx = getNumberOfTabs() - 1;
Tab *tab = mTabs[idx].first;
- gcn::Widget *widget = mTabs[idx].second;
+ Widget *widget = mTabs[idx].second;
removeTab(tab);
if (del)
{
@@ -661,34 +706,34 @@ void TabbedArea::removeAll(const bool del)
void TabbedArea::setWidth(int width)
{
- gcn::Widget::setWidth(width);
+ Widget::setWidth(width);
adjustSize();
}
void TabbedArea::setHeight(int height)
{
- gcn::Widget::setHeight(height);
+ Widget::setHeight(height);
adjustSize();
}
void TabbedArea::setSize(int width, int height)
{
- gcn::Widget::setSize(width, height);
+ Widget::setSize(width, height);
adjustSize();
}
-void TabbedArea::setDimension(const gcn::Rectangle &dimension)
+void TabbedArea::setDimension(const Rect &dimension)
{
- gcn::Widget::setDimension(dimension);
+ Widget::setDimension(dimension);
adjustSize();
}
-void TabbedArea::keyPressed(gcn::KeyEvent& keyEvent)
+void TabbedArea::keyPressed(KeyEvent& keyEvent)
{
if (mBlockSwitching || keyEvent.isConsumed() || !isFocused())
return;
- const int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int actionId = keyEvent.getActionId();
if (actionId == Input::KEY_GUI_LEFT)
{
@@ -716,7 +761,7 @@ void TabbedArea::keyPressed(gcn::KeyEvent& keyEvent)
}
}
-void TabbedArea::death(const gcn::Event &event)
+void TabbedArea::death(const Event &event)
{
Tab *const tab = dynamic_cast<Tab*>(event.getSource());
diff --git a/src/gui/widgets/tabbedarea.h b/src/gui/widgets/tabbedarea.h
index d0f97b688..dbaa4334b 100644
--- a/src/gui/widgets/tabbedarea.h
+++ b/src/gui/widgets/tabbedarea.h
@@ -20,16 +20,59 @@
* 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 "gui/widgets/widget2.h"
+#include "listeners/keylistener.h"
+#include "listeners/mouselistener.h"
+#include "listeners/widgetlistener.h"
+
+#include "gui/base/widgets/container.hpp"
-#include <guichan/actionlistener.hpp>
-#include <guichan/keylistener.hpp>
-#include <guichan/mouselistener.hpp>
-#include <guichan/widgetlistener.hpp>
-#include <guichan/widgets/container.hpp>
+#include "listeners/actionlistener.h"
class Button;
class Image;
@@ -38,12 +81,11 @@ class Tab;
/**
* A tabbed area, the same as the guichan tabbed area in 0.8, but extended
*/
-class TabbedArea final : public Widget2,
- public gcn::ActionListener,
+class TabbedArea final : public ActionListener,
public gcn::BasicContainer,
- public gcn::KeyListener,
- public gcn::MouseListener,
- public gcn::WidgetListener
+ public KeyListener,
+ public MouseListener,
+ public WidgetListener
{
public:
/**
@@ -60,7 +102,7 @@ class TabbedArea final : public Widget2,
/**
* Draw the tabbed area.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
/**
* Return how many tabs have been created.
@@ -76,17 +118,17 @@ class TabbedArea final : public Widget2,
Tab *getTabByIndex(const int index) const A_WARN_UNUSED;
- gcn::Widget *getWidgetByIndex(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
*/
- gcn::Widget *getWidget(const std::string &name) const A_WARN_UNUSED;
+ Widget *getWidget(const std::string &name) const A_WARN_UNUSED;
/**
* Returns the widget for the current tab
*/
- gcn::Widget *getCurrentWidget() const A_WARN_UNUSED;
+ Widget *getCurrentWidget() const A_WARN_UNUSED;
/**
* Add a tab. Overridden since it needs to size the widget.
@@ -94,11 +136,11 @@ class TabbedArea final : public Widget2,
* @param tab The tab widget for the tab.
* @param widget The widget to view when the tab is selected.
*/
- void addTab(Tab *const tab, gcn::Widget *const widget);
+ void addTab(Tab *const tab, Widget *const widget);
- void addTab(const std::string &caption, gcn::Widget *const widget);
+ void addTab(const std::string &caption, Widget *const widget);
- void addTab(Image *const image, gcn::Widget *const widget);
+ void addTab(Image *const image, Widget *const widget);
bool isTabSelected(const unsigned int index) const A_WARN_UNUSED;
@@ -140,7 +182,7 @@ class TabbedArea final : public Widget2,
void setSelectedTabByName(const std::string &name);
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
/*
void moveLeft(Tab *tab);
@@ -149,11 +191,11 @@ class TabbedArea final : public Widget2,
*/
void adjustTabPositions();
- void action(const gcn::ActionEvent& actionEvent) override final;
+ void action(const ActionEvent& actionEvent) override final;
// Inherited from MouseListener
- void mousePressed(gcn::MouseEvent &mouseEvent) override final;
+ void mousePressed(MouseEvent &mouseEvent) override final;
void enableScrollButtons(const bool enable);
@@ -169,7 +211,7 @@ class TabbedArea final : public Widget2,
bool getFollowDownScroll() const A_WARN_UNUSED
{ return mFollowDownScroll; }
- void keyPressed(gcn::KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& keyEvent) override final;
void setBlockSwitching(const bool b)
{ mBlockSwitching = b; }
@@ -180,21 +222,21 @@ class TabbedArea final : public Widget2,
void setSize(int width, int height);
- void setDimension(const gcn::Rectangle &dimension);
+ void setDimension(const Rect &dimension);
- void death(const gcn::Event &event);
+ void death(const Event &event);
void setResizeHeight(bool b)
{ mResizeHeight = b; }
- void adjustWidget(gcn::Widget *const widget) const;
+ void adjustWidget(Widget *const widget) const;
void selectNextTab();
void selectPrevTab();
private:
- typedef std::vector <std::pair<Tab*, gcn::Widget*> > TabContainer;
+ typedef std::vector <std::pair<Tab*, Widget*> > TabContainer;
/** The tab arrows */
Button *mArrowButton[2];
diff --git a/src/gui/widgets/tabs/chattab.cpp b/src/gui/widgets/tabs/chattab.cpp
index 331101209..fe979ae5a 100644
--- a/src/gui/widgets/tabs/chattab.cpp
+++ b/src/gui/widgets/tabs/chattab.cpp
@@ -24,6 +24,7 @@
#include "chatlogger.h"
#include "client.h"
+#include "commands.h"
#include "commandhandler.h"
#include "configuration.h"
#include "soundconsts.h"
@@ -50,12 +51,13 @@
static const unsigned int MAX_WORD_SIZE = 50;
-ChatTab::ChatTab(const Widget2 *const widget, const std::string &name,
+ChatTab::ChatTab(const Widget2 *const widget,
+ const std::string &name,
const std::string &channel) :
Tab(widget),
mTextOutput(new BrowserBox(this, BrowserBox::AUTO_WRAP, true,
"browserbox.xml")),
- mScrollArea(new ScrollArea(mTextOutput, false)),
+ mScrollArea(new ScrollArea(this, mTextOutput, false)),
mChannelName(channel),
mAllowHightlight(true),
mRemoveNames(false),
@@ -405,7 +407,7 @@ void ChatTab::chatInput(const std::string &message)
void ChatTab::scroll(const int amount)
{
const int range = mScrollArea->getHeight() / 8 * amount;
- gcn::Rectangle scr;
+ Rect scr;
scr.y = mScrollArea->getVerticalScrollAmount() + range;
scr.height = abs(range);
mTextOutput->showPart(scr);
diff --git a/src/gui/widgets/tabs/chattab.h b/src/gui/widgets/tabs/chattab.h
index 651e69d6b..a46279483 100644
--- a/src/gui/widgets/tabs/chattab.h
+++ b/src/gui/widgets/tabs/chattab.h
@@ -58,7 +58,8 @@ class ChatTab : public Tab
/**
* Constructor.
*/
- ChatTab(const Widget2 *const widget, const std::string &name,
+ ChatTab(const Widget2 *const widget,
+ const std::string &name,
const std::string &channel);
A_DELETE_COPY(ChatTab)
diff --git a/src/gui/widgets/tabs/guildchattab.h b/src/gui/widgets/tabs/guildchattab.h
index fbfd3a032..cfcf901ca 100644
--- a/src/gui/widgets/tabs/guildchattab.h
+++ b/src/gui/widgets/tabs/guildchattab.h
@@ -28,7 +28,8 @@
/**
* A tab for a guild chat channel.
*/
-class GuildChatTab final : public ChatTab, public ConfigListener
+class GuildChatTab final : public ChatTab,
+ public ConfigListener
{
public:
explicit GuildChatTab(const Widget2 *const widget);
diff --git a/src/gui/widgets/tabs/langtab.cpp b/src/gui/widgets/tabs/langtab.cpp
index fb6a5e12b..f5064be8c 100644
--- a/src/gui/widgets/tabs/langtab.cpp
+++ b/src/gui/widgets/tabs/langtab.cpp
@@ -26,7 +26,8 @@
#include "debug.h"
-LangTab::LangTab(const Widget2 *const widget, const std::string &lang) :
+LangTab::LangTab(const Widget2 *const widget,
+ const std::string &lang) :
// TRANSLATORS: lang chat tab name
ChatTab(widget, _("Lang"), lang + " ")
{
diff --git a/src/gui/widgets/tabs/langtab.h b/src/gui/widgets/tabs/langtab.h
index 275b69399..e036e4dd8 100644
--- a/src/gui/widgets/tabs/langtab.h
+++ b/src/gui/widgets/tabs/langtab.h
@@ -26,7 +26,8 @@
class LangTab final : public ChatTab
{
public:
- LangTab(const Widget2 *const widget, const std::string &lang);
+ LangTab(const Widget2 *const widget,
+ const std::string &lang);
A_DELETE_COPY(LangTab)
diff --git a/src/gui/widgets/tabs/setup_audio.cpp b/src/gui/widgets/tabs/setup_audio.cpp
index 1bb119ee4..6cf675635 100644
--- a/src/gui/widgets/tabs/setup_audio.cpp
+++ b/src/gui/widgets/tabs/setup_audio.cpp
@@ -30,28 +30,15 @@
#include "gui/viewport.h"
+#include "gui/models/soundsmodel.h"
+
#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/namesmodel.h"
#include "gui/widgets/scrollarea.h"
#include "utils/gettext.h"
#include "debug.h"
-class SoundsModel final : public NamesModel
-{
-public:
- SoundsModel() :
- NamesModel()
- {
- mNames.push_back(gettext("(no sound)"));
- Theme::fillSoundsList(mNames);
- }
-
- ~SoundsModel()
- { }
-};
-
Setup_Audio::Setup_Audio(const Widget2 *const widget) :
SetupTabScroll(widget),
mSoundModel(new SoundsModel),
@@ -168,7 +155,7 @@ Setup_Audio::Setup_Audio(const Widget2 *const widget) :
new SetupItemCheckBox(_("Download music"), "",
"download-music", this, "download-musicEvent");
- setDimension(gcn::Rectangle(0, 0, 550, 350));
+ setDimension(Rect(0, 0, 550, 350));
}
Setup_Audio::~Setup_Audio()
diff --git a/src/gui/widgets/tabs/setup_audio.h b/src/gui/widgets/tabs/setup_audio.h
index 839734b39..b3736e814 100644
--- a/src/gui/widgets/tabs/setup_audio.h
+++ b/src/gui/widgets/tabs/setup_audio.h
@@ -25,6 +25,8 @@
#include "gui/widgets/setupitem.h"
+#include "gui/widgets/tabs/setuptabscroll.h"
+
class Setup_Audio final : public SetupTabScroll
{
public:
@@ -37,7 +39,7 @@ class Setup_Audio final : public SetupTabScroll
void apply() override final;
private:
- gcn::ListModel *mSoundModel;
+ ListModel *mSoundModel;
SetupItemNames *mChannelsList;
};
diff --git a/src/gui/widgets/tabs/setup_chat.cpp b/src/gui/widgets/tabs/setup_chat.cpp
index 3aa6d39d2..7ac88ab0a 100644
--- a/src/gui/widgets/tabs/setup_chat.cpp
+++ b/src/gui/widgets/tabs/setup_chat.cpp
@@ -195,7 +195,7 @@ Setup_Chat::Setup_Chat(const Widget2 *const widget) :
new SetupItemCheckBox(_("Show motd server message on start"), "",
"showmotd", this, "showmotdEvent");
- setDimension(gcn::Rectangle(0, 0, 550, 350));
+ setDimension(Rect(0, 0, 550, 350));
}
void Setup_Chat::apply()
diff --git a/src/gui/widgets/tabs/setup_colors.cpp b/src/gui/widgets/tabs/setup_colors.cpp
index 1094f5e29..ac6bf2837 100644
--- a/src/gui/widgets/tabs/setup_colors.cpp
+++ b/src/gui/widgets/tabs/setup_colors.cpp
@@ -21,7 +21,8 @@
#include "gui/widgets/tabs/setup_colors.h"
-#include "gui/sdlfont.h"
+#include "gui/font.h"
+#include "gui/gui.h"
#include "gui/userpalette.h"
#include "gui/widgets/browserbox.h"
@@ -47,34 +48,35 @@ const char *const Setup_Colors::rawmsg =
Setup_Colors::Setup_Colors(const Widget2 *const widget) :
SetupTab(widget),
- gcn::SelectionListener(),
+ SelectionListener(),
mColorBox(new ListBox(this, userPalette, "")),
- mScroll(new ScrollArea(mColorBox, true, "setup_colors_background.xml")),
+ mScroll(new ScrollArea(this, mColorBox,
+ true, "setup_colors_background.xml")),
mPreview(new BrowserBox(this, BrowserBox::AUTO_WRAP, true,
"browserbox.xml")),
mTextPreview(new TextPreview(this, gettext(rawmsg))),
- mPreviewBox(new ScrollArea(mPreview, true,
+ mPreviewBox(new ScrollArea(this, mPreview, true,
"setup_colors_preview_background.xml")),
mSelected(-1),
// TRANSLATORS: colors tab. label.
mGradTypeLabel(new Label(this, _("Type:"))),
- mGradTypeSlider(new Slider(0, 3)),
+ mGradTypeSlider(new Slider(this, 0, 3)),
mGradTypeText(new Label(this)),
// TRANSLATORS: colors tab. label.
mGradDelayLabel(new Label(this, _("Delay:"))),
- mGradDelaySlider(new Slider(20, 100)),
+ mGradDelaySlider(new Slider(this, 20, 100)),
mGradDelayText(new TextField(this)),
// TRANSLATORS: colors tab. label.
mRedLabel(new Label(this, _("Red:"))),
- mRedSlider(new Slider(0, 255)),
+ mRedSlider(new Slider(this, 0, 255)),
mRedText(new TextField(this)),
// TRANSLATORS: colors tab. label.
mGreenLabel(new Label(this, _("Green:"))),
- mGreenSlider(new Slider(0, 255)),
+ mGreenSlider(new Slider(this, 0, 255)),
mGreenText(new TextField(this)),
// TRANSLATORS: colors tab. label.
mBlueLabel(new Label(this, _("Blue:"))),
- mBlueSlider(new Slider(0, 255)),
+ mBlueSlider(new Slider(this, 0, 255)),
mBlueText(new TextField(this))
{
mColorBox->postInit();
@@ -101,7 +103,7 @@ Setup_Colors::Setup_Colors(const Widget2 *const widget) :
// TRANSLATORS: color type
std::string longText = _("Static");
- const gcn::Font *const font = getFont();
+ const Font *const font = getFont();
if (getFont()->getWidth(_("Pulse")) > font->getWidth(longText))
{
// TRANSLATORS: color type
@@ -190,7 +192,7 @@ Setup_Colors::Setup_Colors(const Widget2 *const widget) :
mGradTypeText->setCaption("");
- setDimension(gcn::Rectangle(0, 0, 365, 350));
+ setDimension(Rect(0, 0, 365, 350));
}
Setup_Colors::~Setup_Colors()
@@ -207,7 +209,7 @@ Setup_Colors::~Setup_Colors()
}
}
-void Setup_Colors::action(const gcn::ActionEvent &event)
+void Setup_Colors::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "slider_grad")
@@ -244,14 +246,14 @@ void Setup_Colors::action(const gcn::ActionEvent &event)
}
}
-void Setup_Colors::valueChanged(const gcn::SelectionEvent &event A_UNUSED)
+void Setup_Colors::valueChanged(const SelectionEvent &event A_UNUSED)
{
if (!userPalette)
return;
mSelected = mColorBox->getSelected();
const int type = userPalette->getColorTypeAt(mSelected);
- const gcn::Color *col = &userPalette->getColor(type);
+ const Color *col = &userPalette->getColor(type);
const Palette::GradientType grad = userPalette->getGradientType(type);
const int delay = userPalette->getGradientDelay(type);
@@ -381,7 +383,7 @@ void Setup_Colors::cancel()
userPalette->rollback();
const int type = userPalette->getColorTypeAt(mSelected);
- const gcn::Color *const col = &userPalette->getColor(type);
+ const Color *const col = &userPalette->getColor(type);
mGradTypeSlider->setValue2(userPalette->getGradientType(type));
const int delay = userPalette->getGradientDelay(type);
setEntry(mGradDelaySlider, mGradDelayText, delay);
@@ -442,7 +444,7 @@ void Setup_Colors::updateColor()
}
else if (grad == Palette::PULSE)
{
- userPalette->setTestColor(type, gcn::Color(
+ userPalette->setTestColor(type, Color(
static_cast<int>(mRedSlider->getValue()),
static_cast<int>(mGreenSlider->getValue()),
static_cast<int>(mBlueSlider->getValue())));
diff --git a/src/gui/widgets/tabs/setup_colors.h b/src/gui/widgets/tabs/setup_colors.h
index b2f860415..ce491706c 100644
--- a/src/gui/widgets/tabs/setup_colors.h
+++ b/src/gui/widgets/tabs/setup_colors.h
@@ -24,9 +24,7 @@
#include "gui/widgets/tabs/setuptab.h"
-#include <guichan/selectionlistener.hpp>
-
-#include <string>
+#include "listeners/selectionlistener.h"
class BrowserBox;
class Label;
@@ -37,7 +35,7 @@ class TextField;
class TextPreview;
class Setup_Colors final : public SetupTab,
- public gcn::SelectionListener
+ public SelectionListener
{
public:
explicit Setup_Colors(const Widget2 *const widget);
@@ -50,9 +48,9 @@ class Setup_Colors final : public SetupTab,
void cancel() override final;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
- void valueChanged(const gcn::SelectionEvent &event) override final;
+ void valueChanged(const SelectionEvent &event) override final;
private:
static const char *const rawmsg;
diff --git a/src/gui/widgets/tabs/setup_input.cpp b/src/gui/widgets/tabs/setup_input.cpp
index 9ce6fd616..b04937881 100644
--- a/src/gui/widgets/tabs/setup_input.cpp
+++ b/src/gui/widgets/tabs/setup_input.cpp
@@ -28,6 +28,7 @@
#include "input/inputmanager.h"
#include "input/keyboardconfig.h"
+#include "gui/gui.h"
#include "gui/setupactiondata.h"
#include "gui/windows/okdialog.h"
@@ -38,7 +39,7 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/tabstrip.h"
-#include <guichan/listmodel.hpp>
+#include "gui/models/listmodel.h"
#include "debug.h"
@@ -50,7 +51,7 @@ static const int setupGroups = 9;
*
* \ingroup Interface
*/
-class KeyListModel final : public gcn::ListModel
+class KeyListModel final : public ListModel
{
public:
KeyListModel() :
@@ -103,7 +104,8 @@ Setup_Input::Setup_Input(const Widget2 *const widget) :
// 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(mKeyList, true, "setup_input_background.xml")),
+ mScrollArea(new ScrollArea(this, mKeyList,
+ true, "setup_input_background.xml")),
mKeySetting(false),
mActionDataSize(new int [9])
{
@@ -125,7 +127,7 @@ Setup_Input::Setup_Input(const Widget2 *const widget) :
mKeyListModel->setSize(mActionDataSize[0]);
refreshKeys();
if (gui)
- mKeyList->setFont(reinterpret_cast<gcn::Font*>(gui->getHelpFont()));
+ mKeyList->setFont(gui->getHelpFont());
mKeyList->addActionListener(this);
mScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
@@ -162,7 +164,7 @@ Setup_Input::Setup_Input(const Widget2 *const widget) :
if (config.getIntValue("screenwidth") >= 730)
width += 100;
- setDimension(gcn::Rectangle(0, 0, width, 350));
+ setDimension(Rect(0, 0, width, 350));
}
Setup_Input::~Setup_Input()
@@ -213,7 +215,7 @@ void Setup_Input::cancel()
refreshKeys();
}
-void Setup_Input::action(const gcn::ActionEvent &event)
+void Setup_Input::action(const ActionEvent &event)
{
const std::string id = event.getId();
diff --git a/src/gui/widgets/tabs/setup_input.h b/src/gui/widgets/tabs/setup_input.h
index 135cb3339..43ec53b56 100644
--- a/src/gui/widgets/tabs/setup_input.h
+++ b/src/gui/widgets/tabs/setup_input.h
@@ -55,7 +55,7 @@ class Setup_Input final : public SetupTab
void cancel() override final;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Get an update on the assigned key.
diff --git a/src/gui/widgets/tabs/setup_joystick.cpp b/src/gui/widgets/tabs/setup_joystick.cpp
index 6f023a488..b3d7b78b9 100644
--- a/src/gui/widgets/tabs/setup_joystick.cpp
+++ b/src/gui/widgets/tabs/setup_joystick.cpp
@@ -26,12 +26,13 @@
#include "input/joystick.h"
+#include "gui/models/namesmodel.h"
+
#include "gui/widgets/button.h"
#include "gui/widgets/checkbox.h"
#include "gui/widgets/dropdown.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/namesmodel.h"
#include "utils/gettext.h"
@@ -93,7 +94,7 @@ Setup_Joystick::Setup_Joystick(const Widget2 *const widget) :
place(0, 4, mCalibrateLabel);
place(0, 5, mCalibrateButton);
- setDimension(gcn::Rectangle(0, 0, 365, 75));
+ setDimension(Rect(0, 0, 365, 75));
}
Setup_Joystick::~Setup_Joystick()
@@ -102,9 +103,9 @@ Setup_Joystick::~Setup_Joystick()
mNamesModel = nullptr;
}
-void Setup_Joystick::action(const gcn::ActionEvent &event)
+void Setup_Joystick::action(const ActionEvent &event)
{
- const gcn::Widget *const source = event.getSource();
+ const Widget *const source = event.getSource();
if (source == mJoystickEnabled)
{
setTempEnabled(mJoystickEnabled->isSelected());
diff --git a/src/gui/widgets/tabs/setup_joystick.h b/src/gui/widgets/tabs/setup_joystick.h
index 5c7b764ec..ac6caef24 100644
--- a/src/gui/widgets/tabs/setup_joystick.h
+++ b/src/gui/widgets/tabs/setup_joystick.h
@@ -44,7 +44,7 @@ class Setup_Joystick final : public SetupTab
void cancel() override final;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void setTempEnabled(const bool sel);
diff --git a/src/gui/widgets/tabs/setup_mods.cpp b/src/gui/widgets/tabs/setup_mods.cpp
index ada0ef686..b30b84c16 100644
--- a/src/gui/widgets/tabs/setup_mods.cpp
+++ b/src/gui/widgets/tabs/setup_mods.cpp
@@ -44,7 +44,7 @@ Setup_Mods::Setup_Mods(const Widget2 *const widget) :
ContainerPlacer place = h.getPlacer(0, 0);
place(0, 0, mScroll, 10, 10);
- setDimension(gcn::Rectangle(0, 0, 550, 350));
+ setDimension(Rect(0, 0, 550, 350));
}
Setup_Mods::~Setup_Mods()
diff --git a/src/gui/widgets/tabs/setup_other.cpp b/src/gui/widgets/tabs/setup_other.cpp
index 985baa744..e4801506c 100644
--- a/src/gui/widgets/tabs/setup_other.cpp
+++ b/src/gui/widgets/tabs/setup_other.cpp
@@ -22,8 +22,9 @@
#include "gui/widgets/tabs/setup_other.h"
+#include "gui/models/namesmodel.h"
+
#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/namesmodel.h"
#include "gui/widgets/setupitem.h"
#include "gui/widgets/scrollarea.h"
@@ -390,7 +391,7 @@ Setup_Other::Setup_Other(const Widget2 *const widget) :
new SetupItemDropDown(_("Screen density override"), "",
"screenDensity", this, "screenDensityEvent", mDensityList, 100);
- setDimension(gcn::Rectangle(0, 0, 550, 350));
+ setDimension(Rect(0, 0, 550, 350));
}
Setup_Other::~Setup_Other()
diff --git a/src/gui/widgets/tabs/setup_perfomance.cpp b/src/gui/widgets/tabs/setup_perfomance.cpp
index 271501e38..5a0566ec2 100644
--- a/src/gui/widgets/tabs/setup_perfomance.cpp
+++ b/src/gui/widgets/tabs/setup_perfomance.cpp
@@ -22,8 +22,9 @@
#include "gui/widgets/tabs/setup_perfomance.h"
+#include "gui/models/namesmodel.h"
+
#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/namesmodel.h"
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/setupitem.h"
@@ -153,7 +154,7 @@ Setup_Perfomance::Setup_Perfomance(const Widget2 *const widget) :
"", "uselonglivesounds", this,
"uselonglivesoundsEvent");
- setDimension(gcn::Rectangle(0, 0, 550, 350));
+ setDimension(Rect(0, 0, 550, 350));
}
Setup_Perfomance::~Setup_Perfomance()
diff --git a/src/gui/widgets/tabs/setup_players.cpp b/src/gui/widgets/tabs/setup_players.cpp
index d4f29fa2c..01bb60f53 100644
--- a/src/gui/widgets/tabs/setup_players.cpp
+++ b/src/gui/widgets/tabs/setup_players.cpp
@@ -100,5 +100,5 @@ Setup_Players::Setup_Players(const Widget2 *const widget) :
new SetupItemCheckBox(_("Use special diagonal speed in players moving"),
"", "useDiagonalSpeed", this, "useDiagonalSpeedEvent");
- setDimension(gcn::Rectangle(0, 0, 550, 350));
+ setDimension(Rect(0, 0, 550, 350));
}
diff --git a/src/gui/widgets/tabs/setup_relations.cpp b/src/gui/widgets/tabs/setup_relations.cpp
index 89d1f5beb..1458ecd25 100644
--- a/src/gui/widgets/tabs/setup_relations.cpp
+++ b/src/gui/widgets/tabs/setup_relations.cpp
@@ -26,6 +26,9 @@
#include "being/localplayer.h"
+#include "gui/models/ignorechoiceslistmodel.h"
+#include "gui/models/playerrelationlistmodel.h"
+
#include "gui/widgets/button.h"
#include "gui/widgets/checkbox.h"
#include "gui/widgets/dropdown.h"
@@ -60,43 +63,6 @@ static const char *const table_titles[COLUMNS_NR] =
N_("Relation")
};
-static const char *const RELATION_NAMES[PlayerRelation::RELATIONS_NR] =
-{
- // TRANSLATORS: relation type
- N_("Neutral"),
- // TRANSLATORS: relation type
- N_("Friend"),
- // TRANSLATORS: relation type
- N_("Disregarded"),
- // TRANSLATORS: relation type
- N_("Ignored"),
- // TRANSLATORS: relation type
- N_("Erased"),
- // TRANSLATORS: relation type
- N_("Blacklisted"),
- // TRANSLATORS: relation type
- N_("Enemy")
-};
-
-class PlayerRelationListModel final : public gcn::ListModel
-{
-public:
- ~PlayerRelationListModel()
- { }
-
- int getNumberOfElements() override final
- {
- return PlayerRelation::RELATIONS_NR;
- }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "";
- return gettext(RELATION_NAMES[i]);
- }
-};
-
class PlayerTableModel final : public Widget2, public TableModel
{
public:
@@ -165,7 +131,7 @@ public:
player_names->size()); r < sz; ++r)
{
const std::string name = (*player_names)[r];
- gcn::Widget *const widget = new Label(this, name);
+ Widget *const widget = new Label(this, name);
mWidgets.push_back(widget);
DropDown *const choicebox = new DropDown(this, mListModel);
@@ -186,7 +152,7 @@ public:
}
- gcn::Widget *getElementAt(int row, int column) const override final
+ Widget *getElementAt(int row, int column) const override final
{
return mWidgets[WIDGET_AT(row, column)];
}
@@ -209,35 +175,10 @@ public:
protected:
StringVect *mPlayers;
- std::vector<gcn::Widget *> mWidgets;
+ std::vector<Widget *> mWidgets;
PlayerRelationListModel *mListModel;
};
-/**
- * Class for choosing one of the various `what to do when ignoring a player' options
- */
-class IgnoreChoicesListModel final : public gcn::ListModel
-{
-public:
- ~IgnoreChoicesListModel()
- { }
-
- int getNumberOfElements() override final
- {
- return static_cast<int>(player_relations.getPlayerIgnoreStrategies()
- ->size());
- }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
-
- return (*player_relations.getPlayerIgnoreStrategies())
- [i]->mDescription;
- }
-};
-
static const std::string ACTION_DELETE("delete");
static const std::string ACTION_TABLE("table");
static const std::string ACTION_STRATEGY("strategy");
@@ -249,7 +190,7 @@ Setup_Relations::Setup_Relations(const Widget2 *const widget) :
mPlayerTableModel(new PlayerTableModel(this)),
mPlayerTable(new GuiTable(this, mPlayerTableModel)),
mPlayerTitleTable(new GuiTable(this, mPlayerTableTitleModel)),
- mPlayerScrollArea(new ScrollArea(mPlayerTable)),
+ mPlayerScrollArea(new ScrollArea(this, mPlayerTable)),
// TRANSLATORS: relation dialog button
mDefaultTrading(new CheckBox(this, _("Allow trading"),
player_relations.getDefault() & PlayerRelation::TRADE)),
@@ -319,7 +260,7 @@ Setup_Relations::Setup_Relations(const Widget2 *const widget) :
player_relations.addListener(this);
- setDimension(gcn::Rectangle(0, 0, 500, 350));
+ setDimension(Rect(0, 0, 500, 350));
}
Setup_Relations::~Setup_Relations()
@@ -370,7 +311,7 @@ void Setup_Relations::cancel()
{
}
-void Setup_Relations::action(const gcn::ActionEvent &event)
+void Setup_Relations::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == ACTION_TABLE)
diff --git a/src/gui/widgets/tabs/setup_relations.h b/src/gui/widgets/tabs/setup_relations.h
index c9d8e50a3..9fc197ffc 100644
--- a/src/gui/widgets/tabs/setup_relations.h
+++ b/src/gui/widgets/tabs/setup_relations.h
@@ -27,19 +27,17 @@
#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;
-namespace gcn
-{
- class ListModel;
-}
-
class Setup_Relations final : public SetupTab,
public PlayerRelationsListener
{
@@ -56,7 +54,7 @@ public:
void reset();
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void updatedPlayer(const std::string &name);
@@ -76,7 +74,7 @@ private:
Button *mDeleteButton;
- gcn::ListModel *mIgnoreActionChoicesModel;
+ ListModel *mIgnoreActionChoicesModel;
DropDown *mIgnoreActionChoicesBox;
};
diff --git a/src/gui/widgets/tabs/setup_theme.cpp b/src/gui/widgets/tabs/setup_theme.cpp
index d7cc4b4df..424828694 100644
--- a/src/gui/widgets/tabs/setup_theme.cpp
+++ b/src/gui/widgets/tabs/setup_theme.cpp
@@ -22,14 +22,18 @@
#include "gui/widgets/tabs/setup_theme.h"
+#include "gui/gui.h"
+
#include "gui/windows/okdialog.h"
+#include "gui/models/extendedlistmodel.h"
+#include "gui/models/fontsmodel.h"
+#include "gui/models/themesmodel.h"
+
#include "gui/widgets/button.h"
#include "gui/widgets/dropdown.h"
-#include "gui/widgets/extendedlistmodel.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/namesmodel.h"
#include "configuration.h"
@@ -51,31 +55,6 @@ const char* ACTION_JAPAN_FONT = "japanese font";
const char* ACTION_CHINA_FONT = "chinese font";
const char* ACTION_INFO = "info";
-class ThemesModel final : public NamesModel
-{
-public:
- ThemesModel() :
- NamesModel()
- {
- mNames.push_back(gettext("(default)"));
- Theme::fillSkinsList(mNames);
- }
-
- ~ThemesModel()
- { }
-};
-
-class FontsModel final : public NamesModel
-{
-public:
- FontsModel() :
- NamesModel()
- { Theme::fillFontsList(mNames); }
-
- ~FontsModel()
- { }
-};
-
const int maxFontSizes = 16;
const char *SIZE_NAME[maxFontSizes] =
@@ -114,7 +93,7 @@ const char *SIZE_NAME[maxFontSizes] =
N_("Huge (23)"),
};
-class FontSizeChoiceListModel final : public gcn::ListModel
+class FontSizeChoiceListModel final : public ListModel
{
public:
~FontSizeChoiceListModel()
@@ -387,7 +366,7 @@ Setup_Theme::Setup_Theme(const Widget2 *const widget) :
else if (size > maxWidth)
size = maxWidth;
- setDimension(gcn::Rectangle(0, 0, size, 500));
+ setDimension(Rect(0, 0, size, 500));
}
Setup_Theme::~Setup_Theme()
@@ -433,7 +412,7 @@ void Setup_Theme::updateInfo()
mInfoButton->setEnabled(!mThemeInfo.empty());
}
-void Setup_Theme::action(const gcn::ActionEvent &event)
+void Setup_Theme::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == ACTION_THEME)
diff --git a/src/gui/widgets/tabs/setup_theme.h b/src/gui/widgets/tabs/setup_theme.h
index a7f3ad101..5e8fe7c2a 100644
--- a/src/gui/widgets/tabs/setup_theme.h
+++ b/src/gui/widgets/tabs/setup_theme.h
@@ -46,7 +46,7 @@ class Setup_Theme final : public SetupTab
void cancel() override final;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void updateInfo();
diff --git a/src/gui/widgets/tabs/setup_touch.cpp b/src/gui/widgets/tabs/setup_touch.cpp
index 5d995f914..fb50ab4d5 100644
--- a/src/gui/widgets/tabs/setup_touch.cpp
+++ b/src/gui/widgets/tabs/setup_touch.cpp
@@ -20,7 +20,11 @@
#include "gui/widgets/tabs/setup_touch.h"
+#include "gui/models/namesmodel.h"
+#include "gui/models/touchactionmodel.h"
+
#include "gui/widgets/layouthelper.h"
+#include "gui/widgets/setuptouchitem.h"
#include "gui/widgets/scrollarea.h"
#include "utils/gettext.h"
@@ -117,7 +121,7 @@ Setup_Touch::Setup_Touch(const Widget2 *const widget) :
key, this, event, mActionsList, 250);
}
- setDimension(gcn::Rectangle(0, 0, 550, 350));
+ setDimension(Rect(0, 0, 550, 350));
}
Setup_Touch::~Setup_Touch()
diff --git a/src/gui/widgets/tabs/setup_touch.h b/src/gui/widgets/tabs/setup_touch.h
index 9adc2d5cd..ef1afdda3 100644
--- a/src/gui/widgets/tabs/setup_touch.h
+++ b/src/gui/widgets/tabs/setup_touch.h
@@ -21,7 +21,10 @@
#ifndef GUI_WIDGETS_TABS_SETUP_TOUCH_H
#define GUI_WIDGETS_TABS_SETUP_TOUCH_H
-#include "gui/widgets/setuptouchitem.h"
+#include "gui/widgets/tabs/setuptabscroll.h"
+
+class NamesModel;
+class TouchActionsModel;
class Setup_Touch final : public SetupTabScroll
{
diff --git a/src/gui/widgets/tabs/setup_video.cpp b/src/gui/widgets/tabs/setup_video.cpp
index 45ada01df..f55dceaa4 100644
--- a/src/gui/widgets/tabs/setup_video.cpp
+++ b/src/gui/widgets/tabs/setup_video.cpp
@@ -46,7 +46,7 @@
#include "test/testmain.h"
-#include <guichan/listmodel.hpp>
+#include "gui/models/listmodel.h"
#include <algorithm>
@@ -54,7 +54,7 @@
extern Graphics *mainGraphics;
-class ModeListModel final : public gcn::ListModel
+class ModeListModel final : public ListModel
{
public:
ModeListModel();
@@ -159,7 +159,7 @@ int ModeListModel::getIndexOf(const std::string &widthXHeightMode)
return -1;
}
-class OpenGLListModel final : public gcn::ListModel
+class OpenGLListModel final : public ListModel
{
public:
~OpenGLListModel()
@@ -178,7 +178,7 @@ public:
Setup_Video::Setup_Video(const Widget2 *const widget) :
SetupTab(widget),
- gcn::KeyListener(),
+ KeyListener(),
mFullScreenEnabled(config.getBoolValue("screen")),
mOpenGLEnabled(intToRenderType(config.getIntValue("opengl"))),
mFps(config.getIntValue("fpslimit")),
@@ -191,9 +191,9 @@ Setup_Video::Setup_Video(const Widget2 *const widget) :
mOpenGLDropDown(new DropDown(widget, mOpenGLListModel)),
// TRANSLATORS: video settings checkbox
mFpsCheckBox(new CheckBox(this, _("FPS limit:"))),
- mFpsSlider(new Slider(2, 160)),
+ mFpsSlider(new Slider(this, 2, 160)),
mFpsLabel(new Label(this)),
- mAltFpsSlider(new Slider(2, 160)),
+ mAltFpsSlider(new Slider(this, 2, 160)),
// TRANSLATORS: video settings label
mAltFpsLabel(new Label(this, _("Alt FPS limit: "))),
#if !defined(ANDROID) && !defined(__APPLE__)
@@ -224,7 +224,7 @@ Setup_Video::Setup_Video(const Widget2 *const widget) :
// TRANSLATORS: video settings tab name
setName(_("Video"));
- ScrollArea *const scrollArea = new ScrollArea(mModeList,
+ ScrollArea *const scrollArea = new ScrollArea(this, mModeList,
true, "setup_video_background.xml");
scrollArea->setWidth(150);
scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -304,7 +304,7 @@ Setup_Video::Setup_Video(const Widget2 *const widget) :
if (config.getIntValue("screenwidth") >= 730)
width += 100;
- setDimension(gcn::Rectangle(0, 0, width, 300));
+ setDimension(Rect(0, 0, width, 300));
}
Setup_Video::~Setup_Video()
@@ -445,7 +445,7 @@ void Setup_Video::cancel()
config.setValue("noframe", mNoFrame);
}
-void Setup_Video::action(const gcn::ActionEvent &event)
+void Setup_Video::action(const ActionEvent &event)
{
const std::string &id = event.getId();
diff --git a/src/gui/widgets/tabs/setup_video.h b/src/gui/widgets/tabs/setup_video.h
index 22d55c121..250fac0e0 100644
--- a/src/gui/widgets/tabs/setup_video.h
+++ b/src/gui/widgets/tabs/setup_video.h
@@ -25,7 +25,7 @@
#include "gui/widgets/tabs/setuptab.h"
-#include <guichan/keylistener.hpp>
+#include "listeners/keylistener.h"
class Button;
class CheckBox;
@@ -37,7 +37,8 @@ class OpenGLListModel;
class Slider;
class TextDialog;
-class Setup_Video final : public SetupTab, public gcn::KeyListener
+class Setup_Video final : public SetupTab,
+ public KeyListener
{
public:
explicit Setup_Video(const Widget2 *const widget);
@@ -50,7 +51,7 @@ class Setup_Video final : public SetupTab, public gcn::KeyListener
void cancel() override final;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
private:
bool mFullScreenEnabled;
diff --git a/src/gui/widgets/tabs/setup_visual.cpp b/src/gui/widgets/tabs/setup_visual.cpp
index ac608f756..9666b224a 100644
--- a/src/gui/widgets/tabs/setup_visual.cpp
+++ b/src/gui/widgets/tabs/setup_visual.cpp
@@ -21,8 +21,9 @@
#include "gui/widgets/tabs/setup_visual.h"
+#include "gui/models/namesmodel.h"
+
#include "gui/widgets/layouthelper.h"
-#include "gui/widgets/namesmodel.h"
#include "gui/widgets/scrollarea.h"
#include "client.h"
@@ -202,7 +203,7 @@ Setup_Visual::Setup_Visual(const Widget2 *const widget) :
new SetupItemCheckBox(_("Allow screensaver to run"),
"", "allowscreensaver", this, "allowscreensaverEvent");
- setDimension(gcn::Rectangle(0, 0, 550, 350));
+ setDimension(Rect(0, 0, 550, 350));
}
Setup_Visual::~Setup_Visual()
diff --git a/src/gui/widgets/tabs/setup_visual.h b/src/gui/widgets/tabs/setup_visual.h
index 2d40d3a08..1229757dd 100644
--- a/src/gui/widgets/tabs/setup_visual.h
+++ b/src/gui/widgets/tabs/setup_visual.h
@@ -24,6 +24,8 @@
#include "gui/widgets/setupitem.h"
+#include "gui/widgets/tabs/setuptabscroll.h"
+
class NamesModel;
class Setup_Visual final : public SetupTabScroll
diff --git a/src/gui/widgets/tabs/setuptab.cpp b/src/gui/widgets/tabs/setuptab.cpp
index c445e2ad7..6de77d7a0 100644
--- a/src/gui/widgets/tabs/setuptab.cpp
+++ b/src/gui/widgets/tabs/setuptab.cpp
@@ -26,8 +26,8 @@
SetupTab::SetupTab(const Widget2 *const widget) :
Container(widget),
- gcn::ActionListener(),
- gcn::WidgetListener(),
+ ActionListener(),
+ WidgetListener(),
mName()
{
setOpaque(false);
diff --git a/src/gui/widgets/tabs/setuptab.h b/src/gui/widgets/tabs/setuptab.h
index 388b0a988..4d6049b6a 100644
--- a/src/gui/widgets/tabs/setuptab.h
+++ b/src/gui/widgets/tabs/setuptab.h
@@ -25,8 +25,8 @@
#include "gui/widgets/container.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/widgetlistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/widgetlistener.h"
#include <string>
@@ -36,8 +36,8 @@
* A container for the contents of a tab in the setup window.
*/
class SetupTab : public Container,
- public gcn::ActionListener,
- public gcn::WidgetListener
+ public ActionListener,
+ public WidgetListener
{
public:
A_DELETE_COPY(SetupTab)
diff --git a/src/gui/widgets/tabs/setuptabscroll.cpp b/src/gui/widgets/tabs/setuptabscroll.cpp
index 659ef5824..9c185b2bb 100644
--- a/src/gui/widgets/tabs/setuptabscroll.cpp
+++ b/src/gui/widgets/tabs/setuptabscroll.cpp
@@ -29,7 +29,7 @@
SetupTabScroll::SetupTabScroll(const Widget2 *const widget) :
SetupTab(widget),
mContainer(new VertContainer(this, 25, false, 8)),
- mScroll(new ScrollArea(mContainer, false)),
+ mScroll(new ScrollArea(this, mContainer, false)),
mItems(),
mAllItems(),
mPreferredFirstItemSize(200)
@@ -146,7 +146,7 @@ void SetupTabScroll::externalUnloaded()
}
}
-void SetupTabScroll::widgetResized(const gcn::Event &event A_UNUSED)
+void SetupTabScroll::widgetResized(const Event &event A_UNUSED)
{
mScroll->setWidth(getWidth() - 12);
mScroll->setHeight(getHeight() - 12 - 12);
diff --git a/src/gui/widgets/tabs/setuptabscroll.h b/src/gui/widgets/tabs/setuptabscroll.h
index fb7de574d..f7aa628c9 100644
--- a/src/gui/widgets/tabs/setuptabscroll.h
+++ b/src/gui/widgets/tabs/setuptabscroll.h
@@ -56,14 +56,14 @@ class SetupTabScroll : public SetupTab
virtual void externalUnloaded() override;
- virtual void action(const gcn::ActionEvent &event A_UNUSED)
+ virtual void action(const ActionEvent &event A_UNUSED)
override final
{ }
int getPreferredFirstItemSize() const A_WARN_UNUSED
{ return mPreferredFirstItemSize; }
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
void reread(const std::string &name);
diff --git a/src/gui/widgets/tabs/tab.cpp b/src/gui/widgets/tabs/tab.cpp
index 4f1703d31..96ae76787 100644
--- a/src/gui/widgets/tabs/tab.cpp
+++ b/src/gui/widgets/tabs/tab.cpp
@@ -20,14 +20,61 @@
* 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 "client.h"
#include "graphicsvertexes.h"
+#include "gui/gui.h"
+
#include "gui/widgets/label.h"
#include "gui/widgets/tabbedarea.h"
+#include "resources/image.h"
+
#include "debug.h"
int Tab::mInstances = 0;
@@ -44,10 +91,9 @@ static std::string const data[Tab::TAB_COUNT] =
Skin *Tab::tabImg[Tab::TAB_COUNT];
Tab::Tab(const Widget2 *const widget) :
- gcn::BasicContainer(),
- Widget2(widget),
- gcn::MouseListener(),
- gcn::WidgetListener(),
+ gcn::BasicContainer(widget),
+ MouseListener(),
+ WidgetListener(),
mLabel(new Label(this)),
mTabbedArea(nullptr),
mTabColor(&getThemeColor(Theme::TAB)),
@@ -153,7 +199,7 @@ void Tab::updateAlpha()
}
}
-void Tab::draw(gcn::Graphics *graphics)
+void Tab::draw(Graphics *graphics)
{
BLOCK_START("Tab::draw")
int mode = TAB_STANDARD;
@@ -204,19 +250,19 @@ void Tab::draw(gcn::Graphics *graphics)
updateAlpha();
- Graphics *const g = static_cast<Graphics*>(graphics);
-
// draw tab
if (isBatchDrawRenders(openGLMode))
{
const ImageRect &rect = skin->getBorder();
- if (mRedraw || mode != mMode || g->getRedraw())
+ if (mRedraw || mode != mMode || graphics->getRedraw())
{
mMode = mode;
mRedraw = false;
mVertexes->clear();
- g->calcWindow(mVertexes, 0, 0,
- mDimension.width, mDimension.height, rect);
+ graphics->calcWindow(mVertexes,
+ 0, 0,
+ mDimension.width, mDimension.height,
+ rect);
if (mImage)
{
@@ -224,25 +270,28 @@ void Tab::draw(gcn::Graphics *graphics)
if (skin1)
{
const int padding = skin1->getPadding();
- g->calcTileCollection(mVertexes, mImage,
- padding, padding);
+ graphics->calcTileCollection(mVertexes,
+ mImage,
+ padding,
+ padding);
}
}
}
- g->drawTileCollection(mVertexes);
+ graphics->drawTileCollection(mVertexes);
}
else
{
- g->drawImageRect(0, 0,
- mDimension.width, mDimension.height, skin->getBorder());
+ graphics->drawImageRect(0, 0,
+ mDimension.width, mDimension.height,
+ skin->getBorder());
if (mImage)
{
const Skin *const skin1 = tabImg[TAB_STANDARD];
if (skin1)
{
const int padding = skin1->getPadding();
- g->drawImage2(mImage, padding, padding);
+ graphics->drawImage(mImage, padding, padding);
}
}
}
@@ -251,17 +300,17 @@ void Tab::draw(gcn::Graphics *graphics)
BLOCK_END("Tab::draw")
}
-void Tab::widgetResized(const gcn::Event &event A_UNUSED)
+void Tab::widgetResized(const Event &event A_UNUSED)
{
mRedraw = true;
}
-void Tab::widgetMoved(const gcn::Event &event A_UNUSED)
+void Tab::widgetMoved(const Event &event A_UNUSED)
{
mRedraw = true;
}
-void Tab::setLabelFont(gcn::Font *const font)
+void Tab::setLabelFont(Font *const font)
{
if (!mLabel)
return;
@@ -324,12 +373,12 @@ const std::string &Tab::getCaption() const
return mLabel->getCaption();
}
-void Tab::mouseEntered(gcn::MouseEvent& mouseEvent A_UNUSED)
+void Tab::mouseEntered(MouseEvent& mouseEvent A_UNUSED)
{
mHasMouse = true;
}
-void Tab::mouseExited(gcn::MouseEvent& mouseEvent A_UNUSED)
+void Tab::mouseExited(MouseEvent& mouseEvent A_UNUSED)
{
mHasMouse = false;
}
diff --git a/src/gui/widgets/tabs/tab.h b/src/gui/widgets/tabs/tab.h
index 118b1f0e2..1f52cde88 100644
--- a/src/gui/widgets/tabs/tab.h
+++ b/src/gui/widgets/tabs/tab.h
@@ -20,14 +20,56 @@
* 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/widget2.h"
+#include "gui/base/basiccontainer.hpp"
-#include <guichan/basiccontainer.hpp>
-#include <guichan/mouselistener.hpp>
-#include <guichan/widgetlistener.hpp>
+#include "listeners/mouselistener.h"
+#include "listeners/widgetlistener.h"
#include "localconsts.h"
@@ -40,9 +82,8 @@ class TabbedArea;
* A tab, the same as the Guichan tab in 0.8, but extended
*/
class Tab : public gcn::BasicContainer,
- public Widget2,
- public gcn::MouseListener,
- public gcn::WidgetListener
+ public MouseListener,
+ public WidgetListener
{
public:
explicit Tab(const Widget2 *const widget);
@@ -68,13 +109,13 @@ class Tab : public gcn::BasicContainer,
/**
* Draw the tabbed area.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
/**
* Set the normal color for the tab's text.
*/
- void setTabColor(const gcn::Color *const color1,
- const gcn::Color *const color2)
+ void setTabColor(const Color *const color1,
+ const Color *const color2)
{
mTabColor = color1;
mTabOutlineColor = color2;
@@ -83,8 +124,8 @@ class Tab : public gcn::BasicContainer,
/**
* Set the highlighted color for the tab's text.
*/
- void setHighlightedTabColor(const gcn::Color *const color1,
- const gcn::Color *const color2)
+ void setHighlightedTabColor(const Color *const color1,
+ const Color *const color2)
{
mTabHighlightedColor = color1;
mTabHighlightedOutlineColor = color2;
@@ -93,8 +134,8 @@ class Tab : public gcn::BasicContainer,
/**
* Set the selected color for the tab's text.
*/
- void setSelectedTabColor(const gcn::Color *const color1,
- const gcn::Color *const color2)
+ void setSelectedTabColor(const Color *const color1,
+ const Color *const color2)
{
mTabSelectedColor = color1;
mTabSelectedOutlineColor = color2;
@@ -103,8 +144,8 @@ class Tab : public gcn::BasicContainer,
/**
* Set the flash color for the tab's text.
*/
- void setFlashTabColor(const gcn::Color *const color1,
- const gcn::Color *const color2)
+ void setFlashTabColor(const Color *const color1,
+ const Color *const color2)
{
mFlashColor = color1;
mFlashOutlineColor = color2;
@@ -113,8 +154,8 @@ class Tab : public gcn::BasicContainer,
/**
* Set the player flash color for the tab's text.
*/
- void setPlayerFlashTabColor(const gcn::Color *const color1,
- const gcn::Color *const color2)
+ void setPlayerFlashTabColor(const Color *const color1,
+ const Color *const color2)
{
mPlayerFlashColor = color1;
mPlayerFlashOutlineColor = color2;
@@ -129,11 +170,11 @@ class Tab : public gcn::BasicContainer,
int getFlash() const A_WARN_UNUSED
{ return mFlash; }
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
- void widgetMoved(const gcn::Event &event) override final;
+ void widgetMoved(const Event &event) override final;
- void setLabelFont(gcn::Font *const font);
+ void setLabelFont(Font *const font);
Label *getLabel() const A_WARN_UNUSED
{ return mLabel; }
@@ -148,9 +189,9 @@ class Tab : public gcn::BasicContainer,
const std::string &getCaption() const A_WARN_UNUSED;
- void mouseEntered(gcn::MouseEvent &mouseEvent) override final;
+ void mouseEntered(MouseEvent &mouseEvent) override final;
- void mouseExited(gcn::MouseEvent &mouseEvent) override final;
+ void mouseExited(MouseEvent &mouseEvent) override final;
void setImage(Image *const image);
@@ -173,16 +214,16 @@ class Tab : public gcn::BasicContainer,
static int mInstances; /**< Number of tab instances */
static float mAlpha;
- const gcn::Color *mTabColor;
- const gcn::Color *mTabOutlineColor;
- const gcn::Color *mTabHighlightedColor;
- const gcn::Color *mTabHighlightedOutlineColor;
- const gcn::Color *mTabSelectedColor;
- const gcn::Color *mTabSelectedOutlineColor;
- const gcn::Color *mFlashColor;
- const gcn::Color *mFlashOutlineColor;
- const gcn::Color *mPlayerFlashColor;
- const gcn::Color *mPlayerFlashOutlineColor;
+ 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;
Image *mImage;
diff --git a/src/gui/widgets/tabs/whispertab.cpp b/src/gui/widgets/tabs/whispertab.cpp
index ec02bb70f..023d94110 100644
--- a/src/gui/widgets/tabs/whispertab.cpp
+++ b/src/gui/widgets/tabs/whispertab.cpp
@@ -34,7 +34,8 @@
#include "debug.h"
-WhisperTab::WhisperTab(const Widget2 *const widget, const std::string &nick) :
+WhisperTab::WhisperTab(const Widget2 *const widget,
+ const std::string &nick) :
ChatTab(widget, nick, ""),
mNick(nick)
{
diff --git a/src/gui/widgets/tabs/whispertab.h b/src/gui/widgets/tabs/whispertab.h
index 5dbb05a4e..84b55ae58 100644
--- a/src/gui/widgets/tabs/whispertab.h
+++ b/src/gui/widgets/tabs/whispertab.h
@@ -57,7 +57,8 @@ class WhisperTab final : public ChatTab
*
* @param nick the name of the player this tab is whispering to
*/
- WhisperTab(const Widget2 *const widget, const std::string &nick);
+ WhisperTab(const Widget2 *const widget,
+ const std::string &nick);
~WhisperTab();
diff --git a/src/gui/widgets/tabstrip.cpp b/src/gui/widgets/tabstrip.cpp
index 24c33c614..57520afce 100644
--- a/src/gui/widgets/tabstrip.cpp
+++ b/src/gui/widgets/tabstrip.cpp
@@ -25,19 +25,21 @@
#include "debug.h"
TabStrip::TabStrip(const Widget2 *const widget,
- const std::string &group, const int height,
+ const std::string &group,
+ const int height,
const int spacing) :
WidgetGroup(widget, group, height, spacing)
{
}
TabStrip::TabStrip(const Widget2 *const widget,
- const int height, const int spacing) :
+ const int height,
+ const int spacing) :
WidgetGroup(widget, "", height, spacing)
{
}
-gcn::Widget *TabStrip::createWidget(const std::string &text) const
+Widget *TabStrip::createWidget(const std::string &text) const
{
Button *const widget = new Button(this);
widget->setStick(true);
@@ -48,12 +50,12 @@ gcn::Widget *TabStrip::createWidget(const std::string &text) const
return widget;
}
-void TabStrip::action(const gcn::ActionEvent &event)
+void TabStrip::action(const ActionEvent &event)
{
WidgetGroup::action(event);
if (event.getSource())
{
- gcn::Widget *const widget = event.getSource();
+ Widget *const widget = event.getSource();
if (static_cast<Button*>(widget)->isPressed2())
{
FOR_EACH (WidgetListConstIterator, iter, mWidgets)
diff --git a/src/gui/widgets/tabstrip.h b/src/gui/widgets/tabstrip.h
index 622ccba81..a89dd5144 100644
--- a/src/gui/widgets/tabstrip.h
+++ b/src/gui/widgets/tabstrip.h
@@ -23,24 +23,24 @@
#include "gui/widgets/widgetgroup.h"
-#include <guichan/widget.hpp>
-
class TabStrip final : public WidgetGroup
{
public:
TabStrip(const Widget2 *const widget,
- const std::string &group, const int height,
+ const std::string &group,
+ const int height,
const int spacing = 0);
TabStrip(const Widget2 *const widget,
- const int height, const int spacing = 0);
+ const int height,
+ const int spacing = 0);
A_DELETE_COPY(TabStrip)
- gcn::Widget *createWidget(const std::string &name)
- const override final A_WARN_UNUSED;
+ Widget *createWidget(const std::string &name)
+ const override final A_WARN_UNUSED;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
};
#endif // GUI_WIDGETS_TABSTRIP_H
diff --git a/src/gui/widgets/textbox.cpp b/src/gui/widgets/textbox.cpp
index f59bc0ceb..a1ce0e61d 100644
--- a/src/gui/widgets/textbox.cpp
+++ b/src/gui/widgets/textbox.cpp
@@ -22,18 +22,19 @@
#include "gui/widgets/textbox.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
-#include <guichan/font.hpp>
+#include "gui/font.h"
+#include "gui/gui.h"
#include <sstream>
#include "debug.h"
TextBox::TextBox(const Widget2 *const widget) :
- gcn::TextBox(),
- Widget2(widget),
+ gcn::TextBox(widget),
mMinWidth(getWidth())
{
mForegroundColor = getThemeColor(Theme::TEXTBOX);
@@ -87,7 +88,7 @@ void TextBox::setTextWrapped(const std::string &text, const int minDimension)
text.substr(lastNewlinePos, newlinePos - lastNewlinePos);
size_t lastSpacePos = 0;
xpos = 0;
- const gcn::Font *const font = getFont();
+ const Font *const font = getFont();
const int spaceWidth = font->getWidth(" ");
size_t sz = line.size();
@@ -165,10 +166,10 @@ void TextBox::setTextWrapped(const std::string &text, const int minDimension)
gcn::TextBox::setText(wrappedStream.str());
}
-void TextBox::keyPressed(gcn::KeyEvent& keyEvent)
+void TextBox::keyPressed(KeyEvent& keyEvent)
{
- const gcn::Key &key = keyEvent.getKey();
- const int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const Key &key = keyEvent.getKey();
+ const int action = keyEvent.getActionId();
switch (action)
{
@@ -291,7 +292,7 @@ void TextBox::keyPressed(gcn::KeyEvent& keyEvent)
case Input::KEY_GUI_PAGE_UP:
{
- gcn::Widget *const par = getParent();
+ Widget *const par = getParent();
if (par)
{
@@ -307,7 +308,7 @@ void TextBox::keyPressed(gcn::KeyEvent& keyEvent)
case Input::KEY_GUI_PAGE_DOWN:
{
- gcn::Widget *const par = getParent();
+ Widget *const par = getParent();
if (par)
{
@@ -350,16 +351,16 @@ void TextBox::keyPressed(gcn::KeyEvent& keyEvent)
keyEvent.consume();
}
-void TextBox::draw(gcn::Graphics* graphics)
+void TextBox::draw(Graphics* graphics)
{
BLOCK_START("TextBox::draw")
if (mOpaque)
{
graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
+ graphics->fillRectangle(Rect(0, 0, getWidth(), getHeight()));
}
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
if (isFocused() && isEditable())
{
drawCaret(graphics, font->getWidth(
@@ -367,8 +368,7 @@ void TextBox::draw(gcn::Graphics* graphics)
mCaretRow * font->getHeight());
}
- static_cast<Graphics*>(graphics)->setColorAll(
- mForegroundColor, mForegroundColor2);
+ graphics->setColorAll(mForegroundColor, mForegroundColor2);
const int fontHeight = font->getHeight();
for (size_t i = 0, sz = mTextRows.size(); i < sz; i++)
@@ -379,14 +379,14 @@ void TextBox::draw(gcn::Graphics* graphics)
BLOCK_END("TextBox::draw")
}
-void TextBox::setForegroundColor(const gcn::Color &color)
+void TextBox::setForegroundColor(const Color &color)
{
mForegroundColor = color;
mForegroundColor2 = color;
}
-void TextBox::setForegroundColorAll(const gcn::Color &color1,
- const gcn::Color &color2)
+void TextBox::setForegroundColorAll(const Color &color1,
+ const Color &color2)
{
mForegroundColor = color1;
mForegroundColor2 = color2;
diff --git a/src/gui/widgets/textbox.h b/src/gui/widgets/textbox.h
index 501744515..3f78fd247 100644
--- a/src/gui/widgets/textbox.h
+++ b/src/gui/widgets/textbox.h
@@ -23,9 +23,7 @@
#ifndef GUI_WIDGETS_TEXTBOX_H
#define GUI_WIDGETS_TEXTBOX_H
-#include "gui/widgets/widget2.h"
-
-#include <guichan/widgets/textbox.hpp>
+#include "gui/base/widgets/textbox.hpp"
#include "localconsts.h"
@@ -36,8 +34,7 @@
*
* \ingroup GUI
*/
-class TextBox final : public gcn::TextBox,
- public Widget2
+class TextBox final : public gcn::TextBox
{
public:
/**
@@ -60,14 +57,14 @@ class TextBox final : public gcn::TextBox,
int getMinWidth() const A_WARN_UNUSED
{ return mMinWidth; }
- void keyPressed(gcn::KeyEvent& keyEvent) override final;
+ void keyPressed(KeyEvent& keyEvent) override final;
- void draw(gcn::Graphics* graphics) override final;
+ void draw(Graphics* graphics) override final;
- void setForegroundColor(const gcn::Color &color);
+ void setForegroundColor(const Color &color);
- void setForegroundColorAll(const gcn::Color &color1,
- const gcn::Color &color2);
+ void setForegroundColorAll(const Color &color1,
+ const Color &color2);
private:
int mMinWidth;
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index 269ace775..78a2826d5 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -26,10 +26,10 @@
#include "input/inputmanager.h"
-#include "input/keyevent.h"
-
-#include "gui/sdlinput.h"
+#include "events/keyevent.h"
+#include "gui/font.h"
+#include "gui/gui.h"
#include "gui/viewport.h"
#include "gui/popups/popupmenu.h"
@@ -39,8 +39,6 @@
#include "utils/copynpaste.h"
#include "utils/timer.h"
-#include <guichan/font.hpp>
-
#undef DELETE // Win32 compatibility hack
#include "debug.h"
@@ -53,12 +51,11 @@ ImageRect TextField::skin;
TextField::TextField(const Widget2 *restrict const widget,
const std::string &restrict text,
const bool loseFocusOnTab,
- gcn::ActionListener *restrict const listener,
+ ActionListener *restrict const listener,
const std::string &restrict eventId,
const bool sendAlwaysEvents):
- gcn::TextField(text),
- gcn::FocusListener(),
- Widget2(widget),
+ gcn::TextField(widget, text),
+ FocusListener(),
mSendAlwaysEvents(sendAlwaysEvents),
mCaretColor(&getThemeColor(Theme::CARET)),
mPopupMenu(nullptr),
@@ -137,30 +134,32 @@ void TextField::updateAlpha()
}
}
-void TextField::draw(gcn::Graphics *graphics)
+void TextField::draw(Graphics *graphics)
{
BLOCK_START("TextField::draw")
updateAlpha();
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
if (isFocused())
{
drawCaret(graphics,
font->getWidth(mText.substr(0, mCaretPosition)) - mXScroll);
}
- static_cast<Graphics*>(graphics)->setColorAll(
- mForegroundColor, mForegroundColor2);
+ graphics->setColorAll(mForegroundColor, mForegroundColor2);
font->drawString(graphics, mText, mPadding - mXScroll, mPadding);
BLOCK_END("TextField::draw")
}
-void TextField::drawFrame(gcn::Graphics *graphics)
+void TextField::drawFrame(Graphics *graphics)
{
BLOCK_START("TextField::drawFrame")
const int bs = 2 * mFrameSize;
- static_cast<Graphics*>(graphics)->drawImageRect(0, 0,
- mDimension.width + bs, mDimension.height + bs, skin);
+ graphics->drawImageRect(0,
+ 0,
+ mDimension.width + bs,
+ mDimension.height + bs,
+ skin);
BLOCK_END("TextField::drawFrame")
}
@@ -196,13 +195,13 @@ int TextField::getValue() const
return value;
}
-void TextField::keyPressed(gcn::KeyEvent &keyEvent)
+void TextField::keyPressed(KeyEvent &keyEvent)
{
const int val = keyEvent.getKey().getValue();
#ifdef USE_SDL2
if (val == Key::TEXTINPUT)
{
- std::string str = static_cast<KeyEvent*>(&keyEvent)->getText();
+ std::string str = keyEvent.getText();
mText.insert(mCaretPosition, str);
mCaretPosition += str.size();
keyEvent.consume();
@@ -252,7 +251,7 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
}
if (len > 1)
- buf[0] |= static_cast<char>(255 << (8 - len));
+ buf[0] |= static_cast<char>(255U << (8 - len));
mText.insert(mCaretPosition, std::string(buf, buf + len));
mCaretPosition += len;
@@ -291,7 +290,7 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent)
}
else
{
- const int action = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int action = keyEvent.getActionId();
if (!inputManager.isActionActive(static_cast<int>(
Input::KEY_GUI_CTRL)))
{
@@ -661,12 +660,14 @@ void TextField::handleCopy() const
sendBuffer(text);
}
-void TextField::drawCaret(gcn::Graphics* graphics, int x)
+void TextField::drawCaret(Graphics* graphics, int x)
{
- const gcn::Rectangle &clipArea = graphics->getCurrentClipArea();
+ const Rect *const clipArea = graphics->getCurrentClipArea();
+ if (!clipArea)
+ return;
graphics->setColor(*mCaretColor);
- graphics->drawLine(x + mPadding, clipArea.height - mPadding,
+ graphics->drawLine(x + mPadding, clipArea->height - mPadding,
x + mPadding, mPadding);
}
@@ -722,13 +723,13 @@ void TextField::fontChanged()
fixScroll();
}
-void TextField::mousePressed(gcn::MouseEvent &mouseEvent)
+void TextField::mousePressed(MouseEvent &mouseEvent)
{
#ifdef ANDROID
if (!client->isKeyboardVisible())
inputManager.executeAction(Input::KEY_SHOW_KEYBOARD);
#endif
- if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT)
+ if (mouseEvent.getButton() == MouseEvent::RIGHT)
{
if (viewport)
{
@@ -756,7 +757,7 @@ void TextField::mousePressed(gcn::MouseEvent &mouseEvent)
}
}
-void TextField::focusGained(const gcn::Event &event A_UNUSED)
+void TextField::focusGained(const Event &event A_UNUSED)
{
#ifdef ANDROID
if (!client->isKeyboardVisible())
@@ -764,6 +765,6 @@ void TextField::focusGained(const gcn::Event &event A_UNUSED)
#endif
}
-void TextField::focusLost(const gcn::Event &event A_UNUSED)
+void TextField::focusLost(const Event &event A_UNUSED)
{
}
diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h
index abff9cf2a..ccc1b16d6 100644
--- a/src/gui/widgets/textfield.h
+++ b/src/gui/widgets/textfield.h
@@ -23,10 +23,9 @@
#ifndef GUI_WIDGETS_TEXTFIELD_H
#define GUI_WIDGETS_TEXTFIELD_H
-#include "gui/widgets/widget2.h"
+#include "listeners/focuslistener.h"
-#include <guichan/focuslistener.hpp>
-#include <guichan/widgets/textfield.hpp>
+#include "gui/base/widgets/textfield.hpp"
#include "localconsts.h"
@@ -38,8 +37,7 @@ class PopupMenu;
* \ingroup GUI
*/
class TextField : public gcn::TextField,
- public gcn::FocusListener,
- public Widget2
+ public FocusListener
{
public:
/**
@@ -48,7 +46,7 @@ class TextField : public gcn::TextField,
explicit TextField(const Widget2 *restrict const widget,
const std::string &restrict text = "",
const bool loseFocusOnTab = true,
- gcn::ActionListener *restrict
+ ActionListener *restrict
const listener = nullptr,
const std::string &restrict eventId = "",
const bool sendAlwaysEvents = false);
@@ -60,7 +58,7 @@ class TextField : public gcn::TextField,
/**
* Draws the text field.
*/
- virtual void draw(gcn::Graphics *graphics) override;
+ virtual void draw(Graphics *graphics) override;
/**
* Update the alpha value to the graphic components.
@@ -70,7 +68,7 @@ class TextField : public gcn::TextField,
/**
* Draws the background and border.
*/
- void drawFrame(gcn::Graphics *graphics) override final;
+ void drawFrame(Graphics *graphics) override final;
/**
* Determine whether the field should be numeric or not
@@ -89,7 +87,7 @@ class TextField : public gcn::TextField,
/**
* Processes one keypress.
*/
- void keyPressed(gcn::KeyEvent &keyEvent) override;
+ void keyPressed(KeyEvent &keyEvent) override;
/**
* Set the minimum value for a range
@@ -117,15 +115,15 @@ class TextField : public gcn::TextField,
void setCaretPosition(unsigned int position);
- void mousePressed(gcn::MouseEvent &mouseEvent) override final;
+ void mousePressed(MouseEvent &mouseEvent) override final;
void handlePaste();
void handleCopy() const;
- void focusGained(const gcn::Event &event) override final;
+ void focusGained(const Event &event) override final;
- void focusLost(const gcn::Event &event) override;
+ void focusLost(const Event &event) override;
void moveCaretBack();
@@ -142,7 +140,7 @@ class TextField : public gcn::TextField,
void caretDeleteWord();
protected:
- void drawCaret(gcn::Graphics* graphics, int x) override final;
+ void drawCaret(Graphics* graphics, int x) override final;
void fixScroll();
@@ -161,7 +159,7 @@ class TextField : public gcn::TextField,
static Skin *mSkin;
private:
- const gcn::Color *mCaretColor;
+ const Color *mCaretColor;
PopupMenu *mPopupMenu;
static int instances;
static float mAlpha;
diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp
index 8d473dd46..10bd936c6 100644
--- a/src/gui/widgets/textpreview.cpp
+++ b/src/gui/widgets/textpreview.cpp
@@ -24,8 +24,8 @@
#include "client.h"
+#include "gui/font.h"
#include "gui/gui.h"
-#include "gui/sdlfont.h"
#include "debug.h"
@@ -35,8 +35,7 @@ Skin *TextPreview::mSkin = nullptr;
TextPreview::TextPreview(const Widget2 *const widget,
const std::string &text) :
- gcn::Widget(),
- Widget2(widget),
+ Widget(widget),
mFont(gui->getFont()),
mText(text),
mTextColor(&getThemeColor(Theme::TEXT)),
@@ -79,49 +78,47 @@ TextPreview::~TextPreview()
}
}
-void TextPreview::draw(gcn::Graphics* graphics)
+void TextPreview::draw(Graphics* graphics)
{
+ if (!mFont)
+ return;
+
BLOCK_START("TextPreview::draw")
if (client->getGuiAlpha() != mAlpha)
mAlpha = client->getGuiAlpha();
- Graphics *const g = static_cast<Graphics*>(graphics);
const int intAlpha = static_cast<int>(mAlpha * 255.0F);
const int alpha = mTextAlpha ? intAlpha : 255;
if (mOpaque)
{
- g->setColor(gcn::Color(static_cast<int>(mBGColor->r),
+ graphics->setColor(Color(static_cast<int>(mBGColor->r),
static_cast<int>(mBGColor->g),
static_cast<int>(mBGColor->b),
static_cast<int>(mAlpha * 255.0F)));
- g->fillRectangle(gcn::Rectangle(0, 0,
+ graphics->fillRectangle(Rect(0, 0,
mDimension.width, mDimension.height));
}
if (mTextBGColor)
{
- const SDLFont *const font = dynamic_cast<SDLFont*>(mFont);
- if (font)
- {
- const int x = font->getWidth(mText) + 1
- + 2 * ((mOutline || mShadow) ? 1 :0);
- const int y = font->getHeight() + 1
- + 2 * ((mOutline || mShadow) ? 1 : 0);
- g->setColor(gcn::Color(static_cast<int>(mTextBGColor->r),
- static_cast<int>(mTextBGColor->g),
- static_cast<int>(mTextBGColor->b),
- intAlpha));
- g->fillRectangle(gcn::Rectangle(mPadding, mPadding, x, y));
- }
+ 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(static_cast<int>(mTextBGColor->r),
+ static_cast<int>(mTextBGColor->g),
+ static_cast<int>(mTextBGColor->b),
+ intAlpha));
+ graphics->fillRectangle(Rect(mPadding, mPadding, x, y));
}
- g->setColorAll(gcn::Color(mTextColor->r, mTextColor->g, mTextColor->b,
- alpha), gcn::Color(mTextColor2->r, mTextColor2->g, mTextColor2->b,
- alpha));
+ graphics->setColorAll(Color(mTextColor->r,
+ mTextColor->g, mTextColor->b, alpha),
+ Color(mTextColor2->r, mTextColor2->g, mTextColor2->b, alpha));
if (mOutline && mTextColor != mTextColor2)
- g->setColor2(Theme::getThemeColor(Theme::OUTLINE));
+ graphics->setColor2(Theme::getThemeColor(Theme::OUTLINE));
mFont->drawString(graphics, mText, mPadding + 1, mPadding + 1);
BLOCK_END("TextPreview::draw")
diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h
index eeb6805fb..5a09e1148 100644
--- a/src/gui/widgets/textpreview.h
+++ b/src/gui/widgets/textpreview.h
@@ -23,29 +23,27 @@
#ifndef GUI_WIDGETS_TEXTPREVIEW_H
#define GUI_WIDGETS_TEXTPREVIEW_H
-#include "gui/widgets/widget2.h"
-
-#include <guichan/widget.hpp>
+#include "gui/widgets/widget.h"
#include "localconsts.h"
/**
* Preview widget for particle colors, etc.
*/
-class TextPreview final : public gcn::Widget,
- public Widget2
+class TextPreview final : public Widget
{
public:
- TextPreview(const Widget2 *const widget, const std::string &text);
+ TextPreview(const Widget2 *const widget,
+ const std::string &text);
A_DELETE_COPY(TextPreview)
~TextPreview();
- inline void setTextColor(const gcn::Color *color)
+ inline void setTextColor(const Color *color)
{ mTextColor = color; adjustSize(); }
- inline void setTextColor2(const gcn::Color *color)
+ inline void setTextColor2(const Color *color)
{ mTextColor2 = color; adjustSize(); }
/**
@@ -62,7 +60,7 @@ class TextPreview final : public gcn::Widget,
*
* @param color the color to set
*/
- inline void setTextBGColor(const gcn::Color *color)
+ inline void setTextBGColor(const Color *color)
{ mTextBGColor = color; }
/**
@@ -70,7 +68,7 @@ class TextPreview final : public gcn::Widget,
*
* @param color the color to set
*/
- inline void setBGColor(const gcn::Color *color)
+ inline void setBGColor(const Color *color)
{ mBGColor = color; }
/**
@@ -78,7 +76,7 @@ class TextPreview final : public gcn::Widget,
*
* @param font the font to use.
*/
- inline void setFont(gcn::Font *const font)
+ inline void setFont(Font *const font)
{ mFont = font; }
/**
@@ -102,7 +100,7 @@ class TextPreview final : public gcn::Widget,
*
* @param graphics graphics to draw into
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
/**
* Set opacity for this widget (whether or not to show the background
@@ -123,12 +121,12 @@ class TextPreview final : public gcn::Widget,
void adjustSize();
private:
- gcn::Font *mFont;
+ Font *mFont;
std::string mText;
- const gcn::Color *mTextColor;
- const gcn::Color *mTextColor2;
- const gcn::Color *mBGColor;
- const gcn::Color *mTextBGColor;
+ const Color *mTextColor;
+ const Color *mTextColor2;
+ const Color *mBGColor;
+ const Color *mTextBGColor;
int mPadding;
static int instances;
static float mAlpha;
diff --git a/src/gui/widgets/vertcontainer.cpp b/src/gui/widgets/vertcontainer.cpp
index a91f20657..b86aa3e5f 100644
--- a/src/gui/widgets/vertcontainer.cpp
+++ b/src/gui/widgets/vertcontainer.cpp
@@ -24,10 +24,11 @@
#include "debug.h"
VertContainer::VertContainer(const Widget2 *const widget,
- const int verticalItemSize, const bool resizable,
+ const int verticalItemSize,
+ const bool resizable,
const int leftSpacing) :
Container(widget),
- gcn::WidgetListener(),
+ WidgetListener(),
mResizableWidgets(),
mVerticalItemSize(verticalItemSize),
mCount(0),
@@ -39,12 +40,12 @@ VertContainer::VertContainer(const Widget2 *const widget,
addWidgetListener(this);
}
-void VertContainer::add1(gcn::Widget *const widget, const int spacing)
+void VertContainer::add1(Widget *const widget, const int spacing)
{
add2(widget, mResizable, spacing);
}
-void VertContainer::add2(gcn::Widget *const widget, const bool resizable,
+void VertContainer::add2(Widget *const widget, const bool resizable,
const int spacing)
{
if (!widget)
@@ -79,8 +80,8 @@ void VertContainer::clear()
mResizableWidgets.clear();
}
-void VertContainer::widgetResized(const gcn::Event &event A_UNUSED)
+void VertContainer::widgetResized(const Event &event A_UNUSED)
{
- FOR_EACH (std::vector<gcn::Widget*>::const_iterator, it, mResizableWidgets)
+ 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
index 76f6354dd..05ba2e32f 100644
--- a/src/gui/widgets/vertcontainer.h
+++ b/src/gui/widgets/vertcontainer.h
@@ -24,7 +24,7 @@
#include "gui/widgets/container.h"
-#include <guichan/widgetlistener.hpp>
+#include "listeners/widgetlistener.h"
#include <vector>
@@ -35,26 +35,28 @@
*
* This container places it's contents veritcally.
*/
-class VertContainer final : public Container, public gcn::WidgetListener
+class VertContainer final : public Container,
+ public WidgetListener
{
public:
VertContainer(const Widget2 *const widget,
- const int verticalItemSize, const bool resizable = true,
+ const int verticalItemSize,
+ const bool resizable = true,
const int leftSpacing = 0);
A_DELETE_COPY(VertContainer)
- void add2(gcn::Widget *const widget, const bool resizable,
+ void add2(Widget *const widget, const bool resizable,
const int spacing = -1);
- void add1(gcn::Widget *const widget, const int spacing = -1);
+ void add1(Widget *const widget, const int spacing = -1);
void clear();
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
private:
- std::vector<gcn::Widget*> mResizableWidgets;
+ std::vector<Widget*> mResizableWidgets;
int mVerticalItemSize;
int mCount;
int mNextY;
diff --git a/src/gui/widgets/widget.cpp b/src/gui/widgets/widget.cpp
new file mode 100644
index 000000000..5b2024b1f
--- /dev/null
+++ b/src/gui/widgets/widget.cpp
@@ -0,0 +1,666 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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 "events/actionevent.h"
+
+#include "events/event.h"
+
+#include "gui/focushandler.h"
+
+#include "listeners/actionlistener.h"
+#include "listeners/deathlistener.h"
+#include "listeners/widgetlistener.h"
+
+#include "render/graphics.h"
+
+#include "debug.h"
+
+Font* Widget::mGlobalFont = nullptr;
+std::list<Widget*> Widget::mWidgets;
+std::set<Widget*> Widget::mWidgetsSet;
+
+Widget::Widget(const Widget2 *const widget) :
+ Widget2(widget),
+ mMouseListeners(),
+ mKeyListeners(),
+ mActionListeners(),
+ mDeathListeners(),
+ mFocusListeners(),
+ mWidgetListeners(),
+ mForegroundColor(0x000000),
+ mBackgroundColor(0xffffff),
+ mBaseColor(0x808090),
+ mSelectionColor(0xc3d9ff),
+ mFocusHandler(nullptr),
+ mInternalFocusHandler(nullptr),
+ mParent(nullptr),
+ mDimension(),
+ mFrameSize(0),
+ mActionEventId(),
+ mFocusable(false),
+ mVisible(true),
+ mTabIn(true),
+ mTabOut(true),
+ mEnabled(true),
+ mId(),
+ mCurrentFont(nullptr)
+{
+ mWidgets.push_back(this);
+ mWidgetsSet.insert(this);
+}
+
+Widget::~Widget()
+{
+ for (DeathListenerIterator iter = mDeathListeners.begin();
+ iter != mDeathListeners.end();
+ ++iter)
+ {
+ Event event(this);
+ (*iter)->death(event);
+ }
+
+ _setFocusHandler(nullptr);
+
+ mWidgets.remove(this);
+ mWidgetsSet.erase(this);
+}
+
+void Widget::drawFrame(Graphics* graphics)
+{
+ BLOCK_START("Widget::drawFrame")
+ const Color &faceColor = getBaseColor();
+ Color highlightColor = faceColor + Color(0x303030);
+ Color shadowColor = faceColor - Color(0x303030);
+ const int alpha = getBaseColor().a;
+ const int width = getWidth() + getFrameSize() * 2 - 1;
+ const int height = getHeight() + getFrameSize() * 2 - 1;
+ highlightColor.a = alpha;
+ shadowColor.a = alpha;
+
+ for (unsigned int i = 0; i < getFrameSize(); ++i)
+ {
+ graphics->setColor(shadowColor);
+ graphics->drawLine(i, i, width - i, i);
+ graphics->drawLine(i, i + 1, i, height - i - 1);
+ graphics->setColor(highlightColor);
+ graphics->drawLine(width - i, i + 1, width - i, height - i);
+ graphics->drawLine(i, height - i, width - i - 1, height - i);
+ }
+ BLOCK_END("Widget::drawFrame")
+}
+
+void Widget::_setParent(Widget* parent)
+{
+ mParent = parent;
+}
+
+void Widget::setWidth(int width)
+{
+ Rect newDimension = mDimension;
+ newDimension.width = width;
+
+ setDimension(newDimension);
+}
+
+void Widget::setHeight(int height)
+{
+ Rect newDimension = mDimension;
+ newDimension.height = height;
+
+ setDimension(newDimension);
+}
+
+void Widget::setX(int x)
+{
+ Rect newDimension = mDimension;
+ newDimension.x = x;
+
+ setDimension(newDimension);
+}
+
+void Widget::setY(int y)
+{
+ Rect newDimension = mDimension;
+ newDimension.y = y;
+
+ setDimension(newDimension);
+}
+
+void Widget::setPosition(int x, 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();
+ }
+}
+
+void Widget::setFrameSize(unsigned int frameSize)
+{
+ mFrameSize = frameSize;
+}
+
+unsigned int Widget::getFrameSize() const
+{
+ return mFrameSize;
+}
+
+const Rect& Widget::getDimension() const
+{
+ return mDimension;
+}
+
+const std::string& Widget::getActionEventId() const
+{
+ return mActionEventId;
+}
+
+void Widget::setActionEventId(const std::string& actionEventId)
+{
+ mActionEventId = actionEventId;
+}
+
+bool Widget::isFocused() const
+{
+ if (!mFocusHandler)
+ return false;
+
+ return (mFocusHandler->isFocused(this));
+}
+
+void Widget::setFocusable(bool focusable)
+{
+ if (!focusable && isFocused())
+ {
+ mFocusHandler->focusNone();
+ }
+
+ mFocusable = focusable;
+}
+
+bool Widget::isFocusable() const
+{
+ return mFocusable && isVisible() && isEnabled();
+}
+
+void Widget::requestFocus()
+{
+ if (!mFocusHandler)
+ return;
+
+ if (isFocusable())
+ mFocusHandler->requestFocus(this);
+}
+
+void Widget::requestMoveToTop()
+{
+ if (mParent)
+ mParent->moveToTop(this);
+}
+
+void Widget::requestMoveToBottom()
+{
+ if (mParent)
+ mParent->moveToBottom(this);
+}
+
+void Widget::setVisible(bool visible)
+{
+ if (!visible && isFocused())
+ mFocusHandler->focusNone();
+
+ if (visible)
+ distributeShownEvent();
+ else
+ distributeHiddenEvent();
+
+ mVisible = visible;
+}
+
+void Widget::setBaseColor(const Color& color)
+{
+ mBaseColor = color;
+}
+
+const Color& Widget::getBaseColor() const
+{
+ return mBaseColor;
+}
+
+void Widget::setForegroundColor(const Color& color)
+{
+ mForegroundColor = color;
+}
+
+const Color& Widget::getForegroundColor() const
+{
+ return mForegroundColor;
+}
+
+void Widget::setBackgroundColor(const Color& color)
+{
+ mBackgroundColor = color;
+}
+
+const Color& Widget::getBackgroundColor() const
+{
+ return mBackgroundColor;
+}
+
+void Widget::setSelectionColor(const Color& color)
+{
+ mSelectionColor = color;
+}
+
+const Color& Widget::getSelectionColor() const
+{
+ return mSelectionColor;
+}
+
+void Widget::_setFocusHandler(FocusHandler* focusHandler)
+{
+ if (mFocusHandler)
+ {
+ releaseModalFocus();
+ mFocusHandler->remove(this);
+ }
+
+ if (focusHandler)
+ focusHandler->add(this);
+
+ mFocusHandler = focusHandler;
+}
+
+FocusHandler* Widget::_getFocusHandler()
+{
+ return mFocusHandler;
+}
+
+void Widget::addActionListener(ActionListener* actionListener)
+{
+ mActionListeners.push_back(actionListener);
+}
+
+void Widget::removeActionListener(ActionListener* actionListener)
+{
+ mActionListeners.remove(actionListener);
+}
+
+void Widget::addDeathListener(DeathListener* deathListener)
+{
+ mDeathListeners.push_back(deathListener);
+}
+
+void Widget::removeDeathListener(DeathListener* deathListener)
+{
+ mDeathListeners.remove(deathListener);
+}
+
+void Widget::addKeyListener(KeyListener* keyListener)
+{
+ mKeyListeners.push_back(keyListener);
+}
+
+void Widget::removeKeyListener(KeyListener* keyListener)
+{
+ mKeyListeners.remove(keyListener);
+}
+
+void Widget::addFocusListener(FocusListener* focusListener)
+{
+ mFocusListeners.push_back(focusListener);
+}
+
+void Widget::removeFocusListener(FocusListener* focusListener)
+{
+ mFocusListeners.remove(focusListener);
+}
+
+void Widget::addMouseListener(MouseListener* mouseListener)
+{
+ mMouseListeners.push_back(mouseListener);
+}
+
+void Widget::removeMouseListener(MouseListener* mouseListener)
+{
+ mMouseListeners.remove(mouseListener);
+}
+
+void Widget::addWidgetListener(WidgetListener* widgetListener)
+{
+ mWidgetListeners.push_back(widgetListener);
+}
+
+void Widget::removeWidgetListener(WidgetListener* widgetListener)
+{
+ mWidgetListeners.remove(widgetListener);
+}
+
+void Widget::getAbsolutePosition(int& x, int& y) const
+{
+ if (!mParent)
+ {
+ 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)
+ return mGlobalFont;
+ return mCurrentFont;
+}
+
+void Widget::setGlobalFont(Font* font)
+{
+ mGlobalFont = font;
+
+ for (std::list<Widget*>::const_iterator iter = mWidgets.begin();
+ iter != mWidgets.end(); ++iter)
+ {
+ if (!(*iter)->mCurrentFont)
+ (*iter)->fontChanged();
+ }
+}
+
+void Widget::setFont(Font* font)
+{
+ mCurrentFont = font;
+ fontChanged();
+}
+
+bool Widget::widgetExists(const Widget* widget)
+{
+ return mWidgetsSet.find(const_cast<Widget*>(widget))
+ != mWidgetsSet.end();
+}
+
+bool Widget::isTabInEnabled() const
+{
+ return mTabIn;
+}
+
+void Widget::setTabInEnabled(bool enabled)
+{
+ mTabIn = enabled;
+}
+
+bool Widget::isTabOutEnabled() const
+{
+ return mTabOut;
+}
+
+void Widget::setTabOutEnabled(bool enabled)
+{
+ mTabOut = enabled;
+}
+
+void Widget::setSize(int width, int height)
+{
+ Rect newDimension = mDimension;
+ newDimension.width = width;
+ newDimension.height = height;
+
+ setDimension(newDimension);
+}
+
+void Widget::setEnabled(bool enabled)
+{
+ mEnabled = enabled;
+}
+
+bool Widget::isEnabled() const
+{
+ return mEnabled && isVisible();
+}
+
+void Widget::requestModalFocus()
+{
+ if (!mFocusHandler)
+ return;
+
+ mFocusHandler->requestModalFocus(this);
+}
+
+void Widget::requestModalMouseInputFocus()
+{
+ if (!mFocusHandler)
+ return;
+
+ mFocusHandler->requestModalMouseInputFocus(this);
+}
+
+void Widget::releaseModalFocus()
+{
+ if (!mFocusHandler)
+ return;
+
+ mFocusHandler->releaseModalFocus(this);
+}
+
+void Widget::releaseModalMouseInputFocus()
+{
+ if (!mFocusHandler)
+ return;
+
+ mFocusHandler->releaseModalMouseInputFocus(this);
+}
+
+bool Widget::isModalFocused() const
+{
+ if (!mFocusHandler)
+ return false;
+
+ if (mParent)
+ {
+ return (mFocusHandler->getModalFocused() == this)
+ || mParent->isModalFocused();
+ }
+
+ return mFocusHandler->getModalFocused() == this;
+}
+
+bool Widget::isModalMouseInputFocused() const
+{
+ if (!mFocusHandler)
+ return false;
+
+ if (mParent)
+ {
+ return (mFocusHandler->getModalMouseInputFocused() == this)
+ || mParent->isModalMouseInputFocused();
+ }
+
+ return mFocusHandler->getModalMouseInputFocused() == this;
+}
+
+Widget *Widget::getWidgetAt(int x A_UNUSED, int y A_UNUSED)
+{
+ return nullptr;
+}
+
+const std::list<MouseListener*>& Widget::_getMouseListeners()
+{
+ return mMouseListeners;
+}
+
+const std::list<KeyListener*>& Widget::_getKeyListeners()
+{
+ return mKeyListeners;
+}
+
+const std::list<FocusListener*>& Widget::_getFocusListeners()
+{
+ return mFocusListeners;
+}
+
+Rect Widget::getChildrenArea()
+{
+ return Rect(0, 0, 0, 0);
+}
+
+FocusHandler* Widget::_getInternalFocusHandler()
+{
+ return mInternalFocusHandler;
+}
+
+void Widget::setInternalFocusHandler(FocusHandler* focusHandler)
+{
+ mInternalFocusHandler = focusHandler;
+}
+
+void Widget::distributeResizedEvent()
+{
+ for (WidgetListenerIterator iter = mWidgetListeners.begin();
+ iter != mWidgetListeners.end();
+ ++ iter)
+ {
+ Event event(this);
+ (*iter)->widgetResized(event);
+ }
+}
+
+void Widget::distributeMovedEvent()
+{
+ for (WidgetListenerIterator iter = mWidgetListeners.begin();
+ iter != mWidgetListeners.end();
+ ++ iter)
+ {
+ Event event(this);
+ (*iter)->widgetMoved(event);
+ }
+}
+
+void Widget::distributeHiddenEvent()
+{
+ for (WidgetListenerIterator iter = mWidgetListeners.begin();
+ iter != mWidgetListeners.end();
+ ++ iter)
+ {
+ Event event(this);
+ (*iter)->widgetHidden(event);
+ }
+}
+
+void Widget::distributeActionEvent()
+{
+ for (ActionListenerIterator iter = mActionListeners.begin();
+ iter != mActionListeners.end();
+ ++iter)
+ {
+ ActionEvent actionEvent(this, mActionEventId);
+ (*iter)->action(actionEvent);
+ }
+}
+
+void Widget::distributeShownEvent()
+{
+ for (WidgetListenerIterator iter = mWidgetListeners.begin();
+ iter != mWidgetListeners.end();
+ ++iter)
+ {
+ Event event(this);
+ (*iter)->widgetShown(event);
+ }
+}
+
+void Widget::showPart(Rect rectangle)
+{
+ if (mParent)
+ mParent->showWidgetPart(this, rectangle);
+}
diff --git a/src/gui/widgets/widget.h b/src/gui/widgets/widget.h
new file mode 100644
index 000000000..17f016c76
--- /dev/null
+++ b/src/gui/widgets/widget.h
@@ -0,0 +1,1230 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* _______ __ __ __ ______ __ __ _______ __ __
+ * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
+ * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
+ * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
+ * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
+ * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
+ * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
+ *
+ * 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 <list>
+#include <set>
+#include <string>
+
+#include "gui/color.h"
+#include "gui/rect.h"
+
+#include "gui/widgets/widget2.h"
+
+#include "localconsts.h"
+
+class ActionListener;
+class DeathListener;
+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.
+ * @since 0.1.0
+ */
+class Widget : public Widget2
+{
+ public:
+ /**
+ * 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.
+ * @since 0.1.0
+ */
+ virtual void draw(Graphics* graphics) = 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
+ * @since 0.8.0
+ */
+ virtual void drawFrame(Graphics* graphics);
+
+ /**
+ * 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
+ * @since 0.8.0
+ */
+ void setFrameSize(unsigned int 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
+ * @since 0.8.0
+ */
+ unsigned int getFrameSize() const A_WARN_UNUSED;
+
+ /**
+ * 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
+ * @since 0.1.0
+ */
+ virtual void logic()
+ { }
+
+ /**
+ * Gets the widget's parent container.
+ *
+ * @return The widget's parent container. NULL if the widget
+ * has no parent.
+ * @since 0.1.0
+ */
+ virtual Widget* getParent() const 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
+ * @since 0.1.0
+ */
+ void setWidth(int width);
+
+ /**
+ * Gets the width of the widget.
+ *
+ * @return The width of the widget.
+ * @see setWidth, setHeight, getHeight, setSize,
+ * setDimension, getDimension
+ * @since 0.1.0
+ */
+ int getWidth() const 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
+ * @since 0.1.0
+ */
+ void setHeight(int height);
+
+ /**
+ * Gets the height of the widget.
+ *
+ * @return The height of the widget.
+ * @see setHeight, setWidth, getWidth, setSize,
+ * setDimension, getDimension
+ * @since 0.1.0
+ */
+ int getHeight() const 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
+ * @since 0.1.0
+ */
+ void setSize(int width, 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
+ * @since 0.1.0
+ */
+ void setX(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
+ * @since 0.1.0
+ */
+ int getX() const 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
+ * @since 0.1.0
+ */
+ void setY(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
+ * @since 0.1.0
+ */
+ int getY() const 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
+ * @since 0.1.0
+ */
+ void setPosition(int x, 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
+ * @since 0.1.0
+ */
+ 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
+ * @since 0.1.0
+ */
+ const Rect& getDimension() const A_WARN_UNUSED;
+
+ /**
+ * Sets the widget to be fosusable, or not.
+ *
+ * @param focusable True if the widget should be focusable,
+ * false otherwise.
+ * @see isFocusable
+ * @since 0.1.0
+ */
+ void setFocusable(bool focusable);
+
+ /**
+ * Checks if a widget is focsable.
+ *
+ * @return True if the widget should be focusable, false otherwise.
+ * @see setFocusable
+ * @since 0.1.0
+ */
+ bool isFocusable() const A_WARN_UNUSED;
+
+ /**
+ * Checks if the widget is focused.
+ *
+ * @return True if the widget is focused, false otherwise.
+ * @since 0.1.0
+ */
+ 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
+ * @since 0.1.0
+ */
+ void setEnabled(bool 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
+ * @since 0.1.0
+ */
+ 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
+ * @since 0.1.0
+ */
+ void setVisible(bool visible);
+
+ /**
+ * Checks if the widget is visible.
+ *
+ * @return True if widget is be visible, false otherwise.
+ * @see setVisible
+ * @since 0.1.0
+ */
+ bool isVisible() const A_WARN_UNUSED
+ { return mVisible && (!mParent || mParent->isVisible()); }
+
+ /**
+ * Sets the base color of the widget.
+ *
+ * @param color The baseground color.
+ * @see getBaseColor
+ * @since 0.1.0
+ */
+ void setBaseColor(const Color& color);
+
+ /**
+ * Gets the base color.
+ *
+ * @return The base color.
+ * @see setBaseColor
+ * @since 0.1.0
+ */
+ const Color& getBaseColor() const A_WARN_UNUSED;
+
+ /**
+ * Sets the foreground color.
+ *
+ * @param color The foreground color.
+ * @see getForegroundColor
+ * @since 0.1.0
+ */
+ void setForegroundColor(const Color& color);
+
+ /**
+ * Gets the foreground color.
+ *
+ * @see setForegroundColor
+ * @since 0.1.0
+ */
+ const Color& getForegroundColor() const A_WARN_UNUSED;
+
+ /**
+ * Sets the background color.
+ *
+ * @param color The background Color.
+ * @see setBackgroundColor
+ * @since 0.1.0
+ */
+ void setBackgroundColor(const Color& color);
+
+ /**
+ * Gets the background color.
+ *
+ * @see setBackgroundColor
+ * @since 0.1.0
+ */
+ const Color& getBackgroundColor() const A_WARN_UNUSED;
+
+ /**
+ * Sets the selection color.
+ *
+ * @param color The selection color.
+ * @see getSelectionColor
+ * @since 0.6.0
+ */
+ void setSelectionColor(const Color& color);
+
+ /**
+ * Gets the selection color.
+ *
+ * @return The selection color.
+ * @see setSelectionColor
+ * @since 0.6.0
+ */
+ const Color& getSelectionColor() const A_WARN_UNUSED;
+
+ /**
+ * 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
+ * @since 0.1.0
+ */
+ virtual void _setFocusHandler(FocusHandler* 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
+ * @since 0.1.0
+ */
+ virtual FocusHandler* _getFocusHandler() A_WARN_UNUSED;
+
+ /**
+ * 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
+ * @since 0.1.0
+ */
+ void addActionListener(ActionListener* actionListener);
+
+ /**
+ * Removes an added action listener from the widget.
+ *
+ * @param actionListener The action listener to remove.
+ * @see addActionListener
+ * @since 0.1.0
+ */
+ void removeActionListener(ActionListener* 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
+ * @since 0.1.0
+ */
+ void addDeathListener(DeathListener* deathListener);
+
+ /**
+ * Removes an added death listener from the widget.
+ *
+ * @param deathListener The death listener to remove.
+ * @see addDeathListener
+ * @since 0.1.0
+ */
+ void removeDeathListener(DeathListener* 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
+ * @since 0.1.0
+ */
+ void addMouseListener(MouseListener* mouseListener);
+
+ /**
+ * Removes an added mouse listener from the widget.
+ *
+ * @param mouseListener The mouse listener to remove.
+ * @see addMouseListener
+ * @since 0.1.0
+ */
+ void removeMouseListener(MouseListener* 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
+ * @since 0.1.0
+ */
+ void addKeyListener(KeyListener* keyListener);
+
+ /**
+ * Removes an added key listener from the widget.
+ *
+ * @param keyListener The key listener to remove.
+ * @see addKeyListener
+ * @since 0.1.0
+ */
+ void removeKeyListener(KeyListener* 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
+ * @since 0.7.0
+ */
+ void addFocusListener(FocusListener* focusListener);
+
+ /**
+ * Removes an added focus listener from the widget.
+ *
+ * @param focusListener The focus listener to remove.
+ * @see addFocusListener
+ * @since 0.7.0
+ */
+ void removeFocusListener(FocusListener* 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
+ * @since 0.8.0
+ */
+ void addWidgetListener(WidgetListener* widgetListener);
+
+ /**
+ * Removes an added widget listener from the widget.
+ *
+ * @param widgetListener The widget listener to remove.
+ * @see addWidgetListener
+ * @since 0.8.0
+ */
+ void removeWidgetListener(WidgetListener* 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
+ * @since 0.6.0
+ */
+ void setActionEventId(const std::string& actionEventId);
+
+ /**
+ * Gets the action event identifier of the widget.
+ *
+ * @return The action event identifier of the widget.
+ * @see setActionEventId
+ * @since 0.6.0
+ */
+ const std::string& getActionEventId() const;
+
+ /**
+ * 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.
+ * @since 0.1.0
+ */
+ 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
+ * @since 0.1.0
+ */
+ virtual void _setParent(Widget* 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
+ * @since 0.1.0
+ */
+ Font *getFont() const A_WARN_UNUSED;
+
+ /**
+ * Sets the global font to be used by default for all widgets.
+ *
+ * @param font The global font.
+ * @see getGlobalFont
+ * @since 0.1.0
+ */
+ static void setGlobalFont(Font* font);
+
+ /**
+ * 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
+ * @since 0.1.0
+ */
+ void setFont(Font* 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.
+ *
+ * @since 0.1.0
+ */
+ 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.
+ * @since 0.1.0
+ */
+ static bool widgetExists(const Widget* 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
+ * @since 0.1.0
+ */
+ bool isTabInEnabled() const A_WARN_UNUSED;
+
+ /**
+ * 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
+ * @since 0.1.0
+ */
+ void setTabInEnabled(bool 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
+ * @since 0.1.0
+ */
+ bool isTabOutEnabled() const A_WARN_UNUSED;
+
+ /**
+ * 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
+ * @since 0.1.0
+ */
+ void setTabOutEnabled(bool 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
+ * @since 0.4.0
+ */
+ virtual 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
+ * @since 0.6.0
+ */
+ virtual void requestModalMouseInputFocus();
+
+ /**
+ * Releases modal focus. Modal focus will only be released if the
+ * widget has modal focus.
+ *
+ * @see requestModalFocus, isModalFocused
+ * @since 0.4.0
+ */
+ 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
+ * @since 0.6.0
+ */
+ 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
+ * @since 0.8.0
+ */
+ 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
+ * @since 0.8.0
+ */
+ 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.
+ * @since 0.6.0
+ */
+ virtual Widget *getWidgetAt(int x, int y) A_WARN_UNUSED;
+
+ /**
+ * Gets the mouse listeners of the widget.
+ *
+ * @return The mouse listeners of the widget.
+ * @since 0.6.0
+ */
+ virtual const std::list<MouseListener*>& _getMouseListeners()
+ A_WARN_UNUSED;
+
+ /**
+ * Gets the key listeners of the widget.
+ *
+ * @return The key listeners of the widget.
+ * @since 0.6.0
+ */
+ virtual const std::list<KeyListener*>& _getKeyListeners()
+ A_WARN_UNUSED;
+
+ /**
+ * Gets the focus listeners of the widget.
+ *
+ * @return The focus listeners of the widget.
+ * @since 0.7.0
+ */
+ virtual const std::list<FocusListener*>& _getFocusListeners()
+ 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
+ * @since 0.1.0
+ */
+ 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
+ * @since 0.1.0
+ */
+ 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
+ * @since 0.1.0
+ */
+ void setInternalFocusHandler(FocusHandler* 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
+ * @since 0.1.0
+ */
+ 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
+ * @since 0.1.0
+ */
+ virtual void moveToBottom(Widget* widget A_UNUSED)
+ { }
+
+ /**
+ * Focuses the next widget in the widget.
+ *
+ * @see moveToBottom
+ * @since 0.1.0
+ */
+ virtual void focusNext()
+ { }
+
+ /**
+ * Focuses the previous widget in the widget.
+ *
+ * @see moveToBottom
+ * @since 0.1.0
+ */
+ 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.
+ * @since 0.1.0
+ */
+ virtual void showWidgetPart(Widget* widget A_UNUSED,
+ 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, BasicContainer::findWidgetById
+ * @since 0.8.0
+ */
+ void setId(const std::string& id)
+ { mId = id; }
+
+ /**
+ * Gets the 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 setId, BasicContainer::findWidgetById
+ * @since 0.8.0
+ */
+ const std::string& getId() const 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.
+ * @since 0.8.0
+ */
+ virtual void showPart(Rect rectangle);
+
+ protected:
+ /**
+ * Distributes an action event to all action listeners
+ * of the widget.
+ *
+ * @since 0.8.0
+ */
+ void distributeActionEvent();
+
+ /**
+ * Distributes resized events to all of the widget's listeners.
+ *
+ * @since 0.8.0
+ */
+ void distributeResizedEvent();
+
+ /**
+ * Distributes moved events to all of the widget's listeners.
+ *
+ * @since 0.8.0
+ */
+ void distributeMovedEvent();
+
+ /**
+ * Distributes hidden events to all of the widget's listeners.
+ *
+ * @since 0.8.0
+ * @author Olof Naessén
+ */
+ void distributeHiddenEvent();
+
+ /**
+ * Distributes shown events to all of the widget's listeners.
+ *
+ * @since 0.8.0
+ * @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<DeathListener*> DeathListenerList;
+
+ /**
+ * Holds the death listeners of the widget.
+ */
+ DeathListenerList mDeathListeners;
+
+ /**
+ * Typdef.
+ */
+ typedef DeathListenerList::iterator DeathListenerIterator;
+
+ /**
+ * 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 selection color of the widget.
+ */
+ Color mSelectionColor;
+
+ /**
+ * 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 dimension of the widget.
+ */
+ Rect mDimension;
+
+ /**
+ * Holds the frame size of the widget.
+ */
+ unsigned int mFrameSize;
+
+ /**
+ * Holds the action event of the widget.
+ */
+ std::string mActionEventId;
+
+ /**
+ * True if the widget focusable, false otherwise.
+ */
+ bool mFocusable;
+
+ /**
+ * True if the widget visible, false otherwise.
+ */
+ bool mVisible;
+
+ /**
+ * 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;
+
+ /**
+ * Holds the id of the widget.
+ */
+ std::string mId;
+
+ /**
+ * Holds the font used by the widget.
+ */
+ Font* mCurrentFont;
+
+ /**
+ * Holds the global font used by the widget.
+ */
+ static Font* mGlobalFont;
+
+ /**
+ * Holds a list of all instances of widgets.
+ */
+ static std::list<Widget*> mWidgets;
+
+ static std::set<Widget*> mWidgetsSet;
+};
+
+#endif // GUI_WIDGETS_WIDGET_H
diff --git a/src/gui/widgets/widget2.h b/src/gui/widgets/widget2.h
index f6e94556a..ff565815f 100644
--- a/src/gui/widgets/widget2.h
+++ b/src/gui/widgets/widget2.h
@@ -21,7 +21,6 @@
#ifndef GUI_WIDGETS_WIDGET2_H
#define GUI_WIDGETS_WIDGET2_H
-#include "gui/gui.h"
#include "gui/theme.h"
#include "render/renderers.h"
@@ -33,16 +32,16 @@ class Widget2
{
}
- inline const gcn::Color &getThemeColor(const int type,
- const int alpha = 255)
- const A_WARN_UNUSED
+ inline const Color &getThemeColor(const int type,
+ const int alpha = 255)
+ const A_WARN_UNUSED
{
return Theme::getThemeColor(mPaletteOffset + type, alpha);
}
- inline const gcn::Color &getThemeCharColor(const signed char c,
- bool &valid)
- const A_WARN_UNUSED
+ inline const Color &getThemeCharColor(const signed char c,
+ bool &valid)
+ const A_WARN_UNUSED
{
const int colorId = Theme::getThemeIdByChar(c, valid);
if (valid)
@@ -72,18 +71,12 @@ class Widget2
}
}
- void setForegroundColor2(const gcn::Color &color)
+ void setForegroundColor2(const Color &color)
{
mForegroundColor2 = color;
}
protected:
- Widget2() :
- mPaletteOffset(0),
- mForegroundColor2()
- {
- }
-
explicit Widget2(const Widget2 *const widget) :
mPaletteOffset(widget ? widget->mPaletteOffset : 0),
mForegroundColor2()
@@ -92,7 +85,7 @@ class Widget2
}
int mPaletteOffset;
- gcn::Color mForegroundColor2;
+ Color mForegroundColor2;
};
extern RenderType openGLMode;
diff --git a/src/gui/widgets/widgetgroup.cpp b/src/gui/widgets/widgetgroup.cpp
index 34cbeebb5..07c4df43c 100644
--- a/src/gui/widgets/widgetgroup.cpp
+++ b/src/gui/widgets/widgetgroup.cpp
@@ -23,11 +23,12 @@
#include "debug.h"
WidgetGroup::WidgetGroup(const Widget2 *const widget,
- const std::string &group, const int height,
+ const std::string &group,
+ const int height,
const int spacing) :
Container(widget),
- gcn::WidgetListener(),
- gcn::ActionListener(),
+ WidgetListener(),
+ ActionListener(),
mSpacing(spacing),
mCount(0),
mGroup(group),
@@ -57,7 +58,7 @@ void WidgetGroup::addButton(const std::string &restrict text,
}
}
-void WidgetGroup::action(const gcn::ActionEvent &event)
+void WidgetGroup::action(const ActionEvent &event)
{
for (ActionListenerIterator iter = mActionListeners.begin();
iter != mActionListeners.end(); ++iter)
@@ -66,7 +67,7 @@ void WidgetGroup::action(const gcn::ActionEvent &event)
}
}
-void WidgetGroup::add(gcn::Widget *const widget, const int spacing)
+void WidgetGroup::add(Widget *const widget, const int spacing)
{
if (!widget)
return;
@@ -84,6 +85,6 @@ void WidgetGroup::clear()
mCount = 0;
}
-void WidgetGroup::widgetResized(const gcn::Event &event A_UNUSED)
+void WidgetGroup::widgetResized(const Event &event A_UNUSED)
{
}
diff --git a/src/gui/widgets/widgetgroup.h b/src/gui/widgets/widgetgroup.h
index 3d63b02f8..051234cda 100644
--- a/src/gui/widgets/widgetgroup.h
+++ b/src/gui/widgets/widgetgroup.h
@@ -23,14 +23,14 @@
#include "gui/widgets/container.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/widgetlistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/widgetlistener.h"
#include "localconsts.h"
class WidgetGroup : public Container,
- public gcn::WidgetListener,
- public gcn::ActionListener
+ public WidgetListener,
+ public ActionListener
{
public:
A_DELETE_COPY(WidgetGroup)
@@ -40,21 +40,22 @@ class WidgetGroup : public Container,
virtual void addButton(const std::string &restrict text,
const std::string &restrict tag);
- void action(const gcn::ActionEvent &event) override;
+ void action(const ActionEvent &event) override;
- virtual void add(gcn::Widget *const widget,
+ virtual void add(Widget *const widget,
const int spacing);
virtual void clear();
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
virtual Widget *createWidget(const std::string &name)
const A_WARN_UNUSED = 0;
protected:
WidgetGroup(const Widget2 *const widget,
- const std::string &group, const int height,
+ const std::string &group,
+ const int height,
const int spacing);
int mSpacing;
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 36372dcaa..ec83af9a8 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -20,6 +20,49 @@
* 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"
@@ -29,6 +72,8 @@
#include "soundconsts.h"
#include "soundmanager.h"
+#include "gui/focushandler.h"
+#include "gui/font.h"
#include "gui/gui.h"
#include "gui/viewport.h"
@@ -37,10 +82,6 @@
#include "resources/cursor.h"
#include "resources/image.h"
-#include <guichan/exception.hpp>
-#include <guichan/focushandler.hpp>
-#include <guichan/font.hpp>
-
#include "debug.h"
const int resizeMask = 8 + 4 + 2 + 1;
@@ -50,9 +91,17 @@ int Window::mouseResize = 0;
Window::Window(const std::string &caption, const bool modal,
Window *const parent, std::string skin) :
- gcn::Window(caption),
- Widget2(),
- gcn::WidgetListener(),
+ gcn::Container(nullptr),
+ MouseListener(),
+ WidgetListener(),
+ mCaption(caption),
+ mAlignment(Graphics::CENTER),
+ mPadding(2),
+ mTitleBarHeight(16),
+ mMovable(true),
+ mDragOffsetX(0),
+ mDragOffsetY(0),
+ mMoved(false),
mSkin(nullptr),
mDefaultX(0),
mDefaultY(0),
@@ -74,7 +123,7 @@ Window::Window(const std::string &caption, const bool modal,
mVertexes(new ImageCollection),
mCaptionOffsetX(7),
mCaptionOffsetY(5),
- mCaptionAlign(gcn::Graphics::LEFT),
+ mCaptionAlign(Graphics::LEFT),
mTitlePadding(4),
mGripPadding(2),
mResizeHandles(-1),
@@ -92,16 +141,11 @@ Window::Window(const std::string &caption, const bool modal,
{
logger->log("Window::Window(\"%s\")", caption.c_str());
-#ifndef USE_INTERNALGUICHAN
- mDragOffsetX = 0;
- mDragOffsetY = 0;
-#endif
-
- if (!windowContainer)
- throw GCN_EXCEPTION("Window::Window(): no windowContainer set");
-
windowInstances++;
+// mFrameSize = 1;
+ addMouseListener(this);
+
setFrameSize(0);
setPadding(3);
setTitleBarHeight(20);
@@ -119,7 +163,7 @@ Window::Window(const std::string &caption, const bool modal,
{
setPadding(mSkin->getPadding());
if (getOptionBool("titlebarBold"))
- mCaptionFont = reinterpret_cast<gcn::Font*>(boldFont);
+ mCaptionFont = boldFont;
mTitlePadding = mSkin->getTitlePadding();
mGripPadding = getOption("resizePadding");
mCaptionOffsetX = getOption("captionoffsetx");
@@ -128,12 +172,12 @@ Window::Window(const std::string &caption, const bool modal,
mCaptionOffsetY = getOption("captionoffsety");
if (!mCaptionOffsetY)
mCaptionOffsetY = 5;
- mCaptionAlign = static_cast<gcn::Graphics::Alignment>(
+ mCaptionAlign = static_cast<Graphics::Alignment>(
getOption("captionalign"));
- if (mCaptionAlign < gcn::Graphics::LEFT
- || mCaptionAlign > gcn::Graphics::RIGHT)
+ if (mCaptionAlign < Graphics::LEFT
+ || mCaptionAlign > Graphics::RIGHT)
{
- mCaptionAlign = gcn::Graphics::LEFT;
+ mCaptionAlign = Graphics::LEFT;
}
setTitleBarHeight(getOption("titlebarHeight"));
if (!mTitleBarHeight)
@@ -147,7 +191,8 @@ Window::Window(const std::string &caption, const bool modal,
}
// Add this window to the window container
- windowContainer->add(this);
+ if (windowContainer)
+ windowContainer->add(this);
if (mModal)
{
@@ -208,13 +253,12 @@ void Window::setWindowContainer(WindowContainer *const wc)
windowContainer = wc;
}
-void Window::draw(gcn::Graphics *graphics)
+void Window::draw(Graphics *graphics)
{
if (!mSkin)
return;
BLOCK_START("Window::draw")
- Graphics *const g = static_cast<Graphics*>(graphics);
bool update = false;
if (isBatchDrawRenders(openGLMode))
@@ -230,8 +274,11 @@ void Window::draw(gcn::Graphics *graphics)
mRedraw = false;
update = true;
mVertexes->clear();
- g->calcWindow(mVertexes, 0, 0, mDimension.width,
- mDimension.height, mSkin->getBorder());
+ graphics->calcWindow(mVertexes,
+ 0, 0,
+ mDimension.width,
+ mDimension.height,
+ mSkin->getBorder());
// Draw Close Button
if (mCloseWindowButton)
@@ -240,8 +287,10 @@ void Window::draw(gcn::Graphics *graphics)
mResizeHandles == CLOSE);
if (button)
{
- g->calcTileCollection(mVertexes, button,
- mCloseRect.x, mCloseRect.y);
+ graphics->calcTileCollection(mVertexes,
+ button,
+ mCloseRect.x,
+ mCloseRect.y);
}
}
// Draw Sticky Button
@@ -250,27 +299,33 @@ void Window::draw(gcn::Graphics *graphics)
const Image *const button = mSkin->getStickyImage(mSticky);
if (button)
{
- g->calcTileCollection(mVertexes, button,
- mStickyRect.x, mStickyRect.y);
+ graphics->calcTileCollection(mVertexes,
+ button,
+ mStickyRect.x,
+ mStickyRect.y);
}
}
if (mGrip)
{
- g->calcTileCollection(mVertexes, mGrip,
- mGripRect.x, mGripRect.y);
+ graphics->calcTileCollection(mVertexes,
+ mGrip,
+ mGripRect.x,
+ mGripRect.y);
}
}
else
{
mLastRedraw = false;
}
- g->drawTileCollection(mVertexes);
+ graphics->drawTileCollection(mVertexes);
}
else
{
- g->drawImageRect(0, 0, mDimension.width,
- mDimension.height, mSkin->getBorder());
+ graphics->drawImageRect(0, 0,
+ mDimension.width,
+ mDimension.height,
+ mSkin->getBorder());
// Draw Close Button
if (mCloseWindowButton)
@@ -278,24 +333,24 @@ void Window::draw(gcn::Graphics *graphics)
const Image *const button = mSkin->getCloseImage(
mResizeHandles == CLOSE);
if (button)
- g->drawImage2(button, mCloseRect.x, mCloseRect.y);
+ graphics->drawImage(button, mCloseRect.x, mCloseRect.y);
}
// Draw Sticky Button
if (mStickyButton)
{
const Image *const button = mSkin->getStickyImage(mSticky);
if (button)
- g->drawImage2(button, mStickyRect.x, mStickyRect.y);
+ graphics->drawImage(button, mStickyRect.x, mStickyRect.y);
}
if (mGrip)
- g->drawImage2(mGrip, mGripRect.x, mGripRect.y);
+ graphics->drawImage(mGrip, mGripRect.x, mGripRect.y);
}
// Draw title
if (mShowTitle)
{
- g->setColorAll(mForegroundColor, mForegroundColor2);
+ graphics->setColorAll(mForegroundColor, mForegroundColor2);
int x;
switch (mCaptionAlign)
{
@@ -310,14 +365,14 @@ void Window::draw(gcn::Graphics *graphics)
x = mCaptionOffsetX - mCaptionFont->getWidth(mCaption);
break;
}
- mCaptionFont->drawString(g, mCaption, x, mCaptionOffsetY);
+ mCaptionFont->drawString(graphics, mCaption, x, mCaptionOffsetY);
}
if (update)
{
- g->setRedraw(update);
+ graphics->setRedraw(update);
drawChildren(graphics);
- g->setRedraw(false);
+ graphics->setRedraw(false);
}
else
{
@@ -343,7 +398,7 @@ void Window::setContentSize(int width, int height)
setSize(width, height);
}
-void Window::setLocationRelativeTo(const gcn::Widget *const widget)
+void Window::setLocationRelativeTo(const Widget *const widget)
{
if (!widget)
return;
@@ -360,7 +415,7 @@ void Window::setLocationRelativeTo(const gcn::Widget *const widget)
- mDimension.height) / 2 - y));
}
-void Window::setLocationHorisontallyRelativeTo(const gcn::Widget *const widget)
+void Window::setLocationHorisontallyRelativeTo(const Widget *const widget)
{
if (!widget)
return;
@@ -485,9 +540,9 @@ void Window::setResizable(const bool r)
}
}
-void Window::widgetResized(const gcn::Event &event A_UNUSED)
+void Window::widgetResized(const Event &event A_UNUSED)
{
- const gcn::Rectangle area = getChildrenArea();
+ const Rect area = getChildrenArea();
if (mGrip)
{
@@ -549,12 +604,12 @@ void Window::widgetResized(const gcn::Event &event A_UNUSED)
mRedraw = true;
}
-void Window::widgetMoved(const gcn::Event& event A_UNUSED)
+void Window::widgetMoved(const Event& event A_UNUSED)
{
mRedraw = true;
}
-void Window::widgetHidden(const gcn::Event &event A_UNUSED)
+void Window::widgetHidden(const Event &event A_UNUSED)
{
if (gui)
gui->setCursorType(Cursor::CURSOR_POINTER);
@@ -608,25 +663,21 @@ void Window::setVisible(const bool visible, const bool forceSticky)
// Check if the window is off screen...
if (visible)
- {
ensureOnScreen();
- }
else
- {
mResizeHandles = 0;
- }
if (mStickyButtonLock)
- gcn::Window::setVisible(visible);
+ gcn::Container::setVisible(visible);
else
- gcn::Window::setVisible((!forceSticky && mSticky) || visible);
+ gcn::Container::setVisible((!forceSticky && mSticky) || visible);
if (visible)
{
if (mPlayVisibleSound)
soundManager.playGuiSound(SOUND_SHOW_WINDOW);
if (gui)
{
- gcn::MouseEvent *const event = reinterpret_cast<gcn::MouseEvent*>(
+ MouseEvent *const event = reinterpret_cast<MouseEvent*>(
gui->createMouseEvent(this));
if (event)
{
@@ -653,12 +704,19 @@ void Window::scheduleDelete()
windowContainer->scheduleDelete(this);
}
-void Window::mousePressed(gcn::MouseEvent &event)
+void Window::mousePressed(MouseEvent &event)
{
- // Let Guichan move window to top and figure out title bar drag
- gcn::Window::mousePressed(event);
+ if (event.getSource() == this)
+ {
+ if (getParent())
+ getParent()->moveToTop(this);
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ mDragOffsetX = event.getX();
+ mDragOffsetY = event.getY();
+ mMoved = event.getY() <= static_cast<int>(mTitleBarHeight);
+ }
+
+ if (event.getButton() == MouseEvent::LEFT)
{
const int x = event.getX();
const int y = event.getY();
@@ -696,7 +754,7 @@ void Window::close()
setVisible(false);
}
-void Window::mouseReleased(gcn::MouseEvent &event A_UNUSED)
+void Window::mouseReleased(MouseEvent &event A_UNUSED)
{
if (mGrip && mouseResize)
{
@@ -705,22 +763,21 @@ void Window::mouseReleased(gcn::MouseEvent &event A_UNUSED)
gui->setCursorType(Cursor::CURSOR_POINTER);
}
- // This should be the responsibility of Guichan (and is from 0.8.0 on)
mMoved = false;
}
-void Window::mouseEntered(gcn::MouseEvent &event)
+void Window::mouseEntered(MouseEvent &event)
{
updateResizeHandler(event);
}
-void Window::mouseExited(gcn::MouseEvent &event A_UNUSED)
+void Window::mouseExited(MouseEvent &event A_UNUSED)
{
if (mGrip && !mouseResize && gui)
gui->setCursorType(Cursor::CURSOR_POINTER);
}
-void Window::updateResizeHandler(gcn::MouseEvent &event)
+void Window::updateResizeHandler(MouseEvent &event)
{
if (!gui)
return;
@@ -755,7 +812,7 @@ void Window::updateResizeHandler(gcn::MouseEvent &event)
}
}
-void Window::mouseMoved(gcn::MouseEvent &event)
+void Window::mouseMoved(MouseEvent &event)
{
updateResizeHandler(event);
if (viewport)
@@ -767,12 +824,20 @@ bool Window::canMove() const
return !mStickyButtonLock || !mSticky;
}
-void Window::mouseDragged(gcn::MouseEvent &event)
+void Window::mouseDragged(MouseEvent &event)
{
if (canMove())
{
- // Let Guichan handle title bar drag
- gcn::Window::mouseDragged(event);
+ if (!event.isConsumed() && event.getSource() == this)
+ {
+ if (isMovable() && mMoved)
+ {
+ setPosition(event.getX() - mDragOffsetX + getX(),
+ event.getY() - mDragOffsetY + getY());
+ }
+
+ event.consume();
+ }
}
else
{
@@ -794,7 +859,7 @@ void Window::mouseDragged(gcn::MouseEvent &event)
{
const int dx = event.getX() - mDragOffsetX;
const int dy = event.getY() - mDragOffsetY;
- gcn::Rectangle newDim = getDimension();
+ Rect newDim = getDimension();
if (mouseResize & (TOP | BOTTOM))
{
@@ -1080,10 +1145,10 @@ void Window::adjustSizeToScreen()
if (mDimension.height > screenHeight)
mDimension.height = screenHeight;
if (oldWidth != mDimension.width || oldHeight != mDimension.height)
- widgetResized(gcn::Event(this));
+ widgetResized(Event(this));
}
-int Window::getResizeHandles(const gcn::MouseEvent &event)
+int Window::getResizeHandles(const MouseEvent &event)
{
if (event.getX() < 0 || event.getY() < 0)
return 0;
@@ -1120,7 +1185,7 @@ int Window::getResizeHandles(const gcn::MouseEvent &event)
return resizeHandles;
}
-bool Window::isResizeAllowed(const gcn::MouseEvent &event) const
+bool Window::isResizeAllowed(const MouseEvent &event) const
{
const int y = event.getY();
@@ -1165,7 +1230,7 @@ void Window::clearLayout()
}
}
-LayoutCell &Window::place(const int x, const int y, gcn::Widget *const wg,
+LayoutCell &Window::place(const int x, const int y, Widget *const wg,
const int w, const int h)
{
add(wg);
@@ -1192,7 +1257,7 @@ void Window::redraw()
{
if (mLayout)
{
- const gcn::Rectangle area = getChildrenArea();
+ const Rect area = getChildrenArea();
int w = area.width;
int h = area.height;
mLayout->reflow(w, h);
@@ -1228,12 +1293,12 @@ void Window::ensureOnScreen()
mDimension.y = 0;
}
-gcn::Rectangle Window::getWindowArea() const
+Rect Window::getWindowArea() const
{
- return gcn::Rectangle(mPadding,
- mPadding,
- mDimension.width - mPadding * 2,
- mDimension.height - mPadding * 2);
+ return Rect(mPadding,
+ mPadding,
+ mDimension.width - mPadding * 2,
+ mDimension.height - mPadding * 2);
}
int Window::getOption(const std::string &name, const int def) const
@@ -1255,6 +1320,37 @@ bool Window::getOptionBool(const std::string &name, const bool def) const
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()
{
diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h
index bb0f19bb3..6369990bb 100644
--- a/src/gui/widgets/window.h
+++ b/src/gui/widgets/window.h
@@ -20,16 +20,58 @@
* 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 "render/graphics.h"
-#include "gui/widgets/widget2.h"
+#include "listeners/mouselistener.h"
+#include "listeners/widgetlistener.h"
-#include <guichan/widgetlistener.hpp>
-
-#include <guichan/widgets/window.hpp>
+#include "gui/base/widgets/container.hpp"
#include "localconsts.h"
@@ -46,9 +88,9 @@ class WindowContainer;
*
* \ingroup GUI
*/
-class Window : public gcn::Window,
- public Widget2,
- private gcn::WidgetListener
+class Window : public gcn::Container,
+ public MouseListener,
+ private WidgetListener
{
public:
/**
@@ -80,7 +122,7 @@ class Window : public gcn::Window,
/**
* Draws the window.
*/
- void draw(gcn::Graphics *graphics) override;
+ void draw(Graphics *graphics) override;
/**
* Sets the size of this window.
@@ -90,12 +132,12 @@ class Window : public gcn::Window,
/**
* Sets the location relative to the given widget.
*/
- void setLocationRelativeTo(const gcn::Widget *const widget);
+ void setLocationRelativeTo(const Widget *const widget);
/**
* Sets the location relative to the given widget (only horisontally)
*/
- void setLocationHorisontallyRelativeTo(const gcn::Widget
+ void setLocationHorisontallyRelativeTo(const Widget
*const widget);
/**
@@ -114,14 +156,14 @@ class Window : public gcn::Window,
/**
* Called whenever the widget changes size.
*/
- virtual void widgetResized(const gcn::Event &event) override;
+ virtual void widgetResized(const Event &event) override;
- virtual void widgetMoved(const gcn::Event& event) override;
+ virtual void widgetMoved(const Event& event) override;
/**
* Called whenever the widget is hidden.
*/
- virtual void widgetHidden(const gcn::Event &event) override;
+ virtual void widgetHidden(const Event &event) override;
/**
* Sets whether or not the window has a close button.
@@ -257,35 +299,35 @@ class Window : public gcn::Window,
/**
* Starts window resizing when appropriate.
*/
- void mousePressed(gcn::MouseEvent &event) override;
+ void mousePressed(MouseEvent &event) override;
/**
* Implements window resizing and makes sure the window is not
* dragged/resized outside of the screen.
*/
- void mouseDragged(gcn::MouseEvent &event) override;
+ void mouseDragged(MouseEvent &event) override;
/**
* Implements custom cursor image changing context, based on mouse
* relative position.
*/
- void mouseMoved(gcn::MouseEvent &event) override;
+ 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(gcn::MouseEvent &event) override;
+ 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(gcn::MouseEvent &event) override;
+ void mouseExited(MouseEvent &event) override;
- void mouseEntered(gcn::MouseEvent &event) override;
+ void mouseEntered(MouseEvent &event) override;
- void updateResizeHandler(gcn::MouseEvent &event);
+ void updateResizeHandler(MouseEvent &event);
/**
* Sets the name of the window. This is not the window title.
@@ -373,7 +415,7 @@ class Window : public gcn::Window,
/**
* Adds a widget to the window and sets it at given cell.
*/
- LayoutCell &place(const int x, const int y, gcn::Widget *const wg,
+ LayoutCell &place(const int x, const int y, Widget *const wg,
const int w = 1, const int h = 1);
/**
@@ -408,11 +450,11 @@ class Window : public gcn::Window,
*/
int getGuiAlpha() const A_WARN_UNUSED;
- gcn::Rectangle getWindowArea() const A_WARN_UNUSED;
+ Rect getWindowArea() const A_WARN_UNUSED;
- bool isResizeAllowed(const gcn::MouseEvent &event) const A_WARN_UNUSED;
+ bool isResizeAllowed(const MouseEvent &event) const A_WARN_UNUSED;
- void setCaptionFont(gcn::Font *font)
+ void setCaptionFont(Font *font)
{ mCaptionFont = font; }
void enableVisibleSound(bool b)
@@ -421,6 +463,105 @@ class Window : public gcn::Window,
bool isWindowVisible() const A_WARN_UNUSED
{ return mVisible; }
+ /**
+ * 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(unsigned 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
+ */
+ unsigned 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()
+ { 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; }
+
+ /**
+ * 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(bool 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; }
+
+ virtual Rect getChildrenArea();
+
+ /**
+ * Resizes the window to fit the content.
+ */
+ virtual void resizeToContent();
+
#ifdef USE_PROFILER
virtual void logic();
#endif
@@ -440,6 +581,50 @@ class Window : public gcn::Window,
int getTitlePadding() const 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.
+ */
+ unsigned int mPadding;
+
+ /**
+ * Holds the title bar height of the window.
+ */
+ unsigned int mTitleBarHeight;
+
+ /**
+ * True if the window is movable, false otherwise.
+ */
+ bool 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 */
@@ -474,14 +659,14 @@ class Window : public gcn::Window,
*
* @see ResizeHandles
*/
- int getResizeHandles(const gcn::MouseEvent &event) A_WARN_UNUSED;
+ int getResizeHandles(const MouseEvent &event) A_WARN_UNUSED;
Image *mGrip; /**< Resize grip */
Window *mParent; /**< The parent window */
Layout *mLayout; /**< Layout handler */
- gcn::Rectangle mCloseRect; /**< Close button rectangle */
- gcn::Rectangle mStickyRect; /**< Sticky button rectangle */
- gcn::Rectangle mGripRect; /**< Resize grip rectangle */
+ Rect mCloseRect; /**< Close button rectangle */
+ Rect mStickyRect; /**< Sticky button rectangle */
+ Rect mGripRect; /**< Resize grip rectangle */
std::string mWindowName; /**< Name of the window */
int mMinWinWidth; /**< Minimum window width */
int mMinWinHeight; /**< Minimum window height */
@@ -501,12 +686,12 @@ class Window : public gcn::Window,
ImageCollection *mVertexes;
int mCaptionOffsetX;
int mCaptionOffsetY;
- gcn::Graphics::Alignment mCaptionAlign;
+ Graphics::Alignment mCaptionAlign;
int mTitlePadding;
int mGripPadding;
int mResizeHandles;
int mOldResizeHandles;
- gcn::Font *mCaptionFont;
+ Font *mCaptionFont;
bool mShowTitle; /**< Window has a title bar */
bool mModal; /**< Window is modal */
bool mCloseWindowButton; /**< Window has a close button */
diff --git a/src/gui/widgets/windowcontainer.cpp b/src/gui/widgets/windowcontainer.cpp
index d23f29bad..a9b556410 100644
--- a/src/gui/widgets/windowcontainer.cpp
+++ b/src/gui/widgets/windowcontainer.cpp
@@ -42,7 +42,7 @@ void WindowContainer::slowLogic()
mDeathList.clear();
}
-void WindowContainer::scheduleDelete(gcn::Widget *const widget)
+void WindowContainer::scheduleDelete(Widget *const widget)
{
if (widget)
mDeathList.push_back(widget);
@@ -58,8 +58,8 @@ void WindowContainer::adjustAfterResize(const int oldScreenWidth,
}
}
-void WindowContainer::moveWidgetAfter(gcn::Widget *const after,
- gcn::Widget *const widget)
+void WindowContainer::moveWidgetAfter(Widget *const after,
+ Widget *const widget)
{
const WidgetListIterator widgetIter = std::find(
mWidgets.begin(), mWidgets.end(), widget);
@@ -79,7 +79,7 @@ void WindowContainer::moveWidgetAfter(gcn::Widget *const after,
}
#ifdef USE_PROFILER
-void WindowContainer::draw(gcn::Graphics* graphics)
+void WindowContainer::draw(Graphics* graphics)
{
BLOCK_START("WindowContainer::draw")
Container::draw(graphics);
diff --git a/src/gui/widgets/windowcontainer.h b/src/gui/widgets/windowcontainer.h
index 2ee4ea37d..a822fadb5 100644
--- a/src/gui/widgets/windowcontainer.h
+++ b/src/gui/widgets/windowcontainer.h
@@ -44,7 +44,7 @@ class WindowContainer : public Container
* Schedule a widget for deletion. It will be deleted at the start of
* the next logic update.
*/
- void scheduleDelete(gcn::Widget *const widget);
+ void scheduleDelete(Widget *const widget);
/**
* Ensures that all visible windows are on the screen after the screen
@@ -53,18 +53,18 @@ class WindowContainer : public Container
void adjustAfterResize(const int oldScreenWidth,
const int oldScreenHeight);
- void moveWidgetAfter(gcn::Widget *const before,
- gcn::Widget *const widget);
+ void moveWidgetAfter(Widget *const before,
+ Widget *const widget);
#ifdef USE_PROFILER
- void draw(gcn::Graphics* graphics);
+ void draw(Graphics* graphics);
#endif
private:
/**
* List of widgets that are scheduled to be deleted.
*/
- typedef std::vector<gcn::Widget*> Widgets;
+ typedef std::vector<Widget*> Widgets;
typedef Widgets::iterator WidgetIterator;
Widgets mDeathList;
};
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index a094b5b08..795f2ad5a 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -31,9 +31,8 @@
#include "gui/popups/textpopup.h"
#include "gui/windows/skilldialog.h"
-#ifdef MANASERV_SUPPORT
-#include "gui/specialswindow.h"
-#endif
+
+#include "gui/widgets/button.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -44,9 +43,9 @@
WindowMenu::WindowMenu(const Widget2 *const widget) :
Container(widget),
- gcn::ActionListener(),
- gcn::SelectionListener(),
- gcn::MouseListener(),
+ ActionListener(),
+ SelectionListener(),
+ MouseListener(),
mSkin(Theme::instance() ? Theme::instance()->load("windowmenu.xml", "")
: nullptr),
mPadding(mSkin ? mSkin->getPadding() : 1),
@@ -109,15 +108,6 @@ WindowMenu::WindowMenu(const Widget2 *const widget) :
_("Skills"), x, h, Input::KEY_WINDOW_SKILL);
}
-#ifdef MANASERV_SUPPORT
- if (Net::getNetworkType() == ServerInfo::MANASERV)
- {
- // TRANSLATORS: short button name for specials window.
- addButton(N_("SPE"),
- _("Specials"), x, h, Input::KEY_NO_VALUE);
- }
-#endif
-
// TRANSLATORS: short button name for social window.
addButton(N_("SOC"),
// TRANSLATORS: full button name
@@ -166,7 +156,7 @@ WindowMenu::WindowMenu(const Widget2 *const widget) :
x += mPadding - mSpacing;
if (mainGraphics)
- setDimension(gcn::Rectangle(mainGraphics->mWidth - x, 0, x, h));
+ setDimension(Rect(mainGraphics->mWidth - x, 0, x, h));
loadButtons();
@@ -213,7 +203,7 @@ WindowMenu::~WindowMenu()
}
}
-void WindowMenu::action(const gcn::ActionEvent &event)
+void WindowMenu::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
@@ -248,12 +238,12 @@ void WindowMenu::addButton(const char *const text,
mButtonTexts.push_back(new ButtonText(description, key));
}
-void WindowMenu::mousePressed(gcn::MouseEvent &event)
+void WindowMenu::mousePressed(MouseEvent &event)
{
if (!viewport)
return;
- if (!mSmallWindow && event.getButton() == gcn::MouseEvent::RIGHT)
+ if (!mSmallWindow && event.getButton() == MouseEvent::RIGHT)
{
Button *const btn = dynamic_cast<Button*>(event.getSource());
if (!btn)
@@ -266,7 +256,7 @@ void WindowMenu::mousePressed(gcn::MouseEvent &event)
}
}
-void WindowMenu::mouseMoved(gcn::MouseEvent &event)
+void WindowMenu::mouseMoved(MouseEvent &event)
{
mHaveMouse = true;
@@ -291,7 +281,7 @@ void WindowMenu::mouseMoved(gcn::MouseEvent &event)
const int x = event.getX();
const int y = event.getY();
const int key = btn->getTag();
- const gcn::Rectangle &rect = mDimension;
+ const Rect &rect = mDimension;
if (key != Input::KEY_NO_VALUE)
{
mTextPopup->show(x + rect.x, y + rect.y, btn->getDescription(),
@@ -305,7 +295,7 @@ void WindowMenu::mouseMoved(gcn::MouseEvent &event)
}
}
-void WindowMenu::mouseExited(gcn::MouseEvent& mouseEvent A_UNUSED)
+void WindowMenu::mouseExited(MouseEvent& mouseEvent A_UNUSED)
{
mHaveMouse = false;
if (!mTextPopup)
@@ -348,7 +338,7 @@ void WindowMenu::updateButtons()
}
x += mPadding - mSpacing;
if (mainGraphics)
- setDimension(gcn::Rectangle(mainGraphics->mWidth - x, 0, x, h));
+ setDimension(Rect(mainGraphics->mWidth - x, 0, x, h));
}
void WindowMenu::loadButtons()
@@ -419,7 +409,7 @@ void WindowMenu::saveButtons() const
config.deleteKey("windowmenu" + toString(f));
}
-void WindowMenu::drawChildren(gcn::Graphics* graphics)
+void WindowMenu::drawChildren(Graphics* graphics)
{
if (mHaveMouse || !mAutoHide || (mAutoHide == 1
&& mainGraphics && (mSmallWindow || mainGraphics->mWidth > 800)))
diff --git a/src/gui/windowmenu.h b/src/gui/windowmenu.h
index 38ee090a7..a1ed66a7d 100644
--- a/src/gui/windowmenu.h
+++ b/src/gui/windowmenu.h
@@ -23,21 +23,21 @@
#ifndef GUI_WINDOWMENU_H
#define GUI_WINDOWMENU_H
-#include "configlistener.h"
+#include "listeners/configlistener.h"
#include "gui/widgets/container.h"
-#include "gui/widgets/button.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/selectionlistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/mouselistener.h"
+#include "listeners/selectionlistener.h"
#include "localconsts.h"
#include <map>
#include <vector>
+class Button;
class TextPopup;
-class Window;
struct ButtonInfo final
{
@@ -77,9 +77,9 @@ struct ButtonText final
*/
class WindowMenu final : public Container,
public ConfigListener,
- public gcn::ActionListener,
- public gcn::SelectionListener,
- public gcn::MouseListener
+ public ActionListener,
+ public SelectionListener,
+ public MouseListener
{
public:
explicit WindowMenu(const Widget2 *const widget);
@@ -88,13 +88,13 @@ class WindowMenu final : public Container,
~WindowMenu();
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
- void mousePressed(gcn::MouseEvent &event) override final;
+ void mousePressed(MouseEvent &event) override final;
- void mouseMoved(gcn::MouseEvent &event) override final;
+ void mouseMoved(MouseEvent &event) override final;
- void mouseExited(gcn::MouseEvent& mouseEvent A_UNUSED) override final;
+ void mouseExited(MouseEvent& mouseEvent A_UNUSED) override final;
std::map <std::string, ButtonInfo*> &getButtonNames() A_WARN_UNUSED
{ return mButtonNames; }
@@ -118,7 +118,7 @@ class WindowMenu final : public Container,
#endif
protected:
- void drawChildren(gcn::Graphics* graphics) override final;
+ void drawChildren(Graphics* graphics) override final;
private:
inline void addButton(const char *const text,
diff --git a/src/gui/windows/botcheckerwindow.cpp b/src/gui/windows/botcheckerwindow.cpp
index b94093ebb..d1fc0e7bd 100644
--- a/src/gui/windows/botcheckerwindow.cpp
+++ b/src/gui/windows/botcheckerwindow.cpp
@@ -101,7 +101,7 @@ public:
freeWidgets();
mPlayers.clear();
if (actorManager && botCheckerWindow
- && botCheckerWindow->mEnabled)
+ && botCheckerWindow->mBotcheckerEnabled)
{
std::set<ActorSprite*> beings = actorManager->getAll();
FOR_EACH (ActorSprites::iterator, i, beings)
@@ -125,7 +125,7 @@ public:
continue;
const Being *const player = mPlayers.at(r);
- gcn::Widget *widget = new Label(this, player->getName());
+ Widget *widget = new Label(this, player->getName());
mWidgets.push_back(widget);
@@ -235,14 +235,14 @@ public:
{
}
- gcn::Widget *getElementAt(const int row, const int column) const
+ Widget *getElementAt(const int row, const int column) const
{
return mWidgets[WIDGET_AT(row, column)];
}
void freeWidgets()
{
- for (std::vector<gcn::Widget *>::const_iterator it = mWidgets.begin();
+ for (std::vector<Widget *>::const_iterator it = mWidgets.begin();
it != mWidgets.end(); ++it)
{
delete *it;
@@ -253,17 +253,17 @@ public:
protected:
std::vector<Being*> mPlayers;
- std::vector<gcn::Widget*> mWidgets;
+ std::vector<Widget*> mWidgets;
};
BotCheckerWindow::BotCheckerWindow():
// TRANSLATORS: bot checker window header
Window(_("Bot Checker"), false, nullptr, "botchecker.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mTableModel(new UsersTableModel(this)),
mTable(new GuiTable(this, mTableModel)),
- playersScrollArea(new ScrollArea(mTable, true,
+ playersScrollArea(new ScrollArea(this, mTable, true,
"bochecker_background.xml")),
mPlayerTableTitleModel(new StaticTableModel(1, COLUMNS_NR)),
mPlayerTitleTable(new GuiTable(this, mPlayerTableTitleModel)),
@@ -271,7 +271,7 @@ BotCheckerWindow::BotCheckerWindow():
mIncButton(new Button(this, _("Reset"), "reset", this)),
mLastUpdateTime(0),
mNeedUpdate(false),
- mEnabled(false)
+ mBotcheckerEnabled(false)
{
const int w = 500;
const int h = 250;
@@ -346,7 +346,7 @@ BotCheckerWindow::BotCheckerWindow():
enableVisibleSound(true);
config.addListener("enableBotCheker", this);
- mEnabled = config.getBoolValue("enableBotCheker");
+ mBotcheckerEnabled = config.getBoolValue("enableBotCheker");
}
BotCheckerWindow::~BotCheckerWindow()
@@ -358,7 +358,7 @@ BotCheckerWindow::~BotCheckerWindow()
void BotCheckerWindow::slowLogic()
{
BLOCK_START("BotCheckerWindow::slowLogic")
- if (mEnabled && mTableModel)
+ if (mBotcheckerEnabled && mTableModel)
{
const unsigned int nowTime = cur_time;
if (nowTime - mLastUpdateTime > 5 && mNeedUpdate)
@@ -377,7 +377,7 @@ void BotCheckerWindow::slowLogic()
BLOCK_END("BotCheckerWindow::slowLogic")
}
-void BotCheckerWindow::action(const gcn::ActionEvent &event)
+void BotCheckerWindow::action(const ActionEvent &event)
{
if (event.getId() == "reset")
{
@@ -417,7 +417,7 @@ void BotCheckerWindow::reset()
void BotCheckerWindow::optionChanged(const std::string &name)
{
if (name == "enableBotCheker")
- mEnabled = config.getBoolValue("enableBotCheker");
+ mBotcheckerEnabled = config.getBoolValue("enableBotCheker");
}
#ifdef USE_PROFILER
diff --git a/src/gui/windows/botcheckerwindow.h b/src/gui/windows/botcheckerwindow.h
index d3615957d..0c86b13b0 100644
--- a/src/gui/windows/botcheckerwindow.h
+++ b/src/gui/windows/botcheckerwindow.h
@@ -23,11 +23,11 @@
#ifndef GUI_BOTCHECKERWINDOW_H
#define GUI_BOTCHECKERWINDOW_H
-#include "configlistener.h"
+#include "listeners/configlistener.h"
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
struct BOTCHK final
{
@@ -43,7 +43,7 @@ class UsersTableModel;
class StaticTableModel;
class BotCheckerWindow final : public Window,
- public gcn::ActionListener,
+ public ActionListener,
public ConfigListener
{
public:
@@ -61,7 +61,7 @@ class BotCheckerWindow final : public Window,
*/
~BotCheckerWindow();
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void update();
@@ -86,7 +86,7 @@ class BotCheckerWindow final : public Window,
Button *mIncButton;
int mLastUpdateTime;
bool mNeedUpdate;
- bool mEnabled;
+ bool mBotcheckerEnabled;
};
extern BotCheckerWindow *botCheckerWindow;
diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp
index cfefa8159..c2514a15d 100644
--- a/src/gui/windows/buydialog.cpp
+++ b/src/gui/windows/buydialog.cpp
@@ -28,13 +28,15 @@
#include "gui/windows/tradewindow.h"
+#include "gui/models/shopitems.h"
+#include "gui/models/sortlistmodelbuy.h"
+
#include "gui/widgets/button.h"
#include "gui/widgets/dropdown.h"
#include "gui/widgets/inttextfield.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layout.h"
#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/shopitems.h"
#include "gui/widgets/shoplistbox.h"
#include "gui/widgets/slider.h"
@@ -51,41 +53,6 @@
#include "debug.h"
-static const char *const SORT_NAME_BUY[7] =
-{
- // TRANSLATORS: buy dialog sort type.
- N_("unsorted"),
- // TRANSLATORS: buy dialog sort type.
- N_("by price"),
- // TRANSLATORS: buy dialog sort type.
- N_("by name"),
- // TRANSLATORS: buy dialog sort type.
- N_("by id"),
- // TRANSLATORS: buy dialog sort type.
- N_("by weight"),
- // TRANSLATORS: buy dialog sort type.
- N_("by amount"),
- // TRANSLATORS: buy dialog sort type.
- N_("by type")
-};
-
-class SortListModelBuy final : public gcn::ListModel
-{
-public:
- ~SortListModelBuy()
- { }
-
- int getNumberOfElements()
- { return 7; }
-
- std::string getElementAt(int i)
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
- return gettext(SORT_NAME_BUY[i]);
- }
-};
-
class SortItemPriceFunctor final
{
public:
@@ -193,8 +160,8 @@ BuyDialog::DialogList BuyDialog::instances;
BuyDialog::BuyDialog() :
// TRANSLATORS: buy dialog name
Window(_("Create items"), false, nullptr, "buy.xml"),
- gcn::ActionListener(),
- gcn::SelectionListener(),
+ ActionListener(),
+ SelectionListener(),
mNpcId(-2), mMoney(0), mAmountItems(0), mMaxItems(0), mNick(),
mSortModel(nullptr),
mSortDropDown(nullptr)
@@ -205,8 +172,8 @@ BuyDialog::BuyDialog() :
BuyDialog::BuyDialog(const int npcId) :
// TRANSLATORS: buy dialog name
Window(_("Buy"), false, nullptr, "buy.xml"),
- gcn::ActionListener(),
- gcn::SelectionListener(),
+ ActionListener(),
+ SelectionListener(),
mNpcId(npcId), mMoney(0), mAmountItems(0), mMaxItems(0), mNick(),
mSortModel(nullptr),
mSortDropDown(nullptr)
@@ -217,8 +184,8 @@ BuyDialog::BuyDialog(const int npcId) :
BuyDialog::BuyDialog(std::string nick) :
// TRANSLATORS: buy dialog name
Window(_("Buy"), false, nullptr, "buy.xml"),
- gcn::ActionListener(),
- gcn::SelectionListener(),
+ ActionListener(),
+ SelectionListener(),
mNpcId(-1), mMoney(0), mAmountItems(0), mMaxItems(0), mNick(nick),
mSortModel(new SortListModelBuy),
mSortDropDown(new DropDown(this, mSortModel, false, false, this, "sort"))
@@ -240,14 +207,14 @@ void BuyDialog::init()
mShopItemList = new ShopListBox(this, mShopItems, mShopItems);
mShopItemList->postInit();
- mScrollArea = new ScrollArea(mShopItemList,
+ mScrollArea = new ScrollArea(this, mShopItemList,
getOptionBool("showbackground"), "buy_background.xml");
mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
- mSlider = new Slider(1.0);
+ mSlider = new Slider(this, 1.0);
mQuantityLabel = new Label(this, strprintf(
"%d / %d", mAmountItems, mMaxItems));
- mQuantityLabel->setAlignment(gcn::Graphics::CENTER);
+ mQuantityLabel->setAlignment(Graphics::CENTER);
// TRANSLATORS: buy dialog label
mMoneyLabel = new Label(this, strprintf(
_("Price: %s / Total: %s"), "", ""));
@@ -388,7 +355,7 @@ void BuyDialog::sort()
}
}
-void BuyDialog::action(const gcn::ActionEvent &event)
+void BuyDialog::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "quit")
@@ -482,7 +449,7 @@ void BuyDialog::action(const gcn::ActionEvent &event)
}
}
-void BuyDialog::valueChanged(const gcn::SelectionEvent &event A_UNUSED)
+void BuyDialog::valueChanged(const SelectionEvent &event A_UNUSED)
{
// Reset amount of items and update labels
mAmountItems = 1;
diff --git a/src/gui/windows/buydialog.h b/src/gui/windows/buydialog.h
index e11317cde..aa163d5d0 100644
--- a/src/gui/windows/buydialog.h
+++ b/src/gui/windows/buydialog.h
@@ -25,8 +25,8 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/selectionlistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/selectionlistener.h"
class Button;
class DropDown;
@@ -35,7 +35,6 @@ class ShopListBox;
class SortListModelBuy;
class IntTextField;
class Label;
-class ListBox;
class ScrollArea;
class Slider;
@@ -45,8 +44,8 @@ class Slider;
* \ingroup Interface
*/
class BuyDialog final : public Window,
- public gcn::ActionListener,
- public gcn::SelectionListener
+ public ActionListener,
+ public SelectionListener
{
public:
/**
@@ -98,7 +97,7 @@ class BuyDialog final : public Window,
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Returns the number of items in the shop inventory.
@@ -108,7 +107,7 @@ class BuyDialog final : public Window,
/**
* Updates the labels according to the selected item.
*/
- void valueChanged(const gcn::SelectionEvent &event) override final;
+ void valueChanged(const SelectionEvent &event) override final;
/**
* Updates the state of buttons and labels.
diff --git a/src/gui/windows/buyselldialog.cpp b/src/gui/windows/buyselldialog.cpp
index 22f39f449..92f6503bb 100644
--- a/src/gui/windows/buyselldialog.cpp
+++ b/src/gui/windows/buyselldialog.cpp
@@ -37,7 +37,7 @@ BuySellDialog::DialogList BuySellDialog::dialogInstances;
BuySellDialog::BuySellDialog(const int npcId) :
// TRANSLATORS: shop window name
Window(_("Shop"), false, nullptr, "buysell.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mNpcId(npcId),
mNick(""),
mBuyButton(nullptr)
@@ -48,7 +48,7 @@ BuySellDialog::BuySellDialog(const int npcId) :
BuySellDialog::BuySellDialog(const std::string &nick) :
// TRANSLATORS: shop window name
Window(_("Shop"), false, nullptr, "buysell.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mNpcId(-1),
mNick(nick),
mBuyButton(nullptr)
@@ -119,7 +119,7 @@ void BuySellDialog::setVisible(bool visible)
}
}
-void BuySellDialog::action(const gcn::ActionEvent &event)
+void BuySellDialog::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "Buy")
diff --git a/src/gui/windows/buyselldialog.h b/src/gui/windows/buyselldialog.h
index 34a716ee1..a89ff0bea 100644
--- a/src/gui/windows/buyselldialog.h
+++ b/src/gui/windows/buyselldialog.h
@@ -25,7 +25,7 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
class Button;
@@ -34,7 +34,8 @@ class Button;
*
* \ingroup Interface
*/
-class BuySellDialog final : public Window, public gcn::ActionListener
+class BuySellDialog final : public Window,
+ public ActionListener
{
public:
/**
@@ -58,7 +59,7 @@ class BuySellDialog final : public Window, public gcn::ActionListener
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Returns true if any instances exist.
diff --git a/src/gui/windows/changeemaildialog.cpp b/src/gui/windows/changeemaildialog.cpp
index a9f3b3449..b8f9c1fd2 100644
--- a/src/gui/windows/changeemaildialog.cpp
+++ b/src/gui/windows/changeemaildialog.cpp
@@ -45,7 +45,7 @@
ChangeEmailDialog::ChangeEmailDialog(LoginData *const data):
// TRANSLATORS: change email dialog header
Window(_("Change Email Address"), true, nullptr, "changeemail.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mFirstEmailField(new TextField(this)),
mSecondEmailField(new TextField(this)),
// TRANSLATORS: button in change email dialog
@@ -109,7 +109,7 @@ ChangeEmailDialog::~ChangeEmailDialog()
mWrongDataNoticeListener = nullptr;
}
-void ChangeEmailDialog::action(const gcn::ActionEvent &event)
+void ChangeEmailDialog::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "cancel")
diff --git a/src/gui/windows/changeemaildialog.h b/src/gui/windows/changeemaildialog.h
index 31ffa7b39..d2928025d 100644
--- a/src/gui/windows/changeemaildialog.h
+++ b/src/gui/windows/changeemaildialog.h
@@ -25,7 +25,7 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
class Button;
class LoginData;
@@ -37,7 +37,8 @@ class WrongDataNoticeListener;
*
* \ingroup Interface
*/
-class ChangeEmailDialog final : public Window, public gcn::ActionListener
+class ChangeEmailDialog final : public Window,
+ public ActionListener
{
public:
/**
@@ -57,7 +58,7 @@ class ChangeEmailDialog final : public Window, public gcn::ActionListener
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* This is used to pass the pointer to where the new email should be
diff --git a/src/gui/windows/changepassworddialog.cpp b/src/gui/windows/changepassworddialog.cpp
index 4646947fa..05c7a9309 100644
--- a/src/gui/windows/changepassworddialog.cpp
+++ b/src/gui/windows/changepassworddialog.cpp
@@ -46,7 +46,7 @@
ChangePasswordDialog::ChangePasswordDialog(LoginData *const data):
// TRANSLATORS: change password window name
Window(_("Change Password"), true, nullptr, "changepassword.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mOldPassField(new PasswordField(this)),
mFirstPassField(new PasswordField(this)),
mSecondPassField(new PasswordField(this)),
@@ -88,7 +88,7 @@ ChangePasswordDialog::~ChangePasswordDialog()
mWrongDataNoticeListener = nullptr;
}
-void ChangePasswordDialog::action(const gcn::ActionEvent &event)
+void ChangePasswordDialog::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "cancel")
diff --git a/src/gui/windows/changepassworddialog.h b/src/gui/windows/changepassworddialog.h
index ce45e6f47..adbaf109a 100644
--- a/src/gui/windows/changepassworddialog.h
+++ b/src/gui/windows/changepassworddialog.h
@@ -25,7 +25,7 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
class Button;
class LoginData;
@@ -37,7 +37,8 @@ class WrongDataNoticeListener;
*
* \ingroup Interface
*/
-class ChangePasswordDialog final : public Window, public gcn::ActionListener
+class ChangePasswordDialog final : public Window,
+ public ActionListener
{
public:
/**
@@ -57,7 +58,7 @@ class ChangePasswordDialog final : public Window, public gcn::ActionListener
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
private:
TextField *mOldPassField;
diff --git a/src/gui/windows/charcreatedialog.cpp b/src/gui/windows/charcreatedialog.cpp
index cbce28db7..a877f45e0 100644
--- a/src/gui/windows/charcreatedialog.cpp
+++ b/src/gui/windows/charcreatedialog.cpp
@@ -24,12 +24,14 @@
#include "main.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
#include "gui/windows/okdialog.h"
#include "gui/widgets/button.h"
+#include "gui/windows/charselectdialog.h"
#include "gui/widgets/label.h"
#include "gui/widgets/playerbox.h"
#include "gui/widgets/radiobutton.h"
@@ -63,8 +65,8 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent,
const int slot) :
// TRANSLATORS: char create dialog name
Window(_("New Character"), true, parent, "charcreate.xml"),
- gcn::ActionListener(),
- gcn::KeyListener(),
+ ActionListener(),
+ KeyListener(),
mCharSelectDialog(parent),
mNameField(new TextField(this, "")),
// TRANSLATORS: char create dialog label
@@ -123,7 +125,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent,
mMaxLook(CharDB::getMaxLook()),
mPlayer(new Being(0, ActorSprite::PLAYER, static_cast<uint16_t>(mRace),
nullptr)),
- mPlayerBox(new PlayerBox(mPlayer, "charcreate_playerbox.xml",
+ mPlayerBox(new PlayerBox(this, mPlayer, "charcreate_playerbox.xml",
"charcreate_selectedplayerbox.xml")),
mHairStyle(0),
mHairColor(0),
@@ -206,13 +208,13 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent,
const int h = 350;
setContentSize(w, h);
- mPlayerBox->setDimension(gcn::Rectangle(360, 0, 110, 90));
+ mPlayerBox->setDimension(Rect(360, 0, 110, 90));
mActionButton->setPosition(385, 100);
mRotateButton->setPosition(415, 100);
mNameLabel->setPosition(5, 2);
mNameField->setDimension(
- gcn::Rectangle(60, 2, 300, mNameField->getHeight()));
+ Rect(60, 2, 300, mNameField->getHeight()));
const int leftX = 120;
const int rightX = 300;
@@ -318,16 +320,12 @@ CharCreateDialog::~CharCreateDialog()
Net::getCharServerHandler()->setCharCreateDialog(nullptr);
}
-void CharCreateDialog::action(const gcn::ActionEvent &event)
+void CharCreateDialog::action(const ActionEvent &event)
{
const std::string id = event.getId();
if (id == "create")
{
- if (
-#ifdef MANASERV_SUPPORT
- Net::getNetworkType() == ServerInfo::MANASERV ||
-#endif
- getName().length() >= 4)
+ if (getName().length() >= 4)
{
// Attempt to create the character
mCreateButton->setEnabled(false);
@@ -339,14 +337,7 @@ void CharCreateDialog::action(const gcn::ActionEvent &event)
mAttributeSlider[i]->getValue()));
}
-#ifdef MANASERV_SUPPORT
- int characterSlot = mSlot;
- // On Manaserv, the slots start at 1, so we offset them.
- if (Net::getNetworkType() == ServerInfo::MANASERV)
- ++characterSlot;
-#else
const int characterSlot = mSlot;
-#endif
Net::getCharServerHandler()->newCharacter(getName(), characterSlot,
mFemale->isSelected(), mHairStyle, mHairColor,
@@ -527,8 +518,8 @@ void CharCreateDialog::setAttributes(const StringVect &labels,
mAttributeLabel[i]->adjustSize();
add(mAttributeLabel[i]);
- mAttributeSlider[i] = new Slider(min, max);
- mAttributeSlider[i]->setDimension(gcn::Rectangle(140, y + i * 24,
+ mAttributeSlider[i] = new Slider(this, min, max);
+ mAttributeSlider[i]->setDimension(Rect(140, y + i * 24,
150, 12));
mAttributeSlider[i]->setActionEventId("statslider");
mAttributeSlider[i]->addActionListener(this);
@@ -664,14 +655,14 @@ void CharCreateDialog::updatePlayer()
}
}
-void CharCreateDialog::keyPressed(gcn::KeyEvent &keyEvent)
+void CharCreateDialog::keyPressed(KeyEvent &keyEvent)
{
- const int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int actionId = keyEvent.getActionId();
switch (actionId)
{
case Input::KEY_GUI_CANCEL:
keyEvent.consume();
- action(gcn::ActionEvent(mCancelButton,
+ action(ActionEvent(mCancelButton,
mCancelButton->getActionEventId()));
break;
diff --git a/src/gui/windows/charcreatedialog.h b/src/gui/windows/charcreatedialog.h
index 0d73bf805..12ddf7970 100644
--- a/src/gui/windows/charcreatedialog.h
+++ b/src/gui/windows/charcreatedialog.h
@@ -25,11 +25,13 @@
#include "being/being.h"
-#include "gui/windows/charselectdialog.h"
+#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/keylistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/keylistener.h"
+class Button;
+class CharSelectDialog;
class Label;
class PlayerBox;
class RadioButton;
@@ -42,8 +44,8 @@ class TextField;
* \ingroup Interface
*/
class CharCreateDialog final : public Window,
- public gcn::ActionListener,
- public gcn::KeyListener
+ public ActionListener,
+ public KeyListener
{
public:
/**
@@ -58,7 +60,7 @@ class CharCreateDialog final : public Window,
*/
~CharCreateDialog();
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Unlocks the dialog, enabling the create character button again.
@@ -76,7 +78,7 @@ class CharCreateDialog final : public Window,
void updatePlayer();
- void keyPressed(gcn::KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &keyEvent) override final;
private:
int getDistributedPoints() const A_WARN_UNUSED;
diff --git a/src/gui/windows/charselectdialog.cpp b/src/gui/windows/charselectdialog.cpp
index 3f44617f8..4480f06af 100644
--- a/src/gui/windows/charselectdialog.cpp
+++ b/src/gui/windows/charselectdialog.cpp
@@ -26,8 +26,9 @@
#include "configuration.h"
#include "units.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
#include "gui/windows/charcreatedialog.h"
#include "gui/windows/confirmdialog.h"
@@ -43,6 +44,7 @@
#include "net/logindata.h"
#include "net/loginhandler.h"
+#include "net/net.h"
#include "utils/gettext.h"
@@ -70,7 +72,7 @@ class CharDeleteConfirm final : public ConfirmDialog
A_DELETE_COPY(CharDeleteConfirm)
- void action(const gcn::ActionEvent &event)
+ void action(const ActionEvent &event)
{
if (event.getId() == "yes" && mMaster)
mMaster->askPasswordForDeletion(mIndex);
@@ -88,8 +90,8 @@ CharSelectDialog::CharSelectDialog(LoginData *const data):
Window(strprintf(_("Account %s (last login time %s)"),
data->username.c_str(), data->lastLogin.c_str()),
false, nullptr, "char.xml"),
- gcn::ActionListener(),
- gcn::KeyListener(),
+ ActionListener(),
+ KeyListener(),
mLoginData(data),
// TRANSLATORS: char select dialog. button.
mSwitchLoginButton(new Button(this, _("Switch Login"), "switch", this)),
@@ -205,10 +207,10 @@ void CharSelectDialog::postInit()
requestFocus();
}
-void CharSelectDialog::action(const gcn::ActionEvent &event)
+void CharSelectDialog::action(const ActionEvent &event)
{
// Check if a button of a character was pressed
- const gcn::Widget *const sourceParent = event.getSource()->getParent();
+ const Widget *const sourceParent = event.getSource()->getParent();
int selected = -1;
for (unsigned int i = 0, sz = static_cast<unsigned int>(
mCharacterEntries.size()); i < sz; ++i)
@@ -315,14 +317,14 @@ void CharSelectDialog::use(const int selected)
}
}
-void CharSelectDialog::keyPressed(gcn::KeyEvent &keyEvent)
+void CharSelectDialog::keyPressed(KeyEvent &keyEvent)
{
- const int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int actionId = keyEvent.getActionId();
switch (actionId)
{
case Input::KEY_GUI_CANCEL:
keyEvent.consume();
- action(gcn::ActionEvent(mSwitchLoginButton,
+ action(ActionEvent(mSwitchLoginButton,
mSwitchLoginButton->getActionEventId()));
break;
@@ -471,15 +473,7 @@ void CharSelectDialog::setCharacters(const Net::Characters &characters)
Net::Character *const character = *i;
- // Slots Number start at 1 for Manaserv, so we offset them by one.
-#ifdef MANASERV_SUPPORT
- int characterSlot = character->slot;
- if (Net::getNetworkType() == ServerInfo::MANASERV && characterSlot > 0)
- --characterSlot;
-#else
const int characterSlot = character->slot;
-#endif
-
if (characterSlot >= static_cast<int>(mCharacterEntries.size()))
{
logger->log("Warning: slot out of range: %d", character->slot);
@@ -563,7 +557,7 @@ void CharSelectDialog::close()
Window::close();
}
-void CharSelectDialog::widgetResized(const gcn::Event &event)
+void CharSelectDialog::widgetResized(const Event &event)
{
Window::widgetResized(event);
if (mCharacterView)
diff --git a/src/gui/windows/charselectdialog.h b/src/gui/windows/charselectdialog.h
index 3ac5d664f..38c307f30 100644
--- a/src/gui/windows/charselectdialog.h
+++ b/src/gui/windows/charselectdialog.h
@@ -29,13 +29,12 @@
#include "net/charserverhandler.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/keylistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/keylistener.h"
class Button;
class CharacterDisplay;
class CharacterViewBase;
-class Label;
class LoginData;
class TextDialog;
@@ -45,8 +44,8 @@ class TextDialog;
* \ingroup Interface
*/
class CharSelectDialog final : public Window,
- public gcn::ActionListener,
- public gcn::KeyListener
+ public ActionListener,
+ public KeyListener
{
public:
friend class CharDeleteConfirm;
@@ -61,9 +60,9 @@ class CharSelectDialog final : public Window,
~CharSelectDialog();
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
- void keyPressed(gcn::KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &keyEvent) override final;
enum SelectAction
{
@@ -86,7 +85,7 @@ class CharSelectDialog final : public Window,
void close() override final;
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
void updateState();
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp
index 26f665052..d769c4397 100644
--- a/src/gui/windows/chatwindow.cpp
+++ b/src/gui/windows/chatwindow.cpp
@@ -35,13 +35,16 @@
#include "being/playerinfo.h"
#include "being/playerrelations.h"
+#include "events/keyevent.h"
+
#include "input/inputmanager.h"
-#include "input/keyevent.h"
-#include "gui/sdlfont.h"
-#include "gui/sdlinput.h"
+#include "gui/focushandler.h"
+#include "gui/gui.h"
#include "gui/viewport.h"
+#include "gui/models/colorlistmodel.h"
+
#include "gui/windows/emotewindow.h"
#include "gui/windows/setupwindow.h"
#include "gui/widgets/tabbedarea.h"
@@ -68,8 +71,6 @@
#include "resources/resourcemanager.h"
-#include <guichan/focushandler.hpp>
-
#include <sstream>
#include <sys/stat.h>
@@ -97,7 +98,7 @@ class ChatInput final : public TextField
* Called if the chat input loses focus. It will set itself to
* invisible as result.
*/
- void focusLost(const gcn::Event &event)
+ void focusLost(const Event &event)
{
TextField::focusLost(event);
if (mFocusGaining || !config.getBoolValue("protectChatFocus"))
@@ -145,65 +146,13 @@ class ChatInput final : public TextField
bool mFocusGaining;
};
-const char *COLOR_NAME[14] =
-{
- // TRANSLATORS: chat color
- N_("default"),
- // TRANSLATORS: chat color
- N_("black"),
- // TRANSLATORS: chat color
- N_("red"),
- // TRANSLATORS: chat color
- N_("green"),
- // TRANSLATORS: chat color
- N_("blue"),
- // TRANSLATORS: chat color
- N_("gold"),
- // TRANSLATORS: chat color
- N_("yellow"),
- // TRANSLATORS: chat color
- N_("pink"),
- // TRANSLATORS: chat color
- N_("purple"),
- // TRANSLATORS: chat color
- N_("grey"),
- // TRANSLATORS: chat color
- N_("brown"),
- // TRANSLATORS: chat color
- N_("rainbow 1"),
- // TRANSLATORS: chat color
- N_("rainbow 2"),
- // TRANSLATORS: chat color
- N_("rainbow 3"),
-};
-
-
-class ColorListModel final : public gcn::ListModel
-{
-public:
- ~ColorListModel()
- { }
-
- int getNumberOfElements()
- {
- return 14;
- }
-
- std::string getElementAt(int i)
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
- return gettext(COLOR_NAME[i]);
- }
-};
-
static const char *const ACTION_COLOR_PICKER = "color picker";
ChatWindow::ChatWindow():
// TRANSLATORS: chat window name
Window(_("Chat"), false, nullptr, "chat.xml"),
- gcn::ActionListener(),
- gcn::KeyListener(),
+ ActionListener(),
+ KeyListener(),
mItemLinkHandler(new ItemLinkHandler),
mChatTabs(new TabbedArea(this)),
mChatInput(new ChatInput(this)),
@@ -378,7 +327,7 @@ void ChatWindow::updateTabsMargin()
void ChatWindow::adjustTabSize()
{
- const gcn::Rectangle area = getChildrenArea();
+ const Rect area = getChildrenArea();
const int aw = area.width;
const int ah = area.height;
@@ -425,7 +374,7 @@ void ChatWindow::adjustTabSize()
const ChatTab *const tab = getFocused();
if (tab)
{
- gcn::Widget *const content = tab->mScrollArea;
+ Widget *const content = tab->mScrollArea;
if (content)
{
const int contentFrame2 = 2 * content->getFrameSize();
@@ -441,7 +390,7 @@ void ChatWindow::adjustTabSize()
mChatTabs->adjustSize();
}
-void ChatWindow::widgetResized(const gcn::Event &event)
+void ChatWindow::widgetResized(const Event &event)
{
Window::widgetResized(event);
@@ -514,7 +463,7 @@ void ChatWindow::defaultTab()
mChatTabs->setSelectedTabByIndex(static_cast<unsigned>(0));
}
-void ChatWindow::action(const gcn::ActionEvent &event)
+void ChatWindow::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "chatinput")
@@ -770,12 +719,12 @@ void ChatWindow::scroll(const int amount) const
tab->scroll(amount);
}
-void ChatWindow::mousePressed(gcn::MouseEvent &event)
+void ChatWindow::mousePressed(MouseEvent &event)
{
if (event.isConsumed())
return;
- if (event.getButton() == gcn::MouseEvent::RIGHT)
+ if (event.getButton() == MouseEvent::RIGHT)
{
if (viewport)
{
@@ -804,7 +753,7 @@ void ChatWindow::mousePressed(gcn::MouseEvent &event)
if (event.isConsumed())
return;
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
const ChatTab *const tab = getFocused();
if (tab)
@@ -815,7 +764,7 @@ void ChatWindow::mousePressed(gcn::MouseEvent &event)
mDragOffsetY = event.getY();
}
-void ChatWindow::mouseDragged(gcn::MouseEvent &event)
+void ChatWindow::mouseDragged(MouseEvent &event)
{
Window::mouseDragged(event);
@@ -836,10 +785,10 @@ void ChatWindow::mouseDragged(gcn::MouseEvent &event)
temp = str; \
break
-void ChatWindow::keyPressed(gcn::KeyEvent &event)
+void ChatWindow::keyPressed(KeyEvent &event)
{
const int key = event.getKey().getValue();
- const int actionId = static_cast<KeyEvent*>(&event)->getActionId();
+ const int actionId = event.getActionId();
if (actionId == static_cast<int>(Input::KEY_GUI_DOWN))
{
if (mCurHist != mHistory.end())
@@ -1884,25 +1833,25 @@ void ChatWindow::optionChanged(const std::string &name)
parseGlobalsFilter();
}
-void ChatWindow::mouseMoved(gcn::MouseEvent &event)
+void ChatWindow::mouseMoved(MouseEvent &event)
{
mHaveMouse = true;
Window::mouseMoved(event);
}
-void ChatWindow::mouseEntered(gcn::MouseEvent& mouseEvent)
+void ChatWindow::mouseEntered(MouseEvent& mouseEvent)
{
mHaveMouse = true;
Window::mouseEntered(mouseEvent);
}
-void ChatWindow::mouseExited(gcn::MouseEvent& mouseEvent)
+void ChatWindow::mouseExited(MouseEvent& mouseEvent)
{
updateVisibility();
Window::mouseExited(mouseEvent);
}
-void ChatWindow::draw(gcn::Graphics* graphics)
+void ChatWindow::draw(Graphics* graphics)
{
BLOCK_START("ChatWindow::draw")
if (!mAutoHide || mHaveMouse)
diff --git a/src/gui/windows/chatwindow.h b/src/gui/windows/chatwindow.h
index 3093c52e9..2ec4e6bec 100644
--- a/src/gui/windows/chatwindow.h
+++ b/src/gui/windows/chatwindow.h
@@ -23,14 +23,14 @@
#ifndef GUI_WINDOWS_CHATWINDOW_H
#define GUI_WINDOWS_CHATWINDOW_H
-#include "depricatedlistener.h"
+#include "listeners/depricatedlistener.h"
-#include "configlistener.h"
+#include "listeners/configlistener.h"
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/keylistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/keylistener.h"
#include <list>
#include <map>
@@ -83,8 +83,8 @@ struct CHATLOG final
* \ingroup Interface
*/
class ChatWindow final : public Window,
- public gcn::ActionListener,
- public gcn::KeyListener,
+ public ActionListener,
+ public KeyListener,
public DepricatedListener,
public ConfigListener
{
@@ -139,7 +139,7 @@ class ChatWindow final : public Window,
/**
* Performs action.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Request focus for typing chat message.
@@ -169,7 +169,7 @@ class ChatWindow final : public Window,
void localChatInput(const std::string &msg) const;
/** Called when key is pressed */
- void keyPressed(gcn::KeyEvent &event) override final;
+ void keyPressed(KeyEvent &event) override final;
/** Set the chat input as the given text. */
void setInputText(const std::string &text);
@@ -186,12 +186,12 @@ class ChatWindow final : public Window,
/**
* Handles mouse when dragged.
*/
- void mouseDragged(gcn::MouseEvent &event) override final;
+ void mouseDragged(MouseEvent &event) override final;
/**
* Handles mouse when pressed.
*/
- void mousePressed(gcn::MouseEvent &event) override final;
+ void mousePressed(MouseEvent &event) override final;
void processEvent(const Channels channel,
const DepricatedEvent &event) override final;
@@ -274,19 +274,19 @@ class ChatWindow final : public Window,
void optionChanged(const std::string &name) override final;
- void mouseEntered(gcn::MouseEvent& mouseEvent) override final;
+ void mouseEntered(MouseEvent& mouseEvent) override final;
- void mouseMoved(gcn::MouseEvent &event) override final;
+ void mouseMoved(MouseEvent &event) override final;
- void mouseExited(gcn::MouseEvent& mouseEvent A_UNUSED) override final;
+ void mouseExited(MouseEvent& mouseEvent A_UNUSED) override final;
- void draw(gcn::Graphics* graphics) override final;
+ void draw(Graphics* graphics) override final;
void updateVisibility();
void unHideWindow();
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
void addGlobalMessage(const std::string &line);
diff --git a/src/gui/windows/confirmdialog.cpp b/src/gui/windows/confirmdialog.cpp
index e48427a5b..6eb21622d 100644
--- a/src/gui/windows/confirmdialog.cpp
+++ b/src/gui/windows/confirmdialog.cpp
@@ -29,7 +29,7 @@
#include "utils/gettext.h"
-#include <guichan/font.hpp>
+#include "gui/font.h"
#include "debug.h"
@@ -39,7 +39,7 @@ ConfirmDialog::ConfirmDialog(const std::string &restrict title,
const bool ignore,
const bool modal, Window *const parent):
Window(title, modal, parent, "confirm.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mTextBox(new TextBox(this)),
mIgnore(ignore)
{
@@ -107,7 +107,7 @@ void ConfirmDialog::postInit()
yesButton->requestFocus();
}
-void ConfirmDialog::action(const gcn::ActionEvent &event)
+void ConfirmDialog::action(const ActionEvent &event)
{
setActionEventId(event.getId());
distributeActionEvent();
diff --git a/src/gui/windows/confirmdialog.h b/src/gui/windows/confirmdialog.h
index 0b092e234..0d9f25d38 100644
--- a/src/gui/windows/confirmdialog.h
+++ b/src/gui/windows/confirmdialog.h
@@ -29,7 +29,7 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
class TextBox;
@@ -38,7 +38,8 @@ class TextBox;
*
* \ingroup GUI
*/
-class ConfirmDialog : public Window, public gcn::ActionListener
+class ConfirmDialog : public Window,
+ public ActionListener
{
public:
/**
@@ -57,7 +58,7 @@ class ConfirmDialog : public Window, public gcn::ActionListener
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override;
+ void action(const ActionEvent &event) override;
void postInit() override final;
diff --git a/src/gui/windows/connectiondialog.cpp b/src/gui/windows/connectiondialog.cpp
index 6d01dcaae..1a7c23187 100644
--- a/src/gui/windows/connectiondialog.cpp
+++ b/src/gui/windows/connectiondialog.cpp
@@ -34,14 +34,14 @@
ConnectionDialog::ConnectionDialog(const std::string &text,
const State cancelState):
Window("", false, nullptr, "connection.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mCancelState(cancelState)
{
setTitleBarHeight(0);
setMovable(false);
setMinWidth(0);
- ProgressIndicator *const progressIndicator = new ProgressIndicator;
+ ProgressIndicator *const progressIndicator = new ProgressIndicator(this);
Label *const label = new Label(this, text);
Button *const cancelButton = new Button(
// TRANSLATORS: connection dialog button
@@ -60,13 +60,13 @@ void ConnectionDialog::postInit()
setVisible(true);
}
-void ConnectionDialog::action(const gcn::ActionEvent &)
+void ConnectionDialog::action(const ActionEvent &)
{
logger->log1("Cancel pressed");
client->setState(mCancelState);
}
-void ConnectionDialog::draw(gcn::Graphics *graphics)
+void ConnectionDialog::draw(Graphics *graphics)
{
BLOCK_START("ConnectionDialog::draw")
// Don't draw the window background, only draw the children
diff --git a/src/gui/windows/connectiondialog.h b/src/gui/windows/connectiondialog.h
index 2f861bc52..059d4bd6d 100644
--- a/src/gui/windows/connectiondialog.h
+++ b/src/gui/windows/connectiondialog.h
@@ -27,14 +27,15 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
/**
* The connection dialog.
*
* \ingroup Interface
*/
-class ConnectionDialog final : public Window, private gcn::ActionListener
+class ConnectionDialog final : public Window,
+ private ActionListener
{
public:
/**
@@ -55,9 +56,9 @@ class ConnectionDialog final : public Window, private gcn::ActionListener
* Called when the user presses Cancel. Restores the global state to
* the previous one.
*/
- void action(const gcn::ActionEvent &) override;
+ void action(const ActionEvent &) override;
- void draw(gcn::Graphics *graphics) override;
+ void draw(Graphics *graphics) override;
private:
State mCancelState;
diff --git a/src/gui/windows/debugwindow.cpp b/src/gui/windows/debugwindow.cpp
index 30d202054..50dc5dbe5 100644
--- a/src/gui/windows/debugwindow.cpp
+++ b/src/gui/windows/debugwindow.cpp
@@ -75,7 +75,7 @@ DebugWindow::DebugWindow() :
// TRANSLATORS: debug window tab
mTabs->addTab(std::string(_("Net")), mNetWidget);
- mTabs->setDimension(gcn::Rectangle(0, 0, 600, 300));
+ mTabs->setDimension(Rect(0, 0, 600, 300));
const int w = mDimension.width;
const int h = mDimension.height;
@@ -129,7 +129,7 @@ void DebugWindow::slowLogic()
BLOCK_END("DebugWindow::slowLogic")
}
-void DebugWindow::draw(gcn::Graphics *g)
+void DebugWindow::draw(Graphics *g)
{
BLOCK_START("DebugWindow::draw")
Window::draw(g);
@@ -139,8 +139,7 @@ void DebugWindow::draw(gcn::Graphics *g)
const Being *const target = player_node->getTarget();
if (target)
{
- Graphics *const g2 = static_cast<Graphics*>(g);
- target->draw(g2, -target->getPixelX() + mapTileSize / 2
+ target->draw(g, -target->getPixelX() + mapTileSize / 2
+ mDimension.width / 2, -target->getPixelY() + mapTileSize
+ mDimension.height / 2);
}
@@ -148,11 +147,11 @@ void DebugWindow::draw(gcn::Graphics *g)
BLOCK_END("DebugWindow::draw")
}
-void DebugWindow::widgetResized(const gcn::Event &event)
+void DebugWindow::widgetResized(const Event &event)
{
Window::widgetResized(event);
- mTabs->setDimension(gcn::Rectangle(0, 0,
+ mTabs->setDimension(Rect(0, 0,
mDimension.width, mDimension.height));
}
@@ -268,7 +267,7 @@ MapDebugTab::MapDebugTab(const Widget2 *const widget) :
#endif
place.getCell().matchColWidth(0, 0);
place = h.getPlacer(0, 1);
- setDimension(gcn::Rectangle(0, 0, 600, 300));
+ setDimension(Rect(0, 0, 600, 300));
}
void MapDebugTab::logic()
@@ -413,7 +412,7 @@ TargetDebugTab::TargetDebugTab(const Widget2 *const widget) :
place.getCell().matchColWidth(0, 0);
place = h.getPlacer(0, 1);
- setDimension(gcn::Rectangle(0, 0, 600, 300));
+ setDimension(Rect(0, 0, 600, 300));
}
void TargetDebugTab::logic()
@@ -532,7 +531,7 @@ NetDebugTab::NetDebugTab(const Widget2 *const widget) :
place.getCell().matchColWidth(0, 0);
place = h.getPlacer(0, 1);
- setDimension(gcn::Rectangle(0, 0, 600, 300));
+ setDimension(Rect(0, 0, 600, 300));
}
void NetDebugTab::logic()
diff --git a/src/gui/windows/debugwindow.h b/src/gui/windows/debugwindow.h
index 13e73c29e..1a56f3164 100644
--- a/src/gui/windows/debugwindow.h
+++ b/src/gui/windows/debugwindow.h
@@ -41,7 +41,7 @@ class DebugTab : public Container
}
void resize(const int x, const int y)
- { setDimension(gcn::Rectangle(0, 0, x, y)); }
+ { setDimension(Rect(0, 0, x, y)); }
protected:
explicit DebugTab(const Widget2 *const widget) :
@@ -147,11 +147,11 @@ class DebugWindow final : public Window
*/
void slowLogic();
- void draw(gcn::Graphics *g) override final;
+ void draw(Graphics *g) override final;
void setPing(int pingTime);
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
#ifdef USE_PROFILER
void logicChildren();
diff --git a/src/gui/windows/didyouknowwindow.cpp b/src/gui/windows/didyouknowwindow.cpp
index 93166e6fa..79ad4c208 100644
--- a/src/gui/windows/didyouknowwindow.cpp
+++ b/src/gui/windows/didyouknowwindow.cpp
@@ -24,7 +24,7 @@
#include "configuration.h"
-#include "gui/sdlfont.h"
+#include "gui/gui.h"
#include "gui/windows/setupwindow.h"
@@ -48,10 +48,10 @@ static const int maxTip = 18;
DidYouKnowWindow::DidYouKnowWindow() :
// TRANSLATORS: did you know window name
Window(_("Did You Know?"), false, nullptr, "didyouknow.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mBrowserBox(new BrowserBox(this, BrowserBox::AUTO_SIZE, true,
"browserbox.xml")),
- mScrollArea(new ScrollArea(mBrowserBox,
+ mScrollArea(new ScrollArea(this, mBrowserBox,
true, "didyouknow_background.xml")),
// TRANSLATORS: did you know window button
mButtonPrev(new Button(this, _("< Previous"), "prev", this)),
@@ -78,7 +78,8 @@ DidYouKnowWindow::DidYouKnowWindow() :
Button *const okButton = new Button(this, _("Close"), "close", this);
mBrowserBox->setLinkHandler(this);
- mBrowserBox->setFont(gui->getHelpFont());
+ if (gui)
+ mBrowserBox->setFont(gui->getHelpFont());
mBrowserBox->setProcessVersion(true);
mBrowserBox->setEnableImages(true);
mBrowserBox->setEnableKeys(true);
@@ -99,10 +100,10 @@ DidYouKnowWindow::DidYouKnowWindow() :
void DidYouKnowWindow::postInit()
{
- widgetResized(gcn::Event(nullptr));
+ widgetResized(Event(nullptr));
}
-void DidYouKnowWindow::action(const gcn::ActionEvent &event)
+void DidYouKnowWindow::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "close")
@@ -129,7 +130,7 @@ void DidYouKnowWindow::action(const gcn::ActionEvent &event)
}
void DidYouKnowWindow::handleLink(const std::string &link,
- gcn::MouseEvent *event A_UNUSED)
+ MouseEvent *event A_UNUSED)
{
if (strStartWith(link, "http://") || strStartWith(link, "https://"))
openBrowser(link);
diff --git a/src/gui/windows/didyouknowwindow.h b/src/gui/windows/didyouknowwindow.h
index 942bcf41c..fd539e360 100644
--- a/src/gui/windows/didyouknowwindow.h
+++ b/src/gui/windows/didyouknowwindow.h
@@ -26,7 +26,7 @@
#include "gui/widgets/linkhandler.h"
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
class Button;
class BrowserBox;
@@ -38,7 +38,7 @@ class ScrollArea;
*/
class DidYouKnowWindow final : public Window,
public LinkHandler,
- public gcn::ActionListener
+ public ActionListener
{
public:
/**
@@ -53,13 +53,13 @@ class DidYouKnowWindow final : public Window,
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Handles link action.
*/
void handleLink(const std::string &link,
- gcn::MouseEvent *event) override final;
+ MouseEvent *event) override final;
void loadData(int num = 0);
diff --git a/src/gui/windows/editdialog.cpp b/src/gui/windows/editdialog.cpp
index 5c002212f..55102acdb 100644
--- a/src/gui/windows/editdialog.cpp
+++ b/src/gui/windows/editdialog.cpp
@@ -33,7 +33,7 @@ EditDialog::EditDialog(const std::string &restrict title,
const std::string &restrict eventOk, const int width,
Window *const parent, const bool modal):
Window(title, modal, parent, "edit.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mEventOk(eventOk),
mTextField(new TextField(this))
{
@@ -65,7 +65,7 @@ void EditDialog::postInit()
okButton->requestFocus();
}
-void EditDialog::action(const gcn::ActionEvent &event)
+void EditDialog::action(const ActionEvent &event)
{
// Proxy button events to our listeners
FOR_EACH (ActionListenerIterator, i, mActionListeners)
diff --git a/src/gui/windows/editdialog.h b/src/gui/windows/editdialog.h
index fa4a02bf7..b3bfe1f45 100644
--- a/src/gui/windows/editdialog.h
+++ b/src/gui/windows/editdialog.h
@@ -28,7 +28,7 @@
#include "gui/widgets/window.h"
#include "gui/widgets/textfield.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
#define ACTION_EDIT_OK "edit ok"
@@ -37,7 +37,8 @@
*
* \ingroup GUI
*/
-class EditDialog final : public Window, public gcn::ActionListener
+class EditDialog final : public Window,
+ public ActionListener
{
public:
/**
@@ -58,7 +59,7 @@ class EditDialog final : public Window, public gcn::ActionListener
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
std::string getMsg() const A_WARN_UNUSED
{ return mTextField->getText(); }
diff --git a/src/gui/windows/editserverdialog.cpp b/src/gui/windows/editserverdialog.cpp
index 900fe840b..316a7051b 100644
--- a/src/gui/windows/editserverdialog.cpp
+++ b/src/gui/windows/editserverdialog.cpp
@@ -21,8 +21,11 @@
#include "gui/windows/editserverdialog.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
+
+#include "gui/models/typelistmodel.h"
#include "gui/windows/okdialog.h"
#include "gui/windows/serverdialog.h"
@@ -35,36 +38,13 @@
#include "utils/gettext.h"
-std::string TypeListModel::getElementAt(int elementIndex)
-{
- if (elementIndex == 0)
- return "TmwAthena";
- else if (elementIndex == 1)
- return "Evol";
-#ifdef EATHENA_SUPPORT
- else if (elementIndex == 2)
- return "eAthena";
-#ifdef MANASERV_SUPPORT
- else if (elementIndex == 3)
- return "ManaServ";
-#endif
-#else
-#ifdef MANASERV_SUPPORT
- else if (elementIndex == 2)
- return "ManaServ";
-#endif
-#endif
- else
- return "Unknown";
-}
-
EditServerDialog::EditServerDialog(ServerDialog *const parent,
ServerInfo server,
const int index) :
// TRANSLATORS: edit server dialog name
Window(_("Edit Server"), true, parent),
- gcn::ActionListener(),
- gcn::KeyListener(),
+ ActionListener(),
+ KeyListener(),
mServerAddressField(new TextField(this, std::string())),
mPortField(new TextField(this, std::string())),
mNameField(new TextField(this, std::string())),
@@ -159,17 +139,6 @@ EditServerDialog::EditServerDialog(ServerDialog *const parent,
case ServerInfo::EATHENA:
mTypeField->setSelected(2);
break;
- case ServerInfo::MANASERV:
-#ifdef MANASERV_SUPPORT
- mTypeField->setSelected(3);
- break;
-#endif
-#else
- case ServerInfo::MANASERV:
-#ifdef MANASERV_SUPPORT
- mTypeField->setSelected(2);
- break;
-#endif
#endif
default:
case ServerInfo::UNKNOWN:
@@ -198,7 +167,7 @@ void EditServerDialog::postInit()
mNameField->requestFocus();
}
-void EditServerDialog::action(const gcn::ActionEvent &event)
+void EditServerDialog::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
@@ -246,17 +215,6 @@ void EditServerDialog::action(const gcn::ActionEvent &event)
case 2:
mServer.type = ServerInfo::EATHENA;
break;
-#ifdef MANASERV_SUPPORT
- case 3:
- mServer.type = ServerInfo::MANASERV;
- break;
-#endif
-#else
-#ifdef MANASERV_SUPPORT
- case 2:
- mServer.type = ServerInfo::MANASERV;
- break;
-#endif
#endif
default:
mServer.type = ServerInfo::UNKNOWN;
@@ -284,13 +242,12 @@ void EditServerDialog::action(const gcn::ActionEvent &event)
}
}
-void EditServerDialog::keyPressed(gcn::KeyEvent &keyEvent)
+void EditServerDialog::keyPressed(KeyEvent &keyEvent)
{
if (keyEvent.isConsumed())
return;
- const int actionId = static_cast<KeyEvent*>(
- &keyEvent)->getActionId();
+ const int actionId = keyEvent.getActionId();
if (actionId == static_cast<int>(Input::KEY_GUI_CANCEL))
{
@@ -299,6 +256,6 @@ void EditServerDialog::keyPressed(gcn::KeyEvent &keyEvent)
else if (actionId == static_cast<int>(Input::KEY_GUI_SELECT)
|| actionId == static_cast<int>(Input::KEY_GUI_SELECT2))
{
- action(gcn::ActionEvent(nullptr, mOkButton->getActionEventId()));
+ action(ActionEvent(nullptr, mOkButton->getActionEventId()));
}
}
diff --git a/src/gui/windows/editserverdialog.h b/src/gui/windows/editserverdialog.h
index 525005429..b70d1031b 100644
--- a/src/gui/windows/editserverdialog.h
+++ b/src/gui/windows/editserverdialog.h
@@ -26,48 +26,14 @@ class Button;
class TextField;
class DropDown;
class ServerDialog;
+class TypeListModel;
#include "gui/widgets/window.h"
#include "net/serverinfo.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/keylistener.hpp>
-#include <guichan/listmodel.hpp>
-
-/**
- * Server Type List Model
- */
-class TypeListModel : public gcn::ListModel
-{
- public:
- TypeListModel()
- { }
-
- /**
- * Used to get number of line in the list
- */
- int getNumberOfElements() override final A_WARN_UNUSED
-#ifdef EATHENA_SUPPORT
-#ifdef MANASERV_SUPPORT
- { return 4; }
-#else
- { return 3; }
-#endif
-#else
-#ifdef MANASERV_SUPPORT
- { return 3; }
-#else
- { return 2; }
-#endif
-#endif
-
- /**
- * Used to get an element from the list
- */
- std::string getElementAt(int elementIndex)
- override final A_WARN_UNUSED;
-};
+#include "listeners/actionlistener.h"
+#include "listeners/keylistener.h"
/**
* The custom server addition dialog.
@@ -75,8 +41,8 @@ class TypeListModel : public gcn::ListModel
* \ingroup Interface
*/
class EditServerDialog final : public Window,
- public gcn::ActionListener,
- public gcn::KeyListener
+ public ActionListener,
+ public KeyListener
{
public:
EditServerDialog(ServerDialog *const parent, ServerInfo server,
@@ -91,9 +57,9 @@ class EditServerDialog final : public Window,
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
- void keyPressed(gcn::KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &keyEvent) override final;
private:
TextField *mServerAddressField;
diff --git a/src/gui/windows/emotewindow.cpp b/src/gui/windows/emotewindow.cpp
index 9dd5f648c..3a7141533 100644
--- a/src/gui/windows/emotewindow.cpp
+++ b/src/gui/windows/emotewindow.cpp
@@ -20,10 +20,11 @@
#include "gui/windows/emotewindow.h"
-#include "gui/widgets/colormodel.h"
+#include "gui/models/colormodel.h"
+#include "gui/models/namesmodel.h"
+
#include "gui/widgets/colorpage.h"
#include "gui/widgets/emotepage.h"
-#include "gui/widgets/namesmodel.h"
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/tabbedarea.h"
@@ -51,10 +52,10 @@ EmoteWindow::EmoteWindow() :
mEmotePage(new EmotePage(this)),
mColorModel(ColorModel::createDefault(this)),
mColorPage(new ColorPage(this, mColorModel, "colorpage.xml")),
- mScrollColorPage(new ScrollArea(mColorPage, false, "emotepage.xml")),
+ mScrollColorPage(new ScrollArea(this, mColorPage, false, "emotepage.xml")),
mFontModel(new NamesModel),
mFontPage(new ListBox(this, mFontModel, "")),
- mScrollFontPage(new ScrollArea(mFontPage, false, "fontpage.xml")),
+ mScrollFontPage(new ScrollArea(this, mFontPage, false, "fontpage.xml")),
mImageSet(Theme::getImageSetFromThemeXml("emotetabs.xml", "", 17, 16))
{
mTabs->postInit();
@@ -207,14 +208,14 @@ void EmoteWindow::clearFont()
setVisible(false);
}
-void EmoteWindow::addListeners(gcn::ActionListener *const listener)
+void EmoteWindow::addListeners(ActionListener *const listener)
{
mEmotePage->addActionListener(listener);
mColorPage->addActionListener(listener);
mFontPage->addActionListener(listener);
}
-void EmoteWindow::widgetResized(const gcn::Event &event)
+void EmoteWindow::widgetResized(const Event &event)
{
Window::widgetResized(event);
const int pad2 = mPadding * 2;
@@ -229,7 +230,7 @@ void EmoteWindow::widgetResized(const gcn::Event &event)
mEmotePage->widgetResized(event);
}
-void EmoteWindow::widgetMoved(const gcn::Event &event)
+void EmoteWindow::widgetMoved(const Event &event)
{
Window::widgetMoved(event);
mEmotePage->widgetResized(event);
diff --git a/src/gui/windows/emotewindow.h b/src/gui/windows/emotewindow.h
index 0f15b7bc6..37a5c015f 100644
--- a/src/gui/windows/emotewindow.h
+++ b/src/gui/windows/emotewindow.h
@@ -59,11 +59,11 @@ class EmoteWindow final : public Window
void clearFont();
- void addListeners(gcn::ActionListener *const listener);
+ void addListeners(ActionListener *const listener);
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
- void widgetMoved(const gcn::Event &event) override final;
+ void widgetMoved(const Event &event) override final;
private:
TabbedArea *mTabs;
diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp
index 3b97e12d7..c793ba6ce 100644
--- a/src/gui/windows/equipmentwindow.cpp
+++ b/src/gui/windows/equipmentwindow.cpp
@@ -32,6 +32,7 @@
#include "being/localplayer.h"
#include "being/playerinfo.h"
+#include "gui/font.h"
#include "gui/viewport.h"
#include "gui/popups/itempopup.h"
@@ -46,8 +47,6 @@
#include "utils/dtor.h"
#include "utils/gettext.h"
-#include <guichan/font.hpp>
-
#include "debug.h"
static const int BOX_COUNT = 13;
@@ -57,10 +56,11 @@ EquipmentWindow::EquipmentWindow(Equipment *const equipment,
const bool foring):
// TRANSLATORS: equipment window name
Window(_("Equipment"), false, nullptr, "equipment.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mEquipment(equipment),
mItemPopup(new ItemPopup),
- mPlayerBox(new PlayerBox("equipment_playerbox.xml",
+ mPlayerBox(new PlayerBox(this,
+ "equipment_playerbox.xml",
"equipment_selectedplayerbox.xml")),
// TRANSLATORS: equipment window button
mUnequip(new Button(this, _("Unequip"), "unequip", this)),
@@ -92,7 +92,7 @@ EquipmentWindow::EquipmentWindow(Equipment *const equipment,
mBoxSize = 36;
// Control that shows the Player
- mPlayerBox->setDimension(gcn::Rectangle(50, 80, 74, 168));
+ mPlayerBox->setDimension(Rect(50, 80, 74, 168));
mPlayerBox->setPlayer(being);
if (foring)
@@ -116,7 +116,7 @@ EquipmentWindow::EquipmentWindow(Equipment *const equipment,
void EquipmentWindow::postInit()
{
- const gcn::Rectangle &area = getChildrenArea();
+ const Rect &area = getChildrenArea();
mUnequip->setPosition(area.width - mUnequip->getWidth() - mButtonPadding,
area.height - mUnequip->getHeight() - mButtonPadding);
mUnequip->setEnabled(false);
@@ -156,15 +156,14 @@ EquipmentWindow::~EquipmentWindow()
mVertexes = nullptr;
}
-void EquipmentWindow::draw(gcn::Graphics *graphics)
+void EquipmentWindow::draw(Graphics *graphics)
{
BLOCK_START("EquipmentWindow::draw")
// Draw window graphics
Window::draw(graphics);
- Graphics *const g = static_cast<Graphics*>(graphics);
int i = 0;
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
const int fontHeight = font->getHeight();
if (isBatchDrawRenders(openGLMode))
@@ -179,17 +178,19 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
continue;
if (i == mSelected)
{
- g->calcTileCollection(mVertexes,
- mSlotHighlightedBackground, box->x, box->y);
+ graphics->calcTileCollection(mVertexes,
+ mSlotHighlightedBackground,
+ box->x, box->y);
}
else
{
- g->calcTileCollection(mVertexes, mSlotBackground,
+ graphics->calcTileCollection(mVertexes,
+ mSlotBackground,
box->x, box->y);
}
}
}
- g->drawTileCollection(mVertexes);
+ graphics->drawTileCollection(mVertexes);
}
else
{
@@ -200,9 +201,14 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
if (!box)
continue;
if (i == mSelected)
- g->drawImage2(mSlotHighlightedBackground, box->x, box->y);
+ {
+ graphics->drawImage(mSlotHighlightedBackground,
+ box->x, box->y);
+ }
else
- g->drawImage2(mSlotBackground, box->x, box->y);
+ {
+ graphics->drawImage(mSlotBackground, box->x, box->y);
+ }
}
}
@@ -228,13 +234,14 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
{
image->setAlpha(1.0F); // Ensure the image is drawn
// with maximum opacity
- g->drawImage2(image, box->x + mItemPadding,
+ graphics->drawImage(image, box->x + mItemPadding,
box->y + mItemPadding);
if (i == EQUIP_PROJECTILE_SLOT)
{
- g->setColorAll(mLabelsColor, mLabelsColor2);
+ graphics->setColorAll(mLabelsColor, mLabelsColor2);
const std::string str = toString(item->getQuantity());
- font->drawString(g, str,
+ font->drawString(graphics,
+ str,
box->x + (mBoxSize - font->getWidth(str)) / 2,
box->y - fontHeight);
}
@@ -242,14 +249,15 @@ void EquipmentWindow::draw(gcn::Graphics *graphics)
}
else if (box->image)
{
- g->drawImage2(box->image, box->x + mItemPadding,
+ graphics->drawImage(box->image,
+ box->x + mItemPadding,
box->y + mItemPadding);
}
}
BLOCK_END("EquipmentWindow::draw")
}
-void EquipmentWindow::action(const gcn::ActionEvent &event)
+void EquipmentWindow::action(const ActionEvent &event)
{
if (!mEquipment)
return;
@@ -275,7 +283,7 @@ Item *EquipmentWindow::getItem(const int x, const int y) const
const EquipmentBox *const box = *it;
if (!box)
continue;
- const gcn::Rectangle tRect(box->x, box->y, mBoxSize, mBoxSize);
+ const Rect tRect(box->x, box->y, mBoxSize, mBoxSize);
if (tRect.isPointInRect(x, y))
return mEquipment->getEquipment(i);
@@ -283,7 +291,7 @@ Item *EquipmentWindow::getItem(const int x, const int y) const
return nullptr;
}
-void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
+void EquipmentWindow::mousePressed(MouseEvent& mouseEvent)
{
if (!mEquipment)
{
@@ -294,7 +302,7 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
const int x = mouseEvent.getX();
const int y = mouseEvent.getY();
- if (mouseEvent.getButton() == gcn::MouseEvent::LEFT)
+ if (mouseEvent.getButton() == MouseEvent::LEFT)
{
if (mForing)
{
@@ -313,7 +321,7 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
if (!box)
continue;
const Item *const item = mEquipment->getEquipment(i);
- const gcn::Rectangle tRect(box->x, box->y, mBoxSize, mBoxSize);
+ const Rect tRect(box->x, box->y, mBoxSize, mBoxSize);
if (tRect.isPointInRect(x, y))
{
@@ -329,7 +337,7 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
return;
}
}
- else if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT)
+ else if (mouseEvent.getButton() == MouseEvent::RIGHT)
{
if (Item *const item = getItem(x, y))
{
@@ -354,7 +362,7 @@ void EquipmentWindow::mousePressed(gcn::MouseEvent& mouseEvent)
Window::mousePressed(mouseEvent);
}
-void EquipmentWindow::mouseReleased(gcn::MouseEvent &mouseEvent)
+void EquipmentWindow::mouseReleased(MouseEvent &mouseEvent)
{
Window::mouseReleased(mouseEvent);
const DragDropSource src = dragDrop.getSource();
@@ -394,7 +402,7 @@ void EquipmentWindow::mouseReleased(gcn::MouseEvent &mouseEvent)
const EquipmentBox *const box = *it;
if (!box)
continue;
- const gcn::Rectangle tRect(box->x, box->y, mBoxSize, mBoxSize);
+ const Rect tRect(box->x, box->y, mBoxSize, mBoxSize);
if (tRect.isPointInRect(x, y))
return;
@@ -409,7 +417,7 @@ void EquipmentWindow::mouseReleased(gcn::MouseEvent &mouseEvent)
}
// Show ItemTooltip
-void EquipmentWindow::mouseMoved(gcn::MouseEvent &event)
+void EquipmentWindow::mouseMoved(MouseEvent &event)
{
Window::mouseMoved(event);
@@ -433,7 +441,7 @@ void EquipmentWindow::mouseMoved(gcn::MouseEvent &event)
}
// Hide ItemTooltip
-void EquipmentWindow::mouseExited(gcn::MouseEvent &event A_UNUSED)
+void EquipmentWindow::mouseExited(MouseEvent &event A_UNUSED)
{
if (mItemPopup)
mItemPopup->setVisible(false);
@@ -506,7 +514,7 @@ void EquipmentWindow::fillBoxes()
void EquipmentWindow::loadPlayerBox(const XmlNodePtr playerBoxNode)
{
- mPlayerBox->setDimension(gcn::Rectangle(
+ mPlayerBox->setDimension(Rect(
XML::getProperty(playerBoxNode, "x", 50),
XML::getProperty(playerBoxNode, "y", 80),
XML::getProperty(playerBoxNode, "width", 74),
diff --git a/src/gui/windows/equipmentwindow.h b/src/gui/windows/equipmentwindow.h
index 7387fb249..0ab4ca462 100644
--- a/src/gui/windows/equipmentwindow.h
+++ b/src/gui/windows/equipmentwindow.h
@@ -30,7 +30,7 @@
#include "utils/xml.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
#include <vector>
@@ -60,7 +60,8 @@ struct EquipmentBox final
*
* \ingroup Interface
*/
-class EquipmentWindow final : public Window, public gcn::ActionListener
+class EquipmentWindow final : public Window,
+ public ActionListener
{
public:
/**
@@ -81,11 +82,11 @@ class EquipmentWindow final : public Window, public gcn::ActionListener
/**
* Draws the equipment window.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
- void mousePressed(gcn::MouseEvent& mouseEvent) override final;
+ void mousePressed(MouseEvent& mouseEvent) override final;
const Item* getEquipment(const int i) const A_WARN_UNUSED
{ return mEquipment ? mEquipment->getEquipment(i) : nullptr; }
@@ -96,11 +97,11 @@ class EquipmentWindow final : public Window, public gcn::ActionListener
void resetBeing(const Being *const being);
- void mouseExited(gcn::MouseEvent &event) override final;
+ void mouseExited(MouseEvent &event) override final;
- void mouseMoved(gcn::MouseEvent &event) override final;
+ void mouseMoved(MouseEvent &event) override final;
- void mouseReleased(gcn::MouseEvent &event) override final;
+ void mouseReleased(MouseEvent &event) override final;
void recalcSize();
@@ -135,10 +136,10 @@ class EquipmentWindow final : public Window, public gcn::ActionListener
ImageSet *mImageSet;
Being *mBeing;
std::vector<EquipmentBox*> mBoxes;
- gcn::Color mHighlightColor;
- gcn::Color mBorderColor;
- gcn::Color mLabelsColor;
- gcn::Color mLabelsColor2;
+ Color mHighlightColor;
+ Color mBorderColor;
+ Color mLabelsColor;
+ Color mLabelsColor2;
Image *mSlotBackground;
Image *mSlotHighlightedBackground;
ImageCollection *mVertexes;
diff --git a/src/gui/windows/helpwindow.cpp b/src/gui/windows/helpwindow.cpp
index eb2300e0e..fa9963217 100644
--- a/src/gui/windows/helpwindow.cpp
+++ b/src/gui/windows/helpwindow.cpp
@@ -24,7 +24,7 @@
#include "configuration.h"
-#include "gui/sdlfont.h"
+#include "gui/gui.h"
#include "gui/windows/didyouknowwindow.h"
#include "gui/windows/setupwindow.h"
@@ -48,12 +48,13 @@
HelpWindow::HelpWindow() :
// TRANSLATORS: help window name
Window(_("Help"), false, nullptr, "help.xml"),
- gcn::ActionListener(),
+ ActionListener(),
// TRANSLATORS: help window. button.
mDYKButton(new Button(this, _("Did you know..."), "DYK", this)),
mBrowserBox(new BrowserBox(this, BrowserBox::AUTO_SIZE, true,
"browserbox.xml")),
- mScrollArea(new ScrollArea(mBrowserBox, true, "help_background.xml")),
+ mScrollArea(new ScrollArea(this, mBrowserBox,
+ true, "help_background.xml")),
mTagFileMap()
{
setMinWidth(300);
@@ -72,7 +73,8 @@ HelpWindow::HelpWindow() :
mBrowserBox->setOpaque(false);
mBrowserBox->setLinkHandler(this);
- mBrowserBox->setFont(gui->getHelpFont());
+ if (gui)
+ mBrowserBox->setFont(gui->getHelpFont());
mBrowserBox->setProcessVersion(true);
mBrowserBox->setEnableImages(true);
mBrowserBox->setEnableKeys(true);
@@ -87,10 +89,10 @@ HelpWindow::HelpWindow() :
loadWindowState();
loadTags();
enableVisibleSound(true);
- widgetResized(gcn::Event(nullptr));
+ widgetResized(Event(nullptr));
}
-void HelpWindow::action(const gcn::ActionEvent &event)
+void HelpWindow::action(const ActionEvent &event)
{
if (event.getId() == "DYK")
{
@@ -104,7 +106,7 @@ void HelpWindow::action(const gcn::ActionEvent &event)
}
void HelpWindow::handleLink(const std::string &link,
- gcn::MouseEvent *event A_UNUSED)
+ MouseEvent *event A_UNUSED)
{
if (!strStartWith(link, "http://") && !strStartWith(link, "https://"))
{
diff --git a/src/gui/windows/helpwindow.h b/src/gui/windows/helpwindow.h
index 72c0d4aba..4290c99f9 100644
--- a/src/gui/windows/helpwindow.h
+++ b/src/gui/windows/helpwindow.h
@@ -26,7 +26,7 @@
#include "gui/widgets/linkhandler.h"
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
#include "localconsts.h"
@@ -44,8 +44,9 @@ typedef std::map<std::string, HelpNames> HelpTagsMap;
/**
* The help window.
*/
-class HelpWindow final : public Window, public LinkHandler,
- public gcn::ActionListener
+class HelpWindow final : public Window,
+ public LinkHandler,
+ public ActionListener
{
public:
/**
@@ -58,13 +59,13 @@ class HelpWindow final : public Window, public LinkHandler,
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Handles link action.
*/
void handleLink(const std::string &link,
- gcn::MouseEvent *event A_UNUSED) override final;
+ MouseEvent *event A_UNUSED) override final;
/**
* Loads help in the dialog.
diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp
index 6fd2ab95b..ee8c85f06 100644
--- a/src/gui/windows/inventorywindow.cpp
+++ b/src/gui/windows/inventorywindow.cpp
@@ -28,11 +28,16 @@
#include "being/playerinfo.h"
+#include "events/keyevent.h"
+
#include "input/inputmanager.h"
-#include "input/keyevent.h"
+#include "gui/font.h"
+#include "gui/gui.h"
#include "gui/viewport.h"
+#include "gui/models/sortlistmodelinv.h"
+
#include "gui/popups/textpopup.h"
#include "gui/windows/equipmentwindow.h"
@@ -42,7 +47,6 @@
#include "gui/windows/shopwindow.h"
#include "gui/windows/tradewindow.h"
-
#include "gui/widgets/button.h"
#include "gui/widgets/dropdown.h"
#include "gui/widgets/itemcontainer.h"
@@ -57,53 +61,17 @@
#include "utils/gettext.h"
-#include <guichan/font.hpp>
-
#include <string>
#include "debug.h"
-static const char *const SORT_NAME_INVENTORY[6] =
-{
- // TRANSLATORS: inventory sort mode
- N_("default"),
- // TRANSLATORS: inventory sort mode
- N_("by name"),
- // TRANSLATORS: inventory sort mode
- N_("by id"),
- // TRANSLATORS: inventory sort mode
- N_("by weight"),
- // TRANSLATORS: inventory sort mode
- N_("by amount"),
- // TRANSLATORS: inventory sort mode
- N_("by type")
-};
-
-class SortListModelInv final : public gcn::ListModel
-{
-public:
- ~SortListModelInv()
- { }
-
- int getNumberOfElements() override final
- { return 6; }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
-
- return gettext(SORT_NAME_INVENTORY[i]);
- }
-};
-
InventoryWindow::WindowList InventoryWindow::invInstances;
InventoryWindow::InventoryWindow(Inventory *const inventory):
Window("Inventory", false, nullptr, "inventory.xml"),
- gcn::ActionListener(),
- gcn::KeyListener(),
- gcn::SelectionListener(),
+ ActionListener(),
+ KeyListener(),
+ SelectionListener(),
InventoryListener(),
mInventory(inventory),
mItems(new ItemContainer(this, mInventory)),
@@ -183,8 +151,8 @@ InventoryWindow::InventoryWindow(Inventory *const inventory):
mItems->addSelectionListener(this);
- gcn::ScrollArea *const invenScroll = new ScrollArea(
- mItems, getOptionBool("showbackground"), "inventory_background.xml");
+ gcn::ScrollArea *const invenScroll = new ScrollArea(this, mItems,
+ getOptionBool("showbackground"), "inventory_background.xml");
invenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
const int size = config.getIntValue("fontSize");
@@ -295,7 +263,7 @@ void InventoryWindow::postInit()
slotsChanged(mInventory);
mItems->setSortType(mSortDropDown->getSelected());
- widgetResized(gcn::Event(nullptr));
+ widgetResized(Event(nullptr));
if (!isMainInventory())
setVisible(true);
}
@@ -335,7 +303,7 @@ void InventoryWindow::storeSortOrder()
}
}
-void InventoryWindow::action(const gcn::ActionEvent &event)
+void InventoryWindow::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "outfit")
@@ -459,13 +427,13 @@ void InventoryWindow::unselectItem()
mItems->selectNone();
}
-void InventoryWindow::widgetHidden(const gcn::Event &event)
+void InventoryWindow::widgetHidden(const Event &event)
{
Window::widgetHidden(event);
mItems->hidePopup();
}
-void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
+void InventoryWindow::mouseClicked(MouseEvent &event)
{
Window::mouseClicked(event);
@@ -481,7 +449,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
&& inputManager.isActionActive(static_cast<int>(
Input::KEY_STOP_ATTACK)));
- if (!mod && !mod2 && event.getButton() == gcn::MouseEvent::RIGHT)
+ if (!mod && !mod2 && event.getButton() == MouseEvent::RIGHT)
{
Item *const item = mItems->getSelectedItem();
@@ -501,8 +469,8 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
if (!mInventory)
return;
- if (event.getButton() == gcn::MouseEvent::LEFT
- || event.getButton() == gcn::MouseEvent::RIGHT)
+ if (event.getButton() == MouseEvent::LEFT
+ || event.getButton() == MouseEvent::RIGHT)
{
Item *const item = mItems->getSelectedItem();
@@ -513,7 +481,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
{
if (mInventory->isMainInventory())
{
- if (event.getButton() == gcn::MouseEvent::RIGHT)
+ if (event.getButton() == MouseEvent::RIGHT)
{
ItemAmountWindow::showWindow(ItemAmountWindow::StoreAdd,
inventoryWindow, item);
@@ -527,7 +495,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
}
else
{
- if (event.getButton() == gcn::MouseEvent::RIGHT)
+ if (event.getButton() == MouseEvent::RIGHT)
{
ItemAmountWindow::showWindow(ItemAmountWindow::StoreRemove,
inventoryWindow, item);
@@ -544,7 +512,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
{
if (PlayerInfo::isItemProtected(item->getId()))
return;
- if (event.getButton() == gcn::MouseEvent::RIGHT)
+ if (event.getButton() == MouseEvent::RIGHT)
{
ItemAmountWindow::showWindow(ItemAmountWindow::TradeAdd,
tradeWindow, item);
@@ -588,15 +556,15 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
}
}
-void InventoryWindow::mouseMoved(gcn::MouseEvent &event)
+void InventoryWindow::mouseMoved(MouseEvent &event)
{
Window::mouseMoved(event);
- const gcn::Widget *const src = event.getSource();
+ const Widget *const src = event.getSource();
if (src == mSlotsBar || src == mWeightBar)
{
const int x = event.getX();
const int y = event.getY();
- const gcn::Rectangle &rect = mDimension;
+ const Rect &rect = mDimension;
mTextPopup->show(rect.x + x, rect.y + y, strprintf(_("Money: %s"),
Units::formatCurrency(PlayerInfo::getAttribute(
PlayerInfo::MONEY)).c_str()));
@@ -607,30 +575,24 @@ void InventoryWindow::mouseMoved(gcn::MouseEvent &event)
}
}
-void InventoryWindow::mouseExited(gcn::MouseEvent &event A_UNUSED)
+void InventoryWindow::mouseExited(MouseEvent &event A_UNUSED)
{
mTextPopup->hide();
}
-void InventoryWindow::keyPressed(gcn::KeyEvent &event)
+void InventoryWindow::keyPressed(KeyEvent &event)
{
- if (static_cast<KeyEvent*>(&event)->getActionId()
- == static_cast<int>(Input::KEY_GUI_MOD))
- {
+ if (event.getActionId() == static_cast<int>(Input::KEY_GUI_MOD))
mSplit = true;
- }
}
-void InventoryWindow::keyReleased(gcn::KeyEvent &event)
+void InventoryWindow::keyReleased(KeyEvent &event)
{
- if (static_cast<KeyEvent*>(&event)->getActionId()
- == static_cast<int>(Input::KEY_GUI_MOD))
- {
+ if (event.getActionId() == static_cast<int>(Input::KEY_GUI_MOD))
mSplit = false;
- }
}
-void InventoryWindow::valueChanged(const gcn::SelectionEvent &event A_UNUSED)
+void InventoryWindow::valueChanged(const SelectionEvent &event A_UNUSED)
{
if (!mInventory || !mInventory->isMainInventory())
return;
@@ -812,7 +774,7 @@ bool InventoryWindow::isAnyInputFocused()
return false;
}
-void InventoryWindow::widgetResized(const gcn::Event &event)
+void InventoryWindow::widgetResized(const Event &event)
{
Window::widgetResized(event);
diff --git a/src/gui/windows/inventorywindow.h b/src/gui/windows/inventorywindow.h
index 4e32f6fa2..c81e83d77 100644
--- a/src/gui/windows/inventorywindow.h
+++ b/src/gui/windows/inventorywindow.h
@@ -24,19 +24,19 @@
#define GUI_WINDOWS_INVENTORYWINDOW_H
#include "inventory.h"
-#include "depricatedlistener.h"
+
+#include "listeners/depricatedlistener.h"
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/keylistener.hpp>
-#include <guichan/selectionlistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/keylistener.h"
+#include "listeners/selectionlistener.h"
class Button;
class DropDown;
class Item;
class ItemContainer;
-class Label;
class LayoutCell;
class ProgressBar;
class SortListModelInv;
@@ -50,9 +50,9 @@ class TextPopup;
* \ingroup Interface
*/
class InventoryWindow final : public Window,
- public gcn::ActionListener,
- public gcn::KeyListener,
- public gcn::SelectionListener,
+ public ActionListener,
+ public KeyListener,
+ public SelectionListener,
public InventoryListener,
public DepricatedListener
{
@@ -76,7 +76,7 @@ class InventoryWindow final : public Window,
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Returns the selected item.
@@ -91,27 +91,27 @@ class InventoryWindow final : public Window,
/**
* Handles closing of the window
*/
- void widgetHidden(const gcn::Event &event) override final;
+ void widgetHidden(const Event &event) override final;
/**
* Handles the mouse clicks.
*/
- void mouseClicked(gcn::MouseEvent &event) override final;
+ void mouseClicked(MouseEvent &event) override final;
/**
* Handles the key presses.
*/
- void keyPressed(gcn::KeyEvent &event) override final;
+ void keyPressed(KeyEvent &event) override final;
/**
* Handles the key releases.
*/
- void keyReleased(gcn::KeyEvent &event) override final;
+ void keyReleased(KeyEvent &event) override final;
/**
* Updates labels to currently selected item.
*/
- void valueChanged(const gcn::SelectionEvent &event) override final;
+ void valueChanged(const SelectionEvent &event) override final;
/**
* Sets whether the split button should be shown.
@@ -144,11 +144,11 @@ class InventoryWindow final : public Window,
bool isInputFocused() const A_WARN_UNUSED;
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
- void mouseMoved(gcn::MouseEvent &event) override final;
+ void mouseMoved(MouseEvent &event) override final;
- void mouseExited(gcn::MouseEvent &event) override final;
+ void mouseExited(MouseEvent &event) override final;
void setVisible(bool visible) override final;
diff --git a/src/gui/windows/itemamountwindow.cpp b/src/gui/windows/itemamountwindow.cpp
index 975892888..fc0c5880b 100644
--- a/src/gui/windows/itemamountwindow.cpp
+++ b/src/gui/windows/itemamountwindow.cpp
@@ -33,6 +33,8 @@
#include "net/net.h"
#include "gui/viewport.h"
+#include "gui/models/itemsmodel.h"
+
#include "gui/popups/itempopup.h"
#include "gui/windows/shopwindow.h"
@@ -50,55 +52,6 @@
#include "debug.h"
-class ItemsModal final : public gcn::ListModel
-{
-public:
- ItemsModal() :
- mStrings()
- {
- const std::map<int, ItemInfo*> &items = ItemDB::getItemInfos();
- std::list<std::string> tempStrings;
-
- for (std::map<int, ItemInfo*>::const_iterator
- i = items.begin(), i_end = items.end();
- i != i_end; ++i)
- {
- if (i->first < 0)
- continue;
-
- const ItemInfo &info = *i->second;
- const std::string name = info.getName();
- if (name != "unnamed" && !info.getName().empty()
- && info.getName() != "unnamed")
- {
- tempStrings.push_back(name);
- }
- }
- tempStrings.sort();
- FOR_EACH (std::list<std::string>::const_iterator, i, tempStrings)
- mStrings.push_back(*i);
- }
-
- A_DELETE_COPY(ItemsModal)
-
- ~ItemsModal()
- { }
-
- int getNumberOfElements() override final
- {
- return static_cast<int>(mStrings.size());
- }
-
- std::string getElementAt(int i) override final
- {
- if (i < 0 || i >= getNumberOfElements())
- return "???";
- return mStrings.at(i);
- }
-private:
- StringVect mStrings;
-};
-
void ItemAmountWindow::finish(Item *const item, const int amount,
const int price, const Usage usage)
{
@@ -138,8 +91,8 @@ void ItemAmountWindow::finish(Item *const item, const int amount,
ItemAmountWindow::ItemAmountWindow(const Usage usage, Window *const parent,
Item *const item, const int maxRange) :
Window("", false, parent, "amount.xml"),
- gcn::ActionListener(),
- gcn::KeyListener(),
+ ActionListener(),
+ KeyListener(),
mItemAmountTextField(new IntTextField(this, 1)),
mItemPriceTextField(nullptr),
mGPLabel(nullptr),
@@ -148,7 +101,7 @@ ItemAmountWindow::ItemAmountWindow(const Usage usage, Window *const parent,
mMax(maxRange),
mUsage(usage),
mItemPopup(new ItemPopup),
- mItemAmountSlide(new Slider(1.0, mMax)),
+ mItemAmountSlide(new Slider(this, 1.0, mMax)),
mItemPriceSlide(nullptr),
mItemDropDown(nullptr),
mItemsModal(nullptr),
@@ -182,7 +135,7 @@ ItemAmountWindow::ItemAmountWindow(const Usage usage, Window *const parent,
mItemPriceTextField->setWidth(35);
mItemPriceTextField->addKeyListener(this);
- mItemPriceSlide = new Slider(1.0, 10000000);
+ mItemPriceSlide = new Slider(this, 1.0, 10000000);
mItemPriceSlide->setHeight(10);
mItemPriceSlide->setActionEventId("slidePrice");
mItemPriceSlide->addActionListener(this);
@@ -313,7 +266,7 @@ ItemAmountWindow::~ItemAmountWindow()
}
// Show ItemTooltip
-void ItemAmountWindow::mouseMoved(gcn::MouseEvent &event)
+void ItemAmountWindow::mouseMoved(MouseEvent &event)
{
Window::mouseMoved(event);
@@ -328,7 +281,7 @@ void ItemAmountWindow::mouseMoved(gcn::MouseEvent &event)
}
// Hide ItemTooltip
-void ItemAmountWindow::mouseExited(gcn::MouseEvent &event A_UNUSED)
+void ItemAmountWindow::mouseExited(MouseEvent &event A_UNUSED)
{
if (mItemPopup)
mItemPopup->setVisible(false);
@@ -339,7 +292,7 @@ void ItemAmountWindow::resetAmount()
mItemAmountTextField->setValue(1);
}
-void ItemAmountWindow::action(const gcn::ActionEvent &event)
+void ItemAmountWindow::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "cancel")
@@ -435,7 +388,7 @@ void ItemAmountWindow::close()
scheduleDelete();
}
-void ItemAmountWindow::keyReleased(gcn::KeyEvent &keyEvent A_UNUSED)
+void ItemAmountWindow::keyReleased(KeyEvent &keyEvent A_UNUSED)
{
mItemAmountSlide->setValue2(mItemAmountTextField->getValue());
}
diff --git a/src/gui/windows/itemamountwindow.h b/src/gui/windows/itemamountwindow.h
index 7625c4a71..cf721ee30 100644
--- a/src/gui/windows/itemamountwindow.h
+++ b/src/gui/windows/itemamountwindow.h
@@ -25,8 +25,8 @@
#include "gui/widgets/window.h"
-#include <guichan/keylistener.hpp>
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/keylistener.h"
class DropDown;
class Icon;
@@ -43,8 +43,8 @@ class Slider;
* \ingroup Interface
*/
class ItemAmountWindow final : public Window,
- public gcn::ActionListener,
- public gcn::KeyListener
+ public ActionListener,
+ public KeyListener
{
public:
enum Usage
@@ -65,7 +65,7 @@ class ItemAmountWindow final : public Window,
/**
* Called when receiving actions from widget.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Sets default amount value.
@@ -73,16 +73,16 @@ class ItemAmountWindow final : public Window,
void resetAmount();
// MouseListener
- void mouseMoved(gcn::MouseEvent &event) override final;
+ void mouseMoved(MouseEvent &event) override final;
- void mouseExited(gcn::MouseEvent &event) override final;
+ void mouseExited(MouseEvent &event) override final;
/**
* Schedules the Item Amount window for deletion.
*/
void close();
- void keyReleased(gcn::KeyEvent &keyEvent) override final;
+ void keyReleased(KeyEvent &keyEvent) override final;
/**
* Creates the dialog, or bypass it if there aren't enough items.
diff --git a/src/gui/windows/killstats.cpp b/src/gui/windows/killstats.cpp
index 0adabc3ad..710875a3c 100644
--- a/src/gui/windows/killstats.cpp
+++ b/src/gui/windows/killstats.cpp
@@ -40,7 +40,7 @@
KillStats::KillStats() :
// TRANSLATORS: kill stats window name
Window(_("Kill stats"), false, nullptr, "killstats.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mKillCounter(0),
mExpCounter(0),
mKillTCounter(0),
@@ -156,7 +156,7 @@ KillStats::~KillStats()
{
}
-void KillStats::action(const gcn::ActionEvent &event)
+void KillStats::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "reset")
diff --git a/src/gui/windows/killstats.h b/src/gui/windows/killstats.h
index 094147383..486ec9135 100644
--- a/src/gui/windows/killstats.h
+++ b/src/gui/windows/killstats.h
@@ -23,9 +23,8 @@
#ifndef GUI_WINDOWS_KILLSTATS_H
#define GUI_WINDOWS_KILLSTATS_H
-#include <guichan/actionlistener.hpp>
-
-#include "depricatedlistener.h"
+#include "listeners/actionlistener.h"
+#include "listeners/depricatedlistener.h"
#include "gui/widgets/window.h"
@@ -33,7 +32,7 @@ class Label;
class Button;
class KillStats final : public Window,
- private gcn::ActionListener,
+ private ActionListener,
public DepricatedListener
{
public:
@@ -52,7 +51,7 @@ class KillStats final : public Window,
/**
* Stuff.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void gainXp(int Xp);
diff --git a/src/gui/windows/logindialog.cpp b/src/gui/windows/logindialog.cpp
index 8ec6144a0..71abf153a 100644
--- a/src/gui/windows/logindialog.cpp
+++ b/src/gui/windows/logindialog.cpp
@@ -25,8 +25,12 @@
#include "client.h"
#include "configuration.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
+
+#include "gui/models/updatelistmodel.h"
+#include "gui/models/updatetypemodel.h"
#include "gui/windows/confirmdialog.h"
@@ -53,17 +57,17 @@ std::string LoginDialog::savedPasswordKey("");
namespace
{
- struct OpenUrlListener : public gcn::ActionListener
+ struct OpenUrlListener : public ActionListener
{
OpenUrlListener() :
- gcn::ActionListener(),
+ ActionListener(),
url()
{
}
A_DELETE_COPY(OpenUrlListener)
- void action(const gcn::ActionEvent &event) override final
+ void action(const ActionEvent &event) override final
{
if (event.getId() == "yes")
openBrowser(url);
@@ -73,78 +77,12 @@ namespace
} urlListener;
} // namespace
-const char *UPDATE_TYPE_TEXT[3] =
-{
- // TRANSLATORS: update type
- N_("Normal"),
- // TRANSLATORS: update type
- N_("Auto Close"),
- // TRANSLATORS: update type
- N_("Skip"),
-};
-
-class UpdateTypeModel final : public gcn::ListModel
-{
- public:
- UpdateTypeModel()
- { }
-
- A_DELETE_COPY(UpdateTypeModel)
-
- ~UpdateTypeModel()
- { }
-
- int getNumberOfElements() override final
- {
- return 3;
- }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
- return gettext(UPDATE_TYPE_TEXT[i]);
- }
-};
-
-class UpdateListModel final : public gcn::ListModel
-{
- public:
- explicit UpdateListModel(LoginData *const data) :
- gcn::ListModel(),
- mLoginData(data)
- {
- }
-
- A_DELETE_COPY(UpdateListModel)
-
- ~UpdateListModel()
- { }
-
- int getNumberOfElements() override final
- {
- if (!mLoginData)
- return 0;
- return static_cast<int>(mLoginData->updateHosts.size());
- }
-
- std::string getElementAt(int i) override final
- {
- if (!mLoginData || i >= getNumberOfElements() || i < 0)
- return "???";
- return mLoginData->updateHosts[i];
- }
-
- protected:
- LoginData *mLoginData;
-};
-
LoginDialog::LoginDialog(LoginData *const data, std::string serverName,
std::string *const updateHost):
// TRANSLATORS: login dialog name
Window(_("Login"), false, nullptr, "login.xml"),
- gcn::ActionListener(),
- gcn::KeyListener(),
+ ActionListener(),
+ KeyListener(),
mLoginData(data),
mUserField(new TextField(this, mLoginData->username)),
mPassField(new PasswordField(this, mLoginData->password)),
@@ -276,7 +214,7 @@ LoginDialog::~LoginDialog()
mUpdateListModel = nullptr;
}
-void LoginDialog::action(const gcn::ActionEvent &event)
+void LoginDialog::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "login" && canSubmit())
@@ -318,7 +256,7 @@ void LoginDialog::action(const gcn::ActionEvent &event)
}
}
-void LoginDialog::keyPressed(gcn::KeyEvent &keyEvent)
+void LoginDialog::keyPressed(KeyEvent &keyEvent)
{
if (keyEvent.isConsumed())
{
@@ -326,16 +264,15 @@ void LoginDialog::keyPressed(gcn::KeyEvent &keyEvent)
return;
}
- const int actionId = static_cast<KeyEvent*>(
- &keyEvent)->getActionId();
+ const int actionId = keyEvent.getActionId();
if (actionId == static_cast<int>(Input::KEY_GUI_CANCEL))
{
- action(gcn::ActionEvent(nullptr, mServerButton->getActionEventId()));
+ action(ActionEvent(nullptr, mServerButton->getActionEventId()));
}
else if (actionId == static_cast<int>(Input::KEY_GUI_SELECT)
|| actionId == static_cast<int>(Input::KEY_GUI_SELECT2))
{
- action(gcn::ActionEvent(nullptr, mLoginButton->getActionEventId()));
+ action(ActionEvent(nullptr, mLoginButton->getActionEventId()));
}
else
{
diff --git a/src/gui/windows/logindialog.h b/src/gui/windows/logindialog.h
index c9d2ad61f..7150b62c1 100644
--- a/src/gui/windows/logindialog.h
+++ b/src/gui/windows/logindialog.h
@@ -25,8 +25,8 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/keylistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/keylistener.h"
#include <string>
@@ -44,8 +44,9 @@ class UpdateTypeModel;
*
* \ingroup Interface
*/
-class LoginDialog final : public Window, public gcn::ActionListener,
- public gcn::KeyListener
+class LoginDialog final : public Window,
+ public ActionListener,
+ public KeyListener
{
public:
/**
@@ -65,12 +66,12 @@ class LoginDialog final : public Window, public gcn::ActionListener,
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Called when a key is pressed in one of the text fields.
*/
- void keyPressed(gcn::KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &keyEvent) override final;
void close() override final;
diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp
index 02be64a13..ef1830763 100644
--- a/src/gui/windows/minimap.cpp
+++ b/src/gui/windows/minimap.cpp
@@ -213,7 +213,7 @@ void Minimap::setMap(const Map *const map)
setHeight(height);
}
- const gcn::Rectangle &rect = mDimension;
+ const Rect &rect = mDimension;
setDefaultSize(rect.x, rect.y, rect.width, rect.height);
resetToDefaultSize();
@@ -233,7 +233,7 @@ void Minimap::toggle()
mShow = isWindowVisible();
}
-void Minimap::draw(gcn::Graphics *graphics)
+void Minimap::draw(Graphics *graphics)
{
BLOCK_START("Minimap::draw")
Window::draw(graphics);
@@ -244,9 +244,7 @@ void Minimap::draw(gcn::Graphics *graphics)
return;
}
- Graphics *const graph = static_cast<Graphics*>(graphics);
-
- const gcn::Rectangle a = getChildrenArea();
+ const Rect a = getChildrenArea();
graphics->pushClipArea(a);
@@ -286,7 +284,7 @@ void Minimap::draw(gcn::Graphics *graphics)
mMapOriginY = 0;
}
- graph->drawImage2(mMapImage, mMapOriginX, mMapOriginY);
+ graphics->drawImage(mMapImage, mMapOriginX, mMapOriginY);
}
const ActorSprites &actors = actorManager->getAll();
@@ -348,7 +346,7 @@ void Minimap::draw(gcn::Graphics *graphics)
dotSize - 1) * mWidthProportion);
const Vector &pos = being->getPosition();
- graphics->fillRectangle(gcn::Rectangle(
+ graphics->fillRectangle(Rect(
static_cast<float>(pos.x * mWidthProportion) / 32
+ mMapOriginX - offsetWidth,
static_cast<float>(pos.y * mHeightProportion) / 32
@@ -386,7 +384,7 @@ void Minimap::draw(gcn::Graphics *graphics)
const int offsetWidth = static_cast<int>(
mWidthProportion);
- graphics->fillRectangle(gcn::Rectangle(
+ graphics->fillRectangle(Rect(
static_cast<int>(member->getX()
* mWidthProportion) + mMapOriginX - offsetWidth,
static_cast<int>(member->getY()
@@ -401,8 +399,8 @@ void Minimap::draw(gcn::Graphics *graphics)
const Vector &pos = player_node->getPosition();
- const int gw = graph->getWidth();
- const int gh = graph->getHeight();
+ const int gw = graphics->getWidth();
+ const int gh = graphics->getHeight();
int x = static_cast<float>((pos.x - (gw / 2)
+ viewport->getCameraRelativeX())
* mWidthProportion) / 32 + mMapOriginX;
@@ -431,19 +429,19 @@ void Minimap::draw(gcn::Graphics *graphics)
}
graphics->setColor(userPalette->getColor(UserPalette::PC));
- graphics->drawRectangle(gcn::Rectangle(x, y, w, h));
+ graphics->drawRectangle(Rect(x, y, w, h));
graphics->popClipArea();
BLOCK_END("Minimap::draw")
}
-void Minimap::mouseReleased(gcn::MouseEvent &event)
+void Minimap::mouseReleased(MouseEvent &event)
{
Window::mouseReleased(event);
if (!player_node || !viewport)
return;
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
int x = event.getX();
int y = event.getY();
@@ -451,7 +449,7 @@ void Minimap::mouseReleased(gcn::MouseEvent &event)
player_node->navigateTo(x, y);
}
- else if (event.getButton() == gcn::MouseEvent::RIGHT)
+ else if (event.getButton() == MouseEvent::RIGHT)
{
int x = event.getX();
int y = event.getY();
@@ -460,16 +458,16 @@ void Minimap::mouseReleased(gcn::MouseEvent &event)
}
}
-void Minimap::mouseMoved(gcn::MouseEvent &event)
+void Minimap::mouseMoved(MouseEvent &event)
{
Window::mouseMoved(event);
const int x = event.getX();
const int y = event.getY();
- const gcn::Rectangle &rect = mDimension;
+ const Rect &rect = mDimension;
mTextPopup->show(x + rect.x, y + rect.y, mCaption);
}
-void Minimap::mouseExited(gcn::MouseEvent &event)
+void Minimap::mouseExited(MouseEvent &event)
{
Window::mouseExited(event);
mTextPopup->hide();
@@ -477,7 +475,7 @@ void Minimap::mouseExited(gcn::MouseEvent &event)
void Minimap::screenToMap(int &x, int &y)
{
- const gcn::Rectangle a = getChildrenArea();
+ const Rect a = getChildrenArea();
x = (x - a.x - mMapOriginX + mWidthProportion) / mWidthProportion;
y = (y - a.y - mMapOriginY + mHeightProportion) / mHeightProportion;
}
diff --git a/src/gui/windows/minimap.h b/src/gui/windows/minimap.h
index 90c08db0f..d99aea13d 100644
--- a/src/gui/windows/minimap.h
+++ b/src/gui/windows/minimap.h
@@ -60,13 +60,13 @@ class Minimap final : public Window, public ConfigListener
/**
* Draws the minimap.
*/
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
- void mouseMoved(gcn::MouseEvent &event) override final;
+ void mouseMoved(MouseEvent &event) override final;
- void mouseReleased(gcn::MouseEvent &event) override final;
+ void mouseReleased(MouseEvent &event) override final;
- void mouseExited(gcn::MouseEvent &event) override final;
+ void mouseExited(MouseEvent &event) override final;
void screenToMap(int &x, int &y);
diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp
index b5832c7b7..db4555b26 100644
--- a/src/gui/windows/ministatuswindow.cpp
+++ b/src/gui/windows/ministatuswindow.cpp
@@ -308,21 +308,21 @@ void MiniStatusWindow::logic()
BLOCK_END("MiniStatusWindow::logic")
}
-void MiniStatusWindow::draw(gcn::Graphics *graphics)
+void MiniStatusWindow::draw(Graphics *graphics)
{
BLOCK_START("MiniStatusWindow::draw")
drawChildren(graphics);
BLOCK_END("MiniStatusWindow::draw")
}
-void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event)
+void MiniStatusWindow::mouseMoved(MouseEvent &event)
{
Popup::mouseMoved(event);
const int x = event.getX();
const int y = event.getY();
- const gcn::Rectangle &rect = mDimension;
+ const Rect &rect = mDimension;
if (event.getSource() == mStatusBar)
{
mStatusPopup->view(x + rect.x, y + rect.y);
@@ -433,12 +433,12 @@ void MiniStatusWindow::mouseMoved(gcn::MouseEvent &event)
}
}
-void MiniStatusWindow::mousePressed(gcn::MouseEvent &event)
+void MiniStatusWindow::mousePressed(MouseEvent &event)
{
if (!viewport)
return;
- if (event.getButton() == gcn::MouseEvent::RIGHT)
+ if (event.getButton() == MouseEvent::RIGHT)
{
const ProgressBar *const bar = dynamic_cast<ProgressBar*>(
event.getSource());
@@ -452,7 +452,7 @@ void MiniStatusWindow::mousePressed(gcn::MouseEvent &event)
}
}
-void MiniStatusWindow::mouseExited(gcn::MouseEvent &event)
+void MiniStatusWindow::mouseExited(MouseEvent &event)
{
Popup::mouseExited(event);
@@ -535,12 +535,12 @@ void MiniStatusWindow::updateArrows()
StatusWindow::updateArrowsBar(mArrowsBar);
}
-gcn::Rectangle MiniStatusWindow::getChildrenArea()
+Rect MiniStatusWindow::getChildrenArea()
{
const int padding = mPadding;
const int padding2 = padding * 2;
- const gcn::Rectangle &rect = mDimension;
- return gcn::Rectangle(padding, padding,
+ const Rect &rect = mDimension;
+ return Rect(padding, padding,
rect.width - padding2,
rect.height - padding2);
}
diff --git a/src/gui/windows/ministatuswindow.h b/src/gui/windows/ministatuswindow.h
index 2a5903eca..0344d6c3a 100644
--- a/src/gui/windows/ministatuswindow.h
+++ b/src/gui/windows/ministatuswindow.h
@@ -24,7 +24,8 @@
#define GUI_WINDOWS_MINISTATUSWINDOW_H
#include "inventory.h"
-#include "depricatedlistener.h"
+
+#include "listeners/depricatedlistener.h"
#include "gui/widgets/popup.h"
@@ -68,13 +69,13 @@ class MiniStatusWindow final : public Popup,
void logic() override final;
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
- void mouseMoved(gcn::MouseEvent &mouseEvent) override final;
+ void mouseMoved(MouseEvent &mouseEvent) override final;
- void mousePressed(gcn::MouseEvent &event) override final;
+ void mousePressed(MouseEvent &event) override final;
- void mouseExited(gcn::MouseEvent &event) override final;
+ void mouseExited(MouseEvent &event) override final;
void showBar(const std::string &name, const bool visible);
@@ -87,7 +88,7 @@ class MiniStatusWindow final : public Popup,
std::vector <ProgressBar*> &getBars() A_WARN_UNUSED
{ return mBars; }
- gcn::Rectangle getChildrenArea() override final A_WARN_UNUSED;
+ Rect getChildrenArea() override final A_WARN_UNUSED;
#ifdef USE_PROFILER
void logicChildren();
diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp
index b441b724c..a1b2109fb 100644
--- a/src/gui/windows/npcdialog.cpp
+++ b/src/gui/windows/npcdialog.cpp
@@ -32,8 +32,8 @@
#include "being/being.h"
+#include "gui/font.h"
#include "gui/gui.h"
-#include "gui/sdlfont.h"
#include "gui/viewport.h"
#include "gui/windows/inventorywindow.h"
@@ -59,8 +59,6 @@
#include "utils/copynpaste.h"
#include "utils/gettext.h"
-#include <guichan/font.hpp>
-
#include "debug.h"
// TRANSLATORS: npc dialog button
@@ -80,18 +78,18 @@ typedef std::vector<Image *>::iterator ImageVectorIter;
NpcDialog::NpcDialog(const int npcId) :
// TRANSLATORS: npc dialog name
Window(_("NPC"), false, nullptr, "npc.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mNpcId(npcId),
mDefaultInt(0),
mDefaultString(),
mTextBox(new BrowserBox(this, BrowserBox::AUTO_WRAP, true,
"browserbox.xml")),
- mScrollArea(new ScrollArea(mTextBox,
+ mScrollArea(new ScrollArea(this, mTextBox,
getOptionBool("showtextbackground"), "npc_textbackground.xml")),
mText(),
mNewText(),
mItemList(new ExtendedListBox(this, this, "extendedlistbox.xml")),
- mListScrollArea(new ScrollArea(mItemList,
+ mListScrollArea(new ScrollArea(this, mItemList,
getOptionBool("showlistbackground"), "npc_listbackground.xml")),
mItems(),
mImages(),
@@ -113,7 +111,7 @@ NpcDialog::NpcDialog(const int npcId) :
mResetButton(new Button(this, _("Reset"), "reset", this)),
mInventory(new Inventory(Inventory::NPC, 1)),
mItemContainer(new ItemContainer(this, mInventory)),
- mItemScrollArea(new ScrollArea(mItemContainer,
+ mItemScrollArea(new ScrollArea(this, mItemContainer,
getOptionBool("showitemsbackground"), "npc_listbackground.xml")),
mInputState(NPC_INPUT_NONE),
mActionState(NPC_ACTION_WAIT),
@@ -170,7 +168,7 @@ NpcDialog::NpcDialog(const int npcId) :
mTextField->setVisible(true);
mIntField->setVisible(true);
- const gcn::Font *const fnt = mButton->getFont();
+ const Font *const fnt = mButton->getFont();
int width = std::max(fnt->getWidth(CAPTION_WAITING),
fnt->getWidth(CAPTION_NEXT));
width = std::max(width, fnt->getWidth(CAPTION_CLOSE));
@@ -295,7 +293,7 @@ void NpcDialog::showCloseButton()
buildLayout();
}
-void NpcDialog::action(const gcn::ActionEvent &event)
+void NpcDialog::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "ok")
@@ -965,10 +963,10 @@ void NpcDialog::clearDialogs()
mNpcDialogs.clear();
}
-void NpcDialog::mousePressed(gcn::MouseEvent &event)
+void NpcDialog::mousePressed(MouseEvent &event)
{
Window::mousePressed(event);
- if (event.getButton() == gcn::MouseEvent::RIGHT
+ if (event.getButton() == MouseEvent::RIGHT
&& event.getSource() == mTextBox)
{
if (viewport)
diff --git a/src/gui/windows/npcdialog.h b/src/gui/windows/npcdialog.h
index 5e679d7d1..5188c2fe2 100644
--- a/src/gui/windows/npcdialog.h
+++ b/src/gui/windows/npcdialog.h
@@ -23,14 +23,15 @@
#ifndef GUI_WINDOWS_NPCDIALOG_H
#define GUI_WINDOWS_NPCDIALOG_H
-#include "configlistener.h"
+#include "listeners/configlistener.h"
+
+#include "gui/models/extendedlistmodel.h"
-#include "gui/widgets/extendedlistmodel.h"
#include "gui/widgets/window.h"
#include "utils/stringvector.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
#include <list>
@@ -45,7 +46,6 @@ class ItemContainer;
class NpcDialog;
class PlayerBox;
class ScrollArea;
-class TextBox;
class TextField;
typedef std::map<int, NpcDialog*> NpcDialogs;
@@ -56,7 +56,7 @@ typedef std::map<int, NpcDialog*> NpcDialogs;
* \ingroup Interface
*/
class NpcDialog final : public Window,
- public gcn::ActionListener,
+ public ActionListener,
public ExtendedListModel,
public ConfigListener
{
@@ -77,7 +77,7 @@ class NpcDialog final : public Window,
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Sets the text shows in the dialog.
@@ -210,7 +210,7 @@ class NpcDialog final : public Window,
void clearRows();
- void mousePressed(gcn::MouseEvent &event);
+ void mousePressed(MouseEvent &event);
int isCloseState() const
{ return mActionState == NPC_ACTION_CLOSE; }
diff --git a/src/gui/windows/npcpostdialog.cpp b/src/gui/windows/npcpostdialog.cpp
index 63ae6f53b..3c63775fe 100644
--- a/src/gui/windows/npcpostdialog.cpp
+++ b/src/gui/windows/npcpostdialog.cpp
@@ -42,7 +42,7 @@ NpcPostDialog::DialogList NpcPostDialog::instances;
NpcPostDialog::NpcPostDialog(const int npcId):
// TRANSLATORS: npc post dialog caption
Window(_("NPC"), false, nullptr, "npcpost.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mNpcId(npcId),
mText(new TextBox(this)),
mSender(new TextField(this))
@@ -74,9 +74,9 @@ void NpcPostDialog::postInit()
mText->setEditable(true);
// create scroll box for letter text
- ScrollArea *const scrollArea = new ScrollArea(mText);
+ ScrollArea *const scrollArea = new ScrollArea(this, mText);
scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
- scrollArea->setDimension(gcn::Rectangle(
+ scrollArea->setDimension(Rect(
5, mSender->getHeight() + 5,
380, 140 - (mSender->getHeight() + sendButton->getHeight())));
@@ -98,7 +98,7 @@ NpcPostDialog::~NpcPostDialog()
instances.remove(this);
}
-void NpcPostDialog::action(const gcn::ActionEvent &event)
+void NpcPostDialog::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "send")
diff --git a/src/gui/windows/npcpostdialog.h b/src/gui/windows/npcpostdialog.h
index e111f150e..5396aad6e 100644
--- a/src/gui/windows/npcpostdialog.h
+++ b/src/gui/windows/npcpostdialog.h
@@ -25,13 +25,13 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
class TextBox;
class TextField;
class NpcPostDialog final : public Window,
- public gcn::ActionListener
+ public ActionListener
{
public:
/**
@@ -48,7 +48,7 @@ class NpcPostDialog final : public Window,
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void setVisible(bool visible) override final;
diff --git a/src/gui/windows/okdialog.cpp b/src/gui/windows/okdialog.cpp
index c16123abd..3d734b7ad 100644
--- a/src/gui/windows/okdialog.cpp
+++ b/src/gui/windows/okdialog.cpp
@@ -30,7 +30,7 @@
#include "utils/gettext.h"
-#include <guichan/font.hpp>
+#include "gui/font.h"
#include "debug.h"
@@ -40,7 +40,7 @@ OkDialog::OkDialog(const std::string &restrict title,
const bool showCenter, Window *const parent,
const int minWidth) :
Window(title, modal, parent, "ok.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mTextBox(new TextBox(this))
{
mTextBox->setEditable(false);
@@ -84,7 +84,7 @@ OkDialog::OkDialog(const std::string &restrict title,
soundManager.playGuiSound(SOUND_ERROR);
}
-void OkDialog::action(const gcn::ActionEvent &event)
+void OkDialog::action(const ActionEvent &event)
{
setActionEventId(event.getId());
distributeActionEvent();
diff --git a/src/gui/windows/okdialog.h b/src/gui/windows/okdialog.h
index 7d2ff070b..b8236dfbc 100644
--- a/src/gui/windows/okdialog.h
+++ b/src/gui/windows/okdialog.h
@@ -27,7 +27,7 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
class TextBox;
@@ -44,7 +44,7 @@ enum
* \ingroup GUI
*/
class OkDialog final : public Window,
- public gcn::ActionListener
+ public ActionListener
{
public:
/**
@@ -63,7 +63,7 @@ class OkDialog final : public Window,
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
private:
TextBox *mTextBox;
diff --git a/src/gui/windows/outfitwindow.cpp b/src/gui/windows/outfitwindow.cpp
index d686056ac..6fcea7d3a 100644
--- a/src/gui/windows/outfitwindow.cpp
+++ b/src/gui/windows/outfitwindow.cpp
@@ -51,7 +51,7 @@
OutfitWindow::OutfitWindow():
// TRANSLATORS: outfits window name
Window(_("Outfits"), false, nullptr, "outfits.xml"),
- gcn::ActionListener(),
+ ActionListener(),
// TRANSLATORS: outfits window button
mPreviousButton(new Button(this, _("<"), "previous", this)),
// TRANSLATORS: outfits window button
@@ -91,8 +91,8 @@ OutfitWindow::OutfitWindow():
setMinWidth(145);
setMinHeight(220);
- mCurrentLabel->setAlignment(gcn::Graphics::CENTER);
- mKeyLabel->setAlignment(gcn::Graphics::CENTER);
+ mCurrentLabel->setAlignment(Graphics::CENTER);
+ mKeyLabel->setAlignment(Graphics::CENTER);
mUnequipCheck->setActionEventId("unequip");
mUnequipCheck->addActionListener(this);
@@ -225,7 +225,7 @@ void OutfitWindow::save() const
serverConfig.setValue("OutfitAwayIndex", mAwayOutfit);
}
-void OutfitWindow::action(const gcn::ActionEvent &event)
+void OutfitWindow::action(const ActionEvent &event)
{
const std::string eventId = event.getId();
if (eventId == "next")
@@ -310,11 +310,10 @@ void OutfitWindow::copyOutfit(const int src, const int dst)
save();
}
-void OutfitWindow::draw(gcn::Graphics *graphics)
+void OutfitWindow::draw(Graphics *graphics)
{
BLOCK_START("OutfitWindow::draw")
Window::draw(graphics);
- Graphics *const g = static_cast<Graphics*>(graphics);
if (mCurrentOutfit < 0 || mCurrentOutfit
>= static_cast<signed int>(OUTFITS_COUNT))
@@ -326,12 +325,12 @@ void OutfitWindow::draw(gcn::Graphics *graphics)
{
const int itemX = mPadding + ((i % mGridWidth) * mBoxWidth);
const int itemY = mPadding + mTitleBarHeight
- + ((i / mGridWidth) * mBoxHeight);
+ + ((i / static_cast<unsigned int>(mGridWidth)) * mBoxHeight);
graphics->setColor(mBorderColor);
- graphics->drawRectangle(gcn::Rectangle(itemX, itemY, 32, 32));
+ graphics->drawRectangle(Rect(itemX, itemY, 32, 32));
graphics->setColor(mBackgroundColor);
- graphics->fillRectangle(gcn::Rectangle(itemX, itemY, 32, 32));
+ graphics->fillRectangle(Rect(itemX, itemY, 32, 32));
if (mItems[mCurrentOutfit][i] < 0)
continue;
@@ -348,7 +347,7 @@ void OutfitWindow::draw(gcn::Graphics *graphics)
const Image *const image = item->getImage();
if (image)
{
- g->drawImage2(image, itemX, itemY);
+ graphics->drawImage(image, itemX, itemY);
foundItem = true;
}
}
@@ -359,7 +358,7 @@ void OutfitWindow::draw(gcn::Graphics *graphics)
mItemColors[mCurrentOutfit][i]);
if (image)
{
- g->drawImage2(image, itemX, itemY);
+ graphics->drawImage(image, itemX, itemY);
image->decRef();
}
}
@@ -367,9 +366,9 @@ void OutfitWindow::draw(gcn::Graphics *graphics)
BLOCK_END("OutfitWindow::draw")
}
-void OutfitWindow::mouseDragged(gcn::MouseEvent &event)
+void OutfitWindow::mouseDragged(MouseEvent &event)
{
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
if (dragDrop.isEmpty() && mItemClicked)
{
@@ -410,12 +409,12 @@ void OutfitWindow::mouseDragged(gcn::MouseEvent &event)
Window::mouseDragged(event);
}
-void OutfitWindow::mousePressed(gcn::MouseEvent &event)
+void OutfitWindow::mousePressed(MouseEvent &event)
{
const int index = getIndexFromGrid(event.getX(), event.getY());
if (index == -1)
{
- if (event.getButton() == gcn::MouseEvent::RIGHT && viewport)
+ if (event.getButton() == MouseEvent::RIGHT && viewport)
{
viewport->showOutfitsPopup();
event.consume();
@@ -447,9 +446,9 @@ void OutfitWindow::mousePressed(gcn::MouseEvent &event)
Window::mousePressed(event);
}
-void OutfitWindow::mouseReleased(gcn::MouseEvent &event)
+void OutfitWindow::mouseReleased(MouseEvent &event)
{
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
if (mCurrentOutfit < 0 || mCurrentOutfit
>= static_cast<signed int>(OUTFITS_COUNT))
@@ -484,7 +483,7 @@ void OutfitWindow::mouseReleased(gcn::MouseEvent &event)
int OutfitWindow::getIndexFromGrid(const int pointX, const int pointY) const
{
- const gcn::Rectangle tRect = gcn::Rectangle(mPadding, mTitleBarHeight,
+ const Rect tRect = Rect(mPadding, mTitleBarHeight,
mGridWidth * mBoxWidth, mGridHeight * mBoxHeight);
if (!tRect.isPointInRect(pointX, pointY))
return -1;
diff --git a/src/gui/windows/outfitwindow.h b/src/gui/windows/outfitwindow.h
index eeedc2ec6..55948f834 100644
--- a/src/gui/windows/outfitwindow.h
+++ b/src/gui/windows/outfitwindow.h
@@ -25,7 +25,7 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
const unsigned int OUTFITS_COUNT = 100;
const unsigned int OUTFIT_ITEM_COUNT = 16;
@@ -35,7 +35,7 @@ class CheckBox;
class Label;
class OutfitWindow final : public Window,
- private gcn::ActionListener
+ private ActionListener
{
public:
/**
@@ -50,15 +50,15 @@ class OutfitWindow final : public Window,
*/
~OutfitWindow();
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
- void draw(gcn::Graphics *graphics) override final;
+ void draw(Graphics *graphics) override final;
- void mousePressed(gcn::MouseEvent &event) override final;
+ void mousePressed(MouseEvent &event) override final;
- void mouseDragged(gcn::MouseEvent &event) override final;
+ void mouseDragged(MouseEvent &event) override final;
- void mouseReleased(gcn::MouseEvent &event) override final;
+ void mouseReleased(MouseEvent &event) override final;
void load(const bool oldConfig = false);
@@ -115,8 +115,8 @@ class OutfitWindow final : public Window,
int mItems[OUTFITS_COUNT + 1][OUTFIT_ITEM_COUNT];
int mAwayOutfit;
- gcn::Color mBorderColor;
- gcn::Color mBackgroundColor;
+ Color mBorderColor;
+ Color mBackgroundColor;
unsigned char mItemColors[OUTFITS_COUNT + 1][OUTFIT_ITEM_COUNT];
bool mItemClicked;
bool mItemsUnequip[OUTFITS_COUNT];
diff --git a/src/gui/windows/questswindow.cpp b/src/gui/windows/questswindow.cpp
index e5f599f0f..eee3e4259 100644
--- a/src/gui/windows/questswindow.cpp
+++ b/src/gui/windows/questswindow.cpp
@@ -26,13 +26,15 @@
#include "being/localplayer.h"
-#include "gui/sdlfont.h"
+#include "gui/font.h"
+#include "gui/gui.h"
+
+#include "gui/models/questsmodel.h"
#include "gui/widgets/browserbox.h"
#include "gui/widgets/button.h"
#include "gui/widgets/layout.h"
#include "gui/widgets/extendedlistbox.h"
-#include "gui/widgets/extendednamesmodel.h"
#include "gui/widgets/itemlinkhandler.h"
#include "gui/widgets/scrollarea.h"
@@ -87,20 +89,6 @@ struct QuestItem final
bool broken;
};
-class QuestsModel final : public ExtendedNamesModel
-{
- public:
- QuestsModel() :
- ExtendedNamesModel()
- {
- }
-
- A_DELETE_COPY(QuestsModel)
-
- ~QuestsModel()
- { }
-};
-
struct QuestEffect final
{
QuestEffect() :
@@ -122,15 +110,15 @@ struct QuestEffect final
QuestsWindow::QuestsWindow() :
// TRANSLATORS: quests window name
Window(_("Quests"), false, nullptr, "quests.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mQuestsModel(new QuestsModel),
mQuestsListBox(new ExtendedListBox(this,
mQuestsModel, "extendedlistbox.xml")),
- mQuestScrollArea(new ScrollArea(mQuestsListBox,
+ mQuestScrollArea(new ScrollArea(this, mQuestsListBox,
getOptionBool("showlistbackground"), "quests_list_background.xml")),
mItemLinkHandler(new ItemLinkHandler),
mText(new BrowserBox(this, BrowserBox::AUTO_WRAP, true, "browserbox.xml")),
- mTextScrollArea(new ScrollArea(mText,
+ mTextScrollArea(new ScrollArea(this, mText,
getOptionBool("showtextbackground"), "quests_text_background.xml")),
// TRANSLATORS: quests window button
mCloseButton(new Button(this, _("Close"), "close", this)),
@@ -166,7 +154,7 @@ QuestsWindow::QuestsWindow() :
mText->setLinkHandler(mItemLinkHandler);
mTextScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
mQuestsListBox->setWidth(500);
- if (gui->getNpcFont()->getHeight() < 20)
+ if (gui && gui->getNpcFont()->getHeight() < 20)
mQuestsListBox->setRowHeight(20);
else
mQuestsListBox->setRowHeight(gui->getNpcFont()->getHeight());
@@ -318,7 +306,7 @@ void QuestsWindow::loadEffect(const int var, const XmlNodePtr node)
mAllEffects.push_back(effect);
}
-void QuestsWindow::action(const gcn::ActionEvent &event)
+void QuestsWindow::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "select")
diff --git a/src/gui/windows/questswindow.h b/src/gui/windows/questswindow.h
index 7ecc86c84..9000fcaa9 100644
--- a/src/gui/windows/questswindow.h
+++ b/src/gui/windows/questswindow.h
@@ -27,7 +27,7 @@
#include "utils/xml.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
#include <map>
#include <vector>
@@ -48,7 +48,7 @@ typedef std::map<int, const QuestEffect*> NpcQuestEffectMap;
typedef NpcQuestEffectMap::const_iterator NpcQuestEffectMapCIter;
class QuestsWindow final : public Window,
- public gcn::ActionListener
+ public ActionListener
{
public:
QuestsWindow();
@@ -57,7 +57,7 @@ class QuestsWindow final : public Window,
~QuestsWindow();
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void updateQuest(const int var, const int val);
diff --git a/src/gui/windows/quitdialog.cpp b/src/gui/windows/quitdialog.cpp
index ff9f669b7..98aa70c70 100644
--- a/src/gui/windows/quitdialog.cpp
+++ b/src/gui/windows/quitdialog.cpp
@@ -28,8 +28,9 @@
#include "soundconsts.h"
#include "soundmanager.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
#include "gui/viewport.h"
@@ -49,8 +50,8 @@
QuitDialog::QuitDialog(QuitDialog **const pointerToMe):
// TRANSLATORS: quit dialog name
Window(_("Quit"), true, nullptr, "quit.xml"),
- gcn::ActionListener(),
- gcn::KeyListener(),
+ ActionListener(),
+ KeyListener(),
mOptions(),
// TRANSLATORS: quit dialog button
mLogoutQuit(new RadioButton(this, _("Quit"), "quitdialog")),
@@ -147,7 +148,7 @@ void QuitDialog::placeOption(ContainerPlacer &placer,
mOptions.push_back(option);
}
-void QuitDialog::action(const gcn::ActionEvent &event)
+void QuitDialog::action(const ActionEvent &event)
{
soundManager.playGuiSound(SOUND_HIDE_WINDOW);
if (event.getId() == "ok")
@@ -202,20 +203,19 @@ void QuitDialog::action(const gcn::ActionEvent &event)
scheduleDelete();
}
-void QuitDialog::keyPressed(gcn::KeyEvent &keyEvent)
+void QuitDialog::keyPressed(KeyEvent &keyEvent)
{
- const int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int actionId = keyEvent.getActionId();
int dir = 0;
switch (actionId)
{
case Input::KEY_GUI_SELECT:
case Input::KEY_GUI_SELECT2:
- action(gcn::ActionEvent(nullptr, mOkButton->getActionEventId()));
+ action(ActionEvent(nullptr, mOkButton->getActionEventId()));
break;
case Input::KEY_GUI_CANCEL:
- action(gcn::ActionEvent(nullptr,
- mCancelButton->getActionEventId()));
+ action(ActionEvent(nullptr, mCancelButton->getActionEventId()));
break;
case Input::KEY_GUI_UP:
dir = -1;
diff --git a/src/gui/windows/quitdialog.h b/src/gui/windows/quitdialog.h
index ab395c7f4..8ce60d06c 100644
--- a/src/gui/windows/quitdialog.h
+++ b/src/gui/windows/quitdialog.h
@@ -25,8 +25,8 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/keylistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/keylistener.h"
#include <vector>
@@ -38,8 +38,9 @@ class RadioButton;
*
* \ingroup Interface
*/
-class QuitDialog final : public Window, public gcn::ActionListener,
- public gcn::KeyListener
+class QuitDialog final : public Window,
+ public ActionListener,
+ public KeyListener
{
public:
/**
@@ -61,9 +62,9 @@ class QuitDialog final : public Window, public gcn::ActionListener,
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
- void keyPressed(gcn::KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &keyEvent) override final;
private:
void placeOption(ContainerPlacer &placer,
diff --git a/src/gui/windows/registerdialog.cpp b/src/gui/windows/registerdialog.cpp
index 1867b6b40..50344f223 100644
--- a/src/gui/windows/registerdialog.cpp
+++ b/src/gui/windows/registerdialog.cpp
@@ -24,8 +24,9 @@
#include "client.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
#include "gui/windows/okdialog.h"
@@ -44,7 +45,7 @@
#include "debug.h"
WrongDataNoticeListener::WrongDataNoticeListener():
- gcn::ActionListener(),
+ ActionListener(),
mTarget(nullptr)
{
}
@@ -54,7 +55,7 @@ void WrongDataNoticeListener::setTarget(TextField *const textField)
mTarget = textField;
}
-void WrongDataNoticeListener::action(const gcn::ActionEvent &event)
+void WrongDataNoticeListener::action(const ActionEvent &event)
{
if (event.getId() == "ok" && mTarget)
mTarget->requestFocus();
@@ -63,8 +64,8 @@ void WrongDataNoticeListener::action(const gcn::ActionEvent &event)
RegisterDialog::RegisterDialog(LoginData *const data) :
// TRANSLATORS: register dialog name
Window(_("Register"), false, nullptr, "register.xml"),
- gcn::ActionListener(),
- gcn::KeyListener(),
+ ActionListener(),
+ KeyListener(),
mLoginData(data),
mUserField(new TextField(this, mLoginData->username)),
mPasswordField(new PasswordField(this, mLoginData->password)),
@@ -172,7 +173,7 @@ RegisterDialog::~RegisterDialog()
mWrongDataNoticeListener = nullptr;
}
-void RegisterDialog::action(const gcn::ActionEvent &event)
+void RegisterDialog::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "cancel")
@@ -281,23 +282,22 @@ void RegisterDialog::action(const gcn::ActionEvent &event)
}
}
-void RegisterDialog::keyPressed(gcn::KeyEvent &keyEvent)
+void RegisterDialog::keyPressed(KeyEvent &keyEvent)
{
if (keyEvent.isConsumed())
{
mRegisterButton->setEnabled(canSubmit());
return;
}
- const int actionId = static_cast<KeyEvent*>(
- &keyEvent)->getActionId();
+ const int actionId = keyEvent.getActionId();
if (actionId == static_cast<int>(Input::KEY_GUI_CANCEL))
{
- action(gcn::ActionEvent(nullptr, mCancelButton->getActionEventId()));
+ action(ActionEvent(nullptr, mCancelButton->getActionEventId()));
}
else if (actionId == static_cast<int>(Input::KEY_GUI_SELECT)
|| actionId == static_cast<int>(Input::KEY_GUI_SELECT2))
{
- action(gcn::ActionEvent(nullptr, mRegisterButton->getActionEventId()));
+ action(ActionEvent(nullptr, mRegisterButton->getActionEventId()));
}
else
{
diff --git a/src/gui/windows/registerdialog.h b/src/gui/windows/registerdialog.h
index 66c3e40b7..1d5b5e48b 100644
--- a/src/gui/windows/registerdialog.h
+++ b/src/gui/windows/registerdialog.h
@@ -25,8 +25,8 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/keylistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/keylistener.h"
class Button;
class LoginData;
@@ -38,7 +38,7 @@ class TextField;
* to the field which contained wrong data when the Ok button was pressed on
* the error notice.
*/
-class WrongDataNoticeListener final : public gcn::ActionListener
+class WrongDataNoticeListener final : public ActionListener
{
public:
WrongDataNoticeListener();
@@ -47,7 +47,7 @@ class WrongDataNoticeListener final : public gcn::ActionListener
void setTarget(TextField *const textField);
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
private:
TextField *mTarget;
};
@@ -58,8 +58,8 @@ class WrongDataNoticeListener final : public gcn::ActionListener
* \ingroup Interface
*/
class RegisterDialog final : public Window,
- public gcn::ActionListener,
- public gcn::KeyListener
+ public ActionListener,
+ public KeyListener
{
public:
/**
@@ -82,12 +82,12 @@ class RegisterDialog final : public Window,
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override;
+ void action(const ActionEvent &event) override;
/**
* Called when a key is pressed in one of the text fields.
*/
- void keyPressed(gcn::KeyEvent &keyEvent) override;
+ void keyPressed(KeyEvent &keyEvent) override;
void close() override;
diff --git a/src/gui/windows/selldialog.cpp b/src/gui/windows/selldialog.cpp
index 15389a9c3..8bfcc6728 100644
--- a/src/gui/windows/selldialog.cpp
+++ b/src/gui/windows/selldialog.cpp
@@ -30,11 +30,12 @@
#include "gui/windows/confirmdialog.h"
#include "gui/windows/tradewindow.h"
+#include "gui/models/shopitems.h"
+
#include "gui/widgets/button.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layout.h"
#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/shopitems.h"
#include "gui/widgets/shoplistbox.h"
#include "gui/widgets/slider.h"
@@ -53,8 +54,8 @@ SellDialog::DialogList SellDialog::instances;
SellDialog::SellDialog(const int npcId) :
// TRANSLATORS: sell dialog name
Window(_("Sell"), false, nullptr, "sell.xml"),
- gcn::ActionListener(),
- gcn::SelectionListener(),
+ ActionListener(),
+ SelectionListener(),
mNpcId(npcId), mMaxItems(0), mAmountItems(0), mNick("")
{
init();
@@ -63,8 +64,8 @@ SellDialog::SellDialog(const int npcId) :
SellDialog::SellDialog(const std::string &nick):
// TRANSLATORS: sell dialog name
Window(_("Sell"), false, nullptr, "sell.xml"),
- gcn::ActionListener(),
- gcn::SelectionListener(),
+ ActionListener(),
+ SelectionListener(),
mNpcId(-1), mMaxItems(0), mAmountItems(0), mNick(nick)
{
init();
@@ -86,15 +87,15 @@ void SellDialog::init()
mShopItemList = new ShopListBox(this, mShopItems, mShopItems);
mShopItemList->postInit();
mShopItemList->setProtectItems(true);
- mScrollArea = new ScrollArea(mShopItemList,
+ mScrollArea = new ScrollArea(this, mShopItemList,
getOptionBool("showbackground"), "sell_background.xml");
mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
- mSlider = new Slider(1.0);
+ mSlider = new Slider(this, 1.0);
mQuantityLabel = new Label(this, strprintf(
"%d / %d", mAmountItems, mMaxItems));
- mQuantityLabel->setAlignment(gcn::Graphics::CENTER);
+ mQuantityLabel->setAlignment(Graphics::CENTER);
// TRANSLATORS: sell dialog label
mMoneyLabel = new Label(this, strprintf(_("Price: %s / Total: %s"),
"", ""));
@@ -185,7 +186,7 @@ void SellDialog::addItem(const int id, const unsigned char color,
}
-void SellDialog::action(const gcn::ActionEvent &event)
+void SellDialog::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
@@ -257,20 +258,10 @@ void SellDialog::action(const gcn::ActionEvent &event)
mMaxItems -= mAmountItems;
while (mAmountItems > 0)
{
-#ifdef MANASERV_SUPPORT
- // This order is important, item->getCurrentInvIndex() would
- // return the inventory index of the next Duplicate otherwise.
- int itemIndex = item->getCurrentInvIndex();
- const int sellCount = item->sellCurrentDuplicate(mAmountItems);
- // For Manaserv, the Item id is to be given as index.
- if ((Net::getNetworkType() == ServerInfo::MANASERV))
- itemIndex = item->getId();
-#else
// This order is important, item->getCurrentInvIndex() would
// return the inventory index of the next Duplicate otherwise.
const int itemIndex = item->getCurrentInvIndex();
const int sellCount = item->sellCurrentDuplicate(mAmountItems);
-#endif
Net::getNpcHandler()->sellItem(mNpcId, itemIndex, sellCount);
mAmountItems -= sellCount;
}
@@ -291,7 +282,7 @@ void SellDialog::action(const gcn::ActionEvent &event)
delete mShopItems->at(selectedItem);
mShopItems->erase(selectedItem);
- gcn::Rectangle scroll;
+ Rect scroll;
scroll.y = mShopItemList->getRowHeight() * (selectedItem + 1);
scroll.height = mShopItemList->getRowHeight();
mShopItemList->showPart(scroll);
@@ -309,7 +300,7 @@ void SellDialog::action(const gcn::ActionEvent &event)
}
}
-void SellDialog::valueChanged(const gcn::SelectionEvent &event A_UNUSED)
+void SellDialog::valueChanged(const SelectionEvent &event A_UNUSED)
{
// Reset amount of items and update labels
mAmountItems = 1;
diff --git a/src/gui/windows/selldialog.h b/src/gui/windows/selldialog.h
index 15db28f10..bd270919e 100644
--- a/src/gui/windows/selldialog.h
+++ b/src/gui/windows/selldialog.h
@@ -25,8 +25,8 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/selectionlistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/selectionlistener.h"
class Button;
class Item;
@@ -42,8 +42,8 @@ class Slider;
* \ingroup Interface
*/
class SellDialog final : public Window,
- private gcn::ActionListener,
- private gcn::SelectionListener
+ private ActionListener,
+ private SelectionListener
{
public:
/**
@@ -80,14 +80,14 @@ class SellDialog final : public Window,
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Updates labels according to selected item.
*
* @see SelectionListener::selectionChanged
*/
- void valueChanged(const gcn::SelectionEvent &event) override final;
+ void valueChanged(const SelectionEvent &event) override final;
/**
* Gives Player's Money amount
diff --git a/src/gui/windows/serverdialog.cpp b/src/gui/windows/serverdialog.cpp
index 3006922c3..af29da656 100644
--- a/src/gui/windows/serverdialog.cpp
+++ b/src/gui/windows/serverdialog.cpp
@@ -27,11 +27,16 @@
#include "configuration.h"
#include "main.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
-#include "gui/sdlfont.h"
+#include "gui/font.h"
+#include "gui/gui.h"
+
+#include "gui/models/serverslistmodel.h"
+#include "gui/widgets/checkbox.h"
#include "gui/windows/editserverdialog.h"
#include "gui/windows/logindialog.h"
@@ -44,8 +49,6 @@
#include "utils/gettext.h"
#include "utils/langs.h"
-#include <guichan/font.hpp>
-
#include <string>
#include "debug.h"
@@ -60,19 +63,10 @@ static std::string serverTypeToString(const ServerInfo::Type type)
return "TmwAthena";
case ServerInfo::EVOL:
return "Evol";
-#ifdef EATHENA_SUPPORT
case ServerInfo::EATHENA:
+#ifdef EATHENA_SUPPORT
return "eAthena";
#endif
-#ifdef MANASERV_SUPPORT
- case ServerInfo::MANASERV:
- return "ManaServ";
-#else
- case ServerInfo::MANASERV:
-#endif
-#ifndef EATHENA_SUPPORT
- case ServerInfo::EATHENA:
-#endif
default:
case ServerInfo::UNKNOWN:
return "";
@@ -87,60 +81,11 @@ static uint16_t defaultPortForServerType(const ServerInfo::Type type)
case ServerInfo::EATHENA:
#ifdef EATHENA_SUPPORT
return 6900;
-#else
- return 6901;
#endif
case ServerInfo::UNKNOWN:
case ServerInfo::TMWATHENA:
case ServerInfo::EVOL:
-#ifdef MANASERV_SUPPORT
- return 6901;
- case ServerInfo::MANASERV:
- return 9601;
-#else
- case ServerInfo::MANASERV:
return 6901;
-#endif
- }
-}
-
-ServersListModel::ServersListModel(ServerInfos *const servers,
- ServerDialog *const parent) :
- mServers(servers),
- mVersionStrings(servers->size(), VersionString(0, "")),
- mParent(parent)
-{
-}
-
-int ServersListModel::getNumberOfElements()
-{
- MutexLocker lock = mParent->lock();
- return static_cast<int>(mServers->size());
-}
-
-std::string ServersListModel::getElementAt(int elementIndex)
-{
- MutexLocker lock = mParent->lock();
- const ServerInfo &server = mServers->at(elementIndex);
- std::string myServer;
- myServer.append(server.hostname);
- return myServer;
-}
-
-void ServersListModel::setVersionString(const int index,
- const std::string &version)
-{
- if (index < 0 || index >= static_cast<int>(mVersionStrings.size()))
- return;
-
- if (version.empty())
- {
- mVersionStrings[index] = VersionString(0, "");
- }
- else
- {
- mVersionStrings[index] = VersionString(
- gui->getFont()->getWidth(version), version);
}
}
@@ -157,19 +102,18 @@ public:
mHighlightColor = getThemeColor(Theme::HIGHLIGHT);
}
- void draw(gcn::Graphics *graphics) override final
+ void draw(Graphics *graphics) override final
{
if (!mListModel)
return;
ServersListModel *const model = static_cast<ServersListModel *const>(
mListModel);
- Graphics *const g = static_cast<Graphics*>(graphics);
updateAlpha();
mHighlightColor.a = static_cast<int>(mAlpha * 255.0F);
- g->setColor(mHighlightColor);
+ graphics->setColor(mHighlightColor);
const int height = getRowHeight();
mNotSupportedColor.a = static_cast<int>(mAlpha * 255.0F);
@@ -177,13 +121,13 @@ public:
// Draw filled rectangle around the selected list element
if (mSelected >= 0)
{
- graphics->fillRectangle(gcn::Rectangle(mPadding,
+ graphics->fillRectangle(Rect(mPadding,
height * mSelected + mPadding, getWidth() - 2 * mPadding,
height));
}
- gcn::Font *const font1 = boldFont;
- gcn::Font *const font2 = getFont();
+ Font *const font1 = boldFont;
+ Font *const font2 = getFont();
const int fontHeight = font1->getHeight();
const int pad1 = fontHeight + mPadding;
const int pad2 = height / 4 + mPadding;
@@ -196,12 +140,12 @@ public:
if (mSelected == i)
{
- g->setColorAll(mForegroundSelectedColor,
+ graphics->setColorAll(mForegroundSelectedColor,
mForegroundSelectedColor2);
}
else
{
- g->setColorAll(mForegroundColor, mForegroundColor2);
+ graphics->setColorAll(mForegroundColor, mForegroundColor2);
}
int top;
@@ -224,7 +168,7 @@ public:
if (info.version.first > 0)
{
- g->setColorAll(mNotSupportedColor, mNotSupportedColor2);
+ graphics->setColorAll(mNotSupportedColor, mNotSupportedColor2);
font2->drawString(graphics, info.version.second,
width - info.version.first - mPadding, top);
}
@@ -236,8 +180,8 @@ public:
return 2 * getFont()->getHeight() + 5;
}
private:
- gcn::Color mNotSupportedColor;
- gcn::Color mNotSupportedColor2;
+ Color mNotSupportedColor;
+ Color mNotSupportedColor2;
};
@@ -245,9 +189,9 @@ ServerDialog::ServerDialog(ServerInfo *const serverInfo,
const std::string &dir) :
// TRANSLATORS: servers dialog name
Window(_("Choose Your Server"), false, nullptr, "server.xml"),
- gcn::ActionListener(),
- gcn::KeyListener(),
- gcn::SelectionListener(),
+ ActionListener(),
+ KeyListener(),
+ SelectionListener(),
mMutex(),
mDescription(new Label(this, std::string())),
// TRANSLATORS: servers dialog button
@@ -294,7 +238,7 @@ ServerDialog::ServerDialog(ServerInfo *const serverInfo,
mServersList->addMouseListener(this);
- ScrollArea *const usedScroll = new ScrollArea(mServersList,
+ ScrollArea *const usedScroll = new ScrollArea(this, mServersList,
getOptionBool("showbackground"), "server_background.xml");
usedScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -405,7 +349,7 @@ void ServerDialog::connectToSelectedServer()
client->setState(STATE_CONNECT_SERVER);
}
-void ServerDialog::action(const gcn::ActionEvent &event)
+void ServerDialog::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "connect")
@@ -445,9 +389,9 @@ void ServerDialog::action(const gcn::ActionEvent &event)
}
}
-void ServerDialog::keyPressed(gcn::KeyEvent &keyEvent)
+void ServerDialog::keyPressed(KeyEvent &keyEvent)
{
- switch (static_cast<KeyEvent*>(&keyEvent)->getActionId())
+ switch (keyEvent.getActionId())
{
case Input::KEY_GUI_CANCEL:
keyEvent.consume();
@@ -457,7 +401,7 @@ void ServerDialog::keyPressed(gcn::KeyEvent &keyEvent)
case Input::KEY_GUI_SELECT:
case Input::KEY_GUI_SELECT2:
keyEvent.consume();
- action(gcn::ActionEvent(nullptr,
+ action(ActionEvent(nullptr,
mConnectButton->getActionEventId()));
return;
@@ -495,7 +439,7 @@ void ServerDialog::keyPressed(gcn::KeyEvent &keyEvent)
mServersList->keyPressed(keyEvent);
}
-void ServerDialog::valueChanged(const gcn::SelectionEvent &)
+void ServerDialog::valueChanged(const SelectionEvent &)
{
const int index = mServersList->getSelected();
if (index == -1)
@@ -506,13 +450,13 @@ void ServerDialog::valueChanged(const gcn::SelectionEvent &)
mDeleteButton->setEnabled(true);
}
-void ServerDialog::mouseClicked(gcn::MouseEvent &mouseEvent)
+void ServerDialog::mouseClicked(MouseEvent &mouseEvent)
{
if (mouseEvent.getClickCount() == 2 &&
mouseEvent.getSource() == mServersList)
{
- action(gcn::ActionEvent(mConnectButton,
- mConnectButton->getActionEventId()));
+ action(ActionEvent(mConnectButton,
+ mConnectButton->getActionEventId()));
}
}
@@ -644,7 +588,7 @@ void ServerDialog::loadServers(const bool addNew)
version = strprintf(_("requires v%s"), version.c_str());
}
- const gcn::Font *const font = gui->getFont();
+ const Font *const font = gui->getFont();
for_each_xml_child_node(subNode, serverNode)
{
diff --git a/src/gui/windows/serverdialog.h b/src/gui/windows/serverdialog.h
index ad6f554c6..39c82279e 100644
--- a/src/gui/windows/serverdialog.h
+++ b/src/gui/windows/serverdialog.h
@@ -24,66 +24,23 @@
#define GUI_WINDOWS_SERVERDIALOG_H
#include "gui/widgets/window.h"
-#include "gui/widgets/checkbox.h"
#include "net/download.h"
#include "net/serverinfo.h"
#include "utils/mutex.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/keylistener.hpp>
-#include <guichan/listmodel.hpp>
-#include <guichan/selectionlistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/keylistener.h"
+#include "listeners/selectionlistener.h"
#include <string>
-#include <vector>
class Button;
+class CheckBox;
class Label;
class ListBox;
-class ServerDialog;
-
-/**
- * Server and Port List Model
- */
-class ServersListModel final : public gcn::ListModel
-{
- public:
- typedef std::pair<int, std::string> VersionString;
-
- ServersListModel(ServerInfos *const servers,
- ServerDialog *const parent);
-
- A_DELETE_COPY(ServersListModel)
-
- /**
- * Used to get number of line in the list
- */
- int getNumberOfElements() override final A_WARN_UNUSED;
-
- /**
- * Used to get an element from the list
- */
- std::string getElementAt(int elementIndex)
- override final A_WARN_UNUSED;
-
- /**
- * Used to get the corresponding Server struct
- */
- const ServerInfo &getServer(const int elementIndex) const A_WARN_UNUSED
- { return mServers->at(elementIndex); }
-
- void setVersionString(const int index, const std::string &version);
-
- private:
- typedef std::vector<VersionString> VersionStrings;
-
- ServerInfos *mServers;
- VersionStrings mVersionStrings;
- ServerDialog *mParent;
-};
-
+class ServersListModel;
/**
* The server choice dialog.
@@ -91,9 +48,9 @@ class ServersListModel final : public gcn::ListModel
* \ingroup Interface
*/
class ServerDialog final : public Window,
- public gcn::ActionListener,
- public gcn::KeyListener,
- public gcn::SelectionListener
+ public ActionListener,
+ public KeyListener,
+ public SelectionListener
{
public:
/**
@@ -115,16 +72,16 @@ class ServerDialog final : public Window,
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
- void keyPressed(gcn::KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &keyEvent) override final;
/**
* Called when the selected value changed in the servers list box.
*/
- void valueChanged(const gcn::SelectionEvent &event) override final;
+ void valueChanged(const SelectionEvent &event) override final;
- void mouseClicked(gcn::MouseEvent &mouseEvent) override final;
+ void mouseClicked(MouseEvent &mouseEvent) override final;
void logic() override final;
diff --git a/src/gui/windows/setupwindow.cpp b/src/gui/windows/setupwindow.cpp
index 0780865aa..2bcac85a5 100644
--- a/src/gui/windows/setupwindow.cpp
+++ b/src/gui/windows/setupwindow.cpp
@@ -44,6 +44,7 @@
#include "gui/widgets/tabs/setup_video.h"
#include "gui/widgets/tabs/setup_visual.h"
+#include "gui/widgets/button.h"
#include "gui/widgets/label.h"
#include "gui/widgets/tabbedarea.h"
@@ -58,7 +59,7 @@ SetupWindow *setupWindow = nullptr;
SetupWindow::SetupWindow() :
// TRANSLATORS: setup window name
Window(_("Setup"), false, nullptr, "setup.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mTabs(),
mModsTab(nullptr),
mWindowsToReset(),
@@ -112,7 +113,7 @@ void SetupWindow::postInit()
mResetWindows = btn;
}
- mPanel->setDimension(gcn::Rectangle(5, 5, width - 10, height - 40));
+ mPanel->setDimension(Rect(5, 5, width - 10, height - 40));
mPanel->enableScrollButtons(true);
mTabs.push_back(new Setup_Video(this));
@@ -149,7 +150,7 @@ void SetupWindow::postInit()
center();
- widgetResized(gcn::Event(nullptr));
+ widgetResized(Event(nullptr));
setInGame(false);
enableVisibleSound(true);
}
@@ -160,7 +161,7 @@ SetupWindow::~SetupWindow()
mButtons.clear();
}
-void SetupWindow::action(const gcn::ActionEvent &event)
+void SetupWindow::action(const ActionEvent &event)
{
if (Game::instance())
Game::instance()->resetAdjustLevel();
@@ -260,16 +261,16 @@ void SetupWindow::setVisible(bool visible)
Window::setVisible(visible);
}
-void SetupWindow::widgetResized(const gcn::Event &event)
+void SetupWindow::widgetResized(const Event &event)
{
Window::widgetResized(event);
- const gcn::Rectangle area = getChildrenArea();
+ const Rect area = getChildrenArea();
int x = area.width;
const int height = area.height;
const int width = area.width;
const int buttonPadding = getOption("buttonPadding", 5);
- mPanel->setDimension(gcn::Rectangle(5, 5, width - 10, height - 40));
+ mPanel->setDimension(Rect(5, 5, width - 10, height - 40));
FOR_EACH (std::vector<Button*>::iterator, it, mButtons)
{
Button *const btn = *it;
diff --git a/src/gui/windows/setupwindow.h b/src/gui/windows/setupwindow.h
index f5406e8ac..38b3eb206 100644
--- a/src/gui/windows/setupwindow.h
+++ b/src/gui/windows/setupwindow.h
@@ -25,7 +25,7 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
#include <list>
@@ -41,7 +41,7 @@ class TabbedArea;
* \ingroup GUI
*/
class SetupWindow final : public Window,
- public gcn::ActionListener
+ public ActionListener
{
public:
SetupWindow();
@@ -52,7 +52,7 @@ class SetupWindow final : public Window,
void postInit() override final;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void setInGame(const bool inGame);
@@ -71,7 +71,7 @@ class SetupWindow final : public Window,
void setVisible(bool visible) override final;
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
private:
void unloadModTab();
diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp
index a940e4cdb..32e249d35 100644
--- a/src/gui/windows/shopwindow.cpp
+++ b/src/gui/windows/shopwindow.cpp
@@ -27,12 +27,13 @@
#include "gui/windows/selldialog.h"
#include "gui/windows/tradewindow.h"
+#include "gui/models/shopitems.h"
+
#include "gui/widgets/button.h"
#include "gui/widgets/checkbox.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layout.h"
#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/shopitems.h"
#include "gui/widgets/shoplistbox.h"
#include "gui/widgets/tabs/chattab.h"
@@ -71,17 +72,17 @@ ShopWindow::DialogList ShopWindow::instances;
ShopWindow::ShopWindow():
// TRANSLATORS: shop window name
Window(_("Personal Shop"), false, nullptr, "shop.xml"),
- gcn::ActionListener(),
- gcn::SelectionListener(),
+ ActionListener(),
+ SelectionListener(),
// TRANSLATORS: shop window button
mCloseButton(new Button(this, _("Close"), "close", this)),
mBuyShopItems(new ShopItems),
mSellShopItems(new ShopItems),
mBuyShopItemList(new ShopListBox(this, mBuyShopItems, mBuyShopItems)),
mSellShopItemList(new ShopListBox(this, mSellShopItems, mSellShopItems)),
- mBuyScrollArea(new ScrollArea(mBuyShopItemList,
+ mBuyScrollArea(new ScrollArea(this, mBuyShopItemList,
getOptionBool("showbuybackground"), "shop_buy_background.xml")),
- mSellScrollArea(new ScrollArea(mSellShopItemList,
+ mSellScrollArea(new ScrollArea(this, mSellShopItemList,
getOptionBool("showsellbackground"), "shop_sell_background.xml")),
// TRANSLATORS: shop window label
mBuyLabel(new Label(this, _("Buy items"))),
@@ -205,7 +206,7 @@ ShopWindow::~ShopWindow()
instances.remove(this);
}
-void ShopWindow::action(const gcn::ActionEvent &event)
+void ShopWindow::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "close")
@@ -307,7 +308,7 @@ void ShopWindow::startTrade()
mTradeNick.clear();
}
-void ShopWindow::valueChanged(const gcn::SelectionEvent &event A_UNUSED)
+void ShopWindow::valueChanged(const SelectionEvent &event A_UNUSED)
{
updateButtonsAndLabels();
}
diff --git a/src/gui/windows/shopwindow.h b/src/gui/windows/shopwindow.h
index 95eee1e05..76971364b 100644
--- a/src/gui/windows/shopwindow.h
+++ b/src/gui/windows/shopwindow.h
@@ -25,8 +25,8 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/selectionlistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/selectionlistener.h"
class Button;
class CheckBox;
@@ -43,8 +43,8 @@ class ShopListBox;
* \ingroup Interface
*/
class ShopWindow final : public Window,
- public gcn::ActionListener,
- public gcn::SelectionListener
+ public ActionListener,
+ public SelectionListener
{
public:
enum ShopMode
@@ -72,12 +72,12 @@ class ShopWindow final : public Window,
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Updates the labels according to the selected item.
*/
- void valueChanged(const gcn::SelectionEvent &event) override final;
+ void valueChanged(const SelectionEvent &event) override final;
/**
* Updates the state of buttons and labels.
diff --git a/src/gui/windows/shortcutwindow.cpp b/src/gui/windows/shortcutwindow.cpp
index 96ec8c93c..5b3c03e90 100644
--- a/src/gui/windows/shortcutwindow.cpp
+++ b/src/gui/windows/shortcutwindow.cpp
@@ -40,7 +40,8 @@ class ShortcutTab final : public Tab
{
public:
ShortcutTab(const Widget2 *const widget,
- std::string name, ShortcutContainer *const content) :
+ std::string name,
+ ShortcutContainer *const content) :
Tab(widget),
mContent(content)
{
@@ -58,7 +59,7 @@ ShortcutWindow::ShortcutWindow(const std::string &restrict title,
int width, int height) :
Window("Window", false, nullptr, skinFile),
mItems(content),
- mScrollArea(new ScrollArea(mItems, false)),
+ mScrollArea(new ScrollArea(this, mItems, false)),
mTabs(nullptr),
mPages()
{
@@ -160,7 +161,7 @@ ShortcutWindow::~ShortcutWindow()
void ShortcutWindow::addTab(const std::string &name,
ShortcutContainer *const content)
{
- ScrollArea *const scroll = new ScrollArea(content, false);
+ ScrollArea *const scroll = new ScrollArea(this, content, false);
scroll->setPosition(SCROLL_PADDING, SCROLL_PADDING);
scroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
content->setWidget2(this);
@@ -176,7 +177,7 @@ int ShortcutWindow::getTabIndex() const
return mTabs->getSelectedTabIndex();
}
-void ShortcutWindow::widgetHidden(const gcn::Event &event)
+void ShortcutWindow::widgetHidden(const Event &event)
{
if (mItems)
mItems->widgetHidden(event);
@@ -195,21 +196,21 @@ void ShortcutWindow::widgetHidden(const gcn::Event &event)
}
}
-void ShortcutWindow::mousePressed(gcn::MouseEvent &event)
+void ShortcutWindow::mousePressed(MouseEvent &event)
{
Window::mousePressed(event);
if (event.isConsumed())
return;
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
mDragOffsetX = event.getX();
mDragOffsetY = event.getY();
}
}
-void ShortcutWindow::mouseDragged(gcn::MouseEvent &event)
+void ShortcutWindow::mouseDragged(MouseEvent &event)
{
Window::mouseDragged(event);
@@ -226,7 +227,7 @@ void ShortcutWindow::mouseDragged(gcn::MouseEvent &event)
}
}
-void ShortcutWindow::widgetMoved(const gcn::Event& event)
+void ShortcutWindow::widgetMoved(const Event& event)
{
Window::widgetMoved(event);
if (mItems)
diff --git a/src/gui/windows/shortcutwindow.h b/src/gui/windows/shortcutwindow.h
index f4c417c94..5e36e68d7 100644
--- a/src/gui/windows/shortcutwindow.h
+++ b/src/gui/windows/shortcutwindow.h
@@ -60,13 +60,13 @@ class ShortcutWindow final : public Window
int getTabIndex() const A_WARN_UNUSED;
- void widgetHidden(const gcn::Event &event) override final;
+ void widgetHidden(const Event &event) override final;
- void widgetMoved(const gcn::Event& event) override final;
+ void widgetMoved(const Event& event) override final;
- void mousePressed(gcn::MouseEvent &event) override final;
+ void mousePressed(MouseEvent &event) override final;
- void mouseDragged(gcn::MouseEvent &event) override final;
+ void mouseDragged(MouseEvent &event) override final;
void nextTab();
diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp
index 04baad26a..21cc009bc 100644
--- a/src/gui/windows/skilldialog.cpp
+++ b/src/gui/windows/skilldialog.cpp
@@ -29,10 +29,13 @@
#include "being/localplayer.h"
+#include "gui/font.h"
#include "gui/viewport.h"
#include "gui/popups/textpopup.h"
+#include "gui/models/skillmodel.h"
+
#include "gui/windows/setupwindow.h"
#include "gui/windows/shortcutwindow.h"
@@ -40,7 +43,6 @@
#include "gui/widgets/label.h"
#include "gui/widgets/listbox.h"
#include "gui/widgets/scrollarea.h"
-#include "gui/widgets/skillmodel.h"
#include "gui/widgets/tabs/tab.h"
#include "gui/widgets/tabbedarea.h"
@@ -53,14 +55,13 @@
#include "resources/beingcommon.h"
-#include <guichan/font.hpp>
-
#include "debug.h"
class SkillListBox final : public ListBox
{
public:
- SkillListBox(const Widget2 *const widget, SkillModel *const model) :
+ SkillListBox(const Widget2 *const widget,
+ SkillModel *const model) :
ListBox(widget, model, "skilllistbox.xml"),
mModel(model),
mPopup(new TextPopup),
@@ -100,15 +101,13 @@ class SkillListBox final : public ListBox
return static_cast<SkillModel*>(mListModel)->getSkillAt(selected);
}
- void draw(gcn::Graphics *gcnGraphics) override
+ void draw(Graphics *graphics) override
{
if (!mListModel)
return;
SkillModel *const model = static_cast<SkillModel*>(mListModel);
updateAlpha();
- Graphics *const graphics = static_cast<Graphics *const>(
- gcnGraphics);
mHighlightColor.a = static_cast<int>(mAlpha * 255.0F);
graphics->setColor(mHighlightColor);
@@ -116,14 +115,14 @@ class SkillListBox final : public ListBox
// Draw filled rectangle around the selected list element
if (mSelected >= 0)
{
- graphics->fillRectangle(gcn::Rectangle(mPadding, getRowHeight()
+ graphics->fillRectangle(Rect(mPadding, getRowHeight()
* mSelected + mPadding, getWidth() - 2 * mPadding,
getRowHeight()));
}
// Draw the list elements
graphics->setColorAll(mTextColor, mTextColor2);
- gcn::Font *const font = getFont();
+ Font *const font = getFont();
const int space = font->getHeight() + mSpacing;
const int width2 = getWidth() - mPadding;
for (int i = 0, y = 1;
@@ -136,7 +135,7 @@ class SkillListBox final : public ListBox
const SkillData *const data = e->data;
const int yPad = y + mPadding;
const std::string &description = data->description;
- graphics->drawImage2(data->icon, mPadding, yPad);
+ graphics->drawImage(data->icon, mPadding, yPad);
font->drawString(graphics, data->name, mTextPadding, yPad);
if (!description.empty())
{
@@ -159,7 +158,7 @@ class SkillListBox final : public ListBox
unsigned int getRowHeight() const override
{ return mRowHeight; }
- const SkillInfo *getSkillByEvent(const gcn::MouseEvent &event) const
+ const SkillInfo *getSkillByEvent(const MouseEvent &event) const
{
const int y = (event.getY() + mPadding) / getRowHeight();
if (!mModel || y >= mModel->getNumberOfElements())
@@ -170,7 +169,7 @@ class SkillListBox final : public ListBox
return skill;
}
- void mouseMoved(gcn::MouseEvent &event) override
+ void mouseMoved(MouseEvent &event) override
{
ListBox::mouseMoved(event);
if (!viewport || !dragDrop.isEmpty())
@@ -184,9 +183,9 @@ class SkillListBox final : public ListBox
skill->data->dispName, skill->data->description);
}
- void mouseDragged(gcn::MouseEvent &event)
+ void mouseDragged(MouseEvent &event)
{
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
if (dragDrop.isEmpty())
{
@@ -208,10 +207,10 @@ class SkillListBox final : public ListBox
}
}
- void mousePressed(gcn::MouseEvent &event)
+ void mousePressed(MouseEvent &event)
{
ListBox::mousePressed(event);
- if (event.getButton() == gcn::MouseEvent::LEFT)
+ if (event.getButton() == MouseEvent::LEFT)
{
const SkillInfo *const skill = getSkillByEvent(event);
if (!skill)
@@ -220,12 +219,12 @@ class SkillListBox final : public ListBox
}
}
- void mouseReleased(gcn::MouseEvent &event)
+ void mouseReleased(MouseEvent &event)
{
ListBox::mouseReleased(event);
}
- void mouseExited(gcn::MouseEvent &event A_UNUSED) override
+ void mouseExited(MouseEvent &event A_UNUSED) override
{
mPopup->hide();
}
@@ -233,8 +232,8 @@ class SkillListBox final : public ListBox
private:
SkillModel *mModel;
TextPopup *mPopup;
- gcn::Color mTextColor;
- gcn::Color mTextColor2;
+ Color mTextColor;
+ Color mTextColor2;
int mTextPadding;
int mSpacing;
bool mSkillClicked;
@@ -244,7 +243,8 @@ class SkillTab final : public Tab
{
public:
SkillTab(const Widget2 *const widget,
- const std::string &name, SkillListBox *const listBox) :
+ const std::string &name,
+ SkillListBox *const listBox) :
Tab(widget),
mListBox(listBox)
{
@@ -281,7 +281,7 @@ class SkillTab final : public Tab
SkillDialog::SkillDialog() :
// TRANSLATORS: skills dialog name
Window(_("Skills"), false, nullptr, "skills.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mSkills(),
mTabs(new TabbedArea(this)),
mDeleteTabs(),
@@ -323,7 +323,7 @@ SkillDialog::~SkillDialog()
clearSkills();
}
-void SkillDialog::action(const gcn::ActionEvent &event)
+void SkillDialog::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "inc")
@@ -544,7 +544,7 @@ void SkillDialog::loadXmlFile(const std::string &fileName)
SkillListBox *const listbox = new SkillListBox(this, model);
listbox->setActionEventId("sel");
listbox->addActionListener(this);
- ScrollArea *const scroll = new ScrollArea(listbox, false);
+ ScrollArea *const scroll = new ScrollArea(this, listbox, false);
scroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
scroll->setVerticalScrollPolicy(ScrollArea::SHOW_ALWAYS);
@@ -619,7 +619,7 @@ SkillInfo* SkillDialog::getSkillByItem(const int itemId) const
return nullptr;
}
-void SkillDialog::widgetResized(const gcn::Event &event)
+void SkillDialog::widgetResized(const Event &event)
{
Window::widgetResized(event);
diff --git a/src/gui/windows/skilldialog.h b/src/gui/windows/skilldialog.h
index 4a6182d38..3bf64df9b 100644
--- a/src/gui/windows/skilldialog.h
+++ b/src/gui/windows/skilldialog.h
@@ -25,7 +25,7 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
const int SKILL_MIN_ID = 200000;
const unsigned int SKILL_VAR_MIN_ID = 1000000;
@@ -43,7 +43,8 @@ struct SkillInfo;
*
* \ingroup Interface
*/
-class SkillDialog final : public Window, public gcn::ActionListener
+class SkillDialog final : public Window,
+ public ActionListener
{
public:
SkillDialog();
@@ -57,7 +58,7 @@ class SkillDialog final : public Window, public gcn::ActionListener
/**
* Called when receiving actions from widget.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Update the given skill's display
@@ -87,7 +88,7 @@ class SkillDialog final : public Window, public gcn::ActionListener
bool hasSkills() const A_WARN_UNUSED
{ return !mSkills.empty(); }
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
void useItem(const int itemId) const;
diff --git a/src/gui/windows/socialwindow.cpp b/src/gui/windows/socialwindow.cpp
index 2385066be..f33534a85 100644
--- a/src/gui/windows/socialwindow.cpp
+++ b/src/gui/windows/socialwindow.cpp
@@ -33,6 +33,8 @@
#include "input/keyboardconfig.h"
+#include "gui/models/beingslistmodel.h"
+
#include "gui/windows/confirmdialog.h"
#include "gui/windows/okdialog.h"
#include "gui/windows/setupwindow.h"
@@ -41,6 +43,7 @@
#include "gui/windows/outfitwindow.h"
+#include "gui/widgets/avatarlistbox.h"
#include "gui/widgets/button.h"
#include "gui/widgets/browserbox.h"
#include "gui/widgets/label.h"
@@ -115,6 +118,11 @@ public:
virtual void selectIndex(const unsigned num A_UNUSED)
{ }
+ virtual void buildCounter(const int online A_UNUSED = 0,
+ const int total A_UNUSED = 0)
+ {
+ }
+
protected:
friend class SocialWindow;
@@ -157,11 +165,6 @@ protected:
socialWindow->setCounter(this, mCounterString);
}
- virtual void buildCounter(const int online A_UNUSED = 0,
- const int total A_UNUSED = 0)
- {
- }
-
TextDialog *mInviteDialog;
ConfirmDialog *mConfirmDialog;
ScrollArea *mScroll;
@@ -169,13 +172,14 @@ protected:
std::string mCounterString;
};
-class SocialGuildTab final : public SocialTab, public gcn::ActionListener
+class SocialGuildTab final : public SocialTab, public ActionListener
{
public:
SocialGuildTab(const Widget2 *const widget,
- Guild *const guild, const bool showBackground) :
+ Guild *const guild,
+ const bool showBackground) :
SocialTab(widget),
- gcn::ActionListener(),
+ ActionListener(),
mGuild(guild)
{
// TRANSLATORS: tab in social window
@@ -191,7 +195,7 @@ public:
mList = new AvatarListBox(this, guild);
mList->postInit();
- mScroll = new ScrollArea(mList, showBackground,
+ mScroll = new ScrollArea(this, mList, showBackground,
"social_background.xml");
mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
@@ -208,7 +212,7 @@ public:
mScroll = nullptr;
}
- void action(const gcn::ActionEvent &event) override final
+ void action(const ActionEvent &event) override final
{
const std::string &eventId = event.getId();
if (eventId == "do invite")
@@ -305,13 +309,14 @@ private:
Guild *mGuild;
};
-class SocialGuildTab2 final : public SocialTab, public gcn::ActionListener
+class SocialGuildTab2 final : public SocialTab, public ActionListener
{
public:
- SocialGuildTab2(const Widget2 *const widget, Guild *const guild,
+ SocialGuildTab2(const Widget2 *const widget,
+ Guild *const guild,
const bool showBackground) :
SocialTab(widget),
- gcn::ActionListener()
+ ActionListener()
{
// TRANSLATORS: tab in social window
setCaption(_("Guild"));
@@ -326,7 +331,7 @@ public:
mList = new AvatarListBox(this, guild);
mList->postInit();
- mScroll = new ScrollArea(mList, showBackground,
+ mScroll = new ScrollArea(this, mList, showBackground,
"social_background.xml");
mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
@@ -343,7 +348,7 @@ public:
mScroll = nullptr;
}
- void action(const gcn::ActionEvent &event A_UNUSED) override final
+ void action(const ActionEvent &event A_UNUSED) override final
{
}
@@ -372,13 +377,14 @@ public:
}
};
-class SocialPartyTab final : public SocialTab, public gcn::ActionListener
+class SocialPartyTab final : public SocialTab, public ActionListener
{
public:
SocialPartyTab(const Widget2 *const widget,
- Party *const party, const bool showBackground) :
+ Party *const party,
+ const bool showBackground) :
SocialTab(widget),
- gcn::ActionListener(),
+ ActionListener(),
mParty(party)
{
// TRANSLATORS: tab in social window
@@ -394,7 +400,7 @@ public:
mList = new AvatarListBox(this, party);
mList->postInit();
- mScroll = new ScrollArea(mList, showBackground,
+ mScroll = new ScrollArea(this, mList, showBackground,
"social_background.xml");
mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
@@ -411,7 +417,7 @@ public:
mScroll = nullptr;
}
- void action(const gcn::ActionEvent &event) override final
+ void action(const ActionEvent &event) override final
{
const std::string &eventId = event.getId();
if (eventId == "do invite")
@@ -499,52 +505,18 @@ private:
Party *mParty;
};
-class BeingsListModal final : public AvatarListModel
-{
-public:
- BeingsListModal() :
- AvatarListModel(),
- mMembers()
- {
- }
-
- A_DELETE_COPY(BeingsListModal)
-
- ~BeingsListModal()
- {
- delete_all(mMembers);
- mMembers.clear();
- }
-
- std::vector<Avatar*> *getMembers()
- {
- return &mMembers;
- }
-
- Avatar *getAvatarAt(int index) override final
- {
- return mMembers[index];
- }
-
- int getNumberOfElements() override final
- {
- return static_cast<int>(mMembers.size());
- }
-
- std::vector<Avatar*> mMembers;
-};
-
class SocialPlayersTab final : public SocialTab
{
public:
SocialPlayersTab(const Widget2 *const widget,
- std::string name, const bool showBackground) :
+ std::string name,
+ const bool showBackground) :
SocialTab(widget),
- mBeings(new BeingsListModal)
+ mBeings(new BeingsListModel)
{
mList = new AvatarListBox(this, mBeings);
mList->postInit();
- mScroll = new ScrollArea(mList, showBackground,
+ mScroll = new ScrollArea(this, mList, showBackground,
"social_background.xml");
mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
@@ -696,7 +668,7 @@ public:
}
private:
- BeingsListModal *mBeings;
+ BeingsListModel *mBeings;
};
@@ -706,11 +678,11 @@ public:
SocialNavigationTab(const Widget2 *const widget,
const bool showBackground) :
SocialTab(widget),
- mBeings(new BeingsListModal)
+ mBeings(new BeingsListModel)
{
mList = new AvatarListBox(this, mBeings);
mList->postInit();
- mScroll = new ScrollArea(mList, showBackground,
+ mScroll = new ScrollArea(this, mList, showBackground,
"social_background.xml");
mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
@@ -973,7 +945,7 @@ public:
}
private:
- BeingsListModal *mBeings;
+ BeingsListModel *mBeings;
};
@@ -1035,11 +1007,11 @@ public:
SocialAttackTab(const Widget2 *const widget,
const bool showBackground) :
SocialTab(widget),
- mBeings(new BeingsListModal)
+ mBeings(new BeingsListModel)
{
mList = new AvatarListBox(this, mBeings);
mList->postInit();
- mScroll = new ScrollArea(mList, showBackground,
+ mScroll = new ScrollArea(this, mList, showBackground,
"social_background.xml");
mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
@@ -1073,7 +1045,7 @@ public:
}
private:
- BeingsListModal *mBeings;
+ BeingsListModel *mBeings;
};
class SocialPickupTab final : public SocialTab
@@ -1082,11 +1054,11 @@ public:
SocialPickupTab(const Widget2 *const widget,
const bool showBackground) :
SocialTab(widget),
- mBeings(new BeingsListModal)
+ mBeings(new BeingsListModel)
{
mList = new AvatarListBox(this, mBeings);
mList->postInit();
- mScroll = new ScrollArea(mList, showBackground,
+ mScroll = new ScrollArea(this, mList, showBackground,
"social_background.xml");
mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
@@ -1118,7 +1090,7 @@ public:
}
private:
- BeingsListModal *mBeings;
+ BeingsListModel *mBeings;
};
@@ -1126,13 +1098,14 @@ class SocialFriendsTab final : public SocialTab
{
public:
SocialFriendsTab(const Widget2 *const widget,
- std::string name, const bool showBackground) :
+ std::string name,
+ const bool showBackground) :
SocialTab(widget),
- mBeings(new BeingsListModal)
+ mBeings(new BeingsListModel)
{
mList = new AvatarListBox(this, mBeings);
mList->postInit();
- mScroll = new ScrollArea(mList, showBackground,
+ mScroll = new ScrollArea(this, mList, showBackground,
"social_background.xml");
mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO);
@@ -1208,7 +1181,7 @@ public:
}
private:
- BeingsListModal *mBeings;
+ BeingsListModel *mBeings;
};
@@ -1242,7 +1215,7 @@ public:
A_DELETE_COPY(CreatePopup)
void handleLink(const std::string &link,
- gcn::MouseEvent *event A_UNUSED) override final
+ MouseEvent *event A_UNUSED) override final
{
if (link == "guild" && socialWindow)
{
@@ -1256,7 +1229,7 @@ public:
setVisible(false);
}
- void show(gcn::Widget *parent)
+ void show(Widget *parent)
{
if (!parent)
return;
@@ -1276,7 +1249,7 @@ private:
SocialWindow::SocialWindow() :
// TRANSLATORS: social window name
Window(_("Social"), false, nullptr, "social.xml"),
- gcn::ActionListener(),
+ ActionListener(),
PlayerRelationsListener(),
mGuildInvited(0),
mGuildAcceptDialog(nullptr),
@@ -1336,7 +1309,7 @@ void SocialWindow::postInit()
place(0, 1, mCountLabel);
place(0, 2, mTabs, 4, 4);
- widgetResized(gcn::Event(nullptr));
+ widgetResized(Event(nullptr));
loadWindowState();
@@ -1482,7 +1455,7 @@ bool SocialWindow::removeTab(Party *const party)
return true;
}
-void SocialWindow::action(const gcn::ActionEvent &event)
+void SocialWindow::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
@@ -1744,7 +1717,6 @@ void SocialWindow::slowLogic()
const unsigned int nowTime = cur_time;
if (mNeedUpdate && nowTime - mLastUpdateTime > 1)
{
- logger->log("soc update");
mPlayers->updateList();
mFriends->updateList();
mNeedUpdate = false;
@@ -1863,7 +1835,7 @@ void SocialWindow::updateParty()
}
}
-void SocialWindow::widgetResized(const gcn::Event &event)
+void SocialWindow::widgetResized(const Event &event)
{
Window::widgetResized(event);
if (mTabs)
diff --git a/src/gui/windows/socialwindow.h b/src/gui/windows/socialwindow.h
index e8dc44043..57fbd5be5 100644
--- a/src/gui/windows/socialwindow.h
+++ b/src/gui/windows/socialwindow.h
@@ -24,9 +24,8 @@
#include "gui/widgets/window.h"
-#include "being/playerrelationslistener.h"
-
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/playerrelationslistener.h"
#include <string>
#include <map>
@@ -48,7 +47,7 @@ class TextDialog;
* \ingroup Interface
*/
class SocialWindow final : public Window,
- private gcn::ActionListener,
+ private ActionListener,
public PlayerRelationsListener
{
public:
@@ -68,7 +67,7 @@ public:
bool removeTab(Party *const party);
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void showGuildInvite(const std::string &restrict guildName,
const int guildId,
@@ -123,7 +122,7 @@ public:
void updatePickupFilter();
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
void setCounter(const SocialTab *const tab, const std::string &str);
diff --git a/src/gui/windows/statuswindow.cpp b/src/gui/windows/statuswindow.cpp
index 80e86e66f..05172c9b3 100644
--- a/src/gui/windows/statuswindow.cpp
+++ b/src/gui/windows/statuswindow.cpp
@@ -113,7 +113,7 @@ class DerDisplay final : public AttrDisplay
{ return DERIVED; }
};
-class ChangeDisplay final : public AttrDisplay, gcn::ActionListener
+class ChangeDisplay final : public AttrDisplay, ActionListener
{
public:
ChangeDisplay(const Widget2 *const widget,
@@ -129,7 +129,7 @@ class ChangeDisplay final : public AttrDisplay, gcn::ActionListener
void setPointsNeeded(const int needed);
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
private:
int mNeeded;
@@ -142,7 +142,7 @@ class ChangeDisplay final : public AttrDisplay, gcn::ActionListener
StatusWindow::StatusWindow() :
Window(player_node ? player_node->getName() :
"?", false, nullptr, "status.xml"),
- gcn::ActionListener(),
+ ActionListener(),
// TRANSLATORS: status window label
mLvlLabel(new Label(this, strprintf(_("Level: %d"), 0))),
// TRANSLATORS: status window label
@@ -159,9 +159,9 @@ StatusWindow::StatusWindow() :
mJobLabel(nullptr),
mJobBar(nullptr),
mAttrCont(new VertContainer(this, 32)),
- mAttrScroll(new ScrollArea(mAttrCont, false)),
+ mAttrScroll(new ScrollArea(this, mAttrCont, false)),
mDAttrCont(new VertContainer(this, 32)),
- mDAttrScroll(new ScrollArea(mDAttrCont, false)),
+ mDAttrScroll(new ScrollArea(this, mDAttrCont, false)),
mCharacterPointsLabel(new Label(this, "C")),
mCorrectionPointsLabel(nullptr),
// TRANSLATORS: status window button
@@ -746,7 +746,7 @@ void StatusWindow::updateStatusBar(ProgressBar *const bar,
bar->setBackgroundColor(Theme::getThemeColor(Theme::STATUSBAR_OFF));
}
-void StatusWindow::action(const gcn::ActionEvent &event)
+void StatusWindow::action(const ActionEvent &event)
{
if (!chatWindow)
return;
@@ -820,7 +820,7 @@ ChangeDisplay::ChangeDisplay(const Widget2 *const widget,
const int id, const std::string &restrict name,
const std::string &restrict shortName) :
AttrDisplay(widget, id, name, shortName),
- gcn::ActionListener(),
+ ActionListener(),
mNeeded(1),
// TRANSLATORS: status window label
mPoints(new Label(this, _("Max"))),
@@ -873,7 +873,7 @@ void ChangeDisplay::setPointsNeeded(const int needed)
update();
}
-void ChangeDisplay::action(const gcn::ActionEvent &event)
+void ChangeDisplay::action(const ActionEvent &event)
{
if (Net::getPlayerHandler()->canCorrectAttributes() &&
event.getSource() == mDec)
diff --git a/src/gui/windows/statuswindow.h b/src/gui/windows/statuswindow.h
index 94f1aaa65..3b171a25e 100644
--- a/src/gui/windows/statuswindow.h
+++ b/src/gui/windows/statuswindow.h
@@ -23,11 +23,11 @@
#ifndef GUI_WINDOWS_STATUSWINDOW_H
#define GUI_WINDOWS_STATUSWINDOW_H
-#include "depricatedlistener.h"
+#include "listeners/depricatedlistener.h"
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
#include <map>
@@ -44,7 +44,7 @@ class VertContainer;
* \ingroup Interface
*/
class StatusWindow final : public Window,
- public gcn::ActionListener,
+ public ActionListener,
public DepricatedListener
{
public:
@@ -83,7 +83,7 @@ class StatusWindow final : public Window,
const int id,
const bool percent = true);
- void action(const gcn::ActionEvent &event) override;
+ void action(const ActionEvent &event) override;
void clearAttributes();
diff --git a/src/gui/windows/textcommandeditor.cpp b/src/gui/windows/textcommandeditor.cpp
index 4ae098a3c..dead469bc 100644
--- a/src/gui/windows/textcommandeditor.cpp
+++ b/src/gui/windows/textcommandeditor.cpp
@@ -27,6 +27,10 @@
#include "input/keyboardconfig.h"
+#include "gui/models/iconsmodel.h"
+#include "gui/models/magicschoolmodel.h"
+#include "gui/models/targettypemodel.h"
+
#include "gui/widgets/button.h"
#include "gui/widgets/dropdown.h"
#include "gui/widgets/inttextfield.h"
@@ -36,131 +40,12 @@
#include "utils/gettext.h"
-#include "resources/iteminfo.h"
-
-#include "resources/db/itemdb.h"
-
#include "debug.h"
-class IconsModal final : public gcn::ListModel
-{
-public:
- IconsModal() :
- mStrings()
- {
- const std::map<int, ItemInfo*> &items = ItemDB::getItemInfos();
- std::list<std::string> tempStrings;
-
- for (std::map<int, ItemInfo*>::const_iterator
- i = items.begin(), i_end = items.end();
- i != i_end; ++i)
- {
- if (i->first < 0)
- continue;
-
- const ItemInfo &info = (*i->second);
- const std::string name = info.getName();
- if (name != "unnamed" && !info.getName().empty()
- && info.getName() != "unnamed")
- {
- tempStrings.push_back(name);
- }
- }
- tempStrings.sort();
- mStrings.push_back("");
- FOR_EACH (std::list<std::string>::const_iterator, i, tempStrings)
- mStrings.push_back(*i);
- }
-
- A_DELETE_COPY(IconsModal)
-
- ~IconsModal()
- { }
-
- int getNumberOfElements() override final
- {
- return static_cast<int>(mStrings.size());
- }
-
- std::string getElementAt(int i) override final
- {
- if (i < 0 || i >= getNumberOfElements())
- return "???";
- return mStrings.at(i);
- }
-private:
- StringVect mStrings;
-};
-
-
-const char *TARGET_TYPE_TEXT[3] =
-{
- // TRANSLATORS: target type
- N_("No Target"),
- // TRANSLATORS: target type
- N_("Allow Target"),
- // TRANSLATORS: target type
- N_("Need Target"),
-};
-
-const char *MAGIC_SCHOOL_TEXT[6] =
-{
- // TRANSLATORS: magic school
- N_("General Magic"),
- // TRANSLATORS: magic school
- N_("Life Magic"),
- // TRANSLATORS: magic school
- N_("War Magic"),
- // TRANSLATORS: magic school
- N_("Transmute Magic"),
- // TRANSLATORS: magic school
- N_("Nature Magic"),
- // TRANSLATORS: magic school
- N_("Astral Magic")
-};
-
-class TargetTypeModel final : public gcn::ListModel
-{
-public:
- ~TargetTypeModel()
- { }
-
- int getNumberOfElements() override final
- {
- return 3;
- }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
- return TARGET_TYPE_TEXT[i];
- }
-};
-
-class MagicSchoolModel final : public gcn::ListModel
-{
-public:
- ~MagicSchoolModel()
- { }
-
- int getNumberOfElements() override final
- {
- return 6;
- }
-
- std::string getElementAt(int i) override final
- {
- if (i >= getNumberOfElements() || i < 0)
- return "???";
- return MAGIC_SCHOOL_TEXT[i];
- }
-};
-
TextCommandEditor::TextCommandEditor(TextCommand *const command) :
// TRANSLATORS: command editor name
Window(_("Command Editor"), false, nullptr, "commandeditor.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mIsMagicCommand(command->getCommandType() == TEXT_COMMAND_MAGIC),
mCommand(command),
// TRANSLATORS: command editor button
@@ -180,10 +65,10 @@ TextCommandEditor::TextCommandEditor(TextCommand *const command) :
// TRANSLATORS: command editor label
mTypeLabel(new Label(this, _("Target Type:"))),
mTypeDropDown(new DropDown(this, mTargetTypeModel)),
- mIconsModal(new IconsModal),
+ mIconsModel(new IconsModel),
// TRANSLATORS: command editor label
mIconLabel(new Label(this, _("Icon:"))),
- mIconDropDown(new DropDown(this, mIconsModal)),
+ mIconDropDown(new DropDown(this, mIconsModel)),
// TRANSLATORS: command editor label
mManaLabel(new Label(this, _("Mana:"))),
mManaField(new IntTextField(this, 0)),
@@ -306,15 +191,15 @@ void TextCommandEditor::postInit()
TextCommandEditor::~TextCommandEditor()
{
- delete mIconsModal;
- mIconsModal = nullptr;
+ delete mIconsModel;
+ mIconsModel = nullptr;
delete mTargetTypeModel;
mTargetTypeModel = nullptr;
delete mMagicSchoolModel;
mMagicSchoolModel = nullptr;
}
-void TextCommandEditor::action(const gcn::ActionEvent &event)
+void TextCommandEditor::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "magic")
diff --git a/src/gui/windows/textcommandeditor.h b/src/gui/windows/textcommandeditor.h
index a31cdbaf2..de7f3b1a4 100644
--- a/src/gui/windows/textcommandeditor.h
+++ b/src/gui/windows/textcommandeditor.h
@@ -25,11 +25,11 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
class Button;
class DropDown;
-class IconsModal;
+class IconsModel;
class IntTextField;
class Label;
class MagicSchoolModel;
@@ -38,7 +38,8 @@ class TargetTypeModel;
class TextCommand;
class TextField;
-class TextCommandEditor final : public Window, public gcn::ActionListener
+class TextCommandEditor final : public Window,
+ public ActionListener
{
public:
/**
@@ -55,7 +56,7 @@ class TextCommandEditor final : public Window, public gcn::ActionListener
void postInit() override final;
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
void scheduleDelete() override final;
@@ -82,7 +83,7 @@ class TextCommandEditor final : public Window, public gcn::ActionListener
TargetTypeModel *mTargetTypeModel;
Label *mTypeLabel;
DropDown *mTypeDropDown;
- IconsModal *mIconsModal;
+ IconsModel *mIconsModel;
Label *mIconLabel;
DropDown *mIconDropDown;
Label *mManaLabel;
diff --git a/src/gui/windows/textdialog.cpp b/src/gui/windows/textdialog.cpp
index 936f08c76..9b7bb3eb1 100644
--- a/src/gui/windows/textdialog.cpp
+++ b/src/gui/windows/textdialog.cpp
@@ -30,7 +30,7 @@
#include "utils/gettext.h"
-#include <guichan/font.hpp>
+#include "gui/font.h"
#include "debug.h"
@@ -41,7 +41,7 @@ TextDialog::TextDialog(const std::string &restrict title,
Window *const parent,
const bool isPassword):
Window(title, true, parent, "textdialog.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mTextField(nullptr),
mPasswordField(nullptr),
// TRANSLATORS: text dialog button
@@ -68,7 +68,7 @@ TextDialog::TextDialog(const std::string &restrict title,
place(2, 2, mOkButton);
place(3, 2, cancelButton);
- const gcn::Font *const font = getFont();
+ const Font *const font = getFont();
if (font)
{
int width = font->getWidth(title);
@@ -104,7 +104,7 @@ TextDialog::~TextDialog()
instances--;
}
-void TextDialog::action(const gcn::ActionEvent &event)
+void TextDialog::action(const ActionEvent &event)
{
if (event.getId() == "CANCEL")
setActionEventId("~" + getActionEventId());
diff --git a/src/gui/windows/textdialog.h b/src/gui/windows/textdialog.h
index 9bfb4ae5f..8e69e8a3d 100644
--- a/src/gui/windows/textdialog.h
+++ b/src/gui/windows/textdialog.h
@@ -25,7 +25,7 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
class Button;
class PasswordField;
@@ -36,7 +36,8 @@ class TextField;
*
* \ingroup GUI
*/
-class TextDialog final : public Window, public gcn::ActionListener
+class TextDialog final : public Window,
+ public ActionListener
{
public:
/**
@@ -58,7 +59,7 @@ public:
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Get the text in the textfield
diff --git a/src/gui/windows/tradewindow.cpp b/src/gui/windows/tradewindow.cpp
index a379f0f28..506f25c17 100644
--- a/src/gui/windows/tradewindow.cpp
+++ b/src/gui/windows/tradewindow.cpp
@@ -31,7 +31,8 @@
#include "being/playerinfo.h"
#include "being/playerrelations.h"
-#include "gui/sdlfont.h"
+#include "gui/font.h"
+#include "gui/gui.h"
#include "gui/windows/inventorywindow.h"
#include "gui/windows/itemamountwindow.h"
@@ -51,8 +52,6 @@
#include "utils/gettext.h"
-#include <guichan/font.hpp>
-
#include "debug.h"
// TRANSLATORS: trade window button
@@ -67,8 +66,8 @@
TradeWindow::TradeWindow():
// TRANSLATORS: trade window caption
Window(_("Trade: You"), false, nullptr, "trade.xml"),
- gcn::ActionListener(),
- gcn::SelectionListener(),
+ ActionListener(),
+ SelectionListener(),
mMyInventory(new Inventory(Inventory::TRADE)),
mPartnerInventory(new Inventory(Inventory::TRADE)),
mMyItemContainer(new ItemContainer(this, mMyInventory.get())),
@@ -102,7 +101,7 @@ TradeWindow::TradeWindow():
if (setupWindow)
setupWindow->registerWindowForReset(this);
- const gcn::Font *const fnt = mOkButton->getFont();
+ const Font *const fnt = mOkButton->getFont();
int width = std::max(fnt->getWidth(CAPTION_PROPOSE),
fnt->getWidth(CAPTION_CONFIRMED));
width = std::max(width, fnt->getWidth(CAPTION_ACCEPT));
@@ -112,13 +111,14 @@ TradeWindow::TradeWindow():
mMyItemContainer->addSelectionListener(this);
- ScrollArea *const myScroll = new ScrollArea(mMyItemContainer,
+ ScrollArea *const myScroll = new ScrollArea(this, mMyItemContainer,
true, "trade_background.xml");
myScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
mPartnerItemContainer->addSelectionListener(this);
- ScrollArea *const partnerScroll = new ScrollArea(mPartnerItemContainer,
+ ScrollArea *const partnerScroll = new ScrollArea(this,
+ mPartnerItemContainer,
true, "trade_background.xml");
partnerScroll->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER);
@@ -130,8 +130,7 @@ TradeWindow::TradeWindow():
place(1, 0, mMoneyLabel);
place(0, 1, myScroll).setPadding(3);
place(1, 1, partnerScroll).setPadding(3);
- ContainerPlacer placer;
- placer = getPlacer(0, 0);
+ ContainerPlacer placer = getPlacer(0, 0);
placer(0, 0, moneyLabel2);
placer(1, 0, mMoneyField, 2);
placer(3, 0, mMoneyChangeButton).setHAlign(LayoutCell::LEFT);
@@ -268,7 +267,7 @@ void TradeWindow::tradeItem(const Item *const item, const int quantity,
Net::getTradeHandler()->addItem(item, quantity);
}
-void TradeWindow::valueChanged(const gcn::SelectionEvent &event)
+void TradeWindow::valueChanged(const SelectionEvent &event)
{
if (!mMyItemContainer || !mPartnerItemContainer)
return;
@@ -318,7 +317,7 @@ void TradeWindow::setStatus(const Status s)
mOkButton->setEnabled((s != PROPOSING && s != ACCEPTED));
}
-void TradeWindow::action(const gcn::ActionEvent &event)
+void TradeWindow::action(const ActionEvent &event)
{
if (!inventoryWindow)
return;
diff --git a/src/gui/windows/tradewindow.h b/src/gui/windows/tradewindow.h
index ac49c1f52..9704c1e80 100644
--- a/src/gui/windows/tradewindow.h
+++ b/src/gui/windows/tradewindow.h
@@ -25,8 +25,8 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/selectionlistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/selectionlistener.h"
#include <memory>
@@ -43,8 +43,8 @@ class TextField;
* \ingroup Interface
*/
class TradeWindow final : public Window,
- private gcn::ActionListener,
- private gcn::SelectionListener
+ private ActionListener,
+ private SelectionListener
{
public:
/**
@@ -109,12 +109,12 @@ class TradeWindow final : public Window,
* Updates the labels and makes sure only one item is selected in
* either my inventory or partner inventory.
*/
- void valueChanged(const gcn::SelectionEvent &event) override final;
+ void valueChanged(const SelectionEvent &event) override final;
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
/**
* Closes the Trade Window, as well as telling the server that the
diff --git a/src/gui/windows/unregisterdialog.cpp b/src/gui/windows/unregisterdialog.cpp
index 76afb1539..3326ca2bb 100644
--- a/src/gui/windows/unregisterdialog.cpp
+++ b/src/gui/windows/unregisterdialog.cpp
@@ -45,7 +45,7 @@
UnRegisterDialog::UnRegisterDialog(LoginData *const data) :
// TRANSLATORS: unregister dialog name
Window(_("Unregister"), true, nullptr, "unregister.xml"),
- gcn::ActionListener(),
+ ActionListener(),
mLoginData(data),
mPasswordField(new PasswordField(this, mLoginData->password)),
// TRANSLATORS: unregister dialog. button.
@@ -101,7 +101,7 @@ UnRegisterDialog::~UnRegisterDialog()
mWrongDataNoticeListener = nullptr;
}
-void UnRegisterDialog::action(const gcn::ActionEvent &event)
+void UnRegisterDialog::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "cancel")
diff --git a/src/gui/windows/unregisterdialog.h b/src/gui/windows/unregisterdialog.h
index fd40810ac..206c05413 100644
--- a/src/gui/windows/unregisterdialog.h
+++ b/src/gui/windows/unregisterdialog.h
@@ -25,7 +25,7 @@
#include "gui/widgets/window.h"
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
class Button;
class LoginData;
@@ -37,7 +37,8 @@ class WrongDataNoticeListener;
*
* \ingroup Interface
*/
-class UnRegisterDialog final : public Window, public gcn::ActionListener
+class UnRegisterDialog final : public Window,
+ public ActionListener
{
public:
/**
@@ -56,7 +57,7 @@ class UnRegisterDialog final : public Window, public gcn::ActionListener
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
private:
LoginData *mLoginData;
diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp
index eab1bea1b..e72308da7 100644
--- a/src/gui/windows/updaterwindow.cpp
+++ b/src/gui/windows/updaterwindow.cpp
@@ -25,8 +25,9 @@
#include "client.h"
#include "configuration.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
#include "gui/widgets/browserbox.h"
#include "gui/widgets/button.h"
@@ -156,8 +157,8 @@ UpdaterWindow::UpdaterWindow(const std::string &restrict updateHost,
const int updateType):
// TRANSLATORS: updater window name
Window(_("Updating..."), false, nullptr, "update.xml"),
- gcn::ActionListener(),
- gcn::KeyListener(),
+ ActionListener(),
+ KeyListener(),
mDownloadStatus(UPDATE_NEWS),
mUpdateHost(updateHost),
mUpdatesDir(updatesDir),
@@ -189,7 +190,8 @@ UpdaterWindow::UpdaterWindow(const std::string &restrict updateHost,
"updateprogressbar.xml", "updateprogressbar_fill.xml")),
mBrowserBox(new BrowserBox(this, BrowserBox::AUTO_SIZE, true,
"browserbox.xml")),
- mScrollArea(new ScrollArea(mBrowserBox, true, "update_background.xml")),
+ mScrollArea(new ScrollArea(this, mBrowserBox,
+ true, "update_background.xml")),
mUpdateServerPath(mUpdateHost)
{
setWindowName("UpdaterWindow");
@@ -270,7 +272,7 @@ void UpdaterWindow::enable()
client->setState(STATE_LOAD_DATA);
}
-void UpdaterWindow::action(const gcn::ActionEvent &event)
+void UpdaterWindow::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "cancel")
@@ -290,12 +292,12 @@ void UpdaterWindow::action(const gcn::ActionEvent &event)
}
}
-void UpdaterWindow::keyPressed(gcn::KeyEvent &keyEvent)
+void UpdaterWindow::keyPressed(KeyEvent &keyEvent)
{
- const int actionId = static_cast<KeyEvent*>(&keyEvent)->getActionId();
+ const int actionId = keyEvent.getActionId();
if (actionId == static_cast<int>(Input::KEY_GUI_CANCEL))
{
- action(gcn::ActionEvent(nullptr, mCancelButton->getActionEventId()));
+ action(ActionEvent(nullptr, mCancelButton->getActionEventId()));
client->setState(STATE_LOGIN);
}
else if (actionId == static_cast<int>(Input::KEY_GUI_SELECT)
@@ -304,12 +306,11 @@ void UpdaterWindow::keyPressed(gcn::KeyEvent &keyEvent)
if (mDownloadStatus == UPDATE_COMPLETE ||
mDownloadStatus == UPDATE_ERROR)
{
- action(gcn::ActionEvent(nullptr, mPlayButton->getActionEventId()));
+ action(ActionEvent(nullptr, mPlayButton->getActionEventId()));
}
else
{
- action(gcn::ActionEvent(nullptr,
- mCancelButton->getActionEventId()));
+ action(ActionEvent(nullptr, mCancelButton->getActionEventId()));
}
}
}
@@ -971,7 +972,7 @@ unsigned long UpdaterWindow::getFileHash(const std::string &filePath)
}
void UpdaterWindow::handleLink(const std::string &link,
- gcn::MouseEvent *event A_UNUSED)
+ MouseEvent *event A_UNUSED)
{
if (strStartWith(link, "http://") || strStartWith(link, "https://"))
openBrowser(link);
diff --git a/src/gui/windows/updaterwindow.h b/src/gui/windows/updaterwindow.h
index bddd3ef9e..79d764752 100644
--- a/src/gui/windows/updaterwindow.h
+++ b/src/gui/windows/updaterwindow.h
@@ -30,8 +30,8 @@
#include "utils/mutex.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/keylistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/keylistener.h"
#include <string>
#include <vector>
@@ -69,9 +69,9 @@ struct UpdateFile final
* \ingroup GUI
*/
class UpdaterWindow final : public Window,
- public gcn::ActionListener,
+ public ActionListener,
public LinkHandler,
- public gcn::KeyListener
+ public KeyListener
{
public:
/**
@@ -119,14 +119,14 @@ class UpdaterWindow final : public Window,
void loadPatch();
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
- void keyPressed(gcn::KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &keyEvent) override final;
void logic() override final;
void handleLink(const std::string &link,
- gcn::MouseEvent *event A_UNUSED) override final;
+ MouseEvent *event A_UNUSED) override final;
void loadFile(std::string file);
diff --git a/src/gui/windows/whoisonline.cpp b/src/gui/windows/whoisonline.cpp
index fd54076ed..dabc8c7c1 100644
--- a/src/gui/windows/whoisonline.cpp
+++ b/src/gui/windows/whoisonline.cpp
@@ -87,7 +87,7 @@ WhoIsOnline::WhoIsOnline() :
mCurlError(new char[CURL_ERROR_SIZE]),
mBrowserBox(new BrowserBox(this, BrowserBox::AUTO_SIZE, true,
"onlinebrowserbox.xml")),
- mScrollArea(new ScrollArea(mBrowserBox, false)),
+ mScrollArea(new ScrollArea(this, mBrowserBox, false)),
mUpdateTimer(0),
mOnlinePlayers(),
mOnlineNicks(),
@@ -116,10 +116,10 @@ void WhoIsOnline::postInit()
setSaveVisible(true);
mUpdateButton->setEnabled(false);
- mUpdateButton->setDimension(gcn::Rectangle(5, 5, w - 10, 20 + 5));
+ mUpdateButton->setDimension(Rect(5, 5, w - 10, 20 + 5));
mBrowserBox->setOpaque(false);
- mScrollArea->setDimension(gcn::Rectangle(5, 20 + 10, w - 10, h - 10 - 30));
+ mScrollArea->setDimension(Rect(5, 20 + 10, w - 10, h - 10 - 30));
mScrollArea->setSize(w - 10, h - 10 - 30);
mBrowserBox->setLinkHandler(this);
@@ -133,7 +133,7 @@ void WhoIsOnline::postInit()
download();
- widgetResized(gcn::Event(nullptr));
+ widgetResized(Event(nullptr));
config.addListener("updateOnlineList", this);
config.addListener("groupFriends", this);
mGroupFriends = config.getBoolValue("groupFriends");
@@ -159,9 +159,9 @@ WhoIsOnline::~WhoIsOnline()
mOnlineNicks.clear();
}
-void WhoIsOnline::handleLink(const std::string& link, gcn::MouseEvent *event)
+void WhoIsOnline::handleLink(const std::string& link, MouseEvent *event)
{
- if (!event || event->getButton() == gcn::MouseEvent::LEFT)
+ if (!event || event->getButton() == MouseEvent::LEFT)
{
if (chatWindow)
{
@@ -177,7 +177,7 @@ void WhoIsOnline::handleLink(const std::string& link, gcn::MouseEvent *event)
}
}
}
- else if (event->getButton() == gcn::MouseEvent::RIGHT)
+ else if (event->getButton() == MouseEvent::RIGHT)
{
if (player_node && link == player_node->getName())
return;
@@ -683,7 +683,7 @@ void WhoIsOnline::slowLogic()
BLOCK_END("WhoIsOnline::slowLogic")
}
-void WhoIsOnline::action(const gcn::ActionEvent &event)
+void WhoIsOnline::action(const ActionEvent &event)
{
if (event.getId() == "update")
{
@@ -715,7 +715,7 @@ void WhoIsOnline::action(const gcn::ActionEvent &event)
}
}
-void WhoIsOnline::widgetResized(const gcn::Event &event)
+void WhoIsOnline::widgetResized(const Event &event)
{
Window::widgetResized(event);
updateSize();
@@ -723,7 +723,7 @@ void WhoIsOnline::widgetResized(const gcn::Event &event)
void WhoIsOnline::updateSize()
{
- const gcn::Rectangle area = getChildrenArea();
+ const Rect area = getChildrenArea();
if (mUpdateButton)
mUpdateButton->setWidth(area.width - 10);
diff --git a/src/gui/windows/whoisonline.h b/src/gui/windows/whoisonline.h
index 10a8be4b5..bc04c8066 100644
--- a/src/gui/windows/whoisonline.h
+++ b/src/gui/windows/whoisonline.h
@@ -23,14 +23,14 @@
#ifndef GUI_WINDOWS_WHOISONLINE_H
#define GUI_WINDOWS_WHOISONLINE_H
-#include "configlistener.h"
+#include "listeners/configlistener.h"
#include "gui/widgets/linkhandler.h"
#include "gui/widgets/window.h"
#include <set>
-#include <guichan/actionlistener.hpp>
+#include "listeners/actionlistener.h"
class BrowserBox;
class Button;
@@ -102,7 +102,7 @@ class OnlinePlayer final
*/
class WhoIsOnline final : public Window,
public LinkHandler,
- public gcn::ActionListener,
+ public ActionListener,
public ConfigListener
{
public:
@@ -128,15 +128,15 @@ public:
void loadList(std::vector<OnlinePlayer*> &list);
void handleLink(const std::string& link,
- gcn::MouseEvent *event) override final;
+ MouseEvent *event) override final;
void logic() override final;
void slowLogic();
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
- void widgetResized(const gcn::Event &event) override final;
+ void widgetResized(const Event &event) override final;
const std::set<OnlinePlayer*> &getOnlinePlayers() const A_WARN_UNUSED
{ return mOnlinePlayers; }
diff --git a/src/gui/windows/worldselectdialog.cpp b/src/gui/windows/worldselectdialog.cpp
index a3fd0fc73..77d167c82 100644
--- a/src/gui/windows/worldselectdialog.cpp
+++ b/src/gui/windows/worldselectdialog.cpp
@@ -24,14 +24,17 @@
#include "client.h"
+#include "events/keyevent.h"
+
#include "input/keydata.h"
-#include "input/keyevent.h"
#include "gui/widgets/button.h"
#include "gui/widgets/layout.h"
#include "gui/widgets/listbox.h"
#include "gui/widgets/scrollarea.h"
+#include "gui/models/worldlistmodel.h"
+
#include "net/loginhandler.h"
#include "net/net.h"
@@ -41,49 +44,11 @@
extern WorldInfo **server_info;
-/**
- * The list model for the server list.
- */
-class WorldListModel final : public gcn::ListModel
-{
- public:
- explicit WorldListModel(Worlds worlds) :
- mWorlds(worlds)
- {
- }
-
- A_DELETE_COPY(WorldListModel)
-
- ~WorldListModel()
- { }
-
- int getNumberOfElements() override final
- {
- return static_cast<int>(mWorlds.size());
- }
-
- std::string getElementAt(int i) override final
- {
- const WorldInfo *const si = mWorlds[i];
- if (si)
- {
- return std::string(si->name).append(" (").append(
- toString(si->online_users)).append(")");
- }
- else
- {
- return "???";
- }
- }
- private:
- Worlds mWorlds;
-};
-
WorldSelectDialog::WorldSelectDialog(Worlds worlds):
// TRANSLATORS: world select dialog name
Window(_("Select World"), false, nullptr, "world.xml"),
- gcn::ActionListener(),
- gcn::KeyListener(),
+ ActionListener(),
+ KeyListener(),
mWorldListModel(new WorldListModel(worlds)),
mWorldList(new ListBox(this, mWorldListModel, "")),
// TRANSLATORS: world dialog button
@@ -92,7 +57,7 @@ WorldSelectDialog::WorldSelectDialog(Worlds worlds):
mChooseWorld(new Button(this, _("Choose World"), "world", this))
{
mWorldList->postInit();
- ScrollArea *const worldsScroll = new ScrollArea(mWorldList,
+ ScrollArea *const worldsScroll = new ScrollArea(this, mWorldList,
getOptionBool("showbackground"), "world_background.xml");
worldsScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -134,7 +99,7 @@ WorldSelectDialog::~WorldSelectDialog()
mWorldListModel = nullptr;
}
-void WorldSelectDialog::action(const gcn::ActionEvent &event)
+void WorldSelectDialog::action(const ActionEvent &event)
{
const std::string &eventId = event.getId();
if (eventId == "world")
@@ -153,19 +118,18 @@ void WorldSelectDialog::action(const gcn::ActionEvent &event)
}
}
-void WorldSelectDialog::keyPressed(gcn::KeyEvent &keyEvent)
+void WorldSelectDialog::keyPressed(KeyEvent &keyEvent)
{
- const int actionId = static_cast<KeyEvent*>(
- &keyEvent)->getActionId();
+ const int actionId = keyEvent.getActionId();
if (actionId == static_cast<int>(Input::KEY_GUI_CANCEL))
{
- action(gcn::ActionEvent(nullptr,
+ action(ActionEvent(nullptr,
mChangeLoginButton->getActionEventId()));
}
else if (actionId == static_cast<int>(Input::KEY_GUI_SELECT)
|| actionId == static_cast<int>(Input::KEY_GUI_SELECT2))
{
- action(gcn::ActionEvent(nullptr, mChooseWorld->getActionEventId()));
+ action(ActionEvent(nullptr, mChooseWorld->getActionEventId()));
}
}
diff --git a/src/gui/windows/worldselectdialog.h b/src/gui/windows/worldselectdialog.h
index f7491689b..9d06ac25e 100644
--- a/src/gui/windows/worldselectdialog.h
+++ b/src/gui/windows/worldselectdialog.h
@@ -27,8 +27,8 @@
#include "net/worldinfo.h"
-#include <guichan/actionlistener.hpp>
-#include <guichan/keylistener.hpp>
+#include "listeners/actionlistener.h"
+#include "listeners/keylistener.h"
class Button;
class ListBox;
@@ -39,8 +39,9 @@ class WorldListModel;
*
* \ingroup Interface
*/
-class WorldSelectDialog final : public Window, public gcn::ActionListener,
- public gcn::KeyListener
+class WorldSelectDialog final : public Window,
+ public ActionListener,
+ public KeyListener
{
public:
/**
@@ -62,9 +63,9 @@ class WorldSelectDialog final : public Window, public gcn::ActionListener,
/**
* Called when receiving actions from the widgets.
*/
- void action(const gcn::ActionEvent &event) override final;
+ void action(const ActionEvent &event) override final;
- void keyPressed(gcn::KeyEvent &keyEvent) override final;
+ void keyPressed(KeyEvent &keyEvent) override final;
private:
WorldListModel *mWorldListModel;