ext/ruby2d/ruby2d.c in ruby2d-0.7.0 vs ext/ruby2d/ruby2d.c in ruby2d-0.8.0
- old
+ new
@@ -153,10 +153,37 @@
return val > 0 ? val / 32767.0 : val / 32768.0;
}
/*
+ * Ruby2D#self.ext_base_path
+ */
+#if MRUBY
+static R_VAL ruby2d_ext_base_path(mrb_state* mrb, R_VAL self) {
+#else
+static R_VAL ruby2d_ext_base_path(R_VAL self) {
+#endif
+ return r_str_new(SDL_GetBasePath());
+}
+
+
+/*
+ * Ruby2D#self.ext_screenshot
+ */
+#if MRUBY
+static R_VAL ruby2d_ext_screenshot(mrb_state* mrb, R_VAL self) {
+ mrb_value path;
+ mrb_get_args(mrb, "o", &path);
+#else
+static R_VAL ruby2d_ext_screenshot(R_VAL self, R_VAL path) {
+#endif
+ S2D_Screenshot(window, RSTRING_PTR(path));
+ return R_NIL;
+}
+
+
+/*
* Ruby2D::Triangle#ext_render
*/
#if MRUBY
static R_VAL ruby2d_triangle_ext_render(mrb_state* mrb, R_VAL self) {
#else
@@ -427,10 +454,16 @@
R_VAL h = r_iv_get(self, "@flip_height");
if (r_test(h)) spr->height = NUM2DBL(h);
S2D_RotateSprite(spr, NUM2DBL(r_iv_get(self, "@rotate")), S2D_CENTER);
+ R_VAL c = r_iv_get(self, "@color");
+ spr->color.r = NUM2DBL(r_iv_get(c, "@r"));
+ spr->color.g = NUM2DBL(r_iv_get(c, "@g"));
+ spr->color.b = NUM2DBL(r_iv_get(c, "@b"));
+ spr->color.a = NUM2DBL(r_iv_get(c, "@a"));
+
S2D_ClipSprite(
spr,
NUM2INT(r_iv_get(self, "@clip_x")),
NUM2INT(r_iv_get(self, "@clip_y")),
NUM2INT(r_iv_get(self, "@clip_width")),
@@ -670,25 +703,37 @@
return R_NIL;
}
/*
- * Ruby2D::Music#ext_volume
+ * Ruby2D::Music#ext_get_volume
*/
#if MRUBY
-static R_VAL ruby2d_music_ext_volume(mrb_state* mrb, R_VAL self) {
- mrb_value vol;
- mrb_get_args(mrb, "o", &vol);
+static R_VAL ruby2d_music_ext_get_volume(mrb_state* mrb, R_VAL self) {
#else
-static R_VAL ruby2d_music_ext_volume(R_VAL self, R_VAL vol) {
+static R_VAL ruby2d_music_ext_get_volume(R_VAL self) {
#endif
- int mix_vol = NUM2INT(vol) == -1 ? -1 : MIX_MAX_VOLUME * NUM2INT(vol) / 100.0;
- return INT2NUM(ceil(Mix_VolumeMusic(mix_vol) * 100.0 / MIX_MAX_VOLUME));
+ return INT2NUM(S2D_GetMusicVolume());
}
/*
+ * Ruby2D::Music#ext_set_volume
+ */
+#if MRUBY
+static R_VAL ruby2d_music_ext_set_volume(mrb_state* mrb, R_VAL self) {
+ mrb_value volume;
+ mrb_get_args(mrb, "o", &volume);
+#else
+static R_VAL ruby2d_music_ext_set_volume(R_VAL self, R_VAL volume) {
+#endif
+ S2D_SetMusicVolume(NUM2INT(volume));
+ return R_NIL;
+}
+
+
+/*
* Ruby2D::Music#ext_fadeout
*/
#if MRUBY
static R_VAL ruby2d_music_ext_fadeout(mrb_state* mrb, R_VAL self) {
mrb_value ms;
@@ -1067,10 +1112,13 @@
#endif
// Ruby2D
R_CLASS ruby2d_module = r_define_module("Ruby2D");
+ // Ruby2D#self.ext_base_path
+ r_define_class_method(ruby2d_module, "ext_base_path", ruby2d_ext_base_path, r_args_none);
+
// Ruby2D::Triangle
R_CLASS ruby2d_triangle_class = r_define_class(ruby2d_module, "Triangle");
// Ruby2D::Triangle#ext_render
r_define_method(ruby2d_triangle_class, "ext_render", ruby2d_triangle_ext_render, r_args_none);
@@ -1148,13 +1196,16 @@
r_define_method(ruby2d_music_class, "ext_resume", ruby2d_music_ext_resume, r_args_none);
// Ruby2D::Music#ext_stop
r_define_method(ruby2d_music_class, "ext_stop", ruby2d_music_ext_stop, r_args_none);
- // Ruby2D::Music#self.ext_volume
- r_define_class_method(ruby2d_music_class, "ext_volume", ruby2d_music_ext_volume, r_args_req(1));
+ // Ruby2D::Music#self.ext_get_volume
+ r_define_class_method(ruby2d_music_class, "ext_get_volume", ruby2d_music_ext_get_volume, r_args_none);
+ // Ruby2D::Music#self.ext_set_volume
+ r_define_class_method(ruby2d_music_class, "ext_set_volume", ruby2d_music_ext_set_volume, r_args_req(1));
+
// Ruby2D::Music#ext_fadeout
r_define_method(ruby2d_music_class, "ext_fadeout", ruby2d_music_ext_fadeout, r_args_req(1));
// Ruby2D::Window
R_CLASS ruby2d_window_class = r_define_class(ruby2d_module, "Window");
@@ -1165,9 +1216,12 @@
// Ruby2D::Window#ext_add_controller_mappings
r_define_method(ruby2d_window_class, "ext_add_controller_mappings", ruby2d_window_ext_add_controller_mappings, r_args_req(1));
// Ruby2D::Window#ext_show
r_define_method(ruby2d_window_class, "ext_show", ruby2d_window_ext_show, r_args_none);
+
+ // Ruby2D::Window#ext_screenshot
+ r_define_method(ruby2d_window_class, "ext_screenshot", ruby2d_ext_screenshot, r_args_req(1));
// Ruby2D::Window#ext_close
r_define_method(ruby2d_window_class, "ext_close", ruby2d_window_ext_close, r_args_none);
#if MRUBY