]>
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 | { | |
96f201da RR |
152 | // allow negative ? -> no |
153 | m_userScaleX = x; | |
154 | m_userScaleY = y; | |
2d120f83 | 155 | ComputeScaleAndOrigin(); |
af0bb3b1 | 156 | } |
4bb6408c JS |
157 | |
158 | void wxDC::SetLogicalScale( double x, double y ) | |
159 | { | |
96f201da RR |
160 | // allow negative ? |
161 | m_logicalScaleX = x; | |
162 | m_logicalScaleY = y; | |
2d120f83 | 163 | ComputeScaleAndOrigin(); |
af0bb3b1 | 164 | } |
4bb6408c JS |
165 | |
166 | void wxDC::SetLogicalOrigin( long x, long y ) | |
167 | { | |
2d120f83 JS |
168 | m_logicalOriginX = x * m_signX; // is this still correct ? |
169 | m_logicalOriginY = y * m_signY; | |
170 | ComputeScaleAndOrigin(); | |
af0bb3b1 | 171 | } |
4bb6408c JS |
172 | |
173 | void wxDC::SetDeviceOrigin( long x, long y ) | |
174 | { | |
2d120f83 JS |
175 | m_externalDeviceOriginX = x; |
176 | m_externalDeviceOriginY = y; | |
177 | ComputeScaleAndOrigin(); | |
af0bb3b1 | 178 | } |
4bb6408c JS |
179 | |
180 | void wxDC::SetInternalDeviceOrigin( long x, long y ) | |
181 | { | |
2d120f83 JS |
182 | m_internalDeviceOriginX = x; |
183 | m_internalDeviceOriginY = y; | |
184 | ComputeScaleAndOrigin(); | |
af0bb3b1 | 185 | } |
4bb6408c JS |
186 | |
187 | void wxDC::GetInternalDeviceOrigin( long *x, long *y ) | |
188 | { | |
2d120f83 JS |
189 | if (x) *x = m_internalDeviceOriginX; |
190 | if (y) *y = m_internalDeviceOriginY; | |
af0bb3b1 | 191 | } |
4bb6408c JS |
192 | |
193 | void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
194 | { | |
af0bb3b1 VZ |
195 | m_signX = xLeftRight ? 1 : -1; |
196 | m_signY = yBottomUp ? -1 : 1; | |
2d120f83 | 197 | ComputeScaleAndOrigin(); |
af0bb3b1 | 198 | } |
4bb6408c | 199 | |
af0bb3b1 | 200 | long wxDCBase::DeviceToLogicalX(long x) const |
4bb6408c | 201 | { |
af0bb3b1 VZ |
202 | return ((wxDC *)this)->XDEV2LOG(x); |
203 | } | |
4bb6408c | 204 | |
af0bb3b1 | 205 | long wxDCBase::DeviceToLogicalY(long y) const |
4bb6408c | 206 | { |
af0bb3b1 VZ |
207 | return ((wxDC *)this)->YDEV2LOG(y); |
208 | } | |
4bb6408c | 209 | |
af0bb3b1 | 210 | long wxDCBase::DeviceToLogicalXRel(long x) const |
4bb6408c | 211 | { |
af0bb3b1 VZ |
212 | return ((wxDC *)this)->XDEV2LOGREL(x); |
213 | } | |
4bb6408c | 214 | |
af0bb3b1 | 215 | long wxDCBase::DeviceToLogicalYRel(long y) const |
4bb6408c | 216 | { |
af0bb3b1 VZ |
217 | return ((wxDC *)this)->YDEV2LOGREL(y); |
218 | } | |
4bb6408c | 219 | |
af0bb3b1 | 220 | long wxDCBase::LogicalToDeviceX(long x) const |
4bb6408c | 221 | { |
af0bb3b1 VZ |
222 | return ((wxDC *)this)->XLOG2DEV(x); |
223 | } | |
4bb6408c | 224 | |
af0bb3b1 | 225 | long wxDCBase::LogicalToDeviceY(long y) const |
4bb6408c | 226 | { |
af0bb3b1 VZ |
227 | return ((wxDC *)this)->YLOG2DEV(y); |
228 | } | |
4bb6408c | 229 | |
af0bb3b1 | 230 | long wxDCBase::LogicalToDeviceXRel(long x) const |
4bb6408c | 231 | { |
af0bb3b1 VZ |
232 | return ((wxDC *)this)->XLOG2DEVREL(x); |
233 | } | |
2d120f83 | 234 | |
af0bb3b1 | 235 | long wxDCBase::LogicalToDeviceYRel(long y) const |
4bb6408c | 236 | { |
af0bb3b1 VZ |
237 | return ((wxDC *)this)->YLOG2DEVREL(y); |
238 | } | |
4bb6408c | 239 | |
af0bb3b1 | 240 | void wxDC::ComputeScaleAndOrigin() |
4bb6408c | 241 | { |
2d120f83 JS |
242 | // CMB: copy scale to see if it changes |
243 | double origScaleX = m_scaleX; | |
244 | double origScaleY = m_scaleY; | |
af0bb3b1 | 245 | |
2d120f83 JS |
246 | m_scaleX = m_logicalScaleX * m_userScaleX; |
247 | m_scaleY = m_logicalScaleY * m_userScaleY; | |
af0bb3b1 | 248 | |
2d120f83 JS |
249 | m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX; |
250 | m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY; | |
af0bb3b1 VZ |
251 | |
252 | // CMB: if scale has changed call SetPen to recalulate the line width | |
2d120f83 JS |
253 | if (m_scaleX != origScaleX || m_scaleY != origScaleY) |
254 | { | |
255 | // this is a bit artificial, but we need to force wxDC to think | |
256 | // the pen has changed | |
257 | wxPen* pen = & GetPen(); | |
258 | wxPen tempPen; | |
259 | m_pen = tempPen; | |
260 | SetPen(* pen); | |
261 | } | |
af0bb3b1 | 262 | } |
4bb6408c | 263 |