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