1 /*
2  * box2dgearjoint.h
3  * Copyright (c) 2011 Joonas Erkinheimo <joonas.erkinheimo@nokia.com>
4  *
5  * This file is part of the Box2D QML plugin.
6  *
7  * This software is provided 'as-is', without any express or implied warranty.
8  * In no event will the authors be held liable for any damages arising from
9  * the use of this software.
10  *
11  * Permission is granted to anyone to use this software for any purpose,
12  * including commercial applications, and to alter it and redistribute it
13  * freely, subject to the following restrictions:
14  *
15  * 1. The origin of this software must not be misrepresented; you must not
16  *    claim that you wrote the original software. If you use this software in
17  *    a product, an acknowledgment in the product documentation would be
18  *    appreciated but is not required.
19  *
20  * 2. Altered source versions must be plainly marked as such, and must not be
21  *    misrepresented as being the original software.
22  *
23  * 3. This notice may not be removed or altered from any source distribution.
24  */
25 
26 #ifndef BOX2DGEARJOINT_H
27 #define BOX2DGEARJOINT_H
28 
29 #include "box2djoint.h"
30 #include <Box2D.h>
31 
32 class Box2DGearJoint : public Box2DJoint
33 {
34     Q_OBJECT
35 
36     Q_PROPERTY(Box2DJoint *joint1 READ joint1 WRITE setJoint1 NOTIFY joint1Changed)
37     Q_PROPERTY(Box2DJoint *joint2 READ joint2 WRITE setJoint2 NOTIFY joint2Changed)
38     Q_PROPERTY(float ratio READ ratio WRITE setRatio NOTIFY ratioChanged)
39 
40 public:
41     explicit Box2DGearJoint(QObject *parent = 0);
42 
43     Box2DJoint *joint1() const;
44     void setJoint1(Box2DJoint *joint1);
45 
46     Box2DJoint *joint2() const;
47     void setJoint2(Box2DJoint *joint2);
48 
49     float ratio() const;
50     void setRatio(float ratio);
51 
52     b2GearJoint *gearJoint() const;
53 
54 signals:
55     void joint1Changed();
56     void joint2Changed();
57     void ratioChanged();
58 
59 protected:
60     b2Joint *createJoint();
61 
62 private slots:
63     void joint1Created();
64     void joint2Created();
65 
66 private:
67     Box2DJoint *m_joint1;
68     Box2DJoint *m_joint2;
69     float m_ratio;
70 };
71 
joint1()72 inline Box2DJoint *Box2DGearJoint::joint1() const
73 {
74     return m_joint1;
75 }
76 
joint2()77 inline Box2DJoint *Box2DGearJoint::joint2() const
78 {
79     return m_joint2;
80 }
81 
ratio()82 inline float Box2DGearJoint::ratio() const
83 {
84     return m_ratio;
85 }
86 
gearJoint()87 inline b2GearJoint *Box2DGearJoint::gearJoint() const
88 {
89     return static_cast<b2GearJoint*>(joint());
90 }
91 
92 #endif // BOX2DGEARJOINT_H
93