2018-10-04 16:15:42 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* QSkinny - Copyright (C) 2016 Uwe Rathmann
|
|
|
|
* This file may be used under the terms of the QSkinny License, Version 1.0
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "QskPaintedNode.h"
|
|
|
|
#include "QskTextureRenderer.h"
|
|
|
|
|
|
|
|
class QskPaintedNode::PaintHelper : public QskTextureRenderer::PaintHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
inline PaintHelper( QskPaintedNode* node )
|
|
|
|
: m_node( node )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void paint( QPainter* painter, const QSize& size ) override
|
|
|
|
{
|
|
|
|
m_node->paint( painter, size );
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
QskPaintedNode* m_node;
|
|
|
|
};
|
|
|
|
|
|
|
|
QskPaintedNode::QskPaintedNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QskPaintedNode::~QskPaintedNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-11-01 15:44:15 +01:00
|
|
|
void QskPaintedNode::update( QQuickWindow* window,
|
2018-10-04 16:15:42 +02:00
|
|
|
QskTextureRenderer::RenderMode renderMode, const QRect& rect )
|
|
|
|
{
|
2020-10-26 18:06:06 +01:00
|
|
|
bool isTextureDirty = isNull();
|
2018-10-04 16:15:42 +02:00
|
|
|
|
|
|
|
if ( !isTextureDirty )
|
|
|
|
{
|
|
|
|
const auto oldRect = QskTextureNode::rect();
|
|
|
|
isTextureDirty = ( rect.width() != static_cast< int >( oldRect.width() ) ) ||
|
2019-01-04 13:42:16 +01:00
|
|
|
( rect.height() != static_cast< int >( oldRect.height() ) );
|
2018-10-04 16:15:42 +02:00
|
|
|
}
|
|
|
|
|
2020-11-01 15:44:15 +01:00
|
|
|
const auto newHash = hash();
|
2018-10-04 16:15:42 +02:00
|
|
|
if ( ( newHash == 0 ) || ( newHash != m_hash ) )
|
|
|
|
{
|
|
|
|
m_hash = newHash;
|
|
|
|
isTextureDirty = true;
|
|
|
|
}
|
|
|
|
|
2020-11-01 15:44:15 +01:00
|
|
|
auto textureId = QskTextureNode::textureId();
|
|
|
|
|
2018-10-04 16:15:42 +02:00
|
|
|
if ( isTextureDirty )
|
|
|
|
{
|
|
|
|
PaintHelper helper( this );
|
2020-11-01 15:44:15 +01:00
|
|
|
textureId = QskTextureRenderer::createTexture(
|
2021-12-13 16:43:34 +01:00
|
|
|
window, renderMode, rect.size(), &helper );
|
2018-10-04 16:15:42 +02:00
|
|
|
}
|
2020-11-01 15:44:15 +01:00
|
|
|
|
|
|
|
QskTextureNode::setTexture( window, rect, textureId );
|
2018-10-04 16:15:42 +02:00
|
|
|
}
|