Added real animations to the Shogi animator.
[tagua.git] / src / graphicalinfo.h__
blobf38dd936f7f9d5d507829d22a154e055278e1503
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 GRAPHICALINFO_H
12 #define GRAPHICALINFO_H
14 #include <boost/shared_ptr.hpp>
15 #include <QObject>
16 #include "kboard.h"
17 #include "element.h"
18 #include "graphicalposition.h"
20 class ChessTable;
21 class Board;
22 class Animator;
23 class GraphicalPosition;
24 class UserEntity;
25 class GraphicalInfo;
27 class GraphicalInfoProxy : public QObject {
28 Q_OBJECT
29   friend class GraphicalInfo;
30   GraphicalInfo *m_info;
31   GraphicalInfoProxy(GraphicalInfo *i) : QObject(), m_info(i) {}
33 public slots:
34   void settingsChanged();
37 /**
38   * @class GraphicalInfo <graphicalinfo.h>
39   * @brief The graphical information about sprites and pieces.
40   *
41   * This class provides the variant's animator the facilites requires to add/remove
42   * pieces to and from the board, keeping syncronized the sprites and the underlaying
43   * board pieces.
44   */
45 class GraphicalInfo : private GraphicalPosition {
46 public: // TODO: temporarily remove access limitations.
47         // NOTE to Maurizio:why are getElement, setElement, etc... private?
48   typedef boost::shared_ptr<PieceSprite> SpritePtr;
50   /** The current chess table */
51   ChessTable* m_view;
53   /** The current board */
54   Board* m_board;
56   /** The position data */
57   AbstractPosition::Ptr m_pos;
59   /** The variant specific animator */
60   AbstractAnimator::Ptr m_animator;
62   /** The current variant */
63   VariantInfo* m_variant;
65   /** signal proxy */
66   GraphicalInfoProxy* m_proxy;
68   /** @a GraphicalPosition interface function implementation */
69   virtual int getIntSetting(const QString& key, int def_value) const;
71   /** @a GraphicalPosition interface function implementation */
72   virtual bool getBoolSetting(const QString& key, bool def_value) const;
74   /** @a GraphicalPosition interface function implementation */
75   virtual QString getStringSetting(const QString& key, const QString& def_value) const;
77   /** @a GraphicalPosition interface function implementation */
78   virtual SpritePtr getSprite(const Point& p) const;
80   /** @a GraphicalPosition interface function implementation */
81   virtual SpritePtr setPiece(const Point& p, AbstractPiece::Ptr e,
82                               bool usedrop = false, bool show = true);
84   /** @a GraphicalPosition interface function implementation */
85   virtual Element getElement(const Point& p) const;
87   /** @a GraphicalPosition interface function implementation */
88   virtual void setElement(const Point& p, const Element& e);
90   /** @a GraphicalPosition interface function implementation */
91   virtual void removeElement(const Point& p);
93   /** @a GraphicalPosition interface function implementation */
94   virtual void updatePool(AbstractPosition::PoolPtr pool);
96   /** @a GraphicalPosition interface function implementation */
97   virtual void addTag(const QString& name, Point, bool over = false);
99   /** @a GraphicalPosition interface function implementation */
100   virtual void clearTags(const QString& name);
102   /** @a GraphicalPosition interface function implementation */
103   virtual void setTags(const QString& name, Point p1 = Point::invalid(), Point p2 = Point::invalid(),
104                                       Point p3 = Point::invalid(), Point p4 = Point::invalid(),
105                                       Point p5 = Point::invalid(), Point p6 = Point::invalid() );
107   /** @a GraphicalPosition interface function implementation */
108   virtual Point first() const;
110   /** @a GraphicalPosition interface function implementation */
111   virtual Point last() const;
113   /** @a GraphicalPosition interface function implementation */
114   virtual Point next(const Point& p) const;
116   /** @a GraphicalPosition interface function implementation */
117   virtual bool valid(const Point& p) const;
120   /** @a GraphicalPosition interface function implementation */
121   virtual bool consistent() const;
123   /** internal function */
124   void settingsChanged();
126   /** internal function */
127   virtual void addToPool(AbstractPiece::Ptr p, int n);
129   /** internal function */
130   virtual void removeFromPool(AbstractPiece::Ptr p, int n);
132 public:
133   /** Constructor */
134   GraphicalInfo(ChessTable* view, AbstractPosition::Ptr startingPosition,
135                                               VariantInfo* variant);
136   virtual ~GraphicalInfo();
138   /** Sets the reference entity */
139   void setup(const boost::shared_ptr<UserEntity>& entity);
141   /** Goes forward playing a move, that has to be legal and checked */
142   void forward(AbstractMove::Ptr move, AbstractPosition::Ptr pos,
143                const boost::shared_ptr<PieceSprite>& = boost::shared_ptr<PieceSprite>());
145   /** Goes back undoing a move, that has to be legal and checked */
146   void back(AbstractMove::Ptr lastMove, AbstractMove::Ptr move, AbstractPosition::Ptr pos);
148   /** Warps to a new position */
149   void warp(AbstractMove::Ptr lastMove, AbstractPosition::Ptr pos);
151   /** Adjusts a sprite to the correct position */
152   void adjustSprite(const Point& p);
154   /** Sets the current turn */
155   void setTurn(int turn);
157   /** Returns the position */
158   AbstractPosition::Ptr position() const { return m_pos; }
162 #endif //GRAPHICALINFO_H