Click count and events

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

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
<@Jeffrey_Carpenter>On 2014/07/ 09, at 17:34, Alvin Beach wrote:

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
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

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

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:

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,

AlvinOn 09/07/14 20:14, Jonas Kulla wrote:

2014-07-10 0:34 GMT+02:00 Alvin Beach <@Alvin_Beach mailto:Alvin_Beach>:

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:

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

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 :frowning:

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?> On 2014/07/ 09, at 17:34, Alvin Beach 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?:> 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 [image: 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?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

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 DOn Thu, Oct 15, 2015 at 7:23 AM, 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?:

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 [image: 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?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

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” <@Dominus (@Dominus)> escribi??:

    	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 [Image: http://forums.libsdl.org/images/smiles/icon_sad.gif ]

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 (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
SDL at lists.libsdl.org (SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org (http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

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).