]>
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); | |
27 | ||
28 | int m_width; | |
29 | int m_style; | |
30 | int m_joinStyle; | |
31 | int m_capStyle; | |
32 | wxColour m_colour; | |
33 | }; | |
34 | ||
35 | wxPenRefData::wxPenRefData(void) | |
36 | { | |
37 | m_width = 1; | |
38 | m_style = wxSOLID; | |
39 | m_joinStyle = wxJOIN_ROUND; | |
40 | m_capStyle = wxCAP_ROUND; | |
ff7b1510 | 41 | } |
c801d85f KB |
42 | |
43 | //----------------------------------------------------------------------------- | |
44 | ||
45 | #define M_PENDATA ((wxPenRefData *)m_refData) | |
46 | ||
47 | IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject) | |
48 | ||
49 | wxPen::wxPen(void) | |
50 | { | |
51 | if (wxThePenList) wxThePenList->AddPen( this ); | |
ff7b1510 | 52 | } |
c801d85f KB |
53 | |
54 | wxPen::wxPen( const wxColour &colour, int width, int style ) | |
55 | { | |
56 | m_refData = new wxPenRefData(); | |
57 | M_PENDATA->m_width = width; | |
58 | M_PENDATA->m_style = style; | |
59 | M_PENDATA->m_colour = colour; | |
52cbfcf0 | 60 | |
c801d85f | 61 | if (wxThePenList) wxThePenList->AddPen( this ); |
ff7b1510 | 62 | } |
c801d85f KB |
63 | |
64 | wxPen::wxPen( const wxString &colourName, 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 = colourName; | |
52cbfcf0 | 70 | |
c801d85f | 71 | if (wxThePenList) wxThePenList->AddPen( this ); |
ff7b1510 | 72 | } |
c801d85f KB |
73 | |
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 | { | |
112 | if (!m_refData) | |
113 | m_refData = new wxPenRefData(); | |
114 | ||
115 | M_PENDATA->m_colour = colour; | |
ff7b1510 | 116 | } |
c801d85f KB |
117 | |
118 | void wxPen::SetColour( const wxString &colourName ) | |
119 | { | |
120 | if (!m_refData) | |
121 | m_refData = new wxPenRefData(); | |
122 | ||
123 | M_PENDATA->m_colour = colourName; | |
ff7b1510 | 124 | } |
c801d85f | 125 | |
debe6624 | 126 | void wxPen::SetColour( int red, int green, int blue ) |
c801d85f KB |
127 | { |
128 | if (!m_refData) | |
129 | m_refData = new wxPenRefData(); | |
130 | ||
131 | M_PENDATA->m_colour.Set( red, green, blue ); | |
ff7b1510 | 132 | } |
c801d85f KB |
133 | |
134 | void wxPen::SetCap( int capStyle ) | |
135 | { | |
136 | if (!m_refData) | |
137 | m_refData = new wxPenRefData(); | |
138 | ||
139 | M_PENDATA->m_capStyle = capStyle; | |
ff7b1510 | 140 | } |
c801d85f KB |
141 | |
142 | void wxPen::SetJoin( int joinStyle ) | |
143 | { | |
144 | if (!m_refData) | |
145 | m_refData = new wxPenRefData(); | |
146 | ||
147 | M_PENDATA->m_joinStyle = joinStyle; | |
ff7b1510 | 148 | } |
c801d85f KB |
149 | |
150 | void wxPen::SetStyle( int style ) | |
151 | { | |
152 | if (!m_refData) | |
153 | m_refData = new wxPenRefData(); | |
154 | ||
155 | M_PENDATA->m_style = style; | |
ff7b1510 | 156 | } |
c801d85f KB |
157 | |
158 | void wxPen::SetWidth( int width ) | |
159 | { | |
160 | if (!m_refData) | |
161 | m_refData = new wxPenRefData(); | |
162 | ||
163 | M_PENDATA->m_width = width; | |
ff7b1510 | 164 | } |
c801d85f KB |
165 | |
166 | int wxPen::GetCap(void) const | |
167 | { | |
168 | return M_PENDATA->m_capStyle; | |
ff7b1510 | 169 | } |
c801d85f KB |
170 | |
171 | int wxPen::GetJoin(void) const | |
172 | { | |
173 | if (!m_refData) | |
174 | return 0; | |
175 | else | |
176 | return M_PENDATA->m_joinStyle; | |
ff7b1510 | 177 | } |
c801d85f KB |
178 | |
179 | int wxPen::GetStyle(void) const | |
180 | { | |
181 | if (!m_refData) | |
182 | return 0; | |
183 | else | |
184 | return M_PENDATA->m_style; | |
ff7b1510 | 185 | } |
c801d85f KB |
186 | |
187 | int wxPen::GetWidth(void) const | |
188 | { | |
189 | if (!m_refData) | |
190 | return 0; | |
191 | else | |
192 | return M_PENDATA->m_width; | |
ff7b1510 | 193 | } |
c801d85f KB |
194 | |
195 | wxColour &wxPen::GetColour(void) const | |
196 | { | |
197 | if (!m_refData) | |
198 | return wxNullColour; | |
199 | else | |
200 | return M_PENDATA->m_colour; | |
ff7b1510 | 201 | } |
c801d85f KB |
202 | |
203 | bool wxPen::Ok(void) const | |
204 | { | |
205 | return (m_refData); | |
ff7b1510 | 206 | } |
c801d85f | 207 |