Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef UTCOLOR_H
00021 #define UTCOLOR_H
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include "config.h"
00025 #endif
00026
00027
00028
00029
00030
00031 #ifndef UT_TYPES_H
00032 #include "ut_types.h"
00033 #endif
00034
00035
00036 #include <string>
00037
00038
00039 #define UT_RGBCOLOR_PROXIMITY 45
00040
00041 class ABI_EXPORT UT_ColorPatImpl
00042 {
00043 public:
00044 virtual ~UT_ColorPatImpl();
00045 virtual UT_ColorPatImpl * clone() const= 0;
00046 };
00047
00048 class ABI_EXPORT UT_RGBColor
00049 {
00050 public:
00051 UT_RGBColor();
00052 UT_RGBColor(unsigned char, unsigned char, unsigned char, bool bTransparent = false);
00053 UT_RGBColor(const UT_RGBColor&);
00054
00055 UT_RGBColor(const UT_ColorPatImpl * pattern);
00056 ~UT_RGBColor();
00057 bool operator != (const UT_RGBColor &op1)
00058 {
00059 return (op1.m_red != m_red || op1.m_grn != m_grn || op1.m_blu != m_blu);
00060 }
00061
00062 bool operator == (const UT_RGBColor &op1)
00063 {
00064 return (op1.m_red == m_red && op1.m_grn == m_grn && op1.m_blu == m_blu);
00065 }
00066
00067
00068 bool operator %= (const UT_RGBColor &op1)
00069 {
00070 UT_uint32 iDiff = abs(m_red - op1.m_red) + abs(m_grn - op1.m_grn) + abs(m_blu - op1.m_blu);
00071 return (iDiff < UT_RGBCOLOR_PROXIMITY);
00072 }
00073
00074 UT_RGBColor & operator ^= (const UT_RGBColor &op1)
00075 {
00076 m_red ^= op1.m_red;
00077 m_grn ^= op1.m_grn;
00078 m_blu ^= op1.m_blu;
00079 return *this;
00080 }
00081
00082 UT_RGBColor & operator += (const unsigned char inc)
00083 {
00084 m_red += inc;
00085 m_grn += inc;
00086 m_blu += inc;
00087 return *this;
00088 }
00089
00090 UT_RGBColor & operator += (const UT_RGBColor &inc)
00091 {
00092 m_red += inc.m_red;
00093 m_grn += inc.m_grn;
00094 m_blu += inc.m_blu;
00095 return *this;
00096 }
00097
00098 UT_RGBColor & operator -= (const UT_RGBColor &inc)
00099 {
00100 m_red -= inc.m_red;
00101 m_grn -= inc.m_grn;
00102 m_blu -= inc.m_blu;
00103 return *this;
00104 }
00105
00106 UT_RGBColor & operator=(const UT_RGBColor &inc);
00107
00108 bool isTransparent() const
00109 {
00110 return m_bIsTransparent;
00111 }
00112 bool setColor(const char * pszColor);
00113
00114 bool isPattern() const
00115 {
00116 return m_patImpl != NULL;
00117 }
00118 const UT_ColorPatImpl *pattern() const
00119 {
00120 return m_patImpl;
00121 }
00122
00123 void setPattern(const UT_ColorPatImpl *p)
00124 {
00125 if(m_patImpl) {
00126 delete m_patImpl;
00127 }
00128 m_patImpl = p;
00129 }
00130
00131 unsigned char m_red;
00132 unsigned char m_grn;
00133 unsigned char m_blu;
00134 bool m_bIsTransparent;
00135 private:
00136 const UT_ColorPatImpl * m_patImpl;
00137 };
00138
00139 void UT_setColor(UT_RGBColor & col, unsigned char r, unsigned char g, unsigned char b, bool bTransparent = false);
00140 ABI_EXPORT void UT_parseColor(const char*, UT_RGBColor&);
00141 ABI_EXPORT std::string UT_colorToHex(const char*, bool bPrefix = false);
00142
00143 class ABI_EXPORT UT_HashColor
00144 {
00145 private:
00146 char m_colorBuffer[8];
00147
00148 public:
00149 UT_HashColor ();
00150 ~UT_HashColor ();
00151
00152 const char * c_str() const
00153 { return m_colorBuffer; }
00154
00155
00156
00157 const char * setColor (unsigned char r, unsigned char g, unsigned char b);
00158 const char * setColor (const UT_RGBColor & color) { return setColor (color.m_red, color.m_grn, color.m_blu); }
00159 const char * setColor (const char * color);
00160 const char * lookupNamedColor (const char * color_name);
00161 const char * setHashIfValid (const char * color_hash);
00162
00163 const UT_RGBColor rgb ();
00164 };
00165
00166
00167
00168 #ifdef TOOLKIT_GTK_ALL
00169 #include "ut_unixColor.h"
00170 #else
00171
00172 typedef void AbiNativeWidget;
00173 #endif
00174
00175 #endif