don't update overlay ranges until all events are polled

This commit is contained in:
Toad King 2013-12-26 20:37:52 -05:00
parent 51c994da39
commit da75ee5a88
3 changed files with 34 additions and 8 deletions

View File

@ -60,6 +60,8 @@ struct overlay_desc
float alpha_mod;
float range_mod;
bool updated;
};
struct overlay
@ -748,15 +750,9 @@ void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out, int16_t
{
struct overlay_desc *desc = &ol->active->descs[i];
if (!inside_hitbox(desc, x, y))
{
desc->range_x_mod = desc->range_x;
desc->range_y_mod = desc->range_y;
continue;
}
// If pressed, change the hitbox.
desc->range_x_mod = desc->range_x * desc->range_mod;
desc->range_y_mod = desc->range_y * desc->range_mod;
desc->updated = true;
if (desc->image.image)
ol->iface->set_alpha(ol->iface_data, desc->image_index,
@ -787,6 +783,30 @@ void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out, int16_t
memset(out, 0, sizeof(*out));
}
void input_overlay_update_range_mod(input_overlay_t *ol)
{
size_t i;
for (i = 0; i < ol->active->size; i++)
{
struct overlay_desc *desc = &ol->active->descs[i];
if (desc->updated)
{
// If pressed this frame, change the hitbox.
desc->range_x_mod = desc->range_x * desc->range_mod;
desc->range_y_mod = desc->range_y * desc->range_mod;
}
else
{
desc->range_x_mod = desc->range_x;
desc->range_y_mod = desc->range_y;
}
desc->updated = false;
}
}
void input_overlay_poll_clear(input_overlay_t *ol)
{
size_t i;
@ -798,6 +818,7 @@ void input_overlay_poll_clear(input_overlay_t *ol)
struct overlay_desc *desc = &ol->active->descs[i];
desc->range_x_mod = desc->range_x;
desc->range_y_mod = desc->range_y;
desc->updated = false;
}
}

View File

@ -46,6 +46,9 @@ bool input_overlay_full_screen(input_overlay_t *ol);
// norm_x and norm_y are the result of input_translate_coord_viewport().
void input_overlay_poll(input_overlay_t *ol, input_overlay_state_t *out, int16_t norm_x, int16_t norm_y);
// called after all the input_overlay_poll calls to update the range modifiers for pressed/unpressed regions
void input_overlay_update_range_mod(input_overlay_t *ol);
// Call when there is nothing to poll. Allows overlay to clear certain state.
void input_overlay_poll_clear(input_overlay_t *ol);

View File

@ -518,7 +518,9 @@ static inline void input_poll_overlay(void)
polled = true;
}
if (!polled)
if (polled)
input_overlay_update_range_mod(driver.overlay);
else
input_overlay_poll_clear(driver.overlay);
}
#endif