2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
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 <core/taguaapi.h>
17 #include <core/piece.h>
18 #include <core/state_fwd.h>
19 #include <core/namedsprite.h>
31 class GraphicalSystem
: public QObject
,
37 /** The current chess table */
40 /** The current board */
43 /** The current state */
46 /** The variant specific animator */
47 IAnimator
* m_animator
;
49 /** The current variant */
54 /** @a GraphicalPosition interface function implementation */
55 // virtual void addTag(const QString& name, Point, bool over = false);
57 /** @a GraphicalPosition interface function implementation */
58 // virtual void clearTags(const QString& name);
60 /** @a GraphicalPosition interface function implementation */
61 // virtual void setTags(const QString& name, Point p1 = Point::invalid(), Point p2 = Point::invalid(),
62 // Point p3 = Point::invalid(), Point p4 = Point::invalid(),
63 // Point p5 = Point::invalid(), Point p6 = Point::invalid() );
66 /** internal function to listen at setting changes */
67 void settingsChanged();
71 * \return the current abstract position. (interface for GraphicalAPI)
73 virtual const PointConverter
* converter() const;
76 * \return the current abstract position. (interface for GraphicalAPI)
78 virtual const IState
* state() const;
81 * \return a sprite at the position \a index in the graphical pool. (interface for GraphicalAPI)
83 virtual NamedSprite
getSprite(const Point
& p
);
86 * Removes a sprite at the position \a index in the graphical pool. (interface for GraphicalAPI)
87 * \return the newly created sprite.
89 virtual NamedSprite
takeSprite(const Point
& p
);
92 * Sets the piece at the position \a index in the graphical pool. (interface for GraphicalAPI)
93 * \return the newly created sprite.
95 virtual NamedSprite
setPiece(const Point
& p
, const Piece
& piece
, bool show
);
98 * Create a new piece, but do not add it to the graphical system.
99 * \return the newly created sprite.
101 virtual NamedSprite
createPiece(const Point
& p
, const Piece
& piece
, bool show
);
104 * Sets the sprite at the position \a index in the graphical pool. (interface for GraphicalAPI)
105 * \return the newly created sprite.
107 virtual void setSprite(const Point
& p
, const NamedSprite
& sprite
);
110 * \return how many sprites are contained in the pool
112 virtual int poolSize(int pool
);
115 * \return the sprite at the position \a index in the graphical pool. (interface for GraphicalAPI)
117 virtual NamedSprite
getPoolSprite(int pool
, int index
);
120 * Removes the sprite at the position \a index in the graphical pool. (interface for GraphicalAPI)
122 virtual void removePoolSprite(int pool
, int index
);
125 * Removes the sprite at the position \a index in the graphical pool (only for drops).
126 * (interface for GraphicalAPI)
127 * \return the removed sprite.
129 virtual NamedSprite
takePoolSprite(int pool
, int index
);
132 * Inserts a sprite at the position \a index in the graphical pool. (interface for GraphicalAPI)
133 * \return the newly created sprite.
135 virtual NamedSprite
insertPoolPiece(int pool
, int index
, const Piece
& piece
);
138 * \return the piece of the pool that has been dropped, or (-1,-1). (interface for GraphicalAPI)
140 virtual std::pair
<const IColor
*, int> droppedPoolPiece();
144 GraphicalSystem(ChessTable
* view
, const StatePtr
& startingPosition
, Variant
* variant
);
145 virtual ~GraphicalSystem();
147 /** Sets the reference entity */
148 void setup(const boost::shared_ptr
<UserEntity
>& entity
);
150 /** Goes forward playing a move, that has to be legal and checked */
151 void forward(const Move
& move
,
153 const SpritePtr
& = SpritePtr());
155 /** Goes back undoing a move, that has to be legal and checked */
156 void back(const Move
& lastMove
,
158 const StatePtr
& pos
);
160 /** Warps to a new position */
161 void warp(const Move
& lastMove
,
162 const StatePtr
& pos
);
164 /** Adjusts a sprite to the correct position */
165 void adjustSprite(const Point
& p
);
167 /** Sets the current turn */
168 void setTurn(const IColor
* turn
);
173 const INamer
* namer() const { return m_namer
; }
175 // TODO: factor the following animation related functions
176 // out into a separate class
177 virtual AnimationPtr
group(const QString
& flags
) const;
178 virtual AnimationPtr
appear(const NamedSprite
& sprite
,
179 const QString
& flags
) const;
180 virtual AnimationPtr
disappear(const NamedSprite
& sprite
,
181 const QString
& flags
) const;
182 virtual AnimationPtr
move(const NamedSprite
& sprite
,
183 const Point
& destination
,
184 const QString
& flags
) const;
185 virtual AnimationPtr
move(const NamedSprite
& sprite
,
187 const QString
& flags
) const;
188 virtual AnimationPtr
morph(const NamedSprite
& sprite1
,
189 const NamedSprite
& sprite2
,
190 const QString
& flags
) const;
196 #endif //GRAPHICALSYSTEM_H