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
exult-ios/gumps/iphone_gumps.cc at master · litchie/exult-ios · GitHub
)
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