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

very rough port of the iemgui scaling handle. Works perfectly for bng atm

parent cd92b517
......@@ -963,7 +963,11 @@ static void scalehandle_clickhook(t_scalehandle *h, t_floatarg f,
static void scalehandle_motionhook(t_scalehandle *h,
t_floatarg f1, t_floatarg f2)
{
h->h_motionfn(h,f1-h->h_offset_x,f2-h->h_offset_y);
h->h_motionfn(h,f1,f2);
// Now set the offset to the new mouse position
h->h_offset_x = f1;
h->h_offset_y = f2;
}
void iemgui__clickhook3(t_scalehandle *sh, int newstate) {
......
......@@ -114,7 +114,8 @@ void bng_draw_config(t_bng* x, t_glist* glist)
gui_end_vmess();
}
static void bng__clickhook(t_scalehandle *sh, int newstate)
/* can eventually remove this */
static void bng__clickhook_old(t_scalehandle *sh, int newstate)
{
t_bng *x = (t_bng *)(sh->h_master);
if (sh->h_dragon && newstate == 0 && sh->h_scale)
......@@ -135,18 +136,81 @@ static void bng__clickhook(t_scalehandle *sh, int newstate)
iemgui__clickhook3(sh,newstate);
}
static void bng__clickhook(t_scalehandle *sh, int newstate)
{
t_bng *x = (t_bng *)(sh->h_master);
if (newstate && sh->h_scale)
{
canvas_apply_setundo(x->x_gui.x_glist, (t_gobj *)x);
}
/* not sure we need this anymore... */
else if (newstate == 0 && sh->h_scale)
{
if (sh->h_dragx || sh->h_dragy)
{
x->x_gui.x_w += sh->h_dragx;
x->x_gui.x_h += sh->h_dragy;
canvas_dirty(x->x_gui.x_glist, 1);
}
if (glist_isvisible(x->x_gui.x_glist))
{
bng_draw_move(x, x->x_gui.x_glist);
scalehandle_unclick_scale(sh);
}
}
iemgui__clickhook3(sh,newstate);
}
static void bng__motionhook(t_scalehandle *sh,
t_floatarg f1, t_floatarg f2)
t_floatarg mouse_x, t_floatarg mouse_y)
{
if (sh->h_dragon && sh->h_scale)
if (sh->h_scale)
{
t_bng *x = (t_bng *)(sh->h_master);
int d = maxi((int)f1,(int)f2);
d = maxi(d,IEM_GUI_MINSIZE-x->x_gui.x_w);
int width = x->x_gui.x_w,
height = x->x_gui.x_h;
int x1, y1, x2, y2;
x1 = text_xpix(&x->x_gui.x_obj, x->x_gui.x_glist);
y1 = text_ypix(&x->x_gui.x_obj, x->x_gui.x_glist);
x2 = x1 + width;
y2 = y1 + height;
int d;
if (mouse_x <= x2)
{
if (mouse_y > y2)
d = mouse_y - y2;
else if (abs(mouse_y - y2) < abs(mouse_x - x2))
d = mouse_y - y2;
else
d = mouse_x - x2;
}
else
{
if (mouse_y <= y2)
d = mouse_x - x2;
else
d = maxi(mouse_y - y2, mouse_x - x2);
}
sh->h_dragx = d;
sh->h_dragy = d;
scalehandle_drag_scale(sh);
width = maxi(width + d, IEM_GUI_MINSIZE);
height = width;
x->x_gui.x_w = width;
x->x_gui.x_h = height;
sh->h_offset_x = mouse_x;
sh->h_offset_y = mouse_y;
if (glist_isvisible(x->x_gui.x_glist))
{
bng_draw_move(x, x->x_gui.x_glist);
scalehandle_unclick_scale(sh);
}
int properties = gfxstub_haveproperties((void *)x);
if (properties)
{
......@@ -154,7 +218,7 @@ static void bng__motionhook(t_scalehandle *sh,
properties_set_field_int(properties,"dim.w_ent",new_w);
}
}
scalehandle_dragon_label(sh,f1,f2);
scalehandle_dragon_label(sh,mouse_x,mouse_y);
}
void bng_draw(t_bng *x, t_glist *glist, int mode)
......
......@@ -3385,10 +3385,30 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which,
int noutlet;
int ninlet;
/* resize? only for "true" text boxes or canvases*/
if (!sys_k12_mode && ob && !x->gl_editor->e_textedfor &&
if (ob && ob->te_iemgui && xpos >= x2-4 && ypos > y2-6)
{
if (doit)
{
x->gl_editor->e_onmotion = MA_RESIZE;
x->gl_editor->e_xwas = x1;
x->gl_editor->e_ywas = y1;
x->gl_editor->e_xnew = xpos;
x->gl_editor->e_ynew = ypos;
t_pd *sh = (t_pd *)((t_iemgui *)ob)->x_handle;
pd_vmess(sh, gensym("_click"), "fff",
(t_float)1, (t_float)xpos, (t_float)ypos);
}
else
{
canvas_setcursor(x,
CURSOR_EDITMODE_RESIZE_BOTTOM_RIGHT);
}
canvas_check_nlet_highlights(x);
}
else if (!sys_k12_mode && ob && !x->gl_editor->e_textedfor &&
(ob->te_pd->c_wb == &text_widgetbehavior ||
ob->ob_pd == canvas_class) &&
xpos >= x2-4 && ypos < y2-4 && ypos > y1+4)
ob->ob_pd == canvas_class) &&
xpos >= x2-4 && ypos < y2-4 && ypos > y1+4)
{
if (doit)
{
......@@ -5388,6 +5408,12 @@ void canvas_motion(t_canvas *x, t_floatarg xpos, t_floatarg ypos,
gobj_vis(y1, x, 1);
canvas_dirty(x, 1);
}
else if (ob && ob->te_iemgui)
{
t_pd *sh = (t_pd *)((t_iemgui *)ob)->x_handle;
pd_vmess(sh, gensym("_motion"), "ff", (t_float)xpos, (t_float)ypos);
//pd_vmess(sh, gensym("_click"), "fff", 0, xpos, ypos);
}
else post("not resizable");
}
}
......
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