From a35cc9936a1b8f19be617daa1e4f778a05aaaa65 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Wed, 1 Jun 2022 18:27:05 +0200 Subject: [PATCH] mirroring added --- src/nodes/QskPaintedNode.cpp | 45 ++++++++++++++++++++++++++++++++---- src/nodes/QskPaintedNode.h | 4 ++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/nodes/QskPaintedNode.cpp b/src/nodes/QskPaintedNode.cpp index e153b2bb..8f505caf 100644 --- a/src/nodes/QskPaintedNode.cpp +++ b/src/nodes/QskPaintedNode.cpp @@ -64,6 +64,20 @@ static GLuint qskTakeTexture( QOpenGLFramebufferObject& fbo ) return textureId; } +static inline QSGImageNode::TextureCoordinatesTransformMode + qskEffectiveTransformMode( const Qt::Orientations mirrored ) +{ + QSGImageNode::TextureCoordinatesTransformMode mode; + + if ( mirrored & Qt::Vertical ) + mode |= QSGImageNode::MirrorVertically; + + if ( mirrored & Qt::Horizontal ) + mode |= QSGImageNode::MirrorHorizontally; + + return mode; +} + namespace { const quint8 imageRole = 250; // reserved for internal use @@ -104,6 +118,25 @@ QskPaintedNode::RenderHint QskPaintedNode::renderHint() const return m_renderHint; } +void QskPaintedNode::setMirrored( Qt::Orientations orientations ) +{ + if ( orientations != m_mirrored ) + { + m_mirrored == orientations; + + if ( auto imageNode = findImageNode( this ) ) + { + imageNode->setTextureCoordinatesTransform( + qskEffectiveTransformMode( orientations ) ); + } + } +} + +Qt::Orientations QskPaintedNode::mirrored() const +{ + return m_mirrored; +} + QRectF QskPaintedNode::rect() const { const auto imageNode = findImageNode( this ); @@ -145,6 +178,14 @@ void QskPaintedNode::update( QQuickWindow* window, else updateImageNode( window, rect, nodeData ); } + + imageNode = findImageNode( this ); + if ( imageNode ) + { + imageNode->setRect( rect ); + imageNode->setTextureCoordinatesTransform( + qskEffectiveTransformMode( m_mirrored ) ); + } } void QskPaintedNode::updateImageNode( @@ -183,8 +224,6 @@ void QskPaintedNode::updateImageNode( texture->setImage( image ); else imageNode->setTexture( window->createTextureFromImage( image ) ); - - imageNode->setRect( rect ); } void QskPaintedNode::updateImageNodeGL( @@ -240,8 +279,6 @@ void QskPaintedNode::updateImageNodeGL( texture->setTextureSize( size ); } #endif - - imageNode->setRect( rect ); } uint32_t QskPaintedNode::createTexture( diff --git a/src/nodes/QskPaintedNode.h b/src/nodes/QskPaintedNode.h index 5ae43ec3..755b8dac 100644 --- a/src/nodes/QskPaintedNode.h +++ b/src/nodes/QskPaintedNode.h @@ -38,6 +38,9 @@ class QSK_EXPORT QskPaintedNode : public QSGNode void setRenderHint( RenderHint ); RenderHint renderHint() const; + void setMirrored( Qt::Orientations ); + Qt::Orientations mirrored() const; + QRectF rect() const; protected: @@ -55,6 +58,7 @@ class QSK_EXPORT QskPaintedNode : public QSGNode uint32_t createTexture( QQuickWindow*, const QSize&, const void* nodeData ); RenderHint m_renderHint = OpenGL; + Qt::Orientations m_mirrored; QskHashValue m_hash = 0; };