diff --git a/src/nodes/QskBoxRenderer.h b/src/nodes/QskBoxRenderer.h index f5d77617..fde93674 100644 --- a/src/nodes/QskBoxRenderer.h +++ b/src/nodes/QskBoxRenderer.h @@ -7,6 +7,7 @@ #define QSK_BOX_RENDERER_H #include "QskBoxShapeMetrics.h" +#include "QskVertex.h" #include class QskBoxBorderMetrics; @@ -15,11 +16,6 @@ class QskGradient; class QSGGeometry; -namespace QskVertex -{ - class ColoredLine; -} - class QSK_EXPORT QskBoxRenderer { public: @@ -35,60 +31,15 @@ class QSK_EXPORT QskBoxRenderer static bool isGradientSupported( const QskGradient& ); - class Quad - { - public: - inline constexpr Quad() noexcept - : left( 0.0 ) - , top( 0.0 ) - , right( 0.0 ) - , bottom( 0.0 ) - , width( 0.0 ) - , height( 0.0 ) - { - } - - inline constexpr Quad( const QRectF& rect ) noexcept - : left( rect.left() ) - , top( rect.top() ) - , right( rect.right() ) - , bottom( rect.bottom() ) - , width( rect.width() ) - , height( rect.height() ) - { - } - - inline constexpr bool operator==( const Quad& other ) const noexcept - { - return - ( left == other.left ) && - ( right == other.right ) && - ( top == other.top ) && - ( bottom == other.bottom ); - } - - inline constexpr bool operator!=( const Quad& other ) const noexcept - { - return !( *this == other ); - } - - inline constexpr bool isEmpty() const noexcept - { - return ( width <= 0 ) || ( height <= 0 ); - } - - qreal left, top, right, bottom, width, height; - }; - class Metrics { public: Metrics( const QRectF&, const QskBoxShapeMetrics&, const QskBoxBorderMetrics& ); - Quad outerQuad; - Quad innerQuad; + QskVertex::Quad outerQuad; + QskVertex::Quad innerQuad; #if 1 - Quad centerQuad; // to be removed + QskVertex::Quad centerQuad; // to be removed #endif struct Corner @@ -130,7 +81,8 @@ class QSK_EXPORT QskBoxRenderer static void renderDiagonalFill( const Metrics&, const QskGradient&, int lineCount, QskVertex::ColoredLine* ); - static void renderRectFill( const Quad&, const QskGradient&, QskVertex::ColoredLine* ); + static void renderRectFill( const QskVertex::Quad&, + const QskGradient&, QskVertex::ColoredLine* ); }; inline void QskBoxRenderer::renderBorder( diff --git a/src/nodes/QskBoxRendererRect.cpp b/src/nodes/QskBoxRendererRect.cpp index 949a51c9..75c0cf8c 100644 --- a/src/nodes/QskBoxRendererRect.cpp +++ b/src/nodes/QskBoxRendererRect.cpp @@ -18,7 +18,7 @@ namespace class VRectIterator { public: - inline VRectIterator( const QskBoxRenderer::Quad& rect ) + inline VRectIterator( const Quad& rect ) : m_rect( rect ) , m_value( rect.top ) { @@ -53,14 +53,14 @@ namespace } private: - const QskBoxRenderer::Quad& m_rect; + const Quad& m_rect; qreal m_value; }; class HRectIterator { public: - inline HRectIterator( const QskBoxRenderer::Quad& rect ) + inline HRectIterator( const Quad& rect ) : m_rect( rect ) , m_value( rect.left ) { @@ -95,14 +95,14 @@ namespace } private: - const QskBoxRenderer::Quad& m_rect; + const Quad& m_rect; qreal m_value; }; class DSquareIterator { public: - inline DSquareIterator( const QskBoxRenderer::Quad& rect ) + inline DSquareIterator( const Quad& rect ) : m_rect( rect ) , m_step( 0 ) { @@ -171,14 +171,14 @@ namespace } private: - const QskBoxRenderer::Quad& m_rect; + const Quad& m_rect; int m_step; }; class DRectIterator { public: - inline DRectIterator( const QskBoxRenderer::Quad& rect ) + inline DRectIterator( const Quad& rect ) : m_rect( rect ) , m_step( 0 ) { @@ -332,7 +332,7 @@ namespace } private: - const QskBoxRenderer::Quad& m_rect; + const Quad& m_rect; qreal m_fx, m_fy; qreal m_lx, m_ly; @@ -342,7 +342,7 @@ namespace }; } -static inline void qskCreateFillOrdered( const QskBoxRenderer::Quad& rect, +static inline void qskCreateFillOrdered( const Quad& rect, const QskGradient& gradient, ColoredLine* line ) { const auto dir = gradient.linearDirection(); @@ -374,7 +374,7 @@ static inline void qskCreateFillOrdered( const QskBoxRenderer::Quad& rect, template< class ColorMap, class Line > static inline void qskCreateFillRandom( Qt::Orientation orientation, - const QskBoxRenderer::Quad& r, const ColorMap& map, Line* line ) + const Quad& r, const ColorMap& map, Line* line ) { if ( orientation == Qt::Vertical ) { @@ -390,14 +390,7 @@ static inline void qskCreateFillRandom( Qt::Orientation orientation, template< class Line > static inline void qskCreateBorderMonochrome( - const QskBoxRenderer::Quad& out, const QskBoxRenderer::Quad& in, QRgb rgb, Line* line ) -{ - qskCreateBorderMonochrome( out, in, Color( rgb ), line ); -} - -template< class Line > -static inline void qskCreateBorderMonochrome( - const QskBoxRenderer::Quad& out, const QskBoxRenderer::Quad& in, Color color, Line* line ) + const Quad& out, const Quad& in, Color color, Line* line ) { auto l = line; @@ -411,7 +404,7 @@ static inline void qskCreateBorderMonochrome( template< class Line > static inline void qskCreateBorder( - const QskBoxRenderer::Quad& out, const QskBoxRenderer::Quad& in, + const Quad& out, const Quad& in, const QskBoxBorderColors& colors, Line* line ) { const qreal dx1 = in.right - in.left; @@ -655,7 +648,7 @@ void QskBoxRenderer::renderRect( const QRectF& rect, if ( bc.isMonochrome() ) { const auto rgb = bc.left().rgbStart(); - qskCreateBorderMonochrome( rect, in, rgb, fillLines ); + qskCreateBorderMonochrome( rect, in, Color( rgb ), fillLines ); } else { @@ -664,7 +657,7 @@ void QskBoxRenderer::renderRect( const QRectF& rect, } } -void QskBoxRenderer::renderRectFill( const QskBoxRenderer::Quad& rect, +void QskBoxRenderer::renderRectFill( const QskVertex::Quad& rect, const QskGradient& gradient, QskVertex::ColoredLine* line ) { qskCreateFillOrdered( rect, gradient, line ); diff --git a/src/nodes/QskVertex.h b/src/nodes/QskVertex.h index 0700d0ae..6a6b7d09 100644 --- a/src/nodes/QskVertex.h +++ b/src/nodes/QskVertex.h @@ -13,7 +13,7 @@ namespace QskVertex { - class QSK_EXPORT Color + class Color { public: constexpr Color() noexcept; @@ -32,75 +32,6 @@ namespace QskVertex unsigned char r, g, b, a; }; - class QSK_EXPORT Line - { - public: - inline void setLine( float x1, float y1, float x2, float y2 ) noexcept - { - p1.set( x1, y1 ); - p2.set( x2, y2 ); - } - - inline void setHLine( float x1, float x2, float y ) noexcept - { - setLine( x1, y, x2, y ); - } - - inline void setVLine( float x, float y1, float y2 ) noexcept - { - setLine( x, y1, x, y2 ); - } - - inline void setLine( float x1, float y1, float x2, float y2, Color ) noexcept - { - /* The color parameter makes no sense, but is useful - when being using from templated code - */ - setLine( x1, y1, x2, y2 ); - } - - QSGGeometry::Point2D p1; - QSGGeometry::Point2D p2; - }; - - class QSK_EXPORT ColoredLine - { - public: - inline void setLine( float x1, float y1, Color c1, - float x2, float y2, Color c2 ) noexcept - { - p1.set( x1, y1, c1.r, c1.g, c1.b, c1.a ); - p2.set( x2, y2, c2.r, c2.g, c2.b, c2.a ); - } - - inline void setLine( float x1, float y1, float x2, float y2, Color color ) noexcept - { - setLine( x1, y1, color, x2, y2, color ); - } - - inline void setHLine( qreal x1, qreal x2, qreal y, Color color ) noexcept - { - setLine( x1, y, color, x2, y, color ); - } - - inline void setVLine( qreal x, qreal y1, qreal y2, Color color ) noexcept - { - setLine( x, y1, color, x, y2, color ); - } - - QSGGeometry::ColoredPoint2D p1; - QSGGeometry::ColoredPoint2D p2; - }; - - template< class Line > - static inline Line* allocateLines( QSGGeometry& geometry, int lineCount ) - { - geometry.allocate( 2 * lineCount ); // 2 points per line - return reinterpret_cast< Line* >( geometry.vertexData() ); - } - - void QSK_EXPORT debugGeometry( const QSGGeometry& ); - inline constexpr Color::Color() noexcept : r( 0 ) , g( 0 ) @@ -167,11 +98,134 @@ namespace QskVertex } } +namespace QskVertex +{ + class Line + { + public: + inline void setLine( float x1, float y1, float x2, float y2 ) noexcept + { + p1.set( x1, y1 ); + p2.set( x2, y2 ); + } + + inline void setHLine( float x1, float x2, float y ) noexcept + { + setLine( x1, y, x2, y ); + } + + inline void setVLine( float x, float y1, float y2 ) noexcept + { + setLine( x, y1, x, y2 ); + } + + inline void setLine( float x1, float y1, float x2, float y2, Color ) noexcept + { + /* The color parameter makes no sense, but is useful + when being using from templated code + */ + setLine( x1, y1, x2, y2 ); + } + + QSGGeometry::Point2D p1; + QSGGeometry::Point2D p2; + }; + + class ColoredLine + { + public: + inline void setLine( float x1, float y1, Color c1, + float x2, float y2, Color c2 ) noexcept + { + p1.set( x1, y1, c1.r, c1.g, c1.b, c1.a ); + p2.set( x2, y2, c2.r, c2.g, c2.b, c2.a ); + } + + inline void setLine( float x1, float y1, float x2, float y2, Color color ) noexcept + { + setLine( x1, y1, color, x2, y2, color ); + } + + inline void setHLine( qreal x1, qreal x2, qreal y, Color color ) noexcept + { + setLine( x1, y, color, x2, y, color ); + } + + inline void setVLine( qreal x, qreal y1, qreal y2, Color color ) noexcept + { + setLine( x, y1, color, x, y2, color ); + } + + QSGGeometry::ColoredPoint2D p1; + QSGGeometry::ColoredPoint2D p2; + }; + + template< class Line > + static inline Line* allocateLines( QSGGeometry& geometry, int lineCount ) + { + geometry.allocate( 2 * lineCount ); // 2 points per line + return reinterpret_cast< Line* >( geometry.vertexData() ); + } +} + +namespace QskVertex +{ + class Quad + { + public: + constexpr Quad() noexcept = default; + + inline constexpr Quad( const QRectF& rect ) noexcept + : left( rect.left() ) + , top( rect.top() ) + , right( rect.right() ) + , bottom( rect.bottom() ) + , width( rect.width() ) + , height( rect.height() ) + { + } + + inline constexpr bool operator==( const Quad& other ) const noexcept + { + return + ( left == other.left ) && + ( right == other.right ) && + ( top == other.top ) && + ( bottom == other.bottom ); + } + + inline constexpr bool operator!=( const Quad& other ) const noexcept + { + return !( *this == other ); + } + + inline constexpr bool isEmpty() const noexcept + { + return ( width <= 0 ) || ( height <= 0 ); + } + + qreal left = 0.0; + qreal top = 0.0; + qreal right = 0.0; + qreal bottom = 0.0; + qreal width = 0.0; + qreal height = 0.0; + }; +} + +namespace QskVertex +{ + void debugGeometry( const QSGGeometry& ); +} + #ifndef QT_NO_DEBUG_STREAM -class QDebug; -QDebug operator<<( QDebug debug, QskVertex::Color ); -QDebug operator<<( QDebug debug, const QskVertex::ColoredLine& ); -QDebug operator<<( QDebug debug, const QskVertex::Line& ); + + class QDebug; + + QDebug operator<<( QDebug debug, QskVertex::Color ); + QDebug operator<<( QDebug debug, const QskVertex::ColoredLine& ); + QDebug operator<<( QDebug debug, const QskVertex::Line& ); + #endif #endif