X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5942996c94a82dcbedf7b1041b08acd8d1d97449..25d7497c18a95bb2953ccad72a127c955285ae84:/src/dfb/dc.cpp diff --git a/src/dfb/dc.cpp b/src/dfb/dc.cpp index f5fac4bcc0..60b3782b92 100644 --- a/src/dfb/dc.cpp +++ b/src/dfb/dc.cpp @@ -78,22 +78,15 @@ void wxDC::Init(const wxIDirectFBSurfacePtr& surface) // clipping // --------------------------------------------------------------------------- - -#define DO_SET_CLIPPING_BOX(rg) \ -{ \ - wxRect rect = rg.GetBox(); \ - m_clipX1 = (wxCoord) XDEV2LOG(rect.GetLeft()); \ - m_clipY1 = (wxCoord) YDEV2LOG(rect.GetTop()); \ - m_clipX2 = (wxCoord) XDEV2LOG(rect.GetRight()); \ - m_clipY2 = (wxCoord) YDEV2LOG(rect.GetBottom()); \ -} - void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch) { wxCHECK_RET( Ok(), wxT("invalid dc") ); wxSize size(GetSize()); + wxASSERT_MSG( !m_clipping, + _T("narrowing clipping region not implemented yet") ); + // NB: We intersect the clipping rectangle with surface's area here because // DirectFB will return an error if you try to set clipping rectangle // that is partially outside of the surface. @@ -115,8 +108,7 @@ void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch) void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) { - // NB: this can be done because wxDFB only supports - // rectangular regions + // NB: this can be done because wxDFB only supports rectangular regions SetClippingRegion(region.AsRect()); } @@ -188,8 +180,32 @@ void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) if ( m_pen.GetStyle() == wxTRANSPARENT ) return; - m_surface->DrawLine(XLOG2DEV(x1), YLOG2DEV(y1), - XLOG2DEV(x2), YLOG2DEV(y2)); + wxCoord xx1 = XLOG2DEV(x1); + wxCoord yy1 = YLOG2DEV(y1); + wxCoord xx2 = XLOG2DEV(x2); + wxCoord yy2 = YLOG2DEV(y2); + + // FIXME: DrawLine() shouldn't draw the last pixel, but DFB's DrawLine() + // does draw it. We should undo any change to the last pixel by + // using GetPixel() and PutPixel(), but until they are implemented, + // handle at least the special case of vertical and horizontal + // lines correctly: + if ( xx1 == xx2 ) + { + if ( yy1 < yy2 ) + yy2--; + else if ( yy1 > yy2 ) + yy2++; + } + if ( yy1 == yy2 ) + { + if ( xx1 < xx2 ) + xx2--; + else if ( xx1 > xx2 ) + xx2++; + } + + m_surface->DrawLine(xx1, yy1, xx2, yy2); CalcBoundingBox(x1, y1); CalcBoundingBox(x2, y2); @@ -259,7 +275,8 @@ void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { SelectColour(m_brush.GetColour()); m_surface->FillRectangle(xx, yy, ww, hh); - // restore pen's colour + // restore pen's colour, because other drawing functions expect the + // colour to be set to the pen: SelectColour(m_pen.GetColour()); } @@ -309,16 +326,22 @@ void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) // if background mode is solid, DrawText must paint text's background: if ( m_backgroundMode == wxSOLID ) { - wxCHECK_RET( m_backgroundBrush.Ok(), wxT("invalid background brush") ); + wxCHECK_RET( m_textBackgroundColour.Ok(), + wxT("invalid background color") ); - SelectColour(m_backgroundBrush.GetColour()); + SelectColour(m_textBackgroundColour); m_surface->FillRectangle(xx, yy, XLOG2DEVREL(w), YLOG2DEVREL(h)); - // restore pen's colour - SelectColour(m_pen.GetColour()); } // finally draw the text itself: + wxCHECK_RET( m_textForegroundColour.Ok(), + wxT("invalid foreground color") ); + SelectColour(m_textForegroundColour); m_surface->DrawString(wxSTR_TO_DFB(text), -1, xx, yy, DSTF_LEFT | DSTF_TOP); + + // restore pen's colour, because other drawing functions expect the colour + // to be set to the pen: + SelectColour(m_pen.GetColour()); } void wxDC::DoDrawRotatedText(const wxString& text, @@ -758,6 +781,16 @@ bool wxDC::DoBlitFromSurface(const wxIDirectFBSurfacePtr& src, wxCoord w, wxCoord h, wxCoord dstx, wxCoord dsty) { + // don't do anything if the source rectangle is outside of source surface, + // DirectFB would assert in that case: + wxSize srcsize; + src->GetSize(&srcsize.x, &srcsize.y); + if ( !wxRect(srcx, srcy, w, h).Intersects(wxRect(srcsize)) ) + { + wxLogDebug(_T("Blitting from area outside of the source surface, caller code needs fixing.")); + return false; + } + CalcBoundingBox(dstx, dsty); CalcBoundingBox(dstx + w, dsty + h);