-
Notifications
You must be signed in to change notification settings - Fork 6
/
MKColorPickerView.m
51 lines (43 loc) · 1.55 KB
/
MKColorPickerView.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
//
// MKColorPickerView.m
// Color Picker
//
// Created by Mark Dodwell on 5/27/12.
// Copyright (c) 2012 mkdynamic. All rights reserved.
//
#import "MKColorPickerView.h"
#import "MKColorSwatchMatrix.h"
#import "MKColorSwatchCell.h"
#import "MKColorWell.h"
@implementation MKColorPickerView
@synthesize matrix;
- (void)drawRect:(NSRect)dirtyRect
{
[[NSColor darkGrayColor] setFill];
NSRectFill(dirtyRect);
[super drawRect:dirtyRect];
}
- (id)initWithColors:(NSArray *)colors
numberOfRows:(NSInteger)rows
numberOfColumns:(NSInteger)columns
swatchSize:(NSSize)size
targetColorWell:(MKColorWell *)aTargetColorWell
{
NSSize spacing = NSMakeSize(1, 1);
NSRect matrixFrame = NSMakeRect(spacing.width, spacing.height,
columns * size.width + ((columns - 1) * spacing.width),
rows * size.height + ((rows - 1)) * spacing.height);
self = [self initWithFrame:NSInsetRect(matrixFrame, -spacing.width, -spacing.height)];
if (self) {
matrix = [[MKColorSwatchMatrix alloc] initWithFrame:matrixFrame
numberOfRows:rows
numberOfColumns:columns
colors:colors
targetColorWell:aTargetColorWell];
[matrix setIntercellSpacing:spacing];
[matrix setCellSize:size];
[self addSubview:matrix];
}
return self;
}
@end