2 * Copyright (C) 2004 Tilman Sauerbeck (tilman at code-monkey de)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "rb_evas_main.h"
25 #include "rb_evas_object.h"
27 #define DEF_CONST(mod, prefix, name) \
28 rb_define_const ((mod), #name, INT2FIX (prefix##name));
30 #define GET_COLOR_METHOD(name) \
31 int r = 0, g = 0, b = 0, a = 0; \
33 GET_OBJ (self, RbEvasObject, e); \
35 evas_object_text_##name##_color_get (e->real, &r, &g, &b, &a); \
37 return rb_ary_new3 (4, \
38 INT2FIX (r), INT2FIX (g), \
39 INT2FIX (b), INT2FIX (a));
41 #define SET_COLOR_METHOD(name) \
42 GET_OBJ (self, RbEvasObject, e); \
44 Check_Type (r, T_FIXNUM); \
45 Check_Type (g, T_FIXNUM); \
46 Check_Type (b, T_FIXNUM); \
47 Check_Type (a, T_FIXNUM); \
49 evas_object_text_##name##_color_set (e->real, \
50 FIX2INT (r), FIX2INT (g), \
51 FIX2INT (b), FIX2INT (a)); \
57 * Evas::Text.new(evas) => text
59 * Creates an Evas::Text object.
61 static VALUE c_init (VALUE self, VALUE evas)
63 CHECK_CLASS (evas, cEvas);
64 GET_OBJ (evas, RbEvas, e);
65 GET_OBJ (self, RbEvasObject, text);
67 text->real = evas_object_text_add (e->real);
69 rb_call_super (1, &evas);
76 * text.font_source => string or nil
78 * Returns the font source of <i>text</i>.
80 static VALUE c_font_source_get (VALUE self)
84 GET_OBJ (self, RbEvasObject, e);
86 if (!(tmp = evas_object_text_font_source_get (e->real)))
89 return rb_str_new2 (tmp);
94 * text.font_source(source)
96 * Sets the font source of <i>text</i>.
98 static VALUE c_font_source_set (VALUE self, VALUE val)
100 GET_OBJ (self, RbEvasObject, e);
102 evas_object_text_font_source_set (e->real, StringValuePtr (val));
109 * text.get_font => array
111 * Returns the font name and font size of <i>text</i>.
113 * text.set_font("vera", 10) #=> nil
114 * text_get_font #=> ["vera", 10]
116 static VALUE c_get_font (VALUE self)
119 Evas_Font_Size size = 0;
121 GET_OBJ (self, RbEvasObject, e);
123 evas_object_text_font_get (e->real, &font, &size);
125 return rb_ary_new3 (2, font ? rb_str_new2 (font) : Qnil,
131 * text.set_font(font, size) => nil
133 * Sets the font name and font size of <i>text</i>.
135 * text.set_font("vera", 10) #=> nil
137 static VALUE c_set_font (VALUE self, VALUE font, VALUE size)
139 GET_OBJ (self, RbEvasObject, e);
141 Check_Type (size, T_FIXNUM);
143 evas_object_text_font_set (e->real, StringValuePtr (font),
151 * text.text => string
153 * Returns the text of <i>text</i>.
155 static VALUE c_text_get (VALUE self)
159 GET_OBJ (self, RbEvasObject, e);
161 if (!(tmp = evas_object_text_text_get (e->real)))
164 return rb_str_new2 (tmp);
171 * Sets the text of <i>text</i>.
173 static VALUE c_text_set (VALUE self, VALUE val)
175 GET_OBJ (self, RbEvasObject, e);
177 evas_object_text_text_set (e->real, StringValuePtr (val));
184 * text.style => integer
186 * Returns the style of <i>text</i>.
188 static VALUE c_style_get (VALUE self)
190 GET_OBJ (self, RbEvasObject, e);
192 return INT2FIX (evas_object_text_style_get (e->real));
197 * text.style = integer
199 * Sets the style of <i>text</i>.
201 static VALUE c_style_set (VALUE self, VALUE val)
203 GET_OBJ (self, RbEvasObject, e);
205 Check_Type (val, T_FIXNUM);
207 evas_object_text_style_set (e->real, FIX2INT (val));
212 static VALUE c_style_pad_get (VALUE self)
214 int l = 0, r = 0, t = 0, b = 0;
216 GET_OBJ (self, RbEvasObject, e);
218 evas_object_text_style_pad_get (e->real, &l, &r, &t, &b);
220 return rb_ary_new3 (4,
221 INT2FIX (l), INT2FIX (r),
222 INT2FIX (r), INT2FIX (b));
227 * e.get_shadow_color => array
229 * Returns the shadow color of <i>e</i>.
231 * e.set_shadow_color(128, 128, 128, 0) #=> nil
232 * e.get_shadow_color #=> [128, 128, 128, 0]
234 static VALUE c_get_shadow_color (VALUE self)
236 GET_COLOR_METHOD (shadow);
241 * e.set_shadow_color(r, g, b, a) => nil
243 * Sets the shadow color of <i>e</i>.
245 * e.set_shadow_color(128, 128, 128, 0) #=> nil
247 static VALUE c_set_shadow_color (VALUE self,
248 VALUE r, VALUE g, VALUE b, VALUE a)
250 SET_COLOR_METHOD (shadow);
255 * e.get_glow_color => array
257 * Returns the glow color of <i>e</i>.
259 * e.set_glow_color(128, 128, 128, 0) #=> nil
260 * e.get_glow_color #=> [128, 128, 128, 0]
262 static VALUE c_get_glow_color (VALUE self)
264 GET_COLOR_METHOD (glow);
269 * e.set_glow_color(r, g, b, a) => nil
271 * Sets the glow color of <i>e</i>.
273 * e.set_glow_color(128, 128, 128, 0) #=> nil
275 static VALUE c_set_glow_color (VALUE self,
276 VALUE r, VALUE g, VALUE b, VALUE a)
278 SET_COLOR_METHOD (glow);
283 * e.get_glow2_color => array
285 * Returns the glow2 color of <i>e</i>.
287 * e.set_glow2_color(128, 128, 128, 0) #=> nil
288 * e.get_glow2_color #=> [128, 128, 128, 0]
290 static VALUE c_get_glow2_color (VALUE self)
292 GET_COLOR_METHOD (glow2);
297 * e.set_glow2_color(r, g, b, a) => nil
299 * Sets the glow2 color of <i>e</i>.
301 * e.set_glow2_color(128, 128, 128, 0) #=> nil
303 static VALUE c_set_glow2_color (VALUE self,
304 VALUE r, VALUE g, VALUE b, VALUE a)
306 SET_COLOR_METHOD (glow2);
311 * e.get_outline_color => array
313 * Returns the outline color of <i>e</i>.
315 * e.set_outline_color(128, 128, 128, 0) #=> nil
316 * e.get_outline_color #=> [128, 128, 128, 0]
318 static VALUE c_get_outline_color (VALUE self)
320 GET_COLOR_METHOD (outline);
325 * e.set_outline_color(r, g, b, a) => nil
327 * Sets the outline color of <i>e</i>.
329 * e.set_outline_color(128, 128, 128, 0) #=> nil
331 static VALUE c_set_outline_color (VALUE self,
332 VALUE r, VALUE g, VALUE b, VALUE a)
334 SET_COLOR_METHOD (outline);
337 static VALUE c_ascent_get (VALUE self)
339 GET_OBJ (self, RbEvasObject, e);
341 return INT2FIX ((int) evas_object_text_ascent_get (e->real));
344 static VALUE c_descent_get (VALUE self)
346 GET_OBJ (self, RbEvasObject, e);
348 return INT2FIX ((int) evas_object_text_descent_get (e->real));
351 static VALUE c_max_ascent_get (VALUE self)
353 GET_OBJ (self, RbEvasObject, e);
355 return INT2FIX ((int) evas_object_text_max_ascent_get (e->real));
358 static VALUE c_max_descent_get (VALUE self)
360 GET_OBJ (self, RbEvasObject, e);
362 return INT2FIX ((int) evas_object_text_max_descent_get (e->real));
365 static VALUE c_advance_get (VALUE self)
369 GET_OBJ (self, RbEvasObject, e);
371 h = (int) evas_object_text_horiz_advance_get (e->real);
372 v = (int) evas_object_text_vert_advance_get (e->real);
374 return rb_ary_new3 (2, INT2FIX (h), INT2FIX (v));
377 static VALUE c_inset_get (VALUE self)
379 GET_OBJ (self, RbEvasObject, e);
381 return INT2FIX ((int) evas_object_text_inset_get (e->real));
384 void Init_Text (void)
388 c = rb_define_class_under (mEvas, "Text", cEvasObject);
390 rb_define_method (c, "initialize", c_init, 1);
391 rb_define_method (c, "font_source", c_font_source_get, 0);
392 rb_define_method (c, "font_source=", c_font_source_set, 1);
393 rb_define_method (c, "get_font", c_get_font, 0);
394 rb_define_method (c, "set_font", c_set_font, 2);
395 rb_define_method (c, "text", c_text_get, 0);
396 rb_define_method (c, "text=", c_text_set, 1);
397 rb_define_method (c, "style", c_style_get, 0);
398 rb_define_method (c, "style=", c_style_set, 1);
399 rb_define_method (c, "style_pad", c_style_pad_get, 0);
400 rb_define_method (c, "get_shadow_color", c_get_shadow_color, 0);
401 rb_define_method (c, "set_shadow_color", c_set_shadow_color, 4);
402 rb_define_method (c, "get_glow_color", c_get_glow_color, 0);
403 rb_define_method (c, "set_glow_color", c_set_glow_color, 4);
404 rb_define_method (c, "get_glow2_color", c_get_glow2_color, 0);
405 rb_define_method (c, "set_glow2_color", c_set_glow2_color, 4);
406 rb_define_method (c, "get_outline_color", c_get_outline_color, 0);
407 rb_define_method (c, "set_outline_color", c_set_outline_color, 4);
409 rb_define_method (c, "ascent", c_ascent_get, 0);
410 rb_define_method (c, "descent", c_descent_get, 0);
411 rb_define_method (c, "max_ascent", c_max_ascent_get, 0);
412 rb_define_method (c, "max_descent", c_max_descent_get, 0);
413 rb_define_method (c, "advance", c_advance_get, 0);
414 rb_define_method (c, "inset", c_inset_get, 0);
416 c2 = rb_define_class_under (mEvas, "Style", c);
418 DEF_CONST (c2, EVAS_TEXT_STYLE_, PLAIN);
419 DEF_CONST (c2, EVAS_TEXT_STYLE_, SHADOW);
420 DEF_CONST (c2, EVAS_TEXT_STYLE_, OUTLINE);
421 DEF_CONST (c2, EVAS_TEXT_STYLE_, SOFT_OUTLINE);
422 DEF_CONST (c2, EVAS_TEXT_STYLE_, GLOW);
423 DEF_CONST (c2, EVAS_TEXT_STYLE_, OUTLINE_SHADOW);
424 DEF_CONST (c2, EVAS_TEXT_STYLE_, FAR_SHADOW);
425 DEF_CONST (c2, EVAS_TEXT_STYLE_, OUTLINE_SOFT_SHADOW);
426 DEF_CONST (c2, EVAS_TEXT_STYLE_, SOFT_SHADOW);
427 DEF_CONST (c2, EVAS_TEXT_STYLE_, FAR_SOFT_SHADOW);