colour.h
上传用户:hzhsqp
上传日期:2007-01-06
资源大小:1600k
文件大小:8k
- /*
- * colour.h
- *
- * Colour description.
- *
- * Portable Windows Library
- *
- * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
- *
- * The contents of this file are subject to the Mozilla Public License
- * Version 1.0 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS"
- * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
- * the License for the specific language governing rights and limitations
- * under the License.
- *
- * The Original Code is Portable Windows Library.
- *
- * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
- *
- * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
- * All Rights Reserved.
- *
- * Contributor(s): ______________________________________.
- *
- * $Log: colour.h,v $
- * Revision 1.15 1999/03/10 03:49:51 robertj
- * More documentation adjustments.
- *
- * Revision 1.14 1999/03/09 08:01:47 robertj
- * Changed comments for doc++ support (more to come).
- *
- * Revision 1.13 1999/02/16 08:08:45 robertj
- * MSVC 6.0 compatibility changes.
- *
- * Revision 1.12 1998/09/23 06:23:07 robertj
- * Added open source copyright license.
- *
- * Revision 1.11 1995/03/14 12:41:09 robertj
- * Updated documentation to use HTML codes.
- *
- * Revision 1.10 1995/01/27 11:05:33 robertj
- * Added description string.
- *
- * Revision 1.9 1994/11/29 10:13:08 robertj
- * Documentation.
- *
- * Revision 1.8 1994/11/19 00:05:00 robertj
- * Added clear standard colour.
- *
- * Revision 1.7 1994/10/23 03:51:57 robertj
- * Changed colours to have 8 bit components.
- *
- * Revision 1.6 1994/08/23 11:32:52 robertj
- * Oops
- *
- * Revision 1.5 1994/08/22 00:46:48 robertj
- * Added pragma fro GNU C++ compiler.
- *
- * Revision 1.4 1994/01/03 04:42:23 robertj
- * Mass changes to common container classes and interactors etc etc etc.
- *
- * Revision 1.3 1993/08/24 00:27:59 robertj
- * Added Grey standard colour.
- *
- * Revision 1.2 1993/07/14 12:49:16 robertj
- * Fixed RCS keywords.
- *
- */
- #define _PCOLOUR
- #ifdef __GNUC__
- #pragma interface
- #endif
- /**A class representing a colour specification. This class provides
- encapsulation for a 4 component colour. These are the amount of Red, Green,
- Blue and transparency (Alpha).
-
- This class allows for the representation of an arbitrary colour which may
- not be able to be realised on the particular drawing canvas. A descendent
- from this class called a Ref{PRealColour} always represents a colour that
- actually can be displayed. For example, for a typical printer canvas the
- only two colours possible are Black and White.
- It is up the application and its colour needs to determine if simply using
- the PColour or translating it to a PRealColour first is required.
- Note that for target drawing systems that do not support the opaqueness to
- transparency as a continuous value, zero indicates transparent and non-zero
- indicates full opaque, ie solid colour with no background.
- */
- class PColour : public PObject
- {
- PCLASSINFO(PColour, PObject);
- public:
- /**Codes for specification of standard, most common colours. These are the
- primaries plus some greys and the {it Clear} or transparent colour.
- */
- enum StandardColours {
- /// Red=0, Green=0, Blue=0, Alpha=255
- Black,
- /// Red=255, Green=0, Blue=0, Alpha=255
- Red,
- /// Red=0, Green=255, Blue=0, Alpha=255
- Green,
- /// Red=255, Green=255, Blue=0, Alpha=255
- Yellow,
- /// Red=0, Green=0, Blue=255, Alpha=255
- Blue,
- /// Red=255, Green=0, Blue=255, Alpha=255
- Magenta,
- /// Red=0, Green=255, Blue=255, Alpha=255
- Cyan,
- /// Red=255, Green=255, Blue=255, Alpha=255
- White,
- /// Red=64, Green=64, Blue=64, Alpha=255
- LightGrey,
- /// Red=128, Green=128, Blue=128, Alpha=255
- Grey,
- /// Red=192, Green=192, Blue=192, Alpha=255
- DarkGrey,
- /// Red=0, Green=0, Blue=0, Alpha=0
- Clear,
- NumStandardColours
- };
- /**Create a standard colour specification.
- */
- PColour(
- StandardColours col = Black /// Standard colour code
- );
- /** Create a colour of the specified RGB values and alpha channel. */
- PColour(
- BYTE r, /// Red component
- BYTE g, /// Green component
- BYTE b, /// Blue component
- BYTE a = 0xff /// Opaqueness, 0=fully transparent, 255=fully opaque
- );
- /**Create a colour from a description string. The description string
- simply contains the four colour components separated by commas or
- spaces. The order of the components is red, green, blue and opacity.
- */
- PColour(
- const PString & description /// Standard colour description string.
- );
- /**@name Overrides from class PObject */
- /**Create a copy of the colour. It is the callers responsibility to delete
- an object created using this funtion.
- @return
- a new PColour object with the same value.
- */
- virtual PObject * Clone() const;
- /**Determine if the two colours are the same, ie have the save values for
- all of the components.
- @return
- #EqualTo# if all componets equal, #GreaterThan#
- otherwise.
- */
- virtual Comparison Compare(
- const PObject & obj /// PColour object to compare against
- ) const;
- /**Default hash function for putting colours into dictionaries.
- @return
- number from 0 to 50 based on the following expression:
- begin{verbatim}
- ((Red ^ 0x55) + (Green ^ 0xaa) + (Blue ^ 0xc3))%51
- end{verbatim}
- */
- virtual PINDEX HashFunction() const;
- /**@name New functions for class */
- /**Get the colour description string. This string defines the colour as a
- string for use in configuration files etc.
- @return
- description string for colour.
- */
- PString GetDescription() const;
- /** Set the red component of the colour specification. */
- virtual void SetRed(
- BYTE r /// New value for the red component
- );
- /**Get the red component of the colour specification.
- @return
- value from 0 to 255 for the red component.
- */
- BYTE GetRed() const;
- /** Set the green component of the colour specification. */
- virtual void SetGreen(
- BYTE g /// New value for the green component
- );
- /**Get the greeen component of the colour specification.
- @return
- value from 0 to 255 for the green component.
- */
- BYTE GetGreen() const;
- /** Set the blue component of the colour specification. */
- virtual void SetBlue(
- BYTE b /// New value for the blue component
- );
- /**Get the blue component of the colour specification.
- @return
- value from 0 to 255 for the blue component.
- */
- BYTE GetBlue() const;
- /** Set the alpha (opacity) component of the colour specification. */
- virtual void SetAlpha(
- BYTE a /// New value for the opaqueness component
- );
- /**Get the opaqueness component of the colour specification.
- @return
- value from 0 to 255 for the opaqueness component.
- */
- BYTE GetAlpha() const;
- /** Component indexes for Ref{operator[]} access method. */
- enum {
- /// Red
- RedComponent,
- /// Green
- GreenComponent,
- /// Blue
- BlueComponent,
- /// Transparency
- AlphaComponent,
- NumComponents
- };
- /**Get the component specified by the index. The index may be of the
- following values: 0 for Red, 1 for Green, 2 for Blue, 3 for Alpha.
- @return
- value from 0 to 255 for the component specified.
- */
- BYTE operator[](
- PINDEX component /// Component index.
- ) const;
- /**Calculate a distance metric between the two colours in RGB colour space.
- @return
- distance metric between the colours.
- */
- long GetDistance(
- const PColour & other /// Colour to measure distance from.
- ) const;
- protected:
- /** Components of the colour */
- BYTE component[NumComponents];
- #ifdef DOC_PLUS_PLUS
- };
- #endif
- // Class declaration continued in platform specific header file ///////////////