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

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