]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/colour.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/colour.cpp
3 // Purpose: wxColour class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/colour.h"
17 #include "wx/gdicmn.h"
20 #include "wx/mac/private.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxColour
, wxObject
)
24 wxColour::wxColour(const RGBColor
& col
)
29 wxColour::wxColour( const wxColour
& col
)
32 m_green
= col
.m_green
;
34 m_alpha
= col
.m_alpha
;
35 m_cgColour
= col
.m_cgColour
;
38 wxColour::wxColour(CGColorRef col
)
43 void wxColour::GetRGBColor( RGBColor
*col
) const
45 col
->red
= (m_red
<< 8) + m_red
;
46 col
->blue
= (m_blue
<< 8) + m_blue
;
47 col
->green
= (m_green
<< 8) + m_green
;
50 wxColour::~wxColour ()
54 wxColour
& wxColour::operator=(const RGBColor
& col
)
60 wxColour
& wxColour::operator=(CGColorRef col
)
66 wxColour
& wxColour::operator=(const wxColour
& col
)
69 m_green
= col
.m_green
;
71 m_alpha
= col
.m_alpha
;
72 m_cgColour
= col
.m_cgColour
;
76 void wxColour::InitRGBA (ChannelType r
, ChannelType g
, ChannelType b
, ChannelType a
)
84 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
85 if ( CGColorCreateGenericRGB
)
86 col
= CGColorCreateGenericRGB( r
/ 255.0, g
/ 255.0, b
/ 255.0, a
/ 255.0 );
90 CGFloat components
[4] = { r
/ 255.0, g
/ 255.0, b
/ 255.0, a
/ 255.0 } ;
91 col
= CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ;
93 m_cgColour
.reset( col
);
96 void wxColour::InitRGBColor( const RGBColor
& col
)
99 m_blue
= col
.blue
>> 8;
100 m_green
= col
.green
>> 8;
101 m_alpha
= wxALPHA_OPAQUE
;
103 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
104 if ( CGColorCreateGenericRGB
)
105 cfcol
= CGColorCreateGenericRGB( col
.red
/ 65535.0, col
.green
/ 65535.0, col
.blue
/ 65535.0, 1.0 );
109 CGFloat components
[4] = { col
.red
/ 65535.0, col
.green
/ 65535.0, col
.blue
/ 65535.0, 1.0 } ;
110 cfcol
= CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ;
112 m_cgColour
.reset( cfcol
);
115 void wxColour::InitCGColorRef( CGColorRef col
)
117 m_cgColour
.reset( col
);
118 size_t noComp
= CGColorGetNumberOfComponents( col
);
119 if ( noComp
>=3 && noComp
<= 4 )
121 // TODO verify whether we really are on a RGB color space
122 const CGFloat
*components
= CGColorGetComponents( col
);
123 m_red
= (int)(components
[0]*255+0.5);
124 m_green
= (int)(components
[1]*255+0.5);
125 m_blue
= (int)(components
[2]*255+0.5);
127 m_alpha
= (int)(components
[3]*255+0.5);
129 m_alpha
= wxALPHA_OPAQUE
;
133 m_alpha
= wxALPHA_OPAQUE
;
134 m_red
= m_green
= m_blue
= 0;
138 bool wxColour::operator == (const wxColour
& colour
) const
140 return ( (IsOk() == colour
.IsOk()) && (!IsOk() ||
141 CGColorEqualToColor( m_cgColour
, colour
.m_cgColour
) ) );