]>
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 /////////////////////////////////////////////////////////////////////////////
14 // For compilers that support precompilation, includes "wx/wx.h".
15 #include "wx/wxprec.h"
32 #include "wx/textfile.h"
33 #include "wx/html/htmlwin.h"
36 #include "wx/stockitem.h"
38 BEGIN_EVENT_TABLE(FortyFrame
, wxFrame
)
39 EVT_MENU(wxID_NEW
, FortyFrame::NewGame
)
40 EVT_MENU(wxID_EXIT
, FortyFrame::Exit
)
41 EVT_MENU(wxID_ABOUT
, FortyFrame::About
)
42 EVT_MENU(wxID_HELP_CONTENTS
, FortyFrame::Help
)
43 EVT_MENU(wxID_UNDO
, FortyFrame::Undo
)
44 EVT_MENU(wxID_REDO
, FortyFrame::Redo
)
45 EVT_MENU(SCORES
, FortyFrame::Scores
)
46 EVT_MENU(RIGHT_BUTTON_UNDO
, FortyFrame::ToggleRightButtonUndo
)
47 EVT_MENU(HELPING_HAND
, FortyFrame::ToggleHelpingHand
)
48 EVT_MENU(LARGE_CARDS
, FortyFrame::ToggleCardSize
)
49 EVT_CLOSE(FortyFrame::OnCloseWindow
)
52 // Create a new application object
53 IMPLEMENT_APP (FortyApp
)
55 wxColour
* FortyApp::m_backgroundColour
= 0;
56 wxColour
* FortyApp::m_textColour
= 0;
57 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;
73 m_helpFile
= wxGetCwd() + wxFILE_SEP_PATH
+ wxT("about.htm");
74 if (!wxFileExists(m_helpFile
))
77 m_helpFile
= wxPathOnly(argv
[0]) + wxFILE_SEP_PATH
+ wxT("about.htm");
82 if ((argc
> 1) && (!wxStrcmp(argv
[1],wxT("-L"))))
85 size
= wxSize(1000,750);
88 FortyFrame
* frame
= new FortyFrame(
99 frame
->GetCanvas()->ShowPlayerDialog();
104 const wxColour
& FortyApp::BackgroundColour()
106 if (!m_backgroundColour
)
108 m_backgroundColour
= new wxColour(0, 128, 0);
111 return *m_backgroundColour
;
114 const wxBrush
& FortyApp::BackgroundBrush()
116 if (!m_backgroundBrush
)
118 m_backgroundBrush
= new wxBrush(BackgroundColour(), wxSOLID
);
121 return *m_backgroundBrush
;
124 const wxColour
& FortyApp::TextColour()
128 m_textColour
= new wxColour(*wxBLACK
);
131 return *m_textColour
;
134 // My frame constructor
135 FortyFrame::FortyFrame(wxFrame
* frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, bool largecards
):
136 wxFrame(frame
, wxID_ANY
, title
, pos
, size
)
139 wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
143 SetIcon(wxIcon(wxT("CardsIcon")));
145 SetIcon(wxIcon(forty_xpm
));
149 wxMenu
* gameMenu
= new wxMenu
;
150 gameMenu
->Append(wxID_NEW
, wxGetStockLabel(wxID_NEW
), wxT("Start a new game"));
151 gameMenu
->Append(SCORES
, wxT("&Scores..."), wxT("Displays scores"));
152 gameMenu
->Append(wxID_EXIT
, wxGetStockLabel(wxID_EXIT
), wxT("Exits Forty Thieves"));
154 wxMenu
* editMenu
= new wxMenu
;
155 editMenu
->Append(wxID_UNDO
, wxGetStockLabel(wxID_UNDO
), wxT("Undo the last move"));
156 editMenu
->Append(wxID_REDO
, wxGetStockLabel(wxID_REDO
), wxT("Redo a move that has been undone"));
158 wxMenu
* optionsMenu
= new wxMenu
;
159 optionsMenu
->Append(RIGHT_BUTTON_UNDO
,
160 wxT("&Right button undo"),
161 wxT("Enables/disables right mouse button undo and redo"),
164 optionsMenu
->Append(HELPING_HAND
,
165 wxT("&Helping hand"),
166 wxT("Enables/disables hand cursor when a card can be moved"),
169 optionsMenu
->Append(LARGE_CARDS
,
171 wxT("Enables/disables large cards for high resolution displays"),
174 optionsMenu
->Check(HELPING_HAND
, true);
175 optionsMenu
->Check(RIGHT_BUTTON_UNDO
, true);
176 optionsMenu
->Check(LARGE_CARDS
, largecards
? true : false);
178 wxMenu
* helpMenu
= new wxMenu
;
179 helpMenu
->Append(wxID_HELP_CONTENTS
, wxT("&Help Contents"), wxT("Displays information about playing the game"));
180 helpMenu
->Append(wxID_ABOUT
, wxT("&About..."), wxT("About Forty Thieves"));
182 m_menuBar
= new wxMenuBar
;
183 m_menuBar
->Append(gameMenu
, wxT("&Game"));
184 m_menuBar
->Append(editMenu
, wxT("&Edit"));
185 m_menuBar
->Append(optionsMenu
, wxT("&Options"));
186 m_menuBar
->Append(helpMenu
, wxT("&Help"));
188 SetMenuBar(m_menuBar
);
193 m_canvas
= new FortyCanvas(this, wxDefaultPosition
, size
);
195 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
196 topsizer
->Add( m_canvas
, 1, wxEXPAND
| wxALL
, 0);
197 SetSizer( topsizer
);
201 #endif // wxUSE_STATUSBAR
203 topsizer
->SetSizeHints( this );
206 void FortyFrame::OnCloseWindow(wxCloseEvent
& event
)
208 if (m_canvas
->OnCloseCanvas() )
217 FortyFrame::NewGame(wxCommandEvent
&)
223 FortyFrame::Exit(wxCommandEvent
&)
229 FortyFrame::Help(wxCommandEvent
& event
)
232 if (wxFileExists(wxGetApp().GetHelpFile()))
234 FortyAboutDialog
dialog(this, wxID_ANY
, wxT("Forty Thieves Instructions"));
235 if (dialog
.ShowModal() == wxID_OK
)
247 FortyFrame::About(wxCommandEvent
&)
250 wxT("Forty Thieves\n\n")
251 wxT("A free card game written with the wxWidgets toolkit\n")
252 wxT("Author: Chris Breeze (c) 1992-2004\n")
253 wxT("email: chris@breezesys.com"),
254 wxT("About Forty Thieves"),
255 wxOK
|wxICON_INFORMATION
, this
261 FortyFrame::Undo(wxCommandEvent
&)
267 FortyFrame::Redo(wxCommandEvent
&)
273 FortyFrame::Scores(wxCommandEvent
&)
275 m_canvas
->UpdateScores();
276 ScoreDialog
scores(this, m_canvas
->GetScoreFile());
281 FortyFrame::ToggleRightButtonUndo(wxCommandEvent
& event
)
283 bool checked
= m_menuBar
->IsChecked(event
.GetId());
284 m_canvas
->EnableRightButtonUndo(checked
);
288 FortyFrame::ToggleHelpingHand(wxCommandEvent
& event
)
290 bool checked
= m_menuBar
->IsChecked(event
.GetId());
291 m_canvas
->EnableHelpingHand(checked
);
295 FortyFrame::ToggleCardSize(wxCommandEvent
& event
)
297 bool checked
= m_menuBar
->IsChecked(event
.GetId());
298 Card::SetScale(checked
? 1.3 : 1);
299 m_canvas
->LayoutGame();
303 //----------------------------------------------------------------------------
305 //----------------------------------------------------------------------------
307 FortyAboutDialog::FortyAboutDialog( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
308 const wxPoint
&position
, const wxSize
& size
, long style
) :
309 wxDialog( parent
, id
, title
, position
, size
, style
)
316 bool FortyAboutDialog::AddControls(wxWindow
* parent
)
320 wxString htmlFile
= wxGetApp().GetHelpFile();
323 wxTextFile
file(htmlFile
);
327 for ( htmlText
= file
.GetFirstLine();
329 htmlText
<< file
.GetNextLine() << wxT("\n") ) ;
333 if (htmlText
.empty())
335 htmlText
.Printf(wxT("<html><head><title>Warning</title></head><body><P>Sorry, could not find resource for About dialog<P></body></html>"));
338 // Customize the HTML
339 htmlText
.Replace(wxT("$DATE$"), wxT(__DATE__
));
341 wxSize
htmlSize(400, 290);
343 // Note: in later versions of wxWin this will be fixed so wxRAISED_BORDER
344 // does the right thing. Meanwhile, this is a workaround.
346 long borderStyle
= wxDOUBLE_BORDER
;
348 long borderStyle
= wxRAISED_BORDER
;
351 wxHtmlWindow
* html
= new wxHtmlWindow(this, ID_ABOUT_HTML_WINDOW
, wxDefaultPosition
, htmlSize
, borderStyle
);
352 html
-> SetBorders(10);
353 html
-> SetPage(htmlText
);
355 //// Start of sizer-based control creation
357 wxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
359 wxWindow
*item1
= parent
->FindWindow( ID_ABOUT_HTML_WINDOW
);
361 item0
->Add( item1
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
363 wxButton
*item2
= new wxButton( parent
, wxID_CLOSE
);
366 SetAffirmativeId(wxID_CLOSE
);
368 item0
->Add( item2
, 0, wxALIGN_RIGHT
|wxALL
, 5 );
370 parent
->SetSizer( item0
);
372 item0
->Fit( parent
);
373 item0
->SetSizeHints( parent
);