#include "wx/dcprint.h"
#endif
+#include "wx/stack.h"
+
#include "wx/private/graphics.h"
#include "wx/msw/wrapgdip.h"
#include "wx/msw/dc.h"
#include <commdlg.h>
#endif
-#include "wx/stack.h"
-
namespace
{
virtual void StrokePath( const wxGraphicsPath& p );
virtual void FillPath( const wxGraphicsPath& p , wxPolygonFillMode fillStyle = wxODDEVEN_RULE );
+ virtual void DrawRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h );
+
// stroke lines connecting each of the points
virtual void StrokeLines( size_t n, const wxPoint2DDouble *points);
virtual bool SetAntialiasMode(wxAntialiasMode antialias);
+ virtual bool SetInterpolationQuality(wxInterpolationQuality interpolation);
+
virtual bool SetCompositionMode(wxCompositionMode op);
virtual void BeginLayer(wxDouble opacity);
GraphicsState m_state1;
GraphicsState m_state2;
- wxDouble m_width;
- wxDouble m_height;
-
DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusContext)
};
DashStyle dashStyle = DashStyleSolid;
switch ( pen.GetStyle() )
{
- case wxSOLID :
+ case wxPENSTYLE_SOLID :
break;
- case wxDOT :
+ case wxPENSTYLE_DOT :
dashStyle = DashStyleDot;
break;
- case wxLONG_DASH :
+ case wxPENSTYLE_LONG_DASH :
dashStyle = DashStyleDash; // TODO verify
break;
- case wxSHORT_DASH :
+ case wxPENSTYLE_SHORT_DASH :
dashStyle = DashStyleDash;
break;
- case wxDOT_DASH :
+ case wxPENSTYLE_DOT_DASH :
dashStyle = DashStyleDashDot;
break;
- case wxUSER_DASH :
+ case wxPENSTYLE_USER_DASH :
{
dashStyle = DashStyleCustom;
wxDash *dashes;
}
}
break;
- case wxSTIPPLE :
+ case wxPENSTYLE_STIPPLE :
{
wxBitmap* bmp = pen.GetStipple();
- if ( bmp && bmp->Ok() )
+ if ( bmp && bmp->IsOk() )
{
m_penImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),
#if wxUSE_PALETTE
}
break;
default :
- if ( pen.GetStyle() >= wxFIRST_HATCH && pen.GetStyle() <= wxLAST_HATCH )
+ if ( pen.GetStyle() >= wxPENSTYLE_FIRST_HATCH &&
+ pen.GetStyle() <= wxPENSTYLE_LAST_HATCH )
{
- HatchStyle style = HatchStyleHorizontal;
+ HatchStyle style;
switch( pen.GetStyle() )
{
- case wxBDIAGONAL_HATCH :
+ case wxPENSTYLE_BDIAGONAL_HATCH :
style = HatchStyleBackwardDiagonal;
break ;
- case wxCROSSDIAG_HATCH :
+ case wxPENSTYLE_CROSSDIAG_HATCH :
style = HatchStyleDiagonalCross;
break ;
- case wxFDIAGONAL_HATCH :
+ case wxPENSTYLE_FDIAGONAL_HATCH :
style = HatchStyleForwardDiagonal;
break ;
- case wxCROSS_HATCH :
+ case wxPENSTYLE_CROSS_HATCH :
style = HatchStyleCross;
break ;
- case wxHORIZONTAL_HATCH :
+ case wxPENSTYLE_HORIZONTAL_HATCH :
style = HatchStyleHorizontal;
break ;
- case wxVERTICAL_HATCH :
+ case wxPENSTYLE_VERTICAL_HATCH :
style = HatchStyleVertical;
break ;
-
+ default:
+ style = HatchStyleHorizontal;
}
m_penBrush = new HatchBrush
(
}
else if ( brush.IsHatch() )
{
- HatchStyle style = HatchStyleHorizontal;
+ HatchStyle style;
switch( brush.GetStyle() )
{
- case wxBDIAGONAL_HATCH :
+ case wxBRUSHSTYLE_BDIAGONAL_HATCH :
style = HatchStyleBackwardDiagonal;
break ;
- case wxCROSSDIAG_HATCH :
+ case wxBRUSHSTYLE_CROSSDIAG_HATCH :
style = HatchStyleDiagonalCross;
break ;
- case wxFDIAGONAL_HATCH :
+ case wxBRUSHSTYLE_FDIAGONAL_HATCH :
style = HatchStyleForwardDiagonal;
break ;
- case wxCROSS_HATCH :
+ case wxBRUSHSTYLE_CROSS_HATCH :
style = HatchStyleCross;
break ;
- case wxHORIZONTAL_HATCH :
+ case wxBRUSHSTYLE_HORIZONTAL_HATCH :
style = HatchStyleHorizontal;
break ;
- case wxVERTICAL_HATCH :
+ case wxBRUSHSTYLE_VERTICAL_HATCH :
style = HatchStyleVertical;
break ;
-
+ default:
+ style = HatchStyleHorizontal;
}
m_brush = new HatchBrush
(
else
{
wxBitmap* bmp = brush.GetStipple();
- if ( bmp && bmp->Ok() )
+ if ( bmp && bmp->IsOk() )
{
wxDELETE( m_brushImage );
m_brushImage = Bitmap::FromHBITMAP((HBITMAP)bmp->GetHBITMAP(),
: wxGraphicsContext(renderer)
{
Init();
+ m_enableOffset = true;
m_context = new Graphics( hwnd);
RECT rect = wxGetWindowRect(hwnd);
m_width = rect.right - rect.left;
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 true;
}
+bool wxGDIPlusContext::SetInterpolationQuality(wxInterpolationQuality WXUNUSED(interpolation))
+{
+ // placeholder
+ return false;
+}
+
bool wxGDIPlusContext::SetCompositionMode(wxCompositionMode op)
{
if ( m_composition == op )
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);
{
Rect drawRect((REAL) x, (REAL)y, (REAL)w, (REAL)h);
m_context->SetPixelOffsetMode( PixelOffsetModeNone );
- m_context->DrawImage(image, drawRect, 0 , 0 , image->GetWidth()-1, image->GetHeight()-1, UnitPixel ) ;
+ m_context->DrawImage(image, drawRect, 0 , 0 , image->GetWidth(), image->GetHeight(), UnitPixel ) ;
m_context->SetPixelOffsetMode( PixelOffsetModeHalf );
}
else
bool wxGDIPlusContext::ShouldOffset() const
{
+ if ( !m_enableOffset )
+ return false;
+
int penwidth = 0 ;
if ( !m_pen.IsNull() )
{
if ( m_gditoken )
{
GdiplusShutdown(m_gditoken);
- m_gditoken = NULL;
+ m_gditoken = 0;
}
m_loaded = -1; // next Load() will try again
}
wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxWindowDC& dc)
{
ENSURE_LOADED_OR_RETURN(NULL);
- return new wxGDIPlusContext(this, dc);
+ wxGDIPlusContext* context = new wxGDIPlusContext(this, dc);
+ context->EnableOffset(true);
+ return context;
}
#if wxUSE_PRINTING_ARCHITECTURE
wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxMemoryDC& dc)
{
ENSURE_LOADED_OR_RETURN(NULL);
- return new wxGDIPlusContext(this, dc);
+ wxGDIPlusContext* context = new wxGDIPlusContext(this, dc);
+ context->EnableOffset(true);
+ return context;
}
wxGraphicsContext * wxGDIPlusRenderer::CreateMeasuringContext()
wxGraphicsPen wxGDIPlusRenderer::CreatePen(const wxPen& pen)
{
ENSURE_LOADED_OR_RETURN(wxNullGraphicsPen);
- if ( !pen.Ok() || pen.GetStyle() == wxTRANSPARENT )
+ if ( !pen.IsOk() || pen.GetStyle() == wxTRANSPARENT )
return wxNullGraphicsPen;
else
{
wxGraphicsBrush wxGDIPlusRenderer::CreateBrush(const wxBrush& brush )
{
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBrush);
- if ( !brush.Ok() || brush.GetStyle() == wxTRANSPARENT )
+ if ( !brush.IsOk() || brush.GetStyle() == wxTRANSPARENT )
return wxNullGraphicsBrush;
else
{
const wxColour &col )
{
ENSURE_LOADED_OR_RETURN(wxNullGraphicsFont);
- if ( font.Ok() )
+ if ( font.IsOk() )
{
wxGraphicsFont p;
p.SetRefData(new wxGDIPlusFontData( this, gc, font, col ));
wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmap( const wxBitmap &bitmap )
{
ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap);
- if ( bitmap.Ok() )
+ if ( bitmap.IsOk() )
{
wxGraphicsBitmap p;
p.SetRefData(new wxGDIPlusBitmapData( this , bitmap ));