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 //+-------------------------------------------------------------+
22 // For compilers that support precompilation, includes "wx/wx.h".
23 #include "wx/wxprec.h"
40 #include "pictures.xpm"
41 #include "symbols.xbm"
44 wxBitmap
* Card::m_pictureBmap
= 0;
45 wxBitmap
* Card::m_symbolBmap
= 0;
47 double Card::m_scale
= 1.0;
48 int Card::m_width
= 50;
49 int Card::m_height
= 70;
51 //+-------------------------------------------------------------+
53 //+-------------------------------------------------------------+
55 //| Constructor for a playing card. |
56 //| Checks that the value is in the range 1..52 and then |
57 //| initialises the suit, colour, pipValue and wayUp. |
58 //+-------------------------------------------------------------+
59 Card::Card(int value
, WayUp way_up
) :
65 m_symbolBmap
= new wxBitmap(_T("CardSymbols"), wxBITMAP_TYPE_BMP_RESOURCE
);
67 m_symbolBmap
= new wxBitmap(Symbols_bits
, Symbols_width
, Symbols_height
);
69 if (!m_symbolBmap
->Ok())
71 ::wxMessageBox(_T("Failed to load bitmap CardSymbols"), _T("Error"));
77 m_pictureBmap
= new wxBitmap(_T("CardPictures"), wxBITMAP_TYPE_BMP_RESOURCE
);
79 m_pictureBmap
= new wxBitmap(Pictures
);
81 if (!m_pictureBmap
->Ok())
83 ::wxMessageBox(_T("Failed to load bitmap CardPictures"), _T("Error"));
87 if (value
>= 1 && value
<= PackSize
)
89 switch ((value
- 1) / 13)
108 m_pipValue
= 1 + (value
- 1) % 13;
118 //+-------------------------------------------------------------+
119 //| Card::SetScale() |
120 //+-------------------------------------------------------------+
122 //| Scales the cards |
123 //+-------------------------------------------------------------+
124 void Card::SetScale(double scale
)
127 m_width
= int(50*scale
);
128 m_height
= int(70*scale
);
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
, m_width
, m_height
);
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
, m_width
, m_height
, 4);
178 if (m_wayUp
== facedown
)
180 dc
.SetBackground(* wxRED_BRUSH
);
181 dc
.SetBackgroundMode(wxSOLID
);
182 wxBrush
* brush
= wxTheBrushList
->FindOrCreateBrush(
183 _T("BLACK"), wxCROSSDIAG_HATCH
185 dc
.SetBrush(* brush
);
187 dc
.DrawRoundedRectangle(
189 m_width
- 8, m_height
- 8,
197 memoryDC
.SelectObject(*m_symbolBmap
);
199 // dc.SetBackgroundMode(wxTRANSPARENT);
201 dc
.SetTextBackground(*wxWHITE
);
206 dc
.SetTextForeground(*wxBLACK
);
210 dc
.SetTextForeground(*wxRED
);
220 int pipsize
,pippos
,valueheight
,valuewidth
;
240 dc
.Blit((wxCoord
)(x
+ m_scale
*3),
241 (wxCoord
)(y
+ m_scale
*3),
245 valuewidth
* (m_pipValue
- 1),
248 dc
.Blit((wxCoord
)(x
+ m_width
- m_scale
*3 - valuewidth
),
249 (wxCoord
)(y
+ m_height
- valueheight
- m_scale
*3),
253 valuewidth
* (m_pipValue
- 1),
254 valuepos
+valueheight
,
258 dc
.Blit((wxCoord
)(x
+ m_scale
*3 + valuewidth
+2),
259 (wxCoord
)(y
+ m_scale
*3),
266 dc
.Blit((wxCoord
)(x
+ m_width
- m_scale
*3-valuewidth
-pipsize
-2),
267 (wxCoord
)(y
+ m_height
- pipsize
- m_scale
*3),
278 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
279 (wxCoord
)(y
- m_scale
*5 + m_height
/ 2),
289 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
290 (wxCoord
)(y
- symdist
+ m_height
/ 2),
298 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
299 (wxCoord
)(y
- symdist
+ m_height
/ 4),
306 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
307 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
317 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
318 (wxCoord
)(y
- symdist
+ m_height
/ 2),
326 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
327 (wxCoord
)(y
- symdist
+ m_height
/ 4),
334 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
335 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
342 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
343 (wxCoord
)(y
- symdist
+ m_height
/ 4),
350 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
351 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
361 dc
.Blit((wxCoord
)(x
- symdist
+ 5 * m_width
/ 10),
362 (wxCoord
)(y
- symdist
+ 5 * m_height
/ 8),
370 dc
.Blit((wxCoord
)(x
- symdist
+ 5 * m_width
/ 10),
371 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 8),
379 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
380 (wxCoord
)(y
- symdist
+ m_height
/ 4),
383 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
384 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
385 (wxCoord
)(y
- symdist
+ m_height
/ 2),
392 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
393 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
400 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
401 (wxCoord
)(y
- symdist
+ m_height
/ 4),
408 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
409 (wxCoord
)(y
- symdist
+ m_height
/ 2),
416 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
417 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
427 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
428 (wxCoord
)(y
- symdist
+ 2 * m_height
/ 3),
436 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
437 (wxCoord
)(y
- symdist2
+ m_height
/ 4),
444 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
445 (wxCoord
)(y
- symdist2
+ 5 * m_height
/ 12),
452 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
453 (wxCoord
)(y
- symdist
+ 7 * m_height
/ 12),
460 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
461 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
469 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
470 (wxCoord
)(y
- symdist2
+ m_height
/ 4),
477 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
478 (wxCoord
)(y
- symdist2
+ 5 * m_height
/ 12),
485 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
486 (wxCoord
)(y
- symdist
+ 7 * m_height
/ 12),
493 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
494 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
501 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
502 (wxCoord
)(y
- symdist
+ m_height
/ 3),
513 memoryDC
.SelectObject(*m_pictureBmap
);
514 int picwidth
= 40,picheight
= 45;
515 dc
.Blit((wxCoord
)(x
+ (m_width
-picwidth
)/2),
516 (wxCoord
)(y
- picheight
/2 + m_height
/2),
520 picwidth
* (m_pipValue
- 11),
524 memoryDC
.SelectObject(*m_symbolBmap
);
525 dc
.Blit((wxCoord
)(x
+ m_width
-(m_width
-picwidth
)/2-symsize
-3),
526 (wxCoord
)(y
- picheight
/2+m_height
/2+1),
533 dc
.Blit((wxCoord
)(x
+ (m_width
-picwidth
)/2+2),
534 (wxCoord
)(y
+ picheight
/2 + m_height
/2-symsize
),
545 dc
.SetBackground( backgroundBrush
);
549 //+-------------------------------------------------------------+
550 //| Card::DrawNullCard() |
551 //+-------------------------------------------------------------+
553 //| Draws the outline of a card at (x, y). |
554 //| Used to draw place holders for empty piles of cards. |
555 //+-------------------------------------------------------------+
556 void Card::DrawNullCard(wxDC
& dc
, int x
, int y
)
558 wxPen
* pen
= wxThePenList
->FindOrCreatePen(FortyApp::TextColour(), 1, wxSOLID
);
559 dc
.SetBrush(FortyApp::BackgroundBrush());
561 dc
.DrawRoundedRectangle(x
, y
, m_width
, m_height
, 4);
562 } // Card::DrawNullCard()