Line data Source code
1 0 : /*
2 :
3 : OOColor.h
4 :
5 : An RGBA colour in device colour space.
6 :
7 :
8 : Oolite
9 : Copyright (C) 2004-2013 Giles C Williams and contributors
10 :
11 : This program is free software; you can redistribute it and/or
12 : modify it under the terms of the GNU General Public License
13 : as published by the Free Software Foundation; either version 2
14 : of the License, or (at your option) any later version.
15 :
16 : This program is distributed in the hope that it will be useful,
17 : but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : GNU General Public License for more details.
20 :
21 : You should have received a copy of the GNU General Public License
22 : along with this program; if not, write to the Free Software
23 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 : MA 02110-1301, USA.
25 :
26 : */
27 :
28 : #import "OOCocoa.h"
29 : #import "OOOpenGL.h"
30 :
31 :
32 0 : typedef struct
33 : {
34 0 : float r, g, b, a;
35 : } OORGBAComponents;
36 :
37 :
38 0 : typedef struct
39 : {
40 0 : float h, s, b, a;
41 : } OOHSBAComponents;
42 :
43 :
44 0 : @interface OOColor: NSObject <NSCopying>
45 : {
46 : @private
47 : float rgba[4];
48 0 : }
49 :
50 : + (OOColor *) colorWithHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha; // Note: hue in 0..1
51 0 : + (OOColor *) colorWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
52 0 : + (OOColor *) colorWithWhite:(float)white alpha:(float)alpha;
53 0 : + (OOColor *) colorWithRGBAComponents:(OORGBAComponents)components;
54 0 : + (OOColor *) colorWithHSBAComponents:(OOHSBAComponents)components; // Note: hue in 0..360
55 0 :
56 : // Flexible color creator; takes a selector name, a string with components, or an array.
57 : + (OOColor *) colorWithDescription:(id)description;
58 0 :
59 : // Like +colorWithDescription:, but forces brightness of at least 0.5.
60 : + (OOColor *) brightColorWithDescription:(id)description;
61 0 :
62 : /* Like +colorWithDescription:, but multiplies saturation by provided factor.
63 : If the colour is an HSV dictionary, it may specify a saturation greater
64 : than 1.0 to override the scaling.
65 : */
66 : + (OOColor *) colorWithDescription:(id)description saturationFactor:(float)factor;
67 0 :
68 : // Creates a colour given a string with components.
69 : + (OOColor *) colorFromString:(NSString*) colorFloatString;
70 0 :
71 : + (OOColor *) blackColor; // 0.0 white
72 0 : + (OOColor *) darkGrayColor; // 0.333 white
73 0 : + (OOColor *) lightGrayColor; // 0.667 white
74 0 : + (OOColor *) whiteColor; // 1.0 white
75 0 : + (OOColor *) grayColor; // 0.5 white
76 0 : + (OOColor *) redColor; // 1.0, 0.0, 0.0 RGB
77 0 : + (OOColor *) greenColor; // 0.0, 1.0, 0.0 RGB
78 0 : + (OOColor *) blueColor; // 0.0, 0.0, 1.0 RGB
79 0 : + (OOColor *) cyanColor; // 0.0, 1.0, 1.0 RGB
80 0 : + (OOColor *) yellowColor; // 1.0, 1.0, 0.0 RGB
81 0 : + (OOColor *) magentaColor; // 1.0, 0.0, 1.0 RGB
82 0 : + (OOColor *) orangeColor; // 1.0, 0.5, 0.0 RGB
83 0 : + (OOColor *) purpleColor; // 0.5, 0.0, 0.5 RGB
84 0 : + (OOColor *) brownColor; // 0.6, 0.4, 0.2 RGB
85 0 : + (OOColor *) clearColor; // 0.0 white, 0.0 alpha
86 0 :
87 : // Linear blend in working colour space (no attempt at gamma correction).
88 : - (OOColor *) blendedColorWithFraction:(float)fraction ofColor:(OOColor *)color;
89 0 :
90 : // Get the red, green, or blue components.
91 : - (float) redComponent;
92 0 : - (float) greenComponent;
93 0 : - (float) blueComponent;
94 0 : - (void) getRed:(float *)red green:(float *)green blue:(float *)blue alpha:(float *)alpha;
95 0 :
96 : - (OORGBAComponents) rgbaComponents;
97 0 :
98 : - (BOOL) isBlack;
99 0 : - (BOOL) isWhite;
100 0 :
101 : /* Get the components as hue, saturation, or brightness.
102 :
103 : IMPORTANT: for reasons of bugwards compatibility, these return hue values
104 : in the range [0, 360], but +colorWithedHue:... expects values in the
105 : range [0, 1].
106 : */
107 : - (float) hueComponent;
108 0 : - (float) saturationComponent;
109 0 : - (float) brightnessComponent;
110 0 : - (void) getHue:(float *)hue saturation:(float *)saturation brightness:(float *)brightness alpha:(float *)alpha;
111 0 :
112 : - (OOHSBAComponents) hsbaComponents;
113 0 :
114 :
115 : // Get the alpha component.
116 : - (float) alphaComponent;
117 0 :
118 : /* Returns the colour, premultiplied by its alpha channel, and with an alpha
119 : of 1.0. If the reciever's alpha is 1.0, it will return itself.
120 : */
121 : - (OOColor *) premultipliedColor;
122 0 :
123 : // Multiply r, g and b components of a colour by specified factor, clamped to [0..1].
124 : - (OOColor *) colorWithBrightnessFactor:(float)factor;
125 0 :
126 : // r,g,b,a array in 0..1 range.
127 : - (NSArray *) normalizedArray;
128 0 :
129 : - (NSString *) rgbaDescription;
130 0 : - (NSString *) hsbaDescription;
131 0 :
132 : @end
133 :
134 :
135 : NSString *OORGBAComponentsDescription(OORGBAComponents components);
136 0 : NSString *OOHSBAComponentsDescription(OOHSBAComponents components);
|