]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dc.cpp | |
3 | // Purpose: wxDC class | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
af0bb3b1 | 9 | // Licence: wxWindows licence |
4bb6408c JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
af0bb3b1 | 13 | #pragma implementation "dc.h" |
4bb6408c JS |
14 | #endif |
15 | ||
16 | #include "wx/dc.h" | |
a367b9b3 | 17 | #include "wx/dcmemory.h" |
4bb6408c JS |
18 | |
19 | #if !USE_SHARED_LIBRARY | |
af0bb3b1 | 20 | IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) |
4bb6408c JS |
21 | #endif |
22 | ||
23 | //----------------------------------------------------------------------------- | |
24 | // constants | |
25 | //----------------------------------------------------------------------------- | |
26 | ||
af0bb3b1 VZ |
27 | #define mm2inches 0.0393700787402 |
28 | #define inches2mm 25.4 | |
29 | #define mm2twips 56.6929133859 | |
30 | #define twips2mm 0.0176388888889 | |
31 | #define mm2pt 2.83464566929 | |
32 | #define pt2mm 0.352777777778 | |
4bb6408c JS |
33 | |
34 | //----------------------------------------------------------------------------- | |
35 | // wxDC | |
36 | //----------------------------------------------------------------------------- | |
37 | ||
af0bb3b1 | 38 | wxDC::wxDC() |
4bb6408c | 39 | { |
2d120f83 | 40 | m_ok = FALSE; |
af0bb3b1 | 41 | |
2d120f83 JS |
42 | m_mm_to_pix_x = 1.0; |
43 | m_mm_to_pix_y = 1.0; | |
af0bb3b1 | 44 | |
2d120f83 | 45 | m_backgroundMode = wxTRANSPARENT; |
af0bb3b1 | 46 | |
2d120f83 | 47 | m_isInteractive = FALSE; |
af0bb3b1 | 48 | } |
4bb6408c | 49 | |
af0bb3b1 | 50 | void wxDC::DoDrawIcon( const wxIcon &icon, long x, long y) |
4bb6408c | 51 | { |
af0bb3b1 VZ |
52 | wxCHECK_RET( Ok(), "invalid dc" ); |
53 | wxCHECK_RET( icon.Ok(), "invalid icon" ); | |
4bb6408c | 54 | |
af0bb3b1 VZ |
55 | DoDrawBitmap(icon, x, y, TRUE); |
56 | } | |
4bb6408c | 57 | |
af0bb3b1 | 58 | void wxDC::DoDrawBitmap( const wxBitmap& bitmap, long x, long y, bool useMask ) |
a367b9b3 | 59 | { |
af0bb3b1 VZ |
60 | wxCHECK_RET( bitmap.Ok(), "invalid bitmap" ); |
61 | ||
a367b9b3 JS |
62 | wxMemoryDC memDC; |
63 | memDC.SelectObject(bitmap); | |
af0bb3b1 VZ |
64 | |
65 | #if 0 | |
66 | // Not sure if we need this. The mask should leave the masked areas as per | |
67 | // the original background of this DC. | |
a367b9b3 JS |
68 | if (useMask) |
69 | { | |
af0bb3b1 VZ |
70 | // There might be transparent areas, so make these the same colour as this |
71 | // DC | |
72 | memDC.SetBackground(* GetBackground()); | |
73 | memDC.Clear(); | |
a367b9b3 | 74 | } |
af0bb3b1 | 75 | #endif // 0 |
a367b9b3 | 76 | |
af0bb3b1 | 77 | Blit(x, y, bitmap.GetWidth(), bitmap.GetHeight(), &memDC, 0, 0, wxCOPY, useMask); |
4bb6408c | 78 | |
af0bb3b1 VZ |
79 | memDC.SelectObject(wxNullBitmap); |
80 | } | |
4bb6408c | 81 | |
af0bb3b1 | 82 | void wxDC::DoSetClippingRegion( long x, long y, long width, long height ) |
4bb6408c | 83 | { |
2d120f83 JS |
84 | m_clipping = TRUE; |
85 | m_clipX1 = x; | |
86 | m_clipY1 = y; | |
87 | m_clipX2 = x + width; | |
88 | m_clipY2 = y + height; | |
af0bb3b1 | 89 | } |
4bb6408c | 90 | |
af0bb3b1 | 91 | void wxDC::DestroyClippingRegion() |
4bb6408c | 92 | { |
2d120f83 | 93 | m_clipping = FALSE; |
af0bb3b1 | 94 | } |
4bb6408c | 95 | |
af0bb3b1 | 96 | void wxDC::DoGetSize( int* width, int* height ) const |
4bb6408c | 97 | { |
af0bb3b1 VZ |
98 | if ( width ) |
99 | *width = m_maxX - m_minX; | |
100 | if ( height ) | |
101 | *height = m_maxY - m_minY; | |
102 | } | |
4bb6408c | 103 | |
af0bb3b1 | 104 | void wxDC::DoGetSizeMM( int* width, int* height ) const |
4bb6408c | 105 | { |
af0bb3b1 | 106 | int w, h; |
2d120f83 | 107 | GetSize( &w, &h ); |
af0bb3b1 VZ |
108 | |
109 | if ( width ) | |
110 | *width = int( double(w) / (m_scaleX*m_mm_to_pix_x) ); | |
111 | if ( height ) | |
112 | *height = int( double(h) / (m_scaleY*m_mm_to_pix_y) ); | |
113 | } | |
4bb6408c | 114 | |
7bcb11d3 | 115 | // Resolution in pixels per logical inch |
af0bb3b1 | 116 | wxSize wxDC::GetPPI() const |
7bcb11d3 JS |
117 | { |
118 | // TODO (should probably be pure virtual) | |
119 | return wxSize(0, 0); | |
120 | } | |
121 | ||
4bb6408c JS |
122 | void wxDC::SetMapMode( int mode ) |
123 | { | |
af0bb3b1 | 124 | switch (mode) |
2d120f83 | 125 | { |
e3065973 | 126 | case wxMM_TWIPS: |
2d120f83 JS |
127 | SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); |
128 | break; | |
e3065973 | 129 | case wxMM_POINTS: |
2d120f83 JS |
130 | SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y ); |
131 | break; | |
e3065973 | 132 | case wxMM_METRIC: |
2d120f83 JS |
133 | SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); |
134 | break; | |
e3065973 | 135 | case wxMM_LOMETRIC: |
2d120f83 JS |
136 | SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 ); |
137 | break; | |
4bb6408c | 138 | default: |
e3065973 | 139 | case wxMM_TEXT: |
2d120f83 JS |
140 | SetLogicalScale( 1.0, 1.0 ); |
141 | break; | |
af0bb3b1 | 142 | } |
e3065973 | 143 | if (mode != wxMM_TEXT) |
2d120f83 JS |
144 | { |
145 | m_needComputeScaleX = TRUE; | |
146 | m_needComputeScaleY = TRUE; | |
af0bb3b1 VZ |
147 | } |
148 | } | |
4bb6408c JS |
149 | |
150 | void wxDC::SetUserScale( double x, double y ) | |
151 | { | |
af0bb3b1 | 152 | wxDCBase::SetUserScale(x, y); |
2d120f83 | 153 | ComputeScaleAndOrigin(); |
af0bb3b1 | 154 | } |
4bb6408c JS |
155 | |
156 | void wxDC::SetLogicalScale( double x, double y ) | |
157 | { | |
af0bb3b1 | 158 | wxDCBase::SetLogicalScale(x, y); |
2d120f83 | 159 | ComputeScaleAndOrigin(); |
af0bb3b1 | 160 | } |
4bb6408c JS |
161 | |
162 | void wxDC::SetLogicalOrigin( long x, long y ) | |
163 | { | |
2d120f83 JS |
164 | m_logicalOriginX = x * m_signX; // is this still correct ? |
165 | m_logicalOriginY = y * m_signY; | |
166 | ComputeScaleAndOrigin(); | |
af0bb3b1 | 167 | } |
4bb6408c JS |
168 | |
169 | void wxDC::SetDeviceOrigin( long x, long y ) | |
170 | { | |
2d120f83 JS |
171 | m_externalDeviceOriginX = x; |
172 | m_externalDeviceOriginY = y; | |
173 | ComputeScaleAndOrigin(); | |
af0bb3b1 | 174 | } |
4bb6408c JS |
175 | |
176 | void wxDC::SetInternalDeviceOrigin( long x, long y ) | |
177 | { | |
2d120f83 JS |
178 | m_internalDeviceOriginX = x; |
179 | m_internalDeviceOriginY = y; | |
180 | ComputeScaleAndOrigin(); | |
af0bb3b1 | 181 | } |
4bb6408c JS |
182 | |
183 | void wxDC::GetInternalDeviceOrigin( long *x, long *y ) | |
184 | { | |
2d120f83 JS |
185 | if (x) *x = m_internalDeviceOriginX; |
186 | if (y) *y = m_internalDeviceOriginY; | |
af0bb3b1 | 187 | } |
4bb6408c JS |
188 | |
189 | void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
190 | { | |
af0bb3b1 VZ |
191 | m_signX = xLeftRight ? 1 : -1; |
192 | m_signY = yBottomUp ? -1 : 1; | |
2d120f83 | 193 | ComputeScaleAndOrigin(); |
af0bb3b1 | 194 | } |
4bb6408c | 195 | |
af0bb3b1 | 196 | long wxDCBase::DeviceToLogicalX(long x) const |
4bb6408c | 197 | { |
af0bb3b1 VZ |
198 | return ((wxDC *)this)->XDEV2LOG(x); |
199 | } | |
4bb6408c | 200 | |
af0bb3b1 | 201 | long wxDCBase::DeviceToLogicalY(long y) const |
4bb6408c | 202 | { |
af0bb3b1 VZ |
203 | return ((wxDC *)this)->YDEV2LOG(y); |
204 | } | |
4bb6408c | 205 | |
af0bb3b1 | 206 | long wxDCBase::DeviceToLogicalXRel(long x) const |
4bb6408c | 207 | { |
af0bb3b1 VZ |
208 | return ((wxDC *)this)->XDEV2LOGREL(x); |
209 | } | |
4bb6408c | 210 | |
af0bb3b1 | 211 | long wxDCBase::DeviceToLogicalYRel(long y) const |
4bb6408c | 212 | { |
af0bb3b1 VZ |
213 | return ((wxDC *)this)->YDEV2LOGREL(y); |
214 | } | |
4bb6408c | 215 | |
af0bb3b1 | 216 | long wxDCBase::LogicalToDeviceX(long x) const |
4bb6408c | 217 | { |
af0bb3b1 VZ |
218 | return ((wxDC *)this)->XLOG2DEV(x); |
219 | } | |
4bb6408c | 220 | |
af0bb3b1 | 221 | long wxDCBase::LogicalToDeviceY(long y) const |
4bb6408c | 222 | { |
af0bb3b1 VZ |
223 | return ((wxDC *)this)->YLOG2DEV(y); |
224 | } | |
4bb6408c | 225 | |
af0bb3b1 | 226 | long wxDCBase::LogicalToDeviceXRel(long x) const |
4bb6408c | 227 | { |
af0bb3b1 VZ |
228 | return ((wxDC *)this)->XLOG2DEVREL(x); |
229 | } | |
2d120f83 | 230 | |
af0bb3b1 | 231 | long wxDCBase::LogicalToDeviceYRel(long y) const |
4bb6408c | 232 | { |
af0bb3b1 VZ |
233 | return ((wxDC *)this)->YLOG2DEVREL(y); |
234 | } | |
4bb6408c | 235 | |
af0bb3b1 | 236 | void wxDC::ComputeScaleAndOrigin() |
4bb6408c | 237 | { |
2d120f83 JS |
238 | // CMB: copy scale to see if it changes |
239 | double origScaleX = m_scaleX; | |
240 | double origScaleY = m_scaleY; | |
af0bb3b1 | 241 | |
2d120f83 JS |
242 | m_scaleX = m_logicalScaleX * m_userScaleX; |
243 | m_scaleY = m_logicalScaleY * m_userScaleY; | |
af0bb3b1 | 244 | |
2d120f83 JS |
245 | m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX; |
246 | m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY; | |
af0bb3b1 VZ |
247 | |
248 | // CMB: if scale has changed call SetPen to recalulate the line width | |
2d120f83 JS |
249 | if (m_scaleX != origScaleX || m_scaleY != origScaleY) |
250 | { | |
251 | // this is a bit artificial, but we need to force wxDC to think | |
252 | // the pen has changed | |
253 | wxPen* pen = & GetPen(); | |
254 | wxPen tempPen; | |
255 | m_pen = tempPen; | |
256 | SetPen(* pen); | |
257 | } | |
af0bb3b1 | 258 | } |
4bb6408c | 259 |