]>
git.saurik.com Git - wxWidgets.git/blob - demos/life/life.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: The game of Life, created by J. H. Conway
4 // Author: Guillermo Rodriguez Garcia, <guille@iies.es>
8 // Copyright: (c) 2000, Guillermo Rodriguez Garcia
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "life.h"
19 // for compilers that support precompilation, includes "wx/wx.h"
20 #include "wx/wxprec.h"
26 // for all others, include the necessary headers
31 #include "wx/minifram.h"
36 // --------------------------------------------------------------------------
38 // --------------------------------------------------------------------------
40 // Note that in LifeCanvas, all cell coordinates are
41 // named i, j, while screen coordinates are named x, y.
43 class LifeCanvas
: public wxWindow
47 LifeCanvas(wxWindow
* parent
, Life
* life
, bool interactive
= true);
51 int GetCellSize() const { return m_cellsize
; };
52 void SetCellSize(int cellsize
);
53 void Recenter(wxInt32 i
, wxInt32 j
);
57 void DrawCell(wxInt32 i
, wxInt32 j
, bool alive
);
60 // any class wishing to process wxWidgets events must use this macro
63 // draw a cell (parametrized by DC)
64 void DrawCell(wxInt32 i
, wxInt32 j
, wxDC
&dc
);
67 void OnPaint(wxPaintEvent
& event
);
68 void OnMouse(wxMouseEvent
& event
);
69 void OnSize(wxSizeEvent
& event
);
70 void OnScroll(wxScrollWinEvent
& event
);
71 void OnEraseBackground(wxEraseEvent
& event
);
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
; };
79 // what is the user doing?
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
97 wxInt32 m_mi
, m_mj
; // last mouse position
101 // --------------------------------------------------------------------------
103 // --------------------------------------------------------------------------
105 class LifeNavigator
: public wxMiniFrame
109 LifeNavigator(wxWindow
*parent
);
112 // any class wishing to process wxWidgets events must use this macro
113 DECLARE_EVENT_TABLE()
116 void OnClose(wxCloseEvent
& event
);
120 // --------------------------------------------------------------------------
122 // --------------------------------------------------------------------------
124 class LifeFrame
: public wxFrame
132 void UpdateInfoText();
136 // any class wishing to process wxWidgets events must use this macro
137 DECLARE_EVENT_TABLE()
140 void OnMenu(wxCommandEvent
& event
);
141 void OnOpen(wxCommandEvent
& event
);
142 void OnSamples(wxCommandEvent
& event
);
143 void OnNavigate(wxCommandEvent
& event
);
144 void OnZoom(wxCommandEvent
& event
);
145 void OnSlider(wxScrollEvent
& event
);
146 void OnTimer(wxTimerEvent
& event
);
147 void OnClose(wxCloseEvent
& event
);
149 // event handler helpers
155 LifeCanvas
*m_canvas
;
156 LifeNavigator
*m_navigator
;
157 wxStaticText
*m_text
;
166 // --------------------------------------------------------------------------
168 // --------------------------------------------------------------------------
170 class LifeApp
: public wxApp
173 virtual bool OnInit();
176 #endif // _LIFE_APP_H_