Lots of new stuff.
[ruby-evas.git] / src / rb_evas.c
index 2ba53d174d0f8c5b1f0f9c74ff47fd6acdcd9644..dfb949aec2c2e0ec12417fd7c02a93daa3abac50 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_evas.c 2 2004-06-19 18:55:39Z tilman $
+ * $Id: rb_evas.c 20 2004-06-22 20:46:56Z tilman $
  *
  * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
  *
 
 #include <Evas.h>
 
+#include "rb_evas_main.h"
+#include "rb_evas.h"
 #include "rb_evas_object.h"
 
-VALUE cEvas;
+#define GET_OBJ(obj, type, o, desc) \
+       type **(o) = NULL; \
+\
+       Data_Get_Struct ((obj), type *, (o)); \
+\
+       if (!*(o)) { \
+               rb_raise (rb_eException, desc " destroyed already"); \
+               return Qnil; \
+       }
+
 static VALUE parents;
 
 static void c_mark (Evas **e)
@@ -55,16 +66,199 @@ VALUE TO_EVAS (VALUE parent, Evas *e)
        return self;
 }
 
-void Init_evas (void)
+static VALUE c_font_path_clear (VALUE self)
+{
+       GET_OBJ (self, Evas, e, "Evas");
+
+       evas_font_path_clear (*e);
+
+       return Qnil;
+}
+
+static VALUE c_font_path_append (VALUE self, VALUE path)
+{
+       GET_OBJ (self, Evas, e, "Evas");
+
+       Check_Type (path, T_STRING);
+
+       evas_font_path_append (*e, StringValuePtr (path));
+
+       return Qnil;
+}
+
+static VALUE c_font_path_prepend (VALUE self, VALUE path)
 {
-       cEvas = rb_define_class ("Evas", rb_cObject);
+       GET_OBJ (self, Evas, e, "Evas");
+
+       Check_Type (path, T_STRING);
+
+       evas_font_path_append (*e, StringValuePtr (path));
+
+       return Qnil;
+}
+
+static VALUE c_font_path_get (VALUE self)
+{
+       VALUE ary;
+       const Evas_List *list, *l;
+
+       GET_OBJ (self, Evas, e, "Evas");
+
+       if (!(list = evas_font_path_list (*e)))
+               return rb_ary_new ();
+
+       ary = rb_ary_new2 (evas_list_count ((Evas_List *) list));
+
+       for (l = list; l; l = l->next)
+               rb_ary_push (ary, rb_str_new2 (l->data));
+
+       return ary;
+}
+
+static VALUE c_font_cache_get (VALUE self)
+ {
+       GET_OBJ (self, Evas, e, "Evas");
+
+       return INT2FIX (evas_font_cache_get (*e));
+}
+
+static VALUE c_font_cache_set (VALUE self, VALUE val)
+{
+       GET_OBJ (self, Evas, e, "Evas");
+
+       Check_Type (val, T_FIXNUM);
+
+       evas_font_cache_set (*e, FIX2INT (val));
+
+       return Qnil;
+}
+
+static VALUE c_font_cache_flush (VALUE self)
+{
+       GET_OBJ (self, Evas, e, "Evas");
+
+       evas_font_cache_flush (*e);
+
+       return Qnil;
+}
+
+static VALUE c_image_cache_get (VALUE self)
+{
+       GET_OBJ (self, Evas, e, "Evas");
+
+       return INT2FIX (evas_image_cache_get (*e));
+}
+
+static VALUE c_image_cache_set (VALUE self, VALUE val)
+{
+       GET_OBJ (self, Evas, e, "Evas");
+
+       Check_Type (val, T_FIXNUM);
+
+       evas_image_cache_set (*e, FIX2INT (val));
+
+       return Qnil;
+}
+
+static VALUE c_image_cache_reload (VALUE self)
+{
+       GET_OBJ (self, Evas, e, "Evas");
+
+       evas_image_cache_reload (*e);
+
+       return Qnil;
+}
+
+static VALUE c_image_cache_flush (VALUE self)
+{
+       GET_OBJ (self, Evas, e, "Evas");
+
+       evas_image_cache_flush (*e);
+
+       return Qnil;
+}
+
+static VALUE c_top_get (VALUE self)
+{
+       Evas_Object *o;
+       void *obj;
+
+       GET_OBJ (self, Evas, e, "Evas");
+
+       if (!(o = evas_object_top_get (*e)))
+               return Qnil;
+
+       if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
+               rb_raise (rb_eException, "EvasObject Ruby object key missing");
+               return Qnil;
+       }
+
+       return (VALUE) obj;
+}
+
+static VALUE c_bottom_get (VALUE self)
+{
+       Evas_Object *o;
+       void *obj;
+
+       GET_OBJ (self, Evas, e, "Evas");
+
+       if (!(o = evas_object_bottom_get (*e)))
+               return Qnil;
+
+       if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
+               rb_raise (rb_eException, "EvasObject Ruby object key missing");
+               return Qnil;
+       }
+
+       return (VALUE) obj;
+}
+
+static VALUE c_find_object (VALUE self, VALUE name)
+{
+       Evas_Object *o;
+       void *obj;
+
+       GET_OBJ (self, Evas, e, "Evas");
+
+       Check_Type (name, T_STRING);
+
+       if (!(o = evas_object_name_find (*e, StringValuePtr (name))))
+               return Qnil;
+
+       if (!(obj = evas_object_data_get (o, RUBY_EVAS_OBJECT_KEY))) {
+               rb_raise (rb_eException, "EvasObject Ruby object key missing");
+               return Qnil;
+       }
+
+       return (VALUE) obj;
+}
+
+void Init_Evas (void)
+{
+       cEvas = rb_define_class_under (mEvas, "Evas", rb_cObject);
 
        /* not publically instantiable yet */
        rb_define_private_method (rb_singleton_class (cEvas),
                                  "new", NULL, 0);
+       rb_define_method (cEvas, "font_path_clear", c_font_path_clear, 0);
+       rb_define_method (cEvas, "font_path_append", c_font_path_append, 1);
+       rb_define_method (cEvas, "font_path_prepend", c_font_path_prepend, 1);
+       rb_define_method (cEvas, "font_path", c_font_path_get, 0);
+       rb_define_method (cEvas, "font_cache", c_font_cache_get, 0);
+       rb_define_method (cEvas, "font_cache=", c_font_cache_set, 1);
+       rb_define_method (cEvas, "font_cache_flush",
+                         c_font_cache_flush, 0);
+       rb_define_method (cEvas, "image_cache", c_image_cache_get, 0);
+       rb_define_method (cEvas, "image_cache=", c_image_cache_set, 1);
+       rb_define_method (cEvas, "image_cache_reload",
+                         c_image_cache_reload, 0);
+       rb_define_method (cEvas, "image_cache_flush",
+                         c_image_cache_flush, 0);
+       rb_define_method (cEvas, "top", c_top_get, 0);
+       rb_define_method (cEvas, "bottom", c_bottom_get, 0);
+       rb_define_method (cEvas, "find_object", c_find_object, 1);
 
        parents = rb_hash_new ();
        rb_global_variable (&parents);
-
-       Init_EvasObject ();
 }