]> git.saurik.com Git - wxWidgets.git/blame - src/dfb/dc.cpp
Don't call wxSafeYield() from wxGenericListCtrl::EditLabel().
[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
fdaad94e 98void wxDFBDCImpl::DoSetDeviceClippingRegion(const wxRegion& region)
b3c86150 99{
f87d0500 100 // NB: this can be done because wxDFB only supports rectangular regions
fdaad94e
VZ
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
6a8dba37 110 DoSetClippingRegion(rect.x, rect.y, rect.width, rect.height);
b3c86150
VS
111}
112
4a624f6e 113void wxDFBDCImpl::DestroyClippingRegion()
b3c86150 114{
4a624f6e 115 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150 116
52c8d32a 117 m_surface->SetClip(NULL);
b3c86150
VS
118
119 ResetClipping();
120}
121
122// ---------------------------------------------------------------------------
123// query capabilities
124// ---------------------------------------------------------------------------
125
4a624f6e 126int wxDFBDCImpl::GetDepth() const
b3c86150 127{
a5b31f4e 128 return m_surface->GetDepth();
b3c86150
VS
129}
130
131// ---------------------------------------------------------------------------
132// drawing
133// ---------------------------------------------------------------------------
134
4a624f6e 135void wxDFBDCImpl::Clear()
b3c86150 136{
4a624f6e 137 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150
VS
138
139 if ( m_backgroundBrush.GetStyle() == wxTRANSPARENT )
140 return;
141
142 wxColour clr = m_backgroundBrush.GetColour();
52c8d32a 143 m_surface->Clear(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha());
20671963
VS
144
145 wxSize size(GetSize());
146 CalcBoundingBox(XDEV2LOG(0), YDEV2LOG(0));
147 CalcBoundingBox(XDEV2LOG(size.x), YDEV2LOG(size.y));
b3c86150
VS
148}
149
150extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
89efaf2b 151 const wxColour & col, wxFloodFillStyle style);
b3c86150 152
4a624f6e 153bool wxDFBDCImpl::DoFloodFill(wxCoord x, wxCoord y,
89efaf2b 154 const wxColour& col, wxFloodFillStyle style)
b3c86150 155{
4a624f6e 156 return wxDoFloodFill(GetOwner(), x, y, col, style);
b3c86150
VS
157}
158
4a624f6e 159bool wxDFBDCImpl::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const
b3c86150 160{
4a624f6e 161 wxCHECK_MSG( col, false, "NULL colour parameter in wxDFBDCImpl::GetPixel");
b3c86150 162
a5001e93 163 wxFAIL_MSG( "GetPixel not implemented" );
4a624f6e
VZ
164
165 wxUnusedVar(x);
166 wxUnusedVar(y);
167
b3c86150
VS
168 return false;
169}
170
4a624f6e 171void wxDFBDCImpl::DoCrossHair(wxCoord x, wxCoord y)
b3c86150 172{
4a624f6e 173 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150 174
a5001e93 175 wxFAIL_MSG( "CrossHair not implemented" );
4a624f6e
VZ
176
177 wxUnusedVar(x);
178 wxUnusedVar(y);
b3c86150
VS
179}
180
4a624f6e 181void wxDFBDCImpl::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
b3c86150 182{
4a624f6e 183 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150
VS
184
185 if ( m_pen.GetStyle() == wxTRANSPARENT )
186 return;
187
ea280776 188 wxCoord xx1 = XLOG2DEV(x1);
59eb2aca 189 wxCoord yy1 = YLOG2DEV(y1);
ea280776 190 wxCoord xx2 = XLOG2DEV(x2);
59eb2aca 191 wxCoord yy2 = YLOG2DEV(y2);
ea280776
VS
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);
b3c86150
VS
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)
4a624f6e
VZ
221void wxDFBDCImpl::DoDrawArc(wxCoord WXUNUSED(x1), wxCoord WXUNUSED(y1),
222 wxCoord WXUNUSED(x2), wxCoord WXUNUSED(y2),
223 wxCoord WXUNUSED(xc), wxCoord WXUNUSED(yc))
b3c86150 224{
4a624f6e 225 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150 226
a5001e93 227 wxFAIL_MSG( "DrawArc not implemented" );
b3c86150
VS
228}
229
4a624f6e 230void wxDFBDCImpl::DoDrawPoint(wxCoord x, wxCoord y)
b3c86150 231{
4a624f6e 232 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150 233
3af4da32
VS
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)
b3c86150
VS
240}
241
4a624f6e
VZ
242void wxDFBDCImpl::DoDrawPolygon(int WXUNUSED(n), wxPoint WXUNUSED(points)[],
243 wxCoord WXUNUSED(xoffset), wxCoord WXUNUSED(yoffset),
89efaf2b 244 wxPolygonFillMode WXUNUSED(fillStyle))
b3c86150 245{
4a624f6e 246 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150 247
a5001e93 248 wxFAIL_MSG( "DrawPolygon not implemented" );
b3c86150
VS
249}
250
4a624f6e
VZ
251void wxDFBDCImpl::DoDrawLines(int WXUNUSED(n), wxPoint WXUNUSED(points)[],
252 wxCoord WXUNUSED(xoffset), wxCoord WXUNUSED(yoffset))
b3c86150 253{
4a624f6e 254 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150
VS
255
256 // TODO: impl. using DirectDB's DrawLines
a5001e93 257 wxFAIL_MSG( "DrawLines not implemented" );
b3c86150
VS
258}
259
4a624f6e 260void wxDFBDCImpl::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
b3c86150 261{
4a624f6e 262 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150
VS
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());
52c8d32a 285 m_surface->FillRectangle(xx, yy, ww, hh);
3dcc2231
VS
286 // restore pen's colour, because other drawing functions expect the
287 // colour to be set to the pen:
b3c86150
VS
288 SelectColour(m_pen.GetColour());
289 }
290
291 if ( m_pen.GetStyle() != wxTRANSPARENT )
292 {
52c8d32a 293 m_surface->DrawRectangle(xx, yy, ww, hh);
b3c86150
VS
294 }
295
296 CalcBoundingBox(x, y);
297 CalcBoundingBox(x + width, y + height);
298}
299
4a624f6e
VZ
300void wxDFBDCImpl::DoDrawRoundedRectangle(wxCoord WXUNUSED(x),
301 wxCoord WXUNUSED(y),
302 wxCoord WXUNUSED(width),
303 wxCoord WXUNUSED(height),
304 double WXUNUSED(radius))
b3c86150 305{
4a624f6e 306 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150 307
a5001e93 308 wxFAIL_MSG( "DrawRoundedRectangle not implemented" );
b3c86150
VS
309}
310
4a624f6e
VZ
311void wxDFBDCImpl::DoDrawEllipse(wxCoord WXUNUSED(x),
312 wxCoord WXUNUSED(y),
313 wxCoord WXUNUSED(width),
314 wxCoord WXUNUSED(height))
b3c86150 315{
4a624f6e 316 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150 317
a5001e93 318 wxFAIL_MSG( "DrawElipse not implemented" );
b3c86150
VS
319}
320
4a624f6e
VZ
321void 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))
b3c86150 327{
4a624f6e 328 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150 329
a5001e93 330 wxFAIL_MSG( "DrawElipticArc not implemented" );
b3c86150
VS
331}
332
4a624f6e 333void wxDFBDCImpl::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
b3c86150 334{
4a624f6e 335 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150
VS
336
337 wxCoord xx = XLOG2DEV(x);
5034c9db 338 wxCoord yy = YLOG2DEV(y);
b3c86150
VS
339
340 // update the bounding box
341 wxCoord w, h;
342 CalcBoundingBox(x, y);
4a624f6e 343 DoGetTextExtent(text, &w, &h);
b3c86150
VS
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 {
a1b806b9 349 wxCHECK_RET( m_textBackgroundColour.IsOk(),
3dcc2231 350 wxT("invalid background color") );
b3c86150 351
3dcc2231 352 SelectColour(m_textBackgroundColour);
52c8d32a 353 m_surface->FillRectangle(xx, yy, XLOG2DEVREL(w), YLOG2DEVREL(h));
b3c86150
VS
354 }
355
356 // finally draw the text itself:
a1b806b9 357 wxCHECK_RET( m_textForegroundColour.IsOk(),
3dcc2231
VS
358 wxT("invalid foreground color") );
359 SelectColour(m_textForegroundColour);
26f03c44 360 m_surface->DrawString(text.utf8_str(), -1, xx, yy, DSTF_LEFT | DSTF_TOP);
3dcc2231
VS
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());
b3c86150
VS
365}
366
4a624f6e
VZ
367void wxDFBDCImpl::DoDrawRotatedText(const wxString& WXUNUSED(text),
368 wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
369 double WXUNUSED(angle))
b3c86150 370{
4a624f6e 371 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150 372
a5001e93 373 wxFAIL_MSG( "DrawRotatedText not implemented" );
b3c86150
VS
374}
375
376// ---------------------------------------------------------------------------
377// set GDI objects
378// ---------------------------------------------------------------------------
379
4a624f6e 380void wxDFBDCImpl::SetPen(const wxPen& pen)
b3c86150 381{
a1b806b9 382 m_pen = pen.IsOk() ? pen : DEFAULT_PEN;
b3c86150
VS
383
384 SelectColour(m_pen.GetColour());
385}
386
4a624f6e 387void wxDFBDCImpl::SetBrush(const wxBrush& brush)
b3c86150 388{
a1b806b9 389 m_brush = brush.IsOk() ? brush : DEFAULT_BRUSH;
b3c86150
VS
390}
391
4a624f6e 392void wxDFBDCImpl::SelectColour(const wxColour& clr)
b3c86150 393{
52c8d32a 394 m_surface->SetColor(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha());
b3c86150
VS
395 #warning "use SetColorIndex?"
396}
397
398#if wxUSE_PALETTE
4a624f6e 399void wxDFBDCImpl::SetPalette(const wxPalette& WXUNUSED(palette))
b3c86150 400{
4a624f6e 401 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150 402
a5001e93 403 wxFAIL_MSG( "SetPalette not implemented" );
b3c86150
VS
404}
405#endif // wxUSE_PALETTE
406
4a624f6e 407void wxDFBDCImpl::SetFont(const wxFont& font)
b3c86150 408{
4a624f6e 409 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150 410
a1b806b9 411 wxFont f(font.IsOk() ? font : DEFAULT_FONT);
b3c86150 412
d7ae4a62 413 wxFont oldfont(m_font);
b3c86150 414
071f5576 415 m_font = f;
d7ae4a62
VS
416
417 if ( !m_surface->SetFont(GetCurrentFont()) )
418 {
419 m_font = oldfont;
420 return;
421 }
422}
423
4a624f6e 424wxIDirectFBFontPtr wxDFBDCImpl::GetCurrentFont() const
d7ae4a62
VS
425{
426 bool aa = (GetDepth() > 8);
427 return m_font.GetDirectFBFont(aa);
b3c86150
VS
428}
429
4a624f6e 430void wxDFBDCImpl::SetBackground(const wxBrush& brush)
b3c86150 431{
4a624f6e 432 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150 433
a1b806b9 434 if (!brush.IsOk()) return;
b3c86150
VS
435
436 m_backgroundBrush = brush;
437}
438
4a624f6e 439void wxDFBDCImpl::SetBackgroundMode(int mode)
b3c86150
VS
440{
441 m_backgroundMode = mode;
442}
443
89efaf2b 444void wxDFBDCImpl::SetLogicalFunction(wxRasterOperationMode function)
b3c86150 445{
4a624f6e 446 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150 447
5942996c
VS
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,
a5001e93 451 "only wxCOPY logical function supported" );
b3c86150
VS
452
453 m_logicalFunction = function;
454}
455
4a624f6e 456bool wxDFBDCImpl::StartDoc(const wxString& WXUNUSED(message))
b3c86150
VS
457{
458 // We might be previewing, so return true to let it continue.
459 return true;
460}
461
4a624f6e 462void wxDFBDCImpl::EndDoc()
b3c86150
VS
463{
464}
465
4a624f6e 466void wxDFBDCImpl::StartPage()
b3c86150
VS
467{
468}
469
4a624f6e 470void wxDFBDCImpl::EndPage()
b3c86150
VS
471{
472}
473
474// ---------------------------------------------------------------------------
475// text metrics
476// ---------------------------------------------------------------------------
477
4a624f6e 478wxCoord wxDFBDCImpl::GetCharHeight() const
b3c86150 479{
4a624f6e 480 wxCHECK_MSG( IsOk(), -1, wxT("invalid dc") );
a1b806b9 481 wxCHECK_MSG( m_font.IsOk(), -1, wxT("no font selected") );
b3c86150
VS
482
483 int h = -1;
d7ae4a62 484 GetCurrentFont()->GetHeight(&h);
b3c86150
VS
485 return YDEV2LOGREL(h);
486}
487
4a624f6e 488wxCoord wxDFBDCImpl::GetCharWidth() const
b3c86150 489{
4a624f6e 490 wxCHECK_MSG( IsOk(), -1, wxT("invalid dc") );
a1b806b9 491 wxCHECK_MSG( m_font.IsOk(), -1, wxT("no font selected") );
b3c86150
VS
492
493 int w = -1;
d7ae4a62 494 GetCurrentFont()->GetStringWidth("H", 1, &w);
b3c86150
VS
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
4a624f6e 500void wxDFBDCImpl::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y,
b3c86150 501 wxCoord *descent, wxCoord *externalLeading,
c94f845b 502 const wxFont *theFont) const
b3c86150 503{
4a624f6e 504 wxCHECK_RET( IsOk(), wxT("invalid dc") );
a1b806b9
DS
505 wxCHECK_RET( m_font.IsOk(), wxT("no font selected") );
506 wxCHECK_RET( !theFont || theFont->IsOk(), wxT("invalid font") );
b3c86150
VS
507
508 wxFont oldFont;
509 if ( theFont != NULL )
510 {
511 oldFont = m_font;
4a624f6e 512 wxConstCast(this, wxDFBDCImpl)->SetFont(*theFont);
b3c86150
VS
513 }
514
515 wxCoord xx = 0, yy = 0;
516 DFBRectangle rect;
d7ae4a62 517 wxIDirectFBFontPtr f = GetCurrentFont();
b3c86150 518
26f03c44 519 if ( f->GetStringExtents(string.utf8_str(), -1, &rect, NULL) )
b3c86150
VS
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;
52c8d32a 529 if ( f->GetDescender(&d) )
b3c86150
VS
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 )
4a624f6e 541 wxConstCast(this, wxDFBDCImpl)->SetFont(oldFont);
b3c86150
VS
542}
543
544
545
546// ---------------------------------------------------------------------------
547// mapping modes
548// ---------------------------------------------------------------------------
549
04ab8b6d
RR
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
4a624f6e
VZ
553
554void wxDFBDCImpl::DoGetSize(int *w, int *h) const
b3c86150 555{
4a624f6e 556 wxCHECK_RET( IsOk(), wxT("invalid dc") );
b3c86150 557
52c8d32a 558 m_surface->GetSize(w, h);
b3c86150
VS
559}
560
4a624f6e 561void wxDFBDCImpl::DoGetSizeMM(int *width, int *height) const
b3c86150
VS
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
4a624f6e 571wxSize wxDFBDCImpl::GetPPI() const
b3c86150
VS
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
4a624f6e
VZ
583bool wxDFBDCImpl::DoBlit(wxCoord xdest, wxCoord ydest,
584 wxCoord width, wxCoord height,
585 wxDC *source, wxCoord xsrc, wxCoord ysrc,
89efaf2b 586 wxRasterOperationMode rop, bool useMask,
4a624f6e 587 wxCoord xsrcMask, wxCoord ysrcMask)
b3c86150 588{
4a624f6e 589 wxCHECK_MSG( IsOk(), false, "invalid dc" );
a5001e93 590 wxCHECK_MSG( source, false, "invalid source dc" );
5942996c
VS
591
592 // NB: we could also support XOR here (via DSBLIT_XOR)
593 // and possibly others via SetSrc/DstBlendFunction()
a5001e93 594 wxCHECK_MSG( rop == wxCOPY, false, "only wxCOPY function supported" );
b3c86150
VS
595
596 // transform the source DC coords to the device ones
597 xsrc = source->LogicalToDeviceX(xsrc);
598 ysrc = source->LogicalToDeviceY(ysrc);
599
5942996c
VS
600 // FIXME_DFB: use the mask origin when drawing transparently
601 wxASSERT_MSG( xsrcMask == -1 && ysrcMask == -1,
a5001e93 602 "non-default source mask offset not implemented" );
5942996c 603#if 0
b3c86150
VS
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 }
5942996c 613#endif
b3c86150 614
5942996c
VS
615 wxMemoryDC *sourceAsMemDC = wxDynamicCast(source, wxMemoryDC);
616 if ( sourceAsMemDC )
b3c86150 617 {
4a624f6e 618 DoDrawSubBitmap(sourceAsMemDC->GetSelectedBitmap(),
5942996c
VS
619 xsrc, ysrc,
620 width, height,
621 xdest, ydest,
622 rop,
623 useMask);
b3c86150
VS
624 }
625 else
626 {
4a624f6e
VZ
627 return DoBlitFromSurface
628 (
629 static_cast<wxDFBDCImpl *>(source->GetImpl())
630 ->GetDirectFBSurface(),
631 xsrc, ysrc,
632 width, height,
633 xdest, ydest
634 );
b3c86150
VS
635 }
636
637 return true;
b3c86150
VS
638}
639
4a624f6e 640void wxDFBDCImpl::DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask)
b3c86150 641{
4a624f6e 642 wxCHECK_RET( IsOk(), wxT("invalid dc") );
a1b806b9 643 wxCHECK_RET( bmp.IsOk(), wxT("invalid bitmap") );
b3c86150 644
5942996c
VS
645 DoDrawSubBitmap(bmp,
646 0, 0, bmp.GetWidth(), bmp.GetHeight(),
647 x, y,
648 m_logicalFunction, useMask);
b3c86150
VS
649}
650
4a624f6e 651void wxDFBDCImpl::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
b3c86150
VS
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
4a624f6e 657void wxDFBDCImpl::DoDrawSubBitmap(const wxBitmap &bmp,
b3c86150
VS
658 wxCoord x, wxCoord y, wxCoord w, wxCoord h,
659 wxCoord destx, wxCoord desty, int rop, bool useMask)
660{
4a624f6e 661 wxCHECK_RET( IsOk(), wxT("invalid dc") );
a1b806b9 662 wxCHECK_RET( bmp.IsOk(), wxT("invalid bitmap") );
b3c86150 663
5942996c
VS
664 // NB: we could also support XOR here (via DSBLIT_XOR)
665 // and possibly others via SetSrc/DstBlendFunction()
a5001e93 666 wxCHECK_RET( rop == wxCOPY, "only wxCOPY function supported" );
b3c86150
VS
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.
a5001e93 672 wxFAIL_MSG( "drawing mono bitmaps not implemented" );
5942996c 673 return;
b3c86150
VS
674 }
675
676 if ( useMask && bmp.GetMask() )
677 {
0e1f8ea4 678 // FIXME_DFB: Could use blitting modes for this; also see
5942996c 679 // DFB's SetSrcBlendFunction() and SetSrcColorKey()
a5001e93 680 wxFAIL_MSG( "drawing bitmaps with masks not implemented" );
5942996c
VS
681 return;
682 }
b3c86150 683
5942996c
VS
684 DoBlitFromSurface(bmp.GetDirectFBSurface(),
685 x, y,
686 w, h,
687 destx, desty);
688}
b3c86150 689
4a624f6e
VZ
690bool wxDFBDCImpl::DoBlitFromSurface(const wxIDirectFBSurfacePtr& src,
691 wxCoord srcx, wxCoord srcy,
692 wxCoord w, wxCoord h,
693 wxCoord dstx, wxCoord dsty)
5942996c 694{
21e3246c
VS
695 // don't do anything if the source rectangle is outside of source surface,
696 // DirectFB would assert in that case:
697 wxSize srcsize;
698 src->GetSize(&srcsize.x, &srcsize.y);
699 if ( !wxRect(srcx, srcy, w, h).Intersects(wxRect(srcsize)) )
700 {
a5001e93 701 wxLogDebug("Blitting from area outside of the source surface, caller code needs fixing.");
21e3246c
VS
702 return false;
703 }
704
5942996c
VS
705 CalcBoundingBox(dstx, dsty);
706 CalcBoundingBox(dstx + w, dsty + h);
b3c86150 707
5942996c
VS
708 DFBRectangle srcRect = { srcx, srcy, w, h };
709 DFBRectangle dstRect = { XLOG2DEV(dstx), YLOG2DEV(dsty),
710 XLOG2DEVREL(w), YLOG2DEVREL(h) };
b3c86150 711
5942996c 712 wxIDirectFBSurfacePtr dst(m_surface);
b3c86150 713
5942996c 714 // FIXME: this will have to be different in useMask case, see above
e2badebb
VS
715 DFBSurfaceBlittingFlags blitFlag = (src->GetPixelFormat() == DSPF_ARGB)
716 ? DSBLIT_BLEND_ALPHACHANNEL
717 : DSBLIT_NOFX;
718 if ( !dst->SetBlittingFlags(blitFlag) )
5942996c 719 return false;
b3c86150 720
5942996c
VS
721 if ( srcRect.w != dstRect.w || srcRect.h != dstRect.h )
722 {
723 // the bitmap is drawn stretched:
724 dst->StretchBlit(src, &srcRect, &dstRect);
b3c86150 725 }
b3c86150
VS
726 else
727 {
5942996c
VS
728 // no stretching, size is preserved:
729 dst->Blit(src, &srcRect, dstRect.x, dstRect.y);
b3c86150 730 }
5942996c
VS
731
732 return true;
b3c86150 733}