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