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

#include "LayerMover.h"

using namespace gge::utils;

namespace gge { namespace effects {
	void LayerMover::Setup(Point From, Point To, int Time) {

		from=From;
		current=from;
		to=To;

		Target->BoundingBox.MoveTo(from);
		this->progressed=0;

		if(Time) {
			speed.x=(float)(to.x-from.x)/Time;
			speed.y=(float)(to.y-from.y)/Time;
			this->Play();
		} else {
			speed.x=0;
			speed.y=0;
			current=from=to;
			Target->BoundingBox.MoveTo(to);
		}
	}

	void LayerMover::Setup( utils::Point To, int Time ) {
		Setup(Point((int)current.x,(int)current.y), To, Time);
	}

	bool LayerMover::isFinished() {
		return current==to;
	}

	void LayerMover::Process(int Time) {
		if(from.x>to.x) {
			current.x=from.x+Time*speed.x;

			if(current.x<to.x)
				current.x=to.x;
		} else {
			current.x=from.x+Time*speed.x;
			if(current.x>to.x)
				current.x=to.x;
		}


		if(from.y>to.y) {
			current.y=from.y+Time*speed.y;

			if(current.y<to.y)
				current.y=to.y;
		} else {
			current.y=from.y+Time*speed.y;
			if(current.y>to.y)
				current.y=to.y;
		}
		Target->BoundingBox.MoveTo(current);

	}

	LayerMover::LayerMover( LayerBase *Target ) :
	speed(0,0),
		current(Target->BoundingBox.TopLeft()),
		Target(Target), FinishedEvent("Finished", this) {
		AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
	}

	LayerMover::LayerMover( LayerBase &Target ) :
	speed(0,0),
		current(Target.BoundingBox.TopLeft()),
		Target(&Target), FinishedEvent("Finished", this) {
		AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
	}

} }

mercurial