The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Click count and events
Alvin Beach
Guest

Hello,

Is it expected/normal that when dealing with multiple clicks (double, triple, etc.) that a
SDL_MouseButtonEvent (DOWN/UP) be generated for each intermediate click?

For example, say I want to do something for a single click and something different for a
double-click, I always receive two events when I perform a double-click: one for the first click and
the other for the second click. This results in the single-click code being executed (not desired)
and then the double-click code.

I was expecting to only receive one event when a double-click occurs. Just curious if this is a bug
or just a misunderstanding on my part.

Alvin
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Click count and events
Jeffrey Carpenter
Guest

Alvin,

Hi. I do believe so (if my memory is serving me right!) that it is normal for this behavior to occur. You can use the clicks field of SDL_MouseButtonEvent in order to filter out the undesirable events:

if( ev.type == SDL_MOUSEBUTTONDOWN && ev.button.clicks == 2 )
{
// Execute action
}


Cheers,
Jeffrey Carpenter


On 2014/07/ 09, at 17:34, Alvin Beach wrote:

Quote:
Hello,

Is it expected/normal that when dealing with multiple clicks (double, triple, etc.) that a
SDL_MouseButtonEvent (DOWN/UP) be generated for each intermediate click?

For example, say I want to do something for a single click and something different for a
double-click, I always receive two events when I perform a double-click: one for the first click and
the other for the second click. This results in the single-click code being executed (not desired)
and then the double-click code.

I was expecting to only receive one event when a double-click occurs. Just curious if this is a bug
or just a misunderstanding on my part.

Alvin
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Click count and events
Jonas Kulla
Guest

2014-07-10 0:34 GMT+02:00 Alvin Beach:
Quote:
Hello,

Is it expected/normal that when dealing with multiple clicks (double, triple, etc.) that a
SDL_MouseButtonEvent (DOWN/UP) be generated for each intermediate click?

For example, say I want to do something for a single click and something different for a
double-click, I always receive two events when I perform a double-click: one for the first click and
the other for the second click. This results in the single-click code being executed (not desired)
and then the double-click code.

I was expecting to only receive one event when a double-click occurs. Just curious if this is a bug
or just a misunderstanding on my part.



If you think about it, to get the kind of behavior you are asking for, SDL would have to
setup a timer each time a button down event occurs, and only send the "single click"
event when it is sure (the time period expired) that this click is not part of a double click,
meaning everyone only interested in single clicks would always get (in the context of 
video games) greatly delayed mouse events; not something very desirable in a multimedia
toolkit, don't you think? Wink 
Click count and events
Alvin Beach
Guest

On 09/07/14 20:14, Jonas Kulla wrote:
Quote:
2014-07-10 0:34 GMT+02:00 Alvin Beach <mailto:>:

Hello,

Is it expected/normal that when dealing with multiple clicks (double, triple, etc.) that a
SDL_MouseButtonEvent (DOWN/UP) be generated for each intermediate click?

[snip]


If you think about it, to get the kind of behavior you are asking for, SDL would have to
setup a timer each time a button down event occurs, and only send the "single click"
event when it is sure (the time period expired) that this click is not part of a double click,
meaning everyone only interested in single clicks would always get (in the context of
video games) greatly delayed mouse events; not something very desirable in a multimedia
toolkit, don't you think? Wink


Yeah, that's how I was thinking it could be handled. Didn't make much sense to me either for that
reason as well. Just wanted to be sure. Thanks.

Cheers,

Alvin


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Re: Click count and events
Dominus


Joined: 13 Oct 2009
Posts: 127
Jeffrey Carpenter wrote:
Alvin,

Hi. I do believe so (if my memory is serving me right!) that it is normal for this behavior to occur. You can use the clicks field of SDL_MouseButtonEvent in order to filter out the undesirable events:

if( ev.type == SDL_MOUSEBUTTONDOWN && ev.button.clicks == 2 )
{
// Execute action
}


Cheers,
Jeffrey Carpenter


On 2014/07/ 09, at 17:34, Alvin Beach wrote:

Quote:
Hello,

Is it expected/normal that when dealing with multiple clicks (double, triple, etc.) that a
SDL_MouseButtonEvent (DOWN/UP) be generated for each intermediate click?

For example, say I want to do something for a single click and something different for a
double-click, I always receive two events when I perform a double-click: one for the first click and
the other for the second click. This results in the single-click code being executed (not desired)
and then the double-click code.

I was expecting to only receive one event when a double-click occurs. Just curious if this is a bug
or just a misunderstanding on my part.

Alvin



A year later and this behavior bites me Sad

We have this code in the iOS port of Exult

Code:
int ShortcutBar_gump::handle_event(SDL_Event *event)
{
   if (event->type == SDL_MOUSEBUTTONDOWN || event->type == SDL_MOUSEBUTTONUP) {
      Game_window *gwin = Game_window::get_instance();
      int scale = gwin->get_fastmouse() ? 1 : gwin->get_win()->get_scale_factor();
      int x = event->button.x / scale;
      int y = event->button.y / scale;

#if 0
      std::cout << "clicks:" << (int)event->button.clicks << ", x,y: "
         << x << "," << y << " locx,locy: " << locx << "," << locy
         << " widthXheight: " << width << "X" << height << std::endl;
#endif
      
      if (x >= locx && x <= (locx + width) && y >= locy && y <= (locy + height)) {
         if (event->type == SDL_MOUSEBUTTONDOWN) {
            mouse_down(event, x - locx, y - locy);
         } else if (event->type == SDL_MOUSEBUTTONUP) {
            mouse_up(event, x - locx, y - locy);
         }
         return 1;
      }
   }
   return 0;
}

void ShortcutBar_gump::mouse_down(SDL_Event *event, int mx, int my)
{
   int i;
   for (i = 0; i < numButtons; i++) {
      if (buttonItems[i].rect->has_point(mx, my))
         break;
   }
   if (i == numButtons)
      return;
   
   ShortcutBarButtonItem *item = buttonItems + i;
   item->pushed = true;
   
   lastClickTime = SDL_GetTicks();
}


void ShortcutBar_gump::mouse_up(SDL_Event *event, int mx, int my)
{
   int i;
   
   for (i = 0; i < numButtons; i++) {
      if (buttonItems[i].rect->has_point(mx, my))
         break;
   }
   
   if (i == numButtons) {
      goto Done;
   }
   
   /* NOTE: for every double click,
    * there is usually a previous single click.
    */
   if (event->button.clicks >= 2) {
      onItemClicked(i, true);
   } else {
      onItemClicked(i, false);
   }
   
Done:
   for (i = 0; i < numButtons; i++) {
      buttonItems[i].pushed = false;
   }
}


(see https://github.com/litchie/exult-ios/blob/master/gumps/iphone_gumps.cc#L250)

And I can't fix the part
Code:
if (event->button.clicks >= 2) {
      onItemClicked(i, true);
   } else {
      onItemClicked(i, false);
   }

to differ better between single and double clicks. Can anyone help me?
Click count and events
J. M. B. C.
Guest

You can count a single click as happened, until the timed delay for a double click chance has expired. That manner you know for sure if it is just a single click or an in middle double click click. Yes, there is, a double click click interval milliseconds value stored in some SDL variable.
Expection is to event.mouse.clicks care about that, and just ignore on event->mouse.down and event->mouse.up
// if mouse down or up but click or else then click handling blah blah blah
switch mouse->clicks
{
   case 1:  single_click(); break;
   case 2: double_click(); break;
}
If SDL does not take care of that then there is, or was, or should, an event->mouse.lastclickt and an SDL_GetClickInterval().
P.S.: You sure know better than me. El 15/10/2015 01:50, "Dominus" escribió:
Quote:
Jeffrey Carpenter wrote: Alvin,

Hi. I do believe so (if my memory is serving me right!) that it is normal for this behavior to occur. You can use the clicks field of SDL_MouseButtonEvent in order to filter out the undesirable events:

if( ev.type == SDL_MOUSEBUTTONDOWN && ev.button.clicks == 2 )
{
// Execute action
}


Cheers,
Jeffrey Carpenter
<>

On 2014/07/ 09, at 17:34, Alvin Beach <> wrote:

Quote: Hello,

Is it expected/normal that when dealing with multiple clicks (double, triple, etc.) that a
SDL_MouseButtonEvent (DOWN/UP) be generated for each intermediate click?

For example, say I want to do something for a single click and something different for a
double-click, I always receive two events when I perform a double-click: one for the first click and
the other for the second click. This results in the single-click code being executed (not desired)
and then the double-click code.

I was expecting to only receive one event when a double-click occurs. Just curious if this is a bug
or just a misunderstanding on my part.

Alvin



A year later and this behavior bites me

We have this code in the iOS port of Exult

Code: int ShortcutBar_gump::handle_event(SDL_Event *event)
{
   if (event->type == SDL_MOUSEBUTTONDOWN || event->type == SDL_MOUSEBUTTONUP) {
      Game_window *gwin = Game_window::get_instance();
      int scale = gwin->get_fastmouse() ? 1 : gwin->get_win()->get_scale_factor();
      int x = event->button.x / scale;
      int y = event->button.y / scale;

#if 0
      std::cout << "clicks:" << (int)event->button.clicks << ", x,y: "
         << x << "," << y << " locx,locy: " << locx << "," << locy
         << " widthXheight: " << width << "X" << height << std::endl;
#endif
      
      if (x >= locx && x <= (locx + width) && y >= locy && y <= (locy + height)) {
         if (event->type == SDL_MOUSEBUTTONDOWN) {
            mouse_down(event, x - locx, y - locy);
         } else if (event->type == SDL_MOUSEBUTTONUP) {
            mouse_up(event, x - locx, y - locy);
         }
         return 1;
      }
   }
   return 0;
}

void ShortcutBar_gump::mouse_down(SDL_Event *event, int mx, int my)
{
   int i;
   for (i = 0; i < numButtons; i++) {
      if (buttonItems[i].rect->has_point(mx, my))
         break;
   }
   if (i == numButtons)
      return;
   
   ShortcutBarButtonItem *item = buttonItems + i;
   item->pushed = true;
   
   lastClickTime = SDL_GetTicks();
}


void ShortcutBar_gump::mouse_up(SDL_Event *event, int mx, int my)
{
   int i;
   
   for (i = 0; i < numButtons; i++) {
      if (buttonItems[i].rect->has_point(mx, my))
         break;
   }
   
   if (i == numButtons) {
      goto Done;
   }
   
   /* NOTE: for every double click,
    * there is usually a previous single click.
    */
   if (event->button.clicks >= 2) {
      onItemClicked(i, true);
   } else {
      onItemClicked(i, false);
   }
   
Done:
   for (i = 0; i < numButtons; i++) {
      buttonItems[i].pushed = false;
   }
}


(see https://github.com/litchie/exult-ios/blob/master/gumps/iphone_gumps.cc#L250)

And I can't fix the part
Code: if (event->button.clicks >= 2) {
      onItemClicked(i, true);
   } else {
      onItemClicked(i, false);
   }
to differ better between single and double clicks. Can anyone help me?


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Click count and events
Jonny D


Joined: 12 Sep 2009
Posts: 932
Here are 2 options when considering single vs. double clicks.

Most common: Make their functionality not interfere.  You see this in a particular UI when single click means "select" and double click means "activate".


Less common: Add a delay in processing clicks.  You essentially wait to process clicks until you know that they are not part of a double-click (impossible to predict).  This can make your UI less responsive.  If you have to do it this way, then you might consider it a bug in your UI design.


Jonny D






On Thu, Oct 15, 2015 at 7:23 AM, J. M. B. C. wrote:
Quote:

You can count a single click as happened, until the timed delay for a double click chance has expired. That manner you know for sure if it is just a single click or an in middle double click click. Yes, there is, a double click click interval milliseconds value stored in some SDL variable.
Expection is to event.mouse.clicks care about that, and just ignore on event->mouse.down and event->mouse.up
// if mouse down or up but click or else then click handling blah blah blah
switch mouse->clicks
{
   case 1:  single_click(); break;
   case 2: double_click(); break;
}
If SDL does not take care of that then there is, or was, or should, an event->mouse.lastclickt and an SDL_GetClickInterval().
P.S.: You sure know better than me. El 15/10/2015 01:50, "Dominus" escribió:

Quote:
Jeffrey Carpenter wrote: Alvin,

Hi. I do believe so (if my memory is serving me right!) that it is normal for this behavior to occur. You can use the clicks field of SDL_MouseButtonEvent in order to filter out the undesirable events:

if( ev.type == SDL_MOUSEBUTTONDOWN && ev.button.clicks == 2 )
{
// Execute action
}


Cheers,
Jeffrey Carpenter
<>

On 2014/07/ 09, at 17:34, Alvin Beach <> wrote:

Quote: Hello,

Is it expected/normal that when dealing with multiple clicks (double, triple, etc.) that a
SDL_MouseButtonEvent (DOWN/UP) be generated for each intermediate click?

For example, say I want to do something for a single click and something different for a
double-click, I always receive two events when I perform a double-click: one for the first click and
the other for the second click. This results in the single-click code being executed (not desired)
and then the double-click code.

I was expecting to only receive one event when a double-click occurs. Just curious if this is a bug
or just a misunderstanding on my part.

Alvin



A year later and this behavior bites me

We have this code in the iOS port of Exult

Code: int ShortcutBar_gump::handle_event(SDL_Event *event)
{
   if (event->type == SDL_MOUSEBUTTONDOWN || event->type == SDL_MOUSEBUTTONUP) {
      Game_window *gwin = Game_window::get_instance();
      int scale = gwin->get_fastmouse() ? 1 : gwin->get_win()->get_scale_factor();
      int x = event->button.x / scale;
      int y = event->button.y / scale;

#if 0
      std::cout << "clicks:" << (int)event->button.clicks << ", x,y: "
         << x << "," << y << " locx,locy: " << locx << "," << locy
         << " widthXheight: " << width << "X" << height << std::endl;
#endif
      
      if (x >= locx && x <= (locx + width) && y >= locy && y <= (locy + height)) {
         if (event->type == SDL_MOUSEBUTTONDOWN) {
            mouse_down(event, x - locx, y - locy);
         } else if (event->type == SDL_MOUSEBUTTONUP) {
            mouse_up(event, x - locx, y - locy);
         }
         return 1;
      }
   }
   return 0;
}

void ShortcutBar_gump::mouse_down(SDL_Event *event, int mx, int my)
{
   int i;
   for (i = 0; i < numButtons; i++) {
      if (buttonItems[i].rect->has_point(mx, my))
         break;
   }
   if (i == numButtons)
      return;
   
   ShortcutBarButtonItem *item = buttonItems + i;
   item->pushed = true;
   
   lastClickTime = SDL_GetTicks();
}


void ShortcutBar_gump::mouse_up(SDL_Event *event, int mx, int my)
{
   int i;
   
   for (i = 0; i < numButtons; i++) {
      if (buttonItems[i].rect->has_point(mx, my))
         break;
   }
   
   if (i == numButtons) {
      goto Done;
   }
   
   /* NOTE: for every double click,
    * there is usually a previous single click.
    */
   if (event->button.clicks >= 2) {
      onItemClicked(i, true);
   } else {
      onItemClicked(i, false);
   }
   
Done:
   for (i = 0; i < numButtons; i++) {
      buttonItems[i].pushed = false;
   }
}


(see https://github.com/litchie/exult-ios/blob/master/gumps/iphone_gumps.cc#L250)

And I can't fix the part
Code: if (event->button.clicks >= 2) {
      onItemClicked(i, true);
   } else {
      onItemClicked(i, false);
   }
to differ better between single and double clicks. Can anyone help me?




_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: Click count and events
Dominus


Joined: 13 Oct 2009
Posts: 127
Thank you, I'll see if I can come up with something here. I'm mostly pulling my hair since everything I tried so far didn't work. But I might be able to proceed from these hints.

Dom

J. M. B. C. wrote:
You can count a single click as happened, until the timed delay for a double click chance has expired. That manner you know for sure if it is just a single click or an in middle double click click. Yes, there is, a double click click interval milliseconds value stored in some SDL variable.
Expection is to event.mouse.clicks care about that, and just ignore on event->mouse.down and event->mouse.up
// if mouse down or up but click or else then click handling blah blah blah
switch mouse->clicks
{
   case 1:  single_click(); break;
   case 2: double_click(); break;
}
If SDL does not take care of that then there is, or was, or should, an event->mouse.lastclickt and an SDL_GetClickInterval().
P.S.: You sure know better than me. El 15/10/2015 01:50, "Dominus" escribió:
Quote:
Jeffrey Carpenter wrote: Alvin,

Hi. I do believe so (if my memory is serving me right!) that it is normal for this behavior to occur. You can use the clicks field of SDL_MouseButtonEvent in order to filter out the undesirable events:

if( ev.type == SDL_MOUSEBUTTONDOWN && ev.button.clicks == 2 )
{
// Execute action
}


Cheers,
Jeffrey Carpenter
<>

On 2014/07/ 09, at 17:34, Alvin Beach <> wrote:

Quote: Hello,

Is it expected/normal that when dealing with multiple clicks (double, triple, etc.) that a
SDL_MouseButtonEvent (DOWN/UP) be generated for each intermediate click?

For example, say I want to do something for a single click and something different for a
double-click, I always receive two events when I perform a double-click: one for the first click and
the other for the second click. This results in the single-click code being executed (not desired)
and then the double-click code.

I was expecting to only receive one event when a double-click occurs. Just curious if this is a bug
or just a misunderstanding on my part.

Alvin



A year later and this behavior bites me

We have this code in the iOS port of Exult

Code: int ShortcutBar_gump::handle_event(SDL_Event *event)
{
   if (event->type == SDL_MOUSEBUTTONDOWN || event->type == SDL_MOUSEBUTTONUP) {
      Game_window *gwin = Game_window::get_instance();
      int scale = gwin->get_fastmouse() ? 1 : gwin->get_win()->get_scale_factor();
      int x = event->button.x / scale;
      int y = event->button.y / scale;

#if 0
      std::cout << "clicks:" << (int)event->button.clicks << ", x,y: "
         << x << "," << y << " locx,locy: " << locx << "," << locy
         << " widthXheight: " << width << "X" << height << std::endl;
#endif
      
      if (x >= locx && x <= (locx + width) && y >= locy && y <= (locy + height)) {
         if (event->type == SDL_MOUSEBUTTONDOWN) {
            mouse_down(event, x - locx, y - locy);
         } else if (event->type == SDL_MOUSEBUTTONUP) {
            mouse_up(event, x - locx, y - locy);
         }
         return 1;
      }
   }
   return 0;
}

void ShortcutBar_gump::mouse_down(SDL_Event *event, int mx, int my)
{
   int i;
   for (i = 0; i < numButtons; i++) {
      if (buttonItems[i].rect->has_point(mx, my))
         break;
   }
   if (i == numButtons)
      return;
   
   ShortcutBarButtonItem *item = buttonItems + i;
   item->pushed = true;
   
   lastClickTime = SDL_GetTicks();
}


void ShortcutBar_gump::mouse_up(SDL_Event *event, int mx, int my)
{
   int i;
   
   for (i = 0; i < numButtons; i++) {
      if (buttonItems[i].rect->has_point(mx, my))
         break;
   }
   
   if (i == numButtons) {
      goto Done;
   }
   
   /* NOTE: for every double click,
    * there is usually a previous single click.
    */
   if (event->button.clicks >= 2) {
      onItemClicked(i, true);
   } else {
      onItemClicked(i, false);
   }
   
Done:
   for (i = 0; i < numButtons; i++) {
      buttonItems[i].pushed = false;
   }
}


(see https://github.com/litchie/exult-ios/blob/master/gumps/iphone_gumps.cc#L250)

And I can't fix the part
Code: if (event->button.clicks >= 2) {
      onItemClicked(i, true);
   } else {
      onItemClicked(i, false);
   }
to differ better between single and double clicks. Can anyone help me?


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: Click count and events
Dominus


Joined: 13 Oct 2009
Posts: 127
Jonny D wrote:
Here are 2 options when considering single vs. double clicks.

Most common: Make their functionality not interfere.  You see this in a particular UI when single click means "select" and double click means "activate".


Less common: Add a delay in processing clicks.  You essentially wait to process clicks until you know that they are not part of a double-click (impossible to predict).  This can make your UI less responsive.  If you have to do it this way, then you might consider it a bug in your UI design.


Jonny D



I'll have to take the less common way. Exult is an engine remake of a Dos game, so much use of mouse and shortcut keys. The port to iOS doesn't leave much choice but assigning bot single and double click (or fill the screen with many buttons to press).