Browse Source

Can switch from military time to am/pm display

Thomas Buck 9 years ago
parent
commit
252c641c8d

+ 4
- 0
OtaClock/Base.lproj/MainMenu.xib View File

99
                 <outlet property="keepOnTopItem" destination="LVI-ch-nme" id="lL1-Yi-zMN"/>
99
                 <outlet property="keepOnTopItem" destination="LVI-ch-nme" id="lL1-Yi-zMN"/>
100
                 <outlet property="lockPositionItem" destination="ShL-8K-SbX" id="ppY-l8-Bda"/>
100
                 <outlet property="lockPositionItem" destination="ShL-8K-SbX" id="ppY-l8-Bda"/>
101
                 <outlet property="mainView" destination="EiT-Mj-1SZ" id="sQZ-BE-YrX"/>
101
                 <outlet property="mainView" destination="EiT-Mj-1SZ" id="sQZ-BE-YrX"/>
102
+                <outlet property="militaryTimeItem" destination="Cgd-DK-xB0" id="7Sz-zg-2dg"/>
102
                 <outlet property="setAlarmItem" destination="IRB-i7-bez" id="V2f-2Y-Eyh"/>
103
                 <outlet property="setAlarmItem" destination="IRB-i7-bez" id="V2f-2Y-Eyh"/>
103
                 <outlet property="showDateItem" destination="0Cy-4I-9bF" id="T7y-ik-8nT"/>
104
                 <outlet property="showDateItem" destination="0Cy-4I-9bF" id="T7y-ik-8nT"/>
104
             </connections>
105
             </connections>
112
                         <items>
113
                         <items>
113
                             <menuItem title="Military Time" id="Cgd-DK-xB0">
114
                             <menuItem title="Military Time" id="Cgd-DK-xB0">
114
                                 <modifierMask key="keyEquivalentModifierMask"/>
115
                                 <modifierMask key="keyEquivalentModifierMask"/>
116
+                                <connections>
117
+                                    <action selector="toggleMilitaryTime:" target="QvC-M9-y7g" id="hoC-N1-2pe"/>
118
+                                </connections>
115
                             </menuItem>
119
                             </menuItem>
116
                             <menuItem title="Alarm Mode" id="S8W-ak-RY9">
120
                             <menuItem title="Alarm Mode" id="S8W-ak-RY9">
117
                                 <modifierMask key="keyEquivalentModifierMask"/>
121
                                 <modifierMask key="keyEquivalentModifierMask"/>

+ 21
- 0
OtaClock/Images.xcassets/font_time.imageset/Contents.json View File

1
+{
2
+  "images" : [
3
+    {
4
+      "idiom" : "universal",
5
+      "scale" : "1x",
6
+      "filename" : "font_time.png"
7
+    },
8
+    {
9
+      "idiom" : "universal",
10
+      "scale" : "2x"
11
+    },
12
+    {
13
+      "idiom" : "universal",
14
+      "scale" : "3x"
15
+    }
16
+  ],
17
+  "info" : {
18
+    "version" : 1,
19
+    "author" : "xcode"
20
+  }
21
+}

BIN
OtaClock/Images.xcassets/font_time.imageset/font_time.png View File


+ 1
- 1
OtaClock/Info.plist View File

19
 	<key>CFBundleSignature</key>
19
 	<key>CFBundleSignature</key>
20
 	<string>????</string>
20
 	<string>????</string>
21
 	<key>CFBundleVersion</key>
21
 	<key>CFBundleVersion</key>
22
-	<string>389</string>
22
+	<string>401</string>
23
 	<key>LSApplicationCategoryType</key>
23
 	<key>LSApplicationCategoryType</key>
24
 	<string>public.app-category.utilities</string>
24
 	<string>public.app-category.utilities</string>
25
 	<key>LSMinimumSystemVersion</key>
25
 	<key>LSMinimumSystemVersion</key>

+ 35
- 2
OtaClock/MainWindow.m View File

55
 @property (weak) IBOutlet NSMenuItem *showDateItem;
55
 @property (weak) IBOutlet NSMenuItem *showDateItem;
56
 @property (weak) IBOutlet NSMenuItem *alarmModeItem;
56
 @property (weak) IBOutlet NSMenuItem *alarmModeItem;
57
 @property (weak) IBOutlet NSMenuItem *alarmTextItem;
57
 @property (weak) IBOutlet NSMenuItem *alarmTextItem;
58
+@property (weak) IBOutlet NSMenuItem *militaryTimeItem;
58
 
59
 
59
 @property (weak) IBOutlet NSMenuItem *changeSize1;
60
 @property (weak) IBOutlet NSMenuItem *changeSize1;
60
 @property (weak) IBOutlet NSMenuItem *changeSize2;
61
 @property (weak) IBOutlet NSMenuItem *changeSize2;
172
         self.showDateItem.state = NSOffState;
173
         self.showDateItem.state = NSOffState;
173
     }
174
     }
174
     
175
     
176
+    // load alarm mode state
175
     if ([defaults objectForKey:CONFIG_ALARM_MODE] != nil) {
177
     if ([defaults objectForKey:CONFIG_ALARM_MODE] != nil) {
176
         if ([defaults boolForKey:CONFIG_ALARM_MODE] == YES) {
178
         if ([defaults boolForKey:CONFIG_ALARM_MODE] == YES) {
177
             [self.alarmModeItem setState:NSOnState];
179
             [self.alarmModeItem setState:NSOnState];
179
         }
181
         }
180
     }
182
     }
181
     
183
     
184
+    // load military time state
185
+    if ([defaults objectForKey:CONFIG_MILITARY_TIME] == nil) {
186
+        [self.militaryTimeItem setState:NSOnState];
187
+        [[self.mainView render] drawMilitaryTime:YES];
188
+    } else {
189
+        if ([defaults boolForKey:CONFIG_MILITARY_TIME]) {
190
+            [self.militaryTimeItem setState:NSOnState];
191
+            [[self.mainView render] drawMilitaryTime:YES];
192
+        } else {
193
+            [[self.mainView render] drawMilitaryTime:NO];
194
+        }
195
+    }
196
+    
182
     [[self.mainView render] drawDate:showDate];
197
     [[self.mainView render] drawDate:showDate];
183
     
198
     
184
     [self setFrame:frame display:YES];
199
     [self setFrame:frame display:YES];
185
 }
200
 }
186
 
201
 
202
+- (IBAction)toggleMilitaryTime:(id)sender {
203
+    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
204
+    
205
+    if (self.militaryTimeItem.state == NSOnState) {
206
+        // Turn off military time
207
+        [self.militaryTimeItem setState:NSOffState];
208
+        [[self.mainView render] drawMilitaryTime:NO];
209
+        [defaults setBool:NO forKey:CONFIG_MILITARY_TIME];
210
+    } else {
211
+        // Turn on military time
212
+        [self.militaryTimeItem setState:NSOnState];
213
+        [[self.mainView render] drawMilitaryTime:YES];
214
+        [defaults setBool:YES forKey:CONFIG_MILITARY_TIME];
215
+    }
216
+    
217
+    [defaults synchronize];
218
+    self.mainView.needsDisplay = YES;
219
+}
220
+
187
 - (IBAction)toggleAlarm:(id)sender {
221
 - (IBAction)toggleAlarm:(id)sender {
188
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
222
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
189
     
223
     
238
     if (self.alarmModeItem.state == NSOnState) {
272
     if (self.alarmModeItem.state == NSOnState) {
239
         NSDateComponents *alarmComponents = [[NSCalendar currentCalendar] components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:self.alarmDatePicker.dateValue];
273
         NSDateComponents *alarmComponents = [[NSCalendar currentCalendar] components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:self.alarmDatePicker.dateValue];
240
         if (([components minute] == [alarmComponents minute]) && ([components hour] == [alarmComponents hour]) && ([components second] == 0)) {
274
         if (([components minute] == [alarmComponents minute]) && ([components hour] == [alarmComponents hour]) && ([components second] == 0)) {
241
-            // We have reached the alarm time
242
-            NSLog(@"Alarm time reached!");
275
+            NSLog(@"Alarm time reached! (%02ld:%02ld)", (long)[alarmComponents hour], (long)[alarmComponents minute]);
243
             [self drawAnimation:[NSNumber numberWithInteger:1]];
276
             [self drawAnimation:[NSNumber numberWithInteger:1]];
244
         }
277
         }
245
     }
278
     }

+ 1
- 0
OtaClock/Render.h View File

16
 - (NSSize)baseSize;
16
 - (NSSize)baseSize;
17
 
17
 
18
 - (void)blinkDots;
18
 - (void)blinkDots;
19
+- (void)drawMilitaryTime:(BOOL)mil;
19
 - (void)drawAnimation:(NSInteger)state;
20
 - (void)drawAnimation:(NSInteger)state;
20
 - (void)drawAlarmDate:(NSDate *)alarm;
21
 - (void)drawAlarmDate:(NSDate *)alarm;
21
 - (void)drawDate:(BOOL)draw;
22
 - (void)drawDate:(BOOL)draw;

+ 69
- 14
OtaClock/Render.m View File

53
 #define FONT_SMALL_ALARM_X2_OFFSET 41
53
 #define FONT_SMALL_ALARM_X2_OFFSET 41
54
 #define FONT_SMALL_ALARM_X3_OFFSET 46
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
 #define ALARM_X_OFFSET 5
60
 #define ALARM_X_OFFSET 5
57
 #define ALARM_Y_OFFSET 57
61
 #define ALARM_Y_OFFSET 57
58
 
62
 
71
 @property (assign) CGImageRef otaconGraphic, bubbleGraphic, alarmGraphic, blankGraphic;
75
 @property (assign) CGImageRef otaconGraphic, bubbleGraphic, alarmGraphic, blankGraphic;
72
 @property (assign) CGImageRef otacon1Graphic, otacon2Graphic, otacon3Graphic;
76
 @property (assign) CGImageRef otacon1Graphic, otacon2Graphic, otacon3Graphic;
73
 @property (assign) CGImageRef eye0, eye1, eye2, eye3, eye4, dotSmallGraphic, dotLargeGraphic;
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
 @property (assign) CGImageRef fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
79
 @property (assign) CGImageRef fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
76
 @property (assign) CGImageRef fontLarge1, fontLarge2, fontLarge3, fontLarge4, fontLarge5, fontLarge6, fontLarge7, fontLarge8, fontLarge9, fontLarge0;
80
 @property (assign) CGImageRef fontLarge1, fontLarge2, fontLarge3, fontLarge4, fontLarge5, fontLarge6, fontLarge7, fontLarge8, fontLarge9, fontLarge0;
77
 
81
 
79
 @property (assign) NSInteger dateDigit0, dateDigit1, dateDigit2, dateDigit3;
83
 @property (assign) NSInteger dateDigit0, dateDigit1, dateDigit2, dateDigit3;
80
 @property (assign) NSInteger alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
84
 @property (assign) NSInteger alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
81
 @property (assign) NSInteger timeDigit0, timeDigit1, timeDigit2, timeDigit3, timeDigit4, timeDigit5;
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
 @property (assign) NSSize fullSize;
88
 @property (assign) NSSize fullSize;
85
 @property (assign) CGContextRef drawContext;
89
 @property (assign) CGContextRef drawContext;
93
 @synthesize otaconGraphic, bubbleGraphic, alarmGraphic, blankGraphic;
97
 @synthesize otaconGraphic, bubbleGraphic, alarmGraphic, blankGraphic;
94
 @synthesize otacon1Graphic, otacon2Graphic, otacon3Graphic;
98
 @synthesize otacon1Graphic, otacon2Graphic, otacon3Graphic;
95
 @synthesize eye0, eye1, eye2, eye3, eye4, dotSmallGraphic, dotLargeGraphic;
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
 @synthesize fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
101
 @synthesize fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
98
 @synthesize fontLarge1, fontLarge2, fontLarge3, fontLarge4, fontLarge5, fontLarge6, fontLarge7, fontLarge8, fontLarge9, fontLarge0;
102
 @synthesize fontLarge1, fontLarge2, fontLarge3, fontLarge4, fontLarge5, fontLarge6, fontLarge7, fontLarge8, fontLarge9, fontLarge0;
99
 
103
 
101
 @synthesize dateDigit0, dateDigit1, dateDigit2, dateDigit3;
105
 @synthesize dateDigit0, dateDigit1, dateDigit2, dateDigit3;
102
 @synthesize alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
106
 @synthesize alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
103
 @synthesize timeDigit0, timeDigit1, timeDigit2, timeDigit3, timeDigit4, timeDigit5;
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
 @synthesize fullSize;
110
 @synthesize fullSize;
107
 @synthesize drawContext;
111
 @synthesize drawContext;
180
     NSImage *fontDaysImage = [NSImage imageNamed:@"font_days"];
184
     NSImage *fontDaysImage = [NSImage imageNamed:@"font_days"];
181
     NSImage *fontSmallImage = [NSImage imageNamed:@"font_small"];
185
     NSImage *fontSmallImage = [NSImage imageNamed:@"font_small"];
182
     NSImage *fontLargeImage = [NSImage imageNamed:@"font_large"];
186
     NSImage *fontLargeImage = [NSImage imageNamed:@"font_large"];
187
+    NSImage *fontTimeImage = [NSImage imageNamed:@"font_time"];
183
     NSImage *alarmImage = [NSImage imageNamed:@"alarm"];
188
     NSImage *alarmImage = [NSImage imageNamed:@"alarm"];
184
     NSImage *dotsSmallImage = [NSImage imageNamed:@"dots_small"];
189
     NSImage *dotsSmallImage = [NSImage imageNamed:@"dots_small"];
185
     NSImage *dotsLargeImage = [NSImage imageNamed:@"dots_large"];
190
     NSImage *dotsLargeImage = [NSImage imageNamed:@"dots_large"];
276
     rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
281
     rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
277
     fontLarge9 = CGImageCreateWithImageInRect(fontLarge, rect);
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
     fullSize.width = FULL_IMAGE_WIDTH;
293
     fullSize.width = FULL_IMAGE_WIDTH;
280
     fullSize.height = FULL_IMAGE_HEIGHT;
294
     fullSize.height = FULL_IMAGE_HEIGHT;
281
     
295
     
295
     timeDigit4 = 8;
309
     timeDigit4 = 8;
296
     timeDigit5 = 8;
310
     timeDigit5 = 8;
297
     timeDots = YES;
311
     timeDots = YES;
312
+    militaryTime = NO;
313
+    isAfternoon = NO;
298
     
314
     
299
     alarmDigit0 = -1;
315
     alarmDigit0 = -1;
300
     alarmDigit1 = -1;
316
     alarmDigit1 = -1;
339
     }
355
     }
340
 }
356
 }
341
 
357
 
358
+- (void)drawMilitaryTime:(BOOL)mil {
359
+    militaryTime = mil;
360
+    [self drawWithDate:[NSDate date]];
361
+}
362
+
342
 - (void)drawAnimation:(NSInteger)state {
363
 - (void)drawAnimation:(NSInteger)state {
343
     if (animState != state) {
364
     if (animState != state) {
344
         [[self.parent window] invalidateShadow];
365
         [[self.parent window] invalidateShadow];
374
     NSDateComponents *components = [[NSCalendar currentCalendar] components:comps fromDate:date];
395
     NSDateComponents *components = [[NSCalendar currentCalendar] components:comps fromDate:date];
375
     dayOfWeek = [components weekday] - 2; // map sun=1 to sun=-1
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
     CONVERT_DECIMAL([components month], dateDigit0, dateDigit1);
414
     CONVERT_DECIMAL([components month], dateDigit0, dateDigit1);
378
     CONVERT_DECIMAL([components day], dateDigit2, dateDigit3);
415
     CONVERT_DECIMAL([components day], dateDigit2, dateDigit3);
379
-    CONVERT_DECIMAL([components hour], timeDigit0, timeDigit1);
416
+    CONVERT_DECIMAL(hour, timeDigit0, timeDigit1);
380
     CONVERT_DECIMAL([components minute], timeDigit2, timeDigit3);
417
     CONVERT_DECIMAL([components minute], timeDigit2, timeDigit3);
381
     CONVERT_DECIMAL([components second], timeDigit4, timeDigit5);
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
 - (void)drawWithEye:(NSInteger)eyeIndex {
428
 - (void)drawWithEye:(NSInteger)eyeIndex {
456
         size.origin.x = FONT_LARGE_X3_OFFSET;
500
         size.origin.x = FONT_LARGE_X3_OFFSET;
457
         CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit3]);
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
     // Draw dots between hours, minutes and seconds
521
     // Draw dots between hours, minutes and seconds
472
         size.origin.y = DOTS_TIME_Y_OFFSET;
525
         size.origin.y = DOTS_TIME_Y_OFFSET;
473
         size.origin.x = DOTS_TIME_X0_OFFSET;
526
         size.origin.x = DOTS_TIME_X0_OFFSET;
474
         CGContextDrawImage(drawContext, size, dotLargeGraphic);
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
     // Draw Alarm Graphic
534
     // Draw Alarm Graphic

Loading…
Cancel
Save