]>
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 wxString
* players
= 0;
63 scoreFile
->GetPlayerList(&players
, length
);
67 os
<< "Player\tWins\tGames\tScore\n";
68 for (int i
= 0; i
< length
; i
++)
70 int wins
, games
, score
;
71 scoreFile
->ReadPlayersScore(players
[i
], wins
, games
, score
);
75 average
= (2 * score
+ games
) / (2 * games
);
78 os
<< players
[i
] << '\t'
90 ScoreCanvas::~ScoreCanvas()
94 void ScoreCanvas::OnDraw(wxDC
& dc
)
98 const char* str
= m_text
;
100 unsigned int tabstops
[] = { 5, 100, 150, 200 };
102 // get the line spacing for the current font
106 dc
.GetTextExtent("Testing", &w
, &h
);
107 lineSpacing
= (int)h
;
116 while (*str
&& *str
>= ' ') *dest
++ = *str
++;
119 dc
.DrawText(text
, tabstops
[tab
], y
);
123 if (tab
< sizeof(tabstops
) / sizeof(tabstops
[0]) - 1)
128 else if (*str
== '\n')
138 ScoreDialog::ScoreDialog(
142 wxDialog(parent
, -1, "Scores",
143 wxDefaultPosition
, wxSize(310, 200),
144 wxDIALOG_MODAL
| wxDEFAULT_DIALOG_STYLE
),
147 // enable constraints
148 SetAutoLayout (TRUE
);
150 ScoreCanvas
* list
= new ScoreCanvas(this, m_scoreFile
);
151 m_OK
= new wxButton(this, wxID_OK
, "OK");
153 wxLayoutConstraints
* layout
;
155 // Constrain the OK button
156 layout
= new wxLayoutConstraints
;
157 layout
->left
.SameAs (this, wxLeft
, 10);
158 layout
->bottom
.SameAs (this, wxBottom
, 10);
159 layout
->height
.AsIs();
160 layout
->width
.AsIs();
161 m_OK
->SetConstraints(layout
);
163 // Constrain the list of players
164 layout
= new wxLayoutConstraints
;
165 layout
->left
.SameAs (this, wxLeft
, 10);
166 layout
->right
.SameAs (this, wxRight
, 10);
167 layout
->top
.SameAs (this, wxTop
, 10);
168 layout
->bottom
.SameAs (m_OK
, wxTop
, 10);
169 list
->SetConstraints(layout
);
174 ScoreDialog::~ScoreDialog()
178 void ScoreDialog::Display()
183 bool ScoreDialog::OnClose()
186 // NB don't return TRUE otherwise delete is called