aboutsummaryrefslogtreecommitdiff
path: root/cursor.c
diff options
context:
space:
mode:
authorHans-Christoph Steiner <eighthave@users.sourceforge.net>2007-10-31 07:12:11 +0000
committerHans-Christoph Steiner <eighthave@users.sourceforge.net>2007-10-31 07:12:11 +0000
commit300914553d7e70cc7265db078e5730e159b9b2da (patch)
treeaddfb0cd1d4669cf0054ca51afadc05b2d2c0326 /cursor.c
parent9226becd95c6f3be2efb7fc96e89590a3dc66088 (diff)
first working sketch of the cursor object getting data from the system mouse pointer; It works, but it only reports for the current canvas, not all teh time. I need to dive in deeper to Krzysztof's tricks
svn path=/trunk/externals/hcs/; revision=8912
Diffstat (limited to 'cursor.c')
-rw-r--r--cursor.c127
1 files changed, 92 insertions, 35 deletions
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");
}