]>
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;
55 bool FortyApp::OnInit()
57 bool largecards
= FALSE
;
60 if ((argc
> 1) && (!wxStrcmp(argv
[1],"-L")))
63 size
= wxSize(1000,750);
66 FortyFrame
* frame
= new FortyFrame(
69 -1, -1, size
.x
, size
.y
,largecards
75 frame
->GetCanvas()->ShowPlayerDialog();
80 const wxColour
& FortyApp::BackgroundColour()
82 if (!m_backgroundColour
)
84 m_backgroundColour
= new wxColour(0, 128, 0);
87 return *m_backgroundColour
;
90 const wxBrush
& FortyApp::BackgroundBrush()
92 if (!m_backgroundBrush
)
94 m_backgroundBrush
= new wxBrush(BackgroundColour(), wxSOLID
);
97 return *m_backgroundBrush
;
100 const wxColour
& FortyApp::TextColour()
104 m_textColour
= new wxColour("BLACK");
107 return *m_textColour
;
110 // My frame constructor
111 FortyFrame::FortyFrame(wxFrame
* frame
, char* title
, int x
, int y
, int w
, int h
,bool largecards
):
112 wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
115 // we need this in order to allow the about menu relocation, since ABOUT is not the default id of the about menu
116 wxApp::s_macAboutMenuItemId
= ABOUT
;
120 SetIcon(wxIcon("CardsIcon"));
123 SetIcon(wxIcon(Cards_bits
, Cards_width
, Cards_height
));
128 wxMenu
* gameMenu
= new wxMenu
;
129 gameMenu
->Append(NEW_GAME
, "&New", "Start a new game");
130 gameMenu
->Append(SCORES
, "&Scores...", "Displays scores");
131 gameMenu
->Append(EXIT
, "E&xit", "Exits Forty Thieves");
133 wxMenu
* editMenu
= new wxMenu
;
134 editMenu
->Append(UNDO
, "&Undo", "Undo the last move");
135 editMenu
->Append(REDO
, "&Redo", "Redo a move that has been undone");
137 wxMenu
* optionsMenu
= new wxMenu
;
138 optionsMenu
->Append(RIGHT_BUTTON_UNDO
,
139 "&Right button undo",
140 "Enables/disables right mouse button undo and redo",
143 optionsMenu
->Append(HELPING_HAND
,
145 "Enables/disables hand cursor when a card can be moved",
148 optionsMenu
->Append(LARGE_CARDS
,
150 "Enables/disables large cards for high resolution displays",
153 optionsMenu
->Check(HELPING_HAND
, TRUE
);
154 optionsMenu
->Check(RIGHT_BUTTON_UNDO
, TRUE
);
155 optionsMenu
->Check(LARGE_CARDS
, largecards
? TRUE
: FALSE
);
157 wxMenu
* helpMenu
= new wxMenu
;
158 helpMenu
->Append(ABOUT
, "&About", "Displays program version information");
160 m_menuBar
= new wxMenuBar
;
161 m_menuBar
->Append(gameMenu
, "&Game");
162 m_menuBar
->Append(editMenu
, "&Edit");
163 m_menuBar
->Append(optionsMenu
, "&Options");
164 m_menuBar
->Append(helpMenu
, "&Help");
166 SetMenuBar(m_menuBar
);
171 m_canvas
= new FortyCanvas(this, 0, 0, 400, 400);
172 wxLayoutConstraints
* constr
= new wxLayoutConstraints
;
173 constr
->left
.SameAs(this, wxLeft
);
174 constr
->top
.SameAs(this, wxTop
);
175 constr
->right
.SameAs(this, wxRight
);
176 constr
->height
.SameAs(this, wxHeight
);
177 m_canvas
->SetConstraints(constr
);
182 FortyFrame::~FortyFrame()
186 void FortyFrame::OnCloseWindow(wxCloseEvent
& event
)
188 if (m_canvas
->OnCloseCanvas() )
197 FortyFrame::NewGame(wxCommandEvent
&)
203 FortyFrame::Exit(wxCommandEvent
&)
206 // wxGTK doesn't call OnClose() so we do it here
213 FortyFrame::About(wxCommandEvent
&)
217 "A freeware program using the wxWindows\n"
218 "portable C++ GUI toolkit.\n"
219 "http://www.wxwindows.org\n"
220 "http://www.freiburg.linux.de/~wxxt\n\n"
221 "Author: Chris Breeze (c) 1992-1998\n"
222 "email: chris.breeze@iname.com",
223 "About Forty Thieves",
229 FortyFrame::Undo(wxCommandEvent
&)
235 FortyFrame::Redo(wxCommandEvent
&)
241 FortyFrame::Scores(wxCommandEvent
&)
243 m_canvas
->UpdateScores();
244 ScoreDialog
scores(this, m_canvas
->GetScoreFile());
249 FortyFrame::ToggleRightButtonUndo(wxCommandEvent
& event
)
251 bool checked
= m_menuBar
->IsChecked(event
.GetId());
252 m_canvas
->EnableRightButtonUndo(checked
);
256 FortyFrame::ToggleHelpingHand(wxCommandEvent
& event
)
258 bool checked
= m_menuBar
->IsChecked(event
.GetId());
259 m_canvas
->EnableHelpingHand(checked
);
263 FortyFrame::ToggleCardSize(wxCommandEvent
& event
)
265 bool checked
= m_menuBar
->IsChecked(event
.GetId());
266 Card::SetScale(checked
? 1.3 : 1);
267 m_canvas
->LayoutGame();