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