]>
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(EXIT
, FortyFrame::Exit
)
43 EVT_MENU(ABOUT
, FortyFrame::About
)
44 EVT_MENU(UNDO
, FortyFrame::Undo
)
45 EVT_MENU(REDO
, FortyFrame::Redo
)
46 EVT_MENU(SCORES
, FortyFrame::Scores
)
47 EVT_MENU(RIGHT_BUTTON_UNDO
, FortyFrame::ToggleRightButtonUndo
)
48 EVT_MENU(HELPING_HAND
, FortyFrame::ToggleHelpingHand
)
49 EVT_MENU(LARGE_CARDS
, FortyFrame::ToggleCardSize
)
50 EVT_CLOSE(FortyFrame::OnCloseWindow
)
53 // Create a new application object
54 IMPLEMENT_APP (FortyApp
)
56 wxColour
* FortyApp::m_backgroundColour
= 0;
57 wxColour
* FortyApp::m_textColour
= 0;
58 wxBrush
* FortyApp::m_backgroundBrush
= 0;
66 delete m_backgroundColour
;
68 delete m_backgroundBrush
;
69 delete Card::m_symbolBmap
;
70 delete Card::m_pictureBmap
;
74 bool FortyApp::OnInit()
76 bool largecards
= FALSE
;
79 if ((argc
> 1) && (!wxStrcmp(argv
[1],"-L")))
82 size
= wxSize(1000,750);
85 FortyFrame
* frame
= new FortyFrame(
88 -1, -1, size
.x
, size
.y
,largecards
94 frame
->GetCanvas()->ShowPlayerDialog();
99 const wxColour
& FortyApp::BackgroundColour()
101 if (!m_backgroundColour
)
103 m_backgroundColour
= new wxColour(0, 128, 0);
106 return *m_backgroundColour
;
109 const wxBrush
& FortyApp::BackgroundBrush()
111 if (!m_backgroundBrush
)
113 m_backgroundBrush
= new wxBrush(BackgroundColour(), wxSOLID
);
116 return *m_backgroundBrush
;
119 const wxColour
& FortyApp::TextColour()
123 m_textColour
= new wxColour("BLACK");
126 return *m_textColour
;
129 // My frame constructor
130 FortyFrame::FortyFrame(wxFrame
* frame
, char* title
, int x
, int y
, int w
, int h
,bool largecards
):
131 wxFrame(frame
, -1, title
, wxPoint(x
, y
), wxSize(w
, h
))
134 // we need this in order to allow the about menu relocation, since ABOUT is not the default id of the about menu
135 wxApp::s_macAboutMenuItemId
= ABOUT
;
139 SetIcon(wxIcon("CardsIcon"));
142 SetIcon(wxIcon(Cards_bits
, Cards_width
, Cards_height
));
147 wxMenu
* gameMenu
= new wxMenu
;
148 gameMenu
->Append(NEW_GAME
, "&New", "Start a new game");
149 gameMenu
->Append(SCORES
, "&Scores...", "Displays scores");
150 gameMenu
->Append(EXIT
, "E&xit", "Exits Forty Thieves");
152 wxMenu
* editMenu
= new wxMenu
;
153 editMenu
->Append(UNDO
, "&Undo", "Undo the last move");
154 editMenu
->Append(REDO
, "&Redo", "Redo a move that has been undone");
156 wxMenu
* optionsMenu
= new wxMenu
;
157 optionsMenu
->Append(RIGHT_BUTTON_UNDO
,
158 "&Right button undo",
159 "Enables/disables right mouse button undo and redo",
162 optionsMenu
->Append(HELPING_HAND
,
164 "Enables/disables hand cursor when a card can be moved",
167 optionsMenu
->Append(LARGE_CARDS
,
169 "Enables/disables large cards for high resolution displays",
172 optionsMenu
->Check(HELPING_HAND
, TRUE
);
173 optionsMenu
->Check(RIGHT_BUTTON_UNDO
, TRUE
);
174 optionsMenu
->Check(LARGE_CARDS
, largecards
? TRUE
: FALSE
);
176 wxMenu
* helpMenu
= new wxMenu
;
177 helpMenu
->Append(ABOUT
, "&About...", "Displays information about the game");
179 m_menuBar
= new wxMenuBar
;
180 m_menuBar
->Append(gameMenu
, "&Game");
181 m_menuBar
->Append(editMenu
, "&Edit");
182 m_menuBar
->Append(optionsMenu
, "&Options");
183 m_menuBar
->Append(helpMenu
, "&Help");
185 SetMenuBar(m_menuBar
);
190 m_canvas
= new FortyCanvas(this, 0, 0, 400, 400);
191 wxLayoutConstraints
* constr
= new wxLayoutConstraints
;
192 constr
->left
.SameAs(this, wxLeft
);
193 constr
->top
.SameAs(this, wxTop
);
194 constr
->right
.SameAs(this, wxRight
);
195 constr
->height
.SameAs(this, wxHeight
);
196 m_canvas
->SetConstraints(constr
);
201 FortyFrame::~FortyFrame()
205 void FortyFrame::OnCloseWindow(wxCloseEvent
& event
)
207 if (m_canvas
->OnCloseCanvas() )
216 FortyFrame::NewGame(wxCommandEvent
&)
222 FortyFrame::Exit(wxCommandEvent
&)
225 // wxGTK doesn't call OnClose() so we do it here
232 FortyFrame::About(wxCommandEvent
&)
235 if (wxFileExists(wxT("about.htm")))
237 FortyAboutDialog
dialog(this, -1, wxT("About Forty Thieves"));
238 if (dialog
.ShowModal() == wxID_OK
)
247 "A freeware program using the wxWindows\n"
248 "portable C++ GUI toolkit.\n"
249 "http://www.wxwindows.org\n"
250 "http://www.freiburg.linux.de/~wxxt\n\n"
251 "Author: Chris Breeze (c) 1992-1998\n"
252 "email: chris.breeze@iname.com",
253 "About Forty Thieves",
260 FortyFrame::Undo(wxCommandEvent
&)
266 FortyFrame::Redo(wxCommandEvent
&)
272 FortyFrame::Scores(wxCommandEvent
&)
274 m_canvas
->UpdateScores();
275 ScoreDialog
scores(this, m_canvas
->GetScoreFile());
280 FortyFrame::ToggleRightButtonUndo(wxCommandEvent
& event
)
282 bool checked
= m_menuBar
->IsChecked(event
.GetId());
283 m_canvas
->EnableRightButtonUndo(checked
);
287 FortyFrame::ToggleHelpingHand(wxCommandEvent
& event
)
289 bool checked
= m_menuBar
->IsChecked(event
.GetId());
290 m_canvas
->EnableHelpingHand(checked
);
294 FortyFrame::ToggleCardSize(wxCommandEvent
& event
)
296 bool checked
= m_menuBar
->IsChecked(event
.GetId());
297 Card::SetScale(checked
? 1.3 : 1);
298 m_canvas
->LayoutGame();
302 //----------------------------------------------------------------------------
304 //----------------------------------------------------------------------------
306 BEGIN_EVENT_TABLE(FortyAboutDialog
,wxDialog
)
309 FortyAboutDialog::FortyAboutDialog( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
310 const wxPoint
&position
, const wxSize
& size
, long style
) :
311 wxDialog( parent
, id
, title
, position
, size
, style
)
318 bool FortyAboutDialog::AddControls(wxWindow
* parent
)
322 wxString
htmlFile(wxT("about.htm"));
324 //if (!wxGetApp().GetMemoryTextResource(wxT("about.htm"), htmlText))
326 // wxSetWorkingDirectory(wxGetApp().GetAppDir());
327 // wxString htmlFile(wxGetApp().GetFullAppPath(wxT("about.htm")));
329 if (wxFileExists(htmlFile
))
332 file
.Open(htmlFile
, wxFile::read
);
333 long len
= file
.Length();
334 char* buf
= htmlText
.GetWriteBuf(len
+ 1);
337 htmlText
.UngetWriteBuf();
341 if (htmlText
.IsEmpty())
343 htmlText
.Printf(wxT("<html><head><title>Warning</title></head><body><P>Sorry, could not find resource for About dialog<P></body></html>"));
346 // Customize the HTML
349 verString
.Printf("%.2f", stVERSION_NUMBER
);
350 htmlText
.Replace(wxT("$VERSION$"), verString
);
352 htmlText
.Replace(wxT("$DATE$"), __DATE__
);
354 wxSize
htmlSize(400, 290);
356 // Note: in later versions of wxWin this will be fixed so wxRAISED_BORDER
357 // does the right thing. Meanwhile, this is a workaround.
359 long borderStyle
= wxDOUBLE_BORDER
;
361 long borderStyle
= wxRAISED_BORDER
;
364 wxHtmlWindow
* html
= new wxHtmlWindow(this, ID_ABOUT_HTML_WINDOW
, wxDefaultPosition
, htmlSize
, borderStyle
);
365 html
-> SetBorders(10);
366 html
-> SetPage(htmlText
);
368 //// Start of sizer-based control creation
370 wxSizer
*item0
= new wxBoxSizer( wxVERTICAL
);
372 wxWindow
*item1
= parent
->FindWindow( ID_ABOUT_HTML_WINDOW
);
374 item0
->Add( item1
, 0, wxALIGN_CENTRE
|wxALL
, 5 );
376 wxButton
*item2
= new wxButton( parent
, wxID_CANCEL
, "&Close", wxDefaultPosition
, wxDefaultSize
, 0 );
380 item0
->Add( item2
, 0, wxALIGN_RIGHT
|wxALL
, 5 );
382 parent
->SetAutoLayout( TRUE
);
383 parent
->SetSizer( item0
);
385 item0
->Fit( parent
);
386 item0
->SetSizeHints( parent
);