]>
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 #include "wx/stockitem.h"
42 BEGIN_EVENT_TABLE(FortyFrame
, wxFrame
)
43 EVT_MENU(wxID_NEW
, FortyFrame::NewGame
)
44 EVT_MENU(wxID_EXIT
, FortyFrame::Exit
)
45 EVT_MENU(wxID_ABOUT
, FortyFrame::About
)
46 EVT_MENU(wxID_HELP_CONTENTS
, FortyFrame::Help
)
47 EVT_MENU(wxID_UNDO
, FortyFrame::Undo
)
48 EVT_MENU(wxID_REDO
, FortyFrame::Redo
)
49 EVT_MENU(SCORES
, FortyFrame::Scores
)
50 EVT_MENU(RIGHT_BUTTON_UNDO
, FortyFrame::ToggleRightButtonUndo
)
51 EVT_MENU(HELPING_HAND
, FortyFrame::ToggleHelpingHand
)
52 EVT_MENU(LARGE_CARDS
, FortyFrame::ToggleCardSize
)
53 EVT_CLOSE(FortyFrame::OnCloseWindow
)
56 // Create a new application object
57 IMPLEMENT_APP (FortyApp
)
59 wxColour
* FortyApp::m_backgroundColour
= 0;
60 wxColour
* FortyApp::m_textColour
= 0;
61 wxBrush
* FortyApp::m_backgroundBrush
= 0;
65 delete m_backgroundColour
;
67 delete m_backgroundBrush
;
68 delete Card::m_symbolBmap
;
69 delete Card::m_pictureBmap
;
73 bool FortyApp::OnInit()
75 bool largecards
= false;
77 m_helpFile
= wxGetCwd() + wxFILE_SEP_PATH
+ wxT("about.htm");
78 if (!wxFileExists(m_helpFile
))
81 m_helpFile
= wxPathOnly(argv
[0]) + wxFILE_SEP_PATH
+ wxT("about.htm");
86 if ((argc
> 1) && (!wxStrcmp(argv
[1],_T("-L"))))
89 size
= wxSize(1000,750);
92 FortyFrame
* frame
= new FortyFrame(
103 frame
->GetCanvas()->ShowPlayerDialog();
108 const wxColour
& FortyApp::BackgroundColour()
110 if (!m_backgroundColour
)
112 m_backgroundColour
= new wxColour(0, 128, 0);
115 return *m_backgroundColour
;
118 const wxBrush
& FortyApp::BackgroundBrush()
120 if (!m_backgroundBrush
)
122 m_backgroundBrush
= new wxBrush(BackgroundColour(), wxSOLID
);
125 return *m_backgroundBrush
;
128 const wxColour
& FortyApp::TextColour()
132 m_textColour
= new wxColour(_T("BLACK"));
135 return *m_textColour
;
138 // My frame constructor
139 FortyFrame::FortyFrame(wxFrame
* frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, bool largecards
):
140 wxFrame(frame
, wxID_ANY
, title
, pos
, size
)
143 wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
147 SetIcon(wxIcon(_T("CardsIcon")));
150 SetIcon(wxIcon(Cards_bits
, Cards_width
, Cards_height
));
155 wxMenu
* gameMenu
= new wxMenu
;
156 gameMenu
->Append(wxID_NEW
, wxGetStockLabel(wxID_NEW
), _T("Start a new game"));
157 gameMenu
->Append(SCORES
, _T("&Scores..."), _T("Displays scores"));
158 gameMenu
->Append(wxID_EXIT
, wxGetStockLabel(wxID_EXIT
), _T("Exits Forty Thieves"));
160 wxMenu
* editMenu
= new wxMenu
;
161 editMenu
->Append(wxID_UNDO
, wxGetStockLabel(wxID_UNDO
), _T("Undo the last move"));
162 editMenu
->Append(wxID_REDO
, wxGetStockLabel(wxID_REDO
), _T("Redo a move that has been undone"));
164 wxMenu
* optionsMenu
= new wxMenu
;
165 optionsMenu
->Append(RIGHT_BUTTON_UNDO
,
166 _T("&Right button undo"),
167 _T("Enables/disables right mouse button undo and redo"),
170 optionsMenu
->Append(HELPING_HAND
,
172 _T("Enables/disables hand cursor when a card can be moved"),
175 optionsMenu
->Append(LARGE_CARDS
,
177 _T("Enables/disables large cards for high resolution displays"),
180 optionsMenu
->Check(HELPING_HAND
, true);
181 optionsMenu
->Check(RIGHT_BUTTON_UNDO
, true);
182 optionsMenu
->Check(LARGE_CARDS
, largecards
? true : false);
184 wxMenu
* helpMenu
= new wxMenu
;
185 helpMenu
->Append(wxID_HELP_CONTENTS
, _T("&Help Contents"), _T("Displays information about playing the game"));
186 helpMenu
->Append(wxID_ABOUT
, _T("&About..."), _T("About Forty Thieves"));
188 m_menuBar
= new wxMenuBar
;
189 m_menuBar
->Append(gameMenu
, _T("&Game"));
190 m_menuBar
->Append(editMenu
, _T("&Edit"));
191 m_menuBar
->Append(optionsMenu
, _T("&Options"));
192 m_menuBar
->Append(helpMenu
, _T("&Help"));
194 SetMenuBar(m_menuBar
);
199 m_canvas
= new FortyCanvas(this, wxDefaultPosition
, size
);
201 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
202 topsizer
->Add( m_canvas
, 1, wxEXPAND
| wxALL
, 0);
203 SetSizer( topsizer
);
204 topsizer
->SetSizeHints( this );
208 #endif // wxUSE_STATUSBAR
211 void FortyFrame::OnCloseWindow(wxCloseEvent
& event
)
213 if (m_canvas
->OnCloseCanvas() )
222 FortyFrame::NewGame(wxCommandEvent
&)
228 FortyFrame::Exit(wxCommandEvent
&)
234 FortyFrame::Help(wxCommandEvent
& event
)
237 if (wxFileExists(wxGetApp().GetHelpFile()))
239 FortyAboutDialog
dialog(this, wxID_ANY
, wxT("Forty Thieves Instructions"));
240 if (dialog
.ShowModal() == wxID_OK
)
252 FortyFrame::About(wxCommandEvent
&)
255 _T("Forty Thieves\n\n")
256 _T("A free card game written with the wxWidgets toolkit\n")
257 _T("Author: Chris Breeze (c) 1992-2004\n")
258 _T("email: chris@breezesys.com"),
259 _T("About Forty Thieves"),
260 wxOK
|wxICON_INFORMATION
, this
266 FortyFrame::Undo(wxCommandEvent
&)
272 FortyFrame::Redo(wxCommandEvent
&)
278 FortyFrame::Scores(wxCommandEvent
&)
280 m_canvas
->UpdateScores();
281 ScoreDialog
scores(this, m_canvas
->GetScoreFile());
286 FortyFrame::ToggleRightButtonUndo(wxCommandEvent
& event
)
288 bool checked
= m_menuBar
->IsChecked(event
.GetId());
289 m_canvas
->EnableRightButtonUndo(checked
);
293 FortyFrame::ToggleHelpingHand(wxCommandEvent
& event
)
295 bool checked
= m_menuBar
->IsChecked(event
.GetId());
296 m_canvas
->EnableHelpingHand(checked
);
300 FortyFrame::ToggleCardSize(wxCommandEvent
& event
)
302 bool checked
= m_menuBar
->IsChecked(event
.GetId());
303 Card::SetScale(checked
? 1.3 : 1);
304 m_canvas
->LayoutGame();
308 //----------------------------------------------------------------------------
310 //----------------------------------------------------------------------------
312 BEGIN_EVENT_TABLE(FortyAboutDialog
,wxDialog
)
313 EVT_BUTTON(wxID_CLOSE
, wxDialog::OnOK
)
316 FortyAboutDialog::FortyAboutDialog( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
317 const wxPoint
&position
, const wxSize
& size
, long style
) :
318 wxDialog( parent
, id
, title
, position
, size
, style
)
325 bool FortyAboutDialog::AddControls(wxWindow
* parent
)
329 wxString htmlFile
= wxGetApp().GetHelpFile();
332 wxTextFile
file(htmlFile
);
336 for ( htmlText
= file
.GetFirstLine();
338 htmlText
<< file
.GetNextLine() << _T("\n") ) ;
342 if (htmlText
.empty())
344 htmlText
.Printf(wxT("<html><head><title>Warning</title></head><body><P>Sorry, could not find resource for About dialog<P></body></html>"));
347 // Customize the HTML
348 htmlText
.Replace(wxT("$DATE$"), _T(__DATE__
));
350 wxSize
htmlSize(400, 290);
352 // Note: in later versions of wxWin this will be fixed so wxRAISED_BORDER
353 // does the right thing. Meanwhile, this is a workaround.
355 long borderStyle
= wxDOUBLE_BORDER
;
357 long borderStyle
= wxRAISED_BORDER
;
360 wxHtmlWindow
* html
= new wxHtmlWindow(this, ID_ABOUT_HTML_WINDOW
, wxDefaultPosition
, htmlSize
, borderStyle
);
361 html
-> SetBorders(10);
362 html
-> SetPage(htmlText
);
364 //// Start of sizer-based control creation
366 wxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
368 wxWindow
*item1
= parent
->FindWindow( ID_ABOUT_HTML_WINDOW
);
370 item0
->Add( item1
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
372 wxButton
*item2
= new wxButton( parent
, wxID_CLOSE
);
376 item0
->Add( item2
, 0, wxALIGN_RIGHT
|wxALL
, 5 );
378 parent
->SetSizer( item0
);
380 item0
->Fit( parent
);
381 item0
->SetSizeHints( parent
);