Browse Source

Added alarm display, fixed memory leak

Thomas Buck 8 years ago
parent
commit
3b69e15e72
3 changed files with 50 additions and 13 deletions
  1. 1
    1
      OtaClock/Info.plist
  2. 2
    1
      OtaClock/MainWindow.m
  3. 47
    11
      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>198</string>
22
+	<string>215</string>
23 23
 	<key>LSApplicationCategoryType</key>
24 24
 	<string>public.app-category.utilities</string>
25 25
 	<key>LSMinimumSystemVersion</key>

+ 2
- 1
OtaClock/MainWindow.m View File

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

+ 47
- 11
OtaClock/Render.m View File

@@ -35,6 +35,12 @@
35 35
 #define FONT_SMALL_DATE_X2_OFFSET 17
36 36
 #define FONT_SMALL_DATE_X3_OFFSET 22
37 37
 
38
+#define FONT_SMALL_ALARM_Y_OFFSET 57
39
+#define FONT_SMALL_ALARM_X0_OFFSET 29
40
+#define FONT_SMALL_ALARM_X1_OFFSET 34
41
+#define FONT_SMALL_ALARM_X2_OFFSET 41
42
+#define FONT_SMALL_ALARM_X3_OFFSET 46
43
+
38 44
 @interface Render ()
39 45
 
40 46
 @property (assign) CGImageRef otaconGraphic, bubbleGraphic;
@@ -45,6 +51,7 @@
45 51
 
46 52
 @property (assign) NSInteger eyeToDraw, dayOfWeek;
47 53
 @property (assign) NSInteger dateDigit0, dateDigit1, dateDigit2, dateDigit3;
54
+@property (assign) NSInteger alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
48 55
 
49 56
 @property (assign) NSSize fullSize;
50 57
 @property (assign) CGContextRef drawContext;
@@ -63,6 +70,7 @@
63 70
 
64 71
 @synthesize eyeToDraw, dayOfWeek;
65 72
 @synthesize dateDigit0, dateDigit1, dateDigit2, dateDigit3;
73
+@synthesize alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
66 74
 
67 75
 @synthesize fullSize;
68 76
 @synthesize drawContext;
@@ -234,6 +242,10 @@
234 242
     dateDigit1 = 8;
235 243
     dateDigit2 = 8;
236 244
     dateDigit3 = 8;
245
+    alarmDigit0 = 8;
246
+    alarmDigit1 = 8;
247
+    alarmDigit2 = 8;
248
+    alarmDigit3 = 8;
237 249
     
238 250
     return self;
239 251
 }
@@ -268,11 +280,6 @@
268 280
         dateDigit2 = 0;
269 281
         dateDigit3 = [components day];
270 282
     }
271
-    
272
-    // Check if something changed, if so, set needsDisplay
273
-    // if (bla) {
274
-    //     parent.needsDisplay = YES;
275
-    // }
276 283
 }
277 284
 
278 285
 - (void)drawWithEye:(NSInteger)eyeIndex {
@@ -300,12 +307,18 @@
300 307
         size.origin.x = FONT_SMALL_DATE_X0_OFFSET;
301 308
         CGContextDrawImage(drawContext, size, fontSmall1);
302 309
     }
303
-    size.origin.x = FONT_SMALL_DATE_X1_OFFSET;
304
-    CGContextDrawImage(drawContext, size, [self smallHelper:dateDigit1]);
305
-    size.origin.x = FONT_SMALL_DATE_X2_OFFSET;
306
-    CGContextDrawImage(drawContext, size, [self smallHelper:dateDigit2]);
307
-    size.origin.x = FONT_SMALL_DATE_X3_OFFSET;
308
-    CGContextDrawImage(drawContext, size, [self smallHelper:dateDigit3]);
310
+    if ((dateDigit1 >= 0) && (dateDigit1 <= 9)) {
311
+        size.origin.x = FONT_SMALL_DATE_X1_OFFSET;
312
+        CGContextDrawImage(drawContext, size, [self smallHelper:dateDigit1]);
313
+    }
314
+    if ((dateDigit2 >= 0) && (dateDigit2 <= 9)) {
315
+        size.origin.x = FONT_SMALL_DATE_X2_OFFSET;
316
+        CGContextDrawImage(drawContext, size, [self smallHelper:dateDigit2]);
317
+    }
318
+    if ((dateDigit3 >= 0) && (dateDigit3 <= 9)) {
319
+        size.origin.x = FONT_SMALL_DATE_X3_OFFSET;
320
+        CGContextDrawImage(drawContext, size, [self smallHelper:dateDigit3]);
321
+    }
309 322
 
310 323
     // Draw Day of Week
311 324
     CGImageRef day = [self dayHelper:dayOfWeek];
@@ -317,6 +330,28 @@
317 330
     
318 331
     // Draw Time
319 332
     
333
+    
334
+    // Draw Alarm Time
335
+    size.size.width = FONT_SMALL_WIDTH;
336
+    size.size.height = FONT_SMALL_HEIGHT;
337
+    size.origin.y = FONT_SMALL_ALARM_Y_OFFSET;
338
+    if ((alarmDigit0 >= 0) && (alarmDigit0 <= 9)) {
339
+        size.origin.x = FONT_SMALL_ALARM_X0_OFFSET;
340
+        CGContextDrawImage(drawContext, size, [self smallHelper:alarmDigit0]);
341
+    }
342
+    if ((alarmDigit1 >= 0) && (alarmDigit1 <= 9)) {
343
+        size.origin.x = FONT_SMALL_ALARM_X1_OFFSET;
344
+        CGContextDrawImage(drawContext, size, [self smallHelper:alarmDigit1]);
345
+    }
346
+    if ((alarmDigit2 >= 0) && (alarmDigit2 <= 9)) {
347
+        size.origin.x = FONT_SMALL_ALARM_X2_OFFSET;
348
+        CGContextDrawImage(drawContext, size, [self smallHelper:alarmDigit2]);
349
+    }
350
+    if ((alarmDigit3 >= 0) && (alarmDigit3 <= 9)) {
351
+        size.origin.x = FONT_SMALL_ALARM_X3_OFFSET;
352
+        CGContextDrawImage(drawContext, size, [self smallHelper:alarmDigit3]);
353
+    }
354
+    
320 355
     // Draw Otacon
321 356
     size.size.width = CGImageGetWidth(otaconGraphic);
322 357
     size.size.height = CGImageGetHeight(otaconGraphic);
@@ -335,6 +370,7 @@
335 370
     CGImageRef drawnImage = CGBitmapContextCreateImage(drawContext);
336 371
     NSImage *result = [[NSImage alloc] initWithCGImage:drawnImage size:fullSize];
337 372
     [result drawInRect:[view bounds] fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:NO hints:[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:NSImageInterpolationNone] forKey:NSImageHintInterpolation]];
373
+    CGImageRelease(drawnImage);
338 374
 }
339 375
 
340 376
 @end

Loading…
Cancel
Save