From f54bd48a884e4e3c95818f042a4b2418a6e070a4 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Tue, 7 Oct 2008 17:14:27 +0000 Subject: working button click --- src/ui/widget.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 8 deletions(-) (limited to 'src/ui/widget.h') diff --git a/src/ui/widget.h b/src/ui/widget.h index fcb8e6b..13f392e 100644 --- a/src/ui/widget.h +++ b/src/ui/widget.h @@ -7,6 +7,8 @@ #ifndef __INCLUDED_UI_WIDGET_H__ #define __INCLUDED_UI_WIDGET_H__ +#include "SDL/SDL.h" + #include #include @@ -21,6 +23,9 @@ namespace ui { class Widget { public: + /// type definition for child widgets + typedef std::list Children; + /// create a new widget Widget(Widget *parent=0); @@ -28,8 +33,6 @@ public: virtual ~Widget(); /* -- inspectors -------------------------------------------- */ - inline bool visible() const { return widget_visible; } - inline math::Vector2f &location() { return widget_location; } inline math::Vector2f &size() { return widget_size; } @@ -48,10 +51,14 @@ public: inline bool border() const { return widget_border; } - inline bool background() { return widget_background; } + inline bool background() const { return widget_background; } inline Widget *parent() { return widget_parent; } + inline bool visible() const { return widget_visible; } + + bool has_focus() const; + /* -- mutators --------------------------------------------- */ @@ -87,13 +94,18 @@ public: void set_background(bool background); /// resize event - virtual void resize_event(); + virtual void event_resize(); /// draw event - virtual void draw_event(); + virtual void event_draw(); - /// type definition for child widgets - typedef std::list Children; + /// handle mouse cursor + virtual void event_mousecursor(float x, float y); + + /// handle keyboard input + virtual void event_keypress(unsigned int key, unsigned int modifier); + + virtual void event_keyrelease(unsigned int key, unsigned int modifier); /// child widgets inline Children &children() { return widget_children; } @@ -117,8 +129,31 @@ protected: /// print widget description virtual void print(size_t indent); + /// map local coordinates to global coordinates + inline math::Vector2f to_global_coords(math::Vector2f const &local) + { + math::Vector2f v(local); + Widget *parent = widget_parent; + do { + v -= parent->location(); + parent = parent->widget_parent; + } while(parent); + return v; + } + + /// map global coordinates to local coordinates + inline math::Vector2f to_local_coords(math::Vector2f const &global) { + math::Vector2f v(global); + Widget *parent = this; + while (parent) { + v += parent->location(); + parent = parent->widget_parent; + } + return v; + } + /// map local widget location to global location - inline math::Vector2f global_location() { + inline math::Vector2f global_location() const { math::Vector2f v(widget_location); Widget *parent = widget_parent; while (parent) { @@ -131,7 +166,13 @@ protected: /// remove a child widget void remove_child(Widget *child); + /// find the child widget with focus + /** @param pos local position within the widget + */ + Widget *find_focus(math::Vector2f const & pos); + Palette *widget_palette; + private: bool widget_visible; bool widget_background; @@ -141,6 +182,7 @@ private: std::string widget_label; Children widget_children; + Widget *widget_parent; Children::iterator find_child(Widget *child); -- cgit v1.2.3