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