Added real animations to the Shogi animator.
[tagua.git] / src / piecepool.h
blobe4117e612f7cbafb605718695c4b8ae9ed11cf9f
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 PIECEPOOL_H
12 #define PIECEPOOL_H
14 #include <boost/shared_ptr.hpp>
15 #include "piecegroup.h"
16 #include "namedsprite.h"
18 /**
19 * @class PiecePool <piecepool.h>
20 * @brief The class representing a crazyhouse-like piece pool.
22 * PiecePool is a canvas item attached to a Board that keeps a
23 * stack of pieces and lets you drop them on the board, notifying
24 * the board.
26 class PiecePool : public ClickableCanvas {
28 private:
29 int m_pool_num;
31 /** displayed m_sprites */
32 std::vector<NamedSprite> m_sprites;
34 /** refrence board */
35 class Board* m_board;
37 /** true if flipped */
38 bool m_flipped;
40 /** size if a square */
41 int m_square_size;
43 /** the width of the pool (ie how many pieces) */
44 int m_width;
46 /** loader class, to load pieces */
47 PixmapLoader m_loader;
49 /** the piece that is being dragged, if any */
50 NamedSprite m_dragged;
52 /** the index of the piece being dragged */
53 int m_dragged_index;
55 /** main animation structure */
56 MainAnimation* m_main_animation;
58 /** internal function, resizes the grid vector to hold x pieces */
59 void setFill(int x);
61 /** removes the drag putting it back together with his friends in the pool.
62 if fadeOff is true the current drag will fade off while a new piece will
63 fade in the pool, while if fadeOff is false the fade off is not done.
64 fadeOff will typically be false if the piece sprite has been used in the
65 board and we don't want a clone that is fading off */
66 void cancelDragging(bool fadeOff = true);
68 /** takes the named sprite */
69 NamedSprite takeSpriteAt(int i);
71 /** converts an index to the upper left point of the corresponding square */
72 QPoint toReal(int i);
74 /** finds to which index corresponds the point p, or -1 if corresponds to none */
75 int toLogical(const QPoint& p);
77 public:
78 friend class GraphicalSystem;
79 friend class ChessTable;
81 /** Constructor, requires the board the pool will be attached to */
82 PiecePool(int num, Board* b, KGameCanvasAbstract* parent);
83 ~PiecePool();
85 /** returns the sprite loader */
86 PixmapLoader* loader() { return &m_loader; }
88 /** returns the sprite loader */
89 const PixmapLoader* loader() const { return &m_loader; }
91 /** returns the flipped value */
92 bool flipped() const { return m_flipped; }
94 /** returns the number of pieces in the pool */
95 int fill();
97 /** removes all the pieces */
98 void clear();
100 /** adds a sprite to the pool */
101 void insertSprite(int index, const NamedSprite& sprite);
103 /** \return the sprite at the given index. */
104 NamedSprite getSprite(int index);
106 /** removes the sprite at the given index from the pool and returns it. */
107 NamedSprite takeSprite(int index);
111 /** sets the width of the grid (the fill will stay the same, and the
112 grid height will be recalculated) */
113 void setGridWidth(int w);
115 /** piecesGroup overload */
116 virtual KGameCanvasAbstract* piecesGroup();
118 /** the rect that will be covered by the pool */
119 virtual QRect boardRect() { return QRect(pos(), QSize(m_square_size*m_width,
120 (m_flipped?-1:1)*m_square_size*((m_sprites.size()+m_width-1)/m_width)) ); }
122 /** flips and moves the pieces in the pool at the same time */
123 void flipAndMoveBy(QPoint p);
125 /** mouse release event */
126 virtual void onMouseRelease(const QPoint& pos, int button);
128 /** mouse press event */
129 virtual void onMousePress(const QPoint& pos, int button);
131 /** mouse move event */
132 virtual void onMouseMove(const QPoint& pos, int button);
134 /** resize event (new_size is the new size of a SQUARE) */
135 virtual void onResize(int new_size, bool force_reload = false);
137 /** changed settings handler */
138 virtual void settingsChanged();
141 #endif //PIECEPOOL_H