2 * $Id: rb_text.c 368 2006-02-15 18:07:49Z tilman $
4 * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "rb_evas_main.h"
27 #include "rb_evas_object.h"
29 #define DEF_CONST(mod, prefix, name) \
30 rb_define_const ((mod), #name, INT2FIX (prefix##name));
32 #define GET_COLOR_METHOD(name) \
33 int r = 0, g = 0, b = 0, a = 0; \
35 GET_OBJ (self, RbEvasObject, e); \
37 evas_object_text_##name##_color_get (e->real, &r, &g, &b, &a); \
39 return rb_ary_new3 (4, \
40 INT2FIX (r), INT2FIX (g), \
41 INT2FIX (b), INT2FIX (a));
43 #define SET_COLOR_METHOD(name) \
44 GET_OBJ (self, RbEvasObject, e); \
46 Check_Type (r, T_FIXNUM); \
47 Check_Type (g, T_FIXNUM); \
48 Check_Type (b, T_FIXNUM); \
49 Check_Type (a, T_FIXNUM); \
51 evas_object_text_##name##_color_set (e->real, \
52 FIX2INT (r), FIX2INT (g), \
53 FIX2INT (b), FIX2INT (a)); \
59 * Evas::Text.new(evas) => text
61 * Creates an Evas::Text object.
63 static VALUE c_init (VALUE self, VALUE evas)
65 CHECK_CLASS (evas, cEvas);
66 GET_OBJ (evas, RbEvas, e);
67 GET_OBJ (self, RbEvasObject, text);
69 text->real = evas_object_text_add (e->real);
71 rb_call_super (1, &evas);
78 * text.font_source => string or nil
80 * Returns the font source of <i>text</i>.
82 static VALUE c_font_source_get (VALUE self)
86 GET_OBJ (self, RbEvasObject, e);
88 if (!(tmp = evas_object_text_font_source_get (e->real)))
91 return rb_str_new2 (tmp);
96 * text.font_source(source)
98 * Sets the font source of <i>text</i>.
100 static VALUE c_font_source_set (VALUE self, VALUE val)
102 GET_OBJ (self, RbEvasObject, e);
104 Check_Type (val, T_STRING);
106 evas_object_text_font_source_set (e->real, StringValuePtr (val));
113 * text.get_font => array
115 * Returns the font name and font size of <i>text</i>.
117 * text.set_font("vera", 10) #=> nil
118 * text_get_font #=> ["vera", 10]
120 static VALUE c_get_font (VALUE self)
123 Evas_Font_Size size = 0;
125 GET_OBJ (self, RbEvasObject, e);
127 evas_object_text_font_get (e->real, &font, &size);
129 return rb_ary_new3 (2, font ? rb_str_new2 (font) : Qnil,
135 * text.set_font(font, size) => nil
137 * Sets the font name and font size of <i>text</i>.
139 * text.set_font("vera", 10) #=> nil
141 static VALUE c_set_font (VALUE self, VALUE font, VALUE size)
143 GET_OBJ (self, RbEvasObject, e);
145 Check_Type (font, T_STRING);
146 Check_Type (size, T_FIXNUM);
148 evas_object_text_font_set (e->real, StringValuePtr (font),
156 * text.text => string
158 * Returns the text of <i>text</i>.
160 static VALUE c_text_get (VALUE self)
164 GET_OBJ (self, RbEvasObject, e);
166 if (!(tmp = evas_object_text_text_get (e->real)))
169 return rb_str_new2 (tmp);
176 * Sets the text of <i>text</i>.
178 static VALUE c_text_set (VALUE self, VALUE val)
180 GET_OBJ (self, RbEvasObject, e);
182 Check_Type (val, T_STRING);
184 evas_object_text_text_set (e->real, StringValuePtr (val));
191 * text.style => integer
193 * Returns the style of <i>text</i>.
195 static VALUE c_style_get (VALUE self)
197 GET_OBJ (self, RbEvasObject, e);
199 return INT2FIX (evas_object_text_style_get (e->real));
204 * text.style = integer
206 * Sets the style of <i>text</i>.
208 static VALUE c_style_set (VALUE self, VALUE val)
210 GET_OBJ (self, RbEvasObject, e);
212 Check_Type (val, T_FIXNUM);
214 evas_object_text_style_set (e->real, FIX2INT (val));
219 static VALUE c_style_pad_get (VALUE self)
221 int l = 0, r = 0, t = 0, b = 0;
223 GET_OBJ (self, RbEvasObject, e);
225 evas_object_text_style_pad_get (e->real, &l, &r, &t, &b);
227 return rb_ary_new3 (4,
228 INT2FIX (l), INT2FIX (r),
229 INT2FIX (r), INT2FIX (b));
234 * e.get_shadow_color => array
236 * Returns the shadow color of <i>e</i>.
238 * e.set_shadow_color(128, 128, 128, 0) #=> nil
239 * e.get_shadow_color #=> [128, 128, 128, 0]
241 static VALUE c_get_shadow_color (VALUE self)
243 GET_COLOR_METHOD (shadow);
248 * e.set_shadow_color(r, g, b, a) => nil
250 * Sets the shadow color of <i>e</i>.
252 * e.set_shadow_color(128, 128, 128, 0) #=> nil
254 static VALUE c_set_shadow_color (VALUE self,
255 VALUE r, VALUE g, VALUE b, VALUE a)
257 SET_COLOR_METHOD (shadow);
262 * e.get_glow_color => array
264 * Returns the glow color of <i>e</i>.
266 * e.set_glow_color(128, 128, 128, 0) #=> nil
267 * e.get_glow_color #=> [128, 128, 128, 0]
269 static VALUE c_get_glow_color (VALUE self)
271 GET_COLOR_METHOD (glow);
276 * e.set_glow_color(r, g, b, a) => nil
278 * Sets the glow color of <i>e</i>.
280 * e.set_glow_color(128, 128, 128, 0) #=> nil
282 static VALUE c_set_glow_color (VALUE self,
283 VALUE r, VALUE g, VALUE b, VALUE a)
285 SET_COLOR_METHOD (glow);
290 * e.get_glow2_color => array
292 * Returns the glow2 color of <i>e</i>.
294 * e.set_glow2_color(128, 128, 128, 0) #=> nil
295 * e.get_glow2_color #=> [128, 128, 128, 0]
297 static VALUE c_get_glow2_color (VALUE self)
299 GET_COLOR_METHOD (glow2);
304 * e.set_glow2_color(r, g, b, a) => nil
306 * Sets the glow2 color of <i>e</i>.
308 * e.set_glow2_color(128, 128, 128, 0) #=> nil
310 static VALUE c_set_glow2_color (VALUE self,
311 VALUE r, VALUE g, VALUE b, VALUE a)
313 SET_COLOR_METHOD (glow2);
318 * e.get_outline_color => array
320 * Returns the outline color of <i>e</i>.
322 * e.set_outline_color(128, 128, 128, 0) #=> nil
323 * e.get_outline_color #=> [128, 128, 128, 0]
325 static VALUE c_get_outline_color (VALUE self)
327 GET_COLOR_METHOD (outline);
332 * e.set_outline_color(r, g, b, a) => nil
334 * Sets the outline color of <i>e</i>.
336 * e.set_outline_color(128, 128, 128, 0) #=> nil
338 static VALUE c_set_outline_color (VALUE self,
339 VALUE r, VALUE g, VALUE b, VALUE a)
341 SET_COLOR_METHOD (outline);
344 void Init_Text (void)
348 c = rb_define_class_under (mEvas, "Text", cEvasObject);
350 rb_define_method (c, "initialize", c_init, 1);
351 rb_define_method (c, "font_source", c_font_source_get, 0);
352 rb_define_method (c, "font_source=", c_font_source_set, 1);
353 rb_define_method (c, "get_font", c_get_font, 0);
354 rb_define_method (c, "set_font", c_set_font, 2);
355 rb_define_method (c, "text", c_text_get, 0);
356 rb_define_method (c, "text=", c_text_set, 1);
357 rb_define_method (c, "style", c_style_get, 0);
358 rb_define_method (c, "style=", c_style_set, 1);
359 rb_define_method (c, "style_pad", c_style_pad_get, 0);
360 rb_define_method (c, "get_shadow_color", c_get_shadow_color, 0);
361 rb_define_method (c, "set_shadow_color", c_set_shadow_color, 4);
362 rb_define_method (c, "get_glow_color", c_get_glow_color, 0);
363 rb_define_method (c, "set_glow_color", c_set_glow_color, 4);
364 rb_define_method (c, "get_glow2_color", c_get_glow2_color, 0);
365 rb_define_method (c, "set_glow2_color", c_set_glow2_color, 4);
366 rb_define_method (c, "get_outline_color", c_get_outline_color, 0);
367 rb_define_method (c, "set_outline_color", c_set_outline_color, 4);
369 c2 = rb_define_class_under (mEvas, "Style", c);
371 DEF_CONST (c2, EVAS_TEXT_STYLE_, PLAIN);
372 DEF_CONST (c2, EVAS_TEXT_STYLE_, SHADOW);
373 DEF_CONST (c2, EVAS_TEXT_STYLE_, OUTLINE);
374 DEF_CONST (c2, EVAS_TEXT_STYLE_, SOFT_OUTLINE);
375 DEF_CONST (c2, EVAS_TEXT_STYLE_, GLOW);
376 DEF_CONST (c2, EVAS_TEXT_STYLE_, OUTLINE_SHADOW);
377 DEF_CONST (c2, EVAS_TEXT_STYLE_, FAR_SHADOW);
378 DEF_CONST (c2, EVAS_TEXT_STYLE_, OUTLINE_SOFT_SHADOW);
379 DEF_CONST (c2, EVAS_TEXT_STYLE_, SOFT_SHADOW);
380 DEF_CONST (c2, EVAS_TEXT_STYLE_, FAR_SOFT_SHADOW);