-
Notifications
You must be signed in to change notification settings - Fork 0
/
RowColumnHighlightLayer.m
73 lines (62 loc) · 2.3 KB
/
RowColumnHighlightLayer.m
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
//
// RowColumnHighlightLayer.m
// JazzBall
//
// Created by Julez on 1/29/12.
// Copyright 2012 __MyCompanyName__. All rights reserved.
//
#import "RowColumnHighlightLayer.h"
#import "JBOptionsViewController.h"
static CGFloat redTraditionalColorComponents[] = {1.0, .3, .3, .7};
static CGFloat blueTraditionalColorComponents[] = {0., 0., 1.0, .7};
static CGFloat redAstralColorComponents[] = {1.0, .3, .3, 1.0};
static CGFloat blueAstralColorComponents[] = {.4, .4, 1.0, 1.0};
@implementation RowColumnHighlightLayer
@synthesize midpoint;
@synthesize direction;
-(id) init {
if ([super init]) {
NSString* tilename = [[NSUserDefaults standardUserDefaults] stringForKey:UDGameTileNameKey];
if ([tilename isEqualToString:@"astral"]) {
redColor = redAstralColorComponents;
blueColor = blueAstralColorComponents;
}
else {
redColor = redTraditionalColorComponents;
blueColor = blueTraditionalColorComponents;
}
}
return self;
}
- (void) drawInContext:(CGContextRef)ctx {
static CGColorSpaceRef cspace = nil;
if (cspace == nil) {
cspace = CGColorSpaceCreateDeviceRGB();
}
CGRect bounds = self.bounds;
CGContextSetLineWidth(ctx, 2.0);
CGContextSetStrokeColorSpace(ctx, cspace);
if (direction == HighlightDirectionRow) {
CGContextSetStrokeColor(ctx, redColor);
CGContextMoveToPoint(ctx, 0, CGRectGetMidY(bounds));
CGContextAddLineToPoint(ctx, midpoint, CGRectGetMidY(bounds));
CGContextStrokePath(ctx);
CGContextBeginPath(ctx);
CGContextSetStrokeColor(ctx, blueColor);
CGContextMoveToPoint(ctx, midpoint, CGRectGetMidY(bounds));
CGContextAddLineToPoint(ctx, bounds.size.width, CGRectGetMidY(bounds));
CGContextStrokePath(ctx);
}
else {
CGContextSetStrokeColor(ctx, redColor);
CGContextMoveToPoint(ctx, CGRectGetMidX(bounds), 0);
CGContextAddLineToPoint(ctx, CGRectGetMidX(bounds), midpoint);
CGContextStrokePath(ctx);
CGContextBeginPath(ctx);
CGContextSetStrokeColor(ctx, blueColor);
CGContextMoveToPoint(ctx, CGRectGetMidX(bounds), midpoint);
CGContextAddLineToPoint(ctx, CGRectGetMidX(bounds), bounds.size.height);
CGContextStrokePath(ctx);
}
}
@end