]>
git.saurik.com Git - wxWidgets.git/blob - samples/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"
37 class FortyFrame
: public wxFrame
40 FortyFrame(wxFrame
* frame
, char* title
, int x
, int y
, int w
, int h
);
41 virtual ~FortyFrame();
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
);
58 enum MenuCommands
{ NEW_GAME
= 10, SCORES
, EXIT
,
60 RIGHT_BUTTON_UNDO
, HELPING_HAND
,
64 FortyCanvas
* m_canvas
;
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
)
78 // Create a new application object
79 IMPLEMENT_APP (FortyApp
)
81 wxColour
* FortyApp::m_backgroundColour
= 0;
82 wxColour
* FortyApp::m_textColour
= 0;
83 wxBrush
* FortyApp::m_backgroundBrush
= 0;
85 bool FortyApp::OnInit()
87 FortyFrame
* frame
= new FortyFrame(
99 const wxColour
& FortyApp::BackgroundColour()
101 if (!m_backgroundColour
)
103 m_backgroundColour
= new wxColour(0, 128, 0);
106 return *m_backgroundColour
;
109 const wxBrush
& FortyApp::BackgroundBrush()
111 if (!m_backgroundBrush
)
113 m_backgroundBrush
= new wxBrush(BackgroundColour(), wxSOLID
);
116 return *m_backgroundBrush
;
119 const wxColour
& FortyApp::TextColour()
123 m_textColour
= new wxColour("BLACK");
126 return *m_textColour
;
129 // My frame constructor
130 FortyFrame::FortyFrame(wxFrame
* frame
, char* title
, int x
, int y
, int w
, int h
):
131 wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
135 SetIcon(wxIcon("CardsIcon"));
138 SetIcon(wxIcon(Cards_bits
, Cards_width
, Cards_height
));
143 wxMenu
* gameMenu
= new wxMenu
;
144 gameMenu
->Append(NEW_GAME
, "&New", "Start a new game");
145 gameMenu
->Append(SCORES
, "&Scores...", "Displays scores");
146 gameMenu
->Append(EXIT
, "E&xit", "Exits Forty Thieves");
148 wxMenu
* editMenu
= new wxMenu
;
149 editMenu
->Append(UNDO
, "&Undo", "Undo the last move");
150 editMenu
->Append(REDO
, "&Redo", "Redo a move that has been undone");
152 wxMenu
* optionsMenu
= new wxMenu
;
153 optionsMenu
->Append(RIGHT_BUTTON_UNDO
,
154 "&Right button undo",
155 "Enables/disables right mouse button undo and redo",
158 optionsMenu
->Append(HELPING_HAND
,
160 "Enables/disables hand cursor when a card can be moved",
163 optionsMenu
->Check(HELPING_HAND
, TRUE
);
164 optionsMenu
->Check(RIGHT_BUTTON_UNDO
, TRUE
);
166 wxMenu
* helpMenu
= new wxMenu
;
167 helpMenu
->Append(ABOUT
, "&About", "Displays program version information");
169 m_menuBar
= new wxMenuBar
;
170 m_menuBar
->Append(gameMenu
, "&Game");
171 m_menuBar
->Append(editMenu
, "&Edit");
172 m_menuBar
->Append(optionsMenu
, "&Options");
173 m_menuBar
->Append(helpMenu
, "&Help");
175 SetMenuBar(m_menuBar
);
177 m_canvas
= new FortyCanvas(this, 0, 0, 400, 400);
178 wxLayoutConstraints
* constr
= new wxLayoutConstraints
;
179 constr
->left
.SameAs(this, wxLeft
);
180 constr
->top
.SameAs(this, wxTop
);
181 constr
->right
.SameAs(this, wxRight
);
182 constr
->height
.SameAs(this, wxHeight
);
183 m_canvas
->SetConstraints(constr
);
188 FortyFrame::~FortyFrame()
192 bool FortyFrame::OnClose()
194 return m_canvas
->OnClose();
198 FortyFrame::NewGame(wxCommandEvent
&)
204 FortyFrame::Exit(wxCommandEvent
&)
207 // wxGTK doesn't call OnClose() so we do it here
214 FortyFrame::About(wxCommandEvent
&)
218 "A freeware program using the wxWindows\n"
219 "portable C++ GUI toolkit.\n"
220 "http://web.ukonline.co.uk/julian.smart/wxwin\n"
221 "http://www.freiburg.linux.de/~wxxt\n\n"
222 "Author: Chris Breeze (c) 1992-1998\n"
223 "email: chris.breeze@iname.com",
224 "About Forty Thieves",
230 FortyFrame::Undo(wxCommandEvent
&)
236 FortyFrame::Redo(wxCommandEvent
&)
242 FortyFrame::Scores(wxCommandEvent
&)
244 m_canvas
->UpdateScores();
245 ScoreDialog
scores(this, m_canvas
->GetScoreFile());
250 FortyFrame::ToggleRightButtonUndo(wxCommandEvent
& event
)
252 bool checked
= m_menuBar
->IsChecked(event
.GetId());
253 m_canvas
->EnableRightButtonUndo(checked
);
257 FortyFrame::ToggleHelpingHand(wxCommandEvent
& event
)
259 bool checked
= m_menuBar
->IsChecked(event
.GetId());
260 m_canvas
->EnableHelpingHand(checked
);