/*
            __
           / /_______________  ____  ___
          / __/ ___/ ___/ __ \/ __ \/ _ \
         / /_(__  ) /__/ /_/ / /_/ /  __/
         \__/____/\___/\____/ .___/\___/
                           /_/
    
    mouse interface

    By Michael Stevens

    See license.html for copyright information
*/

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


// draw a textbox
void ts_textbox(int x1, int y1, int x2, int y2)
{
    if (!_graphics_flag)
        _graphics_init();
    int tmpfill = ts_fill(FALSE);
    ts_rect(x1 - 4, y1 - 7, x2 + 4, y2 + 7);
    ts_rect(x1 - 7, y1 - 4, x2 + 7, y2 + 4);
    ts_fill(tmpfill);
}

// put a next-button on the screen & wait 
void ts_button(int x, int y)
{
    if (!_mousegui_flag)
        _mousegui_init();
    int w, h, ok = 0;
    int xmin, xmax, ymin, ymax;
    int tmpcolor, tmpfill;

    // always write to the screen
    map *oldmap;
    oldmap = _destmap;
    _destmap = _screenmap;

    // some coordinates of the button
    w = 12;
    h = 8;
    xmin = x - w / 2;
    xmax = x + w / 2;
    ymin = y - h / 2;
    ymax = y + h / 2;

    // draw the button
    if (_coordinates == STANDARD) {
        if (x < 0 || x > SXMAX || y < 0 || y > SYMAX)
            ts_fatal
                ("ts_button: bad coordinates, button will be off screen.");
    } else {
        if (x < -XMAX || x > XMAX || y < -YMAX || y > YMAX)
            ts_fatal
                ("ts_button: bad coordinates, button will be off screen.");
    }

    ts_textbox(xmin - 1, ymin - 1, xmax + 1, ymax + 1);
    tmpcolor = ts_fgcolor(_mousecolor);
    tmpfill = ts_fill(TRUE);

    ts_triangle(xmax, (ymin + ymax) / 2, xmin, ymin, xmin, ymax);
    ts_fgcolor(tmpcolor);
    ts_fill(tmpfill);

    // show the mouse pointer
    ts_drawmouse();

    // wait for a click
    do {
        _rtc_nap();
        poll_mouse();
        if (mouse_b & 1)
            if (ts_xmouse() > xmin - 5 && ts_xmouse() < xmax + 5)
                if (ts_ymouse() > ymin - 5 && ts_ymouse() < ymax + 5)
                    ok = 1;
    } while (!ok);
    do {
        _rtc_nap();
        poll_mouse();
    }
    while (mouse_b & 1);

    // hide the mouse button
    ts_hidemouse();
    _destmap = oldmap;
}

// put the mouse cursor on the screen
int ts_drawmouse()
{
    if (!_mousegui_flag)
        _mousegui_init();
    show_mouse(screen);
    return 1;
}

// hide the mouse cursor
int ts_hidemouse()
{
    if (!_mousegui_flag)
        _mousegui_init();
    show_mouse(NULL);
    return 1;
}

// get the horizontal position of the mouse cursor
int ts_xmouse()
{
    if (!_mousegui_flag)
        _mousegui_init();

    poll_mouse();
    if (_coordinates == CARTESIAN)
        return cx(mouse_x);
    else
        return mouse_x;
}

// get the vertical position of the mouse cursor
int ts_ymouse()
{
    if (!_mousegui_flag)
        _mousegui_init();

    poll_mouse();
    if (_coordinates == CARTESIAN)
        return cy(mouse_y);
    else
        return mouse_y;
}

// move the mouse to a specific position
void ts_mousepos(int x, int y)
{
    if (!_mousegui_flag)
        _mousegui_init();

    if (_coordinates == CARTESIAN) {
        _mousex = sx(x);
        _mousey = sy(y);
    } else {
        _mousex = x;
        _mousey = y;
    }
    position_mouse(_mousex, _mousey);

}

// change the mouse color
int ts_mousecolor(int color)
{
    if (!_graphics_flag)
        _graphics_init();

    int oldval = _mousecolor;
    _mousecolor = color;

    if (_mousegui_flag)
        _mousegui_exit();
    _mousegui_init();

    return oldval;
}


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