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