2000-01-08 13:27:19 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dialogs.cpp
|
|
|
|
// Purpose: Life! dialogs
|
|
|
|
// Author: Guillermo Rodriguez Garcia, <guille@iies.es>
|
|
|
|
// Modified by:
|
|
|
|
// Created: Jan/2000
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2000, Guillermo Rodriguez Garcia
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ==========================================================================
|
2000-02-08 15:04:48 -05:00
|
|
|
// headers, declarations, constants
|
2000-01-08 13:27:19 -05:00
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation "dialogs.h"
|
|
|
|
#endif
|
|
|
|
|
2000-02-16 06:53:16 -05:00
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
2000-01-08 13:27:19 -05:00
|
|
|
#include "wx/statline.h"
|
2000-03-03 13:21:48 -05:00
|
|
|
#include "wx/minifram.h"
|
2005-04-02 12:26:08 -05:00
|
|
|
#include "wx/settings.h"
|
2000-01-08 13:27:19 -05:00
|
|
|
|
|
|
|
#include "dialogs.h"
|
|
|
|
#include "life.h"
|
|
|
|
#include "game.h"
|
|
|
|
|
2000-03-03 13:21:48 -05:00
|
|
|
|
2000-02-08 15:04:48 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// resources
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2005-03-13 12:32:40 -05:00
|
|
|
#include "bitmaps/life.xpm"
|
2000-02-08 15:04:48 -05:00
|
|
|
|
|
|
|
// sample configurations
|
|
|
|
#include "samples.inc"
|
|
|
|
|
2000-01-08 13:27:19 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// IDs for the controls and the menu commands
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
// listbox in samples dialog
|
2000-02-08 15:04:48 -05:00
|
|
|
ID_LISTBOX
|
2000-01-08 13:27:19 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
2004-05-25 07:20:37 -04:00
|
|
|
// event tables and other macros for wxWidgets
|
2000-01-08 13:27:19 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Event tables
|
|
|
|
BEGIN_EVENT_TABLE(LifeSamplesDialog, wxDialog)
|
|
|
|
EVT_LISTBOX (ID_LISTBOX, LifeSamplesDialog::OnListBox)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
|
|
|
// ==========================================================================
|
|
|
|
// implementation
|
|
|
|
// ==========================================================================
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// LifeSamplesDialog
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
LifeSamplesDialog::LifeSamplesDialog(wxWindow *parent)
|
2004-05-25 08:44:56 -04:00
|
|
|
: wxDialog(parent, wxID_ANY, _("Sample games"),
|
|
|
|
wxDefaultPosition, wxDefaultSize)
|
2000-01-08 13:27:19 -05:00
|
|
|
{
|
|
|
|
m_value = 0;
|
2004-05-25 08:44:56 -04:00
|
|
|
|
2005-04-02 12:26:08 -05:00
|
|
|
wxSize listSize = wxDefaultSize;
|
|
|
|
bool isPDA = wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA;
|
|
|
|
|
|
|
|
// Screens are generally horizontal in orientation,
|
|
|
|
// but PDAs are generally vertical.
|
|
|
|
bool screenIsHorizontal = true;
|
|
|
|
if (isPDA &&
|
|
|
|
wxSystemSettings::GetMetric(wxSYS_SCREEN_X) < wxSystemSettings::GetMetric(wxSYS_SCREEN_Y))
|
|
|
|
{
|
|
|
|
listSize = wxSize(-1, 50);
|
|
|
|
screenIsHorizontal = false;
|
|
|
|
}
|
|
|
|
|
2000-01-08 13:27:19 -05:00
|
|
|
// create and populate the list of available samples
|
|
|
|
m_list = new wxListBox( this, ID_LISTBOX,
|
|
|
|
wxDefaultPosition,
|
2005-04-02 12:26:08 -05:00
|
|
|
listSize,
|
2000-01-08 13:27:19 -05:00
|
|
|
0, NULL,
|
|
|
|
wxLB_SINGLE | wxLB_NEEDED_SB | wxLB_HSCROLL );
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
for (unsigned i = 0; i < (sizeof(g_patterns) / sizeof(LifePattern)); i++)
|
|
|
|
m_list->Append(g_patterns[i].m_name);
|
2000-01-08 13:27:19 -05:00
|
|
|
|
|
|
|
// descriptions
|
2004-05-25 08:44:56 -04:00
|
|
|
wxStaticBox *statbox = new wxStaticBox( this, wxID_ANY, _("Description"));
|
2000-02-08 15:04:48 -05:00
|
|
|
m_life = new Life();
|
2000-07-15 15:51:35 -04:00
|
|
|
m_life->SetPattern(g_patterns[0]);
|
2004-05-25 08:44:56 -04:00
|
|
|
m_canvas = new LifeCanvas( this, m_life, false );
|
|
|
|
m_text = new wxTextCtrl( this, wxID_ANY,
|
2000-07-15 15:51:35 -04:00
|
|
|
g_patterns[0].m_description,
|
2000-01-08 13:27:19 -05:00
|
|
|
wxDefaultPosition,
|
|
|
|
wxSize(300, 60),
|
|
|
|
wxTE_MULTILINE | wxTE_READONLY);
|
|
|
|
|
|
|
|
// layout components
|
2005-04-02 12:26:08 -05:00
|
|
|
|
2000-01-08 13:27:19 -05:00
|
|
|
wxStaticBoxSizer *sizer1 = new wxStaticBoxSizer( statbox, wxVERTICAL );
|
2000-03-03 13:21:48 -05:00
|
|
|
sizer1->Add( m_canvas, 2, wxGROW | wxALL, 5);
|
|
|
|
sizer1->Add( m_text, 1, wxGROW | wxALL, 5 );
|
2000-01-08 13:27:19 -05:00
|
|
|
|
2005-04-02 12:26:08 -05:00
|
|
|
wxBoxSizer *sizer2 = new wxBoxSizer( screenIsHorizontal ? wxHORIZONTAL : wxVERTICAL );
|
2000-03-03 13:21:48 -05:00
|
|
|
sizer2->Add( m_list, 0, wxGROW | wxALL, 5 );
|
|
|
|
sizer2->Add( sizer1, 1, wxGROW | wxALL, 5 );
|
2000-01-08 13:27:19 -05:00
|
|
|
|
|
|
|
wxBoxSizer *sizer3 = new wxBoxSizer( wxVERTICAL );
|
2005-04-02 12:26:08 -05:00
|
|
|
sizer3->Add( CreateTextSizer(_("Select a configuration")), 0, wxALL|wxCENTRE, isPDA ? 2 : 10 );
|
2004-07-23 04:51:53 -04:00
|
|
|
#if wxUSE_STATLINE
|
2005-04-02 12:26:08 -05:00
|
|
|
if (!isPDA)
|
|
|
|
sizer3->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 10 );
|
2004-07-23 04:51:53 -04:00
|
|
|
#endif // wxUSE_STATLINE
|
2000-03-03 13:21:48 -05:00
|
|
|
sizer3->Add( sizer2, 1, wxGROW | wxALL, 5 );
|
2004-07-23 04:51:53 -04:00
|
|
|
#if wxUSE_STATLINE
|
2005-04-02 12:26:08 -05:00
|
|
|
if (!isPDA)
|
|
|
|
sizer3->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 10 );
|
2004-07-23 04:51:53 -04:00
|
|
|
#endif // wxUSE_STATLINE
|
2005-04-02 12:26:08 -05:00
|
|
|
|
|
|
|
#if defined(__SMARTPHONE__)
|
|
|
|
SetLeftMenu(wxID_CANCEL);
|
|
|
|
SetRightMenu(wxID_OK);
|
|
|
|
#endif
|
2000-01-08 13:27:19 -05:00
|
|
|
|
|
|
|
// activate
|
|
|
|
SetSizer(sizer3);
|
2005-03-13 12:32:40 -05:00
|
|
|
|
2005-03-14 12:10:32 -05:00
|
|
|
#if !defined(__POCKETPC__) && !defined(__SMARTPHONE__)
|
2005-04-02 12:26:08 -05:00
|
|
|
sizer3->Add( CreateButtonSizer(wxOK | wxCANCEL), 0, wxCENTRE | wxALL, isPDA ? 2 : 10 );
|
2000-01-08 13:27:19 -05:00
|
|
|
sizer3->SetSizeHints(this);
|
|
|
|
sizer3->Fit(this);
|
2000-02-08 15:04:48 -05:00
|
|
|
Centre(wxBOTH | wxCENTRE_ON_SCREEN);
|
2005-03-13 12:32:40 -05:00
|
|
|
#endif
|
2000-01-08 13:27:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
LifeSamplesDialog::~LifeSamplesDialog()
|
|
|
|
{
|
|
|
|
m_canvas->Destroy();
|
|
|
|
}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
const LifePattern& LifeSamplesDialog::GetPattern()
|
2000-01-08 13:27:19 -05:00
|
|
|
{
|
2000-07-15 15:51:35 -04:00
|
|
|
return g_patterns[m_value];
|
2000-01-08 13:27:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void LifeSamplesDialog::OnListBox(wxCommandEvent& event)
|
|
|
|
{
|
2000-02-08 15:04:48 -05:00
|
|
|
int sel = event.GetSelection();
|
|
|
|
|
|
|
|
if (sel != -1)
|
2000-01-08 13:27:19 -05:00
|
|
|
{
|
|
|
|
m_value = m_list->GetSelection();
|
2000-07-15 15:51:35 -04:00
|
|
|
m_text->SetValue(g_patterns[ sel ].m_description);
|
|
|
|
m_life->SetPattern(g_patterns[ sel ]);
|
2000-02-08 15:04:48 -05:00
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
// these values shouldn't be hardcoded...
|
|
|
|
if ((size_t)sel < (sizeof(g_patterns) / sizeof(LifePattern)) - 3)
|
2000-02-08 15:04:48 -05:00
|
|
|
m_canvas->SetCellSize(8);
|
2000-07-15 15:51:35 -04:00
|
|
|
else
|
|
|
|
m_canvas->SetCellSize(2);
|
2000-01-08 13:27:19 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-08 15:04:48 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// LifeAboutDialog
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
LifeAboutDialog::LifeAboutDialog(wxWindow *parent)
|
2004-05-25 08:44:56 -04:00
|
|
|
: wxDialog(parent, wxID_ANY, _("About Life!"),
|
|
|
|
wxDefaultPosition, wxDefaultSize)
|
2000-02-08 15:04:48 -05:00
|
|
|
{
|
|
|
|
// logo
|
2005-03-14 11:37:02 -05:00
|
|
|
wxStaticBitmap *sbmp = new wxStaticBitmap(this, wxID_ANY, wxBitmap(life_xpm));
|
2000-02-08 15:04:48 -05:00
|
|
|
|
|
|
|
// layout components
|
|
|
|
wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
sizer->Add( sbmp, 0, wxCENTRE | wxALL, 10 );
|
2004-07-23 04:51:53 -04:00
|
|
|
#if wxUSE_STATLINE
|
2004-05-25 08:44:56 -04:00
|
|
|
sizer->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 5 );
|
2004-07-23 04:51:53 -04:00
|
|
|
#endif // wxUSE_STATLINE
|
2004-05-25 07:20:37 -04:00
|
|
|
sizer->Add( CreateTextSizer(_("Life! version 2.2 for wxWidgets\n\n\
|
2003-08-25 13:24:20 -04:00
|
|
|
(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.")),
|
2000-02-08 15:04:48 -05:00
|
|
|
0, wxCENTRE | wxALL, 20 );
|
2004-07-23 04:51:53 -04:00
|
|
|
#if wxUSE_STATLINE
|
2004-05-25 08:44:56 -04:00
|
|
|
sizer->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 5 );
|
2004-07-23 04:51:53 -04:00
|
|
|
#endif // wxUSE_STATLINE
|
2005-03-14 11:37:02 -05:00
|
|
|
|
2005-03-16 12:51:41 -05:00
|
|
|
#if ! (defined(__SMARTPHONE__) || defined(__POCKETPC__))
|
2000-02-08 15:04:48 -05:00
|
|
|
sizer->Add( CreateButtonSizer(wxOK), 0, wxCENTRE | wxALL, 10 );
|
2005-03-14 11:37:02 -05:00
|
|
|
#endif
|
2000-02-08 15:04:48 -05:00
|
|
|
|
|
|
|
// activate
|
|
|
|
SetSizer(sizer);
|
2005-03-13 12:32:40 -05:00
|
|
|
|
2005-03-16 12:51:41 -05:00
|
|
|
#if ! (defined(__SMARTPHONE__) || defined(__POCKETPC__))
|
2000-02-08 15:04:48 -05:00
|
|
|
sizer->SetSizeHints(this);
|
|
|
|
sizer->Fit(this);
|
|
|
|
Centre(wxBOTH | wxCENTRE_ON_SCREEN);
|
2005-03-13 12:32:40 -05:00
|
|
|
#endif
|
2000-02-08 15:04:48 -05:00
|
|
|
}
|
2000-03-03 13:21:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
|