]>
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 // ==========================================================================
14 // ==========================================================================
16 // --------------------------------------------------------------------------
18 // --------------------------------------------------------------------------
21 #pragma implementation "dialogs.h"
24 // for compilers that support precompilation, includes "wx/wx.h"
25 #include "wx/wxprec.h"
31 // for all others, include the necessary headers
36 #include "wx/statline.h"
37 #include "wx/spinctrl.h"
43 // --------------------------------------------------------------------------
45 // --------------------------------------------------------------------------
47 // IDs for the controls and the menu commands
50 // listbox in samples dialog
54 // sample configurations
55 #include "samples.inc"
57 // --------------------------------------------------------------------------
58 // event tables and other macros for wxWindows
59 // --------------------------------------------------------------------------
62 BEGIN_EVENT_TABLE(LifeNewGameDialog
, wxDialog
)
63 EVT_BUTTON (wxID_OK
, LifeNewGameDialog::OnOK
)
66 BEGIN_EVENT_TABLE(LifeSamplesDialog
, wxDialog
)
67 EVT_LISTBOX (ID_LISTBOX
, LifeSamplesDialog::OnListBox
)
71 // ==========================================================================
73 // ==========================================================================
75 // --------------------------------------------------------------------------
77 // --------------------------------------------------------------------------
79 LifeNewGameDialog::LifeNewGameDialog(wxWindow
*parent
, int *w
, int *h
)
80 : wxDialog(parent
, -1,
84 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
)
90 m_spinctrlw
= new wxSpinCtrl( this, -1 );
91 m_spinctrlw
->SetValue(*m_w
);
92 m_spinctrlw
->SetRange(LIFE_MIN
, LIFE_MAX
);
94 m_spinctrlh
= new wxSpinCtrl( this, -1 );
95 m_spinctrlh
->SetValue(*m_h
);
96 m_spinctrlh
->SetRange(LIFE_MIN
, LIFE_MAX
);
99 wxBoxSizer
*inputsizer1
= new wxBoxSizer( wxHORIZONTAL
);
100 inputsizer1
->Add( new wxStaticText(this, -1, _("Width")), 1, wxCENTRE
| wxLEFT
, 20);
101 inputsizer1
->Add( m_spinctrlw
, 2, wxCENTRE
| wxLEFT
| wxRIGHT
, 20 );
103 wxBoxSizer
*inputsizer2
= new wxBoxSizer( wxHORIZONTAL
);
104 inputsizer2
->Add( new wxStaticText(this, -1, _("Height")), 1, wxCENTRE
| wxLEFT
, 20);
105 inputsizer2
->Add( m_spinctrlh
, 2, wxCENTRE
| wxLEFT
| wxRIGHT
, 20 );
107 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
108 topsizer
->Add( CreateTextSizer(_("Enter board dimensions")), 0, wxALL
, 10 );
109 topsizer
->Add( new wxStaticLine(this, -1), 0, wxGROW
| wxLEFT
| wxRIGHT
| wxBOTTOM
, 10);
110 topsizer
->Add( inputsizer1
, 1, wxGROW
| wxLEFT
| wxRIGHT
, 5 );
111 topsizer
->Add( inputsizer2
, 1, wxGROW
| wxLEFT
| wxRIGHT
, 5 );
112 topsizer
->Add( new wxStaticLine(this, -1), 0, wxGROW
| wxLEFT
| wxRIGHT
| wxTOP
, 10);
113 topsizer
->Add( CreateButtonSizer(wxOK
| wxCANCEL
), 0, wxCENTRE
| wxALL
, 10);
118 topsizer
->SetSizeHints(this);
123 void LifeNewGameDialog::OnOK(wxCommandEvent
& WXUNUSED(event
))
125 *m_w
= m_spinctrlw
->GetValue();
126 *m_h
= m_spinctrlh
->GetValue();
131 // --------------------------------------------------------------------------
133 // --------------------------------------------------------------------------
135 LifeSamplesDialog::LifeSamplesDialog(wxWindow
*parent
)
136 : wxDialog(parent
, -1,
140 wxDEFAULT_DIALOG_STYLE
| wxDIALOG_MODAL
)
144 // create and populate the list of available samples
145 m_list
= new wxListBox( this, ID_LISTBOX
,
149 wxLB_SINGLE
| wxLB_NEEDED_SB
| wxLB_HSCROLL
);
151 for (unsigned i
= 0; i
< (sizeof(g_shapes
) / sizeof(LifeShape
)); i
++)
152 m_list
->Append(g_shapes
[i
].m_name
);
155 wxStaticBox
*statbox
= new wxStaticBox( this, -1, _("Description"));
156 m_life
= new Life( 16, 16 );
157 m_life
->SetShape(g_shapes
[0]);
158 m_canvas
= new LifeCanvas( this, m_life
, FALSE
);
159 m_text
= new wxTextCtrl( this, -1,
163 wxTE_MULTILINE
| wxTE_READONLY
);
166 wxStaticBoxSizer
*sizer1
= new wxStaticBoxSizer( statbox
, wxVERTICAL
);
167 sizer1
->Add( m_canvas
, 2, wxGROW
| wxCENTRE
| wxALL
, 5);
168 sizer1
->Add( m_text
, 1, wxGROW
| wxCENTRE
| wxALL
, 5 );
170 wxBoxSizer
*sizer2
= new wxBoxSizer( wxHORIZONTAL
);
171 sizer2
->Add( m_list
, 0, wxGROW
| wxCENTRE
| wxALL
, 5 );
172 sizer2
->Add( sizer1
, 1, wxGROW
| wxCENTRE
| wxALL
, 5 );
174 wxBoxSizer
*sizer3
= new wxBoxSizer( wxVERTICAL
);
175 sizer3
->Add( CreateTextSizer(_("Select one configuration")), 0, wxALL
, 10 );
176 sizer3
->Add( new wxStaticLine(this, -1), 0, wxGROW
| wxLEFT
| wxRIGHT
, 10 );
177 sizer3
->Add( sizer2
, 1, wxGROW
| wxCENTRE
| wxALL
, 5 );
178 sizer3
->Add( new wxStaticLine(this, -1), 0, wxGROW
| wxLEFT
| wxRIGHT
, 10 );
179 sizer3
->Add( CreateButtonSizer(wxOK
| wxCANCEL
), 0, wxCENTRE
| wxALL
, 10 );
184 sizer3
->SetSizeHints(this);
189 LifeSamplesDialog::~LifeSamplesDialog()
195 int LifeSamplesDialog::GetValue()
200 void LifeSamplesDialog::OnListBox(wxCommandEvent
& event
)
202 if (event
.GetSelection() != -1)
204 m_value
= m_list
->GetSelection();
205 m_text
->SetValue(g_shapes
[ event
.GetSelection() ].m_desc
);
206 m_life
->SetShape(g_shapes
[ event
.GetSelection() ]);
208 m_canvas
->DrawEverything(TRUE
); // force redraw everything
209 m_canvas
->Refresh(FALSE
); // do not erase background