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