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

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