]>
Commit | Line | Data |
---|---|---|
a24aff65 DE |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: colour.h | |
3 | // Purpose: wxColour class | |
683b185d | 4 | // Author: David Elliott |
a24aff65 | 5 | // Modified by: |
683b185d | 6 | // Created: 2003/06/17 |
a24aff65 | 7 | // RCS-ID: $Id$ |
683b185d | 8 | // Copyright: (c) 2003 David Elliott |
65571936 | 9 | // Licence: wxWindows licence |
a24aff65 DE |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
683b185d DE |
12 | #ifndef __WX_COCOA_COLOUR_H__ |
13 | #define __WX_COCOA_COLOUR_H__ | |
a24aff65 DE |
14 | |
15 | #include "wx/object.h" | |
16 | #include "wx/string.h" | |
17 | ||
683b185d DE |
18 | // ======================================================================== |
19 | // wxColour | |
20 | // ======================================================================== | |
a24aff65 DE |
21 | class WXDLLEXPORT wxColour: public wxObject |
22 | { | |
23 | public: | |
211436b6 VZ |
24 | wxColour() { Init(); } |
25 | ||
a24aff65 | 26 | // from RGB |
683b185d DE |
27 | wxColour( unsigned char red, unsigned char green, unsigned char blue ) |
28 | : m_cocoaNSColor(NULL) | |
29 | { Set(red,green,blue); } | |
30 | wxColour( unsigned long colRGB ) | |
31 | : m_cocoaNSColor(NULL) | |
32 | { Set(colRGB); } | |
aad6765c | 33 | |
a24aff65 | 34 | // implicit conversion from the colour name |
683b185d | 35 | wxColour( const wxString &colourName ) |
683b185d DE |
36 | { InitFromName(colourName); } |
37 | wxColour( const char *colourName ) | |
683b185d | 38 | { InitFromName(wxString::FromAscii(colourName)); } |
c58ae5f2 RN |
39 | #if wxUSE_UNICODE |
40 | wxColour( const wxChar *colourName ) { InitFromName( wxString(colourName) ); } | |
41 | #endif | |
a24aff65 DE |
42 | |
43 | // copy ctors and assignment operators | |
683b185d DE |
44 | wxColour( const wxColour& col ); |
45 | wxColour& operator = ( const wxColour& col ); | |
a24aff65 | 46 | |
211436b6 | 47 | virtual ~wxColour(); |
a24aff65 | 48 | |
683b185d DE |
49 | // accessors |
50 | bool Ok() const { return m_cocoaNSColor; } | |
211436b6 | 51 | WX_NSColor GetNSColor() { return m_cocoaNSColor; } |
a24aff65 | 52 | |
683b185d DE |
53 | unsigned char Red() const { return m_red; } |
54 | unsigned char Green() const { return m_green; } | |
55 | unsigned char Blue() const { return m_blue; } | |
a24aff65 | 56 | |
683b185d DE |
57 | // comparison |
58 | bool operator == (const wxColour& colour) const | |
59 | { | |
211436b6 | 60 | // VZ: sure we want to compare NSColor objects for equality here? |
aad6765c JS |
61 | return (m_cocoaNSColor == colour.m_cocoaNSColor |
62 | && m_red == colour.m_red | |
63 | && m_green == colour.m_green | |
64 | && m_blue == colour.m_blue); | |
683b185d DE |
65 | } |
66 | bool operator != (const wxColour& colour) const | |
67 | { return !(*this == colour); } | |
a24aff65 | 68 | |
683b185d DE |
69 | // Set() functions |
70 | void Set( unsigned char red, unsigned char green, unsigned char blue ); | |
71 | void Set( unsigned long colRGB ) | |
72 | { | |
73 | // we don't need to know sizeof(long) here because we assume that the three | |
74 | // least significant bytes contain the R, G and B values | |
75 | Set((unsigned char)colRGB, | |
76 | (unsigned char)(colRGB >> 8), | |
77 | (unsigned char)(colRGB >> 16)); | |
78 | } | |
a24aff65 | 79 | |
211436b6 VZ |
80 | protected: |
81 | // puts the object in an invalid, uninitialized state | |
82 | void Init(); | |
83 | ||
84 | // create the object from name, leaves it uninitialized if it failed | |
683b185d | 85 | void InitFromName(const wxString& col); |
a24aff65 DE |
86 | |
87 | private: | |
683b185d DE |
88 | WX_NSColor m_cocoaNSColor; |
89 | unsigned char m_red; | |
90 | unsigned char m_green; | |
91 | unsigned char m_blue; | |
211436b6 VZ |
92 | |
93 | DECLARE_DYNAMIC_CLASS(wxColour) | |
a24aff65 DE |
94 | }; |
95 | ||
683b185d | 96 | #endif // __WX_COCOA_COLOUR_H__ |