Commit 9734acb5 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

constrained dragging for both gop rect and gop object on the parent

parent ff6fd860
......@@ -489,8 +489,10 @@ t_canvas *canvas_new(void *dummy, t_symbol *sel, int argc, t_atom *argv)
pd_pushsym(&x->gl_pd);
//dpsaha@vt.edu gop resize (refactored by mathieu)
x-> x_handle = scalehandle_new((t_object *)x,x,1,canvasgop__clickhook,canvasgop__motionhook);
x->x_mhandle = scalehandle_new((t_object *)x,x,0,canvasgop__clickhook,canvasgop__motionhook);
x->x_handle = scalehandle_new((t_object *)x, x, 1,
canvasgop__clickhook,canvasgop__motionhook);
x->x_mhandle = scalehandle_new((t_object *)x, x, 0,
canvasgop__clickhook,canvasgop__motionhook);
x->u_queue = canvas_undo_init(x);
//glist_setlastxy(x, 20, 20);
......@@ -985,7 +987,7 @@ void canvas_free(t_canvas *x)
if (x->gl_editor)
canvas_destroy_editor(x); /* bug workaround; should already be gone*/
if (x-> x_handle) scalehandle_free( x->x_handle);
if (x->x_handle) scalehandle_free(x->x_handle);
if (x->x_mhandle) scalehandle_free(x->x_mhandle);
canvas_unbind(x);
......@@ -2318,6 +2320,7 @@ void canvasgop_checksize(t_canvas *x)
extern int glob_shift;
void canvasgop__clickhook(t_scalehandle *sh, int newstate)
{
post("clickhook");
t_canvas *x = (t_canvas *)(sh->h_master);
if (!glob_shift)
post("note: use <shift-click> to constrain dragging");
......@@ -2329,11 +2332,27 @@ void canvasgop__clickhook(t_scalehandle *sh, int newstate)
be constrained to that first direction. */
sh->h_constrain = 0;
/* set undo */
/* We're using newstate as a sentinel value to figure out whether we
are clicking a red gop rectangle = 1, or whether we are clicking the
bottom right-hand corner of a gop object on the parent = 2.
When h_scale is not zero, we know we can check for our sentinel value.
(Otherwise the click is for moving the gop red rect.) */
if (sh->h_scale)
sh->h_scale = newstate;
/* set undo for this canvas if we're moving or resizing the red rectangle.
Otherwise, we're resizing our gop canvas on the parent, so set undo
for our toplevel canvas. */
canvas_undo_add(x, 8, "apply", canvas_undo_set_canvas(x));
if (sh->h_scale) /* resize_gop hook */
if (sh->h_scale == 1) /* resize gop hook for (red) gop rect */
{
/* This is for resizing the gop by clicking the (red) gop rectangle
that shows up when gop is enabled on a canvas. We use a sentinel
value of "1" to differentiate between clicking on the gop canvas
itself. */
/* Store an adjustment for difference between the initial
pointer position-- which is within five pixels or so-- and the
bottom right-hand corner. Otherwise we'd get a "jump" from the
......@@ -2351,6 +2370,18 @@ void canvasgop__clickhook(t_scalehandle *sh, int newstate)
just move the scalehandle stuff directly to the GUI... */
//sys_vgui("lower %s\n", sh->h_pathname);
}
// combine these two if there's no difference in the code
else if (sh->h_scale == 2)
{
/* This is for clicking on the bottom right-hand corner of the
gop canvas when it's displayed on the parent canvas. */
sh->h_adjust_x = sh->h_offset_x -
(((t_object *)x)->te_xpix + x->gl_pixwidth);
sh->h_adjust_y = sh->h_offset_y -
(((t_object *)x)->te_ypix + x->gl_pixheight);
post("adjust x is %d", sh->h_adjust_x);
post("adjust y is %d", sh->h_adjust_y);
}
else /* move_gop hook */
{
/* Same as above... */
......@@ -2358,6 +2389,9 @@ void canvasgop__clickhook(t_scalehandle *sh, int newstate)
}
}
#define HORIZ 1
#define VERT -1
void canvasgop__motionhook(t_scalehandle *sh, t_floatarg mouse_x,
t_floatarg mouse_y)
{
......@@ -2368,16 +2402,16 @@ void canvasgop__motionhook(t_scalehandle *sh, t_floatarg mouse_x,
if (glob_shift && !sh->h_constrain)
{
if (dx)
sh->h_constrain = 1; /* only move/resize horizontally */
sh->h_constrain = HORIZ; /* only move/resize horizontally */
else if (dy)
sh->h_constrain = -1; /* vertically */
sh->h_constrain = VERT; /* vertically */
}
if (sh->h_scale) /* resize_gop hook */
if (sh->h_scale == 1) /* resize_gop red rect hook */
{
int width = (sh->h_constrain == -1) ? x->gl_pixwidth :
int width = (sh->h_constrain == VERT) ? x->gl_pixwidth :
(int)mouse_x - x->gl_xmargin - sh->h_adjust_x;
int height = (sh->h_constrain == 1) ? x->gl_pixheight :
int height = (sh->h_constrain == HORIZ) ? x->gl_pixheight :
(int)mouse_y - x->gl_ymargin - sh->h_adjust_y;
x->gl_pixwidth = width = maxi(SCALE_GOP_MINWIDTH, width);
x->gl_pixheight = height = maxi(SCALE_GOP_MINHEIGHT, height);
......@@ -2396,6 +2430,63 @@ void canvasgop__motionhook(t_scalehandle *sh, t_floatarg mouse_x,
"y_pix",x->gl_pixheight + sh->h_dragy);
}
}
else if (sh->h_scale == 2) /* resize the gop on the parent */
{
int tmpx1 = 0, tmpy1 = 0, tmpx2 = 0, tmpy2 = 0;
int tmp_x_final = 0, tmp_y_final = 0;
/* The member h_glist currently points our current glist x. I think
that is being used to draw the gop red rect move anchor atm. So
rather than muck around with that code, we just set a pointer to
whatever our toplevel is here: */
t_glist *owner = canvas_getrootfor(x);
/* Just unvis the object, then vis it once we've done our
mutation and checks */
gobj_vis((t_gobj *)x, owner, 0);
/* struct _glist has its own member e_xnew for storing our offset.
At some point we need to refactor since our t_scalehandle has
members for storing offsets already. */
x->gl_pixwidth = (sh->h_constrain == VERT) ?
x->gl_pixwidth :
(int)mouse_x - ((t_object *)x)->te_xpix - sh->h_adjust_x;
x->gl_pixheight = (sh->h_constrain == HORIZ) ?
x->gl_pixheight :
(int)mouse_y - ((t_object *)x)->te_ypix - sh->h_adjust_y;
/* If the box text is not hidden then it sets a lower boundary for
box size... */
graph_checkgop_rect((t_gobj *)x, owner, &tmpx1, &tmpy1, &tmpx2,
&tmpy2);
tmpx1 = ((t_object *)x)->te_xpix;
tmpy1 = ((t_object *)x)->te_ypix;
//fprintf(stderr,"%d %d %d %d\n", tmpx1, tmpy1, tmpx2, tmpy2);
if (!x->gl_hidetext)
{
tmp_x_final = tmpx2 - tmpx1;
tmp_y_final = tmpy2 - tmpy1;
}
else
{
tmp_x_final = tmpx2;
tmp_y_final = tmpy2;
}
if (tmp_x_final > x->gl_pixwidth)
x->gl_pixwidth = tmp_x_final;
if (tmp_y_final > x->gl_pixheight)
x->gl_pixheight = tmp_y_final;
owner->gl_editor->e_xnew = mouse_x;
owner->gl_editor->e_ynew = mouse_y;
canvas_fixlinesfor(owner, (t_text *)x);
gobj_vis((t_gobj *)x, owner, 1);
canvas_dirty(owner, 1);
int properties = gfxstub_haveproperties((void *)x);
if (properties)
{
properties_set_field_int(properties,
"x_pix",x->gl_pixwidth + sh->h_dragx);
properties_set_field_int(properties,
"y_pix",x->gl_pixheight + sh->h_dragy);
}
}
else /* move_gop hook */
{
int properties = gfxstub_haveproperties((void *)x);
......
......@@ -3128,6 +3128,41 @@ void canvas_done_popup(t_canvas *x, t_float which, t_float xpos,
open_via_helppath("intro.pd", canvas_getdir((t_canvas *)x)->s_name);
}
/* For triggering text_widgetbehavior objects, graphs, atom/dropdown, and
comment resizing */
static int text_resizing_hotspot(t_canvas *x, t_object *ob, int xpos, int ypos,
int x1, int y1, int x2, int y2)
{
int offset;
/* No dragging in k12 mode, plus sanity checks */
if (sys_k12_mode || !ob || x->gl_editor->e_textedfor)
return 0;
/* only handle default text objects, atom boxes, or canvases
(both default and graph) */
if (ob->te_pd->c_wb != &text_widgetbehavior &&
ob->te_type != T_ATOM &&
ob->ob_pd != canvas_class)
{
return 0;
}
if (ob->ob_pd != canvas_class || !((t_canvas *)ob)->gl_isgraph)
{
/* For text objects and atoms our hotspot is on the right edge, making
sure to stay out of the way of potential inlet/outlet hotspots */
offset = -4;
}
else
{
/* For gop canvases, we want to be reactive. If we have 0-1 outlets then
let the hotspot extend all the way to the bottom. If not, then 4
pixels higher. */
offset = (obj_noutlets(ob) > 1) ? -4 : 0;
}
return (xpos >= x2 - 4 && ypos < y2 + offset && ypos > y1 + 4);
}
#define NOMOD 0
#define SHIFTMOD 1
#define CTRLMOD 2
......@@ -3156,8 +3191,8 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
t_gobj *yclick = NULL;
t_object *ob;
//fprintf(stderr,"MAIN canvas_doclick %d %d %d %d %d\n",
// xpos, ypos, which, mod, doit);
fprintf(stderr,"MAIN canvas_doclick %d %d %d %d %d\n",
xpos, ypos, which, mod, doit);
if (!x->gl_editor)
{
......@@ -3204,10 +3239,10 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
to let go */
if (doit)
{
//fprintf(stderr,"doit %d\n", x->gl_editor->e_onmotion);
fprintf(stderr,"doit %d\n", x->gl_editor->e_onmotion);
if (x->gl_editor->e_onmotion == MA_MOVE)
{
//fprintf(stderr,"letting go of objects\n");
fprintf(stderr,"letting go of objects\n");
t_selection *sel;
for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next)
{
......@@ -3287,10 +3322,17 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
{
/* check you're in the rectangle */
ob = pd_checkobject(&y->g_pd);
/* Let's go ahead and do our resizing hotspot check early. We need
it to short-circuit an earlier branch... */
int in_text_resizing_hotspot = text_resizing_hotspot(x, ob, xpos, ypos,
x1, y1, x2, y2);
if (rightclick)
canvas_rightclick(x, xpos, ypos, y);
else if (shiftmod && x->gl_editor->canvas_cnct_outlet_tag[0] == 0)
else if (!in_text_resizing_hotspot && shiftmod &&
x->gl_editor->canvas_cnct_outlet_tag[0] == 0)
{
fprintf(stderr, "inside canvas_cnct_outlet_tag branch\n");
//selection (only if we are not hovering above an outlet)
if (doit)
{
......@@ -3339,7 +3381,7 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
&& pd_class((t_pd *)ob) != my_canvas_class
|| pd_class(&ob->te_pd)->c_name == gensym("Scope~")
|| pd_class(&ob->te_pd)->c_name == gensym("grid"))
&& xpos >= x2-4 && ypos > y2-6)
&& xpos >= x2 - 4 && ypos > y2 - 6)
{
if (doit)
{
......@@ -3367,12 +3409,9 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
}
canvas_check_nlet_highlights(x);
}
else if (!sys_k12_mode && ob && !x->gl_editor->e_textedfor &&
(ob->te_pd->c_wb == &text_widgetbehavior ||
ob->te_type == T_ATOM ||
ob->ob_pd == canvas_class) &&
xpos >= x2-4 && ypos < y2-4 && ypos > y1+4)
else if (in_text_resizing_hotspot)
{
fprintf(stderr, "inside textedfor canvas_class\n");
if (doit)
{
if (!glist_isselected(x, y) || x->gl_editor->e_selection->sel_next)
......@@ -3385,8 +3424,18 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
x->gl_editor->e_ywas = y1;
x->gl_editor->e_xnew = xpos;
x->gl_editor->e_ynew = ypos;
canvas_undo_add(x, 6, "resize",
canvas_undo_set_apply(x, glist_getindex(x, y)));
if (ob->ob_pd != canvas_class ||
!((t_canvas *)ob)->gl_isgraph)
{
canvas_undo_add(x, 6, "resize",
canvas_undo_set_apply(x, glist_getindex(x, y)));
}
else
{
t_pd *sh = (t_pd *)((t_canvas *)ob)->x_handle;
pd_vmess(sh, gensym("_click"), "fff",
(t_float)2, (t_float)xpos, (t_float)ypos);
}
}
else
{
......@@ -3408,6 +3457,7 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
// and we are within the bottom area of an object
else if (ob && (noutlet = obj_noutlets(ob)) && ypos >= y2-4)
{
fprintf(stderr, "bottom area of object\n");
int width = x2 - x1;
int nout1 = (noutlet > 1 ? noutlet - 1 : 1);
int closest = ((xpos-x1) * (nout1) + width/2)/width;
......@@ -3419,7 +3469,7 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
{
if (doit)
{
//fprintf(stderr,"start connection\n");
fprintf(stderr,"start connection\n");
int issignal = obj_issignaloutlet(ob, closest);
x->gl_editor->e_onmotion = MA_CONNECT;
x->gl_editor->e_xwas = xpos;
......@@ -3493,6 +3543,7 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
since they are not connectable) */
else if (ob && (ninlet = obj_ninlets(ob)) && ypos <= y1+4)
{
fprintf(stderr, "inlet branch\n");
canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
int width = x2 - x1;
int nin1 = (ninlet > 1 ? ninlet - 1 : 1);
......@@ -3538,6 +3589,7 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
/* not in an outlet; select and move */
else if (doit)
{
fprintf(stderr, "not in an outlet; select and move\n");
t_rtext *rt;
/* check if the box is being text edited */
nooutletafterall:
......@@ -3584,6 +3636,7 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
else
// jsarlo
{
fprintf(stderr, "magic glass?\n");
if (x->gl_editor->canvas_cnct_inlet_tag[0] != 0)
{
canvas_nlet_conf(x,'i');
......@@ -3622,6 +3675,7 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
ypos <= x->gl_ymargin + x->gl_pixheight + 4 &&
ypos > x->gl_ymargin + x->gl_pixheight - 2)
{
fprintf(stderr, "handling gop rect\n");
// refactor the if into a function call...
if (doit)
{
......@@ -3747,9 +3801,13 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
}
// end jsarlo
if (x->gl_editor->e_onmotion != MA_SCROLL)
{
fprintf(stderr, "onmotion != MA_SCROLL\n");
canvas_setcursor(x, CURSOR_EDITMODE_NOTHING);
}
if (doit)
{
fprintf(stderr, "bottom doit\n");
if (!shiftmod &&
(x->gl_editor->e_selection || x->gl_editor->e_selectedline))
{
......@@ -5192,7 +5250,7 @@ void canvas_key(t_canvas *x, t_symbol *s, int ac, t_atom *av)
pd_vmess(&x->gl_pd, gensym("motion"), "fff",
(double)canvas_last_glist_x,
(double)canvas_last_glist_y,
(double)(glob_shift+glob_ctrl*2+glob_alt*4));
(double)(glob_shift + glob_ctrl * 2 + glob_alt * 4));
}
extern void graph_checkgop_rect(t_gobj *z, t_glist *glist,
......@@ -5293,11 +5351,17 @@ void canvas_motion(t_canvas *x, t_floatarg xpos, t_floatarg ypos,
}
else if (ob && ob->ob_pd == canvas_class)
{
/*
int tmpx1 = 0, tmpy1 = 0, tmpx2 = 0, tmpy2 = 0;
int tmp_x_final = 0, tmp_y_final = 0;
gobj_vis(y1, x, 0);
((t_canvas *)ob)->gl_pixwidth += xpos - x->gl_editor->e_xnew;
((t_canvas *)ob)->gl_pixheight += ypos - x->gl_editor->e_ynew;
post("pixwidth is %d", ((t_canvas *)ob)->gl_pixwidth);
post("pixheight is %d", ((t_canvas *)ob)->gl_pixheight);
graph_checkgop_rect((t_gobj *)ob, x, &tmpx1, &tmpy1, &tmpx2,
&tmpy2);
tmpx1 = ob->te_xpix;
......@@ -5322,6 +5386,12 @@ void canvas_motion(t_canvas *x, t_floatarg xpos, t_floatarg ypos,
canvas_fixlinesfor(x, ob);
gobj_vis(y1, x, 1);
canvas_dirty(x, 1);
*/
t_pd *sh = (t_pd *)((t_canvas *)ob)->x_handle;
pd_vmess(sh, gensym("_motion"), "ff", (t_float)xpos,
(t_float)ypos);
//marker
}
else if (ob && ob->te_iemgui)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment