View Raw SPL
#include
static in_vclip, cursor, tagstr, ltarg;
extern _vclip_w, _vclip_t, _vclip_c;
/* visually clip a series with mouse cursor */
vclip(w, type, color)
{
(w, type, color) = vclip_parse_args(w, type, color);
/* set to pen cursor */
cursor = getconf("line_cursor");
if (type == 0)
{
/* rectangle - use crosshair cursor */
setconf("line_cursor", "-14");
}
else
{
/* line - use pen cursor */
setconf("line_cursor", "-17");
}
/* tag string */
tagstr = getconf("line_tag");
setconf("line_tag", "clipline");
/* line target */
ltarg = getconf("line_target");
setconf("line_target", "0");
/* draw clip shapes */
vclip_loop(w, type, color);
/* restore cursor */
setconf("line_cursor", cursor);
cursor = "";
/* restore tag */
setconf("line_tag", tagstr);
tagstr = "";
/* restore target */
setconf("line_target", ltarg);
ltarg = "";
}
vclip_loop(w, type, color)
{
local h;
w = castwindow(w);
in_vclip = 0;
if (length(w) > 0)
{
in_vclip = 1;
/* source window */
moveto(w);
if (type == 0)
{
h = rectcur(color)
}
else
{
/* line cursor */
h = linecur(color);
}
/* set tag so we can track the line */
if (ishandle(h))
{
h.showtag = 0;
h.tag = "clipline";
/* renter clip loop */
_vclip_w = castwindow(w);
_vclip_t = type;
_vclip_c = color;
pushkey(strescape("vclip(_vclip_w, _vclip_t, _vclip_c)\r"));
}
}
in_vclip = 0;
}
/* reset cursor on error */
vclip_error(errnum, errmes)
{
if (strlen(cursor) > 0)
{
setconf("line_cursor", cursor);
cursor = "";
}
if (strlen(tagstr) > 0)
{
setconf("line_tag", tagstr);
line_tag = "";
}
if (strlen(ltarg) > 0)
{
setconf("line_target", ltarg);
ltarg = "";
}
in_vclip = 0;
error(errmes);
}
/* visual edit in progress */
is_vclip()
{
return(in_vclip);
}
vclip_parse_args(w, type, color)
{
local winstr;
if (argc < 3)
{
if (argc < 2)
{
if (argc < 1)
{
w = castwindow(0);
type = 0;
color = lred;
}
else
{
if (isscalar(w))
{
type = w;
w = castwindow(0);
color = lred;
}
else
{
type = 0;
color = lred;
}
}
}
else
{
if (isscalar(w))
{
color = type;
type = w;
w = castwindow(0);
}
else
{
color = lred;
}
}
}
if (not(iswindow(w))) error("vclip - invalid series argument");
if (not(isscalar(type))) error("vclip - invalid type argument");
if (not(isscalar(color))) error("vclip - invalid color argument");
winstr = strwin(w);
return(winstr, type, color);
}
vclip_clear()
{
local h;
/* get line handles placed for cliping */
h = findhandle(w0, "tag", "clipline");
if (length(h) > 0)
{
deletehandle(h);
}
}