Browse Source

Now reading all fonts, splitting them and displaying the current date

Thomas Buck 9 years ago
parent
commit
cf28f1f1f8

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


BIN
OtaClock/Images.xcassets/font_small.imageset/font_small.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>162</string>
22
+	<string>198</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>

+ 148
- 3
OtaClock/Render.m View File

22
 #define FONT_DAYS_X_OFFSET 31
22
 #define FONT_DAYS_X_OFFSET 31
23
 #define FONT_DAYS_Y_OFFSET 72
23
 #define FONT_DAYS_Y_OFFSET 72
24
 
24
 
25
+#define FONT_LARGE_WIDTH 6
26
+#define FONT_LARGE_HEIGHT 7
27
+#define FONT_LARGE_PADDING 1
28
+
29
+#define FONT_SMALL_WIDTH 4
30
+#define FONT_SMALL_HEIGHT 5
31
+#define FONT_SMALL_PADDING 1
32
+#define FONT_SMALL_DATE_Y_OFFSET 71
33
+#define FONT_SMALL_DATE_X0_OFFSET 3
34
+#define FONT_SMALL_DATE_X1_OFFSET 8
35
+#define FONT_SMALL_DATE_X2_OFFSET 17
36
+#define FONT_SMALL_DATE_X3_OFFSET 22
37
+
25
 @interface Render ()
38
 @interface Render ()
26
 
39
 
27
 @property (assign) CGImageRef otaconGraphic, bubbleGraphic;
40
 @property (assign) CGImageRef otaconGraphic, bubbleGraphic;
28
 @property (assign) CGImageRef eye0, eye1, eye2, eye3, eye4;
41
 @property (assign) CGImageRef eye0, eye1, eye2, eye3, eye4;
29
 @property (assign) CGImageRef fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
42
 @property (assign) CGImageRef fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
43
+@property (assign) CGImageRef fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
44
+@property (assign) CGImageRef fontLarge1, fontLarge2, fontLarge3, fontLarge4, fontLarge5, fontLarge6, fontLarge7, fontLarge8, fontLarge9, fontLarge0;
45
+
30
 @property (assign) NSInteger eyeToDraw, dayOfWeek;
46
 @property (assign) NSInteger eyeToDraw, dayOfWeek;
47
+@property (assign) NSInteger dateDigit0, dateDigit1, dateDigit2, dateDigit3;
31
 
48
 
32
 @property (assign) NSSize fullSize;
49
 @property (assign) NSSize fullSize;
33
 @property (assign) CGContextRef drawContext;
50
 @property (assign) CGContextRef drawContext;
41
 @synthesize otaconGraphic, bubbleGraphic;
58
 @synthesize otaconGraphic, bubbleGraphic;
42
 @synthesize eye0, eye1, eye2, eye3, eye4;
59
 @synthesize eye0, eye1, eye2, eye3, eye4;
43
 @synthesize fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
60
 @synthesize fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
61
+@synthesize fontSmall1, fontSmall2, fontSmall3, fontSmall4, fontSmall5, fontSmall6, fontSmall7, fontSmall8, fontSmall9, fontSmall0;
62
+@synthesize fontLarge1, fontLarge2, fontLarge3, fontLarge4, fontLarge5, fontLarge6, fontLarge7, fontLarge8, fontLarge9, fontLarge0;
63
+
44
 @synthesize eyeToDraw, dayOfWeek;
64
 @synthesize eyeToDraw, dayOfWeek;
65
+@synthesize dateDigit0, dateDigit1, dateDigit2, dateDigit3;
45
 
66
 
46
 @synthesize fullSize;
67
 @synthesize fullSize;
47
 @synthesize drawContext;
68
 @synthesize drawContext;
72
     return fontMonday;
93
     return fontMonday;
73
 }
94
 }
74
 
95
 
96
+- (CGImageRef)smallHelper:(NSInteger)index {
97
+    if (index == 0) return fontSmall0;
98
+    if (index == 1) return fontSmall1;
99
+    if (index == 2) return fontSmall2;
100
+    if (index == 3) return fontSmall3;
101
+    if (index == 4) return fontSmall4;
102
+    if (index == 5) return fontSmall5;
103
+    if (index == 6) return fontSmall6;
104
+    if (index == 7) return fontSmall7;
105
+    if (index == 8) return fontSmall8;
106
+    if (index == 9) return fontSmall9;
107
+    
108
+    NSLog(@"Render:smallHelper:%ld unknown index!", (long)index);
109
+    return fontSmall0;
110
+}
111
+
112
+- (CGImageRef)largeHelper:(NSInteger)index {
113
+    if (index == 0) return fontLarge0;
114
+    if (index == 1) return fontLarge1;
115
+    if (index == 2) return fontLarge2;
116
+    if (index == 3) return fontLarge3;
117
+    if (index == 4) return fontLarge4;
118
+    if (index == 5) return fontLarge5;
119
+    if (index == 6) return fontLarge6;
120
+    if (index == 7) return fontLarge7;
121
+    if (index == 8) return fontLarge8;
122
+    if (index == 9) return fontLarge9;
123
+    
124
+    NSLog(@"Render:largeHelper:%ld unknown index!", (long)index);
125
+    return fontLarge0;
126
+}
127
+
75
 - (id)initWithParent:(MainView *)par {
128
 - (id)initWithParent:(MainView *)par {
76
     self = [super init];
129
     self = [super init];
77
     if (self == nil) return nil;
130
     if (self == nil) return nil;
86
     NSImage *eye3Image = [NSImage imageNamed:@"eyes_3"];
139
     NSImage *eye3Image = [NSImage imageNamed:@"eyes_3"];
87
     NSImage *eye4Image = [NSImage imageNamed:@"eyes_4"];
140
     NSImage *eye4Image = [NSImage imageNamed:@"eyes_4"];
88
     NSImage *fontDaysImage = [NSImage imageNamed:@"font_days"];
141
     NSImage *fontDaysImage = [NSImage imageNamed:@"font_days"];
142
+    NSImage *fontSmallImage = [NSImage imageNamed:@"font_small"];
143
+    NSImage *fontLargeImage = [NSImage imageNamed:@"font_large"];
89
     
144
     
90
     NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithAttributes:nil];
145
     NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithAttributes:nil];
91
     
146
     
117
     rectDay.origin.y += FONT_DAYS_HEIGHT + FONT_DAYS_PADDING;
172
     rectDay.origin.y += FONT_DAYS_HEIGHT + FONT_DAYS_PADDING;
118
     fontSunday = CGImageCreateWithImageInRect(fontDays, rectDay);
173
     fontSunday = CGImageCreateWithImageInRect(fontDays, rectDay);
119
     
174
     
175
+    NSRect rect;
176
+    CGImageRef fontSmall = [fontSmallImage CGImageForProposedRect:nil context:context hints:nil];
177
+    rect.size.width = FONT_SMALL_WIDTH;
178
+    rect.size.height = FONT_SMALL_HEIGHT;
179
+    rect.origin.x = 0;
180
+    rect.origin.y = 0;
181
+    fontSmall0 = CGImageCreateWithImageInRect(fontSmall, rect);
182
+    rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
183
+    fontSmall1 = CGImageCreateWithImageInRect(fontSmall, rect);
184
+    rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
185
+    fontSmall2 = CGImageCreateWithImageInRect(fontSmall, rect);
186
+    rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
187
+    fontSmall3 = CGImageCreateWithImageInRect(fontSmall, rect);
188
+    rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
189
+    fontSmall4 = CGImageCreateWithImageInRect(fontSmall, rect);
190
+    rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
191
+    fontSmall5 = CGImageCreateWithImageInRect(fontSmall, rect);
192
+    rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
193
+    fontSmall6 = CGImageCreateWithImageInRect(fontSmall, rect);
194
+    rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
195
+    fontSmall7 = CGImageCreateWithImageInRect(fontSmall, rect);
196
+    rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
197
+    fontSmall8 = CGImageCreateWithImageInRect(fontSmall, rect);
198
+    rect.origin.x += FONT_SMALL_WIDTH + FONT_SMALL_PADDING;
199
+    fontSmall9 = CGImageCreateWithImageInRect(fontSmall, rect);
200
+    
201
+    CGImageRef fontLarge = [fontLargeImage CGImageForProposedRect:nil context:context hints:nil];
202
+    rect.size.width = FONT_LARGE_WIDTH;
203
+    rect.size.height = FONT_LARGE_HEIGHT;
204
+    rect.origin.x = 0;
205
+    rect.origin.y = 0;
206
+    fontLarge0 = CGImageCreateWithImageInRect(fontLarge, rect);
207
+    rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
208
+    fontLarge1 = CGImageCreateWithImageInRect(fontLarge, rect);
209
+    rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
210
+    fontLarge2 = CGImageCreateWithImageInRect(fontLarge, rect);
211
+    rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
212
+    fontLarge3 = CGImageCreateWithImageInRect(fontLarge, rect);
213
+    rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
214
+    fontLarge4 = CGImageCreateWithImageInRect(fontLarge, rect);
215
+    rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
216
+    fontLarge5 = CGImageCreateWithImageInRect(fontLarge, rect);
217
+    rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
218
+    fontLarge6 = CGImageCreateWithImageInRect(fontLarge, rect);
219
+    rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
220
+    fontLarge7 = CGImageCreateWithImageInRect(fontLarge, rect);
221
+    rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
222
+    fontLarge8 = CGImageCreateWithImageInRect(fontLarge, rect);
223
+    rect.origin.x += FONT_LARGE_WIDTH + FONT_LARGE_PADDING;
224
+    fontLarge9 = CGImageCreateWithImageInRect(fontLarge, rect);
225
+    
120
     fullSize.width = FULL_IMAGE_WIDTH;
226
     fullSize.width = FULL_IMAGE_WIDTH;
121
     fullSize.height = FULL_IMAGE_HEIGHT;
227
     fullSize.height = FULL_IMAGE_HEIGHT;
122
     
228
     
124
     
230
     
125
     eyeToDraw = 0;
231
     eyeToDraw = 0;
126
     dayOfWeek = 0;
232
     dayOfWeek = 0;
233
+    dateDigit0 = 1;
234
+    dateDigit1 = 8;
235
+    dateDigit2 = 8;
236
+    dateDigit3 = 8;
127
     
237
     
128
     return self;
238
     return self;
129
 }
239
 }
133
 }
243
 }
134
 
244
 
135
 - (void)drawWithDate:(NSDate *)date {
245
 - (void)drawWithDate:(NSDate *)date {
136
-    NSDateComponents *components = [[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:date];
137
-    dayOfWeek = [components weekday] - 2;
246
+    NSCalendarUnit comps = NSWeekdayCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
247
+    NSDateComponents *components = [[NSCalendar currentCalendar] components:comps fromDate:date];
248
+    dayOfWeek = [components weekday] - 2; // map sun=1 to sun=-1
138
     
249
     
250
+    if ([components month] >= 10) {
251
+        dateDigit0 = 1;
252
+        dateDigit1 = [components month] - 10;
253
+    } else {
254
+        dateDigit0 = 0;
255
+        dateDigit1 = [components month];
256
+    }
257
+    
258
+    if ([components day] >= 30) {
259
+        dateDigit2 = 3;
260
+        dateDigit3 = [components day] - 30;
261
+    } else if ([components day] >= 20) {
262
+        dateDigit2 = 2;
263
+        dateDigit3 = [components day] - 20;
264
+    } else if ([components day] >= 10) {
265
+        dateDigit2 = 1;
266
+        dateDigit3 = [components day] - 10;
267
+    } else {
268
+        dateDigit2 = 0;
269
+        dateDigit3 = [components day];
270
+    }
139
     
271
     
140
     // Check if something changed, if so, set needsDisplay
272
     // Check if something changed, if so, set needsDisplay
141
     // if (bla) {
273
     // if (bla) {
159
     size.size.height = CGImageGetHeight(bubbleGraphic);
291
     size.size.height = CGImageGetHeight(bubbleGraphic);
160
     size.origin.y = BUBBLE_Y_OFFSET;
292
     size.origin.y = BUBBLE_Y_OFFSET;
161
     CGContextDrawImage(drawContext, size, bubbleGraphic);
293
     CGContextDrawImage(drawContext, size, bubbleGraphic);
162
-    
294
+
163
     // Draw Date
295
     // Draw Date
296
+    size.size.width = FONT_SMALL_WIDTH;
297
+    size.size.height = FONT_SMALL_HEIGHT;
298
+    size.origin.y = FONT_SMALL_DATE_Y_OFFSET;
299
+    if (dateDigit0 == 1) {
300
+        size.origin.x = FONT_SMALL_DATE_X0_OFFSET;
301
+        CGContextDrawImage(drawContext, size, fontSmall1);
302
+    }
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]);
164
 
309
 
165
     // Draw Day of Week
310
     // Draw Day of Week
166
     CGImageRef day = [self dayHelper:dayOfWeek];
311
     CGImageRef day = [self dayHelper:dayOfWeek];

Loading…
Cancel
Save