Fix (lots of) memory leaks in Game.cpp
[numtypysics.git] / Ui.h
blobd1703bf48edcbdc48ef94b7a758fda88f1f8039e
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 Widget;
28 class WidgetParent
30 public:
31 virtual void add( Widget* w )=0;
32 virtual void remove( Widget* w )=0;
35 class Widget
37 public:
38 virtual ~Widget() {}
39 virtual bool isDirty() {return false;}
40 virtual Rect dirtyArea() {return Rect();};
41 virtual void onTick( int tick ) {}
42 virtual void draw( Canvas& screen, const Rect& area ) {};
43 virtual bool handleEvent( SDL_Event& ev ) {return false;}
44 void setParent(WidgetParent* p) {m_parent = p;}
45 WidgetParent* parent() { return m_parent; }
46 protected:
47 WidgetParent* m_parent;
48 Rect m_pos;
51 class Label : public Widget
53 public:
54 Label();
55 void text( std::string& s );
56 void align( int a );
57 private:
61 class Button : public Widget
63 public:
64 Button();
67 class Container : public Widget, public WidgetParent
69 public:
70 Container();
72 virtual bool isDirty();
73 virtual Rect dirtyArea();
74 virtual void onTick( int tick );
75 virtual void draw( Canvas& screen, const Rect& area );
76 virtual bool handleEvent( SDL_Event& ev );
78 void add( Widget* w );
79 virtual void remove( Widget* w );
83 class Layer : public Widget
85 public:
86 virtual void onShow() {}
87 virtual void onHide() {}
91 #endif //UI_H