]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/brush.cpp
minimize overlay area to avoid eg scrolling artifacts when using a caret
[wxWidgets.git] / src / gtk / brush.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
7ecb8b06 2// Name: src/gtk/brush.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
f96aa4d9 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
c801d85f 13#include "wx/brush.h"
7cf41a5d
WS
14
15#ifndef WX_PRECOMP
0416c418 16 #include "wx/bitmap.h"
7cf41a5d
WS
17 #include "wx/colour.h"
18#endif
c801d85f
KB
19
20//-----------------------------------------------------------------------------
21// wxBrush
22//-----------------------------------------------------------------------------
23
24class wxBrushRefData: public wxObjectRefData
25{
58c837a4 26public:
c89f5c02
RR
27 wxBrushRefData()
28 {
29 m_style = 0;
30 }
46562151 31
c89f5c02 32 wxBrushRefData( const wxBrushRefData& data )
d84afea9 33 : wxObjectRefData()
c89f5c02
RR
34 {
35 m_style = data.m_style;
36 m_stipple = data.m_stipple;
37 m_colour = data.m_colour;
38 }
46562151 39
c89f5c02
RR
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 }
46562151 46
c89f5c02
RR
47 int m_style;
48 wxColour m_colour;
49 wxBitmap m_stipple;
c801d85f
KB
50};
51
c801d85f
KB
52//-----------------------------------------------------------------------------
53
54#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
55
56IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
57
debe6624 58wxBrush::wxBrush( const wxColour &colour, int style )
c801d85f 59{
58c837a4
RR
60 m_refData = new wxBrushRefData();
61 M_BRUSHDATA->m_style = style;
62 M_BRUSHDATA->m_colour = colour;
ff7b1510 63}
c801d85f 64
c801d85f
KB
65wxBrush::wxBrush( const wxBitmap &stippleBitmap )
66{
58c837a4 67 m_refData = new wxBrushRefData();
58c837a4 68 M_BRUSHDATA->m_colour = *wxBLACK;
7ecb8b06 69
58c837a4 70 M_BRUSHDATA->m_stipple = stippleBitmap;
e1208c31 71
de2d2cdc 72 if (M_BRUSHDATA->m_stipple.GetMask())
7ecb8b06
VZ
73 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
74 else
75 M_BRUSHDATA->m_style = wxSTIPPLE;
ff7b1510 76}
c801d85f 77
8bbe427f 78wxBrush::~wxBrush()
c801d85f 79{
c89f5c02 80 // m_refData unrefed in ~wxObject
ff7b1510 81}
c801d85f 82
c89f5c02 83wxObjectRefData *wxBrush::CreateRefData() const
c801d85f 84{
c89f5c02 85 return new wxBrushRefData;
ff7b1510 86}
c801d85f 87
c89f5c02 88wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
c801d85f 89{
c89f5c02 90 return new wxBrushRefData(*(wxBrushRefData *)data);
ff7b1510 91}
c801d85f 92
c89f5c02 93bool wxBrush::operator == ( const wxBrush& brush ) const
c801d85f 94{
46562151
WS
95 if (m_refData == brush.m_refData) return true;
96
97 if (!m_refData || !brush.m_refData) return false;
98
c89f5c02 99 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
ff7b1510 100}
c801d85f 101
8bbe427f 102int wxBrush::GetStyle() const
c801d85f 103{
58c837a4
RR
104 if (m_refData == NULL)
105 {
106 wxFAIL_MSG( wxT("invalid brush") );
107 return 0;
108 }
e55ad60e 109
58c837a4 110 return M_BRUSHDATA->m_style;
ff7b1510 111}
c801d85f 112
8bbe427f 113wxColour &wxBrush::GetColour() const
c801d85f 114{
58c837a4
RR
115 if (m_refData == NULL)
116 {
117 wxFAIL_MSG( wxT("invalid brush") );
118 return wxNullColour;
119 }
8bbe427f 120
58c837a4 121 return M_BRUSHDATA->m_colour;
ff7b1510 122}
c801d85f 123
8bbe427f 124wxBitmap *wxBrush::GetStipple() const
c801d85f 125{
58c837a4
RR
126 if (m_refData == NULL)
127 {
128 wxFAIL_MSG( wxT("invalid brush") );
129 return &wxNullBitmap;
130 }
8bbe427f 131
58c837a4 132 return &M_BRUSHDATA->m_stipple;
ff7b1510 133}
c801d85f 134
e55ad60e
RR
135void wxBrush::SetColour( const wxColour& col )
136{
c89f5c02 137 AllocExclusive();
46562151 138
58c837a4 139 M_BRUSHDATA->m_colour = col;
e55ad60e
RR
140}
141
1a1498c0 142void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
e55ad60e 143{
c89f5c02 144 AllocExclusive();
46562151 145
58c837a4 146 M_BRUSHDATA->m_colour.Set( r, g, b );
e55ad60e
RR
147}
148
149void wxBrush::SetStyle( int style )
150{
c89f5c02 151 AllocExclusive();
46562151 152
58c837a4 153 M_BRUSHDATA->m_style = style;
e55ad60e
RR
154}
155
156void wxBrush::SetStipple( const wxBitmap& stipple )
157{
c89f5c02 158 AllocExclusive();
46562151 159
58c837a4 160 M_BRUSHDATA->m_stipple = stipple;
de2d2cdc
VZ
161 if (M_BRUSHDATA->m_stipple.GetMask())
162 {
7ecb8b06
VZ
163 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
164 }
165 else
166 {
167 M_BRUSHDATA->m_style = wxSTIPPLE;
168 }
e55ad60e 169}