// G. Hagopian
// https://opentextbc.ca/physicstestbook2/chapter/elastic-collisions-in-one-dimension/
// https://opengameart.org/content/8-ball-pool-assets
#include <iostream>
#include<vector>
#include <SFML/Graphics/Image.hpp>
//#include <SFML/Graphics/ImageLoader.hpp>
#include <SFML/Graphics.hpp>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>;

class EllipseShape : public sf::Shape {
public:
	explicit EllipseShape(const sf::Vector2f& radius = sf::Vector2f(0, 0)) :
		m_radius(radius) {
		update();
	}

	void setRadius(const sf::Vector2f& radius) 	{
		m_radius = radius;
		update();
	}

	const sf::Vector2f& getRadius() const {
		return m_radius;
	}

	virtual unsigned int getPointCount() const 	{
		return 30; // fixed, but could be an attribute of the class if needed
	}

	virtual sf::Vector2f getPoint(unsigned int index) const {
		static const float pi = 3.141592654f;

		float angle = index * 2 * pi / getPointCount() - pi / 2;
		float x = std::cos(angle) * m_radius.x;
		float y = std::sin(angle) * m_radius.y;

		return sf::Vector2f(m_radius.x + x, m_radius.y + y);
	}

private:
	sf::Vector2f m_radius;
};

sf::Vector2i dims(1200, 800);

int main() {
	srand(unsigned(time(0)));

	sf::RenderWindow window(sf::VideoMode(dims.x, dims.y), "Billiards!");
	window.setFramerateLimit(240);

	//Outline

		/*Shapes can have an outline.You can set the thickness
		and color of the outline with the setOutlineThickness
		and setOutlineColor functions.
		*/
	sf::CircleShape shape(50);
	shape.setFillColor(sf::Color(150, 50, 250,0));

	// set a 10-pixel wide orange outline
	shape.setOutlineThickness(10);
	shape.setOutlineColor(sf::Color(250, 150, 100));
	/*
	 By default, the outline is extruded outwards from the shape (e.g. if you have a 
	 circle with a radius of 10 and an outline thickness of 5, the total radius of 
	 the circle will be 15). You can make it extrude towards the center of the shape 
	 instead, by setting a negative thickness.

	To disable the outline, set its thickness to 0. If you only want the outline, you 
	can set the fill color to sf::Color::Transparent. 
	
	Texture

	Shapes can also be textured, just like sprites. To specify a part of the texture 
	to be mapped to the shape, you must use the setTextureRect function. It takes the 
	texture rectangle to map to the bounding rectangle of the shape. This method doesn't 
	offer maximum flexibility, but it is much easier to use than individually setting 
	the texture coordinates of each point of the shape.
	*/
	sf::CircleShape shape2(50);

	sf::Texture texture;
	texture.loadFromFile("assets//table.png");
	// map a 100x100 textured rectangle to the shape
	shape2.setTexture(&texture); // texture is a sf::Texture
	shape2.setTextureRect(sf::IntRect(10, 10, 100, 100));
	shape2.setPosition(100, 100);
	
	EllipseShape ellipse(sf::Vector2f(300, 150));
	ellipse.setFillColor(sf::Color::Blue);
	ellipse.setOrigin(300, 150);
	ellipse.setPosition(100, 30);
	while (window.isOpen())
	{
		sf::Event event;

		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				window.close();
		}
		window.clear();
		//draw

		//window.draw(billiardsTable);
		window.draw(shape);
		window.draw(shape2);
		window.draw(ellipse);
		ellipse.rotate(1);
		window.display();
	}

	return 0;
}