Skip to content
Permalink
Browse files

SDL_RenderSetIntegerScale

  • Loading branch information
flibitijibibo committed Jan 5, 2016
1 parent 416d046 commit 167cf14c1fc19b921f03101ef4df433ce09fab00
Showing with 58 additions and 1 deletion.
  1. +24 −0 include/SDL_render.h
  2. +31 −1 src/render/SDL_render.c
  3. +3 −0 src/render/SDL_sysrender.h
@@ -499,6 +499,30 @@ extern DECLSPEC int SDLCALL SDL_RenderSetLogicalSize(SDL_Renderer * renderer, in
*/
extern DECLSPEC void SDLCALL SDL_RenderGetLogicalSize(SDL_Renderer * renderer, int *w, int *h);

/**
* \brief Set whether to force integer scales for resolution-independent rendering
*
* \param renderer The renderer for which integer scaling should be set.
* \param enable Enable or disable integer scaling
*
* This function restricts the logical viewport to integer values - that is, when
* a resolution is between two multiples of a logical size, the viewport size is
* rounded down to the lower multiple.
*
* \sa SDL_RenderSetLogicalSize()
*/
extern DECLSPEC int SDLCALL SDL_RenderSetIntegerScale(SDL_Renderer * renderer,
SDL_bool enable);

/**
* \brief Get whether integer scales are forced for resolution-independent rendering
*
* \param renderer The renderer from which integer scaling should be queried.
*
* \sa SDL_RenderSetIntegerScale()
*/
extern DECLSPEC SDL_bool SDLCALL SDL_RenderGetIntegerScale(SDL_Renderer * renderer);

/**
* \brief Set the drawing area for rendering on the current target.
*
@@ -1154,7 +1154,19 @@ UpdateLogicalSize(SDL_Renderer *renderer)
/* Clear the scale because we're setting viewport in output coordinates */
SDL_RenderSetScale(renderer, 1.0f, 1.0f);

if (SDL_fabs(want_aspect-real_aspect) < 0.0001) {
if (renderer->integer_scale) {
if (want_aspect > real_aspect) {
scale = w / renderer->logical_w;
} else {
scale = h / renderer->logical_h;
}
viewport.w = (int)SDL_ceil(renderer->logical_w * scale);
viewport.x = (w - viewport.w) / 2;
viewport.h = (int)SDL_ceil(renderer->logical_h * scale);
viewport.y = (h - viewport.h) / 2;

SDL_RenderSetViewport(renderer, &viewport);
} else if (SDL_fabs(want_aspect-real_aspect) < 0.0001) {
/* The aspect ratios are the same, just scale appropriately */
scale = (float)w / renderer->logical_w;
SDL_RenderSetViewport(renderer, NULL);
@@ -1215,6 +1227,24 @@ SDL_RenderGetLogicalSize(SDL_Renderer * renderer, int *w, int *h)
}
}

int
SDL_RenderSetIntegerScale(SDL_Renderer * renderer, SDL_bool enable)
{
CHECK_RENDERER_MAGIC(renderer, -1);

renderer->integer_scale = enable;

return UpdateLogicalSize(renderer);
}

SDL_bool
SDLCALL SDL_RenderGetIntegerScale(SDL_Renderer * renderer)
{
CHECK_RENDERER_MAGIC(renderer, SDL_FALSE);

return renderer->integer_scale;
}

int
SDL_RenderSetViewport(SDL_Renderer * renderer, const SDL_Rect * rect)
{
@@ -135,6 +135,9 @@ struct SDL_Renderer
int logical_w_backup;
int logical_h_backup;

/* Whether or not to force the viewport to even integer intervals */
SDL_bool integer_scale;

/* The drawable area within the window */
SDL_Rect viewport;
SDL_Rect viewport_backup;

0 comments on commit 167cf14

Please sign in to comment.