QskBoxBorderColors: Use gradients instead of colors
This commit is contained in:
parent
ab0fe2ac1c
commit
16df96700d
|
@ -19,19 +19,14 @@ static void qskRegisterBoxBorderColors()
|
|||
|
||||
Q_CONSTRUCTOR_FUNCTION( qskRegisterBoxBorderColors )
|
||||
|
||||
static inline bool qskIsVisble( const QColor& c )
|
||||
{
|
||||
return c.isValid() && ( c.alpha() > 0 );
|
||||
}
|
||||
|
||||
static inline void qskSetColors( const QColor& c, QColor* colors )
|
||||
static inline void qskSetColors( const QColor& c, QskGradient* colors )
|
||||
{
|
||||
colors[ 0 ] = colors[ 1 ] = colors[ 2 ] = colors[ 3 ] = c.toRgb();
|
||||
}
|
||||
|
||||
static inline void qskSetColors(
|
||||
const QColor& left, const QColor& top,
|
||||
const QColor& right, const QColor& bottom, QColor* colors )
|
||||
const QColor& right, const QColor& bottom, QskGradient* colors )
|
||||
{
|
||||
colors[ Qsk::Left ] = left.toRgb();
|
||||
colors[ Qsk::Top ] = top.toRgb();
|
||||
|
@ -47,12 +42,12 @@ QskBoxBorderColors::QskBoxBorderColors(
|
|||
const QColor& left, const QColor& top,
|
||||
const QColor& right, const QColor& bottom )
|
||||
{
|
||||
qskSetColors( left, top, right, bottom, m_colors );
|
||||
qskSetColors( left, top, right, bottom, m_gradients );
|
||||
}
|
||||
|
||||
QskBoxBorderColors::QskBoxBorderColors( const QColor& color )
|
||||
{
|
||||
qskSetColors( color, m_colors );
|
||||
qskSetColors( color, m_gradients );
|
||||
}
|
||||
|
||||
QskBoxBorderColors::~QskBoxBorderColors()
|
||||
|
@ -61,37 +56,37 @@ QskBoxBorderColors::~QskBoxBorderColors()
|
|||
|
||||
bool QskBoxBorderColors::operator==( const QskBoxBorderColors& other ) const
|
||||
{
|
||||
return ( m_colors[ 0 ] == other.m_colors[ 0 ] ) &&
|
||||
( m_colors[ 1 ] == other.m_colors[ 1 ] ) &&
|
||||
( m_colors[ 2 ] == other.m_colors[ 2 ] ) &&
|
||||
( m_colors[ 3 ] == other.m_colors[ 3 ] );
|
||||
return ( m_gradients[ 0 ] == other.m_gradients[ 0 ] ) &&
|
||||
( m_gradients[ 1 ] == other.m_gradients[ 1 ] ) &&
|
||||
( m_gradients[ 2 ] == other.m_gradients[ 2 ] ) &&
|
||||
( m_gradients[ 3 ] == other.m_gradients[ 3 ] );
|
||||
}
|
||||
|
||||
void QskBoxBorderColors::setAlpha( int alpha )
|
||||
{
|
||||
for ( int i = 0; i < 4; i++ )
|
||||
{
|
||||
if ( m_colors[ i ].isValid() && m_colors[ i ].alpha() )
|
||||
m_colors[ i ].setAlpha( alpha );
|
||||
if ( m_gradients[ i ].isValid() )
|
||||
m_gradients[ i ].setAlpha( alpha );
|
||||
}
|
||||
}
|
||||
|
||||
void QskBoxBorderColors::setColors( const QColor& color )
|
||||
{
|
||||
qskSetColors( color, m_colors );
|
||||
qskSetColors( color, m_gradients );
|
||||
}
|
||||
|
||||
void QskBoxBorderColors::setColors(
|
||||
const QColor& left, const QColor& top,
|
||||
const QColor& right, const QColor& bottom )
|
||||
{
|
||||
qskSetColors( left, top, right, bottom, m_colors );
|
||||
qskSetColors( left, top, right, bottom, m_gradients );
|
||||
}
|
||||
|
||||
void QskBoxBorderColors::setColor(
|
||||
Qsk::Position position, const QColor& color )
|
||||
{
|
||||
m_colors[ position ] = color.toRgb();
|
||||
m_gradients[ position ] = color.toRgb();
|
||||
}
|
||||
|
||||
void QskBoxBorderColors::setColorsAt( Qt::Edges edges, const QColor& color )
|
||||
|
@ -99,33 +94,33 @@ void QskBoxBorderColors::setColorsAt( Qt::Edges edges, const QColor& color )
|
|||
const QColor c = color.toRgb();
|
||||
|
||||
if ( edges & Qt::TopEdge )
|
||||
m_colors[ Qsk::Top ] = c;
|
||||
m_gradients[ Qsk::Top ] = c;
|
||||
|
||||
if ( edges & Qt::LeftEdge )
|
||||
m_colors[ Qsk::Left ] = c;
|
||||
m_gradients[ Qsk::Left ] = c;
|
||||
|
||||
if ( edges & Qt::RightEdge )
|
||||
m_colors[ Qsk::Right ] = c;
|
||||
m_gradients[ Qsk::Right ] = c;
|
||||
|
||||
if ( edges & Qt::BottomEdge )
|
||||
m_colors[ Qsk::Bottom ] = c;
|
||||
m_gradients[ Qsk::Bottom ] = c;
|
||||
}
|
||||
|
||||
QColor QskBoxBorderColors::colorAt( Qt::Edge edge ) const
|
||||
QskGradient QskBoxBorderColors::colorAt( Qt::Edge edge ) const
|
||||
{
|
||||
switch ( edge )
|
||||
{
|
||||
case Qt::TopEdge:
|
||||
return m_colors[ Qsk::Top ];
|
||||
return m_gradients[ Qsk::Top ];
|
||||
|
||||
case Qt::LeftEdge:
|
||||
return m_colors[ Qsk::Left ];
|
||||
return m_gradients[ Qsk::Left ];
|
||||
|
||||
case Qt::RightEdge:
|
||||
return m_colors[ Qsk::Right ];
|
||||
return m_gradients[ Qsk::Right ];
|
||||
|
||||
case Qt::BottomEdge:
|
||||
return m_colors[ Qsk::Bottom ];
|
||||
return m_gradients[ Qsk::Bottom ];
|
||||
}
|
||||
|
||||
return QColor();
|
||||
|
@ -133,16 +128,16 @@ QColor QskBoxBorderColors::colorAt( Qt::Edge edge ) const
|
|||
|
||||
bool QskBoxBorderColors::isVisible() const
|
||||
{
|
||||
if ( qskIsVisble( m_colors[ 0 ] ) )
|
||||
if ( m_gradients[ 0 ].isVisible() )
|
||||
return true;
|
||||
|
||||
if ( qskIsVisble( m_colors[ 1 ] ) )
|
||||
if ( m_gradients[ 1 ].isVisible() )
|
||||
return true;
|
||||
|
||||
if ( qskIsVisble( m_colors[ 2 ] ) )
|
||||
if ( m_gradients[ 2 ].isVisible() )
|
||||
return true;
|
||||
|
||||
if ( qskIsVisble( m_colors[ 3 ] ) )
|
||||
if ( m_gradients[ 3 ].isVisible() )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
@ -150,16 +145,19 @@ bool QskBoxBorderColors::isVisible() const
|
|||
|
||||
bool QskBoxBorderColors::isMonochrome() const
|
||||
{
|
||||
if ( m_colors[ 1 ] != m_colors[ 0 ] )
|
||||
if ( m_gradients[ 1 ] != m_gradients[ 0 ] )
|
||||
return false;
|
||||
|
||||
if ( m_colors[ 2 ] != m_colors[ 1 ] )
|
||||
if ( m_gradients[ 2 ] != m_gradients[ 1 ] )
|
||||
return false;
|
||||
|
||||
if ( m_colors[ 3 ] != m_colors[ 2 ] )
|
||||
if ( m_gradients[ 3 ] != m_gradients[ 2 ] )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return m_gradients[ 0 ].isMonochrome()
|
||||
&& m_gradients[ 1 ].isMonochrome()
|
||||
&& m_gradients[ 2 ].isMonochrome()
|
||||
&& m_gradients[ 3 ].isMonochrome();
|
||||
}
|
||||
|
||||
QskBoxBorderColors QskBoxBorderColors::interpolated(
|
||||
|
@ -169,8 +167,8 @@ QskBoxBorderColors QskBoxBorderColors::interpolated(
|
|||
|
||||
for ( size_t i = 0; i < 4; i++ )
|
||||
{
|
||||
colors.m_colors[ i ] = QskRgb::interpolated(
|
||||
m_colors[ i ], to.m_colors[ i ], ratio );
|
||||
colors.m_gradients[ i ] = colors.m_gradients[ i ].interpolated(
|
||||
to.m_gradients[ i ], ratio );
|
||||
}
|
||||
|
||||
return colors;
|
||||
|
@ -184,30 +182,18 @@ QVariant QskBoxBorderColors::interpolate(
|
|||
|
||||
uint QskBoxBorderColors::hash( uint seed ) const
|
||||
{
|
||||
const QRgb rgb[] =
|
||||
{
|
||||
m_colors[ 0 ].rgba(),
|
||||
m_colors[ 1 ].rgba(),
|
||||
m_colors[ 2 ].rgba(),
|
||||
m_colors[ 3 ].rgba(),
|
||||
};
|
||||
uint h = m_gradients[ 0 ].hash( seed );
|
||||
h = m_gradients[ 1 ].hash( h );
|
||||
h = m_gradients[ 2 ].hash( h );
|
||||
h = m_gradients[ 3 ].hash( h );
|
||||
|
||||
return qHashBits( rgb, sizeof( rgb ), seed );
|
||||
return h;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
|
||||
#include <qdebug.h>
|
||||
|
||||
static inline void qskDebugColor( QDebug debug, const QColor& c )
|
||||
{
|
||||
debug << '('
|
||||
<< c.red() << ','
|
||||
<< c.green() << ','
|
||||
<< c.blue() << ','
|
||||
<< c.alpha() << ')';
|
||||
}
|
||||
|
||||
QDebug operator<<( QDebug debug, const QskBoxBorderColors& colors )
|
||||
{
|
||||
QDebugStateSaver saver( debug );
|
||||
|
@ -215,17 +201,13 @@ QDebug operator<<( QDebug debug, const QskBoxBorderColors& colors )
|
|||
|
||||
debug << "BoxBorderColors" << '(';
|
||||
|
||||
debug << " L";
|
||||
qskDebugColor( debug, colors.color( Qsk::Left ) );
|
||||
debug << " L" << colors.color( Qsk::Left );
|
||||
|
||||
debug << ", T";
|
||||
qskDebugColor( debug, colors.color( Qsk::Top ) );
|
||||
debug << ", T" << colors.color( Qsk::Top );
|
||||
|
||||
debug << ", R";
|
||||
qskDebugColor( debug, colors.color( Qsk::Right ) );
|
||||
debug << ", R" << colors.color( Qsk::Right );
|
||||
|
||||
debug << ", B";
|
||||
qskDebugColor( debug, colors.color( Qsk::Bottom ) );
|
||||
debug << ", B" << colors.color( Qsk::Bottom );
|
||||
|
||||
debug << " )";
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#ifndef QSK_BOX_BORDER_COLORS_H
|
||||
#define QSK_BOX_BORDER_COLORS_H
|
||||
|
||||
#include "QskGradient.h"
|
||||
#include "QskNamespace.h"
|
||||
|
||||
#include <qcolor.h>
|
||||
|
@ -37,12 +38,10 @@ class QSK_EXPORT QskBoxBorderColors
|
|||
const QColor& right, const QColor& bottom );
|
||||
|
||||
void setColor( Qsk::Position, const QColor& );
|
||||
QColor color( Qsk::Position ) const;
|
||||
QskGradient color( Qsk::Position ) const;
|
||||
|
||||
void setColorsAt( Qt::Edges, const QColor& );
|
||||
QColor colorAt( Qt::Edge ) const;
|
||||
|
||||
QRgb rgb( Qsk::Position ) const;
|
||||
QskGradient colorAt( Qt::Edge ) const;
|
||||
|
||||
QskBoxBorderColors interpolated( const QskBoxBorderColors&, qreal value ) const;
|
||||
|
||||
|
@ -55,8 +54,7 @@ class QSK_EXPORT QskBoxBorderColors
|
|||
bool isVisible() const;
|
||||
|
||||
private:
|
||||
// should be stored as QRgb
|
||||
QColor m_colors[ 4 ];
|
||||
QskGradient m_gradients[ 4 ];
|
||||
};
|
||||
|
||||
inline QskBoxBorderColors::QskBoxBorderColors( Qt::GlobalColor color )
|
||||
|
@ -74,14 +72,9 @@ inline bool QskBoxBorderColors::operator!=( const QskBoxBorderColors& other ) co
|
|||
return !( *this == other );
|
||||
}
|
||||
|
||||
inline QColor QskBoxBorderColors::color( Qsk::Position position ) const
|
||||
inline QskGradient QskBoxBorderColors::color( Qsk::Position position ) const
|
||||
{
|
||||
return m_colors[ position ];
|
||||
}
|
||||
|
||||
inline QRgb QskBoxBorderColors::rgb( Qsk::Position position ) const
|
||||
{
|
||||
return m_colors[ position ].rgba();
|
||||
return m_gradients[ position ];
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DEBUG_STREAM
|
||||
|
|
|
@ -171,7 +171,7 @@ void QskBoxNode::setBoxData( const QRectF& rect,
|
|||
}
|
||||
else
|
||||
{
|
||||
flatMaterial->setColor( borderColors.color( Qsk::Left ).rgba() );
|
||||
flatMaterial->setColor( borderColors.color( Qsk::Left ).startColor().rgba() ); // ###
|
||||
renderer.renderBorder( m_rect, shape, borderMetrics, *geometry() );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -859,17 +859,17 @@ static inline void qskRenderBorder( const QskBoxRenderer::Metrics& metrics,
|
|||
|
||||
if ( colors.isMonochrome() )
|
||||
{
|
||||
qskRenderBorderLines( metrics, orientation, line, BorderMapSolid( c.rgb( Qsk::Left ) ) );
|
||||
qskRenderBorderLines( metrics, orientation, line, BorderMapSolid( c.color( Qsk::Left ).startColor().rgb() ) ); // ###
|
||||
}
|
||||
else
|
||||
{
|
||||
const int stepCount = metrics.corner[ 0 ].stepCount;
|
||||
|
||||
qskRenderBorderLines( metrics, orientation, line,
|
||||
BorderMapGradient( stepCount, c.rgb( Qsk::Top ), c.rgb( Qsk::Left ) ),
|
||||
BorderMapGradient( stepCount, c.rgb( Qsk::Right ), c.rgb( Qsk::Top ) ),
|
||||
BorderMapGradient( stepCount, c.rgb( Qsk::Left ), c.rgb( Qsk::Bottom ) ),
|
||||
BorderMapGradient( stepCount, c.rgb( Qsk::Bottom ), c.rgb( Qsk::Right ) ) );
|
||||
BorderMapGradient( stepCount, c.color( Qsk::Top ).startColor().rgb(), c.color( Qsk::Left ).startColor().rgb() ), // ###
|
||||
BorderMapGradient( stepCount, c.color( Qsk::Right ).startColor().rgb(), c.color( Qsk::Top ).startColor().rgb() ), // ###
|
||||
BorderMapGradient( stepCount, c.color( Qsk::Left ).startColor().rgb(), c.color( Qsk::Bottom ).startColor().rgb() ), // ###
|
||||
BorderMapGradient( stepCount, c.color( Qsk::Bottom ).startColor().rgb(), c.color( Qsk::Right ).startColor().rgb() ) ); // ###
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -899,7 +899,7 @@ static inline void qskRenderBoxRandom(
|
|||
|
||||
if ( bc.isMonochrome() )
|
||||
{
|
||||
const BorderMapSolid borderMap( bc.rgb( Qsk::Left ) );
|
||||
const BorderMapSolid borderMap( bc.color( Qsk::Left ).startColor().rgb() ); // ###
|
||||
|
||||
if ( gradient.isMonochrome() )
|
||||
{
|
||||
|
@ -918,10 +918,10 @@ static inline void qskRenderBoxRandom(
|
|||
{
|
||||
const int n = metrics.corner[ 0 ].stepCount;
|
||||
|
||||
const BorderMapGradient tl( n, bc.rgb( Qsk::Top ), bc.rgb( Qsk::Left ) );
|
||||
const BorderMapGradient tr( n, bc.rgb( Qsk::Right ), bc.rgb( Qsk::Top ) );
|
||||
const BorderMapGradient bl( n, bc.rgb( Qsk::Left ), bc.rgb( Qsk::Bottom ) );
|
||||
const BorderMapGradient br( n, bc.rgb( Qsk::Bottom ), bc.rgb( Qsk::Right ) );
|
||||
const BorderMapGradient tl( n, bc.color( Qsk::Top ).startColor().rgb(), bc.color( Qsk::Left ).startColor().rgb() );
|
||||
const BorderMapGradient tr( n, bc.color( Qsk::Right ).startColor().rgb(), bc.color( Qsk::Top ).startColor().rgb() );
|
||||
const BorderMapGradient bl( n, bc.color( Qsk::Left ).startColor().rgb(), bc.color( Qsk::Bottom ).startColor().rgb() );
|
||||
const BorderMapGradient br( n, bc.color( Qsk::Bottom ).startColor().rgb(), bc.color( Qsk::Right ).startColor().rgb() );
|
||||
|
||||
if ( gradient.isMonochrome() )
|
||||
{
|
||||
|
|
|
@ -422,10 +422,10 @@ static inline void qskCreateBorder(
|
|||
const QskBoxRenderer::Quad& out, const QskBoxRenderer::Quad& in,
|
||||
const QskBoxBorderColors& colors, Line* line )
|
||||
{
|
||||
const Color colorLeft = colors.rgb( Qsk::Left );
|
||||
const Color colorRight = colors.rgb( Qsk::Right );
|
||||
const Color colorTop = colors.rgb( Qsk::Top );
|
||||
const Color colorBottom = colors.rgb( Qsk::Bottom );
|
||||
const Color colorLeft = colors.color( Qsk::Left ).startColor().rgb(); // ###
|
||||
const Color colorRight = colors.color( Qsk::Right ).startColor().rgb(); // ###
|
||||
const Color colorTop = colors.color( Qsk::Top ).startColor().rgb(); // ###
|
||||
const Color colorBottom = colors.color( Qsk::Bottom ).startColor().rgb(); // ###
|
||||
|
||||
( line++ )->setLine( in.right, in.bottom, out.right, out.bottom, colorBottom );
|
||||
( line++ )->setLine( in.left, in.bottom, out.left, out.bottom, colorBottom );
|
||||
|
@ -587,7 +587,7 @@ void QskBoxRenderer::renderRect(
|
|||
auto fillLines = line + fillLineCount;
|
||||
|
||||
if ( bc.isMonochrome() )
|
||||
qskCreateBorderMonochrome( rect, in, bc.rgb( Qsk::Left ), fillLines );
|
||||
qskCreateBorderMonochrome( rect, in, bc.color( Qsk::Left ).startColor().rgb(), fillLines );
|
||||
else
|
||||
qskCreateBorder( rect, in, bc, fillLines );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue