]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/dfb/brush.cpp | |
3 | // Purpose: wxBrush class implementation | |
4 | // Author: Vaclav Slavik | |
5 | // Created: 2006-08-04 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2006 REA Elektronik GmbH | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // For compilers that support precompilation, includes "wx.h". | |
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
18 | #include "wx/brush.h" | |
19 | ||
20 | #ifndef WX_PRECOMP | |
21 | #include "wx/colour.h" | |
22 | #endif | |
23 | ||
24 | ||
25 | //----------------------------------------------------------------------------- | |
26 | // wxBrush | |
27 | //----------------------------------------------------------------------------- | |
28 | ||
29 | class wxBrushRefData : public wxGDIRefData | |
30 | { | |
31 | public: | |
32 | wxBrushRefData(const wxColour& clr = wxNullColour, wxBrushStyle style = wxBRUSHSTYLE_SOLID) | |
33 | { | |
34 | m_colour = clr; | |
35 | SetStyle(style); | |
36 | } | |
37 | ||
38 | wxBrushRefData(const wxBrushRefData& data) | |
39 | { | |
40 | m_colour = data.m_colour; | |
41 | m_style = data.m_style; | |
42 | } | |
43 | ||
44 | virtual bool IsOk() const { return m_colour.IsOk(); } | |
45 | ||
46 | void SetStyle(wxBrushStyle style) | |
47 | { | |
48 | if ( style != wxSOLID && style != wxTRANSPARENT ) | |
49 | { | |
50 | wxFAIL_MSG( wxT("only wxSOLID and wxTRANSPARENT styles are supported") ); | |
51 | style = wxBRUSHSTYLE_SOLID; | |
52 | } | |
53 | ||
54 | m_style = style; | |
55 | } | |
56 | ||
57 | wxColour m_colour; | |
58 | wxBrushStyle m_style; | |
59 | }; | |
60 | ||
61 | //----------------------------------------------------------------------------- | |
62 | ||
63 | #define M_BRUSHDATA ((wxBrushRefData *)m_refData) | |
64 | ||
65 | IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject) | |
66 | ||
67 | wxBrush::wxBrush(const wxColour &colour, wxBrushStyle style) | |
68 | { | |
69 | m_refData = new wxBrushRefData(colour, style); | |
70 | } | |
71 | ||
72 | #if FUTURE_WXWIN_COMPATIBILITY_3_0 | |
73 | wxBrush::wxBrush(const wxColour& col, int style) | |
74 | { | |
75 | m_refData = new wxBrushRefData(col, (wxBrushStyle)style); | |
76 | } | |
77 | #endif | |
78 | ||
79 | wxBrush::wxBrush(const wxBitmap &stippleBitmap) | |
80 | { | |
81 | wxFAIL_MSG( wxT("brushes with stipple bitmaps not implemented") ); | |
82 | ||
83 | m_refData = new wxBrushRefData(*wxBLACK); | |
84 | } | |
85 | ||
86 | bool wxBrush::operator==(const wxBrush& brush) const | |
87 | { | |
88 | #warning "this is incorrect (MGL too)" | |
89 | return m_refData == brush.m_refData; | |
90 | } | |
91 | ||
92 | wxBrushStyle wxBrush::GetStyle() const | |
93 | { | |
94 | wxCHECK_MSG( Ok(), wxBRUSHSTYLE_INVALID, _T("invalid brush") ); | |
95 | ||
96 | return M_BRUSHDATA->m_style; | |
97 | } | |
98 | ||
99 | wxColour wxBrush::GetColour() const | |
100 | { | |
101 | wxCHECK_MSG( Ok(), wxNullColour, _T("invalid brush") ); | |
102 | ||
103 | return M_BRUSHDATA->m_colour; | |
104 | } | |
105 | ||
106 | wxBitmap *wxBrush::GetStipple() const | |
107 | { | |
108 | wxFAIL_MSG( wxT("brushes with stipple bitmaps not implemented") ); | |
109 | return &wxNullBitmap; | |
110 | } | |
111 | ||
112 | void wxBrush::SetColour(const wxColour& col) | |
113 | { | |
114 | AllocExclusive(); | |
115 | M_BRUSHDATA->m_colour = col; | |
116 | } | |
117 | ||
118 | void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b) | |
119 | { | |
120 | AllocExclusive(); | |
121 | M_BRUSHDATA->m_colour.Set(r, g, b); | |
122 | } | |
123 | ||
124 | void wxBrush::SetStyle(wxBrushStyle style) | |
125 | { | |
126 | AllocExclusive(); | |
127 | M_BRUSHDATA->SetStyle(style); | |
128 | } | |
129 | ||
130 | void wxBrush::SetStipple(const wxBitmap& WXUNUSED(stipple)) | |
131 | { | |
132 | wxFAIL_MSG( wxT("brushes with stipple bitmaps not implemented") ); | |
133 | } | |
134 | ||
135 | wxGDIRefData *wxBrush::CreateGDIRefData() const | |
136 | { | |
137 | return new wxBrushRefData; | |
138 | } | |
139 | ||
140 | wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *data) const | |
141 | { | |
142 | return new wxBrushRefData(*(wxBrushRefData *)data); | |
143 | } |