#include "tycho.h"

extern "C" {
	struct int2 {
		std::int16_t x, y;
	};

	void paint_arc(QPainter *paint,
	               std::int16_t x,
	               std::int16_t y,
	               std::int16_t w,
	               std::int16_t h,
	               std::int16_t t,
	               std::int16_t p)
	{
		paint->drawArc(x, y, w, h, t, p);
	}

	void paint_chord(QPainter *paint,
	                 std::int16_t x,
	                 std::int16_t y,
	                 std::int16_t w,
	                 std::int16_t h,
	                 std::int16_t t,
	                 std::int16_t p)
	{
		paint->drawChord(x, y, w, h, t, p);
	}

	void paint_ellipse(QPainter *paint,
	                   std::int16_t x,
	                   std::int16_t y,
	                   std::int16_t w,
	                   std::int16_t h)
	{
		paint->drawEllipse(x, y, w, h);
	}

	void paint_image(QPainter *paint,
	                 std::int16_t x,
	                 std::int16_t y,
	                 char const *fname)
	{
		paint->drawImage(x, y, QImage(QString(fname)));
	}

	void paint_line(QPainter *paint,
	                std::int16_t x1,
	                std::int16_t y1,
	                std::int16_t x2,
	                std::int16_t y2)
	{
		paint->drawLine(x1, y1, x2, y2);
	}

	void paint_point(QPainter *paint, std::int16_t x, std::int16_t y)
	{
		paint->drawPoint(x, y);
	}

	void paint_polygon(QPainter *paint, int2 const *points, std::size_t len)
	{
		QPolygon poly;

		for(auto i = 0; i < len; i++) {
			poly << QPoint(points[i].x, points[i].y);
		}

		paint->drawPolygon(poly);
	}

	void paint_rect(QPainter *paint,
	                std::int16_t x,
	                std::int16_t y,
	                std::int16_t w,
	                std::int16_t h)
	{
		paint->drawRect(x, y, w, h);
	}

	void paint_squircle(QPainter *paint,
	                    std::int16_t x,
	                    std::int16_t y,
	                    std::int16_t w,
	                    std::int16_t h,
	                    std::int16_t r1,
	                    std::int16_t r2)
	{
		paint->drawRoundedRect(x, y, w, h, r1, r2);
	}

	void paint_text(QPainter *paint,
	                std::int16_t x,
	                std::int16_t y,
	                char const *text)
	{
		paint->drawText(x, y, QString(text));
	}

	void paint_fg(QPainter *paint,
	              std::uint8_t r,
	              std::uint8_t g,
	              std::uint8_t b,
	              std::uint8_t a)
	{
		QColor color{r, g, b, a};
		paint->setPen(color);
	}
}

// EOF
