Commit ff6fd860 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

add constrained dragging to gop rectangle

parent 9484aff7
......@@ -783,7 +783,10 @@ t_scalehandle *scalehandle_new(t_object *x, t_glist *glist, int scale,
h->h_scale = scale;
h->h_offset_x = 0;
h->h_offset_y = 0;
h->h_adjust_x = 0;
h->h_adjust_y = 0;
h->h_vis = 0;
h->h_constrain = 0;
sprintf(h->h_pathname, ".x%lx.h%lx", (t_int)h->h_glist, (t_int)h);
h->h_clickfn = chf;
h->h_motionfn = mhf;
......
......@@ -54,6 +54,9 @@ typedef struct _scalehandle
int h_dragy;
int h_offset_x;
int h_offset_y;
int h_adjust_x;
int h_adjust_y;
int h_constrain;
int h_vis; // bool
t_clickhandlefn h_clickfn;
t_motionhandlefn h_motionfn;
......
......@@ -2315,111 +2315,47 @@ void canvasgop_checksize(t_canvas *x)
}
}
extern int glob_shift;
void canvasgop__clickhook(t_scalehandle *sh, int newstate)
{
t_canvas *x = (t_canvas *)(sh->h_master);
if (sh->h_dragon && newstate == 0)
{
/* done dragging */
if(sh->h_scale) //enter if resize_gop hook
{
canvas_undo_add(x, 8, "apply", canvas_undo_set_canvas(x));
if (!glob_shift)
post("note: use <shift-click> to constrain dragging");
if (sh->h_dragx || sh->h_dragy)
{
x->gl_pixwidth += sh->h_dragx;
x->gl_pixheight += sh->h_dragy;
// check if the text is not hidden. if so, make minimum
// width and height based retrieved from getrect.
if (!x->gl_hidetext)
{
int x1=0, y1=0, x2=0, y2=0;
if (x->gl_owner)
{
gobj_getrect((t_gobj*)x, x->gl_owner,
&x1, &y1, &x2, &y2);
}
else
{
graph_checkgop_rect((t_gobj*)x, x, &x1, &y1, &x2, &y2);
}
if (x2-x1 > x->gl_pixwidth) x->gl_pixwidth = x2-x1;
if (y2-y1 > x->gl_pixheight) x->gl_pixheight = y2-y1;
}
canvas_dirty(x, 1);
}
/* Set constrain to zero. Then when the motion starts in
canvasgop__motionhook, we'll check to see what is the
first direction that the pointer moves. If the shift key
is depressed at that time then constrained dragging will
be constrained to that first direction. */
sh->h_constrain = 0;
// can't remove this update because the text size check above is not in motionhook
int properties = gfxstub_haveproperties((void *)x);
if (properties)
{
properties_set_field_int(properties,"x_pix",x->gl_pixwidth);
properties_set_field_int(properties,"y_pix",x->gl_pixheight);
}
/* set undo */
canvas_undo_add(x, 8, "apply", canvas_undo_set_canvas(x));
if (glist_isvisible(x))
{
/* Still not sure what this is doing... */
//sys_vgui(".x%x.c delete %s\n", x, sh->h_outlinetag);
canvasgop_draw_move(x,1);
canvas_fixlinesfor(x, (t_text *)x);
scrollbar_update(x);
}
}
else //enter if move_gop hook
{
// this block is similar to scalehandle_unclick_label but not enough
// We've actually removed scalehandle_unclick_label everywhere, so
// check to see whether this can be removed as well...
canvas_undo_add(x, 8, "apply", canvas_undo_set_canvas(x));
if (sh->h_dragx || sh->h_dragy)
{
x->gl_xmargin += sh->h_dragx;
x->gl_ymargin += sh->h_dragy;
canvas_dirty(x, 1);
}
if (glist_isvisible(x))
{
canvasgop_draw_move(x,1);
canvas_fixlinesfor(x, (t_text *)x);
scrollbar_update(x);
}
}
}
else if (!sh->h_dragon && newstate)
if (sh->h_scale) /* resize_gop hook */
{
/* set undo */
canvas_undo_add(x, 8, "apply", canvas_undo_set_canvas(x));
/* 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
the current dimensions to the pointer offset. Such a jump would
become noticeable with constrained dragging, as the constrained
dimension would initially jump to the pointer position.
if(sh->h_scale) //enter if resize_gop hook
{
/* We could port this, but it might be better to wait until we
just move the scalehandle stuff directly to the GUI... */
//sys_vgui("lower %s\n", sh->h_pathname);
//delete GOP rect where it started from
/* Doesn't look like we're using this anymore, so no need to
port it. */
//sys_vgui(".x%lx.c delete GOP\n", x);
//sys_vgui(".x%x.c create rectangle %d %d %d %d "
// "-outline $pd_colors(selection) -width 1 -tags %s\n",
// x, x->gl_xmargin, x->gl_ymargin,
// x->gl_xmargin + x->gl_pixwidth,
// x->gl_ymargin + x->gl_pixheight, sh->h_outlinetag);
}
else //enter if move_gop hook
{
//scalehandle_draw_erase(sh,x);
/* Same as above... */
//sys_vgui("lower %s\n", sh->h_pathname);
We could alternatively use dx/dy, but then the pointer position
would stray when the user attempts to drag past the minimum
width/height of the rectangle. */
sh->h_adjust_x = sh->h_offset_x - (x->gl_xmargin + x->gl_pixwidth);
sh->h_adjust_y = sh->h_offset_y - (x->gl_ymargin + x->gl_pixheight);
//delete GOP_resblob when moving the whole GOP
//sys_vgui(".x%lx.c delete %lxSCALE\n", x, x);
}
sh->h_dragx = 0;
sh->h_dragy = 0;
/* We could port this, but it might be better to wait until we
just move the scalehandle stuff directly to the GUI... */
//sys_vgui("lower %s\n", sh->h_pathname);
}
else /* move_gop hook */
{
/* Same as above... */
//sys_vgui("lower %s\n", sh->h_pathname);
}
sh->h_dragon = newstate;
}
void canvasgop__motionhook(t_scalehandle *sh, t_floatarg mouse_x,
......@@ -2428,51 +2364,60 @@ void canvasgop__motionhook(t_scalehandle *sh, t_floatarg mouse_x,
t_canvas *x = (t_canvas *)(sh->h_master);
int dx = (int)mouse_x - sh->h_offset_x,
dy = (int)mouse_y - sh->h_offset_y;
if (sh->h_dragon)
{
if (sh->h_scale) //enter if resize_gop hook
if (glob_shift && !sh->h_constrain)
{
if (dx)
sh->h_constrain = 1; /* only move/resize horizontally */
else if (dy)
sh->h_constrain = -1; /* vertically */
}
if (sh->h_scale) /* resize_gop hook */
{
int width = (sh->h_constrain == -1) ? x->gl_pixwidth :
(int)mouse_x - x->gl_xmargin - sh->h_adjust_x;
int height = (sh->h_constrain == 1) ? 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);
gui_vmess("gui_canvas_redrect_coords", "xiiii",
x,
x->gl_xmargin,
x->gl_ymargin,
x->gl_xmargin + width,
x->gl_ymargin + height);
int properties = gfxstub_haveproperties((void *)x);
if (properties)
{
int width = mouse_x - x->gl_xmargin,
height = mouse_y - x->gl_ymargin;
x->gl_pixwidth = width = maxi(SCALE_GOP_MINWIDTH, width);
x->gl_pixheight = height = maxi(SCALE_GOP_MINHEIGHT, height);
gui_vmess("gui_canvas_redrect_coords", "xiiii",
x,
x->gl_xmargin,
x->gl_ymargin,
x->gl_xmargin + width,
x->gl_ymargin + height);
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);
}
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 //enter if move_gop hook
}
else /* move_gop hook */
{
int properties = gfxstub_haveproperties((void *)x);
if (properties)
{
int properties = gfxstub_haveproperties((void *)x);
if (properties)
{
properties_set_field_int(properties,
"x_margin",x->gl_xmargin + dx);
properties_set_field_int(properties,
"x_margin",x->gl_xmargin + dx);
properties_set_field_int(properties,
"y_margin",x->gl_ymargin + dy);
}
"y_margin",x->gl_ymargin + dy);
}
if (sh->h_constrain == 1 || !sh->h_constrain)
x->gl_xmargin += dx;
if (sh->h_constrain == -1 || !sh->h_constrain)
x->gl_ymargin += dy;
int x1 = x->gl_xmargin, x2 = x1+x->gl_pixwidth;
int y1 = x->gl_ymargin, y2 = y1+x->gl_pixheight;
int x1 = x->gl_xmargin, x2 = x1+x->gl_pixwidth;
int y1 = x->gl_ymargin, y2 = y1+x->gl_pixheight;
gui_vmess("gui_canvas_redrect_coords", "xiiii",
x, x1, y1, x2, y2);
sh->h_dragx = dx;
sh->h_dragy = dy;
}
gui_vmess("gui_canvas_redrect_coords", "xiiii",
x, x1, y1, x2, y2);
sh->h_dragx = dx;
sh->h_dragy = dy;
}
}
......
Supports Markdown
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