Browse Source

Added time rendering and alarm sign

Thomas Buck 8 years ago
parent
commit
f9305cbc03
3 changed files with 65 additions and 5 deletions
  1. 1
    1
      OtaClock/Info.plist
  2. 2
    2
      OtaClock/MainWindow.m
  3. 62
    2
      OtaClock/Render.m

+ 1
- 1
OtaClock/Info.plist View File

@@ -19,7 +19,7 @@
19 19
 	<key>CFBundleSignature</key>
20 20
 	<string>????</string>
21 21
 	<key>CFBundleVersion</key>
22
-	<string>215</string>
22
+	<string>239</string>
23 23
 	<key>LSApplicationCategoryType</key>
24 24
 	<string>public.app-category.utilities</string>
25 25
 	<key>LSMinimumSystemVersion</key>

+ 2
- 2
OtaClock/MainWindow.m View File

@@ -128,8 +128,8 @@
128 128
 }
129 129
 
130 130
 - (void)updateTime:(id)sender {
131
-    //[[self.mainView render] drawWithDate:[NSDate date]];
132
-    //self.mainView.needsDisplay = YES;
131
+    [[self.mainView render] drawWithDate:[NSDate date]];
132
+    self.mainView.needsDisplay = YES;
133 133
 }
134 134
 
135 135
 - (void)blink {

+ 62
- 2
OtaClock/Render.m View File

@@ -26,9 +26,18 @@
26 26
 #define FONT_LARGE_HEIGHT 7
27 27
 #define FONT_LARGE_PADDING 1
28 28
 
29
+#define FONT_LARGE_Y_OFFSET 63
30
+#define FONT_LARGE_X0_OFFSET 5
31
+#define FONT_LARGE_X1_OFFSET 12
32
+#define FONT_LARGE_X2_OFFSET 21
33
+#define FONT_LARGE_X3_OFFSET 28
34
+#define FONT_LARGE_X4_OFFSET 37
35
+#define FONT_LARGE_X5_OFFSET 44
36
+
29 37
 #define FONT_SMALL_WIDTH 4
30 38
 #define FONT_SMALL_HEIGHT 5
31 39
 #define FONT_SMALL_PADDING 1
40
+
32 41
 #define FONT_SMALL_DATE_Y_OFFSET 71
33 42
 #define FONT_SMALL_DATE_X0_OFFSET 3
34 43
 #define FONT_SMALL_DATE_X1_OFFSET 8
@@ -41,9 +50,12 @@
41 50
 #define FONT_SMALL_ALARM_X2_OFFSET 41
42 51
 #define FONT_SMALL_ALARM_X3_OFFSET 46
43 52
 
53
+#define ALARM_X_OFFSET 5
54
+#define ALARM_Y_OFFSET 57
55
+
44 56
 @interface Render ()
45 57
 
46
-@property (assign) CGImageRef otaconGraphic, bubbleGraphic;
58
+@property (assign) CGImageRef otaconGraphic, bubbleGraphic, alarmGraphic;
47 59
 @property (assign) CGImageRef eye0, eye1, eye2, eye3, eye4;
48 60
 @property (assign) CGImageRef fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
49 61
 @property (assign) CGImageRef fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
@@ -52,6 +64,8 @@
52 64
 @property (assign) NSInteger eyeToDraw, dayOfWeek;
53 65
 @property (assign) NSInteger dateDigit0, dateDigit1, dateDigit2, dateDigit3;
54 66
 @property (assign) NSInteger alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
67
+@property (assign) NSInteger timeDigit0, timeDigit1, timeDigit2, timeDigit3, timeDigit4, timeDigit5;
68
+@property (assign) BOOL alarmSign;
55 69
 
56 70
 @property (assign) NSSize fullSize;
57 71
 @property (assign) CGContextRef drawContext;
@@ -62,7 +76,7 @@
62 76
 
63 77
 @implementation Render
64 78
 
65
-@synthesize otaconGraphic, bubbleGraphic;
79
+@synthesize otaconGraphic, bubbleGraphic, alarmGraphic;
66 80
 @synthesize eye0, eye1, eye2, eye3, eye4;
67 81
 @synthesize fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
68 82
 @synthesize fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
@@ -71,6 +85,8 @@
71 85
 @synthesize eyeToDraw, dayOfWeek;
72 86
 @synthesize dateDigit0, dateDigit1, dateDigit2, dateDigit3;
73 87
 @synthesize alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
88
+@synthesize timeDigit0, timeDigit1, timeDigit2, timeDigit3, timeDigit4, timeDigit5;
89
+@synthesize alarmSign;
74 90
 
75 91
 @synthesize fullSize;
76 92
 @synthesize drawContext;
@@ -149,11 +165,13 @@
149 165
     NSImage *fontDaysImage = [NSImage imageNamed:@"font_days"];
150 166
     NSImage *fontSmallImage = [NSImage imageNamed:@"font_small"];
151 167
     NSImage *fontLargeImage = [NSImage imageNamed:@"font_large"];
168
+    NSImage *alarmImage = [NSImage imageNamed:@"alarm"];
152 169
     
153 170
     NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithAttributes:nil];
154 171
     
155 172
     otaconGraphic = [otaconImage CGImageForProposedRect:nil context:context hints:nil];
156 173
     bubbleGraphic = [bubbleImage CGImageForProposedRect:nil context:context hints:nil];
174
+    alarmGraphic = [alarmImage CGImageForProposedRect:nil context:context hints:nil];
157 175
     eye0 = [eye0Image CGImageForProposedRect:nil context:context hints:nil];
158 176
     eye1 = [eye1Image CGImageForProposedRect:nil context:context hints:nil];
159 177
     eye2 = [eye2Image CGImageForProposedRect:nil context:context hints:nil];
@@ -246,6 +264,13 @@
246 264
     alarmDigit1 = 8;
247 265
     alarmDigit2 = 8;
248 266
     alarmDigit3 = 8;
267
+    timeDigit0 = 8;
268
+    timeDigit1 = 8;
269
+    timeDigit2 = 8;
270
+    timeDigit3 = 8;
271
+    timeDigit4 = 8;
272
+    timeDigit5 = 8;
273
+    alarmSign = YES;
249 274
     
250 275
     return self;
251 276
 }
@@ -329,7 +354,42 @@
329 354
     CGContextDrawImage(drawContext, size, day);
330 355
     
331 356
     // Draw Time
357
+    size.size.width = FONT_LARGE_WIDTH;
358
+    size.size.height = FONT_LARGE_HEIGHT;
359
+    size.origin.y = FONT_LARGE_Y_OFFSET;
360
+    if ((timeDigit0 >= 0) && (timeDigit0 <= 9)) {
361
+        size.origin.x = FONT_LARGE_X0_OFFSET;
362
+        CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit0]);
363
+    }
364
+    if ((timeDigit1 >= 0) && (timeDigit1 <= 9)) {
365
+        size.origin.x = FONT_LARGE_X1_OFFSET;
366
+        CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit1]);
367
+    }
368
+    if ((timeDigit2 >= 0) && (timeDigit2 <= 9)) {
369
+        size.origin.x = FONT_LARGE_X2_OFFSET;
370
+        CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit2]);
371
+    }
372
+    if ((timeDigit3 >= 0) && (timeDigit3 <= 9)) {
373
+        size.origin.x = FONT_LARGE_X3_OFFSET;
374
+        CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit3]);
375
+    }
376
+    if ((timeDigit4 >= 0) && (timeDigit4 <= 9)) {
377
+        size.origin.x = FONT_LARGE_X4_OFFSET;
378
+        CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit4]);
379
+    }
380
+    if ((timeDigit5 >= 0) && (timeDigit5 <= 9)) {
381
+        size.origin.x = FONT_LARGE_X5_OFFSET;
382
+        CGContextDrawImage(drawContext, size, [self largeHelper:timeDigit5]);
383
+    }
332 384
     
385
+    // Draw Alarm Graphic
386
+    if (alarmSign == YES) {
387
+        size.size.width = CGImageGetWidth(alarmGraphic);
388
+        size.size.height = CGImageGetHeight(alarmGraphic);
389
+        size.origin.x = ALARM_X_OFFSET;
390
+        size.origin.y = ALARM_Y_OFFSET;
391
+        CGContextDrawImage(drawContext, size, alarmGraphic);
392
+    }
333 393
     
334 394
     // Draw Alarm Time
335 395
     size.size.width = FONT_SMALL_WIDTH;

Loading…
Cancel
Save