package com.HawkEngine.Core;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.lang.annotation.Annotation;

public class Renderer
{
	public static synchronized void RenderSquare(Graphics g, Vector2 position, Vector2 size, Color c)
	{
		g.setColor(c);
		g.fillRect((int)position.x, (int)position.y, (int)size.x, (int)size.y);
	}
	public static synchronized void RenderSquareRotated(Graphics g, Vector2 position, Vector2 size, float degrees, Color c)
	{
		Graphics2D g2d = (Graphics2D)g;
		AffineTransform old = g2d.getTransform();
		g2d.rotate(Math.toRadians(degrees), position.x + (size.x/2), position.y + (size.y/2));
		g2d.setColor(c);
		g2d.fillRect((int)position.x, (int)position.y, (int)size.x, (int)size.y);
		g2d.setTransform(old);
	}
	public static void RenderEllipse(Graphics g, Vector2 position, Vector2 size, int angle, Color c)
	{
		g.setColor(c);
		g.fillArc((int)position.x, (int)position.y, (int)size.x, (int)size.y, 0, angle);
	}
	public static synchronized void RenderEllipseRotated(Graphics g, Vector2 position, Vector2 size, float degrees, float rotation, Color c)
	{
		Graphics2D g2d = (Graphics2D)g;
		AffineTransform old = g2d.getTransform();
		g2d.rotate(rotation, position.x + (size.x/2), position.y + (size.y/2));
		g2d.setColor(c);
		g2d.fillArc((int)position.x, (int)position.y, (int)size.x, (int)size.y, 0, (int)degrees);
		g2d.setTransform(old);
	}
	public static synchronized void RenderSprite(Graphics g, Sprite sprite)
	{
		Texture t = sprite.GetTexture();
		if(t == null)
		{
			System.err.println("Texture not found!");
			return;
		}
		Graphics2D graphics = (Graphics2D)g;

		Vector2 position = sprite.GetPosition();
		Vector2 size = sprite.GetSize();

		graphics.drawImage(t.GetImage(), (int)position.x, (int)position.y, (int)size.x, (int)size.y, null);
	}
	public static synchronized void RenderSpriteRotated(Graphics g, Sprite sprite, float rotationDegrees)
	{
		Texture t = sprite.GetTexture();
		if(t == null)
		{
			System.err.println("Texture not found!");
			return;
		}
		Graphics2D graphics = (Graphics2D)g;

		Vector2 position = sprite.GetPosition();
		Vector2 size = sprite.GetSize();

		AffineTransform old = graphics.getTransform();

		System.out.println(Math.toDegrees(rotationDegrees));

		graphics.rotate(Math.toRadians(rotationDegrees), position.x + (size.x/2), position.y + (size.y / 2));

		graphics.drawImage(t.GetImage(), (int)position.x, (int)position.y, (int)size.x, (int)size.y, null);

		graphics.setTransform(old);
	}
	public static synchronized void RenderTexture(Graphics g, Texture texture, int x, int y, int w, int h)
	{
		Graphics2D graphics = (Graphics2D)g;
		graphics.drawImage(texture.GetImage(), x, y, w, h, null);
	}
}