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 //| Erase the card at (x, y) by drawing a rectangle in the |
141 //| background colour. |
142 //+-------------------------------------------------------------+
143 void Card::Erase(wxDC
& dc
, int x
, int y
)
145 wxPen
* pen
= wxThePenList
->FindOrCreatePen(
146 FortyApp::BackgroundColour(),
151 dc
.SetBrush(FortyApp::BackgroundBrush());
152 dc
.DrawRectangle(x
, y
, m_width
, m_height
);
156 //+-------------------------------------------------------------+
158 //+-------------------------------------------------------------+
160 //| Draw the card at (x, y). |
161 //| If the card is facedown draw the back of the card. |
162 //| If the card is faceup draw the front of the card. |
163 //| Cards are not held in bitmaps, instead they are drawn |
164 //| from their constituent parts when required. |
165 //| hbmap_symbols contains large and small suit symbols and |
166 //| pip values. These are copied to the appropriate part of |
167 //| the card. Picture cards use the pictures defined in |
168 //| hbmap_pictures. Note that only one picture is defined |
169 //| for the Jack, Queen and King, unlike a real pack where |
170 //| each suit is different. |
173 //| The locations of these symbols is 'hard-wired' into the |
174 //| code. Editing the bitmaps or the numbers below will |
175 //| result in the wrong symbols being displayed. |
176 //+-------------------------------------------------------------+
177 void Card::Draw(wxDC
& dc
, int x
, int y
)
179 wxBrush
backgroundBrush( dc
.GetBackground() );
180 dc
.SetBrush(* wxWHITE_BRUSH
);
181 dc
.SetPen(* wxBLACK_PEN
);
182 dc
.DrawRoundedRectangle(x
, y
, m_width
, m_height
, 4);
183 if (m_wayUp
== facedown
)
185 dc
.SetBackground(* wxRED_BRUSH
);
186 dc
.SetBackgroundMode(wxSOLID
);
187 wxBrush
* brush
= wxTheBrushList
->FindOrCreateBrush(
188 _T("BLACK"), wxCROSSDIAG_HATCH
190 dc
.SetBrush(* brush
);
192 dc
.DrawRoundedRectangle(
194 m_width
- 8, m_height
- 8,
202 memoryDC
.SelectObject(*m_symbolBmap
);
204 // dc.SetBackgroundMode(wxTRANSPARENT);
206 dc
.SetTextBackground(*wxWHITE
);
211 dc
.SetTextForeground(*wxBLACK
);
215 dc
.SetTextForeground(*wxRED
);
225 int pipsize
,pippos
,valueheight
,valuewidth
;
245 dc
.Blit((wxCoord
)(x
+ m_scale
*3),
246 (wxCoord
)(y
+ m_scale
*3),
250 valuewidth
* (m_pipValue
- 1),
253 dc
.Blit((wxCoord
)(x
+ m_width
- m_scale
*3 - valuewidth
),
254 (wxCoord
)(y
+ m_height
- valueheight
- m_scale
*3),
258 valuewidth
* (m_pipValue
- 1),
259 valuepos
+valueheight
,
263 dc
.Blit((wxCoord
)(x
+ m_scale
*3 + valuewidth
+2),
264 (wxCoord
)(y
+ m_scale
*3),
271 dc
.Blit((wxCoord
)(x
+ m_width
- m_scale
*3-valuewidth
-pipsize
-2),
272 (wxCoord
)(y
+ m_height
- pipsize
- m_scale
*3),
283 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
284 (wxCoord
)(y
- m_scale
*5 + m_height
/ 2),
294 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
295 (wxCoord
)(y
- symdist
+ m_height
/ 2),
303 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
304 (wxCoord
)(y
- symdist
+ m_height
/ 4),
311 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
312 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
322 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
323 (wxCoord
)(y
- symdist
+ m_height
/ 2),
331 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
332 (wxCoord
)(y
- symdist
+ m_height
/ 4),
339 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
340 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
347 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
348 (wxCoord
)(y
- symdist
+ m_height
/ 4),
355 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
356 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
366 dc
.Blit((wxCoord
)(x
- symdist
+ 5 * m_width
/ 10),
367 (wxCoord
)(y
- symdist
+ 5 * m_height
/ 8),
375 dc
.Blit((wxCoord
)(x
- symdist
+ 5 * m_width
/ 10),
376 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 8),
384 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
385 (wxCoord
)(y
- symdist
+ m_height
/ 4),
388 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
389 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
390 (wxCoord
)(y
- symdist
+ m_height
/ 2),
397 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
398 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
405 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
406 (wxCoord
)(y
- symdist
+ m_height
/ 4),
413 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
414 (wxCoord
)(y
- symdist
+ m_height
/ 2),
421 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
422 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
432 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
433 (wxCoord
)(y
- symdist
+ 2 * m_height
/ 3),
441 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
442 (wxCoord
)(y
- symdist2
+ m_height
/ 4),
449 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
450 (wxCoord
)(y
- symdist2
+ 5 * m_height
/ 12),
457 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
458 (wxCoord
)(y
- symdist
+ 7 * m_height
/ 12),
465 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
466 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
474 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
475 (wxCoord
)(y
- symdist2
+ m_height
/ 4),
482 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
483 (wxCoord
)(y
- symdist2
+ 5 * m_height
/ 12),
490 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
491 (wxCoord
)(y
- symdist
+ 7 * m_height
/ 12),
498 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
499 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
506 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
507 (wxCoord
)(y
- symdist
+ m_height
/ 3),
518 memoryDC
.SelectObject(*m_pictureBmap
);
519 int picwidth
= 40,picheight
= 45;
520 dc
.Blit((wxCoord
)(x
+ (m_width
-picwidth
)/2),
521 (wxCoord
)(y
- picheight
/2 + m_height
/2),
525 picwidth
* (m_pipValue
- 11),
529 memoryDC
.SelectObject(*m_symbolBmap
);
530 dc
.Blit((wxCoord
)(x
+ m_width
-(m_width
-picwidth
)/2-symsize
-3),
531 (wxCoord
)(y
- picheight
/2+m_height
/2+1),
538 dc
.Blit((wxCoord
)(x
+ (m_width
-picwidth
)/2+2),
539 (wxCoord
)(y
+ picheight
/2 + m_height
/2-symsize
),
550 dc
.SetBackground( backgroundBrush
);
554 //+-------------------------------------------------------------+
555 //| Card::DrawNullCard() |
556 //+-------------------------------------------------------------+
558 //| Draws the outline of a card at (x, y). |
559 //| Used to draw place holders for empty piles of cards. |
560 //+-------------------------------------------------------------+
561 void Card::DrawNullCard(wxDC
& dc
, int x
, int y
)
563 wxPen
* pen
= wxThePenList
->FindOrCreatePen(FortyApp::TextColour(), 1, wxSOLID
);
564 dc
.SetBrush(FortyApp::BackgroundBrush());
566 dc
.DrawRoundedRectangle(x
, y
, m_width
, m_height
, 4);
567 } // Card::DrawNullCard()