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