forked from jigish/slate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGridCellView.m
68 lines (60 loc) · 2.84 KB
/
GridCellView.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
//
// GridCellView.m
// Slate
//
// Created by Jigish Patel on 9/10/12.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses
#import "GridCellView.h"
#import "SlateConfig.h"
#import "Constants.h"
@implementation GridCellView
@synthesize bg, inactiveBg, activeBg, cornerSize;
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setWantsLayer:YES];
NSArray *bgColorArr = [[SlateConfig getInstance] getArrayConfig:GRID_CELL_BACKGROUND_COLOR];
if ([bgColorArr count] < 4) bgColorArr = [GRID_CELL_BACKGROUND_COLOR_DEFAULT componentsSeparatedByString:SEMICOLON];
NSColor *backgroundColor = [NSColor colorWithDeviceRed:[[bgColorArr objectAtIndex:0] floatValue]/255.0
green:[[bgColorArr objectAtIndex:1] floatValue]/255.0
blue:[[bgColorArr objectAtIndex:2] floatValue]/255.0
alpha:[[bgColorArr objectAtIndex:3] floatValue]];
[self setBg:backgroundColor];
[self setInactiveBg:backgroundColor];
NSArray *activeColorArr = [[SlateConfig getInstance] getArrayConfig:GRID_CELL_SELECTED_COLOR];
if ([activeColorArr count] < 4) activeColorArr = [GRID_CELL_SELECTED_COLOR_DEFAULT componentsSeparatedByString:SEMICOLON];
NSColor *activeColor = [NSColor colorWithDeviceRed:[[activeColorArr objectAtIndex:0] floatValue]/255.0
green:[[activeColorArr objectAtIndex:1] floatValue]/255.0
blue:[[activeColorArr objectAtIndex:2] floatValue]/255.0
alpha:[[activeColorArr objectAtIndex:3] floatValue]];
[self setActiveBg:activeColor];
[self setCornerSize:[[SlateConfig getInstance] getFloatConfig:GRID_CELL_ROUNDED_CORNER_SIZE]];
}
return self;
}
- (void)activate {
[self setBg:[self activeBg]];
[self setNeedsDisplay:YES];
}
- (void)deactivate {
[self setBg:[self inactiveBg]];
[self setNeedsDisplay:YES];
}
- (void)drawRect:(NSRect)dirtyRect {
[[self bg] set];
NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:[self bounds] xRadius:[self cornerSize] yRadius:[self cornerSize]];
[path fill];
}
@end