1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Forty Thieves patience game
4 // Author: Chris Breeze
7 // Copyright: (c) 1993-1998 Chris Breeze
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
25 // adjust USE_GRID_FOR_SCORE with O or 1 to your preferences
26 // by default it takes wxGrid component for score display if available in target port
27 #define USE_GRID_FOR_SCORE wxUSE_GRID
29 #if USE_GRID_FOR_SCORE
32 class ScoreCanvas
: public wxScrolledWindow
35 ScoreCanvas(wxWindow
* parent
, ScoreFile
* scoreFile
, const wxPoint
& pos
, wxSize
& size
);
36 virtual ~ScoreCanvas();
38 void OnDraw(wxDC
& dc
);
45 ScoreCanvas::ScoreCanvas(wxWindow
* parent
, ScoreFile
* scoreFile
, const wxPoint
& pos
, wxSize
& size
) :
46 wxScrolledWindow(parent
, wxID_ANY
, pos
, size
, wxSUNKEN_BORDER
)
48 SetBackgroundColour(*wxWHITE
);
50 m_font
= wxTheFontList
->FindOrCreateFont(12, wxROMAN
, wxNORMAL
, wxNORMAL
);
52 m_font
= wxTheFontList
->FindOrCreateFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
55 wxArrayString players
;
56 scoreFile
->GetPlayerList( players
);
60 os
<< wxT("Player\tWins\tGames\tScore\n");
61 for (unsigned int i
= 0; i
< players
.Count(); i
++)
63 int wins
, games
, score
;
64 scoreFile
->ReadPlayersScore(players
[i
], wins
, games
, score
);
68 average
= (2 * score
+ games
) / (2 * games
);
71 os
<< players
[i
] << wxT('\t')
74 << average
<< wxT('\n');
80 ScoreCanvas::~ScoreCanvas()
84 void ScoreCanvas::OnDraw(wxDC
& dc
)
88 const wxChar
* str
= m_text
;
90 unsigned int tabstops
[] = { 5, 100, 150, 200 };
92 // get the line spacing for the current font
96 dc
.GetTextExtent(wxT("Testing"), &w
, &h
);
106 while (*str
&& *str
>= ' ') *dest
++ = *str
++;
109 dc
.DrawText(text
, tabstops
[tab
], y
);
113 if (tab
< sizeof(tabstops
) / sizeof(tabstops
[0]) - 1)
118 else if (*str
== '\n')
128 BEGIN_EVENT_TABLE(ScoreDialog
, wxDialog
)
129 EVT_CLOSE(ScoreDialog::OnCloseWindow
)
132 ScoreDialog::ScoreDialog(wxWindow
* parent
, ScoreFile
* file
) :
133 wxDialog(parent
, wxID_ANY
, _("Scores"),
134 wxDefaultPosition
, wxSize(400, 300)),
137 // create grid with players
138 wxArrayString players
;
139 file
->GetPlayerList(players
);
141 wxSize sz
= wxSize(400, 300);
143 #if USE_GRID_FOR_SCORE
144 wxGrid
* list
= new wxGrid(this, wxID_ANY
, wxDefaultPosition
, sz
, 0);
145 list
->CreateGrid(players
.Count(), 4);
146 for (unsigned int i
= 0; i
< players
.Count(); i
++)
148 int wins
, games
, score
;
149 wxString string_value
;
151 file
->ReadPlayersScore(players
[i
], wins
, games
, score
);
155 average
= (2 * score
+ games
) / (2 * games
);
157 list
->SetCellValue(i
,0,players
[i
]);
158 string_value
.Printf( wxT("%u"), wins
);
159 list
->SetCellValue(i
,1,string_value
);
160 string_value
.Printf( wxT("%u"), games
);
161 list
->SetCellValue(i
,2,string_value
);
162 string_value
.Printf( wxT("%u"), average
);
163 list
->SetCellValue(i
,3,string_value
);
165 list
->SetColLabelValue(0, wxT("Players"));
166 list
->SetColLabelValue(1, wxT("Wins"));
167 list
->SetColLabelValue(2, wxT("Games"));
168 list
->SetColLabelValue(3, wxT("Score"));
169 list
->EnableEditing(false);
170 list
->AutoSizeColumns();
171 list
->AutoSizeRows();
172 list
->SetRowLabelSize(0);
173 list
->EnableDragRowSize(false);
174 list
->EnableDragColSize(false);
175 list
->EnableDragGridSize(false);
176 list
->ClearSelection();
177 list
->EnableEditing(false);
178 sz
.x
= wxDefaultCoord
;
180 ScoreCanvas
* list
= new ScoreCanvas(this, m_scoreFile
, wxDefaultPosition
, sz
);
183 list
->SetInitialSize(sz
);
185 // locate and resize with sizers
186 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
187 topsizer
->Add( list
, 1, wxALL
|wxGROW
, 10 );
188 wxButton
*button
= new wxButton(this, wxID_OK
);
189 topsizer
->Add( button
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 10 );
192 SetSizer( topsizer
);
194 GetSizer()->Fit(this);
195 GetSizer()->SetSizeHints(this);
200 void ScoreDialog::Display()
205 void ScoreDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))