]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: pen.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
5 | // Created: 01/02/97 | |
6 | // Id: | |
7 | // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "pen.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/pen.h" | |
17 | ||
18 | //----------------------------------------------------------------------------- | |
19 | // wxPen | |
20 | //----------------------------------------------------------------------------- | |
21 | ||
22 | class wxPenRefData: public wxObjectRefData | |
23 | { | |
24 | public: | |
25 | ||
26 | wxPenRefData(void); | |
335a8b43 | 27 | wxPenRefData(const wxPenRefData& data); |
c801d85f KB |
28 | |
29 | int m_width; | |
30 | int m_style; | |
31 | int m_joinStyle; | |
32 | int m_capStyle; | |
33 | wxColour m_colour; | |
34 | }; | |
35 | ||
36 | wxPenRefData::wxPenRefData(void) | |
37 | { | |
38 | m_width = 1; | |
39 | m_style = wxSOLID; | |
40 | m_joinStyle = wxJOIN_ROUND; | |
41 | m_capStyle = wxCAP_ROUND; | |
ff7b1510 | 42 | } |
c801d85f | 43 | |
e55ad60e RR |
44 | wxPenRefData::wxPenRefData( const wxPenRefData& data ) |
45 | { | |
46 | m_style = data.m_style; | |
47 | m_width = data.m_width; | |
48 | m_joinStyle = data.m_joinStyle; | |
49 | m_capStyle = data.m_capStyle; | |
50 | m_colour = data.m_colour; | |
51 | } | |
52 | ||
c801d85f KB |
53 | //----------------------------------------------------------------------------- |
54 | ||
55 | #define M_PENDATA ((wxPenRefData *)m_refData) | |
56 | ||
57 | IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject) | |
58 | ||
59 | wxPen::wxPen(void) | |
60 | { | |
61 | if (wxThePenList) wxThePenList->AddPen( this ); | |
ff7b1510 | 62 | } |
c801d85f KB |
63 | |
64 | wxPen::wxPen( const wxColour &colour, int width, int style ) | |
65 | { | |
66 | m_refData = new wxPenRefData(); | |
67 | M_PENDATA->m_width = width; | |
68 | M_PENDATA->m_style = style; | |
69 | M_PENDATA->m_colour = colour; | |
52cbfcf0 | 70 | |
c801d85f | 71 | if (wxThePenList) wxThePenList->AddPen( this ); |
ff7b1510 | 72 | } |
c801d85f | 73 | |
c801d85f KB |
74 | wxPen::wxPen( const wxPen& pen ) |
75 | { | |
76 | Ref( pen ); | |
77 | if (wxThePenList) wxThePenList->AddPen( this ); | |
ff7b1510 | 78 | } |
c801d85f KB |
79 | |
80 | wxPen::wxPen( const wxPen* pen ) | |
81 | { | |
82 | UnRef(); | |
83 | if (pen) Ref( *pen ); | |
52cbfcf0 | 84 | |
c801d85f | 85 | if (wxThePenList) wxThePenList->AddPen( this ); |
ff7b1510 | 86 | } |
c801d85f KB |
87 | |
88 | wxPen::~wxPen(void) | |
89 | { | |
90 | if (wxThePenList) wxThePenList->RemovePen( this ); | |
ff7b1510 | 91 | } |
c801d85f KB |
92 | |
93 | wxPen& wxPen::operator = ( const wxPen& pen ) | |
94 | { | |
95 | if (*this == pen) return (*this); | |
96 | Ref( pen ); | |
97 | return *this; | |
ff7b1510 | 98 | } |
c801d85f KB |
99 | |
100 | bool wxPen::operator == ( const wxPen& pen ) | |
101 | { | |
102 | return m_refData == pen.m_refData; | |
ff7b1510 | 103 | } |
c801d85f KB |
104 | |
105 | bool wxPen::operator != ( const wxPen& pen ) | |
106 | { | |
107 | return m_refData != pen.m_refData; | |
ff7b1510 | 108 | } |
c801d85f KB |
109 | |
110 | void wxPen::SetColour( const wxColour &colour ) | |
111 | { | |
e55ad60e | 112 | Unshare(); |
c801d85f | 113 | M_PENDATA->m_colour = colour; |
ff7b1510 | 114 | } |
c801d85f | 115 | |
debe6624 | 116 | void wxPen::SetColour( int red, int green, int blue ) |
c801d85f | 117 | { |
e55ad60e | 118 | Unshare(); |
c801d85f | 119 | M_PENDATA->m_colour.Set( red, green, blue ); |
ff7b1510 | 120 | } |
c801d85f KB |
121 | |
122 | void wxPen::SetCap( int capStyle ) | |
123 | { | |
e55ad60e | 124 | Unshare(); |
c801d85f | 125 | M_PENDATA->m_capStyle = capStyle; |
ff7b1510 | 126 | } |
c801d85f KB |
127 | |
128 | void wxPen::SetJoin( int joinStyle ) | |
129 | { | |
e55ad60e | 130 | Unshare(); |
c801d85f | 131 | M_PENDATA->m_joinStyle = joinStyle; |
ff7b1510 | 132 | } |
c801d85f KB |
133 | |
134 | void wxPen::SetStyle( int style ) | |
135 | { | |
e55ad60e | 136 | Unshare(); |
c801d85f | 137 | M_PENDATA->m_style = style; |
ff7b1510 | 138 | } |
c801d85f KB |
139 | |
140 | void wxPen::SetWidth( int width ) | |
141 | { | |
e55ad60e | 142 | Unshare(); |
c801d85f | 143 | M_PENDATA->m_width = width; |
ff7b1510 | 144 | } |
c801d85f KB |
145 | |
146 | int wxPen::GetCap(void) const | |
147 | { | |
e55ad60e RR |
148 | if (!m_refData) |
149 | { | |
150 | wxFAIL_MSG( "invalid pen" ); | |
151 | return -1; | |
152 | } | |
153 | ||
c801d85f | 154 | return M_PENDATA->m_capStyle; |
ff7b1510 | 155 | } |
c801d85f KB |
156 | |
157 | int wxPen::GetJoin(void) const | |
158 | { | |
159 | if (!m_refData) | |
e55ad60e RR |
160 | { |
161 | wxFAIL_MSG( "invalid pen" ); | |
162 | return -1; | |
163 | } | |
164 | ||
165 | return M_PENDATA->m_joinStyle; | |
ff7b1510 | 166 | } |
c801d85f KB |
167 | |
168 | int wxPen::GetStyle(void) const | |
169 | { | |
170 | if (!m_refData) | |
e55ad60e RR |
171 | { |
172 | wxFAIL_MSG( "invalid pen" ); | |
173 | return -1; | |
174 | } | |
175 | ||
176 | return M_PENDATA->m_style; | |
ff7b1510 | 177 | } |
c801d85f KB |
178 | |
179 | int wxPen::GetWidth(void) const | |
180 | { | |
181 | if (!m_refData) | |
e55ad60e RR |
182 | { |
183 | wxFAIL_MSG( "invalid pen" ); | |
184 | return -1; | |
185 | } | |
186 | ||
187 | return M_PENDATA->m_width; | |
ff7b1510 | 188 | } |
c801d85f KB |
189 | |
190 | wxColour &wxPen::GetColour(void) const | |
191 | { | |
192 | if (!m_refData) | |
e55ad60e RR |
193 | { |
194 | wxFAIL_MSG( "invalid pen" ); | |
c801d85f | 195 | return wxNullColour; |
e55ad60e RR |
196 | } |
197 | ||
198 | return M_PENDATA->m_colour; | |
ff7b1510 | 199 | } |
c801d85f KB |
200 | |
201 | bool wxPen::Ok(void) const | |
202 | { | |
e55ad60e RR |
203 | return (m_refData != NULL); |
204 | } | |
205 | ||
206 | void wxPen::Unshare(void) | |
207 | { | |
208 | if (!m_refData) | |
209 | { | |
210 | m_refData = new wxPenRefData(); | |
211 | } | |
212 | else | |
213 | { | |
214 | wxPenRefData* ref = new wxPenRefData( *(wxPenRefData*)m_refData ); | |
215 | UnRef(); | |
216 | m_refData = ref; | |
217 | } | |
ff7b1510 | 218 | } |
c801d85f | 219 |