/*
            __
           / /_______________  ____  ___
          / __/ ___/ ___/ __ \/ __ \/ _ \
         / /_(__  ) /__/ /_/ / /_/ /  __/
         \__/____/\___/\____/ .___/\___/
                           /_/
    
    drawing functions

    By Michael Stevens

    See license.html for copyright information
*/

#include "../include/tscope.h"
#include "../include/tscope/internal.h"

// draw a pixel
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);
}

// get the color value of a screen pixel
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);
}

// draw a circle
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);
}

// draw a line
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);
}

// draw a horizontal line
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);
}

// draw a vertical line
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);
}

// draw a rectangle
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);
}

// draw a triangle
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);
    }
}

// draw a polygon
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]);
    }
}

// draw an arc
void ts_arc(int x, int y, int ang1, int ang2, int r)
{
    if (!_graphics_flag)
        _graphics_init();
    ang1 = ang1 % 360;          // rescale angle to 0-360
    ang2 = ang2 % 360;
    ang1 = (ang1 * 256) / 360;  // convert to allegro angles
    ang2 = (ang2 * 256) / 360;
    if (_coordinates == CARTESIAN) {
        x = sx(x);
        y = sy(y);
    }
    arc(_destmap->b, x, y, ang1 << 16, ang2 << 16, r, _fgcolor);
}

// draw an ellipse
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);
}

// fill an enclosed area
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);
}


top
Persoonlijke pagina Universiteit GentTscope
Allegro | Cygwin | Gcc
© See license.html for copyright information