#include "../include/tscope.h"
#include "../include/tscope/internal.h"
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);
}
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;
map *oldmap;
oldmap = _destmap;
_destmap = _screenmap;
w = 12;
h = 8;
xmin = x - w / 2;
xmax = x + w / 2;
ymin = y - h / 2;
ymax = y + h / 2;
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);
ts_drawmouse();
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);
ts_hidemouse();
_destmap = oldmap;
}
int ts_drawmouse()
{
if (!_mousegui_flag)
_mousegui_init();
show_mouse(screen);
return 1;
}
int ts_hidemouse()
{
if (!_mousegui_flag)
_mousegui_init();
show_mouse(NULL);
return 1;
}
int ts_xmouse()
{
if (!_mousegui_flag)
_mousegui_init();
poll_mouse();
if (_coordinates == CARTESIAN)
return cx(mouse_x);
else
return mouse_x;
}
int ts_ymouse()
{
if (!_mousegui_flag)
_mousegui_init();
poll_mouse();
if (_coordinates == CARTESIAN)
return cy(mouse_y);
else
return mouse_y;
}
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);
}
int ts_mousecolor(int color)
{
if (!_graphics_flag)
_graphics_init();
int oldval = _mousecolor;
_mousecolor = color;
if (_mousegui_flag)
_mousegui_exit();
_mousegui_init();
return oldval;
}