From d11d27f56a611be4523b0caed6da93a4cc5269f6 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Sat, 27 Nov 2004 15:38:52 +0000 Subject: [PATCH] Added Ecore::Animator. --- src/ecore/Makefile.am | 3 +- src/ecore/rb_animator.c | 106 ++++++++++++++++++++++++++++++++++++++++ src/ecore/rb_animator.h | 26 ++++++++++ src/ecore/rb_ecore.c | 4 +- 4 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 src/ecore/rb_animator.c create mode 100644 src/ecore/rb_animator.h diff --git a/src/ecore/Makefile.am b/src/ecore/Makefile.am index be693de..6d481de 100644 --- a/src/ecore/Makefile.am +++ b/src/ecore/Makefile.am @@ -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 index 0000000..6544baa --- /dev/null +++ b/src/ecore/rb_animator.c @@ -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 +#include + +#include + +#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 index 0000000..b0bc3a5 --- /dev/null +++ b/src/ecore/rb_animator.h @@ -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 diff --git a/src/ecore/rb_ecore.c b/src/ecore/rb_ecore.c index f950f7e..4d7190e 100644 --- a/src/ecore/rb_ecore.c +++ b/src/ecore/rb_ecore.c @@ -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 (); -- 2.30.2