1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Forty Thieves patience game
4 // Author: Chris Breeze
8 // Copyright: (c) 1993-1998 Chris Breeze
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(__APPLE__)
13 #pragma implementation
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
31 // adjust USE_GRID_FOR_SCORE with O or 1 to your preferences
32 // by default it takes wxGrid component for score display if available in target port
33 #define USE_GRID_FOR_SCORE wxUSE_GRID
35 #if USE_GRID_FOR_SCORE
38 class ScoreCanvas
: public wxScrolledWindow
41 ScoreCanvas(wxWindow
* parent
, ScoreFile
* scoreFile
, const wxPoint
& pos
, wxSize
& size
);
42 virtual ~ScoreCanvas();
44 void OnDraw(wxDC
& dc
);
51 ScoreCanvas::ScoreCanvas(wxWindow
* parent
, ScoreFile
* scoreFile
, const wxPoint
& pos
, wxSize
& size
) :
52 wxScrolledWindow(parent
, wxID_ANY
, pos
, size
, wxSUNKEN_BORDER
)
54 SetBackgroundColour(*wxWHITE
);
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
<< wxT("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
] << wxT('\t')
80 << average
<< wxT('\n');
86 ScoreCanvas::~ScoreCanvas()
90 void ScoreCanvas::OnDraw(wxDC
& dc
)
94 const wxChar
* str
= m_text
;
96 unsigned int tabstops
[] = { 5, 100, 150, 200 };
98 // get the line spacing for the current font
102 dc
.GetTextExtent(wxT("Testing"), &w
, &h
);
103 lineSpacing
= (int)h
;
112 while (*str
&& *str
>= ' ') *dest
++ = *str
++;
115 dc
.DrawText(text
, tabstops
[tab
], y
);
119 if (tab
< sizeof(tabstops
) / sizeof(tabstops
[0]) - 1)
124 else if (*str
== '\n')
134 BEGIN_EVENT_TABLE(ScoreDialog
, wxDialog
)
135 EVT_CLOSE(ScoreDialog::OnCloseWindow
)
138 ScoreDialog::ScoreDialog(wxWindow
* parent
, ScoreFile
* file
) :
139 wxDialog(parent
, wxID_ANY
, _("Scores"),
140 wxDefaultPosition
, wxSize(400, 300)),
143 // create grid with players
144 wxArrayString players
;
145 file
->GetPlayerList(players
);
147 wxSize sz
= wxSize(400, 300);
149 #if USE_GRID_FOR_SCORE
150 wxGrid
* list
= new wxGrid(this, wxID_ANY
, wxDefaultPosition
, sz
, 0);
151 list
->CreateGrid(players
.Count(), 4);
152 for (unsigned int i
= 0; i
< players
.Count(); i
++)
154 int wins
, games
, score
;
155 wxString string_value
;
157 file
->ReadPlayersScore(players
[i
], wins
, games
, score
);
161 average
= (2 * score
+ games
) / (2 * games
);
163 list
->SetCellValue(i
,0,players
[i
]);
164 string_value
.Printf( _T("%u"), wins
);
165 list
->SetCellValue(i
,1,string_value
);
166 string_value
.Printf( _T("%u"), games
);
167 list
->SetCellValue(i
,2,string_value
);
168 string_value
.Printf( _T("%u"), average
);
169 list
->SetCellValue(i
,3,string_value
);
171 list
->SetColLabelValue(0, _T("Players"));
172 list
->SetColLabelValue(1, _T("Wins"));
173 list
->SetColLabelValue(2, _T("Games"));
174 list
->SetColLabelValue(3, _T("Score"));
175 list
->SetEditable(false);
176 list
->AutoSizeColumns();
177 list
->AutoSizeRows();
178 list
->SetRowLabelSize(0);
179 list
->EnableDragRowSize(false);
180 list
->EnableDragColSize(false);
181 list
->EnableDragGridSize(false);
182 list
->ClearSelection();
183 list
->EnableEditing(false);
184 sz
.x
= wxDefaultCoord
;
186 ScoreCanvas
* list
= new ScoreCanvas(this, m_scoreFile
, wxDefaultPosition
, sz
);
189 list
->SetBestFittingSize(sz
);
191 // locate and resize with sizers
192 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
193 topsizer
->Add( list
, 1, wxALL
|wxGROW
, 10 );
194 wxButton
*button
= new wxButton(this, wxID_OK
);
195 topsizer
->Add( button
, 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 10 );
198 SetSizer( topsizer
);
200 GetSizer()->Fit(this);
201 GetSizer()->SetSizeHints(this);
206 void ScoreDialog::Display()
211 void ScoreDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))