]>
Commit | Line | Data |
---|---|---|
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); | |
27 | wxPenRefData(const wxPenRefData& data); | |
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; | |
42 | } | |
43 | ||
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 | ||
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 ); | |
62 | } | |
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; | |
70 | ||
71 | if (wxThePenList) wxThePenList->AddPen( this ); | |
72 | } | |
73 | ||
74 | wxPen::wxPen( const wxPen& pen ) | |
75 | { | |
76 | Ref( pen ); | |
77 | if (wxThePenList) wxThePenList->AddPen( this ); | |
78 | } | |
79 | ||
80 | wxPen::wxPen( const wxPen* pen ) | |
81 | { | |
82 | UnRef(); | |
83 | if (pen) Ref( *pen ); | |
84 | ||
85 | if (wxThePenList) wxThePenList->AddPen( this ); | |
86 | } | |
87 | ||
88 | wxPen::~wxPen(void) | |
89 | { | |
90 | if (wxThePenList) wxThePenList->RemovePen( this ); | |
91 | } | |
92 | ||
93 | wxPen& wxPen::operator = ( const wxPen& pen ) | |
94 | { | |
95 | if (*this == pen) return (*this); | |
96 | Ref( pen ); | |
97 | return *this; | |
98 | } | |
99 | ||
100 | bool wxPen::operator == ( const wxPen& pen ) | |
101 | { | |
102 | return m_refData == pen.m_refData; | |
103 | } | |
104 | ||
105 | bool wxPen::operator != ( const wxPen& pen ) | |
106 | { | |
107 | return m_refData != pen.m_refData; | |
108 | } | |
109 | ||
110 | void wxPen::SetColour( const wxColour &colour ) | |
111 | { | |
112 | Unshare(); | |
113 | M_PENDATA->m_colour = colour; | |
114 | } | |
115 | ||
116 | void wxPen::SetColour( int red, int green, int blue ) | |
117 | { | |
118 | Unshare(); | |
119 | M_PENDATA->m_colour.Set( red, green, blue ); | |
120 | } | |
121 | ||
122 | void wxPen::SetCap( int capStyle ) | |
123 | { | |
124 | Unshare(); | |
125 | M_PENDATA->m_capStyle = capStyle; | |
126 | } | |
127 | ||
128 | void wxPen::SetJoin( int joinStyle ) | |
129 | { | |
130 | Unshare(); | |
131 | M_PENDATA->m_joinStyle = joinStyle; | |
132 | } | |
133 | ||
134 | void wxPen::SetStyle( int style ) | |
135 | { | |
136 | Unshare(); | |
137 | M_PENDATA->m_style = style; | |
138 | } | |
139 | ||
140 | void wxPen::SetWidth( int width ) | |
141 | { | |
142 | Unshare(); | |
143 | M_PENDATA->m_width = width; | |
144 | } | |
145 | ||
146 | int wxPen::GetCap(void) const | |
147 | { | |
148 | if (!m_refData) | |
149 | { | |
150 | wxFAIL_MSG( "invalid pen" ); | |
151 | return -1; | |
152 | } | |
153 | ||
154 | return M_PENDATA->m_capStyle; | |
155 | } | |
156 | ||
157 | int wxPen::GetJoin(void) const | |
158 | { | |
159 | if (!m_refData) | |
160 | { | |
161 | wxFAIL_MSG( "invalid pen" ); | |
162 | return -1; | |
163 | } | |
164 | ||
165 | return M_PENDATA->m_joinStyle; | |
166 | } | |
167 | ||
168 | int wxPen::GetStyle(void) const | |
169 | { | |
170 | if (!m_refData) | |
171 | { | |
172 | wxFAIL_MSG( "invalid pen" ); | |
173 | return -1; | |
174 | } | |
175 | ||
176 | return M_PENDATA->m_style; | |
177 | } | |
178 | ||
179 | int wxPen::GetWidth(void) const | |
180 | { | |
181 | if (!m_refData) | |
182 | { | |
183 | wxFAIL_MSG( "invalid pen" ); | |
184 | return -1; | |
185 | } | |
186 | ||
187 | return M_PENDATA->m_width; | |
188 | } | |
189 | ||
190 | wxColour &wxPen::GetColour(void) const | |
191 | { | |
192 | if (!m_refData) | |
193 | { | |
194 | wxFAIL_MSG( "invalid pen" ); | |
195 | return wxNullColour; | |
196 | } | |
197 | ||
198 | return M_PENDATA->m_colour; | |
199 | } | |
200 | ||
201 | bool wxPen::Ok(void) const | |
202 | { | |
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 | } | |
218 | } | |
219 |