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.
15 #include "piecegroup.h"
16 #include "pointconverter.h"
17 #include "animation.h"
20 using namespace boost
;
24 PieceGroup::PieceGroup(Canvas::Abstract
* parent
)
25 : ClickableCanvas(parent
)
28 m_main_animation
= new MainAnimation( 1.0 );
32 PieceGroup::~PieceGroup()
34 delete m_main_animation
;
37 void PieceGroup::settingsChanged() {
38 Settings s_anim
= settings
.group("animations");
39 if (s_anim
.flag("enabled", true)) {
40 m_anim_fade
= s_anim
["fading"].flag("enabled", true);
41 m_anim_movement
= s_anim
["movement"].flag("enabled", true);
45 m_anim_movement
= false;
48 int speed
= (s_anim
["speed"] | 16);
49 int smoothness
= (s_anim
["smoothness"] | 16);
50 m_main_animation
->setSpeed( 0.4*pow(10.0, speed
/32.0) );
51 m_main_animation
->setDelay( int(70.0*pow(10.0, -smoothness
/32.0)) );
54 void PieceGroup::onResize(int new_size
, bool force_reload
) {
55 if(m_square_size
== new_size
&& !force_reload
)
58 m_square_size
= new_size
;
59 m_loader
.setSize(m_square_size
);
62 void PieceGroup::animatePiece(const shared_ptr
<Sprite
>& piece
,
63 const Point
& to
, double speed
) {
66 ? shared_ptr
<Animation
>(new MovementAnimation(piece
, converter()->toReal(to
), speed
))
67 : shared_ptr
<Animation
>(new InstantAnimation(piece
, converter()->toReal(to
)))
71 void PieceGroup::enqueue(const shared_ptr
<Animation
>& anim
) {
72 m_main_animation
->addAnimation(anim
);
75 void PieceGroup::stopAnimations() {
76 m_main_animation
->stop();
79 void PieceGroup::finalizeAnimation(AnimationGroup
* group
) {
83 void PieceGroup::adjustSprite(const Point
& p
, bool smooth
) {
84 shared_ptr
<Sprite
> sprite
= spriteAt(p
);
87 animatePiece(sprite
, p
, 1.0);
90 enqueue(shared_ptr
<Animation
>(new InstantAnimation(sprite
, converter()->toReal(p
))));
95 void PieceGroup::fadeIn(const Point
& p
) {
96 shared_ptr
<Sprite
> sprite
= spriteAt(p
);
99 enqueue(shared_ptr
<Animation
>(new FadeAnimation(sprite
, converter()->toReal(p
), 0, 255)));
101 enqueue(shared_ptr
<Animation
>(new DropAnimation(sprite
)));
105 SpritePtr
PieceGroup::createSprite(const QPixmap
& pix
, const Point
& pos
) {
106 return SpritePtr(new Sprite(pix
, piecesGroup(), converter()->toReal(pos
)));