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