]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/colour.mm
adding isFlipped to userpane
[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
7// RCS-ID: $Id$
8// Copyright: (c) 2003 David Elliott
526954c5 9// Licence: wxWindows 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 20#include "wx/cocoa/autorelease.h"
6a5c31c2 21#include "wx/cocoa/ObjcRef.h"
7fc77f30 22
449c5673
DE
23#import <AppKit/NSColor.h>
24
211436b6 25void wxColour::Init()
683b185d 26{
211436b6
VZ
27 m_cocoaNSColor = NULL;
28 m_red =
29 m_blue =
30 m_green = 0;
683b185d
DE
31}
32
33wxColour::wxColour (const wxColour& col)
34: m_cocoaNSColor(col.m_cocoaNSColor)
35, m_red(col.m_red)
36, m_green(col.m_green)
37, m_blue(col.m_blue)
71064979 38, m_alpha(col.m_alpha)
683b185d 39{
6a5c31c2 40 wxGCSafeRetain(m_cocoaNSColor);
683b185d
DE
41}
42
d8fdd58f
DE
43wxColour::wxColour( WX_NSColor aColor )
44: m_cocoaNSColor(nil)
45{
46 Set(aColor);
47}
48
683b185d
DE
49wxColour& wxColour::operator =(const wxColour& col)
50{
6a5c31c2 51 m_cocoaNSColor = wxGCSafeRetain(col.m_cocoaNSColor);
683b185d
DE
52 m_red = col.m_red;
53 m_green = col.m_green;
54 m_blue = col.m_blue;
71064979 55 m_alpha = col.m_alpha;
683b185d
DE
56 return *this;
57}
58
683b185d
DE
59wxColour::~wxColour ()
60{
6a5c31c2 61 wxGCSafeRelease(m_cocoaNSColor);
683b185d
DE
62}
63
aea95b1c 64void wxColour::InitRGBA(unsigned char r,
71064979
VZ
65 unsigned char g,
66 unsigned char b,
67 unsigned char a)
683b185d 68{
7fc77f30 69 wxAutoNSAutoreleasePool pool;
6a5c31c2
DE
70 wxGCSafeRelease(m_cocoaNSColor);
71 m_cocoaNSColor = wxGCSafeRetain([NSColor colorWithCalibratedRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a/255.0]);
683b185d
DE
72 m_red = r;
73 m_green = g;
74 m_blue = b;
71064979 75 m_alpha = a;
683b185d
DE
76}
77
d8fdd58f
DE
78void wxColour::Set( WX_NSColor aColor )
79{
6a5c31c2
DE
80 wxGCSafeRetain(aColor);
81 wxGCSafeRelease(m_cocoaNSColor);
d8fdd58f
DE
82 m_cocoaNSColor = aColor;
83
84 /* Make a temporary color in RGB format and get the values. Note that
85 unless the color was actually RGB to begin with it's likely that
86 these will be fairly bogus. Particulary if the color is a pattern. */
87 NSColor *rgbColor = [m_cocoaNSColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
edc536d3 88 m_red = (wxUint8) ([rgbColor redComponent] * 255.0);
2692aef4 89 m_green = (wxUint8) ([rgbColor greenComponent] * 255.0);
edc536d3 90 m_blue = (wxUint8) ([rgbColor blueComponent] * 255.0);
71064979 91 m_alpha = (wxUint8) ([rgbColor alphaComponent] * 255.0);
d8fdd58f 92}