From 3fd85e7626e48aebe8689c88082cc32a473c380f Mon Sep 17 00:00:00 2001 From: Ivica Ico Bukvic <ico@vt.edu> Date: Fri, 17 Aug 2012 20:04:53 -0400 Subject: [PATCH] added accelerated displacement of scalars --- src/g_scalar.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++-- src/g_template.c | 4 ++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/g_scalar.c b/src/g_scalar.c index 35321e172..c2415aa53 100644 --- a/src/g_scalar.c +++ b/src/g_scalar.c @@ -222,14 +222,32 @@ static void scalar_select(t_gobj *z, t_glist *owner, int state) t_template *tmpl; t_symbol *templatesym = x->sc_template; t_atom at; + t_canvas *templatecanvas = NULL; t_gpointer gp; gpointer_init(&gp); gpointer_setglist(&gp, owner, x); SETPOINTER(&at, &gp); - if (tmpl = template_findbyname(templatesym)) + if (tmpl = template_findbyname(templatesym)) { template_notify(tmpl, (state ? gensym("select") : gensym("deselect")), 1, &at); + templatecanvas = template_findcanvas(tmpl); + } gpointer_unset(&gp); + if (state) { + sys_vgui(".x%lx.c addtag selected withtag scalar%lx\n", + glist_getcanvas(owner), x); + if (templatecanvas) { + sys_vgui(".x%lx.c addtag selected withtag %lx\n", + glist_getcanvas(owner), x->sc_vec); + } + } else { + sys_vgui(".x%lx.c dtag scalar%lx selected\n", + glist_getcanvas(owner), x); + if (templatecanvas) { + sys_vgui(".x%lx.c dtag %lx selected\n", + glist_getcanvas(owner), x->sc_vec); + } + } //sys_vgui("pdtk_select_all_gop_widgets .x%lx %lx %d\n", glist_getcanvas(owner), owner, state); scalar_drawselectrect(x, owner, state); } @@ -269,6 +287,41 @@ static void scalar_displace(t_gobj *z, t_glist *glist, int dx, int dy) scalar_redraw(x, glist); } +static void scalar_displace_withtag(t_gobj *z, t_glist *glist, int dx, int dy) +{ + t_scalar *x = (t_scalar *)z; + t_symbol *templatesym = x->sc_template; + t_template *template = template_findbyname(templatesym); + t_symbol *zz; + t_atom at[3]; + t_gpointer gp; + int xonset, yonset, xtype, ytype, gotx, goty; + if (!template) + { + error("scalar: couldn't find template %s", templatesym->s_name); + return; + } + gotx = template_find_field(template, gensym("x"), &xonset, &xtype, &zz); + if (gotx && (xtype != DT_FLOAT)) + gotx = 0; + goty = template_find_field(template, gensym("y"), &yonset, &ytype, &zz); + if (goty && (ytype != DT_FLOAT)) + goty = 0; + if (gotx) + *(t_float *)(((char *)(x->sc_vec)) + xonset) += + dx * (glist_pixelstox(glist, 1) - glist_pixelstox(glist, 0)); + if (goty) + *(t_float *)(((char *)(x->sc_vec)) + yonset) += + dy * (glist_pixelstoy(glist, 1) - glist_pixelstoy(glist, 0)); + gpointer_init(&gp); + gpointer_setglist(&gp, glist, x); + SETPOINTER(&at[0], &gp); + SETFLOAT(&at[1], (t_float)dx); + SETFLOAT(&at[2], (t_float)dy); + template_notify(template, gensym("displace"), 2, at); + //scalar_redraw(x, glist); +} + static void scalar_activate(t_gobj *z, t_glist *owner, int state) { /* post("scalar_activate %d", state); */ @@ -413,7 +466,7 @@ static t_widgetbehavior scalar_widgetbehavior = scalar_delete, scalar_vis, scalar_click, - NULL, + scalar_displace_withtag, }; static void scalar_free(t_scalar *x) diff --git a/src/g_template.c b/src/g_template.c index 38a765b4b..ecfdd37bb 100644 --- a/src/g_template.c +++ b/src/g_template.c @@ -1173,8 +1173,8 @@ static void curve_vis(t_gobj *z, t_glist *glist, fill, outline); else sys_vgui("-fill %s\\\n", outline); if (flags & BEZ) sys_vgui("-smooth 1\\\n"); - sys_vgui("-tags .x%lx.x%lx.curve%lx\n", glist_getcanvas(glist), glist, - data); + sys_vgui("-tags {.x%lx.x%lx.curve%lx %lx}\n", glist_getcanvas(glist), glist, + data, data); } else post("warning: curves need at least two points to be graphed"); } -- GitLab