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