Double Click

Hi Guys
Do you know if there is an easy way to detect double click,
instead of just down or up?

Trish x

In a time of universal deceit, telling the truth is a revolutionary act.

     Do you know if there is an easy way to detect double click,

instead of just down or up?

Check events, etc…

if (event == MOUSE_BUTTONDOWN)
{
if (IsDoubleClick == TRUE)
{

/* Double click detected. */
}
}

Check Double Click;

BOOL IsDoubleClick (void)
{
static ULONG LastClickTicks;
ULONG CurrentClickTicks;

/* First time this function is called, LastClickTicks
    has not been initialised yet. */

if (! LastClickTicks)
{
    LastClickTicks = SDL_GetTicks ();
    return (FALSE);
}

else
{
    CurrentClickTicks = SDL_GetTicks ();

    /* If the period between the two clicks is smaller
        or equal to a pre-defined number, we report a
        DoubleClick event. */

    if (CurrentClickTicks - LastClickTicks <= MAX_TICKS)
    {
        /* Update LastClickTicks and signal a DoubleClick. */

        LastClickTicks = CurrentClickTicks;
        return (TRUE);
    }

    /* Update LastClickTicks and signal a SingleClick. */

    LastClickTicks - CurrentClickTicks;
    return (FALSE);
}

}

Not tested, but this is how I would do it.

Cheers,
Peter

Peter Ketting wrote:

     Do you know if there is an easy way to detect double click,

instead of just down or up?

Check events, etc…
[snip]

Not tested, but this is how I would do it.

Cheers,
Peter

You asked for an easy way and got one from Peter. In practice the
problems start as soon as your render loop gets heavy load and takes
longer than a double click, in which case you can’t detect the double
clicks anymore.

In Linux, the workaround is to handle your events in a separate thread.
For Windows and MacOSX, the only hard way I found was to patch SDL to
add timestamps to the events, and then use these timestamps to see how
much time passed between the clicks. These patches are at

http://www.yasara.org/sdl_patches.zip

But that’s really the hard solution, if someone knows an easier one,
please tell me :wink:

Ciao,
Elmar–
Elmar Krieger, PhD
YASARA Biosciences & CMBI Outstation Austria
Neue-Welt-Hoehe 13/b
A-8042 Graz
Austria/Europe

             Ww
           c(@@)c

================()==OUu============
=WHAT IF YASARA knows the answer?!=
=----- http://www.yasara.org -----=
=- http://www.cmbi.kun.nl/whatif -=
============OOo====================
() ()
/ /

You asked for an easy way and got one from Peter. In practice the
problems start as soon as your render loop gets heavy load and takes
longer than a double click, in which case you can’t detect the double
clicks anymore.

Maybe if you recorded how many ticks it took to render and re-calibrate the
maximum number of ticks allowed between clicks for it to be a double-click?
Probably not an ideal solution, but it just might work.

Cheers,
Peter

Well, at least on Windows there are specific double click messages.

Just search the SDK documentation for WM_LBUTTONDBLCLK.

Now since this is the SDL mailing list I guess that you want to do
it in a portable way.

So just patch SDL event loop to process these messages and provide
the information on the SDL_event structure. Maybe this could then
be integrated on the standard SDL.

Cheers,
Paulo

Elmar Krieger schrieb:> Peter Ketting wrote:

     Do you know if there is an easy way to detect double click,

instead of just down or up?

Check events, etc…

[snip]

Not tested, but this is how I would do it.

Cheers,
Peter

You asked for an easy way and got one from Peter. In practice the
problems start as soon as your render loop gets heavy load and takes
longer than a double click, in which case you can’t detect the double
clicks anymore.

In Linux, the workaround is to handle your events in a separate thread.
For Windows and MacOSX, the only hard way I found was to patch SDL to
add timestamps to the events, and then use these timestamps to see how
much time passed between the clicks. These patches are at

http://www.yasara.org/sdl_patches.zip

But that’s really the hard solution, if someone knows an easier one,
please tell me :wink:

Ciao,
Elmar

Well, at least on Windows there are specific double click messages.

Just search the SDK documentation for WM_LBUTTONDBLCLK.

Now since this is the SDL mailing list I guess that you want to do
it in a portable way.

So just patch SDL event loop to process these messages and provide
the information on the SDL_event structure. Maybe this could then
be integrated on the standard SDL.

That part i easy: just come up with a reason why Tux Paint needs double
clicks and it sorts it self out just fine :wink:

On a more serious note: I whould be glad if double clicks and key repeat
was added to 1.3 event system, since it would give everybody’s homegrown
GUI-system a bit more native feeling.On Sun, 6 May 2007, Paulo Pinto wrote:

On a more serious note: I whould be glad if double clicks and key
repeat
was added to 1.3 event system, since it would give everybody’s
homegrown
GUI-system a bit more native feeling.

I agree with double click, but key repeat is in 1.2.

RegardsOn 7 May 2007, at 2:46 PM, Mattias Karlsson wrote:


Kuon

“Your computer requests another OS, deny or allow?”
“You should stop playing with that, or it will eventually works.”

Company website:
http://www.goyman.com/

Personal blog:
http://arkhi.goyman.com/blojsom/blog/default/

Hey now… 100,000+ downloads per month can’t be wrong! ;)On Mon, May 07, 2007 at 02:46:18PM +0200, Mattias Karlsson wrote:

That part i easy: just come up with a reason why Tux Paint needs double
clicks and it sorts it self out just fine :wink:


-bill!
bill at newbreedsoftware.com
http://www.newbreedsoftware.com/

On a more serious note: I whould be glad if double clicks and key
repeat
was added to 1.3 event system, since it would give everybody’s
homegrown
GUI-system a bit more native feeling.

I agree with double click, but key repeat is in 1.2.

Well, the key repeat that is in 1.2 is only syntax suger if you ask me.
Now, if it had a way to use enable the OS defaults it would be a diffrent
thing.

As in, behave the same way the user configured for the rest of their OS?
Yes, that’d be dandy. Ditto fro double-click.

Of course, at this rate, we’re getting a little beyond
SIMPLE DirectMedia Layer, but I think these kinds of things are probably
not too complicated or bloated. Folks may want to look into other, more
well-behaved widget sets, though (like wxWidgets or Qt?) shrugOn Mon, May 07, 2007 at 06:31:57PM +0200, Mattias Karlsson wrote:

Well, the key repeat that is in 1.2 is only syntax suger if you ask me.
Now, if it had a way to use enable the OS defaults it would be a diffrent
thing.


-bill!
bill at newbreedsoftware.com
http://www.newbreedsoftware.com/

Well, the key repeat that is in 1.2 is only syntax suger if you ask me.
Now, if it had a way to use enable the OS defaults it would be a diffrent
thing.

As in, behave the same way the user configured for the rest of their OS?
Yes, that’d be dandy. Ditto fro double-click.

Exactly. Now, I havent checked that bit of code in ages but earlier
versions of SDL had special code to detect key repeat so it can be
ignored.

Of course, at this rate, we’re getting a little beyond
SIMPLE DirectMedia Layer, but I think these kinds of things are probably
not too complicated or bloated. Folks may want to look into other, more
well-behaved widget sets, though (like wxWidgets or Qt?) shrug

My definition of what “Simple” means changed quite a long time a go. In
SDL 1.1 (when I discovered SDL) it used to mean “realy low level”,
but as time has passed it is more and more a case of “easy to use” instead.

And I think it’s starting to get realy bloated as well. The build I use
for development is only about 1/3 the size of a default build, and it
still contains video, events, threads and timers…

I havent checked yet, but I have a gut feeling I can remove atleast 1/3 of
the remaining size by letting my GUI library talk directly to the
SDL-backends.On Mon, 7 May 2007, Bill Kendrick wrote:

On Mon, May 07, 2007 at 06:31:57PM +0200, Mattias Karlsson wrote: