1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Forty Thieves patience game
4 // Author: Chris Breeze
8 // Copyright: (c) 1993-1998 Chris Breeze
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
26 // adjust USE_GRID_FOR_SCORE with O or 1 to your preferences
27 // by default it takes wxGrid component for score display if available in target port
28 #define USE_GRID_FOR_SCORE wxUSE_GRID
30 #if USE_GRID_FOR_SCORE
33 class ScoreCanvas
: public wxScrolledWindow
36 ScoreCanvas(wxWindow
* parent
, ScoreFile
* scoreFile
, const wxPoint
& pos
, wxSize
& size
);
37 virtual ~ScoreCanvas();
39 void OnDraw(wxDC
& dc
);
46 ScoreCanvas::ScoreCanvas(wxWindow
* parent
, ScoreFile
* scoreFile
, const wxPoint
& pos
, wxSize
& size
) :
47 wxScrolledWindow(parent
, wxID_ANY
, pos
, size
, wxSUNKEN_BORDER
)
49 SetBackgroundColour(*wxWHITE
);
51 m_font
= wxTheFontList
->FindOrCreateFont(12, wxROMAN
, wxNORMAL
, wxNORMAL
);
53 m_font
= wxTheFontList
->FindOrCreateFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
56 wxArrayString players
;
57 scoreFile
->GetPlayerList( players
);
61 os
<< wxT("Player\tWins\tGames\tScore\n");
62 for (unsigned int i
= 0; i
< players
.Count(); i
++)
64 int wins
, games
, score
;
65 scoreFile
->ReadPlayersScore(players
[i
], wins
, games
, score
);
69 average
= (2 * score
+ games
) / (2 * games
);
72 os
<< players
[i
] << wxT('\t')
75 << average
<< wxT('\n');
81 ScoreCanvas::~ScoreCanvas()
85 void ScoreCanvas::OnDraw(wxDC
& dc
)
89 const wxChar
* str
= m_text
;
91 unsigned int tabstops
[] = { 5, 100, 150, 200 };
93 // get the line spacing for the current font
97 dc
.GetTextExtent(wxT("Testing"), &w
, &h
);
107 while (*str
&& *str
>= ' ') *dest
++ = *str
++;
110 dc
.DrawText(text
, tabstops
[tab
], y
);
114 if (tab
< sizeof(tabstops
) / sizeof(tabstops
[0]) - 1)
119 else if (*str
== '\n')
129 BEGIN_EVENT_TABLE(ScoreDialog
, wxDialog
)
130 EVT_CLOSE(ScoreDialog::OnCloseWindow
)
133 ScoreDialog::ScoreDialog(wxWindow
* parent
, ScoreFile
* file
) :
134 wxDialog(parent
, wxID_ANY
, _("Scores"),
135 wxDefaultPosition
, wxSize(400, 300)),
138 // create grid with players
139 wxArrayString players
;
140 file
->GetPlayerList(players
);
142 wxSize sz
= wxSize(400, 300);
144 #if USE_GRID_FOR_SCORE
145 wxGrid
* list
= new wxGrid(this, wxID_ANY
, wxDefaultPosition
, sz
, 0);
146 list
->CreateGrid(players
.Count(), 4);
147 for (unsigned int i
= 0; i
< players
.Count(); i
++)
149 int wins
, games
, score
;
150 wxString string_value
;
152 file
->ReadPlayersScore(players
[i
], wins
, games
, score
);
156 average
= (2 * score
+ games
) / (2 * games
);
158 list
->SetCellValue(i
,0,players
[i
]);
159 string_value
.Printf( wxT("%u"), wins
);
160 list
->SetCellValue(i
,1,string_value
);
161 string_value
.Printf( wxT("%u"), games
);
162 list
->SetCellValue(i
,2,string_value
);
163 string_value
.Printf( wxT("%u"), average
);
164 list
->SetCellValue(i
,3,string_value
);
166 list
->SetColLabelValue(0, wxT("Players"));
167 list
->SetColLabelValue(1, wxT("Wins"));
168 list
->SetColLabelValue(2, wxT("Games"));
169 list
->SetColLabelValue(3, wxT("Score"));
170 list
->SetEditable(false);
171 list
->AutoSizeColumns();
172 list
->AutoSizeRows();
173 list
->SetRowLabelSize(0);
174 list
->EnableDragRowSize(false);
175 list
->EnableDragColSize(false);
176 list
->EnableDragGridSize(false);
177 list
->ClearSelection();
178 list
->EnableEditing(false);
179 sz
.x
= wxDefaultCoord
;
181 ScoreCanvas
* list
= new ScoreCanvas(this, m_scoreFile
, wxDefaultPosition
, sz
);
184 list
->SetInitialSize(sz
);
186 // locate and resize with sizers
187 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
188 topsizer
->Add( list
, 1, wxALL
|wxGROW
, 10 );
189 wxButton
*button
= new wxButton(this, wxID_OK
);
190 topsizer
->Add( button
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 10 );
193 SetSizer( topsizer
);
195 GetSizer()->Fit(this);
196 GetSizer()->SetSizeHints(this);
201 void ScoreDialog::Display()
206 void ScoreDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))