Added Ecore::Animator.
authorTilman Sauerbeck <tilman@code-monkey.de>
Sat, 27 Nov 2004 15:38:52 +0000 (15:38 +0000)
committerTilman Sauerbeck <tilman@code-monkey.de>
Sat, 27 Nov 2004 15:38:52 +0000 (15:38 +0000)
src/ecore/Makefile.am
src/ecore/rb_animator.c [new file with mode: 0644]
src/ecore/rb_animator.h [new file with mode: 0644]
src/ecore/rb_ecore.c

index be693deac4a9bce2688bcf5ed1c6f664a121278d..6d481def67e801970b1834ef4d70fe5a660b9af3 100644 (file)
@@ -1,4 +1,4 @@
-## $Id: Makefile.am 120 2004-10-18 20:23:32Z tilman $
+## $Id: Makefile.am 146 2004-11-27 15:38:52Z tilman $
 
 AM_CFLAGS = $(ECORE_CFLAGS)
 INCLUDES = -I$(RUBYDIR)
@@ -9,6 +9,7 @@ extdir = $(RUBYSITEDIR)
 ecore_la_SOURCES = rb_ecore.c rb_ecore.h \
                    rb_idler.c rb_idler.h \
                    rb_timer.c rb_timer.h \
+                   rb_animator.c rb_animator.h \
                    rb_event_handler.c rb_event_handler.h \
                    rb_fd_handler.c rb_fd_handler.h
 
diff --git a/src/ecore/rb_animator.c b/src/ecore/rb_animator.c
new file mode 100644 (file)
index 0000000..6544baa
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * $Id: rb_animator.c 146 2004-11-27 15:38:52Z tilman $
+ *
+ * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
+ *
+ * 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 <Ecore.h>
+
+#include "rb_ecore.h"
+
+typedef struct {
+       Ecore_Animator *real;
+       VALUE callback;
+       bool deleted;
+} RbAnimator;
+
+static int on_animator (void *data)
+{
+       VALUE r;
+       RbAnimator *animator = data;
+
+       r = rb_funcall (animator->callback, rb_intern ("call"), 0);
+
+       /* if the callback returns false, we return 0 and Ecore
+        * will remove the animator
+        */
+       if (r == Qfalse)
+               animator->deleted = true;
+
+       return (r != Qfalse);
+}
+
+static void c_mark (RbAnimator *animator)
+{
+       rb_gc_mark (animator->callback);
+}
+
+static void c_free (RbAnimator *animator)
+{
+       if (animator->real && !animator->deleted)
+               ecore_animator_del (animator->real);
+
+       ecore_shutdown ();
+
+       free (animator);
+}
+
+static VALUE c_new (VALUE klass)
+{
+       VALUE self;
+       RbAnimator *animator = NULL;
+
+       if (!rb_block_given_p ())
+               return Qnil;
+
+       self = Data_Make_Struct (klass, RbAnimator, c_mark, c_free, animator);
+
+       ecore_init ();
+
+       animator->callback = rb_block_proc ();
+       animator->deleted = false;
+       animator->real = ecore_animator_add (on_animator, animator);
+
+       rb_obj_call_init (self, 0, NULL);
+
+       return self;
+}
+
+static VALUE c_delete (VALUE self)
+{
+       GET_OBJ (self, RbAnimator, animator);
+
+       if (animator->real && !animator->deleted) {
+               ecore_animator_del (animator->real);
+               animator->real = NULL;
+               animator->deleted = true;
+       } else
+               rb_raise (rb_eException, "Animator already deleted!");
+
+       return Qnil;
+}
+
+void Init_Animator (void)
+{
+       VALUE c = rb_define_class_under (mEcore, "Animator", rb_cObject);
+
+       rb_define_singleton_method (c, "new", c_new, 0);
+       rb_define_method (c, "delete", c_delete, 0);
+}
diff --git a/src/ecore/rb_animator.h b/src/ecore/rb_animator.h
new file mode 100644 (file)
index 0000000..b0bc3a5
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * $Id: rb_animator.h 146 2004-11-27 15:38:52Z tilman $
+ *
+ * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
+ *
+ * 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_ANIMATOR_H
+#define __RB_ANIMATOR_H
+
+void Init_Animator (void);
+
+#endif
index f950f7e0079f3a0e2fac96a50fb77b0b400e00da..4d7190e6140f31c885470c7ca85c1c6d87cb6b4c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_ecore.c 109 2004-09-01 20:33:15Z tilman $
+ * $Id: rb_ecore.c 146 2004-11-27 15:38:52Z tilman $
  *
  * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
  *
@@ -25,6 +25,7 @@
 #define __RB_ECORE_C
 #include "rb_ecore.h"
 #include "rb_timer.h"
+#include "rb_animator.h"
 #include "rb_idler.h"
 #include "rb_event_handler.h"
 #include "rb_fd_handler.h"
@@ -142,6 +143,7 @@ void Init_ecore (void)
                                   m_main_loop_quit, 0);
 
        Init_Timer ();
+       Init_Animator ();
        Init_Idler ();
        Init_EventHandler ();
        Init_FdHandler ();