[PD-cvs] pd/src desire.c,1.1.2.113,1.1.2.114
Mathieu Bouchard
matju at users.sourceforge.net
Sun Aug 20 22:35:44 CEST 2006
Update of /cvsroot/pure-data/pd/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31353
Modified Files:
Tag: devel_0_39
desire.c
Log Message:
deleted another 500 lines.
Index: desire.c
===================================================================
RCS file: /cvsroot/pure-data/pd/src/Attic/desire.c,v
retrieving revision 1.1.2.113
retrieving revision 1.1.2.114
diff -C2 -d -r1.1.2.113 -r1.1.2.114
*** desire.c 20 Aug 2006 20:20:19 -0000 1.1.2.113
--- desire.c 20 Aug 2006 20:35:42 -0000 1.1.2.114
***************
*** 923,927 ****
t_gobj *y;
int dspstate = canvas_suspend_dsp();
- canvas_noundo(x);
if (canvas_editing == x) canvas_editing = 0;
if (canvas_whichfind == x) canvas_whichfind = 0;
--- 923,926 ----
***************
*** 1439,1446 ****
static void glist_setlastxy(t_glist *gl, int xval, int yval);
static void glist_donewloadbangs(t_glist *x);
- static t_binbuf *canvas_docopy(t_canvas *x);
- static void canvas_dopaste(t_canvas *x, t_binbuf *b);
- static void canvas_paste(t_canvas *x);
- static void canvas_clearline(t_canvas *x);
static t_binbuf *copy_binbuf;
static char *canvas_textcopybuf;
--- 1438,1441 ----
***************
*** 1696,1809 ****
}
! /* ------------------- support for undo/redo -------------------------- */
!
! static t_undofn canvas_undo_fn; /* current undo function if any */
! static int canvas_undo_whatnext; /* whether we can now UNDO or REDO */
! static void *canvas_undo_buf; /* data private to the undo function */
! static t_canvas *canvas_undo_canvas; /* which canvas we can undo on */
! static const char *canvas_undo_name;
!
! void canvas_setundo(t_canvas *x, t_undofn undofn, void *buf,
! const char *name)
! {
! int hadone = 0;
! /* blow away the old undo information. In one special case the
! old undo info is re-used; if so we shouldn't free it here. */
! if (canvas_undo_fn && canvas_undo_buf && (buf != canvas_undo_buf))
! {
! (*canvas_undo_fn)(canvas_undo_canvas, canvas_undo_buf, UNDO_FREE);
! hadone = 1;
! }
! canvas_undo_canvas = x;
! canvas_undo_fn = undofn;
! canvas_undo_buf = buf;
! canvas_undo_whatnext = UNDO_UNDO;
! canvas_undo_name = name;
! if (x && glist_isvisible(x) && glist_istoplevel(x))
! /* enable undo in menu */
! sys_vgui("pdtk_undomenu .x%lx %s no\n", (long)x, name);
! else if (hadone)
! sys_vgui("pdtk_undomenu nobody no no\n");
! }
!
! /* clear undo if it happens to be for the canvas x.
! (but if x is 0, clear it regardless of who owns it.) */
! void canvas_noundo(t_canvas *x)
! {
! if (!x || (x == canvas_undo_canvas))
! canvas_setundo(0, 0, 0, "foo");
! }
!
! static void canvas_undo(t_canvas *x)
! {
! if (x != canvas_undo_canvas)
! bug("canvas_undo 1");
! else if (canvas_undo_whatnext != UNDO_UNDO)
! bug("canvas_undo 2");
! else
! {
! /* post("undo"); */
! (*canvas_undo_fn)(canvas_undo_canvas, canvas_undo_buf, UNDO_UNDO);
! /* enable redo in menu */
! if (glist_isvisible(x) && glist_istoplevel(x))
! sys_vgui("pdtk_undomenu .x%lx no %s\n", (long)x, canvas_undo_name);
! canvas_undo_whatnext = UNDO_REDO;
! }
! }
!
! static void canvas_redo(t_canvas *x)
! {
! if (x != canvas_undo_canvas)
! bug("canvas_undo 1");
! else if (canvas_undo_whatnext != UNDO_REDO)
! bug("canvas_undo 2");
! else
! {
! /* post("redo"); */
! (*canvas_undo_fn)(canvas_undo_canvas, canvas_undo_buf, UNDO_REDO);
! /* enable undo in menu */
! if (glist_isvisible(x) && glist_istoplevel(x))
! sys_vgui("pdtk_undomenu .x%lx %s no\n", (long)x, canvas_undo_name);
! canvas_undo_whatnext = UNDO_UNDO;
! }
! }
!
! /* ------- specific undo methods: 1. connect and disconnect -------- */
!
! typedef struct _undo_connect
! {
! int u_index1;
! int u_outletno;
! int u_index2;
! int u_inletno;
! } t_undo_connect;
!
! static void *canvas_undo_set_disconnect(t_canvas *x,
! int index1, int outno, int index2, int inno)
! {
! t_undo_connect *buf = (t_undo_connect *)getbytes(sizeof(*buf));
! buf->u_index1 = index1;
! buf->u_outletno = outno;
! buf->u_index2 = index2;
! buf->u_inletno = inno;
! return (buf);
! }
!
! void canvas_disconnect(t_canvas *x,
! float index1, float outno, float index2, float inno)
! {
t_linetraverser t;
t_outconnect *oc;
linetraverser_start(&t, x);
! while ((oc = linetraverser_next(&t)))
! {
int srcno = canvas_getindex(x, &t.tr_ob->ob_g);
int sinkno = canvas_getindex(x, &t.tr_ob2->ob_g);
if (srcno == index1 && t.tr_outno == outno &&
! sinkno == index2 && t.tr_inno == inno)
! {
! //sys_mgui(oc,"delete","");
! obj_disconnect(t.tr_ob, t.tr_outno, t.tr_ob2, t.tr_inno);
! break;
}
}
--- 1691,1706 ----
}
! void canvas_disconnect(t_canvas *x, float index1, float outno, float index2, float inno) {
t_linetraverser t;
t_outconnect *oc;
linetraverser_start(&t, x);
! while ((oc = linetraverser_next(&t))) {
int srcno = canvas_getindex(x, &t.tr_ob->ob_g);
int sinkno = canvas_getindex(x, &t.tr_ob2->ob_g);
if (srcno == index1 && t.tr_outno == outno &&
! sinkno == index2 && t.tr_inno == inno) {
! //sys_mgui(oc,"delete","");
! obj_disconnect(t.tr_ob, t.tr_outno, t.tr_ob2, t.tr_inno);
! break;
}
}
***************
*** 1811,2087 ****
}
- static void canvas_undo_disconnect(t_canvas *x, void *z, int action)
- {
- t_undo_connect *buf = (t_undo_connect *)z;
- if (action == UNDO_UNDO)
- {
- canvas_connect(x, buf->u_index1, buf->u_outletno,
- buf->u_index2, buf->u_inletno);
- }
- else if (action == UNDO_REDO)
- {
- canvas_disconnect(x, buf->u_index1, buf->u_outletno,
- buf->u_index2, buf->u_inletno);
- }
- else if (action == UNDO_FREE)
- t_freebytes(buf, sizeof(*buf));
- }
-
- /* connect just calls disconnect actions backward... */
- static void *canvas_undo_set_connect(t_canvas *x,
- int index1, int outno, int index2, int inno)
- {
- return (canvas_undo_set_disconnect(x, index1, outno, index2, inno));
- }
-
- static void canvas_undo_connect(t_canvas *x, void *z, int action)
- {
- int myaction;
- if (action == UNDO_UNDO)
- myaction = UNDO_REDO;
- else if (action == UNDO_REDO)
- myaction = UNDO_UNDO;
- else myaction = action;
- canvas_undo_disconnect(x, z, myaction);
- }
-
- /* ---------- ... 2. cut, clear, and typing into objects: -------- */
-
- #define UCUT_CUT 1 /* operation was a cut */
- #define UCUT_CLEAR 2 /* .. a clear */
- #define UCUT_TEXT 3 /* text typed into a box */
-
- typedef struct _undo_cut
- {
- t_binbuf *u_objectbuf; /* the object cleared or typed into */
- t_binbuf *u_reconnectbuf; /* connections into and out of object */
- t_binbuf *u_redotextbuf; /* buffer to paste back for redo if TEXT */
- int u_mode; /* from flags above */
- } t_undo_cut;
-
- static void *canvas_undo_set_cut(t_canvas *x, int mode)
- {
- t_undo_cut *buf;
- t_linetraverser t;
- t_outconnect *oc;
- int nnotsel= glist_selectionindex(x, 0, 0);
- buf = (t_undo_cut *)getbytes(sizeof(*buf));
- buf->u_mode = mode;
- buf->u_redotextbuf = 0;
-
- /* store connections into/out of the selection */
- buf->u_reconnectbuf = binbuf_new();
- linetraverser_start(&t, x);
- while ((oc = linetraverser_next(&t)))
- {
- int issel1 = glist_isselected(x, &t.tr_ob->ob_g);
- int issel2 = glist_isselected(x, &t.tr_ob2->ob_g);
- if (issel1 != issel2)
- {
- binbuf_addv(buf->u_reconnectbuf, "ssiiii;",
- gensym("#X"), gensym("connect"),
- (issel1 ? nnotsel : 0)
- + glist_selectionindex(x, &t.tr_ob->ob_g, issel1),
- t.tr_outno,
- (issel2 ? nnotsel : 0) +
- glist_selectionindex(x, &t.tr_ob2->ob_g, issel2),
- t.tr_inno);
- }
- }
- if (mode == UCUT_TEXT)
- {
- buf->u_objectbuf = canvas_docopy(x);
- }
- else if (mode == UCUT_CUT)
- {
- buf->u_objectbuf = 0;
- }
- else if (mode == UCUT_CLEAR)
- {
- buf->u_objectbuf = canvas_docopy(x);
- }
- return (buf);
- }
-
- static void canvas_undo_cut(t_canvas *x, void *z, int action)
- {
- t_undo_cut *buf = (t_undo_cut *)z;
- int mode = buf->u_mode;
- if (action == UNDO_UNDO)
- {
- if (mode == UCUT_CUT)
- canvas_dopaste(x, copy_binbuf);
- else if (mode == UCUT_CLEAR)
- canvas_dopaste(x, buf->u_objectbuf);
- else if (mode == UCUT_TEXT)
- {
- t_gobj *y1, *y2;
- glist_noselect(x);
- for (y1 = x->gl_list; (y2 = y1->g_next); y1 = y2)
- ;
- if (y1)
- {
- if (!buf->u_redotextbuf)
- {
- glist_noselect(x);
- glist_select(x, y1);
- buf->u_redotextbuf = canvas_docopy(x);
- glist_noselect(x);
- }
- glist_delete(x, y1);
- }
- canvas_dopaste(x, buf->u_objectbuf);
- }
- pd_bind(&x->gl_pd, gensym("#X"));
- binbuf_eval(buf->u_reconnectbuf, 0, 0, 0);
- pd_unbind(&x->gl_pd, gensym("#X"));
- }
- else if (action == UNDO_REDO)
- {
- if (mode == UCUT_CUT || mode == UCUT_CLEAR)
- canvas_doclear(x);
- else if (mode == UCUT_TEXT)
- {
- t_gobj *y1, *y2;
- for (y1 = x->gl_list; (y2 = y1->g_next); y1 = y2)
- ;
- if (y1)
- glist_delete(x, y1);
- canvas_dopaste(x, buf->u_redotextbuf);
- pd_bind(&x->gl_pd, gensym("#X"));
- binbuf_eval(buf->u_reconnectbuf, 0, 0, 0);
- pd_unbind(&x->gl_pd, gensym("#X"));
- }
- }
- else if (action == UNDO_FREE)
- {
- if (buf->u_objectbuf)
- binbuf_free(buf->u_objectbuf);
- if (buf->u_reconnectbuf)
- binbuf_free(buf->u_reconnectbuf);
- if (buf->u_redotextbuf)
- binbuf_free(buf->u_redotextbuf);
- t_freebytes(buf, sizeof(*buf));
- }
- }
-
- /* --------- 3. motion, including "tidy up" and stretching ----------- */
-
- typedef struct _undo_move_elem
- {
- int e_index;
- int e_xpix;
- int e_ypix;
- } t_undo_move_elem;
-
- typedef struct _undo_move
- {
- t_undo_move_elem *u_vec;
- int u_n;
- } t_undo_move;
-
- static int canvas_undo_already_set_move;
-
- static void *canvas_undo_set_move(t_canvas *x, int selected)
- {
- int x1, y1, x2, y2, i, indx;
- t_gobj *y;
- t_undo_move *buf = (t_undo_move *)getbytes(sizeof(*buf));
- buf->u_n = selected ? glist_selectionindex(x, 0, 1) : glist_getindex(x, 0);
- buf->u_vec = (t_undo_move_elem *)getbytes(sizeof(*buf->u_vec) *
- (selected ? glist_selectionindex(x, 0, 1) : glist_getindex(x, 0)));
- if (selected)
- {
- for (y = x->gl_list, i = indx = 0; y; y = y->g_next, indx++)
- if (glist_isselected(x, y))
- {
- gobj_getrect(y, x, &x1, &y1, &x2, &y2);
- buf->u_vec[i].e_index = indx;
- buf->u_vec[i].e_xpix = x1;
- buf->u_vec[i].e_ypix = y1;
- i++;
- }
- }
- else
- {
- for (y = x->gl_list, indx = 0; y; y = y->g_next, indx++)
- {
- gobj_getrect(y, x, &x1, &y1, &x2, &y2);
- buf->u_vec[indx].e_index = indx;
- buf->u_vec[indx].e_xpix = x1;
- buf->u_vec[indx].e_ypix = y1;
- }
- }
- canvas_undo_already_set_move = 1;
- return (buf);
- }
-
- static void canvas_undo_move(t_canvas *x, void *z, int action)
- {
- t_undo_move *buf = (t_undo_move *)z;
- if (action == UNDO_UNDO || action == UNDO_REDO)
- {
- int i;
- for (i = 0; i < buf->u_n; i++)
- {
- int x1, y1, x2, y2, newx, newy;
- t_gobj *y;
- newx = buf->u_vec[i].e_xpix;
- newy = buf->u_vec[i].e_ypix;
- y = glist_nth(x, buf->u_vec[i].e_index);
- if (y)
- {
- gobj_getrect(y, x, &x1, &y1, &x2, &y2);
- gobj_displace(y, x, newx-x1, newy - y1);
- buf->u_vec[i].e_xpix = x1;
- buf->u_vec[i].e_ypix = y1;
- }
- }
- }
- else if (action == UNDO_FREE)
- {
- t_freebytes(buf->u_vec, buf->u_n * sizeof(*buf->u_vec));
- t_freebytes(buf, sizeof(*buf));
- }
- }
-
- /* --------- 4. paste (also duplicate) ----------- */
-
- typedef struct _undo_paste
- {
- int u_index; /* index of first object pasted */
- } t_undo_paste;
-
- static void *canvas_undo_set_paste(t_canvas *x)
- {
- t_undo_paste *buf = (t_undo_paste *)getbytes(sizeof(*buf));
- buf->u_index = glist_getindex(x, 0);
- return (buf);
- }
-
- static void canvas_undo_paste(t_canvas *x, void *z, int action)
- {
- t_undo_paste *buf = (t_undo_paste *)z;
- if (action == UNDO_UNDO)
- {
- t_gobj *y;
- glist_noselect(x);
- for (y = glist_nth(x, buf->u_index); y; y = y->g_next)
- glist_select(x, y);
- canvas_doclear(x);
- }
- else if (action == UNDO_REDO)
- {
- t_selection *sel;
- canvas_dopaste(x, copy_binbuf);
- /* if it was "duplicate" have to re-enact the displacement. */
- if (canvas_undo_name && canvas_undo_name[0] == 'd')
- for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next)
- gobj_displace(sel->sel_what, x, 10, 10);
- }
- else if (action == UNDO_FREE)
- t_freebytes(buf, sizeof(*buf));
- }
-
/* recursively check for abstractions to reload as result of a save.
Don't reload the one we just saved ("except") though. */
--- 1708,1711 ----
***************
*** 2109,2116 ****
glist_noselect(gl);
glist_select(gl, g);
- canvas_setundo(gl, canvas_undo_cut,
- canvas_undo_set_cut(gl, UCUT_CLEAR), "clear");
canvas_doclear(gl);
! canvas_undo(gl);
glist_noselect(gl);
g = glist_nth(gl, j);
--- 1733,1738 ----
glist_noselect(gl);
glist_select(gl, g);
canvas_doclear(gl);
! /*FIXME (gl); */
glist_noselect(gl);
g = glist_nth(gl, j);
***************
*** 2616,2662 ****
}
- static t_binbuf *canvas_docopy(t_canvas *x)
- {
- t_gobj *y;
- t_linetraverser t;
- t_outconnect *oc;
- t_binbuf *b = binbuf_new();
- for (y = x->gl_list; y; y = y->g_next)
- {
- if (glist_isselected(x, y))
- gobj_save(y, b);
- }
- linetraverser_start(&t, x);
- while ((oc = linetraverser_next(&t)))
- {
- if (glist_isselected(x, &t.tr_ob->ob_g)
- && glist_isselected(x, &t.tr_ob2->ob_g))
- {
- binbuf_addv(b, "ssiiii;", gensym("#X"), gensym("connect"),
- glist_selectionindex(x, &t.tr_ob->ob_g, 1), t.tr_outno,
- glist_selectionindex(x, &t.tr_ob2->ob_g, 1), t.tr_inno);
- }
- }
- return (b);
- }
-
- static void canvas_clearline(t_canvas *x)
- {
- if (x->gl_editor->e_selectedline)
- {
- canvas_disconnect(x, x->gl_editor->e_selectline_index1,
- x->gl_editor->e_selectline_outno,
- x->gl_editor->e_selectline_index2,
- x->gl_editor->e_selectline_inno);
- canvas_setundo(x, canvas_undo_disconnect,
- canvas_undo_set_disconnect(x,
- x->gl_editor->e_selectline_index1,
- x->gl_editor->e_selectline_outno,
- x->gl_editor->e_selectline_index2,
- x->gl_editor->e_selectline_inno),
- "disconnect");
- }
- }
-
extern t_pd *newest;
static void canvas_doclear(t_canvas *x)
--- 2238,2241 ----
***************
*** 2672,2682 ****
x->gl_editor->e_selectline_index2,
x->gl_editor->e_selectline_inno);
- canvas_setundo(x, canvas_undo_disconnect,
- canvas_undo_set_disconnect(x,
- x->gl_editor->e_selectline_index1,
- x->gl_editor->e_selectline_outno,
- x->gl_editor->e_selectline_index2,
- x->gl_editor->e_selectline_inno),
- "disconnect");
}
/* if text is selected, deselecting it might remake the
--- 2251,2254 ----
***************
*** 2730,2799 ****
}
- static void canvas_dopaste(t_canvas *x, t_binbuf *b)
- {
- t_gobj *g2;
- int dspstate = canvas_suspend_dsp(), nbox, count;
-
- canvas_editmode(x, 1.);
- glist_noselect(x);
- for (g2 = x->gl_list, nbox = 0; g2; g2 = g2->g_next) nbox++;
-
- paste_onset = nbox;
- paste_canvas = x;
-
- pd_bind(&x->gl_pd, gensym("#X"));
- binbuf_eval(b, 0, 0, 0);
- pd_unbind(&x->gl_pd, gensym("#X"));
- for (g2 = x->gl_list, count = 0; g2; g2 = g2->g_next, count++)
- if (count >= nbox)
- glist_select(x, g2);
- paste_canvas = 0;
- canvas_resume_dsp(dspstate);
- canvas_dirty(x, 1);
- sys_mgui(x,"getscroll","");
- glist_donewloadbangs(x);
- }
-
- static void canvas_paste(t_canvas *x)
- {
- if (!x->gl_editor)
- return;
- if (x->gl_editor->e_textedfor)
- {
- /* simulate keystrokes as if the copy buffer were typed in. */
- #ifdef UNIX
- /* in UNIX we kept the text in our own copy buffer */
- int i;
- for (i = 0; i < canvas_textcopybufsize; i++)
- {
- pd_vmess(&x->gl_gobj.g_pd, gensym("key"), "iii",
- 1, canvas_textcopybuf[i]&0xff, 0);
- }
- #else /* UNIX */
- /* otherwise appeal to the GUI to send the clipboard down */
- sys_gui("pdtk_pastetext\n");
- #endif /* UNIX */
-
- }
- else
- {
- canvas_setundo(x, canvas_undo_paste, canvas_undo_set_paste(x),
- "paste");
- canvas_dopaste(x, copy_binbuf);
- }
- }
-
- static void canvas_selectall(t_canvas *x)
- {
- t_gobj *y;
- if (!x->gl_edit)
- canvas_editmode(x, 1);
- for (y = x->gl_list; y; y = y->g_next)
- {
- if (!glist_isselected(x, y))
- glist_select(x, y);
- }
- }
-
extern t_class *text_class;
--- 2302,2305 ----
***************
*** 2862,2868 ****
int all = (x->gl_editor ? (x->gl_editor->e_selection == 0) : 1);
- canvas_setundo(x, canvas_undo_move, canvas_undo_set_move(x, !all),
- "motion");
-
/* tidy horizontally */
for (y = x->gl_list; y; y = y->g_next)
--- 2368,2371 ----
***************
*** 2992,2997 ****
if (xresize != 1 || yresize != 1)
{
- canvas_setundo(x, canvas_undo_move, canvas_undo_set_move(x, 0),
- "motion");
for (y = x->gl_list; y; y = y->g_next)
{
--- 2495,2498 ----
***************
*** 12215,12221 ****
/* should die: */
- class_addmethod3(c,canvas_selectall,"selectall","");
- class_addmethod3(c,canvas_undo, "undo","");
- class_addmethod3(c,canvas_redo, "redo","");
class_addmethod3(c,canvas_tidy, "tidy","");
class_addmethod3(c,canvas_texteditor,"texteditor","");
--- 11716,11719 ----
More information about the Pd-cvs
mailing list