source: trunk/nv/gui/gui_element.hh @ 132

Last change on this file since 132 was 132, checked in by shark, 12 years ago
  • Added missing spaces in all of my documentation comments (whoops!)
  • nv::to_string( string ) and nv::from_string( string, string ) were missing template <>
File size: 6.1 KB
RevLine 
[66]1// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
2// http://chaosforge.org/
3//
4// This file is part of NV Libraries.
5// For conditions of distribution and use, see copyright notice in nv.hh
6
7/**
8 * @file gui_element.hh
9 * @author Kornel Kisielewicz
10 * @brief GUI Element
11 */
12
13#ifndef NV_GUI_ELEMENT_HH
14#define NV_GUI_ELEMENT_HH
15
16#include <nv/object.hh>
17#include <nv/position.hh>
[69]18#include <nv/io_event.hh>
19#include <nv/gui/gui_common.hh>
[66]20
21namespace nv
22{
23        namespace gui
24        {
25                class element : public object
26                {
27                public:
[110]28
29                        /**
[132]30                         * Creates a new GUI element.
[110]31                         */
[66]32                        element() : object() {}
[110]33
34                        /**
[132]35                         * Creates a new GUI element with the give root node and postioning data.
[110]36                         *
[132]37                         * @param aroot The root object that will be this object's parent.
38                         * @param r The rectangle representing the position and size of this element.
[110]39                         */
[99]40                        element( root* aroot, const rectangle& r );
[110]41
42                        /**
[132]43                         * Gets the deepest child element that contains the indicated point.
[110]44                         *
[132]45                         * @param p The position to check.
46                         * @returns The last child element that contains the given point.
[110]47                         */
[66]48                        element* get_element( const position& p );
[110]49
50                        /**
[132]51                         * Event handler for update events.  Calls on_update for all affected children.
[110]52                         *
[132]53                         * @param elapsed Time since last update.
[110]54                         */
[66]55                        virtual void on_update( uint32 elapsed );
[110]56
57                        /**
[132]58                         * Event handler for draw events.  Calls on_draw for all affected children.
[110]59                         */
[66]60                        virtual void on_draw();
[110]61
62                        /**
[132]63                         * Event handler for IO events.  Calls on_event for all affected children.
[110]64                         *
[132]65                         * @param event The event data.
66                         * @returns ???
[110]67                         */
[69]68                        virtual bool on_event( const io_event& event );
[110]69
70                        /**
[132]71                         * Checks if this element contains the given point.
[110]72                         *
[132]73                         * @param p The point to check.
74                         * @returns True if the point is within the region of the element, false otherwise.
[110]75                         */
[69]76                        virtual bool contains( const position& p ) const;
[110]77
78                        /**
[132]79                         * Sets the position and size of this element relative to its parent.
[110]80                         *
[132]81                         * @param r The new position and size of the element.
[110]82                         */
[66]83                        virtual void set_relative( const rectangle& r );
[110]84
85                        /**
[132]86                         * Sets the position of this element relative to its parent.
[110]87                         *
[132]88                         * @param p The new position of the element.
[110]89                         */
[66]90                        virtual void set_relative( const position& p );
[110]91
92                        /**
[132]93                         * Gets the position and size of the element relative to its parent.
[110]94                         *
[132]95                         * @returns The element's position and size relative to its parent.
[110]96                         */
[66]97                        virtual const rectangle& get_relative() const { return m_relative; }
[110]98
99                        /**
[132]100                         * Gets the position and size of the element relative to the root (window).
[110]101                         *
[132]102                         * @returns The element's position and size relative to the root (window).
[110]103                         */
[66]104                        virtual const rectangle& get_absolute() const { return m_absolute; }
[110]105
106                        /**
[132]107                         * Gets the parent element of this element.
[110]108                         *
[132]109                         * @returns The parent element.
[110]110                         */
[66]111                        virtual element* get_parent() const { return (element*)m_parent; }
[110]112
113                        /**
[132]114                         * Gets whether this element is currently accepting events.
[110]115                         *
[132]116                         * @returns True if the element is receiving events, false otherwise.
[110]117                         */
[66]118                        virtual bool is_enabled() const { return m_enabled; }
[110]119
120                        /**
[132]121                         * Gets whether this element is currently visible.
[110]122                         *
[132]123                         * @returns True if the element is visible, false otherwise.
[110]124                         */
[66]125                        virtual bool is_visible() const { return m_visible; }
[110]126
127                        /**
[132]128                         * Gets whether this element needs to be redrawn.
[110]129                         *
[132]130                         * @returns True if the element needs to be redrawn, false if not.
[110]131                         */
[69]132                        virtual bool is_dirty()   const { return m_dirty; }
[110]133
134                        /**
[132]135                         * Sets whether this element is currently accepting events.
[110]136                         *
[132]137                         * @param value True to allow the element and its children to receive events, false to disable.
[110]138                         */
[66]139                        virtual void set_enabled( bool value ) { m_enabled = value; }
[110]140
141                        /**
[132]142                         * Sets whether this element is visible on the screen.
[110]143                         *
[132]144                         * @param value True to display the element and its children, false to hide it and its children.
[110]145                         */
[66]146                        virtual void set_visible( bool value ) { m_visible = value; }
[110]147
148                        /**
[132]149                         * Sets whether this element needs to be redrawn.
[110]150                         *
[132]151                         * @param value True to request that the element and its children be redrawn, false if not.
[110]152                         */
[69]153                        virtual void set_dirty( bool value )   { m_dirty   = value; }
[110]154
155                        /**
[132]156                         * Gets the text associated with this element.
[110]157                         *
[132]158                         * @returns A string containing the associated text.
[110]159                         */
[69]160                        virtual const string& get_text() const { return m_text; }
[110]161
162                        /**
[132]163                         * Sets the text associated with this element.
[110]164                         *
[132]165                         * @param text The new text to associate with this element.
[110]166                         */
[69]167                        virtual void set_text( const string& text ) { m_text = text; m_dirty = true; }
[110]168
169                        /**
[132]170                         * Gets the class name associated with this element.
[110]171                         *
[132]172                         * @returns A string containing the class name of this element.
[110]173                         */
[69]174                        virtual const string& get_class() const { return m_class; }
[110]175
176                        /**
[132]177                         * sets the class name associated with this element.
[110]178                         *
[132]179                         * @param class_ The new class name.
[110]180                         */
[69]181                        virtual void set_class( const string& class_ ) { m_class = class_; m_dirty = true; }
[110]182
183                        /**
[132]184                         * Recalcuates the absolute position of the element and the element's children.
[110]185                         */
[66]186                        virtual void recalculate_absolute();
[110]187
188                        /**
[132]189                         * Recalculates the aboslute position of the element's children.
[110]190                         */
[99]191                        virtual void recalculate_absolute_children();
[110]192
193                        /**
[132]194                         * Destroys the element.
[110]195                         */
[99]196                        virtual ~element();
[66]197                protected:
[99]198                        friend class environment;
[126]199                        friend class renderer;
[99]200
[110]201                        string    m_class; ///< Class name.
202                        string    m_text; ///< Displayed label or text.
203                        rectangle m_relative; ///< Position relative to parent.
204                        rectangle m_absolute; ///< Position relative to window/screen.
205                        bool m_enabled; ///< Whether the element accepts events.
206                        bool m_visible; ///< Whether the element is drawn.
207                        bool m_dirty; ///< Whether the element needs updating.
208                        render_data* m_render_data; ///<   -?-
[66]209                };
210
211        } // namespace gui
212
213} // namespace nv
214
215#endif // NV_GUI_ELEMENT_HH
Note: See TracBrowser for help on using the repository browser.