aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cursor-help.pd54
-rw-r--r--cursor.c127
2 files changed, 130 insertions, 51 deletions
diff --git a/cursor-help.pd b/cursor-help.pd
index 9b04a7a..bb9b74f 100644
--- a/cursor-help.pd
+++ b/cursor-help.pd
@@ -1,17 +1,39 @@
-#N canvas 0 22 454 304 10;
-#X msg 178 124 start;
-#X msg 227 124 stop;
-#X obj 142 123 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
-1;
-#X obj 157 151 cursor 80 80;
-#X floatatom 99 242 5 0 0 0 - - -;
-#X floatatom 239 242 5 0 0 0 - - -;
-#X obj 131 258 print LEFT;
+#N canvas 446 305 462 312 10;
+#X obj 105 271 print LEFT;
#X obj 226 265 print RIGHT;
-#X connect 0 0 3 0;
-#X connect 1 0 3 0;
-#X connect 2 0 3 0;
-#X connect 3 0 4 0;
-#X connect 3 0 6 0;
-#X connect 3 1 5 0;
-#X connect 3 1 7 0;
+#X obj 151 96 symbol;
+#X msg 149 61 boat;
+#X msg 109 61 clock;
+#X msg 245 61 dot;
+#X msg 275 61 dotbox;
+#X msg 322 61 gumby;
+#X msg 365 61 gobbler;
+#X msg 366 130 pirate;
+#X msg 366 87 mouse;
+#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
+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;
diff --git a/cursor.c b/cursor.c
index 1a934a0..85e8537 100644
--- a/cursor.c
+++ b/cursor.c
@@ -1,63 +1,120 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <m_pd.h>
+#include <g_canvas.h>
-/* this object should probably register a e_motionfn callback with the root
- * canvas so that it is guaranteed to get the mouse motion data regardless of
- * whether the current canvas is visible. Check g_canvas.h for info.*/
+static t_symbol *button_symbol;
+static t_symbol *motion_symbol;
+static t_symbol *wheel_symbol;
-// list of Tk cursors: http://www.die.net/doc/linux/man/mann/cursors.n.html
-
-#include "m_pd.h"
-#include "g_canvas.h"
+static t_class *cursor_class;
-typedef struct _cursor {
- t_object x_obj;
- t_outlet *x_data_outlet;
- t_outlet *x_status_outlet;
+typedef struct _cursor
+{
+ t_object x_obj;
+ t_symbol *receive_symbol;
+ t_symbol *current_cursor;
+ t_canvas *parent_canvas;
+ t_outlet *data_outlet;
+ t_outlet *status_outlet;
+ t_int optionc;
+ char *optionv[];
} t_cursor;
-t_widgetbehavior cursor_widgetbehavior;
-static t_class *cursor_class;
-
-static void cursor_motion(t_cursor *x, t_floatarg dx, t_floatarg dy)
+static void cursor_float(t_cursor *x, t_float f)
{
+ if(f > 0)
+ {
+ sys_vgui("bind all <ButtonPress> {+pd [concat %s button %%b 1 \\;]}\n",
+ x->receive_symbol->s_name);
+ sys_vgui("bind all <ButtonRelease> {+pd [concat %s button %%b 0 \\;]}\n",
+ x->receive_symbol->s_name);
+ sys_vgui("bind all <Motion> {+pd [concat %s motion %%x %%y \\;]}\n",
+ x->receive_symbol->s_name);
+ sys_vgui("bind all <MouseWheel> {+pd [concat %s wheel %%D \\;]}\n",
+ x->receive_symbol->s_name);
+ }
+ else
+ {
+ }
+}
+static void cursor_cursor(t_cursor *x, t_symbol *s)
+{
+ post("setting cursor: %s", s->s_name);
+ x->current_cursor = s;
+ post("set parent%lx [winfo parent .x%lx.c]; $parent%lx configure -cursor %s \n",
+ x, x->parent_canvas, x, s->s_name);
+ sys_vgui("set parent%lx [winfo parent .x%lx.c]; $parent%lx configure -cursor %s \n",
+ x, x->parent_canvas, x, s->s_name);
}
-static void cursor_bang(t_cursor *x)
+static void cursor_button_callback(t_cursor *x, t_float button, t_float state)
{
+ t_atom output_atoms[2];
+
+ SETFLOAT(output_atoms, button);
+ SETFLOAT(output_atoms + 1, state);
+ outlet_anything(x->data_outlet, button_symbol, 2, output_atoms);
+}
+static void cursor_motion_callback(t_cursor *x, t_float x_position, t_float y_position)
+{
+ t_atom output_atoms[2];
+
+ SETFLOAT(output_atoms, x_position);
+ SETFLOAT(output_atoms + 1, y_position);
+ outlet_anything(x->data_outlet, motion_symbol, 2, output_atoms);
}
-static void cursor_float(t_cursor *x, t_floatarg f)
+static void cursor_wheel_callback(t_cursor *x, t_float f)
{
+ t_atom output_atom;
+
+ SETFLOAT(&output_atom, f);
+ outlet_anything(x->data_outlet, wheel_symbol, 1, &output_atom);
+}
+static void cursor_free(t_cursor *x)
+{
+ pd_unbind(&x->x_obj.ob_pd, x->receive_symbol);
}
static void *cursor_new(t_symbol *s, int argc, t_atom *argv)
{
+ char buf[MAXPDSTRING];
t_cursor *x = (t_cursor *)pd_new(cursor_class);
+ x->parent_canvas = canvas_getcurrent();
- return (x);
-}
-
-static void cursor_free(t_cursor *x)
-{
+ sprintf(buf, "#%lx", (t_int)x);
+ x->receive_symbol = gensym(buf);
+ pd_bind(&x->x_obj.ob_pd, x->receive_symbol);
+ x->data_outlet = outlet_new(&x->x_obj, 0);
+ x->status_outlet = outlet_new(&x->x_obj, 0);
+ return(x);
}
void cursor_setup(void)
{
- cursor_class = class_new(gensym("cursor"), (t_newmethod)cursor_new,
- (t_method)cursor_free, sizeof(t_cursor), 0, A_GIMME, 0);
- class_addbang(cursor_class, cursor_bang);
- class_addfloat(cursor_class, cursor_float);
-
- cursor_widgetbehavior.w_getrectfn = NULL;
- cursor_widgetbehavior.w_displacefn = NULL;
- cursor_widgetbehavior.w_selectfn = NULL;
- cursor_widgetbehavior.w_activatefn = NULL;
- cursor_widgetbehavior.w_deletefn = NULL;
- cursor_widgetbehavior.w_visfn = NULL;
- cursor_widgetbehavior.w_clickfn = NULL;
- class_setwidget(cursor_class, &cursor_widgetbehavior);
+ cursor_class = class_new(gensym("cursor"),
+ (t_newmethod)cursor_new, (t_method)cursor_free,
+ sizeof(t_cursor), 0, 0);
+
+ class_addfloat(cursor_class, (t_method)cursor_float);
+
+ 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);
+ class_addmethod(cursor_class, (t_method)cursor_motion_callback,
+ gensym("motion"), 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");
}