pleyo.com

/src/trunk2/BAL/Interfaces/graphics/Color.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-6 Apple Computer, Inc.  All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  * 1. Redistributions of source code must retain the above copyright
00008  *    notice, this list of conditions and the following disclaimer.
00009  * 2. Redistributions in binary form must reproduce the above copyright
00010  *    notice, this list of conditions and the following disclaimer in the
00011  *    documentation and/or other materials provided with the distribution.
00012  *
00013  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
00014  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00015  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00016  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
00017  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00018  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00019  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00020  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00021  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00023  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
00024  */
00025 
00026 #ifndef Color_h
00027 #define Color_h
00028 
00029 #include <wtf/Platform.h>
00030 
00031 #if PLATFORM(CG)
00032 typedef struct CGColor* CGColorRef;
00033 #endif
00034 
00035 #if PLATFORM(QT)
00036 class QColor;
00037 #endif
00038 
00039 namespace WebCore {
00040 
00041 class String;
00042 class Color;
00043 
00044 typedef unsigned RGBA32;        // RGBA quadruplet
00045 
00046 RGBA32 makeRGB(int r, int g, int b);
00047 RGBA32 makeRGBA(int r, int g, int b, int a);
00048 RGBA32 makeRGBAFromHSLA(double h, double s, double l, double a);
00049 
00050 int differenceSquared(const Color&, const Color&);
00051 
00052 class Color {
00053 public:
00054     Color() : m_color(0), m_valid(false) { }
00055     Color(RGBA32 col) : m_color(col), m_valid(true) { }
00056     Color(int r, int g, int b) : m_color(makeRGB(r, g, b)), m_valid(true) { }
00057     Color(int r, int g, int b, int a) : m_color(makeRGBA(r, g, b, a)), m_valid(true) { }
00058     explicit Color(const String&);
00059     explicit Color(const char*);
00060     
00061     String name() const;
00062     void setNamedColor(const String&);
00063 
00064     bool isValid() const { return m_valid; }
00065 
00066     bool hasAlpha() const { return alpha() < 255; }
00067 
00068     int red() const { return (m_color >> 16) & 0xFF; }
00069     int green() const { return (m_color >> 8) & 0xFF; }
00070     int blue() const { return m_color & 0xFF; }
00071     int alpha() const { return (m_color >> 24) & 0xFF; }
00072     
00073     RGBA32 rgb() const { return m_color; } // Preserve the alpha.
00074     void setRGB(int r, int g, int b) { m_color = makeRGB(r, g, b); m_valid = true; }
00075     void setRGB(RGBA32 rgb) { m_color = rgb; m_valid = true; }
00076     void getRGBA(float& r, float& g, float& b, float& a) const;
00077     void getRGBA(double& r, double& g, double& b, double& a) const;
00078 
00079     Color light() const;
00080     Color dark() const;
00081 
00082     Color blend(const Color&) const;
00083     Color blendWithWhite() const;
00084 
00085 #if PLATFORM(QT)
00086     Color(const QColor&);
00087     operator QColor() const;
00088 #endif
00089 
00090     static bool parseHexColor(const String& name, RGBA32& rgb);
00091 
00092     static const RGBA32 black = 0xFF000000;
00093     static const RGBA32 white = 0xFFFFFFFF;
00094     static const RGBA32 darkGray = 0xFF808080;
00095     static const RGBA32 gray = 0xFFA0A0A0;
00096     static const RGBA32 lightGray = 0xFFC0C0C0;
00097     static const RGBA32 transparent = 0x00000000;
00098 
00099 private:
00100     RGBA32 m_color;
00101     bool m_valid : 1;
00102 };
00103 
00104 inline bool operator==(const Color& a, const Color& b)
00105 {
00106     return a.rgb() == b.rgb() && a.isValid() == b.isValid();
00107 }
00108 
00109 inline bool operator!=(const Color& a, const Color& b)
00110 {
00111     return !(a == b);
00112 }
00113 
00114 Color focusRingColor();
00115 void setFocusRingColorChangeFunction(void (*)());
00116 
00117 #if PLATFORM(CG)
00118 CGColorRef cgColor(const Color&);
00119 #endif
00120 
00121 } // namespace WebCore
00122 
00123 #endif // Color_h

Generated on Wed Nov 21 20:04:17 2007 for Origyn Web Browser by Doxygen 1.5.3

pleyo.com
pleyo.com