]>
git.saurik.com Git - wxWidgets.git/blob - demos/life/dialogs.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: life/dialogs.cpp
3 // Purpose: Life! dialogs
4 // Author: Guillermo Rodriguez Garcia, <guille@iies.es>
7 // Copyright: (c) 2000, Guillermo Rodriguez Garcia
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ==========================================================================
12 // headers, declarations, constants
13 // ==========================================================================
15 // For compilers that support precompilation, includes "wx/wx.h".
16 #include "wx/wxprec.h"
26 #include "wx/statline.h"
27 #include "wx/minifram.h"
28 #include "wx/settings.h"
35 // --------------------------------------------------------------------------
37 // --------------------------------------------------------------------------
39 #include "bitmaps/life.xpm"
41 // sample configurations
42 #include "samples.inc"
44 // --------------------------------------------------------------------------
46 // --------------------------------------------------------------------------
48 // IDs for the controls and the menu commands
51 // listbox in samples dialog
55 // --------------------------------------------------------------------------
56 // event tables and other macros for wxWidgets
57 // --------------------------------------------------------------------------
60 BEGIN_EVENT_TABLE(LifeSamplesDialog
, wxDialog
)
61 EVT_LISTBOX (ID_LISTBOX
, LifeSamplesDialog::OnListBox
)
65 // ==========================================================================
67 // ==========================================================================
69 // --------------------------------------------------------------------------
71 // --------------------------------------------------------------------------
73 LifeSamplesDialog::LifeSamplesDialog(wxWindow
*parent
)
74 : wxDialog(parent
, wxID_ANY
, _("Sample games"),
75 wxDefaultPosition
, wxDefaultSize
)
79 wxSize listSize
= wxDefaultSize
;
80 bool isPDA
= wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
;
82 // Screens are generally horizontal in orientation,
83 // but PDAs are generally vertical.
84 bool screenIsHorizontal
= true;
86 wxSystemSettings::GetMetric(wxSYS_SCREEN_X
) < wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
))
88 listSize
= wxSize(wxDefaultCoord
, 50);
89 screenIsHorizontal
= false;
92 // create and populate the list of available samples
93 m_list
= new wxListBox( this, ID_LISTBOX
,
97 wxLB_SINGLE
| wxLB_NEEDED_SB
| wxLB_HSCROLL
);
99 for (unsigned i
= 0; i
< (sizeof(g_patterns
) / sizeof(LifePattern
)); i
++)
100 m_list
->Append(g_patterns
[i
].m_name
);
103 wxStaticBox
*statbox
= new wxStaticBox( this, wxID_ANY
, _("Description"));
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
,
111 wxTE_MULTILINE
| wxTE_READONLY
);
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 );
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 );
123 wxBoxSizer
*sizer3
= new wxBoxSizer( wxVERTICAL
);
124 sizer3
->Add( CreateTextSizer(_("Select a configuration")), 0, wxALL
|wxCENTRE
, isPDA
? 2 : 10 );
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 );
131 wxSizer
*sizerBtns
= CreateButtonSizer(wxOK
|wxCANCEL
);
134 sizer3
->Add(sizerBtns
, wxSizerFlags().Expand().Border());
139 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
140 sizer3
->SetSizeHints(this);
142 Centre(wxBOTH
| wxCENTRE_ON_SCREEN
);
146 LifeSamplesDialog::~LifeSamplesDialog()
151 const LifePattern
& LifeSamplesDialog::GetPattern()
153 return g_patterns
[m_value
];
156 void LifeSamplesDialog::OnListBox(wxCommandEvent
& event
)
158 int sel
= event
.GetSelection();
162 m_value
= m_list
->GetSelection();
163 m_text
->SetValue(g_patterns
[ sel
].m_description
);
164 m_life
->SetPattern(g_patterns
[ sel
]);
166 // these values shouldn't be hardcoded...
167 if ((size_t)sel
< (sizeof(g_patterns
) / sizeof(LifePattern
)) - 3)
168 m_canvas
->SetCellSize(8);
170 m_canvas
->SetCellSize(2);
174 // --------------------------------------------------------------------------
176 // --------------------------------------------------------------------------
178 LifeAboutDialog::LifeAboutDialog(wxWindow
*parent
)
179 : wxDialog(parent
, wxID_ANY
, _("About Life!"),
180 wxDefaultPosition
, wxDefaultSize
)
183 wxStaticBitmap
*sbmp
= new wxStaticBitmap(this, wxID_ANY
, wxBitmap(life_xpm
));
186 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
187 sizer
->Add( sbmp
, 0, wxCENTRE
| wxALL
, 10 );
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 );
199 wxSizer
*sizerBtns
= CreateButtonSizer(wxOK
);
202 sizer
->Add(sizerBtns
, wxSizerFlags().Expand().Border());
207 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
208 sizer
->SetSizeHints(this);
210 Centre(wxBOTH
| wxCENTRE_ON_SCREEN
);