Crazy Eddie's GUI System  0.8.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
widgets/MenuItem.h
1 /***********************************************************************
2  created: 2/4/2005
3  author: Tomas Lindquist Olsen (based on code by Paul D Turner)
4 
5  purpose: Interface to base class for MenuItem widget
6 *************************************************************************/
7 /***************************************************************************
8  * Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining
11  * a copy of this software and associated documentation files (the
12  * "Software"), to deal in the Software without restriction, including
13  * without limitation the rights to use, copy, modify, merge, publish,
14  * distribute, sublicense, and/or sell copies of the Software, and to
15  * permit persons to whom the Software is furnished to do so, subject to
16  * the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27  * OTHER DEALINGS IN THE SOFTWARE.
28  ***************************************************************************/
29 #ifndef _CEGUIMenuItem_h_
30 #define _CEGUIMenuItem_h_
31 
32 #include "../Base.h"
33 #include "../Window.h"
34 #include "./ItemEntry.h"
35 
36 #if defined(_MSC_VER)
37 # pragma warning(push)
38 # pragma warning(disable : 4251)
39 #endif
40 
41 // Start of CEGUI namespace section
42 namespace CEGUI
43 {
44 
49 class CEGUIEXPORT MenuItem : public ItemEntry
50 {
51 public:
52  static const String EventNamespace;
53  static const String WidgetTypeName;
54 
55  /*************************************************************************
56  Event name constants
57  *************************************************************************/
58  // generated internally by Window
63  static const String EventClicked;
64 
65 
66  /*************************************************************************
67  Accessor type functions
68  *************************************************************************/
76  bool isHovering(void) const
77  {
78  return d_hovering;
79  }
80 
81 
89  bool isPushed(void) const
90  {
91  return d_pushed;
92  }
93 
94 
99  bool isOpened(void) const
100  {
101  return d_opened;
102  }
103 
108  bool isPopupClosing(void) const
109  {
110  return d_popupClosing;
111  }
112 
117  bool hasAutoPopup(void) const
118  {
119  return d_autoPopupTimeout > 0.0f;
120  }
121 
126  float getAutoPopupTimeout(void) const
127  {
128  return d_autoPopupTimeout;
129  }
130 
135  void setAutoPopupTimeout(float time)
136  {
137  d_autoPopupTimeout = time;
138  }
139 
147  PopupMenu* getPopupMenu(void) const
148  {
149  return d_popup;
150  }
151 
156  const UVector2& getPopupOffset(void) const
157  {
158  return d_popupOffset;
159  }
160 
165  void setPopupOffset(const UVector2& popupOffset)
166  {
167  d_popupOffset = popupOffset;
168  }
169 
170  /*************************************************************************
171  Manipulators
172  *************************************************************************/
183  void setPopupMenu(PopupMenu* popup);
184 
185 
193  void openPopupMenu(bool notify = true);
194 
195 
206  void closePopupMenu(bool notify = true);
207 
208 
216  bool togglePopupMenu(void);
217 
222  void startPopupClosing(void);
223 
228  void startPopupOpening(void);
229  /*************************************************************************
230  Construction and Destruction
231  *************************************************************************/
236  MenuItem(const String& type, const String& name);
237 
238 
243  virtual ~MenuItem(void);
244 
245 
246 protected:
247  /*************************************************************************
248  New Event Handlers
249  *************************************************************************/
254  virtual void onClicked(WindowEventArgs& e);
255 
256 
257  /*************************************************************************
258  Overridden event handlers
259  *************************************************************************/
260  virtual void onMouseMove(MouseEventArgs& e);
261  virtual void onMouseButtonDown(MouseEventArgs& e);
262  virtual void onMouseButtonUp(MouseEventArgs& e);
263  virtual void onCaptureLost(WindowEventArgs& e);
264  virtual void onMouseLeaves(MouseEventArgs& e);
265  virtual void onTextChanged(WindowEventArgs& e);
266  virtual void updateSelf(float elapsed);
267 
268 
269  /*************************************************************************
270  Implementation Functions
271  *************************************************************************/
282  void updateInternalState(const Vector2f& mouse_pos);
283 
284 
292  void closeAllMenuItemPopups();
293 
294 
305  void setPopupMenu_impl(PopupMenu* popup, bool add_as_child = true);
306 
307  /*************************************************************************
308  Implementation Data
309  *************************************************************************/
310  bool d_pushed;
311  bool d_hovering;
312  bool d_opened;
317 
319 
321 
323 
324 private:
325 
326  /*************************************************************************
327  Private methods
328  *************************************************************************/
329  void addMenuItemProperties(void);
330 
334  virtual void addChild_impl(Element* element);
335 };
336 
337 } // End of CEGUI namespace section
338 
339 #if defined(_MSC_VER)
340 # pragma warning(pop)
341 #endif
342 
343 #endif // end of guard _CEGUIMenuItem_h_