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