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