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