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 19KB

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