/* ui/widget.h This file is part of the Osirion project and is distributed under the terms of the GNU General Public License version 2 */ #ifndef __INCLUDED_UI_WIDGET_H__ #define __INCLUDED_UI_WIDGET_H__ #include #include #include "auxiliary/functions.h" #include "math/color.h" #include "math/vector2f.h" #include "ui/palette.h" #include "sys/sys.h" namespace ui { class Widget { public: /// create a new widget Widget(Widget *parent=0); /// destroy a widget virtual ~Widget(); /* -- inspectors -------------------------------------------- */ inline bool visible() const { return widget_visible; } inline math::Vector2f &location() { return widget_location; } inline math::Vector2f &size() { return widget_size; } inline float const left() const { return widget_location.x; } inline float const top() const { return widget_location.y; } inline float const width() const { return widget_size.x; } inline float const height() const { return widget_size.y; } inline Palette const *palette() const { return widget_palette; } inline std::string const &label() const { return widget_label; } inline bool border() const { return widget_border; } inline bool background() { return widget_background; } inline Widget *parent() { return widget_parent; } /* -- mutators --------------------------------------------- */ /// show the widget void show(); /// hide the widget void hide(); /// set location of the top-left corner void set_location(float const x, float const y); /// set the widgets width and height void set_size(float const w, float const h); /// set the widgets width void set_width(float const w); /// set the widgets height void set_height(float const h); /// set the widgets palette void set_palette(Palette *palette); /// set the widgets label void set_label(std::string const &label); /// set the widgets label void set_label(char const *label); void set_border(bool border); void set_background(bool background); /// resize event virtual void resize_event(); /// draw event virtual void draw_event(); /// type definition for child widgets typedef std::list Children; /// child widgets inline Children &children() { return widget_children; } protected: /// draw the widget virtual void draw(); /// resize the widget virtual void resize(); /// draw the widget background virtual void draw_background(); /// draw the widget border virtual void draw_border(); /// list widget content size_t list(size_t indent); /// print widget description virtual void print(size_t indent); /// map local widget location to global location inline math::Vector2f global_location() { math::Vector2f v(widget_location); Widget *parent = widget_parent; while (parent) { v += parent->location(); parent = parent->widget_parent; } return v; } /// remove a child widget void remove_child(Widget *child); Palette *widget_palette; private: bool widget_visible; bool widget_background; bool widget_border; math::Vector2f widget_location; math::Vector2f widget_size; std::string widget_label; Children widget_children; Widget *widget_parent; Children::iterator find_child(Widget *child); void add_child(Widget *child); }; } #endif // __INCLUDED_UI_WIDGET_H__