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