#ifndef INTERFACE_H_
#define INTERFACE_H_

#include "framework.h"
#include <CommCtrl.h>
#include <Commdlg.h>
#include <ShlObj_core.h>
#include "resource.h"
#include <Unknwn.h>   
#include <gdiplus.h>
#include "Device.h"
#include "Logging.h"


#define NUMBER_OF_TRACKER_TO_DISPLAY								  8
#define PATH_TO_BITMAP_TRACKER									TEXT("Images\\faceReco.bmp")
#define FOLDER_FOR_DOCUMENTS									TEXT("\\AFS Data")
#define FOLDER_FOR_LOGGER										TEXT("\\Logger")


#define MAINWIN_RECTANGLE_INTERFACE_RIGHT							 -3
#define MAINWIN_RECTANGLE_INTERFACE_BOTTTOM							 88
#define MAINWIN_RECTANGLE_INTERFACE_LEFT							  1
#define MAINWIN_RECTANGLE_INTERFACE_TOP								  1
#define MAINWIN_RECTANGLE_INTERFACE_RIGHT_USER						 -3
#define MAINWIN_RECTANGLE_INTERFACE_BOTTTOM_USER					800
#define MAINWIN_RECTANGLE_INTERFACE_LEFT_USER						  1
#define MAINWIN_RECTANGLE_INTERFACE_TOP_USER						 89
#define EDIT_CALIBRATION_NAME									 L"0.0"
#define EDIT_CALIBRATION_LEFT										332
#define EDIT_CALIBRATION_TOP										  6
#define EDIT_CALIBRATION_WIDTH										 58
#define EDIT_CALIBRATION_HEIGHT										 20
#define EDIT_TEMPERATURETEXTMEASURE_LEFT							395
#define EDIT_TEMPERATURETEXTMEASURE_TOP								  8
#define EDIT_TEMPERATURETEXTMEASURE_WIDTH							100
#define EDIT_TEMPERATURETEXTMEASURE_HEIGHT							 20
#define EDIT_TEMPERATURETEXTREGION_LEFT								600
#define EDIT_TEMPERATURETEXTREGION_TOP								  4
#define EDIT_TEMPERATURETEXTREGION_WIDTH							100
#define EDIT_TEMPERATURETEXTREGION_HEIGHT							 20
#define EDIT_TEMPERATURETEXTFACE_LEFT								810
#define EDIT_TEMPERATURETEXTFACE_TOP								  4
#define EDIT_TEMPERATURETEXTFACE_WIDTH								100
#define EDIT_TEMPERATURETEXTFACE_HEIGHT								 20
#define EDIT_TEMPERATUREREGIONTEXT_LEFT								600
#define EDIT_TEMPERATUREREGIONTEXT_TOP								 26
#define EDIT_TEMPERATUREREGIONTEXT_WIDTH							100
#define EDIT_TEMPERATUREREGIONTEXT_HEIGHT							 20
#define EDIT_FACETEXT_LEFT											810
#define EDIT_FACETEXT_TOP											 26
#define EDIT_FACETEXT_WIDTH											100
#define EDIT_FACETEXT_HEIGHT										 20
#define EDIT_TEMPERATUREREGION_NAME								 L"0.0"
#define EDIT_TEMPERATUREREGION_LEFT									600
#define EDIT_TEMPERATUREREGION_TOP									 52
#define EDIT_TEMPERATUREREGION_WIDTH								100
#define EDIT_TEMPERATUREREGION_HEIGHT								 20
#define EDIT_TEMPERATUREFACE_NAME								 L"0.0"
#define EDIT_TEMPERATUREFACE_LEFT									810
#define EDIT_TEMPERATUREFACE_TOP									 52
#define EDIT_TEMPERATUREFACE_WIDTH									100
#define EDIT_TEMPERATUREFACE_HEIGHT									 20
#define COMBO_PALLETE_LEFT											701
#define COMBO_PALLETE_TOP											  4
#define COMBO_PALLETE_WIDTH											120
#define COMBO_PALLETE_HEIGHT										250
#define BUTTON_START_NAME									   L"Start"
#define BUTTON_START_TOP											  4
#define BUTTON_START_LEFT											  4
#define BUTTON_START_WIDTH											 80
#define BUTTON_START_HEIGHT											 80
#define BUTTON_PAUSE_NAME									   L"Pause"
#define BUTTON_PAUSE_TOP											  4
#define BUTTON_PAUSE_LEFT											 86
#define BUTTON_PAUSE_WIDTH											 80
#define BUTTON_PAUSE_HEIGHT											 80
#define BUTTON_STOP_NAME										L"Stop"
#define BUTTON_STOP_TOP												  4
#define BUTTON_STOP_LEFT											168
#define BUTTON_STOP_WIDTH											 80
#define BUTTON_STOP_HEIGHT											 80
#define VIDEOCAPTURE_LEFT											  4
#define VIDEOCAPTURE_TOP									     TOPOUT
#define BUTTON_FACE_NAME										L"Face detection"
#define BUTTON_FACE_TOP												  4
#define BUTTON_FACE_LEFT											250
#define BUTTON_FACE_WIDTH											 80
#define BUTTON_FACE_HEIGHT											 80
#define BUTTON_CALI_BUTTON_NAME										L"Calibrate"
#define BUTTON_CALI_BUTTON_TOP										 26
#define BUTTON_CALI_BUTTON_LEFT										332
#define BUTTON_CALI_BUTTON_WIDTH									 58
#define BUTTON_CALI_BUTTON_HEIGHT									 58
#define BUTTON_ALARM_BUTTON_NAME								L"Alarm set"
#define BUTTON_ALARM_BUTTON_TOP										 26
#define BUTTON_ALARM_BUTTON_LEFT									520
#define BUTTON_ALARM_BUTTON_WIDTH									 58
#define BUTTON_ALARM_BUTTON_HEIGHT									 58
#define EDIT_ALARM_NAME											 L"0.0"
#define EDIT_ALARM_LEFT												520
#define EDIT_ALARM_TOP												  6
#define EDIT_ALARM_WIDTH											 58
#define EDIT_ALARM_HEIGHT											 20
#define EDIT_FACETRUE_LEFT											400
#define EDIT_FACETRUE_TOP											 32
#define EDIT_FACETRUE_WIDTH											 30
#define EDIT_FACETRUE_HEIGHT										 20
#define EDIT_FACEFALSE_LEFT											446
#define EDIT_FACEFALSE_TOP											 32
#define EDIT_FACEFALSE_WIDTH										 70
#define EDIT_FACEFALSE_HEIGHT										 20
#define EDIT_TRUE_NAME											 L"0.0"
#define EDIT_TRUE_LEFT												394
#define EDIT_TRUE_TOP												 54
#define EDIT_TRUE_WIDTH												 58
#define EDIT_TRUE_HEIGHT											 20
#define EDIT_FALSE_NAME											 L"0.0"
#define EDIT_FALSE_LEFT												450
#define EDIT_FALSE_TOP												 54
#define EDIT_FALSE_WIDTH											 58
#define EDIT_FALSE_HEIGHT											 20

#define EDIT_REGION_TRACKER_NAME								  L"0.0"
#define BUTTON_REGION_TRACKER_NAME								 L"Tracker"
#define REGION_FOR_TRACKERS_EDIT_LEFT								890
#define REGION_FOR_TRACKERS_EDIT_TOP								  4
#define REGION_FOR_TRACKERS_EDIT_WIDTH								 58
#define REGION_FOR_TRACKERS_EDIT_HEIGHT								 20
#define REGION_FOR_TRACKERS_LEFT									890
#define REGION_FOR_TRACKERS_TOP										 26
#define REGION_FOR_TRACKERS_WIDTH									 58
#define REGION_FOR_TRACKERS_HEIGHT									 58

/**
* @class Interface
* @brief Create interface for user with WINDOWS API
* @author Matej Roman (student of BUT)
*/
class Interface {

	// Color constants.
	const COLORREF rgbRed = 0x000000FF;
	const COLORREF rgbGreen = 0x0000FF00;
	const COLORREF rgbBlue = 0x00FF0000;
	const COLORREF rgbBlack = 0x00000000;
	const COLORREF rgbWhite = 0x00FFFFFF;

	struct Tracker
	{
		std::vector<std::vector<std::pair<std::pair<HWND, bool>, std::pair<float, bool>>>> tracker;
		std::vector<bool> wasUsed;
	};

public:

	Interface(HINSTANCE hInst) :
		_hInst(hInst),
		_hideNoVideo(false),
		_isErased(false),
		_colorForMouseTemp(rgbBlue),
		_hWndMain(NULL),
		_hEditCalibrate(NULL),
		_hEditRegion(NULL),
		_hEditFace(NULL),
		_NoVideoWindow(NULL)
	{}

	void DrawRectangle(HWND& hWnd, HDC& hdc, int index);

	void SetAbsolutePath(TCHAR* path) { _absolutePath = path; }

	void InitTrackersForDisplay(HWND hWnd);

	void HideAllTrackers();

	void ShowAllTrackers(bool fromMenu);

	void ShowTemperatureToEdit(int index);

	void HideTracker(int index);

	void ShowTracker(int index, bool fromMenu);

	void DrawTrackers(HWND hWnd, thermoCamera::Device* device);

	void CreateInterface(HWND hWnd, thermoCamera::Device* device);

	void AddCombos(HWND hWnd);

	void InitLogger();

	void CloseLogger() { _Logger.CloseLogger(); }

	void InitRecordConfig(HWND hWnd, thermoCamera::Device* device);

	void InitWindowConfig(HWND hWnd, thermoCamera::Device* device);

	void InitVideoConfig(HWND hWnd, thermoCamera::Device* device);

	void InitFaceSetting(HWND hWnd, thermoCamera::Device* device);

	void InitAlarmSetting(HWND hWnd, thermoCamera::Device* device);

	void InitTempConfig(HWND hWnd, thermoCamera::Device* device);

	void OpenAndSetRecordPathOutput(HWND hWnd, thermoCamera::Device* device);

	void OpenAndSetRecordPathInput(HWND hWnd, thermoCamera::Device* device);

	void OpenAndSetClassifierPath(HWND hWnd, thermoCamera::Device* device);

	void OpenAndSetAlarmPath(HWND hWnd, thermoCamera::Device* device);

	void AddButtons(HWND hWnd);

	void AddImages(HWND hWnd, HDC hdc);

	void SetNumberOfFaces(HWND hWnd, thermoCamera::Device* device);

	void SetTemperatureOfRegion(HWND hWnd, thermoCamera::Device* device);

	void SetAlarm(HWND hWnd, thermoCamera::Device* device);

	void SetCalibrateValue(HWND hWnd, thermoCamera::Device* device);

	INT_PTR DoRecordCongig(HWND hWnd);

	INT_PTR DoWindowConfig(HWND hWnd);

	INT_PTR DoSettingsConfig(HWND hWnd);

	void ShowNoVideo() { _hideNoVideo = false; }

	void HideNoVideo() { _hideNoVideo = true; }

	void ShowImage(HWND image) { if (image) ShowWindow(image, SW_SHOW); }

	void HideImage(HWND image) { if (image) ShowWindow(image, SW_HIDE); }

	COLORREF GetColorForMouseTemp() { return _colorForMouseTemp; }

	void SetColorForMouseTemp(COLORREF color) { _colorForMouseTemp = color; }

	void ValidateTrackers(int num, float alarmThreshold);

	void Delete();

private:

	#if UNICODE
		myLogging::Logger<std::wstring, std::wofstream>                  _Logger;
	#else
		myLogging::Logger<std::string, std::ofstream>                    _Logger;
	#endif

	TCHAR* _absolutePath;

	HINSTANCE _hInst;

	Tracker _trackersEdit;

	Gdiplus::Image* _image;

	ULONG_PTR _gdiplusToken;

	bool _hideNoVideo;

	bool _isErased;

	COLORREF _colorForMouseTemp;

	HWND _hWndMain;

	HWND _hEditCalibrate;

	HWND _hEditAlarm;

	HWND _hEditTrue;

	HWND _hEditFalse;

	HWND _hEditRegion;

	HWND _hEditFace;

	HWND _NoVideoWindow;

	UINT _GetIDOfFaces(int index);

	UINT _GetIDOfFacesClick(int index);
};

#endif
