]>
Commit | Line | Data |
---|---|---|
683b185d | 1 | ///////////////////////////////////////////////////////////////////////////// |
edc536d3 | 2 | // Name: src/cococa/colour.mm |
683b185d DE |
3 | // Purpose: wxColour class |
4 | // Author: David Elliott | |
5 | // Modified by: | |
6 | // Created: 2003/06/17 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2003 David Elliott | |
edc536d3 | 9 | // Licence: wxWidgets licence |
683b185d DE |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
449c5673 | 12 | #include "wx/wxprec.h" |
40989e46 WS |
13 | |
14 | #include "wx/colour.h" | |
15 | ||
449c5673 | 16 | #ifndef WX_PRECOMP |
dd05139a | 17 | #include "wx/gdicmn.h" |
449c5673 | 18 | #endif //WX_PRECOMP |
683b185d | 19 | |
7fc77f30 DE |
20 | #include "wx/cocoa/autorelease.h" |
21 | ||
449c5673 DE |
22 | #import <AppKit/NSColor.h> |
23 | ||
683b185d DE |
24 | IMPLEMENT_DYNAMIC_CLASS(wxColour, wxObject) |
25 | ||
211436b6 | 26 | void wxColour::Init() |
683b185d | 27 | { |
211436b6 VZ |
28 | m_cocoaNSColor = NULL; |
29 | m_red = | |
30 | m_blue = | |
31 | m_green = 0; | |
683b185d DE |
32 | } |
33 | ||
34 | wxColour::wxColour (const wxColour& col) | |
35 | : m_cocoaNSColor(col.m_cocoaNSColor) | |
36 | , m_red(col.m_red) | |
37 | , m_green(col.m_green) | |
38 | , m_blue(col.m_blue) | |
39 | { | |
40 | [m_cocoaNSColor retain]; | |
41 | } | |
42 | ||
d8fdd58f DE |
43 | wxColour::wxColour( WX_NSColor aColor ) |
44 | : m_cocoaNSColor(nil) | |
45 | { | |
46 | Set(aColor); | |
47 | } | |
48 | ||
683b185d DE |
49 | wxColour& wxColour::operator =(const wxColour& col) |
50 | { | |
51 | m_cocoaNSColor = col.m_cocoaNSColor; | |
52 | m_red = col.m_red; | |
53 | m_green = col.m_green; | |
54 | m_blue = col.m_blue; | |
55 | [m_cocoaNSColor retain]; | |
56 | return *this; | |
57 | } | |
58 | ||
683b185d DE |
59 | wxColour::~wxColour () |
60 | { | |
61 | [m_cocoaNSColor release]; | |
62 | } | |
63 | ||
40989e46 | 64 | void wxColour::InitWith (unsigned char r, unsigned char g, unsigned char b) |
683b185d | 65 | { |
7fc77f30 | 66 | wxAutoNSAutoreleasePool pool; |
683b185d DE |
67 | [m_cocoaNSColor release]; |
68 | m_cocoaNSColor = [[NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0] retain]; | |
69 | m_red = r; | |
70 | m_green = g; | |
71 | m_blue = b; | |
72 | } | |
73 | ||
d8fdd58f DE |
74 | void wxColour::Set( WX_NSColor aColor ) |
75 | { | |
76 | [aColor retain]; | |
77 | [m_cocoaNSColor release]; | |
78 | m_cocoaNSColor = aColor; | |
79 | ||
80 | /* Make a temporary color in RGB format and get the values. Note that | |
81 | unless the color was actually RGB to begin with it's likely that | |
82 | these will be fairly bogus. Particulary if the color is a pattern. */ | |
83 | NSColor *rgbColor = [m_cocoaNSColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; | |
edc536d3 | 84 | m_red = (wxUint8) ([rgbColor redComponent] * 255.0); |
2692aef4 | 85 | m_green = (wxUint8) ([rgbColor greenComponent] * 255.0); |
edc536d3 | 86 | m_blue = (wxUint8) ([rgbColor blueComponent] * 255.0); |
d8fdd58f | 87 | } |