* Moving to trunk step 2

Wed, 17 Nov 2010 07:48:28 +0000

author
cemkalyoncu
date
Wed, 17 Nov 2010 07:48:28 +0000
changeset 1
1ef17765f966
parent 0
8e51ab8b695e
child 2
7a6b515752f9

* Moving to trunk step 2

Effects/CountingText.cpp file | annotate | diff | comparison | revisions
Effects/CountingText.h file | annotate | diff | comparison | revisions
Effects/Flip.cpp file | annotate | diff | comparison | revisions
Effects/Flip.h file | annotate | diff | comparison | revisions
Effects/LayerMover.cpp file | annotate | diff | comparison | revisions
Effects/LayerMover.h file | annotate | diff | comparison | revisions
Effects/LayerResizer.cpp file | annotate | diff | comparison | revisions
Effects/LayerResizer.h file | annotate | diff | comparison | revisions
Effects/Tinting.cpp file | annotate | diff | comparison | revisions
Effects/Tinting.h file | annotate | diff | comparison | revisions
Engine/Animator.cpp file | annotate | diff | comparison | revisions
Engine/Animator.h file | annotate | diff | comparison | revisions
Engine/CustomLayer.cpp file | annotate | diff | comparison | revisions
Engine/CustomLayer.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.cpp file | annotate | diff | comparison | revisions
Engine/Multimedia.h 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/ResizableObject.h file | annotate | diff | comparison | revisions
Engine/Sound.cpp file | annotate | diff | comparison | revisions
Engine/Sound.h file | annotate | diff | comparison | revisions
Engine/Wave.cpp file | annotate | diff | comparison | revisions
Engine/Wave.h file | annotate | diff | comparison | revisions
Engine/Windows.cpp file | annotate | diff | comparison | revisions
External/AL/al.h file | annotate | diff | comparison | revisions
External/AL/alc.h file | annotate | diff | comparison | revisions
External/JPEG/README.libjpeg file | annotate | diff | comparison | revisions
External/JPEG/jconfig.h file | annotate | diff | comparison | revisions
External/JPEG/jerror.h file | annotate | diff | comparison | revisions
External/JPEG/jmorecfg.h file | annotate | diff | comparison | revisions
External/JPEG/jpeglib.h file | annotate | diff | comparison | revisions
External/JPEG/src/cderror.h file | annotate | diff | comparison | revisions
External/JPEG/src/cdjpeg.h file | annotate | diff | comparison | revisions
External/JPEG/src/jcapimin.c file | annotate | diff | comparison | revisions
External/JPEG/src/jcapistd.c file | annotate | diff | comparison | revisions
External/JPEG/src/jccoefct.c file | annotate | diff | comparison | revisions
External/JPEG/src/jccolor.c file | annotate | diff | comparison | revisions
External/JPEG/src/jcdctmgr.c file | annotate | diff | comparison | revisions
External/JPEG/src/jchuff.c file | annotate | diff | comparison | revisions
External/JPEG/src/jchuff.h file | annotate | diff | comparison | revisions
External/JPEG/src/jcinit.c file | annotate | diff | comparison | revisions
External/JPEG/src/jcmainct.c file | annotate | diff | comparison | revisions
External/JPEG/src/jcmarker.c file | annotate | diff | comparison | revisions
External/JPEG/src/jcmaster.c file | annotate | diff | comparison | revisions
External/JPEG/src/jcomapi.c file | annotate | diff | comparison | revisions
External/JPEG/src/jconfig.h file | annotate | diff | comparison | revisions
External/JPEG/src/jcparam.c file | annotate | diff | comparison | revisions
External/JPEG/src/jcphuff.c file | annotate | diff | comparison | revisions
External/JPEG/src/jcprepct.c file | annotate | diff | comparison | revisions
External/JPEG/src/jcsample.c file | annotate | diff | comparison | revisions
External/JPEG/src/jctrans.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdapimin.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdapistd.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdatadst.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdatasrc.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdcoefct.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdcolor.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdct.h file | annotate | diff | comparison | revisions
External/JPEG/src/jddctmgr.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdhuff.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdhuff.h file | annotate | diff | comparison | revisions
External/JPEG/src/jdinput.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdmainct.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdmarker.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdmaster.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdmerge.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdphuff.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdpostct.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdsample.c file | annotate | diff | comparison | revisions
External/JPEG/src/jdtrans.c file | annotate | diff | comparison | revisions
External/JPEG/src/jerror.c file | annotate | diff | comparison | revisions
External/JPEG/src/jerror.h file | annotate | diff | comparison | revisions
External/JPEG/src/jfdctflt.c file | annotate | diff | comparison | revisions
External/JPEG/src/jfdctfst.c file | annotate | diff | comparison | revisions
External/JPEG/src/jfdctint.c file | annotate | diff | comparison | revisions
External/JPEG/src/jidctflt.c file | annotate | diff | comparison | revisions
External/JPEG/src/jidctfst.c file | annotate | diff | comparison | revisions
External/JPEG/src/jidctint.c file | annotate | diff | comparison | revisions
External/JPEG/src/jidctred.c file | annotate | diff | comparison | revisions
External/JPEG/src/jinclude.h file | annotate | diff | comparison | revisions
External/JPEG/src/jmemansi.c file | annotate | diff | comparison | revisions
External/JPEG/src/jmemmgr.c file | annotate | diff | comparison | revisions
External/JPEG/src/jmemsys.h file | annotate | diff | comparison | revisions
External/JPEG/src/jmorecfg.h file | annotate | diff | comparison | revisions
External/JPEG/src/jpegint.h file | annotate | diff | comparison | revisions
External/JPEG/src/jpeglib.h file | annotate | diff | comparison | revisions
External/JPEG/src/jquant1.c file | annotate | diff | comparison | revisions
External/JPEG/src/jquant2.c file | annotate | diff | comparison | revisions
External/JPEG/src/jutils.c file | annotate | diff | comparison | revisions
External/JPEG/src/jversion.h file | annotate | diff | comparison | revisions
External/JPEG/src/transupp.h file | annotate | diff | comparison | revisions
External/LZMA/LzmaDecode.cpp file | annotate | diff | comparison | revisions
External/LZMA/LzmaDecode.h file | annotate | diff | comparison | revisions
External/LZMA/LzmaTypes.h file | annotate | diff | comparison | revisions
External/StackWalker/StackWalker.cpp file | annotate | diff | comparison | revisions
External/StackWalker/StackWalker.h file | annotate | diff | comparison | revisions
External/XmlParser/xmlParser.cpp file | annotate | diff | comparison | revisions
External/XmlParser/xmlParser.h file | annotate | diff | comparison | revisions
External/XmlParser/xmlParser.h - AFPL-license.txt file | annotate | diff | comparison | revisions
External/dirent.h file | annotate | diff | comparison | revisions
External/pThreads/pthread.h file | annotate | diff | comparison | revisions
External/pThreads/sched.h file | annotate | diff | comparison | revisions
External/pThreads/semaphore.h file | annotate | diff | comparison | revisions
External/png/png.h file | annotate | diff | comparison | revisions
External/png/pngconf.h file | annotate | diff | comparison | revisions
External/png/zconf.h file | annotate | diff | comparison | revisions
External/png/zlib.h file | annotate | diff | comparison | revisions
GGE Filter for VS.txt 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/Definitions.h file | annotate | diff | comparison | revisions
Resource/FolderResource.cpp 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/LinkNode.cpp file | annotate | diff | comparison | revisions
Resource/LinkNode.h file | annotate | diff | comparison | revisions
Resource/ResourceBase.cpp 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
Resource/SoundResource.cpp file | annotate | diff | comparison | revisions
Resource/SoundResource.h file | annotate | diff | comparison | revisions
Resource/TextResource.cpp file | annotate | diff | comparison | revisions
Resource/TextResource.h file | annotate | diff | comparison | revisions
Sample cpp file.txt file | annotate | diff | comparison | revisions
Utils/Any.h file | annotate | diff | comparison | revisions
Utils/BasicGraphics.h file | annotate | diff | comparison | revisions
Utils/Bounds2D.h file | annotate | diff | comparison | revisions
Utils/BufferList.h file | annotate | diff | comparison | revisions
Utils/Collection.h file | annotate | diff | comparison | revisions
Utils/EventChain.h file | annotate | diff | comparison | revisions
Utils/GGE Flags.txt file | annotate | diff | comparison | revisions
Utils/GGE.h file | annotate | diff | comparison | revisions
Utils/Iterator.h file | annotate | diff | comparison | revisions
Utils/LinkedList.h file | annotate | diff | comparison | revisions
Utils/ManagedBuffer.h file | annotate | diff | comparison | revisions
Utils/Margins.h file | annotate | diff | comparison | revisions
Utils/PAClassList.h file | annotate | diff | comparison | revisions
Utils/Point2D.h file | annotate | diff | comparison | revisions
Utils/Random.h file | annotate | diff | comparison | revisions
Utils/Rectangle2D.h file | annotate | diff | comparison | revisions
Utils/Size2D.h file | annotate | diff | comparison | revisions
Utils/Utils.h file | annotate | diff | comparison | revisions
Utils/ValueList.h file | annotate | diff | comparison | revisions
Widgets/Button.cpp file | annotate | diff | comparison | revisions
Widgets/Button.h file | annotate | diff | comparison | revisions
Widgets/ButtonBP.cpp file | annotate | diff | comparison | revisions
Widgets/ButtonBP.h file | annotate | diff | comparison | revisions
Widgets/ButtonElement.cpp file | annotate | diff | comparison | revisions
Widgets/ButtonElement.h file | annotate | diff | comparison | revisions
Widgets/ButtonLoader.cpp file | annotate | diff | comparison | revisions
Widgets/ButtonStyleGroup.cpp file | annotate | diff | comparison | revisions
Widgets/ButtonStyleGroup.h file | annotate | diff | comparison | revisions
Widgets/CheckboxBP.cpp file | annotate | diff | comparison | revisions
Widgets/CheckboxBP.h file | annotate | diff | comparison | revisions
Widgets/CheckboxBase.cpp file | annotate | diff | comparison | revisions
Widgets/CheckboxBase.h file | annotate | diff | comparison | revisions
Widgets/CheckboxElement.cpp file | annotate | diff | comparison | revisions
Widgets/CheckboxElement.h file | annotate | diff | comparison | revisions
Widgets/CheckboxLoader.cpp file | annotate | diff | comparison | revisions
Widgets/CheckboxStyleGroup.cpp file | annotate | diff | comparison | revisions
Widgets/CheckboxStyleGroup.h file | annotate | diff | comparison | revisions
Widgets/Frame.cpp file | annotate | diff | comparison | revisions
Widgets/Frame.h file | annotate | diff | comparison | revisions
Widgets/FrameBP.h file | annotate | diff | comparison | revisions
Widgets/Heatbar.cpp file | annotate | diff | comparison | revisions
Widgets/Heatbar.h file | annotate | diff | comparison | revisions
Widgets/IDialog.h file | annotate | diff | comparison | revisions
Widgets/IProgressor.h file | annotate | diff | comparison | revisions
Widgets/IScroller.h file | annotate | diff | comparison | revisions
Widgets/IWidgetBluePrint.cpp file | annotate | diff | comparison | revisions
Widgets/IWidgetBluePrint.h file | annotate | diff | comparison | revisions
Widgets/IWidgetContainer.cpp file | annotate | diff | comparison | revisions
Widgets/IWidgetContainer.h file | annotate | diff | comparison | revisions
Widgets/IWidgetObject.cpp file | annotate | diff | comparison | revisions
Widgets/IWidgetObject.h file | annotate | diff | comparison | revisions
Widgets/Indicatorbar.cpp file | annotate | diff | comparison | revisions
Widgets/Indicatorbar.h file | annotate | diff | comparison | revisions
Widgets/Label.h file | annotate | diff | comparison | revisions
Widgets/Line.cpp file | annotate | diff | comparison | revisions
Widgets/Line.h file | annotate | diff | comparison | revisions
Widgets/LinearOrganizer.cpp file | annotate | diff | comparison | revisions
Widgets/LinearOrganizer.h file | annotate | diff | comparison | revisions
Widgets/MessageDialog.cpp file | annotate | diff | comparison | revisions
Widgets/MessageDialog.h file | annotate | diff | comparison | revisions
Widgets/NamedSlider.cpp file | annotate | diff | comparison | revisions
Widgets/NamedSlider.h file | annotate | diff | comparison | revisions
Widgets/Percentbar.cpp file | annotate | diff | comparison | revisions
Widgets/Percentbar.h file | annotate | diff | comparison | revisions
Widgets/Progressbar.cpp file | annotate | diff | comparison | revisions
Widgets/Progressbar.h file | annotate | diff | comparison | revisions
Widgets/RadioGroup.cpp file | annotate | diff | comparison | revisions
Widgets/RadioGroup.h file | annotate | diff | comparison | revisions
Widgets/Radiobar.cpp file | annotate | diff | comparison | revisions
Widgets/Radiobar.h file | annotate | diff | comparison | revisions
Widgets/Rectangle.cpp file | annotate | diff | comparison | revisions
Widgets/Rectangle.h file | annotate | diff | comparison | revisions
Widgets/Scrollbar.cpp file | annotate | diff | comparison | revisions
Widgets/Scrollbar.h file | annotate | diff | comparison | revisions
Widgets/Selectbar.cpp file | annotate | diff | comparison | revisions
Widgets/Selectbar.h file | annotate | diff | comparison | revisions
Widgets/Slider.cpp file | annotate | diff | comparison | revisions
Widgets/Slider.h file | annotate | diff | comparison | revisions
Widgets/SliderBP.cpp file | annotate | diff | comparison | revisions
Widgets/SliderBP.h file | annotate | diff | comparison | revisions
Widgets/SliderBase.cpp file | annotate | diff | comparison | revisions
Widgets/SliderBase.h file | annotate | diff | comparison | revisions
Widgets/SliderElement.cpp file | annotate | diff | comparison | revisions
Widgets/SliderElement.h file | annotate | diff | comparison | revisions
Widgets/SliderLoader.cpp file | annotate | diff | comparison | revisions
Widgets/SliderStyleGroup.cpp file | annotate | diff | comparison | revisions
Widgets/SliderStyleGroup.h file | annotate | diff | comparison | revisions
Widgets/Spinner.cpp file | annotate | diff | comparison | revisions
Widgets/Spinner.h file | annotate | diff | comparison | revisions
Widgets/Textbox.cpp file | annotate | diff | comparison | revisions
Widgets/Textbox.h file | annotate | diff | comparison | revisions
Widgets/TextboxBP.cpp file | annotate | diff | comparison | revisions
Widgets/TextboxBP.h file | annotate | diff | comparison | revisions
Widgets/TextboxElement.cpp file | annotate | diff | comparison | revisions
Widgets/TextboxElement.h file | annotate | diff | comparison | revisions
Widgets/TextboxLoader.cpp file | annotate | diff | comparison | revisions
Widgets/TextboxStyleGroup.cpp file | annotate | diff | comparison | revisions
Widgets/TextboxStyleGroup.h file | annotate | diff | comparison | revisions
Widgets/VirtualFrame.cpp file | annotate | diff | comparison | revisions
Widgets/VirtualFrame.h file | annotate | diff | comparison | revisions
Widgets/WidgetMain.cpp file | annotate | diff | comparison | revisions
Widgets/WidgetMain.h file | annotate | diff | comparison | revisions
Widgets/WidgetRegistry.cpp file | annotate | diff | comparison | revisions
Widgets/WidgetRegistry.h file | annotate | diff | comparison | revisions
Wooden.wgt file | annotate | diff | comparison | revisions
instructions.txt file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Effects/CountingText.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,47 @@
+#include "CountingText.h"
+
+namespace geffects {
+	void CountingText::Setup(float From, float To, int Time) {
+		if(Time)
+			speed=(To-From)/Time;
+		else
+			speed=0;
+
+		from=From;
+		current=from;
+		to=To;
+
+		this->progressed=0;
+		this->Play();
+	}
+
+	bool CountingText::isFinished() {
+		return current==to;
+	}
+
+	void CountingText::Print(I2DColorizableGraphicsTarget *target, int X, int Y) {
+		char text[50];
+
+		if(Format.length()) {
+			sprintf(text, Format.data(), current);
+		} else {
+			char tmp[10];
+			sprintf(tmp, "%%.%if", Decimals);
+			sprintf(text, tmp, current);
+		}
+
+		Font->Print(target, X, Y, Width, text, Color, Align, Shadow);
+	}
+
+	void CountingText::Process(int Time) {
+		if(from>to) {
+			current=from+Time*speed;
+			if(current<to)
+				current=to;
+		} else {
+			current=from+Time*speed;
+			if(current>to)
+				current=to;
+		}
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Effects/CountingText.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,70 @@
+#pragma once
+
+#include "../Utils/GGE.h"
+#include "../Resource/GRE.h"
+#include "../Engine/Animator.h"
+#include "../Engine/Graphics.h"
+#include "../Resource/BitmapFontResource.h"
+
+using namespace gge;
+using namespace gre;
+
+namespace geffects {
+
+	////This effect displays a counting number going from a given value to another one.
+	class CountingText : public AnimatorBase {
+	public:
+		////This event is fired when the animation
+		/// completes
+		EventChain<CountingText, empty_event_params> FinishedEvent;
+
+		////Color of the text, default is black
+		RGBint Color;
+		////Text shadow, default is none
+		ShadowParams Shadow;
+		////Alignment of the text, default is left
+		TextAlignment Align;
+		////Width of the text
+		int Width;
+		////Number of decimal places, default is 0
+		int Decimals;
+		////Customized printing format, printf style that can feature a %f as the current value
+		string Format;
+		////The font to be used
+		BitmapFontResource *Font;
+
+
+		////Initializes the effect
+		CountingText(BitmapFontResource *Font=NULL, RGBint color=RGBint(0xff000000), int Width=0, TextAlignment Align=TEXTALIGN_LEFT, ShadowParams Shadow=ShadowParams(), int Decimals=0) : 
+			Color(color),
+			Font(Font),
+			Shadow(Shadow),
+			Width(Width),
+			Align(Align),
+			Decimals(Decimals),
+			from(0), to(0), speed(0), current(0), FinishedEvent("Finished", this)
+		{ 
+			AnimatorBase::FinishedEvent=FinishedEvent;
+		}
+
+		float Current() { return current; }
+		////Sets source and destination to the given values and allows time duration to reach the
+		/// destination
+		void Setup(float From, float To, int Time);
+		////Sets current destination to the given value and allows time duration to reach it
+		void Setup(float To, int Time) { Setup(current, To, Time); }
+		
+		////Prints the current text to a layer
+		void Print(I2DColorizableGraphicsTarget *target, int X, int Y);
+
+	protected:
+		float from;
+		float to;
+		float current;
+		float speed;
+
+
+		virtual bool isFinished();
+		virtual void Process(int Time);
+	};
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Effects/Flip.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,188 @@
+#pragma warning(disable:4244)
+
+#include "Flip.h"
+
+#define PI		3.1416f
+#define PIO2	1.5708f
+
+namespace geffects {
+	void FlipEffect::Draw(I2DGraphicsTarget *Layer,int X,int Y) {
+		if(isFinished()) {
+			if(Backside) {
+				Back->Draw(Layer, X, Y);
+			} else {
+				Front->Draw(Layer, X, Y);
+			}
+		} else {
+			float ang=((float)AnimatorBase::currentTime()/ETA)*PI;
+			bool rev=false;
+			if(ang>PIO2) {
+				ang=PI-ang;
+				rev=true;
+			}
+
+			Buffered2DGraphic *img=NULL;
+			int cx,cy;
+			if(Backside ^ rev) {
+				img=Back;
+			} else {
+				img=Front;
+			}
+			if(img==NULL)
+				return;
+
+			cx=img->Texture.W;
+			cy=img->Texture.H;
+
+			FlipSide cside=Side;
+			if(Backside ^ rev) {
+				switch(Side) {
+					case EAFS_Top:
+						cside=EAFS_Bottom;
+						break;
+					case EAFS_Left:
+						cside=EAFS_Right;
+						break;
+					case EAFS_Bottom:
+						cside=EAFS_Top;
+						break;
+					case EAFS_Right:
+						cside=EAFS_Left;
+						break;
+				}
+			}
+
+			Point pivot;
+			if(Backside)
+				pivot=PivotBack;
+			else
+				pivot=PivotFront;
+
+			int x1=0,x2=cx,x3=cx,x4=0,y1=0,y2=0,y3=cy,y4=cy;
+			float tmp;
+
+			switch(cside) {
+				case EAFS_Top:
+					tmp=(sin(ang)*cx)*Perspective;
+
+					y1-=pivot.y;
+					y3-=pivot.y;
+	
+					y1*=cosf(ang);
+					y3*=cosf(ang);
+
+					y1+=pivot.y;
+					y3+=pivot.y;
+					y2=y1;
+					y4=y3;
+
+					x3+=tmp;
+					x4-=tmp;
+					break;
+				case EAFS_Left:
+					tmp=(sin(ang)*cy)*Perspective;
+
+					x1-=pivot.x;
+					x2-=pivot.x;
+
+					x1*=cosf(ang);
+					x2*=cosf(ang);
+
+					x1+=pivot.x;
+					x2+=pivot.x;
+					x4=x1;
+					x3=x2;
+
+					y2-=tmp;
+					y3+=tmp;
+					break;
+				case EAFS_Bottom:
+					tmp=(sin(ang)*cx)*Perspective;
+
+					y1-=pivot.y;
+					y3-=pivot.y;
+	
+					y1*=cosf(ang);
+					y3*=cosf(ang);
+
+					y1+=pivot.y;
+					y3+=pivot.y;
+					y2=y1;
+					y4=y3;
+
+					x1-=tmp;
+					x2+=tmp;
+					break;
+				case EAFS_Right:
+					tmp=(sin(ang)*cy)*Perspective;
+
+					x1-=pivot.x;
+					x2-=pivot.x;
+
+					x1*=cosf(ang);
+					x2*=cosf(ang);
+
+					x1+=pivot.x;
+					x2+=pivot.x;
+					x4=x1;
+					x3=x2;
+
+					y1-=tmp;
+					y4+=tmp;
+					break;
+			}
+			
+			img->Draw(Layer,x1+X,y1+Y,x2+X,y2+Y,x3+X,y3+Y,x4+X,y4+Y);
+		}
+	}
+
+	void FlipEffect::Flip(int ETA) {
+		if(this->ETA!=0) {
+			Backside=!Backside;
+			progressed=this->ETA-progressed;
+		}
+
+		this->ETA=ETA;
+		Play();
+		Flipping=true;
+	}
+
+	void FlipEffect::Initialize() {
+		Front=Back=NULL;
+		Perspective=0.0125;
+		Flipping=false;
+		Backside=false;
+		ETA=0;
+		Side=EAFS_Top;
+
+		PivotFront.x=0;
+		PivotFront.y=0;
+		PivotBack.x=0;
+		PivotBack.y=0;
+
+		Pause();
+	}
+
+	void FlipEffect::CenterPivot() {
+		if(Front) {
+			PivotFront.x=Front->Texture.W /2;
+			PivotFront.y=Front->Texture.H /2;
+		}
+		else if(Back) {
+			PivotFront.x=Back->Texture.W /2;
+			PivotFront.y=Back->Texture.H /2;
+		}
+
+		PivotBack=PivotFront;
+	}
+
+	void FlipEffect::Process(int Time) {
+		if(Time>=ETA) {
+			ETA=0;
+			Pause();
+			progressed=0;
+			Flipping=false;
+			Backside=!Backside;
+		}
+	}
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Effects/Flip.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,52 @@
+#pragma once
+
+#include "../Utils/GGE.h"
+#include "../Resource/GRE.h"
+#include "../Engine/Animator.h"
+#include "../Engine/Graphics.h"
+#include "../Engine/GraphicLayers.h"
+
+using namespace gre;
+
+namespace geffects {
+	enum FlipSide {
+		EAFS_Top=1,
+		EAFS_Left,
+		EAFS_Bottom,
+		EAFS_Right,
+	};
+
+	class FlipEffect : public AnimatorBase, public Buffered2DGraphic {
+	public:
+		////This event is fired when the animation
+		/// completes
+		EventChain<FlipEffect, empty_event_params> FinishedEvent;
+
+		FlipEffect() : FinishedEvent("Finished", this) { 
+			AnimatorBase::FinishedEvent=FinishedEvent;
+			Initialize(); 
+		}
+
+		void Flip(int ETA);
+		void CenterPivot();
+
+		Buffered2DGraphic *Front,*Back;
+		FlipSide Side;
+		bool Backside;
+		bool Flipping;
+		float Perspective;
+		int ETA;
+
+		Point PivotFront;
+		Point PivotBack;
+
+		virtual void Draw(I2DGraphicsTarget *Layer, int X, int Y);
+		virtual void Draw(I2DGraphicsTarget &Layer, int X, int Y) { Draw(&Layer, X,Y); }
+
+	protected:
+		void Initialize();
+
+		virtual bool isFinished() { return AnimatorBase::currentTime()>=ETA; }
+		virtual void Process(int Time);
+	};
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Effects/LayerMover.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,58 @@
+#include "LayerMover.h"
+
+namespace geffects {
+	void LayerMover::Setup(Point From, Point To, int Time) {
+
+		from=From;
+		current=from;
+		to=To;
+
+		Target->X=from.x;
+		Target->Y=from.y;
+		this->progressed=0;
+
+		if(Time) {
+			speed.x=(float)(to.x-from.x)/Time;
+			speed.y=(float)(to.y-from.y)/Time;
+			this->Play();
+		} else {
+			speed.x=0;
+			speed.y=0;
+			current=from=to;
+			Target->X=to.x;
+			Target->Y=to.y;
+		}
+	}
+
+	bool LayerMover::isFinished() {
+		return current.x==to.x && current.y==to.y;
+	}
+
+	void LayerMover::Process(int Time) {
+		if(from.x>to.x) {
+			current.x=from.x+Time*speed.x;
+
+			if(current.x<to.x)
+				current.x=to.x;
+		} else {
+			current.x=from.x+Time*speed.x;
+			if(current.x>to.x)
+				current.x=to.x;
+		}
+		Target->X=current.x;
+
+
+		if(from.y>to.y) {
+			current.y=from.y+Time*speed.y;
+
+			if(current.y<to.y)
+				current.y=to.y;
+		} else {
+			current.y=from.y+Time*speed.y;
+			if(current.y>to.y)
+				current.y=to.y;
+		}
+		Target->Y=current.y;
+
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Effects/LayerMover.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,56 @@
+#pragma once
+
+#include "../Utils/GGE.h"
+#include "../Resource/GRE.h"
+#include "../Engine/Animator.h"
+#include "../Engine/Graphics.h"
+#include "../Engine/Layer.h"
+
+using namespace gge;
+using namespace gre;
+
+namespace geffects {
+
+	////This effect moves a given layer. Moving operation is animated from a given
+	/// value to another one
+	class LayerMover : public AnimatorBase {
+	public:
+		////This event is fired when the animation
+		/// completes
+		EventChain<LayerMover, empty_event_params> FinishedEvent;
+
+		////Target of this effect
+		LayerBase *Target;
+
+		////Initializes the effect
+		LayerMover(LayerBase *Target) :
+			speed(0,0),
+			current(Target->X, Target->Y),
+			Target(Target), FinishedEvent("Finished", this)
+		{
+			AnimatorBase::FinishedEvent=FinishedEvent;
+		}
+		////Initializes the effect
+		LayerMover(LayerBase &Target) :
+			speed(0,0),
+			current(Target.X, Target.Y),
+			Target(&Target), FinishedEvent("Finished", this)
+		{
+			AnimatorBase::FinishedEvent=FinishedEvent;
+		}
+		////Sets source and destination to the given values and allows time duration to reach the
+		/// destination
+		void Setup(Point From, 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); }
+
+	protected:
+		Point2D from;
+		Point2D to;
+		Point2D current;
+		Point2D speed;
+
+		virtual bool isFinished();
+		virtual void Process(int Time);
+	};
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Effects/LayerResizer.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,91 @@
+#include "LayerResizer.h"
+namespace geffects {
+	void LayerResizer::Setup(gge::Rectangle From, gge::Rectangle To, int Time) {
+
+		from=From;
+		current=from;
+		to=To;
+
+		Target->X=from.Left;
+		Target->Y=from.Top;
+		Target->W=from.Width;
+		Target->H=from.Height;
+		this->progressed=0;
+
+		if(Time) {
+			speed.Left=(float)(to.Left-from.Left)/Time;
+			speed.Top=(float)(to.Top-from.Top)/Time;
+			speed.Width=(float)(to.Width-from.Width)/Time;
+			speed.Height=(float)(to.Height-from.Height)/Time;
+
+			this->Play();
+		} else {
+			speed.Left=0;
+			speed.Top=0;
+			speed.Width=0;
+			speed.Height=0;
+			current=from=to;
+			Target->X=to.Left;
+			Target->Y=to.Top;
+			Target->W=to.Width;
+			Target->H=to.Height;
+		}
+	}
+
+	bool LayerResizer::isFinished() {
+		return current.Left==to.Left && current.Top==to.Top && current.Width==to.Width && current.Height==to.Height;
+	}
+
+	void LayerResizer::Process(int Time) {
+		if(from.Left>to.Left) {
+			current.Left=from.Left+Time*speed.Left;
+
+			if(current.Left<to.Left)
+				current.Left=to.Left;
+		} else {
+			current.Left=from.Left+Time*speed.Left;
+			if(current.Left>to.Left)
+				current.Left=to.Left;
+		}
+		Target->X=Round(current.Left);
+
+
+		if(from.Top>to.Top) {
+			current.Top=from.Top+Time*speed.Top;
+
+			if(current.Top<to.Top)
+				current.Top=to.Top;
+		} else {
+			current.Top=from.Top+Time*speed.Top;
+			if(current.Top>to.Top)
+				current.Top=to.Top;
+		}
+		Target->Y=Round(current.Top);
+
+
+		if(from.Width>to.Width) {
+			current.Width=from.Width+Time*speed.Width;
+
+			if(current.Width<to.Width)
+				current.Width=to.Width;
+		} else {
+			current.Width=from.Width+Time*speed.Width;
+			if(current.Width>to.Width)
+				current.Width=to.Width;
+		}
+		Target->W=Round(current.Width);
+
+
+		if(from.Height>to.Height) {
+			current.Height=from.Height+Time*speed.Height;
+
+			if(current.Height<to.Height)
+				current.Height=to.Height;
+		} else {
+			current.Height=from.Height+Time*speed.Height;
+			if(current.Height>to.Height)
+				current.Height=to.Height;
+		}
+		Target->H=Round(current.Height);
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Effects/LayerResizer.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,59 @@
+#pragma once
+
+#include "../Utils/GGE.h"
+#include "../Resource/GRE.h"
+#include "../Engine/Animator.h"
+#include "../Engine/Graphics.h"
+#include "../Engine/Layer.h"
+
+using namespace gge;
+using namespace gre;
+
+namespace geffects {
+
+	////This effect resizes a given layer. Resize operation is animated from a given
+	/// value to another one
+	class LayerResizer : public AnimatorBase {
+	public:
+		////This event is fired when the animation
+		/// completes
+		EventChain<LayerResizer, empty_event_params> FinishedEvent;
+
+		////Target of this effect
+		LayerBase *Target;
+
+		////Initializes the effect
+		LayerResizer(LayerBase *Target) :
+			speed(0,0 , 0,0),
+			current(Target->X, Target->Y, Target->W, Target->H),
+			Target(Target),
+			FinishedEvent("Finished", this)
+		{
+			AnimatorBase::FinishedEvent=FinishedEvent;
+		}
+
+		////Initializes the effect
+		LayerResizer(LayerBase &Target) :
+			speed(0,0 , 0,0),
+			current(Target.X, Target.Y, Target.W, Target.H),
+			Target(&Target),
+			FinishedEvent("Finished", this)
+		{
+			AnimatorBase::FinishedEvent=FinishedEvent;
+		}
+		////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);
+		////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); }
+
+	protected:
+		Rectangle2D from;
+		Rectangle2D to;
+		Rectangle2D current;
+		Rectangle2D speed;
+
+		virtual bool isFinished();
+		virtual void Process(int Time);
+	};
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Effects/Tinting.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,81 @@
+#include "Tinting.h"
+
+namespace geffects {
+	void Tinting::Setup(RGBint From, RGBint To, int Time) {
+
+		from=From;
+		current=From;
+		to=To;
+
+		Target->Ambient=from;
+
+		if(Time) {
+			speed.a=(float)(to.a-from.a)/Time;
+			speed.r=(float)(to.r-from.r)/Time;
+			speed.g=(float)(to.g-from.g)/Time;
+			speed.b=(float)(to.b-from.b)/Time;
+		} else {
+			speed.a=0;
+			speed.r=0;
+			speed.g=0;
+			speed.b=0;
+		}
+
+		this->progressed=0;
+		this->Play();
+	}
+
+	bool Tinting::isFinished() {
+		return current.a==to.a && current.r==to.r && current.g==to.g && current.g==to.b;
+	}
+
+	void Tinting::Process(int Time) {
+		if(from.a>to.a) {
+			current.a=from.a+Time*speed.a;
+
+			if(current.a<to.a)
+				current.a=to.a;
+		} else {
+			current.a=from.a+Time*speed.a;
+			if(current.a>to.a)
+				current.a=to.a;
+		}
+		Target->Ambient.a=current.a*255;
+
+		if(from.r>to.r) {
+			current.r=from.r+Time*speed.r;
+
+			if(current.r<to.r)
+				current.r=to.r;
+		} else {
+			current.r=from.r+Time*speed.r;
+			if(current.r>to.r)
+				current.r=to.r;
+		}
+		Target->Ambient.r=current.r*255;
+
+		if(from.g>to.g) {
+			current.g=from.g+Time*speed.g;
+
+			if(current.g<to.g)
+				current.g=to.g;
+		} else {
+			current.g=from.g+Time*speed.g;
+			if(current.g>to.g)
+				current.g=to.g;
+		}
+		Target->Ambient.g=current.g*255;
+
+		if(from.b>to.b) {
+			current.b=from.b+Time*speed.b;
+
+			if(current.b<to.b)
+				current.b=to.b;
+		} else {
+			current.b=from.b+Time*speed.b;
+			if(current.b>to.b)
+				current.b=to.b;
+		}
+		Target->Ambient.b=current.b*255;
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Effects/Tinting.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,59 @@
+#pragma once
+
+#include "../Utils/GGE.h"
+#include "../Resource/GRE.h"
+#include "../Engine/Animator.h"
+#include "../Engine/Graphics.h"
+
+using namespace gge;
+using namespace gre;
+
+namespace geffects {
+
+	////This effect tints a given colorizable target. Tinting is animated from a given
+	/// value to another one
+	class Tinting : public AnimatorBase {
+	public:
+		////This event is fired when the animation
+		/// completes
+		EventChain<Tinting, empty_event_params> FinishedEvent;
+
+		////Target of this effect
+		I2DColorizableGraphicsTarget *Target;
+
+		////Initializes the effect
+		Tinting(I2DColorizableGraphicsTarget *Target) : 
+			from(), to(), current(), 
+			speed(0, 0,0,0),
+			Target(Target),
+			FinishedEvent("Finished", this)
+		{
+			AnimatorBase::FinishedEvent=FinishedEvent;
+		}
+
+		////Initializes the effect
+		Tinting(I2DColorizableGraphicsTarget &Target) : 
+			from(), to(), current(), 
+			speed(0, 0,0,0),
+			Target(&Target),
+			FinishedEvent("Finished", this)
+		{
+			AnimatorBase::FinishedEvent=FinishedEvent;
+		}
+		
+		////Sets source and destination to the given values and allows time duration to reach the
+		/// destination
+		void Setup(RGBint From, RGBint To, int Time);
+		////Sets current destination to the given value and allows time duration to reach it
+		void Setup(RGBint To, int Time) { Setup(current, To, Time); }
+
+	protected:
+		RGBfloat from;
+		RGBfloat to;
+		RGBfloat current;
+		RGBfloat speed;
+
+		virtual bool isFinished();
+		virtual void Process(int Time);
+	};
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Animator.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,321 @@
+#include "Animator.h"
+#include "GGEMain.h"
+
+namespace gge {
+	Collection<AnimatorBase> Animators;
+	extern GGEMain *main;
+
+	void Animator_Signal(IntervalObject *interval, void *data) {
+		Animators.ResetIteration();
+		foreach(AnimatorBase, anim, Animators)
+			anim->Progress();
+	}
+
+	void InitializeAnimation(GGEMain *main) {
+		main->RegisterInterval(0, NULL, Animator_Signal);
+	}
+
+	AnimatorBase::AnimatorBase() : 
+		FinishedEvent("Finished", this),
+		InterruptedEvent("Interrupted", this)
+	{
+		Animators.Add(this);
+
+		///*Assigning default values
+		pauseat=-1;
+		pausedat=main->CurrentTime;
+		speed=1;
+		lasttick=main->CurrentTime;
+		ispaused=false;
+		progressed=0;
+	}
+
+	AnimatorBase::~AnimatorBase() {
+		Animators.Remove(this);
+	}
+
+	int AnimatorBase::currentTime() {
+		return (int)progressed;
+	}
+
+	bool AnimatorBase::isPlaying() {
+		return !ispaused && !isFinished();
+	}
+
+	void AnimatorBase::Pause() {
+		ispaused=true;
+		pausedat=main->CurrentTime;
+	}
+
+	void AnimatorBase::PauseAt(int ms) {
+		pauseat=ms;
+	}
+
+	void AnimatorBase::setSpeed(float Speed) {
+		speed=Speed;
+	}
+
+	void AnimatorBase::Progress() {
+		if(isFinished()) return;
+
+		if(!ispaused) {
+			ProgressBy(main->CurrentTime-lasttick);
+			lasttick=main->CurrentTime;
+		}
+	}
+
+	void AnimatorBase::ProgressBy(int ms) {
+		progressed+=(float)ms*speed;
+		Process((int)progressed);
+
+		if(!ispaused) {
+			if(progressed>pauseat && pauseat>0) {
+				pauseat=-1;
+				Pause();
+				InterruptedEvent();
+			}
+		}
+
+		if(isFinished()) {
+			FinishedEvent();
+		}
+	}
+
+	void AnimatorBase::ProgressTo(float ms) {
+		progressed=ms;
+		Process((int)progressed);
+
+		if(!ispaused) {
+			if(progressed>pauseat && pauseat>0) {
+				pauseat=-1;
+				Pause();
+				InterruptedEvent();
+			}
+		}
+
+		if(isFinished()) {
+			FinishedEvent();
+		}
+	}
+
+	void AnimatorBase::Play() {
+		lasttick=main->CurrentTime;
+		ispaused=false;
+	}
+
+	DiscreteAnimatorBase::DiscreteAnimatorBase() : 
+		AnimatorBase(),
+		FrameChangedEvent("framechanged",this),
+		FrameInterruptedEvent("frameinterrupted",this)
+	{
+		totalframes=0;
+		frametimings=NULL;
+		framedurations=NULL;
+		currentframe=0;
+		averagedurations=0;
+		duration=0;
+		frametimings=NULL;
+		EventOnFrameChange=false;
+		progressed=0;
+		gobackwards=false;
+		islooping=true;
+	}
+
+	void DiscreteAnimatorBase::GotoFrame(int Frame) {
+#ifdef _DEBUG
+		if(Frame<0) {
+			DisplayMessage("Discreate animation","Negative frame requested!");
+			assert(0);
+			return;
+		}
+		if(Frame>totalframes) {
+			DisplayMessage("Discreate animation","Specified frame does not exists!");
+			assert(0);
+			return;
+		}
+#endif
+
+		AnimatorBase::ProgressTo((float)frametimings[Frame]);
+	}
+
+	void DiscreteAnimatorBase::setLoop(bool loop) {
+		islooping=loop;
+	}
+
+	void DiscreteAnimatorBase::Reverse() {
+		gobackwards=!gobackwards;
+		speed=-speed;
+
+		//reverses the duration passed in this frame
+		ProgressTo(frametimings[currentframe]+framedurations[currentframe]-(progressed-frametimings[currentframe]));
+	}
+	void DiscreteAnimatorBase::GoForwards() {
+		if(gobackwards && progressed==duration-1) {
+			progressed=0;
+			currentframe=0;
+		}
+
+		if(speed<0)
+			speed=-speed;
+		gobackwards=false;
+	}
+	void DiscreteAnimatorBase::GoBackwards() {
+		if(!gobackwards && progressed==0) {
+			progressed=(float)(duration-1);
+			currentframe=totalframes-1;
+		}
+
+		if(speed>0)
+			speed=-speed;
+		gobackwards=true;
+	}
+
+	bool DiscreteAnimatorBase::isLooping() {
+		return islooping;
+	}
+	bool DiscreteAnimatorBase::isBackwards() {
+		return gobackwards;
+	}
+	int  DiscreteAnimatorBase::currentFrame() {
+		return currentframe;
+	}
+	void DiscreteAnimatorBase::setTotalFrames(int total) {
+#ifdef _DEBUG
+		if(total==0) {
+			DisplayMessage("Discreate animation","Empty total frames requested!");
+			assert(0);
+		}
+#endif
+
+		///*Startup
+		totalframes=total;
+		framedurations=FrameDurations();
+
+		if(frametimings)
+			delete[] frametimings;
+		frametimings=new int[total+1];
+
+		///*Calculate frame timings
+		int i;
+		duration=0;
+		for(i=0;i<total;i++) {
+			frametimings[i]=duration;
+			duration+=framedurations[i];
+		}
+		frametimings[i]=duration;
+
+#ifdef _DEBUG
+		if(duration==0) {
+			DisplayMessage("Discreate animation","Empty duration animation!");
+			assert(0);
+		}
+#endif
+
+
+		///*Calculate statistics
+		averagedurations=duration/total;
+
+		Progress();
+	}
+	void DiscreteAnimatorBase::Process(int time) {
+		int i;
+		if(duration==0)
+			return;
+
+#ifdef _DEBUG
+		if(averagedurations==0) {
+			DisplayMessage("Discreate animation","Trying to process an empty animation!");
+			assert(0);
+		}
+#endif
+		///*Checking time boundaries
+		//when going back
+		if(time<0 && gobackwards) {
+			if(islooping) {
+				if(time<-duration)
+					time=time % duration;
+
+				progressed=(float)((duration-1)+time);
+			} else {
+				progressed=0;
+				Pause();
+			}
+		}//when going forward
+		else if(time>=duration && !gobackwards) {
+			if(islooping) {
+				time=time % duration;
+				progressed=(float)time;
+			} else {
+				progressed=(float)(duration-1);
+				Pause();
+			}
+		}
+		time=(int)progressed;
+
+		///*finding current frame
+		//statistics is used to speedup search
+		int guessedframe=time/averagedurations;
+		int targetframe;
+#ifdef _DEBUG
+		if(guessedframe<0) {
+			DisplayMessage("Discreate animation","Guessed frame is lower than 0??");
+			guessedframe=0;
+		} else if(guessedframe>=totalframes) {
+			guessedframe=totalframes-1;
+		}
+#endif
+
+		//guessedframe=0;
+		//if guess is higher
+		if(frametimings[guessedframe]>time) {
+			for(i=guessedframe-1;i>=0;i--)
+				if(frametimings[i]<time) {
+					targetframe=i;
+					break;
+				}
+		}//if guess is lower
+		else if(frametimings[guessedframe+1]<time) {
+			for(i=guessedframe+1;i<totalframes;i++)
+				if(frametimings[i+1]>time) {
+					targetframe=i;
+					break;
+				}
+		}//if exact find
+		else {
+			targetframe=guessedframe;
+		}
+
+		//frame is changed
+		if(targetframe!=currentframe) {
+			frame_changed_event_params p(currentframe,targetframe);
+			FrameChangedEvent(p);
+		}
+#ifdef _DEBUG
+		if(targetframe<0) {
+			DisplayMessage("Discreate animation","Target frame is lower than 0!");
+			guessedframe=0;
+		} else if(targetframe>=totalframes) {
+			DisplayMessage("Discreate animation","Target frame is higher than totalframes!");
+			assert(0);
+		}
+#endif
+
+		currentframe=targetframe;
+
+		//checking for pause at frame
+		if(gobackwards && pauseatframe>targetframe) {
+			FrameInterruptedEvent();
+			pauseatframe=-1;
+		}
+		if(!gobackwards && pauseatframe<targetframe && pauseatframe>-1) {
+			FrameInterruptedEvent();
+			pauseatframe=-1;
+		}
+
+		ProcessFrame(currentframe);
+	}
+	void DiscreteAnimatorBase::PauseAtFrame(int frame) {
+		pauseatframe=frame;
+	}
+	void DiscreteAnimatorBase::ProcessFrame(int frame) { }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Animator.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,210 @@
+#pragma once
+
+#include "../Utils/Any.h"
+#include "../Utils/EventChain.h"
+#ifdef _DEBUG
+#include <assert.h>
+#endif
+
+///-This file contains animation support classes and
+/// functions
+
+namespace gge {
+	class GGEMain;
+
+	////This function should be called before any animation related
+	/// function is called.
+	void InitializeAnimation(GGEMain *main);
+
+	////This is the base class for all animations.
+	/// Provides several ready functions.
+	class AnimatorBase {
+	public:
+		AnimatorBase();
+		~AnimatorBase();
+		////This event is fired when the animation
+		/// completes
+		EventChain<AnimatorBase, empty_event_params> FinishedEvent;
+		////This event is fired whenever the animation
+		/// is interrupted when it reaches the time
+		/// specified by PauseAt function
+		EventChain<AnimatorBase, empty_event_params> InterruptedEvent;
+
+		////Starts or continues animation
+		virtual void Play();
+		////Pauses the animation
+		virtual void Pause();
+		////Progresses animation
+		virtual void Progress();
+		////Progresses the animation by the given time,
+		/// this function is also effected by speed
+		virtual void ProgressBy(int ms);
+		////Sets a pause position at the given time.
+		/// When animation reaches or passes that time
+		/// animation is paused and interrupt event
+		/// is fired. Negative values cancel this function.
+		void PauseAt(int ms);
+		////Cancels the set pause position
+		void CancelPauseAt() { PauseAt(-1); }
+		////Instantly progresses to the given time. Notice that
+		/// some animations cannot handle going back in time.
+		/// This function is not affected by speed
+		virtual void ProgressTo(float ms);
+		////Changes the speed of the animation, some animation may
+		/// dislike changing this value
+		///@Speed		: speed of the animation, default is 1 while
+		/// 0 effectively stops the animation
+		virtual void setSpeed(float Speed);
+		////Returns the current time of the animation
+		int currentTime();
+		////Returns whether the animation is playing
+		bool isPlaying();
+
+	protected:
+		////This function is called whenever processing
+		/// is required. Animator object can use
+		/// progressed variable to determine the current
+		/// relative time.
+		virtual void Process(int time)=0;
+
+		////Returns true when animation completes.
+		/// This function should be implemented by
+		/// animator class.
+		virtual bool isFinished()=0;
+
+		////The time of the last tick, used to determine
+		/// process time
+		unsigned int lasttick;
+		////Used for pause support
+		unsigned int pausedat;
+		////Time progressed since the beginning of the
+		/// animation, double is used to handle slower
+		/// speeds
+		float progressed;
+		////Whether the animation is paused
+		bool ispaused;
+		float speed;
+		////Used for PauseAt support
+		int pauseat;
+	};
+
+	////Used pass current and previous frame numbers when a frame change
+	/// event occurs
+	struct frame_changed_event_params {
+		frame_changed_event_params() { }
+		frame_changed_event_params(int prev,int cur) {
+			previous=prev;
+			current=cur;
+		}
+		////Previous frame
+		int previous;
+		////Current frame
+		int current;
+	};
+
+	////This base class defines a discreate animator,
+	/// it includes few common variables and functions
+	class DiscreteAnimatorBase : public AnimatorBase {
+	public:
+		////Constructor to setup the system
+		DiscreteAnimatorBase();
+		////Fired whenever a frame change occurs when EventOnFrameChange
+		/// flag is set
+		EventChain<DiscreteAnimatorBase, frame_changed_event_params> FrameChangedEvent;
+		////This event is fired whenever the animation
+		/// is interrupted when it reaches the frame
+		/// specified by PauseAtFrame function
+		EventChain<DiscreteAnimatorBase, empty_event_params> FrameInterruptedEvent;
+		////This function sets the current frame to the given value.
+		/// Animation time is moved to the beginning of the given frame
+		///@Frame		: the frame to go
+		virtual void GotoFrame(int Frame);
+		////Sets the whether to loop or not.
+		virtual void setLoop(bool loop);
+		////Sets a pause position at the given frame.
+		/// When animation reaches or passes that frame
+		/// animation is paused and frameinterrupt event
+		/// is fired. Negative values cancel this function.
+		virtual void PauseAtFrame(int Frame);
+		////Cancels the set pause position
+		void CancelPauseAtFrame() { PauseAtFrame(-1); }
+		////Reverses the direction of the animation
+		virtual void Reverse();
+		////Sets animation direction to forwards
+		virtual void GoForwards();
+		////Sets animation direction to backwards
+		virtual void GoBackwards();
+		////Returns whether the animation is looping
+		virtual bool isLooping();
+		////Changes the speed of the animation, some animation may
+		/// dislike changing this value
+		///@Speed		: speed of the animation, default is 1 while
+		/// 0 effectively stops the animation
+		virtual void setSpeed(float Speed) {
+			if(gobackwards)
+				AnimatorBase::setSpeed(-Speed);
+			else
+				AnimatorBase::setSpeed( Speed);
+		}
+		////Returns whether the animation is playing
+		/// backwards
+		virtual bool isBackwards();
+		////Returns the current frame
+		virtual int currentFrame();
+		////Returns total frames in this animation
+		int totalFrames();
+		////Overrides play to roll animation to beginning
+		virtual void Play() { 
+			if(gobackwards && progressed==0) progressed=(float)duration-1; 
+			else if(!gobackwards && progressed==duration-1) duration=0;
+			AnimatorBase::Play();
+		}
+
+		////If this flag is set, an event is fired when a frame
+		/// transition occurs
+		bool EventOnFrameChange;
+	protected:
+		////This value should not be modified by animator,
+		/// instead setTotalFrames function should be used
+		int totalframes;
+		////This value is used to internally and automatically
+		/// calculated and should not be changed. The value
+		/// is probed when setTotalFrames is called
+		int duration;
+		////Whether the animation is looping state
+		bool islooping;
+		////Whether the animation is running backwards
+		bool gobackwards;
+		////This value should not be modified by animator,
+		/// instead setTotalFrames function should be used
+		int *frametimings;
+		////This value should not be modified by animator,
+		/// instead setTotalFrames function should be used
+		int *framedurations;
+		////The current frame, should not be changed by animator,
+		/// GotoFrame function should be used in place
+		int currentframe;
+		////This value is used to speed up searches,
+		/// should only be changed when necessary. The value
+		/// is probed when setTotalFrames is called
+		int averagedurations;
+		////Used for pause@frame support
+		int pauseatframe;
+
+
+		////Used to change the total number of frames
+		/// by the animator, invokes probing of frame timings
+		/// and durations
+		void setTotalFrames(int total);
+		////This function should return the duration
+		/// time of frames
+		virtual int* FrameDurations()=0;
+		////Processes the current time to determine current frame
+		virtual void Process(int time);
+		////Can be overriden to process a frame,
+		/// a default method doing nothing is provided
+		virtual void ProcessFrame(int frame);
+		////This function returns whether this animation is finished
+		virtual bool isFinished() { return !islooping && ( (currentframe==totalframes-1 && !gobackwards) || (currentframe==0 && gobackwards) ); }
+	};
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/CustomLayer.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,104 @@
+#include "CustomLayer.h"
+#include "Graphics.h"
+#include "GGEMain.h"
+#include <gl/gl.h>
+
+namespace gge {
+	extern RGBfloat CurrentLayerColor;
+	extern GGEMain *main;
+	extern int trX,trY;
+	extern int scX,scY,scW,scH;
+
+	CustomLayer::CustomLayer(CustomRenderer Renderer,int X, int Y, int W, int H) {
+		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;
+	}
+
+	void CustomLayer::Render() {
+		int pscX,pscY,pscW,pscH;
+		trX+=X;
+		trY+=Y;
+		glPushAttrib(GL_SCISSOR_BIT);
+		glEnable(GL_SCISSOR_TEST);
+
+		pscX=scX;
+		pscY=scY;
+		pscW=scW;
+		pscH=scH;
+
+		int r=scX+scW;
+		int b=scY+scH;
+
+		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);
+
+		scW=r-scX;
+		scH=b-scY;
+
+		if(scH<=0 || scW<=0) {
+			scX=pscX;
+			scY=pscY;
+			scW=pscW;
+			scH=pscH;
+		}
+
+		glScissor(scX, (ScreenSize.y-scY)-scH, scW, scH);
+
+
+		glColor4f(1,1,1,1);
+		glViewport(X, (main->H-Y)-H, W, H);
+		glClear(GL_DEPTH_BUFFER_BIT);
+		glMatrixMode(GL_PROJECTION);
+		glPushMatrix();
+
+		glLoadIdentity();
+		glOrtho(Xs, Xe, Ys, Ye, Zs, Ze);
+
+		glMatrixMode(GL_MODELVIEW);
+		glPushMatrix();
+		glLoadIdentity();
+
+		glBindTexture(GL_TEXTURE_2D, -1);
+		glDepthFunc(GL_LESS);
+
+		this->Renderer();
+
+		glDepthFunc(GL_LEQUAL);
+
+		glPopMatrix();
+
+		glMatrixMode(GL_PROJECTION);
+		glPopMatrix();
+
+		glMatrixMode(GL_MODELVIEW);
+		glColor4fv(CurrentLayerColor.vect);
+		glClear(GL_DEPTH_BUFFER_BIT);
+		glViewport(0, 0, main->W, main->H);
+		
+		scX=pscX;
+		scY=pscY;
+		scW=pscW;
+		scH=pscH;
+
+		glPopAttrib();
+		trX-=X;
+		trY-=Y;
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/CustomLayer.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "Layer.h"
+
+namespace gge {
+
+	typedef void (*CustomRenderer)();
+
+	class CustomLayer : public LayerBase {
+	public:
+		CustomLayer(CustomRenderer Renderer, int X, int Y, int W, int H);
+
+		virtual void Render();
+
+		virtual void Clear() { }
+
+		float Xs, Xe, Ys, Ye, Zs, Ze;
+
+		CustomRenderer Renderer;
+	};
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/GGEMain.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,122 @@
+#include "GGEMain.h"
+#include <atlbase.h>
+
+namespace gge {
+	GGEMain *main;
+
+	GGEMain::GGEMain(char *SystemName, InstanceHandle Instance, int Width, int Height, int BitDepth, bool FullScreen) :
+		SystemName(SystemName),
+		Instance(Instance),
+		Width(Width)  ,
+		Height(Height),
+		BitDepth(BitDepth),
+		FullScreen(FullScreen),
+		BeforeRenderEvent("BeforeRender", this),
+		AfterRenderEvent("AfterRender", this)
+	{
+
+		W=Width;
+		H=Height;
+		X=0;
+		Y=0;
+
+		gge::AddPointerTarget(this,0);
+
+		Window_Activate=NULL;
+		Window_Deactivate=NULL;
+		Window_Destroy=NULL;
+
+		CurrentTime=GetTime();
+
+		CoInitialize(NULL);
+		main=this;
+
+		FPS=50;
+	}
+
+	GGEMain::~GGEMain() {
+		CoUninitialize();
+	}
+
+	void GGEMain::BeforeGameLoop() {
+		static unsigned int lastFPSUpdate=CurrentTime;
+		static int fpscounter=0;
+		///*Setting game time
+		CurrentTime=GetTime();
+		if(CurrentTime-lastFPSUpdate>=1000) {
+			FPS=fpscounter;
+			fpscounter=1;
+			lastFPSUpdate=CurrentTime;
+		} else
+			fpscounter++;
+
+		gge::ProcessMessage();
+		ProcessMousePosition(Window);
+	}
+
+	void GGEMain::BeforeRender() {
+		BeforeRenderEvent();
+
+		///*Processing interval objects
+		IntervalObjects.ResetIteration();
+		IntervalObject *interval;
+
+		while(interval=IntervalObjects.next()) {
+			if(interval->Enabled)
+				if(CurrentTime-interval->LastSignal>interval->Timeout) {
+					interval->Signal(interval, interval->Data);
+					interval->LastSignal=CurrentTime;
+				}
+		}
+
+	}
+
+	void IntervalObject::Reset() {
+		Enabled=true;
+		LastSignal=main->CurrentTime;
+	}
+
+	void GGEMain::AfterRender() {
+		AfterRenderEvent();
+
+		Sleep(1);
+	}
+
+	void GGEMain::Render() {
+		gge::PreRender();
+		LayerBase::Render();
+		gge::PostRender(Device);
+	}
+
+	IntervalObject *GGEMain::RegisterInterval(unsigned int Timeout, void* Data, IntervalSignalEvent Signal) {
+		IntervalObject *interval=new IntervalObject;
+
+		interval->Data=Data;
+		interval->Enabled=true;
+		interval->LastSignal=CurrentTime;
+		interval->Timeout=Timeout;
+		interval->Signal=Signal;
+
+		IntervalObjects.Add(interval);
+
+		return interval;
+	}
+
+	void GGEMain::UnregisterInterval(IntervalObject *Interval) {
+		IntervalObjects.Remove(Interval);
+
+		delete Interval;
+	}
+
+	void GGEMain::InitializeAll(const char *Title, gge::IconHandle Icon, int X, int Y) {
+		main->InitializeOS();
+		main->CreateWin(Title, Icon, X, Y);
+		main->InitializeGraphics();
+		main->InitializeSound();
+		main->InitializeInput();
+		main->InitializeAnimation();
+		main->InitializePointer();
+		main->InitializeWidgets();
+	}
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/GGEMain.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,187 @@
+#pragma once
+
+#include "OS.h"
+#include "Sound.h"
+#include "../Utils/Any.h"
+#include "../Utils/EventChain.h"
+#include "Graphics.h"
+#include "Input.h"
+#include "Layer.h"
+#include "Animator.h"
+#include "../Widgets/WidgetMain.h"
+
+namespace gge {
+	void InitializePointer(GGEMain *Main);
+
+	struct IntervalObject;
+
+	////Function definition required to handle interval signal events
+	typedef void (*IntervalSignalEvent)(IntervalObject *interval, void *data);
+
+	////Function definition to handle notifications
+	typedef void (*Notification)();
+
+	////This structure holds information about intervals
+	/// its variables can be modified, intervals are checked
+	/// before "BeforeRender" event, so if this object is modified
+	/// the modifications will not be effective before the next loop
+	struct IntervalObject {
+		////Timeout interval in msec
+		unsigned int Timeout;
+		////This variable is used internally to track when
+		/// this interval is signaled
+		unsigned int LastSignal;
+		////The data to ba passed signal handler
+		void *Data;
+		////Wheter 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
+		/// setting LastSignal to current time while enabling
+		/// the interval object
+		bool Enabled;
+		////The signal handler
+		IntervalSignalEvent Signal;
+
+		void Reset();
+	};
+
+	////This is main class of Gorgon Game Engine. This class is responsible
+	/// of organizing various resources. Although there is no mechanism to
+	/// 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 BasicPointerTarget {
+	public:
+		////Handle of the device context specifying drawable area of
+		/// the created window. Can be changed but should be modified with care
+		DeviceHandle Device;
+
+		int FPS;
+
+		////Width of the graphics area
+		inline int getWidth() { return Width; }
+		////Height of the graphics area
+		inline int getHeight() { return Height; }
+		////Bitdepth of screen if running fullscreen, this function does not
+		/// return active bitdepth, only the specified value
+		inline int getBitDepth() { return BitDepth; }
+		////Whether running in windowed mode
+		inline int getFullScreen() { return FullScreen; }
+		////The name of the system (code name of the game)
+		inline char *getSystemName() { return SystemName; }
+		////Handle of the window
+		inline WindowHandle getWindow() { return Window; }
+		////Handle of the application instance
+		inline InstanceHandle getInstance() { return Instance; }
+
+		////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(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, MouseEventType event, int x, int y, void *data) {
+			return LayerBase::PropagateMouseScrollEvent(amount, event, x, y, data);
+		}
+
+		////Constructor
+		///@SystemName	: The name of the system (code name of the game)
+		/// should contain alpha numeric characters obeying
+		/// variable naming rules
+		///@Instance	: Handle of the application instance
+		GGEMain(char *SystemName, InstanceHandle Instance, int Width=800, int Height=600, int BitDepth=32, bool FullScreen=false);
+
+		////This function should be called within the game loop before anything else
+		void BeforeGameLoop();
+		////This function must be called after every drawing function before
+		/// calling Render function. The order shall not be changed but you may
+		/// insert additional operations between this function and Render function.
+		void BeforeRender();
+		////Renders everything that is marked to be drawn. Must be called after
+		/// "BeforeRender" function
+		virtual void Render();
+		////This function should be called after Render function. At this step, any time consuming
+		/// operations that are not related with graphics are made.
+		void AfterRender();
+
+		////This function creates the game window. You may specify title, icon and position
+		/// of the window. However, position is ignored if this is a fullscreen application.
+		/// OS should be initialized before calling this function
+		WindowHandle CreateWin(const char *Title, IconHandle Icon, int X=0, int Y=0) {
+			Window=gge::CreateWin(SystemName,Title,Icon,Instance,X,Y,Width,Height,BitDepth,FullScreen);
+			return Window;
+		}
+
+		////Initializes graphic subsystem. All graphic related functions will fail if
+		/// called before this method. 
+		DeviceHandle InitializeGraphics() { Device = gge::InitializeGraphics(Window, BitDepth, Width, Height); return Device; }
+		////Initializes sound subsystem. All sound related functions will fail if
+		/// called before this method.
+		void		 InitializeSound() { gge::InitializeSound(Window); }
+		////Initializes input subsystem. All check on keyboard state before calling
+		/// this method is error prone. This method should be called before any
+		/// call to BeforeGameLoop function.
+		void		 InitializeInput() { gge::InitializeInput(); }
+		////Initializes OS subsystem allowing it to setup events. Should be called before creating a window
+		void		 InitializeOS() { gge::InitializeOS(); }
+		////Initializes all systems creating the main window
+		void		 InitializeAll(const char *Title, IconHandle Icon, int X=0, int Y=0);
+		////Initializes Animation subsystem. Before calling this function, animations does not progress
+		/// automatically.
+		void		 InitializeAnimation() { gge::InitializeAnimation(this); }
+		////Initializes Pointer subsystem. Before calling this function, pointers cannot be used
+		void		 InitializePointer() { gge::InitializePointer(this); }
+		void		 InitializeWidgets() { gorgonwidgets::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
+		IntervalObject *RegisterInterval(unsigned int Timeout, void* Data, IntervalSignalEvent Signal);
+		////Unregisters and destroys given interval. Given interval object is destroyed therefore,
+		/// it cannot be used after this function is called
+		void UnregisterInterval(IntervalObject *Interval);
+
+
+		////This notification is triggered when the window activates
+		Notification Window_Activate;
+		////This notification is triggered when the window deactivates
+		Notification Window_Deactivate;
+		////This notification is triggered when the window is destroyed.
+		/// There is no way to prevent destruction after this notification is
+		/// issued. Also graphic and sound functions will not work.
+		Notification Window_Destroy;
+		////This event is triggered before rendering, after intervals
+		EventChain<GGEMain, empty_event_params> BeforeRenderEvent;
+		////This event is triggered after rendering before the next
+		/// game loop
+		EventChain<GGEMain, empty_event_params> AfterRenderEvent;
+
+		////Destructor, cleans up resources
+		~GGEMain();
+
+	protected:
+		////Width of the graphics area
+		int Width;
+		////Height of the graphics area
+		int Height;
+		////Bitdepth of screen if running fullscreen
+		int BitDepth;
+		////Whether running in fullscreen mode
+		bool FullScreen;
+		////The name of the system (code name of the game)
+		/// should contain alpha numeric characters obeying
+		/// variable naming rules
+		char *SystemName;
+		////Handle of the window
+		WindowHandle Window;
+		////Handle of the application instance
+		InstanceHandle Instance;
+
+		Collection<IntervalObject> IntervalObjects;
+	};
+
+	extern GGEMain *main;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/GraphicLayers.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,1330 @@
+#include "GraphicLayers.h"
+#pragma warning(disable:4244)
+
+namespace gge {
+	RGBfloat CurrentLayerColor;
+	int trX,trY;
+	extern MouseEventObject *pressedObject;
+	int scX,scY,scW,scH;
+
+	Basic2DLayer::Basic2DLayer(int X,int Y,int W,int H) {
+		this->X=X;
+		this->Y=Y;
+		this->W=W;
+		this->H=H;
+		isVisible=true;
+
+		EnableClipping=false;
+	}
+
+	Basic2DLayer::Basic2DLayer(gge::Rectangle r) {
+		this->X=r.Left;
+		this->Y=r.Top;
+		this->W=r.Width;
+		this->H=r.Height;
+		isVisible=true;
+
+		EnableClipping=false;
+	}
+	void Basic2DLayer::Draw(gge::GLTexture *Image, int X1, int Y1, int X2, int Y2, int X3, int Y3, int X4, int Y4) {
+		BasicSurface *surface=Surfaces.Add();
+
+		surface->setTexture(Image);
+		surface->VertexCoords[0].x=X1;
+		surface->VertexCoords[0].y=Y1;
+
+		surface->VertexCoords[1].x=X2;
+		surface->VertexCoords[1].y=Y2;
+
+		surface->VertexCoords[2].x=X3;
+		surface->VertexCoords[2].y=Y3;
+
+		surface->VertexCoords[3].x=X4;
+		surface->VertexCoords[3].y=Y4;
+	}
+
+	void Basic2DLayer::DrawTiled(GLTexture *Image,int X,int Y,int W,int H) {
+		///*Handles special case where size is 2^n
+		if(sl2(Image->H)==Image->H) {
+			if(sl2(Image->W)==Image->W) { //both axis are size of 2^n
+				BasicSurface *surface=Surfaces.Add();
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=X;
+				surface->VertexCoords[0].y=Y;
+
+				surface->TextureCoords[1].s=(float)W/Image->W;
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=X+W;
+				surface->VertexCoords[1].y=Y;
+
+				surface->TextureCoords[2].s=(float)W/Image->W;
+				surface->TextureCoords[2].t=(float)H/Image->H;
+				surface->VertexCoords[2].x=X+W;
+				surface->VertexCoords[2].y=Y+H;
+	 
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=(float)H/Image->H;
+				surface->VertexCoords[3].x=X;
+				surface->VertexCoords[3].y=Y+H;
+			} else { //only height is 2^n
+				//we leave at least a portion of an image to the last part
+				//so that there will be less controls
+				int x=X,tx=X+W-Image->W;
+				//draw whole parts where image is texture repeated in
+				//y axis, we only need to draw multiple images for x axis
+				for(x=X;x<tx;x+=Image->W) { 
+					BasicSurface *surface=Surfaces.Add();
+
+					surface->setTexture(Image);
+					surface->CreateTextureCoords();
+
+					surface->TextureCoords[0].s=0;
+					surface->TextureCoords[0].t=0;
+					surface->VertexCoords[0].x=x;
+					surface->VertexCoords[0].y=Y;
+
+					surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+					surface->TextureCoords[1].t=0;
+					surface->VertexCoords[1].x=x+Image->W;
+					surface->VertexCoords[1].y=Y;
+
+					surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+					surface->TextureCoords[2].t=(float)H/Image->H;
+					surface->VertexCoords[2].x=x+Image->W;
+					surface->VertexCoords[2].y=Y+H;
+		 
+					surface->TextureCoords[3].s=0;
+					surface->TextureCoords[3].t=(float)H/Image->H;
+					surface->VertexCoords[3].x=x;
+					surface->VertexCoords[3].y=Y+H;
+				}
+
+				//last image (might be partial)
+				BasicSurface *surface=Surfaces.Add();
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=x;
+				surface->VertexCoords[0].y=Y;
+
+				surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=X+W;
+				surface->VertexCoords[1].y=Y;
+
+				surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
+				surface->TextureCoords[2].t=(float)H/Image->H;
+				surface->VertexCoords[2].x=X+W;
+				surface->VertexCoords[2].y=Y+H;
+	 
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=(float)H/Image->H;
+				surface->VertexCoords[3].x=x;
+				surface->VertexCoords[3].y=Y+H;
+			}
+		} else {
+			if(sl2(Image->W) == Image->W) { //only width is 2^n
+				//we leave at least a portion of an image to the last part
+				//so that there will be less controls
+				int y=Y,ty=Y+H-Image->H;
+				//draw whole parts where image is texture repeated in
+				//x axis, we only need to draw multiple images for y axis
+				for(y=Y;y<ty;y+=Image->H) {
+					BasicSurface *surface=Surfaces.Add();
+
+					surface->setTexture(Image);
+					surface->CreateTextureCoords();
+
+					surface->TextureCoords[0].s=0;
+					surface->TextureCoords[0].t=0;
+					surface->VertexCoords[0].x=X;
+					surface->VertexCoords[0].y=y;
+
+					surface->TextureCoords[1].s=(float)W/Image->W;
+					surface->TextureCoords[1].t=0;
+					surface->VertexCoords[1].x=X+W;
+					surface->VertexCoords[1].y=y;
+
+					surface->TextureCoords[2].s=(float)W/Image->W;
+					surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+					surface->VertexCoords[2].x=X+W;
+					surface->VertexCoords[2].y=y+Image->H;
+		 
+					surface->TextureCoords[3].s=0;
+					surface->TextureCoords[3].t=Image->ImageCoord[3].t;
+					surface->VertexCoords[3].x=X;
+					surface->VertexCoords[3].y=y+Image->H;
+				}
+
+				//last image (might be partial)
+				BasicSurface *surface=Surfaces.Add();
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=X;
+				surface->VertexCoords[0].y=y;
+
+				surface->TextureCoords[1].s=(float)W/Image->W;
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=X+W;
+				surface->VertexCoords[1].y=y;
+
+				surface->TextureCoords[2].s=(float)W/Image->W;
+				surface->TextureCoords[2].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[2].x=X+W;
+				surface->VertexCoords[2].y=Y+H;
+	 
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=Image->ImageCoord[3].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[3].x=X;
+				surface->VertexCoords[3].y=Y+H;
+			} else { //if the image has no 2^n dimensions
+				//we move row by row
+				int y=Y,ty=Y+H-Image->H;
+				for(y=Y;y<ty;y+=Image->H) {
+					//this part is x axis
+					int cy=y+Image->H;
+					int x=X,tx=X+W-Image->W;
+					for(x=X;x<tx;x+=Image->W) {
+						//whole images
+						BasicSurface *surface=Surfaces.Add();
+
+						surface->setTexture(Image);
+						surface->CreateTextureCoords();
+
+						surface->TextureCoords[0].s=0;
+						surface->TextureCoords[0].t=0;
+						surface->VertexCoords[0].x=x;
+						surface->VertexCoords[0].y=y;
+
+						surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+						surface->TextureCoords[1].t=0;
+						surface->VertexCoords[1].x=x+Image->W;
+						surface->VertexCoords[1].y=y;
+
+						surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+						surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+						surface->VertexCoords[2].x=x+Image->W;
+						surface->VertexCoords[2].y=cy;
+			 
+						surface->TextureCoords[3].s=0;
+						surface->TextureCoords[3].t=Image->ImageCoord[3].t;
+						surface->VertexCoords[3].x=x;
+						surface->VertexCoords[3].y=cy;
+					}
+
+					//partial image at the end of x axis, only x axis is partial
+					BasicSurface *surface=Surfaces.Add();
+
+					surface->setTexture(Image);
+					surface->CreateTextureCoords();
+
+					surface->TextureCoords[0].s=0;
+					surface->TextureCoords[0].t=0;
+					surface->VertexCoords[0].x=x;
+					surface->VertexCoords[0].y=y;
+
+					surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
+					surface->TextureCoords[1].t=0;
+					surface->VertexCoords[1].x=X+W;
+					surface->VertexCoords[1].y=y;
+
+					surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
+					surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+					surface->VertexCoords[2].x=X+W;
+					surface->VertexCoords[2].y=cy;
+		 
+					surface->TextureCoords[3].s=0;
+					surface->TextureCoords[3].t=Image->ImageCoord[2].t;
+					surface->VertexCoords[3].x=x;
+					surface->VertexCoords[3].y=cy;
+					
+				}
+
+				//this part is the last partial row
+				//this is the partial texture coordinate
+				float pty=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
+				int cy=Y+H;
+				int x=X,tx=X+W-Image->W;
+				for(x=X;x<tx;x+=Image->W) {
+					//partial image in y axis
+					BasicSurface *surface=Surfaces.Add();
+
+					surface->setTexture(Image);
+					surface->CreateTextureCoords();
+
+					surface->TextureCoords[0].s=0;
+					surface->TextureCoords[0].t=0;
+					surface->VertexCoords[0].x=x;
+					surface->VertexCoords[0].y=y;
+
+					surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+					surface->TextureCoords[1].t=0;
+					surface->VertexCoords[1].x=x+Image->W;
+					surface->VertexCoords[1].y=y;
+
+					surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+					surface->TextureCoords[2].t=pty;
+					surface->VertexCoords[2].x=x+Image->W;
+					surface->VertexCoords[2].y=cy;
+		 
+					surface->TextureCoords[3].s=0;
+					surface->TextureCoords[3].t=pty;
+					surface->VertexCoords[3].x=x;
+					surface->VertexCoords[3].y=cy;
+				}
+
+				//partial image at the end of x axis at last row, both axis are partial
+				BasicSurface *surface=Surfaces.Add();
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=x;
+				surface->VertexCoords[0].y=y;
+
+				surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=X+W;
+				surface->VertexCoords[1].y=y;
+
+				surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
+				surface->TextureCoords[2].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[2].x=X+W;
+				surface->VertexCoords[2].y=Y+H;
+	 
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[3].x=x;
+				surface->VertexCoords[3].y=Y+H;
+
+			}
+		}
+	}
+
+	void Basic2DLayer::DrawHTiled(GLTexture *Image,int X,int Y,int W,int H) {
+		if(sl2(Image->W)==Image->W) { //both x axis is size of 2^n
+			//stretch and repeat as we need
+			BasicSurface *surface=Surfaces.Add();
+
+			surface->setTexture(Image);
+			surface->CreateTextureCoords();
+
+			surface->TextureCoords[0].s=0;
+			surface->TextureCoords[0].t=0;
+			surface->VertexCoords[0].x=X;
+			surface->VertexCoords[0].y=Y;
+
+			surface->TextureCoords[1].s=(float)W/Image->W;
+			surface->TextureCoords[1].t=0;
+			surface->VertexCoords[1].x=X+W;
+			surface->VertexCoords[1].y=Y;
+
+			surface->TextureCoords[2].s=(float)W/Image->W;
+			surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+			surface->VertexCoords[2].x=X+W;
+			surface->VertexCoords[2].y=Y+H;
+ 
+			surface->TextureCoords[3].s=0;
+			surface->TextureCoords[3].t=Image->ImageCoord[2].t;
+			surface->VertexCoords[3].x=X;
+			surface->VertexCoords[3].y=Y+H;
+		} else {
+			//we leave at least a portion of an image to the last part
+			//so that there will be less controls
+			int x=X,tx=X+W-Image->W;
+			//draw whole parts where image is texture stretched in
+			//y axis, we only need to draw multiple images for x axis
+			for(x=X;x<tx;x+=Image->W) { 
+				BasicSurface *surface=Surfaces.Add();
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=x;
+				surface->VertexCoords[0].y=Y;
+
+				surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=x+Image->W;
+				surface->VertexCoords[1].y=Y;
+
+				surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+				surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+				surface->VertexCoords[2].x=x+Image->W;
+				surface->VertexCoords[2].y=Y+H;
+	 
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=Image->ImageCoord[2].t;
+				surface->VertexCoords[3].x=x;
+				surface->VertexCoords[3].y=Y+H;
+			}
+
+			//last image (might be partial)
+			BasicSurface *surface=Surfaces.Add();
+
+			surface->setTexture(Image);
+			surface->CreateTextureCoords();
+
+			surface->TextureCoords[0].s=0;
+			surface->TextureCoords[0].t=0;
+			surface->VertexCoords[0].x=x;
+			surface->VertexCoords[0].y=Y;
+
+			surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
+			surface->TextureCoords[1].t=0;
+			surface->VertexCoords[1].x=X+W;
+			surface->VertexCoords[1].y=Y;
+
+			surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
+			surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+			surface->VertexCoords[2].x=X+W;
+			surface->VertexCoords[2].y=Y+H;
+ 
+			surface->TextureCoords[3].s=0;
+			surface->TextureCoords[3].t=Image->ImageCoord[2].t;
+			surface->VertexCoords[3].x=x;
+			surface->VertexCoords[3].y=Y+H;	
+		}
+	}
+
+	void Basic2DLayer::DrawVTiled(GLTexture *Image,int X,int Y,int W,int H) {
+		if(sl2(Image->H)==Image->H) { //both x axis is size of 2^n
+			//stretch and repeat as we need
+			BasicSurface *surface=Surfaces.Add();
+
+			surface->setTexture(Image);
+			surface->CreateTextureCoords();
+
+			surface->TextureCoords[0].s=0;
+			surface->TextureCoords[0].t=0;
+			surface->VertexCoords[0].x=X;
+			surface->VertexCoords[0].y=Y;
+
+			surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+			surface->TextureCoords[1].t=0;
+			surface->VertexCoords[1].x=X+W;
+			surface->VertexCoords[1].y=Y;
+
+			surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+			surface->TextureCoords[2].t=(float)H/Image->H;
+			surface->VertexCoords[2].x=X+W;
+			surface->VertexCoords[2].y=Y+H;
+ 
+			surface->TextureCoords[3].s=0;
+			surface->TextureCoords[3].t=(float)H/Image->H;
+			surface->VertexCoords[3].x=X;
+			surface->VertexCoords[3].y=Y+H;
+		} else {
+				//we leave at least a portion of an image to the last part
+				//so that there will be less controls
+				int y=Y,ty=Y+H-Image->H;
+				//draw whole parts where image is texture repeated in
+				//x axis, we only need to draw multiple images for y axis
+				for(y=Y;y<ty;y+=Image->H) {
+					BasicSurface *surface=Surfaces.Add();
+
+					surface->setTexture(Image);
+					surface->CreateTextureCoords();
+
+					surface->TextureCoords[0].s=0;
+					surface->TextureCoords[0].t=0;
+					surface->VertexCoords[0].x=X;
+					surface->VertexCoords[0].y=y;
+
+					surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+					surface->TextureCoords[1].t=0;
+					surface->VertexCoords[1].x=X+W;
+					surface->VertexCoords[1].y=y;
+
+					surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+					surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+					surface->VertexCoords[2].x=X+W;
+					surface->VertexCoords[2].y=y+Image->H;
+		 
+					surface->TextureCoords[3].s=0;
+					surface->TextureCoords[3].t=Image->ImageCoord[3].t;
+					surface->VertexCoords[3].x=X;
+					surface->VertexCoords[3].y=y+Image->H;
+				}
+
+				//last image (might be partial)
+				BasicSurface *surface=Surfaces.Add();
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=X;
+				surface->VertexCoords[0].y=y;
+
+				surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=X+W;
+				surface->VertexCoords[1].y=y;
+
+				surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+				surface->TextureCoords[2].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[2].x=X+W;
+				surface->VertexCoords[2].y=Y+H;
+	 
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=Image->ImageCoord[3].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[3].x=X;
+				surface->VertexCoords[3].y=Y+H;
+		}
+	}
+
+	void Basic2DLayer::Render() {
+		int pscX,pscY,pscW,pscH;
+		if(!isVisible) return;
+		glPushAttrib(GL_SCISSOR_BIT);
+
+		glPushMatrix();
+		glTranslatef(X, Y, 0);
+		trX+=X;
+		trY+=Y;
+
+		if(EnableClipping) {
+			pscX=scX;
+			pscY=scY;
+			pscW=scW;
+			pscH=scH;
+
+			int r=scX+scW;
+			int b=scY+scH;
+
+			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);
+
+			scW=r-scX;
+			scH=b-scY;
+
+			if(scH<=0 || scW<=0) {
+				scX=pscX;
+				scY=pscY;
+				scW=pscW;
+				scH=pscH;
+			}
+
+			glScissor(scX, (ScreenSize.y-scY)-scH, scW, scH);
+		}
+
+		int i;
+		for(i=0;i<Surfaces.getCount();i++) {
+			BasicSurface *surface=Surfaces[i];
+			glBindTexture(GL_TEXTURE_2D, surface->getTexture()->ID);
+			glBegin(GL_QUADS);
+				glTexCoord2fv(surface->TextureCoords[0].vect);
+				glVertex3fv(surface->VertexCoords[0].vect);
+				glTexCoord2fv(surface->TextureCoords[1].vect);
+				glVertex3fv(surface->VertexCoords[1].vect);
+				glTexCoord2fv(surface->TextureCoords[2].vect);
+				glVertex3fv(surface->VertexCoords[2].vect);
+				glTexCoord2fv(surface->TextureCoords[3].vect);
+				glVertex3fv(surface->VertexCoords[3].vect);
+			glEnd();
+		}
+
+		LayerBase *layer;
+		LinkedListOrderedIterator<LayerBase> it=SubLayers.GetReverseOrderedIterator();
+		while(layer=it) {
+			layer->Render();
+		}
+
+		glPopMatrix();
+		trX-=X;
+		trY-=Y;
+		
+		if(EnableClipping) {
+			scX=pscX;
+			scY=pscY;
+			scW=pscW;
+			scH=pscH;
+		}
+
+		glPopAttrib();
+	}
+
+	Colorizable2DLayer::Colorizable2DLayer(int X,int Y,int W,int H) {
+		Ambient=RGBint(0xffffffff);
+		this->X=X;
+		this->Y=Y;
+		this->W=W;
+		this->H=H;
+
+		isVisible=true;
+		EnableClipping=false;
+	}
+	Colorizable2DLayer::Colorizable2DLayer(gge::Rectangle r){
+		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;
+
+		if(!isVisible) return;
+		glPushAttrib(GL_SCISSOR_BIT);
+
+
+		glPushMatrix();
+		glTranslatef(X, Y, 0);
+		trX+=X;
+		trY+=Y;
+
+		if(EnableClipping) {
+			pscX=scX;
+			pscY=scY;
+			pscW=scW;
+			pscH=scH;
+
+			int r=scX+scW;
+			int b=scY+scH;
+
+			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);
+
+			scW=r-scX;
+			scH=b-scY;
+
+			if(scH<=0 || scW<=0) {
+				scX=pscX;
+				scY=pscY;
+				scW=pscW;
+				scH=pscH;
+			}
+
+			glScissor(scX, (ScreenSize.y-scY)-scH, scW, scH);
+		}
+
+		RGBfloat prevcolor=CurrentLayerColor;
+		CurrentLayerColor.a*=(float)Ambient.a/255;
+		CurrentLayerColor.r*=(float)Ambient.r/255;
+		CurrentLayerColor.g*=(float)Ambient.g/255;
+		CurrentLayerColor.b*=(float)Ambient.b/255;
+
+		int i;
+		for(i=0;i<Surfaces.getCount();i++) {
+			ColorizableSurface *surface=Surfaces[i];
+			glColor4f(surface->Color.r*CurrentLayerColor.r,surface->Color.g*CurrentLayerColor.g,surface->Color.b*CurrentLayerColor.b,surface->Color.a*CurrentLayerColor.a);
+			glBindTexture(GL_TEXTURE_2D, surface->getTexture()->ID);
+			glBegin(GL_QUADS);
+				glTexCoord2fv(surface->TextureCoords[0].vect);
+				glVertex3fv(surface->VertexCoords[0].vect);
+				glTexCoord2fv(surface->TextureCoords[1].vect);
+				glVertex3fv(surface->VertexCoords[1].vect);
+				glTexCoord2fv(surface->TextureCoords[2].vect);
+				glVertex3fv(surface->VertexCoords[2].vect);
+				glTexCoord2fv(surface->TextureCoords[3].vect);
+				glVertex3fv(surface->VertexCoords[3].vect);
+			glEnd();
+		}
+
+		glColor4fv(CurrentLayerColor.vect);
+		LayerBase *layer;
+		LinkedListOrderedIterator<LayerBase> it=SubLayers.GetReverseOrderedIterator();
+		while(layer=it) {
+			layer->Render();
+		}
+
+		CurrentLayerColor=prevcolor;
+		glColor4fv(prevcolor.vect);
+
+		glPopMatrix();
+		trX-=X;
+		trY-=Y;
+		
+		if(EnableClipping) {
+			scX=pscX;
+			scY=pscY;
+			scW=pscW;
+			scH=pscH;
+		}
+
+		glPopAttrib();
+
+	}
+
+	void Colorizable2DLayer::Draw(gge::GLTexture *Image, int X1, int Y1, int X2, int Y2, int X3, int Y3, int X4, int Y4, RGBint color) {
+		ColorizableSurface *surface=Surfaces.Add();
+
+		surface->setTexture(Image);
+		surface->VertexCoords[0].x=X1;
+		surface->VertexCoords[0].y=Y1;
+
+		surface->VertexCoords[1].x=X2;
+		surface->VertexCoords[1].y=Y2;
+
+		surface->VertexCoords[2].x=X3;
+		surface->VertexCoords[2].y=Y3;
+
+		surface->VertexCoords[3].x=X4;
+		surface->VertexCoords[3].y=Y4;
+		surface->Color=ToRGBfloat(color);
+	}
+
+	void Colorizable2DLayer::Draw(gge::GLTexture *Image, int X1, int Y1, int X2, int Y2, int X3, int Y3, int X4, int Y4) {
+		ColorizableSurface *surface=Surfaces.Add();
+
+		surface->setTexture(Image);
+		surface->VertexCoords[0].x=X1;
+		surface->VertexCoords[0].y=Y1;
+
+		surface->VertexCoords[1].x=X2;
+		surface->VertexCoords[1].y=Y2;
+
+		surface->VertexCoords[2].x=X3;
+		surface->VertexCoords[2].y=Y3;
+
+		surface->VertexCoords[3].x=X4;
+		surface->VertexCoords[3].y=Y4;
+		surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+	}
+
+	void Colorizable2DLayer::DrawTiled(GLTexture *Image,int X,int Y,int W,int H) {
+		///*Handles special case where size is 2^n
+		if(sl2(Image->H)==Image->H) {
+			if(sl2(Image->W)==Image->W) { //both axis are size of 2^n
+				ColorizableSurface *surface=Surfaces.Add();
+				surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=X;
+				surface->VertexCoords[0].y=Y;
+
+				surface->TextureCoords[1].s=(float)W/Image->W;
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=X+W;
+				surface->VertexCoords[1].y=Y;
+
+				surface->TextureCoords[2].s=(float)W/Image->W;
+				surface->TextureCoords[2].t=(float)H/Image->H;
+				surface->VertexCoords[2].x=X+W;
+				surface->VertexCoords[2].y=Y+H;
+	 
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=(float)H/Image->H;
+				surface->VertexCoords[3].x=X;
+				surface->VertexCoords[3].y=Y+H;
+			} else { //only height is 2^n
+				//we leave at least a portion of an image to the last part
+				//so that there will be less controls
+				int x=X,tx=X+W-Image->W;
+				//draw whole parts where image is texture repeated in
+				//y axis, we only need to draw multiple images for x axis
+				for(x=X;x<tx;x+=Image->W) { 
+					ColorizableSurface *surface=Surfaces.Add();
+					surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+
+					surface->setTexture(Image);
+					surface->CreateTextureCoords();
+
+					surface->TextureCoords[0].s=0;
+					surface->TextureCoords[0].t=0;
+					surface->VertexCoords[0].x=x;
+					surface->VertexCoords[0].y=Y;
+
+					surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+					surface->TextureCoords[1].t=0;
+					surface->VertexCoords[1].x=x+Image->W;
+					surface->VertexCoords[1].y=Y;
+
+					surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+					surface->TextureCoords[2].t=(float)H/Image->H;
+					surface->VertexCoords[2].x=x+Image->W;
+					surface->VertexCoords[2].y=Y+H;
+		 
+					surface->TextureCoords[3].s=0;
+					surface->TextureCoords[3].t=(float)H/Image->H;
+					surface->VertexCoords[3].x=x;
+					surface->VertexCoords[3].y=Y+H;
+				}
+
+				//last image (might be partial)
+				ColorizableSurface *surface=Surfaces.Add();
+				surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=x;
+				surface->VertexCoords[0].y=Y;
+
+				surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=X+W;
+				surface->VertexCoords[1].y=Y;
+
+				surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
+				surface->TextureCoords[2].t=(float)H/Image->H;
+				surface->VertexCoords[2].x=X+W;
+				surface->VertexCoords[2].y=Y+H;
+	 
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=(float)H/Image->H;
+				surface->VertexCoords[3].x=x;
+				surface->VertexCoords[3].y=Y+H;
+			}
+		} else {
+			if(sl2(Image->W) == Image->W) { //only width is 2^n
+				//we leave at least a portion of an image to the last part
+				//so that there will be less controls
+				int y=Y,ty=Y+H-Image->H;
+				//draw whole parts where image is texture repeated in
+				//x axis, we only need to draw multiple images for y axis
+				for(y=Y;y<ty;y+=Image->H) {
+					ColorizableSurface *surface=Surfaces.Add();
+					surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+
+					surface->setTexture(Image);
+					surface->CreateTextureCoords();
+
+					surface->TextureCoords[0].s=0;
+					surface->TextureCoords[0].t=0;
+					surface->VertexCoords[0].x=X;
+					surface->VertexCoords[0].y=y;
+
+					surface->TextureCoords[1].s=(float)W/Image->W;
+					surface->TextureCoords[1].t=0;
+					surface->VertexCoords[1].x=X+W;
+					surface->VertexCoords[1].y=y;
+
+					surface->TextureCoords[2].s=(float)W/Image->W;
+					surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+					surface->VertexCoords[2].x=X+W;
+					surface->VertexCoords[2].y=y+Image->H;
+		 
+					surface->TextureCoords[3].s=0;
+					surface->TextureCoords[3].t=Image->ImageCoord[3].t;
+					surface->VertexCoords[3].x=X;
+					surface->VertexCoords[3].y=y+Image->H;
+				}
+
+				//last image (might be partial)
+				ColorizableSurface *surface=Surfaces.Add();
+				surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=X;
+				surface->VertexCoords[0].y=y;
+
+				surface->TextureCoords[1].s=(float)W/Image->W;
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=X+W;
+				surface->VertexCoords[1].y=y;
+
+				surface->TextureCoords[2].s=(float)W/Image->W;
+				surface->TextureCoords[2].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[2].x=X+W;
+				surface->VertexCoords[2].y=Y+H;
+	 
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=Image->ImageCoord[3].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[3].x=X;
+				surface->VertexCoords[3].y=Y+H;
+			} else { //if the image has no 2^n dimensions
+				//we move row by row
+				int y=Y,ty=Y+H-Image->H;
+				for(y=Y;y<ty;y+=Image->H) {
+					//this part is x axis
+					int cy=y+Image->H;
+					int x=X,tx=X+W-Image->W;
+					for(x=X;x<tx;x+=Image->W) {
+						//whole images
+						ColorizableSurface *surface=Surfaces.Add();
+						surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+
+						surface->setTexture(Image);
+						surface->CreateTextureCoords();
+
+						surface->TextureCoords[0].s=0;
+						surface->TextureCoords[0].t=0;
+						surface->VertexCoords[0].x=x;
+						surface->VertexCoords[0].y=y;
+
+						surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+						surface->TextureCoords[1].t=0;
+						surface->VertexCoords[1].x=x+Image->W;
+						surface->VertexCoords[1].y=y;
+
+						surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+						surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+						surface->VertexCoords[2].x=x+Image->W;
+						surface->VertexCoords[2].y=cy;
+			 
+						surface->TextureCoords[3].s=0;
+						surface->TextureCoords[3].t=Image->ImageCoord[3].t;
+						surface->VertexCoords[3].x=x;
+						surface->VertexCoords[3].y=cy;
+					}
+
+					//partial image at the end of x axis, only x axis is partial
+					ColorizableSurface *surface=Surfaces.Add();
+					surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+
+					surface->setTexture(Image);
+					surface->CreateTextureCoords();
+
+					surface->TextureCoords[0].s=0;
+					surface->TextureCoords[0].t=0;
+					surface->VertexCoords[0].x=x;
+					surface->VertexCoords[0].y=y;
+
+					surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
+					surface->TextureCoords[1].t=0;
+					surface->VertexCoords[1].x=X+W;
+					surface->VertexCoords[1].y=y;
+
+					surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
+					surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+					surface->VertexCoords[2].x=X+W;
+					surface->VertexCoords[2].y=cy;
+		 
+					surface->TextureCoords[3].s=0;
+					surface->TextureCoords[3].t=Image->ImageCoord[2].t;
+					surface->VertexCoords[3].x=x;
+					surface->VertexCoords[3].y=cy;
+					
+				}
+
+				//this part is the last partial row
+				//this is the partial texture coordinate
+				float pty=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
+				int cy=Y+H;
+				int x=X,tx=X+W-Image->W;
+				for(x=X;x<tx;x+=Image->W) {
+					//partial image in y axis
+					ColorizableSurface *surface=Surfaces.Add();
+					surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+
+					surface->setTexture(Image);
+					surface->CreateTextureCoords();
+
+					surface->TextureCoords[0].s=0;
+					surface->TextureCoords[0].t=0;
+					surface->VertexCoords[0].x=x;
+					surface->VertexCoords[0].y=y;
+
+					surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+					surface->TextureCoords[1].t=0;
+					surface->VertexCoords[1].x=x+Image->W;
+					surface->VertexCoords[1].y=y;
+
+					surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+					surface->TextureCoords[2].t=pty;
+					surface->VertexCoords[2].x=x+Image->W;
+					surface->VertexCoords[2].y=cy;
+		 
+					surface->TextureCoords[3].s=0;
+					surface->TextureCoords[3].t=pty;
+					surface->VertexCoords[3].x=x;
+					surface->VertexCoords[3].y=cy;
+				}
+
+				//partial image at the end of x axis at last row, both axis are partial
+				ColorizableSurface *surface=Surfaces.Add();
+				surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=x;
+				surface->VertexCoords[0].y=y;
+
+				surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=X+W;
+				surface->VertexCoords[1].y=y;
+
+				surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
+				surface->TextureCoords[2].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[2].x=X+W;
+				surface->VertexCoords[2].y=Y+H;
+	 
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[3].x=x;
+				surface->VertexCoords[3].y=Y+H;
+
+			}
+		}
+	}
+
+	void Colorizable2DLayer::DrawHTiled(GLTexture *Image,int X,int Y,int W,int H) {
+		if(sl2(Image->W)==Image->W) { //both x axis is size of 2^n
+			//stretch and repeat as we need
+			ColorizableSurface *surface=Surfaces.Add();
+			surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+
+			surface->setTexture(Image);
+			surface->CreateTextureCoords();
+
+			surface->TextureCoords[0].s=0;
+			surface->TextureCoords[0].t=0;
+			surface->VertexCoords[0].x=X;
+			surface->VertexCoords[0].y=Y;
+
+			surface->TextureCoords[1].s=(float)W/Image->W;
+			surface->TextureCoords[1].t=0;
+			surface->VertexCoords[1].x=X+W;
+			surface->VertexCoords[1].y=Y;
+
+			surface->TextureCoords[2].s=(float)W/Image->W;
+			surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+			surface->VertexCoords[2].x=X+W;
+			surface->VertexCoords[2].y=Y+H;
+ 
+			surface->TextureCoords[3].s=0;
+			surface->TextureCoords[3].t=Image->ImageCoord[2].t;
+			surface->VertexCoords[3].x=X;
+			surface->VertexCoords[3].y=Y+H;
+		} else {
+			//we leave at least a portion of an image to the last part
+			//so that there will be less controls
+			int x=X,tx=X+W-Image->W;
+			//draw whole parts where image is texture stretched in
+			//y axis, we only need to draw multiple images for x axis
+			for(x=X;x<tx;x+=Image->W) { 
+				ColorizableSurface *surface=Surfaces.Add();
+				surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=x;
+				surface->VertexCoords[0].y=Y;
+
+				surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=x+Image->W;
+				surface->VertexCoords[1].y=Y;
+
+				surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+				surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+				surface->VertexCoords[2].x=x+Image->W;
+				surface->VertexCoords[2].y=Y+H;
+	 
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=Image->ImageCoord[2].t;
+				surface->VertexCoords[3].x=x;
+				surface->VertexCoords[3].y=Y+H;
+			}
+
+			//last image (might be partial)
+			ColorizableSurface *surface=Surfaces.Add();
+			surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+
+			surface->setTexture(Image);
+			surface->CreateTextureCoords();
+
+			surface->TextureCoords[0].s=0;
+			surface->TextureCoords[0].t=0;
+			surface->VertexCoords[0].x=x;
+			surface->VertexCoords[0].y=Y;
+
+			surface->TextureCoords[1].s=Image->ImageCoord[1].s*((float)(W-(x-X))/Image->W);
+			surface->TextureCoords[1].t=0;
+			surface->VertexCoords[1].x=X+W;
+			surface->VertexCoords[1].y=Y;
+
+			surface->TextureCoords[2].s=Image->ImageCoord[2].s*((float)(W-(x-X))/Image->W);
+			surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+			surface->VertexCoords[2].x=X+W;
+			surface->VertexCoords[2].y=Y+H;
+ 
+			surface->TextureCoords[3].s=0;
+			surface->TextureCoords[3].t=Image->ImageCoord[2].t;
+			surface->VertexCoords[3].x=x;
+			surface->VertexCoords[3].y=Y+H;	
+		}
+	}
+
+	void Colorizable2DLayer::DrawVTiled(GLTexture *Image,int X,int Y,int W,int H) {
+		if(sl2(Image->H)==Image->H) { //both x axis is size of 2^n
+			//stretch and repeat as we need
+			ColorizableSurface *surface=Surfaces.Add();
+			surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+
+			surface->setTexture(Image);
+			surface->CreateTextureCoords();
+
+			surface->TextureCoords[0].s=0;
+			surface->TextureCoords[0].t=0;
+			surface->VertexCoords[0].x=X;
+			surface->VertexCoords[0].y=Y;
+
+			surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+			surface->TextureCoords[1].t=0;
+			surface->VertexCoords[1].x=X+W;
+			surface->VertexCoords[1].y=Y;
+
+			surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+			surface->TextureCoords[2].t=(float)H/Image->H;
+			surface->VertexCoords[2].x=X+W;
+			surface->VertexCoords[2].y=Y+H;
+ 
+			surface->TextureCoords[3].s=0;
+			surface->TextureCoords[3].t=(float)H/Image->H;
+			surface->VertexCoords[3].x=X;
+			surface->VertexCoords[3].y=Y+H;
+		} else {
+				//we leave at least a portion of an image to the last part
+				//so that there will be less controls
+				int y=Y,ty=Y+H-Image->H;
+				//draw whole parts where image is texture repeated in
+				//x axis, we only need to draw multiple images for y axis
+				for(y=Y;y<ty;y+=Image->H) {
+					ColorizableSurface *surface=Surfaces.Add();
+					surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+
+					surface->setTexture(Image);
+					surface->CreateTextureCoords();
+
+					surface->TextureCoords[0].s=0;
+					surface->TextureCoords[0].t=0;
+					surface->VertexCoords[0].x=X;
+					surface->VertexCoords[0].y=y;
+
+					surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+					surface->TextureCoords[1].t=0;
+					surface->VertexCoords[1].x=X+W;
+					surface->VertexCoords[1].y=y;
+
+					surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+					surface->TextureCoords[2].t=Image->ImageCoord[2].t;
+					surface->VertexCoords[2].x=X+W;
+					surface->VertexCoords[2].y=y+Image->H;
+		 
+					surface->TextureCoords[3].s=0;
+					surface->TextureCoords[3].t=Image->ImageCoord[3].t;
+					surface->VertexCoords[3].x=X;
+					surface->VertexCoords[3].y=y+Image->H;
+				}
+
+				//last image (might be partial)
+				ColorizableSurface *surface=Surfaces.Add();
+				surface->Color.a=surface->Color.r=surface->Color.g=surface->Color.b=1;
+
+				surface->setTexture(Image);
+				surface->CreateTextureCoords();
+
+				surface->TextureCoords[0].s=0;
+				surface->TextureCoords[0].t=0;
+				surface->VertexCoords[0].x=X;
+				surface->VertexCoords[0].y=y;
+
+				surface->TextureCoords[1].s=Image->ImageCoord[1].s;
+				surface->TextureCoords[1].t=0;
+				surface->VertexCoords[1].x=X+W;
+				surface->VertexCoords[1].y=y;
+
+				surface->TextureCoords[2].s=Image->ImageCoord[2].s;
+				surface->TextureCoords[2].t=Image->ImageCoord[2].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[2].x=X+W;
+				surface->VertexCoords[2].y=Y+H;
+	 
+				surface->TextureCoords[3].s=0;
+				surface->TextureCoords[3].t=Image->ImageCoord[3].t*((float)(H-(y-Y))/Image->H);
+				surface->VertexCoords[3].x=X;
+				surface->VertexCoords[3].y=Y+H;
+		}
+	}
+
+	void Basic2DRawGraphicsLayer::Draw(BYTE *Image, int Width, int Height, gge::ColorMode Mode, int X1, int Y1, int X2, int Y2, int X3, int Y3, int X4, int Y4) {
+		RawSurface *surface=Surfaces.Add();
+
+		surface->Data=Image;
+		surface->Mode=Mode;
+		surface->CreateTextureCoords();
+		surface->Width=Width;
+		surface->Height=Height;
+
+
+		surface->TextureCoords[0].s=0;
+		surface->TextureCoords[0].t=0;
+		surface->TextureCoords[1].s=(float)Width/sl2(Width);
+		surface->TextureCoords[1].t=0;
+		surface->TextureCoords[2].s=(float)Width/sl2(Width);
+		surface->TextureCoords[2].t=(float)Height/sl2(Height);
+		surface->TextureCoords[3].s=0;
+		surface->TextureCoords[3].t=(float)Height/sl2(Height);
+
+		surface->VertexCoords[0].x=X1;
+		surface->VertexCoords[0].y=Y1;
+
+		surface->VertexCoords[1].x=X2;
+		surface->VertexCoords[1].y=Y2;
+
+		surface->VertexCoords[2].x=X3;
+		surface->VertexCoords[2].y=Y3;
+
+		surface->VertexCoords[3].x=X4;
+		surface->VertexCoords[3].y=Y4;
+	}
+	void Basic2DRawGraphicsLayer::Render() {
+		if(!isVisible) return;
+		int pscX,pscY,pscW,pscH;
+
+		glPushAttrib(GL_SCISSOR_BIT);
+
+
+		glPushMatrix();
+		glTranslatef(X, Y, 0);
+		trX+=X;
+		trY+=Y;
+
+		if(EnableClipping) {
+			pscX=scX;
+			pscY=scY;
+			pscW=scW;
+			pscH=scH;
+
+			int r=scX+scW;
+			int b=scY+scH;
+
+			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);
+
+			scW=r-scX;
+			scH=b-scY;
+
+			if(scH<=0 || scW<=0) {
+				scX=pscX;
+				scY=pscY;
+				scW=pscW;
+				scH=pscH;
+			}
+
+			glScissor(scX, (ScreenSize.y-scY)-scH, scW, scH);
+		}
+
+		int i;
+		for(i=0;i<Surfaces.getCount();i++) {
+			RawSurface *surface=Surfaces[i];
+			glBindTexture(GL_TEXTURE_2D, NULL);
+			SetTexture(surface->Data, surface->Width, surface->Height, surface->Mode);
+
+			glBegin(GL_QUADS);
+				glTexCoord2fv(surface->TextureCoords[0].vect);
+				glVertex3fv(surface->VertexCoords[0].vect);
+				glTexCoord2fv(surface->TextureCoords[1].vect);
+				glVertex3fv(surface->VertexCoords[1].vect);
+				glTexCoord2fv(surface->TextureCoords[2].vect);
+				glVertex3fv(surface->VertexCoords[2].vect);
+				glTexCoord2fv(surface->TextureCoords[3].vect);
+				glVertex3fv(surface->VertexCoords[3].vect);
+			glEnd();
+		}
+
+		LayerBase *layer;
+		LinkedListOrderedIterator<LayerBase> it=SubLayers.GetReverseOrderedIterator();
+		while(layer=it) {
+			layer->Render();
+		}
+
+		glPopMatrix();
+		trX-=X;
+		trY-=Y;
+		
+		if(EnableClipping) {
+			scX=pscX;
+			scY=pscY;
+			scW=pscW;
+			scH=pscH;
+		}
+
+		glPopAttrib();
+	}
+	Basic2DRawGraphicsLayer::Basic2DRawGraphicsLayer(int X,int Y,int W,int H) {
+		this->X=X;
+		this->Y=Y;
+		this->W=W;
+		this->H=H;
+
+		isVisible=true;
+		EnableClipping=false;
+	}
+	bool WidgetLayer::PropagateMouseEvent(gge::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, 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::PropagateMouseEvent(event, x-X, y-Y, data);
+			else
+				return false;
+		}
+
+		return false;
+	}
+	bool WidgetLayer::PropagateMouseScrollEvent(int amount, gge::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, y, data))
+				return true;
+
+			if( isVisible && ((x>X && y>Y && x<X+W && y<Y+H)) )
+				return BasicPointerTarget::PropagateMouseScrollEvent(amount, event, x-X, y-Y, data);
+			else
+				return false;
+		}
+
+		return false;
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/GraphicLayers.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,144 @@
+#pragma once
+
+#include "../Utils/GGE.h"
+#include "Layer.h"
+#include "../Utils/PAClassList.h"
+#include "Graphics.h"
+
+namespace gge {
+	////_private
+	struct ColorizableSurface : public BasicSurface {
+		RGBfloat Color; 
+	};
+
+	////_private
+	struct RawSurface : public BasicSurface {
+		BYTE *Data;
+		ColorMode Mode;
+		int Width;
+		int Height;
+	};
+
+	////This layer is a basic 2D graphics target
+	class Basic2DLayer : public LayerBase, public I2DGraphicsTarget {
+	public:
+		////This list contains surfaces to be drawn
+		PAClassList<BasicSurface> Surfaces;
+		////Whether or not enable clipping
+		bool EnableClipping;
+
+		////Default constructor to initialize variables
+		Basic2DLayer(int X, int Y, int W, int H);
+		Basic2DLayer(gge::Rectangle r);
+
+		////Draws a simple image to the screen.
+		/// In this draw function every corner can be specified
+		/// thus various transformations can be made
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		///@X1		: top-left corner
+		///@Y1		: top-left corner
+		///@X2		: top-right corner
+		///@Y2		: top-right corner
+		///@X3		: bottom-right corner
+		///@Y3		: bottom-right corner
+		///@X4		: bottom-left corner
+		///@Y4		: bottom-left corner
+		virtual void Draw(GLTexture *Image,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4);
+		////Draws a tiled image to the screen
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		virtual void DrawTiled(GLTexture *Image,int X,int Y,int W,int H);
+		////Draws a horizontally tiled image to the screen
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		virtual void DrawHTiled(GLTexture *Image,int X,int Y,int W,int H);
+		////Draws a veritically 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);
+		////Renders the current layer, default handling is to pass
+		/// the request to the sub-layers
+		virtual void Render();
+		virtual void Clear() { Surfaces.Clear(); }
+	};
+	////This layer is a 2D graphics target and also has colorization support
+	class Colorizable2DLayer : public I2DColorizableGraphicsTarget, public LayerBase {
+	public:
+		////Whether or not enable clipping
+		bool EnableClipping;
+		////Default constructor to initialize variables
+		Colorizable2DLayer(int X, int Y, int W, int H);
+		Colorizable2DLayer(gge::Rectangle r);
+
+		////This list contains surfaces to be drawn
+		PAClassList<ColorizableSurface> Surfaces;
+
+		////Draws a simple image to the screen.
+		/// In this draw function every corner can be specified
+		/// thus various transformations can be made
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		///@X1		: top-left corner
+		///@Y1		: top-left corner
+		///@X2		: top-right corner
+		///@Y2		: top-right corner
+		///@X3		: bottom-right corner
+		///@Y3		: bottom-right corner
+		///@X4		: bottom-left corner
+		///@Y4		: bottom-left corner
+		///@Color	: color
+		virtual void Draw(GLTexture *Image,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4, RGBint Color);
+		virtual void Draw(GLTexture *Image,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4);
+		virtual void Render();
+		virtual void Clear() { Surfaces.Clear(); }
+		////Draws a tiled image to the screen
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		virtual void DrawTiled(GLTexture *Image,int X,int Y,int W,int H);
+		////Draws a horizontally tiled image to the screen
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		virtual void DrawHTiled(GLTexture *Image,int X,int Y,int W,int H);
+		////Draws a veritically 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);
+	};
+	class Basic2DRawGraphicsLayer : public I2DRawGraphicsTarget, public LayerBase {
+	public:
+		////Whether or not enable clipping
+		bool EnableClipping;
+		////This list contains surfaces to be drawn
+		PAClassList<RawSurface> Surfaces;
+
+		////Default constructor to initialize variables
+		Basic2DRawGraphicsLayer(int X, int Y, int W, int H);
+
+		////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);
+
+		////Renders this layer
+		virtual void Render();
+		////Clear the contents of the layer
+		virtual void Clear() { Surfaces.Clear(); }
+	};
+	class WidgetLayer :  public BasicPointerTarget, public Basic2DLayer {
+	public:
+		WidgetLayer(int X,int Y,int W,int H) : Basic2DLayer(X,Y,W,H) {
+		}
+		////Renders this layer
+		virtual void Render() { Basic2DLayer::Render(); }
+
+	protected:
+		////Processes the mouse event for the current layer, default
+		/// handling is to pass the request to the sub-layers
+		virtual bool PropagateMouseEvent(MouseEventType event, int x, int y, void *data);
+		virtual bool PropagateMouseScrollEvent(int amount, MouseEventType event, int x, int y, void *data);
+	};
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Graphics.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,261 @@
+#include "Graphics.h"
+#ifdef WIN32
+#include <windows.h>
+
+#endif
+namespace gge {
+	Point ScreenSize;
+	extern RGBfloat CurrentLayerColor;
+	extern int scX,scY,scW,scH;
+	extern int trX,trY;
+
+	DeviceHandle InitializeGraphics(WindowHandle hWnd, int BitDepth, int Width, int Height) {
+		///!Platform specific
+#ifdef WIN32
+		///*Preparing device context, platform specific
+		HDC hDC = GetDC((HWND)hWnd);
+
+		static	PIXELFORMATDESCRIPTOR pfd=	// pfd Tells Windows How We Want Things To Be
+		{
+			sizeof(PIXELFORMATDESCRIPTOR),	// Size Of This Pixel Format Descriptor
+			1,								// Version Number
+			PFD_DRAW_TO_WINDOW |			// Format Must Support Window
+			PFD_SUPPORT_OPENGL |			// Format Must Support OpenGL
+			PFD_DOUBLEBUFFER,				// Must Support Double Buffering
+			PFD_TYPE_RGBA,					// Request An RGBA Format
+			BitDepth,						// Select Our Color Depth
+			0, 0, 0, 0, 0, 0,				// Color Bits Ignored
+			0,								// No Alpha Buffer
+			0,								// Shift Bit Ignored
+			0,								// No Accumulation Buffer
+			0, 0, 0, 0,						// Accumulation Bits Ignored
+			16,								// 16Bit Z-Buffer (Depth Buffer)
+			0,								// No Stencil Buffer
+			0,								// No Auxiliary Buffer
+			PFD_MAIN_PLANE,					// Main Drawing Layer
+			0,								// Reserved
+			0, 0, 0							// Layer Masks Ignored
+		};
+
+		int PixelFormat=ChoosePixelFormat(hDC,&pfd);
+		SetPixelFormat(hDC,PixelFormat,&pfd);
+
+
+		HGLRC hRC;
+		hRC = wglCreateContext( hDC );
+		bool r=wglMakeCurrent(hDC,hRC);
+#endif
+
+		ScreenSize.x=Width;
+		ScreenSize.y=Height;
+
+		///*Setting OpenGL parameters
+		glShadeModel(GL_SMOOTH);							// Enables Smooth Shading
+
+		glClearColor(0.0f, 0.0f, 0.0f, 1.0f);				// Black Background
+		glColor4f(1.0f,1.0f,1.0f,1.0f);						// Full Brightness, 50% Alpha ( NEW )
+
+		glClearDepth(1.0f);									// Depth Buffer Setup
+		glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
+		glDepthFunc(GL_LEQUAL);
+
+		//Alpha
+		glEnable(GL_BLEND);
+		glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);	// Blending Function For Translucency Based On Source Alpha Value ( NEW )
+
+		//textures
+		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
+		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
+		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+		glEnable(GL_TEXTURE_2D);
+
+
+		///*Adjusting Matrices
+		glViewport(0, 0, Width, Height);					// Reset The Current Viewport
+
+
+		//These can be overridden by layers
+		glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix
+		glLoadIdentity();									// Reset The Projection Matrix
+		glOrtho(0,Width,Height,0,-100,100);					// Calculate The Aspect Ratio Of The Window
+		glFrontFace(GL_CW);
+
+		//position
+		glMatrixMode(GL_MODELVIEW);							// Select The Modelview Matrix
+		glLoadIdentity();									// Reset The Modelview Matrix
+
+		return (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;
+		
+		__asm {
+			; A8 (actually saved as a) data to 
+			; A8L8
+
+			; push everything so we can use them at will
+			push edi		; destination array
+			push esi		; source array
+			push ecx		; x
+			push edx		; y
+			push ebx		; temp
+			
+			mov  edi,dest	; destination data
+			mov  esi,data	; source data
+
+
+			mov edx,0		; y=0
+loopystart:
+			cmp edx,[icy]	; if y=cy
+			je loopyend		; break y loop
+
+			mov ecx,0		; x=0
+loopxstart:
+			cmp ecx,[icx]	; if x=cx
+			je loopxend		; break x loop
+			
+			mov byte ptr[edi],0xff
+			inc edi
+
+			movsb
+
+			inc ecx			; x++
+			jmp loopxstart	; next
+loopxend:
+			inc edx			; y++
+			jmp loopystart	; next
+loopyend:
+
+			; restore everything
+			pop ebx
+			pop ecx
+			pop edx
+			pop esi
+			pop edi
+		}
+	}
+	void SetTexture(BYTE *data, int cx, int cy, ColorMode mode) {
+		GLenum colormode=getGLColorMode(mode);
+
+		BYTE *target=NULL;
+
+		///*Setting Texture Parameters to
+		/// Magnify filter: Linear,
+		/// Minify filter:  Linear,
+		/// Border color:   Transparent
+		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+		glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BORDER_COLOR, 0x0);
+
+		if(mode==ALPHAONLY_8BPP) {
+			///*If alpha only, converted to grayscale alpha
+			glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
+			glPixelStorei(GL_PACK_ALIGNMENT, 2);
+
+			target=new BYTE[cx*cy*2];	
+			A8ToA8L8(cx,cy,data,target);
+			data=target;
+
+			mode=AGRAYSCALE_16BPP;
+			colormode=GL_LUMINANCE_ALPHA;
+		} else {
+			glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
+			glPixelStorei(GL_PACK_ALIGNMENT, 4);
+		}
+
+		glTexImage2D(GL_TEXTURE_2D,0,getBPP(mode),sl2(cx),sl2(cy),0,colormode,GL_UNSIGNED_BYTE,NULL);
+		glTexSubImage2D(GL_TEXTURE_2D,0,0,0,cx,cy,colormode,GL_UNSIGNED_BYTE,data);
+
+		if(target)
+			delete target;
+	}
+	GLTexture GenerateTexture(BYTE *data,int cx,int cy,ColorMode mode) {
+
+		GLTexture ret;
+		ret.CalcuateCoordinates(cx,cy);
+
+		///*Create the texture object
+		glGenTextures(1,&ret.ID);
+		glBindTexture(GL_TEXTURE_2D,ret.ID);
+
+		SetTexture(data,cx,cy,mode);
+
+		return ret;
+	}
+
+	void DestroyTexture(GLTexture *texture) {
+		glDeleteTextures(1, &texture->ID);
+		texture->ID=0;
+	}
+	void GLTexture::CalcuateCoordinates(int cx,int cy) {
+		W=cx;
+		H=cy;
+		TW=sl2(cx);//+0.0001
+		TH=sl2(cy);//+0.0001
+		S=(float)cx/TW;
+		T=(float)cy/TH;
+
+		ImageCoord[0].s=0;
+		ImageCoord[0].t=0;
+		ImageCoord[1].s=S;
+		ImageCoord[1].t=0;
+		ImageCoord[2].s=S;
+		ImageCoord[2].t=T;
+		ImageCoord[3].s=0;
+		ImageCoord[3].t=T;
+	}
+	GLenum getGLColorMode(ColorMode color_mode) {
+		switch(color_mode) {
+		case ALPHAONLY_8BPP:
+			return GL_ALPHA;
+		case AGRAYSCALE_16BPP:
+			return GL_LUMINANCE_ALPHA;
+		case RGB:
+			return GL_BGR;
+		case BGR:
+			return GL_RGB;
+		case ABGR_32BPP:
+			return GL_RGBA;
+		case ARGB_32BPP:
+			return GL_BGRA;
+		default:
+			return GL_BGRA;
+		}
+	}
+
+	void PreRender() {
+		///*Resetting OpenGL parameters
+		glDisable(GL_SCISSOR_TEST);
+		glMatrixMode(GL_MODELVIEW);
+		glLoadIdentity();
+
+		///*Clearing buffers
+		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+		CurrentLayerColor.a=1;
+		CurrentLayerColor.r=1;
+		CurrentLayerColor.g=1;
+		CurrentLayerColor.b=1;
+
+		trX=0;
+		trY=0;
+		scX=scY=0;
+		scW=ScreenSize.x;
+		scH=ScreenSize.y;
+	}
+
+	void PostRender(DeviceHandle hDC) {
+		///*Swapping back and front buffers
+		SwapBuffers( (HDC)hDC );
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Graphics.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,741 @@
+#pragma once
+
+#include "../Utils/GGE.h"
+#include "OS.h"
+#define WINGDIAPI	__declspec(dllimport)
+#define APIENTRY	__stdcall
+#define CALLBACK	__stdcall
+#include <gl/gl.h>
+#include <gl/glu.h>
+#include <assert.h>
+#include "../Utils/ManagedBuffer.h"
+
+////Namespace for Gorgon Game Engine
+namespace gge {
+	union TexturePosition { struct{float s,t;}; float vect[2];};
+	union VertexPosition { struct{float x,y,z;};float vect[3];};
+
+	////GGE Color mode constants
+	enum ColorMode {
+		////RGB base color mode
+		RGB = 1,
+		////Palleted base color mode
+		PALLETTED = 2,
+		////Gray base color mode
+		GRAY = 4,
+		////Alpha base color mode
+		ALPHA = 8,
+		////BGR base color mode
+		BGR = 16,
+		////4-byte RGB color with alpha
+		ARGB_32BPP = RGB | ALPHA,
+		////4-byte revered RGB color with alpha
+		ABGR_32BPP = BGR | ALPHA,
+		////1-byte palletted color mode, is not available yet
+		PALLETTED_8BPP = PALLETTED,
+		////2-byte palleted color mode with alpha, is not available yet
+		APALLETTED_16BPP = PALLETTED | ALPHA,
+		////1-byte alpha only color mode, converted to AGRAYSCALE_16BPP
+		ALPHAONLY_8BPP = ALPHA,
+		////1-byte gray (luminiance) only color mode, is not available yet
+		GRAYSCALE_8BPP = GRAY,
+		////2-byte gray (luminiance) color mode with alpha
+		AGRAYSCALE_16BPP = GRAY | ALPHA
+	};
+
+
+
+	////This structure contains all necessary information
+	/// of a texture. Using this information, image can be
+	/// drawn without requiring its actual size.
+	/// Also contains data to increase performance
+	struct GLTexture {
+		////OpenGL texture id
+		GLuint ID;
+		////Width of the image (not texture's)
+		int W;
+		////Height of the image (not texture's)
+		int H;
+		////Width of the texture
+		int TW;
+		////Height of the texture
+		int TH;
+
+		////S (texture x) position for the width of the image
+		float S;
+		////T position (texture y) position for the height of
+		/// the image
+		float T;
+
+		////Readily calculated texture coordinates of the image
+		TexturePosition ImageCoord[4];
+
+		////Calculates the necessary coordinates from
+		/// the give image size
+		void CalcuateCoordinates(int W,int H);
+	};
+
+	union RGBfloat {
+		RGBfloat() { }
+		RGBfloat(float a, float r, float g, float b) : a(a), r(r), g(g), b(b) { }
+
+		void Blend(RGBfloat color) {
+			float alpha=color.a;
+			float alpham1=1-color.a;
+			
+			a+=color.a;
+			if(a>1) a=1;
+			r=r*alpham1+color.r*alpha;
+			g=g*alpham1+color.g*alpha;
+			b=b*alpham1+color.b*alpha;
+		}
+		
+		struct {
+			////Color element
+			float b,g,r;
+			////Alpha value
+			float a;
+		};
+
+		float vect[4];
+	};
+
+	////A structure to extend standard argb integer
+	/// This structure helps with conversions
+	struct RGBint {
+		////Color element
+		unsigned char b,g,r;
+		////Alpha value
+		unsigned char a;
+
+		RGBint(unsigned int i) { memcpy(this,&i,4); }
+		RGBint(int i) { memcpy(this,&i,4); }
+		RGBint(BYTE a, BYTE r, BYTE g, BYTE b) : a(a), r(r), g(g), b(b) { }
+		RGBint(RGBfloat f) { a=(BYTE)(f.a*255); r=(BYTE)(f.r*255); g=(BYTE)(f.g*255); b=(BYTE)(f.b*255); }
+		RGBint(float lum) { a=255; r=(BYTE)lum*255; g=(BYTE)lum*255; b=(BYTE)lum*255; }
+		RGBint() { }
+		
+		////Converts RGBint structure to ARGB integer
+		operator int () { return *(int*)this; }
+		////Converts RGBint structure to ARGB (unsigned) integer
+		operator unsigned int () { return *(unsigned int*)this; }
+		RGBint &operator =(unsigned int i) { 
+			memcpy(this,&i,4);
+			return *this;
+		}
+		RGBint &operator =(int i) { 
+			memcpy(this,&i,4);
+			return *this;
+		}
+		RGBint &operator =(float lum) { 
+			a=255; r=(BYTE)(lum*255); g=(BYTE)(lum*255); b=(BYTE)(lum*255);
+			return *this;
+		}
+
+		RGBint &operator +=(RGBint color) {
+			r+=color.r;
+			g+=color.g;
+			b+=color.b;
+
+			return *this;
+		}
+
+		RGBint operator +(RGBint color) {
+			RGBint c;
+
+			c.r=r+color.r;
+			c.g=g+color.g;
+			c.b=b+color.b;
+
+			return c;
+		}
+
+		RGBint &operator -=(RGBint color) {
+			r=(r-color.r)/2 + 127;
+			g=(r-color.g)/2 + 127;
+			b=(r-color.b)/2 + 127;
+
+			return *this;
+		}
+
+		RGBint operator -(RGBint color) {
+			RGBint c;
+
+			c.r=(r-color.r)/2 + 127;
+			c.g=(r-color.g)/2 + 127;
+			c.b=(r-color.b)/2 + 127;
+
+			return c;
+		}
+		
+		RGBint &operator *=(float c) {
+			r=(BYTE)(r*c);
+			g=(BYTE)(g*c);
+			b=(BYTE)(b*c);
+
+			return *this;
+		}
+		
+		RGBint operator *(float c) {
+			RGBint color;
+			
+			color.r=(BYTE)(r*c);
+			color.g=(BYTE)(g*c);
+			color.b=(BYTE)(b*c);
+
+			return color;
+		}
+		
+		RGBint &operator /=(float c) {
+			r=(BYTE)(r/c);
+			g=(BYTE)(g/c);
+			b=(BYTE)(b/c);
+
+			return *this;
+		}
+		
+		RGBint operator /(float c) {
+			RGBint color;
+			
+			color.r=(BYTE)(r/c);
+			color.g=(BYTE)(g/c);
+			color.b=(BYTE)(b/c);
+
+			return color;
+		}
+
+
+		operator RGBfloat() {
+			RGBfloat f;
+			f.a=(float)a/255;
+			f.r=(float)r/255;
+			f.g=(float)g/255;
+			f.b=(float)b/255;
+
+			return f;
+		}
+		int Luminance() { 
+			return (r>>3) + (r>>4) + (r>>5) + (g>>1) + (g>>3) + (g>>4) + (g>>5) + (b>>4); 
+		}
+		float AccurateLuminance() { 
+			return  0.2126f*r + 0.7151f*g + 0.0722f*b; 
+		}
+
+		operator float() { return AccurateLuminance()/255.0f; }
+
+		string HTMLColor() {
+			stringstream str2;
+			stringstream str;
+			str2<<std::hex<<((int)(*this)&0x00ffffff);
+
+			str<<"#"<<fixed<<setw(6)<<setfill('0')<<str2.str();
+
+			return str.str();
+		}
+
+		void Blend(RGBint color) {
+			if(color.a==255) {
+				a=255;
+				r=color.r;
+				g=color.g;
+				b=color.b;
+			} else {
+				float alpha  =(float)color.a/255;
+				float alpham1=(float)(255-color.a)/255;
+
+				if(a<255) {
+					int aa=(int)a+color.a;
+					if(aa>255)
+						a=255;
+					else
+						a=aa;
+				}
+
+				r=(BYTE)(r*alpham1+color.r*alpha);
+				g=(BYTE)(g*alpham1+color.g*alpha);
+				b=(BYTE)(b*alpham1+color.b*alpha);
+			}
+		}
+
+		operator string() {
+			return HTMLColor();
+		}
+		////Returns BGRA integer
+		int operator !() { return (r<<16)+(g<<8)+b+(a<<24); }
+	};
+
+	inline ostream &operator <<(ostream &stream, RGBint color) {
+		stream<<(string)color;
+
+		return stream;
+	}
+
+	////Color range definition from one color
+	/// to another, this also includes alpha
+	struct RGBRangeint {
+		////Starting value
+		RGBint from;
+		////Ending value
+		RGBint to;
+	};
+
+	////This class can be used to store basic surface information.
+	/// It has also support for modifiable texture coordinates.
+	class BasicSurface {
+	public:
+		////Coordinates of vertices
+		VertexPosition VertexCoords[4];
+		////Coordinates of texture rectangle
+		TexturePosition *TextureCoords;
+		////Whether this surface has its own texture coordinates
+		bool hasOwnTextureCoords;
+
+		////Empty constructor
+		BasicSurface() {
+			Texture=NULL;
+			hasOwnTextureCoords=false;
+			VertexCoords[0].z=0;
+			VertexCoords[1].z=0;
+			VertexCoords[2].z=0;
+			VertexCoords[3].z=0;
+		}
+
+		////Filling constructor that sets texture
+		BasicSurface(GLTexture *texture) {
+			this->Texture=texture;
+			TextureCoords=texture->ImageCoord;
+
+			hasOwnTextureCoords=false;
+		}
+
+		////Changes current texture to the given one
+		void setTexture(GLTexture *texture) {
+			DeleteTextureCoords();
+
+			this->Texture=texture;
+			TextureCoords=texture->ImageCoord;
+		}
+
+		////Returns current texture
+		GLTexture *getTexture() {
+			return Texture;
+		}
+
+		////Deletes texture coordinate information
+		__forceinline void DeleteTextureCoords() {
+			if(hasOwnTextureCoords) {
+				hasOwnTextureCoords=false;
+				delete TextureCoords;
+			}
+		}
+
+		////Creates texture coordinate information,
+		/// should be called before modifying texture
+		/// coordinates
+		__forceinline void CreateTextureCoords() {
+			if(!hasOwnTextureCoords) {
+				hasOwnTextureCoords=true;
+				TextureCoords=new TexturePosition[4];
+			}
+		}
+
+		////Clears any unneeded data
+		~BasicSurface() {
+			if(hasOwnTextureCoords)
+				delete TextureCoords;
+		}
+	protected:
+		////The texture to be used
+		GLTexture *Texture;
+	};
+
+	////this structure is used to ease conversions
+	/// between RGB integer and float values used
+	/// in graphic adapters.
+	////Converts RGBint to RGBfloat
+	inline RGBfloat ToRGBfloat(RGBint color) { RGBfloat f; f.a=(float)color.a/255; f.r=(float)color.r/255; f.g=(float)color.g/255; f.b=(float)color.b/255; return f; }
+
+	////Converts an int color to RGBint structure
+	inline RGBint ToRGBint(unsigned int argb) { RGBint r(argb); return r; }
+	////Converts an int color to RGBint structure
+	inline RGBint ToRGBint(int argb) { RGBint r(argb); return r; }
+	////Logarithm Base 2
+	inline int log2(int num) {
+		int i=0;
+		int s=1;
+		while(num-s>0) {
+			i++;
+			s<<=1;
+		}
+
+		return i;
+	}
+
+	////Rounds the given number to the lowest 2^n (where n is integer) number that is higher than the given number
+	inline int sl2(int num) {
+		int s=1;
+		while(num-s>0) {
+			s<<=1;
+		}
+
+		return s;
+	}
+
+	////Returns the Bytes required for a given color mode
+	inline int getBPP(ColorMode color_mode) {
+		switch(color_mode) {
+		case GRAYSCALE_8BPP:
+		case PALLETTED_8BPP:
+		case ALPHAONLY_8BPP:
+			return 1;
+		case APALLETTED_16BPP:
+		case AGRAYSCALE_16BPP:
+			return 2;
+		case RGB:
+			return 3;
+		default:
+			return 4;
+		}
+	}
+
+	///This interface defines a class that can be used
+	///as a common drawing target
+	class I2DGraphicsTarget {
+	public:
+		////Draws a simple image to the screen.
+		/// In this draw function every corner can be specified
+		/// thus various transformations can be made
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		///@X1		: top-left corner
+		///@Y1		: top-left corner
+		///@X2		: top-right corner
+		///@Y2		: top-right corner
+		///@X3		: bottom-right corner
+		///@Y3		: bottom-right corner
+		///@X4		: bottom-left corner
+		///@Y4		: bottom-left corner
+		virtual void Draw(GLTexture *Image,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4)=0;
+		////Draws a simple image to the screen.
+		/// This function supports scaling.
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		inline virtual void Draw(GLTexture *Image,int X,int Y,int W,int H) { Draw(Image,X,Y,X+W,Y,X+W,Y+H,X,Y+H); }
+		////Draws a simple image to the screen.
+		/// This function does not support any transformations
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		inline virtual void Draw(GLTexture *Image,int X,int Y) { Draw(Image,X,Y,X+Image->W,Y,X+Image->W,Y+Image->H,X,Y+Image->H); }
+		////Draws a tiled image to the screen
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		virtual void DrawTiled(GLTexture *Image,int X,int Y,int W,int H)=0;
+		////Draws a horizontally tiled image to the screen
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		virtual void DrawHTiled(GLTexture *Image,int X,int Y,int W,int H)=0;
+		////Draws a veritically tiled image to the screen
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		///@W		: the width of the image to be drawn
+		/// if it is more than the size of the image
+		virtual void DrawVTiled(GLTexture *Image,int X,int Y,int W,int H)=0;
+		////Clears drawing buffer, in layer architecture this request only affects
+		/// the layer itself, not sub-layers
+		virtual void Clear()=0;
+	};
+
+	////This is a graphics target with colorization support
+	class I2DColorizableGraphicsTarget : public I2DGraphicsTarget {
+	public:
+		////Global ambient color of this layer
+		RGBint Ambient;
+		////Draws a simple image to the screen.
+		/// In this draw function every corner can be specified
+		/// thus various transformations can be made
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		///@X1		: top-left corner
+		///@Y1		: top-left corner
+		///@X2		: top-right corner
+		///@Y2		: top-right corner
+		///@X3		: bottom-right corner
+		///@Y3		: bottom-right corner
+		///@X4		: bottom-left corner
+		///@Y4		: bottom-left corner
+		virtual void Draw(GLTexture *Image,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4, RGBint Color)=0;
+		////Draws a simple image to the screen.
+		/// This function supports scaling.
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		inline virtual void Draw(GLTexture *Image,int X,int Y,int W,int H, RGBint Color) { Draw(Image,X,Y,X+W,Y,X+W,Y+H,X,Y+H,Color); }
+		////Draws a simple image to the screen.
+		/// This function does not support any transformations
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		inline virtual void Draw(GLTexture *Image,int X,int Y, RGBint Color) { Draw(Image,X,Y,X+Image->W,Y,X+Image->W,Y+Image->H,X,Y+Image->H,Color); }
+	};
+
+	class I2DRawGraphicsTarget {
+	public:
+		////Draws a simple image to the screen.
+		/// In this draw function every corner can be specified
+		/// thus various transformations can be made
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		///@X1		: top-left corner
+		///@Y1		: top-left corner
+		///@X2		: top-right corner
+		///@Y2		: top-right corner
+		///@X3		: bottom-right corner
+		///@Y3		: bottom-right corner
+		///@X4		: bottom-left corner
+		///@Y4		: bottom-left corner
+		virtual void Draw(BYTE *Image, int Width, int Height, ColorMode Mode,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4)=0;
+		////Draws a simple image to the screen.
+		/// This function supports scaling.
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		_inline virtual void Draw(BYTE *Image, int Width, int Height, ColorMode Mode,int X,int Y,int W,int H) { Draw(Image,Width,Height,Mode,X,Y,X+W,Y,X+W,Y+H,X,Y+H); }
+		////Draws a simple image to the screen.
+		/// This function does not support any transformations
+		///@Image	: image texture to be drawn, this can be obtained
+		/// using generate texture function
+		_inline virtual void Draw(BYTE *Image, int Width, int Height, ColorMode Mode,int X,int Y) { Draw(Image,Width,Height,Mode,X,Y,X+Width,Y,X+Width,Y+Height,X,Y+Height); }
+	};
+	////This is a basic drawing object
+	class Buffered2DGraphic {
+	public:
+		GLTexture Texture;
+
+		Buffered2DGraphic() { Texture.ID=0; }
+
+		////Draws this object to the given target
+		///@Target	: The target that will be used to draw
+		/// this image
+		virtual void Draw(I2DGraphicsTarget *Target,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) { 
+			Draw(Target, pnt.x, pnt.y, Texture.W, Texture.H);
+		}
+		virtual void Draw(I2DGraphicsTarget *Target,int X,int Y) { 
+			Draw(Target, X, Y, Texture.W, Texture.H);
+		}
+		virtual void Draw(I2DGraphicsTarget &Target,int X,int Y) { Draw(&Target, X,Y); }
+
+
+		////Draws this object to the given target with the specified size
+		///@Target	: The target that will be used to draw
+		/// this image
+		virtual void Draw(I2DGraphicsTarget *Target,int X,int Y,int W,int H) { 
+#ifdef _DEBUG
+			if(Texture.ID==0) {
+				DisplayMessage("Buffered 2D Graphic","Invalid texture ID, image is not initialized.");
+				assert(0);
+			}
+#endif
+			Target->Draw(&Texture, X, Y, W, H);
+		}
+		virtual void Draw(I2DGraphicsTarget &Target,int X,int Y,int W,int H) { Draw(&Target, X,Y, W,H); }
+
+
+		////Draws this object to the given target with the specified size
+		///@Target	: The target that will be used to draw
+		/// this image
+		virtual void Draw(I2DGraphicsTarget *Target,int X1,int Y1, int X2,int Y2, int X3,int Y3, int X4, int Y4) { 
+#ifdef _DEBUG
+			if(Texture.ID==0) {
+				DisplayMessage("Buffered 2D Graphic","Invalid texture ID, image is not initialized.");
+				assert(0);
+			}
+#endif
+			Target->Draw(&Texture, X1,Y1, X2,Y2, X3,Y3, X4,Y4);
+		}
+		virtual void Draw(I2DGraphicsTarget &Target,int X1,int Y1, int X2,int Y2, int X3,int Y3, int X4, int Y4) { Draw(&Target, X1,Y1, X2,Y2, X3,Y3, X4,Y4); }
+
+
+		virtual void DrawTiled(I2DGraphicsTarget *Target,int X,int Y, int W, int H) { 
+#ifdef _DEBUG
+			if(Texture.ID==0) {
+				DisplayMessage("Buffered 2D Graphic","Invalid texture ID, image is not initialized in tiled draw.");
+				assert(0);
+			}
+#endif
+			Target->DrawTiled(&Texture,X,Y,W,H);
+		}
+		virtual void DrawTiled(I2DGraphicsTarget &Target,int X,int Y, int W, int H) { DrawTiled(&Target, X,Y, W,H); }
+
+
+		virtual void DrawHTiled(I2DGraphicsTarget *Target,int X,int Y, int W, int H) { 
+#ifdef _DEBUG
+			if(Texture.ID==0) {
+				DisplayMessage("Buffered 2D Graphic","Invalid texture ID, image is not initialized in tiled draw.");
+				assert(0);
+			}
+#endif
+			Target->DrawHTiled(&Texture,X,Y,W,H);
+		}
+		virtual void DrawHTiled(I2DGraphicsTarget &Target,int X,int Y, int W, int H) { DrawHTiled(&Target, X,Y, W,H); }
+
+
+		virtual void DrawVTiled(I2DGraphicsTarget *Target,int X,int Y, int W, int H) { 
+#ifdef _DEBUG
+			if(Texture.ID==0) {
+				DisplayMessage("Buffered 2D Graphic","Invalid texture ID, image is not initialized in tiled draw.");
+				assert(0);
+			}
+#endif
+			Target->DrawVTiled(&Texture,X,Y,W,H);
+		}
+		virtual void DrawVTiled(I2DGraphicsTarget &Target,int X,int Y, int W, int H) { DrawVTiled(Target, X,Y, W,H); }
+	};
+
+
+	////This is a graphics object with colorization support
+	class Colorizable2DGraphic : public Buffered2DGraphic {
+	public:
+		virtual void DrawColored(I2DColorizableGraphicsTarget *Target,int X,int Y,RGBint Color) { 
+#ifdef _DEBUG
+			if(Texture.ID==0) {
+				DisplayMessage("Colorizable 2D Graphic","Invalid texture ID, image is not initialized.");
+				assert(0);
+			}
+#endif
+			Target->Draw(&Texture, X, Y, Color);
+		}
+		virtual void DrawColored(I2DColorizableGraphicsTarget &Target,int X,int Y,RGBint Color) { DrawColored(&Target, X,Y, Color); }
+
+		inline void DrawColored(I2DColorizableGraphicsTarget *Target,int X,int Y,unsigned int Color) { DrawColored(Target,X,Y,ToRGBint(Color)); }
+	};
+
+	////This is a basic drawing object
+	class Raw2DGraphic {
+	public:
+		ManagedBuffer<BYTE> Data;
+		int Width;
+		int Height;
+		ColorMode Mode;
+
+		Raw2DGraphic() { Width=0; Height=0; Mode=ARGB_32BPP; }
+		Raw2DGraphic(Raw2DGraphic &graph) {
+			Data=graph.Data;
+			Width=graph.Width;
+			Height=graph.Height;
+			Mode=graph.Mode;
+			
+			Data++;
+		}
+
+		////Draws this object to the given target
+		///@Target	: The target that will be used to draw
+		/// this image
+		virtual void DrawRaw(I2DRawGraphicsTarget *Target,int X,int Y) { 
+#ifdef _DEBUG
+			if(Data.GetSize()==0) {
+				DisplayMessage("Raw 2D Graphic","Empty data, image is not initialized.");
+				assert(0);
+			}
+#endif
+			Target->Draw(Data, Width, Height, Mode, X, Y);
+		}
+
+		virtual void DrawRaw(I2DRawGraphicsTarget *Target,int X,int Y, int W, int H) { 
+#ifdef _DEBUG
+			if(Data==NULL) {
+				DisplayMessage("Raw 2D Graphic","Empty data, image is not initialized.");
+				assert(0);
+			}
+#endif
+			Target->Draw(Data, Width, Height, Mode, X, Y, W, H);
+		}
+
+		virtual void DrawRaw(I2DRawGraphicsTarget *Target,int X1,int Y1,int X2,int Y2,int X3,int Y3,int X4,int Y4) {
+#ifdef _DEBUG
+			if(Data==NULL) {
+				DisplayMessage("Raw 2D Graphic","Empty data, image is not initialized.");
+				assert(0);
+			}
+#endif
+			Target->Draw(Data, Width, Height, Mode, X1, Y1, X2, Y2, X3, Y3, X4, Y4);
+		}
+
+		virtual void DrawRawFlipped(I2DRawGraphicsTarget *Target,int X,int Y) { 
+#ifdef _DEBUG
+			if(Data==NULL) {
+				DisplayMessage("Raw 2D Graphic","Empty data, image is not initialized.");
+				assert(0);
+			}
+#endif
+			Target->Draw(Data, Width, Height, Mode, X, Y+Height, X+Width, Y+Height, X+Width, Y, X, Y);
+		}
+
+		virtual void DrawRawFlipped(I2DRawGraphicsTarget *Target,int X,int Y, int W, int H) { 
+#ifdef _DEBUG
+			if(Data==NULL) {
+				DisplayMessage("Raw 2D Graphic","Empty data, image is not initialized.");
+				assert(0);
+			}
+#endif
+			Target->Draw(Data, Width, Height, Mode, X, Y+H, X+W, Y+H, X+W, Y, X, Y);
+		}
+
+		virtual void Resize(int Width, int Height, ColorMode Mode) {
+			int bits=getBPP(Mode);
+
+			Data.Resize(Width*Height*bits);
+
+			this->Width=Width;
+			this->Height=Height;
+			this->Mode=Mode;
+		}
+
+		~Raw2DGraphic() {  }
+	};
+
+
+
+	////Finds integer log of base 2
+	inline int log2(int num);
+	////Finds nearest 2^n value that is larger than num
+	inline int sl2(int num);
+	////Initializes OpenGL graphics with the given parameters,
+	/// returns created device context
+	///@hWnd		: Handle for the target window
+	///@BitDepth	: Used if fullscreen, changed bitdepth of screen
+	DeviceHandle InitializeGraphics(WindowHandle hWnd, int BitDepth, int Width, int Height);
+	////Creates rectangle structure based on give parameters
+	//RECT makerect(int x, int y, int w, int h);
+	////Converts Alpha only image to Alpha and Luminance (grayscale) image.
+	/// Destination array should be allocated. This algorithm is optimized
+	/// for speed.
+	///@Source		: Source data array, no justification is needed,
+	///               should be 1 byte/pix
+	///@Destination	: Destination data array, data is copied without
+	///               any justification, should be allocated for 2 byte/pix
+	void A8ToA8L8(int Width, int Height, BYTE *Source, BYTE *Destination);
+	////This function sets the current texture to given data
+	void SetTexture(BYTE *data, int cx, int cy, ColorMode mode);
+	////This function creates a texture from the given data and
+	/// returns texture information in a structure
+	///@Image		: Image data
+	///@Mode		: Color mode
+	GLTexture GenerateTexture(BYTE *Image,int Width,int Height,ColorMode Mode);
+	void DestroyTexture(GLTexture *texture);
+	////Returns equivalent OpenGL color mode constant
+	///@Mode		: GGE color mode constant
+	GLenum getGLColorMode(ColorMode Mode);
+	////Returns required bytes per pixel for a given color mode
+	int getBPP(ColorMode Mode);
+	////Cleans render buffer and prepares for rendering
+	void PreRender();
+	////Performs post render tasks
+	///@hDC			: Device context that is created by
+	/// initialize graphics function
+	void PostRender(DeviceHandle Device);
+
+	extern Point ScreenSize;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Input.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,426 @@
+#include "Input.h"
+
+using namespace gge;
+
+namespace gge {
+
+	bool isAlternateKey=false;
+
+	KeyboardModifier KeyboardModifiers;
+	Collection<KeyboardEventObject> KeyboardEventObjects;
+	LinkedList<BasicPointerTarget> PointerTargets;
+	MouseEventObject *hoveredObject=NULL;
+	MouseEventObject *pressedObject=NULL;
+	MouseEventType MouseButtons=MOUSE_EVENT_NONE;
+
+	bool hoverfound=false;
+
+	void InitializeInput() {
+		KeyboardModifiers=KEYB_MOD_NONE;
+	}
+
+	LinkedListItem<BasicPointerTarget> *AddPointerTarget(BasicPointerTarget *target, int order) {
+		return PointerTargets.AddItem(target,order);
+	}
+
+	void RemovePointerTarget(LinkedListItem<BasicPointerTarget> * target) {
+		PointerTargets.Remove(target);
+	}
+
+	////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;
+
+		while(target=it) {
+			if(target->PropagateMouseEvent(event, x, y, NULL))
+				break;
+		}
+	}
+
+	////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;
+
+		while(target=it) {
+			if(target->PropagateMouseScrollEvent(amount, event, x, y, NULL))
+				break;
+		}
+	}
+	
+	void ProcessMousePosition(WindowHandle Window) {
+		Point pnt;
+		pnt=getMousePosition(Window);
+
+		int x=pnt.x;
+		int y=pnt.y;
+
+		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;
+		}
+	}
+
+	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;
+
+
+		propagateevent(event, x, y);
+		pressedObject=NULL;
+	}
+
+	void ProcessMouseDown(int button,int x,int y) {
+
+		MouseButtons=(MouseEventType)(MouseButtons | button);
+
+		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;
+
+		propagateevent(event, x, y);
+	}
+
+	void ProcessMouseUp(int button,int x,int y){
+
+		MouseButtons=(MouseEventType)(MouseButtons & ~button);
+
+		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);
+	}
+
+	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);
+	}
+
+	void ProcessVScroll(int amount,int x,int y){
+
+		propagatescrollevent(amount, MOUSE_EVENT_VSCROLLL, x, y);
+	}
+
+	void ProcessHScroll(int amount,int x,int y){
+
+		propagatescrollevent(amount, MOUSE_EVENT_HSCROLLL, x, y);
+	}
+
+	int	 RegisterKeyboardEvent(void *data,KeyboardEvent Char,KeyboardEvent Down,KeyboardEvent Up,bool Modified) {
+		KeyboardEventObject *obj=new KeyboardEventObject;
+		
+		obj->data=data;
+		obj->chr=Char;
+		obj->down=Down;
+		obj->up=Up;
+		obj->id=KeyboardEventObjects.Add(obj);
+		obj->Modified=Modified;
+		obj->Enabled=true;
+
+
+		return obj->id;
+	}
+
+	void UnregisterKeyboardEvent(int id) {
+		KeyboardEventObjects.Remove(id);
+	}
+
+	void ProcessChar(int Char) {
+		KeyboardEventObject *kevent;
+		KeyboardEventObjects.ResetIteration(true);
+		while(kevent=KeyboardEventObjects.previous()) {
+			if(kevent->Enabled && kevent->chr && (!CheckModifier(KeyboardModifiers) || kevent->Modified))
+				if(kevent->chr(KEYB_EVENT_CHR, Char, KeyboardModifiers, kevent->data))
+					return;
+		}
+	}
+
+	void ProcessKeyDown(int Key) {
+		KeyboardEventObject *kevent;
+		KeyboardEventObjects.ResetIteration(true);
+		while(kevent=KeyboardEventObjects.previous()) {
+			if(kevent->Enabled && kevent->down && (!CheckModifier(KeyboardModifiers) || kevent->Modified))
+				if(kevent->down(KEYB_EVENT_DOWN, Key, KeyboardModifiers, kevent->data))
+					return;
+		}
+	}
+
+	void ProcessKeyUp(int Key) {
+		KeyboardEventObject *kevent;
+		KeyboardEventObjects.ResetIteration(true);
+		while(kevent=KeyboardEventObjects.previous()) {
+			if(kevent->Enabled && kevent->up && (!CheckModifier(KeyboardModifiers) || kevent->Modified))
+				if(kevent->up(KEYB_EVENT_UP, Key, KeyboardModifiers, kevent->data))
+					return;
+		}
+	}
+
+	void EnableKeyboardEvent(int id) {
+		KeyboardEventObjects[id]->Enabled=true;
+	}
+
+	void DisableKeyboardEvent(int id) {
+		KeyboardEventObjects[id]->Enabled=false;
+	}
+	
+	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;
+
+				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;
+	}
+
+	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.Remove(token);
+	}
+
+	bool BasicPointerTarget::PropagateMouseClickEvent(MouseEventType event, int x, int y, void *data) {
+		bool ret=false;
+
+		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;
+				}
+			}
+		}
+
+		return ret;
+	}
+
+	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;				
+				}
+			}
+		}
+
+		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 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;				
+			}
+		}
+
+		return false;
+	}
+
+	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;				
+			}
+		}
+
+		return false;
+	}
+
+	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;				
+			}
+		}
+
+		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;
+				}
+			}
+		}
+
+		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;				
+			}
+		}
+
+		return false;
+	}
+
+	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(MouseEventType::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);
+
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Input.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,380 @@
+#pragma once
+
+#include "../Utils/LinkedList.h"
+#include "../Utils/Collection.h"
+#include "../Utils/GGE.h"
+#include "OS.h"
+#include "../Utils/Utils.h"
+
+namespace gge {
+	class BasicPointerTarget;
+	////Types of keyboard modifiers
+	enum KeyboardModifier {
+		////No modifier
+		KEYB_MOD_NONE=0,
+		////Shift key is pressed
+		KEYB_MOD_SHIFT=1,
+		////Control key is pressed
+		KEYB_MOD_CTRL=2,
+		////Shift and control keys are presses
+		KEYB_MOD_SHIFT_CTRL=3,
+		////Alt key is pressed
+		KEYB_MOD_ALT=4,
+		////Shift and alt keys are pressed
+		KEYB_MOD_SHIFT_ALT=5,
+		////Control and alt keys are pressed
+		KEYB_MOD_CTRL_ALT=6,
+		////Shift control and alt keys are pressed
+		KEYB_MOD_SHIFT_CTRL_ALT=7,
+		////Windows / Super key is pressed
+		KEYB_MOD_WIN=8,
+		////Menu key is pressed
+		KEYB_MOD_MENU=16,
+		////This flag is set when alternate version of
+		/// the key is pressed, alternative keys should
+		/// not be relied since not all keyboards have them
+		/// this is no longer used, check isAlternateKey
+		/// variable
+		KEYB_MOD_ALTERNATIVE=32,
+		//KEYB_MOD_RIGHTSHIFT=33 ...
+	};
+
+	////Whether pressed key is an alternate key (e.g. numpad or right shift)
+	extern bool isAlternateKey;
+
+	////Types of mouse event
+	enum MouseEventType {
+		MOUSE_EVENT_NONE=0,
+		MOUSE_EVENT_LEFT=1,
+		MOUSE_EVENT_RIGHT=2,
+		MOUSE_EVENT_MIDDLE=4,
+
+		MOUSE_EVENT_CLICK=0,
+		////Left click
+		MOUSE_EVENT_LCLICK=1,
+		////Right click
+		MOUSE_EVENT_RCLICK=2,
+		////Middle click
+		MOUSE_EVENT_MCLICK=4,
+
+		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,
+
+		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,
+
+		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,
+
+		////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 recieved
+		MOUSE_EVENT_OVER_CHECK,
+
+		////Verticle 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,
+
+		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,
+		
+	};
+
+	////Types of keyboard events
+	enum KeyboardEventType {
+		////A character is typed (O/S controlled, i.e. repeating keys)
+		KEYB_EVENT_CHR,
+		////A key is pressed
+		KEYB_EVENT_DOWN,
+		////A key is released
+		KEYB_EVENT_UP
+	};
+
+	struct MouseEventObject;
+	////Token given by registering a mouse event
+	typedef	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);
+	////Defines how a keyboard event handling functoin should be
+	typedef bool (*KeyboardEvent)(KeyboardEventType event, int keycode, KeyboardModifier modifier, void *data);
+
+	////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;
+		////Verticle 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;
+	};
+
+	////Keyboard event objects are internally used to track keyboard event handlers
+	struct KeyboardEventObject {
+		////This is the event handler that is fired when a char is typed
+		/// either by pressing a key or pressing a key and holding it to repeat
+		KeyboardEvent chr;
+		////This event handler is called when a key is pressed
+		KeyboardEvent down;
+		////This event handler is called when a key is released
+		KeyboardEvent up;
+		////ID of the keyboard event, can be used to enable/disable/cancel this
+		/// event set
+		int id;
+		////Any data that is left to be passed to event handlers
+		void *data;
+		////Whether these events accept modified keys (i.e. when a modifier is set)
+		bool Modified;
+		////Whether this 
+		bool Enabled;
+	};
+	
+	////Registers a keyboard event handler object, event handler function should be in this format:
+	/// bool (KeyboardEventType event, int keycode, KeyboardModifier modifier, void *data)
+	/// and should return true if the key is processed or blocked and false if the key should be passed
+	/// to next event object
+	///@data	: the data to be passed to handlers
+	///@Char	: This is the event handler that is fired when a char is typed
+	/// either by pressing a key or pressing a key and holding it to repeat
+	///@Down	: This event handler is called when a key is pressed
+	///@Up		: This event handler is called when a key is released
+	int	  RegisterKeyboardEvent(void *data,KeyboardEvent Char,KeyboardEvent Down=NULL,KeyboardEvent Up=NULL,bool AllowModified=false);
+	////Unregisters a keyboard event object
+	///@id		: the identifier returned by RegisterKeyboardEvent function
+	void  UnregisterKeyboardEvent(int id);
+	////Disables a keyboard event, unlike unregister this state is not permanent
+	void  DisableKeyboardEvent(int Index);
+	////Enables a keyboard event
+	void  EnableKeyboardEvent (int Index);
+
+
+	////Processes a given char, this function intended to be called from OS
+	/// sub-system, however a knowledgable attempt to call from elsewhere is
+	/// also valid
+	///@Char	: Character code (8bit ASCII or equivalent (ISO-8859))
+	void ProcessChar(int Char);
+	////Processes a given key as pressed, this function intended to be called from OS
+	/// sub-system, however a knowledgable attempt to call from elsewhere is
+	/// also valid
+	///@Key		: The keyboard code of the pressed key
+	void ProcessKeyDown(int Key);
+	////Processes a given key as released, this function intended to be called from OS
+	/// sub-system, however a knowledgable attempt to call from elsewhere is
+	/// also valid
+	///@Key		: The keyboard code of the pressed key
+	void ProcessKeyUp(int Key);
+
+	////Processes the current mouse position this information is taken from OS subsystem
+	void ProcessMousePosition(WindowHandle Window);
+	////Processes click of mouse button
+	///@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
+	void ProcessMouseDown(int button,int x,int y);
+	////Processes given mouse button as released
+	///@button	: button number 1 for left, 2 for right and 4 for middle
+	void ProcessMouseUp(int button,int x,int y);
+	////Processes double click action
+	///@button	: button number 1 for left, 2 for right and 4 for middle
+	void ProcessMouseDblClick(int button,int x,int y);
+	////Processes verticle scroll
+	void ProcessVScroll(int amount,int x,int y);
+	////Processes horizontal scroll
+	void ProcessHScroll(int amount,int x,int y);
+
+	////This interface defines a class that can be used
+	/// as a common target of mouse events
+	class BasicPointerTarget {
+	public:
+		////The array of mouse events
+		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 verticle 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);
+
+	};
+
+	////Bitwise OR operation on KeyboardModifier enumeration
+	inline KeyboardModifier operator | (KeyboardModifier m1, KeyboardModifier m2) {
+		return (KeyboardModifier)((int)m1|(int)m2);
+	}
+
+	////Bitwise AND operation on KeyboardModifier enumeration
+	inline KeyboardModifier operator & (KeyboardModifier m1, KeyboardModifier m2) {
+		return (KeyboardModifier)((int)m1&(int)m2);
+	}
+
+	////Bitwise EQUAL OR operation on KeyboardModifier enumeration
+	inline KeyboardModifier operator |= (KeyboardModifier m1, KeyboardModifier m2) {
+		return (KeyboardModifier)((int)m1|(int)m2);
+	}
+
+	////Bitwise EQUAL AND operation on KeyboardModifier enumeration
+	inline KeyboardModifier operator &= (KeyboardModifier m1, KeyboardModifier m2) {
+		return (KeyboardModifier)((int)m1&(int)m2);
+	}
+
+
+	////Checks the the current state of the keyboard if there are any real modifiers
+	/// in effect (Namely control, alt, and windows keys)
+	inline bool CheckModifier(KeyboardModifier m1) {
+		return m1&KEYB_MOD_CTRL || m1&KEYB_MOD_ALT || m1&KEYB_MOD_WIN;
+	}
+
+
+	////This function can be used internally to remove the second keyboard modifier
+	/// from the first one
+	inline void RemoveModifier(KeyboardModifier &m1,KeyboardModifier m2) {
+		m1=m1&(KeyboardModifier)(~m2);
+	}
+	////This function add a keyboard modifier to another one
+	inline void AddModifier(KeyboardModifier &m1,KeyboardModifier m2) {
+		m1=m1|m2;
+	}
+
+	extern KeyboardModifier KeyboardModifiers;
+	extern MouseEventType MouseButtons;
+	extern Collection<KeyboardEventObject> KeyboardEventObjects;
+	////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
+	LinkedListItem<BasicPointerTarget> * AddPointerTarget(BasicPointerTarget *target, int order);
+	////Removes a previously registered pointer target
+	void RemovePointerTarget(LinkedListItem<BasicPointerTarget> *target);
+	////Initializes Input system
+	void InitializeInput();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Layer.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,74 @@
+#include "Layer.h"
+
+namespace gge {
+	extern int trX,trY;
+	extern MouseEventObject *pressedObject;
+
+	bool InputLayer::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)) ) {
+			if(LayerBase::PropagateMouseEvent(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::PropagateMouseEvent(event, x-X, y-Y, data);
+			else
+				return false;
+		}
+
+		return false;
+	}
+
+	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))
+					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;
+		if(isVisible) {
+			LinkedListOrderedIterator<LayerBase> it=SubLayers.GetReverseOrderedIterator();
+			LayerBase *layer;
+			
+			while(layer=it)
+				layer->Render();
+		}
+		trX-=X;
+		trY-=Y;
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Layer.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,80 @@
+#pragma once
+
+#include "../Utils/Collection.h"
+#include "../Utils/LinkedList.h"
+#include "Input.h"
+
+namespace gge {
+	////This class is the base class for all layer types.
+	/// All common methods are implemented with a common way.
+	/// This class always implements basic processing functions.
+	/// Derived classes can override them. Unless overriden these
+	/// basic functions only propagate the call.
+	class LayerBase {
+	public:
+		////Whether this layer is visible, invisible layers will not
+		/// be drawn or receive any events
+		bool isVisible;
+		////Sub-layers that this layer holds, all the sub-layers are
+		/// considered to be above current layer
+		LinkedList<LayerBase> SubLayers;
+
+		////Parent layer
+		LayerBase *parent;
+		////Main class for GGE
+		//GGEMain *main;
+
+		LayerBase() : parent(NULL) { }
+
+		virtual LayerBase *Add(LayerBase *layer, int Order=0) { layer->parent=this; SubLayers.AddItem(layer, (float)Order); return layer; }
+		virtual LayerBase &Add(LayerBase &layer, int Order=0) { layer.parent=this; SubLayers.AddItem(&layer, (float)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;
+		////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((float)Order);
+		}
+
+		void OrderToTop() {
+			if(parent)
+				parent->SubLayers.FindListItem(this)->setOrder(parent->SubLayers.LowestOrder()-1);
+		}
+
+		int getOrder() { 
+			if(parent)
+				return (int)parent->SubLayers.FindListItem(this)->getOrder(); 
+			else
+				return 0;
+		}
+
+	protected:
+		////Processes the mouse event for the current layer, default
+		/// handling is to pass the request to the sub-layers
+		virtual bool PropagateMouseEvent(MouseEventType event, int x, int y, void *data);
+		virtual bool PropagateMouseScrollEvent(int amount, MouseEventType event, int x, int y, void *data);
+	};
+
+	class InputLayer : public LayerBase, public BasicPointerTarget {
+	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(MouseEventType event, int x, int y, void *data);
+		virtual bool PropagateMouseScrollEvent(int amount, MouseEventType event, int x, int y, void *data);
+	};
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Multimedia.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,66 @@
+#include "Multimedia.h"
+
+namespace gge {
+	void Multimedia::ProcessMsg() {
+		// Make sure that we don't access the media event interface
+		// after it has already been released.
+		if (!pME || isDestroyed)
+			return;
+
+		// Process all queued events
+	    LONG evCode, evParam1, evParam2;
+		while(pME->GetEvent(&evCode, (LONG_PTR *) &evParam1,(LONG_PTR *) &evParam2, 0)==0)
+		{
+			pME->FreeEventParams(evCode, evParam1, evParam2);
+			if(EC_COMPLETE == evCode) {
+				Finished();
+
+				if(AutoDestroy)
+					_destroy();
+
+				return;
+			}
+		}
+	}
+
+	void Multimedia::_destroy() {
+		isDestroyed=true;
+		pGB->Abort();
+		pME->SetNotifyWindow((int)main->getWindow(), WM_VIDEO_NOTIFY, NULL);
+		pControl->Release();
+		pME->Release();
+		pVW->Release();
+		pGB->Release();
+		
+		pME=NULL;
+		pVW=NULL;
+		pGB=NULL;
+
+		delete pGB;
+		
+		UpdateWindow((HWND)main->getWindow());
+	}
+
+	Multimedia::Multimedia(GGEMain *main) :
+		Finished("Finished", this),
+		isDestroyed(false),
+		main(main),
+		Width(main->getWidth()),
+		Height(main->getHeight()),
+		X(0), Y(0), AutoDestroy(true)
+	{
+		int hr=CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,IID_IGraphBuilder, (void **)&pGB);
+		hr = pGB->QueryInterface(IID_IMediaControl, (void **)&pControl);
+		pGB->QueryInterface(IID_IMediaEventEx, (void **)&pME);
+		pGB->QueryInterface(IID_IVideoWindow, (void **)&pVW);
+	}
+
+	void Multimedia::Loadfile(wchar_t *Filename) {
+		pGB->RenderFile(Filename, NULL);
+
+		pVW->put_Owner((int)main->getWindow());
+		pVW->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
+		pVW->SetWindowPosition(X, Y, Width, Height);
+		pME->SetNotifyWindow((int)main->getWindow(), WM_VIDEO_NOTIFY,(int)this);
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Multimedia.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,56 @@
+#pragma once
+
+
+#include "GGEMain.h"
+#include <dshow.h>
+#include <atlbase.h>
+#include "../Utils/Any.h"
+#include "../Utils/EventChain.h"
+
+namespace gge {
+	////This class provides multimedia support, video or music files can be
+	/// loaded and played with this.
+	class Multimedia {
+		IGraphBuilder *pGB;
+		IVideoWindow  *pVW;
+		IMediaEventEx *pME;
+		IMediaControl *pControl;
+		void _destroy();
+
+	public:
+		////Width of the video area, auto set to fill the screen
+		int Width;
+		////Height of the video area, auto set to fill the screen
+		int Height;
+		////X of the video area
+		int X;
+		////Y of the video area
+		int Y;
+		////Processes messages coming from the Multimedia subsystem
+		void ProcessMsg();
+		////Plays the media
+		void Play() { pControl->Run(); }
+		////Pauses the media
+		void Pause() { pControl->Pause(); }
+		////Stops the media. Even if AutoDestroy is set, stop will not trigger destruction
+		void Stop() { pControl->Stop(); }
+		////Loads a given file
+		void Loadfile(wchar_t *Filename);
+		////Main object
+		GGEMain *main;
+		////Whether this object is destroyed. A destroyed object can be restored by reloading
+		/// media file
+		bool isDestroyed;
+		////Whether to destroy this object when playback is finished. Default value is true
+		bool AutoDestroy;
+		////Destroys the current object. All calls to play/pause/stop will fail after the object 
+		/// is destroyed
+		void Destroy() { _destroy(); }
+
+		////Initializes the object
+		Multimedia(GGEMain *main);
+
+		////Fired when playback is finished, occurs before auto destroy if it is set.
+		EventChain<Multimedia, empty_event_params> Finished;
+	};
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/OS.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,76 @@
+#pragma once
+
+#include "../Utils/GGE.h"
+#include "../Utils/Any.h"
+#include "../Utils/EventChain.h"
+
+#ifdef WIN32
+#ifdef __cplusplus
+extern "C" {            /* Assume C declarations for C++ */
+#endif  /* __cplusplus */
+	__declspec(dllimport) unsigned long __stdcall timeGetTime(void);
+#ifdef __cplusplus
+}                       /* End of extern "C" { */
+#endif  /* __cplusplus */
+#endif
+
+namespace gge {
+
+#ifdef WIN32
+
+#define WM_USER                         0x0400
+	////Handle for window
+	typedef unsigned long	WindowHandle;
+	////Handle for icon
+	typedef unsigned long	IconHandle;
+	////Handle for application instance
+	typedef unsigned long	InstanceHandle;
+	////Handle for cursor
+	typedef unsigned long	CursorHandle;
+	////Handle for Device Context
+	typedef unsigned long	DeviceHandle;
+
+	////Window message to process video operation
+	#define WM_VIDEO_NOTIFY  WM_USER+3
+
+	////This function returns the current time
+	inline unsigned int GetTime() { return timeGetTime(); }
+#else
+#endif
+
+	extern CursorHandle defaultcursor;
+	extern bool ospointerdisplayed;
+
+	////This function creates a window
+	///@Name		: Identifier name for the window, should abide by variable naming rules
+	///@Title		: Title of the window
+	///@Icon		: The icon to be used, depends on OS
+	///@Instance	: The handle for the application instance
+	///@Left		: Distance of the window from the left of the screen
+	///@Top			: Distance of the window from the top of the screen
+	///@Width		: The width of the window
+	///@Height		: The height of the window
+	///@FullScreen	: Whether to create a fullscreen window
+	WindowHandle CreateWin(const char *Name, const char *Title, IconHandle Icon, InstanceHandle Instance, int Left, int Top, int Width, int Height, int BitDepth, bool &FullScreen);
+	////This function shows a OS message box to display errors, for other messages
+	/// its better to use in-game dialogs
+	void DisplayMessage(char *Title, char *Text);
+	////Hides the pointer displayed by OS
+	void HideOSPointer();
+	////Shows the pointer displayed by OS
+	void ShowOSPointer();
+	////Quits the application while returning the given code, if no errors exists
+	/// return value should be 0, other return codes should be arranged by application
+	void Quit(int ret);
+	////Gets the position of the cursor
+	Point getMousePosition(WindowHandle Window);
+	////This function processes OS messages
+	void ProcessMessage();
+	////Initializes OS subsystem by setting up events
+	void InitializeOS();
+
+	extern EventChain<Empty, empty_event_params> WindowActivateEvent;
+	extern EventChain<Empty, empty_event_params> WindowDeactivateEvent;
+	extern EventChain<Empty, empty_event_params> WindowDestroyedEvent;
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Pointer.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,142 @@
+#include "Pointer.h"
+#include "../Utils/Collection.h"
+#include "../Utils/LinkedList.h"
+#include "GraphicLayers.h"
+#include "GGEMain.h"
+#include "../Resource/FolderResource.h"
+#include "../Resource/GRE.h"
+#include "OS.h"
+
+namespace gge {
+	Collection<Pointer> Pointers;
+	LinkedList<Pointer> ActivePointers;
+	Basic2DLayer *PointerLayer=NULL;
+	Pointer *BasePointer=NULL;
+	bool PointerVisible=false;
+	bool OSPointerVisible=true;
+
+	void Pointer_Window_Activate(empty_event_params p, Empty &caller, Any data, string eventname) {
+		ShowPointer();
+	}
+
+	void Pointer_Window_Deactivate(empty_event_params p, Empty &caller, Any data, string eventname) {
+		HidePointer();
+	}
+
+	void Pointer_Draw(empty_event_params p, GGEMain &caller, Any data, string eventname) {
+		if(!BasePointer || !PointerVisible)
+			return;
+
+		Point pnt;
+		pnt=getMousePosition(caller.getWindow());
+
+		PointerLayer->Clear();
+
+		if(pnt.x<0 || pnt.y<0 || pnt.x>caller.getWidth() || pnt.y>caller.getHeight()) {
+			ShowOSPointer();
+			OSPointerVisible=true;
+			return;
+		} else if(OSPointerVisible) {
+			OSPointerVisible=false;
+			HideOSPointer();
+		}
+
+		Pointer *pointer=ActivePointers.getOrderedLastItem();
+		if(pointer==NULL)
+			pointer=BasePointer;
+
+		int x,y;
+
+		x=pnt.x-pointer->HotspotX;
+		y=pnt.y-pointer->HotspotY;
+
+		pointer->Image->Draw(PointerLayer, x, y);
+	}
+
+	void InitializePointer(GGEMain *Main) {
+		PointerLayer=(Basic2DLayer*)Main->Add( new Basic2DLayer(0, 0, Main->getWidth(), Main->getHeight()) , -100 );
+
+		WindowActivateEvent.Register(Pointer_Window_Activate);
+		WindowDeactivateEvent.Register(Pointer_Window_Deactivate);
+
+		Main->BeforeRenderEvent.Register(Pointer_Draw);
+
+		HideOSPointer();
+		PointerLayer->isVisible=false;
+	}
+
+	void FetchPointers(FolderResource *Folder) {
+		DataResource *data=Folder->asData(0);
+		
+		LinkedListIterator<ResourceBase> it=Folder->Subitems;
+		ResourceBase *resource;
+		resource=it;
+
+		int i=0;
+		while(resource=it) {
+			if(resource->getGID()==GID_ANIMATION) {
+				AnimationResource *anim=(AnimationResource *)resource;
+				Pointers.Add( new Pointer(anim->getAnimation(), data->getPoint(i+1).x, data->getPoint(i+1).y, (PointerTypes)data->getInt(i)) );
+			} else if(resource->getGID()==GID_IMAGE) {
+				ImageResource *img=(ImageResource *)resource;
+				Pointers.Add( new Pointer(img, data->getPoint(i+1).x, data->getPoint(i+1).y, (PointerTypes)data->getInt(i)) );
+			}
+
+			i+=2;
+		}
+
+		if(i>0)
+			BasePointer=Pointers[0];
+	}
+
+	Pointer *AddPointer(Buffered2DGraphic *pointer, Point Hotspot, PointerTypes Type) {
+		Pointer *ret=new Pointer(pointer, Hotspot.x, Hotspot.y, Type);
+		Pointers.Add( ret );
+		return ret;
+	}
+
+	void RemovePointer(Pointer *Pointer) {
+		Pointers.Remove(Pointer);
+	}
+
+	int SetPointer(Pointer *Pointer) {
+		return (int)ActivePointers.AddItem(Pointer, ActivePointers.HighestOrder()+1);
+	}
+
+	int SetPointer(PointerTypes Type) {
+		if(Type==PointerTypes::None)
+			return SetPointer(BasePointer);
+		Pointers.ResetIteration();
+		Pointer *pointer;
+		while(pointer=Pointers.next()) {
+			if(pointer->Type==Type)
+				return SetPointer(pointer);
+		}
+
+		return SetPointer(BasePointer);
+	}
+
+	void ResetPointer(int StackNo) {
+		ActivePointers.Remove((LinkedListItem<Pointer>*)StackNo);
+	}
+
+	void ChangeBasePointer(Pointer *Pointer) {
+		BasePointer=Pointer;
+	}
+
+	void ShowPointer() {
+		PointerVisible=true;
+		HideOSPointer();
+		HideOSPointer();
+		HideOSPointer();
+
+		PointerLayer->isVisible=true;
+	}
+
+	void HidePointer() {
+		PointerVisible=false;
+
+		PointerLayer->isVisible=false;
+	}
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Pointer.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,81 @@
+#pragma once
+
+#include "../Utils/GGE.h"
+#include "Graphics.h"
+
+namespace gre { class FolderResource; }
+
+using namespace gre;
+
+namespace gge {
+	class GGEMain;
+
+	////Pointer types
+	enum PointerTypes {
+		////No pointer is selected or using default
+		None=0,
+		////Arrow / Pointer
+		Arrow=1,
+		////Wait / Hourglass
+		Wait=2,
+		////No / Not allowed
+		No=3,
+		////Text / Beam pointer
+		Text=4,
+		////Hand pointer
+		Hand=5,
+		////Drag / Closed hand pointer
+		Drag=6
+	};
+
+	class Pointer {
+	public:
+		////The image of the pointer
+		Buffered2DGraphic *Image;
+		////Point of click
+		int HotspotX;
+		////Point of click
+		int HotspotY;
+		////Type of the pointer
+		PointerTypes Type;
+
+		////Initializes a pointer
+		Pointer(Buffered2DGraphic *pointer, int HotspotX, int HotspotY, PointerTypes Type) {
+			this->Image=pointer;
+			this->HotspotX=HotspotX;
+			this->HotspotY=HotspotY;
+			this->Type=Type;
+		}
+	};
+
+	////Initializes Pointer Subsystem
+	void InitializePointer(GGEMain *Main);
+	////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
+	/// animation or image resource
+	void FetchPointers(FolderResource *Folder);
+	////Adds a pointer to the list of pointers
+	Pointer *AddPointer(Buffered2DGraphic *Pointer, Point Hotspot, PointerTypes Type=None);
+	////Removes a pointer from the list
+	void RemovePointer(Buffered2DGraphic *Pointer);
+	////Sets the given pointer as current one, this operation should be revered by
+	/// using reset pointer with the returned integer
+	int SetPointer(Pointer *Pointer);
+	////Sets the given pointer as current one, this operation should be revered by
+	/// using reset pointer with the returned integer
+	int SetPointer(PointerTypes Type);
+	////This function changes base pointer to the given one, it is best to use this function
+	/// once at the startup. This function or FetchFolders function should be called before 
+	/// calling show pointer function
+	void ChangeBasePointer(Pointer *Pointer);
+	////Removes a given stack no from pointer display list. The displayed pointer is always
+	/// the one at the top. But any pointer can be removed from the list without the requirement
+	/// of being on top. 
+	void ResetPointer(int StackNo);
+	////Shows current pointer, ChangeBasePointer or FetchPointers function should be called before
+	/// calling this function
+	void ShowPointer();
+	////Hides current pointer
+	void HidePointer();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/ResizableObject.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "../Utils/GGE.h"
+
+namespace gge {
+
+	class ResizableObject {
+	public:
+		virtual void DrawResized(I2DGraphicsTarget *Target, int X, int Y, int W, int H, Alignment Align)=0;
+		virtual void DrawResized(I2DGraphicsTarget &Target, int X, int Y, int W, int H, Alignment Align) { DrawResized(&Target, X, Y, W, H, Align); }
+		virtual int  Width(int W=-1)=0;
+		virtual int  Height(int H=-1)=0;
+		virtual void Reset(bool Reverse=false)=0;
+		virtual void Reverse()=0;
+		virtual void Play()=0;
+		virtual void Pause()=0;
+		virtual void setLoop(bool Loop)=0;
+		virtual int getDuration()=0;
+	};
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Sound.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,89 @@
+#include "Sound.h"
+
+namespace gge {
+	bool				isSoundAvailable=false;
+
+	int InitializeSound(WindowHandle Window, char *device) {
+		isSoundAvailable=false;
+
+		///*Opening audio device
+		ALCdevice *Device=alcOpenDevice(device);
+		if(Device==NULL)
+			return ERRAL_DEVICE_ERR;
+
+		///*Creating device context
+		ALCcontext *context=alcCreateContext(Device,NULL);
+		if(context==NULL)
+			return ERRAL_CONTEXT_ERR;
+
+		alcMakeContextCurrent(context);
+
+		isSoundAvailable=true;
+
+		return ERRNO_ERR;
+	}
+
+	SoundBufferHandle CreateSoundBuffer(WaveFormat Format, void *Data, int Size) {
+		SoundBufferHandle buffer=0;
+
+		///*Creating Buffer
+		alGetError();
+		alGenBuffers(1,&buffer);
+		if(alGetError()!=AL_NO_ERROR)
+			return 0;
+
+		///*Deciding OpenAL wave format
+		ALenum format;
+		if(Format.Channels==1) {
+			if(Format.BitsPerSample==8) {
+				format=AL_FORMAT_MONO8;
+			} else {
+				format=AL_FORMAT_MONO16;
+			}
+		} else {
+			if(Format.BitsPerSample==8) {
+				format=AL_FORMAT_STEREO8;
+			} else {
+				format=AL_FORMAT_STEREO16;
+			}
+		}
+
+		///*Filling buffer
+		alBufferData(buffer, format, Data, Size, Format.SamplesPerSec);
+
+		return buffer;
+	}
+
+	SoundControlHandle CreateSoundController(SoundBufferHandle Buffer) {
+		SoundControlHandle source;
+
+		alGetError();
+		alGenSources(1,&source);
+		int ret=alGetError();
+		if(ret==AL_NO_ERROR)
+			alSourceQueueBuffers(source, 1, &Buffer);
+
+		alSourcef(source, AL_ROLLOFF_FACTOR, 0);
+
+		return source;
+	}
+
+	SoundControlHandle Create3DSoundController(SoundBufferHandle Buffer, int maxWaveDistance) {
+		SoundControlHandle source;
+
+		alGetError();
+		alGenSources(1,&source);
+		int ret=alGetError();
+		if(ret==AL_NO_ERROR)
+			alSourceQueueBuffers(source, 1, &Buffer);
+
+		alSourcef(source, AL_ROLLOFF_FACTOR, 1.0);
+		alSourcef(source, AL_REFERENCE_DISTANCE, maxWaveDistance);
+
+		return source;
+	}
+
+	void SetListener3DPosition(float x,float y,float z) {
+		alListener3f(AL_POSITION,x,y,z);
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Sound.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,75 @@
+#pragma once
+
+#include "../Utils/GGE.h"
+#include "../External/AL/alc.h"
+#include "../External/AL/al.h"
+#include "OS.h"
+
+#define ERRNO_ERR			0
+#define ERRAL_DEVICE_ERR	1
+#define ERRAL_CONTEXT_ERR	2
+
+namespace gge {
+	////Handle type for sound buffers
+	typedef ALuint	SoundBufferHandle;
+	////Handle type for sound controllers
+	typedef ALuint	SoundControlHandle;
+
+	////Wave format definition, compatible with
+	/// Win32 MMSystem's WaveFormatEx structure
+	struct WaveFormat {
+		////Format type
+		WORD        FormatTag;
+		////Number of channels, mono and sterio are fully 
+		/// supported, rest is untested
+		WORD        Channels;
+		////Samples/second (like 22000 for 22kHz)
+		DWORD       SamplesPerSec;
+		////Avarage bytes/second can be used as statistics
+		DWORD       AvgBytesPerSec;
+		///*???
+		WORD        BlockAlign;
+		////Bits/Sample, represents the quality when combined with Samples/second
+		/// this data is for single channel
+		WORD        BitsPerSample;
+		////Lame and useless, the size of the structure,
+		/// retained for compatibility
+		WORD        Size;
+	};
+
+
+	////Initializes the sound sub system, if no sound
+	/// can be used this function fails gracefully disabling
+	/// any audio attempt without causing any trouble.
+	/// soundavailable variable can be checked whether 
+	/// sound system is up and running.
+	///@Window	: Handle of the main window 
+	///@Device	: The device identifier to be created, NULL will
+	/// use default device.
+	int InitializeSound(WindowHandle Window, char *Device=NULL);
+
+	////Creates a new wave from a given buffer.
+	/// Returns sound handle that can be used to run
+	/// the created buffer
+	///@Format	: Format of given buffer, only mono, streo and 8bit, 16bit
+	/// types work
+	///@Data	: Pointer to the wave data
+	///@Size	: The size of the wave data
+	SoundBufferHandle CreateSoundBuffer(WaveFormat Format, void *Data, int Size);
+
+	////Creates a new sound controller to play a given buffer
+	SoundControlHandle CreateSoundController(SoundBufferHandle Buffer);
+
+	////Creates a new sound controller with 3D positional properties. maxWaveDistance
+	/// allows the control of attenuation
+	SoundControlHandle Create3DSoundController(SoundBufferHandle Buffer, int maxWaveDistance);
+
+	////Changes the position of the sound listener for 3D positional elements
+	void SetListenerPos(float x,float y,float z);
+
+	////Used to identify if sound is available
+	extern bool	isSoundAvailable;
+
+	////Changes Position of 3D Listener
+	void SetListener3DPosition(float x,float y,float z);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Wave.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,93 @@
+#include "Wave.h"
+
+namespace gge {
+	////For garbage collection
+	static Collection<Wave> Waves;
+
+	Wave::Wave(SoundBufferHandle buffer, int maxWaveDistance) {
+		buffer=buffer;
+		isavailable=false;
+		AutoDestruct=true;
+		finished=NULL;
+		finishedstateisknown=0;
+
+		if(maxWaveDistance)
+			isavailable= (source=Create3DSoundController(buffer, maxWaveDistance));
+		else
+			isavailable= (source=CreateSoundController(buffer));
+
+		Waves.Add(this);
+	}
+
+	void WaveGarbageCollect_fire(empty_event_params params, GGEMain &main, Any data, string eventname) {
+		CollectWaveGarbage();
+	}
+
+	void InitWaveGarbageCollect(GGEMain *main) {
+		main->AfterRenderEvent.Register(WaveGarbageCollect_fire);
+	}
+
+	Wave* Wave::Play() {
+		finishedstateisknown=0;
+		
+		alSourcei(source,AL_LOOPING,0);
+		alSourcePlay(source);
+		return this;
+	}
+
+	Wave::~Wave() {
+		_destroy();
+	}
+	
+	Wave* Wave::Loop() {
+		finishedstateisknown=0;
+		alSourcei(source, AL_LOOPING, 1);
+		alSourcePlay(source);
+		return this;
+	}
+	
+	Wave* Wave::SetVolume(float Volume) {
+		alSourcef(source, AL_GAIN, Volume);
+
+		return this;
+	}
+	
+	Wave* Wave::Set3DPosition(float x,float y,float z) {
+		alSource3f(source, AL_POSITION, x, y, z);
+
+		return this;
+	}
+	
+	Wave* Wave::Stop() {
+		alSourceStop(source);
+		return this;
+	}
+	
+	void Wave::_destroy() {
+		isavailable=false;
+		alDeleteSources(1,&source);
+		source=0;
+	}
+
+	bool Wave::isPlaying() {
+		int status=0;
+		alGetSourcei(source,AL_SOURCE_STATE,&status);
+		return status==AL_PLAYING;
+	}
+
+	void CollectWaveGarbage() {
+		Waves.ResetIteration();
+		Wave *wave;
+
+		while(wave=Waves.next()) {
+			if(wave->AutoDestruct) {
+				if(!wave->isPlaying()) {
+					Waves.Remove(wave);
+					wave->_destroy();
+					delete wave;
+					wave=NULL;
+				}
+			}
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Wave.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,71 @@
+#pragma once
+
+#include "GGEMain.h"
+#include "Sound.h"
+#include "../Utils/Collection.h"
+
+namespace gge {
+	////This function initializes garbage collection subsystem
+	void InitWaveGarbageCollect(GGEMain *gge);
+
+	////This function checks finished waves that are marked as
+	/// garbage collectable and destroys them.
+	void CollectWaveGarbage();
+
+	class Wave;
+	////This is function definition required to signal
+	/// when a wave finishes its execution
+	typedef void(*wavefinish)(Wave *wave);
+
+	////Class to control wave-type sounds, this class handles
+	/// the creation of controller and supports 3D positioning
+	/// looping sounds, auto destruction, volume adjustment
+	/// and an event handler to be run when finished
+	class Wave {
+	public:
+		////default constructor requires buffer handle.
+		///@maxWaveDistance	: if specified the generated sound controller
+		/// will have 3D properties
+		Wave(SoundBufferHandle Buffer, int maxWaveDistance=0);
+		////Plays this sound once
+		Wave* Play();
+		////Plays this sound continously until stopped
+		Wave* Loop();
+		////Stops the sound
+		Wave* Stop();
+		////Used to adjust the volume, it can decrease or increase the
+		/// output, 1.0 is volume at 100% while 0.25 is at 25%
+		Wave* SetVolume(float Volume);
+		////Adjusts 3D position of the current sound source allowing
+		/// attuniation to take place.
+		Wave* Set3DPosition(float x,float y,float z);
+
+		////Used to check if sound is being played
+		bool isPlaying();
+
+		////Whether this sound should free itself when it is finished
+		bool AutoDestruct;
+
+		////This event is fired when sound buffer is played.
+		/// This event is fired by GGEMain while sound is being
+		/// examined for auto destruction.
+		wavefinish finished;
+
+		////Default destroyer used to free resources
+		~Wave();
+		////Destroys the controller that this class is bound to
+		void _destroy();
+
+	protected:
+		////Whether finished event is fired or not
+		bool finishedstateisknown;
+		////The wave buffer
+		SoundBufferHandle	buffer;
+		////The controller
+		SoundControlHandle	source;
+		////Whether this sound is available to be played
+		bool isavailable;
+	};
+
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Engine/Windows.cpp	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,419 @@
+#include "OS.h"
+#include "input.h"
+#include "Multimedia.h"
+
+#ifdef WIN32
+
+#define WINVER 0x0500
+#define _WIN32_WINNT 0x0500
+#include <windows.h>
+#undef CreateWindow
+#undef Rectangle
+
+#ifndef WM_MOUSEWHEEL
+#define WM_MOUSEWHEEL					0x020A
+#define GET_WHEEL_DELTA_WPARAM(wParam)  ((short)HIWORD(wParam))
+#endif
+
+
+#ifndef WM_XBUTTONDOWN
+#define WM_XBUTTONDOWN                  0x020B
+#define WM_XBUTTONUP                    0x020C
+#define WM_XBUTTONDBLCLK                0x020D
+
+#define GET_XBUTTON_WPARAM(wParam)      (HIWORD(wParam))
+#endif
+
+
+#ifndef WM_MOUSEHWHEEL
+#define WM_MOUSEHWHEEL					0x020E
+#endif
+
+namespace gge {
+
+	EventChain<Empty, empty_event_params> WindowActivateEvent("WindowActivate",NULL);
+	EventChain<Empty, empty_event_params> WindowDeactivateEvent("WindowDectivate",NULL);
+	EventChain<Empty, empty_event_params> WindowDestroyedEvent("WindowDestroyed",NULL);
+
+	CursorHandle defaultcursor;
+	bool ospointerdisplayed;
+
+	POINT windowoverhead;
+	HWND curwin;
+
+	LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+	{
+		switch(message)
+		{
+		case WM_ACTIVATE:
+			if(LOWORD(wParam))  {
+				WindowActivateEvent();
+			}
+			else {
+				WindowDeactivateEvent();
+			}
+			break;
+		case WM_ERASEBKGND:
+			return true;
+		case WM_LBUTTONDOWN:
+			{
+				int x=lParam%0x10000;
+				int y=lParam>>16;
+				
+				ProcessMouseDown(1,x,y);
+			}
+			break;
+		case WM_LBUTTONUP:
+			{
+				int x=lParam%0x10000;
+				int y=lParam>>16;
+				
+				ProcessMouseUp(1,x,y);
+				ProcessMouseClick(1,x,y);
+			}
+			break;
+		case WM_LBUTTONDBLCLK:
+			{
+				int x=lParam%0x10000;
+				int y=lParam>>16;
+				
+				ProcessMouseDblClick(1,x,y);
+			}
+			break;
+
+		case WM_RBUTTONDOWN:
+			{
+				int x=lParam%0x10000;
+				int y=lParam>>16;
+				
+				ProcessMouseDown(2,x,y);
+			}
+			break;
+		case WM_RBUTTONUP:
+			{
+				int x=lParam%0x10000;
+				int y=lParam>>16;
+				
+				ProcessMouseUp(2,x,y);
+				ProcessMouseClick(2,x,y);
+			}
+			break;
+		case WM_RBUTTONDBLCLK:
+			{
+				int x=lParam%0x10000;
+				int y=lParam>>16;
+				
+				ProcessMouseDblClick(2,x,y);
+			}
+			break;
+
+		case WM_MBUTTONDOWN:
+			{
+				int x=lParam%0x10000;
+				int y=lParam>>16;
+				
+				ProcessMouseDown(4,x,y);
+			}
+			break;
+		case WM_MBUTTONUP:
+			{
+				int x=lParam%0x10000;
+				int y=lParam>>16;
+				
+				ProcessMouseUp(4,x,y);
+				ProcessMouseClick(4,x,y);
+			}
+			break;
+		case WM_MBUTTONDBLCLK:
+			{
+				int x=lParam%0x10000;
+				int y=lParam>>16;
+				
+				ProcessMouseDblClick(4,x,y);
+			}
+			break;
+
+		case WM_XBUTTONDOWN:
+			{
+				int x=lParam%0x10000;
+				int y=lParam>>16;
+				
+				switch(GET_XBUTTON_WPARAM(wParam)) {
+				case 1:
+					ProcessMouseDown(101,x,y);
+					break;
+				case 2:
+					ProcessMouseDown(102,x,y);
+					break;
+				}
+			}
+			break;
+		case WM_XBUTTONUP:
+			{
+				int x=lParam%0x10000;
+				int y=lParam>>16;
+				
+				
+				switch(GET_XBUTTON_WPARAM(wParam)) {
+				case 1:
+					ProcessMouseUp(101,x,y);
+					ProcessMouseClick(101,x,y);
+					break;
+				case 2:
+					ProcessMouseUp(102,x,y);
+					ProcessMouseClick(102,x,y);
+					break;
+				}
+			}
+			break;
+		case WM_XBUTTONDBLCLK:
+			{
+				int x=lParam%0x10000;
+				int y=lParam>>16;
+				
+				switch(GET_XBUTTON_WPARAM(wParam)) {
+				case 1:
+					ProcessMouseDblClick(101,x,y);
+					break;
+				case 2:
+					ProcessMouseDblClick(102,x,y);
+					break;
+				}
+			}
+			break;
+
+		case WM_MOUSEWHEEL:
+			{
+				int x=lParam%0x10000;
+				int y=lParam>>16;
+				
+				ProcessVScroll(GET_WHEEL_DELTA_WPARAM(wParam)/120,x-windowoverhead.x,y-windowoverhead.y);
+			}
+			break;
+		case WM_MOUSEHWHEEL:
+			{
+				int x=lParam%0x10000;
+				int y=lParam>>16;
+				
+				ProcessHScroll(GET_WHEEL_DELTA_WPARAM(wParam)/120,x-windowoverhead.x,y-windowoverhead.y);
+			}
+			break;
+
+		case WM_KEYDOWN:
+			if(lParam&1<<24)
+				isAlternateKey=true;
+			else
+				isAlternateKey=false;
+
+			if(lParam==0x360001)
+				AddModifier(KeyboardModifiers,KEYB_MOD_ALTERNATIVE);
+
+
+			switch(wParam) {
+			case VK_CONTROL:
+				AddModifier(KeyboardModifiers,KEYB_MOD_CTRL);
+				break;
+			case VK_SHIFT:
+				AddModifier(KeyboardModifiers,KEYB_MOD_SHIFT);
+				break;
+			case VK_MENU:
+				AddModifier(KeyboardModifiers,KEYB_MOD_ALT);
+				break;
+			case VK_LWIN:
+				RemoveModifier(KeyboardModifiers,KEYB_MOD_ALTERNATIVE);
+				AddModifier(KeyboardModifiers,KEYB_MOD_WIN);
+				break;
+			case VK_RWIN:
+				AddModifier(KeyboardModifiers,KEYB_MOD_ALTERNATIVE);
+				AddModifier(KeyboardModifiers,KEYB_MOD_WIN);
+				break;
+			default:
+				RemoveModifier(KeyboardModifiers,KEYB_MOD_ALTERNATIVE);
+			}
+			ProcessKeyDown(wParam);
+				
+			break; 
+		case WM_KEYUP:
+			if(lParam&1<<24)
+				isAlternateKey=true;
+			else
+				isAlternateKey=false;
+
+			ProcessKeyUp(wParam);
+			switch(wParam) {
+			case VK_CONTROL:
+				RemoveModifier(KeyboardModifiers,KEYB_MOD_CTRL);
+				break;
+			case VK_SHIFT:
+				RemoveModifier(KeyboardModifiers,KEYB_MOD_SHIFT);
+				break;
+			case VK_MENU:
+				RemoveModifier(KeyboardModifiers,KEYB_MOD_ALT);
+				break;
+			case VK_LWIN:
+				RemoveModifier(KeyboardModifiers,KEYB_MOD_ALTERNATIVE);
+				RemoveModifier(KeyboardModifiers,KEYB_MOD_WIN);
+				break;
+			case VK_RWIN:
+				RemoveModifier(KeyboardModifiers,KEYB_MOD_ALTERNATIVE);
+				RemoveModifier(KeyboardModifiers,KEYB_MOD_WIN);
+				break;
+			}
+				
+			break; 
+		case WM_CHAR:
+			/*if(lParam&1<<24)
+				AddModifier(&KeyboardModifier,KEYB_MOD_ALTERNATIVE);
+			else
+				RemoveModifier(&KeyboardModifier,KEYB_MOD_ALTERNATIVE);*/
+
+			ProcessChar(wParam);
+			break; 
+		case WM_SYSKEYDOWN:
+			AddModifier(KeyboardModifiers,KEYB_MOD_ALT);
+			break; 
+		case WM_SYSKEYUP:
+			RemoveModifier(KeyboardModifiers,KEYB_MOD_ALT);
+			break; 
+		case WM_SYSCHAR:
+			AddModifier(KeyboardModifiers,KEYB_MOD_ALT);
+			ProcessChar(wParam);
+			RemoveModifier(KeyboardModifiers,KEYB_MOD_ALT);
+			break;
+		case WM_VIDEO_NOTIFY:
+			if(lParam) {
+				Multimedia* vid=((Multimedia*)lParam);
+				vid->ProcessMsg();
+			}
+			break;
+		case WM_DESTROY:
+			WindowDestroyedEvent();
+			break;
+		default:
+			return DefWindowProc(hWnd, message, wParam, lParam);
+		}
+		return 0;
+	}
+
+	WindowHandle CreateWin(const char *Name, const char *Title, IconHandle Icon, InstanceHandle Instance, int Left, int Top, int Width, int Height, int BitDepth, bool &FullScreen) {
+		WNDCLASSEX windclass;
+
+		HWND ret;
+
+		///*Creating window class
+		windclass.cbClsExtra=0;
+		windclass.cbSize=sizeof(WNDCLASSEX);
+		windclass.cbWndExtra=0;
+		windclass.hbrBackground=(HBRUSH)16;
+		windclass.hCursor=LoadCursor(NULL, NULL);
+		windclass.hInstance=(HINSTANCE)Instance;
+		windclass.lpfnWndProc=WndProc;
+		windclass.lpszClassName=Name;
+		windclass.lpszMenuName=NULL;
+		windclass.hIcon=(HICON)Icon;
+		windclass.hIconSm=(HICON)Icon;
+		windclass.style=3;
+		RegisterClassEx(&windclass);
+
+		///*Setting fullscreen parameters
+		if (FullScreen) {
+			DEVMODE dmScreenSettings;									// device mode
+			memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
+			dmScreenSettings.dmSize       = sizeof(dmScreenSettings); 
+			dmScreenSettings.dmPelsWidth  = Width;						// screen width
+			dmScreenSettings.dmPelsHeight = Height;						// screen height
+			dmScreenSettings.dmBitsPerPel = BitDepth;					// bits per pixel
+			dmScreenSettings.dmFields	  = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
+			if(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN)!= DISP_CHANGE_SUCCESSFUL) {
+				MessageBox(NULL,"Cannot run in fullscreen, reverting to windowed mode\nTam ekran modu çalışmamakta, pencerede gösterim modu seçildi","Initialize / Başlangıç",0);
+				FullScreen=false;
+			}
+		}
+
+		///*Creating window
+		if(!FullScreen)
+			ret=CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, Name, Title, WS_MINIMIZEBOX | WS_SYSMENU | WS_CLIPSIBLINGS |WS_CLIPCHILDREN ,CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, (HINSTANCE)Instance, NULL);
+		else																							   
+			ret=CreateWindowA(Name, Title, WS_POPUP, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, (HINSTANCE)Instance, NULL);
+
+		///*Adjusting window size and position
+		ShowWindow(ret,1);
+		if(!FullScreen) {
+			RECT cr,wr;
+			GetClientRect(ret,&cr);
+			GetWindowRect(ret,&wr);
+
+			SetWindowPos(ret, 0, 0, 0, 
+				Width + ( (wr.right-wr.left) - (cr.right-cr.left) ),
+				Height + ( (wr.bottom-wr.top) - (cr.bottom-cr.top) ),0);
+		}
+		else
+			SetWindowPos(ret, 0, Left, Top, Width, Height, 0);
+
+		UpdateWindow(ret);
+		curwin=ret;
+
+		HCURSOR cursor=LoadCursor(NULL, IDC_ARROW);
+		defaultcursor=(CursorHandle)cursor;
+
+		windowoverhead.x=0;
+		windowoverhead.y=0;
+
+		if(!FullScreen)
+			ClientToScreen(ret,&windowoverhead);
+
+		if(!FullScreen)
+			SetWindowPos(ret, 0, Left, Top, 0, 0,SWP_NOSIZE | SWP_NOZORDER);
+
+
+		return (WindowHandle)ret;
+	}
+
+	void ProcessMessage() {
+		MSG msg;
+		if( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ) {
+			GetMessage(&msg, NULL, 0, 0 );
+
+			// Translate and dispatch the message
+			TranslateMessage( &msg ); 
+			DispatchMessage( &msg );
+		}
+	}
+	void DisplayMessage(char *Title, char *Text) {
+		MessageBox(NULL,Text,Title,0);
+	}
+	void ShowOSPointer() {
+		if(!ospointerdisplayed) {
+			ospointerdisplayed=true;
+			ShowCursor(true);
+			SetCursor((HCURSOR)defaultcursor);
+		}
+	}
+	void HideOSPointer() {
+		if(ospointerdisplayed) {
+			ospointerdisplayed=false;
+			SetCursor(NULL);
+			ShowCursor(false);
+		}
+	}
+	void Quit(int ret) {
+		PostQuitMessage(ret);
+		exit(ret);
+	}
+	Point getMousePosition(WindowHandle Window) {
+		POINT pnt;
+		RECT winrect;
+		Point ret;
+		GetWindowRect((HWND)Window, &winrect);
+		GetCursorPos(&pnt);
+
+		ret.x=pnt.x-(windowoverhead.x+winrect.left);
+		ret.y=pnt.y-(windowoverhead.y+winrect.top);
+
+		return ret;
+	}
+	void InitializeOS() {
+		ospointerdisplayed=true;
+	}
+}
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/External/AL/al.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,732 @@
+#ifndef AL_AL_H
+#define AL_AL_H
+
+
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#if defined(_WIN32) && !defined(_XBOX)
+ /* _OPENAL32LIB is deprecated */
+ #if defined(AL_BUILD_LIBRARY) || defined (_OPENAL32LIB)
+  #define AL_API __declspec(dllexport)
+ #else
+  #define AL_API __declspec(dllimport)
+ #endif
+#else
+ #define AL_API extern
+#endif
+
+#if defined(_WIN32)
+ #define AL_APIENTRY __cdecl
+#else
+ #define AL_APIENTRY
+#endif
+
+#if TARGET_OS_MAC
+ #pragma export on
+#endif
+
+/* The OPENAL, ALAPI, and ALAPIENTRY macros are deprecated, but are included for applications porting code
+   from AL 1.0 */
+#define OPENAL
+#define ALAPI AL_API
+#define ALAPIENTRY AL_APIENTRY
+
+#define AL_VERSION_1_0
+#define AL_VERSION_1_1
+
+
+/** 8-bit boolean */
+typedef char ALboolean;
+
+/** character */
+typedef char ALchar;
+
+/** signed 8-bit 2's complement integer */
+typedef char ALbyte;
+
+/** unsigned 8-bit integer */
+typedef unsigned char ALubyte;
+
+/** signed 16-bit 2's complement integer */
+typedef short ALshort;
+
+/** unsigned 16-bit integer */
+typedef unsigned short ALushort;
+
+/** signed 32-bit 2's complement integer */
+typedef int ALint;
+
+/** unsigned 32-bit integer */
+typedef unsigned int ALuint;
+
+/** non-negative 32-bit binary integer size */
+typedef int ALsizei;
+
+/** enumerated 32-bit value */
+typedef int ALenum;
+
+/** 32-bit IEEE754 floating-point */
+typedef float ALfloat;
+
+/** 64-bit IEEE754 floating-point */
+typedef double ALdouble;
+
+/** void type (for opaque pointers only) */
+typedef void ALvoid;
+
+
+/* Enumerant values begin at column 50. No tabs. */
+
+/* bad value */
+#define AL_INVALID                                -1
+
+#define AL_NONE                                   0
+
+/* Boolean False. */
+#define AL_FALSE                                  0
+
+/** Boolean True. */
+#define AL_TRUE                                   1
+
+/** Indicate Source has relative coordinates. */
+#define AL_SOURCE_RELATIVE                        0x202
+
+
+
+/**
+ * Directional source, inner cone angle, in degrees.
+ * Range:    [0-360] 
+ * Default:  360
+ */
+#define AL_CONE_INNER_ANGLE                       0x1001
+
+/**
+ * Directional source, outer cone angle, in degrees.
+ * Range:    [0-360] 
+ * Default:  360
+ */
+#define AL_CONE_OUTER_ANGLE                       0x1002
+
+/**
+ * Specify the pitch to be applied, either at source,
+ *  or on mixer results, at listener.
+ * Range:   [0.5-2.0]
+ * Default: 1.0
+ */
+#define AL_PITCH                                  0x1003
+  
+/** 
+ * Specify the current location in three dimensional space.
+ * OpenAL, like OpenGL, uses a right handed coordinate system,
+ *  where in a frontal default view X (thumb) points right, 
+ *  Y points up (index finger), and Z points towards the
+ *  viewer/camera (middle finger). 
+ * To switch from a left handed coordinate system, flip the
+ *  sign on the Z coordinate.
+ * Listener position is always in the world coordinate system.
+ */ 
+#define AL_POSITION                               0x1004
+  
+/** Specify the current direction. */
+#define AL_DIRECTION                              0x1005
+  
+/** Specify the current velocity in three dimensional space. */
+#define AL_VELOCITY                               0x1006
+
+/**
+ * Indicate whether source is looping.
+ * Type: ALboolean?
+ * Range:   [AL_TRUE, AL_FALSE]
+ * Default: FALSE.
+ */
+#define AL_LOOPING                                0x1007
+
+/**
+ * Indicate the buffer to provide sound samples. 
+ * Type: ALuint.
+ * Range: any valid Buffer id.
+ */
+#define AL_BUFFER                                 0x1009
+  
+/**
+ * Indicate the gain (volume amplification) applied. 
+ * Type:   ALfloat.
+ * Range:  ]0.0-  ]
+ * A value of 1.0 means un-attenuated/unchanged.
+ * Each division by 2 equals an attenuation of -6dB.
+ * Each multiplicaton with 2 equals an amplification of +6dB.
+ * A value of 0.0 is meaningless with respect to a logarithmic
+ *  scale; it is interpreted as zero volume - the channel
+ *  is effectively disabled.
+ */
+#define AL_GAIN                                   0x100A
+
+/*
+ * Indicate minimum source attenuation
+ * Type: ALfloat
+ * Range:  [0.0 - 1.0]
+ *
+ * Logarthmic
+ */
+#define AL_MIN_GAIN                               0x100D
+
+/**
+ * Indicate maximum source attenuation
+ * Type: ALfloat
+ * Range:  [0.0 - 1.0]
+ *
+ * Logarthmic
+ */
+#define AL_MAX_GAIN                               0x100E
+
+/**
+ * Indicate listener orientation.
+ *
+ * at/up 
+ */
+#define AL_ORIENTATION                            0x100F
+
+/**
+ * Specify the channel mask. (Creative)
+ * Type: ALuint
+ * Range: [0 - 255]
+ */
+#define AL_CHANNEL_MASK                           0x3000
+
+
+/**
+ * Source state information.
+ */
+#define AL_SOURCE_STATE                           0x1010
+#define AL_INITIAL                                0x1011
+#define AL_PLAYING                                0x1012
+#define AL_PAUSED                                 0x1013
+#define AL_STOPPED                                0x1014
+
+/**
+ * Buffer Queue params
+ */
+#define AL_BUFFERS_QUEUED                         0x1015
+#define AL_BUFFERS_PROCESSED                      0x1016
+
+/**
+ * Source buffer position information
+ */
+#define AL_SEC_OFFSET                             0x1024
+#define AL_SAMPLE_OFFSET                          0x1025
+#define AL_BYTE_OFFSET                            0x1026
+
+/*
+ * Source type (Static, Streaming or undetermined)
+ * Source is Static if a Buffer has been attached using AL_BUFFER
+ * Source is Streaming if one or more Buffers have been attached using alSourceQueueBuffers
+ * Source is undetermined when it has the NULL buffer attached
+ */
+#define AL_SOURCE_TYPE                            0x1027
+#define AL_STATIC                                 0x1028
+#define AL_STREAMING                              0x1029
+#define AL_UNDETERMINED                           0x1030
+
+/** Sound samples: format specifier. */
+#define AL_FORMAT_MONO8                           0x1100
+#define AL_FORMAT_MONO16                          0x1101
+#define AL_FORMAT_STEREO8                         0x1102
+#define AL_FORMAT_STEREO16                        0x1103
+
+/**
+ * source specific reference distance
+ * Type: ALfloat
+ * Range:  0.0 - +inf
+ *
+ * At 0.0, no distance attenuation occurs.  Default is
+ * 1.0.
+ */
+#define AL_REFERENCE_DISTANCE                     0x1020
+
+/**
+ * source specific rolloff factor
+ * Type: ALfloat
+ * Range:  0.0 - +inf
+ *
+ */
+#define AL_ROLLOFF_FACTOR                         0x1021
+
+/**
+ * Directional source, outer cone gain.
+ *
+ * Default:  0.0
+ * Range:    [0.0 - 1.0]
+ * Logarithmic
+ */
+#define AL_CONE_OUTER_GAIN                        0x1022
+
+/**
+ * Indicate distance above which sources are not
+ * attenuated using the inverse clamped distance model.
+ *
+ * Default: +inf
+ * Type: ALfloat
+ * Range:  0.0 - +inf
+ */
+#define AL_MAX_DISTANCE                           0x1023
+
+/** 
+ * Sound samples: frequency, in units of Hertz [Hz].
+ * This is the number of samples per second. Half of the
+ *  sample frequency marks the maximum significant
+ *  frequency component.
+ */
+#define AL_FREQUENCY                              0x2001
+#define AL_BITS                                   0x2002
+#define AL_CHANNELS                               0x2003
+#define AL_SIZE                                   0x2004
+
+/**
+ * Buffer state.
+ *
+ * Not supported for public use (yet).
+ */
+#define AL_UNUSED                                 0x2010
+#define AL_PENDING                                0x2011
+#define AL_PROCESSED                              0x2012
+
+
+/** Errors: No Error. */
+#define AL_NO_ERROR                               AL_FALSE
+
+/** 
+ * Invalid Name paramater passed to AL call.
+ */
+#define AL_INVALID_NAME                           0xA001
+
+/** 
+ * Invalid parameter passed to AL call.
+ */
+#define AL_ILLEGAL_ENUM                           0xA002
+#define AL_INVALID_ENUM                           0xA002
+
+/** 
+ * Invalid enum parameter value.
+ */
+#define AL_INVALID_VALUE                          0xA003
+
+/** 
+ * Illegal call.
+ */
+#define AL_ILLEGAL_COMMAND                        0xA004
+#define AL_INVALID_OPERATION                      0xA004
+
+  
+/**
+ * No mojo.
+ */
+#define AL_OUT_OF_MEMORY                          0xA005
+
+
+/** Context strings: Vendor Name. */
+#define AL_VENDOR                                 0xB001
+#define AL_VERSION                                0xB002
+#define AL_RENDERER                               0xB003
+#define AL_EXTENSIONS                             0xB004
+
+/** Global tweakage. */
+
+/**
+ * Doppler scale.  Default 1.0
+ */
+#define AL_DOPPLER_FACTOR                         0xC000
+
+/**
+ * Tweaks speed of propagation.
+ */
+#define AL_DOPPLER_VELOCITY                       0xC001
+
+/**
+ * Speed of Sound in units per second
+ */
+#define AL_SPEED_OF_SOUND                         0xC003
+
+/**
+ * Distance models
+ *
+ * used in conjunction with DistanceModel
+ *
+ * implicit: NONE, which disances distance attenuation.
+ */
+#define AL_DISTANCE_MODEL                         0xD000
+#define AL_INVERSE_DISTANCE                       0xD001
+#define AL_INVERSE_DISTANCE_CLAMPED               0xD002
+#define AL_LINEAR_DISTANCE                        0xD003
+#define AL_LINEAR_DISTANCE_CLAMPED                0xD004
+#define AL_EXPONENT_DISTANCE                      0xD005
+#define AL_EXPONENT_DISTANCE_CLAMPED              0xD006
+
+
+#if !defined(AL_NO_PROTOTYPES)
+
+/*
+ * Renderer State management
+ */
+AL_API void AL_APIENTRY alEnable( ALenum capability );
+
+AL_API void AL_APIENTRY alDisable( ALenum capability ); 
+
+AL_API ALboolean AL_APIENTRY alIsEnabled( ALenum capability ); 
+
+
+/*
+ * State retrieval
+ */
+AL_API const ALchar* AL_APIENTRY alGetString( ALenum param );
+
+AL_API void AL_APIENTRY alGetBooleanv( ALenum param, ALboolean* data );
+
+AL_API void AL_APIENTRY alGetIntegerv( ALenum param, ALint* data );
+
+AL_API void AL_APIENTRY alGetFloatv( ALenum param, ALfloat* data );
+
+AL_API void AL_APIENTRY alGetDoublev( ALenum param, ALdouble* data );
+
+AL_API ALboolean AL_APIENTRY alGetBoolean( ALenum param );
+
+AL_API ALint AL_APIENTRY alGetInteger( ALenum param );
+
+AL_API ALfloat AL_APIENTRY alGetFloat( ALenum param );
+
+AL_API ALdouble AL_APIENTRY alGetDouble( ALenum param );
+
+
+/*
+ * Error support.
+ * Obtain the most recent error generated in the AL state machine.
+ */
+AL_API ALenum AL_APIENTRY alGetError( void );
+
+
+/* 
+ * Extension support.
+ * Query for the presence of an extension, and obtain any appropriate
+ * function pointers and enum values.
+ */
+AL_API ALboolean AL_APIENTRY alIsExtensionPresent( const ALchar* extname );
+
+AL_API void* AL_APIENTRY alGetProcAddress( const ALchar* fname );
+
+AL_API ALenum AL_APIENTRY alGetEnumValue( const ALchar* ename );
+
+
+/*
+ * LISTENER
+ * Listener represents the location and orientation of the
+ * 'user' in 3D-space.
+ *
+ * Properties include: -
+ *
+ * Gain         AL_GAIN         ALfloat
+ * Position     AL_POSITION     ALfloat[3]
+ * Velocity     AL_VELOCITY     ALfloat[3]
+ * Orientation  AL_ORIENTATION  ALfloat[6] (Forward then Up vectors)
+*/
+
+/*
+ * Set Listener parameters
+ */
+AL_API void AL_APIENTRY alListenerf( ALenum param, ALfloat value );
+
+AL_API void AL_APIENTRY alListener3f( ALenum param, ALfloat value1, ALfloat value2, ALfloat value3 );
+
+AL_API void AL_APIENTRY alListenerfv( ALenum param, const ALfloat* values ); 
+
+AL_API void AL_APIENTRY alListeneri( ALenum param, ALint value );
+
+AL_API void AL_APIENTRY alListener3i( ALenum param, ALint value1, ALint value2, ALint value3 );
+
+AL_API void AL_APIENTRY alListeneriv( ALenum param, const ALint* values );
+
+/*
+ * Get Listener parameters
+ */
+AL_API void AL_APIENTRY alGetListenerf( ALenum param, ALfloat* value );
+
+AL_API void AL_APIENTRY alGetListener3f( ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3 );
+
+AL_API void AL_APIENTRY alGetListenerfv( ALenum param, ALfloat* values );
+
+AL_API void AL_APIENTRY alGetListeneri( ALenum param, ALint* value );
+
+AL_API void AL_APIENTRY alGetListener3i( ALenum param, ALint *value1, ALint *value2, ALint *value3 );
+
+AL_API void AL_APIENTRY alGetListeneriv( ALenum param, ALint* values );
+
+
+/**
+ * SOURCE
+ * Sources represent individual sound objects in 3D-space.
+ * Sources take the PCM data provided in the specified Buffer,
+ * apply Source-specific modifications, and then
+ * submit them to be mixed according to spatial arrangement etc.
+ * 
+ * Properties include: -
+ *
+ * Gain                              AL_GAIN                 ALfloat
+ * Min Gain                          AL_MIN_GAIN             ALfloat
+ * Max Gain                          AL_MAX_GAIN             ALfloat
+ * Position                          AL_POSITION             ALfloat[3]
+ * Velocity                          AL_VELOCITY             ALfloat[3]
+ * Direction                         AL_DIRECTION            ALfloat[3]
+ * Head Relative Mode                AL_SOURCE_RELATIVE      ALint (AL_TRUE or AL_FALSE)
+ * Reference Distance                AL_REFERENCE_DISTANCE   ALfloat
+ * Max Distance                      AL_MAX_DISTANCE         ALfloat
+ * RollOff Factor                    AL_ROLLOFF_FACTOR       ALfloat
+ * Inner Angle                       AL_CONE_INNER_ANGLE     ALint or ALfloat
+ * Outer Angle                       AL_CONE_OUTER_ANGLE     ALint or ALfloat
+ * Cone Outer Gain                   AL_CONE_OUTER_GAIN      ALint or ALfloat
+ * Pitch                             AL_PITCH                ALfloat
+ * Looping                           AL_LOOPING              ALint (AL_TRUE or AL_FALSE)
+ * MS Offset                         AL_MSEC_OFFSET          ALint or ALfloat
+ * Byte Offset                       AL_BYTE_OFFSET          ALint or ALfloat
+ * Sample Offset                     AL_SAMPLE_OFFSET        ALint or ALfloat
+ * Attached Buffer                   AL_BUFFER               ALint
+ * State (Query only)                AL_SOURCE_STATE         ALint
+ * Buffers Queued (Query only)       AL_BUFFERS_QUEUED       ALint
+ * Buffers Processed (Query only)    AL_BUFFERS_PROCESSED    ALint
+ */
+
+/* Create Source objects */
+AL_API void AL_APIENTRY alGenSources( ALsizei n, ALuint* sources ); 
+
+/* Delete Source objects */
+AL_API void AL_APIENTRY alDeleteSources( ALsizei n, const ALuint* sources );
+
+/* Verify a handle is a valid Source */ 
+AL_API ALboolean AL_APIENTRY alIsSource( ALuint sid ); 
+
+/*
+ * Set Source parameters
+ */
+AL_API void AL_APIENTRY alSourcef( ALuint sid, ALenum param, ALfloat value ); 
+
+AL_API void AL_APIENTRY alSource3f( ALuint sid, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3 );
+
+AL_API void AL_APIENTRY alSourcefv( ALuint sid, ALenum param, const ALfloat* values ); 
+
+AL_API void AL_APIENTRY alSourcei( ALuint sid, ALenum param, ALint value ); 
+
+AL_API void AL_APIENTRY alSource3i( ALuint sid, ALenum param, ALint value1, ALint value2, ALint value3 );
+
+AL_API void AL_APIENTRY alSourceiv( ALuint sid, ALenum param, const ALint* values );
+
+/*
+ * Get Source parameters
+ */
+AL_API void AL_APIENTRY alGetSourcef( ALuint sid, ALenum param, ALfloat* value );
+
+AL_API void AL_APIENTRY alGetSource3f( ALuint sid, ALenum param, ALfloat* value1, ALfloat* value2, ALfloat* value3);
+
+AL_API void AL_APIENTRY alGetSourcefv( ALuint sid, ALenum param, ALfloat* values );
+
+AL_API void AL_APIENTRY alGetSourcei( ALuint sid,  ALenum param, ALint* value );
+
+AL_API void AL_APIENTRY alGetSource3i( ALuint sid, ALenum param, ALint* value1, ALint* value2, ALint* value3);
+
+AL_API void AL_APIENTRY alGetSourceiv( ALuint sid,  ALenum param, ALint* values );
+
+
+/*
+ * Source vector based playback calls
+ */
+
+/* Play, replay, or resume (if paused) a list of Sources */
+AL_API void AL_APIENTRY alSourcePlayv( ALsizei ns, const ALuint *sids );
+
+/* Stop a list of Sources */
+AL_API void AL_APIENTRY alSourceStopv( ALsizei ns, const ALuint *sids );
+
+/* Rewind a list of Sources */
+AL_API void AL_APIENTRY alSourceRewindv( ALsizei ns, const ALuint *sids );
+
+/* Pause a list of Sources */
+AL_API void AL_APIENTRY alSourcePausev( ALsizei ns, const ALuint *sids );
+
+/*
+ * Source based playback calls
+ */
+
+/* Play, replay, or resume a Source */
+AL_API void AL_APIENTRY alSourcePlay( ALuint sid );
+
+/* Stop a Source */
+AL_API void AL_APIENTRY alSourceStop( ALuint sid );
+
+/* Rewind a Source (set playback postiton to beginning) */
+AL_API void AL_APIENTRY alSourceRewind( ALuint sid );
+
+/* Pause a Source */
+AL_API void AL_APIENTRY alSourcePause( ALuint sid );
+
+/*
+ * Source Queuing 
+ */
+AL_API void AL_APIENTRY alSourceQueueBuffers( ALuint sid, ALsizei numEntries, const ALuint *bids );
+
+AL_API void AL_APIENTRY alSourceUnqueueBuffers( ALuint sid, ALsizei numEntries, ALuint *bids );
+
+
+/**
+ * BUFFER
+ * Buffer objects are storage space for sample data.
+ * Buffers are referred to by Sources. One Buffer can be used
+ * by multiple Sources.
+ *
+ * Properties include: -
+ *
+ * Frequency (Query only)    AL_FREQUENCY      ALint
+ * Size (Query only)         AL_SIZE           ALint
+ * Bits (Query only)         AL_BITS           ALint
+ * Channels (Query only)     AL_CHANNELS       ALint
+ */
+
+/* Create Buffer objects */
+AL_API void AL_APIENTRY alGenBuffers( ALsizei n, ALuint* buffers );
+
+/* Delete Buffer objects */
+AL_API void AL_APIENTRY alDeleteBuffers( ALsizei n, const ALuint* buffers );
+
+/* Verify a handle is a valid Buffer */
+AL_API ALboolean AL_APIENTRY alIsBuffer( ALuint bid );
+
+/* Specify the data to be copied into a buffer */
+AL_API void AL_APIENTRY alBufferData( ALuint bid, ALenum format, const ALvoid* data, ALsizei size, ALsizei freq );
+
+/*
+ * Set Buffer parameters
+ */
+AL_API void AL_APIENTRY alBufferf( ALuint bid, ALenum param, ALfloat value );
+
+AL_API void AL_APIENTRY alBuffer3f( ALuint bid, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3 );
+
+AL_API void AL_APIENTRY alBufferfv( ALuint bid, ALenum param, const ALfloat* values );
+
+AL_API void AL_APIENTRY alBufferi( ALuint bid, ALenum param, ALint value );
+
+AL_API void AL_APIENTRY alBuffer3i( ALuint bid, ALenum param, ALint value1, ALint value2, ALint value3 );
+
+AL_API void AL_APIENTRY alBufferiv( ALuint bid, ALenum param, const ALint* values );
+
+/*
+ * Get Buffer parameters
+ */
+AL_API void AL_APIENTRY alGetBufferf( ALuint bid, ALenum param, ALfloat* value );
+
+AL_API void AL_APIENTRY alGetBuffer3f( ALuint bid, ALenum param, ALfloat* value1, ALfloat* value2, ALfloat* value3);
+
+AL_API void AL_APIENTRY alGetBufferfv( ALuint bid, ALenum param, ALfloat* values );
+
+AL_API void AL_APIENTRY alGetBufferi( ALuint bid, ALenum param, ALint* value );
+
+AL_API void AL_APIENTRY alGetBuffer3i( ALuint bid, ALenum param, ALint* value1, ALint* value2, ALint* value3);
+
+AL_API void AL_APIENTRY alGetBufferiv( ALuint bid, ALenum param, ALint* values );
+
+
+/*
+ * Global Parameters
+ */
+AL_API void AL_APIENTRY alDopplerFactor( ALfloat value );
+
+AL_API void AL_APIENTRY alDopplerVelocity( ALfloat value );
+
+AL_API void AL_APIENTRY alSpeedOfSound( ALfloat value );
+
+AL_API void AL_APIENTRY alDistanceModel( ALenum distanceModel );
+
+#else /* AL_NO_PROTOTYPES */
+
+typedef void           (AL_APIENTRY *LPALENABLE)( ALenum capability );
+typedef void           (AL_APIENTRY *LPALDISABLE)( ALenum capability ); 
+typedef ALboolean      (AL_APIENTRY *LPALISENABLED)( ALenum capability ); 
+typedef const ALchar*  (AL_APIENTRY *LPALGETSTRING)( ALenum param );
+typedef void           (AL_APIENTRY *LPALGETBOOLEANV)( ALenum param, ALboolean* data );
+typedef void           (AL_APIENTRY *LPALGETINTEGERV)( ALenum param, ALint* data );
+typedef void           (AL_APIENTRY *LPALGETFLOATV)( ALenum param, ALfloat* data );
+typedef void           (AL_APIENTRY *LPALGETDOUBLEV)( ALenum param, ALdouble* data );
+typedef ALboolean      (AL_APIENTRY *LPALGETBOOLEAN)( ALenum param );
+typedef ALint          (AL_APIENTRY *LPALGETINTEGER)( ALenum param );
+typedef ALfloat        (AL_APIENTRY *LPALGETFLOAT)( ALenum param );
+typedef ALdouble       (AL_APIENTRY *LPALGETDOUBLE)( ALenum param );
+typedef ALenum         (AL_APIENTRY *LPALGETERROR)( void );
+typedef ALboolean      (AL_APIENTRY *LPALISEXTENSIONPRESENT)(const ALchar* extname );
+typedef void*          (AL_APIENTRY *LPALGETPROCADDRESS)( const ALchar* fname );
+typedef ALenum         (AL_APIENTRY *LPALGETENUMVALUE)( const ALchar* ename );
+typedef void           (AL_APIENTRY *LPALLISTENERF)( ALenum param, ALfloat value );
+typedef void           (AL_APIENTRY *LPALLISTENER3F)( ALenum param, ALfloat value1, ALfloat value2, ALfloat value3 );
+typedef void           (AL_APIENTRY *LPALLISTENERFV)( ALenum param, const ALfloat* values );
+typedef void           (AL_APIENTRY *LPALLISTENERI)( ALenum param, ALint value );
+typedef void           (AL_APIENTRY *LPALLISTENER3I)( ALenum param, ALint value1, ALint value2, ALint value3 );
+typedef void           (AL_APIENTRY *LPALLISTENERIV)( ALenum param, const ALint* values );
+typedef void           (AL_APIENTRY *LPALGETLISTENERF)( ALenum param, ALfloat* value );
+typedef void           (AL_APIENTRY *LPALGETLISTENER3F)( ALenum param, ALfloat *value1, ALfloat *value2, ALfloat *value3 );
+typedef void           (AL_APIENTRY *LPALGETLISTENERFV)( ALenum param, ALfloat* values );
+typedef void           (AL_APIENTRY *LPALGETLISTENERI)( ALenum param, ALint* value );
+typedef void           (AL_APIENTRY *LPALGETLISTENER3I)( ALenum param, ALint *value1, ALint *value2, ALint *value3 );
+typedef void           (AL_APIENTRY *LPALGETLISTENERIV)( ALenum param, ALint* values );
+typedef void           (AL_APIENTRY *LPALGENSOURCES)( ALsizei n, ALuint* sources ); 
+typedef void           (AL_APIENTRY *LPALDELETESOURCES)( ALsizei n, const ALuint* sources );
+typedef ALboolean      (AL_APIENTRY *LPALISSOURCE)( ALuint sid ); 
+typedef void           (AL_APIENTRY *LPALSOURCEF)( ALuint sid, ALenum param, ALfloat value); 
+typedef void           (AL_APIENTRY *LPALSOURCE3F)( ALuint sid, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3 );
+typedef void           (AL_APIENTRY *LPALSOURCEFV)( ALuint sid, ALenum param, const ALfloat* values );
+typedef void           (AL_APIENTRY *LPALSOURCEI)( ALuint sid, ALenum param, ALint value); 
+typedef void           (AL_APIENTRY *LPALSOURCE3I)( ALuint sid, ALenum param, ALint value1, ALint value2, ALint value3 );
+typedef void           (AL_APIENTRY *LPALSOURCEIV)( ALuint sid, ALenum param, const ALint* values );
+typedef void           (AL_APIENTRY *LPALGETSOURCEF)( ALuint sid, ALenum param, ALfloat* value );
+typedef void           (AL_APIENTRY *LPALGETSOURCE3F)( ALuint sid, ALenum param, ALfloat* value1, ALfloat* value2, ALfloat* value3);
+typedef void           (AL_APIENTRY *LPALGETSOURCEFV)( ALuint sid, ALenum param, ALfloat* values );
+typedef void           (AL_APIENTRY *LPALGETSOURCEI)( ALuint sid, ALenum param, ALint* value );
+typedef void           (AL_APIENTRY *LPALGETSOURCE3I)( ALuint sid, ALenum param, ALint* value1, ALint* value2, ALint* value3);
+typedef void           (AL_APIENTRY *LPALGETSOURCEIV)( ALuint sid, ALenum param, ALint* values );
+typedef void           (AL_APIENTRY *LPALSOURCEPLAYV)( ALsizei ns, const ALuint *sids );
+typedef void           (AL_APIENTRY *LPALSOURCESTOPV)( ALsizei ns, const ALuint *sids );
+typedef void           (AL_APIENTRY *LPALSOURCEREWINDV)( ALsizei ns, const ALuint *sids );
+typedef void           (AL_APIENTRY *LPALSOURCEPAUSEV)( ALsizei ns, const ALuint *sids );
+typedef void           (AL_APIENTRY *LPALSOURCEPLAY)( ALuint sid );
+typedef void           (AL_APIENTRY *LPALSOURCESTOP)( ALuint sid );
+typedef void           (AL_APIENTRY *LPALSOURCEREWIND)( ALuint sid );
+typedef void           (AL_APIENTRY *LPALSOURCEPAUSE)( ALuint sid );
+typedef void           (AL_APIENTRY *LPALSOURCEQUEUEBUFFERS)(ALuint sid, ALsizei numEntries, const ALuint *bids );
+typedef void           (AL_APIENTRY *LPALSOURCEUNQUEUEBUFFERS)(ALuint sid, ALsizei numEntries, ALuint *bids );
+typedef void           (AL_APIENTRY *LPALGENBUFFERS)( ALsizei n, ALuint* buffers );
+typedef void           (AL_APIENTRY *LPALDELETEBUFFERS)( ALsizei n, const ALuint* buffers );
+typedef ALboolean      (AL_APIENTRY *LPALISBUFFER)( ALuint bid );
+typedef void           (AL_APIENTRY *LPALBUFFERDATA)( ALuint bid, ALenum format, const ALvoid* data, ALsizei size, ALsizei freq );
+typedef void           (AL_APIENTRY *LPALBUFFERF)( ALuint bid, ALenum param, ALfloat value);
+typedef void           (AL_APIENTRY *LPALBUFFER3F)( ALuint bid, ALenum param, ALfloat value1, ALfloat value2, ALfloat value3 );
+typedef void           (AL_APIENTRY *LPALBUFFERFV)( ALuint bid, ALenum param, const ALfloat* values );
+typedef void           (AL_APIENTRY *LPALBUFFERI)( ALuint bid, ALenum param, ALint value);
+typedef void           (AL_APIENTRY *LPALBUFFER3I)( ALuint bid, ALenum param, ALint value1, ALint value2, ALint value3 );
+typedef void           (AL_APIENTRY *LPALBUFFERIV)( ALuint bid, ALenum param, const ALint* values );
+typedef void           (AL_APIENTRY *LPALGETBUFFERF)( ALuint bid, ALenum param, ALfloat* value );
+typedef void           (AL_APIENTRY *LPALGETBUFFER3F)( ALuint bid, ALenum param, ALfloat* value1, ALfloat* value2, ALfloat* value3);
+typedef void           (AL_APIENTRY *LPALGETBUFFERFV)( ALuint bid, ALenum param, ALfloat* values );
+typedef void           (AL_APIENTRY *LPALGETBUFFERI)( ALuint bid, ALenum param, ALint* value );
+typedef void           (AL_APIENTRY *LPALGETBUFFER3I)( ALuint bid, ALenum param, ALint* value1, ALint* value2, ALint* value3);
+typedef void           (AL_APIENTRY *LPALGETBUFFERIV)( ALuint bid, ALenum param, ALint* values );
+typedef void           (AL_APIENTRY *LPALDOPPLERFACTOR)( ALfloat value );
+typedef void           (AL_APIENTRY *LPALDOPPLERVELOCITY)( ALfloat value );
+typedef void           (AL_APIENTRY *LPALSPEEDOFSOUND)( ALfloat value );
+typedef void           (AL_APIENTRY *LPALDISTANCEMODEL)( ALenum distanceModel );
+
+#endif /* AL_NO_PROTOTYPES */
+
+#if TARGET_OS_MAC
+ #pragma export off
+#endif
+
+#if defined(__cplusplus)
+}  /* extern "C" */
+#endif
+
+#endif /* AL_AL_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/External/AL/alc.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,276 @@
+#ifndef AL_ALC_H
+#define AL_ALC_H
+
+#pragma once
+
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+#if defined(_WIN32) && !defined(_XBOX)
+ /* _OPENAL32LIB is deprecated */
+ #if defined(AL_BUILD_LIBRARY) || defined (_OPENAL32LIB)
+  #define ALC_API __declspec(dllexport)
+ #else
+  #define ALC_API __declspec(dllimport)
+ #endif
+#else
+ #define ALC_API extern
+#endif
+
+#if defined(_WIN32)
+ #define ALC_APIENTRY __cdecl
+#else
+ #define ALC_APIENTRY
+#endif
+
+#if TARGET_OS_MAC
+ #pragma export on
+#endif
+
+/* The ALCAPI, and ALCAPIENTRY macros are deprecated, but are included for applications porting code
+   from AL 1.0 */
+#define ALCAPI ALC_API
+#define ALCAPIENTRY ALC_APIENTRY
+
+#define ALC_VERSION_0_1         1
+
+typedef struct ALCdevice_struct ALCdevice;
+typedef struct ALCcontext_struct ALCcontext;
+
+
+/** 8-bit boolean */
+typedef char ALCboolean;
+
+/** character */
+typedef char ALCchar;
+
+/** signed 8-bit 2's complement integer */
+typedef char ALCbyte;
+
+/** unsigned 8-bit integer */
+typedef unsigned char ALCubyte;
+
+/** signed 16-bit 2's complement integer */
+typedef short ALCshort;
+
+/** unsigned 16-bit integer */
+typedef unsigned short ALCushort;
+
+/** signed 32-bit 2's complement integer */
+typedef int ALCint;
+
+/** unsigned 32-bit integer */
+typedef unsigned int ALCuint;
+
+/** non-negative 32-bit binary integer size */
+typedef int ALCsizei;
+
+/** enumerated 32-bit value */
+typedef int ALCenum;
+
+/** 32-bit IEEE754 floating-point */
+typedef float ALCfloat;
+
+/** 64-bit IEEE754 floating-point */
+typedef double ALCdouble;
+
+/** void type (for opaque pointers only) */
+typedef void ALCvoid;
+
+
+/* Enumerant values begin at column 50. No tabs. */
+
+/* bad value */
+#define ALC_INVALID                              0
+
+/* Boolean False. */
+#define ALC_FALSE                                0
+
+/* Boolean True. */
+#define ALC_TRUE                                 1
+
+/**
+ * followed by <int> Hz
+ */
+#define ALC_FREQUENCY                            0x1007
+
+/**
+ * followed by <int> Hz
+ */
+#define ALC_REFRESH                              0x1008
+
+/**
+ * followed by AL_TRUE, AL_FALSE
+ */
+#define ALC_SYNC                                 0x1009
+
+/**
+ * followed by <int> Num of requested Mono (3D) Sources
+ */
+#define ALC_MONO_SOURCES                         0x1010
+
+/**
+ * followed by <int> Num of requested Stereo Sources
+ */
+#define ALC_STEREO_SOURCES                       0x1011
+
+/**
+ * errors
+ */
+
+/**
+ * No error
+ */
+#define ALC_NO_ERROR                             ALC_FALSE
+
+/**
+ * No device
+ */
+#define ALC_INVALID_DEVICE                       0xA001
+
+/**
+ * invalid context ID
+ */
+#define ALC_INVALID_CONTEXT                      0xA002
+
+/**
+ * bad enum
+ */
+#define ALC_INVALID_ENUM                         0xA003
+
+/**
+ * bad value
+ */
+#define ALC_INVALID_VALUE                        0xA004
+
+/**
+ * Out of memory.
+ */
+#define ALC_OUT_OF_MEMORY                        0xA005
+
+
+/**
+ * The Specifier string for default device
+ */
+#define ALC_DEFAULT_DEVICE_SPECIFIER             0x1004
+#define ALC_DEVICE_SPECIFIER                     0x1005
+#define ALC_EXTENSIONS                           0x1006
+
+#define ALC_MAJOR_VERSION                        0x1000
+#define ALC_MINOR_VERSION                        0x1001
+
+#define ALC_ATTRIBUTES_SIZE                      0x1002
+#define ALC_ALL_ATTRIBUTES                       0x1003
+
+/**
+ * Capture extension
+ */
+#define ALC_CAPTURE_DEVICE_SPECIFIER             0x310
+#define ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER     0x311
+#define ALC_CAPTURE_SAMPLES                      0x312
+
+
+#if !defined(ALC_NO_PROTOTYPES)
+
+/*
+ * Context Management
+ */
+ALC_API ALCcontext *    ALC_APIENTRY alcCreateContext( ALCdevice *device, const ALCint* attrlist );
+
+ALC_API ALCboolean      ALC_APIENTRY alcMakeContextCurrent( ALCcontext *context );
+
+ALC_API void            ALC_APIENTRY alcProcessContext( ALCcontext *context );
+
+ALC_API void            ALC_APIENTRY alcSuspendContext( ALCcontext *context );
+
+ALC_API void            ALC_APIENTRY alcDestroyContext( ALCcontext *context );
+
+ALC_API ALCcontext *    ALC_APIENTRY alcGetCurrentContext( ALCvoid );
+
+ALC_API ALCdevice*      ALC_APIENTRY alcGetContextsDevice( ALCcontext *context );
+
+
+/*
+ * Device Management
+ */
+ALC_API ALCdevice *     ALC_APIENTRY alcOpenDevice( const ALCchar *devicename );
+
+ALC_API ALCboolean      ALC_APIENTRY alcCloseDevice( ALCdevice *device );
+
+
+/*
+ * Error support.
+ * Obtain the most recent Context error
+ */
+ALC_API ALCenum         ALC_APIENTRY alcGetError( ALCdevice *device );
+
+
+/* 
+ * Extension support.
+ * Query for the presence of an extension, and obtain any appropriate
+ * function pointers and enum values.
+ */
+ALC_API ALCboolean      ALC_APIENTRY alcIsExtensionPresent( ALCdevice *device, const ALCchar *extname );
+
+ALC_API void  *         ALC_APIENTRY alcGetProcAddress( ALCdevice *device, const ALCchar *funcname );
+
+ALC_API ALCenum         ALC_APIENTRY alcGetEnumValue( ALCdevice *device, const ALCchar *enumname );
+
+
+/*
+ * Query functions
+ */
+ALC_API const ALCchar * ALC_APIENTRY alcGetString( ALCdevice *device, ALCenum param );
+
+ALC_API void            ALC_APIENTRY alcGetIntegerv( ALCdevice *device, ALCenum param, ALCsizei size, ALCint *data );
+
+
+/*
+ * Capture functions
+ */
+ALC_API ALCdevice*      ALC_APIENTRY alcCaptureOpenDevice( const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize );
+
+ALC_API ALCboolean      ALC_APIENTRY alcCaptureCloseDevice( ALCdevice *device );
+
+ALC_API void            ALC_APIENTRY alcCaptureStart( ALCdevice *device );
+
+ALC_API void            ALC_APIENTRY alcCaptureStop( ALCdevice *device );
+
+ALC_API void            ALC_APIENTRY alcCaptureSamples( ALCdevice *device, ALCvoid *buffer, ALCsizei samples );
+
+#else /* ALC_NO_PROTOTYPES */
+
+typedef ALCcontext *   (ALC_APIENTRY *LPALCCREATECONTEXT) (ALCdevice *device, const ALCint *attrlist);
+typedef ALCboolean     (ALC_APIENTRY *LPALCMAKECONTEXTCURRENT)( ALCcontext *context );
+typedef void           (ALC_APIENTRY *LPALCPROCESSCONTEXT)( ALCcontext *context );
+typedef void           (ALC_APIENTRY *LPALCSUSPENDCONTEXT)( ALCcontext *context );
+typedef void           (ALC_APIENTRY *LPALCDESTROYCONTEXT)( ALCcontext *context );
+typedef ALCcontext *   (ALC_APIENTRY *LPALCGETCURRENTCONTEXT)( ALCvoid );
+typedef ALCdevice *    (ALC_APIENTRY *LPALCGETCONTEXTSDEVICE)( ALCcontext *context );
+typedef ALCdevice *    (ALC_APIENTRY *LPALCOPENDEVICE)( const ALCchar *devicename );
+typedef ALCboolean     (ALC_APIENTRY *LPALCCLOSEDEVICE)( ALCdevice *device );
+typedef ALCenum        (ALC_APIENTRY *LPALCGETERROR)( ALCdevice *device );
+typedef ALCboolean     (ALC_APIENTRY *LPALCISEXTENSIONPRESENT)( ALCdevice *device, const ALCchar *extname );
+typedef void *         (ALC_APIENTRY *LPALCGETPROCADDRESS)(ALCdevice *device, const ALCchar *funcname );
+typedef ALCenum        (ALC_APIENTRY *LPALCGETENUMVALUE)(ALCdevice *device, const ALCchar *enumname );
+typedef const ALCchar* (ALC_APIENTRY *LPALCGETSTRING)( ALCdevice *device, ALCenum param );
+typedef void           (ALC_APIENTRY *LPALCGETINTEGERV)( ALCdevice *device, ALCenum param, ALCsizei size, ALCint *dest );
+typedef ALCdevice *    (ALC_APIENTRY *LPALCCAPTUREOPENDEVICE)( const ALCchar *devicename, ALCuint frequency, ALCenum format, ALCsizei buffersize );
+typedef ALCboolean     (ALC_APIENTRY *LPALCCAPTURECLOSEDEVICE)( ALCdevice *device );
+typedef void           (ALC_APIENTRY *LPALCCAPTURESTART)( ALCdevice *device );
+typedef void           (ALC_APIENTRY *LPALCCAPTURESTOP)( ALCdevice *device );
+typedef void           (ALC_APIENTRY *LPALCCAPTURESAMPLES)( ALCdevice *device, ALCvoid *buffer, ALCsizei samples );
+
+#endif /* ALC_NO_PROTOTYPES */
+
+#if TARGET_OS_MAC
+ #pragma export off
+#endif
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* AL_ALC_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/External/JPEG/README.libjpeg	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,385 @@
+The Independent JPEG Group's JPEG software
+==========================================
+
+README for release 6b of 27-Mar-1998
+====================================
+
+This distribution contains the sixth public release of the Independent JPEG
+Group's free JPEG software.  You are welcome to redistribute this software and
+to use it for any purpose, subject to the conditions under LEGAL ISSUES, below.
+
+Serious users of this software (particularly those incorporating it into
+larger programs) should contact IJG at jpeg-info@uunet.uu.net to be added to
+our electronic mailing list.  Mailing list members are notified of updates
+and have a chance to participate in technical discussions, etc.
+
+This software is the work of Tom Lane, Philip Gladstone, Jim Boucher,
+Lee Crocker, Julian Minguillon, Luis Ortiz, George Phillips, Davide Rossi,
+Guido Vollbeding, Ge' Weijers, and other members of the Independent JPEG
+Group.
+
+IJG is not affiliated with the official ISO JPEG standards committee.
+
+
+DOCUMENTATION ROADMAP
+=====================
+
+This file contains the following sections:
+
+OVERVIEW            General description of JPEG and the IJG software.
+LEGAL ISSUES        Copyright, lack of warranty, terms of distribution.
+REFERENCES          Where to learn more about JPEG.
+ARCHIVE LOCATIONS   Where to find newer versions of this software.
+RELATED SOFTWARE    Other stuff you should get.
+FILE FORMAT WARS    Software *not* to get.
+TO DO               Plans for future IJG releases.
+
+Other documentation files in the distribution are:
+
+User documentation:
+  install.doc       How to configure and install the IJG software.
+  usage.doc         Usage instructions for cjpeg, djpeg, jpegtran,
+                    rdjpgcom, and wrjpgcom.
+  *.1               Unix-style man pages for programs (same info as usage.doc).
+  wizard.doc        Advanced usage instructions for JPEG wizards only.
+  change.log        Version-to-version change highlights.
+Programmer and internal documentation:
+  libjpeg.doc       How to use the JPEG library in your own programs.
+  example.c         Sample code for calling the JPEG library.
+  structure.doc     Overview of the JPEG library's internal structure.
+  filelist.doc      Road map of IJG files.
+  coderules.doc     Coding style rules --- please read if you contribute code.
+
+Please read at least the files install.doc and usage.doc.  Useful information
+can also be found in the JPEG FAQ (Frequently Asked Questions) article.  See
+ARCHIVE LOCATIONS below to find out where to obtain the FAQ article.
+
+If you want to understand how the JPEG code works, we suggest reading one or
+more of the REFERENCES, then looking at the documentation files (in roughly
+the order listed) before diving into the code.
+
+
+OVERVIEW
+========
+
+This package contains C software to implement JPEG image compression and
+decompression.  JPEG (pronounced "jay-peg") is a standardized compression
+method for full-color and gray-scale images.  JPEG is intended for compressing
+"real-world" scenes; line drawings, cartoons and other non-realistic images
+are not its strong suit.  JPEG is lossy, meaning that the output image is not
+exactly identical to the input image.  Hence you must not use JPEG if you
+have to have identical output bits.  However, on typical photographic images,
+very good compression levels can be obtained with no visible change, and
+remarkably high compression levels are possible if you can tolerate a
+low-quality image.  For more details, see the references, or just experiment
+with various compression settings.
+
+This software implements JPEG baseline, extended-sequential, and progressive
+compression processes.  Provision is made for supporting all variants of these
+processes, although some uncommon parameter settings aren't implemented yet.
+For legal reasons, we are not distributing code for the arithmetic-coding
+variants of JPEG; see LEGAL ISSUES.  We have made no provision for supporting
+the hierarchical or lossless processes defined in the standard.
+
+We provide a set of library routines for reading and writing JPEG image files,
+plus two sample applications "cjpeg" and "djpeg", which use the library to
+perform conversion between JPEG and some other popular image file formats.
+The library is intended to be reused in other applications.
+
+In order to support file conversion and viewing software, we have included
+considerable functionality beyond the bare JPEG coding/decoding capability;
+for example, the color quantization modules are not strictly part of JPEG
+decoding, but they are essential for output to colormapped file formats or
+colormapped displays.  These extra functions can be compiled out of the
+library if not required for a particular application.  We have also included
+"jpegtran", a utility for lossless transcoding between different JPEG
+processes, and "rdjpgcom" and "wrjpgcom", two simple applications for
+inserting and extracting textual comments in JFIF files.
+
+The emphasis in designing this software has been on achieving portability and
+flexibility, while also making it fast enough to be useful.  In particular,
+the software is not intended to be read as a tutorial on JPEG.  (See the
+REFERENCES section for introductory material.)  Rather, it is intended to
+be reliable, portable, industrial-strength code.  We do not claim to have
+achieved that goal in every aspect of the software, but we strive for it.
+
+We welcome the use of this software as a component of commercial products.
+No royalty is required, but we do ask for an acknowledgement in product
+documentation, as described under LEGAL ISSUES.
+
+
+LEGAL ISSUES
+============
+
+In plain English:
+
+1. We don't promise that this software works.  (But if you find any bugs,
+   please let us know!)
+2. You can use this software for whatever you want.  You don't have to pay us.
+3. You may not pretend that you wrote this software.  If you use it in a
+   program, you must acknowledge somewhere in your documentation that
+   you've used the IJG code.
+
+In legalese:
+
+The authors make NO WARRANTY or representation, either express or implied,
+with respect to this software, its quality, accuracy, merchantability, or
+fitness for a particular purpose.  This software is provided "AS IS", and you,
+its user, assume the entire risk as to its quality and accuracy.
+
+This software is copyright (C) 1991-1998, Thomas G. Lane.
+All Rights Reserved except as specified below.
+
+Permission is hereby granted to use, copy, modify, and distribute this
+software (or portions thereof) for any purpose, without fee, subject to these
+conditions:
+(1) If any part of the source code for this software is distributed, then this
+README file must be included, with this copyright and no-warranty notice
+unaltered; and any additions, deletions, or changes to the original files
+must be clearly indicated in accompanying documentation.
+(2) If only executable code is distributed, then the accompanying
+documentation must state that "this software is based in part on the work of
+the Independent JPEG Group".
+(3) Permission for use of this software is granted only if the user accepts
+full responsibility for any undesirable consequences; the authors accept
+NO LIABILITY for damages of any kind.
+
+These conditions apply to any software derived from or based on the IJG code,
+not just to the unmodified library.  If you use our work, you ought to
+acknowledge us.
+
+Permission is NOT granted for the use of any IJG author's name or company name
+in advertising or publicity relating to this software or products derived from
+it.  This software may be referred to only as "the Independent JPEG Group's
+software".
+
+We specifically permit and encourage the use of this software as the basis of
+commercial products, provided that all warranty or liability claims are
+assumed by the product vendor.
+
+
+ansi2knr.c is included in this distribution by permission of L. Peter Deutsch,
+sole proprietor of its copyright holder, Aladdin Enterprises of Menlo Park, CA.
+ansi2knr.c is NOT covered by the above copyright and conditions, but instead
+by the usual distribution terms of the Free Software Foundation; principally,
+that you must include source code if you redistribute it.  (See the file
+ansi2knr.c for full details.)  However, since ansi2knr.c is not needed as part
+of any program generated from the IJG code, this does not limit you more than
+the foregoing paragraphs do.
+
+The Unix configuration script "configure" was produced with GNU Autoconf.
+It is copyright by the Free Software Foundation but is freely distributable.
+The same holds for its supporting scripts (config.guess, config.sub,
+ltconfig, ltmain.sh).  Another support script, install-sh, is copyright
+by M.I.T. but is also freely distributable.
+
+It appears that the arithmetic coding option of the JPEG spec is covered by
+patents owned by IBM, AT&T, and Mitsubishi.  Hence arithmetic coding cannot
+legally be used without obtaining one or more licenses.  For this reason,
+support for arithmetic coding has been removed from the free JPEG software.
+(Since arithmetic coding provides only a marginal gain over the unpatented
+Huffman mode, it is unlikely that very many implementations will support it.)
+So far as we are aware, there are no patent restrictions on the remaining
+code.
+
+The IJG distribution formerly included code to read and write GIF files.
+To avoid entanglement with the Unisys LZW patent, GIF reading support has
+been removed altogether, and the GIF writer has been simplified to produce
+"uncompressed GIFs".  This technique does not use the LZW algorithm; the
+resulting GIF files are larger than usual, but are readable by all standard
+GIF decoders.
+
+We are required to state that
+    "The Graphics Interchange Format(c) is the Copyright property of
+    CompuServe Incorporated.  GIF(sm) is a Service Mark property of
+    CompuServe Incorporated."
+
+
+REFERENCES
+==========
+
+We highly recommend reading one or more of these references before trying to
+understand the innards of the JPEG software.
+
+The best short technical introduction to the JPEG compression algorithm is
+	Wallace, Gregory K.  "The JPEG Still Picture Compression Standard",
+	Communications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.
+(Adjacent articles in that issue discuss MPEG motion picture compression,
+applications of JPEG, and related topics.)  If you don't have the CACM issue
+handy, a PostScript file containing a revised version of Wallace's article is
+available at ftp://ftp.uu.net/graphics/jpeg/wallace.ps.gz.  The file (actually
+a preprint for an article that appeared in IEEE Trans. Consumer Electronics)
+omits the sample images that appeared in CACM, but it includes corrections
+and some added material.  Note: the Wallace article is copyright ACM and IEEE,
+and it may not be used for commercial purposes.
+
+A somewhat less technical, more leisurely introduction to JPEG can be found in
+"The Data Compression Book" by Mark Nelson and Jean-loup Gailly, published by
+M&T Books (New York), 2nd ed. 1996, ISBN 1-55851-434-1.  This book provides
+good explanations and example C code for a multitude of compression methods
+including JPEG.  It is an excellent source if you are comfortable reading C
+code but don't know much about data compression in general.  The book's JPEG
+sample code is far from industrial-strength, but when you are ready to look
+at a full implementation, you've got one here...
+
+The best full description of JPEG is the textbook "JPEG Still Image Data
+Compression Standard" by William B. Pennebaker and Joan L. Mitchell, published
+by Van Nostrand Reinhold, 1993, ISBN 0-442-01272-1.  Price US$59.95, 638 pp.
+The book includes the complete text of the ISO JPEG standards (DIS 10918-1
+and draft DIS 10918-2).  This is by far the most complete exposition of JPEG
+in existence, and we highly recommend it.
+
+The JPEG standard itself is not available electronically; you must order a
+paper copy through ISO or ITU.  (Unless you feel a need to own a certified
+official copy, we recommend buying the Pennebaker and Mitchell book instead;
+it's much cheaper and includes a great deal of useful explanatory material.)
+In the USA, copies of the standard may be ordered from ANSI Sales at (212)
+642-4900, or from Global Engineering Documents at (800) 854-7179.  (ANSI
+doesn't take credit card orders, but Global does.)  It's not cheap: as of
+1992, ANSI was charging $95 for Part 1 and $47 for Part 2, plus 7%
+shipping/handling.  The standard is divided into two parts, Part 1 being the
+actual specification, while Part 2 covers compliance testing methods.  Part 1
+is titled "Digital Compression and Coding of Continuous-tone Still Images,
+Part 1: Requirements and guidelines" and has document numbers ISO/IEC IS
+10918-1, ITU-T T.81.  Part 2 is titled "Digital Compression and Coding of
+Continuous-tone Still Images, Part 2: Compliance testing" and has document
+numbers ISO/IEC IS 10918-2, ITU-T T.83.
+
+Some extensions to the original JPEG standard are defined in JPEG Part 3,
+a newer ISO standard numbered ISO/IEC IS 10918-3 and ITU-T T.84.  IJG
+currently does not support any Part 3 extensions.
+
+The JPEG standard does not specify all details of an interchangeable file
+format.  For the omitted details we follow the "JFIF" conventions, revision
+1.02.  A copy of the JFIF spec is available from:
+	Literature Department
+	C-Cube Microsystems, Inc.
+	1778 McCarthy Blvd.
+	Milpitas, CA 95035
+	phone (408) 944-6300,  fax (408) 944-6314
+A PostScript version of this document is available by FTP at
+ftp://ftp.uu.net/graphics/jpeg/jfif.ps.gz.  There is also a plain text
+version at ftp://ftp.uu.net/graphics/jpeg/jfif.txt.gz, but it is missing
+the figures.
+
+The TIFF 6.0 file format specification can be obtained by FTP from
+ftp://ftp.sgi.com/graphics/tiff/TIFF6.ps.gz.  The JPEG incorporation scheme
+found in the TIFF 6.0 spec of 3-June-92 has a number of serious problems.
+IJG does not recommend use of the TIFF 6.0 design (TIFF Compression tag 6).
+Instead, we recommend the JPEG design proposed by TIFF Technical Note #2
+(Compression tag 7).  Copies of this Note can be obtained from ftp.sgi.com or
+from ftp://ftp.uu.net/graphics/jpeg/.  It is expected that the next revision
+of the TIFF spec will replace the 6.0 JPEG design with the Note's design.
+Although IJG's own code does not support TIFF/JPEG, the free libtiff library
+uses our library to implement TIFF/JPEG per the Note.  libtiff is available
+from ftp://ftp.sgi.com/graphics/tiff/.
+
+
+ARCHIVE LOCATIONS
+=================
+
+The "official" archive site for this software is ftp.uu.net (Internet
+address 192.48.96.9).  The most recent released version can always be found
+there in directory graphics/jpeg.  This particular version will be archived
+as ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz.  If you don't have
+direct Internet access, UUNET's archives are also available via UUCP; contact
+help@uunet.uu.net for information on retrieving files that way.
+
+Numerous Internet sites maintain copies of the UUNET files.  However, only
+ftp.uu.net is guaranteed to have the latest official version.
+
+You can also obtain this software in DOS-compatible "zip" archive format from
+the SimTel archives (ftp://ftp.simtel.net/pub/simtelnet/msdos/graphics/), or
+on CompuServe in the Graphics Support forum (GO CIS:GRAPHSUP), library 12
+"JPEG Tools".  Again, these versions may sometimes lag behind the ftp.uu.net
+release.
+
+The JPEG FAQ (Frequently Asked Questions) article is a useful source of
+general information about JPEG.  It is updated constantly and therefore is
+not included in this distribution.  The FAQ is posted every two weeks to
+Usenet newsgroups comp.graphics.misc, news.answers, and other groups.
+It is available on the World Wide Web at http://www.faqs.org/faqs/jpeg-faq/
+and other news.answers archive sites, including the official news.answers
+archive at rtfm.mit.edu: ftp://rtfm.mit.edu/pub/usenet/news.answers/jpeg-faq/.
+If you don't have Web or FTP access, send e-mail to mail-server@rtfm.mit.edu
+with body
+	send usenet/news.answers/jpeg-faq/part1
+	send usenet/news.answers/jpeg-faq/part2
+
+
+RELATED SOFTWARE
+================
+
+Numerous viewing and image manipulation programs now support JPEG.  (Quite a
+few of them use this library to do so.)  The JPEG FAQ described above lists
+some of the more popular free and shareware viewers, and tells where to
+obtain them on Internet.
+
+If you are on a Unix machine, we highly recommend Jef Poskanzer's free
+PBMPLUS software, which provides many useful operations on PPM-format image
+files.  In particular, it can convert PPM images to and from a wide range of
+other formats, thus making cjpeg/djpeg considerably more useful.  The latest
+version is distributed by the NetPBM group, and is available from numerous
+sites, notably ftp://wuarchive.wustl.edu/graphics/graphics/packages/NetPBM/.
+Unfortunately PBMPLUS/NETPBM is not nearly as portable as the IJG software is;
+you are likely to have difficulty making it work on any non-Unix machine.
+
+A different free JPEG implementation, written by the PVRG group at Stanford,
+is available from ftp://havefun.stanford.edu/pub/jpeg/.  This program
+is designed for research and experimentation rather than production use;
+it is slower, harder to use, and less portable than the IJG code, but it
+is easier to read and modify.  Also, the PVRG code supports lossless JPEG,
+which we do not.  (On the other hand, it doesn't do progressive JPEG.)
+
+
+FILE FORMAT WARS
+================
+
+Some JPEG programs produce files that are not compatible with our library.
+The root of the problem is that the ISO JPEG committee failed to specify a
+concrete file format.  Some vendors "filled in the blanks" on their own,
+creating proprietary formats that no one else could read.  (For example, none
+of the early commercial JPEG implementations for the Macintosh were able to
+exchange compressed files.)
+
+The file format we have adopted is called JFIF (see REFERENCES).  This format
+has been agreed to by a number of major commercial JPEG vendors, and it has
+become the de facto standard.  JFIF is a minimal or "low end" representation.
+We recommend the use of TIFF/JPEG (TIFF revision 6.0 as modified by TIFF
+Technical Note #2) for "high end" applications that need to record a lot of
+additional data about an image.  TIFF/JPEG is fairly new and not yet widely
+supported, unfortunately.
+
+The upcoming JPEG Part 3 standard defines a file format called SPIFF.
+SPIFF is interoperable with JFIF, in the sense that most JFIF decoders should
+be able to read the most common variant of SPIFF.  SPIFF has some technical
+advantages over JFIF, but its major claim to fame is simply that it is an
+official standard rather than an informal one.  At this point it is unclear
+whether SPIFF will supersede JFIF or whether JFIF will remain the de-facto
+standard.  IJG intends to support SPIFF once the standard is frozen, but we
+have not decided whether it should become our default output format or not.
+(In any case, our decoder will remain capable of reading JFIF indefinitely.)
+
+Various proprietary file formats incorporating JPEG compression also exist.
+We have little or no sympathy for the existence of these formats.  Indeed,
+one of the original reasons for developing this free software was to help
+force convergence on common, open format standards for JPEG files.  Don't
+use a proprietary file format!
+
+
+TO DO
+=====
+
+The major thrust for v7 will probably be improvement of visual quality.
+The current method for scaling the quantization tables is known not to be
+very good at low Q values.  We also intend to investigate block boundary
+smoothing, "poor man's variable quantization", and other means of improving
+quality-vs-file-size performance without sacrificing compatibility.
+
+In future versions, we are considering supporting some of the upcoming JPEG
+Part 3 extensions --- principally, variable quantization and the SPIFF file
+format.
+
+As always, speeding things up is of great interest.
+
+Please send bug reports, offers of help, etc. to jpeg-info@uunet.uu.net.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/External/JPEG/jconfig.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,58 @@
+/* jconfig.h.  Generated automatically by configure.  */
+/* jconfig.cfg --- source file edited by configure script */
+/* see jconfig.doc for explanations */
+
+#define HAVE_PROTOTYPES 
+#define HAVE_UNSIGNED_CHAR 
+#define HAVE_UNSIGNED_SHORT 
+
+#ifdef _WIN32
+# include <windows.h>
+/* Define "boolean" as unsigned char, not int, per Windows custom */
+# if !defined __RPCNDR_H__ || defined __MINGW32__    /* don't conflict if rpcndr.h already read */
+#  ifndef boolean     /* don't conflict if rpcndr.h already read */
+    typedef unsigned char boolean;
+#  endif /* boolean */
+# endif /* __RPCNDR_H__ */
+# define HAVE_BOOLEAN     /* prevent jmorecfg.h from redefining it */
+# define USE_WINDOWS_MESSAGEBOX 1
+#endif /* _WIN32 */
+
+#undef void
+#undef const
+#undef CHAR_IS_UNSIGNED
+#define HAVE_STDDEF_H 
+#define HAVE_STDLIB_H 
+#undef NEED_BSD_STRINGS
+#undef NEED_SYS_TYPES_H
+#undef NEED_FAR_POINTERS
+#undef NEED_SHORT_EXTERNAL_NAMES
+/* Define this if you get warnings about undefined structures. */
+#undef INCOMPLETE_TYPES_BROKEN
+
+#ifdef JPEG_INTERNALS
+
+#undef RIGHT_SHIFT_IS_UNSIGNED
+#define INLINE __inline__
+/* These are for configuring the JPEG memory manager. */
+#undef DEFAULT_MAX_MEM
+#undef NO_MKTEMP
+
+#endif /* JPEG_INTERNALS */
+
+#ifdef JPEG_CJPEG_DJPEG
+
+#define BMP_SUPPORTED		/* BMP image file format */
+#define GIF_SUPPORTED		/* GIF image file format */
+#define PPM_SUPPORTED		/* PBMPLUS PPM/PGM image file format */
+#define RLE_SUPPORTED		/* Utah RLE image file format */
+#define TARGA_SUPPORTED		/* Targa image file format */
+
+#undef TWO_FILE_COMMANDLINE
+#undef NEED_SIGNAL_CATCHER
+#undef DONT_USE_B_MODE
+
+/* Define this if you want percent-done progress reports from cjpeg/djpeg. */
+#undef PROGRESS_REPORT
+
+#endif /* JPEG_CJPEG_DJPEG */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/External/JPEG/jerror.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,303 @@
+/*
+ * jerror.h
+ *
+ * Copyright (C) 1994-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file defines the error and message codes for the JPEG library.
+ * Edit this file to add new codes, or to translate the message strings to
+ * some other language.
+ * A set of error-reporting macros are defined too.  Some applications using
+ * the JPEG library may wish to include this file to get the error codes
+ * and/or the macros.
+ */
+
+/*
+ * To define the enum list of message codes, include this file without
+ * defining macro JMESSAGE.  To create a message string table, include it
+ * again with a suitable JMESSAGE definition (see jerror.c for an example).
+ */
+#ifndef JMESSAGE
+#ifndef JERROR_H
+/* First time through, define the enum list */
+#define JMAKE_ENUM_LIST
+#else
+/* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */
+#define JMESSAGE(code,string)
+#endif /* JERROR_H */
+#endif /* JMESSAGE */
+
+#ifdef JMAKE_ENUM_LIST
+
+typedef enum {
+
+#define JMESSAGE(code,string)	code ,
+
+#endif /* JMAKE_ENUM_LIST */
+
+JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
+
+/* For maintenance convenience, list is alphabetical by message code name */
+JMESSAGE(JERR_ARITH_NOTIMPL,
+	 "Sorry, there are legal restrictions on arithmetic coding")
+JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
+JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
+JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
+JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
+JMESSAGE(JERR_BAD_CROP_SPEC, "Invalid crop request")
+JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
+JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
+JMESSAGE(JERR_BAD_DROP_SAMPLING,
+        "Component index %d: mismatching sampling ratio %d:%d, %d:%d, %c")
+JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
+JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
+JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
+JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
+JMESSAGE(JERR_BAD_LIB_VERSION,
+	 "Wrong JPEG library version: library is %d, caller expects %d")
+JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
+JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
+JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
+JMESSAGE(JERR_BAD_PROGRESSION,
+	 "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
+JMESSAGE(JERR_BAD_PROG_SCRIPT,
+	 "Invalid progressive parameters at scan script entry %d")
+JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
+JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
+JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
+JMESSAGE(JERR_BAD_STRUCT_SIZE,
+	 "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
+JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
+JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
+JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
+JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
+JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
+JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
+JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
+JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
+JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
+JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
+JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
+JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
+JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
+JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
+JMESSAGE(JERR_FILE_READ, "Input file read error")
+JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
+JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
+JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
+JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
+JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
+JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
+JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
+JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
+	 "Cannot transcode due to multiple use of quantization table %d")
+JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
+JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
+JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
+JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
+JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
+JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
+JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
+JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
+JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
+JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
+JMESSAGE(JERR_QUANT_COMPONENTS,
+	 "Cannot quantize more than %d color components")
+JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
+JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
+JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
+JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
+JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
+JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
+JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
+JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
+JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
+JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
+JMESSAGE(JERR_TFILE_WRITE,
+	 "Write failed on temporary file --- out of disk space?")
+JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
+JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
+JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
+JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
+JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
+JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
+JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
+JMESSAGE(JMSG_VERSION, JVERSION)
+JMESSAGE(JTRC_16BIT_TABLES,
+	 "Caution: quantization tables are too coarse for baseline JPEG")
+JMESSAGE(JTRC_ADOBE,
+	 "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
+JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
+JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
+JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
+JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
+JMESSAGE(JTRC_DQT, "Define Quantization Table %d  precision %d")
+JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
+JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
+JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
+JMESSAGE(JTRC_EOI, "End Of Image")
+JMESSAGE(JTRC_HUFFBITS, "        %3d %3d %3d %3d %3d %3d %3d %3d")
+JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d  %d")
+JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
+	 "Warning: thumbnail image size does not match data length %u")
+JMESSAGE(JTRC_JFIF_EXTENSION,
+	 "JFIF extension marker: type 0x%02x, length %u")
+JMESSAGE(JTRC_JFIF_THUMBNAIL, "    with %d x %d thumbnail image")
+JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
+JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
+JMESSAGE(JTRC_QUANTVALS, "        %4u %4u %4u %4u %4u %4u %4u %4u")
+JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
+JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
+JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
+JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
+JMESSAGE(JTRC_RST, "RST%d")
+JMESSAGE(JTRC_SMOOTH_NOTIMPL,
+	 "Smoothing not supported with nonstandard sampling ratios")
+JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
+JMESSAGE(JTRC_SOF_COMPONENT, "    Component %d: %dhx%dv q=%d")
+JMESSAGE(JTRC_SOI, "Start of Image")
+JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
+JMESSAGE(JTRC_SOS_COMPONENT, "    Component %d: dc=%d ac=%d")
+JMESSAGE(JTRC_SOS_PARAMS, "  Ss=%d, Se=%d, Ah=%d, Al=%d")
+JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
+JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
+JMESSAGE(JTRC_THUMB_JPEG,
+	 "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
+JMESSAGE(JTRC_THUMB_PALETTE,
+	 "JFIF extension marker: palette thumbnail image, length %u")
+JMESSAGE(JTRC_THUMB_RGB,
+	 "JFIF extension marker: RGB thumbnail image, length %u")
+JMESSAGE(JTRC_UNKNOWN_IDS,
+	 "Unrecognized component IDs %d %d %d, assuming YCbCr")
+JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
+JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
+JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
+JMESSAGE(JWRN_BOGUS_PROGRESSION,
+	 "Inconsistent progression sequence for component %d coefficient %d")
+JMESSAGE(JWRN_EXTRANEOUS_DATA,
+	 "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
+JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
+JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
+JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
+JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
+JMESSAGE(JWRN_MUST_RESYNC,
+	 "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
+JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
+JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
+
+#ifdef JMAKE_ENUM_LIST
+
+  JMSG_LASTMSGCODE
+} J_MESSAGE_CODE;
+
+#undef JMAKE_ENUM_LIST
+#endif /* JMAKE_ENUM_LIST */
+
+/* Zap JMESSAGE macro so that future re-inclusions do nothing by default */
+#undef JMESSAGE
+
+
+#ifndef JERROR_H
+#define JERROR_H
+
+/* Macros to simplify using the error and trace message stuff */
+/* The first parameter is either type of cinfo pointer */
+
+/* Fatal errors (print message and exit) */
+#define ERREXIT(cinfo,code)  \
+  ((cinfo)->err->msg_code = (code), \
+   (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
+#define ERREXIT1(cinfo,code,p1)  \
+  ((cinfo)->err->msg_code = (code), \
+   (cinfo)->err->msg_parm.i[0] = (p1), \
+   (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
+#define ERREXIT2(cinfo,code,p1,p2)  \
+  ((cinfo)->err->msg_code = (code), \
+   (cinfo)->err->msg_parm.i[0] = (p1), \
+   (cinfo)->err->msg_parm.i[1] = (p2), \
+   (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
+#define ERREXIT3(cinfo,code,p1,p2,p3)  \
+  ((cinfo)->err->msg_code = (code), \
+   (cinfo)->err->msg_parm.i[0] = (p1), \
+   (cinfo)->err->msg_parm.i[1] = (p2), \
+   (cinfo)->err->msg_parm.i[2] = (p3), \
+   (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
+#define ERREXIT4(cinfo,code,p1,p2,p3,p4)  \
+  ((cinfo)->err->msg_code = (code), \
+   (cinfo)->err->msg_parm.i[0] = (p1), \
+   (cinfo)->err->msg_parm.i[1] = (p2), \
+   (cinfo)->err->msg_parm.i[2] = (p3), \
+   (cinfo)->err->msg_parm.i[3] = (p4), \
+   (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
+#define ERREXIT6(cinfo,code,p1,p2,p3,p4,p5,p6)  \
+  ((cinfo)->err->msg_code = (code), \
+   (cinfo)->err->msg_parm.i[0] = (p1), \
+   (cinfo)->err->msg_parm.i[1] = (p2), \
+   (cinfo)->err->msg_parm.i[2] = (p3), \
+   (cinfo)->err->msg_parm.i[3] = (p4), \
+   (cinfo)->err->msg_parm.i[4] = (p5), \
+   (cinfo)->err->msg_parm.i[5] = (p6), \
+   (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
+#define ERREXITS(cinfo,code,str)  \
+  ((cinfo)->err->msg_code = (code), \
+   strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
+   (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
+
+#define MAKESTMT(stuff)		do { stuff } while (0)
+
+/* Nonfatal errors (we can keep going, but the data is probably corrupt) */
+#define WARNMS(cinfo,code)  \
+  ((cinfo)->err->msg_code = (code), \
+   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
+#define WARNMS1(cinfo,code,p1)  \
+  ((cinfo)->err->msg_code = (code), \
+   (cinfo)->err->msg_parm.i[0] = (p1), \
+   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
+#define WARNMS2(cinfo,code,p1,p2)  \
+  ((cinfo)->err->msg_code = (code), \
+   (cinfo)->err->msg_parm.i[0] = (p1), \
+   (cinfo)->err->msg_parm.i[1] = (p2), \
+   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
+
+/* Informational/debugging messages */
+#define TRACEMS(cinfo,lvl,code)  \
+  ((cinfo)->err->msg_code = (code), \
+   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
+#define TRACEMS1(cinfo,lvl,code,p1)  \
+  ((cinfo)->err->msg_code = (code), \
+   (cinfo)->err->msg_parm.i[0] = (p1), \
+   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
+#define TRACEMS2(cinfo,lvl,code,p1,p2)  \
+  ((cinfo)->err->msg_code = (code), \
+   (cinfo)->err->msg_parm.i[0] = (p1), \
+   (cinfo)->err->msg_parm.i[1] = (p2), \
+   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
+#define TRACEMS3(cinfo,lvl,code,p1,p2,p3)  \
+  MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
+	   _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
+	   (cinfo)->err->msg_code = (code); \
+	   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
+#define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4)  \
+  MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
+	   _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
+	   (cinfo)->err->msg_code = (code); \
+	   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
+#define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5)  \
+  MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
+	   _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
+	   _mp[4] = (p5); \
+	   (cinfo)->err->msg_code = (code); \
+	   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
+#define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8)  \
+  MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
+	   _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
+	   _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
+	   (cinfo)->err->msg_code = (code); \
+	   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
+#define TRACEMSS(cinfo,lvl,code,str)  \
+  ((cinfo)->err->msg_code = (code), \
+   strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
+   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
+
+#endif /* JERROR_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/External/JPEG/jmorecfg.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,426 @@
+/*
+ * jmorecfg.h
+ *
+ * Copyright (C) 1991-1997, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file contains additional configuration options that customize the
+ * JPEG software for special applications or support machine-dependent
+ * optimizations.  Most users will not need to touch this file.
+ */
+
+
+/*
+ * Define BITS_IN_JSAMPLE as either
+ *   8   for 8-bit sample values (the usual setting)
+ *   12  for 12-bit sample values
+ * Only 8 and 12 are legal data precisions for lossy JPEG according to the
+ * JPEG standard, and the IJG code does not support anything else!
+ * We do not support run-time selection of data precision, sorry.
+ */
+
+#define BITS_IN_JSAMPLE  8	/* use 8 or 12 */
+
+#if (defined (_MSC_VER) && (_MSC_VER >= 800))
+#define HAVE_UNSIGNED_CHAR
+#define HAVE_ALL_INTS
+#define EXTERN(type)  extern type __cdecl
+#endif
+
+/*
+ * Maximum number of components (color channels) allowed in JPEG image.
+ * To meet the letter of the JPEG spec, set this to 255.  However, darn
+ * few applications need more than 4 channels (maybe 5 for CMYK + alpha
+ * mask).  We recommend 10 as a reasonable compromise; use 4 if you are
+ * really short on memory.  (Each allowed component costs a hundred or so
+ * bytes of storage, whether actually used in an image or not.)
+ */
+
+#define MAX_COMPONENTS  10	/* maximum number of image components */
+
+
+/*
+ * Basic data types.
+ * You may need to change these if you have a machine with unusual data
+ * type sizes; for example, "char" not 8 bits, "short" not 16 bits,
+ * or "long" not 32 bits.  We don't care whether "int" is 16 or 32 bits,
+ * but it had better be at least 16.
+ */
+
+/* Representation of a single sample (pixel element value).
+ * We frequently allocate large arrays of these, so it's important to keep
+ * them small.  But if you have memory to burn and access to char or short
+ * arrays is very slow on your hardware, you might want to change these.
+ */
+
+#if BITS_IN_JSAMPLE == 8
+/* JSAMPLE should be the smallest type that will hold the values 0..255.
+ * You can use a signed char by having GETJSAMPLE mask it with 0xFF.
+ */
+
+#ifdef HAVE_UNSIGNED_CHAR
+
+typedef unsigned char JSAMPLE;
+#define GETJSAMPLE(value)  ((int) (value))
+
+#else /* not HAVE_UNSIGNED_CHAR */
+
+typedef char JSAMPLE;
+#ifdef CHAR_IS_UNSIGNED
+#define GETJSAMPLE(value)  ((int) (value))
+#else
+#define GETJSAMPLE(value)  ((int) (value) & 0xFF)
+#endif /* CHAR_IS_UNSIGNED */
+
+#endif /* HAVE_UNSIGNED_CHAR */
+
+#define MAXJSAMPLE	255
+#define CENTERJSAMPLE	128
+
+#endif /* BITS_IN_JSAMPLE == 8 */
+
+
+#if BITS_IN_JSAMPLE == 12
+/* JSAMPLE should be the smallest type that will hold the values 0..4095.
+ * On nearly all machines "short" will do nicely.
+ */
+
+typedef short JSAMPLE;
+#define GETJSAMPLE(value)  ((int) (value))
+
+#define MAXJSAMPLE	4095
+#define CENTERJSAMPLE	2048
+
+#endif /* BITS_IN_JSAMPLE == 12 */
+
+
+/* Representation of a DCT frequency coefficient.
+ * This should be a signed value of at least 16 bits; "short" is usually OK.
+ * Again, we allocate large arrays of these, but you can change to int
+ * if you have memory to burn and "short" is really slow.
+ */
+
+typedef short JCOEF;
+
+
+/* Compressed datastreams are represented as arrays of JOCTET.
+ * These must be EXACTLY 8 bits wide, at least once they are written to
+ * external storage.  Note that when using the stdio data source/destination
+ * managers, this is also the data type passed to fread/fwrite.
+ */
+
+#ifdef HAVE_UNSIGNED_CHAR
+
+typedef unsigned char JOCTET;
+#define GETJOCTET(value)  (value)
+
+#else /* not HAVE_UNSIGNED_CHAR */
+
+typedef char JOCTET;
+#ifdef CHAR_IS_UNSIGNED
+#define GETJOCTET(value)  (value)
+#else
+#define GETJOCTET(value)  ((value) & 0xFF)
+#endif /* CHAR_IS_UNSIGNED */
+
+#endif /* HAVE_UNSIGNED_CHAR */
+
+
+/* These typedefs are used for various table entries and so forth.
+ * They must be at least as wide as specified; but making them too big
+ * won't cost a huge amount of memory, so we don't provide special
+ * extraction code like we did for JSAMPLE.  (In other words, these
+ * typedefs live at a different point on the speed/space tradeoff curve.)
+ */
+
+/* UINT8 must hold at least the values 0..255. */
+#ifndef HAVE_ALL_INTS
+
+#ifdef HAVE_UNSIGNED_CHAR
+typedef unsigned char UINT8;
+#else /* not HAVE_UNSIGNED_CHAR */
+#ifdef CHAR_IS_UNSIGNED
+typedef char UINT8;
+#else /* not CHAR_IS_UNSIGNED */
+typedef short UINT8;
+#endif /* CHAR_IS_UNSIGNED */
+#endif /* HAVE_UNSIGNED_CHAR */
+
+/* UINT16 must hold at least the values 0..65535. */
+
+#ifdef HAVE_UNSIGNED_SHORT
+typedef unsigned short UINT16;
+#else /* not HAVE_UNSIGNED_SHORT */
+typedef unsigned int UINT16;
+#endif /* HAVE_UNSIGNED_SHORT */
+
+/* INT16 must hold at least the values -32768..32767. */
+
+#ifndef XMD_H			/* X11/xmd.h correctly defines INT16 */
+typedef short INT16;
+#endif
+
+/* INT32 must hold at least signed 32-bit values. */
+
+#if !defined(XMD_H) && !defined(_WIN32)			/* X11/xmd.h correctly defines INT32 */
+typedef long INT32;
+#endif
+
+#endif /* HAVE_ALL_INTS */
+
+/* Datatype used for image dimensions.  The JPEG standard only supports
+ * images up to 64K*64K due to 16-bit fields in SOF markers.  Therefore
+ * "unsigned int" is sufficient on all machines.  However, if you need to
+ * handle larger images and you don't mind deviating from the spec, you
+ * can change this datatype.
+ */
+
+typedef unsigned int JDIMENSION;
+
+#define JPEG_MAX_DIMENSION  65500L  /* a tad under 64K to prevent overflows */
+
+
+/* These macros are used in all function definitions and extern declarations.
+ * You could modify them if you need to change function linkage conventions;
+ * in particular, you'll need to do that to make the library a Windows DLL.
+ * Another application is to make all functions global for use with debuggers
+ * or code profilers that require it.
+ */
+
+#ifdef _WIN32
+#  if defined(ALL_STATIC)
+#    if defined(JPEG_DLL)
+#      undef JPEG_DLL
+#    endif
+#    if !defined(JPEG_STATIC)
+#      define JPEG_STATIC
+#    endif
+#  endif
+#  if defined(JPEG_DLL)
+#    if defined(JPEG_STATIC)
+#      undef JPEG_STATIC
+#    endif
+#  endif
+#  if defined(JPEG_DLL)
+/* building a DLL */
+#    define JPEG_IMPEXP __declspec(dllexport)
+#  elif defined(JPEG_STATIC)
+/* building or linking to a static library */
+#    define JPEG_IMPEXP
+#  else
+/* linking to the DLL */
+#    define JPEG_IMPEXP __declspec(dllimport)
+#  endif
+#  if !defined(JPEG_API)
+#    define JPEG_API __cdecl
+#  endif
+/* The only remaining magic that is necessary for cygwin */
+#elif defined(__CYGWIN__)
+#  if !defined(JPEG_IMPEXP)
+#    define JPEG_IMPEXP
+#  endif
+#  if !defined(JPEG_API)
+#    define JPEG_API __cdecl
+#  endif
+#endif
+
+/* Ensure our magic doesn't hurt other platforms */
+#if !defined(JPEG_IMPEXP)
+#  define JPEG_IMPEXP
+#endif
+#if !defined(JPEG_API)
+#  define JPEG_API
+#endif
+
+/* a function called through method pointers: */
+#define METHODDEF(type)       static type
+/* a function used only in its module: */
+#define LOCAL(type)      static type
+/* a function referenced thru EXTERNs: */
+#define GLOBAL(type)          type JPEG_API
+/* a reference to a GLOBAL function: */
+#ifndef EXTERN 
+# define EXTERN(type)          extern JPEG_IMPEXP type JPEG_API
+/* a reference to a "GLOBAL" function exported by sourcefiles of utility progs */
+#endif /* EXTERN */
+#define EXTERN_1(type)   extern type JPEG_API
+
+
+/* This macro is used to declare a "method", that is, a function pointer.
+ * We want to supply prototype parameters if the compiler can cope.
+ * Note that the arglist parameter must be parenthesized!
+ * Again, you can customize this if you need special linkage keywords.
+ */
+
+#ifdef HAVE_PROTOTYPES
+#define JMETHOD(type,methodname,arglist)  type (*methodname) arglist
+#else
+#define JMETHOD(type,methodname,arglist)  type (*methodname) ()
+#endif
+
+
+/* Here is the pseudo-keyword for declaring pointers that must be "far"
+ * on 80x86 machines.  Most of the specialized coding for 80x86 is handled
+ * by just saying "FAR *" where such a pointer is needed.  In a few places
+ * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.
+ */
+
+/* jmorecfg.h line 220 */
+/* HJH modification: several of the windows header files already define FAR
+   because of this, the code below was changed so that it only tinkers with
+   the FAR define if FAR is still undefined */
+#ifndef FAR
+  #ifdef NEED_FAR_POINTERS
+  #define FAR  far
+  #else
+  #define FAR
+  #endif
+#endif
+
+
+/*
+ * On a few systems, type boolean and/or its values FALSE, TRUE may appear
+ * in standard header files.  Or you may have conflicts with application-
+ * specific header files that you want to include together with these files.
+ * Defining HAVE_BOOLEAN before including jpeglib.h should make it work.
+ */
+
+#ifndef HAVE_BOOLEAN
+typedef int boolean;
+#endif
+#ifndef FALSE			/* in case these macros already exist */
+#define FALSE	0		/* values of boolean */
+#endif
+#ifndef TRUE
+#define TRUE	1
+#endif
+
+
+/*
+ * The remaining options affect code selection within the JPEG library,
+ * but they don't need to be visible to most applications using the library.
+ * To minimize application namespace pollution, the symbols won't be
+ * defined unless JPEG_INTERNALS or JPEG_INTERNAL_OPTIONS has been defined.
+ */
+
+#ifdef JPEG_INTERNALS
+#define JPEG_INTERNAL_OPTIONS
+#endif
+
+#ifdef JPEG_INTERNAL_OPTIONS
+
+
+/*
+ * These defines indicate whether to include various optional functions.
+ * Undefining some of these symbols will produce a smaller but less capable
+ * library.  Note that you can leave certain source files out of the
+ * compilation/linking process if you've #undef'd the corresponding symbols.
+ * (You may HAVE to do that if your compiler doesn't like null source files.)
+ */
+
+/* Arithmetic coding is unsupported for legal reasons.  Complaints to IBM. */
+
+/* Capability options common to encoder and decoder: */
+
+#define DCT_ISLOW_SUPPORTED	/* slow but accurate integer algorithm */
+#define DCT_IFAST_SUPPORTED	/* faster, less accurate integer method */
+#define DCT_FLOAT_SUPPORTED	/* floating-point: accurate, fast on fast HW */
+
+/* Encoder capability options: */
+
+#undef  C_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */
+#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
+#define C_PROGRESSIVE_SUPPORTED	    /* Progressive JPEG? (Requires MULTISCAN)*/
+#define ENTROPY_OPT_SUPPORTED	    /* Optimization of entropy coding parms? */
+/* Note: if you selected 12-bit data precision, it is dangerous to turn off
+ * ENTROPY_OPT_SUPPORTED.  The standard Huffman tables are only good for 8-bit
+ * precision, so jchuff.c normally uses entropy optimization to compute
+ * usable tables for higher precision.  If you don't want to do optimization,
+ * you'll have to supply different default Huffman tables.
+ * The exact same statements apply for progressive JPEG: the default tables
+ * don't work for progressive mode.  (This may get fixed, however.)
+ */
+#define INPUT_SMOOTHING_SUPPORTED   /* Input image smoothing option? */
+
+/* Decoder capability options: */
+
+#undef  D_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */
+#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
+#define D_PROGRESSIVE_SUPPORTED	    /* Progressive JPEG? (Requires MULTISCAN)*/
+#define SAVE_MARKERS_SUPPORTED	    /* jpeg_save_markers() needed? */
+#define BLOCK_SMOOTHING_SUPPORTED   /* Block smoothing? (Progressive only) */
+#define IDCT_SCALING_SUPPORTED	    /* Output rescaling via IDCT? */
+#undef  UPSAMPLE_SCALING_SUPPORTED  /* Output rescaling at upsample stage? */
+#define UPSAMPLE_MERGING_SUPPORTED  /* Fast path for sloppy upsampling? */
+#define QUANT_1PASS_SUPPORTED	    /* 1-pass color quantization? */
+#define QUANT_2PASS_SUPPORTED	    /* 2-pass color quantization? */
+
+/* more capability options later, no doubt */
+
+
+/*
+ * Ordering of RGB data in scanlines passed to or from the application.
+ * If your application wants to deal with data in the order B,G,R, just
+ * change these macros.  You can also deal with formats such as R,G,B,X
+ * (one extra byte per pixel) by changing RGB_PIXELSIZE.  Note that changing
+ * the offsets will also change the order in which colormap data is organized.
+ * RESTRICTIONS:
+ * 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats.
+ * 2. These macros only affect RGB<=>YCbCr color conversion, so they are not
+ *    useful if you are using JPEG color spaces other than YCbCr or grayscale.
+ * 3. The color quantizer modules will not behave desirably if RGB_PIXELSIZE
+ *    is not 3 (they don't understand about dummy color components!).  So you
+ *    can't use color quantization if you change that value.
+ */
+
+#define RGB_RED		0	/* Offset of Red in an RGB scanline element */
+#define RGB_GREEN	1	/* Offset of Green */
+#define RGB_BLUE	2	/* Offset of Blue */
+#define RGB_PIXELSIZE	3	/* JSAMPLEs per RGB scanline element */
+
+
+/* Definitions for speed-related optimizations. */
+
+
+/* If your compiler supports inline functions, define INLINE
+ * as the inline keyword; otherwise define it as empty.
+ */
+
+#ifndef INLINE
+#ifdef __GNUC__			/* for instance, GNU C knows about inline */
+#define INLINE __inline__
+#endif
+#ifndef INLINE
+#define INLINE			/* default is to define it as empty */
+#endif
+#endif
+
+
+/* On some machines (notably 68000 series) "int" is 32 bits, but multiplying
+ * two 16-bit shorts is faster than multiplying two ints.  Define MULTIPLIER
+ * as short on such a machine.  MULTIPLIER must be at least 16 bits wide.
+ */
+
+#ifndef MULTIPLIER
+#define MULTIPLIER  int		/* type for fastest integer multiply */
+#endif
+
+
+/* FAST_FLOAT should be either float or double, whichever is done faster
+ * by your compiler.  (Note that this type is only used in the floating point
+ * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.)
+ * Typically, float is faster in ANSI C compilers, while double is faster in
+ * pre-ANSI compilers (because they insist on converting to double anyway).
+ * The code below therefore chooses float if we have ANSI-style prototypes.
+ */
+
+#ifndef FAST_FLOAT
+#ifdef HAVE_PROTOTYPES
+#define FAST_FLOAT  float
+#else
+#define FAST_FLOAT  double
+#endif
+#endif
+
+#endif /* JPEG_INTERNAL_OPTIONS */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/External/JPEG/jpeglib.h	Wed Nov 17 07:48:28 2010 +0000
@@ -0,0 +1,1110 @@
+/*
+ * jpeglib.h
+ *
+ * Copyright (C) 1991-1998, Thomas G. Lane.
+ * This file is part of the Independent JPEG Group's software.
+ * For conditions of distribution and use, see the accompanying README file.
+ *
+ * This file defines the application interface for the JPEG library.
+ * Most applications using the library need only include this file,
+ * and perhaps jerror.h if they want to know the exact error codes.
+ */
+#define NEED_SHORT_EXTERNAL_NAMES
+#ifndef JPEGLIB_H
+#define JPEGLIB_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * First we include the configuration files that record how this
+ * installation of the JPEG library is set up.  jconfig.h can be
+ * generated automatically for many systems.  jmorecfg.h contains
+ * manual configuration options that most people need not worry about.
+ */
+
+#ifndef JCONFIG_INCLUDED	/* in case jinclude.h already did */
+#include "jconfig.h"		/* widely used configuration options */
+#endif
+#include "jmorecfg.h"		/* seldom changed options */
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* Version ID for the JPEG library.
+ * Might be useful for tests like "#if JPEG_LIB_VERSION >= 60".
+ */
+
+#define JPEG_LIB_VERSION  62	/* Version 6b */
+
+
+/* Various constants determining the sizes of things.
+ * All of these are specified by the JPEG standard, so don't change them
+ * if you want to be compatible.
+ */
+
+#define DCTSIZE		    8	/* The basic DCT block is 8x8 samples */
+#define DCTSIZE2	    64	/* DCTSIZE squared; # of elements in a block */
+#define NUM_QUANT_TBLS      4	/* Quantization tables are numbered 0..3 */
+#define NUM_HUFF_TBLS       4	/* Huffman tables are numbered 0..3 */
+#define NUM_ARITH_TBLS      16	/* Arith-coding tables are numbered 0..15 */
+#define MAX_COMPS_IN_SCAN   4	/* JPEG limit on # of components in one scan */
+#define MAX_SAMP_FACTOR     4	/* JPEG limit on sampling factors */
+/* Unfortunately, some bozo at Adobe saw no reason to be bound by the standard;
+ * the PostScript DCT filter can emit files with many more than 10 blocks/MCU.
+ * If you happen to run across such a file, you can up D_MAX_BLOCKS_IN_MCU
+ * to handle it.  We even let you do this from the jconfig.h file.  However,
+ * we strongly discourage changing C_MAX_BLOCKS_IN_MCU; just because Adobe
+ * sometimes emits noncompliant files doesn't mean you should too.
+ */
+#define C_MAX_BLOCKS_IN_MCU   10 /* compressor's limit on blocks per MCU */
+#ifndef D_MAX_BLOCKS_IN_MCU
+#define D_MAX_BLOCKS_IN_MCU   10 /* decompressor's limit on blocks per MCU */
+#endif
+
+
+/* Data structures for images (arrays of samples and of DCT coefficients).
+ * On 80x86 machines, the image arrays are too big for near pointers,
+ * but the pointer arrays can fit in near memory.
+ */
+
+typedef JSAMPLE FAR *JSAMPROW;	/* ptr to one image row of pixel samples. */
+typedef JSAMPROW *JSAMPARRAY;	/* ptr to some rows (a 2-D sample array) */
+typedef JSAMPARRAY *JSAMPIMAGE;	/* a 3-D sample array: top index is color */
+
+typedef JCOEF JBLOCK[DCTSIZE2];	/* one block of coefficients */
+typedef JBLOCK FAR *JBLOCKROW;	/* pointer to one row of coefficient blocks */
+typedef JBLOCKROW *JBLOCKARRAY;		/* a 2-D array of coefficient blocks */
+typedef JBLOCKARRAY *JBLOCKIMAGE;	/* a 3-D array of coefficient blocks */
+
+typedef JCOEF FAR *JCOEFPTR;	/* useful in a couple of places */
+
+
+/* Types for JPEG compression parameters and working tables. */
+
+
+/* DCT coefficient quantization tables. */
+
+typedef struct {
+  /* This array gives the coefficient quantizers in natural array order
+   * (not the zigzag order in which they are stored in a JPEG DQT marker).
+   * CAUTION: IJG versions prior to v6a kept this array in zigzag order.
+   */
+  UINT16 quantval[DCTSIZE2];	/* quantization step for each coefficient */
+  /* This field is used only during compression.  It's initialized FALSE when
+   * the table is created, and set TRUE when it's been output to the file.
+   * You could suppress output of a table by setting this to TRUE.
+   * (See jpeg_suppress_tables for an example.)
+   */
+  boolean sent_table;		/* TRUE when table has been output */
+} JQUANT_TBL;
+
+
+/* Huffman coding tables. */
+
+typedef struct {
+  /* These two fields directly represent the contents of a JPEG DHT marker */
+  UINT8 bits[17];		/* bits[k] = # of symbols with codes of */
+				/* length k bits; bits[0] is unused */
+  UINT8 huffval[256];		/* The symbols, in order of incr code length */
+  /* This field is used only during compression.  It's initialized FALSE when
+   * the table is created, and set TRUE when it's been output to the file.
+   * You could suppress output of a table by setting this to TRUE.
+   * (See jpeg_suppress_tables for an example.)
+   */
+  boolean sent_table;		/* TRUE when table has been output */
+} JHUFF_TBL;
+
+
+/* Basic info about one component (color channel). */
+
+typedef struct {
+  /* These values are fixed over the whole image. */
+  /* For compression, they must be supplied by parameter setup; */
+  /* for decompression, they are read from the SOF marker. */
+  int component_id;		/* identifier for this component (0..255) */
+  int component_index;		/* its index in SOF or cinfo->comp_info[] */
+  int h_samp_factor;		/* horizontal sampling factor (1..4) */
+  int v_samp_factor;		/* vertical sampling factor (1..4) */
+  int quant_tbl_no;		/* quantization table selector (0..3) */
+  /* These values may vary between scans. */
+  /* For compression, they must be supplied by parameter setup; */
+  /* for decompression, they are read from the SOS marker. */
+  /* The decompressor output side may not use these variables. */
+  int dc_tbl_no;		/* DC entropy table selector (0..3) */
+  int ac_tbl_no;		/* AC entropy table selector (0..3) */
+  
+  /* Remaining fields should be treated as private by applications. */
+  
+  /* These values are computed during compression or decompression startup: */
+  /* Component's size in DCT blocks.
+   * Any dummy blocks added to complete an MCU are not counted; therefore
+   * these values do not depend on whether a scan is interleaved or not.
+   */
+  JDIMENSION width_in_blocks;
+  JDIMENSION height_in_blocks;
+  /* Size of a DCT block in samples.  Always DCTSIZE for compression.
+   * For decompression this is the size of the output from one DCT block,
+   * reflecting any scaling we choose to apply during the IDCT step.
+   * Values of 1,2,4,8 are likely to be supported.  Note that different
+   * components may receive different IDCT scalings.
+   */
+  int DCT_scaled_size;
+  /* The downsampled dimensions are the component's actual, unpadded number
+   * of samples at the main buffer (preprocessing/compression interface), thus
+   * downsampled_width = ceil(image_width * Hi/Hmax)
+   * and similarly for height.  For decompression, IDCT scaling is included, so
+   * downsampled_width = ceil(image_width * Hi/Hmax * DCT_scaled_size/DCTSIZE)
+   */
+  JDIMENSION downsampled_width;	 /* actual width in samples */
+  JDIMENSION downsampled_height; /* actual height in samples */
+  /* This flag is used only for decompression.  In cases where some of the
+   * components will be ignored (eg grayscale output from YCbCr image),
+   * we can skip most computations for the unused components.
+   */
+  boolean component_needed;	/* do we need the value of this component? */
+
+  /* These values are computed before starting a scan of the component. */
+  /* The decompressor output side may not use these variables. */
+  int MCU_width;		/* number of blocks per MCU, horizontally */
+  int MCU_height;		/* number of blocks per MCU, vertically */
+  int MCU_blocks;		/* MCU_width * MCU_height */
+  int MCU_sample_width;		/* MCU width in samples, MCU_width*DCT_scaled_size */
+  int last_col_width;		/* # of non-dummy blocks across in last MCU */
+  int last_row_height;		/* # of non-dummy blocks down in last MCU */
+
+  /* Saved quantization table for component; NULL if none yet saved.
+   * See jdinput.c comments about the need for this information.
+   * This field is currently used only for decompression.
+   */
+  JQUANT_TBL * quant_table;
+
+  /* Private per-component storage for DCT or IDCT subsystem. */
+  void * dct_table;
+} jpeg_component_info;
+
+
+/* The script for encoding a multiple-scan file is an array of these: */
+
+typedef struct {
+  int comps_in_scan;		/* number of components encoded in this scan */
+  int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
+  int Ss, Se;			/* progressive JPEG spectral selection parms */
+  int Ah, Al;			/* progressive JPEG successive approx. parms */
+} jpeg_scan_info;
+
+/* The decompressor can save APPn and COM markers in a list of these: */
+
+typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
+
+struct jpeg_marker_struct {
+  jpeg_saved_marker_ptr next;	/* next in list, or NULL */
+  UINT8 marker;			/* marker code: JPEG_COM, or JPEG_APP0+n */
+  unsigned int original_length;	/* # bytes of data in the file */
+  unsigned int data_length;	/* # bytes of data saved at data[] */
+  JOCTET FAR * data;		/* the data contained in the marker */
+  /* the marker length word is not counted in data_length or original_length */
+};
+
+/* Known color spaces. */
+
+typedef enum {
+	JCS_UNKNOWN,		/* error/unspecified */
+	JCS_GRAYSCALE,		/* monochrome */
+	JCS_RGB,		/* red/green/blue */
+	JCS_YCbCr,		/* Y/Cb/Cr (also known as YUV) */
+	JCS_CMYK,		/* C/M/Y/K */
+	JCS_YCCK		/* Y/Cb/Cr/K */
+} J_COLOR_SPACE;
+
+/* DCT/IDCT algorithm options. */
+
+typedef enum {
+	JDCT_ISLOW,		/* slow but accurate integer algorithm */
+	JDCT_IFAST,		/* faster, less accurate integer method */
+	JDCT_FLOAT		/* floating-point: accurate, fast on fast HW */
+} J_DCT_METHOD;
+
+#ifndef JDCT_DEFAULT		/* may be overridden in jconfig.h */
+#define JDCT_DEFAULT  JDCT_ISLOW
+#endif
+#ifndef JDCT_FASTEST		/* may be overridden in jconfig.h */
+#define JDCT_FASTEST  JDCT_IFAST
+#endif
+
+/* Dithering options for decompression. */
+
+typedef enum {
+	JDITHER_NONE,		/* no dithering */
+	JDITHER_ORDERED,	/* simple ordered dither */
+	JDITHER_FS		/* Floyd-Steinberg error diffusion dither */
+} J_DITHER_MODE;
+
+
+/* Common fields between JPEG compression and decompression master structs. */
+
+#define jpeg_common_fields \
+  struct jpeg_error_mgr * err;	/* Error handler module */\
+  struct jpeg_memory_mgr * mem;	/* Memory manager module */\
+  struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
+  void * client_data;		/* Available for use by application */\
+  boolean is_decompressor;	/* So common code can tell which is which */\
+  int global_state		/* For checking call sequence validity */
+
+/* Routines that are to be used by both halves of the library are declared
+ * to receive a pointer to this structure.  There are no actual instances of
+ * jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct.
+ */
+struct jpeg_common_struct {
+  jpeg_common_fields;		/* Fields common to both master struct types */
+  /* Additional fields follow in an actual jpeg_compress_struct or
+   * jpeg_decompress_struct.  All three structs must agree on these
+   * initial fields!  (This would be a lot cleaner in C++.)
+   */
+};
+
+typedef struct jpeg_common_struct * j_common_ptr;
+typedef struct jpeg_compress_struct * j_compress_ptr;
+typedef struct jpeg_decompress_struct * j_decompress_ptr;
+
+
+/* Master record for a compression instance */
+
+struct jpeg_compress_struct {
+  jpeg_common_fields;		/* Fields shared with jpeg_decompress_struct */
+
+  /* Destination for compressed data */
+  struct jpeg_destination_mgr * dest;
+
+  /* Description of source image --- these fields must be filled in by