]>
Commit | Line | Data |
---|---|---|
9b6dbb09 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: colour.h | |
3 | // Purpose: wxColour class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
65571936 | 9 | // Licence: wxWindows licence |
9b6dbb09 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_COLOUR_H_ | |
13 | #define _WX_COLOUR_H_ | |
14 | ||
9b6dbb09 JS |
15 | #include "wx/object.h" |
16 | #include "wx/string.h" | |
17 | ||
18 | // Colour | |
e4a81a2e | 19 | class WXDLLEXPORT wxColour : public wxObject |
9b6dbb09 | 20 | { |
83df96d6 | 21 | DECLARE_DYNAMIC_CLASS(wxColour) |
9b6dbb09 | 22 | public: |
83df96d6 | 23 | // ctors |
e4a81a2e | 24 | // default |
83df96d6 | 25 | wxColour(); |
e4a81a2e | 26 | // from RGB |
564a150b VZ |
27 | wxColour( unsigned char red, unsigned char green, unsigned char blue ) |
28 | { Set(red, green, blue); } | |
83df96d6 | 29 | wxColour( unsigned long colRGB ) { Set(colRGB); } |
aad6765c | 30 | |
e4a81a2e | 31 | // implicit conversion from the colour name |
83df96d6 JS |
32 | wxColour( const wxString &colourName ) { InitFromName(colourName); } |
33 | wxColour( const char *colourName ) { InitFromName(colourName); } | |
aad6765c | 34 | |
e4a81a2e | 35 | // copy ctors and assignment operators |
83df96d6 JS |
36 | wxColour( const wxColour& col ); |
37 | wxColour& operator = ( const wxColour& col ); | |
aad6765c | 38 | |
e4a81a2e | 39 | // dtor |
83df96d6 | 40 | ~wxColour(); |
aad6765c | 41 | |
83df96d6 JS |
42 | // Set() functions |
43 | void Set( unsigned char red, unsigned char green, unsigned char blue ); | |
44 | void Set( unsigned long colRGB ) | |
45 | { | |
46 | // we don't need to know sizeof(long) here because we assume that the three | |
47 | // least significant bytes contain the R, G and B values | |
48 | Set((unsigned char)colRGB, | |
49 | (unsigned char)(colRGB >> 8), | |
50 | (unsigned char)(colRGB >> 16)); | |
51 | } | |
aad6765c | 52 | |
83df96d6 JS |
53 | // accessors |
54 | bool Ok() const {return m_isInit; } | |
55 | unsigned char Red() const { return m_red; } | |
56 | unsigned char Green() const { return m_green; } | |
57 | unsigned char Blue() const { return m_blue; } | |
aad6765c | 58 | |
83df96d6 | 59 | int GetPixel() const { return m_pixel; }; |
aad6765c JS |
60 | void SetPixel(int pixel) { m_pixel = pixel; m_isInit = true; }; |
61 | ||
83df96d6 | 62 | inline bool operator == (const wxColour& colour) const { return (m_red == colour.m_red && m_green == colour.m_green && m_blue == colour.m_blue); } |
aad6765c | 63 | |
83df96d6 | 64 | inline bool operator != (const wxColour& colour) const { return (!(m_red == colour.m_red && m_green == colour.m_green && m_blue == colour.m_blue)); } |
c0a83c51 MB |
65 | |
66 | // Get colour from name or wxNullColour | |
67 | static wxColour CreateByName(const wxString& name); | |
68 | ||
83df96d6 | 69 | // Allocate a colour, or nearest colour, using the given display. |
aad6765c | 70 | // If realloc is true, ignore the existing pixel, otherwise just return |
83df96d6 JS |
71 | // the existing one. |
72 | // Returns the allocated pixel. | |
aad6765c | 73 | |
83df96d6 JS |
74 | // TODO: can this handle mono displays? If not, we should have an extra |
75 | // flag to specify whether this should be black or white by default. | |
aad6765c JS |
76 | |
77 | int AllocColour(WXDisplay* display, bool realloc = false); | |
78 | ||
83df96d6 | 79 | void InitFromName(const wxString& col); |
aad6765c JS |
80 | |
81 | protected: | |
82 | // Helper function | |
83 | void Init(); | |
84 | ||
e4a81a2e | 85 | private: |
83df96d6 JS |
86 | bool m_isInit; |
87 | unsigned char m_red; | |
88 | unsigned char m_blue; | |
89 | unsigned char m_green; | |
aad6765c | 90 | |
e4a81a2e | 91 | public: |
83df96d6 | 92 | int m_pixel; |
9b6dbb09 JS |
93 | }; |
94 | ||
9b6dbb09 | 95 | #endif |
83df96d6 | 96 | // _WX_COLOUR_H_ |