Oolite
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 "OOFoundation.h"
29#import "OOOpenGL.h"
30
31typedef struct
32{
33 float r, g, b, a;
35
36typedef struct
37{
38 float h, s, b, a;
40
41@interface OOColor : NSObject <NSCopying> {
42@private
43 float rgba[4];
44}
45
46+ (OOColor*)colorWithHue:(float)hue saturation:(float)saturation brightness:(float)brightness alpha:(float)alpha; // Note: hue in 0..1
47+ (OOColor*)colorWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
48+ (OOColor*)colorWithWhite:(float)white alpha:(float)alpha;
49+ (OOColor*)colorWithRGBAComponents:(OORGBAComponents)components;
50+ (OOColor*)colorWithHSBAComponents:(OOHSBAComponents)components; // Note: hue in 0..360
51
52// Flexible color creator; takes a selector name, a string with components, or an array.
53+ (OOColor*)colorWithDescription:(id)description;
54
55// Like +colorWithDescription:, but forces brightness of at least 0.5.
56+ (OOColor*)brightColorWithDescription:(id)description;
57
58/* Like +colorWithDescription:, but multiplies saturation by provided factor.
59 If the colour is an HSV dictionary, it may specify a saturation greater
60 than 1.0 to override the scaling.
61*/
62+ (OOColor*)colorWithDescription:(id)description saturationFactor:(float)factor;
63
64// Creates a colour given a string with components.
65+ (OOColor*)colorFromString:(NSString*)colorFloatString;
66
67+ (OOColor*)blackColor; // 0.0 white
68+ (OOColor*)darkGrayColor; // 0.333 white
69+ (OOColor*)lightGrayColor; // 0.667 white
70+ (OOColor*)whiteColor; // 1.0 white
71+ (OOColor*)grayColor; // 0.5 white
72+ (OOColor*)redColor; // 1.0, 0.0, 0.0 RGB
73+ (OOColor*)greenColor; // 0.0, 1.0, 0.0 RGB
74+ (OOColor*)blueColor; // 0.0, 0.0, 1.0 RGB
75+ (OOColor*)cyanColor; // 0.0, 1.0, 1.0 RGB
76+ (OOColor*)yellowColor; // 1.0, 1.0, 0.0 RGB
77+ (OOColor*)magentaColor; // 1.0, 0.0, 1.0 RGB
78+ (OOColor*)orangeColor; // 1.0, 0.5, 0.0 RGB
79+ (OOColor*)purpleColor; // 0.5, 0.0, 0.5 RGB
80+ (OOColor*)brownColor; // 0.6, 0.4, 0.2 RGB
81+ (OOColor*)clearColor; // 0.0 white, 0.0 alpha
82
83// Linear blend in working colour space (no attempt at gamma correction).
84- (OOColor*)blendedColorWithFraction:(float)fraction ofColor:(OOColor*)color;
85
86// Get the red, green, or blue components.
87- (float)redComponent;
88- (float)greenComponent;
89- (float)blueComponent;
90- (void)getRed:(float*)red green:(float*)green blue:(float*)blue alpha:(float*)alpha;
91
92- (OORGBAComponents)rgbaComponents;
93
94- (BOOL)isBlack;
95- (BOOL)isWhite;
96
97/* Get the components as hue, saturation, or brightness.
98
99 IMPORTANT: for reasons of bugwards compatibility, these return hue values
100 in the range [0, 360], but +colorWithedHue:... expects values in the
101 range [0, 1].
102*/
103- (float)hueComponent;
104- (float)saturationComponent;
105- (float)brightnessComponent;
106- (void)getHue:(float*)hue saturation:(float*)saturation brightness:(float*)brightness alpha:(float*)alpha;
107
108- (OOHSBAComponents)hsbaComponents;
109
110// Get the alpha component.
111- (float)alphaComponent;
112
113/* Returns the colour, premultiplied by its alpha channel, and with an alpha
114 of 1.0. If the reciever's alpha is 1.0, it will return itself.
115*/
116- (OOColor*)premultipliedColor;
117
118// Multiply r, g and b components of a colour by specified factor, clamped to [0..1].
119- (OOColor*)colorWithBrightnessFactor:(float)factor;
120
121// r,g,b,a array in 0..1 range.
122- (NSArray*)normalizedArray;
123
124- (NSString*)rgbaDescription;
125- (NSString*)hsbaDescription;
126
127@end
128
NSString * OORGBAComponentsDescription(OORGBAComponents components)
Definition OOColor.m:489
NSString * OOHSBAComponentsDescription(OOHSBAComponents components)
Definition OOColor.m:494
float rgba[4]
Definition OOColor.h:43