#include <xtl.h>
#include "xbinput.h"
extern int FontCenteredText(WCHAR *,int,int, int);
extern int screenOptions;
extern int screenResize;
extern int screenResizeP;
extern int screenResizeI;
extern int screenResizePB;
extern int screenResizeJ;
extern int screenResizeG;
extern int screenResizeB;
extern int screenResizeA;
extern int screenResizeA2;
extern int screenOptionsM;
extern int screenOptionsHelp;
extern int screenResizeS;
extern int screenControllerOptions;
extern int screenCheatOptions;
extern int screensoundOptions;
extern int screenSoundOptions;
extern int screenLightGunOptions;
extern int screenGeneralOptions;
extern int screenResizeMovie;
extern int screenGeneralOptionsGG;
extern int FontInit(int i);
extern bool initMovie(char*);
int gameGuideLines = 22;
int gameGuideColor = 0;
int gameGuideFontSize = 15;
extern void buildCheatCodeList();
#include <string>
extern std::string romBasePath;
extern void  searchDirectory(std::string, bool);

int fontType = 0;
extern int mpType;
extern void switchMP(int i);

extern IDirect3DTexture8 *TexGUIPreview;
extern int cDist;
float screenShotSpeed = 3.0f;
float imageMovementSpeed = 0.1f;
float imageScaleSpeed = 0.01f;
extern int screenGUIOptions;
extern void setHeight(int v);
// Global instance of custom gamepad devices
extern int DisableMenuSounds;

extern void playEffect(int i);
int repeatAnimation = 1;
extern  void writeConfig();

#include "custom_launch_params.h"
extern float distA;
extern float minA;
extern float maxA;

extern float distA2;
extern float minA2;
extern float maxA2;
			
extern XBGAMEPAD g_Gamepads[4];
extern int zTopEO;
extern int zLeftEO;
int fadeSpeed = 18;
extern int rWidth;
int vSpace = 20;
extern int fontResizeV;
extern int fontResizeRumble;
extern int fontResizeGT;
extern int fontResizeIT;
extern int fontResizeS;
extern int fontResizeG;
extern int fontResizeCD;
extern int fontResizeM;
extern int gFont;
int GameNameColor = 0;//white
int GameNameSelectedColor = 4;
int FolderColor = 2;//green
int MenuOption = 0;
int MenuOptionSelected = 4;
int FontSizeGUI = 18;
int FullNameColor = 4;//yellow
DWORD menuColor[6];
int animationFPS = 6;
float animationSpeed = 0.12f;
extern float zTopS;
extern int zLeftGT;
extern int zTopGT;
int romBrowserCount = 13;

extern int zLeftIT;
extern int zTopIT;

extern int zLeftCC;
extern int zTopCC;
extern void loadGUIPreview(char* path);
extern float zLeftS ;
extern float zBottomS ;
extern float zRightS ;
//menuColor[FullNameColor];
////menuColor[FolderColor];
//menuColor[GameNameColor];
//menuColor[GameNameSelectedColor]
//menuColor[MenuOption]
int showNes6502 = 1;
int showTransparency = 0;
int transparency = 200;
int automaticScreenShotSwitching = 1;
extern int EnableVideoAudio;
extern unsigned char * keys;
extern int firstVidRender;
extern int FlickerFilter;
extern "C" {
extern unsigned char FPSAtStart;
extern  unsigned char FPSOn;
extern unsigned char RevStereo;
extern unsigned char SPCDisable;
extern unsigned char RewindStates;// = how many states 0 - 25
extern unsigned char RewindFrames;// = how many half seconds between rewind states 0 - 40
extern unsigned int per2exec;
extern unsigned int cfgper2exec;
extern void Setper2exec();
extern int Bper2exec ;
extern int Bcfgper2exec ;


}
int screenResizeJS = 0;

int screenResizeG = 0;
extern  int HardwareFilter;
extern unsigned char SoftwareFilter;
extern  int FlickerFilter;
extern  int ShowFPS;
extern  int Soften;
int guiOptionSelected = 0;
extern void setFlickerSoft();
extern int LowPassFilter;
extern int SoundFrequency;
extern int SoundInterpolation;
extern int SurroundSound;

extern "C" {
extern void SetReverseStereo();
extern void SetSPCEnable();
extern void setFrequency();
extern void setLowPassFilter();
extern void setSoundInterpolation();
extern void setSurroundSound();
}



extern int fadeColor;
extern int fadeColor2;
extern int DisableMenuSounds;

extern "C" {
	extern unsigned char ForceROMTiming;
	extern unsigned char pl3contrl;
	extern unsigned char pl4contrl;
}

extern int Disable34;
extern int DisableSaveStates;

extern void processOptions();

extern int inGame;

extern int HighRes;
int showBorder = 1;
extern float XBINPUT_DEADZONE;
extern int fontResizeR;
extern int fontResizeEO;
extern int fontResizeCO;
extern int fontResizeCC;
extern int fontResizeClip;
extern int fontResizeTO;
extern int fontResizeCCO;
extern int fontResizeF; 


extern int FontSetColour(unsigned int colour);
extern int FontText(WCHAR *,int,int, int);

//*************************************************************************
//DRAW
int yGUI = 0;
int drawGUI_Count = 0;

void drawGUIText(char* text) {
     DWORD color = menuColor[MenuOption];
     
	// WCHAR text2345678_[80]={0};
	// wsprintfW(text2345678_,  L"Option Selected: %d, ShowFPS: %d", controllerConfigSelected, B[0].Button_ShowFPS);
	// FontSetColour(0xffff00);
	// FontText(text2345678_,50,300, 600);
	 
	 
	 
	 if(drawGUI_Count == guiOptionSelected) color = menuColor[MenuOptionSelected]; 
     
     //Draw the text string
     WCHAR text23456789[80]={0};
	 //wsprintfW(text2345678_, (LPCWSTR)text);

	 for(int i = 0; i < 1000; i++) {
		 if(text[i] == '\0') {
			text23456789[i] = '\0';
			break;
		 }
		 text23456789[i] = text[i];
	 }
	 FontSetColour(color);
	 
	 if(gFont == 5) {	
		FontText(text23456789,400+zLeftIT,yGUI+10+zTopIT, 600);
		yGUI += vSpace;
		drawGUI_Count++;
	    return;
	 }
	 int xO = 640/2;
//	 int yO = 130;
	 if(gFont == 3)
		FontCenteredText(text23456789,xO+zLeftEO,yGUI+zTopEO, 600);	
	 else
		 FontText(text23456789,400+zLeftGT,yGUI+zTopGT, 600);
	 yGUI += vSpace;
     drawGUI_Count++;
}

void drawG_Text(char* text) {
		
     DWORD color = menuColor[MenuOption];
     
	// WCHAR text2345678_[80]={0};
	// wsprintfW(text2345678_,  L"Option Selected: %d, ShowFPS: %d", controllerConfigSelected, B[0].Button_ShowFPS);
	// FontSetColour(0xffff00);
	// FontText(text2345678_,50,300, 600);
	 
	 if(drawGUI_Count == guiOptionSelected) color = menuColor[MenuOptionSelected]; 
     
     //Draw the text string
     WCHAR text23456789[80]={0};
	 //wsprintfW(text2345678_, (LPCWSTR)text);

	 for(int i = 0; i < 1000; i++) {
		 if(text[i] == '\0') {
			text23456789[i] = '\0';
			break;
		 }
		 text23456789[i] = text[i];
	 }
	 FontSetColour(color);
	 int xO = 640/2;
//	 int yO = 130;
	 //FontText(texta12345678_,xO+zLeftEO,yO+zTopEO, 700);
	//		yO += oSpace;
	 //+zLeftEO
	 
	 if(gFont == 5) {
		
		FontText(text23456789,150+zLeftIT,yGUI+10+zTopIT, 700);
	    return;
	 }

	 if(gFont == 3) 
		FontCenteredText(text23456789,xO+zLeftEO,yGUI+zTopEO, 700);	
	 else
		 FontText(text23456789,165+zLeftGT,yGUI+zTopGT, 700);
	 //yGUI += 20;
     //drawGUI_Count++;
}

float zoomSpeed = 25.0f;

#include <string>
#include <vector>
using namespace std;
vector<std::string> skins;
#include <algorithm>

void buildSkinList() {
	skins.clear();

	HANDLE find=NULL;
	WIN32_FIND_DATA wfd;
	memset(&wfd,0,sizeof(wfd));

	find=FindFirstFile("D:\\skins\\*",&wfd);

	if (find==INVALID_HANDLE_VALUE)return;

	for (;;)
	{
		if((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
		   std::string t1(wfd.cFileName);
		   if(skins.size() <= 15) skins.push_back(t1);
		}
		if (FindNextFile(find,&wfd)==0) break;
	}
	sort(skins.begin(), skins.end());
	FindClose(find);
	loadGUIPreview((char*)skins[0].c_str());
}

void drawSkinList() {
	for(int i = 0; i < skins.size(); i++) {
		drawG_Text((char*)skins[i].c_str());drawGUIText("");
	}
}
extern void loadScreen();
extern "C" int dprintf(char *format, ...);
extern void loadTextures(char* path, int i);
extern void loadSkinIniFromFolder(char* folder);
extern void writeConfig();
extern char skinPath[512];
void changeSkin() {
	dprintf("Current skinpath: %s\n",skinPath);
	dprintf("Number of skins: %d\n", skins.size());
	dprintf("Selected skin: %d\n", guiOptionSelected);
	/*if(skins.size() > 0 && guiOptionSelected > 0) {
		dprintf("skins[guiOptionSelected]: %s\n", (char*)skins[guiOptionSelected].c_str());
	}
	else {
		dprintf("skins error\n");
		return;
	}*/



	for(int i = 0; i < 512; i++) skinPath[i] = '\0';
	for(int i = 0; i < 512; i++) {
		if(skins[guiOptionSelected][i] == '\0') {
			skinPath[i] = skins[guiOptionSelected][i];
			break;
		}
		skinPath[i] = skins[guiOptionSelected][i];
	}

	dprintf("new skinPath: %s\n", skinPath);
	for(int i = 0; i < 512; i++) {
		if(skinPath[i] == '\n') skinPath[i] = '\0';
	}

	dprintf("skinPath: %s\n", skinPath);
	
	loadSkinIniFromFolder(skinPath);
	
	dprintf("before writeConfig();\n");
	writeConfig();
	dprintf("after writeConfig();\n");
	dprintf("Just loaded new skin ini. skinPath written is: %s\n", skinPath);

	//////dprintf("Just Saved: %s", skinPath);
	//////dprintf("Just Saved: %s\n", skinPath);
	//reset the emulator



	//Loading screen
	loadScreen();

	dprintf("Just loaded new skin ini. skinPath written is: %s\n", skinPath);



	PLAUNCH_DATA ldata ;
	memset( &ldata, 0, sizeof(PLAUNCH_DATA) ) ;
	XLaunchNewImage( "D:\\default.xbe", ldata ) ;
	

}

void checkGUIOptions() {
   if(g_Gamepads[0].Event == XBGAMEPAD_B) {
	   if(DisableMenuSounds == 0) playEffect(1);
	   if(gFont == 2) {
		  gFont = 1;
		  guiOptionSelected = 0;
		  return;
	   }


	   if(gFont == 4) {
		  gFont = 0;
		  guiOptionSelected = 0;
		  return;
	   }

	   if(gFont == 5) {
		  gFont = 3;
		  guiOptionSelected = 2;
		  if(TexGUIPreview) {
			TexGUIPreview->Release();
			TexGUIPreview = NULL;
		  }
		  return;
	   }

	   if(gFont == 0 || gFont == 1) {
		   guiOptionSelected = gFont ^ 1;
		   gFont = 3;
		  
		  return;
	   }
	   
      screenGeneralOptions = 0;
	  screenGeneralOptionsGG = 0;
	  screenGUIOptions = 0;
      screenOptionsM   = 0;
	  screenResize = 0;
	  screenOptionsHelp   = 0;
	  screenResizeP = 0;
	  screenResizeI = 0;
	  screenResizePB = 0;
	  screenResizeJ = 0;
	  screenResizeG = 0;
	  screenResizeB = 0;
	  screenResizeA = 0;
	  screenResizeA2 = 0;
	  screenResizeS = 0;
	  screenControllerOptions = 0;
	 // fadeColor = 255;
	 // fadeColor2 = 255;
	  screenOptions = 1;
	  writeConfig();
	  
      return;          
   } 
   
   if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_DOWN)  {  
		if(DisableMenuSounds == 0) playEffect(0);	
		guiOptionSelected++;
		
		if(gFont == 3) {
			if(guiOptionSelected > 2) guiOptionSelected = 0;
			return;
		}
		if(gFont == 4) {
			if(guiOptionSelected > 14) guiOptionSelected = 0;
			return;
		}

		if(gFont == 5) {
			
			if(guiOptionSelected > (skins.size()-1)) guiOptionSelected = 0;

			loadGUIPreview((char*)skins[guiOptionSelected].c_str());
			return;
		}

		if(gFont == 2) {
			if(guiOptionSelected > 15) guiOptionSelected = 0;
			return;
		}
		if(gFont == 1) { 
			if(guiOptionSelected > 14) guiOptionSelected = 0;
		}
		else {
			if(guiOptionSelected > 14) guiOptionSelected = 0;
		}
   
   }	

   if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_UP)  {  
		if(DisableMenuSounds == 0) playEffect(0);	
		guiOptionSelected--; 

		if(gFont == 4) {
			if(guiOptionSelected < 0) guiOptionSelected = 14;
			return;
		}
		if(gFont == 5) {

			if(guiOptionSelected < 0)  guiOptionSelected = (skins.size()-1);

			loadGUIPreview((char*)skins[guiOptionSelected].c_str());
			return;
		}
		if(gFont == 3) {
			if(guiOptionSelected < 0) guiOptionSelected = 2;
			return;
		}

		if(gFont == 2) {
			if(guiOptionSelected < 0) guiOptionSelected = 15;
			return;
		}

		if(gFont == 1) { 
			if(guiOptionSelected < 0) guiOptionSelected = 14;//font
		}
		else {
			if(guiOptionSelected < 0) guiOptionSelected = 14;
		}  
   }  

   if(g_Gamepads[0].Event == XBGAMEPAD_A) {
       dprintf("A pressed\n");
	  
	   if(gFont == 3) {
		   if(DisableMenuSounds == 0) playEffect(2);
		   //if(optionSelectedM == 2 ) { fadeOption = 1; fadeColor = 255; fadeColor2 = 255;guiOptionSelected = 0; screenOptionsM = 0; screenGUIOptions = 1; gFont = 3; screenOptions = 0;}
			if(guiOptionSelected == 0){ gFont = 1; guiOptionSelected = 0; }
			if(guiOptionSelected == 1){ gFont = 0; guiOptionSelected = 0; }
			if(guiOptionSelected == 2){ gFont = 5; buildSkinList(); guiOptionSelected = 0;}
			return;
		}

	   if(gFont == 5) {
		   if(DisableMenuSounds == 0) playEffect(2);
		    dprintf("Change skin\n");
			changeSkin();
			return;
	   }

	   if(gFont == 2) {
		   if(DisableMenuSounds == 0) playEffect(2);
			if(guiOptionSelected == 0){ fontResizeEO = 1; fontResizeF = 0;screenGUIOptions = 0; }
			if(guiOptionSelected == 1){ fontResizeCO = 1; fontResizeF = 0;screenGUIOptions = 0;}
			if(guiOptionSelected == 2){ fontResizeTO = 1; fontResizeF = 0;screenGUIOptions = 0;}
			if(guiOptionSelected == 3){ fontResizeCCO = 1; fontResizeF = 0;screenGUIOptions = 0;}
			if(guiOptionSelected == 4){ fontResizeGT = 1; fontResizeF = 0;screenGUIOptions = 0;}
			if(guiOptionSelected == 5){ fontResizeIT = 1; fontResizeF = 0;screenGUIOptions = 0;}
			if(guiOptionSelected == 6){ fontResizeCC = 1; fontResizeF = 0;screenGUIOptions = 0;}
			if(guiOptionSelected == 7){ 
				//dprintf("7 - Build cheat code list\n");
				buildCheatCodeList();
				//dprintf("7 - After build cheat code list\n");
				fontResizeClip = 1; 
				fontResizeF = 0;
				screenGUIOptions = 0;
			}
			if(guiOptionSelected == 8){ rWidth++; if(rWidth > 640) rWidth = 10;}
			if(guiOptionSelected == 9){ 
				//dprintf("9 - Build cheat code list\n");
				buildCheatCodeList(); 
				//dprintf("9 - After build cheat code list\n");
				fontResizeCD = 1; 
				fontResizeF = 0;
				screenGUIOptions = 0;
			}
			if(guiOptionSelected == 10){ romBrowserCount++; if(romBrowserCount > 25) romBrowserCount = 1;}
			if(guiOptionSelected == 11) {fontResizeRumble = 1; fontResizeF = 0;screenGUIOptions = 0; }
			if(guiOptionSelected == 12) {
				fontType++; 
				if(fontType > 4) fontType = 0;
				FontInit(fontType);  
				setHeight(FontSizeGUI);
			}

			if(guiOptionSelected == 13) {gameGuideLines++; if(gameGuideLines > 100) gameGuideLines = 1;}
			if(guiOptionSelected == 14) {gameGuideColor += 1; gameGuideColor &= 1; }
			if(guiOptionSelected == 15) {gameGuideFontSize++; if(gameGuideFontSize > 50) gameGuideFontSize = 14;  }


			return;
		}

	   if(gFont == 4) {
		   if(DisableMenuSounds == 0) playEffect(2);
			if(guiOptionSelected == 0){ minA2+=0.0001f;}
			if(guiOptionSelected == 1){ maxA2+=0.0001f;}
			if(guiOptionSelected == 2){ distA2+=0.00001f;}
			if(guiOptionSelected == 3){ minA+=0.0001f;}
			if(guiOptionSelected == 4){ maxA+=0.0001f;}
			if(guiOptionSelected == 5){ distA+=0.00001f;}
			if(guiOptionSelected == 6){ cDist+=5;}
			if(guiOptionSelected == 7) {repeatAnimation += 1; repeatAnimation &= 1; }
			if(guiOptionSelected == 8){ zoomSpeed+=0.5f; if(zoomSpeed > 50) zoomSpeed = 0.5f; }
			if(guiOptionSelected == 9) {automaticScreenShotSwitching += 1; automaticScreenShotSwitching &= 1; }
			if(guiOptionSelected == 10){ screenShotSpeed+=0.5f; if(screenShotSpeed > 10) screenShotSpeed = 0.5f; }
			if(guiOptionSelected == 11){ screenResizeMovie = 1; initMovie("D:\\media\\videopreview.xmv"); screenGUIOptions = 0; }
			if(guiOptionSelected == 12){ imageMovementSpeed+=0.1f; if(imageMovementSpeed > 10) imageMovementSpeed = 0.1f; }
			if(guiOptionSelected == 13){ imageScaleSpeed+=0.01f; if(imageScaleSpeed > 1) imageScaleSpeed = 0.01f; }
			if(guiOptionSelected == 14){EnableVideoAudio += 1; EnableVideoAudio &= 1; }

			return;
	   }
		 
	   if(gFont == 1) {
		 if(DisableMenuSounds == 0) playEffect(2);
	     if(guiOptionSelected == 0){ GameNameColor++; if(GameNameColor > 5) GameNameColor = 0; }
		 if(guiOptionSelected == 1) {GameNameSelectedColor++; if(GameNameSelectedColor > 5) GameNameSelectedColor = 0; }
		 if(guiOptionSelected == 2) {FullNameColor++; if(FullNameColor > 5) FullNameColor = 0; }
		 if(guiOptionSelected == 3) {FolderColor++; if(FolderColor > 5) FolderColor = 0; }
		 if(guiOptionSelected == 4) {MenuOption++; if(MenuOption > 5) MenuOption = 0; }
		 if(guiOptionSelected == 5) { MenuOptionSelected++; if( MenuOptionSelected > 5)  MenuOptionSelected = 0; }
		 if(guiOptionSelected == 6) {FontSizeGUI++; if(FontSizeGUI > 50) FontSizeGUI = 14; setHeight(FontSizeGUI); }
		 if(guiOptionSelected == 7) {vSpace++; if(vSpace > 40) vSpace = 10;  }
		 if(guiOptionSelected == 8) {fontResizeR = 1; screenGUIOptions = 0; 
				searchDirectory(romBasePath, false);
		   }
		  if(guiOptionSelected == 9) {searchDirectory(romBasePath, false); fontResizeF = 1; screenGUIOptions = 0; }
		  if(guiOptionSelected == 10) {fontResizeV = 1; fontResizeF = 0;screenGUIOptions = 0; }
		  if(guiOptionSelected == 11) {fontResizeS = 1; fontResizeF = 0;screenGUIOptions = 0; }
		  if(guiOptionSelected == 12) {fontResizeG = 1; fontResizeF = 0;screenGUIOptions = 0; }
		  if(guiOptionSelected == 13) {fontResizeM = 1; fontResizeF = 0;screenGUIOptions = 0; }
		  if(guiOptionSelected == 14) {gFont = 2; guiOptionSelected = 0;}
		 
	   }
	   else {
		   if(DisableMenuSounds == 0) playEffect(2);
		 if(guiOptionSelected == 0) {showTransparency += 1; showTransparency &= 1; }
		 if(guiOptionSelected == 1){  screenResizeP = 1; screenGUIOptions = 0; }
		 if(guiOptionSelected == 2){ screenResizeJ = 1; screenGUIOptions = 0;}
		 if(guiOptionSelected == 3){ screenResizePB = 1; screenGUIOptions = 0; }
		 if(guiOptionSelected == 4){ screenResizeB = 1; screenGUIOptions = 0; }
		 if(guiOptionSelected == 5){ screenResizeA = 1; screenGUIOptions = 0; }
		 if(guiOptionSelected == 6){ 
			 screenResizeS = 1; screenGUIOptions = 0; }
		 if(guiOptionSelected == 7){ animationFPS++; if(animationFPS > 60) animationFPS = 1; }
		 if(guiOptionSelected == 8){ animationSpeed+=0.00005; if(animationSpeed > 5) animationSpeed = 0.1f;}
		 if(guiOptionSelected == 9){ screenResizeG = 1; screenGUIOptions = 0;}
		 if(guiOptionSelected == 10){ transparency++; if(transparency > 255) transparency = 0; }
		 if(guiOptionSelected == 11) {showBorder += 1; showBorder &= 1; }
		 if(guiOptionSelected == 12){ fadeSpeed+=1; if(fadeSpeed > 255) fadeSpeed = 0;}
		 if(guiOptionSelected == 13){ screenResizeA2 = 1; screenGUIOptions = 0; }
		 if(guiOptionSelected == 14){ gFont = 4; guiOptionSelected = 0; }

	   }
		 
   }

   if(g_Gamepads[0].Event == XBGAMEPAD_X) {
       if(DisableMenuSounds == 0) playEffect(2);
	  
	    if(gFont == 3) {
			if(guiOptionSelected == 0){ gFont = 1; }
			if(guiOptionSelected == 1){ gFont = 0; }
			if(guiOptionSelected == 2){ gFont = 5; }
			return;
		}

	   if(gFont == 2) {
			if(guiOptionSelected == 0){fontResizeEO = 1; fontResizeF = 0;screenGUIOptions = 0; }
			if(guiOptionSelected == 1){fontResizeCO = 1; fontResizeF = 0;screenGUIOptions = 0; }
			if(guiOptionSelected == 2){ fontResizeTO = 1; fontResizeF = 0;screenGUIOptions = 0;}
			if(guiOptionSelected == 3){ fontResizeCCO = 1; fontResizeF = 0;screenGUIOptions = 0;}
			if(guiOptionSelected == 4){ fontResizeGT = 1; fontResizeF = 0;screenGUIOptions = 0;}
			if(guiOptionSelected == 5){ fontResizeIT = 1; fontResizeF = 0;screenGUIOptions = 0;}
			if(guiOptionSelected == 6){ fontResizeCC = 1; fontResizeF = 0;screenGUIOptions = 0;}
			if(guiOptionSelected == 7){ buildCheatCodeList(); fontResizeClip = 1; fontResizeF = 0;screenGUIOptions = 0;}
			if(guiOptionSelected == 8){ rWidth--; if(rWidth < 10) rWidth = 640;}
			if(guiOptionSelected == 9){ buildCheatCodeList(); fontResizeCD = 1; fontResizeF = 0;screenGUIOptions = 0;}
			if(guiOptionSelected == 10){ romBrowserCount--; if(romBrowserCount < 1) romBrowserCount = 25;}
			if(guiOptionSelected == 11) {fontResizeRumble = 1; fontResizeF = 0;screenGUIOptions = 0; }
			if(guiOptionSelected == 12) {
				fontType--; 
				if(fontType < 0) fontType = 4;
				FontInit(fontType );	
				setHeight(FontSizeGUI);
			}
			//int gameGuideLines = 44;
			//int gameGuideColor = 0;
			//int gameGuideFontSize = 15;
			if(guiOptionSelected == 13) {gameGuideLines--; if(gameGuideLines < 1) gameGuideLines = 100;}
			if(guiOptionSelected == 14) {gameGuideColor += 1; gameGuideColor &= 1; }
			if(guiOptionSelected == 15) {gameGuideFontSize--; if(gameGuideFontSize < 14) gameGuideFontSize = 50;  }




			return;
		}

	   if(gFont == 4) {
			if(guiOptionSelected == 0){ minA2-=0.0001f;}
			if(guiOptionSelected == 1){ maxA2-=0.0001f;}
			if(guiOptionSelected == 2){ distA2-=0.00001f;}
			if(guiOptionSelected == 3){ minA-=0.0001f;}
			if(guiOptionSelected == 4){ maxA-=0.0001f;}
			if(guiOptionSelected == 5){ distA-=0.00001f;}
			if(guiOptionSelected == 6){ cDist-=5;}
			if(guiOptionSelected == 7) {repeatAnimation += 1; repeatAnimation &= 1; }
			if(guiOptionSelected == 8){ zoomSpeed-=0.5f; if(zoomSpeed < 0) zoomSpeed = 50.0f; }
			if(guiOptionSelected == 9) {automaticScreenShotSwitching += 1; automaticScreenShotSwitching &= 1; }
			if(guiOptionSelected == 10){ screenShotSpeed-=0.5f; if(screenShotSpeed < 0.5f) screenShotSpeed = 10.0f; }
			if(guiOptionSelected == 11){ screenResizeMovie = 1; initMovie("D:\\media\\videopreview.xmv"); screenGUIOptions = 0; }
			if(guiOptionSelected == 12){ imageMovementSpeed-=0.1f; if(imageMovementSpeed < 0.1f) imageMovementSpeed = 10; }
			if(guiOptionSelected == 13){ imageScaleSpeed-=0.01f; if(imageScaleSpeed < 0.01f) imageScaleSpeed = 1; }
			if(guiOptionSelected == 14){EnableVideoAudio -= 1; EnableVideoAudio &= 1; }
			return;
	   }

	   if(gFont == 1) {
		   if(guiOptionSelected == 0){ GameNameColor--; if(GameNameColor < 0) GameNameColor = 5; }
		   if(guiOptionSelected == 1) {GameNameSelectedColor--; if(GameNameSelectedColor  < 0) GameNameSelectedColor = 5; }
		   if(guiOptionSelected == 2) {FullNameColor--; if(FullNameColor  < 0) FullNameColor = 5; }
		   if(guiOptionSelected == 3) {FolderColor--; if(FolderColor  < 0) FolderColor = 5; }
		   if(guiOptionSelected == 4) {MenuOption--; if(MenuOption  < 0) MenuOption = 5; }
		   if(guiOptionSelected == 5) { MenuOptionSelected--; if( MenuOptionSelected  < 0)  MenuOptionSelected = 5; }
		   if(guiOptionSelected == 6) {FontSizeGUI--; if(FontSizeGUI  < 14) FontSizeGUI = 50; setHeight(FontSizeGUI); }
		   if(guiOptionSelected == 7) {vSpace--; if(vSpace < 10) vSpace = 40;  }
		   if(guiOptionSelected == 8) {fontResizeR = 1; screenGUIOptions = 0; 
				searchDirectory(romBasePath, false);
		   }
		   if(guiOptionSelected == 9) {searchDirectory(romBasePath, false); fontResizeF = 1; screenGUIOptions = 0; }
		   if(guiOptionSelected == 10) {fontResizeV = 1; fontResizeF = 0;screenGUIOptions = 0; }
		    if(guiOptionSelected == 11) {fontResizeS = 1; fontResizeF = 0;screenGUIOptions = 0; }
			 if(guiOptionSelected == 12) {fontResizeG = 1; fontResizeF = 0;screenGUIOptions = 0; }
			  if(guiOptionSelected == 13) {fontResizeM = 1; fontResizeF = 0;screenGUIOptions = 0; }
			  if(guiOptionSelected == 14) {gFont = 2; guiOptionSelected = 0;}
	   }
	   else {
			   if(guiOptionSelected == 0) {showTransparency += 1; showTransparency &= 1; }
			   if(guiOptionSelected == 1){  screenResizeP = 1; screenGUIOptions = 0; }
			   if(guiOptionSelected == 2){ screenResizeJ = 1; screenGUIOptions = 0;}
			   if(guiOptionSelected == 3){ screenResizePB = 1; screenGUIOptions = 0; }
			   if(guiOptionSelected == 4){ screenResizeB = 1; screenGUIOptions = 0; }
			   if(guiOptionSelected == 5){ screenResizeA = 1; screenGUIOptions = 0; }
			   if(guiOptionSelected == 6){ 
				   screenResizeS = 1; screenGUIOptions = 0; }
			   if(guiOptionSelected == 7){ animationFPS--; if(animationFPS < 1) animationFPS = 60; }
			   if(guiOptionSelected == 8){ animationSpeed-=0.00005; if(animationSpeed < 0) animationSpeed = 5.0f; }
			   if(guiOptionSelected == 9){ screenResizeG = 1; screenGUIOptions = 0;}
			   if(guiOptionSelected == 10){ transparency--; if(transparency < 0) transparency = 255; }
			   if(guiOptionSelected == 11) {showBorder += 1; showBorder &= 1; }
			   if(guiOptionSelected == 12){ fadeSpeed-=1; if(fadeSpeed < 0) fadeSpeed = 255;}
			   if(guiOptionSelected == 13){ screenResizeA2 = 1; screenGUIOptions = 0; }
			   if(guiOptionSelected == 14){ gFont = 4; guiOptionSelected = 0; }
		}
		 
   }
   return;
} 



extern int sWidth;
#include <sstream>

extern int FontSmallText(WCHAR *,int,int, int);
void drawGUIOptions() {
		/*WCHAR text2345[280]={0};
		wsprintfW(text2345,L"Press \"B\" to exit.");
		FontSetColour(0xffff00);
		FontSmallText(text2345,sWidth/2,70, 600);*/
	    drawGUI_Count = 0;
        yGUI = 110;

		if(gFont == 3) {
			yGUI = 130;
			drawG_Text("Text Options"); drawGUIText("");
			drawG_Text("Image Options"); drawGUIText("");	
			drawG_Text("Skins"); drawGUIText("");	
			return;
		}

		if(gFont == 2) {
			drawG_Text("Emulator + GUI Options Menu Text Adjust"); drawGUIText("");
			drawG_Text("Controller Menu Text Adjust"); drawGUIText("");
			drawG_Text("Turbo Options Text Adjust "); drawGUIText("");
			drawG_Text("Controller Options Text Adjust "); drawGUIText("");
			drawG_Text("Text Options + Image Options Adjust"); drawGUIText("");
			drawG_Text("In-Game Options + Save/Load State Text Adjust"); drawGUIText("");
			drawG_Text("3 Digit Cheat Code Text Adjust"); drawGUIText("");
			drawG_Text("Cheat Code Clipping Adjust"); drawGUIText("");
			
			std::ostringstream q5;
			q5 << rWidth;
			std::string w5 = q5.str();
			drawG_Text("Rombrowser Text Width: "); drawGUIText((char*)w5.c_str());
			drawG_Text("Game Genie Database Adjust"); drawGUIText("");
			
			std::ostringstream gq5;
			gq5 << romBrowserCount;
			std::string gw5 = gq5.str();
			drawG_Text("Rombrowser Count: "); drawGUIText((char*)gw5.c_str());

			drawG_Text("Rumble Options Text Adjust "); drawGUIText("");

			if(fontType == 0){ drawG_Text("Font Type: "); drawGUIText("Font 1");}
			if(fontType == 1) {drawG_Text("Font Type: "); drawGUIText("Font 2");}
			if(fontType == 2) {drawG_Text("Font Type: "); drawGUIText("Font 3");}
			if(fontType == 3) {drawG_Text("Font Type: "); drawGUIText("Font 4");}
			if(fontType == 4) {drawG_Text("Font Type: "); drawGUIText("Font 5");}	




			std::ostringstream gq53;
			gq53 << gameGuideLines;
			std::string gw53 = gq53.str();
			drawG_Text("Game Guide Line Count: "); drawGUIText((char*)gw53.c_str());
			
			if(gameGuideColor == 0) {
				drawG_Text("Game Guide Font Color: "); drawGUIText("Green");
			}
			else {
				drawG_Text("Game Guide Font Color: "); drawGUIText("White");
			}

			std::ostringstream gq53e;
			gq53e << gameGuideFontSize;
			std::string gw53e = gq53e.str();
			drawG_Text("Game Guide Font Size: "); drawGUIText((char*)gw53e.c_str());

			return;
		}

		if(gFont == 5) {
			drawSkinList();
			return;
		}


		if(gFont == 4) {
			std::ostringstream q0;
			q0 << minA2;
			std::string w0 = q0.str();
			drawG_Text("RB Animated Logo Min:"); drawGUIText((char*)w0.c_str());
			
			std::ostringstream q1;
			q1 << maxA2;
			std::string w1 = q1.str();
			drawG_Text("RB Animated Logo Max:"); drawGUIText((char*)w1.c_str());

			std::ostringstream q2;
			q2 << distA2;
			std::string w2 = q2.str();
			drawG_Text("RB Animated Logo Speed:"); drawGUIText((char*)w2.c_str());
			

			std::ostringstream q0a;
			q0a << minA;
			std::string w0a = q0a.str();
			drawG_Text("MM Animated Logo Min:"); drawGUIText((char*)w0a.c_str());
			
			std::ostringstream q1aa;
			q1aa << maxA;
			std::string w1aa = q1aa.str();
			drawG_Text("MM Animated Logo Max:"); drawGUIText((char*)w1aa.c_str());

			std::ostringstream q2aaa;
			q2aaa << distA;
			std::string w2aaa = q2aaa.str();
			drawG_Text("MM Animated Logo Speed:"); drawGUIText((char*)w2aaa.c_str());

			std::ostringstream rq0;
			rq0 << cDist;
			std::string rw0 = rq0.str();
			drawG_Text("RB Animation Delay:"); drawGUIText((char*)rw0.c_str());

			
			if(repeatAnimation == 1) {
				drawG_Text("RB Animation Repeat:"); drawGUIText("On");
			
			}
			else {
				drawG_Text("RB Animation Repeat:"); drawGUIText("Off");
			}

			std::ostringstream drq0;
			drq0 << zoomSpeed;
			std::string drw0 = drq0.str();
			drawG_Text("Exit Game Animation Speed:"); drawGUIText((char*)drw0.c_str());

			

			if(automaticScreenShotSwitching == 1) {
				drawG_Text("Screenshot Switching:"); drawGUIText("On");
			
			}
			else {
				drawG_Text("Screenshot Switching:"); drawGUIText("Off");
			}

			std::ostringstream gdrq0;
			gdrq0 << screenShotSpeed;
			std::string gdrw0 = gdrq0.str();
			drawG_Text("Preview Switching Speed:"); drawGUIText((char*)gdrw0.c_str());

	
			drawG_Text("Video Preview Adjust"); drawGUIText("");
			
			std::ostringstream gdrq0q;
			gdrq0q << imageMovementSpeed;
			std::string gdrw0q = gdrq0q.str();
			drawG_Text("Image Movement Speed:"); drawGUIText((char*)gdrw0q.c_str());
			
			std::ostringstream gdrq0qq;
			gdrq0qq << imageScaleSpeed;
			std::string gdrw0qq = gdrq0qq.str();
			drawG_Text("Image Scale Speed:"); drawGUIText((char*)gdrw0qq.c_str());

			if(EnableVideoAudio == 1) {
				drawG_Text("Video Preview Audio:"); drawGUIText("On");
			
			}
			else {
				drawG_Text("Video Preview Audio:"); drawGUIText("Off");
			}
			return;
		}

		if(gFont == 1) {

			if(GameNameColor == 0) { drawG_Text("File Color: "); drawGUIText("White");  }
			if(GameNameColor == 1) { drawG_Text("File Color: "); drawGUIText("Red");  }
			if(GameNameColor == 2) { drawG_Text("File Color: "); drawGUIText("Green");  }
			if(GameNameColor == 3) { drawG_Text("File Color: "); drawGUIText("Blue");  }
			if(GameNameColor == 4) { drawG_Text("File Color: "); drawGUIText("Yellow");  }
			if(GameNameColor == 5) { drawG_Text("File Color: "); drawGUIText("Black");  }

			if(GameNameSelectedColor == 0) { drawG_Text("File Selection Color: "); drawGUIText("White");  }
			if(GameNameSelectedColor == 1) { drawG_Text("File Selection Color: "); drawGUIText("Red");  }
			if(GameNameSelectedColor == 2) { drawG_Text("File Selection Color: "); drawGUIText("Green");  }
			if(GameNameSelectedColor == 3) { drawG_Text("File Selection Color: "); drawGUIText("Blue");  }
			if(GameNameSelectedColor == 4) { drawG_Text("File Selection Color: "); drawGUIText("Yellow");  }
			if(GameNameSelectedColor == 5) { drawG_Text("File Selection Color: "); drawGUIText("Black");  }

			if(FullNameColor == 0) { drawG_Text("Full Name Color: "); drawGUIText("White");  }
			if(FullNameColor == 1) { drawG_Text("Full Name Color: "); drawGUIText("Red");  }
			if(FullNameColor == 2) { drawG_Text("Full Name Color: "); drawGUIText("Green");  }
			if(FullNameColor == 3) { drawG_Text("Full Name Color: "); drawGUIText("Blue");  }
			if(FullNameColor == 4) { drawG_Text("Full Name Color: "); drawGUIText("Yellow");  }
			if(FullNameColor == 5) { drawG_Text("Full Name Color: "); drawGUIText("Black");  }

			if(FolderColor == 0) { drawG_Text("Folder Color: "); drawGUIText("White");  }
			if(FolderColor == 1) { drawG_Text("Folder Color: "); drawGUIText("Red");  }
			if(FolderColor == 2) { drawG_Text("Folder Color: "); drawGUIText("Green");  }
			if(FolderColor == 3) { drawG_Text("Folder Color: "); drawGUIText("Blue");  }
			if(FolderColor == 4) { drawG_Text("Folder Color: "); drawGUIText("Yellow");  }
			if(FolderColor == 5) { drawG_Text("Folder Color: "); drawGUIText("Black");  }

			if(MenuOption == 0) { drawG_Text("Menu Color: "); drawGUIText("White");  }
			if(MenuOption == 1) { drawG_Text("Menu Color: "); drawGUIText("Red");  }
			if(MenuOption == 2) { drawG_Text("Menu Color: "); drawGUIText("Green");  }
			if(MenuOption == 3) { drawG_Text("Menu Color: "); drawGUIText("Blue");  }
			if(MenuOption == 4) { drawG_Text("Menu Color: "); drawGUIText("Yellow");  }
			if(MenuOption == 5) { drawG_Text("Menu Color: "); drawGUIText("Black");  }

			if(MenuOptionSelected == 0) { drawG_Text("Menu Selection Color: "); drawGUIText("White");  }
			if(MenuOptionSelected == 1) { drawG_Text("Menu Selection Color: "); drawGUIText("Red");  }
			if(MenuOptionSelected == 2) { drawG_Text("Menu Selection Color: "); drawGUIText("Green");  }
			if(MenuOptionSelected == 3) { drawG_Text("Menu Selection Color: "); drawGUIText("Blue");  }
			if(MenuOptionSelected == 4) { drawG_Text("Menu Selection Color: "); drawGUIText("Yellow");  }
			if(MenuOptionSelected == 5) { drawG_Text("Menu Selection Color: "); drawGUIText("Black");  }
			

			std::ostringstream q;
			q << FontSizeGUI;
			std::string w = q.str();
			drawG_Text("Font Size: "); drawGUIText((char*)w.c_str());

			std::ostringstream q2;
			q2 << vSpace;
			std::string w2 = q2.str();
			drawG_Text("Menu Vertical Spacing: "); drawGUIText((char*)w2.c_str());

			drawG_Text("Rombrowser Text Adjust "); drawGUIText("");
			drawG_Text("Full Name Text Adjust "); drawGUIText("");
			drawG_Text("Video Options Text Adjust "); drawGUIText("");
			drawG_Text("Sound Options Text Adjust "); drawGUIText("");
			drawG_Text("General Options Text Adjust "); drawGUIText("");
			drawG_Text("Main Menu Text Adjust "); drawGUIText("");
			drawG_Text("Text Options: Page 2"); drawGUIText("");
		}
		else {
			//if(showNes6502 == 1) { drawG_Text("by nes6502: "); drawGUIText("On");  }
			//if(showNes6502 == 0) { drawG_Text("by nes6502: "); drawGUIText("Off");  }

			if(showTransparency == 1) { drawG_Text("Screenshot Transparency: "); drawGUIText("On");  }
			if(showTransparency == 0) { drawG_Text("Screenshot Transparency: "); drawGUIText("Off");  }

			drawG_Text("Screenshot Preview Adjust "); drawGUIText("");
			///drawG_Text("Japanese Screenshot Preview Adjust "); drawGUIText("");
			//drawG_Text("USA Box Art Adjust "); drawGUIText("");
			drawG_Text("Japanese Box Art Adjust "); drawGUIText("");
			
			drawG_Text("Preview Border Adjust "); drawGUIText("");
			drawG_Text("SaveState + Exit Game Preview Adjust "); drawGUIText("");
			drawG_Text("Main Menu Animated Logo Adjust "); drawGUIText("");
			drawG_Text("Moving Character Animation Adjust "); drawGUIText("");

			std::ostringstream q3;
			q3 << animationFPS;
			std::string w3 = q3.str();
			drawG_Text("Moving Character FPS: "); drawGUIText((char*)w3.c_str());

			std::ostringstream q23;
			q23 << animationSpeed;
			std::string w23 = q23.str();
			drawG_Text("Moving Character Speed:"); drawGUIText((char*)w23.c_str());

			drawG_Text("GUI Background Adjust "); drawGUIText("");

			std::ostringstream q31;
			q31 << transparency;
			std::string w31 = q31.str();
			drawG_Text("Preview Transparency: "); drawGUIText((char*)w31.c_str());

			if(showBorder == 1) { drawG_Text("Game Preview Border: "); drawGUIText("On");  }
			if(showBorder == 0) { drawG_Text("Game Preview Border: "); drawGUIText("Off");  }

			std::ostringstream q23t;
			q23t << fadeSpeed;
			std::string w23t = q23t.str();
			drawG_Text("GUI Transition Speed:"); drawGUIText((char*)w23t.c_str());

			drawG_Text("Rombrowser Animated Logo Adjust "); drawGUIText("");
			drawG_Text("Image Options: Page 2 "); drawGUIText("");
		}
}