Started EvasObject callback implementation.
authorTilman Sauerbeck <tilman@code-monkey.de>
Mon, 14 Mar 2005 20:51:40 +0000 (20:51 +0000)
committerTilman Sauerbeck <tilman@code-monkey.de>
Mon, 14 Mar 2005 20:51:40 +0000 (20:51 +0000)
ChangeLog
src/Makefile.am
src/rb_evas_main.c
src/rb_evas_object.c
src/rb_evas_object.h
src/rb_evas_object_events.c [new file with mode: 0644]
src/rb_evas_object_events.h [new file with mode: 0644]

index 519b521852adc8fb0736683bd6618becb78dbeca..10241685004b5de4691b92ac4e406270473bb7a7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
-$Id: ChangeLog 63 2004-08-12 19:36:40Z tilman $
+$Id: ChangeLog 281 2005-03-14 20:51:40Z tilman $
+
+2005-03-14 Tilman Sauerbeck (tilman at code-monkey de)
+        * src/Makefile.am, src/rb_evas_object_events.[ch],
+          src/rb_evas_main.c, src/rb_evas_object.[ch]: Started EvasObject
+          callback implementation
 
 2004-08-12 Tilman Sauerbeck (tilman at code-monkey de)
         * Makefile.am, src/Makefile.am, src/rb_evas_main.c,
index 860f5b83aca5248511a71801aed8be4f51edb3cb..d1e46b0e7700f0c08fc283b4a212e630d1f43f5a 100644 (file)
@@ -1,4 +1,4 @@
-## $Id: Makefile.am 118 2004-10-18 20:16:11Z tilman $
+## $Id: Makefile.am 281 2005-03-14 20:51:40Z tilman $
 
 AM_CFLAGS = $(EVAS_CFLAGS)
 INCLUDES = -I$(RUBYDIR)
@@ -9,6 +9,7 @@ extdir = $(RUBYSITEDIR)
 evas_la_SOURCES = rb_evas_main.c rb_evas_main.h \
                   rb_evas.c rb_evas.h \
                   rb_evas_object.c rb_evas_object.h \
+                  rb_evas_object_events.c rb_evas_object_events.h \
                   rb_rectangle.c rb_rectangle.h \
                   rb_line.c rb_line.h \
                   rb_gradient.c rb_gradient.h \
index 958e87719b00b8d5d0959b7a372a1402a971aac7..1c8b812c414022bb48eee53ffda7a89ff96f23d4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_evas_main.c 61 2004-08-12 10:04:07Z tilman $
+ * $Id: rb_evas_main.c 281 2005-03-14 20:51:40Z tilman $
  *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
@@ -25,6 +25,7 @@
 #include "rb_evas_main.h"
 #include "rb_evas.h"
 #include "rb_evas_object.h"
+#include "rb_evas_object_events.h"
 #include "rb_rectangle.h"
 #include "rb_line.h"
 #include "rb_gradient.h"
@@ -39,6 +40,7 @@ void Init_evas (void)
 
        Init_Evas ();
        Init_EvasObject ();
+       Init_EvasObjectEvents ();
        Init_Rectangle ();
        Init_Line ();
        Init_Gradient ();
index 4487d1d3d25fef660f0fb12b6c30d5f063f0ba39..b32f2b8ebf5c4d425b740dc8364aa88e7b012f3f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_evas_object.c 106 2004-08-29 15:56:35Z tilman $
+ * $Id: rb_evas_object.c 281 2005-03-14 20:51:40Z tilman $
  *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
@@ -49,6 +49,7 @@ VALUE TO_EVAS_OBJECT (Evas_Object *o)
 void c_evas_object_mark (RbEvasObject *e)
 {
        rb_gc_mark (e->parent);
+       rb_gc_mark (e->callbacks);
 }
 
 void c_evas_object_free (RbEvasObject *e, bool free_mem)
@@ -68,6 +69,7 @@ static VALUE c_init (VALUE self, VALUE parent)
        evas_object_data_set (e->real, RUBY_EVAS_OBJECT_KEY, (void *) self);
 
        e->parent = parent;
+       e->callbacks = rb_hash_new ();
 
        return self;
 }
index 91a90c5a18052d39b9b8257022d17b68c5ef3640..ae60574bea8915b3d7d7efe66768872703040914 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_evas_object.h 68 2004-08-16 15:42:19Z tilman $
+ * $Id: rb_evas_object.h 281 2005-03-14 20:51:40Z tilman $
  *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
@@ -28,6 +28,7 @@
 typedef struct {
        Evas_Object *real;
        VALUE parent;
+       VALUE callbacks;
 } RbEvasObject;
 
 void Init_EvasObject (void);
diff --git a/src/rb_evas_object_events.c b/src/rb_evas_object_events.c
new file mode 100644 (file)
index 0000000..2ac56fa
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * $Id: rb_evas_object_events.c 281 2005-03-14 20:51:40Z tilman $
+ *
+ * Copyright (C) 2005 Tilman Sauerbeck (tilman at code-monkey de)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <ruby.h>
+#include <stdbool.h>
+
+#include <Evas.h>
+
+#include "rb_evas_main.h"
+#include "rb_evas.h"
+#include "rb_evas_object.h"
+
+#define CALLBACK_HANDLER_FUNC(name) \
+       static void on_##name (void *data, Evas *evas, \
+                              Evas_Object *evas_obj, void *event) \
+{ \
+       RbEvasObject *e = (RbEvasObject *) data; \
+       VALUE argv[1] = {(VALUE) event}, klass, cb, ev, s; \
+\
+       s = rb_str_new2 (#name); \
+       klass = rb_hash_aref (event_classes, s); \
+       ev = rb_class_new_instance(1, argv, klass); \
+       cb = rb_hash_aref (e->callbacks, s); \
+\
+       rb_funcall (cb, rb_intern ("call"), 1, ev); \
+}
+
+#define CALLBACK_HANDLER_METHOD(name, callback) \
+       GET_OBJ (self, RbEvasObject, e); \
+\
+       if (!rb_block_given_p ()) \
+               return Qnil; \
+\
+       rb_hash_aset (e->callbacks, rb_str_new2 (#name), \
+                     rb_block_proc ()); \
+       evas_object_event_callback_add (e->real, EVAS_CALLBACK_##callback, \
+                                       on_##name, e); \
+\
+       return Qnil;
+
+#define CALLBACK_REGISTER(name, clsname) \
+       rb_define_method (cEvasObject, "on_"#name, c_on_##name, 0); \
+\
+       c = rb_define_class_under (mEvas, (clsname), rb_cObject); \
+       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 c_ev_mouse_down_init (VALUE self, VALUE ev)
+{
+       Evas_Event_Mouse_Down *e = (Evas_Event_Mouse_Down *) ev;
+
+       rb_iv_set (self, "@button", INT2FIX (e->button));
+
+       return self;
+}
+
+static VALUE c_ev_mouse_up_init (VALUE self, VALUE ev)
+{
+       Evas_Event_Mouse_Up *e = (Evas_Event_Mouse_Up *) ev;
+
+       rb_iv_set (self, "@button", INT2FIX (e->button));
+
+       return self;
+}
+
+static VALUE c_ev_mouse_move_init (VALUE self, VALUE ev)
+{
+       Evas_Event_Mouse_Move *e = (Evas_Event_Mouse_Move *) ev;
+
+       rb_iv_set (self, "@buttons", INT2FIX (e->buttons));
+
+       return self;
+}
+
+CALLBACK_HANDLER_FUNC (mouse_down);
+CALLBACK_HANDLER_FUNC (mouse_up);
+CALLBACK_HANDLER_FUNC (mouse_move);
+
+static VALUE c_on_mouse_down (VALUE self)
+{
+       CALLBACK_HANDLER_METHOD (mouse_down, MOUSE_DOWN);
+}
+
+static VALUE c_on_mouse_up (VALUE self)
+{
+       CALLBACK_HANDLER_METHOD (mouse_up, MOUSE_UP);
+}
+
+static VALUE c_on_mouse_move (VALUE self)
+{
+       CALLBACK_HANDLER_METHOD (mouse_move, MOUSE_MOVE);
+}
+
+void Init_EvasObjectEvents (void)
+{
+       VALUE c;
+
+       event_classes = rb_hash_new ();
+       rb_global_variable (&event_classes);
+
+       CALLBACK_REGISTER (mouse_down, "MouseDownEvent");
+       rb_define_attr (c, "button", 1, 0);
+
+       CALLBACK_REGISTER (mouse_up, "MouseUpEvent");
+       rb_define_attr (c, "button", 1, 0);
+
+       CALLBACK_REGISTER (mouse_move, "MouseMoveEvent");
+       rb_define_attr (c, "buttons", 1, 0);
+}
diff --git a/src/rb_evas_object_events.h b/src/rb_evas_object_events.h
new file mode 100644 (file)
index 0000000..69d42b3
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * $Id: rb_evas_object_events.h 281 2005-03-14 20:51:40Z tilman $
+ *
+ * Copyright (C) 2005 Tilman Sauerbeck (tilman at code-monkey de)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __RB_EVAS_OBJECT_EVENTS_H
+#define __RB_EVAS_OBJECT_EVENTS_H
+
+void Init_EvasObjectEvents (void);
+
+#endif