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

Last change on this file since 126 was 126, checked in by epyon, 12 years ago
  • commiting the gui_element/gui_environment and gui_renderer in it's current state
  • the implementation is very WIP though, but too long stayed out of SVN
  • minor fix to c_file_system
File size: 6.0 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                public:
28
29                        /**
30                         *Creates a new GUI element.
31                         */
32                        element() : object() {}
33
34                        /**
35                         *Creates a new GUI element with the give root node and postioning data.
36                         *
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.
39                         */
40                        element( root* aroot, const rectangle& r );
41
42                        /**
43                         *Gets the deepest child element that contains the indicated point.
44                         *
45                         *@param p The position to check.
46                         *@returns The last child element that contains the given point.
47                         */
48                        element* get_element( const position& p );
49
50                        /**
51                         *Event handler for update events.  Calls on_update for all affected children.
52                         *
53                         *@param elapsed Time since last update.
54                         */
55                        virtual void on_update( uint32 elapsed );
56
57                        /**
58                         *Event handler for draw events.  Calls on_draw for all affected children.
59                         */
60                        virtual void on_draw();
61
62                        /**
63                         *Event handler for IO events.  Class on_event for all affected children.
64                         *
65                         *@param event The event data.
66                         *@returns ???
67                         */
68                        virtual bool on_event( const io_event& event );
69
70                        /**
71                         *Checks if this element contains the given point.
72                         *
73                         *@param p The point to check.
74                         *@returns True if the point is within the region of the element, false otherwise.
75                         */
76                        virtual bool contains( const position& p ) const;
77
78                        /**
79                         *Sets the position and size of this element relative to its parent.
80                         *
81                         *@param r The new position and size of the element.
82                         */
83                        virtual void set_relative( const rectangle& r );
84
85                        /**
86                         *Sets the position of this element relative to its parent.
87                         *
88                         *@param p The new position of the element.
89                         */
90                        virtual void set_relative( const position& p );
91
92                        /**
93                         *Gets the position and size of the element relative to its parent.
94                         *
95                         *@returns The element's position and size relative to its parent.
96                         */
97                        virtual const rectangle& get_relative() const { return m_relative; }
98
99                        /**
100                         *Gets the position and size of the element relative to the root (window).
101                         *
102                         *@returns The element's position and size relative to the root (window).
103                         */
104                        virtual const rectangle& get_absolute() const { return m_absolute; }
105
106                        /**
107                         *Gets the parent element of this element.
108                         *
109                         *@returns The parent element.
110                         */
111                        virtual element* get_parent() const { return (element*)m_parent; }
112
113                        /**
114                         *Gets whether this element is currently accepting events.
115                         *
116                         *@returns True if the element is receiving events, false otherwise.
117                         */
118                        virtual bool is_enabled() const { return m_enabled; }
119
120                        /**
121                         *Gets whether this element is currently visible.
122                         *
123                         *@returns True if the element is visible, false otherwise.
124                         */
125                        virtual bool is_visible() const { return m_visible; }
126
127                        /**
128                         *Gets whether this element needs to be redrawn.
129                         *
130                         *@returns True if the element needs to be redrawn, false if not.
131                         */
132                        virtual bool is_dirty()   const { return m_dirty; }
133
134                        /**
135                         *Sets whether this element is currently accepting events.
136                         *
137                         *@param value True to allow the element and its children to receive events, false to disable.
138                         */
139                        virtual void set_enabled( bool value ) { m_enabled = value; }
140
141                        /**
142                         *Sets whether this element is visible on the screen.
143                         *
144                         *@param value True to display the element and its children, false to hide it and its children.
145                         */
146                        virtual void set_visible( bool value ) { m_visible = value; }
147
148                        /**
149                         *Sets whether this element needs to be redrawn.
150                         *
151                         *@param value True to request that the element and its children be redrawn, false if not.
152                         */
153                        virtual void set_dirty( bool value )   { m_dirty   = value; }
154
155                        /**
156                         *Gets the text associated with this element.
157                         *
158                         *@returns A string containing the associated text.
159                         */
160                        virtual const string& get_text() const { return m_text; }
161
162                        /**
163                         *Sets the text associated with this element.
164                         *
165                         *@param text The new text to associate with this element.
166                         */
167                        virtual void set_text( const string& text ) { m_text = text; m_dirty = true; }
168
169                        /**
170                         *Gets the class name associated with this element.
171                         *
172                         *@returns A string containing the class name of this element.
173                         */
174                        virtual const string& get_class() const { return m_class; }
175
176                        /**
177                         *sets the class name associated with this element.
178                         *
179                         *@param class_ The new class name.
180                         */
181                        virtual void set_class( const string& class_ ) { m_class = class_; m_dirty = true; }
182
183                        /**
184                         *Recalcuates the absolute position of the element and the element's children.
185                         */
186                        virtual void recalculate_absolute();
187
188                        /**
189                         *Recalculates the aboslute position of the element's children.
190                         */
191                        virtual void recalculate_absolute_children();
192
193                        /**
194                         *Destroys the element.
195                         */
196                        virtual ~element();
197                protected:
198                        friend class environment;
199                        friend class renderer;
200
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; ///<   -?-
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.