1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cococa/colour.mm
3 // Purpose: wxColour class
4 // Author: David Elliott
7 // Copyright: (c) 2003 David Elliott
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
13 #include "wx/colour.h"
16 #include "wx/gdicmn.h"
19 #include "wx/cocoa/autorelease.h"
20 #include "wx/cocoa/ObjcRef.h"
22 #import <AppKit/NSColor.h>
26 m_cocoaNSColor = NULL;
32 wxColour::wxColour (const wxColour& col)
33 : m_cocoaNSColor(col.m_cocoaNSColor)
35 , m_green(col.m_green)
37 , m_alpha(col.m_alpha)
39 wxGCSafeRetain(m_cocoaNSColor);
42 wxColour::wxColour( WX_NSColor aColor )
48 wxColour& wxColour::operator =(const wxColour& col)
50 m_cocoaNSColor = wxGCSafeRetain(col.m_cocoaNSColor);
52 m_green = col.m_green;
54 m_alpha = col.m_alpha;
58 wxColour::~wxColour ()
60 wxGCSafeRelease(m_cocoaNSColor);
63 void wxColour::InitRGBA(unsigned char r,
68 wxAutoNSAutoreleasePool pool;
69 wxGCSafeRelease(m_cocoaNSColor);
70 m_cocoaNSColor = wxGCSafeRetain([NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a/255.0]);
77 void wxColour::Set( WX_NSColor aColor )
79 wxGCSafeRetain(aColor);
80 wxGCSafeRelease(m_cocoaNSColor);
81 m_cocoaNSColor = aColor;
83 /* Make a temporary color in RGB format and get the values. Note that
84 unless the color was actually RGB to begin with it's likely that
85 these will be fairly bogus. Particulary if the color is a pattern. */
86 NSColor *rgbColor = [m_cocoaNSColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
87 m_red = (wxUint8) ([rgbColor redComponent] * 255.0);
88 m_green = (wxUint8) ([rgbColor greenComponent] * 255.0);
89 m_blue = (wxUint8) ([rgbColor blueComponent] * 255.0);
90 m_alpha = (wxUint8) ([rgbColor alphaComponent] * 255.0);