diff options
author | Mike Krus <mike.krus@kdab.com> | 2017-06-27 10:36:59 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2017-07-08 09:08:37 +0000 |
commit | 55844801dc09da2d05e6f581ce7ad3d4d334b5c1 (patch) | |
tree | e6c9a3469a0897b89e6b92d944e7f851bfcc5c2e /src | |
parent | b21eef8788de6e93da79441a459bcbcba0f3085e (diff) |
Introduce QSpriteGrid
Takes a texture and a number of rows and columns.
Uses a current index to compute a texture transform to map
texture coordinates to a cell in the grid.
Abstract base class to use in SpriteSheet which
supports non regular grid sprite sheets (like a general
atlas).
Change-Id: Ia48bea22e2f687d8ae3ef1db4e41ae3c539e54d2
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/extras/defaults/defaults.pri | 6 | ||||
-rw-r--r-- | src/extras/defaults/qabstractspritesheet.cpp | 143 | ||||
-rw-r--r-- | src/extras/defaults/qabstractspritesheet.h | 93 | ||||
-rw-r--r-- | src/extras/defaults/qabstractspritesheet_p.h | 101 | ||||
-rw-r--r-- | src/extras/defaults/qspritegrid.cpp | 156 | ||||
-rw-r--r-- | src/extras/defaults/qspritegrid.h | 88 | ||||
-rw-r--r-- | src/extras/defaults/qspritegrid_p.h | 82 | ||||
-rw-r--r-- | src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp | 3 |
8 files changed, 672 insertions, 0 deletions
diff --git a/src/extras/defaults/defaults.pri b/src/extras/defaults/defaults.pri index 8a18fb6e9..fc16557eb 100644 --- a/src/extras/defaults/defaults.pri +++ b/src/extras/defaults/defaults.pri @@ -29,6 +29,10 @@ HEADERS += \ $$PWD/qfirstpersoncameracontroller_p.h \ $$PWD/qorbitcameracontroller.h \ $$PWD/qorbitcameracontroller_p.h \ + $$PWD/qspritegrid.h \ + $$PWD/qspritegrid_p.h \ + $$PWD/qabstractspritesheet.h \ + $$PWD/qabstractspritesheet_p.h \ $$PWD/qtexturematerial.h \ $$PWD/qtexturematerial_p.h \ $$PWD/qmetalroughmaterial.h \ @@ -53,6 +57,8 @@ SOURCES += \ $$PWD/qt3dwindow.cpp \ $$PWD/qfirstpersoncameracontroller.cpp \ $$PWD/qorbitcameracontroller.cpp \ + $$PWD/qspritegrid.cpp \ + $$PWD/qabstractspritesheet.cpp \ $$PWD/qtexturematerial.cpp \ $$PWD/qmetalroughmaterial.cpp \ $$PWD/qtexturedmetalroughmaterial.cpp \ diff --git a/src/extras/defaults/qabstractspritesheet.cpp b/src/extras/defaults/qabstractspritesheet.cpp new file mode 100644 index 000000000..640e600c7 --- /dev/null +++ b/src/extras/defaults/qabstractspritesheet.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qabstractspritesheet.h" +#include "qabstractspritesheet_p.h" + +#include <Qt3DRender/qabstracttexture.h> + +QT_BEGIN_NAMESPACE + +using namespace Qt3DCore; + +namespace Qt3DExtras { + +QAbstractSpriteSheetPrivate::QAbstractSpriteSheetPrivate() + : QNodePrivate() + , m_texture(nullptr) + , m_currentIndex(-1) +{ +} + +void QAbstractSpriteSheetPrivate::init() +{ + m_textureTransform.setToIdentity(); +} + +void QAbstractSpriteSheetPrivate::updateTexture(Qt3DRender::QAbstractTexture *texture) +{ + if (m_texture) { + disconnect(m_texture, &Qt3DRender::QAbstractTexture::widthChanged, + this, &QAbstractSpriteSheetPrivate::updateSizes); + disconnect(m_texture, &Qt3DRender::QAbstractTexture::heightChanged, + this, &QAbstractSpriteSheetPrivate::updateSizes); + } + m_texture = texture; + if (m_texture) { + connect(m_texture, &Qt3DRender::QAbstractTexture::widthChanged, + this, &QAbstractSpriteSheetPrivate::updateSizes); + connect(m_texture, &Qt3DRender::QAbstractTexture::heightChanged, + this, &QAbstractSpriteSheetPrivate::updateSizes); + } +} + +void QAbstractSpriteSheetPrivate::updateIndex(int newIndex) +{ + Q_Q(QAbstractSpriteSheet); + if (newIndex > maxIndex()) + newIndex = 0; + + m_currentIndex = newIndex; + emit q->currentIndexChanged(newIndex); + updateTransform(); +} + +QAbstractSpriteSheet::QAbstractSpriteSheet(QAbstractSpriteSheetPrivate &dd, QNode *parent) + : Qt3DCore::QNode(dd, parent) +{ + Q_D(QAbstractSpriteSheet); + d->init(); +} + +QAbstractSpriteSheet::~QAbstractSpriteSheet() +{ +} + +/*! + \property QAbstractSpriteSheet::texture + + Holds the current texture used by the material. +*/ +Qt3DRender::QAbstractTexture *QAbstractSpriteSheet::texture() const +{ + Q_D(const QAbstractSpriteSheet); + return d->m_texture; +} + +void QAbstractSpriteSheet::setTexture(Qt3DRender::QAbstractTexture *texture) +{ + Q_D(QAbstractSpriteSheet); + if (d->m_texture != texture) { + d->updateTexture(texture); + d->updateSizes(); + emit textureChanged(d->m_texture); + } +} + +QMatrix3x3 QAbstractSpriteSheet::textureTransform() const +{ + Q_D(const QAbstractSpriteSheet); + return d->m_textureTransform; +} + +int QAbstractSpriteSheet::currentIndex() const +{ + Q_D(const QAbstractSpriteSheet); + return d->m_currentIndex; +} + +void QAbstractSpriteSheet::setCurrentIndex(int currentIndex) +{ + Q_D(QAbstractSpriteSheet); + d->updateIndex(currentIndex); +} + +} // namespace Qt3DExtras + +QT_END_NAMESPACE diff --git a/src/extras/defaults/qabstractspritesheet.h b/src/extras/defaults/qabstractspritesheet.h new file mode 100644 index 000000000..cb8b70fd9 --- /dev/null +++ b/src/extras/defaults/qabstractspritesheet.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DEXTRAS_QABSTRACTSPRITESHEET_H +#define QT3DEXTRAS_QABSTRACTSPRITESHEET_H + +#include <Qt3DExtras/qt3dextras_global.h> +#include <Qt3DCore/QNode> +#include <QVector2D> +#include <QMatrix3x3> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QAbstractTexture; + +} // namespace Qt3DRender + +namespace Qt3DExtras { + +class QAbstractSpriteSheetPrivate; + +class QT3DEXTRASSHARED_EXPORT QAbstractSpriteSheet : public Qt3DCore::QNode +{ + Q_OBJECT + Q_PROPERTY(Qt3DRender::QAbstractTexture *texture READ texture WRITE setTexture NOTIFY textureChanged) + Q_PROPERTY(QMatrix3x3 textureTransform READ textureTransform NOTIFY textureTransformChanged) + Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) +public: + ~QAbstractSpriteSheet(); + + Qt3DRender::QAbstractTexture *texture() const; + QMatrix3x3 textureTransform() const; + int currentIndex() const; + +public Q_SLOTS: + void setTexture(Qt3DRender::QAbstractTexture *texture); + void setCurrentIndex(int currentIndex); + +Q_SIGNALS: + void textureChanged(Qt3DRender::QAbstractTexture *texture); + void textureTransformChanged(const QMatrix3x3 &textureTransform); + void currentIndexChanged(int currentIndex); + +protected: + explicit QAbstractSpriteSheet(QAbstractSpriteSheetPrivate &d, Qt3DCore::QNode *parent = nullptr); + +private: + Q_DECLARE_PRIVATE(QAbstractSpriteSheet) +}; + +} // Qt3DExtras + +QT_END_NAMESPACE + +#endif // QT3DEXTRAS_QABSTRACTSPRITESHEET_H diff --git a/src/extras/defaults/qabstractspritesheet_p.h b/src/extras/defaults/qabstractspritesheet_p.h new file mode 100644 index 000000000..604fc3c62 --- /dev/null +++ b/src/extras/defaults/qabstractspritesheet_p.h @@ -0,0 +1,101 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DEXTRAS_QABSTRACTSPRITESHEET_P_H +#define QT3DEXTRAS_QABSTRACTSPRITESHEET_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DCore/private/qnode_p.h> +#include <QMatrix3x3> +#include <QSize> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QFilterKey; +class QEffect; +class QAbstractTexture; +class QTechnique; +class QParameter; +class QShaderProgram; +class QRenderPass; + +} // namespace Qt3DRender + +namespace Qt3DExtras { + +class QAbstractSpriteSheet; + +class QAbstractSpriteSheetPrivate : public Qt3DCore::QNodePrivate +{ +public: + QAbstractSpriteSheetPrivate(); + + virtual void init(); + void updateTexture(Qt3DRender::QAbstractTexture *texture); + void updateIndex(int newIndex); + virtual int maxIndex() const = 0; + virtual void updateSizes() = 0; + virtual void updateTransform() = 0; + + Qt3DRender::QAbstractTexture *m_texture; + QMatrix3x3 m_textureTransform; + QSize m_textureSize; + int m_currentIndex; + + Q_DECLARE_PUBLIC(QAbstractSpriteSheet) +}; + +} // Qt3DExtras + +QT_END_NAMESPACE + +#endif // QT3DEXTRAS_QABSTRACTSPRITESHEET_P_H + diff --git a/src/extras/defaults/qspritegrid.cpp b/src/extras/defaults/qspritegrid.cpp new file mode 100644 index 000000000..31d4dd5c0 --- /dev/null +++ b/src/extras/defaults/qspritegrid.cpp @@ -0,0 +1,156 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qspritegrid.h" +#include "qspritegrid_p.h" + +#include <Qt3DRender/qabstracttexture.h> + +QT_BEGIN_NAMESPACE + +using namespace Qt3DCore; + +namespace Qt3DExtras { + +QSpriteGridPrivate::QSpriteGridPrivate() + : QAbstractSpriteSheetPrivate() + , m_numColumns(1) + , m_numRows(1) +{ +} + +int QSpriteGridPrivate::maxIndex() const +{ + return m_numColumns * m_numRows; +} + +void QSpriteGridPrivate::updateSizes() +{ + Q_Q(QSpriteGrid); + if (m_texture && m_numColumns && m_numRows) { + m_textureSize = QSize(m_texture->width(), m_texture->height()); + m_cellSize = QSize(m_texture->width() / m_numColumns, m_texture->height() / m_numRows); + } else { + m_textureSize = QSize(); + m_cellSize = QSize(); + } + + if (m_cellSize.isEmpty() || m_numColumns == 0 || m_numRows == 0) { + if (m_currentIndex != -1) { + m_currentIndex = -1; + emit q->currentIndexChanged(m_currentIndex); + } + m_textureTransform.setToIdentity(); + emit q->textureTransformChanged(m_textureTransform); + return; + } + + if (m_currentIndex == -1) { + m_currentIndex = 0; + emit q->currentIndexChanged(m_currentIndex); + } + updateTransform(); +} + +void QSpriteGridPrivate::updateTransform() +{ + Q_Q(QSpriteGrid); + const float xScale = (float) m_cellSize.width() / (float) m_textureSize.width(); + const float yScale = (float) m_cellSize.height() / (float) m_textureSize.height(); + + const int currentRow = m_currentIndex / m_numColumns; + const int currentColumn = m_currentIndex % m_numColumns; + const float xTranslate = currentColumn * xScale; + const float yTranslate = currentRow * yScale; + + m_textureTransform.setToIdentity(); + m_textureTransform(0, 0) = xScale; + m_textureTransform(1, 1) = yScale; + m_textureTransform(0, 2) = xTranslate; + m_textureTransform(1, 2) = yTranslate; + emit q->textureTransformChanged(m_textureTransform); +} + +/*! + Constructs a new QSpriteGrid instance with parent object \a parent. + */ +QSpriteGrid::QSpriteGrid(QNode *parent) + : QAbstractSpriteSheet(*new QSpriteGridPrivate, parent) +{ +} + +QSpriteGrid::~QSpriteGrid() +{ +} + +int QSpriteGrid::rows() const +{ + Q_D(const QSpriteGrid); + return d->m_numRows; +} + +void QSpriteGrid::setRows(int rows) +{ + Q_D(QSpriteGrid); + if (d->m_numRows != rows) { + d->m_numRows = rows; + d->updateSizes(); + emit rowsChanged(rows); + } +} + +int QSpriteGrid::columns() const +{ + Q_D(const QSpriteGrid); + return d->m_numColumns; +} + +void QSpriteGrid::setColumns(int columns) +{ + Q_D(QSpriteGrid); + if (d->m_numColumns != columns) { + d->m_numColumns = columns; + d->updateSizes(); + emit columnsChanged(columns); + } +} + +} // namespace Qt3DExtras + +QT_END_NAMESPACE diff --git a/src/extras/defaults/qspritegrid.h b/src/extras/defaults/qspritegrid.h new file mode 100644 index 000000000..47080a786 --- /dev/null +++ b/src/extras/defaults/qspritegrid.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DEXTRAS_QSPRITEGRID_H +#define QT3DEXTRAS_QSPRITEGRID_H + +#include <Qt3DExtras/qabstractspritesheet.h> +#include <Qt3DCore/qcomponent.h> +#include <QVector2D> +#include <QMatrix3x3> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +class QAbstractTexture; + +} // namespace Qt3DRender + +namespace Qt3DExtras { + +class QSpriteGridPrivate; + +class QT3DEXTRASSHARED_EXPORT QSpriteGrid : public QAbstractSpriteSheet +{ + Q_OBJECT + Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged) + Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged) +public: + explicit QSpriteGrid(Qt3DCore::QNode *parent = nullptr); + ~QSpriteGrid(); + + int rows() const; + int columns() const; + +public Q_SLOTS: + void setRows(int rows); + void setColumns(int columns); + +Q_SIGNALS: + void rowsChanged(int rows); + void columnsChanged(int columns); + +private: + Q_DECLARE_PRIVATE(QSpriteGrid) +}; + +} // Qt3DExtras + +QT_END_NAMESPACE + +#endif // QT3DEXTRAS_QSPRITEGRID_H diff --git a/src/extras/defaults/qspritegrid_p.h b/src/extras/defaults/qspritegrid_p.h new file mode 100644 index 000000000..6135ebf0d --- /dev/null +++ b/src/extras/defaults/qspritegrid_p.h @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DEXTRAS_QSPRITEGRID_P_H +#define QT3DEXTRAS_QSPRITEGRID_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <Qt3DExtras/private/qabstractspritesheet_p.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DExtras { + +class QSpriteGrid; + +class QSpriteGridPrivate : public QAbstractSpriteSheetPrivate +{ + QSpriteGridPrivate(); + + int maxIndex() const override; + void updateSizes() override; + void updateTransform() override; + + int m_numColumns; + int m_numRows; + QSize m_cellSize; + + Q_DECLARE_PUBLIC(QSpriteGrid) +}; + +} // Qt3DExtras + +QT_END_NAMESPACE + +#endif // QT3DEXTRAS_QSPRITEGRID_P_H + diff --git a/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp b/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp index 879b79294..125a087ab 100644 --- a/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp +++ b/src/quick3d/imports/extras/qt3dquick3dextrasplugin.cpp @@ -66,6 +66,7 @@ #include <Qt3DExtras/qskyboxentity.h> #include <Qt3DExtras/qspheregeometry.h> #include <Qt3DExtras/qspheremesh.h> +#include <Qt3DExtras/qspritegrid.h> #include <Qt3DExtras/qtext2dentity.h> #include <Qt3DExtras/qtexturedmetalroughmaterial.h> #include <Qt3DExtras/qtexturematerial.h> @@ -108,6 +109,8 @@ void Qt3DQuick3DExtrasPlugin::registerTypes(const char *uri) qmlRegisterType<Qt3DExtras::QTexturedMetalRoughMaterial>(uri, 2, 9, "TexturedMetalRoughMaterial"); qmlRegisterType<Qt3DExtras::QMorphPhongMaterial>(uri, 2, 9, "MorphPhongMaterial"); + qmlRegisterType<Qt3DExtras::QSpriteGrid>(uri, 2, 10, "SpriteGrid"); + // Meshes qmlRegisterType<Qt3DExtras::QConeMesh>(uri, 2, 0, "ConeMesh"); qmlRegisterType<Qt3DExtras::QConeGeometry>(uri, 2, 0, "ConeGeometry"); |