ManaPlus
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes

#include <windowmenu.h>

Inheritance diagram for WindowMenu:
Container ConfigListener ActionListener SelectionListener MouseListener BasicContainer2 BasicContainer Widget WidgetDeathListener Widget2

Public Member Functions

 WindowMenu (const Widget2 *const widget)
 
 ~WindowMenu ()
 
void action (const ActionEvent &event)
 
void mousePressed (MouseEvent &event)
 
void mouseMoved (MouseEvent &event)
 
void mouseExited (MouseEvent &event)
 
std::map< std::string, ButtonInfo * > & getButtonNames ()
 
std::vector< Button * > & getButtons ()
 
std::vector< ButtonText * > & getButtonTexts ()
 
void showButton (const std::string &name, const Visible visible)
 
void loadButtons ()
 
void saveButtons () const
 
void optionChanged (const std::string &name)
 
- Public Member Functions inherited from Container
 Container (const Widget2 *const widget)
 
 ~Container ()
 
bool safeRemove (Widget *const widget)
 
void removeControls ()
 
- Public Member Functions inherited from BasicContainer2
 BasicContainer2 (const Widget2 *const widget)
 
 ~BasicContainer2 ()
 
void setOpaque (Opaque opaque)
 
bool isOpaque () const
 
virtual void add (Widget *const widget)
 
void addXY (Widget *const widget, const int x, const int y)
 
void draw (Graphics *const graphics)
 
void safeDraw (Graphics *const graphics)
 
- Public Member Functions inherited from BasicContainer
 BasicContainer (const Widget2 *const widget)
 
 ~BasicContainer ()
 
void showWidgetPart (Widget *const widget, const Rect &area)
 
void moveToTop (Widget *const widget)
 
void moveToBottom (Widget *const widget)
 
Rect getChildrenArea ()
 
void focusNext ()
 
void focusPrevious ()
 
void logic ()
 
void setFocusHandler (FocusHandler *const focusHandler)
 
void setInternalFocusHandler (FocusHandler *const focusHandler)
 
WidgetgetWidgetAt (int x, int y)
 
void death (const Event &event)
 
WidgetfindFirstWidget (const std::set< Widget *> &list)
 
void add (Widget *const widget)
 
virtual void remove (Widget *const widget)
 
virtual void clear ()
 
- Public Member Functions inherited from Widget
 Widget (const Widget2 *const widget)
 
 ~Widget ()
 
virtual void drawFrame (Graphics *graphics)
 
virtual void safeDrawFrame (Graphics *graphics)
 
void setFrameSize (const unsigned int frameSize)
 
unsigned int getFrameSize () const
 
WidgetgetParent () const
 
void setWidth (const int width)
 
int getWidth () const
 
void setHeight (const int height)
 
int getHeight () const
 
void setSize (const int width, const int height)
 
void setX (const int x)
 
int getX () const
 
void setY (const int y)
 
int getY () const
 
void setPosition (const int x, const int y)
 
void setDimension (const Rect &dimension)
 
const RectgetDimension () const
 
void setFocusable (const bool focusable)
 
bool isFocusable () const
 
virtual bool isFocused () const
 
void setEnabled (const bool enabled)
 
bool isEnabled () const
 
void setVisible (Visible visible)
 
bool isVisible () const
 
void setBaseColor (const Color &color)
 
const ColorgetBaseColor () const
 
void setForegroundColor (const Color &color)
 
const ColorgetForegroundColor () const
 
void setBackgroundColor (const Color &color)
 
const ColorgetBackgroundColor () const
 
virtual void requestFocus ()
 
virtual void requestMoveToTop ()
 
virtual void requestMoveToBottom ()
 
FocusHandlergetFocusHandler ()
 
void addActionListener (ActionListener *const actionListener)
 
void removeActionListener (ActionListener *const actionListener)
 
void addDeathListener (WidgetDeathListener *const deathListener)
 
void removeDeathListener (WidgetDeathListener *const deathListener)
 
void addMouseListener (MouseListener *const mouseListener)
 
void removeMouseListener (MouseListener *const mouseListener)
 
void addKeyListener (KeyListener *const keyListener)
 
void removeKeyListener (KeyListener *const keyListener)
 
void addFocusListener (FocusListener *const focusListener)
 
void removeFocusListener (FocusListener *const focusListener)
 
void addWidgetListener (WidgetListener *const widgetListener)
 
void removeWidgetListener (WidgetListener *const widgetListener)
 
void setActionEventId (const std::string &actionEventId)
 
const std::string & getActionEventId () const
 
virtual void getAbsolutePosition (int &x, int &y) const
 
virtual void setParent (Widget *parent)
 
FontgetFont () const
 
void setFont (Font *const font)
 
virtual void fontChanged ()
 
bool isTabInEnabled () const
 
void setTabInEnabled (const bool enabled)
 
bool isTabOutEnabled () const
 
void setTabOutEnabled (const bool enabled)
 
void requestModalFocus ()
 
virtual void requestModalMouseInputFocus ()
 
virtual void releaseModalFocus ()
 
virtual void releaseModalMouseInputFocus ()
 
virtual bool isModalFocused () const
 
virtual bool isModalMouseInputFocused () const
 
const std::list< MouseListener * > & getMouseListeners () const A_CONST
 
const std::list< KeyListener * > & getKeyListeners () const A_CONST
 
const std::list< FocusListener * > & getFocusListeners () const A_CONST
 
virtual FocusHandlergetInternalFocusHandler ()
 
void setInternalFocusHandler (FocusHandler *const internalFocusHandler)
 
void setId (const std::string &id)
 
const std::string & getId () const
 
virtual void showPart (const Rect &rectangle)
 
bool isAllowLogic () const
 
void setMouseConsume (const bool b)
 
bool isMouseConsume () const
 
void setRedraw (const bool b)
 
virtual bool isSelectable () const
 
void setSelectable (const bool selectable)
 
void windowResized ()
 
virtual void postInit ()
 
- Public Member Functions inherited from Widget2
virtual ~Widget2 ()
 
const ColorgetThemeColor (const ThemeColorIdT type, const unsigned int alpha) const A_INLINE
 
const ColorgetThemeCharColor (const signed char c, bool &valid) const A_INLINE
 
virtual void setWidget2 (const Widget2 *const widget)
 
void setPalette (int palette)
 
void checkPalette ()
 
void setForegroundColor2 (const Color &color)
 
WidgetgetWindow () const
 
virtual void setWindow (Widget *const window)
 
- Public Member Functions inherited from WidgetDeathListener
virtual ~WidgetDeathListener ()
 
- Public Member Functions inherited from ConfigListener
 ConfigListener ()
 
virtual ~ConfigListener ()
 
- Public Member Functions inherited from ActionListener
virtual ~ActionListener ()
 
- Public Member Functions inherited from SelectionListener
virtual ~SelectionListener ()
 
virtual void valueChanged (const SelectionEvent &event)
 
- Public Member Functions inherited from MouseListener
virtual ~MouseListener ()
 
virtual void mouseEntered (MouseEvent &event)
 
virtual void mouseReleased (MouseEvent &event)
 
virtual void mouseClicked (MouseEvent &event)
 
virtual void mouseWheelMovedUp (MouseEvent &event)
 
virtual void mouseWheelMovedDown (MouseEvent &event)
 
virtual void mouseDragged (MouseEvent &event)
 

Protected Member Functions

void drawChildren (Graphics *const graphics)
 
void safeDrawChildren (Graphics *const graphics)
 
- Protected Member Functions inherited from BasicContainer
virtual void logicChildren ()
 
- Protected Member Functions inherited from Widget
void distributeActionEvent ()
 
void distributeResizedEvent ()
 
void distributeMovedEvent ()
 
void distributeHiddenEvent ()
 
void distributeShownEvent ()
 
- Protected Member Functions inherited from Widget2
 Widget2 (const Widget2 *const widget)
 
- Protected Member Functions inherited from WidgetDeathListener
 WidgetDeathListener ()
 
- Protected Member Functions inherited from ActionListener
 ActionListener ()
 
- Protected Member Functions inherited from SelectionListener
 SelectionListener ()
 
- Protected Member Functions inherited from MouseListener
 MouseListener ()
 

Private Member Functions

void addButton (const char *const text, const int iconNumber, const std::string &description, int &x, int &h, const InputActionT key, const Visible visible)
 
void updateButtons ()
 

Private Attributes

SkinmSkin
 
ImageSetmImageSet
 
int mPadding
 
int mSpacing
 
std::vector< Button * > mButtons
 
std::vector< ButtonText * > mButtonTexts
 
std::map< std::string, ButtonInfo * > mButtonNames
 
bool mHaveMouse
 
int mAutoHide
 
bool mSmallWindow
 

Additional Inherited Members

- Static Public Member Functions inherited from Widget
static void setGlobalFont (Font *const font)
 
static FontgetGloablFont ()
 
static void cleanGlobalFont ()
 
static bool widgetExists (const Widget *const widget)
 
static void distributeWindowResizeEvent ()
 
static WidgetcallPostInit (Widget *const widget)
 
- Data Fields inherited from Widget
Visible mVisible
 
- Protected Types inherited from BasicContainer
typedef std::vector< Widget * > WidgetList
 
typedef WidgetList::iterator WidgetListIterator
 
typedef WidgetList::const_iterator WidgetListConstIterator
 
typedef WidgetList::reverse_iterator WidgetListReverseIterator
 
typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator
 
- Protected Types inherited from Widget
typedef std::list< MouseListener * > MouseListenerList
 
typedef MouseListenerList::iterator MouseListenerIterator
 
typedef std::list< KeyListener * > KeyListenerList
 
typedef KeyListenerList::iterator KeyListenerIterator
 
typedef std::list< ActionListener * > ActionListenerList
 
typedef ActionListenerList::iterator ActionListenerIterator
 
typedef std::list< WidgetDeathListener * > WidgetDeathListenerList
 
typedef WidgetDeathListenerList::iterator WidgetDeathListenerIterator
 
typedef std::list< FocusListener * > FocusListenerList
 
typedef FocusListenerList::iterator FocusListenerIterator
 
typedef std::list< WidgetListener * > WidgetListenerList
 
typedef WidgetListenerList::iterator WidgetListenerIterator
 
- Protected Attributes inherited from BasicContainer2
Opaque mOpaque
 
- Protected Attributes inherited from BasicContainer
WidgetList mWidgets
 
WidgetList mLogicWidgets
 
- Protected Attributes inherited from Widget
MouseListenerList mMouseListeners
 
KeyListenerList mKeyListeners
 
ActionListenerList mActionListeners
 
WidgetDeathListenerList mDeathListeners
 
FocusListenerList mFocusListeners
 
WidgetListenerList mWidgetListeners
 
Color mForegroundColor
 
Color mBackgroundColor
 
Color mBaseColor
 
Rect mDimension
 
std::string mActionEventId
 
std::string mId
 
FocusHandlermFocusHandler
 
FocusHandlermInternalFocusHandler
 
WidgetmParent
 
FontmCurrentFont
 
unsigned int mFrameSize
 
bool mFocusable
 
bool mTabIn
 
bool mTabOut
 
bool mEnabled
 
bool mAllowLogic
 
bool mMouseConsume
 
bool mRedraw
 
bool mSelectable
 
- Protected Attributes inherited from Widget2
int mPaletteOffset
 
WidgetmWindow
 
Color mForegroundColor2
 
- Static Protected Attributes inherited from Widget
static FontmGlobalFont = 0
 

Detailed Description

The window menu. Allows showing and hiding many of the different windows used in the game.

Definition at line 48 of file windowmenu.h.

Constructor & Destructor Documentation

◆ WindowMenu()

WindowMenu::WindowMenu ( const Widget2 *const  widget)
explicit

Definition at line 52 of file windowmenu.cpp.

References _, addButton(), Configuration::addListener(), Widget::addMouseListener(), config, Theme::getImageSetFromTheme(), Configuration::getIntValue(), Skin::getOption(), SkillDialog::hasSkills(), loadButtons(), mainGraphics, mAutoHide, mImageSet, mPadding, mSkin, mSpacing, Graphics::mWidth, N_, Widget::setDimension(), Widget::setFocusable(), settings, Widget::setVisible(), InputAction::SHOW_WINDOWS, Settings::showButtonIcons, skillDialog, Visible_false, Visible_true, InputAction::WINDOW_BANK, InputAction::WINDOW_CART, InputAction::WINDOW_CHAT, InputAction::WINDOW_CLAN, InputAction::WINDOW_DEBUG, InputAction::WINDOW_DIDYOUKNOW, InputAction::WINDOW_DROP, InputAction::WINDOW_EMOTE_SHORTCUT, InputAction::WINDOW_EQUIPMENT, InputAction::WINDOW_HELP, InputAction::WINDOW_INVENTORY, InputAction::WINDOW_KILLS, InputAction::WINDOW_MAIL, InputAction::WINDOW_MINIMAP, InputAction::WINDOW_ONLINE, InputAction::WINDOW_OUTFIT, InputAction::WINDOW_QUESTS, InputAction::WINDOW_SERVER_INFO, InputAction::WINDOW_SETUP, InputAction::WINDOW_SHOP, InputAction::WINDOW_SHORTCUT, InputAction::WINDOW_SKILL, InputAction::WINDOW_SOCIAL, InputAction::WINDOW_SPELLS, InputAction::WINDOW_STATUS, InputAction::WINDOW_UPDATER, and x.

52  :
53  Container(widget),
57  MouseListener(),
58  mSkin(theme != nullptr ? theme->load("windowmenu.xml", "",
59  true, Theme::getThemePath()) : nullptr),
60  mImageSet(nullptr),
61  mPadding(mSkin != nullptr ? mSkin->getPadding() : 1),
62  mSpacing(mSkin != nullptr ? mSkin->getOption("spacing", 3) : 3),
63  mButtons(),
64  mButtonTexts(),
65  mButtonNames(),
66  mHaveMouse(false),
67  mAutoHide(1),
69 {
70  int x = mPadding;
71  int h = 0;
72 
73  setFocusable(false);
74 
76  {
77  mImageSet = Theme::getImageSetFromTheme("buttonsicons.png",
78  mSkin->getOption("imageWidth", 20),
79  mSkin->getOption("imageHeight", 20));
80  }
81 
82  // TRANSLATORS: short button name for who is online window.
83  addButton(N_("ONL"),
84  13,
85  // TRANSLATORS: long button name for who is online window.
86  _("Who is online"), x, h, InputAction::WINDOW_ONLINE,
87  Visible_true);
88  // TRANSLATORS: short button name for help window.
89  addButton(N_("HLP"),
90  0,
91  // TRANSLATORS: long button name for help window.
92  _("Help"), x, h, InputAction::WINDOW_HELP,
93  Visible_true);
94  // TRANSLATORS: short button name for quests window.
95  addButton(N_("QE"),
96  12,
97  // TRANSLATORS: long button name for quests window.
98  _("Quests"), x, h, InputAction::WINDOW_QUESTS,
99  Visible_true);
100  // TRANSLATORS: short button name for kill stats window.
101  addButton(N_("KS"),
102  16,
103  // TRANSLATORS: long button name for kill stats window.
104  _("Kill stats"), x, h, InputAction::WINDOW_KILLS,
105  Visible_true);
106  addButton(":-)",
107  6,
108  // TRANSLATORS: long button name for emotes window.
109  _("Smilies"), x, h, InputAction::WINDOW_EMOTE_SHORTCUT,
110  Visible_true);
111  // TRANSLATORS: short button name for chat window.
112  addButton(N_("CH"),
113  20,
114  // TRANSLATORS: longt button name for chat window.
115  _("Chat"), x, h, InputAction::WINDOW_CHAT,
116 #ifdef ANDROID
117  Visible_true);
118 #else // ANDROID
119  Visible_false);
120 #endif // ANDROID
121 
122  // TRANSLATORS: short button name for status window.
123  addButton(N_("STA"),
124  17,
125  // TRANSLATORS: long button name for status window.
126  _("Status"), x, h, InputAction::WINDOW_STATUS,
127  Visible_true);
128  // TRANSLATORS: short button name for equipment window.
129  addButton(N_("EQU"),
130  7,
131  // TRANSLATORS: long button name for equipment window.
132  _("Equipment"), x, h, InputAction::WINDOW_EQUIPMENT,
133  Visible_true);
134  // TRANSLATORS: short button name for inventory window.
135  addButton(N_("INV"),
136  9,
137  // TRANSLATORS: long button name for inventory window.
138  _("Inventory"), x, h, InputAction::WINDOW_INVENTORY,
139  Visible_true);
140  // TRANSLATORS: short button name for cart window.
141  addButton(N_("CA"),
142  11,
143  // TRANSLATORS: long button name for cart window.
144  _("Cart"), x, h, InputAction::WINDOW_CART,
145  Visible_true);
146  // TRANSLATORS: short button name for map window.
147  addButton(N_("MAP"),
148  19,
149  // TRANSLATORS: long button name for map window.
150  _("Map"), x, h, InputAction::WINDOW_MINIMAP,
151  Visible_false);
152 
153  if (skillDialog->hasSkills())
154  {
155  // TRANSLATORS: short button name for skills window.
156  addButton(N_("SKI"),
157  5,
158  // TRANSLATORS: long button name for skills window.
159  _("Skills"), x, h, InputAction::WINDOW_SKILL,
160  Visible_true);
161  }
162 
163  // TRANSLATORS: short button name for social window.
164  addButton(N_("SOC"),
165  1,
166  // TRANSLATORS: long button name for social window.
167  _("Social"), x, h, InputAction::WINDOW_SOCIAL,
168  Visible_true);
169  // TRANSLATORS: short button name for shortcuts window.
170  addButton(N_("SH"),
171  14,
172  // TRANSLATORS: long button name for shortcuts window.
173  _("Shortcuts"), x, h, InputAction::WINDOW_SHORTCUT,
174  Visible_true);
175  // TRANSLATORS: short button name for spells window.
176  addButton(N_("SP"),
177  15,
178  // TRANSLATORS: long button name for spells window.
179  _("Spells"), x, h, InputAction::WINDOW_SPELLS,
180  Visible_true);
181  // TRANSLATORS: short button name for drops window.
182  addButton(N_("DR"),
183  26,
184  // TRANSLATORS: long button name for drops window.
185  _("Drop"), x, h, InputAction::WINDOW_DROP,
186  Visible_false);
187  // TRANSLATORS: short button name for did you know window.
188  addButton(N_("YK"),
189  24,
190  // TRANSLATORS: long button name for did you know window.
191  _("Did you know"), x, h, InputAction::WINDOW_DIDYOUKNOW,
192  Visible_false);
193  // TRANSLATORS: short button name for shop window.
194  addButton(N_("SHP"),
195  18,
196  // TRANSLATORS: long button name for shop window.
197  _("Shop"), x, h, InputAction::WINDOW_SHOP,
198  Visible_false);
199  // TRANSLATORS: short button name for outfits window.
200  addButton(N_("OU"),
201  21,
202  // TRANSLATORS: long button name for outfits window.
203  _("Outfits"), x, h, InputAction::WINDOW_OUTFIT,
204  Visible_false);
205  // TRANSLATORS: short button name for updates window.
206  addButton(N_("UP"),
207  25,
208  // TRANSLATORS: long button name for updates window.
209  _("Updates"), x, h, InputAction::WINDOW_UPDATER,
210  Visible_false);
211  // TRANSLATORS: short button name for bank window.
212  addButton(N_("BA"),
213  2,
214  // TRANSLATORS: long button name for bank window.
215  _("Bank"), x, h, InputAction::WINDOW_BANK,
216  Visible_true);
217  // TRANSLATORS: short button name for mail window.
218  addButton(N_("MA"),
219  10,
220  // TRANSLATORS: long button name for mail window.
221  _("Mail"), x, h, InputAction::WINDOW_MAIL,
222  Visible_true);
223  // TRANSLATORS: short button name for clan window.
224  addButton(N_("CL"),
225  4,
226  // TRANSLATORS: long button name for clan window.
227  _("Clan"), x, h, InputAction::WINDOW_CLAN,
228  Visible_true);
229  // TRANSLATORS: short button name for server info window.
230  addButton(N_("SI"),
231  8,
232  // TRANSLATORS: long button name for server info window.
233  _("Server info"), x, h, InputAction::WINDOW_SERVER_INFO,
234  Visible_true);
235  // TRANSLATORS: short button name for debug window.
236  addButton(N_("DBG"),
237  22,
238  // TRANSLATORS: long button name for debug window.
239  _("Debug"), x, h, InputAction::WINDOW_DEBUG,
240 #ifdef ANDROID
241  Visible_true);
242 #else // ANDROID
243  Visible_false);
244 #endif // ANDROID
245 
246  // TRANSLATORS: short button name for windows list menu.
247  addButton(N_("WIN"),
248  23,
249  // TRANSLATORS: long button name for windows list menu.
250  _("Windows"), x, h, InputAction::SHOW_WINDOWS,
251  Visible_false);
252  // TRANSLATORS: short button name for setup window.
253  addButton(N_("SET"),
254  3,
255  // TRANSLATORS: long button name for setup window.
256  _("Setup"), x, h, InputAction::WINDOW_SETUP,
257  Visible_true);
258 
259  x += mPadding - mSpacing;
260  if (mainGraphics != nullptr)
261  setDimension(Rect(mainGraphics->mWidth - x, 0, x, h));
262 
263  loadButtons();
264 
265  addMouseListener(this);
267 
268  config.addListener("autohideButtons", this);
269  mAutoHide = config.getIntValue("autohideButtons");
270 }
#define _(s)
Definition: gettext.h:34
std::vector< ButtonText * > mButtonTexts
Definition: windowmenu.h:112
const bool Visible_true
Definition: visible.h:29
bool mSmallWindow
Definition: windowmenu.h:116
#define N_(s)
Definition: gettext.h:35
void setVisible(Visible visible)
Definition: widget.cpp:224
int mAutoHide
Definition: windowmenu.h:115
Definition: rect.h:72
int mWidth
Definition: graphics.h:483
int mSpacing
Definition: windowmenu.h:110
Configuration config
static std::string getThemePath()
Definition: theme.h:66
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
ImageSet * mImageSet
Definition: windowmenu.h:108
Skin * load(const std::string &filename, const std::string &filename2, const bool full, const std::string &defaultPath)
Definition: theme.cpp:178
int getIntValue(const std::string &key) const
int getWidth() const
Definition: graphics.cpp:642
bool showButtonIcons
Definition: settings.h:163
void addListener(const std::string &key, ConfigListener *const listener)
int getOption(const std::string &name) const
Definition: skin.h:105
Container(const Widget2 *const widget)
Definition: container.cpp:29
Settings settings
Definition: settings.cpp:31
void loadButtons()
Definition: windowmenu.cpp:483
int getPadding() const
Definition: skin.h:99
static ImageSet * getImageSetFromTheme(const std::string &path, const int w, const int h)
Definition: theme.cpp:659
void addButton(const char *const text, const int iconNumber, const std::string &description, int &x, int &h, const InputActionT key, const Visible visible)
Definition: windowmenu.cpp:322
const bool Visible_false
Definition: visible.h:29
bool mHaveMouse
Definition: windowmenu.h:114
int mPadding
Definition: windowmenu.h:109
Graphics * mainGraphics
Definition: graphics.cpp:108
void addMouseListener(MouseListener *const mouseListener)
Definition: widget.cpp:291
bool hasSkills() const
Definition: skilldialog.h:118
SkillDialog * skillDialog
Definition: skilldialog.cpp:65
Theme * theme
Definition: theme.cpp:61
void setFocusable(const bool focusable)
Definition: widget.cpp:191
Skin * mSkin
Definition: windowmenu.h:107
std::map< std::string, ButtonInfo * > mButtonNames
Definition: windowmenu.h:113
std::vector< Button * > mButtons
Definition: windowmenu.h:111

◆ ~WindowMenu()

WindowMenu::~WindowMenu ( )

Definition at line 272 of file windowmenu.cpp.

References CHECKLISTENERS, config, Resource::decRef(), delete_all(), FOR_EACH, mButtonNames, mButtons, mButtonTexts, mImageSet, mSkin, Widget::mVisible, Configuration::removeListener(), theme, Theme::unload(), and Visible_false.

273 {
274  config.removeListener("autohideButtons", this);
276 
277  for (std::map <std::string, ButtonInfo*>::iterator
278  it = mButtonNames.begin(),
279  it_fend = mButtonNames.end(); it != it_fend; ++it)
280  {
281  delete (*it).second;
282  }
283  mButtonNames.clear();
284  FOR_EACH (STD_VECTOR <Button*>::iterator, it, mButtons)
285  {
286  Button *const btn = *it;
287  if (btn == nullptr)
288  continue;
289  if (btn->mVisible == Visible_false)
290  delete btn;
291  }
293  mButtonTexts.clear();
294  if (mImageSet != nullptr)
295  {
296  mImageSet->decRef();
297  mImageSet = nullptr;
298  }
299  if (mSkin != nullptr)
300  {
301  if (theme != nullptr)
302  theme->unload(mSkin);
303  mSkin = nullptr;
304  }
305 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
void unload(Skin *const skin)
Definition: theme.cpp:249
std::vector< ButtonText * > mButtonTexts
Definition: windowmenu.h:112
virtual void decRef()
Definition: resource.cpp:49
Definition: button.h:96
Configuration config
ImageSet * mImageSet
Definition: windowmenu.h:108
Visible mVisible
Definition: widget.h:962
void delete_all(Container &c)
Definition: dtor.h:55
const bool Visible_false
Definition: visible.h:29
Theme * theme
Definition: theme.cpp:61
Skin * mSkin
Definition: windowmenu.h:107
#define CHECKLISTENERS
Definition: localconsts.h:268
std::map< std::string, ButtonInfo * > mButtonNames
Definition: windowmenu.h:113
std::vector< Button * > mButtons
Definition: windowmenu.h:111
void removeListener(const std::string &key, ConfigListener *const listener)

Member Function Documentation

◆ action()

void WindowMenu::action ( const ActionEvent actionEvent)
virtual

Called when an action is recieved from a widget. It is used to be able to recieve a notification that an action has occured.

Parameters
actionEventThe event of the action.

Implements ActionListener.

Definition at line 307 of file windowmenu.cpp.

References InputManager::executeAction(), Actions::info(), inputManager, ButtonInfo::key, and mButtonNames.

308 {
309  const std::string &eventId = event.getId();
310  const std::map <std::string, ButtonInfo*>::iterator
311  it = mButtonNames.find(eventId);
312  if (it == mButtonNames.end())
313  return;
314 
315  const ButtonInfo *const info = (*it).second;
316  if (info == nullptr)
317  return;
318 
320 }
bool info(InputEvent &event)
Definition: commands.cpp:56
InputManager inputManager
std::map< std::string, ButtonInfo * > mButtonNames
Definition: windowmenu.h:113
InputActionT key
Definition: buttoninfo.h:46
void executeAction(const InputActionT keyNum)

◆ addButton()

void WindowMenu::addButton ( const char *const  text,
const int  iconNumber,
const std::string &  description,
int &  x,
int &  h,
const InputActionT  key,
const Visible  visible 
)
inlineprivate

Definition at line 322 of file windowmenu.cpp.

References BasicContainer2::add(), Button::adjustSize(), BUTTON_SKIN, CAST_S32, ImageSet::get(), Widget::getHeight(), Widget::getWidth(), mButtonNames, mButtons, mButtonTexts, mImageSet, mPadding, mSpacing, Button::setDescription(), Widget::setFocusable(), Button::setImage(), Widget::setPosition(), Button::setTag(), settings, InputAction::SHOW_WINDOWS, and Settings::showButtonIcons.

Referenced by getButtonTexts(), and WindowMenu().

329 {
330  Button *btn = nullptr;
332  mImageSet)
333  {
334  Image *const image = mImageSet->get(iconNumber);
335  if (image != nullptr)
336  {
337 /*
338  btn = new Button(this,
339  "buttonsicons.png",
340  20,
341  20,
342  text,
343  BUTTON_SKIN,
344  this);
345 */
346  btn = new Button(this,
347  std::string(),
348  text,
349  BUTTON_SKIN,
350  this);
351  btn->setImage(image);
352  btn->adjustSize();
353  }
354  }
355  if (btn == nullptr)
356  {
357  btn = new Button(this,
358  gettext(text),
359  text,
360  BUTTON_SKIN,
361  this);
362  }
363  btn->setPosition(x, mPadding);
364  btn->setDescription(description);
365  btn->setTag(CAST_S32(key));
366  add(btn);
367  btn->setFocusable(false);
368  x += btn->getWidth() + mSpacing;
369  h = btn->getHeight() + 2 * mPadding;
370  mButtons.push_back(btn);
371  mButtonNames[text] = new ButtonInfo(btn, key, visible);
372  if (key != InputAction::SHOW_WINDOWS)
373  mButtonTexts.push_back(new ButtonText(description, key));
374 }
int getWidth() const
Definition: widget.h:220
Image * get(const size_type i) const
Definition: imageset.cpp:66
std::vector< ButtonText * > mButtonTexts
Definition: windowmenu.h:112
void setImage(Image *const image)
Definition: button.cpp:378
int mSpacing
Definition: windowmenu.h:110
Definition: button.h:96
ImageSet * mImageSet
Definition: windowmenu.h:108
bool showButtonIcons
Definition: settings.h:163
void adjustSize()
Definition: button.cpp:798
Settings settings
Definition: settings.cpp:31
#define CAST_S32
Definition: cast.h:29
const std::string BUTTON_SKIN
Definition: button.h:88
virtual void add(Widget *const widget)
int mPadding
Definition: windowmenu.h:109
void setPosition(const int x, const int y)
Definition: widget.cpp:160
void setFocusable(const bool focusable)
Definition: widget.cpp:191
void setTag(int tag)
Definition: button.h:173
Definition: image.h:61
int getHeight() const
Definition: widget.h:239
std::map< std::string, ButtonInfo * > mButtonNames
Definition: windowmenu.h:113
void setDescription(const std::string &text)
Definition: button.h:164
std::vector< Button * > mButtons
Definition: windowmenu.h:111

◆ drawChildren()

void WindowMenu::drawChildren ( Graphics *const  graphics)
protectedvirtual

Draws the children widgets of the basic container.

Parameters
graphicsA graphics object to draw with.

Reimplemented from BasicContainer.

Definition at line 553 of file windowmenu.cpp.

References BasicContainer::drawChildren(), mainGraphics, mAutoHide, mHaveMouse, mSmallWindow, and Graphics::mWidth.

Referenced by getButtonTexts().

554 {
555  if (mHaveMouse ||
556  mAutoHide == 0 ||
557  (mAutoHide == 1 &&
558  mainGraphics != nullptr &&
559  (mSmallWindow || mainGraphics->mWidth > 800)))
560  {
561  Container::drawChildren(graphics);
562  }
563 }
bool mSmallWindow
Definition: windowmenu.h:116
int mAutoHide
Definition: windowmenu.h:115
int mWidth
Definition: graphics.h:483
bool mHaveMouse
Definition: windowmenu.h:114
Graphics * mainGraphics
Definition: graphics.cpp:108
virtual void drawChildren(Graphics *const graphics)

◆ getButtonNames()

std::map<std::string, ButtonInfo*>& WindowMenu::getButtonNames ( )
inline

Definition at line 69 of file windowmenu.h.

References mButtonNames.

70  { return mButtonNames; }
std::map< std::string, ButtonInfo * > mButtonNames
Definition: windowmenu.h:113

◆ getButtons()

std::vector<Button*>& WindowMenu::getButtons ( )
inline

Definition at line 72 of file windowmenu.h.

References mButtons.

Referenced by PopupMenu::showPopup().

73  { return mButtons; }
std::vector< Button * > mButtons
Definition: windowmenu.h:111

◆ getButtonTexts()

std::vector<ButtonText*>& WindowMenu::getButtonTexts ( )
inline

◆ loadButtons()

void WindowMenu::loadButtons ( )

Definition at line 483 of file windowmenu.cpp.

References ButtonInfo::button, config, fromBool, Widget::getActionEventId(), ConfigurationObject::getValue(), Actions::info(), mButtonNames, mSmallWindow, Widget::setVisible(), ServerCommandType::str, Catch::toString(), updateButtons(), ButtonInfo::visible, Visible_false, and Visible_true.

Referenced by getButtonTexts(), and WindowMenu().

484 {
485  if (!mSmallWindow)
486  {
487  if (config.getValue("windowmenu0", "").empty())
488  {
489  for (std::map <std::string, ButtonInfo*>::iterator
490  it = mButtonNames.begin(),
491  it_fend = mButtonNames.end(); it != it_fend; ++it)
492  {
493  const ButtonInfo *const info = (*it).second;
494  if (info == nullptr ||
495  info->button == nullptr ||
496  info->visible == Visible_true)
497  {
498  continue;
499  }
501  }
502  updateButtons();
503  return;
504  }
505 
506  for (int f = 0; f < 30; f ++)
507  {
508  const std::string str = config.getValue(
509  "windowmenu" + toString(f), "");
510  if (str.empty() || str == "SET")
511  continue;
512  const ButtonInfo *const info = mButtonNames[str];
513  if ((info == nullptr) || (info->button == nullptr))
514  continue;
516  }
517  }
518  else
519  {
520  for (std::map <std::string, ButtonInfo*>::iterator
521  it = mButtonNames.begin(),
522  it_fend = mButtonNames.end(); it != it_fend; ++it)
523  {
524  const ButtonInfo *const info = (*it).second;
525  if ((info == nullptr) || (info->button == nullptr))
526  continue;
527  Button *const button = info->button;
528  const std::string &str = button->getActionEventId();
529  button->setVisible(fromBool(
530  str == "SET" || str == "WIN", Visible));
531  }
532  }
533  updateButtons();
534 }
void updateButtons()
Definition: windowmenu.cpp:458
const bool Visible_true
Definition: visible.h:29
bool mSmallWindow
Definition: windowmenu.h:116
void setVisible(Visible visible)
Definition: widget.cpp:224
Definition: button.h:96
Configuration config
const std::string & getActionEventId() const
Definition: widget.h:604
const bool Visible_false
Definition: visible.h:29
#define fromBool(val, name)
Definition: booldefines.h:48
bool info(InputEvent &event)
Definition: commands.cpp:56
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
std::string getValue(const std::string &key, const std::string &deflt) const
Visible visible
Definition: buttoninfo.h:47
std::map< std::string, ButtonInfo * > mButtonNames
Definition: windowmenu.h:113
Button * button
Definition: buttoninfo.h:45

◆ mouseExited()

void WindowMenu::mouseExited ( MouseEvent event)
virtual

Called when the mouse has exited the widget area.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 437 of file windowmenu.cpp.

References Popup::hide(), mHaveMouse, and textPopup.

438 {
439  mHaveMouse = false;
440  if (textPopup == nullptr)
441  return;
442 
443  textPopup->hide();
444 }
void hide()
Definition: popup.cpp:262
bool mHaveMouse
Definition: windowmenu.h:114
TextPopup * textPopup
Definition: textpopup.cpp:32

◆ mouseMoved()

void WindowMenu::mouseMoved ( MouseEvent event)
virtual

Called when the mouse has moved in the widget area and no mouse button has been pressed (i.e no widget is being dragged).

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 398 of file windowmenu.cpp.

References _, Button::getDescription(), InputManager::getKeyValueString(), Event::getSource(), Button::getTag(), Popup::hide(), inputManager, Widget::mDimension, mHaveMouse, InputAction::NO_VALUE, TextPopup::show(), strprintf(), textPopup, x, Rect::x, y, and Rect::y.

399 {
400  mHaveMouse = true;
401 
402  if (textPopup == nullptr)
403  return;
404 
405  if (event.getSource() == this)
406  {
407  textPopup->hide();
408  return;
409  }
410 
411  const Button *const btn = dynamic_cast<const Button *>(
412  event.getSource());
413 
414  if (btn == nullptr)
415  {
416  textPopup->hide();
417  return;
418  }
419 
420  const int x = event.getX();
421  const int y = event.getY();
422  const InputActionT key = static_cast<InputActionT>(btn->getTag());
423  const Rect &rect = mDimension;
424  if (key != InputAction::NO_VALUE)
425  {
426  textPopup->show(x + rect.x, y + rect.y, btn->getDescription(),
427  // TRANSLATORS: short key name
429  key).c_str()));
430  }
431  else
432  {
433  textPopup->show(x + rect.x, y + rect.y, btn->getDescription());
434  }
435 }
void show(const int x, const int y, const std::string &str1)
Definition: textpopup.h:56
#define _(s)
Definition: gettext.h:34
Definition: rect.h:72
Definition: button.h:96
int x
Definition: rect.h:208
void hide()
Definition: popup.cpp:262
std::string getDescription() const
Definition: button.h:167
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99
std::string getKeyValueString(const InputActionT index) const
Widget * getSource() const
Definition: event.h:103
int y
Definition: rect.h:213
bool mHaveMouse
Definition: windowmenu.h:114
int getTag() const
Definition: button.h:176
InputAction ::T InputActionT
Definition: inputaction.h:715
InputManager inputManager
Rect mDimension
Definition: widget.h:1100
TextPopup * textPopup
Definition: textpopup.cpp:32

◆ mousePressed()

void WindowMenu::mousePressed ( MouseEvent event)
virtual

Called when a mouse button has been pressed on the widget area.

NOTE: A mouse press is NOT equal to a mouse click. Use mouseClickMessage to check for mouse clicks.

Parameters
eventDescribes the event.

Reimplemented from MouseListener.

Definition at line 376 of file windowmenu.cpp.

References MouseEvent::getButton(), MouseEvent::getX(), Widget::getX(), Widget::getY(), mSmallWindow, popupManager, popupMenu, MouseButton::RIGHT, and PopupMenu::showPopup().

377 {
378  if (popupManager == nullptr)
379  return;
380 
381  if (event.getButton() == MouseButton::RIGHT)
382  {
383  if (mSmallWindow)
384  return;
385 
386  event.consume();
387  Button *const btn = dynamic_cast<Button*>(event.getSource());
388  if (btn == nullptr)
389  return;
390  if (popupMenu != nullptr)
391  {
392  popupMenu->showPopup(getX() + event.getX(),
393  getY() + event.getY(), btn);
394  }
395  }
396 }
bool mSmallWindow
Definition: windowmenu.h:116
int getY() const
Definition: widget.h:287
MouseButtonT getButton() const
Definition: mouseevent.h:115
Definition: button.h:96
PopupManager * popupManager
PopupMenu * popupMenu
Definition: popupmenu.cpp:102
int getX() const
Definition: widget.h:268
int getX() const
Definition: mouseevent.h:126
void showPopup(const int x, const int y, const Being *const being)
Definition: popupmenu.cpp:202

◆ optionChanged()

void WindowMenu::optionChanged ( const std::string &  name)
virtual

Called when an option changed. The config listener will have to be registered to the option name first.

Implements ConfigListener.

Definition at line 577 of file windowmenu.cpp.

References BLOCK_END, BLOCK_START, config, Configuration::getIntValue(), BasicContainer::logicChildren(), and mAutoHide.

Referenced by getButtonTexts().

578 {
579  if (name == "autohideButtons")
580  mAutoHide = config.getIntValue("autohideButtons");
581 }
int mAutoHide
Definition: windowmenu.h:115
Configuration config
int getIntValue(const std::string &key) const

◆ safeDrawChildren()

void WindowMenu::safeDrawChildren ( Graphics *const  graphics)
protectedvirtual

Reimplemented from BasicContainer.

Definition at line 565 of file windowmenu.cpp.

References mainGraphics, mAutoHide, mHaveMouse, mSmallWindow, Graphics::mWidth, and BasicContainer::safeDrawChildren().

Referenced by getButtonTexts().

566 {
567  if (mHaveMouse ||
568  mAutoHide == 0 ||
569  (mAutoHide == 1 &&
570  mainGraphics != nullptr &&
571  (mSmallWindow || mainGraphics->mWidth > 800)))
572  {
573  Container::safeDrawChildren(graphics);
574  }
575 }
bool mSmallWindow
Definition: windowmenu.h:116
int mAutoHide
Definition: windowmenu.h:115
int mWidth
Definition: graphics.h:483
bool mHaveMouse
Definition: windowmenu.h:114
Graphics * mainGraphics
Definition: graphics.cpp:108
virtual void safeDrawChildren(Graphics *const graphics)

◆ saveButtons()

void WindowMenu::saveButtons ( ) const

Definition at line 536 of file windowmenu.cpp.

References config, ConfigurationObject::deleteKey(), FOR_EACH, Widget::getActionEventId(), mButtons, Widget::mVisible, Configuration::setValue(), Catch::toString(), and Visible_false.

Referenced by getButtonTexts(), and showButton().

537 {
538  int i = 0;
539  FOR_EACH (STD_VECTOR <Button*>::const_iterator, it, mButtons)
540  {
541  const Button *const btn = *it;
542  if ((btn != nullptr) && btn->mVisible == Visible_false)
543  {
544  config.setValue("windowmenu" + toString(i),
545  btn->getActionEventId());
546  i ++;
547  }
548  }
549  for (int f = i; f < 30; f ++)
550  config.deleteKey("windowmenu" + toString(f));
551 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
Definition: button.h:96
Configuration config
const std::string & getActionEventId() const
Definition: widget.h:604
Visible mVisible
Definition: widget.h:962
const bool Visible_false
Definition: visible.h:29
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
void deleteKey(const std::string &key)
void setValue(const std::string &key, const std::string &value)
std::vector< Button * > mButtons
Definition: windowmenu.h:111

◆ showButton()

void WindowMenu::showButton ( const std::string &  name,
const Visible  visible 
)

Definition at line 446 of file windowmenu.cpp.

References ButtonInfo::button, Actions::info(), mButtonNames, saveButtons(), Widget::setVisible(), and updateButtons().

Referenced by getButtonTexts(), and PopupMenu::handleLink().

448 {
449  const ButtonInfo *const info = mButtonNames[name];
450  if ((info == nullptr) || (info->button == nullptr))
451  return;
452 
453  info->button->setVisible(visible);
454  updateButtons();
455  saveButtons();
456 }
void updateButtons()
Definition: windowmenu.cpp:458
void setVisible(Visible visible)
Definition: widget.cpp:224
void saveButtons() const
Definition: windowmenu.cpp:536
bool info(InputEvent &event)
Definition: commands.cpp:56
std::map< std::string, ButtonInfo * > mButtonNames
Definition: windowmenu.h:113
Button * button
Definition: buttoninfo.h:45

◆ updateButtons()

void WindowMenu::updateButtons ( )
private

Definition at line 458 of file windowmenu.cpp.

References BasicContainer2::add(), FOR_EACH, Widget::getHeight(), Widget::getWidth(), mainGraphics, mButtons, mPadding, mSpacing, Widget::mVisible, Graphics::mWidth, Container::safeRemove(), Widget::setDimension(), Widget::setPosition(), Visible_true, and x.

Referenced by getButtonTexts(), loadButtons(), and showButton().

459 {
460  int x = mPadding;
461  int h = 0;
462  FOR_EACH (STD_VECTOR <Button*>::const_iterator, it, mButtons)
463  safeRemove(*it);
464  const int pad2 = 2 * mPadding;
465  FOR_EACH (STD_VECTOR <Button*>::iterator, it, mButtons)
466  {
467  Button *const btn = *it;
468  if (btn == nullptr)
469  continue;
470  if (btn->mVisible == Visible_true)
471  {
472  btn->setPosition(x, mPadding);
473  add(btn);
474  x += btn->getWidth() + mSpacing;
475  h = btn->getHeight() + pad2;
476  }
477  }
478  x += mPadding - mSpacing;
479  if (mainGraphics != nullptr)
480  setDimension(Rect(mainGraphics->mWidth - x, 0, x, h));
481 }
#define FOR_EACH(type, iter, array)
Definition: foreach.h:24
int getWidth() const
Definition: widget.h:220
const bool Visible_true
Definition: visible.h:29
Definition: rect.h:72
int mWidth
Definition: graphics.h:483
int mSpacing
Definition: windowmenu.h:110
Definition: button.h:96
void setDimension(const Rect &dimension)
Definition: widget.cpp:168
bool safeRemove(Widget *const widget)
Definition: container.cpp:48
Visible mVisible
Definition: widget.h:962
virtual void add(Widget *const widget)
int mPadding
Definition: windowmenu.h:109
Graphics * mainGraphics
Definition: graphics.cpp:108
void setPosition(const int x, const int y)
Definition: widget.cpp:160
int getHeight() const
Definition: widget.h:239
std::vector< Button * > mButtons
Definition: windowmenu.h:111

Field Documentation

◆ mAutoHide

int WindowMenu::mAutoHide
private

Definition at line 115 of file windowmenu.h.

Referenced by drawChildren(), optionChanged(), safeDrawChildren(), and WindowMenu().

◆ mButtonNames

std::map<std::string, ButtonInfo*> WindowMenu::mButtonNames
private

Definition at line 113 of file windowmenu.h.

Referenced by action(), addButton(), getButtonNames(), loadButtons(), showButton(), and ~WindowMenu().

◆ mButtons

std::vector<Button*> WindowMenu::mButtons
private

Definition at line 111 of file windowmenu.h.

Referenced by addButton(), getButtons(), saveButtons(), updateButtons(), and ~WindowMenu().

◆ mButtonTexts

std::vector<ButtonText*> WindowMenu::mButtonTexts
private

Definition at line 112 of file windowmenu.h.

Referenced by addButton(), getButtonTexts(), and ~WindowMenu().

◆ mHaveMouse

bool WindowMenu::mHaveMouse
private

Definition at line 114 of file windowmenu.h.

Referenced by drawChildren(), mouseExited(), mouseMoved(), and safeDrawChildren().

◆ mImageSet

ImageSet* WindowMenu::mImageSet
private

Definition at line 108 of file windowmenu.h.

Referenced by addButton(), WindowMenu(), and ~WindowMenu().

◆ mPadding

int WindowMenu::mPadding
private

Definition at line 109 of file windowmenu.h.

Referenced by addButton(), updateButtons(), and WindowMenu().

◆ mSkin

Skin* WindowMenu::mSkin
private

Definition at line 107 of file windowmenu.h.

Referenced by WindowMenu(), and ~WindowMenu().

◆ mSmallWindow

bool WindowMenu::mSmallWindow
private

Definition at line 116 of file windowmenu.h.

Referenced by drawChildren(), loadButtons(), mousePressed(), and safeDrawChildren().

◆ mSpacing

int WindowMenu::mSpacing
private

Definition at line 110 of file windowmenu.h.

Referenced by addButton(), updateButtons(), and WindowMenu().


The documentation for this class was generated from the following files: