]>
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 | ||
43 | #if defined(__WXGTK__) || defined(__WXMOTIF__) | |
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 GRG |
62 | // -------------------------------------------------------------------------- |
63 | // event tables and other macros for wxWindows | |
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) | |
81 | : wxDialog(parent, -1, | |
82 | _("Sample games"), | |
83 | wxDefaultPosition, | |
84 | wxDefaultSize, | |
85 | wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL) | |
86 | { | |
87 | m_value = 0; | |
88 | ||
89 | // create and populate the list of available samples | |
90 | m_list = new wxListBox( this, ID_LISTBOX, | |
91 | wxDefaultPosition, | |
92 | wxDefaultSize, | |
93 | 0, NULL, | |
94 | wxLB_SINGLE | wxLB_NEEDED_SB | wxLB_HSCROLL ); | |
95 | ||
96 | for (unsigned i = 0; i < (sizeof(g_shapes) / sizeof(LifeShape)); i++) | |
97 | m_list->Append(g_shapes[i].m_name); | |
98 | ||
99 | // descriptions | |
100 | wxStaticBox *statbox = new wxStaticBox( this, -1, _("Description")); | |
e0a40292 | 101 | m_life = new Life(); |
2480be69 GRG |
102 | m_life->SetShape(g_shapes[0]); |
103 | m_canvas = new LifeCanvas( this, m_life, FALSE ); | |
104 | m_text = new wxTextCtrl( this, -1, | |
105 | g_shapes[0].m_desc, | |
106 | wxDefaultPosition, | |
107 | wxSize(300, 60), | |
108 | wxTE_MULTILINE | wxTE_READONLY); | |
109 | ||
110 | // layout components | |
111 | wxStaticBoxSizer *sizer1 = new wxStaticBoxSizer( statbox, wxVERTICAL ); | |
29b07a38 GRG |
112 | sizer1->Add( m_canvas, 2, wxGROW | wxALL, 5); |
113 | sizer1->Add( m_text, 1, wxGROW | wxALL, 5 ); | |
2480be69 GRG |
114 | |
115 | wxBoxSizer *sizer2 = new wxBoxSizer( wxHORIZONTAL ); | |
29b07a38 GRG |
116 | sizer2->Add( m_list, 0, wxGROW | wxALL, 5 ); |
117 | sizer2->Add( sizer1, 1, wxGROW | wxALL, 5 ); | |
2480be69 GRG |
118 | |
119 | wxBoxSizer *sizer3 = new wxBoxSizer( wxVERTICAL ); | |
120 | sizer3->Add( CreateTextSizer(_("Select one configuration")), 0, wxALL, 10 ); | |
121 | sizer3->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT, 10 ); | |
29b07a38 | 122 | sizer3->Add( sizer2, 1, wxGROW | wxALL, 5 ); |
2480be69 GRG |
123 | sizer3->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT, 10 ); |
124 | sizer3->Add( CreateButtonSizer(wxOK | wxCANCEL), 0, wxCENTRE | wxALL, 10 ); | |
125 | ||
126 | // activate | |
127 | SetSizer(sizer3); | |
128 | SetAutoLayout(TRUE); | |
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 | ||
e0a40292 | 139 | const LifeShape& LifeSamplesDialog::GetShape() |
2480be69 | 140 | { |
e0a40292 | 141 | return g_shapes[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(); | |
e0a40292 GRG |
151 | m_text->SetValue(g_shapes[ sel ].m_desc); |
152 | m_life->SetShape(g_shapes[ sel ]); | |
153 | ||
154 | // quick and dirty :-) | |
155 | if ((g_shapes[ sel ].m_width > 36) || | |
156 | (g_shapes[ sel ].m_height > 22)) | |
157 | m_canvas->SetCellSize(2); | |
158 | else | |
159 | m_canvas->SetCellSize(8); | |
2480be69 GRG |
160 | } |
161 | } | |
162 | ||
e0a40292 GRG |
163 | // -------------------------------------------------------------------------- |
164 | // LifeAboutDialog | |
165 | // -------------------------------------------------------------------------- | |
166 | ||
167 | LifeAboutDialog::LifeAboutDialog(wxWindow *parent) | |
168 | : wxDialog(parent, -1, | |
169 | _("About Life!"), | |
170 | wxDefaultPosition, | |
171 | wxDefaultSize, | |
172 | wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL) | |
173 | { | |
174 | // logo | |
175 | wxBitmap bmp = wxBITMAP(life); | |
176 | #if !defined(__WXGTK__) && !defined(__WXMOTIF__) | |
177 | bmp.SetMask(new wxMask(bmp, *wxBLUE)); | |
178 | #endif | |
179 | wxStaticBitmap *sbmp = new wxStaticBitmap(this, -1, bmp); | |
180 | ||
181 | // layout components | |
182 | wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL ); | |
183 | sizer->Add( sbmp, 0, wxCENTRE | wxALL, 10 ); | |
184 | sizer->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT, 5 ); | |
29b07a38 | 185 | sizer->Add( CreateTextSizer(_("Life! version 2.1 for wxWindows\n\n" |
e0a40292 GRG |
186 | "(c) 2000 Guillermo Rodriguez Garcia\n\n" |
187 | "<guille@iies.es>\n\n" | |
030d06e1 | 188 | "Portions of the code are based in XLife;\n" |
e0a40292 GRG |
189 | "XLife is (c) 1989 by Jon Bennett et al.")), |
190 | 0, wxCENTRE | wxALL, 20 ); | |
191 | sizer->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT, 5 ); | |
192 | sizer->Add( CreateButtonSizer(wxOK), 0, wxCENTRE | wxALL, 10 ); | |
193 | ||
194 | // activate | |
195 | SetSizer(sizer); | |
196 | SetAutoLayout(TRUE); | |
197 | sizer->SetSizeHints(this); | |
198 | sizer->Fit(this); | |
199 | Centre(wxBOTH | wxCENTRE_ON_SCREEN); | |
200 | } | |
29b07a38 GRG |
201 | |
202 | ||
203 |