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 49 of file windowmenu.h.

Constructor & Destructor Documentation

◆ WindowMenu()

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

Definition at line 53 of file windowmenu.cpp.

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

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.

◆ ~WindowMenu()

WindowMenu::~WindowMenu ( )

Definition at line 273 of file windowmenu.cpp.

274 {
275  config.removeListener("autohideButtons", this);
277 
278  for (std::map <std::string, ButtonInfo*>::iterator
279  it = mButtonNames.begin(),
280  it_fend = mButtonNames.end(); it != it_fend; ++it)
281  {
282  delete (*it).second;
283  }
284  mButtonNames.clear();
285  FOR_EACH (STD_VECTOR <Button*>::iterator, it, mButtons)
286  {
287  Button *const btn = *it;
288  if (btn == nullptr)
289  continue;
290  if (btn->mVisible == Visible_false)
291  delete btn;
292  }
294  mButtonTexts.clear();
295  if (mImageSet != nullptr)
296  {
297  mImageSet->decRef();
298  mImageSet = nullptr;
299  }
300  if (mSkin != nullptr)
301  {
302  if (theme != nullptr)
303  theme->unload(mSkin);
304  mSkin = nullptr;
305  }
306 }
Definition: button.h:102
void removeListener(const std::string &key, ConfigListener *const listener)
virtual void decRef()
Definition: resource.cpp:50
void unload(Skin *const skin)
Definition: theme.cpp:250
Visible mVisible
Definition: widget.h:963
void delete_all(Container &c)
Definition: dtor.h:56
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
#define CHECKLISTENERS
Definition: localconsts.h:277

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

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 308 of file windowmenu.cpp.

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

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

◆ 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 323 of file windowmenu.cpp.

330 {
331  Button *btn = nullptr;
333  mImageSet)
334  {
335  Image *const image = mImageSet->get(iconNumber);
336  if (image != nullptr)
337  {
338 /*
339  btn = new Button(this,
340  "buttonsicons.png",
341  20,
342  20,
343  text,
344  BUTTON_SKIN,
345  this);
346 */
347  btn = new Button(this,
348  std::string(),
349  text,
350  BUTTON_SKIN,
351  this);
352  btn->setImage(image);
353  btn->adjustSize();
354  }
355  }
356  if (btn == nullptr)
357  {
358  btn = new Button(this,
359  gettext(text),
360  text,
361  BUTTON_SKIN,
362  this);
363  }
364  btn->setPosition(x, mPadding);
365  btn->setDescription(description);
366  btn->setTag(CAST_S32(key));
367  add(btn);
368  btn->setFocusable(false);
369  x += btn->getWidth() + mSpacing;
370  h = btn->getHeight() + 2 * mPadding;
371  mButtons.push_back(btn);
372  mButtonNames[text] = new ButtonInfo(btn, key, visible);
373  if (key != InputAction::SHOW_WINDOWS)
374  mButtonTexts.push_back(new ButtonText(description, key));
375 }
const std::string BUTTON_SKIN
Definition: button.h:89
#define CAST_S32
Definition: cast.h:30
virtual void add(Widget *const widget)
void setImage(Image *const image)
Definition: button.cpp:379
void setDescription(const std::string &text)
Definition: button.h:165
void setTag(int tag)
Definition: button.h:174
void adjustSize()
Definition: button.cpp:799
Image * get(const size_type i) const
Definition: imageset.cpp:67
void setPosition(const int x, const int y)
Definition: widget.cpp:161
int getHeight() const
Definition: widget.h:240
int getWidth() const
Definition: widget.h:221

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, Settings::showButtonIcons, and x.

Referenced by WindowMenu().

◆ 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 554 of file windowmenu.cpp.

555 {
556  if (mHaveMouse ||
557  mAutoHide == 0 ||
558  (mAutoHide == 1 &&
559  mainGraphics != nullptr &&
560  (mSmallWindow || mainGraphics->mWidth > 800)))
561  {
562  Container::drawChildren(graphics);
563  }
564 }
virtual void drawChildren(Graphics *const graphics)

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

◆ getButtonNames()

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

Definition at line 70 of file windowmenu.h.

71  { return mButtonNames; }

References mButtonNames.

◆ getButtons()

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

Definition at line 73 of file windowmenu.h.

74  { return mButtons; }

References mButtons.

Referenced by PopupMenu::showPopup().

◆ getButtonTexts()

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

Definition at line 76 of file windowmenu.h.

77  { return mButtonTexts; }

References mButtonTexts.

Referenced by PopupMenu::showWindowsPopup().

◆ loadButtons()

void WindowMenu::loadButtons ( )

Definition at line 484 of file windowmenu.cpp.

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

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

Referenced by WindowMenu().

◆ 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 438 of file windowmenu.cpp.

439 {
440  mHaveMouse = false;
441  if (textPopup == nullptr)
442  return;
443 
444  textPopup->hide();
445 }
void hide()
Definition: popup.cpp:265
TextPopup * textPopup
Definition: textpopup.cpp:33

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

◆ 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 399 of file windowmenu.cpp.

400 {
401  mHaveMouse = true;
402 
403  if (textPopup == nullptr)
404  return;
405 
406  if (event.getSource() == this)
407  {
408  textPopup->hide();
409  return;
410  }
411 
412  const Button *const btn = dynamic_cast<const Button *>(
413  event.getSource());
414 
415  if (btn == nullptr)
416  {
417  textPopup->hide();
418  return;
419  }
420 
421  const int x = event.getX();
422  const int y = event.getY();
423  const InputActionT key = static_cast<InputActionT>(btn->getTag());
424  const Rect &rect = mDimension;
425  if (key != InputAction::NO_VALUE)
426  {
427  textPopup->show(x + rect.x, y + rect.y, btn->getDescription(),
428  // TRANSLATORS: short key name
430  key).c_str()));
431  }
432  else
433  {
434  textPopup->show(x + rect.x, y + rect.y, btn->getDescription());
435  }
436 }
std::string getDescription() const
Definition: button.h:168
int getTag() const
Definition: button.h:177
Widget * getSource() const
Definition: event.h:104
std::string getKeyValueString(const InputActionT index) const
int y
Definition: rect.h:214
int x
Definition: rect.h:209
void show(const int x, const int y, const std::string &str1)
Definition: textpopup.h:57
Rect mDimension
Definition: widget.h:1101
InputAction ::T InputActionT
Definition: inputaction.h:717
std::string strprintf(const char *const format,...)

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

◆ 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 377 of file windowmenu.cpp.

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

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

◆ 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 578 of file windowmenu.cpp.

579 {
580  if (name == "autohideButtons")
581  mAutoHide = config.getIntValue("autohideButtons");
582 }

References config, Configuration::getIntValue(), and mAutoHide.

◆ safeDrawChildren()

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

Reimplemented from BasicContainer.

Definition at line 566 of file windowmenu.cpp.

567 {
568  if (mHaveMouse ||
569  mAutoHide == 0 ||
570  (mAutoHide == 1 &&
571  mainGraphics != nullptr &&
572  (mSmallWindow || mainGraphics->mWidth > 800)))
573  {
574  Container::safeDrawChildren(graphics);
575  }
576 }
virtual void safeDrawChildren(Graphics *const graphics)

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

◆ saveButtons()

void WindowMenu::saveButtons ( ) const

Definition at line 537 of file windowmenu.cpp.

538 {
539  int i = 0;
540  FOR_EACH (STD_VECTOR <Button*>::const_iterator, it, mButtons)
541  {
542  const Button *const btn = *it;
543  if ((btn != nullptr) && btn->mVisible == Visible_false)
544  {
545  config.setValue("windowmenu" + toString(i),
546  btn->getActionEventId());
547  i ++;
548  }
549  }
550  for (int f = i; f < 30; f ++)
551  config.deleteKey("windowmenu" + toString(f));
552 }
void deleteKey(const std::string &key)
void setValue(const std::string &key, const std::string &value)

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

Referenced by showButton().

◆ showButton()

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

Definition at line 447 of file windowmenu.cpp.

449 {
450  const ButtonInfo *const info = mButtonNames[name];
451  if ((info == nullptr) || (info->button == nullptr))
452  return;
453 
454  info->button->setVisible(visible);
455  updateButtons();
456  saveButtons();
457 }
void saveButtons() const
Definition: windowmenu.cpp:537

References Actions::info(), mButtonNames, saveButtons(), and updateButtons().

Referenced by PopupMenu::handleLink().

◆ updateButtons()

void WindowMenu::updateButtons ( )
private

Definition at line 459 of file windowmenu.cpp.

460 {
461  int x = mPadding;
462  int h = 0;
463  FOR_EACH (STD_VECTOR <Button*>::const_iterator, it, mButtons)
464  safeRemove(*it);
465  const int pad2 = 2 * mPadding;
466  FOR_EACH (STD_VECTOR <Button*>::iterator, it, mButtons)
467  {
468  Button *const btn = *it;
469  if (btn == nullptr)
470  continue;
471  if (btn->mVisible == Visible_true)
472  {
473  btn->setPosition(x, mPadding);
474  add(btn);
475  x += btn->getWidth() + mSpacing;
476  h = btn->getHeight() + pad2;
477  }
478  }
479  x += mPadding - mSpacing;
480  if (mainGraphics != nullptr)
481  setDimension(Rect(mainGraphics->mWidth - x, 0, x, h));
482 }
bool safeRemove(Widget *const widget)
Definition: container.cpp:49

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 loadButtons(), and showButton().

Field Documentation

◆ mAutoHide

int WindowMenu::mAutoHide
private

Definition at line 116 of file windowmenu.h.

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

◆ mButtonNames

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

Definition at line 114 of file windowmenu.h.

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

◆ mButtons

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

Definition at line 112 of file windowmenu.h.

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

◆ mButtonTexts

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

Definition at line 113 of file windowmenu.h.

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

◆ mHaveMouse

bool WindowMenu::mHaveMouse
private

Definition at line 115 of file windowmenu.h.

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

◆ mImageSet

ImageSet* WindowMenu::mImageSet
private

Definition at line 109 of file windowmenu.h.

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

◆ mPadding

int WindowMenu::mPadding
private

Definition at line 110 of file windowmenu.h.

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

◆ mSkin

Skin* WindowMenu::mSkin
private

Definition at line 108 of file windowmenu.h.

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

◆ mSmallWindow

bool WindowMenu::mSmallWindow
private

Definition at line 117 of file windowmenu.h.

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

◆ mSpacing

int WindowMenu::mSpacing
private

Definition at line 111 of file windowmenu.h.

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


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