Skip to content

Commit 6d5841c

Browse files
committed
df outline - WIP
1 parent 6856b3b commit 6d5841c

File tree

7 files changed

+292
-9
lines changed

7 files changed

+292
-9
lines changed

cocos2d-ios.xcodeproj/project.pbxproj

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@
332332
D27451B819AE5517006DA0A1 /* CCEffectDistanceField.m in Sources */ = {isa = PBXBuildFile; fileRef = D27451B619AE5517006DA0A1 /* CCEffectDistanceField.m */; };
333333
D27451BD19AEC84C006DA0A1 /* CCEffectDistanceField.m in Sources */ = {isa = PBXBuildFile; fileRef = D27451B619AE5517006DA0A1 /* CCEffectDistanceField.m */; };
334334
D27451BE19AEC84F006DA0A1 /* CCEffectDistanceField.h in Headers */ = {isa = PBXBuildFile; fileRef = D27451B519AE5517006DA0A1 /* CCEffectDistanceField.h */; };
335+
D27451C619B111A9006DA0A1 /* CCEffectDFOutline.h in Headers */ = {isa = PBXBuildFile; fileRef = D27451C419B111A9006DA0A1 /* CCEffectDFOutline.h */; };
336+
D27451C719B111A9006DA0A1 /* CCEffectDFOutline.h in Headers */ = {isa = PBXBuildFile; fileRef = D27451C419B111A9006DA0A1 /* CCEffectDFOutline.h */; };
337+
D27451C819B111A9006DA0A1 /* CCEffectDFOutline.m in Sources */ = {isa = PBXBuildFile; fileRef = D27451C519B111A9006DA0A1 /* CCEffectDFOutline.m */; };
338+
D27451C919B111A9006DA0A1 /* CCEffectDFOutline.m in Sources */ = {isa = PBXBuildFile; fileRef = D27451C519B111A9006DA0A1 /* CCEffectDFOutline.m */; };
335339
D285ECF0192EA92A009F4E88 /* CCGLView.h in Headers */ = {isa = PBXBuildFile; fileRef = D285ECEE192EA92A009F4E88 /* CCGLView.h */; };
336340
D285ECF1192EA92A009F4E88 /* CCGLView.m in Sources */ = {isa = PBXBuildFile; fileRef = D285ECEF192EA92A009F4E88 /* CCGLView.m */; };
337341
D285ECF8192EF5B2009F4E88 /* CCDirectorAndroid.h in Headers */ = {isa = PBXBuildFile; fileRef = D285ECF6192EF5B2009F4E88 /* CCDirectorAndroid.h */; };
@@ -1059,6 +1063,8 @@
10591063
D27451A919AD430A006DA0A1 /* CCEffectDropShadow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCEffectDropShadow.m; sourceTree = "<group>"; };
10601064
D27451B519AE5517006DA0A1 /* CCEffectDistanceField.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCEffectDistanceField.h; sourceTree = "<group>"; };
10611065
D27451B619AE5517006DA0A1 /* CCEffectDistanceField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCEffectDistanceField.m; sourceTree = "<group>"; };
1066+
D27451C419B111A9006DA0A1 /* CCEffectDFOutline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCEffectDFOutline.h; sourceTree = "<group>"; };
1067+
D27451C519B111A9006DA0A1 /* CCEffectDFOutline.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCEffectDFOutline.m; sourceTree = "<group>"; };
10621068
D285ECEE192EA92A009F4E88 /* CCGLView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCGLView.h; path = Android/CCGLView.h; sourceTree = "<group>"; };
10631069
D285ECEF192EA92A009F4E88 /* CCGLView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCGLView.m; path = Android/CCGLView.m; sourceTree = "<group>"; };
10641070
D285ECF6192EF5B2009F4E88 /* CCDirectorAndroid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCDirectorAndroid.h; path = Android/CCDirectorAndroid.h; sourceTree = "<group>"; };
@@ -1801,7 +1807,7 @@
18011807
D272031618FC897D00B100FF /* Effects */ = {
18021808
isa = PBXGroup;
18031809
children = (
1804-
D27451BF19AFC44D006DA0A1 /* Experimental */,
1810+
D27451BF19AFC44D006DA0A1 /* DistanceField */,
18051811
D3903B081995285B003AA81A /* CCEffectBlur.h */,
18061812
D3903B091995285B003AA81A /* CCEffectBlur.m */,
18071813
D268FE151980791300ECBCD0 /* CCEffectRefraction.h */,
@@ -1839,13 +1845,15 @@
18391845
name = Effects;
18401846
sourceTree = "<group>";
18411847
};
1842-
D27451BF19AFC44D006DA0A1 /* Experimental */ = {
1848+
D27451BF19AFC44D006DA0A1 /* DistanceField */ = {
18431849
isa = PBXGroup;
18441850
children = (
18451851
D27451B519AE5517006DA0A1 /* CCEffectDistanceField.h */,
18461852
D27451B619AE5517006DA0A1 /* CCEffectDistanceField.m */,
1853+
D27451C419B111A9006DA0A1 /* CCEffectDFOutline.h */,
1854+
D27451C519B111A9006DA0A1 /* CCEffectDFOutline.m */,
18471855
);
1848-
name = Experimental;
1856+
name = DistanceField;
18491857
sourceTree = "<group>";
18501858
};
18511859
D285ECED192E7E06009F4E88 /* Android */ = {
@@ -2120,6 +2128,7 @@
21202128
B791E84A182064BF00DAE1D7 /* CCTiledMapLayer_Private.h in Headers */,
21212129
B7705FEF1831A07B0043CC67 /* ALSource.h in Headers */,
21222130
B7705FED1831A07B0043CC67 /* ALSoundSourcePool.h in Headers */,
2131+
D27451C619B111A9006DA0A1 /* CCEffectDFOutline.h in Headers */,
21232132
B7705FDC1831A07B0043CC67 /* OALSimpleAudio.h in Headers */,
21242133
A6DC4E0918055DCC00C280A6 /* CCTransition.h in Headers */,
21252134
B791E85D182074C500DAE1D7 /* CCProgressNode_Private.h in Headers */,
@@ -2218,6 +2227,7 @@
22182227
D2FEB644194F6C9E00FC0574 /* CCLayoutBox.h in Headers */,
22192228
D2FEB645194F6C9E00FC0574 /* CCTouchIOS.h in Headers */,
22202229
D2FEB646194F6C9E00FC0574 /* CCEffect.h in Headers */,
2230+
D27451C719B111A9006DA0A1 /* CCEffectDFOutline.h in Headers */,
22212231
D24161141958F738003673BD /* CCAnimationManager.h in Headers */,
22222232
D2FEB647194F6C9E00FC0574 /* CCEffect_Private.h in Headers */,
22232233
D2FEB648194F6C9E00FC0574 /* CCEffectStack.h in Headers */,
@@ -2523,6 +2533,7 @@
25232533
509A79980F6188420032F449 /* CCSprite.m in Sources */,
25242534
D37D197718B6665700B23FDE /* CCTiledMap.m in Sources */,
25252535
D36DFA2819996EC500DEC135 /* CCRendererGLSupport.m in Sources */,
2536+
D27451C819B111A9006DA0A1 /* CCEffectDFOutline.m in Sources */,
25262537
50C508C70F7C194400799124 /* CCFileUtils.m in Sources */,
25272538
B7705FD31831A07B0043CC67 /* OALAudioActions.m in Sources */,
25282539
D25B4F4C194A499700DA9D60 /* CCTouch.m in Sources */,
@@ -2688,6 +2699,7 @@
26882699
D2FEB6DA194F6C9E00FC0574 /* OALAudioActions.m in Sources */,
26892700
D2FEB6DB194F6C9E00FC0574 /* CCTouch.m in Sources */,
26902701
D2EC6039199D9F82001A15E9 /* CCRendererGLSupport.m in Sources */,
2702+
D27451C919B111A9006DA0A1 /* CCEffectDFOutline.m in Sources */,
26912703
D2FEB6DC194F6C9E00FC0574 /* CCEffectNode.m in Sources */,
26922704
D2FEB6DD194F6C9E00FC0574 /* CCTiledMapObjectGroup.m in Sources */,
26932705
D2FEB6DE194F6C9E00FC0574 /* CGPointExtension.m in Sources */,

cocos2d-ui-tests/tests/CCEffectsTest.m

Lines changed: 76 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
#import "CCNodeColor.h"
44
#import "CCEffectNode.h"
55

6+
enum DFTest { DISTANCE_FIELD, OUTLINE };
7+
68
@interface CCEffectsTest : TestBase @end
79
@implementation CCEffectsTest {
810
#if CC_EFFECTS_EXPERIMENTAL
911
CCEffectDistanceField* _distanceFieldEffect;
1012
#endif
13+
CCEffectDFOutline* _outlineEffect;
14+
enum DFTest _currentEffect;
1115
}
1216

1317
-(id)init
@@ -20,11 +24,68 @@ -(id)init
2024
return self;
2125
}
2226

27+
#pragma mark Distance Fields
28+
29+
-(void)setupDFOutlineEffectTest
30+
{
31+
_currentEffect = OUTLINE;
32+
self.subTitle = @"Distance Field Outline Test";
33+
34+
CCSprite *environment = [CCSprite spriteWithImageNamed:@"Images/MountainPanorama.jpg"];
35+
environment.positionType = CCPositionTypeNormalized;
36+
environment.anchorPoint = ccp(0.5, 0.5);
37+
environment.position = ccp(0.5f, 0.5f);
38+
39+
_outlineEffect = [CCEffectDFOutline effectWithOutlineColor:[CCColor redColor] fillColor:[CCColor blackColor]];
40+
41+
CCSprite *sampleSprite = [CCSprite spriteWithImageNamed:@"Images/output.png"];
42+
sampleSprite.position = ccp(0.5, 0.5);
43+
sampleSprite.positionType = CCPositionTypeNormalized;
44+
sampleSprite.effect = _outlineEffect;
45+
sampleSprite.scale = 2.0f;
46+
47+
CCSpriteFrame* background = [CCSpriteFrame frameWithImageNamed:@"Tests/slider-background.png"];
48+
CCSpriteFrame* backgroundHilite = [CCSpriteFrame frameWithImageNamed:@"Tests/slider-background-hilite.png"];
49+
CCSpriteFrame* handle = [CCSpriteFrame frameWithImageNamed:@"Tests/slider-handle.png"];
50+
51+
CCSlider* slider = [[CCSlider alloc] initWithBackground:background andHandleImage:handle];
52+
[slider setBackgroundSpriteFrame:backgroundHilite forState:CCControlStateHighlighted];
53+
slider.positionType = CCPositionTypeNormalized;
54+
slider.position = ccp(0.1f, 0.5f);
55+
56+
slider.preferredSizeType = CCSizeTypeMake(CCSizeUnitNormalized, CCSizeUnitUIPoints);
57+
slider.preferredSize = CGSizeMake(0.5f, 10);
58+
slider.rotation = 90;
59+
slider.anchorPoint = ccp(0.5f, 0.5f);
60+
slider.scale = 0.8;
61+
62+
[slider setTarget:self selector:@selector(outlineInnerWidthChange:)];
63+
64+
CCSlider* slider2 = [[CCSlider alloc] initWithBackground:background andHandleImage:handle];
65+
[slider2 setBackgroundSpriteFrame:backgroundHilite forState:CCControlStateHighlighted];
66+
slider2.positionType = CCPositionTypeNormalized;
67+
slider2.position = ccp(0.15f, 0.5f);
68+
69+
slider2.preferredSizeType = CCSizeTypeMake(CCSizeUnitNormalized, CCSizeUnitUIPoints);
70+
slider2.preferredSize = CGSizeMake(0.5f, 10);
71+
slider2.rotation = 90;
72+
slider2.anchorPoint = ccp(0.5f, 0.5f);
73+
slider2.scale = 0.8;
74+
75+
[slider2 setTarget:self selector:@selector(outlineOuterWidthChange:)];
76+
77+
[self.contentNode addChild:environment];
78+
[self.contentNode addChild:slider];
79+
[self.contentNode addChild:slider2];
80+
[self.contentNode addChild:sampleSprite];
81+
}
82+
2383
#if CC_EFFECTS_EXPERIMENTAL
2484
-(void)setupDistanceFieldEffectTest
2585
{
86+
_currentEffect = DISTANCE_FIELD;
2687
self.subTitle = @"Distance Field Effect Test";
27-
88+
2889
// CCNodeColor* environment = [CCNodeColor nodeWithColor:[CCColor whiteColor]];
2990
CCSprite *environment = [CCSprite spriteWithImageNamed:@"Images/MountainPanorama.jpg"];
3091
environment.positionType = CCPositionTypeNormalized;
@@ -105,16 +166,25 @@ -(void)setupDistanceFieldEffectTest
105166
[self.contentNode addChild:slider3];
106167
}
107168

169+
#endif
170+
108171
- (void)outlineInnerWidthChange:(id)sender
109172
{
110173
CCSlider* slider = sender;
111-
_distanceFieldEffect.outlineInnerWidth = slider.sliderValue;
174+
if(_currentEffect == DISTANCE_FIELD)
175+
_distanceFieldEffect.outlineInnerWidth = slider.sliderValue;
176+
else if(_currentEffect == OUTLINE)
177+
_outlineEffect.outlineInnerWidth = slider.sliderValue;
178+
112179
}
113180

114181
- (void)outlineOuterWidthChange:(id)sender
115182
{
116183
CCSlider* slider = sender;
117-
_distanceFieldEffect.outlineOuterWidth = slider.sliderValue;
184+
if(_currentEffect == DISTANCE_FIELD)
185+
_distanceFieldEffect.outlineOuterWidth = slider.sliderValue;
186+
else if(_currentEffect == OUTLINE)
187+
_outlineEffect.outlineOuterWidth = slider.sliderValue;
118188
}
119189

120190
- (void)glowWidthChange:(id)sender
@@ -133,7 +203,7 @@ - (void)enableOutline:(id)sender
133203
_distanceFieldEffect.outline = !_distanceFieldEffect.outline;
134204
}
135205

136-
#endif
206+
#pragma mark DropShadow
137207

138208
-(void)setupDropShadowEffectTest
139209
{
@@ -163,6 +233,8 @@ -(void)setupDropShadowEffectTest
163233
[self.contentNode addChild:effectNode];
164234
}
165235

236+
#pragma mark Glass
237+
166238
-(void)setupGlassEffectTest
167239
{
168240
self.subTitle = @"Glass Effect Test";

cocos2d/CCEffectDFOutline.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// CCEffectDFOutline.h
3+
// cocos2d-ios
4+
//
5+
// Created by Oleg Osin on 8/29/14.
6+
//
7+
//
8+
9+
#import "CCEffect.h"
10+
11+
/**
12+
* CCEffectDFOutline create a drop shadow.
13+
*
14+
*/
15+
16+
@interface CCEffectDFOutline : CCEffect
17+
18+
/// -----------------------------------------------------------------------
19+
/// @name Accessing Effect Attributes
20+
/// -----------------------------------------------------------------------
21+
22+
@property (nonatomic, strong) CCColor* fillColor;
23+
@property (nonatomic, strong) CCColor* outlineColor;
24+
25+
@property (nonatomic) float outlineInnerWidth;
26+
@property (nonatomic) float outlineOuterWidth;
27+
28+
/// -----------------------------------------------------------------------
29+
/// @name Initializing a CCEffectDFOutline object
30+
/// -----------------------------------------------------------------------
31+
32+
/**
33+
* Initializes a CCEffectDFOutline object with a (5, -5) black drop shadow offset .
34+
*
35+
* @return The CCEffectDFOutline object.
36+
*/
37+
-(id)init;
38+
39+
/**
40+
* Initializes a CCEffectDFOutline object with the supplied parameters.
41+
*
42+
* @param glowColor Color of the glow, a [CCColor blackColor] will result in an opaque black drop shadow.
43+
*
44+
* @return The CCEffectDFOutline object.
45+
*/
46+
-(id)initWithOutlineColor:(CCColor*)outlineColor fillColor:(CCColor*)fillColor;
47+
48+
49+
/// -----------------------------------------------------------------------
50+
/// @name Creating a CCEffectDFOutline object
51+
/// -----------------------------------------------------------------------
52+
53+
/**
54+
* Initializes a CCEffectDFOutline object with the supplied parameters.
55+
*
56+
* @param glowColor Color of the glow, a [CCColor blackColor] will result in an opaque black drop shadow.
57+
*
58+
* @return The CCEffectDFOutline object.
59+
*/
60+
+(id)effectWithOutlineColor:(CCColor*)outlineColor fillColor:(CCColor*)fillColor;
61+
62+
@end

0 commit comments

Comments
 (0)