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