Life! version 2
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5912 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
BIN
demos/life/bitmaps/life.bmp
Normal file
BIN
demos/life/bitmaps/life.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.5 KiB |
81
demos/life/bitmaps/life.xpm
Normal file
81
demos/life/bitmaps/life.xpm
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
/* XPM */
|
||||||
|
static char * life_xpm[] = {
|
||||||
|
"151 73 5 1",
|
||||||
|
" c None",
|
||||||
|
". c #808080",
|
||||||
|
"X c Black",
|
||||||
|
"o c Gray100",
|
||||||
|
"O c #c0c0c0",
|
||||||
|
" .X ",
|
||||||
|
" .XXo.. ",
|
||||||
|
" .XXOooooX ",
|
||||||
|
" .XXooOoooooX ",
|
||||||
|
" XXXoooooOoooooX ",
|
||||||
|
" .XXXoooOoooooOooooX. ",
|
||||||
|
" .XXoOoooooOoooooOoooOOX ",
|
||||||
|
" .XXXooooOoooooOoooooOOOoooX ",
|
||||||
|
" .XXooOoooooOoooooOoooOOOoooooX ",
|
||||||
|
" .XXXooooooooooooooooo.OOoooOoooooX ",
|
||||||
|
" .XXoooOooooooOoooooOo.XXXOoooooOoooo.. ",
|
||||||
|
" ..XXooooooOooooooOoooOXXXXXXX.oooooOoooooX ",
|
||||||
|
" .XXooooooooooOooooooO.XXXXXXXXXXXoooooOoooOOX ",
|
||||||
|
" .XXooOooooooooooOooo.XXXXXXXXXXXXXXXoooooOOOOooX ",
|
||||||
|
" .XXOoooooOoooooOoooo.XXXXXXXXXXXXXXXXXXXooOOOOoooooX. ",
|
||||||
|
" .XXoooOoooooOoooooOo.XXXXXXXXXXXXXXXXXXXXXXOOoooOOoooooX ",
|
||||||
|
" .XXoOoooooOoooooOooooOXXXXXXXXXXXXXXXXXXXXXX.oOooooooOoooooX ",
|
||||||
|
" .XXOooooOoooooOoooooOOOOooXXXXXXXXXXXXXXXXXX.OoooooOoooooOoooooX ",
|
||||||
|
" .XXOooooooooOoooooOoo.XX.oooooXXXXXXXXXXXXXXX.oooOoooooOoooooOoooOOX. ",
|
||||||
|
" .XX.ooooooooooOoooooOXXXXXXOoooooXXXXXXXXXXX.OOoooooOoooooOoooooOOOooo.X ",
|
||||||
|
" .XXOooOoooooOoooooOoO.XXXXXXXXXOoooooXXXXXXXXoooooOoooooOoooooOooOOoOOoooooX ",
|
||||||
|
" XXXOoooooOoooooOoooo.XXXXXXXXXXXXXOoooooXXXXXXXooooooOoooooOooooOOOoooooOoooooX ",
|
||||||
|
" .XXXooooOoooooOooooo..XXXXXXXXXXXXXXXXXOoooOOXXXXXXXooooooOoooooOOOOooOooooooOoooooX ",
|
||||||
|
" ..XXooOoooooOoooooOooOXXXXXXXXXXXXXXXXXXXXX.OOoooXXXXXXXooooooOoo.XXXooooooOoooooOoooooX. ",
|
||||||
|
" ..XXOoooooOoooooOoooooXXXXXXXXXXXXXXXXXXXXXXXOoOoooooXXXXXXXoooooOXXXXXXXooooooOoooooOoooOOOX ",
|
||||||
|
" ..XXoooOooooooooooooooOOooXXXXXXXXXXXXXXXXXXX.oooooOoooooXXXXXXXo.XXXXXXXXXXXOoooooOoooooOOOooooX ",
|
||||||
|
" ..XXoOoooooOoooooOoooO.XOoooooXXXXXXXXXXXXXXX.OoOooooooOoooooXXXXXXXXXXXXXXXXXXXXXoooooOoOOOOoOoooooX ",
|
||||||
|
" ..XX.ooooOoooooOooooo..XXXXXoooooOXXXXXXXXXXXXOoooooOooooooOoooooXXXXXXXXXXXXXXXXXXXXXooooOOooooooOoooooX. ",
|
||||||
|
" ..XXoooOoooooOoooooOooOOoXXXXXXXooooo.XXXXXXX.OoooOoooooOooooooOooOOOXXXXXXXXXXXXXXXXXXXXXOOOooOooooooOooooo.X ",
|
||||||
|
" .XXOOoooooOoooooOoooooOOOooooXXXXXXXooooo.XXXXXXooooooOoooooOoooooOOoooooXXXXXXXXXXXXXXXXXXXOOooooooOoooooOooooooX ",
|
||||||
|
" .XXOoooOOoooooOoooooOoOOooOooooooXXXXXX.ooooOXXXXXXXooooooOoooooOoOOOooOoooooXXXXXXXXXXXXXXX.ooooOooooooOoooooOoooOOoX ",
|
||||||
|
" ..XX.oOoooooOooooooOoooOOOoooooOooooo.XXXXXXOOOOooXXXXXXXooooooOooo.XXooooooOoooooXXXXXXXXXX.OooOoooooOooooooOoooooOOoooooX. ",
|
||||||
|
" ..XXooooooOoooooOoooooOOOooooooooooOoooooXXXXXXXOoooooXXXXXXXoooooOXXXXXXXooooooOoooooXXXXXXX.ooooooOoooooOooooooOoOOOooOooooo.X ",
|
||||||
|
" .XXXoOoooooOoooooOoooooOOoooooOooooooOoooooXXXXXXXooooooXXXXXXXoooO.XXXXXXXXooooooOoooooXXXXXXX.ooooooOooooooOoooo.XOoooooOooooo.X ",
|
||||||
|
" XoooooOoooooOoooooXOOooooOoooooOoooooOoooOOOXXXXXXXooooooXXXXXXX.XXXXXXXXXXXXooooooOoooOOXXXXXXXXooooooOooooooO.XXXXXooooooOooooooX ",
|
||||||
|
" XoooooOooooooOo.XXX.ooooooOoooooOoooooOOOooooXXXXXXXoooooOXXXXXXXXXXXXXXXXXXXXoooooOOOOoooXXXXXXXXooooooOooo.XXXXXXXXXOoooooOooooooX ",
|
||||||
|
" XoooooOooooO.XXXXXXooooooOooooooOoOOooOooooo.XXXXXXXooooo.XXXXXXXXXXXXXXXXXXXXooOOOoOooooo.XXXXXXXooooooXXXXXXXXXXXXXX.oooooOOoooOOX. ",
|
||||||
|
" ..oooooOOOoooXXXXXXXooooooOooooOOOoooooOoooooXXXXXXX.OOOoo.XXXXXXXXXXXXXXXXXXXOOoooooOooooo.XXXXXXXoO.XXXXXXXXXXXXXXXXXXooooooOOOooo.X ",
|
||||||
|
" XooOOOOoooooOXXXXXX.ooooooOOOoooOoooooOooooooXXXXXXXOoooooXXXXXXXXXXXXXXXXXoooOooooooOooooo.XXXXXXXXXXXXXXXXXXXXXXXXXXXXooOOOoOooooooX ",
|
||||||
|
" .XoooooOoooooXXXXXXXooOOOOOooooooOoooooOooooooXXXXXXXooooooXXXXXXXXXXXX.OooooooOooooooOooooo.XXXXXXXXXXXXXXXXXXXXXXXXXXXXOoooooOooooooX ",
|
||||||
|
" XoooooOooooooXXXXXXXOoooooOoooooOooooooOoOOOooXXXXXXXooooooXXXXXXXX.ooooOooooooOooooooOooOOO.XXXXXXXXXXXXXXXXXXXXXXXX.ooOooooooOooooooX ",
|
||||||
|
" .XoooooOooooo.XXXXXX.ooooooOoooooOooooOOOooooo.XXXXXXXooooooXXXXXXXooooooOooooooOoooooOOOoooo.XXXXXXXXXXXXXXXXXXX.OOoooooOOoooooOOoooooX.",
|
||||||
|
" XoooooOoooOOOXXXXXXXooooooOooooooOOOoooOOoooooXXXXXXXXoooOOOXXXXXXXooooooOooooooOoOOoooOooooo.XXXXXXXXXXXXXXXXoooooOooooooOooooooOoo.XXXX",
|
||||||
|
" XooooOOOoooooXXXXXXXooooooOooOOooOoooooOooooooXXXXXXX.OOooo.XXXXXXXooooooOoooOOOOooooooOooooooXXXXXXXXXXX.ooOooooooOooooooOooooO.XXXX ",
|
||||||
|
" XOOOoooOoooooXXXXXXX.ooooOOOoooooOooooooOooooooXXXXXXXOooooo.XXXXXXXooooooOOoooooOooooooOooooooXXXXXX.OooooooOooooooOooooooXO.XXX. ",
|
||||||
|
" XoooooOooooooXXXXXXXOOOoooOOoooooOooooooOooooOOXXXXXXXooooooXXXXXXXXoOOOooOooooooOooooooOoooooOXXOoooOOooooooOooooooOooo.XXXX. ",
|
||||||
|
" XooooooOooooo.XXXXXXXooooooOooooooOoooooOOOOooo.XXXXXXXooooooXXXXXXX.ooooooOooooooOooooooOoOOOooOooooooOooooooOoooooOXXXX. ",
|
||||||
|
" XoooooOoooooOXXXXXXX.ooooooOooooooOooOOOOooooooXXXXXXXXooooooXXXXXXX.ooooooOooooooOooooOOOooooooOooooooOooooooOO.XXXX. ",
|
||||||
|
" ..oooooOOOOoooXXXXXXXoooooooOooooOOOoooooOooooooXXXXXXXXooOOooXXXXXXXOoooooOOoooooOOOOOoooOooooooOooooooOoooO.XXX.. ",
|
||||||
|
" XoooOOOOooooo.XXXXXXXooooooOOOOoooOooooooOooooooXXXXXXX.oooooOXXXXXXXOoooooOOooOOOoOooooooOooooooOoooooOXXXXX. ",
|
||||||
|
" .XoooooOooooooXXXXXXX.ooOOOOOooooooOooooooOoooooOXXXXXXXooooooOXXXXXXXoooooOOOooooooOooooooOooooooOo.XXXX. ",
|
||||||
|
" XooooooOoooooOXXXXXXXOoooooOOoooooOooooooOoooOOo.XXXXXXXoooooo.XXXXXXXOOOOooOoooooooOooooooOoooO.XXXX. ",
|
||||||
|
" .XoooooOooooooXXXXXXXXooooooOooooooOooooO.XooooooXXXXXXXXoooooo.XXXXXOOooooooOooooooooooooo.XXXXX. ",
|
||||||
|
" XooooooOoooOOOXXXXXXX.ooooooOoooooo..XXXXXXooooooXXXXXXXXoooooOXOoooooOooooooOoooooooooO.XXX. ",
|
||||||
|
" XoooooOOOoooo.XXXXXXXooooooOooo.XXXXXXXXXX.ooooooXXXXXXXXOOOoooOooooooOooooooOooooO.XXX. ",
|
||||||
|
" XOOOOooOooooooXXXXXXXXooooO.XXXXXXXXXXXXXXXooooooOXXXXXXOOooooooOooooooOooooooX.XXXX. ",
|
||||||
|
" XooooooOooooooXXXXXXXX.XXXXXXXXXXXXXXXXXXXXooooooOXOooooOoooooooOooooooOoo.XXXX. ",
|
||||||
|
" X.oooooOoooooo.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXoOOOooOooooooOooooooOOoooo.XXXX. ",
|
||||||
|
" XooooooOoooooOXXXXXXXXXXXXXXXXXXXXXXXXXXX.OOooooooOooooooOoooooo...XXX. ",
|
||||||
|
" X.oooooOOOOoooOXXXXXXXXXXXXXXXXXXXXXX.OooooOOooooooOooooooOoo..XXX. ",
|
||||||
|
" XoooOOoOooooooXXXXXXXXXXXXXXXXXX.OooOooooooOooooooOOoooo.XXXX. ",
|
||||||
|
" .XoooooOOooooooXXXXXXXXXXXXXOOoooooooOooooooOooooooX.XXXX. ",
|
||||||
|
" XooooooOoooooo.XXXXXXXXOoooooOooooooOoooooooOoo.XXXX. ",
|
||||||
|
" .XooooooOooooooXXXXoooOooooooOOooooooOooooO.XXXX. ",
|
||||||
|
" XooooooOoooOOOoOooooooOooooooOoooooooX.XXXX. ",
|
||||||
|
" XoooooOOOoooooOooooooOOooooooOoO.XXXX.. ",
|
||||||
|
" XXOOoooOOooooooOooooooOooooO.XXXX. ",
|
||||||
|
" XooooooOooooooOooooooOX.XXX. ",
|
||||||
|
" X.ooooooOooooooOoO.XXXX. ",
|
||||||
|
" XooooooOooooO.XXX.. ",
|
||||||
|
" X.oooooOXXXXX. ",
|
||||||
|
" XOO.XXX.. ",
|
||||||
|
".XX. "};
|
BIN
demos/life/bitmaps/zoomin.bmp
Normal file
BIN
demos/life/bitmaps/zoomin.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 246 B |
23
demos/life/bitmaps/zoomin.xpm
Normal file
23
demos/life/bitmaps/zoomin.xpm
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* XPM */
|
||||||
|
static char * zoomin_xpm[] = {
|
||||||
|
"16 16 3 1",
|
||||||
|
" c None",
|
||||||
|
". c Black",
|
||||||
|
"X c Gray100",
|
||||||
|
" .... ",
|
||||||
|
" ..XXXX.. ",
|
||||||
|
" .XXXXXXXX. ",
|
||||||
|
" .XXX..XXX. ",
|
||||||
|
".XXXX..XXXX. ",
|
||||||
|
".XX......XX. ",
|
||||||
|
".XX......XX. ",
|
||||||
|
".XXXX..XXXX. ",
|
||||||
|
" .XXX..XXX. ",
|
||||||
|
" .XXXXXXXX. ",
|
||||||
|
" ..XXXX... ",
|
||||||
|
" .... ... ",
|
||||||
|
" ... ",
|
||||||
|
" ... ",
|
||||||
|
" ... ",
|
||||||
|
" .. "
|
||||||
|
};
|
BIN
demos/life/bitmaps/zoomout.bmp
Normal file
BIN
demos/life/bitmaps/zoomout.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 246 B |
23
demos/life/bitmaps/zoomout.xpm
Normal file
23
demos/life/bitmaps/zoomout.xpm
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* XPM */
|
||||||
|
static char * zoomout_xpm[] = {
|
||||||
|
"16 16 3 1",
|
||||||
|
" c None",
|
||||||
|
". c Black",
|
||||||
|
"X c Gray100",
|
||||||
|
" .... ",
|
||||||
|
" ..XXXX.. ",
|
||||||
|
" .XXXXXXXX. ",
|
||||||
|
" .XXXXXXXX. ",
|
||||||
|
".XXXXXXXXXX. ",
|
||||||
|
".XX......XX. ",
|
||||||
|
".XX......XX. ",
|
||||||
|
".XXXXXXXXXX. ",
|
||||||
|
" .XXXXXXXX. ",
|
||||||
|
" .XXXXXXXX. ",
|
||||||
|
" ..XXXX... ",
|
||||||
|
" .... ... ",
|
||||||
|
" ... ",
|
||||||
|
" ... ",
|
||||||
|
" ... ",
|
||||||
|
" .. "
|
||||||
|
};
|
@@ -10,29 +10,13 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// declarations
|
// headers, declarations, constants
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// headers
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma implementation "dialogs.h"
|
#pragma implementation "dialogs.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// for compilers that support precompilation, includes "wx/wx.h"
|
|
||||||
#include "wx/wxprec.h"
|
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
|
||||||
#pragma hdrstop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// for all others, include the necessary headers
|
|
||||||
#ifndef WX_PRECOMP
|
|
||||||
#include "wx/wx.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "wx/statline.h"
|
#include "wx/statline.h"
|
||||||
#include "wx/spinctrl.h"
|
#include "wx/spinctrl.h"
|
||||||
|
|
||||||
@@ -40,6 +24,18 @@
|
|||||||
#include "life.h"
|
#include "life.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
// resources
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if defined(__WXGTK__) || defined(__WXMOTIF__)
|
||||||
|
// logo for the about dialog
|
||||||
|
#include "bitmaps/life.xpm"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// sample configurations
|
||||||
|
#include "samples.inc"
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// constants
|
// constants
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@@ -47,24 +43,21 @@
|
|||||||
// IDs for the controls and the menu commands
|
// IDs for the controls and the menu commands
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
// listbox in samples dialog
|
// bmp window in about dialog
|
||||||
ID_LISTBOX = 2001
|
ID_BMPWIN = 2001,
|
||||||
};
|
|
||||||
|
|
||||||
// sample configurations
|
// listbox in samples dialog
|
||||||
#include "samples.inc"
|
ID_LISTBOX
|
||||||
|
};
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// event tables and other macros for wxWindows
|
// event tables and other macros for wxWindows
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
// Event tables
|
// Event tables
|
||||||
BEGIN_EVENT_TABLE(LifeNewGameDialog, wxDialog)
|
|
||||||
EVT_BUTTON (wxID_OK, LifeNewGameDialog::OnOK)
|
|
||||||
END_EVENT_TABLE()
|
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(LifeSamplesDialog, wxDialog)
|
BEGIN_EVENT_TABLE(LifeSamplesDialog, wxDialog)
|
||||||
EVT_LISTBOX (ID_LISTBOX, LifeSamplesDialog::OnListBox)
|
EVT_LISTBOX (ID_LISTBOX, LifeSamplesDialog::OnListBox)
|
||||||
|
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
|
||||||
@@ -72,62 +65,6 @@ END_EVENT_TABLE()
|
|||||||
// implementation
|
// implementation
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// LifeNewGameDialog
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
LifeNewGameDialog::LifeNewGameDialog(wxWindow *parent, int *w, int *h)
|
|
||||||
: wxDialog(parent, -1,
|
|
||||||
_("New game"),
|
|
||||||
wxDefaultPosition,
|
|
||||||
wxDefaultSize,
|
|
||||||
wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL)
|
|
||||||
{
|
|
||||||
m_w = w;
|
|
||||||
m_h = h;
|
|
||||||
|
|
||||||
// spin ctrls
|
|
||||||
m_spinctrlw = new wxSpinCtrl( this, -1 );
|
|
||||||
m_spinctrlw->SetValue(*m_w);
|
|
||||||
m_spinctrlw->SetRange(LIFE_MIN, LIFE_MAX);
|
|
||||||
|
|
||||||
m_spinctrlh = new wxSpinCtrl( this, -1 );
|
|
||||||
m_spinctrlh->SetValue(*m_h);
|
|
||||||
m_spinctrlh->SetRange(LIFE_MIN, LIFE_MAX);
|
|
||||||
|
|
||||||
// component layout
|
|
||||||
wxBoxSizer *inputsizer1 = new wxBoxSizer( wxHORIZONTAL );
|
|
||||||
inputsizer1->Add( new wxStaticText(this, -1, _("Width")), 1, wxCENTRE | wxLEFT, 20);
|
|
||||||
inputsizer1->Add( m_spinctrlw, 2, wxCENTRE | wxLEFT | wxRIGHT, 20 );
|
|
||||||
|
|
||||||
wxBoxSizer *inputsizer2 = new wxBoxSizer( wxHORIZONTAL );
|
|
||||||
inputsizer2->Add( new wxStaticText(this, -1, _("Height")), 1, wxCENTRE | wxLEFT, 20);
|
|
||||||
inputsizer2->Add( m_spinctrlh, 2, wxCENTRE | wxLEFT | wxRIGHT, 20 );
|
|
||||||
|
|
||||||
wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
|
|
||||||
topsizer->Add( CreateTextSizer(_("Enter board dimensions")), 0, wxALL, 10 );
|
|
||||||
topsizer->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT | wxBOTTOM, 10);
|
|
||||||
topsizer->Add( inputsizer1, 1, wxGROW | wxLEFT | wxRIGHT, 5 );
|
|
||||||
topsizer->Add( inputsizer2, 1, wxGROW | wxLEFT | wxRIGHT, 5 );
|
|
||||||
topsizer->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT | wxTOP, 10);
|
|
||||||
topsizer->Add( CreateButtonSizer(wxOK | wxCANCEL), 0, wxCENTRE | wxALL, 10);
|
|
||||||
|
|
||||||
// activate
|
|
||||||
SetSizer(topsizer);
|
|
||||||
SetAutoLayout(TRUE);
|
|
||||||
topsizer->SetSizeHints(this);
|
|
||||||
topsizer->Fit(this);
|
|
||||||
Centre(wxBOTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LifeNewGameDialog::OnOK(wxCommandEvent& WXUNUSED(event))
|
|
||||||
{
|
|
||||||
*m_w = m_spinctrlw->GetValue();
|
|
||||||
*m_h = m_spinctrlh->GetValue();
|
|
||||||
|
|
||||||
EndModal(wxID_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// LifeSamplesDialog
|
// LifeSamplesDialog
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@@ -153,7 +90,7 @@ LifeSamplesDialog::LifeSamplesDialog(wxWindow *parent)
|
|||||||
|
|
||||||
// descriptions
|
// descriptions
|
||||||
wxStaticBox *statbox = new wxStaticBox( this, -1, _("Description"));
|
wxStaticBox *statbox = new wxStaticBox( this, -1, _("Description"));
|
||||||
m_life = new Life( 16, 16 );
|
m_life = new Life();
|
||||||
m_life->SetShape(g_shapes[0]);
|
m_life->SetShape(g_shapes[0]);
|
||||||
m_canvas = new LifeCanvas( this, m_life, FALSE );
|
m_canvas = new LifeCanvas( this, m_life, FALSE );
|
||||||
m_text = new wxTextCtrl( this, -1,
|
m_text = new wxTextCtrl( this, -1,
|
||||||
@@ -183,30 +120,73 @@ LifeSamplesDialog::LifeSamplesDialog(wxWindow *parent)
|
|||||||
SetAutoLayout(TRUE);
|
SetAutoLayout(TRUE);
|
||||||
sizer3->SetSizeHints(this);
|
sizer3->SetSizeHints(this);
|
||||||
sizer3->Fit(this);
|
sizer3->Fit(this);
|
||||||
Centre(wxBOTH);
|
Centre(wxBOTH | wxCENTRE_ON_SCREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
LifeSamplesDialog::~LifeSamplesDialog()
|
LifeSamplesDialog::~LifeSamplesDialog()
|
||||||
{
|
{
|
||||||
m_canvas->Destroy();
|
m_canvas->Destroy();
|
||||||
delete m_life;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int LifeSamplesDialog::GetValue()
|
const LifeShape& LifeSamplesDialog::GetShape()
|
||||||
{
|
{
|
||||||
return m_value;
|
return g_shapes[m_value];
|
||||||
}
|
}
|
||||||
|
|
||||||
void LifeSamplesDialog::OnListBox(wxCommandEvent& event)
|
void LifeSamplesDialog::OnListBox(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
if (event.GetSelection() != -1)
|
int sel = event.GetSelection();
|
||||||
|
|
||||||
|
if (sel != -1)
|
||||||
{
|
{
|
||||||
m_value = m_list->GetSelection();
|
m_value = m_list->GetSelection();
|
||||||
m_text->SetValue(g_shapes[ event.GetSelection() ].m_desc);
|
m_text->SetValue(g_shapes[ sel ].m_desc);
|
||||||
m_life->SetShape(g_shapes[ event.GetSelection() ]);
|
m_life->SetShape(g_shapes[ sel ]);
|
||||||
|
|
||||||
m_canvas->DrawEverything(TRUE); // force redraw everything
|
// quick and dirty :-)
|
||||||
m_canvas->Refresh(FALSE); // do not erase background
|
if ((g_shapes[ sel ].m_width > 36) ||
|
||||||
|
(g_shapes[ sel ].m_height > 22))
|
||||||
|
m_canvas->SetCellSize(2);
|
||||||
|
else
|
||||||
|
m_canvas->SetCellSize(8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
// LifeAboutDialog
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
LifeAboutDialog::LifeAboutDialog(wxWindow *parent)
|
||||||
|
: wxDialog(parent, -1,
|
||||||
|
_("About Life!"),
|
||||||
|
wxDefaultPosition,
|
||||||
|
wxDefaultSize,
|
||||||
|
wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL)
|
||||||
|
{
|
||||||
|
// logo
|
||||||
|
wxBitmap bmp = wxBITMAP(life);
|
||||||
|
#if !defined(__WXGTK__) && !defined(__WXMOTIF__)
|
||||||
|
bmp.SetMask(new wxMask(bmp, *wxBLUE));
|
||||||
|
#endif
|
||||||
|
wxStaticBitmap *sbmp = new wxStaticBitmap(this, -1, bmp);
|
||||||
|
|
||||||
|
// layout components
|
||||||
|
wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
|
||||||
|
sizer->Add( sbmp, 0, wxCENTRE | wxALL, 10 );
|
||||||
|
sizer->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT, 5 );
|
||||||
|
sizer->Add( CreateTextSizer(_("Life! for wxWindows, version 2.0\n\n"
|
||||||
|
"(c) 2000 Guillermo Rodriguez Garcia\n\n"
|
||||||
|
"<guille@iies.es>\n\n"
|
||||||
|
"Portions of the code are based in XLife\n"
|
||||||
|
"XLife is (c) 1989 by Jon Bennett et al.")),
|
||||||
|
0, wxCENTRE | wxALL, 20 );
|
||||||
|
sizer->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT, 5 );
|
||||||
|
sizer->Add( CreateButtonSizer(wxOK), 0, wxCENTRE | wxALL, 10 );
|
||||||
|
|
||||||
|
// activate
|
||||||
|
SetSizer(sizer);
|
||||||
|
SetAutoLayout(TRUE);
|
||||||
|
sizer->SetSizeHints(this);
|
||||||
|
sizer->Fit(this);
|
||||||
|
Centre(wxBOTH | wxCENTRE_ON_SCREEN);
|
||||||
|
}
|
||||||
|
@@ -34,33 +34,6 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
|
|
||||||
// sample configurations
|
|
||||||
extern LifeShape g_shapes[];
|
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// LifeNewGameDialog
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// LifeSamplesDialog
|
// LifeSamplesDialog
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@@ -73,14 +46,14 @@ public:
|
|||||||
~LifeSamplesDialog();
|
~LifeSamplesDialog();
|
||||||
|
|
||||||
// members
|
// members
|
||||||
int GetValue();
|
const LifeShape& GetShape();
|
||||||
|
|
||||||
// event handlers
|
// event handlers
|
||||||
void OnListBox(wxCommandEvent &event);
|
void OnListBox(wxCommandEvent &event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// any class wishing to process wxWindows events must use this macro
|
// any class wishing to process wxWindows events must use this macro
|
||||||
DECLARE_EVENT_TABLE();
|
DECLARE_EVENT_TABLE()
|
||||||
|
|
||||||
int m_value;
|
int m_value;
|
||||||
wxListBox *m_list;
|
wxListBox *m_list;
|
||||||
@@ -89,4 +62,15 @@ private:
|
|||||||
Life *m_life;
|
Life *m_life;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
// LifeAboutDialog
|
||||||
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class LifeAboutDialog : public wxDialog
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// ctor
|
||||||
|
LifeAboutDialog(wxWindow *parent);
|
||||||
|
};
|
||||||
|
|
||||||
#endif // _LIFE_DIALOGS_H_
|
#endif // _LIFE_DIALOGS_H_
|
||||||
|
1406
demos/life/game.cpp
1406
demos/life/game.cpp
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// Name: game.h
|
// Name: game.h
|
||||||
// Purpose: Life! game logic
|
// Purpose: Life! game logic, version 2
|
||||||
// Author: Guillermo Rodriguez Garcia, <guille@iies.es>
|
// Author: Guillermo Rodriguez Garcia, <guille@iies.es>
|
||||||
// Modified by:
|
// Modified by:
|
||||||
// Created: Jan/2000
|
// Created: Jan/2000
|
||||||
@@ -29,41 +29,37 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// constants
|
// Cell
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
// minimum and maximum table size, in each dimension
|
// A Cell is just a struct which contains a pair of (i, j) coords.
|
||||||
#define LIFE_MIN 20
|
// These structs are not used internally anywhere; they are just
|
||||||
#define LIFE_MAX 200
|
// used to pass cell coordinates around.
|
||||||
|
struct Cell
|
||||||
// --------------------------------------------------------------------------
|
{
|
||||||
// Cell and CellArray;
|
wxInt32 i;
|
||||||
// --------------------------------------------------------------------------
|
wxInt32 j;
|
||||||
|
};
|
||||||
typedef long Cell;
|
|
||||||
typedef wxArrayLong CellArray;
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// LifeShape
|
// LifeShape
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// A class which holds a pattern
|
||||||
class LifeShape
|
class LifeShape
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LifeShape::LifeShape(wxString name,
|
LifeShape::LifeShape(wxString name,
|
||||||
wxString desc,
|
wxString desc,
|
||||||
int width, int height, char *data,
|
int width,
|
||||||
int fieldWidth = 20, int fieldHeight = 20,
|
int height,
|
||||||
bool wrap = TRUE)
|
char *data)
|
||||||
{
|
{
|
||||||
m_name = name;
|
m_name = name;
|
||||||
m_desc = desc;
|
m_desc = desc;
|
||||||
m_width = width;
|
m_width = width;
|
||||||
m_height = height;
|
m_height = height;
|
||||||
m_data = data;
|
m_data = data;
|
||||||
m_fieldWidth = fieldWidth;
|
|
||||||
m_fieldHeight = fieldHeight;
|
|
||||||
m_wrap = wrap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString m_name;
|
wxString m_name;
|
||||||
@@ -71,59 +67,77 @@ public:
|
|||||||
int m_width;
|
int m_width;
|
||||||
int m_height;
|
int m_height;
|
||||||
char *m_data;
|
char *m_data;
|
||||||
int m_fieldWidth;
|
|
||||||
int m_fieldHeight;
|
|
||||||
bool m_wrap;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// Life
|
// Life
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class CellBox;
|
||||||
|
|
||||||
class Life
|
class Life
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// ctor and dtor
|
// ctor and dtor
|
||||||
Life(int width, int height);
|
Life();
|
||||||
~Life();
|
~Life();
|
||||||
void Create(int width, int height);
|
|
||||||
void Destroy();
|
|
||||||
|
|
||||||
// game field
|
// accessors
|
||||||
inline int GetWidth() const { return m_width; };
|
inline wxUint32 GetNumCells() const { return m_numcells; };
|
||||||
inline int GetHeight() const { return m_height; };
|
bool IsAlive (wxInt32 x, wxInt32 y);
|
||||||
inline void SetBorderWrap(bool on) { m_wrap = on; };
|
void SetCell (wxInt32 x, wxInt32 y, bool alive = TRUE);
|
||||||
|
void SetShape(const LifeShape &shape);
|
||||||
|
|
||||||
// cells
|
// game control
|
||||||
bool IsAlive(int i, int j) const;
|
|
||||||
bool IsAlive(Cell c) const;
|
|
||||||
int GetX(Cell c) const;
|
|
||||||
int GetY(Cell c) const;
|
|
||||||
const CellArray* GetCells() const { return &m_cells; };
|
|
||||||
const CellArray* GetChangedCells() const { return &m_changed; };
|
|
||||||
|
|
||||||
// game logic
|
|
||||||
void Clear();
|
void Clear();
|
||||||
Cell SetCell(int i, int j, bool alive = TRUE);
|
|
||||||
void SetShape(LifeShape &shape);
|
|
||||||
bool NextTic();
|
bool NextTic();
|
||||||
|
|
||||||
|
// The following functions find cells within a given viewport; either
|
||||||
|
// all alive cells, or only those cells which have changed since last
|
||||||
|
// generation. You first call BeginFind() to specify the viewport,
|
||||||
|
// then keep calling FindMore() until it returns TRUE.
|
||||||
|
//
|
||||||
|
// BeginFind:
|
||||||
|
// Specify the viewport and whether to look for alive cells or for
|
||||||
|
// cells which have changed since the last generation and thus need
|
||||||
|
// to be repainted. In this latter case, there is no distinction
|
||||||
|
// between newborn or just-dead cells.
|
||||||
|
//
|
||||||
|
// FindMore:
|
||||||
|
// Fills an array with cells that match the specification given with
|
||||||
|
// BeginFind(). The array itself belongs to the Life object and must
|
||||||
|
// not be modified or freed by the caller. If this function returns
|
||||||
|
// FALSE, then the operation is not complete: just process all cells
|
||||||
|
// and call FillMore() again.
|
||||||
|
//
|
||||||
|
void BeginFind(wxInt32 i0, wxInt32 j0,
|
||||||
|
wxInt32 i1, wxInt32 j1,
|
||||||
|
bool changed);
|
||||||
|
bool FindMore(Cell *cells[], size_t *ncells);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int GetNeighbors(int i, int j) const;
|
// cellbox-related
|
||||||
inline Cell MakeCell(int i, int j, bool alive) const;
|
CellBox *CreateBox(wxInt32 x, wxInt32 y, wxUint32 hv);
|
||||||
|
CellBox *LinkBox(wxInt32 x, wxInt32 y, bool create = TRUE);
|
||||||
|
void KillBox(CellBox *c);
|
||||||
|
|
||||||
enum CellFlags
|
// helpers for FindMore & co.
|
||||||
{
|
void DoLine(wxInt32 i, wxInt32 j, wxUint32 alive, wxUint32 old);
|
||||||
CELL_DEAD = 0x0000, // is dead
|
void DoLine(wxInt32 i, wxInt32 j, wxUint32 alive);
|
||||||
CELL_ALIVE = 0x0001, // is alive
|
|
||||||
CELL_MARK = 0x0002, // will change / has changed
|
|
||||||
};
|
|
||||||
|
|
||||||
int m_width;
|
|
||||||
int m_height;
|
CellBox *m_head; // list of alive boxes
|
||||||
CellArray m_cells;
|
CellBox *m_available; // list of reusable dead boxes
|
||||||
CellArray m_changed;
|
CellBox **m_boxes; // hash table of alive boxes
|
||||||
bool m_wrap;
|
wxUint32 m_numcells; // population (number of alive cells)
|
||||||
|
Cell *m_cells; // cell array for FindMore()
|
||||||
|
size_t m_ncells; // number of valid cells in cell array
|
||||||
|
wxInt32 m_i, m_j, // state vars for FindMore()
|
||||||
|
m_i0, m_j0,
|
||||||
|
m_i1, m_j1;
|
||||||
|
bool m_changed;
|
||||||
|
bool m_findmore;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _LIFE_GAME_H_
|
#endif // _LIFE_GAME_H_
|
||||||
|
@@ -10,29 +10,13 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// declarations
|
// headers, declarations, constants
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
// headers
|
|
||||||
// --------------------------------------------------------------------------
|
|
||||||
|
|
||||||
#ifdef __GNUG__
|
#ifdef __GNUG__
|
||||||
#pragma implementation "life.h"
|
#pragma implementation "life.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// for compilers that support precompilation, includes "wx/wx.h"
|
|
||||||
#include "wx/wxprec.h"
|
|
||||||
|
|
||||||
#ifdef __BORLANDC__
|
|
||||||
#pragma hdrstop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// for all others, include the necessary headers
|
|
||||||
#ifndef WX_PRECOMP
|
|
||||||
#include "wx/wx.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "wx/statline.h"
|
#include "wx/statline.h"
|
||||||
|
|
||||||
#include "life.h"
|
#include "life.h"
|
||||||
@@ -51,6 +35,8 @@
|
|||||||
#include "bitmaps/reset.xpm"
|
#include "bitmaps/reset.xpm"
|
||||||
#include "bitmaps/play.xpm"
|
#include "bitmaps/play.xpm"
|
||||||
#include "bitmaps/stop.xpm"
|
#include "bitmaps/stop.xpm"
|
||||||
|
#include "bitmaps/zoomin.xpm"
|
||||||
|
#include "bitmaps/zoomout.xpm"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@@ -61,15 +47,17 @@
|
|||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
// menu items and toolbar buttons
|
// menu items and toolbar buttons
|
||||||
ID_NEWGAME = 1001,
|
ID_RESET = 1001,
|
||||||
ID_SAMPLES,
|
ID_SAMPLES,
|
||||||
ID_ABOUT,
|
ID_ABOUT,
|
||||||
ID_EXIT,
|
ID_EXIT,
|
||||||
ID_CLEAR,
|
ID_CENTER,
|
||||||
ID_START,
|
ID_START,
|
||||||
ID_STEP,
|
ID_STEP,
|
||||||
ID_STOP,
|
ID_STOP,
|
||||||
ID_WRAP,
|
ID_ZOOMIN,
|
||||||
|
ID_ZOOMOUT,
|
||||||
|
ID_TOPSPEED,
|
||||||
|
|
||||||
// speed selection slider
|
// speed selection slider
|
||||||
ID_SLIDER
|
ID_SLIDER
|
||||||
@@ -81,44 +69,49 @@ enum
|
|||||||
|
|
||||||
// Event tables
|
// Event tables
|
||||||
BEGIN_EVENT_TABLE(LifeFrame, wxFrame)
|
BEGIN_EVENT_TABLE(LifeFrame, wxFrame)
|
||||||
EVT_MENU (ID_NEWGAME, LifeFrame::OnNewGame)
|
|
||||||
EVT_MENU (ID_SAMPLES, LifeFrame::OnSamples)
|
EVT_MENU (ID_SAMPLES, LifeFrame::OnSamples)
|
||||||
|
EVT_MENU (ID_RESET, LifeFrame::OnMenu)
|
||||||
EVT_MENU (ID_ABOUT, LifeFrame::OnMenu)
|
EVT_MENU (ID_ABOUT, LifeFrame::OnMenu)
|
||||||
EVT_MENU (ID_EXIT, LifeFrame::OnMenu)
|
EVT_MENU (ID_EXIT, LifeFrame::OnMenu)
|
||||||
EVT_MENU (ID_CLEAR, LifeFrame::OnMenu)
|
EVT_MENU (ID_CENTER, LifeFrame::OnMenu)
|
||||||
EVT_MENU (ID_START, LifeFrame::OnMenu)
|
EVT_MENU (ID_START, LifeFrame::OnMenu)
|
||||||
EVT_MENU (ID_STEP, LifeFrame::OnMenu)
|
EVT_MENU (ID_STEP, LifeFrame::OnMenu)
|
||||||
EVT_MENU (ID_STOP, LifeFrame::OnMenu)
|
EVT_MENU (ID_STOP, LifeFrame::OnMenu)
|
||||||
EVT_MENU (ID_WRAP, LifeFrame::OnMenu)
|
EVT_MENU (ID_ZOOMIN, LifeFrame::OnMenu)
|
||||||
|
EVT_MENU (ID_ZOOMOUT, LifeFrame::OnMenu)
|
||||||
|
EVT_MENU (ID_TOPSPEED, LifeFrame::OnMenu)
|
||||||
EVT_COMMAND_SCROLL (ID_SLIDER, LifeFrame::OnSlider)
|
EVT_COMMAND_SCROLL (ID_SLIDER, LifeFrame::OnSlider)
|
||||||
|
EVT_CLOSE ( LifeFrame::OnClose)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(LifeCanvas, wxScrolledWindow)
|
BEGIN_EVENT_TABLE(LifeCanvas, wxWindow)
|
||||||
EVT_PAINT ( LifeCanvas::OnPaint)
|
EVT_PAINT ( LifeCanvas::OnPaint)
|
||||||
|
EVT_SCROLLWIN ( LifeCanvas::OnScroll)
|
||||||
EVT_SIZE ( LifeCanvas::OnSize)
|
EVT_SIZE ( LifeCanvas::OnSize)
|
||||||
EVT_MOUSE_EVENTS ( LifeCanvas::OnMouse)
|
EVT_MOUSE_EVENTS ( LifeCanvas::OnMouse)
|
||||||
|
EVT_ERASE_BACKGROUND( LifeCanvas::OnEraseBackground)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
|
||||||
// Create a new application object
|
// Create a new application object
|
||||||
IMPLEMENT_APP(LifeApp)
|
IMPLEMENT_APP(LifeApp)
|
||||||
|
|
||||||
|
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// implementation
|
// implementation
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
// some shortcuts
|
// some shortcuts
|
||||||
#define ADD_TOOL(a, b, c, d) \
|
#define ADD_TOOL(id, bmp, tooltip, help) \
|
||||||
toolBar->AddTool(a, b, wxNullBitmap, FALSE, -1, -1, (wxObject *)0, c, d)
|
toolBar->AddTool(id, bmp, wxNullBitmap, FALSE, -1, -1, (wxObject *)0, tooltip, help)
|
||||||
|
|
||||||
#define GET_FRAME() \
|
#define GET_FRAME() ((LifeFrame *) wxGetApp().GetTopWindow())
|
||||||
((LifeFrame *) wxGetApp().GetTopWindow())
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// LifeApp
|
// LifeApp
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
// `Main program' equivalent: the program execution "starts" here
|
// 'Main program' equivalent: the program execution "starts" here
|
||||||
bool LifeApp::OnInit()
|
bool LifeApp::OnInit()
|
||||||
{
|
{
|
||||||
// create the main application window
|
// create the main application window
|
||||||
@@ -146,21 +139,23 @@ LifeFrame::LifeFrame() : wxFrame((wxFrame *)0, -1, _("Life!"), wxPoint(50, 50))
|
|||||||
wxMenu *menuFile = new wxMenu("", wxMENU_TEAROFF);
|
wxMenu *menuFile = new wxMenu("", wxMENU_TEAROFF);
|
||||||
wxMenu *menuGame = new wxMenu("", wxMENU_TEAROFF);
|
wxMenu *menuGame = new wxMenu("", wxMENU_TEAROFF);
|
||||||
|
|
||||||
menuFile->Append(ID_NEWGAME, _("New game..."), _("Start a new game"));
|
menuFile->Append(ID_RESET, _("Reset"), _("Start a new game"));
|
||||||
menuFile->Append(ID_SAMPLES, _("Sample game..."), _("Select a sample configuration"));
|
menuFile->Append(ID_SAMPLES, _("Sample game..."), _("Select a sample configuration"));
|
||||||
menuFile->AppendSeparator();
|
menuFile->AppendSeparator();
|
||||||
menuFile->Append(ID_ABOUT, _("&About...\tCtrl-A"), _("Show about dialog"));
|
menuFile->Append(ID_ABOUT, _("&About...\tCtrl-A"), _("Show about dialog"));
|
||||||
menuFile->AppendSeparator();
|
menuFile->AppendSeparator();
|
||||||
menuFile->Append(ID_EXIT, _("E&xit\tAlt-X"), _("Quit this program"));
|
menuFile->Append(ID_EXIT, _("E&xit\tAlt-X"), _("Quit this program"));
|
||||||
|
|
||||||
menuGame->Append(ID_CLEAR, _("&Clear\tCtrl-C"), _("Clear game field"));
|
menuGame->Append(ID_CENTER, _("Re¢er\tCtrl-C"), _("Go to (0, 0)"));
|
||||||
menuGame->Append(ID_START, _("&Start\tCtrl-S"), _("Start"));
|
menuGame->Append(ID_START, _("&Start\tCtrl-S"), _("Start"));
|
||||||
menuGame->Append(ID_STEP, _("&Next\tCtrl-N"), _("Single step"));
|
menuGame->Append(ID_STEP, _("&Next\tCtrl-N"), _("Single step"));
|
||||||
menuGame->Append(ID_STOP, _("S&top\tCtrl-T"), _("Stop"));
|
menuGame->Append(ID_STOP, _("S&top\tCtrl-T"), _("Stop"));
|
||||||
menuGame->Enable(ID_STOP, FALSE);
|
menuGame->Enable(ID_STOP, FALSE);
|
||||||
menuGame->AppendSeparator();
|
menuGame->AppendSeparator();
|
||||||
menuGame->Append(ID_WRAP, _("&Wraparound\tCtrl-W"), _("Wrap around borders"), TRUE);
|
menuGame->Append(ID_TOPSPEED, _("Top speed!"), _("Go as fast as possible"));
|
||||||
menuGame->Check (ID_WRAP, TRUE);
|
menuGame->AppendSeparator();
|
||||||
|
menuGame->Append(ID_ZOOMIN, _("Zoom &in\tCtrl-I"));
|
||||||
|
menuGame->Append(ID_ZOOMOUT, _("Zoom &out\tCtrl-O"));
|
||||||
|
|
||||||
wxMenuBar *menuBar = new wxMenuBar();
|
wxMenuBar *menuBar = new wxMenuBar();
|
||||||
menuBar->Append(menuFile, _("&File"));
|
menuBar->Append(menuFile, _("&File"));
|
||||||
@@ -168,36 +163,43 @@ LifeFrame::LifeFrame() : wxFrame((wxFrame *)0, -1, _("Life!"), wxPoint(50, 50))
|
|||||||
SetMenuBar(menuBar);
|
SetMenuBar(menuBar);
|
||||||
|
|
||||||
// tool bar
|
// tool bar
|
||||||
wxBitmap tbBitmaps[3];
|
wxBitmap tbBitmaps[5];
|
||||||
|
|
||||||
tbBitmaps[0] = wxBITMAP(reset);
|
tbBitmaps[0] = wxBITMAP(reset);
|
||||||
tbBitmaps[1] = wxBITMAP(play);
|
tbBitmaps[1] = wxBITMAP(play);
|
||||||
tbBitmaps[2] = wxBITMAP(stop);
|
tbBitmaps[2] = wxBITMAP(stop);
|
||||||
|
tbBitmaps[3] = wxBITMAP(zoomin);
|
||||||
|
tbBitmaps[4] = wxBITMAP(zoomout);
|
||||||
|
|
||||||
wxToolBar *toolBar = CreateToolBar();
|
wxToolBar *toolBar = CreateToolBar();
|
||||||
toolBar->SetMargins(5, 5);
|
toolBar->SetMargins(5, 5);
|
||||||
toolBar->SetToolBitmapSize(wxSize(16, 16));
|
toolBar->SetToolBitmapSize(wxSize(16, 16));
|
||||||
ADD_TOOL(ID_CLEAR, tbBitmaps[0], _("Clear"), _("Clear game board"));
|
ADD_TOOL(ID_RESET, tbBitmaps[0], _("Reset"), _("Start a new game"));
|
||||||
ADD_TOOL(ID_START, tbBitmaps[1], _("Start"), _("Start"));
|
ADD_TOOL(ID_START, tbBitmaps[1], _("Start"), _("Start"));
|
||||||
ADD_TOOL(ID_STOP , tbBitmaps[2], _("Stop"), _("Stop"));
|
ADD_TOOL(ID_STOP, tbBitmaps[2], _("Stop"), _("Stop"));
|
||||||
toolBar->EnableTool(ID_STOP, FALSE);
|
toolBar->AddSeparator();
|
||||||
|
ADD_TOOL(ID_ZOOMIN, tbBitmaps[3], _("Zoom in"), _("Zoom in"));
|
||||||
|
ADD_TOOL(ID_ZOOMOUT, tbBitmaps[4], _("Zoom out"), _("Zoom out"));
|
||||||
toolBar->Realize();
|
toolBar->Realize();
|
||||||
|
toolBar->EnableTool(ID_STOP, FALSE); // must be after Realize() !
|
||||||
|
|
||||||
// status bar
|
// status bar
|
||||||
CreateStatusBar(2);
|
CreateStatusBar(2);
|
||||||
SetStatusText(_("Welcome to Life!"));
|
SetStatusText(_("Welcome to Life!"));
|
||||||
|
|
||||||
// game
|
// game and canvas
|
||||||
wxPanel *panel = new wxPanel(this, -1);
|
wxPanel *panel = new wxPanel(this, -1);
|
||||||
m_life = new Life(20, 20);
|
m_life = new Life();
|
||||||
m_canvas = new LifeCanvas(panel, m_life);
|
m_canvas = new LifeCanvas(panel, m_life);
|
||||||
m_timer = new LifeTimer();
|
m_timer = new LifeTimer();
|
||||||
|
m_running = FALSE;
|
||||||
|
m_topspeed = FALSE;
|
||||||
m_interval = 500;
|
m_interval = 500;
|
||||||
m_tics = 0;
|
m_tics = 0;
|
||||||
m_text = new wxStaticText(panel, -1, "");
|
m_text = new wxStaticText(panel, -1, "");
|
||||||
UpdateInfoText();
|
UpdateInfoText();
|
||||||
|
|
||||||
// slider
|
// speed selection slider
|
||||||
wxSlider *slider = new wxSlider(panel, ID_SLIDER,
|
wxSlider *slider = new wxSlider(panel, ID_SLIDER,
|
||||||
5, 1, 10,
|
5, 1, 10,
|
||||||
wxDefaultPosition,
|
wxDefaultPosition,
|
||||||
@@ -220,49 +222,80 @@ LifeFrame::LifeFrame() : wxFrame((wxFrame *)0, -1, _("Life!"), wxPoint(50, 50))
|
|||||||
LifeFrame::~LifeFrame()
|
LifeFrame::~LifeFrame()
|
||||||
{
|
{
|
||||||
delete m_timer;
|
delete m_timer;
|
||||||
delete m_life;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LifeFrame::UpdateInfoText()
|
void LifeFrame::UpdateInfoText()
|
||||||
{
|
{
|
||||||
wxString msg;
|
wxString msg;
|
||||||
|
|
||||||
msg.Printf(_("Generation: %u, Interval: %u ms"), m_tics, m_interval);
|
msg.Printf(_(" Generation: %u (T: %u ms), Population: %u "),
|
||||||
|
m_tics,
|
||||||
|
m_topspeed? 0 : m_interval,
|
||||||
|
m_life->GetNumCells());
|
||||||
m_text->SetLabel(msg);
|
m_text->SetLabel(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enable or disable tools and menu entries according to the current
|
||||||
|
// state. See also wxEVT_UPDATE_UI events for a slightly different
|
||||||
|
// way to do this.
|
||||||
|
void LifeFrame::UpdateUI()
|
||||||
|
{
|
||||||
|
GetToolBar()->EnableTool(ID_START, !m_running);
|
||||||
|
GetToolBar()->EnableTool(ID_STOP, m_running);
|
||||||
|
GetMenuBar()->GetMenu(1)->Enable(ID_START, !m_running);
|
||||||
|
GetMenuBar()->GetMenu(1)->Enable(ID_STEP, !m_running);
|
||||||
|
GetMenuBar()->GetMenu(1)->Enable(ID_STOP, m_running);
|
||||||
|
}
|
||||||
|
|
||||||
// event handlers
|
// event handlers
|
||||||
void LifeFrame::OnMenu(wxCommandEvent& event)
|
void LifeFrame::OnMenu(wxCommandEvent& event)
|
||||||
{
|
{
|
||||||
switch (event.GetId())
|
switch (event.GetId())
|
||||||
{
|
{
|
||||||
|
case ID_CENTER : m_canvas->Recenter(0, 0); break;
|
||||||
case ID_START : OnStart(); break;
|
case ID_START : OnStart(); break;
|
||||||
case ID_STEP : OnTimer(); break;
|
case ID_STEP : OnTimer(); break;
|
||||||
case ID_STOP : OnStop(); break;
|
case ID_STOP : OnStop(); break;
|
||||||
case ID_WRAP :
|
case ID_ZOOMIN :
|
||||||
{
|
{
|
||||||
bool checked = GetMenuBar()->GetMenu(1)->IsChecked(ID_WRAP);
|
int cellsize = m_canvas->GetCellSize();
|
||||||
m_life->SetBorderWrap(checked);
|
if (cellsize < 32)
|
||||||
|
m_canvas->SetCellSize(cellsize * 2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ID_CLEAR :
|
case ID_ZOOMOUT :
|
||||||
{
|
{
|
||||||
|
int cellsize = m_canvas->GetCellSize();
|
||||||
|
if (cellsize > 1)
|
||||||
|
m_canvas->SetCellSize(cellsize / 2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ID_TOPSPEED:
|
||||||
|
{
|
||||||
|
m_running = TRUE;
|
||||||
|
m_topspeed = TRUE;
|
||||||
|
UpdateUI();
|
||||||
|
while (m_running && m_topspeed)
|
||||||
|
{
|
||||||
|
OnTimer();
|
||||||
|
wxYield();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ID_RESET:
|
||||||
|
{
|
||||||
|
// stop if it was running
|
||||||
OnStop();
|
OnStop();
|
||||||
m_life->Clear();
|
m_life->Clear();
|
||||||
m_canvas->DrawEverything(TRUE);
|
m_canvas->Recenter(0, 0);
|
||||||
m_canvas->Refresh(FALSE);
|
|
||||||
m_tics = 0;
|
m_tics = 0;
|
||||||
UpdateInfoText();
|
UpdateInfoText();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ID_ABOUT :
|
case ID_ABOUT:
|
||||||
{
|
{
|
||||||
wxMessageBox(
|
LifeAboutDialog dialog(this);
|
||||||
_("This is the about dialog of the Life! sample.\n"
|
dialog.ShowModal();
|
||||||
"(c) 2000 Guillermo Rodriguez Garcia"),
|
|
||||||
_("About Life!"),
|
|
||||||
wxOK | wxICON_INFORMATION,
|
|
||||||
this);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ID_EXIT :
|
case ID_EXIT :
|
||||||
@@ -274,42 +307,14 @@ void LifeFrame::OnMenu(wxCommandEvent& event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LifeFrame::OnNewGame(wxCommandEvent& WXUNUSED(event))
|
void LifeFrame::OnClose(wxCloseEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
int w = m_life->GetWidth();
|
// Stop if it was running; this is absolutely needed because
|
||||||
int h = m_life->GetHeight();
|
// the frame won't be actually destroyed until there are no
|
||||||
|
// more pending events, and this in turn won't ever happen
|
||||||
// stop if it was running
|
// if the timer is running faster than the window can redraw.
|
||||||
OnStop();
|
OnStop();
|
||||||
|
Destroy();
|
||||||
// dialog box
|
|
||||||
LifeNewGameDialog dialog(this, &w, &h);
|
|
||||||
|
|
||||||
// new game?
|
|
||||||
if (dialog.ShowModal() == wxID_OK)
|
|
||||||
{
|
|
||||||
// check dimensions
|
|
||||||
if (w >= LIFE_MIN && w <= LIFE_MAX &&
|
|
||||||
h >= LIFE_MIN && h <= LIFE_MAX)
|
|
||||||
{
|
|
||||||
// resize game field
|
|
||||||
m_life->Destroy();
|
|
||||||
m_life->Create(w, h);
|
|
||||||
|
|
||||||
// tell the canvas
|
|
||||||
m_canvas->Reset();
|
|
||||||
m_canvas->Refresh();
|
|
||||||
m_tics = 0;
|
|
||||||
UpdateInfoText();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxString msg;
|
|
||||||
msg.Printf(_("Both dimensions must be within %u and %u.\n"),
|
|
||||||
LIFE_MIN, LIFE_MAX);
|
|
||||||
wxMessageBox(msg, _("Error!"), wxOK | wxICON_EXCLAMATION, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LifeFrame::OnSamples(wxCommandEvent& WXUNUSED(event))
|
void LifeFrame::OnSamples(wxCommandEvent& WXUNUSED(event))
|
||||||
@@ -323,40 +328,14 @@ void LifeFrame::OnSamples(wxCommandEvent& WXUNUSED(event))
|
|||||||
// new game?
|
// new game?
|
||||||
if (dialog.ShowModal() == wxID_OK)
|
if (dialog.ShowModal() == wxID_OK)
|
||||||
{
|
{
|
||||||
int result = dialog.GetValue();
|
const LifeShape shape = dialog.GetShape();
|
||||||
|
|
||||||
if (result == -1)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int gw = g_shapes[result].m_fieldWidth;
|
|
||||||
int gh = g_shapes[result].m_fieldHeight;
|
|
||||||
int wrap = g_shapes[result].m_wrap;
|
|
||||||
|
|
||||||
// set wraparound (don't ask the user)
|
|
||||||
m_life->SetBorderWrap(wrap);
|
|
||||||
GetMenuBar()->GetMenu(1)->Check(ID_WRAP, wrap);
|
|
||||||
|
|
||||||
// need to resize the game field?
|
|
||||||
if (gw > m_life->GetWidth() || gh > m_life->GetHeight())
|
|
||||||
{
|
|
||||||
wxString s;
|
|
||||||
s.Printf(_("Your game field is too small for this configuration.\n"
|
|
||||||
"It is recommended to resize it to %u x %u. Proceed?\n"),
|
|
||||||
gw, gh);
|
|
||||||
|
|
||||||
if (wxMessageBox(s, _("Question"), wxYES_NO | wxICON_QUESTION, this) == wxYES)
|
|
||||||
{
|
|
||||||
m_life->Destroy();
|
|
||||||
m_life->Create(gw, gh);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// put the shape
|
// put the shape
|
||||||
m_life->SetShape(g_shapes[result]);
|
m_life->Clear();
|
||||||
|
m_life->SetShape(shape);
|
||||||
|
|
||||||
// tell the canvas about the change
|
// recenter canvas
|
||||||
m_canvas->Reset();
|
m_canvas->Recenter(0, 0);
|
||||||
m_canvas->Refresh();
|
|
||||||
m_tics = 0;
|
m_tics = 0;
|
||||||
UpdateInfoText();
|
UpdateInfoText();
|
||||||
}
|
}
|
||||||
@@ -366,14 +345,9 @@ void LifeFrame::OnStart()
|
|||||||
{
|
{
|
||||||
if (!m_running)
|
if (!m_running)
|
||||||
{
|
{
|
||||||
GetToolBar()->EnableTool(ID_START, FALSE);
|
|
||||||
GetToolBar()->EnableTool(ID_STOP, TRUE);
|
|
||||||
GetMenuBar()->GetMenu(1)->Enable(ID_START, FALSE);
|
|
||||||
GetMenuBar()->GetMenu(1)->Enable(ID_STEP, FALSE);
|
|
||||||
GetMenuBar()->GetMenu(1)->Enable(ID_STOP, TRUE);
|
|
||||||
|
|
||||||
m_timer->Start(m_interval);
|
m_timer->Start(m_interval);
|
||||||
m_running = TRUE;
|
m_running = TRUE;
|
||||||
|
UpdateUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,14 +355,10 @@ void LifeFrame::OnStop()
|
|||||||
{
|
{
|
||||||
if (m_running)
|
if (m_running)
|
||||||
{
|
{
|
||||||
GetToolBar()->EnableTool(ID_START, TRUE);
|
|
||||||
GetToolBar()->EnableTool(ID_STOP, FALSE);
|
|
||||||
GetMenuBar()->GetMenu(1)->Enable(ID_START, TRUE);
|
|
||||||
GetMenuBar()->GetMenu(1)->Enable(ID_STEP, TRUE);
|
|
||||||
GetMenuBar()->GetMenu(1)->Enable(ID_STOP, FALSE);
|
|
||||||
|
|
||||||
m_timer->Stop();
|
m_timer->Stop();
|
||||||
m_running = FALSE;
|
m_running = FALSE;
|
||||||
|
m_topspeed = FALSE;
|
||||||
|
UpdateUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,20 +369,18 @@ void LifeFrame::OnTimer()
|
|||||||
else
|
else
|
||||||
OnStop();
|
OnStop();
|
||||||
|
|
||||||
|
m_canvas->DrawChanged();
|
||||||
UpdateInfoText();
|
UpdateInfoText();
|
||||||
m_canvas->DrawEverything();
|
|
||||||
m_canvas->Refresh(FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LifeFrame::OnSlider(wxScrollEvent& event)
|
void LifeFrame::OnSlider(wxScrollEvent& event)
|
||||||
{
|
{
|
||||||
m_interval = event.GetPosition() * 100;
|
m_interval = event.GetPosition() * 100;
|
||||||
|
|
||||||
// restart timer if running, to set the new interval
|
|
||||||
if (m_running)
|
if (m_running)
|
||||||
{
|
{
|
||||||
m_timer->Stop();
|
OnStop();
|
||||||
m_timer->Start(m_interval);
|
OnStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateInfoText();
|
UpdateInfoText();
|
||||||
@@ -433,129 +401,209 @@ void LifeTimer::Notify()
|
|||||||
|
|
||||||
// canvas constructor
|
// canvas constructor
|
||||||
LifeCanvas::LifeCanvas(wxWindow *parent, Life *life, bool interactive)
|
LifeCanvas::LifeCanvas(wxWindow *parent, Life *life, bool interactive)
|
||||||
: wxScrolledWindow(parent, -1, wxPoint(0, 0), wxSize(100, 100))
|
: wxWindow(parent, -1, wxPoint(0, 0), wxSize(100, 100),
|
||||||
|
wxSUNKEN_BORDER)
|
||||||
{
|
{
|
||||||
m_life = life;
|
m_life = life;
|
||||||
m_interactive = interactive;
|
m_interactive = interactive;
|
||||||
m_cellsize = 8;
|
m_cellsize = 8;
|
||||||
m_bmp = NULL;
|
m_status = MOUSE_NOACTION;
|
||||||
Reset();
|
m_viewportX = 0;
|
||||||
|
m_viewportY = 0;
|
||||||
|
m_viewportH = 0;
|
||||||
|
m_viewportW = 0;
|
||||||
|
|
||||||
|
if (m_interactive)
|
||||||
|
SetCursor(*wxCROSS_CURSOR);
|
||||||
|
|
||||||
|
// reduce flicker if wxEVT_ERASE_BACKGROUND is not available
|
||||||
|
SetBackgroundColour(*wxWHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
LifeCanvas::~LifeCanvas()
|
LifeCanvas::~LifeCanvas()
|
||||||
{
|
{
|
||||||
delete m_bmp;
|
delete m_life;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LifeCanvas::Reset()
|
// recenter at the given position
|
||||||
|
void LifeCanvas::Recenter(wxInt32 i, wxInt32 j)
|
||||||
{
|
{
|
||||||
if (m_bmp)
|
m_viewportX = i - m_viewportW / 2;
|
||||||
delete m_bmp;
|
m_viewportY = j - m_viewportH / 2;
|
||||||
|
|
||||||
m_status = MOUSE_NOACTION;
|
|
||||||
m_width = CellToCoord(m_life->GetWidth()) + 1;
|
|
||||||
m_height = CellToCoord(m_life->GetHeight()) + 1;
|
|
||||||
m_bmp = new wxBitmap(m_width, m_height);
|
|
||||||
wxCoord w = GetClientSize().GetX();
|
|
||||||
wxCoord h = GetClientSize().GetY();
|
|
||||||
m_xoffset = (w > m_width)? ((w - m_width) / 2) : 0;
|
|
||||||
m_yoffset = (h > m_height)? ((h - m_height) / 2) : 0;
|
|
||||||
|
|
||||||
// redraw everything
|
// redraw everything
|
||||||
DrawEverything(TRUE);
|
Refresh(FALSE);
|
||||||
SetScrollbars(10, 10, (m_width + 9) / 10, (m_height + 9) / 10);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LifeCanvas::DrawEverything(bool force)
|
// set the cell size and refresh display
|
||||||
|
void LifeCanvas::SetCellSize(int cellsize)
|
||||||
{
|
{
|
||||||
wxMemoryDC dc;
|
m_cellsize = cellsize;
|
||||||
|
|
||||||
dc.SelectObject(*m_bmp);
|
// find current center
|
||||||
dc.BeginDrawing();
|
wxInt32 cx = m_viewportX + m_viewportW / 2;
|
||||||
|
wxInt32 cy = m_viewportY + m_viewportH / 2;
|
||||||
|
|
||||||
// draw cells
|
// get current canvas size and adjust viewport accordingly
|
||||||
const CellArray *cells =
|
wxCoord w, h;
|
||||||
force? m_life->GetCells() : m_life->GetChangedCells();
|
GetClientSize(&w, &h);
|
||||||
|
m_viewportW = (w + m_cellsize - 1) / m_cellsize;
|
||||||
|
m_viewportH = (h + m_cellsize - 1) / m_cellsize;
|
||||||
|
|
||||||
for (unsigned i = 0; i < cells->GetCount(); i++)
|
// recenter
|
||||||
DrawCell(cells->Item(i), dc);
|
m_viewportX = cx - m_viewportW / 2;
|
||||||
|
m_viewportY = cy - m_viewportH / 2;
|
||||||
|
|
||||||
// bounding rectangle (always drawn - better than clipping region)
|
// adjust scrollbars
|
||||||
dc.SetPen(*wxBLACK_PEN);
|
if (m_interactive)
|
||||||
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
|
||||||
dc.DrawRectangle(0, 0, m_width, m_height);
|
|
||||||
|
|
||||||
dc.EndDrawing();
|
|
||||||
dc.SelectObject(wxNullBitmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LifeCanvas::DrawCell(Cell c)
|
|
||||||
{
|
|
||||||
wxMemoryDC dc;
|
|
||||||
|
|
||||||
dc.SelectObject(*m_bmp);
|
|
||||||
dc.BeginDrawing();
|
|
||||||
|
|
||||||
dc.SetClippingRegion(1, 1, m_width - 2, m_height - 2);
|
|
||||||
DrawCell(c, dc);
|
|
||||||
|
|
||||||
dc.EndDrawing();
|
|
||||||
dc.SelectObject(wxNullBitmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LifeCanvas::DrawCell(Cell c, wxDC &dc)
|
|
||||||
{
|
|
||||||
if (m_life->IsAlive(c))
|
|
||||||
{
|
{
|
||||||
|
SetScrollbar(wxHORIZONTAL, m_viewportW, m_viewportW, 3 * m_viewportW);
|
||||||
|
SetScrollbar(wxVERTICAL, m_viewportH, m_viewportH, 3 * m_viewportH);
|
||||||
|
m_thumbX = m_viewportW;
|
||||||
|
m_thumbY = m_viewportH;
|
||||||
|
}
|
||||||
|
|
||||||
|
Refresh(FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw a cell
|
||||||
|
void LifeCanvas::DrawCell(wxInt32 i, wxInt32 j, bool alive)
|
||||||
|
{
|
||||||
|
wxClientDC dc(this);
|
||||||
|
|
||||||
|
dc.SetPen(alive? *wxBLACK_PEN : *wxWHITE_PEN);
|
||||||
|
dc.SetBrush(alive? *wxBLACK_BRUSH : *wxWHITE_BRUSH);
|
||||||
|
|
||||||
|
dc.BeginDrawing();
|
||||||
|
DrawCell(i, j, dc);
|
||||||
|
dc.EndDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LifeCanvas::DrawCell(wxInt32 i, wxInt32 j, wxDC &dc)
|
||||||
|
{
|
||||||
|
wxCoord x = CellToX(i);
|
||||||
|
wxCoord y = CellToY(j);
|
||||||
|
|
||||||
|
// if cellsize is 1 or 2, there will be no grid
|
||||||
|
switch (m_cellsize)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
dc.DrawPoint(x, y);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
dc.DrawRectangle(x, y, 2, 2);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dc.DrawRectangle(x + 1, y + 1, m_cellsize - 1, m_cellsize - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw all changed cells
|
||||||
|
void LifeCanvas::DrawChanged()
|
||||||
|
{
|
||||||
|
wxClientDC dc(this);
|
||||||
|
|
||||||
|
size_t ncells;
|
||||||
|
Cell *cells;
|
||||||
|
bool done = FALSE;
|
||||||
|
|
||||||
|
m_life->BeginFind(m_viewportX,
|
||||||
|
m_viewportY,
|
||||||
|
m_viewportX + m_viewportW,
|
||||||
|
m_viewportY + m_viewportH,
|
||||||
|
TRUE);
|
||||||
|
|
||||||
|
dc.BeginDrawing();
|
||||||
|
dc.SetLogicalFunction(wxINVERT);
|
||||||
|
|
||||||
|
if (m_cellsize == 1)
|
||||||
|
{
|
||||||
|
// drawn using DrawPoint
|
||||||
dc.SetPen(*wxBLACK_PEN);
|
dc.SetPen(*wxBLACK_PEN);
|
||||||
dc.SetBrush(*wxBLACK_BRUSH);
|
|
||||||
dc.DrawRectangle(CellToCoord( m_life->GetX(c) ),
|
|
||||||
CellToCoord( m_life->GetY(c) ),
|
|
||||||
m_cellsize,
|
|
||||||
m_cellsize);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dc.SetPen(*wxLIGHT_GREY_PEN);
|
// drawn using DrawRectangle
|
||||||
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
||||||
dc.DrawRectangle(CellToCoord( m_life->GetX(c) ),
|
dc.SetBrush(*wxBLACK_BRUSH);
|
||||||
CellToCoord( m_life->GetY(c) ),
|
|
||||||
m_cellsize,
|
|
||||||
m_cellsize);
|
|
||||||
dc.SetPen(*wxWHITE_PEN);
|
|
||||||
dc.SetBrush(*wxWHITE_BRUSH);
|
|
||||||
dc.DrawRectangle(CellToCoord( m_life->GetX(c) ) + 1,
|
|
||||||
CellToCoord( m_life->GetY(c) ) + 1,
|
|
||||||
m_cellsize - 1,
|
|
||||||
m_cellsize - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (!done)
|
||||||
|
{
|
||||||
|
done = m_life->FindMore(&cells, &ncells);
|
||||||
|
|
||||||
|
for (size_t m = 0; m < ncells; m++)
|
||||||
|
DrawCell(cells[m].i, cells[m].j, dc);
|
||||||
|
}
|
||||||
|
dc.EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
// event handlers
|
// event handlers
|
||||||
void LifeCanvas::OnPaint(wxPaintEvent& event)
|
void LifeCanvas::OnPaint(wxPaintEvent& event)
|
||||||
{
|
{
|
||||||
wxPaintDC dc(this);
|
wxPaintDC dc(this);
|
||||||
wxMemoryDC memdc;
|
wxRect rect = GetUpdateRegion().GetBox();
|
||||||
|
wxCoord x, y, w, h;
|
||||||
|
wxInt32 i0, j0, i1, j1;
|
||||||
|
|
||||||
wxRegionIterator upd(GetUpdateRegion());
|
// find damaged area
|
||||||
wxCoord x, y, w, h, xx, yy;
|
x = rect.GetX();
|
||||||
|
y = rect.GetY();
|
||||||
|
w = rect.GetWidth();
|
||||||
|
h = rect.GetHeight();
|
||||||
|
|
||||||
|
i0 = XToCell(x);
|
||||||
|
j0 = YToCell(y);
|
||||||
|
i1 = XToCell(x + w - 1);
|
||||||
|
j1 = YToCell(y + h - 1);
|
||||||
|
|
||||||
|
size_t ncells;
|
||||||
|
Cell *cells;
|
||||||
|
bool done = FALSE;
|
||||||
|
|
||||||
|
m_life->BeginFind(i0, j0, i1, j1, FALSE);
|
||||||
|
done = m_life->FindMore(&cells, &ncells);
|
||||||
|
|
||||||
|
// erase all damaged cells and draw the grid
|
||||||
dc.BeginDrawing();
|
dc.BeginDrawing();
|
||||||
memdc.SelectObject(*m_bmp);
|
dc.SetBrush(*wxWHITE_BRUSH);
|
||||||
|
|
||||||
while(upd)
|
if (m_cellsize <= 2)
|
||||||
{
|
{
|
||||||
x = upd.GetX();
|
// no grid
|
||||||
y = upd.GetY();
|
dc.SetPen(*wxWHITE_PEN);
|
||||||
w = upd.GetW();
|
dc.DrawRectangle(x, y, w, h);
|
||||||
h = upd.GetH();
|
}
|
||||||
CalcUnscrolledPosition(x, y, &xx, &yy);
|
else
|
||||||
|
{
|
||||||
|
x = CellToX(i0);
|
||||||
|
y = CellToY(j0);
|
||||||
|
w = CellToX(i1 + 1) - x + 1;
|
||||||
|
h = CellToY(j1 + 1) - y + 1;
|
||||||
|
|
||||||
dc.Blit(x, y, w, h, &memdc, xx - m_xoffset, yy - m_yoffset);
|
dc.SetPen(*wxLIGHT_GREY_PEN);
|
||||||
upd++;
|
for (wxInt32 yy = y; yy <= (y + h - m_cellsize); yy += m_cellsize)
|
||||||
|
dc.DrawRectangle(x, yy, w, m_cellsize + 1);
|
||||||
|
for (wxInt32 xx = x; xx <= (x + w - m_cellsize); xx += m_cellsize)
|
||||||
|
dc.DrawLine(xx, y, xx, y + h);
|
||||||
}
|
}
|
||||||
|
|
||||||
memdc.SelectObject(wxNullBitmap);
|
// draw all alive cells
|
||||||
|
dc.SetPen(*wxBLACK_PEN);
|
||||||
|
dc.SetBrush(*wxBLACK_BRUSH);
|
||||||
|
|
||||||
|
while (!done)
|
||||||
|
{
|
||||||
|
for (size_t m = 0; m < ncells; m++)
|
||||||
|
DrawCell(cells[m].i, cells[m].j, dc);
|
||||||
|
|
||||||
|
done = m_life->FindMore(&cells, &ncells);
|
||||||
|
}
|
||||||
|
|
||||||
|
// last set
|
||||||
|
for (size_t m = 0; m < ncells; m++)
|
||||||
|
DrawCell(cells[m].i, cells[m].j, dc);
|
||||||
|
|
||||||
dc.EndDrawing();
|
dc.EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -564,42 +612,21 @@ void LifeCanvas::OnMouse(wxMouseEvent& event)
|
|||||||
if (!m_interactive)
|
if (!m_interactive)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int x, y, xx, yy, i, j;
|
|
||||||
|
|
||||||
// which cell are we pointing at?
|
// which cell are we pointing at?
|
||||||
x = event.GetX();
|
wxInt32 i = XToCell( event.GetX() );
|
||||||
y = event.GetY();
|
wxInt32 j = YToCell( event.GetY() );
|
||||||
CalcUnscrolledPosition(x, y, &xx, &yy);
|
|
||||||
i = CoordToCell( xx - m_xoffset );
|
|
||||||
j = CoordToCell( yy - m_yoffset );
|
|
||||||
|
|
||||||
// adjust x, y to point to the upper left corner of the cell
|
// set statusbar text
|
||||||
CalcScrolledPosition( CellToCoord(i) + m_xoffset,
|
|
||||||
CellToCoord(j) + m_yoffset,
|
|
||||||
&x, &y );
|
|
||||||
|
|
||||||
// set cursor shape and statusbar text
|
|
||||||
if (i < 0 || i >= m_life->GetWidth() ||
|
|
||||||
j < 0 || j >= m_life->GetHeight())
|
|
||||||
{
|
|
||||||
GET_FRAME()->SetStatusText(wxEmptyString, 1);
|
|
||||||
SetCursor(*wxSTANDARD_CURSOR);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxString msg;
|
wxString msg;
|
||||||
msg.Printf(_("Cell: (%u, %u)"), i, j);
|
msg.Printf(_("Cell: (%d, %d)"), i, j);
|
||||||
GET_FRAME()->SetStatusText(msg, 1);
|
GET_FRAME()->SetStatusText(msg, 1);
|
||||||
SetCursor(*wxCROSS_CURSOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
// button pressed?
|
// button pressed?
|
||||||
if (!event.LeftIsDown())
|
if (!event.LeftIsDown())
|
||||||
{
|
{
|
||||||
m_status = MOUSE_NOACTION;
|
m_status = MOUSE_NOACTION;
|
||||||
}
|
}
|
||||||
else if (i >= 0 && i < m_life->GetWidth() &&
|
else
|
||||||
j >= 0 && j < m_life->GetHeight())
|
|
||||||
{
|
{
|
||||||
bool alive = m_life->IsAlive(i, j);
|
bool alive = m_life->IsAlive(i, j);
|
||||||
|
|
||||||
@@ -611,20 +638,124 @@ void LifeCanvas::OnMouse(wxMouseEvent& event)
|
|||||||
if (((m_status == MOUSE_ERASING) && alive) ||
|
if (((m_status == MOUSE_ERASING) && alive) ||
|
||||||
((m_status == MOUSE_DRAWING) && !alive))
|
((m_status == MOUSE_DRAWING) && !alive))
|
||||||
{
|
{
|
||||||
wxRect rect(x, y, m_cellsize + 1, m_cellsize + 1);
|
m_life->SetCell(i, j, !alive);
|
||||||
DrawCell( m_life->SetCell(i, j, !alive) );
|
DrawCell(i, j, !alive);
|
||||||
Refresh(FALSE, &rect);
|
GET_FRAME()->UpdateInfoText();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LifeCanvas::OnSize(wxSizeEvent& event)
|
void LifeCanvas::OnSize(wxSizeEvent& event)
|
||||||
{
|
{
|
||||||
|
// find center
|
||||||
|
wxInt32 cx = m_viewportX + m_viewportW / 2;
|
||||||
|
wxInt32 cy = m_viewportY + m_viewportH / 2;
|
||||||
|
|
||||||
|
// get new size
|
||||||
wxCoord w = event.GetSize().GetX();
|
wxCoord w = event.GetSize().GetX();
|
||||||
wxCoord h = event.GetSize().GetY();
|
wxCoord h = event.GetSize().GetY();
|
||||||
m_xoffset = (w > m_width)? ((w - m_width) / 2) : 0;
|
m_viewportW = (w + m_cellsize - 1) / m_cellsize;
|
||||||
m_yoffset = (h > m_height)? ((h - m_height) / 2) : 0;
|
m_viewportH = (h + m_cellsize - 1) / m_cellsize;
|
||||||
|
|
||||||
|
// recenter
|
||||||
|
m_viewportX = cx - m_viewportW / 2;
|
||||||
|
m_viewportY = cy - m_viewportH / 2;
|
||||||
|
|
||||||
|
// scrollbars
|
||||||
|
if (m_interactive)
|
||||||
|
{
|
||||||
|
SetScrollbar(wxHORIZONTAL, m_viewportW, m_viewportW, 3 * m_viewportW);
|
||||||
|
SetScrollbar(wxVERTICAL, m_viewportH, m_viewportH, 3 * m_viewportH);
|
||||||
|
m_thumbX = m_viewportW;
|
||||||
|
m_thumbY = m_viewportH;
|
||||||
|
}
|
||||||
|
|
||||||
// allow default processing
|
// allow default processing
|
||||||
event.Skip();
|
event.Skip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LifeCanvas::OnScroll(wxScrollWinEvent& event)
|
||||||
|
{
|
||||||
|
WXTYPE type = event.GetEventType();
|
||||||
|
int pos = event.GetPosition();
|
||||||
|
int orient = event.GetOrientation();
|
||||||
|
bool scrolling = event.IsScrolling();
|
||||||
|
int scrollinc = 0;
|
||||||
|
|
||||||
|
// calculate scroll increment
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case wxEVT_SCROLLWIN_TOP:
|
||||||
|
{
|
||||||
|
if (orient == wxHORIZONTAL)
|
||||||
|
scrollinc = -m_viewportW;
|
||||||
|
else
|
||||||
|
scrollinc = -m_viewportH;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case wxEVT_SCROLLWIN_BOTTOM:
|
||||||
|
{
|
||||||
|
if (orient == wxHORIZONTAL)
|
||||||
|
scrollinc = m_viewportW;
|
||||||
|
else
|
||||||
|
scrollinc = m_viewportH;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case wxEVT_SCROLLWIN_LINEUP: scrollinc = -1; break;
|
||||||
|
case wxEVT_SCROLLWIN_LINEDOWN: scrollinc = +1; break;
|
||||||
|
case wxEVT_SCROLLWIN_PAGEUP: scrollinc = -10; break;
|
||||||
|
case wxEVT_SCROLLWIN_PAGEDOWN: scrollinc = +10; break;
|
||||||
|
case wxEVT_SCROLLWIN_THUMBTRACK:
|
||||||
|
{
|
||||||
|
if (scrolling)
|
||||||
|
{
|
||||||
|
// user is dragging the thumb in the scrollbar
|
||||||
|
if (orient == wxHORIZONTAL)
|
||||||
|
{
|
||||||
|
scrollinc = pos - m_thumbX;
|
||||||
|
m_thumbX = pos;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scrollinc = pos - m_thumbY;
|
||||||
|
m_thumbY = pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// user released the thumb after dragging
|
||||||
|
m_thumbX = m_viewportW;
|
||||||
|
m_thumbY = m_viewportH;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __WXGTK__ // what about Motif?
|
||||||
|
// wxGTK updates the thumb automatically (wxMSW doesn't); reset it back
|
||||||
|
if ((type != wxEVT_SCROLLWIN_THUMBTRACK) || !scrolling)
|
||||||
|
{
|
||||||
|
SetScrollbar(wxHORIZONTAL, m_viewportW, m_viewportW, 3 * m_viewportW);
|
||||||
|
SetScrollbar(wxVERTICAL, m_viewportH, m_viewportH, 3 * m_viewportH);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (scrollinc == 0) return;
|
||||||
|
|
||||||
|
// scroll the window and adjust the viewport
|
||||||
|
if (orient == wxHORIZONTAL)
|
||||||
|
{
|
||||||
|
m_viewportX += scrollinc;
|
||||||
|
ScrollWindow( -m_cellsize * scrollinc, 0, (const wxRect *) NULL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_viewportY += scrollinc;
|
||||||
|
ScrollWindow( 0, -m_cellsize * scrollinc, (const wxRect *) NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LifeCanvas::OnEraseBackground(wxEraseEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
// do nothing. I just don't want the background to be erased, you know.
|
||||||
|
}
|
||||||
|
@@ -34,30 +34,46 @@
|
|||||||
// LifeCanvas
|
// LifeCanvas
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
|
|
||||||
class LifeCanvas : public wxScrolledWindow
|
/* Note that in LifeCanvas, all cell coordinates are
|
||||||
|
* named i, j, while screen coordinates are named x, y.
|
||||||
|
*/
|
||||||
|
class LifeCanvas : public wxWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// ctor and dtor
|
// ctor and dtor
|
||||||
LifeCanvas(wxWindow* parent, Life* life, bool interactive = TRUE);
|
LifeCanvas(wxWindow* parent, Life* life, bool interactive = TRUE);
|
||||||
~LifeCanvas();
|
~LifeCanvas();
|
||||||
|
|
||||||
// member functions
|
// view management
|
||||||
void Reset();
|
int GetCellSize() const { return m_cellsize; };
|
||||||
void DrawEverything(bool force = FALSE);
|
void SetCellSize(int cellsize);
|
||||||
void DrawCell(Cell c);
|
void Recenter(wxInt32 i, wxInt32 j);
|
||||||
void DrawCell(Cell c, 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
|
// drawing
|
||||||
void OnPaint(wxPaintEvent& event);
|
void DrawChanged();
|
||||||
void OnMouse(wxMouseEvent& event);
|
void DrawCell(wxInt32 i, wxInt32 j, bool alive);
|
||||||
void OnSize(wxSizeEvent& event);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// any class wishing to process wxWindows events must use this macro
|
// any class wishing to process wxWindows events must use this macro
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
|
|
||||||
|
// draw a cell (parametrized by DC)
|
||||||
|
void DrawCell(wxInt32 i, wxInt32 j, wxDC &dc);
|
||||||
|
|
||||||
|
// event handlers
|
||||||
|
void OnPaint(wxPaintEvent& event);
|
||||||
|
void OnMouse(wxMouseEvent& event);
|
||||||
|
void OnSize(wxSizeEvent& event);
|
||||||
|
void OnScroll(wxScrollWinEvent& event);
|
||||||
|
void OnEraseBackground(wxEraseEvent& event);
|
||||||
|
|
||||||
|
// 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; };
|
||||||
|
|
||||||
|
// what is the user doing?
|
||||||
enum MouseStatus
|
enum MouseStatus
|
||||||
{
|
{
|
||||||
MOUSE_NOACTION,
|
MOUSE_NOACTION,
|
||||||
@@ -65,15 +81,16 @@ private:
|
|||||||
MOUSE_ERASING
|
MOUSE_ERASING
|
||||||
};
|
};
|
||||||
|
|
||||||
Life *m_life;
|
Life *m_life; // Life object
|
||||||
wxBitmap *m_bmp;
|
int m_cellsize; // current cell size, in pixels
|
||||||
int m_height;
|
bool m_interactive; // is this canvas interactive?
|
||||||
int m_width;
|
MouseStatus m_status; // what is the user doing?
|
||||||
int m_cellsize;
|
wxInt32 m_viewportX; // first visible cell (x coord)
|
||||||
wxCoord m_xoffset;
|
wxInt32 m_viewportY; // first visible cell (y coord)
|
||||||
wxCoord m_yoffset;
|
wxInt32 m_viewportW; // number of visible cells (w)
|
||||||
MouseStatus m_status;
|
wxInt32 m_viewportH; // number of visible cells (h)
|
||||||
bool m_interactive;
|
int m_thumbX; // horiz. scrollbar thumb position
|
||||||
|
int m_thumbY; // vert. scrollbar thumb position
|
||||||
};
|
};
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
@@ -100,25 +117,27 @@ public:
|
|||||||
|
|
||||||
// member functions
|
// member functions
|
||||||
void UpdateInfoText();
|
void UpdateInfoText();
|
||||||
|
void UpdateUI();
|
||||||
// event handlers
|
|
||||||
void OnMenu(wxCommandEvent& event);
|
|
||||||
void OnNewGame(wxCommandEvent& event);
|
|
||||||
void OnSamples(wxCommandEvent& event);
|
|
||||||
void OnStart();
|
|
||||||
void OnStop();
|
|
||||||
void OnTimer();
|
void OnTimer();
|
||||||
void OnSlider(wxScrollEvent& event);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// any class wishing to process wxWindows events must use this macro
|
// any class wishing to process wxWindows events must use this macro
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
|
|
||||||
|
// event handlers
|
||||||
|
void OnMenu(wxCommandEvent& event);
|
||||||
|
void OnSamples(wxCommandEvent& event);
|
||||||
|
void OnSlider(wxScrollEvent& event);
|
||||||
|
void OnClose(wxCloseEvent& event);
|
||||||
|
void OnStart();
|
||||||
|
void OnStop();
|
||||||
|
|
||||||
Life *m_life;
|
Life *m_life;
|
||||||
LifeTimer *m_timer;
|
LifeTimer *m_timer;
|
||||||
LifeCanvas *m_canvas;
|
LifeCanvas *m_canvas;
|
||||||
wxStaticText *m_text;
|
wxStaticText *m_text;
|
||||||
bool m_running;
|
bool m_running;
|
||||||
|
bool m_topspeed;
|
||||||
long m_interval;
|
long m_interval;
|
||||||
long m_tics;
|
long m_tics;
|
||||||
};
|
};
|
||||||
|
@@ -4,3 +4,6 @@ mondrian ICON "mondrian.ico"
|
|||||||
reset BITMAP "bitmaps/reset.bmp"
|
reset BITMAP "bitmaps/reset.bmp"
|
||||||
play BITMAP "bitmaps/play.bmp"
|
play BITMAP "bitmaps/play.bmp"
|
||||||
stop BITMAP "bitmaps/stop.bmp"
|
stop BITMAP "bitmaps/stop.bmp"
|
||||||
|
zoomin BITMAP "bitmaps/zoomin.bmp"
|
||||||
|
zoomout BITMAP "bitmaps/zoomout.bmp"
|
||||||
|
life BITMAP "bitmaps/life.bmp"
|
||||||
|
@@ -17,14 +17,13 @@
|
|||||||
*
|
*
|
||||||
* Name,
|
* Name,
|
||||||
* Description,
|
* Description,
|
||||||
* Width, Height,
|
* Width,
|
||||||
* Data, ('*' = alive, '.' = dead)
|
* Height,
|
||||||
* Field width, Field height, (optional, defaults to 20 x 20)
|
* Data ('*' = alive, '.' = dead)
|
||||||
* Wraparound (optional, defaults to TRUE)
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
LifeShape g_shapes[] =
|
const LifeShape g_shapes[] =
|
||||||
{
|
{
|
||||||
LifeShape( _("Glider"),
|
LifeShape( _("Glider"),
|
||||||
_("The glider is the first of a series of life forms, known "
|
_("The glider is the first of a series of life forms, known "
|
||||||
@@ -111,8 +110,7 @@ LifeShape g_shapes[] =
|
|||||||
3, 3,
|
3, 3,
|
||||||
".**"
|
".**"
|
||||||
"**."
|
"**."
|
||||||
".*.",
|
".*." ),
|
||||||
80, 80, FALSE ),
|
|
||||||
LifeShape( _("Thunderbird"),
|
LifeShape( _("Thunderbird"),
|
||||||
_("The thunderbird is another popular methuselah, which "
|
_("The thunderbird is another popular methuselah, which "
|
||||||
"doesn't stabilize until the 243th generation. Note that "
|
"doesn't stabilize until the 243th generation. Note that "
|
||||||
@@ -124,17 +122,14 @@ LifeShape g_shapes[] =
|
|||||||
"..."
|
"..."
|
||||||
".*."
|
".*."
|
||||||
".*."
|
".*."
|
||||||
".*.",
|
".*." ),
|
||||||
60, 60, FALSE ),
|
|
||||||
LifeShape( _("Accorn"),
|
LifeShape( _("Accorn"),
|
||||||
_("Probably the most popular methuselah, the accorn lives "
|
_("Probably the most popular methuselah, the accorn lives "
|
||||||
"for 5206 (!) generations. To see it in action, a very "
|
"for 5206 (!) generations."),
|
||||||
"large game field is needed."),
|
|
||||||
7, 3,
|
7, 3,
|
||||||
".*....."
|
".*....."
|
||||||
"...*..."
|
"...*..."
|
||||||
"**..***",
|
"**..***" ),
|
||||||
150, 150, FALSE ),
|
|
||||||
LifeShape( _("Galaxy"),
|
LifeShape( _("Galaxy"),
|
||||||
_("One from my personal collection. It is really beautiful "
|
_("One from my personal collection. It is really beautiful "
|
||||||
"to see this configuration expand and shrink periodically "
|
"to see this configuration expand and shrink periodically "
|
||||||
@@ -152,6 +147,110 @@ LifeShape g_shapes[] =
|
|||||||
"*.....*......"
|
"*.....*......"
|
||||||
"......*......"
|
"......*......"
|
||||||
"......*......"
|
"......*......"
|
||||||
".......***...",
|
".......***..." ),
|
||||||
80, 80, FALSE )
|
LifeShape( _("Glider gun"),
|
||||||
|
_("A gun is a stationary pattern that emits spaceships "
|
||||||
|
"forever. The glider gun shown here was the first known "
|
||||||
|
"gun, and indeed the first known finite pattern with "
|
||||||
|
"unbounded growth. It was found by Bill Gosper in "
|
||||||
|
"November 1970. Many new guns have since been found."),
|
||||||
|
36, 9,
|
||||||
|
".........................*.........."
|
||||||
|
"......................****....*....."
|
||||||
|
".............*.......****.....*....."
|
||||||
|
"............*.*......*..*.........**"
|
||||||
|
"...........*...**....****.........**"
|
||||||
|
"**.........*...**.....****.........."
|
||||||
|
"**.........*...**........*.........."
|
||||||
|
"............*.*....................."
|
||||||
|
".............*......................" ),
|
||||||
|
LifeShape( _("Puffer train"),
|
||||||
|
_("A puffer is an object that moves like a spaceship, except "
|
||||||
|
"that it leaves a trail of debris behind. The puffer train "
|
||||||
|
"is one of the best-known puffers. Originally found by "
|
||||||
|
"Bill Gosper, this is a very dirty puffer; the tail does "
|
||||||
|
"not stabilize until generation 5533. It consists of a "
|
||||||
|
"B-heptomino (the middle pattern) escorted by two light "
|
||||||
|
"weight space ships."),
|
||||||
|
5, 18,
|
||||||
|
"...*."
|
||||||
|
"....*"
|
||||||
|
"*...*"
|
||||||
|
".****"
|
||||||
|
"....."
|
||||||
|
"....."
|
||||||
|
"....."
|
||||||
|
"*...."
|
||||||
|
".**.."
|
||||||
|
"..*.."
|
||||||
|
"..*.."
|
||||||
|
".*..."
|
||||||
|
"....."
|
||||||
|
"....."
|
||||||
|
"...*."
|
||||||
|
"....*"
|
||||||
|
"*...*"
|
||||||
|
".****" ),
|
||||||
|
LifeShape( _("Max"),
|
||||||
|
_("Max is the fastest-growing known pattern in Conway's Game "
|
||||||
|
"of Life (possibly the fastest possible). It fills space to "
|
||||||
|
"a density of 1/2, conjectured to be the maximum density, "
|
||||||
|
"and does it at a speed of c/2 in each of the 4 directions, "
|
||||||
|
"which has been proven to be the maximum possible speed.\n"
|
||||||
|
"\n"
|
||||||
|
"Population growth is:\n"
|
||||||
|
"[(t+19)^2+463]/4 for t divisible by 4;\n"
|
||||||
|
"[(t+19)^2+487]/4 for t even, not div. by 4;\n"
|
||||||
|
"[(t+18)^2+639]/4 for t odd.\n"
|
||||||
|
"\n"
|
||||||
|
"Original construction, top/bottom stretchers by Hartmut "
|
||||||
|
"Holzwart; Size optimization, left/right stretchers by David "
|
||||||
|
"Bell; Original idea, middle part, left/right stretcher "
|
||||||
|
"connection by Al Hensel.\n"
|
||||||
|
"\n"
|
||||||
|
"This spacefiller by David Bell, September 1993."),
|
||||||
|
29, 43,
|
||||||
|
".....*.*....................."
|
||||||
|
"....*..*....................."
|
||||||
|
"...**........................"
|
||||||
|
"..*.........................."
|
||||||
|
".****........................"
|
||||||
|
"*....*......................."
|
||||||
|
"*..*........................."
|
||||||
|
"*..*........................."
|
||||||
|
".*.........***...***........."
|
||||||
|
"..****.*..*..*...*..*........"
|
||||||
|
"...*...*.....*...*..........."
|
||||||
|
"....*........*...*..........."
|
||||||
|
"....*.*......*...*..........."
|
||||||
|
"............................."
|
||||||
|
"...***.....***...***........."
|
||||||
|
"...**.......*.....*.........."
|
||||||
|
"...***......*******.........."
|
||||||
|
"...........*.......*........."
|
||||||
|
"....*.*...***********........"
|
||||||
|
"...*..*..*............**....."
|
||||||
|
"...*.....************...*...."
|
||||||
|
"...*...*.............*...*..."
|
||||||
|
"....*...************.....*..."
|
||||||
|
".....**............*..*..*..."
|
||||||
|
"........***********...*.*...."
|
||||||
|
".........*.......*..........."
|
||||||
|
"..........*******......***..."
|
||||||
|
"..........*.....*.......**..."
|
||||||
|
".........***...***.....***..."
|
||||||
|
"............................."
|
||||||
|
"...........*...*......*.*...."
|
||||||
|
"...........*...*........*...."
|
||||||
|
"...........*...*.....*...*..."
|
||||||
|
"........*..*...*..*..*.****.."
|
||||||
|
".........***...***.........*."
|
||||||
|
".........................*..*"
|
||||||
|
".........................*..*"
|
||||||
|
".......................*....*"
|
||||||
|
"........................****."
|
||||||
|
"..........................*.."
|
||||||
|
"........................**..."
|
||||||
|
".....................*..*...."
|
||||||
|
".....................*.*....." )
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user