]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/dc.cpp
mdi fix
[wxWidgets.git] / src / dfb / dc.cpp
CommitLineData
b3c86150
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/dfb/dc.cpp
3// Purpose: wxDC class
4// Author: Vaclav Slavik
5// Created: 2006-08-07
6// RCS-ID: $Id$
7// Copyright: (c) 2006 REA Elektronik GmbH
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// ===========================================================================
12// declarations
13// ===========================================================================
14
15// ---------------------------------------------------------------------------
16// headers
17// ---------------------------------------------------------------------------
18
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#ifndef WX_PRECOMP
27 #include "wx/dc.h"
28 #include "wx/log.h"
29#endif
30
31#include "wx/dfb/private.h"
32
071f5576
VS
33// these values are used to initialize newly created DC
34#define DEFAULT_FONT (*wxNORMAL_FONT)
35#define DEFAULT_PEN (*wxBLACK_PEN)
36#define DEFAULT_BRUSH (*wxWHITE_BRUSH)
37
b3c86150
VS
38// ===========================================================================
39// implementation
40// ===========================================================================
41
42//-----------------------------------------------------------------------------
43// wxDC
44//-----------------------------------------------------------------------------
45
46IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase)
47
48// Default constructor
49wxDC::wxDC()
50{
51 m_ok = false;
52}
53
52c8d32a 54wxDC::wxDC(const wxIDirectFBSurfacePtr& surface)
b3c86150
VS
55{
56 Init(surface);
57}
58
52c8d32a 59void wxDC::Init(const wxIDirectFBSurfacePtr& surface)
b3c86150
VS
60{
61 m_ok = (surface != NULL);
62 wxCHECK_RET( surface != NULL, _T("invalid surface") );
63
64 m_surface = surface;
65
66 m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() /
67 (double)wxGetDisplaySizeMM().GetWidth();
68 m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() /
69 (double)wxGetDisplaySizeMM().GetHeight();
70
071f5576
VS
71 SetFont(DEFAULT_FONT);
72 SetPen(DEFAULT_PEN);
73 SetBrush(DEFAULT_BRUSH);
b3c86150
VS
74}
75
76
77// ---------------------------------------------------------------------------
78// clipping
79// ---------------------------------------------------------------------------
80
81
82#define DO_SET_CLIPPING_BOX(rg) \
83{ \
84 wxRect rect = rg.GetBox(); \
85 m_clipX1 = (wxCoord) XDEV2LOG(rect.GetLeft()); \
86 m_clipY1 = (wxCoord) YDEV2LOG(rect.GetTop()); \
87 m_clipX2 = (wxCoord) XDEV2LOG(rect.GetRight()); \
88 m_clipY2 = (wxCoord) YDEV2LOG(rect.GetBottom()); \
89}
90
91void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch)
92{
93 wxCHECK_RET( Ok(), wxT("invalid dc") );
94
564b429f
VS
95 wxSize size(GetSize());
96
97 // NB: We intersect the clipping rectangle with surface's area here because
98 // DirectFB will return an error if you try to set clipping rectangle
99 // that is partially outside of the surface.
b3c86150 100 DFBRegion r;
564b429f
VS
101 r.x1 = wxMax(0, XLOG2DEV(cx));
102 r.y1 = wxMax(0, YLOG2DEV(cy));
103 r.x2 = wxMin(r.x1 + XLOG2DEVREL(cw), size.x) - 1;
104 r.y2 = wxMin(r.y1 + YLOG2DEVREL(ch), size.y) - 1;
b3c86150 105
52c8d32a 106 if ( !m_surface->SetClip(&r) )
b3c86150
VS
107 return;
108
109 m_clipX1 = cx;
110 m_clipY1 = cy;
111 m_clipX2 = cx + cw - 1;
112 m_clipY2 = cy + ch -1;
113 m_clipping = true;
114}
115
116void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region)
117{
118 // NB: this can be done because wxDFB only supports
119 // rectangular regions
120 SetClippingRegion(region.AsRect());
121}
122
123void wxDC::DestroyClippingRegion()
124{
125 wxCHECK_RET( Ok(), wxT("invalid dc") );
126
52c8d32a 127 m_surface->SetClip(NULL);
b3c86150
VS
128
129 ResetClipping();
130}
131
132// ---------------------------------------------------------------------------
133// query capabilities
134// ---------------------------------------------------------------------------
135
136int wxDC::GetDepth() const
137{
a5b31f4e 138 return m_surface->GetDepth();
b3c86150
VS
139}
140
141// ---------------------------------------------------------------------------
142// drawing
143// ---------------------------------------------------------------------------
144
145void wxDC::Clear()
146{
147 wxCHECK_RET( Ok(), wxT("invalid dc") );
148
149 if ( m_backgroundBrush.GetStyle() == wxTRANSPARENT )
150 return;
151
152 wxColour clr = m_backgroundBrush.GetColour();
52c8d32a 153 m_surface->Clear(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha());
20671963
VS
154
155 wxSize size(GetSize());
156 CalcBoundingBox(XDEV2LOG(0), YDEV2LOG(0));
157 CalcBoundingBox(XDEV2LOG(size.x), YDEV2LOG(size.y));
b3c86150
VS
158}
159
160extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
161 const wxColour & col, int style);
162
163bool wxDC::DoFloodFill(wxCoord x, wxCoord y,
164 const wxColour& col, int style)
165{
166 return wxDoFloodFill(this, x, y, col, style);
167}
168
169bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
170{
171 wxCHECK_MSG( col, false, _T("NULL colour parameter in wxDC::GetPixel"));
172
173 wxFAIL_MSG( _T("GetPixel not implemented") );
174 return false;
175}
176
177void wxDC::DoCrossHair(wxCoord x, wxCoord y)
178{
179 wxCHECK_RET( Ok(), wxT("invalid dc") );
180
181 wxFAIL_MSG( _T("CrossHair not implemented") );
182}
183
184void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
185{
186 wxCHECK_RET( Ok(), wxT("invalid dc") );
187
188 if ( m_pen.GetStyle() == wxTRANSPARENT )
189 return;
190
52c8d32a
VS
191 m_surface->DrawLine(XLOG2DEV(x1), YLOG2DEV(y1),
192 XLOG2DEV(x2), YLOG2DEV(y2));
b3c86150
VS
193
194 CalcBoundingBox(x1, y1);
195 CalcBoundingBox(x2, y2);
196}
197
198// Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
199// and ending at (x2, y2)
200void wxDC::DoDrawArc(wxCoord x1, wxCoord y1,
201 wxCoord x2, wxCoord y2,
202 wxCoord xc, wxCoord yc)
203{
204 wxCHECK_RET( Ok(), wxT("invalid dc") );
205
206 wxFAIL_MSG( _T("DrawArc not implemented") );
207}
208
209void wxDC::DoDrawPoint(wxCoord x, wxCoord y)
210{
211 wxCHECK_RET( Ok(), wxT("invalid dc") );
212
3af4da32
VS
213 // NB: DirectFB API doesn't provide a function for drawing points, so
214 // implement it as 1px long line. This is inefficient, but then, so is
215 // using DrawPoint() for drawing more than a few points.
216 DoDrawLine(x, y, x, y);
217
218 // FIXME_DFB: implement special cases for common formats (RGB24,RGBA/RGB32)
b3c86150
VS
219}
220
221void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int WXUNUSED(fillStyle))
222{
223 wxCHECK_RET( Ok(), wxT("invalid dc") );
224
225 wxFAIL_MSG( _T("DrawPolygon not implemented") );
226}
227
228void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
229{
230 wxCHECK_RET( Ok(), wxT("invalid dc") );
231
232 // TODO: impl. using DirectDB's DrawLines
233 wxFAIL_MSG( _T("DrawLines not implemented") );
234}
235
236void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
237{
238 wxCHECK_RET( Ok(), wxT("invalid dc") );
239
240 wxCoord xx = XLOG2DEV(x);
241 wxCoord yy = YLOG2DEV(y);
242 wxCoord ww = m_signX * XLOG2DEVREL(width);
243 wxCoord hh = m_signY * YLOG2DEVREL(height);
244
245 if ( ww == 0 || hh == 0 ) return;
246
247 if ( ww < 0 )
248 {
249 ww = -ww;
250 xx = xx - ww;
251 }
252 if ( hh < 0 )
253 {
254 hh = -hh;
255 yy = yy - hh;
256 }
257
258 if ( m_brush.GetStyle() != wxTRANSPARENT )
259 {
260 SelectColour(m_brush.GetColour());
52c8d32a 261 m_surface->FillRectangle(xx, yy, ww, hh);
b3c86150
VS
262 // restore pen's colour
263 SelectColour(m_pen.GetColour());
264 }
265
266 if ( m_pen.GetStyle() != wxTRANSPARENT )
267 {
52c8d32a 268 m_surface->DrawRectangle(xx, yy, ww, hh);
b3c86150
VS
269 }
270
271 CalcBoundingBox(x, y);
272 CalcBoundingBox(x + width, y + height);
273}
274
275void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
276{
277 wxCHECK_RET( Ok(), wxT("invalid dc") );
278
279 wxFAIL_MSG( _T("DrawRoundedRectangle not implemented") );
280}
281
282void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
283{
284 wxCHECK_RET( Ok(), wxT("invalid dc") );
285
286 wxFAIL_MSG( _T("DrawElipse not implemented") );
287}
288
289void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
290{
291 wxCHECK_RET( Ok(), wxT("invalid dc") );
292
293 wxFAIL_MSG( _T("DrawElipticArc not implemented") );
294}
295
296void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
297{
298 wxCHECK_RET( Ok(), wxT("invalid dc") );
299
300 wxCoord xx = XLOG2DEV(x);
5034c9db 301 wxCoord yy = YLOG2DEV(y);
b3c86150
VS
302
303 // update the bounding box
304 wxCoord w, h;
305 CalcBoundingBox(x, y);
306 GetTextExtent(text, &w, &h);
307 CalcBoundingBox(x + w, y + h);
308
309 // if background mode is solid, DrawText must paint text's background:
310 if ( m_backgroundMode == wxSOLID )
311 {
312 wxCHECK_RET( m_backgroundBrush.Ok(), wxT("invalid background brush") );
313
314 SelectColour(m_backgroundBrush.GetColour());
52c8d32a 315 m_surface->FillRectangle(xx, yy, XLOG2DEVREL(w), YLOG2DEVREL(h));
b3c86150
VS
316 // restore pen's colour
317 SelectColour(m_pen.GetColour());
318 }
319
320 // finally draw the text itself:
52c8d32a 321 m_surface->DrawString(wxSTR_TO_DFB(text), -1, xx, yy, DSTF_LEFT | DSTF_TOP);
b3c86150
VS
322}
323
324void wxDC::DoDrawRotatedText(const wxString& text,
325 wxCoord x, wxCoord y,
326 double angle)
327{
328 wxCHECK_RET( Ok(), wxT("invalid dc") );
329
330 wxFAIL_MSG( _T("DrawRotatedText not implemented") );
331}
332
333// ---------------------------------------------------------------------------
334// set GDI objects
335// ---------------------------------------------------------------------------
336
337void wxDC::SetPen(const wxPen& pen)
338{
071f5576 339 m_pen = pen.Ok() ? pen : DEFAULT_PEN;
b3c86150
VS
340
341 SelectColour(m_pen.GetColour());
342}
343
344void wxDC::SetBrush(const wxBrush& brush)
345{
071f5576 346 m_brush = brush.Ok() ? brush : DEFAULT_BRUSH;
b3c86150
VS
347}
348
349void wxDC::SelectColour(const wxColour& clr)
350{
52c8d32a 351 m_surface->SetColor(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha());
b3c86150
VS
352 #warning "use SetColorIndex?"
353}
354
355#if wxUSE_PALETTE
356void wxDC::SetPalette(const wxPalette& WXUNUSED(palette))
357{
358 wxCHECK_RET( Ok(), wxT("invalid dc") );
359
360 wxFAIL_MSG( _T("SetPalette not implemented") );
361}
362#endif // wxUSE_PALETTE
363
364void wxDC::SetFont(const wxFont& font)
365{
366 wxCHECK_RET( Ok(), wxT("invalid dc") );
367
071f5576 368 wxFont f(font.Ok() ? font : DEFAULT_FONT);
b3c86150 369
071f5576 370 if ( !m_surface->SetFont(f.GetDirectFBFont()) )
b3c86150
VS
371 return;
372
071f5576 373 m_font = f;
b3c86150
VS
374}
375
376void wxDC::SetBackground(const wxBrush& brush)
377{
378 wxCHECK_RET( Ok(), wxT("invalid dc") );
379
380 if (!brush.Ok()) return;
381
382 m_backgroundBrush = brush;
383}
384
385void wxDC::SetBackgroundMode(int mode)
386{
387 m_backgroundMode = mode;
388}
389
390void wxDC::SetLogicalFunction(int function)
391{
392 wxCHECK_RET( Ok(), wxT("invalid dc") );
393
394 wxFAIL_MSG( _T("SetLogicalFunction not implemented") );
395
396 m_logicalFunction = function;
397}
398
399bool wxDC::StartDoc(const wxString& WXUNUSED(message))
400{
401 // We might be previewing, so return true to let it continue.
402 return true;
403}
404
405void wxDC::EndDoc()
406{
407}
408
409void wxDC::StartPage()
410{
411}
412
413void wxDC::EndPage()
414{
415}
416
417// ---------------------------------------------------------------------------
418// text metrics
419// ---------------------------------------------------------------------------
420
421wxCoord wxDC::GetCharHeight() const
422{
423 wxCHECK_MSG( Ok(), -1, wxT("invalid dc") );
424 wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") );
425
426 int h = -1;
52c8d32a 427 m_font.GetDirectFBFont()->GetHeight(&h);
b3c86150
VS
428 return YDEV2LOGREL(h);
429}
430
431wxCoord wxDC::GetCharWidth() const
432{
433 wxCHECK_MSG( Ok(), -1, wxT("invalid dc") );
434 wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") );
435
436 int w = -1;
52c8d32a 437 m_font.GetDirectFBFont()->GetStringWidth("H", 1, &w);
b3c86150
VS
438 // VS: YDEV is corrent, it should *not* be XDEV, because font's are only
439 // scaled according to m_scaleY
440 return YDEV2LOGREL(w);
441}
442
443void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
444 wxCoord *descent, wxCoord *externalLeading,
445 wxFont *theFont) const
446{
447 wxCHECK_RET( Ok(), wxT("invalid dc") );
448 wxCHECK_RET( m_font.Ok(), wxT("no font selected") );
449 wxCHECK_RET( !theFont || theFont->Ok(), wxT("invalid font") );
450
451 wxFont oldFont;
452 if ( theFont != NULL )
453 {
454 oldFont = m_font;
455 wxConstCast(this, wxDC)->SetFont(*theFont);
456 }
457
458 wxCoord xx = 0, yy = 0;
459 DFBRectangle rect;
52c8d32a 460 wxIDirectFBFontPtr f = m_font.GetDirectFBFont();
b3c86150 461
52c8d32a 462 if ( f->GetStringExtents(wxSTR_TO_DFB(string), -1, &rect, NULL) )
b3c86150
VS
463 {
464 // VS: YDEV is corrent, it should *not* be XDEV, because font's are
465 // only scaled according to m_scaleY
466 xx = YDEV2LOGREL(rect.w);
467 yy = YDEV2LOGREL(rect.h);
468
469 if ( descent )
470 {
471 int d;
52c8d32a 472 if ( f->GetDescender(&d) )
b3c86150
VS
473 *descent = YDEV2LOGREL(-d);
474 else
475 *descent = 0;
476 }
477 }
478
479 if ( x ) *x = xx;
480 if ( y ) *y = yy;
481 if ( externalLeading ) *externalLeading = 0;
482
483 if ( theFont != NULL )
484 wxConstCast(this, wxDC)->SetFont(oldFont);
485}
486
487
488
489// ---------------------------------------------------------------------------
490// mapping modes
491// ---------------------------------------------------------------------------
492
493void wxDC::ComputeScaleAndOrigin()
494{
495 m_scaleX = m_logicalScaleX * m_userScaleX;
496 m_scaleY = m_logicalScaleY * m_userScaleY;
497
498 // FIXME_DFB: scaling affects pixel size of font, pens, brushes, which
499 // is not currently implemented here; probably makes sense to
500 // switch to Cairo instead of implementing everything for DFB
501 wxASSERT_MSG( m_scaleX == 1.0 && m_scaleY == 1.0,
502 _T("scaling is not implemented in wxDFB") );
503}
504
505void wxDC::SetMapMode(int mode)
506{
507 #warning "move this to common code, it's shared by almost all ports!"
508 switch (mode)
509 {
510 case wxMM_TWIPS:
511 SetLogicalScale(twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y);
512 break;
513 case wxMM_POINTS:
514 SetLogicalScale(pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y);
515 break;
516 case wxMM_METRIC:
517 SetLogicalScale(m_mm_to_pix_x, m_mm_to_pix_y);
518 break;
519 case wxMM_LOMETRIC:
520 SetLogicalScale(m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0);
521 break;
522 default:
523 case wxMM_TEXT:
524 SetLogicalScale(1.0, 1.0);
525 break;
526 }
527 m_mappingMode = mode;
528}
529
530void wxDC::SetUserScale(double x, double y)
531{
532 #warning "move this to common code?"
533 // allow negative ? -> no
534 m_userScaleX = x;
535 m_userScaleY = y;
536 ComputeScaleAndOrigin();
537}
538
539void wxDC::SetLogicalScale(double x, double y)
540{
541 #warning "move this to common code?"
542 // allow negative ?
543 m_logicalScaleX = x;
544 m_logicalScaleY = y;
545 ComputeScaleAndOrigin();
546}
547
548void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
549{
550 #warning "move this to common code?"
551 m_logicalOriginX = x * m_signX; // is this still correct ?
552 m_logicalOriginY = y * m_signY;
553 ComputeScaleAndOrigin();
554}
555
556void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
557{
558 #warning "move this to common code?"
559 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
560 m_deviceOriginX = x;
561 m_deviceOriginY = y;
562 ComputeScaleAndOrigin();
563}
564
565void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
566{
567 #warning "move this to common code?"
568 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
569 m_signX = (xLeftRight ? 1 : -1);
570 m_signY = (yBottomUp ? -1 : 1);
571 ComputeScaleAndOrigin();
572}
573
574// ---------------------------------------------------------------------------
575// coordinates transformations
576// ---------------------------------------------------------------------------
577
578wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
579{
580 return ((wxDC *)this)->XDEV2LOG(x);
581}
582
583wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
584{
585 return ((wxDC *)this)->YDEV2LOG(y);
586}
587
588wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
589{
590 return ((wxDC *)this)->XDEV2LOGREL(x);
591}
592
593wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
594{
595 return ((wxDC *)this)->YDEV2LOGREL(y);
596}
597
598wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
599{
600 return ((wxDC *)this)->XLOG2DEV(x);
601}
602
603wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
604{
605 return ((wxDC *)this)->YLOG2DEV(y);
606}
607
608wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
609{
610 return ((wxDC *)this)->XLOG2DEVREL(x);
611}
612
613wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
614{
615 return ((wxDC *)this)->YLOG2DEVREL(y);
616}
617
618
619void wxDC::DoGetSize(int *w, int *h) const
620{
621 wxCHECK_RET( Ok(), wxT("invalid dc") );
622
52c8d32a 623 m_surface->GetSize(w, h);
b3c86150
VS
624}
625
626void wxDC::DoGetSizeMM(int *width, int *height) const
627{
628 #warning "move this to common code?"
629 int w = 0;
630 int h = 0;
631 GetSize(&w, &h);
632 if ( width ) *width = int(double(w) / (m_userScaleX*m_mm_to_pix_x));
633 if ( height ) *height = int(double(h) / (m_userScaleY*m_mm_to_pix_y));
634}
635
636wxSize wxDC::GetPPI() const
637{
638 #warning "move this to common code?"
639 return wxSize(int(double(m_mm_to_pix_x) * inches2mm),
640 int(double(m_mm_to_pix_y) * inches2mm));
641}
642
643
644// ---------------------------------------------------------------------------
645// Blitting
646// ---------------------------------------------------------------------------
647
648bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest,
649 wxCoord width, wxCoord height,
650 wxDC *source, wxCoord xsrc, wxCoord ysrc,
651 int rop, bool useMask,
652 wxCoord xsrcMask, wxCoord ysrcMask)
653{
654#warning "FIXME"
655 return false;
656#if 0
657 wxCHECK_MSG( Ok(), false, wxT("invalid dc") );
658 wxCHECK_MSG( source, false, wxT("invalid source dc") );
659
660 // transform the source DC coords to the device ones
661 xsrc = source->LogicalToDeviceX(xsrc);
662 ysrc = source->LogicalToDeviceY(ysrc);
663
664 /* FIXME_MGL: use the mask origin when drawing transparently */
665 if (xsrcMask == -1 && ysrcMask == -1)
666 {
667 xsrcMask = xsrc; ysrcMask = ysrc;
668 }
669 else
670 {
671 xsrcMask = source->LogicalToDeviceX(xsrcMask);
672 ysrcMask = source->LogicalToDeviceY(ysrcMask);
673 }
674
675 CalcBoundingBox(xdest, ydest);
676 CalcBoundingBox(xdest + width, ydest + height);
677
678 /* scale/translate size and position */
679 wxCoord xx = XLOG2DEV(xdest);
680 wxCoord yy = YLOG2DEV(ydest);
681 wxCoord ww = XLOG2DEVREL(width);
682 wxCoord hh = YLOG2DEVREL(height);
683
684 if ( source->m_isMemDC )
685 {
686 wxMemoryDC *memDC = (wxMemoryDC*) source;
687 DoDrawSubBitmap(memDC->GetSelectedObject(), xsrc, ysrc, ww, hh,
688 xdest, ydest, rop, useMask);
689 }
690 else
691 {
692 m_MGLDC->makeCurrent(); // will go away with MGL6.0
693 m_MGLDC->bitBlt(*source->GetMGLDC(),
694 xsrc, ysrc, xsrc + ww, ysrc + hh,
695 xx, yy, LogicalFunctionToMGLRop(rop));
696 }
697
698 return true;
699#endif
700}
701
702void wxDC::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask)
703{
704 wxCHECK_RET( Ok(), wxT("invalid dc") );
705 wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") );
706
707 wxCoord w = bmp.GetWidth();
708 wxCoord h = bmp.GetHeight();
709
710 DoDrawSubBitmap(bmp, 0, 0, w, h, x, y, m_logicalFunction, useMask);
711}
712
713void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
714{
715 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
716 DoDrawBitmap((const wxBitmap&)icon, x, y, true);
717}
718
719void wxDC::DoDrawSubBitmap(const wxBitmap &bmp,
720 wxCoord x, wxCoord y, wxCoord w, wxCoord h,
721 wxCoord destx, wxCoord desty, int rop, bool useMask)
722{
723#if 0
724 wxCHECK_RET( Ok(), wxT("invalid dc") );
725 wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") );
726
727 CalcBoundingBox(x, y);
728 CalcBoundingBox(x + w, y + h);
729
730 wxCoord dx = XLOG2DEV(destx);
731 wxCoord dy = YLOG2DEV(desty);
732 wxCoord dw = XLOG2DEVREL(w);
733 wxCoord dh = YLOG2DEVREL(h);
734
735 m_MGLDC->makeCurrent(); // will go away with MGL6.0
736
737 bool useStretching = ((w != dw) || (h != dh));
738 bool putSection = (w != bmp.GetWidth() || h != bmp.GetHeight());
739 MGL_writeModeType mglRop = (MGL_writeModeType)LogicalFunctionToMGLRop(rop);
740
741 if ( bmp.GetDepth() == 1 )
742 {
743 // Mono bitmaps are handled in special way -- all 1s are drawn in
744 // foreground colours, all 0s in background colour.
745
746 ((wxBitmap&)bmp).SetMonoPalette(m_textForegroundColour, m_textBackgroundColour);
747 }
748
749 if ( useMask && bmp.GetMask() )
750 {
751 // Since MGL does not support masks directly (in MGL, mask is handled
752 // in same way as in wxImage, i.e. there is one "key" color), we
753 // simulate masked bitblt in 6 steps (same as in MSW):
754 //
755 // 1. Create a temporary bitmap and copy the destination area into it.
756 // 2. Copy the source area into the temporary bitmap using the
757 // specified logical function.
758 // 3. Set the masked area in the temporary bitmap to BLACK by ANDing
759 // the mask bitmap with the temp bitmap with the foreground colour
760 // set to WHITE and the bg colour set to BLACK.
761 // 4. Set the unmasked area in the destination area to BLACK by
762 // ANDing the mask bitmap with the destination area with the
763 // foreground colour set to BLACK and the background colour set
764 // to WHITE.
765 // 5. OR the temporary bitmap with the destination area.
766 // 6. Delete the temporary bitmap.
767 //
768 // This sequence of operations ensures that the source's transparent
769 // area need not be black, and logical functions are supported.
770
771 wxBitmap *mask = bmp.GetMask()->GetBitmap();
772
773 MGLMemoryDC *temp;
774
775 if ( GetDepth() <= 8 )
776 {
777 temp = new MGLMemoryDC(dw, dh, GetDepth(), NULL);
778 wxDC tempdc;
779 tempdc.SetMGLDC(temp, false);
780 tempdc.SetPalette(m_palette);
781 }
782 else
783 {
784 pixel_format_t pf;
785 m_MGLDC->getPixelFormat(pf);
786 temp = new MGLMemoryDC(dw, dh, GetDepth(), &pf);
787 }
788
789 wxCHECK_RET( temp->isValid(), wxT("cannot create temporary dc") );
790
791 temp->bitBlt(*m_MGLDC, dx, dy, dx + dw, dy + dh, 0, 0, MGL_REPLACE_MODE);
792
793 DoBitBlt(bmp, temp, x, y, w, h, 0, 0, dw, dh, mglRop,
794 useStretching, putSection);
795
796 mask->SetMonoPalette(wxColour(0,0,0), wxColour(255,255,255));
797 DoBitBlt(*mask, temp, x, y, w, h, 0, 0, dw, dh, MGL_R2_MASKSRC,
798 useStretching, putSection);
799 DoBitBlt(*mask, m_MGLDC, x, y, w, h, dx, dy, dw, dh, MGL_R2_MASKNOTSRC,
800 useStretching, putSection);
801
802 m_MGLDC->bitBlt(*temp, 0, 0, dw, dh, dx, dy, MGL_OR_MODE);
803
804 delete temp;
805 }
806
807 else
808 {
809 DoBitBlt(bmp, m_MGLDC, x, y, w, h, dx, dy, dw, dh, mglRop,
810 useStretching, putSection);
811 }
812#endif
813}