Skip to content

Commit b484bf7

Browse files
committed
Merge pull request #8 from spritebuilder/headless-develop
Android directory lookup fixes and Label outilnes/shadows fixes.
2 parents 3011147 + 28d56b8 commit b484bf7

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

cocos2d/CCLabelTTF.m

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,20 @@ - (BOOL) updateTexture
451451

452452
}
453453

454+
- (void)applyShadowOnContext:(CGContextRef)context color:(CGColorRef)color blurRadius:(CGFloat)blurRadius offset:(CGPoint)offset {
455+
456+
CGContextSetShadowWithColor(context, CGSizeMake(offset.x, -offset.y), blurRadius, color);
457+
458+
}
459+
460+
- (void)applyOutlineOnContext:(CGContextRef)context color:(CGColorRef)color width:(CGFloat)width {
461+
CGContextSetTextDrawingMode(context, kCGTextStroke);
462+
CGContextSetLineWidth(context, width * 2);
463+
CGContextSetLineJoin(context, kCGLineJoinRound);
464+
CGContextSetStrokeColorWithColor(context, color);
465+
466+
}
467+
454468
- (CCTexture*) createTextureWithAttributedString:(NSAttributedString*)attributedString useFullColor:(BOOL) fullColor
455469
{
456470
NSAssert(attributedString, @"Invalid attributedString");
@@ -589,36 +603,37 @@ - (CCTexture*) createTextureWithAttributedString:(NSAttributedString*)attributed
589603
free(data);
590604
return NULL;
591605
}
592-
// Handle shadow
593-
if (hasShadow)
594-
{
595-
CGContextSetShadowWithColor(context, CGSizeMake(shadowOffset.x, -shadowOffset.y), shadowBlurRadius, _shadowColor.CGColor);
596-
}
597606

598-
// Handle outline
599-
if (hasOutline)
600-
{
601-
CGContextSetTextDrawingMode(context, kCGTextFillStroke);
602-
CGContextSetLineWidth(context, outlineWidth * 2);
603-
CGContextSetLineJoin(context, kCGLineJoinRound);
604-
605-
NSMutableAttributedString* outlineString = [attributedString mutableCopy];
606-
//[outlineString addAttribute:NSForegroundColorAttributeName value:(__bridge id)_outlineColor.CGColor range:NSMakeRange(0, outlineString.length)]; //donotcheckin
607-
608-
[self drawAttributedString:outlineString inContext:context inRect:drawArea];
609-
610-
// Don't draw shadow for main font
611-
CGContextSetShadowWithColor(context, CGSizeZero, 0, NULL);
612-
613-
if (hasShadow)
614-
{
615-
// Draw outline again because shadow overlap
616-
[self drawAttributedString:outlineString inContext:context inRect:drawArea];
617-
}
618-
CGContextSetTextDrawingMode(context, kCGTextFill);
619-
}
620607

621-
[self drawAttributedString:attributedString inContext:context inRect:drawArea];
608+
if (!hasShadow && !hasOutline) {
609+
[self drawAttributedString:attributedString inContext:context inRect:drawArea];
610+
611+
} else if (hasShadow && !hasOutline) {
612+
[self applyShadowOnContext:context color:_shadowColor.CGColor blurRadius:shadowBlurRadius offset:shadowOffset];
613+
[self drawAttributedString:attributedString inContext:context inRect:drawArea];
614+
615+
} else if (!hasShadow && hasOutline) {
616+
CGContextSaveGState(context);
617+
[self applyOutlineOnContext:context color:_outlineColor.CGColor width:outlineWidth];
618+
[self drawAttributedString:attributedString inContext:context inRect:drawArea];
619+
CGContextRestoreGState(context);
620+
[self drawAttributedString:attributedString inContext:context inRect:drawArea];
621+
622+
623+
} else if (hasShadow && hasOutline) {
624+
CGContextSaveGState(context);
625+
[self applyOutlineOnContext:context color:_outlineColor.CGColor width:outlineWidth];
626+
[self applyShadowOnContext:context color:_shadowColor.CGColor blurRadius:shadowBlurRadius offset:shadowOffset];
627+
[self drawAttributedString:attributedString inContext:context inRect:drawArea];
628+
CGContextRestoreGState(context);
629+
CGContextSaveGState(context);
630+
[self applyOutlineOnContext:context color:_outlineColor.CGColor width:outlineWidth];
631+
[self drawAttributedString:attributedString inContext:context inRect:drawArea];
632+
CGContextRestoreGState(context);
633+
[self drawAttributedString:attributedString inContext:context inRect:drawArea];
634+
635+
636+
}
622637

623638
CGContextRelease(context);
624639

cocos2d/Platforms/Android/CCActivity.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ - (void)run
9090
[self.windowManager.defaultDisplay getMetrics:metrics];
9191

9292
// Configure Cocos2d with the options set in SpriteBuilder
93-
// TODO: repalce Published-iOS with Published-Android
94-
NSString* configPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Published-iOS"];
93+
NSString* configPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Published-Android"];
9594

9695
configPath = [configPath stringByAppendingPathComponent:@"configCocos2d.plist"];
9796

0 commit comments

Comments
 (0)