]> git.saurik.com Git - wxWidgets.git/blobdiff - src/dfb/dc.cpp
fix wxGetFreeMemory() for Linux 2.6 (part of patch 1549176)
[wxWidgets.git] / src / dfb / dc.cpp
index 60afcaa00e93df56717e5ab39065abff2a3115a5..f5d6a1691ddcf77cefcdde57a929480a5964f6a2 100644 (file)
 
 #include "wx/dfb/private.h"
 
+// these values are used to initialize newly created DC
+#define DEFAULT_FONT      (*wxNORMAL_FONT)
+#define DEFAULT_PEN       (*wxBLACK_PEN)
+#define DEFAULT_BRUSH     (*wxWHITE_BRUSH)
+
 // ===========================================================================
 // implementation
 // ===========================================================================
@@ -63,9 +68,9 @@ void wxDC::Init(const wxIDirectFBSurfacePtr& surface)
     m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() /
                     (double)wxGetDisplaySizeMM().GetHeight();
 
-    SetFont(*wxNORMAL_FONT);
-    SetPen(*wxBLACK_PEN);
-    SetBrush(*wxWHITE_BRUSH);
+    SetFont(DEFAULT_FONT);
+    SetPen(DEFAULT_PEN);
+    SetBrush(DEFAULT_BRUSH);
 }
 
 
@@ -87,11 +92,16 @@ void wxDC::DoSetClippingRegion(wxCoord cx, wxCoord cy, wxCoord cw, wxCoord ch)
 {
     wxCHECK_RET( Ok(), wxT("invalid dc") );
 
+    wxSize size(GetSize());
+
+    // 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.
     DFBRegion r;
-    r.x1 = XLOG2DEV(cx);
-    r.y1 = YLOG2DEV(cy);
-    r.x2 = r.x1 + XLOG2DEVREL(cw) - 1;
-    r.y2 = r.y1 + XLOG2DEVREL(ch) - 1;
+    r.x1 = wxMax(0, XLOG2DEV(cx));
+    r.y1 = wxMax(0, YLOG2DEV(cy));
+    r.x2 = wxMin(r.x1 + XLOG2DEVREL(cw), size.x) - 1;
+    r.y2 = wxMin(r.y1 + YLOG2DEVREL(ch), size.y) - 1;
 
     if ( !m_surface->SetClip(&r) )
         return;
@@ -125,7 +135,7 @@ void wxDC::DestroyClippingRegion()
 
 int wxDC::GetDepth() const
 {
-    return wxDfbGetSurfaceDepth(m_surface);
+    return m_surface->GetDepth();
 }
 
 // ---------------------------------------------------------------------------
@@ -141,6 +151,10 @@ void wxDC::Clear()
 
     wxColour clr = m_backgroundBrush.GetColour();
     m_surface->Clear(clr.Red(), clr.Green(), clr.Blue(), clr.Alpha());
+
+    wxSize size(GetSize());
+    CalcBoundingBox(XDEV2LOG(0), YDEV2LOG(0));
+    CalcBoundingBox(XDEV2LOG(size.x), YDEV2LOG(size.y));
 }
 
 extern bool wxDoFloodFill(wxDC *dc, wxCoord x, wxCoord y,
@@ -196,7 +210,12 @@ void wxDC::DoDrawPoint(wxCoord x, wxCoord y)
 {
     wxCHECK_RET( Ok(), wxT("invalid dc") );
 
-    wxFAIL_MSG( _T("DrawPoint not implemented") );
+    // NB: DirectFB API doesn't provide a function for drawing points, so
+    //     implement it as 1px long line. This is inefficient, but then, so is
+    //     using DrawPoint() for drawing more than a few points.
+    DoDrawLine(x, y, x, y);
+
+    // FIXME_DFB: implement special cases for common formats (RGB24,RGBA/RGB32)
 }
 
 void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int WXUNUSED(fillStyle))
@@ -279,7 +298,7 @@ void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y)
     wxCHECK_RET( Ok(), wxT("invalid dc") );
 
     wxCoord xx = XLOG2DEV(x);
-    wxCoord yy = XLOG2DEV(y);
+    wxCoord yy = YLOG2DEV(y);
 
     // update the bounding box
     wxCoord w, h;
@@ -317,16 +336,14 @@ void wxDC::DoDrawRotatedText(const wxString& text,
 
 void wxDC::SetPen(const wxPen& pen)
 {
-    if ( !pen.Ok() ) return;
-    m_pen = pen;
+    m_pen = pen.Ok() ? pen : DEFAULT_PEN;
 
     SelectColour(m_pen.GetColour());
 }
 
 void wxDC::SetBrush(const wxBrush& brush)
 {
-    if ( !brush.Ok() ) return;
-    m_brush = brush;
+    m_brush = brush.Ok() ? brush : DEFAULT_BRUSH;
 }
 
 void wxDC::SelectColour(const wxColour& clr)
@@ -348,13 +365,12 @@ void wxDC::SetFont(const wxFont& font)
 {
     wxCHECK_RET( Ok(), wxT("invalid dc") );
 
-    if ( !font.Ok() )
-        return;
+    wxFont f(font.Ok() ? font : DEFAULT_FONT);
 
-    if ( !m_surface->SetFont(font.GetDirectFBFont()) )
+    if ( !m_surface->SetFont(f.GetDirectFBFont()) )
         return;
 
-    m_font = font;
+    m_font = f;
 }
 
 void wxDC::SetBackground(const wxBrush& brush)