]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
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" | |
03e11df5 | 17 | #include "wx/app.h" |
2f1ae414 | 18 | #include "wx/mac/uma.h" |
3dec57ad SC |
19 | #include "wx/dcmemory.h" |
20 | #include "wx/region.h" | |
21 | #include "wx/image.h" | |
e9576ca5 | 22 | |
5b781a67 SC |
23 | #if __MSL__ >= 0x6000 |
24 | #include "math.h" | |
25 | #endif | |
26 | ||
2f1ae414 | 27 | #if !USE_SHARED_LIBRARY |
e9576ca5 | 28 | IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) |
2f1ae414 | 29 | #endif |
e9576ca5 SC |
30 | |
31 | //----------------------------------------------------------------------------- | |
32 | // constants | |
33 | //----------------------------------------------------------------------------- | |
34 | ||
35 | #define mm2inches 0.0393700787402 | |
36 | #define inches2mm 25.4 | |
37 | #define mm2twips 56.6929133859 | |
38 | #define twips2mm 0.0176388888889 | |
39 | #define mm2pt 2.83464566929 | |
40 | #define pt2mm 0.352777777778 | |
2461b2e7 | 41 | #ifndef __UNIX__ |
3dec57ad | 42 | const double M_PI = 3.14159265358979 ; |
2461b2e7 | 43 | #endif |
3dec57ad SC |
44 | const double RAD2DEG = 180.0 / M_PI; |
45 | ||
46 | //----------------------------------------------------------------------------- | |
47 | // Local functions | |
48 | //----------------------------------------------------------------------------- | |
49 | ||
50 | static inline double dmin(double a, double b) { return a < b ? a : b; } | |
51 | static inline double dmax(double a, double b) { return a > b ? a : b; } | |
52 | static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } | |
e9576ca5 SC |
53 | |
54 | //----------------------------------------------------------------------------- | |
55 | // wxDC | |
56 | //----------------------------------------------------------------------------- | |
57 | ||
2f1ae414 | 58 | wxDC::wxDC() |
e9576ca5 SC |
59 | { |
60 | m_ok = FALSE; | |
e9576ca5 | 61 | m_colour = TRUE; |
e9576ca5 | 62 | |
2f1ae414 SC |
63 | m_mm_to_pix_x = mm2pt; |
64 | m_mm_to_pix_y = mm2pt; | |
e9576ca5 | 65 | |
e9576ca5 SC |
66 | m_internalDeviceOriginX = 0; |
67 | m_internalDeviceOriginY = 0; | |
68 | m_externalDeviceOriginX = 0; | |
69 | m_externalDeviceOriginY = 0; | |
70 | ||
71 | m_logicalScaleX = 1.0; | |
72 | m_logicalScaleY = 1.0; | |
73 | m_userScaleX = 1.0; | |
74 | m_userScaleY = 1.0; | |
75 | m_scaleX = 1.0; | |
76 | m_scaleY = 1.0; | |
77 | ||
e9576ca5 SC |
78 | m_needComputeScaleX = FALSE; |
79 | m_needComputeScaleY = FALSE; | |
80 | ||
e9576ca5 SC |
81 | m_maxX = m_maxY = -100000; |
82 | m_minY = m_minY = 100000; | |
83 | ||
519cb848 | 84 | m_macPort = NULL ; |
8208e181 | 85 | m_macMask = NULL ; |
519cb848 SC |
86 | m_ok = FALSE ; |
87 | ||
88 | m_macFontInstalled = false ; | |
89 | m_macBrushInstalled = false ; | |
90 | m_macPenInstalled = false ; | |
91 | ||
519cb848 SC |
92 | m_macLocalOrigin.h = m_macLocalOrigin.v = 0 ; |
93 | m_macClipRect.left = -32000 ; | |
94 | m_macClipRect.top = -32000 ; | |
95 | m_macClipRect.right = 32000 ; | |
96 | m_macClipRect.bottom = 32000 ; | |
9ff647cf SC |
97 | |
98 | m_pen = *wxBLACK_PEN; | |
99 | m_font = *wxNORMAL_FONT; | |
100 | m_brush = *wxWHITE_BRUSH; | |
3dec57ad | 101 | } |
f87a708b | 102 | wxMacPortSetter::wxMacPortSetter( const wxDC* dc ) : |
0eaa1d68 SC |
103 | m_ph( dc->m_macPort ) |
104 | { | |
105 | wxASSERT( dc->Ok() ) ; | |
106 | ||
107 | dc->MacSetupPort(&m_ph) ; | |
108 | } | |
109 | ||
110 | wxMacPortSetter::~wxMacPortSetter() | |
111 | { | |
112 | } | |
113 | ||
e9576ca5 SC |
114 | wxDC::~wxDC(void) |
115 | { | |
3dec57ad | 116 | } |
0eaa1d68 | 117 | void wxDC::MacSetupPort(AGAPortHelper* help) const |
519cb848 | 118 | { |
b668a735 | 119 | // help->Setup( m_macPort ) ; |
519cb848 | 120 | ::SetOrigin(-m_macLocalOrigin.h, -m_macLocalOrigin.v); |
a8cd4a3a | 121 | |
65608e3b SC |
122 | if ( m_clipping ) |
123 | { | |
3dec57ad | 124 | Rect clip = { m_clipY1 , m_clipX1 , m_clipY2 , m_clipX2 } ; |
65608e3b SC |
125 | ::SectRect( &clip , &m_macClipRect , &clip ) ; |
126 | ::ClipRect( &clip ) ; | |
127 | } | |
128 | else | |
129 | { | |
130 | ::ClipRect(&m_macClipRect); | |
131 | } | |
132 | ||
519cb848 SC |
133 | |
134 | m_macFontInstalled = false ; | |
135 | m_macBrushInstalled = false ; | |
136 | m_macPenInstalled = false ; | |
137 | } | |
138 | ||
2f1ae414 | 139 | void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask ) |
519cb848 | 140 | { |
3dec57ad SC |
141 | wxCHECK_RET( Ok(), wxT("invalid window dc") ); |
142 | ||
143 | wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") ); | |
144 | ||
145 | wxMacPortSetter helper(this) ; | |
146 | ||
147 | wxCoord xx = XLOG2DEV(x); | |
148 | wxCoord yy = YLOG2DEV(y); | |
149 | wxCoord w = bmp.GetWidth(); | |
150 | wxCoord h = bmp.GetHeight(); | |
151 | wxCoord ww = XLOG2DEVREL(w); | |
152 | wxCoord hh = YLOG2DEVREL(h); | |
153 | ||
154 | // Set up drawing mode | |
155 | short mode = (m_logicalFunction == wxCOPY ? srcCopy : | |
156 | //m_logicalFunction == wxCLEAR ? WHITENESS : | |
157 | //m_logicalFunction == wxSET ? BLACKNESS : | |
158 | m_logicalFunction == wxINVERT ? hilite : | |
159 | //m_logicalFunction == wxAND ? MERGECOPY : | |
160 | m_logicalFunction == wxOR ? srcOr : | |
161 | m_logicalFunction == wxSRC_INVERT ? notSrcCopy : | |
162 | m_logicalFunction == wxXOR ? srcXor : | |
163 | m_logicalFunction == wxOR_REVERSE ? notSrcOr : | |
164 | //m_logicalFunction == wxAND_REVERSE ? SRCERASE : | |
165 | //m_logicalFunction == wxSRC_OR ? srcOr : | |
166 | //m_logicalFunction == wxSRC_AND ? SRCAND : | |
167 | srcCopy ); | |
168 | ||
169 | if ( bmp.GetBitmapType() == kMacBitmapTypePict ) { | |
170 | Rect bitmaprect = { 0 , 0 , hh, ww }; | |
171 | ::OffsetRect( &bitmaprect, xx, yy ) ; | |
172 | ::DrawPicture( bmp.GetPict(), &bitmaprect ) ; | |
519cb848 | 173 | } |
3dec57ad SC |
174 | else if ( bmp.GetBitmapType() == kMacBitmapTypeGrafWorld ) |
175 | { | |
176 | GWorldPtr bmapworld = bmp.GetHBITMAP(); | |
177 | PixMapHandle bmappixels ; | |
178 | ||
179 | // Set foreground and background colours (for bitmaps depth = 1) | |
180 | if(bmp.GetDepth() == 1) | |
181 | { | |
182 | RGBColor fore = m_textForegroundColour.GetPixel(); | |
183 | RGBColor back = m_textBackgroundColour.GetPixel(); | |
184 | RGBForeColor(&fore); | |
185 | RGBBackColor(&back); | |
186 | } | |
187 | else | |
188 | { | |
189 | RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ; | |
190 | RGBColor black = { 0,0,0} ; | |
191 | RGBForeColor( &black ) ; | |
192 | RGBBackColor( &white ) ; | |
193 | } | |
194 | ||
195 | bmappixels = GetGWorldPixMap( bmapworld ) ; | |
196 | ||
197 | wxCHECK_RET(LockPixels(bmappixels), | |
198 | wxT("DoDrawBitmap: Unable to lock pixels")); | |
199 | ||
200 | Rect source = { 0, 0, h, w }; | |
201 | Rect dest = { yy, xx, yy + hh, xx + ww }; | |
202 | ||
203 | if ( useMask && bmp.GetMask() ) | |
204 | { | |
205 | if( LockPixels(GetGWorldPixMap(bmp.GetMask()->GetMaskBitmap()))) | |
206 | { | |
207 | CopyDeepMask | |
208 | ( | |
209 | GetPortBitMapForCopyBits(bmapworld), | |
210 | GetPortBitMapForCopyBits(bmp.GetMask()->GetMaskBitmap()), | |
211 | GetPortBitMapForCopyBits( m_macPort ), | |
212 | &source, &source, &dest, mode, NULL | |
213 | ); | |
214 | UnlockPixels(GetGWorldPixMap(bmp.GetMask()->GetMaskBitmap())); | |
215 | } | |
216 | } | |
217 | else { | |
218 | CopyBits( GetPortBitMapForCopyBits( bmapworld ), | |
219 | GetPortBitMapForCopyBits( m_macPort ), | |
220 | &source, &dest, mode, NULL ) ; | |
221 | } | |
222 | UnlockPixels( bmappixels ) ; | |
223 | } | |
224 | else if ( bmp.GetBitmapType() == kMacBitmapTypeIcon ) | |
225 | { | |
226 | Rect bitmaprect = { 0 , 0 , bmp.GetHeight(), bmp.GetWidth() } ; | |
227 | OffsetRect( &bitmaprect, xx, yy ) ; | |
228 | PlotCIconHandle( &bitmaprect , atNone , ttNone , bmp.GetHICON() ) ; | |
229 | } | |
230 | m_macPenInstalled = false ; | |
231 | m_macBrushInstalled = false ; | |
232 | m_macFontInstalled = false ; | |
233 | ||
519cb848 SC |
234 | } |
235 | ||
2f1ae414 | 236 | void wxDC::DoDrawIcon( const wxIcon &icon, wxCoord x, wxCoord y ) |
e9576ca5 | 237 | { |
3dec57ad SC |
238 | wxCHECK_RET(Ok(), wxT("Invalid dc wxDC::DoDrawIcon")); |
239 | ||
240 | wxCHECK_RET(icon.Ok(), wxT("Invalid icon wxDC::DoDrawIcon")); | |
241 | ||
a2f94f40 | 242 | DoDrawBitmap( icon , x , y , icon.GetMask() != NULL ) ; |
3dec57ad | 243 | } |
2f1ae414 | 244 | void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
e9576ca5 | 245 | { |
3dec57ad SC |
246 | wxCHECK_RET(Ok(), wxT("wxDC::DoSetClippingRegion Invalid DC")); |
247 | wxCoord xx, yy, ww, hh; | |
248 | ||
249 | xx = XLOG2DEV(x); | |
250 | yy = YLOG2DEV(y); | |
251 | ww = XLOG2DEVREL(width); | |
252 | hh = YLOG2DEVREL(height); | |
e9576ca5 | 253 | |
3dec57ad SC |
254 | if( m_clipping ) |
255 | { | |
256 | m_clipX1 = wxMax( m_clipX1 , xx ); | |
257 | m_clipY1 = wxMax( m_clipY1 , yy ); | |
258 | m_clipX2 = wxMin( m_clipX2, (xx + ww)); | |
259 | m_clipY2 = wxMin( m_clipY2, (yy + hh)); | |
260 | } | |
261 | else | |
262 | { | |
263 | m_clipping = TRUE; | |
264 | m_clipX1 = xx; | |
265 | m_clipY1 = yy; | |
266 | m_clipX2 = xx + ww; | |
267 | m_clipY2 = yy + hh; | |
268 | } | |
269 | ||
270 | } | |
2f1ae414 SC |
271 | void wxDC::DoSetClippingRegionAsRegion( const wxRegion ®ion ) |
272 | { | |
3dec57ad | 273 | wxCHECK_RET( Ok(), wxT("invalid window dc") ) ; |
2f1ae414 | 274 | |
0eaa1d68 | 275 | wxMacPortSetter helper(this) ; |
2f1ae414 SC |
276 | if (region.Empty()) |
277 | { | |
278 | DestroyClippingRegion(); | |
279 | return; | |
280 | } | |
281 | ||
282 | wxCoord xx, yy, ww, hh; | |
283 | region.GetBox( xx, yy, ww, hh ); | |
284 | wxDC::DoSetClippingRegion( xx, yy, ww, hh ); | |
ee41971c UJ |
285 | } |
286 | ||
3dec57ad | 287 | void wxDC::DestroyClippingRegion() |
e9576ca5 | 288 | { |
0eaa1d68 | 289 | wxMacPortSetter helper(this) ; |
e9576ca5 | 290 | m_clipping = FALSE; |
3dec57ad | 291 | } |
2f1ae414 | 292 | void wxDC::DoGetSize( int* width, int* height ) const |
e9576ca5 SC |
293 | { |
294 | *width = m_maxX-m_minX; | |
295 | *height = m_maxY-m_minY; | |
3dec57ad | 296 | } |
2f1ae414 | 297 | void wxDC::DoGetSizeMM( int* width, int* height ) const |
e9576ca5 SC |
298 | { |
299 | int w = 0; | |
300 | int h = 0; | |
301 | GetSize( &w, &h ); | |
302 | *width = long( double(w) / (m_scaleX*m_mm_to_pix_x) ); | |
303 | *height = long( double(h) / (m_scaleY*m_mm_to_pix_y) ); | |
3dec57ad | 304 | } |
e9576ca5 SC |
305 | void wxDC::SetTextForeground( const wxColour &col ) |
306 | { | |
3dec57ad SC |
307 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
308 | m_textForegroundColour = col; | |
309 | m_macFontInstalled = false ; | |
310 | } | |
e9576ca5 SC |
311 | void wxDC::SetTextBackground( const wxColour &col ) |
312 | { | |
3dec57ad SC |
313 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
314 | m_textBackgroundColour = col; | |
315 | m_macFontInstalled = false ; | |
316 | } | |
e9576ca5 SC |
317 | void wxDC::SetMapMode( int mode ) |
318 | { | |
319 | switch (mode) | |
320 | { | |
e3065973 | 321 | case wxMM_TWIPS: |
e9576ca5 SC |
322 | SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); |
323 | break; | |
e3065973 | 324 | case wxMM_POINTS: |
e9576ca5 SC |
325 | SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y ); |
326 | break; | |
e3065973 | 327 | case wxMM_METRIC: |
e9576ca5 SC |
328 | SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); |
329 | break; | |
e3065973 | 330 | case wxMM_LOMETRIC: |
e9576ca5 SC |
331 | SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 ); |
332 | break; | |
333 | default: | |
e3065973 | 334 | case wxMM_TEXT: |
e9576ca5 SC |
335 | SetLogicalScale( 1.0, 1.0 ); |
336 | break; | |
3dec57ad | 337 | } |
e3065973 | 338 | if (mode != wxMM_TEXT) |
e9576ca5 SC |
339 | { |
340 | m_needComputeScaleX = TRUE; | |
341 | m_needComputeScaleY = TRUE; | |
3dec57ad SC |
342 | } |
343 | } | |
e9576ca5 SC |
344 | void wxDC::SetUserScale( double x, double y ) |
345 | { | |
346 | // allow negative ? -> no | |
347 | m_userScaleX = x; | |
348 | m_userScaleY = y; | |
349 | ComputeScaleAndOrigin(); | |
3dec57ad | 350 | } |
e9576ca5 SC |
351 | void wxDC::SetLogicalScale( double x, double y ) |
352 | { | |
353 | // allow negative ? | |
354 | m_logicalScaleX = x; | |
355 | m_logicalScaleY = y; | |
356 | ComputeScaleAndOrigin(); | |
3dec57ad | 357 | } |
2f1ae414 | 358 | void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) |
e9576ca5 SC |
359 | { |
360 | m_logicalOriginX = x * m_signX; // is this still correct ? | |
361 | m_logicalOriginY = y * m_signY; | |
362 | ComputeScaleAndOrigin(); | |
3dec57ad | 363 | } |
2f1ae414 | 364 | void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) |
e9576ca5 SC |
365 | { |
366 | m_externalDeviceOriginX = x; | |
367 | m_externalDeviceOriginY = y; | |
368 | ComputeScaleAndOrigin(); | |
3dec57ad SC |
369 | } |
370 | ||
371 | #if 0 | |
e9576ca5 SC |
372 | void wxDC::SetInternalDeviceOrigin( long x, long y ) |
373 | { | |
374 | m_internalDeviceOriginX = x; | |
375 | m_internalDeviceOriginY = y; | |
376 | ComputeScaleAndOrigin(); | |
3dec57ad | 377 | } |
e9576ca5 SC |
378 | void wxDC::GetInternalDeviceOrigin( long *x, long *y ) |
379 | { | |
380 | if (x) *x = m_internalDeviceOriginX; | |
381 | if (y) *y = m_internalDeviceOriginY; | |
3dec57ad SC |
382 | } |
383 | #endif | |
e9576ca5 SC |
384 | void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) |
385 | { | |
386 | m_signX = (xLeftRight ? 1 : -1); | |
387 | m_signY = (yBottomUp ? -1 : 1); | |
388 | ComputeScaleAndOrigin(); | |
3dec57ad | 389 | }/* |
e9576ca5 SC |
390 | |
391 | void wxDC::CalcBoundingBox( long x, long y ) | |
392 | { | |
393 | if (x < m_minX) m_minX = x; | |
394 | if (y < m_minY) m_minY = y; | |
395 | if (x > m_maxX) m_maxX = x; | |
396 | if (y > m_maxY) m_maxY = y; | |
3dec57ad | 397 | }*/ |
2f1ae414 SC |
398 | wxSize wxDC::GetPPI() const |
399 | { | |
400 | return wxSize(72, 72); | |
401 | } | |
402 | ||
403 | int wxDC::GetDepth() const | |
404 | { | |
405 | return wxDisplayDepth() ; | |
406 | } | |
e9576ca5 | 407 | |
3dec57ad | 408 | void wxDC::ComputeScaleAndOrigin() |
e9576ca5 SC |
409 | { |
410 | // CMB: copy scale to see if it changes | |
411 | double origScaleX = m_scaleX; | |
412 | double origScaleY = m_scaleY; | |
413 | ||
414 | m_scaleX = m_logicalScaleX * m_userScaleX; | |
415 | m_scaleY = m_logicalScaleY * m_userScaleY; | |
416 | ||
417 | m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX; | |
418 | m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY; | |
419 | ||
420 | // CMB: if scale has changed call SetPen to recalulate the line width | |
421 | if (m_scaleX != origScaleX || m_scaleY != origScaleY) | |
422 | { | |
5b781a67 SC |
423 | // this is a bit artificial, but we need to force wxDC to think |
424 | // the pen has changed | |
425 | wxPen* pen = & GetPen(); | |
426 | wxPen tempPen; | |
427 | m_pen = tempPen; | |
428 | SetPen(* pen); | |
e9576ca5 | 429 | } |
3dec57ad | 430 | } |
519cb848 SC |
431 | void wxDC::SetPalette( const wxPalette& palette ) |
432 | { | |
433 | } | |
434 | ||
435 | void wxDC::SetBackgroundMode( int mode ) | |
436 | { | |
437 | m_backgroundMode = mode ; | |
438 | } | |
439 | ||
440 | void wxDC::SetFont( const wxFont &font ) | |
441 | { | |
3dec57ad SC |
442 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
443 | ||
444 | m_font = font; | |
445 | m_macFontInstalled = false ; | |
519cb848 SC |
446 | } |
447 | ||
448 | void wxDC::SetPen( const wxPen &pen ) | |
449 | { | |
3dec57ad | 450 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
519cb848 SC |
451 | |
452 | if ( m_pen == pen ) | |
453 | return ; | |
454 | ||
455 | m_pen = pen; | |
3dec57ad | 456 | |
519cb848 SC |
457 | m_macPenInstalled = false ; |
458 | } | |
459 | ||
460 | void wxDC::SetBrush( const wxBrush &brush ) | |
461 | { | |
3dec57ad | 462 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
519cb848 SC |
463 | |
464 | if (m_brush == brush) | |
465 | return; | |
466 | ||
467 | m_brush = brush; | |
468 | m_macBrushInstalled = false ; | |
469 | } | |
470 | ||
471 | void wxDC::SetBackground( const wxBrush &brush ) | |
472 | { | |
3dec57ad | 473 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
519cb848 SC |
474 | |
475 | if (m_backgroundBrush == brush) | |
476 | return; | |
477 | ||
478 | m_backgroundBrush = brush; | |
479 | ||
480 | if (!m_backgroundBrush.Ok()) | |
481 | return; | |
482 | m_macBrushInstalled = false ; | |
483 | } | |
484 | ||
485 | void wxDC::SetLogicalFunction( int function ) | |
486 | { | |
487 | if (m_logicalFunction == function) | |
488 | return; | |
489 | ||
490 | m_logicalFunction = function ; | |
491 | m_macFontInstalled = false ; | |
492 | m_macBrushInstalled = false ; | |
493 | m_macPenInstalled = false ; | |
494 | } | |
495 | ||
2f1ae414 SC |
496 | void wxDC::DoFloodFill( wxCoord x, wxCoord y, const wxColour& col, |
497 | int style ) | |
519cb848 SC |
498 | { |
499 | } | |
500 | ||
2f1ae414 | 501 | bool wxDC::DoGetPixel( wxCoord x, wxCoord y, wxColour *col ) const |
519cb848 | 502 | { |
3dec57ad SC |
503 | wxCHECK_MSG( Ok(), false, wxT("wxDC::DoGetPixel Invalid DC") ); |
504 | wxMacPortSetter helper(this) ; | |
505 | ||
506 | RGBColor colour; | |
507 | ||
508 | GetCPixel( XLOG2DEV(x), YLOG2DEV(y), &colour ); | |
509 | ||
510 | // Convert from Mac colour to wx | |
511 | col->Set( colour.red >> 8, | |
512 | colour.green >> 8, | |
513 | colour.blue >> 8); | |
514 | ||
515 | return true ; | |
519cb848 SC |
516 | } |
517 | ||
2f1ae414 | 518 | void wxDC::DoDrawLine( wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2 ) |
519cb848 | 519 | { |
3dec57ad | 520 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
519cb848 | 521 | |
0eaa1d68 | 522 | wxMacPortSetter helper(this) ; |
519cb848 SC |
523 | |
524 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
525 | { | |
526 | MacInstallPen() ; | |
3dec57ad SC |
527 | wxCoord offset = ( (m_pen.GetWidth() == 0 ? 1 : |
528 | m_pen.GetWidth() ) * (wxCoord)m_scaleX - 1) / 2; | |
529 | ||
2301e281 RR |
530 | wxCoord xx1 = XLOG2DEV(x1) - offset; |
531 | wxCoord yy1 = YLOG2DEV(y1) - offset; | |
532 | wxCoord xx2 = XLOG2DEV(x2) - offset; | |
533 | wxCoord yy2 = YLOG2DEV(y2) - offset; | |
534 | ||
535 | if ((m_pen.GetCap() == wxCAP_ROUND) && | |
536 | (m_pen.GetWidth() <= 1)) | |
537 | { | |
538 | // Implement LAST_NOT for MAC at least for | |
539 | // orthogonal lines. RR. | |
540 | if (xx1 == xx2) | |
541 | { | |
542 | if (yy1 < yy2) | |
543 | yy2--; | |
544 | if (yy1 > yy2) | |
545 | yy2++; | |
546 | } | |
547 | if (yy1 == yy2) | |
548 | { | |
549 | if (xx1 < xx2) | |
550 | xx2--; | |
551 | if (xx1 > xx2) | |
552 | xx2++; | |
553 | } | |
554 | } | |
555 | ||
556 | ::MoveTo(xx1, yy1); | |
557 | ::LineTo(xx2, yy2); | |
3dec57ad | 558 | } |
519cb848 SC |
559 | } |
560 | ||
2f1ae414 | 561 | void wxDC::DoCrossHair( wxCoord x, wxCoord y ) |
519cb848 | 562 | { |
3dec57ad SC |
563 | wxCHECK_RET( Ok(), wxT("wxDC::DoCrossHair Invalid window dc") ); |
564 | ||
565 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
566 | { | |
567 | int w = 0; | |
568 | int h = 0; | |
569 | GetSize( &w, &h ); | |
570 | wxCoord xx = XLOG2DEV(x); | |
571 | wxCoord yy = YLOG2DEV(y); | |
572 | ||
573 | MacInstallPen(); | |
574 | ::MoveTo( 0, yy ); | |
575 | ::LineTo( XLOG2DEVREL(w), yy ); | |
576 | ::MoveTo( xx, 0 ); | |
577 | ::LineTo( xx, YLOG2DEVREL(h) ); | |
578 | } | |
579 | } | |
580 | ||
581 | /* | |
582 | * To draw arcs properly the angles need to be converted from the WX style: | |
583 | * Angles start on the +ve X axis and go anti-clockwise (As you would draw on | |
584 | * a normal axis on paper). | |
585 | * TO | |
586 | * the Mac style: | |
587 | * Angles start on the +ve y axis and go clockwise. | |
588 | * To achive this I work out which quadrant the angle lies in then map this to | |
589 | * the equivalent quadrant on the Mac. (Sin and Cos values reveal which | |
590 | * quadrant you are in). | |
591 | */ | |
592 | static double wxConvertWXangleToMACangle(double angle) | |
593 | { | |
594 | double sin_a, cos_a; | |
595 | ||
596 | sin_a = sin(angle / RAD2DEG); | |
597 | cos_a = cos(angle / RAD2DEG); | |
598 | ||
599 | if( (sin_a >= 0.0) && (cos_a >= 0.0) ) { | |
600 | angle = acos(sin_a) * RAD2DEG; | |
601 | } | |
602 | else if( (sin_a >= 0.0) && (cos_a <= 0.0) ) { | |
603 | sin_a *= -1; | |
604 | angle = acos(sin_a) * RAD2DEG + 180; | |
605 | } | |
606 | else if( (sin_a <= 0.0) && (cos_a >= 0.0) ) { | |
607 | angle = acos(sin_a) * RAD2DEG + 180; | |
608 | } | |
609 | else if( (sin_a < 0.0) && (cos_a < 0.0) ) { | |
610 | sin_a *= -1; | |
611 | angle = acos(sin_a) * RAD2DEG + 180; | |
612 | } | |
613 | return angle; | |
519cb848 SC |
614 | } |
615 | ||
2f1ae414 SC |
616 | void wxDC::DoDrawArc( wxCoord x1, wxCoord y1, |
617 | wxCoord x2, wxCoord y2, | |
618 | wxCoord xc, wxCoord yc ) | |
519cb848 | 619 | { |
3dec57ad SC |
620 | wxCHECK_RET(Ok(), wxT("wxDC::DoDrawArc Invalid DC")); |
621 | ||
622 | wxCoord xx1 = XLOG2DEV(x1); | |
623 | wxCoord yy1 = YLOG2DEV(y1); | |
624 | wxCoord xx2 = XLOG2DEV(x2); | |
625 | wxCoord yy2 = YLOG2DEV(y2); | |
626 | wxCoord xxc = XLOG2DEV(xc); | |
627 | wxCoord yyc = YLOG2DEV(yc); | |
628 | double dx = xx1 - xxc; | |
629 | double dy = yy1 - yyc; | |
630 | double radius = sqrt((double)(dx*dx+dy*dy)); | |
631 | wxCoord rad = (wxCoord)radius; | |
632 | double radius1, radius2; | |
633 | ||
634 | if (xx1 == xx2 && yy1 == yy2) | |
635 | { | |
636 | radius1 = 0.0; | |
637 | radius2 = 360.0; | |
638 | } | |
639 | else if (radius == 0.0) | |
640 | { | |
641 | radius1 = radius2 = 0.0; | |
642 | } | |
643 | else | |
644 | { | |
645 | radius1 = (xx1 - xxc == 0) ? | |
646 | (yy1 - yyc < 0) ? 90.0 : -90.0 : | |
647 | -atan2(double(yy1-yyc), double(xx1-xxc)) * RAD2DEG; | |
648 | radius2 = (xx2 - xxc == 0) ? | |
649 | (yy2 - yyc < 0) ? 90.0 : -90.0 : | |
650 | -atan2(double(yy2-yyc), double(xx2-xxc)) * RAD2DEG; | |
651 | } | |
652 | wxCoord alpha2 = wxCoord(radius2 - radius1); | |
653 | wxCoord alpha1 = wxCoord(wxConvertWXangleToMACangle(radius1)); | |
654 | if( (xx1 > xx2) || (yy1 > yy2) ) { | |
655 | alpha2 *= -1; | |
656 | } | |
657 | ||
658 | Rect r = { yyc - rad, xxc - rad, yyc + rad, xxc + rad }; | |
659 | ||
660 | if(m_brush.GetStyle() != wxTRANSPARENT) { | |
661 | MacInstallBrush(); | |
662 | PaintArc(&r, alpha1, alpha2); | |
663 | } | |
664 | if(m_pen.GetStyle() != wxTRANSPARENT) { | |
665 | MacInstallPen(); | |
666 | FrameArc(&r, alpha1, alpha2); | |
667 | } | |
519cb848 SC |
668 | } |
669 | ||
2f1ae414 SC |
670 | void wxDC::DoDrawEllipticArc( wxCoord x, wxCoord y, wxCoord w, wxCoord h, |
671 | double sa, double ea ) | |
519cb848 | 672 | { |
3dec57ad SC |
673 | wxCHECK_RET(Ok(), wxT("wxDC::DoDrawEllepticArc Invalid DC")); |
674 | ||
675 | Rect r; | |
676 | double angle = sa - ea; // Order important Mac in opposite direction to wx | |
677 | ||
678 | wxCoord xx = XLOG2DEV(x); | |
679 | wxCoord yy = YLOG2DEV(y); | |
680 | wxCoord ww = m_signX * XLOG2DEVREL(w); | |
681 | wxCoord hh = m_signY * YLOG2DEVREL(h); | |
682 | ||
683 | // handle -ve width and/or height | |
684 | if (ww < 0) { ww = -ww; xx = xx - ww; } | |
685 | if (hh < 0) { hh = -hh; yy = yy - hh; } | |
686 | ||
687 | sa = wxConvertWXangleToMACangle(sa); | |
688 | ||
689 | r.top = yy; | |
690 | r.left = xx; | |
691 | r.bottom = yy + hh; | |
692 | r.right = xx + ww; | |
693 | ||
694 | if(m_brush.GetStyle() != wxTRANSPARENT) { | |
695 | MacInstallBrush(); | |
696 | PaintArc(&r, (short)sa, (short)angle); | |
697 | } | |
698 | if(m_pen.GetStyle() != wxTRANSPARENT) { | |
699 | MacInstallPen(); | |
700 | FrameArc(&r, (short)sa, (short)angle); | |
701 | } | |
519cb848 SC |
702 | } |
703 | ||
2f1ae414 | 704 | void wxDC::DoDrawPoint( wxCoord x, wxCoord y ) |
519cb848 | 705 | { |
3dec57ad | 706 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
519cb848 | 707 | |
0eaa1d68 | 708 | wxMacPortSetter helper(this) ; |
519cb848 SC |
709 | |
710 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
711 | { | |
712 | MacInstallPen() ; | |
3dec57ad SC |
713 | wxCoord xx1 = XLOG2DEV(x); |
714 | wxCoord yy1 = YLOG2DEV(y); | |
519cb848 SC |
715 | |
716 | ::MoveTo(xx1,yy1); | |
717 | ::LineTo(xx1+1, yy1+1); | |
3dec57ad | 718 | } |
519cb848 SC |
719 | } |
720 | ||
2f1ae414 SC |
721 | void wxDC::DoDrawLines(int n, wxPoint points[], |
722 | wxCoord xoffset, wxCoord yoffset) | |
519cb848 | 723 | { |
3dec57ad | 724 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
0eaa1d68 | 725 | wxMacPortSetter helper(this) ; |
519cb848 SC |
726 | |
727 | if (m_pen.GetStyle() == wxTRANSPARENT) | |
728 | return; | |
729 | ||
03e11df5 | 730 | MacInstallPen() ; |
519cb848 | 731 | |
3dec57ad SC |
732 | wxCoord offset = ( (m_pen.GetWidth() == 0 ? 1 : |
733 | m_pen.GetWidth() ) * (wxCoord)m_scaleX - 1) / 2 ; | |
734 | ||
735 | wxCoord x1, x2 , y1 , y2 ; | |
519cb848 | 736 | x1 = XLOG2DEV(points[0].x + xoffset); |
03e11df5 | 737 | y1 = YLOG2DEV(points[0].y + yoffset); |
3dec57ad | 738 | ::MoveTo(x1 - offset, y1 - offset ); |
519cb848 SC |
739 | |
740 | for (int i = 0; i < n-1; i++) | |
741 | { | |
03e11df5 GD |
742 | x2 = XLOG2DEV(points[i+1].x + xoffset); |
743 | y2 = YLOG2DEV(points[i+1].y + yoffset); | |
3dec57ad | 744 | ::LineTo( x2 - offset, y2 - offset ); |
519cb848 SC |
745 | } |
746 | } | |
747 | ||
2f1ae414 SC |
748 | void wxDC::DoDrawPolygon(int n, wxPoint points[], |
749 | wxCoord xoffset, wxCoord yoffset, | |
750 | int fillStyle ) | |
519cb848 | 751 | { |
3dec57ad | 752 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
0eaa1d68 | 753 | wxMacPortSetter helper(this) ; |
519cb848 SC |
754 | |
755 | PolyHandle polygon = OpenPoly() ; | |
3dec57ad | 756 | wxCoord x1, x2 , y1 , y2 ; |
519cb848 | 757 | x1 = XLOG2DEV(points[0].x + xoffset); |
03e11df5 GD |
758 | y1 = YLOG2DEV(points[0].y + yoffset); |
759 | ::MoveTo(x1,y1); | |
519cb848 SC |
760 | |
761 | for (int i = 0; i < n-1; i++) | |
762 | { | |
03e11df5 GD |
763 | x2 = XLOG2DEV(points[i+1].x + xoffset); |
764 | y2 = YLOG2DEV(points[i+1].y + yoffset); | |
765 | ::LineTo(x2, y2); | |
519cb848 SC |
766 | } |
767 | ||
768 | ClosePoly() ; | |
769 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
770 | { | |
771 | MacInstallBrush() ; | |
772 | ::PaintPoly( polygon ) ; | |
3dec57ad | 773 | } |
519cb848 SC |
774 | |
775 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
776 | { | |
777 | MacInstallPen() ; | |
778 | ::FramePoly( polygon ) ; | |
3dec57ad | 779 | } |
519cb848 SC |
780 | KillPoly( polygon ) ; |
781 | } | |
782 | ||
3dec57ad | 783 | void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
519cb848 | 784 | { |
3dec57ad SC |
785 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
786 | wxMacPortSetter helper(this) ; | |
787 | ||
788 | wxCoord xx = XLOG2DEV(x); | |
789 | wxCoord yy = YLOG2DEV(y); | |
790 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
791 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
519cb848 SC |
792 | |
793 | // CMB: draw nothing if transformed w or h is 0 | |
794 | if (ww == 0 || hh == 0) | |
795 | return; | |
796 | ||
797 | // CMB: handle -ve width and/or height | |
798 | if (ww < 0) | |
799 | { | |
800 | ww = -ww; | |
801 | xx = xx - ww; | |
802 | } | |
803 | ||
804 | if (hh < 0) | |
805 | { | |
806 | hh = -hh; | |
807 | yy = yy - hh; | |
808 | } | |
809 | ||
810 | Rect rect = { yy , xx , yy + hh , xx + ww } ; | |
811 | ||
812 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
813 | { | |
814 | MacInstallBrush() ; | |
815 | ::PaintRect( &rect ) ; | |
3dec57ad | 816 | } |
519cb848 SC |
817 | |
818 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
819 | { | |
820 | MacInstallPen() ; | |
821 | ::FrameRect( &rect ) ; | |
3dec57ad | 822 | } |
519cb848 SC |
823 | } |
824 | ||
2f1ae414 SC |
825 | void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, |
826 | wxCoord width, wxCoord height, | |
827 | double radius) | |
519cb848 | 828 | { |
3dec57ad SC |
829 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
830 | wxMacPortSetter helper(this) ; | |
519cb848 | 831 | |
3dec57ad SC |
832 | if (radius < 0.0) |
833 | radius = - radius * ((width < height) ? width : height); | |
519cb848 | 834 | |
3dec57ad SC |
835 | wxCoord xx = XLOG2DEV(x); |
836 | wxCoord yy = YLOG2DEV(y); | |
837 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
838 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
519cb848 SC |
839 | |
840 | // CMB: draw nothing if transformed w or h is 0 | |
841 | if (ww == 0 || hh == 0) | |
842 | return; | |
843 | ||
844 | // CMB: handle -ve width and/or height | |
845 | if (ww < 0) | |
846 | { | |
847 | ww = -ww; | |
848 | xx = xx - ww; | |
849 | } | |
850 | ||
851 | if (hh < 0) | |
852 | { | |
853 | hh = -hh; | |
854 | yy = yy - hh; | |
855 | } | |
856 | ||
857 | Rect rect = { yy , xx , yy + hh , xx + ww } ; | |
858 | ||
859 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
860 | { | |
861 | MacInstallBrush() ; | |
03e11df5 | 862 | ::PaintRoundRect( &rect , int(radius * 2) , int(radius * 2) ) ; |
3dec57ad | 863 | } |
519cb848 SC |
864 | |
865 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
866 | { | |
867 | MacInstallPen() ; | |
03e11df5 | 868 | ::FrameRoundRect( &rect , int(radius * 2) , int(radius * 2) ) ; |
3dec57ad | 869 | } |
519cb848 SC |
870 | } |
871 | ||
2f1ae414 | 872 | void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height) |
519cb848 | 873 | { |
3dec57ad SC |
874 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
875 | wxMacPortSetter helper(this) ; | |
519cb848 | 876 | |
3dec57ad SC |
877 | wxCoord xx = XLOG2DEV(x); |
878 | wxCoord yy = YLOG2DEV(y); | |
879 | wxCoord ww = m_signX * XLOG2DEVREL(width); | |
880 | wxCoord hh = m_signY * YLOG2DEVREL(height); | |
519cb848 SC |
881 | |
882 | // CMB: draw nothing if transformed w or h is 0 | |
883 | if (ww == 0 || hh == 0) | |
884 | return; | |
885 | ||
886 | // CMB: handle -ve width and/or height | |
887 | if (ww < 0) | |
888 | { | |
889 | ww = -ww; | |
890 | xx = xx - ww; | |
891 | } | |
892 | ||
893 | if (hh < 0) | |
894 | { | |
895 | hh = -hh; | |
896 | yy = yy - hh; | |
897 | } | |
898 | ||
899 | Rect rect = { yy , xx , yy + hh , xx + ww } ; | |
900 | ||
901 | if (m_brush.GetStyle() != wxTRANSPARENT) | |
902 | { | |
903 | MacInstallBrush() ; | |
904 | ::PaintOval( &rect ) ; | |
3dec57ad | 905 | } |
519cb848 SC |
906 | |
907 | if (m_pen.GetStyle() != wxTRANSPARENT) | |
908 | { | |
909 | MacInstallPen() ; | |
910 | ::FrameOval( &rect ) ; | |
3dec57ad | 911 | } |
519cb848 SC |
912 | } |
913 | ||
519cb848 SC |
914 | |
915 | ||
916 | bool wxDC::CanDrawBitmap(void) const | |
917 | { | |
918 | return true ; | |
919 | } | |
920 | ||
921 | ||
2f1ae414 SC |
922 | bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, |
923 | wxDC *source, wxCoord xsrc, wxCoord ysrc, int logical_func , bool useMask ) | |
519cb848 | 924 | { |
3dec57ad SC |
925 | wxCHECK_MSG(Ok(), false, wxT("wxDC::DoBlit Illegal dc")); |
926 | wxCHECK_MSG(source->Ok(), false, wxT("wxDC::DoBlit Illegal source DC")); | |
927 | wxMacPortSetter helper(this) ; | |
519cb848 SC |
928 | |
929 | CGrafPtr sourcePort = (CGrafPtr) source->m_macPort ; | |
930 | PixMapHandle bmappixels = GetGWorldPixMap( sourcePort ) ; | |
03e11df5 GD |
931 | RGBColor white = { 0xFFFF, 0xFFFF,0xFFFF} ; |
932 | RGBColor black = { 0,0,0} ; | |
933 | RGBColor forecolor = m_textForegroundColour.GetPixel(); | |
934 | RGBColor backcolor = m_textBackgroundColour.GetPixel(); | |
935 | RGBForeColor( &forecolor ) ; | |
936 | RGBBackColor( &backcolor ) ; | |
519cb848 SC |
937 | |
938 | if ( LockPixels(bmappixels) ) | |
939 | { | |
940 | Rect srcrect , dstrect ; | |
941 | srcrect.top = source->YLOG2DEV(ysrc) ; | |
942 | srcrect.left = source->XLOG2DEV(xsrc) ; | |
943 | srcrect.right = source->XLOG2DEV(xsrc + width ) ; | |
944 | srcrect.bottom = source->YLOG2DEV(ysrc + height) ; | |
945 | dstrect.top = YLOG2DEV(ydest) ; | |
946 | dstrect.left = XLOG2DEV(xdest) ; | |
947 | dstrect.bottom = YLOG2DEV(ydest + height ) ; | |
948 | dstrect.right = XLOG2DEV(xdest + width ) ; | |
8208e181 SC |
949 | |
950 | short mode = (logical_func == wxCOPY ? srcCopy : | |
951 | // logical_func == wxCLEAR ? WHITENESS : | |
952 | // logical_func == wxSET ? BLACKNESS : | |
953 | logical_func == wxINVERT ? hilite : | |
954 | // logical_func == wxAND ? MERGECOPY : | |
955 | logical_func == wxOR ? srcOr : | |
956 | logical_func == wxSRC_INVERT ? notSrcCopy : | |
957 | logical_func == wxXOR ? srcXor : | |
958 | // logical_func == wxOR_REVERSE ? MERGEPAINT : | |
959 | // logical_func == wxAND_REVERSE ? SRCERASE : | |
2f1ae414 | 960 | // logical_func == wxSRC_OR ? srcOr : |
8208e181 SC |
961 | // logical_func == wxSRC_AND ? SRCAND : |
962 | srcCopy ); | |
963 | ||
964 | if ( useMask && source->m_macMask ) | |
965 | { | |
966 | wxASSERT( mode == srcCopy ) ; | |
967 | if ( LockPixels( GetGWorldPixMap( source->m_macMask ) ) ) | |
968 | { | |
3dec57ad SC |
969 | CopyMask( GetPortBitMapForCopyBits( sourcePort ) , |
970 | GetPortBitMapForCopyBits( source->m_macMask ) , | |
971 | GetPortBitMapForCopyBits( m_macPort ) , | |
972 | &srcrect, &srcrect , &dstrect ) ; | |
8208e181 SC |
973 | UnlockPixels( GetGWorldPixMap( source->m_macMask ) ) ; |
974 | } | |
975 | } | |
976 | else | |
977 | { | |
3dec57ad SC |
978 | CopyBits( GetPortBitMapForCopyBits( sourcePort ) , |
979 | GetPortBitMapForCopyBits( m_macPort ) , | |
8208e181 SC |
980 | &srcrect, &dstrect, mode, NULL ) ; |
981 | } | |
519cb848 SC |
982 | UnlockPixels( bmappixels ) ; |
983 | } | |
984 | ||
985 | m_macPenInstalled = false ; | |
986 | m_macBrushInstalled = false ; | |
987 | m_macFontInstalled = false ; | |
988 | ||
989 | return TRUE; | |
990 | } | |
991 | ||
2f1ae414 | 992 | void wxDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, |
3dec57ad | 993 | double angle) |
2f1ae414 | 994 | { |
3dec57ad SC |
995 | wxCHECK_RET( Ok(), wxT("wxDC::DoDrawRotatedText Invalid window dc") ); |
996 | ||
997 | if (angle == 0.0) | |
998 | { | |
999 | DrawText(text, x, y); | |
1000 | return; | |
1001 | } | |
1002 | ||
1003 | MacInstallFont(); | |
1004 | ||
1005 | // the size of the text | |
1006 | wxCoord w, h; | |
1007 | GetTextExtent(text, &w, &h); | |
1008 | ||
1009 | // draw the string normally | |
1010 | wxBitmap src(w, h); | |
1011 | wxMemoryDC dc; | |
1012 | dc.SelectObject(src); | |
1013 | dc.SetFont(GetFont()); | |
1014 | dc.SetBackground(*wxWHITE_BRUSH); | |
1015 | dc.SetBrush(*wxBLACK_BRUSH); | |
1016 | dc.Clear(); | |
1017 | dc.DrawText(text, 0, 0); | |
1018 | dc.SetFont(wxNullFont); | |
1019 | dc.SelectObject(wxNullBitmap); | |
1020 | ||
1021 | wxMacPortSetter helper(this) ; | |
1022 | ||
1023 | // Calculate the size of the rotated bounding box. | |
1024 | double rad = DegToRad(angle); | |
1025 | double dx = cos(rad); | |
1026 | double dy = sin(rad); | |
1027 | ||
1028 | // the rectngle vertices are counted clockwise with the first one being at | |
1029 | // (0, 0) (or, rather, at (x, y)) | |
1030 | double x2 = w * dx; | |
1031 | double y2 = -w * dy; // y axis points to the bottom, hence minus | |
1032 | double x4 = h * dy; | |
1033 | double y4 = h * dx; | |
1034 | double x3 = x4 + x2; | |
1035 | double y3 = y4 + y2; | |
1036 | ||
1037 | // calc max and min | |
1038 | wxCoord maxX = (wxCoord)(dmax(x2, dmax(x3, x4)) + 0.5); | |
1039 | wxCoord maxY = (wxCoord)(dmax(y2, dmax(y3, y4)) + 0.5); | |
1040 | wxCoord minX = (wxCoord)(dmin(x2, dmin(x3, x4)) - 0.5); | |
1041 | wxCoord minY = (wxCoord)(dmin(y2, dmin(y3, y4)) - 0.5); | |
1042 | ||
1043 | // prepare to blit-with-rotate the bitmap to the DC | |
1044 | wxImage image(src); | |
1045 | ||
1046 | RGBColor colText = m_textForegroundColour.GetPixel(); | |
1047 | RGBColor colBack = m_textBackgroundColour.GetPixel(); | |
1048 | ||
1049 | unsigned char *data = image.GetData(); | |
1050 | ||
1051 | wxCoord dstX, dstY; | |
1052 | double r, angleOrig; | |
1053 | bool textPixel; | |
1054 | ||
1055 | // paint pixel by pixel | |
1056 | for ( wxCoord srcX = 0; srcX < w; srcX++ ) | |
1057 | { | |
1058 | for ( wxCoord srcY = 0; srcY < h; srcY++ ) | |
1059 | { | |
1060 | // transform source coords to dest coords | |
1061 | r = sqrt( (double)(srcX * srcX + srcY * srcY) ); | |
1062 | angleOrig = atan2((double)srcY, (double)srcX) - rad; | |
1063 | dstX = (wxCoord)(r * cos(angleOrig) + 0.5); | |
1064 | dstY = (wxCoord)(r * sin(angleOrig) + 0.5); | |
1065 | ||
1066 | // black pixel? | |
1067 | textPixel = data[(srcY*w + srcX)*3] == 0; | |
1068 | if ( textPixel || (m_backgroundMode == wxSOLID) ) | |
1069 | { | |
1070 | SetCPixel(XLOG2DEV(x + dstX), YLOG2DEV(y + dstY), | |
1071 | textPixel ? &colText : &colBack); | |
1072 | } | |
1073 | } | |
1074 | } | |
1075 | ||
1076 | // it would be better to draw with non underlined font and draw the line | |
1077 | // manually here (it would be more straight...) | |
1078 | #if 0 | |
1079 | if ( m_font.GetUnderlined() ) | |
1080 | { | |
1081 | ::MoveTo(XLOG2DEV(x + x4), YLOG2DEV(y + y4 + font->descent)); | |
1082 | ::LineTo(XLOG2DEV(x + x3), YLOG2DEV(y + y3 + font->descent)); | |
1083 | } | |
1084 | #endif // 0 | |
1085 | ||
1086 | // update the bounding box | |
1087 | CalcBoundingBox(x + minX, y + minY); | |
1088 | CalcBoundingBox(x + maxX, y + maxY); | |
2f1ae414 SC |
1089 | } |
1090 | void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y) | |
519cb848 | 1091 | { |
3dec57ad SC |
1092 | wxCHECK_RET(Ok(), wxT("wxDC::DoDrawText Invalid DC")); |
1093 | wxMacPortSetter helper(this) ; | |
519cb848 SC |
1094 | |
1095 | long xx = XLOG2DEV(x); | |
1096 | long yy = YLOG2DEV(y); | |
1097 | ||
1098 | // if (m_pen.GetStyle() != wxTRANSPARENT) | |
1099 | { | |
1100 | MacInstallFont() ; | |
1101 | /* | |
1102 | Rect clip = { -32000 , -32000 , 32000 , 32000 } ; | |
1103 | ||
1104 | ::ClipRect( &clip ) ; | |
1105 | */ | |
1106 | ||
1107 | FontInfo fi ; | |
1108 | ::GetFontInfo( &fi ) ; | |
1109 | ||
1110 | yy += fi.ascent ; | |
1111 | ::MoveTo( xx , yy ); | |
1112 | if ( m_backgroundMode == wxTRANSPARENT ) | |
1113 | { | |
1114 | ::TextMode( srcOr) ; | |
1115 | } | |
1116 | else | |
1117 | { | |
1118 | ::TextMode( srcCopy ) ; | |
1119 | } | |
1120 | ||
1121 | const char *text = NULL ; | |
1122 | int length = 0 ; | |
1123 | wxString macText ; | |
1124 | ||
1125 | if ( wxApp::s_macDefaultEncodingIsPC ) | |
1126 | { | |
2f1ae414 | 1127 | macText = wxMacMakeMacStringFromPC( strtext ) ; |
519cb848 SC |
1128 | text = macText ; |
1129 | length = macText.Length() ; | |
1130 | } | |
1131 | else | |
1132 | { | |
2f1ae414 SC |
1133 | text = strtext ; |
1134 | length = strtext.Length() ; | |
519cb848 SC |
1135 | } |
1136 | ||
1137 | int laststop = 0 ; | |
1138 | int i = 0 ; | |
1139 | int line = 0 ; | |
1140 | ||
1141 | while( i < length ) | |
1142 | { | |
1143 | if( text[i] == 13 || text[i] == 10) | |
1144 | { | |
1145 | ::DrawText( text , laststop , i - laststop ) ; | |
1146 | line++ ; | |
1147 | ::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) ); | |
1148 | laststop = i+1 ; | |
1149 | } | |
1150 | i++ ; | |
1151 | } | |
1152 | ||
1153 | ::DrawText( text , laststop , i - laststop ) ; | |
1154 | ::TextMode( srcOr ) ; | |
1155 | } | |
1156 | } | |
1157 | ||
3dec57ad | 1158 | bool wxDC::CanGetTextExtent() const |
519cb848 | 1159 | { |
3dec57ad | 1160 | wxCHECK_MSG(Ok(), false, wxT("Invalid DC")); |
519cb848 SC |
1161 | |
1162 | return true ; | |
1163 | } | |
1164 | ||
2f1ae414 SC |
1165 | void wxDC::DoGetTextExtent( const wxString &string, wxCoord *width, wxCoord *height, |
1166 | wxCoord *descent, wxCoord *externalLeading , | |
1167 | wxFont *theFont ) const | |
519cb848 | 1168 | { |
3dec57ad | 1169 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
0eaa1d68 | 1170 | wxMacPortSetter helper(this) ; |
519cb848 SC |
1171 | |
1172 | wxFont formerFont = m_font ; | |
1173 | ||
1174 | if ( theFont ) | |
1175 | { | |
1176 | wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; | |
1177 | ||
1178 | if ( font ) | |
1179 | { | |
519cb848 | 1180 | ::TextFont( font->m_macFontNum ) ; |
2f1ae414 | 1181 | ::TextSize( YLOG2DEVREL( font->m_macFontSize) ) ; |
519cb848 SC |
1182 | ::TextFace( font->m_macFontStyle ) ; |
1183 | } | |
1184 | } | |
1185 | else | |
1186 | { | |
1187 | MacInstallFont() ; | |
1188 | } | |
1189 | ||
1190 | FontInfo fi ; | |
1191 | ::GetFontInfo( &fi ) ; | |
1192 | ||
2f1ae414 SC |
1193 | if ( height ) |
1194 | *height = YDEV2LOGREL( fi.descent + fi.ascent ) ; | |
1195 | if ( descent ) | |
1196 | *descent =YDEV2LOGREL( fi.descent ); | |
1197 | if ( externalLeading ) | |
1198 | *externalLeading = YDEV2LOGREL( fi.leading ) ; | |
519cb848 SC |
1199 | |
1200 | const char *text = NULL ; | |
1201 | int length = 0 ; | |
1202 | wxString macText ; | |
1203 | if ( wxApp::s_macDefaultEncodingIsPC ) | |
1204 | { | |
1205 | macText = wxMacMakeMacStringFromPC( string ) ; | |
1206 | text = macText ; | |
1207 | length = macText.Length() ; | |
1208 | } | |
1209 | else | |
1210 | { | |
1211 | text = string ; | |
1212 | length = string.Length() ; | |
1213 | } | |
1214 | ||
1215 | int laststop = 0 ; | |
1216 | int i = 0 ; | |
1217 | int curwidth = 0 ; | |
2f1ae414 | 1218 | if ( width ) |
519cb848 | 1219 | { |
2f1ae414 SC |
1220 | *width = 0 ; |
1221 | ||
1222 | while( i < length ) | |
519cb848 | 1223 | { |
2f1ae414 SC |
1224 | if( text[i] == 13 || text[i] == 10) |
1225 | { | |
1226 | if ( height ) | |
1227 | *height += YDEV2LOGREL( fi.descent + fi.ascent + fi.leading ) ; | |
1228 | curwidth = ::TextWidth( text , laststop , i - laststop ) ; | |
1229 | if ( curwidth > *width ) | |
1230 | *width = XDEV2LOGREL( curwidth ) ; | |
1231 | laststop = i+1 ; | |
1232 | } | |
1233 | i++ ; | |
519cb848 | 1234 | } |
2f1ae414 SC |
1235 | |
1236 | curwidth = ::TextWidth( text , laststop , i - laststop ) ; | |
1237 | if ( curwidth > *width ) | |
1238 | *width = XDEV2LOGREL( curwidth ) ; | |
519cb848 | 1239 | } |
519cb848 SC |
1240 | |
1241 | if ( theFont ) | |
1242 | { | |
1243 | m_macFontInstalled = false ; | |
1244 | } | |
1245 | } | |
1246 | ||
ee41971c | 1247 | wxCoord wxDC::GetCharWidth(void) const |
519cb848 | 1248 | { |
3dec57ad | 1249 | wxCHECK_MSG(Ok(), 1, wxT("Invalid DC")); |
519cb848 | 1250 | |
0eaa1d68 | 1251 | wxMacPortSetter helper(this) ; |
519cb848 SC |
1252 | |
1253 | MacInstallFont() ; | |
1254 | ||
1255 | FontInfo fi ; | |
1256 | ::GetFontInfo( &fi ) ; | |
1257 | ||
2f1ae414 | 1258 | return YDEV2LOGREL((fi.descent + fi.ascent) / 2) ; |
519cb848 SC |
1259 | } |
1260 | ||
ee41971c | 1261 | wxCoord wxDC::GetCharHeight(void) const |
519cb848 | 1262 | { |
3dec57ad | 1263 | wxCHECK_MSG(Ok(), 1, wxT("Invalid DC")); |
519cb848 | 1264 | |
3dec57ad | 1265 | wxMacPortSetter helper(this) ; |
519cb848 SC |
1266 | |
1267 | MacInstallFont() ; | |
1268 | ||
1269 | FontInfo fi ; | |
1270 | ::GetFontInfo( &fi ) ; | |
1271 | ||
2f1ae414 | 1272 | return YDEV2LOGREL( fi.descent + fi.ascent ); |
519cb848 SC |
1273 | } |
1274 | ||
1275 | void wxDC::Clear(void) | |
1276 | { | |
3dec57ad SC |
1277 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
1278 | wxMacPortSetter helper(this) ; | |
519cb848 SC |
1279 | Rect rect = { -32767 , -32767 , 32767 , 32767 } ; |
1280 | ||
1281 | if (m_backgroundBrush.GetStyle() != wxTRANSPARENT) | |
1282 | { | |
1283 | MacInstallBrush() ; | |
1284 | ::EraseRect( &rect ) ; | |
3dec57ad | 1285 | } |
519cb848 SC |
1286 | } |
1287 | ||
1288 | void wxDC::MacInstallFont() const | |
1289 | { | |
3dec57ad | 1290 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
0eaa1d68 SC |
1291 | // if ( m_macFontInstalled ) |
1292 | // return ; | |
2f1ae414 SC |
1293 | Pattern blackColor ; |
1294 | ||
519cb848 SC |
1295 | wxFontRefData * font = (wxFontRefData*) m_font.GetRefData() ; |
1296 | ||
1297 | if ( font ) | |
1298 | { | |
1299 | ::TextFont( font->m_macFontNum ) ; | |
03e11df5 | 1300 | ::TextSize( short(m_scaleY * font->m_macFontSize) ) ; |
519cb848 SC |
1301 | ::TextFace( font->m_macFontStyle ) ; |
1302 | ||
1303 | m_macFontInstalled = true ; | |
1304 | m_macBrushInstalled = false ; | |
1305 | m_macPenInstalled = false ; | |
03e11df5 GD |
1306 | |
1307 | RGBColor forecolor = m_textForegroundColour.GetPixel(); | |
1308 | RGBColor backcolor = m_textBackgroundColour.GetPixel(); | |
1309 | ::RGBForeColor( &forecolor ); | |
1310 | ::RGBBackColor( &backcolor ); | |
519cb848 SC |
1311 | } |
1312 | else | |
1313 | { | |
1314 | short fontnum ; | |
1315 | ||
1316 | GetFNum( "\pGeneva" , &fontnum ) ; | |
1317 | ::TextFont( fontnum ) ; | |
03e11df5 | 1318 | ::TextSize( short(m_scaleY * 10) ) ; |
519cb848 SC |
1319 | ::TextFace( 0 ) ; |
1320 | ||
1321 | // todo reset after spacing changes - or store the current spacing somewhere | |
1322 | ||
1323 | m_macFontInstalled = true ; | |
1324 | m_macBrushInstalled = false ; | |
1325 | m_macPenInstalled = false ; | |
519cb848 | 1326 | |
03e11df5 GD |
1327 | RGBColor forecolor = m_textForegroundColour.GetPixel(); |
1328 | RGBColor backcolor = m_textBackgroundColour.GetPixel(); | |
1329 | ::RGBForeColor( &forecolor ); | |
1330 | ::RGBBackColor( &backcolor ); | |
1331 | } | |
519cb848 SC |
1332 | |
1333 | short mode = patCopy ; | |
1334 | ||
1335 | // todo : | |
1336 | ||
1337 | switch( m_logicalFunction ) | |
1338 | { | |
1339 | case wxCOPY: // src | |
1340 | mode = patCopy ; | |
1341 | break ; | |
1342 | case wxINVERT: // NOT dst | |
2f1ae414 | 1343 | ::PenPat(GetQDGlobalsBlack(&blackColor)); |
519cb848 SC |
1344 | mode = patXor ; |
1345 | break ; | |
1346 | case wxXOR: // src XOR dst | |
1347 | mode = patXor ; | |
1348 | break ; | |
1349 | case wxOR_REVERSE: // src OR (NOT dst) | |
1350 | mode = notPatOr ; | |
1351 | break ; | |
1352 | case wxSRC_INVERT: // (NOT src) | |
1353 | mode = notPatCopy ; | |
1354 | break ; | |
1355 | ||
1356 | // unsupported TODO | |
1357 | ||
1358 | case wxCLEAR: // 0 | |
1359 | case wxAND_REVERSE:// src AND (NOT dst) | |
1360 | case wxAND: // src AND dst | |
1361 | case wxAND_INVERT: // (NOT src) AND dst | |
1362 | case wxNO_OP: // dst | |
1363 | case wxNOR: // (NOT src) AND (NOT dst) | |
1364 | case wxEQUIV: // (NOT src) XOR dst | |
1365 | case wxOR_INVERT: // (NOT src) OR dst | |
1366 | case wxNAND: // (NOT src) OR (NOT dst) | |
1367 | case wxOR: // src OR dst | |
1368 | case wxSET: // 1 | |
2f1ae414 SC |
1369 | // case wxSRC_OR: // source _bitmap_ OR destination |
1370 | // case wxSRC_AND: // source _bitmap_ AND destination | |
519cb848 SC |
1371 | break ; |
1372 | } | |
1373 | ::PenMode( mode ) ; | |
1374 | } | |
1375 | ||
1376 | static void wxMacGetHatchPattern(int hatchStyle, Pattern *pattern) | |
1377 | { | |
1378 | int thePatListID = sysPatListID; | |
1379 | int theIndex; | |
1380 | switch(hatchStyle) | |
1381 | { | |
1382 | case wxBDIAGONAL_HATCH: | |
1383 | theIndex = 34; // WCH: this is not good | |
1384 | break; | |
1385 | case wxFDIAGONAL_HATCH: | |
1386 | theIndex = 26; | |
1387 | break; | |
1388 | case wxCROSS_HATCH: | |
1389 | theIndex = 5; | |
1390 | break; | |
1391 | case wxHORIZONTAL_HATCH: | |
1392 | theIndex = 25; | |
1393 | break; | |
1394 | case wxVERTICAL_HATCH: | |
1395 | theIndex = 6; | |
1396 | break; | |
1397 | case wxCROSSDIAG_HATCH: | |
1398 | theIndex = 4; // WCH: this is not good | |
1399 | break; | |
1400 | default: | |
1401 | theIndex = 1; // solid pattern | |
1402 | break; | |
1403 | } | |
1404 | GetIndPattern( pattern, thePatListID, theIndex); | |
1405 | } | |
1406 | ||
1407 | void wxDC::MacInstallPen() const | |
1408 | { | |
3dec57ad | 1409 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
519cb848 | 1410 | |
2f1ae414 SC |
1411 | Pattern blackColor; |
1412 | ||
0eaa1d68 SC |
1413 | // if ( m_macPenInstalled ) |
1414 | // return ; | |
519cb848 | 1415 | |
03e11df5 GD |
1416 | RGBColor forecolor = m_pen.GetColour().GetPixel(); |
1417 | RGBColor backcolor = m_backgroundBrush.GetColour().GetPixel(); | |
1418 | ::RGBForeColor( &forecolor ); | |
1419 | ::RGBBackColor( &backcolor ); | |
519cb848 SC |
1420 | |
1421 | ::PenNormal() ; | |
3dec57ad | 1422 | int penWidth = m_pen.GetWidth() * (int) m_scaleX ; |
0b014ec7 SC |
1423 | |
1424 | // null means only one pixel, at whatever resolution | |
1425 | if ( penWidth == 0 ) | |
1426 | penWidth = 1 ; | |
519cb848 SC |
1427 | ::PenSize(penWidth, penWidth); |
1428 | ||
1429 | int penStyle = m_pen.GetStyle(); | |
1430 | ||
1431 | if (penStyle == wxSOLID) | |
03e11df5 | 1432 | { |
2f1ae414 | 1433 | ::PenPat(GetQDGlobalsBlack(&blackColor)); |
03e11df5 | 1434 | } |
519cb848 SC |
1435 | else if (IS_HATCH(penStyle)) |
1436 | { | |
1437 | Pattern pat ; | |
1438 | wxMacGetHatchPattern(penStyle, &pat); | |
1439 | ::PenPat(&pat); | |
1440 | } | |
1441 | else | |
1442 | { | |
2f1ae414 | 1443 | ::PenPat(GetQDGlobalsBlack(&blackColor)); |
519cb848 SC |
1444 | } |
1445 | ||
1446 | short mode = patCopy ; | |
1447 | ||
1448 | // todo : | |
1449 | ||
1450 | switch( m_logicalFunction ) | |
1451 | { | |
1452 | case wxCOPY: // src | |
1453 | mode = patCopy ; | |
1454 | break ; | |
1455 | case wxINVERT: // NOT dst | |
2f1ae414 | 1456 | ::PenPat(GetQDGlobalsBlack(&blackColor)); |
519cb848 SC |
1457 | mode = patXor ; |
1458 | break ; | |
1459 | case wxXOR: // src XOR dst | |
1460 | mode = patXor ; | |
1461 | break ; | |
1462 | case wxOR_REVERSE: // src OR (NOT dst) | |
1463 | mode = notPatOr ; | |
1464 | break ; | |
1465 | case wxSRC_INVERT: // (NOT src) | |
1466 | mode = notPatCopy ; | |
1467 | break ; | |
1468 | ||
1469 | // unsupported TODO | |
1470 | ||
1471 | case wxCLEAR: // 0 | |
1472 | case wxAND_REVERSE:// src AND (NOT dst) | |
1473 | case wxAND: // src AND dst | |
1474 | case wxAND_INVERT: // (NOT src) AND dst | |
1475 | case wxNO_OP: // dst | |
1476 | case wxNOR: // (NOT src) AND (NOT dst) | |
1477 | case wxEQUIV: // (NOT src) XOR dst | |
1478 | case wxOR_INVERT: // (NOT src) OR dst | |
1479 | case wxNAND: // (NOT src) OR (NOT dst) | |
1480 | case wxOR: // src OR dst | |
1481 | case wxSET: // 1 | |
2f1ae414 SC |
1482 | // case wxSRC_OR: // source _bitmap_ OR destination |
1483 | // case wxSRC_AND: // source _bitmap_ AND destination | |
519cb848 SC |
1484 | break ; |
1485 | } | |
1486 | ::PenMode( mode ) ; | |
1487 | m_macPenInstalled = true ; | |
1488 | m_macBrushInstalled = false ; | |
1489 | m_macFontInstalled = false ; | |
1490 | } | |
1491 | ||
1492 | void wxDC::MacInstallBrush() const | |
1493 | { | |
3dec57ad | 1494 | wxCHECK_RET(Ok(), wxT("Invalid DC")); |
0eaa1d68 | 1495 | |
2f1ae414 | 1496 | Pattern blackColor, whiteColor ; |
0eaa1d68 SC |
1497 | // if ( m_macBrushInstalled ) |
1498 | // return ; | |
519cb848 SC |
1499 | |
1500 | // foreground | |
1501 | ||
03e11df5 GD |
1502 | RGBColor forecolor = m_brush.GetColour().GetPixel(); |
1503 | RGBColor backcolor = m_backgroundBrush.GetColour().GetPixel(); | |
1504 | ::RGBForeColor( &forecolor ); | |
1505 | ::RGBBackColor( &backcolor ); | |
519cb848 SC |
1506 | |
1507 | int brushStyle = m_brush.GetStyle(); | |
1508 | if (brushStyle == wxSOLID) | |
2f1ae414 | 1509 | ::PenPat(GetQDGlobalsBlack(&blackColor)); |
519cb848 SC |
1510 | else if (IS_HATCH(brushStyle)) |
1511 | { | |
1512 | Pattern pat ; | |
1513 | wxMacGetHatchPattern(brushStyle, &pat); | |
1514 | ::PenPat(&pat); | |
1515 | } | |
1516 | else | |
1517 | { | |
2f1ae414 | 1518 | ::PenPat(GetQDGlobalsBlack(&blackColor)); |
519cb848 SC |
1519 | } |
1520 | ||
1521 | ||
1522 | // background | |
1523 | ||
1524 | brushStyle = m_backgroundBrush.GetStyle(); | |
1525 | if (brushStyle == wxSOLID) | |
2f1ae414 | 1526 | ::BackPat(GetQDGlobalsWhite(&whiteColor)); |
519cb848 SC |
1527 | else if (IS_HATCH(brushStyle)) |
1528 | { | |
1529 | Pattern pat ; | |
1530 | wxMacGetHatchPattern(brushStyle, &pat); | |
1531 | ::BackPat(&pat); | |
1532 | } | |
1533 | else | |
1534 | { | |
2f1ae414 | 1535 | ::BackPat(GetQDGlobalsWhite(&whiteColor)); |
519cb848 SC |
1536 | } |
1537 | ||
1538 | short mode = patCopy ; | |
1539 | ||
1540 | // todo : | |
1541 | ||
1542 | switch( m_logicalFunction ) | |
1543 | { | |
1544 | case wxCOPY: // src | |
1545 | mode = patCopy ; | |
1546 | break ; | |
1547 | case wxINVERT: // NOT dst | |
2f1ae414 | 1548 | ::PenPat(GetQDGlobalsBlack(&blackColor)); |
519cb848 SC |
1549 | mode = patXor ; |
1550 | break ; | |
1551 | case wxXOR: // src XOR dst | |
1552 | mode = patXor ; | |
1553 | break ; | |
1554 | case wxOR_REVERSE: // src OR (NOT dst) | |
1555 | mode = notPatOr ; | |
1556 | break ; | |
1557 | case wxSRC_INVERT: // (NOT src) | |
1558 | mode = notPatCopy ; | |
1559 | break ; | |
1560 | ||
1561 | // unsupported TODO | |
1562 | ||
1563 | case wxCLEAR: // 0 | |
1564 | case wxAND_REVERSE:// src AND (NOT dst) | |
1565 | case wxAND: // src AND dst | |
1566 | case wxAND_INVERT: // (NOT src) AND dst | |
1567 | case wxNO_OP: // dst | |
1568 | case wxNOR: // (NOT src) AND (NOT dst) | |
1569 | case wxEQUIV: // (NOT src) XOR dst | |
1570 | case wxOR_INVERT: // (NOT src) OR dst | |
1571 | case wxNAND: // (NOT src) OR (NOT dst) | |
1572 | case wxOR: // src OR dst | |
1573 | case wxSET: // 1 | |
2f1ae414 SC |
1574 | // case wxSRC_OR: // source _bitmap_ OR destination |
1575 | // case wxSRC_AND: // source _bitmap_ AND destination | |
519cb848 SC |
1576 | break ; |
1577 | } | |
1578 | ::PenMode( mode ) ; | |
1579 | m_macBrushInstalled = true ; | |
1580 | m_macPenInstalled = false ; | |
1581 | m_macFontInstalled = false ; | |
1582 | } | |
1583 | ||
2f1ae414 SC |
1584 | // --------------------------------------------------------------------------- |
1585 | // coordinates transformations | |
1586 | // --------------------------------------------------------------------------- | |
519cb848 | 1587 | |
2f1ae414 SC |
1588 | |
1589 | wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const | |
1590 | { | |
1591 | return ((wxDC *)this)->XDEV2LOG(x); | |
1592 | } | |
1593 | ||
1594 | wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const | |
1595 | { | |
1596 | return ((wxDC *)this)->YDEV2LOG(y); | |
1597 | } | |
1598 | ||
1599 | wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const | |
1600 | { | |
1601 | return ((wxDC *)this)->XDEV2LOGREL(x); | |
1602 | } | |
1603 | ||
1604 | wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const | |
1605 | { | |
1606 | return ((wxDC *)this)->YDEV2LOGREL(y); | |
1607 | } | |
1608 | ||
1609 | wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const | |
1610 | { | |
1611 | return ((wxDC *)this)->XLOG2DEV(x); | |
1612 | } | |
1613 | ||
1614 | wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const | |
1615 | { | |
1616 | return ((wxDC *)this)->YLOG2DEV(y); | |
1617 | } | |
1618 | ||
1619 | wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const | |
1620 | { | |
1621 | return ((wxDC *)this)->XLOG2DEVREL(x); | |
1622 | } | |
1623 | ||
1624 | wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const | |
1625 | { | |
1626 | return ((wxDC *)this)->YLOG2DEVREL(y); | |
1627 | } |