Skip to content

Commit 4d385f6

Browse files
committed
Merge branch 'develop-v3' of github:cocos2d/cocos2d-iphone into develop-v3
Former-commit-id: 82a78a3
2 parents 0802d21 + 87fa687 commit 4d385f6

File tree

2 files changed

+240
-5
lines changed

2 files changed

+240
-5
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
40af2ecdcbc1edb7178d4fff03c6c62e439fee8a
1+
11bc1d4cdb4f251665a23432b31a4395f2e92a41

cocos2d/Support/CCColor.h

Lines changed: 239 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,64 +27,285 @@
2727
#import "ccTypes.h"
2828

2929
/**
30-
* Defines a CCColor to use with cocos2d.
30+
* A CCColor object represents color and sometimes opacity (alpha value) for use with Cocos2D objects.
3131
*/
32-
@interface CCColor : NSObject
33-
{
32+
@interface CCColor : NSObject {
3433
GLfloat _r;
3534
GLfloat _g;
3635
GLfloat _b;
3736
GLfloat _a;
3837
}
3938

39+
40+
#pragma mark - Creating a CCColor Object from Component Values
41+
/// -----------------------------------------------------------------------
42+
/// @name Creating a CCColor Object from Component Values
43+
/// -----------------------------------------------------------------------
44+
45+
/**
46+
* Creates and returns a color object using the specified opacity and grayscale values.
47+
*
48+
* @param white The grayscale value of the color object, specified as a value from 0.0 to 1.0.
49+
* @param alpha The opacity value of the color object, specified as a value from 0.0 to 1.0.
50+
*
51+
* @return The color object.
52+
*/
4053
+ (CCColor *)colorWithWhite:(float)white alpha:(float)alpha;
54+
55+
/**
56+
* Creates and returns a color object using the specified opacity and RGBA component values.
57+
*
58+
* @param red The red component of the color object, specified as a value from 0.0 to 1.0.
59+
* @param green The green component of the color object, specified as a value from 0.0 to 1.0.
60+
* @param blue The blue component of the color object, specified as a value from 0.0 to 1.0.
61+
* @param alpha The opacity value of the color object, specified as a value from 0.0 to 1.0.
62+
*
63+
* @return The color object.
64+
*/
4165
+ (CCColor *)colorWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
66+
67+
/**
68+
* Creates and returns a color object using the specified opacity and RGB component values. Alpha will default to 1.0.
69+
*
70+
* @param red The red component of the color object, specified as a value from 0.0 to 1.0.
71+
* @param green The green component of the color object, specified as a value from 0.0 to 1.0.
72+
* @param blue The blue component of the color object, specified as a value from 0.0 to 1.0.
73+
*
74+
* @return The color object.
75+
*/
4276
+ (CCColor *)colorWithRed:(float)red green:(float)green blue:(float)blue;
77+
78+
/**
79+
* Creates and returns a color object using the specified Quartz color reference.
80+
*
81+
* @param cgColor A reference to a Quartz color.
82+
*
83+
* @return The color object.
84+
*/
4385
+ (CCColor *)colorWithCGColor:(CGColorRef)cgColor;
86+
87+
/**
88+
* Creates and returns a color object that has the same color space and component values as the receiver, but has the specified alpha component.
89+
*
90+
* @param alpha The opacity value of the new CCColor object.
91+
*
92+
* @return The color object.
93+
*/
4494
- (CCColor *)colorWithAlphaComponent:(float)alpha;
4595

4696
#ifdef __CC_PLATFORM_IOS
97+
/**
98+
* Converts a UIColor object to its CCColor equivalent.
99+
*
100+
* @param color UIColor object.
101+
*
102+
* @return The color object.
103+
*/
47104
+ (CCColor *)colorWithUIColor:(UIColor*)color;
48105
#endif
49106

107+
108+
#pragma mark - Initializing a CCColor Object
109+
/// -----------------------------------------------------------------------
110+
/// @name Initializing a CCColor Object
111+
/// -----------------------------------------------------------------------
112+
113+
/**
114+
* Initializes and returns a color object using the specified opacity and grayscale values.
115+
*
116+
* @param white The grayscale value of the color object, specified as a value from 0.0 to 1.0.
117+
* @param alpha The opacity value of the color object, specified as a value from 0.0 to 1.0.
118+
*
119+
* @return An initialized color object.
120+
*/
50121
- (CCColor *)initWithWhite:(float)white alpha:(float)alpha;
122+
123+
/**
124+
* Initializes and returns a color object using the specified opacity and RGBA component values.
125+
*
126+
* @param red The red component of the color object, specified as a value from 0.0 to 1.0.
127+
* @param green The green component of the color object, specified as a value from 0.0 to 1.0.
128+
* @param blue The blue component of the color object, specified as a value from 0.0 to 1.0.
129+
* @param alpha The opacity value of the color object, specified as a value from 0.0 to 1.0.
130+
*
131+
* @return An initialized color object.
132+
*/
51133
- (CCColor *)initWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
134+
135+
/**
136+
* Initializes and returns a color object using the specified opacity and RGB component values. Alpha will default to 1.0.
137+
*
138+
* @param red The red component of the color object, specified as a value from 0.0 to 1.0.
139+
* @param green The green component of the color object, specified as a value from 0.0 to 1.0.
140+
* @param blue The blue component of the color object, specified as a value from 0.0 to 1.0.
141+
*
142+
* @return An initialized color object.
143+
*/
52144
- (CCColor *)initWithRed:(float)red green:(float)green blue:(float)blue;
145+
146+
/**
147+
* Initializes and returns a color object using the specified Quartz color reference.
148+
*
149+
* @param cgColor A reference to a Quartz color.
150+
*
151+
* @return An initialized color object.
152+
*/
53153
- (CCColor *)initWithCGColor:(CGColorRef)cgColor;
54154

55155
#ifdef __CC_PLATFORM_IOS
156+
/**
157+
* Initializes and returns a UIColor object to its CCColor equivalent.
158+
*
159+
* @param color UIColor object.
160+
*
161+
* @return An initialized color object.
162+
*/
56163
- (CCColor *)initWithUIColor:(UIColor*)color;
57164
#endif
58165

166+
167+
#pragma mark - Creating a CCColor with Preset Component Values
168+
/// -----------------------------------------------------------------------
169+
/// @name Creating a CCColor with Preset Component Values
170+
/// -----------------------------------------------------------------------
171+
172+
/**
173+
* Returns a color object whose RGB values are 0.0, 1.0, and 1.0 and whose alpha value is 1.0.
174+
*
175+
* @return The CCColor object.
176+
*/
59177
+ (CCColor *)blackColor;
178+
179+
/**
180+
* Returns a color object whose grayscale value is 1/3 and whose alpha value is 1.0.
181+
*
182+
* @return The CCColor object.
183+
*/
60184
+ (CCColor *)darkGrayColor;
185+
186+
/**
187+
* Returns a color object whose grayscale value is 2/3 and whose alpha value is 1.0.
188+
*
189+
* @return The CCColor object.
190+
*/
61191
+ (CCColor *)lightGrayColor;
192+
193+
/**
194+
* Returns a color object whose grayscale value is 1.0 and whose alpha value is 1.0.
195+
*
196+
* @return The CCColor object.
197+
*/
62198
+ (CCColor *)whiteColor;
199+
200+
/**
201+
* Returns a color object whose grayscale value is 0.5 and whose alpha value is 1.0.
202+
*
203+
* @return The CCColor object.
204+
*/
63205
+ (CCColor *)grayColor;
206+
207+
/**
208+
* Returns a color object whose RGB values are 1.0, 0.0, and 0.0 and whose alpha value is 1.0.
209+
*
210+
* @return The CCColor object.
211+
*/
64212
+ (CCColor *)redColor;
213+
214+
/**
215+
* Returns a color object whose RGB values are 0.0, 1.0, and 0.0 and whose alpha value is 1.0.
216+
*
217+
* @return The CCColor object.
218+
*/
65219
+ (CCColor *)greenColor;
220+
221+
/**
222+
* Returns a color object whose RGB values are 0.0, 0.0, and 1.0 and whose alpha value is 1.0.
223+
*
224+
* @return The CCColor object.
225+
*/
66226
+ (CCColor *)blueColor;
227+
228+
/**
229+
* Returns a color object whose RGB values are 0.0, 1.0, and 1.0 and whose alpha value is 1.0..
230+
*
231+
* @return The CCColor object.
232+
*/
67233
+ (CCColor *)cyanColor;
234+
235+
/**
236+
* Returns a color object whose RGB values are 1.0, 1.0, and 0.0 and whose alpha value is 1.0.
237+
*
238+
* @return The CCColor object.
239+
*/
68240
+ (CCColor *)yellowColor;
241+
242+
/**
243+
* Returns a color object whose RGB values are 1.0, 0.0, and 1.0 and whose alpha value is 1.0.
244+
*
245+
* @return The CCColor object.
246+
*/
69247
+ (CCColor *)magentaColor;
248+
249+
/**
250+
* Returns a color object whose RGB values are 1.0, 0.5, and 0.0 and whose alpha value is 1.0..
251+
*
252+
* @return The CCColor object.
253+
*/
70254
+ (CCColor *)orangeColor;
255+
256+
/**
257+
* Returns a color object whose RGB values are 0.5, 0.0, and 0.5 and whose alpha value is 1.0.
258+
*
259+
* @return The CCColor object.
260+
*/
71261
+ (CCColor *)purpleColor;
262+
263+
/**
264+
* Returns a color object whose RGB values are 0.6, 0.4, and 0.2 and whose alpha value is 1.0.
265+
*
266+
* @return The CCColor object.
267+
*/
72268
+ (CCColor *)brownColor;
269+
270+
/**
271+
* Returns a color object whose RGB values are 0.0, 0.0, and 0.0 and whose alpha value is 0.0.
272+
*
273+
* @return The CCColor object.
274+
*/
73275
+ (CCColor *)clearColor;
74276

277+
/// -----------------------------------------------------------------------
278+
/// @name Accessing Color Attributes
279+
/// -----------------------------------------------------------------------
280+
281+
/** The Quartz color reference that corresponds to the CCColor color. */
75282
@property(nonatomic, readonly) CGColorRef CGColor;
76283

77284
#ifdef __CC_PLATFORM_IOS
285+
/** The UIColor color reference that corresponds to the CCColor color. */
78286
@property (nonatomic, readonly) UIColor* UIColor;
79287
#endif
80288

81289
#ifdef __CC_PLATFORM_MAC
290+
/** The NSColor color reference that corresponds to the CCColor color. */
82291
@property (nonatomic, readonly) NSColor* NSColor;
83292
#endif
84293

294+
295+
#pragma mark - Retrieving Color Information
296+
/// -----------------------------------------------------------------------
297+
/// @name Retrieving Color Information
298+
/// -----------------------------------------------------------------------
299+
85300
- (BOOL)getRed:(float *)red green:(float *)green blue:(float *)blue alpha:(float *)alpha;
86301
- (BOOL)getWhite:(float *)white alpha:(float *)alpha;
87302

303+
304+
#pragma mark - Color Helpers
305+
/// -----------------------------------------------------------------------
306+
/// @name Color Helpers
307+
/// -----------------------------------------------------------------------
308+
88309
/**
89310
* Linearly interpolate from this color to 'toColor'. Parameter t is normalised
90311
*
@@ -97,6 +318,9 @@
97318

98319
@end
99320

321+
322+
#pragma mark - OpenGL Category
323+
// Helper category for OpenGL compatible color creating/accessing.
100324
@interface CCColor (OpenGL)
101325

102326
+ (CCColor*)colorWithCcColor3b: (ccColor3B) c;
@@ -113,13 +337,24 @@
113337

114338
@end
115339

340+
341+
#pragma mark - ExtraProperties Category
342+
// Convenience category for accessing properties.
343+
116344
@interface CCColor (ExtraProperties)
117345

118346
@property (nonatomic, readonly) float red;
119347
@property (nonatomic, readonly) float green;
120348
@property (nonatomic, readonly) float blue;
121349
@property (nonatomic, readonly) float alpha;
122350

351+
352+
// Compare specified color value to current color and return match result.
353+
//
354+
// @param color Color to compare.
355+
//
356+
// @return True if color match.
357+
//
123358
- (BOOL)isEqualToColor:(CCColor*) color;
124359

125-
@end
360+
@end

0 commit comments

Comments
 (0)