X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5aac6f3f9563d5a56470982cc11c35c81f555671..b50e6e416e2b4cdc849ea6f24181094c0957d904:/src/msw/graphics.cpp diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index c60609ce1e..62d56a1023 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -11,12 +11,12 @@ #include "wx/wxprec.h" -#include "wx/dc.h" - #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif +#include "wx/dc.h" + #if wxUSE_GRAPHICS_CONTEXT #ifndef WX_PRECOMP @@ -40,6 +40,7 @@ #include "wx/private/graphics.h" #include "wx/msw/wrapgdip.h" #include "wx/msw/dc.h" +#include "wx/dcgraph.h" #include "wx/stack.h" @@ -298,7 +299,7 @@ public: virtual void StrokePath( const wxGraphicsPath& p ); virtual void FillPath( const wxGraphicsPath& p , wxPolygonFillMode fillStyle = wxODDEVEN_RULE ); - // stroke lines connecting each of the points + // stroke lines connecting each of the points virtual void StrokeLines( size_t n, const wxPoint2DDouble *points); // draws a polygon @@ -311,7 +312,7 @@ public: virtual void BeginLayer(wxDouble opacity); virtual void EndLayer(); - + virtual void Translate( wxDouble dx , wxDouble dy ); virtual void Scale( wxDouble xScale , wxDouble yScale ); virtual void Rotate( wxDouble angle ); @@ -1121,19 +1122,19 @@ void wxGDIPlusContext::StrokeLines( size_t n, const wxPoint2DDouble *points) if (m_composition == wxCOMPOSITION_DEST) return; - if ( !m_pen.IsNull() ) - { - wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() ); - Point *cpoints = new Point[n]; - for (size_t i = 0; i < n; i++) - { - cpoints[i].X = (int)(points[i].m_x ); - cpoints[i].Y = (int)(points[i].m_y ); - - } // for (size_t i = 0; i < n; i++) - m_context->DrawLines( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , cpoints , n ) ; - delete[] cpoints; - } + if ( !m_pen.IsNull() ) + { + wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() ); + Point *cpoints = new Point[n]; + for (size_t i = 0; i < n; i++) + { + cpoints[i].X = (int)(points[i].m_x ); + cpoints[i].Y = (int)(points[i].m_y ); + + } // for (size_t i = 0; i < n; i++) + m_context->DrawLines( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , cpoints , n ) ; + delete[] cpoints; + } } void wxGDIPlusContext::DrawLines( size_t n, const wxPoint2DDouble *points, wxPolygonFillMode WXUNUSED(fillStyle) ) @@ -1142,18 +1143,18 @@ void wxGDIPlusContext::DrawLines( size_t n, const wxPoint2DDouble *points, wxPol return; wxGDIPlusOffsetHelper helper( m_context , ShouldOffset() ); - Point *cpoints = new Point[n]; - for (size_t i = 0; i < n; i++) - { - cpoints[i].X = (int)(points[i].m_x ); - cpoints[i].Y = (int)(points[i].m_y ); + Point *cpoints = new Point[n]; + for (size_t i = 0; i < n; i++) + { + cpoints[i].X = (int)(points[i].m_x ); + cpoints[i].Y = (int)(points[i].m_y ); - } // for (int i = 0; i < n; i++) - if ( !m_brush.IsNull() ) - m_context->FillPolygon( ((wxGDIPlusBrushData*)m_brush.GetRefData())->GetGDIPlusBrush() , cpoints , n ) ; - if ( !m_pen.IsNull() ) - m_context->DrawLines( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , cpoints , n ) ; - delete[] cpoints; + } // for (int i = 0; i < n; i++) + if ( !m_brush.IsNull() ) + m_context->FillPolygon( ((wxGDIPlusBrushData*)m_brush.GetRefData())->GetGDIPlusBrush() , cpoints , n ) ; + if ( !m_pen.IsNull() ) + m_context->DrawLines( ((wxGDIPlusPenData*)m_pen.GetGraphicsData())->GetGDIPlusPen() , cpoints , n ) ; + delete[] cpoints; } void wxGDIPlusContext::StrokePath( const wxGraphicsPath& path ) @@ -1186,9 +1187,9 @@ bool wxGDIPlusContext::SetAntialiasMode(wxAntialiasMode antialias) { if (m_antialias == antialias) return true; - + m_antialias = antialias; - + SmoothingMode antialiasMode; switch (antialias) { @@ -1209,9 +1210,9 @@ bool wxGDIPlusContext::SetCompositionMode(wxCompositionMode op) { if ( m_composition == op ) return true; - + m_composition = op; - + if (m_composition == wxCOMPOSITION_DEST) return true; @@ -1240,7 +1241,7 @@ void wxGDIPlusContext::BeginLayer(wxDouble /* opacity */) void wxGDIPlusContext::EndLayer() { // TODO -} +} void wxGDIPlusContext::Rotate( wxDouble angle ) { @@ -1453,23 +1454,37 @@ void wxGDIPlusContext::GetPartialTextExtents(const wxString& text, wxArrayDouble RectF layoutRect(0,0, 100000.0f, 100000.0f); StringFormat strFormat( StringFormat::GenericTypographic() ); - CharacterRange* ranges = new CharacterRange[len] ; - Region* regions = new Region[len]; - for( size_t i = 0 ; i < len ; ++i) - { - ranges[i].First = i ; - ranges[i].Length = 1 ; - } - strFormat.SetMeasurableCharacterRanges(len,ranges); - strFormat.SetFormatFlags( StringFormatFlagsMeasureTrailingSpaces | strFormat.GetFormatFlags() ); - m_context->MeasureCharacterRanges(ws, -1 , f,layoutRect, &strFormat,1,regions) ; + size_t startPosition = 0; + size_t remainder = len; + const size_t maxSpan = 32; + CharacterRange* ranges = new CharacterRange[maxSpan] ; + Region* regions = new Region[maxSpan]; - RectF bbox ; - for ( size_t i = 0 ; i < len ; ++i) + while( remainder > 0 ) { - regions[i].GetBounds(&bbox,m_context); - widths[i] = bbox.GetRight()-bbox.GetLeft(); + size_t span = wxMin( maxSpan, remainder ); + + for( size_t i = 0 ; i < span ; ++i) + { + ranges[i].First = 0 ; + ranges[i].Length = startPosition+i+1 ; + } + strFormat.SetMeasurableCharacterRanges(span,ranges); + strFormat.SetFormatFlags( StringFormatFlagsMeasureTrailingSpaces | strFormat.GetFormatFlags() ); + m_context->MeasureCharacterRanges(ws, -1 , f,layoutRect, &strFormat,span,regions) ; + + RectF bbox ; + for ( size_t i = 0 ; i < span ; ++i) + { + regions[i].GetBounds(&bbox,m_context); + widths[startPosition+i] = bbox.Width; + } + remainder -= span; + startPosition += span; } + + delete[] ranges; + delete[] regions; } bool wxGDIPlusContext::ShouldOffset() const @@ -1580,6 +1595,9 @@ public : // create a native bitmap representation virtual wxGraphicsBitmap CreateBitmap( const wxBitmap &bitmap ); + // create a graphics bitmap from a native bitmap + virtual wxGraphicsBitmap CreateBitmapFromNativeBitmap( void* bitmap ); + // create a subimage from a native image representation virtual wxGraphicsBitmap CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ); @@ -1807,6 +1825,19 @@ wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmap( const wxBitmap &bitmap ) return wxNullGraphicsBitmap; } +wxGraphicsBitmap wxGDIPlusRenderer::CreateBitmapFromNativeBitmap( void *bitmap ) +{ + ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); + if ( bitmap != NULL ) + { + wxGraphicsBitmap p; + p.SetRefData(new wxGDIPlusBitmapData( this , (Bitmap*) bitmap )); + return p; + } + else + return wxNullGraphicsBitmap; +} + wxGraphicsBitmap wxGDIPlusRenderer::CreateSubBitmap( const wxGraphicsBitmap &bitmap, wxDouble x, wxDouble y, wxDouble w, wxDouble h ) { ENSURE_LOADED_OR_RETURN(wxNullGraphicsBitmap); @@ -1834,4 +1865,32 @@ private: IMPLEMENT_DYNAMIC_CLASS(wxGDIPlusRendererModule, wxModule) +// ---------------------------------------------------------------------------- +// wxMSW-specific parts of wxGCDC +// ---------------------------------------------------------------------------- + +WXHDC wxGCDC::AcquireHDC() +{ + wxGraphicsContext * const gc = GetGraphicsContext(); + if ( !gc ) + return NULL; + + Graphics * const g = static_cast(gc->GetNativeContext()); + return g ? g->GetHDC() : NULL; +} + +void wxGCDC::ReleaseHDC(WXHDC hdc) +{ + if ( !hdc ) + return; + + wxGraphicsContext * const gc = GetGraphicsContext(); + wxCHECK_RET( gc, "can't release HDC because there is no wxGraphicsContext" ); + + Graphics * const g = static_cast(gc->GetNativeContext()); + wxCHECK_RET( g, "can't release HDC because there is no Graphics" ); + + g->ReleaseHDC((HDC)hdc); +} + #endif // wxUSE_GRAPHICS_CONTEXT