1 | // Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
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 "qabstractspritesheet.h" |
5 | #include "qabstractspritesheet_p.h" |
6 | |
7 | #include <Qt3DRender/qabstracttexture.h> |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | using namespace Qt3DCore; |
12 | |
13 | namespace Qt3DExtras { |
14 | |
15 | QAbstractSpriteSheetPrivate::() |
16 | : QNodePrivate() |
17 | , m_texture(nullptr) |
18 | , m_currentIndex(-1) |
19 | { |
20 | } |
21 | |
22 | void QAbstractSpriteSheetPrivate::() |
23 | { |
24 | m_textureTransform.setToIdentity(); |
25 | } |
26 | |
27 | void QAbstractSpriteSheetPrivate::(Qt3DRender::QAbstractTexture *texture) |
28 | { |
29 | if (m_texture) { |
30 | disconnect(sender: m_texture, signal: &Qt3DRender::QAbstractTexture::widthChanged, |
31 | receiverPrivate: this, slot: &QAbstractSpriteSheetPrivate::updateSizes); |
32 | disconnect(sender: m_texture, signal: &Qt3DRender::QAbstractTexture::heightChanged, |
33 | receiverPrivate: this, slot: &QAbstractSpriteSheetPrivate::updateSizes); |
34 | } |
35 | m_texture = texture; |
36 | if (m_texture) { |
37 | connect(sender: m_texture, signal: &Qt3DRender::QAbstractTexture::widthChanged, |
38 | receiverPrivate: this, slot: &QAbstractSpriteSheetPrivate::updateSizes); |
39 | connect(sender: m_texture, signal: &Qt3DRender::QAbstractTexture::heightChanged, |
40 | receiverPrivate: this, slot: &QAbstractSpriteSheetPrivate::updateSizes); |
41 | } |
42 | } |
43 | |
44 | void QAbstractSpriteSheetPrivate::(int newIndex) |
45 | { |
46 | Q_Q(QAbstractSpriteSheet); |
47 | if (newIndex > maxIndex()) |
48 | newIndex = 0; |
49 | |
50 | m_currentIndex = newIndex; |
51 | emit q->currentIndexChanged(currentIndex: newIndex); |
52 | updateTransform(); |
53 | } |
54 | |
55 | QAbstractSpriteSheet::(QAbstractSpriteSheetPrivate &dd, QNode *parent) |
56 | : Qt3DCore::QNode(dd, parent) |
57 | { |
58 | Q_D(QAbstractSpriteSheet); |
59 | d->init(); |
60 | } |
61 | |
62 | QAbstractSpriteSheet::() |
63 | { |
64 | } |
65 | |
66 | /*! |
67 | \property Qt3DExtras::QAbstractSpriteSheet::texture |
68 | |
69 | Holds the current texture used by the material. |
70 | */ |
71 | Qt3DRender::QAbstractTexture *QAbstractSpriteSheet::() const |
72 | { |
73 | Q_D(const QAbstractSpriteSheet); |
74 | return d->m_texture; |
75 | } |
76 | |
77 | void QAbstractSpriteSheet::(Qt3DRender::QAbstractTexture *texture) |
78 | { |
79 | Q_D(QAbstractSpriteSheet); |
80 | if (d->m_texture != texture) { |
81 | d->updateTexture(texture); |
82 | d->updateSizes(); |
83 | emit textureChanged(texture: d->m_texture); |
84 | } |
85 | } |
86 | |
87 | QMatrix3x3 QAbstractSpriteSheet::() const |
88 | { |
89 | Q_D(const QAbstractSpriteSheet); |
90 | return d->m_textureTransform; |
91 | } |
92 | |
93 | int QAbstractSpriteSheet::() const |
94 | { |
95 | Q_D(const QAbstractSpriteSheet); |
96 | return d->m_currentIndex; |
97 | } |
98 | |
99 | void QAbstractSpriteSheet::(int currentIndex) |
100 | { |
101 | Q_D(QAbstractSpriteSheet); |
102 | d->updateIndex(newIndex: currentIndex); |
103 | } |
104 | |
105 | } // namespace Qt3DExtras |
106 | |
107 | QT_END_NAMESPACE |
108 | |
109 | #include "moc_qabstractspritesheet.cpp" |
110 | |