mirror of https://github.com/encounter/SDL.git
SDL_RenderSetIntegerScale
This commit is contained in:
parent
416d046663
commit
167cf14c1f
|
@ -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);
|
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.
|
* \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 */
|
/* Clear the scale because we're setting viewport in output coordinates */
|
||||||
SDL_RenderSetScale(renderer, 1.0f, 1.0f);
|
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 */
|
/* The aspect ratios are the same, just scale appropriately */
|
||||||
scale = (float)w / renderer->logical_w;
|
scale = (float)w / renderer->logical_w;
|
||||||
SDL_RenderSetViewport(renderer, NULL);
|
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
|
int
|
||||||
SDL_RenderSetViewport(SDL_Renderer * renderer, const SDL_Rect * rect)
|
SDL_RenderSetViewport(SDL_Renderer * renderer, const SDL_Rect * rect)
|
||||||
{
|
{
|
||||||
|
|
|
@ -135,6 +135,9 @@ struct SDL_Renderer
|
||||||
int logical_w_backup;
|
int logical_w_backup;
|
||||||
int logical_h_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 */
|
/* The drawable area within the window */
|
||||||
SDL_Rect viewport;
|
SDL_Rect viewport;
|
||||||
SDL_Rect viewport_backup;
|
SDL_Rect viewport_backup;
|
||||||
|
|
Loading…
Reference in New Issue