]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/brush.cpp
fix also wxPen to use wxPenStyle,wxPenJoin,wxPenCap enums instead of plain int; remov...
[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
8f884a0d 24class wxBrushRefData: public wxGDIRefData
c801d85f 25{
58c837a4 26public:
3e6858cd 27 wxBrushRefData(const wxColour& colour = wxNullColour, wxBrushStyle style = wxBRUSHSTYLE_SOLID)
c89f5c02 28 {
3e6858cd
FM
29 m_style = style;
30 m_colour = colour;
c89f5c02 31 }
46562151 32
c89f5c02 33 wxBrushRefData( const wxBrushRefData& data )
8f884a0d 34 : wxGDIRefData()
c89f5c02
RR
35 {
36 m_style = data.m_style;
37 m_stipple = data.m_stipple;
38 m_colour = data.m_colour;
39 }
46562151 40
c89f5c02
RR
41 bool operator == (const wxBrushRefData& data) const
42 {
43 return (m_style == data.m_style &&
a3ab1c18 44 m_stipple.IsSameAs(data.m_stipple) &&
c89f5c02
RR
45 m_colour == data.m_colour);
46 }
46562151 47
3e6858cd
FM
48 wxBrushStyle m_style;
49 wxColour m_colour;
50 wxBitmap m_stipple;
c801d85f
KB
51};
52
c801d85f
KB
53//-----------------------------------------------------------------------------
54
55#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
56
57IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
58
3e6858cd 59wxBrush::wxBrush( const wxColour &colour, wxBrushStyle style )
c801d85f 60{
3e6858cd 61 m_refData = new wxBrushRefData(colour, style);
ff7b1510 62}
c801d85f 63
c801d85f
KB
64wxBrush::wxBrush( const wxBitmap &stippleBitmap )
65{
3e6858cd
FM
66 wxBrushStyle style = wxBRUSHSTYLE_STIPPLE;
67 if (stippleBitmap.GetMask())
68 style = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE;
7ecb8b06 69
3e6858cd 70 m_refData = new wxBrushRefData(*wxBLACK, style);
58c837a4 71 M_BRUSHDATA->m_stipple = stippleBitmap;
ff7b1510 72}
c801d85f 73
8bbe427f 74wxBrush::~wxBrush()
c801d85f 75{
c89f5c02 76 // m_refData unrefed in ~wxObject
ff7b1510 77}
c801d85f 78
8f884a0d 79wxGDIRefData *wxBrush::CreateGDIRefData() const
c801d85f 80{
c89f5c02 81 return new wxBrushRefData;
ff7b1510 82}
c801d85f 83
8f884a0d 84wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const
c801d85f 85{
c89f5c02 86 return new wxBrushRefData(*(wxBrushRefData *)data);
ff7b1510 87}
c801d85f 88
8f884a0d 89bool wxBrush::operator==(const wxBrush& brush) const
c801d85f 90{
46562151
WS
91 if (m_refData == brush.m_refData) return true;
92
93 if (!m_refData || !brush.m_refData) return false;
94
c89f5c02 95 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
ff7b1510 96}
c801d85f 97
3e6858cd 98wxBrushStyle wxBrush::GetStyle() const
c801d85f 99{
58c837a4
RR
100 if (m_refData == NULL)
101 {
102 wxFAIL_MSG( wxT("invalid brush") );
3e6858cd 103 return wxBRUSHSTYLE_MAX;
58c837a4 104 }
e55ad60e 105
58c837a4 106 return M_BRUSHDATA->m_style;
ff7b1510 107}
c801d85f 108
8bbe427f 109wxColour &wxBrush::GetColour() const
c801d85f 110{
58c837a4
RR
111 if (m_refData == NULL)
112 {
113 wxFAIL_MSG( wxT("invalid brush") );
114 return wxNullColour;
115 }
8bbe427f 116
58c837a4 117 return M_BRUSHDATA->m_colour;
ff7b1510 118}
c801d85f 119
8bbe427f 120wxBitmap *wxBrush::GetStipple() const
c801d85f 121{
58c837a4
RR
122 if (m_refData == NULL)
123 {
124 wxFAIL_MSG( wxT("invalid brush") );
125 return &wxNullBitmap;
126 }
8bbe427f 127
58c837a4 128 return &M_BRUSHDATA->m_stipple;
ff7b1510 129}
c801d85f 130
e55ad60e
RR
131void wxBrush::SetColour( const wxColour& col )
132{
c89f5c02 133 AllocExclusive();
46562151 134
58c837a4 135 M_BRUSHDATA->m_colour = col;
e55ad60e
RR
136}
137
1a1498c0 138void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
e55ad60e 139{
c89f5c02 140 AllocExclusive();
46562151 141
58c837a4 142 M_BRUSHDATA->m_colour.Set( r, g, b );
e55ad60e
RR
143}
144
3e6858cd 145void wxBrush::SetStyle( wxBrushStyle style )
e55ad60e 146{
c89f5c02 147 AllocExclusive();
46562151 148
58c837a4 149 M_BRUSHDATA->m_style = style;
e55ad60e
RR
150}
151
152void wxBrush::SetStipple( const wxBitmap& stipple )
153{
c89f5c02 154 AllocExclusive();
46562151 155
58c837a4 156 M_BRUSHDATA->m_stipple = stipple;
de2d2cdc
VZ
157 if (M_BRUSHDATA->m_stipple.GetMask())
158 {
3e6858cd 159 M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE;
7ecb8b06
VZ
160 }
161 else
162 {
3e6858cd 163 M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE;
7ecb8b06 164 }
e55ad60e 165}