]>
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 wxWidgets 2.0
12 /////////////////////////////////////////////////////////////////////////////
15 #pragma implementation
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
36 #include "wx/textfile.h"
37 #include "wx/html/htmlwin.h"
40 BEGIN_EVENT_TABLE(FortyFrame
, wxFrame
)
41 EVT_MENU(NEW_GAME
, FortyFrame::NewGame
)
42 EVT_MENU(wxID_EXIT
, FortyFrame::Exit
)
43 EVT_MENU(wxID_ABOUT
, FortyFrame::About
)
44 EVT_MENU(wxID_HELP_CONTENTS
, FortyFrame::Help
)
45 EVT_MENU(UNDO
, FortyFrame::Undo
)
46 EVT_MENU(REDO
, FortyFrame::Redo
)
47 EVT_MENU(SCORES
, FortyFrame::Scores
)
48 EVT_MENU(RIGHT_BUTTON_UNDO
, FortyFrame::ToggleRightButtonUndo
)
49 EVT_MENU(HELPING_HAND
, FortyFrame::ToggleHelpingHand
)
50 EVT_MENU(LARGE_CARDS
, FortyFrame::ToggleCardSize
)
51 EVT_CLOSE(FortyFrame::OnCloseWindow
)
54 // Create a new application object
55 IMPLEMENT_APP (FortyApp
)
57 wxColour
* FortyApp::m_backgroundColour
= 0;
58 wxColour
* FortyApp::m_textColour
= 0;
59 wxBrush
* FortyApp::m_backgroundBrush
= 0;
67 delete m_backgroundColour
;
69 delete m_backgroundBrush
;
70 delete Card::m_symbolBmap
;
71 delete Card::m_pictureBmap
;
75 bool FortyApp::OnInit()
77 bool largecards
= false;
79 m_helpFile
= wxGetCwd() + wxFILE_SEP_PATH
+ wxT("about.htm");
80 if (!wxFileExists(m_helpFile
))
83 m_helpFile
= wxPathOnly(argv
[0]) + wxFILE_SEP_PATH
+ wxT("about.htm");
88 if ((argc
> 1) && (!wxStrcmp(argv
[1],_T("-L"))))
91 size
= wxSize(1000,750);
94 FortyFrame
* frame
= new FortyFrame(
105 frame
->GetCanvas()->ShowPlayerDialog();
110 const wxColour
& FortyApp::BackgroundColour()
112 if (!m_backgroundColour
)
114 m_backgroundColour
= new wxColour(0, 128, 0);
117 return *m_backgroundColour
;
120 const wxBrush
& FortyApp::BackgroundBrush()
122 if (!m_backgroundBrush
)
124 m_backgroundBrush
= new wxBrush(BackgroundColour(), wxSOLID
);
127 return *m_backgroundBrush
;
130 const wxColour
& FortyApp::TextColour()
134 m_textColour
= new wxColour(_T("BLACK"));
137 return *m_textColour
;
140 // My frame constructor
141 FortyFrame::FortyFrame(wxFrame
* frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, bool largecards
):
142 wxFrame(frame
, wxID_ANY
, title
, pos
, size
)
145 wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
149 SetIcon(wxIcon(_T("CardsIcon")));
152 SetIcon(wxIcon(Cards_bits
, Cards_width
, Cards_height
));
157 wxMenu
* gameMenu
= new wxMenu
;
158 gameMenu
->Append(NEW_GAME
, _T("&New"), _T("Start a new game"));
159 gameMenu
->Append(SCORES
, _T("&Scores..."), _T("Displays scores"));
160 gameMenu
->Append(wxID_EXIT
, _T("E&xit"), _T("Exits Forty Thieves"));
162 wxMenu
* editMenu
= new wxMenu
;
163 editMenu
->Append(UNDO
, _T("&Undo"), _T("Undo the last move"));
164 editMenu
->Append(REDO
, _T("&Redo"), _T("Redo a move that has been undone"));
166 wxMenu
* optionsMenu
= new wxMenu
;
167 optionsMenu
->Append(RIGHT_BUTTON_UNDO
,
168 _T("&Right button undo"),
169 _T("Enables/disables right mouse button undo and redo"),
172 optionsMenu
->Append(HELPING_HAND
,
174 _T("Enables/disables hand cursor when a card can be moved"),
177 optionsMenu
->Append(LARGE_CARDS
,
179 _T("Enables/disables large cards for high resolution displays"),
182 optionsMenu
->Check(HELPING_HAND
, true);
183 optionsMenu
->Check(RIGHT_BUTTON_UNDO
, true);
184 optionsMenu
->Check(LARGE_CARDS
, largecards
? true : false);
186 wxMenu
* helpMenu
= new wxMenu
;
187 helpMenu
->Append(wxID_HELP_CONTENTS
, _T("&Help Contents"), _T("Displays information about playing the game"));
188 helpMenu
->Append(wxID_ABOUT
, _T("&About..."), _T("About Forty Thieves"));
190 m_menuBar
= new wxMenuBar
;
191 m_menuBar
->Append(gameMenu
, _T("&Game"));
192 m_menuBar
->Append(editMenu
, _T("&Edit"));
193 m_menuBar
->Append(optionsMenu
, _T("&Options"));
194 m_menuBar
->Append(helpMenu
, _T("&Help"));
196 SetMenuBar(m_menuBar
);
201 m_canvas
= new FortyCanvas(this, wxDefaultPosition
, size
);
203 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
204 topsizer
->Add( m_canvas
, 1, wxEXPAND
| wxALL
, 0);
205 SetSizer( topsizer
);
206 topsizer
->SetSizeHints( this );
210 #endif // wxUSE_STATUSBAR
213 FortyFrame::~FortyFrame()
217 void FortyFrame::OnCloseWindow(wxCloseEvent
& event
)
219 if (m_canvas
->OnCloseCanvas() )
228 FortyFrame::NewGame(wxCommandEvent
&)
234 FortyFrame::Exit(wxCommandEvent
&)
240 FortyFrame::Help(wxCommandEvent
& event
)
243 if (wxFileExists(wxGetApp().GetHelpFile()))
245 FortyAboutDialog
dialog(this, wxID_ANY
, wxT("Forty Thieves Instructions"));
246 if (dialog
.ShowModal() == wxID_OK
)
258 FortyFrame::About(wxCommandEvent
&)
261 _T("Forty Thieves\n\n")
262 _T("A free card game written with the wxWidgets toolkit\n")
263 _T("Author: Chris Breeze (c) 1992-2004\n")
264 _T("email: chris@breezesys.com"),
265 _T("About Forty Thieves"),
266 wxOK
|wxICON_INFORMATION
, this
272 FortyFrame::Undo(wxCommandEvent
&)
278 FortyFrame::Redo(wxCommandEvent
&)
284 FortyFrame::Scores(wxCommandEvent
&)
286 m_canvas
->UpdateScores();
287 ScoreDialog
scores(this, m_canvas
->GetScoreFile());
292 FortyFrame::ToggleRightButtonUndo(wxCommandEvent
& event
)
294 bool checked
= m_menuBar
->IsChecked(event
.GetId());
295 m_canvas
->EnableRightButtonUndo(checked
);
299 FortyFrame::ToggleHelpingHand(wxCommandEvent
& event
)
301 bool checked
= m_menuBar
->IsChecked(event
.GetId());
302 m_canvas
->EnableHelpingHand(checked
);
306 FortyFrame::ToggleCardSize(wxCommandEvent
& event
)
308 bool checked
= m_menuBar
->IsChecked(event
.GetId());
309 Card::SetScale(checked
? 1.3 : 1);
310 m_canvas
->LayoutGame();
314 //----------------------------------------------------------------------------
316 //----------------------------------------------------------------------------
318 BEGIN_EVENT_TABLE(FortyAboutDialog
,wxDialog
)
321 FortyAboutDialog::FortyAboutDialog( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
322 const wxPoint
&position
, const wxSize
& size
, long style
) :
323 wxDialog( parent
, id
, title
, position
, size
, style
)
330 bool FortyAboutDialog::AddControls(wxWindow
* parent
)
334 wxString htmlFile
= wxGetApp().GetHelpFile();
337 wxTextFile
file(htmlFile
);
341 for ( htmlText
= file
.GetFirstLine();
343 htmlText
<< file
.GetNextLine() << _T("\n") ) ;
347 if (htmlText
.IsEmpty())
349 htmlText
.Printf(wxT("<html><head><title>Warning</title></head><body><P>Sorry, could not find resource for About dialog<P></body></html>"));
352 // Customize the HTML
353 htmlText
.Replace(wxT("$DATE$"), _T(__DATE__
));
355 wxSize
htmlSize(400, 290);
357 // Note: in later versions of wxWin this will be fixed so wxRAISED_BORDER
358 // does the right thing. Meanwhile, this is a workaround.
360 long borderStyle
= wxDOUBLE_BORDER
;
362 long borderStyle
= wxRAISED_BORDER
;
365 wxHtmlWindow
* html
= new wxHtmlWindow(this, ID_ABOUT_HTML_WINDOW
, wxDefaultPosition
, htmlSize
, borderStyle
);
366 html
-> SetBorders(10);
367 html
-> SetPage(htmlText
);
369 //// Start of sizer-based control creation
371 wxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
373 wxWindow
*item1
= parent
->FindWindow( ID_ABOUT_HTML_WINDOW
);
375 item0
->Add( item1
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
377 wxButton
*item2
= new wxButton( parent
, wxID_CANCEL
, _T("&Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
381 item0
->Add( item2
, 0, wxALIGN_RIGHT
|wxALL
, 5 );
383 parent
->SetSizer( item0
);
385 item0
->Fit( parent
);
386 item0
->SetSizeHints( parent
);