Merge branch 'master' of http://skoegl.net/uni/numpty
[numtypysics.git] / Ui.h
blob95656051db9d8f0c9c1ffaff9f11e66ed1edf364
1 /*
2 * This file is part of NumptyPhysics
3 * Copyright (C) 2008 Tim Edmonds
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
17 #ifndef UI_H
18 #define UI_H
20 #include "Common.h"
22 #include <string>
23 #include <SDL/SDL.h>
25 class Canvas;
26 class Window;
27 class Widget;
29 class WidgetParent
31 public:
32 virtual void add( Widget* w )=0;
33 virtual void remove( Widget* w )=0;
36 class Widget
38 public:
39 virtual ~Widget() {}
40 virtual bool isDirty() {return false;}
41 virtual Rect dirtyArea() {return Rect();};
42 virtual void onTick( int tick ) {}
43 virtual void draw( Canvas& screen, const Rect& area ) {};
44 virtual bool handleEvent( SDL_Event& ev ) {return false;};
45 virtual Window* getWindow() {return NULL;}
46 void setParent(WidgetParent* p) {m_parent = p;}
47 WidgetParent* parent() { return m_parent; }
48 protected:
49 WidgetParent* m_parent;
50 Rect m_pos;
53 class Label : public Widget
55 public:
56 Label();
57 void text( std::string& s );
58 void align( int a );
59 private:
63 class Button : public Widget
65 public:
66 Button();
69 class Container : public Widget, public WidgetParent
71 public:
72 Container();
74 virtual bool isDirty();
75 virtual Rect dirtyArea();
76 virtual void onTick( int tick );
77 virtual void draw( Canvas& screen, const Rect& area );
78 virtual bool handleEvent( SDL_Event& ev );
80 void add( Widget* w );
81 virtual void remove( Widget* w );
85 class Layer : public Widget
87 public:
88 virtual void onShow() {}
89 virtual void onHide() {}
93 #endif //UI_H