* Engine and Effects are adapted to new utils

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

author
cemkalyoncu
date
Mon, 18 Jul 2011 22:25:11 +0000
changeset 30
5a1daa2eb409
parent 29
e0904c8bf1d3
child 31
f95ed30e87ae

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

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.h file | annotate | diff | comparison | revisions
Engine/Animator.cpp file | annotate | diff | comparison | revisions
Engine/CustomLayer.cpp file | annotate | diff | comparison | revisions
Engine/CustomLayer.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/GGE.h file | annotate | diff | comparison | revisions
Engine/GGEMain.cpp file | annotate | diff | comparison | revisions
Engine/GGEMain.h file | annotate | diff | comparison | revisions
Engine/GraphicLayers.cpp file | annotate | diff | comparison | revisions
Engine/GraphicLayers.h file | annotate | diff | comparison | revisions
Engine/Graphics.cpp file | annotate | diff | comparison | revisions
Engine/Graphics.h file | annotate | diff | comparison | revisions
Engine/Input.cpp file | annotate | diff | comparison | revisions
Engine/Input.h file | annotate | diff | comparison | revisions
Engine/Layer.cpp file | annotate | diff | comparison | revisions
Engine/Layer.h file | annotate | diff | comparison | revisions
Engine/Multimedia.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
Engine/Sound.h file | annotate | diff | comparison | revisions
Engine/Wave.cpp 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/DataResource.h file | annotate | diff | comparison | revisions
Resource/FolderResource.h file | annotate | diff | comparison | revisions
Resource/GRE.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.cpp file | annotate | diff | comparison | revisions
Resource/ResourceFile.h file | annotate | diff | comparison | revisions
Utils/Bounds2D.h file | annotate | diff | comparison | revisions
Utils/ConsumableEvent.h file | annotate | diff | comparison | revisions
Utils/EventChain.h file | annotate | diff | comparison | revisions
Utils/GGE.h file | annotate | diff | comparison | revisions
Utils/Iterator.h file | annotate | diff | comparison | revisions
Utils/ManagedBuffer.h file | annotate | diff | comparison | revisions
Utils/Margins.h file | annotate | diff | comparison | revisions
Utils/Point2D.h file | annotate | diff | comparison | revisions
Utils/Rectangle2D.h file | annotate | diff | comparison | revisions
Utils/SortedCollection.h file | annotate | diff | comparison | revisions
--- a/Effects/CountingText.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Effects/CountingText.h	Mon Jul 18 22:25:11 2011 +0000
@@ -1,6 +1,5 @@
 #pragma once
 
-#include "../Utils/GGE.h"
 #include "../Resource/GRE.h"
 #include "../Engine/Animator.h"
 #include "../Engine/Graphics.h"
@@ -21,7 +20,7 @@
 		////Text shadow, default is none
 		gge::ShadowParams Shadow;
 		////Alignment of the text, default is left
-		gge::TextAlignment Align;
+		gge::TextAlignment::Type Align;
 		////Width of the text
 		int Width;
 		////Number of decimal places, default is 0
@@ -33,7 +32,7 @@
 
 
 		////Initializes the effect
-		CountingText(resource::BitmapFontResource *Font=NULL, graphics::RGBint color=graphics::RGBint(0xff000000), int Width=0, TextAlignment Align=TEXTALIGN_LEFT, ShadowParams Shadow=ShadowParams(), int Decimals=0) : 
+		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),
--- a/Effects/Flip.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Effects/Flip.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -4,6 +4,7 @@
 
 using namespace gge::resource;
 using namespace gge::graphics;
+using namespace gge::utils;
 
 namespace gge { namespace effects {
 	void FlipEffect::Draw(I2DGraphicsTarget *Layer,int X,int Y) {
--- a/Effects/Flip.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Effects/Flip.h	Mon Jul 18 22:25:11 2011 +0000
@@ -1,6 +1,5 @@
 #pragma once
 
-#include "../Utils/GGE.h"
 #include "../Resource/GRE.h"
 #include "../Engine/Animator.h"
 #include "../Engine/Graphics.h"
@@ -35,8 +34,8 @@
 		float Perspective;
 		int ETA;
 
-		Point PivotFront;
-		Point PivotBack;
+		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); }
--- a/Effects/LayerMover.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Effects/LayerMover.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -1,5 +1,7 @@
 #include "LayerMover.h"
 
+using namespace gge::utils;
+
 namespace gge { namespace effects {
 	void LayerMover::Setup(Point From, Point To, int Time) {
 
@@ -7,8 +9,7 @@
 		current=from;
 		to=To;
 
-		Target->X=(int)from.x;
-		Target->Y=(int)from.y;
+		Target->BoundingBox.MoveTo(from);
 		this->progressed=0;
 
 		if(Time) {
@@ -19,13 +20,16 @@
 			speed.x=0;
 			speed.y=0;
 			current=from=to;
-			Target->X=(int)to.x;
-			Target->Y=(int)to.y;
+			Target->BoundingBox.MoveTo(to);
 		}
 	}
 
+	void LayerMover::Setup( utils::Point To, int Time ) {
+		Setup(Point((int)current.x,(int)current.y), To, Time);
+	}
+
 	bool LayerMover::isFinished() {
-		return current.x==to.x && current.y==to.y;
+		return current==to;
 	}
 
 	void LayerMover::Process(int Time) {
@@ -39,7 +43,6 @@
 			if(current.x>to.x)
 				current.x=to.x;
 		}
-		Target->X=(int)current.x;
 
 
 		if(from.y>to.y) {
@@ -52,7 +55,22 @@
 			if(current.y>to.y)
 				current.y=to.y;
 		}
-		Target->Y=(int)current.y;
+		Target->BoundingBox.MoveTo(current);
 
 	}
+
+	LayerMover::LayerMover( LayerBase *Target ) :
+	speed(0,0),
+		current(Target->BoundingBox.TopLeft()),
+		Target(Target), FinishedEvent("Finished", this) {
+		AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
+	}
+
+	LayerMover::LayerMover( LayerBase &Target ) :
+	speed(0,0),
+		current(Target.BoundingBox.TopLeft()),
+		Target(&Target), FinishedEvent("Finished", this) {
+		AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
+	}
+
 } }
--- a/Effects/LayerMover.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Effects/LayerMover.h	Mon Jul 18 22:25:11 2011 +0000
@@ -1,6 +1,5 @@
 #pragma once
 
-#include "../Utils/GGE.h"
 #include "../Resource/GRE.h"
 #include "../Engine/Animator.h"
 #include "../Engine/Graphics.h"
@@ -20,32 +19,20 @@
 		LayerBase *Target;
 
 		////Initializes the effect
-		LayerMover(LayerBase *Target) :
-			speed(0,0),
-			current((float)Target->X, (float)Target->Y),
-			Target(Target), FinishedEvent("Finished", this)
-		{
-			AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
-		}
+		LayerMover(LayerBase *Target);
 		////Initializes the effect
-		LayerMover(LayerBase &Target) :
-			speed(0,0),
-			current((float)Target.X, (float)Target.Y),
-			Target(&Target), FinishedEvent("Finished", this)
-		{
-			AnimatorBase::FinishedEvent.DoubleLink(FinishedEvent);
-		}
+		LayerMover(LayerBase &Target);
 		////Sets source and destination to the given values and allows time duration to reach the
 		/// destination
-		void Setup(Point From, Point To, int Time);
+		void Setup(utils::Point From, utils::Point To, int Time);
 		////Sets current destination to the given value and allows time duration to reach it
-		void Setup(Point To, int Time) { Setup(Point((int)current.x,(int)current.y), To, Time); }
+		void Setup(utils::Point To, int Time);
 
 	protected:
-		Point2D from;
-		Point2D to;
-		Point2D current;
-		Point2D speed;
+		utils::Point2D from;
+		utils::Point2D to;
+		utils::Point2D current;
+		utils::Point2D speed;
 
 		virtual bool isFinished();
 		virtual void Process(int Time);
--- a/Effects/LayerResizer.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Effects/LayerResizer.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -1,15 +1,16 @@
 #include "LayerResizer.h"
+#include "..\Utils\BasicMath.h"
+
+using namespace gge::utils;
+
 namespace gge { namespace effects {
-	void LayerResizer::Setup(gge::Rectangle From, gge::Rectangle To, int Time) {
+	void LayerResizer::Setup(utils::Rectangle From, utils::Rectangle To, int Time) {
 
 		from=Rectangle2D(From);
 		current=from;
 		to=To;
 
-		Target->X=(int)from.Left;
-		Target->Y=(int)from.Top;
-		Target->W=(int)from.Width;
-		Target->H=(int)from.Height;
+		Target->BoundingBox=from;
 		this->progressed=0;
 
 		if(Time) {
@@ -25,15 +26,16 @@
 			speed.Width=0;
 			speed.Height=0;
 			current=from=to;
-			Target->X=(int)to.Left;
-			Target->Y=(int)to.Top;
-			Target->W=(int)to.Width;
-			Target->H=(int)to.Height;
+			Target->BoundingBox=to;
 		}
 	}
 
+	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);
+	}
+
 	bool LayerResizer::isFinished() {
-		return current.Left==to.Left && current.Top==to.Top && current.Width==to.Width && current.Height==to.Height;
+		return current==to;
 	}
 
 	void LayerResizer::Process(int Time) {
@@ -47,7 +49,7 @@
 			if(current.Left>to.Left)
 				current.Left=to.Left;
 		}
-		Target->X=Round(current.Left);
+		Target->BoundingBox.Left=Round(current.Left);
 
 
 		if(from.Top>to.Top) {
@@ -60,7 +62,7 @@
 			if(current.Top>to.Top)
 				current.Top=to.Top;
 		}
-		Target->Y=Round(current.Top);
+		Target->BoundingBox.Top=Round(current.Top);
 
 
 		if(from.Width>to.Width) {
@@ -73,7 +75,6 @@
 			if(current.Width>to.Width)
 				current.Width=to.Width;
 		}
-		Target->W=Round(current.Width);
 
 
 		if(from.Height>to.Height) {
@@ -86,6 +87,7 @@
 			if(current.Height>to.Height)
 				current.Height=to.Height;
 		}
-		Target->H=Round(current.Height);
+
+		Target->BoundingBox.SetSize(Round(current.Width), Round(current.Height));
 	}
 } }
--- a/Effects/LayerResizer.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Effects/LayerResizer.h	Mon Jul 18 22:25:11 2011 +0000
@@ -1,10 +1,10 @@
 #pragma once
 
-#include "../Utils/GGE.h"
 #include "../Resource/GRE.h"
 #include "../Engine/Animator.h"
 #include "../Engine/Graphics.h"
 #include "../Engine/Layer.h"
+#include "../Utils/Rectangle2D.h"
 
 namespace gge { namespace effects {
 
@@ -22,7 +22,7 @@
 		////Initializes the effect
 		LayerResizer(LayerBase *Target) :
 			speed(0,0 , 0,0),
-			current((float)Target->X, (float)Target->Y, (float)Target->W, (float)Target->H),
+			current((utils::Bounds2D)Target->BoundingBox),
 			Target(Target),
 			FinishedEvent("Finished", this)
 		{
@@ -32,7 +32,7 @@
 		////Initializes the effect
 		LayerResizer(LayerBase &Target) :
 			speed(0,0 , 0,0),
-			current((float)Target.X, (float)Target.Y, (float)Target.W, (float)Target.H),
+			current((utils::Bounds2D)Target.BoundingBox),
 			Target(&Target),
 			FinishedEvent("Finished", this)
 		{
@@ -40,15 +40,15 @@
 		}
 		////Sets source and destination to the given values and allows time duration to reach the
 		/// destination
-		void Setup(gge::Rectangle From, gge::Rectangle To, int Time);
+		void Setup(utils::Rectangle From, utils::Rectangle To, int Time);
 		////Sets current destination to the given value and allows time duration to reach it
-		void Setup(gge::Rectangle To, int Time) { Setup(gge::Rectangle(Round(current.Left), Round(current.Top), Round(current.Width), Round(current.Height)), To, Time); }
+		void Setup(utils::Rectangle To, int Time);
 
 	protected:
-		Rectangle2D from;
-		Rectangle2D to;
-		Rectangle2D current;
-		Rectangle2D speed;
+		utils::Rectangle2D from;
+		utils::Rectangle2D to;
+		utils::Rectangle2D current;
+		utils::Rectangle2D speed;
 
 		virtual bool isFinished();
 		virtual void Process(int Time);
--- a/Effects/Tinting.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Effects/Tinting.h	Mon Jul 18 22:25:11 2011 +0000
@@ -1,6 +1,5 @@
 #pragma once
 
-#include "../Utils/GGE.h"
 #include "../Resource/GRE.h"
 #include "../Engine/Animator.h"
 #include "../Engine/Graphics.h"
--- a/Engine/Animator.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/Animator.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -7,9 +7,8 @@
 	Collection<AnimatorBase> Animators;
 
 	void Animator_Signal(IntervalObject *interval, void *data) {
-		Animators.ResetIteration();
-		foreach(AnimatorBase, anim, Animators)
-			anim->Progress();
+		for(Collection<AnimatorBase>::Iterator i=Animators.First();i.isValid();i.Next())
+			i->Progress();
 	}
 
 	void InitializeAnimation(GGEMain *main) {
--- a/Engine/CustomLayer.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/CustomLayer.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -4,69 +4,48 @@
 #include <gl/gl.h>
 
 using namespace gge::graphics;
+using namespace gge::utils;
 
 namespace gge {
 	namespace graphics {
 		extern RGBfloat CurrentLayerColor;
-		extern int trX,trY;
-		extern int scX,scY,scW,scH;
-	}
-
-	CustomLayer::CustomLayer(CustomRenderer Renderer,int X, int Y, int W, int H) : LayerBase() {
-		this->X=X;
-		this->Y=Y;
-		this->W=W;
-		this->H=H;
-		this->Renderer=Renderer;
-
-		Xs=-10;
-		Xe= 10;
-		Ys=-10;
-		Ye= 10;
-		Zs=-10;
-		Ze= 10;
+		extern Point translate;
+		extern Rectangle scissors;
 	}
 
 	void CustomLayer::Render() {
-		int pscX,pscY,pscW,pscH;
-		trX+=X;
-		trY+=Y;
+		Rectangle psc;
+		translate+=BoundingBox.TopLeft();
 		glPushAttrib(GL_SCISSOR_BIT);
 		glEnable(GL_SCISSOR_TEST);
 
-		pscX=scX;
-		pscY=scY;
-		pscW=scW;
-		pscH=scH;
+		psc=scissors;
 
-		int r=scX+scW;
-		int b=scY+scH;
+		int r=scissors.Right();
+		int b=scissors.Bottom();
 
 		glEnable(GL_SCISSOR_TEST);
-		if(trX>scX)
-			scX=trX;
-		if(trY>scY)
-			scY=trY;
-		if(trY+H<b)
-			b=(H+trY);
-		if(trX+W<r)
-			r=(W+trX);
+		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());
 
-		scW=r-scX;
-		scH=b-scY;
+		scissors.SetRight(r);
+		scissors.SetBottom(b);
 
-		if(scH<=0 || scW<=0) {
-			scX=pscX;
-			scY=pscY;
-			scW=pscW;
-			scH=pscH;
+		if(r<=scissors.Left || b<=scissors.Top) {
+			return;
 		}
 
-		glScissor(scX, (ScreenSize.y-scY)-scH, scW, scH);
+		glScissor(scissors.Left, (ScreenSize.Height-scissors.Top)-scissors.Height, scissors.Width, scissors.Height);
 
 
 		glColor4f(1,1,1,1);
-		glViewport(X, (Main.H-Y)-H, W, H);
+		glViewport(BoundingBox.Left, (Main.getHeight()-BoundingBox.Top)-BoundingBox.Height(), BoundingBox.Width(), BoundingBox.Height());
 		glClear(GL_DEPTH_BUFFER_BIT);
 		glMatrixMode(GL_PROJECTION);
 		glPushMatrix();
@@ -81,7 +60,7 @@
 		glBindTexture(GL_TEXTURE_2D, -1);
 		glDepthFunc(GL_LESS);
 
-		this->Renderer();
+		Renderer();
 
 		glDepthFunc(GL_LEQUAL);
 
@@ -93,15 +72,21 @@
 		glMatrixMode(GL_MODELVIEW);
 		glColor4fv(CurrentLayerColor.vect);
 		glClear(GL_DEPTH_BUFFER_BIT);
-		glViewport(0, 0, Main.W, Main.H);
+		glViewport(0, 0, Main.getWidth(), Main.getHeight());
 		
-		scX=pscX;
-		scY=pscY;
-		scW=pscW;
-		scH=pscH;
+		scissors=psc;
 
 		glPopAttrib();
-		trX-=X;
-		trY-=Y;
+		translate-=BoundingBox.TopLeft();
 	}
+
+	void CustomLayer::init() {
+		Xs=-10;
+		Xe= 10;
+		Ys=-10;
+		Ye= 10;
+		Zs=-10;
+		Ze= 10;
+	}
+
 }
\ No newline at end of file
--- a/Engine/CustomLayer.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/CustomLayer.h	Mon Jul 18 22:25:11 2011 +0000
@@ -1,18 +1,29 @@
 #pragma once
 
 #include "Layer.h"
+#include <functional>
 
 namespace gge {
 
-	typedef void (*CustomRenderer)();
 
 	class CustomLayer : public LayerBase {
 	public:
-		CustomLayer(CustomRenderer Renderer, int X=0, int Y=0, int W=100, int H=100);
+		typedef std::function<void()> CustomRenderer;
+
+		CustomLayer(CustomRenderer Renderer) : Renderer(Renderer), LayerBase() { init(); }
+
+		CustomLayer(CustomRenderer Renderer, const utils::Bounds &b) : Renderer(Renderer), LayerBase(b) { init(); }
+
+		CustomLayer(CustomRenderer Renderer, int L, int T, int R, int B) : Renderer(Renderer), LayerBase(L,T,R,B) { init(); }
+
+		CustomLayer(CustomRenderer Renderer, int X,int Y) : Renderer(Renderer), LayerBase(X,Y) { init(); }
+
+		CustomLayer(CustomRenderer Renderer, const utils::Point &p) : Renderer(Renderer), LayerBase(p) { init(); }
 
 		virtual void Render();
 
 		virtual void Clear() { }
+		void init();
 
 		float Xs, Xe, Ys, Ye, Zs, Ze;
 
--- a/Engine/Font.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/Font.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -59,17 +59,17 @@
 		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 Align) {
+	void Font::Print(I2DColorizableGraphicsTarget *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 Align) {
+	void Font::Print(I2DColorizableGraphicsTarget *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);
 	}
-	void Font::Print_Test(int X, int Y, int W, string Text, EPrintData *Data, int DataLen, TextAlignment Align) {
+	void Font::Print_Test(int X, int Y, int W, string Text, EPrintData *Data, int DataLen, TextAlignment::Type Align) {
 		FontRenderer *r;
 		if(r=getRenderer())
 			r->Print_Test(X, Y, W, Text, Data, DataLen, Align);
--- a/Engine/Font.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/Font.h	Mon Jul 18 22:25:11 2011 +0000
@@ -31,7 +31,7 @@
 
 		Font &operator =(Font &);
 		Font &operator =(const FontStyle);
-		
+
 
 		static FontInitiator Load(resource::File* file,FILE* gfile,int sz);
 
@@ -47,39 +47,38 @@
 
 
 
-
 		//Print Functions
 		////Prints the given text to the target using given color.
 		void Print(graphics::I2DColorizableGraphicsTarget *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 Align=TEXTALIGN_LEFT);
+		void Print(graphics::I2DColorizableGraphicsTarget *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 Align=TEXTALIGN_LEFT);
+		void Print(graphics::I2DColorizableGraphicsTarget *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 Align);
+		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) 
 		{ Print(&target, X, Y, Text); }
-		void Print(graphics::I2DColorizableGraphicsTarget &target, int X, int Y, int W, string Text, TextAlignment Align=TEXTALIGN_LEFT) 
+		void Print(graphics::I2DColorizableGraphicsTarget &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 Align=TEXTALIGN_LEFT)
+		void Print(graphics::I2DColorizableGraphicsTarget &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, Point p, string Text) 
+		void Print(graphics::I2DColorizableGraphicsTarget &target, utils::Point p, string Text) 
 		{ Print(&target, p.x, p.y, Text); }
-		void Print(graphics::I2DColorizableGraphicsTarget &target, Point p, int W, string Text, TextAlignment Align=TEXTALIGN_LEFT) 
+		void Print(graphics::I2DColorizableGraphicsTarget &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, Point p, int W, string Text, EPrintData *Data, int DataLen, TextAlignment Align=TEXTALIGN_LEFT)
+		void Print(graphics::I2DColorizableGraphicsTarget &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, Point p, string Text) 
+		void Print(graphics::I2DColorizableGraphicsTarget *target, utils::Point p, string Text) 
 		{ Print(target, p.x, p.y, Text); }
-		void Print(graphics::I2DColorizableGraphicsTarget *target, Point p, int W, string Text, TextAlignment Align=TEXTALIGN_LEFT) 
+		void Print(graphics::I2DColorizableGraphicsTarget *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, Point p, int W, string Text, EPrintData *Data, int DataLen, TextAlignment Align=TEXTALIGN_LEFT)
+		void Print(graphics::I2DColorizableGraphicsTarget *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	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/FontRenderer.h	Mon Jul 18 22:25:11 2011 +0000
@@ -9,30 +9,16 @@
 namespace gge {
 
 	////Text alignment constants
-	enum TextAlignment {
-		TEXTALIGN_LEFT=8,
-		TEXTALIGN_CENTER=32,
-		TEXTALIGN_RIGHT=16
-	};
+	class TextAlignment {
+	public:
+		enum Type {
+			Left		= 8 ,
+			Center		= 32,
+			Right		= 16,
+		};
 
-	////Extended print meta data types. This enum can be changed
-	/// breaking compatibility
-	enum EPrintMetaDataTypes {
-		////This is not used
-		EMT_None=0,
-		////Simple spacing, gives the specified amount of
-		/// pixels as space between two characters
-		EMT_Spacing=1,
-		////Detects the pixel position of a given character
-		EMT_PositionDetect,
-		////Changes the color after a given point
-		EMT_Color,
-		////Changes shadow color after a given point
-		EMT_ShadowColor,
-		////Detects the character that is closest to the given point
-		EMT_CharacterDetect,
-		////Toggles word wrap
-		EMT_Wrap
+	private:
+		TextAlignment() {}
 	};
 
 	////Base type for shadow parameters
@@ -46,18 +32,18 @@
 
 		////Type of the shadow
 		ShadowTypes Type;
-		Point Offset;
+		utils::Point Offset;
 		////Shadow color
 		graphics::RGBint Color;
 
-		ShadowParams() : Type(None), Offset(Point(1,2)), Color(0x60808080) 
+		ShadowParams() : Type(None), Offset(utils::Point(1,2)), Color(0x60808080) 
 		{ }
 
 		ShadowParams(ShadowTypes Type, graphics::RGBint color, int XDist, int YDist) : 
-			Type(Type), Offset(Point(XDist, YDist)), Color(color) 
+			Type(Type), Offset(utils::Point(XDist, YDist)), Color(color) 
 		{ }
 
-		ShadowParams(ShadowTypes Type, graphics::RGBint color, Point Offset=Point(1,2)) : 
+		ShadowParams(ShadowTypes Type, graphics::RGBint color, utils::Point Offset=utils::Point(1,2)) : 
 			Type(Type), Color(color), Offset(Offset) 
 		{ }
 
@@ -74,10 +60,28 @@
 			return s;
 		}
 	};
+
 	////Extended print data structure, this structure can be changed
 	struct EPrintData {
 		////Type of the meta data
-		EPrintMetaDataTypes Type;
+		enum EPrintDataTypes {
+			////This is not used
+			None=0,
+			////Simple spacing, gives the specified amount of
+			/// pixels as space between two characters
+			Spacing=1,
+			////Detects the pixel position of a given character
+			PositionDetect,
+			////Changes the color after a given point
+			Color,
+			////Changes shadow color after a given point
+			ShadowColor,
+			////Detects the character that is closest to the given point
+			CharacterDetect,
+			////Toggles word wrap
+			Wrap
+		} Type;
+
 		////Position of the related character
 		int CharPosition;
 		////Input data, depending on the type one of the
@@ -98,10 +102,10 @@
 			int value;
 		} Out;
 
-		////Default constuctor
+		////Default constructor
 		EPrintData() { 
 			CharPosition=-1;
-			Type=EMT_None;
+			Type=None;
 			In.color=0x0;
 			Out.position.x=0;
 			Out.position.y=0;
@@ -114,12 +118,12 @@
 		////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;
 		////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 Align=TEXTALIGN_LEFT, ShadowParams Shadow=ShadowParams())=0;
+		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;
 		////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 Align=TEXTALIGN_LEFT, ShadowParams Shadow=ShadowParams())=0;
+		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;
 		////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 Align)=0;
+		virtual void Print_Test(int X, int Y, int W, string Text, EPrintData *Data, int DataLen, TextAlignment::Type Align)=0;
 
 		virtual int FontHeight()=0;
 		virtual int TextWidth(string Text)=0;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/GGE.h	Mon Jul 18 22:25:11 2011 +0000
@@ -0,0 +1,86 @@
+#pragma once
+
+#include "../Utils/UtilsBase.h"
+#include "../Utils/Binary.h"
+
+
+typedef unsigned long       DWORD;
+typedef int                 BOOL;
+typedef unsigned short      WORD;
+
+#pragma warning(disable:4355)
+
+
+////Gorgon Game Engine
+namespace gge {
+
+	class Alignment {
+	public:
+		enum Type {
+			Left	= B8(00001000),
+			Right	= B8(00010000),
+			Center	= B8(00100000),
+
+			Top		= B8(00000001),
+			Bottom	= B8(00000010),
+			Middle	= B8(00000100),
+
+			Top_Left		= Top	 | Left		,
+			Top_Center		= Top	 | Center	,
+			Top_Right		= Top	 | Right	,
+
+			Bottom_Left		= Bottom | Left		,
+			Bottom_Right	= Bottom | Right	,
+			Bottom_Center	= Bottom | Center	,
+
+			Middle_Left		= Middle | Left		,
+			Middle_Center	= Middle | Center	,
+			Middle_Right	= Middle | Right	,
+		};
+
+		static const int Mask_Vertical		= B8(00000111);
+		static const int Mask_Horizontal	= B8(00111000);
+		static const int Mask_Used			= B8(00111111);
+		static const int Mask_Invalid		= ~Mask_Used;
+
+		bool isLeft(Type t) {
+			return (t&Mask_Horizontal) == Left;
+		}
+
+		bool isRight(Type t) {
+			return (t&Mask_Horizontal) == Right;
+		}
+
+		bool isCenter(Type t) {
+			return (t&Mask_Horizontal) == Center;
+		}
+
+		bool isTop(Type t) {
+			return (t&Mask_Vertical) == Top;
+		}
+
+		bool isBottom(Type t) {
+			return (t&Mask_Vertical) == Bottom;
+		}
+
+		bool isMiddle(Type t) {
+			return (t&Mask_Vertical) == Middle;
+		}
+
+		bool isValid(Type t) {
+			if(t&Mask_Invalid)
+				return false;
+
+			int h=t&Mask_Horizontal;
+			if( !(h==Left || h==Right || h==Center) )
+				return false;
+
+			int v=t&Mask_Vertical;
+			if( !(v==Top || v==Bottom || v==Middle) )
+				return false;
+
+			return true;
+		}
+	}; 
+
+}
--- a/Engine/GGEMain.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/GGEMain.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -14,8 +14,7 @@
 		AfterRenderEvent("AfterRender", this),
 		Window(NULL)
 	{
-		X=0;
-		Y=0;
+		BoundingBox=utils::Bounds(0,0, Width,Height);
 		isVisible=true;
 
 		CurrentTime=os::GetTime();
@@ -33,10 +32,12 @@
 #endif
 		this->SystemName=SystemName;
 		this->Instance=Instance;
-		this->Width=W=Width;
-		this->Height=H=Height;
+		this->Width=Width;
+		this->Height=Height;
 		this->BitDepth=BitDepth;
 		this->FullScreen=FullScreen;
+
+		BoundingBox.SetSize(Width, Height);
 	}
 
 	GGEMain::~GGEMain() {
@@ -62,10 +63,7 @@
 		BeforeRenderEvent();
 
 		///*Processing interval objects
-		IntervalObjects.ResetIteration();
-		IntervalObject *interval;
-
-		while(interval=IntervalObjects.next()) {
+		for(utils::Collection<IntervalObject>::Iterator interval=IntervalObjects.First();interval.isValid();interval.Next()) {
 			if(interval->Enabled)
 				if(CurrentTime-interval->LastSignal>interval->Timeout) {
 					interval->Signal(interval, interval->Data);
@@ -116,11 +114,10 @@
 		InitializeGraphics();
 		InitializeSound();
 		InitializeInput();
-		gge::input::AddPointerTarget(this,0); 
 
 		InitializeAnimation();
 		InitializePointer();
-		InitializeWidgets();
+		//InitializeWidgets();
 	}
 
 }
\ No newline at end of file
--- a/Engine/GGEMain.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/GGEMain.h	Mon Jul 18 22:25:11 2011 +0000
@@ -3,7 +3,7 @@
 #include "../Utils/Any.h"
 #include "../Utils/EventChain.h"
 
-#include "../Widgets/WidgetMain.h"
+//#include "../Widgets/WidgetMain.h"
 
 #include "OS.h"
 #include "Sound.h"
@@ -32,12 +32,12 @@
 		////This variable is used internally to track when
 		/// this interval is signaled
 		unsigned int LastSignal;
-		////The data to ba passed signal handler
+		////The data to be passed signal handler
 		void *Data;
-		////Wheter this object is enabled, when enabled
+		////Whether this object is enabled, when enabled
 		/// this interval will continue from where it left
 		/// most probably triggering a signal in the next
-		/// signal check, this behaviour can be prevented by
+		/// signal check, this behavior can be prevented by
 		/// setting LastSignal to current time while enabling
 		/// the interval object
 		bool Enabled;
@@ -52,7 +52,7 @@
 	/// prevent it, multiple GGEMain classes are not possible currently.
 	/// Before calling any initialization function apart from OS, a window should be created.
 	/// GGEMain is also the topmost layer.
-	class GGEMain : public LayerBase, public input::BasicPointerTarget {
+	class GGEMain : public LayerBase{
 	public:
 		////Handle of the device context specifying drawable area of
 		/// the created window. Can be changed but should be modified with care
@@ -81,16 +81,6 @@
 		////Current system time. This time does not change in a given game loop
 		unsigned int CurrentTime;
 
-		////This is the top-level mouse event propagator
-		virtual bool PropagateMouseEvent(input::MouseEventType event, int x, int y, void *data) {
-			return LayerBase::PropagateMouseEvent(event, x, y, data);
-		}
-
-		////This is the top-level mouse event propagator
-		virtual bool PropagateMouseScrollEvent(int amount, input::MouseEventType event, int x, int y, void *data) {
-			return LayerBase::PropagateMouseScrollEvent(amount, event, x, y, data);
-		}
-
 		////Constructor
 		GGEMain();
 
@@ -126,7 +116,6 @@
 		/// call to BeforeGameLoop function.
 		void		 InitializeInput() { 
 			gge::input::Initialize(); 
-			gge::input::AddPointerTarget(this,0); 
 		}
 		////Initializes OS subsystem allowing it to setup events. Should be called before creating a window
 		void		 InitializeOS() { gge::os::Initialize(); }
@@ -137,7 +126,7 @@
 		void		 InitializeAnimation() { gge::InitializeAnimation(this); }
 		////Initializes Pointer subsystem. Before calling this function, pointers cannot be used
 		void		 InitializePointer() { Pointers.Initialize(*this); }
-		void		 InitializeWidgets() { gge::widgets::InitializeWidgets(this); }
+		//void		 InitializeWidgets() { gge::widgets::InitializeWidgets(this); }
 
 		////Registers a signal handler to be called in every given time. Exact time passed from the
 		/// last signal can be checked using LastSignal variable of the IntervalObject
--- a/Engine/GraphicLayers.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/GraphicLayers.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -1,33 +1,16 @@
 #include "GraphicLayers.h"
 #pragma warning(disable:4244)
 
+
+
 using namespace gge::utils;
 using namespace gge::input;
 
 namespace gge { namespace graphics {
 	RGBfloat CurrentLayerColor;
-	int trX,trY;
-	int scX,scY,scW,scH;
-
-	Basic2DLayer::Basic2DLayer(int X,int Y,int W,int H) : LayerBase() {
-		this->X=X;
-		this->Y=Y;
-		this->W=W;
-		this->H=H;
-		isVisible=true;
+	Point translate;
+	Rectangle scissors;
 
-		EnableClipping=false;
-	}
-
-	Basic2DLayer::Basic2DLayer(gge::Rectangle r) : LayerBase() {
-		this->X=r.Left;
-		this->Y=r.Top;
-		this->W=r.Width;
-		this->H=r.Height;
-		isVisible=true;
-
-		EnableClipping=false;
-	}
 	void Basic2DLayer::Draw(GLTexture *Image, int X1, int Y1, int X2, int Y2, int X3, int Y3, int X4, int Y4) {
 		BasicSurface *surface=Surfaces.Add();
 
@@ -494,45 +477,38 @@
 	}
 
 	void Basic2DLayer::Render() {
-		int pscX,pscY,pscW,pscH;
+		Rectangle psc;
 		if(!isVisible) return;
 		glPushAttrib(GL_SCISSOR_BIT);
 
 		glPushMatrix();
-		glTranslatef(X, Y, 0);
-		trX+=X;
-		trY+=Y;
+		glTranslatef(BoundingBox.Left, BoundingBox.Top, 0);
+		translate+=BoundingBox.TopLeft();
 
 		if(EnableClipping) {
-			pscX=scX;
-			pscY=scY;
-			pscW=scW;
-			pscH=scH;
+			psc=scissors;
 
-			int r=scX+scW;
-			int b=scY+scH;
+			int r=scissors.Right();
+			int b=scissors.Bottom();
 
 			glEnable(GL_SCISSOR_TEST);
-			if(trX>scX)
-				scX=trX;
-			if(trY>scY)
-				scY=trY;
-			if(trY+H<b)
-				b=(H+trY);
-			if(trX+W<r)
-				r=(W+trX);
+			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());
 
-			scW=r-scX;
-			scH=b-scY;
+			scissors.SetRight(r);
+			scissors.SetBottom(b);
 
-			if(scH<=0 || scW<=0) {
-				scX=pscX;
-				scY=pscY;
-				scW=pscW;
-				scH=pscH;
+			if(r<=scissors.Left || b<=scissors.Top) {
+				return;
 			}
 
-			glScissor(scX, (ScreenSize.y-scY)-scH, scW, scH);
+			glScissor(scissors.Left, (ScreenSize.Height-scissors.Top)-scissors.Height, scissors.Width, scissors.Height);
 		}
 
 		int i;
@@ -551,90 +527,57 @@
 			glEnd();
 		}
 
-		LayerBase *layer;
-		LinkedListOrderedIterator<LayerBase> it=SubLayers.GetReverseOrderedIterator();
-		while(layer=it) {
-			layer->Render();
+		for(utils::SortedCollection<LayerBase>::Iterator i=SubLayers.Last(); i.isValid(); i.Previous()) {
+			i->Render();
 		}
 
 		glPopMatrix();
-		trX-=X;
-		trY-=Y;
+		translate-=BoundingBox.TopLeft();
 
 		if(EnableClipping) {
-			scX=pscX;
-			scY=pscY;
-			scW=pscW;
-			scH=pscH;
+			scissors=psc;
 		}
 
 		glPopAttrib();
 	}
 
-	Colorizable2DLayer::Colorizable2DLayer(int X,int Y,int W,int H) : LayerBase() {
-		Ambient=RGBint(0xffffffff);
-		this->X=X;
-		this->Y=Y;
-		this->W=W;
-		this->H=H;
-
-		isVisible=true;
-		EnableClipping=false;
-	}
-	Colorizable2DLayer::Colorizable2DLayer(gge::Rectangle r) : LayerBase() {
-		Ambient=RGBint(0xffffffff);
-		this->X=r.Left;
-		this->Y=r.Top;
-		this->W=r.Width;
-		this->H=r.Height;
-
-		isVisible=true;
-		EnableClipping=false;
-	}
 	void Colorizable2DLayer::Render() {
-		int pscX,pscY,pscW,pscH;
-
+		Rectangle psc;
 		if(!isVisible) return;
+		if(Ambient.a==0) return;
 		glPushAttrib(GL_SCISSOR_BIT);
 
-
 		glPushMatrix();
-		glTranslatef(X, Y, 0);
-		trX+=X;
-		trY+=Y;
+		glTranslatef(BoundingBox.Left, BoundingBox.Top, 0);
+		translate+=BoundingBox.TopLeft();
 
 		if(EnableClipping) {
-			pscX=scX;
-			pscY=scY;
-			pscW=scW;
-			pscH=scH;
+			psc=scissors;
 
-			int r=scX+scW;
-			int b=scY+scH;
+			int r=scissors.Right();
+			int b=scissors.Bottom();
 
 			glEnable(GL_SCISSOR_TEST);
-			if(trX>scX)
-				scX=trX;
-			if(trY>scY)
-				scY=trY;
-			if(trY+H<b)
-				b=(H+trY);
-			if(trX+W<r)
-				r=(W+trX);
+			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());
 
-			scW=r-scX;
-			scH=b-scY;
+			scissors.SetRight(r);
+			scissors.SetBottom(b);
 
-			if(scH<=0 || scW<=0) {
-				scX=pscX;
-				scY=pscY;
-				scW=pscW;
-				scH=pscH;
+			if(r<=scissors.Left || b<=scissors.Top) {
+				return;
 			}
 
-			glScissor(scX, (ScreenSize.y-scY)-scH, scW, scH);
+			glScissor(scissors.Left, (ScreenSize.Height-scissors.Top)-scissors.Height, scissors.Width, scissors.Height);
 		}
 
+
 		RGBfloat prevcolor=CurrentLayerColor;
 		CurrentLayerColor.a*=(float)Ambient.a/255;
 		CurrentLayerColor.r*=(float)Ambient.r/255;
@@ -659,24 +602,20 @@
 		}
 
 		glColor4fv(CurrentLayerColor.vect);
-		LayerBase *layer;
-		LinkedListOrderedIterator<LayerBase> it=SubLayers.GetReverseOrderedIterator();
-		while(layer=it) {
-			layer->Render();
+		for(utils::SortedCollection<LayerBase>::Iterator i=SubLayers.Last(); i.isValid(); i.Previous()) {
+			i->Render();
 		}
 
+
 		CurrentLayerColor=prevcolor;
 		glColor4fv(prevcolor.vect);
 
+
 		glPopMatrix();
-		trX-=X;
-		trY-=Y;
+		translate-=BoundingBox.TopLeft();
 
 		if(EnableClipping) {
-			scX=pscX;
-			scY=pscY;
-			scW=pscW;
-			scH=pscH;
+			scissors=psc;
 		}
 
 		glPopAttrib();
@@ -1214,47 +1153,38 @@
 		surface->VertexCoords[3].y=Y4;
 	}
 	void Basic2DRawGraphicsLayer::Render() {
+		Rectangle psc;
 		if(!isVisible) return;
-		int pscX,pscY,pscW,pscH;
-
 		glPushAttrib(GL_SCISSOR_BIT);
 
-
 		glPushMatrix();
-		glTranslatef(X, Y, 0);
-		trX+=X;
-		trY+=Y;
+		glTranslatef(BoundingBox.Left, BoundingBox.Top, 0);
+		translate+=BoundingBox.TopLeft();
 
 		if(EnableClipping) {
-			pscX=scX;
-			pscY=scY;
-			pscW=scW;
-			pscH=scH;
+			psc=scissors;
 
-			int r=scX+scW;
-			int b=scY+scH;
+			int r=scissors.Right();
+			int b=scissors.Bottom();
 
 			glEnable(GL_SCISSOR_TEST);
-			if(trX>scX)
-				scX=trX;
-			if(trY>scY)
-				scY=trY;
-			if(trY+H<b)
-				b=(H+trY);
-			if(trX+W<r)
-				r=(W+trX);
+			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());
 
-			scW=r-scX;
-			scH=b-scY;
+			scissors.SetRight(r);
+			scissors.SetBottom(b);
 
-			if(scH<=0 || scW<=0) {
-				scX=pscX;
-				scY=pscY;
-				scW=pscW;
-				scH=pscH;
+			if(r<=scissors.Left || b<=scissors.Top) {
+				return;
 			}
 
-			glScissor(scX, (ScreenSize.y-scY)-scH, scW, scH);
+			glScissor(scissors.Left, (ScreenSize.Height-scissors.Top)-scissors.Height, scissors.Width, scissors.Height);
 		}
 
 		int i;
@@ -1275,32 +1205,19 @@
 			glEnd();
 		}
 
-		LayerBase *layer;
-		LinkedListOrderedIterator<LayerBase> it=SubLayers.GetReverseOrderedIterator();
-		while(layer=it) {
-			layer->Render();
+
+		for(utils::SortedCollection<LayerBase>::Iterator i=SubLayers.Last(); i.isValid(); i.Previous()) {
+			i->Render();
 		}
 
 		glPopMatrix();
-		trX-=X;
-		trY-=Y;
+		translate-=BoundingBox.TopLeft();
 
 		if(EnableClipping) {
-			scX=pscX;
-			scY=pscY;
-			scW=pscW;
-			scH=pscH;
+			scissors=psc;
 		}
 
 		glPopAttrib();
-	}
-	Basic2DRawGraphicsLayer::Basic2DRawGraphicsLayer(int X,int Y,int W,int H) : LayerBase() {
-		this->X=X;
-		this->Y=Y;
-		this->W=W;
-		this->H=H;
 
-		isVisible=true;
-		EnableClipping=false;
 	}
 } }
--- a/Engine/GraphicLayers.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/GraphicLayers.h	Mon Jul 18 22:25:11 2011 +0000
@@ -1,6 +1,6 @@
 #pragma once
 
-#include "../Utils/GGE.h"
+#include "GGE.h"
 #include "Layer.h"
 #include "../Utils/PAClassList.h"
 #include "Graphics.h"
@@ -27,9 +27,21 @@
 		////Whether or not enable clipping
 		bool EnableClipping;
 
-		////Default constructor to initialize variables
-		Basic2DLayer(int X=0, int Y=0, int W=100, int H=100);
-		Basic2DLayer(gge::Rectangle r);
+
+		Basic2DLayer() : LayerBase() { init(); }
+
+		Basic2DLayer(const utils::Bounds &b) : LayerBase(b) { init(); }
+
+		Basic2DLayer(int L, int T, int R, int B) : LayerBase(L,T,R,B) { init(); }
+
+		Basic2DLayer(int X,int Y) : LayerBase(X,Y) { init(); }
+
+		Basic2DLayer(const utils::Point &p) : LayerBase(p) { init(); }
+
+		void init() {
+			isVisible=true;
+			EnableClipping=false;
+		}
 
 		////Draws a simple image to the screen.
 		/// In this draw function every corner can be specified
@@ -53,7 +65,7 @@
 		///@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);
-		////Draws a veritically tiled image to the screen
+		////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
@@ -64,8 +76,8 @@
 		virtual void Render();
 		virtual void Clear() { Surfaces.Clear(); }
 
-		virtual int Width() { return W; }
-		virtual int Height() { return H; }
+		virtual int Width() { return BoundingBox.Width(); }
+		virtual int Height() { return BoundingBox.Height(); }
 	};
 	////This layer is a 2D graphics target and also has colorization support
 	class Colorizable2DLayer : public I2DColorizableGraphicsTarget, public LayerBase {
@@ -73,8 +85,22 @@
 		////Whether or not enable clipping
 		bool EnableClipping;
 		////Default constructor to initialize variables
-		Colorizable2DLayer(int X=0, int Y=0, int W=100, int H=100);
-		Colorizable2DLayer(gge::Rectangle r);
+
+		Colorizable2DLayer() : LayerBase() { init(); }
+
+		Colorizable2DLayer(const utils::Bounds &b) : LayerBase(b) { init(); }
+
+		Colorizable2DLayer(int L, int T, int R, int B) : LayerBase(L,T,R,B) { init(); }
+
+		Colorizable2DLayer(int X,int Y) : LayerBase(X,Y) { init(); }
+
+		Colorizable2DLayer(const utils::Point &p) : LayerBase(p) { init(); }
+
+		void init() {
+			Ambient=RGBint(0xffffffff);
+			isVisible=true;
+			EnableClipping=false;
+		}
 
 		////This list contains surfaces to be drawn
 		PAClassList<ColorizableSurface> Surfaces;
@@ -105,15 +131,15 @@
 		///@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);
-		////Draws a veritically tiled image to the screen
+		////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);
 
-		virtual int Width() { return W; }
-		virtual int Height() { return H; }
+		virtual int Width() { return BoundingBox.Width(); }
+		virtual int Height() { return BoundingBox.Height(); }
 	};
 	class Basic2DRawGraphicsLayer : public I2DRawGraphicsTarget, public LayerBase {
 	public:
@@ -122,11 +148,23 @@
 		////This list contains surfaces to be drawn
 		PAClassList<RawSurface> Surfaces;
 
-		////Default constructor to initialize variables
-		Basic2DRawGraphicsLayer(int X=0, int Y=0, int W=100, int H=100);
-
 		////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;
+		}
+
+		Basic2DRawGraphicsLayer() : LayerBase() { init(); }
+
+		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(); }
+
+		Basic2DRawGraphicsLayer(const utils::Point &p) : LayerBase(p) { init(); }
 
 		////Renders this layer
 		virtual void Render();
--- a/Engine/Graphics.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/Graphics.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -2,12 +2,15 @@
 #ifdef WIN32
 #include <windows.h>
 
+
+using namespace gge::utils;
+
 #endif
 namespace gge { namespace graphics {
-	Point ScreenSize;
+	Size ScreenSize;
 	extern RGBfloat CurrentLayerColor;
-	extern int scX,scY,scW,scH;
-	extern int trX,trY;
+	extern utils::Rectangle scissors;
+	extern Point translate;
 
 	os::DeviceHandle Initialize(os::WindowHandle hWnd, int BitDepth, int Width, int Height) {
 		///!Platform specific
@@ -46,8 +49,8 @@
 		wglMakeCurrent(hDC,hRC);
 #endif
 
-		ScreenSize.x=Width;
-		ScreenSize.y=Height;
+		ScreenSize.Width=Width;
+		ScreenSize.Height=Height;
 
 		///*Setting OpenGL parameters
 		glShadeModel(GL_SMOOTH);							// Enables Smooth Shading
@@ -87,15 +90,6 @@
 
 		return (os::DeviceHandle)hDC;
 	}
-	RECT makerect(int x, int y, int w, int h) {	
-		RECT ret;
-		ret.left=x;
-		ret.right=x+w;
-		ret.top=y;
-		ret.bottom=y+h;
-
-		return ret;
-	}
 	void A8ToA8L8(int cx,int cy,Byte *data,Byte *dest)
 	{
 		int icx=cx,icy=cy;
@@ -229,11 +223,8 @@
 		CurrentLayerColor.g=1;
 		CurrentLayerColor.b=1;
 
-		trX=0;
-		trY=0;
-		scX=scY=0;
-		scW=ScreenSize.x;
-		scH=ScreenSize.y;
+		translate=Point(0,0);
+		scissors=utils::Rectangle(0, 0, ScreenSize);
 	}
 
 	void PostRender(os::DeviceHandle hDC) {
--- a/Engine/Graphics.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/Graphics.h	Mon Jul 18 22:25:11 2011 +0000
@@ -1,6 +1,6 @@
 #pragma once
 
-#include "../Utils/GGE.h"
+#include "GGE.h"
 #include "OS.h"
 
 #define WINGDIAPI	__declspec(dllimport)
@@ -11,7 +11,12 @@
 #include <gl/glu.h>
 #include <assert.h>
 #include <stdexcept>
+#include <string>
+
 #include "../Utils/ManagedBuffer.h"
+#include "../Utils/Point2D.h"
+#include "../Utils/Rectangle2D.h"
+#include "../Utils/Size2D.h"
 
 #undef WINGDIAPI
 #undef APIENTRY
@@ -571,13 +576,13 @@
 		////Draws this object to the given target
 		///@Target	: The target that will be used to draw
 		/// this image
-		virtual void Draw(I2DGraphicsTarget *Target,Point pnt) { 
+		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,Point pnt) { 
+		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) { 
@@ -699,7 +704,7 @@
 	////This is a basic drawing object
 	class Raw2DGraphic {
 	public:
-		ManagedBuffer<Byte> Data;
+		utils::ManagedBuffer<Byte> Data;
 	protected:
 		int Width;
 		int Height;
@@ -712,8 +717,6 @@
 			Width=graph.Width;
 			Height=graph.Height;
 			Mode=graph.Mode;
-			
-			Data++;
 		}
 
 		////Draws this object to the given target
@@ -826,5 +829,5 @@
 	/// initialize graphics function
 	void PostRender(os::DeviceHandle Device);
 
-	extern Point ScreenSize;
+	extern utils::Size ScreenSize;
 } }
--- a/Engine/Input.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/Input.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -1,397 +1,450 @@
 #include "Input.h"
+#include "GGEMain.h"
 
 using namespace gge;
 using namespace utils;
 
 namespace gge { namespace input {
 
-	bool KeyboardModifier::isAlternate=false;
-	KeyboardModifier::Type KeyboardModifier::Current=KeyboardModifier::None;
-
-	LinkedList<BasicPointerTarget> PointerTargets;
-	MouseEventObject *hoveredObject=NULL;
-	MouseEventObject *pressedObject=NULL;
-	MouseEventType MouseButtons=MOUSE_EVENT_NONE;
-	utils::ConsumableEvent<utils::Empty, KeyboardEvent> KeyboardEvents;
-
-	bool hoverfound=false;
-
-	void Initialize() {
-
-	}
-
-	LinkedListItem<BasicPointerTarget> *AddPointerTarget(BasicPointerTarget *target, int order) {
-		return PointerTargets.AddItem(target,order);
-	}
-
-	void RemovePointerTarget(LinkedListItem<BasicPointerTarget> * target) {
-		PointerTargets.Remove(target);
+	namespace keyboard {
+		bool Modifier::isAlternate=false;
+		Modifier::Type Modifier::Current=Modifier::None;
+		utils::ConsumableEvent<utils::Empty, Event> Events;
 	}
 
-	////This internal function propagates an event to all top level targets
-	void propagateevent(MouseEventType event, int x, int y) {
-		LinkedListOrderedIterator<BasicPointerTarget> it=PointerTargets;
-		BasicPointerTarget *target;
+
+	namespace mouse {
+		Event::Type		PressedButtons	= Event::None;
+		Event::Target	*HoveredObject	= NULL;
+		Event::Target	*PressedObject	= NULL;
+
+		utils::Point	PressedPoint	= utils::Point(0,0);
+		utils::Point	CurrentPoint	= utils::Point(0,0);
+
+		const int DragDistance			= 5;//px
+
+		bool EventProvider::PropagateMouseEvent(Event::Type event, utils::Point location, int amount) {
+			if(Event::isClick(event)) {
+				for(utils::SortedCollection<EventChain::Object>::Iterator i = this->MouseEvents.Events.First();i.isValid();i.Next()) {
+					if(&(*i)==PressedObject && i->Bounds.isInside(location)) {
+						if(i->Fire(event, location-i->Bounds.TopLeft(), amount))
+							return true;
+					}
+				}
+
+				return false;
+			}
+			else if(Event::isDown(event)) {
+				for(utils::SortedCollection<EventChain::Object>::Iterator i = this->MouseEvents.Events.First();i.isValid();i.Next()) {
+					if(i->Bounds.isInside(location)) {
+						if(i->Fire(event, location-i->Bounds.TopLeft(), amount)) {
+							mouse::PressedObject=&(*i);
+							return true;
+						}
+					}
+				}
 
-		while(target=it) {
-			if(target->PropagateMouseEvent(event, x, y, NULL))
-				break;
-		}
-	}
+				return false;
+			}
+			else if(event==Event::Move) {
+				for(utils::SortedCollection<EventChain::Object>::Iterator i = this->MouseEvents.Events.First();i.isValid();i.Next()) {
+					if(i->Bounds.isInside(location)) {
+						if(i->EventMask & Event::OverCheck)
+							if(!i->Fire(Event::OverCheck, location-i->Bounds.TopLeft(), 0))
+								continue;
+
+						bool ret=false;
+
+						if(i->EventMask & Event::Over && &(*i)!=HoveredObject && !PressedObject) {
+							ret = i->Fire(Event::Over, location-i->Bounds.TopLeft(), amount);
 
-	////This internal function propagates scroll event to all top level targets
-	void propagatescrollevent(int amount, MouseEventType event, int x, int y) {
-		LinkedListOrderedIterator<BasicPointerTarget> it=PointerTargets;
-		BasicPointerTarget *target;
+							if(ret) {
+								if(HoveredObject)
+									HoveredObject->Fire(Event::Out, utils::Point(0,0), 0);
+
+								HoveredObject = &(*i);
+
+								i->Fire(Event::Move, location-i->Bounds.TopLeft(), amount);
+							}
+						}
+						else if(!PressedObject || PressedObject==&(*i)) {
+							ret = i->Fire(Event::Over, location-i->Bounds.TopLeft(), amount);
+						}
+
+						if(&(*i)==HoveredObject)
+							system::hoverfound=true;
+
+						if(ret || &(*i)==HoveredObject)
+							return true;
+					}
+				}
 
-		while(target=it) {
-			if(target->PropagateMouseScrollEvent(amount, event, x, y, NULL))
-				break;
+				return false;
+			}
+			else { //Scrolls, double click
+				for(utils::SortedCollection<EventChain::Object>::Iterator i = this->MouseEvents.Events.First();i.isValid();i.Next()) {
+					if(i->Bounds.isInside(location)) {
+						if(i->Fire(event, location-i->Bounds.TopLeft(), amount))
+							return true;
+					}
+				}
+
+				return false;
+			}
 		}
-	}
+
+		bool CallbackProvider::PropagateMouseEvent(Event::Type event, utils::Point location, int amount) {
+			if(!Callback) return false;
+
+			if(Event::isClick(event)) {
+				if(Callback.object==PressedObject) {
+					if(Callback.object->Fire(event, location, amount))
+						return true;
+				}
+
+				return false;
+			}
+			else if(Event::isDown(event)) {
+				if(Callback.object->Fire(event, location, amount)) {
+					mouse::PressedObject=Callback.object;
+					return true;
+				}
 
-	namespace system {
-		void ProcessMousePosition(os::WindowHandle Window) {
-			Point pnt;
-			pnt=os::input::getMousePosition(Window);
+				return false;
+			}
+			else if(event==Event::Move) {
+				if(Callback.object->EventMask & Event::OverCheck)
+					if(!Callback.object->Fire(Event::OverCheck, location, 0))
+						return false;
+
+				bool ret=false;
+
+				if(Callback.object->EventMask & Event::Over && Callback.object!=HoveredObject && !PressedObject) {
+					ret = Callback.object->Fire(Event::Over, location, amount);
+
+					if(ret) {
+						if(HoveredObject)
+							HoveredObject->Fire(Event::Out, utils::Point(0,0), 0);
+
+						HoveredObject = Callback.object;
 
-			int x=pnt.x;
-			int y=pnt.y;
+						Callback.object->Fire(Event::Move, location, amount);
+					}
+				}
+				else if(!PressedObject || PressedObject==Callback.object) {
+					ret = Callback.object->Fire(Event::Over, location, amount);
+				}
 
-			hoverfound=false;
-			propagateevent(MOUSE_EVENT_MOVE, x, y);
-			if(!hoverfound && hoveredObject) {
-				if(hoveredObject->out)
-					hoveredObject->out(MOUSE_EVENT_OUT, x, y, hoveredObject->data);
-				hoveredObject=NULL;
+				if(Callback.object==HoveredObject)
+					system::hoverfound=true;
+
+				return (ret || Callback.object==HoveredObject);
+			}
+			else { //Scrolls, double click
+				if(Callback.object->Fire(event, location, amount))
+					return true;
+
+				return false;
 			}
 		}
 
-		void ProcessMouseClick(int button,int x,int y) {
-			MouseEventType event;
-			if(button==1)
-				event=MOUSE_EVENT_LCLICK;
-			if(button==2)
-				event=MOUSE_EVENT_RCLICK;
-			if(button==4)
-				event=MOUSE_EVENT_MCLICK;
-			if(button==101)
-				event=MOUSE_EVENT_X1CLICK;
-			if(button==102)
-				event=MOUSE_EVENT_X2CLICK;
+		EventChain::Object & EventChain::Register( bool (*fn)(Event::Type event, utils::Point location, int amount, utils::Any data), utils::Bounds bounds, utils::Any data, Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Register(
+				new FullFunctionHandler(fn,data),
+				bounds,
+				eventmask
+				);
+		}
 
-
-			propagateevent(event, x, y);
-			pressedObject=NULL;
+		EventChain::Object & EventChain::Register( bool (*fn)(Event::Type event, utils::Point location, int amount), utils::Bounds bounds, Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Register(
+				new FunctionHandler(fn),
+				bounds,
+				eventmask
+				);
 		}
 
-		void ProcessMouseDown(int button,int x,int y) {
-
-			MouseButtons=(MouseEventType)(MouseButtons | button);
+		EventChain::Object & EventChain::Register( bool (*fn)(Event::Type event, utils::Point location), utils::Bounds bounds, Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Register(
+				new NoAmountFunctionHandler(fn),
+				bounds,
+				eventmask
+				);
+		}
 
-			MouseEventType event;
-			if(button==1)
-				event=MOUSE_EVENT_LDOWN;
-			if(button==2)
-				event=MOUSE_EVENT_RDOWN;
-			if(button==4)
-				event=MOUSE_EVENT_MDOWN;
-			if(button==101)
-				event=MOUSE_EVENT_X1DOWN;
-			if(button==102)
-				event=MOUSE_EVENT_X2DOWN;
+		EventChain::Object & EventChain::Register( bool (*fn)(utils::Point location), utils::Bounds bounds, Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Register(
+				new LocationOnlyFunctionHandler(fn),
+				bounds,
+				eventmask
+				);
+		}
 
-			propagateevent(event, x, y);
+		EventChain::Object & EventChain::Register( bool (*fn)(), utils::Bounds bounds, Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Register(
+				new EmptyFunctionHandler(fn),
+				bounds,
+				eventmask
+				);
 		}
 
-		void ProcessMouseUp(int button,int x,int y){
-
-			MouseButtons=(MouseEventType)(MouseButtons & ~button);
+		template <class R_>
+		EventChain::Object & EventChain::Register( R_ &object, bool (R_::*fn)(), utils::Bounds bounds, Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Register(
+				new EmptyClassHandler(object,fn),
+				bounds,
+				eventmask
+				);
+		}
 
-			MouseEventType event;
-			if(button==1)
-				event=MOUSE_EVENT_LUP;
-			if(button==2)
-				event=MOUSE_EVENT_RUP;
-			if(button==4)
-				event=MOUSE_EVENT_MUP;
-			if(button==101)
-				event=MOUSE_EVENT_X1UP;
-			if(button==102)
-				event=MOUSE_EVENT_X2UP;
-
-			propagateevent(event, x, y);
+		template <class R_>
+		EventChain::Object & EventChain::Register( R_ &object, bool (R_::*fn)(utils::Point location), utils::Bounds bounds, Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Register(
+				new LocationOnlyClassHandler(object,fn),
+				bounds,
+				eventmask
+				);
 		}
 
-		void ProcessMouseDblClick(int button,int x,int y){
-			MouseEventType event;
-			if(button==1)
-				event=MOUSE_EVENT_LDBLCLICK;
-			if(button==2)
-				event=MOUSE_EVENT_RDBLCLICK;
-			if(button==4)
-				event=MOUSE_EVENT_MDBLCLICK;
-			if(button==101)
-				event=MOUSE_EVENT_X1DBLCLICK;
-			if(button==102)
-				event=MOUSE_EVENT_X2DBLCLICK;
-
-			propagateevent(event, x, y);
+		template <class R_>
+		EventChain::Object & EventChain::Register( R_ &object, bool (R_::*fn)(Event::Type event, utils::Point location), utils::Bounds bounds, Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Register(
+				new NoAmountClassHandler(object,fn),
+				bounds,
+				eventmask
+				);
 		}
 
-		void ProcessVScroll(int amount,int x,int y){
-			propagatescrollevent(amount, MOUSE_EVENT_VSCROLLL, x, y);
+		template <class R_>
+		EventChain::Object & EventChain::Register( R_ &object, bool (R_::*fn)(Event::Type event, utils::Point location, int amount), utils::Bounds bounds, Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Register(
+				new ClassHandler(object,fn),
+				bounds,
+				eventmask
+				);
 		}
 
-		void ProcessHScroll(int amount,int x,int y){
-			propagatescrollevent(amount, MOUSE_EVENT_HSCROLLL, x, y);
+		template <class R_>
+		EventChain::Object & EventChain::Register( R_ &object, bool (R_::*fn)(Event::Type event, utils::Point location, int amount, utils::Any data), utils::Bounds bounds, utils::Any data, Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Register(
+				new FullClassHandler(object,fn,data),
+				bounds,
+				eventmask
+				);
 		}
 
 
-		void ProcessChar(int Char) {
-			KeyboardEvent params;
-			params.keycode=Char;
-			params.event=KeyboardEvent::Char;
+		EventCallback::Object & EventCallback::Set( bool (*fn)(Event::Type event, utils::Point location, int amount, utils::Any data), utils::Any data, Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Set(
+				new FullFunctionHandler(fn,data),
+				
+				eventmask
+				);
+		}
+
+		EventCallback::Object & EventCallback::Set( bool (*fn)(Event::Type event, utils::Point location, int amount), Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Set(
+				new FunctionHandler(fn),
+				
+				eventmask
+				);
+		}
+
+		EventCallback::Object & EventCallback::Set( bool (*fn)(Event::Type event, utils::Point location), Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Set(
+				new NoAmountFunctionHandler(fn),
+				
+				eventmask
+				);
+		}
 
-			KeyboardEvents(params);
+		EventCallback::Object & EventCallback::Set( bool (*fn)(utils::Point location), Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Set(
+				new LocationOnlyFunctionHandler(fn),
+				
+				eventmask
+				);
+		}
+
+		EventCallback::Object & EventCallback::Set( bool (*fn)(), Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Set(
+				new EmptyFunctionHandler(fn),
+				
+				eventmask
+				);
+		}
+
+		template <class R_>
+		EventCallback::Object & EventCallback::Set( R_ &object, bool (R_::*fn)(), Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Set(
+				new EmptyClassHandler(object,fn),
+				
+				eventmask
+				);
 		}
 
-		void ProcessKeyDown(int Key) {
-			KeyboardEvent params;
-			params.keycode=Key;
-			params.event=KeyboardEvent::Down;
+		template <class R_>
+		EventCallback::Object & EventCallback::Set( R_ &object, bool (R_::*fn)(utils::Point location), Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Set(
+				new LocationOnlyClassHandler(object,fn),
+				
+				eventmask
+				);
+		}
 
-			KeyboardEvents(params);
+		template <class R_>
+		EventCallback::Object & EventCallback::Set( R_ &object, bool (R_::*fn)(Event::Type event, utils::Point location), Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Set(
+				new NoAmountClassHandler(object,fn),
+				
+				eventmask
+				);
+		}
+
+		template <class R_>
+		EventCallback::Object & EventCallback::Set( R_ &object, bool (R_::*fn)(Event::Type event, utils::Point location, int amount), Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Set(
+				new ClassHandler(object,fn),
+				
+				eventmask
+				);
 		}
 
-		void ProcessKeyUp(int Key) {
-			KeyboardEvent params;
-			params.keycode=Key;
-			params.event=KeyboardEvent::Up;
+		template <class R_>
+		EventCallback::Object & EventCallback::Set( R_ &object, bool (R_::*fn)(Event::Type event, utils::Point location, int amount, utils::Any data), utils::Any data, Event::Type eventmask/*=AllUsed*/ )
+		{
+			return Set(
+				new FullClassHandler(object,fn,data),
+				
+				eventmask
+				);
+		}
+
+
+		void EventChain::Object::Remove() {
+			if(PressedObject==this)
+				PressedObject=NULL;
 
-			KeyboardEvents(params);
+			if(HoveredObject==this)
+				HoveredObject=NULL;
+
+			wrapper->Delete();
+		}
+
+		bool Event::Target::Fire(Event::Type event, utils::Point location, int amount )	{
+			if(!handler) 
+				return false;
+
+			if((EventMask&event) != event)
+				return false;
+
+			return handler->Fire(event, location, amount);
+		}
+
+		EventChain::Object::~Object() {
+			delete handler;
 		}
 
 	}
 
-	MouseEventToken BasicPointerTarget::RegisterMouseEvent(Bounds bounds, void *data, 
-		MouseEvent click, MouseEvent over, MouseEvent out,
-		MouseEvent move , MouseEvent down, MouseEvent up , MouseEvent doubleclick) {
 
-			MouseEventObject *meo=new MouseEventObject;
+	void Initialize() {
 
-			meo->bounds=bounds;
-			meo->data=data;
-			meo->Enabled=true;
-			meo->click=click;
-			meo->over=over;
-			meo->out=out;
-			meo->move=move;
-			meo->down=down;
-			meo->up=up;
-			meo->dblclick=doubleclick;
-			meo->parent=this;
-			meo->checkover=NULL;
-			meo->vscroll=NULL;
-			meo->hscroll=NULL;
-
-			MouseEventToken token=mouseevents.AddItem(meo, 0);
-
-			return token;
 	}
+	
+	namespace system {
+		void ProcessChar(int Char) {
+			keyboard::Event params;
+			params.keycode=Char;
+			params.event=keyboard::Event::Char;
 
-	void BasicPointerTarget::DisableMouseEvent(MouseEventToken token) {
-		token->Item->Enabled=false;
-	}
-
-	void BasicPointerTarget::EnableMouseEvent(MouseEventToken token) {
-		token->Item->Enabled=true;
-	}
-
-	void BasicPointerTarget::RemoveMouseEvent(MouseEventToken token) {
-		delete token->Item;
-		token->Item=NULL;
-
-		mouseevents.Delete((MouseEventObject*)token);
-	}
+			keyboard::Events(params);
+		}
 
-	bool BasicPointerTarget::PropagateMouseClickEvent(MouseEventType event, int x, int y, void *data) {
-		bool ret=false;
+		void ProcessKeyDown(int Key) {
+			keyboard::Event params;
+			params.keycode=Key;
+			params.event=keyboard::Event::Down;
 
-		LinkedListOrderedIterator<MouseEventObject> it=mouseevents;
-		MouseEventObject *object;
-		while(object=it) {
-			if(object->click && isinbounds(x,y,object->bounds) && object->Enabled) {
-
-				MouseEventObject *obj=pressedObject;
-				if(pressedObject==NULL || pressedObject==object) {
-					if(object->click(event, x, y, object->data))
-						ret=true;
-				}
-			}
+			keyboard::Events.TokenList[params]=keyboard::Events(params);
+			
 		}
 
-		return ret;
-	}
+		void ProcessKeyUp(int Key) {
+			keyboard::Event params;
+			params.keycode=Key;
+			params.event=keyboard::Event::Down;
 
-	bool BasicPointerTarget::PropagateMouseDownEvent(MouseEventType event, int x, int y, void *data) {
-		LinkedListOrderedIterator<MouseEventObject> it=mouseevents;
-		MouseEventObject *object;
-		while(object=it) {
-			if(object->down && isinbounds(x,y,object->bounds) && object->Enabled) {
-				if(object->down(event, x, y, object->data)) {
-					pressedObject=object;
-					return true;				
-				}
-			}
+			keyboard::Events.Fire(keyboard::Events.TokenList[params], keyboard::Event(keyboard::Event::Up, Key));
+			keyboard::Events.TokenList[params]=keyboard::Events.NullToken;
 		}
 
-		return false;
-	}
+
 
-	bool BasicPointerTarget::PropagateMouseUpEvent(MouseEventType event, int x, int y, void *data) {
-		LinkedListOrderedIterator<MouseEventObject> it=mouseevents;
-		MouseEventObject *object;
-		while(object=it) {
-			if(object->up && object==pressedObject) {
-				if(object->up(event, x, y, object->data))
-					return true;		
-			}
-		}
 
-		return false;
-	}
+		bool hoverfound=false;
 
-	bool BasicPointerTarget::PropagateMouseDblClickEvent(MouseEventType event, int x, int y, void *data) {
-		LinkedListOrderedIterator<MouseEventObject> it=mouseevents;
-		MouseEventObject *object;
-		while(object=it) {
-			if(object->dblclick && isinbounds(x,y,object->bounds) && object->Enabled) {
-				if(object->dblclick(event, x, y, object->data))
-					return true;				
-			}
-		}
+		void ProcessMousePosition(os::WindowHandle Window) {
+			mouse::CurrentPoint=os::input::getMousePosition(Window);
 
-		return false;
-	}
+			hoverfound=false;
+			Main.PropagateMouseEvent(mouse::Event::Move, mouse::CurrentPoint, 0);
 
-	bool BasicPointerTarget::PropagateMouseHScrollEvent(int amount, MouseEventType event, int x, int y, void *data) {
-		LinkedListOrderedIterator<MouseEventObject> it=mouseevents;
-		MouseEventObject *object;
-		while(object=it) {
-			if(object->hscroll && isinbounds(x,y,object->bounds) && object->Enabled) {
-				if(object->hscroll(amount, event, x, y, object->data))
-					return true;				
+			if(!hoverfound && mouse::HoveredObject && !mouse::PressedObject) {
+				mouse::HoveredObject->Fire(mouse::Event::Out, mouse::CurrentPoint, 0);
+				mouse::HoveredObject=NULL;
 			}
 		}
 
-		return false;
-	}
+		void ProcessMouseClick(mouse::Event::Type button,int x,int y) {
+			if(mouse::PressedPoint.Distance(utils::Point(x,y))<mouse::DragDistance)
+				Main.PropagateMouseEvent(mouse::Event::Click | button, utils::Point(x,y), 0);
 
-	bool BasicPointerTarget::PropagateMouseVScrollEvent(int amount, MouseEventType event, int x, int y, void *data) {
-		LinkedListOrderedIterator<MouseEventObject> it=mouseevents;
-		MouseEventObject *object;
-		while(object=it) {
-			if(object->vscroll && isinbounds(x,y,object->bounds) && object->Enabled) {
-				if(object->vscroll(amount, event, x, y, object->data))
-					return true;				
-			}
+			mouse::PressedObject=NULL;
+		}
+
+		void ProcessMouseDown(mouse::Event::Type button,int x,int y) {
+			mouse::PressedButtons = mouse::PressedButtons | button;
+			mouse::PressedPoint   = utils::Point(x,y);
+
+			Main.PropagateMouseEvent(mouse::Event::Down | button, utils::Point(x,y), 0);
 		}
 
-		return false;
-	}
-
-	bool BasicPointerTarget::PropagateMouseOverEvent(MouseEventType event, int x, int y, void *data) {
-		LinkedListOrderedIterator<MouseEventObject> it=mouseevents;
-		MouseEventObject *object;
-		while(object=it) {
-			if(isinbounds(x,y,object->bounds) && object->Enabled) {
-				if(object->over) {
-					if(object->over(event, x, y, object->data))
-						return true;
-					else 
-						return false;
-				} else {
-					return true;
-				}
-			}
+		void ProcessMouseUp(mouse::Event::Type button,int x,int y){
+			mouse::PressedButtons = mouse::PressedButtons & ~button;
+			Main.PropagateMouseEvent(mouse::Event::Up | button, utils::Point(x,y), 0);
 		}
 
-		return false;
-	}
-
-	bool BasicPointerTarget::PropagateMouseOutEvent(MouseEventType event, int x, int y, void *data) {
-		LinkedListOrderedIterator<MouseEventObject> it=mouseevents;
-		MouseEventObject *object;
-		while(object=it) {
-			if(object->out && isinbounds(x,y,object->bounds) && object->Enabled) {
-				if(object->out(event, x, y, object->data))
-					return true;				
-			}
+		void ProcessMouseDblClick(mouse::Event::Type button,int x,int y){
+			Main.PropagateMouseEvent(mouse::Event::DoubleClick | button, utils::Point(x,y), 0);
 		}
 
-		return false;
+		void ProcessVScroll(int amount,int x,int y){
+			Main.PropagateMouseEvent(mouse::Event::VScroll, utils::Point(x,y), amount);
+		}
+
+		void ProcessHScroll(int amount,int x,int y){
+			Main.PropagateMouseEvent(mouse::Event::HScroll, utils::Point(x,y), amount);
+		}
 	}
 
-	bool BasicPointerTarget::PropagateMouseMoveEvent(MouseEventType event, int x, int y, void *data) {
-		LinkedListOrderedIterator<MouseEventObject> it=mouseevents;
-		MouseEventObject *object;
-		while(object=it) {
-			if(isinbounds(x,y,object->bounds) && object->Enabled && !hoverfound) {
-				if(object!=hoveredObject) {
-					if(object->over) {
-						bool isowned=true;
-						if(object->checkover)
-							isowned=object->checkover(MOUSE_EVENT_OVER_CHECK, x, y, hoveredObject->data);
-						if(isowned) {
-							if(hoveredObject)
-								if(hoveredObject->out)
-									hoveredObject->out(MOUSE_EVENT_OUT, x, y, hoveredObject->data);
-							if(object->over(MOUSE_EVENT_OVER, x, y, object->data)) {
-
-								hoveredObject=object;
-								hoverfound=true;
-								return true;
-							}
-						}
-					}
-				} else 
-					hoverfound=true;
-			}
-
-			if(object->move && isinbounds(x,y,object->bounds) && !pressedObject) {
-				if(object->move(event, x, y, object->data))
-					return true;				
-			}
-
-			if(object->move && pressedObject==object) {
-				if(object->move(event, x, y, object->data))
-					return true;				
-			}
-		}
-
-		return false;
-	}
-
-	bool BasicPointerTarget::PropagateMouseEvent(MouseEventType event, int x, int y, void *data) {
-		if(event == MOUSE_EVENT_MOVE)
-			return PropagateMouseMoveEvent(event, x, y, data);
-		else if(event & MOUSE_EVENT_UP) 
-			return PropagateMouseUpEvent(event, x, y, data);
-		else if(event & MOUSE_EVENT_DOWN)
-			return PropagateMouseDownEvent(event, x, y, data);
-		else if(event & MOUSE_EVENT_DBLCLICK)
-			return PropagateMouseDblClickEvent(event, x, y, data);
-		else
-			return PropagateMouseClickEvent(event, x, y, data);
-	}
-
-	bool BasicPointerTarget::PropagateMouseScrollEvent(int amount, MouseEventType event, int x, int y, void *data) {
-		if(event == MOUSE_EVENT_VSCROLLL)
-			return PropagateMouseVScrollEvent(amount, event, x, y, data);
-		else if(event == MOUSE_EVENT_HSCROLLL)
-			return PropagateMouseHScrollEvent(amount, event, x, y, data);
-
-		return false;
-	}
 } }
--- a/Engine/Input.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/Input.h	Mon Jul 18 22:25:11 2011 +0000
@@ -1,239 +1,711 @@
 #pragma once
 
-#include "../Utils/LinkedList.h"
+#include "../Utils/SortedCollection.h"
 #include "../Utils/Collection.h"
-#include "../Utils/GGE.h"
-#include "../Utils/Utils.h"
+#include "GGE.h"
 
 #include "OS.h"
 #include "../Utils/ConsumableEvent.h"
+#include "../Utils/Bounds2D.h"
 
 namespace gge { namespace input {
 	class BasicPointerTarget;
 
-	class KeyboardModifier {
-	public:
-		enum Type {
-			None		= 0,
-			Shift		= 1,
-			Ctrl		= 2,
-			Alt			= 4,
-			Super		= 8,
+
+	namespace keyboard {
+		class Modifier {
+		public:
+			enum Type {
+				None		= 0,
+				Shift		= 1,
+				Ctrl		= 2,
+				Alt			= 4,
+				Super		= 8,
+
+				ShiftCtrl	= Shift | Ctrl ,
+				ShiftAlt	= Shift | Alt  ,
+				CtrlAlt		= Ctrl  | Alt  ,
+				ShiftCtrlAlt= Shift | Ctrl | Alt ,
+			};
+
+			static bool isAlternate;
+			static Type Current;
+
+			////Checks the the current state of the keyboard if there are any real modifiers
+			/// in effect (Namely control, alt, and windows keys)
+			static bool Check(Type m1) {
+				return m1&Ctrl || m1&Alt || m1&Super;
+			}
 
-			ShiftCtrl	= Shift | Ctrl ,
-			ShiftAlt	= Shift | Alt  ,
-			CtrlAlt		= Ctrl  | Alt  ,
-			ShiftCtrlAlt= Shift | Ctrl | Alt ,
+			static bool Check() {
+				return Current&Ctrl || Current&Alt || Current&Super;
+			}
+
+			static Type Remove(Type m1, Type m2) {
+				return Type(m1 & ~m2);
+			}
+
+			static Type Add(Type m1, Type m2) {
+				return Type(m1 | m2);
+			}
+
+			static void Remove(Type m2) {
+				Current=Type(Current & ~m2);
+			}
+
+			static void Add(Type m2) {
+				Current=Type(Current | m2);
+			}
+
+			static bool IsModified() {
+				return Check();
+			}
+
+
+		private:
+			Modifier();
 		};
 
-		static bool isAlternate;
-		static Type Current;
-
-		////Checks the the current state of the keyboard if there are any real modifiers
-		/// in effect (Namely control, alt, and windows keys)
-		static bool Check(Type m1) {
-			return m1&Ctrl || m1&Alt || m1&Super;
-		}
-
-		static bool Check() {
-			return Current&Ctrl || Current&Alt || Current&Super;
+		////Bitwise OR operation on KeyboardModifier enumeration
+		inline Modifier::Type operator | (Modifier::Type m1, Modifier::Type m2) {
+			return Modifier::Type( m1|m2 );
 		}
 
-		static Type Remove(Type m1, Type m2) {
-			return Type(m1 & ~m2);
+		////Bitwise AND operation on KeyboardModifier enumeration
+		inline Modifier::Type operator & (Modifier::Type m1, Modifier::Type m2) {
+			return Modifier::Type( m1&m2 );
 		}
 
-		static Type Add(Type m1, Type m2) {
-			return Type(m1 | m2);
+		////Bitwise EQUAL OR operation on KeyboardModifier enumeration
+		inline Modifier::Type operator |= (Modifier::Type m1, Modifier::Type m2) {
+			return Modifier::Type( m1|m2 );
 		}
 
-		static void Remove(Type m2) {
-			Current=Type(Current & ~m2);
-		}
-
-		static void Add(Type m2) {
-			Current=Type(Current | m2);
+		////Bitwise EQUAL AND operation on KeyboardModifier enumeration
+		inline Modifier::Type operator &= (Modifier::Type m1, Modifier::Type m2) {
+			return Modifier::Type( m1&m2 );
 		}
 
-		static bool IsModified() {
-			return Check();
-		}
+		class KeyCodes {
+		public:
+			static const int Shift;
+			static const int Control;
+			static const int Alt;
+			static const int Super;
+
+			static const int Home;
+			static const int End;
+			static const int Insert;
+			static const int Delete;
+			static const int PageUp;
+			static const int PageDown;
+
+			static const int Left;
+			static const int Up;
+			static const int Right;
+			static const int Down;
+
+			static const int PrintScreen;
+			static const int Pause;
+
+			static const int CapsLock;
+			static const int NumLock;
+
+			static const int Enter;
+			static const int Tab;
+			static const int Backspace;
+			static const int Space;
+			static const int Escape;
+
+			static const int F1;
+			static const int F2;
+			static const int F3;
+			static const int F4;
+			static const int F5;
+			static const int F6;
+			static const int F7;
+			static const int F8;
+			static const int F9;
+			static const int F10;
+			static const int F11;
+			static const int F12;
+		};
 
 
-	private:
-		KeyboardModifier();
-	};
+		////Types of keyboard events
+		class Event {
+		public:
+			enum Type {
+				////A character is typed (O/S controlled, i.e. repeating keys)
+				Char,
+				////A key is pressed
+				Down,
+				////A key is released
+				Up
+			} event;
 
-	////Bitwise OR operation on KeyboardModifier enumeration
-	inline KeyboardModifier::Type operator | (KeyboardModifier::Type m1, KeyboardModifier::Type m2) {
-		return KeyboardModifier::Type( m1|m2 );
-	}
+			int keycode;
+
+			Event() { }
+			Event(Type event, int keycode) : event(event), keycode(keycode) { }
 
-	////Bitwise AND operation on KeyboardModifier enumeration
-	inline KeyboardModifier::Type operator & (KeyboardModifier::Type m1, KeyboardModifier::Type m2) {
-		return KeyboardModifier::Type( m1&m2 );
+			bool operator ==(const Event &r) const {
+				return (event==r.event)&&(keycode==r.keycode);
+			}
+		};
 	}
+} }
 
-	////Bitwise EQUAL OR operation on KeyboardModifier enumeration
-	inline KeyboardModifier::Type operator |= (KeyboardModifier::Type m1, KeyboardModifier::Type m2) {
-		return KeyboardModifier::Type( m1|m2 );
+namespace std { //for consumable event's token list
+	template<>
+	class hash<gge::input::keyboard::Event>
+		: public unary_function<gge::input::keyboard::Event, size_t>
+	{	// hash functor
+	public:
+		typedef gge::input::keyboard::Event _Kty;
+
+		size_t operator()(const _Kty& _Keyval) const {	
+			return _Keyval.event<<16 ^ _Keyval.keycode;
+		}
+	};
+}
+
+namespace gge { namespace input {
+	namespace keyboard {
+		extern utils::ConsumableEvent<utils::Empty, Event> Events;
 	}
 
-	////Bitwise EQUAL AND operation on KeyboardModifier enumeration
-	inline KeyboardModifier::Type operator &= (KeyboardModifier::Type m1, KeyboardModifier::Type m2) {
-		return KeyboardModifier::Type( m1&m2 );
-	}
+	namespace mouse {
+
+		class HandlerBase;
+		class Event;
+
+		class MouseTarget {
 
-	class KeyCodes {
-	public:
-		static const int Shift;
-		static const int Control;
-		static const int Alt;
-		static const int Super;
+		};
+
+		class Event {
+		public:
+			enum Type {
+				None		= 0,
 
-		//!TODO: list all keycode except ASCII ones
-/*		static const int Home;
-		static const int End;
-		static const int PageUp;
-		static const int PageDown;
-		static const int Left;
-		static const int Top;
-		static const int Right;
-		static const int Bottom;
-	*/
-	};
+				Left		= 1<<0,
+				Right		= 1<<1,
+				Middle		= 1<<2,
+				X1			= 1<<3,
+				X2			= 1<<4,
 
+				Click		= 1<<5,
+				Down		= 1<<6,
+				Up			= 1<<7,
+				DoubleClick	= 1<<8,
+
+				Over		= 1<<9,
+				Out			= 1<<10,
+				Move		= 1<<11,
+				VScroll		= 1<<12,
+				HScroll		= 1<<13,
+
+				OverCheck	= 1<<14,
 
 
-	////Types of mouse event
-	enum MouseEventType {
-		MOUSE_EVENT_NONE=0,
-		MOUSE_EVENT_LEFT=1,
-		MOUSE_EVENT_RIGHT=2,
-		MOUSE_EVENT_MIDDLE=4,
+				Left_Click	= Left	| Click,
+				Right_Click	= Right	| Click,
+				Middle_Click= Middle| Click,
+				X1_Click	= X1	| Click,
+				X2_Click	= X2	| Click,
+
+				Left_Down	= Left	| Down,
+				Right_Down	= Right	| Down,
+				Middle_Down	= Middle| Down,
+				X1_Down		= X1	| Down,
+				X2_Down		= X2	| Down,
+
+				Left_Up		= Left	| Up,
+				Right_Up	= Right	| Up,
+				Middle_Up	= Middle| Up,
+				X1_Up		= X1	| Up,
+				X2_Up		= X2	| Up,
+
+				Left_DoubleClick	= Left	| DoubleClick,
+				Right_DoubleClick	= Right	| DoubleClick,
+				Middle_DoubleClick	= Middle| DoubleClick,
+				X1_DoubleClick		= X1	| DoubleClick,
+				X2_DoubleClick		= X2	| DoubleClick,
+
+				ButtonMask			= B8 (00001111),
+				AllButOverCheck		= B16(00011111,11111111),
+			};
 
-		MOUSE_EVENT_CLICK=0,
-		////Left click
-		MOUSE_EVENT_LCLICK=1,
-		////Right click
-		MOUSE_EVENT_RCLICK=2,
-		////Middle click
-		MOUSE_EVENT_MCLICK=4,
+			static bool isClick(Type t) {
+				return (t&ButtonMask) && (t&Click);
+			}
+
+			static bool isDown(Type t) {
+				return (t&ButtonMask) && (t&Down);
+			}
+
+			static bool isUp(Type t) {
+				return (t&ButtonMask) && (t&Up);
+			}
+
+			static bool isDoubleClick(Type t) {
+				return (t&ButtonMask) && (t&DoubleClick);
+			}
+
+			static bool isLeft(Type t) {
+				return (t&Left);
+			}
+
+			static bool isRight(Type t) {
+				return (t&Right)!=0;
+			}
+
+			static bool isMiddle(Type t) {
+				return (t&Middle)!=0;
+			}
+
+			static Type getButton(Type t) {
+				return (Type)(t&ButtonMask);
+			}
 
-		MOUSE_EVENT_DOWN=8,
-		////Left button down
-		MOUSE_EVENT_LDOWN=9,
-		////Right button down
-		MOUSE_EVENT_RDOWN=10,
-		////Middle button down
-		MOUSE_EVENT_MDOWN=12,
+			static bool isX1(Type t) {
+				return (t&X1)!=0;
+			}
+
+			static bool isX2(Type t) {
+				return (t&X2)!=0;
+			}
+
+			class Target {
+			public:
+
+				Target(HandlerBase *handler, Event::Type eventmask=AllButOverCheck) : EventMask(eventmask) ,handler(handler)  {
+
+				}
+
+				Event::Type EventMask;
+				HandlerBase *handler;
+
+				virtual bool Fire(Event::Type event, utils::Point location, int amount);
+
+			};
+		};
+
+		Event::Type operator | (Event::Type l, Event::Type r) {
+			return (Event::Type)((int)l|r);
+		}
+
+		Event::Type operator & (Event::Type l, Event::Type r) {
+			return (Event::Type)((int)l&r);
+		}
 
-		MOUSE_EVENT_UP=16,
-		////Left button up
-		MOUSE_EVENT_LUP=17,
-		////Right button up
-		MOUSE_EVENT_RUP=18,
-		////Middle button up
-		MOUSE_EVENT_MUP=20,
+		Event::Type operator ~ (Event::Type l) {
+			return (Event::Type)(~(int)l);
+		}
+
+		class EventChain {
+		private:
+
+		public:
+			class Object : public Event::Target {
+				friend class EventChain;
+			public:
+				Object(HandlerBase *handler, utils::Bounds bounds, Event::Type eventmask=Event::AllButOverCheck) : Event::Target(handler, eventmask), Bounds(bounds), enabled(true) {
+
+				}
+				~Object();
+
+				utils::Bounds Bounds;
+
+				void Reorder(int order) {
+					wrapper->Reorder(order);
+				}
+
+				int GetOrder() const {
+					return wrapper->GetKey();
+				}
+
+				void Remove();
+
+				void Enable() {
+					enabled=true;
+				}
 
-		MOUSE_EVENT_DBLCLICK=32,
-		////Left button double click
-		MOUSE_EVENT_LDBLCLICK=33,
-		////Right button double click
-		MOUSE_EVENT_RDBLCLICK=34,
-		////Middle button double click
-		MOUSE_EVENT_MDBLCLICK=36,
+				void Disable() {
+					enabled=false;
+				}
+
+				void ToggleEnabled() {
+					enabled=!enabled;
+				}
+
+				bool isEnabled() const {
+					return enabled;
+				}
+
+				virtual bool Fire(Event::Type event, utils::Point location, int amount) {
+					if(!enabled)
+						return false;
+
+					return Event::Target::Fire(event, location, amount);
+				}
+
+			private:
+				utils::SortedCollection<Object>::Wrapper * wrapper;
+
+				bool enabled;
+			};
+
+			bool Fire(Event::Type event, utils::Point location, int amount) {
+				for(utils::SortedCollection<Object>::Iterator i=Events.First();i.isValid();i.Next()) {
+					i->Fire(event, location, amount);
+				}
+			}
+
+			utils::SortedCollection<Object> Events;
+
+
+		private:
+			Object &Register(HandlerBase *handler, utils::Bounds bounds, Event::Type eventmask) {
+				Object *obj=new Object(
+					handler,
+					bounds,
+					eventmask
+				);
+
+				obj->wrapper=&Events.Add(obj);
+
+				return *obj;
+			}
+
+		public:
+			Object &Register(bool (*fn)(Event::Type event, utils::Point location, int amount, utils::Any data), utils::Bounds bounds, utils::Any data, Event::Type eventmask=Event::AllButOverCheck);
+
+			Object &Register(bool (*fn)(Event::Type event, utils::Point location, int amount), utils::Bounds bounds, Event::Type eventmask=Event::AllButOverCheck);
+
+			Object &Register(bool (*fn)(Event::Type event, utils::Point location), utils::Bounds bounds, Event::Type eventmask=Event::AllButOverCheck);
+
+			Object &Register(bool (*fn)(utils::Point location), utils::Bounds bounds, Event::Type eventmask=Event::AllButOverCheck);
+
+			Object &Register(bool (*fn)(), utils::Bounds bounds, Event::Type eventmask=Event::AllButOverCheck);
+
+			template <class R_>
+			Object &Register(R_ &object, bool (R_::*fn)(Event::Type event, utils::Point location, int amount, utils::Any data), utils::Bounds bounds, utils::Any data, Event::Type eventmask=Event::AllButOverCheck);
 
-		////Mouse is over the target
-		MOUSE_EVENT_OVER,
-		////Mouse is out of the target
-		MOUSE_EVENT_OUT,
-		////Mouse moves within the target
-		MOUSE_EVENT_MOVE,
-		////Check if the mouse is over the target
-		/// application should not perform any mouse over
-		/// operation if the event is received
-		MOUSE_EVENT_OVER_CHECK,
+			template <class R_>
+			Object &Register(R_ &object, bool (R_::*fn)(Event::Type event, utils::Point location, int amount), utils::Bounds bounds, Event::Type eventmask=Event::AllButOverCheck);
+
+			template <class R_>
+			Object &Register(R_ &object, bool (R_::*fn)(Event::Type event, utils::Point location), utils::Bounds bounds, Event::Type eventmask=Event::AllButOverCheck);
+
+			template <class R_>
+			Object &Register(R_ &object, bool (R_::*fn)(utils::Point location), utils::Bounds bounds, Event::Type eventmask=Event::AllButOverCheck);
+
+			template <class R_>
+			Object &Register(R_ &object, bool (R_::*fn)(), utils::Bounds bounds, Event::Type eventmask=Event::AllButOverCheck);
+		};
+
+		////This is a code base to help with mouse events
+		class EventProvider {
+		public:
+
+			virtual bool PropagateMouseEvent(Event::Type event, utils::Point location, int amount);
+
+			EventChain MouseEvents;
+
+		protected:
+
+		};
+
+		class EventCallback {
+		private:
 
-		////Vertical mouse scrolling is used
-		MOUSE_EVENT_VSCROLLL,
-		////Horizontal mouse scrolling is used
-		MOUSE_EVENT_HSCROLLL,
-		
-		
-		MOUSE_EVENT_X1=64,
-		MOUSE_EVENT_X1CLICK=MOUSE_EVENT_X1 | MOUSE_EVENT_CLICK,
-		MOUSE_EVENT_X1DOWN=MOUSE_EVENT_X1 | MOUSE_EVENT_DOWN,
-		MOUSE_EVENT_X1UP=MOUSE_EVENT_X1 | MOUSE_EVENT_DOWN,
-		MOUSE_EVENT_X1DBLCLICK=MOUSE_EVENT_X1 | MOUSE_EVENT_DBLCLICK,
+		public:
+			class Object : public Event::Target {
+				friend class EventCallback;
+			public:
+				Object(HandlerBase *handler, Event::Type eventmask=Event::AllButOverCheck) : Event::Target(handler, eventmask), enabled(true) {
+
+				}
+				~Object();
+
+				void Enable() {
+					enabled=true;
+				}
+
+				void Disable() {
+					enabled=false;
+				}
+
+				void ToggleEnabled() {
+					enabled=!enabled;
+				}
+
+				bool isEnabled() const {
+					return enabled;
+				}
+
+				virtual bool Fire(Event::Type event, utils::Point location, int amount) {
+					if(!enabled)
+						return false;
+
+					return Event::Target::Fire(event, location, amount);
+				}
+
+			private:
+				utils::SortedCollection<Object>::Wrapper * wrapper;
 
-		MOUSE_EVENT_X2=128,
-		MOUSE_EVENT_X2CLICK=MOUSE_EVENT_X2 | MOUSE_EVENT_CLICK,
-		MOUSE_EVENT_X2DOWN=MOUSE_EVENT_X2 | MOUSE_EVENT_DOWN,
-		MOUSE_EVENT_X2UP=MOUSE_EVENT_X2 | MOUSE_EVENT_DOWN,
-		MOUSE_EVENT_X2DBLCLICK=MOUSE_EVENT_X2 | MOUSE_EVENT_DBLCLICK,
-		
-	};
+				bool enabled;
+			};
+
+			operator bool() {
+				if(!object)
+					return false;
+				if(!object->isEnabled())
+					return false;
+
+				return true;
+			}
+
+			bool Fire(Event::Type event, utils::Point location, int amount) {
+				if(object)
+					object->Fire(event, location, amount);
+				else
+					return false;
+			}
+
+			Object *object;
+
+
+		private:
+			Object &Set(HandlerBase *handler, Event::Type eventmask) {
+				if(object)
+					delete object;
+
+				object=new Object(
+					handler,
+					eventmask
+				);
+
+				return *object;
+			}
+
+		public:
+			Object &Set(bool (*fn)(Event::Type event, utils::Point location, int amount, utils::Any data), utils::Any data, Event::Type eventmask=Event::AllButOverCheck);
+
+			Object &Set(bool (*fn)(Event::Type event, utils::Point location, int amount), Event::Type eventmask=Event::AllButOverCheck);
+
+			Object &Set(bool (*fn)(Event::Type event, utils::Point location), Event::Type eventmask=Event::AllButOverCheck);
+
+			Object &Set(bool (*fn)(utils::Point location), Event::Type eventmask=Event::AllButOverCheck);
+
+			Object &Set(bool (*fn)(), Event::Type eventmask=Event::AllButOverCheck);
+
+			template <class R_>
+			Object &Set(R_ &object, bool (R_::*fn)(Event::Type event, utils::Point location, int amount, utils::Any data), utils::Any data, Event::Type eventmask=Event::AllButOverCheck);
+
+			template <class R_>
+			Object &Set(R_ &object, bool (R_::*fn)(Event::Type event, utils::Point location, int amount), Event::Type eventmask=Event::AllButOverCheck);
+
+			template <class R_>
+			Object &Set(R_ &object, bool (R_::*fn)(Event::Type event, utils::Point location), Event::Type eventmask=Event::AllButOverCheck);
+
+			template <class R_>
+			Object &Set(R_ &object, bool (R_::*fn)(utils::Point location), Event::Type eventmask=Event::AllButOverCheck);
+
+			template <class R_>
+			Object &Set(R_ &object, bool (R_::*fn)(), Event::Type eventmask=Event::AllButOverCheck);
 
-	////Types of keyboard events
-	class KeyboardEvent {
-	public:
-		enum Type {
-			////A character is typed (O/S controlled, i.e. repeating keys)
-			Char,
-			////A key is pressed
-			Down,
-			////A key is released
-			Up
-		} event;
+			void Reset() {
+				if(object)
+					delete object;
+
+				object=NULL;
+			}
+		};
+
+		////This is a code base to help with mouse events
+		class CallbackProvider {
+		public:
+
+			virtual bool PropagateMouseEvent(Event::Type event, utils::Point location, int amount);
+
+			EventCallback Callback;
+
+		protected:
+
+		};
+
+		class HandlerBase{
+		public:
+			utils::Any data;
+
+			HandlerBase(utils::Any data) : data(data) {
+
+			}
 
-		int keycode;
-	};
+			virtual bool Fire(Event::Type event, utils::Point location, int amount) = 0;
+		};
+		class FullFunctionHandler : public HandlerBase {
+		public:
+			typedef bool (*Handler)(Event::Type event, utils::Point location, int amount, utils::Any data);
+			Handler fn;
+
+			FullFunctionHandler(Handler fn, utils::Any data) : HandlerBase(data), fn(fn) {
+
+			}
+
+			virtual bool Fire(Event::Type event, utils::Point location, int amount) {
+				return fn(event, location, amount, data);
+			}
+		};
 
-	struct MouseEventObject;
-	////Token given by registering a mouse event
-	typedef	utils::LinkedListItem<MouseEventObject> (*MouseEventToken);
-	////Defines how a mouse event handing function should be
-	typedef bool (*MouseEvent)(MouseEventType event, int x, int y, void *data);
-	////Defines how a mouse scroll event handing function should be
-	typedef bool (*MouseScrollEvent)(int amount, MouseEventType event, int x, int y, void *data);
+		class FunctionHandler : public HandlerBase {
+		public:
+			typedef bool (*Handler)(Event::Type event, utils::Point location, int amount);
+			Handler fn;
+
+			FunctionHandler(Handler fn) : HandlerBase(utils::Any()), fn(fn) {
+
+			}
+
+			virtual bool Fire(Event::Type event, utils::Point location, int amount) {
+				return fn(event, location, amount);
+			}
+		};
+
+		class NoAmountFunctionHandler : public HandlerBase {
+		public:
+			typedef bool (*Handler)(Event::Type event, utils::Point location);
+			Handler fn;
 
-	////Mouse event object is used internally to keep track of mouse event handlers
-	struct MouseEventObject {
-		////Bounds of the event area, this variable is relative to the enclosing layer
-		Bounds bounds;
-		////Mouse over event handler
-		MouseEvent over;
-		////Mouse over event check handler
-		MouseEvent checkover;
-		////Mouse out event handler
-		MouseEvent out;
-		////Mouse click event handler
-		MouseEvent click;
-		////Mouse move event handler
-		MouseEvent move;
-		////Mouse down event handler
-		MouseEvent down;
-		////Mouse up event handler
-		MouseEvent up;
-		////Mouse double click event handler
-		MouseEvent dblclick;
-		////Vertical scroll event
-		MouseScrollEvent vscroll;
-		////Horizontal scroll event (don't rely on it most mice do not have horizontal scroll)
-		MouseScrollEvent hscroll;
-		////The token given by register mouse event
-		MouseEventToken *token;
-		BasicPointerTarget *parent;
-		////Any data that is left to be passed to event handlers
-		void *data;
-		////Whether mouse is reported to be over this region
-		bool isover;
-		////Whether this mouse event is enabled
-		bool Enabled;
-	};
-	extern MouseEventObject *pressedObject;
+			NoAmountFunctionHandler(Handler fn) : HandlerBase(utils::Any()), fn(fn) {
+
+			}
+
+			virtual bool Fire(Event::Type event, utils::Point location, int amount) {
+				return fn(event, location);
+			}
+		};
+
+		class LocationOnlyFunctionHandler : public HandlerBase {
+		public:
+			typedef bool (*Handler)(utils::Point location);
+			Handler fn;
+
+			LocationOnlyFunctionHandler(Handler fn) : HandlerBase(utils::Any()), fn(fn) {
+
+			}
+
+			virtual bool Fire(Event::Type event, utils::Point location, int amount) {
+				return fn(location);
+			}
+		};
+
+		class EmptyFunctionHandler : public HandlerBase {
+		public:
+			typedef bool (*Handler)();
+			Handler fn;
+
+			EmptyFunctionHandler(Handler fn) : HandlerBase(utils::Any()), fn(fn) {
+
+			}
+
+			virtual bool Fire(Event::Type event, utils::Point location, int amount) {
+				return fn();
+			}
+		};
+
+		template <class R_>
+		class FullClassHandler : public HandlerBase {
+		public:
+			typedef bool (*Handler)(Event::Type event, utils::Point location, int amount, utils::Any data);
+			Handler fn;
+			R_ *object;
+
+			FullClassHandler(R_ *object, Handler fn, utils::Any data) : HandlerBase(data), object(object), fn(fn) {
+
+			}
+
+			virtual bool Fire(Event::Type event, utils::Point location, int amount) {
+				return (object->*fn)(event, location, amount, data);
+			}
+		};
+
+		template <class R_>
+		class ClassHandler : public HandlerBase {
+		public:
+			typedef bool (*Handler)(Event::Type event, utils::Point location, int amount);
+			Handler fn;
+			R_ *object;
+
+			ClassHandler(R_ *object, Handler fn) : HandlerBase(utils::Any()), object(object), fn(fn) {
 
+			}
+
+			virtual bool Fire(Event::Type event, utils::Point location, int amount) {
+				return (object->*fn)(event, location, amount);
+			}
+		};
+
+		template <class R_>
+		class NoAmountClassHandler : public HandlerBase {
+		public:
+			typedef bool (*Handler)(Event::Type event, utils::Point location);
+			Handler fn;
+			R_ *object;
+
+			NoAmountClassHandler(R_ *object, Handler fn) : HandlerBase(utils::Any()), object(object), fn(fn) {
+
+			}
+
+			virtual bool Fire(Event::Type event, utils::Point location, int amount) {
+				return (object->*fn)(event, location);
+			}
+		};
+
+		template <class R_>
+		class LocationOnlyClassHandler : public HandlerBase {
+		public:
+			typedef bool (*Handler)(utils::Point location);
+			Handler fn;
+			R_ *object;
+
+			LocationOnlyClassHandler(R_ *object, Handler fn) : HandlerBase(utils::Any()), object(object), fn(fn) {
+
+			}
+
+			virtual bool Fire(Event::Type event, utils::Point location, int amount) {
+				return (object->*fn)(location);
+			}
+		};
+
+		template <class R_>
+		class EmptyClassHandler : public HandlerBase {
+		public:
+			typedef bool (*Handler)();
+			Handler fn;
+			R_ *object;
+
+			EmptyClassHandler(R_ *object, Handler fn) : HandlerBase(utils::Any()), object(object), fn(fn) {
+
+			}
+
+			virtual bool Fire(Event::Type event, utils::Point location, int amount) {
+				return (object->*fn)();
+			}
+		};
+
+		
+		extern Event::Type		PressedButtons;
+
+		extern Event::Target	*HoveredObject;
+		extern Event::Target	*PressedObject;
+
+		extern utils::Point	PressedPoint;
+		extern utils::Point	CurrentPoint;
+	}
 
 	namespace system {
 		////Processes a given char, this function intended to be called from OS
@@ -255,7 +727,7 @@
 		////Processes the current mouse position this information is taken from OS subsystem
 		void ProcessMousePosition(os::WindowHandle Window);
 		////Processes click of mouse button
-		///@button	: button number 1 for left, 2 for right and 4 for middle
+		///@button	: button number 1 for left, 2 for right  and 4 for middle
 		void ProcessMouseClick(int button, int x, int y);
 		////Processes given mouse button as pressed
 		///@button	: button number 1 for left, 2 for right and 4 for middle
@@ -270,103 +742,13 @@
 		void ProcessVScroll(int amount,int x,int y);
 		////Processes horizontal scroll
 		void ProcessHScroll(int amount,int x,int y);
+
+		extern bool hoverfound;
 	}
 
-	////This interface defines a class that can be used
-	/// as a common target of mouse events
-	class BasicPointerTarget {
-	public:
-		////The array of mouse events
-		utils::LinkedList<MouseEventObject> mouseevents;
 
-		////This function propagates the mouse event to mouse events
-		/// registered for this target if any of one of the targets is
-		/// the receiver of the event function will return true and 
-		/// propagation will terminate, this function is responsible
-		/// to determine who will receive the event
-		///@event	: the type of the mouse event
-		///@x		: Position of the event	
-		///@y		: Position of the event	
-		///@data	: Always null, used to preserve compatibility
-		virtual bool PropagateMouseEvent(MouseEventType event, int x, int y, void *data);
 
-		////This function propagates the mouse scroll event to mouse events
-		/// registered for this target if any of one of the targets is
-		/// the receiver of the event function will return true and 
-		/// propagation will terminate, this function is responsible
-		/// to determine who will receive the event
-		///@amount	: amount of scrolling
-		///@event	: the type of the mouse event
-		///@x		: Position of the event	
-		///@y		: Position of the event	
-		///@data	: Always null, used to preserve compatibility
-		virtual bool PropagateMouseScrollEvent(int amount, MouseEventType event, int x, int y, void *data);
-		////This function registers a mouse event with the given coordinates,
-		/// data and event handlers. This function returns mouse event token that
-		/// can be used to modify event properties, events are created in enabled state
-		MouseEventToken RegisterMouseEvent(int x, int y, int w, int h, void *data, 
-			MouseEvent click	, MouseEvent over=NULL, MouseEvent out=NULL,
-			MouseEvent move=NULL, MouseEvent down=NULL, MouseEvent up=NULL, MouseEvent doubleclick=NULL) {
-				Bounds b(x,y,x+w,y+h);
-				return RegisterMouseEvent(b,data,click,over,out,move,down,up,doubleclick);
-		}
-		////This function registers a mouse event with the given coordinates,
-		/// data and event handlers. This function returns mouse event token that
-		/// can be used to modify event properties, events are created in enabled state
-		MouseEventToken RegisterMouseEvent(Point position, int w, int h, void *data, 
-			MouseEvent click	, MouseEvent over=NULL, MouseEvent out=NULL,
-			MouseEvent move=NULL, MouseEvent down=NULL, MouseEvent up=NULL, MouseEvent doubleclick=NULL) {
-				Bounds b(position,w,h);
-				return RegisterMouseEvent(b,data,click,over,out,move,down,up,doubleclick);
-		}
-		////This function registers a mouse event with the given coordinates,
-		/// data and event handlers. This function returns mouse event token that
-		/// can be used to modify event properties, events are created in enabled state
-		MouseEventToken RegisterMouseEvent(Bounds bounds, void *data, 
-			MouseEvent click	, MouseEvent over=NULL, MouseEvent out=NULL,
-			MouseEvent move=NULL, MouseEvent down=NULL, MouseEvent up=NULL, MouseEvent doubleclick=NULL);
-		////This function disables a mouse event
-		void DisableMouseEvent(MouseEventToken token);
-		////This function enables a mouse event
-		void EnableMouseEvent(MouseEventToken token);
-		////This function removes the given mouse event
-		void RemoveMouseEvent(MouseEventToken token);
 
-	protected:
-		////This internal function propagates click events
-		virtual bool PropagateMouseClickEvent(MouseEventType event, int x, int y, void *data);
-		////This internal function propagates down events
-		virtual bool PropagateMouseDownEvent(MouseEventType event, int x, int y, void *data);
-		////This internal function propagates up events
-		virtual bool PropagateMouseUpEvent(MouseEventType event, int x, int y, void *data);
-		////This internal function propagates double click events
-		virtual bool PropagateMouseDblClickEvent(MouseEventType event, int x, int y, void *data);
-		////This internal function propagates move event
-		virtual bool PropagateMouseMoveEvent(MouseEventType event, int x, int y, void *data);
-		////This internal function propagates over event
-		virtual bool PropagateMouseOverEvent(MouseEventType event, int x, int y, void *data);
-		////This internal function propagates out event
-		virtual bool PropagateMouseOutEvent(MouseEventType event, int x, int y, void *data);
-		////This internal function propagates vertical scroll event
-		virtual bool PropagateMouseVScrollEvent(int amount, MouseEventType event, int x, int y, void *data);
-		////This internal function propagates horizontal scroll event
-		virtual bool PropagateMouseHScrollEvent(int amount, MouseEventType event, int x, int y, void *data);
-
-	};
-
-	extern utils::ConsumableEvent<utils::Empty, KeyboardEvent> KeyboardEvents;
-	extern MouseEventType MouseButtons;
-	////This is the object that is hovered, if mouse moves out of it
-	/// it should receive mouse out event
-	extern MouseEventObject *hoveredObject;
-
-	////This function registers a top level pointer target.
-	/// Lower level targets should be registered to their attached
-	/// targets, these pointer targets receive event coordinates
-	/// unaltered
-	utils::LinkedListItem<BasicPointerTarget> * AddPointerTarget(BasicPointerTarget *target, int order);
-	////Removes a previously registered pointer target
-	void RemovePointerTarget(utils::LinkedListItem<BasicPointerTarget> *target);
 	////Initializes Input system
 	void Initialize();
 } }
--- a/Engine/Layer.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/Layer.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -1,79 +1,62 @@
 #include "Layer.h"
+#include "GGEMain.h"
 
 using namespace gge::input;
 using namespace gge::utils;
 
 namespace gge {
 	namespace graphics {
-		extern int trX,trY;
+		extern Point translate;
 	}
 	using namespace graphics;
 
-	bool InputLayer::PropagateMouseEvent(input::MouseEventType event, int x, int y, void *data) {
-		if( isVisible && ((x>X && y>Y && x<X+W && y<Y+H) || (event&MOUSE_EVENT_UP) || (pressedObject && event&MOUSE_EVENT_MOVE)) ) {
-			if(LayerBase::PropagateMouseEvent(event, x-X, y-Y, data))
-				return true;
+	bool InputLayer::PropagateMouseEvent(input::mouse::Event::Type event, utils::Point location, int amount) {
+		if(LayerBase::PropagateMouseEvent(event, location, amount))
+			return true;
 
-			if( isVisible && ((x>X && y>Y && x<X+W && y<Y+H) || (event&MOUSE_EVENT_UP) || (pressedObject->parent==this && event&MOUSE_EVENT_MOVE)) )
-				return BasicPointerTarget::PropagateMouseEvent(event, x-X, y-Y, data);
-			else
-				return false;
-		}
-
-		return false;
+		return EventProvider::PropagateMouseEvent(event, location-BoundingBox.TopLeft(), amount);
 	}
 
-	bool LayerBase::PropagateMouseEvent(MouseEventType event, int x, int y, void *data) {
-		if( isVisible && ((x>X && y>Y && x<X+W && y<Y+H) || (event&MOUSE_EVENT_UP) || (pressedObject && event&MOUSE_EVENT_MOVE)) ) {
-			LinkedListOrderedIterator<LayerBase> it=SubLayers;
-			LayerBase *layer;
-			
-			while(layer=it)
-				if(layer->PropagateMouseEvent(event, x-X, y-Y, data))
+	bool LayerBase::PropagateMouseEvent(input::mouse::Event::Type event, utils::Point location, int amount) {
+		if( 
+			(isVisible && BoundingBox.isInside(location)) || 
+			input::mouse::Event::isUp(event) || 
+			(event&input::mouse::Event::Out) || 
+			(input::mouse::PressedObject && (event&input::mouse::Event::Move)) ) 
+		{
+			for(utils::SortedCollection<LayerBase>::Iterator i=SubLayers.Last(); i.isValid(); i.Previous()) {
+				if(i->PropagateMouseEvent(event, location-BoundingBox.TopLeft(), amount))
 					return true;
-		}
-
-		return false;
-	}
-
-	bool InputLayer::PropagateMouseScrollEvent(int amount, MouseEventType event, int x, int y, void *data) {
-		if( isVisible && ((x>X && y>Y && x<X+W && y<Y+H)) ) {
-			if(LayerBase::PropagateMouseScrollEvent(amount, event, x-X, y-Y, data))
-				return true;
-
-			if( isVisible && ((x>X && y>Y && x<X+W && y<Y+H) || (event&MOUSE_EVENT_UP) || (pressedObject->parent==this && event&MOUSE_EVENT_MOVE)) )
-				return BasicPointerTarget::PropagateMouseScrollEvent(amount, event, x-X, y-Y, data);
-			else
-				return false;
-		}
-
-		return false;
-	}
-
-	bool LayerBase::PropagateMouseScrollEvent(int amount, MouseEventType event, int x, int y, void *data) {
-		if( isVisible && ((x>X && y>Y && x<X+W && y<Y+H)) ) {
-			LinkedListOrderedIterator<LayerBase> it=SubLayers;
-			LayerBase *layer;
-			
-			while(layer=it)
-				if(layer->PropagateMouseScrollEvent(amount, event, x-X, y-Y, data))
-					return true;
+			}
 		}
 
 		return false;
 	}
 
 	void LayerBase::Render() {
-		trX+=X;
-		trY+=Y;
+		translate+=BoundingBox.TopLeft();
 		if(isVisible) {
-			LinkedListOrderedIterator<LayerBase> it=SubLayers.GetReverseOrderedIterator();
-			LayerBase *layer;
-			
-			while(layer=it)
-				layer->Render();
+			for(utils::SortedCollection<LayerBase>::Iterator i=SubLayers.Last(); i.isValid(); i.Previous()) {
+				i->Render();
+			}
 		}
-		trX-=X;
-		trY-=Y;
+		translate-=BoundingBox.TopLeft();
+	}
+
+	LayerBase::LayerBase(int X,int Y ) : 
+		parent(NULL), 
+		wrapper(NULL), 
+		BoundingBox(X, Y, X+Main.getWidth(), Y+Main.getHeight()),
+		isVisible(true) {
+
+	}
+
+	LayerBase::LayerBase( const utils::Point &p ) : 
+		parent(NULL), 
+		wrapper(NULL), 
+		BoundingBox(p.x, p.y, p.x+Main.getWidth(), p.y+Main.getHeight()),
+		isVisible(true)
+	{
+
 	}
 }
\ No newline at end of file
--- a/Engine/Layer.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/Layer.h	Mon Jul 18 22:25:11 2011 +0000
@@ -1,9 +1,13 @@
 #pragma once
 
 #include "../Utils/Collection.h"
-#include "../Utils/LinkedList.h"
+#include "../Utils/Point2D.h"
+#include "../Utils/SortedCollection.h"
 
 #include "Input.h"
+#include "../Utils/Size2D.h"
+#include "../Utils/Rectangle2D.h"
+#include "../Utils/Bounds2D.h"
 
 namespace gge {
 	////This class is the base class for all layer types.
@@ -18,70 +22,103 @@
 		bool isVisible;
 		////Sub-layers that this layer holds, all the sub-layers are
 		/// considered to be above current layer
-		utils::LinkedList<LayerBase> SubLayers;
+		utils::SortedCollection<LayerBase> SubLayers;
 
 		////Parent layer
 		LayerBase *parent;
-		////Main class for GGE
-		//GGEMain *main;
+		utils::SortedCollection<LayerBase>::Wrapper   *wrapper;
+		utils::Bounds BoundingBox;
+
+		LayerBase() : 
+			parent(NULL), 
+			wrapper(NULL),
+			isVisible(true)
+		{ }
 
-		LayerBase() : parent(NULL) { }
+		LayerBase(const utils::Bounds &b) : 
+			parent(NULL), 
+			wrapper(NULL), 
+			BoundingBox(b),
+			isVisible(true)
+		{ }
+
+		LayerBase(int L, int T, int R, int B) : 
+			parent(NULL), 
+			wrapper(NULL), 
+			BoundingBox(L,T,R,B),
+			isVisible(true)
+		{ }
+
+		LayerBase(int X,int Y);
 
-		virtual LayerBase *Add(LayerBase *layer, int Order=0) { if(layer->parent) layer->parent->Remove(layer); layer->parent=this; SubLayers.AddItem(layer, Order); return layer; }
-		virtual LayerBase &Add(LayerBase &layer, int Order=0) { if(layer.parent) layer.parent->Remove(layer); layer.parent=this; SubLayers.AddItem(&layer, Order); return layer; }
-		virtual void Remove(LayerBase *layer) { SubLayers.Remove(layer); }
-		virtual void Remove(LayerBase &layer) { SubLayers.Remove(&layer); }
-		////Size of layer
-		int W;
-		////Size of layer
-		int H;
-		////Position of layer
-		int X;
-		////Position of layer
-		int Y;
+		LayerBase(const utils::Point &p);
+
+		virtual LayerBase *Add(LayerBase *layer, int Order=0) {
+			if(layer->parent) 
+				layer->parent->Remove(layer);
+
+			layer->parent=this;
+			layer->wrapper=&SubLayers.Add(layer, Order); 
+
+			return layer; 
+		}
+		virtual LayerBase &Add(LayerBase &layer, int Order=0) { 
+			return *Add(&layer,Order);
+		}
+		virtual void Remove(LayerBase *layer) { 
+			SubLayers.Remove(layer);
+			layer->parent=NULL;
+			layer->wrapper=NULL;
+		}
+		virtual void Remove(LayerBase &layer) { 
+			SubLayers.Remove(&layer); 
+			layer.parent=NULL;
+			layer.wrapper=NULL;
+		}
+		
 		////Renders the current layer, default handling is to pass
 		/// the request to the sub-layers
 		virtual void Render();
 
 		void setOrder(int Order) {
-			if(parent)
-				parent->SubLayers.FindListItem(this)->setOrder(Order);
+			if(parent && wrapper)
+				wrapper->Reorder(Order);
 		}
 
 		void OrderToTop() {
-			if(parent)
-				parent->SubLayers.FindListItem(this)->setOrder(parent->SubLayers.LowestOrder()-1);
+			if(parent && wrapper)
+				wrapper->Reorder(parent->SubLayers.LowestOrder()-1);
 		}
 
-		int getOrder() { 
-			if(parent)
-				return (int)parent->SubLayers.FindListItem(this)->getOrder(); 
+		int getOrder() const { 
+			if(parent && wrapper)
+				return wrapper->GetKey(); 
 			else
 				return 0;
 		}
 
 		void Move(int X,int Y) {
-			this->X=X;
-			this->Y=Y;
+			BoundingBox.MoveTo(X,Y);
 		}
 
 		void Resize(int W, int H) {
-			this->W=W;
-			this->H=H;
+			BoundingBox.SetSize(W, H);
+		}
+
+		void Move(const utils::Point &p) {
+			BoundingBox.MoveTo(p);
 		}
 
-		void SetRectangle(Rectangle rect) {
-			X=rect.Left;
-			Y=rect.Top;
-			W=rect.Width;
-			H=rect.Height;
+		void Resize(const utils::Size &s) {
+			BoundingBox.SetSize(s);
+		}
+
+		void SetRectangle(utils::Rectangle rect) {
+			BoundingBox=rect;
 		}
 
 		void SetRectangle(int Left, int Top, int Width, int Height) {
-			X=Left;
-			Y=Top;
-			W=Width;
-			H=Height;
+			BoundingBox=utils::Bounds(Left, Top, Width, Height);
 		}
 
 		virtual ~LayerBase() {
@@ -89,22 +126,25 @@
 				parent->Remove(this);
 		}
 
-	protected:
 		////Processes the mouse event for the current layer, default
 		/// handling is to pass the request to the sub-layers
-		virtual bool PropagateMouseEvent(input::MouseEventType event, int x, int y, void *data);
-		virtual bool PropagateMouseScrollEvent(int amount, input::MouseEventType event, int x, int y, void *data);
+		virtual bool PropagateMouseEvent(input::mouse::Event::Type event, utils::Point location, int amount);
+
+	protected:
 	};
 
-	class InputLayer : public LayerBase, public input::BasicPointerTarget {
+	class InputLayer : public LayerBase, public input::mouse::EventProvider {
 	public:
-		InputLayer(int X, int Y, int W, int H) : LayerBase() {
-			this->X=X;
-			this->Y=Y;
-			this->W=W;
-			this->H=H;
-		}
-		virtual bool PropagateMouseEvent(input::MouseEventType event, int x, int y, void *data);
-		virtual bool PropagateMouseScrollEvent(int amount, input::MouseEventType event, int x, int y, void *data);
+ 		InputLayer() : LayerBase() { }
+
+		InputLayer(const utils::Bounds &b) : LayerBase(b) { }
+
+		InputLayer(int L, int T, int R, int B) : LayerBase(L,T,R,B) { }
+
+		InputLayer(int X,int Y) : LayerBase(X,Y) { }
+
+		InputLayer(const utils::Point &p) : LayerBase(p) { }
+
+		virtual bool PropagateMouseEvent(input::mouse::Event::Type event, utils::Point location, int amount);
 	};
 }
--- a/Engine/Multimedia.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/Multimedia.h	Mon Jul 18 22:25:11 2011 +0000
@@ -2,8 +2,8 @@
 
 
 #include "GGEMain.h"
+#include <atlbase.h>
 #include <dshow.h>
-#include <atlbase.h>
 #include "../Utils/Any.h"
 #include "../Utils/EventChain.h"
 
--- a/Engine/OS.Win32.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/OS.Win32.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -91,7 +91,7 @@
 						int x=lParam%0x10000;
 						int y=lParam>>16;
 						
-						ProcessMouseDown(1,x,y);
+						ProcessMouseDown(mouse::Event::Left,x,y);
 					}
 					break;
 				case WM_LBUTTONUP:
@@ -99,8 +99,8 @@
 						int x=lParam%0x10000;
 						int y=lParam>>16;
 						
-						ProcessMouseUp(1,x,y);
-						ProcessMouseClick(1,x,y);
+						ProcessMouseUp(mouse::Event::Left,x,y);
+						ProcessMouseClick(mouse::Event::Left,x,y);
 					}
 					break;
 				case WM_LBUTTONDBLCLK:
@@ -108,7 +108,7 @@
 						int x=lParam%0x10000;
 						int y=lParam>>16;
 						
-						ProcessMouseDblClick(1,x,y);
+						ProcessMouseDblClick(mouse::Event::Left,x,y);
 					}
 					break;
 
@@ -117,7 +117,7 @@
 						int x=lParam%0x10000;
 						int y=lParam>>16;
 						
-						ProcessMouseDown(2,x,y);
+						ProcessMouseDown(mouse::Event::Right,x,y);
 					}
 					break;
 				case WM_RBUTTONUP:
@@ -125,8 +125,8 @@
 						int x=lParam%0x10000;
 						int y=lParam>>16;
 						
-						ProcessMouseUp(2,x,y);
-						ProcessMouseClick(2,x,y);
+						ProcessMouseUp(mouse::Event::Right,x,y);
+						ProcessMouseClick(mouse::Event::Right,x,y);
 					}
 					break;
 				case WM_RBUTTONDBLCLK:
@@ -134,7 +134,7 @@
 						int x=(int)lParam%0x10000;
 						int y=(int)lParam>>16;
 						
-						ProcessMouseDblClick(2,x,y);
+						ProcessMouseDblClick(mouse::Event::Right,x,y);
 					}
 					break;
 
@@ -143,7 +143,7 @@
 						int x=lParam%0x10000;
 						int y=lParam>>16;
 						
-						ProcessMouseDown(4,x,y);
+						ProcessMouseDown(mouse::Event::Middle,x,y);
 					}
 					break;
 				case WM_MBUTTONUP:
@@ -151,8 +151,8 @@
 						int x=lParam%0x10000;
 						int y=lParam>>16;
 						
-						ProcessMouseUp(4,x,y);
-						ProcessMouseClick(4,x,y);
+						ProcessMouseUp(mouse::Event::Middle,x,y);
+						ProcessMouseClick(mouse::Event::Middle,x,y);
 					}
 					break;
 				case WM_MBUTTONDBLCLK:
@@ -160,7 +160,7 @@
 						int x=lParam%0x10000;
 						int y=lParam>>16;
 						
-						ProcessMouseDblClick(4,x,y);
+						ProcessMouseDblClick(mouse::Event::Middle,x,y);
 					}
 					break;
 
@@ -171,10 +171,10 @@
 						
 						switch(GET_XBUTTON_WPARAM(wParam)) {
 						case 1:
-							ProcessMouseDown(101,x,y);
+							ProcessMouseDown(mouse::Event::X1,x,y);
 							break;
 						case 2:
-							ProcessMouseDown(102,x,y);
+							ProcessMouseDown(mouse::Event::X2,x,y);
 							break;
 						}
 					}
@@ -187,12 +187,12 @@
 						
 						switch(GET_XBUTTON_WPARAM(wParam)) {
 						case 1:
-							ProcessMouseUp(101,x,y);
-							ProcessMouseClick(101,x,y);
+							ProcessMouseUp(mouse::Event::X1,x,y);
+							ProcessMouseClick(mouse::Event::X1,x,y);
 							break;
 						case 2:
-							ProcessMouseUp(102,x,y);
-							ProcessMouseClick(102,x,y);
+							ProcessMouseUp(mouse::Event::X2,x,y);
+							ProcessMouseClick(mouse::Event::X2,x,y);
 							break;
 						}
 					}
@@ -204,10 +204,10 @@
 						
 						switch(GET_XBUTTON_WPARAM(wParam)) {
 						case 1:
-							ProcessMouseDblClick(101,x,y);
+							ProcessMouseDblClick(mouse::Event::X1,x,y);
 							break;
 						case 2:
-							ProcessMouseDblClick(102,x,y);
+							ProcessMouseDblClick(mouse::Event::X2,x,y);
 							break;
 						}
 					}
@@ -232,72 +232,72 @@
 
 				case WM_KEYDOWN:
 					if(lParam&1<<24) //Ctrl & Alt
-						KeyboardModifier::isAlternate=true;
+						keyboard::Modifier::isAlternate=true;
 					else
-						KeyboardModifier::isAlternate=false;
+						keyboard::Modifier::isAlternate=false;
 
 					if(lParam==0x360001) //Shift
-						KeyboardModifier::isAlternate=true;
+						keyboard::Modifier::isAlternate=true;
 
 					if(wParam==VK_RWIN) { //Win
-						KeyboardModifier::isAlternate=true;
+						keyboard::Modifier::isAlternate=true;
 						wParam=VK_LWIN;
 					}
 
 					ProcessKeyDown(wParam);
-					KeyboardModifier::isAlternate=false;
+					keyboard::Modifier::isAlternate=false;
 
 					switch(wParam) {
 					case VK_CONTROL:
-						KeyboardModifier::Add(KeyboardModifier::Ctrl);
+						keyboard::Modifier::Add(keyboard::Modifier::Ctrl);
 						break;
 					case VK_SHIFT:
-						KeyboardModifier::Add(KeyboardModifier::Shift);
+						keyboard::Modifier::Add(keyboard::Modifier::Shift);
 						break;
 					case VK_MENU:
-						KeyboardModifier::Add(KeyboardModifier::Alt);
+						keyboard::Modifier::Add(keyboard::Modifier::Alt);
 						break;
 					case VK_LWIN:
-						KeyboardModifier::Add(KeyboardModifier::Super);
+						keyboard::Modifier::Add(keyboard::Modifier::Super);
 						break;
 					case VK_RWIN:
-						KeyboardModifier::Add(KeyboardModifier::Super);
+						keyboard::Modifier::Add(keyboard::Modifier::Super);
 						break;
 					}
 						
 					break; 
 				case WM_KEYUP:
 					if(lParam&1<<24)
-						KeyboardModifier::isAlternate=true;
+						keyboard::Modifier::isAlternate=true;
 					else
-						KeyboardModifier::isAlternate=false;
+						keyboard::Modifier::isAlternate=false;
 
 					if(lParam==0x360001)
-						KeyboardModifier::isAlternate=true;
+						keyboard::Modifier::isAlternate=true;
 
 					if(wParam==VK_RWIN) {
-						KeyboardModifier::isAlternate=true;
+						keyboard::Modifier::isAlternate=true;
 						wParam=VK_LWIN;
 					}
 
 					ProcessKeyUp(wParam);
-					KeyboardModifier::isAlternate=false;
+					keyboard::Modifier::isAlternate=false;
 
 					switch(wParam) {
 					case VK_CONTROL:
-						KeyboardModifier::Remove(KeyboardModifier::Ctrl);
+						keyboard::Modifier::Remove(keyboard::Modifier::Ctrl);
 						break;
 					case VK_SHIFT:
-						KeyboardModifier::Remove(KeyboardModifier::Shift);
+						keyboard::Modifier::Remove(keyboard::Modifier::Shift);
 						break;
 					case VK_MENU:
-						KeyboardModifier::Remove(KeyboardModifier::Alt);
+						keyboard::Modifier::Remove(keyboard::Modifier::Alt);
 						break;
 					case VK_LWIN:
-						KeyboardModifier::Remove(KeyboardModifier::Super);
+						keyboard::Modifier::Remove(keyboard::Modifier::Super);
 						break;
 					case VK_RWIN:
-						KeyboardModifier::Remove(KeyboardModifier::Super);
+						keyboard::Modifier::Remove(keyboard::Modifier::Super);
 						break;
 					}
 					
@@ -311,15 +311,15 @@
 					ProcessChar(wParam);
 					break; 
 				case WM_SYSKEYDOWN:
-					KeyboardModifier::Add(KeyboardModifier::Alt);
+					keyboard::Modifier::Add(keyboard::Modifier::Alt);
 					break; 
 				case WM_SYSKEYUP:
-					KeyboardModifier::Remove(KeyboardModifier::Alt);
+					keyboard::Modifier::Remove(keyboard::Modifier::Alt);
 					break; 
 				case WM_SYSCHAR:
-					KeyboardModifier::Add(KeyboardModifier::Alt);
+					keyboard::Modifier::Add(keyboard::Modifier::Alt);
 					ProcessChar(wParam);
-					KeyboardModifier::Remove(KeyboardModifier::Alt);
+					keyboard::Modifier::Remove(keyboard::Modifier::Alt);
 					break;
 				case WM_VIDEO_NOTIFY:
 					if(lParam) {
@@ -428,10 +428,10 @@
 			}
 		}
 		namespace input {
-			Point getMousePosition(WindowHandle Window) {
+			utils::Point getMousePosition(WindowHandle Window) {
 				POINT pnt;
 				RECT winrect;
-				Point ret;
+				utils::Point ret;
 				GetWindowRect((HWND)Window, &winrect);
 				GetCursorPos(&pnt);
 
@@ -447,10 +447,47 @@
 	} 
 
 	namespace input {
-		const int KeyCodes::Shift = VK_SHIFT;
-		const int KeyCodes::Control = VK_CONTROL;
-		const int KeyCodes::Alt = VK_MENU;
-		const int KeyCodes::Super = VK_LWIN;
+		const int keyboard::KeyCodes::Shift		= VK_SHIFT;
+		const int keyboard::KeyCodes::Control	= VK_CONTROL;
+		const int keyboard::KeyCodes::Alt		= VK_MENU;
+		const int keyboard::KeyCodes::Super		= VK_LWIN;
+
+		const int keyboard::KeyCodes::Home		= VK_HOME;
+		const int keyboard::KeyCodes::End		= VK_END;
+		const int keyboard::KeyCodes::Insert	= VK_INSERT;
+		const int keyboard::KeyCodes::Delete	= VK_DELETE;
+		const int keyboard::KeyCodes::PageUp	= VK_PRIOR;
+		const int keyboard::KeyCodes::PageDown	= VK_NEXT;
+
+		const int keyboard::KeyCodes::Left		= VK_LEFT;
+		const int keyboard::KeyCodes::Up		= VK_UP;
+		const int keyboard::KeyCodes::Right		= VK_RIGHT;
+		const int keyboard::KeyCodes::Down		= VK_DOWN;
+
+		const int keyboard::KeyCodes::PrintScreen=VK_SNAPSHOT;
+		const int keyboard::KeyCodes::Pause		= VK_PAUSE;
+
+		const int keyboard::KeyCodes::CapsLock	= VK_CAPITAL;
+		const int keyboard::KeyCodes::NumLock	= VK_NUMLOCK;
+
+		const int keyboard::KeyCodes::Enter		= VK_RETURN;
+		const int keyboard::KeyCodes::Backspace	= VK_BACK;
+		const int keyboard::KeyCodes::Escape	= VK_ESCAPE;
+		const int keyboard::KeyCodes::Tab		= VK_TAB;
+		const int keyboard::KeyCodes::Space		= VK_SPACE;
+
+		const int keyboard::KeyCodes::F1		= VK_F1;
+		const int keyboard::KeyCodes::F2		= VK_F2;
+		const int keyboard::KeyCodes::F3		= VK_F3;
+		const int keyboard::KeyCodes::F4		= VK_F4;
+		const int keyboard::KeyCodes::F5		= VK_F5;
+		const int keyboard::KeyCodes::F6		= VK_F6;
+		const int keyboard::KeyCodes::F7		= VK_F7;
+		const int keyboard::KeyCodes::F8		= VK_F8;
+		const int keyboard::KeyCodes::F9		= VK_F9;
+		const int keyboard::KeyCodes::F10		= VK_F10;
+		const int keyboard::KeyCodes::F11		= VK_F11;
+		const int keyboard::KeyCodes::F12		= VK_F12;
 	}
 
 }
--- a/Engine/OS.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/OS.h	Mon Jul 18 22:25:11 2011 +0000
@@ -1,6 +1,6 @@
 #pragma once
 
-#include "../Utils/GGE.h"
+#include "../Utils/Point2D.h"
 #include "../Utils/Any.h"
 #include "../Utils/EventChain.h"
 
@@ -33,7 +33,7 @@
 
 	namespace input {
 		////Gets the position of the cursor
-		Point getMousePosition(os::WindowHandle Window);
+		utils::Point getMousePosition(os::WindowHandle Window);
 		inline bool isPointerDisplayed() { return system::pointerdisplayed; }
 	}
 
--- a/Engine/Pointer.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/Pointer.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -1,6 +1,6 @@
 #include "Pointer.h"
 #include "../Utils/Collection.h"
-#include "../Utils/LinkedList.h"
+#include "../Utils/SortedCollection.h"
 #include "GraphicLayers.h"
 #include "GGEMain.h"
 #include "../Resource/FolderResource.h"
@@ -10,6 +10,7 @@
 #include "OS.h"
 
 using namespace gge::resource;
+using namespace gge::utils;
 
 namespace gge {
 
@@ -39,16 +40,20 @@
 			os::HidePointer();
 		}
 
-		Pointer *pointer=ActivePointers.getOrderedLastItem();
-		if(pointer==NULL)
+		Pointer *pointer;
+		
+		if(ActivePointers.GetSize()==0)
 			pointer=BasePointer;
+		else
+			pointer=ActivePointers.LastItem().GetPtr();
 
 
 		pointer->Image->Draw(PointerLayer, pnt-pointer->Hotspot);
 	}
 
-	void PointerCollection::Initialize(GGEMain &Main) {
-		PointerLayer=dynamic_cast<graphics::Basic2DLayer*>(Main.Add( new graphics::Basic2DLayer(0, 0, Main.getWidth(), Main.getHeight()) , -100 ));
+	void PointerCollection::Initialize(GGEMain &Main, int LayerOrder) {
+		PointerLayer=new graphics::Basic2DLayer(0, 0, Main.getWidth(), Main.getHeight());
+		Main.Add( PointerLayer , LayerOrder );
 
 		os::window::Activated.Register(this, &PointerCollection::Window_Activate);
 		os::window::Deactivated.Register(this, &PointerCollection::Window_Deactivate);
@@ -61,18 +66,14 @@
 
 	void PointerCollection::Fetch(FolderResource *Folder) {
 		DataResource *data=Folder->asData(0);
-		
-		utils::LinkedListIterator<ResourceBase> it=Folder->Subitems;
-		ResourceBase *resource;
-		resource=it;
 
 		int i=0;
-		while(resource=it) {
-			if(resource->getGID()==GID_ANIMATION) {
-				AnimationResource *anim=dynamic_cast<AnimationResource *>(resource);
+		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)) );
-			} else if(resource->getGID()==GID_IMAGE) {
-				ImageResource *img=dynamic_cast<ImageResource *>(resource);
+			} 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)) );
 			}
 
@@ -80,7 +81,7 @@
 		}
 
 		if(i>0)
-			BasePointer=(*this)[0];
+			BasePointer=&(*this)[0];
 	}
 
 	Pointer *PointerCollection::Add(graphics::Buffered2DGraphic *pointer, Point Hotspot, Pointer::PointerTypes Type) {
@@ -90,15 +91,13 @@
 	}
 
 	int PointerCollection::Set(Pointer *Pointer) {
-		return reinterpret_cast<int>(ActivePointers.AddItem(Pointer, ActivePointers.HighestOrder()+1));
+		return reinterpret_cast<Token>(&ActivePointers.Add(Pointer, ActivePointers.HighestOrder()+1));
 	}
 
 	int PointerCollection::Set(Pointer::PointerTypes Type) {
 		if(Type==Pointer::None)
 			return Set(BasePointer);
-		this->ResetIteration();
-		Pointer *pointer;
-		while(pointer=this->next()) {
+		for(Collection<Pointer,10>::Iterator pointer=this->First();pointer.isValid();pointer.Next()) {
 			if(pointer->Type==Type)
 				return Set(pointer);
 		}
@@ -107,7 +106,7 @@
 	}
 
 	void PointerCollection::Reset(int StackNo) {
-		ActivePointers.Remove(reinterpret_cast<utils::LinkedListItem<Pointer>*>(StackNo));
+		ActivePointers.Remove(*reinterpret_cast<utils::SortedCollection<Pointer>::Wrapper*>(StackNo));
 	}
 
 	void PointerCollection::ChangeBase(Pointer *Pointer) {
--- a/Engine/Pointer.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/Pointer.h	Mon Jul 18 22:25:11 2011 +0000
@@ -1,7 +1,7 @@
 #pragma once
 
-#include "../Utils/GGE.h"
-#include "../Utils/LinkedList.h"
+#include "GGE.h"
+#include "../Utils/SortedCollection.h"
 #include "Graphics.h"
 
 namespace gge {
@@ -34,7 +34,7 @@
 		////The image of the pointer
 		graphics::Buffered2DGraphic *Image;
 		////Point of click
-		Point Hotspot;
+		utils::Point Hotspot;
 		////Type of the pointer
 		PointerTypes Type;
 
@@ -47,7 +47,7 @@
 		}
 
 		////Initializes a pointer
-		Pointer(graphics::Buffered2DGraphic &pointer, Point Hotspot, PointerTypes Type) {
+		Pointer(graphics::Buffered2DGraphic &pointer, utils::Point Hotspot, PointerTypes Type) {
 			this->Image=&pointer;
 			this->Hotspot=Hotspot;
 			this->Type=Type;
@@ -57,8 +57,11 @@
 
 	class PointerCollection : public utils::Collection<Pointer, 10> {
 	public:
+
+		typedef int Token;
+
 		////Initializes Pointer Subsystem
-		void Initialize(GGEMain &Main);
+		void Initialize(GGEMain &Main, int LayerOrder=-100);
 		////Fetches list of pointers from a given folder resource. The given folder shall contain
 		/// a data file as the first item containing two entries per pointer. First entry must be
 		/// the Type(integer) ranging 0-6, second is Hotspot(point). Every pointer should be either
@@ -66,9 +69,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, Point Hotspot=Point(2,2), Pointer::PointerTypes Type=Pointer::None);
+		Pointer *Add(graphics::Buffered2DGraphic *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, Point Hotspot=Point(2,2), Pointer::PointerTypes Type=Pointer::None) {
+		Pointer &Add(graphics::Buffered2DGraphic &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
@@ -95,7 +98,7 @@
 		PointerCollection() : PointerLayer(NULL), BasePointer(NULL), PointerVisible(false), OSPointerVisible(true) { }
 
 	protected:
-		utils::LinkedList<Pointer> ActivePointers;
+		utils::SortedCollection<Pointer> ActivePointers;
 		graphics::Basic2DLayer *PointerLayer;
 		Pointer *BasePointer;
 		bool PointerVisible;
--- a/Engine/Sound.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/Sound.h	Mon Jul 18 22:25:11 2011 +0000
@@ -1,6 +1,6 @@
 #pragma once
 
-#include "../Utils/GGE.h"
+#include "GGE.h"
 #include "../External/OpenAL/alc.h"
 #include "../External/OpenAL/al.h"
 #include "OS.h"
--- a/Engine/Wave.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Engine/Wave.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -1,5 +1,7 @@
 #include "Wave.h"
 
+using namespace gge::utils;
+
 namespace gge { namespace sound {
 
 	namespace system {
@@ -10,14 +12,10 @@
 		}
 
 		void CollectWaveGarbage() {
-			Waves.ResetIteration();
-			Wave *wave;
-
-			while(wave=Waves.next()) {
+			for(Collection<Wave>::Iterator wave=Waves.First();wave.isValid();wave.Next()) {
 				if(!wave->isPlaying()) {
 					if(wave->AutoDestruct) {
-						Waves.Remove(wave);
-						delete wave;
+						wave.Delete();
 					} else {
 						if(wave->finished) wave->finished(*wave);
 					}
--- a/Resource/AnimationResource.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Resource/AnimationResource.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -53,7 +53,7 @@
 		int h=this->Height(H);
 		int w=this->Width(W);
 
-		if(Align & ALIGN_CENTER)
+		if(Align & Alignment::Center)
 			X+=(W-w)/2;
 		else if(Align & ALIGN_RIGHT)
 			X+= W-w;
--- a/Resource/AnimationResource.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Resource/AnimationResource.h	Mon Jul 18 22:25:11 2011 +0000
@@ -92,8 +92,8 @@
 		virtual int  Height(int H=-1);
 
 	public:
-		virtual void DrawResized(graphics::I2DGraphicsTarget *Target, int X, int Y, int W, int H, Alignment Align=ALIGN_MIDDLE_CENTER);
-		virtual void DrawResized(graphics::I2DGraphicsTarget &Target, int X, int Y, int W, int H, Alignment Align=ALIGN_MIDDLE_CENTER) { DrawResized(&Target, X,Y ,W,H, Align); }
+		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;
@@ -116,7 +116,7 @@
 		friend class ImageAnimation;
 	public:
 		////03010000h (Gaming, Animation)
-		virtual int getGID() { return GID_ANIMATION; }
+		virtual int getGID() { return GID::Animation; }
 		////Currently does nothing
 		virtual bool Save(File *File, FILE *Data) { return false; }
 		
@@ -124,14 +124,14 @@
 		AnimationResource() : ResourceBase() { Durations=NULL; FrameCount=0; }
 
 		////Returns the width of the first image
-		int getWidth() { if(Subitems.getCount()>0) return ((ImageResource*)Subitems[0])->getWidth(); return 0; }
+		int getWidth() { if(Subitems.GetSize()>0) return dynamic_cast<ImageResource&>(Subitems[0]).getWidth(); return 0; }
 		////Returns the height of the first image
-		int getHeight() { if(Subitems.getCount()>0) return ((ImageResource*)Subitems[0])->getHeight(); return 0; }
+		int getHeight() { if(Subitems.GetSize()>0) return dynamic_cast<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()) {
+			if(Subitems.GetSize()) {
 				ImageAnimation *ret=new ImageAnimation(this); 
 				return ret;
 			} else
--- a/Resource/BitmapFontResource.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Resource/BitmapFontResource.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -80,7 +80,7 @@
 			Print(target,x+Shadow.Offset.x,y+Shadow.Offset.y,w,text,Shadow.Color,align);
 
 		if(w==0) {
-			/*align=TEXTALIGN_LEFT;
+			/*align=TextAlignment::Left;
 			w=10000;*/
 			wrap=false;
 		}
@@ -117,7 +117,7 @@
 
 			if(nextline) {
 				switch(align) {
-				case TEXTALIGN_LEFT:
+				case TextAlignment::Left:
 					l=x;
 					break;
 				case TEXTALIGN_CENTER:
@@ -219,7 +219,7 @@
 			nowrap=true;
 
 		switch(Align) {
-		case TEXTALIGN_LEFT:
+		case TextAlignment::Left:
 			l=x;
 			break;
 		case TEXTALIGN_CENTER:
@@ -271,7 +271,7 @@
 
 			if(nextline) {
 				switch(Align) {
-				case TEXTALIGN_LEFT:
+				case TextAlignment::Left:
 					l=x;
 					break;
 				case TEXTALIGN_CENTER:
@@ -426,7 +426,7 @@
 			nowrap=true;
 
 		switch(Align) {
-		case TEXTALIGN_LEFT:
+		case TextAlignment::Left:
 			l=x;
 			break;
 		case TEXTALIGN_CENTER:
@@ -478,7 +478,7 @@
 
 			if(nextline) {
 				switch(Align) {
-				case TEXTALIGN_LEFT:
+				case TextAlignment::Left:
 					l=x;
 					break;
 				case TEXTALIGN_CENTER:
--- a/Resource/BitmapFontResource.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Resource/BitmapFontResource.h	Mon Jul 18 22:25:11 2011 +0000
@@ -24,7 +24,7 @@
 		////Size of the tabs in spaces, default is 4
 		int Tabsize;
 		////03020000h (Game, Bitmap font)
-		virtual int getGID() { return GID_FONT; }
+		virtual int getGID() { return GID::Font; }
 		////Currently does nothing
 		virtual bool Save(File *File, FILE *Data) { return false; }
 
@@ -45,9 +45,9 @@
 		////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());
 		////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 Align=TEXTALIGN_LEFT, ShadowParams Shadow=ShadowParams());
+		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());
 		////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 Align=TEXTALIGN_LEFT, ShadowParams Shadow=ShadowParams());
+		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());
 		////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 Align);
@@ -56,9 +56,9 @@
 
 		void Print(graphics::I2DColorizableGraphicsTarget &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 Align=TEXTALIGN_LEFT, ShadowParams Shadow=ShadowParams()) 
+		void Print(graphics::I2DColorizableGraphicsTarget &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 Align=TEXTALIGN_LEFT, ShadowParams Shadow=ShadowParams())
+		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())
 		{ Print(&target, X, Y, W, Text, Color, Data, DataLen, Align, Shadow); }
 
 		////Returns the height of this font, all characters have same height
--- a/Resource/DataResource.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Resource/DataResource.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -10,45 +10,45 @@
 		while(ftell(Data)<tpos) {
 			int gid,size,tmpint;
 			float tmpfloat;
-			Point tmppoint;
-			gge::Rectangle tmprect;
+			utils::Point tmppoint;
+			utils::Rectangle tmprect;
 			utils::SGuid tmpguid;
 
 			char *tmpstr;
 			fread(&gid,1,4,Data);
 			fread(&size,1,4,Data);
 
-			if(gid==GID_DATAARRAY_TEXT) {
+			if(gid==GID::Data_Text) {
 				tmpstr=new char[size+1];
 				fread(tmpstr,size,1,Data);
 				tmpstr[size]=0;
 
 				dat->Add(tmpstr);
 			}
-			else if(gid==GID_GUID) {
+			else if(gid==GID::SGuid) {
 				dat->guid.Load(Data);
 			}
-			else if(gid==GID_DATAARRAY_INT) {
+			else if(gid==GID::Data_Int) {
 				fread(&tmpint,1,4,Data);
 
 				dat->Add(tmpint);
 			}
-			else if(gid==GID_DATAARRAY_FLOAT) {
+			else if(gid==GID::Data_Float) {
 				fread(&tmpfloat,1,4,Data);
 
 				dat->Add(tmpfloat);
 			}
-			else if(gid==GID_DATAARRAY_POINT) {
-				fread(&tmppoint,1,8,Data);
+			else if(gid==GID::Data_Point) {
+				fread(&tmppoint,4,2,Data);
 
 				dat->Add(tmppoint);
 			}
-			else if(gid==GID_DATAARRAY_RECT) {
-				fread(&tmprect,1,16,Data);
+			else if(gid==GID::Data_Rect) {
+				fread(&tmprect,4,4,Data);
 
 				dat->Add(tmprect);
 			}
-			else if(gid==GID_DATAARRAY_LINK) {
+			else if(gid==GID::Data_Link) {
 				tmpguid.Load(Data);
 
 				dat->Add(tmpguid);
@@ -62,7 +62,7 @@
 
 				dat->Add(f);
 			}
-			else //should query for pluginable data items
+			else ///!TODO: should query for pluggable data items
 				EatChunk(Data,size);
 		}
 
@@ -74,4 +74,61 @@
 		value=File->Root().FindObject(guid);
 	}
 
+
+	IntegerData		& DataResource::Add( int value ) {
+		IntegerData &o=*new IntegerData(value);
+		Data.Add(o);
+
+		return o;
+	}
+
+	FloatData		& DataResource::Add( float value ) {
+		FloatData &o=*new FloatData(value);
+		Data.Add(o);
+
+		return o;
+	}
+
+	StringData		& DataResource::Add( string value ) {
+		StringData &o=*new StringData(value);
+		Data.Add(o);
+
+		return o;
+	}
+
+	PointData		& DataResource::Add( utils::Point value ) {
+		PointData &o=*new PointData(value);
+		Data.Add(o);
+
+		return o;
+	}
+
+	RectangleData	& DataResource::Add( utils::Rectangle value ) {
+		RectangleData &o=*new RectangleData(value);
+		Data.Add(o);
+
+		return o;
+	}
+
+	FontData		& DataResource::Add( Font value ) {
+		FontData &o=*new FontData(value);
+		Data.Add(o);
+
+		return o;
+	}
+
+	FontData		& DataResource::Add( FontInitiator value ) {
+		FontData &o=*new FontData(value);
+		Data.Add(o);
+
+		return o;
+	}
+
+	LinkData		& DataResource::Add( utils::SGuid value ) {
+		LinkData &o=*new LinkData(value);
+		Data.Add(o);
+
+		return o;
+	}
+
 } }
--- a/Resource/DataResource.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Resource/DataResource.h	Mon Jul 18 22:25:11 2011 +0000
@@ -18,11 +18,11 @@
 	enum DataTypes {
 		////4 byte Integer data
 		DT_Integer,
-		////Floating point (4 byte)
+		////Floating utils::Point (4 byte)
 		DT_Float,
 		////String data
 		DT_String,
-		////4 byte integer point data
+		////4 byte integer utils::Point data
 		DT_Point,
 		////4 byte integer rectangle data
 		DT_Rectangle,
@@ -43,7 +43,7 @@
 	class IntegerData : public IData {
 	public:
 		////02030C02h (Basic, Data resource, Data types, integer)
-		virtual int getGID() { return GID_DATAARRAY_INT; }
+		virtual int getGID() const { return GID::Data_Int; }
 		int value;
 
 		IntegerData(int value) { this->value=value; }
@@ -54,7 +54,7 @@
 	class FloatData : public IData {
 	public:
 		////02030C03h (Basic, Data resource, Data types, float)
-		virtual int getGID() { return GID_DATAARRAY_FLOAT; }
+		virtual int getGID() const { return GID::Data_Float; }
 		float value;
 
 		FloatData(float value) { this->value=value; }
@@ -65,7 +65,7 @@
 	class StringData : public IData {
 	public:
 		////02030C01h (Basic, Data resource, Data types, text)
-		virtual int getGID() { return GID_DATAARRAY_TEXT; }
+		virtual int getGID() const { return GID::Data_Text; }
 		string value;
 
 		StringData(string value) { this->value=value; }
@@ -73,40 +73,37 @@
 		operator const char *() { return value.c_str(); }
 	};
 
-	////Point data
+	////utils::Point data
 	class PointData : public IData {
 	public:
-		////02030C04h (Basic, Data resource, Data types, point)
-		virtual int getGID() { return GID_DATAARRAY_POINT; }
-		Point value;
+		////02030C04h (Basic, Data resource, Data types, utils::Point)
+		virtual int getGID() const { return GID::Data_Point; }
+		utils::Point value;
 
-		PointData(Point value) { this->value=value; }
+		PointData(utils::Point value) { this->value=value; }
 
-		operator Point() { return value; }
-		operator Size2D() { return value; }
+		operator utils::Point() { return value; }
+		operator utils::Size() { return value; }
 	};
 
 	////Rectangle data
 	class RectangleData : public IData {
 	public:
 		////02030C05h (Basic, Data resource, Data types, rectangle)
-		virtual int getGID() { return GID_DATAARRAY_RECT; }
-		gge::Rectangle value;
+		virtual int getGID() const { return GID::Data_Rect; }
+		utils::Rectangle value;
 
-		RectangleData(gge::Rectangle value)	{ this->value=value; }
-		RectangleData(Bounds value)		{ this->value=value; }
+		RectangleData(utils::Rectangle value)	{ this->value=value; }
 
-		Bounds getBounds() { return (Bounds)value; }
-		operator Bounds() { return (Bounds)value; }
-		operator Rectangle() { return value; }
-		operator Margins() { return Margins(value.Left,value.Top,value.Width,value.Height); }
+		operator utils::Rectangle() { return value; }
+		operator utils::Margins() { return utils::Margins(value.Left,value.Top,value.Width,value.Height); }
 	};
 
 	////Link data
 	class LinkData : public IData {
 	public:
 		////02030C02h (Basic, Data resource, Data types, integer)
-		virtual int getGID() { return GID_DATAARRAY_LINK; }
+		virtual int getGID() const { return GID::Data_Link; }
 		int getObjectGID() { if(value) return value->getGID(); return 0; }
 		ResourceBase *value;
 		utils::SGuid guid;
@@ -123,7 +120,7 @@
 	class FontData : public IData {
 	public:
 		////03300C01h (Gaming, FontTheme, Data types, font)
-		virtual int getGID() { return 0x03300C01; }
+		virtual int getGID() const { return 0x03300C01; }
 		Font value;
 		FontInitiator initiator;
 
@@ -136,7 +133,7 @@
 	};
 
 	////This is data resource which holds an array of basic data types. These types are
-	/// integer, float, string, point and rectangle.
+	/// integer, float, string, utils::Point and rectangle.
 	class DataResource : public ResourceBase {
 		friend ResourceBase *LoadDataResource(File* File, FILE* Data, int Size);
 	public:
@@ -144,59 +141,60 @@
 		utils::Collection<IData> Data;
 
 		////Adds a new integer value to this resource
-		IntegerData *Add(int value) { return dynamic_cast<IntegerData*>(Data[Data.Add(new IntegerData(value))]); }
+		IntegerData		&Add(int value);
 		////Adds a new float value to this resource
-		FloatData   *Add(float value) { return dynamic_cast<FloatData*>(Data[Data.Add(new FloatData(value))]); }
+		FloatData		&Add(float value);
 		////Adds a new string value to this resource
-		StringData  *Add(string value) { return dynamic_cast<StringData*>(Data[Data.Add(new StringData(value))]); }
-		////Adds a new point value to this resource
-		PointData  *Add(Point value) { return dynamic_cast<PointData*>(Data[Data.Add(new PointData(value))]); }
+		StringData		&Add(string value);
+		////Adds a new utils::Point value to this resource
+		PointData		&Add(utils::Point value);
 		////Adds a new rectangle to this resource
-		RectangleData  *Add(gge::Rectangle value) { return dynamic_cast<RectangleData*>(Data[Data.Add(new RectangleData(value))]); }
+		RectangleData	&Add(utils::Rectangle value);
 		////Adds a new rectangle to this resource
-		RectangleData  *Add(Bounds value) { return dynamic_cast<RectangleData*>(Data[Data.Add(new RectangleData(value))]); }
+		FontData		&Add(Font value);
 		////Adds a new rectangle to this resource
-		FontData	   *Add(Font value) { return dynamic_cast<FontData*>(Data[Data.Add(new FontData(value))]); }
-		////Adds a new rectangle to this resource
-		FontData	   *Add(FontInitiator value) { return dynamic_cast<FontData*>(Data[Data.Add(new FontData(value))]); }
+		FontData		&Add(FontInitiator value);
 		////Adds a new integer value to this resource
-		LinkData *Add(utils::SGuid value) { return dynamic_cast<LinkData*>(Data[Data.Add(new LinkData(value))]); }
+		LinkData		&Add(utils::SGuid value);
 
 		////Returns item at index
-		IData *operator [] (int Index) { return Data[Index]; }
+		IData *operator [] (int Index) { return &Data[Index]; }
 		////Returns integer at index
-		int getInt(int Index) { return dynamic_cast<IntegerData*>(Data[Index])->value; }
+		int getInt(int Index) { return dynamic_cast<IntegerData&>(Data[Index]).value; }
 		////Returns float at index
-		float getFloat(int Index) { return dynamic_cast<FloatData*>(Data[Index])->value; }
+		float getFloat(int Index) { return dynamic_cast<FloatData&>(Data[Index]).value; }
 		////Returns string at index
-		string getString(int Index) { return dynamic_cast<StringData*>(Data[Index])->value; }
+		string getString(int Index) { return dynamic_cast<StringData&>(Data[Index]).value; }
 		////Returns char array at index
-		const char *getText(int Index) { return dynamic_cast<StringData*>(Data[Index])->value.data(); }
-		////Returns point at index
-		Point getPoint(int Index) { return dynamic_cast<PointData*>(Data[Index])->value; }
+		const char *getText(int Index) { return dynamic_cast<StringData&>(Data[Index]).value.data(); }
+		////Returns utils::Point at index
+		utils::Point getPoint(int Index) { return dynamic_cast<PointData&>(Data[Index]).value; }
 		////Returns size at index
-		Size2D getSize2D(int Index) { return dynamic_cast<PointData*>(Data[Index])->value; }
+		utils::Size getSize(int Index) { return dynamic_cast<PointData&>(Data[Index]).value; }
 		////Returns rectangle at index
-		gge::Rectangle getRectangle(int Index) { return dynamic_cast<RectangleData*>(Data[Index])->value; }
-		////Returns margins at index
-		gge::Margins getMargins(int Index) { return *dynamic_cast<RectangleData*>(Data[Index]); }
-		////Returns bounds at index
-		Bounds getBounds(int Index) { return dynamic_cast<RectangleData*>(Data[Index])->getBounds(); }
+		utils::Rectangle getRectangle(int Index) { return dynamic_cast<RectangleData&>(Data[Index]).value; }
+		////Returns utils::Margins at index
+		utils::Margins getMargins(int Index) { return dynamic_cast<RectangleData&>(Data[Index]); }
+		////Returns utils::Bounds at index
+		utils::Bounds getBounds(int Index) { return dynamic_cast<RectangleData&>(Data[Index]).value; }
 		////Returns resource object from a link
-		ResourceBase &getLink(int Index) { return dynamic_cast<LinkData*>(Data[Index])->Get(); }
+		ResourceBase &getLink(int Index) { return dynamic_cast<LinkData&>(Data[Index]).Get(); }
 		////Returns font object
-		Font getFont(int Index) { return dynamic_cast<FontData*>(Data[Index])->value; }
+		Font getFont(int Index) { return dynamic_cast<FontData&>(Data[Index]).value; }
 		////Returns number of items in the array
 		int getCount() { return Data.getCount(); }
 		
 		////02030000h (Basic, Data resource)
-		virtual int getGID() { return GID_DATAARRAY; }
+		virtual int getGID() const { return GID::Data; }
 		////Currently does nothing
 		virtual bool Save(File *File, FILE *Data) { return false; }
 
 		virtual ~DataResource() { Data.Destroy(); ResourceBase::~ResourceBase(); }
 
-		virtual void Prepare(GGEMain *main) { foreach(IData, data, Data) data->Prepare(file); }
+		virtual void Prepare(GGEMain *main) { 
+			for(utils::Collection<IData>::Iterator i=Data.First();i.isValid();i.Next()) 
+				i->Prepare(file); 
+		}
 
 	protected:
 		File *file;
--- a/Resource/FolderResource.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Resource/FolderResource.h	Mon Jul 18 22:25:11 2011 +0000
@@ -25,20 +25,20 @@
 		int EntryPoint;
 
 		////01010000h, (System, Folder)
-		virtual int getGID() { return GID_FOLDER; }
+		virtual int getGID() { return GID::Folder; }
 		////Currently does nothing
 		virtual bool Save(File *File, FILE *Data) { return false; }
 
 		////Returns the number of items contained
-		int			 getCount() { return Subitems.getCount(); }
+		int			 getCount() { return Subitems.GetSize(); }
 		////Returns an item with the given index
-		ResourceBase	*getItem (int Index) { return Subitems[Index]; }
+		ResourceBase	*getItem (int Index) { return &Subitems[Index]; }
 		////Returns an item with the given index
-		ResourceBase	&operator [] (int Index) { return *(Subitems[Index]); }
+		ResourceBase	&operator [] (int Index) { return (Subitems[Index]); }
 		////Adds a new resource to this folder
-		void	Add(ResourceBase *resource) { Subitems.AddItem(resource); }
+		void	Add(ResourceBase *resource) { Subitems.Add(resource); }
 		////Adds a new resource to this folder
-		FolderResource	&operator << (ResourceBase &resource) { Subitems.AddItem(&resource); return *this; }
+		FolderResource	&operator << (ResourceBase &resource) { Subitems.Add(resource); return *this; }
 
 		////Returns the given subitem with folder resource type. Used to avoid type casting
 		FolderResource	*asFolder	(int Index);
--- a/Resource/GRE.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Resource/GRE.h	Mon Jul 18 22:25:11 2011 +0000
@@ -1,7 +1,6 @@
 #pragma once
 
-#include "../Utils/GGE.h"
-#include "../Utils/Utils.h"
+#include "../Engine/GGE.h"
 #include "../Utils/SGuid.h"
 #include <string>
 #ifdef _DEBUG
--- a/Resource/ImageResource.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Resource/ImageResource.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -419,7 +419,7 @@
 		int h=this->Height(H);
 		int w=this->Width(W);
 
-		if(Align & ALIGN_CENTER)
+		if(Align & Alignment::Center)
 			X+=(W-w)/2;
 		else if(Align & ALIGN_RIGHT)
 			X+= W-w;
--- a/Resource/ImageResource.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Resource/ImageResource.h	Mon Jul 18 22:25:11 2011 +0000
@@ -62,7 +62,7 @@
 		bool PNGExport(string filename);
 		
 		////02020000h (Basic, Image)
-		virtual int getGID() { return GID_IMAGE; }
+		virtual int getGID() { return GID::Image; }
 		////Currently does nothing
 		virtual bool Save(File *File, FILE *Data) { return false; }
 		////Loads image data from the file. This function is required for late
@@ -83,7 +83,7 @@
 
 
 		////Destroys used data
-		void destroy() { Data--; if(Palette) delete Palette; }
+		void destroy() { Data.RemoveReference(); if(Palette) delete Palette; }
 
 		////Destroys used data
 		virtual ~ImageResource() { if(Palette) delete Palette; }
@@ -100,8 +100,8 @@
 			this->VerticalTiling=Vertical;
 		}
 
-		virtual void DrawResized(graphics::I2DGraphicsTarget *Target, int X, int Y, int W, int H, Alignment Align=ALIGN_MIDDLE_CENTER);
-		virtual void DrawResized(graphics::I2DGraphicsTarget &Target, int X, int Y, int W, int H, Alignment Align=ALIGN_MIDDLE_CENTER) {
+		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) { 
--- a/Resource/ResizableObject.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Resource/ResizableObject.h	Mon Jul 18 22:25:11 2011 +0000
@@ -1,8 +1,7 @@
 #pragma once
 
 #include "../Utils/Margins.h"
-#include "../Utils/GGE.h"
-#include "../Utils/Utils.h"
+#include "../Utils/BasicMath.h"
 #include "../Engine/Graphics.h"
 #include "../Resource/ResourceBase.h"
 
@@ -49,11 +48,11 @@
 				if(Type==Integral) {
 					switch(CalculationMethod) {
 						case SmallerThanGivenSize:
-							return (int)gge::Max(floor((float)Requested/Original), 1)*Original;
+							return (int)utils::Max(floor((float)Requested/Original), 1)*Original;
 						case ClosestToGivenSize:
-							return (int)gge::Max(gge::Round((float)Requested/Original), 1)*Original;
+							return (int)utils::Max(utils::Round((float)Requested/Original), 1)*Original;
 						case FillTheGivenSize:
-							return (int)gge::Max(ceil((float)Requested/Original), 1)*Original;
+							return (int)utils::Max(ceil((float)Requested/Original), 1)*Original;
 					}
 				}
 
@@ -94,11 +93,11 @@
 				}
 
 				if(CalculationMethod==SmallerThanGivenSize)
-					return (int)gge::Max(floor( ((float)(w-Overhead)) / Increment ), 0)  * Increment + Overhead;
+					return (int)utils::Max(floor( ((float)(w-Overhead)) / Increment ), 0)  * Increment + Overhead;
 				else if(CalculationMethod==ClosestToGivenSize)
-					return (int)gge::Max(gge::Round( ((float)(w-Overhead)) / Increment ), 0)  * Increment + Overhead;
+					return (int)utils::Max(utils::Round( ((float)(w-Overhead)) / Increment ), 0)  * Increment + Overhead;
 				else
-					return (int)gge::Max(ceil( ((float)(w-Overhead)) / Increment ), 0)  * Increment + Overhead;
+					return (int)utils::Max(ceil( ((float)(w-Overhead)) / Increment ), 0)  * Increment + Overhead;
 			}
 		};
 
@@ -144,10 +143,10 @@
 			return is;
 		}
 
-		virtual void DrawResized(gge::graphics::I2DGraphicsTarget *Target, int X, int Y, int W, int H, gge::Alignment Align=ALIGN_CENTER) =0;
-		virtual void DrawResized(gge::graphics::I2DGraphicsTarget &Target, int X, int Y, int W, int H, gge::Alignment Align=ALIGN_CENTER) { DrawResized(&Target, X, Y, W, H, Align); }
-		virtual void DrawResized(gge::graphics::I2DGraphicsTarget *Target, int X=0, int Y=0, gge::Alignment Align=ALIGN_CENTER) { DrawResized(Target, X, Y, Target->Width(), Target->Height(), Align); }
-		virtual void DrawResized(gge::graphics::I2DGraphicsTarget &Target, int X=0, int Y=0, gge::Alignment Align=ALIGN_CENTER) { DrawResized(&Target, X, Y, Target.Width(), Target.Height(), Align); }
+		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) {}
@@ -156,7 +155,7 @@
 		virtual void Pause() {}
 		virtual void setLoop(bool Loop) {}
 		virtual int  getDuration() { return 0; }
-		virtual gge::Margins getBorderWidth() { return gge::Margins(0); }
+		virtual utils::Margins getBorderWidth() { return utils::Margins(0); }
 
 		virtual ~ResizableObject() {}
 	};
--- a/Resource/ResourceBase.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Resource/ResourceBase.h	Mon Jul 18 22:25:11 2011 +0000
@@ -30,7 +30,7 @@
 		virtual bool Save(File *File, FILE *Data)=0;
 
 		////This function tests whether this object has the given utils::SGuid
-		bool isEqual(utils::SGuid guid) const { return guid==this->guid; }
+		bool isEqual(const utils::SGuid &guid) const { return guid==this->guid; }
 
 		////utils::SGuid to identify this resource object
 		utils::SGuid guid;
@@ -41,7 +41,7 @@
 
 		////Subitems that this resource object have. Some of the sub items
 		/// can be hidden therefore, this is not guaranteed to be complete
-		utils::LinkedList<ResourceBase> Subitems;
+		utils::SortedCollection<ResourceBase> Subitems;
 
 		////Searches the public children of this resource object
 		virtual ResourceBase *FindObject(utils::SGuid guid) const;
--- a/Resource/ResourceFile.cpp	Sat Jul 16 06:43:45 2011 +0000
+++ b/Resource/ResourceFile.cpp	Mon Jul 18 22:25:11 2011 +0000
@@ -11,41 +11,33 @@
 
 namespace gge { namespace resource {
 
-	bool File::LoadFile(string filename) {
+	bool File::LoadFile(const string &Filename) {
 		char sgn[7];
 
-		ErrorText=NULL;
-		ErrorNo=0;
-		Filename=filename;
+		this->Filename=Filename;
 
-		///*Check file existance
+		///*Check file existence
 		FILE *data;
 		errno_t err;
-		err=fopen_s(&data, filename.data(), "rb");
+		err=fopen_s(&data, Filename.data(), "rb");
 		if(data==NULL) {
-			ErrorText=ERT_FILENOTFOUND;
-			ErrorNo  =ERR_FILENOTFOUND;
-			return false;
+			throw load_error(load_error::FileNotFound, load_error::strings::FileNotFound);
 		}
 
 
 		fread(sgn,6,1,data);
 		sgn[6]=0;
-		///*Check file signiture
+		///*Check file signature
 		if(strcmp(sgn,"GORGON")!=0) {
-			ErrorText=ERT_SIGNITURE;
-			ErrorNo  =ERR_SIGNITURE;
 			fclose(data);
-			return false;
+			throw load_error(load_error::Signature, load_error::strings::Signature);
 		}
 
 		///*Check file version
 		fread(&FileVersion,1,4,data);
-		if(FileVersion>CURVERSION) {
-			ErrorText=ERT_VERSION;
-			ErrorNo  =ERR_SIGNITURE;
+		if(FileVersion>CurrentVersion) {
 			fclose(data);
-			return false;
+			throw load_error(load_error::VersionMismatch, load_error::strings::VersionMismatch);
 		}
 
 		///*Load file type
@@ -54,11 +46,9 @@
 		///*Check first element
 		int tmpint;
 		fread(&tmpint,1,4,data);
-		if(tmpint!=GID_FOLDER) {
-			ErrorText=ERT_CONTAINMENT;
-			ErrorNo  =ERR_CONTAINMENT;
+		if(tmpint!=GID::Folder) {
 			fclose(data);
-			return false;
+			throw load_error(load_error::Containment, load_error::strings::Containment);
 		}
 
 		int size;
@@ -109,4 +99,10 @@
 		Loaders.Add(new ResourceLoader(GID_FONTTHEME, LoadFontTheme)); 
 		Loaders.Add(new ResourceLoader(GID_FONTTHEME, LoadFontTheme)); 
 	}
+
+	const string load_error::strings::FileNotFound		= "Cannot find the file specified";
+	const string load_error::strings::Signature			= "Signature mismatch";
+	const string load_error::strings::VersionMismatch	= "Version mismatch";
+	const string load_error::strings::Containment		= "The supplied file is does not contain any data or its representation is invalid.";
+
 } }
--- a/Resource/ResourceFile.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Resource/ResourceFile.h	Mon Jul 18 22:25:11 2011 +0000
@@ -50,10 +50,10 @@
 
 		class strings {
 		public:
-			static const string FileNotFound	= "Cannot find the file specified";
-			static const string Signature		= "Signature mismatch";
-			static const string VersionMismatch	= "Version mismatch";
-			static const string Containment		= "The supplied file is does not contain any data or its representation is invalid.";
+			static const string FileNotFound	;
+			static const string Signature		;
+			static const string VersionMismatch	;
+			static const string Containment		;
 		};
 
 
@@ -61,7 +61,7 @@
 
 		}
 
-		load_error(ErrorType number, const chqr *text) : runtime_error(text), number(number) {
+		load_error(ErrorType number, const char *text) : runtime_error(text), number(number) {
 
 		}
 
@@ -97,9 +97,9 @@
 			if(guid.isEmpty()) 
 				return NULL;
 
-			foreach(Redirect, redirect, Redirects) {
-				if(redirect->source==guid)
-					guid=redirect->target;
+			for(utils::Collection<Redirect>::Iterator i=Redirects.First();i.isValid();i.Next()) {
+				if(i->source==guid)
+					guid=i->target;
 			}
 			
 			return root->FindObject(guid); 
--- a/Utils/Bounds2D.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Utils/Bounds2D.h	Mon Jul 18 22:25:11 2011 +0000
@@ -88,6 +88,8 @@
 			if(Left>Right) std::swap(Left,Right);
 			if(Top>Bottom) std::swap(Top,Bottom);
 		}
+		template<class O_>
+		basic_Bounds2D(const basic_Bounds2D<O_> &r) : Left((T_)r.Left), Top((T_)r.Top), Right((T_)r.Right), Bottom((T_)r.Bottom) {}
 		basic_Bounds2D(const basic_Rectangle2D<T_> &bounds);
 
 		operator basic_Rectangle2D<T_>() const;
@@ -179,6 +181,14 @@
 			);
 		}
 
+		bool operator ==(const basic_Bounds2D &b) const {
+			return Left==b.Left && Top==b.Top && Right==b.Right && Bottom==b.Bottom;
+		}
+
+		bool operator !=(const basic_Bounds2D &b) const {
+			return Left!=b.Left || Top!=b.Top || Right!=b.Right || Bottom!=b.Bottom;
+		}
+
 		basic_Bounds2D operator +(const basic_Bounds2D &b) const {
 			return Union(b);
 		}
@@ -244,6 +254,30 @@
 		bool isInside(const basic_Point2D<T_> &p) const {
 			return p.x>Left && p.y>Top && p.x<Right && p.y<Bottom;
 		}
+
+		void SetSize(const basic_Size2D<T_> &s) {
+			Right = Left + s.Width;
+			Bottom= Top  + s.Height;
+		}
+
+		void SetSize(T_ Width, T_ Height) {
+			Right = Left + Width;
+			Bottom= Top  + Height;
+		}
+
+		void MoveTo(const basic_Point2D<T_> &p) {
+			Right = (Right-Left)+p.x	;
+			Bottom= (Bottom-Top)+p.y	;
+			Left  = p.x	;
+			Top   = p.y ;
+		}
+		
+		void MoveTo(T_ x, T_ y) {
+			Right = (Right-Left)+x	;
+			Bottom= (Bottom-Top)+y	;
+			Left  = x;
+			Top   = y;
+		}
 	};
 
 	////Allows streaming of bounds. in string representation, bounds is show as
@@ -298,7 +332,7 @@
 	{ }
 
 	template <class T_>
-	inline basic_Bounds2D<T_>::operator basic_Rectangle2D<T_>() {
+	inline basic_Bounds2D<T_>::operator basic_Rectangle2D<T_>() const {
 		return basic_Rectangle2D<T_>(*this);
 	}
 
--- a/Utils/ConsumableEvent.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Utils/ConsumableEvent.h	Mon Jul 18 22:25:11 2011 +0000
@@ -10,6 +10,7 @@
 //REQUIRES:
 //	gge::utils::SortedCollection
 //	gge::utils::Any
+//	std::unordered_map
 
 //LICENSE
 //	This program is free software: you can redistribute it and/or modify
@@ -46,6 +47,7 @@
 #include "Any.h"
 #include "SortedCollection.h"
 #include "EventChain.h"
+#include <unordered_map>
 
 
 
@@ -559,6 +561,10 @@
 	public:
 
 		typedef int Token;
+		static const Token NullToken = 0;
+
+		//To be used by owner
+		std::unordered_map<P_, Token> TokenList;
 
 		////Constructor
 		///@Name	: Name of the event
@@ -773,6 +779,7 @@
 		}
 
 		template<class R_>
+		
 		Token DoubleLink(ConsumableEvent<R_, P_> &target, int order) {
 			typedef bool(ConsumableEvent<O_,P_>::*MyFire	)(P_) ;
 			typedef bool(ConsumableEvent<R_,P_>::*TargetFire)(P_);
@@ -795,28 +802,6 @@
 
 		////Unregisters the given event handler using handler function
 		template<class F_>
-		void Unregister(F_ handler) {
-			for(SortedCollection<HANDLER_,int>::Iterator it=events.First(); it.isValid(); it.Next()) {
-				if(Compare(&(*it), handler)) {
-					it.Delete();
-					return;
-				}
-			}
-		}
-
-		////Unregisters the given handler referenced by the object and function
-		template<class R_, class F_>
-		void Unregister(R_ *obj, F_ handler) {
-			for(SortedCollection<HANDLER_,int>::Iterator it=events.First(); it.isValid(); it.Next()) {
-				if(Compare(&(*it),obj, handler)) {
-					it.Delete();
-					return;
-				}
-			}
-		}
-
-		////Unregisters the given event handler using handler function
-		template<class F_>
 		Token Find(F_ handler) {
 			for(SortedCollection<HANDLER_,int>::Iterator it=events.First(); it.isValid(); it.Next()) {
 				if(Compare(&(*it), handler)) {
@@ -837,6 +822,28 @@
 			}
 		}
 
+		////Unregisters the given event handler using handler function
+		template<class F_>
+		void Unregister(F_ handler) {
+			for(SortedCollection<HANDLER_,int>::Iterator it=events.First(); it.isValid(); it.Next()) {
+				if(Compare(&(*it), handler)) {
+					Unregister(reinterpret_cast<Token>(&it.GetWrapper()));
+					return;
+				}
+			}
+		}
+
+		////Unregisters the given handler referenced by the object and function
+		template<class R_, class F_>
+		void Unregister(R_ *obj, F_ handler) {
+			for(SortedCollection<HANDLER_,int>::Iterator it=events.First(); it.isValid(); it.Next()) {
+				if(Compare(&(*it),obj, handler)) {
+					Unregister(reinterpret_cast<Token>(&it.GetWrapper()));
+					return;
+				}
+			}
+		}
+
 		template<class R_, class F_>
 		void UnregisterClass(R_ &obj, F_ handler) {
 			Unregister(&obj, handler);
@@ -847,7 +854,7 @@
 		void UnregisterClass(R_ *obj, F_ handler) {
 			for(SortedCollection<HANDLER_,int>::Iterator it=events.First(); it.isValid(); it.Next()) {
 				if(Compare(&(*it), obj, handler)) {
-					it.Delete();
+					Unregister(reinterpret_cast<Token>(&it.GetWrapper()));
 					return;
 				}
 			}
@@ -861,7 +868,12 @@
 
 		////Unregisters a given handler token
 		void Unregister(Token token) {
-			reinterpret_cast< ITEMTYPE_* >(token).Delete();
+			for(std::map<P_, Token>::iterator i=TokenList.begin();i!=TokenList.end();++i) {
+				if(i->second==token)
+					i->second=NullToken;
+			}
+
+			reinterpret_cast< ITEMTYPE_* >(token)->Delete();
 		}
 
 		void MakeFirst(Token token) {
@@ -918,33 +930,44 @@
 			return item->Item->enabled;
 		}
 
+		bool Fire(Token token, P_ params) {
+			if(token==NullToken)
+				return false;
+
+			return reinterpret_cast< ITEMTYPE_* >(token)->Get().Fire(params, *this->object, eventname);
+		}
+
+		bool Fire(Token token) {
+			Fire(token, P_());
+		}
+
 		////This function triggers the event causing all 
 		/// handlers to be called
-		bool operator()(P_ params) {
+		Token operator()(P_ params) {
 			return Fire(params);
 		}
 
 		////This function triggers the event causing all 
 		/// handlers to be called
-		bool operator()() {
+		Token operator()() {
 			return Fire();
 		}
 
 		////This function triggers the event causing all 
 		/// handlers to be called
-		bool Fire(P_ params) {
+		Token Fire(P_ params) {
 			for(SortedCollection<HANDLER_, int>::Iterator it=events.First();it.isValid();it.Next()) {
 				if(it->enabled)
 					if(it->Fire(params, *this->object, eventname))
-						return true;
+						return reinterpret_cast<Token>(&it.GetWrapper());
 			}
 
-			return false;
+			return 0;
 		}
 
 		////This function triggers the event causing all 
 		/// handlers to be called
-		bool Fire() {
+		Token Fire() {
 			return Fire(P_());
 		}
 
@@ -974,12 +997,12 @@
 		Token AddHandler(HANDLER_ *object) {
 			ITEMTYPE_ *item = &events.Add(object);
 
-			return reinterpret_cast<int>(item);
+			return reinterpret_cast<Token>(item);
 		}
 		Token AddHandler(HANDLER_ *object, int order) {
 			ITEMTYPE_ *item = &events.Add(object, order);
 
-			return reinterpret_cast<int>(item);
+			return reinterpret_cast<Token>(item);
 		}
 
 
--- a/Utils/EventChain.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Utils/EventChain.h	Mon Jul 18 22:25:11 2011 +0000
@@ -820,12 +820,10 @@
 		}
 
 		void linkedfire(P_ params) {
-			events.ResetIteration(true);
-			prvt::eventchain::EventHandler<P_, O_> *object;
-
-			while(object=events.previous()) {
-				if(!checklinkedfire(object))
-					object->Fire(params, *this->object, eventname);
+			for(Collection<prvt::eventchain::EventHandler<P_, O_>, 5>::Iterator it = events.First();
+				it.isValid();it.Next()) {
+				if(!checklinkedfire(it.CurrentPtr()))
+					it->Fire(params, *this->object, eventname);
 			}
 		}
 
--- a/Utils/GGE.h	Sat Jul 16 06:43:45 2011 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,96 +0,0 @@
-//TO BE MOVED
-
-
-#pragma once
-
-#include "math.h"
-#include "memory.h"
-#include "Binary.h"
-#include "UtilsBase.h"
-
-
-typedef unsigned long       DWORD;
-typedef int                 BOOL;
-typedef unsigned short      WORD;
-
-
-#include "Point2D.h"
-#include "Bounds2D.h"
-#include "Rectangle2D.h"
-
-#pragma warning(disable:4355)
-
-
-////Gorgon Game Engine
-namespace gge {
-
-	class Alignment {
-	public:
-		enum Type {
-			Left	= B8(00001000),
-			Right	= B8(00010000),
-			Center	= B8(00100000),
-
-			Top		= B8(00000001),
-			Bottom	= B8(00000010),
-			Middle	= B8(00000100),
-
-			Top_Left		= Top	 | Left		,
-			Top_Center		= Top	 | Center	,
-			Top_Right		= Top	 | Right	,
-
-			Bottom_Left		= Bottom | Left		,
-			Bottom_Right	= Bottom | Right	,
-			Bottom_Center	= Bottom | Center	,
-
-			Middle_Left		= Middle | Left		,
-			Middle_Center	= Middle | Center	,
-			Middle_Right	= Middle | Right	,
-		};
-
-		const int Mask_Vertical	  = B8(00000111);
-		const int Mask_Horizontal = B8(00111000);
-		const int Mask_Used = B8(00111111);
-		const int Mask_Invalid = ~Mask_Used;
-
-		bool isLeft(Type t) {
-			return t&Mask_Horizontal == Left;
-		}
-
-		bool isRight(Type t) {
-			return t&Mask_Horizontal == Right;
-		}
-
-		bool isCenter(Type t) {
-			return t&Mask_Horizontal == Center;
-		}
-
-		bool isTop(Type t) {
-			return t&Mask_Vertical == Top;
-		}
-
-		bool isBottom(Type t) {
-			return t&Mask_Vertical == Bottom;
-		}
-
-		bool isMiddle(Type t) {
-			return t&Mask_Vertical == Middle;
-		}
-
-		bool isValid(Type t) {
-			if(t&Mask_Invalid)
-				return false;
-
-			int h=t&Mask_Horizontal;
-			if( !(h==Left || h==Right || h==Center) )
-				return false;
-
-			int v=t&Mask_Vertical;
-			if( !(v==Top || v==Bottom || v==Middle) )
-				return false;
-
-			return true;
-		}
-	}; 
-
-}
--- a/Utils/Iterator.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Utils/Iterator.h	Mon Jul 18 22:25:11 2011 +0000
@@ -81,6 +81,15 @@
 		T_ &Current() const {
 			return iterator().current();
 		}
+		////Returns current item
+		T_ *CurrentPtr() {
+			return &iterator().current();
+		}
+
+		////Returns current item
+		T_ *CurrentPtr() const {
+			return &iterator().current();
+		}
 
 		////Moves the iterator by the given amount
 		bool MoveBy(int amount) {
--- a/Utils/ManagedBuffer.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Utils/ManagedBuffer.h	Mon Jul 18 22:25:11 2011 +0000
@@ -53,7 +53,7 @@
 
 		ManagedBuffer &operator =(const ManagedBuffer &buf) {
 			if(this==&buf) return *this;
-			if(this->data==buf->data) return *this;
+			if(this->data==buf.data) return *this;
 
 			refassign(buf);
 
--- a/Utils/Margins.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Utils/Margins.h	Mon Jul 18 22:25:11 2011 +0000
@@ -49,7 +49,7 @@
 #define MARGINS2D_EXISTS
 
 
-namespace gge {
+namespace gge { namespace utils {
 	template <class T_>
 	class basic_Margins2D {
 	public:
@@ -161,4 +161,4 @@
 #endif
 
 	typedef basic_Margins2D<int> Margins;
-}
\ No newline at end of file
+} }
--- a/Utils/Point2D.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Utils/Point2D.h	Mon Jul 18 22:25:11 2011 +0000
@@ -53,7 +53,7 @@
 
 
 
-namespace gge {
+namespace gge { namespace utils {
 
 	template <class T_>
 	class basic_Point2D {
@@ -63,7 +63,7 @@
 		basic_Point2D() {}
 		basic_Point2D(T_ X, T_ Y) : x(X), y(Y) {  }
 		template <class U_>
-		basic_Point2D(const basic_Point2D<U_> &point) : x(point.x), y(point.y) { }
+		basic_Point2D(const basic_Point2D<U_> &point) : x((T_)point.x), y((T_)point.y) { }
 
 		template <class U_>
 		basic_Point2D& operator =(const basic_Point2D<U_> &point) { x=T_(point.x); y=T_(point.y); return *this; }
@@ -344,4 +344,4 @@
 
 	typedef basic_Point2D<int> Point;
 
-}
+} }
--- a/Utils/Rectangle2D.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Utils/Rectangle2D.h	Mon Jul 18 22:25:11 2011 +0000
@@ -74,9 +74,22 @@
 				Height=-Height;
 			}
 		}
-			
+
 		basic_Rectangle2D(const basic_Point2D<T_> &TopLeft, const basic_Size2D<T_> &HeightWidth) : 
-			Left(TopLeft.x), Top(TopLeft.y), Width(HeightWidth.Width), Height(HeightWidth.Height)
+		Left(TopLeft.x), Top(TopLeft.y), Width(HeightWidth.Width), Height(HeightWidth.Height)
+		{
+			if(Width<0) {
+				Left=Left+Width;
+				Width=-Width;
+			}
+			if(Height<0) {
+				Top=Top+Height;
+				Height=-Height;
+			}
+		}
+
+		basic_Rectangle2D(T_ Left, T_ Top, const basic_Size2D<T_> &HeightWidth) : 
+		Left(Left), Top(Top), Width(HeightWidth.Width), Height(HeightWidth.Height)
 		{
 			if(Width<0) {
 				Left=Left+Width;
@@ -144,8 +157,23 @@
 		////Calculates and returns the height of the region
 		T_ Bottom() const { return Height+Top;  }
 
-		void SetRight(T_ right) { Width=right-Left; }
-		void SetBottom(T_ bottom) { Height=bottom-Top; }
+		void SetRight(T_ right) { 
+			if(right>Left) 
+				Width=right-Left; 
+			else {
+				Width=Left-right;
+				Left=right;
+			}
+		}
+		void SetBottom(T_ bottom) {
+			if(bottom>Top) 
+				Height=bottom-Top; 
+			else {
+				Height=Top-bottom;
+				Top=bottom;
+			}
+		}
+
 		void SetSize(const basic_Size2D<T_> &s) { 
 			Width=s.Width;
 			Height=s.Height;
@@ -227,6 +255,14 @@
 			return basic_Point2D<T_>(Left+Width,Top+Height);
 		}
 
+		bool operator ==(const basic_Rectangle2D &r) const {
+			return Left==r.Left && Top==r.Top && Width==r.Width && Height==r.Height;
+		}
+
+		bool operator !=(const basic_Rectangle2D &r) const {
+			return Left!=r.Left || Top!=r.Top || Width!=r.Width || Height!=r.Height;
+		}
+
 		basic_Rectangle2D operator +(const basic_Point2D<T_> &amount) const {
 			return Translate(amount);
 		}
--- a/Utils/SortedCollection.h	Sat Jul 16 06:43:45 2011 +0000
+++ b/Utils/SortedCollection.h	Mon Jul 18 22:25:11 2011 +0000
@@ -51,7 +51,7 @@
 namespace gge { namespace utils {
 	//SortedCollection is a linked list and cannot
 	//employ object pools
-	template<class T_, class K_>
+	template<class T_, class K_=int>
 	class SortedCollection : RefCounter<SortedCollection<T_, K_> > {
 		friend class Iterator_;
 		friend class RefCounter<SortedCollection>;
@@ -101,6 +101,14 @@
 				return key;
 			}
 
+			T_ &Get() {
+				return *item;
+			}
+
+			T_ *GetPtr() {
+				return item;
+			}
+
 			void Reorder(const K_ &key) {
 				parent->Reorder(*this, key);
 			}
@@ -143,6 +151,13 @@
 			Iterator_(const Iterator_&it) : Current(it.Current) {
 			}
 
+			Wrapper &GetWrapper() {
+				if(!Current)
+					throw std::out_of_range("Current item does not exists");
+
+				return *Current;
+			}
+
 			void Reorder(const K_ &key)  {
 				if(Current) {
 					Current->parent->Reorder(*this, key);
@@ -179,7 +194,7 @@
 		protected:
 			O_& current() const {
 				if(!Current)
-					throw runtime_error("Invalid location");
+					throw std::runtime_error("Invalid location");
 				return *(Current->item);
 			}
 
@@ -567,6 +582,30 @@
 				Reorder(*item.Current, key);
 		}
 
+		void Remove(Iterator &item) {
+			if(item.Current==NULL)
+				return;
+
+			Wrapper &w=*item.Current;
+			item.Current=item.Current->next;
+
+			Remove(w);
+
+			return;
+		}
+
+		void Delete(Iterator &item) {
+			if(item.Current==NULL)
+				return;
+
+			Wrapper &w=*item.Current;
+			item.Current=item.Current->next;
+
+			Remove(w);
+
+			return;
+		}
+
 		void Remove(Wrapper &item) {
 			if(item.previous) {
 				item.previous->next=item.next;
@@ -597,7 +636,8 @@
 		}
 
 		void Remove(T_ *item) {
-			Remove(Find(item));
+			Iterator it=Find(item);
+			Remove(it);
 		}
 
 		void Delete(T_ *item) {
@@ -638,30 +678,6 @@
 			return *this;
 		}
 
-		void Remove(Iterator &item) {
-			if(item.Current==NULL)
-				return;
-
-			Wrapper &w=item.Current;
-			item.Current=item.Current->next;
-
-			Remove(w);
-
-			return;
-		}
-
-		void Delete(Iterator &item) {
-			if(item.Current==NULL)
-				return;
-
-			Wrapper &w=*item.Current;
-			item.Current=item.Current->next;
-
-			Remove(w);
-
-			return;
-		}
-
 		SortedCollection &operator -=(Iterator &item) {
 			return Remove(item);
 		}
@@ -758,7 +774,7 @@
 		}
 
 		T_ &Get(int Index) {
-			T_ *r=get_(Index);
+			T_ *r=get_(Index)->GetPtr();
 
 			if(r==NULL)
 				throw std::out_of_range("Index out of range");
@@ -816,7 +832,7 @@
 		}
 
 		Iterator Last() {
-			return Iterator(*tail, this, this);
+			return Iterator(*tail, this);
 		}
 
 		ConstIterator begin() const {

mercurial