6 * Portable Windows Library
8 * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
10 * The contents of this file are subject to the Mozilla Public License
11 * Version 1.0 (the "License"); you may not use this file except in
12 * compliance with the License. You may obtain a copy of the License at
13 * http://www.mozilla.org/MPL/
15 * Software distributed under the License is distributed on an "AS IS"
16 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17 * the License for the specific language governing rights and limitations
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25 * All Rights Reserved.
27 * Contributor(s): ______________________________________.
30 * Revision 1.16 2001/05/22 12:49:32 robertj
31 * Did some seriously wierd rewrite of platform headers to eliminate the
32 * stupid GNU compiler warning about braces not matching.
34 * Revision 1.15 1999/03/10 03:49:51 robertj
35 * More documentation adjustments.
37 * Revision 1.14 1999/03/09 08:01:47 robertj
38 * Changed comments for doc++ support (more to come).
40 * Revision 1.13 1999/02/16 08:08:45 robertj
41 * MSVC 6.0 compatibility changes.
43 * Revision 1.12 1998/09/23 06:23:07 robertj
44 * Added open source copyright license.
46 * Revision 1.11 1995/03/14 12:41:09 robertj
47 * Updated documentation to use HTML codes.
49 * Revision 1.10 1995/01/27 11:05:33 robertj
50 * Added description string.
52 * Revision 1.9 1994/11/29 10:13:08 robertj
55 * Revision 1.8 1994/11/19 00:05:00 robertj
56 * Added clear standard colour.
58 * Revision 1.7 1994/10/23 03:51:57 robertj
59 * Changed colours to have 8 bit components.
61 * Revision 1.6 1994/08/23 11:32:52 robertj
64 * Revision 1.5 1994/08/22 00:46:48 robertj
65 * Added pragma fro GNU C++ compiler.
67 * Revision 1.4 1994/01/03 04:42:23 robertj
68 * Mass changes to common container classes and interactors etc etc etc.
70 * Revision 1.3 1993/08/24 00:27:59 robertj
71 * Added Grey standard colour.
73 * Revision 1.2 1993/07/14 12:49:16 robertj
86 /**A class representing a colour specification. This class provides
87 encapsulation for a 4 component colour. These are the amount of Red, Green,
88 Blue and transparency (Alpha).
90 This class allows for the representation of an arbitrary colour which may
91 not be able to be realised on the particular drawing canvas. A descendent
92 from this class called a \Ref{PRealColour} always represents a colour that
93 actually can be displayed. For example, for a typical printer canvas the
94 only two colours possible are Black and White.
96 It is up the application and its colour needs to determine if simply using
97 the PColour or translating it to a PRealColour first is required.
99 Note that for target drawing systems that do not support the opaqueness to
100 transparency as a continuous value, zero indicates transparent and non-zero
101 indicates full opaque, ie solid colour with no background.
103 class PColour
: public PObject
105 PCLASSINFO(PColour
, PObject
);
108 /**Codes for specification of standard, most common colours. These are the
109 primaries plus some greys and the {\it Clear} or transparent colour.
111 enum StandardColours
{
112 /// Red=0, Green=0, Blue=0, Alpha=255
114 /// Red=255, Green=0, Blue=0, Alpha=255
116 /// Red=0, Green=255, Blue=0, Alpha=255
118 /// Red=255, Green=255, Blue=0, Alpha=255
120 /// Red=0, Green=0, Blue=255, Alpha=255
122 /// Red=255, Green=0, Blue=255, Alpha=255
124 /// Red=0, Green=255, Blue=255, Alpha=255
126 /// Red=255, Green=255, Blue=255, Alpha=255
128 /// Red=64, Green=64, Blue=64, Alpha=255
130 /// Red=128, Green=128, Blue=128, Alpha=255
132 /// Red=192, Green=192, Blue=192, Alpha=255
134 /// Red=0, Green=0, Blue=0, Alpha=0
139 /**Create a standard colour specification.
142 StandardColours col
= Black
/// Standard colour code
145 /** Create a colour of the specified RGB values and alpha channel. */
147 BYTE r
, /// Red component
148 BYTE g
, /// Green component
149 BYTE b
, /// Blue component
150 BYTE a
= 0xff /// Opaqueness, 0=fully transparent, 255=fully opaque
153 /**Create a colour from a description string. The description string
154 simply contains the four colour components separated by commas or
155 spaces. The order of the components is red, green, blue and opacity.
158 const PString
& description
/// Standard colour description string.
162 /**@name Overrides from class PObject */
163 /**Create a copy of the colour. It is the callers responsibility to delete
164 an object created using this funtion.
167 a new PColour object with the same value.
169 virtual PObject
* Clone() const;
171 /**Determine if the two colours are the same, ie have the save values for
172 all of the components.
175 #EqualTo# if all componets equal, #GreaterThan#
178 virtual Comparison
Compare(
179 const PObject
& obj
/// PColour object to compare against
182 /**Default hash function for putting colours into dictionaries.
185 number from 0 to 50 based on the following expression:
187 ((Red ^ 0x55) + (Green ^ 0xaa) + (Blue ^ 0xc3))%51
190 virtual PINDEX
HashFunction() const;
193 /**@name New functions for class */
194 /**Get the colour description string. This string defines the colour as a
195 string for use in configuration files etc.
198 description string for colour.
200 PString
GetDescription() const;
202 /** Set the red component of the colour specification. */
204 BYTE r
/// New value for the red component
207 /**Get the red component of the colour specification.
210 value from 0 to 255 for the red component.
214 /** Set the green component of the colour specification. */
215 virtual void SetGreen(
216 BYTE g
/// New value for the green component
219 /**Get the greeen component of the colour specification.
222 value from 0 to 255 for the green component.
224 BYTE
GetGreen() const;
226 /** Set the blue component of the colour specification. */
227 virtual void SetBlue(
228 BYTE b
/// New value for the blue component
231 /**Get the blue component of the colour specification.
234 value from 0 to 255 for the blue component.
236 BYTE
GetBlue() const;
238 /** Set the alpha (opacity) component of the colour specification. */
239 virtual void SetAlpha(
240 BYTE a
/// New value for the opaqueness component
243 /**Get the opaqueness component of the colour specification.
246 value from 0 to 255 for the opaqueness component.
248 BYTE
GetAlpha() const;
251 /** Component indexes for \Ref{operator[]} access method. */
264 /**Get the component specified by the index. The index may be of the
265 following values: 0 for Red, 1 for Green, 2 for Blue, 3 for Alpha.
268 value from 0 to 255 for the component specified.
271 PINDEX component
/// Component index.
275 /**Calculate a distance metric between the two colours in RGB colour space.
278 distance metric between the colours.
281 const PColour
& other
/// Colour to measure distance from.
286 /** Components of the colour */
287 BYTE component
[NumComponents
];
290 // Include platform dependent part of class
291 #include <pwlib/colour.h>
295 // End Of File ///////////////////////////////////////////////////////////////