12
12
#define NSFont UIFont
13
13
#endif
14
14
15
- @implementation FaceScene
16
-
17
- BOOL vectorDisplay = YES ;
15
+ CGFloat workingRadiusForFaceOfSizeWithAngle (CGSize faceSize, CGFloat angle)
16
+ {
17
+ CGFloat faceHeight = faceSize.height ;
18
+ CGFloat faceWidth = faceSize.width ;
19
+
20
+ CGFloat workingRadius = 0 ;
21
+
22
+ double vx = cos (angle);
23
+ double vy = sin (angle);
24
+
25
+ double x1 = 0 ;
26
+ double y1 = 0 ;
27
+ double x2 = faceHeight;
28
+ double y2 = faceWidth;
29
+ double px = faceHeight/2 ;
30
+ double py = faceWidth/2 ;
31
+
32
+ double t[4 ];
33
+ double smallestT = 1000 ;
34
+
35
+ t[0 ]=(x1-px)/vx;
36
+ t[1 ]=(x2-px)/vx;
37
+ t[2 ]=(y1-py)/vy;
38
+ t[3 ]=(y2-py)/vy;
39
+
40
+ for (int m = 0 ; m < 4 ; m++)
41
+ {
42
+ double currentT = t[m];
43
+
44
+ if (currentT > 0 && currentT < smallestT)
45
+ smallestT = currentT;
46
+ }
47
+
48
+ workingRadius = smallestT;
49
+
50
+ return workingRadius;
51
+ }
18
52
19
- // 184 x 224
53
+ @implementation FaceScene
20
54
21
55
- (instancetype )initWithCoder : (NSCoder *)coder
22
56
{
23
57
self = [super initWithCoder: coder];
24
58
if (self) {
25
59
26
60
self.theme = ThemeHermesPink;
61
+ self.useProgrammaticLayout = YES ;
62
+ self.useRoundFace = YES ;
27
63
28
64
[self setupColors ];
29
65
[self setupScene ];
@@ -33,21 +69,21 @@ - (instancetype)initWithCoder:(NSCoder *)coder
33
69
return self;
34
70
}
35
71
36
- -(void )setupTickmarks
72
+ -(void )setupTickmarksForRoundFace
37
73
{
38
74
CGFloat margin = 4.0 ;
39
75
CGFloat labelMargin = 26.0 ;
40
76
41
77
SKNode *faceMarkings = [SKNode node ];
42
78
43
79
/* Hardcoded for 44mm Apple Watch */
44
- CGFloat faceWidth = 184 ;
45
- CGFloat faceHeight = 224 ;
46
-
80
+
81
+ CGSize faceSize = (CGSize){ 184 , 224 } ;
82
+
47
83
for (int i = 0 ; i < 12 ; i++)
48
84
{
49
85
CGFloat angle = -(2 *M_PI)/12.0 * i;
50
- CGFloat workingRadius = faceWidth /2 ;
86
+ CGFloat workingRadius = faceSize. width /2 ;
51
87
CGFloat longTickHeight = workingRadius/15 ;
52
88
53
89
SKSpriteNode *tick = [SKSpriteNode spriteNodeWithColor: self .markColor size: CGSizeMake (2 , longTickHeight)];
@@ -73,7 +109,7 @@ -(void)setupTickmarks
73
109
for (int i = 0 ; i < 60 ; i++)
74
110
{
75
111
CGFloat angle = - (2 *M_PI)/60.0 * i;
76
- CGFloat workingRadius = faceWidth /2 ;
112
+ CGFloat workingRadius = faceSize. width /2 ;
77
113
CGFloat shortTickHeight = workingRadius/20 ;
78
114
SKSpriteNode *tick = [SKSpriteNode spriteNodeWithColor: self .markColor size: CGSizeMake (1 , shortTickHeight)];
79
115
@@ -87,10 +123,81 @@ -(void)setupTickmarks
87
123
}
88
124
89
125
[self addChild: faceMarkings];
126
+ }
127
+
128
+ -(void )setupTickmarksForRectangularFace
129
+ {
130
+ CGFloat margin = 5.0 ;
131
+ CGFloat labelYMargin = 30.0 ;
132
+ CGFloat labelXMargin = 24.0 ;
133
+
134
+ CGSize faceSize = (CGSize){184 , 224 };
90
135
91
- SKNode *face = [self childNodeWithName: @" Face" ];
92
- SKSpriteNode *numbersLayer = (SKSpriteNode *)[face childNodeWithName: @" Numbers" ];
93
- numbersLayer.alpha = 0 ;
136
+ /* Major */
137
+ for (int i = 0 ; i < 12 ; i++)
138
+ {
139
+ CGFloat angle = -(2 *M_PI)/12.0 * i;
140
+ CGFloat workingRadius = workingRadiusForFaceOfSizeWithAngle (faceSize, angle);
141
+ CGFloat longTickHeight = workingRadius/10.0 ;
142
+
143
+ SKSpriteNode *tick = [SKSpriteNode spriteNodeWithColor: self .markColor size: CGSizeMake (2 , longTickHeight)];
144
+
145
+ tick.position = CGPointZero;
146
+ tick.anchorPoint = CGPointMake (0.5 , (workingRadius-margin)/longTickHeight);
147
+ tick.zRotation = angle;
148
+
149
+ tick.zPosition = 0 ;
150
+
151
+ [self addChild: tick];
152
+ }
153
+
154
+ /* Minor */
155
+ for (int i = 0 ; i < 60 ; i++)
156
+ {
157
+
158
+ CGFloat angle = - (2 *M_PI)/60.0 * i;
159
+ CGFloat workingRadius = workingRadiusForFaceOfSizeWithAngle (faceSize, angle);
160
+ CGFloat shortTickHeight = workingRadius/20 ;
161
+ SKSpriteNode *tick = [SKSpriteNode spriteNodeWithColor: self .markColor size: CGSizeMake (1 , shortTickHeight)];
162
+
163
+ tick.position = CGPointZero;
164
+ tick.anchorPoint = CGPointMake (0.5 , (workingRadius-margin)/shortTickHeight);
165
+ tick.zRotation = angle;
166
+
167
+ tick.zPosition = 0 ;
168
+ if (i % 5 != 0 )
169
+ [self addChild: tick];
170
+ }
171
+
172
+ /* Numerals */
173
+ for (int i = 1 ; i <= 12 ; i++)
174
+ {
175
+ CGFloat fontSize = 25 ;
176
+
177
+ SKSpriteNode *labelNode = [SKSpriteNode spriteNodeWithColor: [SKColor clearColor ] size: CGSizeMake (fontSize, fontSize)];
178
+ labelNode.anchorPoint = CGPointMake (0.5 ,0.5 );
179
+
180
+ if (i == 1 || i == 11 || i == 12 )
181
+ labelNode.position = CGPointMake (labelXMargin-faceSize.width /2 + ((i+1 )%3 ) * (faceSize.width -labelXMargin*2 )/3.0 + (faceSize.width -labelXMargin*2 )/6.0 , faceSize.height /2 -labelYMargin);
182
+ else if (i == 5 || i == 6 || i == 7 )
183
+ labelNode.position = CGPointMake (labelXMargin-faceSize.width /2 + (2 -((i+1 )%3 )) * (faceSize.width -labelXMargin*2 )/3.0 + (faceSize.width -labelXMargin*2 )/6.0 , -faceSize.height /2 +labelYMargin);
184
+ else if (i == 2 || i == 3 || i == 4 )
185
+ labelNode.position = CGPointMake (faceSize.height /2 -fontSize-labelXMargin, -(faceSize.width -labelXMargin*2 )/2 + (2 -((i+1 )%3 )) * (faceSize.width -labelXMargin*2 )/3.0 + (faceSize.width -labelYMargin*2 )/6.0 );
186
+ else if (i == 8 || i == 9 || i == 10 )
187
+ labelNode.position = CGPointMake (-faceSize.height /2 +fontSize+labelXMargin, -(faceSize.width -labelXMargin*2 )/2 + ((i+1 )%3 ) * (faceSize.width -labelXMargin*2 )/3.0 + (faceSize.width -labelYMargin*2 )/6.0 );
188
+
189
+ [self addChild: labelNode];
190
+
191
+ NSDictionary *attribs = @{NSFontAttributeName : [NSFont fontWithName: @" Futura-Medium" size: fontSize], NSForegroundColorAttributeName : self.textColor };
192
+
193
+ NSAttributedString *labelText = [[NSAttributedString alloc ] initWithString: [NSString stringWithFormat: @" %i " , i] attributes: attribs];
194
+
195
+ SKLabelNode *numberLabel = [SKLabelNode labelNodeWithAttributedText: labelText];
196
+
197
+ numberLabel.position = CGPointMake (0 , -9 );
198
+
199
+ [labelNode addChild: numberLabel];
200
+ }
94
201
}
95
202
96
203
-(void )setupColors
@@ -163,6 +270,36 @@ -(void)setupColors
163
270
textColor = [SKColor whiteColor ];
164
271
break ;
165
272
}
273
+ case ThemeContrast:
274
+ {
275
+ lightColor = [SKColor whiteColor ];
276
+ darkColor = [SKColor whiteColor ];
277
+ inlayColor = [SKColor whiteColor ];
278
+ markColor = [SKColor blackColor ];
279
+ handColor = [SKColor blackColor ];
280
+ textColor = [SKColor blackColor ];
281
+ break ;
282
+ }
283
+ case ThemeVictoire:
284
+ {
285
+ lightColor = [SKColor colorWithRed: 0.937 green: 0.925 blue: 0.871 alpha: 1.000 ];
286
+ darkColor = [SKColor colorWithRed: 0.737 green: 0.725 blue: 0.671 alpha: 1.000 ];
287
+ inlayColor = lightColor;
288
+ markColor = [SKColor colorWithRed: 0.337 green: 0.325 blue: 0.271 alpha: 1.000 ];
289
+ handColor = [SKColor blackColor ];
290
+ textColor = [SKColor colorWithRed: 0.137 green: 0.125 blue: 0.071 alpha: 1.000 ];
291
+ break ;
292
+ }
293
+ case ThemeLiquid:
294
+ {
295
+ lightColor = [SKColor colorWithWhite: 0.2 alpha: 1.0 ];
296
+ darkColor = lightColor;
297
+ inlayColor = [SKColor colorWithWhite: 0.3 alpha: 1.0 ];
298
+ markColor = [SKColor colorWithWhite: 0.5 alpha: 1.0 ];
299
+ handColor = [SKColor whiteColor ];
300
+ textColor = [SKColor whiteColor ];
301
+ break ;
302
+ }
166
303
167
304
default :
168
305
break ;
@@ -213,8 +350,21 @@ -(void)setupScene
213
350
minuteHandInlay.color = self.inlayColor ;
214
351
minuteHandInlay.colorBlendFactor = 1.0 ;
215
352
216
- if (vectorDisplay)
217
- [self setupTickmarks ];
353
+ if (self.useProgrammaticLayout )
354
+ {
355
+ SKNode *face = [self childNodeWithName: @" Face" ];
356
+ SKSpriteNode *numbersLayer = (SKSpriteNode *)[face childNodeWithName: @" Numbers" ];
357
+ numbersLayer.alpha = 0 ;
358
+
359
+ if (self.useRoundFace )
360
+ {
361
+ [self setupTickmarksForRoundFace ];
362
+ }
363
+ else
364
+ {
365
+ [self setupTickmarksForRectangularFace ];
366
+ }
367
+ }
218
368
}
219
369
220
370
- (void )update : (NSTimeInterval )currentTime forScene : (SKScene *)scene
0 commit comments