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