]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/colour.cpp
different CoreText font caches for Robin's tests
[wxWidgets.git] / src / mac / carbon / colour.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/colour.cpp
3 // Purpose: wxColour class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/colour.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/gdicmn.h"
18 #endif
19
20 #include "wx/mac/private.h"
21
22 IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject)
23
24 wxColour::wxColour(const RGBColor& col)
25 {
26 InitRGBColor(col);
27 }
28
29 wxColour::wxColour(CGColorRef col)
30 {
31 InitCGColorRef(col);
32 }
33
34 void wxColour::GetRGBColor( RGBColor *col ) const
35 {
36 col->red = (m_red << 8) + m_red;
37 col->blue = (m_blue << 8) + m_blue;
38 col->green = (m_green << 8) + m_green;
39 }
40
41 wxColour::~wxColour ()
42 {
43 }
44
45 wxColour& wxColour::operator=(const RGBColor& col)
46 {
47 InitRGBColor(col);
48 return *this;
49 }
50
51 wxColour& wxColour::operator=(CGColorRef col)
52 {
53 InitCGColorRef(col);
54 return *this;
55 }
56
57 void wxColour::InitRGBA (ChannelType r, ChannelType g, ChannelType b, ChannelType a)
58 {
59 m_red = r;
60 m_green = g;
61 m_blue = b;
62 m_alpha = a ;
63
64 CGColorRef col = 0 ;
65 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
66 if ( CGColorCreateGenericRGB )
67 col = CGColorCreateGenericRGB( r / 255.0, g / 255.0, b / 255.0, a / 255.0 );
68 else
69 #endif
70 {
71 CGFloat components[4] = { r / 255.0, g / 255.0, b / 255.0, a / 255.0 } ;
72 col = CGColorCreate( wxMacGetGenericRGBColorSpace() , components ) ;
73 }
74 m_cgColour.reset( col );
75 }
76
77 void wxColour::InitRGBColor( const RGBColor& col )
78 {
79 m_red = col.red >> 8;
80 m_blue = col.blue >> 8;
81 m_green = col.green >> 8;
82 m_alpha = wxALPHA_OPAQUE;
83 CGColorRef cfcol;
84 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
85 if ( CGColorCreateGenericRGB )
86 cfcol = CGColorCreateGenericRGB( col.red / 65535.0, col.green / 65535.0, col.blue / 65535.0, 1.0 );
87 else
88 #endif
89 {
90 CGFloat components[4] = { col.red / 65535.0, col.green / 65535.0, col.blue / 65535.0, 1.0 } ;
91 cfcol = CGColorCreate( wxMacGetGenericRGBColorSpace() , components ) ;
92 }
93 m_cgColour.reset( cfcol );
94 }
95
96 void wxColour::InitCGColorRef( CGColorRef col )
97 {
98 m_cgColour.reset( col );
99 size_t noComp = CGColorGetNumberOfComponents( col );
100 if ( noComp >=3 && noComp <= 4 )
101 {
102 // TODO verify whether we really are on a RGB color space
103 const CGFloat *components = CGColorGetComponents( col );
104 m_red = (int)(components[0]*255+0.5);
105 m_green = (int)(components[1]*255+0.5);
106 m_blue = (int)(components[2]*255+0.5);
107 if ( noComp == 4 )
108 m_alpha = (int)(components[3]*255+0.5);
109 else
110 m_alpha = wxALPHA_OPAQUE;
111 }
112 else
113 {
114 m_alpha = wxALPHA_OPAQUE;
115 m_red = m_green = m_blue = 0;
116 }
117 }
118
119 bool wxColour::operator == (const wxColour& colour) const
120 {
121 return ( (IsOk() == colour.IsOk()) && (!IsOk() ||
122 CGColorEqualToColor( m_cgColour, colour.m_cgColour ) ) );
123 }
124
125