Crazy Eddies GUI System  0.7.8
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_