]>
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"
39 // --------------------------------------------------------------------------
41 // --------------------------------------------------------------------------
43 #include "bitmaps/life.xpm"
45 // sample configurations
46 #include "samples.inc"
48 // --------------------------------------------------------------------------
50 // --------------------------------------------------------------------------
52 // IDs for the controls and the menu commands
55 // listbox in samples dialog
59 // --------------------------------------------------------------------------
60 // event tables and other macros for wxWidgets
61 // --------------------------------------------------------------------------
64 BEGIN_EVENT_TABLE(LifeSamplesDialog
, wxDialog
)
65 EVT_LISTBOX (ID_LISTBOX
, LifeSamplesDialog::OnListBox
)
69 // ==========================================================================
71 // ==========================================================================
73 // --------------------------------------------------------------------------
75 // --------------------------------------------------------------------------
77 LifeSamplesDialog::LifeSamplesDialog(wxWindow
*parent
)
78 : wxDialog(parent
, wxID_ANY
, _("Sample games"),
79 wxDefaultPosition
, wxDefaultSize
)
83 // create and populate the list of available samples
84 m_list
= new wxListBox( this, ID_LISTBOX
,
88 wxLB_SINGLE
| wxLB_NEEDED_SB
| wxLB_HSCROLL
);
90 for (unsigned i
= 0; i
< (sizeof(g_patterns
) / sizeof(LifePattern
)); i
++)
91 m_list
->Append(g_patterns
[i
].m_name
);
94 wxStaticBox
*statbox
= new wxStaticBox( this, wxID_ANY
, _("Description"));
96 m_life
->SetPattern(g_patterns
[0]);
97 m_canvas
= new LifeCanvas( this, m_life
, false );
98 m_text
= new wxTextCtrl( this, wxID_ANY
,
99 g_patterns
[0].m_description
,
102 wxTE_MULTILINE
| wxTE_READONLY
);
105 wxStaticBoxSizer
*sizer1
= new wxStaticBoxSizer( statbox
, wxVERTICAL
);
106 sizer1
->Add( m_canvas
, 2, wxGROW
| wxALL
, 5);
107 sizer1
->Add( m_text
, 1, wxGROW
| wxALL
, 5 );
109 wxBoxSizer
*sizer2
= new wxBoxSizer( wxHORIZONTAL
);
110 sizer2
->Add( m_list
, 0, wxGROW
| wxALL
, 5 );
111 sizer2
->Add( sizer1
, 1, wxGROW
| wxALL
, 5 );
113 wxBoxSizer
*sizer3
= new wxBoxSizer( wxVERTICAL
);
114 sizer3
->Add( CreateTextSizer(_("Select one configuration")), 0, wxALL
, 10 );
116 sizer3
->Add( new wxStaticLine(this, wxID_ANY
), 0, wxGROW
| wxLEFT
| wxRIGHT
, 10 );
117 #endif // wxUSE_STATLINE
118 sizer3
->Add( sizer2
, 1, wxGROW
| wxALL
, 5 );
120 sizer3
->Add( new wxStaticLine(this, wxID_ANY
), 0, wxGROW
| wxLEFT
| wxRIGHT
, 10 );
121 #endif // wxUSE_STATLINE
122 sizer3
->Add( CreateButtonSizer(wxOK
| wxCANCEL
), 0, wxCENTRE
| wxALL
, 10 );
127 #if !defined(__POCKETPC__) && !defined(__SMARTPHONE__)
128 sizer3
->SetSizeHints(this);
130 Centre(wxBOTH
| wxCENTRE_ON_SCREEN
);
134 LifeSamplesDialog::~LifeSamplesDialog()
139 const LifePattern
& LifeSamplesDialog::GetPattern()
141 return g_patterns
[m_value
];
144 void LifeSamplesDialog::OnListBox(wxCommandEvent
& event
)
146 int sel
= event
.GetSelection();
150 m_value
= m_list
->GetSelection();
151 m_text
->SetValue(g_patterns
[ sel
].m_description
);
152 m_life
->SetPattern(g_patterns
[ sel
]);
154 // these values shouldn't be hardcoded...
155 if ((size_t)sel
< (sizeof(g_patterns
) / sizeof(LifePattern
)) - 3)
156 m_canvas
->SetCellSize(8);
158 m_canvas
->SetCellSize(2);
162 // --------------------------------------------------------------------------
164 // --------------------------------------------------------------------------
166 LifeAboutDialog::LifeAboutDialog(wxWindow
*parent
)
167 : wxDialog(parent
, wxID_ANY
, _("About Life!"),
168 wxDefaultPosition
, wxDefaultSize
)
171 wxStaticBitmap
*sbmp
= new wxStaticBitmap(this, wxID_ANY
, wxBitmap(life_xpm
));
174 wxBoxSizer
*sizer
= new wxBoxSizer( wxVERTICAL
);
175 sizer
->Add( sbmp
, 0, wxCENTRE
| wxALL
, 10 );
177 sizer
->Add( new wxStaticLine(this, wxID_ANY
), 0, wxGROW
| wxLEFT
| wxRIGHT
, 5 );
178 #endif // wxUSE_STATLINE
179 sizer
->Add( CreateTextSizer(_("Life! version 2.2 for wxWidgets\n\n\
180 (c) 2000 Guillermo Rodriguez Garcia\n\n\
181 <guille@iies.es>\n\n\
182 Portions of the code are based in XLife;\n\
183 XLife is (c) 1989 by Jon Bennett et al.")),
184 0, wxCENTRE
| wxALL
, 20 );
186 sizer
->Add( new wxStaticLine(this, wxID_ANY
), 0, wxGROW
| wxLEFT
| wxRIGHT
, 5 );
187 #endif // wxUSE_STATLINE
189 #if ! (defined(__SMARTPHONE__) || defined(__POCKETPC__))
190 sizer
->Add( CreateButtonSizer(wxOK
), 0, wxCENTRE
| wxALL
, 10 );
196 #if ! (defined(__SMARTPHONE__) || defined(__POCKETPC__))
197 sizer
->SetSizeHints(this);
199 Centre(wxBOTH
| wxCENTRE_ON_SCREEN
);