+ if ( clockwise )
+ {
+ if( sweepAngle < 0 )
+ sweepAngle += 2 * M_PI;
+ }
+ else
+ {
+ if( sweepAngle > 0 )
+ sweepAngle -= 2 * M_PI;
+
+ }
+ }
+ m_path->AddArc((REAL) (x-r),(REAL) (y-r),(REAL) (2*r),(REAL) (2*r),RadToDeg(startAngle),RadToDeg(sweepAngle));
+}
+
+void wxGDIPlusPathData::AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
+{
+ m_path->AddRectangle(RectF(x,y,w,h));
+}
+
+void wxGDIPlusPathData::AddPath( const wxGraphicsPathData* path )
+{
+ m_path->AddPath( (GraphicsPath*) path->GetNativePath(), FALSE);
+}
+
+
+// transforms each point of this path by the matrix
+void wxGDIPlusPathData::Transform( const wxGraphicsMatrixData* matrix )
+{
+ m_path->Transform( (Matrix*) matrix->GetNativeMatrix() );
+}
+
+// gets the bounding box enclosing all points (possibly including control points)
+void wxGDIPlusPathData::GetBox(wxDouble *x, wxDouble *y, wxDouble *w, wxDouble *h) const
+{
+ RectF bounds;
+ m_path->GetBounds( &bounds, NULL, NULL) ;
+ *x = bounds.X;
+ *y = bounds.Y;
+ *w = bounds.Width;
+ *h = bounds.Height;
+}
+
+bool wxGDIPlusPathData::Contains( wxDouble x, wxDouble y, wxPolygonFillMode fillStyle ) const
+{
+ m_path->SetFillMode( fillStyle == wxODDEVEN_RULE ? FillModeAlternate : FillModeWinding);
+ return m_path->IsVisible( (FLOAT) x,(FLOAT) y) == TRUE ;
+}
+
+//-----------------------------------------------------------------------------
+// wxGDIPlusMatrixData implementation
+//-----------------------------------------------------------------------------
+
+wxGDIPlusMatrixData::wxGDIPlusMatrixData(wxGraphicsRenderer* renderer, Matrix* matrix )
+ : wxGraphicsMatrixData(renderer)
+{
+ if ( matrix )
+ m_matrix = matrix ;
+ else
+ m_matrix = new Matrix();
+}
+
+wxGDIPlusMatrixData::~wxGDIPlusMatrixData()
+{
+ delete m_matrix;
+}
+
+wxGraphicsObjectRefData *wxGDIPlusMatrixData::Clone() const
+{
+ return new wxGDIPlusMatrixData( GetRenderer(), m_matrix->Clone());
+}
+
+// concatenates the matrix
+void wxGDIPlusMatrixData::Concat( const wxGraphicsMatrixData *t )
+{
+ m_matrix->Multiply( (Matrix*) t->GetNativeMatrix());
+}
+
+// sets the matrix to the respective values
+void wxGDIPlusMatrixData::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d,
+ wxDouble tx, wxDouble ty)
+{
+ m_matrix->SetElements(a,b,c,d,tx,ty);
+}
+
+// gets the component valuess of the matrix
+void wxGDIPlusMatrixData::Get(wxDouble* a, wxDouble* b, wxDouble* c,
+ wxDouble* d, wxDouble* tx, wxDouble* ty) const
+{
+ REAL elements[6];
+ m_matrix->GetElements(elements);
+ if (a) *a = elements[0];
+ if (b) *b = elements[1];
+ if (c) *c = elements[2];
+ if (d) *d = elements[3];
+ if (tx) *tx= elements[4];
+ if (ty) *ty= elements[5];
+}
+
+// makes this the inverse matrix
+void wxGDIPlusMatrixData::Invert()
+{
+ m_matrix->Invert();
+}
+
+// returns true if the elements of the transformation matrix are equal ?
+bool wxGDIPlusMatrixData::IsEqual( const wxGraphicsMatrixData* t) const
+{
+ return m_matrix->Equals((Matrix*) t->GetNativeMatrix())== TRUE ;
+}
+
+// return true if this is the identity matrix
+bool wxGDIPlusMatrixData::IsIdentity() const
+{
+ return m_matrix->IsIdentity() == TRUE ;
+}
+
+//
+// transformation
+//
+
+// add the translation to this matrix
+void wxGDIPlusMatrixData::Translate( wxDouble dx , wxDouble dy )
+{
+ m_matrix->Translate(dx,dy);
+}
+
+// add the scale to this matrix
+void wxGDIPlusMatrixData::Scale( wxDouble xScale , wxDouble yScale )
+{
+ m_matrix->Scale(xScale,yScale);
+}
+
+// add the rotation to this matrix (radians)
+void wxGDIPlusMatrixData::Rotate( wxDouble angle )
+{
+ m_matrix->Rotate( RadToDeg(angle) );
+}
+
+//
+// apply the transforms
+//
+
+// applies that matrix to the point
+void wxGDIPlusMatrixData::TransformPoint( wxDouble *x, wxDouble *y ) const
+{
+ PointF pt(*x,*y);
+ m_matrix->TransformPoints(&pt);
+ *x = pt.X;
+ *y = pt.Y;
+}
+
+// applies the matrix except for translations
+void wxGDIPlusMatrixData::TransformDistance( wxDouble *dx, wxDouble *dy ) const
+{
+ PointF pt(*dx,*dy);
+ m_matrix->TransformVectors(&pt);
+ *dx = pt.X;
+ *dy = pt.Y;
+}
+
+// returns the native representation
+void * wxGDIPlusMatrixData::GetNativeMatrix() const
+{
+ return m_matrix;
+}
+
+//-----------------------------------------------------------------------------
+// wxGDIPlusContext implementation
+//-----------------------------------------------------------------------------
+
+class wxGDIPlusOffsetHelper
+{
+public :
+ wxGDIPlusOffsetHelper( Graphics* gr , bool offset )
+ {
+ m_gr = gr;
+ m_offset = offset;
+ if ( m_offset )
+ m_gr->TranslateTransform( 0.5, 0.5 );
+ }
+ ~wxGDIPlusOffsetHelper( )
+ {
+ if ( m_offset )
+ m_gr->TranslateTransform( -0.5, -0.5 );
+ }
+public :
+ Graphics* m_gr;
+ bool m_offset;
+} ;
+
+wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, HDC hdc, wxDouble width, wxDouble height )
+ : wxGraphicsContext(renderer)
+{
+ Init(new Graphics(hdc), width, height);
+}
+
+wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, const wxDC& dc )
+ : wxGraphicsContext(renderer)
+{
+ wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl );
+ HDC hdc = (HDC) msw->GetHDC();
+ wxSize sz = dc.GetSize();
+
+ Init(new Graphics(hdc), sz.x, sz.y);
+}
+
+wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, HWND hwnd )
+ : wxGraphicsContext(renderer)
+{
+ RECT rect = wxGetWindowRect(hwnd);
+ Init(new Graphics(hwnd), rect.right - rect.left, rect.bottom - rect.top);
+ m_enableOffset = true;
+}
+
+wxGDIPlusContext::wxGDIPlusContext( wxGraphicsRenderer* renderer, Graphics* gr )
+ : wxGraphicsContext(renderer)
+{
+ Init(gr, 0, 0);
+}
+
+wxGDIPlusContext::wxGDIPlusContext(wxGraphicsRenderer* renderer)
+ : wxGraphicsContext(renderer)
+{
+ // Derived class must call Init() later but just set m_context to NULL for
+ // safety to avoid crashing in our dtor if Init() ends up not being called.
+ m_context = NULL;
+}
+
+void wxGDIPlusContext::Init(Graphics* graphics, int width, int height)
+{
+ m_context = graphics;
+ m_state1 = 0;
+ m_state2 = 0;
+ m_width = width;
+ m_height = height;
+ m_fontScaleRatio = 1.0;
+
+ m_context->SetTextRenderingHint(TextRenderingHintSystemDefault);
+ m_context->SetPixelOffsetMode(PixelOffsetModeHalf);
+ m_context->SetSmoothingMode(SmoothingModeHighQuality);
+ m_context->SetInterpolationMode(InterpolationModeHighQuality);
+ m_state1 = m_context->Save();
+ m_state2 = m_context->Save();
+}
+
+wxGDIPlusContext::~wxGDIPlusContext()
+{
+ if ( m_context )
+ {
+ m_context->Restore( m_state2 );
+ m_context->Restore( m_state1 );
+ delete m_context;
+ }
+}
+
+
+void wxGDIPlusContext::Clip( const wxRegion ®ion )
+{
+ Region rgn((HRGN)region.GetHRGN());
+ m_context->SetClip(&rgn,CombineModeIntersect);
+}
+
+void wxGDIPlusContext::Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
+{
+ m_context->SetClip(RectF(x,y,w,h),CombineModeIntersect);
+}
+
+void wxGDIPlusContext::ResetClip()
+{
+ m_context->ResetClip();
+}
+
+void wxGDIPlusContext::DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h )
+{
+ if (m_composition == wxCOMPOSITION_DEST)
+ return;
+
+ wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() );
+ Brush *brush = m_brush.IsNull() ? NULL : ((wxGDIPlusBrushData*)m_brush.GetRefData())->GetGDIPlusBrush();
+ Pen *pen = m_pen.IsNull() ? NULL : ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen();
+
+ if ( brush )
+ {
+ // the offset is used to fill only the inside of the rectangle and not paint underneath
+ // its border which may influence a transparent Pen
+ REAL offset = 0;
+ if ( pen )
+ offset = pen->GetWidth();
+ m_context->FillRectangle( brush, (REAL)x + offset/2, (REAL)y + offset/2, (REAL)w - offset, (REAL)h - offset);
+ }
+
+ if ( pen )
+ {
+ m_context->DrawRectangle( pen, (REAL)x, (REAL)y, (REAL)w, (REAL)h );
+ }
+}
+
+void wxGDIPlusContext::StrokeLines( size_t n, const wxPoint2DDouble *points)
+{
+ if (m_composition == wxCOMPOSITION_DEST)
+ return;
+
+ if ( !m_pen.IsNull() )
+ {
+ wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() );
+ Point *cpoints = new Point[n];
+ for (size_t i = 0; i < n; i++)
+ {
+ cpoints[i].X = (int)(points[i].m_x );
+ cpoints[i].Y = (int)(points[i].m_y );
+
+ } // for (size_t i = 0; i < n; i++)
+ m_context->DrawLines( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , cpoints , n ) ;
+ delete[] cpoints;
+ }
+}
+
+void wxGDIPlusContext::DrawLines( size_t n, const wxPoint2DDouble *points, wxPolygonFillMode WXUNUSED(fillStyle) )
+{
+ if (m_composition == wxCOMPOSITION_DEST)
+ return;
+
+ wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() );
+ Point *cpoints = new Point[n];
+ for (size_t i = 0; i < n; i++)
+ {
+ cpoints[i].X = (int)(points[i].m_x );
+ cpoints[i].Y = (int)(points[i].m_y );
+
+ } // for (int i = 0; i < n; i++)
+ if ( !m_brush.IsNull() )
+ m_context->FillPolygon( ((wxGDIPlusBrushData*)m_brush.GetRefData())->GetGDIPlusBrush() , cpoints , n ) ;
+ if ( !m_pen.IsNull() )
+ m_context->DrawLines( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , cpoints , n ) ;
+ delete[] cpoints;
+}
+
+void wxGDIPlusContext::StrokePath( const wxGraphicsPath& path )
+{
+ if (m_composition == wxCOMPOSITION_DEST)
+ return;
+
+ if ( !m_pen.IsNull() )
+ {
+ wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() );
+ m_context->DrawPath( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , (GraphicsPath*) path.GetNativePath() );
+ }
+}
+
+void wxGDIPlusContext::FillPath( const wxGraphicsPath& path , wxPolygonFillMode fillStyle )
+{
+ if (m_composition == wxCOMPOSITION_DEST)
+ return;
+
+ if ( !m_brush.IsNull() )
+ {
+ wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() );
+ ((GraphicsPath*) path.GetNativePath())->SetFillMode( fillStyle == wxODDEVEN_RULE ? FillModeAlternate : FillModeWinding);
+ m_context->FillPath( ((wxGDIPlusBrushData*)m_brush.GetRefData())->GetGDIPlusBrush() ,
+ (GraphicsPath*) path.GetNativePath());
+ }
+}
+
+bool wxGDIPlusContext::SetAntialiasMode(wxAntialiasMode antialias)
+{
+ if (m_antialias == antialias)
+ return true;
+
+ m_antialias = antialias;
+
+ SmoothingMode antialiasMode;
+ switch (antialias)
+ {
+ case wxANTIALIAS_DEFAULT:
+ antialiasMode = SmoothingModeHighQuality;
+ break;
+ case wxANTIALIAS_NONE:
+ antialiasMode = SmoothingModeNone;
+ break;
+ default:
+ return false;
+ }
+ m_context->SetSmoothingMode(antialiasMode);
+ return true;
+}
+
+bool wxGDIPlusContext::SetInterpolationQuality(wxInterpolationQuality interpolation)
+{
+ if (m_interpolation == interpolation)
+ return true;
+
+ InterpolationMode interpolationMode = InterpolationModeDefault;
+ switch (interpolation)
+ {
+ case wxINTERPOLATION_DEFAULT:
+ interpolationMode = InterpolationModeDefault;
+ break;
+
+ case wxINTERPOLATION_NONE:
+ interpolationMode = InterpolationModeNearestNeighbor;
+ break;
+
+ case wxINTERPOLATION_FAST:
+ interpolationMode = InterpolationModeLowQuality;
+ break;
+
+ case wxINTERPOLATION_GOOD:
+ interpolationMode = InterpolationModeHighQuality;
+ break;
+
+ case wxINTERPOLATION_BEST:
+ interpolationMode = InterpolationModeHighQualityBicubic;
+ break;
+
+ default:
+ return false;
+ }
+
+ if ( m_context->SetInterpolationMode(interpolationMode) != Gdiplus::Ok )
+ return false;
+
+ m_interpolation = interpolation;
+
+ return true;
+}
+
+bool wxGDIPlusContext::SetCompositionMode(wxCompositionMode op)
+{
+ if ( m_composition == op )
+ return true;
+
+ m_composition = op;
+
+ if (m_composition == wxCOMPOSITION_DEST)
+ return true;
+
+ CompositingMode cop;
+ switch (op)
+ {
+ case wxCOMPOSITION_SOURCE:
+ cop = CompositingModeSourceCopy;
+ break;
+ case wxCOMPOSITION_OVER:
+ cop = CompositingModeSourceOver;
+ break;
+ default:
+ return false;
+ }
+
+ m_context->SetCompositingMode(cop);
+ return true;
+}
+
+void wxGDIPlusContext::BeginLayer(wxDouble /* opacity */)
+{
+ // TODO
+}
+
+void wxGDIPlusContext::EndLayer()
+{
+ // TODO
+}
+
+void wxGDIPlusContext::Rotate( wxDouble angle )
+{
+ m_context->RotateTransform( RadToDeg(angle) );
+}
+
+void wxGDIPlusContext::Translate( wxDouble dx , wxDouble dy )
+{
+ m_context->TranslateTransform( dx , dy );
+}
+
+void wxGDIPlusContext::Scale( wxDouble xScale , wxDouble yScale )
+{
+ m_context->ScaleTransform(xScale,yScale);
+}
+
+void wxGDIPlusContext::PushState()
+{
+ GraphicsState state = m_context->Save();
+ m_stateStack.push(state);
+}
+
+void wxGDIPlusContext::PopState()
+{
+ wxCHECK_RET( !m_stateStack.empty(), wxT("No state to pop") );
+
+ GraphicsState state = m_stateStack.top();
+ m_stateStack.pop();
+ m_context->Restore(state);
+}
+
+void wxGDIPlusContext::DrawBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
+{
+ if (m_composition == wxCOMPOSITION_DEST)
+ return;
+
+ Bitmap* image = static_cast<wxGDIPlusBitmapData*>(bmp.GetRefData())->GetGDIPlusBitmap();
+ if ( image )
+ {
+ if( image->GetWidth() != (UINT) w || image->GetHeight() != (UINT) h )
+ {
+ Rect drawRect((REAL) x, (REAL)y, (REAL)w, (REAL)h);
+ m_context->SetPixelOffsetMode( PixelOffsetModeNone );
+ m_context->DrawImage(image, drawRect, 0 , 0 , image->GetWidth(), image->GetHeight(), UnitPixel ) ;
+ m_context->SetPixelOffsetMode( PixelOffsetModeHalf );
+ }
+ else
+ m_context->DrawImage(image,(REAL) x,(REAL) y,(REAL) w,(REAL) h) ;
+ }
+}
+
+void wxGDIPlusContext::DrawBitmap( const wxBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
+{
+ wxGraphicsBitmap bitmap = GetRenderer()->CreateBitmap(bmp);
+ DrawBitmap(bitmap, x, y, w, h);
+}
+
+void wxGDIPlusContext::DrawIcon( const wxIcon &icon, wxDouble x, wxDouble y, wxDouble w, wxDouble h )
+{
+ if (m_composition == wxCOMPOSITION_DEST)
+ return;
+
+ // the built-in conversion fails when there is alpha in the HICON (eg XP style icons), we can only
+ // find out by looking at the bitmap data whether there really was alpha in it
+ HICON hIcon = (HICON)icon.GetHICON();
+ ICONINFO iconInfo ;
+ // IconInfo creates the bitmaps for color and mask, we must dispose of them after use
+ if (!GetIconInfo(hIcon,&iconInfo))
+ return;
+
+ Bitmap interim(iconInfo.hbmColor,NULL);