1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2001-2002 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 //-----------------------------------------------------------------------------
51 #define M_PI 3.14159265358979323846
54 const double mm2inches
= 0.0393700787402;
55 const double inches2mm
= 25.4;
56 const double mm2twips
= 56.6929133859;
57 const double twips2mm
= 0.0176388888889;
58 const double mm2pt
= 2.83464566929;
59 const double pt2mm
= 0.352777777778;
60 const double RAD2DEG
= 180.0 / M_PI
;
63 //-----------------------------------------------------------------------------
65 //-----------------------------------------------------------------------------
67 const ushort STIPPLE_wxDOT
= 0x5555/* - - - - - - - -*/;
68 const ushort STIPPLE_wxLONG_DASH
= 0xF0F0/* ---- ----*/;
69 const ushort STIPPLE_wxSHORT_DASH
= 0xCCCC/*-- -- -- -- */;
70 const ushort STIPPLE_wxDOT_DASH
= 0x3939/* --- - --- -*/;
71 const ushort STIPPLE_wxSOLID
= 0xFFFF/*----------------*/;
73 #define PATTERN_ROW(b7,b6,b5,b4,b3,b2,b1,b0) \
74 ((b7 << 7) | (b6 << 6) | (b5 << 5) | (b4 << 4) | \
75 (b3 << 3) | (b2 << 2) | (b1 << 1) | b0)
77 static pattern_t PATTERN_wxFDIAGONAL_HATCH
= {{
78 PATTERN_ROW(1,0,0,0,0,0,0,0),
79 PATTERN_ROW(0,1,0,0,0,0,0,0),
80 PATTERN_ROW(0,0,1,0,0,0,0,0),
81 PATTERN_ROW(0,0,0,1,0,0,0,0),
82 PATTERN_ROW(0,0,0,0,1,0,0,0),
83 PATTERN_ROW(0,0,0,0,0,1,0,0),
84 PATTERN_ROW(0,0,0,0,0,0,1,0),
85 PATTERN_ROW(0,0,0,0,0,0,0,1),
88 static pattern_t PATTERN_wxCROSSDIAG_HATCH
= {{
89 PATTERN_ROW(1,0,0,0,0,0,0,1),
90 PATTERN_ROW(0,1,0,0,0,0,1,0),
91 PATTERN_ROW(0,0,1,0,0,1,0,0),
92 PATTERN_ROW(0,0,0,1,1,0,0,0),
93 PATTERN_ROW(0,0,0,1,1,0,0,0),
94 PATTERN_ROW(0,0,1,0,0,1,0,0),
95 PATTERN_ROW(0,1,0,0,0,0,1,0),
96 PATTERN_ROW(1,0,0,0,0,0,0,1),
99 static pattern_t PATTERN_wxBDIAGONAL_HATCH
= {{
100 PATTERN_ROW(0,0,0,0,0,0,0,1),
101 PATTERN_ROW(0,0,0,0,0,0,1,0),
102 PATTERN_ROW(0,0,0,0,0,1,0,0),
103 PATTERN_ROW(0,0,0,0,1,0,0,0),
104 PATTERN_ROW(0,0,0,1,0,0,0,0),
105 PATTERN_ROW(0,0,1,0,0,0,0,0),
106 PATTERN_ROW(0,1,0,0,0,0,0,0),
107 PATTERN_ROW(1,0,0,0,0,0,0,0),
110 static pattern_t PATTERN_wxCROSS_HATCH
= {{
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(1,1,1,1,1,1,1,1),
115 PATTERN_ROW(0,0,0,1,0,0,0,0),
116 PATTERN_ROW(0,0,0,1,0,0,0,0),
117 PATTERN_ROW(0,0,0,1,0,0,0,0),
118 PATTERN_ROW(0,0,0,1,0,0,0,0),
121 static pattern_t PATTERN_wxHORIZONTAL_HATCH
= {{
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(1,1,1,1,1,1,1,1),
126 PATTERN_ROW(0,0,0,0,0,0,0,0),
127 PATTERN_ROW(0,0,0,0,0,0,0,0),
128 PATTERN_ROW(0,0,0,0,0,0,0,0),
129 PATTERN_ROW(0,0,0,0,0,0,0,0),
132 static pattern_t PATTERN_wxVERTICAL_HATCH
= {{
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),
137 PATTERN_ROW(0,0,0,1,0,0,0,0),
138 PATTERN_ROW(0,0,0,1,0,0,0,0),
139 PATTERN_ROW(0,0,0,1,0,0,0,0),
140 PATTERN_ROW(0,0,0,1,0,0,0,0),
145 //-----------------------------------------------------------------------------
147 //-----------------------------------------------------------------------------
149 IMPLEMENT_ABSTRACT_CLASS(wxDC
, wxDCBase
)
151 // Default constructor
157 m_ok
= FALSE
; // must call SetMGLDevCtx() before using it
159 m_mm_to_pix_x
= (double)wxGetDisplaySize().GetWidth() /
160 (double)wxGetDisplaySizeMM().GetWidth();
161 m_mm_to_pix_y
= (double)wxGetDisplaySize().GetHeight() /
162 (double)wxGetDisplaySizeMM().GetHeight();
164 m_pen
= *wxBLACK_PEN
;
165 m_font
= *wxNORMAL_FONT
;
166 m_brush
= *wxWHITE_BRUSH
;
167 m_penOfsX
= m_penOfsY
= 0;
169 m_penSelected
= m_brushSelected
= FALSE
;
170 m_downloadedPatterns
[0] = m_downloadedPatterns
[1] = FALSE
;
182 void wxDC::SetMGLDC(MGLDevCtx
*mgldc
, bool OwnsMGLDC
)
184 if ( m_OwnsMGLDC
&& m_MGLDC
)
187 m_OwnsMGLDC
= OwnsMGLDC
;
190 if ( !m_globalClippingRegion
.IsNull() )
191 SetClippingRegion(m_globalClippingRegion
);
196 void wxDC::InitializeMGLDC()
198 if ( GetDepth() > 8 )
200 wxCurrentDCSwitcher
switcher(m_MGLDC
); // will go away with MGL6
201 m_MGLDC
->setFontBlendMode(MGL_AA_RGBBLEND
);
206 // ---------------------------------------------------------------------------
208 // ---------------------------------------------------------------------------
211 #define DO_SET_CLIPPING_BOX(rg) \
213 wxRect rect = rg.GetBox(); \
214 m_clipX1 = (wxCoord) XDEV2LOG(rect.GetLeft()); \
215 m_clipY1 = (wxCoord) YDEV2LOG(rect.GetTop()); \
216 m_clipX2 = (wxCoord) XDEV2LOG(rect.GetRight()); \
217 m_clipY2 = (wxCoord) YDEV2LOG(rect.GetBottom()); \
220 void wxDC::DoSetClippingRegion(wxCoord cx
, wxCoord cy
, wxCoord cw
, wxCoord ch
)
222 wxCHECK_RET( Ok(), wxT("invalid dc") );
224 wxRect
rect(XLOG2DEV(cx
), YLOG2DEV(cy
), XLOG2DEVREL(cw
), YLOG2DEVREL(ch
));
226 if ( !m_currentClippingRegion
.IsNull() )
227 m_currentClippingRegion
.Intersect(rect
);
229 m_currentClippingRegion
.Union(rect
);
231 m_MGLDC
->setClipRegion(m_currentClippingRegion
.GetMGLRegion());
234 DO_SET_CLIPPING_BOX(m_currentClippingRegion
)
237 void wxDC::DoSetClippingRegionAsRegion(const wxRegion
& region
)
239 wxCHECK_RET( Ok(), wxT("invalid dc") );
241 if ( region
.IsEmpty() )
243 DestroyClippingRegion();
249 // check if the DC is scaled or moved, and if yes, then
250 // convert rg to device coordinates:
251 if ( m_deviceOriginX
!= 0 || m_deviceOriginY
!= 0 ||
252 m_logicalOriginX
!= 0 || m_logicalOriginY
!= 0 ||
253 XLOG2DEVREL(500) != 500 || YLOG2DEVREL(500) != 500 )
255 region_t
*mrg
= rg
.GetMGLRegion().rgnPointer();
258 for (s
= mrg
->spans
; s
; s
= s
->next
)
260 s
->y
= YLOG2DEV(s
->y
);
261 for (p
= s
->seg
; p
; p
= p
->next
)
262 p
->x
= XLOG2DEV(p
->x
);
266 if ( !m_currentClippingRegion
.IsNull() )
267 m_currentClippingRegion
.Intersect(rg
);
269 m_currentClippingRegion
.Union(rg
);
271 m_MGLDC
->setClipRegion(m_currentClippingRegion
.GetMGLRegion());
274 DO_SET_CLIPPING_BOX(m_currentClippingRegion
)
277 void wxDC::DestroyClippingRegion()
279 wxCHECK_RET( Ok(), wxT("invalid dc") );
281 if ( !m_globalClippingRegion
.IsNull() )
283 m_MGLDC
->setClipRegion(m_globalClippingRegion
.GetMGLRegion());
284 m_currentClippingRegion
= m_globalClippingRegion
;
289 m_MGLDC
->setClipRect(MGLRect(0, 0, m_MGLDC
->sizex()+1, m_MGLDC
->sizey()+1));
291 m_currentClippingRegion
.Clear();
295 // ---------------------------------------------------------------------------
296 // query capabilities
297 // ---------------------------------------------------------------------------
299 bool wxDC::CanDrawBitmap() const
304 bool wxDC::CanGetTextExtent() const
309 int wxDC::GetDepth() const
311 return m_MGLDC
->getBitsPerPixel();
314 // ---------------------------------------------------------------------------
316 // ---------------------------------------------------------------------------
320 wxCHECK_RET( Ok(), wxT("invalid dc") );
322 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
323 if ( m_backgroundBrush
.GetStyle() != wxTRANSPARENT
)
326 wxBrush oldb
= m_brush
;
327 SetBrush(m_backgroundBrush
);
330 m_MGLDC
->fillRect(0, 0, w
, h
);
335 void wxDC::DoFloodFill(wxCoord x
, wxCoord y
, const wxColour
& col
, int style
)
337 wxFAIL_MSG( wxT("wxDC::DoFloodFill not implemented") );
340 bool wxDC::DoGetPixel(wxCoord x
, wxCoord y
, wxColour
*col
) const
342 wxCHECK_MSG( col
, FALSE
, _T("NULL colour parameter in wxDC::GetPixel"));
345 m_MGLDC
->unpackColorFast(m_MGLDC
->getPixel(XLOG2DEV(x
), YLOG2DEV(y
)),
351 void wxDC::DoCrossHair(wxCoord x
, wxCoord y
)
353 wxCHECK_RET( Ok(), wxT("invalid dc") );
355 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
360 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
361 if ( !m_penSelected
)
363 wxCoord xx
= XLOG2DEV(x
);
364 wxCoord yy
= YLOG2DEV(y
);
365 m_MGLDC
->line(m_penOfsX
, yy
+ m_penOfsY
, w
-1 + m_penOfsX
, yy
+ m_penOfsY
);
366 m_MGLDC
->line(xx
+ m_penOfsX
, m_penOfsY
, x
+ m_penOfsX
, h
-1 + m_penOfsY
);
367 CalcBoundingBox(0, 0);
368 CalcBoundingBox(w
, h
);
372 void wxDC::DoDrawLine(wxCoord x1
, wxCoord y1
, wxCoord x2
, wxCoord y2
)
374 wxCHECK_RET( Ok(), wxT("invalid dc") );
376 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
378 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
379 if ( !m_penSelected
)
381 m_MGLDC
->lineExt(XLOG2DEV(x1
) + m_penOfsX
, YLOG2DEV(y1
) + m_penOfsY
,
382 XLOG2DEV(x2
) + m_penOfsX
, YLOG2DEV(y2
) + m_penOfsY
,FALSE
);
383 CalcBoundingBox(x1
, y1
);
384 CalcBoundingBox(x2
, y2
);
388 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
389 // and ending at (x2, y2)
390 void wxDC::DoDrawArc(wxCoord x1
, wxCoord y1
,
391 wxCoord x2
, wxCoord y2
,
392 wxCoord xc
, wxCoord yc
)
394 wxCHECK_RET( Ok(), wxT("invalid dc") );
396 wxCoord xx1
= XLOG2DEV(x1
);
397 wxCoord yy1
= YLOG2DEV(y1
);
398 wxCoord xx2
= XLOG2DEV(x2
);
399 wxCoord yy2
= YLOG2DEV(y2
);
400 wxCoord xxc
= XLOG2DEV(xc
);
401 wxCoord yyc
= YLOG2DEV(yc
);
402 double dx
= xx1
- xxc
;
403 double dy
= yy1
- yyc
;
404 double radius
= sqrt((double)(dx
*dx
+dy
*dy
));
405 wxCoord r
= (wxCoord
)radius
;
406 double radius1
, radius2
;
409 if (xx1
== xx2
&& yy1
== yy2
)
414 else if (radius
== 0.0)
416 radius1
= radius2
= 0.0;
420 radius1
= (xx1
- xxc
== 0) ?
421 (yy1
- yyc
< 0) ? 90.0 : -90.0 :
422 -atan2(double(yy1
-yyc
), double(xx1
-xxc
)) * RAD2DEG
;
423 radius2
= (xx2
- xxc
== 0) ?
424 (yy2
- yyc
< 0) ? 90.0 : -90.0 :
425 -atan2(double(yy2
-yyc
), double(xx2
-xxc
)) * RAD2DEG
;
427 wxCoord alpha1
= wxCoord(radius1
);
428 wxCoord alpha2
= alpha1
+ wxCoord(radius2
- radius1
);
429 while (alpha2
<= 0) alpha2
+= 360;
430 while (alpha1
> 360) alpha1
-= 360;
432 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
433 if ( m_brush
.GetStyle() != wxTRANSPARENT
)
435 if ( !m_brushSelected
)
437 m_MGLDC
->fillEllipseArc(xxc
, yyc
, r
, r
, alpha1
, alpha2
);
440 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
442 if ( !m_penSelected
)
444 m_MGLDC
->ellipseArc(xxc
+ m_penOfsX
, yyc
+ m_penOfsY
, r
, r
, alpha1
, alpha2
);
447 CalcBoundingBox(xc
- r
, yc
- r
);
448 CalcBoundingBox(xc
+ r
, yc
+ r
);
451 void wxDC::DoDrawPoint(wxCoord x
, wxCoord y
)
453 wxCHECK_RET( Ok(), wxT("invalid dc") );
455 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
457 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
458 if ( !m_penSelected
)
460 m_MGLDC
->pixel(XLOG2DEV(x
), YLOG2DEV(y
));
461 CalcBoundingBox(x
, y
);
465 void wxDC::DoDrawPolygon(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
,int fillStyle
)
467 wxCHECK_RET( Ok(), wxT("invalid dc") );
469 wxCoord xxoffset
= XLOG2DEVREL(xoffset
),
470 yyoffset
= YLOG2DEVREL(yoffset
);
471 MGLPoint
*cpoints
= new MGLPoint
[n
+1];
472 for (int i
= 0; i
< n
; i
++)
474 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
475 cpoints
[i
].x
= (int)(XLOG2DEV(points
[i
].x
));
476 cpoints
[i
].y
= (int)(YLOG2DEV(points
[i
].y
));
478 cpoints
[n
] = cpoints
[0];
480 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
481 if ( m_brush
.GetStyle() != wxTRANSPARENT
)
483 if ( !m_brushSelected
)
485 m_MGLDC
->fillPolygon(n
, cpoints
, xxoffset
, yyoffset
);
488 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
490 if ( !m_penSelected
)
492 if (m_penOfsX
!= 0 || m_penOfsY
!= 0)
494 for (int i
= 0; i
<= n
; i
++)
496 cpoints
[i
].x
+= m_penOfsX
;
497 cpoints
[i
].y
+= m_penOfsY
;
500 m_MGLDC
->polyLine(n
+1, cpoints
);
506 void wxDC::DoDrawLines(int n
, wxPoint points
[], wxCoord xoffset
, wxCoord yoffset
)
508 wxCHECK_RET( Ok(), wxT("invalid dc") );
510 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
512 MGLPoint
*cpoints
= new MGLPoint
[n
];
513 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
514 if ( !m_penSelected
)
516 for (int i
= 0; i
< n
; i
++)
518 CalcBoundingBox(points
[i
].x
+ xoffset
, points
[i
].y
+ yoffset
);
519 cpoints
[i
].x
= (int)(XLOG2DEV(points
[i
].x
+ xoffset
) /*+ m_penOfsX*/);
520 cpoints
[i
].y
= (int)(YLOG2DEV(points
[i
].y
+ yoffset
) /*+ m_penOfsY*/);
522 m_MGLDC
->polyLine(n
, cpoints
);
527 void wxDC::DoDrawRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
529 wxCHECK_RET( Ok(), wxT("invalid dc") );
531 wxCoord xx
= XLOG2DEV(x
);
532 wxCoord yy
= YLOG2DEV(y
);
533 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
534 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
536 if ( ww
== 0 || hh
== 0 ) return;
549 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
550 if ( m_brush
.GetStyle() != wxTRANSPARENT
)
552 if ( !m_brushSelected
)
554 m_MGLDC
->fillRect(xx
, yy
, xx
+ ww
, yy
+ hh
);
557 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
559 if ( !m_penSelected
)
562 m_MGLDC
->rect(xx
+ m_penOfsX
, yy
+ m_penOfsY
,
563 xx
+ ww
+ m_penOfsX
, yy
+ hh
+ m_penOfsY
);
566 CalcBoundingBox(x
, y
);
567 CalcBoundingBox(x
+ width
, y
+ height
);
570 void wxDC::DoDrawRoundedRectangle(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
, double radius
)
572 wxCHECK_RET( Ok(), wxT("invalid dc") );
575 radius
= -radius
* ((width
< height
) ? width
: height
);
577 wxCoord xx
= XLOG2DEV(x
);
578 wxCoord yy
= YLOG2DEV(y
);
579 wxCoord ww
= m_signX
* XLOG2DEVREL(width
);
580 wxCoord hh
= m_signY
* YLOG2DEVREL(height
);
581 wxCoord rr
= XLOG2DEVREL((wxCoord
)radius
);
583 // CMB: handle -ve width and/or height
595 // CMB: if radius is zero use DrawRectangle() instead to avoid
596 // X drawing errors with small radii
599 DrawRectangle(x
, y
, width
, height
);
603 // CMB: draw nothing if transformed w or h is 0
604 if ( ww
== 0 || hh
== 0 ) return;
606 // CMB: ensure dd is not larger than rectangle otherwise we
607 // get an hour glass shape
609 if ( dd
> ww
) dd
= ww
;
610 if ( dd
> hh
) dd
= hh
;
613 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
614 if ( m_brush
.GetStyle() != wxTRANSPARENT
)
616 if (!m_brushSelected
)
618 m_MGLDC
->fillRect(xx
+rr
, yy
, xx
+ww
-rr
, yy
+hh
);
619 m_MGLDC
->fillRect(xx
, yy
+rr
, xx
+ww
, yy
+hh
-rr
);
620 m_MGLDC
->fillEllipseArc(xx
+rr
, yy
+rr
, rr
, rr
, 90, 180);
621 m_MGLDC
->fillEllipseArc(xx
+ww
-rr
, yy
+rr
, rr
, rr
, 0, 90);
622 m_MGLDC
->fillEllipseArc(xx
+rr
, yy
+hh
-rr
, rr
, rr
, 180, 270);
623 m_MGLDC
->fillEllipseArc(xx
+ww
-rr
, yy
+hh
-rr
, rr
, rr
, 270, 0);
626 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
628 if ( !m_penSelected
)
632 m_MGLDC
->line(xx
+rr
+1, yy
, xx
+ww
-rr
, yy
);
633 m_MGLDC
->ellipseArc(xx
+ww
-rr
, yy
+rr
, rr
, rr
, 0, 90);
634 m_MGLDC
->line(xx
+ww
, yy
+rr
+1, xx
+ww
, yy
+hh
-rr
);
635 m_MGLDC
->ellipseArc(xx
+ww
-rr
, yy
+hh
-rr
, rr
, rr
, 270, 0);
636 m_MGLDC
->line(xx
+ww
-rr
, yy
+hh
, xx
+rr
+1, yy
+hh
);
637 m_MGLDC
->ellipseArc(xx
+rr
, yy
+hh
-rr
, rr
, rr
, 180, 270);
638 m_MGLDC
->line(xx
, yy
+hh
-rr
, xx
, yy
+rr
+1);
639 m_MGLDC
->ellipseArc(xx
+rr
, yy
+rr
, rr
, rr
, 90, 180);
642 CalcBoundingBox(x
, y
);
643 CalcBoundingBox(x
+ width
, y
+ height
);
646 void wxDC::DoDrawEllipse(wxCoord x
, wxCoord y
, wxCoord width
, wxCoord height
)
648 wxCHECK_RET( Ok(), wxT("invalid dc") );
650 wxCoord x2
= (x
+width
);
651 wxCoord y2
= (y
+height
);
653 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
654 if ( m_brush
.GetStyle() != wxTRANSPARENT
)
656 if ( !m_brushSelected
)
658 MGLRect
rect(XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
659 m_MGLDC
->fillEllipse(rect
);
662 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
664 if ( !m_penSelected
)
666 MGLRect
rect(XLOG2DEV(x
) + m_penOfsX
, YLOG2DEV(y
) + m_penOfsY
,
667 XLOG2DEV(x2
) + m_penOfsX
, YLOG2DEV(y2
) + m_penOfsY
);
668 m_MGLDC
->ellipse(rect
);
671 CalcBoundingBox(x
, y
);
672 CalcBoundingBox(x2
, y2
);
675 void wxDC::DoDrawEllipticArc(wxCoord x
,wxCoord y
,wxCoord w
,wxCoord h
,double sa
,double ea
)
677 wxCHECK_RET( Ok(), wxT("invalid dc") );
682 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
683 if ( m_brush
.GetStyle() != wxTRANSPARENT
)
685 if (!m_brushSelected
) SelectBrush();
686 MGLRect
rect(XLOG2DEV(x
), YLOG2DEV(y
), XLOG2DEV(x2
), YLOG2DEV(y2
));
687 m_MGLDC
->fillEllipseArc(rect
, (int)sa
, (int)ea
);
690 if ( m_pen
.GetStyle() != wxTRANSPARENT
)
692 if ( !m_penSelected
)
694 MGLRect
rect(XLOG2DEV(x
) + m_penOfsX
, YLOG2DEV(y
) + m_penOfsY
,
695 XLOG2DEV(x2
) + m_penOfsX
, YLOG2DEV(y2
) + m_penOfsY
);
696 m_MGLDC
->ellipseArc(rect
, (int)sa
, (int)ea
);
699 CalcBoundingBox(x
, y
);
700 CalcBoundingBox(x2
, y2
);
703 void wxDC::DoDrawText(const wxString
& text
, wxCoord x
, wxCoord y
)
705 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
706 DrawAnyText(text
, x
, y
);
708 // update the bounding box
710 CalcBoundingBox(x
, y
);
711 GetTextExtent(text
, &w
, &h
);
712 CalcBoundingBox(x
+ w
, y
+ h
);
715 bool wxDC::SelectMGLFont()
717 if ( m_mglFont
== NULL
)
719 float scale
= m_scaleY
;
720 bool antialiased
= (GetDepth() > 8);
722 m_mglFont
= m_font
.GetMGLfont_t(scale
, antialiased
);
723 wxCHECK_MSG( m_mglFont
, FALSE
, wxT("invalid font") );
725 m_MGLDC
->useFont(m_mglFont
);
726 wxLogTrace("mgl_font", "useFont(%p)", m_mglFont
);
729 wxNativeEncodingInfo nativeEnc
;
730 wxFontEncoding encoding
= m_font
.GetEncoding();
731 if ( !wxGetNativeFontEncoding(encoding
, &nativeEnc
) ||
732 !wxTestFontEncoding(nativeEnc
) )
735 if ( !wxTheFontMapper
->GetAltForEncoding(encoding
, &nativeEnc
) )
738 nativeEnc
.mglEncoding
= MGL_ENCODING_ASCII
;
741 m_MGLDC
->setTextEncoding(nativeEnc
.mglEncoding
);
747 void wxDC::DrawAnyText(const wxString
& text
, wxCoord x
, wxCoord y
)
749 wxCHECK_RET( Ok(), wxT("invalid dc") );
754 wxCoord xx
= XLOG2DEV(x
);
755 wxCoord yy
= YLOG2DEV(y
);
757 m_MGLDC
->setLineStyle(MGL_LINE_STIPPLE
);
758 m_MGLDC
->setLineStipple(0xFFFF);
759 m_MGLDC
->setPenSize(1, 1);
760 m_MGLDC
->setPenStyle(MGL_BITMAP_SOLID
);
763 const wchar_t *c_text
= text
.c_str();
765 const char *c_text
= text
.c_str();
769 // FIXME_MGL - this is a temporary hack in absence of proper
770 // implementation of solid text background in MGL. Once
771 // the bug in MGL is fixed, this code should be nuked
772 // immediately. Note that the code is not 100% correct;
773 // it only works with wxCOPY logical function
774 if ( m_backgroundMode
== wxSOLID
)
776 int w
= m_MGLDC
->textWidth(c_text
);
777 int h
= m_MGLDC
->textHeight();
778 m_MGLDC
->setColor(m_MGLDC
->packColorFast(m_textBackgroundColour
.Red(),
779 m_textBackgroundColour
.Green(), m_textBackgroundColour
.Blue()));
780 m_MGLDC
->fillRect(xx
, yy
, xx
+w
, yy
+h
);
784 m_MGLDC
->setColor(m_MGLDC
->packColorFast(m_textForegroundColour
.Red(),
785 m_textForegroundColour
.Green(), m_textForegroundColour
.Blue()));
786 m_MGLDC
->setBackColor(m_MGLDC
->packColorFast(m_textBackgroundColour
.Red(),
787 m_textBackgroundColour
.Green(), m_textBackgroundColour
.Blue()));
789 m_MGLDC
->drawStr(xx
, yy
, c_text
);
792 if ( m_font
.GetUnderlined() )
794 int x1
= xx
, y1
= yy
;
796 int w
= m_MGLDC
->textWidth(c_text
);
797 m_MGLDC
->underScoreLocation(x1
, y1
, c_text
);
798 switch (m_MGLDC
->getTextDirection())
800 case MGL_RIGHT_DIR
: x2
= x1
+ w
, y2
= y1
; break;
801 case MGL_LEFT_DIR
: x2
= x1
- w
, y2
= y1
; break;
802 case MGL_UP_DIR
: x2
= x1
, y2
= y1
- w
; break;
803 case MGL_DOWN_DIR
: x2
= x1
, y2
= y1
+ w
; break;
805 m_MGLDC
->line(x1
, y1
, x2
, y2
);
808 m_penSelected
= m_brushSelected
= FALSE
;
811 void wxDC::DoDrawRotatedText(const wxString
& text
,
812 wxCoord x
, wxCoord y
,
815 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
819 DoDrawText(text
, x
, y
);
822 else if ( angle
== 90.0 )
823 m_MGLDC
->setTextDirection(MGL_UP_DIR
);
824 else if ( angle
== 180.0 )
825 m_MGLDC
->setTextDirection(MGL_LEFT_DIR
);
826 else if ( angle
== 270.0 )
827 m_MGLDC
->setTextDirection(MGL_DOWN_DIR
);
830 // FIXME_MGL -- implement once MGL supports it
831 wxFAIL_MSG(wxT("wxMGL only supports rotated text with angle 0,90,180 or 270"));
835 DrawAnyText(text
, x
, y
);
838 m_MGLDC
->setTextDirection(MGL_RIGHT_DIR
);
841 // ---------------------------------------------------------------------------
843 // ---------------------------------------------------------------------------
845 void wxDC::SelectMGLStipplePen(int style
)
851 case wxDOT
: stipple
= STIPPLE_wxDOT
; break;
852 case wxLONG_DASH
: stipple
= STIPPLE_wxLONG_DASH
; break;
853 case wxSHORT_DASH
: stipple
= STIPPLE_wxSHORT_DASH
; break;
854 case wxDOT_DASH
: stipple
= STIPPLE_wxDOT_DASH
; break;
855 default: stipple
= STIPPLE_wxSOLID
; break;
858 m_MGLDC
->setLineStyle(MGL_LINE_STIPPLE
);
859 m_MGLDC
->setLineStipple(stipple
);
860 m_MGLDC
->setPenSize(1, 1);
861 m_MGLDC
->setPenStyle(MGL_BITMAP_SOLID
);
862 m_penOfsY
= m_penOfsX
= 0;
865 // Accepted valus of SelectMGLFatPen's 2nd argument
867 wxMGL_SELECT_FROM_PEN
,
868 wxMGL_SELECT_FROM_BRUSH
871 void wxDC::SelectMGLFatPen(int style
, int flag
)
873 MGL_penStyleType penstyle
;
874 const pattern_t
*pattern
= NULL
;
875 pixpattern24_t
*pixPattern
= NULL
;
879 // Since MGL pens may be created from wxBrush or wxPen and we often
880 // switch between pens and brushes, we take advantage of MGL's ability
881 // to have multiple (pix)pattern_t's loaded. We always download pen
882 // to 0th slot and brush to 1st slot.
883 if ( flag
== wxMGL_SELECT_FROM_PEN
)
888 // compute pen's width:
889 if ( m_pen
.GetWidth() <= 1 )
892 m_penOfsX
= m_penOfsY
= 0;
896 wx
= (int)(0.5 + fabs((double) XLOG2DEVREL(m_pen
.GetWidth())));
897 wy
= (int)(0.5 + fabs((double) YLOG2DEVREL(m_pen
.GetWidth())));
903 penstyle
= MGL_BITMAP_TRANSPARENT
;
906 case wxBDIAGONAL_HATCH
: pattern
= &PATTERN_wxBDIAGONAL_HATCH
;
907 penstyle
= MGL_BITMAP_TRANSPARENT
;
909 case wxCROSSDIAG_HATCH
: pattern
= &PATTERN_wxCROSSDIAG_HATCH
;
910 penstyle
= MGL_BITMAP_TRANSPARENT
;
912 case wxFDIAGONAL_HATCH
: pattern
= &PATTERN_wxFDIAGONAL_HATCH
;
913 penstyle
= MGL_BITMAP_TRANSPARENT
;
915 case wxCROSS_HATCH
: pattern
= &PATTERN_wxCROSS_HATCH
;
916 penstyle
= MGL_BITMAP_TRANSPARENT
;
918 case wxHORIZONTAL_HATCH
: pattern
= &PATTERN_wxHORIZONTAL_HATCH
;
919 penstyle
= MGL_BITMAP_TRANSPARENT
;
921 case wxVERTICAL_HATCH
: pattern
= &PATTERN_wxVERTICAL_HATCH
;
922 penstyle
= MGL_BITMAP_TRANSPARENT
;
926 if ( flag
== wxMGL_SELECT_FROM_PEN
)
927 pixPattern
= (pixpattern24_t
*) m_pen
.GetPixPattern();
929 pixPattern
= (pixpattern24_t
*) m_brush
.GetPixPattern();
930 penstyle
= MGL_PIXMAP
;
933 case wxSTIPPLE_MASK_OPAQUE
:
934 pattern
= (pattern_t
*) m_brush
.GetMaskPattern();
935 penstyle
= MGL_BITMAP_OPAQUE
;
940 penstyle
= MGL_BITMAP_SOLID
; break;
943 // ...and finally, pass the pen to MGL:
947 if ( !m_downloadedPatterns
[slot
] )
949 m_MGLDC
->setPenBitmapPattern(slot
, pattern
);
950 m_downloadedPatterns
[slot
] = TRUE
;
952 m_MGLDC
->usePenBitmapPattern(slot
);
957 if ( !m_downloadedPatterns
[slot
] )
965 for (y
= 0; y
< 8; y
++)
966 for (x
= 0; x
< 8; x
++)
967 pix
.b8
.p
[x
][y
] = m_MGLDC
->packColorFast(
968 pixPattern
->p
[x
][y
][0],
969 pixPattern
->p
[x
][y
][1],
970 pixPattern
->p
[x
][y
][2]);
974 for (y
= 0; y
< 8; y
++)
975 for (x
= 0; x
< 8; x
++)
976 pix
.b16
.p
[x
][y
] = m_MGLDC
->packColorFast(
977 pixPattern
->p
[x
][y
][0],
978 pixPattern
->p
[x
][y
][1],
979 pixPattern
->p
[x
][y
][2]);
982 for (y
= 0; y
< 8; y
++)
983 for (x
= 0; x
< 8; x
++)
984 for (c
= 0; c
< 3; c
++)
985 pix
.b24
.p
[x
][y
][c
] = pixPattern
->p
[x
][y
][c
];
988 for (y
= 0; y
< 8; y
++)
989 for (x
= 0; x
< 8; x
++)
990 pix
.b32
.p
[x
][y
] = m_MGLDC
->packColorFast(
991 pixPattern
->p
[x
][y
][0],
992 pixPattern
->p
[x
][y
][1],
993 pixPattern
->p
[x
][y
][2]);
996 wxFAIL_MSG(_T("invalid DC depth"));
999 m_MGLDC
->setPenPixmapPattern(slot
, &pix
);
1000 m_downloadedPatterns
[slot
] = TRUE
;
1002 m_MGLDC
->usePenPixmapPattern(slot
);
1005 m_MGLDC
->setLineStyle(MGL_LINE_PENSTYLE
);
1006 m_MGLDC
->setPenStyle(penstyle
);
1007 m_MGLDC
->setPenSize(wy
, wx
);
1010 void wxDC::SelectPen()
1012 wxCHECK_RET( Ok(), wxT("invalid dc") );
1014 wxColour
& clr
= m_pen
.GetColour();
1015 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
1016 m_MGLDC
->setColorRGB(clr
.Red(), clr
.Green(), clr
.Blue());
1018 switch (m_pen
.GetStyle())
1027 SelectMGLStipplePen(m_pen
.GetStyle());
1030 case wxBDIAGONAL_HATCH
:
1031 case wxCROSSDIAG_HATCH
:
1032 case wxFDIAGONAL_HATCH
:
1034 case wxHORIZONTAL_HATCH
:
1035 case wxVERTICAL_HATCH
:
1036 SelectMGLFatPen(m_pen
.GetStyle(), wxMGL_SELECT_FROM_PEN
);
1040 SelectMGLFatPen(m_pen
.GetStyle(), wxMGL_SELECT_FROM_PEN
);
1046 if ( m_pen
.GetWidth() <= 1 )
1047 SelectMGLStipplePen(wxSOLID
);
1049 SelectMGLFatPen(wxSOLID
, wxMGL_SELECT_FROM_PEN
);
1052 m_penSelected
= TRUE
;
1053 m_brushSelected
= FALSE
;
1056 void wxDC::SelectBrush()
1058 wxCHECK_RET( Ok(), wxT("invalid dc") );
1061 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
1063 if ( m_brush
.GetStyle() == wxSTIPPLE_MASK_OPAQUE
)
1065 fg
= m_textForegroundColour
;
1066 bg
= m_textBackgroundColour
;
1070 fg
= m_brush
.GetColour();
1071 bg
= m_backgroundBrush
.GetColour();
1074 m_MGLDC
->setColorRGB(fg
.Red(), fg
.Green(), fg
.Blue());
1075 m_MGLDC
->setBackColor(m_MGLDC
->packColorFast(bg
.Red(), bg
.Green(), bg
.Blue()));
1076 m_penSelected
= FALSE
;
1077 m_brushSelected
= TRUE
;
1079 SelectMGLFatPen(m_brush
.GetStyle(), wxMGL_SELECT_FROM_BRUSH
);
1082 void wxDC::SetPen(const wxPen
& pen
)
1084 if ( !pen
.Ok() ) return;
1085 if ( m_pen
== pen
) return;
1087 m_penSelected
= FALSE
;
1088 m_downloadedPatterns
[0] = FALSE
;
1091 void wxDC::SetBrush(const wxBrush
& brush
)
1093 if ( !brush
.Ok() ) return;
1094 if ( m_brush
== brush
) return;
1096 m_brushSelected
= FALSE
;
1097 m_downloadedPatterns
[1] = FALSE
;
1100 void wxDC::SetPalette(const wxPalette
& palette
)
1102 wxCHECK_RET( Ok(), wxT("invalid dc") );
1104 if ( palette
== wxNullPalette
)
1106 if ( m_oldPalette
.Ok() )
1107 SetPalette(m_oldPalette
);
1111 if ( !palette
.Ok() ) return;
1112 if ( m_palette
== palette
) return;
1113 m_oldPalette
= m_palette
;
1114 m_palette
= palette
;
1116 int cnt
= m_palette
.GetColoursCount();
1117 palette_t
*pal
= m_palette
.GetMGLpalette_t();
1118 m_MGLDC
->setPalette(pal
, cnt
, 0);
1119 m_MGLDC
->realizePalette(cnt
, 0, TRUE
);
1122 void wxDC::SetFont(const wxFont
& font
)
1131 void wxDC::SetBackground(const wxBrush
& brush
)
1133 wxCHECK_RET( Ok(), wxT("invalid dc") );
1135 if (!m_backgroundBrush
.Ok()) return;
1137 m_backgroundBrush
= brush
;
1138 wxColour
&clr
= m_backgroundBrush
.GetColour();
1139 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
1140 m_MGLDC
->setBackColor(
1141 m_MGLDC
->packColorFast(clr
.Red(), clr
.Green(), clr
.Blue()));
1144 void wxDC::SetBackgroundMode(int mode
)
1146 m_backgroundMode
= mode
;
1147 if ( mode
== wxSOLID
)
1148 m_MGLDC
->setBackMode(MGL_OPAQUE_BACKGROUND
);
1150 m_MGLDC
->setBackMode(MGL_TRANSPARENT_BACKGROUND
);
1153 void wxDC::SetLogicalFunction(int function
)
1155 wxCHECK_RET( Ok(), wxT("invalid dc") );
1157 m_logicalFunction
= function
;
1159 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
1160 m_MGLDC
->setWriteMode(LogicalFunctionToMGLRop(m_logicalFunction
));
1163 int wxDC::LogicalFunctionToMGLRop(int logFunc
) const
1165 MGL_writeModeType rop
;
1169 case wxCLEAR
: rop
= MGL_R2_BLACK
; break;
1170 case wxXOR
: rop
= MGL_R2_XORSRC
; break;
1171 case wxINVERT
: rop
= MGL_R2_NOT
; break;
1172 case wxOR_REVERSE
: rop
= MGL_R2_MERGESRCNOT
; break;
1173 case wxAND_REVERSE
: rop
= MGL_R2_MASKSRCNOT
; break;
1174 case wxCOPY
: rop
= MGL_R2_COPYSRC
; break;
1175 case wxAND
: rop
= MGL_R2_MASKSRC
; break;
1176 case wxAND_INVERT
: rop
= MGL_R2_MASKNOTSRC
; break;
1177 case wxNO_OP
: rop
= MGL_R2_NOP
; break;
1178 case wxNOR
: rop
= MGL_R2_NOTMERGESRC
; break;
1179 case wxEQUIV
: rop
= MGL_R2_NOTXORSRC
; break;
1180 case wxSRC_INVERT
: rop
= MGL_R2_NOTCOPYSRC
; break;
1181 case wxOR_INVERT
: rop
= MGL_R2_MERGENOTSRC
; break;
1182 case wxNAND
: rop
= MGL_R2_NOTMASKSRC
; break;
1183 case wxOR
: rop
= MGL_R2_MERGESRC
; break;
1184 case wxSET
: rop
= MGL_R2_WHITE
; break;
1186 wxFAIL_MSG( wxT("unsupported logical function") );
1187 return MGL_REPLACE_MODE
;
1192 bool wxDC::StartDoc(const wxString
& message
)
1194 // We might be previewing, so return TRUE to let it continue.
1202 void wxDC::StartPage()
1206 void wxDC::EndPage()
1210 // ---------------------------------------------------------------------------
1212 // ---------------------------------------------------------------------------
1214 wxCoord
wxDC::GetCharHeight() const
1216 wxCurrentDCSwitcher
switcher(m_MGLDC
);
1217 if ( !wxConstCast(this, wxDC
)->SelectMGLFont() ) return -1;
1218 return YDEV2LOGREL(m_mglFont
->fontHeight
);
1221 wxCoord
wxDC::GetCharWidth() const
1223 wxCurrentDCSwitcher
switcher(m_MGLDC
);
1224 if ( !wxConstCast(this, wxDC
)->SelectMGLFont() ) return -1;
1225 // VS: wxT() is intentional, charWidth() has both char and wchar_t version
1226 // VS: YDEV is corrent, it should *not* be XDEV, because font's are only
1227 // scaled according to m_scaleY
1228 return YDEV2LOGREL(m_mglFont
->fontWidth
);
1231 void wxDC::DoGetTextExtent(const wxString
& string
, wxCoord
*x
, wxCoord
*y
,
1232 wxCoord
*descent
, wxCoord
*externalLeading
,
1233 wxFont
*theFont
) const
1237 if ( theFont
!= NULL
)
1240 wxConstCast(this, wxDC
)->SetFont(*theFont
);
1243 wxCurrentDCSwitcher
switcher(m_MGLDC
);
1244 if ( !wxConstCast(this, wxDC
)->SelectMGLFont() ) return;
1247 // VS: YDEV is corrent, it should *not* be XDEV, because font's are
1248 // only scaled according to m_scaleY
1249 *x
= YDEV2LOGREL(m_MGLDC
->textWidth(string
.c_str()));
1251 *y
= YDEV2LOGREL(m_MGLDC
->textHeight());
1253 *descent
= YDEV2LOGREL(m_mglFont
->descent
);
1254 if ( externalLeading
)
1255 *externalLeading
= YDEV2LOGREL(m_mglFont
->leading
);
1257 if ( theFont
!= NULL
)
1258 wxConstCast(this, wxDC
)->SetFont(oldFont
);
1263 // ---------------------------------------------------------------------------
1265 // ---------------------------------------------------------------------------
1267 void wxDC::ComputeScaleAndOrigin()
1269 double newX
= m_logicalScaleX
* m_userScaleX
;
1270 double newY
= m_logicalScaleY
* m_userScaleY
;
1272 // make sure font will be reloaded before drawing:
1273 if ( newY
!= m_scaleY
)
1275 // make sure m_penOfs{X,Y} will be reevaluated before drawing:
1276 if ( newY
!= m_scaleY
|| newX
!= m_scaleX
)
1277 m_penSelected
= FALSE
;
1279 m_scaleX
= newX
, m_scaleY
= newY
;
1282 void wxDC::SetMapMode(int mode
)
1287 SetLogicalScale(twips2mm
*m_mm_to_pix_x
, twips2mm
*m_mm_to_pix_y
);
1290 SetLogicalScale(pt2mm
*m_mm_to_pix_x
, pt2mm
*m_mm_to_pix_y
);
1293 SetLogicalScale(m_mm_to_pix_x
, m_mm_to_pix_y
);
1296 SetLogicalScale(m_mm_to_pix_x
/10.0, m_mm_to_pix_y
/10.0);
1300 SetLogicalScale(1.0, 1.0);
1303 m_mappingMode
= mode
;
1306 void wxDC::SetUserScale( double x
, double y
)
1308 // allow negative ? -> no
1311 ComputeScaleAndOrigin();
1314 void wxDC::SetLogicalScale( double x
, double y
)
1317 m_logicalScaleX
= x
;
1318 m_logicalScaleY
= y
;
1319 ComputeScaleAndOrigin();
1322 void wxDC::SetLogicalOrigin( wxCoord x
, wxCoord y
)
1324 m_logicalOriginX
= x
* m_signX
; // is this still correct ?
1325 m_logicalOriginY
= y
* m_signY
;
1326 ComputeScaleAndOrigin();
1329 void wxDC::SetDeviceOrigin( wxCoord x
, wxCoord y
)
1331 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
1332 m_deviceOriginX
= x
;
1333 m_deviceOriginY
= y
;
1334 ComputeScaleAndOrigin();
1337 void wxDC::SetAxisOrientation( bool xLeftRight
, bool yBottomUp
)
1339 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
1340 m_signX
= (xLeftRight
? 1 : -1);
1341 m_signY
= (yBottomUp
? -1 : 1);
1342 ComputeScaleAndOrigin();
1345 // ---------------------------------------------------------------------------
1346 // coordinates transformations
1347 // ---------------------------------------------------------------------------
1349 wxCoord
wxDCBase::DeviceToLogicalX(wxCoord x
) const
1351 return ((wxDC
*)this)->XDEV2LOG(x
);
1354 wxCoord
wxDCBase::DeviceToLogicalY(wxCoord y
) const
1356 return ((wxDC
*)this)->YDEV2LOG(y
);
1359 wxCoord
wxDCBase::DeviceToLogicalXRel(wxCoord x
) const
1361 return ((wxDC
*)this)->XDEV2LOGREL(x
);
1364 wxCoord
wxDCBase::DeviceToLogicalYRel(wxCoord y
) const
1366 return ((wxDC
*)this)->YDEV2LOGREL(y
);
1369 wxCoord
wxDCBase::LogicalToDeviceX(wxCoord x
) const
1371 return ((wxDC
*)this)->XLOG2DEV(x
);
1374 wxCoord
wxDCBase::LogicalToDeviceY(wxCoord y
) const
1376 return ((wxDC
*)this)->YLOG2DEV(y
);
1379 wxCoord
wxDCBase::LogicalToDeviceXRel(wxCoord x
) const
1381 return ((wxDC
*)this)->XLOG2DEVREL(x
);
1384 wxCoord
wxDCBase::LogicalToDeviceYRel(wxCoord y
) const
1386 return ((wxDC
*)this)->YLOG2DEVREL(y
);
1390 void wxDC::DoGetSize(int *w
, int *h
) const
1392 if (w
) *w
= m_MGLDC
->sizex()+1;
1393 if (h
) *h
= m_MGLDC
->sizey()+1;
1396 void wxDC::DoGetSizeMM(int *width
, int *height
) const
1401 if ( width
) *width
= int(double(w
) / (m_userScaleX
*m_mm_to_pix_x
));
1402 if ( height
) *height
= int(double(h
) / (m_userScaleY
*m_mm_to_pix_y
));
1405 wxSize
wxDC::GetPPI() const
1407 return wxSize(int(double(m_mm_to_pix_x
) * inches2mm
),
1408 int(double(m_mm_to_pix_y
) * inches2mm
));
1412 // ---------------------------------------------------------------------------
1414 // ---------------------------------------------------------------------------
1416 bool wxDC::DoBlit(wxCoord xdest
, wxCoord ydest
,
1417 wxCoord width
, wxCoord height
,
1418 wxDC
*source
, wxCoord xsrc
, wxCoord ysrc
,
1419 int rop
, bool useMask
,
1420 wxCoord xsrcMask
, wxCoord ysrcMask
)
1422 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid dc") );
1423 wxCHECK_MSG( source
, FALSE
, wxT("invalid source dc") );
1425 // transform the source DC coords to the device ones
1426 xsrc
= source
->LogicalToDeviceX(xsrc
);
1427 ysrc
= source
->LogicalToDeviceY(ysrc
);
1429 /* FIXME_MGL: use the mask origin when drawing transparently */
1430 if (xsrcMask
== -1 && ysrcMask
== -1)
1432 xsrcMask
= xsrc
; ysrcMask
= ysrc
;
1436 xsrcMask
= source
->LogicalToDeviceX(xsrcMask
);
1437 ysrcMask
= source
->LogicalToDeviceY(ysrcMask
);
1440 CalcBoundingBox(xdest
, ydest
);
1441 CalcBoundingBox(xdest
+ width
, ydest
+ height
);
1443 /* scale/translate size and position */
1444 wxCoord xx
= XLOG2DEV(xdest
);
1445 wxCoord yy
= YLOG2DEV(ydest
);
1446 wxCoord ww
= XLOG2DEVREL(width
);
1447 wxCoord hh
= YLOG2DEVREL(height
);
1449 if ( source
->m_isMemDC
)
1451 wxMemoryDC
*memDC
= (wxMemoryDC
*) source
;
1452 DoDrawSubBitmap(memDC
->GetSelectedObject(), xsrc
, ysrc
, ww
, hh
,
1453 xdest
, ydest
, rop
, useMask
);
1457 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
1458 m_MGLDC
->bitBlt(*source
->GetMGLDC(),
1459 xsrc
, ysrc
, xsrc
+ ww
, ysrc
+ hh
,
1460 xx
, yy
, LogicalFunctionToMGLRop(rop
));
1466 void wxDC::DoDrawBitmap(const wxBitmap
&bmp
, wxCoord x
, wxCoord y
, bool useMask
)
1468 wxCHECK_RET( Ok(), wxT("invalid dc") );
1469 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
1471 wxCoord w
= bmp
.GetWidth();
1472 wxCoord h
= bmp
.GetHeight();
1474 DoDrawSubBitmap(bmp
, 0, 0, w
, h
, x
, y
, m_logicalFunction
, useMask
);
1477 void wxDC::DoDrawIcon(const wxIcon
& icon
, wxCoord x
, wxCoord y
)
1479 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
1480 DoDrawBitmap((const wxBitmap
&)icon
, x
, y
, (bool)TRUE
);
1484 static inline void DoBitBlt(const wxBitmap
& src
, MGLDevCtx
*dst
,
1485 int sx
, int sy
, int sw
, int sh
,
1486 int dx
, int dy
, int dw
, int dh
,
1487 int rop
, bool useStretching
, bool putSection
)
1489 bitmap_t
*bmp
= src
.GetMGLbitmap_t();
1493 dst
->putBitmap(dx
, dy
, bmp
, rop
);
1495 dst
->putBitmapSection(sx
, sy
, sx
+ sw
, sy
+ sh
, dx
, dy
, bmp
, rop
);
1500 dst
->stretchBitmap(dx
, dy
, dx
+ dw
, dy
+ dh
, bmp
, rop
);
1502 dst
->stretchBitmapSection(sx
, sy
, sx
+ sw
, sy
+ sh
,
1503 dx
, dy
, dx
+ dw
, dy
+ dh
, bmp
, rop
);
1507 void wxDC::DoDrawSubBitmap(const wxBitmap
&bmp
,
1508 wxCoord x
, wxCoord y
, wxCoord w
, wxCoord h
,
1509 wxCoord destx
, wxCoord desty
, int rop
, bool useMask
)
1511 wxCHECK_RET( Ok(), wxT("invalid dc") );
1512 wxCHECK_RET( bmp
.Ok(), wxT("invalid bitmap") );
1514 CalcBoundingBox(x
, y
);
1515 CalcBoundingBox(x
+ w
, y
+ h
);
1517 wxCoord dx
= XLOG2DEV(destx
);
1518 wxCoord dy
= YLOG2DEV(desty
);
1519 wxCoord dw
= XLOG2DEVREL(w
);
1520 wxCoord dh
= YLOG2DEVREL(h
);
1522 m_MGLDC
->makeCurrent(); // will go away with MGL6.0
1524 bool useStretching
= ((w
!= dw
) || (h
!= dh
));
1525 bool putSection
= (w
!= bmp
.GetWidth() || h
!= bmp
.GetHeight());
1526 MGL_writeModeType mglRop
= (MGL_writeModeType
)LogicalFunctionToMGLRop(rop
);
1528 if ( bmp
.GetDepth() == 1 )
1530 // Mono bitmaps are handled in special way -- all 1s are drawn in
1531 // foreground colours, all 0s in background colour.
1533 ((wxBitmap
&)bmp
).SetMonoPalette(m_textForegroundColour
, m_textBackgroundColour
);
1536 if ( useMask
&& bmp
.GetMask() )
1538 // Since MGL does not support masks directly (in MGL, mask is handled
1539 // in same way as in wxImage, i.e. there is one "key" color), we
1540 // simulate masked bitblt in 6 steps (same as in MSW):
1542 // 1. Create a temporary bitmap and copy the destination area into it.
1543 // 2. Copy the source area into the temporary bitmap using the
1544 // specified logical function.
1545 // 3. Set the masked area in the temporary bitmap to BLACK by ANDing
1546 // the mask bitmap with the temp bitmap with the foreground colour
1547 // set to WHITE and the bg colour set to BLACK.
1548 // 4. Set the unmasked area in the destination area to BLACK by
1549 // ANDing the mask bitmap with the destination area with the
1550 // foreground colour set to BLACK and the background colour set
1552 // 5. OR the temporary bitmap with the destination area.
1553 // 6. Delete the temporary bitmap.
1555 // This sequence of operations ensures that the source's transparent
1556 // area need not be black, and logical functions are supported.
1558 wxBitmap
*mask
= bmp
.GetMask()->GetBitmap();
1562 if ( GetDepth() <= 8 )
1564 temp
= new MGLMemoryDC(dw
, dh
, GetDepth(), NULL
);
1566 tempdc
.SetMGLDC(temp
, FALSE
);
1567 tempdc
.SetPalette(m_palette
);
1572 m_MGLDC
->getPixelFormat(pf
);
1573 temp
= new MGLMemoryDC(dw
, dh
, GetDepth(), &pf
);
1576 wxCHECK_RET( temp
->isValid(), wxT("cannot create temporary dc") );
1578 temp
->bitBlt(*m_MGLDC
, dx
, dy
, dx
+ dw
, dy
+ dh
, 0, 0, MGL_REPLACE_MODE
);
1580 DoBitBlt(bmp
, temp
, x
, y
, w
, h
, 0, 0, dw
, dh
, mglRop
,
1581 useStretching
, putSection
);
1583 mask
->SetMonoPalette(wxColour(0,0,0), wxColour(255,255,255));
1584 DoBitBlt(*mask
, temp
, x
, y
, w
, h
, 0, 0, dw
, dh
, MGL_R2_MASKSRC
,
1585 useStretching
, putSection
);
1586 DoBitBlt(*mask
, m_MGLDC
, x
, y
, w
, h
, dx
, dy
, dw
, dh
, MGL_R2_MASKNOTSRC
,
1587 useStretching
, putSection
);
1589 m_MGLDC
->bitBlt(*temp
, 0, 0, dw
, dh
, dx
, dy
, MGL_OR_MODE
);
1596 DoBitBlt(bmp
, m_MGLDC
, x
, y
, w
, h
, dx
, dy
, dw
, dh
, mglRop
,
1597 useStretching
, putSection
);