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 |
|
---|
21 | namespace 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 positioning data.
|
---|
31 | *
|
---|
32 | * @param r The rectangle representing the position and size of this element.
|
---|
33 | */
|
---|
34 | explicit element( const rectangle& r )
|
---|
35 | : object( "" ), m_class(""), m_relative( r ), m_absolute( r ), m_enabled( true ), m_visible( true ), m_dirty( true ), m_render_data( nullptr ) {}
|
---|
36 |
|
---|
37 | public:
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * Checks if this element contains the given point.
|
---|
41 | *
|
---|
42 | * @param p The point to check.
|
---|
43 | * @returns True if the point is within the region of the element, false otherwise.
|
---|
44 | */
|
---|
45 | virtual bool contains( const position& p ) const
|
---|
46 | {
|
---|
47 | return m_absolute.contains( p );
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Gets the position and size of the element relative to its parent.
|
---|
52 | *
|
---|
53 | * @returns The element's position and size relative to its parent.
|
---|
54 | */
|
---|
55 | virtual const rectangle& get_relative() const { return m_relative; }
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Gets the position and size of the element relative to the root (window).
|
---|
59 | *
|
---|
60 | * @returns The element's position and size relative to the root (window).
|
---|
61 | */
|
---|
62 | virtual const rectangle& get_absolute() const { return m_absolute; }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Gets whether this element is currently accepting events.
|
---|
66 | *
|
---|
67 | * @returns True if the element is receiving events, false otherwise.
|
---|
68 | */
|
---|
69 | virtual bool is_enabled() const { return m_enabled; }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Gets whether this element is currently visible.
|
---|
73 | *
|
---|
74 | * @returns True if the element is visible, false otherwise.
|
---|
75 | */
|
---|
76 | virtual bool is_visible() const { return m_visible; }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Gets whether this element needs to be redrawn.
|
---|
80 | *
|
---|
81 | * @returns True if the element needs to be redrawn, false if not.
|
---|
82 | */
|
---|
83 | virtual bool is_dirty() const { return m_dirty; }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * Sets whether this element is currently accepting events.
|
---|
87 | *
|
---|
88 | * @param value True to allow the element and its children to receive events, false to disable.
|
---|
89 | */
|
---|
90 | virtual void set_enabled( bool value ) { m_enabled = value; }
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Sets whether this element is visible on the screen.
|
---|
94 | *
|
---|
95 | * @param value True to display the element and its children, false to hide it and its children.
|
---|
96 | */
|
---|
97 | virtual void set_visible( bool value ) { m_visible = value; }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Sets whether this element needs to be redrawn.
|
---|
101 | *
|
---|
102 | * @param value True to request that the element and its children be redrawn, false if not.
|
---|
103 | */
|
---|
104 | virtual void set_dirty( bool value ) { m_dirty = value; }
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Gets the text associated with this element.
|
---|
108 | *
|
---|
109 | * @returns A string containing the associated text.
|
---|
110 | */
|
---|
111 | virtual const string& get_text() const { return m_text; }
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * Sets the text associated with this element.
|
---|
115 | *
|
---|
116 | * @param text The new text to associate with this element.
|
---|
117 | */
|
---|
118 | virtual void set_text( const string& text ) { m_text = text; m_dirty = true; }
|
---|
119 |
|
---|
120 | /**
|
---|
121 | * Gets the class name associated with this element.
|
---|
122 | *
|
---|
123 | * @returns A string containing the class name of this element.
|
---|
124 | */
|
---|
125 | virtual const string& get_class() const { return m_class; }
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * sets the class name associated with this element.
|
---|
129 | *
|
---|
130 | * @param class_ The new class name.
|
---|
131 | */
|
---|
132 | virtual void set_class( const string& class_ ) { m_class = class_; m_dirty = true; }
|
---|
133 |
|
---|
134 | protected:
|
---|
135 | /**
|
---|
136 | * Destroys the element.
|
---|
137 | */
|
---|
138 | virtual ~element() { delete m_render_data; }
|
---|
139 | protected:
|
---|
140 | friend class environment;
|
---|
141 | friend class renderer;
|
---|
142 |
|
---|
143 | string m_class; ///< Class name.
|
---|
144 | string m_text; ///< Displayed label or text.
|
---|
145 | rectangle m_relative; ///< Position relative to parent.
|
---|
146 | rectangle m_absolute; ///< Position relative to window/screen.
|
---|
147 | bool m_enabled; ///< Whether the element accepts events.
|
---|
148 | bool m_visible; ///< Whether the element is drawn.
|
---|
149 | bool m_dirty; ///< Whether the element needs updating.
|
---|
150 | render_data* m_render_data; ///< -?-
|
---|
151 | };
|
---|
152 |
|
---|
153 | } // namespace gui
|
---|
154 |
|
---|
155 | } // namespace nv
|
---|
156 |
|
---|
157 | #endif // NV_GUI_ELEMENT_HH
|
---|