#ifndef DRAWRECT_H_
#define DRAWRECT_H_

#include <Windows.h>

namespace drw {

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


	/**
	* @class DrawRectangle
	* @brief Draw rectangle on the screen Windows API
	* @author Matej Roman (student of BUT)
	*/
	class DrawRectangle {

	public:

		DrawRectangle() :
			hWnd(NULL),
			_active(false),
			_painting(false),
			_isDrawn(false),
			_rangeLeft{ 0,0 },
			_rangeRight{ 0,0 },
			_color(rgbGreen),
			_width(4),
			_left{ 0,0 },
			_right{ 0,0 },
			_validateRect{0,0,0,0}
		{}

		DrawRectangle(HWND hWnd, BOOL active, POINT rangeLeft, POINT rangeRight, COLORREF color, INT16 width) :
			hWnd(hWnd),
			_active(active),
			_painting(false),
			_isDrawn(false),
			_rangeLeft(rangeLeft),
			_rangeRight(rangeRight),
			_color(color),
			_width(width),
			_left{ 0,0 },
			_right{ 0,0 },
			_validateRect{ 0,0,0,0 }
		{}

		BOOL Draw(HDC hdc);

		void UpdateRectangle();

		void ValidateRect();

		// Setters and getters
		

		void setActive() { _active = true; }
		void clearActive() { _active = false; }
		BOOL isActive() { return _active; }

		void clearRect();

		BOOL setRange(POINT rangeLeft, POINT rangeRight);
		void getRange(POINT& rangeLeft, POINT& rangeRight);

		void setColor(COLORREF color) { _color = color; }
		COLORREF getColor() { return _color; }

		BOOL setWidth(INT16 width);
		INT16 getWidth() { return _width; }

		RECT getRectangleOfRegion() { RECT rc = { _left.x, _left.y, _right.x, _right.y }; return rc; }

		void enablePainting();
		void disablePainting();

		void setLeft(POINT left) { _left = left; }
		void setRight(POINT right) { _right = right; }

		BOOL isPainting() { return _painting; }
		BOOL isDrawn() { return _isDrawn; }

		HWND hWnd;

	private:

		BOOL _active;
		BOOL _painting;
		BOOL _isDrawn;

		POINT _rangeLeft;
		POINT _rangeRight;
		COLORREF _color;
		INT16 _width;

		POINT _left;
		POINT _right;

		RECT _validateRect;

		BOOL _isSet(POINT& left, POINT& right);
		BOOL _createValidateRect();
	};

}

#endif