From 2a0b7589734538cc794896494d4dd77fd7bb5b7b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 25 Aug 2014 17:47:53 +0000 Subject: [PATCH] Fix order of radial gradient stops in wxMSW. Ensure that the order of stops is consistent with the documentation and other platforms behaviour, i.e. they are counted from inside to outside of the circle and not vice versa, which happens to be the GDI+ convention. Closes #16443. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77481 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/graphics.cpp | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index 35237953b8..0ca6e03f73 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -281,7 +281,9 @@ protected: private: // common part of Create{Linear,Radial}GradientBrush() template - void SetGradientStops(T *brush, const wxGraphicsGradientStops& stops); + void SetGradientStops(T *brush, + const wxGraphicsGradientStops& stops, + bool reversed = false); Brush* m_brush; Image* m_brushImage; @@ -852,7 +854,8 @@ void wxGDIPlusBrushData::Init() template void wxGDIPlusBrushData::SetGradientStops(T *brush, - const wxGraphicsGradientStops& stops) + const wxGraphicsGradientStops& stops, + bool reversed) { const unsigned numStops = stops.GetCount(); if ( numStops <= 2 ) @@ -865,12 +868,25 @@ wxGDIPlusBrushData::SetGradientStops(T *brush, wxVector colors(numStops); wxVector positions(numStops); - for ( unsigned i = 0; i < numStops; i++ ) + if ( reversed ) { - wxGraphicsGradientStop stop = stops.Item(i); + for ( unsigned i = 0; i < numStops; i++ ) + { + wxGraphicsGradientStop stop = stops.Item(numStops - i - 1); - colors[i] = wxColourToColor(stop.GetColour()); - positions[i] = stop.GetPosition(); + colors[i] = wxColourToColor(stop.GetColour()); + positions[i] = 1.0 - stop.GetPosition(); + } + } + else + { + for ( unsigned i = 0; i < numStops; i++ ) + { + wxGraphicsGradientStop stop = stops.Item(i); + + colors[i] = wxColourToColor(stop.GetColour()); + positions[i] = stop.GetPosition(); + } } brush->SetInterpolationColors(&colors[0], &positions[0], numStops); @@ -909,7 +925,9 @@ wxGDIPlusBrushData::CreateRadialGradientBrush(wxDouble xo, wxDouble yo, int count = 1; brush->SetSurroundColors(&col, &count); - SetGradientStops(brush, stops); + // Because the GDI+ API draws radial gradients from outside towards the + // center we have to reverse the order of the gradient stops. + SetGradientStops(brush, stops, true); } //-----------------------------------------------------------------------------