Effects/LayerMover.cpp

Mon, 18 Jul 2011 22:25:11 +0000

author
cemkalyoncu
date
Mon, 18 Jul 2011 22:25:11 +0000
changeset 30
5a1daa2eb409
parent 21
016809939f8a
child 34
e4ad59dfbcc4
permissions
-rw-r--r--

* Engine and Effects are adapted to new utils
* input::keyboard
- KeyCodes
- Key up event is only served to the handler which received key down
* Some new methods for Rectangle and Bounds
* ConsumableEvent
- Fire event returns the handler which received the event
- Can fire a specific handler via its token
- Additional unordered_map to store TokenList where keys are parameter object and tokens removed from it when they are destroyed
* Mouse system is completely coded anew
* CustomLayer now uses std::function instead of a simple call back, which allows using class member method via bind(fn, ref(x))
* TextAlignment fixed
* ScreenSize is now of type Size as it should be
* Current translation is renamed and it uses Point
* Current scissors is renamed and uses Rectangle
* Layers now cache their wrappers for fast access
* LayerBase provides many constructors and other layers follow
* OS to input transfer of mouse buttons are now made by Event::Type

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);
1
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
13 this->progressed=0;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
14
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
15 if(Time) {
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
16 speed.x=(float)(to.x-from.x)/Time;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
17 speed.y=(float)(to.y-from.y)/Time;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
18 this->Play();
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
19 } else {
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
20 speed.x=0;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
21 speed.y=0;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
22 current=from=to;
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
23 Target->BoundingBox.MoveTo(to);
1
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
24 }
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
25 }
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
26
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
27 void LayerMover::Setup( utils::Point To, int Time ) {
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
28 Setup(Point((int)current.x,(int)current.y), To, Time);
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
29 }
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
30
1
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
31 bool LayerMover::isFinished() {
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
32 return current==to;
1
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
33 }
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
34
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
35 void LayerMover::Process(int Time) {
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
36 if(from.x>to.x) {
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
37 current.x=from.x+Time*speed.x;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
38
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
39 if(current.x<to.x)
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
40 current.x=to.x;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
41 } else {
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
42 current.x=from.x+Time*speed.x;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
43 if(current.x>to.x)
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
44 current.x=to.x;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
45 }
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
46
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
47
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
48 if(from.y>to.y) {
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
49 current.y=from.y+Time*speed.y;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
50
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
51 if(current.y<to.y)
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
52 current.y=to.y;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
53 } else {
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
54 current.y=from.y+Time*speed.y;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
55 if(current.y>to.y)
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
56 current.y=to.y;
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
57 }
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
58 Target->BoundingBox.MoveTo(current);
1
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
59
1ef17765f966 * Moving to trunk step 2
cemkalyoncu
parents:
diff changeset
60 }
30
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
61
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
62 LayerMover::LayerMover( LayerBase *Target ) :
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
63 speed(0,0),
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
64 current(Target->BoundingBox.TopLeft()),
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
65 Target(Target), FinishedEvent("Finished", this) {
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
66 AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
67 }
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
68
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
69 LayerMover::LayerMover( LayerBase &Target ) :
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
70 speed(0,0),
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
71 current(Target.BoundingBox.TopLeft()),
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
72 Target(&Target), FinishedEvent("Finished", this) {
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
73 AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
74 }
5a1daa2eb409 * Engine and Effects are adapted to new utils
cemkalyoncu
parents: 21
diff changeset
75
20
cc549c0f8ebd * geffects >> gorgon::effects
cemkalyoncu
parents: 1
diff changeset
76 } }

mercurial