]>
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"
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;
81 if ((argc
> 1) && (!wxStrcmp(argv
[1],_T("-L"))))
84 size
= wxSize(1000,750);
87 FortyFrame
* frame
= new FortyFrame(
98 frame
->GetCanvas()->ShowPlayerDialog();
103 const wxColour
& FortyApp::BackgroundColour()
105 if (!m_backgroundColour
)
107 m_backgroundColour
= new wxColour(0, 128, 0);
110 return *m_backgroundColour
;
113 const wxBrush
& FortyApp::BackgroundBrush()
115 if (!m_backgroundBrush
)
117 m_backgroundBrush
= new wxBrush(BackgroundColour(), wxSOLID
);
120 return *m_backgroundBrush
;
123 const wxColour
& FortyApp::TextColour()
127 m_textColour
= new wxColour(_T("BLACK"));
130 return *m_textColour
;
133 // My frame constructor
134 FortyFrame::FortyFrame(wxFrame
* frame
, const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
, bool largecards
):
135 wxFrame(frame
, wxID_ANY
, title
, pos
, size
)
138 wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
142 SetIcon(wxIcon(_T("CardsIcon")));
145 SetIcon(wxIcon(Cards_bits
, Cards_width
, Cards_height
));
150 wxMenu
* gameMenu
= new wxMenu
;
151 gameMenu
->Append(NEW_GAME
, _T("&New"), _T("Start a new game"));
152 gameMenu
->Append(SCORES
, _T("&Scores..."), _T("Displays scores"));
153 gameMenu
->Append(wxID_EXIT
, _T("E&xit"), _T("Exits Forty Thieves"));
155 wxMenu
* editMenu
= new wxMenu
;
156 editMenu
->Append(UNDO
, _T("&Undo"), _T("Undo the last move"));
157 editMenu
->Append(REDO
, _T("&Redo"), _T("Redo a move that has been undone"));
159 wxMenu
* optionsMenu
= new wxMenu
;
160 optionsMenu
->Append(RIGHT_BUTTON_UNDO
,
161 _T("&Right button undo"),
162 _T("Enables/disables right mouse button undo and redo"),
165 optionsMenu
->Append(HELPING_HAND
,
167 _T("Enables/disables hand cursor when a card can be moved"),
170 optionsMenu
->Append(LARGE_CARDS
,
172 _T("Enables/disables large cards for high resolution displays"),
175 optionsMenu
->Check(HELPING_HAND
, true);
176 optionsMenu
->Check(RIGHT_BUTTON_UNDO
, true);
177 optionsMenu
->Check(LARGE_CARDS
, largecards
? true : false);
179 wxMenu
* helpMenu
= new wxMenu
;
180 helpMenu
->Append(wxID_HELP_CONTENTS
, _T("&Help Contents"), _T("Displays information about playing the game"));
181 helpMenu
->Append(wxID_ABOUT
, _T("&About..."), _T("About Forty Thieves"));
183 m_menuBar
= new wxMenuBar
;
184 m_menuBar
->Append(gameMenu
, _T("&Game"));
185 m_menuBar
->Append(editMenu
, _T("&Edit"));
186 m_menuBar
->Append(optionsMenu
, _T("&Options"));
187 m_menuBar
->Append(helpMenu
, _T("&Help"));
189 SetMenuBar(m_menuBar
);
194 m_canvas
= new FortyCanvas(this, wxDefaultPosition
, size
);
196 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
197 topsizer
->Add( m_canvas
, 1, wxEXPAND
| wxALL
, 0);
198 SetSizer( topsizer
);
199 topsizer
->SetSizeHints( this );
204 FortyFrame::~FortyFrame()
208 void FortyFrame::OnCloseWindow(wxCloseEvent
& event
)
210 if (m_canvas
->OnCloseCanvas() )
219 FortyFrame::NewGame(wxCommandEvent
&)
225 FortyFrame::Exit(wxCommandEvent
&)
231 FortyFrame::Help(wxCommandEvent
& event
)
234 if (wxFileExists(wxT("about.htm")))
236 FortyAboutDialog
dialog(this, wxID_ANY
, wxT("Forty Thieves Instructions"));
237 if (dialog
.ShowModal() == wxID_OK
)
249 FortyFrame::About(wxCommandEvent
&)
252 _T("Forty Thieves\n\n")
253 _T("A free card game written with the wxWidgets toolkit\n")
254 _T("Author: Chris Breeze (c) 1992-2004\n")
255 _T("email: chris@breezesys.com"),
256 _T("About Forty Thieves"),
257 wxOK
|wxICON_INFORMATION
, this
263 FortyFrame::Undo(wxCommandEvent
&)
269 FortyFrame::Redo(wxCommandEvent
&)
275 FortyFrame::Scores(wxCommandEvent
&)
277 m_canvas
->UpdateScores();
278 ScoreDialog
scores(this, m_canvas
->GetScoreFile());
283 FortyFrame::ToggleRightButtonUndo(wxCommandEvent
& event
)
285 bool checked
= m_menuBar
->IsChecked(event
.GetId());
286 m_canvas
->EnableRightButtonUndo(checked
);
290 FortyFrame::ToggleHelpingHand(wxCommandEvent
& event
)
292 bool checked
= m_menuBar
->IsChecked(event
.GetId());
293 m_canvas
->EnableHelpingHand(checked
);
297 FortyFrame::ToggleCardSize(wxCommandEvent
& event
)
299 bool checked
= m_menuBar
->IsChecked(event
.GetId());
300 Card::SetScale(checked
? 1.3 : 1);
301 m_canvas
->LayoutGame();
305 //----------------------------------------------------------------------------
307 //----------------------------------------------------------------------------
309 BEGIN_EVENT_TABLE(FortyAboutDialog
,wxDialog
)
312 FortyAboutDialog::FortyAboutDialog( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
313 const wxPoint
&position
, const wxSize
& size
, long style
) :
314 wxDialog( parent
, id
, title
, position
, size
, style
)
321 bool FortyAboutDialog::AddControls(wxWindow
* parent
)
325 wxString
htmlFile(wxT("about.htm"));
327 //if (!wxGetApp().GetMemoryTextResource(wxT("about.htm"), htmlText))
329 // wxSetWorkingDirectory(wxGetApp().GetAppDir());
330 // wxString htmlFile(wxGetApp().GetFullAppPath(wxT("about.htm")));
332 if (wxFileExists(htmlFile
))
335 file
.Open(htmlFile
, wxFile::read
);
336 long len
= file
.Length();
337 wxChar
* buf
= htmlText
.GetWriteBuf(len
+ 1);
340 htmlText
.UngetWriteBuf();
344 if (htmlText
.IsEmpty())
346 htmlText
.Printf(wxT("<html><head><title>Warning</title></head><body><P>Sorry, could not find resource for About dialog<P></body></html>"));
349 // Customize the HTML
352 verString
.Printf("%.2f", stVERSION_NUMBER
);
353 htmlText
.Replace(wxT("$VERSION$"), verString
);
355 htmlText
.Replace(wxT("$DATE$"), _T(__DATE__
));
357 wxSize
htmlSize(400, 290);
359 // Note: in later versions of wxWin this will be fixed so wxRAISED_BORDER
360 // does the right thing. Meanwhile, this is a workaround.
362 long borderStyle
= wxDOUBLE_BORDER
;
364 long borderStyle
= wxRAISED_BORDER
;
367 wxHtmlWindow
* html
= new wxHtmlWindow(this, ID_ABOUT_HTML_WINDOW
, wxDefaultPosition
, htmlSize
, borderStyle
);
368 html
-> SetBorders(10);
369 html
-> SetPage(htmlText
);
371 //// Start of sizer-based control creation
373 wxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
375 wxWindow
*item1
= parent
->FindWindow( ID_ABOUT_HTML_WINDOW
);
377 item0
->Add( item1
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
379 wxButton
*item2
= new wxButton( parent
, wxID_CANCEL
, _T("&Close"), wxDefaultPosition
, wxDefaultSize
, 0 );
383 item0
->Add( item2
, 0, wxALIGN_RIGHT
|wxALL
, 5 );
385 parent
->SetSizer( item0
);
387 item0
->Fit( parent
);
388 item0
->SetSizeHints( parent
);