]>
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 /////////////////////////////////////////////////////////////////////////////
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
33 // --------------------------------------------------------------------------
35 // --------------------------------------------------------------------------
37 /* Note that in LifeCanvas, all cell coordinates are
38 * named i, j, while screen coordinates are named x, y.
40 class LifeCanvas
: public wxWindow
44 LifeCanvas(wxWindow
* parent
, Life
* life
, bool interactive
= TRUE
);
48 int GetCellSize() const { return m_cellsize
; };
49 void SetCellSize(int cellsize
);
50 void Recenter(wxInt32 i
, wxInt32 j
);
54 void DrawCell(wxInt32 i
, wxInt32 j
, bool alive
);
57 // any class wishing to process wxWindows events must use this macro
60 // draw a cell (parametrized by DC)
61 void DrawCell(wxInt32 i
, wxInt32 j
, wxDC
&dc
);
64 void OnPaint(wxPaintEvent
& event
);
65 void OnMouse(wxMouseEvent
& event
);
66 void OnSize(wxSizeEvent
& event
);
67 void OnScroll(wxScrollWinEvent
& event
);
68 void OnEraseBackground(wxEraseEvent
& event
);
70 // conversion between cell and screen coordinates
71 inline wxInt32
XToCell(wxCoord x
) const { return (x
/ m_cellsize
) + m_viewportX
; };
72 inline wxInt32
YToCell(wxCoord y
) const { return (y
/ m_cellsize
) + m_viewportY
; };
73 inline wxCoord
CellToX(wxInt32 i
) const { return (i
- m_viewportX
) * m_cellsize
; };
74 inline wxCoord
CellToY(wxInt32 j
) const { return (j
- m_viewportY
) * m_cellsize
; };
76 // what is the user doing?
84 Life
*m_life
; // Life object
85 int m_cellsize
; // current cell size, in pixels
86 bool m_interactive
; // is this canvas interactive?
87 MouseStatus m_status
; // what is the user doing?
88 wxInt32 m_viewportX
; // first visible cell (x coord)
89 wxInt32 m_viewportY
; // first visible cell (y coord)
90 wxInt32 m_viewportW
; // number of visible cells (w)
91 wxInt32 m_viewportH
; // number of visible cells (h)
92 int m_thumbX
; // horiz. scrollbar thumb position
93 int m_thumbY
; // vert. scrollbar thumb position
94 wxInt32 m_mi
, m_mj
; // last mouse position
97 // --------------------------------------------------------------------------
99 // --------------------------------------------------------------------------
102 class LifeTimer
: public wxTimer
108 // --------------------------------------------------------------------------
110 // --------------------------------------------------------------------------
112 class LifeFrame
: public wxFrame
120 void UpdateInfoText();
125 // any class wishing to process wxWindows events must use this macro
126 DECLARE_EVENT_TABLE()
129 void OnMenu(wxCommandEvent
& event
);
130 void OnSamples(wxCommandEvent
& event
);
131 void OnSlider(wxScrollEvent
& event
);
132 void OnClose(wxCloseEvent
& event
);
138 LifeCanvas
*m_canvas
;
139 wxStaticText
*m_text
;
146 // --------------------------------------------------------------------------
148 // --------------------------------------------------------------------------
150 class LifeApp
: public wxApp
153 virtual bool OnInit();
156 #endif // _LIFE_APP_H_