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