]>
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 | ||
2480be69 GRG |
20 | #include "wx/statline.h" |
21 | #include "wx/spinctrl.h" | |
22 | ||
23 | #include "dialogs.h" | |
24 | #include "life.h" | |
25 | #include "game.h" | |
26 | ||
e0a40292 GRG |
27 | // -------------------------------------------------------------------------- |
28 | // resources | |
29 | // -------------------------------------------------------------------------- | |
30 | ||
31 | #if defined(__WXGTK__) || defined(__WXMOTIF__) | |
32 | // logo for the about dialog | |
33 | #include "bitmaps/life.xpm" | |
34 | #endif | |
35 | ||
36 | // sample configurations | |
37 | #include "samples.inc" | |
38 | ||
2480be69 GRG |
39 | // -------------------------------------------------------------------------- |
40 | // constants | |
41 | // -------------------------------------------------------------------------- | |
42 | ||
43 | // IDs for the controls and the menu commands | |
44 | enum | |
45 | { | |
e0a40292 GRG |
46 | // bmp window in about dialog |
47 | ID_BMPWIN = 2001, | |
48 | ||
2480be69 | 49 | // listbox in samples dialog |
e0a40292 | 50 | ID_LISTBOX |
2480be69 GRG |
51 | }; |
52 | ||
2480be69 GRG |
53 | // -------------------------------------------------------------------------- |
54 | // event tables and other macros for wxWindows | |
55 | // -------------------------------------------------------------------------- | |
56 | ||
57 | // Event tables | |
2480be69 GRG |
58 | BEGIN_EVENT_TABLE(LifeSamplesDialog, wxDialog) |
59 | EVT_LISTBOX (ID_LISTBOX, LifeSamplesDialog::OnListBox) | |
e0a40292 | 60 | |
2480be69 GRG |
61 | END_EVENT_TABLE() |
62 | ||
63 | ||
64 | // ========================================================================== | |
65 | // implementation | |
66 | // ========================================================================== | |
67 | ||
2480be69 GRG |
68 | // -------------------------------------------------------------------------- |
69 | // LifeSamplesDialog | |
70 | // -------------------------------------------------------------------------- | |
71 | ||
72 | LifeSamplesDialog::LifeSamplesDialog(wxWindow *parent) | |
73 | : wxDialog(parent, -1, | |
74 | _("Sample games"), | |
75 | wxDefaultPosition, | |
76 | wxDefaultSize, | |
77 | wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL) | |
78 | { | |
79 | m_value = 0; | |
80 | ||
81 | // create and populate the list of available samples | |
82 | m_list = new wxListBox( this, ID_LISTBOX, | |
83 | wxDefaultPosition, | |
84 | wxDefaultSize, | |
85 | 0, NULL, | |
86 | wxLB_SINGLE | wxLB_NEEDED_SB | wxLB_HSCROLL ); | |
87 | ||
88 | for (unsigned i = 0; i < (sizeof(g_shapes) / sizeof(LifeShape)); i++) | |
89 | m_list->Append(g_shapes[i].m_name); | |
90 | ||
91 | // descriptions | |
92 | wxStaticBox *statbox = new wxStaticBox( this, -1, _("Description")); | |
e0a40292 | 93 | m_life = new Life(); |
2480be69 GRG |
94 | m_life->SetShape(g_shapes[0]); |
95 | m_canvas = new LifeCanvas( this, m_life, FALSE ); | |
96 | m_text = new wxTextCtrl( this, -1, | |
97 | g_shapes[0].m_desc, | |
98 | wxDefaultPosition, | |
99 | wxSize(300, 60), | |
100 | wxTE_MULTILINE | wxTE_READONLY); | |
101 | ||
102 | // layout components | |
103 | wxStaticBoxSizer *sizer1 = new wxStaticBoxSizer( statbox, wxVERTICAL ); | |
104 | sizer1->Add( m_canvas, 2, wxGROW | wxCENTRE | wxALL, 5); | |
105 | sizer1->Add( m_text, 1, wxGROW | wxCENTRE | wxALL, 5 ); | |
106 | ||
107 | wxBoxSizer *sizer2 = new wxBoxSizer( wxHORIZONTAL ); | |
108 | sizer2->Add( m_list, 0, wxGROW | wxCENTRE | wxALL, 5 ); | |
109 | sizer2->Add( sizer1, 1, wxGROW | wxCENTRE | wxALL, 5 ); | |
110 | ||
111 | wxBoxSizer *sizer3 = new wxBoxSizer( wxVERTICAL ); | |
112 | sizer3->Add( CreateTextSizer(_("Select one configuration")), 0, wxALL, 10 ); | |
113 | sizer3->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT, 10 ); | |
114 | sizer3->Add( sizer2, 1, wxGROW | wxCENTRE | wxALL, 5 ); | |
115 | sizer3->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT, 10 ); | |
116 | sizer3->Add( CreateButtonSizer(wxOK | wxCANCEL), 0, wxCENTRE | wxALL, 10 ); | |
117 | ||
118 | // activate | |
119 | SetSizer(sizer3); | |
120 | SetAutoLayout(TRUE); | |
121 | sizer3->SetSizeHints(this); | |
122 | sizer3->Fit(this); | |
e0a40292 | 123 | Centre(wxBOTH | wxCENTRE_ON_SCREEN); |
2480be69 GRG |
124 | } |
125 | ||
126 | LifeSamplesDialog::~LifeSamplesDialog() | |
127 | { | |
128 | m_canvas->Destroy(); | |
2480be69 GRG |
129 | } |
130 | ||
e0a40292 | 131 | const LifeShape& LifeSamplesDialog::GetShape() |
2480be69 | 132 | { |
e0a40292 | 133 | return g_shapes[m_value]; |
2480be69 GRG |
134 | } |
135 | ||
136 | void LifeSamplesDialog::OnListBox(wxCommandEvent& event) | |
137 | { | |
e0a40292 GRG |
138 | int sel = event.GetSelection(); |
139 | ||
140 | if (sel != -1) | |
2480be69 GRG |
141 | { |
142 | m_value = m_list->GetSelection(); | |
e0a40292 GRG |
143 | m_text->SetValue(g_shapes[ sel ].m_desc); |
144 | m_life->SetShape(g_shapes[ sel ]); | |
145 | ||
146 | // quick and dirty :-) | |
147 | if ((g_shapes[ sel ].m_width > 36) || | |
148 | (g_shapes[ sel ].m_height > 22)) | |
149 | m_canvas->SetCellSize(2); | |
150 | else | |
151 | m_canvas->SetCellSize(8); | |
2480be69 GRG |
152 | } |
153 | } | |
154 | ||
e0a40292 GRG |
155 | // -------------------------------------------------------------------------- |
156 | // LifeAboutDialog | |
157 | // -------------------------------------------------------------------------- | |
158 | ||
159 | LifeAboutDialog::LifeAboutDialog(wxWindow *parent) | |
160 | : wxDialog(parent, -1, | |
161 | _("About Life!"), | |
162 | wxDefaultPosition, | |
163 | wxDefaultSize, | |
164 | wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL) | |
165 | { | |
166 | // logo | |
167 | wxBitmap bmp = wxBITMAP(life); | |
168 | #if !defined(__WXGTK__) && !defined(__WXMOTIF__) | |
169 | bmp.SetMask(new wxMask(bmp, *wxBLUE)); | |
170 | #endif | |
171 | wxStaticBitmap *sbmp = new wxStaticBitmap(this, -1, bmp); | |
172 | ||
173 | // layout components | |
174 | wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL ); | |
175 | sizer->Add( sbmp, 0, wxCENTRE | wxALL, 10 ); | |
176 | sizer->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT, 5 ); | |
177 | sizer->Add( CreateTextSizer(_("Life! for wxWindows, version 2.0\n\n" | |
178 | "(c) 2000 Guillermo Rodriguez Garcia\n\n" | |
179 | "<guille@iies.es>\n\n" | |
180 | "Portions of the code are based in XLife\n" | |
181 | "XLife is (c) 1989 by Jon Bennett et al.")), | |
182 | 0, wxCENTRE | wxALL, 20 ); | |
183 | sizer->Add( new wxStaticLine(this, -1), 0, wxGROW | wxLEFT | wxRIGHT, 5 ); | |
184 | sizer->Add( CreateButtonSizer(wxOK), 0, wxCENTRE | wxALL, 10 ); | |
185 | ||
186 | // activate | |
187 | SetSizer(sizer); | |
188 | SetAutoLayout(TRUE); | |
189 | sizer->SetSizeHints(this); | |
190 | sizer->Fit(this); | |
191 | Centre(wxBOTH | wxCENTRE_ON_SCREEN); | |
192 | } |