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

Last change on this file since 267 was 267, checked in by epyon, 11 years ago
  • gui::element class now pure data
  • gui::element related code in environment
  • gui shaders use general library mechanism
File size: 4.6 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                {
[257]27                protected:
[110]28
29                        /**
[267]30                         * Creates a new GUI element with the give root node and positioning data.
[110]31                         *
[132]32                         * @param r The rectangle representing the position and size of this element.
[110]33                         */
[267]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 ) {}
[110]36
[257]37                public:
38
[110]39                        /**
[132]40                         * Checks if this element contains the given point.
[110]41                         *
[132]42                         * @param p The point to check.
43                         * @returns True if the point is within the region of the element, false otherwise.
[110]44                         */
[267]45                        virtual bool contains( const position& p ) const
46                        {
47                                return m_absolute.contains( p );
48                        }
[110]49
50                        /**
[132]51                         * Gets the position and size of the element relative to its parent.
[110]52                         *
[132]53                         * @returns The element's position and size relative to its parent.
[110]54                         */
[66]55                        virtual const rectangle& get_relative() const { return m_relative; }
[110]56
57                        /**
[132]58                         * Gets the position and size of the element relative to the root (window).
[110]59                         *
[132]60                         * @returns The element's position and size relative to the root (window).
[110]61                         */
[66]62                        virtual const rectangle& get_absolute() const { return m_absolute; }
[110]63
64                        /**
[132]65                         * Gets whether this element is currently accepting events.
[110]66                         *
[132]67                         * @returns True if the element is receiving events, false otherwise.
[110]68                         */
[66]69                        virtual bool is_enabled() const { return m_enabled; }
[110]70
71                        /**
[132]72                         * Gets whether this element is currently visible.
[110]73                         *
[132]74                         * @returns True if the element is visible, false otherwise.
[110]75                         */
[66]76                        virtual bool is_visible() const { return m_visible; }
[110]77
78                        /**
[132]79                         * Gets whether this element needs to be redrawn.
[110]80                         *
[132]81                         * @returns True if the element needs to be redrawn, false if not.
[110]82                         */
[69]83                        virtual bool is_dirty()   const { return m_dirty; }
[110]84
85                        /**
[132]86                         * Sets whether this element is currently accepting events.
[110]87                         *
[132]88                         * @param value True to allow the element and its children to receive events, false to disable.
[110]89                         */
[66]90                        virtual void set_enabled( bool value ) { m_enabled = value; }
[110]91
92                        /**
[132]93                         * Sets whether this element is visible on the screen.
[110]94                         *
[132]95                         * @param value True to display the element and its children, false to hide it and its children.
[110]96                         */
[66]97                        virtual void set_visible( bool value ) { m_visible = value; }
[110]98
99                        /**
[132]100                         * Sets whether this element needs to be redrawn.
[110]101                         *
[132]102                         * @param value True to request that the element and its children be redrawn, false if not.
[110]103                         */
[69]104                        virtual void set_dirty( bool value )   { m_dirty   = value; }
[110]105
106                        /**
[132]107                         * Gets the text associated with this element.
[110]108                         *
[132]109                         * @returns A string containing the associated text.
[110]110                         */
[69]111                        virtual const string& get_text() const { return m_text; }
[110]112
113                        /**
[132]114                         * Sets the text associated with this element.
[110]115                         *
[132]116                         * @param text The new text to associate with this element.
[110]117                         */
[69]118                        virtual void set_text( const string& text ) { m_text = text; m_dirty = true; }
[110]119
120                        /**
[132]121                         * Gets the class name associated with this element.
[110]122                         *
[132]123                         * @returns A string containing the class name of this element.
[110]124                         */
[69]125                        virtual const string& get_class() const { return m_class; }
[110]126
127                        /**
[132]128                         * sets the class name associated with this element.
[110]129                         *
[132]130                         * @param class_ The new class name.
[110]131                         */
[69]132                        virtual void set_class( const string& class_ ) { m_class = class_; m_dirty = true; }
[110]133
[257]134                protected:
[110]135                        /**
[132]136                         * Destroys the element.
[110]137                         */
[267]138                        virtual ~element() { delete m_render_data; }
[66]139                protected:
[99]140                        friend class environment;
[126]141                        friend class renderer;
[99]142
[110]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; ///<   -?-
[66]151                };
152
153        } // namespace gui
154
155} // namespace nv
156
157#endif // NV_GUI_ELEMENT_HH
Note: See TracBrowser for help on using the repository browser.