X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Frb_text.c;fp=src%2Frb_text.c;h=c6ffa422abb5f33ce961a35640ad2bb5e51b3283;hb=ba05ccf5a7b503e2d9a58c1de4072312b5abfab7;hp=0000000000000000000000000000000000000000;hpb=2118372cfbb06b10e6254539b30887e0342650fd;p=ruby-evas.git diff --git a/src/rb_text.c b/src/rb_text.c new file mode 100644 index 0000000..c6ffa42 --- /dev/null +++ b/src/rb_text.c @@ -0,0 +1,136 @@ +/* + * $Id: rb_text.c 23 2004-06-26 22:55:31Z 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" + +static VALUE c_new (VALUE klass, VALUE evas) +{ + VALUE self, argv[1]; + Evas_Object **rect; + + if (!rb_obj_is_kind_of (evas, cEvas)) { + rb_raise (rb_eTypeError, + "wrong argument type %s (expected Evas)", + rb_obj_classname (evas)); + return Qnil; + } + + GET_OBJ (evas, Evas, e, "Evas"); + + self = Data_Make_Struct (klass, Evas_Object *, c_evas_object_mark, + c_evas_object_free, rect); + *rect = evas_object_text_add (*e); + + argv[0] = evas; + rb_obj_call_init (self, 1, argv); + + return self; +} + +static VALUE c_font_source_get (VALUE self) +{ + const char *tmp; + + GET_OBJ (self, Evas_Object, e, "Text"); + + if (!(tmp = evas_object_text_font_source_get (*e))) + return Qnil; + else + return rb_str_new2 (tmp); +} + +static VALUE c_font_source_set (VALUE self, VALUE val) +{ + GET_OBJ (self, Evas_Object, e, "Text"); + + Check_Type (val, T_STRING); + + evas_object_text_font_source_set (*e, StringValuePtr (val)); + + return Qnil; +} + +static VALUE c_get_font (VALUE self) +{ + char *font = NULL; + Evas_Font_Size size = 0; + + GET_OBJ (self, Evas_Object, e, "Text"); + + evas_object_text_font_get (*e, &font, &size); + + return rb_ary_new3 (2, font ? rb_str_new2 (font) : Qnil, + INT2FIX (size)); +} + +static VALUE c_set_font (VALUE self, VALUE font, VALUE size) +{ + GET_OBJ (self, Evas_Object, e, "Text"); + + Check_Type (font, T_STRING); + Check_Type (font, T_FIXNUM); + + evas_object_text_font_set (*e, StringValuePtr (font), + FIX2INT (size)); + + return Qnil; +} + +static VALUE c_text_get (VALUE self) +{ + const char *tmp; + + GET_OBJ (self, Evas_Object, e, "Text"); + + if (!(tmp = evas_object_text_text_get (*e))) + return Qnil; + else + return rb_str_new2 (tmp); +} + +static VALUE c_text_set (VALUE self, VALUE val) +{ + GET_OBJ (self, Evas_Object, e, "Text"); + + Check_Type (val, T_STRING); + + evas_object_text_text_set (*e, StringValuePtr (val)); + + return Qnil; +} + +void Init_Text (void) +{ + VALUE cText = rb_define_class_under (mEvas, "Text", cEvasObject); + + rb_define_singleton_method (cText, "new", c_new, 1); + rb_define_method (cText, "font_source", c_font_source_get, 0); + rb_define_method (cText, "font_source=", c_font_source_set, 1); + rb_define_method (cText, "get_font", c_get_font, 0); + rb_define_method (cText, "set_font", c_set_font, 2); + rb_define_method (cText, "text", c_text_get, 0); + rb_define_method (cText, "text=", c_text_set, 1); +}