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