diff --git a/binding/graphics-binding.cpp b/binding/graphics-binding.cpp index 2d03e0e3..8ffee11b 100644 --- a/binding/graphics-binding.cpp +++ b/binding/graphics-binding.cpp @@ -97,6 +97,21 @@ shState->graphics().set##PropName(value); \ return rb_bool_new(value); \ } +#define DEF_GRA_PROP_F(PropName) \ +RB_METHOD(graphics##Get##PropName) \ +{ \ +RB_UNUSED_PARAM; \ +return rb_float_new(shState->graphics().get##PropName()); \ +} \ +RB_METHOD(graphics##Set##PropName) \ +{ \ +RB_UNUSED_PARAM; \ +double value; \ +rb_get_args(argc, argv, "f", &value RB_ARG_END); \ +shState->graphics().set##PropName(value); \ +return rb_float_new(value); \ +} + RB_METHOD(graphicsWidth) { RB_UNUSED_PARAM; @@ -219,6 +234,7 @@ DEF_GRA_PROP_I(Brightness) DEF_GRA_PROP_B(Fullscreen) DEF_GRA_PROP_B(ShowCursor) +DEF_GRA_PROP_F(Scale); #define INIT_GRA_PROP_BIND(PropName, prop_name_s) \ { \ @@ -263,4 +279,5 @@ void graphicsBindingInit() INIT_GRA_PROP_BIND( Fullscreen, "fullscreen" ); INIT_GRA_PROP_BIND( ShowCursor, "show_cursor" ); + INIT_GRA_PROP_BIND( Scale, "scale" ); } diff --git a/src/graphics.cpp b/src/graphics.cpp index d1588933..3a39b1da 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -40,6 +40,7 @@ #include "binding.h" #include "debugwriter.h" +#include #include #include #include @@ -1059,6 +1060,19 @@ void Graphics::setShowCursor(bool value) p->threadData->ethread->requestShowCursor(value); } +double Graphics::getScale() const +{ + return (double)p->scSize.y / p->scRes.y; +} + +void Graphics::setScale(double factor) +{ + factor = clamp(factor, 0.5, 2.0); + int widthpx = p->scRes.x * factor; + int heightpx = p->scRes.y * factor; + shState->eThread().requestWindowResize(widthpx, heightpx); +} + Scene *Graphics::getScreen() const { return &p->screen; diff --git a/src/graphics.h b/src/graphics.h index 5f265fce..eba250a8 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -62,6 +62,7 @@ public: /* Non-standard extension */ DECL_ATTR( Fullscreen, bool ) DECL_ATTR( ShowCursor, bool ) + DECL_ATTR( Scale, double ) /* */ Scene *getScreen() const;