]> git.saurik.com Git - wxWidgets.git/blob - demos/life/life.h
added wxUSE_NOTEBOOK to include/wx/msw/setup0.h, removed wxUSE_RADIOBUTTON (we
[wxWidgets.git] / demos / life / life.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: life.h
3 // Purpose: The game of life, created by J. H. Conway
4 // Author: Guillermo Rodriguez Garcia, <guille@iies.es>
5 // Modified by:
6 // Created: Jan/2000
7 // RCS-ID: $Id$
8 // Copyright: (c) 2000, Guillermo Rodriguez Garcia
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _LIFE_APP_H_
13 #define _LIFE_APP_H_
14
15 #ifdef __GNUG__
16 #pragma interface "life.h"
17 #endif
18
19 // for compilers that support precompilation, includes "wx/wx.h"
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 // for all others, include the necessary headers
27 #ifndef WX_PRECOMP
28 #include "wx/wx.h"
29 #endif
30
31 #include "game.h"
32
33 // --------------------------------------------------------------------------
34 // LifeCanvas
35 // --------------------------------------------------------------------------
36
37 class LifeCanvas : public wxScrolledWindow
38 {
39 public:
40 // ctor and dtor
41 LifeCanvas(wxWindow* parent, Life* life, bool interactive = TRUE);
42 ~LifeCanvas();
43
44 // member functions
45 void Reset();
46 void DrawEverything(bool force = FALSE);
47 void DrawCell(Cell c);
48 void DrawCell(Cell c, wxDC &dc);
49 inline int CellToCoord(int i) const { return (i * m_cellsize); };
50 inline int CoordToCell(int x) const { return ((x >= 0)? (x / m_cellsize) : -1); };
51
52 // event handlers
53 void OnPaint(wxPaintEvent& event);
54 void OnMouse(wxMouseEvent& event);
55 void OnSize(wxSizeEvent& event);
56
57 private:
58 // any class wishing to process wxWindows events must use this macro
59 DECLARE_EVENT_TABLE()
60
61 enum MouseStatus
62 {
63 MOUSE_NOACTION,
64 MOUSE_DRAWING,
65 MOUSE_ERASING
66 };
67
68 Life *m_life;
69 wxBitmap *m_bmp;
70 int m_height;
71 int m_width;
72 int m_cellsize;
73 wxCoord m_xoffset;
74 wxCoord m_yoffset;
75 MouseStatus m_status;
76 bool m_interactive;
77 };
78
79 // --------------------------------------------------------------------------
80 // LifeTimer
81 // --------------------------------------------------------------------------
82
83 // Life timer
84 class LifeTimer : public wxTimer
85 {
86 public:
87 void Notify();
88 };
89
90 // --------------------------------------------------------------------------
91 // LifeFrame
92 // --------------------------------------------------------------------------
93
94 class LifeFrame : public wxFrame
95 {
96 public:
97 // ctor and dtor
98 LifeFrame();
99 ~LifeFrame();
100
101 // member functions
102 void UpdateInfoText();
103
104 // event handlers
105 void OnMenu(wxCommandEvent& event);
106 void OnNewGame(wxCommandEvent& event);
107 void OnSamples(wxCommandEvent& event);
108 void OnStart();
109 void OnStop();
110 void OnTimer();
111 void OnSlider(wxScrollEvent& event);
112
113 private:
114 // any class wishing to process wxWindows events must use this macro
115 DECLARE_EVENT_TABLE()
116
117 Life *m_life;
118 LifeTimer *m_timer;
119 LifeCanvas *m_canvas;
120 wxStaticText *m_text;
121 bool m_running;
122 long m_interval;
123 long m_tics;
124 };
125
126 // --------------------------------------------------------------------------
127 // LifeApp
128 // --------------------------------------------------------------------------
129
130 class LifeApp : public wxApp
131 {
132 public:
133 virtual bool OnInit();
134 };
135
136 #endif // _LIFE_APP_H_