qskinny/src/graphic/QskGraphicTextureFactory.cpp

97 lines
2.2 KiB
C++
Raw Normal View History

2017-07-21 18:21:34 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#include "QskGraphicTextureFactory.h"
#include "QskTextureRenderer.h"
2017-07-21 18:21:34 +02:00
2018-07-19 14:10:48 +02:00
#include <qquickwindow.h>
2017-07-21 18:21:34 +02:00
QskGraphicTextureFactory::QskGraphicTextureFactory()
{
}
QskGraphicTextureFactory::QskGraphicTextureFactory(
2018-08-03 08:15:28 +02:00
const QskGraphic& graphic, const QSize& size )
: m_graphic( graphic )
, m_size( size )
2017-07-21 18:21:34 +02:00
{
}
QskGraphicTextureFactory::~QskGraphicTextureFactory()
{
}
2020-11-01 10:43:16 +01:00
void QskGraphicTextureFactory::setGraphic( const QskGraphic& graphic )
2017-07-21 18:21:34 +02:00
{
2020-11-01 10:43:16 +01:00
m_graphic = graphic;
}
QskGraphic QskGraphicTextureFactory::graphic() const
{
return m_graphic;
}
void QskGraphicTextureFactory::setColorFilter(
const QskColorFilter& colorFilter )
{
m_colorFilter = colorFilter;
}
2017-07-21 18:21:34 +02:00
2020-11-01 10:43:16 +01:00
const QskColorFilter& QskGraphicTextureFactory::colorFilter() const
{
return m_colorFilter;
}
2017-07-21 18:21:34 +02:00
2020-11-01 10:43:16 +01:00
void QskGraphicTextureFactory::setSize( const QSize& size )
{
m_size = size;
}
2020-11-01 08:48:50 +01:00
2020-11-01 10:43:16 +01:00
QSize QskGraphicTextureFactory::size() const
{
return m_size;
}
2020-11-01 08:48:50 +01:00
2020-11-01 10:43:16 +01:00
QSGTexture* QskGraphicTextureFactory::createTexture( QQuickWindow* window ) const
{
class PaintHelper : public QskTextureRenderer::PaintHelper
{
public:
PaintHelper( const QskGraphic& graphic, const QskColorFilter& filter )
: m_graphic( graphic )
, m_filter( filter )
{
}
void paint( QPainter* painter, const QSize& size ) override
{
const QRect rect( 0, 0, size.width(), size.height() );
m_graphic.render( painter, rect, m_filter );
}
private:
const QskGraphic& m_graphic;
const QskColorFilter& m_filter;
};
PaintHelper helper( m_graphic, m_colorFilter );
return QskTextureRenderer::createPaintedTexture( window, m_size, &helper );
2017-07-21 18:21:34 +02:00
}
QSize QskGraphicTextureFactory::textureSize() const
{
return m_size;
}
int QskGraphicTextureFactory::textureByteCount() const
{
return m_size.width() * m_size.height() * 4;
}
QImage QskGraphicTextureFactory::image() const
{
return m_graphic.toImage( m_size, Qt::KeepAspectRatio );
}