]> git.saurik.com Git - wxWidgets.git/blame - demos/life/life.h
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / demos / life / life.h
CommitLineData
2480be69
GRG
1/////////////////////////////////////////////////////////////////////////////
2// Name: life.h
29b07a38 3// Purpose: The game of Life, created by J. H. Conway
2480be69
GRG
4// Author: Guillermo Rodriguez Garcia, <guille@iies.es>
5// Modified by:
6// Created: Jan/2000
2480be69
GRG
7// Copyright: (c) 2000, Guillermo Rodriguez Garcia
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef _LIFE_APP_H_
12#define _LIFE_APP_H_
13
29b07a38
GRG
14#include "wx/minifram.h"
15
2480be69
GRG
16#include "game.h"
17
29b07a38 18
2480be69
GRG
19// --------------------------------------------------------------------------
20// LifeCanvas
21// --------------------------------------------------------------------------
22
29b07a38
GRG
23// Note that in LifeCanvas, all cell coordinates are
24// named i, j, while screen coordinates are named x, y.
25
e0a40292 26class LifeCanvas : public wxWindow
2480be69
GRG
27{
28public:
29 // ctor and dtor
2a21ac15 30 LifeCanvas(wxWindow* parent, Life* life, bool interactive = true);
d3c7fc99 31 virtual ~LifeCanvas();
2480be69 32
e0a40292
GRG
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
42private:
be5a51fb 43 // any class wishing to process wxWidgets events must use this macro
e0a40292
GRG
44 DECLARE_EVENT_TABLE()
45
46 // draw a cell (parametrized by DC)
47 void DrawCell(wxInt32 i, wxInt32 j, wxDC &dc);
2480be69
GRG
48
49 // event handlers
50 void OnPaint(wxPaintEvent& event);
51 void OnMouse(wxMouseEvent& event);
52 void OnSize(wxSizeEvent& event);
e0a40292
GRG
53 void OnScroll(wxScrollWinEvent& event);
54 void OnEraseBackground(wxEraseEvent& event);
2480be69 55
e0a40292
GRG
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; };
2480be69 61
e0a40292 62 // what is the user doing?
2480be69
GRG
63 enum MouseStatus
64 {
65 MOUSE_NOACTION,
66 MOUSE_DRAWING,
67 MOUSE_ERASING
68 };
69
e0a40292
GRG
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)
5d2ac6b8
WS
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
2480be69
GRG
81};
82
29b07a38 83
2480be69 84// --------------------------------------------------------------------------
29b07a38 85// LifeNavigator
2480be69
GRG
86// --------------------------------------------------------------------------
87
29b07a38 88class LifeNavigator : public wxMiniFrame
2480be69
GRG
89{
90public:
29b07a38
GRG
91 // ctor
92 LifeNavigator(wxWindow *parent);
93
94private:
be5a51fb 95 // any class wishing to process wxWidgets events must use this macro
29b07a38
GRG
96 DECLARE_EVENT_TABLE()
97
98 // event handlers
99 void OnClose(wxCloseEvent& event);
2480be69
GRG
100};
101
29b07a38 102
2480be69
GRG
103// --------------------------------------------------------------------------
104// LifeFrame
105// --------------------------------------------------------------------------
106
107class LifeFrame : public wxFrame
108{
109public:
110 // ctor and dtor
111 LifeFrame();
d3c7fc99 112 virtual ~LifeFrame();
2480be69
GRG
113
114 // member functions
115 void UpdateInfoText();
e0a40292 116 void UpdateUI();
e0a40292
GRG
117
118private:
be5a51fb 119 // any class wishing to process wxWidgets events must use this macro
e0a40292 120 DECLARE_EVENT_TABLE()
2480be69
GRG
121
122 // event handlers
29b07a38 123 void OnMenu(wxCommandEvent& event);
f6bcfd97
BP
124 void OnOpen(wxCommandEvent& event);
125 void OnSamples(wxCommandEvent& event);
29b07a38
GRG
126 void OnNavigate(wxCommandEvent& event);
127 void OnZoom(wxCommandEvent& event);
e0a40292 128 void OnSlider(wxScrollEvent& event);
29b07a38 129 void OnTimer(wxTimerEvent& event);
e0a40292 130 void OnClose(wxCloseEvent& event);
29b07a38
GRG
131
132 // event handler helpers
2480be69
GRG
133 void OnStart();
134 void OnStop();
29b07a38
GRG
135 void OnStep();
136
5d2ac6b8 137 Life *m_life;
29b07a38
GRG
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;
2480be69
GRG
146};
147
29b07a38 148
2480be69
GRG
149// --------------------------------------------------------------------------
150// LifeApp
151// --------------------------------------------------------------------------
152
153class LifeApp : public wxApp
154{
155public:
156 virtual bool OnInit();
157};
158
159#endif // _LIFE_APP_H_