SDL_RenderSetIntegerScale
authorEthan Lee <flibitijibibo@flibitijibibo.com>
Tue, 05 Jan 2016 16:39:18 -0500
changeset 1003956c514efb1fa
parent 10038 2bab6f8d403e
child 10040 e1c7d34f1886
SDL_RenderSetIntegerScale
include/SDL_render.h
src/render/SDL_render.c
src/render/SDL_sysrender.h
     1.1 --- a/include/SDL_render.h	Thu Jan 07 14:02:37 2016 -0500
     1.2 +++ b/include/SDL_render.h	Tue Jan 05 16:39:18 2016 -0500
     1.3 @@ -500,6 +500,30 @@
     1.4  extern DECLSPEC void SDLCALL SDL_RenderGetLogicalSize(SDL_Renderer * renderer, int *w, int *h);
     1.5  
     1.6  /**
     1.7 + *  \brief Set whether to force integer scales for resolution-independent rendering
     1.8 + *
     1.9 + *  \param renderer The renderer for which integer scaling should be set.
    1.10 + *  \param enable   Enable or disable integer scaling
    1.11 + *
    1.12 + *  This function restricts the logical viewport to integer values - that is, when
    1.13 + *  a resolution is between two multiples of a logical size, the viewport size is
    1.14 + *  rounded down to the lower multiple.
    1.15 + *
    1.16 + *  \sa SDL_RenderSetLogicalSize()
    1.17 + */
    1.18 +extern DECLSPEC int SDLCALL SDL_RenderSetIntegerScale(SDL_Renderer * renderer,
    1.19 +                                                      SDL_bool enable);
    1.20 +
    1.21 +/**
    1.22 + *  \brief Get whether integer scales are forced for resolution-independent rendering
    1.23 + *
    1.24 + *  \param renderer The renderer from which integer scaling should be queried.
    1.25 + *
    1.26 + *  \sa SDL_RenderSetIntegerScale()
    1.27 + */
    1.28 +extern DECLSPEC SDL_bool SDLCALL SDL_RenderGetIntegerScale(SDL_Renderer * renderer);
    1.29 +
    1.30 +/**
    1.31   *  \brief Set the drawing area for rendering on the current target.
    1.32   *
    1.33   *  \param renderer The renderer for which the drawing area should be set.
     2.1 --- a/src/render/SDL_render.c	Thu Jan 07 14:02:37 2016 -0500
     2.2 +++ b/src/render/SDL_render.c	Tue Jan 05 16:39:18 2016 -0500
     2.3 @@ -1154,7 +1154,19 @@
     2.4      /* Clear the scale because we're setting viewport in output coordinates */
     2.5      SDL_RenderSetScale(renderer, 1.0f, 1.0f);
     2.6  
     2.7 -    if (SDL_fabs(want_aspect-real_aspect) < 0.0001) {
     2.8 +    if (renderer->integer_scale) {
     2.9 +        if (want_aspect > real_aspect) {
    2.10 +            scale = w / renderer->logical_w;
    2.11 +        } else {
    2.12 +            scale = h / renderer->logical_h;
    2.13 +        }
    2.14 +        viewport.w = (int)SDL_ceil(renderer->logical_w * scale);
    2.15 +        viewport.x = (w - viewport.w) / 2;
    2.16 +        viewport.h = (int)SDL_ceil(renderer->logical_h * scale);
    2.17 +        viewport.y = (h - viewport.h) / 2;
    2.18 +
    2.19 +        SDL_RenderSetViewport(renderer, &viewport);
    2.20 +    } else if (SDL_fabs(want_aspect-real_aspect) < 0.0001) {
    2.21          /* The aspect ratios are the same, just scale appropriately */
    2.22          scale = (float)w / renderer->logical_w;
    2.23          SDL_RenderSetViewport(renderer, NULL);
    2.24 @@ -1216,6 +1228,24 @@
    2.25  }
    2.26  
    2.27  int
    2.28 +SDL_RenderSetIntegerScale(SDL_Renderer * renderer, SDL_bool enable)
    2.29 +{
    2.30 +    CHECK_RENDERER_MAGIC(renderer, -1);
    2.31 +
    2.32 +    renderer->integer_scale = enable;
    2.33 +
    2.34 +    return UpdateLogicalSize(renderer);
    2.35 +}
    2.36 +
    2.37 +SDL_bool
    2.38 +SDLCALL SDL_RenderGetIntegerScale(SDL_Renderer * renderer)
    2.39 +{
    2.40 +    CHECK_RENDERER_MAGIC(renderer, SDL_FALSE);
    2.41 +
    2.42 +    return renderer->integer_scale;
    2.43 +}
    2.44 +
    2.45 +int
    2.46  SDL_RenderSetViewport(SDL_Renderer * renderer, const SDL_Rect * rect)
    2.47  {
    2.48      CHECK_RENDERER_MAGIC(renderer, -1);
     3.1 --- a/src/render/SDL_sysrender.h	Thu Jan 07 14:02:37 2016 -0500
     3.2 +++ b/src/render/SDL_sysrender.h	Tue Jan 05 16:39:18 2016 -0500
     3.3 @@ -135,6 +135,9 @@
     3.4      int logical_w_backup;
     3.5      int logical_h_backup;
     3.6  
     3.7 +    /* Whether or not to force the viewport to even integer intervals */
     3.8 +    SDL_bool integer_scale;
     3.9 +
    3.10      /* The drawable area within the window */
    3.11      SDL_Rect viewport;
    3.12      SDL_Rect viewport_backup;