Commit 30d73c06 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

port envgen text display, change tabs to spaces, remove trailing spaces, and reformat brackets

parent d62cb1f5
......@@ -44,7 +44,7 @@ static void draw_inlets(t_envgen *x, t_glist *glist, int firsttime, int nin, int
0,
0);
}
else
else
{
//sys_vgui(".x%x.c coords %xo%d %d %d %d %d\n",
// glist_getcanvas(glist), x, i,
......@@ -89,85 +89,87 @@ static void draw_inlets(t_envgen *x, t_glist *glist, int firsttime, int nin, int
}
}
static int envgen_next_doodle(t_envgen *x, struct _glist *glist,
int xpos,int ypos)
{
int ret = -1;
float xscale,yscale;
int dxpos,dypos;
float minval = 100000.0;
float tval;
int i;
int insertpos = -1;
if (xpos > text_xpix(&x->x_obj,glist) + x->w.width)
xpos = text_xpix(&x->x_obj,glist) + x->w.width;
xscale = x->w.width/x->duration[x->last_state];
yscale = x->w.height;
dxpos = text_xpix(&x->x_obj,glist);/* + BORDER */;
dypos = text_ypix(&x->x_obj,glist) + BORDER;
for (i=0;i<=x->last_state;i++) {
float dx2 = (dxpos + (x->duration[i] * xscale)) - xpos;
float dy2 = (dypos + yscale - (x->finalvalues[i] * yscale)) - ypos;
dx2*=dx2;
dy2*=dy2;
tval = sqrt(dx2+dy2);
if (tval <= minval) {
minval = tval;
insertpos = i;
}
}
/* decide if we want to make a new one */
if (minval > /*5*/ 8 && insertpos >= 0 && !x->x_freeze) {
while (((dxpos + (x->duration[insertpos] * xscale)) - xpos) < 0)
insertpos++;
while (((dxpos + (x->duration[insertpos-1] * xscale)) - xpos) > 0)
insertpos--;
if (x->last_state+1 >= x->args)
envgen_resize(x,x->args+1);
for (i=x->last_state;i>=insertpos;i--) {
x->duration[i+1] = x->duration[i];
x->finalvalues[i+1] = x->finalvalues[i];
}
x->duration[insertpos] = (float)(xpos-dxpos)/x->w.width*x->duration[x->last_state++];
x->w.pointerx = xpos;
x->w.pointery = ypos;
}
else {
x->w.pointerx = text_xpix(&x->x_obj,glist) + x->duration[insertpos]*x->w.width/x->duration[x->last_state];
x->w.pointery = text_ypix(&x->x_obj,glist) +
(1.f - x->finalvalues[insertpos])*x->w.height;
}
x->w.grabbed = insertpos;
return insertpos;
int ret = -1;
float xscale,yscale;
int dxpos,dypos;
float minval = 100000.0;
float tval;
int i;
int insertpos = -1;
if (xpos > text_xpix(&x->x_obj,glist) + x->w.width)
xpos = text_xpix(&x->x_obj,glist) + x->w.width;
xscale = x->w.width/x->duration[x->last_state];
yscale = x->w.height;
dxpos = text_xpix(&x->x_obj,glist);/* + BORDER */;
dypos = text_ypix(&x->x_obj,glist) + BORDER;
for (i = 0; i <= x->last_state; i++)
{
float dx2 = (dxpos + (x->duration[i] * xscale)) - xpos;
float dy2 = (dypos + yscale - (x->finalvalues[i] * yscale)) - ypos;
dx2*=dx2;
dy2*=dy2;
tval = sqrt(dx2+dy2);
if (tval <= minval)
{
minval = tval;
insertpos = i;
}
}
/* decide if we want to make a new one */
if (minval > /*5*/ 8 && insertpos >= 0 && !x->x_freeze)
{
while (((dxpos + (x->duration[insertpos] * xscale)) - xpos) < 0)
insertpos++;
while (((dxpos + (x->duration[insertpos-1] * xscale)) - xpos) > 0)
insertpos--;
if (x->last_state+1 >= x->args)
envgen_resize(x,x->args+1);
for (i=x->last_state;i>=insertpos;i--)
{
x->duration[i+1] = x->duration[i];
x->finalvalues[i+1] = x->finalvalues[i];
}
x->duration[insertpos] = (float)(xpos-dxpos)/x->w.width*x->duration[x->last_state++];
x->w.pointerx = xpos;
x->w.pointery = ypos;
}
else
{
x->w.pointerx = text_xpix(&x->x_obj,glist) + x->duration[insertpos]*x->w.width/x->duration[x->last_state];
x->w.pointery = text_ypix(&x->x_obj,glist) +
(1.f - x->finalvalues[insertpos])*x->w.height;
}
x->w.grabbed = insertpos;
return insertpos;
}
static void envgen_create_doodles(t_envgen *x, t_glist *glist)
{
float xscale,yscale;
int xpos,ypos;
float xscale, yscale;
int xpos, ypos;
int i;
char guistr[255];
xscale = x->w.width/x->duration[x->last_state];
xscale = x->w.width / x->duration[x->last_state];
yscale = x->w.height;
xpos = text_xpix(&x->x_obj,glist);
ypos = (int) (text_ypix(&x->x_obj,glist) + x->w.height);
ypos = (int)(text_ypix(&x->x_obj,glist) + x->w.height);
for (i = 0; i <= x->last_state; i++)
{
//sprintf(guistr, ".x%x.c create oval %d %d %d %d -tags %xD%d",
......@@ -180,7 +182,7 @@ static void envgen_create_doodles(t_envgen *x, t_glist *glist)
//if (i == x->w.grabbed)
// strcat(guistr," -fill red\n");
//else
//else
// strcat(guistr,"\n");
//sys_vgui("%s",guistr);
gui_vmess("gui_envgen_draw_doodle", "xxii",
......@@ -206,46 +208,48 @@ static void envgen_delete_doodles(t_envgen *x, t_glist *glist)
static void envgen_update_doodles(t_envgen *x, t_glist *glist)
{
envgen_delete_doodles(x,glist);
/* LATER only create new doodles if necessary */
envgen_create_doodles(x, glist);
envgen_delete_doodles(x,glist);
/* LATER only create new doodles if necessary */
envgen_create_doodles(x, glist);
}
static void envgen_delnum(t_envgen *x)
{
sys_vgui(".x%x.c delete %xT\n",glist_getcanvas(x->w.glist),x);
//sys_vgui(".x%x.c delete %xT\n",glist_getcanvas(x->w.glist),x);
gui_vmess("gui_envgen_erase_text", "xx",
glist_getcanvas(x->w.glist), x);
}
static void envgen_shownum(t_envgen *x,t_glist* glist)
static void envgen_shownum(t_envgen *x, t_glist* glist)
{
float xscale,yscale;
int xpos,ypos;
int i= x->w.grabbed;
xscale = x->w.width/x->duration[x->last_state];
yscale = x->w.height;
xpos = text_xpix(&x->x_obj,glist);
ypos = (int) (text_ypix(&x->x_obj,glist) + x->w.height);
envgen_delnum(x);
sys_vgui(".x%x.c create text %d %d -text %fx%f -tags %xT\n",
(unsigned int)glist_getcanvas(x->w.glist),
(int) (xpos+(x->duration[i] * xscale) + 12),
(int) (ypos - x->finalvalues[i]*yscale - 2),
x->finalvalues[i]*(x->max-x->min),
x->duration[i],
(unsigned int)x);
clock_delay(x->w.numclock,700);
}
float xscale, yscale;
int xpos, ypos;
int i = x->w.grabbed;
xscale = x->w.width / x->duration[x->last_state];
yscale = x->w.height;
xpos = text_xpix(&x->x_obj, glist);
ypos = (int) (text_ypix(&x->x_obj,glist) + x->w.height);
envgen_delnum(x);
//sys_vgui(".x%x.c create text %d %d -text %fx%f -tags %xT\n",
// (unsigned int)glist_getcanvas(x->w.glist),
// (int) (xpos+(x->duration[i] * xscale) + 12),
// (int) (ypos - x->finalvalues[i]*yscale - 2),
// x->finalvalues[i]*(x->max-x->min),
// x->duration[i],
// (unsigned int)x);
gui_vmess("gui_envgen_text", "xxiiff",
glist_getcanvas(x->w.glist),
x,
(int)(x->duration[i] * xscale) + 12,
(int)(x->w.height - x->finalvalues[i] * yscale - 2),
x->finalvalues[i] * (x->max - x->min),
x->duration[i]);
clock_delay(x->w.numclock,700);
}
static void envgen_create(t_envgen *x, t_glist *glist)
{
......@@ -257,14 +261,14 @@ static void envgen_create(t_envgen *x, t_glist *glist)
xpos = text_xpix(&x->x_obj, glist);
ypos = (int)text_ypix(&x->x_obj, glist);
x->w.numclock = clock_new(x, (t_method)envgen_delnum);
x->w.numclock = clock_new(x, (t_method)envgen_delnum);
gui_vmess("gui_gobj_new", "xxsiii",
glist_getcanvas(glist),
x,
"obj",
xpos,
ypos);
ypos);
//sys_vgui(".x%x.c create rectangle "
// "%d %d %d %d -tags %xS -fill "BACKGROUNDCOLOR"\n",
......@@ -315,16 +319,16 @@ static void envgen_update(t_envgen *x, t_glist *glist)
// glist_getcanvas(glist), x,
// xpos - BORDER, ypos -BORDER,
// xpos + x->w.width+2*BORDER, ypos + x->w.height+2*BORDER);
gui_start_vmess("gui_envgen_coords", "xxii",
glist_getcanvas(glist),
x,
xpos,
ypos);
x->w.width + 2 * BORDER,
x->w.height + 2 * BORDER);
xscale = x->w.width/x->duration[x->last_state];
yscale = x->w.height;
//sprintf(buf,".x%x.c coords %pP",(unsigned int)glist_getcanvas(glist),x);
gui_start_array();
......@@ -348,16 +352,12 @@ static void envgen_update(t_envgen *x, t_glist *glist)
void envgen_drawme(t_envgen *x, t_glist *glist, int firsttime)
{
if (firsttime) envgen_create(x,glist);
else envgen_update(x,glist);
if (firsttime) envgen_create(x,glist);
else envgen_update(x,glist);
draw_inlets(x, glist, firsttime, 1,2);
draw_inlets(x, glist, firsttime, 1,2);
}
void envgen_erase(t_envgen* x, t_glist* glist)
{
int n;
......@@ -374,20 +374,17 @@ void envgen_erase(t_envgen* x, t_glist* glist)
glist_getcanvas(glist), x);
//envgen_delete_doodles(x, glist);
}
/* ------------------------ envgen widgetbehaviour----------------------------- */
static void envgen_getrect(t_gobj *z, t_glist *owner,
int *xp1, int *yp1, int *xp2, int *yp2)
{
int width, height;
t_envgen* s = (t_envgen*)z;
width = s->w.width + 2*BORDER;
height = s->w.height + 2*BORDER;
width = s->w.width + 2 * BORDER;
height = s->w.height + 2 * BORDER;
//*xp1 = text_xpix(&s->x_obj,owner)-BORDER;
//*yp1 = text_ypix(&s->x_obj,owner)-BORDER;
*xp1 = text_xpix(&s->x_obj,owner);
......@@ -396,8 +393,7 @@ static void envgen_getrect(t_gobj *z, t_glist *owner,
*yp2 = text_ypix(&s->x_obj,owner) + height + 4;
}
static void envgen_displace(t_gobj *z, t_glist *glist,
int dx, int dy)
static void envgen_displace(t_gobj *z, t_glist *glist, int dx, int dy)
{
t_envgen *x = (t_envgen *)z;
x->x_obj.te_xpix += dx;
......@@ -409,9 +405,11 @@ static void envgen_displace(t_gobj *z, t_glist *glist,
static void envgen_select(t_gobj *z, t_glist *glist, int state)
{
t_envgen *x = (t_envgen *)z;
sys_vgui(".x%x.c itemconfigure %xS -fill %s\n", glist,
x, (state? "blue" : BACKGROUNDCOLOR));
t_envgen *x = (t_envgen *)z;
//sys_vgui(".x%x.c itemconfigure %xS -fill %s\n", glist,
// x, (state? "blue" : BACKGROUNDCOLOR));
gui_vmess("gui_envgen_select", "xxi",
glist_getcanvas(glist), x, state);
}
......@@ -428,14 +426,13 @@ static void envgen_delete(t_gobj *z, t_glist *glist)
canvas_deletelinesfor(glist, x);
}
static void envgen_vis(t_gobj *z, t_glist *glist, int vis)
{
t_envgen* s = (t_envgen*)z;
if (vis)
envgen_drawme(s, glist, 1);
envgen_drawme(s, glist, 1);
else
envgen_erase(s,glist);
envgen_erase(s,glist);
}
/* can we use the normal text save function ?? */
......@@ -444,7 +441,7 @@ static void envgen_save(t_gobj *z, t_binbuf *b)
{
t_envgen *x = (t_envgen *)z;
binbuf_addv(b, "ssiisiiffss", gensym("#X"), gensym("obj"),
(t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
(t_int)x->x_obj.te_xpix, (t_int)x->x_obj.te_ypix,
atom_getsymbol(binbuf_getvec(x->x_obj.te_binbuf)),
x->w.width,x->w.height,x->max,x->min,x->r_sym,x->s_sym);
binbuf_addv(b, ";");
......@@ -454,93 +451,89 @@ static void envgen_save(t_gobj *z, t_binbuf *b)
static void envgen_followpointer(t_envgen* x,t_glist* glist)
{
float dur;
float xscale = x->duration[x->last_state]/x->w.width;
if ((x->w.grabbed > 0) && (x->w.grabbed < x->last_state)) {
dur = (x->w.pointerx - text_xpix(&x->x_obj,glist))*xscale;
if (dur < x->duration[x->w.grabbed-1])
dur = x->duration[x->w.grabbed-1];
if (dur > x->duration[x->w.grabbed+1])
dur = x->duration[x->w.grabbed+1];
x->duration[x->w.grabbed] = dur;
}
x->finalvalues[x->w.grabbed] = 1.0f - (x->w.pointery - (float)text_ypix(&x->x_obj,glist))/(float)x->w.height;
if (x->finalvalues[x->w.grabbed] < 0.0)
x->finalvalues[x->w.grabbed]= 0.0;
else if (x->finalvalues[x->w.grabbed] > 1.0)
x->finalvalues[x->w.grabbed]= 1.0;
float dur;
float xscale = x->duration[x->last_state]/x->w.width;
if ((x->w.grabbed > 0) && (x->w.grabbed < x->last_state))
{
dur = (x->w.pointerx - text_xpix(&x->x_obj,glist))*xscale;
if (dur < x->duration[x->w.grabbed-1])
dur = x->duration[x->w.grabbed-1];
if (dur > x->duration[x->w.grabbed+1])
dur = x->duration[x->w.grabbed+1];
x->duration[x->w.grabbed] = dur;
}
x->finalvalues[x->w.grabbed] = 1.0f - (x->w.pointery - (float)text_ypix(&x->x_obj,glist)) / (float)x->w.height;
if (x->finalvalues[x->w.grabbed] < 0.0)
x->finalvalues[x->w.grabbed]= 0.0;
else if (x->finalvalues[x->w.grabbed] > 1.0)
x->finalvalues[x->w.grabbed]= 1.0;
}
void envgen_motion(t_envgen *x, t_floatarg dx, t_floatarg dy)
{
if (x->w.shift) {
x->w.pointerx+=dx/1000.f;
x->w.pointery+=dy/1000.f;
}
else
{
x->w.pointerx+=dx;
x->w.pointery+=dy;
}
if (!x->resizing)
envgen_followpointer(x,x->w.glist);
else {
x->w.width+=dx;
x->w.height+=dy;
}
envgen_shownum(x,x->w.glist);
envgen_update(x,x->w.glist);
if (x->w.shift) {
x->w.pointerx += dx / 1000.f;
x->w.pointery += dy / 1000.f;
}
else
{
x->w.pointerx += dx;
x->w.pointery += dy;
}
if (!x->resizing)
envgen_followpointer(x, x->w.glist);
else
{
x->w.width += dx;
x->w.height += dy;
}
envgen_shownum(x, x->w.glist);
envgen_update(x, x->w.glist);
}
void envgen_key(t_envgen *x, t_floatarg f)
{
if (f == 8.0 && x->w.grabbed < x->last_state && x->w.grabbed > 0) {
int i;
for (i=x->w.grabbed;i<=x->last_state;i++) {
x->duration[i] = x->duration[i+1];
x->finalvalues[i] = x->finalvalues[i+1];
}
x->last_state--;
x->w.grabbed--;
envgen_update(x,x->w.glist);
}
if (f == 8.0 && x->w.grabbed < x->last_state && x->w.grabbed > 0)
{
int i;
for (i = x->w.grabbed; i <= x->last_state; i++)
{
x->duration[i] = x->duration[i+1];
x->finalvalues[i] = x->finalvalues[i+1];
}
x->last_state--;
x->w.grabbed--;
envgen_update(x,x->w.glist);
}
}
static int envgen_newclick(t_envgen *x, struct _glist *glist,
int xpos, int ypos, int shift, int alt, int dbl, int doit)
{
/* check if user wants to resize */
float wxpos = text_xpix(&x->x_obj,glist);
float wypos = (int) (text_ypix(&x->x_obj,glist) + x->w.height);
if (doit){
envgen_next_doodle(x,glist,xpos,ypos);
glist_grab(x->w.glist, &x->x_obj.te_g, (t_glistmotionfn) envgen_motion,
(t_glistkeyfn) envgen_key, xpos, ypos);
x->resizing = 0;
if (x->resizeable && (xpos > wxpos + x->w.width) &&
(ypos > wypos)) {
x->resizing = 1;
return (0);
}
x->w.shift = shift;
envgen_followpointer(x,glist);
envgen_shownum(x,glist);
envgen_update(x,glist);
}
return (1);
}
float wxpos = text_xpix(&x->x_obj, glist);
float wypos = (int) (text_ypix(&x->x_obj,glist) + x->w.height);
if (doit)
{
envgen_next_doodle(x, glist, xpos, ypos);
glist_grab(x->w.glist, &x->x_obj.te_g, (t_glistmotionfn) envgen_motion,
(t_glistkeyfn) envgen_key, xpos, ypos);
x->resizing = 0;
if (x->resizeable && (xpos > wxpos + x->w.width) &&
(ypos > wypos))
{
x->resizing = 1;
return (0);
}
x->w.shift = shift;
envgen_followpointer(x, glist);
envgen_shownum(x, glist);
envgen_update(x, glist);
}
return (1);
}
......@@ -3151,7 +3151,7 @@ function add_popup(cid, popup) {
// envgen
function gui_envgen_draw_bg(cid, tag, bg_color, w, h, points_array) {
var g = get_gobj(cid, tag),
bg, pline;
bg, border, pline;
bg = create_item(cid, "rect", {
width: w,
height: h,
......@@ -3160,6 +3160,17 @@ function gui_envgen_draw_bg(cid, tag, bg_color, w, h, points_array) {
"stroke-width": "2",
transform: "translate(0.5, 0.5)"
});
// draw an extra path so we can give envgen
// a border class without affecting the
// background color of envgen
border = create_item(cid, "path", {
"stroke-width": 1,
d: ["M", 0, 0, w+1, 0,
"M", w+1, 0, w+1, h+1,
"M", w+1, h+1, 0, h+1,
"M", 0, h+1, 0, 0].join(" "),
"class": "border",
});
pline = create_item(cid, "polyline", {
stroke: "black",
fill: "none",
......@@ -3167,6 +3178,7 @@ function gui_envgen_draw_bg(cid, tag, bg_color, w, h, points_array) {
points: points_array.join(" ")
});
g.appendChild(bg);
g.appendChild(border);
g.appendChild(pline);
}
......@@ -3194,15 +3206,57 @@ function gui_envgen_erase_doodles(cid, tag) {
}
}
function gui_envgen_coords(cid, tag, x, y, points_array) {
function gui_envgen_coords(cid, tag, w, h, points_array) {
var g = get_gobj(cid, tag),
bg = g.querySelector("rect"),
border = g.querySelector(".border"),
polyline = g.querySelector("polyline");
elem_move(g, x, y);
configure_item(bg, {
width: w,
height: h
});
configure_item(border, {
d: ["M", 0, 0, w+1, 0,
"M", w+1, 0, w+1, h+1,