X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8e108c1ec983157ea68a6b4b971e1d007a51e156..f5766910b6731eb03e82371416e9778203396ce7:/src/msw/graphics.cpp diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index 04d75772e6..e6ac141891 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -137,7 +137,6 @@ static GDILoader gGDILoader; class WXDLLEXPORT wxGDIPlusPath : public wxGraphicsPath { - DECLARE_NO_COPY_CLASS(wxGDIPlusPath) public : wxGDIPlusPath(); ~wxGDIPlusPath(); @@ -182,21 +181,36 @@ public : virtual void AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) ; */ - GraphicsPath* GetPath() const; + // returns the native path + virtual void * GetNativePath() const { return m_path; } + + // give the native path returned by GetNativePath() back (there might be some deallocations necessary) + virtual void UnGetNativePath(void * WXUNUSED(path)) {} + private : GraphicsPath* m_path; + DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusPath) }; class WXDLLEXPORT wxGDIPlusContext : public wxGraphicsContext { - DECLARE_NO_COPY_CLASS(wxGDIPlusContext) - public: - wxGDIPlusContext( WXHDC hdc ); + wxGDIPlusContext( HDC hdc ); + wxGDIPlusContext( HWND hwnd ); + wxGDIPlusContext( Graphics* gr); wxGDIPlusContext(); + virtual ~wxGDIPlusContext(); virtual void Clip( const wxRegion ®ion ); + // clips drawings to the rect + virtual void Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ); + + // resets the clipping to original extent + virtual void ResetClip(); + + virtual void * GetNativeContext(); + virtual void StrokePath( const wxGraphicsPath *p ); virtual void FillPath( const wxGraphicsPath *p , int fillStyle = wxWINDING_RULE ); @@ -224,6 +238,9 @@ public: virtual void GetPartialTextExtents(const wxString& text, wxArrayDouble& widths) const; private: + void Init(); + void SetDefaults(); + Graphics* m_context; vector m_stateStack; GraphicsState m_state1; @@ -243,8 +260,11 @@ private: Font* m_font; // wxPen m_pen; // wxBrush m_brush; + DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusContext) }; +IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusPath,wxGraphicsPath) + wxGDIPlusPath::wxGDIPlusPath() { m_path = new GraphicsPath(); @@ -255,11 +275,6 @@ wxGDIPlusPath::~wxGDIPlusPath() delete m_path; } -GraphicsPath* wxGDIPlusPath::GetPath() const -{ - return m_path; -} - // // The Primitives // @@ -328,30 +343,64 @@ void wxGDIPlusPath::AddRectangle( wxDouble x, wxDouble y, wxDouble w, wxDouble h m_path->AddRectangle(RectF(x,y,w,h)); } -// -// -// -/* -// closes the current subpath -void wxGDIPlusPath::AddArcToPoint( wxDouble x1, wxDouble y1 , wxDouble x2, wxDouble y2, wxDouble r ) +//----------------------------------------------------------------------------- +// wxGDIPlusContext implementation +//----------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusContext,wxGraphicsContext) + +wxGDIPlusContext::wxGDIPlusContext( HDC hdc ) { -// CGPathAddArcToPoint( m_path, NULL , x1, y1, x2, y2, r); + Init(); + m_context = new Graphics( hdc); + SetDefaults(); } -*/ +wxGDIPlusContext::wxGDIPlusContext( HWND hwnd ) +{ + Init(); + m_context = new Graphics( hwnd); + SetDefaults(); +} -//----------------------------------------------------------------------------- -// wxGDIPlusContext implementation -//----------------------------------------------------------------------------- +wxGDIPlusContext::wxGDIPlusContext( Graphics* gr ) +{ + Init(); + m_context = gr; + SetDefaults(); +} + +wxGDIPlusContext::wxGDIPlusContext() +{ + Init(); +} -wxGDIPlusContext::wxGDIPlusContext( WXHDC hdc ) +void wxGDIPlusContext::Init() { gGDILoader.EnsureIsLoaded(); - m_context = new Graphics( (HDC) hdc); + m_context = NULL; + m_state1 = 0; + m_state2= 0; + + m_pen = NULL; + m_penTransparent = true; + m_penImage = NULL; + m_penBrush = NULL; + + m_brush = NULL; + m_brushTransparent = true; + m_brushImage = NULL; + m_brushPath = NULL; + + m_textBrush = NULL; + m_font = NULL; +} + +void wxGDIPlusContext::SetDefaults() +{ m_context->SetSmoothingMode(SmoothingModeHighQuality); m_state1 = m_context->Save(); m_state2 = m_context->Save(); - // set defaults m_penTransparent = false; @@ -386,27 +435,35 @@ wxGDIPlusContext::~wxGDIPlusContext() } -void wxGDIPlusContext::Clip( const wxRegion & WXUNUSED(region) ) +void wxGDIPlusContext::Clip( const wxRegion ®ion ) +{ + m_context->SetClip((HRGN)region.GetHRGN(),CombineModeIntersect); +} + +void wxGDIPlusContext::Clip( wxDouble x, wxDouble y, wxDouble w, wxDouble h ) +{ + m_context->SetClip(RectF(x,y,w,h),CombineModeIntersect); +} + +void wxGDIPlusContext::ResetClip() { -// ClipCGContextToRegion ( m_context, &bounds , (RgnHandle) dc->m_macCurrentClipRgn ); + m_context->ResetClip(); } -void wxGDIPlusContext::StrokePath( const wxGraphicsPath *p ) +void wxGDIPlusContext::StrokePath( const wxGraphicsPath *path ) { if ( m_penTransparent ) return; - const wxGDIPlusPath* path = dynamic_cast< const wxGDIPlusPath*>( p ); - m_context->DrawPath( m_pen , path->GetPath() ); + m_context->DrawPath( m_pen , (GraphicsPath*) path->GetNativePath() ); } -void wxGDIPlusContext::FillPath( const wxGraphicsPath *p , int fillStyle ) +void wxGDIPlusContext::FillPath( const wxGraphicsPath *path , int fillStyle ) { if ( !m_brushTransparent ) { - const wxGDIPlusPath* path = dynamic_cast< const wxGDIPlusPath*>( p ); - path->GetPath()->SetFillMode( fillStyle == wxODDEVEN_RULE ? FillModeAlternate : FillModeWinding); - m_context->FillPath( m_brush , path->GetPath() ); + ((GraphicsPath*) path->GetNativePath())->SetFillMode( fillStyle == wxODDEVEN_RULE ? FillModeAlternate : FillModeWinding); + m_context->FillPath( m_brush , (GraphicsPath*) path->GetNativePath()); } } @@ -417,7 +474,7 @@ wxGraphicsPath* wxGDIPlusContext::CreatePath() void wxGDIPlusContext::Rotate( wxDouble angle ) { - m_context->RotateTransform( angle ); + m_context->RotateTransform( RadToDeg(angle) ); } void wxGDIPlusContext::Translate( wxDouble dx , wxDouble dy ) @@ -927,10 +984,26 @@ void wxGDIPlusContext::SetFont( const wxFont &font ) m_font = new Font( s , size , style ); } +void* wxGDIPlusContext::GetNativeContext() +{ + return m_context; +} + wxGraphicsContext* wxGraphicsContext::Create( const wxWindowDC& dc) { return new wxGDIPlusContext( (HDC) dc.GetHDC() ); } +wxGraphicsContext* wxGraphicsContext::Create( wxWindow * window ) +{ + return new wxGDIPlusContext( (HWND) window->GetHWND() ); +} + +wxGraphicsContext* wxGraphicsContext::CreateFromNative( void * context ) +{ + return new wxGDIPlusContext( (Graphics*) context ); +} + + #endif // wxUSE_GRAPHICS_CONTEXT