Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-10-12 14:55:10 +0000
committerStijn Buys <ingar@osirion.org>2008-10-12 14:55:10 +0000
commitb417df720584c101f3799874a0c836a543a8d0a8 (patch)
treefb7105ed662f13753a6ab8d3efb047bad04f2316 /src/ui/widget.h
parent18383a5fc596bf9546f14d7393ee66c57720b116 (diff)
user interface updates, work-in-progress
Diffstat (limited to 'src/ui/widget.h')
-rw-r--r--src/ui/widget.h330
1 files changed, 207 insertions, 123 deletions
diff --git a/src/ui/widget.h b/src/ui/widget.h
index 2078134..e069220 100644
--- a/src/ui/widget.h
+++ b/src/ui/widget.h
@@ -20,199 +20,283 @@
#include "ui/definitions.h"
#include "sys/sys.h"
-namespace ui {
+namespace ui
+{
-class Widget {
+class Widget
+{
public:
/// type definition for child widgets
typedef std::list<Widget *> Children;
-
+
/// create a new widget
Widget(Widget *parent=0);
-
+
/// destroy a widget
virtual ~Widget();
-
+
+ /// parent widget this widget belongs to
+ inline Widget *parent() const {
+ return widget_parent;
+ }
+
/* -- inspectors -------------------------------------------- */
- 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 std::string const &label() const { return widget_label; }
-
- inline bool border() const { return widget_border; }
-
- inline bool background() const { return widget_background; }
-
- inline Widget *parent() const { return widget_parent; }
-
- inline bool visible() const { return widget_visible; }
-
- Palette const *palette() const;
-
- Font const *font() const;
-
- bool has_focus() const;
-
-
+ /// pixel coordinates of the top-left corner of this widget within its parent
+ inline const math::Vector2f &location() const {
+ return widget_location;
+ }
+
+ /// size of this widget in pixels
+ inline const math::Vector2f &size() const {
+ return widget_size;
+ }
+
+ /// left coordinate of location()
+ /**
+ * @see location
+ */
+ inline float left() const {
+ return widget_location.x;
+ }
+
+ /// top coordinate of location()
+ /**
+ * @see location
+ */
+ inline float top() const {
+ return widget_location.y;
+ }
+
+ /// width of the widget in pixels
+ /**
+ * @see size()
+ */
+ inline float width() const {
+ return widget_size.x;
+ }
+
+ /// height of the widget in pixels
+ /**
+ * @see size()
+ */
+ inline float height() const {
+ return widget_size.y;
+ }
+
+ /// widget label
+ inline const std::string &label() const {
+ return widget_label;
+ }
+
+ /// true if this widget will draw a background
+ inline bool background() const {
+ return widget_background;
+ }
+
+ /// true if this widget will draw a border
+ inline bool border() const {
+ return widget_border;
+ }
+
+ /// true if this widget is visible
+ inline bool visible() const {
+ return widget_visible;
+ }
+
+ /// true if this widget is not visible
+ inline bool hidden() const {
+ return !widget_visible;
+ }
+
+ /// the palette used to draw this widget
+ const Palette *palette() const;
+
+ /// the font used to draw this widget
+ const Font *font() const;
+
+ /// return true if the widget has input focus
+ bool has_input_focus() const;
+
+ /// returns true if the widget has mouse focus
+ bool has_mouse_focus() const;
+
/* -- mutators --------------------------------------------- */
-
+
/// raise the widget to the top of the widget stack
void raise();
-
+
/// lower the widget to the bottom of the widget stack
void lower();
-
+
/// show the widget
- void show();
-
+ virtual void show();
+
/// hide the widget
- void hide();
-
+ virtual void hide();
+
/// set visibility
void set_visible(bool visible = true);
-
- /// set location of the top-left corner
+
+ /// set input focus
+ void set_focus();
+
+ /// set location of the top-left corner, relative to the parent
void set_location(float const x, float const y);
-
+
+ /// set location of the top-left corner, relative to the parent
+ void set_location(const math::Vector2f &location);
+
/// set the widgets width and height
void set_size(float const w, float const h);
-
+
/// set the widgets width and height
void set_size(math::Vector2f const &size);
-
+
/// 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);
-
+ void set_palette(const Palette *palette);
+
/// set the widgets font
- void set_font(Font *font);
-
+ void set_font(const Font *font);
+
/// 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
+ void set_label(const char *label);
+
+ /// enable or disable widget border
+ void set_border(bool border = true);
+
+ ///enable or disable widget background
+ void set_background(bool background = true);
+
+ /// child widgets
+ inline Children &children() {
+ return widget_children;
+ }
+
+
+ /* -- event distributors ----------------------------------- */
+
+ /// distribute resize event
virtual void event_resize();
-
- /// draw event
+
+ /// distribute draw event
virtual void event_draw();
-
- /// keyboard event
- virtual bool event_key(bool pressed, unsigned int key, unsigned int modifier);
-
- /// find the child widget with focus
- /** @param pos local position within the widget
- */
- Widget *event_focus(math::Vector2f const & pos);
-
- /// child widgets
- inline Children &children() { return widget_children; }
-
+
+ /// distribute keyboard events
+ virtual bool event_key(const bool pressed, const int key, const unsigned int modifier);
+
+ /// distribute mouse movement events
+ virtual bool event_mouse(const math::Vector2f &cursor);
+
protected:
- /// handle keyboard events
- /** returns true if the event was handled by this widget
- */
- virtual bool keypress(unsigned int key, unsigned int modifier);
-
- /// handle keyboard events
- /** returns true if the event was handled by this widget
- */
- virtual bool keyrelease(unsigned int key, unsigned int modifier);
-
- /// 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();
-
+ /// find the widget that has input focus
+ virtual Widget *find_input_focus();
+
+ /// find widget that has mosue focus
+ /** @param cursor mouse cursor position relative to this widget's location
+ */
+ Widget *find_mouse_focus(const math::Vector2f & cursor);
+
/// list widget content
- size_t list(size_t indent);
-
+ size_t list(const size_t indent) const;
+
/// print widget description
- virtual void print(size_t indent);
-
+ virtual void print(const size_t indent) const;
+
+ /* -- coordinate mapping ----------------------------------- */
+
/// map local coordinates to global coordinates
- inline math::Vector2f to_global_coords(math::Vector2f const &local)
- {
+ inline math::Vector2f to_global_coords(const math::Vector2f &local) {
math::Vector2f v(local);
Widget *parent = widget_parent;
do {
v -= parent->location();
- parent = parent->widget_parent;
- } while(parent);
+ parent = parent->parent();
+ } while (parent);
return v;
}
-
+
/// map global coordinates to local coordinates
- inline math::Vector2f to_local_coords(math::Vector2f const &global) {
+ inline math::Vector2f to_local_coords(const math::Vector2f &global) {
math::Vector2f v(global);
Widget *parent = this;
while (parent) {
v += parent->location();
- parent = parent->widget_parent;
+ parent = parent->parent();
}
return v;
}
-
+
/// map local widget location to global location
- inline math::Vector2f global_location() const {
+ inline math::Vector2f global_location() {
math::Vector2f v(widget_location);
Widget *parent = widget_parent;
while (parent) {
v += parent->location();
- parent = parent->widget_parent;
+ parent = parent->parent();
}
return v;
}
-
- /// remove a child widget
+
+ /* -- event handlers --------------------------------------- */
+
+ /// called when the mouse receives mouse movement
+ virtual void on_mousemove(const math::Vector2f &cursor);
+
+ /// called when the mouse enters the widget
+ virtual void on_mouseover(const math::Vector2f &cursor);
+
+ /// called when the widget receives a key press
+ virtual bool on_keypress(const int key, const unsigned int modifier);
+
+ /// called when the widget receives a key release
+ virtual bool on_keyrelease(const int key, const unsigned int modifier);
+
+ /* -- draw functions --------------------------------------- */
+
+ /// resize event
+ virtual void resize();
+
+ /// draw the widget
+ virtual void draw();
+
+ /// draw the widget background
+ virtual void draw_background();
+
+ /// draw the widget border
+ virtual void draw_border();
+
+ void add_child(Widget *child);
void remove_child(Widget *child);
-
+
private:
- bool widget_visible;
- bool widget_background;
- bool widget_border;
- math::Vector2f widget_location;
- math::Vector2f widget_size;
- std::string widget_label;
+ bool widget_visible;
+ bool widget_background;
+ bool widget_border;
+ bool widget_focus;
+
+ math::Vector2f widget_location;
+ math::Vector2f widget_size;
+ std::string widget_label;
Children widget_children;
-
- Palette *widget_palette;
- Font *widget_font;
+
+ const Palette *widget_palette;
+ const Font *widget_font;
Widget *widget_parent;
Children::iterator find_child(Widget *child);
-
- void add_child(Widget *child);
+
};
}