]> git.saurik.com Git - wxWidgets.git/blob - include/wx/colour.h
Allow specifying non default port for wxFTP connections.
[wxWidgets.git] / include / wx / colour.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/colour.h
3 // Purpose: wxColourBase definition
4 // Author: Julian Smart
5 // Modified by: Francesco Montorsi
6 // Created:
7 // RCS-ID: $Id$
8 // Copyright: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_COLOUR_H_BASE_
13 #define _WX_COLOUR_H_BASE_
14
15 #include "wx/defs.h"
16 #include "wx/gdiobj.h"
17
18 class WXDLLIMPEXP_FWD_CORE wxColour;
19
20 // A macro to define the standard wxColour constructors:
21 //
22 // It avoids the need to repeat these lines across all colour.h files, since
23 // Set() is a virtual function and thus cannot be called by wxColourBase ctors
24 #define DEFINE_STD_WXCOLOUR_CONSTRUCTORS \
25 wxColour() { Init(); } \
26 wxColour(ChannelType red, \
27 ChannelType green, \
28 ChannelType blue, \
29 ChannelType alpha = wxALPHA_OPAQUE) \
30 { Init(); Set(red, green, blue, alpha); } \
31 wxColour(unsigned long colRGB) { Init(); Set(colRGB ); } \
32 wxColour(const wxString& colourName) { Init(); Set(colourName); } \
33 wxColour(const char *colourName) { Init(); Set(colourName); } \
34 wxColour(const wchar_t *colourName) { Init(); Set(colourName); }
35
36
37 // flags for wxColour -> wxString conversion (see wxColour::GetAsString)
38 #define wxC2S_NAME 1 // return colour name, when possible
39 #define wxC2S_CSS_SYNTAX 2 // return colour in rgb(r,g,b) syntax
40 #define wxC2S_HTML_SYNTAX 4 // return colour in #rrggbb syntax
41
42
43 const unsigned char wxALPHA_TRANSPARENT = 0;
44 const unsigned char wxALPHA_OPAQUE = 0xff;
45
46 // a valid but fully transparent colour
47 #define wxTransparentColour wxColour(0, 0, 0, wxALPHA_TRANSPARENT)
48 #define wxTransparentColor wxTransparentColour
49
50 // ----------------------------------------------------------------------------
51 // wxVariant support
52 // ----------------------------------------------------------------------------
53
54 #if wxUSE_VARIANT
55 #include "wx/variant.h"
56 DECLARE_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLIMPEXP_CORE)
57 #endif
58
59 //-----------------------------------------------------------------------------
60 // wxColourBase: this class has no data members, just some functions to avoid
61 // code redundancy in all native wxColour implementations
62 //-----------------------------------------------------------------------------
63
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__ )
69 #define wxCOLOUR_IS_GDIOBJECT 0
70 #else
71 #define wxCOLOUR_IS_GDIOBJECT 1
72 #endif
73
74 class WXDLLIMPEXP_CORE wxColourBase : public
75 #if wxCOLOUR_IS_GDIOBJECT
76 wxGDIObject
77 #else
78 wxObject
79 #endif
80 {
81 public:
82 // type of a single colour component
83 typedef unsigned char ChannelType;
84
85 wxColourBase() {}
86 virtual ~wxColourBase() {}
87
88
89 // Set() functions
90 // ---------------
91
92 void Set(ChannelType red,
93 ChannelType green,
94 ChannelType blue,
95 ChannelType alpha = wxALPHA_OPAQUE)
96 { InitRGBA(red, green, blue, alpha); }
97
98 // implemented in colourcmn.cpp
99 bool Set(const wxString &str)
100 { return FromString(str); }
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
106 Set((ChannelType)(0xFF & colRGB),
107 (ChannelType)(0xFF & (colRGB >> 8)),
108 (ChannelType)(0xFF & (colRGB >> 16)));
109 }
110
111
112
113 // accessors
114 // ---------
115
116 virtual ChannelType Red() const = 0;
117 virtual ChannelType Green() const = 0;
118 virtual ChannelType Blue() const = 0;
119 virtual ChannelType Alpha() const
120 { return wxALPHA_OPAQUE ; }
121
122 // implemented in colourcmn.cpp
123 virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const;
124
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
146 #if !wxCOLOUR_IS_GDIOBJECT
147 virtual bool IsOk() const= 0;
148
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
153
154 // manipulation
155 // ------------
156
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
163 static void MakeGrey (unsigned char* r, unsigned char* g, unsigned char* b,
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;
169
170 // old, deprecated
171 // ---------------
172
173 #if WXWIN_COMPATIBILITY_2_6
174 wxDEPRECATED( static wxColour CreateByName(const wxString& name) );
175 wxDEPRECATED( void InitFromName(const wxString& col) );
176 #endif
177
178 protected:
179 // Some ports need Init() and while we don't, provide a stub so that the
180 // ports which don't need it are not forced to define it
181 void Init() { }
182
183 virtual void
184 InitRGBA(ChannelType r, ChannelType g, ChannelType b, ChannelType a) = 0;
185
186 virtual bool FromString(const wxString& s);
187
188 #if wxCOLOUR_IS_GDIOBJECT
189 // wxColour doesn't use reference counted data (at least not in all ports)
190 // so provide stubs for the functions which need to be defined if we do use
191 // them
192 virtual wxGDIRefData *CreateGDIRefData() const
193 {
194 wxFAIL_MSG( "must be overridden if used" );
195
196 return NULL;
197 }
198
199 virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *WXUNUSED(data)) const
200 {
201 wxFAIL_MSG( "must be overridden if used" );
202
203 return NULL;
204 }
205 #endif
206 };
207
208
209 // wxColour <-> wxString utilities, used by wxConfig, defined in colourcmn.cpp
210 WXDLLIMPEXP_CORE wxString wxToString(const wxColourBase& col);
211 WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxColourBase* col);
212
213
214
215 #if defined(__WXPALMOS__)
216 #include "wx/generic/colour.h"
217 #elif defined(__WXMSW__)
218 #include "wx/msw/colour.h"
219 #elif defined(__WXMOTIF__)
220 #include "wx/motif/colour.h"
221 #elif defined(__WXGTK20__)
222 #include "wx/gtk/colour.h"
223 #elif defined(__WXGTK__)
224 #include "wx/gtk1/colour.h"
225 #elif defined(__WXMGL__)
226 #include "wx/generic/colour.h"
227 #elif defined(__WXDFB__)
228 #include "wx/generic/colour.h"
229 #elif defined(__WXX11__)
230 #include "wx/x11/colour.h"
231 #elif defined(__WXMAC__)
232 #include "wx/osx/colour.h"
233 #elif defined(__WXCOCOA__)
234 #include "wx/cocoa/colour.h"
235 #elif defined(__WXPM__)
236 #include "wx/os2/colour.h"
237 #endif
238
239 #define wxColor wxColour
240
241 #endif // _WX_COLOUR_H_BASE_