]>
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" |
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 | ||
e334d0ea | 43 | #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__) |
e0a40292 GRG |
44 | // logo for the about dialog |
45 | #include "bitmaps/life.xpm" | |
46 | #endif | |
47 | ||
48 | // sample configurations | |
49 | #include "samples.inc" | |
50 | ||
2480be69 GRG |
51 | // -------------------------------------------------------------------------- |
52 | // constants | |
53 | // -------------------------------------------------------------------------- | |
54 | ||
55 | // IDs for the controls and the menu commands | |
56 | enum | |
57 | { | |
58 | // listbox in samples dialog | |
e0a40292 | 59 | ID_LISTBOX |
2480be69 GRG |
60 | }; |
61 | ||
2480be69 | 62 | // -------------------------------------------------------------------------- |
be5a51fb | 63 | // event tables and other macros for wxWidgets |
2480be69 GRG |
64 | // -------------------------------------------------------------------------- |
65 | ||
66 | // Event tables | |
2480be69 GRG |
67 | BEGIN_EVENT_TABLE(LifeSamplesDialog, wxDialog) |
68 | EVT_LISTBOX (ID_LISTBOX, LifeSamplesDialog::OnListBox) | |
69 | END_EVENT_TABLE() | |
70 | ||
71 | ||
72 | // ========================================================================== | |
73 | // implementation | |
74 | // ========================================================================== | |
75 | ||
2480be69 GRG |
76 | // -------------------------------------------------------------------------- |
77 | // LifeSamplesDialog | |
78 | // -------------------------------------------------------------------------- | |
79 | ||
80 | LifeSamplesDialog::LifeSamplesDialog(wxWindow *parent) | |
2a21ac15 DS |
81 | : wxDialog(parent, wxID_ANY, _("Sample games"), |
82 | wxDefaultPosition, wxDefaultSize) | |
2480be69 GRG |
83 | { |
84 | m_value = 0; | |
2a21ac15 | 85 | |
2480be69 GRG |
86 | // create and populate the list of available samples |
87 | m_list = new wxListBox( this, ID_LISTBOX, | |
88 | wxDefaultPosition, | |
89 | wxDefaultSize, | |
90 | 0, NULL, | |
91 | wxLB_SINGLE | wxLB_NEEDED_SB | wxLB_HSCROLL ); | |
92 | ||
f6bcfd97 BP |
93 | for (unsigned i = 0; i < (sizeof(g_patterns) / sizeof(LifePattern)); i++) |
94 | m_list->Append(g_patterns[i].m_name); | |
2480be69 GRG |
95 | |
96 | // descriptions | |
2a21ac15 | 97 | wxStaticBox *statbox = new wxStaticBox( this, wxID_ANY, _("Description")); |
e0a40292 | 98 | m_life = new Life(); |
f6bcfd97 | 99 | m_life->SetPattern(g_patterns[0]); |
2a21ac15 DS |
100 | m_canvas = new LifeCanvas( this, m_life, false ); |
101 | m_text = new wxTextCtrl( this, wxID_ANY, | |
f6bcfd97 | 102 | g_patterns[0].m_description, |
2480be69 GRG |
103 | wxDefaultPosition, |
104 | wxSize(300, 60), | |
105 | wxTE_MULTILINE | wxTE_READONLY); | |
106 | ||
107 | // layout components | |
108 | wxStaticBoxSizer *sizer1 = new wxStaticBoxSizer( statbox, wxVERTICAL ); | |
29b07a38 GRG |
109 | sizer1->Add( m_canvas, 2, wxGROW | wxALL, 5); |
110 | sizer1->Add( m_text, 1, wxGROW | wxALL, 5 ); | |
2480be69 GRG |
111 | |
112 | wxBoxSizer *sizer2 = new wxBoxSizer( wxHORIZONTAL ); | |
29b07a38 GRG |
113 | sizer2->Add( m_list, 0, wxGROW | wxALL, 5 ); |
114 | sizer2->Add( sizer1, 1, wxGROW | wxALL, 5 ); | |
2480be69 GRG |
115 | |
116 | wxBoxSizer *sizer3 = new wxBoxSizer( wxVERTICAL ); | |
117 | sizer3->Add( CreateTextSizer(_("Select one configuration")), 0, wxALL, 10 ); | |
27dc5184 | 118 | #if wxUSE_STATLINE |
2a21ac15 | 119 | sizer3->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 10 ); |
27dc5184 | 120 | #endif // wxUSE_STATLINE |
29b07a38 | 121 | sizer3->Add( sizer2, 1, wxGROW | wxALL, 5 ); |
27dc5184 | 122 | #if wxUSE_STATLINE |
2a21ac15 | 123 | sizer3->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 10 ); |
27dc5184 | 124 | #endif // wxUSE_STATLINE |
2480be69 GRG |
125 | sizer3->Add( CreateButtonSizer(wxOK | wxCANCEL), 0, wxCENTRE | wxALL, 10 ); |
126 | ||
127 | // activate | |
128 | SetSizer(sizer3); | |
2480be69 GRG |
129 | sizer3->SetSizeHints(this); |
130 | sizer3->Fit(this); | |
e0a40292 | 131 | Centre(wxBOTH | wxCENTRE_ON_SCREEN); |
2480be69 GRG |
132 | } |
133 | ||
134 | LifeSamplesDialog::~LifeSamplesDialog() | |
135 | { | |
136 | m_canvas->Destroy(); | |
2480be69 GRG |
137 | } |
138 | ||
f6bcfd97 | 139 | const LifePattern& LifeSamplesDialog::GetPattern() |
2480be69 | 140 | { |
f6bcfd97 | 141 | return g_patterns[m_value]; |
2480be69 GRG |
142 | } |
143 | ||
144 | void 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 | ||
166 | LifeAboutDialog::LifeAboutDialog(wxWindow *parent) | |
2a21ac15 DS |
167 | : wxDialog(parent, wxID_ANY, _("About Life!"), |
168 | wxDefaultPosition, wxDefaultSize) | |
e0a40292 GRG |
169 | { |
170 | // logo | |
171 | wxBitmap bmp = wxBITMAP(life); | |
a99c96b0 | 172 | #if !defined(__WXGTK__) && !defined(__WXMOTIF__) && !defined(__WXMAC__) |
e0a40292 GRG |
173 | bmp.SetMask(new wxMask(bmp, *wxBLUE)); |
174 | #endif | |
2a21ac15 | 175 | wxStaticBitmap *sbmp = new wxStaticBitmap(this, wxID_ANY, bmp); |
e0a40292 GRG |
176 | |
177 | // layout components | |
178 | wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL ); | |
179 | sizer->Add( sbmp, 0, wxCENTRE | wxALL, 10 ); | |
27dc5184 | 180 | #if wxUSE_STATLINE |
2a21ac15 | 181 | sizer->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 5 ); |
27dc5184 | 182 | #endif // wxUSE_STATLINE |
be5a51fb | 183 | sizer->Add( CreateTextSizer(_("Life! version 2.2 for wxWidgets\n\n\ |
1babe8fd JS |
184 | (c) 2000 Guillermo Rodriguez Garcia\n\n\ |
185 | <guille@iies.es>\n\n\ | |
186 | Portions of the code are based in XLife;\n\ | |
187 | XLife is (c) 1989 by Jon Bennett et al.")), | |
e0a40292 | 188 | 0, wxCENTRE | wxALL, 20 ); |
27dc5184 | 189 | #if wxUSE_STATLINE |
2a21ac15 | 190 | sizer->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 5 ); |
27dc5184 | 191 | #endif // wxUSE_STATLINE |
e0a40292 GRG |
192 | sizer->Add( CreateButtonSizer(wxOK), 0, wxCENTRE | wxALL, 10 ); |
193 | ||
194 | // activate | |
195 | SetSizer(sizer); | |
e0a40292 GRG |
196 | sizer->SetSizeHints(this); |
197 | sizer->Fit(this); | |
198 | Centre(wxBOTH | wxCENTRE_ON_SCREEN); | |
199 | } | |
29b07a38 GRG |
200 | |
201 | ||
202 |