|
@@ -6,6 +6,7 @@
|
6
|
6
|
// Copyright (c) 2015 xythobuz. All rights reserved.
|
7
|
7
|
//
|
8
|
8
|
|
|
9
|
+#import "MainView.h"
|
9
|
10
|
#import "Render.h"
|
10
|
11
|
|
11
|
12
|
#define FULL_IMAGE_WIDTH 86
|
|
@@ -15,25 +16,36 @@
|
15
|
16
|
#define EYE_X_OFFSET 60
|
16
|
17
|
#define EYE_Y_OFFSET 45
|
17
|
18
|
|
|
19
|
+#define FONT_DAYS_WIDTH 17
|
|
20
|
+#define FONT_DAYS_HEIGHT 3
|
|
21
|
+#define FONT_DAYS_PADDING 1
|
|
22
|
+#define FONT_DAYS_X_OFFSET 31
|
|
23
|
+#define FONT_DAYS_Y_OFFSET 72
|
|
24
|
+
|
18
|
25
|
@interface Render ()
|
19
|
26
|
|
20
|
|
-@property (assign) CGImageRef otaconGraphic;
|
21
|
|
-@property (assign) CGImageRef bubbleGraphic;
|
|
27
|
+@property (assign) CGImageRef otaconGraphic, bubbleGraphic;
|
22
|
28
|
@property (assign) CGImageRef eye0, eye1, eye2, eye3, eye4;
|
|
29
|
+@property (assign) CGImageRef fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
|
|
30
|
+@property (assign) NSInteger eyeToDraw, dayOfWeek;
|
23
|
31
|
|
24
|
32
|
@property (assign) NSSize fullSize;
|
25
|
33
|
@property (assign) CGContextRef drawContext;
|
26
|
34
|
|
|
35
|
+@property (weak) MainView *parent;
|
|
36
|
+
|
27
|
37
|
@end
|
28
|
38
|
|
29
|
39
|
@implementation Render
|
30
|
40
|
|
31
|
|
-@synthesize otaconGraphic;
|
32
|
|
-@synthesize bubbleGraphic;
|
|
41
|
+@synthesize otaconGraphic, bubbleGraphic;
|
33
|
42
|
@synthesize eye0, eye1, eye2, eye3, eye4;
|
|
43
|
+@synthesize fontMonday, fontTuesday, fontWednesday, fontThursday, fontFriday, fontSaturday, fontSunday;
|
|
44
|
+@synthesize eyeToDraw, dayOfWeek;
|
34
|
45
|
|
35
|
46
|
@synthesize fullSize;
|
36
|
47
|
@synthesize drawContext;
|
|
48
|
+@synthesize parent;
|
37
|
49
|
|
38
|
50
|
- (CGImageRef)eyeHelper:(NSInteger)index {
|
39
|
51
|
if (index == 0) return eye0;
|
|
@@ -46,10 +58,26 @@
|
46
|
58
|
return eye0;
|
47
|
59
|
}
|
48
|
60
|
|
49
|
|
-- (id)init {
|
|
61
|
+- (CGImageRef)dayHelper:(NSInteger)index {
|
|
62
|
+ if (index == -1) return fontSunday;
|
|
63
|
+ if (index == 0) return fontMonday;
|
|
64
|
+ if (index == 1) return fontTuesday;
|
|
65
|
+ if (index == 2) return fontWednesday;
|
|
66
|
+ if (index == 3) return fontThursday;
|
|
67
|
+ if (index == 4) return fontFriday;
|
|
68
|
+ if (index == 5) return fontSaturday;
|
|
69
|
+ if (index == 6) return fontSunday;
|
|
70
|
+
|
|
71
|
+ NSLog(@"Render:dayHelper:%ld unknown index!", (long)index);
|
|
72
|
+ return fontMonday;
|
|
73
|
+}
|
|
74
|
+
|
|
75
|
+- (id)initWithParent:(MainView *)par {
|
50
|
76
|
self = [super init];
|
51
|
77
|
if (self == nil) return nil;
|
52
|
78
|
|
|
79
|
+ parent = par;
|
|
80
|
+
|
53
|
81
|
NSImage *otaconImage = [NSImage imageNamed:@"otacon"];
|
54
|
82
|
NSImage *bubbleImage = [NSImage imageNamed:@"bubble"];
|
55
|
83
|
NSImage *eye0Image = [NSImage imageNamed:@"eyes_0"];
|
|
@@ -57,6 +85,7 @@
|
57
|
85
|
NSImage *eye2Image = [NSImage imageNamed:@"eyes_2"];
|
58
|
86
|
NSImage *eye3Image = [NSImage imageNamed:@"eyes_3"];
|
59
|
87
|
NSImage *eye4Image = [NSImage imageNamed:@"eyes_4"];
|
|
88
|
+ NSImage *fontDaysImage = [NSImage imageNamed:@"font_days"];
|
60
|
89
|
|
61
|
90
|
NSGraphicsContext *context = [NSGraphicsContext graphicsContextWithAttributes:nil];
|
62
|
91
|
|
|
@@ -68,11 +97,34 @@
|
68
|
97
|
eye3 = [eye3Image CGImageForProposedRect:nil context:context hints:nil];
|
69
|
98
|
eye4 = [eye4Image CGImageForProposedRect:nil context:context hints:nil];
|
70
|
99
|
|
|
100
|
+ CGImageRef fontDays = [fontDaysImage CGImageForProposedRect:nil context:context hints:nil];
|
|
101
|
+ NSRect rectDay;
|
|
102
|
+ rectDay.size.width = FONT_DAYS_WIDTH;
|
|
103
|
+ rectDay.size.height = FONT_DAYS_HEIGHT;
|
|
104
|
+ rectDay.origin.x = 0;
|
|
105
|
+ rectDay.origin.y = 0;
|
|
106
|
+ fontMonday = CGImageCreateWithImageInRect(fontDays, rectDay);
|
|
107
|
+ rectDay.origin.y += FONT_DAYS_HEIGHT + FONT_DAYS_PADDING;
|
|
108
|
+ fontTuesday = CGImageCreateWithImageInRect(fontDays, rectDay);
|
|
109
|
+ rectDay.origin.y += FONT_DAYS_HEIGHT + FONT_DAYS_PADDING;
|
|
110
|
+ fontWednesday = CGImageCreateWithImageInRect(fontDays, rectDay);
|
|
111
|
+ rectDay.origin.y += FONT_DAYS_HEIGHT + FONT_DAYS_PADDING;
|
|
112
|
+ fontThursday = CGImageCreateWithImageInRect(fontDays, rectDay);
|
|
113
|
+ rectDay.origin.y += FONT_DAYS_HEIGHT + FONT_DAYS_PADDING;
|
|
114
|
+ fontFriday = CGImageCreateWithImageInRect(fontDays, rectDay);
|
|
115
|
+ rectDay.origin.y += FONT_DAYS_HEIGHT + FONT_DAYS_PADDING;
|
|
116
|
+ fontSaturday = CGImageCreateWithImageInRect(fontDays, rectDay);
|
|
117
|
+ rectDay.origin.y += FONT_DAYS_HEIGHT + FONT_DAYS_PADDING;
|
|
118
|
+ fontSunday = CGImageCreateWithImageInRect(fontDays, rectDay);
|
|
119
|
+
|
71
|
120
|
fullSize.width = FULL_IMAGE_WIDTH;
|
72
|
121
|
fullSize.height = FULL_IMAGE_HEIGHT;
|
73
|
122
|
|
74
|
123
|
drawContext = CGBitmapContextCreate(NULL, fullSize.width, fullSize.height, 8, 0, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast | kCGBitmapByteOrderDefault);
|
75
|
124
|
|
|
125
|
+ eyeToDraw = 0;
|
|
126
|
+ dayOfWeek = 0;
|
|
127
|
+
|
76
|
128
|
return self;
|
77
|
129
|
}
|
78
|
130
|
|
|
@@ -80,10 +132,24 @@
|
80
|
132
|
return fullSize;
|
81
|
133
|
}
|
82
|
134
|
|
83
|
|
-- (void)drawWith:(NSInteger)eyeIndex {
|
84
|
|
- CGRect size;
|
|
135
|
+- (void)drawWithDate:(NSDate *)date {
|
|
136
|
+ NSDateComponents *components = [[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:date];
|
|
137
|
+ dayOfWeek = [components weekday] - 2;
|
85
|
138
|
|
|
139
|
+
|
|
140
|
+ // Check if something changed, if so, set needsDisplay
|
|
141
|
+ // if (bla) {
|
|
142
|
+ // parent.needsDisplay = YES;
|
|
143
|
+ // }
|
|
144
|
+}
|
|
145
|
+
|
|
146
|
+- (void)drawWithEye:(NSInteger)eyeIndex {
|
|
147
|
+ eyeToDraw = eyeIndex;
|
|
148
|
+}
|
|
149
|
+
|
|
150
|
+- (void)drawInto:(NSView *)view {
|
86
|
151
|
// Clear entire canvas
|
|
152
|
+ CGRect size;
|
87
|
153
|
size.size = fullSize;
|
88
|
154
|
size.origin = NSZeroPoint;
|
89
|
155
|
CGContextClearRect(drawContext, size);
|
|
@@ -94,6 +160,18 @@
|
94
|
160
|
size.origin.y = BUBBLE_Y_OFFSET;
|
95
|
161
|
CGContextDrawImage(drawContext, size, bubbleGraphic);
|
96
|
162
|
|
|
163
|
+ // Draw Date
|
|
164
|
+
|
|
165
|
+ // Draw Day of Week
|
|
166
|
+ CGImageRef day = [self dayHelper:dayOfWeek];
|
|
167
|
+ size.size.width = FONT_DAYS_WIDTH;
|
|
168
|
+ size.size.height = FONT_DAYS_HEIGHT;
|
|
169
|
+ size.origin.x = FONT_DAYS_X_OFFSET;
|
|
170
|
+ size.origin.y = FONT_DAYS_Y_OFFSET;
|
|
171
|
+ CGContextDrawImage(drawContext, size, day);
|
|
172
|
+
|
|
173
|
+ // Draw Time
|
|
174
|
+
|
97
|
175
|
// Draw Otacon
|
98
|
176
|
size.size.width = CGImageGetWidth(otaconGraphic);
|
99
|
177
|
size.size.height = CGImageGetHeight(otaconGraphic);
|
|
@@ -102,14 +180,13 @@
|
102
|
180
|
CGContextDrawImage(drawContext, size, otaconGraphic);
|
103
|
181
|
|
104
|
182
|
// Draw eyes
|
105
|
|
- size.size.width = CGImageGetWidth([self eyeHelper:eyeIndex]);
|
106
|
|
- size.size.height = CGImageGetHeight([self eyeHelper:eyeIndex]);
|
|
183
|
+ size.size.width = CGImageGetWidth([self eyeHelper:eyeToDraw]);
|
|
184
|
+ size.size.height = CGImageGetHeight([self eyeHelper:eyeToDraw]);
|
107
|
185
|
size.origin.x = EYE_X_OFFSET;
|
108
|
186
|
size.origin.y = EYE_Y_OFFSET;
|
109
|
|
- CGContextDrawImage(drawContext, size, [self eyeHelper:eyeIndex]);
|
110
|
|
-}
|
111
|
|
-
|
112
|
|
-- (void)drawInto:(NSView *)view {
|
|
187
|
+ CGContextDrawImage(drawContext, size, [self eyeHelper:eyeToDraw]);
|
|
188
|
+
|
|
189
|
+ // Render resulting canvas into bitmap and scale this into our window
|
113
|
190
|
CGImageRef drawnImage = CGBitmapContextCreateImage(drawContext);
|
114
|
191
|
NSImage *result = [[NSImage alloc] initWithCGImage:drawnImage size:fullSize];
|
115
|
192
|
[result drawInRect:[view bounds] fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0 respectFlipped:NO hints:[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:NSImageInterpolationNone] forKey:NSImageHintInterpolation]];
|