Browse Source

Added alarm display, fixed memory leak

Thomas Buck 9 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
 	<key>CFBundleSignature</key>
19
 	<key>CFBundleSignature</key>
20
 	<string>????</string>
20
 	<string>????</string>
21
 	<key>CFBundleVersion</key>
21
 	<key>CFBundleVersion</key>
22
-	<string>198</string>
22
+	<string>215</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
- 1
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]];
131
+    //[[self.mainView render] drawWithDate:[NSDate date]];
132
+    //self.mainView.needsDisplay = YES;
132
 }
133
 }
133
 
134
 
134
 - (void)blink {
135
 - (void)blink {

+ 47
- 11
OtaClock/Render.m View File

35
 #define FONT_SMALL_DATE_X2_OFFSET 17
35
 #define FONT_SMALL_DATE_X2_OFFSET 17
36
 #define FONT_SMALL_DATE_X3_OFFSET 22
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
 @interface Render ()
44
 @interface Render ()
39
 
45
 
40
 @property (assign) CGImageRef otaconGraphic, bubbleGraphic;
46
 @property (assign) CGImageRef otaconGraphic, bubbleGraphic;
45
 
51
 
46
 @property (assign) NSInteger eyeToDraw, dayOfWeek;
52
 @property (assign) NSInteger eyeToDraw, dayOfWeek;
47
 @property (assign) NSInteger dateDigit0, dateDigit1, dateDigit2, dateDigit3;
53
 @property (assign) NSInteger dateDigit0, dateDigit1, dateDigit2, dateDigit3;
54
+@property (assign) NSInteger alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
48
 
55
 
49
 @property (assign) NSSize fullSize;
56
 @property (assign) NSSize fullSize;
50
 @property (assign) CGContextRef drawContext;
57
 @property (assign) CGContextRef drawContext;
63
 
70
 
64
 @synthesize eyeToDraw, dayOfWeek;
71
 @synthesize eyeToDraw, dayOfWeek;
65
 @synthesize dateDigit0, dateDigit1, dateDigit2, dateDigit3;
72
 @synthesize dateDigit0, dateDigit1, dateDigit2, dateDigit3;
73
+@synthesize alarmDigit0, alarmDigit1, alarmDigit2, alarmDigit3;
66
 
74
 
67
 @synthesize fullSize;
75
 @synthesize fullSize;
68
 @synthesize drawContext;
76
 @synthesize drawContext;
234
     dateDigit1 = 8;
242
     dateDigit1 = 8;
235
     dateDigit2 = 8;
243
     dateDigit2 = 8;
236
     dateDigit3 = 8;
244
     dateDigit3 = 8;
245
+    alarmDigit0 = 8;
246
+    alarmDigit1 = 8;
247
+    alarmDigit2 = 8;
248
+    alarmDigit3 = 8;
237
     
249
     
238
     return self;
250
     return self;
239
 }
251
 }
268
         dateDigit2 = 0;
280
         dateDigit2 = 0;
269
         dateDigit3 = [components day];
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
 - (void)drawWithEye:(NSInteger)eyeIndex {
285
 - (void)drawWithEye:(NSInteger)eyeIndex {
300
         size.origin.x = FONT_SMALL_DATE_X0_OFFSET;
307
         size.origin.x = FONT_SMALL_DATE_X0_OFFSET;
301
         CGContextDrawImage(drawContext, size, fontSmall1);
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
     // Draw Day of Week
323
     // Draw Day of Week
311
     CGImageRef day = [self dayHelper:dayOfWeek];
324
     CGImageRef day = [self dayHelper:dayOfWeek];
317
     
330
     
318
     // Draw Time
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
     // Draw Otacon
355
     // Draw Otacon
321
     size.size.width = CGImageGetWidth(otaconGraphic);
356
     size.size.width = CGImageGetWidth(otaconGraphic);
322
     size.size.height = CGImageGetHeight(otaconGraphic);
357
     size.size.height = CGImageGetHeight(otaconGraphic);
335
     CGImageRef drawnImage = CGBitmapContextCreateImage(drawContext);
370
     CGImageRef drawnImage = CGBitmapContextCreateImage(drawContext);
336
     NSImage *result = [[NSImage alloc] initWithCGImage:drawnImage size:fullSize];
371
     NSImage *result = [[NSImage alloc] initWithCGImage:drawnImage size:fullSize];
337
     [result drawInRect:[view bounds] fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:NO hints:[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:NSImageInterpolationNone] forKey:NSImageHintInterpolation]];
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
 @end
376
 @end

Loading…
Cancel
Save