source: OGRE/trunk/ogre_dependencies/Dependencies/include/CEGUI/elements/CEGUIMenuItem.h @ 692

Revision 692, 11.4 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
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    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 _CEGUIMenuItem_h_
27#define _CEGUIMenuItem_h_
28
29#include "CEGUIBase.h"
30#include "CEGUIWindow.h"
31#include "elements/CEGUITextItem.h"
32#include "elements/CEGUIMenuItemProperties.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
42namespace CEGUI
43{
44
45/*!
46\brief
47        Base class for menu items.
48*/
49class CEGUIEXPORT MenuItem : public TextItem
50{
51public:
52        static const String EventNamespace;                             //!< Namespace for global events
53
54        /*************************************************************************
55                Constants
56        *************************************************************************/
57        // default colours for rendering
58       
59        static const colour             DefaultHoverColour;                     //!< Default colour used when rendering in hover / highlight state.
60        static const colour             DefaultPushedColour;            //!< Default colour used when rendering in pushed state.
61        static const colour             DefaultOpenedColour;            //!< Default colour used when rendering in opended state.
62        static const colour             DefaultNormalTextColour;        //!< Default colour used when rendering the text in normal state.
63        static const colour             DefaultDisabledTextColour;      //!< Default colour used when rendering the text in disabled state.
64
65
66        /*************************************************************************
67                Event name constants
68        *************************************************************************/
69        // generated internally by Window
70        static const String EventClicked;                                       //!< The menuitem was clicked.
71
72
73        /*************************************************************************
74                Accessor type functions
75        *************************************************************************/
76        /*!
77        \brief
78                return true if user is hovering over this widget (or it's pushed and user is not over it for highlight)
79
80        \return
81                true if the user is hovering or if the button is pushed and the mouse is not over the button.  Otherwise return false.
82        */
83        bool    isHovering(void) const                  {return d_hovering;}
84
85
86        /*!
87        \brief
88                Return true if the button widget is in the pushed state.
89
90        \return
91                true if the button-type widget is pushed, false if the widget is not pushed.
92        */
93        bool    isPushed(void) const                    {return d_pushed;}
94
95
96        /*!
97        \brief
98                return text label colour used for hover / highlight rendering
99
100        \return
101                colour value that is used for the label text when rendering in the hover / highlighted states.
102        */
103        colour  getHoverColour(void) const                      {return d_hoverColour;}
104
105
106        /*!
107        \brief
108                return text label colour used for pushed rendering
109
110        \return
111                colour value that is used for the label text when rendering in the pushed state.
112        */
113        colour  getPushedColour(void) const                     {return d_pushedColour;}
114
115
116        /*!
117        \brief
118                return text label colour used for opened rendering
119
120        \return
121                colour value that is used for the label text when rendering in the opened state.
122        */
123        colour  getOpenedColour(void) const                     {return d_openedColour;}
124
125
126        /*!
127        \brief
128                return text label colour used for normal rendering
129
130        \return
131                colour value that is used for the label text when rendering in the normal state.
132        */
133        colour  getNormalTextColour(void) const                 {return d_normalTextColour;}
134
135
136        /*!
137        \brief
138                return text label colour used for disabled rendering
139
140        \return
141                colour value that is used for the label text when rendering in the disabled state.
142        */
143        colour  getDisabledTextColour(void) const               {return d_disabledTextColour;}
144
145
146        /*!
147        \brief
148                Get the PopupMenu that is currently attached to this MenuItem.
149
150        \return
151                A pointer to the currently attached PopupMenu.  Null is there is no PopupMenu attached.
152        */
153        PopupMenu*      getPopupMenu(void) const                        {return d_popup;}
154
155
156        /*************************************************************************
157                Manipulators
158        *************************************************************************/
159        /*!
160        \brief
161                Set the colour to use when rendering in the hover / highlighted states.
162
163        \param colour
164                colour value specifying the colour to be used.
165
166        \return
167                Nothing.
168        */
169        void    setHoverColour(const colour& colour);
170
171
172        /*!
173        \brief
174                Set the colour to use when rendering in the pushed state.
175
176        \param colour
177                colour value specifying the colour to be used.
178
179        \return
180                Nothing.
181        */
182        void    setPushedColour(const colour& colour);
183
184
185        /*!
186        \brief
187                Set the colour to use when rendering in the opened state.
188
189        \param colour
190                colour value specifying the colour to be used.
191
192        \return
193                Nothing.
194        */
195        void    setOpenedColour(const colour& colour);
196
197
198        /*!
199        \brief
200                Set the colour to use for the label text when rendering in the normal state.
201
202        \param colour
203                colour value specifying the colour to be used.
204
205        \return
206                Nothing.
207        */
208        void    setNormalTextColour(const colour& colour);
209
210
211        /*!
212        \brief
213                Set the colour to use for the label text when rendering in the disabled state.
214
215        \param colour
216                colour value specifying the colour to be used.
217
218        \return
219                Nothing.
220        */
221        void    setDisabledTextColour(const colour& colour);
222
223
224        /*!
225        \brief
226                Set the popup menu for this item.
227
228        \param popup
229                popupmenu window to attach to this item
230
231        \return
232                Nothing.
233        */
234        void    setPopupMenu(PopupMenu* popup);
235
236
237        /*!
238        \brief
239                Opens the PopupMenu.
240        */
241        void    openPopupMenu(void);
242
243
244        /*!
245        \brief
246                Closes the PopupMenu.
247
248        \param notify
249                true if the parent menubar is to be notified of the close.
250
251        \return
252                Nothing.
253        */
254        void    closePopupMenu(bool notify=true);
255
256
257        /*!
258        \brief
259                Toggles the PopupMenu.
260
261        \return
262                true if the popup was opened. false if it was closed.
263        */
264        bool    togglePopupMenu(void);
265
266
267        /*************************************************************************
268                Construction and Destruction
269        *************************************************************************/
270        /*!
271        \brief
272                Constructor for MenuItem objects
273        */
274        MenuItem(const String& type, const String& name);
275
276
277        /*!
278        \brief
279                Destructor for MenuItem objects
280        */
281        virtual ~MenuItem(void);
282
283
284protected:
285        /*************************************************************************
286                New Event Handlers
287        *************************************************************************/
288        /*!
289        \brief
290                handler invoked internally when the MenuItem is clicked.
291        */
292        virtual void    onClicked(WindowEventArgs& e);
293
294
295        /*************************************************************************
296                Overridden event handlers
297        *************************************************************************/
298        virtual void    onMouseMove(MouseEventArgs& e);
299        virtual void    onMouseButtonDown(MouseEventArgs& e);
300        virtual void    onMouseButtonUp(MouseEventArgs& e);
301        virtual void    onCaptureLost(WindowEventArgs& e);
302        virtual void    onMouseLeaves(MouseEventArgs& e);
303
304
305        /*************************************************************************
306                Implementation Functions
307        *************************************************************************/
308        /*!
309        \brief
310                Update the internal state of the widget with the mouse at the given position.
311
312        \param mouse_pos
313                Point object describing, in screen pixel co-ordinates, the location of the mouse cursor.
314
315        \return
316                Nothing
317        */
318        void    updateInternalState(const Point& mouse_pos);
319
320
321        /*!
322        \brief
323                Add menuitem specific events
324        */
325        void    addMenuItemEvents(void);
326
327
328        /*!
329        \brief
330                Recursive function that closes all popups down the hierarcy starting with this one.
331
332        \return
333                Nothing.
334        */
335        void    closeAllMenuItemPopups();
336
337
338        /*!
339        \brief
340                Return whether this window was inherited from the given class name at some point in the inheritance heirarchy.
341
342        \param class_name
343                The class name that is to be checked.
344
345        \return
346                true if this window was inherited from \a class_name. false if not.
347        */
348        virtual bool    testClassName_impl(const String& class_name) const
349        {
350                if (class_name==(const utf8*)"MenuItem")        return true;
351                return TextItem::testClassName_impl(class_name);
352        }
353
354
355        /*************************************************************************
356                Implementation Rendering Functions
357        *************************************************************************/
358
359        /*************************************************************************
360                Implementation Data
361        *************************************************************************/
362        bool    d_pushed;                       //!< true when widget is pushed
363        bool    d_hovering;                     //!< true when the button is in 'hover' state and requires the hover rendering.
364        bool    d_opened;                       //!< true when the menu item's popup menu is opened.
365
366        // common rendering setting data
367        colour  d_hoverColour;                                  //!< Colour used when rendering in highlighted state
368        colour  d_pushedColour;                                 //!< Colour used when rendering in pushed state
369        colour  d_openedColour;                                 //!< Colour used when rendering in opened state
370        colour  d_normalTextColour;                             //!< Colour used for the text when rendering in normal state
371        colour  d_disabledTextColour;                   //!< Colour used for the text when rendering in disabled state
372
373        PopupMenu* d_popup;                                             //!< PopupMenu that this item displays when activated.
374
375        bool    d_popupWasClosed;                               //!< Used internally to determine if a popup was just closed on a Clicked event
376
377private:
378        /*************************************************************************
379                Static Properties for this class
380        *************************************************************************/
381        static MenuItemProperties::HoverColour                  d_hoverColourProperty;
382        static MenuItemProperties::PushedColour                 d_pushedColourProperty;
383        static MenuItemProperties::OpenedColour                 d_openedColourProperty;
384        static MenuItemProperties::NormalTextColour             d_normalTextColourProperty;
385        static MenuItemProperties::DisabledTextColour   d_disabledTextColourProperty;
386
387
388        /*************************************************************************
389                Private methods
390        *************************************************************************/
391        void addMenuItemProperties(void);
392
393
394        /*!
395        \brief
396                Add given window to child list at an appropriate position
397        */
398        virtual void    addChild_impl(Window* wnd);
399};
400
401} // End of  CEGUI namespace section
402
403
404#if defined(_MSC_VER)
405#       pragma warning(pop)
406#endif
407
408
409#endif  // end of guard _CEGUIMenuItem_h_
Note: See TracBrowser for help on using the repository browser.