]>
Commit | Line | Data |
---|---|---|
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 | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_COLOUR_H_ | |
13 | #define _WX_COLOUR_H_ | |
14 | ||
15 | #include "wx/object.h" | |
16 | #include "wx/string.h" | |
17 | ||
18 | // Colour | |
19 | class WXDLLEXPORT wxColour : public wxObject | |
20 | { | |
21 | DECLARE_DYNAMIC_CLASS(wxColour) | |
22 | public: | |
23 | // ctors | |
24 | // default | |
25 | wxColour(); | |
26 | // from RGB | |
27 | wxColour( unsigned char red, unsigned char green, unsigned char blue ) | |
28 | { Set(red, green, blue); } | |
29 | wxColour( unsigned long colRGB ) { Set(colRGB); } | |
30 | ||
31 | // implicit conversion from the colour name | |
32 | wxColour( const wxString &colourName ) { InitFromName(colourName); } | |
33 | wxColour( const char *colourName ) { InitFromName(colourName); } | |
34 | ||
35 | // copy ctors and assignment operators | |
36 | wxColour( const wxColour& col ); | |
37 | wxColour& operator = ( const wxColour& col ); | |
38 | ||
39 | // dtor | |
40 | ~wxColour(); | |
41 | ||
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 | } | |
52 | ||
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; } | |
58 | ||
59 | int GetPixel() const { return m_pixel; }; | |
60 | void SetPixel(int pixel) { m_pixel = pixel; m_isInit = true; }; | |
61 | ||
62 | inline bool operator == (const wxColour& colour) const { return (m_red == colour.m_red && m_green == colour.m_green && m_blue == colour.m_blue); } | |
63 | ||
64 | inline bool operator != (const wxColour& colour) const { return (!(m_red == colour.m_red && m_green == colour.m_green && m_blue == colour.m_blue)); } | |
65 | ||
66 | // Get colour from name or wxNullColour | |
67 | static wxColour CreateByName(const wxString& name); | |
68 | ||
69 | // Allocate a colour, or nearest colour, using the given display. | |
70 | // If realloc is true, ignore the existing pixel, otherwise just return | |
71 | // the existing one. | |
72 | // Returns the allocated pixel. | |
73 | ||
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. | |
76 | ||
77 | int AllocColour(WXDisplay* display, bool realloc = false); | |
78 | ||
79 | void InitFromName(const wxString& col); | |
80 | ||
81 | protected: | |
82 | // Helper function | |
83 | void Init(); | |
84 | ||
85 | private: | |
86 | bool m_isInit; | |
87 | unsigned char m_red; | |
88 | unsigned char m_blue; | |
89 | unsigned char m_green; | |
90 | ||
91 | public: | |
92 | int m_pixel; | |
93 | }; | |
94 | ||
95 | #endif | |
96 | // _WX_COLOUR_H_ |