From b021a32ac44f5d92fb8dc210d08510d1850a260c Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Thu, 24 May 2018 00:39:52 -0700 Subject: libstage: add stage_[sg]et_position() Starting to get an inkling of a need for a more hierarchical structure for the stage. Something which allows arbitrary grouping of nodes which can then be moved around and even scaled as one at the parent. --- src/stage.c | 15 +++++++++++++++ src/stage.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/stage.c b/src/stage.c index c30f785..7871f8f 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. */ + v2f_t position; /* position of the stage (defaults to 0,0) */ float alpha; /* alpha to apply to all nodes */ }; @@ -339,6 +340,20 @@ void stage_get_alpha(stage_t *stage, float *res_alpha) } +/* set the global position for the stage, all nodes are shifted by this @ render time */ +void stage_set_position(stage_t *stage, v2f_t *position) +{ + stage->position = *position; +} + + +/* get the global position for the stage */ +void stage_get_position(stage_t *stage, v2f_t *res_position) +{ + *res_position = stage->position; +} + + 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... */ diff --git a/src/stage.h b/src/stage.h index d29a763..e16f917 100644 --- a/src/stage.h +++ b/src/stage.h @@ -36,6 +36,8 @@ stage_t * stage_free(stage_t *stage); 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_set_position(stage_t *stage, v2f_t *position); +void stage_get_position(stage_t *stage, v2f_t *res_position); void stage_render(const stage_t *stage); stage_node_t * stage_node_new(stage_t *stage, int layer, const char *name, void *object, stage_render_func_t render_func, stage_free_func_t free_func); -- cgit v1.2.1