]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dc.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
6f65e337 | 5 | // RCS-ID: $Id$ |
dbf858b5 | 6 | // Copyright: (c) 1998 Robert Roebling, Markus Holzem |
c801d85f KB |
7 | // Licence: wxWindows licence |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "dc.h" | |
13 | #endif | |
14 | ||
15 | #include "wx/dc.h" | |
16 | ||
17 | //----------------------------------------------------------------------------- | |
18 | // constants | |
19 | //----------------------------------------------------------------------------- | |
20 | ||
21 | #define mm2inches 0.0393700787402 | |
22 | #define inches2mm 25.4 | |
23 | #define mm2twips 56.6929133859 | |
24 | #define twips2mm 0.0176388888889 | |
25 | #define mm2pt 2.83464566929 | |
26 | #define pt2mm 0.352777777778 | |
27 | ||
28 | //----------------------------------------------------------------------------- | |
29 | // wxDC | |
30 | //----------------------------------------------------------------------------- | |
31 | ||
32 | IMPLEMENT_ABSTRACT_CLASS(wxDC,wxObject) | |
33 | ||
34 | wxDC::wxDC(void) | |
35 | { | |
36 | m_ok = FALSE; | |
37 | m_optimize = FALSE; | |
38 | m_autoSetting = FALSE; | |
39 | m_colour = TRUE; | |
40 | m_clipping = FALSE; | |
41 | ||
42 | m_mm_to_pix_x = 1.0; | |
43 | m_mm_to_pix_y = 1.0; | |
44 | ||
45 | m_logicalOriginX = 0; | |
46 | m_logicalOriginY = 0; | |
47 | m_deviceOriginX = 0; | |
48 | m_deviceOriginY = 0; | |
c801d85f KB |
49 | |
50 | m_logicalScaleX = 1.0; | |
51 | m_logicalScaleY = 1.0; | |
52 | m_userScaleX = 1.0; | |
53 | m_userScaleY = 1.0; | |
54 | m_scaleX = 1.0; | |
55 | m_scaleY = 1.0; | |
56 | ||
57 | m_mappingMode = MM_TEXT; | |
58 | m_needComputeScaleX = FALSE; | |
59 | m_needComputeScaleY = FALSE; | |
60 | ||
61 | m_signX = 1; // default x-axis left to right | |
62 | m_signY = 1; // default y-axis top down | |
63 | ||
64 | m_maxX = m_maxY = -100000; | |
65 | m_minY = m_minY = 100000; | |
66 | ||
67 | m_logicalFunction = wxCOPY; | |
68 | // m_textAlignment = wxALIGN_TOP_LEFT; | |
69 | m_backgroundMode = wxTRANSPARENT; | |
70 | ||
71 | m_textForegroundColour = *wxBLACK; | |
72 | m_textBackgroundColour = *wxWHITE; | |
73 | m_pen = *wxBLACK_PEN; | |
74 | m_font = *wxNORMAL_FONT; | |
75 | m_brush = *wxTRANSPARENT_BRUSH; | |
76 | m_backgroundBrush = *wxWHITE_BRUSH; | |
77 | ||
78 | // m_palette = wxAPP_COLOURMAP; | |
ff7b1510 | 79 | } |
c801d85f KB |
80 | |
81 | wxDC::~wxDC(void) | |
82 | { | |
ff7b1510 | 83 | } |
c801d85f | 84 | |
cf7a7e13 RR |
85 | bool wxDC::Ok(void) const |
86 | { | |
db5d183b | 87 | wxASSERT_MSG( m_ok, "invalid display context" ); |
cf7a7e13 RR |
88 | return m_ok; |
89 | } | |
90 | ||
c801d85f KB |
91 | void wxDC::DrawArc( long WXUNUSED(x1), long WXUNUSED(y1), long WXUNUSED(x2), long WXUNUSED(y2), |
92 | double WXUNUSED(xc), double WXUNUSED(yc) ) | |
93 | { | |
ff7b1510 | 94 | } |
c801d85f KB |
95 | |
96 | void wxDC::DrawIcon( const wxIcon &WXUNUSED(icon), long WXUNUSED(x), long WXUNUSED(y), bool WXUNUSED(useMask) ) | |
97 | { | |
ff7b1510 | 98 | } |
c801d85f KB |
99 | |
100 | void wxDC::DrawPoint( wxPoint& point ) | |
101 | { | |
102 | DrawPoint( point.x, point.y ); | |
ff7b1510 | 103 | } |
c801d85f KB |
104 | |
105 | void wxDC::DrawPolygon( wxList *list, long xoffset, long yoffset, int fillStyle ) | |
106 | { | |
107 | int n = list->Number(); | |
108 | wxPoint *points = new wxPoint[n]; | |
109 | ||
110 | int i = 0; | |
111 | for( wxNode *node = list->First(); node; node = node->Next() ) | |
112 | { | |
113 | wxPoint *point = (wxPoint *)node->Data(); | |
114 | points[i].x = point->x; | |
115 | points[i++].y = point->y; | |
ff7b1510 | 116 | } |
c801d85f KB |
117 | DrawPolygon( n, points, xoffset, yoffset, fillStyle ); |
118 | delete[] points; | |
ff7b1510 | 119 | } |
c801d85f KB |
120 | |
121 | void wxDC::DrawLines( wxList *list, long xoffset, long yoffset ) | |
122 | { | |
123 | int n = list->Number(); | |
124 | wxPoint *points = new wxPoint[n]; | |
125 | ||
126 | int i = 0; | |
127 | for( wxNode *node = list->First(); node; node = node->Next() ) | |
128 | { | |
129 | wxPoint *point = (wxPoint *)node->Data(); | |
130 | points[i].x = point->x; | |
131 | points[i++].y = point->y; | |
ff7b1510 | 132 | } |
c801d85f KB |
133 | DrawLines( n, points, xoffset, yoffset ); |
134 | delete []points; | |
ff7b1510 | 135 | } |
c801d85f KB |
136 | |
137 | void wxDC::DrawSpline( long x1, long y1, long x2, long y2, long x3, long y3 ) | |
138 | { | |
139 | wxList list; | |
c0392997 RR |
140 | list.Append( (wxObject*)new wxPoint(x1, y1) ); |
141 | list.Append( (wxObject*)new wxPoint(x2, y2) ); | |
142 | list.Append( (wxObject*)new wxPoint(x3, y3) ); | |
c801d85f | 143 | DrawSpline(&list); |
33d0b396 RR |
144 | wxNode *node = list.First(); |
145 | while (node) | |
146 | { | |
147 | wxPoint *p = (wxPoint*)node->Data(); | |
148 | delete p; | |
149 | node = node->Next(); | |
ff7b1510 RR |
150 | } |
151 | } | |
c801d85f | 152 | |
c801d85f KB |
153 | void wxDC::DrawSpline( int n, wxPoint points[] ) |
154 | { | |
155 | wxList list; | |
156 | for (int i = 0; i < n; i++) list.Append( (wxObject*)&points[i] ); | |
157 | DrawSpline( &list ); | |
ff7b1510 | 158 | } |
c801d85f KB |
159 | |
160 | void wxDC::SetClippingRegion( long x, long y, long width, long height ) | |
161 | { | |
162 | m_clipping = TRUE; | |
163 | m_clipX1 = x; | |
164 | m_clipY1 = y; | |
165 | m_clipX2 = x + width; | |
166 | m_clipY2 = y + height; | |
ff7b1510 | 167 | } |
c801d85f KB |
168 | |
169 | void wxDC::DestroyClippingRegion(void) | |
170 | { | |
171 | m_clipping = FALSE; | |
ff7b1510 | 172 | } |
c801d85f KB |
173 | |
174 | void wxDC::GetClippingBox( long *x, long *y, long *width, long *height ) const | |
175 | { | |
176 | if (m_clipping) | |
177 | { | |
178 | if (x) *x = m_clipX1; | |
179 | if (y) *y = m_clipY1; | |
180 | if (width) *width = (m_clipX2 - m_clipX1); | |
181 | if (height) *height = (m_clipY2 - m_clipY1); | |
182 | } | |
183 | else | |
184 | *x = *y = *width = *height = 0; | |
ff7b1510 | 185 | } |
c801d85f KB |
186 | |
187 | void wxDC::GetSize( int* width, int* height ) const | |
188 | { | |
189 | *width = m_maxX-m_minX; | |
190 | *height = m_maxY-m_minY; | |
ff7b1510 | 191 | } |
c801d85f KB |
192 | |
193 | void wxDC::GetSizeMM( long* width, long* height ) const | |
194 | { | |
195 | int w = 0; | |
196 | int h = 0; | |
197 | GetSize( &w, &h ); | |
198 | *width = long( double(w) / (m_scaleX*m_mm_to_pix_x) ); | |
199 | *height = long( double(h) / (m_scaleY*m_mm_to_pix_y) ); | |
ff7b1510 | 200 | } |
c801d85f KB |
201 | |
202 | void wxDC::SetTextForeground( const wxColour &col ) | |
203 | { | |
204 | if (!Ok()) return; | |
205 | m_textForegroundColour = col; | |
ff7b1510 | 206 | } |
c801d85f KB |
207 | |
208 | void wxDC::SetTextBackground( const wxColour &col ) | |
209 | { | |
210 | if (!Ok()) return; | |
211 | m_textBackgroundColour = col; | |
ff7b1510 | 212 | } |
c801d85f KB |
213 | |
214 | void wxDC::SetMapMode( int mode ) | |
215 | { | |
216 | switch (mode) | |
217 | { | |
218 | case MM_TWIPS: | |
219 | SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); | |
220 | break; | |
221 | case MM_POINTS: | |
222 | SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y ); | |
223 | break; | |
224 | case MM_METRIC: | |
225 | SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); | |
226 | break; | |
227 | case MM_LOMETRIC: | |
228 | SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 ); | |
229 | break; | |
230 | default: | |
231 | case MM_TEXT: | |
232 | SetLogicalScale( 1.0, 1.0 ); | |
233 | break; | |
ff7b1510 | 234 | } |
c801d85f KB |
235 | if (mode != MM_TEXT) |
236 | { | |
237 | m_needComputeScaleX = TRUE; | |
238 | m_needComputeScaleY = TRUE; | |
ff7b1510 RR |
239 | } |
240 | } | |
c801d85f KB |
241 | |
242 | void wxDC::SetUserScale( double x, double y ) | |
243 | { | |
244 | // allow negative ? -> no | |
245 | m_userScaleX = x; | |
246 | m_userScaleY = y; | |
247 | ComputeScaleAndOrigin(); | |
ff7b1510 | 248 | } |
c801d85f KB |
249 | |
250 | void wxDC::GetUserScale( double *x, double *y ) | |
251 | { | |
252 | if (x) *x = m_userScaleX; | |
253 | if (y) *y = m_userScaleY; | |
ff7b1510 | 254 | } |
c801d85f KB |
255 | |
256 | void wxDC::SetLogicalScale( double x, double y ) | |
257 | { | |
258 | // allow negative ? | |
259 | m_logicalScaleX = x; | |
260 | m_logicalScaleY = y; | |
261 | ComputeScaleAndOrigin(); | |
ff7b1510 | 262 | } |
c801d85f KB |
263 | |
264 | void wxDC::GetLogicalScale( double *x, double *y ) | |
265 | { | |
266 | if (x) *x = m_logicalScaleX; | |
267 | if (y) *y = m_logicalScaleY; | |
ff7b1510 | 268 | } |
c801d85f KB |
269 | |
270 | void wxDC::SetLogicalOrigin( long x, long y ) | |
271 | { | |
272 | m_logicalOriginX = x * m_signX; // is this still correct ? | |
273 | m_logicalOriginY = y * m_signY; | |
274 | ComputeScaleAndOrigin(); | |
ff7b1510 | 275 | } |
c801d85f KB |
276 | |
277 | void wxDC::GetLogicalOrigin( long *x, long *y ) | |
278 | { | |
279 | if (x) *x = m_logicalOriginX; | |
280 | if (y) *y = m_logicalOriginY; | |
ff7b1510 | 281 | } |
c801d85f KB |
282 | |
283 | void wxDC::SetDeviceOrigin( long x, long y ) | |
284 | { | |
11026f7b RR |
285 | m_deviceOriginX = x; |
286 | m_deviceOriginY = y; | |
c801d85f | 287 | ComputeScaleAndOrigin(); |
ff7b1510 | 288 | } |
c801d85f KB |
289 | |
290 | void wxDC::GetDeviceOrigin( long *x, long *y ) | |
291 | { | |
d4c99d6f RR |
292 | if (x) *x = m_deviceOriginX; |
293 | if (y) *y = m_deviceOriginY; | |
ff7b1510 | 294 | } |
c801d85f | 295 | |
c801d85f KB |
296 | void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) |
297 | { | |
298 | m_signX = (xLeftRight ? 1 : -1); | |
299 | m_signY = (yBottomUp ? -1 : 1); | |
300 | ComputeScaleAndOrigin(); | |
ff7b1510 | 301 | } |
c801d85f KB |
302 | |
303 | long wxDC::DeviceToLogicalX(long x) const | |
304 | { | |
305 | return XDEV2LOG(x); | |
ff7b1510 | 306 | } |
c801d85f KB |
307 | |
308 | long wxDC::DeviceToLogicalY(long y) const | |
309 | { | |
310 | return YDEV2LOG(y); | |
ff7b1510 | 311 | } |
c801d85f KB |
312 | |
313 | long wxDC::DeviceToLogicalXRel(long x) const | |
314 | { | |
315 | return XDEV2LOGREL(x); | |
ff7b1510 | 316 | } |
c801d85f KB |
317 | |
318 | long wxDC::DeviceToLogicalYRel(long y) const | |
319 | { | |
320 | return YDEV2LOGREL(y); | |
ff7b1510 | 321 | } |
c801d85f KB |
322 | |
323 | long wxDC::LogicalToDeviceX(long x) const | |
324 | { | |
325 | return XLOG2DEV(x); | |
ff7b1510 | 326 | } |
c801d85f KB |
327 | |
328 | long wxDC::LogicalToDeviceY(long y) const | |
329 | { | |
330 | return YLOG2DEV(y); | |
ff7b1510 | 331 | } |
c801d85f KB |
332 | |
333 | long wxDC::LogicalToDeviceXRel(long x) const | |
334 | { | |
335 | return XLOG2DEVREL(x); | |
ff7b1510 | 336 | } |
c801d85f KB |
337 | |
338 | long wxDC::LogicalToDeviceYRel(long y) const | |
339 | { | |
340 | return YLOG2DEVREL(y); | |
ff7b1510 | 341 | } |
c801d85f KB |
342 | |
343 | void wxDC::CalcBoundingBox( long x, long y ) | |
344 | { | |
345 | if (x < m_minX) m_minX = x; | |
346 | if (y < m_minY) m_minY = y; | |
347 | if (x > m_maxX) m_maxX = x; | |
348 | if (y > m_maxY) m_maxY = y; | |
ff7b1510 | 349 | } |
c801d85f KB |
350 | |
351 | void wxDC::ComputeScaleAndOrigin(void) | |
352 | { | |
6f65e337 JS |
353 | // CMB: copy scale to see if it changes |
354 | double origScaleX = m_scaleX; | |
355 | double origScaleY = m_scaleY; | |
356 | ||
c801d85f KB |
357 | m_scaleX = m_logicalScaleX * m_userScaleX; |
358 | m_scaleY = m_logicalScaleY * m_userScaleY; | |
359 | ||
6f65e337 JS |
360 | // CMB: if scale has changed call SetPen to recalulate the line width |
361 | if (m_scaleX != origScaleX || m_scaleY != origScaleY) | |
362 | { | |
363 | // this is a bit artificial, but we need to force wxDC to think | |
364 | // the pen has changed | |
365 | wxPen* pen = GetPen(); | |
366 | wxPen tempPen; | |
367 | m_pen = tempPen; | |
368 | SetPen(pen); | |
369 | } | |
ff7b1510 | 370 | } |
c801d85f | 371 |