diff --git a/binding/graphics-binding.cpp b/binding/graphics-binding.cpp index fc93bbfc..7238aa05 100644 --- a/binding/graphics-binding.cpp +++ b/binding/graphics-binding.cpp @@ -241,6 +241,22 @@ RB_METHOD(graphicsResizeScreen) return Qnil; } +RB_METHOD(graphicsResizeWindow) +{ + RB_UNUSED_PARAM; + + int width, height; + bool center = false; + rb_get_args(argc, argv, "ii|b", &width, &height, ¢er RB_ARG_END); + + + GFX_LOCK; + shState->graphics().resizeWindow(width, height, center); + GFX_UNLOCK; + + return Qnil; +} + RB_METHOD(graphicsReset) { RB_UNUSED_PARAM; @@ -371,6 +387,7 @@ void graphicsBindingInit() _rb_define_module_function(module, "fadein", graphicsFadein); _rb_define_module_function(module, "snap_to_bitmap", graphicsSnapToBitmap); _rb_define_module_function(module, "resize_screen", graphicsResizeScreen); + _rb_define_module_function(module, "resize_window", graphicsResizeWindow); _rb_define_module_function(module, "center", graphicsCenter); INIT_GRA_PROP_BIND( Brightness, "brightness" ); diff --git a/src/display/graphics.cpp b/src/display/graphics.cpp index 1e59893a..2b9ff675 100644 --- a/src/display/graphics.cpp +++ b/src/display/graphics.cpp @@ -1325,9 +1325,6 @@ int Graphics::width() const { return p->scRes.x; } int Graphics::height() const { return p->scRes.y; } void Graphics::resizeScreen(int width, int height) { - // width = clamp(width, 1, 640); - // height = clamp(height, 1, 480); - p->threadData->rqWindowAdjust.wait(); Vec2i size(width, height); @@ -1348,7 +1345,21 @@ void Graphics::resizeScreen(int width, int height) { p->threadData->rqWindowAdjust.set(); shState->eThread().requestWindowResize(width, height); - update(); +} + +void Graphics::resizeWindow(int width, int height, bool center) { + p->threadData->rqWindowAdjust.wait(); + //factor = clamp(factor, 0.5, 4.0); + + if (width == p->winSize.x / p->backingScaleFactor && + height == p->winSize.y / p->backingScaleFactor) + return; + + p->threadData->rqWindowAdjust.set(); + shState->eThread().requestWindowResize(width, height); + + if (center) + this->center(); } bool Graphics::updateMovieInput(Movie *movie) { @@ -1518,18 +1529,12 @@ void Graphics::setLastMileScaling(bool value) double Graphics::getScale() const { return (double)(p->winSize.y / p->backingScaleFactor) / p->scRes.y; } void Graphics::setScale(double factor) { - p->threadData->rqWindowAdjust.wait(); - factor = clamp(factor, 0.5, 4.0); - - if (factor == getScale()) - return; + //factor = clamp(factor, 0.5, 4.0); int widthpx = p->scRes.x * factor; int heightpx = p->scRes.y * factor; - p->threadData->rqWindowAdjust.set(); - shState->eThread().requestWindowResize(widthpx, heightpx); - update(); + resizeWindow(widthpx, heightpx); } bool Graphics::getFrameskip() const { return p->useFrameSkip; } diff --git a/src/display/graphics.h b/src/display/graphics.h index e2bcc33f..e32f91ed 100644 --- a/src/display/graphics.h +++ b/src/display/graphics.h @@ -59,6 +59,7 @@ public: int width() const; int height() const; void resizeScreen(int width, int height); + void resizeWindow(int width, int height, bool center=false); void drawMovieFrame(const THEORAPLAY_VideoFrame* video, Bitmap *videoBitmap); bool updateMovieInput(Movie *movie); void playMovie(const char *filename, int volume, bool skippable);