/*
 *  EpeeEngine.h
 *  
 *	
 *  Epee Engine
 *  Created by Alan Uthoff on 3/12/06.
	Copyright (C) 2006

	This Code is free software; you can redistribute it and/or
    modify it under the terms of the zlib/libpng License as published 
	by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.
	This software is provided 'as-is', without any express or implied warranty.
	
	In no event will the authors be held liable for any damages arising from the use of this software.

	Permission is granted to anyone to use this software for any purpose, 
	including commercial applications, and to alter it and redistribute 
	it freely, subject to the following restrictions:

    1. The origin of this software must not be misrepresented; 
	   you must not claim that you wrote the original software. 
	   If you use this software in a product, an acknowledgment 
	   in the product documentation would be appreciated but is not required.

    2. Altered source versions must be plainly marked as such, 
		and must not be misrepresented as being the original software.

    3. This notice may not be removed or altered from any source distribution.


 */


#ifndef _EPEEENGINE_h_
#define _EPEEENGINE_h_

#define Version_Number_h .35
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
 #include <sstream>
 //#include <stdexcept>
#include "SDL_ttf.h"
#include "SDL_rotozoom.h"
#include "SDL_framerate.h"
#include "SDL_mixer.h"
#include "SDL_image.h"
#include "tinyxml.h"




#if defined (WIN32)
//#include <windows.h>

    #if defined(_MSC_VER)
		
        #include "SDL.h"
		#include "SDL_thread.h"
	

    #else
         #include "SDL/SDL.h"
		#include "SDL/SDL_thread.h"

    #endif
//#include <gl/gl.h>
#define True_Type_Font_Location "C:\\WINDOWS\\Fonts\\" //windows
#define True_Type_Font_Defalut  "ARIAL.TTF" //windows 
#else

#if defined (__APPLE__)
#include "SDL/SDL.h"
#include "SDL/SDL_thread.h"
#define True_Type_Font_Location "/Library/Fonts/"   //Macintosh
#define True_Type_Font_Defalut  "Chalkboard.ttf" //Macintosh
#endif

#endif


 



#define Type_Image 1
#define Type_TextBox 2
#define Type_Button 3
#define Type_ButtonTB 4
#define Type_Animation 5
#define Type_AnimationScript 6

//user defined events
#define ANIMATION_EVENT 29
#define TEXT_BOX_CHANGED_EVENT 30
#define NETWORK_DATA_RECIVED 50

//#define Anim_Funtion_Rotate 1
//#define Anim_Funtion_Motion 2

//error defintions
#define EPEE_NO_ERROR 0
#define TEXTBOX_CONVERION_ERROR 1
#define SOUND_PLAYING_ERROR 10
#define SOUND_ERROR         11
#define SOUND_LOADING_ERROR 12
#define SOUND_DELETING_ERROR 13
#define SOUND_NOT_FOUND      14
#define NULL_POINTER_PASSED 20
#define SPROCKET_NOT_FOUND 30
#define SPROCKET_ERROR     31
#define SPROCKET_DELETING_ERROR 32
#define RENDERLIST_NOT_FOUND 40
#define RENDERLIST_DELETING_ERROR 41
#define RENDERING_ERROR 50

//textbox Justifications
#define TEXT_LEFT_JUSTIFIED 100
#define TEXT_RIGHT_JUSTIFIED 102
#define TEXT_CENTER_JUSTIFIED 103

#define FONT_QUALITY_LOW 0
#define FONT_QUALITY_HIGH 1
#define FONT_QUALITY_SHADED 2
using namespace std;
#define RECIVEING_IP 0
#define SENDING_IP 1




//********************Begin Of ControlCharacters Class******************************
class ControlCharacters
{
	bool m_bShift;
	bool m_bControl;
	bool m_bAlt;
	bool m_bCommand;
	bool m_bCapsLock;
	bool m_keyCaught;
	


public:
	friend class EpeeEngine;
	ControlCharacters();
	bool IsAltPressed();
	bool IsCtrlPressed();
	bool IsShiftPressed();
	bool IsCapLockPressed();
protected:
	void ProcessKeyEvent(SDL_Event *_event);
	void SetCapLock(bool _caps);
	bool GetKeyCaught();


};
//***********************End Of ControlCharacters Class*********************************

//***********************Begin Of EpeeEngineError Class***************************
class EpeeEngineError
{
public:
		std::string m_sError_Message;
	int m_iErrorCode;
	void * ObjectWhereErrorOccured;
	EpeeEngineError(std::string _message,int _code,void * obj);
	EpeeEngineError();		

};
//***********************End Of EpeeEngineError Class***************************

//***********************Begin Of FileLookUp Class***************************
class FileLookUp
{

	public:
		FileLookUp();
		FileLookUp(std::string _Symbol, std::string _fileName);
		std::string m_ssymbol;
		std::string m_sfilename;
		

};
//***********************End Of FileLookUp Class***************************

//***********************Begin Of Sound Class***************************
class Sound 
{

	std::string m_sFileName;
	std::string m_sName;
	Mix_Chunk * m_pSound; 
	int m_iChannel;
	int m_iNumberOfTimesToLoop;
	int m_iVolume;
public:
	Sound(std::string _Name ,std::string _FileName,int _Channel=0,int _NumberOfTimesToLoop=0, int _Volume=MIX_MAX_VOLUME);
	~Sound();
	int GetVolume();
	bool SetVolume(int _Volume);
	bool LoadSound();
	Mix_Chunk * GetMixChunkPointer();
	bool SetChannel(int _ChannelToSetTo);	
	int GetChannel();
	bool SetNumberOfTimesToLoop(int _NumberOfTimesToLoop);
	int GetNumberOfTimesToLoop();
	std::string GetName();
	
};
//***********************End Of Sound Class***************************

//***********************Begin Of Sprocket Class***************************
class Sprockets //Base Class
{	int m_iz;
	std::string m_sName;
	int m_iSprocketType;
	bool m_bDraw;
	int m_iCurrentPostion;
	bool m_iAntiAliased;
	bool m_bblit;
	EpeeEngineError m_cCurrentError;
	bool m_bShowSurfaceOutline;

	
protected:
		double m_iRotation;
		double m_iScaleX;
		double m_iScaleY;
		bool m_bactive;
		bool  m_bDontMoveButton;
		bool m_bCurrentlySelected;
		SDL_Rect m_cBox;
		SDL_Surface *m_porignalSurface;
		SDL_Surface *m_pModifySurface;
public:
	 Sprockets(std::string _NameMain,int _TypeMain);
	 Sprockets(std::string _NameMain,int _TypeMain, int _x, int _y,int _z);
   	 Sprockets();
	 virtual ~Sprockets();
	
	friend class EpeeEngine;
	friend class RenderList;

	void SetLocation(int _x,int _y);
	int GetLocationX();
	int GetLocationY();
	std::string GetName();
	int GetLocationZ ();
	EpeeEngineError GetLastError();
	void SetLastError(EpeeEngineError _error);
	void ClearError();
	virtual void SetHeightWidth(unsigned int _Height,unsigned int _Width);
	unsigned int GetHeight();
	unsigned int GetWidth ();
	bool SetDraw(bool _Draw);
	bool GetDraw();
	int GetType();
	bool SetScalingFactor(double _ScalingX,double _ScalingY);
	bool SetScalingFactorY(double _ScalingY);
	bool SetScalingFactorX(double _ScalingX);
	double  GetScalingFactorX();
	double  GetScalingFactorY();
	bool SetRotation(double _Degrees );
    double GetRotation();
	bool SetAntiAliased(bool _AntiAliased );
	bool GetAntiAliased();
    int GetCurrentVectorPostion();
    virtual Sprockets * WasClicked(int _mouselocationX, int _mouselocationY);
	void DisableClick();
	void EnableClick();
	bool GetIsClickEnabled();
	void DisableAndTurnOffDraw();
	void EnableAndTurnOnDraw();
	void SetDontMoveOnClick(bool _flag);
	bool GetDontMoveOnClick();
	bool WasLastSprocketClicked();
	void ShowOutLine();
	void HideOutLine();
	bool GetOutLine();
protected:

	bool GetBlit();
    virtual SDL_Surface * SetSurface();
	virtual SDL_Surface * GetSprocketSurface();
	SDL_Rect * GetRect();
    bool SetCurrentArrayPostion(int _newPostion);
    void SetType(int _type);
	void SetLocationZ(int _z);//DO NOT call this function call ChangeSprocketZ instead
	void SetBlit(bool _blit);
	virtual void SetModifySurFace(SDL_Surface * _ModifySurface);
	SDL_Surface * GetModifySurFace();
	
};
//***********************End Of Sprocket Class*******************************

//***********************Begin Of RenderList Class***************************
class RenderList
{
std::string m_sNameOfRenenderList;
std::vector  <Sprockets*> m_vSprocketsList;
Sprockets  * m_pLastSprocketFound;
int m_uiTotalSprocketsCreated;
EpeeEngineError m_cCurrentError;

public:
	
	RenderList(std::string _name);
	~RenderList();

friend class EpeeEngine;
	EpeeEngineError GetLastError();
	void SetLastError(EpeeEngineError _error);
	void ClearError();	
	std::string GetName();	
	bool InsertSprocket(Sprockets * _newSprocket,bool _new=true);
	bool DestroySprocket(std::string _name);
	bool UpdateVectorlocation();
	bool ChangeSprocketZ(Sprockets * _SprocketToChange,int _newZ);
	Sprockets *  FindSprockets(std::string _name);	
	unsigned int GetTotalSprockesCreated();
	void RemoveSprocketFromList(Sprockets * _sprocketToErase);

};
//***********************End Of RenderList Class***************************


//***********************Begin of textBox Class****************************
class textBox :public Sprockets
{
	std::string m_sTrue_Type_Font_Location;
	std::string m_sTextBoxMessage;
	std::string m_sFont;
	int m_iFontPoint;
	SDL_Color m_cColorOfText;
	SDL_Color m_cBackGroundColor;
	SDL_Color m_cColorOfSelectedText;
	SDL_Color m_cSelectedBackGroundColor;
	bool m_bblit;
	TTF_Font *m_pLoadedFont;
	bool m_bEditable;
	bool m_bNumbersOnly;
	int m_iJustify;
	int m_iOffsetXJustiy;
	bool m_bDoNotClipTextHeight;
	bool m_bDoNotClipTextWidth;
	int m_bQuality;
	bool m_bChangeTextBoxColorOnClick;
	SDL_Rect m_cModBox;

public:

protected:
 	textBox(int _Obj_Type,std::string _NameTextBox,int _x,int _y,int _z,std::string _TextBoxMessage=" ",unsigned int _height=-1,unsigned int _width=-1,std::string _Font=True_Type_Font_Defalut,int _FontPoint=18,unsigned int _red=255,unsigned int _blue=255 ,unsigned int _green=255,std::string _FontPath = True_Type_Font_Location);//:Sprockets(_NameTextBox,_Obj_Type);
	virtual void SetModifySurFace(SDL_Surface * _ModifySurface);
public:
	textBox(std::string _NameTextBox, int _x, int _y,int _z,std::string _TextBoxMessage=" ",unsigned int _height=-1,unsigned int _width=-1,std::string _Font=True_Type_Font_Defalut,int _FontPoint=18,unsigned int _red=255,unsigned int _blue=255 ,unsigned int _green=255,std::string _FontPath = True_Type_Font_Location);//:Sprockets(_NameTextBox,Type_TextBox);
	textBox();
	~textBox();

	friend class EpeeEngine;

	bool GetClipTextHeight();
	bool GetClipTextWidth();
	void SetQuality(int _Quality);
	int GetQuality();
	void SetText(std::string _text,bool _setevent=false);
	virtual void SetHeightWidth(unsigned int _Height,unsigned int _Width);
	void SetHightBasedOfRenderedText();
	void SetWidthBasedOfRenderedText();
	int GetJustifyOffset();
	int GetTextJustification();
	void SetTextJustification(int _justify);
	std::string GetText ();
	int GetTextToInt();
	float GetTextToFloat();
	bool  SetTextFromInt(int _value,bool _setevent=false);
	bool SetTextFromFloat(float _value,bool _setevent=false);
	std::string GetFont();
	void SetFont(std::string _FontArg);
	int GetFontPoint();
	void SetFontPoint(int _FontPointArg);
	SDL_Color GetBackGroundColor();
	bool SetBackGroundColor(unsigned int _red,unsigned int _blue ,unsigned int _green);
	SDL_Color GetTextColor();
	bool SetTextColor(unsigned int _red,unsigned int _blue ,unsigned int _green);
	std::string GetFontPath();
	void SetFontPath(std::string _Location);
	void SetEditable(bool _flag);
	bool GetEditable();
	void SetNumbersOnly(bool _flag);
	bool GetNumbersOnly();
	bool IsColorChangedOnClick();	
	void SetColorChangedOnClick(bool _ChangeOnClick);
	void SetSelectBackGroundColor(unsigned int _red,unsigned int _blue ,unsigned int _green);
	void SetSelectTextColor(unsigned int _red,unsigned int _blue ,unsigned int _green);
	 virtual Sprockets * WasClicked(int _mouselocationX, int _mouselocationY);
//	template <class datatype> 
//	datatype GetTextToNumericData(datatype _type);
	
//	template <class datatype> 
//	bool  SetTextFromNumericData(datatype _value,bool _setevent);
	template <class datatype> 
	datatype GetTextToNumericData(datatype _type)
	{datatype tempint=0;
			std::istringstream tempstream(m_sTextBoxMessage);
			if (!(tempstream>>tempint)) {
				std::string tempstring ="Could not convert"+m_sTextBoxMessage+"to the specified data type";
				 EpeeEngineError temperror(tempstring,TEXTBOX_CONVERION_ERROR,this);
				this->SetLastError(temperror);
				return 0;
			}
			this->ClearError();
			return tempint;
	}

	template <class datatype> 
	bool  SetTextFromNumericData(datatype _value,bool _setevent)
	{
			datatype tempint=_value;
			std::ostringstream tempstream;
			if (!(tempstream<<_value)) {
				
				std::string tempstring ="Could not convert numeric data to string";
				 EpeeEngineError temperror(tempstring,TEXTBOX_CONVERION_ERROR,this);
				this->SetLastError(temperror);
				return false;
				
			}
			this->SetText(tempstream.str(),_setevent);
			this->ClearError();
			return true;
	}



	bool  WillTextFitIntoBox(std::string _text);
protected:
	TTF_Font * GetFontPointer();
	SDL_Surface * SetSurface();
	void LoadFont();
protected:
	void SetJustifyOffset();
};
//***********************End of textBox Class****************************

//***********************Begin of image Class****************************

class image :public Sprockets
{SDL_Rect m_cOrgialDem;
	std::string m_sFileName;
	SDL_Rect ClipingRect;
	bool m_bClip;
	bool m_bTransparency;

public:
	image (std::string _FileNameImage, std::string _NameImageHere,int _x,int _y,int _z,bool _Transparency=false);//:Sprockets( _NameImageHere,Type_Image ,_x, _y, _z)
	friend class EpeeEngine;
	
	std::string GetFileName();
	void SetClippingRect(int _x,int _y,int _w,int _h);
	bool GetClip();
	int GetClippingX();
	int GetClippingY();
	int GetClippingW();
	int GetClippingH();
	void SetTransparency (bool _Transparency);
	bool GetTransparency();
 protected:
	bool LoadFileSurface();
	image (std::string _FileNameImage, std::string _NameImageHere,int _x,int _y,int _z,int _type,bool _Transparency=false);//:Sprockets( _NameImageHere,_type ,_x, _y, _z)
	image();
	image(std::string _FileNameImage);	
	SDL_Rect * GetClippingRect();
	SDL_Rect * GetOrignalRect();

	

};

//***********************End of image Class*********************************



typedef bool (*PlayScrtipFuntionPointer) (float,Sprockets *);
//***********************Begin of Animation Class***************************

class Animation : public image
{
private:
	int m_ianimationFPS;
	float m_iFrameEverInMillSecounds;
	int m_iStripNumFrames;
	int m_iNumberOfRows;
	int m_iCurrentFrame;
	int m_iLoop;
	float m_iCurrentTime;
	float m_iPrevTime;
	bool m_bPlaying;
	int m_iNumberofTimesPlayed;
	bool m_bReversPlay;
	int m_iframeEvent;
	unsigned int WidthForBoxInPixles;
	unsigned int HeightForBoxInPixles;
	
public:
	Animation(std::string _FileName,std::string _AnimationName,int _fps,int _x,int _y, int _z,int _AnimStripFrames,int _StartFrame=0,int _Loop=1,bool _Transparency=false,bool _StartNow=true, int _NumberOfRows=1);//:image( _FileName, _AnimationName, _x, _y, _z,Type_Animation,_Transparency)
	void  JumpToFrame(int _Frame);
	void UpdateTime();
	int GetFPS();
	void SetFPS(int _fps);
	void SetClipingBoxForFrame();
	void StopAnimation();
	void PlayAnimation();
	void ResumeAnimation();
	void SetLoop(int _Loop);
	int GetLoop();
	int GetCurrentFrame();
	bool GetReversPlay();
	void SetReversPlay(bool _BackWards);
	int GetTotalNumberOfFrames();
	int GetTotalNumberOfRows();
	int GetTotalNumberOfFramesPerRow();
	int GetNumberOfTimesPlayed();
	void SetFrameEvent(int _frame);
	int GetFrameEvent();
	bool IsPlaying();
private:
	void CheckForNextFrame(float _time)	;
};

//********************End of Animation Class*************************************

//********************Begin Of Animation Sctipt Class****************************
class AnimationScript : public Sprockets
{
private:
	int m_ianimationFPS;
	float m_iFrameEverInMillSecounds;
	int m_iNumFrames;
	int m_iLoop;
	int m_iCurrentFrame;
	float m_iCurrentTime;
	float m_iPrevTime;
	bool m_bPlaying;
	int m_iNumberofTimesPlayed;
	int m_iframeEvent;
	bool m_bReversPlay;
	bool 	m_bFuntionIsDoneWithOneCycle;
	PlayScrtipFuntionPointer* m_fPlayScrtipFuntionPointer;     
	
	
public:
	Sprockets * m_pAnimationSprocket; //sprocket funtions need to be remaped instead of this  being public
	AnimationScript(std::string _AnimationName,Sprockets * _AnimationSprocket,int _z,PlayScrtipFuntionPointer* _ScrtipFuntionPointer,int _fps,int _TotalNumberOfFrames,int _StartFrame=0,int _Loop=1,bool _StartNow=true);//:image( _FileName, _AnimationName, _x, _y, _z,Type_Animation,_Transparency)

	void  JumpToFrame(int _Frame);
	void UpdateTime();
	int GetFPS();
	void SetFPS(int _fps);
	void StopAnimation();
	virtual void PlayAnimation();
	void ResumeAnimation();
	void SetLoop(int _Loop);
	int GetLoop();
	int GetCurrentFrame();
	int GetTotalNumberOfFrames();
	int GetNumberOfTimesPlayed();
	void SetFrameEvent(int _frame);
	int GetFrameEvent();
	bool IsPlaying();
	void SetFuntionPointer(PlayScrtipFuntionPointer * _PlayScrtipFuntionPointer);
	PlayScrtipFuntionPointer GetFuntionPointer();
	virtual bool Script(float _time,Sprockets * _AnimationSprocket);//called if m_fPlayScrtipFuntionPointer is NULL
	//virtual bool ResetFuntion(float _time,Sprockets * _AnimationSprocket);//called to reset the script
private:
	void CheckForNextFrame(float _time)	;
};
//*******************End of Animation Script Class*********************

//*******************Begin of Button Class****************************************



class Button :public image
{
	int m_ibuttonheight;
	int m_ibuttonwidth;
	int m_ibuttonx;
	int m_ibuttony;

public:
Button(std::string _ButtonFileNameImage, std::string _ButtonName,int _Buttonx,int _Buttony,int _Buttonz,bool _Transparency=false,bool _SButtonactive=true);//:image( _ButtonFileNameImage, _ButtonName, _Buttonx, _Buttony, _Buttonz,Type_Button,_Transparency)
Button(std::string _ButtonName,int _Buttonx,int _Buttony,int _Buttonz,int m_iButtonHeight,int m_iButtonwidth,bool _Transparency=false,bool _SButtonactive=true);//:image(" ", _ButtonName, _Buttonx, _Buttony, _Buttonz,Type_Button,_Transparency)
Button();

virtual Sprockets * WasClicked(int _mouselocationX, int _mouselocationY);

	
};

//********************************End of Button Class******************************

//********************************Begin of ButtonTB Class********************************
class ButtonTB :public textBox
{

int m_ibuttonx;
int m_ibuttony;

public:
ButtonTB(std::string _ButtonName,int _Buttonx,int _Buttony,int _Buttonz,std::string _ButtonText ,bool _SButtonactive=true,unsigned int _ButtonTB_height=30,unsigned int _ButtonTB_width=100,std::string _ButtonTB_Font=True_Type_Font_Defalut,int _ButtonTB_FontPoint=18,unsigned int _ButtonTB_red=255,unsigned int _ButtonTB_blue=255 ,unsigned int _ButtonTB_green=255,std::string _ButtonFontPath=True_Type_Font_Location);//:textBox(Type_ButtonTB,_ButtonName, _Buttonx,_Buttony,_Buttonz,_ButtonText, _ButtonTB_height, _ButtonTB_width,_ButtonTB_Font,_ButtonTB_FontPoint,_ButtonTB_red, _ButtonTB_blue ,_ButtonTB_green,_ButtonFontPath)	

};

//********************************End of ButtonTB Class********************************




//==============For other Class funtions see above=====================



/*
class Sprockets
public memeber funtions
	 Sprockets(std::string _NameMain,int _TypeMain)
	 Sprockets(std::string _NameMain,int _TypeMain,int _x,int _y,int _z)
	 Sprockets()
	

	void SetLocation( int _x,unsigned int _y)
	unsigned int GetLocationX()
	unsigned int GetLocationY()
	std::string GetName()
	int GetLocationZ ()
	void SetheightWidth(unsigned int _height,unsigned int _Width)
	unsigned int Getheight()
	unsigned int GetWidth ()
	bool SetDraw(bool _Draw)//set to false for the sprocket not to be drawn on screen (setting it to false will not remove it from the renderable list) or true for it to be drawn on screen 
	bool GetDraw()
	int GetType()
    bool SetScalingFactor(double _ScalingX,double _ScalingY)
    bool SetScalingFactorX(double _ScalingX)
    bool SetScalingFactorY(double _ScalingY)
	double  GetScalingFactorX()
	double  GetScalingFactorY()
	bool SetRotation(double _Degrees )
    double GetRotation()
	bool SetAntiAliased(bool _AntiAliased )
	bool GetAntiAliased()      
    int GetCurrentVectorPostion()//returns the current index of where the sprocket is in the rendable list



class textBox : public Sprockets
public member funtions
textBox(std::string _NameTextBox,unsigned int _x,unsigned int _y,int _z,std::string _TextBoxMessage=" ",unsigned int _height=30,unsigned int _width=100,std::string _Font=True_Type_Font_Defalut,int _FontPoint=18,unsigned int _red=255,unsigned int _blue=255 ,unsigned int _green=255):Sprockets(_NameTextBox,Type_TextBox)
	
	~textBox()
	void SetText(std::string _text)//set the text that will be displayed in the textBox
	std::string GetText ()//get the text that the textBox is diplaying
	std::string GetFont()//get the font of the textBox
	void SetFont(std::string _FontArg)//set the font of the textBox
	int GetFontPoint()//Gets the size of the font
	void SetFontPoint(int _FontPointArg)//gets the size of the font
	SDL_Color GetTextColor()
	bool SetTextColor(unsigned int _red,unsigned int _blue ,unsigned int _green)//sets the color of the text in the textBox


class image: public Sprockets
public member funtions
	image (std::string _FileNameImage, std::string _NameImageHere,unsigned int _x,unsigned int _y,int _z,bool _Transparency=false):Sprockets( _NameImageHere,Type_Image ,_x, _y, _z)
  ~image()
	  std::string GetFileName()//get the name of the file assonated with the image
	void SetClippingRect(int _x,int _y,int _w,int _h)//Sets the clipping rectangle for the image
	bool GetClip() //gets if the drawing function uses the clipping rectangle
	int GetClippingX()
	int GetClippingY()
	int GetClippingW()
	int GetClippingH()
	void SetTransparency (bool _Transparency) //if true is passed then any pixels with the same color as the top left pixle will not be drawn 
	bool GetTransparency()//returns ture if the transparency flag is set flase otherwise
	

class Animation : public image 
public member functions
		Animation(std::string _FileName,std::string _AnimationName,int _fps,unsigned int _x,unsigned int _y, int _z,int _AnimStripFrames,int _StartFrame=0,int _Loop=1,bool _Transparency=false,bool _StartNow=true):image( _FileName, _AnimationName, _x, _y, _z,Type_Animation,_Transparency)
		void  JumpToFrame(int _Frame) //jumps the frame to _Frame
		void UpdateTime()//updates the current time for the animation and check to see if the frame needs to be incrmated
		int GetFPS()//returns the current frames per seconds for the animation
		void SetFPS(int _fps,unsigned int _time)//set the frames per seconds for the animation
		void SetClipingBoxForFrame() //sets cliping box for the current frame
		void StopAnimation()//Stops Animation
		void PlayAnimation()//Plays Animation and resets the number of times the animation has played
		void SetLoop(int _Loop)//sets the number of times to loop the animation
		int GetLoop()//returns the number of times the animation should loop
		int GetCurrentFrame()//get the current frame that is being displayed
		bool GetReversPlay()//returns true if the animation should play backwards false otherwise
		void SetReversPlay(bool _BackWards)//set to true to play animation backwards false otherwise
		int GetTotalNumberOfFrames()//gets the total number of frames in the animation. Frame one is always zero
		int GetNumberOfTimesPlayed()//gets the number if times the animation has played
		



class Button :image
public member funtions
	Button(std::string _ButtonFileNameImage, std::string _ButtonName,unsigned int _Buttonx,unsigned int _Buttony,int _Buttonz,bool _Transparency=false,bool _SButtonactive=true):image( _ButtonFileNameImage, _ButtonName, _Buttonx, _Buttony, _Buttonz,Type_Button,_Transparency)
    Button(std::string _ButtonName,unsigned int _Buttonx,unsigned int _Buttony,int _Buttonz,int m_iButtonheight,int m_iButtonwidth,bool _Transparency=false,bool _SButtonactive=true):image(" ", _ButtonName, _Buttonx, _Buttony, _Buttonz,Type_Button,_Transparency)
	Button()
	~Button()
	virtual Button * WasClicked(int _mouselocationX, int _mouselocationY)//determans if _mouselocationX and _mouselocationY are inclosed in the button (it the button was clicked by the user)
	void Disable()//disables the clickablity of the button
	void Enable()//enables the clickablity of the button
	bool GetActive()//returns where the button is enabled or disabled
	void DisableAndTurnOffDraw()//disables the button and hides the image
	void EnableAndTurnOnDraw()//enables the button and shows the image

class ButtonTB :textBox
public member funtions
    ButtonTB(std::string _ButtonName,unsigned int _Buttonx,unsigned int _Buttony,int _Buttonz,std::string _ButtonText ,bool _SButtonactive=true,unsigned int _ButtonTB_height=30,unsigned int _ButtonTB_width=100,std::string _ButtonTB_Font=True_Type_Font_Defalut,int _ButtonTB_FontPoint=18,unsigned int _ButtonTB_red=255,unsigned int _ButtonTB_blue=255 ,unsigned int _ButtonTB_green=255):textBox(Type_ButtonTB,_ButtonName, _Buttonx,_Buttony,_Buttonz,_ButtonText, _ButtonTB_height, _ButtonTB_width,_ButtonTB_Font,_ButtonTB_FontPoint,_ButtonTB_red, _ButtonTB_blue ,_ButtonTB_green)
  	Button()
	~Button()
	virtual ButtonTB * WasClicked(int _mouselocationX, int _mouselocationY)//determans if _mouselocationX and _mouselocationY are inclosed in the button (it the button was clicked by the user)
	void Disable()//disables the clickablity of the button
	void Enable()//enables the clickablity of the button
	bool GetActive()//returns where the button is enabled or disabled
	
 class sound 
 public member funtions
 int GetVolume()
 bool SetVolume(int _Volume)
 bool SetChannel(int _ChannelToSetTo)
 bool SetNumberOfTimesToLoop(int _NumberOfTimesToLoop)
 int GetChannel()
 int GetNumberOfTimesToLoop()
 std::string GetName()
 */




class EpeeEngine
{


public:
	EpeeEngine();
	EpeeEngine(std::vector<FileLookUp> filetable);
	~EpeeEngine();


	bool EventProcessing(SDL_Event *_event); //event processing for the graphics engin currently handles movement of buttons when pressed
	bool SetUp(unsigned int Screen_Width,unsigned int Screen_Heigth,bool FullSreenMod=false,std::string _WindowName="Your App Name Here",bool _Resize=false,int _fps=60,unsigned int _BitDepthOfScreen=16,bool Anyformat=false);
	bool SetUp(std::vector<FileLookUp> filetable,unsigned int Screen_Width,unsigned int Screen_Heigth,bool FullSreenMode=false,std::string _WindowName="Your App Name Here",bool _Resize=false,int _fps=60,unsigned int _BitDepthOfScreen=16,bool Anyformat=false);
	bool RenderSeen(bool _UpdateScreenNow=false); //call this to proccess the render list and pass true to this funtion for it to call updatescreen 
	bool UpdateScreen();// draws the proccesed render list to the screen
	
	image * CreateImageFromList(std::string _symbol,std::string _ImageName,int _x,int _y,int _z);//creates a new image from a filelist and adds it to renable list
    bool RemoveIteamFromRendableList(std::string _card); //removes the card from the rendable list
	
	bool SetNumberOfMixingChannels(int _NumberOfChannels);//Set up funtion for the sound list this need to be at lest on for sounds to work. This does not have any barring to the background music
	Sound *  FindSound(std::string _name);//returns a pointer to a sound object from the sound list
	Sound * CreateSound(std::string _GroupName,std::string _FileName,int _Channel=0,int _NumberOfTimesToLoop=0,int _Volume=MIX_MAX_VOLUME);//creates a new sound and adds it to the sound list
	bool DestroySound(std::string _name);//deletes the a sound from the sound list
	bool PlaySoundNow(Sound * _pSound);//plays a sound pointed to by _pSound

	bool SetAndPlayBackGroundMusic(std::string _NameOfAudio,int _NumberOfTimesToLoop,int _Volume=MIX_MAX_VOLUME,int _ms=0);//creates and plays background music. THIS IS NOT ADDED TO THE SOUND LIST. you can only have one music file loaded and playing at a time
	bool StopBackGroundMusic(int _ms=0);//stops the background music
	bool FadeInSound(Sound * _pSound,int _ms);
	bool FadeOutSound(Sound * _pSound,int _ms);
	bool FadeOutSound(int _Channel,int _ms);
	bool StopSoundNow(int _Channel);
	bool StopSoundNow(Sound * _pSound);
	bool IsSoundPlaying(Sound *_pSound);
	bool IsBackGoundMusicPlaying();
	
	bool LoadConfigurationFile(std::string _FileName);


		
	float GetTimeSinceSetup(); //gets the number of milliseconds since setup was called
	void SleepDelay(Uint32 _millisecounds);	//sleeps for _millisecounds does not use up clock cycles
	textBox * CreateTextBox(std::string _Name,int _x,int _y,int _z,std::string _TextBoxMessage=" ",std::string _AddtoCurrentRenderlist="Current",unsigned int _height=-1,unsigned int _width=-1,std::string _Font=True_Type_Font_Defalut,int _FontPoint=18,unsigned int _red=255,unsigned int _blue=255 ,unsigned int _green=255,std::string _FontPath = True_Type_Font_Location);//creates a textbox and adds it to the rendable list
    image * CreateImage(std::string _fileName ,std::string _Name,int _x,int _y,int _z,std::string  _AddtoCurrentRenderlist="Current",bool _Transparency=false);//creates image and adds it to the rendable list
	Animation * CreateAnimation(std::string _fileName ,std::string _Name,int _x,int _y,int _z,int _NumberOfFrames,int _fps,int _StartFrame=0,int _Loop=1,int _NumberOfRowsOfFrames=1,bool _Transparency=false,bool _StartNow=true,std::string  _AddtoCurrentRenderlist="Current");//Creates an animation and adds it to the renderable list
	AnimationScript * CreateAnimationScript(std::string _Name,Sprockets * _AnimationSprocket,PlayScrtipFuntionPointer* _ScrtipFuntionPointer,int _z,int  _TotalNumberOfFrames,int _fps=30,int _StartFrame=0,int _Loop=1,bool _StartNow=true,std::string  _AddtoCurrentRenderlist="Current");

	ButtonTB * CreateButtonTB(std::string _ButtonName,int _Buttonx,int _Buttony,int _Buttonz,std::string _ButtonText ,bool _SButtonactive=true,std::string  _AddtoCurrentRenderlist="Current",unsigned int _ButtonTB_height=30,unsigned int _ButtonTB_width=100,std::string _ButtonTB_Font=True_Type_Font_Defalut,int _ButtonTB_FontPoint=18,unsigned int _ButtonTB_red=255,unsigned int _ButtonTB_blue=255 ,unsigned int _ButtonTB_green=255,std::string _ButtonFontPath=True_Type_Font_Location);//creates a textbox that is a button on the screen and adds the button to the rendable list
	Button * CreateButton(std::string _localfileName ,std::string _localName,int _localx,int _localy,int _localz,bool _Transparency=false,bool _localactive=true,std::string  _AddtoCurrentRenderlist="Current");//creates a button that is attached to an image. the button is added to the rendable list
    Button * CreateButton(std::string _localName,int _localx,int _localy,int _localz,int _height,int _width,bool _Transparency=false,bool _localactive=true,std::string  _AddtoCurrentRenderlist="Current");//creates a button that is not attached to an image an is invsable to the user. this button is added to the rendable list but is not draw on the screen
   Sprockets * WasAButtonClicked(int _x, int _y);//returns the button that contanes the x and y values.
	
	textBox * FindTextBox(std::string _name);//returns a pointer to a textBox _name from the rendable list
	Button * FindButton(std::string _name);//returns a pointer to a Button _name from the rendable list
	ButtonTB * FindButtonTB(std::string _name);////returns a pointer to a ButtonTB _name from the rendable list
    image *FindImage(std::string _name);//returns a pointer to a Image _name from the rendable list
		Animation * FindAnimation(std::string _name);//returns a pointer to an Animation _name from the rendable list
		
		image* CloneImage(image * _imageToClone,std::string _nameOfImage,std::string _RenderList="Current",int _x=-1,int _y=-1,int _z=-1);

	textBox* CloneTextBox(textBox * _textBoxToClone,std::string _nameOfImage,std::string _RenderList="Current",int _x=-1,int _y=-1,int _z=-1 );
	//***********NOTE IMAGES,ANIMATIONS TEXTBOXES,AND BUTTONS ARE ALL SPROCKETS***********************
	bool DestroySprocket(std::string _name); // removes a sprocket from the rendable list
		Sprockets * FindSprockets(std::string _name,std::string _renderlist="Current"); //returns a pointer to a sprocket from the rendable list
	bool EpeeEngine::ChangeSprocketZ(Sprockets * _SprocketToChange,int _newZ,RenderList * _list=NULL);//changes the depth of a sprocket
		

	int GetFps(); // returns the current frames to a secound of the render engine
	bool SetFps(int _fps);//sets the frames to a secound of the render engine
	
	bool IsFoucsOnTextBox()
	{
		if (m_pCurrentEditedTextBox==NULL) {
			return false;
		}
		else
		{
			return true;
		}
		return false;
		
	}
std::string GetCurrentRenderList();
RenderList * GetCurrentRenderListptr();
	bool SetCurrentRentderList(std::string _ListToChangeTo);
	bool InsertRenderList(RenderList * _newRenderList);
	
bool DestroyRenderList(std::string _name);
bool RemoveIteamFromRendableList(std::string _card,std::string _renderList);
RenderList*  FindRenderList(std::string _name);
RenderList * CreateRenderList(std::string _name);
unsigned int GetTotalRenderList();
bool ValideVersionNumberOfCppWithHeader();
double GetVersionNumberH();
double GetVersionNumberCpp();
void TransferSprocketToNewRenderList(RenderList * _sorceRenderList,RenderList * _destinationRenderList,Sprockets * _sprocketToTransfer);

//template <typename datatype> datatype StringToNumericData(std::string _stringtoconvert,datatype temp);//temp is the data type that you want back
template <typename datatype> datatype StringToNumericData(std::string _stringtoconvert,datatype temp)
	{datatype tempint=0;

			std::istringstream tempstream(_stringtoconvert);
			if (!(tempstream>>tempint)) {
				std::string tempstring ="Could not convert"+_stringtoconvert+"to the specified data type";
				 EpeeEngineError temperror(tempstring,TEXTBOX_CONVERION_ERROR,this);
				 this->SetLastError(temperror);
				return 0;
			}
			this->ClearError();
			return tempint;
	}



//template <typename datatype> std::string  StringFromNumericData(datatype _value);
template <typename datatype> std::string StringFromNumericData(datatype _value)
	{datatype tempint=_value;
			std::ostringstream tempstream;
			if (!(tempstream<<_value)) {
				
				std::string tempstring ="Could not convert numeric data to string";
				 EpeeEngineError temperror(tempstring,TEXTBOX_CONVERION_ERROR,this);
				this->SetLastError(temperror);
				return "NULL";
				
			}
			this->ClearError();
			return tempstream.str(); 
			
			
	}



		
	//std::string GetLastError() {return m_sCurrentError;}//Returns the last error from the last funtion called
	 EpeeEngineError GetLastError() {return m_cLastError;}//Returns the last error from the last funtion called
	
	unsigned int GetTotalSprockesCreated();//returns that total number of sprockets created
	unsigned int GetTotalSoundsCreated();//returns the total number of sounds created
	void WriteRenderListToFile();//Writes the contents of the render list out to the cout file. Only works in debug right now
	void WriteSoundListToFile();//Writes the contents of the sound list out to the cout file. Only works in debug right now
	void TurnOnFPS();//Turns on the Frames Per Second in the upper left hand corner
	void TurnOffFPS();//Turns Off the Frames Per Second in the upper left hand corner
	void EpeeEngine::ToggleFullScreen(bool _FullScreen);//Toggles the window from fullscreen to window and back true for fullscreen false for windowed
    void ChangedResolution(int _Width, int _height,bool _useCurrentFlags=true,bool _FullScreen=false,bool _Resize=false,bool _AnyFormat=false);//Changes the current window resolution
	bool GetEvent(SDL_Event * _event); //Removes and polulates _event with the next event in the event que. Returns false if the is no events in the que returns true otherwise


	unsigned int GetCurrentScreenHeight();
	unsigned int GetCurrentScreenWidth();


	bool IsKeyDisplayable(SDLKey _KeyToCheck);
	char IsKeyModifiedByOtherKeys(SDLKey _KeyToCheck);
	ControlCharacters * GetControlCharacters();

	void DrawOutlineWithRect(SDL_Surface * _SurfaceToBeOutLined,SDL_Rect *OutLine,Uint8 _red=255,Uint8 _blue=0,Uint8 _green=0,unsigned int _thickness=1 );
	void DrawOutline(SDL_Surface * _SurfaceToBeOutLined,unsigned int _x,unsigned int _y,Uint8 _red=255,Uint8 _blue=0,Uint8 _green=0,unsigned int _thickness=1 );

private:
	void ClearError();
	void SetLastError(EpeeEngineError _error);
	void LoadAnimationFromFile(TiXmlElement *element);
	void LoadButtonTBFromFile(TiXmlElement *element);
	void  LoadButtonFromFile(TiXmlElement *element);
	void LoadTextBoxFromFile(TiXmlElement *element);
	void LoadImageFromFile(TiXmlElement *element);	
	bool WriteText(std::string TextToWrite,int x,int y,int point=12,std::string font="arial.ttf",int text_box_height=30,int text_box_width=200);
	bool WriteText(textBox* _TextBox);
	bool InsertIntoSprocketList(Sprockets * _newSprocket,RenderList * _List=NULL);
	bool DrawImage(image* _ImageToDraw);
	bool ScaleImageDraw(image* _ImageToDraw);
	void fpsDelay();
	bool UpdateVectorlocateion();
	bool PlaySoundNow(std::string _NameOfAudio,int _NumberOfTimesToLoop,int _Channel=-1);
	void HandleKeyBordEvents(SDL_Event *_event);
	void HadleKeyBordKeys(SDL_Event *_event,bool flagtemp);
	bool HandleMouseEvents(SDL_Event *_event);
	std::vector <FileLookUp> m_cfiletable;
	 Uint32 m_u32VideoFlags;
	//std::vector  <textBox*> m_vTextBoxList;
	//std::vector <Button> m_vButtonList;
//	std::vector  <Sprockets*> m_vSprocketsList;
	std::vector <RenderList*> m_vRenderList;
	std::vector <Sound*> m_vSounds;
	SDL_Surface *m_pscreen;
	EpeeEngineError m_cLastError;
	textBox * m_pCurrentEditedTextBox;
	 unsigned int m_iScreen_Heigth;
	unsigned int  m_iScreen_Width;
//	TTF_Font *m_pfont1;
	RenderList * m_uiCurrentRenderList;
	bool m_bFullScreen;
	bool m_bResizeAble;
	int m_ifps;
	FPSmanager m_cfpsManager;
	Mix_Music *m_pBackGroundMusic;
	std::string m_sCurrentError;
	Mix_Chunk * m_pSoundOne; 
	int m_iframe;
	int m_ifpstime;
	textBox * FrameRate;
	float m_fCurrentFrameRate;
	Sprockets  * m_pLastSprocketClicked;
	RenderList * m_LastRenderListFound;
	Sprockets * m_pDownedButton;
	unsigned int m_uiTotalRenderListsCreated;
	unsigned int m_uiTotalSoundsCreated;
	unsigned int m_uiTotalConnectionsCreated;
	bool SetKeyColor(SDL_Surface * _SurfaceToKey);
	int m_bHardWareAccelration;//0 is software 1 is openGl soon 2 will be directX 
	ControlCharacters m_cKeybordControlCharacters;


};




//template <typename datatype> datatype StringToNumericData(std::string _stringtoconvert,datatype temp);//temp is the data type that you want back
template <typename datatype> datatype StringToNumericData(std::string _stringtoconvert,datatype temp)
	{datatype tempint=0;

			std::istringstream tempstream(_stringtoconvert);
			if (!(tempstream>>tempint)) {
				std::string tempstring ="Could not convert"+_stringtoconvert+"to the specified data type";
				 //EpeeEngineError temperror(tempstring,TEXTBOX_CONVERION_ERROR,this);
				// this->SetLastError(temperror);
				return 0;
			}
		//	this->ClearError();
			return tempint;
	}



//template <typename datatype> std::string  StringFromNumericData(datatype _value);
template <typename datatype> std::string StringFromNumericData(datatype _value)
	{datatype tempint=_value;
			std::ostringstream tempstream;
			if (!(tempstream<<_value)) {
				
				std::string tempstring ="Could not convert numeric data to string";
				// EpeeEngineError temperror(tempstring,TEXTBOX_CONVERION_ERROR,this);
			//	this->SetLastError(temperror);
				return "NULL";
				
			}
			//this->ClearError();
			return tempstream.str(); 
			
			
	}





#endif



