]>
git.saurik.com Git - wxWidgets.git/blob - demos/forty/card.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Forty Thieves patience game
4 // Author: Chris Breeze
7 // Copyright: (c) 1993-1998 Chris Breeze
8 // Licence: wxWindows licence
9 //---------------------------------------------------------------------------
10 // Last modified: 22nd July 1998 - ported to wxWidgets 2.0
11 /////////////////////////////////////////////////////////////////////////////
12 //+-------------------------------------------------------------+
14 //| A class for drawing playing cards.
15 //| Currently assumes that the card symbols have been
16 //| loaded into hbmap_symbols and the pictures for the
17 //| Jack, Queen and King have been loaded into
19 //+-------------------------------------------------------------+
21 // For compilers that support precompilation, includes "wx/wx.h".
22 #include "wx/wxprec.h"
38 #include "pictures.xpm"
39 #include "symbols.xpm"
41 wxBitmap
* Card::m_pictureBmap
= 0;
42 wxBitmap
* Card::m_symbolBmap
= 0;
44 double Card::m_scale
= 1.0;
45 int Card::m_width
= 50;
46 int Card::m_height
= 70;
48 //+-------------------------------------------------------------+
50 //+-------------------------------------------------------------+
52 //| Constructor for a playing card. |
53 //| Checks that the value is in the range 1..52 and then |
54 //| initialises the suit, colour, pipValue and wayUp. |
55 //+-------------------------------------------------------------+
56 Card::Card(int value
, WayUp way_up
) :
61 m_symbolBmap
= new wxBitmap(symbols_xpm
);
62 if (!m_symbolBmap
->IsOk())
64 ::wxMessageBox(wxT("Failed to load bitmap CardSymbols"), wxT("Error"));
69 m_pictureBmap
= new wxBitmap(Pictures
);
70 if (!m_pictureBmap
->IsOk())
72 ::wxMessageBox(wxT("Failed to load bitmap CardPictures"), wxT("Error"));
76 if (value
>= 1 && value
<= PackSize
)
78 switch ((value
- 1) / 13)
97 m_pipValue
= 1 + (value
- 1) % 13;
107 //+-------------------------------------------------------------+
108 //| Card::SetScale() |
109 //+-------------------------------------------------------------+
111 //| Scales the cards |
112 //+-------------------------------------------------------------+
113 void Card::SetScale(double scale
)
116 m_width
= int(50*scale
);
117 m_height
= int(70*scale
);
120 //+-------------------------------------------------------------+
122 //+-------------------------------------------------------------+
124 //| Erase the card at (x, y) by drawing a rectangle in the |
125 //| background colour. |
126 //+-------------------------------------------------------------+
127 void Card::Erase(wxDC
& dc
, int x
, int y
)
129 wxPen
* pen
= wxThePenList
->FindOrCreatePen(
130 FortyApp::BackgroundColour(),
135 dc
.SetBrush(FortyApp::BackgroundBrush());
136 dc
.DrawRectangle(x
, y
, m_width
, m_height
);
140 //+-------------------------------------------------------------+
142 //+-------------------------------------------------------------+
144 //| Draw the card at (x, y). |
145 //| If the card is facedown draw the back of the card. |
146 //| If the card is faceup draw the front of the card. |
147 //| Cards are not held in bitmaps, instead they are drawn |
148 //| from their constituent parts when required. |
149 //| hbmap_symbols contains large and small suit symbols and |
150 //| pip values. These are copied to the appropriate part of |
151 //| the card. Picture cards use the pictures defined in |
152 //| hbmap_pictures. Note that only one picture is defined |
153 //| for the Jack, Queen and King, unlike a real pack where |
154 //| each suit is different. |
157 //| The locations of these symbols is 'hard-wired' into the |
158 //| code. Editing the bitmaps or the numbers below will |
159 //| result in the wrong symbols being displayed. |
160 //+-------------------------------------------------------------+
161 void Card::Draw(wxDC
& dc
, int x
, int y
)
163 wxBrush
backgroundBrush( dc
.GetBackground() );
164 dc
.SetBrush(* wxWHITE_BRUSH
);
165 dc
.SetPen(* wxBLACK_PEN
);
166 dc
.DrawRoundedRectangle(x
, y
, m_width
, m_height
, 4);
167 if (m_wayUp
== facedown
)
169 dc
.SetBackground(* wxRED_BRUSH
);
170 dc
.SetBackgroundMode(wxSOLID
);
171 wxBrush
* brush
= wxTheBrushList
->FindOrCreateBrush(
172 *wxBLACK
, wxCROSSDIAG_HATCH
174 dc
.SetBrush(* brush
);
176 dc
.DrawRoundedRectangle(
178 m_width
- 8, m_height
- 8,
186 memoryDC
.SelectObject(*m_symbolBmap
);
188 // dc.SetBackgroundMode(wxTRANSPARENT);
190 dc
.SetTextBackground(*wxWHITE
);
195 dc
.SetTextForeground(*wxBLACK
);
199 dc
.SetTextForeground(*wxRED
);
209 int pipsize
,pippos
,valueheight
,valuewidth
;
229 dc
.Blit((wxCoord
)(x
+ m_scale
*3),
230 (wxCoord
)(y
+ m_scale
*3),
234 valuewidth
* (m_pipValue
- 1),
237 dc
.Blit((wxCoord
)(x
+ m_width
- m_scale
*3 - valuewidth
),
238 (wxCoord
)(y
+ m_height
- valueheight
- m_scale
*3),
242 valuewidth
* (m_pipValue
- 1),
243 valuepos
+valueheight
,
247 dc
.Blit((wxCoord
)(x
+ m_scale
*3 + valuewidth
+2),
248 (wxCoord
)(y
+ m_scale
*3),
255 dc
.Blit((wxCoord
)(x
+ m_width
- m_scale
*3-valuewidth
-pipsize
-2),
256 (wxCoord
)(y
+ m_height
- pipsize
- m_scale
*3),
267 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
268 (wxCoord
)(y
- m_scale
*5 + m_height
/ 2),
278 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
279 (wxCoord
)(y
- symdist
+ m_height
/ 2),
287 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
288 (wxCoord
)(y
- symdist
+ m_height
/ 4),
295 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
296 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
306 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
307 (wxCoord
)(y
- symdist
+ m_height
/ 2),
315 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
316 (wxCoord
)(y
- symdist
+ m_height
/ 4),
323 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
324 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
331 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
332 (wxCoord
)(y
- symdist
+ m_height
/ 4),
339 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
340 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
350 dc
.Blit((wxCoord
)(x
- symdist
+ 5 * m_width
/ 10),
351 (wxCoord
)(y
- symdist
+ 5 * m_height
/ 8),
359 dc
.Blit((wxCoord
)(x
- symdist
+ 5 * m_width
/ 10),
360 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 8),
368 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
369 (wxCoord
)(y
- symdist
+ m_height
/ 4),
372 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
373 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
374 (wxCoord
)(y
- symdist
+ m_height
/ 2),
381 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
382 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
389 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
390 (wxCoord
)(y
- symdist
+ m_height
/ 4),
397 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
398 (wxCoord
)(y
- symdist
+ m_height
/ 2),
405 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
406 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
416 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
417 (wxCoord
)(y
- symdist
+ 2 * m_height
/ 3),
425 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
426 (wxCoord
)(y
- symdist2
+ m_height
/ 4),
433 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
434 (wxCoord
)(y
- symdist2
+ 5 * m_height
/ 12),
441 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
442 (wxCoord
)(y
- symdist
+ 7 * m_height
/ 12),
449 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
450 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
458 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
459 (wxCoord
)(y
- symdist2
+ m_height
/ 4),
466 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
467 (wxCoord
)(y
- symdist2
+ 5 * m_height
/ 12),
474 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
475 (wxCoord
)(y
- symdist
+ 7 * m_height
/ 12),
482 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
483 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
490 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
491 (wxCoord
)(y
- symdist
+ m_height
/ 3),
502 memoryDC
.SelectObject(*m_pictureBmap
);
503 int picwidth
= 40,picheight
= 45;
504 dc
.Blit((wxCoord
)(x
+ (m_width
-picwidth
)/2),
505 (wxCoord
)(y
- picheight
/2 + m_height
/2),
509 picwidth
* (m_pipValue
- 11),
513 memoryDC
.SelectObject(*m_symbolBmap
);
514 dc
.Blit((wxCoord
)(x
+ m_width
-(m_width
-picwidth
)/2-symsize
-3),
515 (wxCoord
)(y
- picheight
/2+m_height
/2+1),
522 dc
.Blit((wxCoord
)(x
+ (m_width
-picwidth
)/2+2),
523 (wxCoord
)(y
+ picheight
/2 + m_height
/2-symsize
),
534 dc
.SetBackground( backgroundBrush
);
538 //+-------------------------------------------------------------+
539 //| Card::DrawNullCard() |
540 //+-------------------------------------------------------------+
542 //| Draws the outline of a card at (x, y). |
543 //| Used to draw place holders for empty piles of cards. |
544 //+-------------------------------------------------------------+
545 void Card::DrawNullCard(wxDC
& dc
, int x
, int y
)
547 wxPen
* pen
= wxThePenList
->FindOrCreatePen(FortyApp::TextColour(), 1, wxSOLID
);
548 dc
.SetBrush(FortyApp::BackgroundBrush());
550 dc
.DrawRoundedRectangle(x
, y
, m_width
, m_height
, 4);
551 } // Card::DrawNullCard()