]>
Commit | Line | Data |
---|---|---|
63cafd27 JS |
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 "scoredg.h" | |
33 | #ifdef wx_x | |
34 | #include "cards.xbm" | |
35 | #endif | |
36 | ||
37 | class FortyFrame: public wxFrame | |
38 | { | |
39 | public: | |
40 | FortyFrame(wxFrame* frame, char* title, int x, int y, int w, int h); | |
41 | virtual ~FortyFrame(); | |
42 | ||
43 | bool OnClose(); | |
44 | ||
45 | // Menu callbacks | |
46 | void NewGame(wxCommandEvent& event); | |
47 | void Exit(wxCommandEvent& event); | |
48 | void About(wxCommandEvent& event); | |
49 | void Undo(wxCommandEvent& event); | |
50 | void Redo(wxCommandEvent& event); | |
51 | void Scores(wxCommandEvent& event); | |
52 | void ToggleRightButtonUndo(wxCommandEvent& event); | |
53 | void ToggleHelpingHand(wxCommandEvent& event); | |
54 | ||
55 | DECLARE_EVENT_TABLE() | |
56 | ||
57 | private: | |
58 | enum MenuCommands { NEW_GAME = 10, SCORES, EXIT, | |
59 | UNDO, REDO, | |
60 | RIGHT_BUTTON_UNDO, HELPING_HAND, | |
61 | ABOUT }; | |
62 | ||
63 | wxMenuBar* m_menuBar; | |
64 | FortyCanvas* m_canvas; | |
65 | }; | |
66 | ||
67 | BEGIN_EVENT_TABLE(FortyFrame, wxFrame) | |
68 | EVT_MENU(NEW_GAME, FortyFrame::NewGame) | |
69 | EVT_MENU(EXIT, FortyFrame::Exit) | |
70 | EVT_MENU(ABOUT, FortyFrame::About) | |
71 | EVT_MENU(UNDO, FortyFrame::Undo) | |
72 | EVT_MENU(REDO, FortyFrame::Redo) | |
73 | EVT_MENU(SCORES, FortyFrame::Scores) | |
74 | EVT_MENU(RIGHT_BUTTON_UNDO, FortyFrame::ToggleRightButtonUndo) | |
75 | EVT_MENU(HELPING_HAND, FortyFrame::ToggleHelpingHand) | |
76 | END_EVENT_TABLE() | |
77 | ||
78 | // Create a new application object | |
79 | IMPLEMENT_APP (FortyApp) | |
80 | ||
81 | wxColour* FortyApp::m_backgroundColour = 0; | |
82 | wxColour* FortyApp::m_textColour = 0; | |
83 | wxBrush* FortyApp::m_backgroundBrush = 0; | |
84 | ||
85 | bool FortyApp::OnInit() | |
86 | { | |
87 | FortyFrame* frame = new FortyFrame( | |
88 | 0, | |
89 | "Forty Thieves", | |
90 | -1, -1, 668, 510 | |
91 | ); | |
92 | ||
93 | // Show the frame | |
94 | frame->Show(TRUE); | |
95 | ||
96 | return true; | |
97 | } | |
98 | ||
99 | wxColour* FortyApp::BackgroundColour() | |
100 | { | |
101 | if (!m_backgroundColour) | |
102 | { | |
103 | m_backgroundColour = new wxColour(0, 128, 0); | |
104 | } | |
105 | return m_backgroundColour; | |
106 | } | |
107 | ||
108 | wxBrush* FortyApp::BackgroundBrush() | |
109 | { | |
110 | if (!m_backgroundBrush) | |
111 | { | |
112 | m_backgroundBrush = new wxBrush(*BackgroundColour(), wxSOLID); | |
113 | } | |
114 | return m_backgroundBrush; | |
115 | } | |
116 | ||
117 | wxColour* FortyApp::TextColour() | |
118 | { | |
119 | if (!m_textColour) | |
120 | { | |
121 | m_textColour = new wxColour("BLACK"); | |
122 | } | |
123 | return m_textColour; | |
124 | } | |
125 | ||
126 | // My frame constructor | |
127 | FortyFrame::FortyFrame(wxFrame* frame, char* title, int x, int y, int w, int h): | |
128 | wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h)) | |
129 | { | |
130 | // set the icon | |
131 | #ifdef __WXMSW__ | |
132 | SetIcon(new wxIcon("CardsIcon")); | |
133 | #else | |
134 | #ifdef GTK_TBD | |
135 | SetIcon(new wxIcon(Cards_bits, Cards_width, Cards_height)); | |
136 | #endif | |
137 | #endif | |
138 | ||
139 | // Make a menu bar | |
140 | wxMenu* gameMenu = new wxMenu; | |
141 | gameMenu->Append(NEW_GAME, "&New", "Start a new game"); | |
142 | gameMenu->Append(SCORES, "&Scores...", "Displays scores"); | |
143 | gameMenu->Append(EXIT, "E&xit", "Exits Forty Thieves"); | |
144 | ||
145 | wxMenu* editMenu = new wxMenu; | |
146 | editMenu->Append(UNDO, "&Undo", "Undo the last move"); | |
147 | editMenu->Append(REDO, "&Redo", "Redo a move that has been undone"); | |
148 | ||
149 | wxMenu* optionsMenu = new wxMenu; | |
150 | optionsMenu->Append(RIGHT_BUTTON_UNDO, | |
151 | "&Right button undo", | |
152 | "Enables/disables right mouse button undo and redo", | |
153 | TRUE | |
154 | ); | |
155 | optionsMenu->Append(HELPING_HAND, | |
156 | "&Helping hand", | |
157 | "Enables/disables hand cursor when a card can be moved", | |
158 | TRUE | |
159 | ); | |
160 | optionsMenu->Check(HELPING_HAND, TRUE); | |
161 | optionsMenu->Check(RIGHT_BUTTON_UNDO, TRUE); | |
162 | ||
163 | wxMenu* helpMenu = new wxMenu; | |
164 | helpMenu->Append(ABOUT, "&About", "Displays program version information"); | |
165 | ||
166 | m_menuBar = new wxMenuBar; | |
167 | m_menuBar->Append(gameMenu, "&Game"); | |
168 | m_menuBar->Append(editMenu, "&Edit"); | |
169 | m_menuBar->Append(optionsMenu, "&Options"); | |
170 | m_menuBar->Append(helpMenu, "&Help"); | |
171 | ||
172 | SetMenuBar(m_menuBar); | |
173 | ||
174 | m_canvas = new FortyCanvas(this, 0, 0, 400, 400); | |
175 | wxLayoutConstraints* constr = new wxLayoutConstraints; | |
176 | constr->left.SameAs(this, wxLeft); | |
177 | constr->top.SameAs(this, wxTop); | |
178 | constr->right.SameAs(this, wxRight); | |
179 | constr->height.SameAs(this, wxHeight); | |
180 | m_canvas->SetConstraints(constr); | |
181 | ||
182 | CreateStatusBar(); | |
183 | } | |
184 | ||
185 | FortyFrame::~FortyFrame() | |
186 | { | |
187 | } | |
188 | ||
189 | bool FortyFrame::OnClose() | |
190 | { | |
191 | return m_canvas->OnClose(); | |
192 | } | |
193 | ||
194 | void | |
195 | FortyFrame::NewGame(wxCommandEvent&) | |
196 | { | |
197 | m_canvas->NewGame(); | |
198 | } | |
199 | ||
200 | void | |
201 | FortyFrame::Exit(wxCommandEvent&) | |
202 | { | |
203 | #ifdef __WXGTK__ | |
204 | // wxGTK doesn't call OnClose() so we do it here | |
205 | if (OnClose()) | |
206 | #endif | |
207 | Close(TRUE); | |
208 | } | |
209 | ||
210 | void | |
211 | FortyFrame::About(wxCommandEvent&) | |
212 | { | |
213 | wxMessageBox( | |
214 | "Forty Thieves\n\n" | |
215 | "A freeware program using the wxWindows\n" | |
216 | "portable C++ GUI toolkit.\n" | |
217 | "http://web.ukonline.co.uk/julian.smart/wxwin\n" | |
218 | "http://www.freiburg.linux.de/~wxxt\n\n" | |
219 | "Author: Chris Breeze (c) 1992-1998\n" | |
220 | "email: chris.breeze@iname.com", | |
221 | "About Forty Thieves", | |
222 | wxOK, this | |
223 | ); | |
224 | } | |
225 | ||
226 | void | |
227 | FortyFrame::Undo(wxCommandEvent&) | |
228 | { | |
229 | m_canvas->Undo(); | |
230 | } | |
231 | ||
232 | void | |
233 | FortyFrame::Redo(wxCommandEvent&) | |
234 | { | |
235 | m_canvas->Redo(); | |
236 | } | |
237 | ||
238 | void | |
239 | FortyFrame::Scores(wxCommandEvent&) | |
240 | { | |
241 | m_canvas->UpdateScores(); | |
242 | ScoreDialog scores(this, m_canvas->GetScoreFile()); | |
243 | scores.Display(); | |
244 | } | |
245 | ||
246 | void | |
247 | FortyFrame::ToggleRightButtonUndo(wxCommandEvent& event) | |
248 | { | |
249 | bool checked = m_menuBar->IsChecked(event.GetId()); | |
250 | m_canvas->EnableRightButtonUndo(checked); | |
251 | } | |
252 | ||
253 | void | |
254 | FortyFrame::ToggleHelpingHand(wxCommandEvent& event) | |
255 | { | |
256 | bool checked = m_menuBar->IsChecked(event.GetId()); | |
257 | m_canvas->EnableHelpingHand(checked); | |
258 | } |