]>
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( (CGFloat
)(r
/ 255.0), (CGFloat
) (g
/ 255.0), (CGFloat
) (b
/ 255.0), (CGFloat
) (a
/ 255.0) );
77 CGFloat components
[4] = { (CGFloat
)(r
/ 255.0), (CGFloat
) (g
/ 255.0), (CGFloat
) (b
/ 255.0), (CGFloat
) (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((CGFloat
)(col
.red
/ 65535.0), (CGFloat
)(col
.green
/ 65535.0),
93 (CGFloat
)(col
.blue
/ 65535.0), (CGFloat
) 1.0 );
97 CGFloat components
[4] = { (CGFloat
)(col
.red
/ 65535.0), (CGFloat
)(col
.green
/ 65535.0),
98 (CGFloat
)(col
.blue
/ 65535.0), (CGFloat
) 1.0 } ;
99 cfcol
= CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ;
101 m_cgColour
.reset( cfcol
);
104 void wxColour::InitCGColorRef( CGColorRef col
)
106 m_cgColour
.reset( col
);
107 size_t noComp
= CGColorGetNumberOfComponents( col
);
108 if ( noComp
>= 1 && noComp
<= 4 )
110 // TODO verify whether we really are on a RGB color space
111 m_alpha
= wxALPHA_OPAQUE
;
112 const CGFloat
*components
= CGColorGetComponents( col
);
115 m_red
= (int)(components
[0]*255+0.5);
116 m_green
= (int)(components
[1]*255+0.5);
117 m_blue
= (int)(components
[2]*255+0.5);
119 m_alpha
= (int)(components
[3]*255+0.5);
123 m_red
= (int)(components
[0]*255+0.5);
124 m_green
= (int)(components
[0]*255+0.5);
125 m_blue
= (int)(components
[0]*255+0.5);
130 m_alpha
= wxALPHA_OPAQUE
;
131 m_red
= m_green
= m_blue
= 0;
135 bool wxColour::operator == (const wxColour
& colour
) const
137 return ( (IsOk() == colour
.IsOk()) && (!IsOk() ||
138 CGColorEqualToColor( m_cgColour
, colour
.m_cgColour
) ) );