38
38
39
39
#import " CCTexture_Private.h"
40
40
41
- #define kProgressTextureCoordsCount 4
42
- // kProgressTextureCoords holds points {0,1} {0,0} {1,0} {1,1} we can represent it as bits
43
- const char kCCProgressTextureCoords = 0x4b ;
44
-
45
- @interface CCProgressNode () {
41
+ @implementation CCProgressNode {
46
42
CCProgressNodeType _type;
47
43
float _percentage;
48
44
CCSprite *_sprite;
@@ -57,15 +53,6 @@ @interface CCProgressNode () {
57
53
BOOL _needsUpdateProgress;
58
54
}
59
55
60
- -(void )updateProgress ;
61
- -(void )updateBar ;
62
- -(void )updateRadial ;
63
- -(void )updateColor ;
64
- -(CGPoint)boundaryTexCoord : (char )index ;
65
- @end
66
-
67
-
68
- @implementation CCProgressNode
69
56
@synthesize percentage = _percentage;
70
57
@synthesize sprite = _sprite;
71
58
@synthesize type = _type;
@@ -200,8 +187,6 @@ -(GLKVector2)textureCoordFromAlphaPoint:(CGPoint) alpha
200
187
CC_SWAP (alpha.x , alpha.y );
201
188
}
202
189
203
- // As of 3.1, the x alpha needs to be flipped. Not really sure why.
204
- alpha.x = 1.0 - alpha.x ;
205
190
return GLKVector2Make (min.x * (1 .f - alpha.x ) + max.x * alpha.x , min.y * (1 .f - alpha.y ) + max.y * alpha.y );
206
191
}
207
192
@@ -271,6 +256,13 @@ -(void)setMidpoint:(CGPoint)midPoint
271
256
_midpoint = ccpClamp (midPoint, CGPointZero, ccp (1 ,1 ));
272
257
}
273
258
259
+ static inline CGPoint
260
+ BoundryTexCoord (int index)
261
+ {
262
+ static const CGPoint points[] = {{1 ,1 }, {1 ,0 }, {0 ,0 }, {0 ,1 }};
263
+ return points[index];
264
+ }
265
+
274
266
// /
275
267
// Update does the work of mapping the texture onto the triangles
276
268
// It now doesn't occur the cost of free/alloc data every update cycle.
@@ -317,11 +309,11 @@ -(void)updateRadial
317
309
318
310
float min_t = FLT_MAX;
319
311
320
- for (int i = 0 ; i <= kProgressTextureCoordsCount ; ++i) {
321
- int pIndex = (i + ( kProgressTextureCoordsCount - 1 ))% kProgressTextureCoordsCount ;
312
+ for (int i = 0 ; i <= 4 ; ++i) {
313
+ int pIndex = (i + 3 )% 4 ;
322
314
323
- CGPoint edgePtA = [ self boundaryTexCoord: i % kProgressTextureCoordsCount ] ;
324
- CGPoint edgePtB = [ self boundaryTexCoord: pIndex] ;
315
+ CGPoint edgePtA = BoundryTexCoord ( i % 4 ) ;
316
+ CGPoint edgePtB = BoundryTexCoord ( pIndex) ;
325
317
326
318
// Remember that the top edge is split in half for the 12 o'clock position
327
319
// Let's deal with that here by finding the correct endpoints
@@ -391,7 +383,7 @@ -(void)updateRadial
391
383
_verts[1 ].position = [self vertexFromAlphaPoint: topMid];
392
384
393
385
for (int i = 0 ; i < index; ++i){
394
- CGPoint alphaPoint = [ self boundaryTexCoord: i] ;
386
+ CGPoint alphaPoint = BoundryTexCoord (i) ;
395
387
_verts[i+2 ].texCoord1 = [self textureCoordFromAlphaPoint: alphaPoint];
396
388
_verts[i+2 ].position = [self vertexFromAlphaPoint: alphaPoint];
397
389
}
@@ -504,18 +496,6 @@ -(void)updateBar
504
496
[self updateColor ];
505
497
}
506
498
507
- -(CGPoint)boundaryTexCoord : (char )index
508
- {
509
- if (index < kProgressTextureCoordsCount ) {
510
- if (_reverseDirection) {
511
- return ccp ((kCCProgressTextureCoords >>(7 -(index<<1 )))&1 ,(kCCProgressTextureCoords >>(7 -((index<<1 )+1 )))&1 );
512
- } else {
513
- return ccp ((kCCProgressTextureCoords >>((index<<1 )+1 ))&1 ,(kCCProgressTextureCoords >>(index<<1 ))&1 );
514
- }
515
- }
516
- return CGPointZero;
517
- }
518
-
519
499
-(void )visit : (CCRenderer *)renderer parentTransform : (const GLKMatrix4 *)parentTransform
520
500
{
521
501
[super visit: renderer parentTransform: parentTransform];
0 commit comments