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 #define USE_GRID_FOR_SCORE 0
33 #if USE_GRID_FOR_SCORE
36 class ScoreCanvas
: public wxScrolledWindow
39 ScoreCanvas(wxWindow
* parent
, ScoreFile
* scoreFile
, const wxPoint
& pos
, wxSize
& size
);
40 virtual ~ScoreCanvas();
42 void OnDraw(wxDC
& dc
);
49 ScoreCanvas::ScoreCanvas(wxWindow
* parent
, ScoreFile
* scoreFile
, const wxPoint
& pos
, wxSize
& size
) :
50 wxScrolledWindow(parent
, wxID_ANY
, pos
, size
, wxSUNKEN_BORDER
)
52 SetBackgroundColour(*wxWHITE
);
54 m_font
= wxTheFontList
->FindOrCreateFont(12, wxROMAN
, wxNORMAL
, wxNORMAL
);
56 m_font
= wxTheFontList
->FindOrCreateFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
59 wxArrayString players
;
60 scoreFile
->GetPlayerList( players
);
64 os
<< wxT("Player\tWins\tGames\tScore\n");
65 for (unsigned int i
= 0; i
< players
.Count(); i
++)
67 int wins
, games
, score
;
68 scoreFile
->ReadPlayersScore(players
[i
], wins
, games
, score
);
72 average
= (2 * score
+ games
) / (2 * games
);
75 os
<< players
[i
] << wxT('\t')
78 << average
<< wxT('\n');
84 ScoreCanvas::~ScoreCanvas()
88 void ScoreCanvas::OnDraw(wxDC
& dc
)
92 const wxChar
* str
= m_text
;
94 unsigned int tabstops
[] = { 5, 100, 150, 200 };
96 // get the line spacing for the current font
100 dc
.GetTextExtent(wxT("Testing"), &w
, &h
);
101 lineSpacing
= (int)h
;
110 while (*str
&& *str
>= ' ') *dest
++ = *str
++;
113 dc
.DrawText(text
, tabstops
[tab
], y
);
117 if (tab
< sizeof(tabstops
) / sizeof(tabstops
[0]) - 1)
122 else if (*str
== '\n')
132 BEGIN_EVENT_TABLE(ScoreDialog
, wxDialog
)
133 EVT_CLOSE(ScoreDialog::OnCloseWindow
)
136 ScoreDialog::ScoreDialog(wxWindow
* parent
, ScoreFile
* file
) :
137 wxDialog(parent
, wxID_ANY
, _("Scores"),
138 wxDefaultPosition
, wxSize(400, 300)),
141 // create grid with players
142 wxArrayString players
;
143 file
->GetPlayerList(players
);
145 wxSize sz
= wxSize(400, 300);
147 #if USE_GRID_FOR_SCORE
148 wxGrid
* list
= new wxGrid(this, wxID_ANY
, wxDefaultPosition
, sz
, 0);
149 list
->CreateGrid(players
.Count(), 4);
150 for (unsigned int i
= 0; i
< players
.Count(); i
++)
152 int wins
, games
, score
;
153 wxString string_value
;
155 file
->ReadPlayersScore(players
[i
], wins
, games
, score
);
159 average
= (2 * score
+ games
) / (2 * games
);
161 list
->SetCellValue(i
,0,players
[i
]);
162 string_value
.Printf( _T("%u"), wins
);
163 list
->SetCellValue(i
,1,string_value
);
164 string_value
.Printf( _T("%u"), games
);
165 list
->SetCellValue(i
,2,string_value
);
166 string_value
.Printf( _T("%u"), average
);
167 list
->SetCellValue(i
,3,string_value
);
169 list
->SetColLabelValue(0, _T("Players"));
170 list
->SetColLabelValue(1, _T("Wins"));
171 list
->SetColLabelValue(2, _T("Games"));
172 list
->SetColLabelValue(3, _T("Score"));
173 list
->SetEditable(false);
174 list
->AutoSizeColumns();
175 list
->AutoSizeRows();
176 list
->SetRowLabelSize(0);
177 list
->EnableDragRowSize(false);
178 list
->EnableDragColSize(false);
179 list
->EnableDragGridSize(false);
181 ScoreCanvas
* list
= new ScoreCanvas(this, m_scoreFile
, wxDefaultPosition
, sz
);
184 // locate and resize with sizers
185 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
186 topsizer
->Add( list
, 1, wxALL
|wxGROW
, 10 );
187 topsizer
->Add( new wxButton(this, wxID_OK
, _("OK")), 0, wxALIGN_CENTER_HORIZONTAL
|wxALL
, 10 );
189 SetSizer( topsizer
);
191 GetSizer()->Fit(this);
192 GetSizer()->SetSizeHints(this);
197 ScoreDialog::~ScoreDialog()
201 void ScoreDialog::Display()
206 void ScoreDialog::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))