Crazy Eddies GUI System 0.7.5

CEGUIMenuItem.h

00001 /***********************************************************************
00002     filename:   CEGUIMenuItem.h
00003     created:    2/4/2005
00004     author:     Tomas Lindquist Olsen (based on code by Paul D Turner)
00005 
00006     purpose:    Interface to base class for MenuItem widget
00007 *************************************************************************/
00008 /***************************************************************************
00009  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
00010  *
00011  *   Permission is hereby granted, free of charge, to any person obtaining
00012  *   a copy of this software and associated documentation files (the
00013  *   "Software"), to deal in the Software without restriction, including
00014  *   without limitation the rights to use, copy, modify, merge, publish,
00015  *   distribute, sublicense, and/or sell copies of the Software, and to
00016  *   permit persons to whom the Software is furnished to do so, subject to
00017  *   the following conditions:
00018  *
00019  *   The above copyright notice and this permission notice shall be
00020  *   included in all copies or substantial portions of the Software.
00021  *
00022  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00023  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00024  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00025  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
00026  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00027  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00028  *   OTHER DEALINGS IN THE SOFTWARE.
00029  ***************************************************************************/
00030 #ifndef _CEGUIMenuItem_h_
00031 #define _CEGUIMenuItem_h_
00032 
00033 #include "../CEGUIBase.h"
00034 #include "../CEGUIWindow.h"
00035 #include "CEGUIItemEntry.h"
00036 
00037 #include "CEGUIMenuItemProperties.h"
00038 
00039 #if defined(_MSC_VER)
00040 #   pragma warning(push)
00041 #   pragma warning(disable : 4251)
00042 #endif
00043 
00044 // Start of CEGUI namespace section
00045 namespace CEGUI
00046 {
00047 
00052 class CEGUIEXPORT MenuItem : public ItemEntry
00053 {
00054 public:
00055     static const String EventNamespace;             
00056     static const String WidgetTypeName;             
00057 
00058     /*************************************************************************
00059         Event name constants
00060     *************************************************************************/
00061     // generated internally by Window
00066     static const String EventClicked;
00067 
00068 
00069     /*************************************************************************
00070         Accessor type functions
00071     *************************************************************************/
00079     bool    isHovering(void) const
00080     {
00081         return d_hovering;
00082     }
00083 
00084 
00092     bool    isPushed(void) const
00093     {
00094         return d_pushed;
00095     }
00096 
00097 
00102     bool    isOpened(void) const
00103     {
00104         return d_opened;
00105     }
00106 
00111     bool    isPopupClosing(void) const
00112     {
00113         return d_popupClosing;
00114     }
00115 
00120     bool    hasAutoPopup(void) const
00121     {
00122         return d_autoPopupTimeout > 0.0f;
00123     }
00124 
00129     float    getAutoPopupTimeout(void) const
00130     {
00131         return d_autoPopupTimeout;
00132     }
00133 
00138     void    setAutoPopupTimeout(float time)
00139     {
00140         d_autoPopupTimeout = time;
00141     }
00142 
00150     PopupMenu*  getPopupMenu(void) const
00151     {
00152         return d_popup;
00153     }
00154 
00159     const UVector2& getPopupOffset(void) const
00160     {
00161         return d_popupOffset;
00162     }
00163 
00168     void setPopupOffset(const UVector2& popupOffset)
00169     {
00170         d_popupOffset = popupOffset;
00171     }
00172 
00173     /*************************************************************************
00174         Manipulators
00175     *************************************************************************/
00186     void    setPopupMenu(PopupMenu* popup);
00187 
00188 
00196     void    openPopupMenu(bool notify = true);
00197 
00198 
00209     void    closePopupMenu(bool notify = true);
00210 
00211 
00219     bool    togglePopupMenu(void);
00220 
00225     void    startPopupClosing(void);
00226 
00231     void    startPopupOpening(void);
00232     /*************************************************************************
00233         Construction and Destruction
00234     *************************************************************************/
00239     MenuItem(const String& type, const String& name);
00240 
00241 
00246     virtual ~MenuItem(void);
00247 
00248 
00249 protected:
00250     /*************************************************************************
00251         New Event Handlers
00252     *************************************************************************/
00257     virtual void    onClicked(WindowEventArgs& e);
00258 
00259 
00260     /*************************************************************************
00261         Overridden event handlers
00262     *************************************************************************/
00263     virtual void    onMouseMove(MouseEventArgs& e);
00264     virtual void    onMouseButtonDown(MouseEventArgs& e);
00265     virtual void    onMouseButtonUp(MouseEventArgs& e);
00266     virtual void    onCaptureLost(WindowEventArgs& e);
00267     virtual void    onMouseLeaves(MouseEventArgs& e);
00268     virtual void    onTextChanged(WindowEventArgs& e);
00269     virtual void    updateSelf(float elapsed);
00270 
00271 
00272     /*************************************************************************
00273         Implementation Functions
00274     *************************************************************************/
00285     void    updateInternalState(const Point& mouse_pos);
00286 
00287 
00295     void    closeAllMenuItemPopups();
00296 
00297 
00308     void    setPopupMenu_impl(PopupMenu* popup, bool add_as_child = true);
00309 
00310 
00321     virtual bool    testClassName_impl(const String& class_name) const
00322     {
00323         if (class_name == "MenuItem") return true;
00324 
00325         return ItemEntry::testClassName_impl(class_name);
00326     }
00327 
00328 
00329     /*************************************************************************
00330         Implementation Data
00331     *************************************************************************/
00332     bool d_pushed;          
00333     bool d_hovering;        
00334     bool d_opened;          
00335     bool d_popupClosing;    
00336     bool d_popupOpening;    
00337     float d_autoPopupTimeout; 
00338     float d_autoPopupTimeElapsed;  
00339 
00340     PopupMenu*  d_popup;    
00341 
00342     bool d_popupWasClosed;  
00343 
00344     UVector2 d_popupOffset; 
00345 
00346 private:
00347     /************************************************************************
00348     Static Properties for this class
00349     ************************************************************************/
00350     static MenuItemProperties::PopupOffset d_popupOffsetProperty;
00351     static MenuItemProperties::AutoPopupTimeout d_autoPopupTimeoutProperty;
00352 
00353     /*************************************************************************
00354         Private methods
00355     *************************************************************************/
00356     void addMenuItemProperties(void);
00357 
00362     virtual void    addChild_impl(Window* wnd);
00363 };
00364 
00365 } // End of  CEGUI namespace section
00366 
00367 #if defined(_MSC_VER)
00368 #   pragma warning(pop)
00369 #endif
00370 
00371 #endif  // end of guard _CEGUIMenuItem_h_