diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2018-05-14 23:34:31 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2018-05-15 00:19:02 -0700 |
commit | bcf1646fe89b2e55e8282ea5bed7633ba4d2b8be (patch) | |
tree | f9bb7fee9cb80d35342491012539222cdf2e432d /src/stage.c | |
parent | 0c541e2900c8b886fb44f237bfdc62f9a1ae858b (diff) |
stage: add stage_[sg]et_alpha()
Convenient for whole-stage fades...
Diffstat (limited to 'src/stage.c')
-rw-r--r-- | src/stage.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/stage.c b/src/stage.c index b50bc22..7344104 100644 --- a/src/stage.c +++ b/src/stage.c @@ -52,6 +52,7 @@ struct stage_t { list_head_t layers[STAGE_LAYERS_MAX]; SDL_Renderer *renderer; /* target renderer */ float aspect_ratio; /* width/height ratio of stage, -1.0...1.0 range of node coordinates map to this ratio. */ + float alpha; /* alpha to apply to all nodes */ }; @@ -326,6 +327,20 @@ void stage_fit(const stage_t *stage, int width, int height, int *res_width, int } +/* set the global alpha factor for the stage, the individual node alphas are multiplied by this value @ render time. */ +void stage_set_alpha(stage_t *stage, float alpha) +{ + stage->alpha = alpha; +} + + +/* get the global alpha factor for the stage */ +void stage_get_alpha(stage_t *stage, float *res_alpha) +{ + *res_alpha = stage->alpha; +} + + static void aabb_to_rect(const aabb_t *aabb, const v2f_t *pos, const SDL_Rect *stage_rect, SDL_Rect *res_rect) { float half_w = ((float)stage_rect->w) * .5f, half_h = ((float)stage_rect->h) * .5f; /* FIXME silly to recompute this repeatedly... */ @@ -340,7 +355,7 @@ static void aabb_to_rect(const aabb_t *aabb, const v2f_t *pos, const SDL_Rect *s } -static void render_nodes(list_head_t *head, SDL_Renderer *renderer, SDL_Rect *dest_rect) +static void render_nodes(const stage_t *stage, const list_head_t *head, SDL_Renderer *renderer, SDL_Rect *dest_rect) { stage_node_t *node; @@ -372,7 +387,7 @@ static void render_nodes(list_head_t *head, SDL_Renderer *renderer, SDL_Rect *de node->render(renderer, node->object, node_rect.w, node_rect.h, &node->cached.texture); node->cached.width = node_rect.w; node->cached.height = node_rect.h; - SDL_SetTextureAlphaMod(node->cached.texture, ((float)node->alpha * 255.0f)); + SDL_SetTextureAlphaMod(node->cached.texture, stage->alpha * node->alpha * 255.0f); /* copy the texture to renderer */ if (node->angle == 0) @@ -399,7 +414,7 @@ void stage_get_output_size(stage_t *stage, int *res_width, int *res_height) * will center the rendering and leave blank borders on the edges left empty. * The renderer may be sized precisely by first calling stage_fit(). */ -void stage_render(stage_t *stage) +void stage_render(const stage_t *stage) { SDL_Rect rect; int i, width, height; @@ -414,7 +429,7 @@ void stage_render(stage_t *stage) SDL_RenderClear(stage->renderer); /* TODO: handle -1 on error */ for (i = 0; i < STAGE_LAYERS_MAX; i++) - render_nodes(&stage->layers[i], stage->renderer, &rect); + render_nodes(stage, &stage->layers[i], stage->renderer, &rect); } |