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