Skip to content

Commit

Permalink
Added double and triple click detection for SDL2 and GL (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyle-Tafoya committed Nov 17, 2023
1 parent d1c1d26 commit a4e563d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
16 changes: 13 additions & 3 deletions gl/pdckbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,22 @@ static int _process_mouse_event(void)
{
SDL_Event rel;

if (SDL_WaitEventTimeout(&rel, SP->mouse_wait))
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
16 changes: 13 additions & 3 deletions sdl2/pdckbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,22 @@ static int _process_mouse_event(void)
{
SDL_Event rel;

if (SDL_WaitEventTimeout(&rel, SP->mouse_wait))
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 a4e563d

Please sign in to comment.