ext/text.c in ray-0.1.1 vs ext/text.c in ray-0.2.0
- old
+ new
@@ -15,17 +15,23 @@
}
static
VALUE ray_text_alloc(VALUE self) {
say_text *text = say_text_create();
- return Data_Wrap_Struct(self, NULL, say_text_free, text);
+ VALUE rb = Data_Wrap_Struct(self, NULL, say_text_free, text);
+
+ say_drawable_set_shader_proc(text->drawable, ray_drawable_shader_proc);
+ say_drawable_set_other_data(text->drawable, (void*)rb);
+
+ return rb;
}
static
VALUE ray_text_init_copy(VALUE self, VALUE orig) {
say_text_copy(ray_rb2text(self), ray_rb2text(orig));
rb_iv_set(self, "@font", rb_iv_get(orig, "@font"));
+ ray_drawable_copy_attr(self, orig);
return self;
}
/* @return [Ray::Font] */
static
@@ -129,11 +135,44 @@
static
VALUE ray_text_rect(VALUE self) {
return ray_rect2rb(say_text_get_rect(ray_rb2text(self)));
}
+/*
+ * @return [Ray::Vector2, nil] Auto-centering ratio. Nil when disabled.
+ */
+static
+VALUE ray_text_auto_center(VALUE self) {
+ say_text *text = ray_rb2text(self);
+ if (say_text_auto_center(text))
+ return ray_vector2_to_rb(say_text_get_auto_center_ratio(text));
+ else
+ return Qnil;
+}
+
+/*
+ * @overload auto_center=(val)
+ * Sets the auto centering ratio. It's a vector2 containing values between 0
+ * and 1 (typically, at least) to determine the center of the text when it is
+ * resized. (0.5, 1), for example, would set the origin to (middle, bottom).
+ *
+ * @param [Ray::Vector2, nil] val New auto centering ratio. If nil, disables
+ * auto-centering.
+ */
+static
+VALUE ray_text_set_auto_center(VALUE self, VALUE center) {
+ say_text *text = ray_rb2text(self);
+
+ if (NIL_P(center))
+ say_text_disable_auto_center(text);
+ else
+ say_text_enable_auto_center(text, ray_convert_to_vector2(center));
+
+ return center;
+}
+
void Init_ray_text() {
ray_cText = rb_define_class_under(ray_mRay, "Text", ray_cDrawable);
rb_define_alloc_func(ray_cText, ray_text_alloc);
rb_define_method(ray_cText, "initialize_copy", ray_text_init_copy, 1);
@@ -152,9 +191,12 @@
rb_define_method(ray_cText, "color", ray_text_color, 0);
rb_define_method(ray_cText, "color=", ray_text_set_color, 1);
rb_define_method(ray_cText, "rect", ray_text_rect, 0);
+
+ rb_define_method(ray_cText, "auto_center", ray_text_auto_center, 0);
+ rb_define_method(ray_cText, "auto_center=", ray_text_set_auto_center, 1);
rb_define_const(ray_cText, "Normal", INT2FIX(SAY_TEXT_NORMAL));
rb_define_const(ray_cText, "Bold", INT2FIX(SAY_TEXT_BOLD));
rb_define_const(ray_cText, "Italic", INT2FIX(SAY_TEXT_ITALIC));
rb_define_const(ray_cText, "Underlined", INT2FIX(SAY_TEXT_UNDERLINED));