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-07 17:14:27 +0000
committerStijn Buys <ingar@osirion.org>2008-10-07 17:14:27 +0000
commitf54bd48a884e4e3c95818f042a4b2418a6e070a4 (patch)
tree73e82729a2f97b58e94ffd6944ac1ad47bf8314e /src/ui/widget.h
parentf8d1ee921c83b7b148883b3ee16e4ec9c776d6db (diff)
working button click
Diffstat (limited to 'src/ui/widget.h')
-rw-r--r--src/ui/widget.h58
1 files changed, 50 insertions, 8 deletions
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 <string>
#include <list>
@@ -21,6 +23,9 @@ namespace ui {
class Widget {
public:
+ /// type definition for child widgets
+ typedef std::list<Widget *> 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<Widget *> 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);