* New graphics system

Tue, 26 Jul 2011 09:55:07 +0000

author
cemkalyoncu
date
Tue, 26 Jul 2011 09:55:07 +0000
changeset 34
e4ad59dfbcc4
parent 33
ef28f560b1d0
child 35
d77959911b02

* New graphics system
- Supports 3 different drawables: basic, rectangular, sizeless
- Colorizable layer now supports color thru a state variable
* New animation system
- Simpler
- Allows single controller to control more than one animation
* Data resource now reads font, link and color correctly
* When no screen location is specified, windows are located at the center of the screen.
* Resizable object is simplified due to new graphics system
* Basic math got a new function: PositiveMod
* A bug in collection is fixed
* Castable managed buffer now actually works
* SoundResource is fixed
* Scroll bug is fixed

Effects/CountingText.cpp file | annotate | diff | comparison | revisions
Effects/CountingText.h file | annotate | diff | comparison | revisions
Effects/Flip.cpp file | annotate | diff | comparison | revisions
Effects/Flip.h file | annotate | diff | comparison | revisions
Effects/LayerMover.cpp file | annotate | diff | comparison | revisions
Effects/LayerMover.h file | annotate | diff | comparison | revisions
Effects/LayerResizer.cpp file | annotate | diff | comparison | revisions
Effects/LayerResizer.h file | annotate | diff | comparison | revisions
Effects/Tinting.cpp file | annotate | diff | comparison | revisions
Effects/Tinting.h file | annotate | diff | comparison | revisions
Engine/Animation.cpp file | annotate | diff | comparison | revisions
Engine/Animation.h file | annotate | diff | comparison | revisions
Engine/Animator.cpp file | annotate | diff | comparison | revisions
Engine/Animator.h file | annotate | diff | comparison | revisions
Engine/Font.cpp file | annotate | diff | comparison | revisions
Engine/Font.h file | annotate | diff | comparison | revisions
Engine/FontRenderer.h file | annotate | diff | comparison | revisions
Engine/GGEMain.cpp file | annotate | diff | comparison | revisions
Engine/GGEMain.h file | annotate | diff | comparison | revisions
Engine/Graphic2D.cpp file | annotate | diff | comparison | revisions
Engine/Graphic2D.h file | annotate | diff | comparison | revisions
Engine/GraphicLayers.cpp file | annotate | diff | comparison | revisions
Engine/GraphicLayers.h file | annotate | diff | comparison | revisions
Engine/GraphicTargets2D.h file | annotate | diff | comparison | revisions
Engine/Graphics.cpp file | annotate | diff | comparison | revisions
Engine/Graphics.h file | annotate | diff | comparison | revisions
Engine/Image.cpp file | annotate | diff | comparison | revisions
Engine/Image.h file | annotate | diff | comparison | revisions
Engine/OS.Win32.cpp file | annotate | diff | comparison | revisions
Engine/OS.h file | annotate | diff | comparison | revisions
Engine/Pointer.cpp file | annotate | diff | comparison | revisions
Engine/Pointer.h file | annotate | diff | comparison | revisions
Resource/AnimationResource.cpp file | annotate | diff | comparison | revisions
Resource/AnimationResource.h file | annotate | diff | comparison | revisions
Resource/BitmapFontResource.cpp file | annotate | diff | comparison | revisions
Resource/BitmapFontResource.h file | annotate | diff | comparison | revisions
Resource/DataResource.cpp file | annotate | diff | comparison | revisions
Resource/Definitions.h file | annotate | diff | comparison | revisions
Resource/ImageResource.cpp file | annotate | diff | comparison | revisions
Resource/ImageResource.h file | annotate | diff | comparison | revisions
Resource/ResizableObject.h file | annotate | diff | comparison | revisions
Resource/ResourceBase.h file | annotate | diff | comparison | revisions
Resource/ResourceFile.h file | annotate | diff | comparison | revisions
Resource/SoundResource.cpp file | annotate | diff | comparison | revisions
Resource/SoundResource.h file | annotate | diff | comparison | revisions
Utils/BasicMath.h file | annotate | diff | comparison | revisions
Utils/CastableManagedBuffer.h file | annotate | diff | comparison | revisions
Utils/Collection.h file | annotate | diff | comparison | revisions
Utils/Point2D.h file | annotate | diff | comparison | revisions
Utils/SortedCollection.h file | annotate | diff | comparison | revisions
--- a/Effects/CountingText.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Effects/CountingText.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -3,8 +3,37 @@
 using namespace gge;
 using namespace gge::graphics;
 using namespace gge::resource;
+using namespace gge::animation;
 
 namespace gge { namespace effects {
+
+	CountingText::CountingText( animation::AnimationTimer &controller, bool owner/*=false*/ ) : 
+		AnimationBase(controller, owner),
+		Color(0xff000000),
+		Font(NULL),
+		Shadow(),
+		Width(0),
+		Align(TextAlignment::Center),
+		Decimals(0),
+		from(0), to(0), speed(0), current(0)
+	{
+
+	}
+
+	CountingText::CountingText( bool create/*=false*/ ) : 
+		AnimationBase(create),
+		Color(0xff000000),
+		Font(NULL),
+		Shadow(),
+		Width(0),
+		Align(TextAlignment::Center),
+		Decimals(0),
+		from(0), to(0), speed(0), current(0)
+	{
+
+	}
+
+
 	void CountingText::Setup(float From, float To, int Time) {
 		if(Time)
 			speed=(To-From)/Time;
@@ -15,15 +44,10 @@
 		current=from;
 		to=To;
 
-		this->progressed=0;
-		this->Play();
+		if(Controller) Controller->ResetProgress();
 	}
 
-	bool CountingText::isFinished() {
-		return current==to;
-	}
-
-	void CountingText::Print(I2DColorizableGraphicsTarget *target, int X, int Y) {
+	void CountingText::Print(ColorizableImageTarget2D *target, int X, int Y) {
 		char text[50];
 
 		if(Format.length()) {
@@ -37,7 +61,19 @@
 		Font->Print(target, X, Y, Width, text, Color, Align, Shadow);
 	}
 
-	void CountingText::Process(int Time) {
+	animation::ProgressResult::Type CountingText::Progress() {
+		if(from==to)
+			return animation::ProgressResult::Finished;
+
+		if(!Controller)
+			return animation::ProgressResult::None;
+
+		if(Controller->GetProgress()<0) {
+			throw std::runtime_error("CountingText cannot handle negative animation time.");
+		}
+
+		int Time=Controller->GetProgress();
+
 		if(from>to) {
 			current=from+Time*speed;
 			if(current<to)
@@ -47,5 +83,11 @@
 			if(current>to)
 				current=to;
 		}
+
+		if(from==to)
+			return animation::ProgressResult::Finished;
+		else
+			return animation::ProgressResult::None;
 	}
+
 } }
--- a/Effects/CountingText.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Effects/CountingText.h	Tue Jul 26 09:55:07 2011 +0000
@@ -1,7 +1,7 @@
 #pragma once
 
 #include "../Resource/GRE.h"
-#include "../Engine/Animator.h"
+#include "../Engine/Animation.h"
 #include "../Engine/Graphics.h"
 #include "../Resource/BitmapFontResource.h"
 
@@ -9,12 +9,8 @@
 namespace gge { namespace effects {
 
 	////This effect displays a counting number going from a given value to another one.
-	class CountingText : public AnimatorBase {
+	class CountingText : public animation::AnimationBase {
 	public:
-		////This event is fired when the animation
-		/// completes
-		utils::EventChain<CountingText> FinishedEvent;
-
 		////Color of the text, default is black
 		graphics::RGBint Color;
 		////Text shadow, default is none
@@ -32,16 +28,16 @@
 
 
 		////Initializes the effect
-		CountingText(resource::BitmapFontResource *Font=NULL, graphics::RGBint color=graphics::RGBint(0xff000000), int Width=0, TextAlignment::Type Align=TextAlignment::Left, ShadowParams Shadow=ShadowParams(), int Decimals=0) : 
-			Color(color),
-			Font(Font),
-			Shadow(Shadow),
-			Width(Width),
-			Align(Align),
-			Decimals(Decimals),
-			from(0), to(0), speed(0), current(0), FinishedEvent("Finished", this)
-		{ 
-			AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
+		CountingText(animation::AnimationTimer &controller, bool owner=false);
+
+		////Initializes the effect
+		explicit CountingText(bool create=false);
+
+		void Adjust(resource::BitmapFontResource *Font=NULL, 
+			graphics::RGBint color=graphics::RGBint(0xff000000), 
+			int Width=0, TextAlignment::Type Align=TextAlignment::Left, 
+			ShadowParams Shadow=ShadowParams(), int Decimals=0) {
+
 		}
 
 		float Current() { return current; }
@@ -52,7 +48,7 @@
 		void Setup(float To, int Time) { Setup(current, To, Time); }
 		
 		////Prints the current text to a layer
-		void Print(graphics::I2DColorizableGraphicsTarget *target, int X, int Y);
+		void Print(graphics::ColorizableImageTarget2D *target, int X, int Y);
 
 	protected:
 		float from;
@@ -61,7 +57,6 @@
 		float speed;
 
 
-		virtual bool isFinished();
-		virtual void Process(int Time);
+		virtual animation::ProgressResult::Type Progress();
 	};
 } }
--- a/Effects/Flip.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Effects/Flip.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -7,22 +7,22 @@
 using namespace gge::utils;
 
 namespace gge { namespace effects {
-	void FlipEffect::Draw(I2DGraphicsTarget *Layer,int X,int Y) {
-		if(isFinished()) {
+	void FlipEffect::draw(ImageTarget2D &Layer,int X,int Y) {
+		if(!Flipping) {
 			if(Backside) {
 				Back->Draw(Layer, X, Y);
 			} else {
 				Front->Draw(Layer, X, Y);
 			}
 		} else {
-			float ang=((float)AnimatorBase::currentTime()/ETA)*PI;
+			float ang=((float)GetProgress()/ETA)*PI;
 			bool rev=false;
 			if(ang>PI/2) {
 				ang=PI-ang;
 				rev=true;
 			}
 
-			Buffered2DGraphic *img=NULL;
+			RectangularGraphic2D *img=NULL;
 			int cx,cy;
 			if(Backside ^ rev) {
 				img=Back;
@@ -32,8 +32,8 @@
 			if(img==NULL)
 				return;
 
-			cx=img->Texture.W;
-			cy=img->Texture.H;
+			cx=img->GetWidth();
+			cy=img->GetHeight();
 
 			FlipSide cside=Side;
 			if(Backside ^ rev) {
@@ -138,13 +138,14 @@
 	}
 
 	void FlipEffect::Flip(int ETA) {
+		Reset();
+
 		if(this->ETA!=0) {
 			Backside=!Backside;
-			progressed=this->ETA-progressed;
+			SetProgress(this->ETA-GetProgress());
 		}
 
 		this->ETA=ETA;
-		Play();
 		Flipping=true;
 	}
 
@@ -160,30 +161,32 @@
 		PivotFront.y=0;
 		PivotBack.x=0;
 		PivotBack.y=0;
-
-		Pause();
 	}
 
 	void FlipEffect::CenterPivot() {
 		if(Front) {
-			PivotFront.x=Front->Texture.W /2;
-			PivotFront.y=Front->Texture.H /2;
+			PivotFront.x=Front->GetWidth() /2;
+			PivotFront.y=Front->GetHeight() /2;
 		}
 		else if(Back) {
-			PivotFront.x=Back->Texture.W /2;
-			PivotFront.y=Back->Texture.H /2;
+			PivotFront.x=Back->GetWidth() /2;
+			PivotFront.y=Back->GetHeight() /2;
 		}
 
 		PivotBack=PivotFront;
 	}
 
-	void FlipEffect::Process(int Time) {
-		if(Time>=ETA) {
+	animation::ProgressResult::Type FlipEffect::Progress() {
+		if(GetProgress()>=ETA) {
 			ETA=0;
-			Pause();
-			progressed=0;
 			Flipping=false;
 			Backside=!Backside;
+
+			return animation::ProgressResult::Finished;
 		}
+
+		return animation::ProgressResult::None;
 	}
+
+
 } }
--- a/Effects/Flip.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Effects/Flip.h	Tue Jul 26 09:55:07 2011 +0000
@@ -1,13 +1,14 @@
 #pragma once
 
 #include "../Resource/GRE.h"
-#include "../Engine/Animator.h"
 #include "../Engine/Graphics.h"
 #include "../Engine/GraphicLayers.h"
+#include "../Engine/Graphic2D.h"
+#include "../Engine/Animation.h"
 
 namespace gge { namespace effects {
 
-	class FlipEffect : public AnimatorBase, public graphics::Buffered2DGraphic {
+	class FlipEffect : public animation::AnimationBase, public graphics::Graphic2D {
 	public:
 		enum FlipSide {
 			Top=1,
@@ -15,19 +16,19 @@
 			Bottom,
 			Right,
 		};
-		////This event is fired when the animation
-		/// completes
-		utils::EventChain<FlipEffect> FinishedEvent;
 
-		FlipEffect() : FinishedEvent("Finished", this) { 
-			AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
+		FlipEffect(animation::AnimationTimer &controller, bool owner=false) : AnimationBase(controller,owner) { 
+			Initialize(); 
+		}
+
+		explicit FlipEffect(bool create=false) : AnimationBase(create) { 
 			Initialize(); 
 		}
 
 		void Flip(int ETA);
 		void CenterPivot();
 
-		graphics::Buffered2DGraphic *Front,*Back;
+		graphics::RectangularGraphic2D *Front,*Back;
 		FlipSide Side;
 		bool Backside;
 		bool Flipping;
@@ -37,13 +38,28 @@
 		utils::Point PivotFront;
 		utils::Point PivotBack;
 
-		virtual void Draw(graphics::I2DGraphicsTarget *Layer, int X, int Y);
-		virtual void Draw(graphics::I2DGraphicsTarget &Layer, int X, int Y) { Draw(&Layer, X,Y); }
-
 	protected:
 		void Initialize();
 
-		virtual bool isFinished() { return AnimatorBase::currentTime()>=ETA; }
-		virtual void Process(int Time);
+		virtual animation::ProgressResult::Type Progress();
+
+		virtual void draw(graphics::ImageTarget2D& Target, int X, int Y);
+
+		void SetProgress(int progress) {
+			if(Controller)
+				Controller->SetProgress(progress);
+		}
+
+		int GetProgress() {
+			if(Controller)
+				return Controller->GetProgress();
+			else
+				return 0;
+		}
+
+		void Reset() {
+			if(Controller)
+				Controller->ResetProgress();
+		}
 	};
 } }
--- a/Effects/LayerMover.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Effects/LayerMover.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -10,12 +10,13 @@
 		to=To;
 
 		Target->BoundingBox.MoveTo(from);
-		this->progressed=0;
+		
+		if(Controller)
+			Controller->ResetProgress();
 
 		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;
@@ -32,7 +33,19 @@
 		return current==to;
 	}
 
-	void LayerMover::Process(int Time) {
+	animation::ProgressResult::Type LayerMover::Progress() {
+		if(from==to)
+			return animation::ProgressResult::Finished;
+
+		if(!Controller)
+			return animation::ProgressResult::None;
+
+		if(Controller->GetProgress()<0) {
+			throw std::runtime_error("LayerMover cannot handle negative animation time.");
+		}
+
+		int Time=Controller->GetProgress();
+
 		if(from.x>to.x) {
 			current.x=from.x+Time*speed.x;
 
@@ -57,20 +70,32 @@
 		}
 		Target->BoundingBox.MoveTo(current);
 
+
+		if(from==to)
+			return animation::ProgressResult::Finished;
+		else
+			return animation::ProgressResult::None;
 	}
 
-	LayerMover::LayerMover( LayerBase *Target ) :
-	speed(0,0),
+	LayerMover::LayerMover( LayerBase *Target, animation::AnimationTimer &controller, bool owner ) :
+		AnimationBase(controller, owner),
+		speed(0,0),
 		current(Target->BoundingBox.TopLeft()),
-		Target(Target), FinishedEvent("Finished", this) {
-		AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
+		Target(Target)
+	{
 	}
 
-	LayerMover::LayerMover( LayerBase &Target ) :
-	speed(0,0),
+	LayerMover::LayerMover( LayerBase &Target, animation::AnimationTimer &controller, bool owner ) :
+		AnimationBase(controller, owner),
+		speed(0,0),
 		current(Target.BoundingBox.TopLeft()),
-		Target(&Target), FinishedEvent("Finished", this) {
-		AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
+		Target(&Target) 
+	{
+	}
+
+	LayerMover::LayerMover( LayerBase *Target, bool create/*=false*/ )
+	{
+
 	}
 
 } }
--- a/Effects/LayerMover.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Effects/LayerMover.h	Tue Jul 26 09:55:07 2011 +0000
@@ -1,7 +1,7 @@
 #pragma once
 
 #include "../Resource/GRE.h"
-#include "../Engine/Animator.h"
+#include "../Engine/Animation.h"
 #include "../Engine/Graphics.h"
 #include "../Engine/Layer.h"
 
@@ -9,19 +9,22 @@
 
 	////This effect moves a given layer. Moving operation is animated from a given
 	/// value to another one
-	class LayerMover : public gge::AnimatorBase {
+	class LayerMover : public animation::AnimationBase {
 	public:
-		////This event is fired when the animation
-		/// completes
-		utils::EventChain<LayerMover> FinishedEvent;
 
 		////Target of this effect
 		LayerBase *Target;
 
 		////Initializes the effect
-		LayerMover(LayerBase *Target);
+		LayerMover(LayerBase *Target, animation::AnimationTimer &controller, bool owner=false);
+		////Initializes the effect
+		LayerMover(LayerBase &Target, animation::AnimationTimer &controller, bool owner=false);
+
 		////Initializes the effect
-		LayerMover(LayerBase &Target);
+		LayerMover(LayerBase *Target, bool create=false);
+		////Initializes the effect
+		LayerMover(LayerBase &Target, bool create=false);
+
 		////Sets source and destination to the given values and allows time duration to reach the
 		/// destination
 		void Setup(utils::Point From, utils::Point To, int Time);
@@ -35,6 +38,6 @@
 		utils::Point2D speed;
 
 		virtual bool isFinished();
-		virtual void Process(int Time);
+		virtual animation::ProgressResult::Type Progress();
 	};
 } }
--- a/Effects/LayerResizer.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Effects/LayerResizer.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -11,15 +11,15 @@
 		to=To;
 
 		Target->BoundingBox=from;
-		this->progressed=0;
+
+		if(Controller)
+			Controller->ResetProgress();
 
 		if(Time) {
 			speed.Left=(float)(to.Left-from.Left)/Time;
 			speed.Top=(float)(to.Top-from.Top)/Time;
 			speed.Width=(float)(to.Width-from.Width)/Time;
 			speed.Height=(float)(to.Height-from.Height)/Time;
-
-			this->Play();
 		} else {
 			speed.Left=0;
 			speed.Top=0;
@@ -31,14 +31,22 @@
 	}
 
 	void LayerResizer::Setup( utils::Rectangle To, int Time ) {
-		Setup(utils::Rectangle(Round(current.Left), Round(current.Top), Round(current.Width), Round(current.Height)), To, Time);
+		Setup(utils::Rectangle((int)Round(current.Left), (int)Round(current.Top), (int)Round(current.Width), (int)Round(current.Height)), To, Time);
 	}
 
-	bool LayerResizer::isFinished() {
-		return current==to;
-	}
+	animation::ProgressResult::Type LayerResizer::Progress() {
+		if(from==to)
+			return animation::ProgressResult::Finished;
+
+		if(!Controller)
+			return animation::ProgressResult::None;
 
-	void LayerResizer::Process(int Time) {
+		if(Controller->GetProgress()<0) {
+			throw std::runtime_error("LayerMover cannot handle negative animation time.");
+		}
+
+		int Time=Controller->GetProgress();
+
 		if(from.Left>to.Left) {
 			current.Left=from.Left+Time*speed.Left;
 
@@ -49,7 +57,7 @@
 			if(current.Left>to.Left)
 				current.Left=to.Left;
 		}
-		Target->BoundingBox.Left=Round(current.Left);
+		Target->BoundingBox.Left=(int)Round(current.Left);
 
 
 		if(from.Top>to.Top) {
@@ -62,7 +70,7 @@
 			if(current.Top>to.Top)
 				current.Top=to.Top;
 		}
-		Target->BoundingBox.Top=Round(current.Top);
+		Target->BoundingBox.Top=(int)Round(current.Top);
 
 
 		if(from.Width>to.Width) {
@@ -88,6 +96,12 @@
 				current.Height=to.Height;
 		}
 
-		Target->BoundingBox.SetSize(Round(current.Width), Round(current.Height));
+		Target->BoundingBox.SetSize((int)Round(current.Width), (int)Round(current.Height));
+
+
+		if(from==to)
+			return animation::ProgressResult::Finished;
+		else
+			return animation::ProgressResult::None;
 	}
 } }
--- a/Effects/LayerResizer.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Effects/LayerResizer.h	Tue Jul 26 09:55:07 2011 +0000
@@ -1,7 +1,7 @@
 #pragma once
 
 #include "../Resource/GRE.h"
-#include "../Engine/Animator.h"
+#include "../Engine/Animation.h"
 #include "../Engine/Graphics.h"
 #include "../Engine/Layer.h"
 #include "../Utils/Rectangle2D.h"
@@ -10,33 +10,46 @@
 
 	////This effect resizes a given layer. Resize operation is animated from a given
 	/// value to another one
-	class LayerResizer : public AnimatorBase {
+	class LayerResizer : public animation::AnimationBase {
 	public:
-		////This event is fired when the animation
-		/// completes
-		utils::EventChain<LayerResizer> FinishedEvent;
 
 		////Target of this effect
 		LayerBase *Target;
 
 		////Initializes the effect
-		LayerResizer(LayerBase *Target) :
+		LayerResizer(LayerBase *Target, animation::AnimationTimer &controller, bool owner=false) :
+			AnimationBase(controller,owner),
 			speed(0,0 , 0,0),
 			current((utils::Bounds2D)Target->BoundingBox),
-			Target(Target),
-			FinishedEvent("Finished", this)
+			Target(Target)
 		{
-			AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
 		}
 
 		////Initializes the effect
-		LayerResizer(LayerBase &Target) :
+		LayerResizer(LayerBase &Target, animation::AnimationTimer &controller, bool owner=false) :
+			AnimationBase(controller,owner),
 			speed(0,0 , 0,0),
 			current((utils::Bounds2D)Target.BoundingBox),
-			Target(&Target),
-			FinishedEvent("Finished", this)
+			Target(&Target)
 		{
-			AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
+		}
+
+			////Initializes the effect
+		LayerResizer(LayerBase *Target, bool create=false) :
+			AnimationBase(create),
+			speed(0,0 , 0,0),
+			current((utils::Bounds2D)Target->BoundingBox),
+			Target(Target)
+		{
+		}
+
+		////Initializes the effect
+		LayerResizer(LayerBase &Target, bool create=false) :
+			AnimationBase(create),
+			speed(0,0 , 0,0),
+			current((utils::Bounds2D)Target.BoundingBox),
+			Target(&Target)
+		{
 		}
 		////Sets source and destination to the given values and allows time duration to reach the
 		/// destination
@@ -50,7 +63,6 @@
 		utils::Rectangle2D current;
 		utils::Rectangle2D speed;
 
-		virtual bool isFinished();
-		virtual void Process(int Time);
+		virtual animation::ProgressResult::Type Progress();
 	};
 } }
--- a/Effects/Tinting.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Effects/Tinting.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -2,6 +2,7 @@
 #include "../Engine/GGEMain.h"
 
 using namespace gge::graphics;
+using namespace gge::animation;
 
 namespace gge { namespace effects {
 	void Tinting::Setup(RGBint From, RGBint To, int Time) {
@@ -24,16 +25,22 @@
 			speed.b=0;
 		}
 
-		this->progressed=0;
-		this->lasttick=Main.CurrentTime;
-		this->Play();
+		Controller->ResetProgress();
 	}
 
-	bool Tinting::isFinished() {
-		return current.a==to.a && current.r==to.r && current.g==to.g && current.b==to.b;
-	}
+	animation::ProgressResult::Type Tinting::Progress() {
+		if(from==to)
+			return animation::ProgressResult::Finished;
+
+		if(!Controller)
+			return animation::ProgressResult::None;
 
-	void Tinting::Process(int Time) {
+		if(Controller->GetProgress()<0) {
+			throw std::runtime_error("Tinting cannot handle negative animation time.");
+		}
+
+		int Time=Controller->GetProgress();
+
 		if(from.a>to.a) {
 			current.a=from.a+Time*speed.a;
 
@@ -81,5 +88,29 @@
 				current.b=to.b;
 		}
 		Target->Ambient.b=(Byte)current.b*255;
+
+		if(from==to)
+			return animation::ProgressResult::Finished;
+		else
+			return animation::ProgressResult::None;
+
 	}
+
+	Tinting::Tinting( graphics::Colorizable2DLayer &Target, bool create/*=false*/ ) : 
+		AnimationBase(create),
+		from(0), to(0), current(0), 
+		speed(0, 0,0,0),
+		Target(&Target)
+	{
+	}
+
+
+	Tinting::Tinting( graphics::Colorizable2DLayer *Target, bool create/*=false*/ ) : 
+		AnimationBase(create),
+		from(0), to(0), current(0), 
+		speed(0, 0,0,0),
+		Target(Target)
+	{
+	}
+
 } }
--- a/Effects/Tinting.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Effects/Tinting.h	Tue Jul 26 09:55:07 2011 +0000
@@ -1,41 +1,38 @@
 #pragma once
 
 #include "../Resource/GRE.h"
-#include "../Engine/Animator.h"
+#include "../Engine/Animation.h"
 #include "../Engine/Graphics.h"
+#include "../Engine/GraphicLayers.h"
 
 namespace gge { namespace effects {
 
 	////This effect tints a given colorizable target. Tinting is animated from a given
 	/// value to another one
-	class Tinting : public AnimatorBase {
+	class Tinting : public animation::AnimationBase {
 	public:
-		////This event is fired when the animation
-		/// completes
-		utils::EventChain<Tinting> FinishedEvent;
 
-		////Target of this effect
-		graphics::I2DColorizableGraphicsTarget *Target;
+		////Initializes the effect
+		Tinting(graphics::Colorizable2DLayer *Target, animation::AnimationTimer &Controller, bool owner=false) : 
+			AnimationBase(Controller, owner),
+			from(0), to(0), current(0), 
+			speed(0, 0,0,0),
+			Target(Target)
+		{ } 
 
 		////Initializes the effect
-		Tinting(graphics::I2DColorizableGraphicsTarget *Target) : 
-			from(), to(), current(), 
+		Tinting(graphics::Colorizable2DLayer &Target, animation::AnimationTimer &Controller, bool owner=false) : 
+			AnimationBase(Controller, owner),
+			from(0), to(0), current(0), 
 			speed(0, 0,0,0),
-			Target(Target),
-			FinishedEvent("Finished", this)
-		{
-			AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
-		}
+			Target(&Target)
+		{ }
 
 		////Initializes the effect
-		Tinting(graphics::I2DColorizableGraphicsTarget &Target) : 
-			from(), to(), current(), 
-			speed(0, 0,0,0),
-			Target(&Target),
-			FinishedEvent("Finished", this)
-		{
-			AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
-		}
+		Tinting(graphics::Colorizable2DLayer *Target, bool create=false); 
+
+		////Initializes the effect
+		Tinting(graphics::Colorizable2DLayer &Target, bool create=false);
 		
 		////Sets source and destination to the given values and allows time duration to reach the
 		/// destination
@@ -43,13 +40,20 @@
 		////Sets current destination to the given value and allows time duration to reach it
 		void Setup(graphics::RGBint To, int Time) { Setup(current, To, Time); }
 
+		bool IsFinished() { return from == to; }
+
+		void SetTarget(graphics::Colorizable2DLayer *target) { Target=target; Progress(); }
+		void SetTarget(graphics::Colorizable2DLayer &target) { Target=&target; Progress(); }
+		graphics::Colorizable2DLayer &GetTarget() { return *Target; }
 	protected:
+		////Target of this effect
+		graphics::Colorizable2DLayer *Target;
+
 		graphics::RGBfloat from;
 		graphics::RGBfloat to;
 		graphics::RGBfloat current;
 		graphics::RGBfloat speed;
 
-		virtual bool isFinished();
-		virtual void Process(int Time);
+		virtual animation::ProgressResult::Type Progress();
 	};
 } }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Animation.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -0,0 +1,222 @@
+
+#include "Animation.h"
+#include "..\Utils\Collection.h"
+#include "..\Utils\BasicMath.h"
+
+using namespace gge::utils;
+using namespace gge::graphics;
+
+namespace gge { namespace animation {
+
+	Collection<AnimationTimer> Timers;
+	Collection<AnimationBase> Animations;
+
+	unsigned LastTick;
+
+	void Animator_Signal(IntervalObject *interval, void *data) {
+		unsigned progressed=Main.CurrentTime-LastTick;
+		if(progressed==0) return;
+
+		for(Collection<AnimationTimer>::Iterator i=Timers.First();i.isValid();i.Next())
+			i->Progress(progressed);
+
+		for(Collection<AnimationBase>::Iterator i=Animations.First();i.isValid();i.Next()) {
+			if(i->HasController()) {
+				ProgressResult::Type r=i->Progress();
+
+				if(r!=ProgressResult::None)
+					i->GetController().Obtained(r, i);
+			}
+		}
+
+		LastTick=Main.CurrentTime;
+	}
+
+	void Initialize(GGEMain &main) {
+		main.RegisterInterval(0, NULL, Animator_Signal);
+		LastTick=main.CurrentTime;
+	}
+
+
+	AnimationTimer::AnimationTimer() : progress(0) {
+		Timers.Add(this);
+	}
+
+	AnimationTimer::~AnimationTimer() {
+		Timers.Remove(this);
+	}
+
+	void AnimationTimer::Progress( unsigned timepassed ) {
+		progress += timepassed;
+	}
+
+
+	AnimationController::AnimationController() : AnimationTimer(), 
+		ispaused(false), isfinished(false), speed(1.f),
+		Finished("Finished", this),
+		Paused("Paused", this)
+	{
+
+	}
+
+	void AnimationController::Progress( unsigned timepassed ) {
+		if(!ispaused && !isfinished) {
+			if(Round(mprogress)!=progress)
+				mprogress=progress;
+
+			mprogress+=(float)timepassed*speed;
+			progress=(int)Round<double>(mprogress);
+
+			if(pauseat>0 && speed>0 && pauseat<=progress) {
+				ispaused=true;
+				pauseat=-1;
+				Paused(source_param(NULL));
+			}
+			else if(pauseat>0 && speed<0 && pauseat>=progress) {
+				ispaused=true;
+				pauseat=-1;
+				Paused(source_param(NULL));
+			}
+		}
+	}
+
+	void AnimationController::Play() {
+		ispaused=false; 
+		isfinished=false;
+		mprogress=0;
+		progress=0;
+	}
+
+	void AnimationController::Obtained( ProgressResult::Type r, AnimationBase &source ) {
+		if(r==ProgressResult::Finished) {
+			isfinished=true;
+			ispaused=true;
+			Finished(source_param(&source));
+		}
+		if(r==ProgressResult::Pause) {
+			ispaused=true;
+			Paused(source_param(&source));
+		}
+
+		if(Round(mprogress)!=progress)
+			mprogress=progress;
+	}
+
+	void AnimationController::Pause() {
+		ispaused=true;
+	}
+
+	void AnimationController::ResetProgress() {
+		isfinished=false;
+		if(speed<0) {
+			mprogress=-1;
+			progress=-1;
+		}
+		else {
+			mprogress=0;
+			progress=0;
+		}
+	}
+
+
+	AnimationBase::AnimationBase(AnimationTimer &Controller, bool owner) : Controller(&Controller), owner(owner) {
+		Animations.Add(this);
+	}
+
+	AnimationBase::AnimationBase(bool create) : Controller(NULL) {
+		Animations.Add(this);
+
+		if(create) {
+			Controller=new AnimationTimer();
+			owner=true;
+		}
+	}
+
+	void AnimationBase::SetController( AnimationTimer &controller, bool owner ) {
+		if(this->owner && Controller)
+			delete Controller;
+
+		Controller=&controller; 
+		this->owner=owner;
+		
+		ProgressResult::Type r=Progress();
+
+		if(r!=ProgressResult::None)
+			controller.Obtained(r, *this);
+	}
+
+	AnimationBase::~AnimationBase() {
+		Animations.Remove(this);
+		if(owner && Controller)
+			delete Controller;
+	}
+
+
+
+	void DiscreteController::Progress(unsigned timepassed) {
+		AnimationController::Progress(timepassed);
+
+		int t=GetProgress();
+		int tl=info.GetDuration();
+
+		if(tl==0)
+			currentframe=-1;
+		else {
+			if(!islooping && ( (t>=tl && speed>=0) || (t<=0 && speed<0) )  ) {
+				isfinished=true;
+				Finished(source_param(NULL));
+
+				if(speed>0)
+					currentframe=info.GetNumberofFrames()-1;
+				else
+					currentframe=0;
+			}
+			else {
+				currentframe=FrameAt(PositiveMod(t,tl));
+			}
+		}
+
+		if(pauseatframe>0 && speed>0 && currentframe>=pauseatframe) {
+			ispaused=true;
+			pauseatframe=-1;
+			Paused(source_param(NULL));
+		}
+		else if(pauseatframe>0 && speed<0 && currentframe<=pauseatframe) {
+			ispaused=true;
+			pauseatframe=-1;
+			Paused(source_param(NULL));
+		}
+	}
+
+	void DiscreteController::Goto(int Frame) {
+		if( utils::InRange(Frame,0,GetNumberofFrames()-1) ) {
+			if(speed>0)
+				SetProgress(info.StartOf(Frame));
+			else
+				SetProgress(info.EndOf(Frame));
+
+			currentframe=Frame;
+		}
+		else {
+			SetProgress(0);
+			currentframe=-1;
+		}
+	}
+
+	void DiscreteController::Play() {
+		ispaused=false;
+		ResetProgress();
+	}
+
+	void DiscreteController::ResetProgress() {
+		isfinished=false;
+		if(speed>=0) {
+			SetProgress(0);
+		}
+		else {
+			SetProgress(info.GetDuration()-1);
+		}
+	}
+
+
+} }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Animation.h	Tue Jul 26 09:55:07 2011 +0000
@@ -0,0 +1,207 @@
+//This file contains core of animation system
+// all animations exposes interfaces defined here
+// and 
+
+#pragma once
+
+#include "Graphic2D.h"
+#include "GGEMain.h"
+#include <stdexcept>
+
+namespace gge { namespace animation {
+
+	void Initialize(GGEMain &main);
+
+	class ProgressResult {
+	public:
+		enum Type {
+			None,
+			Pause,
+			Finished,
+		};
+	};
+
+	class AnimationBase;
+
+	class AnimationTimer {
+	public:
+		enum Type {
+			Continous,
+			Discrete
+		};
+
+		AnimationTimer();
+
+		virtual ~AnimationTimer();
+
+		virtual void Progress(unsigned timepassed);
+		virtual void Obtained(ProgressResult::Type r, AnimationBase &source) 
+		{}
+
+		virtual void ResetProgress() { progress=0; }
+		virtual void SetProgress(int progress) { this->progress=progress; }
+		virtual int GetProgress() const { return progress; }
+
+		virtual Type GetType() const { return Continous; }
+
+	protected:
+		int progress;
+	};
+
+	class source_param {
+	public:
+
+		source_param(AnimationBase *source) : source(source)
+		{ }
+
+		AnimationBase *source;
+	};
+
+	class AnimationController : public AnimationTimer {
+	public:
+
+		AnimationController();
+
+		virtual void Progress(unsigned timepassed);
+		virtual void Obtained(ProgressResult::Type r, AnimationBase &source);
+
+		virtual void Pause();
+		virtual void Resume() { ispaused=false; }
+
+		virtual void Play();
+
+		virtual void SetSpeed(float speed) { this->speed=speed; }
+		virtual float GetSpeed() { return speed; }
+
+		virtual void Reverse() { speed=-speed; }
+
+		bool IsPaused() { return ispaused; }
+		bool IsFinished() { return isfinished; }
+
+		virtual void ResetProgress();
+
+		void SetPauseAt(int t) {
+			pauseat=t;
+		}
+		void RemovePauseAt() {
+			pauseat=-1;
+		}
+		virtual void SetProgress(int progress) { mprogress=this->progress=progress; }
+
+		utils::EventChain<AnimationController, source_param> Finished;
+		utils::EventChain<AnimationController, source_param> Paused;
+
+	protected:
+		bool ispaused;
+		float speed;
+		int pauseat;
+		bool isfinished;
+		double mprogress;
+	};
+
+	class DiscreteInfoProvider {
+	public:
+		//if there is a single frame, duration should be 0
+		virtual int GetDuration() const					= 0;
+		virtual int GetDuration(unsigned Frame) const	= 0;
+		virtual int GetNumberofFrames() const			= 0;
+
+		//Caller is responsible to supply a time between 0 and GetDuration()-1, if no frame exists it should return -1
+		virtual int		 FrameAt(unsigned Time) const	= 0; 
+		//Should always return a time between 0 and GetDuration unless Frame does not exists it should return -1
+		virtual int		 StartOf(unsigned Frame) const	= 0; 
+		virtual	int		 EndOf(unsigned Frame) const { return StartOf(Frame)+GetDuration(Frame); }
+	};
+
+	class DiscreteController : public AnimationController {
+	public:
+		DiscreteController(DiscreteInfoProvider &info) : AnimationController(), 
+			islooping(true), info(info), pauseatframe(-1), currentframe(-1)
+		{ }
+
+
+		bool IsLooping() const { return islooping; }
+		void SetLoop(bool loop) { islooping=loop; }
+
+		void Goto(int Frame);
+		//-1 is invalid frame
+		int CurrentFrame() const { return currentframe; }
+
+		void SetPauseAtFrame(int Frame) { pauseatframe=Frame; }
+		int  GetPauseAtFrame() const { return pauseatframe; }
+		void CancelPauseAtFrame() { pauseatframe=-1; }
+
+		virtual int FrameAt(unsigned Time) const { 
+			return info.FrameAt(Time); 
+		}
+
+		virtual int StartOf(int Frame) const { 
+			if(!utils::InRange(Frame, 0, GetDuration())) 
+				return 0; 
+
+			return info.StartOf(Frame); 
+		}
+
+		virtual int EndOf(int Frame) const { 
+			if(!utils::InRange(Frame, 0, GetDuration())) 
+				return GetNumberofFrames(); 
+
+			return info.EndOf(Frame); 
+		}
+
+		virtual int GetDuration() const { return info.GetDuration(); }
+		virtual int GetNumberofFrames() const { return info.GetNumberofFrames(); }
+
+		virtual Type GetType() const { return AnimationTimer::Discrete; }
+		virtual void Progress(unsigned timepassed);
+
+		virtual void Play();
+		virtual void ResetProgress();
+
+	protected:
+		bool islooping;
+		int pauseatframe;
+		int currentframe;
+		DiscreteInfoProvider &info;
+	};
+
+	class AnimationBase {
+	public:
+		AnimationBase(AnimationTimer &Controller, bool owner=false);
+		explicit AnimationBase(bool create=false);
+		
+		virtual ~AnimationBase();
+
+		virtual void SetController(AnimationTimer &controller, bool owner=false);
+		bool HasController() { return Controller!=NULL; }
+		AnimationTimer &GetController() { return *Controller; }
+		void RemoveController() { Controller=NULL; }
+
+
+		virtual ProgressResult::Type Progress() = 0;
+		virtual void DeleteAnimation() { delete this; }
+
+
+	protected:
+		AnimationTimer *Controller;
+		bool owner;
+	};
+
+	class Graphic2DAnimation : public virtual AnimationBase, public graphics::RectangularGraphic2D {
+	protected:
+
+		Graphic2DAnimation() : AnimationBase() { }
+		Graphic2DAnimation(AnimationTimer &Controller) : AnimationBase(Controller) { }
+	};
+
+	class AnimationProvider {
+	public:
+		virtual AnimationBase &CreateAnimation(AnimationTimer &controller, bool owner=false) = 0;
+		virtual AnimationBase &CreateAnimation(bool create=false) = 0;
+	};
+
+	class Graphic2DAnimationProvider : public AnimationProvider {
+		virtual Graphic2DAnimation &CreateAnimation(AnimationTimer &controller, bool owner=false) = 0;
+		virtual Graphic2DAnimation &CreateAnimation(bool create=false) = 0;
+	};
+} }
--- a/Engine/Animator.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,322 +0,0 @@
-#include "Animator.h"
-#include "GGEMain.h"
-
-using namespace gge::utils;
-
-namespace gge {
-	Collection<AnimatorBase> Animators;
-
-	void Animator_Signal(IntervalObject *interval, void *data) {
-		for(Collection<AnimatorBase>::Iterator i=Animators.First();i.isValid();i.Next())
-			i->Progress();
-	}
-
-	void InitializeAnimation(GGEMain *main) {
-		Main.RegisterInterval(0, NULL, Animator_Signal);
-	}
-
-	AnimatorBase::AnimatorBase() : 
-		FinishedEvent("Finished", this),
-		InterruptedEvent("Interrupted", this)
-	{
-		Animators.Add(this);
-
-		///*Assigning default values
-		pauseat=-1;
-		pausedat=Main.CurrentTime;
-		speed=1;
-		lasttick=Main.CurrentTime;
-		ispaused=false;
-		progressed=0;
-	}
-
-	AnimatorBase::~AnimatorBase() {
-		Animators.Remove(this);
-	}
-
-	int AnimatorBase::currentTime() {
-		return (int)progressed;
-	}
-
-	bool AnimatorBase::isPlaying() {
-		return !ispaused && !isFinished();
-	}
-
-	void AnimatorBase::Pause() {
-		ispaused=true;
-		pausedat=Main.CurrentTime;
-	}
-
-	void AnimatorBase::PauseAt(int ms) {
-		pauseat=ms;
-	}
-
-	void AnimatorBase::setSpeed(float Speed) {
-		speed=Speed;
-	}
-
-	void AnimatorBase::Progress() {
-		if(isFinished()) return;
-
-		if(!ispaused) {
-			ProgressBy(Main.CurrentTime-lasttick);
-			lasttick=Main.CurrentTime;
-		}
-	}
-
-	void AnimatorBase::ProgressBy(int ms) {
-		progressed+=(float)ms*speed;
-		Process((int)progressed);
-
-		if(!ispaused) {
-			if(progressed>pauseat && pauseat>0) {
-				pauseat=-1;
-				Pause();
-				InterruptedEvent();
-			}
-		}
-
-		if(isFinished()) {
-			FinishedEvent();
-		}
-	}
-
-	void AnimatorBase::ProgressTo(float ms) {
-		progressed=ms;
-		Process((int)progressed);
-
-		if(!ispaused) {
-			if(progressed>pauseat && pauseat>0) {
-				pauseat=-1;
-				Pause();
-				InterruptedEvent();
-			}
-		}
-
-		if(isFinished()) {
-			FinishedEvent();
-		}
-	}
-
-	void AnimatorBase::Play() {
-		lasttick=Main.CurrentTime;
-		ispaused=false;
-	}
-
-	DiscreteAnimatorBase::DiscreteAnimatorBase() : 
-		AnimatorBase(),
-		FrameChangedEvent("framechanged",this),
-		FrameInterruptedEvent("frameinterrupted",this)
-	{
-		totalframes=0;
-		frametimings=NULL;
-		framedurations=NULL;
-		currentframe=0;
-		averagedurations=0;
-		duration=0;
-		frametimings=NULL;
-		EventOnFrameChange=false;
-		progressed=0;
-		gobackwards=false;
-		islooping=true;
-	}
-
-	void DiscreteAnimatorBase::GotoFrame(int Frame) {
-#ifdef _DEBUG
-		if(Frame<0) {
-			os::DisplayMessage("Discreate animation","Negative frame requested!");
-			assert(0);
-			return;
-		}
-		if(Frame>totalframes) {
-			os::DisplayMessage("Discreate animation","Specified frame does not exists!");
-			assert(0);
-			return;
-		}
-#endif
-
-		AnimatorBase::ProgressTo((float)frametimings[Frame]);
-	}
-
-	void DiscreteAnimatorBase::setLoop(bool loop) {
-		islooping=loop;
-	}
-
-	void DiscreteAnimatorBase::Reverse() {
-		gobackwards=!gobackwards;
-		speed=-speed;
-
-		//reverses the duration passed in this frame
-		ProgressTo(frametimings[currentframe]+framedurations[currentframe]-(progressed-frametimings[currentframe]));
-	}
-	void DiscreteAnimatorBase::GoForwards() {
-		if(gobackwards && progressed==duration-1) {
-			progressed=0;
-			currentframe=0;
-		}
-
-		if(speed<0)
-			speed=-speed;
-		gobackwards=false;
-	}
-	void DiscreteAnimatorBase::GoBackwards() {
-		if(!gobackwards && progressed==0) {
-			progressed=(float)(duration-1);
-			currentframe=totalframes-1;
-		}
-
-		if(speed>0)
-			speed=-speed;
-		gobackwards=true;
-	}
-
-	bool DiscreteAnimatorBase::isLooping() {
-		return islooping;
-	}
-	bool DiscreteAnimatorBase::isBackwards() {
-		return gobackwards;
-	}
-	int  DiscreteAnimatorBase::currentFrame() {
-		return currentframe;
-	}
-	void DiscreteAnimatorBase::setTotalFrames(int total) {
-#ifdef _DEBUG
-		if(total==0) {
-			os::DisplayMessage("Discrete animation","Empty total frames requested!");
-			assert(0);
-		}
-#endif
-
-		///*Startup
-		totalframes=total;
-		framedurations=FrameDurations();
-
-		if(frametimings)
-			delete[] frametimings;
-		frametimings=new int[total+1];
-
-		///*Calculate frame timings
-		int i;
-		duration=0;
-		for(i=0;i<total;i++) {
-			frametimings[i]=duration;
-			duration+=framedurations[i];
-		}
-		frametimings[i]=duration;
-
-#ifdef _DEBUG
-		if(duration==0) {
-			os::DisplayMessage("Discrete animation","Empty duration animation!");
-			assert(0);
-		}
-#endif
-
-
-		///*Calculate statistics
-		averagedurations=duration/total;
-
-		Progress();
-	}
-	void DiscreteAnimatorBase::Process(int time) {
-		int i;
-		if(duration==0)
-			return;
-
-#ifdef _DEBUG
-		if(averagedurations==0) {
-			os::DisplayMessage("Discrete animation","Trying to process an empty animation!");
-			assert(0);
-		}
-#endif
-		///*Checking time boundaries
-		//when going back
-		if(time<0 && gobackwards) {
-			if(islooping) {
-				if(time<-duration)
-					time=time % duration;
-
-				progressed=(float)((duration-1)+time);
-			} else {
-				progressed=0;
-				Pause();
-			}
-		}//when going forward
-		else if(time>=duration && !gobackwards) {
-			if(islooping) {
-				time=time % duration;
-				progressed=(float)time;
-			} else {
-				progressed=(float)(duration-1);
-				Pause();
-			}
-		}
-		time=(int)progressed;
-
-		///*finding current frame
-		//statistics is used to speedup search
-		int guessedframe=time/averagedurations;
-		int targetframe;
-#ifdef _DEBUG
-		if(guessedframe<0) {
-			os::DisplayMessage("Discrete animation","Guessed frame is lower than 0??");
-			guessedframe=0;
-		} else if(guessedframe>=totalframes) {
-			guessedframe=totalframes-1;
-		}
-#endif
-
-		targetframe=0;
-		//guessedframe=0;
-		//if guess is higher
-		if(frametimings[guessedframe]>time) {
-			for(i=guessedframe-1;i>=0;i--)
-				if(frametimings[i]<time) {
-					targetframe=i;
-					break;
-				}
-		}//if guess is lower
-		else if(frametimings[guessedframe+1]<time) {
-			for(i=guessedframe+1;i<totalframes;i++)
-				if(frametimings[i+1]>time) {
-					targetframe=i;
-					break;
-				}
-		}//if exact find
-		else {
-			targetframe=guessedframe;
-		}
-
-		//frame is changed
-		if(targetframe!=currentframe) {
-			frame_changed_event_params p(currentframe,targetframe);
-			FrameChangedEvent(p);
-		}
-#ifdef _DEBUG
-		if(targetframe<0) {
-			os::DisplayMessage("Discrete animation","Target frame is lower than 0!");
-			guessedframe=0;
-		} else if(targetframe>=totalframes) {
-			os::DisplayMessage("Discrete animation","Target frame is higher than totalframes!");
-			assert(0);
-		}
-#endif
-
-		currentframe=targetframe;
-
-		//checking for pause at frame
-		if(gobackwards && pauseatframe>targetframe) {
-			FrameInterruptedEvent();
-			pauseatframe=-1;
-		}
-		if(!gobackwards && pauseatframe<targetframe && pauseatframe>-1) {
-			FrameInterruptedEvent();
-			pauseatframe=-1;
-		}
-
-		ProcessFrame(currentframe);
-	}
-	void DiscreteAnimatorBase::PauseAtFrame(int frame) {
-		pauseatframe=frame;
-	}
-	void DiscreteAnimatorBase::ProcessFrame(int frame) { }
-}
\ No newline at end of file
--- a/Engine/Animator.h	Thu Jul 21 11:46:42 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,217 +0,0 @@
-#pragma once
-
-#include "../Utils/Any.h"
-#include "../Utils/EventChain.h"
-#ifdef _DEBUG
-#include <assert.h>
-#endif
-
-///-This file contains animation support classes and
-/// functions
-
-namespace gge {
-	class GGEMain;
-
-	////This function should be called before any animation related
-	/// function is called.
-	void InitializeAnimation(GGEMain *main);
-
-	////This is the base class for all animations.
-	/// Provides several ready functions.
-	class AnimatorBase {
-	public:
-		AnimatorBase();
-		~AnimatorBase();
-		////This event is fired when the animation
-		/// completes
-		utils::EventChain<AnimatorBase, utils::empty_event_params> FinishedEvent;
-		////This event is fired whenever the animation
-		/// is interrupted when it reaches the time
-		/// specified by PauseAt function
-		utils::EventChain<AnimatorBase, utils::empty_event_params> InterruptedEvent;
-
-		////Starts or continues animation
-		virtual void Play();
-		////Pauses the animation
-		virtual void Pause();
-		////Progresses animation
-		virtual void Progress();
-		////Progresses the animation by the given time,
-		/// this function is also effected by speed
-		virtual void ProgressBy(int ms);
-		////Sets a pause position at the given time.
-		/// When animation reaches or passes that time
-		/// animation is paused and interrupt event
-		/// is fired. Negative values cancel this function.
-		void PauseAt(int ms);
-		////Cancels the set pause position
-		void CancelPauseAt() { PauseAt(-1); }
-		////Instantly progresses to the given time. Notice that
-		/// some animations cannot handle going back in time.
-		/// This function is not affected by speed
-		virtual void ProgressTo(float ms);
-		////Changes the speed of the animation, some animation may
-		/// dislike changing this value
-		///@Speed		: speed of the animation, default is 1 while
-		/// 0 effectively stops the animation
-		virtual void setSpeed(float Speed);
-		virtual float getSpeed() { return speed; }
-		////Returns the current time of the animation
-		int currentTime();
-		////Returns whether the animation is playing
-		bool isPlaying();
-
-	protected:
-		////This function is called whenever processing
-		/// is required. Animator object can use
-		/// progressed variable to determine the current
-		/// relative time.
-		virtual void Process(int time)=0;
-
-		////Returns true when animation completes.
-		/// This function should be implemented by
-		/// animator class.
-		virtual bool isFinished()=0;
-
-		////The time of the last tick, used to determine
-		/// process time
-		unsigned int lasttick;
-		////Used for pause support
-		unsigned int pausedat;
-		////Time progressed since the beginning of the
-		/// animation, double is used to handle slower
-		/// speeds
-		float progressed;
-		////Whether the animation is paused
-		bool ispaused;
-		float speed;
-		////Used for PauseAt support
-		int pauseat;
-	};
-
-	////Used pass current and previous frame numbers when a frame change
-	/// event occurs
-	struct frame_changed_event_params {
-		frame_changed_event_params() { }
-		frame_changed_event_params(int prev,int cur) {
-			previous=prev;
-			current=cur;
-		}
-		////Previous frame
-		int previous;
-		////Current frame
-		int current;
-	};
-
-	////This base class defines a discreate animator,
-	/// it includes few common variables and functions
-	class DiscreteAnimatorBase : public AnimatorBase {
-	public:
-		////Constructor to setup the system
-		DiscreteAnimatorBase();
-		////Fired whenever a frame change occurs when EventOnFrameChange
-		/// flag is set
-		utils::EventChain<DiscreteAnimatorBase, frame_changed_event_params> FrameChangedEvent;
-		////This event is fired whenever the animation
-		/// is interrupted when it reaches the frame
-		/// specified by PauseAtFrame function
-		utils::EventChain<DiscreteAnimatorBase, utils::empty_event_params> FrameInterruptedEvent;
-		////This function sets the current frame to the given value.
-		/// Animation time is moved to the beginning of the given frame
-		///@Frame		: the frame to go
-		virtual void GotoFrame(int Frame);
-		////Sets the whether to loop or not.
-		virtual void setLoop(bool loop);
-		////Sets a pause position at the given frame.
-		/// When animation reaches or passes that frame
-		/// animation is paused and frameinterrupt event
-		/// is fired. Negative values cancel this function.
-		virtual void PauseAtFrame(int Frame);
-		////Cancels the set pause position
-		void CancelPauseAtFrame() { PauseAtFrame(-1); }
-		////Reverses the direction of the animation
-		virtual void Reverse();
-		////Sets animation direction to forwards
-		virtual void GoForwards();
-		////Sets animation direction to backwards
-		virtual void GoBackwards();
-		////Returns whether the animation is looping
-		virtual bool isLooping();
-		////Changes the speed of the animation, some animation may
-		/// dislike changing this value
-		///@Speed		: speed of the animation, default is 1 while
-		/// 0 effectively stops the animation
-		virtual void setSpeed(float Speed) {
-			if(gobackwards)
-				AnimatorBase::setSpeed(-Speed);
-			else
-				AnimatorBase::setSpeed( Speed);
-		}
-		virtual float getSpeed() { 
-			if(gobackwards)
-				return -speed; 
-			else
-				return speed; 
-		}
-		////Returns whether the animation is playing
-		/// backwards
-		virtual bool isBackwards();
-		////Returns the current frame
-		virtual int currentFrame();
-		////Returns total frames in this animation
-		int totalFrames();
-		////Overrides play to roll animation to beginning
-		virtual void Play() { 
-			if(gobackwards && progressed==0) progressed=(float)duration-1; 
-			else if(!gobackwards && progressed==duration-1) duration=0;
-			AnimatorBase::Play();
-		}
-
-		////If this flag is set, an event is fired when a frame
-		/// transition occurs
-		bool EventOnFrameChange;
-	protected:
-		////This value should not be modified by animator,
-		/// instead setTotalFrames function should be used
-		int totalframes;
-		////This value is used to internally and automatically
-		/// calculated and should not be changed. The value
-		/// is probed when setTotalFrames is called
-		int duration;
-		////Whether the animation is looping state
-		bool islooping;
-		////Whether the animation is running backwards
-		bool gobackwards;
-		////This value should not be modified by animator,
-		/// instead setTotalFrames function should be used
-		int *frametimings;
-		////This value should not be modified by animator,
-		/// instead setTotalFrames function should be used
-		int *framedurations;
-		////The current frame, should not be changed by animator,
-		/// GotoFrame function should be used in place
-		int currentframe;
-		////This value is used to speed up searches,
-		/// should only be changed when necessary. The value
-		/// is probed when setTotalFrames is called
-		int averagedurations;
-		////Used for pause@frame support
-		int pauseatframe;
-
-
-		////Used to change the total number of frames
-		/// by the animator, invokes probing of frame timings
-		/// and durations
-		void setTotalFrames(int total);
-		////This function should return the duration
-		/// time of frames
-		virtual int* FrameDurations()=0;
-		////Processes the current time to determine current frame
-		virtual void Process(int time);
-		////Can be overridden to process a frame,
-		/// a default method doing nothing is provided
-		virtual void ProcessFrame(int frame);
-		////This function returns whether this animation is finished
-		virtual bool isFinished() { return !islooping && ( (currentframe==totalframes-1 && !gobackwards) || (currentframe==0 && gobackwards) ); }
-	};
-}
--- a/Engine/Font.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Engine/Font.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -54,17 +54,17 @@
 
 
 	//Print Functions
-	void Font::Print(I2DColorizableGraphicsTarget *target, int X, int Y, string Text) {
+	void Font::Print(ColorizableImageTarget2D *target, int X, int Y, string Text) {
 		FontRenderer *r;
 		if(r=getRenderer())
 			r->Print(target, X, Y, Text, Color, Shadow);
 	}
-	void Font::Print(I2DColorizableGraphicsTarget *target, int X, int Y, int W, string Text, TextAlignment::Type Align) {
+	void Font::Print(ColorizableImageTarget2D *target, int X, int Y, int W, string Text, TextAlignment::Type Align) {
 		FontRenderer *r;
 		if(r=getRenderer())
 			r->Print(target, X, Y, W, Text, Color, Align, Shadow);
 	}
-	void Font::Print(I2DColorizableGraphicsTarget *target, int X, int Y, int W, string Text, EPrintData *Data, int DataLen, TextAlignment::Type Align) {
+	void Font::Print(ColorizableImageTarget2D *target, int X, int Y, int W, string Text, EPrintData *Data, int DataLen, TextAlignment::Type Align) {
 		FontRenderer *r;
 		if(r=getRenderer())
 			r->Print(target, X, Y, W, Text, Color, Data, DataLen, Align, Shadow);
--- a/Engine/Font.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Engine/Font.h	Tue Jul 26 09:55:07 2011 +0000
@@ -49,36 +49,36 @@
 
 		//Print Functions
 		////Prints the given text to the target using given color.
-		void Print(graphics::I2DColorizableGraphicsTarget *target, int X, int Y, string Text);
+		void Print(graphics::ColorizableImageTarget2D *target, int X, int Y, string Text);
 		////Prints the given text to the target using given color. Text is wrapped and aligned as necessary
-		void Print(graphics::I2DColorizableGraphicsTarget *target, int X, int Y, int W, string Text, TextAlignment::Type Align=TextAlignment::Left);
+		void Print(graphics::ColorizableImageTarget2D *target, int X, int Y, int W, string Text, TextAlignment::Type Align=TextAlignment::Left);
 		////This method is extended to cover meta functionality for advanced text rendering
-		void Print(graphics::I2DColorizableGraphicsTarget *target, int X, int Y, int W, string Text, EPrintData *Data, int DataLen, TextAlignment::Type Align=TextAlignment::Left);
+		void Print(graphics::ColorizableImageTarget2D *target, int X, int Y, int W, string Text, EPrintData *Data, int DataLen, TextAlignment::Type Align=TextAlignment::Left);
 		////This method is extended to cover meta functionality for advanced text rendering. This function does not render the given text
 		/// it only processes meta data
 		void Print_Test(int X, int Y, int W, string Text, EPrintData *Data, int DataLen, TextAlignment::Type Align);
 
 
 		//Target references
-		void Print(graphics::I2DColorizableGraphicsTarget &target, int X, int Y, string Text) 
+		void Print(graphics::ColorizableImageTarget2D &target, int X, int Y, string Text) 
 		{ Print(&target, X, Y, Text); }
-		void Print(graphics::I2DColorizableGraphicsTarget &target, int X, int Y, int W, string Text, TextAlignment::Type Align=TextAlignment::Left) 
+		void Print(graphics::ColorizableImageTarget2D &target, int X, int Y, int W, string Text, TextAlignment::Type Align=TextAlignment::Left) 
 		{ Print(&target, X, Y, W, Text, Align); }
-		void Print(graphics::I2DColorizableGraphicsTarget &target, int X, int Y, int W, string Text, EPrintData *Data, int DataLen, TextAlignment::Type Align=TextAlignment::Left)
+		void Print(graphics::ColorizableImageTarget2D &target, int X, int Y, int W, string Text, EPrintData *Data, int DataLen, TextAlignment::Type Align=TextAlignment::Left)
 		{ Print(&target, X, Y, W, Text, Data, DataLen, Align); }
 
-		void Print(graphics::I2DColorizableGraphicsTarget &target, utils::Point p, string Text) 
+		void Print(graphics::ColorizableImageTarget2D &target, utils::Point p, string Text) 
 		{ Print(&target, p.x, p.y, Text); }
-		void Print(graphics::I2DColorizableGraphicsTarget &target, utils::Point p, int W, string Text, TextAlignment::Type Align=TextAlignment::Left) 
+		void Print(graphics::ColorizableImageTarget2D &target, utils::Point p, int W, string Text, TextAlignment::Type Align=TextAlignment::Left) 
 		{ Print(&target, p.x, p.y, W, Text, Align); }
-		void Print(graphics::I2DColorizableGraphicsTarget &target, utils::Point p, int W, string Text, EPrintData *Data, int DataLen, TextAlignment::Type Align=TextAlignment::Left)
+		void Print(graphics::ColorizableImageTarget2D &target, utils::Point p, int W, string Text, EPrintData *Data, int DataLen, TextAlignment::Type Align=TextAlignment::Left)
 		{ Print(&target, p.x, p.y, W, Text, Data, DataLen, Align); }
 
-		void Print(graphics::I2DColorizableGraphicsTarget *target, utils::Point p, string Text) 
+		void Print(graphics::ColorizableImageTarget2D *target, utils::Point p, string Text) 
 		{ Print(target, p.x, p.y, Text); }
-		void Print(graphics::I2DColorizableGraphicsTarget *target, utils::Point p, int W, string Text, TextAlignment::Type Align=TextAlignment::Left) 
+		void Print(graphics::ColorizableImageTarget2D *target, utils::Point p, int W, string Text, TextAlignment::Type Align=TextAlignment::Left) 
 		{ Print(target, p.x, p.y, W, Text, Align); }
-		void Print(graphics::I2DColorizableGraphicsTarget *target, utils::Point p, int W, string Text, EPrintData *Data, int DataLen, TextAlignment::Type Align=TextAlignment::Left)
+		void Print(graphics::ColorizableImageTarget2D *target, utils::Point p, int W, string Text, EPrintData *Data, int DataLen, TextAlignment::Type Align=TextAlignment::Left)
 		{ Print(target, p.x, p.y, W, Text, Data, DataLen, Align); }
 
 	protected:
--- a/Engine/FontRenderer.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Engine/FontRenderer.h	Tue Jul 26 09:55:07 2011 +0000
@@ -2,6 +2,7 @@
 
 #include "../Engine/Graphics.h"
 #include "../Resource/ResourceFile.h"
+#include "GraphicTargets2D.h"
 
 namespace gge { namespace resource {
 	class File;
@@ -117,11 +118,11 @@
 		friend class Font;
 	protected:
 		////Prints the given text to the target using given color.
-		virtual void Print(graphics::I2DColorizableGraphicsTarget *target, int X, int Y, string Text, graphics::RGBint Color, ShadowParams Shadow=ShadowParams())=0;
+		virtual void Print(graphics::ColorizableImageTarget2D *target, int X, int Y, string Text, graphics::RGBint Color, ShadowParams Shadow=ShadowParams())=0;
 		////Prints the given text to the target using given color. Text is wrapped and aligned as necessary
-		virtual void Print(graphics::I2DColorizableGraphicsTarget *target, int X, int Y, int W, string Text, graphics::RGBint Color, TextAlignment::Type Align=TextAlignment::Left, ShadowParams Shadow=ShadowParams())=0;
+		virtual void Print(graphics::ColorizableImageTarget2D *target, int X, int Y, int W, string Text, graphics::RGBint Color, TextAlignment::Type Align=TextAlignment::Left, ShadowParams Shadow=ShadowParams())=0;
 		////This method is extended to cover meta functionality for advanced text rendering
-		virtual void Print(graphics::I2DColorizableGraphicsTarget *target, int X, int Y, int W, string Text, graphics::RGBint Color, EPrintData *Data, int DataLen, TextAlignment::Type Align=TextAlignment::Left, ShadowParams Shadow=ShadowParams())=0;
+		virtual void Print(graphics::ColorizableImageTarget2D *target, int X, int Y, int W, string Text, graphics::RGBint Color, EPrintData *Data, int DataLen, TextAlignment::Type Align=TextAlignment::Left, ShadowParams Shadow=ShadowParams())=0;
 		////This method is extended to cover meta functionality for advanced text rendering. This function does not render the given text
 		/// it only processes meta data
 		virtual void Print_Test(int X, int Y, int W, string Text, EPrintData *Data, int DataLen, TextAlignment::Type Align)=0;
--- a/Engine/GGEMain.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Engine/GGEMain.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -3,8 +3,11 @@
 #include "Pointer.h"
 #include "Graphics.h"
 #include "Input.h"
-#include "Animator.h"
+#include "Animation.h"
 //#include "../Widgets/WidgetMain.h"
+#include "..\Utils\Rectangle2D.h"
+
+using namespace gge::utils;
 
 namespace gge {
 	GGEMain Main;
@@ -91,9 +94,9 @@
 	}
 
 	void GGEMain::Render() {
-		graphics::PreRender();
+		graphics::system::PreRender();
 		LayerBase::Render();
-		graphics::PostRender(Device);
+		graphics::system::PostRender(Device);
 	}
 
 	IntervalObject *GGEMain::RegisterInterval(unsigned int Timeout, void* Data, IntervalSignalEvent Signal) {
@@ -126,6 +129,21 @@
 		//InitializeWidgets();
 	}
 
+	void GGEMain::InitializeAll(string Title, os::IconHandle Icon) {
+		InitializeOS();
+		Rectangle r=os::window::UsableScreenMetrics();
+		r.Width-=Width;
+		r.Height-=Height;
+		CreateWindow(Title, Icon, r.Left+r.Width/2, r.Top+r.Height/4);
+		InitializeGraphics();
+		InitializeSound();
+		InitializeInput();
+
+		InitializeAnimation();
+		InitializePointer();
+		//InitializeWidgets();
+	}
+
 	os::DeviceHandle GGEMain::InitializeGraphics() {
 		Device = gge::graphics::Initialize(Window, BitDepth, Width, Height); return Device;
 	}
@@ -143,7 +161,7 @@
 	}
 
 	void GGEMain::InitializeAnimation() {
-		gge::InitializeAnimation(this);
+		gge::animation::Initialize(*this);
 	}
 
 	void GGEMain::InitializePointer() {
--- a/Engine/GGEMain.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Engine/GGEMain.h	Tue Jul 26 09:55:07 2011 +0000
@@ -109,7 +109,9 @@
 		////Initializes OS subsystem allowing it to setup events. Should be called before creating a window
 		void		 InitializeOS();
 		////Initializes all systems creating the main window
-		void		 InitializeAll(string Title, os::IconHandle Icon, int X=0, int Y=0);
+		void		 InitializeAll(string Title, os::IconHandle Icon, int X, int Y);
+		////Initializes all systems creating the main window and centering
+		void		 InitializeAll(string Title, os::IconHandle Icon);
 		////Initializes Animation subsystem. Before calling this function, animations does not progress
 		/// automatically.
 		void		 InitializeAnimation();
@@ -126,11 +128,13 @@
 
 
 		void MoveWindow(int X, int Y) {
-			os::window::MoveWindow(Window, X, Y);
+			if(!FullScreen)
+				os::window::MoveWindow(Window, X, Y);
 		}
 
 		void MoveWindow(utils::Point p) {
-			os::window::MoveWindow(Window, p);
+			if(!FullScreen)
+				os::window::MoveWindow(Window, p);
 		}
 
 		////This event is triggered before rendering, after intervals
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Graphic2D.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -0,0 +1,30 @@
+
+#include "Graphic2D.h"
+
+namespace gge { namespace graphics {
+
+	void RectangularGraphic2D::DrawRotated( ImageTarget2D& Target, utils::Point p, float angle, utils::Point origin/*=utils::Point(0,0)*/ )
+	{
+		int W=getwidth();
+		int H=getheight();
+
+		origin+=p;
+		utils::Point p1=p;
+		utils::Point p2=p;
+		utils::Point p3=p;
+		utils::Point p4=p;
+
+		p1.x+=W;
+		p2.x+=W;
+		p2.y+=H;
+		p3.y+=H;
+
+		p1.Rotate(angle, origin);
+		p2.Rotate(angle, origin);
+		p3.Rotate(angle, origin);
+		p4.Rotate(angle, origin);
+
+		Draw(Target, p1,p2,p3,p4);
+	}
+
+} }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Graphic2D.h	Tue Jul 26 09:55:07 2011 +0000
@@ -0,0 +1,392 @@
+#pragma once
+
+
+#include "Graphics.h"
+#include "GraphicTargets2D.h"
+#include "..\Utils\Size2D.h"
+
+
+namespace gge { namespace graphics {
+
+	class Graphic2D {
+	public:
+		//Only top left specified
+		void Draw(ImageTarget2D &target, int X, int Y) {
+			draw(target, X,Y);
+		}
+		void Draw(ImageTarget2D *target, int X, int Y) {
+			draw(*target, X,Y);
+		}
+
+		void Draw(ImageTarget2D &target, utils::Point p) {
+			draw(target, p.x,p.y);
+		}
+		void Draw(ImageTarget2D *target, utils::Point p) {
+			draw(*target, p.x,p.y);
+		}
+
+	protected:
+		virtual void draw(ImageTarget2D& Target, int X, int Y) = 0;
+	};
+
+	class SizelessGraphic2D {
+	public:
+
+		//With size factor, scaling the image
+		void DrawIn(ImageTarget2D &target, int X, int Y, int W, int H) {
+			drawin(target, X,Y, W,H);
+		}
+		void DrawIn(ImageTarget2D *target, int X, int Y, int W, int H) {
+			drawin(*target, X,Y, W,H);
+		}
+
+		void DrawIn(ImageTarget2D &target, utils::Point p, int W, int H) {
+			drawin(target, p.x,p.y, W,H);
+		}
+		void DrawIn(ImageTarget2D *target, utils::Point p, int W, int H) {
+			drawin(*target, p.x,p.y, W,H);
+		}
+
+
+		void DrawIn(ImageTarget2D &target, int X, int Y, utils::Size s) {
+			drawin(target, X,Y, s.Width,s.Height);
+		}
+		void DrawIn(ImageTarget2D *target, int X, int Y, utils::Size s) {
+			drawin(*target, X,Y, s.Width,s.Height);
+		}
+
+		void DrawIn(ImageTarget2D &target, utils::Point p, utils::Size s) {
+			drawin(target, p.x,p.y, s.Width,s.Height);
+		}
+		void DrawIn(ImageTarget2D *target, utils::Point p, utils::Size s) {
+			drawin(*target, p.x,p.y, s.Width,s.Height);
+		}
+
+
+
+		//Draw using a rectangle, still point and size
+		void DrawIn(ImageTarget2D &target, utils::Rectangle r) {
+			drawin(target, r.Left,r.Top, r.Width,r.Height);
+		}
+		void DrawIn(ImageTarget2D *target, utils::Rectangle r) {
+			drawin(*target, r.Left,r.Top, r.Width,r.Height);
+		}
+
+
+
+		//Draw size controlled
+		void DrawIn(ImageTarget2D &target, SizeController2D &controller, int X, int Y, int W, int H) {
+			drawin(target, controller, X,Y, W,H);
+		}
+		void DrawIn(ImageTarget2D *target, SizeController2D &controller, int X, int Y, int W, int H) {
+			drawin(*target, controller, X,Y, W,H);
+		}
+
+		void DrawIn(ImageTarget2D &target, SizeController2D &controller, utils::Point p, int W, int H) {
+			drawin(target, controller, p.x,p.y, W,H);
+		}
+		void DrawIn(ImageTarget2D *target, SizeController2D &controller, utils::Point p, int W, int H) {
+			drawin(*target, controller, p.x,p.y, W,H);
+		}
+
+		void DrawIn(ImageTarget2D &target, SizeController2D &controller, int X, int Y, utils::Size s) {
+			drawin(target, controller, X,Y, s.Width, s.Height);
+		}
+		void DrawIn(ImageTarget2D *target, SizeController2D &controller, int X, int Y, utils::Size s) {
+			drawin(*target, controller, X,Y, s.Width, s.Height);
+		}
+
+		void DrawIn(ImageTarget2D &target, SizeController2D &controller, utils::Point p, utils::Size s) {
+			drawin(target, controller, p.x,p.y, s.Width, s.Height);
+		}
+		void DrawIn(ImageTarget2D *target, SizeController2D &controller, utils::Point p, utils::Size s) {
+			drawin(*target, controller, p.x,p.y, s.Width, s.Height);
+		}
+
+
+		void DrawIn(ImageTarget2D &target, SizeController2D &controller, utils::Rectangle r) {
+			drawin(target, controller, r.Left,r.Top, r.Width, r.Height);
+		}
+		void DrawIn(ImageTarget2D *target, SizeController2D &controller, utils::Rectangle r) {
+			drawin(*target, controller, r.Left,r.Top, r.Width, r.Height);
+		}
+
+
+
+		//Size calculation
+		int CalculateWidth(int W=-1) const {
+			return calculatewidth(W);
+		}
+		int CalculateHeight(int H=-1) const {
+			return calculateheight(H);
+		}
+		utils::Size	CalculateSize(int W=-1, int H=-1) const {
+			return utils::Size(calculatewidth(W), calculateheight(H));
+		}
+		utils::Size	CalculateSize(utils::Size s) const {
+			return utils::Size(calculatewidth(s.Width), calculateheight(s.Height));
+		}
+
+		int CalculateWidth(const SizeController2D &controller, int W=-1) const {
+			return calculatewidth(controller, W);
+		}
+		int CalculateHeight(const SizeController2D &controller, int H=-1) const {
+			return calculateheight(controller, H);
+		}
+		utils::Size	CalculateCalculateSize(const SizeController2D &controller, int W=-1, int H=-1) const {
+			return utils::Size(calculatewidth(controller, W), calculateheight(controller, H));
+		}
+		utils::Size	CalculateSize(const SizeController2D &controller, utils::Size s) const {
+			return utils::Size(calculatewidth(controller, s.Width), calculateheight(controller, s.Height));
+		}
+
+	protected:
+		virtual void drawin(ImageTarget2D& Target, int X, int Y, int W, int H) = 0;
+		virtual void drawin(ImageTarget2D& Target, SizeController2D &controller, int X, int Y, int W, int H) = 0;
+
+		virtual int calculatewidth (int w=-1) const = 0;
+		virtual int calculateheight(int h=-1) const = 0;
+
+		virtual int calculatewidth (const SizeController2D &controller, int w=-1) const = 0;
+		virtual int calculateheight(const SizeController2D &controller, int h=-1) const = 0;
+	};
+
+
+	////This is a basic drawing object
+	class RectangularGraphic2D : public Graphic2D, public SizelessGraphic2D {
+	public:
+		//public methods
+
+		using Graphic2D::Draw;
+
+		//With size factor, scaling the image
+		void DrawStretched(ImageTarget2D &target, int X, int Y, int W, int H) {
+			drawstretched(target, X,Y, W,H);
+		}
+		void DrawStretched(ImageTarget2D *target, int X, int Y, int W, int H) {
+			drawstretched(*target, X,Y, W,H);
+		}
+
+		void DrawStretched(ImageTarget2D &target, utils::Point p, int W, int H) {
+			drawstretched(target, p.x,p.y, W,H);
+		}
+		void DrawStretched(ImageTarget2D *target, utils::Point p, int W, int H) {
+			drawstretched(*target, p.x,p.y, W,H);
+		}
+
+
+		void DrawStretched(ImageTarget2D &target, int X, int Y, utils::Size s) {
+			drawstretched(target, X,Y, s.Width,s.Height);
+		}
+		void DrawStretched(ImageTarget2D *target, int X, int Y, utils::Size s) {
+			drawstretched(*target, X,Y, s.Width,s.Height);
+		}
+
+		void DrawStretched(ImageTarget2D &target, utils::Point p, utils::Size s) {
+			drawstretched(target, p.x,p.y, s.Width,s.Height);
+		}
+		void DrawStretched(ImageTarget2D *target, utils::Point p, utils::Size s) {
+			drawstretched(*target, p.x,p.y, s.Width,s.Height);
+		}
+
+
+
+		//Draw using a rectangle, still point and size
+		void DrawStretched(ImageTarget2D &target, utils::Rectangle r) {
+			drawstretched(target, r.Left,r.Top, r.Width,r.Height);
+		}
+		void DrawStretched(ImageTarget2D *target, utils::Rectangle r) {
+			drawstretched(*target, r.Left,r.Top, r.Width,r.Height);
+		}
+
+
+
+		//Draw using 4 coords
+		void Draw(ImageTarget2D& Target, int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4) {
+			draw(Target, X1,Y1, X2,Y2, X3,Y3, X4,Y4);
+		}
+		void Draw(ImageTarget2D* Target, int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4) {
+			draw(*Target, X1,Y1, X2,Y2, X3,Y3, X4,Y4);
+		}
+
+		void Draw(ImageTarget2D& Target, utils::Point p1, utils::Point p2, utils::Point p3, utils::Point p4) {
+			draw(Target, p1.x,p1.y, p2.x,p2.y, p3.x,p3.y, p4.x,p4.y);
+		}
+		void Draw(ImageTarget2D* Target, utils::Point p1, utils::Point p2, utils::Point p3, utils::Point p4) {
+			draw(*Target, p1.x,p1.y, p2.x,p2.y, p3.x,p3.y, p4.x,p4.y);
+		}
+
+
+
+		//Draw rotated
+		void DrawRotated(ImageTarget2D& Target, utils::Point p, float angle, utils::Point origin=utils::Point(0,0));
+		void DrawRotated(ImageTarget2D* Target, utils::Point p, float angle, utils::Point origin=utils::Point(0,0)) {
+			DrawRotated(*Target, p, angle, origin);
+		}
+
+		void DrawRotated(ImageTarget2D& Target, int X,int Y, float angle, int oX=0,int oY=0) {
+			DrawRotated(Target, utils::Point(X,Y), angle, utils::Point(oX,oY));
+		}
+		void DrawRotated(ImageTarget2D* Target, int X,int Y, float angle, int oX=0,int oY=0) {
+			DrawRotated(*Target, utils::Point(X,Y), angle, utils::Point(oX,oY));
+		}
+
+
+
+		//Draw tiled
+		void Draw(ImageTarget2D &target, Tiling2D::Type tiling, int X, int Y, int W, int H) {
+			draw(target, tiling, X,Y, W,H);
+		}
+		void Draw(ImageTarget2D *target, Tiling2D::Type tiling, int X, int Y, int W, int H) {
+			draw(*target, tiling, X,Y, W,H);
+		}
+
+		void Draw(ImageTarget2D &target, Tiling2D::Type tiling, utils::Point p, int W, int H) {
+			draw(target, tiling, p.x,p.y, W,H);
+		}
+		void Draw(ImageTarget2D *target, Tiling2D::Type tiling, utils::Point p, int W, int H) {
+			draw(*target, tiling, p.x,p.y, W,H);
+		}
+
+		void Draw(ImageTarget2D &target, Tiling2D::Type tiling, int X, int Y, utils::Size s) {
+			draw(target, tiling, X,Y, s.Width, s.Height);
+		}
+		void Draw(ImageTarget2D *target, Tiling2D::Type tiling, int X, int Y, utils::Size s) {
+			draw(*target, tiling, X,Y, s.Width, s.Height);
+		}
+
+		void Draw(ImageTarget2D &target, Tiling2D::Type tiling, utils::Point p, utils::Size s) {
+			draw(target, tiling, p.x,p.y, s.Width, s.Height);
+		}
+		void Draw(ImageTarget2D *target, Tiling2D::Type tiling, utils::Point p, utils::Size s) {
+			draw(*target, tiling, p.x,p.y, s.Width, s.Height);
+		}
+
+
+		void Draw(ImageTarget2D &target, Tiling2D::Type tiling, utils::Rectangle r) {
+			draw(target, tiling, r.Left,r.Top, r.Width, r.Height);
+		}
+		void Draw(ImageTarget2D *target, Tiling2D::Type tiling, utils::Rectangle r) {
+			draw(*target, tiling, r.Left,r.Top, r.Width, r.Height);
+		}
+
+
+
+
+
+		//Draw partial
+		void Draw(ImageTarget2D& target, int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) {
+			draw(target, X1,Y1, X2,Y2, X3,Y3, X4,Y4, S1,U1, S2,U2, S3,U3, S4,U4);
+		}
+		void Draw(ImageTarget2D* target, int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) {
+			draw(*target, X1,Y1, X2,Y2, X3,Y3, X4,Y4, S1,U1, S2,U2, S3,U3, S4,U4);
+		}
+
+		void Draw(ImageTarget2D& target, utils::Point p1, utils::Point p2, utils::Point p3, utils::Point p4, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) {
+			draw(target, p1.x,p1.y, p2.x,p2.y, p3.x,p3.y, p4.x,p4.y, S1,U1, S2,U2, S3,U3, S4,U4);
+		}
+		void Draw(ImageTarget2D* target, utils::Point p1, utils::Point p2, utils::Point p3, utils::Point p4, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) {
+			draw(*target, p1.x,p1.y, p2.x,p2.y, p3.x,p3.y, p4.x,p4.y, S1,U1, S2,U2, S3,U3, S4,U4);
+		}
+
+		void Draw(ImageTarget2D& target, int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4, utils::Point2D t1, utils::Point2D t2, utils::Point2D t3, utils::Point2D t4) {
+			draw(target, X1,Y1, X2,Y2, X3,Y3, X4,Y4, t1.x,t1.y, t2.x,t2.y, t3.x,t3.y, t4.x,t4.y);
+		}
+		void Draw(ImageTarget2D* target, int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4, utils::Point2D t1, utils::Point2D t2, utils::Point2D t3, utils::Point2D t4) {
+			draw(*target, X1,Y1, X2,Y2, X3,Y3, X4,Y4, t1.x,t1.y, t2.x,t2.y, t3.x,t3.y, t4.x,t4.y);
+		}
+
+		void Draw(ImageTarget2D& target, utils::Point p1, utils::Point p2, utils::Point p3, utils::Point p4, utils::Point2D t1, utils::Point2D t2, utils::Point2D t3, utils::Point2D t4) {
+			draw(target, p1.x,p1.y, p2.x,p2.y, p3.x,p3.y, p4.x,p4.y, t1.x,t1.y, t2.x,t2.y, t3.x,t3.y, t4.x,t4.y);
+		}
+		void Draw(ImageTarget2D* target, utils::Point p1, utils::Point p2, utils::Point p3, utils::Point p4, utils::Point2D t1, utils::Point2D t2, utils::Point2D t3, utils::Point2D t4) {
+			draw(*target, p1.x,p1.y, p2.x,p2.y, p3.x,p3.y, p4.x,p4.y, t1.x,t1.y, t2.x,t2.y, t3.x,t3.y, t4.x,t4.y);
+		}
+
+		void Draw(ImageTarget2D& target, int X,int Y,int W,int H, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) {
+			draw(target, X,Y, X+W,Y, X+W,Y+H, X,Y+H, S1,U1, S2,U2, S3,U3, S4,U4);
+		}
+		void Draw(ImageTarget2D* target, int X,int Y,int W,int H, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) {
+			draw(*target, X,Y, X+W,Y, X+W,Y+H, X,Y+H, S1,U1, S2,U2, S3,U3, S4,U4);
+		}
+
+		void Draw(ImageTarget2D& target, int X,int Y,int W,int H, utils::Point2D t1, utils::Point2D t2, utils::Point2D t3, utils::Point2D t4) {
+			draw(target, X,Y, X+W,Y, X+W,Y+H, X,Y+H, t1.x,t1.y, t2.x,t2.y, t3.x,t3.y, t4.x,t4.y);
+		}
+		void Draw(ImageTarget2D* target, int X,int Y,int W,int H, utils::Point2D t1, utils::Point2D t2, utils::Point2D t3, utils::Point2D t4) {
+			draw(*target, X,Y, X+W,Y, X+W,Y+H, X,Y+H, t1.x,t1.y, t2.x,t2.y, t3.x,t3.y, t4.x,t4.y);
+		}
+
+		void Draw(ImageTarget2D& target, utils::Point p,int W,int H, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) {
+			draw(target, p.x,p.y, p.x+W,p.y, p.x+W,p.y+H, p.x,p.y+H, S1,U1, S2,U2, S3,U3, S4,U4);
+		}
+		void Draw(ImageTarget2D* target, utils::Point p,int W,int H, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) {
+			draw(*target, p.x,p.y, p.x+W,p.y, p.x+W,p.y+H, p.x,p.y+H, S1,U1, S2,U2, S3,U3, S4,U4);
+		}
+
+		void Draw(ImageTarget2D& target, utils::Point p,int W,int H, utils::Point2D t1, utils::Point2D t2, utils::Point2D t3, utils::Point2D t4) {
+			draw(target, p.x,p.y, p.x+W,p.y, p.x+W,p.y+H, p.x,p.y+H, t1.x,t1.y, t2.x,t2.y, t3.x,t3.y, t4.x,t4.y);
+		}
+		void Draw(ImageTarget2D* target, utils::Point p,int W,int H, utils::Point2D t1, utils::Point2D t2, utils::Point2D t3, utils::Point2D t4) {
+			draw(*target, p.x,p.y, p.x+W,p.y, p.x+W,p.y+H, p.x,p.y+H, t1.x,t1.y, t2.x,t2.y, t3.x,t3.y, t4.x,t4.y);
+		}
+
+		void Draw(ImageTarget2D& target, int X,int Y,utils::Size s, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) {
+			draw(target, X,Y, X+s.Width,Y, X+s.Width,Y+s.Height, X,Y+s.Height, S1,U1, S2,U2, S3,U3, S4,U4);
+		}
+		void Draw(ImageTarget2D* target, int X,int Y,utils::Size s, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) {
+			draw(*target, X,Y, X+s.Width,Y, X+s.Width,Y+s.Height, X,Y+s.Height, S1,U1, S2,U2, S3,U3, S4,U4);
+		}
+
+		void Draw(ImageTarget2D& target, int X,int Y,utils::Size s, utils::Point2D t1, utils::Point2D t2, utils::Point2D t3, utils::Point2D t4) {
+			draw(target, X,Y, X+s.Width,Y, X+s.Width,Y+s.Height, X,Y+s.Height, t1.x,t1.y, t2.x,t2.y, t3.x,t3.y, t4.x,t4.y);
+		}
+		void Draw(ImageTarget2D* target, int X,int Y,utils::Size s, utils::Point2D t1, utils::Point2D t2, utils::Point2D t3, utils::Point2D t4) {
+			draw(*target, X,Y, X+s.Width,Y, X+s.Width,Y+s.Height, X,Y+s.Height, t1.x,t1.y, t2.x,t2.y, t3.x,t3.y, t4.x,t4.y);
+		}
+
+		void Draw(ImageTarget2D& target, utils::Point p,utils::Size s, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) {
+			draw(target, p.x,p.y, p.x+s.Width,p.y, p.x+s.Width,p.y+s.Height, p.x,p.y+s.Height, S1,U1, S2,U2, S3,U3, S4,U4);
+		}
+		void Draw(ImageTarget2D* target, utils::Point p,utils::Size s, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) {
+			draw(*target, p.x,p.y, p.x+s.Width,p.y, p.x+s.Width,p.y+s.Height, p.x,p.y+s.Height, S1,U1, S2,U2, S3,U3, S4,U4);
+		}
+
+		void Draw(ImageTarget2D& target, utils::Point p,utils::Size s, utils::Point2D t1, utils::Point2D t2, utils::Point2D t3, utils::Point2D t4) {
+			draw(target, p.x,p.y, p.x+s.Width,p.y, p.x+s.Width,p.y+s.Height, p.x,p.y+s.Height, t1.x,t1.y, t2.x,t2.y, t3.x,t3.y, t4.x,t4.y);
+		}
+		void Draw(ImageTarget2D* target, utils::Point p,utils::Size s, utils::Point2D t1, utils::Point2D t2, utils::Point2D t3, utils::Point2D t4) {
+			draw(*target, p.x,p.y, p.x+s.Width,p.y, p.x+s.Width,p.y+s.Height, p.x,p.y+s.Height, t1.x,t1.y, t2.x,t2.y, t3.x,t3.y, t4.x,t4.y);
+		}
+
+
+
+
+
+		int GetWidth() const {
+			return getwidth();
+		}
+		int GetHeight() const {
+			return getheight();
+		}
+		utils::Size	GetSize() const {
+			return utils::Size(getwidth(), getheight());
+		}
+
+
+
+	protected:
+		virtual void draw(ImageTarget2D& Target, int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) = 0;
+		virtual void draw(ImageTarget2D& Target, int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4) = 0;
+		virtual void drawstretched(ImageTarget2D& Target, int X, int Y, int W, int H) = 0;
+		virtual void draw(ImageTarget2D& Target, Tiling2D::Type Tiling, int X, int Y, int W, int H) = 0;
+		virtual void draw(ImageTarget2D& Target, int X, int Y) {
+			drawstretched(Target, X,Y, getwidth(), getheight());
+		}
+
+		virtual int getwidth () const = 0;
+		virtual int getheight() const = 0;
+	};
+
+
+} }
--- a/Engine/GraphicLayers.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Engine/GraphicLayers.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -5,6 +5,7 @@
 
 using namespace gge::utils;
 using namespace gge::input;
+using namespace gge::graphics::system;
 
 namespace gge { namespace graphics {
 	RGBfloat CurrentLayerColor;
@@ -28,6 +29,38 @@
 		surface->VertexCoords[3].y=Y4;
 	}
 
+	void Basic2DLayer::Draw(GLTexture *Image, int X1, int Y1, int X2, int Y2, int X3, int Y3, int X4, int Y4,  float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) {
+		BasicSurface *surface=Surfaces.Add();
+
+		surface->setTexture(Image);
+		surface->VertexCoords[0].x=X1;
+		surface->VertexCoords[0].y=Y1;
+
+		surface->VertexCoords[1].x=X2;
+		surface->VertexCoords[1].y=Y2;
+
+		surface->VertexCoords[2].x=X3;
+		surface->VertexCoords[2].y=Y3;
+
+		surface->VertexCoords[3].x=X4;
+		surface->VertexCoords[3].y=Y4;
+
+		surface->CreateTextureCoords();
+
+		float w=Image->ImageCoord[2].s, h=Image->ImageCoord[2].t;
+		surface->TextureCoords[0].s=w*S1;
+		surface->TextureCoords[0].t=h*U1;
+
+		surface->TextureCoords[1].s=w*S2;
+		surface->TextureCoords[1].t=h*U2;
+
+		surface->TextureCoords[2].s=w*S3;
+		surface->TextureCoords[2].t=h*U3;
+
+		surface->TextureCoords[3].s=w*S4;
+		surface->TextureCoords[3].t=h*U4;
+	}
+
 	void Basic2DLayer::DrawTiled(GLTexture *Image,int X,int Y,int W,int H) {
 		///*Handles special case where size is 2^n
 		if(sl2(Image->H)==Image->H) {
@@ -541,6 +574,523 @@
 		glPopAttrib();
 	}
 
+
+	void Colorizable2DLayer::Draw(GLTexture *Image, int X1, int Y1, int X2, int Y2, int X3, int Y3, int X4, int Y4) {
+		ColorizableSurface *surface=Surfaces.Add();
+
+		surface->setTexture(Image);
+		surface->VertexCoords[0].x=X1;
+		surface->VertexCoords[0].y=Y1;
+
+		surface->VertexCoords[1].x=X2;
+		surface->VertexCoords[1].y=Y2;
+
+		surface->VertexCoords[2].x=X3;
+		surface->VertexCoords[2].y=Y3;
+
+		surface->VertexCoords[3].x=X4;
+		surface->VertexCoords[3].y=Y4;
+
+		surface->Color=ToRGBfloat(CurrentColor);
+	}
+
+	void Colorizable2DLayer::Draw(GLTexture *Image, int X1, int Y1, int X2, int Y2, int X3, int Y3, int X4, int Y4,  float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) {
+		ColorizableSurface *surface=Surfaces.Add();
+
+		surface->setTexture(Image);
+		surface->VertexCoords[0].x=X1;
+		surface->VertexCoords[0].y=Y1;
+
+		surface->VertexCoords[1].x=X2;
+		surface->VertexCoords[1].y=Y2;
+
+		surface->VertexCoords[2].x=X3;
+		surface->VertexCoords[2].y=Y3;
+
+		surface->VertexCoords[3].x=X4;
+		surface->VertexCoords[3].y=Y4;
+
+		surface->CreateTextureCoords();
+
+		float w=Image->ImageCoord[2].s, h=Image->ImageCoord[2].t;
+		surface->TextureCoords[0].s=w*S1;
+		surface->TextureCoords[0].t=h*U1;
+
+		surface->TextureCoords[1].s=w*S2;
+		surface->TextureCoords[1].t=h*U2;
+
+		surface->TextureCoords[2].s=w*S3;
+		surface->TextureCoords[2].t=h*U3;
+
+		surface->TextureCoords[3].s=w*S4;
+		surface->TextureCoords[3].t=h*U4;
+
+		surface->Color=ToRGBfloat(CurrentColor);
+	}
+
+	void Colorizable2DLayer::DrawTiled(GLTexture *Image,int X,int Y,int W,int H) {
+		///*Handles special case where size is 2^n
+		if(sl2(Image->H)==Image->H) {
+			if(sl2(Image->W)==Image->W) { //both axis are size of 2^n
+				ColorizableSurface *surface=Surfaces.Add();
+				surface->Color=ToRGBfloat(CurrentColor);
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=X;
+				surface->VertexCoords[0].y=Y;
+
+				surface->TextureCoords[1].s=(float)W/Image->W;
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=X+W;
+				surface->VertexCoords[1].y=Y;
+
+				surface->TextureCoords[2].s=(float)W/Image->W;
+				surface->TextureCoords[2].t=(float)H/Image->H;
+				surface->VertexCoords[2].x=X+W;
+				surface->VertexCoords[2].y=Y+H;
+
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=(float)H/Image->H;
+				surface->VertexCoords[3].x=X;
+				surface->VertexCoords[3].y=Y+H;
+			} else { //only height is 2^n
+				//we leave at least a portion of an image to the last part
+				//so that there will be less controls
+				int x=X,tx=X+W-Image->W;
+				//draw whole parts where image is texture repeated in
+				//y axis, we only need to draw multiple images for x axis
+				for(x=X;x<tx;x+=Image->W) { 
+					ColorizableSurface *surface=Surfaces.Add();
+					surface->Color=ToRGBfloat(CurrentColor);
+
+					surface->setTexture(Image);
+					surface->CreateTextureCoords();
+
+					surface->TextureCoords[0].s=0;
+					surface->TextureCoords[0].t=0;
+					surface->VertexCoords[0].x=x;
+					surface->VertexCoords[0].y=Y;
+
+					surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+					surface->TextureCoords[1].t=0;
+					surface->VertexCoords[1].x=x+Image->W;
+					surface->VertexCoords[1].y=Y;
+
+					surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+					surface->TextureCoords[2].t=(float)H/Image->H;
+					surface->VertexCoords[2].x=x+Image->W;
+					surface->VertexCoords[2].y=Y+H;
+
+					surface->TextureCoords[3].s=0;
+					surface->TextureCoords[3].t=(float)H/Image->H;
+					surface->VertexCoords[3].x=x;
+					surface->VertexCoords[3].y=Y+H;
+				}
+
+				//last image (might be partial)
+				ColorizableSurface *surface=Surfaces.Add();
+				surface->Color=ToRGBfloat(CurrentColor);
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=x;
+				surface->VertexCoords[0].y=Y;
+
+				surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=X+W;
+				surface->VertexCoords[1].y=Y;
+
+				surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
+				surface->TextureCoords[2].t=(float)H/Image->H;
+				surface->VertexCoords[2].x=X+W;
+				surface->VertexCoords[2].y=Y+H;
+
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=(float)H/Image->H;
+				surface->VertexCoords[3].x=x;
+				surface->VertexCoords[3].y=Y+H;
+			}
+		} else {
+			if(sl2(Image->W) == Image->W) { //only width is 2^n
+				//we leave at least a portion of an image to the last part
+				//so that there will be less controls
+				int y=Y,ty=Y+H-Image->H;
+				//draw whole parts where image is texture repeated in
+				//x axis, we only need to draw multiple images for y axis
+				for(y=Y;y<ty;y+=Image->H) {
+					ColorizableSurface *surface=Surfaces.Add();
+					surface->Color=ToRGBfloat(CurrentColor);
+
+					surface->setTexture(Image);
+					surface->CreateTextureCoords();
+
+					surface->TextureCoords[0].s=0;
+					surface->TextureCoords[0].t=0;
+					surface->VertexCoords[0].x=X;
+					surface->VertexCoords[0].y=y;
+
+					surface->TextureCoords[1].s=(float)W/Image->W;
+					surface->TextureCoords[1].t=0;
+					surface->VertexCoords[1].x=X+W;
+					surface->VertexCoords[1].y=y;
+
+					surface->TextureCoords[2].s=(float)W/Image->W;
+					surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+					surface->VertexCoords[2].x=X+W;
+					surface->VertexCoords[2].y=y+Image->H;
+
+					surface->TextureCoords[3].s=0;
+					surface->TextureCoords[3].t=Image->ImageCoord[3].t;
+					surface->VertexCoords[3].x=X;
+					surface->VertexCoords[3].y=y+Image->H;
+				}
+
+				//last image (might be partial)
+				ColorizableSurface *surface=Surfaces.Add();
+				surface->Color=ToRGBfloat(CurrentColor);
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=X;
+				surface->VertexCoords[0].y=y;
+
+				surface->TextureCoords[1].s=(float)W/Image->W;
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=X+W;
+				surface->VertexCoords[1].y=y;
+
+				surface->TextureCoords[2].s=(float)W/Image->W;
+				surface->TextureCoords[2].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[2].x=X+W;
+				surface->VertexCoords[2].y=Y+H;
+
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=Image->ImageCoord[3].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[3].x=X;
+				surface->VertexCoords[3].y=Y+H;
+			} else { //if the image has no 2^n dimensions
+				//we move row by row
+				int y=Y,ty=Y+H-Image->H;
+				for(y=Y;y<ty;y+=Image->H) {
+					//this part is x axis
+					int cy=y+Image->H;
+					int x=X,tx=X+W-Image->W;
+					for(x=X;x<tx;x+=Image->W) {
+						//whole images
+						ColorizableSurface *surface=Surfaces.Add();
+						surface->Color=ToRGBfloat(CurrentColor);
+
+						surface->setTexture(Image);
+						surface->CreateTextureCoords();
+
+						surface->TextureCoords[0].s=0;
+						surface->TextureCoords[0].t=0;
+						surface->VertexCoords[0].x=x;
+						surface->VertexCoords[0].y=y;
+
+						surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+						surface->TextureCoords[1].t=0;
+						surface->VertexCoords[1].x=x+Image->W;
+						surface->VertexCoords[1].y=y;
+
+						surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+						surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+						surface->VertexCoords[2].x=x+Image->W;
+						surface->VertexCoords[2].y=cy;
+
+						surface->TextureCoords[3].s=0;
+						surface->TextureCoords[3].t=Image->ImageCoord[3].t;
+						surface->VertexCoords[3].x=x;
+						surface->VertexCoords[3].y=cy;
+					}
+
+					//partial image at the end of x axis, only x axis is partial
+					ColorizableSurface *surface=Surfaces.Add();
+					surface->Color=ToRGBfloat(CurrentColor);
+
+					surface->setTexture(Image);
+					surface->CreateTextureCoords();
+
+					surface->TextureCoords[0].s=0;
+					surface->TextureCoords[0].t=0;
+					surface->VertexCoords[0].x=x;
+					surface->VertexCoords[0].y=y;
+
+					surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
+					surface->TextureCoords[1].t=0;
+					surface->VertexCoords[1].x=X+W;
+					surface->VertexCoords[1].y=y;
+
+					surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
+					surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+					surface->VertexCoords[2].x=X+W;
+					surface->VertexCoords[2].y=cy;
+
+					surface->TextureCoords[3].s=0;
+					surface->TextureCoords[3].t=Image->ImageCoord[2].t;
+					surface->VertexCoords[3].x=x;
+					surface->VertexCoords[3].y=cy;
+
+				}
+
+				//this part is the last partial row
+				//this is the partial texture coordinate
+				float pty=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
+				int cy=Y+H;
+				int x=X,tx=X+W-Image->W;
+				for(x=X;x<tx;x+=Image->W) {
+					//partial image in y axis
+					ColorizableSurface *surface=Surfaces.Add();
+					surface->Color=ToRGBfloat(CurrentColor);
+
+					surface->setTexture(Image);
+					surface->CreateTextureCoords();
+
+					surface->TextureCoords[0].s=0;
+					surface->TextureCoords[0].t=0;
+					surface->VertexCoords[0].x=x;
+					surface->VertexCoords[0].y=y;
+
+					surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+					surface->TextureCoords[1].t=0;
+					surface->VertexCoords[1].x=x+Image->W;
+					surface->VertexCoords[1].y=y;
+
+					surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+					surface->TextureCoords[2].t=pty;
+					surface->VertexCoords[2].x=x+Image->W;
+					surface->VertexCoords[2].y=cy;
+
+					surface->TextureCoords[3].s=0;
+					surface->TextureCoords[3].t=pty;
+					surface->VertexCoords[3].x=x;
+					surface->VertexCoords[3].y=cy;
+				}
+
+				//partial image at the end of x axis at last row, both axis are partial
+				ColorizableSurface *surface=Surfaces.Add();
+				surface->Color=ToRGBfloat(CurrentColor);
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=x;
+				surface->VertexCoords[0].y=y;
+
+				surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=X+W;
+				surface->VertexCoords[1].y=y;
+
+				surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
+				surface->TextureCoords[2].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[2].x=X+W;
+				surface->VertexCoords[2].y=Y+H;
+
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[3].x=x;
+				surface->VertexCoords[3].y=Y+H;
+
+			}
+		}
+	}
+
+	void Colorizable2DLayer::DrawHTiled(GLTexture *Image,int X,int Y,int W,int H) {
+		if(sl2(Image->W)==Image->W) { //both x axis is size of 2^n
+			//stretch and repeat as we need
+			ColorizableSurface *surface=Surfaces.Add();
+			surface->Color=ToRGBfloat(CurrentColor);
+
+			surface->setTexture(Image);
+			surface->CreateTextureCoords();
+
+			surface->TextureCoords[0].s=0;
+			surface->TextureCoords[0].t=0;
+			surface->VertexCoords[0].x=X;
+			surface->VertexCoords[0].y=Y;
+
+			surface->TextureCoords[1].s=(float)W/Image->W;
+			surface->TextureCoords[1].t=0;
+			surface->VertexCoords[1].x=X+W;
+			surface->VertexCoords[1].y=Y;
+
+			surface->TextureCoords[2].s=(float)W/Image->W;
+			surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+			surface->VertexCoords[2].x=X+W;
+			surface->VertexCoords[2].y=Y+H;
+
+			surface->TextureCoords[3].s=0;
+			surface->TextureCoords[3].t=Image->ImageCoord[2].t;
+			surface->VertexCoords[3].x=X;
+			surface->VertexCoords[3].y=Y+H;
+		} else {
+			//we leave at least a portion of an image to the last part
+			//so that there will be less controls
+			int x=X,tx=X+W-Image->W;
+			//draw whole parts where image is texture stretched in
+			//y axis, we only need to draw multiple images for x axis
+			for(x=X;x<tx;x+=Image->W) { 
+				ColorizableSurface *surface=Surfaces.Add();
+				surface->Color=ToRGBfloat(CurrentColor);
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=x;
+				surface->VertexCoords[0].y=Y;
+
+				surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=x+Image->W;
+				surface->VertexCoords[1].y=Y;
+
+				surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+				surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+				surface->VertexCoords[2].x=x+Image->W;
+				surface->VertexCoords[2].y=Y+H;
+
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=Image->ImageCoord[2].t;
+				surface->VertexCoords[3].x=x;
+				surface->VertexCoords[3].y=Y+H;
+			}
+
+			//last image (might be partial)
+			ColorizableSurface *surface=Surfaces.Add();
+			surface->Color=ToRGBfloat(CurrentColor);
+
+			surface->setTexture(Image);
+			surface->CreateTextureCoords();
+
+			surface->TextureCoords[0].s=0;
+			surface->TextureCoords[0].t=0;
+			surface->VertexCoords[0].x=x;
+			surface->VertexCoords[0].y=Y;
+
+			surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
+			surface->TextureCoords[1].t=0;
+			surface->VertexCoords[1].x=X+W;
+			surface->VertexCoords[1].y=Y;
+
+			surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
+			surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+			surface->VertexCoords[2].x=X+W;
+			surface->VertexCoords[2].y=Y+H;
+
+			surface->TextureCoords[3].s=0;
+			surface->TextureCoords[3].t=Image->ImageCoord[2].t;
+			surface->VertexCoords[3].x=x;
+			surface->VertexCoords[3].y=Y+H;	
+		}
+	}
+
+	void Colorizable2DLayer::DrawVTiled(GLTexture *Image,int X,int Y,int W,int H) {
+		if(sl2(Image->H)==Image->H) { //both x axis is size of 2^n
+			//stretch and repeat as we need
+			ColorizableSurface *surface=Surfaces.Add();
+			surface->Color=ToRGBfloat(CurrentColor);
+
+			surface->setTexture(Image);
+			surface->CreateTextureCoords();
+
+			surface->TextureCoords[0].s=0;
+			surface->TextureCoords[0].t=0;
+			surface->VertexCoords[0].x=X;
+			surface->VertexCoords[0].y=Y;
+
+			surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+			surface->TextureCoords[1].t=0;
+			surface->VertexCoords[1].x=X+W;
+			surface->VertexCoords[1].y=Y;
+
+			surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+			surface->TextureCoords[2].t=(float)H/Image->H;
+			surface->VertexCoords[2].x=X+W;
+			surface->VertexCoords[2].y=Y+H;
+
+			surface->TextureCoords[3].s=0;
+			surface->TextureCoords[3].t=(float)H/Image->H;
+			surface->VertexCoords[3].x=X;
+			surface->VertexCoords[3].y=Y+H;
+		} else {
+			//we leave at least a portion of an image to the last part
+			//so that there will be less controls
+			int y=Y,ty=Y+H-Image->H;
+			//draw whole parts where image is texture repeated in
+			//x axis, we only need to draw multiple images for y axis
+			for(y=Y;y<ty;y+=Image->H) {
+				ColorizableSurface *surface=Surfaces.Add();
+				surface->Color=ToRGBfloat(CurrentColor);
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=X;
+				surface->VertexCoords[0].y=y;
+
+				surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=X+W;
+				surface->VertexCoords[1].y=y;
+
+				surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+				surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+				surface->VertexCoords[2].x=X+W;
+				surface->VertexCoords[2].y=y+Image->H;
+
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=Image->ImageCoord[3].t;
+				surface->VertexCoords[3].x=X;
+				surface->VertexCoords[3].y=y+Image->H;
+			}
+
+			//last image (might be partial)
+			ColorizableSurface *surface=Surfaces.Add();
+			surface->Color=ToRGBfloat(CurrentColor);
+
+			surface->setTexture(Image);
+			surface->CreateTextureCoords();
+
+			surface->TextureCoords[0].s=0;
+			surface->TextureCoords[0].t=0;
+			surface->VertexCoords[0].x=X;
+			surface->VertexCoords[0].y=y;
+
+			surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+			surface->TextureCoords[1].t=0;
+			surface->VertexCoords[1].x=X+W;
+			surface->VertexCoords[1].y=y;
+
+			surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+			surface->TextureCoords[2].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
+			surface->VertexCoords[2].x=X+W;
+			surface->VertexCoords[2].y=Y+H;
+
+			surface->TextureCoords[3].s=0;
+			surface->TextureCoords[3].t=Image->ImageCoord[3].t*((float)(H-(y-Y))/Image->H);
+			surface->VertexCoords[3].x=X;
+			surface->VertexCoords[3].y=Y+H;
+		}
+	}
+
 	void Colorizable2DLayer::Render() {
 		Rectangle psc;
 		if(!isVisible) return;
@@ -622,602 +1172,4 @@
 
 	}
 
-	void Colorizable2DLayer::Draw(GLTexture *Image, int X1, int Y1, int X2, int Y2, int X3, int Y3, int X4, int Y4, RGBint color) {
-		ColorizableSurface *surface=Surfaces.Add();
-
-		surface->setTexture(Image);
-		surface->VertexCoords[0].x=X1;
-		surface->VertexCoords[0].y=Y1;
-
-		surface->VertexCoords[1].x=X2;
-		surface->VertexCoords[1].y=Y2;
-
-		surface->VertexCoords[2].x=X3;
-		surface->VertexCoords[2].y=Y3;
-
-		surface->VertexCoords[3].x=X4;
-		surface->VertexCoords[3].y=Y4;
-		surface->Color=ToRGBfloat(color);
-	}
-
-	void Colorizable2DLayer::Draw(GLTexture *Image, int X1, int Y1, int X2, int Y2, int X3, int Y3, int X4, int Y4) {
-		ColorizableSurface *surface=Surfaces.Add();
-
-		surface->setTexture(Image);
-		surface->VertexCoords[0].x=X1;
-		surface->VertexCoords[0].y=Y1;
-
-		surface->VertexCoords[1].x=X2;
-		surface->VertexCoords[1].y=Y2;
-
-		surface->VertexCoords[2].x=X3;
-		surface->VertexCoords[2].y=Y3;
-
-		surface->VertexCoords[3].x=X4;
-		surface->VertexCoords[3].y=Y4;
-		surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-	}
-
-	void Colorizable2DLayer::DrawTiled(GLTexture *Image,int X,int Y,int W,int H) {
-		///*Handles special case where size is 2^n
-		if(sl2(Image->H)==Image->H) {
-			if(sl2(Image->W)==Image->W) { //both axis are size of 2^n
-				ColorizableSurface *surface=Surfaces.Add();
-				surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-
-				surface->setTexture(Image);
-				surface->CreateTextureCoords();
-
-				surface->TextureCoords[0].s=0;
-				surface->TextureCoords[0].t=0;
-				surface->VertexCoords[0].x=X;
-				surface->VertexCoords[0].y=Y;
-
-				surface->TextureCoords[1].s=(float)W/Image->W;
-				surface->TextureCoords[1].t=0;
-				surface->VertexCoords[1].x=X+W;
-				surface->VertexCoords[1].y=Y;
-
-				surface->TextureCoords[2].s=(float)W/Image->W;
-				surface->TextureCoords[2].t=(float)H/Image->H;
-				surface->VertexCoords[2].x=X+W;
-				surface->VertexCoords[2].y=Y+H;
-
-				surface->TextureCoords[3].s=0;
-				surface->TextureCoords[3].t=(float)H/Image->H;
-				surface->VertexCoords[3].x=X;
-				surface->VertexCoords[3].y=Y+H;
-			} else { //only height is 2^n
-				//we leave at least a portion of an image to the last part
-				//so that there will be less controls
-				int x=X,tx=X+W-Image->W;
-				//draw whole parts where image is texture repeated in
-				//y axis, we only need to draw multiple images for x axis
-				for(x=X;x<tx;x+=Image->W) { 
-					ColorizableSurface *surface=Surfaces.Add();
-					surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-
-					surface->setTexture(Image);
-					surface->CreateTextureCoords();
-
-					surface->TextureCoords[0].s=0;
-					surface->TextureCoords[0].t=0;
-					surface->VertexCoords[0].x=x;
-					surface->VertexCoords[0].y=Y;
-
-					surface->TextureCoords[1].s=Image->ImageCoord[1].s;
-					surface->TextureCoords[1].t=0;
-					surface->VertexCoords[1].x=x+Image->W;
-					surface->VertexCoords[1].y=Y;
-
-					surface->TextureCoords[2].s=Image->ImageCoord[2].s;
-					surface->TextureCoords[2].t=(float)H/Image->H;
-					surface->VertexCoords[2].x=x+Image->W;
-					surface->VertexCoords[2].y=Y+H;
-
-					surface->TextureCoords[3].s=0;
-					surface->TextureCoords[3].t=(float)H/Image->H;
-					surface->VertexCoords[3].x=x;
-					surface->VertexCoords[3].y=Y+H;
-				}
-
-				//last image (might be partial)
-				ColorizableSurface *surface=Surfaces.Add();
-				surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-
-				surface->setTexture(Image);
-				surface->CreateTextureCoords();
-
-				surface->TextureCoords[0].s=0;
-				surface->TextureCoords[0].t=0;
-				surface->VertexCoords[0].x=x;
-				surface->VertexCoords[0].y=Y;
-
-				surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
-				surface->TextureCoords[1].t=0;
-				surface->VertexCoords[1].x=X+W;
-				surface->VertexCoords[1].y=Y;
-
-				surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
-				surface->TextureCoords[2].t=(float)H/Image->H;
-				surface->VertexCoords[2].x=X+W;
-				surface->VertexCoords[2].y=Y+H;
-
-				surface->TextureCoords[3].s=0;
-				surface->TextureCoords[3].t=(float)H/Image->H;
-				surface->VertexCoords[3].x=x;
-				surface->VertexCoords[3].y=Y+H;
-			}
-		} else {
-			if(sl2(Image->W) == Image->W) { //only width is 2^n
-				//we leave at least a portion of an image to the last part
-				//so that there will be less controls
-				int y=Y,ty=Y+H-Image->H;
-				//draw whole parts where image is texture repeated in
-				//x axis, we only need to draw multiple images for y axis
-				for(y=Y;y<ty;y+=Image->H) {
-					ColorizableSurface *surface=Surfaces.Add();
-					surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-
-					surface->setTexture(Image);
-					surface->CreateTextureCoords();
-
-					surface->TextureCoords[0].s=0;
-					surface->TextureCoords[0].t=0;
-					surface->VertexCoords[0].x=X;
-					surface->VertexCoords[0].y=y;
-
-					surface->TextureCoords[1].s=(float)W/Image->W;
-					surface->TextureCoords[1].t=0;
-					surface->VertexCoords[1].x=X+W;
-					surface->VertexCoords[1].y=y;
-
-					surface->TextureCoords[2].s=(float)W/Image->W;
-					surface->TextureCoords[2].t=Image->ImageCoord[2].t;
-					surface->VertexCoords[2].x=X+W;
-					surface->VertexCoords[2].y=y+Image->H;
-
-					surface->TextureCoords[3].s=0;
-					surface->TextureCoords[3].t=Image->ImageCoord[3].t;
-					surface->VertexCoords[3].x=X;
-					surface->VertexCoords[3].y=y+Image->H;
-				}
-
-				//last image (might be partial)
-				ColorizableSurface *surface=Surfaces.Add();
-				surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-
-				surface->setTexture(Image);
-				surface->CreateTextureCoords();
-
-				surface->TextureCoords[0].s=0;
-				surface->TextureCoords[0].t=0;
-				surface->VertexCoords[0].x=X;
-				surface->VertexCoords[0].y=y;
-
-				surface->TextureCoords[1].s=(float)W/Image->W;
-				surface->TextureCoords[1].t=0;
-				surface->VertexCoords[1].x=X+W;
-				surface->VertexCoords[1].y=y;
-
-				surface->TextureCoords[2].s=(float)W/Image->W;
-				surface->TextureCoords[2].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
-				surface->VertexCoords[2].x=X+W;
-				surface->VertexCoords[2].y=Y+H;
-
-				surface->TextureCoords[3].s=0;
-				surface->TextureCoords[3].t=Image->ImageCoord[3].t*((float)(H-(y-Y))/Image->H);
-				surface->VertexCoords[3].x=X;
-				surface->VertexCoords[3].y=Y+H;
-			} else { //if the image has no 2^n dimensions
-				//we move row by row
-				int y=Y,ty=Y+H-Image->H;
-				for(y=Y;y<ty;y+=Image->H) {
-					//this part is x axis
-					int cy=y+Image->H;
-					int x=X,tx=X+W-Image->W;
-					for(x=X;x<tx;x+=Image->W) {
-						//whole images
-						ColorizableSurface *surface=Surfaces.Add();
-						surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-
-						surface->setTexture(Image);
-						surface->CreateTextureCoords();
-
-						surface->TextureCoords[0].s=0;
-						surface->TextureCoords[0].t=0;
-						surface->VertexCoords[0].x=x;
-						surface->VertexCoords[0].y=y;
-
-						surface->TextureCoords[1].s=Image->ImageCoord[1].s;
-						surface->TextureCoords[1].t=0;
-						surface->VertexCoords[1].x=x+Image->W;
-						surface->VertexCoords[1].y=y;
-
-						surface->TextureCoords[2].s=Image->ImageCoord[2].s;
-						surface->TextureCoords[2].t=Image->ImageCoord[2].t;
-						surface->VertexCoords[2].x=x+Image->W;
-						surface->VertexCoords[2].y=cy;
-
-						surface->TextureCoords[3].s=0;
-						surface->TextureCoords[3].t=Image->ImageCoord[3].t;
-						surface->VertexCoords[3].x=x;
-						surface->VertexCoords[3].y=cy;
-					}
-
-					//partial image at the end of x axis, only x axis is partial
-					ColorizableSurface *surface=Surfaces.Add();
-					surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-
-					surface->setTexture(Image);
-					surface->CreateTextureCoords();
-
-					surface->TextureCoords[0].s=0;
-					surface->TextureCoords[0].t=0;
-					surface->VertexCoords[0].x=x;
-					surface->VertexCoords[0].y=y;
-
-					surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
-					surface->TextureCoords[1].t=0;
-					surface->VertexCoords[1].x=X+W;
-					surface->VertexCoords[1].y=y;
-
-					surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
-					surface->TextureCoords[2].t=Image->ImageCoord[2].t;
-					surface->VertexCoords[2].x=X+W;
-					surface->VertexCoords[2].y=cy;
-
-					surface->TextureCoords[3].s=0;
-					surface->TextureCoords[3].t=Image->ImageCoord[2].t;
-					surface->VertexCoords[3].x=x;
-					surface->VertexCoords[3].y=cy;
-
-				}
-
-				//this part is the last partial row
-				//this is the partial texture coordinate
-				float pty=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
-				int cy=Y+H;
-				int x=X,tx=X+W-Image->W;
-				for(x=X;x<tx;x+=Image->W) {
-					//partial image in y axis
-					ColorizableSurface *surface=Surfaces.Add();
-					surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-
-					surface->setTexture(Image);
-					surface->CreateTextureCoords();
-
-					surface->TextureCoords[0].s=0;
-					surface->TextureCoords[0].t=0;
-					surface->VertexCoords[0].x=x;
-					surface->VertexCoords[0].y=y;
-
-					surface->TextureCoords[1].s=Image->ImageCoord[1].s;
-					surface->TextureCoords[1].t=0;
-					surface->VertexCoords[1].x=x+Image->W;
-					surface->VertexCoords[1].y=y;
-
-					surface->TextureCoords[2].s=Image->ImageCoord[2].s;
-					surface->TextureCoords[2].t=pty;
-					surface->VertexCoords[2].x=x+Image->W;
-					surface->VertexCoords[2].y=cy;
-
-					surface->TextureCoords[3].s=0;
-					surface->TextureCoords[3].t=pty;
-					surface->VertexCoords[3].x=x;
-					surface->VertexCoords[3].y=cy;
-				}
-
-				//partial image at the end of x axis at last row, both axis are partial
-				ColorizableSurface *surface=Surfaces.Add();
-				surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-
-				surface->setTexture(Image);
-				surface->CreateTextureCoords();
-
-				surface->TextureCoords[0].s=0;
-				surface->TextureCoords[0].t=0;
-				surface->VertexCoords[0].x=x;
-				surface->VertexCoords[0].y=y;
-
-				surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
-				surface->TextureCoords[1].t=0;
-				surface->VertexCoords[1].x=X+W;
-				surface->VertexCoords[1].y=y;
-
-				surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
-				surface->TextureCoords[2].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
-				surface->VertexCoords[2].x=X+W;
-				surface->VertexCoords[2].y=Y+H;
-
-				surface->TextureCoords[3].s=0;
-				surface->TextureCoords[3].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
-				surface->VertexCoords[3].x=x;
-				surface->VertexCoords[3].y=Y+H;
-
-			}
-		}
-	}
-
-	void Colorizable2DLayer::DrawHTiled(GLTexture *Image,int X,int Y,int W,int H) {
-		if(sl2(Image->W)==Image->W) { //both x axis is size of 2^n
-			//stretch and repeat as we need
-			ColorizableSurface *surface=Surfaces.Add();
-			surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-
-			surface->setTexture(Image);
-			surface->CreateTextureCoords();
-
-			surface->TextureCoords[0].s=0;
-			surface->TextureCoords[0].t=0;
-			surface->VertexCoords[0].x=X;
-			surface->VertexCoords[0].y=Y;
-
-			surface->TextureCoords[1].s=(float)W/Image->W;
-			surface->TextureCoords[1].t=0;
-			surface->VertexCoords[1].x=X+W;
-			surface->VertexCoords[1].y=Y;
-
-			surface->TextureCoords[2].s=(float)W/Image->W;
-			surface->TextureCoords[2].t=Image->ImageCoord[2].t;
-			surface->VertexCoords[2].x=X+W;
-			surface->VertexCoords[2].y=Y+H;
-
-			surface->TextureCoords[3].s=0;
-			surface->TextureCoords[3].t=Image->ImageCoord[2].t;
-			surface->VertexCoords[3].x=X;
-			surface->VertexCoords[3].y=Y+H;
-		} else {
-			//we leave at least a portion of an image to the last part
-			//so that there will be less controls
-			int x=X,tx=X+W-Image->W;
-			//draw whole parts where image is texture stretched in
-			//y axis, we only need to draw multiple images for x axis
-			for(x=X;x<tx;x+=Image->W) { 
-				ColorizableSurface *surface=Surfaces.Add();
-				surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-
-				surface->setTexture(Image);
-				surface->CreateTextureCoords();
-
-				surface->TextureCoords[0].s=0;
-				surface->TextureCoords[0].t=0;
-				surface->VertexCoords[0].x=x;
-				surface->VertexCoords[0].y=Y;
-
-				surface->TextureCoords[1].s=Image->ImageCoord[1].s;
-				surface->TextureCoords[1].t=0;
-				surface->VertexCoords[1].x=x+Image->W;
-				surface->VertexCoords[1].y=Y;
-
-				surface->TextureCoords[2].s=Image->ImageCoord[2].s;
-				surface->TextureCoords[2].t=Image->ImageCoord[2].t;
-				surface->VertexCoords[2].x=x+Image->W;
-				surface->VertexCoords[2].y=Y+H;
-
-				surface->TextureCoords[3].s=0;
-				surface->TextureCoords[3].t=Image->ImageCoord[2].t;
-				surface->VertexCoords[3].x=x;
-				surface->VertexCoords[3].y=Y+H;
-			}
-
-			//last image (might be partial)
-			ColorizableSurface *surface=Surfaces.Add();
-			surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-
-			surface->setTexture(Image);
-			surface->CreateTextureCoords();
-
-			surface->TextureCoords[0].s=0;
-			surface->TextureCoords[0].t=0;
-			surface->VertexCoords[0].x=x;
-			surface->VertexCoords[0].y=Y;
-
-			surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
-			surface->TextureCoords[1].t=0;
-			surface->VertexCoords[1].x=X+W;
-			surface->VertexCoords[1].y=Y;
-
-			surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
-			surface->TextureCoords[2].t=Image->ImageCoord[2].t;
-			surface->VertexCoords[2].x=X+W;
-			surface->VertexCoords[2].y=Y+H;
-
-			surface->TextureCoords[3].s=0;
-			surface->TextureCoords[3].t=Image->ImageCoord[2].t;
-			surface->VertexCoords[3].x=x;
-			surface->VertexCoords[3].y=Y+H;	
-		}
-	}
-
-	void Colorizable2DLayer::DrawVTiled(GLTexture *Image,int X,int Y,int W,int H) {
-		if(sl2(Image->H)==Image->H) { //both x axis is size of 2^n
-			//stretch and repeat as we need
-			ColorizableSurface *surface=Surfaces.Add();
-			surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-
-			surface->setTexture(Image);
-			surface->CreateTextureCoords();
-
-			surface->TextureCoords[0].s=0;
-			surface->TextureCoords[0].t=0;
-			surface->VertexCoords[0].x=X;
-			surface->VertexCoords[0].y=Y;
-
-			surface->TextureCoords[1].s=Image->ImageCoord[1].s;
-			surface->TextureCoords[1].t=0;
-			surface->VertexCoords[1].x=X+W;
-			surface->VertexCoords[1].y=Y;
-
-			surface->TextureCoords[2].s=Image->ImageCoord[2].s;
-			surface->TextureCoords[2].t=(float)H/Image->H;
-			surface->VertexCoords[2].x=X+W;
-			surface->VertexCoords[2].y=Y+H;
-
-			surface->TextureCoords[3].s=0;
-			surface->TextureCoords[3].t=(float)H/Image->H;
-			surface->VertexCoords[3].x=X;
-			surface->VertexCoords[3].y=Y+H;
-		} else {
-			//we leave at least a portion of an image to the last part
-			//so that there will be less controls
-			int y=Y,ty=Y+H-Image->H;
-			//draw whole parts where image is texture repeated in
-			//x axis, we only need to draw multiple images for y axis
-			for(y=Y;y<ty;y+=Image->H) {
-				ColorizableSurface *surface=Surfaces.Add();
-				surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-
-				surface->setTexture(Image);
-				surface->CreateTextureCoords();
-
-				surface->TextureCoords[0].s=0;
-				surface->TextureCoords[0].t=0;
-				surface->VertexCoords[0].x=X;
-				surface->VertexCoords[0].y=y;
-
-				surface->TextureCoords[1].s=Image->ImageCoord[1].s;
-				surface->TextureCoords[1].t=0;
-				surface->VertexCoords[1].x=X+W;
-				surface->VertexCoords[1].y=y;
-
-				surface->TextureCoords[2].s=Image->ImageCoord[2].s;
-				surface->TextureCoords[2].t=Image->ImageCoord[2].t;
-				surface->VertexCoords[2].x=X+W;
-				surface->VertexCoords[2].y=y+Image->H;
-
-				surface->TextureCoords[3].s=0;
-				surface->TextureCoords[3].t=Image->ImageCoord[3].t;
-				surface->VertexCoords[3].x=X;
-				surface->VertexCoords[3].y=y+Image->H;
-			}
-
-			//last image (might be partial)
-			ColorizableSurface *surface=Surfaces.Add();
-			surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
-
-			surface->setTexture(Image);
-			surface->CreateTextureCoords();
-
-			surface->TextureCoords[0].s=0;
-			surface->TextureCoords[0].t=0;
-			surface->VertexCoords[0].x=X;
-			surface->VertexCoords[0].y=y;
-
-			surface->TextureCoords[1].s=Image->ImageCoord[1].s;
-			surface->TextureCoords[1].t=0;
-			surface->VertexCoords[1].x=X+W;
-			surface->VertexCoords[1].y=y;
-
-			surface->TextureCoords[2].s=Image->ImageCoord[2].s;
-			surface->TextureCoords[2].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
-			surface->VertexCoords[2].x=X+W;
-			surface->VertexCoords[2].y=Y+H;
-
-			surface->TextureCoords[3].s=0;
-			surface->TextureCoords[3].t=Image->ImageCoord[3].t*((float)(H-(y-Y))/Image->H);
-			surface->VertexCoords[3].x=X;
-			surface->VertexCoords[3].y=Y+H;
-		}
-	}
-
-	void Basic2DRawGraphicsLayer::Draw(Byte *Image, int Width, int Height, ColorMode Mode, int X1, int Y1, int X2, int Y2, int X3, int Y3, int X4, int Y4) {
-		RawSurface *surface=Surfaces.Add();
-
-		surface->Data=Image;
-		surface->Mode=Mode;
-		surface->CreateTextureCoords();
-		surface->Width=Width;
-		surface->Height=Height;
-
-
-		surface->TextureCoords[0].s=0;
-		surface->TextureCoords[0].t=0;
-		surface->TextureCoords[1].s=(float)Width/sl2(Width);
-		surface->TextureCoords[1].t=0;
-		surface->TextureCoords[2].s=(float)Width/sl2(Width);
-		surface->TextureCoords[2].t=(float)Height/sl2(Height);
-		surface->TextureCoords[3].s=0;
-		surface->TextureCoords[3].t=(float)Height/sl2(Height);
-
-		surface->VertexCoords[0].x=X1;
-		surface->VertexCoords[0].y=Y1;
-
-		surface->VertexCoords[1].x=X2;
-		surface->VertexCoords[1].y=Y2;
-
-		surface->VertexCoords[2].x=X3;
-		surface->VertexCoords[2].y=Y3;
-
-		surface->VertexCoords[3].x=X4;
-		surface->VertexCoords[3].y=Y4;
-	}
-	void Basic2DRawGraphicsLayer::Render() {
-		Rectangle psc;
-		if(!isVisible) return;
-		glPushAttrib(GL_SCISSOR_BIT);
-
-		glPushMatrix();
-		glTranslatef(BoundingBox.Left, BoundingBox.Top, 0);
-		translate+=BoundingBox.TopLeft();
-
-		if(EnableClipping) {
-			psc=scissors;
-
-			int r=scissors.Right();
-			int b=scissors.Bottom();
-
-			glEnable(GL_SCISSOR_TEST);
-			if(translate.x>scissors.Left)
-				scissors.Left=translate.x;
-			if(translate.y>scissors.Top)
-				scissors.Top=translate.y;
-			if(translate.y+BoundingBox.Height()<b)
-				b=(translate.y+BoundingBox.Height());
-			if(translate.x+BoundingBox.Width()<r)
-				r=(translate.x+BoundingBox.Width());
-
-			scissors.SetRight(r);
-			scissors.SetBottom(b);
-
-			if(r<=scissors.Left || b<=scissors.Top) {
-				return;
-			}
-
-			glScissor(scissors.Left, (ScreenSize.Height-scissors.Top)-scissors.Height, scissors.Width, scissors.Height);
-		}
-
-		int i;
-		for(i=0;i<Surfaces.getCount();i++) {
-			RawSurface *surface=Surfaces[i];
-			glBindTexture(GL_TEXTURE_2D, NULL);
-			SetTexture(surface->Data, surface->Width, surface->Height, surface->Mode);
-
-			glBegin(GL_QUADS);
-			glTexCoord2fv(surface->TextureCoords[0].vect);
-			glVertex3fv(surface->VertexCoords[0].vect);
-			glTexCoord2fv(surface->TextureCoords[1].vect);
-			glVertex3fv(surface->VertexCoords[1].vect);
-			glTexCoord2fv(surface->TextureCoords[2].vect);
-			glVertex3fv(surface->VertexCoords[2].vect);
-			glTexCoord2fv(surface->TextureCoords[3].vect);
-			glVertex3fv(surface->VertexCoords[3].vect);
-			glEnd();
-		}
-
-
-		for(utils::SortedCollection<LayerBase>::Iterator i=SubLayers.Last(); i.isValid(); i.Previous()) {
-			i->Render();
-		}
-
-		glPopMatrix();
-		translate-=BoundingBox.TopLeft();
-
-		if(EnableClipping) {
-			scissors=psc;
-		}
-
-		glPopAttrib();
-
-	}
 } }
--- a/Engine/GraphicLayers.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Engine/GraphicLayers.h	Tue Jul 26 09:55:07 2011 +0000
@@ -4,6 +4,7 @@
 #include "Layer.h"
 #include "../Utils/PAClassList.h"
 #include "Graphics.h"
+#include "GraphicTargets2D.h"
 
 namespace gge { namespace graphics {
 	////_private
@@ -14,13 +15,13 @@
 	////_private
 	struct RawSurface : public BasicSurface {
 		Byte *Data;
-		ColorMode Mode;
+		ColorMode::Type Mode;
 		int Width;
 		int Height;
 	};
 
 	////This layer is a basic 2D graphics target
-	class Basic2DLayer : public LayerBase, public I2DGraphicsTarget {
+	class Basic2DLayer : public LayerBase, public ImageTarget2D {
 	public:
 		////This list contains surfaces to be drawn
 		PAClassList<BasicSurface> Surfaces;
@@ -57,30 +58,54 @@
 		///@X4		: bottom-left corner
 		///@Y4		: bottom-left corner
 		virtual void Draw(GLTexture *Image,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4);
+
+		virtual void Draw(GLTexture *Image,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4);
+
+		virtual void Draw(GLTexture *Image, int X, int Y, int W, int H) { Draw(Image, X,Y, X+W,Y, X+W,Y+H, X,Y+H); }
+
+		virtual void Draw(GLTexture *Image, Tiling2D::Type Tiling, int X, int Y, int W, int H) {
+			switch(Tiling) {
+			case Tiling2D::None:
+				Draw(Image,X,Y, W,H);
+				break;
+			case Tiling2D::Horizontal:
+				DrawHTiled(Image,X,Y, W,H);
+				break;
+			case Tiling2D::Vertical:
+				DrawVTiled(Image,X,Y, W,H);
+				break;
+			case Tiling2D::Both:
+				DrawTiled(Image,X,Y, W,H);
+				break;
+			}
+		}
+
 		////Draws a tiled image to the screen
 		///@Image	: image texture to be drawn, this can be obtained
 		/// using generate texture function
-		virtual void DrawTiled(GLTexture *Image,int X,int Y,int W,int H);
+		void DrawTiled(GLTexture *Image,int X,int Y,int W,int H);
 		////Draws a horizontally tiled image to the screen
 		///@Image	: image texture to be drawn, this can be obtained
 		/// using generate texture function
-		virtual void DrawHTiled(GLTexture *Image,int X,int Y,int W,int H);
+		void DrawHTiled(GLTexture *Image,int X,int Y,int W,int H);
 		////Draws a vertically tiled image to the screen
 		///@Image	: image texture to be drawn, this can be obtained
 		/// using generate texture function
 		///@W		: the width of the image to be drawn
 		/// if it is more than the size of the image
-		virtual void DrawVTiled(GLTexture *Image,int X,int Y,int W,int H);
+		void DrawVTiled(GLTexture *Image,int X,int Y,int W,int H);
+
 		////Renders the current layer, default handling is to pass
 		/// the request to the sub-layers
 		virtual void Render();
 		virtual void Clear() { Surfaces.Clear(); }
 
-		virtual int Width() { return BoundingBox.Width(); }
-		virtual int Height() { return BoundingBox.Height(); }
+		virtual int GetWidth() const { return BoundingBox.Width(); }
+		virtual int GetHeight() const { return BoundingBox.Height(); }
 	};
+
 	////This layer is a 2D graphics target and also has colorization support
-	class Colorizable2DLayer : public I2DColorizableGraphicsTarget, public LayerBase {
+	class Colorizable2DLayer : public ColorizableImageTarget2D, public LayerBase {
 	public:
 		////Whether or not enable clipping
 		bool EnableClipping;
@@ -98,6 +123,7 @@
 
 		void init() {
 			Ambient=RGBint(0xffffffff);
+			CurrentColor=RGBint(0xffffffff);
 			isVisible=true;
 			EnableClipping=false;
 		}
@@ -118,58 +144,63 @@
 		///@Y3		: bottom-right corner
 		///@X4		: bottom-left corner
 		///@Y4		: bottom-left corner
-		///@Color	: color
-		virtual void Draw(GLTexture *Image,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4, RGBint Color);
 		virtual void Draw(GLTexture *Image,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4);
-		virtual void Render();
-		virtual void Clear() { Surfaces.Clear(); }
+
+		virtual void Draw(GLTexture *Image,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4);
+
+		virtual void Draw(GLTexture *Image, int X, int Y, int W, int H) { Draw(Image, X,Y, X+W,Y, X+W,Y+H, X,Y+H); }
+
+		virtual void Draw(GLTexture *Image, Tiling2D::Type Tiling, int X, int Y, int W, int H) {
+			switch(Tiling) {
+			case Tiling2D::None:
+				Draw(Image,X,Y, W,H);
+				break;
+			case Tiling2D::Horizontal:
+				DrawHTiled(Image,X,Y, W,H);
+				break;
+			case Tiling2D::Vertical:
+				DrawVTiled(Image,X,Y, W,H);
+				break;
+			case Tiling2D::Both:
+				DrawTiled(Image,X,Y, W,H);
+				break;
+			}
+		}
+
 		////Draws a tiled image to the screen
 		///@Image	: image texture to be drawn, this can be obtained
 		/// using generate texture function
-		virtual void DrawTiled(GLTexture *Image,int X,int Y,int W,int H);
+		void DrawTiled(GLTexture *Image,int X,int Y,int W,int H);
 		////Draws a horizontally tiled image to the screen
 		///@Image	: image texture to be drawn, this can be obtained
 		/// using generate texture function
-		virtual void DrawHTiled(GLTexture *Image,int X,int Y,int W,int H);
+		void DrawHTiled(GLTexture *Image,int X,int Y,int W,int H);
 		////Draws a vertically tiled image to the screen
 		///@Image	: image texture to be drawn, this can be obtained
 		/// using generate texture function
 		///@W		: the width of the image to be drawn
 		/// if it is more than the size of the image
-		virtual void DrawVTiled(GLTexture *Image,int X,int Y,int W,int H);
+		void DrawVTiled(GLTexture *Image,int X,int Y,int W,int H);
+
+
 
-		virtual int Width() { return BoundingBox.Width(); }
-		virtual int Height() { return BoundingBox.Height(); }
-	};
-	class Basic2DRawGraphicsLayer : public I2DRawGraphicsTarget, public LayerBase {
-	public:
-		////Whether or not enable clipping
-		bool EnableClipping;
-		////This list contains surfaces to be drawn
-		PAClassList<RawSurface> Surfaces;
+		////Renders the current layer, default handling is to pass
+		/// the request to the sub-layers
+		virtual void Render();
+		virtual void Clear() { Surfaces.Clear(); }
+
 
-		////Draws a given data to the screen
-		virtual void Draw(Byte *Image, int Width, int Height, ColorMode Mode,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4);
-	
-		void init() {
-			isVisible=true;
-			EnableClipping=false;
-		}
+		virtual int GetWidth() const { return BoundingBox.Width(); }
+		virtual int GetHeight() const { return BoundingBox.Height(); }
 
-		Basic2DRawGraphicsLayer() : LayerBase() { init(); }
+		RGBint Ambient;
 
-		Basic2DRawGraphicsLayer(const utils::Bounds &b) : LayerBase(b) { init(); }
-
-		Basic2DRawGraphicsLayer(int L, int T, int R, int B) : LayerBase(L,T,R,B) { init(); }
-
-		Basic2DRawGraphicsLayer(int X,int Y) : LayerBase(X,Y) { init(); }
+		virtual void SetCurrentColor(RGBint color) { CurrentColor=color; }
+		virtual void SetCurrentColor(RGBfloat color) { CurrentColor=color; }
+		virtual RGBint GetCurrentColor() { return CurrentColor; }
 
-		Basic2DRawGraphicsLayer(const utils::Point &p) : LayerBase(p) { init(); }
-
-		////Renders this layer
-		virtual void Render();
-		////Clear the contents of the layer
-		virtual void Clear() { Surfaces.Clear(); }
+	protected:
+		RGBfloat CurrentColor;
 	};
 
 } }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/GraphicTargets2D.h	Tue Jul 26 09:55:07 2011 +0000
@@ -0,0 +1,64 @@
+#pragma once
+#include "Graphics.h"
+
+
+namespace gge { namespace graphics {
+
+	////This interface defines a class that can be used
+	/// as a common target for images
+	class ImageTarget2D {
+	public:
+		////Draws a simple image to the screen.
+		/// In this draw function every corner can be specified
+		/// thus various transformations can be made
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		///@X1		: top-left corner
+		///@Y1		: top-left corner
+		///@X2		: top-right corner
+		///@Y2		: top-right corner
+		///@X3		: bottom-right corner
+		///@Y3		: bottom-right corner
+		///@X4		: bottom-left corner
+		///@Y4		: bottom-left corner
+		virtual void Draw(GLTexture *Image,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4) = 0;
+
+		virtual void Draw(GLTexture *Image,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) = 0;
+
+		////Draws a simple image to the screen.
+		/// This function does not support any transformations
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		virtual void Draw(GLTexture *Image, int X, int Y, int W, int H) = 0;
+
+		////Draws a simple image to the screen.
+		/// This function does not support any transformations
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		virtual void Draw(GLTexture *Image, Tiling2D::Type Tiling, int X, int Y, int W, int H) = 0;
+
+		////Clears drawing buffer, in layer architecture this request only affects
+		/// the layer itself, not sub-layers
+		virtual void Clear()=0;
+
+		////Size of the target
+		virtual int GetWidth() const  = 0;
+		virtual int GetHeight() const = 0;
+
+		utils::Size GetSize() { 
+			return utils::Size(GetWidth(), GetHeight()); 
+		}
+	};
+
+	class ColorizableTarget {
+	public:
+		virtual void SetCurrentColor(RGBint color) = 0;
+		virtual void SetCurrentColor(RGBfloat color) = 0;
+
+		virtual RGBint GetCurrentColor() = 0;
+	};
+
+	class ColorizableImageTarget2D : public ImageTarget2D, public ColorizableTarget {
+	};
+
+} }
--- a/Engine/Graphics.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Engine/Graphics.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -90,145 +90,152 @@
 
 		return (os::DeviceHandle)hDC;
 	}
-	void A8ToA8L8(int cx,int cy,Byte *data,Byte *dest)
-	{
-		int icx=cx,icy=cy;
-		
-		__asm {
-			; A8 (actually saved as a) data to 
-			; A8L8
+
+	namespace system {
+		void A8ToA8L8(int cx,int cy,Byte *data,Byte *dest)
+		{
+			int icx=cx,icy=cy;
+
+			__asm {
+				; A8 (actually saved as a) data to 
+					; A8L8
 
-			; push everything so we can use them at will
-			push edi		; destination array
-			push esi		; source array
-			push ecx		; x
-			push edx		; y
-			push ebx		; temp
-			
-			mov  edi,dest	; destination data
-			mov  esi,data	; source data
+					; push everything so we can use them at will
+					push edi		; destination array
+					push esi		; source array
+					push ecx		; x
+					push edx		; y
+					push ebx		; temp
+
+					mov  edi,dest	; destination data
+					mov  esi,data	; source data
 
 
-			mov edx,0		; y=0
-loopystart:
-			cmp edx,[icy]	; if y=cy
-			je loopyend		; break y loop
+					mov edx,0		; y=0
+	loopystart:
+				cmp edx,[icy]	; if y=cy
+					je loopyend		; break y loop
 
-			mov ecx,0		; x=0
-loopxstart:
-			cmp ecx,[icx]	; if x=cx
-			je loopxend		; break x loop
-			
-			mov byte ptr[edi],0xff
-			inc edi
+					mov ecx,0		; x=0
+	loopxstart:
+				cmp ecx,[icx]	; if x=cx
+					je loopxend		; break x loop
+
+					mov byte ptr[edi],0xff
+					inc edi
+
+					movsb
 
-			movsb
+					inc ecx			; x++
+					jmp loopxstart	; next
+	loopxend:
+				inc edx			; y++
+					jmp loopystart	; next
+	loopyend:
 
-			inc ecx			; x++
-			jmp loopxstart	; next
-loopxend:
-			inc edx			; y++
-			jmp loopystart	; next
-loopyend:
-
-			; restore everything
-			pop ebx
-			pop ecx
-			pop edx
-			pop esi
-			pop edi
+				; restore everything
+					pop ebx
+					pop ecx
+					pop edx
+					pop esi
+					pop edi
+			}
 		}
-	}
-	void SetTexture(Byte *data, int cx, int cy, ColorMode mode) {
-		GLenum colormode=getGLColorMode(mode);
-
-		Byte *target=NULL;
+		GLenum getGLColorMode(ColorMode::Type color_mode) {
+			switch(color_mode) {
+			case ColorMode::Alpha:
+				return GL_ALPHA;
+			case ColorMode::Grayscale_Alpha:
+				return GL_LUMINANCE_ALPHA;
+			case ColorMode::BGR:
+				return GL_BGR;
+			case ColorMode::RGB:
+				return GL_RGB;
+			case ColorMode::ABGR:
+				return GL_RGBA;
+			case ColorMode::ARGB:
+				return GL_BGRA;
+			default:
+				return GL_BGRA;
+			}
+		}
+		void SetTexture(Byte *data, int cx, int cy, ColorMode::Type mode) {
+			GLenum colormode=getGLColorMode(mode);
 
-		///*Setting Texture Parameters to
-		/// Magnify filter: Linear,
-		/// Minify filter:  Linear,
-		/// Border color:   Transparent
-		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BORDER_COLOR, 0x0);
+			Byte *target=NULL;
+
+			///*Setting Texture Parameters to
+			/// Magnify filter: Linear,
+			/// Minify filter:  Linear,
+			/// Border color:   Transparent
+			glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+			glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BORDER_COLOR, 0x0);
 
-		if(mode==ALPHAONLY_8BPP) {
-			///*If alpha only, converted to grayscale alpha
-			glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
-			glPixelStorei(GL_PACK_ALIGNMENT, 2);
+			if(mode==ColorMode::Alpha) {
+				///*If alpha only, converted to grayscale alpha
+				glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
+				glPixelStorei(GL_PACK_ALIGNMENT, 2);
+
+				target=new Byte[cx*cy*2];	
+				A8ToA8L8(cx,cy,data,target);
+				delete data;
+				data=target;
 
-			target=new Byte[cx*cy*2];	
-			A8ToA8L8(cx,cy,data,target);
-			delete data;
-			data=target;
+				mode=ColorMode::Grayscale_Alpha;
+				colormode=GL_LUMINANCE_ALPHA;
+			} else {
+				glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
+				glPixelStorei(GL_PACK_ALIGNMENT, 4);
+			}
 
-			mode=AGRAYSCALE_16BPP;
-			colormode=GL_LUMINANCE_ALPHA;
-		} else {
-			glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
-			glPixelStorei(GL_PACK_ALIGNMENT, 4);
+			glTexImage2D(GL_TEXTURE_2D,0,getBPP(mode),sl2(cx),sl2(cy),0,colormode,GL_UNSIGNED_BYTE,NULL);
+			glTexSubImage2D(GL_TEXTURE_2D,0,0,0,cx,cy,colormode,GL_UNSIGNED_BYTE,data);
+		}
+		GLTexture GenerateTexture(Byte *data,int cx,int cy,ColorMode::Type mode) {
+
+			GLTexture ret;
+			ret.CalcuateCoordinates(cx,cy);
+
+			///*Create the texture object
+			glGenTextures(1,&ret.ID);
+			glBindTexture(GL_TEXTURE_2D,ret.ID);
+
+			SetTexture(data,cx,cy,mode);
+
+			return ret;
 		}
 
-		glTexImage2D(GL_TEXTURE_2D,0,getBPP(mode),sl2(cx),sl2(cy),0,colormode,GL_UNSIGNED_BYTE,NULL);
-		glTexSubImage2D(GL_TEXTURE_2D,0,0,0,cx,cy,colormode,GL_UNSIGNED_BYTE,data);
-	}
-	GLTexture GenerateTexture(Byte *data,int cx,int cy,ColorMode mode) {
-
-		GLTexture ret;
-		ret.CalcuateCoordinates(cx,cy);
+		void DestroyTexture(GLTexture *texture) {
+			glDeleteTextures(1, &texture->ID);
+			texture->ID=0;
+		}
 
-		///*Create the texture object
-		glGenTextures(1,&ret.ID);
-		glBindTexture(GL_TEXTURE_2D,ret.ID);
-
-		SetTexture(data,cx,cy,mode);
-
-		return ret;
-	}
+		void PreRender() {
+			///*Resetting OpenGL parameters
+			glDisable(GL_SCISSOR_TEST);
+			glMatrixMode(GL_MODELVIEW);
+			glLoadIdentity();
 
-	void DestroyTexture(GLTexture *texture) {
-		glDeleteTextures(1, &texture->ID);
-		texture->ID=0;
-	}
+			///*Clearing buffers
+			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+			CurrentLayerColor.a=1;
+			CurrentLayerColor.r=1;
+			CurrentLayerColor.g=1;
+			CurrentLayerColor.b=1;
 
-	GLenum getGLColorMode(ColorMode color_mode) {
-		switch(color_mode) {
-		case ALPHAONLY_8BPP:
-			return GL_ALPHA;
-		case AGRAYSCALE_16BPP:
-			return GL_LUMINANCE_ALPHA;
-		case RGB:
-			return GL_BGR;
-		case BGR:
-			return GL_RGB;
-		case ABGR_32BPP:
-			return GL_RGBA;
-		case ARGB_32BPP:
-			return GL_BGRA;
-		default:
-			return GL_BGRA;
+			translate=Point(0,0);
+			scissors=utils::Rectangle(0, 0, ScreenSize);
+		}
+
+		void PostRender(os::DeviceHandle hDC) {
+			///*Swapping back and front buffers
+			SwapBuffers( (HDC)hDC );
 		}
 	}
 
-	void PreRender() {
-		///*Resetting OpenGL parameters
-		glDisable(GL_SCISSOR_TEST);
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
+	const SizeController2D SizeController2D::TileFit;
+	const SizeController2D SizeController2D::StretchFit;
 
-		///*Clearing buffers
-		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-		CurrentLayerColor.a=1;
-		CurrentLayerColor.r=1;
-		CurrentLayerColor.g=1;
-		CurrentLayerColor.b=1;
 
-		translate=Point(0,0);
-		scissors=utils::Rectangle(0, 0, ScreenSize);
-	}
-
-	void PostRender(os::DeviceHandle hDC) {
-		///*Swapping back and front buffers
-		SwapBuffers( (HDC)hDC );
-	}
 } }
--- a/Engine/Graphics.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Engine/Graphics.h	Tue Jul 26 09:55:07 2011 +0000
@@ -38,57 +38,34 @@
 	union VertexPosition { struct{float x,y,z;};float vect[3];};
 
 	////GGE Color mode constants
-	enum ColorMode {
-		////RGB base color mode
-		RGB = 1,
-		////Palleted base color mode
-		PALLETTED = 2,
-		////Gray base color mode
-		GRAY = 4,
-		////Alpha base color mode
-		ALPHA = 8,
-		////BGR base color mode
-		BGR = 16,
-		////4-byte RGB color with alpha
-		ARGB_32BPP = RGB | ALPHA,
-		////4-byte revered RGB color with alpha
-		ABGR_32BPP = BGR | ALPHA,
-		////1-byte palleted color mode, is not available yet
-		PALLETTED_8BPP = PALLETTED,
-		////2-byte palleted color mode with alpha, is not available yet
-		APALLETTED_16BPP = PALLETTED | ALPHA,
-		////1-byte alpha only color mode, converted to AGRAYSCALE_16BPP
-		ALPHAONLY_8BPP = ALPHA,
-		////1-byte gray (luminance) only color mode, is not available yet
-		GRAYSCALE_8BPP = GRAY,
-		////2-byte gray (luminance) color mode with alpha
-		AGRAYSCALE_16BPP = GRAY | ALPHA
+	namespace ColorMode {
+		enum Type {
+			////RGB base color mode
+			RGB = 1,
+			////Palleted base color mode
+			Palleted = 2,
+			////Gray base color mode
+			Grayscale = 4,
+			////Alpha base color mode
+			Alpha = 8,
+			////BGR base color mode
+			BGR = 16,
+			////4-byte RGB color with alpha
+			ARGB = RGB | Alpha,
+			////4-byte revered RGB color with alpha
+			ABGR = BGR | Alpha,
+			////2-byte palleted color mode with alpha, is not available yet
+			Palleted_Alpha = Palleted | Alpha,
+			////2-byte gray (luminance) color mode with alpha
+			Grayscale_Alpha = Grayscale | Alpha
+		};
 	};
 
-	////Logarithm Base 2
-	inline int log2(int num) {
-		int i=0;
-		int s=1;
-		while(num-s>0) {
-			i++;
-			s<<=1;
-		}
-
-		return i;
+	namespace system {
+		int sl2(int num);
+		int log2(int num);
 	}
 
-	////Rounds the given number to the lowest 2^n (where n is integer) number 
-	/// that is higher than the given number
-	inline int sl2(int num) {
-		int s=1;
-		while(num-s>0) {
-			s<<=1;
-		}
-
-		return s;
-	}
-
-
 	////This structure contains all necessary information
 	/// of a texture. Using this information, image can be
 	/// drawn without requiring its actual size.
@@ -119,8 +96,8 @@
 		void CalcuateCoordinates(int W,int H) {
 			this->W=W;
 			this->H=H;
-			TW=sl2(W);//+0.0001
-			TH=sl2(H);//+0.0001
+			TW=system::sl2(W);//+0.0001
+			TH=system::sl2(H);//+0.0001
 			S=(float)W/TW;
 			T=(float)H/TH;
 
@@ -135,7 +112,10 @@
 		}
 	};
 
+	struct RGBint;
+
 	union RGBfloat {
+		RGBfloat(const RGBint &);
 		RGBfloat() { }
 		RGBfloat(float a, float r, float g, float b) : a(a), r(r), g(g), b(b) { }
 
@@ -157,6 +137,12 @@
 			float a;
 		};
 
+		bool operator ==(const RGBfloat &c) const {
+			return a==c.a && r==c.r && g==c.g && b==c.b;
+		}
+
+		RGBfloat &operator =(const RGBint &c);
+
 		float vect[4];
 	};
 
@@ -330,6 +316,22 @@
 		return stream;
 	}
 
+	inline RGBfloat::RGBfloat(const RGBint &c) {
+		a=(float)c.a/255;
+		r=(float)c.r/255;
+		g=(float)c.g/255;
+		b=(float)c.b/255;
+	}
+
+	inline RGBfloat &RGBfloat::operator =(const RGBint &c) {
+		a=(float)c.a/255;
+		r=(float)c.r/255;
+		g=(float)c.g/255;
+		b=(float)c.b/255;
+
+		return *this;
+	}
+
 	////Color range definition from one color
 	/// to another, this also includes alpha
 	struct RGBRangeint {
@@ -421,413 +423,139 @@
 	inline RGBint ToRGBint(int argb) { RGBint r(argb); return r; }
 
 	////Returns the Bytes required for a given color mode
-	inline int getBPP(ColorMode color_mode) {
+	inline int getBPP(ColorMode::Type color_mode) {
 		switch(color_mode) {
-		case GRAYSCALE_8BPP:
-		case PALLETTED_8BPP:
-		case ALPHAONLY_8BPP:
+		case ColorMode::Grayscale:
+		case ColorMode::Alpha:
+		case ColorMode::Palleted:
 			return 1;
-		case APALLETTED_16BPP:
-		case AGRAYSCALE_16BPP:
+		case ColorMode::Palleted_Alpha:
+		case ColorMode::Grayscale_Alpha:
 			return 2;
-		case RGB:
+		case ColorMode::RGB:
+		case ColorMode::BGR:
 			return 3;
 		default:
 			return 4;
 		}
 	}
 
-	////This interface defines a class that can be used
-	/// as a common drawing target
-	class I2DGraphicsTarget {
-	public:
-		////Draws a simple image to the screen.
-		/// In this draw function every corner can be specified
-		/// thus various transformations can be made
-		///@Image	: image texture to be drawn, this can be obtained
-		/// using generate texture function
-		///@X1		: top-left corner
-		///@Y1		: top-left corner
-		///@X2		: top-right corner
-		///@Y2		: top-right corner
-		///@X3		: bottom-right corner
-		///@Y3		: bottom-right corner
-		///@X4		: bottom-left corner
-		///@Y4		: bottom-left corner
-		virtual void Draw(GLTexture *Image,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4)=0;
-		////Draws a simple image to the screen.
-		/// This function supports scaling.
-		///@Image	: image texture to be drawn, this can be obtained
-		/// using generate texture function
-		inline virtual void Draw(GLTexture *Image,int X,int Y,int W,int H) { Draw(Image,X,Y,X+W,Y,X+W,Y+H,X,Y+H); }
-		////Draws a simple image to the screen.
-		/// This function does not support any transformations
-		///@Image	: image texture to be drawn, this can be obtained
-		/// using generate texture function
-		inline virtual void Draw(GLTexture *Image,int X,int Y) { Draw(Image,X,Y,X+Image->W,Y,X+Image->W,Y+Image->H,X,Y+Image->H); }
-		////Draws a tiled image to the screen
-		///@Image	: image texture to be drawn, this can be obtained
-		/// using generate texture function
-		virtual void DrawTiled(GLTexture *Image,int X,int Y,int W,int H)=0;
-		////Draws a horizontally tiled image to the screen
-		///@Image	: image texture to be drawn, this can be obtained
-		/// using generate texture function
-		virtual void DrawHTiled(GLTexture *Image,int X,int Y,int W,int H)=0;
-		////Draws a vertically tiled image to the screen
-		///@Image	: image texture to be drawn, this can be obtained
-		/// using generate texture function
-		///@W		: the width of the image to be drawn
-		/// if it is more than the size of the image
-		virtual void DrawVTiled(GLTexture *Image,int X,int Y,int W,int H)=0;
-		////Clears drawing buffer, in layer architecture this request only affects
-		/// the layer itself, not sub-layers
-		virtual void Clear()=0;
-
-		virtual int Width()  =0;
-		virtual int Height() =0;
-	};
-
-	////This is a graphics target with colorization support
-	class I2DColorizableGraphicsTarget : public I2DGraphicsTarget {
+	class Tiling2D {
 	public:
-		////Global ambient color of this layer
-		RGBint Ambient;
-		////Draws a simple image to the screen.
-		/// In this draw function every corner can be specified
-		/// thus various transformations can be made
-		///@Image	: image texture to be drawn, this can be obtained
-		/// using generate texture function
-		///@X1		: top-left corner
-		///@Y1		: top-left corner
-		///@X2		: top-right corner
-		///@Y2		: top-right corner
-		///@X3		: bottom-right corner
-		///@Y3		: bottom-right corner
-		///@X4		: bottom-left corner
-		///@Y4		: bottom-left corner
-		virtual void Draw(GLTexture *Image,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4, RGBint Color)=0;
-		////Draws a simple image to the screen.
-		/// This function supports scaling.
-		///@Image	: image texture to be drawn, this can be obtained
-		/// using generate texture function
-		inline virtual void Draw(GLTexture *Image,int X,int Y,int W,int H, RGBint Color) { Draw(Image,X,Y,X+W,Y,X+W,Y+H,X,Y+H,Color); }
-		////Draws a simple image to the screen.
-		/// This function does not support any transformations
-		///@Image	: image texture to be drawn, this can be obtained
-		/// using generate texture function
-		inline virtual void Draw(GLTexture *Image,int X,int Y, RGBint Color) { Draw(Image,X,Y,X+Image->W,Y,X+Image->W,Y+Image->H,X,Y+Image->H,Color); }
-	};
-
-	class I2DRawGraphicsTarget {
-	public:
-		////Draws a simple image to the screen.
-		/// In this draw function every corner can be specified
-		/// thus various transformations can be made
-		///@Image	: image texture to be drawn, this can be obtained
-		/// using generate texture function
-		///@X1		: top-left corner
-		///@Y1		: top-left corner
-		///@X2		: top-right corner
-		///@Y2		: top-right corner
-		///@X3		: bottom-right corner
-		///@Y3		: bottom-right corner
-		///@X4		: bottom-left corner
-		///@Y4		: bottom-left corner
-		virtual void Draw(Byte *Image, int Width, int Height, ColorMode Mode,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4)=0;
-		////Draws a simple image to the screen.
-		/// This function supports scaling.
-		///@Image	: image texture to be drawn, this can be obtained
-		/// using generate texture function
-		_inline virtual void Draw(Byte *Image, int Width, int Height, ColorMode Mode,int X,int Y,int W,int H) { Draw(Image,Width,Height,Mode,X,Y,X+W,Y,X+W,Y+H,X,Y+H); }
-		////Draws a simple image to the screen.
-		/// This function does not support any transformations
-		///@Image	: image texture to be drawn, this can be obtained
-		/// using generate texture function
-		_inline virtual void Draw(Byte *Image, int Width, int Height, ColorMode Mode,int X,int Y) { Draw(Image,Width,Height,Mode,X,Y,X+Width,Y,X+Width,Y+Height,X,Y+Height); }
-	};
-	////This is a basic drawing object
-	class Buffered2DGraphic {
-	public:
-		GLTexture Texture;
-
-		enum TilingDirection {
-			None,
-			Horizontal=1,
-			Vertical=2,
-			Both=3,
+		enum Type {
+			None		= 0,
+			Horizontal	= 1, 
+			Vertical	= 2,
+			Both		= 3,
 		};
 
-		static TilingDirection Tiling(bool H, bool V) {
-			if(H) {
-				if(V)
-					return Both;
-				else
-					return Horizontal;
-			} else {
-				if(V)
-					return Vertical;
-				else
-					return None;
-			} 
-		}
-
-		Buffered2DGraphic() { Texture.ID=0; }
-
-		////Draws this object to the given target
-		///@Target	: The target that will be used to draw
-		/// this image
-		virtual void Draw(I2DGraphicsTarget *Target,utils::Point pnt) { 
-			Draw(Target, pnt.x, pnt.y, Texture.W, Texture.H);
-		}
-		////Draws this object to the given target
-		///@Target	: The target that will be used to draw
-		/// this image
-		virtual void Draw(I2DGraphicsTarget &Target,utils::Point pnt) { 
-			Draw(Target, pnt.x, pnt.y, Texture.W, Texture.H);
-		}
-		virtual void Draw(I2DGraphicsTarget *Target,int X,int Y) { 
-			Draw(Target, X, Y, Texture.W, Texture.H);
-		}
-		virtual void Draw(I2DGraphicsTarget &Target,int X,int Y) { Draw(&Target, X,Y); }
-
-
-		////Draws this object to the given target with the specified size
-		///@Target	: The target that will be used to draw
-		/// this image
-		virtual void Draw(I2DGraphicsTarget *Target,int X,int Y,int W,int H) { 
-#ifdef _DEBUG
-			if(Texture.ID==0)
-				std::runtime_error("Invalid texture ID, image is not initialized in tiled draw.");
-			if(Target==NULL)
-				std::runtime_error("Target is NULL");
-#endif
-			Target->Draw(&Texture, X, Y, W, H);
-		}
-		virtual void Draw(I2DGraphicsTarget &Target,int X,int Y,int W,int H) { Draw(&Target, X,Y, W,H); }
-
-
-		////Draws this object to the given target with the specified size
-		///@Target	: The target that will be used to draw
-		/// this image
-		virtual void Draw(I2DGraphicsTarget *Target,int X1,int Y1, int X2,int Y2, int X3,int Y3, int X4, int Y4) { 
-#ifdef _DEBUG
-			if(Texture.ID==0)
-				std::runtime_error("Invalid texture ID, image is not initialized in tiled draw.");
-			if(Target==NULL)
-				std::runtime_error("Target is NULL");
-#endif
-			Target->Draw(&Texture, X1,Y1, X2,Y2, X3,Y3, X4,Y4);
+		static Type Tile(bool H, bool V) {
+			return (H ?
+				(V ? Both     : Horizontal) :
+				(V ? Vertical : None)
+			);
 		}
-		virtual void Draw(I2DGraphicsTarget &Target,int X1,int Y1, int X2,int Y2, int X3,int Y3, int X4, int Y4) { Draw(&Target, X1,Y1, X2,Y2, X3,Y3, X4,Y4); }
-
-
-		virtual void DrawTiled(I2DGraphicsTarget *Target,int X,int Y, int W, int H) { 
-#ifdef _DEBUG
-			if(Texture.ID==0)
-				std::runtime_error("Invalid texture ID, image is not initialized in tiled draw.");
-			if(Target==NULL)
-				std::runtime_error("Target is NULL");
-#endif
-			Target->DrawTiled(&Texture,X,Y,W,H);
-		}
-		virtual void DrawTiled(I2DGraphicsTarget &Target,int X,int Y, int W, int H) { DrawTiled(&Target, X,Y, W,H); }
-
-
-		virtual void DrawResized(TilingDirection Tiling, I2DGraphicsTarget *Target,int X,int Y, int W, int H) { 
-#ifdef _DEBUG
-			if(Texture.ID==0)
-				std::runtime_error("Invalid texture ID, image is not initialized in tiled draw.");
-			if(Target==NULL)
-				std::runtime_error("Target is NULL");
-#endif
-			switch(Tiling) {
-				case None:
-					Target->Draw(&Texture,X,Y,W,H);
-					break;
-				case Horizontal:
-					Target->DrawHTiled(&Texture,X,Y,W,H);
-					break;
-				case Vertical:
-					Target->DrawVTiled(&Texture,X,Y,W,H);
-					break;
-				case Both:
-					Target->DrawTiled(&Texture,X,Y,W,H);
-					break;
-			}
-		}
-		virtual void DrawResized(TilingDirection Tiling, I2DGraphicsTarget &Target,int X,int Y, int W, int H) { DrawResized(Tiling, &Target, X,Y, W,H); }
-
-
-		virtual void DrawHTiled(I2DGraphicsTarget *Target,int X,int Y, int W, int H) { 
-#ifdef _DEBUG
-			if(Texture.ID==0)
-				std::runtime_error("Invalid texture ID, image is not initialized in tiled draw.");
-			if(Target==NULL)
-				std::runtime_error("Target is NULL");
-#endif
-			Target->DrawHTiled(&Texture,X,Y,W,H);
-		}
-		virtual void DrawHTiled(I2DGraphicsTarget &Target,int X,int Y, int W, int H) { DrawHTiled(&Target, X,Y, W,H); }
-
-
-		virtual void DrawVTiled(I2DGraphicsTarget *Target,int X,int Y, int W, int H) { 
-#ifdef _DEBUG
-			if(Texture.ID==0)
-				std::runtime_error("Invalid texture ID, image is not initialized in tiled draw.");
-			if(Target==NULL)
-				std::runtime_error("Target is NULL");
-#endif
-			Target->DrawVTiled(&Texture,X,Y,W,H);
-		}
-		virtual void DrawVTiled(I2DGraphicsTarget &Target,int X,int Y, int W, int H) { DrawVTiled(Target, X,Y, W,H); }
 	};
 
+	class SizeController2D {
+	public:
+		enum TilingType {
+			//Should work as Continous if object is sizable
+			Single					= B8(00000000),
+			//Should work as Continous if object is sizable
+			Stretch					= B8(00000010),
 
-	////This is a graphics object with colorization support
-	class Colorizable2DGraphic : public Buffered2DGraphic {
-	public:
+			/*
+			Integral	= B8(00000100),
+			Smaller		= B8(00001000),
+			Closest		= B8(00010000),
+			Best		= B8(00100000),
+			*/
 
-		virtual void DrawColored(I2DColorizableGraphicsTarget *Target,int X,int Y,RGBint Color) { 
-#ifdef _DEBUG
-			if(Texture.ID==0) {
-				os::DisplayMessage("Colorizable 2D Graphic","Invalid texture ID, image is not initialized.");
-				assert(0);
-			}
-#endif
-			Target->Draw(&Texture, X, Y, Color);
-		}
-		virtual void DrawColored(I2DColorizableGraphicsTarget &Target,int X,int Y,RGBint Color) { DrawColored(&Target, X,Y, Color); }
+			//An object can either be sizable or tilable
+			Continous			= B8(00000001),
+			Integral_Smaller	= B8(00001101),
+			Integral_Fill		= B8(00010101),
+			Integral_Best		= B8(00100101),
 
-		inline void DrawColored(I2DColorizableGraphicsTarget *Target,int X,int Y,unsigned int Color) { DrawColored(Target,X,Y,ToRGBint(Color)); }
+			Tile_Continous			= B8(00000001),
+			Tile_Integral_Smaller	= B8(00001101),
+			Tile_Integral_Fill		= B8(00010101),
+			Tile_Integral_Best		= B8(00100101),
+		} HorizontalTiling, VerticalTiling;
+
+		Alignment::Type Align;
+
+		class Integral {
+		public:
+			int Overhead;
+			int Increment;
+		} Horizontal, Vertical;
+
+		static const SizeController2D TileFit;
+		static const SizeController2D StretchFit;
 	};
 
-	////This is a basic drawing object
-	class Raw2DGraphic {
-	public:
-		utils::ManagedBuffer<Byte> Data;
-	protected:
-		int Width;
-		int Height;
-		ColorMode Mode;
-
-	public:
-		Raw2DGraphic() { Width=0; Height=0; Mode=ARGB_32BPP; }
-		Raw2DGraphic(Raw2DGraphic &graph) {
-			Data=graph.Data;
-			Width=graph.Width;
-			Height=graph.Height;
-			Mode=graph.Mode;
-		}
-
-		////Draws this object to the given target
-		///@Target	: The target that will be used to draw
-		/// this image
-		virtual void DrawRaw(I2DRawGraphicsTarget *Target,int X,int Y) { 
-#ifdef _DEBUG
-			if(Data.GetSize()==0) {
-				os::DisplayMessage("Raw 2D Graphic","Empty data, image is not initialized.");
-				assert(0);
-			}
-#endif
-			Target->Draw(Data, Width, Height, Mode, X, Y);
-		}
-
-		virtual void DrawRaw(I2DRawGraphicsTarget *Target,int X,int Y, int W, int H) { 
-#ifdef _DEBUG
-			if(Data==NULL) {
-				os::DisplayMessage("Raw 2D Graphic","Empty data, image is not initialized.");
-				assert(0);
-			}
-#endif
-			Target->Draw(Data, Width, Height, Mode, X, Y, W, H);
-		}
+	
 
-		virtual void DrawRaw(I2DRawGraphicsTarget *Target,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4) {
-#ifdef _DEBUG
-			if(Data==NULL) {
-				os::DisplayMessage("Raw 2D Graphic","Empty data, image is not initialized.");
-				assert(0);
-			}
-#endif
-			Target->Draw(Data, Width, Height, Mode, X1, Y1, X2, Y2, X3, Y3, X4, Y4);
-		}
-
-		virtual void DrawRawFlipped(I2DRawGraphicsTarget *Target,int X,int Y) { 
-#ifdef _DEBUG
-			if(Data==NULL) {
-				os::DisplayMessage("Raw 2D Graphic","Empty data, image is not initialized.");
-				assert(0);
-			}
-#endif
-			Target->Draw(Data, Width, Height, Mode, X, Y+Height, X+Width, Y+Height, X+Width, Y, X, Y);
-		}
-
-		virtual void DrawRawFlipped(I2DRawGraphicsTarget *Target,int X,int Y, int W, int H) { 
-#ifdef _DEBUG
-			if(Data==NULL) {
-				os::DisplayMessage("Raw 2D Graphic","Empty data, image is not initialized.");
-				assert(0);
-			}
-#endif
-			Target->Draw(Data, Width, Height, Mode, X, Y+H, X+W, Y+H, X+W, Y, X, Y);
-		}
-
-		virtual void Resize(int Width, int Height, ColorMode Mode) {
-			int bits=getBPP(Mode);
-
-			Data.Resize(Width*Height*bits);
-
-			this->Width=Width;
-			this->Height=Height;
-			this->Mode=Mode;
-		}
-
-		~Raw2DGraphic() {  }
-		int getWidth() { return Width; }
-		int getHeight() { return Height; }
-		ColorMode getMode() { return Mode; }
-	};
-
-
-
-	////Finds integer log of base 2
-	inline int log2(int num);
-	////Finds nearest 2^n value that is larger than num
-	inline int sl2(int num);
 	////Initializes OpenGL graphics with the given parameters,
 	/// returns created device context
 	///@hWnd		: Handle for the target window
 	///@BitDepth	: Used if fullscreen, changed bitdepth of screen
 	os::DeviceHandle Initialize(os::WindowHandle hWnd, int BitDepth, int Width, int Height);
-	////Creates rectangle structure based on give parameters
-	//RECT makerect(int x, int y, int w, int h);
-	////Converts Alpha only image to Alpha and Luminance (grayscale) image.
-	/// Destination array should be allocated. This algorithm is optimized
-	/// for speed.
-	///@Source		: Source data array, no justification is needed,
-	///               should be 1 byte/pix
-	///@Destination	: Destination data array, data is copied without
-	///               any justification, should be allocated for 2 byte/pix
-	void A8ToA8L8(int Width, int Height, Byte *Source, Byte *Destination);
-	////This function sets the current texture to given data
-	void SetTexture(Byte *data, int cx, int cy, ColorMode mode);
-	////This function creates a texture from the given data and
-	/// returns texture information in a structure
-	///@Image		: Image data
-	///@Mode		: Color mode
-	GLTexture GenerateTexture(Byte *Image,int Width,int Height,ColorMode Mode);
-	void DestroyTexture(GLTexture *texture);
-	////Returns equivalent OpenGL color mode constant
-	///@Mode		: GGE color mode constant
-	GLenum getGLColorMode(ColorMode Mode);
-	////Returns required bytes per pixel for a given color mode
-	int getBPP(ColorMode Mode);
-	////Cleans render buffer and prepares for rendering
-	void PreRender();
-	////Performs post render tasks
-	///@hDC			: Device context that is created by
-	/// initialize graphics function
-	void PostRender(os::DeviceHandle Device);
+
+	namespace system {
+
+		////Logarithm Base 2
+		inline int log2(int num) {
+			int i=0;
+			int s=1;
+			while(num-s>0) {
+				i++;
+				s<<=1;
+			}
+
+			return i;
+		}
+
+		////Rounds the given number to the lowest 2^n (where n is integer) number 
+		/// that is higher than the given number
+		inline int sl2(int num) {
+			int s=1;
+			while(num-s>0) {
+				s<<=1;
+			}
+
+			return s;
+		}
+		////Creates rectangle structure based on give parameters
+		//RECT makerect(int x, int y, int w, int h);
+		////Converts Alpha only image to Alpha and Luminance (grayscale) image.
+		/// Destination array should be allocated. This algorithm is optimized
+		/// for speed.
+		///@Source		: Source data array, no justification is needed,
+		///               should be 1 byte/pix
+		///@Destination	: Destination data array, data is copied without
+		///               any justification, should be allocated for 2 byte/pix
+		void A8ToA8L8(int Width, int Height, Byte *Source, Byte *Destination);
+		////This function sets the current texture to given data
+		void SetTexture(Byte *data, int cx, int cy, ColorMode::Type mode);
+		////This function creates a texture from the given data and
+		/// returns texture information in a structure
+		///@Image		: Image data
+		///@Mode		: Color mode
+		GLTexture GenerateTexture(Byte *Image,int Width,int Height,ColorMode::Type Mode);
+		void DestroyTexture(GLTexture *texture);
+		////Returns equivalent OpenGL color mode constant
+		///@Mode		: GGE color mode constant
+		GLenum getGLColorMode(ColorMode::Type Mode);
+		////Cleans render buffer and prepares for rendering
+		void PreRender();
+		////Performs post render tasks
+		///@hDC			: Device context that is created by
+		/// initialize graphics function
+		void PostRender(os::DeviceHandle Device);
+	}
 
 	extern utils::Size ScreenSize;
 } }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Image.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -0,0 +1,128 @@
+
+#include "Image.h"
+#include <cmath>
+#include "..\Utils\BasicMath.h"
+
+using namespace std;
+using namespace gge::utils;
+
+namespace gge { namespace graphics {
+
+	void TextureImage::drawto(ImageTarget2D& Target, SizeController2D &controller, int X, int Y, int W, int H) {
+		bool HTile=false, VTile=false;
+		int w,h;
+		if(controller.HorizontalTiling==SizeController2D::Single) {
+			HTile=false;
+			w=getimagewidth();
+
+			if(Alignment::isCenter(controller.Align))
+				X+=(W-w)/2;
+			else if(Alignment::isRight(controller.Align))
+				X+=(W-w);
+
+		}
+		else if(controller.HorizontalTiling==SizeController2D::Tile_Continous) {
+			HTile=true;
+
+		}
+		else if(controller.HorizontalTiling==SizeController2D::Stretch) {
+			HTile=false;
+		}
+		else {
+			HTile=true;
+
+			if(controller.HorizontalTiling==SizeController2D::Tile_Integral_Best) {
+				w=(int)Round((double)(W-controller.Horizontal.Overhead)/controller.Horizontal.Increment)*controller.Horizontal.Increment+controller.Horizontal.Overhead;
+			}
+			else if(controller.HorizontalTiling==SizeController2D::Tile_Integral_Smaller) {
+				w=(int)floor((double)(W-controller.Horizontal.Overhead)/controller.Horizontal.Increment)*controller.Horizontal.Increment+controller.Horizontal.Overhead;
+			}
+			else if(controller.HorizontalTiling==SizeController2D::Tile_Integral_Fill) {
+				w=(int)ceil((double)(W-controller.Horizontal.Overhead)/controller.Horizontal.Increment)*controller.Horizontal.Increment+controller.Horizontal.Overhead;
+			}
+
+			if(Alignment::isCenter(controller.Align))
+				X+=(W-w)/2;
+			else if(Alignment::isRight(controller.Align))
+				X+=(W-w);
+		}
+
+
+
+
+		if(controller.VerticalTiling==SizeController2D::Single) {
+			VTile=false;
+			h=getimagewidth();
+
+			if(Alignment::isMiddle(controller.Align))
+				Y+=(H-h)/2;
+			else if(Alignment::isBottom(controller.Align))
+				Y+=(H-h);
+
+		}
+		else if(controller.VerticalTiling==SizeController2D::Tile_Continous) {
+			VTile=true;
+
+		}
+		else if(controller.VerticalTiling==SizeController2D::Stretch) {
+			VTile=false;
+		}
+		else {
+			VTile=true;
+
+			if(controller.VerticalTiling==SizeController2D::Tile_Integral_Best) {
+				h=(int)Round((double)(H-controller.Vertical.Overhead)/controller.Vertical.Increment)*controller.Vertical.Increment+controller.Vertical.Overhead;
+			}
+			else if(controller.VerticalTiling==SizeController2D::Tile_Integral_Smaller) {
+				h=(int)floor((double)(H-controller.Vertical.Overhead)/controller.Vertical.Increment)*controller.Vertical.Increment+controller.Vertical.Overhead;
+			}
+			else if(controller.VerticalTiling==SizeController2D::Tile_Integral_Fill) {
+				h=(int)ceil((double)(H-controller.Vertical.Overhead)/controller.Vertical.Increment)*controller.Vertical.Increment+controller.Vertical.Overhead;
+			}
+
+			if(Alignment::isMiddle(controller.Align))
+				Y+=(H-h)/2;
+			else if(Alignment::isBottom(controller.Align))
+				Y+=(H-h);
+		}
+	}
+
+
+	int TextureImage::calculatewidthusing(const SizeController2D &controller, int W ) const {
+		if(controller.HorizontalTiling==SizeController2D::Single) {
+			return getimagewidth();
+		}
+		else if(controller.HorizontalTiling==SizeController2D::Tile_Integral_Best) {
+			return (int)Round((double)(W-controller.Horizontal.Overhead)/controller.Horizontal.Increment)*controller.Horizontal.Increment+controller.Horizontal.Overhead;
+		}
+		else if(controller.HorizontalTiling==SizeController2D::Tile_Integral_Smaller) {
+			return (int)floor((double)(W-controller.Horizontal.Overhead)/controller.Horizontal.Increment)*controller.Horizontal.Increment+controller.Horizontal.Overhead;
+		}
+		else if(controller.HorizontalTiling==SizeController2D::Tile_Integral_Fill) {
+			return (int)ceil((double)(W-controller.Horizontal.Overhead)/controller.Horizontal.Increment)*controller.Horizontal.Increment+controller.Horizontal.Overhead;
+		}
+		else
+			return W;
+	}
+
+	int TextureImage::calculateheightusing(const SizeController2D &controller, int H ) const {
+		if(controller.VerticalTiling==SizeController2D::Single) {
+			return getimagewidth();
+		}
+		else if(controller.VerticalTiling==SizeController2D::Tile_Integral_Best) {
+			return (int)Round((double)(H-controller.Vertical.Overhead)/controller.Vertical.Increment)*controller.Vertical.Increment+controller.Vertical.Overhead;
+		}
+		else if(controller.VerticalTiling==SizeController2D::Tile_Integral_Smaller) {
+			return (int)floor((double)(H-controller.Vertical.Overhead)/controller.Vertical.Increment)*controller.Vertical.Increment+controller.Vertical.Overhead;
+		}
+		else if(controller.VerticalTiling==SizeController2D::Tile_Integral_Fill) {
+			return (int)ceil((double)(H-controller.Vertical.Overhead)/controller.Vertical.Increment)*controller.Vertical.Increment+controller.Vertical.Overhead;
+		}
+		else
+			return H;
+	}
+
+
+
+} }
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Image.h	Tue Jul 26 09:55:07 2011 +0000
@@ -0,0 +1,97 @@
+#pragma once
+#include "..\Utils\UtilsBase.h"
+#include "..\Utils\CastableManagedBuffer.h"
+#include "Graphics.h"
+#include "GraphicTargets2D.h"
+
+
+namespace gge { namespace graphics {
+
+	class ImageData {
+	public:
+		ImageData() : Width(0), Height(0), Mode(ColorMode::ARGB) {
+
+		}
+
+		virtual void Resize(int Width, int Height, ColorMode::Type Mode) {
+			int bits=getBPP(Mode);
+
+			Data.Resize(Width*Height*bits);
+
+			this->Width=Width;
+			this->Height=Height;
+			this->Mode=Mode;
+		}
+
+		int GetWidth() const {
+			return Width;
+		}
+
+		int GetHeight() const {
+			return Height;
+		}
+
+		ColorMode::Type GetMode() const {
+			return Mode;
+		}
+
+	protected:
+		utils::CastableManagedBuffer<Byte> Data;
+		int Width,Height;
+		ColorMode::Type Mode;
+	};
+
+
+	class TextureImage {
+	public:
+
+		virtual int getimagewidth () const { return Texture.W; }
+		virtual int getimageheight() const { return Texture.H; };
+
+		void drawto(ImageTarget2D &target, int X1,int Y1, int X2,int Y2, int X3,int Y3, int X4,int Y4) {
+			target.Draw(&Texture,X1,Y1,X2,Y2,X3,Y3,X4,Y4);
+		}
+
+		void drawto(ColorizableImageTarget2D &target, int X1,int Y1, int X2,int Y2, int X3,int Y3, int X4,int Y4, RGBint color) {
+			target.SetCurrentColor(color);
+			target.Draw(&Texture,X1,Y1,X2,Y2,X3,Y3,X4,Y4);
+		}
+
+		void drawto(ImageTarget2D &target, int X1,int Y1, int X2,int Y2, int X3,int Y3, int X4,int Y4,float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) {
+			target.Draw(&Texture,X1,Y1,X2,Y2,X3,Y3,X4,Y4,S1,U1,S2,U2,S3,U3,S4,U4);
+		}
+
+		void drawto(ColorizableImageTarget2D &target, int X1,int Y1, int X2,int Y2, int X3,int Y3, int X4,int Y4,float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4, RGBint color) {
+			target.SetCurrentColor(color);
+			target.Draw(&Texture,X1,Y1,X2,Y2,X3,Y3,X4,Y4,S1,U1,S2,U2,S3,U3,S4,U4);
+		}
+
+		void drawto(ImageTarget2D &target, int X,int Y, int W,int H) {
+			target.Draw(&Texture, X,Y,W,H);
+		}
+
+		void drawto(ColorizableImageTarget2D &target, int X,int Y, int W,int H, RGBint color) {
+			target.SetCurrentColor(color);
+			target.Draw(&Texture, X,Y,W,H);
+		}
+
+		void drawto(ImageTarget2D &target, Tiling2D::Type Tiling, int X,int Y, int W,int H) {
+			target.Draw(&Texture,Tiling, X,Y,W,H);
+		}
+
+		void drawto(ColorizableImageTarget2D &target, Tiling2D::Type Tiling, int X,int Y, int W,int H, RGBint color) {
+			target.SetCurrentColor(color);
+			target.Draw(&Texture,Tiling, X,Y,W,H);
+		}
+
+		void drawto(ImageTarget2D& Target, SizeController2D &controller, int X, int Y, int W, int H);
+
+		int calculatewidthusing(const SizeController2D &controller, int w) const;
+		int calculateheightusing(const SizeController2D &controller, int h) const;
+
+		GLTexture &GetTexture() { return Texture; }
+
+	protected:
+		GLTexture Texture;
+	};
+} }
--- a/Engine/OS.Win32.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Engine/OS.Win32.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -1,7 +1,9 @@
 #include "OS.h"
 #include "input.h"
 #include "Multimedia.h"
+#include "..\Utils\Point2D.h"
 
+using namespace gge::utils;
 using namespace gge::input;
 using namespace gge::input::system;
 
@@ -71,6 +73,7 @@
 			//!Private
 			POINT overhead;
 			HWND curwin;
+			Point cursorlocation=Point(0,0);
 
 			LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 			{
@@ -218,7 +221,7 @@
 						int x=lParam%0x10000;
 						int y=lParam>>16;
 						
-						ProcessVScroll(GET_WHEEL_DELTA_WPARAM(wParam)/120,x-overhead.x,y-overhead.y);
+						ProcessVScroll(GET_WHEEL_DELTA_WPARAM(wParam)/120,cursorlocation.x,cursorlocation.y);
 					}
 					break;
 				case WM_MOUSEHWHEEL:
@@ -226,7 +229,7 @@
 						int x=lParam%0x10000;
 						int y=lParam>>16;
 						
-						ProcessHScroll(GET_WHEEL_DELTA_WPARAM(wParam)/120,x-overhead.x,y-overhead.y);
+						ProcessHScroll(GET_WHEEL_DELTA_WPARAM(wParam)/120,cursorlocation.x,cursorlocation.y);
 					}
 					break;
 
@@ -414,6 +417,21 @@
 				SetWindowPos((HWND)h, 0, p.x,p.y, 0,0, SWP_NOSIZE | SWP_NOZORDER);
 			}
 
+			utils::Rectangle UsableScreenMetrics(int Monitor) {
+				utils::Rectangle r;
+
+				RECT rect;
+
+				SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, 0);
+
+				r.Left=rect.left;
+				r.Top=rect.left;
+				r.SetRight(rect.right);
+				r.SetBottom(rect.bottom);
+
+				return r;
+			}
+
 		}
 	
 		void ShowPointer() {
@@ -441,6 +459,8 @@
 				ret.x=pnt.x-(window::overhead.x+winrect.left);
 				ret.y=pnt.y-(window::overhead.y+winrect.top);
 
+				os::window::cursorlocation=ret;
+
 				return ret;
 			}
 
--- a/Engine/OS.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Engine/OS.h	Tue Jul 26 09:55:07 2011 +0000
@@ -5,6 +5,7 @@
 #include "../Utils/EventChain.h"
 
 #include "OS.Win32.h"
+#include "../Utils/Rectangle2D.h"
 
 using std::string;
 
@@ -42,6 +43,9 @@
 		extern utils::EventChain<> Deactivated;
 		extern utils::EventChain<> Destroyed;
 
+		//Monitor parameter is ignored for now
+		utils::Rectangle UsableScreenMetrics(int Monitor=0);
+
 		////This function creates a window
 		///@Name		: Identifier name for the window, should abide by variable naming rules
 		///@Title		: Title of the window
@@ -55,7 +59,7 @@
 		WindowHandle CreateWindow(string Name, string Title, os::IconHandle Icon, os::InstanceHandle Instance, int Left, int Top, int Width, int Height, int BitDepth, bool &FullScreen);
 
 		void MoveWindow(WindowHandle,utils::Point);
-		inline void MoveWindow(WindowHandle h,int X,int Y) { MoveWindow(h,X,Y); }
+		inline void MoveWindow(WindowHandle h,int X,int Y) { MoveWindow(h,utils::Point(X,Y)); }
 	}
 
 } }
\ No newline at end of file
--- a/Engine/Pointer.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Engine/Pointer.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -71,7 +71,7 @@
 		for(SortedCollection<ResourceBase>::Iterator resource=Folder->Subitems.First();resource.isValid();resource.Next()) {
 			if(resource->getGID()==GID::Animation) {
 				AnimationResource *anim=dynamic_cast<AnimationResource *>(resource.CurrentPtr());
-				utils::Collection<Pointer, 10>::Add( new Pointer(anim->getAnimation(), data->getPoint(i+1).x, data->getPoint(i+1).y, (Pointer::PointerTypes)data->getInt(i)) );
+				utils::Collection<Pointer, 10>::Add( new Pointer(&anim->CreateAnimation(), data->getPoint(i+1).x, data->getPoint(i+1).y, (Pointer::PointerTypes)data->getInt(i)) );
 			} else if(resource->getGID()==GID::Image) {
 				ImageResource *img=dynamic_cast<ImageResource *>(resource.CurrentPtr());
 				utils::Collection<Pointer, 10>::Add( new Pointer(img, data->getPoint(i+1).x, data->getPoint(i+1).y, (Pointer::PointerTypes)data->getInt(i)) );
@@ -84,7 +84,7 @@
 			BasePointer=&(*this)[0];
 	}
 
-	Pointer *PointerCollection::Add(graphics::Buffered2DGraphic *pointer, Point Hotspot, Pointer::PointerTypes Type) {
+	Pointer *PointerCollection::Add(graphics::RectangularGraphic2D *pointer, Point Hotspot, Pointer::PointerTypes Type) {
 		Pointer *ret=new Pointer(pointer, Hotspot.x, Hotspot.y, Type);
 		utils::Collection<Pointer, 10>::Add( ret );
 		
--- a/Engine/Pointer.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Engine/Pointer.h	Tue Jul 26 09:55:07 2011 +0000
@@ -3,6 +3,7 @@
 #include "GGE.h"
 #include "../Utils/SortedCollection.h"
 #include "Graphics.h"
+#include "Graphic2D.h"
 
 namespace gge {
 	class GGEMain;
@@ -32,14 +33,14 @@
 		};
 
 		////The image of the pointer
-		graphics::Buffered2DGraphic *Image;
+		graphics::Graphic2D *Image;
 		////Point of click
 		utils::Point Hotspot;
 		////Type of the pointer
 		PointerTypes Type;
 
 		////Initializes a pointer
-		Pointer(graphics::Buffered2DGraphic *pointer, int HotspotX, int HotspotY, PointerTypes Type) {
+		Pointer(graphics::Graphic2D *pointer, int HotspotX, int HotspotY, PointerTypes Type) {
 			this->Image=pointer;
 			this->Hotspot.x=HotspotX;
 			this->Hotspot.y=HotspotY;
@@ -47,7 +48,7 @@
 		}
 
 		////Initializes a pointer
-		Pointer(graphics::Buffered2DGraphic &pointer, utils::Point Hotspot, PointerTypes Type) {
+		Pointer(graphics::Graphic2D &pointer, utils::Point Hotspot, PointerTypes Type) {
 			this->Image=&pointer;
 			this->Hotspot=Hotspot;
 			this->Type=Type;
@@ -69,9 +70,9 @@
 		void Fetch(resource::FolderResource *Folder);
 		void Fetch(resource::FolderResource &Folder) { Fetch(&Folder); }
 		////Adds a pointer to the list of pointers
-		Pointer *Add(graphics::Buffered2DGraphic *Pointer, utils::Point Hotspot=utils::Point(2,2), Pointer::PointerTypes Type=Pointer::None);
+		Pointer *Add(graphics::RectangularGraphic2D *Pointer, utils::Point Hotspot=utils::Point(2,2), Pointer::PointerTypes Type=Pointer::None);
 		////Adds a pointer to the list of pointers
-		Pointer &Add(graphics::Buffered2DGraphic &Pointer, utils::Point Hotspot=utils::Point(2,2), Pointer::PointerTypes Type=Pointer::None) {
+		Pointer &Add(graphics::RectangularGraphic2D &Pointer, utils::Point Hotspot=utils::Point(2,2), Pointer::PointerTypes Type=Pointer::None) {
 			return *Add(&Pointer, Hotspot, Type);
 		}
 		////Sets the given pointer as current one, this operation should be revered by
--- a/Resource/AnimationResource.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Resource/AnimationResource.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -1,6 +1,7 @@
 #include "AnimationResource.h"
 #include "ResourceFile.h"
 #include "ImageResource.h"
+#include "..\Utils\BasicMath.h"
 
 using namespace gge::utils;
 using namespace std;
@@ -16,9 +17,16 @@
 			ReadFrom(Data, size);
 
 			if(gid==GID::Animation_Durations) {
-				anim->Durations=new int[size/4];
+				unsigned t=0;
 
-				Data.read((char*)anim->Durations,size);
+				for(int i=0;i<size/4;i++) {
+					unsigned d=ReadFrom<int>(Data);
+					anim->Frames.push_back(AnimationResourceFrame(d,t));
+
+					t+=d;
+				}
+
+				anim->TotalLength=t;
 			} 
 			else if(gid==GID::Guid) {
 				anim->guid.LoadLong(Data);
@@ -34,67 +42,103 @@
 			}
 		}
 
+		int i=0;
+		for(SortedCollection<ResourceBase>::Iterator it=anim->Subitems.First();it.isValid();it.Next(), i++)
+			anim->Frames[i].Image=&dynamic_cast<ImageResource&>(*it);
+
 		anim->FrameCount=anim->Subitems.getCount();
 
 		return anim;
 	}
 
-	int* ImageAnimation::FrameDurations() { 
-		return parent->Durations; 
-	}
-	void ImageAnimation::ProcessFrame(int frame) {
-		this->Texture = dynamic_cast<ImageResource&>(parent->Subitems[frame]).Texture; 
-	}
+
+	animation::ProgressResult::Type ImageAnimation::Progress() {
+		if(Controller && parent.Frames.size()) { 
+			if(Controller->GetType()==animation::AnimationTimer::Discrete) {
+				animation::DiscreteController *dc = dynamic_cast<animation::DiscreteController *>(Controller);
 
-	void ImageAnimation::init() {
-		if(parent->Subitems.getCount())
-			this->Texture = dynamic_cast<ImageResource&>(parent->Subitems[0]).Texture; 
-		else
-			this->Texture.ID = 0;
+				int cf=dc->CurrentFrame();
+				int fc=parent.FrameCount;
 
-		if(parent->FrameCount)
-			setTotalFrames(parent->FrameCount);
-		else
-			Pause();
-	}
-	void ImageAnimation::DrawResized(graphics::I2DGraphicsTarget *Target, int X, int Y, int W, int H, Alignment::Type Align) {
+				if(cf<0) {
+					Texture.ID=0;
+					return animation::ProgressResult::None;
+				}
 
-		int h=this->Height(H);
-		int w=this->Width(W);
+				Texture=parent[cf].GetTexture();
 
-		if(Alignment::isCenter(Align))
-			X+=(W-w)/2;
-		else if(Alignment::isRight(Align))
-			X+= W-w;
+				return animation::ProgressResult::None;
+			}
+			else {
+				animation::ProgressResult::Type ret=animation::ProgressResult::None;
 
-		if(Alignment::isMiddle(Align))
-			Y+=(H-h)/2;
-		else if(Alignment::isBottom(Align))
-			Y+= H-h;
+				int t=Controller->GetProgress();
+				int tl=(int)parent.GetTotalLength();
 
-		if(VerticalTiling.Type==ResizableObject::Stretch) {
-			if(HorizontalTiling.Type==ResizableObject::Stretch) {
-				this->Draw(Target, X,Y , w,h);
-			} else {
-				this->DrawHTiled(Target, X,Y , w,h);
+				Texture=parent.ImageAt(PositiveMod(t,tl)).GetTexture();
+
+				return ret;
 			}
-		} else {
-			if(HorizontalTiling.Type==ResizableObject::Stretch) {
-				this->DrawVTiled(Target, X,Y , w,h);
-			} else {
-				this->DrawTiled(Target, X,Y , w,h);
-			}
+		}
+		else {
+			Texture.ID=0;
+
+			return animation::ProgressResult::None;
 		}
 	}
 
-	int  ImageAnimation::Width(int W) { 
-		if(W==-1) return parent->getWidth();
+	ImageAnimation::ImageAnimation( AnimationResource &parent, animation::AnimationTimer &controller, bool owner ) : 
+	animation::AnimationBase(controller, owner), parent(parent)
+	{
+		Texture=parent.ImageAt(0).GetTexture();
+	}
 
-		return HorizontalTiling.Calculate(parent->getWidth(), W); 
+	ImageAnimation::ImageAnimation( AnimationResource &parent, bool create ) : 
+	animation::AnimationBase(create), parent(parent)
+	{
+		Texture=parent.ImageAt(0).GetTexture();
 	}
-	int  ImageAnimation::Height(int H) { 
-			if(H==-1) return parent->getHeight(); 
-		
-			return VerticalTiling.Calculate(parent->getHeight(), H); 
+
+
+
+	int AnimationResource::FrameAt( unsigned t ) const {
+		if(Subitems.getCount()==0) return -1;
+
+		if(t>=(Frames.end()-1)->Start)
+			return FrameCount-1;
+
+		int Guessed=(int)floor( ((float)t/TotalLength)*FrameCount );
+
+		if(Frames[Guessed].Start>t) {
+			while(Frames[Guessed].Start>t)
+				Guessed--;
+
+			return Guessed;
 		}
+		else if(Frames[Guessed+1].Start<t) {
+			while(Frames[Guessed+1].Start<t)
+				Guessed++;
+
+			return Guessed;
+		} 
+		else
+			return Guessed;
+	}
+
+	int AnimationResource::StartOf(unsigned Frame) const {
+		return Frames[Frame].Start;
+	}
+
+	int AnimationResource::GetDuration() const {
+		return TotalLength;
+	}
+
+	int AnimationResource::GetDuration(unsigned Frame) const {
+		return Frames[Frame].Duration;
+	}
+
+	int AnimationResource::GetNumberofFrames() const {
+		return Frames.size();
+	}
+
 } }
--- a/Resource/AnimationResource.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Resource/AnimationResource.h	Tue Jul 26 09:55:07 2011 +0000
@@ -2,7 +2,7 @@
 
 #include "GRE.h"
 #include "ResourceBase.h"
-#include "../Engine/Animator.h"
+#include "../Engine/Animation.h"
 #include "ImageResource.h"
 #include "../Resource/ResizableObject.h"
 #include "../Utils/Point2D.h"
@@ -16,107 +16,67 @@
 	class AnimationResource;
 
 	////This class draws an animated image
-	class ImageAnimation : public DiscreteAnimatorBase, public graphics::Buffered2DGraphic, public ResizableObject {
-		friend class AnimationResource;
+	class ImageAnimation : 
+		public ResizableObject, public virtual graphics::RectangularGraphic2D, 
+		protected graphics::TextureImage
+	{
 	public:
-	protected:
-		AnimationResource *parent;
-		virtual int* FrameDurations();
-		virtual void ProcessFrame(int frame);
 
-	public:
-		ImageAnimation(AnimationResource *parent): DiscreteAnimatorBase(), parent(parent) 
-		{ init(); SetResizingOptions(ResizableObject::Single,ResizableObject::Single); }
-		ImageAnimation(AnimationResource *parent,  ResizableObject::Tiling Horizontal, ResizableObject::Tiling Vertical): DiscreteAnimatorBase(), parent(parent) 
-		{ init(); SetResizingOptions(Horizontal, Vertical); }
+		ImageAnimation(AnimationResource &parent, animation::AnimationTimer &controller, bool owner=false);
+		ImageAnimation(AnimationResource &parent, bool create=false);
 
-		virtual void Reset(bool Reverse=false) {
-			Pause();
-			GotoFrame(0);
-			if(Reverse)
-				GoBackwards();
-			else
-				GoForwards();
-		}
-		virtual void Reverse() {
-			if(isBackwards())
-				GoForwards();
-			else
-				GoBackwards();
-		}
-		virtual void Play() { DiscreteAnimatorBase::Play(); }
-		virtual void Pause() { DiscreteAnimatorBase::Pause(); }
-		virtual void setLoop(bool Loop) { islooping=Loop; }
-		virtual int getDuration() { return DiscreteAnimatorBase::duration; }
-		virtual void Draw(graphics::I2DGraphicsTarget *Target,int X,int Y) { 
-			Draw(Target, X, Y, Texture.W, Texture.H);
-		}
-		void Draw(graphics::I2DGraphicsTarget &Target,int X,int Y) { Draw(&Target, X,Y); }
-		void Draw(graphics::I2DGraphicsTarget &Target,utils::Point p) { Draw(Target, p.x,p.y); }
-		void Draw(graphics::I2DGraphicsTarget *Target,utils::Point p) { Draw(Target, p.x,p.y); }
+		AnimationResource &parent;
+	protected:
+		virtual animation::ProgressResult::Type Progress();
 
-		virtual void Draw(graphics::I2DGraphicsTarget *Target,int X,int Y,int W,int H) { 
-			if(Texture.ID)
-				graphics::Buffered2DGraphic::Draw(Target, X, Y, W, H);
-		}
-		void Draw(graphics::I2DGraphicsTarget &Target,int X,int Y,int W,int H) { Draw(&Target, X,Y, W,H); }
+		virtual void drawin(graphics::ImageTarget2D& Target, int X, int Y, int W, int H) 
+		{ drawto(Target, graphics::Tiling2D::Both, X,Y, W,H); } 
+
+		virtual void drawin(graphics::ImageTarget2D& Target, graphics::SizeController2D &controller, int X, int Y, int W, int H) 
+		{ drawto(Target, controller, X,Y, W,H); };
 
-		virtual void Draw(graphics::I2DGraphicsTarget *Target,int X1,int Y1, int X2,int Y2, int X3,int Y3, int X4, int Y4) { 
-			if(Texture.ID)
-				Buffered2DGraphic::Draw(Target, X1, Y1, X2, Y2, X3, Y3, X4, Y4);
-		}
-		void Draw(graphics::I2DGraphicsTarget &Target,int X1,int Y1, int X2,int Y2, int X3,int Y3, int X4, int Y4) { Draw(&Target, X1,Y1, X2,Y2, X3,Y3, X4,Y4); }
+		virtual int calculatewidth (int w=-1) const { return getimagewidth(); }
+		virtual int calculateheight(int h=-1) const { return getimageheight(); }
 
-		virtual void DrawTiled(graphics::I2DGraphicsTarget *Target,int X,int Y, int W, int H) { 
-			if(Texture.ID)
-				graphics::Buffered2DGraphic::DrawTiled(Target, X, Y, W, H);
-		}
-		void DrawTiled(graphics::I2DGraphicsTarget &Target,int X,int Y, int W, int H) { DrawTiled(&Target, X,Y, W,H); }
-		virtual void DrawResized(TilingDirection Tiling, graphics::I2DGraphicsTarget *Target,int X,int Y, int W, int H) { 
-			if(Texture.ID)
-				graphics::Buffered2DGraphic::DrawResized(Tiling, Target, X, Y, W, H);
-		}
-		virtual void DrawResized(TilingDirection Tiling, graphics::I2DGraphicsTarget &Target,int X,int Y, int W, int H) { DrawResized(Tiling, &Target, X,Y, W,H); }
-
-		virtual void DrawHTiled(graphics::I2DGraphicsTarget *Target,int X,int Y, int W, int H) { 
-			if(Texture.ID)
-				graphics::Buffered2DGraphic::DrawHTiled(Target, X, Y, W, H);
-		}
-		void DrawHTiled(graphics::I2DGraphicsTarget &Target,int X,int Y, int W, int H) { DrawHTiled(&Target, X,Y, W,H); }
+		virtual int calculatewidth (const graphics::SizeController2D &controller, int w=-1) const  { return calculatewidthusing(controller,w); }
+		virtual int calculateheight(const graphics::SizeController2D &controller, int h=-1) const  { return calculateheightusing(controller,h); }
 
-		virtual void DrawVTiled(graphics::I2DGraphicsTarget *Target,int X,int Y, int W, int H) { 
-			if(Texture.ID)
-				graphics::Buffered2DGraphic::DrawVTiled(Target, X, Y, W, H);
-		}
-		void DrawVTiled(graphics::I2DGraphicsTarget &Target,int X,int Y, int W, int H) { DrawVTiled(&Target, X,Y, W,H); }
-
-
-		virtual int  Width(int W=-1);
-		virtual int  Height(int H=-1);
+		virtual void draw(graphics::ImageTarget2D& Target, int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) 
+		{ drawto(Target, X1,Y1, X2,Y2, X3,Y3, X4,Y4, S1,U1, S2,U2, S3,U3, S4,U4); }
+		virtual void draw(graphics::ImageTarget2D& Target, int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4) 
+		{ drawto(Target, X1,Y1, X2,Y2, X3,Y3, X4,Y4); }
+		virtual void drawstretched(graphics::ImageTarget2D& Target, int X, int Y, int W, int H)
+		{ drawto(Target, X,Y, W,H); }
+		virtual void draw(graphics::ImageTarget2D& Target, graphics::Tiling2D::Type Tiling, int X, int Y, int W, int H)
+		{ drawto(Target, Tiling, X,Y, W,H); }
+		virtual void draw(graphics::ImageTarget2D& Target, graphics::SizeController2D &controller, int X, int Y, int W, int H)
+		{ drawto(Target, controller, X,Y, W,H); }
 
-	public:
-		virtual void DrawResized(graphics::I2DGraphicsTarget *Target, int X, int Y, int W, int H, Alignment::Type Align=Alignment::Middle_Center);
-		virtual void DrawResized(graphics::I2DGraphicsTarget &Target, int X, int Y, int W, int H, Alignment::Type Align=Alignment::Middle_Center) { DrawResized(&Target, X,Y ,W,H, Align); }
-
-		ResizableObject::Tiling HorizontalTiling;
-		ResizableObject::Tiling VerticalTiling;
-
-
-		void SetResizingOptions( ResizableObject::Tiling Horizontal, ResizableObject::Tiling Vertical ) {
-			this->HorizontalTiling=Horizontal;
-			this->VerticalTiling=Vertical;
-		}
-
-
-	protected:
-		void init();
+		virtual int getwidth () const { return getimagewidth(); }
+		virtual int getheight() const { return getimageheight(); }
 
 	};
 
+
+	class AnimationResourceFrame {
+	public:
+		AnimationResourceFrame(unsigned d=0, unsigned s=0, ImageResource *im=NULL) : Duration(d), Start(s), Image(im) { }
+
+		unsigned Duration;
+		unsigned Start;
+		ImageResource *Image;
+	};
+
+
 	////
-	class AnimationResource : public ResourceBase {
+	class AnimationResource : 
+		public ResourceBase, public ResizableObjectProvider, 
+		public animation::DiscreteInfoProvider 
+	{
+
 		friend ResourceBase *LoadAnimationResource(File &File, std::istream &Data, int Size);
 		friend class ImageAnimation;
+		friend class DiscreteImageAnimation;
 	public:
 		////03010000h (Gaming, Animation)
 		virtual GID::Type getGID() const { return GID::Animation; }
@@ -124,29 +84,47 @@
 		virtual bool Save(File &File, std::ostream &Data) { return false; }
 		
 		////Default constructor
-		AnimationResource() : ResourceBase() { Durations=NULL; FrameCount=0; }
+		AnimationResource() : ResourceBase() { FrameCount=TotalLength=0; }
 
 		////Returns the width of the first image
-		int getWidth() { if(Subitems.getCount()>0) return dynamic_cast<ImageResource&>(Subitems[0]).getWidth(); return 0; }
+		int GetWidth() const { if(Subitems.getCount()>0) return dynamic_cast<const ImageResource&>(Subitems[0]).GetWidth(); return 0; }
 		////Returns the height of the first image
-		int getHeight() { if(Subitems.getCount()>0) return dynamic_cast<ImageResource&>(Subitems[0]).getHeight(); return 0; }
+		int GetHeight() const { if(Subitems.getCount()>0) return dynamic_cast<const ImageResource&>(Subitems[0]).GetHeight(); return 0; }
 		////Returns number of frames
-		int getFrameCount() { return FrameCount; }
-		////Creates a new Image animation from this resource
-		ImageAnimation *getAnimation() { 
-			if(Subitems.getCount()) {
-				ImageAnimation *ret=new ImageAnimation(this); 
-				return ret;
-			} else
-				return NULL;
+		int GetFrameCount() const { return FrameCount; }
+
+		virtual ImageAnimation &CreateAnimation(animation::AnimationTimer &controller, bool owner=false) {
+			return *new ImageAnimation(*this, controller, owner);
+		}
+
+		virtual ImageAnimation &CreateAnimation(bool create=false) {
+			return *new ImageAnimation(*this, create);
 		}
 
-		operator ImageAnimation*() { return getAnimation(); }
+		virtual ImageResource &ImageAt(unsigned t) { return *Frames[FrameAt(t)].Image; } //Null Image
+
+		//graphics::RectangularGraphic2D &GraphicAt(unsigned t) { return *Frames[FrameAt(t)].Image; } //Null Image
+
+		unsigned GetTotalLength() const { return TotalLength; }
+
+		ImageResource &operator [](int Frame) {
+			return dynamic_cast<ImageResource&>(Subitems[Frame]);
+		}
+
+		virtual int FrameAt(unsigned t) const;
+
+		virtual int StartOf(unsigned Frame) const;
+
+		virtual int GetDuration(unsigned Frame) const;
+		virtual int GetDuration() const;
+
+		virtual int GetNumberofFrames() const;
 
 	protected:
 		////Total number of frames that this animation have
 		int FrameCount;
 		////Frame durations
-		int *Durations;
+		std::vector<AnimationResourceFrame> Frames;
+		unsigned TotalLength;
 	};
 } }
--- a/Resource/BitmapFontResource.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Resource/BitmapFontResource.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -1,10 +1,13 @@
 #include "BitmapFontResource.h"
 #include "ResourceFile.h"
+#include "..\Engine\Graphics.h"
 
 #ifndef MAX_CHAR_DETECTS
 #define MAX_CHAR_DETECTS	10
 #endif
 
+using namespace gge::graphics;
+
 namespace gge { namespace resource {
 	ResourceBase *LoadBitmapFontResource(File &File, std::istream &Data, int Size) {
 		BitmapFontResource *font=new BitmapFontResource;
@@ -50,26 +53,33 @@
 
 		return font;
 	}
-	void BitmapFontResource::Print(graphics::I2DColorizableGraphicsTarget *target, int X, int Y, string text, graphics::RGBint color, ShadowParams Shadow) {
+	void BitmapFontResource::Print(graphics::ColorizableImageTarget2D *target, int X, int Y, string text, graphics::RGBint color, ShadowParams Shadow) {
 		if(text=="") return;
 
+		RGBint cc=target->GetCurrentColor();
+
 		unsigned int i;
 		if(Shadow.Type==ShadowParams::Flat) {
 			int x=X;
+			target->SetCurrentColor(Shadow.Color);
 			for(i=0;i<text.length();i++) {
 				ImageResource *img=Characters[text[i]];
-				img->DrawColored(target,x+Shadow.Offset.x,Y+Shadow.Offset.y,Shadow.Color);
-				x+=img->getWidth() + Seperator;
+				img->Draw(target,x+Shadow.Offset.x,Y+Shadow.Offset.y);
+				x+=img->GetWidth() + Seperator;
 			}
 		}
+
+		target->SetCurrentColor(color);
 		for(i=0;i<text.length();i++) {
 			ImageResource *img=Characters[text[i]];
-			img->DrawColored(target,X,Y,color);
-			X+=img->getWidth() + Seperator;
+			img->Draw(target,X,Y);
+			X+=img->GetWidth() + Seperator;
 		}
+
+		target->SetCurrentColor(cc);
 	}
 
-	void BitmapFontResource::Print(graphics::I2DColorizableGraphicsTarget *target, int x, int y, int w, string text, graphics::RGBint color, TextAlignment::Type align, ShadowParams Shadow) {
+	void BitmapFontResource::Print(graphics::ColorizableImageTarget2D *target, int x, int y, int w, string text, graphics::RGBint color, TextAlignment::Type align, ShadowParams Shadow) {
 		unsigned i;
 		int l=x;
 		int lstart=0,lword=0;
@@ -82,9 +92,13 @@
 
 		if(text=="") return;
 
+
 		if(Shadow.Type==ShadowParams::Flat)
 			Print(target,x+Shadow.Offset.x,y+Shadow.Offset.y,w,text,Shadow.Color,align);
 
+		RGBint cc=target->GetCurrentColor();
+		target->SetCurrentColor(color);
+
 		if(w==0) {
 			/*align=TextAlignment::Left;
 			w=10000;*/
@@ -98,7 +112,7 @@
 				nextline=true;
 			}
 			else {
-				llen+=Characters[(unsigned char)text[i]]->getWidth()+Seperator;
+				llen+=Characters[(unsigned char)text[i]]->GetWidth()+Seperator;
 
 				if(text[i]==' ' || text[i]==',' || text[i]==')') {
 					lword=i;
@@ -140,14 +154,14 @@
 						ImageResource *img=Characters[(unsigned char)' '];
 						int i;
 						for(i=0;i<Tabsize;i++) {
-							img->DrawColored(target, l, y, color);
-							l+=img->getWidth()+Seperator;
+							img->Draw(target, l, y);
+							l+=img->GetWidth()+Seperator;
 						}
 					}
 					if(text[j]!='\r') {
 						ImageResource *img=Characters[(unsigned char)text[j]];
-						img->DrawColored(target, l, y, color);
-						l+=img->getWidth()+Seperator;
+						img->Draw(target, l, y);
+						l+=img->GetWidth()+Seperator;
 					}
 				}
 
@@ -163,8 +177,14 @@
 				nextline=false;
 			}
 		}
+
+		target->SetCurrentColor(cc);
 	}
-	void BitmapFontResource::Print(graphics::I2DColorizableGraphicsTarget *target, int x, int y, int w, string text, graphics::RGBint color, EPrintData *Data, int DataLen, TextAlignment::Type Align, ShadowParams Shadow) {
+	void BitmapFontResource::Print(graphics::ColorizableImageTarget2D *target, int x, int y, int w, string text, graphics::RGBint color, EPrintData *Data, int DataLen, TextAlignment::Type Align, ShadowParams Shadow) {
+
+		RGBint cc=target->GetCurrentColor();
+		target->SetCurrentColor(color);
+
 		if(text=="") {
 			int d;
 			int xpos=0;
@@ -254,7 +274,7 @@
 				nextline=true;
 			}
 			else {
-				llen+=Characters[(unsigned char)text[i]]->getWidth()+Seperator;
+				llen+=Characters[(unsigned char)text[i]]->GetWidth()+Seperator;
 
 				if(text[i]==' ' || text[i]==',' || text[i]==')') {
 					lword=i;
@@ -323,17 +343,26 @@
 						ImageResource *img=Characters[(unsigned char)' '];
 						int i;
 						for(i=0;i<Tabsize;i++) {
-							img->DrawColored(target,l,y,color);
-							dist=img->getWidth()+Seperator;
+							if(Shadow.Type==ShadowParams::Flat) {
+								target->SetCurrentColor(Shadow.Color);
+								img->Draw(target,l+Shadow.Offset.x,y+Shadow.Offset.y);
+							}
+
+							target->SetCurrentColor(color);
+							img->Draw(target,l,y);
+							dist=img->GetWidth()+Seperator;
 						}
 					}
 					if(text[j]!='\r') {
 						ImageResource *img=Characters[(unsigned char)text[j]];
-						if(Shadow.Type==ShadowParams::Flat)
-							img->DrawColored(target,l+Shadow.Offset.x,y+Shadow.Offset.y,Shadow.Color);
+						if(Shadow.Type==ShadowParams::Flat) {
+							target->SetCurrentColor(Shadow.Color);
+							img->Draw(target,l+Shadow.Offset.x,y+Shadow.Offset.y);
+						}
 
-						img->DrawColored(target,l,y,color);
-						dist=img->getWidth()+Seperator;
+						target->SetCurrentColor(color);
+						img->Draw(target,l,y);
+						dist=img->GetWidth()+Seperator;
 					}
 					for(d=0;d<cchardetectxs;d++) {
 						if(chardetectxs[d].x<(l-sx)+dist/2) {
@@ -371,7 +400,11 @@
 					break;
 				}
 			}
-		}	}
+		}	
+
+		target->SetCurrentColor(cc);
+
+	}
 	void BitmapFontResource::Print_Test(int x, int y, int w, string text, EPrintData *Data, int DataLen, TextAlignment::Type Align) {
 		if(text=="") {
 			int d;
@@ -461,7 +494,7 @@
 				nextline=true;
 			}
 			else {
-				llen+=Characters[(unsigned char)text[i]]->getWidth()+Seperator;
+				llen+=Characters[(unsigned char)text[i]]->GetWidth()+Seperator;
 
 				if(text[i]==' ' || text[i]==',' || text[i]==')') {
 					lword=i;
@@ -528,12 +561,12 @@
 						ImageResource *img=Characters[(unsigned char)' '];
 						int i;
 						for(i=0;i<Tabsize;i++) {
-							dist=img->getWidth()+Seperator;
+							dist=img->GetWidth()+Seperator;
 						}
 					}
 					if(text[j]!='\r') {
 						ImageResource *img=Characters[(unsigned char)text[j]];
-						dist+=img->getWidth()+Seperator;
+						dist+=img->GetWidth()+Seperator;
 					}
 					for(d=0;d<cchardetectxs;d++) {
 						if(chardetectxs[d].x<(l-sx)+dist/2 && j<chardetectxs[d].data->Out.value) {
--- a/Resource/BitmapFontResource.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Resource/BitmapFontResource.h	Tue Jul 26 09:55:07 2011 +0000
@@ -49,32 +49,32 @@
 
 	//protected:
 		////Prints the given text to the target using given color.
-		virtual void Print(graphics::I2DColorizableGraphicsTarget *target, int X, int Y, string Text, graphics::RGBint Color, ShadowParams Shadow=ShadowParams());
+		virtual void Print(graphics::ColorizableImageTarget2D *target, int X, int Y, string Text, graphics::RGBint Color, ShadowParams Shadow=ShadowParams());
 		////Prints the given text to the target using given color. Text is wrapped and aligned as necessary
-		virtual void Print(graphics::I2DColorizableGraphicsTarget *target, int X, int Y, int W, string Text, graphics::RGBint Color, TextAlignment::Type Align=TextAlignment::Left, ShadowParams Shadow=ShadowParams());
+		virtual void Print(graphics::ColorizableImageTarget2D *target, int X, int Y, int W, string Text, graphics::RGBint Color, TextAlignment::Type Align=TextAlignment::Left, ShadowParams Shadow=ShadowParams());
 		////This method is extended to cover meta functionality for advanced text rendering
-		virtual void Print(graphics::I2DColorizableGraphicsTarget *target, int X, int Y, int W, string Text, graphics::RGBint Color, EPrintData *Data, int DataLen, TextAlignment::Type Align=TextAlignment::Left, ShadowParams Shadow=ShadowParams());
+		virtual void Print(graphics::ColorizableImageTarget2D *target, int X, int Y, int W, string Text, graphics::RGBint Color, EPrintData *Data, int DataLen, TextAlignment::Type Align=TextAlignment::Left, ShadowParams Shadow=ShadowParams());
 		////This method is extended to cover meta functionality for advanced text rendering. This function does not render the given text
 		/// it only processes meta data
 		virtual void Print_Test(int X, int Y, int W, string Text, EPrintData *Data, int DataLen, TextAlignment::Type Align);
 
 
 
-		void Print(graphics::I2DColorizableGraphicsTarget &target, int X, int Y, string Text, graphics::RGBint Color, ShadowParams Shadow=ShadowParams()) 
+		void Print(graphics::ColorizableImageTarget2D &target, int X, int Y, string Text, graphics::RGBint Color, ShadowParams Shadow=ShadowParams()) 
 		{ Print(&target, X, Y, Text, Color, Shadow); }
-		void Print(graphics::I2DColorizableGraphicsTarget &target, int X, int Y, int W, string Text, graphics::RGBint Color, TextAlignment::Type Align=TextAlignment::Left, ShadowParams Shadow=ShadowParams()) 
+		void Print(graphics::ColorizableImageTarget2D &target, int X, int Y, int W, string Text, graphics::RGBint Color, TextAlignment::Type Align=TextAlignment::Left, ShadowParams Shadow=ShadowParams()) 
 		{ Print(&target, X, Y, W, Text, Color, Align, Shadow); }
-		void Print(graphics::I2DColorizableGraphicsTarget &target, int X, int Y, int W, string Text, graphics::RGBint Color, EPrintData *Data, int DataLen, TextAlignment::Type Align=TextAlignment::Left, ShadowParams Shadow=ShadowParams())
+		void Print(graphics::ColorizableImageTarget2D &target, int X, int Y, int W, string Text, graphics::RGBint Color, EPrintData *Data, int DataLen, TextAlignment::Type Align=TextAlignment::Left, ShadowParams Shadow=ShadowParams())
 		{ Print(&target, X, Y, W, Text, Color, Data, DataLen, Align, Shadow); }
 
 		////Returns the height of this font, all characters have same height
-		virtual int FontHeight() { return Characters['T']->getHeight(); }
+		virtual int FontHeight() { return Characters['T']->GetHeight(); }
 		////Returns the width of the given text
 		virtual int TextWidth(string Text) { 
 			int i, w=0; 
 			const char *text=Text.c_str(); 
 			for(i=0;text[i];i++) 
-				w+=Characters[(unsigned char)text[i]]->getWidth(); 
+				w+=Characters[(unsigned char)text[i]]->GetWidth(); 
 		
 			return w; 
 		}
--- a/Resource/DataResource.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Resource/DataResource.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -47,10 +47,14 @@
 			else if(gid==GID::Data_Link) {
 				tmpguid.Load(Data);
 
-				dat->Add(SGuid(Data));
+				dat->Add(tmpguid);
 			}
-			else if(gid==0x03300C01) {
+			else if(gid==GID::Data_Color) {
+				dat->Add(ReadFrom<int>(Data));
+			}
+			else if(gid==GID::Data_Font) {
 				FontInitiator f;
+				ReadFrom<int>(Data);//useless gid
 				f=Font::Load(File, Data, ReadFrom<int>(Data));
 				f.file=&File;
 
--- a/Resource/Definitions.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Resource/Definitions.h	Tue Jul 26 09:55:07 2011 +0000
@@ -47,6 +47,8 @@
 		static const Type Data_Link				= 0x02030C07;
 		static const Type Data_Names			= 0x02030101;
 		static const Type Data_Name				= 0x02030102;
+		static const Type Data_Font				= 0x03300C01;
+		static const Type Data_Color			= 0x02030D02;
 
 		//////////////////////////////////////////////////////////////////////////
 		// Gaming resources
--- a/Resource/ImageResource.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Resource/ImageResource.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -17,7 +17,7 @@
 
 		bool lateloading=false;
 		//BYTE *compressionprops;
-		graphics::ColorMode m;
+		graphics::ColorMode::Type m;
 
 		int target=Data.tellg()+Size;
 		while(Data.tellg()<target) {
@@ -86,7 +86,7 @@
 						LzmaDecodeProperties(&state.Properties,img->CompressionProps,LZMA_PROPERTIES_SIZE);
 						state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
 
-						LzmaDecode(&state,tmpdata,size,&processed,img->Data,img->getWidth()*img->getHeight()*img->getBPP(),&processed2);
+						LzmaDecode(&state,tmpdata,size,&processed,img->Data,img->getwidth()*img->getheight()*img->GetBPP	(),&processed2);
 
 						free(state.Probs);
 						delete tmpdata;
@@ -123,20 +123,20 @@
 						int channels=cinfo->num_components;
 
 						if(channels==3)
-							m=graphics::BGR;
+							m=graphics::ColorMode::BGR;
 						else if(channels==4)
-							m=graphics::ABGR_32BPP;
+							m=graphics::ColorMode::ABGR;
 						else if(channels=1)
-							m=graphics::ALPHAONLY_8BPP;
+							m=graphics::ColorMode::Alpha;
 
-						if(img->getMode()!=m)
+						if(img->GetMode()!=ColorMode::ARGB)
 							throw std::runtime_error("Image data size mismatch!");
 
-						int stride=img->getWidth()*channels;
+						int stride=img->GetWidth()*channels;
 						int rowsRead=0;
 
-						Byte ** rowPtr = new Byte * [img->getHeight()];
-						for(i=0;i<img->getHeight();i++)
+						Byte ** rowPtr = new Byte * [img->getheight()];
+						for(i=0;i<img->GetHeight();i++)
 							rowPtr[i]=img->Data+stride*i;
 
 						while(cinfo->output_scanline < cinfo->output_height) {
@@ -174,7 +174,7 @@
 		fseek(gfile,DataLocation,SEEK_SET);
 		
 		if(this->Compression==GID::LZMA) {
-			this->Data.Resize(this->getWidth()*this->getHeight()*this->getBPP());
+			this->Data.Resize(this->GetWidth()*this->GetHeight()*this->GetBPP());
 			Byte *tmpdata=new Byte[DataSize];
 			fread(tmpdata,1,this->DataSize,gfile);
 			size_t processed,processed2;
@@ -183,7 +183,7 @@
 			LzmaDecodeProperties(&state.Properties,this->CompressionProps,LZMA_PROPERTIES_SIZE);
 			state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
 
-			LzmaDecode(&state,tmpdata,DataSize,&processed,this->Data,this->getWidth()*this->getHeight()*this->getBPP(),&processed2);
+			LzmaDecode(&state,tmpdata,DataSize,&processed,this->Data,this->GetWidth()*this->GetHeight()*this->GetBPP(),&processed2);
 
 			free(state.Probs);
 			delete tmpdata;
@@ -216,19 +216,19 @@
 			int channels=cinfo->num_components;
 
 			if(channels==3)
-				Mode=graphics::BGR;
+				Mode=graphics::ColorMode::BGR;
 			else if(channels==4)
-				Mode=graphics::ABGR_32BPP;
+				Mode=graphics::ColorMode::ABGR;
 			else if(channels=1)
-				Mode=graphics::ALPHAONLY_8BPP;
+				Mode=graphics::ColorMode::Alpha;
 
-			Data.Resize(getWidth()*getHeight()*channels);
+			Data.Resize(GetWidth()*GetHeight()*channels);
 
-			int stride=getWidth()*channels;
+			int stride=GetWidth()*channels;
 			int rowsRead=0;
 
-			Byte ** rowPtr = new Byte * [getHeight()];
-			for(i=0;i<getHeight();i++)
+			Byte ** rowPtr = new Byte * [GetHeight()];
+			for(i=0;i<GetHeight();i++)
 				rowPtr[i]=Data+stride*i;
 
 			while(cinfo->output_scanline < cinfo->output_height) {
@@ -258,9 +258,9 @@
 #endif
 		
 		if(Texture.ID>0)
-			DestroyTexture(&Texture);
+			system::DestroyTexture(&Texture);
 
-		Texture = graphics::GenerateTexture(Data, getWidth(), getHeight(), getMode());
+		Texture = graphics::system::GenerateTexture(Data, GetWidth(), GetHeight(), GetMode());
 	}
 
 	bool ImageResource::PNGExport(string filename) {
@@ -283,12 +283,12 @@
 		}
 		setjmp(png_jmpbuf(png_ptr));
 		png_init_io(png_ptr, file);
-		png_set_IHDR(png_ptr, info_ptr, getWidth(), getHeight(),
+		png_set_IHDR(png_ptr, info_ptr, GetWidth(), GetHeight(),
 	       8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE,
 	       PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
 
-		Byte *newdata=new Byte[getWidth()*getHeight()*4];
-		for(i=0;i<getWidth()*getHeight();i++) {
+		Byte *newdata=new Byte[GetWidth()*GetHeight()*4];
+		for(i=0;i<GetWidth()*GetHeight();i++) {
 			newdata[i*4+2]=Data[i*4+0];
 			newdata[i*4+1]=Data[i*4+1];
 			newdata[i*4+0]=Data[i*4+2];
@@ -296,9 +296,9 @@
 		}
 
 		png_write_info(png_ptr, info_ptr);
-		Byte **rows=new Byte*[getHeight()];
-		for(i=0;i<getHeight();i++) {
-			rows[i]=newdata+i*getWidth()*4;
+		Byte **rows=new Byte*[GetHeight()];
+		for(i=0;i<GetHeight();i++) {
+			rows[i]=newdata+i*GetWidth()*4;
 		}
 		png_write_image(png_ptr, rows);
 		png_write_end(png_ptr, NULL);
@@ -395,7 +395,7 @@
 		png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
 
 
-		Resize(width,height,graphics::ARGB_32BPP);
+		Resize(width,height,graphics::ColorMode::ARGB);
 
 		//currently only RGB is supported
 		if(pChannels!=3)
@@ -403,10 +403,10 @@
 
 		for(unsigned y=0;y<height;y++) {
 			for(unsigned x=0;x<width;x++) {
-				Raw2DGraphic::Data[(x+y*width)*4+2]=row_pointers[y][x*3];
-				Raw2DGraphic::Data[(x+y*width)*4+1]=row_pointers[y][x*3+1];
-				Raw2DGraphic::Data[(x+y*width)*4+0]=row_pointers[y][x*3+2];
-				Raw2DGraphic::Data[(x+y*width)*4+3]=0xff;
+				Data[(x+y*width)*4+2]=row_pointers[y][x*3];
+				Data[(x+y*width)*4+1]=row_pointers[y][x*3+1];
+				Data[(x+y*width)*4+0]=row_pointers[y][x*3+2];
+				Data[(x+y*width)*4+3]=0xff;
 			}
 		}
 		
@@ -420,35 +420,5 @@
 
 		return NoError;
 	}
-	void ImageResource::DrawResized(I2DGraphicsTarget *Target, int X, int Y, int W, int H, gge::Alignment::Type Align) {
-
-
-		int h=this->Height(H);
-		int w=this->Width(W);
-
-		if(Align & Alignment::Center)
-			X+=(W-w)/2;
-		else if(Align & Alignment::Right)
-			X+= W-w;
-
-		if(Alignment::isMiddle(Align))
-			Y+=(H-h)/2;
-		else if(Alignment::isBottom(Align))
-			Y+= H-h;
-
-		if(VerticalTiling.Type==ResizableObject::Stretch) {
-			if(HorizontalTiling.Type==ResizableObject::Stretch) {
-				this->Draw(Target, X,Y , w,h);
-			} else {
-				this->DrawHTiled(Target, X,Y , w,h);
-			}
-		} else {
-			if(HorizontalTiling.Type==ResizableObject::Stretch) {
-				this->DrawVTiled(Target, X,Y , w,h);
-			} else {
-				this->DrawTiled(Target, X,Y , w,h);
-			}
-		}
-	}
 
 } }
--- a/Resource/ImageResource.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Resource/ImageResource.h	Tue Jul 26 09:55:07 2011 +0000
@@ -4,6 +4,8 @@
 #include "ResourceBase.h"
 #include "../Engine/Graphics.h"
 #include "ResizableObject.h"
+#include "../Engine/Animation.h"
+#include "../Engine/Image.h"
 
 namespace gge { namespace resource {
 	class File;
@@ -13,7 +15,10 @@
 
 	////This is image resource that holds information about a single image. It supports
 	/// two color modes (ARGB and AL); lzma and jpg compressions
-	class ImageResource : public ResourceBase, public graphics::Colorizable2DGraphic, public graphics::Raw2DGraphic, public ResizableObject {
+	class ImageResource : 
+		public ResourceBase, public ResizableObject, public graphics::RectangularGraphic2D, public ResizableObjectProvider, 
+		protected graphics::ImageData, protected graphics::TextureImage
+	{
 		friend ResourceBase *LoadImageResource(File &File, std::istream &Data, int Size);
 	public:
 		enum PNGReadError {
@@ -35,28 +40,12 @@
 		/// an image object. This flag is used by other systems.
 		bool LeaveData;
 
-		ImageResource() {
-			graphics::Raw2DGraphic::Width=graphics::Raw2DGraphic::Height=0; 
+		ImageResource() : animation::AnimationBase(), TextureImage(), ImageData() {
 			isLoaded=LeaveData=false; Palette=NULL; 
-			Mode=graphics::ARGB_32BPP; 
-			SetResizingOptions(ResizableObject::Single,ResizableObject::Single);
 		}
 
-		ImageResource(int Width, int Height, graphics::ColorMode Mode=graphics::ARGB_32BPP) {
-			isLoaded=LeaveData=true;
-			Palette=NULL;
+		ImageResource(int Width, int Height, graphics::ColorMode::Type Mode=graphics::ColorMode::ARGB) : animation::AnimationBase(), TextureImage(), ImageData() {
 			this->Resize(Width, Height, Mode);
-			SetResizingOptions(ResizableObject::Single,ResizableObject::Single);
-		}
-
-		ImageResource(ImageResource &image, ResizableObject::Tiling Horizontal, ResizableObject::Tiling Vertical) {
-			*this=image;
-			SetResizingOptions(Horizontal, Vertical);
-		}
-
-		ImageResource(ImageResource *image, ResizableObject::Tiling Horizontal, ResizableObject::Tiling Vertical) {
-			*this=*image;
-			SetResizingOptions(Horizontal, Vertical);
 		}
 
 		bool PNGExport(string filename);
@@ -74,13 +63,9 @@
 		PNGReadError ImportPNG(string filename);
 
 		////Returns Bytes/Pixel information
-		int getBPP() { return graphics::getBPP(Mode); }
+		int GetBPP() { return graphics::getBPP(Mode); }
+		graphics::ColorMode::Type GetMode() { return Mode; }
  
-		////Returns the width of the first image
-		int getWidth() { return Raw2DGraphic::Width; }
-		////Returns the height of the first image
-		int getHeight() { return Raw2DGraphic::Height; }
-
 
 		////Destroys used data
 		void destroy() { Data.RemoveReference(); if(Palette) delete Palette; }
@@ -88,41 +73,48 @@
 		////Destroys used data
 		virtual ~ImageResource() { if(Palette) delete Palette; }
 
-
-
-		//For resizable interface
-		ResizableObject::Tiling HorizontalTiling;
-		ResizableObject::Tiling VerticalTiling;
-
-
-		void SetResizingOptions( ResizableObject::Tiling Horizontal, ResizableObject::Tiling Vertical ) {
-			this->HorizontalTiling=Horizontal;
-			this->VerticalTiling=Vertical;
-		}
+		using RectangularGraphic2D::GetHeight;
+		using RectangularGraphic2D::GetWidth;
 
-		virtual void DrawResized(graphics::I2DGraphicsTarget *Target, int X, int Y, int W, int H, Alignment::Type Align=Alignment::Middle_Center);
-		virtual void DrawResized(graphics::I2DGraphicsTarget &Target, int X, int Y, int W, int H, Alignment::Type Align=Alignment::Middle_Center) {
-			DrawResized(&Target, X,Y,W,H,Align);
-		}
-		virtual int  Width(int W=-1) { 
-			if(W==-1) return getWidth();
+		virtual void DeleteAnimation() { } //if used as animation, it will not be deleted
+		virtual ImageResource &CreateAnimation(animation::AnimationTimer &controller, bool owner=false) { return *this; }
+		virtual ImageResource &CreateAnimation(bool create=false) { return *this; }
 
-			return HorizontalTiling.Calculate(getWidth(), W); 
-		}
-		virtual int  Height(int H=-1) { 
-			if(H==-1) return getHeight(); 
-		
-			return VerticalTiling.Calculate(getHeight(), H); 
-		}
-		virtual void Reset(bool Reverse=false) {}
-		virtual void Reverse() {}
-		virtual void Play() {}
-		virtual void Pause() {}
-		virtual void setLoop(bool Loop) {}
-		virtual int getDuration() { return 0; }
+		virtual graphics::RectangularGraphic2D &GraphicAt(unsigned time) { return *this; }
+
+		using TextureImage::GetTexture;
 
 
 	protected:
+		virtual animation::ProgressResult::Type Progress() { return animation::ProgressResult::None; };
+
+		virtual void drawin(graphics::ImageTarget2D& Target, int X, int Y, int W, int H) 
+		{ drawto(Target, graphics::Tiling2D::Both, X,Y, W,H); } 
+
+		virtual void drawin(graphics::ImageTarget2D& Target, graphics::SizeController2D &controller, int X, int Y, int W, int H) 
+		{ drawto(Target, controller, X,Y, W,H); };
+
+		virtual int calculatewidth (int w=-1) const { return getimagewidth(); }
+		virtual int calculateheight(int h=-1) const { return getimageheight(); }
+
+		virtual int calculatewidth (const graphics::SizeController2D &controller, int w=-1) const  { return calculatewidthusing(controller,w); }
+		virtual int calculateheight(const graphics::SizeController2D &controller, int h=-1) const  { return calculateheightusing(controller,h); }
+
+		virtual void draw(graphics::ImageTarget2D& Target, int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4, float S1,float U1, float S2,float U2,float S3,float U3,float S4,float U4) 
+		{ drawto(Target, X1,Y1, X2,Y2, X3,Y3, X4,Y4, S1,U1, S2,U2, S3,U3, S4,U4); }
+		virtual void draw(graphics::ImageTarget2D& Target, int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4) 
+		{ drawto(Target, X1,Y1, X2,Y2, X3,Y3, X4,Y4); }
+		virtual void drawstretched(graphics::ImageTarget2D& Target, int X, int Y, int W, int H)
+		{ drawto(Target, X,Y, W,H); }
+		virtual void draw(graphics::ImageTarget2D& Target, graphics::Tiling2D::Type Tiling, int X, int Y, int W, int H)
+		{ drawto(Target, Tiling, X,Y, W,H); }
+		virtual void draw(graphics::ImageTarget2D& Target, graphics::SizeController2D &controller, int X, int Y, int W, int H)
+		{ drawto(Target, controller, X,Y, W,H); }
+
+		virtual int getwidth () const { if(Texture.ID) return getimagewidth(); else return ImageData::GetWidth(); }
+		virtual int getheight() const { if(Texture.ID) return getimageheight(); else return ImageData::GetHeight(); }
+
+
 		////The file that this image resource is related, used for late loading
 		File *File;
 		////Compression properties read from file, used for late loading
--- a/Resource/ResizableObject.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Resource/ResizableObject.h	Tue Jul 26 09:55:07 2011 +0000
@@ -1,163 +1,24 @@
 #pragma once
 
-#include "../Utils/Margins.h"
-#include "../Utils/BasicMath.h"
-#include "../Engine/Graphics.h"
-#include "../Resource/ResourceBase.h"
+#include "../Engine/Graphic2D.h"
+#include "../Engine/Animation.h"
 
 namespace gge { namespace resource {
 
 	class File;
 
-	class ResizableObject {
+	class ResizableObject : public graphics::SizelessGraphic2D, public virtual animation::AnimationBase  {
 	public:
-
-		enum TileOption {
-			Single=0,
-			Tile,
-			Integral,
-			Stretch,
-		};
-
-		enum IntegralSizeOption {
-			Continous=0,
-			Automatic=1,
-			Manual=2,
-		};
-
-		enum IntegralSizeCalculationMethod {
-			SmallerThanGivenSize,
-			ClosestToGivenSize,
-			FillTheGivenSize
-		};
-
-		class Tiling {
-		public:
-			TileOption Type;
-			IntegralSizeCalculationMethod CalculationMethod;
-
-			Tiling(TileOption Type=Single, IntegralSizeCalculationMethod CalculationMethod=SmallerThanGivenSize) :
-			Type(Type), CalculationMethod(CalculationMethod)
-			{ }
-
-
-			int Calculate(int Original, int Requested) {
-				if(Type==Single)
-					return Original;
-
-				if(Type==Integral) {
-					switch(CalculationMethod) {
-						case SmallerThanGivenSize:
-							return (int)utils::Max(floor((float)Requested/Original), 1)*Original;
-						case ClosestToGivenSize:
-							return (int)utils::Max(utils::Round((float)Requested/Original), 1)*Original;
-						case FillTheGivenSize:
-							return (int)utils::Max(ceil((float)Requested/Original), 1)*Original;
-					}
-				}
-
-				return Requested;
-			}
-		};
-
-		class IntegralSize {
-		public:
-			int Overhead, Increment;
-			IntegralSizeOption Type;
-			IntegralSizeCalculationMethod CalculationMethod;
-
-
-
-			IntegralSize(int Overhead, int Increment, IntegralSizeOption Type=Manual) :
-			Overhead(Overhead), Increment(Increment), Type(Type), CalculationMethod(SmallerThanGivenSize)
-			{ }
-
-			IntegralSize(IntegralSizeOption Type) :
-			Overhead(0), Increment(0), Type(Type), CalculationMethod(SmallerThanGivenSize)
-			{ }
-
-			IntegralSize() :
-			Overhead(0), Increment(0), Type(Continous), CalculationMethod(SmallerThanGivenSize)
-			{ }
-
-			int Calculate(int w, int AutoOverhead=0, int AutoIncrement=1) {
-				if(Type==Continous)
-					return w;
+		ResizableObject() : AnimationBase() { }
+		ResizableObject(animation::AnimationTimer &Controller) : AnimationBase(Controller) { }
 
-				if(w<Overhead)
-					return w;
-			
-				if(Type==Automatic) {
-					Overhead=AutoOverhead;
-					Increment=AutoIncrement;
-				}
-
-				if(CalculationMethod==SmallerThanGivenSize)
-					return (int)utils::Max(floor( ((float)(w-Overhead)) / Increment ), 0)  * Increment + Overhead;
-				else if(CalculationMethod==ClosestToGivenSize)
-					return (int)utils::Max(utils::Round( ((float)(w-Overhead)) / Increment ), 0)  * Increment + Overhead;
-				else
-					return (int)utils::Max(ceil( ((float)(w-Overhead)) / Increment ), 0)  * Increment + Overhead;
-			}
-		};
-
-		static IntegralSize IntegralSizeBestFit(int Overhead, int Increment, IntegralSizeOption Type=Manual) {
-			IntegralSize is(Overhead, Increment, Type);
-			is.CalculationMethod=ClosestToGivenSize;
-
-			return is;
-		}
-
-		static IntegralSize IntegralSizeBestFit(IntegralSizeOption Type=Automatic) {
-			IntegralSize is(Type);
-			is.CalculationMethod=ClosestToGivenSize;
-
-			return is;
-		}
-
-		static IntegralSize IntegralSizeSmaller(int Overhead, int Increment, IntegralSizeOption Type=Manual) {
-			IntegralSize is(Overhead, Increment, Type);
-			is.CalculationMethod=SmallerThanGivenSize;
+		
+	};
 
-			return is;
-		}
-
-		static IntegralSize IntegralSizeSmaller(IntegralSizeOption Type=Automatic) {
-			IntegralSize is(Type);
-			is.CalculationMethod=SmallerThanGivenSize;
-
-			return is;
-		}
-
-		static IntegralSize IntegralSizeFill(int Overhead, int Increment, IntegralSizeOption Type=Manual) {
-			IntegralSize is(Overhead, Increment, Type);
-			is.CalculationMethod=FillTheGivenSize;
-
-			return is;
-		}
-
-		static IntegralSize IntegralSizeFill(IntegralSizeOption Type=Automatic) {
-			IntegralSize is(Type);
-			is.CalculationMethod=FillTheGivenSize;
-
-			return is;
-		}
-
-		virtual void DrawResized(graphics::I2DGraphicsTarget *Target, int X, int Y, int W, int H, Alignment::Type Align=Alignment::Center) =0;
-		virtual void DrawResized(graphics::I2DGraphicsTarget &Target, int X, int Y, int W, int H, Alignment::Type Align=Alignment::Center) { DrawResized(&Target, X, Y, W, H, Align); }
-		virtual void DrawResized(graphics::I2DGraphicsTarget *Target, int X=0, int Y=0, Alignment::Type Align=Alignment::Center) { DrawResized(Target, X, Y, Target->Width(), Target->Height(), Align); }
-		virtual void DrawResized(graphics::I2DGraphicsTarget &Target, int X=0, int Y=0, Alignment::Type Align=Alignment::Center) { DrawResized(&Target, X, Y, Target.Width(), Target.Height(), Align); }
-		virtual int  Width(int W=-1)=0;
-		virtual int  Height(int H=-1)=0;
-		virtual void Reset(bool Reverse=false) {}
-		virtual void Reverse() {}
-		virtual void Play() {}
-		virtual void Pause() {}
-		virtual void setLoop(bool Loop) {}
-		virtual int  getDuration() { return 0; }
-		virtual utils::Margins getBorderWidth() { return utils::Margins(0); }
-
-		virtual ~ResizableObject() {}
+	class ResizableObjectProvider : public animation::AnimationProvider {
+	public:
+		virtual ResizableObject &CreateAnimation(animation::AnimationTimer &controller, bool owner=false) = 0;
+		virtual ResizableObject &CreateAnimation(bool create=false) = 0;
 	};
 
 } }
--- a/Resource/ResourceBase.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Resource/ResourceBase.h	Tue Jul 26 09:55:07 2011 +0000
@@ -8,6 +8,7 @@
 #include "Definitions.h"
 
 #include <fstream>
+#include <iosfwd>
 
 using namespace gge;
 
--- a/Resource/ResourceFile.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Resource/ResourceFile.h	Tue Jul 26 09:55:07 2011 +0000
@@ -3,6 +3,7 @@
 #include <stdexcept>
 #include <iostream>
 #include <fstream>
+#include <functional>
 
 #include "GRE.h"
 #include "../Utils/Collection.h"
--- a/Resource/SoundResource.cpp	Thu Jul 21 11:46:42 2011 +0000
+++ b/Resource/SoundResource.cpp	Tue Jul 26 09:55:07 2011 +0000
@@ -1,6 +1,7 @@
 #include "SoundResource.h"
 #include "ResourceFile.h"
 #include "../External/LZMA/LzmaDecode.h"
+#include "../Engine/Sound.h"
 
 using namespace std;
 using namespace gge::sound;
@@ -75,4 +76,9 @@
 
 		return snd;
 	}
+
+	void SoundResource::Prepare( GGEMain &main ) {
+		Buffer=sound::system::CreateSoundBuffer(Format, Data, Size);
+	}
+
 } }
--- a/Resource/SoundResource.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Resource/SoundResource.h	Tue Jul 26 09:55:07 2011 +0000
@@ -30,6 +30,10 @@
 
 		SoundResource() { Buffer=NULL; Data=NULL; Size=0; Format.BitsPerSample=Format.Channels=0; }
 
+		operator gge::sound::system::SoundBufferHandle() {
+			return Buffer;
+		}
+
 		////Destroys used data
 		void destroy() { if(Data) delete Data; }
 		////Destroys used data
@@ -39,5 +43,7 @@
 		gge::sound::system::SoundBufferHandle Buffer;
 
 		gge::sound::Wave *CreateWave() { return new gge::sound::Wave(Buffer); }
+
+		virtual void Prepare(GGEMain &main);
 	};
 } }
--- a/Utils/BasicMath.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Utils/BasicMath.h	Tue Jul 26 09:55:07 2011 +0000
@@ -22,6 +22,7 @@
 //COPYRIGHT
 //	Cem Kalyoncu, DarkGaze.Org (cemkalyoncu[at]gmail[dot]com)
 
+#pragma once
 
 #include <cmath>
 
@@ -29,22 +30,34 @@
 namespace gge { namespace utils {
 
 	template <class T_>
-	inline int Round(T_ num) {
-		return (int)(num+0.5f); 
+	inline T_ Round(T_ num) {
+		return std::floor(num+0.5f); 
 	}
 
 	template <class T_>
-	inline float Round(T_ num, int digits) {
+	inline T_ Round(const T_ &num, int digits) {
 		T_ d=std::pow(10.0f, digits);
-		return ((int)(num*d+0.5f))/d;
+		return std::floor(num*d+0.5f)/d;
+	}
+
+	//accepts both terminals as in range
+	template <class T_, class U_, class V_>
+	bool InRange(const T_ &num, const U_ &n1, const V_ &n2) {
+		if(n1<n2)
+			return num>=n1 && num<=n2;
+		else
+			return num>=n2 && num<=n1;
 	}
 
 	template <class T_, class U_>
-	T_ Max(T_ num1, U_ num2) { return num1>num2 ? num1 : num2; }
-
+	T_ Max(const T_ &num1, const U_ &num2) { return num1>num2 ? num1 : num2; }
+	
 	template <class T_, class U_>
-	T_ Min(T_ num1, U_ num2) { return num1<num2 ? num1 : num2; }
+	T_ Min(const T_ &num1, const U_ &num2) { return num1<num2 ? num1 : num2; }
 
-
+	template <class T_>
+	inline T_ PositiveMod(const T_ &num, const T_ &mod) {
+		return num<0 ? mod + (num%mod) : num%mod;
+	}
 }}
 
--- a/Utils/CastableManagedBuffer.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Utils/CastableManagedBuffer.h	Tue Jul 26 09:55:07 2011 +0000
@@ -33,13 +33,14 @@
 #include <cstring>
 #include <stdexcept>
 #include <cstdlib>
+#include "RefCounter.h"
 
 namespace gge { namespace utils {
 	template <class T_>
 	class CastableManagedBuffer : RefCounter<CastableManagedBuffer<T_> > {
 		template<class O_>
 		friend class CastableManagedBuffer;
-		friend class RefCounter;
+		friend class RefCounter<CastableManagedBuffer<T_> >;
 		friend void std::swap<T_>(CastableManagedBuffer<T_> &left, CastableManagedBuffer<T_> &right);
 	public:
 		CastableManagedBuffer() : sizefactor(1), noresizer(false) {
@@ -289,12 +290,13 @@
 		float sizefactor;
 
 	};
-}
+
+} }
 
 namespace std {
 	//untested for std compatibility, swaps to buffers in O(1)
 	template<class T_>
-	void swap(gge::CastableManagedBuffer<T_> &left,gge::CastableManagedBuffer<T_> &right) {
+	void swap(gge::utils::CastableManagedBuffer<T_> &left,gge::utils::CastableManagedBuffer<T_> &right) {
 		T_** d;
 		int *s;
 		int *rc;
@@ -319,4 +321,4 @@
 		right.noresizer=nr;
 		right.sizefactor=sf;
 	}
-} }
+}
--- a/Utils/Collection.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Utils/Collection.h	Tue Jul 26 09:55:07 2011 +0000
@@ -833,7 +833,7 @@
 		void grow(int amount=growth) {
 			list.Resize(list.GetSize()+amount);
 
-			std::memset(list.GetBuffer()+(list.GetSize()-amount)*sizeof(T_*),0,sizeof(T_*)*amount);
+			std::memset(list.GetBuffer()+(list.GetSize()-amount),0,sizeof(T_*)*amount);
 		}
 
 		void removeat(int absolutepos) {
--- a/Utils/Point2D.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Utils/Point2D.h	Tue Jul 26 09:55:07 2011 +0000
@@ -43,6 +43,7 @@
 #ifdef GGE_XMLSERVICES
 #include "../External/XmlParser/xmlParser.h"
 #endif
+#include "BasicMath.h"
 
 
 #define POINT2D_EXISTS
@@ -250,18 +251,18 @@
 		void Rotate(FloatingPoint angle) {
 			T_ new_x;
 			FloatingPoint cosa=cosfn(angle), sina=sinfn(angle);
-			new_x = x*cosa - y*sina;
-			y     = x*sina + y*cosa;
+			new_x = (int)Round(x*cosa - y*sina);
+			y     = (int)Round(x*sina + y*cosa);
 
-			x     = new_x;
+			x     = (int)Round(new_x);
 		}
 		void Rotate(FloatingPoint angle, const basic_Point2D &origin) {
 			FloatingPoint cosa=std::cos(angle), sina=std::sin(angle);
 
 			basic_Point2D temp=*this-origin;
 
-			x	= temp.x*cosa - temp.y*sina;
-			y   = temp.x*sina + temp.y*cosa;
+			x	= (int)Round(temp.x*cosa - temp.y*sina);
+			y   = (int)Round(temp.x*sina + temp.y*cosa);
 
 			*this += origin;
 		}
--- a/Utils/SortedCollection.h	Thu Jul 21 11:46:42 2011 +0000
+++ b/Utils/SortedCollection.h	Tue Jul 26 09:55:07 2011 +0000
@@ -787,7 +787,7 @@
 		}
 
 		T_ &Get(int Index) {
-			T_ *r=get_(Index)->GetPtr();
+			Wrapper *r=get_(Index);
 
 			if(r==NULL)
 				throw std::out_of_range("Index out of range");
@@ -796,7 +796,7 @@
 		}
 		
 		const T_ &Get(int Index) const {
-			const T_ *r=get_(Index);
+			const Wrapper *r=get_(Index);
 
 			if(r==NULL)
 				throw std::out_of_range("Index out of range");
@@ -917,6 +917,24 @@
 			return NULL;
 		}
 
+		const Wrapper *get_(int Index) const {
+			if(Index<0 || Index>*count)
+				return NULL;
+
+			const Wrapper *c=*head;
+
+			while(c) {
+				if(!Index)
+					return c;
+
+				Index--;
+				c=c->next;
+			}
+
+
+			return NULL;
+		}
+
 		void dealloc() {
 			Wrapper *c=*head;
 

mercurial