]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dc.cpp | |
3 | // Purpose: wxDC class | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "dc.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/dc.h" | |
17 | ||
18 | #if !USE_SHARED_LIBRARY | |
19 | IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) | |
20 | #endif | |
21 | ||
22 | //----------------------------------------------------------------------------- | |
23 | // constants | |
24 | //----------------------------------------------------------------------------- | |
25 | ||
26 | #define mm2inches 0.0393700787402 | |
27 | #define inches2mm 25.4 | |
28 | #define mm2twips 56.6929133859 | |
29 | #define twips2mm 0.0176388888889 | |
30 | #define mm2pt 2.83464566929 | |
31 | #define pt2mm 0.352777777778 | |
32 | ||
1408104d DW |
33 | //----------------------------------------------------------------------------- |
34 | // wxDCBase | |
35 | //----------------------------------------------------------------------------- | |
36 | ||
37 | long wxDCBase::DeviceToLogicalX(long x) const | |
38 | { | |
39 | return XDEV2LOG(x); | |
40 | }; | |
41 | ||
42 | long wxDCBase::DeviceToLogicalY(long y) const | |
43 | { | |
44 | return YDEV2LOG(y); | |
45 | }; | |
46 | ||
47 | long wxDCBase::DeviceToLogicalXRel(long x) const | |
48 | { | |
49 | return XDEV2LOGREL(x); | |
50 | }; | |
51 | ||
52 | long wxDCBase::DeviceToLogicalYRel(long y) const | |
53 | { | |
54 | return YDEV2LOGREL(y); | |
55 | }; | |
56 | ||
57 | long wxDCBase::LogicalToDeviceX(long x) const | |
58 | { | |
59 | return XLOG2DEV(x); | |
60 | }; | |
61 | ||
62 | long wxDCBase::LogicalToDeviceY(long y) const | |
63 | { | |
64 | return YLOG2DEV(y); | |
65 | }; | |
66 | ||
67 | long wxDCBase::LogicalToDeviceXRel(long x) const | |
68 | { | |
69 | return XLOG2DEVREL(x); | |
70 | }; | |
71 | ||
72 | long wxDCBase::LogicalToDeviceYRel(long y) const | |
73 | { | |
74 | return YLOG2DEVREL(y); | |
75 | }; | |
76 | ||
0e320a79 DW |
77 | //----------------------------------------------------------------------------- |
78 | // wxDC | |
79 | //----------------------------------------------------------------------------- | |
80 | ||
81 | wxDC::wxDC(void) | |
82 | { | |
83 | m_ok = FALSE; | |
84 | m_optimize = FALSE; | |
85 | m_autoSetting = FALSE; | |
86 | m_colour = TRUE; | |
87 | m_clipping = FALSE; | |
1408104d | 88 | |
0e320a79 DW |
89 | m_mm_to_pix_x = 1.0; |
90 | m_mm_to_pix_y = 1.0; | |
1408104d | 91 | |
0e320a79 DW |
92 | m_logicalOriginX = 0; |
93 | m_logicalOriginY = 0; | |
94 | m_deviceOriginX = 0; | |
95 | m_deviceOriginY = 0; | |
96 | m_internalDeviceOriginX = 0; | |
97 | m_internalDeviceOriginY = 0; | |
98 | m_externalDeviceOriginX = 0; | |
99 | m_externalDeviceOriginY = 0; | |
1408104d | 100 | |
0e320a79 DW |
101 | m_logicalScaleX = 1.0; |
102 | m_logicalScaleY = 1.0; | |
103 | m_userScaleX = 1.0; | |
104 | m_userScaleY = 1.0; | |
105 | m_scaleX = 1.0; | |
106 | m_scaleY = 1.0; | |
1408104d | 107 | |
0e320a79 DW |
108 | m_mappingMode = wxMM_TEXT; |
109 | m_needComputeScaleX = FALSE; | |
110 | m_needComputeScaleY = FALSE; | |
1408104d | 111 | |
0e320a79 DW |
112 | m_signX = 1; // default x-axis left to right |
113 | m_signY = 1; // default y-axis top down | |
114 | ||
115 | m_maxX = m_maxY = -100000; | |
116 | m_minY = m_minY = 100000; | |
117 | ||
118 | m_logicalFunction = wxCOPY; | |
119 | // m_textAlignment = wxALIGN_TOP_LEFT; | |
120 | m_backgroundMode = wxTRANSPARENT; | |
1408104d | 121 | |
0e320a79 DW |
122 | m_textForegroundColour = *wxBLACK; |
123 | m_textBackgroundColour = *wxWHITE; | |
124 | m_pen = *wxBLACK_PEN; | |
125 | m_font = *wxNORMAL_FONT; | |
126 | m_brush = *wxTRANSPARENT_BRUSH; | |
127 | m_backgroundBrush = *wxWHITE_BRUSH; | |
1408104d | 128 | |
0e320a79 DW |
129 | // m_palette = wxAPP_COLOURMAP; |
130 | }; | |
131 | ||
132 | wxDC::~wxDC(void) | |
133 | { | |
134 | }; | |
135 | ||
0e320a79 DW |
136 | void wxDC::DestroyClippingRegion(void) |
137 | { | |
138 | m_clipping = FALSE; | |
139 | }; | |
140 | ||
0e320a79 DW |
141 | void wxDC::GetSize( int* width, int* height ) const |
142 | { | |
143 | *width = m_maxX-m_minX; | |
144 | *height = m_maxY-m_minY; | |
145 | }; | |
146 | ||
147 | void wxDC::GetSizeMM( long* width, long* height ) const | |
148 | { | |
149 | int w = 0; | |
150 | int h = 0; | |
151 | GetSize( &w, &h ); | |
152 | *width = long( double(w) / (m_scaleX*m_mm_to_pix_x) ); | |
153 | *height = long( double(h) / (m_scaleY*m_mm_to_pix_y) ); | |
154 | }; | |
155 | ||
0e320a79 DW |
156 | void wxDC::SetMapMode( int mode ) |
157 | { | |
1408104d | 158 | switch (mode) |
0e320a79 DW |
159 | { |
160 | case wxMM_TWIPS: | |
161 | SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); | |
162 | break; | |
163 | case wxMM_POINTS: | |
164 | SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y ); | |
165 | break; | |
166 | case wxMM_METRIC: | |
167 | SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); | |
168 | break; | |
169 | case wxMM_LOMETRIC: | |
170 | SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 ); | |
171 | break; | |
172 | default: | |
173 | case wxMM_TEXT: | |
174 | SetLogicalScale( 1.0, 1.0 ); | |
175 | break; | |
176 | }; | |
177 | if (mode != wxMM_TEXT) | |
178 | { | |
179 | m_needComputeScaleX = TRUE; | |
180 | m_needComputeScaleY = TRUE; | |
181 | }; | |
182 | }; | |
183 | ||
184 | void wxDC::SetUserScale( double x, double y ) | |
185 | { | |
186 | // allow negative ? -> no | |
187 | m_userScaleX = x; | |
188 | m_userScaleY = y; | |
189 | ComputeScaleAndOrigin(); | |
190 | }; | |
191 | ||
192 | void wxDC::GetUserScale( double *x, double *y ) | |
193 | { | |
194 | if (x) *x = m_userScaleX; | |
195 | if (y) *y = m_userScaleY; | |
196 | }; | |
197 | ||
198 | void wxDC::SetLogicalScale( double x, double y ) | |
199 | { | |
200 | // allow negative ? | |
201 | m_logicalScaleX = x; | |
202 | m_logicalScaleY = y; | |
203 | ComputeScaleAndOrigin(); | |
204 | }; | |
205 | ||
0e320a79 DW |
206 | void wxDC::SetLogicalOrigin( long x, long y ) |
207 | { | |
208 | m_logicalOriginX = x * m_signX; // is this still correct ? | |
209 | m_logicalOriginY = y * m_signY; | |
210 | ComputeScaleAndOrigin(); | |
211 | }; | |
212 | ||
0e320a79 DW |
213 | void wxDC::SetDeviceOrigin( long x, long y ) |
214 | { | |
215 | m_externalDeviceOriginX = x; | |
216 | m_externalDeviceOriginY = y; | |
217 | ComputeScaleAndOrigin(); | |
218 | }; | |
219 | ||
0e320a79 DW |
220 | void wxDC::SetInternalDeviceOrigin( long x, long y ) |
221 | { | |
222 | m_internalDeviceOriginX = x; | |
223 | m_internalDeviceOriginY = y; | |
224 | ComputeScaleAndOrigin(); | |
225 | }; | |
226 | ||
227 | void wxDC::GetInternalDeviceOrigin( long *x, long *y ) | |
228 | { | |
229 | if (x) *x = m_internalDeviceOriginX; | |
230 | if (y) *y = m_internalDeviceOriginY; | |
231 | }; | |
232 | ||
233 | void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) | |
234 | { | |
235 | m_signX = (xLeftRight ? 1 : -1); | |
236 | m_signY = (yBottomUp ? -1 : 1); | |
237 | ComputeScaleAndOrigin(); | |
238 | }; | |
239 | ||
1408104d DW |
240 | |
241 | int wxDC::GetDepth() const | |
0e320a79 | 242 | { |
1408104d DW |
243 | // TODO: |
244 | return (1); | |
245 | } | |
0e320a79 | 246 | |
1408104d | 247 | wxSize wxDC::GetPPI() const |
0e320a79 | 248 | { |
1408104d DW |
249 | // TODO: |
250 | return (1); | |
251 | } | |
252 | void wxDC::GetTextExtent( const wxString& string | |
253 | ,long* x | |
254 | ,long* y | |
255 | ,long* decent | |
256 | ,long* externalLeading | |
257 | ,wxFont* theFont | |
258 | ) const | |
259 | { | |
260 | // TODO: | |
261 | } | |
0e320a79 | 262 | |
1408104d | 263 | void wxDC::GetCharWidth() const |
0e320a79 | 264 | { |
1408104d DW |
265 | // TODO |
266 | return(1); | |
267 | } | |
0e320a79 | 268 | |
1408104d | 269 | void wxDC::GetCharHeight() const |
0e320a79 | 270 | { |
1408104d DW |
271 | // TODO |
272 | return(1); | |
273 | } | |
0e320a79 | 274 | |
1408104d | 275 | void wxDC::Clear() |
0e320a79 | 276 | { |
1408104d DW |
277 | // TODO |
278 | } | |
0e320a79 | 279 | |
1408104d | 280 | void wxDC::SetFont(const wxFont& font) |
0e320a79 | 281 | { |
1408104d DW |
282 | // TODO |
283 | } | |
0e320a79 | 284 | |
1408104d | 285 | void wxDC::SetPen(const wxPen& pen) |
0e320a79 | 286 | { |
1408104d DW |
287 | // TODO |
288 | } | |
289 | void wxDC::SetBrush(const wxBrush& brush) | |
290 | { | |
291 | // TODO | |
292 | } | |
0e320a79 | 293 | |
1408104d | 294 | void wxDC::SetBackground(const wxBrush& brush) |
0e320a79 | 295 | { |
1408104d DW |
296 | // TODO |
297 | } | |
298 | ||
299 | void wxDC::SetLogicalFunction(int function) | |
0e320a79 | 300 | { |
1408104d DW |
301 | // TODO |
302 | } | |
303 | ||
304 | void wxDC::SetBackgroundMode(int mode) | |
305 | { | |
306 | // TODO | |
307 | } | |
308 | ||
309 | void wxDC::SetPalette(const wxPalette& palette) | |
310 | { | |
311 | // TODO | |
312 | } | |
313 | ||
314 | void wxDC::DoFloodFill( long x | |
315 | ,long y | |
316 | ,const wxColour& col | |
317 | ,int style = wxFLOOD_SURFACE | |
318 | ) | |
319 | { | |
320 | // TODO | |
321 | } | |
322 | ||
323 | bool wxDC::DoGetPixel(long x, long y, wxColour *col) const | |
324 | { | |
325 | // TODO | |
326 | return(TRUE); | |
327 | } | |
328 | ||
329 | void wxDC::DoDrawPoint(long x, long y) | |
330 | { | |
331 | // TODO | |
332 | } | |
333 | ||
334 | void wxDC::DoDrawLine(long x1, long y1, long x2, long y2) | |
335 | { | |
336 | // TODO | |
337 | } | |
338 | ||
339 | void wxDC::DoDrawArc( long x1, long y1 | |
340 | ,long x2, long y2 | |
341 | ,long xc, long yc | |
342 | ) | |
343 | { | |
344 | // TODO | |
345 | } | |
346 | ||
347 | void wxDC::DoDrawEllipticArc( long x | |
348 | ,long y | |
349 | ,long w | |
350 | ,long h | |
351 | ,double sa | |
352 | ,double ea | |
353 | ) | |
354 | { | |
355 | // TODO | |
356 | } | |
357 | ||
358 | void wxDC::DoDrawRectangle(long x, long y, long width, long height) | |
359 | { | |
360 | // TODO | |
361 | } | |
362 | ||
363 | void wxDC::DoDrawRoundedRectangle( long x, long y | |
364 | ,long width, long height | |
365 | ,double radius | |
366 | ) | |
367 | { | |
368 | // TODO | |
369 | } | |
370 | ||
371 | void wxDC::DoDrawEllipse(long x, long y, long width, long height) | |
372 | { | |
373 | // TODO | |
374 | } | |
375 | ||
376 | void wxDC::DoCrossHair(long x, long y) | |
377 | { | |
378 | // TODO | |
379 | } | |
380 | ||
381 | void wxDC::DoDrawIcon(const wxIcon& icon, long x, long y) | |
382 | { | |
383 | // TODO | |
384 | } | |
385 | ||
386 | void wxDC::DoDrawBitmap( const wxBitmap &bmp | |
387 | ,long x, long y | |
388 | ,bool useMask = FALSE | |
389 | ) | |
390 | { | |
391 | // TODO | |
392 | } | |
393 | ||
394 | void wxDC::DoDrawText(const wxString& text, long x, long y) | |
395 | { | |
396 | // TODO | |
397 | } | |
398 | ||
399 | bool wxDC::DoBlit( long xdest | |
400 | ,long ydest | |
401 | ,long width | |
402 | ,long height | |
403 | ,wxDC *source | |
404 | ,long xsrc | |
405 | ,long ysrc | |
406 | ,int rop = wxCOPY | |
407 | ,bool useMask = FALSE | |
408 | ) | |
409 | { | |
410 | // TODO | |
411 | return(TRUE); | |
412 | } | |
413 | ||
414 | void wxDC::DoGetSize(int *width, int *height) const | |
415 | { | |
416 | // TODO | |
417 | } | |
418 | ||
419 | void wxDC::DoGetSizeMM(int* width, int* height) const | |
420 | { | |
421 | // TODO | |
422 | } | |
423 | ||
424 | void wxDC::DoDrawLines( int n, wxPoint points[] | |
425 | ,long xoffset, long yoffset | |
426 | ) | |
427 | { | |
428 | // TODO | |
429 | } | |
430 | ||
431 | void wxDC::DoDrawPolygon(int n, wxPoint points[] | |
432 | ,long xoffset, long yoffset | |
433 | ,int fillStyle = wxODDEVEN_RULE | |
434 | ) | |
435 | { | |
436 | // TODO | |
437 | } | |
438 | ||
439 | void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) | |
440 | { | |
441 | // TODO | |
442 | } | |
443 | ||
444 | void wxDC::DoSetClippingRegion( long x, long y | |
445 | ,long width, long height | |
446 | ) | |
447 | { | |
448 | // TODO | |
449 | } | |
450 | ||
451 | #if wxUSE_SPLINES | |
452 | void wxDC::DoDrawSpline(wxList *points) | |
453 | { | |
454 | // TODO | |
455 | } | |
456 | #endif | |
457 | ||
458 | // | |
459 | // Private functions | |
460 | // | |
461 | long wxDC::XDEV2LOG(long x) const | |
462 | { | |
463 | long new_x = x - m_deviceOriginX; | |
464 | if (new_x > 0) | |
465 | return (long)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX; | |
466 | else | |
467 | return (long)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX; | |
468 | } | |
469 | ||
470 | long wxDC::XDEV2LOGREL(long x) const | |
471 | { | |
472 | if (x > 0) | |
473 | return (long)((double)(x) / m_scaleX + 0.5); | |
474 | else | |
475 | return (long)((double)(x) / m_scaleX - 0.5); | |
476 | } | |
477 | ||
478 | long wxDC::YDEV2LOG(long y) const | |
479 | { | |
480 | long new_y = y - m_deviceOriginY; | |
481 | if (new_y > 0) | |
482 | return (long)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY; | |
483 | else | |
484 | return (long)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY; | |
485 | } | |
486 | ||
487 | long wxDC::YDEV2LOGREL(long y) const | |
488 | { | |
489 | if (y > 0) | |
490 | return (long)((double)(y) / m_scaleY + 0.5); | |
491 | else | |
492 | return (long)((double)(y) / m_scaleY - 0.5); | |
493 | } | |
494 | ||
495 | long wxDC::XLOG2DEV(long x) const | |
496 | { | |
497 | long new_x = x - m_logicalOriginX; | |
498 | if (new_x > 0) | |
499 | return (long)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX; | |
500 | else | |
501 | return (long)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX; | |
502 | } | |
503 | ||
504 | long wxDC::XLOG2DEVREL(long x) const | |
505 | { | |
506 | if (x > 0) | |
507 | return (long)((double)(x) * m_scaleX + 0.5); | |
508 | else | |
509 | return (long)((double)(x) * m_scaleX - 0.5); | |
510 | } | |
511 | ||
512 | long wxDC::YLOG2DEV(long y) const | |
513 | { | |
514 | long new_y = y - m_logicalOriginY; | |
515 | if (new_y > 0) | |
516 | return (long)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY; | |
517 | else | |
518 | return (long)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY; | |
519 | } | |
520 | ||
521 | long wxDC::YLOG2DEVREL(long y) const | |
522 | { | |
523 | if (y > 0) | |
524 | return (long)((double)(y) * m_scaleY + 0.5); | |
525 | else | |
526 | return (long)((double)(y) * m_scaleY - 0.5); | |
527 | } | |
0e320a79 DW |
528 | |
529 | void wxDC::ComputeScaleAndOrigin(void) | |
530 | { | |
531 | // CMB: copy scale to see if it changes | |
532 | double origScaleX = m_scaleX; | |
533 | double origScaleY = m_scaleY; | |
534 | ||
535 | m_scaleX = m_logicalScaleX * m_userScaleX; | |
536 | m_scaleY = m_logicalScaleY * m_userScaleY; | |
537 | ||
538 | m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX; | |
539 | m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY; | |
540 | ||
1408104d | 541 | // CMB: if scale has changed call SetPen to recalulate the line width |
0e320a79 DW |
542 | if (m_scaleX != origScaleX || m_scaleY != origScaleY) |
543 | { | |
544 | // this is a bit artificial, but we need to force wxDC to think | |
545 | // the pen has changed | |
546 | wxPen* pen = & GetPen(); | |
547 | wxPen tempPen; | |
548 | m_pen = tempPen; | |
549 | SetPen(* pen); | |
550 | } | |
551 | }; | |
552 |