~neon/kolf/master

« back to all changes in this revision

Viewing changes to canvasitem.h

  • Committer: Stefan Majewsky
  • Date: 2010-10-31 23:23:16 UTC
  • Revision ID: git-v1:45f6fdbcc5733b0daa25631ea13b5b2f2d86f20e
Create a Box2D world, and attach Box2D bodies to all CanvasItems.

This is unfortunately a very large patch, because it touches everything
in the CanvasItem hierarchy, the ItemFactory, the KolfGame and the
shapes at once. All these objects are closely related through Box2D's
object hierarchy (world -> bodies -> fixtures -> shapes), so these
changes can hardly be split up further.

svn path=/trunk/KDE/kdegames/kolf/; revision=1191711

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include <QGraphicsRectItem>
28
28
#include <QGraphicsView>
29
29
#include <KDebug>
 
30
class b2Body;
 
31
class b2World;
30
32
 
31
33
class Ball;
32
34
class KConfigGroup;
41
43
class CanvasItem
42
44
{
43
45
public:
44
 
        CanvasItem() : game(0), m_overlay(0) { }
 
46
        CanvasItem(b2World* world);
45
47
        virtual ~CanvasItem();
46
48
        ///load your settings from the KConfigGroup, which represents a course.
47
49
        virtual void load(KConfigGroup *) {}
129
131
 
130
132
//AFTER THIS LINE follows what I have inserted during the refactoring
131
133
        public:
 
134
                enum SimulationFlag
 
135
                {
 
136
                        CollisionFlag = 1 << 0,
 
137
                        KinematicSimulationFlag = 1 << 1,
 
138
                        DynamicSimulationFlag = 1 << 2
 
139
                };
 
140
                enum SimulationType
 
141
                {
 
142
                        ///The object is immovable.
 
143
                        NoSimulation = 0,
 
144
                        ///The object is immovable, but other objects can interact with it.
 
145
                        CollisionSimulation = CollisionFlag,
 
146
                        ///The object moves according to its kinematic state.
 
147
                        KinematicSimulation = CollisionSimulation | KinematicSimulationFlag,
 
148
                        ///Other objects can collide with the shape of this object.
 
149
                        DynamicSimulation = KinematicSimulation | DynamicSimulationFlag
 
150
                };
 
151
 
132
152
                QList<Kolf::Shape*> shapes() const { return m_shapes; }
133
153
                Kolf::Overlay* overlay(bool createIfNecessary = true);
134
154
        protected:
135
155
                void addShape(Kolf::Shape* shape);
 
156
                ///Configure how this object will participate in physical simulation.
 
157
                void setSimulationType(CanvasItem::SimulationType type);
136
158
                ///Creates the optimal overlay for this object. The implementation does not have to propagate its properties to the overlay, as the overlay is updated just after it has been created.
137
159
                ///@warning Do not actually call this function from subclass implementations. Use overlay() instead.
138
160
                virtual Kolf::Overlay* createOverlay() { return 0; } //TODO: make this pure virtual when all CanvasItems are QGraphicsItems and implement createOverlay() (and then disallow createOverlay() == 0)
139
161
                ///This function should be called whenever the value of an object's property changes. This will most prominently cause the overlay to be updated (if it exists).
140
162
                void propagateUpdate();
141
163
        private:
 
164
                friend class Kolf::Shape; //for access to m_body
 
165
                b2Body* m_body;
 
166
 
142
167
                Kolf::Overlay* m_overlay;
143
168
                QList<Kolf::Shape*> m_shapes;
 
169
                CanvasItem::SimulationType m_simulationType;
144
170
};
145
171
 
146
172
//WARNING: pos() is at center (not at top-left edge of bounding rect!)
147
173
class EllipticalCanvasItem : public Tagaro::SpriteObjectItem, public CanvasItem
148
174
{
149
175
        public:
150
 
                EllipticalCanvasItem(bool withEllipse, const QString& spriteKey, QGraphicsItem* parent = 0);
 
176
                EllipticalCanvasItem(bool withEllipse, const QString& spriteKey, QGraphicsItem* parent, b2World* world);
151
177
                QGraphicsEllipseItem* ellipseItem() const { return m_ellipseItem; }
152
178
 
153
179
                virtual bool contains(const QPointF& point) const;