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 /////////////////////////////////////////////////////////////////////////////
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__)
45 #include "pictures.xpm"
46 #include "symbols.xbm"
49 wxBitmap
* Card::m_pictureBmap
= 0;
50 wxBitmap
* Card::m_symbolBmap
= 0;
53 //+-------------------------------------------------------------+
55 //+-------------------------------------------------------------+
57 //| Constructor for a playing card. |
58 //| Checks that the value is in the range 1..52 and then |
59 //| initialises the suit, colour, pipValue and wayUp. |
60 //+-------------------------------------------------------------+
61 Card::Card(int value
, WayUp way_up
) :
67 m_symbolBmap
= new wxBitmap("CardSymbols", wxBITMAP_TYPE_BMP_RESOURCE
);
69 m_symbolBmap
= new wxBitmap(Symbols_bits
, Symbols_width
, Symbols_height
);
71 if (!m_symbolBmap
->Ok())
73 ::wxMessageBox("Failed to load bitmap CardSymbols", "Error");
79 m_pictureBmap
= new wxBitmap("CardPictures", wxBITMAP_TYPE_BMP_RESOURCE
);
81 m_pictureBmap
= new wxBitmap(Pictures
);
83 if (!m_pictureBmap
->Ok())
85 ::wxMessageBox("Failed to load bitmap CardPictures", "Error");
89 if (value
>= 1 && value
<= PackSize
)
91 switch ((value
- 1) / 13)
110 m_pipValue
= 1 + (value
- 1) % 13;
120 //+-------------------------------------------------------------+
122 //+-------------------------------------------------------------+
124 //| Destructor - nothing to do at present. |
125 //+-------------------------------------------------------------+
131 //+-------------------------------------------------------------+
133 //+-------------------------------------------------------------+
135 //| Erase the card at (x, y) by drawing a rectangle in the |
136 //| background colour. |
137 //+-------------------------------------------------------------+
138 void Card::Erase(wxDC
& dc
, int x
, int y
)
140 wxPen
* pen
= wxThePenList
->FindOrCreatePen(
141 FortyApp::BackgroundColour(),
146 dc
.SetBrush(FortyApp::BackgroundBrush());
147 dc
.DrawRectangle(x
, y
, CardWidth
, CardHeight
);
151 //+-------------------------------------------------------------+
153 //+-------------------------------------------------------------+
155 //| Draw the card at (x, y). |
156 //| If the card is facedown draw the back of the card. |
157 //| If the card is faceup draw the front of the card. |
158 //| Cards are not held in bitmaps, instead they are drawn |
159 //| from their constituent parts when required. |
160 //| hbmap_symbols contains large and small suit symbols and |
161 //| pip values. These are copied to the appropriate part of |
162 //| the card. Picture cards use the pictures defined in |
163 //| hbmap_pictures. Note that only one picture is defined |
164 //| for the Jack, Queen and King, unlike a real pack where |
165 //| each suit is different. |
168 //| The locations of these symbols is 'hard-wired' into the |
169 //| code. Editing the bitmaps or the numbers below will |
170 //| result in the wrong symbols being displayed. |
171 //+-------------------------------------------------------------+
172 void Card::Draw(wxDC
& dc
, int x
, int y
)
174 wxBrush
backgroundBrush( dc
.GetBackground() );
175 dc
.SetBrush(* wxWHITE_BRUSH
);
176 dc
.SetPen(* wxBLACK_PEN
);
177 dc
.DrawRoundedRectangle(x
, y
, CardWidth
, CardHeight
, 4);
178 if (m_wayUp
== facedown
)
180 dc
.SetBackground(* wxRED_BRUSH
);
181 dc
.SetBackgroundMode(wxSOLID
);
182 wxBrush
* brush
= wxTheBrushList
->FindOrCreateBrush(
183 "BLACK", wxCROSSDIAG_HATCH
185 dc
.SetBrush(* brush
);
187 dc
.DrawRoundedRectangle(
189 CardWidth
- 8, CardHeight
- 8,
196 memoryDC
.SelectObject(* m_symbolBmap
);
198 // dc.SetBackgroundMode(wxTRANSPARENT);
200 dc
.SetTextBackground(*wxWHITE
);
205 dc
.SetTextForeground(*wxBLACK
);
209 dc
.SetTextForeground(*wxRED
);
213 dc
.Blit(x
+ 3, y
+ 3, 6, 7,
214 &memoryDC
, 6 * (m_pipValue
- 1), 36, wxCOPY
);
215 dc
.Blit(x
+ CardWidth
- 9, y
+ CardHeight
- 11, 6, 7,
216 &memoryDC
, 6 * (m_pipValue
- 1), 43, wxCOPY
);
219 dc
.Blit(x
+ 11, y
+ 3, 7, 7,
220 &memoryDC
, 7 * m_suit
, 0, wxCOPY
);
221 dc
.Blit(x
+ CardWidth
- 17, y
+ CardHeight
- 11, 7, 7,
222 &memoryDC
, 7 * m_suit
, 7, wxCOPY
);
227 dc
.Blit(x
- 5 + CardWidth
/ 2, y
- 5 + CardHeight
/ 2, 11, 11,
228 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
232 dc
.Blit(x
- 5 + CardWidth
/ 2, y
- 5 + CardHeight
/ 2, 11, 11,
233 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
235 dc
.Blit(x
- 5 + CardWidth
/ 2,
236 y
- 5 + CardHeight
/ 4, 11, 11,
237 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
238 dc
.Blit(x
- 5 + CardWidth
/ 2,
239 y
- 5 + 3 * CardHeight
/ 4, 11, 11,
240 &memoryDC
, 11 * m_suit
, 25, wxCOPY
);
244 dc
.Blit(x
- 5 + CardWidth
/ 2, y
- 5 + CardHeight
/ 2, 11, 11,
245 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
247 dc
.Blit(x
- 5 + CardWidth
/ 4,
248 y
- 5 + CardHeight
/ 4, 11, 11,
249 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
250 dc
.Blit(x
- 5 + CardWidth
/ 4,
251 y
- 5 + 3 * CardHeight
/ 4, 11, 11,
252 &memoryDC
, 11 * m_suit
, 25, wxCOPY
);
253 dc
.Blit(x
- 5 + 3 * CardWidth
/ 4,
254 y
- 5 + CardHeight
/ 4, 11, 11,
255 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
256 dc
.Blit(x
- 5 + 3 * CardWidth
/ 4,
257 y
- 5 + 3 * CardHeight
/ 4, 11, 11,
258 &memoryDC
, 11 * m_suit
, 25, wxCOPY
);
262 dc
.Blit(x
- 5 + 5 * CardWidth
/ 10,
263 y
- 5 + 5 * CardHeight
/ 8, 11, 11,
264 &memoryDC
, 11 * m_suit
, 25, wxCOPY
);
266 dc
.Blit(x
- 5 + 5 * CardWidth
/ 10,
267 y
- 5 + 3 * CardHeight
/ 8, 11, 11,
268 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
270 dc
.Blit(x
- 5 + CardWidth
/ 4,
271 y
- 5 + CardHeight
/ 4, 11, 11,
272 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
273 dc
.Blit(x
- 5 + CardWidth
/ 4,
274 y
- 5 + CardHeight
/ 2, 11, 11,
275 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
276 dc
.Blit(x
- 5 + CardWidth
/ 4,
277 y
- 5 + 3 * CardHeight
/ 4, 11, 11,
278 &memoryDC
, 11 * m_suit
, 25, wxCOPY
);
279 dc
.Blit(x
- 5 + 3 * CardWidth
/ 4,
280 y
- 5 + CardHeight
/ 4, 11, 11,
281 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
282 dc
.Blit(x
- 5 + 3 * CardWidth
/ 4,
283 y
- 5 + CardHeight
/ 2, 11, 11,
284 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
285 dc
.Blit(x
- 5 + 3 * CardWidth
/ 4,
286 y
- 5 + 3 * CardHeight
/ 4, 11, 11,
287 &memoryDC
, 11 * m_suit
, 25, wxCOPY
);
291 dc
.Blit(x
- 5 + CardWidth
/ 2,
292 y
- 5 + 2 * CardHeight
/ 3, 11, 11,
293 &memoryDC
, 11 * m_suit
, 25, wxCOPY
);
295 dc
.Blit(x
- 5 + CardWidth
/ 4,
296 y
- 6 + CardHeight
/ 4, 11, 11,
297 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
298 dc
.Blit(x
- 5 + CardWidth
/ 4,
299 y
- 6 + 5 * CardHeight
/ 12, 11, 11,
300 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
301 dc
.Blit(x
- 5 + CardWidth
/ 4,
302 y
- 5 + 7 * CardHeight
/ 12, 11, 11,
303 &memoryDC
, 11 * m_suit
, 25, wxCOPY
);
304 dc
.Blit(x
- 5 + CardWidth
/ 4,
305 y
- 5 + 3 * CardHeight
/ 4, 11, 11,
306 &memoryDC
, 11 * m_suit
, 25, wxCOPY
);
308 dc
.Blit(x
- 5 + 3 * CardWidth
/ 4,
309 y
- 6 + CardHeight
/ 4, 11, 11,
310 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
311 dc
.Blit(x
- 5 + 3 * CardWidth
/ 4,
312 y
- 6 + 5 * CardHeight
/ 12, 11, 11,
313 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
314 dc
.Blit(x
- 5 + 3 * CardWidth
/ 4,
315 y
- 5 + 7 * CardHeight
/ 12, 11, 11,
316 &memoryDC
, 11 * m_suit
, 25, wxCOPY
);
317 dc
.Blit(x
- 5 + 3 * CardWidth
/ 4,
318 y
- 5 + 3 * CardHeight
/ 4, 11, 11,
319 &memoryDC
, 11 * m_suit
, 25, wxCOPY
);
320 dc
.Blit(x
- 5 + CardWidth
/ 2,
321 y
- 5 + CardHeight
/ 3, 11, 11,
322 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
327 memoryDC
.SelectObject(* m_pictureBmap
);
328 dc
.Blit(x
+ 5, y
- 5 + CardHeight
/ 4, 40, 45,
329 &memoryDC
, 40 * (m_pipValue
- 11), 0, wxCOPY
);
330 memoryDC
.SelectObject(* m_symbolBmap
);
331 dc
.Blit(x
+ 32, y
- 3 + CardHeight
/ 4, 11, 11,
332 &memoryDC
, 11 * m_suit
, 14, wxCOPY
);
333 dc
.Blit(x
+ 7, y
+ 27 + CardHeight
/ 4, 11, 11,
334 &memoryDC
, 11 * m_suit
, 25, wxCOPY
);
339 dc
.SetBackground( backgroundBrush
);
343 //+-------------------------------------------------------------+
344 //| Card::DrawNullCard() |
345 //+-------------------------------------------------------------+
347 //| Draws the outline of a card at (x, y). |
348 //| Used to draw place holders for empty piles of cards. |
349 //+-------------------------------------------------------------+
350 void Card::DrawNullCard(wxDC
& dc
, int x
, int y
)
352 wxPen
* pen
= wxThePenList
->FindOrCreatePen(FortyApp::TextColour(), 1, wxSOLID
);
353 dc
.SetBrush(FortyApp::BackgroundBrush());
355 dc
.DrawRoundedRectangle(x
, y
, CardWidth
, CardHeight
, 4);
356 } // Card::DrawNullCard()