|
@@ -22,12 +22,29 @@
|
22
|
22
|
#define FONT_DAYS_X_OFFSET 31
|
23
|
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
|
38
|
@interface Render ()
|
26
|
39
|
|
27
|
40
|
@property (assign) CGImageRef otaconGraphic, bubbleGraphic;
|
28
|
41
|
@property (assign) CGImageRef eye0, eye1, eye2, eye3, eye4;
|
29
|
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
|
46
|
@property (assign) NSInteger eyeToDraw, dayOfWeek;
|
|
47
|
+@property (assign) NSInteger dateDigit0, dateDigit1, dateDigit2, dateDigit3;
|
31
|
48
|
|
32
|
49
|
@property (assign) NSSize fullSize;
|
33
|
50
|
@property (assign) CGContextRef drawContext;
|
|
@@ -41,7 +58,11 @@
|
41
|
58
|
@synthesize otaconGraphic, bubbleGraphic;
|
42
|
59
|
@synthesize eye0, eye1, eye2, eye3, eye4;
|
43
|
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
|
64
|
@synthesize eyeToDraw, dayOfWeek;
|
|
65
|
+@synthesize dateDigit0, dateDigit1, dateDigit2, dateDigit3;
|
45
|
66
|
|
46
|
67
|
@synthesize fullSize;
|
47
|
68
|
@synthesize drawContext;
|
|
@@ -72,6 +93,38 @@
|
72
|
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
|
128
|
- (id)initWithParent:(MainView *)par {
|
76
|
129
|
self = [super init];
|
77
|
130
|
if (self == nil) return nil;
|
|
@@ -86,6 +139,8 @@
|
86
|
139
|
NSImage *eye3Image = [NSImage imageNamed:@"eyes_3"];
|
87
|
140
|
NSImage *eye4Image = [NSImage imageNamed:@"eyes_4"];
|
88
|
141
|
NSImage *fontDaysImage = [NSImage imageNamed:@"font_days"];
|
|
142
|
+ NSImage *fontSmallImage = [NSImage imageNamed:@"font_small"];
|
|
143
|
+ NSImage *fontLargeImage = [NSImage imageNamed:@"font_large"];
|
89
|
144
|
|
90
|
145
|
NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithAttributes:nil];
|
91
|
146
|
|
|
@@ -117,6 +172,57 @@
|
117
|
172
|
rectDay.origin.y += FONT_DAYS_HEIGHT + FONT_DAYS_PADDING;
|
118
|
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
|
226
|
fullSize.width = FULL_IMAGE_WIDTH;
|
121
|
227
|
fullSize.height = FULL_IMAGE_HEIGHT;
|
122
|
228
|
|
|
@@ -124,6 +230,10 @@
|
124
|
230
|
|
125
|
231
|
eyeToDraw = 0;
|
126
|
232
|
dayOfWeek = 0;
|
|
233
|
+ dateDigit0 = 1;
|
|
234
|
+ dateDigit1 = 8;
|
|
235
|
+ dateDigit2 = 8;
|
|
236
|
+ dateDigit3 = 8;
|
127
|
237
|
|
128
|
238
|
return self;
|
129
|
239
|
}
|
|
@@ -133,9 +243,31 @@
|
133
|
243
|
}
|
134
|
244
|
|
135
|
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
|
272
|
// Check if something changed, if so, set needsDisplay
|
141
|
273
|
// if (bla) {
|
|
@@ -159,8 +291,21 @@
|
159
|
291
|
size.size.height = CGImageGetHeight(bubbleGraphic);
|
160
|
292
|
size.origin.y = BUBBLE_Y_OFFSET;
|
161
|
293
|
CGContextDrawImage(drawContext, size, bubbleGraphic);
|
162
|
|
-
|
|
294
|
+
|
163
|
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
|
310
|
// Draw Day of Week
|
166
|
311
|
CGImageRef day = [self dayHelper:dayOfWeek];
|