summaryrefslogtreecommitdiffhomepage
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/ruby2d/ruby2d-opal.rb10
-rw-r--r--ext/ruby2d/ruby2d.c11
2 files changed, 13 insertions, 8 deletions
diff --git a/ext/ruby2d/ruby2d-opal.rb b/ext/ruby2d/ruby2d-opal.rb
index 6980e3b..ff372dc 100644
--- a/ext/ruby2d/ruby2d-opal.rb
+++ b/ext/ruby2d/ruby2d-opal.rb
@@ -130,7 +130,6 @@ function render() {
module Ruby2D
-
class Image
def init(path)
`#{self}.data = S2D.CreateImage(path);`
@@ -146,11 +145,14 @@ module Ruby2D
class Text
def init
`#{self}.data = S2D.CreateText(#{self}.font, #{self}.text, #{self}.size);`
+ @width = `#{self}.data.width;`
+ @height = `#{self}.data.height;`
end
- def text=(t)
- @text = t
- `S2D.SetText(#{self}.data, #{self}.text);`
+ def ext_text_set(msg)
+ `S2D.SetText(#{self}.data, #{msg});`
+ @width = `#{self}.data.width;`
+ @height = `#{self}.data.height;`
end
end
diff --git a/ext/ruby2d/ruby2d.c b/ext/ruby2d/ruby2d.c
index 7f530a5..f25587d 100644
--- a/ext/ruby2d/ruby2d.c
+++ b/ext/ruby2d/ruby2d.c
@@ -229,6 +229,9 @@ static R_VAL ruby2d_text_init(R_VAL self) {
NUM2DBL(r_iv_get(self, "@size"))
);
+ r_iv_set(self, "@width", INT2NUM(txt->width));
+ r_iv_set(self, "@height", INT2NUM(txt->height));
+
r_iv_set(self, "@data", r_data_wrap_struct(text, txt));
return R_NIL;
}
@@ -244,14 +247,14 @@ static R_VAL ruby2d_ext_text_set(mrb_state* mrb, R_VAL self) {
#else
static R_VAL ruby2d_ext_text_set(R_VAL self, R_VAL text) {
#endif
-
- // If called before window is shown, return
- if (!r_test(ruby2d_window)) return R_NIL;
-
S2D_Text *txt;
r_data_get_struct(self, "@data", &text_data_type, S2D_Text, txt);
S2D_SetText(txt, RSTRING_PTR(text));
+
+ r_iv_set(self, "@width", INT2NUM(txt->width));
+ r_iv_set(self, "@height", INT2NUM(txt->height));
+
return R_NIL;
}