]> git.saurik.com Git - wxWidgets.git/blame - demos/life/dialogs.cpp
define USE_QA so that qa library is built
[wxWidgets.git] / demos / life / dialogs.cpp
CommitLineData
2480be69
GRG
1/////////////////////////////////////////////////////////////////////////////
2// Name: dialogs.cpp
3// Purpose: Life! dialogs
4// Author: Guillermo Rodriguez Garcia, <guille@iies.es>
5// Modified by:
6// Created: Jan/2000
7// RCS-ID: $Id$
8// Copyright: (c) 2000, Guillermo Rodriguez Garcia
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ==========================================================================
e0a40292 13// headers, declarations, constants
2480be69
GRG
14// ==========================================================================
15
2480be69
GRG
16#ifdef __GNUG__
17 #pragma implementation "dialogs.h"
18#endif
19
2fa7c206
JS
20// For compilers that support precompilation, includes "wx/wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24#pragma hdrstop
25#endif
26
27#ifndef WX_PRECOMP
28#include "wx/wx.h"
29#endif
30
2480be69 31#include "wx/statline.h"
29b07a38 32#include "wx/minifram.h"
2480be69
GRG
33
34#include "dialogs.h"
35#include "life.h"
36#include "game.h"
37
29b07a38 38
e0a40292
GRG
39// --------------------------------------------------------------------------
40// resources
41// --------------------------------------------------------------------------
42
15025f06 43#include "bitmaps/life.xpm"
e0a40292
GRG
44
45// sample configurations
46#include "samples.inc"
47
2480be69
GRG
48// --------------------------------------------------------------------------
49// constants
50// --------------------------------------------------------------------------
51
52// IDs for the controls and the menu commands
53enum
54{
55 // listbox in samples dialog
e0a40292 56 ID_LISTBOX
2480be69
GRG
57};
58
2480be69 59// --------------------------------------------------------------------------
be5a51fb 60// event tables and other macros for wxWidgets
2480be69
GRG
61// --------------------------------------------------------------------------
62
63// Event tables
2480be69
GRG
64BEGIN_EVENT_TABLE(LifeSamplesDialog, wxDialog)
65 EVT_LISTBOX (ID_LISTBOX, LifeSamplesDialog::OnListBox)
66END_EVENT_TABLE()
67
68
69// ==========================================================================
70// implementation
71// ==========================================================================
72
2480be69
GRG
73// --------------------------------------------------------------------------
74// LifeSamplesDialog
75// --------------------------------------------------------------------------
76
77LifeSamplesDialog::LifeSamplesDialog(wxWindow *parent)
2a21ac15
DS
78 : wxDialog(parent, wxID_ANY, _("Sample games"),
79 wxDefaultPosition, wxDefaultSize)
2480be69
GRG
80{
81 m_value = 0;
2a21ac15 82
2480be69
GRG
83 // create and populate the list of available samples
84 m_list = new wxListBox( this, ID_LISTBOX,
85 wxDefaultPosition,
86 wxDefaultSize,
87 0, NULL,
88 wxLB_SINGLE | wxLB_NEEDED_SB | wxLB_HSCROLL );
89
f6bcfd97
BP
90 for (unsigned i = 0; i < (sizeof(g_patterns) / sizeof(LifePattern)); i++)
91 m_list->Append(g_patterns[i].m_name);
2480be69
GRG
92
93 // descriptions
2a21ac15 94 wxStaticBox *statbox = new wxStaticBox( this, wxID_ANY, _("Description"));
e0a40292 95 m_life = new Life();
f6bcfd97 96 m_life->SetPattern(g_patterns[0]);
2a21ac15
DS
97 m_canvas = new LifeCanvas( this, m_life, false );
98 m_text = new wxTextCtrl( this, wxID_ANY,
f6bcfd97 99 g_patterns[0].m_description,
2480be69
GRG
100 wxDefaultPosition,
101 wxSize(300, 60),
102 wxTE_MULTILINE | wxTE_READONLY);
103
104 // layout components
105 wxStaticBoxSizer *sizer1 = new wxStaticBoxSizer( statbox, wxVERTICAL );
29b07a38
GRG
106 sizer1->Add( m_canvas, 2, wxGROW | wxALL, 5);
107 sizer1->Add( m_text, 1, wxGROW | wxALL, 5 );
2480be69
GRG
108
109 wxBoxSizer *sizer2 = new wxBoxSizer( wxHORIZONTAL );
29b07a38
GRG
110 sizer2->Add( m_list, 0, wxGROW | wxALL, 5 );
111 sizer2->Add( sizer1, 1, wxGROW | wxALL, 5 );
2480be69
GRG
112
113 wxBoxSizer *sizer3 = new wxBoxSizer( wxVERTICAL );
114 sizer3->Add( CreateTextSizer(_("Select one configuration")), 0, wxALL, 10 );
27dc5184 115#if wxUSE_STATLINE
2a21ac15 116 sizer3->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 10 );
27dc5184 117#endif // wxUSE_STATLINE
29b07a38 118 sizer3->Add( sizer2, 1, wxGROW | wxALL, 5 );
27dc5184 119#if wxUSE_STATLINE
2a21ac15 120 sizer3->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 10 );
27dc5184 121#endif // wxUSE_STATLINE
2480be69
GRG
122 sizer3->Add( CreateButtonSizer(wxOK | wxCANCEL), 0, wxCENTRE | wxALL, 10 );
123
124 // activate
125 SetSizer(sizer3);
15025f06 126
f8a10a3d 127#if !defined(__POCKETPC__) && !defined(__SMARTPHONE__)
2480be69
GRG
128 sizer3->SetSizeHints(this);
129 sizer3->Fit(this);
e0a40292 130 Centre(wxBOTH | wxCENTRE_ON_SCREEN);
15025f06 131#endif
2480be69
GRG
132}
133
134LifeSamplesDialog::~LifeSamplesDialog()
135{
136 m_canvas->Destroy();
2480be69
GRG
137}
138
f6bcfd97 139const LifePattern& LifeSamplesDialog::GetPattern()
2480be69 140{
f6bcfd97 141 return g_patterns[m_value];
2480be69
GRG
142}
143
144void LifeSamplesDialog::OnListBox(wxCommandEvent& event)
145{
e0a40292
GRG
146 int sel = event.GetSelection();
147
148 if (sel != -1)
2480be69
GRG
149 {
150 m_value = m_list->GetSelection();
f6bcfd97
BP
151 m_text->SetValue(g_patterns[ sel ].m_description);
152 m_life->SetPattern(g_patterns[ sel ]);
e0a40292 153
f6bcfd97
BP
154 // these values shouldn't be hardcoded...
155 if ((size_t)sel < (sizeof(g_patterns) / sizeof(LifePattern)) - 3)
e0a40292 156 m_canvas->SetCellSize(8);
f6bcfd97
BP
157 else
158 m_canvas->SetCellSize(2);
2480be69
GRG
159 }
160}
161
e0a40292
GRG
162// --------------------------------------------------------------------------
163// LifeAboutDialog
164// --------------------------------------------------------------------------
165
166LifeAboutDialog::LifeAboutDialog(wxWindow *parent)
2a21ac15
DS
167 : wxDialog(parent, wxID_ANY, _("About Life!"),
168 wxDefaultPosition, wxDefaultSize)
e0a40292
GRG
169{
170 // logo
e5c990b3 171 wxStaticBitmap *sbmp = new wxStaticBitmap(this, wxID_ANY, wxBitmap(life_xpm));
e0a40292
GRG
172
173 // layout components
174 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
175 sizer->Add( sbmp, 0, wxCENTRE | wxALL, 10 );
27dc5184 176#if wxUSE_STATLINE
2a21ac15 177 sizer->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 5 );
27dc5184 178#endif // wxUSE_STATLINE
be5a51fb 179 sizer->Add( CreateTextSizer(_("Life! version 2.2 for wxWidgets\n\n\
1babe8fd
JS
180(c) 2000 Guillermo Rodriguez Garcia\n\n\
181<guille@iies.es>\n\n\
182Portions of the code are based in XLife;\n\
183XLife is (c) 1989 by Jon Bennett et al.")),
e0a40292 184 0, wxCENTRE | wxALL, 20 );
27dc5184 185#if wxUSE_STATLINE
2a21ac15 186 sizer->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 5 );
27dc5184 187#endif // wxUSE_STATLINE
e5c990b3 188
a9102b36 189#if ! (defined(__SMARTPHONE__) || defined(__POCKETPC__))
e0a40292 190 sizer->Add( CreateButtonSizer(wxOK), 0, wxCENTRE | wxALL, 10 );
e5c990b3 191#endif
e0a40292
GRG
192
193 // activate
194 SetSizer(sizer);
15025f06 195
a9102b36 196#if ! (defined(__SMARTPHONE__) || defined(__POCKETPC__))
e0a40292
GRG
197 sizer->SetSizeHints(this);
198 sizer->Fit(this);
199 Centre(wxBOTH | wxCENTRE_ON_SCREEN);
15025f06 200#endif
e0a40292 201}
29b07a38
GRG
202
203
204