]> git.saurik.com Git - wxWidgets.git/blame - src/x11/brush.cpp
fix contrib makefile for watcom
[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"
ed39ff57 19#include "wx/colour.h"
83df96d6 20
74dc5eb6
RR
21//-----------------------------------------------------------------------------
22// wxBrush
23//-----------------------------------------------------------------------------
83df96d6 24
74dc5eb6 25class wxBrushRefData: public wxObjectRefData
83df96d6 26{
74dc5eb6
RR
27public:
28 wxBrushRefData()
29 {
30 m_style = 0;
31 }
32
33 wxBrushRefData( const wxBrushRefData& data )
34 {
35 m_style = data.m_style;
36 m_stipple = data.m_stipple;
37 m_colour = data.m_colour;
38 }
39
40 bool operator == (const wxBrushRefData& data) const
41 {
42 return (m_style == data.m_style &&
43 m_stipple == data.m_stipple &&
44 m_colour == data.m_colour);
45 }
46
47 int m_style;
48 wxColour m_colour;
49 wxBitmap m_stipple;
50};
83df96d6 51
74dc5eb6 52//-----------------------------------------------------------------------------
83df96d6 53
74dc5eb6
RR
54#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
55
56IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
57
58wxBrush::wxBrush( const wxColour &colour, int style )
83df96d6 59{
74dc5eb6
RR
60 m_refData = new wxBrushRefData();
61 M_BRUSHDATA->m_style = style;
62 M_BRUSHDATA->m_colour = colour;
83df96d6
JS
63}
64
74dc5eb6 65wxBrush::wxBrush( const wxBitmap &stippleBitmap )
83df96d6 66{
74dc5eb6
RR
67 m_refData = new wxBrushRefData();
68 M_BRUSHDATA->m_colour = *wxBLACK;
69
70 M_BRUSHDATA->m_stipple = stippleBitmap;
71
72 if (M_BRUSHDATA->m_stipple.GetMask())
73 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
74 else
75 M_BRUSHDATA->m_style = wxSTIPPLE;
83df96d6
JS
76}
77
78wxBrush::~wxBrush()
79{
74dc5eb6 80 // m_refData unrefed in ~wxObject
83df96d6
JS
81}
82
74dc5eb6 83wxObjectRefData *wxBrush::CreateRefData() const
83df96d6 84{
74dc5eb6 85 return new wxBrushRefData;
83df96d6
JS
86}
87
74dc5eb6 88wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
83df96d6 89{
74dc5eb6
RR
90 return new wxBrushRefData(*(wxBrushRefData *)data);
91}
83df96d6 92
74dc5eb6
RR
93bool wxBrush::operator == ( const wxBrush& brush ) const
94{
95 if (m_refData == brush.m_refData) return TRUE;
96
97 if (!m_refData || !brush.m_refData) return FALSE;
98
99 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
83df96d6
JS
100}
101
74dc5eb6 102int wxBrush::GetStyle() const
83df96d6 103{
74dc5eb6 104 if (m_refData == NULL)
83df96d6 105 {
74dc5eb6
RR
106 wxFAIL_MSG( wxT("invalid brush") );
107 return 0;
83df96d6 108 }
74dc5eb6
RR
109
110 return M_BRUSHDATA->m_style;
83df96d6
JS
111}
112
74dc5eb6 113wxColour &wxBrush::GetColour() const
83df96d6 114{
74dc5eb6
RR
115 if (m_refData == NULL)
116 {
117 wxFAIL_MSG( wxT("invalid brush") );
118 return wxNullColour;
119 }
83df96d6 120
74dc5eb6 121 return M_BRUSHDATA->m_colour;
83df96d6
JS
122}
123
74dc5eb6 124wxBitmap *wxBrush::GetStipple() const
83df96d6 125{
74dc5eb6
RR
126 if (m_refData == NULL)
127 {
128 wxFAIL_MSG( wxT("invalid brush") );
129 return &wxNullBitmap;
130 }
83df96d6 131
74dc5eb6 132 return &M_BRUSHDATA->m_stipple;
83df96d6
JS
133}
134
74dc5eb6 135void wxBrush::SetColour( const wxColour& col )
83df96d6 136{
74dc5eb6
RR
137 AllocExclusive();
138
139 M_BRUSHDATA->m_colour = col;
83df96d6
JS
140}
141
74dc5eb6 142void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
83df96d6 143{
74dc5eb6
RR
144 AllocExclusive();
145
146 M_BRUSHDATA->m_colour.Set( r, g, b );
83df96d6
JS
147}
148
74dc5eb6 149void wxBrush::SetStyle( int style )
83df96d6 150{
74dc5eb6
RR
151 AllocExclusive();
152
153 M_BRUSHDATA->m_style = style;
83df96d6
JS
154}
155
74dc5eb6
RR
156void wxBrush::SetStipple( const wxBitmap& stipple )
157{
158 AllocExclusive();
159
160 M_BRUSHDATA->m_stipple = stipple;
161 if (M_BRUSHDATA->m_stipple.GetMask())
162 {
163 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
164 }
165 else
166 {
167 M_BRUSHDATA->m_style = wxSTIPPLE;
168 }
169}