// Purpose: graphics context methods common to all platforms
// Author: Stefan Csomor
// Modified by:
-// Created:
+// Created:
// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
#if wxUSE_GRAPHICS_CONTEXT
-#include "wx/graphics.h"
+#include "wx/private/graphics.h"
#ifndef WX_PRECOMP
#include "wx/icon.h"
{
m_renderer = data->m_renderer;
}
-wxGraphicsRenderer* wxGraphicsObjectRefData::GetRenderer() const
-{
- return m_renderer ;
+wxGraphicsRenderer* wxGraphicsObjectRefData::GetRenderer() const
+{
+ return m_renderer ;
}
-wxGraphicsObjectRefData* wxGraphicsObjectRefData::Clone() const
+wxGraphicsObjectRefData* wxGraphicsObjectRefData::Clone() const
{
return new wxGraphicsObjectRefData(this);
}
-wxGraphicsObject::wxGraphicsObject()
+wxGraphicsObject::wxGraphicsObject()
{
}
-wxGraphicsObject::wxGraphicsObject( wxGraphicsRenderer* renderer )
+wxGraphicsObject::wxGraphicsObject( wxGraphicsRenderer* renderer )
{
SetRefData( new wxGraphicsObjectRefData(renderer));
}
-wxGraphicsObject::~wxGraphicsObject()
+wxGraphicsObject::~wxGraphicsObject()
{
}
-bool wxGraphicsObject::IsNull() const
-{
- return m_refData == NULL;
+bool wxGraphicsObject::IsNull() const
+{
+ return m_refData == NULL;
}
-wxGraphicsRenderer* wxGraphicsObject::GetRenderer() const
-{
- return ( IsNull() ? NULL : GetGraphicsData()->GetRenderer() );
+wxGraphicsRenderer* wxGraphicsObject::GetRenderer() const
+{
+ return ( IsNull() ? NULL : GetGraphicsData()->GetRenderer() );
}
-wxGraphicsObjectRefData* wxGraphicsObject::GetGraphicsData() const
-{
- return (wxGraphicsObjectRefData*) m_refData;
+wxGraphicsObjectRefData* wxGraphicsObject::GetGraphicsData() const
+{
+ return (wxGraphicsObjectRefData*) m_refData;
}
wxObjectRefData* wxGraphicsObject::CreateRefData() const
IMPLEMENT_DYNAMIC_CLASS(wxGraphicsPen, wxGraphicsObject)
IMPLEMENT_DYNAMIC_CLASS(wxGraphicsBrush, wxGraphicsObject)
IMPLEMENT_DYNAMIC_CLASS(wxGraphicsFont, wxGraphicsObject)
+IMPLEMENT_DYNAMIC_CLASS(wxGraphicsBitmap, wxGraphicsObject)
WXDLLIMPEXP_DATA_CORE(wxGraphicsPen) wxNullGraphicsPen;
WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush) wxNullGraphicsBrush;
WXDLLIMPEXP_DATA_CORE(wxGraphicsFont) wxNullGraphicsFont;
+WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap) wxNullGraphicsBitmap;
//-----------------------------------------------------------------------------
// matrix
}
// sets the matrix to the respective values
-void wxGraphicsMatrix::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d,
+void wxGraphicsMatrix::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d,
wxDouble tx, wxDouble ty)
{
AllocExclusive();
{
AllocExclusive();
GetMatrixData()->Rotate(angle);
-}
+}
//
// apply the transforms
wxRect2DDouble wxGraphicsPath::GetBox() const
{
- wxDouble x,y,w,h;
- GetBox(&x,&y,&w,&h);
- return wxRect2DDouble( x,y,w,h );
+ wxDouble x,y,w,h;
+ GetBox(&x,&y,&w,&h);
+ return wxRect2DDouble( x,y,w,h );
}
-bool wxGraphicsPath::Contains( const wxPoint2DDouble& c, int fillStyle ) const
+bool wxGraphicsPath::Contains( const wxPoint2DDouble& c, wxPolygonFillMode fillStyle ) const
{
return Contains( c.m_x, c.m_y, fillStyle);
}
GetPathData()->MoveToPoint(x,y);
}
-// adds a straight line from the current point to (x,y)
+// adds a straight line from the current point to (x,y)
void wxGraphicsPath::AddLineToPoint( wxDouble x, wxDouble y )
{
AllocExclusive();
}
//
-// These are convenience functions which - if not available natively will be assembled
+// These are convenience functions which - if not available natively will be assembled
// using the primitives from above
//
GetPathData()->AddQuadCurveToPoint(cx,cy,x,y);
}
-// appends a rectangle as a new closed subpath
+// appends a rectangle as a new closed subpath
void wxGraphicsPath::AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
{
AllocExclusive();
}
// appends a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)
-void wxGraphicsPath::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r )
+void wxGraphicsPath::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r )
{
GetPathData()->AddArcToPoint(x1,y1,x2,y2,r);
}
GetPathData()->GetBox(x,y,w,h);
}
-bool wxGraphicsPath::Contains( wxDouble x, wxDouble y, int fillStyle ) const
+bool wxGraphicsPath::Contains( wxDouble x, wxDouble y, wxPolygonFillMode fillStyle ) const
{
return GetPathData()->Contains(x,y,fillStyle);
}
void wxGraphicsPathData::AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h)
{
+ if (w <= 0. || h <= 0.)
+ return;
+
wxDouble rw = w/2;
wxDouble rh = h/2;
wxDouble xc = x + rw;
// draws a an arc to two tangents connecting (current) to (x1,y1) and (x1,y1) to (x2,y2), also a straight line from (current) to (x1,y1)
void wxGraphicsPathData::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r )
-{
+{
wxPoint2DDouble current;
GetCurrentPoint(¤t.m_x,¤t.m_y);
wxPoint2DDouble p1(x1,y1);
IMPLEMENT_ABSTRACT_CLASS(wxGraphicsContext, wxObject)
-wxGraphicsContext::wxGraphicsContext(wxGraphicsRenderer* renderer) : wxGraphicsObject(renderer)
+wxGraphicsContext::wxGraphicsContext(wxGraphicsRenderer* renderer) : wxGraphicsObject(renderer)
{
m_logicalFunction = wxCOPY;
}
-wxGraphicsContext::~wxGraphicsContext()
+wxGraphicsContext::~wxGraphicsContext()
{
}
-bool wxGraphicsContext::StartDoc(const wxString& WXUNUSED(message))
+bool wxGraphicsContext::StartDoc(const wxString& WXUNUSED(message))
{
return true;
}
-
+
void wxGraphicsContext::EndDoc()
{
}
wxDouble WXUNUSED(height))
{
}
-
+
void wxGraphicsContext::EndPage()
{
}
void wxGraphicsContext::SetAlpha( wxDouble WXUNUSED(alpha) )
{
}
-
+
wxDouble wxGraphicsContext::GetAlpha() const
{
return 1.0;
}
// sets the pen
-void wxGraphicsContext::SetPen( const wxGraphicsPen& pen )
+void wxGraphicsContext::SetPen( const wxGraphicsPen& pen )
{
m_pen = pen;
}
else
SetPen( CreatePen( pen ) );
}
-
+
// sets the brush for filling
-void wxGraphicsContext::SetBrush( const wxGraphicsBrush& brush )
+void wxGraphicsContext::SetBrush( const wxGraphicsBrush& brush )
{
m_brush = brush;
}
}
// sets the brush for filling
-void wxGraphicsContext::SetFont( const wxGraphicsFont& font )
+void wxGraphicsContext::SetFont( const wxGraphicsFont& font )
{
m_font = font;
}
-bool wxGraphicsContext::SetLogicalFunction( int function )
+bool wxGraphicsContext::SetLogicalFunction( wxRasterOperationMode function )
{
if ( function == wxCOPY )
{
SetFont( wxNullGraphicsFont );
}
-void wxGraphicsContext::DrawPath( const wxGraphicsPath& path, int fillStyle )
+void wxGraphicsContext::DrawPath( const wxGraphicsPath& path, wxPolygonFillMode fillStyle )
{
FillPath( path , fillStyle );
StrokePath( path );
}
-void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle )
+void
+wxGraphicsContext::DoDrawRotatedText(const wxString &str,
+ wxDouble x,
+ wxDouble y,
+ wxDouble angle)
{
Translate(x,y);
Rotate( -angle );
Translate(-x,-y);
}
-void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, const wxGraphicsBrush& backgroundBrush )
+void
+wxGraphicsContext::DoDrawFilledText(const wxString &str,
+ wxDouble x,
+ wxDouble y,
+ const wxGraphicsBrush& backgroundBrush)
{
wxGraphicsBrush formerBrush = m_brush;
- wxGraphicsPen formerPen = m_pen;
+ wxGraphicsPen formerPen = m_pen;
wxDouble width;
wxDouble height;
wxDouble descent;
wxDouble externalLeading;
GetTextExtent( str , &width, &height, &descent, &externalLeading );
SetBrush( backgroundBrush );
- // to make sure our 'OffsetToPixelBoundaries' doesn't move the fill shape
- SetPen( wxNullGraphicsPen );
+ // to make sure our 'OffsetToPixelBoundaries' doesn't move the fill shape
+ SetPen( wxNullGraphicsPen );
wxGraphicsPath path = CreatePath();
path.AddRectangle( x , y, width, height );
DrawText( str, x ,y);
SetBrush( formerBrush );
- SetPen( formerPen );
+ SetPen( formerPen );
}
-void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle, const wxGraphicsBrush& backgroundBrush )
+void
+wxGraphicsContext::DoDrawRotatedFilledText(const wxString &str,
+ wxDouble x, wxDouble y,
+ wxDouble angle,
+ const wxGraphicsBrush& backgroundBrush)
{
wxGraphicsBrush formerBrush = m_brush;
- wxGraphicsPen formerPen = m_pen;
+ wxGraphicsPen formerPen = m_pen;
wxDouble width;
wxDouble height;
wxDouble externalLeading;
GetTextExtent( str , &width, &height, &descent, &externalLeading );
SetBrush( backgroundBrush );
- // to make sure our 'OffsetToPixelBoundaries' doesn't move the fill shape
- SetPen( wxNullGraphicsPen );
+ // to make sure our 'OffsetToPixelBoundaries' doesn't move the fill shape
+ SetPen( wxNullGraphicsPen );
wxGraphicsPath path = CreatePath();
path.MoveToPoint( x , y );
FillPath( path );
DrawText( str, x ,y, angle);
SetBrush( formerBrush );
- SetPen( formerPen );
+ SetPen( formerPen );
}
void wxGraphicsContext::StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2)
StrokePath( path );
}
-void wxGraphicsContext::DrawLines( size_t n, const wxPoint2DDouble *points, int fillStyle)
+void wxGraphicsContext::DrawLines( size_t n, const wxPoint2DDouble *points, wxPolygonFillMode fillStyle)
{
wxASSERT(n > 1);
wxGraphicsPath path = CreatePath();
}
// create a 'native' matrix corresponding to these values
-wxGraphicsMatrix wxGraphicsContext::CreateMatrix( wxDouble a, wxDouble b, wxDouble c, wxDouble d,
+wxGraphicsMatrix wxGraphicsContext::CreateMatrix( wxDouble a, wxDouble b, wxDouble c, wxDouble d,
wxDouble tx, wxDouble ty) const
{
return GetRenderer()->CreateMatrix(a,b,c,d,tx,ty);
}
// sets the brush to a linear gradient, starting at (x1,y1) with color c1 to (x2,y2) with color c2
-wxGraphicsBrush wxGraphicsContext::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
+wxGraphicsBrush wxGraphicsContext::CreateLinearGradientBrush( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2,
const wxColour&c1, const wxColour&c2) const
{
return GetRenderer()->CreateLinearGradientBrush(x1,y1,x2,y2,c1,c2);
}
-// sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
+// sets the brush to a radial gradient originating at (xo,yc) with color oColor and ends on a circle around (xc,yc)
// with radius r and color cColor
wxGraphicsBrush wxGraphicsContext::CreateRadialGradientBrush( wxDouble xo, wxDouble yo, wxDouble xc, wxDouble yc, wxDouble radius,
const wxColour &oColor, const wxColour &cColor) const
return GetRenderer()->CreateFont(font,col);
}
-wxGraphicsContext* wxGraphicsContext::Create( const wxWindowDC& dc)
+wxGraphicsBitmap wxGraphicsContext::CreateBitmap( const wxBitmap& bmp ) const
+{
+#ifndef __WXGTK20__
+ return GetRenderer()->CreateBitmap(bmp);
+#else
+ return wxNullGraphicsBitmap;
+#endif
+}
+
+wxGraphicsBitmap wxGraphicsContext::CreateSubBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) const
+{
+#ifndef __WXGTK20__
+ return GetRenderer()->CreateSubBitmap(bmp,x,y,w,h);
+#else
+ return wxNullGraphicsBitmap;
+#endif
+}
+
+/* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxWindowDC& dc)
+{
+ return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc);
+}
+
+/* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxMemoryDC& dc)
{
return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc);
}
-wxGraphicsContext* wxGraphicsContext::Create( const wxMemoryDC& dc)
+#if wxUSE_PRINTING_ARCHITECTURE
+/* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxPrinterDC& dc)
{
return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc);
}
+#endif
wxGraphicsContext* wxGraphicsContext::CreateFromNative( void * context )
{