Skip to content

Commit 7625920

Browse files
committed
Switches floats to CGFloat for better compatibility with ARM 64 devices fixes #672 & #645
1 parent c743e77 commit 7625920

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

cocos2d/CCLabelTTF.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
@property (nonatomic,strong) NSString* fontName;
6565

6666
/** The font size of the text. */
67-
@property (nonatomic,assign) float fontSize;
67+
@property (nonatomic,assign) CGFloat fontSize;
6868

6969
/** The color of the text (If not using shadow or outline). */
7070
@property (nonatomic,strong) CCColor* fontColor;
@@ -90,10 +90,10 @@
9090
@property (nonatomic,assign) BOOL adjustsFontSizeToFit;
9191

9292
/** Used together with adjustsFontSizeToFit. Fonts will not be scaled down below this size (the label will instead be clipped). */
93-
@property (nonatomic,assign) float minimumFontSize;
93+
@property (nonatomic,assign) CGFloat minimumFontSize;
9494

9595
/** Adjusts the fonts baseline, the value is set in points. */
96-
@property (nonatomic,assign) float baselineAdjustment;
96+
@property (nonatomic,assign) CGFloat baselineAdjustment;
9797

9898

9999
/// -----------------------------------------------------------------------
@@ -113,7 +113,7 @@
113113
@property (nonatomic,assign) CCPositionType shadowOffsetType;
114114

115115
/** The blur radius of the shadow. */
116-
@property (nonatomic,assign) float shadowBlurRadius;
116+
@property (nonatomic,assign) CGFloat shadowBlurRadius;
117117

118118

119119
/// -----------------------------------------------------------------------
@@ -124,7 +124,7 @@
124124
@property (nonatomic,strong) CCColor* outlineColor;
125125

126126
/** The width of the text's outline. */
127-
@property (nonatomic,assign) float outlineWidth;
127+
@property (nonatomic,assign) CGFloat outlineWidth;
128128

129129

130130
/// -----------------------------------------------------------------------

cocos2d/CCLabelTTF.m

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ - (id) initWithAttributedString:(NSAttributedString *)attrString dimensions:(CGS
110110
}
111111

112112
// This is a private initializer
113-
- (id) initWithAttributedString:(NSAttributedString *)attrString fontName:(NSString*)fontName fontSize:(float)fontSize dimensions:(CGSize)dimensions
113+
- (id) initWithAttributedString:(NSAttributedString *)attrString fontName:(NSString*)fontName fontSize:(CGFloat)fontSize dimensions:(CGSize)dimensions
114114
{
115115
if ( (self = [super init]) )
116116
{
@@ -181,7 +181,7 @@ - (void)setFontName:(NSString*)fontName
181181
}
182182
}
183183

184-
- (void) setFontSize:(float)fontSize
184+
- (void) setFontSize:(CGFloat)fontSize
185185
{
186186
if( fontSize != _fontSize ) {
187187
_fontSize = fontSize;
@@ -207,7 +207,7 @@ - (void) setFontColor:(CCColor*)fontColor
207207
}
208208
}
209209

210-
- (void) setMinimumFontSize:(float)minimumFontSize
210+
- (void) setMinimumFontSize:(CGFloat)minimumFontSize
211211
{
212212
if (minimumFontSize != _minimumFontSize)
213213
{
@@ -274,7 +274,7 @@ -(CGPoint)shadowOffsetInPoints
274274
return [self convertPositionToPoints:self.shadowOffset type:_shadowOffsetType];
275275
}
276276

277-
- (void) setShadowBlurRadius:(float)shadowBlurRadius
277+
- (void) setShadowBlurRadius:(CGFloat)shadowBlurRadius
278278
{
279279
if (_shadowBlurRadius != shadowBlurRadius)
280280
{
@@ -292,7 +292,7 @@ - (void) setOutlineColor:(CCColor*)outlineColor
292292
}
293293
}
294294

295-
- (void) setOutlineWidth:(float)outlineWidth
295+
- (void) setOutlineWidth:(CGFloat)outlineWidth
296296
{
297297
if (outlineWidth != _outlineWidth)
298298
{
@@ -484,27 +484,27 @@ - (CCTexture*) createTextureWithAttributedString:(NSAttributedString*)attributed
484484

485485
CGSize originalDimensions = _dimensions;
486486

487-
CGFloat scale = [CCDirector sharedDirector].contentScaleFactor;
487+
CGFloat scale = [CCDirector sharedDirector].contentScaleFactor;
488488
originalDimensions.width *= scale;
489489
originalDimensions.height *= scale;
490490

491491
CGSize dimensions = originalDimensions;
492492

493-
float shadowBlurRadius = _shadowBlurRadius * scale;
493+
CGFloat shadowBlurRadius = _shadowBlurRadius * scale;
494494
CGPoint shadowOffset = ccpMult(self.shadowOffsetInPoints, scale);
495-
float outlineWidth = _outlineWidth * scale;
495+
CGFloat outlineWidth = _outlineWidth * scale;
496496

497497
BOOL hasShadow = (_shadowColor.alpha > 0);
498498
BOOL hasOutline = (_outlineColor.alpha > 0 && _outlineWidth > 0);
499499

500-
float xOffset = 0;
501-
float yOffset = 0;
502-
float scaleFactor = 1;
500+
CGFloat xOffset = 0;
501+
CGFloat yOffset = 0;
502+
CGFloat scaleFactor = 1;
503503

504-
float xPadding = 0;
505-
float yPadding = 0;
506-
float wDrawArea = 0;
507-
float hDrawArea = 0;
504+
CGFloat xPadding = 0;
505+
CGFloat yPadding = 0;
506+
CGFloat wDrawArea = 0;
507+
CGFloat hDrawArea = 0;
508508

509509
// Calculate padding
510510
if (hasShadow)
@@ -542,7 +542,7 @@ - (CCTexture*) createTextureWithAttributedString:(NSAttributedString*)attributed
542542
// Handle strings with fixed dimensions
543543
if (_adjustsFontSizeToFit)
544544
{
545-
float fontSize = [attributedString singleFontSize];
545+
CGFloat fontSize = [attributedString singleFontSize];
546546
if (fontSize)
547547
{
548548
// This is a string that can be resized (it only uses one font and size)
@@ -552,8 +552,8 @@ - (CCTexture*) createTextureWithAttributedString:(NSAttributedString*)attributed
552552
CGSize wantedSize = [attributedString boundingRectWithSize:CGSizeZero options:NSStringDrawingUsesLineFragmentOrigin].size;
553553
#endif
554554

555-
float wScaleFactor = 1;
556-
float hScaleFactor = 1;
555+
CGFloat wScaleFactor = 1;
556+
CGFloat hScaleFactor = 1;
557557
if (wantedSize.width > wDrawArea)
558558
{
559559
wScaleFactor = wDrawArea/wantedSize.width;
@@ -568,8 +568,8 @@ - (CCTexture*) createTextureWithAttributedString:(NSAttributedString*)attributed
568568

569569
if (scaleFactor != 1)
570570
{
571-
float newFontSize = fontSize * scaleFactor;
572-
float minFontSize = _minimumFontSize * scale;
571+
CGFloat newFontSize = fontSize * scaleFactor;
572+
CGFloat minFontSize = _minimumFontSize * scale;
573573
if (minFontSize && newFontSize < minFontSize) newFontSize = minFontSize;
574574
attributedString = [attributedString copyWithNewFontSize:newFontSize];
575575
}
@@ -682,7 +682,7 @@ - (CCTexture*) createTextureWithAttributedString:(NSAttributedString*)attributed
682682
[[NSAffineTransform transform] set];
683683

684684
// XXX: The shadows are for some reason scaled on OS X if a retina display is connected
685-
float retinaFix = 1;
685+
CGFloat retinaFix = 1;
686686
for (NSScreen* screen in [NSScreen screens])
687687
{
688688
if (screen.backingScaleFactor > retinaFix) retinaFix = screen.backingScaleFactor;
@@ -802,23 +802,23 @@ - (BOOL) updateTextureOld
802802
- (CCTexture*) createTextureWithString:(NSString*) string useFullColor:(BOOL)useFullColor
803803
{
804804
// Scale everything up by content scale
805-
CGFloat scale = [CCDirector sharedDirector].contentScaleFactor;
805+
CGFloat scale = [CCDirector sharedDirector].contentScaleFactor;
806806
UIFont* font = [UIFont fontWithName:_fontName size:_fontSize * scale];
807-
float shadowBlurRadius = _shadowBlurRadius * scale;
807+
CGFloat shadowBlurRadius = _shadowBlurRadius * scale;
808808
CGPoint shadowOffset = ccpMult(self.shadowOffsetInPoints, scale);
809-
float outlineWidth = _outlineWidth * scale;
809+
CGFloat outlineWidth = _outlineWidth * scale;
810810

811811
BOOL hasShadow = (_shadowColor.alpha > 0);
812812
BOOL hasOutline = (_outlineColor.alpha > 0 && _outlineWidth > 0);
813813

814-
float xOffset = 0;
815-
float yOffset = 0;
816-
float scaleFactor = 1;
814+
CGFloat xOffset = 0;
815+
CGFloat yOffset = 0;
816+
CGFloat scaleFactor = 1;
817817

818-
float xPadding = 0;
819-
float yPadding = 0;
820-
float wDrawArea = 0;
821-
float hDrawArea = 0;
818+
CGFloat xPadding = 0;
819+
CGFloat yPadding = 0;
820+
CGFloat wDrawArea = 0;
821+
CGFloat hDrawArea = 0;
822822

823823
CGSize originalDimensions = _dimensions;
824824
originalDimensions.width *= scale;
@@ -866,12 +866,12 @@ - (CCTexture*) createTextureWithString:(NSString*) string useFullColor:(BOOL)use
866866
// Handle strings with fixed dimensions
867867
if (_adjustsFontSizeToFit)
868868
{
869-
float fontSize = font.pointSize;
869+
CGFloat fontSize = font.pointSize;
870870
CGSize wantedSizeFirstLine = [string sizeWithFont:font];
871871
CGSize wantedSize = [string sizeWithFont:font constrainedToSize:CGSizeMake(wantedSizeFirstLine.width, 1024) lineBreakMode:0];
872872

873-
float wScaleFactor = 1;
874-
float hScaleFactor = 1;
873+
CGFloat wScaleFactor = 1;
874+
CGFloat hScaleFactor = 1;
875875
if (wantedSize.width > wDrawArea)
876876
{
877877
wScaleFactor = wDrawArea/wantedSize.width;
@@ -886,8 +886,8 @@ - (CCTexture*) createTextureWithString:(NSString*) string useFullColor:(BOOL)use
886886

887887
if (scaleFactor != 1)
888888
{
889-
float newFontSize = fontSize * scaleFactor;
890-
float minFontSize = _minimumFontSize * scale;
889+
CGFloat newFontSize = fontSize * scaleFactor;
890+
CGFloat minFontSize = _minimumFontSize * scale;
891891
if (minFontSize && newFontSize < minFontSize) newFontSize = minFontSize;
892892
font = [UIFont fontWithName:font.fontName size:newFontSize];
893893
}

0 commit comments

Comments
 (0)