Initial porting to the new component API.
[tagua/yd.git] / src / graphicalsystem.h
blob9e8d54012c5355d2fc5b6c1c3e09beaa5eeb810b
1 /*
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.
9 */
11 #ifndef GRAPHICALSYSTEM_H
12 #define GRAPHICALSYSTEM_H
14 #include <boost/shared_ptr.hpp>
15 #include <QObject>
16 #include <core/taguaapi.h>
17 #include <core/piece.h>
18 #include <core/state_fwd.h>
19 #include <core/namedsprite.h>
21 class ChessBoard;
22 class ChessTable;
23 class IAnimator;
24 class INamer;
25 class IState;
26 class Move;
27 class PointConverter;
28 class UserEntity;
29 class Variant;
31 class GraphicalSystem : public QObject,
32 private TaguaAPI {
33 Q_OBJECT
35 public:
37 /** The current chess table */
38 ChessTable* m_view;
40 /** The current board */
41 ChessBoard* m_board;
43 /** The current state */
44 StatePtr m_state;
46 /** The variant specific animator */
47 IAnimator* m_animator;
49 /** The current variant */
50 Variant* m_variant;
52 INamer* m_namer;
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() );
65 public Q_SLOTS:
66 /** internal function to listen at setting changes */
67 void settingsChanged();
69 private:
70 /**
71 * \return the current abstract position. (interface for GraphicalAPI)
73 virtual const PointConverter* converter() const;
75 /**
76 * \return the current abstract position. (interface for GraphicalAPI)
78 virtual const IState* state() const;
80 /**
81 * \return a sprite at the position \a index in the graphical pool. (interface for GraphicalAPI)
83 virtual NamedSprite getSprite(const Point& p);
85 /**
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);
91 /**
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);
97 /**
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();
142 public:
143 /** Constructor */
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,
152 const StatePtr& pos,
153 const SpritePtr& = SpritePtr());
155 /** Goes back undoing a move, that has to be legal and checked */
156 void back(const Move& lastMove,
157 const Move& move,
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);
172 // TAGUA API
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,
186 int destination,
187 const QString& flags) const;
188 virtual AnimationPtr morph(const NamedSprite& sprite1,
189 const NamedSprite& sprite2,
190 const QString& flags) const;
192 Variant* variant();
196 #endif //GRAPHICALSYSTEM_H