Skip to content

Commit

Permalink
Extended commit a4e563d, adding double- and triple-clicks for SDL2 an…
Browse files Browse the repository at this point in the history
…d GL, to SDL1. The logic is almost exactly the same, except that SDL1 lacks SDL_WaitEventTimeout(); fortunately, it was easy to implement that function. See issue #309.
  • Loading branch information
Bill-Gray committed Nov 17, 2023
1 parent a4e563d commit 4f6ff6c
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions sdl1/pdckbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ bool PDC_check_key(void)
return haveevent;
}

int SDL_WaitEventTimeout( SDL_Event *event, int timeout_ms)
{
int rval = 0;

while( timeout_ms && !rval)
{
const int slice_ms = (timeout_ms > 20 ? 20 : timeout_ms);

napms( slice_ms);
rval = SDL_PollEvent( event);
timeout_ms -= slice_ms;
}
return( rval);
}

static int _process_key_event(void)
{
int i, key = 0;
Expand Down Expand Up @@ -291,14 +306,22 @@ static int _process_mouse_event(void)
{
SDL_Event rel;

napms(SP->mouse_wait);

if (SDL_PollEvent(&rel))
while( action != BUTTON_TRIPLE_CLICKED && SDL_WaitEventTimeout(&rel, SP->mouse_wait))
{
if (rel.type == SDL_MOUSEBUTTONUP && rel.button.button == btn)
action = BUTTON_CLICKED;
else
{
if( action == BUTTON_PRESSED)
action = BUTTON_CLICKED;
else if( action == BUTTON_CLICKED)
action = BUTTON_DOUBLE_CLICKED;
else if( action == BUTTON_DOUBLE_CLICKED)
action = BUTTON_TRIPLE_CLICKED;
}
else if(rel.type != SDL_MOUSEBUTTONDOWN || rel.button.button != btn)
{
SDL_PushEvent(&rel);
break;
}
}
}

Expand Down

0 comments on commit 4f6ff6c

Please sign in to comment.