5 // Created by Hori,Masaki on 2014/09/05.
6 // Copyright (c) 2014年 Hori,Masaki. All rights reserved.
9 #import "HMMaskSelectView.h"
11 #import "HMMaskInfomation.h"
14 const NSInteger kNumberOfMask = 4;
15 static NSRect maskRects[kNumberOfMask];
17 static NSSize originalSize;
19 @implementation HMMaskSelectView
23 static dispatch_once_t onceToken;
24 dispatch_once(&onceToken, ^{
25 maskRects[0] = NSMakeRect(113, 455, 100, 18);
26 maskRects[1] = NSMakeRect(203, 330, 200, 25);
27 maskRects[2] = NSMakeRect(95, 378, 100, 18);
28 maskRects[3] = NSMakeRect(60, 378, 100, 18);
30 originalSize = NSMakeSize(800, 480);
34 - (id)initWithFrame:(NSRect)frame
36 self = [super initWithFrame:frame];
43 - (id)initWithCoder:(NSCoder *)aDecoder
45 self = [super initWithCoder:aDecoder];
54 self.masks = [NSMutableArray new];
55 NSRect frame = self.frame;
56 CGFloat widthRatio = frame.size.width / originalSize.width;
57 CGFloat heightRatio = frame.size.height / originalSize.height;
59 for(NSInteger i = 0; i < kNumberOfMask; i++ ) {
60 HMMaskInfomation *info = [HMMaskInfomation new];
61 NSRect maskRect = NSMakeRect(
62 maskRects[i].origin.x * widthRatio,
63 maskRects[i].origin.y * heightRatio,
64 maskRects[i].size.width * widthRatio,
65 maskRects[i].size.height * heightRatio
67 info.maskRect = maskRect;
68 [self.masks addObject:info];
70 info.borderColor = [NSColor colorWithCalibratedRed:0.000 green:0.011 blue:1.000 alpha:1.000];
72 info.borderColor = [NSColor redColor];
74 info.maskColor = [NSColor blackColor];
78 - (void)drawRect:(NSRect)dirtyRect
80 NSGraphicsContext *context = [NSGraphicsContext currentContext];
81 [context saveGraphicsState];
82 [context setShouldAntialias:NO];
84 CGFloat dashSeed[] = {3.0, 3.0};
85 for(HMMaskInfomation *info in self.masks) {
86 NSBezierPath *path = [NSBezierPath bezierPathWithRect:info.maskRect];
91 [path setLineDash:dashSeed count:2 phase:0];
92 [info.borderColor set];
94 [path setLineDash:dashSeed count:2 phase:3.0];
95 [[NSColor lightGrayColor] set];
99 [context restoreGraphicsState];
102 NSBezierPath *path = [NSBezierPath bezierPath];
103 for(int i = 0; i < 800; i += 50) {
104 [path moveToPoint:NSMakePoint(i, 0)];
105 [path lineToPoint:NSMakePoint(i, 480)];
107 for(int j = 0; j < 480; j += 50) {
108 [path moveToPoint:NSMakePoint(0, j)];
109 [path lineToPoint:NSMakePoint(800, j)];
111 [[NSColor whiteColor] set];
116 - (void)mouseUp:(NSEvent *)event
118 NSPoint mouse = [event locationInWindow];
119 mouse = [self convertPoint:mouse fromView:nil];
121 for(HMMaskInfomation *info in [self.masks reverseObjectEnumerator]) {
122 if(NSMouseInRect(mouse, info.maskRect, self.isFlipped)) {
123 info.enable = !info.enable;
124 [self setNeedsDisplayInRect:NSInsetRect(info.maskRect, -5, -5)];
130 - (IBAction)disableAllMasks:(id)sender
132 for(HMMaskInfomation *info in self.masks) {
135 [self setNeedsDisplay:YES];