diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/widgets.h | 534 |
1 files changed, 271 insertions, 263 deletions
diff --git a/include/widgets.h b/include/widgets.h index 7a919f4..600bcec 100644 --- a/include/widgets.h +++ b/include/widgets.h @@ -1,263 +1,271 @@ -/* - * mogltk - * Copyright (C) 1999-2004 Nicolas "Pixel" Noble - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* $Id: widgets.h,v 1.6 2004-07-17 10:08:16 pixel Exp $ */ - -#ifndef __WIDGETS_H__ -#define __WIDGETS_H__ - -#include <Exceptions.h> -#include <shape.h> -#include <base.h> - -namespace mogltk { - enum event_t { - E_TIMER, - E_MOUSE_START_DRAG, - E_MOUSE_DRAG, - E_MOUSE_DRAG_OVER, - E_MOUSE_END_DRAG, - E_MOUSE_END_DRAG_OVER, - E_MOUSE_MOVE, - E_MOUSE_OUT, - E_MOUSE_DOWN, - E_MOUSE_UP, - E_MOUSE_CLICK, - E_MOUSE_OUT_CLICK, - E_MOUSE_DBL_CLICK, - }; - class widget : public Base { - public: - virtual ~widget(); - virtual void move(int x, int y); - virtual void resize(int sx, int sy); - int GetX(); - int GetY(); - int GetH(); - int GetW(); - int GetAX(); - int GetAY(); - int GetAX2(); - int GetAY2(); - virtual mogltk::rect GetDrawRect(); - widget * Father(); - widget * Child(); - widget * Next(); - widget * Prev(); - void fulldraw(); - shape * Shaper(); - void mainloop(); - void m_event(int x, int y, event_t event); - bool inside(int x, int y); - bool GetVisible(); - virtual void SetVisible(bool); - bool GetEnabled(); - virtual void SetEnabled(bool); - void MoveOnTop(); - static void check_timed_events(); - protected: - widget(widget * father, int x, int y, int sx, int sy, int type, String name, shape *); - virtual void draw(); - virtual bool process_event(int x, int y, event_t event); - virtual void resize_notify(); - void set_exclusive(widget *); - void unset_exclusive(widget *); - void add_out_move(); - void remove_out_move(); - void add_out_click(); - void remove_out_click(); - void set_timed_event(Uint32); - void set_absolute_timed_event(Uint32); - String caption; - private: - int x, y, sx, sy, ax, ay, ax2, ay2; - widget * father, * next, * prev, * child, * last, * root; - static widget * focused; - int type; - String name; - shape * sh; - widget * exclusive; - bool visible; - bool enabled; - class timed_event { - public: - timed_event(widget * _w, Uint32 _t) : w(_w), t(_t) { } - widget * w; - Uint32 t; - }; - static std::vector<timed_event> timed_events; - - void computeabs(); - void idraw(); - bool ievent(int x, int y, event_t event); - void icomputeabs(); - void iresize_notify(); - }; - - namespace widgets { - class drawer : public Base { - public: - virtual void draw(widget *) = 0; - }; - - class action : public Base { - public: - virtual void do_action(widget *) = 0; - }; - - class Root : public widget { - public: - Root(shape *, drawer * = 0); - void setdrawer(drawer *); - protected: - virtual void draw(); - drawer * dr; - }; - - class Button : public widget { - public: - Button(action *, shape *, widget * father, int x, int y, int w, int h, const String & caption); - protected: - virtual void draw(); - virtual bool process_event(int, int, event_t); - bool bevel; - private: - bool dragging; - action * a; - }; - - class Label : public widget { - public: - Label(shape *, widget * father, int x, int y, int w, int h, const String & caption, const ColorP & color = BLACK); - protected: - virtual void draw(); - private: - ColorP color; - }; - - class SmartBox : public widget { - public: - SmartBox(shape *, widget * father, int x, int y, int w, int h, const String & caption); - virtual rect GetDrawRect(); - protected: - virtual void draw(); - virtual bool process_event(int, int, event_t); - private: - int ox, oy, oax, oay; - }; - - class MsgBox : public SmartBox { - public: - MsgBox(shape *, widget * father, const String & caption, const String & text); - virtual ~MsgBox(); - }; - - class Frame : public widget { - public: - Frame(shape *, widget * father, int x, int y, int w, int h); - virtual rect GetDrawRect(); - protected: - virtual void draw(); - }; - - class ContextMenu : public widget { - public: - ContextMenu(shape *, widget * father, int x, int y); - virtual ~ContextMenu(); - void addnode(const String &, action *); - void addline(); - void addsub(const String &, ContextMenu *); - ContextMenu * createsub(const String &); - virtual void move(int x, int y); - virtual void resize(int w, int h); - virtual void SetVisible(bool); - virtual void SetEnabled(int i, bool); - void StickyDisplay(); - protected: - virtual void draw(); - virtual bool process_event(int x, int y, event_t event); - class node : public Base { - public: - node(const String &, int x, int y, int w, int h, action * = 0, ContextMenu * sub = 0, ContextMenu * father = 0, bool = false); - String GetCaption(); - action * GetAction(); - ContextMenu * GetSub(); - ContextMenu * GetFather(); - bool GetLine(); - bool GetEnabled(); - void SetEnabled(bool); - int GetX(); - int GetY(); - int GetW(); - int GetH(); - private: - String caption; - int x, y, w, h; - action * a; - ContextMenu * sub, * father; - bool line, enabled; - }; - - std::vector<node> nodes; - int selected; - ContextMenu * subselected; - private: - bool in_click, sticky; - - bool iin_click(); - }; - - class Menu : public widget { - public: - Menu(shape *, widget * father); - void addnode(const String &, action *); - void addsub(const String &, ContextMenu * sub); - ContextMenu * createsub(const String &); - virtual void SetEnabled(int i, bool); - void SetCaption(int i, const String &); - protected: - virtual void resize_notify(); - virtual void draw(); - virtual bool process_event(int, int, event_t); - class node : public Base { - public: - node(const String & caption, ContextMenu * sub, action * a, int x); - String GetCaption(); - void SetCaption(const String &); - ContextMenu * GetSub(); - action * GetAction(); - int GetX(); - bool GetEnabled(); - void SetEnabled(bool); - private: - String caption; - ContextMenu * sub; - action * a; - int x; - bool enabled; - }; - private: - std::vector<node> nodes; - int cur_x; - int selected; - }; - }; -}; - -#endif +/*
+ * mogltk
+ * Copyright (C) 1999-2004 Nicolas "Pixel" Noble
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/* $Id: widgets.h,v 1.7 2004-10-19 01:27:29 pixel Exp $ */
+
+#ifndef __WIDGETS_H__
+#define __WIDGETS_H__
+
+#include <Exceptions.h>
+#include <shape.h>
+#include <base.h>
+
+namespace mogltk {
+ enum event_t {
+ E_TIMER,
+ E_MOUSE_START_DRAG,
+ E_MOUSE_DRAG,
+ E_MOUSE_DRAG_OVER,
+ E_MOUSE_END_DRAG,
+ E_MOUSE_END_DRAG_OVER,
+ E_MOUSE_MOVE,
+ E_MOUSE_OUT,
+ E_MOUSE_DOWN,
+ E_MOUSE_UP,
+ E_MOUSE_CLICK,
+ E_MOUSE_OUT_CLICK,
+ E_MOUSE_DBL_CLICK,
+ };
+ class widget : public Base {
+ public:
+ virtual ~widget();
+ virtual void move(int x, int y);
+ virtual void resize(int sx, int sy);
+ int GetX();
+ int GetY();
+ int GetH();
+ int GetW();
+ int GetAX();
+ int GetAY();
+ int GetAX2();
+ int GetAY2();
+ virtual mogltk::rect GetDrawRect();
+ widget * Father();
+ widget * Child();
+ widget * Next();
+ widget * Prev();
+ widget * InnerPanel();
+ virtual widget * find_widget(int x, int y);
+ void fulldraw();
+ shape * Shaper();
+ void mainloop();
+ void m_event(int x, int y, event_t event);
+ bool inside(int x, int y);
+ bool GetVisible();
+ virtual void SetVisible(bool);
+ bool GetEnabled();
+ virtual void SetEnabled(bool);
+ void MoveOnTop();
+ static void check_timed_events();
+ protected:
+ widget(widget * father, int x, int y, int sx, int sy, int type, String name, shape *);
+ virtual void draw();
+ virtual bool process_event(int x, int y, event_t event);
+ virtual void resize_notify();
+ virtual widget * create_panel();
+ void set_exclusive(widget *);
+ void unset_exclusive(widget *);
+ void add_out_move();
+ void remove_out_move();
+ void add_out_click();
+ void remove_out_click();
+ void set_timed_event(Uint32);
+ void set_absolute_timed_event(Uint32);
+ String caption;
+ private:
+ int x, y, sx, sy, ax, ay, ax2, ay2;
+ widget * father, * next, * prev, * child, * last, * root, * panel;
+ static widget * focused;
+ int type;
+ String name;
+ shape * sh;
+ widget * exclusive;
+ bool visible;
+ bool enabled;
+ class timed_event {
+ public:
+ timed_event(widget * _w, Uint32 _t) : w(_w), t(_t) { }
+ widget * w;
+ Uint32 t;
+ };
+ static std::vector<timed_event> timed_events;
+
+ void computeabs();
+ void idraw();
+ bool ievent(int x, int y, event_t event);
+ void icomputeabs();
+ void iresize_notify();
+ };
+
+ namespace widgets {
+ class drawer : public Base {
+ public:
+ virtual void draw(widget *) = 0;
+ };
+
+ class action : public Base {
+ public:
+ virtual void do_action(widget *) = 0;
+ };
+
+ class Root : public widget {
+ public:
+ Root(shape *, drawer * = 0);
+ void setdrawer(drawer *);
+ protected:
+ virtual void draw();
+ drawer * dr;
+ };
+
+ class Panel : public widget {
+ public:
+ Panel(shape *, widget * father, int x, int y, int w, int h);
+ };
+
+ class Button : public widget {
+ public:
+ Button(action *, shape *, widget * father, int x, int y, int w, int h, const String & caption);
+ protected:
+ virtual void draw();
+ virtual bool process_event(int, int, event_t);
+ bool bevel;
+ private:
+ bool dragging;
+ action * a;
+ };
+
+ class Label : public widget {
+ public:
+ Label(shape *, widget * father, int x, int y, int w, int h, const String & caption, const ColorP & color = BLACK);
+ protected:
+ virtual void draw();
+ private:
+ ColorP color;
+ };
+
+ class SmartBox : public widget {
+ public:
+ SmartBox(shape *, widget * father, int x, int y, int w, int h, const String & caption);
+ virtual rect GetDrawRect();
+ protected:
+ virtual void draw();
+ virtual bool process_event(int, int, event_t);
+ private:
+ int ox, oy, oax, oay;
+ };
+
+ class MsgBox : public SmartBox {
+ public:
+ MsgBox(shape *, widget * father, const String & caption, const String & text);
+ virtual ~MsgBox();
+ };
+
+ class Frame : public widget {
+ public:
+ Frame(shape *, widget * father, int x, int y, int w, int h);
+ virtual rect GetDrawRect();
+ protected:
+ virtual void draw();
+ };
+
+ class ContextMenu : public widget {
+ public:
+ ContextMenu(shape *, widget * father, int x, int y);
+ virtual ~ContextMenu();
+ void addnode(const String &, action *);
+ void addline();
+ void addsub(const String &, ContextMenu *);
+ ContextMenu * createsub(const String &);
+ virtual void move(int x, int y);
+ virtual void resize(int w, int h);
+ virtual void SetVisible(bool);
+ virtual void SetEnabled(int i, bool);
+ void StickyDisplay();
+ protected:
+ virtual void draw();
+ virtual bool process_event(int x, int y, event_t event);
+ class node : public Base {
+ public:
+ node(const String &, int x, int y, int w, int h, action * = 0, ContextMenu * sub = 0, ContextMenu * father = 0, bool = false);
+ String GetCaption();
+ action * GetAction();
+ ContextMenu * GetSub();
+ ContextMenu * GetFather();
+ bool GetLine();
+ bool GetEnabled();
+ void SetEnabled(bool);
+ int GetX();
+ int GetY();
+ int GetW();
+ int GetH();
+ private:
+ String caption;
+ int x, y, w, h;
+ action * a;
+ ContextMenu * sub, * father;
+ bool line, enabled;
+ };
+
+ std::vector<node> nodes;
+ int selected;
+ ContextMenu * subselected;
+ private:
+ bool in_click, sticky;
+
+ bool iin_click();
+ };
+
+ class Menu : public widget {
+ public:
+ Menu(shape *, widget * father);
+ void addnode(const String &, action *);
+ void addsub(const String &, ContextMenu * sub);
+ ContextMenu * createsub(const String &);
+ virtual void SetEnabled(int i, bool);
+ void SetCaption(int i, const String &);
+ protected:
+ virtual void resize_notify();
+ virtual void draw();
+ virtual bool process_event(int, int, event_t);
+ class node : public Base {
+ public:
+ node(const String & caption, ContextMenu * sub, action * a, int x);
+ String GetCaption();
+ void SetCaption(const String &);
+ ContextMenu * GetSub();
+ action * GetAction();
+ int GetX();
+ bool GetEnabled();
+ void SetEnabled(bool);
+ private:
+ String caption;
+ ContextMenu * sub;
+ action * a;
+ int x;
+ bool enabled;
+ };
+ private:
+ std::vector<node> nodes;
+ int cur_x;
+ int selected;
+ };
+ };
+};
+
+#endif
|