From 5ab99c0f698fa37abd55038cf0abc62bc0cc2d52 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 8 Mar 2007 00:25:37 +0000 Subject: [PATCH] More 0.5 pixel offset fixes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@44675 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/dcgraph.cpp | 14 ++++++++++++++ src/msw/graphics.cpp | 13 +++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index ff3c1c7e04..f795d13f05 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -693,6 +693,13 @@ void wxGCDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, if (w == 0 || h == 0) return; + if ( m_graphicContext->ShouldOffset() ) + { + // if we are offsetting the entire rectangle is moved 0.5, so the + // border line gets off by 1 + w -= 1; + h -= 1; + } m_graphicContext->DrawRoundedRectangle( x,y,w,h,radius); } @@ -703,6 +710,13 @@ void wxGCDC::DoDrawEllipse(wxCoord x, wxCoord y, wxCoord w, wxCoord h) if ( !m_logicalFunctionSupported ) return; + if ( m_graphicContext->ShouldOffset() ) + { + // if we are offsetting the entire rectangle is moved 0.5, so the + // border line gets off by 1 + w -= 1; + h -= 1; + } m_graphicContext->DrawEllipse(x,y,w,h); } diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index ff3313993a..31d4860294 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -315,6 +315,7 @@ public: virtual void GetTextExtent( const wxString &str, wxDouble *width, wxDouble *height, wxDouble *descent, wxDouble *externalLeading ) const; virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const; + virtual bool ShouldOffset() const; private: void Init(); @@ -1196,6 +1197,18 @@ void wxGDIPlusContext::GetPartialTextExtents(const wxString& text, wxArrayDouble } } +bool wxGDIPlusContext::ShouldOffset() const +{ + int penwidth = 0 ; + if ( !m_pen.IsNull() ) + { + penwidth = (int)((wxGDIPlusPenData*)m_pen.GetRefData())->GetWidth(); + if ( penwidth == 0 ) + penwidth = 1; + } + return ( penwidth % 2 ) == 1; +} + void* wxGDIPlusContext::GetNativeContext() { return m_context;