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
 	<key>CFBundleSignature</key>
19
 	<key>CFBundleSignature</key>
20
 	<string>????</string>
20
 	<string>????</string>
21
 	<key>CFBundleVersion</key>
21
 	<key>CFBundleVersion</key>
22
-	<string>215</string>
22
+	<string>239</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>

+ 2
- 2
OtaClock/MainWindow.m View File

128
 }
128
 }
129
 
129
 
130
 - (void)updateTime:(id)sender {
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
 - (void)blink {
135
 - (void)blink {

+ 62
- 2
OtaClock/Render.m View File

26
 #define FONT_LARGE_HEIGHT 7
26
 #define FONT_LARGE_HEIGHT 7
27
 #define FONT_LARGE_PADDING 1
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
 #define FONT_SMALL_WIDTH 4
37
 #define FONT_SMALL_WIDTH 4
30
 #define FONT_SMALL_HEIGHT 5
38
 #define FONT_SMALL_HEIGHT 5
31
 #define FONT_SMALL_PADDING 1
39
 #define FONT_SMALL_PADDING 1
40
+
32
 #define FONT_SMALL_DATE_Y_OFFSET 71
41
 #define FONT_SMALL_DATE_Y_OFFSET 71
33
 #define FONT_SMALL_DATE_X0_OFFSET 3
42
 #define FONT_SMALL_DATE_X0_OFFSET 3
34
 #define FONT_SMALL_DATE_X1_OFFSET 8
43
 #define FONT_SMALL_DATE_X1_OFFSET 8
41
 #define FONT_SMALL_ALARM_X2_OFFSET 41
50
 #define FONT_SMALL_ALARM_X2_OFFSET 41
42
 #define FONT_SMALL_ALARM_X3_OFFSET 46
51
 #define FONT_SMALL_ALARM_X3_OFFSET 46
43
 
52
 
53
+#define ALARM_X_OFFSET 5
54
+#define ALARM_Y_OFFSET 57
55
+
44
 @interface Render ()
56
 @interface Render ()
45
 
57
 
46
-@property (assign) CGImageRef otaconGraphic, bubbleGraphic;
58
+@property (assign) CGImageRef otaconGraphic, bubbleGraphic, alarmGraphic;
47
 @property (assign) CGImageRef eye0, eye1, eye2, eye3, eye4;
59
 @property (assign) CGImageRef eye0, eye1, eye2, eye3, eye4;
48
 @property (assign) CGImageRef fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
60
 @property (assign) CGImageRef fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
49
 @property (assign) CGImageRef fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
61
 @property (assign) CGImageRef fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
52
 @property (assign) NSInteger eyeToDraw, dayOfWeek;
64
 @property (assign) NSInteger eyeToDraw, dayOfWeek;
53
 @property (assign) NSInteger dateDigit0, dateDigit1, dateDigit2, dateDigit3;
65
 @property (assign) NSInteger dateDigit0, dateDigit1, dateDigit2, dateDigit3;
54
 @property (assign) NSInteger alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
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
 @property (assign) NSSize fullSize;
70
 @property (assign) NSSize fullSize;
57
 @property (assign) CGContextRef drawContext;
71
 @property (assign) CGContextRef drawContext;
62
 
76
 
63
 @implementation Render
77
 @implementation Render
64
 
78
 
65
-@synthesize otaconGraphic, bubbleGraphic;
79
+@synthesize otaconGraphic, bubbleGraphic, alarmGraphic;
66
 @synthesize eye0, eye1, eye2, eye3, eye4;
80
 @synthesize eye0, eye1, eye2, eye3, eye4;
67
 @synthesize fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
81
 @synthesize fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
68
 @synthesize fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
82
 @synthesize fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
71
 @synthesize eyeToDraw, dayOfWeek;
85
 @synthesize eyeToDraw, dayOfWeek;
72
 @synthesize dateDigit0, dateDigit1, dateDigit2, dateDigit3;
86
 @synthesize dateDigit0, dateDigit1, dateDigit2, dateDigit3;
73
 @synthesize alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
87
 @synthesize alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
88
+@synthesize timeDigit0, timeDigit1, timeDigit2, timeDigit3, timeDigit4, timeDigit5;
89
+@synthesize alarmSign;
74
 
90
 
75
 @synthesize fullSize;
91
 @synthesize fullSize;
76
 @synthesize drawContext;
92
 @synthesize drawContext;
149
     NSImage *fontDaysImage = [NSImage imageNamed:@"font_days"];
165
     NSImage *fontDaysImage = [NSImage imageNamed:@"font_days"];
150
     NSImage *fontSmallImage = [NSImage imageNamed:@"font_small"];
166
     NSImage *fontSmallImage = [NSImage imageNamed:@"font_small"];
151
     NSImage *fontLargeImage = [NSImage imageNamed:@"font_large"];
167
     NSImage *fontLargeImage = [NSImage imageNamed:@"font_large"];
168
+    NSImage *alarmImage = [NSImage imageNamed:@"alarm"];
152
     
169
     
153
     NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithAttributes:nil];
170
     NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithAttributes:nil];
154
     
171
     
155
     otaconGraphic = [otaconImage CGImageForProposedRect:nil context:context hints:nil];
172
     otaconGraphic = [otaconImage CGImageForProposedRect:nil context:context hints:nil];
156
     bubbleGraphic = [bubbleImage CGImageForProposedRect:nil context:context hints:nil];
173
     bubbleGraphic = [bubbleImage CGImageForProposedRect:nil context:context hints:nil];
174
+    alarmGraphic = [alarmImage CGImageForProposedRect:nil context:context hints:nil];
157
     eye0 = [eye0Image CGImageForProposedRect:nil context:context hints:nil];
175
     eye0 = [eye0Image CGImageForProposedRect:nil context:context hints:nil];
158
     eye1 = [eye1Image CGImageForProposedRect:nil context:context hints:nil];
176
     eye1 = [eye1Image CGImageForProposedRect:nil context:context hints:nil];
159
     eye2 = [eye2Image CGImageForProposedRect:nil context:context hints:nil];
177
     eye2 = [eye2Image CGImageForProposedRect:nil context:context hints:nil];
246
     alarmDigit1 = 8;
264
     alarmDigit1 = 8;
247
     alarmDigit2 = 8;
265
     alarmDigit2 = 8;
248
     alarmDigit3 = 8;
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
     return self;
275
     return self;
251
 }
276
 }
329
     CGContextDrawImage(drawContext, size, day);
354
     CGContextDrawImage(drawContext, size, day);
330
     
355
     
331
     // Draw Time
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
     // Draw Alarm Time
394
     // Draw Alarm Time
335
     size.size.width = FONT_SMALL_WIDTH;
395
     size.size.width = FONT_SMALL_WIDTH;

Loading…
Cancel
Save