-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardView.mm
76 lines (62 loc) · 1.71 KB
/
CardView.mm
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
/*
* CardView.mm
*
*
*/
#include "Platform.h"
#import "CardView.h"
#import "Deck.h"
#import "CardTableViewController.h"
//#import "GameModel.h"
//#import "VideoPokerAppDelegate.h"
@implementation CardView
@synthesize cardTable;
- (void) drawRect:(CGRect) rect
{
// CGImageRef cardImage = [[VideoPokerAppDelegate app].game.deck getCardImage:[self getCard]];
CGImageRef cardImage = NULL;
Card_t card = [self getCard];
bool held = false;
if (card.getValue() == Card_t::Value::Undefined)
{
cardImage = [self.cardTable getBackImage:[self getIndex]];
}
else
{
cardImage = [self.cardTable getCardImage:card];
held = [self.cardTable isHeldCard:card];
}
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0.0, rect.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextDrawImage(context, rect, cardImage);
if (held)
{
CGImageRef heldImage = [CardView getHeldImage];
// NSInteger border = 10;
NSInteger x = (rect.size.width - CGImageGetWidth(heldImage)) / 2;
CGRect heldRect = CGRectMake(x,
10,
x + CGImageGetWidth(heldImage),
10 + CGImageGetHeight(heldImage));
CGContextDrawImage(context, heldRect, heldImage);
}
}
- (Card_t) getCard
{
return [self.cardTable getCard:[self getIndex]];
}
- (NSInteger) getIndex
{
return self.tag;
}
+ (CGImageRef) getHeldImage
{
static CGImageRef heldImage = NULL;
if (NULL == heldImage)
{
heldImage = [Deck loadImage:@"held.png"];
}
return heldImage;
}
@end