]> git.saurik.com Git - wxWidgets.git/blame - demos/forty/forty.cpp
SWIGged updates for wxGTK
[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"
fc799548 32#include "card.h"
63cafd27
JS
33#include "scoredg.h"
34#ifdef wx_x
35#include "cards.xbm"
36#endif
37
38class FortyFrame: public wxFrame
39{
40public:
fc799548 41 FortyFrame(wxFrame* frame, char* title, int x, int y, int w, int h,bool largecards);
63cafd27
JS
42 virtual ~FortyFrame();
43
e3065973 44 void OnCloseWindow(wxCloseEvent& event);
63cafd27
JS
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);
fc799548 55 void ToggleCardSize(wxCommandEvent& event);
63cafd27
JS
56
57 DECLARE_EVENT_TABLE()
58
59private:
60 enum MenuCommands { NEW_GAME = 10, SCORES, EXIT,
61 UNDO, REDO,
fc799548 62 RIGHT_BUTTON_UNDO, HELPING_HAND, LARGE_CARDS,
63cafd27
JS
63 ABOUT };
64
65 wxMenuBar* m_menuBar;
66 FortyCanvas* m_canvas;
67};
68
69BEGIN_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)
fc799548 78 EVT_MENU(LARGE_CARDS, FortyFrame::ToggleCardSize)
e3065973 79 EVT_CLOSE(FortyFrame::OnCloseWindow)
63cafd27
JS
80END_EVENT_TABLE()
81
82// Create a new application object
83IMPLEMENT_APP (FortyApp)
84
85wxColour* FortyApp::m_backgroundColour = 0;
86wxColour* FortyApp::m_textColour = 0;
87wxBrush* FortyApp::m_backgroundBrush = 0;
88
89bool FortyApp::OnInit()
90{
fc799548
JS
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
63cafd27
JS
100 FortyFrame* frame = new FortyFrame(
101 0,
102 "Forty Thieves",
fc799548 103 -1, -1, size.x, size.y,largecards
63cafd27
JS
104 );
105
cba2db0c 106 // Show the frame
63cafd27
JS
107 frame->Show(TRUE);
108
1e6d9499 109 return TRUE;
63cafd27
JS
110}
111
79490c3d 112const wxColour& FortyApp::BackgroundColour()
63cafd27
JS
113{
114 if (!m_backgroundColour)
115 {
116 m_backgroundColour = new wxColour(0, 128, 0);
117 }
79490c3d
VZ
118
119 return *m_backgroundColour;
63cafd27
JS
120}
121
79490c3d 122const wxBrush& FortyApp::BackgroundBrush()
63cafd27
JS
123{
124 if (!m_backgroundBrush)
125 {
16553659 126 m_backgroundBrush = new wxBrush(BackgroundColour(), wxSOLID);
63cafd27 127 }
79490c3d
VZ
128
129 return *m_backgroundBrush;
63cafd27
JS
130}
131
79490c3d 132const wxColour& FortyApp::TextColour()
63cafd27
JS
133{
134 if (!m_textColour)
135 {
136 m_textColour = new wxColour("BLACK");
137 }
79490c3d
VZ
138
139 return *m_textColour;
63cafd27
JS
140}
141
142// My frame constructor
fc799548 143FortyFrame::FortyFrame(wxFrame* frame, char* title, int x, int y, int w, int h,bool largecards):
63cafd27
JS
144 wxFrame(frame, -1, title, wxPoint(x, y), wxSize(w, h))
145{
8fbb465f
SC
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
63cafd27
JS
150 // set the icon
151#ifdef __WXMSW__
16553659 152 SetIcon(wxIcon("CardsIcon"));
63cafd27
JS
153#else
154#ifdef GTK_TBD
16553659 155 SetIcon(wxIcon(Cards_bits, Cards_width, Cards_height));
63cafd27
JS
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 );
fc799548
JS
180 optionsMenu->Append(LARGE_CARDS,
181 "&Large cards",
182 "Enables/disables large cards for high resolution displays",
183 TRUE
184 );
63cafd27
JS
185 optionsMenu->Check(HELPING_HAND, TRUE);
186 optionsMenu->Check(RIGHT_BUTTON_UNDO, TRUE);
fc799548 187 optionsMenu->Check(LARGE_CARDS, largecards ? TRUE : FALSE);
63cafd27
JS
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
fc799548
JS
200 if (largecards)
201 Card::SetScale(1.3);
202
63cafd27
JS
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
214FortyFrame::~FortyFrame()
215{
216}
217
e3065973 218void FortyFrame::OnCloseWindow(wxCloseEvent& event)
63cafd27 219{
cba2db0c 220 if (m_canvas->OnCloseCanvas() )
e3065973
JS
221 {
222 this->Destroy();
223 }
224 else
225 event.Veto();
63cafd27
JS
226}
227
228void
229FortyFrame::NewGame(wxCommandEvent&)
230{
231 m_canvas->NewGame();
232}
233
234void
235FortyFrame::Exit(wxCommandEvent&)
236{
237#ifdef __WXGTK__
238 // wxGTK doesn't call OnClose() so we do it here
e3065973 239// if (OnClose())
63cafd27
JS
240#endif
241 Close(TRUE);
242}
243
244void
245FortyFrame::About(wxCommandEvent&)
246{
247 wxMessageBox(
248 "Forty Thieves\n\n"
249 "A freeware program using the wxWindows\n"
250 "portable C++ GUI toolkit.\n"
281b0186 251 "http://www.wxwindows.org\n"
63cafd27
JS
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
260void
261FortyFrame::Undo(wxCommandEvent&)
262{
263 m_canvas->Undo();
264}
265
266void
267FortyFrame::Redo(wxCommandEvent&)
268{
269 m_canvas->Redo();
270}
271
272void
273FortyFrame::Scores(wxCommandEvent&)
274{
275 m_canvas->UpdateScores();
276 ScoreDialog scores(this, m_canvas->GetScoreFile());
277 scores.Display();
278}
279
280void
281FortyFrame::ToggleRightButtonUndo(wxCommandEvent& event)
282{
283 bool checked = m_menuBar->IsChecked(event.GetId());
284 m_canvas->EnableRightButtonUndo(checked);
285}
286
287void
288FortyFrame::ToggleHelpingHand(wxCommandEvent& event)
289{
290 bool checked = m_menuBar->IsChecked(event.GetId());
291 m_canvas->EnableHelpingHand(checked);
292}
fc799548
JS
293
294void
295FortyFrame::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