From d36ce8122174a98523857df52cf7308b09bab38d Mon Sep 17 00:00:00 2001 From: Tilman Sauerbeck Date: Wed, 15 Feb 2006 18:07:49 +0000 Subject: [PATCH] Added style support to Evas::Text. --- src/rb_text.c | 213 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 211 insertions(+), 2 deletions(-) diff --git a/src/rb_text.c b/src/rb_text.c index 14b22fa..7488367 100644 --- a/src/rb_text.c +++ b/src/rb_text.c @@ -1,5 +1,5 @@ /* - * $Id: rb_text.c 354 2006-02-10 18:14:08Z tilman $ + * $Id: rb_text.c 368 2006-02-15 18:07:49Z tilman $ * * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de) * @@ -26,6 +26,34 @@ #include "rb_evas.h" #include "rb_evas_object.h" +#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; + /* * call-seq: * Evas::Text.new(evas) => text @@ -158,9 +186,166 @@ static VALUE c_text_set (VALUE self, VALUE 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); + + return INT2FIX (evas_object_text_style_get (e->real)); +} + +/* + * 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; +} + +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) +{ + GET_COLOR_METHOD (shadow); +} + +/* + * 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); +} + void Init_Text (void) { - VALUE c = rb_define_class_under (mEvas, "Text", cEvasObject); + 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); @@ -169,4 +354,28 @@ void Init_Text (void) 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); + + 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); } -- 2.30.2