]> git.saurik.com Git - wxWidgets.git/blob - demos/life/dialogs.cpp
__WXDEBUG__ must be tested with #ifdef, not #if
[wxWidgets.git] / demos / life / dialogs.cpp
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 // ==========================================================================
13 // headers, declarations, constants
14 // ==========================================================================
15
16 #ifdef __GNUG__
17 #pragma implementation "dialogs.h"
18 #endif
19
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
31 #include "wx/statline.h"
32 #include "wx/minifram.h"
33 #include "wx/settings.h"
34
35 #include "dialogs.h"
36 #include "life.h"
37 #include "game.h"
38
39
40 // --------------------------------------------------------------------------
41 // resources
42 // --------------------------------------------------------------------------
43
44 #include "bitmaps/life.xpm"
45
46 // sample configurations
47 #include "samples.inc"
48
49 // --------------------------------------------------------------------------
50 // constants
51 // --------------------------------------------------------------------------
52
53 // IDs for the controls and the menu commands
54 enum
55 {
56 // listbox in samples dialog
57 ID_LISTBOX
58 };
59
60 // --------------------------------------------------------------------------
61 // event tables and other macros for wxWidgets
62 // --------------------------------------------------------------------------
63
64 // Event tables
65 BEGIN_EVENT_TABLE(LifeSamplesDialog, wxDialog)
66 EVT_LISTBOX (ID_LISTBOX, LifeSamplesDialog::OnListBox)
67 END_EVENT_TABLE()
68
69
70 // ==========================================================================
71 // implementation
72 // ==========================================================================
73
74 // --------------------------------------------------------------------------
75 // LifeSamplesDialog
76 // --------------------------------------------------------------------------
77
78 LifeSamplesDialog::LifeSamplesDialog(wxWindow *parent)
79 : wxDialog(parent, wxID_ANY, _("Sample games"),
80 wxDefaultPosition, wxDefaultSize)
81 {
82 m_value = 0;
83
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
97 // create and populate the list of available samples
98 m_list = new wxListBox( this, ID_LISTBOX,
99 wxDefaultPosition,
100 listSize,
101 0, NULL,
102 wxLB_SINGLE | wxLB_NEEDED_SB | wxLB_HSCROLL );
103
104 for (unsigned i = 0; i < (sizeof(g_patterns) / sizeof(LifePattern)); i++)
105 m_list->Append(g_patterns[i].m_name);
106
107 // descriptions
108 wxStaticBox *statbox = new wxStaticBox( this, wxID_ANY, _("Description"));
109 m_life = new Life();
110 m_life->SetPattern(g_patterns[0]);
111 m_canvas = new LifeCanvas( this, m_life, false );
112 m_text = new wxTextCtrl( this, wxID_ANY,
113 g_patterns[0].m_description,
114 wxDefaultPosition,
115 wxSize(300, 60),
116 wxTE_MULTILINE | wxTE_READONLY);
117
118 // layout components
119
120 wxStaticBoxSizer *sizer1 = new wxStaticBoxSizer( statbox, wxVERTICAL );
121 sizer1->Add( m_canvas, 2, wxGROW | wxALL, 5);
122 sizer1->Add( m_text, 1, wxGROW | wxALL, 5 );
123
124 wxBoxSizer *sizer2 = new wxBoxSizer( screenIsHorizontal ? wxHORIZONTAL : wxVERTICAL );
125 sizer2->Add( m_list, 0, wxGROW | wxALL, 5 );
126 sizer2->Add( sizer1, 1, wxGROW | wxALL, 5 );
127
128 wxBoxSizer *sizer3 = new wxBoxSizer( wxVERTICAL );
129 sizer3->Add( CreateTextSizer(_("Select a configuration")), 0, wxALL|wxCENTRE, isPDA ? 2 : 10 );
130 #if wxUSE_STATLINE
131 if (!isPDA)
132 sizer3->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 10 );
133 #endif // wxUSE_STATLINE
134 sizer3->Add( sizer2, 1, wxGROW | wxALL, 5 );
135 #if wxUSE_STATLINE
136 if (!isPDA)
137 sizer3->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 10 );
138 #endif // wxUSE_STATLINE
139
140 #if defined(__SMARTPHONE__)
141 SetLeftMenu(wxID_CANCEL);
142 SetRightMenu(wxID_OK);
143 #endif
144
145 // activate
146 SetSizer(sizer3);
147
148 #if !defined(__POCKETPC__) && !defined(__SMARTPHONE__)
149 sizer3->Add( CreateButtonSizer(wxOK | wxCANCEL), 0, wxCENTRE | wxALL, isPDA ? 2 : 10 );
150 sizer3->SetSizeHints(this);
151 sizer3->Fit(this);
152 Centre(wxBOTH | wxCENTRE_ON_SCREEN);
153 #endif
154 }
155
156 LifeSamplesDialog::~LifeSamplesDialog()
157 {
158 m_canvas->Destroy();
159 }
160
161 const LifePattern& LifeSamplesDialog::GetPattern()
162 {
163 return g_patterns[m_value];
164 }
165
166 void LifeSamplesDialog::OnListBox(wxCommandEvent& event)
167 {
168 int sel = event.GetSelection();
169
170 if (sel != -1)
171 {
172 m_value = m_list->GetSelection();
173 m_text->SetValue(g_patterns[ sel ].m_description);
174 m_life->SetPattern(g_patterns[ sel ]);
175
176 // these values shouldn't be hardcoded...
177 if ((size_t)sel < (sizeof(g_patterns) / sizeof(LifePattern)) - 3)
178 m_canvas->SetCellSize(8);
179 else
180 m_canvas->SetCellSize(2);
181 }
182 }
183
184 // --------------------------------------------------------------------------
185 // LifeAboutDialog
186 // --------------------------------------------------------------------------
187
188 LifeAboutDialog::LifeAboutDialog(wxWindow *parent)
189 : wxDialog(parent, wxID_ANY, _("About Life!"),
190 wxDefaultPosition, wxDefaultSize)
191 {
192 // logo
193 wxStaticBitmap *sbmp = new wxStaticBitmap(this, wxID_ANY, wxBitmap(life_xpm));
194
195 // layout components
196 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
197 sizer->Add( sbmp, 0, wxCENTRE | wxALL, 10 );
198 #if wxUSE_STATLINE
199 sizer->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 5 );
200 #endif // wxUSE_STATLINE
201 sizer->Add( CreateTextSizer(_("Life! version 2.2 for wxWidgets\n\n\
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.")),
206 0, wxCENTRE | wxALL, 20 );
207 #if wxUSE_STATLINE
208 sizer->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 5 );
209 #endif // wxUSE_STATLINE
210
211 #if ! (defined(__SMARTPHONE__) || defined(__POCKETPC__))
212 sizer->Add( CreateButtonSizer(wxOK), 0, wxCENTRE | wxALL, 10 );
213 #endif
214
215 // activate
216 SetSizer(sizer);
217
218 #if ! (defined(__SMARTPHONE__) || defined(__POCKETPC__))
219 sizer->SetSizeHints(this);
220 sizer->Fit(this);
221 Centre(wxBOTH | wxCENTRE_ON_SCREEN);
222 #endif
223 }
224
225
226