2 * $Id: rb_text.c 388 2006-10-07 14:39:24Z 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 evas_object_text_font_source_set (e->real, StringValuePtr (val));
111 * text.get_font => array
113 * Returns the font name and font size of <i>text</i>.
115 * text.set_font("vera", 10) #=> nil
116 * text_get_font #=> ["vera", 10]
118 static VALUE c_get_font (VALUE self)
121 Evas_Font_Size size = 0;
123 GET_OBJ (self, RbEvasObject, e);
125 evas_object_text_font_get (e->real, &font, &size);
127 return rb_ary_new3 (2, font ? rb_str_new2 (font) : Qnil,
133 * text.set_font(font, size) => nil
135 * Sets the font name and font size of <i>text</i>.
137 * text.set_font("vera", 10) #=> nil
139 static VALUE c_set_font (VALUE self, VALUE font, VALUE size)
141 GET_OBJ (self, RbEvasObject, e);
143 Check_Type (size, T_FIXNUM);
145 evas_object_text_font_set (e->real, StringValuePtr (font),
153 * text.text => string
155 * Returns the text of <i>text</i>.
157 static VALUE c_text_get (VALUE self)
161 GET_OBJ (self, RbEvasObject, e);
163 if (!(tmp = evas_object_text_text_get (e->real)))
166 return rb_str_new2 (tmp);
173 * Sets the text of <i>text</i>.
175 static VALUE c_text_set (VALUE self, VALUE val)
177 GET_OBJ (self, RbEvasObject, e);
179 evas_object_text_text_set (e->real, StringValuePtr (val));
186 * text.style => integer
188 * Returns the style of <i>text</i>.
190 static VALUE c_style_get (VALUE self)
192 GET_OBJ (self, RbEvasObject, e);
194 return INT2FIX (evas_object_text_style_get (e->real));
199 * text.style = integer
201 * Sets the style of <i>text</i>.
203 static VALUE c_style_set (VALUE self, VALUE val)
205 GET_OBJ (self, RbEvasObject, e);
207 Check_Type (val, T_FIXNUM);
209 evas_object_text_style_set (e->real, FIX2INT (val));
214 static VALUE c_style_pad_get (VALUE self)
216 int l = 0, r = 0, t = 0, b = 0;
218 GET_OBJ (self, RbEvasObject, e);
220 evas_object_text_style_pad_get (e->real, &l, &r, &t, &b);
222 return rb_ary_new3 (4,
223 INT2FIX (l), INT2FIX (r),
224 INT2FIX (r), INT2FIX (b));
229 * e.get_shadow_color => array
231 * Returns the shadow color of <i>e</i>.
233 * e.set_shadow_color(128, 128, 128, 0) #=> nil
234 * e.get_shadow_color #=> [128, 128, 128, 0]
236 static VALUE c_get_shadow_color (VALUE self)
238 GET_COLOR_METHOD (shadow);
243 * e.set_shadow_color(r, g, b, a) => nil
245 * Sets the shadow color of <i>e</i>.
247 * e.set_shadow_color(128, 128, 128, 0) #=> nil
249 static VALUE c_set_shadow_color (VALUE self,
250 VALUE r, VALUE g, VALUE b, VALUE a)
252 SET_COLOR_METHOD (shadow);
257 * e.get_glow_color => array
259 * Returns the glow color of <i>e</i>.
261 * e.set_glow_color(128, 128, 128, 0) #=> nil
262 * e.get_glow_color #=> [128, 128, 128, 0]
264 static VALUE c_get_glow_color (VALUE self)
266 GET_COLOR_METHOD (glow);
271 * e.set_glow_color(r, g, b, a) => nil
273 * Sets the glow color of <i>e</i>.
275 * e.set_glow_color(128, 128, 128, 0) #=> nil
277 static VALUE c_set_glow_color (VALUE self,
278 VALUE r, VALUE g, VALUE b, VALUE a)
280 SET_COLOR_METHOD (glow);
285 * e.get_glow2_color => array
287 * Returns the glow2 color of <i>e</i>.
289 * e.set_glow2_color(128, 128, 128, 0) #=> nil
290 * e.get_glow2_color #=> [128, 128, 128, 0]
292 static VALUE c_get_glow2_color (VALUE self)
294 GET_COLOR_METHOD (glow2);
299 * e.set_glow2_color(r, g, b, a) => nil
301 * Sets the glow2 color of <i>e</i>.
303 * e.set_glow2_color(128, 128, 128, 0) #=> nil
305 static VALUE c_set_glow2_color (VALUE self,
306 VALUE r, VALUE g, VALUE b, VALUE a)
308 SET_COLOR_METHOD (glow2);
313 * e.get_outline_color => array
315 * Returns the outline color of <i>e</i>.
317 * e.set_outline_color(128, 128, 128, 0) #=> nil
318 * e.get_outline_color #=> [128, 128, 128, 0]
320 static VALUE c_get_outline_color (VALUE self)
322 GET_COLOR_METHOD (outline);
327 * e.set_outline_color(r, g, b, a) => nil
329 * Sets the outline color of <i>e</i>.
331 * e.set_outline_color(128, 128, 128, 0) #=> nil
333 static VALUE c_set_outline_color (VALUE self,
334 VALUE r, VALUE g, VALUE b, VALUE a)
336 SET_COLOR_METHOD (outline);
339 static VALUE c_ascent_get (VALUE self)
341 GET_OBJ (self, RbEvasObject, e);
343 return INT2FIX ((int) evas_object_text_ascent_get (e->real));
346 static VALUE c_descent_get (VALUE self)
348 GET_OBJ (self, RbEvasObject, e);
350 return INT2FIX ((int) evas_object_text_descent_get (e->real));
353 static VALUE c_max_ascent_get (VALUE self)
355 GET_OBJ (self, RbEvasObject, e);
357 return INT2FIX ((int) evas_object_text_max_ascent_get (e->real));
360 static VALUE c_max_descent_get (VALUE self)
362 GET_OBJ (self, RbEvasObject, e);
364 return INT2FIX ((int) evas_object_text_max_descent_get (e->real));
367 static VALUE c_advance_get (VALUE self)
371 GET_OBJ (self, RbEvasObject, e);
373 h = (int) evas_object_text_horiz_advance_get (e->real);
374 v = (int) evas_object_text_vert_advance_get (e->real);
376 return rb_ary_new3 (2, INT2FIX (h), INT2FIX (v));
379 static VALUE c_inset_get (VALUE self)
381 GET_OBJ (self, RbEvasObject, e);
383 return INT2FIX ((int) evas_object_text_inset_get (e->real));
386 void Init_Text (void)
390 c = rb_define_class_under (mEvas, "Text", cEvasObject);
392 rb_define_method (c, "initialize", c_init, 1);
393 rb_define_method (c, "font_source", c_font_source_get, 0);
394 rb_define_method (c, "font_source=", c_font_source_set, 1);
395 rb_define_method (c, "get_font", c_get_font, 0);
396 rb_define_method (c, "set_font", c_set_font, 2);
397 rb_define_method (c, "text", c_text_get, 0);
398 rb_define_method (c, "text=", c_text_set, 1);
399 rb_define_method (c, "style", c_style_get, 0);
400 rb_define_method (c, "style=", c_style_set, 1);
401 rb_define_method (c, "style_pad", c_style_pad_get, 0);
402 rb_define_method (c, "get_shadow_color", c_get_shadow_color, 0);
403 rb_define_method (c, "set_shadow_color", c_set_shadow_color, 4);
404 rb_define_method (c, "get_glow_color", c_get_glow_color, 0);
405 rb_define_method (c, "set_glow_color", c_set_glow_color, 4);
406 rb_define_method (c, "get_glow2_color", c_get_glow2_color, 0);
407 rb_define_method (c, "set_glow2_color", c_set_glow2_color, 4);
408 rb_define_method (c, "get_outline_color", c_get_outline_color, 0);
409 rb_define_method (c, "set_outline_color", c_set_outline_color, 4);
411 rb_define_method (c, "ascent", c_ascent_get, 0);
412 rb_define_method (c, "descent", c_descent_get, 0);
413 rb_define_method (c, "max_ascent", c_max_ascent_get, 0);
414 rb_define_method (c, "max_descent", c_max_descent_get, 0);
415 rb_define_method (c, "advance", c_advance_get, 0);
416 rb_define_method (c, "inset", c_inset_get, 0);
418 c2 = rb_define_class_under (mEvas, "Style", c);
420 DEF_CONST (c2, EVAS_TEXT_STYLE_, PLAIN);
421 DEF_CONST (c2, EVAS_TEXT_STYLE_, SHADOW);
422 DEF_CONST (c2, EVAS_TEXT_STYLE_, OUTLINE);
423 DEF_CONST (c2, EVAS_TEXT_STYLE_, SOFT_OUTLINE);
424 DEF_CONST (c2, EVAS_TEXT_STYLE_, GLOW);
425 DEF_CONST (c2, EVAS_TEXT_STYLE_, OUTLINE_SHADOW);
426 DEF_CONST (c2, EVAS_TEXT_STYLE_, FAR_SHADOW);
427 DEF_CONST (c2, EVAS_TEXT_STYLE_, OUTLINE_SOFT_SHADOW);
428 DEF_CONST (c2, EVAS_TEXT_STYLE_, SOFT_SHADOW);
429 DEF_CONST (c2, EVAS_TEXT_STYLE_, FAR_SOFT_SHADOW);