//Image.cpp
#include "Image.h"

void Image::update_position()
{
  sprite.setPosition(posX, posY);
}
void Image::update_alpha()
{
  if(alpha < 0)   alpha = 0;
  if(alpha > 255) alpha = 255;
  sprite.setColor(sf::Color(255,255,255,alpha));
}
void Image::update_rotation()
{
  if(angle_of_rotation <   0) angle_of_rotation +=360;
  if(angle_of_rotation > 360) angle_of_rotation -=360;
}

Image::Image()
{
  data();
}
Image::Image(sf::String filename, int width, int height)
{
  data();
  init(filename, width, height);
}
void Image::data()
{
  setXY(0, 0);
  setAlpha(255);
  setRotation(0);
  setScale(1);
}
void Image::init(sf::String filename, int width, int height)
{
  width_current = width_original = width;
  height_current = height_original = height;
  
  image.loadFromFile("images/" + filename);
  texture.loadFromImage(image);
  sprite.setTexture(texture);
	
  sprite.setTextureRect(sf::IntRect(0, 0, width, height)); // задаём српайту один прямоугольник для вывода
  sprite.setOrigin(width/2, height/2);
}
void Image::draw(sf::RenderWindow *window)
{
  window->draw(sprite); 
}

float Image::getX()
{
  return posX;
}
float Image::getY()
{
  return posY;
}
void Image::setX(float x)
{
  posX = x;
  update_position();
}
void Image::setY(float y)
{
  posY = y;
  update_position();
}
void Image::setXY(float x, float y)
{
  posX = x;
  posY = y;
  update_position();
}
void Image::setDX(float dx)
{
  posX += dx;
  update_position();
}
void Image::setDY(float dy)
{
  posY += dy;
  update_position();
}
void Image::setDXY(float dx, float dy)
{
  posX += dx;
  posY += dy;
  update_position();
}

void Image::setAlpha(float value_alpha)
{
  alpha = value_alpha;
  update_alpha();
}
void Image::setDAlpha(float value_alpha)
{
  alpha += value_alpha;
  update_alpha();
}
float Image::getAlpha()
{
  return alpha;
}

void Image::setRotation(float angle)
{
  angle_of_rotation = angle;
  sprite.setRotation(angle);
  update_rotation();
}
void Image::rotate(float angle)
{
  angle_of_rotation += angle;
  sprite.rotate(angle);
  update_rotation();
}
float Image::getRotation()
{
  return angle_of_rotation;
}

void Image::setScale(float value_scale)
{
  if(value_scale < 0) 
	value_scale = 0;
  scale = value_scale;
  scaleX = scale;
  scaleY = scale;
  sprite.setScale(scaleX, scaleY);
  width_current = width_original * scale;
  height_current = height_original * scale;
}
void Image::setScale(float x, float y)
{
  scale = 0;
  scaleX = x;
  scaleY = y;
  sprite.setScale(scaleX, scaleY);
  width_current = width_original * scaleX;
  height_current = height_original * scaleY;
}
float Image::getScale()
{
  if(scaleX == scaleY)
    return scale;
  else
	return 0;
}
float Image::getScaleX()
{
  return scaleX;
}
float Image::getScaleY()
{
  return scaleY;
}

float Image::getWidthOriginal()
{
  return width_original;
}
float Image::getHeightOriginal()
{
  return height_original;
}
float Image::getWidthCurrent()
{
  return width_current;
}
float Image::getHeightCurrent()
{
  return height_current;
}

sf::Sprite Image::getSprite()
{
  return sprite;
}
//