#include "event.h"

/* Updates events. */
void
event_update(Event* self)
{
        SDL_Event event;

        memcpy(&self->prev, &self->curr, sizeof(bool) * EVENT_COUNT);
        memset(&self->curr, '\0', sizeof(bool) * EVENT_COUNT);

        while (SDL_PollEvent(&event))
        {
                switch (event.type)
                {
                        case SDL_QUIT:
                                self->curr[EVENT_QUIT] = true;
                                break;
                        default:
                                break;
                }
        }
}

/* Is a given event pressed? */
bool
event_press(Event* self, EventType type)
{
        return (self->curr[type] && !self->prev[type]);
}

/* Is a given event held? */
bool
event_held(Event* self, EventType type)
{
        return (self->curr[type] && self->prev[type]);
}

/* Is a given event released? */
bool
event_release(Event* self, EventType type)
{
        return (!self->curr[type] && self->prev[type]);
}
