27
27
#import " ccTypes.h"
28
28
29
29
/* *
30
- * Defines a CCColor to use with cocos2d .
30
+ * A CCColor object represents color and sometimes opacity (alpha value) for use with Cocos2D objects .
31
31
*/
32
- @interface CCColor : NSObject
33
- {
32
+ @interface CCColor : NSObject {
34
33
GLfloat _r;
35
34
GLfloat _g;
36
35
GLfloat _b;
37
36
GLfloat _a;
38
37
}
39
38
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
+ */
40
53
+ (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
+ */
41
65
+ (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
+ */
42
76
+ (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
+ */
43
85
+ (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
+ */
44
94
- (CCColor *)colorWithAlphaComponent : (float )alpha ;
45
95
46
96
#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
+ */
47
104
+ (CCColor *)colorWithUIColor : (UIColor*)color ;
48
105
#endif
49
106
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
+ */
50
121
- (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
+ */
51
133
- (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
+ */
52
144
- (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
+ */
53
153
- (CCColor *)initWithCGColor : (CGColorRef)cgColor ;
54
154
55
155
#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
+ */
56
163
- (CCColor *)initWithUIColor : (UIColor*)color ;
57
164
#endif
58
165
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
+ */
59
177
+ (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
+ */
60
184
+ (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
+ */
61
191
+ (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
+ */
62
198
+ (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
+ */
63
205
+ (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
+ */
64
212
+ (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
+ */
65
219
+ (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
+ */
66
226
+ (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
+ */
67
233
+ (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
+ */
68
240
+ (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
+ */
69
247
+ (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
+ */
70
254
+ (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
+ */
71
261
+ (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
+ */
72
268
+ (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
+ */
73
275
+ (CCColor *)clearColor ;
74
276
277
+ // / -----------------------------------------------------------------------
278
+ // / @name Accessing Color Attributes
279
+ // / -----------------------------------------------------------------------
280
+
281
+ /* * The Quartz color reference that corresponds to the CCColor color. */
75
282
@property (nonatomic , readonly ) CGColorRef CGColor;
76
283
77
284
#ifdef __CC_PLATFORM_IOS
285
+ /* * The UIColor color reference that corresponds to the CCColor color. */
78
286
@property (nonatomic , readonly ) UIColor* UIColor;
79
287
#endif
80
288
81
289
#ifdef __CC_PLATFORM_MAC
290
+ /* * The NSColor color reference that corresponds to the CCColor color. */
82
291
@property (nonatomic , readonly ) NSColor * NSColor ;
83
292
#endif
84
293
294
+
295
+ #pragma mark - Retrieving Color Information
296
+ // / -----------------------------------------------------------------------
297
+ // / @name Retrieving Color Information
298
+ // / -----------------------------------------------------------------------
299
+
85
300
- (BOOL )getRed : (float *)red green : (float *)green blue : (float *)blue alpha : (float *)alpha ;
86
301
- (BOOL )getWhite : (float *)white alpha : (float *)alpha ;
87
302
303
+
304
+ #pragma mark - Color Helpers
305
+ // / -----------------------------------------------------------------------
306
+ // / @name Color Helpers
307
+ // / -----------------------------------------------------------------------
308
+
88
309
/* *
89
310
* Linearly interpolate from this color to 'toColor'. Parameter t is normalised
90
311
*
97
318
98
319
@end
99
320
321
+
322
+ #pragma mark - OpenGL Category
323
+ // Helper category for OpenGL compatible color creating/accessing.
100
324
@interface CCColor (OpenGL)
101
325
102
326
+ (CCColor*)colorWithCcColor3b : (ccColor3B) c ;
113
337
114
338
@end
115
339
340
+
341
+ #pragma mark - ExtraProperties Category
342
+ // Convenience category for accessing properties.
343
+
116
344
@interface CCColor (ExtraProperties)
117
345
118
346
@property (nonatomic , readonly ) float red;
119
347
@property (nonatomic , readonly ) float green;
120
348
@property (nonatomic , readonly ) float blue;
121
349
@property (nonatomic , readonly ) float alpha;
122
350
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
+ //
123
358
- (BOOL )isEqualToColor : (CCColor*) color ;
124
359
125
- @end
360
+ @end
0 commit comments