]>
git.saurik.com Git - wxWidgets.git/blob - demos/forty/card.cpp
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"
39 #include "pictures.xpm"
40 #include "symbols.xpm"
42 wxBitmap
* Card::m_pictureBmap
= 0;
43 wxBitmap
* Card::m_symbolBmap
= 0;
45 double Card::m_scale
= 1.0;
46 int Card::m_width
= 50;
47 int Card::m_height
= 70;
49 //+-------------------------------------------------------------+
51 //+-------------------------------------------------------------+
53 //| Constructor for a playing card. |
54 //| Checks that the value is in the range 1..52 and then |
55 //| initialises the suit, colour, pipValue and wayUp. |
56 //+-------------------------------------------------------------+
57 Card::Card(int value
, WayUp way_up
) :
62 m_symbolBmap
= new wxBitmap(symbols_xpm
);
63 if (!m_symbolBmap
->Ok())
65 ::wxMessageBox(_T("Failed to load bitmap CardSymbols"), _T("Error"));
70 m_pictureBmap
= new wxBitmap(Pictures
);
71 if (!m_pictureBmap
->Ok())
73 ::wxMessageBox(_T("Failed to load bitmap CardPictures"), _T("Error"));
77 if (value
>= 1 && value
<= PackSize
)
79 switch ((value
- 1) / 13)
98 m_pipValue
= 1 + (value
- 1) % 13;
108 //+-------------------------------------------------------------+
109 //| Card::SetScale() |
110 //+-------------------------------------------------------------+
112 //| Scales the cards |
113 //+-------------------------------------------------------------+
114 void Card::SetScale(double scale
)
117 m_width
= int(50*scale
);
118 m_height
= int(70*scale
);
121 //+-------------------------------------------------------------+
123 //+-------------------------------------------------------------+
125 //| Erase the card at (x, y) by drawing a rectangle in the |
126 //| background colour. |
127 //+-------------------------------------------------------------+
128 void Card::Erase(wxDC
& dc
, int x
, int y
)
130 wxPen
* pen
= wxThePenList
->FindOrCreatePen(
131 FortyApp::BackgroundColour(),
136 dc
.SetBrush(FortyApp::BackgroundBrush());
137 dc
.DrawRectangle(x
, y
, m_width
, m_height
);
141 //+-------------------------------------------------------------+
143 //+-------------------------------------------------------------+
145 //| Draw the card at (x, y). |
146 //| If the card is facedown draw the back of the card. |
147 //| If the card is faceup draw the front of the card. |
148 //| Cards are not held in bitmaps, instead they are drawn |
149 //| from their constituent parts when required. |
150 //| hbmap_symbols contains large and small suit symbols and |
151 //| pip values. These are copied to the appropriate part of |
152 //| the card. Picture cards use the pictures defined in |
153 //| hbmap_pictures. Note that only one picture is defined |
154 //| for the Jack, Queen and King, unlike a real pack where |
155 //| each suit is different. |
158 //| The locations of these symbols is 'hard-wired' into the |
159 //| code. Editing the bitmaps or the numbers below will |
160 //| result in the wrong symbols being displayed. |
161 //+-------------------------------------------------------------+
162 void Card::Draw(wxDC
& dc
, int x
, int y
)
164 wxBrush
backgroundBrush( dc
.GetBackground() );
165 dc
.SetBrush(* wxWHITE_BRUSH
);
166 dc
.SetPen(* wxBLACK_PEN
);
167 dc
.DrawRoundedRectangle(x
, y
, m_width
, m_height
, 4);
168 if (m_wayUp
== facedown
)
170 dc
.SetBackground(* wxRED_BRUSH
);
171 dc
.SetBackgroundMode(wxSOLID
);
172 wxBrush
* brush
= wxTheBrushList
->FindOrCreateBrush(
173 _T("BLACK"), wxCROSSDIAG_HATCH
175 dc
.SetBrush(* brush
);
177 dc
.DrawRoundedRectangle(
179 m_width
- 8, m_height
- 8,
187 memoryDC
.SelectObject(*m_symbolBmap
);
189 // dc.SetBackgroundMode(wxTRANSPARENT);
191 dc
.SetTextBackground(*wxWHITE
);
196 dc
.SetTextForeground(*wxBLACK
);
200 dc
.SetTextForeground(*wxRED
);
210 int pipsize
,pippos
,valueheight
,valuewidth
;
230 dc
.Blit((wxCoord
)(x
+ m_scale
*3),
231 (wxCoord
)(y
+ m_scale
*3),
235 valuewidth
* (m_pipValue
- 1),
238 dc
.Blit((wxCoord
)(x
+ m_width
- m_scale
*3 - valuewidth
),
239 (wxCoord
)(y
+ m_height
- valueheight
- m_scale
*3),
243 valuewidth
* (m_pipValue
- 1),
244 valuepos
+valueheight
,
248 dc
.Blit((wxCoord
)(x
+ m_scale
*3 + valuewidth
+2),
249 (wxCoord
)(y
+ m_scale
*3),
256 dc
.Blit((wxCoord
)(x
+ m_width
- m_scale
*3-valuewidth
-pipsize
-2),
257 (wxCoord
)(y
+ m_height
- pipsize
- m_scale
*3),
268 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
269 (wxCoord
)(y
- m_scale
*5 + m_height
/ 2),
279 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
280 (wxCoord
)(y
- symdist
+ m_height
/ 2),
288 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
289 (wxCoord
)(y
- symdist
+ m_height
/ 4),
296 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
297 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
307 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
308 (wxCoord
)(y
- symdist
+ m_height
/ 2),
316 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
317 (wxCoord
)(y
- symdist
+ m_height
/ 4),
324 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
325 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
332 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
333 (wxCoord
)(y
- symdist
+ m_height
/ 4),
340 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
341 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
351 dc
.Blit((wxCoord
)(x
- symdist
+ 5 * m_width
/ 10),
352 (wxCoord
)(y
- symdist
+ 5 * m_height
/ 8),
360 dc
.Blit((wxCoord
)(x
- symdist
+ 5 * m_width
/ 10),
361 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 8),
369 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
370 (wxCoord
)(y
- symdist
+ m_height
/ 4),
373 &memoryDC
, symsize
* m_suit
, sympos
, wxCOPY
);
374 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
375 (wxCoord
)(y
- symdist
+ m_height
/ 2),
382 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
383 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
390 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
391 (wxCoord
)(y
- symdist
+ m_height
/ 4),
398 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
399 (wxCoord
)(y
- symdist
+ m_height
/ 2),
406 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
407 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
417 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
418 (wxCoord
)(y
- symdist
+ 2 * m_height
/ 3),
426 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
427 (wxCoord
)(y
- symdist2
+ m_height
/ 4),
434 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
435 (wxCoord
)(y
- symdist2
+ 5 * m_height
/ 12),
442 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
443 (wxCoord
)(y
- symdist
+ 7 * m_height
/ 12),
450 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 4),
451 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
459 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
460 (wxCoord
)(y
- symdist2
+ m_height
/ 4),
467 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
468 (wxCoord
)(y
- symdist2
+ 5 * m_height
/ 12),
475 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
476 (wxCoord
)(y
- symdist
+ 7 * m_height
/ 12),
483 dc
.Blit((wxCoord
)(x
- symdist
+ 3 * m_width
/ 4),
484 (wxCoord
)(y
- symdist
+ 3 * m_height
/ 4),
491 dc
.Blit((wxCoord
)(x
- symdist
+ m_width
/ 2),
492 (wxCoord
)(y
- symdist
+ m_height
/ 3),
503 memoryDC
.SelectObject(*m_pictureBmap
);
504 int picwidth
= 40,picheight
= 45;
505 dc
.Blit((wxCoord
)(x
+ (m_width
-picwidth
)/2),
506 (wxCoord
)(y
- picheight
/2 + m_height
/2),
510 picwidth
* (m_pipValue
- 11),
514 memoryDC
.SelectObject(*m_symbolBmap
);
515 dc
.Blit((wxCoord
)(x
+ m_width
-(m_width
-picwidth
)/2-symsize
-3),
516 (wxCoord
)(y
- picheight
/2+m_height
/2+1),
523 dc
.Blit((wxCoord
)(x
+ (m_width
-picwidth
)/2+2),
524 (wxCoord
)(y
+ picheight
/2 + m_height
/2-symsize
),
535 dc
.SetBackground( backgroundBrush
);
539 //+-------------------------------------------------------------+
540 //| Card::DrawNullCard() |
541 //+-------------------------------------------------------------+
543 //| Draws the outline of a card at (x, y). |
544 //| Used to draw place holders for empty piles of cards. |
545 //+-------------------------------------------------------------+
546 void Card::DrawNullCard(wxDC
& dc
, int x
, int y
)
548 wxPen
* pen
= wxThePenList
->FindOrCreatePen(FortyApp::TextColour(), 1, wxSOLID
);
549 dc
.SetBrush(FortyApp::BackgroundBrush());
551 dc
.DrawRoundedRectangle(x
, y
, m_width
, m_height
, 4);
552 } // Card::DrawNullCard()