Add MKXP.power_state

This commit is contained in:
Inori 2019-09-06 02:36:19 -04:00
parent 9edc2aac8c
commit fa53403a98
2 changed files with 29 additions and 0 deletions

View file

@ -44,6 +44,7 @@
#include <zlib.h>
#include <SDL_filesystem.h>
#include <SDL_power.h>
#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);

View file

@ -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)