From 54a03e061d191ac0c4b95407cdc1595f112a80cb Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Fri, 14 Jan 2022 11:37:41 +0100 Subject: [PATCH] turn around rectangular gradients as well --- examples/boxes/main.cpp | 4 ++-- src/nodes/QskBoxRendererRect.cpp | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/boxes/main.cpp b/examples/boxes/main.cpp index b2135e82..6958fd17 100644 --- a/examples/boxes/main.cpp +++ b/examples/boxes/main.cpp @@ -364,7 +364,7 @@ static void addColoredBorderRectangles1( QskLinearBox* parent, bool rounded ) auto* box = new Box( parent ); box->setBorderWidth( 20 ); QskGradient gradient1( Qt::Vertical, { { 0.0, Qt::blue }, - { 0.9, Qt::yellow }, + { 0.7, Qt::yellow }, { 1.0, Qt::darkRed } } ); QskGradient gradient2( Qt::Vertical, { { 0.0, Qt::black }, { 0.3, Qt::white }, @@ -523,7 +523,7 @@ int main( int argc, char* argv[] ) // ### remove: QskWindow window; -#if 0 +#if 1 auto* tabView = new TabView(); window.addItem( tabView ); #else diff --git a/src/nodes/QskBoxRendererRect.cpp b/src/nodes/QskBoxRendererRect.cpp index 5b72c6b2..295ddde2 100644 --- a/src/nodes/QskBoxRendererRect.cpp +++ b/src/nodes/QskBoxRendererRect.cpp @@ -464,13 +464,16 @@ static inline void qskCreateBorder( ( line++ )->setLine( x1, y1, x2, y2, c ); } - for( const QskGradientStop& stop : gradientRight.stops() ) + // ### can we make this easier somehow? + for( int i = gradientRight.stops().count() - 1; i >= 0; --i ) +// for( const QskGradientStop& stop : gradientRight.stops() ) { + auto stop = gradientRight.stops().at( i ); const Color c( stop.color() ); const qreal x1 = in.right; const qreal x2 = out.right; - const qreal y1 = in.bottom + stop.position() * ( in.top - in.bottom ); - const qreal y2 = out.bottom + stop.position() * ( out.top - out.bottom ); + const qreal y1 = in.bottom + (1-stop.position()) * ( in.top - in.bottom ); + const qreal y2 = out.bottom + (1-stop.position()) * ( out.top - out.bottom ); ( line++ )->setLine( x1, y1, x2, y2, c ); }