diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/stage.c | 27 | ||||
-rw-r--r-- | src/stage.h | 2 |
2 files changed, 24 insertions, 5 deletions
diff --git a/src/stage.c b/src/stage.c index 20a1fc0..b50bc22 100644 --- a/src/stage.c +++ b/src/stage.c @@ -37,6 +37,7 @@ struct stage_node_t { char name[STAGE_NODE_NAME_MAX]; stage_cached_t cached; aabb_t aabb; /* node coordinates expressed in the space of -1.0...1.0 */ + v2f_t position; /* position of node, optionally used to move aabb as a whole */ float alpha; /* alpha for the texture when composited */ double angle; /* angle for the texture when composited */ unsigned active:1; /* node is active */ @@ -182,6 +183,22 @@ void stage_node_get_aabb(const stage_t *stage, stage_node_t *node, aabb_t *res_a } +/* set the position for a node */ +void stage_node_set_position(const stage_t *stage, stage_node_t *node, float x, float y) +{ + node->position.x = x; + node->position.y = y; +} + + +/* get the position for a node */ +void stage_node_get_position(const stage_t *stage, stage_node_t *node, float *res_x, float *res_y) +{ + *res_x = node->position.x; + *res_y = node->position.y; +} + + /* set a node to active (participates in rendering) */ void stage_node_set_active(const stage_t *stage, stage_node_t *node) { @@ -309,14 +326,14 @@ void stage_fit(const stage_t *stage, int width, int height, int *res_width, int } -static void aabb_to_rect(const aabb_t *aabb, const SDL_Rect *stage_rect, SDL_Rect *res_rect) +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... */ res_rect->x = stage_rect->x; res_rect->y = stage_rect->y; - res_rect->x += ((float)aabb->min.x) * half_w + half_w; - res_rect->y += stage_rect->h - (((float)aabb->max.y) * half_h + half_h); + res_rect->x += ((float)aabb->min.x + pos->x) * half_w + half_w; + res_rect->y += stage_rect->h - (((float)aabb->max.y + pos->y) * half_h + half_h); res_rect->w = (aabb->max.x - aabb->min.x) * half_w; res_rect->h = (aabb->max.y - aabb->min.y) * half_h; @@ -334,7 +351,7 @@ static void render_nodes(list_head_t *head, SDL_Renderer *renderer, SDL_Rect *de continue; /* scale the node's aabb stage coordinates to destination renderer coordinates */ - aabb_to_rect(&node->aabb, dest_rect, &node_rect); + aabb_to_rect(&node->aabb, &node->position, dest_rect, &node_rect); /* if we have a cached texture, see if the dimensions changed */ if (node->cached.texture && @@ -442,7 +459,7 @@ stage_node_t * stage_node_lookup_cartesian(const stage_t *stage, int x, int y) if (!node->active) continue; - aabb_to_rect(&node->aabb, &rect, &node_rect); + aabb_to_rect(&node->aabb, &node->position, &rect, &node_rect); if (x >= node_rect.x && x < node_rect.x + node_rect.w && y >= node_rect.y && y < node_rect.y + node_rect.h) return node; diff --git a/src/stage.h b/src/stage.h index 05ee3ec..ff43847 100644 --- a/src/stage.h +++ b/src/stage.h @@ -44,6 +44,8 @@ stage_node_t * stage_node_free(stage_t *stage, stage_node_t *node); void stage_node_set_alpha(const stage_t *stage, stage_node_t *node, float alpha); void stage_node_set_aabb(const stage_t *stage, stage_node_t *node, const aabb_t *aabb); void stage_node_get_aabb(const stage_t *stage, stage_node_t *node, aabb_t *res_aabb); +void stage_node_set_position(const stage_t *stage, stage_node_t *node, float x, float y); +void stage_node_get_position(const stage_t *stage, stage_node_t *node, float *res_x, float *res_y); void stage_node_set_active(const stage_t *stage, stage_node_t *node); void stage_node_set_inactive(const stage_t *stage, stage_node_t *node); void stage_node_set_locked(const stage_t *stage, stage_node_t *node); |