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 GET_COLOR_METHOD(name) \
28 int r = 0, g = 0, b = 0, a = 0; \
30 GET_OBJ (self, RbEvasObject, e); \
32 evas_object_text_##name##_color_get (e->real, &r, &g, &b, &a); \
34 return rb_ary_new3 (4, \
35 INT2FIX (r), INT2FIX (g), \
36 INT2FIX (b), INT2FIX (a));
38 #define SET_COLOR_METHOD(name) \
39 GET_OBJ (self, RbEvasObject, e); \
41 Check_Type (r, T_FIXNUM); \
42 Check_Type (g, T_FIXNUM); \
43 Check_Type (b, T_FIXNUM); \
44 Check_Type (a, T_FIXNUM); \
46 evas_object_text_##name##_color_set (e->real, \
47 FIX2INT (r), FIX2INT (g), \
48 FIX2INT (b), FIX2INT (a)); \
54 * Evas::Text.new(evas) => text
56 * Creates an Evas::Text object.
58 static VALUE c_init (VALUE self, VALUE evas)
60 CHECK_CLASS (evas, cEvas);
61 GET_OBJ (evas, RbEvas, e);
62 GET_OBJ (self, RbEvasObject, text);
64 text->real = evas_object_text_add (e->real);
66 rb_call_super (1, &evas);
73 * text.font_source => string or nil
75 * Returns the font source of <i>text</i>.
77 static VALUE c_font_source_get (VALUE self)
81 GET_OBJ (self, RbEvasObject, e);
83 if (!(tmp = evas_object_text_font_source_get (e->real)))
86 return rb_str_new2 (tmp);
91 * text.font_source(source)
93 * Sets the font source of <i>text</i>.
95 static VALUE c_font_source_set (VALUE self, VALUE val)
97 GET_OBJ (self, RbEvasObject, e);
99 evas_object_text_font_source_set (e->real, StringValuePtr (val));
106 * text.get_font => array
108 * Returns the font name and font size of <i>text</i>.
110 * text.set_font("vera", 10) #=> nil
111 * text_get_font #=> ["vera", 10]
113 static VALUE c_get_font (VALUE self)
115 const char *font = NULL;
116 Evas_Font_Size size = 0;
118 GET_OBJ (self, RbEvasObject, e);
120 evas_object_text_font_get (e->real, &font, &size);
122 return rb_ary_new3 (2, font ? rb_str_new2 (font) : Qnil,
128 * text.set_font(font, size) => nil
130 * Sets the font name and font size of <i>text</i>.
132 * text.set_font("vera", 10) #=> nil
134 static VALUE c_set_font (VALUE self, VALUE font, VALUE size)
136 GET_OBJ (self, RbEvasObject, e);
138 Check_Type (size, T_FIXNUM);
140 evas_object_text_font_set (e->real, StringValuePtr (font),
148 * text.text => string
150 * Returns the text of <i>text</i>.
152 static VALUE c_text_get (VALUE self)
156 GET_OBJ (self, RbEvasObject, e);
158 if (!(tmp = evas_object_text_text_get (e->real)))
161 return rb_str_new2 (tmp);
168 * Sets the text of <i>text</i>.
170 static VALUE c_text_set (VALUE self, VALUE val)
172 GET_OBJ (self, RbEvasObject, e);
174 evas_object_text_text_set (e->real, StringValuePtr (val));
181 * text.style => integer
183 * Returns the style of <i>text</i>.
185 static VALUE c_style_get (VALUE self)
187 GET_OBJ (self, RbEvasObject, e);
189 return INT2FIX (evas_object_text_style_get (e->real));
194 * text.style = integer
196 * Sets the style of <i>text</i>.
198 static VALUE c_style_set (VALUE self, VALUE val)
200 GET_OBJ (self, RbEvasObject, e);
202 Check_Type (val, T_FIXNUM);
204 evas_object_text_style_set (e->real, FIX2INT (val));
209 static VALUE c_style_pad_get (VALUE self)
211 int l = 0, r = 0, t = 0, b = 0;
213 GET_OBJ (self, RbEvasObject, e);
215 evas_object_text_style_pad_get (e->real, &l, &r, &t, &b);
217 return rb_ary_new3 (4,
218 INT2FIX (l), INT2FIX (r),
219 INT2FIX (r), INT2FIX (b));
224 * e.get_shadow_color => array
226 * Returns the shadow color of <i>e</i>.
228 * e.set_shadow_color(128, 128, 128, 0) #=> nil
229 * e.get_shadow_color #=> [128, 128, 128, 0]
231 static VALUE c_get_shadow_color (VALUE self)
233 GET_COLOR_METHOD (shadow);
238 * e.set_shadow_color(r, g, b, a) => nil
240 * Sets the shadow color of <i>e</i>.
242 * e.set_shadow_color(128, 128, 128, 0) #=> nil
244 static VALUE c_set_shadow_color (VALUE self,
245 VALUE r, VALUE g, VALUE b, VALUE a)
247 SET_COLOR_METHOD (shadow);
252 * e.get_glow_color => array
254 * Returns the glow color of <i>e</i>.
256 * e.set_glow_color(128, 128, 128, 0) #=> nil
257 * e.get_glow_color #=> [128, 128, 128, 0]
259 static VALUE c_get_glow_color (VALUE self)
261 GET_COLOR_METHOD (glow);
266 * e.set_glow_color(r, g, b, a) => nil
268 * Sets the glow color of <i>e</i>.
270 * e.set_glow_color(128, 128, 128, 0) #=> nil
272 static VALUE c_set_glow_color (VALUE self,
273 VALUE r, VALUE g, VALUE b, VALUE a)
275 SET_COLOR_METHOD (glow);
280 * e.get_glow2_color => array
282 * Returns the glow2 color of <i>e</i>.
284 * e.set_glow2_color(128, 128, 128, 0) #=> nil
285 * e.get_glow2_color #=> [128, 128, 128, 0]
287 static VALUE c_get_glow2_color (VALUE self)
289 GET_COLOR_METHOD (glow2);
294 * e.set_glow2_color(r, g, b, a) => nil
296 * Sets the glow2 color of <i>e</i>.
298 * e.set_glow2_color(128, 128, 128, 0) #=> nil
300 static VALUE c_set_glow2_color (VALUE self,
301 VALUE r, VALUE g, VALUE b, VALUE a)
303 SET_COLOR_METHOD (glow2);
308 * e.get_outline_color => array
310 * Returns the outline color of <i>e</i>.
312 * e.set_outline_color(128, 128, 128, 0) #=> nil
313 * e.get_outline_color #=> [128, 128, 128, 0]
315 static VALUE c_get_outline_color (VALUE self)
317 GET_COLOR_METHOD (outline);
322 * e.set_outline_color(r, g, b, a) => nil
324 * Sets the outline color of <i>e</i>.
326 * e.set_outline_color(128, 128, 128, 0) #=> nil
328 static VALUE c_set_outline_color (VALUE self,
329 VALUE r, VALUE g, VALUE b, VALUE a)
331 SET_COLOR_METHOD (outline);
334 static VALUE c_ascent_get (VALUE self)
336 GET_OBJ (self, RbEvasObject, e);
338 return INT2FIX ((int) evas_object_text_ascent_get (e->real));
341 static VALUE c_descent_get (VALUE self)
343 GET_OBJ (self, RbEvasObject, e);
345 return INT2FIX ((int) evas_object_text_descent_get (e->real));
348 static VALUE c_max_ascent_get (VALUE self)
350 GET_OBJ (self, RbEvasObject, e);
352 return INT2FIX ((int) evas_object_text_max_ascent_get (e->real));
355 static VALUE c_max_descent_get (VALUE self)
357 GET_OBJ (self, RbEvasObject, e);
359 return INT2FIX ((int) evas_object_text_max_descent_get (e->real));
362 static VALUE c_advance_get (VALUE self)
366 GET_OBJ (self, RbEvasObject, e);
368 h = (int) evas_object_text_horiz_advance_get (e->real);
369 v = (int) evas_object_text_vert_advance_get (e->real);
371 return rb_ary_new3 (2, INT2FIX (h), INT2FIX (v));
374 static VALUE c_inset_get (VALUE self)
376 GET_OBJ (self, RbEvasObject, e);
378 return INT2FIX ((int) evas_object_text_inset_get (e->real));
381 void Init_Text (void)
385 c = rb_define_class_under (mEvas, "Text", cEvasObject);
387 rb_define_method (c, "initialize", c_init, 1);
388 rb_define_method (c, "font_source", c_font_source_get, 0);
389 rb_define_method (c, "font_source=", c_font_source_set, 1);
390 rb_define_method (c, "get_font", c_get_font, 0);
391 rb_define_method (c, "set_font", c_set_font, 2);
392 rb_define_method (c, "text", c_text_get, 0);
393 rb_define_method (c, "text=", c_text_set, 1);
394 rb_define_method (c, "style", c_style_get, 0);
395 rb_define_method (c, "style=", c_style_set, 1);
396 rb_define_method (c, "style_pad", c_style_pad_get, 0);
397 rb_define_method (c, "get_shadow_color", c_get_shadow_color, 0);
398 rb_define_method (c, "set_shadow_color", c_set_shadow_color, 4);
399 rb_define_method (c, "get_glow_color", c_get_glow_color, 0);
400 rb_define_method (c, "set_glow_color", c_set_glow_color, 4);
401 rb_define_method (c, "get_glow2_color", c_get_glow2_color, 0);
402 rb_define_method (c, "set_glow2_color", c_set_glow2_color, 4);
403 rb_define_method (c, "get_outline_color", c_get_outline_color, 0);
404 rb_define_method (c, "set_outline_color", c_set_outline_color, 4);
406 rb_define_method (c, "ascent", c_ascent_get, 0);
407 rb_define_method (c, "descent", c_descent_get, 0);
408 rb_define_method (c, "max_ascent", c_max_ascent_get, 0);
409 rb_define_method (c, "max_descent", c_max_descent_get, 0);
410 rb_define_method (c, "advance", c_advance_get, 0);
411 rb_define_method (c, "inset", c_inset_get, 0);
413 c2 = rb_define_class_under (mEvas, "Style", c);
415 DEF_CONST (c2, EVAS_TEXT_STYLE_, PLAIN);
416 DEF_CONST (c2, EVAS_TEXT_STYLE_, SHADOW);
417 DEF_CONST (c2, EVAS_TEXT_STYLE_, OUTLINE);
418 DEF_CONST (c2, EVAS_TEXT_STYLE_, SOFT_OUTLINE);
419 DEF_CONST (c2, EVAS_TEXT_STYLE_, GLOW);
420 DEF_CONST (c2, EVAS_TEXT_STYLE_, OUTLINE_SHADOW);
421 DEF_CONST (c2, EVAS_TEXT_STYLE_, FAR_SHADOW);
422 DEF_CONST (c2, EVAS_TEXT_STYLE_, OUTLINE_SOFT_SHADOW);
423 DEF_CONST (c2, EVAS_TEXT_STYLE_, SOFT_SHADOW);
424 DEF_CONST (c2, EVAS_TEXT_STYLE_, FAR_SOFT_SHADOW);