1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qsgsoftwarespritenode_p.h"
5#include "qsgsoftwarepixmaptexture_p.h"
6#include <QtGui/QPainter>
7
8QT_BEGIN_NAMESPACE
9
10QSGSoftwareSpriteNode::QSGSoftwareSpriteNode()
11{
12 setMaterial((QSGMaterial*)1);
13 setGeometry((QSGGeometry*)1);
14}
15
16QSGSoftwareSpriteNode::~QSGSoftwareSpriteNode()
17{
18 delete m_texture;
19}
20
21void QSGSoftwareSpriteNode::setTexture(QSGTexture *texture)
22{
23 m_texture = qobject_cast<QSGSoftwarePixmapTexture*>(object: texture);
24 markDirty(bits: DirtyMaterial);
25}
26
27void QSGSoftwareSpriteNode::setTime(float time)
28{
29 if (m_time != time) {
30 m_time = time;
31 markDirty(bits: DirtyMaterial);
32 }
33}
34
35void QSGSoftwareSpriteNode::setSourceA(const QPoint &source)
36{
37 if (m_sourceA != source) {
38 m_sourceA = source;
39 markDirty(bits: DirtyMaterial);
40 }
41}
42
43void QSGSoftwareSpriteNode::setSourceB(const QPoint &source)
44{
45 if (m_sourceB != source) {
46 m_sourceB = source;
47 markDirty(bits: DirtyMaterial);
48 }
49}
50
51void QSGSoftwareSpriteNode::setSpriteSize(const QSize &size)
52{
53 if (m_spriteSize != size) {
54 m_spriteSize = size;
55 markDirty(bits: DirtyMaterial);
56 }
57}
58
59void QSGSoftwareSpriteNode::setSheetSize(const QSize &size)
60{
61 if (m_sheetSize != size) {
62 m_sheetSize = size;
63 markDirty(bits: DirtyMaterial);
64 }
65}
66
67void QSGSoftwareSpriteNode::setSize(const QSizeF &size)
68{
69 if (m_size != size) {
70 m_size = size;
71 markDirty(bits: DirtyGeometry);
72 }
73}
74
75void QSGSoftwareSpriteNode::setFiltering(QSGTexture::Filtering filtering)
76{
77 Q_UNUSED(filtering);
78}
79
80void QSGSoftwareSpriteNode::update()
81{
82}
83
84void QSGSoftwareSpriteNode::paint(QPainter *painter)
85{
86 //Get the pixmap handle from the texture
87 if (!m_texture)
88 return;
89
90 const QPixmap &pixmap = m_texture->pixmap();
91
92 // XXX try to do some kind of interpolation between sourceA and sourceB using time
93 painter->drawPixmap(targetRect: QRectF(0, 0, m_size.width(), m_size.height()),
94 pixmap,
95 sourceRect: QRectF(m_sourceA * pixmap.devicePixelRatio(), m_spriteSize * pixmap.devicePixelRatio()));
96}
97
98bool QSGSoftwareSpriteNode::isOpaque() const
99{
100 return false;
101}
102
103QRectF QSGSoftwareSpriteNode::rect() const
104{
105 return QRectF(0, 0, m_size.width(), m_size.height());
106}
107
108QT_END_NAMESPACE
109

source code of qtdeclarative/src/quick/scenegraph/adaptations/software/qsgsoftwarespritenode.cpp