#include "../include/tscope.h"
#include "../include/tscope/internal.h"
int ts_getpixel(int x, int y)
{
if (!_graphics_flag)
_graphics_init();
if (_coordinates == CARTESIAN)
return getpixel(_destmap->b, sx(x), sy(y));
else
return getpixel(_destmap->b, x, y);
}
void ts_putpixel(int x, int y)
{
if (!_graphics_flag)
_graphics_init();
if (_coordinates == CARTESIAN) {
x = sx(x);
y = sy(y);
}
putpixel(_destmap->b, x, y, _fgcolor);
}
void ts_circle(int x, int y, int radius)
{
if (!_graphics_flag)
_graphics_init();
if (_coordinates == CARTESIAN) {
x = sx(x);
y = sy(y);
}
if (_fill)
circlefill(_destmap->b, x, y, radius, _fgcolor);
else
circle(_destmap->b, x, y, radius, _fgcolor);
}
void ts_line(int x1, int y1, int x2, int y2)
{
if (!_graphics_flag)
_graphics_init();
if (_coordinates == CARTESIAN) {
x1 = sx(x1);
x2 = sx(x2);
y1 = sy(y1);
y2 = sy(y2);
}
line(_destmap->b, x1, y1, x2, y2, _fgcolor);
}
void ts_hline(int x1, int x2, int y)
{
if (!_graphics_flag)
_graphics_init();
if (_coordinates == CARTESIAN) {
x1 = sx(x1);
x2 = sx(x2);
y = sy(y);
}
hline(_destmap->b, x1, y, x2, _fgcolor);
}
void ts_vline(int x, int y1, int y2)
{
if (!_graphics_flag)
_graphics_init();
if (_coordinates == CARTESIAN) {
x = sx(x);
y1 = sy(y1);
y2 = sy(y2);
}
vline(_destmap->b, x, y1, y2, _fgcolor);
}
void ts_rect(int x1, int y1, int x2, int y2)
{
if (!_graphics_flag)
_graphics_init();
if (_coordinates == CARTESIAN) {
x1 = sx(x1);
x2 = sx(x2);
y1 = sy(y1);
y2 = sy(y2);
}
if (_fill)
rectfill(_destmap->b, x1, y1, x2, y2, _fgcolor);
else
rect(_destmap->b, x1, y1, x2, y2, _fgcolor);
}
void ts_triangle(int x1, int y1, int x2, int y2, int x3, int y3)
{
if (!_graphics_flag)
_graphics_init();
if (_fill) {
if (_coordinates == CARTESIAN) {
x1 = sx(x1);
x2 = sx(x2);
x3 = sx(x3);
y1 = sy(y1);
y2 = sy(y2);
y3 = sy(y3);
}
triangle(_destmap->b, x1, y1, x2, y2, x3, y3, _fgcolor);
} else {
ts_line(x1, y1, x2, y2);
ts_line(x2, y2, x3, y3);
ts_line(x3, y3, x1, y1);
}
}
void ts_polygon(int points, int *xy)
{
if (!_graphics_flag)
_graphics_init();
int i;
if (_fill) {
if (_coordinates == CARTESIAN)
for (i = 0; i < points * 2; i += 2) {
xy[i] = sx(xy[i]);
xy[i + 1] = sy(xy[i + 1]);
}
polygon(_destmap->b, points, xy, _fgcolor);
} else {
for (i = 0; i < (points * 2) - 2; i += 2)
ts_line(xy[i], xy[i + 1], xy[i + 2], xy[i + 3]);
ts_line(xy[(points * 2) - 2], xy[(points * 2) - 1], xy[0], xy[1]);
}
}
void ts_arc(int x, int y, int ang1, int ang2, int r)
{
if (!_graphics_flag)
_graphics_init();
ang1 = ang1 % 360;
ang2 = ang2 % 360;
ang1 = (ang1 * 256) / 360;
ang2 = (ang2 * 256) / 360;
if (_coordinates == CARTESIAN) {
x = sx(x);
y = sy(y);
}
arc(_destmap->b, x, y, ang1 << 16, ang2 << 16, r, _fgcolor);
}
void ts_ellipse(int x, int y, int rx, int ry)
{
if (!_graphics_flag)
_graphics_init();
if (_coordinates == CARTESIAN) {
x = sx(x);
y = sy(y);
}
if (_fill)
ellipsefill(_destmap->b, x, y, rx, ry, _fgcolor);
else
ellipse(_destmap->b, x, y, rx, ry, _fgcolor);
}
void ts_floodfill(int x, int y)
{
if (!_graphics_flag)
_graphics_init();
if (_coordinates == CARTESIAN) {
x = sx(x);
y = sy(y);
}
floodfill(_destmap->b, x, y, _fgcolor);
}