Inside my typical event loop:
bool mouse_was_down = false;
bool want_to_run = true;
while (want_to_run)
{
SDL_Event event = {};
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
{
want_to_run = false;
break;
}
if (event.type == SDL_MOUSEBUTTONDOWN &&
event.button.button == SDL_BUTTON_LEFT)
{
if (mouse_was_down)
{
puts("HELD");
}
else
{
puts("FIRST");
}
if (!mouse_was_down) mouse_was_down = true;
}
if (event.type == SDL_MOUSEBUTTONUP &&
event.button.button == SDL_BUTTON_LEFT)
{
mouse_was_down = false;
}
}
}
If I hold the mouse down, “FIRST” is printed a single time. “HELD” does not get printed at all.
Why?