]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/colour.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxColour class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "colour.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/gdicmn.h"
24 #include "wx/msw/private.h"
28 #if wxUSE_EXTENDED_RTTI
32 template<> void wxStringReadValue(const wxString &s , wxColour &data )
35 unsigned long tmp = 0;
37 if (s.Length() != 7 || s[0u] != wxT('#') ||
38 wxSscanf(s.c_str(), wxT("#%lX"), &tmp) != 1)
40 wxLogError(_("String To Colour : Incorrect colour specification : %s"),
46 data = wxColour((unsigned char) ((tmp & 0xFF0000) >> 16) ,
47 (unsigned char) ((tmp & 0x00FF00) >> 8),
48 (unsigned char) ((tmp & 0x0000FF)));
52 template<> void wxStringWriteValue(wxString &s , const wxColour &data )
54 s = wxString::Format("#%2X%2X%2X", data.Red() , data.Green() , data.Blue() ) ;
57 WX_CUSTOM_TYPE_INFO(wxColour)
61 IMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( wxColour
, wxObject
, "wx/colour.h" )
63 WX_BEGIN_PROPERTIES_TABLE(wxColour
)
64 WX_READONLY_PROPERTY( Red
, unsigned char , Red
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
65 WX_READONLY_PROPERTY( Green
, unsigned char , Green
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
66 WX_READONLY_PROPERTY( Blue
, unsigned char , Blue
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
67 WX_END_PROPERTIES_TABLE()
69 WX_CONSTRUCTOR_3( wxColour
, unsigned char , Red
, unsigned char , Green
, unsigned char , Blue
)
71 WX_BEGIN_HANDLERS_TABLE(wxColour
)
72 WX_END_HANDLERS_TABLE()
74 IMPLEMENT_DYNAMIC_CLASS(wxColour
, wxObject
)
83 m_red
= m_blue
= m_green
= 0;
86 wxColour::wxColour (unsigned char r
, unsigned char g
, unsigned char b
)
92 m_pixel
= PALETTERGB (m_red
, m_green
, m_blue
);
95 wxColour::wxColour (const wxColour
& col
)
98 m_green
= col
.m_green
;
100 m_isInit
= col
.m_isInit
;
101 m_pixel
= col
.m_pixel
;
104 wxColour
& wxColour::operator =(const wxColour
& col
)
107 m_green
= col
.m_green
;
109 m_isInit
= col
.m_isInit
;
110 m_pixel
= col
.m_pixel
;
114 void wxColour::InitFromName(const wxString
& col
)
116 wxColour
*the_colour
= wxTheColourDatabase
->FindColour (col
);
119 m_red
= the_colour
->Red ();
120 m_green
= the_colour
->Green ();
121 m_blue
= the_colour
->Blue ();
131 m_pixel
= PALETTERGB (m_red
, m_green
, m_blue
);
134 wxColour::~wxColour()
138 void wxColour::Set (unsigned char r
, unsigned char g
, unsigned char b
)
144 m_pixel
= PALETTERGB (m_red
, m_green
, m_blue
);