]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/core/colour.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/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/osx/private.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxColour
, wxObject
)
24 #if wxOSX_USE_COCOA_OR_CARBON
25 wxColour::wxColour(const RGBColor
& col
)
31 wxColour::wxColour(CGColorRef col
)
36 #if wxOSX_USE_COCOA_OR_CARBON
37 void wxColour::GetRGBColor( RGBColor
*col
) const
39 col
->red
= (m_red
<< 8) + m_red
;
40 col
->blue
= (m_blue
<< 8) + m_blue
;
41 col
->green
= (m_green
<< 8) + m_green
;
44 wxColour
& wxColour::operator=(const RGBColor
& col
)
51 wxColour
& wxColour::operator=(CGColorRef col
)
57 wxColour
& wxColour::operator=(const wxColour
& col
)
60 m_green
= col
.m_green
;
62 m_alpha
= col
.m_alpha
;
63 m_cgColour
= col
.m_cgColour
;
67 void wxColour::InitRGBA (ChannelType r
, ChannelType g
, ChannelType b
, ChannelType a
)
75 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
76 if ( CGColorCreateGenericRGB
!= NULL
)
77 col
= CGColorCreateGenericRGB( (CGFloat
)(r
/ 255.0), (CGFloat
) (g
/ 255.0), (CGFloat
) (b
/ 255.0), (CGFloat
) (a
/ 255.0) );
81 CGFloat components
[4] = { (CGFloat
)(r
/ 255.0), (CGFloat
) (g
/ 255.0), (CGFloat
) (b
/ 255.0), (CGFloat
) (a
/ 255.0) } ;
82 col
= CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ;
84 m_cgColour
.reset( col
);
87 #if wxOSX_USE_COCOA_OR_CARBON
88 void wxColour::InitRGBColor( const RGBColor
& col
)
91 m_blue
= col
.blue
>> 8;
92 m_green
= col
.green
>> 8;
93 m_alpha
= wxALPHA_OPAQUE
;
95 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
96 if ( CGColorCreateGenericRGB
!= NULL
)
97 cfcol
= CGColorCreateGenericRGB((CGFloat
)(col
.red
/ 65535.0), (CGFloat
)(col
.green
/ 65535.0),
98 (CGFloat
)(col
.blue
/ 65535.0), (CGFloat
) 1.0 );
102 CGFloat components
[4] = { (CGFloat
)(col
.red
/ 65535.0), (CGFloat
)(col
.green
/ 65535.0),
103 (CGFloat
)(col
.blue
/ 65535.0), (CGFloat
) 1.0 } ;
104 cfcol
= CGColorCreate( wxMacGetGenericRGBColorSpace() , components
) ;
106 m_cgColour
.reset( cfcol
);
110 void wxColour::InitCGColorRef( CGColorRef col
)
112 m_cgColour
.reset( col
);
113 size_t noComp
= CGColorGetNumberOfComponents( col
);
114 if ( noComp
>= 1 && noComp
<= 4 )
116 // TODO verify whether we really are on a RGB color space
117 m_alpha
= wxALPHA_OPAQUE
;
118 const CGFloat
*components
= CGColorGetComponents( col
);
121 m_red
= (int)(components
[0]*255+0.5);
122 m_green
= (int)(components
[1]*255+0.5);
123 m_blue
= (int)(components
[2]*255+0.5);
125 m_alpha
= (int)(components
[3]*255+0.5);
129 m_red
= (int)(components
[0]*255+0.5);
130 m_green
= (int)(components
[0]*255+0.5);
131 m_blue
= (int)(components
[0]*255+0.5);
136 m_alpha
= wxALPHA_OPAQUE
;
137 m_red
= m_green
= m_blue
= 0;
141 bool wxColour::operator == (const wxColour
& colour
) const
143 return ( (IsOk() == colour
.IsOk()) && (!IsOk() ||
144 CGColorEqualToColor( m_cgColour
, colour
.m_cgColour
) ) );