qskinny/src/nodes/QskPaintedNode.cpp

64 lines
1.6 KiB
C++
Raw Normal View History

/******************************************************************************
* 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,
QskTextureRenderer::RenderMode renderMode, const QRect& rect )
{
2020-10-26 18:06:06 +01:00
bool isTextureDirty = isNull();
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() ) );
}
2020-11-01 15:44:15 +01:00
const auto newHash = hash();
if ( ( newHash == 0 ) || ( newHash != m_hash ) )
{
m_hash = newHash;
isTextureDirty = true;
}
2020-11-01 15:44:15 +01:00
auto textureId = QskTextureNode::textureId();
if ( isTextureDirty )
{
PaintHelper helper( this );
2020-11-01 15:44:15 +01:00
textureId = QskTextureRenderer::createTexture(
window, renderMode, rect.size(), &helper );
}
2020-11-01 15:44:15 +01:00
QskTextureNode::setTexture( window, rect, textureId );
}