#ifndef WX_PRECOMP
#include "wx/dc.h"
+ #include "wx/dcmemory.h"
#include "wx/log.h"
#endif
wxDC::wxDC(const wxIDirectFBSurfacePtr& surface)
{
- Init(surface);
+ DFBInit(surface);
}
-void wxDC::Init(const wxIDirectFBSurfacePtr& surface)
+void wxDC::DFBInit(const wxIDirectFBSurfacePtr& surface)
{
m_ok = (surface != NULL);
wxCHECK_RET( surface != NULL, _T("invalid 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.
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());
}
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);
wxFont f(font.Ok() ? font : DEFAULT_FONT);
- if ( !m_surface->SetFont(f.GetDirectFBFont()) )
- return;
+ wxFont oldfont(m_font);
m_font = f;
+
+ if ( !m_surface->SetFont(GetCurrentFont()) )
+ {
+ m_font = oldfont;
+ return;
+ }
+}
+
+wxIDirectFBFontPtr wxDC::GetCurrentFont() const
+{
+ bool aa = (GetDepth() > 8);
+ return m_font.GetDirectFBFont(aa);
}
void wxDC::SetBackground(const wxBrush& brush)
wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") );
int h = -1;
- m_font.GetDirectFBFont()->GetHeight(&h);
+ GetCurrentFont()->GetHeight(&h);
return YDEV2LOGREL(h);
}
wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") );
int w = -1;
- m_font.GetDirectFBFont()->GetStringWidth("H", 1, &w);
+ GetCurrentFont()->GetStringWidth("H", 1, &w);
// VS: YDEV is corrent, it should *not* be XDEV, because font's are only
// scaled according to m_scaleY
return YDEV2LOGREL(w);
wxCoord xx = 0, yy = 0;
DFBRectangle rect;
- wxIDirectFBFontPtr f = m_font.GetDirectFBFont();
+ wxIDirectFBFontPtr f = GetCurrentFont();
if ( f->GetStringExtents(wxSTR_TO_DFB(string), -1, &rect, NULL) )
{
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);