]>
git.saurik.com Git - wxWidgets.git/blob - samples/forty/scoredg.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"
30 #if defined(__WXMSW__) && !defined(GNUWIN32)
33 #include <strstream.h>
38 class ScoreCanvas
: public wxScrolledWindow
41 ScoreCanvas(wxWindow
* parent
, ScoreFile
* scoreFile
);
42 virtual ~ScoreCanvas();
44 void OnDraw(wxDC
& dc
);
52 ScoreCanvas::ScoreCanvas(wxWindow
* parent
, ScoreFile
* scoreFile
) :
53 wxScrolledWindow(parent
)
56 m_font
= wxTheFontList
->FindOrCreateFont(12, wxROMAN
, wxNORMAL
, wxNORMAL
);
58 m_font
= wxTheFontList
->FindOrCreateFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
61 wxArrayString players
;
62 scoreFile
->GetPlayerList( players
);
66 os
<< "Player\tWins\tGames\tScore\n";
67 for (unsigned int i
= 0; i
< players
.Count(); i
++)
69 int wins
, games
, score
;
70 scoreFile
->ReadPlayersScore(players
[i
], wins
, games
, score
);
74 average
= (2 * score
+ games
) / (2 * games
);
77 os
<< players
[i
] << '\t'
88 ScoreCanvas::~ScoreCanvas()
92 void ScoreCanvas::OnDraw(wxDC
& dc
)
96 const char* str
= m_text
;
98 unsigned int tabstops
[] = { 5, 100, 150, 200 };
100 // get the line spacing for the current font
104 dc
.GetTextExtent("Testing", &w
, &h
);
105 lineSpacing
= (int)h
;
114 while (*str
&& *str
>= ' ') *dest
++ = *str
++;
117 dc
.DrawText(text
, tabstops
[tab
], y
);
121 if (tab
< sizeof(tabstops
) / sizeof(tabstops
[0]) - 1)
126 else if (*str
== '\n')
136 ScoreDialog::ScoreDialog(
140 wxDialog(parent
, -1, "Scores",
141 wxDefaultPosition
, wxSize(310, 200),
142 wxDIALOG_MODAL
| wxDEFAULT_DIALOG_STYLE
),
145 // enable constraints
146 SetAutoLayout (TRUE
);
148 ScoreCanvas
* list
= new ScoreCanvas(this, m_scoreFile
);
149 m_OK
= new wxButton(this, wxID_OK
, "OK");
151 wxLayoutConstraints
* layout
;
153 // Constrain the OK button
154 layout
= new wxLayoutConstraints
;
155 layout
->left
.SameAs (this, wxLeft
, 10);
156 layout
->bottom
.SameAs (this, wxBottom
, 10);
157 layout
->height
.AsIs();
158 layout
->width
.AsIs();
159 m_OK
->SetConstraints(layout
);
161 // Constrain the list of players
162 layout
= new wxLayoutConstraints
;
163 layout
->left
.SameAs (this, wxLeft
, 10);
164 layout
->right
.SameAs (this, wxRight
, 10);
165 layout
->top
.SameAs (this, wxTop
, 10);
166 layout
->bottom
.SameAs (m_OK
, wxTop
, 10);
167 list
->SetConstraints(layout
);
172 ScoreDialog::~ScoreDialog()
176 void ScoreDialog::Display()
181 bool ScoreDialog::OnClose()
184 // NB don't return TRUE otherwise delete is called