~keith-penguin/kdegames/trunk

« back to all changes in this revision

Viewing changes to kbreakout/src/item.h

  • Committer: Keith Worrell
  • Date: 2009-03-18 05:35:28 UTC
  • Revision ID: keith.worrell@gmail.com-20090318053528-mx6x9c0ngmg0kg6p
imported project

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright 2007-2008 Fela Winkelmolen <fela.kde@gmail.com> 
 
3
  
 
4
    This program is free software: you can redistribute it and/or modify
 
5
    it under the terms of the GNU General Public License as published by
 
6
    the Free Software Foundation, either version 2 of the License, or
 
7
    (at your option) any later version.
 
8
   
 
9
    This program is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
    GNU General Public License for more details.
 
13
   
 
14
    You should have received a copy of the GNU General Public License
 
15
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
*/
 
17
 
 
18
#ifndef ITEM_H
 
19
#define ITEM_H
 
20
 
 
21
#include <KGameCanvas>
 
22
 
 
23
#include "globals.h"
 
24
 
 
25
 
 
26
// all items (balls, bricks, ...) inerit from this class
 
27
// initially svg and the abstract canvas are set to 0, before calling the 
 
28
// constructor setSvgRenderer() and setCanvasAbstract() should be called!!!
 
29
// TODO: should be and abstract class???
 
30
class Item : public QObject, private KGameCanvasPixmap
 
31
{
 
32
    Q_OBJECT
 
33
public:
 
34
    Item();
 
35
    ~Item();
 
36
    
 
37
    static void setCanvas(KGameCanvasWidget *);
 
38
 
 
39
    static qreal scale() {return m_scale;}
 
40
    static int borderLeft() {return m_borderLeft;}
 
41
    
 
42
    // make superclass functions accessible
 
43
    using KGameCanvasPixmap::hide;
 
44
    using KGameCanvasPixmap::show;
 
45
    using KGameCanvasPixmap::raise;
 
46
    //using KGameCanvasPixmap::visible;
 
47
    using KGameCanvasPixmap::setPixmap;
 
48
    //void hide() {KGameCanvasPixmap::hide();}
 
49
    //void show() {KGameCanvasPixmap::show();}
 
50
    bool isVisible() {return KGameCanvasItem::visible();}
 
51
    //void setPixmap(const QPixmap &p) {KGameCanvasPixmap::setPixmap(p);}
 
52
    
 
53
    void setType(const QString &type);
 
54
    QString type() const {return elementId;}
 
55
    
 
56
    void setRect(const QRectF &newBoundingRect);
 
57
    
 
58
    //rect() const is virtual so DON'T use that name!!!
 
59
    QRect getRect() const;
 
60
    QPoint position() const {return m_position.toPoint();}
 
61
    
 
62
    void moveTo(qreal x, qreal y);
 
63
    //void moveTo(int x, int y);
 
64
    void moveTo(const QPointF &point);
 
65
    void moveBy(qreal dx, qreal dy);
 
66
    void repaint();
 
67
 
 
68
public slots:
 
69
    // load or reloads the sprite
 
70
    virtual void loadSprite();
 
71
    
 
72
protected:
 
73
    static void updateScale();
 
74
    
 
75
    // canvas container of all Items
 
76
    static KGameCanvasWidget *canvas;
 
77
    
 
78
    // TODO: rename to m_scaleRatio
 
79
    static qreal m_scale;
 
80
    static int m_borderLeft;
 
81
    static int m_borderTop;
 
82
    
 
83
    int width;
 
84
    int height;
 
85
    QPointF m_position;
 
86
    QString elementId;
 
87
};
 
88
 
 
89
#endif //ITEM_H