]> git.saurik.com Git - wxWidgets.git/blob - demos/life/dialogs.cpp
Use wxFindWindowAtPoint() for hit testing in wxPopupTransientWindow.
[wxWidgets.git] / demos / life / dialogs.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: life/dialogs.cpp
3 // Purpose: Life! dialogs
4 // Author: Guillermo Rodriguez Garcia, <guille@iies.es>
5 // Modified by:
6 // Created: Jan/2000
7 // Copyright: (c) 2000, Guillermo Rodriguez Garcia
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // ==========================================================================
12 // headers, declarations, constants
13 // ==========================================================================
14
15 // For compilers that support precompilation, includes "wx/wx.h".
16 #include "wx/wxprec.h"
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #ifndef WX_PRECOMP
23 #include "wx/wx.h"
24 #endif
25
26 #include "wx/statline.h"
27 #include "wx/minifram.h"
28 #include "wx/settings.h"
29
30 #include "dialogs.h"
31 #include "life.h"
32 #include "game.h"
33
34
35 // --------------------------------------------------------------------------
36 // resources
37 // --------------------------------------------------------------------------
38
39 #include "bitmaps/life.xpm"
40
41 // sample configurations
42 #include "samples.inc"
43
44 // --------------------------------------------------------------------------
45 // constants
46 // --------------------------------------------------------------------------
47
48 // IDs for the controls and the menu commands
49 enum
50 {
51 // listbox in samples dialog
52 ID_LISTBOX
53 };
54
55 // --------------------------------------------------------------------------
56 // event tables and other macros for wxWidgets
57 // --------------------------------------------------------------------------
58
59 // Event tables
60 BEGIN_EVENT_TABLE(LifeSamplesDialog, wxDialog)
61 EVT_LISTBOX (ID_LISTBOX, LifeSamplesDialog::OnListBox)
62 END_EVENT_TABLE()
63
64
65 // ==========================================================================
66 // implementation
67 // ==========================================================================
68
69 // --------------------------------------------------------------------------
70 // LifeSamplesDialog
71 // --------------------------------------------------------------------------
72
73 LifeSamplesDialog::LifeSamplesDialog(wxWindow *parent)
74 : wxDialog(parent, wxID_ANY, _("Sample games"),
75 wxDefaultPosition, wxDefaultSize)
76 {
77 m_value = 0;
78
79 wxSize listSize = wxDefaultSize;
80 bool isPDA = wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA;
81
82 // Screens are generally horizontal in orientation,
83 // but PDAs are generally vertical.
84 bool screenIsHorizontal = true;
85 if (isPDA &&
86 wxSystemSettings::GetMetric(wxSYS_SCREEN_X) < wxSystemSettings::GetMetric(wxSYS_SCREEN_Y))
87 {
88 listSize = wxSize(wxDefaultCoord, 50);
89 screenIsHorizontal = false;
90 }
91
92 // create and populate the list of available samples
93 m_list = new wxListBox( this, ID_LISTBOX,
94 wxDefaultPosition,
95 listSize,
96 0, NULL,
97 wxLB_SINGLE | wxLB_NEEDED_SB | wxLB_HSCROLL );
98
99 for (unsigned i = 0; i < (sizeof(g_patterns) / sizeof(LifePattern)); i++)
100 m_list->Append(g_patterns[i].m_name);
101
102 // descriptions
103 wxStaticBox *statbox = new wxStaticBox( this, wxID_ANY, _("Description"));
104 m_life = new Life();
105 m_life->SetPattern(g_patterns[0]);
106 m_canvas = new LifeCanvas( this, m_life, false );
107 m_text = new wxTextCtrl( this, wxID_ANY,
108 g_patterns[0].m_description,
109 wxDefaultPosition,
110 wxSize(300, 60),
111 wxTE_MULTILINE | wxTE_READONLY);
112
113 // layout components
114
115 wxStaticBoxSizer *sizer1 = new wxStaticBoxSizer( statbox, wxVERTICAL );
116 sizer1->Add( m_canvas, 2, wxGROW | wxALL, 5);
117 sizer1->Add( m_text, 1, wxGROW | wxALL, 5 );
118
119 wxBoxSizer *sizer2 = new wxBoxSizer( screenIsHorizontal ? wxHORIZONTAL : wxVERTICAL );
120 sizer2->Add( m_list, 0, wxGROW | wxALL, 5 );
121 sizer2->Add( sizer1, 1, wxGROW | wxALL, 5 );
122
123 wxBoxSizer *sizer3 = new wxBoxSizer( wxVERTICAL );
124 sizer3->Add( CreateTextSizer(_("Select a configuration")), 0, wxALL|wxCENTRE, isPDA ? 2 : 10 );
125 #if wxUSE_STATLINE
126 if (!isPDA)
127 sizer3->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 10 );
128 #endif // wxUSE_STATLINE
129 sizer3->Add( sizer2, 1, wxGROW | wxALL, 5 );
130
131 wxSizer *sizerBtns = CreateButtonSizer(wxOK|wxCANCEL);
132 if ( sizerBtns )
133 {
134 sizer3->Add(sizerBtns, wxSizerFlags().Expand().Border());
135 }
136
137 // activate
138 SetSizer(sizer3);
139 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
140 sizer3->SetSizeHints(this);
141 sizer3->Fit(this);
142 Centre(wxBOTH | wxCENTRE_ON_SCREEN);
143 #endif
144 }
145
146 LifeSamplesDialog::~LifeSamplesDialog()
147 {
148 m_canvas->Destroy();
149 }
150
151 const LifePattern& LifeSamplesDialog::GetPattern()
152 {
153 return g_patterns[m_value];
154 }
155
156 void LifeSamplesDialog::OnListBox(wxCommandEvent& event)
157 {
158 int sel = event.GetSelection();
159
160 if (sel != -1)
161 {
162 m_value = m_list->GetSelection();
163 m_text->SetValue(g_patterns[ sel ].m_description);
164 m_life->SetPattern(g_patterns[ sel ]);
165
166 // these values shouldn't be hardcoded...
167 if ((size_t)sel < (sizeof(g_patterns) / sizeof(LifePattern)) - 3)
168 m_canvas->SetCellSize(8);
169 else
170 m_canvas->SetCellSize(2);
171 }
172 }
173
174 // --------------------------------------------------------------------------
175 // LifeAboutDialog
176 // --------------------------------------------------------------------------
177
178 LifeAboutDialog::LifeAboutDialog(wxWindow *parent)
179 : wxDialog(parent, wxID_ANY, _("About Life!"),
180 wxDefaultPosition, wxDefaultSize)
181 {
182 // logo
183 wxStaticBitmap *sbmp = new wxStaticBitmap(this, wxID_ANY, wxBitmap(life_xpm));
184
185 // layout components
186 wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
187 sizer->Add( sbmp, 0, wxCENTRE | wxALL, 10 );
188 #if wxUSE_STATLINE
189 sizer->Add( new wxStaticLine(this, wxID_ANY), 0, wxGROW | wxLEFT | wxRIGHT, 5 );
190 #endif // wxUSE_STATLINE
191 sizer->Add( CreateTextSizer(_("Life! version 2.2 for wxWidgets\n\n\
192 (c) 2000 Guillermo Rodriguez Garcia\n\n\
193 <guille@iies.es>\n\n\
194 Portions of the code are based in XLife;\n\
195 XLife is (c) 1989 by Jon Bennett et al.")),
196 0, wxCENTRE | wxRIGHT|wxLEFT|wxTOP, 20 );
197
198 // buttons if any
199 wxSizer *sizerBtns = CreateButtonSizer(wxOK);
200 if ( sizerBtns )
201 {
202 sizer->Add(sizerBtns, wxSizerFlags().Expand().Border());
203 }
204
205 // activate
206 SetSizer(sizer);
207 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
208 sizer->SetSizeHints(this);
209 sizer->Fit(this);
210 Centre(wxBOTH | wxCENTRE_ON_SCREEN);
211 #endif
212 }