summaryrefslogtreecommitdiffhomepage
path: root/ext
diff options
context:
space:
mode:
authorTom Black <[email protected]>2017-06-07 11:26:18 -0400
committerTom Black <[email protected]>2017-06-12 12:09:57 -0400
commita50cbbcfb6c2994e71f2113f1ba3cab77cf1c53f (patch)
tree1bdc38eb75292daf6d798b1dca7b7711a42cf559 /ext
parente8c4dbc50f6305e9e6a3cb3653e0871e3c14d944 (diff)
downloadruby2d-a50cbbcfb6c2994e71f2113f1ba3cab77cf1c53f.tar.gz
ruby2d-a50cbbcfb6c2994e71f2113f1ba3cab77cf1c53f.zip
Set image width and height in constructor
Diffstat (limited to 'ext')
-rw-r--r--ext/ruby2d/ruby2d.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/ext/ruby2d/ruby2d.c b/ext/ruby2d/ruby2d.c
index 3aad03e..d8d6f35 100644
--- a/ext/ruby2d/ruby2d.c
+++ b/ext/ruby2d/ruby2d.c
@@ -174,8 +174,14 @@ static R_VAL ruby2d_image_init(R_VAL self, R_VAL path) {
sprintf(S2D_msg, "Init image: %s", RSTRING_PTR(path));
S2D_Log(S2D_msg, S2D_INFO);
S2D_Image *img = S2D_CreateImage(RSTRING_PTR(path));
- r_iv_set(self, "@width", INT2NUM(img->width));
- r_iv_set(self, "@height", INT2NUM(img->height));
+
+ // Get width and height from Ruby class. If set, use it, else choose the
+ // native dimensions of the image.
+ R_VAL w = r_iv_get(self, "@width");
+ R_VAL h = r_iv_get(self, "@height");
+ r_iv_set(self, "@width" , r_test(w) ? w : INT2NUM(img->width));
+ r_iv_set(self, "@height", r_test(h) ? h : INT2NUM(img->height));
+
r_iv_set(self, "@data", r_data_wrap_struct(image, img));
return R_NIL;
}