diff --git a/externals/unauthorized/grid/g_grid.h b/externals/unauthorized/grid/g_grid.h index 9c8922874e0ef42a1f0fa4d41495a27d5bf32a16..aeb89f2b495e5d4fcf8d7f1f7d9916a833d6c17f 100644 --- a/externals/unauthorized/grid/g_grid.h +++ b/externals/unauthorized/grid/g_grid.h @@ -32,6 +32,7 @@ typedef struct _grid int x_xlines; /* number of vertical lines */ int x_ylines; /* number of horizontal lines */ char *x_bgcolor; /* background color */ + t_pd *x_handle; /* for click-drag resizing */ } t_grid; #endif diff --git a/externals/unauthorized/grid/grid.c b/externals/unauthorized/grid/grid.c index 2349ce64d1dce45fc6f7ba201e4b4d4c13466918..237ab674e41755e1850050fbca49b642f0a20eb8 100644 --- a/externals/unauthorized/grid/grid.c +++ b/externals/unauthorized/grid/grid.c @@ -16,6 +16,9 @@ #include "g_grid.h" +/* For the scalehandle... */ +#include "g_all_guis.h" + #ifdef _WIN32 #include <io.h> #else @@ -25,6 +28,8 @@ #define DEFAULT_GRID_WIDTH 200 #define DEFAULT_GRID_HEIGHT 200 #define DEFAULT_GRID_NBLINES 10 +#define MIN_GRID_WIDTH 20 +#define MIN_GRID_HEIGHT 20 t_widgetbehavior grid_widgetbehavior; static t_class *grid_class; @@ -678,6 +683,62 @@ static void grid_bang(t_grid *x) { grid_output_current(x); } +static void grid__clickhook(t_scalehandle *sh, int newstate) +{ + t_grid *x = (t_grid *)(sh->h_master); + if (newstate) + { + canvas_apply_setundo(x->x_glist, (t_gobj *)x); + } + sh->h_dragon = newstate; +} + +static void grid__motionhook(t_scalehandle *sh, + t_floatarg mouse_x, t_floatarg mouse_y) +{ + if (sh->h_scale) + { + t_grid *x = (t_grid *)(sh->h_master); + int width = mouse_x - text_xpix(&x->x_obj, x->x_glist), + height = mouse_y - text_ypix(&x->x_obj, x->x_glist), + minw = MIN_GRID_WIDTH, + minh = MIN_GRID_HEIGHT; + x->x_width = width < minw ? minw : width; + x->x_height = height < minh ? minh : height; + if (glist_isvisible(x->x_glist)) + { + grid_draw_configure(x, x->x_glist); + //scalehandle_unclick_scale(sh); + } + + int properties = gfxstub_haveproperties((void *)x); + if (properties) + { + int new_w = x->x_width + sh->h_dragx; + int new_h = x->x_height + sh->h_dragy; + properties_set_field_int(properties,"width",new_w); + properties_set_field_int(properties,"height",new_h); + } + } +} + +/* wrapper method for forwarding "scalehandle" data */ +static void grid_click_for_resizing(t_grid *x, t_floatarg f, + t_floatarg xxx, t_floatarg yyy) +{ + t_scalehandle *sh = (t_scalehandle *)x->x_handle; + grid__clickhook(sh, f); +// grid__clickhook(sh, f, xxx, yyy); +} + +/* another wrapper for forwarding "scalehandle" motion data */ +static void grid_motion_for_resizing(t_grid *x, t_floatarg xxx, + t_floatarg yyy) +{ + t_scalehandle *sh = (t_scalehandle *)x->x_handle; + grid__motionhook(sh, xxx, yyy); +} + static t_grid *grid_new(t_symbol *s, int argc, t_atom *argv) { int zz; @@ -770,6 +831,9 @@ static t_grid *grid_new(t_symbol *s, int argc, t_atom *argv) // post( "grid_new name : %s width: %d height : %d", // x->x_name->s_name, x->x_width, x->x_height ); + x->x_handle = scalehandle_new((t_object *)x, x->x_glist, 1, + grid__clickhook, grid__motionhook); + return (x); } @@ -805,6 +869,14 @@ void grid_setup(void) gensym("dialog"), A_GIMME, 0); class_addmethod(grid_class, (t_method)grid_new_color, gensym("color"), A_FLOAT, A_FLOAT, A_FLOAT, 0); + /* Big hack for receiving edit-mode resize anchor clicks from + g_editor.c. */ + class_addmethod(grid_class, (t_method)grid_click_for_resizing, + gensym("_click_for_resizing"), + A_FLOAT, A_FLOAT, A_FLOAT, 0); + class_addmethod(grid_class, (t_method)grid_motion_for_resizing, + gensym("_motion_for_resizing"), + A_FLOAT, A_FLOAT, 0); grid_widgetbehavior.w_getrectfn = grid_getrect; grid_widgetbehavior.w_displacefn = grid_displace; grid_widgetbehavior.w_selectfn = grid_select; diff --git a/pd/src/g_editor.c b/pd/src/g_editor.c index 436e113fe6085b65c6d390d7308f32ba92290d41..5312f23c2e032798d72e1bfd07df65e2f4259969 100644 --- a/pd/src/g_editor.c +++ b/pd/src/g_editor.c @@ -3306,8 +3306,8 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which, int noutlet; int ninlet; /* resize? only for "true" text boxes, canvases, iemguis, - and -- using an awful hack-- for the Scope~ object - by checking for the class name below. + and -- using an awful hack-- for the Scope~ and grid + objects by checking for the class name below. One exception-- my_canvas. It has a weirdo interface where the visual dimensions usually (i.e., by default) @@ -3315,10 +3315,11 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which, we have a virtual waterfall of conditionals flowing all the way to the GUI just handle resizing a stupid rectangle. */ - if (ob && - (ob->te_iemgui && pd_class((t_pd *)ob) != my_canvas_class - || pd_class(&ob->te_pd)->c_name == gensym("Scope~")) - && xpos >= x2-4 && ypos > y2-6) + if ((ob && ob->te_iemgui + && 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) { if (doit) { @@ -5268,7 +5269,8 @@ void canvas_motion(t_canvas *x, t_floatarg xpos, t_floatarg ypos, pd_vmess(sh, gensym("_motion"), "ff", (t_float)xpos, (t_float)ypos); //pd_vmess(sh, gensym("_click"), "fff", 0, xpos, ypos); } - else if (ob && pd_class(&ob->te_pd)->c_name == gensym("Scope~")) + else if (ob && (pd_class(&ob->te_pd)->c_name == gensym("Scope~") + || pd_class(&ob->te_pd)->c_name == gensym("grid"))) { pd_vmess((t_pd *)ob, gensym("_motion_for_resizing"), "ff", (t_float)xpos, (t_float)ypos);