]>
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"
35 BEGIN_EVENT_TABLE(FortyFrame
, wxFrame
)
36 EVT_MENU(NEW_GAME
, FortyFrame::NewGame
)
37 EVT_MENU(EXIT
, FortyFrame::Exit
)
38 EVT_MENU(ABOUT
, FortyFrame::About
)
39 EVT_MENU(UNDO
, FortyFrame::Undo
)
40 EVT_MENU(REDO
, FortyFrame::Redo
)
41 EVT_MENU(SCORES
, FortyFrame::Scores
)
42 EVT_MENU(RIGHT_BUTTON_UNDO
, FortyFrame::ToggleRightButtonUndo
)
43 EVT_MENU(HELPING_HAND
, FortyFrame::ToggleHelpingHand
)
44 EVT_MENU(LARGE_CARDS
, FortyFrame::ToggleCardSize
)
45 EVT_CLOSE(FortyFrame::OnCloseWindow
)
48 // Create a new application object
49 IMPLEMENT_APP (FortyApp
)
51 wxColour
* FortyApp::m_backgroundColour
= 0;
52 wxColour
* FortyApp::m_textColour
= 0;
53 wxBrush
* FortyApp::m_backgroundBrush
= 0;
61 delete m_backgroundColour
;
63 delete m_backgroundBrush
;
64 delete Card::m_symbolBmap
;
65 delete Card::m_pictureBmap
;
69 bool FortyApp::OnInit()
71 bool largecards
= FALSE
;
74 if ((argc
> 1) && (!wxStrcmp(argv
[1],"-L")))
77 size
= wxSize(1000,750);
80 FortyFrame
* frame
= new FortyFrame(
83 -1, -1, size
.x
, size
.y
,largecards
89 frame
->GetCanvas()->ShowPlayerDialog();
94 const wxColour
& FortyApp::BackgroundColour()
96 if (!m_backgroundColour
)
98 m_backgroundColour
= new wxColour(0, 128, 0);
101 return *m_backgroundColour
;
104 const wxBrush
& FortyApp::BackgroundBrush()
106 if (!m_backgroundBrush
)
108 m_backgroundBrush
= new wxBrush(BackgroundColour(), wxSOLID
);
111 return *m_backgroundBrush
;
114 const wxColour
& FortyApp::TextColour()
118 m_textColour
= new wxColour("BLACK");
121 return *m_textColour
;
124 // My frame constructor
125 FortyFrame::FortyFrame(wxFrame
* frame
, char* title
, int x
, int y
, int w
, int h
,bool largecards
):
126 wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
129 // we need this in order to allow the about menu relocation, since ABOUT is not the default id of the about menu
130 wxApp::s_macAboutMenuItemId
= ABOUT
;
134 SetIcon(wxIcon("CardsIcon"));
137 SetIcon(wxIcon(Cards_bits
, Cards_width
, Cards_height
));
142 wxMenu
* gameMenu
= new wxMenu
;
143 gameMenu
->Append(NEW_GAME
, "&New", "Start a new game");
144 gameMenu
->Append(SCORES
, "&Scores...", "Displays scores");
145 gameMenu
->Append(EXIT
, "E&xit", "Exits Forty Thieves");
147 wxMenu
* editMenu
= new wxMenu
;
148 editMenu
->Append(UNDO
, "&Undo", "Undo the last move");
149 editMenu
->Append(REDO
, "&Redo", "Redo a move that has been undone");
151 wxMenu
* optionsMenu
= new wxMenu
;
152 optionsMenu
->Append(RIGHT_BUTTON_UNDO
,
153 "&Right button undo",
154 "Enables/disables right mouse button undo and redo",
157 optionsMenu
->Append(HELPING_HAND
,
159 "Enables/disables hand cursor when a card can be moved",
162 optionsMenu
->Append(LARGE_CARDS
,
164 "Enables/disables large cards for high resolution displays",
167 optionsMenu
->Check(HELPING_HAND
, TRUE
);
168 optionsMenu
->Check(RIGHT_BUTTON_UNDO
, TRUE
);
169 optionsMenu
->Check(LARGE_CARDS
, largecards
? TRUE
: FALSE
);
171 wxMenu
* helpMenu
= new wxMenu
;
172 helpMenu
->Append(ABOUT
, "&About", "Displays program version information");
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");
180 SetMenuBar(m_menuBar
);
185 m_canvas
= new FortyCanvas(this, 0, 0, 400, 400);
186 wxLayoutConstraints
* constr
= new wxLayoutConstraints
;
187 constr
->left
.SameAs(this, wxLeft
);
188 constr
->top
.SameAs(this, wxTop
);
189 constr
->right
.SameAs(this, wxRight
);
190 constr
->height
.SameAs(this, wxHeight
);
191 m_canvas
->SetConstraints(constr
);
196 FortyFrame::~FortyFrame()
200 void FortyFrame::OnCloseWindow(wxCloseEvent
& event
)
202 if (m_canvas
->OnCloseCanvas() )
211 FortyFrame::NewGame(wxCommandEvent
&)
217 FortyFrame::Exit(wxCommandEvent
&)
220 // wxGTK doesn't call OnClose() so we do it here
227 FortyFrame::About(wxCommandEvent
&)
231 "A freeware program using the wxWindows\n"
232 "portable C++ GUI toolkit.\n"
233 "http://www.wxwindows.org\n"
234 "http://www.freiburg.linux.de/~wxxt\n\n"
235 "Author: Chris Breeze (c) 1992-1998\n"
236 "email: chris.breeze@iname.com",
237 "About Forty Thieves",
243 FortyFrame::Undo(wxCommandEvent
&)
249 FortyFrame::Redo(wxCommandEvent
&)
255 FortyFrame::Scores(wxCommandEvent
&)
257 m_canvas
->UpdateScores();
258 ScoreDialog
scores(this, m_canvas
->GetScoreFile());
263 FortyFrame::ToggleRightButtonUndo(wxCommandEvent
& event
)
265 bool checked
= m_menuBar
->IsChecked(event
.GetId());
266 m_canvas
->EnableRightButtonUndo(checked
);
270 FortyFrame::ToggleHelpingHand(wxCommandEvent
& event
)
272 bool checked
= m_menuBar
->IsChecked(event
.GetId());
273 m_canvas
->EnableHelpingHand(checked
);
277 FortyFrame::ToggleCardSize(wxCommandEvent
& event
)
279 bool checked
= m_menuBar
->IsChecked(event
.GetId());
280 Card::SetScale(checked
? 1.3 : 1);
281 m_canvas
->LayoutGame();