File indexing completed on 2024-03-24 15:14:06

0001 /*
0002  * box2ddebugdraw.h
0003  * Copyright (c) 2010 Thorbjørn Lindeijer <thorbjorn@lindeijer.nl>
0004  * Copyright (c) 2014 Moukhlynin Ruslan <ruslan@khvmntk.ru>
0005  *
0006  * This file is part of the Box2D QML plugin.
0007  *
0008  * This software is provided 'as-is', without any express or implied warranty.
0009  * In no event will the authors be held liable for any damages arising from
0010  * the use of this software.
0011  *
0012  * Permission is granted to anyone to use this software for any purpose,
0013  * including commercial applications, and to alter it and redistribute it
0014  * freely, subject to the following restrictions:
0015  *
0016  * 1. The origin of this software must not be misrepresented; you must not
0017  *    claim that you wrote the original software. If you use this software in
0018  *    a product, an acknowledgment in the product documentation would be
0019  *    appreciated but is not required.
0020  *
0021  * 2. Altered source versions must be plainly marked as such, and must not be
0022  *    misrepresented as being the original software.
0023  *
0024  * 3. This notice may not be removed or altered from any source distribution.
0025  */
0026 
0027 #ifndef BOX2DDEBUGDRAW_H
0028 #define BOX2DDEBUGDRAW_H
0029 
0030 #include <QQuickItem>
0031 
0032 class Box2DWorld;
0033 
0034 class Box2DDebugDraw : public QQuickItem
0035 {
0036     Q_ENUMS(DebugFlag)
0037     Q_OBJECT
0038 
0039     Q_PROPERTY(qreal axisScale READ axisScale WRITE setAxisScale NOTIFY axisScaleChanged)
0040     Q_PROPERTY(DebugFlag flags READ flags WRITE setFlags NOTIFY flagsChanged)
0041     Q_PROPERTY(Box2DWorld *world READ world WRITE setWorld NOTIFY worldChanged)
0042 
0043 public:
0044     enum DebugFlag {
0045         Shape = 1,
0046         Joint = 2,
0047         AABB = 4,
0048         Pair = 8,
0049         CenterOfMass = 16,
0050         Everything = 31
0051     };
0052     explicit Box2DDebugDraw(QQuickItem *parent = 0);
0053 
0054     qreal axisScale() const;
0055     void setAxisScale(qreal _axisScale);
0056 
0057     DebugFlag flags() const;
0058     void setFlags(DebugFlag flags);
0059 
0060     Box2DWorld *world() const;
0061     void setWorld(Box2DWorld *world);
0062 
0063 protected:
0064     QSGNode *updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData *);
0065 
0066 signals:
0067     void axisScaleChanged();
0068     void flagsChanged();
0069     void worldChanged();
0070 
0071 private slots:
0072     void onWorldStepped();
0073 
0074 private:
0075     Box2DWorld *mWorld;
0076     qreal mAxisScale;
0077     DebugFlag mFlags;
0078 };
0079 
0080 inline qreal Box2DDebugDraw::axisScale() const
0081 {
0082     return mAxisScale;
0083 }
0084 
0085 inline Box2DDebugDraw::DebugFlag Box2DDebugDraw::flags() const
0086 {
0087     return mFlags;
0088 }
0089 
0090 inline Box2DWorld *Box2DDebugDraw::world() const
0091 {
0092     return mWorld;
0093 }
0094 
0095 #endif // BOX2DDEBUGDRAW_H