OSDN Git Service

履歴にマークを付けられるようにした
[kcd/KCD.git] / KCD / HMHistoryMarkTransformer.m
1 //
2 //  HMHistoryMarkTransformer.m
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2016/06/26.
6 //  Copyright © 2016年 Hori,Masaki. All rights reserved.
7 //
8
9 #import "HMHistoryMarkTransformer.h"
10
11 @implementation HMHistoryMarkTransformer
12 + (void)load
13 {
14         static dispatch_once_t onceToken;
15         dispatch_once(&onceToken, ^{
16                 [NSValueTransformer setValueTransformer:[self new] forName:@"HMHistoryMarkTransformer"];
17         });
18 }
19 + (Class)transformedValueClass
20 {
21         return [NSImage class];
22 }
23 + (BOOL)allowsReverseTransformation
24 {
25         return NO;
26 }
27
28 - (NSImage *)markImage
29 {
30         const CGFloat radius = 10;
31         NSImage *mark = [[NSImage alloc] initWithSize:NSMakeSize(radius, radius)];
32         [mark lockFocus];
33         {
34                 [[NSColor redColor] set];
35                 NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:NSMakeRect(0, 0, radius, radius)
36                                                                                                                          xRadius:radius / 2
37                                                                                                                          yRadius:radius / 2];
38                 [path fill];
39         }
40         [mark unlockFocus];
41         
42         return mark;
43 }
44
45 - (id)transformedValue:(id)value
46 {
47         BOOL mark = [value boolValue];
48         
49         return mark ? self.markImage : nil;
50         
51 }
52 @end