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.
11 #ifndef GRAPHICALSYSTEM_H
12 #define GRAPHICALSYSTEM_H
14 #include <boost/shared_ptr.hpp>
16 #include "graphicalapi.h"
22 class GraphicalSystem
: public QObject
, private GraphicalAPI
{
27 /** The current chess table */
30 /** The current board */
33 /** The position data */
34 AbstractPosition::Ptr m_pos
;
36 /** The variant specific animator */
37 AbstractAnimator::Ptr m_animator
;
39 /** The current variant */
40 VariantInfo
* m_variant
;
42 /** @a GraphicalPosition interface function implementation */
43 // virtual void addTag(const QString& name, Point, bool over = false);
45 /** @a GraphicalPosition interface function implementation */
46 // virtual void clearTags(const QString& name);
48 /** @a GraphicalPosition interface function implementation */
49 // virtual void setTags(const QString& name, Point p1 = Point::invalid(), Point p2 = Point::invalid(),
50 // Point p3 = Point::invalid(), Point p4 = Point::invalid(),
51 // Point p5 = Point::invalid(), Point p6 = Point::invalid() );
54 /** internal function to listen at setting changes */
55 void settingsChanged();
59 * \return the current abstract position. (interface for GraphicalAPI)
61 virtual const PointConverter
* converter() const;
64 * \return the current abstract position. (interface for GraphicalAPI)
66 virtual AbstractPosition::Ptr
position() const;
69 * \return a sprite at the position \a index in the graphical pool. (interface for GraphicalAPI)
71 virtual NamedSprite
getSprite(const Point
& p
);
74 * Removes a sprite at the position \a index in the graphical pool. (interface for GraphicalAPI)
75 * \return the newly created sprite.
77 virtual NamedSprite
takeSprite(const Point
& p
);
80 * Sets the piece at the position \a index in the graphical pool. (interface for GraphicalAPI)
81 * \return the newly created sprite.
83 virtual NamedSprite
setPiece(const Point
& p
, const AbstractPiece
* piece
, bool show
);
86 * Create a new piece, but do not add it to the graphical system.
87 * \return the newly created sprite.
89 virtual NamedSprite
createPiece(const Point
& p
, const AbstractPiece
* piece
, bool show
);
92 * Sets the sprite at the position \a index in the graphical pool. (interface for GraphicalAPI)
93 * \return the newly created sprite.
95 virtual void setSprite(const Point
& p
, const NamedSprite
& sprite
);
98 * \return how many sprites are contained in the pool
100 virtual int poolSize(int pool
);
103 * \return the sprite at the position \a index in the graphical pool. (interface for GraphicalAPI)
105 //virtual NamedSprite getPoolSprite(int pool, int index);
108 * Removes the sprite at the position \a index in the graphical pool. (interface for GraphicalAPI)
110 virtual void removePoolSprite(int pool
, int index
);
113 * Removes the sprite at the position \a index in the graphical pool (only for drops).
114 * (interface for GraphicalAPI)
115 * \return the removed sprite.
117 virtual NamedSprite
takePoolSprite(int pool
, int index
);
120 * Inserts a sprite at the position \a index in the graphical pool. (interface for GraphicalAPI)
121 * \return the newly created sprite.
123 virtual NamedSprite
insertPoolPiece(int pool
, int index
, const AbstractPiece
* piece
);
126 * \return the piece of the pool that has been dropped, or (-1,-1). (interface for GraphicalAPI)
128 virtual std::pair
<int, int> droppedPoolPiece();
131 * Create an animation from a scheme.
133 virtual AnimationPtr
animate(const Animate::Scheme
& scheme
, Animate::AnimationType type
);
136 GraphicalSystem(ChessTable
* view
, AbstractPosition::Ptr startingPosition
,
137 VariantInfo
* variant
);
138 virtual ~GraphicalSystem();
140 /** Sets the reference entity */
141 void setup(const boost::shared_ptr
<UserEntity
>& entity
);
143 /** Goes forward playing a move, that has to be legal and checked */
144 void forward(const AbstractMove::Ptr
& move
,
145 const AbstractPosition::Ptr
& pos
,
146 const SpritePtr
& = SpritePtr());
148 /** Goes back undoing a move, that has to be legal and checked */
149 void back(const AbstractMove::Ptr
& lastMove
,
150 const AbstractMove::Ptr
& move
,
151 const AbstractPosition::Ptr
& pos
);
153 /** Warps to a new position */
154 void warp(const AbstractMove::Ptr
& lastMove
,
155 const AbstractPosition::Ptr
& pos
);
157 /** Adjusts a sprite to the correct position */
158 void adjustSprite(const Point
& p
);
160 /** Sets the current turn */
161 void setTurn(int turn
);
165 #endif //GRAPHICALSYSTEM_H