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