]> git.saurik.com Git - wxWidgets.git/blob - demos/life/life.h
Remove DoSetSizeHints() call from Create()
[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 // Copyright: (c) 2000, Guillermo Rodriguez Garcia
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _LIFE_APP_H_
12 #define _LIFE_APP_H_
13
14 #include "wx/minifram.h"
15
16 #include "game.h"
17
18
19 // --------------------------------------------------------------------------
20 // LifeCanvas
21 // --------------------------------------------------------------------------
22
23 // Note that in LifeCanvas, all cell coordinates are
24 // named i, j, while screen coordinates are named x, y.
25
26 class LifeCanvas : public wxWindow
27 {
28 public:
29 // ctor and dtor
30 LifeCanvas(wxWindow* parent, Life* life, bool interactive = true);
31 virtual ~LifeCanvas();
32
33 // view management
34 int GetCellSize() const { return m_cellsize; };
35 void SetCellSize(int cellsize);
36 void Recenter(wxInt32 i, wxInt32 j);
37
38 // drawing
39 void DrawChanged();
40 void DrawCell(wxInt32 i, wxInt32 j, bool alive);
41
42 private:
43 // any class wishing to process wxWidgets events must use this macro
44 DECLARE_EVENT_TABLE()
45
46 // draw a cell (parametrized by DC)
47 void DrawCell(wxInt32 i, wxInt32 j, wxDC &dc);
48
49 // event handlers
50 void OnPaint(wxPaintEvent& event);
51 void OnMouse(wxMouseEvent& event);
52 void OnSize(wxSizeEvent& event);
53 void OnScroll(wxScrollWinEvent& event);
54 void OnEraseBackground(wxEraseEvent& event);
55
56 // conversion between cell and screen coordinates
57 inline wxInt32 XToCell(wxCoord x) const { return (x / m_cellsize) + m_viewportX; };
58 inline wxInt32 YToCell(wxCoord y) const { return (y / m_cellsize) + m_viewportY; };
59 inline wxCoord CellToX(wxInt32 i) const { return (i - m_viewportX) * m_cellsize; };
60 inline wxCoord CellToY(wxInt32 j) const { return (j - m_viewportY) * m_cellsize; };
61
62 // what is the user doing?
63 enum MouseStatus
64 {
65 MOUSE_NOACTION,
66 MOUSE_DRAWING,
67 MOUSE_ERASING
68 };
69
70 Life *m_life; // Life object
71 int m_cellsize; // current cell size, in pixels
72 bool m_interactive; // is this canvas interactive?
73 MouseStatus m_status; // what is the user doing?
74 wxInt32 m_viewportX; // first visible cell (x coord)
75 wxInt32 m_viewportY; // first visible cell (y coord)
76 wxInt32 m_viewportW; // number of visible cells (w)
77 wxInt32 m_viewportH; // number of visible cells (h)
78 int m_thumbX; // horiz. scrollbar thumb position
79 int m_thumbY; // vert. scrollbar thumb position
80 wxInt32 m_mi, m_mj; // last mouse position
81 };
82
83
84 // --------------------------------------------------------------------------
85 // LifeNavigator
86 // --------------------------------------------------------------------------
87
88 class LifeNavigator : public wxMiniFrame
89 {
90 public:
91 // ctor
92 LifeNavigator(wxWindow *parent);
93
94 private:
95 // any class wishing to process wxWidgets events must use this macro
96 DECLARE_EVENT_TABLE()
97
98 // event handlers
99 void OnClose(wxCloseEvent& event);
100 };
101
102
103 // --------------------------------------------------------------------------
104 // LifeFrame
105 // --------------------------------------------------------------------------
106
107 class LifeFrame : public wxFrame
108 {
109 public:
110 // ctor and dtor
111 LifeFrame();
112 virtual ~LifeFrame();
113
114 // member functions
115 void UpdateInfoText();
116 void UpdateUI();
117
118 private:
119 // any class wishing to process wxWidgets events must use this macro
120 DECLARE_EVENT_TABLE()
121
122 // event handlers
123 void OnMenu(wxCommandEvent& event);
124 void OnOpen(wxCommandEvent& event);
125 void OnSamples(wxCommandEvent& event);
126 void OnNavigate(wxCommandEvent& event);
127 void OnZoom(wxCommandEvent& event);
128 void OnSlider(wxScrollEvent& event);
129 void OnTimer(wxTimerEvent& event);
130 void OnClose(wxCloseEvent& event);
131
132 // event handler helpers
133 void OnStart();
134 void OnStop();
135 void OnStep();
136
137 Life *m_life;
138 LifeCanvas *m_canvas;
139 LifeNavigator *m_navigator;
140 wxStaticText *m_text;
141 wxTimer *m_timer;
142 bool m_running;
143 bool m_topspeed;
144 long m_interval;
145 long m_tics;
146 };
147
148
149 // --------------------------------------------------------------------------
150 // LifeApp
151 // --------------------------------------------------------------------------
152
153 class LifeApp : public wxApp
154 {
155 public:
156 virtual bool OnInit();
157 };
158
159 #endif // _LIFE_APP_H_