]> git.saurik.com Git - wxWidgets.git/blob - demos/forty/forty.cpp
Fixed compilation error.
[wxWidgets.git] / demos / forty / forty.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: forty.cpp
3 // Purpose: Forty Thieves patience game
4 // Author: Chris Breeze
5 // Modified by:
6 // Created: 21/07/97
7 // RCS-ID: $Id$
8 // Copyright: (c) 1993-1998 Chris Breeze
9 // Licence: wxWindows licence
10 //---------------------------------------------------------------------------
11 // Last modified: 22nd July 1998 - ported to wxWindows 2.0
12 /////////////////////////////////////////////////////////////////////////////
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #pragma interface
17 #endif
18
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #ifndef WX_PRECOMP
27 #include "wx/wx.h"
28 #endif
29
30 #include "canvas.h"
31 #include "forty.h"
32 #include "card.h"
33 #include "scoredg.h"
34 #ifdef wx_x
35 #include "cards.xbm"
36 #endif
37
38 class FortyFrame: public wxFrame
39 {
40 public:
41 FortyFrame(wxFrame* frame, char* title, int x, int y, int w, int h,bool largecards);
42 virtual ~FortyFrame();
43
44 void OnCloseWindow(wxCloseEvent& event);
45
46 // Menu callbacks
47 void NewGame(wxCommandEvent& event);
48 void Exit(wxCommandEvent& event);
49 void About(wxCommandEvent& event);
50 void Undo(wxCommandEvent& event);
51 void Redo(wxCommandEvent& event);
52 void Scores(wxCommandEvent& event);
53 void ToggleRightButtonUndo(wxCommandEvent& event);
54 void ToggleHelpingHand(wxCommandEvent& event);
55 void ToggleCardSize(wxCommandEvent& event);
56
57 DECLARE_EVENT_TABLE()
58
59 private:
60 enum MenuCommands { NEW_GAME = 10, SCORES, EXIT,
61 UNDO, REDO,
62 RIGHT_BUTTON_UNDO, HELPING_HAND, LARGE_CARDS,
63 ABOUT };
64
65 wxMenuBar* m_menuBar;
66 FortyCanvas* m_canvas;
67 };
68
69 BEGIN_EVENT_TABLE(FortyFrame, wxFrame)
70 EVT_MENU(NEW_GAME, FortyFrame::NewGame)
71 EVT_MENU(EXIT, FortyFrame::Exit)
72 EVT_MENU(ABOUT, FortyFrame::About)
73 EVT_MENU(UNDO, FortyFrame::Undo)
74 EVT_MENU(REDO, FortyFrame::Redo)
75 EVT_MENU(SCORES, FortyFrame::Scores)
76 EVT_MENU(RIGHT_BUTTON_UNDO, FortyFrame::ToggleRightButtonUndo)
77 EVT_MENU(HELPING_HAND, FortyFrame::ToggleHelpingHand)
78 EVT_MENU(LARGE_CARDS, FortyFrame::ToggleCardSize)
79 EVT_CLOSE(FortyFrame::OnCloseWindow)
80 END_EVENT_TABLE()
81
82 // Create a new application object
83 IMPLEMENT_APP (FortyApp)
84
85 wxColour* FortyApp::m_backgroundColour = 0;
86 wxColour* FortyApp::m_textColour = 0;
87 wxBrush* FortyApp::m_backgroundBrush = 0;
88
89 bool FortyApp::OnInit()
90 {
91 bool largecards = FALSE;
92 wxSize size(668,510);
93
94 if ((argc > 1) && (!wxStrcmp(argv[1],"-L")))
95 {
96 largecards = TRUE;
97 size = wxSize(1000,750);
98 }
99
100 FortyFrame* frame = new FortyFrame(
101 0,
102 "Forty Thieves",
103 -1, -1, size.x, size.y,largecards
104 );
105
106 // Show the frame
107 frame->Show(TRUE);
108
109 return TRUE;
110 }
111
112 const wxColour& FortyApp::BackgroundColour()
113 {
114 if (!m_backgroundColour)
115 {
116 m_backgroundColour = new wxColour(0, 128, 0);
117 }
118
119 return *m_backgroundColour;
120 }
121
122 const wxBrush& FortyApp::BackgroundBrush()
123 {
124 if (!m_backgroundBrush)
125 {
126 m_backgroundBrush = new wxBrush(BackgroundColour(), wxSOLID);
127 }
128
129 return *m_backgroundBrush;
130 }
131
132 const wxColour& FortyApp::TextColour()
133 {
134 if (!m_textColour)
135 {
136 m_textColour = new wxColour("BLACK");
137 }
138
139 return *m_textColour;
140 }
141
142 // My frame constructor
143 FortyFrame::FortyFrame(wxFrame* frame, char* title, int x, int y, int w, int h,bool largecards):
144 wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
145 {
146 #ifdef __WXMAC__
147 // we need this in order to allow the about menu relocation, since ABOUT is not the default id of the about menu
148 wxApp::s_macAboutMenuItemId = ABOUT ;
149 #endif
150 // set the icon
151 #ifdef __WXMSW__
152 SetIcon(wxIcon("CardsIcon"));
153 #else
154 #ifdef GTK_TBD
155 SetIcon(wxIcon(Cards_bits, Cards_width, Cards_height));
156 #endif
157 #endif
158
159 // Make a menu bar
160 wxMenu* gameMenu = new wxMenu;
161 gameMenu->Append(NEW_GAME, "&New", "Start a new game");
162 gameMenu->Append(SCORES, "&Scores...", "Displays scores");
163 gameMenu->Append(EXIT, "E&xit", "Exits Forty Thieves");
164
165 wxMenu* editMenu = new wxMenu;
166 editMenu->Append(UNDO, "&Undo", "Undo the last move");
167 editMenu->Append(REDO, "&Redo", "Redo a move that has been undone");
168
169 wxMenu* optionsMenu = new wxMenu;
170 optionsMenu->Append(RIGHT_BUTTON_UNDO,
171 "&Right button undo",
172 "Enables/disables right mouse button undo and redo",
173 TRUE
174 );
175 optionsMenu->Append(HELPING_HAND,
176 "&Helping hand",
177 "Enables/disables hand cursor when a card can be moved",
178 TRUE
179 );
180 optionsMenu->Append(LARGE_CARDS,
181 "&Large cards",
182 "Enables/disables large cards for high resolution displays",
183 TRUE
184 );
185 optionsMenu->Check(HELPING_HAND, TRUE);
186 optionsMenu->Check(RIGHT_BUTTON_UNDO, TRUE);
187 optionsMenu->Check(LARGE_CARDS, largecards ? TRUE : FALSE);
188
189 wxMenu* helpMenu = new wxMenu;
190 helpMenu->Append(ABOUT, "&About", "Displays program version information");
191
192 m_menuBar = new wxMenuBar;
193 m_menuBar->Append(gameMenu, "&Game");
194 m_menuBar->Append(editMenu, "&Edit");
195 m_menuBar->Append(optionsMenu, "&Options");
196 m_menuBar->Append(helpMenu, "&Help");
197
198 SetMenuBar(m_menuBar);
199
200 if (largecards)
201 Card::SetScale(1.3);
202
203 m_canvas = new FortyCanvas(this, 0, 0, 400, 400);
204 wxLayoutConstraints* constr = new wxLayoutConstraints;
205 constr->left.SameAs(this, wxLeft);
206 constr->top.SameAs(this, wxTop);
207 constr->right.SameAs(this, wxRight);
208 constr->height.SameAs(this, wxHeight);
209 m_canvas->SetConstraints(constr);
210
211 CreateStatusBar();
212 }
213
214 FortyFrame::~FortyFrame()
215 {
216 }
217
218 void FortyFrame::OnCloseWindow(wxCloseEvent& event)
219 {
220 if (m_canvas->OnCloseCanvas() )
221 {
222 this->Destroy();
223 }
224 else
225 event.Veto();
226 }
227
228 void
229 FortyFrame::NewGame(wxCommandEvent&)
230 {
231 m_canvas->NewGame();
232 }
233
234 void
235 FortyFrame::Exit(wxCommandEvent&)
236 {
237 #ifdef __WXGTK__
238 // wxGTK doesn't call OnClose() so we do it here
239 // if (OnClose())
240 #endif
241 Close(TRUE);
242 }
243
244 void
245 FortyFrame::About(wxCommandEvent&)
246 {
247 wxMessageBox(
248 "Forty Thieves\n\n"
249 "A freeware program using the wxWindows\n"
250 "portable C++ GUI toolkit.\n"
251 "http://www.wxwindows.org\n"
252 "http://www.freiburg.linux.de/~wxxt\n\n"
253 "Author: Chris Breeze (c) 1992-1998\n"
254 "email: chris.breeze@iname.com",
255 "About Forty Thieves",
256 wxOK, this
257 );
258 }
259
260 void
261 FortyFrame::Undo(wxCommandEvent&)
262 {
263 m_canvas->Undo();
264 }
265
266 void
267 FortyFrame::Redo(wxCommandEvent&)
268 {
269 m_canvas->Redo();
270 }
271
272 void
273 FortyFrame::Scores(wxCommandEvent&)
274 {
275 m_canvas->UpdateScores();
276 ScoreDialog scores(this, m_canvas->GetScoreFile());
277 scores.Display();
278 }
279
280 void
281 FortyFrame::ToggleRightButtonUndo(wxCommandEvent& event)
282 {
283 bool checked = m_menuBar->IsChecked(event.GetId());
284 m_canvas->EnableRightButtonUndo(checked);
285 }
286
287 void
288 FortyFrame::ToggleHelpingHand(wxCommandEvent& event)
289 {
290 bool checked = m_menuBar->IsChecked(event.GetId());
291 m_canvas->EnableHelpingHand(checked);
292 }
293
294 void
295 FortyFrame::ToggleCardSize(wxCommandEvent& event)
296 {
297 bool checked = m_menuBar->IsChecked(event.GetId());
298 Card::SetScale(checked ? 1.3 : 1);
299 m_canvas->LayoutGame();
300 m_canvas->Refresh();
301 }
302
303