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