Added Smart object.
authorTilman Sauerbeck <tilman@code-monkey.de>
Thu, 12 Aug 2004 10:04:07 +0000 (10:04 +0000)
committerTilman Sauerbeck <tilman@code-monkey.de>
Thu, 12 Aug 2004 10:04:07 +0000 (10:04 +0000)
ChangeLog
Makefile.am
src/Makefile.am
src/rb_evas_main.c
src/rb_smart.c [new file with mode: 0644]
src/rb_smart.h [new file with mode: 0644]

index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..9e99d1b0242c9d10915eca65589a7c58f0a62d4c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -0,0 +1,7 @@
+$Id: ChangeLog 61 2004-08-12 10:04:07Z tilman $
+
+2004-08-12 Tilman Sauerbeck (tilman at code-monkey de)
+        * Makefile.am, src/Makefile.am, src/rb_evas_main.c,
+          src/rb_smart.[ch]:
+          Added Smart object
+
index c4e5c556d266d1cef22ceaa94342fc9a65ea8598..ce337798706fd40c28c1015c7af93f2253f40ba0 100644 (file)
@@ -1,4 +1,4 @@
-## $Id: Makefile.am 58 2004-08-10 14:10:02Z tilman $
+## $Id: Makefile.am 61 2004-08-12 10:04:07Z tilman $
 
 SUBDIRS = m4 src
 DOC_INPUT = src/rb_evas_main.c \
@@ -8,7 +8,8 @@ DOC_INPUT = src/rb_evas_main.c \
             src/rb_line.c \
             src/rb_polygon.c \
             src/rb_rectangle.c \
-            src/rb_text.c
+            src/rb_text.c \
+            src/rb_smart.c
 
 doc: $(DOC_INPUT)
        rdoc $(DOC_INPUT)
index 8ef25c4a5266d4027e5d918a47c0988d99f200e3..54af43af30d19dc3eb5ca6c4c5d6e6e5ab37f1ee 100644 (file)
@@ -1,4 +1,4 @@
-## $Id: Makefile.am 49 2004-08-01 10:17:39Z tilman $
+## $Id: Makefile.am 61 2004-08-12 10:04:07Z tilman $
 
 AM_CFLAGS = $(EVAS_CFLAGS)
 INCLUDES = -I$(RUBYDIR)
@@ -14,7 +14,8 @@ evas_la_SOURCES = rb_evas_main.c rb_evas_main.h \
                   rb_gradient.c rb_gradient.h \
                   rb_polygon.c rb_polygon.h \
                   rb_image.c rb_image.h \
-                  rb_text.c rb_text.h
+                  rb_text.c rb_text.h \
+                  rb_smart.c rb_smart.h
 
 evas_la_LIBADD = -lruby $(EVAS_LIBS)
 evas_la_LDFLAGS = -module -avoid-version
index 69307d68b758d0916a4e633472d916846b1ee703..958e87719b00b8d5d0959b7a372a1402a971aac7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_evas_main.c 55 2004-08-09 10:55:08Z tilman $
+ * $Id: rb_evas_main.c 61 2004-08-12 10:04:07Z tilman $
  *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
@@ -31,6 +31,7 @@
 #include "rb_polygon.h"
 #include "rb_image.h"
 #include "rb_text.h"
+#include "rb_smart.h"
 
 void Init_evas (void)
 {
@@ -44,4 +45,5 @@ void Init_evas (void)
        Init_Polygon ();
        Init_Image ();
        Init_Text ();
+       Init_Smart ();
 }
diff --git a/src/rb_smart.c b/src/rb_smart.c
new file mode 100644 (file)
index 0000000..366c602
--- /dev/null
@@ -0,0 +1,176 @@
+/*
+ * $Id: rb_smart.c 61 2004-08-12 10:04:07Z tilman $
+ *
+ * Copyright (C) 2004 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 <Evas.h>
+
+#include "rb_evas_main.h"
+#include "rb_evas.h"
+#include "rb_evas_object.h"
+
+#define RUBY_EVAS_SMART_OBJECT_KEY "__RB_EVAS_OBJECT_SMART_OBJECT"
+
+#define GET_EVAS_OBJECT(obj, o) \
+       VALUE (obj); \
+\
+       obj = (VALUE) evas_object_data_get (o, \
+                                           RUBY_EVAS_SMART_OBJECT_KEY); \
+       if (!obj) { \
+               rb_raise (rb_eException, \
+                         "EvasObject Ruby object key missing"); \
+               return; \
+       }
+
+#define SMART_CB_BODY(name) \
+       static ID id; \
+\
+       GET_EVAS_OBJECT (self, o); \
+\
+       if (!id) \
+               id = rb_intern ("on_"#name); \
+\
+       if (!rb_respond_to (self, id)) \
+               return;
+
+#define SMART_CB(name) \
+       static void on_##name (Evas_Object *o) \
+       { \
+               SMART_CB_BODY (name); \
+               rb_funcall (self, id, 0); \
+       }
+
+#define SMART_CB_OBJ(name) \
+       static void on_##name (Evas_Object *o, Evas_Object *other) \
+       { \
+               void *obj; \
+\
+               SMART_CB_BODY (name); \
+\
+               obj = evas_object_data_get (other, RUBY_EVAS_OBJECT_KEY); \
+               if (!obj) { \
+                       rb_raise (rb_eException, "EvasObject Ruby object key missing"); \
+                       return; \
+               } \
+\
+               rb_funcall (self, id, 1, (VALUE) obj); \
+       }
+
+#define SMART_CB_COORD(name) \
+       static void on_##name (Evas_Object *o, Evas_Coord a, Evas_Coord b) \
+       { \
+               SMART_CB_BODY (name); \
+               rb_funcall (self, id, 2, INT2FIX ((int) a), INT2FIX ((int) b)); \
+       }
+
+SMART_CB (delete);
+SMART_CB (raise);
+SMART_CB (lower);
+SMART_CB (show);
+SMART_CB (hide);
+SMART_CB (clip_unset);
+SMART_CB_OBJ (stack_above);
+SMART_CB_OBJ (stack_below);
+SMART_CB_OBJ (clip_set);
+SMART_CB_COORD (move);
+SMART_CB_COORD (resize);
+
+static void on_layer_set (Evas_Object *o, int layer)
+{
+       SMART_CB_BODY (layer_set);
+
+       rb_funcall (self, id, 1, FIX2INT (layer));
+}
+
+static void on_color_set (Evas_Object *o, int r, int g, int b, int a)
+{
+       SMART_CB_BODY (color_set);
+
+       rb_funcall (self, id, 4, INT2FIX (r), INT2FIX (g), INT2FIX (b),
+                   INT2FIX (a));
+}
+
+/*
+ * call-seq:
+ *  Evas::Smart.new(name) => smart
+ *
+ * Creates a Evas::Smart object with the given name.
+ */
+static VALUE c_new (VALUE klass, VALUE name)
+{
+       VALUE self;
+       Evas_Smart **smart;
+
+       Check_Type (name, T_STRING);
+
+       self = Data_Make_Struct (klass, Evas_Smart *, NULL, free, smart);
+       *smart = evas_smart_new (StringValuePtr (name),
+                                NULL, on_delete, on_layer_set,
+                                on_raise, on_lower, on_stack_above,
+                                on_stack_below, on_move, on_resize,
+                                on_show, on_hide, on_color_set,
+                                on_clip_set, on_clip_unset, NULL);
+
+       rb_obj_call_init (self, 0, NULL);
+
+       return self;
+}
+
+static void c_object_free (RbEvasObject *e)
+{
+       c_evas_object_free (e, true);
+}
+
+/*
+ * call-seq:
+ *  smart.new_object(class, evas) => smart_obj
+ *
+ * Creates a Evas::EvasObject from <i>smart</i>.
+ */
+static VALUE c_new_object (VALUE self, VALUE klass, VALUE evas)
+{
+       VALUE obj, argv[1];
+       RbEvasObject *smart;
+
+       CHECK_CLASS (evas, cEvas);
+       GET_OBJ (evas, RbEvas, e);
+
+       GET_OBJ (self, Evas_Smart *, s);
+
+       obj = Data_Make_Struct (klass, RbEvasObject, c_evas_object_mark,
+                               c_object_free, smart);
+       smart->real = evas_object_smart_add (e->real, *s);
+
+       evas_object_data_set (smart->real, RUBY_EVAS_SMART_OBJECT_KEY,
+                             (void *) obj);
+
+       argv[0] = evas;
+       rb_obj_call_init (obj, 1, argv);
+
+       return obj;
+}
+
+void Init_Smart (void)
+{
+       VALUE c = rb_define_class_under (mEvas, "Smart", rb_cObject);
+
+       rb_define_singleton_method (c, "new", c_new, 1);
+       rb_define_method (c, "new_object", c_new_object, 2);
+}
diff --git a/src/rb_smart.h b/src/rb_smart.h
new file mode 100644 (file)
index 0000000..647e70e
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * $Id: rb_smart.h 61 2004-08-12 10:04:07Z tilman $
+ *
+ * Copyright (C) 2004 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_SMART_H
+#define __RB_SMART_H
+
+void Init_Smart (void);
+
+#endif