]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/colour.h
Use correct reload flags on all platforms to avoid compilation errors
[wxWidgets.git] / include / wx / colour.h
... / ...
CommitLineData
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
18class 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)
38enum {
39 wxC2S_NAME = 1, // return colour name, when possible
40 wxC2S_CSS_SYNTAX = 2, // return colour in rgb(r,g,b) syntax
41 wxC2S_HTML_SYNTAX = 4 // return colour in #rrggbb syntax
42};
43
44const unsigned char wxALPHA_TRANSPARENT = 0;
45const unsigned char wxALPHA_OPAQUE = 0xff;
46
47// a valid but fully transparent colour
48#define wxTransparentColour wxColour(0, 0, 0, wxALPHA_TRANSPARENT)
49#define wxTransparentColor wxTransparentColour
50
51// ----------------------------------------------------------------------------
52// wxVariant support
53// ----------------------------------------------------------------------------
54
55#if wxUSE_VARIANT
56#include "wx/variant.h"
57DECLARE_VARIANT_OBJECT_EXPORTED(wxColour,WXDLLIMPEXP_CORE)
58#endif
59
60//-----------------------------------------------------------------------------
61// wxColourBase: this class has no data members, just some functions to avoid
62// code redundancy in all native wxColour implementations
63//-----------------------------------------------------------------------------
64
65/* Transition from wxGDIObject to wxObject is incomplete. If your port does
66 not need the wxGDIObject machinery to handle colors, please add it to the
67 list of ports which do not need it.
68 */
69#if defined( __WXMAC__ ) || defined( __WXMSW__ ) || defined( __WXPM__ ) || defined( __WXCOCOA__ )
70#define wxCOLOUR_IS_GDIOBJECT 0
71#else
72#define wxCOLOUR_IS_GDIOBJECT 1
73#endif
74
75class WXDLLIMPEXP_CORE wxColourBase : public
76#if wxCOLOUR_IS_GDIOBJECT
77 wxGDIObject
78#else
79 wxObject
80#endif
81{
82public:
83 // type of a single colour component
84 typedef unsigned char ChannelType;
85
86 wxColourBase() {}
87 virtual ~wxColourBase() {}
88
89
90 // Set() functions
91 // ---------------
92
93 void Set(ChannelType red,
94 ChannelType green,
95 ChannelType blue,
96 ChannelType alpha = wxALPHA_OPAQUE)
97 { InitRGBA(red, green, blue, alpha); }
98
99 // implemented in colourcmn.cpp
100 bool Set(const wxString &str)
101 { return FromString(str); }
102
103 void Set(unsigned long colRGB)
104 {
105 // we don't need to know sizeof(long) here because we assume that the three
106 // least significant bytes contain the R, G and B values
107 Set((ChannelType)(0xFF & colRGB),
108 (ChannelType)(0xFF & (colRGB >> 8)),
109 (ChannelType)(0xFF & (colRGB >> 16)));
110 }
111
112
113
114 // accessors
115 // ---------
116
117 virtual ChannelType Red() const = 0;
118 virtual ChannelType Green() const = 0;
119 virtual ChannelType Blue() const = 0;
120 virtual ChannelType Alpha() const
121 { return wxALPHA_OPAQUE ; }
122
123 // implemented in colourcmn.cpp
124 virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const;
125
126 void SetRGB(wxUint32 colRGB)
127 {
128 Set((ChannelType)(0xFF & colRGB),
129 (ChannelType)(0xFF & (colRGB >> 8)),
130 (ChannelType)(0xFF & (colRGB >> 16)));
131 }
132
133 void SetRGBA(wxUint32 colRGBA)
134 {
135 Set((ChannelType)(0xFF & colRGBA),
136 (ChannelType)(0xFF & (colRGBA >> 8)),
137 (ChannelType)(0xFF & (colRGBA >> 16)),
138 (ChannelType)(0xFF & (colRGBA >> 24)));
139 }
140
141 wxUint32 GetRGB() const
142 { return Red() | (Green() << 8) | (Blue() << 16); }
143
144 wxUint32 GetRGBA() const
145 { return Red() | (Green() << 8) | (Blue() << 16) | (Alpha() << 24); }
146
147#if !wxCOLOUR_IS_GDIOBJECT
148 virtual bool IsOk() const= 0;
149
150 // older version, for backwards compatibility only (but not deprecated
151 // because it's still widely used)
152 bool Ok() const { return IsOk(); }
153#endif
154
155 // manipulation
156 // ------------
157
158 // These methods are static because they are mostly used
159 // within tight loops (where we don't want to instantiate wxColour's)
160
161 static void MakeMono (unsigned char* r, unsigned char* g, unsigned char* b, bool on);
162 static void MakeDisabled(unsigned char* r, unsigned char* g, unsigned char* b, unsigned char brightness = 255);
163 static void MakeGrey (unsigned char* r, unsigned char* g, unsigned char* b); // integer version
164 static void MakeGrey (unsigned char* r, unsigned char* g, unsigned char* b,
165 double weight_r, double weight_g, double weight_b); // floating point version
166 static unsigned char AlphaBlend (unsigned char fg, unsigned char bg, double alpha);
167 static void ChangeLightness(unsigned char* r, unsigned char* g, unsigned char* b, int ialpha);
168
169 wxColour ChangeLightness(int ialpha) const;
170
171 // old, deprecated
172 // ---------------
173
174#if WXWIN_COMPATIBILITY_2_6
175 static wxDEPRECATED( wxColour CreateByName(const wxString& name) );
176 wxDEPRECATED( void InitFromName(const wxString& col) );
177#endif
178
179protected:
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
184 virtual void
185 InitRGBA(ChannelType r, ChannelType g, ChannelType b, ChannelType a) = 0;
186
187 virtual bool FromString(const wxString& s);
188
189#if wxCOLOUR_IS_GDIOBJECT
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 }
206#endif
207};
208
209
210// wxColour <-> wxString utilities, used by wxConfig, defined in colourcmn.cpp
211WXDLLIMPEXP_CORE wxString wxToString(const wxColourBase& col);
212WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxColourBase* col);
213
214
215
216#if defined(__WXPALMOS__)
217 #include "wx/generic/colour.h"
218#elif defined(__WXMSW__)
219 #include "wx/msw/colour.h"
220#elif defined(__WXMOTIF__)
221 #include "wx/motif/colour.h"
222#elif defined(__WXGTK20__)
223 #include "wx/gtk/colour.h"
224#elif defined(__WXGTK__)
225 #include "wx/gtk1/colour.h"
226#elif defined(__WXMGL__)
227 #include "wx/generic/colour.h"
228#elif defined(__WXDFB__)
229 #include "wx/generic/colour.h"
230#elif defined(__WXX11__)
231 #include "wx/x11/colour.h"
232#elif defined(__WXMAC__)
233 #include "wx/osx/colour.h"
234#elif defined(__WXCOCOA__)
235 #include "wx/cocoa/colour.h"
236#elif defined(__WXPM__)
237 #include "wx/os2/colour.h"
238#endif
239
240#define wxColor wxColour
241
242#endif // _WX_COLOUR_H_BASE_