2 // HMGuardEscapedView.m
5 // Created by Hori,Masaki on 2015/08/10.
6 // Copyright (c) 2015年 Hori,Masaki. All rights reserved.
9 #import "HMGuardEscapedView.h"
12 static NSString *taiString = nil;
13 static NSString *hiString = nil;
15 @implementation HMGuardEscapedView
19 static dispatch_once_t onceToken;
20 dispatch_once(&onceToken, ^{
21 NSBundle *mainBundle = [NSBundle mainBundle];
22 NSString *path = [mainBundle pathForResource:@"Taihi" ofType:@"txt"];
24 NSString *taihiString = [[NSString alloc] initWithContentsOfFile:path
25 encoding:NSUTF8StringEncoding
29 NSLog(@"Could not find Taihi.txt. Error -> %@", error);
33 NSLog(@"Could not find Taihi.txt");
38 if(taihiString.length != 2) {
39 NSLog(@"Taihi.txt length is not two.");
43 taiString = [taihiString substringToIndex:1];
44 hiString = [taihiString substringFromIndex:1];
47 - (void)drawRect:(NSRect)dirtyRect {
48 [super drawRect:dirtyRect];
50 NSRect bounds = self.bounds;
52 NSBezierPath *fillPath = [NSBezierPath bezierPathWithRect:bounds];
53 [[NSColor colorWithCalibratedWhite:0.9 alpha:0.8] set];
56 switch(self.controlSize) {
57 case NSRegularControlSize:
58 [self drawTaihiInrect:bounds];
60 case NSSmallControlSize:
61 case NSMiniControlSize:
62 [self drawSmallTaihiInrect:bounds];
67 - (void)drawTaihiInrect:(NSRect)bounds
70 NSAffineTransform *rotate = [NSAffineTransform transform];
71 [rotate translateXBy:0.0 yBy:65.0];
72 [rotate rotateByDegrees:-27];
75 const CGFloat width = 50;
76 const CGFloat height = 100;
77 NSRect rect = NSMakeRect(
78 (NSInteger)((bounds.size.width - width) * 0.5),
79 (NSInteger)((bounds.size.height - height) * 0.5),
82 NSBezierPath *path = [NSBezierPath bezierPathWithRect:rect];
84 [[NSColor whiteColor] set];
87 [[NSColor blackColor] set];
90 rect = NSInsetRect(rect, 3, 3);
91 path = [NSBezierPath bezierPathWithRect:rect];
95 NSDictionary *taiAttr = @{
96 NSForegroundColorAttributeName : [NSColor lightGrayColor],
97 NSFontAttributeName : [NSFont boldSystemFontOfSize:width - 10],
99 NSAttributedString *tai = [[NSAttributedString alloc] initWithString:taiString attributes:taiAttr];
101 NSAttributedString *hi = [[NSAttributedString alloc] initWithString:hiString attributes:taiAttr];
103 rect = NSInsetRect(rect, 2, 2);
105 rect.size.height -= 2;
106 [tai drawInRect:rect];
107 rect.size.height *= 0.5;
108 [hi drawInRect:rect];
111 - (void)drawSmallTaihiInrect:(NSRect)bounds
113 const CGFloat width = 100;
114 const CGFloat height = 50;
115 NSRect rect = NSMakeRect(
116 (NSInteger)((bounds.size.width - width) * 0.5),
117 (NSInteger)((bounds.size.height - height) * 0.5),
120 NSBezierPath *path = [NSBezierPath bezierPathWithRect:rect];
122 [[NSColor whiteColor] set];
125 [[NSColor blackColor] set];
128 rect = NSInsetRect(rect, 3, 3);
129 path = [NSBezierPath bezierPathWithRect:rect];
133 NSDictionary *taiAttr = @{
134 NSForegroundColorAttributeName : [NSColor lightGrayColor],
135 NSFontAttributeName : [NSFont boldSystemFontOfSize:height - 14],
137 NSAttributedString *tai = [[NSAttributedString alloc] initWithString:taiString attributes:taiAttr];
139 NSAttributedString *hi = [[NSAttributedString alloc] initWithString:hiString attributes:taiAttr];
141 rect = NSInsetRect(rect, 2, 2);
144 rect.size.height -= 2;
145 [tai drawInRect:rect];
146 rect.origin.x += rect.size.width * 0.5;
147 [hi drawInRect:rect];