|
@@ -53,6 +53,10 @@
|
53
|
53
|
#define FONT_SMALL_ALARM_X2_OFFSET 41
|
54
|
54
|
#define FONT_SMALL_ALARM_X3_OFFSET 46
|
55
|
55
|
|
|
56
|
+#define FONT_TIME_WIDTH 11
|
|
57
|
+#define FONT_TIME_HEIGHT 3
|
|
58
|
+#define FONT_TIME_PADDING 1
|
|
59
|
+
|
56
|
60
|
#define ALARM_X_OFFSET 5
|
57
|
61
|
#define ALARM_Y_OFFSET 57
|
58
|
62
|
|
|
@@ -71,7 +75,7 @@
|
71
|
75
|
@property (assign) CGImageRef otaconGraphic, bubbleGraphic, alarmGraphic, blankGraphic;
|
72
|
76
|
@property (assign) CGImageRef otacon1Graphic, otacon2Graphic, otacon3Graphic;
|
73
|
77
|
@property (assign) CGImageRef eye0, eye1, eye2, eye3, eye4, dotSmallGraphic, dotLargeGraphic;
|
74
|
|
-@property (assign) CGImageRef fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
|
|
78
|
+@property (assign) CGImageRef fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday, fontAM, fontPM;
|
75
|
79
|
@property (assign) CGImageRef fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
|
76
|
80
|
@property (assign) CGImageRef fontLarge1, fontLarge2, fontLarge3, fontLarge4, fontLarge5, fontLarge6, fontLarge7, fontLarge8, fontLarge9, fontLarge0;
|
77
|
81
|
|
|
@@ -79,7 +83,7 @@
|
79
|
83
|
@property (assign) NSInteger dateDigit0, dateDigit1, dateDigit2, dateDigit3;
|
80
|
84
|
@property (assign) NSInteger alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
|
81
|
85
|
@property (assign) NSInteger timeDigit0, timeDigit1, timeDigit2, timeDigit3, timeDigit4, timeDigit5;
|
82
|
|
-@property (assign) BOOL alarmSign, alarmDots, timeDots, drawDate;
|
|
86
|
+@property (assign) BOOL alarmSign, alarmDots, timeDots, drawDate, militaryTime, isAfternoon;
|
83
|
87
|
|
84
|
88
|
@property (assign) NSSize fullSize;
|
85
|
89
|
@property (assign) CGContextRef drawContext;
|
|
@@ -93,7 +97,7 @@
|
93
|
97
|
@synthesize otaconGraphic, bubbleGraphic, alarmGraphic, blankGraphic;
|
94
|
98
|
@synthesize otacon1Graphic, otacon2Graphic, otacon3Graphic;
|
95
|
99
|
@synthesize eye0, eye1, eye2, eye3, eye4, dotSmallGraphic, dotLargeGraphic;
|
96
|
|
-@synthesize fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
|
|
100
|
+@synthesize fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday, fontAM, fontPM;
|
97
|
101
|
@synthesize fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
|
98
|
102
|
@synthesize fontLarge1, fontLarge2, fontLarge3, fontLarge4, fontLarge5, fontLarge6, fontLarge7, fontLarge8, fontLarge9, fontLarge0;
|
99
|
103
|
|
|
@@ -101,7 +105,7 @@
|
101
|
105
|
@synthesize dateDigit0, dateDigit1, dateDigit2, dateDigit3;
|
102
|
106
|
@synthesize alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
|
103
|
107
|
@synthesize timeDigit0, timeDigit1, timeDigit2, timeDigit3, timeDigit4, timeDigit5;
|
104
|
|
-@synthesize alarmSign, alarmDots, timeDots, drawDate;
|
|
108
|
+@synthesize alarmSign, alarmDots, timeDots, drawDate, militaryTime, isAfternoon;
|
105
|
109
|
|
106
|
110
|
@synthesize fullSize;
|
107
|
111
|
@synthesize drawContext;
|
|
@@ -180,6 +184,7 @@
|
180
|
184
|
NSImage *fontDaysImage = [NSImage imageNamed:@"font_days"];
|
181
|
185
|
NSImage *fontSmallImage = [NSImage imageNamed:@"font_small"];
|
182
|
186
|
NSImage *fontLargeImage = [NSImage imageNamed:@"font_large"];
|
|
187
|
+ NSImage *fontTimeImage = [NSImage imageNamed:@"font_time"];
|
183
|
188
|
NSImage *alarmImage = [NSImage imageNamed:@"alarm"];
|
184
|
189
|
NSImage *dotsSmallImage = [NSImage imageNamed:@"dots_small"];
|
185
|
190
|
NSImage *dotsLargeImage = [NSImage imageNamed:@"dots_large"];
|
|
@@ -276,6 +281,15 @@
|
276
|
281
|
rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
|
277
|
282
|
fontLarge9 = CGImageCreateWithImageInRect(fontLarge, rect);
|
278
|
283
|
|
|
284
|
+ CGImageRef fontTime = [fontTimeImage CGImageForProposedRect:nil context:context hints:nil];
|
|
285
|
+ rect.size.width = FONT_TIME_WIDTH;
|
|
286
|
+ rect.size.height = FONT_TIME_HEIGHT;
|
|
287
|
+ rect.origin.x = 0;
|
|
288
|
+ rect.origin.y = 0;
|
|
289
|
+ fontAM = CGImageCreateWithImageInRect(fontTime, rect);
|
|
290
|
+ rect.origin.y += FONT_TIME_HEIGHT + FONT_TIME_PADDING;
|
|
291
|
+ fontPM = CGImageCreateWithImageInRect(fontTime, rect);
|
|
292
|
+
|
279
|
293
|
fullSize.width = FULL_IMAGE_WIDTH;
|
280
|
294
|
fullSize.height = FULL_IMAGE_HEIGHT;
|
281
|
295
|
|
|
@@ -295,6 +309,8 @@
|
295
|
309
|
timeDigit4 = 8;
|
296
|
310
|
timeDigit5 = 8;
|
297
|
311
|
timeDots = YES;
|
|
312
|
+ militaryTime = NO;
|
|
313
|
+ isAfternoon = NO;
|
298
|
314
|
|
299
|
315
|
alarmDigit0 = -1;
|
300
|
316
|
alarmDigit1 = -1;
|
|
@@ -339,6 +355,11 @@
|
339
|
355
|
}
|
340
|
356
|
}
|
341
|
357
|
|
|
358
|
+- (void)drawMilitaryTime:(BOOL)mil {
|
|
359
|
+ militaryTime = mil;
|
|
360
|
+ [self drawWithDate:[NSDate date]];
|
|
361
|
+}
|
|
362
|
+
|
342
|
363
|
- (void)drawAnimation:(NSInteger)state {
|
343
|
364
|
if (animState != state) {
|
344
|
365
|
[[self.parent window] invalidateShadow];
|
|
@@ -374,11 +395,34 @@
|
374
|
395
|
NSDateComponents *components = [[NSCalendar currentCalendar] components:comps fromDate:date];
|
375
|
396
|
dayOfWeek = [components weekday] - 2; // map sun=1 to sun=-1
|
376
|
397
|
|
|
398
|
+ // Convert from military time to am/pm format if neccessary
|
|
399
|
+ NSInteger hour = [components hour];
|
|
400
|
+ if (militaryTime == NO) {
|
|
401
|
+ if (hour == 0) {
|
|
402
|
+ hour = 12;
|
|
403
|
+ isAfternoon = false;
|
|
404
|
+ } else if (hour == 12) {
|
|
405
|
+ isAfternoon = true;
|
|
406
|
+ } else if (hour > 12) {
|
|
407
|
+ isAfternoon = true;
|
|
408
|
+ hour -= 12;
|
|
409
|
+ } else if (hour < 12) {
|
|
410
|
+ isAfternoon = false;
|
|
411
|
+ }
|
|
412
|
+ }
|
|
413
|
+
|
377
|
414
|
CONVERT_DECIMAL([components month], dateDigit0, dateDigit1);
|
378
|
415
|
CONVERT_DECIMAL([components day], dateDigit2, dateDigit3);
|
379
|
|
- CONVERT_DECIMAL([components hour], timeDigit0, timeDigit1);
|
|
416
|
+ CONVERT_DECIMAL(hour, timeDigit0, timeDigit1);
|
380
|
417
|
CONVERT_DECIMAL([components minute], timeDigit2, timeDigit3);
|
381
|
418
|
CONVERT_DECIMAL([components second], timeDigit4, timeDigit5);
|
|
419
|
+
|
|
420
|
+ // Remove leading hour zero when drawing in am/pm mode
|
|
421
|
+ if (militaryTime == NO) {
|
|
422
|
+ if (timeDigit0 == 0) {
|
|
423
|
+ timeDigit0 = -1;
|
|
424
|
+ }
|
|
425
|
+ }
|
382
|
426
|
}
|
383
|
427
|
|
384
|
428
|
- (void)drawWithEye:(NSInteger)eyeIndex {
|
|
@@ -456,13 +500,22 @@
|
456
|
500
|
size.origin.x = FONT_LARGE_X3_OFFSET;
|
457
|
501
|
CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit3]);
|
458
|
502
|
}
|
459
|
|
- if ((timeDigit4 >= 0) && (timeDigit4 <= 9)) {
|
460
|
|
- size.origin.x = FONT_LARGE_X4_OFFSET;
|
461
|
|
- CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit4]);
|
462
|
|
- }
|
463
|
|
- if ((timeDigit5 >= 0) && (timeDigit5 <= 9)) {
|
464
|
|
- size.origin.x = FONT_LARGE_X5_OFFSET;
|
465
|
|
- CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit5]);
|
|
503
|
+ if (militaryTime == YES) {
|
|
504
|
+ if ((timeDigit4 >= 0) && (timeDigit4 <= 9)) {
|
|
505
|
+ size.origin.x = FONT_LARGE_X4_OFFSET;
|
|
506
|
+ CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit4]);
|
|
507
|
+ }
|
|
508
|
+ if ((timeDigit5 >= 0) && (timeDigit5 <= 9)) {
|
|
509
|
+ size.origin.x = FONT_LARGE_X5_OFFSET;
|
|
510
|
+ CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit5]);
|
|
511
|
+ }
|
|
512
|
+ } else {
|
|
513
|
+ // Draw AM/PM marker
|
|
514
|
+ size.size.width = FONT_TIME_WIDTH;
|
|
515
|
+ size.size.height = FONT_TIME_HEIGHT;
|
|
516
|
+ size.origin.x = 36;
|
|
517
|
+ size.origin.y = 63;
|
|
518
|
+ CGContextDrawImage(drawContext, size, isAfternoon ? fontPM : fontAM);
|
466
|
519
|
}
|
467
|
520
|
|
468
|
521
|
// Draw dots between hours, minutes and seconds
|
|
@@ -472,8 +525,10 @@
|
472
|
525
|
size.origin.y = DOTS_TIME_Y_OFFSET;
|
473
|
526
|
size.origin.x = DOTS_TIME_X0_OFFSET;
|
474
|
527
|
CGContextDrawImage(drawContext, size, dotLargeGraphic);
|
475
|
|
- size.origin.x = DOTS_TIME_X1_OFFSET;
|
476
|
|
- CGContextDrawImage(drawContext, size, dotLargeGraphic);
|
|
528
|
+ if (militaryTime == YES) {
|
|
529
|
+ size.origin.x = DOTS_TIME_X1_OFFSET;
|
|
530
|
+ CGContextDrawImage(drawContext, size, dotLargeGraphic);
|
|
531
|
+ }
|
477
|
532
|
}
|
478
|
533
|
|
479
|
534
|
// Draw Alarm Graphic
|