summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/stage.c10
-rw-r--r--src/stage.h2
2 files changed, 6 insertions, 6 deletions
diff --git a/src/stage.c b/src/stage.c
index 7344104..064c739 100644
--- a/src/stage.c
+++ b/src/stage.c
@@ -307,9 +307,9 @@ stage_t * stage_free(stage_t *stage)
/* fit a stage to the supplied dimensions, returns the fitted dimensions in the result pointers */
/* the idea is this can be used in a window resize hook to enforce the stage's aspect ratio */
-void stage_fit(const stage_t *stage, int width, int height, int *res_width, int *res_height)
+void stage_fit(float aspect_ratio, int width, int height, int *res_width, int *res_height)
{
- float full_width = stage->aspect_ratio * ((float)height);
+ float full_width = aspect_ratio * ((float)height);
if (full_width == width) {
/* perfect fit */
@@ -317,7 +317,7 @@ void stage_fit(const stage_t *stage, int width, int height, int *res_width, int
*res_height = height;
} else if (full_width > width) {
/* height is too large */
- *res_height = (1.0f / stage->aspect_ratio) * ((float)width);
+ *res_height = (1.0f / aspect_ratio) * ((float)width);
*res_width = width;
} else {
/* width is too large */
@@ -422,7 +422,7 @@ void stage_render(const stage_t *stage)
/* XXX TODO: investigate renderer viewports and scale factors */
SDL_GetRendererOutputSize(stage->renderer, &width, &height);
- stage_fit(stage, width, height, &rect.w, &rect.h);
+ stage_fit(stage->aspect_ratio, width, height, &rect.w, &rect.h);
rect.x = (width - rect.w) / 2;
rect.y = (height - rect.h) / 2;
@@ -460,7 +460,7 @@ stage_node_t * stage_node_lookup_cartesian(const stage_t *stage, int x, int y)
/* FIXME: copy-pasta with render, factor out */
SDL_GetRendererOutputSize(stage->renderer, &width, &height);
- stage_fit(stage, width, height, &rect.w, &rect.h);
+ stage_fit(stage->aspect_ratio, width, height, &rect.w, &rect.h);
rect.x = (width - rect.w) / 2;
rect.y = (height - rect.h) / 2;
diff --git a/src/stage.h b/src/stage.h
index 6d73753..dd053f8 100644
--- a/src/stage.h
+++ b/src/stage.h
@@ -32,7 +32,7 @@ typedef void (*stage_free_func_t)(void *object);
stage_t * stage_new(SDL_Renderer *renderer, float aspect_ratio);
void stage_clear(stage_t *stage);
stage_t * stage_free(stage_t *stage);
-void stage_fit(const stage_t *stage, int width, int height, int *res_width, int *res_height);
+void stage_fit(float aspect_ratio, int width, int height, int *res_width, int *res_height);
void stage_set_alpha(stage_t *stage, float alpha);
void stage_get_alpha(stage_t *stage, float *res_alpha);
void stage_render(const stage_t *stage);
© All Rights Reserved