]> git.saurik.com Git - wxWidgets.git/blame - src/x11/brush.cpp
unapplied part of Dimitri's patch at his request
[wxWidgets.git] / src / x11 / brush.cpp
CommitLineData
83df96d6 1/////////////////////////////////////////////////////////////////////////////
7266b672 2// Name: src/x11/brush.cpp
83df96d6
JS
3// Purpose: wxBrush
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "brush.h"
14#endif
15
16#include "wx/setup.h"
17#include "wx/utils.h"
18#include "wx/brush.h"
19
74dc5eb6
RR
20//-----------------------------------------------------------------------------
21// wxBrush
22//-----------------------------------------------------------------------------
83df96d6 23
74dc5eb6 24class wxBrushRefData: public wxObjectRefData
83df96d6 25{
74dc5eb6
RR
26public:
27 wxBrushRefData()
28 {
29 m_style = 0;
30 }
31
32 wxBrushRefData( const wxBrushRefData& data )
33 {
34 m_style = data.m_style;
35 m_stipple = data.m_stipple;
36 m_colour = data.m_colour;
37 }
38
39 bool operator == (const wxBrushRefData& data) const
40 {
41 return (m_style == data.m_style &&
42 m_stipple == data.m_stipple &&
43 m_colour == data.m_colour);
44 }
45
46 int m_style;
47 wxColour m_colour;
48 wxBitmap m_stipple;
49};
83df96d6 50
74dc5eb6 51//-----------------------------------------------------------------------------
83df96d6 52
74dc5eb6
RR
53#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
54
55IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
56
57wxBrush::wxBrush( const wxColour &colour, int style )
83df96d6 58{
74dc5eb6
RR
59 m_refData = new wxBrushRefData();
60 M_BRUSHDATA->m_style = style;
61 M_BRUSHDATA->m_colour = colour;
83df96d6
JS
62}
63
74dc5eb6 64wxBrush::wxBrush( const wxBitmap &stippleBitmap )
83df96d6 65{
74dc5eb6
RR
66 m_refData = new wxBrushRefData();
67 M_BRUSHDATA->m_colour = *wxBLACK;
68
69 M_BRUSHDATA->m_stipple = stippleBitmap;
70
71 if (M_BRUSHDATA->m_stipple.GetMask())
72 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
73 else
74 M_BRUSHDATA->m_style = wxSTIPPLE;
83df96d6
JS
75}
76
77wxBrush::~wxBrush()
78{
74dc5eb6 79 // m_refData unrefed in ~wxObject
83df96d6
JS
80}
81
74dc5eb6 82wxObjectRefData *wxBrush::CreateRefData() const
83df96d6 83{
74dc5eb6 84 return new wxBrushRefData;
83df96d6
JS
85}
86
74dc5eb6 87wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
83df96d6 88{
74dc5eb6
RR
89 return new wxBrushRefData(*(wxBrushRefData *)data);
90}
83df96d6 91
74dc5eb6
RR
92bool wxBrush::operator == ( const wxBrush& brush ) const
93{
94 if (m_refData == brush.m_refData) return TRUE;
95
96 if (!m_refData || !brush.m_refData) return FALSE;
97
98 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
83df96d6
JS
99}
100
74dc5eb6 101int wxBrush::GetStyle() const
83df96d6 102{
74dc5eb6 103 if (m_refData == NULL)
83df96d6 104 {
74dc5eb6
RR
105 wxFAIL_MSG( wxT("invalid brush") );
106 return 0;
83df96d6 107 }
74dc5eb6
RR
108
109 return M_BRUSHDATA->m_style;
83df96d6
JS
110}
111
74dc5eb6 112wxColour &wxBrush::GetColour() const
83df96d6 113{
74dc5eb6
RR
114 if (m_refData == NULL)
115 {
116 wxFAIL_MSG( wxT("invalid brush") );
117 return wxNullColour;
118 }
83df96d6 119
74dc5eb6 120 return M_BRUSHDATA->m_colour;
83df96d6
JS
121}
122
74dc5eb6 123wxBitmap *wxBrush::GetStipple() const
83df96d6 124{
74dc5eb6
RR
125 if (m_refData == NULL)
126 {
127 wxFAIL_MSG( wxT("invalid brush") );
128 return &wxNullBitmap;
129 }
83df96d6 130
74dc5eb6 131 return &M_BRUSHDATA->m_stipple;
83df96d6
JS
132}
133
74dc5eb6 134void wxBrush::SetColour( const wxColour& col )
83df96d6 135{
74dc5eb6
RR
136 AllocExclusive();
137
138 M_BRUSHDATA->m_colour = col;
83df96d6
JS
139}
140
74dc5eb6 141void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
83df96d6 142{
74dc5eb6
RR
143 AllocExclusive();
144
145 M_BRUSHDATA->m_colour.Set( r, g, b );
83df96d6
JS
146}
147
74dc5eb6 148void wxBrush::SetStyle( int style )
83df96d6 149{
74dc5eb6
RR
150 AllocExclusive();
151
152 M_BRUSHDATA->m_style = style;
83df96d6
JS
153}
154
74dc5eb6
RR
155void wxBrush::SetStipple( const wxBitmap& stipple )
156{
157 AllocExclusive();
158
159 M_BRUSHDATA->m_stipple = stipple;
160 if (M_BRUSHDATA->m_stipple.GetMask())
161 {
162 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
163 }
164 else
165 {
166 M_BRUSHDATA->m_style = wxSTIPPLE;
167 }
168}