Effects/LayerMover.cpp

Sat, 08 Mar 2014 13:55:46 +0200

author
larukedi
date
Sat, 08 Mar 2014 13:55:46 +0200
changeset 401
85c7261e590a
parent 117
f1edaec047ec
permissions
-rw-r--r--

added LICENSE and README.md files

1
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
1 #include "LayerMover.h"
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
2
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
3 using namespace gge::utils;
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
4
20
cc549c0f8ebd * geffects >> gorgon::effects
cemkalyoncu
parents: 1
diff changeset
5 namespace gge { namespace effects {
1
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
6 void LayerMover::Setup(Point From, Point To, int Time) {
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
7
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
8 from=From;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
9 current=from;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
10 to=To;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
11
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
12 Target->BoundingBox.MoveTo(from);
34
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
13
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
14 if(Controller)
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
15 Controller->ResetProgress();
1
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
16
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
17 if(Time) {
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
18 speed.x=(float)(to.x-from.x)/Time;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
19 speed.y=(float)(to.y-from.y)/Time;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
20 } else {
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
21 speed.x=0;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
22 speed.y=0;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
23 current=from=to;
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
24 Target->BoundingBox.MoveTo(to);
1
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
25 }
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
26 }
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
27
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
28 void LayerMover::Setup( utils::Point To, int Time ) {
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
29 Setup(Point((int)current.x,(int)current.y), To, Time);
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
30 }
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
31
1
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
32 bool LayerMover::isFinished() {
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
33 return current==to;
1
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
34 }
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
35
34
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
36 animation::ProgressResult::Type LayerMover::Progress() {
117
f1edaec047ec * Effects are fixed (mostly event related)
cemkalyoncu
parents: 95
diff changeset
37 if(current==to)
34
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
38 return animation::ProgressResult::Finished;
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
39
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
40 if(!Controller)
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
41 return animation::ProgressResult::None;
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
42
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
43 if(Controller->GetProgress()<0) {
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
44 throw std::runtime_error("LayerMover cannot handle negative animation time.");
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
45 }
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
46
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
47 int Time=Controller->GetProgress();
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
48
1
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
49 if(from.x>to.x) {
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
50 current.x=from.x+Time*speed.x;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
51
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
52 if(current.x<to.x)
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
53 current.x=to.x;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
54 } else {
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
55 current.x=from.x+Time*speed.x;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
56 if(current.x>to.x)
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
57 current.x=to.x;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
58 }
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
59
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
60
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
61 if(from.y>to.y) {
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
62 current.y=from.y+Time*speed.y;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
63
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
64 if(current.y<to.y)
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
65 current.y=to.y;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
66 } else {
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
67 current.y=from.y+Time*speed.y;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
68 if(current.y>to.y)
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
69 current.y=to.y;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
70 }
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
71 Target->BoundingBox.MoveTo(current);
1
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
72
34
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
73
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
74 if(from==to)
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
75 return animation::ProgressResult::Finished;
117
f1edaec047ec * Effects are fixed (mostly event related)
cemkalyoncu
parents: 95
diff changeset
76
f1edaec047ec * Effects are fixed (mostly event related)
cemkalyoncu
parents: 95
diff changeset
77 return animation::ProgressResult::None;
1
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
78 }
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
79
95
706ebab3b092 * Massive refactoring
cemkalyoncu
parents: 34
diff changeset
80 LayerMover::LayerMover( LayerBase *Target, animation::Timer &controller, bool owner ) :
706ebab3b092 * Massive refactoring
cemkalyoncu
parents: 34
diff changeset
81 Base(controller, owner),
34
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
82 speed(0,0),
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
83 current(Target->BoundingBox.TopLeft()),
34
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
84 Target(Target)
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
85 {
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
86 }
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
87
95
706ebab3b092 * Massive refactoring
cemkalyoncu
parents: 34
diff changeset
88 LayerMover::LayerMover( LayerBase &Target, animation::Timer &controller, bool owner ) :
706ebab3b092 * Massive refactoring
cemkalyoncu
parents: 34
diff changeset
89 Base(controller, owner),
34
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
90 speed(0,0),
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
91 current(Target.BoundingBox.TopLeft()),
34
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
92 Target(&Target)
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
93 {
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
94 }
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
95
117
f1edaec047ec * Effects are fixed (mostly event related)
cemkalyoncu
parents: 95
diff changeset
96 LayerMover::LayerMover( LayerBase *Target, bool create/*=false*/ ) :
f1edaec047ec * Effects are fixed (mostly event related)
cemkalyoncu
parents: 95
diff changeset
97 Target(Target), Base(create)
f1edaec047ec * Effects are fixed (mostly event related)
cemkalyoncu
parents: 95
diff changeset
98 {
f1edaec047ec * Effects are fixed (mostly event related)
cemkalyoncu
parents: 95
diff changeset
99
f1edaec047ec * Effects are fixed (mostly event related)
cemkalyoncu
parents: 95
diff changeset
100 }
f1edaec047ec * Effects are fixed (mostly event related)
cemkalyoncu
parents: 95
diff changeset
101
f1edaec047ec * Effects are fixed (mostly event related)
cemkalyoncu
parents: 95
diff changeset
102 LayerMover::LayerMover( LayerBase &Target, bool create/*=false*/ ) :
f1edaec047ec * Effects are fixed (mostly event related)
cemkalyoncu
parents: 95
diff changeset
103 Target(&Target), Base(create)
34
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
104 {
e4ad59dfbcc4 * New graphics system
cemkalyoncu
parents: 30
diff changeset
105
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
106 }
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
107
20
cc549c0f8ebd * geffects >> gorgon::effects
cemkalyoncu
parents: 1
diff changeset
108 } }

mercurial