]>
git.saurik.com Git - wxWidgets.git/blob - demos/life/dialogs.cpp
36e98059a7d70c7b6a767e268a104e8797b9826f
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: life/dialogs.cpp
3 // Purpose: Life! dialogs
4 // Author: Guillermo Rodriguez Garcia, <guille@iies.es>
8 // Copyright: (c) 2000, Guillermo Rodriguez Garcia
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ==========================================================================
13 // headers, declarations, constants
14 // ==========================================================================
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/statline.h"
28 #include "wx/minifram.h"
29 #include "wx/settings.h"
36 // --------------------------------------------------------------------------
38 // --------------------------------------------------------------------------
40 #include "bitmaps/life.xpm"
42 // sample configurations
43 #include "samples.inc"
45 // --------------------------------------------------------------------------
47 // --------------------------------------------------------------------------
49 // IDs for the controls and the menu commands
52 // listbox in samples dialog
56 // --------------------------------------------------------------------------
57 // event tables and other macros for wxWidgets
58 // --------------------------------------------------------------------------
61 BEGIN_EVENT_TABLE(LifeSamplesDialog
, wxDialog
)
62 EVT_LISTBOX (ID_LISTBOX
, LifeSamplesDialog::OnListBox
)
66 // ==========================================================================
68 // ==========================================================================
70 // --------------------------------------------------------------------------
72 // --------------------------------------------------------------------------
74 LifeSamplesDialog::LifeSamplesDialog(wxWindow
*parent
)
75 : wxDialog(parent
, wxID_ANY
, _("Sample games"),
76 wxDefaultPosition
, wxDefaultSize
)
80 wxSize listSize
= wxDefaultSize
;
81 bool isPDA
= wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
;
83 // Screens are generally horizontal in orientation,
84 // but PDAs are generally vertical.
85 bool screenIsHorizontal
= true;
87 wxSystemSettings::GetMetric(wxSYS_SCREEN_X
) < wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
))
89 listSize
= wxSize(wxDefaultCoord
, 50);
90 screenIsHorizontal
= false;
93 // create and populate the list of available samples
94 m_list
= new wxListBox( this, ID_LISTBOX
,
98 wxLB_SINGLE
| wxLB_NEEDED_SB
| wxLB_HSCROLL
);
100 for (unsigned i
= 0; i
< (sizeof(g_patterns
) / sizeof(LifePattern
)); i
++)
101 m_list
->Append(g_patterns
[i
].m_name
);
104 wxStaticBox
*statbox
= new wxStaticBox( this, wxID_ANY
, _("Description"));
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
,
112 wxTE_MULTILINE
| wxTE_READONLY
);
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 );
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 );
124 wxBoxSizer
*sizer3
= new wxBoxSizer( wxVERTICAL
);
125 sizer3
->Add( CreateTextSizer(_("Select a configuration")), 0, wxALL
|wxCENTRE
, isPDA
? 2 : 10 );
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 );
132 wxSizer
*buttonSizer
= CreateButtonSizer( wxOK
|wxCANCEL
, true, 10 );
133 if(buttonSizer
->GetChildren().GetCount() > 0 )
135 sizer3
->Add( buttonSizer
, 0, wxEXPAND
| wxALL
, 10 );
139 sizer3
->AddSpacer( 10 );
145 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
146 sizer3
->SetSizeHints(this);
148 Centre(wxBOTH
| wxCENTRE_ON_SCREEN
);
152 LifeSamplesDialog::~LifeSamplesDialog()
157 const LifePattern
& LifeSamplesDialog::GetPattern()
159 return g_patterns
[m_value
];
162 void LifeSamplesDialog::OnListBox(wxCommandEvent
& event
)
164 int sel
= event
.GetSelection();
168 m_value
= m_list
->GetSelection();
169 m_text
->SetValue(g_patterns
[ sel
].m_description
);
170 m_life
->SetPattern(g_patterns
[ sel
]);
172 // these values shouldn't be hardcoded...
173 if ((size_t)sel
< (sizeof(g_patterns
) / sizeof(LifePattern
)) - 3)
174 m_canvas
->SetCellSize(8);
176 m_canvas
->SetCellSize(2);
180 // --------------------------------------------------------------------------
182 // --------------------------------------------------------------------------
184 LifeAboutDialog::LifeAboutDialog(wxWindow
*parent
)
185 : wxDialog(parent
, wxID_ANY
, _("About Life!"),
186 wxDefaultPosition
, wxDefaultSize
)
189 wxStaticBitmap
*sbmp
= new wxStaticBitmap(this, wxID_ANY
, wxBitmap(life_xpm
));
192 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
193 sizer
->Add( sbmp
, 0, wxCENTRE
| wxALL
, 10 );
195 sizer
->Add( new wxStaticLine(this, wxID_ANY
), 0, wxGROW
| wxLEFT
| wxRIGHT
, 5 );
196 #endif // wxUSE_STATLINE
197 sizer
->Add( CreateTextSizer(_("Life! version 2.2 for wxWidgets\n\n\
198 (c) 2000 Guillermo Rodriguez Garcia\n\n\
199 <guille@iies.es>\n\n\
200 Portions of the code are based in XLife;\n\
201 XLife is (c) 1989 by Jon Bennett et al.")),
202 0, wxCENTRE
| wxRIGHT
|wxLEFT
|wxTOP
, 20 );
205 wxSizer
*buttonSizer
= CreateButtonSizer( wxOK
, true, 10 );
206 if(buttonSizer
->GetChildren().GetCount() > 0 )
208 sizer
->Add( buttonSizer
, 0, wxEXPAND
| wxALL
, 10 );
212 sizer
->AddSpacer( 20 );
218 #if !defined(__SMARTPHONE__) && !defined(__POCKETPC__)
219 sizer
->SetSizeHints(this);
221 Centre(wxBOTH
| wxCENTRE_ON_SCREEN
);