tbx  0.7.6
colour.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 
26 #ifndef tbx_colour_H
27 #define tbx_colour_H
28 
29 namespace tbx
30 {
31 
43 class Colour
44 {
45  union {
46  unsigned _colour;
47  struct { char x, r, g, b; } _k;
48  };
49 
50 public:
54  Colour(): _colour(black) {}
60  Colour(unsigned c): _colour(c) {}
71  Colour(int red, int green, int blue) {_k.r=red;_k.g=green;_k.b=blue;_k.x=0;}
72 
78  void red(int r) { _k.r = r; }
84  void green(int g) { _k.g = g; }
90  void blue(int b) { _k.b = b; }
91 
97  int red() const { return _k.r; }
103  int green() const { return _k.g; }
109  int blue() const { return _k.b; }
110 
116  operator unsigned() const { return _colour; }
123  Colour &operator=(unsigned c) { _colour = c; return *this; }
124 
128  enum { black = 0x00000000, white = 0xFFFFFF00,
129  light_red = 0x0000FF00, light_green = 0x00FF0000, light_blue = 0xFF000000,
130  magenta = 0xFFFF0000, yellow = 0x00FFFF00, cyan = 0xFFFF0000,
131  // Wimp colour equivalents
132  wimp_grey0 = 0xFFFFFF00, wimp_grey1 = 0xDDDDDD00, wimp_grey2 = 0xBBBBBB00,
133  wimp_grey3 = 0x99999900, wimp_grey4 = 0x77777700, wimp_grey5 = 0x55555500,
134  wimp_grey6 = 0x33333300, wimp_grey7 = 0x00000000,
135  wimp_dark_blue = 0x99440000, wimp_yellow = 0x00EEEE00,
136  wimp_light_green = 0x00CC0000, wimp_red = 0x0000DD00,
137  wimp_cream = 0xBBEEEE00, wimp_dark_green = 0x00885500,
138  wimp_orange = 0x00BBFF00, wimp_light_blue = 0xFFBB0000,
139  no_colour = 0xFFFFFFFF };
140 };
141 
147 {
148  int _colour;
149 
150 public:
154  WimpColour(): _colour(black) {}
160  WimpColour(int c): _colour(c) {}
161 
167  operator int() const { return _colour; }
168 
175  WimpColour &operator=(int c) { _colour = c; return *this; }
176 
180  enum { white = 0, grey0 = 0, grey1 = 1, grey2 = 2, grey3 = 3,
181  grey4 = 4, grey5 = 5, grey6 = 6, grey7 = 7, black = 7,
182  dark_blue = 8, yellow = 9, light_green = 10, red = 11, cream = 12,
183  dark_green = 13, orange = 14, light_blue = 15, no_colour = -1,
184  minimum = 0, maximum = 15 };
185 };
186 
187 };
188 
189 #endif
tbx::Colour::Colour
Colour(unsigned c)
Construct from a packed colour.
Definition: colour.h:60
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::WimpColour::WimpColour
WimpColour()
Constructor creates black WIMP colour.
Definition: colour.h:154
tbx::Colour::blue
void blue(int b)
Change the blue component of the colour.
Definition: colour.h:90
tbx::WimpColour
Class to represent a standard desktop WIMP colour.
Definition: colour.h:147
tbx::Colour::Colour
Colour(int red, int green, int blue)
Construct colour from rgb components.
Definition: colour.h:71
tbx::Colour::operator=
Colour & operator=(unsigned c)
Set the colour from an unsigned integer.
Definition: colour.h:123
tbx::Colour::Colour
Colour()
Default constructor (creates black)
Definition: colour.h:54
tbx::Colour::green
void green(int g)
Change the green component of the colour.
Definition: colour.h:84
tbx::Colour
Class to represent a RGB colour.
Definition: colour.h:44
tbx::Colour::green
int green() const
Return the amount of green in the colour.
Definition: colour.h:103
tbx::WimpColour::operator=
WimpColour & operator=(int c)
Set colour number.
Definition: colour.h:175
tbx::Colour::red
int red() const
Return the amount of red in the colour.
Definition: colour.h:97
tbx::WimpColour::WimpColour
WimpColour(int c)
Construct from an integer colour number.
Definition: colour.h:160
tbx::Colour::red
void red(int r)
Change the red component of the colour.
Definition: colour.h:78
tbx::Colour::blue
int blue() const
Return the amount of blue in the colour.
Definition: colour.h:109