]>
Commit | Line | Data |
---|---|---|
99d80019 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/colour.h | |
40989e46 | 3 | // Purpose: wxColourBase definition |
99d80019 | 4 | // Author: Julian Smart |
40989e46 | 5 | // Modified by: Francesco Montorsi |
99d80019 | 6 | // Created: |
99d80019 JS |
7 | // Copyright: Julian Smart |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
34138703 JS |
11 | #ifndef _WX_COLOUR_H_BASE_ |
12 | #define _WX_COLOUR_H_BASE_ | |
13 | ||
e45689df | 14 | #include "wx/defs.h" |
40989e46 WS |
15 | #include "wx/gdiobj.h" |
16 | ||
b5dbe15d | 17 | class WXDLLIMPEXP_FWD_CORE wxColour; |
6f5d7825 | 18 | |
9ef6890f VZ |
19 | // A macro to define the standard wxColour constructors: |
20 | // | |
21 | // It avoids the need to repeat these lines across all colour.h files, since | |
22 | // Set() is a virtual function and thus cannot be called by wxColourBase ctors | |
3d4424f7 | 23 | #define DEFINE_STD_WXCOLOUR_CONSTRUCTORS \ |
9ef6890f VZ |
24 | wxColour() { Init(); } \ |
25 | wxColour(ChannelType red, \ | |
26 | ChannelType green, \ | |
27 | ChannelType blue, \ | |
28 | ChannelType alpha = wxALPHA_OPAQUE) \ | |
29 | { Init(); Set(red, green, blue, alpha); } \ | |
30 | wxColour(unsigned long colRGB) { Init(); Set(colRGB ); } \ | |
31 | wxColour(const wxString& colourName) { Init(); Set(colourName); } \ | |
32 | wxColour(const char *colourName) { Init(); Set(colourName); } \ | |
33 | wxColour(const wchar_t *colourName) { Init(); Set(colourName); } | |
40989e46 WS |
34 | |
35 | ||
7d01c54d | 36 | // flags for wxColour -> wxString conversion (see wxColour::GetAsString) |
63a6a750 RD |
37 | enum { |
38 | wxC2S_NAME = 1, // return colour name, when possible | |
39 | wxC2S_CSS_SYNTAX = 2, // return colour in rgb(r,g,b) syntax | |
40 | wxC2S_HTML_SYNTAX = 4 // return colour in #rrggbb syntax | |
41 | }; | |
40989e46 | 42 | |
a69aabc3 SC |
43 | const unsigned char wxALPHA_TRANSPARENT = 0; |
44 | const unsigned char wxALPHA_OPAQUE = 0xff; | |
40989e46 | 45 | |
cd300ef7 VZ |
46 | // a valid but fully transparent colour |
47 | #define wxTransparentColour wxColour(0, 0, 0, wxALPHA_TRANSPARENT) | |
48 | #define wxTransparentColor wxTransparentColour | |
49 | ||
6f5d7825 RR |
50 | // ---------------------------------------------------------------------------- |
51 | // wxVariant support | |
52 | // ---------------------------------------------------------------------------- | |
53 | ||
54 | #if wxUSE_VARIANT | |
55 | #include "wx/variant.h" | |
53a2db12 | 56 | DECLARE_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLIMPEXP_CORE) |
6f5d7825 RR |
57 | #endif |
58 | ||
40989e46 WS |
59 | //----------------------------------------------------------------------------- |
60 | // wxColourBase: this class has no data members, just some functions to avoid | |
61 | // code redundancy in all native wxColour implementations | |
62 | //----------------------------------------------------------------------------- | |
63 | ||
7234425b DE |
64 | /* Transition from wxGDIObject to wxObject is incomplete. If your port does |
65 | not need the wxGDIObject machinery to handle colors, please add it to the | |
66 | list of ports which do not need it. | |
67 | */ | |
68 | #if defined( __WXMAC__ ) || defined( __WXMSW__ ) || defined( __WXPM__ ) || defined( __WXCOCOA__ ) | |
c5ad4777 SC |
69 | #define wxCOLOUR_IS_GDIOBJECT 0 |
70 | #else | |
71 | #define wxCOLOUR_IS_GDIOBJECT 1 | |
72 | #endif | |
73 | ||
53a2db12 | 74 | class WXDLLIMPEXP_CORE wxColourBase : public |
c5ad4777 SC |
75 | #if wxCOLOUR_IS_GDIOBJECT |
76 | wxGDIObject | |
77 | #else | |
78 | wxObject | |
79 | #endif | |
40989e46 | 80 | { |
40989e46 | 81 | public: |
aea95b1c VZ |
82 | // type of a single colour component |
83 | typedef unsigned char ChannelType; | |
84 | ||
40989e46 WS |
85 | wxColourBase() {} |
86 | virtual ~wxColourBase() {} | |
87 | ||
88 | ||
89 | // Set() functions | |
90 | // --------------- | |
91 | ||
aea95b1c VZ |
92 | void Set(ChannelType red, |
93 | ChannelType green, | |
94 | ChannelType blue, | |
95 | ChannelType alpha = wxALPHA_OPAQUE) | |
b0edecea | 96 | { InitRGBA(red, green, blue, alpha); } |
40989e46 WS |
97 | |
98 | // implemented in colourcmn.cpp | |
40989e46 | 99 | bool Set(const wxString &str) |
aea95b1c | 100 | { return FromString(str); } |
40989e46 WS |
101 | |
102 | void Set(unsigned long colRGB) | |
103 | { | |
104 | // we don't need to know sizeof(long) here because we assume that the three | |
105 | // least significant bytes contain the R, G and B values | |
8936f975 VZ |
106 | Set((ChannelType)(0xFF & colRGB), |
107 | (ChannelType)(0xFF & (colRGB >> 8)), | |
108 | (ChannelType)(0xFF & (colRGB >> 16))); | |
40989e46 WS |
109 | } |
110 | ||
111 | ||
112 | ||
113 | // accessors | |
114 | // --------- | |
115 | ||
aea95b1c VZ |
116 | virtual ChannelType Red() const = 0; |
117 | virtual ChannelType Green() const = 0; | |
118 | virtual ChannelType Blue() const = 0; | |
119 | virtual ChannelType Alpha() const | |
a69aabc3 | 120 | { return wxALPHA_OPAQUE ; } |
40989e46 WS |
121 | |
122 | // implemented in colourcmn.cpp | |
123 | virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const; | |
124 | ||
b0edecea VZ |
125 | void SetRGB(wxUint32 colRGB) |
126 | { | |
127 | Set((ChannelType)(0xFF & colRGB), | |
128 | (ChannelType)(0xFF & (colRGB >> 8)), | |
129 | (ChannelType)(0xFF & (colRGB >> 16))); | |
130 | } | |
131 | ||
132 | void SetRGBA(wxUint32 colRGBA) | |
133 | { | |
134 | Set((ChannelType)(0xFF & colRGBA), | |
135 | (ChannelType)(0xFF & (colRGBA >> 8)), | |
136 | (ChannelType)(0xFF & (colRGBA >> 16)), | |
137 | (ChannelType)(0xFF & (colRGBA >> 24))); | |
138 | } | |
139 | ||
140 | wxUint32 GetRGB() const | |
141 | { return Red() | (Green() << 8) | (Blue() << 16); } | |
142 | ||
143 | wxUint32 GetRGBA() const | |
144 | { return Red() | (Green() << 8) | (Blue() << 16) | (Alpha() << 24); } | |
145 | ||
c5ad4777 SC |
146 | #if !wxCOLOUR_IS_GDIOBJECT |
147 | virtual bool IsOk() const= 0; | |
53a2db12 | 148 | |
c5ad4777 SC |
149 | // older version, for backwards compatibility only (but not deprecated |
150 | // because it's still widely used) | |
151 | bool Ok() const { return IsOk(); } | |
152 | #endif | |
40989e46 | 153 | |
198c264d JS |
154 | // manipulation |
155 | // ------------ | |
cd300ef7 | 156 | |
198c264d JS |
157 | // These methods are static because they are mostly used |
158 | // within tight loops (where we don't want to instantiate wxColour's) | |
159 | ||
160 | static void MakeMono (unsigned char* r, unsigned char* g, unsigned char* b, bool on); | |
161 | static void MakeDisabled(unsigned char* r, unsigned char* g, unsigned char* b, unsigned char brightness = 255); | |
162 | static void MakeGrey (unsigned char* r, unsigned char* g, unsigned char* b); // integer version | |
cd300ef7 | 163 | static void MakeGrey (unsigned char* r, unsigned char* g, unsigned char* b, |
198c264d JS |
164 | double weight_r, double weight_g, double weight_b); // floating point version |
165 | static unsigned char AlphaBlend (unsigned char fg, unsigned char bg, double alpha); | |
166 | static void ChangeLightness(unsigned char* r, unsigned char* g, unsigned char* b, int ialpha); | |
167 | ||
168 | wxColour ChangeLightness(int ialpha) const; | |
893d540e | 169 | wxColour& MakeDisabled(unsigned char brightness = 255); |
198c264d | 170 | |
40989e46 WS |
171 | // old, deprecated |
172 | // --------------- | |
173 | ||
7d01c54d | 174 | #if WXWIN_COMPATIBILITY_2_6 |
d65e9d57 | 175 | static wxDEPRECATED( wxColour CreateByName(const wxString& name) ); |
7d01c54d WS |
176 | wxDEPRECATED( void InitFromName(const wxString& col) ); |
177 | #endif | |
aea95b1c VZ |
178 | |
179 | protected: | |
9ef6890f VZ |
180 | // Some ports need Init() and while we don't, provide a stub so that the |
181 | // ports which don't need it are not forced to define it | |
182 | void Init() { } | |
183 | ||
aea95b1c VZ |
184 | virtual void |
185 | InitRGBA(ChannelType r, ChannelType g, ChannelType b, ChannelType a) = 0; | |
186 | ||
e86d4e59 | 187 | virtual bool FromString(const wxString& s); |
8f884a0d | 188 | |
c5ad4777 | 189 | #if wxCOLOUR_IS_GDIOBJECT |
8f884a0d VZ |
190 | // wxColour doesn't use reference counted data (at least not in all ports) |
191 | // so provide stubs for the functions which need to be defined if we do use | |
192 | // them | |
193 | virtual wxGDIRefData *CreateGDIRefData() const | |
194 | { | |
195 | wxFAIL_MSG( "must be overridden if used" ); | |
196 | ||
197 | return NULL; | |
198 | } | |
199 | ||
200 | virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *WXUNUSED(data)) const | |
201 | { | |
202 | wxFAIL_MSG( "must be overridden if used" ); | |
203 | ||
204 | return NULL; | |
205 | } | |
c5ad4777 | 206 | #endif |
40989e46 WS |
207 | }; |
208 | ||
209 | ||
8b51786f VZ |
210 | // wxColour <-> wxString utilities, used by wxConfig, defined in colourcmn.cpp |
211 | WXDLLIMPEXP_CORE wxString wxToString(const wxColourBase& col); | |
212 | WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxColourBase* col); | |
213 | ||
214 | ||
e45689df | 215 | |
bd362275 | 216 | #if defined(__WXMSW__) |
aea95b1c | 217 | #include "wx/msw/colour.h" |
34138703 | 218 | #elif defined(__WXMOTIF__) |
aea95b1c | 219 | #include "wx/motif/colour.h" |
1be7a35c | 220 | #elif defined(__WXGTK20__) |
aea95b1c | 221 | #include "wx/gtk/colour.h" |
1be7a35c | 222 | #elif defined(__WXGTK__) |
aea95b1c | 223 | #include "wx/gtk1/colour.h" |
b3c86150 | 224 | #elif defined(__WXDFB__) |
aea95b1c | 225 | #include "wx/generic/colour.h" |
83df96d6 | 226 | #elif defined(__WXX11__) |
aea95b1c | 227 | #include "wx/x11/colour.h" |
34138703 | 228 | #elif defined(__WXMAC__) |
ef0e9220 | 229 | #include "wx/osx/colour.h" |
e64df9bc | 230 | #elif defined(__WXCOCOA__) |
aea95b1c | 231 | #include "wx/cocoa/colour.h" |
1777b9bb | 232 | #elif defined(__WXPM__) |
aea95b1c | 233 | #include "wx/os2/colour.h" |
34138703 JS |
234 | #endif |
235 | ||
e4a81a2e VZ |
236 | #define wxColor wxColour |
237 | ||
aea95b1c | 238 | #endif // _WX_COLOUR_H_BASE_ |