]>
git.saurik.com Git - wxWidgets.git/blob - demos/life/dialogs.cpp
1 /////////////////////////////////////////////////////////////////////////////
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 // ==========================================================================
17 #pragma implementation "dialogs.h"
20 // For compilers that support precompilation, includes "wx/wx.h".
21 #include "wx/wxprec.h"
31 #include "wx/statline.h"
32 #include "wx/minifram.h"
33 #include "wx/settings.h"
40 // --------------------------------------------------------------------------
42 // --------------------------------------------------------------------------
44 #include "bitmaps/life.xpm"
46 // sample configurations
47 #include "samples.inc"
49 // --------------------------------------------------------------------------
51 // --------------------------------------------------------------------------
53 // IDs for the controls and the menu commands
56 // listbox in samples dialog
60 // --------------------------------------------------------------------------
61 // event tables and other macros for wxWidgets
62 // --------------------------------------------------------------------------
65 BEGIN_EVENT_TABLE(LifeSamplesDialog
, wxDialog
)
66 EVT_LISTBOX (ID_LISTBOX
, LifeSamplesDialog::OnListBox
)
70 // ==========================================================================
72 // ==========================================================================
74 // --------------------------------------------------------------------------
76 // --------------------------------------------------------------------------
78 LifeSamplesDialog::LifeSamplesDialog(wxWindow
*parent
)
79 : wxDialog(parent
, wxID_ANY
, _("Sample games"),
80 wxDefaultPosition
, wxDefaultSize
)
84 wxSize listSize
= wxDefaultSize
;
85 bool isPDA
= wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
;
87 // Screens are generally horizontal in orientation,
88 // but PDAs are generally vertical.
89 bool screenIsHorizontal
= true;
91 wxSystemSettings::GetMetric(wxSYS_SCREEN_X
) < wxSystemSettings::GetMetric(wxSYS_SCREEN_Y
))
93 listSize
= wxSize(-1, 50);
94 screenIsHorizontal
= false;
97 // create and populate the list of available samples
98 m_list
= new wxListBox( this, ID_LISTBOX
,
102 wxLB_SINGLE
| wxLB_NEEDED_SB
| wxLB_HSCROLL
);
104 for (unsigned i
= 0; i
< (sizeof(g_patterns
) / sizeof(LifePattern
)); i
++)
105 m_list
->Append(g_patterns
[i
].m_name
);
108 wxStaticBox
*statbox
= new wxStaticBox( this, wxID_ANY
, _("Description"));
110 m_life
->SetPattern(g_patterns
[0]);
111 m_canvas
= new LifeCanvas( this, m_life
, false );
112 m_text
= new wxTextCtrl( this, wxID_ANY
,
113 g_patterns
[0].m_description
,
116 wxTE_MULTILINE
| wxTE_READONLY
);
120 wxStaticBoxSizer
*sizer1
= new wxStaticBoxSizer( statbox
, wxVERTICAL
);
121 sizer1
->Add( m_canvas
, 2, wxGROW
| wxALL
, 5);
122 sizer1
->Add( m_text
, 1, wxGROW
| wxALL
, 5 );
124 wxBoxSizer
*sizer2
= new wxBoxSizer( screenIsHorizontal
? wxHORIZONTAL
: wxVERTICAL
);
125 sizer2
->Add( m_list
, 0, wxGROW
| wxALL
, 5 );
126 sizer2
->Add( sizer1
, 1, wxGROW
| wxALL
, 5 );
128 wxBoxSizer
*sizer3
= new wxBoxSizer( wxVERTICAL
);
129 sizer3
->Add( CreateTextSizer(_("Select a configuration")), 0, wxALL
|wxCENTRE
, isPDA
? 2 : 10 );
132 sizer3
->Add( new wxStaticLine(this, wxID_ANY
), 0, wxGROW
| wxLEFT
| wxRIGHT
, 10 );
133 #endif // wxUSE_STATLINE
134 sizer3
->Add( sizer2
, 1, wxGROW
| wxALL
, 5 );
137 sizer3
->Add( new wxStaticLine(this, wxID_ANY
), 0, wxGROW
| wxLEFT
| wxRIGHT
, 10 );
138 #endif // wxUSE_STATLINE
140 #if defined(__SMARTPHONE__)
141 SetLeftMenu(wxID_CANCEL
);
142 SetRightMenu(wxID_OK
);
148 #if !defined(__POCKETPC__) && !defined(__SMARTPHONE__)
149 sizer3
->Add( CreateButtonSizer(wxOK
| wxCANCEL
), 0, wxCENTRE
| wxALL
, isPDA
? 2 : 10 );
150 sizer3
->SetSizeHints(this);
152 Centre(wxBOTH
| wxCENTRE_ON_SCREEN
);
156 LifeSamplesDialog::~LifeSamplesDialog()
161 const LifePattern
& LifeSamplesDialog::GetPattern()
163 return g_patterns
[m_value
];
166 void LifeSamplesDialog::OnListBox(wxCommandEvent
& event
)
168 int sel
= event
.GetSelection();
172 m_value
= m_list
->GetSelection();
173 m_text
->SetValue(g_patterns
[ sel
].m_description
);
174 m_life
->SetPattern(g_patterns
[ sel
]);
176 // these values shouldn't be hardcoded...
177 if ((size_t)sel
< (sizeof(g_patterns
) / sizeof(LifePattern
)) - 3)
178 m_canvas
->SetCellSize(8);
180 m_canvas
->SetCellSize(2);
184 // --------------------------------------------------------------------------
186 // --------------------------------------------------------------------------
188 LifeAboutDialog::LifeAboutDialog(wxWindow
*parent
)
189 : wxDialog(parent
, wxID_ANY
, _("About Life!"),
190 wxDefaultPosition
, wxDefaultSize
)
193 wxStaticBitmap
*sbmp
= new wxStaticBitmap(this, wxID_ANY
, wxBitmap(life_xpm
));
196 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
197 sizer
->Add( sbmp
, 0, wxCENTRE
| wxALL
, 10 );
199 sizer
->Add( new wxStaticLine(this, wxID_ANY
), 0, wxGROW
| wxLEFT
| wxRIGHT
, 5 );
200 #endif // wxUSE_STATLINE
201 sizer
->Add( CreateTextSizer(_("Life! version 2.2 for wxWidgets\n\n\
202 (c) 2000 Guillermo Rodriguez Garcia\n\n\
203 <guille@iies.es>\n\n\
204 Portions of the code are based in XLife;\n\
205 XLife is (c) 1989 by Jon Bennett et al.")),
206 0, wxCENTRE
| wxALL
, 20 );
208 sizer
->Add( new wxStaticLine(this, wxID_ANY
), 0, wxGROW
| wxLEFT
| wxRIGHT
, 5 );
209 #endif // wxUSE_STATLINE
211 #if ! (defined(__SMARTPHONE__) || defined(__POCKETPC__))
212 sizer
->Add( CreateButtonSizer(wxOK
), 0, wxCENTRE
| wxALL
, 10 );
218 #if ! (defined(__SMARTPHONE__) || defined(__POCKETPC__))
219 sizer
->SetSizeHints(this);
221 Centre(wxBOTH
| wxCENTRE_ON_SCREEN
);