From da9beb729c58ca2d91f67ab85a6728b628c27cf2 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sun, 5 Oct 2008 19:03:25 +0000 Subject: user interface library --- src/ui/widget.h | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 src/ui/widget.h (limited to 'src/ui/widget.h') diff --git a/src/ui/widget.h b/src/ui/widget.h new file mode 100644 index 0000000..97c6a01 --- /dev/null +++ b/src/ui/widget.h @@ -0,0 +1,147 @@ +/* + 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 "math/vector2f.h" +#include "ui/palette.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); + + /// map local widget coordinates to global coordinates + inline math::Vector2f to_global(math::Vector2f v) { + Widget *parent = widget_parent; + while (parent) { + v += parent->location(); + parent = parent->widget_parent; + } + return v; + } + +private: + + Palette *widget_palette; + 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); + + void remove_child(Widget *child); +}; + +} + +#endif // __INCLUDED_UI_WIDGET_H__ + -- cgit v1.2.3