]> git.saurik.com Git - wxWidgets.git/blame - demos/forty/forty.cpp
configure changes, for wxBase and wx-config
[wxWidgets.git] / demos / forty / forty.cpp
CommitLineData
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
37class FortyFrame: public wxFrame
38{
39public:
40 FortyFrame(wxFrame* frame, char* title, int x, int y, int w, int h);
41 virtual ~FortyFrame();
42
e3065973 43 void OnCloseWindow(wxCloseEvent& event);
63cafd27
JS
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
57private:
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
67BEGIN_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)
e3065973 76 EVT_CLOSE(FortyFrame::OnCloseWindow)
63cafd27
JS
77END_EVENT_TABLE()
78
79// Create a new application object
80IMPLEMENT_APP (FortyApp)
81
82wxColour* FortyApp::m_backgroundColour = 0;
83wxColour* FortyApp::m_textColour = 0;
84wxBrush* FortyApp::m_backgroundBrush = 0;
85
86bool FortyApp::OnInit()
87{
88 FortyFrame* frame = new FortyFrame(
89 0,
90 "Forty Thieves",
91 -1, -1, 668, 510
92 );
93
cba2db0c 94 // Show the frame
63cafd27
JS
95 frame->Show(TRUE);
96
1e6d9499 97 return TRUE;
63cafd27
JS
98}
99
79490c3d 100const wxColour& FortyApp::BackgroundColour()
63cafd27
JS
101{
102 if (!m_backgroundColour)
103 {
104 m_backgroundColour = new wxColour(0, 128, 0);
105 }
79490c3d
VZ
106
107 return *m_backgroundColour;
63cafd27
JS
108}
109
79490c3d 110const wxBrush& FortyApp::BackgroundBrush()
63cafd27
JS
111{
112 if (!m_backgroundBrush)
113 {
16553659 114 m_backgroundBrush = new wxBrush(BackgroundColour(), wxSOLID);
63cafd27 115 }
79490c3d
VZ
116
117 return *m_backgroundBrush;
63cafd27
JS
118}
119
79490c3d 120const wxColour& FortyApp::TextColour()
63cafd27
JS
121{
122 if (!m_textColour)
123 {
124 m_textColour = new wxColour("BLACK");
125 }
79490c3d
VZ
126
127 return *m_textColour;
63cafd27
JS
128}
129
130// My frame constructor
131FortyFrame::FortyFrame(wxFrame* frame, char* title, int x, int y, int w, int h):
132 wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
133{
8fbb465f
SC
134#ifdef __WXMAC__
135 // we need this in order to allow the about menu relocation, since ABOUT is not the default id of the about menu
136 wxApp::s_macAboutMenuItemId = ABOUT ;
137#endif
63cafd27
JS
138 // set the icon
139#ifdef __WXMSW__
16553659 140 SetIcon(wxIcon("CardsIcon"));
63cafd27
JS
141#else
142#ifdef GTK_TBD
16553659 143 SetIcon(wxIcon(Cards_bits, Cards_width, Cards_height));
63cafd27
JS
144#endif
145#endif
146
147 // Make a menu bar
148 wxMenu* gameMenu = new wxMenu;
149 gameMenu->Append(NEW_GAME, "&New", "Start a new game");
150 gameMenu->Append(SCORES, "&Scores...", "Displays scores");
151 gameMenu->Append(EXIT, "E&xit", "Exits Forty Thieves");
152
153 wxMenu* editMenu = new wxMenu;
154 editMenu->Append(UNDO, "&Undo", "Undo the last move");
155 editMenu->Append(REDO, "&Redo", "Redo a move that has been undone");
156
157 wxMenu* optionsMenu = new wxMenu;
158 optionsMenu->Append(RIGHT_BUTTON_UNDO,
159 "&Right button undo",
160 "Enables/disables right mouse button undo and redo",
161 TRUE
162 );
163 optionsMenu->Append(HELPING_HAND,
164 "&Helping hand",
165 "Enables/disables hand cursor when a card can be moved",
166 TRUE
167 );
168 optionsMenu->Check(HELPING_HAND, TRUE);
169 optionsMenu->Check(RIGHT_BUTTON_UNDO, TRUE);
170
171 wxMenu* helpMenu = new wxMenu;
172 helpMenu->Append(ABOUT, "&About", "Displays program version information");
173
174 m_menuBar = new wxMenuBar;
175 m_menuBar->Append(gameMenu, "&Game");
176 m_menuBar->Append(editMenu, "&Edit");
177 m_menuBar->Append(optionsMenu, "&Options");
178 m_menuBar->Append(helpMenu, "&Help");
179
180 SetMenuBar(m_menuBar);
181
182 m_canvas = new FortyCanvas(this, 0, 0, 400, 400);
183 wxLayoutConstraints* constr = new wxLayoutConstraints;
184 constr->left.SameAs(this, wxLeft);
185 constr->top.SameAs(this, wxTop);
186 constr->right.SameAs(this, wxRight);
187 constr->height.SameAs(this, wxHeight);
188 m_canvas->SetConstraints(constr);
189
190 CreateStatusBar();
191}
192
193FortyFrame::~FortyFrame()
194{
195}
196
e3065973 197void FortyFrame::OnCloseWindow(wxCloseEvent& event)
63cafd27 198{
cba2db0c 199 if (m_canvas->OnCloseCanvas() )
e3065973
JS
200 {
201 this->Destroy();
202 }
203 else
204 event.Veto();
63cafd27
JS
205}
206
207void
208FortyFrame::NewGame(wxCommandEvent&)
209{
210 m_canvas->NewGame();
211}
212
213void
214FortyFrame::Exit(wxCommandEvent&)
215{
216#ifdef __WXGTK__
217 // wxGTK doesn't call OnClose() so we do it here
e3065973 218// if (OnClose())
63cafd27
JS
219#endif
220 Close(TRUE);
221}
222
223void
224FortyFrame::About(wxCommandEvent&)
225{
226 wxMessageBox(
227 "Forty Thieves\n\n"
228 "A freeware program using the wxWindows\n"
229 "portable C++ GUI toolkit.\n"
230 "http://web.ukonline.co.uk/julian.smart/wxwin\n"
231 "http://www.freiburg.linux.de/~wxxt\n\n"
232 "Author: Chris Breeze (c) 1992-1998\n"
233 "email: chris.breeze@iname.com",
234 "About Forty Thieves",
235 wxOK, this
236 );
237}
238
239void
240FortyFrame::Undo(wxCommandEvent&)
241{
242 m_canvas->Undo();
243}
244
245void
246FortyFrame::Redo(wxCommandEvent&)
247{
248 m_canvas->Redo();
249}
250
251void
252FortyFrame::Scores(wxCommandEvent&)
253{
254 m_canvas->UpdateScores();
255 ScoreDialog scores(this, m_canvas->GetScoreFile());
256 scores.Display();
257}
258
259void
260FortyFrame::ToggleRightButtonUndo(wxCommandEvent& event)
261{
262 bool checked = m_menuBar->IsChecked(event.GetId());
263 m_canvas->EnableRightButtonUndo(checked);
264}
265
266void
267FortyFrame::ToggleHelpingHand(wxCommandEvent& event)
268{
269 bool checked = m_menuBar->IsChecked(event.GetId());
270 m_canvas->EnableHelpingHand(checked);
271}