X-Git-Url: http://git.code-monkey.de/?p=ruby-evas.git;a=blobdiff_plain;f=src%2Frb_text.c;h=512e07a53ddb02e39ff8f7e6b16c9c48f1551dfd;hp=c6ffa422abb5f33ce961a35640ad2bb5e51b3283;hb=c3202d026f3800676461ee407f2a5e46dc20e2f2;hpb=ba05ccf5a7b503e2d9a58c1de4072312b5abfab7 diff --git a/src/rb_text.c b/src/rb_text.c index c6ffa42..512e07a 100644 --- a/src/rb_text.c +++ b/src/rb_text.c @@ -1,6 +1,4 @@ /* - * $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 @@ -26,111 +24,405 @@ #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; - } +#define DEF_CONST(mod, prefix, name) \ + rb_define_const ((mod), #name, INT2FIX (prefix##name)); + +#define GET_COLOR_METHOD(name) \ + int r = 0, g = 0, b = 0, a = 0; \ +\ + GET_OBJ (self, RbEvasObject, e); \ +\ + evas_object_text_##name##_color_get (e->real, &r, &g, &b, &a); \ +\ + return rb_ary_new3 (4, \ + INT2FIX (r), INT2FIX (g), \ + INT2FIX (b), INT2FIX (a)); + +#define SET_COLOR_METHOD(name) \ + GET_OBJ (self, RbEvasObject, e); \ +\ + Check_Type (r, T_FIXNUM); \ + Check_Type (g, T_FIXNUM); \ + Check_Type (b, T_FIXNUM); \ + Check_Type (a, T_FIXNUM); \ +\ + evas_object_text_##name##_color_set (e->real, \ + FIX2INT (r), FIX2INT (g), \ + FIX2INT (b), FIX2INT (a)); \ +\ + return Qnil; - GET_OBJ (evas, Evas, e, "Evas"); +/* + * call-seq: + * Evas::Text.new(evas) => text + * + * Creates an Evas::Text object. + */ +static VALUE c_init (VALUE self, VALUE evas) +{ + CHECK_CLASS (evas, cEvas); + GET_OBJ (evas, RbEvas, e); + GET_OBJ (self, RbEvasObject, text); - self = Data_Make_Struct (klass, Evas_Object *, c_evas_object_mark, - c_evas_object_free, rect); - *rect = evas_object_text_add (*e); + text->real = evas_object_text_add (e->real); - argv[0] = evas; - rb_obj_call_init (self, 1, argv); + rb_call_super (1, &evas); return self; } +/* + * call-seq: + * text.font_source => string or nil + * + * Returns the font source of text. + */ static VALUE c_font_source_get (VALUE self) { const char *tmp; - GET_OBJ (self, Evas_Object, e, "Text"); + GET_OBJ (self, RbEvasObject, e); - if (!(tmp = evas_object_text_font_source_get (*e))) + if (!(tmp = evas_object_text_font_source_get (e->real))) return Qnil; else return rb_str_new2 (tmp); } +/* + * call-seq: + * text.font_source(source) + * + * Sets the font source of text. + */ static VALUE c_font_source_set (VALUE self, VALUE val) { - GET_OBJ (self, Evas_Object, e, "Text"); + GET_OBJ (self, RbEvasObject, e); - Check_Type (val, T_STRING); - - evas_object_text_font_source_set (*e, StringValuePtr (val)); + evas_object_text_font_source_set (e->real, StringValuePtr (val)); return Qnil; } +/* + * call-seq: + * text.get_font => array + * + * Returns the font name and font size of text. + * + * text.set_font("vera", 10) #=> nil + * text_get_font #=> ["vera", 10] + */ static VALUE c_get_font (VALUE self) { char *font = NULL; Evas_Font_Size size = 0; - GET_OBJ (self, Evas_Object, e, "Text"); + GET_OBJ (self, RbEvasObject, e); - evas_object_text_font_get (*e, &font, &size); + evas_object_text_font_get (e->real, &font, &size); return rb_ary_new3 (2, font ? rb_str_new2 (font) : Qnil, INT2FIX (size)); } +/* + * call-seq: + * text.set_font(font, size) => nil + * + * Sets the font name and font size of text. + * + * text.set_font("vera", 10) #=> nil + */ static VALUE c_set_font (VALUE self, VALUE font, VALUE size) { - GET_OBJ (self, Evas_Object, e, "Text"); + GET_OBJ (self, RbEvasObject, e); - Check_Type (font, T_STRING); - Check_Type (font, T_FIXNUM); + Check_Type (size, T_FIXNUM); - evas_object_text_font_set (*e, StringValuePtr (font), + evas_object_text_font_set (e->real, StringValuePtr (font), FIX2INT (size)); return Qnil; } +/* + * call-seq: + * text.text => string + * + * Returns the text of text. + */ static VALUE c_text_get (VALUE self) { const char *tmp; - GET_OBJ (self, Evas_Object, e, "Text"); + GET_OBJ (self, RbEvasObject, e); - if (!(tmp = evas_object_text_text_get (*e))) + if (!(tmp = evas_object_text_text_get (e->real))) return Qnil; else return rb_str_new2 (tmp); } +/* + * call-seq: + * text.text(string) + * + * Sets the text of text. + */ static VALUE c_text_set (VALUE self, VALUE val) { - GET_OBJ (self, Evas_Object, e, "Text"); + GET_OBJ (self, RbEvasObject, e); + + evas_object_text_text_set (e->real, StringValuePtr (val)); + + return Qnil; +} + +/* + * call-seq: + * text.style => integer + * + * Returns the style of text. + */ +static VALUE c_style_get (VALUE self) +{ + GET_OBJ (self, RbEvasObject, e); - Check_Type (val, T_STRING); + return INT2FIX (evas_object_text_style_get (e->real)); +} - evas_object_text_text_set (*e, StringValuePtr (val)); +/* + * call-seq: + * text.style = integer + * + * Sets the style of text. + */ +static VALUE c_style_set (VALUE self, VALUE val) +{ + GET_OBJ (self, RbEvasObject, e); + + Check_Type (val, T_FIXNUM); + + evas_object_text_style_set (e->real, FIX2INT (val)); return Qnil; } -void Init_Text (void) +static VALUE c_style_pad_get (VALUE self) +{ + int l = 0, r = 0, t = 0, b = 0; + + GET_OBJ (self, RbEvasObject, e); + + evas_object_text_style_pad_get (e->real, &l, &r, &t, &b); + + return rb_ary_new3 (4, + INT2FIX (l), INT2FIX (r), + INT2FIX (r), INT2FIX (b)); +} + +/* + * call-seq: + * e.get_shadow_color => array + * + * Returns the shadow color of e. + * + * e.set_shadow_color(128, 128, 128, 0) #=> nil + * e.get_shadow_color #=> [128, 128, 128, 0] + */ +static VALUE c_get_shadow_color (VALUE self) { - VALUE cText = rb_define_class_under (mEvas, "Text", cEvasObject); + GET_COLOR_METHOD (shadow); +} - 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); +/* + * call-seq: + * e.set_shadow_color(r, g, b, a) => nil + * + * Sets the shadow color of e. + * + * e.set_shadow_color(128, 128, 128, 0) #=> nil + */ +static VALUE c_set_shadow_color (VALUE self, + VALUE r, VALUE g, VALUE b, VALUE a) +{ + SET_COLOR_METHOD (shadow); +} + +/* + * call-seq: + * e.get_glow_color => array + * + * Returns the glow color of e. + * + * e.set_glow_color(128, 128, 128, 0) #=> nil + * e.get_glow_color #=> [128, 128, 128, 0] + */ +static VALUE c_get_glow_color (VALUE self) +{ + GET_COLOR_METHOD (glow); +} + +/* + * call-seq: + * e.set_glow_color(r, g, b, a) => nil + * + * Sets the glow color of e. + * + * e.set_glow_color(128, 128, 128, 0) #=> nil + */ +static VALUE c_set_glow_color (VALUE self, + VALUE r, VALUE g, VALUE b, VALUE a) +{ + SET_COLOR_METHOD (glow); +} + +/* + * call-seq: + * e.get_glow2_color => array + * + * Returns the glow2 color of e. + * + * e.set_glow2_color(128, 128, 128, 0) #=> nil + * e.get_glow2_color #=> [128, 128, 128, 0] + */ +static VALUE c_get_glow2_color (VALUE self) +{ + GET_COLOR_METHOD (glow2); +} + +/* + * call-seq: + * e.set_glow2_color(r, g, b, a) => nil + * + * Sets the glow2 color of e. + * + * e.set_glow2_color(128, 128, 128, 0) #=> nil + */ +static VALUE c_set_glow2_color (VALUE self, + VALUE r, VALUE g, VALUE b, VALUE a) +{ + SET_COLOR_METHOD (glow2); +} + +/* + * call-seq: + * e.get_outline_color => array + * + * Returns the outline color of e. + * + * e.set_outline_color(128, 128, 128, 0) #=> nil + * e.get_outline_color #=> [128, 128, 128, 0] + */ +static VALUE c_get_outline_color (VALUE self) +{ + GET_COLOR_METHOD (outline); +} + +/* + * call-seq: + * e.set_outline_color(r, g, b, a) => nil + * + * Sets the outline color of e. + * + * e.set_outline_color(128, 128, 128, 0) #=> nil + */ +static VALUE c_set_outline_color (VALUE self, + VALUE r, VALUE g, VALUE b, VALUE a) +{ + SET_COLOR_METHOD (outline); +} + +static VALUE c_ascent_get (VALUE self) +{ + GET_OBJ (self, RbEvasObject, e); + + return INT2FIX ((int) evas_object_text_ascent_get (e->real)); +} + +static VALUE c_descent_get (VALUE self) +{ + GET_OBJ (self, RbEvasObject, e); + + return INT2FIX ((int) evas_object_text_descent_get (e->real)); +} + +static VALUE c_max_ascent_get (VALUE self) +{ + GET_OBJ (self, RbEvasObject, e); + + return INT2FIX ((int) evas_object_text_max_ascent_get (e->real)); +} + +static VALUE c_max_descent_get (VALUE self) +{ + GET_OBJ (self, RbEvasObject, e); + + return INT2FIX ((int) evas_object_text_max_descent_get (e->real)); +} + +static VALUE c_advance_get (VALUE self) +{ + int h = 0, v = 0; + + GET_OBJ (self, RbEvasObject, e); + + h = (int) evas_object_text_horiz_advance_get (e->real); + v = (int) evas_object_text_vert_advance_get (e->real); + + return rb_ary_new3 (2, INT2FIX (h), INT2FIX (v)); +} + +static VALUE c_inset_get (VALUE self) +{ + GET_OBJ (self, RbEvasObject, e); + + return INT2FIX ((int) evas_object_text_inset_get (e->real)); +} + +void Init_Text (void) +{ + VALUE c, c2; + + c = rb_define_class_under (mEvas, "Text", cEvasObject); + + rb_define_method (c, "initialize", c_init, 1); + rb_define_method (c, "font_source", c_font_source_get, 0); + rb_define_method (c, "font_source=", c_font_source_set, 1); + rb_define_method (c, "get_font", c_get_font, 0); + rb_define_method (c, "set_font", c_set_font, 2); + rb_define_method (c, "text", c_text_get, 0); + rb_define_method (c, "text=", c_text_set, 1); + rb_define_method (c, "style", c_style_get, 0); + rb_define_method (c, "style=", c_style_set, 1); + rb_define_method (c, "style_pad", c_style_pad_get, 0); + rb_define_method (c, "get_shadow_color", c_get_shadow_color, 0); + rb_define_method (c, "set_shadow_color", c_set_shadow_color, 4); + rb_define_method (c, "get_glow_color", c_get_glow_color, 0); + rb_define_method (c, "set_glow_color", c_set_glow_color, 4); + rb_define_method (c, "get_glow2_color", c_get_glow2_color, 0); + rb_define_method (c, "set_glow2_color", c_set_glow2_color, 4); + rb_define_method (c, "get_outline_color", c_get_outline_color, 0); + rb_define_method (c, "set_outline_color", c_set_outline_color, 4); + + rb_define_method (c, "ascent", c_ascent_get, 0); + rb_define_method (c, "descent", c_descent_get, 0); + rb_define_method (c, "max_ascent", c_max_ascent_get, 0); + rb_define_method (c, "max_descent", c_max_descent_get, 0); + rb_define_method (c, "advance", c_advance_get, 0); + rb_define_method (c, "inset", c_inset_get, 0); + + c2 = rb_define_class_under (mEvas, "Style", c); + + DEF_CONST (c2, EVAS_TEXT_STYLE_, PLAIN); + DEF_CONST (c2, EVAS_TEXT_STYLE_, SHADOW); + DEF_CONST (c2, EVAS_TEXT_STYLE_, OUTLINE); + DEF_CONST (c2, EVAS_TEXT_STYLE_, SOFT_OUTLINE); + DEF_CONST (c2, EVAS_TEXT_STYLE_, GLOW); + DEF_CONST (c2, EVAS_TEXT_STYLE_, OUTLINE_SHADOW); + DEF_CONST (c2, EVAS_TEXT_STYLE_, FAR_SHADOW); + DEF_CONST (c2, EVAS_TEXT_STYLE_, OUTLINE_SOFT_SHADOW); + DEF_CONST (c2, EVAS_TEXT_STYLE_, SOFT_SHADOW); + DEF_CONST (c2, EVAS_TEXT_STYLE_, FAR_SOFT_SHADOW); }