2 * Copyright (C) 2004 ruby-ecore team (see AUTHORS)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 void Init_stack (VALUE *addr);
34 static int on_animator (void *data)
37 RbAnimator *animator = data;
40 /* this fixes a weird segfault that occured when the animator's
41 * callback was called from a Ecore::Timer callback.
48 r = rb_funcall (animator->callback, rb_intern ("call"), 0);
50 /* if the callback returns false, we return 0 and Ecore
51 * will remove the animator
54 animator->deleted = true;
59 static void c_mark (RbAnimator *animator)
61 rb_gc_mark (animator->callback);
64 static void c_free (RbAnimator *animator)
66 if (animator->real && !animator->deleted)
67 ecore_animator_del (animator->real);
74 static VALUE c_alloc (VALUE klass)
76 RbAnimator *animator = NULL;
80 return Data_Make_Struct (klass, RbAnimator, c_mark, c_free, animator);
83 static VALUE c_init (VALUE self)
85 GET_OBJ (self, RbAnimator, animator);
87 if (!rb_block_given_p ())
88 rb_raise (rb_eStandardError, "block missing");
90 animator->callback = rb_block_proc ();
91 animator->deleted = false;
92 animator->real = ecore_animator_add (on_animator, animator);
97 static VALUE c_delete (VALUE self)
99 GET_OBJ (self, RbAnimator, animator);
101 if (animator->real && !animator->deleted) {
102 ecore_animator_del (animator->real);
103 animator->real = NULL;
104 animator->deleted = true;
106 rb_raise (rb_eException, "Animator already deleted!");
111 void Init_Animator (void)
113 VALUE c = rb_define_class_under (mEcore, "Animator", rb_cObject);
115 rb_define_alloc_func (c, c_alloc);
116 rb_define_method (c, "initialize", c_init, 0);
117 rb_define_method (c, "delete", c_delete, 0);