[PD-cvs] pd/src g_canvas.c,1.1.1.4.2.7.2.11,1.1.1.4.2.7.2.12 g_editor.c,1.1.1.4.2.3.2.13,1.1.1.4.2.3.2.14 u_main.tk,1.1.1.4.2.7.4.41,1.1.1.4.2.7.4.42
Mathieu Bouchard
matju at users.sourceforge.net
Sat Apr 17 08:04:04 CEST 2004
Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28493
Modified Files:
Tag: impd_0_37
g_canvas.c g_editor.c u_main.tk
Log Message:
wire creation outsourced to Tcl
Index: g_editor.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/g_editor.c,v
retrieving revision 1.1.1.4.2.3.2.13
retrieving revision 1.1.1.4.2.3.2.14
diff -C2 -d -r1.1.1.4.2.3.2.13 -r1.1.1.4.2.3.2.14
*** g_editor.c 17 Apr 2004 04:04:23 -0000 1.1.1.4.2.3.2.13
--- g_editor.c 17 Apr 2004 06:04:01 -0000 1.1.1.4.2.3.2.14
***************
*** 18,21 ****
--- 18,33 ----
char* inlet_tip(t_inlet* i,int num);
+ void post_atoms(const char *s, int ac, t_atom *av) {
+ char buf[1024];
+ int n=0;
+ int i;
+ n+=sprintf(buf,"%s: ",s);
+ for (i=0; i<ac; i++) {
+ atom_string(av+i,buf+n,sizeof(buf)-1-n);
+ sprintf(buf+n,", ");
+ }
+ post("%s",buf);
+ }
+
/* ------------------ forward declarations --------------- */
static void canvas_doclear(t_canvas *x);
***************
*** 978,982 ****
return;
}
! sys_vgui(".x%x.c delete x\n",x);
/* if not a runmode left click, fall here. */
--- 990,994 ----
return;
}
! /* sys_vgui(".x%x.c delete x\n",x);*/
/* if not a runmode left click, fall here. */
***************
*** 1015,1019 ****
if (ob && (noutlet = obj_noutlets(ob)) && ypos >= y2-4)
{
! int width = x2-x1;
int nout1 = noutlet>1 ? noutlet-1 : 1;
int closest = ((xpos-x1) * nout1 + width/2)/width;
--- 1027,1031 ----
if (ob && (noutlet = obj_noutlets(ob)) && ypos >= y2-4)
{
! /* int width = x2-x1;
int nout1 = noutlet>1 ? noutlet-1 : 1;
int closest = ((xpos-x1) * nout1 + width/2)/width;
***************
*** 1030,1034 ****
}
else if (doit) goto nooutletafterall;
!
}
/* look for an inlet */
--- 1042,1046 ----
}
else if (doit) goto nooutletafterall;
! */
}
/* look for an inlet */
***************
*** 1108,1180 ****
}
! void canvas_doconnect(t_canvas *x, int xpos, int ypos, int which, int doit)
! {
! int x11, y11, x12, y12; t_gobj *y1;
! int x21, y21, x22, y22; t_gobj *y2;
! int xwas = x->gl_editor->e_xwas,
! ywas = x->gl_editor->e_ywas;
! y1 = canvas_findhitbox(x, xwas, ywas, &x11, &y11, &x12, &y12);
! y2 = canvas_findhitbox(x, xpos, ypos, &x21, &y21, &x22, &y22);
! if (y1&&y2) {
! t_object *ob1 = pd_checkobject(&y1->g_pd);
! t_object *ob2 = pd_checkobject(&y2->g_pd);
! int noutlet1, ninlet2;
! if (ob1 && ob2 && ob1 != ob2
! && (noutlet1 = obj_noutlets(ob1))
! && (ninlet2 = obj_ninlets(ob2)))
! {
! int width1 = x12-x11, closest1, hotspot1;
! int width2 = x22-x21, closest2, hotspot2;
! t_outconnect *oc;
!
! if (noutlet1 > 1)
! {
! closest1 = ((xwas-x11) * (noutlet1-1) + width1/2)/width1;
! hotspot1 = x11 + (width1 - IOWIDTH) * closest1 / (noutlet1-1);
! }
! else closest1 = 0, hotspot1 = x11;
!
! if (ninlet2 > 1)
! {
! closest2 = ((xpos-x21) * (ninlet2-1) + width2/2)/width2;
! hotspot2 = x21 + (width2 - IOWIDTH) * closest2 / (ninlet2-1);
! }
! else closest2 = 0, hotspot2 = x21;
!
! if (closest1 >= noutlet1) closest1 = noutlet1-1;
! if (closest2 >= ninlet2) closest2 = ninlet2-1;
!
! if (canvas_isconnected (x, ob1, closest1, ob2, closest2))
! {
! canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
! return;
! }
! if (obj_issignaloutlet(ob1, closest1) &&
! !obj_issignalinlet(ob2, closest2))
! {
! if (doit) error("can't connect signal outlet to control inlet");
! canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
! return;
! }
! if (doit)
! {
! oc = obj_connect(ob1, closest1, ob2, closest2);
! sys_vgui("wire_update l%x {%x %d %x %d %d}\n", oc, y1, closest1, y2, closest2,
! obj_issignaloutlet(ob1, closest1));
sys_vgui("wire_draw2 l%x .x%x.c\n", oc, glist_getcanvas(x));
canvas_setundo(x, canvas_undo_connect,
canvas_undo_set_connect(x,
! canvas_getindex(x, &ob1->ob_g), closest1,
! canvas_getindex(x, &ob2->ob_g), closest2),
"connect");
! }
! else {
! canvas_setcursor(x, CURSOR_EDITMODE_CONNECT);
! canvas_inlettip(x,ob2,closest2,xpos,ypos);
! }
! return;
! }
! }
! canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
}
--- 1120,1145 ----
}
! void canvas_add_wire(t_canvas *x, t_symbol *s, int ac, t_atom *av) {
! if (ac==4 && av[0].a_type == A_SYMBOL && av[1].a_type == A_FLOAT
! && av[2].a_type == A_SYMBOL && av[3].a_type == A_FLOAT) {
! t_object *obj1, *obj2;
! int port1, port2;
! t_symbol *obj1s, *obj2s;
! t_outconnect *oc;
! obj1s = atom_getsymbol(av+0); sscanf(obj1s->s_name,"%x",&obj1); port1 = atom_getint(av+1);
! obj2s = atom_getsymbol(av+2); sscanf(obj2s->s_name,"%x",&obj2); port2 = atom_getint(av+3);
! /* post("canvas_add_wire: .x%x.c %x %d %x %d",x,obj1,port1,obj2,port2); */
! oc = obj_connect(obj1, port1, obj2, port2);
! sys_vgui("wire_update l%x {%x %d %x %d %d}\n", oc, obj1,port1,obj2,port2,
! obj_issignaloutlet(obj1,port1));
sys_vgui("wire_draw2 l%x .x%x.c\n", oc, glist_getcanvas(x));
canvas_setundo(x, canvas_undo_connect,
canvas_undo_set_connect(x,
! canvas_getindex(x, &obj1->ob_g), port1,
! canvas_getindex(x, &obj2->ob_g), port2),
"connect");
! } else {
! post("BORK");
! }
}
***************
*** 1205,1209 ****
else hiy = e->e_ywas, loy = ypos;
canvas_selectinrect(x, lox, loy, hix, hiy);
! sys_vgui(".x%x.c delete x\n", x);
e->e_onmotion = 0;
}
--- 1170,1174 ----
else hiy = e->e_ywas, loy = ypos;
canvas_selectinrect(x, lox, loy, hix, hiy);
! /* sys_vgui(".x%x.c delete x\n", x);*/
e->e_onmotion = 0;
}
***************
*** 1224,1230 ****
#endif
! if (x->gl_editor->e_onmotion == MA_CONNECT)
canvas_doconnect(x, xpos, ypos, which, 1);
! else if (x->gl_editor->e_onmotion == MA_REGION)
canvas_doregion(x, xpos, ypos, 1);
else if (x->gl_editor->e_onmotion == MA_MOVE)
--- 1189,1195 ----
#endif
! /* if (x->gl_editor->e_onmotion == MA_CONNECT)
canvas_doconnect(x, xpos, ypos, which, 1);
! else */ if (x->gl_editor->e_onmotion == MA_REGION)
canvas_doregion(x, xpos, ypos, 1);
else if (x->gl_editor->e_onmotion == MA_MOVE)
***************
*** 1378,1384 ****
else if (x->gl_editor->e_onmotion == MA_REGION)
canvas_doregion(x, xpos, ypos, 0);
! else if (x->gl_editor->e_onmotion == MA_CONNECT)
canvas_doconnect(x, xpos, ypos, 0, 0);
! else if (x->gl_editor->e_onmotion == MA_PASSOUT)
{
if (!x->gl_editor->e_motionfn)
--- 1343,1349 ----
else if (x->gl_editor->e_onmotion == MA_REGION)
canvas_doregion(x, xpos, ypos, 0);
! else /* if (x->gl_editor->e_onmotion == MA_CONNECT)
canvas_doconnect(x, xpos, ypos, 0, 0);
! else */ if (x->gl_editor->e_onmotion == MA_PASSOUT)
{
if (!x->gl_editor->e_motionfn)
***************
*** 2037,2040 ****
--- 2002,2006 ----
class_addmethod(c, (t_method)canvas_key, gensym("key"), A_GIMME, A_NULL);
class_addmethod(c, (t_method)canvas_motion, gensym("motion"), A_FLOAT, A_FLOAT, A_FLOAT, A_NULL);
+ class_addmethod(c, (t_method)canvas_add_wire, gensym("add-wire"), A_GIMME, A_NULL);
/* ------------------------ menu actions ---------------------------- */
class_addmethod(c, (t_method)canvas_menuclose, gensym("menuclose"), A_DEFFLOAT, 0);
Index: u_main.tk
===================================================================
RCS file: /cvsroot/pure-data/pd/src/u_main.tk,v
retrieving revision 1.1.1.4.2.7.4.41
retrieving revision 1.1.1.4.2.7.4.42
diff -C2 -d -r1.1.1.4.2.7.4.41 -r1.1.1.4.2.7.4.42
*** u_main.tk 17 Apr 2004 04:04:23 -0000 1.1.1.4.2.7.4.41
--- u_main.tk 17 Apr 2004 06:04:01 -0000 1.1.1.4.2.7.4.42
***************
*** 820,824 ****
proc pdtk_canvas_click {canvas x y b f} {
! global _
set self [canvastosym $canvas]
set cx [$canvas canvasx $x]
--- 820,824 ----
proc pdtk_canvas_click {canvas x y b f} {
! global _ wire_from
set self [canvastosym $canvas]
set cx [$canvas canvasx $x]
***************
*** 831,834 ****
--- 831,835 ----
pd "$self click-on-object $id $cx $cy $b $f;"
if {$edit && [llength [$canvas bbox ${id}BASE]]} {
+ set wire_from [list $cx $cy]
foreach {x1 y1 x2 y2} [$canvas bbox ${id}BASE] {}
if {abs($y2-3-$cy)<=3} {
***************
*** 840,843 ****
--- 841,845 ----
wire_draw lnew $canvas 1 $cx $cy $cx $cy
$canvas itemconfigure lnew -dash "4 4 4 4"
+ set wire_from [list $id $out]
}
}
***************
*** 850,856 ****
set dehighlight {}
proc pdtk_canvas_motion {canvas x y mods} {
! global current_x current_y tooltip _ dehighlight look
set self [canvastosym $canvas]
set cx [$canvas canvasx $x]
--- 852,859 ----
set dehighlight {}
+ set wire_from {}
proc pdtk_canvas_motion {canvas x y mods} {
! global current_x current_y tooltip _ dehighlight look wire_from wire_to
set self [canvastosym $canvas]
set cx [$canvas canvasx $x]
***************
*** 872,887 ****
object {
if {$edit && [llength [$canvas bbox ${id}BASE]]} {
foreach {x1 y1 x2 y2} [$canvas bbox ${id}BASE] {}
- #post "id=$id cx=$cx cy=$cy x1=$x1 y1=$y1 x2=$x2 y2=$y2"
if {abs($y2-3-$cy)<=3} {
! set outs 0
! catch {set outs $_($id:outlets)}
! if {$outs==0} return
! set out [expr int(($cx-$x1)*$outs/($x2-$x1))]
$canvas create rectangle \
! [l+ [$canvas coords ${id}o${out}] {-4 -4 +4 +4}] \
! -outline $look(outletfg) -width 1 -tags ${id}o${out}b
! set dehighlight "$canvas delete ${id}o${out}b"
}
} {
#post "BASEless object?"
--- 875,906 ----
object {
if {$edit && [llength [$canvas bbox ${id}BASE]]} {
+ if {[llength $wire_from]} {
+ # may highlight an inlet
+ foreach {x1 y1 x2 y2} [$canvas bbox ${id}BASE] {}
+ if {abs($y1+3-$cy)<=3} {
+ set ports 0
+ catch {set ports $_($id:inlets)}
+ if {$ports==0} return
+ set port [expr int(($cx-$x1)*$ports/($x2-$x1))]
+ $canvas create rectangle \
+ [l+ [$canvas coords ${id}i${port}] {-4 -4 +4 +4}] \
+ -outline $look(outletfg) -width 1 -tags ${id}i${port}b
+ set dehighlight "$canvas delete ${id}i${port}b; set wire_to {}"
+ set wire_to [list $id $port]
+ }
+ } {
+ # may highlight an outlet
foreach {x1 y1 x2 y2} [$canvas bbox ${id}BASE] {}
if {abs($y2-3-$cy)<=3} {
! set ports 0
! catch {set ports $_($id:outlets)}
! if {$ports==0} return
! set port [expr int(($cx-$x1)*$ports/($x2-$x1))]
$canvas create rectangle \
! [l+ [$canvas coords ${id}o${port}] {-4 -4 +4 +4}] \
! -outline $look(outletfg) -width 1 -tags ${id}o${port}b
! set dehighlight "$canvas delete ${id}o${port}b"
}
+ }
} {
#post "BASEless object?"
***************
*** 903,923 ****
}
- #proc pdtk_start_wire {canvas x y b f} {
- # if (ob && (noutlet = obj_noutlets(ob)) && ypos >= y2-4) {} {return}
- # width = x2-x1
- # nout1 = noutlet>1 ? noutlet-1 : 1
- # closest = ((xpos-x1) * nout1 + width/2)/width
- # hotspot = x1 + (width-IOWIDTH)*closest/nout1
- # if (closest < noutlet && xpos >= hotspot-1 && xpos <= hotspot + IOWIDTH+1) {
- # if (doit) {
- # issignal = obj_issignaloutlet(ob, closest)
- # x->gl_editor->e_onmotion = MA_CONNECT
- # x->gl_editor->e_xwas = xpos
- # x->gl_editor->e_ywas = ypos
- # wire_draw x .x%x.c %d %d %d %d %d\n", x, issignal?2:1, xpos, ypos, xpos, ypos
- # } {canvas_setcursor(x, CURSOR_EDITMODE_CONNECT)}
- # } {if (doit) goto nooutletafterall}
- #}
-
set pdtk_canvas_mouseup(name) 0
set pdtk_canvas_mouseup(xmin) 0
--- 922,925 ----
***************
*** 930,935 ****
# how to do it right.
proc pdtk_canvas_mouseup {name x y b} {
! global pdtk_canvas_mouseup
! pd "[canvastosym $name] mouseup [$name canvasx $x] [$name canvasy $y] $b ;"
set size [$name bbox all]
if {$size != ""} {
--- 932,942 ----
# how to do it right.
proc pdtk_canvas_mouseup {name x y b} {
! global pdtk_canvas_mouseup wire_from wire_to
! set self [canvastosym $name]
! pd "$self mouseup [$name canvasx $x] [$name canvasy $y] $b ;"
! if {[llength $wire_from]} {
! pd "$self add-wire $wire_from $wire_to ;"
! set wire_from {}
! }
set size [$name bbox all]
if {$size != ""} {
Index: g_canvas.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/g_canvas.c,v
retrieving revision 1.1.1.4.2.7.2.11
retrieving revision 1.1.1.4.2.7.2.12
diff -C2 -d -r1.1.1.4.2.7.2.11 -r1.1.1.4.2.7.2.12
*** g_canvas.c 17 Apr 2004 04:04:23 -0000 1.1.1.4.2.7.2.11
--- g_canvas.c 17 Apr 2004 06:04:01 -0000 1.1.1.4.2.7.2.12
***************
*** 281,288 ****
--- 281,290 ----
t->tr_nout = obj_noutlets(ob);
outno = 0;
+ #ifndef MATJU1
if (glist_isvisible(t->tr_x))
gobj_getrect(y, t->tr_x,
&t->tr_x11, &t->tr_y11, &t->tr_x12, &t->tr_y12);
else t->tr_x11 = t->tr_y11 = t->tr_x12 = t->tr_y12 = 0;
+ #endif /*MATJU1*/
}
t->tr_nextoutno = outno + 1;
***************
*** 294,297 ****
--- 296,300 ----
t->tr_nin = obj_ninlets(t->tr_ob2);
if (!t->tr_nin) bug("drawline");
+ #ifndef MATJU1
if (glist_isvisible(t->tr_x))
{
***************
*** 300,310 ****
gobj_getrect(&t->tr_ob2->ob_g, t->tr_x,
&t->tr_x21, &t->tr_y21, &t->tr_x22, &t->tr_y22);
! t->tr_lx1 = t->tr_x11 +
! ((t->tr_x12 - t->tr_x11 - IOWIDTH) * t->tr_outno) /
! outplus + IOMIDDLE;
t->tr_ly1 = t->tr_y12;
! t->tr_lx2 = t->tr_x21 +
! ((t->tr_x22 - t->tr_x21 - IOWIDTH) * t->tr_inno)/inplus +
! IOMIDDLE;
t->tr_ly2 = t->tr_y21;
}
--- 303,309 ----
gobj_getrect(&t->tr_ob2->ob_g, t->tr_x,
&t->tr_x21, &t->tr_y21, &t->tr_x22, &t->tr_y22);
! t->tr_lx1 = t->tr_x11 + ((t->tr_x12 - t->tr_x11 - IOWIDTH) * t->tr_outno)/outplus + IOMIDDLE;
t->tr_ly1 = t->tr_y12;
! t->tr_lx2 = t->tr_x21 + ((t->tr_x22 - t->tr_x21 - IOWIDTH) * t->tr_inno)/inplus + IOMIDDLE;
t->tr_ly2 = t->tr_y21;
}
***************
*** 314,318 ****
t->tr_lx1 = t->tr_ly1 = t->tr_lx2 = t->tr_ly2 = 0;
}
!
return (rval);
}
--- 313,317 ----
t->tr_lx1 = t->tr_ly1 = t->tr_lx2 = t->tr_ly2 = 0;
}
! #endif /*MATJU1*/
return (rval);
}
More information about the Pd-cvs
mailing list