// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz // http://chaosforge.org/ // // This file is part of NV Libraries. // For conditions of distribution and use, see copyright notice in nv.hh /** * @file gui_element.hh * @author Kornel Kisielewicz * @brief GUI Element */ #ifndef NV_GUI_ELEMENT_HH #define NV_GUI_ELEMENT_HH #include #include #include #include namespace nv { namespace gui { class element : public object { protected: /** * Creates a new GUI element with the give root node and positioning data. * * @param r The rectangle representing the position and size of this element. */ explicit element( const rectangle& r ) : object( "" ), m_class(""), m_relative( r ), m_absolute( r ), m_enabled( true ), m_visible( true ), m_dirty( true ), m_render_data( nullptr ) {} public: /** * Checks if this element contains the given point. * * @param p The point to check. * @returns True if the point is within the region of the element, false otherwise. */ virtual bool contains( const position& p ) const { return m_absolute.contains( p ); } /** * Gets the position and size of the element relative to its parent. * * @returns The element's position and size relative to its parent. */ virtual const rectangle& get_relative() const { return m_relative; } /** * Gets the position and size of the element relative to the root (window). * * @returns The element's position and size relative to the root (window). */ virtual const rectangle& get_absolute() const { return m_absolute; } /** * Gets whether this element is currently accepting events. * * @returns True if the element is receiving events, false otherwise. */ virtual bool is_enabled() const { return m_enabled; } /** * Gets whether this element is currently visible. * * @returns True if the element is visible, false otherwise. */ virtual bool is_visible() const { return m_visible; } /** * Gets whether this element needs to be redrawn. * * @returns True if the element needs to be redrawn, false if not. */ virtual bool is_dirty() const { return m_dirty; } /** * Sets whether this element is currently accepting events. * * @param value True to allow the element and its children to receive events, false to disable. */ virtual void set_enabled( bool value ) { m_enabled = value; } /** * Sets whether this element is visible on the screen. * * @param value True to display the element and its children, false to hide it and its children. */ virtual void set_visible( bool value ) { m_visible = value; } /** * Sets whether this element needs to be redrawn. * * @param value True to request that the element and its children be redrawn, false if not. */ virtual void set_dirty( bool value ) { m_dirty = value; } /** * Gets the text associated with this element. * * @returns A string containing the associated text. */ virtual const string& get_text() const { return m_text; } /** * Sets the text associated with this element. * * @param text The new text to associate with this element. */ virtual void set_text( const string& text ) { m_text = text; m_dirty = true; } /** * Gets the class name associated with this element. * * @returns A string containing the class name of this element. */ virtual const string& get_class() const { return m_class; } /** * sets the class name associated with this element. * * @param class_ The new class name. */ virtual void set_class( const string& class_ ) { m_class = class_; m_dirty = true; } protected: /** * Destroys the element. */ virtual ~element() { delete m_render_data; } protected: friend class environment; friend class renderer; string m_class; ///< Class name. string m_text; ///< Displayed label or text. rectangle m_relative; ///< Position relative to parent. rectangle m_absolute; ///< Position relative to window/screen. bool m_enabled; ///< Whether the element accepts events. bool m_visible; ///< Whether the element is drawn. bool m_dirty; ///< Whether the element needs updating. render_data* m_render_data; ///< -?- }; } // namespace gui } // namespace nv #endif // NV_GUI_ELEMENT_HH