]>
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>
7 // Copyright: (c) 2000, Guillermo Rodriguez Garcia
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
14 #include "wx/minifram.h"
19 // --------------------------------------------------------------------------
21 // --------------------------------------------------------------------------
23 // Note that in LifeCanvas, all cell coordinates are
24 // named i, j, while screen coordinates are named x, y.
26 class LifeCanvas
: public wxWindow
30 LifeCanvas(wxWindow
* parent
, Life
* life
, bool interactive
= true);
31 virtual ~LifeCanvas();
34 int GetCellSize() const { return m_cellsize
; };
35 void SetCellSize(int cellsize
);
36 void Recenter(wxInt32 i
, wxInt32 j
);
40 void DrawCell(wxInt32 i
, wxInt32 j
, bool alive
);
43 // any class wishing to process wxWidgets events must use this macro
46 // draw a cell (parametrized by DC)
47 void DrawCell(wxInt32 i
, wxInt32 j
, wxDC
&dc
);
50 void OnPaint(wxPaintEvent
& event
);
51 void OnMouse(wxMouseEvent
& event
);
52 void OnSize(wxSizeEvent
& event
);
53 void OnScroll(wxScrollWinEvent
& event
);
54 void OnEraseBackground(wxEraseEvent
& event
);
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
; };
62 // what is the user doing?
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)
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
84 // --------------------------------------------------------------------------
86 // --------------------------------------------------------------------------
88 class LifeNavigator
: public wxMiniFrame
92 LifeNavigator(wxWindow
*parent
);
95 // any class wishing to process wxWidgets events must use this macro
99 void OnClose(wxCloseEvent
& event
);
103 // --------------------------------------------------------------------------
105 // --------------------------------------------------------------------------
107 class LifeFrame
: public wxFrame
112 virtual ~LifeFrame();
115 void UpdateInfoText();
119 // any class wishing to process wxWidgets events must use this macro
120 DECLARE_EVENT_TABLE()
123 void OnMenu(wxCommandEvent
& event
);
124 void OnOpen(wxCommandEvent
& event
);
125 void OnSamples(wxCommandEvent
& event
);
126 void OnNavigate(wxCommandEvent
& event
);
127 void OnZoom(wxCommandEvent
& event
);
128 void OnSlider(wxScrollEvent
& event
);
129 void OnTimer(wxTimerEvent
& event
);
130 void OnClose(wxCloseEvent
& event
);
132 // event handler helpers
138 LifeCanvas
*m_canvas
;
139 LifeNavigator
*m_navigator
;
140 wxStaticText
*m_text
;
149 // --------------------------------------------------------------------------
151 // --------------------------------------------------------------------------
153 class LifeApp
: public wxApp
156 virtual bool OnInit();
159 #endif // _LIFE_APP_H_