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 wxWidgets 2.0
12 /////////////////////////////////////////////////////////////////////////////
13 //+-------------------------------------------------------------+
15 //| A class for drawing playing cards.
16 //| Currently assumes that the card symbols have been
17 //| loaded into hbmap_symbols and the pictures for the
18 //| Jack, Queen and King have been loaded into
20 //+-------------------------------------------------------------+
23 #pragma implementation
27 // For compilers that support precompilation, includes "wx/wx.h".
28 #include "wx/wxprec.h"
44 #if defined(__WXGTK__) || defined(__WXMOTIF__) || defined(__WXMAC__) || defined(__WXX11__)
45 #include "pictures.xpm"
46 #include "symbols.xbm"
49 wxBitmap
* Card::m_pictureBmap
= 0;
50 wxBitmap
* Card::m_symbolBmap
= 0;
52 double Card::m_scale
= 1.0;
53 int Card::m_width
= 50;
54 int Card::m_height
= 70;
56 //+-------------------------------------------------------------+
58 //+-------------------------------------------------------------+
60 //| Constructor for a playing card. |
61 //| Checks that the value is in the range 1..52 and then |
62 //| initialises the suit, colour, pipValue and wayUp. |
63 //+-------------------------------------------------------------+
64 Card::Card(int value
, WayUp way_up
) :
70 m_symbolBmap
= new wxBitmap(_T("CardSymbols"), wxBITMAP_TYPE_BMP_RESOURCE
);
72 m_symbolBmap
= new wxBitmap(Symbols_bits
, Symbols_width
, Symbols_height
);
74 if (!m_symbolBmap
->Ok())
76 ::wxMessageBox(_T("Failed to load bitmap CardSymbols"), _T("Error"));
82 m_pictureBmap
= new wxBitmap(_T("CardPictures"), wxBITMAP_TYPE_BMP_RESOURCE
);
84 m_pictureBmap
= new wxBitmap(Pictures
);
86 if (!m_pictureBmap
->Ok())
88 ::wxMessageBox(_T("Failed to load bitmap CardPictures"), _T("Error"));
92 if (value
>= 1 && value
<= PackSize
)
94 switch ((value
- 1) / 13)
113 m_pipValue
= 1 + (value
- 1) % 13;
123 //+-------------------------------------------------------------+
124 //| Card::SetScale() |
125 //+-------------------------------------------------------------+
127 //| Scales the cards |
128 //+-------------------------------------------------------------+
129 void Card::SetScale(double scale
)
132 m_width
= int(50*scale
);
133 m_height
= int(70*scale
);
136 //+-------------------------------------------------------------+
138 //+-------------------------------------------------------------+
140 //| Destructor - nothing to do at present. |
141 //+-------------------------------------------------------------+
147 //+-------------------------------------------------------------+
149 //+-------------------------------------------------------------+
151 //| Erase the card at (x, y) by drawing a rectangle in the |
152 //| background colour. |
153 //+-------------------------------------------------------------+
154 void Card::Erase(wxDC
& dc
, int x
, int y
)
156 wxPen
* pen
= wxThePenList
->FindOrCreatePen(
157 FortyApp::BackgroundColour(),
162 dc
.SetBrush(FortyApp::BackgroundBrush());
163 dc
.DrawRectangle(x
, y
, m_width
, m_height
);
167 //+-------------------------------------------------------------+
169 //+-------------------------------------------------------------+
171 //| Draw the card at (x, y). |
172 //| If the card is facedown draw the back of the card. |
173 //| If the card is faceup draw the front of the card. |
174 //| Cards are not held in bitmaps, instead they are drawn |
175 //| from their constituent parts when required. |
176 //| hbmap_symbols contains large and small suit symbols and |
177 //| pip values. These are copied to the appropriate part of |
178 //| the card. Picture cards use the pictures defined in |
179 //| hbmap_pictures. Note that only one picture is defined |
180 //| for the Jack, Queen and King, unlike a real pack where |
181 //| each suit is different. |
184 //| The locations of these symbols is 'hard-wired' into the |
185 //| code. Editing the bitmaps or the numbers below will |
186 //| result in the wrong symbols being displayed. |
187 //+-------------------------------------------------------------+
188 void Card::Draw(wxDC
& dc
, int x
, int y
)
190 wxBrush
backgroundBrush( dc
.GetBackground() );
191 dc
.SetBrush(* wxWHITE_BRUSH
);
192 dc
.SetPen(* wxBLACK_PEN
);
193 dc
.DrawRoundedRectangle(x
, y
, m_width
, m_height
, 4);
194 if (m_wayUp
== facedown
)
196 dc
.SetBackground(* wxRED_BRUSH
);
197 dc
.SetBackgroundMode(wxSOLID
);
198 wxBrush
* brush
= wxTheBrushList
->FindOrCreateBrush(
199 _T("BLACK"), wxCROSSDIAG_HATCH
201 dc
.SetBrush(* brush
);
203 dc
.DrawRoundedRectangle(
205 m_width
- 8, m_height
- 8,
213 memoryDC
.SelectObject(*m_symbolBmap
);
215 // dc.SetBackgroundMode(wxTRANSPARENT);
217 dc
.SetTextBackground(*wxWHITE
);
222 dc
.SetTextForeground(*wxBLACK
);
226 dc
.SetTextForeground(*wxRED
);
236 int pipsize
,pippos
,valueheight
,valuewidth
;
256 dc
.Blit((wxCoord
)(x
+ m_scale
*3), (wxCoord
)(y
+ m_scale
*3), valuewidth
, valueheight
,
257 &memoryDC
, valuewidth
* (m_pipValue
- 1), valuepos
, wxCOPY
);
258 dc
.Blit((wxCoord
)(x
+ m_width
- m_scale
*3 - valuewidth
), (wxCoord
)(y
+ m_height
- valueheight
- m_scale
*3),
259 valuewidth
, valueheight
,
260 &memoryDC
, valuewidth
* (m_pipValue
- 1), valuepos
+valueheight
, wxCOPY
);
263 dc
.Blit((wxCoord
)(x
+ m_scale
*3 + valuewidth
+2), (wxCoord
)(y
+ m_scale
*3), pipsize
, pipsize
,
264 &memoryDC
, pipsize
* m_suit
, pippos
, wxCOPY
);
265 dc
.Blit((wxCoord
)(x
+ m_width
- m_scale
*3-valuewidth
-pipsize
-2), (wxCoord
)(y
+ m_height
- pipsize
- m_scale
*3),
267 &memoryDC
, pipsize
* m_suit
, pipsize
+pippos
, wxCOPY
);
272 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2), (wxCoord
)(y
- m_scale
*5 + m_height
/ 2), symsize
, symsize
,
273 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
277 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2), (wxCoord
)(y
- symdist
+ m_height
/ 2), symsize
, symsize
,
278 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
280 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
281 (wxCoord
)(y
- symdist
+ m_height
/ 4), symsize
, symsize
,
282 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
283 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
284 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4), symsize
, symsize
,
285 &memoryDC
, symsize
* m_suit
, sympos2
, wxCOPY
);
289 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2), (wxCoord
)(y
- symdist
+ m_height
/ 2), symsize
, symsize
,
290 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
292 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
293 (wxCoord
)(y
- symdist
+ m_height
/ 4), symsize
, symsize
,
294 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
295 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
296 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4), symsize
, symsize
,
297 &memoryDC
, symsize
* m_suit
, sympos2
, wxCOPY
);
298 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
299 (wxCoord
)(y
- symdist
+ m_height
/ 4), symsize
, symsize
,
300 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
301 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
302 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4), symsize
, symsize
,
303 &memoryDC
, symsize
* m_suit
, sympos2
, wxCOPY
);
307 dc
.Blit((wxCoord
)(x
- symdist
+ 5 * m_width
/ 10),
308 (wxCoord
)(y
- symdist
+ 5 * m_height
/ 8), symsize
, symsize
,
309 &memoryDC
, symsize
* m_suit
, sympos2
, wxCOPY
);
311 dc
.Blit((wxCoord
)(x
- symdist
+ 5 * m_width
/ 10),
312 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 8), symsize
, symsize
,
313 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
315 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
316 (wxCoord
)(y
- symdist
+ m_height
/ 4), symsize
, symsize
,
317 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
318 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
319 (wxCoord
)(y
- symdist
+ m_height
/ 2), symsize
, symsize
,
320 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
321 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
322 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4), symsize
, symsize
,
323 &memoryDC
, symsize
* m_suit
, sympos2
, wxCOPY
);
324 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
325 (wxCoord
)(y
- symdist
+ m_height
/ 4), symsize
, symsize
,
326 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
327 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
328 (wxCoord
)(y
- symdist
+ m_height
/ 2), symsize
, symsize
,
329 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
330 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
331 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4), symsize
, symsize
,
332 &memoryDC
, symsize
* m_suit
, sympos2
, wxCOPY
);
336 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
337 (wxCoord
)(y
- symdist
+ 2 * m_height
/ 3), symsize
, symsize
,
338 &memoryDC
, symsize
* m_suit
, sympos2
, wxCOPY
);
340 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
341 (wxCoord
)(y
- symdist2
+ m_height
/ 4), symsize
, symsize
,
342 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
343 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
344 (wxCoord
)(y
- symdist2
+ 5 * m_height
/ 12), symsize
, symsize
,
345 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
346 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
347 (wxCoord
)(y
- symdist
+ 7 * m_height
/ 12), symsize
, symsize
,
348 &memoryDC
, symsize
* m_suit
, sympos2
, wxCOPY
);
349 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
350 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4), symsize
, symsize
,
351 &memoryDC
, symsize
* m_suit
, sympos2
, wxCOPY
);
353 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
354 (wxCoord
)(y
- symdist2
+ m_height
/ 4), symsize
, symsize
,
355 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
356 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
357 (wxCoord
)(y
- symdist2
+ 5 * m_height
/ 12), symsize
, symsize
,
358 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
359 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
360 (wxCoord
)(y
- symdist
+ 7 * m_height
/ 12), symsize
, symsize
,
361 &memoryDC
, symsize
* m_suit
, sympos2
, wxCOPY
);
362 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
363 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4), symsize
, symsize
,
364 &memoryDC
, symsize
* m_suit
, sympos2
, wxCOPY
);
365 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
366 (wxCoord
)(y
- symdist
+ m_height
/ 3), symsize
, symsize
,
367 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
372 memoryDC
.SelectObject(*m_pictureBmap
);
373 int picwidth
= 40,picheight
= 45;
374 dc
.Blit((wxCoord
)(x
+ (m_width
-picwidth
)/2), (wxCoord
)(y
- picheight
/2 + m_height
/2),
376 &memoryDC
, picwidth
* (m_pipValue
- 11), 0, wxCOPY
);
378 memoryDC
.SelectObject(*m_symbolBmap
);
379 dc
.Blit((wxCoord
)(x
+ m_width
-(m_width
-picwidth
)/2-symsize
-3),(wxCoord
)(y
- picheight
/2+m_height
/2+1), symsize
, symsize
,
380 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
381 dc
.Blit((wxCoord
)(x
+ (m_width
-picwidth
)/2+2),(wxCoord
)(y
+ picheight
/2 + m_height
/2-symsize
), symsize
, symsize
,
382 &memoryDC
, symsize
* m_suit
, sympos2
, wxCOPY
);
387 dc
.SetBackground( backgroundBrush
);
391 //+-------------------------------------------------------------+
392 //| Card::DrawNullCard() |
393 //+-------------------------------------------------------------+
395 //| Draws the outline of a card at (x, y). |
396 //| Used to draw place holders for empty piles of cards. |
397 //+-------------------------------------------------------------+
398 void Card::DrawNullCard(wxDC
& dc
, int x
, int y
)
400 wxPen
* pen
= wxThePenList
->FindOrCreatePen(FortyApp::TextColour(), 1, wxSOLID
);
401 dc
.SetBrush(FortyApp::BackgroundBrush());
403 dc
.DrawRoundedRectangle(x
, y
, m_width
, m_height
, 4);
404 } // Card::DrawNullCard()