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