]>
git.saurik.com Git - wxWidgets.git/blob - demos/forty/forty.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Forty Thieves patience game
4 // Author: Chris Breeze
8 // Copyright: (c) 1993-1998 Chris Breeze
9 // Licence: wxWindows licence
10 //---------------------------------------------------------------------------
11 // Last modified: 22nd July 1998 - ported to wxWindows 2.0
12 /////////////////////////////////////////////////////////////////////////////
15 #pragma implementation
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
38 class FortyFrame
: public wxFrame
41 FortyFrame(wxFrame
* frame
, char* title
, int x
, int y
, int w
, int h
,bool largecards
);
42 virtual ~FortyFrame();
44 void OnCloseWindow(wxCloseEvent
& event
);
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
);
60 enum MenuCommands
{ NEW_GAME
= 10, SCORES
, EXIT
,
62 RIGHT_BUTTON_UNDO
, HELPING_HAND
, LARGE_CARDS
,
66 FortyCanvas
* m_canvas
;
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
)
82 // Create a new application object
83 IMPLEMENT_APP (FortyApp
)
85 wxColour
* FortyApp::m_backgroundColour
= 0;
86 wxColour
* FortyApp::m_textColour
= 0;
87 wxBrush
* FortyApp::m_backgroundBrush
= 0;
89 bool FortyApp::OnInit()
91 bool largecards
= FALSE
;
94 if ((argc
> 1) && (!wxStrcmp(argv
[1],"-L")))
97 size
= wxSize(1000,750);
100 FortyFrame
* frame
= new FortyFrame(
103 -1, -1, size
.x
, size
.y
,largecards
112 const wxColour
& FortyApp::BackgroundColour()
114 if (!m_backgroundColour
)
116 m_backgroundColour
= new wxColour(0, 128, 0);
119 return *m_backgroundColour
;
122 const wxBrush
& FortyApp::BackgroundBrush()
124 if (!m_backgroundBrush
)
126 m_backgroundBrush
= new wxBrush(BackgroundColour(), wxSOLID
);
129 return *m_backgroundBrush
;
132 const wxColour
& FortyApp::TextColour()
136 m_textColour
= new wxColour("BLACK");
139 return *m_textColour
;
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
))
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
;
152 SetIcon(wxIcon("CardsIcon"));
155 SetIcon(wxIcon(Cards_bits
, Cards_width
, Cards_height
));
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");
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");
169 wxMenu
* optionsMenu
= new wxMenu
;
170 optionsMenu
->Append(RIGHT_BUTTON_UNDO
,
171 "&Right button undo",
172 "Enables/disables right mouse button undo and redo",
175 optionsMenu
->Append(HELPING_HAND
,
177 "Enables/disables hand cursor when a card can be moved",
180 optionsMenu
->Append(LARGE_CARDS
,
182 "Enables/disables large cards for high resolution displays",
185 optionsMenu
->Check(HELPING_HAND
, TRUE
);
186 optionsMenu
->Check(RIGHT_BUTTON_UNDO
, TRUE
);
187 optionsMenu
->Check(LARGE_CARDS
, largecards
? TRUE
: FALSE
);
189 wxMenu
* helpMenu
= new wxMenu
;
190 helpMenu
->Append(ABOUT
, "&About", "Displays program version information");
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");
198 SetMenuBar(m_menuBar
);
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
);
214 FortyFrame::~FortyFrame()
218 void FortyFrame::OnCloseWindow(wxCloseEvent
& event
)
220 if (m_canvas
->OnCloseCanvas() )
229 FortyFrame::NewGame(wxCommandEvent
&)
235 FortyFrame::Exit(wxCommandEvent
&)
238 // wxGTK doesn't call OnClose() so we do it here
245 FortyFrame::About(wxCommandEvent
&)
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",
261 FortyFrame::Undo(wxCommandEvent
&)
267 FortyFrame::Redo(wxCommandEvent
&)
273 FortyFrame::Scores(wxCommandEvent
&)
275 m_canvas
->UpdateScores();
276 ScoreDialog
scores(this, m_canvas
->GetScoreFile());
281 FortyFrame::ToggleRightButtonUndo(wxCommandEvent
& event
)
283 bool checked
= m_menuBar
->IsChecked(event
.GetId());
284 m_canvas
->EnableRightButtonUndo(checked
);
288 FortyFrame::ToggleHelpingHand(wxCommandEvent
& event
)
290 bool checked
= m_menuBar
->IsChecked(event
.GetId());
291 m_canvas
->EnableHelpingHand(checked
);
295 FortyFrame::ToggleCardSize(wxCommandEvent
& event
)
297 bool checked
= m_menuBar
->IsChecked(event
.GetId());
298 Card::SetScale(checked
? 1.3 : 1);
299 m_canvas
->LayoutGame();