]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/colour.mm
Reflect changes in stc.cpp in stc.cpp.in from which it's generated.
[wxWidgets.git] / src / cocoa / colour.mm
CommitLineData
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
683b185d 7// Copyright: (c) 2003 David Elliott
526954c5 8// Licence: wxWindows licence
683b185d
DE
9/////////////////////////////////////////////////////////////////////////////
10
449c5673 11#include "wx/wxprec.h"
40989e46
WS
12
13#include "wx/colour.h"
14
449c5673 15#ifndef WX_PRECOMP
dd05139a 16 #include "wx/gdicmn.h"
449c5673 17#endif //WX_PRECOMP
683b185d 18
7fc77f30 19#include "wx/cocoa/autorelease.h"
6a5c31c2 20#include "wx/cocoa/ObjcRef.h"
7fc77f30 21
449c5673
DE
22#import <AppKit/NSColor.h>
23
211436b6 24void wxColour::Init()
683b185d 25{
211436b6
VZ
26 m_cocoaNSColor = NULL;
27 m_red =
28 m_blue =
29 m_green = 0;
683b185d
DE
30}
31
32wxColour::wxColour (const wxColour& col)
33: m_cocoaNSColor(col.m_cocoaNSColor)
34, m_red(col.m_red)
35, m_green(col.m_green)
36, m_blue(col.m_blue)
71064979 37, m_alpha(col.m_alpha)
683b185d 38{
6a5c31c2 39 wxGCSafeRetain(m_cocoaNSColor);
683b185d
DE
40}
41
d8fdd58f
DE
42wxColour::wxColour( WX_NSColor aColor )
43: m_cocoaNSColor(nil)
44{
45 Set(aColor);
46}
47
683b185d
DE
48wxColour& wxColour::operator =(const wxColour& col)
49{
6a5c31c2 50 m_cocoaNSColor = wxGCSafeRetain(col.m_cocoaNSColor);
683b185d
DE
51 m_red = col.m_red;
52 m_green = col.m_green;
53 m_blue = col.m_blue;
71064979 54 m_alpha = col.m_alpha;
683b185d
DE
55 return *this;
56}
57
683b185d
DE
58wxColour::~wxColour ()
59{
6a5c31c2 60 wxGCSafeRelease(m_cocoaNSColor);
683b185d
DE
61}
62
aea95b1c 63void wxColour::InitRGBA(unsigned char r,
71064979
VZ
64 unsigned char g,
65 unsigned char b,
66 unsigned char a)
683b185d 67{
7fc77f30 68 wxAutoNSAutoreleasePool pool;
6a5c31c2
DE
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]);
683b185d
DE
71 m_red = r;
72 m_green = g;
73 m_blue = b;
71064979 74 m_alpha = a;
683b185d
DE
75}
76
d8fdd58f
DE
77void wxColour::Set( WX_NSColor aColor )
78{
6a5c31c2
DE
79 wxGCSafeRetain(aColor);
80 wxGCSafeRelease(m_cocoaNSColor);
d8fdd58f
DE
81 m_cocoaNSColor = aColor;
82
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];
edc536d3 87 m_red = (wxUint8) ([rgbColor redComponent] * 255.0);
2692aef4 88 m_green = (wxUint8) ([rgbColor greenComponent] * 255.0);
edc536d3 89 m_blue = (wxUint8) ([rgbColor blueComponent] * 255.0);
71064979 90 m_alpha = (wxUint8) ([rgbColor alphaComponent] * 255.0);
d8fdd58f 91}