]>
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(CGColorRef col
)
34 void wxColour::GetRGBColor( RGBColor
*col
) const
36 col
->red
= (m_red
<< 8) + m_red
;
37 col
->blue
= (m_blue
<< 8) + m_blue
;
38 col
->green
= (m_green
<< 8) + m_green
;
41 wxColour
& wxColour::operator=(const RGBColor
& col
)
47 wxColour
& wxColour::operator=(CGColorRef col
)
53 wxColour
& wxColour::operator=(const wxColour
& col
)
56 m_green
= col
.m_green
;
58 m_alpha
= col
.m_alpha
;
59 m_cgColour
= col
.m_cgColour
;
63 void wxColour::InitRGBA (ChannelType r
, ChannelType g
, ChannelType b
, ChannelType a
)
71 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
72 if ( CGColorCreateGenericRGB
)
73 col
= CGColorCreateGenericRGB( r
/ 255.0, g
/ 255.0, b
/ 255.0, a
/ 255.0 );
77 CGFloat components
[4] = { r
/ 255.0, g
/ 255.0, b
/ 255.0, a
/ 255.0 } ;
78 col
= CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ;
80 m_cgColour
.reset( col
);
83 void wxColour::InitRGBColor( const RGBColor
& col
)
86 m_blue
= col
.blue
>> 8;
87 m_green
= col
.green
>> 8;
88 m_alpha
= wxALPHA_OPAQUE
;
90 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
91 if ( CGColorCreateGenericRGB
)
92 cfcol
= CGColorCreateGenericRGB( col
.red
/ 65535.0, col
.green
/ 65535.0, col
.blue
/ 65535.0, 1.0 );
96 CGFloat components
[4] = { col
.red
/ 65535.0, col
.green
/ 65535.0, col
.blue
/ 65535.0, 1.0 } ;
97 cfcol
= CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ;
99 m_cgColour
.reset( cfcol
);
102 void wxColour::InitCGColorRef( CGColorRef col
)
104 m_cgColour
.reset( col
);
105 size_t noComp
= CGColorGetNumberOfComponents( col
);
106 if ( noComp
>=3 && noComp
<= 4 )
108 // TODO verify whether we really are on a RGB color space
109 const CGFloat
*components
= CGColorGetComponents( col
);
110 m_red
= (int)(components
[0]*255+0.5);
111 m_green
= (int)(components
[1]*255+0.5);
112 m_blue
= (int)(components
[2]*255+0.5);
114 m_alpha
= (int)(components
[3]*255+0.5);
116 m_alpha
= wxALPHA_OPAQUE
;
120 m_alpha
= wxALPHA_OPAQUE
;
121 m_red
= m_green
= m_blue
= 0;
125 bool wxColour::operator == (const wxColour
& colour
) const
127 return ( (IsOk() == colour
.IsOk()) && (!IsOk() ||
128 CGColorEqualToColor( m_cgColour
, colour
.m_cgColour
) ) );