X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f4322df68b099e5e983acc0a3dad4ad5841b57b5..69659fd770f615210efac4b4fa741b3ad6223616:/src/msw/graphics.cpp diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index d41d1db4c3..bda43979a7 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -17,29 +17,30 @@ #pragma hdrstop #endif +#if wxUSE_GRAPHICS_CONTEXT + #ifndef WX_PRECOMP -#include "wx/msw/wrapcdlg.h" -#include "wx/image.h" -#include "wx/window.h" -#include "wx/dc.h" -#include "wx/utils.h" -#include "wx/dialog.h" -#include "wx/app.h" -#include "wx/bitmap.h" -#include "wx/dcmemory.h" -#include "wx/log.h" -#include "wx/icon.h" -#include "wx/dcprint.h" -#include "wx/module.h" + #include "wx/msw/wrapcdlg.h" + #include "wx/image.h" + #include "wx/window.h" + #include "wx/dc.h" + #include "wx/utils.h" + #include "wx/dialog.h" + #include "wx/app.h" + #include "wx/bitmap.h" + #include "wx/dcmemory.h" + #include "wx/log.h" + #include "wx/icon.h" + #include "wx/dcprint.h" + #include "wx/module.h" #endif #include "wx/graphics.h" +#include "wx/msw/wrapgdip.h" -#if wxUSE_GRAPHICS_CONTEXT - -#include +#include "wx/stack.h" -using namespace std; +WX_DECLARE_STACK(GraphicsState, GraphicsStates); //----------------------------------------------------------------------------- // constants @@ -79,20 +80,7 @@ static inline double RadToDeg(double deg) { return (deg * 180.0) / M_PI; } #include #endif -// TODO remove this dependency (gdiplus needs the macros) - -#ifndef max -#define max(a,b) (((a) > (b)) ? (a) : (b)) -#endif - -#ifndef min -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#endif - -#include "gdiplus.h" -using namespace Gdiplus; - -class WXDLLIMPEXP_CORE wxGDIPlusPathData : public wxGraphicsPathData +class wxGDIPlusPathData : public wxGraphicsPathData { public : wxGDIPlusPathData(wxGraphicsRenderer* renderer, GraphicsPath* path = NULL); @@ -160,7 +148,7 @@ private : GraphicsPath* m_path; }; -class WXDLLIMPEXP_CORE wxGDIPlusMatrixData : public wxGraphicsMatrixData +class wxGDIPlusMatrixData : public wxGraphicsMatrixData { public : wxGDIPlusMatrixData(wxGraphicsRenderer* renderer, Matrix* matrix = NULL) ; @@ -217,7 +205,7 @@ private: Matrix* m_matrix ; } ; -class WXDLLIMPEXP_CORE wxGDIPlusPenData : public wxGraphicsObjectRefData +class wxGDIPlusPenData : public wxGraphicsObjectRefData { public: wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &pen ); @@ -236,7 +224,7 @@ protected : wxDouble m_width; }; -class WXDLLIMPEXP_CORE wxGDIPlusBrushData : public wxGraphicsObjectRefData +class wxGDIPlusBrushData : public wxGraphicsObjectRefData { public: wxGDIPlusBrushData( wxGraphicsRenderer* renderer ); @@ -258,7 +246,7 @@ private : GraphicsPath* m_brushPath; }; -class WXDLLIMPEXP_CORE wxGDIPlusFontData : public wxGraphicsObjectRefData +class wxGDIPlusFontData : public wxGraphicsObjectRefData { public: wxGDIPlusFontData( wxGraphicsRenderer* renderer, const wxFont &font, const wxColour& col ); @@ -271,7 +259,7 @@ private : Font* m_font; }; -class WXDLLIMPEXP_CORE wxGDIPlusContext : public wxGraphicsContext +class wxGDIPlusContext : public wxGraphicsContext { public: wxGDIPlusContext( wxGraphicsRenderer* renderer, HDC hdc ); @@ -315,13 +303,14 @@ 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(); void SetDefaults(); Graphics* m_context; - vector m_stateStack; + GraphicsStates m_stateStack; GraphicsState m_state1; GraphicsState m_state2; @@ -964,13 +953,13 @@ void wxGDIPlusContext::Scale( wxDouble xScale , wxDouble yScale ) void wxGDIPlusContext::PushState() { GraphicsState state = m_context->Save(); - m_stateStack.push_back(state); + m_stateStack.push(state); } void wxGDIPlusContext::PopState() { - GraphicsState state = m_stateStack.back(); - m_stateStack.pop_back(); + GraphicsState state = m_stateStack.top(); + m_stateStack.pop(); m_context->Restore(state); } @@ -1180,7 +1169,8 @@ void wxGDIPlusContext::GetPartialTextExtents(const wxString& text, wxArrayDouble CharacterRange* ranges = new CharacterRange[len] ; Region* regions = new Region[len]; - for( size_t i = 0 ; i < len ; ++i) + size_t i; + for( i = 0 ; i < len ; ++i) { ranges[i].First = i ; ranges[i].Length = 1 ; @@ -1189,13 +1179,25 @@ void wxGDIPlusContext::GetPartialTextExtents(const wxString& text, wxArrayDouble m_context->MeasureCharacterRanges(ws, -1 , f,layoutRect, &strFormat,1,regions) ; RectF bbox ; - for ( size_t i = 0 ; i < len ; ++i) + for ( i = 0 ; i < len ; ++i) { regions[i].GetBounds(&bbox,m_context); widths[i] = bbox.GetRight()-bbox.GetLeft(); } } +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; @@ -1224,7 +1226,7 @@ wxGraphicsMatrix wxGDIPlusContext::GetTransform() const // wxGDIPlusRenderer declaration //----------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxGDIPlusRenderer : public wxGraphicsRenderer +class wxGDIPlusRenderer : public wxGraphicsRenderer { public : wxGDIPlusRenderer()