Crazy Eddies GUI System  0.7.9
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
CEGUIMenuItem.h
1 /***********************************************************************
2  filename: CEGUIMenuItem.h
3  created: 2/4/2005
4  author: Tomas Lindquist Olsen (based on code by Paul D Turner)
5 
6  purpose: Interface to base class for MenuItem widget
7 *************************************************************************/
8 /***************************************************************************
9  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining
12  * a copy of this software and associated documentation files (the
13  * "Software"), to deal in the Software without restriction, including
14  * without limitation the rights to use, copy, modify, merge, publish,
15  * distribute, sublicense, and/or sell copies of the Software, and to
16  * permit persons to whom the Software is furnished to do so, subject to
17  * the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be
20  * included in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  * OTHER DEALINGS IN THE SOFTWARE.
29  ***************************************************************************/
30 #ifndef _CEGUIMenuItem_h_
31 #define _CEGUIMenuItem_h_
32 
33 #include "../CEGUIBase.h"
34 #include "../CEGUIWindow.h"
35 #include "CEGUIItemEntry.h"
36 
37 #include "CEGUIMenuItemProperties.h"
38 
39 #if defined(_MSC_VER)
40 # pragma warning(push)
41 # pragma warning(disable : 4251)
42 #endif
43 
44 // Start of CEGUI namespace section
45 namespace CEGUI
46 {
47 
52 class CEGUIEXPORT MenuItem : public ItemEntry
53 {
54 public:
55  static const String EventNamespace;
56  static const String WidgetTypeName;
57 
58  /*************************************************************************
59  Event name constants
60  *************************************************************************/
61  // generated internally by Window
66  static const String EventClicked;
67 
68 
69  /*************************************************************************
70  Accessor type functions
71  *************************************************************************/
79  bool isHovering(void) const
80  {
81  return d_hovering;
82  }
83 
84 
92  bool isPushed(void) const
93  {
94  return d_pushed;
95  }
96 
97 
102  bool isOpened(void) const
103  {
104  return d_opened;
105  }
106 
111  bool isPopupClosing(void) const
112  {
113  return d_popupClosing;
114  }
115 
120  bool hasAutoPopup(void) const
121  {
122  return d_autoPopupTimeout > 0.0f;
123  }
124 
129  float getAutoPopupTimeout(void) const
130  {
131  return d_autoPopupTimeout;
132  }
133 
138  void setAutoPopupTimeout(float time)
139  {
140  d_autoPopupTimeout = time;
141  }
142 
150  PopupMenu* getPopupMenu(void) const
151  {
152  return d_popup;
153  }
154 
159  const UVector2& getPopupOffset(void) const
160  {
161  return d_popupOffset;
162  }
163 
168  void setPopupOffset(const UVector2& popupOffset)
169  {
170  d_popupOffset = popupOffset;
171  }
172 
173  /*************************************************************************
174  Manipulators
175  *************************************************************************/
186  void setPopupMenu(PopupMenu* popup);
187 
188 
196  void openPopupMenu(bool notify = true);
197 
198 
209  void closePopupMenu(bool notify = true);
210 
211 
219  bool togglePopupMenu(void);
220 
225  void startPopupClosing(void);
226 
231  void startPopupOpening(void);
232  /*************************************************************************
233  Construction and Destruction
234  *************************************************************************/
239  MenuItem(const String& type, const String& name);
240 
241 
246  virtual ~MenuItem(void);
247 
248 
249 protected:
250  /*************************************************************************
251  New Event Handlers
252  *************************************************************************/
257  virtual void onClicked(WindowEventArgs& e);
258 
259 
260  /*************************************************************************
261  Overridden event handlers
262  *************************************************************************/
263  virtual void onMouseMove(MouseEventArgs& e);
264  virtual void onMouseButtonDown(MouseEventArgs& e);
265  virtual void onMouseButtonUp(MouseEventArgs& e);
266  virtual void onCaptureLost(WindowEventArgs& e);
267  virtual void onMouseLeaves(MouseEventArgs& e);
268  virtual void onTextChanged(WindowEventArgs& e);
269  virtual void updateSelf(float elapsed);
270 
271 
272  /*************************************************************************
273  Implementation Functions
274  *************************************************************************/
285  void updateInternalState(const Point& mouse_pos);
286 
287 
295  void closeAllMenuItemPopups();
296 
297 
308  void setPopupMenu_impl(PopupMenu* popup, bool add_as_child = true);
309 
310 
321  virtual bool testClassName_impl(const String& class_name) const
322  {
323  if (class_name == "MenuItem") return true;
324 
325  return ItemEntry::testClassName_impl(class_name);
326  }
327 
328 
329  /*************************************************************************
330  Implementation Data
331  *************************************************************************/
332  bool d_pushed;
333  bool d_hovering;
334  bool d_opened;
339 
341 
343 
345 
346 private:
347  /************************************************************************
348  Static Properties for this class
349  ************************************************************************/
350  static MenuItemProperties::PopupOffset d_popupOffsetProperty;
351  static MenuItemProperties::AutoPopupTimeout d_autoPopupTimeoutProperty;
352 
353  /*************************************************************************
354  Private methods
355  *************************************************************************/
356  void addMenuItemProperties(void);
357 
362  virtual void addChild_impl(Window* wnd);
363 };
364 
365 } // End of CEGUI namespace section
366 
367 #if defined(_MSC_VER)
368 # pragma warning(pop)
369 #endif
370 
371 #endif // end of guard _CEGUIMenuItem_h_
Property to specify an offset for the popup menu position.
Definition: CEGUIMenuItemProperties.h:61
Class used as a two dimensional vector (aka a Point)
Definition: CEGUIVector.h:45
bool isHovering(void) const
return true if user is hovering over this widget (or it's pushed and user is not over it for highligh...
Definition: CEGUIMenuItem.h:79
bool d_pushed
true when widget is pushed
Definition: CEGUIMenuItem.h:332
Base class for item type widgets.
Definition: CEGUIItemEntry.h:78
PopupMenu * getPopupMenu(void) const
Get the PopupMenu that is currently attached to this MenuItem.
Definition: CEGUIMenuItem.h:150
Property to specify the time, which has to elapse before the popup window is opened/closed if the hov...
Definition: CEGUIMenuItemProperties.h:86
bool d_popupWasClosed
Used internally to determine if a popup was just closed on a Clicked event.
Definition: CEGUIMenuItem.h:342
float d_autoPopupTimeElapsed
the current time, which is already elapsed if the timer is running (d_popupClosing or d_popupOpening ...
Definition: CEGUIMenuItem.h:338
bool isPopupClosing(void) const
Returns true if the menu item popup is closing or not.
Definition: CEGUIMenuItem.h:111
UVector2 d_popupOffset
current offset for popup placement.
Definition: CEGUIMenuItem.h:344
bool d_hovering
true when the button is in 'hover' state and requires the hover rendering.
Definition: CEGUIMenuItem.h:333
static const String WidgetTypeName
Window factory name.
Definition: CEGUIMenuItem.h:56
bool d_opened
true when the menu item's popup menu is in its opened state.
Definition: CEGUIMenuItem.h:334
virtual bool testClassName_impl(const String &class_name) const
Return whether this window was inherited from the given class name at some point in the inheritance h...
Definition: CEGUIMenuItem.h:321
bool isPushed(void) const
Return true if the button widget is in the pushed state.
Definition: CEGUIMenuItem.h:92
void setPopupOffset(const UVector2 &popupOffset)
sets the current offset for popup placement.
Definition: CEGUIMenuItem.h:168
static const String EventClicked
Definition: CEGUIMenuItem.h:66
PopupMenu * d_popup
PopupMenu that this item displays when activated.
Definition: CEGUIMenuItem.h:340
bool d_popupClosing
true when the d_popupTimerTimeElapsed timer is running to close the popup (another menu item of our c...
Definition: CEGUIMenuItem.h:335
Base class for popup menus.
Definition: CEGUIPopupMenu.h:53
An abstract base class providing common functionality and specifying the required interface for deriv...
Definition: CEGUIWindow.h:138
float d_autoPopupTimeout
the time in seconds, to wait before opening / closing the popup if the mouse is over the item / over ...
Definition: CEGUIMenuItem.h:337
static const String EventNamespace
Namespace for global events.
Definition: CEGUIMenuItem.h:55
EventArgs based class that is used for objects passed to handlers triggered for events concerning som...
Definition: CEGUIInputEvent.h:245
void setAutoPopupTimeout(float time)
Sets the time, which has to elapse before the popup window is opened/closed if the hovering state cha...
Definition: CEGUIMenuItem.h:138
const UVector2 & getPopupOffset(void) const
Returns the current offset for popup placement.
Definition: CEGUIMenuItem.h:159
virtual bool testClassName_impl(const String &class_name) const
Return the "optimal" size for the item.
Definition: CEGUIItemEntry.h:215
bool d_popupOpening
true when the d_popupTimerTimeElapsed timer is running to open the popup (the menu item is hovered) ...
Definition: CEGUIMenuItem.h:336
EventArgs based class that is used for objects passed to input event handlers concerning mouse input...
Definition: CEGUIInputEvent.h:274
Base class for menu items.
Definition: CEGUIMenuItem.h:52
float getAutoPopupTimeout(void) const
Returns the time, which has to elapse before the popup window is opened/closed if the hovering state ...
Definition: CEGUIMenuItem.h:129
bool hasAutoPopup(void) const
Returns true if the menu item popup is closed or opened automatically if hovering with the mouse...
Definition: CEGUIMenuItem.h:120
String class used within the GUI system.
Definition: CEGUIString.h:57
bool isOpened(void) const
Returns true if the popup menu attached to the menu item is open.
Definition: CEGUIMenuItem.h:102
Two dimensional vector class built using unified dimensions (UDims). The UVector2 class is used for r...
Definition: CEGUIUDim.h:128