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