diff --git a/binding/binding-mri.cpp b/binding/binding-mri.cpp index 63f27665..f3662bb5 100644 --- a/binding/binding-mri.cpp +++ b/binding/binding-mri.cpp @@ -44,6 +44,7 @@ #include #include +#include #ifdef __WIN32__ #define NULL_IO "NUL" @@ -104,6 +105,7 @@ RB_METHOD(mkxpMouseInWindow); RB_METHOD(mkxpPlatform); RB_METHOD(mkxpUserLanguage); RB_METHOD(mkxpGameTitle); +RB_METHOD(mkxpPowerState); RB_METHOD(mriRgssMain); RB_METHOD(mriRgssStop); @@ -181,6 +183,7 @@ static void mriBindingInit() _rb_define_module_function(mod, "platform", mkxpPlatform); _rb_define_module_function(mod, "user_language", mkxpUserLanguage); _rb_define_module_function(mod, "game_title", mkxpGameTitle); + _rb_define_module_function(mod, "power_state", mkxpPowerState); /* Load global constants */ rb_gv_set("MKXP", Qtrue); @@ -312,6 +315,24 @@ RB_METHOD(mkxpGameTitle) return rb_str_new_cstr(shState->config().game.title.c_str()); } +RB_METHOD(mkxpPowerState) +{ + RB_UNUSED_PARAM; + + int secs, pct; + SDL_PowerState ps = SDL_GetPowerInfo(&secs, &pct); + + VALUE hash = rb_hash_new(); + + rb_hash_aset(hash, ID2SYM(rb_intern("seconds")), (secs > -1) ? INT2NUM(secs) : RUBY_Qnil); + + rb_hash_aset(hash, ID2SYM(rb_intern("percent")), (pct > -1) ? INT2NUM(pct) : RUBY_Qnil); + + rb_hash_aset(hash, ID2SYM(rb_intern("discharging")), rb_bool_new(ps == SDL_POWERSTATE_ON_BATTERY)); + + return hash; +} + static VALUE rgssMainCb(VALUE block) { rb_funcall2(block, rb_intern("call"), 0, 0); diff --git a/src/graphics.cpp b/src/graphics.cpp index e2a7f635..e60c4919 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -959,7 +959,15 @@ void Graphics::resizeScreen(int width, int height) FloatRect screenRect(0, 0, width, height); p->screenQuad.setTexPosRect(screenRect, screenRect); + int cur_sz = p->scSize.x; shState->eThread().requestWindowResize(width, height); + + // Give things a little time to recalculate before continuing + for (int i = 0; i < p->frameRate; i++) + { + if (cur_sz != p->scSize.x) break; + update(); + } } void Graphics::playMovie(const char *filename)