-
Notifications
You must be signed in to change notification settings - Fork 1
/
Drawhand.cpp
1341 lines (1229 loc) · 35 KB
/
Drawhand.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//----------------------------------------------------------------------------------------
//
// This file and all other Easy Bridge source files are copyright (C) 2002 by Steven Han.
// Use of this file is governed by the GNU General Public License.
// See the files COPYING and COPYRIGHT for details.
//
//----------------------------------------------------------------------------------------
////////////////////////////////////////////////////////////////
//
// Drawhand.cpp : implementation of CEasyBView's hand drawing
//
// Routines:
// ---------
// DisplayHand() show hand
// DrawHoriz() draw hand in horiz row
// PartialDrawHoriz()
// DrawHorizGrouped() draw in horizontal goups
// PartialDrawHorizGrouped()
// DrawHorizDummy() draw horizontal dummy
// PartialDrawHorizDummy()
// DrawVert() draw in vertical row
// PartialDrawVert()
// DrawVertDummy() draw vertical dummy
// PartialDrawVertDummy()
//
// GetPlayerBottomCard(CPlayer& player);
// CheckForTrickCardsOverlap(CDC* pDC, RECT& eraseRect);
// DrawCardBack(CDC* pDC, int x, int y);
//
///////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "EasyB.h"
#include "EasyBdoc.h"
#include "EasyBvw.h"
#include "player.h"
#include "card.h"
#include "deck.h"
#include "DrawParameters.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
#define DEBUG_MODE 1
//
// local functions
//
CCard* GetPlayerBottomCard(CPlayer& player);
void DrawCardBack(CDC* pDC, int x, int y);
//
//===========================================================
//
// DisplayHand
//
// parameters:
// nPos: player positions
// nDisplaySuit: specific suit to display; display
// all suits if left blank
// bClearBackground: clear background before drawing
// bCardPlayed: a card has just been removed
// signals partial redraw
//
//===========================================================
//
void CEasyBView::DisplayHand(Position nPos, int nDisplaySuit,
BOOL bClearBackground, BOOL bCardPlayed)
{
int nStartSuit,nEndSuit;
CDC *pDC = GetDC();
CEasyBDoc* pDoc = CEasyBDoc::GetDoc();
if (!pDOC || !pDOC->IsInitialized())
return;
CPlayer* pPlayer = pDOC->GetPlayer(nPos);
if (pPlayer == NULL)
return;
BOOL bDummy = pPlayer->IsDummy();
CDC cacheDC,*pOldDC;
CBitmap tempBitmap,*pOldBitmap;
RECT clipRect;
int nWidth, nHeight;
// see if we're using triple buffering
if (m_bTripleBuffer)
{
cacheDC.CreateCompatibleDC(pDC);
RECT rect;
GetClientRect(&rect);
tempBitmap.CreateCompatibleBitmap(pDC, rect.right, rect.bottom);
pOldBitmap = (CBitmap*) cacheDC.SelectObject(&tempBitmap);
pDC->GetClipBox(&clipRect);
nWidth = clipRect.right - clipRect.left;
nHeight = clipRect.bottom - clipRect.top;
cacheDC.BitBlt(clipRect.left,clipRect.top,nWidth,nHeight,pDC,clipRect.left,clipRect.top,SRCCOPY);
// pull a switcheroo here
pOldDC = pDC;
pDC = &cacheDC;
}
//
// if (!pDOC->m_bHandsDealt)
// return;
//
if (nDisplaySuit >= 0)
{
// reset the suit to index in suit display table
if (nPos == pDOC->GetDummyPosition())
nStartSuit = m_nDummySuitToScreenIndex[nDisplaySuit];
else
nStartSuit = m_nSuitToScreenIndex[nDisplaySuit];
nEndSuit = nStartSuit;
}
else
{
nStartSuit = 0;
nEndSuit = 3;
}
//
// select subroutine according to position and draw mode
//
// 1/28 -- horrible hack -- the last card in a face-down hand doesn't
// clear properly, so force a complete redraw afterwards
int numCardsLeft = PLAYER(nPos).GetNumCards();
//
if (nPos == SOUTH)
{
//
// player's hand (south); always display face up
//
// if ((bDummy) && (pDOC->IsDummyExposed()) && (theApp.IsGameInProgress()))
if ((bDummy) && (pDOC->IsDummyExposed()) && (m_nCurrMode != MODE_CARDLAYOUT))
{
//
// Dummy player
//
if (!bCardPlayed)
{
// dummy player, face up, full draw
DrawHorizDummy(pDC,nPos,nDisplaySuit,bClearBackground,nStartSuit,nEndSuit);
}
else
{
// dummy player, face up, partial draw
PartialDrawHorizDummy(pDC,nPos);
}
}
else
{
//
// Non-dummy player, face up
//
if (!bCardPlayed)
{
// non-dummy player, face up, full draw
DrawHorizGrouped(pDC,nPos,nDisplaySuit,bClearBackground,nStartSuit,nEndSuit);
}
else
{
// non-dummy player, face up, partial draw
PartialDrawHorizGrouped(pDC,nPos);
}
}
}
else if ((nPos == EAST) || (nPos == WEST))
{
//
// Opponents hands
//
// if ((bDummy) && (pDOC->IsDummyExposed()) && (theApp.IsGameInProgress()))
if ((bDummy) && (pDOC->IsDummyExposed()) && (m_nCurrMode != MODE_CARDLAYOUT))
{
//
// Dummy east-west here
//
if (!bCardPlayed)
{
// dummy player, face up, full draw
DrawVertDummy(pDC,nPos,nDisplaySuit,bClearBackground,nStartSuit,nEndSuit);
}
else
{
// dummy opponent, face up, partial draw
PartialDrawVertDummy(pDC,nPos);
}
}
else
{
//
// non-dummy east-west opponents here
//
if ((!bCardPlayed) || (numCardsLeft == 0))
{
// non-dummy player, face up/down, full draw
DrawVert(pDC,nPos,nDisplaySuit,bClearBackground,nStartSuit,nEndSuit);
}
else
{
// non-dummy opponent, face up/down, partial draw
PartialDrawVert(pDC,nPos);
}
}
}
else
{
//
//--------------------------------------------------
// north (partner)
//
// if ((bDummy) && (pDOC->IsDummyExposed()) && (theApp.IsGameInProgress()))
if ((bDummy) && (pDOC->IsDummyExposed()) && (m_nCurrMode != MODE_CARDLAYOUT))
{
//
// North, Dummy format
//
if (!bCardPlayed)
{
// dummy north, face up, full draw
DrawHorizDummy(pDC,nPos,nDisplaySuit,bClearBackground,nStartSuit,nEndSuit);
}
else
{
// dummy north, face up, partial draw
PartialDrawHorizDummy(pDC,nPos);
}
}
else
{
//
// North, non-dummy format
//
if ( (m_nCurrMode == MODE_CARDLAYOUT) || (m_nCurrMode == MODE_EDITHANDS) ||
(pDOC->GetDeclarerPosition() == NORTH) ||
(theApp.AreCardsFaceUp()) )
{
// show grouped cards
if (!bCardPlayed)
{
DrawHorizGrouped(pDC,nPos,bClearBackground,nDisplaySuit,nStartSuit,nEndSuit);
}
else
{
PartialDrawHorizGrouped(pDC,nPos);
}
}
else if ((!bCardPlayed) || (numCardsLeft == 0))
{
// non-dummy north, face up or down, full draw
DrawHoriz(pDC,nPos,bClearBackground,nDisplaySuit,nStartSuit,nEndSuit);
}
else
{
// non-dummy north, face up or down, partial draw
PartialDrawHoriz(pDC,nPos);
}
}
}
// finish up
if (m_bTripleBuffer)
{
// restore pointer
pDC = pOldDC;
// copy results of offscreen blitting to the screen
RECT rect;
GetHandBoundsRect(nPos,rect);
pDC->BitBlt(clipRect.left,clipRect.top,nWidth,nHeight,&cacheDC,clipRect.left,clipRect.top,SRCCOPY);
// done with triple buffering
(void)cacheDC.SelectObject(pOldBitmap);
cacheDC.DeleteDC();
tempBitmap.DeleteObject();
}
// all done
ReleaseDC(pDC);
}
//
void CEasyBView::GetHandBoundsRect(Position nPos, RECT& rect)
{
int i;
rect.left = m_rectSuitOffset[nPos][0].left;
rect.top = m_rectSuitOffset[nPos][0].top;
rect.right = m_rectSuitOffset[nPos][0].right;
rect.bottom = m_rectSuitOffset[nPos][0].bottom;
for(i=1;i<4;i++)
{
if (m_rectSuitOffset[nPos][i].left < rect.left)
rect.left = m_rectSuitOffset[nPos][i].left;
if (m_rectSuitOffset[nPos][i].top < rect.top)
rect.top = m_rectSuitOffset[nPos][i].top;
if (m_rectSuitOffset[nPos][i].right > rect.right)
rect.right = m_rectSuitOffset[nPos][i].right;
if (m_rectSuitOffset[nPos][i].bottom > rect.bottom)
rect.bottom = m_rectSuitOffset[nPos][i].bottom;
}
}
//
//-------------------------------------------------------------
//
// Draw cards horizontally in an unbroken row
//
void CEasyBView::DrawHoriz(CDC* pDC, Position nPos, int nDisplaySuit,
BOOL bClearBackground, int nStartSuit, int nEndSuit)
{
//
// non-dummy north/south, face up or down, full draw
//
int i,j,nSuit;
int x = m_drawPoint[nPos].x;
int y = m_drawPoint[nPos].y;
// first clear background if requested
// also clear if the last card has been played
// if ((bClearBackground) && (OffsetRectValid(nPos)))
if ( (bClearBackground || (PLAYER(nPos).GetNumCards() == 0)) &&
(OffsetRectValid(nPos)) )
{
ClearDisplayArea(m_rectSuitOffset[nPos][0].left,
m_rectSuitOffset[nPos][0].top,
m_rectSuitOffset[nPos][3].right,
m_rectSuitOffset[nPos][3].bottom,
pDC);
}
// then check to see if we have to do anything more
if (PLAYER(nPos).GetNumCards() == 0)
return;
// display in traditional format
for(i=nStartSuit;i<=nEndSuit;i++)
{
nSuit = theApp.GetSuitSequence(i);
m_rectSuitOffset[nPos][i].left = x;
m_rectSuitOffset[nPos][i].top = y;
//
for(j=0;j<PLAYER(nPos).GetNumCardsInSuit(nSuit);j++)
{
CCard* pCard = PLAYER(nPos).GetCardInSuit(nSuit,j);
ASSERT(pCard != NULL);
pCard->MoveTo(pDC, x, y);
x += m_nCardXGap;
}
m_rectSuitOffset[nPos][i].right = x + m_nCardWidth - m_nCardXGap;
m_rectSuitOffset[nPos][i].bottom = y + m_nCardHeight;
}
}
//
//-------------------------------------------------------------
//
// Partial draw cards horizontally in an unbroken row
//
void CEasyBView::PartialDrawHoriz(CDC* pDC, Position nPos)
{
//
// non-dummy north/south, redrawing after a card was pulled
//
int cx,cy;
int x = m_drawPoint[nPos].x;
int y = m_drawPoint[nPos].y;
if (!theApp.AreCardsFaceUp())
{
//
// non-dummy north, face down,
// partial draw
//
// clear area under bottom card
int numCards = PLAYER(nPos).GetNumCards();
CCard* pPlayedCard = pDOC->GetCurrentTrickCard(nPos);
cy = y + m_nCardHeight;
if (numCards > 0)
{
x += m_nCardWidth + m_nCardXGap*(numCards-1);
cx = x + m_nCardXGap;
ClearDisplayArea(x, y, cx, cy, pDC);
x -= m_nCardWidth;
DrawCardBack(pDC, x, y);
}
else
{
cx = m_nCardWidth;
ClearDisplayArea(x, y, cx, cy, pDC);
}
// and thazzit
return;
}
else
{
//
// non-dummy north, face up, partial draw
//
// since cards are face up, redraw starting
// from card after the one last played
CCard* pOldCard = pDOC->GetCurrentTrickCard(nPos);
// restore the played card's background
pOldCard->RestoreBackground(pDC);
// and then restore remaining cards
int nStart = pOldCard->GetDisplayPosition();
int nEnd = PLAYER(nPos).GetNumCards();
// if this was the last card on the
// stack, then we're done
if ((nStart == nEnd) || (nEnd == 0))
return;
// else clear the area to the right of the
// played card -- grab the card right
// after the card played
CCard* pCard1 = PLAYER(nPos).GetDisplayedCard(nStart);
CCard* pCard2 = PLAYER(nPos).GetDisplayedCard(nEnd-1);
RECT eraseRect;
eraseRect.left = pCard1->GetXPosition() + m_nCardWidth - m_nCardXGap;
eraseRect.top = pCard1->GetYPosition();
eraseRect.right = pCard2->GetXPosition() + m_nCardWidth;
eraseRect.bottom = pCard1->GetYPosition() + m_nCardHeight;
ClearDisplayArea(&eraseRect,pDC);
// and draw remaining cards starting from
// the lcoation of the old card
x = pOldCard->GetXPosition();
y = pOldCard->GetYPosition();
int i;
for(i=nStart;i<nEnd;i++)
{
CCard* pCard = PLAYER(nPos).GetDisplayedCard(i);
ASSERT(pCard != NULL);
pCard->MoveTo(pDC, x, y);
x += m_nCardXGap;
}
}
}
//
//-------------------------------------------------------------
//
// Draw cards horizontally, grouped by suit
//
void CEasyBView::DrawHorizGrouped(CDC* pDC, Position nPos, int nDisplaySuit,
BOOL bClearBackground, int nStartSuit, int nEndSuit)
{
//
// grouped north/south, draw face up, full draw
//
int i,j,nSuit;
int x = m_drawPoint[nPos].x;
int y = m_drawPoint[nPos].y;
// make an x-coord adjustment if this is north
if (nPos == NORTH)
{
// make an exception; draw north using South's x-coord
x = m_drawPoint[SOUTH].x;
}
// first clear background if requested
if ((bClearBackground) && (OffsetRectValid(nPos)))
{
RECT rect;
GetHandBoundsRect(nPos,rect);
ClearDisplayArea(&rect,pDC);
ResetSuitOffsets(nPos); // ??? necessary ???
}
// then check to see if we have to do anything more
if (PLAYER(nPos).GetNumCards() == 0)
return;
// else draw
for(i=nStartSuit;i<=nEndSuit;i++)
{
nSuit = theApp.GetSuitSequence(i);
// init the suit locations or read from it
if (m_rectSuitOffset[nPos][i].left == -1)
{
m_rectSuitOffset[nPos][i].left = x;
m_rectSuitOffset[nPos][i].top = y;
}
else
{
x = m_rectSuitOffset[nPos][i].left;
y = m_rectSuitOffset[nPos][i].top;
}
//
if (PLAYER(nPos).GetNumCardsInSuit(nSuit) > 0)
{
for(j=0;j<PLAYER(nPos).GetNumCardsInSuit(nSuit);j++)
{
CCard* pCard = PLAYER(nPos).GetCardInSuit(nSuit,j);
ASSERT(pCard != NULL);
pCard->MoveTo(pDC, x, y);
x += m_nCardXGap;
}
m_rectSuitOffset[nPos][i].right = x + m_nCardWidth - m_nCardXGap;
x += m_nCardWidth - m_nCardXGap;
}
else
{
m_rectSuitOffset[nPos][i].right = 0;
}
x += m_nSuitSpacer;
m_rectSuitOffset[nPos][i].bottom = y + m_nCardHeight;
}
}
//
//-------------------------------------------------------------
//
// Partially draw cards horizontally, grouped by suit
//
void CEasyBView::PartialDrawHorizGrouped(CDC* pDC, Position nPos)
{
//
// non-dummy north/south, face up, partial draw
//
// since cards are face up, redraw starting
// from card after the one last played
CCard* pOldCard = pDOC->GetCurrentTrickCard(nPos);
// restore the played card's background
pOldCard->RestoreBackground(pDC);
// and then restore remaining cards
int nSuit = pOldCard->GetSuit();
int nStart = pOldCard->GetSuitPosition();
int nEnd = PLAYER(nPos).GetNumCardsInSuit(nSuit);
// if this was the last card in the suit, then clear and we're done
if (nEnd == 0)
{
int nSuitIndex = GetSuitToScreenIndex(nSuit);
ClearDisplayArea(&m_rectSuitOffset[nPos][nSuitIndex], pDC);
return;
}
// else if this was the bottom card on the stack, then we're done
if (nStart >= nEnd)
return;
// clear the suit area to the right of the played card --
// grab the card right after the card played
CCard* pCard1 = PLAYER(nPos).GetCardInSuit(nSuit,nStart);
CCard* pCard2 = PLAYER(nPos).GetCardInSuit(nSuit,nEnd-1);
RECT eraseRect;
eraseRect.left = pCard1->GetXPosition() + m_nCardWidth - m_nCardXGap;
eraseRect.top = pCard1->GetYPosition();
eraseRect.right = pCard2->GetXPosition() + m_nCardWidth;
eraseRect.bottom = pCard1->GetYPosition() + m_nCardHeight;
ClearDisplayArea(&eraseRect, pDC);
// and draw remaining cards starting from
// the location of the old card
int i,x,y;
x = pOldCard->GetXPosition();
y = pOldCard->GetYPosition();
for(i=nStart;i<nEnd;i++)
{
CCard* pCard = PLAYER(nPos).GetCardInSuit(nSuit,i);
ASSERT(pCard != NULL);
pCard->MoveTo(pDC, x, y);
x += m_nCardXGap;
}
}
//
//-------------------------------------------------------------
//
// Draw cards horizontally, in dummy column format
//
void CEasyBView::DrawHorizDummy(CDC* pDC, Position nPos, int nDisplaySuit,
BOOL bClearBackground, int nStartSuit, int nEndSuit)
{
//
// dummy north/south, face up, full draw
//
int i,j,nSuit;
int x = m_drawPoint[nPos].x + m_dummyDrawOffset[nPos].x;
int y = m_drawPoint[nPos].y + m_dummyDrawOffset[nPos].y;
// first clear background if requested
if ((bClearBackground) && (OffsetRectValid(nPos)))
{
RECT rect;
// see if we're only doing one suit
if (nDisplaySuit >= 0)
{
ClearDisplayArea(&m_rectSuitOffset[nPos][nStartSuit],pDC);
}
else
{
// else clear entire hand area
GetHandBoundsRect(nPos,rect);
ClearDisplayArea(&rect,pDC);
}
}
// then check to see if we have to do anything more
if (PLAYER(nPos).GetNumCards() == 0)
return;
// insert offset if drawing a single suit
if (nDisplaySuit >= 0)
{
x = m_rectSuitOffset[nPos][nStartSuit].left;
}
//
for(i=nStartSuit;i<=nEndSuit;i++)
{
// use the DUMMY suit sequence
nSuit = theApp.GetDummySuitSequence(i);
m_rectSuitOffset[nPos][i].left = x;
m_rectSuitOffset[nPos][i].top = y;
int numInSuit = PLAYER(nPos).GetNumCardsInSuit(nSuit);
//
if (nPos == NORTH)
{
for(j=0;j<numInSuit;j++)
{
CCard* pCard = PLAYER(nPos).GetCardInSuit(nSuit,j);
ASSERT(pCard != NULL);
pCard->MoveTo(pDC, x, y);
y += m_nCardYGap;
}
}
else
{
// south as dummy
// draw low card on top
y = m_rectSuitOffset[nPos][i].top -
((numInSuit-1) * m_nCardYGap);
m_rectSuitOffset[nPos][i].top = y;
for(j=numInSuit-1;j>=0;j--)
{
CCard* pCard = PLAYER(nPos).GetCardInSuit(nSuit,j);
ASSERT(pCard != NULL);
pCard->MoveTo(pDC, x, y);
y += m_nCardYGap;
}
}
m_rectSuitOffset[nPos][i].right = x + m_nCardWidth;
m_rectSuitOffset[nPos][i].bottom = y + m_nCardHeight - m_nCardYGap;
x += m_nCardWidth + m_nDummySuitSpacer;
y = m_drawPoint[nPos].y;
}
}
//
//-------------------------------------------------------------
//
// Partial draw cards horizontally, in dummy column format
//
void CEasyBView::PartialDrawHorizDummy(CDC* pDC, Position nPos)
{
//
// dummy north/south, face up, partial draw
//
int i,j,x,y,cx,cy,nSuit,nStart,nEnd;
//
RECT eraseRect;
// first grab played card
CCard* pPlayedCard = pDOC->GetCurrentTrickCard(nPos);
nSuit = pPlayedCard->GetSuit();
// first get the played card's posititon
x = pPlayedCard->GetXPosition();
y = pPlayedCard->GetYPosition();
// handling then depends on whether this is north or south
if (nPos == NORTH)
{
//
nStart = pPlayedCard->GetSuitPosition();
nEnd = PLAYER(nPos).GetNumCardsInSuit(nSuit);
// then establish redraw area
if (nEnd == 0)
{
// last card in suit; the erase rect is simply
// the card iteself
eraseRect.left = x;
eraseRect.top = y;
eraseRect.right = x + m_nCardWidth;
eraseRect.bottom = y + m_nCardHeight;
}
else if (nStart == nEnd)
{
// area to be erased is just bottom portion of
// the played card
eraseRect.left = pPlayedCard->GetXPosition();
eraseRect.top = pPlayedCard->GetYPosition() + m_nCardHeight - m_nCardYGap;
eraseRect.right = pPlayedCard->GetXPosition() + m_nCardWidth;
eraseRect.bottom = pPlayedCard->GetYPosition() + m_nCardHeight;
}
else
{
// else need to clear area under the bottom card
CCard* pCard2 = PLAYER(nPos).GetCardInSuit(nSuit,nEnd-1);
eraseRect.left = pPlayedCard->GetXPosition();
eraseRect.top = pPlayedCard->GetYPosition() + m_nCardHeight - m_nCardYGap;
eraseRect.right = pPlayedCard->GetXPosition() + m_nCardWidth;
eraseRect.bottom = pCard2->GetYPosition() + m_nCardHeight;
}
// see if the area to be erased intersects with a
// card on the table, and if so, erase the card
CheckForTrickCardsOverlap(pDC, eraseRect, pPlayedCard, FALSE);
// now finish erasing and redrawing cards
pPlayedCard->RestoreBackground(pDC);
if (nStart == nEnd)
{
// last card on stack, so nothing more to do
}
else
{
// first clear the affected card stack area
ClearDisplayArea(&eraseRect,pDC);
// then redraw remaining suit stack
for(i=nStart;i<nEnd;i++)
{
CCard* pCard = PLAYER(nPos).GetCardInSuit(nSuit,i);
ASSERT(pCard != NULL);
pCard->MoveTo(pDC, x, y);
y += m_nCardYGap;
}
}
}
else
{
//
nStart = pPlayedCard->GetSuitPosition();
nEnd = 0;
// draw the high card on the bottom
// since we're drawing high card on bottom, we have
// to always redraw the entire stack
// first convert screen suit position to ordinal pos
int nDisplayCol = m_nDummySuitToScreenIndex[pPlayedCard->GetSuit()];
x = m_rectSuitOffset[nPos][nDisplayCol].left;
y = m_rectSuitOffset[nPos][nDisplayCol].top;
cx = m_rectSuitOffset[nPos][nDisplayCol].right;
cy = m_rectSuitOffset[nPos][nDisplayCol].bottom;
// see if the area to be erased intersects with a
// card on the table, and if so, erase the card
eraseRect = m_rectSuitOffset[nPos][nDisplayCol];
CheckForTrickCardsOverlap(pDC, eraseRect, pPlayedCard, FALSE);
// then erase the suit area
ClearDisplayArea(x, y, cx, cy, pDC);
//
y += m_nCardYGap;
m_rectSuitOffset[nPos][nDisplayCol].top = y;
//
for(j=PLAYER(nPos).GetNumCardsInSuit(nSuit)-1;j>=0;j--)
{
CCard* pCard = PLAYER(nPos).GetCardInSuit(nSuit,j);
ASSERT(pCard != NULL);
pCard->MoveTo(pDC, x, y);
y += m_nCardYGap;
}
}
// now redraw any table cards that may have been erased
CheckForTrickCardsOverlap(pDC, eraseRect, pPlayedCard, TRUE);
}
//
//-------------------------------------------------------------
//
// Draw cards vertically in overlapped line format
//
void CEasyBView::DrawVert(CDC* pDC, Position nPos, int nDisplaySuit,
BOOL bClearBackground, int nStartSuit, int nEndSuit)
{
//
// non-dummy east-west, face up or down, full draw
//
int i,j,xx,cx,nSuit;
int x = m_drawPoint[nPos].x;
int y = m_drawPoint[nPos].y;
// first clear background if requested
if ((bClearBackground) && (OffsetRectValid(nPos)))
{
RECT rect;
GetHandBoundsRect(nPos,rect);
ClearDisplayArea(&rect,pDC);
}
// then check to see if we have to do anything more
if (PLAYER(nPos).GetNumCards() == 0)
return;
// else draw
int nSuitsShown = 0;
BOOL bFaceUp = theApp.AreCardsFaceUp() || PLAYER(nPos).AreCardsExposed();
for(i=nStartSuit=0;i<=nEndSuit;i++)
{
if (bFaceUp && m_bOffsetVertSuits)
{
// cards are face up -- offset display of alternate suits
if ((nSuitsShown == 1) || (nSuitsShown == 3))
{
if (nPos == WEST)
xx = x + m_nHorizSuitOffset;
else // East
xx = x - m_nHorizSuitOffset;
}
else
{
xx = x;
}
cx = x + m_nCardWidth + m_nHorizSuitOffset;
}
else
{
// cards are face down -- draw flush left or right
xx = x;
cx = x + m_nCardWidth;
}
nSuit = theApp.GetSuitSequence(i);
m_rectSuitOffset[nPos][i].left = xx;
m_rectSuitOffset[nPos][i].right = cx;
m_rectSuitOffset[nPos][i].top = y;
//
for(j=0;j<PLAYER(nPos).GetNumCardsInSuit(nSuit);j++)
{
CCard* pCard = PLAYER(nPos).GetCardInSuit(nSuit,j);
ASSERT(pCard != NULL);
pCard->MoveTo(pDC, xx, y);
y += m_nCardYGap;
}
if (j > 0)
nSuitsShown++;
m_rectSuitOffset[nPos][i].bottom = y + m_nCardHeight - m_nCardYGap;
}
}
//
//-------------------------------------------------------------
//
// Partial draw cards vertically in overlapped line format
//
void CEasyBView::PartialDrawVert(CDC* pDC, Position nPos)
{
int cx,cy;
int x = m_drawPoint[nPos].x;
int y = m_drawPoint[nPos].y;
//
if (!theApp.AreCardsFaceUp())
{
//
// non-dummy east-west, face DOWN, partial draw
//
// adjust clear area
BOOL bFaceUp = theApp.AreCardsFaceUp() || PLAYER(nPos).AreCardsExposed();
if (bFaceUp && !m_bOffsetVertSuits)
{
if (nPos == WEST)
x += m_nHorizSuitOffset;
else
x -= m_nHorizSuitOffset;
}
// and clear area under bottom card
int numCards = PLAYER(nPos).GetNumCards();
cx = x + m_nCardWidth;
if (numCards > 0)
{
y += m_nCardHeight + m_nCardYGap*(numCards-1);
cy = y + m_nCardYGap;
ClearDisplayArea(x,y,cx,cy,pDC);
y -= m_nCardHeight;
DrawCardBack(pDC,x,y);
}
else
{
cy = m_nCardHeight;
ClearDisplayArea(x,y,cx,cy,pDC);
}
// and thazzit
return;
}
else
{
//
// cards are forced to be face up
// non-dummy east-west, face up, partial draw
//
// redraw starting from card after the one last played
CCard* pOldCard = pDOC->GetCurrentTrickCard(nPos);
// restore the played card's background
pOldCard->RestoreBackground(pDC);
// and then restore remaining cards
int nStart = pOldCard->GetDisplayPosition();
int nEnd = PLAYER(nPos).GetNumCards();
// if we're drawing with vert suit offsets, and we run out of a suit,
// we have to redraw the whole hand
if ((PLAYER(nPos).GetNumCardsInSuit(pOldCard->GetSuit()) == 0) &&
(m_bOffsetVertSuits))
{
DrawVert(pDC, nPos, 0, TRUE, 0, 3);
return;
}
// if this was the bottom card on the
// stack, then we're done
if ((nStart == nEnd) || (nEnd == 0))
return;
// else clear the area under the bottom card
// grab the card right after the card played
CCard* pCard1 = PLAYER(nPos).GetDisplayedCard(nStart);
CCard* pCard2 = PLAYER(nPos).GetDisplayedCard(nEnd-1);
RECT eraseRect;
eraseRect.left = pCard1->GetXPosition();
eraseRect.top = pCard1->GetYPosition() + m_nCardHeight - m_nCardYGap;
eraseRect.right = pCard1->GetXPosition() + m_nCardWidth;
eraseRect.bottom = pCard2->GetYPosition() + m_nCardHeight;
// expand rect if drawing with vert suit offsets
if ( (theApp.AreCardsFaceUp() || PLAYER(nPos).AreCardsExposed()) && m_bOffsetVertSuits)
{
eraseRect.left = m_drawPoint[nPos].x - m_nHorizSuitOffset;
eraseRect.right = m_drawPoint[nPos].x + m_nCardWidth + m_nHorizSuitOffset;
}
ClearDisplayArea(&eraseRect,pDC);
// and draw remaining cards starting from
// the location of the old card
x = pOldCard->GetXPosition();
y = pOldCard->GetYPosition();
int i;
for(i=nStart;i<nEnd;i++)
{
CCard* pCard = PLAYER(nPos).GetDisplayedCard(i);
ASSERT(pCard != NULL);
x = pCard->GetXPosition();
pCard->MoveTo(pDC, x, y);
y += m_nCardYGap;
}
}
}
//
//-------------------------------------------------------------
//
// Draw cards vertically in dummy format
//
void CEasyBView::DrawVertDummy(CDC* pDC, Position nPos, int nDisplaySuit,
BOOL bClearBackground, int nStartSuit, int nEndSuit)
{
//
// dummy east-west, face up, full draw
//
int i,j,nSuit;
int xx = m_drawPoint[nPos].x + m_dummyDrawOffset[nPos].x;
int yy = m_drawPoint[nPos].y + m_dummyDrawOffset[nPos].y;
int x = xx;
int y = yy;
// first clear background if requested
if ((bClearBackground) && (OffsetRectValid(nPos)))
{
RECT rect;
GetHandBoundsRect(nPos,rect);
ClearDisplayArea(&rect,pDC);
}
//
for(i=nStartSuit;i<=nEndSuit;i++)
{
// use the DUMMY suit sequence
nSuit = theApp.GetDummySuitSequence(i);
m_rectSuitOffset[nPos][i].left = x;
m_rectSuitOffset[nPos][i].top = y;
int numInSuit = PLAYER(nPos).GetNumCardsInSuit(nSuit);
//
if (nPos == WEST)