]>
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 /////////////////////////////////////////////////////////////////////////////
14 #if defined(__GNUG__) && !defined(__APPLE__)
15 #pragma implementation
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
33 class ScoreCanvas
: public wxScrolledWindow
36 ScoreCanvas(wxWindow
* parent
, ScoreFile
* scoreFile
);
37 virtual ~ScoreCanvas();
39 void OnDraw(wxDC
& dc
);
47 ScoreCanvas::ScoreCanvas(wxWindow
* parent
, ScoreFile
* scoreFile
) :
48 wxScrolledWindow(parent
)
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 char* str
= m_text
;
91 unsigned int tabstops
[] = { 5, 100, 150, 200 };
93 // get the line spacing for the current font
97 dc
.GetTextExtent("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')
128 BEGIN_EVENT_TABLE(ScoreDialog
, wxDialog
)
129 EVT_CLOSE(ScoreDialog::OnCloseWindow
)
132 ScoreDialog::ScoreDialog(
136 wxDialog(parent
, -1, "Scores",
137 wxDefaultPosition
, wxSize(310, 200),
138 wxDIALOG_MODAL
| wxDEFAULT_DIALOG_STYLE
),
141 // enable constraints
142 SetAutoLayout (TRUE
);
144 ScoreCanvas
* list
= new ScoreCanvas(this, m_scoreFile
);
145 m_OK
= new wxButton(this, wxID_OK
, "OK");
147 wxLayoutConstraints
* layout
;
149 // Constrain the OK button
150 layout
= new wxLayoutConstraints
;
151 layout
->left
.SameAs (this, wxLeft
, 10);
152 layout
->bottom
.SameAs (this, wxBottom
, 10);
153 layout
->height
.AsIs();
154 layout
->width
.AsIs();
155 m_OK
->SetConstraints(layout
);
157 // Constrain the list of players
158 layout
= new wxLayoutConstraints
;
159 layout
->left
.SameAs (this, wxLeft
, 10);
160 layout
->right
.SameAs (this, wxRight
, 10);
161 layout
->top
.SameAs (this, wxTop
, 10);
162 layout
->bottom
.SameAs (m_OK
, wxTop
, 10);
163 list
->SetConstraints(layout
);
168 ScoreDialog::~ScoreDialog()
172 void ScoreDialog::Display()
177 void ScoreDialog::OnCloseWindow(wxCloseEvent
& event
)