//Mouse.cpp
#include "Mouse.h"

// Created by Kildushov Oleg
// Создатель - Кильдюшов Олег
// vk.com/legozaur
// kychka-pc.ru - nikname: legozaur 

Mouse::Mouse()
{
	data();
}
Mouse::~Mouse()
{
}
void Mouse::data()
{
	posX = 0;
	posY = 0;

	isKeyPressed_Left = false;
	isKeyPressed_Right = false;
	isKeyPressed_Middle = false;
}

bool Mouse::setWindow(sf::RenderWindow *RenderWindow)
{
	try
	{
	  window = RenderWindow;
	}
	catch(...)
	{
		cout << "Error Mouse::setWindow";
		return false;
	}
	return true;
}

void Mouse::behavior()
{
	sf::Vector2i pixelPos = sf::Mouse::getPosition(*window);
	sf::Vector2f pos = (*window).mapPixelToCoords(pixelPos);
	posX = pos.x;
	posY = pos.y;
}

int Mouse::getX()
{
	return posX;
}
int Mouse::getY()
{
	return posY;
}

int Mouse::getEventButtonLeft()
{
	bool isPressed = sf::Mouse::isButtonPressed(sf::Mouse::Left);
	if(isKeyPressed_Left != isPressed)
	{
		if(isKeyPressed_Left == true)
		{//ЛКМ была нажата, теперь не нажата
			isKeyPressed_Left = false;
			return 3;
		}
		else
		{//ЛКМ была не нажата, теперь нажата
			isKeyPressed_Left = true;
			return 1;
		}
	}
	else
	{
		if(isKeyPressed_Left == true)
			return 2;
		else
		  return 0;
	}
}
int Mouse::getEventButtonRight()
{
	bool isPressed = sf::Mouse::isButtonPressed(sf::Mouse::Right);
	
	if(isKeyPressed_Right != isPressed)
	{
		if(isKeyPressed_Right == true)
		{//ПКМ была нажата, теперь не нажата
			isKeyPressed_Right = false;
			return 3;
		}
		else
		{//ПКМ была не нажата, теперь нажата
			isKeyPressed_Right = true;
			return 1;
		}
	}
	else
	{
		if(isKeyPressed_Right == true)
			return 2;
		else
		  return 0;
	}
}
int Mouse::getEventButtonMiddle()
{
	bool isPressed = sf::Mouse::isButtonPressed(sf::Mouse::Middle);
	
	if(isKeyPressed_Middle != isPressed)
	{
		if(isKeyPressed_Middle == true)
		{//колесо было нажато, теперь не нажато
			isKeyPressed_Middle = false;
			return 3;
		}
		else
		{//колесо было не нажато, теперь нажато
			isKeyPressed_Middle = true;
			return 1;
		}
	}
	else
	{
		if(isKeyPressed_Middle == true)
			return 2;
		else
		  return 0;
	}
}
//