From 202b377dbc3c721d2139e65461eb1e5162940c96 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 25 Aug 2014 17:50:58 +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/branches/WX_3_0_BRANCH@77482 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + src/msw/graphics.cpp | 32 +++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 37452cd9c8..91ce39369b 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -609,6 +609,7 @@ wxMSW: - Fix wxGrid appearance and behaviour in RTL (Artur Wieczorek). - Add paragraph spacing attributes support to wxTextCtrl (dannchr). - Show new style directory selector even for non existent paths (raychow). +- Fix order of radial gradient stops (Alexandru Pana). 3.0.1: (released 2014-06-15) diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index e46c3709c3..c0ce6da157 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -289,7 +289,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; @@ -857,7 +859,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 ) @@ -870,12 +873,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); @@ -914,7 +930,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); } //-----------------------------------------------------------------------------