]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/dc.cpp
[ 1560860 ] wxComboCtrl EVT_TEXT filtering.
[wxWidgets.git] / src / dfb / dc.cpp
CommitLineData
b3c86150
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/dfb/dc.cpp
3// Purpose: wxDC class
4// Author: Vaclav Slavik
5// Created: 2006-08-07
6// RCS-ID: $Id$
7// Copyright: (c) 2006 REA Elektronik GmbH
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// ===========================================================================
12// declarations
13// ===========================================================================
14
15// ---------------------------------------------------------------------------
16// headers
17// ---------------------------------------------------------------------------
18
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26#ifndef WX_PRECOMP
27 #include "wx/dc.h"
28 #include "wx/log.h"
29#endif
30
31#include "wx/dfb/private.h"
32
071f5576
VS
33// these values are used to initialize newly created DC
34#define DEFAULT_FONT (*wxNORMAL_FONT)
35#define DEFAULT_PEN (*wxBLACK_PEN)
36#define DEFAULT_BRUSH (*wxWHITE_BRUSH)
37
b3c86150
VS
38// ===========================================================================
39// implementation
40// ===========================================================================
41
42//-----------------------------------------------------------------------------
43// wxDC
44//-----------------------------------------------------------------------------
45
46IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase)
47
48// Default constructor
49wxDC::wxDC()
50{
51 m_ok = false;
52}
53
52c8d32a 54wxDC::wxDC(const wxIDirectFBSurfacePtr& surface)
b3c86150
VS
55{
56 Init(surface);
57}
58
52c8d32a 59void wxDC::Init(const wxIDirectFBSurfacePtr& surface)
b3c86150
VS
60{
61 m_ok = (surface != NULL);
62 wxCHECK_RET( surface != NULL, _T("invalid surface") );
63
64 m_surface = surface;
65
66 m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() /
67 (double)wxGetDisplaySizeMM().GetWidth();
68 m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() /
69 (double)wxGetDisplaySizeMM().GetHeight();
70
071f5576
VS
71 SetFont(DEFAULT_FONT);
72 SetPen(DEFAULT_PEN);
73 SetBrush(DEFAULT_BRUSH);
b3c86150
VS
74}
75
76
77// ---------------------------------------------------------------------------
78// clipping
79// ---------------------------------------------------------------------------
80
81
82#define DO_SET_CLIPPING_BOX(rg) \
83{ \
84 wxRect rect = rg.GetBox(); \
85 m_clipX1 = (wxCoord) XDEV2LOG(rect.GetLeft()); \
86 m_clipY1 = (wxCoord) YDEV2LOG(rect.GetTop()); \
87 m_clipX2 = (wxCoord) XDEV2LOG(rect.GetRight()); \
88 m_clipY2 = (wxCoord) YDEV2LOG(rect.GetBottom()); \
89}
90
91void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch)
92{
93 wxCHECK_RET( Ok(), wxT("invalid dc") );
94
564b429f
VS
95 wxSize size(GetSize());
96
97 // NB: We intersect the clipping rectangle with surface's area here because
98 // DirectFB will return an error if you try to set clipping rectangle
99 // that is partially outside of the surface.
b3c86150 100 DFBRegion r;
564b429f
VS
101 r.x1 = wxMax(0, XLOG2DEV(cx));
102 r.y1 = wxMax(0, YLOG2DEV(cy));
103 r.x2 = wxMin(r.x1 + XLOG2DEVREL(cw), size.x) - 1;
104 r.y2 = wxMin(r.y1 + YLOG2DEVREL(ch), size.y) - 1;
b3c86150 105
52c8d32a 106 if ( !m_surface->SetClip(&r) )
b3c86150
VS
107 return;
108
109 m_clipX1 = cx;
110 m_clipY1 = cy;
111 m_clipX2 = cx + cw - 1;
112 m_clipY2 = cy + ch -1;
113 m_clipping = true;
114}
115
116void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region)
117{
118 // NB: this can be done because wxDFB only supports
119 // rectangular regions
120 SetClippingRegion(region.AsRect());
121}
122
123void wxDC::DestroyClippingRegion()
124{
125 wxCHECK_RET( Ok(), wxT("invalid dc") );
126
52c8d32a 127 m_surface->SetClip(NULL);
b3c86150
VS
128
129 ResetClipping();
130}
131
132// ---------------------------------------------------------------------------
133// query capabilities
134// ---------------------------------------------------------------------------
135
136int wxDC::GetDepth() const
137{
a5b31f4e 138 return m_surface->GetDepth();
b3c86150
VS
139}
140
141// ---------------------------------------------------------------------------
142// drawing
143// ---------------------------------------------------------------------------
144
145void wxDC::Clear()
146{
147 wxCHECK_RET( Ok(), wxT("invalid dc") );
148
149 if ( m_backgroundBrush.GetStyle() == wxTRANSPARENT )
150 return;
151
152 wxColour clr = m_backgroundBrush.GetColour();
52c8d32a 153 m_surface->Clear(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha());
20671963
VS
154
155 wxSize size(GetSize());
156 CalcBoundingBox(XDEV2LOG(0), YDEV2LOG(0));
157 CalcBoundingBox(XDEV2LOG(size.x), YDEV2LOG(size.y));
b3c86150
VS
158}
159
160extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
161 const wxColour & col, int style);
162
163bool wxDC::DoFloodFill(wxCoord x, wxCoord y,
164 const wxColour& col, int style)
165{
166 return wxDoFloodFill(this, x, y, col, style);
167}
168
169bool 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
177void wxDC::DoCrossHair(wxCoord x, wxCoord y)
178{
179 wxCHECK_RET( Ok(), wxT("invalid dc") );
180
181 wxFAIL_MSG( _T("CrossHair not implemented") );
182}
183
184void 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
52c8d32a
VS
191 m_surface->DrawLine(XLOG2DEV(x1), YLOG2DEV(y1),
192 XLOG2DEV(x2), YLOG2DEV(y2));
b3c86150
VS
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)
200void 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
209void wxDC::DoDrawPoint(wxCoord x, wxCoord y)
210{
211 wxCHECK_RET( Ok(), wxT("invalid dc") );
212
3af4da32
VS
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)
b3c86150
VS
219}
220
221void 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
228void 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
236void 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());
52c8d32a 261 m_surface->FillRectangle(xx, yy, ww, hh);
3dcc2231
VS
262 // restore pen's colour, because other drawing functions expect the
263 // colour to be set to the pen:
b3c86150
VS
264 SelectColour(m_pen.GetColour());
265 }
266
267 if ( m_pen.GetStyle() != wxTRANSPARENT )
268 {
52c8d32a 269 m_surface->DrawRectangle(xx, yy, ww, hh);
b3c86150
VS
270 }
271
272 CalcBoundingBox(x, y);
273 CalcBoundingBox(x + width, y + height);
274}
275
276void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius)
277{
278 wxCHECK_RET( Ok(), wxT("invalid dc") );
279
280 wxFAIL_MSG( _T("DrawRoundedRectangle not implemented") );
281}
282
283void wxDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
284{
285 wxCHECK_RET( Ok(), wxT("invalid dc") );
286
287 wxFAIL_MSG( _T("DrawElipse not implemented") );
288}
289
290void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,double ea)
291{
292 wxCHECK_RET( Ok(), wxT("invalid dc") );
293
294 wxFAIL_MSG( _T("DrawElipticArc not implemented") );
295}
296
297void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
298{
299 wxCHECK_RET( Ok(), wxT("invalid dc") );
300
301 wxCoord xx = XLOG2DEV(x);
5034c9db 302 wxCoord yy = YLOG2DEV(y);
b3c86150
VS
303
304 // update the bounding box
305 wxCoord w, h;
306 CalcBoundingBox(x, y);
307 GetTextExtent(text, &w, &h);
308 CalcBoundingBox(x + w, y + h);
309
310 // if background mode is solid, DrawText must paint text's background:
311 if ( m_backgroundMode == wxSOLID )
312 {
3dcc2231
VS
313 wxCHECK_RET( m_textBackgroundColour.Ok(),
314 wxT("invalid background color") );
b3c86150 315
3dcc2231 316 SelectColour(m_textBackgroundColour);
52c8d32a 317 m_surface->FillRectangle(xx, yy, XLOG2DEVREL(w), YLOG2DEVREL(h));
b3c86150
VS
318 }
319
320 // finally draw the text itself:
3dcc2231
VS
321 wxCHECK_RET( m_textForegroundColour.Ok(),
322 wxT("invalid foreground color") );
323 SelectColour(m_textForegroundColour);
52c8d32a 324 m_surface->DrawString(wxSTR_TO_DFB(text), -1, xx, yy, DSTF_LEFT | DSTF_TOP);
3dcc2231
VS
325
326 // restore pen's colour, because other drawing functions expect the colour
327 // to be set to the pen:
328 SelectColour(m_pen.GetColour());
b3c86150
VS
329}
330
331void wxDC::DoDrawRotatedText(const wxString& text,
332 wxCoord x, wxCoord y,
333 double angle)
334{
335 wxCHECK_RET( Ok(), wxT("invalid dc") );
336
337 wxFAIL_MSG( _T("DrawRotatedText not implemented") );
338}
339
340// ---------------------------------------------------------------------------
341// set GDI objects
342// ---------------------------------------------------------------------------
343
344void wxDC::SetPen(const wxPen& pen)
345{
071f5576 346 m_pen = pen.Ok() ? pen : DEFAULT_PEN;
b3c86150
VS
347
348 SelectColour(m_pen.GetColour());
349}
350
351void wxDC::SetBrush(const wxBrush& brush)
352{
071f5576 353 m_brush = brush.Ok() ? brush : DEFAULT_BRUSH;
b3c86150
VS
354}
355
356void wxDC::SelectColour(const wxColour& clr)
357{
52c8d32a 358 m_surface->SetColor(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha());
b3c86150
VS
359 #warning "use SetColorIndex?"
360}
361
362#if wxUSE_PALETTE
363void wxDC::SetPalette(const wxPalette& WXUNUSED(palette))
364{
365 wxCHECK_RET( Ok(), wxT("invalid dc") );
366
367 wxFAIL_MSG( _T("SetPalette not implemented") );
368}
369#endif // wxUSE_PALETTE
370
371void wxDC::SetFont(const wxFont& font)
372{
373 wxCHECK_RET( Ok(), wxT("invalid dc") );
374
071f5576 375 wxFont f(font.Ok() ? font : DEFAULT_FONT);
b3c86150 376
071f5576 377 if ( !m_surface->SetFont(f.GetDirectFBFont()) )
b3c86150
VS
378 return;
379
071f5576 380 m_font = f;
b3c86150
VS
381}
382
383void wxDC::SetBackground(const wxBrush& brush)
384{
385 wxCHECK_RET( Ok(), wxT("invalid dc") );
386
387 if (!brush.Ok()) return;
388
389 m_backgroundBrush = brush;
390}
391
392void wxDC::SetBackgroundMode(int mode)
393{
394 m_backgroundMode = mode;
395}
396
397void wxDC::SetLogicalFunction(int function)
398{
399 wxCHECK_RET( Ok(), wxT("invalid dc") );
400
5942996c
VS
401 // NB: we could also support XOR, but for blitting only (via DSBLIT_XOR);
402 // and possibly others via SetSrc/DstBlendFunction()
403 wxASSERT_MSG( function == wxCOPY,
404 _T("only wxCOPY logical function supported") );
b3c86150
VS
405
406 m_logicalFunction = function;
407}
408
409bool wxDC::StartDoc(const wxString& WXUNUSED(message))
410{
411 // We might be previewing, so return true to let it continue.
412 return true;
413}
414
415void wxDC::EndDoc()
416{
417}
418
419void wxDC::StartPage()
420{
421}
422
423void wxDC::EndPage()
424{
425}
426
427// ---------------------------------------------------------------------------
428// text metrics
429// ---------------------------------------------------------------------------
430
431wxCoord wxDC::GetCharHeight() const
432{
433 wxCHECK_MSG( Ok(), -1, wxT("invalid dc") );
434 wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") );
435
436 int h = -1;
52c8d32a 437 m_font.GetDirectFBFont()->GetHeight(&h);
b3c86150
VS
438 return YDEV2LOGREL(h);
439}
440
441wxCoord wxDC::GetCharWidth() const
442{
443 wxCHECK_MSG( Ok(), -1, wxT("invalid dc") );
444 wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") );
445
446 int w = -1;
52c8d32a 447 m_font.GetDirectFBFont()->GetStringWidth("H", 1, &w);
b3c86150
VS
448 // VS: YDEV is corrent, it should *not* be XDEV, because font's are only
449 // scaled according to m_scaleY
450 return YDEV2LOGREL(w);
451}
452
453void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
454 wxCoord *descent, wxCoord *externalLeading,
455 wxFont *theFont) const
456{
457 wxCHECK_RET( Ok(), wxT("invalid dc") );
458 wxCHECK_RET( m_font.Ok(), wxT("no font selected") );
459 wxCHECK_RET( !theFont || theFont->Ok(), wxT("invalid font") );
460
461 wxFont oldFont;
462 if ( theFont != NULL )
463 {
464 oldFont = m_font;
465 wxConstCast(this, wxDC)->SetFont(*theFont);
466 }
467
468 wxCoord xx = 0, yy = 0;
469 DFBRectangle rect;
52c8d32a 470 wxIDirectFBFontPtr f = m_font.GetDirectFBFont();
b3c86150 471
52c8d32a 472 if ( f->GetStringExtents(wxSTR_TO_DFB(string), -1, &rect, NULL) )
b3c86150
VS
473 {
474 // VS: YDEV is corrent, it should *not* be XDEV, because font's are
475 // only scaled according to m_scaleY
476 xx = YDEV2LOGREL(rect.w);
477 yy = YDEV2LOGREL(rect.h);
478
479 if ( descent )
480 {
481 int d;
52c8d32a 482 if ( f->GetDescender(&d) )
b3c86150
VS
483 *descent = YDEV2LOGREL(-d);
484 else
485 *descent = 0;
486 }
487 }
488
489 if ( x ) *x = xx;
490 if ( y ) *y = yy;
491 if ( externalLeading ) *externalLeading = 0;
492
493 if ( theFont != NULL )
494 wxConstCast(this, wxDC)->SetFont(oldFont);
495}
496
497
498
499// ---------------------------------------------------------------------------
500// mapping modes
501// ---------------------------------------------------------------------------
502
503void wxDC::ComputeScaleAndOrigin()
504{
505 m_scaleX = m_logicalScaleX * m_userScaleX;
506 m_scaleY = m_logicalScaleY * m_userScaleY;
507
508 // FIXME_DFB: scaling affects pixel size of font, pens, brushes, which
509 // is not currently implemented here; probably makes sense to
510 // switch to Cairo instead of implementing everything for DFB
511 wxASSERT_MSG( m_scaleX == 1.0 && m_scaleY == 1.0,
512 _T("scaling is not implemented in wxDFB") );
513}
514
515void wxDC::SetMapMode(int mode)
516{
517 #warning "move this to common code, it's shared by almost all ports!"
518 switch (mode)
519 {
520 case wxMM_TWIPS:
521 SetLogicalScale(twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y);
522 break;
523 case wxMM_POINTS:
524 SetLogicalScale(pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y);
525 break;
526 case wxMM_METRIC:
527 SetLogicalScale(m_mm_to_pix_x, m_mm_to_pix_y);
528 break;
529 case wxMM_LOMETRIC:
530 SetLogicalScale(m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0);
531 break;
532 default:
533 case wxMM_TEXT:
534 SetLogicalScale(1.0, 1.0);
535 break;
536 }
537 m_mappingMode = mode;
538}
539
540void wxDC::SetUserScale(double x, double y)
541{
542 #warning "move this to common code?"
543 // allow negative ? -> no
544 m_userScaleX = x;
545 m_userScaleY = y;
546 ComputeScaleAndOrigin();
547}
548
549void wxDC::SetLogicalScale(double x, double y)
550{
551 #warning "move this to common code?"
552 // allow negative ?
553 m_logicalScaleX = x;
554 m_logicalScaleY = y;
555 ComputeScaleAndOrigin();
556}
557
558void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
559{
560 #warning "move this to common code?"
561 m_logicalOriginX = x * m_signX; // is this still correct ?
562 m_logicalOriginY = y * m_signY;
563 ComputeScaleAndOrigin();
564}
565
566void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
567{
568 #warning "move this to common code?"
569 // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there
570 m_deviceOriginX = x;
571 m_deviceOriginY = y;
572 ComputeScaleAndOrigin();
573}
574
575void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp )
576{
577 #warning "move this to common code?"
578 // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there
579 m_signX = (xLeftRight ? 1 : -1);
580 m_signY = (yBottomUp ? -1 : 1);
581 ComputeScaleAndOrigin();
582}
583
584// ---------------------------------------------------------------------------
585// coordinates transformations
586// ---------------------------------------------------------------------------
587
588wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
589{
590 return ((wxDC *)this)->XDEV2LOG(x);
591}
592
593wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
594{
595 return ((wxDC *)this)->YDEV2LOG(y);
596}
597
598wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
599{
600 return ((wxDC *)this)->XDEV2LOGREL(x);
601}
602
603wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
604{
605 return ((wxDC *)this)->YDEV2LOGREL(y);
606}
607
608wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
609{
610 return ((wxDC *)this)->XLOG2DEV(x);
611}
612
613wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
614{
615 return ((wxDC *)this)->YLOG2DEV(y);
616}
617
618wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
619{
620 return ((wxDC *)this)->XLOG2DEVREL(x);
621}
622
623wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
624{
625 return ((wxDC *)this)->YLOG2DEVREL(y);
626}
627
628
629void wxDC::DoGetSize(int *w, int *h) const
630{
631 wxCHECK_RET( Ok(), wxT("invalid dc") );
632
52c8d32a 633 m_surface->GetSize(w, h);
b3c86150
VS
634}
635
636void wxDC::DoGetSizeMM(int *width, int *height) const
637{
638 #warning "move this to common code?"
639 int w = 0;
640 int h = 0;
641 GetSize(&w, &h);
642 if ( width ) *width = int(double(w) / (m_userScaleX*m_mm_to_pix_x));
643 if ( height ) *height = int(double(h) / (m_userScaleY*m_mm_to_pix_y));
644}
645
646wxSize wxDC::GetPPI() const
647{
648 #warning "move this to common code?"
649 return wxSize(int(double(m_mm_to_pix_x) * inches2mm),
650 int(double(m_mm_to_pix_y) * inches2mm));
651}
652
653
654// ---------------------------------------------------------------------------
655// Blitting
656// ---------------------------------------------------------------------------
657
658bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest,
659 wxCoord width, wxCoord height,
660 wxDC *source, wxCoord xsrc, wxCoord ysrc,
661 int rop, bool useMask,
662 wxCoord xsrcMask, wxCoord ysrcMask)
663{
5942996c
VS
664 wxCHECK_MSG( Ok(), false, _T("invalid dc") );
665 wxCHECK_MSG( source, false, _T("invalid source dc") );
666
667 // NB: we could also support XOR here (via DSBLIT_XOR)
668 // and possibly others via SetSrc/DstBlendFunction()
669 wxCHECK_MSG( rop == wxCOPY, false, _T("only wxCOPY function supported") );
b3c86150
VS
670
671 // transform the source DC coords to the device ones
672 xsrc = source->LogicalToDeviceX(xsrc);
673 ysrc = source->LogicalToDeviceY(ysrc);
674
5942996c
VS
675 // FIXME_DFB: use the mask origin when drawing transparently
676 wxASSERT_MSG( xsrcMask == -1 && ysrcMask == -1,
677 _T("non-default source mask offset not implemented") );
678#if 0
b3c86150
VS
679 if (xsrcMask == -1 && ysrcMask == -1)
680 {
681 xsrcMask = xsrc; ysrcMask = ysrc;
682 }
683 else
684 {
685 xsrcMask = source->LogicalToDeviceX(xsrcMask);
686 ysrcMask = source->LogicalToDeviceY(ysrcMask);
687 }
5942996c 688#endif
b3c86150 689
5942996c
VS
690 wxMemoryDC *sourceAsMemDC = wxDynamicCast(source, wxMemoryDC);
691 if ( sourceAsMemDC )
b3c86150 692 {
5942996c
VS
693 DoDrawSubBitmap(sourceAsMemDC->GetSelectedObject(),
694 xsrc, ysrc,
695 width, height,
696 xdest, ydest,
697 rop,
698 useMask);
b3c86150
VS
699 }
700 else
701 {
5942996c
VS
702 return DoBlitFromSurface(source->GetDirectFBSurface(),
703 xsrc, ysrc,
704 width, height,
705 xdest, ydest);
b3c86150
VS
706 }
707
708 return true;
b3c86150
VS
709}
710
711void wxDC::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask)
712{
713 wxCHECK_RET( Ok(), wxT("invalid dc") );
714 wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") );
715
5942996c
VS
716 DoDrawSubBitmap(bmp,
717 0, 0, bmp.GetWidth(), bmp.GetHeight(),
718 x, y,
719 m_logicalFunction, useMask);
b3c86150
VS
720}
721
722void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
723{
724 // VZ: egcs 1.0.3 refuses to compile this without cast, no idea why
725 DoDrawBitmap((const wxBitmap&)icon, x, y, true);
726}
727
728void wxDC::DoDrawSubBitmap(const wxBitmap &bmp,
729 wxCoord x, wxCoord y, wxCoord w, wxCoord h,
730 wxCoord destx, wxCoord desty, int rop, bool useMask)
731{
b3c86150
VS
732 wxCHECK_RET( Ok(), wxT("invalid dc") );
733 wxCHECK_RET( bmp.Ok(), wxT("invalid bitmap") );
734
5942996c
VS
735 // NB: we could also support XOR here (via DSBLIT_XOR)
736 // and possibly others via SetSrc/DstBlendFunction()
737 wxCHECK_RET( rop == wxCOPY, _T("only wxCOPY function supported") );
b3c86150
VS
738
739 if ( bmp.GetDepth() == 1 )
740 {
741 // Mono bitmaps are handled in special way -- all 1s are drawn in
742 // foreground colours, all 0s in background colour.
5942996c
VS
743 wxFAIL_MSG( _T("drawing mono bitmaps not implemented") );
744 return;
b3c86150
VS
745 }
746
747 if ( useMask && bmp.GetMask() )
748 {
5942996c
VS
749 // FIXME_DFB: see MGL sources for a way to do it, but it's not directly
750 // applicable because DirectFB doesn't implement ROPs; OTOH,
751 // it has blitting modes that can be useful; finally, see
752 // DFB's SetSrcBlendFunction() and SetSrcColorKey()
753 wxFAIL_MSG( _T("drawing bitmaps with masks not implemented") );
754 return;
755 }
b3c86150 756
5942996c
VS
757 DoBlitFromSurface(bmp.GetDirectFBSurface(),
758 x, y,
759 w, h,
760 destx, desty);
761}
b3c86150 762
5942996c
VS
763bool wxDC::DoBlitFromSurface(const wxIDirectFBSurfacePtr& src,
764 wxCoord srcx, wxCoord srcy,
765 wxCoord w, wxCoord h,
766 wxCoord dstx, wxCoord dsty)
767{
768 CalcBoundingBox(dstx, dsty);
769 CalcBoundingBox(dstx + w, dsty + h);
b3c86150 770
5942996c
VS
771 DFBRectangle srcRect = { srcx, srcy, w, h };
772 DFBRectangle dstRect = { XLOG2DEV(dstx), YLOG2DEV(dsty),
773 XLOG2DEVREL(w), YLOG2DEVREL(h) };
b3c86150 774
5942996c 775 wxIDirectFBSurfacePtr dst(m_surface);
b3c86150 776
5942996c
VS
777 // FIXME: this will have to be different in useMask case, see above
778 if ( !dst->SetBlittingFlags(DSBLIT_NOFX) )
779 return false;
b3c86150 780
5942996c
VS
781 if ( srcRect.w != dstRect.w || srcRect.h != dstRect.h )
782 {
783 // the bitmap is drawn stretched:
784 dst->StretchBlit(src, &srcRect, &dstRect);
b3c86150 785 }
b3c86150
VS
786 else
787 {
5942996c
VS
788 // no stretching, size is preserved:
789 dst->Blit(src, &srcRect, dstRect.x, dstRect.y);
b3c86150 790 }
5942996c
VS
791
792 return true;
b3c86150 793}