#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 "wx/stack.h"
-#include <vector>
-
-using namespace std;
+WX_DECLARE_STACK(GraphicsState, GraphicsStates);
//-----------------------------------------------------------------------------
// constants
#include <commdlg.h>
#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);
GraphicsPath* m_path;
};
-class WXDLLIMPEXP_CORE wxGDIPlusMatrixData : public wxGraphicsMatrixData
+class wxGDIPlusMatrixData : public wxGraphicsMatrixData
{
public :
wxGDIPlusMatrixData(wxGraphicsRenderer* renderer, Matrix* matrix = NULL) ;
// 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();
Matrix* m_matrix ;
} ;
-class WXDLLIMPEXP_CORE wxGDIPlusPenData : public wxGraphicsObjectRefData
+class wxGDIPlusPenData : public wxGraphicsObjectRefData
{
public:
wxGDIPlusPenData( wxGraphicsRenderer* renderer, const wxPen &pen );
wxDouble m_width;
};
-class WXDLLIMPEXP_CORE wxGDIPlusBrushData : public wxGraphicsObjectRefData
+class wxGDIPlusBrushData : public wxGraphicsObjectRefData
{
public:
wxGDIPlusBrushData( wxGraphicsRenderer* renderer );
GraphicsPath* m_brushPath;
};
-class WXDLLIMPEXP_CORE wxGDIPlusFontData : public wxGraphicsObjectRefData
+class wxGDIPlusFontData : public wxGraphicsObjectRefData
{
public:
wxGDIPlusFontData( wxGraphicsRenderer* renderer, const wxFont &font, const wxColour& col );
Font* m_font;
};
-class WXDLLIMPEXP_CORE wxGDIPlusContext : public wxGraphicsContext
+class wxGDIPlusContext : public wxGraphicsContext
{
public:
wxGDIPlusContext( wxGraphicsRenderer* renderer, HDC hdc );
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<GraphicsState> m_stateStack;
+ GraphicsStates m_stateStack;
GraphicsState m_state1;
GraphicsState m_state2;
void wxGDIPlusPathData::AddArc( wxDouble x, wxDouble y, wxDouble r, double startAngle, double endAngle, bool clockwise )
{
double sweepAngle = endAngle - startAngle ;
- if( abs(sweepAngle) >= 2*M_PI)
+ if( fabs(sweepAngle) >= 2*M_PI)
{
sweepAngle = 2 * M_PI;
}
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);
}
helper->GetPixelFormat(),&data);
image = new Bitmap(data.Width, data.Height, data.Stride,
- PixelFormat32bppARGB , (BYTE*) data.Scan0);
+ PixelFormat32bppPARGB , (BYTE*) data.Scan0);
helper->UnlockBits(&data);
}
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 ;
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;
// wxGDIPlusRenderer declaration
//-----------------------------------------------------------------------------
-class WXDLLIMPEXP_CORE wxGDIPlusRenderer : public wxGraphicsRenderer
+class wxGDIPlusRenderer : public wxGraphicsRenderer
{
public :
wxGDIPlusRenderer()
void EnsureIsLoaded();
void Load();
void Unload();
+ friend class wxGDIPlusRendererModule;
private :
bool m_loaded;
void wxGDIPlusRenderer::Unload()
{
if ( m_gditoken )
+ {
GdiplusShutdown(m_gditoken);
+ m_gditoken = NULL;
+ }
+ m_loaded = false;
}
wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxWindowDC& dc)
return wxNullGraphicsFont;
}
+// Shutdown GDI+ at app exit, before possible dll unload
+class wxGDIPlusRendererModule : public wxModule
+{
+public:
+ virtual bool OnInit() { return true; }
+ virtual void OnExit() { gs_GDIPlusRenderer.Unload(); }
+
+private:
+ DECLARE_DYNAMIC_CLASS(wxGDIPlusRendererModule)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRendererModule, wxModule)
+
#endif // wxUSE_GRAPHICS_CONTEXT