#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Menu_Button.H>
#include <FL/Fl_Menu_Item.H>
#include <FL/Fl_Output.H>
#include <FL/Fl_Double_Window.H>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

//global constants
#define	ID_NOTHING	0
#define ID_SMALL	1
#define ID_LARGEVERT	2
#define ID_LARGEHORZ	3
#define ID_LARGE	4

//global variables
bool blocksInit = false, largeBlockInit = false;
int numBlocks = 0, currLevel = -1, totalMovesCount = 0, numDestinationBlocks = 0;
short selectedBlockType = 0;
Fl_Button *selectedBlock;
FILE *settings;
const char settingsName[] = "/home/default/.flotski";

//widgets for the gui
Fl_Double_Window *mainWindow, *aboutWindow, *youWinWindow, *bestWindow;
Fl_Button *doneButton, *resetButton, *aboutButton, **destinationButton,
	**blockButton, *largeBlockButton, *aboutDoneButton, *youWinDoneButton,	
	*bestDoneButton, *showBestScoresButton, *bestResetButton;
Fl_Output *totalMovesOutput;
Fl_Box *totalMovesLbl, **borderDecoration, **aboutWindowLbl, *youWinLbl, **bestLbl,
	*currLevelLbl;
Fl_Menu_Button *levelButton;

//prototype functions
void SetupGUI();

void doneButtonPressed(Fl_Widget *w, void *data);
void resetButtonPressed(Fl_Widget *w, void *data);
void aboutButtonPressed(Fl_Widget *w, void *data);
void showBestScoresButtonPressed(Fl_Widget *w, void *data);

//void MoveUp();
//void MoveRight();
//void MoveLeft();
//void MoveDown();

void BlockButtonPressed(Fl_Widget *w, void *data);
void DisplayDestinationBlocks();
void DisplayDestinationBlockAt(int x, int y, int w, int h, char label);
void DestinationButtonPressed(Fl_Widget *w, void *data);

void choseLevel0(Fl_Widget *w, void *data);
void choseLevel1(Fl_Widget *w, void *data);
void choseLevel2(Fl_Widget *w, void *data);
void choseLevel3(Fl_Widget *w, void *data);
void choseLevel4(Fl_Widget *w, void *data);
void choseLevel5(Fl_Widget *w, void *data);
void choseLevel6(Fl_Widget *w, void *data);

bool OkToMoveLeft(int x, int y, int w, int h);
bool OkToMoveRight(int x, int y, int w, int h);
bool OkToMoveUp(int x, int y, int w, int h);
bool OkToMoveDown(int x, int y, int w, int h);

void aboutDoneButtonPressed(Fl_Widget *w, void *data);
void youWinDoneButtonPressed(Fl_Widget *w, void *data);
void bestDoneButtonPressed(Fl_Widget *w, void *data);
void bestResetButtonPressed(Fl_Widget *w, void *data);

void ClearBoard();
void ResetTotalMoves();
void CreateNewSettings();
void GetSavedSettings();
void SaveSettings();

//menu definition
Fl_Menu_Item levelMenu[] = {
	{ "Level 0", 0, choseLevel0, 0 },
	{ "Level 1", 0, choseLevel1, 0 },
	{ "Level 2", 0, choseLevel2, 0 },
	{ "Level 3", 0, choseLevel3, 0 },
	{ "Level 4", 0, choseLevel4, 0 },
	{ "Level 5", 0, choseLevel5, 0 },
	{ "Level 6", 0, choseLevel6, 0 },
	{ 0 }
};
