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