]>
git.saurik.com Git - wxWidgets.git/blob - demos/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"
31 #if defined(__WXMSW__) && !defined(__GNUWIN32__) && !defined(__MWERKS__)
34 #include <strstream.h>
38 //using namespace std;
43 class ScoreCanvas
: public wxScrolledWindow
46 ScoreCanvas(wxWindow
* parent
, ScoreFile
* scoreFile
);
47 virtual ~ScoreCanvas();
49 void OnDraw(wxDC
& dc
);
57 ScoreCanvas::ScoreCanvas(wxWindow
* parent
, ScoreFile
* scoreFile
) :
58 wxScrolledWindow(parent
)
61 m_font
= wxTheFontList
->FindOrCreateFont(12, wxROMAN
, wxNORMAL
, wxNORMAL
);
63 m_font
= wxTheFontList
->FindOrCreateFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
66 wxArrayString players
;
67 scoreFile
->GetPlayerList( players
);
71 os
<< "Player\tWins\tGames\tScore\n";
72 for (unsigned int i
= 0; i
< players
.Count(); i
++)
74 int wins
, games
, score
;
75 scoreFile
->ReadPlayersScore(players
[i
], wins
, games
, score
);
79 average
= (2 * score
+ games
) / (2 * games
);
82 os
<< players
[i
] << '\t'
93 ScoreCanvas::~ScoreCanvas()
97 void ScoreCanvas::OnDraw(wxDC
& dc
)
101 const char* str
= m_text
;
102 unsigned int tab
= 0;
103 unsigned int tabstops
[] = { 5, 100, 150, 200 };
105 // get the line spacing for the current font
109 dc
.GetTextExtent("Testing", &w
, &h
);
110 lineSpacing
= (int)h
;
119 while (*str
&& *str
>= ' ') *dest
++ = *str
++;
122 dc
.DrawText(text
, tabstops
[tab
], y
);
126 if (tab
< sizeof(tabstops
) / sizeof(tabstops
[0]) - 1)
131 else if (*str
== '\n')
140 BEGIN_EVENT_TABLE(ScoreDialog
, wxDialog
)
141 EVT_CLOSE(ScoreDialog::OnCloseWindow
)
144 ScoreDialog::ScoreDialog(
148 wxDialog(parent
, -1, "Scores",
149 wxDefaultPosition
, wxSize(310, 200),
150 wxDIALOG_MODAL
| wxDEFAULT_DIALOG_STYLE
),
153 // enable constraints
154 SetAutoLayout (TRUE
);
156 ScoreCanvas
* list
= new ScoreCanvas(this, m_scoreFile
);
157 m_OK
= new wxButton(this, wxID_OK
, "OK");
159 wxLayoutConstraints
* layout
;
161 // Constrain the OK button
162 layout
= new wxLayoutConstraints
;
163 layout
->left
.SameAs (this, wxLeft
, 10);
164 layout
->bottom
.SameAs (this, wxBottom
, 10);
165 layout
->height
.AsIs();
166 layout
->width
.AsIs();
167 m_OK
->SetConstraints(layout
);
169 // Constrain the list of players
170 layout
= new wxLayoutConstraints
;
171 layout
->left
.SameAs (this, wxLeft
, 10);
172 layout
->right
.SameAs (this, wxRight
, 10);
173 layout
->top
.SameAs (this, wxTop
, 10);
174 layout
->bottom
.SameAs (m_OK
, wxTop
, 10);
175 list
->SetConstraints(layout
);
180 ScoreDialog::~ScoreDialog()
184 void ScoreDialog::Display()
189 void ScoreDialog::OnCloseWindow(wxCloseEvent
& event
)