2 * $Id: rb_animator.c 351 2006-02-10 15:25:40Z tilman $
4 * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 void Init_stack (VALUE *addr);
36 static int on_animator (void *data)
39 RbAnimator *animator = data;
42 /* this fixes a weird segfault that occured when the animator's
43 * callback was called from a Ecore::Timer callback.
50 r = rb_funcall (animator->callback, rb_intern ("call"), 0);
52 /* if the callback returns false, we return 0 and Ecore
53 * will remove the animator
56 animator->deleted = true;
61 static void c_mark (RbAnimator *animator)
63 rb_gc_mark (animator->callback);
66 static void c_free (RbAnimator *animator)
68 if (animator->real && !animator->deleted)
69 ecore_animator_del (animator->real);
76 static VALUE c_alloc (VALUE klass)
78 RbAnimator *animator = NULL;
82 return Data_Make_Struct (klass, RbAnimator, c_mark, c_free, animator);
85 static VALUE c_init (VALUE self)
87 GET_OBJ (self, RbAnimator, animator);
89 if (!rb_block_given_p ())
90 rb_raise (rb_eStandardError, "block missing");
92 animator->callback = rb_block_proc ();
93 animator->deleted = false;
94 animator->real = ecore_animator_add (on_animator, animator);
99 static VALUE c_delete (VALUE self)
101 GET_OBJ (self, RbAnimator, animator);
103 if (animator->real && !animator->deleted) {
104 ecore_animator_del (animator->real);
105 animator->real = NULL;
106 animator->deleted = true;
108 rb_raise (rb_eException, "Animator already deleted!");
113 void Init_Animator (void)
115 VALUE c = rb_define_class_under (mEcore, "Animator", rb_cObject);
117 rb_define_alloc_func (c, c_alloc);
118 rb_define_method (c, "initialize", c_init, 0);
119 rb_define_method (c, "delete", c_delete, 0);