2000-01-08 13:27:19 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: life.h
|
2000-03-03 13:21:48 -05:00
|
|
|
// Purpose: The game of Life, created by J. H. Conway
|
2000-01-08 13:27:19 -05:00
|
|
|
// Author: Guillermo Rodriguez Garcia, <guille@iies.es>
|
|
|
|
// Modified by:
|
|
|
|
// Created: Jan/2000
|
|
|
|
// Copyright: (c) 2000, Guillermo Rodriguez Garcia
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _LIFE_APP_H_
|
|
|
|
#define _LIFE_APP_H_
|
|
|
|
|
2000-03-03 13:21:48 -05:00
|
|
|
#include "wx/minifram.h"
|
|
|
|
|
2000-01-08 13:27:19 -05:00
|
|
|
#include "game.h"
|
|
|
|
|
2000-03-03 13:21:48 -05:00
|
|
|
|
2000-01-08 13:27:19 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// LifeCanvas
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2000-03-03 13:21:48 -05:00
|
|
|
// Note that in LifeCanvas, all cell coordinates are
|
|
|
|
// named i, j, while screen coordinates are named x, y.
|
|
|
|
|
2000-02-08 15:04:48 -05:00
|
|
|
class LifeCanvas : public wxWindow
|
2000-01-08 13:27:19 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctor and dtor
|
2004-05-25 08:44:56 -04:00
|
|
|
LifeCanvas(wxWindow* parent, Life* life, bool interactive = true);
|
2006-09-05 16:47:48 -04:00
|
|
|
virtual ~LifeCanvas();
|
2000-01-08 13:27:19 -05:00
|
|
|
|
2000-02-08 15:04:48 -05:00
|
|
|
// view management
|
|
|
|
int GetCellSize() const { return m_cellsize; };
|
|
|
|
void SetCellSize(int cellsize);
|
|
|
|
void Recenter(wxInt32 i, wxInt32 j);
|
|
|
|
|
|
|
|
// drawing
|
|
|
|
void DrawChanged();
|
|
|
|
void DrawCell(wxInt32 i, wxInt32 j, bool alive);
|
|
|
|
|
|
|
|
private:
|
2004-05-25 07:20:37 -04:00
|
|
|
// any class wishing to process wxWidgets events must use this macro
|
2000-02-08 15:04:48 -05:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
|
|
|
|
// draw a cell (parametrized by DC)
|
|
|
|
void DrawCell(wxInt32 i, wxInt32 j, wxDC &dc);
|
2000-01-08 13:27:19 -05:00
|
|
|
|
|
|
|
// event handlers
|
|
|
|
void OnPaint(wxPaintEvent& event);
|
|
|
|
void OnMouse(wxMouseEvent& event);
|
|
|
|
void OnSize(wxSizeEvent& event);
|
2000-02-08 15:04:48 -05:00
|
|
|
void OnScroll(wxScrollWinEvent& event);
|
|
|
|
void OnEraseBackground(wxEraseEvent& event);
|
2000-01-08 13:27:19 -05:00
|
|
|
|
2000-02-08 15:04:48 -05:00
|
|
|
// conversion between cell and screen coordinates
|
|
|
|
inline wxInt32 XToCell(wxCoord x) const { return (x / m_cellsize) + m_viewportX; };
|
|
|
|
inline wxInt32 YToCell(wxCoord y) const { return (y / m_cellsize) + m_viewportY; };
|
|
|
|
inline wxCoord CellToX(wxInt32 i) const { return (i - m_viewportX) * m_cellsize; };
|
|
|
|
inline wxCoord CellToY(wxInt32 j) const { return (j - m_viewportY) * m_cellsize; };
|
2000-01-08 13:27:19 -05:00
|
|
|
|
2000-02-08 15:04:48 -05:00
|
|
|
// what is the user doing?
|
2000-01-08 13:27:19 -05:00
|
|
|
enum MouseStatus
|
|
|
|
{
|
|
|
|
MOUSE_NOACTION,
|
|
|
|
MOUSE_DRAWING,
|
|
|
|
MOUSE_ERASING
|
|
|
|
};
|
|
|
|
|
2000-02-08 15:04:48 -05:00
|
|
|
Life *m_life; // Life object
|
|
|
|
int m_cellsize; // current cell size, in pixels
|
|
|
|
bool m_interactive; // is this canvas interactive?
|
|
|
|
MouseStatus m_status; // what is the user doing?
|
|
|
|
wxInt32 m_viewportX; // first visible cell (x coord)
|
|
|
|
wxInt32 m_viewportY; // first visible cell (y coord)
|
|
|
|
wxInt32 m_viewportW; // number of visible cells (w)
|
|
|
|
wxInt32 m_viewportH; // number of visible cells (h)
|
2005-01-31 13:18:18 -05:00
|
|
|
int m_thumbX; // horiz. scrollbar thumb position
|
|
|
|
int m_thumbY; // vert. scrollbar thumb position
|
|
|
|
wxInt32 m_mi, m_mj; // last mouse position
|
2000-01-08 13:27:19 -05:00
|
|
|
};
|
|
|
|
|
2000-03-03 13:21:48 -05:00
|
|
|
|
2000-01-08 13:27:19 -05:00
|
|
|
// --------------------------------------------------------------------------
|
2000-03-03 13:21:48 -05:00
|
|
|
// LifeNavigator
|
2000-01-08 13:27:19 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2000-03-03 13:21:48 -05:00
|
|
|
class LifeNavigator : public wxMiniFrame
|
2000-01-08 13:27:19 -05:00
|
|
|
{
|
|
|
|
public:
|
2000-03-03 13:21:48 -05:00
|
|
|
// ctor
|
|
|
|
LifeNavigator(wxWindow *parent);
|
|
|
|
|
|
|
|
private:
|
2004-05-25 07:20:37 -04:00
|
|
|
// any class wishing to process wxWidgets events must use this macro
|
2000-03-03 13:21:48 -05:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
|
|
|
|
// event handlers
|
|
|
|
void OnClose(wxCloseEvent& event);
|
2000-01-08 13:27:19 -05:00
|
|
|
};
|
|
|
|
|
2000-03-03 13:21:48 -05:00
|
|
|
|
2000-01-08 13:27:19 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// LifeFrame
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class LifeFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctor and dtor
|
|
|
|
LifeFrame();
|
2006-09-05 16:47:48 -04:00
|
|
|
virtual ~LifeFrame();
|
2000-01-08 13:27:19 -05:00
|
|
|
|
|
|
|
// member functions
|
|
|
|
void UpdateInfoText();
|
2000-02-08 15:04:48 -05:00
|
|
|
void UpdateUI();
|
|
|
|
|
|
|
|
private:
|
2004-05-25 07:20:37 -04:00
|
|
|
// any class wishing to process wxWidgets events must use this macro
|
2000-02-08 15:04:48 -05:00
|
|
|
DECLARE_EVENT_TABLE()
|
2000-01-08 13:27:19 -05:00
|
|
|
|
|
|
|
// event handlers
|
2000-03-03 13:21:48 -05:00
|
|
|
void OnMenu(wxCommandEvent& event);
|
2000-07-15 15:51:35 -04:00
|
|
|
void OnOpen(wxCommandEvent& event);
|
|
|
|
void OnSamples(wxCommandEvent& event);
|
2000-03-03 13:21:48 -05:00
|
|
|
void OnNavigate(wxCommandEvent& event);
|
|
|
|
void OnZoom(wxCommandEvent& event);
|
2000-02-08 15:04:48 -05:00
|
|
|
void OnSlider(wxScrollEvent& event);
|
2000-03-03 13:21:48 -05:00
|
|
|
void OnTimer(wxTimerEvent& event);
|
2000-02-08 15:04:48 -05:00
|
|
|
void OnClose(wxCloseEvent& event);
|
2000-03-03 13:21:48 -05:00
|
|
|
|
|
|
|
// event handler helpers
|
2000-01-08 13:27:19 -05:00
|
|
|
void OnStart();
|
|
|
|
void OnStop();
|
2000-03-03 13:21:48 -05:00
|
|
|
void OnStep();
|
|
|
|
|
2005-01-31 13:18:18 -05:00
|
|
|
Life *m_life;
|
2000-03-03 13:21:48 -05:00
|
|
|
LifeCanvas *m_canvas;
|
|
|
|
LifeNavigator *m_navigator;
|
|
|
|
wxStaticText *m_text;
|
|
|
|
wxTimer *m_timer;
|
|
|
|
bool m_running;
|
|
|
|
bool m_topspeed;
|
|
|
|
long m_interval;
|
|
|
|
long m_tics;
|
2000-01-08 13:27:19 -05:00
|
|
|
};
|
|
|
|
|
2000-03-03 13:21:48 -05:00
|
|
|
|
2000-01-08 13:27:19 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// LifeApp
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class LifeApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool OnInit();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _LIFE_APP_H_
|