Native Mac OS X OtaClock replica
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Render.m 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. //
  2. // Render.m
  3. // OtaClock
  4. //
  5. // Created by Thomas Buck on 17.08.15.
  6. // Copyright (c) 2015 xythobuz. All rights reserved.
  7. //
  8. #import "MainView.h"
  9. #import "Render.h"
  10. #define FULL_IMAGE_WIDTH 86
  11. #define FULL_IMAGE_HEIGHT 80
  12. #define BUBBLE_Y_OFFSET 45
  13. #define OTACON_X_OFFSET 1
  14. #define EYE_X_OFFSET 60
  15. #define EYE_Y_OFFSET 45
  16. #define FONT_DAYS_WIDTH 17
  17. #define FONT_DAYS_HEIGHT 3
  18. #define FONT_DAYS_PADDING 1
  19. #define FONT_DAYS_X_OFFSET 31
  20. #define FONT_DAYS_Y_OFFSET 72
  21. #define FONT_LARGE_WIDTH 6
  22. #define FONT_LARGE_HEIGHT 7
  23. #define FONT_LARGE_PADDING 1
  24. #define FONT_LARGE_Y_OFFSET 63
  25. #define FONT_LARGE_X0_OFFSET 5
  26. #define FONT_LARGE_X1_OFFSET 12
  27. #define FONT_LARGE_X2_OFFSET 21
  28. #define FONT_LARGE_X3_OFFSET 28
  29. #define FONT_LARGE_X4_OFFSET 37
  30. #define FONT_LARGE_X5_OFFSET 44
  31. #define FONT_SMALL_WIDTH 4
  32. #define FONT_SMALL_HEIGHT 5
  33. #define FONT_SMALL_PADDING 1
  34. #define FONT_SMALL_DATE_Y_OFFSET 71
  35. #define FONT_SMALL_DATE_X0_OFFSET 3
  36. #define FONT_SMALL_DATE_X1_OFFSET 8
  37. #define FONT_SMALL_DATE_X2_OFFSET 17
  38. #define FONT_SMALL_DATE_X3_OFFSET 22
  39. #define FONT_SMALL_ALARM_Y_OFFSET 57
  40. #define FONT_SMALL_ALARM_X0_OFFSET 29
  41. #define FONT_SMALL_ALARM_X1_OFFSET 34
  42. #define FONT_SMALL_ALARM_X2_OFFSET 41
  43. #define FONT_SMALL_ALARM_X3_OFFSET 46
  44. #define ALARM_X_OFFSET 5
  45. #define ALARM_Y_OFFSET 57
  46. @interface Render ()
  47. @property (assign) CGImageRef otaconGraphic, bubbleGraphic, alarmGraphic;
  48. @property (assign) CGImageRef eye0, eye1, eye2, eye3, eye4;
  49. @property (assign) CGImageRef fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
  50. @property (assign) CGImageRef fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
  51. @property (assign) CGImageRef fontLarge1, fontLarge2, fontLarge3, fontLarge4, fontLarge5, fontLarge6, fontLarge7, fontLarge8, fontLarge9, fontLarge0;
  52. @property (assign) NSInteger eyeToDraw, dayOfWeek;
  53. @property (assign) NSInteger dateDigit0, dateDigit1, dateDigit2, dateDigit3;
  54. @property (assign) NSInteger alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
  55. @property (assign) NSInteger timeDigit0, timeDigit1, timeDigit2, timeDigit3, timeDigit4, timeDigit5;
  56. @property (assign) BOOL alarmSign;
  57. @property (assign) NSSize fullSize;
  58. @property (assign) CGContextRef drawContext;
  59. @property (weak) MainView *parent;
  60. @end
  61. @implementation Render
  62. @synthesize otaconGraphic, bubbleGraphic, alarmGraphic;
  63. @synthesize eye0, eye1, eye2, eye3, eye4;
  64. @synthesize fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
  65. @synthesize fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
  66. @synthesize fontLarge1, fontLarge2, fontLarge3, fontLarge4, fontLarge5, fontLarge6, fontLarge7, fontLarge8, fontLarge9, fontLarge0;
  67. @synthesize eyeToDraw, dayOfWeek;
  68. @synthesize dateDigit0, dateDigit1, dateDigit2, dateDigit3;
  69. @synthesize alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
  70. @synthesize timeDigit0, timeDigit1, timeDigit2, timeDigit3, timeDigit4, timeDigit5;
  71. @synthesize alarmSign;
  72. @synthesize fullSize;
  73. @synthesize drawContext;
  74. @synthesize parent;
  75. - (CGImageRef)eyeHelper:(NSInteger)index {
  76. if (index == 0) return eye0;
  77. if (index == 1) return eye1;
  78. if (index == 2) return eye2;
  79. if (index == 3) return eye3;
  80. if (index == 4) return eye4;
  81. NSLog(@"Render:eyeHelper:%ld unknown index!", (long)index);
  82. return eye0;
  83. }
  84. - (CGImageRef)dayHelper:(NSInteger)index {
  85. if (index == -1) return fontSunday;
  86. if (index == 0) return fontMonday;
  87. if (index == 1) return fontTuesday;
  88. if (index == 2) return fontWednesday;
  89. if (index == 3) return fontThursday;
  90. if (index == 4) return fontFriday;
  91. if (index == 5) return fontSaturday;
  92. if (index == 6) return fontSunday;
  93. NSLog(@"Render:dayHelper:%ld unknown index!", (long)index);
  94. return fontMonday;
  95. }
  96. - (CGImageRef)smallHelper:(NSInteger)index {
  97. if (index == 0) return fontSmall0;
  98. if (index == 1) return fontSmall1;
  99. if (index == 2) return fontSmall2;
  100. if (index == 3) return fontSmall3;
  101. if (index == 4) return fontSmall4;
  102. if (index == 5) return fontSmall5;
  103. if (index == 6) return fontSmall6;
  104. if (index == 7) return fontSmall7;
  105. if (index == 8) return fontSmall8;
  106. if (index == 9) return fontSmall9;
  107. NSLog(@"Render:smallHelper:%ld unknown index!", (long)index);
  108. return fontSmall0;
  109. }
  110. - (CGImageRef)largeHelper:(NSInteger)index {
  111. if (index == 0) return fontLarge0;
  112. if (index == 1) return fontLarge1;
  113. if (index == 2) return fontLarge2;
  114. if (index == 3) return fontLarge3;
  115. if (index == 4) return fontLarge4;
  116. if (index == 5) return fontLarge5;
  117. if (index == 6) return fontLarge6;
  118. if (index == 7) return fontLarge7;
  119. if (index == 8) return fontLarge8;
  120. if (index == 9) return fontLarge9;
  121. NSLog(@"Render:largeHelper:%ld unknown index!", (long)index);
  122. return fontLarge0;
  123. }
  124. - (id)initWithParent:(MainView *)par {
  125. self = [super init];
  126. if (self == nil) return nil;
  127. parent = par;
  128. NSImage *otaconImage = [NSImage imageNamed:@"otacon"];
  129. NSImage *bubbleImage = [NSImage imageNamed:@"bubble"];
  130. NSImage *eye0Image = [NSImage imageNamed:@"eyes_0"];
  131. NSImage *eye1Image = [NSImage imageNamed:@"eyes_1"];
  132. NSImage *eye2Image = [NSImage imageNamed:@"eyes_2"];
  133. NSImage *eye3Image = [NSImage imageNamed:@"eyes_3"];
  134. NSImage *eye4Image = [NSImage imageNamed:@"eyes_4"];
  135. NSImage *fontDaysImage = [NSImage imageNamed:@"font_days"];
  136. NSImage *fontSmallImage = [NSImage imageNamed:@"font_small"];
  137. NSImage *fontLargeImage = [NSImage imageNamed:@"font_large"];
  138. NSImage *alarmImage = [NSImage imageNamed:@"alarm"];
  139. NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithAttributes:nil];
  140. otaconGraphic = [otaconImage CGImageForProposedRect:nil context:context hints:nil];
  141. bubbleGraphic = [bubbleImage CGImageForProposedRect:nil context:context hints:nil];
  142. alarmGraphic = [alarmImage CGImageForProposedRect:nil context:context hints:nil];
  143. eye0 = [eye0Image CGImageForProposedRect:nil context:context hints:nil];
  144. eye1 = [eye1Image CGImageForProposedRect:nil context:context hints:nil];
  145. eye2 = [eye2Image CGImageForProposedRect:nil context:context hints:nil];
  146. eye3 = [eye3Image CGImageForProposedRect:nil context:context hints:nil];
  147. eye4 = [eye4Image CGImageForProposedRect:nil context:context hints:nil];
  148. CGImageRef fontDays = [fontDaysImage CGImageForProposedRect:nil context:context hints:nil];
  149. NSRect rectDay;
  150. rectDay.size.width = FONT_DAYS_WIDTH;
  151. rectDay.size.height = FONT_DAYS_HEIGHT;
  152. rectDay.origin.x = 0;
  153. rectDay.origin.y = 0;
  154. fontMonday = CGImageCreateWithImageInRect(fontDays, rectDay);
  155. rectDay.origin.y += FONT_DAYS_HEIGHT + FONT_DAYS_PADDING;
  156. fontTuesday = CGImageCreateWithImageInRect(fontDays, rectDay);
  157. rectDay.origin.y += FONT_DAYS_HEIGHT + FONT_DAYS_PADDING;
  158. fontWednesday = CGImageCreateWithImageInRect(fontDays, rectDay);
  159. rectDay.origin.y += FONT_DAYS_HEIGHT + FONT_DAYS_PADDING;
  160. fontThursday = CGImageCreateWithImageInRect(fontDays, rectDay);
  161. rectDay.origin.y += FONT_DAYS_HEIGHT + FONT_DAYS_PADDING;
  162. fontFriday = CGImageCreateWithImageInRect(fontDays, rectDay);
  163. rectDay.origin.y += FONT_DAYS_HEIGHT + FONT_DAYS_PADDING;
  164. fontSaturday = CGImageCreateWithImageInRect(fontDays, rectDay);
  165. rectDay.origin.y += FONT_DAYS_HEIGHT + FONT_DAYS_PADDING;
  166. fontSunday = CGImageCreateWithImageInRect(fontDays, rectDay);
  167. NSRect rect;
  168. CGImageRef fontSmall = [fontSmallImage CGImageForProposedRect:nil context:context hints:nil];
  169. rect.size.width = FONT_SMALL_WIDTH;
  170. rect.size.height = FONT_SMALL_HEIGHT;
  171. rect.origin.x = 0;
  172. rect.origin.y = 0;
  173. fontSmall0 = CGImageCreateWithImageInRect(fontSmall, rect);
  174. rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
  175. fontSmall1 = CGImageCreateWithImageInRect(fontSmall, rect);
  176. rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
  177. fontSmall2 = CGImageCreateWithImageInRect(fontSmall, rect);
  178. rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
  179. fontSmall3 = CGImageCreateWithImageInRect(fontSmall, rect);
  180. rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
  181. fontSmall4 = CGImageCreateWithImageInRect(fontSmall, rect);
  182. rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
  183. fontSmall5 = CGImageCreateWithImageInRect(fontSmall, rect);
  184. rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
  185. fontSmall6 = CGImageCreateWithImageInRect(fontSmall, rect);
  186. rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
  187. fontSmall7 = CGImageCreateWithImageInRect(fontSmall, rect);
  188. rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
  189. fontSmall8 = CGImageCreateWithImageInRect(fontSmall, rect);
  190. rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
  191. fontSmall9 = CGImageCreateWithImageInRect(fontSmall, rect);
  192. CGImageRef fontLarge = [fontLargeImage CGImageForProposedRect:nil context:context hints:nil];
  193. rect.size.width = FONT_LARGE_WIDTH;
  194. rect.size.height = FONT_LARGE_HEIGHT;
  195. rect.origin.x = 0;
  196. rect.origin.y = 0;
  197. fontLarge0 = CGImageCreateWithImageInRect(fontLarge, rect);
  198. rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
  199. fontLarge1 = CGImageCreateWithImageInRect(fontLarge, rect);
  200. rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
  201. fontLarge2 = CGImageCreateWithImageInRect(fontLarge, rect);
  202. rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
  203. fontLarge3 = CGImageCreateWithImageInRect(fontLarge, rect);
  204. rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
  205. fontLarge4 = CGImageCreateWithImageInRect(fontLarge, rect);
  206. rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
  207. fontLarge5 = CGImageCreateWithImageInRect(fontLarge, rect);
  208. rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
  209. fontLarge6 = CGImageCreateWithImageInRect(fontLarge, rect);
  210. rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
  211. fontLarge7 = CGImageCreateWithImageInRect(fontLarge, rect);
  212. rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
  213. fontLarge8 = CGImageCreateWithImageInRect(fontLarge, rect);
  214. rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
  215. fontLarge9 = CGImageCreateWithImageInRect(fontLarge, rect);
  216. fullSize.width = FULL_IMAGE_WIDTH;
  217. fullSize.height = FULL_IMAGE_HEIGHT;
  218. drawContext = CGBitmapContextCreate(NULL, fullSize.width, fullSize.height, 8, 0, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault);
  219. eyeToDraw = 0;
  220. dayOfWeek = 0;
  221. dateDigit0 = 1;
  222. dateDigit1 = 8;
  223. dateDigit2 = 8;
  224. dateDigit3 = 8;
  225. alarmDigit0 = 8;
  226. alarmDigit1 = 8;
  227. alarmDigit2 = 8;
  228. alarmDigit3 = 8;
  229. timeDigit0 = 8;
  230. timeDigit1 = 8;
  231. timeDigit2 = 8;
  232. timeDigit3 = 8;
  233. timeDigit4 = 8;
  234. timeDigit5 = 8;
  235. alarmSign = YES;
  236. return self;
  237. }
  238. - (NSSize)baseSize {
  239. return fullSize;
  240. }
  241. - (void)drawWithDate:(NSDate *)date {
  242. NSCalendarUnit comps = NSWeekdayCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
  243. NSDateComponents *components = [[NSCalendar currentCalendar] components:comps fromDate:date];
  244. dayOfWeek = [components weekday] - 2; // map sun=1 to sun=-1
  245. if ([components month] >= 10) {
  246. dateDigit0 = 1;
  247. dateDigit1 = [components month] - 10;
  248. } else {
  249. dateDigit0 = 0;
  250. dateDigit1 = [components month];
  251. }
  252. if ([components day] >= 30) {
  253. dateDigit2 = 3;
  254. dateDigit3 = [components day] - 30;
  255. } else if ([components day] >= 20) {
  256. dateDigit2 = 2;
  257. dateDigit3 = [components day] - 20;
  258. } else if ([components day] >= 10) {
  259. dateDigit2 = 1;
  260. dateDigit3 = [components day] - 10;
  261. } else {
  262. dateDigit2 = 0;
  263. dateDigit3 = [components day];
  264. }
  265. }
  266. - (void)drawWithEye:(NSInteger)eyeIndex {
  267. eyeToDraw = eyeIndex;
  268. }
  269. - (void)drawInto:(NSView *)view {
  270. // Clear entire canvas
  271. CGRect size;
  272. size.size = fullSize;
  273. size.origin = NSZeroPoint;
  274. CGContextClearRect(drawContext, size);
  275. // Draw Speech Bubble
  276. size.size.width = CGImageGetWidth(bubbleGraphic);
  277. size.size.height = CGImageGetHeight(bubbleGraphic);
  278. size.origin.y = BUBBLE_Y_OFFSET;
  279. CGContextDrawImage(drawContext, size, bubbleGraphic);
  280. // Draw Date
  281. size.size.width = FONT_SMALL_WIDTH;
  282. size.size.height = FONT_SMALL_HEIGHT;
  283. size.origin.y = FONT_SMALL_DATE_Y_OFFSET;
  284. if (dateDigit0 == 1) {
  285. size.origin.x = FONT_SMALL_DATE_X0_OFFSET;
  286. CGContextDrawImage(drawContext, size, fontSmall1);
  287. }
  288. if ((dateDigit1 >= 0) && (dateDigit1 <= 9)) {
  289. size.origin.x = FONT_SMALL_DATE_X1_OFFSET;
  290. CGContextDrawImage(drawContext, size, [self smallHelper:dateDigit1]);
  291. }
  292. if ((dateDigit2 >= 0) && (dateDigit2 <= 9)) {
  293. size.origin.x = FONT_SMALL_DATE_X2_OFFSET;
  294. CGContextDrawImage(drawContext, size, [self smallHelper:dateDigit2]);
  295. }
  296. if ((dateDigit3 >= 0) && (dateDigit3 <= 9)) {
  297. size.origin.x = FONT_SMALL_DATE_X3_OFFSET;
  298. CGContextDrawImage(drawContext, size, [self smallHelper:dateDigit3]);
  299. }
  300. // Draw Day of Week
  301. CGImageRef day = [self dayHelper:dayOfWeek];
  302. size.size.width = FONT_DAYS_WIDTH;
  303. size.size.height = FONT_DAYS_HEIGHT;
  304. size.origin.x = FONT_DAYS_X_OFFSET;
  305. size.origin.y = FONT_DAYS_Y_OFFSET;
  306. CGContextDrawImage(drawContext, size, day);
  307. // Draw Time
  308. size.size.width = FONT_LARGE_WIDTH;
  309. size.size.height = FONT_LARGE_HEIGHT;
  310. size.origin.y = FONT_LARGE_Y_OFFSET;
  311. if ((timeDigit0 >= 0) && (timeDigit0 <= 9)) {
  312. size.origin.x = FONT_LARGE_X0_OFFSET;
  313. CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit0]);
  314. }
  315. if ((timeDigit1 >= 0) && (timeDigit1 <= 9)) {
  316. size.origin.x = FONT_LARGE_X1_OFFSET;
  317. CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit1]);
  318. }
  319. if ((timeDigit2 >= 0) && (timeDigit2 <= 9)) {
  320. size.origin.x = FONT_LARGE_X2_OFFSET;
  321. CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit2]);
  322. }
  323. if ((timeDigit3 >= 0) && (timeDigit3 <= 9)) {
  324. size.origin.x = FONT_LARGE_X3_OFFSET;
  325. CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit3]);
  326. }
  327. if ((timeDigit4 >= 0) && (timeDigit4 <= 9)) {
  328. size.origin.x = FONT_LARGE_X4_OFFSET;
  329. CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit4]);
  330. }
  331. if ((timeDigit5 >= 0) && (timeDigit5 <= 9)) {
  332. size.origin.x = FONT_LARGE_X5_OFFSET;
  333. CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit5]);
  334. }
  335. // Draw Alarm Graphic
  336. if (alarmSign == YES) {
  337. size.size.width = CGImageGetWidth(alarmGraphic);
  338. size.size.height = CGImageGetHeight(alarmGraphic);
  339. size.origin.x = ALARM_X_OFFSET;
  340. size.origin.y = ALARM_Y_OFFSET;
  341. CGContextDrawImage(drawContext, size, alarmGraphic);
  342. }
  343. // Draw Alarm Time
  344. size.size.width = FONT_SMALL_WIDTH;
  345. size.size.height = FONT_SMALL_HEIGHT;
  346. size.origin.y = FONT_SMALL_ALARM_Y_OFFSET;
  347. if ((alarmDigit0 >= 0) && (alarmDigit0 <= 9)) {
  348. size.origin.x = FONT_SMALL_ALARM_X0_OFFSET;
  349. CGContextDrawImage(drawContext, size, [self smallHelper:alarmDigit0]);
  350. }
  351. if ((alarmDigit1 >= 0) && (alarmDigit1 <= 9)) {
  352. size.origin.x = FONT_SMALL_ALARM_X1_OFFSET;
  353. CGContextDrawImage(drawContext, size, [self smallHelper:alarmDigit1]);
  354. }
  355. if ((alarmDigit2 >= 0) && (alarmDigit2 <= 9)) {
  356. size.origin.x = FONT_SMALL_ALARM_X2_OFFSET;
  357. CGContextDrawImage(drawContext, size, [self smallHelper:alarmDigit2]);
  358. }
  359. if ((alarmDigit3 >= 0) && (alarmDigit3 <= 9)) {
  360. size.origin.x = FONT_SMALL_ALARM_X3_OFFSET;
  361. CGContextDrawImage(drawContext, size, [self smallHelper:alarmDigit3]);
  362. }
  363. // Draw Otacon
  364. size.size.width = CGImageGetWidth(otaconGraphic);
  365. size.size.height = CGImageGetHeight(otaconGraphic);
  366. size.origin = NSZeroPoint;
  367. size.origin.x = CGImageGetWidth(bubbleGraphic) + OTACON_X_OFFSET;
  368. CGContextDrawImage(drawContext, size, otaconGraphic);
  369. // Draw eyes
  370. size.size.width = CGImageGetWidth([self eyeHelper:eyeToDraw]);
  371. size.size.height = CGImageGetHeight([self eyeHelper:eyeToDraw]);
  372. size.origin.x = EYE_X_OFFSET;
  373. size.origin.y = EYE_Y_OFFSET;
  374. CGContextDrawImage(drawContext, size, [self eyeHelper:eyeToDraw]);
  375. // Render resulting canvas into bitmap and scale this into our window
  376. CGImageRef drawnImage = CGBitmapContextCreateImage(drawContext);
  377. NSImage *result = [[NSImage alloc] initWithCGImage:drawnImage size:fullSize];
  378. [result drawInRect:[view bounds] fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:NO hints:[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:NSImageInterpolationNone] forKey:NSImageHintInterpolation]];
  379. CGImageRelease(drawnImage);
  380. }
  381. @end