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

Last change on this file since 266 was 266, checked in by epyon, 11 years ago
  • decoupling - uid_store independent of nv::object
  • decoupling - nv::object no longer linked with lua in any way
  • decoupling - gui::element related object methods moved to element
  • uid_store can operate on void* or specialized base class
  • root class no longer carries uid store nor lua state (will be removed later)
File size: 6.2 KB
Line 
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>
18#include <nv/io_event.hh>
19#include <nv/gui/gui_common.hh>
20
21namespace nv
22{
23        namespace gui
24        {
25                class element : public object
26                {
27                protected:
28
29                        /**
30                         * Creates a new GUI element with the give root node and postioning data.
31                         *
32                         * @param r The rectangle representing the position and size of this element.
33                         */
34                        explicit element( const rectangle& r );
35
36                public:
37
38                        /**
39                         * Gets the deepest child element that contains the indicated point.
40                         *
41                         * @param p The position to check.
42                         * @returns The last child element that contains the given point.
43                         */
44                        element* get_element( const position& p );
45
46                        /**
47                         * Event handler for update events.
48                         *
49                         * @param elapsed Time since last update.
50                         */
51                        virtual void on_update( uint32 /*elapsed*/ ) {}
52
53                        /**
54                         * Event handler for draw events.
55                         */
56                        virtual void on_draw() {}
57
58                        /**
59                         * Event handler for IO events.  Calls on_event for all affected children.
60                         *
61                         * @param event The event data.
62                         * @returns ???
63                         */
64                        virtual bool on_event( const io_event& event );
65
66                        /**
67                         * Checks if this element contains the given point.
68                         *
69                         * @param p The point to check.
70                         * @returns True if the point is within the region of the element, false otherwise.
71                         */
72                        virtual bool contains( const position& p ) const;
73
74                        /**
75                         * Sets the position and size of this element relative to its parent.
76                         *
77                         * @param r The new position and size of the element.
78                         */
79                        virtual void set_relative( const rectangle& r );
80
81                        /**
82                         * Sets the position of this element relative to its parent.
83                         *
84                         * @param p The new position of the element.
85                         */
86                        virtual void set_relative( const position& p );
87
88                        /**
89                         * Gets the position and size of the element relative to its parent.
90                         *
91                         * @returns The element's position and size relative to its parent.
92                         */
93                        virtual const rectangle& get_relative() const { return m_relative; }
94
95                        /**
96                         * Gets the position and size of the element relative to the root (window).
97                         *
98                         * @returns The element's position and size relative to the root (window).
99                         */
100                        virtual const rectangle& get_absolute() const { return m_absolute; }
101
102                        /**
103                         * Gets the parent element of this element.
104                         *
105                         * @returns The parent element.
106                         */
107                        virtual element* get_parent() const { return (element*)m_parent; }
108
109                        /**
110                         * Gets whether this element is currently accepting events.
111                         *
112                         * @returns True if the element is receiving events, false otherwise.
113                         */
114                        virtual bool is_enabled() const { return m_enabled; }
115
116                        /**
117                         * Gets whether this element is currently visible.
118                         *
119                         * @returns True if the element is visible, false otherwise.
120                         */
121                        virtual bool is_visible() const { return m_visible; }
122
123                        /**
124                         * Gets whether this element needs to be redrawn.
125                         *
126                         * @returns True if the element needs to be redrawn, false if not.
127                         */
128                        virtual bool is_dirty()   const { return m_dirty; }
129
130                        /**
131                         * Sets whether this element is currently accepting events.
132                         *
133                         * @param value True to allow the element and its children to receive events, false to disable.
134                         */
135                        virtual void set_enabled( bool value ) { m_enabled = value; }
136
137                        /**
138                         * Sets whether this element is visible on the screen.
139                         *
140                         * @param value True to display the element and its children, false to hide it and its children.
141                         */
142                        virtual void set_visible( bool value ) { m_visible = value; }
143
144                        /**
145                         * Sets whether this element needs to be redrawn.
146                         *
147                         * @param value True to request that the element and its children be redrawn, false if not.
148                         */
149                        virtual void set_dirty( bool value )   { m_dirty   = value; }
150
151                        /**
152                         * Gets the text associated with this element.
153                         *
154                         * @returns A string containing the associated text.
155                         */
156                        virtual const string& get_text() const { return m_text; }
157
158                        /**
159                         * Sets the text associated with this element.
160                         *
161                         * @param text The new text to associate with this element.
162                         */
163                        virtual void set_text( const string& text ) { m_text = text; m_dirty = true; }
164
165                        /**
166                         * Gets the class name associated with this element.
167                         *
168                         * @returns A string containing the class name of this element.
169                         */
170                        virtual const string& get_class() const { return m_class; }
171
172                        /**
173                         * sets the class name associated with this element.
174                         *
175                         * @param class_ The new class name.
176                         */
177                        virtual void set_class( const string& class_ ) { m_class = class_; m_dirty = true; }
178
179                        /**
180                         * Recalcuates the absolute position of the element and the element's children.
181                         */
182                        virtual void recalculate_absolute();
183
184                        /**
185                         * Recalculates the aboslute position of the element's children.
186                         */
187                        virtual void recalculate_absolute_children();
188
189                        /**
190                         * Moves element to back of child list (top of stack)
191                         *
192                         * @returns true if object found, false otherwise
193                         */
194                        bool move_to_top( element* child );
195
196                        /**
197                         * Moves element to front of child list (bottom of stack)
198                         *
199                         * @returns true if object found, false otherwise
200                         */
201                        bool move_to_bottom( element* child );
202
203                protected:
204                        /**
205                         * Destroys the element.
206                         */
207                        virtual ~element();
208                protected:
209                        friend class environment;
210                        friend class renderer;
211
212                        string    m_class; ///< Class name.
213                        string    m_text; ///< Displayed label or text.
214                        rectangle m_relative; ///< Position relative to parent.
215                        rectangle m_absolute; ///< Position relative to window/screen.
216                        bool m_enabled; ///< Whether the element accepts events.
217                        bool m_visible; ///< Whether the element is drawn.
218                        bool m_dirty; ///< Whether the element needs updating.
219                        render_data* m_render_data; ///<   -?-
220                };
221
222        } // namespace gui
223
224} // namespace nv
225
226#endif // NV_GUI_ELEMENT_HH
Note: See TracBrowser for help on using the repository browser.