]>
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 JS |
6 | // Created: |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
34138703 JS |
12 | #ifndef _WX_COLOUR_H_BASE_ |
13 | #define _WX_COLOUR_H_BASE_ | |
14 | ||
e45689df | 15 | #include "wx/defs.h" |
40989e46 WS |
16 | #include "wx/gdiobj.h" |
17 | ||
18 | ||
7d01c54d | 19 | // the standard wxColour constructors; |
40989e46 WS |
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 | |
3d4424f7 | 23 | #define DEFINE_STD_WXCOLOUR_CONSTRUCTORS \ |
aea95b1c VZ |
24 | wxColour( ChannelType red, ChannelType green, ChannelType blue, \ |
25 | ChannelType alpha = wxALPHA_OPAQUE ) \ | |
3d4424f7 VS |
26 | { Set(red, green, blue, alpha); } \ |
27 | wxColour( unsigned long colRGB ) { Set(colRGB); } \ | |
28 | wxColour(const wxString &colourName) { Set(colourName); } \ | |
40989e46 WS |
29 | wxColour(const wxChar *colourName) { Set(colourName); } |
30 | ||
31 | ||
7d01c54d | 32 | // flags for wxColour -> wxString conversion (see wxColour::GetAsString) |
40989e46 WS |
33 | #define wxC2S_NAME 1 // return colour name, when possible |
34 | #define wxC2S_CSS_SYNTAX 2 // return colour in rgb(r,g,b) syntax | |
35 | #define wxC2S_HTML_SYNTAX 4 // return colour in #rrggbb syntax | |
36 | ||
37 | ||
38 | class WXDLLEXPORT wxColour; | |
39 | ||
a69aabc3 SC |
40 | const unsigned char wxALPHA_TRANSPARENT = 0; |
41 | const unsigned char wxALPHA_OPAQUE = 0xff; | |
40989e46 WS |
42 | |
43 | //----------------------------------------------------------------------------- | |
44 | // wxColourBase: this class has no data members, just some functions to avoid | |
45 | // code redundancy in all native wxColour implementations | |
46 | //----------------------------------------------------------------------------- | |
47 | ||
48 | class WXDLLEXPORT wxColourBase : public wxGDIObject | |
49 | { | |
40989e46 | 50 | public: |
aea95b1c VZ |
51 | // type of a single colour component |
52 | typedef unsigned char ChannelType; | |
53 | ||
40989e46 WS |
54 | wxColourBase() {} |
55 | virtual ~wxColourBase() {} | |
56 | ||
57 | ||
58 | // Set() functions | |
59 | // --------------- | |
60 | ||
aea95b1c VZ |
61 | void Set(ChannelType red, |
62 | ChannelType green, | |
63 | ChannelType blue, | |
64 | ChannelType alpha = wxALPHA_OPAQUE) | |
65 | { InitRGBA(red,green,blue, alpha); } | |
40989e46 WS |
66 | |
67 | // implemented in colourcmn.cpp | |
68 | bool Set(const wxChar *str) | |
69 | { return FromString(str); } | |
70 | ||
71 | bool Set(const wxString &str) | |
aea95b1c | 72 | { return FromString(str); } |
40989e46 WS |
73 | |
74 | void Set(unsigned long colRGB) | |
75 | { | |
76 | // we don't need to know sizeof(long) here because we assume that the three | |
77 | // least significant bytes contain the R, G and B values | |
aea95b1c VZ |
78 | Set((ChannelType)colRGB, |
79 | (ChannelType)(colRGB >> 8), | |
80 | (ChannelType)(colRGB >> 16)); | |
40989e46 WS |
81 | } |
82 | ||
83 | ||
84 | ||
85 | // accessors | |
86 | // --------- | |
87 | ||
88 | virtual bool Ok() const = 0; | |
89 | ||
aea95b1c VZ |
90 | virtual ChannelType Red() const = 0; |
91 | virtual ChannelType Green() const = 0; | |
92 | virtual ChannelType Blue() const = 0; | |
93 | virtual ChannelType Alpha() const | |
a69aabc3 | 94 | { return wxALPHA_OPAQUE ; } |
40989e46 WS |
95 | |
96 | // implemented in colourcmn.cpp | |
97 | virtual wxString GetAsString(long flags = wxC2S_NAME | wxC2S_CSS_SYNTAX) const; | |
98 | ||
99 | ||
100 | ||
101 | // old, deprecated | |
102 | // --------------- | |
103 | ||
7d01c54d WS |
104 | #if WXWIN_COMPATIBILITY_2_6 |
105 | wxDEPRECATED( static wxColour CreateByName(const wxString& name) ); | |
106 | wxDEPRECATED( void InitFromName(const wxString& col) ); | |
107 | #endif | |
aea95b1c VZ |
108 | |
109 | protected: | |
110 | virtual void | |
111 | InitRGBA(ChannelType r, ChannelType g, ChannelType b, ChannelType a) = 0; | |
112 | ||
113 | virtual bool FromString(const wxChar *s); | |
40989e46 WS |
114 | }; |
115 | ||
116 | ||
e45689df | 117 | |
4055ed82 | 118 | #if defined(__WXPALMOS__) |
aea95b1c | 119 | #include "wx/generic/colour.h" |
ffecfa5a | 120 | #elif defined(__WXMSW__) |
aea95b1c | 121 | #include "wx/msw/colour.h" |
34138703 | 122 | #elif defined(__WXMOTIF__) |
aea95b1c | 123 | #include "wx/motif/colour.h" |
1be7a35c | 124 | #elif defined(__WXGTK20__) |
aea95b1c | 125 | #include "wx/gtk/colour.h" |
1be7a35c | 126 | #elif defined(__WXGTK__) |
aea95b1c | 127 | #include "wx/gtk1/colour.h" |
1e6feb95 | 128 | #elif defined(__WXMGL__) |
aea95b1c | 129 | #include "wx/generic/colour.h" |
b3c86150 | 130 | #elif defined(__WXDFB__) |
aea95b1c | 131 | #include "wx/generic/colour.h" |
83df96d6 | 132 | #elif defined(__WXX11__) |
aea95b1c | 133 | #include "wx/x11/colour.h" |
34138703 | 134 | #elif defined(__WXMAC__) |
aea95b1c | 135 | #include "wx/mac/colour.h" |
e64df9bc | 136 | #elif defined(__WXCOCOA__) |
aea95b1c | 137 | #include "wx/cocoa/colour.h" |
1777b9bb | 138 | #elif defined(__WXPM__) |
aea95b1c | 139 | #include "wx/os2/colour.h" |
34138703 JS |
140 | #endif |
141 | ||
e4a81a2e VZ |
142 | #define wxColor wxColour |
143 | ||
aea95b1c | 144 | #endif // _WX_COLOUR_H_BASE_ |