From 5e566ff6dc37ccfdad0571dd34867cbf1cdd8cbc Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Mon, 14 Mar 2005 21:54:32 +0000 Subject: [PATCH] Fleshed out the mouse_move event. --- src/rb_evas_object_events.c | 56 +++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/src/rb_evas_object_events.c b/src/rb_evas_object_events.c index 2ac56fa..71c087a 100644 --- a/src/rb_evas_object_events.c +++ b/src/rb_evas_object_events.c @@ -1,5 +1,5 @@ /* - * $Id: rb_evas_object_events.c 281 2005-03-14 20:51:40Z tilman $ + * $Id: rb_evas_object_events.c 282 2005-03-14 21:54:32Z tilman $ * * Copyright (C) 2005 Tilman Sauerbeck (tilman at code-monkey de) * @@ -36,7 +36,7 @@ \ s = rb_str_new2 (#name); \ klass = rb_hash_aref (event_classes, s); \ - ev = rb_class_new_instance(1, argv, klass); \ + ev = rb_class_new_instance (1, argv, klass); \ cb = rb_hash_aref (e->callbacks, s); \ \ rb_funcall (cb, rb_intern ("call"), 1, ev); \ @@ -58,12 +58,12 @@ #define CALLBACK_REGISTER(name, clsname) \ rb_define_method (cEvasObject, "on_"#name, c_on_##name, 0); \ \ - c = rb_define_class_under (mEvas, (clsname), rb_cObject); \ + c = rb_define_class_under (mEvas, (clsname), cEvent); \ rb_define_private_method (rb_singleton_class (c), "new", NULL, 0); \ rb_define_private_method (c, "initialize", c_ev_##name##_init, 1); \ rb_hash_aset (event_classes, rb_str_new2 (#name), c); -static VALUE event_classes; +static VALUE event_classes, cPos; static VALUE c_ev_mouse_down_init (VALUE self, VALUE ev) { @@ -85,8 +85,24 @@ static VALUE c_ev_mouse_up_init (VALUE self, VALUE ev) static VALUE c_ev_mouse_move_init (VALUE self, VALUE ev) { + VALUE argv[4]; Evas_Event_Mouse_Move *e = (Evas_Event_Mouse_Move *) ev; + argv[0] = INT2FIX ((int) e->cur.output.x); + argv[1] = INT2FIX ((int) e->cur.output.y); + argv[2] = INT2FIX ((int) e->cur.canvas.x); + argv[3] = INT2FIX ((int) e->cur.canvas.y); + + rb_iv_set (self, "@current", + rb_class_new_instance (4, argv, cPos)); + + argv[0] = INT2FIX ((int) e->prev.output.x); + argv[1] = INT2FIX ((int) e->prev.output.y); + argv[2] = INT2FIX ((int) e->prev.canvas.x); + argv[3] = INT2FIX ((int) e->prev.canvas.y); + + rb_iv_set (self, "@previous", + rb_class_new_instance (4, argv, cPos)); rb_iv_set (self, "@buttons", INT2FIX (e->buttons)); return self; @@ -111,13 +127,41 @@ static VALUE c_on_mouse_move (VALUE self) CALLBACK_HANDLER_METHOD (mouse_move, MOUSE_MOVE); } +static VALUE c_ev_init (VALUE self) +{ + return self; +} + +static VALUE c_pos_init (VALUE self, VALUE output_x, VALUE output_y, + VALUE canvas_x, VALUE canvas_y) +{ + rb_iv_set (self, "@output_x", output_x); + rb_iv_set (self, "@output_y", output_y); + rb_iv_set (self, "@canvas_x", canvas_x); + rb_iv_set (self, "@canvas_y", canvas_y); + + return self; +} + void Init_EvasObjectEvents (void) { - VALUE c; + VALUE cEvent, c; event_classes = rb_hash_new (); rb_global_variable (&event_classes); + cEvent = rb_define_class_under (mEvas, "EvasObjectEvent", rb_cObject); + rb_define_private_method (rb_singleton_class (cEvent), "new", NULL, 0); + rb_define_private_method (cEvent, "initialize", c_ev_init, 0); + + cPos = rb_define_class_under (cEvent, "Position", rb_cObject); + rb_define_private_method (rb_singleton_class (cPos), "new", NULL, 0); + rb_define_private_method (cPos, "initialize", c_pos_init, 4); + rb_define_attr (cPos, "output_x", 1, 0); + rb_define_attr (cPos, "output_y", 1, 0); + rb_define_attr (cPos, "canvas_x", 1, 0); + rb_define_attr (cPos, "canvas_y", 1, 0); + CALLBACK_REGISTER (mouse_down, "MouseDownEvent"); rb_define_attr (c, "button", 1, 0); @@ -125,5 +169,7 @@ void Init_EvasObjectEvents (void) rb_define_attr (c, "button", 1, 0); CALLBACK_REGISTER (mouse_move, "MouseMoveEvent"); + rb_define_attr (c, "current", 1, 0); + rb_define_attr (c, "previous", 1, 0); rb_define_attr (c, "buttons", 1, 0); } -- 2.30.2