Implement Graphics.scale

This commit is contained in:
Inori 2019-08-31 00:02:09 -04:00
parent 30c84badf6
commit 8954a5892f
3 changed files with 32 additions and 0 deletions

View file

@ -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" );
}

View file

@ -40,6 +40,7 @@
#include "binding.h"
#include "debugwriter.h"
#include <SDL.h>
#include <SDL_video.h>
#include <SDL_timer.h>
#include <SDL_image.h>
@ -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;

View file

@ -62,6 +62,7 @@ public:
/* Non-standard extension */
DECL_ATTR( Fullscreen, bool )
DECL_ATTR( ShowCursor, bool )
DECL_ATTR( Scale, double )
/* <internal> */
Scene *getScreen() const;