-// --------------------------------------------------------------------------
-// classes
-// --------------------------------------------------------------------------
-
-class Life;
-class LifeShape;
-class LifeCanvas;
-class LifeTimer;
-class LifeFrame;
-class LifeApp;
-class LifeNewGameDialog;
-class LifeSamplesDialog;
-
-// --------------------------------------------------------------------------
-// non-GUI classes
-// --------------------------------------------------------------------------
-
-// Life
-class Life
-{
-public:
- // ctors and dtors
- Life(int width, int height);
- ~Life();
- void Create(int width, int height);
- void Destroy();
-
- // accessors
- inline int GetWidth() const { return m_width; };
- inline int GetHeight() const { return m_height; };
- inline bool IsAlive(int x, int y) const;
- inline bool HasChanged(int x, int y) const;
-
- // flags
- void SetBorderWrap(bool on);
-
- // game logic
- void Clear();
- void SetCell(int x, int y, bool alive = TRUE);
- void SetShape(LifeShape &shape);
- bool NextTic();
-
-private:
- enum CellFlags {
- CELL_DEAD = 0x0000, // is dead
- CELL_ALIVE = 0x0001, // is alive
- CELL_MARK = 0x0002, // will change / has changed
- };
- typedef int Cell;
-
- int GetNeighbors(int x, int y) const;
- inline void SetCell(int x, int y, Cell status);
-
- int m_width;
- int m_height;
- Cell *m_cells;
- bool m_wrap;
-};
-
-// LifeShape
-class LifeShape
-{
-public:
- LifeShape::LifeShape(wxString name,
- wxString desc,
- int width, int height, char *data,
- int fieldWidth = 20, int fieldHeight = 20,
- bool wrap = TRUE)
- {
- m_name = name;
- m_desc = desc;
- m_width = width;
- m_height = height;
- m_data = data;
- m_fieldWidth = fieldWidth;
- m_fieldHeight = fieldHeight;
- m_wrap = wrap;
- }
-
- wxString m_name;
- wxString m_desc;
- int m_width;
- int m_height;
- char *m_data;
- int m_fieldWidth;
- int m_fieldHeight;
- bool m_wrap;
-};
-
-// --------------------------------------------------------------------------
-// GUI classes
-// --------------------------------------------------------------------------
-
-// Life canvas
-class LifeCanvas : public wxScrolledWindow
-{
-public:
- // ctor and dtor
- LifeCanvas(wxWindow* parent, Life* life, bool interactive = TRUE);
- ~LifeCanvas();
-
- // member functions
- void Reset();
- void DrawEverything(bool force = FALSE);
- void DrawCell(int i, int j);
- void DrawCell(int i, int j, wxDC &dc);
- inline int CellToCoord(int i) const { return (i * m_cellsize); };
- inline int CoordToCell(int x) const { return ((x >= 0)? (x / m_cellsize) : -1); };
-
- // event handlers
- void OnPaint(wxPaintEvent& event);
- void OnMouse(wxMouseEvent& event);
- void OnSize(wxSizeEvent& event);
-
-private:
- // any class wishing to process wxWindows events must use this macro
- DECLARE_EVENT_TABLE()
-
- enum MouseStatus {
- MOUSE_NOACTION,
- MOUSE_DRAWING,
- MOUSE_ERASING
- };
-
- Life *m_life;
- wxBitmap *m_bmp;
- int m_height;
- int m_width;
- int m_cellsize;
- wxCoord m_xoffset;
- wxCoord m_yoffset;
- MouseStatus m_status;
- bool m_interactive;
-};
-
-// Life timer
-class LifeTimer : public wxTimer
-{
-public:
- void Notify();
-};
-
-// Life main frame
-class LifeFrame : public wxFrame
-{
-public:
- // ctor and dtor
- LifeFrame();
- ~LifeFrame();
-
- // member functions
- void UpdateInfoText();
-
- // event handlers
- void OnMenu(wxCommandEvent& event);
- void OnNewGame(wxCommandEvent& event);
- void OnSamples(wxCommandEvent& event);
- void OnStart();
- void OnStop();
- void OnTimer();
- void OnSlider(wxScrollEvent& event);
-
-private:
- // any class wishing to process wxWindows events must use this macro
- DECLARE_EVENT_TABLE()
-
- Life *m_life;
- LifeTimer *m_timer;
- LifeCanvas *m_canvas;
- wxStaticText *m_text;
- bool m_running;
- long m_interval;
- long m_tics;
-};
-
-// Life new game dialog
-class LifeNewGameDialog : public wxDialog
-{
-public:
- // ctor
- LifeNewGameDialog(wxWindow *parent, int *w, int *h);
-
- // event handlers
- void OnOK(wxCommandEvent& event);
-
-private:
- // any class wishing to process wxWindows events must use this macro
- DECLARE_EVENT_TABLE();
-
- int *m_w;
- int *m_h;
- wxSpinCtrl *m_spinctrlw;
- wxSpinCtrl *m_spinctrlh;
-};
-
-// Life sample configurations dialog
-class LifeSamplesDialog : public wxDialog
-{
-public:
- // ctor and dtor
- LifeSamplesDialog(wxWindow *parent);
- ~LifeSamplesDialog();
-
- // members
- int GetValue();
-
- // event handlers
- void OnListBox(wxCommandEvent &event);
-
-private:
- // any class wishing to process wxWindows events must use this macro
- DECLARE_EVENT_TABLE();
-
- int m_value;
- wxListBox *m_list;
- wxTextCtrl *m_text;
- LifeCanvas *m_canvas;
- Life *m_life;
-};
-
-// Life app
-class LifeApp : public wxApp
-{
-public:
- virtual bool OnInit();
-};
-