-
Notifications
You must be signed in to change notification settings - Fork 6
/
MKColorSwatchMatrix.m
65 lines (52 loc) · 1.66 KB
/
MKColorSwatchMatrix.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
//
// MKColorPickerView.m
// Color Picker
//
// Created by Mark Dodwell on 5/26/12.
// Copyright (c) 2012 mkdynamic. All rights reserved.
//
#import "MKColorSwatchMatrix.h"
#import "MKColorSwatchCell.h"
#import "MKColorWell.h"
@implementation MKColorSwatchMatrix
- (id)initWithFrame:(NSRect)frameRect
numberOfRows:(NSInteger)rowsHigh
numberOfColumns:(NSInteger)colsWide
colors:(NSArray *)theColors
targetColorWell:(MKColorWell *)aTargetColorWell
{
colCount = (int)colsWide;
colors = theColors;
self = [super initWithFrame:frameRect
mode:NSTrackModeMatrix
cellClass:[MKColorSwatchCell class]
numberOfRows:rowsHigh
numberOfColumns:colsWide];
if (self) {
targetColorWell = aTargetColorWell;
[self setBackgroundColor:[NSColor darkGrayColor]];
[self setDrawsBackground:YES];
}
return self;
}
- (NSCell *)makeCellAtRow:(NSInteger)row column:(NSInteger)column
{
MKColorSwatchCell *cell = (MKColorSwatchCell *)[super makeCellAtRow:row column:column];
int index = (int)(column + (row * colCount));
if (index < [colors count]) {
cell.color = [colors objectAtIndex:index];
}
return cell;
}
- (void)mouseDown:(NSEvent *)theEvent
{
NSPoint pt = [self convertPoint:[theEvent locationInWindow] fromView:nil];
NSInteger row;
NSInteger column;
BOOL hit = [self getRow:&row column:&column forPoint:pt];
if (hit) {
MKColorSwatchCell *cell = [self cellAtRow:row column:column];
[targetColorWell setColorAndClose:[cell color]];
}
}
@end