From 9a39d26529bddefddc276b45becfbce79bb35bf1 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 31 Oct 2007 19:54:41 +0000 Subject: added bang method and made button and wheel events always be reported, not only when polling svn path=/trunk/externals/hcs/; revision=8919 --- cursor-help.pd | 60 ++++++++++++++++++++++++++++++++-------------------------- cursor.c | 36 ++++++++++++++++++++++------------- 2 files changed, 56 insertions(+), 40 deletions(-) diff --git a/cursor-help.pd b/cursor-help.pd index bb9b74f..469280c 100644 --- a/cursor-help.pd +++ b/cursor-help.pd @@ -1,7 +1,5 @@ -#N canvas 446 305 462 312 10; -#X obj 105 271 print LEFT; -#X obj 226 265 print RIGHT; -#X obj 151 96 symbol; +#N canvas 284 234 514 531 10; +#X obj 151 126 symbol; #X msg 149 61 boat; #X msg 109 61 clock; #X msg 245 61 dot; @@ -13,27 +11,35 @@ #X msg 366 109 target; #X msg 366 151 pencil; #X msg 184 61 coffee_mug; -#X msg 151 121 cursor \$1; -#X obj 49 230 pddp/print; -#X obj 186 205 pddp/print; -#X obj 55 132 tgl 15 0 empty empty empty 0 -6 0 10 -262144 -1 -1 0 +#X msg 151 151 cursor \$1; +#X obj 51 334 pddp/print; +#X obj 188 309 pddp/print; +#X obj 147 250 tgl 15 0 empty empty empty 0 -6 0 10 -262144 -1 -1 0 1; -#X obj 124 174 cursor; -#X connect 2 0 14 0; -#X connect 3 0 2 0; -#X connect 4 0 2 0; -#X connect 5 0 2 0; -#X connect 6 0 2 0; -#X connect 7 0 2 0; -#X connect 8 0 2 0; -#X connect 9 0 2 0; -#X connect 10 0 2 0; -#X connect 11 0 2 0; -#X connect 12 0 2 0; -#X connect 13 0 2 0; -#X connect 14 0 18 0; -#X connect 17 0 18 0; -#X connect 18 0 0 0; -#X connect 18 0 15 0; -#X connect 18 1 1 0; -#X connect 18 1 16 0; +#X obj 126 278 cursor; +#X msg 45 218 bang; +#X obj 46 160 key; +#X obj 45 185 select 32; +#X text 163 247 poll the mouse pointer position; +#X text 80 219 get the current mouse position; +#X obj 111 367 print CURSOR; +#X connect 0 0 12 0; +#X connect 1 0 0 0; +#X connect 2 0 0 0; +#X connect 3 0 0 0; +#X connect 4 0 0 0; +#X connect 5 0 0 0; +#X connect 6 0 0 0; +#X connect 7 0 0 0; +#X connect 8 0 0 0; +#X connect 9 0 0 0; +#X connect 10 0 0 0; +#X connect 11 0 0 0; +#X connect 12 0 16 0; +#X connect 15 0 16 0; +#X connect 16 0 13 0; +#X connect 16 0 22 0; +#X connect 16 1 14 0; +#X connect 17 0 16 0; +#X connect 18 0 19 0; +#X connect 19 0 17 0; diff --git a/cursor.c b/cursor.c index 85e8537..cd323d6 100644 --- a/cursor.c +++ b/cursor.c @@ -22,21 +22,23 @@ typedef struct _cursor char *optionv[]; } t_cursor; + +static void cursor_bang(t_cursor *x) +{ + sys_vgui("pd [concat %s motion [winfo pointerx .] [winfo pointery .] \\;]\n", + x->receive_symbol->s_name); +} + static void cursor_float(t_cursor *x, t_float f) { if(f > 0) { - sys_vgui("bind all {+pd [concat %s button %%b 1 \\;]}\n", - x->receive_symbol->s_name); - sys_vgui("bind all {+pd [concat %s button %%b 0 \\;]}\n", - x->receive_symbol->s_name); sys_vgui("bind all {+pd [concat %s motion %%x %%y \\;]}\n", x->receive_symbol->s_name); - sys_vgui("bind all {+pd [concat %s wheel %%D \\;]}\n", - x->receive_symbol->s_name); } else { + /* TODO figure out how to turn off this binding */ } } @@ -94,6 +96,13 @@ static void *cursor_new(t_symbol *s, int argc, t_atom *argv) x->data_outlet = outlet_new(&x->x_obj, 0); x->status_outlet = outlet_new(&x->x_obj, 0); + sys_vgui("bind all {+pd [concat %s button %%b 1 \\;]}\n", + x->receive_symbol->s_name); + sys_vgui("bind all {+pd [concat %s button %%b 0 \\;]}\n", + x->receive_symbol->s_name); + sys_vgui("bind all {+pd [concat %s wheel %%D \\;]}\n", + x->receive_symbol->s_name); + return(x); } @@ -103,18 +112,19 @@ void cursor_setup(void) (t_newmethod)cursor_new, (t_method)cursor_free, sizeof(t_cursor), 0, 0); + class_addbang(cursor_class, (t_method)cursor_bang); class_addfloat(cursor_class, (t_method)cursor_float); + button_symbol = gensym("button"); + motion_symbol = gensym("motion"); + wheel_symbol = gensym("wheel"); + class_addmethod(cursor_class, (t_method)cursor_cursor, gensym("cursor"), A_DEFSYMBOL, 0); class_addmethod(cursor_class, (t_method)cursor_button_callback, - gensym("button"), A_DEFFLOAT, A_DEFFLOAT, 0); + button_symbol, A_DEFFLOAT, A_DEFFLOAT, 0); class_addmethod(cursor_class, (t_method)cursor_motion_callback, - gensym("motion"), A_DEFFLOAT, A_DEFFLOAT, 0); + motion_symbol, A_DEFFLOAT, A_DEFFLOAT, 0); class_addmethod(cursor_class, (t_method)cursor_wheel_callback, - gensym("wheel"), A_DEFFLOAT, 0); - - button_symbol = gensym("button"); - motion_symbol = gensym("motion"); - wheel_symbol = gensym("wheel"); + wheel_symbol, A_DEFFLOAT, 0); } -- cgit v1.2.1