basic blitting implementation
[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 // 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
38 // ===========================================================================
39 // implementation
40 // ===========================================================================
41
42 //-----------------------------------------------------------------------------
43 // wxDC
44 //-----------------------------------------------------------------------------
45
46 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase)
47
48 // Default constructor
49 wxDC::wxDC()
50 {
51 m_ok = false;
52 }
53
54 wxDC::wxDC(const wxIDirectFBSurfacePtr& surface)
55 {
56 Init(surface);
57 }
58
59 void wxDC::Init(const wxIDirectFBSurfacePtr& surface)
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
71 SetFont(DEFAULT_FONT);
72 SetPen(DEFAULT_PEN);
73 SetBrush(DEFAULT_BRUSH);
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
91 void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch)
92 {
93 wxCHECK_RET( Ok(), wxT("invalid dc") );
94
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.
100 DFBRegion r;
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;
105
106 if ( !m_surface->SetClip(&r) )
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
116 void 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
123 void wxDC::DestroyClippingRegion()
124 {
125 wxCHECK_RET( Ok(), wxT("invalid dc") );
126
127 m_surface->SetClip(NULL);
128
129 ResetClipping();
130 }
131
132 // ---------------------------------------------------------------------------
133 // query capabilities
134 // ---------------------------------------------------------------------------
135
136 int wxDC::GetDepth() const
137 {
138 return m_surface->GetDepth();
139 }
140
141 // ---------------------------------------------------------------------------
142 // drawing
143 // ---------------------------------------------------------------------------
144
145 void 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();
153 m_surface->Clear(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha());
154
155 wxSize size(GetSize());
156 CalcBoundingBox(XDEV2LOG(0), YDEV2LOG(0));
157 CalcBoundingBox(XDEV2LOG(size.x), YDEV2LOG(size.y));
158 }
159
160 extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
161 const wxColour & col, int style);
162
163 bool wxDC::DoFloodFill(wxCoord x, wxCoord y,
164 const wxColour& col, int style)
165 {
166 return wxDoFloodFill(this, x, y, col, style);
167 }
168
169 bool 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
177 void wxDC::DoCrossHair(wxCoord x, wxCoord y)
178 {
179 wxCHECK_RET( Ok(), wxT("invalid dc") );
180
181 wxFAIL_MSG( _T("CrossHair not implemented") );
182 }
183
184 void 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
191 m_surface->DrawLine(XLOG2DEV(x1), YLOG2DEV(y1),
192 XLOG2DEV(x2), YLOG2DEV(y2));
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)
200 void 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
209 void wxDC::DoDrawPoint(wxCoord x, wxCoord y)
210 {
211 wxCHECK_RET( Ok(), wxT("invalid dc") );
212
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)
219 }
220
221 void 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
228 void 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
236 void 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());
261 m_surface->FillRectangle(xx, yy, ww, hh);
262 // restore pen's colour
263 SelectColour(m_pen.GetColour());
264 }
265
266 if ( m_pen.GetStyle() != wxTRANSPARENT )
267 {
268 m_surface->DrawRectangle(xx, yy, ww, hh);
269 }
270
271 CalcBoundingBox(x, y);
272 CalcBoundingBox(x + width, y + height);
273 }
274
275 void 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
282 void 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
289 void 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
296 void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
297 {
298 wxCHECK_RET( Ok(), wxT("invalid dc") );
299
300 wxCoord xx = XLOG2DEV(x);
301 wxCoord yy = YLOG2DEV(y);
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());
315 m_surface->FillRectangle(xx, yy, XLOG2DEVREL(w), YLOG2DEVREL(h));
316 // restore pen's colour
317 SelectColour(m_pen.GetColour());
318 }
319
320 // finally draw the text itself:
321 m_surface->DrawString(wxSTR_TO_DFB(text), -1, xx, yy, DSTF_LEFT | DSTF_TOP);
322 }
323
324 void 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
337 void wxDC::SetPen(const wxPen& pen)
338 {
339 m_pen = pen.Ok() ? pen : DEFAULT_PEN;
340
341 SelectColour(m_pen.GetColour());
342 }
343
344 void wxDC::SetBrush(const wxBrush& brush)
345 {
346 m_brush = brush.Ok() ? brush : DEFAULT_BRUSH;
347 }
348
349 void wxDC::SelectColour(const wxColour& clr)
350 {
351 m_surface->SetColor(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha());
352 #warning "use SetColorIndex?"
353 }
354
355 #if wxUSE_PALETTE
356 void 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
364 void wxDC::SetFont(const wxFont& font)
365 {
366 wxCHECK_RET( Ok(), wxT("invalid dc") );
367
368 wxFont f(font.Ok() ? font : DEFAULT_FONT);
369
370 if ( !m_surface->SetFont(f.GetDirectFBFont()) )
371 return;
372
373 m_font = f;
374 }
375
376 void 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
385 void wxDC::SetBackgroundMode(int mode)
386 {
387 m_backgroundMode = mode;
388 }
389
390 void wxDC::SetLogicalFunction(int function)
391 {
392 wxCHECK_RET( Ok(), wxT("invalid dc") );
393
394 // NB: we could also support XOR, but for blitting only (via DSBLIT_XOR);
395 // and possibly others via SetSrc/DstBlendFunction()
396 wxASSERT_MSG( function == wxCOPY,
397 _T("only wxCOPY logical function supported") );
398
399 m_logicalFunction = function;
400 }
401
402 bool wxDC::StartDoc(const wxString& WXUNUSED(message))
403 {
404 // We might be previewing, so return true to let it continue.
405 return true;
406 }
407
408 void wxDC::EndDoc()
409 {
410 }
411
412 void wxDC::StartPage()
413 {
414 }
415
416 void wxDC::EndPage()
417 {
418 }
419
420 // ---------------------------------------------------------------------------
421 // text metrics
422 // ---------------------------------------------------------------------------
423
424 wxCoord wxDC::GetCharHeight() const
425 {
426 wxCHECK_MSG( Ok(), -1, wxT("invalid dc") );
427 wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") );
428
429 int h = -1;
430 m_font.GetDirectFBFont()->GetHeight(&h);
431 return YDEV2LOGREL(h);
432 }
433
434 wxCoord wxDC::GetCharWidth() const
435 {
436 wxCHECK_MSG( Ok(), -1, wxT("invalid dc") );
437 wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") );
438
439 int w = -1;
440 m_font.GetDirectFBFont()->GetStringWidth("H", 1, &w);
441 // VS: YDEV is corrent, it should *not* be XDEV, because font's are only
442 // scaled according to m_scaleY
443 return YDEV2LOGREL(w);
444 }
445
446 void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
447 wxCoord *descent, wxCoord *externalLeading,
448 wxFont *theFont) const
449 {
450 wxCHECK_RET( Ok(), wxT("invalid dc") );
451 wxCHECK_RET( m_font.Ok(), wxT("no font selected") );
452 wxCHECK_RET( !theFont || theFont->Ok(), wxT("invalid font") );
453
454 wxFont oldFont;
455 if ( theFont != NULL )
456 {
457 oldFont = m_font;
458 wxConstCast(this, wxDC)->SetFont(*theFont);
459 }
460
461 wxCoord xx = 0, yy = 0;
462 DFBRectangle rect;
463 wxIDirectFBFontPtr f = m_font.GetDirectFBFont();
464
465 if ( f->GetStringExtents(wxSTR_TO_DFB(string), -1, &rect, NULL) )
466 {
467 // VS: YDEV is corrent, it should *not* be XDEV, because font's are
468 // only scaled according to m_scaleY
469 xx = YDEV2LOGREL(rect.w);
470 yy = YDEV2LOGREL(rect.h);
471
472 if ( descent )
473 {
474 int d;
475 if ( f->GetDescender(&d) )
476 *descent = YDEV2LOGREL(-d);
477 else
478 *descent = 0;
479 }
480 }
481
482 if ( x ) *x = xx;
483 if ( y ) *y = yy;
484 if ( externalLeading ) *externalLeading = 0;
485
486 if ( theFont != NULL )
487 wxConstCast(this, wxDC)->SetFont(oldFont);
488 }
489
490
491
492 // ---------------------------------------------------------------------------
493 // mapping modes
494 // ---------------------------------------------------------------------------
495
496 void wxDC::ComputeScaleAndOrigin()
497 {
498 m_scaleX = m_logicalScaleX * m_userScaleX;
499 m_scaleY = m_logicalScaleY * m_userScaleY;
500
501 // FIXME_DFB: scaling affects pixel size of font, pens, brushes, which
502 // is not currently implemented here; probably makes sense to
503 // switch to Cairo instead of implementing everything for DFB
504 wxASSERT_MSG( m_scaleX == 1.0 && m_scaleY == 1.0,
505 _T("scaling is not implemented in wxDFB") );
506 }
507
508 void wxDC::SetMapMode(int mode)
509 {
510 #warning "move this to common code, it's shared by almost all ports!"
511 switch (mode)
512 {
513 case wxMM_TWIPS:
514 SetLogicalScale(twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y);
515 break;
516 case wxMM_POINTS:
517 SetLogicalScale(pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y);
518 break;
519 case wxMM_METRIC:
520 SetLogicalScale(m_mm_to_pix_x, m_mm_to_pix_y);
521 break;
522 case wxMM_LOMETRIC:
523 SetLogicalScale(m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0);
524 break;
525 default:
526 case wxMM_TEXT:
527 SetLogicalScale(1.0, 1.0);
528 break;
529 }
530 m_mappingMode = mode;
531 }
532
533 void wxDC::SetUserScale(double x, double y)
534 {
535 #warning "move this to common code?"
536 // allow negative ? -> no
537 m_userScaleX = x;
538 m_userScaleY = y;
539 ComputeScaleAndOrigin();
540 }
541
542 void wxDC::SetLogicalScale(double x, double y)
543 {
544 #warning "move this to common code?"
545 // allow negative ?
546 m_logicalScaleX = x;
547 m_logicalScaleY = y;
548 ComputeScaleAndOrigin();
549 }
550
551 void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
552 {
553 #warning "move this to common code?"
554 m_logicalOriginX = x * m_signX; // is this still correct ?
555 m_logicalOriginY = y * m_signY;
556 ComputeScaleAndOrigin();
557 }
558
559 void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
560 {
561 #warning "move this to common code?"
562 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
563 m_deviceOriginX = x;
564 m_deviceOriginY = y;
565 ComputeScaleAndOrigin();
566 }
567
568 void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
569 {
570 #warning "move this to common code?"
571 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
572 m_signX = (xLeftRight ? 1 : -1);
573 m_signY = (yBottomUp ? -1 : 1);
574 ComputeScaleAndOrigin();
575 }
576
577 // ---------------------------------------------------------------------------
578 // coordinates transformations
579 // ---------------------------------------------------------------------------
580
581 wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
582 {
583 return ((wxDC *)this)->XDEV2LOG(x);
584 }
585
586 wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
587 {
588 return ((wxDC *)this)->YDEV2LOG(y);
589 }
590
591 wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
592 {
593 return ((wxDC *)this)->XDEV2LOGREL(x);
594 }
595
596 wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
597 {
598 return ((wxDC *)this)->YDEV2LOGREL(y);
599 }
600
601 wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
602 {
603 return ((wxDC *)this)->XLOG2DEV(x);
604 }
605
606 wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
607 {
608 return ((wxDC *)this)->YLOG2DEV(y);
609 }
610
611 wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
612 {
613 return ((wxDC *)this)->XLOG2DEVREL(x);
614 }
615
616 wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
617 {
618 return ((wxDC *)this)->YLOG2DEVREL(y);
619 }
620
621
622 void wxDC::DoGetSize(int *w, int *h) const
623 {
624 wxCHECK_RET( Ok(), wxT("invalid dc") );
625
626 m_surface->GetSize(w, h);
627 }
628
629 void wxDC::DoGetSizeMM(int *width, int *height) const
630 {
631 #warning "move this to common code?"
632 int w = 0;
633 int h = 0;
634 GetSize(&w, &h);
635 if ( width ) *width = int(double(w) / (m_userScaleX*m_mm_to_pix_x));
636 if ( height ) *height = int(double(h) / (m_userScaleY*m_mm_to_pix_y));
637 }
638
639 wxSize wxDC::GetPPI() const
640 {
641 #warning "move this to common code?"
642 return wxSize(int(double(m_mm_to_pix_x) * inches2mm),
643 int(double(m_mm_to_pix_y) * inches2mm));
644 }
645
646
647 // ---------------------------------------------------------------------------
648 // Blitting
649 // ---------------------------------------------------------------------------
650
651 bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest,
652 wxCoord width, wxCoord height,
653 wxDC *source, wxCoord xsrc, wxCoord ysrc,
654 int rop, bool useMask,
655 wxCoord xsrcMask, wxCoord ysrcMask)
656 {
657 wxCHECK_MSG( Ok(), false, _T("invalid dc") );
658 wxCHECK_MSG( source, false, _T("invalid source dc") );
659
660 // NB: we could also support XOR here (via DSBLIT_XOR)
661 // and possibly others via SetSrc/DstBlendFunction()
662 wxCHECK_MSG( rop == wxCOPY, false, _T("only wxCOPY function supported") );
663
664 // transform the source DC coords to the device ones
665 xsrc = source->LogicalToDeviceX(xsrc);
666 ysrc = source->LogicalToDeviceY(ysrc);
667
668 // FIXME_DFB: use the mask origin when drawing transparently
669 wxASSERT_MSG( xsrcMask == -1 && ysrcMask == -1,
670 _T("non-default source mask offset not implemented") );
671 #if 0
672 if (xsrcMask == -1 && ysrcMask == -1)
673 {
674 xsrcMask = xsrc; ysrcMask = ysrc;
675 }
676 else
677 {
678 xsrcMask = source->LogicalToDeviceX(xsrcMask);
679 ysrcMask = source->LogicalToDeviceY(ysrcMask);
680 }
681 #endif
682
683 wxMemoryDC *sourceAsMemDC = wxDynamicCast(source, wxMemoryDC);
684 if ( sourceAsMemDC )
685 {
686 DoDrawSubBitmap(sourceAsMemDC->GetSelectedObject(),
687 xsrc, ysrc,
688 width, height,
689 xdest, ydest,
690 rop,
691 useMask);
692 }
693 else
694 {
695 return DoBlitFromSurface(source->GetDirectFBSurface(),
696 xsrc, ysrc,
697 width, height,
698 xdest, ydest);
699 }
700
701 return true;
702 }
703
704 void wxDC::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask)
705 {
706 wxCHECK_RET( Ok(), wxT("invalid dc") );
707 wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") );
708
709 DoDrawSubBitmap(bmp,
710 0, 0, bmp.GetWidth(), bmp.GetHeight(),
711 x, y,
712 m_logicalFunction, useMask);
713 }
714
715 void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
716 {
717 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
718 DoDrawBitmap((const wxBitmap&)icon, x, y, true);
719 }
720
721 void wxDC::DoDrawSubBitmap(const wxBitmap &bmp,
722 wxCoord x, wxCoord y, wxCoord w, wxCoord h,
723 wxCoord destx, wxCoord desty, int rop, bool useMask)
724 {
725 wxCHECK_RET( Ok(), wxT("invalid dc") );
726 wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") );
727
728 // NB: we could also support XOR here (via DSBLIT_XOR)
729 // and possibly others via SetSrc/DstBlendFunction()
730 wxCHECK_RET( rop == wxCOPY, _T("only wxCOPY function supported") );
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 wxFAIL_MSG( _T("drawing mono bitmaps not implemented") );
737 return;
738 }
739
740 if ( useMask && bmp.GetMask() )
741 {
742 // FIXME_DFB: see MGL sources for a way to do it, but it's not directly
743 // applicable because DirectFB doesn't implement ROPs; OTOH,
744 // it has blitting modes that can be useful; finally, see
745 // DFB's SetSrcBlendFunction() and SetSrcColorKey()
746 wxFAIL_MSG( _T("drawing bitmaps with masks not implemented") );
747 return;
748 }
749
750 DoBlitFromSurface(bmp.GetDirectFBSurface(),
751 x, y,
752 w, h,
753 destx, desty);
754 }
755
756 bool wxDC::DoBlitFromSurface(const wxIDirectFBSurfacePtr& src,
757 wxCoord srcx, wxCoord srcy,
758 wxCoord w, wxCoord h,
759 wxCoord dstx, wxCoord dsty)
760 {
761 CalcBoundingBox(dstx, dsty);
762 CalcBoundingBox(dstx + w, dsty + h);
763
764 DFBRectangle srcRect = { srcx, srcy, w, h };
765 DFBRectangle dstRect = { XLOG2DEV(dstx), YLOG2DEV(dsty),
766 XLOG2DEVREL(w), YLOG2DEVREL(h) };
767
768 wxIDirectFBSurfacePtr dst(m_surface);
769
770 // FIXME: this will have to be different in useMask case, see above
771 if ( !dst->SetBlittingFlags(DSBLIT_NOFX) )
772 return false;
773
774 if ( srcRect.w != dstRect.w || srcRect.h != dstRect.h )
775 {
776 // the bitmap is drawn stretched:
777 dst->StretchBlit(src, &srcRect, &dstRect);
778 }
779 else
780 {
781 // no stretching, size is preserved:
782 dst->Blit(src, &srcRect, dstRect.x, dstRect.y);
783 }
784
785 return true;
786 }