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