1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2001 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ===========================================================================
13 // ===========================================================================
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
20 #pragma implementation "dc.h"
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
32 #include "wx/dcmemory.h"
35 #include "wx/fontutil.h"
36 #include "wx/fontmap.h"
37 #include "wx/mgl/private.h"
46 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
50 const double mm2inches
= 0.0393700787402;
51 const double inches2mm
= 25.4;
52 const double mm2twips
= 56.6929133859;
53 const double twips2mm
= 0.0176388888889;
54 const double mm2pt
= 2.83464566929;
55 const double pt2mm
= 0.352777777778;
56 const double RAD2DEG
= 180.0 / M_PI
;
59 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
63 const ushort STIPPLE_wxDOT
= 0x5555/* - - - - - - - -*/;
64 const ushort STIPPLE_wxLONG_DASH
= 0xF0F0/* ---- ----*/;
65 const ushort STIPPLE_wxSHORT_DASH
= 0xCCCC/*-- -- -- -- */;
66 const ushort STIPPLE_wxDOT_DASH
= 0x3939/* --- - --- -*/;
67 const ushort STIPPLE_wxSOLID
= 0xFFFF/*----------------*/;
69 #define PATTERN_ROW(b7,b6,b5,b4,b3,b2,b1,b0) \
70 ((b7 << 7) | (b6 << 6) | (b5 << 5) | (b4 << 4) | \
71 (b3 << 3) | (b2 << 2) | (b1 << 1) | b0)
73 static pattern_t PATTERN_wxFDIAGONAL_HATCH
= {{
74 PATTERN_ROW(1,0,0,0,0,0,0,0),
75 PATTERN_ROW(0,1,0,0,0,0,0,0),
76 PATTERN_ROW(0,0,1,0,0,0,0,0),
77 PATTERN_ROW(0,0,0,1,0,0,0,0),
78 PATTERN_ROW(0,0,0,0,1,0,0,0),
79 PATTERN_ROW(0,0,0,0,0,1,0,0),
80 PATTERN_ROW(0,0,0,0,0,0,1,0),
81 PATTERN_ROW(0,0,0,0,0,0,0,1),
84 static pattern_t PATTERN_wxCROSSDIAG_HATCH
= {{
85 PATTERN_ROW(1,0,0,0,0,0,0,1),
86 PATTERN_ROW(0,1,0,0,0,0,1,0),
87 PATTERN_ROW(0,0,1,0,0,1,0,0),
88 PATTERN_ROW(0,0,0,1,1,0,0,0),
89 PATTERN_ROW(0,0,0,1,1,0,0,0),
90 PATTERN_ROW(0,0,1,0,0,1,0,0),
91 PATTERN_ROW(0,1,0,0,0,0,1,0),
92 PATTERN_ROW(1,0,0,0,0,0,0,1),
95 static pattern_t PATTERN_wxBDIAGONAL_HATCH
= {{
96 PATTERN_ROW(0,0,0,0,0,0,0,1),
97 PATTERN_ROW(0,0,0,0,0,0,1,0),
98 PATTERN_ROW(0,0,0,0,0,1,0,0),
99 PATTERN_ROW(0,0,0,0,1,0,0,0),
100 PATTERN_ROW(0,0,0,1,0,0,0,0),
101 PATTERN_ROW(0,0,1,0,0,0,0,0),
102 PATTERN_ROW(0,1,0,0,0,0,0,0),
103 PATTERN_ROW(1,0,0,0,0,0,0,0),
106 static pattern_t PATTERN_wxCROSS_HATCH
= {{
107 PATTERN_ROW(0,0,0,1,0,0,0,0),
108 PATTERN_ROW(0,0,0,1,0,0,0,0),
109 PATTERN_ROW(0,0,0,1,0,0,0,0),
110 PATTERN_ROW(1,1,1,1,1,1,1,1),
111 PATTERN_ROW(0,0,0,1,0,0,0,0),
112 PATTERN_ROW(0,0,0,1,0,0,0,0),
113 PATTERN_ROW(0,0,0,1,0,0,0,0),
114 PATTERN_ROW(0,0,0,1,0,0,0,0),
117 static pattern_t PATTERN_wxHORIZONTAL_HATCH
= {{
118 PATTERN_ROW(0,0,0,0,0,0,0,0),
119 PATTERN_ROW(0,0,0,0,0,0,0,0),
120 PATTERN_ROW(0,0,0,0,0,0,0,0),
121 PATTERN_ROW(1,1,1,1,1,1,1,1),
122 PATTERN_ROW(0,0,0,0,0,0,0,0),
123 PATTERN_ROW(0,0,0,0,0,0,0,0),
124 PATTERN_ROW(0,0,0,0,0,0,0,0),
125 PATTERN_ROW(0,0,0,0,0,0,0,0),
128 static pattern_t PATTERN_wxVERTICAL_HATCH
= {{
129 PATTERN_ROW(0,0,0,1,0,0,0,0),
130 PATTERN_ROW(0,0,0,1,0,0,0,0),
131 PATTERN_ROW(0,0,0,1,0,0,0,0),
132 PATTERN_ROW(0,0,0,1,0,0,0,0),
133 PATTERN_ROW(0,0,0,1,0,0,0,0),
134 PATTERN_ROW(0,0,0,1,0,0,0,0),
135 PATTERN_ROW(0,0,0,1,0,0,0,0),
136 PATTERN_ROW(0,0,0,1,0,0,0,0),
141 //-----------------------------------------------------------------------------
143 //-----------------------------------------------------------------------------
145 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxDCBase
)
147 // Default constructor
153 m_ok
= FALSE
; // must call SetMGLDevCtx() before using it
155 m_mm_to_pix_x
= (double)wxGetDisplaySize().GetWidth() /
156 (double)wxGetDisplaySizeMM().GetWidth();
157 m_mm_to_pix_y
= (double)wxGetDisplaySize().GetHeight() /
158 (double)wxGetDisplaySizeMM().GetHeight();
160 m_pen
= *wxBLACK_PEN
;
161 m_font
= *wxNORMAL_FONT
;
162 m_brush
= *wxWHITE_BRUSH
;
163 m_penOfsX
= m_penOfsY
= 0;
165 m_penSelected
= m_brushSelected
= FALSE
;
166 m_downloadedPatterns
[0] = m_downloadedPatterns
[1] = FALSE
;
178 void wxDC::SetMGLDC(MGLDevCtx
*mgldc
, bool OwnsMGLDC
)
180 if ( m_OwnsMGLDC
&& m_MGLDC
)
183 m_OwnsMGLDC
= OwnsMGLDC
;
186 if ( !m_globalClippingRegion
.IsNull() )
187 SetClippingRegion(m_globalClippingRegion
);
192 void wxDC::InitializeMGLDC()
194 if ( GetDepth() > 8 )
196 wxCurrentDCSwitcher
switcher(m_MGLDC
); // will go away with MGL6
197 m_MGLDC
->setFontBlendMode(MGL_AA_RGBBLEND
);
202 // ---------------------------------------------------------------------------
204 // ---------------------------------------------------------------------------
207 #define DO_SET_CLIPPING_BOX(rg) \
209 wxRect rect = rg.GetBox(); \
210 m_clipX1 = (wxCoord) XDEV2LOG(rect.GetLeft()); \
211 m_clipY1 = (wxCoord) YDEV2LOG(rect.GetTop()); \
212 m_clipX2 = (wxCoord) XDEV2LOG(rect.GetRight()); \
213 m_clipY2 = (wxCoord) YDEV2LOG(rect.GetBottom()); \
216 void wxDC::DoSetClippingRegion(wxCoord cx
, wxCoord cy
, wxCoord cw
, wxCoord ch
)
218 wxCHECK_RET( Ok(), wxT("invalid dc") );
220 wxRect
rect(XLOG2DEV(cx
), YLOG2DEV(cy
), XLOG2DEVREL(cw
), YLOG2DEVREL(ch
));
222 if ( !m_currentClippingRegion
.IsNull() )
223 m_currentClippingRegion
.Intersect(rect
);
225 m_currentClippingRegion
.Union(rect
);
227 m_MGLDC
->setClipRegion(m_currentClippingRegion
.GetMGLRegion());
230 DO_SET_CLIPPING_BOX(m_currentClippingRegion
)
233 void wxDC::DoSetClippingRegionAsRegion(const wxRegion
& region
)
235 wxCHECK_RET( Ok(), wxT("invalid dc") );
237 if ( region
.IsEmpty() )
239 DestroyClippingRegion();
245 // check if the DC is scaled or moved, and if yes, then
246 // convert rg to device coordinates:
247 if ( m_deviceOriginX
!= 0 || m_deviceOriginY
!= 0 ||
248 XLOG2DEVREL(500) != 500 || YLOG2DEVREL(500) != 500 )
250 region_t
*mrg
= rg
.GetMGLRegion().rgnPointer();
253 for (s
= mrg
->spans
; s
; s
= s
->next
)
255 s
->y
= YLOG2DEV(s
->y
);
256 for (p
= s
->seg
; p
; p
= p
->next
)
257 p
->x
= XLOG2DEV(p
->x
);
261 if ( !m_currentClippingRegion
.IsNull() )
262 m_currentClippingRegion
.Intersect(rg
);
264 m_currentClippingRegion
.Union(rg
);
266 m_MGLDC
->setClipRegion(m_currentClippingRegion
.GetMGLRegion());
269 DO_SET_CLIPPING_BOX(m_currentClippingRegion
)
272 void wxDC::DestroyClippingRegion()
274 wxCHECK_RET( Ok(), wxT("invalid dc") );
276 if ( !m_globalClippingRegion
.IsNull() )
278 m_MGLDC
->setClipRegion(m_globalClippingRegion
.GetMGLRegion());
279 m_currentClippingRegion
= m_globalClippingRegion
;
284 m_MGLDC
->setClipRect(MGLRect(0, 0, m_MGLDC
->sizex()+1, m_MGLDC
->sizey()+1));
286 m_currentClippingRegion
.Clear();
290 // ---------------------------------------------------------------------------
291 // query capabilities
292 // ---------------------------------------------------------------------------
294 bool wxDC::CanDrawBitmap() const
299 bool wxDC::CanGetTextExtent() const
304 int wxDC::GetDepth() const
306 return m_MGLDC
->getBitsPerPixel();
309 // ---------------------------------------------------------------------------
311 // ---------------------------------------------------------------------------
315 wxCHECK_RET( Ok(), wxT("invalid dc") );
317 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
318 if ( m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
321 wxBrush oldb
= m_brush
;
322 SetBrush(m_backgroundBrush
);
325 m_MGLDC
->fillRect(0, 0, w
, h
);
330 void wxDC::DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
, int style
)
332 wxFAIL_MSG( wxT("wxDC::DoFloodFill not implemented") );
335 bool wxDC::DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
337 wxCHECK_MSG( col
, FALSE
, _T("NULL colour parameter in wxDC::GetPixel"));
340 m_MGLDC
->unpackColorFast(m_MGLDC
->getPixel(XLOG2DEV(x
), YLOG2DEV(y
)),
346 void wxDC::DoCrossHair(wxCoord x
, wxCoord y
)
348 wxCHECK_RET( Ok(), wxT("invalid dc") );
350 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
355 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
356 if ( !m_penSelected
)
358 wxCoord xx
= XLOG2DEV(x
);
359 wxCoord yy
= YLOG2DEV(y
);
360 m_MGLDC
->line(m_penOfsX
, yy
+ m_penOfsY
, w
-1 + m_penOfsX
, yy
+ m_penOfsY
);
361 m_MGLDC
->line(xx
+ m_penOfsX
, m_penOfsY
, x
+ m_penOfsX
, h
-1 + m_penOfsY
);
362 CalcBoundingBox(0, 0);
363 CalcBoundingBox(w
, h
);
367 void wxDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
369 wxCHECK_RET( Ok(), wxT("invalid dc") );
371 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
373 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
374 if ( !m_penSelected
)
376 m_MGLDC
->lineExt(XLOG2DEV(x1
) + m_penOfsX
, YLOG2DEV(y1
) + m_penOfsY
,
377 XLOG2DEV(x2
) + m_penOfsX
, YLOG2DEV(y2
) + m_penOfsY
,FALSE
);
378 CalcBoundingBox(x1
, y1
);
379 CalcBoundingBox(x2
, y2
);
383 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
384 // and ending at (x2, y2)
385 void wxDC::DoDrawArc(wxCoord x1
, wxCoord y1
,
386 wxCoord x2
, wxCoord y2
,
387 wxCoord xc
, wxCoord yc
)
389 wxCHECK_RET( Ok(), wxT("invalid dc") );
391 wxCoord xx1
= XLOG2DEV(x1
);
392 wxCoord yy1
= YLOG2DEV(y1
);
393 wxCoord xx2
= XLOG2DEV(x2
);
394 wxCoord yy2
= YLOG2DEV(y2
);
395 wxCoord xxc
= XLOG2DEV(xc
);
396 wxCoord yyc
= YLOG2DEV(yc
);
397 double dx
= xx1
- xxc
;
398 double dy
= yy1
- yyc
;
399 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
400 wxCoord r
= (wxCoord
)radius
;
401 double radius1
, radius2
;
404 if (xx1
== xx2
&& yy1
== yy2
)
409 else if (radius
== 0.0)
411 radius1
= radius2
= 0.0;
415 radius1
= (xx1
- xxc
== 0) ?
416 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
417 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
418 radius2
= (xx2
- xxc
== 0) ?
419 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
420 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
422 wxCoord alpha1
= wxCoord(radius1
);
423 wxCoord alpha2
= alpha1
+ wxCoord(radius2
- radius1
);
424 while (alpha2
<= 0) alpha2
+= 360;
425 while (alpha1
> 360) alpha1
-= 360;
427 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
428 if ( m_brush
.GetStyle() != wxTRANSPARENT
)
430 if ( !m_brushSelected
)
432 m_MGLDC
->fillEllipseArc(xxc
, yyc
, r
, r
, alpha1
, alpha2
);
435 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
437 if ( !m_penSelected
)
439 m_MGLDC
->ellipseArc(xxc
+ m_penOfsX
, yyc
+ m_penOfsY
, r
, r
, alpha1
, alpha2
);
442 CalcBoundingBox(xc
- r
, yc
- r
);
443 CalcBoundingBox(xc
+ r
, yc
+ r
);
446 void wxDC::DoDrawPoint(wxCoord x
, wxCoord y
)
448 wxCHECK_RET( Ok(), wxT("invalid dc") );
450 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
452 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
453 if ( !m_penSelected
)
455 m_MGLDC
->pixel(XLOG2DEV(x
), YLOG2DEV(y
));
456 CalcBoundingBox(x
, y
);
460 void wxDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
,int fillStyle
)
462 wxCHECK_RET( Ok(), wxT("invalid dc") );
464 wxCoord xxoffset
= XLOG2DEVREL(xoffset
),
465 yyoffset
= YLOG2DEVREL(yoffset
);
466 MGLPoint
*cpoints
= new MGLPoint
[n
+1];
467 for (int i
= 0; i
< n
; i
++)
469 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
470 cpoints
[i
].x
= (int)(XLOG2DEV(points
[i
].x
));
471 cpoints
[i
].y
= (int)(YLOG2DEV(points
[i
].y
));
473 cpoints
[n
] = cpoints
[0];
475 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
476 if ( m_brush
.GetStyle() != wxTRANSPARENT
)
478 if ( !m_brushSelected
)
480 m_MGLDC
->fillPolygon(n
, cpoints
, xxoffset
, yyoffset
);
483 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
485 if ( !m_penSelected
)
487 if (m_penOfsX
!= 0 || m_penOfsY
!= 0)
489 for (int i
= 0; i
<= n
; i
++)
491 cpoints
[i
].x
+= m_penOfsX
;
492 cpoints
[i
].y
+= m_penOfsY
;
495 m_MGLDC
->polyLine(n
+1, cpoints
);
501 void wxDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
503 wxCHECK_RET( Ok(), wxT("invalid dc") );
505 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
507 MGLPoint
*cpoints
= new MGLPoint
[n
];
508 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
509 if ( !m_penSelected
)
511 for (int i
= 0; i
< n
; i
++)
513 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
514 cpoints
[i
].x
= (int)(XLOG2DEV(points
[i
].x
+ xoffset
) /*+ m_penOfsX*/);
515 cpoints
[i
].y
= (int)(YLOG2DEV(points
[i
].y
+ yoffset
) /*+ m_penOfsY*/);
517 m_MGLDC
->polyLine(n
, cpoints
);
522 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
524 wxCHECK_RET( Ok(), wxT("invalid dc") );
526 wxCoord xx
= XLOG2DEV(x
);
527 wxCoord yy
= YLOG2DEV(y
);
528 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
529 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
531 if ( ww
== 0 || hh
== 0 ) return;
544 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
545 if ( m_brush
.GetStyle() != wxTRANSPARENT
)
547 if ( !m_brushSelected
)
549 m_MGLDC
->fillRect(xx
, yy
, xx
+ ww
, yy
+ hh
);
552 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
554 if ( !m_penSelected
)
556 m_MGLDC
->rect(xx
+ m_penOfsX
, yy
+ m_penOfsY
,
557 xx
+ ww
+ m_penOfsX
, yy
+ hh
+ m_penOfsY
);
560 CalcBoundingBox(x
, y
);
561 CalcBoundingBox(x
+ width
, y
+ height
);
564 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
566 wxCHECK_RET( Ok(), wxT("invalid dc") );
569 radius
= -radius
* ((width
< height
) ? width
: height
);
571 wxCoord xx
= XLOG2DEV(x
);
572 wxCoord yy
= YLOG2DEV(y
);
573 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
574 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
575 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
577 // CMB: handle -ve width and/or height
589 // CMB: if radius is zero use DrawRectangle() instead to avoid
590 // X drawing errors with small radii
593 DrawRectangle(x
, y
, width
, height
);
597 // CMB: draw nothing if transformed w or h is 0
598 if ( ww
== 0 || hh
== 0 ) return;
600 // CMB: ensure dd is not larger than rectangle otherwise we
601 // get an hour glass shape
603 if ( dd
> ww
) dd
= ww
;
604 if ( dd
> hh
) dd
= hh
;
607 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
608 if ( m_brush
.GetStyle() != wxTRANSPARENT
)
610 if (!m_brushSelected
)
612 m_MGLDC
->fillRect(xx
+rr
, yy
, xx
+ww
-rr
, yy
+hh
);
613 m_MGLDC
->fillRect(xx
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
614 m_MGLDC
->fillEllipseArc(xx
+rr
, yy
+rr
, rr
, rr
, 90, 180);
615 m_MGLDC
->fillEllipseArc(xx
+ww
-rr
, yy
+rr
, rr
, rr
, 0, 90);
616 m_MGLDC
->fillEllipseArc(xx
+rr
, yy
+hh
-rr
, rr
, rr
, 180, 270);
617 m_MGLDC
->fillEllipseArc(xx
+ww
-rr
, yy
+hh
-rr
, rr
, rr
, 270, 0);
620 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
622 if ( !m_penSelected
)
626 m_MGLDC
->line(xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
627 m_MGLDC
->ellipseArc(xx
+ww
-rr
, yy
+rr
, rr
, rr
, 0, 90);
628 m_MGLDC
->line(xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
629 m_MGLDC
->ellipseArc(xx
+ww
-rr
, yy
+hh
-rr
, rr
, rr
, 270, 0);
630 m_MGLDC
->line(xx
+ww
-rr
, yy
+hh
, xx
+rr
+1, yy
+hh
);
631 m_MGLDC
->ellipseArc(xx
+rr
, yy
+hh
-rr
, rr
, rr
, 180, 270);
632 m_MGLDC
->line(xx
, yy
+hh
-rr
, xx
, yy
+rr
+1);
633 m_MGLDC
->ellipseArc(xx
+rr
, yy
+rr
, rr
, rr
, 90, 180);
636 CalcBoundingBox(x
, y
);
637 CalcBoundingBox(x
+ width
, y
+ height
);
640 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
642 wxCHECK_RET( Ok(), wxT("invalid dc") );
644 wxCoord x2
= (x
+width
);
645 wxCoord y2
= (y
+height
);
647 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
648 if ( m_brush
.GetStyle() != wxTRANSPARENT
)
650 if ( !m_brushSelected
)
652 MGLRect
rect(XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
653 m_MGLDC
->fillEllipse(rect
);
656 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
658 if ( !m_penSelected
)
660 MGLRect
rect(XLOG2DEV(x
) + m_penOfsX
, YLOG2DEV(y
) + m_penOfsY
,
661 XLOG2DEV(x2
) + m_penOfsX
, YLOG2DEV(y2
) + m_penOfsY
);
662 m_MGLDC
->ellipse(rect
);
665 CalcBoundingBox(x
, y
);
666 CalcBoundingBox(x2
, y2
);
669 void wxDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
671 wxCHECK_RET( Ok(), wxT("invalid dc") );
676 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
677 if ( m_brush
.GetStyle() != wxTRANSPARENT
)
679 if (!m_brushSelected
) SelectBrush();
680 MGLRect
rect(XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
681 m_MGLDC
->fillEllipseArc(rect
, (int)sa
, (int)ea
);
684 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
686 if ( !m_penSelected
)
688 MGLRect
rect(XLOG2DEV(x
) + m_penOfsX
, YLOG2DEV(y
) + m_penOfsY
,
689 XLOG2DEV(x2
) + m_penOfsX
, YLOG2DEV(y2
) + m_penOfsY
);
690 m_MGLDC
->ellipseArc(rect
, (int)sa
, (int)ea
);
693 CalcBoundingBox(x
, y
);
694 CalcBoundingBox(x2
, y2
);
697 void wxDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
699 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
700 DrawAnyText(text
, x
, y
);
702 // update the bounding box
704 CalcBoundingBox(x
, y
);
705 GetTextExtent(text
, &w
, &h
);
706 CalcBoundingBox(x
+ w
, y
+ h
);
709 bool wxDC::SelectMGLFont()
711 if ( m_mglFont
== NULL
)
713 float scale
= m_scaleY
;
714 bool antialiased
= (GetDepth() > 8);
716 m_mglFont
= m_font
.GetMGLfont_t(scale
, antialiased
);
717 wxCHECK_MSG( m_mglFont
, FALSE
, wxT("invalid font") );
719 m_MGLDC
->useFont(m_mglFont
);
720 wxLogTrace("mgl_font", "useFont(%p)", m_mglFont
);
723 wxNativeEncodingInfo nativeEnc
;
724 wxFontEncoding encoding
= m_font
.GetEncoding();
725 if ( !wxGetNativeFontEncoding(encoding
, &nativeEnc
) ||
726 !wxTestFontEncoding(nativeEnc
) )
729 if ( !wxTheFontMapper
->GetAltForEncoding(encoding
, &nativeEnc
) )
732 nativeEnc
.mglEncoding
= MGL_ENCODING_ASCII
;
735 m_MGLDC
->setTextEncoding(nativeEnc
.mglEncoding
);
741 void wxDC::DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
)
743 wxCHECK_RET( Ok(), wxT("invalid dc") );
748 wxCoord xx
= XLOG2DEV(x
);
749 wxCoord yy
= YLOG2DEV(y
);
751 m_MGLDC
->setLineStyle(MGL_LINE_STIPPLE
);
752 m_MGLDC
->setLineStipple(0xFFFF);
753 m_MGLDC
->setPenSize(1, 1);
754 m_MGLDC
->setPenStyle(MGL_BITMAP_SOLID
);
757 const wchar_t *c_text
= text
.c_str();
759 const char *c_text
= text
.c_str();
763 // FIXME_MGL - this is a temporary hack in absence of proper
764 // implementation of solid text background in MGL. Once
765 // the bug in MGL is fixed, this code should be nuked
766 // immediately. Note that the code is not 100% correct;
767 // it only works with wxCOPY logical function
768 if ( m_backgroundMode
== wxSOLID
)
770 int w
= m_MGLDC
->textWidth(c_text
);
771 int h
= m_MGLDC
->textHeight();
772 m_MGLDC
->setColor(m_MGLDC
->packColorFast(m_textBackgroundColour
.Red(),
773 m_textBackgroundColour
.Green(), m_textBackgroundColour
.Blue()));
774 m_MGLDC
->fillRect(xx
, yy
, xx
+w
, yy
+h
);
778 m_MGLDC
->setColor(m_MGLDC
->packColorFast(m_textForegroundColour
.Red(),
779 m_textForegroundColour
.Green(), m_textForegroundColour
.Blue()));
780 m_MGLDC
->setBackColor(m_MGLDC
->packColorFast(m_textBackgroundColour
.Red(),
781 m_textBackgroundColour
.Green(), m_textBackgroundColour
.Blue()));
783 m_MGLDC
->drawStr(xx
, yy
, c_text
);
786 if ( m_font
.GetUnderlined() )
788 int x1
= xx
, y1
= yy
;
790 int w
= m_MGLDC
->textWidth(c_text
);
791 m_MGLDC
->underScoreLocation(x1
, y1
, c_text
);
792 switch (m_MGLDC
->getTextDirection())
794 case MGL_RIGHT_DIR
: x2
= x1
+ w
, y2
= y1
; break;
795 case MGL_LEFT_DIR
: x2
= x1
- w
, y2
= y1
; break;
796 case MGL_UP_DIR
: x2
= x1
, y2
= y1
- w
; break;
797 case MGL_DOWN_DIR
: x2
= x1
, y2
= y1
+ w
; break;
799 m_MGLDC
->line(x1
, y1
, x2
, y2
);
802 m_penSelected
= m_brushSelected
= FALSE
;
805 void wxDC::DoDrawRotatedText(const wxString
& text
,
806 wxCoord x
, wxCoord y
,
809 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
813 DoDrawText(text
, x
, y
);
816 else if ( angle
== 90.0 )
817 m_MGLDC
->setTextDirection(MGL_UP_DIR
);
818 else if ( angle
== 180.0 )
819 m_MGLDC
->setTextDirection(MGL_LEFT_DIR
);
820 else if ( angle
== 270.0 )
821 m_MGLDC
->setTextDirection(MGL_DOWN_DIR
);
824 // FIXME_MGL -- implement once MGL supports it
825 wxFAIL_MSG(wxT("wxMGL only supports rotated text with angle 0,90,180 or 270"));
829 DrawAnyText(text
, x
, y
);
832 m_MGLDC
->setTextDirection(MGL_RIGHT_DIR
);
835 // ---------------------------------------------------------------------------
837 // ---------------------------------------------------------------------------
839 void wxDC::SelectMGLStipplePen(int style
)
845 case wxDOT
: stipple
= STIPPLE_wxDOT
; break;
846 case wxLONG_DASH
: stipple
= STIPPLE_wxLONG_DASH
; break;
847 case wxSHORT_DASH
: stipple
= STIPPLE_wxSHORT_DASH
; break;
848 case wxDOT_DASH
: stipple
= STIPPLE_wxDOT_DASH
; break;
849 default: stipple
= STIPPLE_wxSOLID
; break;
852 m_MGLDC
->setLineStyle(MGL_LINE_STIPPLE
);
853 m_MGLDC
->setLineStipple(stipple
);
854 m_MGLDC
->setPenSize(1, 1);
855 m_MGLDC
->setPenStyle(MGL_BITMAP_SOLID
);
856 m_penOfsY
= m_penOfsX
= 0;
859 // Accepted valus of SelectMGLFatPen's 2nd argument
861 wxMGL_SELECT_FROM_PEN
,
862 wxMGL_SELECT_FROM_BRUSH
865 void wxDC::SelectMGLFatPen(int style
, int flag
)
867 MGL_penStyleType penstyle
;
868 const pattern_t
*pattern
= NULL
;
869 pixpattern24_t
*pixPattern
= NULL
;
873 // Since MGL pens may be created from wxBrush or wxPen and we often
874 // switch between pens and brushes, we take advantage of MGL's ability
875 // to have multiple (pix)pattern_t's loaded. We always download pen
876 // to 0th slot and brush to 1st slot.
877 if ( flag
== wxMGL_SELECT_FROM_PEN
)
882 // compute pen's width:
883 if ( m_pen
.GetWidth() <= 1 )
886 m_penOfsX
= m_penOfsY
= 0;
890 wx
= (int)(0.5 + fabs((double) XLOG2DEVREL(m_pen
.GetWidth())));
891 wy
= (int)(0.5 + fabs((double) YLOG2DEVREL(m_pen
.GetWidth())));
897 penstyle
= MGL_BITMAP_TRANSPARENT
;
900 case wxBDIAGONAL_HATCH
: pattern
= &PATTERN_wxBDIAGONAL_HATCH
;
901 penstyle
= MGL_BITMAP_TRANSPARENT
;
903 case wxCROSSDIAG_HATCH
: pattern
= &PATTERN_wxCROSSDIAG_HATCH
;
904 penstyle
= MGL_BITMAP_TRANSPARENT
;
906 case wxFDIAGONAL_HATCH
: pattern
= &PATTERN_wxFDIAGONAL_HATCH
;
907 penstyle
= MGL_BITMAP_TRANSPARENT
;
909 case wxCROSS_HATCH
: pattern
= &PATTERN_wxCROSS_HATCH
;
910 penstyle
= MGL_BITMAP_TRANSPARENT
;
912 case wxHORIZONTAL_HATCH
: pattern
= &PATTERN_wxHORIZONTAL_HATCH
;
913 penstyle
= MGL_BITMAP_TRANSPARENT
;
915 case wxVERTICAL_HATCH
: pattern
= &PATTERN_wxVERTICAL_HATCH
;
916 penstyle
= MGL_BITMAP_TRANSPARENT
;
920 if ( flag
== wxMGL_SELECT_FROM_PEN
)
921 pixPattern
= (pixpattern24_t
*) m_pen
.GetPixPattern();
923 pixPattern
= (pixpattern24_t
*) m_brush
.GetPixPattern();
924 penstyle
= MGL_PIXMAP
;
927 case wxSTIPPLE_MASK_OPAQUE
:
928 pattern
= (pattern_t
*) m_brush
.GetMaskPattern();
929 penstyle
= MGL_BITMAP_OPAQUE
;
934 penstyle
= MGL_BITMAP_SOLID
; break;
937 // ...and finally, pass the pen to MGL:
941 if ( !m_downloadedPatterns
[slot
] )
943 m_MGLDC
->setPenBitmapPattern(slot
, pattern
);
944 m_downloadedPatterns
[slot
] = TRUE
;
946 m_MGLDC
->usePenBitmapPattern(slot
);
951 if ( !m_downloadedPatterns
[slot
] )
959 for (y
= 0; y
< 8; y
++)
960 for (x
= 0; x
< 8; x
++)
961 pix
.b8
.p
[x
][y
] = m_MGLDC
->packColorFast(
962 pixPattern
->p
[x
][y
][0],
963 pixPattern
->p
[x
][y
][1],
964 pixPattern
->p
[x
][y
][2]);
968 for (y
= 0; y
< 8; y
++)
969 for (x
= 0; x
< 8; x
++)
970 pix
.b16
.p
[x
][y
] = m_MGLDC
->packColorFast(
971 pixPattern
->p
[x
][y
][0],
972 pixPattern
->p
[x
][y
][1],
973 pixPattern
->p
[x
][y
][2]);
976 for (y
= 0; y
< 8; y
++)
977 for (x
= 0; x
< 8; x
++)
978 for (c
= 0; c
< 3; c
++)
979 pix
.b24
.p
[x
][y
][c
] = pixPattern
->p
[x
][y
][c
];
982 for (y
= 0; y
< 8; y
++)
983 for (x
= 0; x
< 8; x
++)
984 pix
.b32
.p
[x
][y
] = m_MGLDC
->packColorFast(
985 pixPattern
->p
[x
][y
][0],
986 pixPattern
->p
[x
][y
][1],
987 pixPattern
->p
[x
][y
][2]);
990 wxFAIL_MSG(_T("invalid DC depth"));
993 m_MGLDC
->setPenPixmapPattern(slot
, &pix
);
994 m_downloadedPatterns
[slot
] = TRUE
;
996 m_MGLDC
->usePenPixmapPattern(slot
);
999 m_MGLDC
->setLineStyle(MGL_LINE_PENSTYLE
);
1000 m_MGLDC
->setPenStyle(penstyle
);
1001 m_MGLDC
->setPenSize(wy
, wx
);
1004 void wxDC::SelectPen()
1006 wxCHECK_RET( Ok(), wxT("invalid dc") );
1008 wxColour
& clr
= m_pen
.GetColour();
1009 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
1010 m_MGLDC
->setColorRGB(clr
.Red(), clr
.Green(), clr
.Blue());
1012 switch (m_pen
.GetStyle())
1021 SelectMGLStipplePen(m_pen
.GetStyle());
1024 case wxBDIAGONAL_HATCH
:
1025 case wxCROSSDIAG_HATCH
:
1026 case wxFDIAGONAL_HATCH
:
1028 case wxHORIZONTAL_HATCH
:
1029 case wxVERTICAL_HATCH
:
1030 SelectMGLFatPen(m_pen
.GetStyle(), wxMGL_SELECT_FROM_PEN
);
1034 SelectMGLFatPen(m_pen
.GetStyle(), wxMGL_SELECT_FROM_PEN
);
1040 if ( m_pen
.GetWidth() <= 1 )
1041 SelectMGLStipplePen(wxSOLID
);
1043 SelectMGLFatPen(wxSOLID
, wxMGL_SELECT_FROM_PEN
);
1046 m_penSelected
= TRUE
;
1047 m_brushSelected
= FALSE
;
1050 void wxDC::SelectBrush()
1052 wxCHECK_RET( Ok(), wxT("invalid dc") );
1055 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
1057 if ( m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
1059 fg
= m_textForegroundColour
;
1060 bg
= m_textBackgroundColour
;
1064 fg
= m_brush
.GetColour();
1065 bg
= m_backgroundBrush
.GetColour();
1068 m_MGLDC
->setColorRGB(fg
.Red(), fg
.Green(), fg
.Blue());
1069 m_MGLDC
->setBackColor(m_MGLDC
->packColorFast(bg
.Red(), bg
.Green(), bg
.Blue()));
1070 m_penSelected
= FALSE
;
1071 m_brushSelected
= TRUE
;
1073 SelectMGLFatPen(m_brush
.GetStyle(), wxMGL_SELECT_FROM_BRUSH
);
1076 void wxDC::SetPen(const wxPen
& pen
)
1078 if ( !pen
.Ok() ) return;
1079 if ( m_pen
== pen
) return;
1081 m_penSelected
= FALSE
;
1082 m_downloadedPatterns
[0] = FALSE
;
1085 void wxDC::SetBrush(const wxBrush
& brush
)
1087 if ( !brush
.Ok() ) return;
1088 if ( m_brush
== brush
) return;
1090 m_brushSelected
= FALSE
;
1091 m_downloadedPatterns
[1] = FALSE
;
1094 void wxDC::SetPalette(const wxPalette
& palette
)
1096 wxCHECK_RET( Ok(), wxT("invalid dc") );
1098 if ( palette
== wxNullPalette
)
1100 SetPalette(m_oldPalette
);
1104 if ( !palette
.Ok() ) return;
1105 if ( m_palette
== palette
) return;
1106 m_oldPalette
= m_palette
;
1107 m_palette
= palette
;
1109 int cnt
= m_palette
.GetColoursCount();
1110 palette_t
*pal
= m_palette
.GetMGLpalette_t();
1111 m_MGLDC
->setPalette(pal
, cnt
, 0);
1112 m_MGLDC
->realizePalette(cnt
, 0, TRUE
);
1115 void wxDC::SetFont(const wxFont
& font
)
1117 wxCHECK_RET( font
.Ok(), wxT("invalid font") );
1122 void wxDC::SetBackground(const wxBrush
& brush
)
1124 wxCHECK_RET( Ok(), wxT("invalid dc") );
1126 if (!m_backgroundBrush
.Ok()) return;
1128 m_backgroundBrush
= brush
;
1129 wxColour
&clr
= m_backgroundBrush
.GetColour();
1130 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
1131 m_MGLDC
->setBackColor(
1132 m_MGLDC
->packColorFast(clr
.Red(), clr
.Green(), clr
.Blue()));
1135 void wxDC::SetBackgroundMode(int mode
)
1137 m_backgroundMode
= mode
;
1138 if ( mode
== wxSOLID
)
1139 m_MGLDC
->setBackMode(MGL_OPAQUE_BACKGROUND
);
1141 m_MGLDC
->setBackMode(MGL_TRANSPARENT_BACKGROUND
);
1144 void wxDC::SetLogicalFunction(int function
)
1146 wxCHECK_RET( Ok(), wxT("invalid dc") );
1148 m_logicalFunction
= function
;
1150 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
1151 m_MGLDC
->setWriteMode(LogicalFunctionToMGLRop(m_logicalFunction
));
1154 int wxDC::LogicalFunctionToMGLRop(int logFunc
) const
1156 MGL_writeModeType rop
;
1160 case wxCLEAR
: rop
= MGL_R2_BLACK
; break;
1161 case wxXOR
: rop
= MGL_R2_XORSRC
; break;
1162 case wxINVERT
: rop
= MGL_R2_NOT
; break;
1163 case wxOR_REVERSE
: rop
= MGL_R2_MERGESRCNOT
; break;
1164 case wxAND_REVERSE
: rop
= MGL_R2_MASKSRCNOT
; break;
1165 case wxCOPY
: rop
= MGL_R2_COPYSRC
; break;
1166 case wxAND
: rop
= MGL_R2_MASKSRC
; break;
1167 case wxAND_INVERT
: rop
= MGL_R2_MASKNOTSRC
; break;
1168 case wxNO_OP
: rop
= MGL_R2_NOP
; break;
1169 case wxNOR
: rop
= MGL_R2_NOTMERGESRC
; break;
1170 case wxEQUIV
: rop
= MGL_R2_NOTXORSRC
; break;
1171 case wxSRC_INVERT
: rop
= MGL_R2_NOTCOPYSRC
; break;
1172 case wxOR_INVERT
: rop
= MGL_R2_MERGENOTSRC
; break;
1173 case wxNAND
: rop
= MGL_R2_NOTMASKSRC
; break;
1174 case wxOR
: rop
= MGL_R2_MERGESRC
; break;
1175 case wxSET
: rop
= MGL_R2_WHITE
; break;
1177 wxFAIL_MSG( wxT("unsupported logical function") );
1178 return MGL_REPLACE_MODE
;
1183 bool wxDC::StartDoc(const wxString
& message
)
1185 // We might be previewing, so return TRUE to let it continue.
1193 void wxDC::StartPage()
1197 void wxDC::EndPage()
1201 // ---------------------------------------------------------------------------
1203 // ---------------------------------------------------------------------------
1205 wxCoord
wxDC::GetCharHeight() const
1207 wxCurrentDCSwitcher
switcher(m_MGLDC
);
1208 if ( !wxConstCast(this, wxDC
)->SelectMGLFont() ) return -1;
1209 return YDEV2LOGREL(m_mglFont
->fontHeight
);
1212 wxCoord
wxDC::GetCharWidth() const
1214 wxCurrentDCSwitcher
switcher(m_MGLDC
);
1215 if ( !wxConstCast(this, wxDC
)->SelectMGLFont() ) return -1;
1216 // VS: wxT() is intentional, charWidth() has both char and wchar_t version
1217 // VS: YDEV is corrent, it should *not* be XDEV, because font's are only
1218 // scaled according to m_scaleY
1219 return YDEV2LOGREL(m_mglFont
->fontWidth
);
1222 void wxDC::DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
1223 wxCoord
*descent
, wxCoord
*externalLeading
,
1224 wxFont
*theFont
) const
1228 if ( theFont
!= NULL
)
1231 wxConstCast(this, wxDC
)->SetFont(*theFont
);
1234 wxCurrentDCSwitcher
switcher(m_MGLDC
);
1235 if ( !wxConstCast(this, wxDC
)->SelectMGLFont() ) return;
1238 // VS: YDEV is corrent, it should *not* be XDEV, because font's are
1239 // only scaled according to m_scaleY
1240 *x
= YDEV2LOGREL(m_MGLDC
->textWidth(string
.c_str()));
1242 *y
= YDEV2LOGREL(m_MGLDC
->textHeight());
1244 *descent
= YDEV2LOGREL(m_mglFont
->descent
);
1245 if ( externalLeading
)
1246 *externalLeading
= YDEV2LOGREL(m_mglFont
->leading
);
1248 if ( theFont
!= NULL
)
1249 wxConstCast(this, wxDC
)->SetFont(oldFont
);
1254 // ---------------------------------------------------------------------------
1256 // ---------------------------------------------------------------------------
1258 void wxDC::ComputeScaleAndOrigin()
1260 double newX
= m_logicalScaleX
* m_userScaleX
;
1261 double newY
= m_logicalScaleY
* m_userScaleY
;
1263 // make sure font will be reloaded before drawing:
1264 if ( newY
!= m_scaleY
)
1266 // make sure m_penOfs{X,Y} will be reevaluated before drawing:
1267 if ( newY
!= m_scaleY
|| newX
!= m_scaleX
)
1268 m_penSelected
= FALSE
;
1270 m_scaleX
= newX
, m_scaleY
= newY
;
1273 void wxDC::SetMapMode(int mode
)
1278 SetLogicalScale(twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
1281 SetLogicalScale(pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
1284 SetLogicalScale(m_mm_to_pix_x
, m_mm_to_pix_y
);
1287 SetLogicalScale(m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0);
1291 SetLogicalScale(1.0, 1.0);
1294 m_mappingMode
= mode
;
1297 void wxDC::SetUserScale( double x
, double y
)
1299 // allow negative ? -> no
1302 ComputeScaleAndOrigin();
1305 void wxDC::SetLogicalScale( double x
, double y
)
1308 m_logicalScaleX
= x
;
1309 m_logicalScaleY
= y
;
1310 ComputeScaleAndOrigin();
1313 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
1315 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
1316 m_logicalOriginY
= y
* m_signY
;
1317 ComputeScaleAndOrigin();
1320 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1322 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
1323 m_deviceOriginX
= x
;
1324 m_deviceOriginY
= y
;
1325 ComputeScaleAndOrigin();
1328 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1330 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
1331 m_signX
= (xLeftRight
? 1 : -1);
1332 m_signY
= (yBottomUp
? -1 : 1);
1333 ComputeScaleAndOrigin();
1336 // ---------------------------------------------------------------------------
1337 // coordinates transformations
1338 // ---------------------------------------------------------------------------
1340 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1342 return ((wxDC
*)this)->XDEV2LOG(x
);
1345 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1347 return ((wxDC
*)this)->YDEV2LOG(y
);
1350 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1352 return ((wxDC
*)this)->XDEV2LOGREL(x
);
1355 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1357 return ((wxDC
*)this)->YDEV2LOGREL(y
);
1360 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1362 return ((wxDC
*)this)->XLOG2DEV(x
);
1365 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1367 return ((wxDC
*)this)->YLOG2DEV(y
);
1370 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1372 return ((wxDC
*)this)->XLOG2DEVREL(x
);
1375 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1377 return ((wxDC
*)this)->YLOG2DEVREL(y
);
1381 void wxDC::DoGetSize(int *w
, int *h
) const
1383 if (w
) *w
= m_MGLDC
->sizex()+1;
1384 if (h
) *h
= m_MGLDC
->sizey()+1;
1387 void wxDC::DoGetSizeMM(int *width
, int *height
) const
1392 if ( width
) *width
= int(double(w
) / (m_userScaleX
*m_mm_to_pix_x
));
1393 if ( height
) *height
= int(double(h
) / (m_userScaleY
*m_mm_to_pix_y
));
1396 wxSize
wxDC::GetPPI() const
1398 return wxSize(int(double(m_mm_to_pix_x
) * inches2mm
),
1399 int(double(m_mm_to_pix_y
) * inches2mm
));
1403 // ---------------------------------------------------------------------------
1405 // ---------------------------------------------------------------------------
1407 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
,
1408 wxCoord width
, wxCoord height
,
1409 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1410 int rop
, bool useMask
,
1411 wxCoord xsrcMask
, wxCoord ysrcMask
)
1413 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid dc") );
1414 wxCHECK_MSG( source
, FALSE
, wxT("invalid source dc") );
1416 // transform the source DC coords to the device ones
1417 xsrc
= source
->LogicalToDeviceX(xsrc
);
1418 ysrc
= source
->LogicalToDeviceY(ysrc
);
1420 /* FIXME_MGL: use the mask origin when drawing transparently */
1421 if (xsrcMask
== -1 && ysrcMask
== -1)
1423 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1427 xsrcMask
= source
->LogicalToDeviceX(xsrcMask
);
1428 ysrcMask
= source
->LogicalToDeviceY(ysrcMask
);
1431 CalcBoundingBox(xdest
, ydest
);
1432 CalcBoundingBox(xdest
+ width
, ydest
+ height
);
1434 /* scale/translate size and position */
1435 wxCoord xx
= XLOG2DEV(xdest
);
1436 wxCoord yy
= YLOG2DEV(ydest
);
1437 wxCoord ww
= XLOG2DEVREL(width
);
1438 wxCoord hh
= YLOG2DEVREL(height
);
1440 if ( source
->m_isMemDC
)
1442 wxMemoryDC
*memDC
= (wxMemoryDC
*) source
;
1443 DoDrawSubBitmap(memDC
->GetSelectedObject(), xsrc
, ysrc
, ww
, hh
,
1444 xdest
, ydest
, rop
, useMask
);
1448 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
1449 m_MGLDC
->bitBlt(*source
->GetMGLDC(),
1450 xsrc
, ysrc
, xsrc
+ ww
, ysrc
+ hh
,
1451 xx
, yy
, LogicalFunctionToMGLRop(rop
));
1457 void wxDC::DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
1459 wxCHECK_RET( Ok(), wxT("invalid dc") );
1460 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
1462 wxCoord w
= bmp
.GetWidth();
1463 wxCoord h
= bmp
.GetHeight();
1465 DoDrawSubBitmap(bmp
, 0, 0, w
, h
, x
, y
, m_logicalFunction
, useMask
);
1468 void wxDC::DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1470 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
1471 DoDrawBitmap((const wxBitmap
&)icon
, x
, y
, (bool)TRUE
);
1475 static inline void DoBitBlt(const wxBitmap
& src
, MGLDevCtx
*dst
,
1476 int sx
, int sy
, int sw
, int sh
,
1477 int dx
, int dy
, int dw
, int dh
,
1478 int rop
, bool useStretching
, bool putSection
)
1480 bitmap_t
*bmp
= src
.GetMGLbitmap_t();
1484 dst
->putBitmap(dx
, dy
, bmp
, rop
);
1486 dst
->putBitmapSection(sx
, sy
, sx
+ sw
, sy
+ sh
, dx
, dy
, bmp
, rop
);
1491 dst
->stretchBitmap(dx
, dy
, dx
+ dw
, dy
+ dh
, bmp
, rop
);
1493 dst
->stretchBitmapSection(sx
, sy
, sx
+ sw
, sy
+ sh
,
1494 dx
, dy
, dx
+ dw
, dy
+ dh
, bmp
, rop
);
1498 void wxDC::DoDrawSubBitmap(const wxBitmap
&bmp
,
1499 wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
1500 wxCoord destx
, wxCoord desty
, int rop
, bool useMask
)
1502 wxCHECK_RET( Ok(), wxT("invalid dc") );
1503 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
1505 CalcBoundingBox(x
, y
);
1506 CalcBoundingBox(x
+ w
, y
+ h
);
1508 wxCoord dx
= XLOG2DEV(destx
);
1509 wxCoord dy
= YLOG2DEV(desty
);
1510 wxCoord dw
= XLOG2DEVREL(w
);
1511 wxCoord dh
= YLOG2DEVREL(h
);
1513 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
1515 bool useStretching
= ((w
!= dw
) || (h
!= dh
));
1516 bool putSection
= (w
!= bmp
.GetWidth() || h
!= bmp
.GetHeight());
1517 MGL_writeModeType mglRop
= (MGL_writeModeType
)LogicalFunctionToMGLRop(rop
);
1519 if ( bmp
.GetDepth() == 1 )
1521 // Mono bitmaps are handled in special way -- all 1s are drawn in
1522 // foreground colours, all 0s in background colour.
1524 ((wxBitmap
&)bmp
).SetMonoPalette(m_textForegroundColour
, m_textBackgroundColour
);
1527 if ( useMask
&& bmp
.GetMask() )
1529 // Since MGL does not support masks directly (in MGL, mask is handled
1530 // in same way as in wxImage, i.e. there is one "key" color), we
1531 // simulate masked bitblt in 6 steps (same as in MSW):
1533 // 1. Create a temporary bitmap and copy the destination area into it.
1534 // 2. Copy the source area into the temporary bitmap using the
1535 // specified logical function.
1536 // 3. Set the masked area in the temporary bitmap to BLACK by ANDing
1537 // the mask bitmap with the temp bitmap with the foreground colour
1538 // set to WHITE and the bg colour set to BLACK.
1539 // 4. Set the unmasked area in the destination area to BLACK by
1540 // ANDing the mask bitmap with the destination area with the
1541 // foreground colour set to BLACK and the background colour set
1543 // 5. OR the temporary bitmap with the destination area.
1544 // 6. Delete the temporary bitmap.
1546 // This sequence of operations ensures that the source's transparent
1547 // area need not be black, and logical functions are supported.
1549 wxBitmap
*mask
= bmp
.GetMask()->GetBitmap();
1553 if ( GetDepth() <= 8 )
1555 temp
= new MGLMemoryDC(dw
, dh
, GetDepth(), NULL
);
1557 tempdc
.SetMGLDC(temp
, FALSE
);
1558 tempdc
.SetPalette(m_palette
);
1563 m_MGLDC
->getPixelFormat(pf
);
1564 temp
= new MGLMemoryDC(dw
, dh
, GetDepth(), &pf
);
1567 wxCHECK_RET( temp
->isValid(), wxT("cannot create temporary dc") );
1569 temp
->bitBlt(*m_MGLDC
, dx
, dy
, dx
+ dw
, dy
+ dh
, 0, 0, MGL_REPLACE_MODE
);
1571 DoBitBlt(bmp
, temp
, x
, y
, w
, h
, 0, 0, dw
, dh
, mglRop
,
1572 useStretching
, putSection
);
1574 mask
->SetMonoPalette(wxColour(0,0,0), wxColour(255,255,255));
1575 DoBitBlt(*mask
, temp
, x
, y
, w
, h
, 0, 0, dw
, dh
, MGL_R2_MASKSRC
,
1576 useStretching
, putSection
);
1577 DoBitBlt(*mask
, m_MGLDC
, x
, y
, w
, h
, dx
, dy
, dw
, dh
, MGL_R2_MASKNOTSRC
,
1578 useStretching
, putSection
);
1580 m_MGLDC
->bitBlt(*temp
, 0, 0, dw
, dh
, dx
, dy
, MGL_OR_MODE
);
1587 DoBitBlt(bmp
, m_MGLDC
, x
, y
, w
, h
, dx
, dy
, dw
, dh
, mglRop
,
1588 useStretching
, putSection
);