Added gitignore
[tagua/yd.git] / src / piecegroup.h
blobdcdb5a4ca8c07e30452c548df0898ea578adb786
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef BOARD_H
12 #define BOARD_H
14 #include <boost/shared_ptr.hpp>
15 #include "canvas/group.h"
16 #include "point.h"
17 #include "grid.h"
18 #include "animation.h"
19 #include "piecesprite.h"
20 #include "mainanimation.h"
21 #include "pointconverter.h"
22 #include "spriteloader.h"
23 #include "clickablecanvas.h"
24 #include "element.h"
26 class MainAnimation;
27 class PointConverter;
28 class SpriteLoader;
30 //BEGIN PieceGroup
32 /**
33 * @class PieceGroup <piecegroup.h>
34 * @brief The abstract base class for all widgets that draw pieces.
36 * PieceGroup is a general abstract widget that can be subclassed to
37 * implement a rectangular widget with piece m_sprites on it.
38 * It uses the method template pattern to provide a flexible yet comfortable
39 * api for subclassing.
41 class PieceGroup : public ClickableCanvas, protected PointConverter {
42 public:
44 protected:
45 /** fading animations enabled */
46 bool m_anim_fade;
48 /** movement animations enabled */
49 bool m_anim_movement;
51 /** true if the board is flipped */
52 bool m_flipped;
54 /** size of a square in points */
55 int m_square_size;
57 /** loader class, to load pieces */
58 SpriteLoader m_loader;
60 /** main animation structure */
61 MainAnimation* m_main_animation;
63 /** enqueue an animation */
64 void enqueue(const boost::shared_ptr<Animation>&);
66 /** stops all animations */
67 void stopAnimations();
69 /** finalizes an animaiton group */
70 void finalizeAnimation(AnimationGroup*);
72 /** ajdusts the sprite's position */
73 void adjustSprite(const Point&, bool smooth = false);
75 /** enqueue a movement animation (convenience function) */
76 void animatePiece(const boost::shared_ptr<PieceSprite>& piece,
77 const Point& to, double speed);
79 /** fades in the sprite at a given point */
80 void fadeIn(const Point&);
82 /** returns the sprite at p */
83 virtual boost::shared_ptr<PieceSprite> spriteAt(const Point&) = 0;
85 public:
86 PieceGroup(Canvas::Abstract* parent);
87 virtual ~PieceGroup();
89 /** returns the point converter class */
90 PointConverter* converter() { return static_cast<PointConverter*>(this); }
92 /** returns the point converter class */
93 const PointConverter* converter() const { return static_cast<const PointConverter*>(this); }
95 /** returns the sprite loader */
96 SpriteLoader* loader() { return &m_loader; }
98 /** returns the sprite loader */
99 const SpriteLoader* loader() const { return &m_loader; }
101 /** returns the flipped value */
102 virtual bool flipped() const { return m_flipped; }
104 /** returns the size of a square */
105 virtual int squareSize() const { return m_square_size; }
107 /** returns the size of the grid */
108 virtual Point gridSize() const = 0;
110 /** returns the center of a square */
111 QPoint squareCenter(const QPoint& point) {
112 return point - QPoint(m_square_size, m_square_size) / 2;
115 /** x size (deprecated, use boardRect instead) */
116 int boardSizeX() { return m_square_size*gridSize().x; }
118 /** y size (deprecated, use boardRect instead) */
119 int boardSizeY() { return m_square_size*gridSize().y; }
121 /** returns the area covered by the piece grid */
122 virtual QRect boardRect() { return QRect(pos(), QSize(m_square_size*gridSize().x,
123 m_square_size*gridSize().y)); }
125 /** returns the group that contains the pieces (override this) */
126 virtual Canvas::Abstract* piecesGroup() = 0;
128 /** resize event handler (updates the sprites and the square size) */
129 virtual void onResize(int new_size, bool force_reload = false);
131 /** changed settings handler */
132 virtual void settingsChanged();
134 /** create a sprite from a pixmap */
135 virtual boost::shared_ptr<PieceSprite> createSprite(const QPixmap& pix, const Point& pos);
138 //END PieceGroup
140 #endif