X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cb3a0d420a58658bffb26e9d7430f292c2d639d6..69659fd770f615210efac4b4fa741b3ad6223616:/src/msw/graphics.cpp?ds=sidebyside diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index d7b1c86969..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) ; @@ -175,6 +163,10 @@ public : virtual void Set(wxDouble a=1.0, wxDouble b=0.0, wxDouble c=0.0, wxDouble d=1.0, wxDouble tx=0.0, wxDouble ty=0.0); + // gets the component valuess of the matrix + virtual void Get(wxDouble* a=NULL, wxDouble* b=NULL, wxDouble* c=NULL, + wxDouble* d=NULL, wxDouble* tx=NULL, wxDouble* ty=NULL) const; + // makes this the inverse matrix virtual void Invert(); @@ -213,7 +205,7 @@ private: Matrix* m_matrix ; } ; -class WXDLLIMPEXP_CORE wxGDIPlusPenData : public wxGraphicsObjectRefData +class wxGDIPlusPenData : public wxGraphicsObjectRefData { public: wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &pen ); @@ -232,7 +224,7 @@ protected : wxDouble m_width; }; -class WXDLLIMPEXP_CORE wxGDIPlusBrushData : public wxGraphicsObjectRefData +class wxGDIPlusBrushData : public wxGraphicsObjectRefData { public: wxGDIPlusBrushData( wxGraphicsRenderer* renderer ); @@ -254,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 ); @@ -267,7 +259,7 @@ private : Font* m_font; }; -class WXDLLIMPEXP_CORE wxGDIPlusContext : public wxGraphicsContext +class wxGDIPlusContext : public wxGraphicsContext { public: wxGDIPlusContext( wxGraphicsRenderer* renderer, HDC hdc ); @@ -311,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; @@ -766,6 +759,20 @@ void wxGDIPlusMatrixData::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d, 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() { @@ -946,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); } @@ -1162,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 ; @@ -1171,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; @@ -1206,7 +1226,7 @@ wxGraphicsMatrix wxGDIPlusContext::GetTransform() const // wxGDIPlusRenderer declaration //----------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxGDIPlusRenderer : public wxGraphicsRenderer +class wxGDIPlusRenderer : public wxGraphicsRenderer { public : wxGDIPlusRenderer()