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