]> git.saurik.com Git - wxWidgets.git/blob - include/wx/colour.h
adding alpha to core graphics dc
[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
19 // the standard wxColour constructors;
20 // this macro avoids to repeat these lines across all colour.h files, since
21 // Set() is a virtual function and thus cannot be called by wxColourBase
22 // constructors
23 #define DEFINE_STD_WXCOLOUR_CONSTRUCTORS \
24 wxColour( unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255 ) \
25 { Set(red, green, blue, alpha); } \
26 wxColour( unsigned long colRGB ) { Set(colRGB); } \
27 wxColour(const wxString &colourName) { Set(colourName); } \
28 wxColour(const wxChar *colourName) { Set(colourName); }
29
30
31 // flags for wxColour -> wxString conversion (see wxColour::GetAsString)
32 #define wxC2S_NAME 1 // return colour name, when possible
33 #define wxC2S_CSS_SYNTAX 2 // return colour in rgb(r,g,b) syntax
34 #define wxC2S_HTML_SYNTAX 4 // return colour in #rrggbb syntax
35
36
37 class WXDLLEXPORT wxColour;
38
39
40 //-----------------------------------------------------------------------------
41 // wxColourBase: this class has no data members, just some functions to avoid
42 // code redundancy in all native wxColour implementations
43 //-----------------------------------------------------------------------------
44
45 class WXDLLEXPORT wxColourBase : public wxGDIObject
46 {
47 protected:
48
49 virtual void InitWith(unsigned char red, unsigned char green, unsigned char blue) = 0;
50
51 // this will be overridden in alpha supporting classes
52 virtual void InitWith(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha)
53 {
54 InitWith( red, green, blue ) ;
55 }
56
57 virtual bool FromString(const wxChar *);
58
59 public:
60 wxColourBase() {}
61 virtual ~wxColourBase() {}
62
63
64 // Set() functions
65 // ---------------
66
67 void Set(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255)
68 { InitWith(red,green,blue, alpha); }
69
70 // implemented in colourcmn.cpp
71 bool Set(const wxChar *str)
72 { return FromString(str); }
73
74 bool Set(const wxString &str)
75 { return Set((const wxChar *)str); }
76
77 void Set(unsigned long colRGB)
78 {
79 // we don't need to know sizeof(long) here because we assume that the three
80 // least significant bytes contain the R, G and B values
81 Set((unsigned char)colRGB,
82 (unsigned char)(colRGB >> 8),
83 (unsigned char)(colRGB >> 16));
84 }
85
86
87
88 // accessors
89 // ---------
90
91 virtual bool Ok() const = 0;
92
93 virtual unsigned char Red() const = 0;
94 virtual unsigned char Green() const = 0;
95 virtual unsigned char Blue() const = 0;
96 virtual unsigned char Alpha() const
97 { return 255 ; }
98
99 // implemented in colourcmn.cpp
100 virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const;
101
102
103
104 // old, deprecated
105 // ---------------
106
107 #if WXWIN_COMPATIBILITY_2_6
108 wxDEPRECATED( static wxColour CreateByName(const wxString& name) );
109 wxDEPRECATED( void InitFromName(const wxString& col) );
110 #endif
111 };
112
113
114
115 #if defined(__WXPALMOS__)
116 #include "wx/generic/colour.h"
117 #elif defined(__WXMSW__)
118 #include "wx/msw/colour.h"
119 #elif defined(__WXMOTIF__)
120 #include "wx/motif/colour.h"
121 #elif defined(__WXGTK20__)
122 #include "wx/gtk/colour.h"
123 #elif defined(__WXGTK__)
124 #include "wx/gtk1/colour.h"
125 #elif defined(__WXMGL__)
126 #include "wx/generic/colour.h"
127 #elif defined(__WXX11__)
128 #include "wx/x11/colour.h"
129 #elif defined(__WXMAC__)
130 #include "wx/mac/colour.h"
131 #elif defined(__WXCOCOA__)
132 #include "wx/cocoa/colour.h"
133 #elif defined(__WXPM__)
134 #include "wx/os2/colour.h"
135 #endif
136
137 #define wxColor wxColour
138
139 #endif
140 // _WX_COLOUR_H_BASE_