Commit 1e0a0000 authored by Jonathan Wilkes's avatar Jonathan Wilkes
Browse files

add scalehandle for unauthorized/grid

parent c4ef0b17
......@@ -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
......@@ -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;
......
......@@ -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);
......
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