[1812] | 1 | /************************************************************************
|
---|
| 2 | filename: CEGUIMenuBase.h
|
---|
| 3 | created: 5/4/2005
|
---|
| 4 | author: Tomas Lindquist Olsen (based on code by Paul D Turner)
|
---|
| 5 |
|
---|
| 6 | purpose: Interface to base class for MenuBase widget
|
---|
| 7 | *************************************************************************/
|
---|
| 8 | /*************************************************************************
|
---|
| 9 | Crazy Eddie's GUI System (http://www.cegui.org.uk)
|
---|
| 10 | Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
|
---|
| 11 |
|
---|
| 12 | This library is free software; you can redistribute it and/or
|
---|
| 13 | modify it under the terms of the GNU Lesser General Public
|
---|
| 14 | License as published by the Free Software Foundation; either
|
---|
| 15 | version 2.1 of the License, or (at your option) any later version.
|
---|
| 16 |
|
---|
| 17 | This library is distributed in the hope that it will be useful,
|
---|
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | Lesser General Public License for more details.
|
---|
| 21 |
|
---|
| 22 | You should have received a copy of the GNU Lesser General Public
|
---|
| 23 | License along with this library; if not, write to the Free Software
|
---|
| 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 25 | *************************************************************************/
|
---|
| 26 | #ifndef _CEGUIMenuBase_h_
|
---|
| 27 | #define _CEGUIMenuBase_h_
|
---|
| 28 |
|
---|
| 29 | #include "CEGUIBase.h"
|
---|
| 30 | #include "CEGUIWindow.h"
|
---|
| 31 | #include "elements/CEGUIMenuBaseProperties.h"
|
---|
| 32 | #include "elements/CEGUIItemListBase.h"
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 | #if defined(_MSC_VER)
|
---|
| 36 | # pragma warning(push)
|
---|
| 37 | # pragma warning(disable : 4251)
|
---|
| 38 | #endif
|
---|
| 39 |
|
---|
| 40 |
|
---|
| 41 | // Start of CEGUI namespace section
|
---|
| 42 | namespace CEGUI
|
---|
| 43 | {
|
---|
| 44 |
|
---|
| 45 | /*!
|
---|
| 46 | \brief
|
---|
| 47 | Abstract base class for menus.
|
---|
| 48 | */
|
---|
| 49 | class CEGUIEXPORT MenuBase : public ItemListBase
|
---|
| 50 | {
|
---|
| 51 | public:
|
---|
| 52 | static const String EventNamespace; //!< Namespace for global events
|
---|
| 53 |
|
---|
| 54 | /*************************************************************************
|
---|
| 55 | Constants
|
---|
| 56 | *************************************************************************/
|
---|
| 57 | static const colour DefaultBackgroundColour; //!< Default background colour
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | /*************************************************************************
|
---|
| 61 | Event name constants
|
---|
| 62 | *************************************************************************/
|
---|
| 63 | // generated internally by Window
|
---|
| 64 | static const String EventPopupOpened; //!< A MenuItem attached to this menu opened a PopupMenu
|
---|
| 65 | static const String EventPopupClosed; //!< A MenuItem attached to this menu opened a PopupMenu
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | /*************************************************************************
|
---|
| 69 | Accessor type functions
|
---|
| 70 | *************************************************************************/
|
---|
| 71 | /*!
|
---|
| 72 | \brief
|
---|
| 73 | Get the item spacing for this menu.
|
---|
| 74 |
|
---|
| 75 | \return
|
---|
| 76 | A float value with the current item spacing for this menu
|
---|
| 77 | */
|
---|
| 78 | float getItemSpacing(void) const {return d_itemSpacing;}
|
---|
| 79 |
|
---|
| 80 |
|
---|
| 81 | /*!
|
---|
| 82 | \brief
|
---|
| 83 | Get the horizontal padding for this menu's items.
|
---|
| 84 |
|
---|
| 85 | \return
|
---|
| 86 | A float value with the current horizontal padding for this menu's items.
|
---|
| 87 | */
|
---|
| 88 | float getHorzPadding(void) const {return d_horzPadding;}
|
---|
| 89 |
|
---|
| 90 |
|
---|
| 91 | /*!
|
---|
| 92 | \brief
|
---|
| 93 | Get the vertical padding for this menu's items.
|
---|
| 94 |
|
---|
| 95 | \return
|
---|
| 96 | A float value with the current vertical padding for this menu's items.
|
---|
| 97 | */
|
---|
| 98 | float getVertPadding(void) const {return d_vertPadding;}
|
---|
| 99 |
|
---|
| 100 |
|
---|
| 101 | /*!
|
---|
| 102 | \brief
|
---|
| 103 | Get the border width for this menu.
|
---|
| 104 |
|
---|
| 105 | \return
|
---|
| 106 | A float value with the current border width for this menu.
|
---|
| 107 | */
|
---|
| 108 | float getBorderWidth(void) const {return d_borderWidth;}
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | /*!
|
---|
| 112 | \brief
|
---|
| 113 | Get the ColourRect with the colours used for rendering the background of this menu.
|
---|
| 114 |
|
---|
| 115 | \return
|
---|
| 116 | A ColourRect with the colours used for rendering the background of this menu.
|
---|
| 117 | */
|
---|
| 118 | const ColourRect& getBackgroundColours(void) const {return d_backgroundColours;}
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 | /*!
|
---|
| 122 | \brief
|
---|
| 123 | Return whether this menu allows multiple popup menus to open at the same time.
|
---|
| 124 |
|
---|
| 125 | \return
|
---|
| 126 | true if this menu allows multiple popup menus to be opened simultaneously. false if not
|
---|
| 127 | */
|
---|
| 128 | bool isMultiplePopupsAllowed(void) const {return d_allowMultiplePopups;}
|
---|
| 129 |
|
---|
| 130 |
|
---|
| 131 | /*!
|
---|
| 132 | \brief
|
---|
| 133 | Get currently opened MenuItem in this menu. Returns NULL if menu item is open.
|
---|
| 134 |
|
---|
| 135 | \return
|
---|
| 136 | Pointer to the MenuItem currently open.
|
---|
| 137 | */
|
---|
| 138 | MenuItem* getPopupMenuItem(void) const {return d_popup;}
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 | /*************************************************************************
|
---|
| 142 | Manipulators
|
---|
| 143 | *************************************************************************/
|
---|
| 144 | /*!
|
---|
| 145 | \brief
|
---|
| 146 | Set the item spacing for this menu.
|
---|
| 147 | */
|
---|
| 148 | void setItemSpacing(float spacing) {d_itemSpacing=spacing;handleUpdatedItemData();}
|
---|
| 149 |
|
---|
| 150 |
|
---|
| 151 | /*!
|
---|
| 152 | \brief
|
---|
| 153 | Set the horizontal padding for this menu's items.
|
---|
| 154 | */
|
---|
| 155 | void setHorzPadding(float padding) {d_horzPadding=padding;handleUpdatedItemData();}
|
---|
| 156 |
|
---|
| 157 |
|
---|
| 158 | /*!
|
---|
| 159 | \brief
|
---|
| 160 | Set the vertical padding for this menu's items.
|
---|
| 161 | */
|
---|
| 162 | void setVertPadding(float padding) {d_vertPadding=padding;handleUpdatedItemData();}
|
---|
| 163 |
|
---|
| 164 |
|
---|
| 165 | /*!
|
---|
| 166 | \brief
|
---|
| 167 | Set the border width for this menu.
|
---|
| 168 | */
|
---|
| 169 | void setBorderWidth(float border) {d_borderWidth=border;handleUpdatedItemData();}
|
---|
| 170 |
|
---|
| 171 |
|
---|
| 172 | /*!
|
---|
| 173 | \brief
|
---|
| 174 | Set the background colours to used when rendereing this menu.
|
---|
| 175 | */
|
---|
| 176 | void setBackgroundColours(const ColourRect& cr) {d_backgroundColours=cr;}
|
---|
| 177 |
|
---|
| 178 |
|
---|
| 179 | /*!
|
---|
| 180 | \brief
|
---|
| 181 | Change the currently open MenuItem in this menu.
|
---|
| 182 |
|
---|
| 183 | \param item
|
---|
| 184 | Pointer to a MenuItem to open or NULL to close any opened.
|
---|
| 185 | */
|
---|
| 186 | void changePopupMenuItem(MenuItem* item);
|
---|
| 187 |
|
---|
| 188 |
|
---|
| 189 | /*!
|
---|
| 190 | \brief
|
---|
| 191 | Set whether this menu allows multiple popup menus to opened simultaneously.
|
---|
| 192 | */
|
---|
| 193 | void setAllowMultiplePopups(bool setting) {d_allowMultiplePopups=setting;}
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 | /*************************************************************************
|
---|
| 197 | Construction and Destruction
|
---|
| 198 | *************************************************************************/
|
---|
| 199 | /*!
|
---|
| 200 | \brief
|
---|
| 201 | Constructor for MenuBase objects
|
---|
| 202 | */
|
---|
| 203 | MenuBase(const String& type, const String& name);
|
---|
| 204 |
|
---|
| 205 |
|
---|
| 206 | /*!
|
---|
| 207 | \brief
|
---|
| 208 | Destructor for MenuBase objects
|
---|
| 209 | */
|
---|
| 210 | virtual ~MenuBase(void);
|
---|
| 211 |
|
---|
| 212 |
|
---|
| 213 | protected:
|
---|
| 214 | /*************************************************************************
|
---|
| 215 | New Event Handlers
|
---|
| 216 | *************************************************************************/
|
---|
| 217 | /*!
|
---|
| 218 | \brief
|
---|
| 219 | handler invoked internally when the a MenuItem attached to this menu opens its popup.
|
---|
| 220 | */
|
---|
| 221 | virtual void onPopupOpened(WindowEventArgs& e);
|
---|
| 222 |
|
---|
| 223 |
|
---|
| 224 | /*!
|
---|
| 225 | \brief
|
---|
| 226 | handler invoked internally when the a MenuItem attached to this menu closes its popup.
|
---|
| 227 | */
|
---|
| 228 | virtual void onPopupClosed(WindowEventArgs& e);
|
---|
| 229 |
|
---|
| 230 |
|
---|
| 231 | /*************************************************************************
|
---|
| 232 | Implementation Functions
|
---|
| 233 | *************************************************************************/
|
---|
| 234 | /*!
|
---|
| 235 | \brief
|
---|
| 236 | Add MenuBase specific events
|
---|
| 237 | */
|
---|
| 238 | void addMenuBaseEvents(void);
|
---|
| 239 |
|
---|
| 240 |
|
---|
| 241 | /*!
|
---|
| 242 | \brief
|
---|
| 243 | Return whether this window was inherited from the given class name at some point in the inheritance heirarchy.
|
---|
| 244 |
|
---|
| 245 | \param class_name
|
---|
| 246 | The class name that is to be checked.
|
---|
| 247 |
|
---|
| 248 | \return
|
---|
| 249 | true if this window was inherited from \a class_name. false if not.
|
---|
| 250 | */
|
---|
| 251 | virtual bool testClassName_impl(const String& class_name) const
|
---|
| 252 | {
|
---|
| 253 | if (class_name==(const utf8*)"MenuBase") return true;
|
---|
| 254 | return ItemListBase::testClassName_impl(class_name);
|
---|
| 255 | }
|
---|
| 256 |
|
---|
| 257 |
|
---|
| 258 | /*************************************************************************
|
---|
| 259 | Implementation Data
|
---|
| 260 | *************************************************************************/
|
---|
| 261 | float d_itemSpacing; //!< The spacing in pixels between items.
|
---|
| 262 | float d_horzPadding; //!< The width in pixels that is added to the left and right of each item.
|
---|
| 263 | float d_vertPadding; //!< The height in pixels that is added to the top and bottom of each item.
|
---|
| 264 | float d_borderWidth; //!< The width in pixels of the border around the entire content of this menu.
|
---|
| 265 |
|
---|
| 266 | ColourRect d_backgroundColours; //!< The colours used when rendering the background of this menu.
|
---|
| 267 |
|
---|
| 268 | MenuItem* d_popup; //!< The currently open MenuItem. NULL if no item is open. If multiple popups are allowed, this means nothing.
|
---|
| 269 | bool d_allowMultiplePopups; //!< true if multiple popup menus are allowed smultaneously. false if not.
|
---|
| 270 |
|
---|
| 271 |
|
---|
| 272 | private:
|
---|
| 273 | /*************************************************************************
|
---|
| 274 | Static Properties for this class
|
---|
| 275 | *************************************************************************/
|
---|
| 276 | static MenuBaseProperties::ItemSpacing d_itemSpacingProperty;
|
---|
| 277 | static MenuBaseProperties::HorzPadding d_horzPaddingProperty;
|
---|
| 278 | static MenuBaseProperties::VertPadding d_vertPaddingProperty;
|
---|
| 279 | static MenuBaseProperties::BorderWidth d_borderWidthProperty;
|
---|
| 280 | static MenuBaseProperties::BackgroundColours d_backgroundColoursProperty;
|
---|
| 281 | static MenuBaseProperties::AllowMultiplePopups d_allowMultiplePopupsProperty;
|
---|
| 282 |
|
---|
| 283 | /*************************************************************************
|
---|
| 284 | Private methods
|
---|
| 285 | *************************************************************************/
|
---|
| 286 | void addMenuBaseProperties(void);
|
---|
| 287 | };
|
---|
| 288 |
|
---|
| 289 | } // End of CEGUI namespace section
|
---|
| 290 |
|
---|
| 291 |
|
---|
| 292 | #if defined(_MSC_VER)
|
---|
| 293 | # pragma warning(pop)
|
---|
| 294 | #endif
|
---|
| 295 |
|
---|
| 296 | #endif // end of guard _CEGUIMenuBase_h_
|
---|