From fd0de4e1c0f50ac6a3c502d9004f5796cfdfb302 Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Thu, 12 Aug 2004 10:04:07 +0000 Subject: [PATCH] Added Smart object. --- ChangeLog | 7 ++ Makefile.am | 5 +- src/Makefile.am | 5 +- src/rb_evas_main.c | 4 +- src/rb_smart.c | 176 +++++++++++++++++++++++++++++++++++++++++++++ src/rb_smart.h | 26 +++++++ 6 files changed, 218 insertions(+), 5 deletions(-) create mode 100644 src/rb_smart.c create mode 100644 src/rb_smart.h diff --git a/ChangeLog b/ChangeLog index e69de29..9e99d1b 100644 --- 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 + diff --git a/Makefile.am b/Makefile.am index c4e5c55..ce33779 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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) diff --git a/src/Makefile.am b/src/Makefile.am index 8ef25c4..54af43a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/rb_evas_main.c b/src/rb_evas_main.c index 69307d6..958e877 100644 --- a/src/rb_evas_main.c +++ b/src/rb_evas_main.c @@ -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 index 0000000..366c602 --- /dev/null +++ b/src/rb_smart.c @@ -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 + +#include + +#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 smart. + */ +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 index 0000000..647e70e --- /dev/null +++ b/src/rb_smart.h @@ -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 -- 2.30.2