]>
Commit | Line | Data |
---|---|---|
b3c86150 VS |
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 wxObjectRefData | |
30 | { | |
31 | public: | |
32 | wxBrushRefData(const wxColour& clr = wxNullColour, int style = wxSOLID) | |
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 | void SetStyle(int style) | |
45 | { | |
e17cd59f | 46 | if ( style != wxSOLID && style != wxTRANSPARENT ) |
b3c86150 VS |
47 | { |
48 | wxFAIL_MSG( _T("only wxSOLID and wxTRANSPARENT styles are supported") ); | |
49 | style = wxSOLID; | |
50 | } | |
51 | ||
52 | m_style = style; | |
53 | } | |
54 | ||
55 | wxColour m_colour; | |
56 | int m_style; | |
57 | }; | |
58 | ||
59 | //----------------------------------------------------------------------------- | |
60 | ||
61 | #define M_BRUSHDATA ((wxBrushRefData *)m_refData) | |
62 | ||
63 | IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject) | |
64 | ||
65 | wxBrush::wxBrush(const wxColour &colour, int style) | |
66 | { | |
67 | m_refData = new wxBrushRefData(colour, style); | |
68 | } | |
69 | ||
70 | wxBrush::wxBrush(const wxBitmap &stippleBitmap) | |
71 | { | |
72 | wxFAIL_MSG( "brushes with stipple bitmaps not implemented" ); | |
73 | ||
74 | m_refData = new wxBrushRefData(*wxBLACK); | |
75 | } | |
76 | ||
77 | bool wxBrush::operator==(const wxBrush& brush) const | |
78 | { | |
79 | #warning "this is incorrect (MGL too)" | |
80 | return m_refData == brush.m_refData; | |
81 | } | |
82 | ||
83 | bool wxBrush::Ok() const | |
84 | { | |
85 | return ((m_refData) && M_BRUSHDATA->m_colour.Ok()); | |
86 | } | |
87 | ||
88 | int wxBrush::GetStyle() const | |
89 | { | |
90 | if (m_refData == NULL) | |
91 | { | |
92 | wxFAIL_MSG( wxT("invalid brush") ); | |
93 | return 0; | |
94 | } | |
95 | ||
96 | return M_BRUSHDATA->m_style; | |
97 | } | |
98 | ||
99 | wxColour& wxBrush::GetColour() const | |
100 | { | |
101 | if (m_refData == NULL) | |
102 | { | |
103 | wxFAIL_MSG( wxT("invalid brush") ); | |
104 | return wxNullColour; | |
105 | } | |
106 | ||
107 | return M_BRUSHDATA->m_colour; | |
108 | } | |
109 | ||
110 | wxBitmap *wxBrush::GetStipple() const | |
111 | { | |
112 | wxFAIL_MSG( "brushes with stipple bitmaps not implemented" ); | |
113 | return &wxNullBitmap; | |
114 | } | |
115 | ||
116 | void wxBrush::SetColour(const wxColour& col) | |
117 | { | |
118 | AllocExclusive(); | |
119 | M_BRUSHDATA->m_colour = col; | |
120 | } | |
121 | ||
122 | void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b) | |
123 | { | |
124 | AllocExclusive(); | |
125 | M_BRUSHDATA->m_colour.Set(r, g, b); | |
126 | } | |
127 | ||
128 | void wxBrush::SetStyle(int style) | |
129 | { | |
130 | AllocExclusive(); | |
131 | M_BRUSHDATA->SetStyle(style); | |
132 | } | |
133 | ||
134 | void wxBrush::SetStipple(const wxBitmap& WXUNUSED(stipple)) | |
135 | { | |
136 | wxFAIL_MSG( "brushes with stipple bitmaps not implemented" ); | |
137 | } | |
138 | ||
139 | wxObjectRefData *wxBrush::CreateRefData() const | |
140 | { | |
141 | return new wxBrushRefData; | |
142 | } | |
143 | ||
144 | wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const | |
145 | { | |
146 | return new wxBrushRefData(*(wxBrushRefData *)data); | |
147 | } |