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 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | QSGSoftwareSpriteNode::QSGSoftwareSpriteNode() |
11 | { |
12 | setMaterial((QSGMaterial*)1); |
13 | setGeometry((QSGGeometry*)1); |
14 | } |
15 | |
16 | QSGSoftwareSpriteNode::~QSGSoftwareSpriteNode() |
17 | { |
18 | delete m_texture; |
19 | } |
20 | |
21 | void QSGSoftwareSpriteNode::setTexture(QSGTexture *texture) |
22 | { |
23 | m_texture = qobject_cast<QSGSoftwarePixmapTexture*>(object: texture); |
24 | markDirty(bits: DirtyMaterial); |
25 | } |
26 | |
27 | void QSGSoftwareSpriteNode::setTime(float time) |
28 | { |
29 | if (m_time != time) { |
30 | m_time = time; |
31 | markDirty(bits: DirtyMaterial); |
32 | } |
33 | } |
34 | |
35 | void QSGSoftwareSpriteNode::setSourceA(const QPoint &source) |
36 | { |
37 | if (m_sourceA != source) { |
38 | m_sourceA = source; |
39 | markDirty(bits: DirtyMaterial); |
40 | } |
41 | } |
42 | |
43 | void QSGSoftwareSpriteNode::setSourceB(const QPoint &source) |
44 | { |
45 | if (m_sourceB != source) { |
46 | m_sourceB = source; |
47 | markDirty(bits: DirtyMaterial); |
48 | } |
49 | } |
50 | |
51 | void QSGSoftwareSpriteNode::setSpriteSize(const QSize &size) |
52 | { |
53 | if (m_spriteSize != size) { |
54 | m_spriteSize = size; |
55 | markDirty(bits: DirtyMaterial); |
56 | } |
57 | } |
58 | |
59 | void QSGSoftwareSpriteNode::setSheetSize(const QSize &size) |
60 | { |
61 | if (m_sheetSize != size) { |
62 | m_sheetSize = size; |
63 | markDirty(bits: DirtyMaterial); |
64 | } |
65 | } |
66 | |
67 | void QSGSoftwareSpriteNode::setSize(const QSizeF &size) |
68 | { |
69 | if (m_size != size) { |
70 | m_size = size; |
71 | markDirty(bits: DirtyGeometry); |
72 | } |
73 | } |
74 | |
75 | void QSGSoftwareSpriteNode::setFiltering(QSGTexture::Filtering filtering) |
76 | { |
77 | Q_UNUSED(filtering); |
78 | } |
79 | |
80 | void QSGSoftwareSpriteNode::update() |
81 | { |
82 | } |
83 | |
84 | void 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 | |
98 | bool QSGSoftwareSpriteNode::isOpaque() const |
99 | { |
100 | return false; |
101 | } |
102 | |
103 | QRectF QSGSoftwareSpriteNode::rect() const |
104 | { |
105 | return QRectF(0, 0, m_size.width(), m_size.height()); |
106 | } |
107 | |
108 | QT_END_NAMESPACE |
109 |