[bug report] Mouse Double and Triple Click needs fixing

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

[bug report] Mouse Double and Triple Click needs fixing

Post by Ulf »

Hi, I'm back! ;-)
Haven't posted for a while, cause I decided I was asking too many questions, and being concerned with any minor detail! Practice practice.
Understanding code or algorithms is great, but practically researching, implementing and testing the code yourself is the only way to learn properly.

Firstly I want to say thank you to CuteAlien for mentioning me in the change log, about the Mouse Double & Triple Click. Thanks.
But I have a problem with it, unless I'm wrong.

I only just started looking at the mouse handling changes yesterday. I been working on other aspects less to do with the Irrlicht engine and more to do with polygons and sprites and scrolling background for the 2d game engine I'm working on... gradually...

The point is, now there is only a double click for the left mouse button!
Am I wrong? I hope so.

In my OnEvent handler I tried the following:

Code: Select all

//! mouse button was double clicked.
case EMIE_MOUSE_DOUBLE_CLICK:
	if (event.MouseInput.isLeftPressed())
		MouseButtonDblClick(event.MouseInput.X, event.MouseInput.Y, MOUSE_BUTTON_LEFT);
	else if (event.MouseInput.isRightPressed())
		MouseButtonDblClick(event.MouseInput.X, event.MouseInput.Y, MOUSE_BUTTON_RIGHT);
	else if (event.MouseInput.isMiddlePressed())
		MouseButtonDblClick(event.MouseInput.X, event.MouseInput.Y, MOUSE_BUTTON_MIDDLE);
	break;
But it doesn't work. I was shocked.. haha ;-) Really.

I suppose it's not common to use double click with other buttons... but why shouldn't it be available?
If it's for one button, it should be for all in my opinion.
The way I had implemented it, you could do it with any button. Even with the extra (X) buttons if they were implemented.

So, am I wrong?
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

Yes this had to be manually hacked into another project I'm working on. I'll move this to bug reports too, keep making great suggestions!
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

That was intentionally left out. Adding it manually to your project is never a problem. But I wouldn't like to ever see an Irrlicht GUI-Element using double-click for other buttons (nor would I like that in any other application, if you add double-click to other mouse buttons your should imho rather rethink your controls). You might notice it's the same for operating systems, some offer double-click - but double-click always means left mouse button.

Can be discussed, but my vote is against adding that.

edit: For the same reason there is no click_x event. If you need something like that then I would see it as some application specific input handling, but not as some common gui-event.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

Blindside wrote:Yes this had to be manually hacked into another project I'm working on. I'll move this to bug reports too, keep making great suggestions!
Thanks Blindside... very much. "shucks"... hahahaha.. just kidding! ;-) But thanks.
CuteAlien wrote:Can be discussed, but my vote is against adding that.
Ok Cute Alien. A different opinion. Fair enough. It's good to have a debate. Thanks for your reply too, though it's not as complimentary as Blindsides.. luv u blindy... hahahaha..
CuteAlien wrote:Adding it manually to your project is never a problem.
It's not technically difficult, but it may become problematic if you have to modify Linux, Windows, and Apple versions of the engine. Haven't looked into it yet.
CuteAlien wrote:But I wouldn't like to ever see an Irrlicht GUI-Element using double-click for other buttons (nor would I like that in any other application, if you add double-click to other mouse buttons your should imho rather rethink your controls)
It shouldn't be about what you LIKE.
It's what is effectively and efficiently practical and what is useful.

If you don't want your GUI elements double clicking with middle button, then just don't do anything with that signal for those gui elements.
Isn't that how event handling works? Each element has it's own handler, and OnEvent() function? I haven't yet been working with menus or gui elements so I don't know.
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You would just check for clicks, and count the time between. That's how it's working for left double click also. No magic, just some code for your event receiver. And perfectly cross-platform.
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

You would just check for clicks, and count the time between. That's how it's working for left double click also. No magic, just some code for your event receiver. And perfectly cross-platform.
Ok.
It needs a structure to keep track of variables such as position and last click time. If it is simple, why implement left button but not the rest?

You already made some variables to monitor double click time, so why not just add the other buttons to it?
That is what is simple.
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Ulf wrote: It shouldn't be about what you LIKE.
It's what is effectively and efficiently practical and what is useful.

If you don't want your GUI elements double clicking with middle button, then just don't do anything with that signal for those gui elements.
Isn't that how event handling works? Each element has it's own handler, and OnEvent() function? I haven't yet been working with menus or gui elements so I don't know.
My argument is that there really is only one double-click event and pressing 2x times on some other button just isn't what you usually call double-click.

But now that we discuss this I start to realize that maybe it could also be written rather different. I did see our double-click as a replacement for the double-click event as send by Windows. Which has not much to do with left or right button of the mouse, but you should think of it as an own event that just accidentally is usually send by the left mouse button. This is an higher level construct than just polling some input-device. But maybe that was a failure, because we don't really use that original event but do indeed instead really just simulate it with left-button + some time in between (as discussed back then).

Offering double-clicks per mouse-button would be an additional thing which is rather independent of that event. So maybe it would be an possible extension - offering per-button events. But if we do that when I would like to see another change - that the old EMIE_MOUSE_DOUBLE_CLICK in this case gets rewritten to use the actual system-event ignoring all doubleclicktime settings when the OS below does actually offer such an event. And only when this is not offered by the system then we simulate it with an EMIE_LMOUSE_DOUBLE_CLICK.

That would be a solution I could agree to - simply because I still have some bad feeling about ignoring the system-event and this would allow supporting both. Though I'm not sure which of those should then be used within the Irrlicht elements EMIE_MOUSE_DOUBLE_CLICK or EMIE_LMOUSE_DOUBLE_CLICK (and once more there are arguments for both). Also it blows up the interface and I don't know if that really is worth it.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

Another reason why you want to support mirror features for both buttons is because a lot of people are left-handed.
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

Dorth wrote:Another reason why you want to support mirror features for both buttons is because a lot of people are left-handed.
That is an excellent example. Good thinking Dorth.

Although you'd have to build options in your app to use it... So you can reverse the buttons.
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Dorth wrote:Another reason why you want to support mirror features for both buttons is because a lot of people are left-handed.
I guess what you would want in that case is defining that double-click does use the other mouse-button. But you wouldn't want another event for that but the same event. You still would want that gui-elements react on double-click. Which is basically what I meant - double-click is not about mouse-buttons but an event that stands on it's own feet. I think in some systems it's even possible to do double-clicks without mouse at all. Right now we miss that ... which was a decision hard discussed already last time. But last time no one mentioned implementing both - "double-click" and "left-mouse-button-clicked-twice" which might be an alternative. Though admittedly not really that high on my priority list right now as there are a lot more urgent open things to do.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

CuteAlien wrote:So maybe it would be an possible extension - offering per-button events.
It is definitely possible.
This is the win32 example from CIrrDeviceWin32.cpp

Code: Select all

if (dev)
{
	dev->postEventFromUser(event);

	if ( event.MouseInput.Event == irr::EMIE_LMOUSE_PRESSED_DOWN )
	{
		irr::u32 clicks = dev->checkSuccessiveClicks(event.MouseInput.X, event.MouseInput.Y);
		if ( clicks == 2 )
		{
			event.MouseInput.Event = irr::EMIE_MOUSE_DOUBLE_CLICK;
			dev->postEventFromUser(event);
		}
		else if ( clicks == 3 )
		{
			event.MouseInput.Event = irr::EMIE_MOUSE_TRIPLE_CLICK;
			dev->postEventFromUser(event);
		}
	}
}

Code: Select all

if (dev)
{
	dev->postEventFromUser(event);

	EMOUSE_INPUT_EVENT e = event.MouseInput.Event;

	irr::u32 clicks = dev->checkSuccessiveClicks(e, event.MouseInput.X, event.MouseInput.Y);
	if ( clicks == 2 )
	{
		switch(e)
                {
                case irr::EMIE_LMOUSE_PRESSED_DOWN:
                       event.MouseInput.Event = irr::EMIE_LMOUSE_DOUBLE_CLICK;
                 case irr::EMIE_RMOUSE_PRESSED_DOWN:
                       event.MouseInput.Event = irr::EMIE_RMOUSE_DOUBLE_CLICK;
                  case irr::EMIE_MMOUSE_PRESSED_DOWN:
                       event.MouseInput.Event = irr::EMIE_MMOUSE_DOUBLE_CLICK;
                }
		dev->postEventFromUser(event);
	}
}
Do the same with triple click.

checkSuccessiveClicks will need to take the mouse button as a parameter.

It would need the DOUBLE_CLICK and TRIPLE_CLICK parameter for each button as shown with double click.

As it works now, only a left double click generates that event.
So if we try to do what I did below, it can not work at all.

Code: Select all

//! mouse button was double clicked.
case EMIE_MOUSE_DOUBLE_CLICK:
   if (event.MouseInput.isLeftPressed())
      MouseButtonDblClick(event.MouseInput.X, event.MouseInput.Y, MOUSE_BUTTON_LEFT);
   else if (event.MouseInput.isRightPressed())
      MouseButtonDblClick(event.MouseInput.X, event.MouseInput.Y, MOUSE_BUTTON_RIGHT);
   else if (event.MouseInput.isMiddlePressed())
      MouseButtonDblClick(event.MouseInput.X, event.MouseInput.Y, MOUSE_BUTTON_MIDDLE);
   break; 
Is it possible to check for the double clicks on each button separately, but not make the extra left, right, and middle double and triple click variables, e.g irr::EMIE_LMOUSE_DOUBLE_CLICK?

The button states get set anyway, and then the above code would work.
Would it?
Or do we need the extra parameters.
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

CuteAlien wrote:Which is basically what I meant - double-click is not about mouse-buttons but an event that stands on it's own feet. I think in some systems it's even possible to do double-clicks without mouse at all.
I don't understand what you mean.

The systems using double click without mouse is just an emulation of a mouse press.
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Ulf wrote:
CuteAlien wrote:So maybe it would be an possible extension - offering per-button events.
It is definitely possible.
I didn't mean possible in the technical sense ;-)

I don't want to add events just to keep some symetry that pleases programmers. Just because it's easy to implement doesn't mean it's also good. Events should have a concrete use case imho. Somehow I'd rather add functions to allow switching the double-click behaviour to another mouse-button (or to using OS system events instead) than adding more events for that, as I would see concrete use-cases for that but not for the right-button doubleclick (or even middle-button-doubleclick!). I don't know any operating system offering that and I don't know any application using that and therefore I don't really see why we should offer it in Irrlicht.

Dorth mentioned a use-case - even a rather good one - but for that use-case it would be better to have a single event and an additional function to control the meaning of double-click than adding more events. Which is something I'd consider implementing.

So far I haven't seen a good use-case for more events. Are there really any or is this just something you think somebody might find useful, but isn't actually a real case?
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Ulf
Posts: 281
Joined: Mon Jun 15, 2009 8:53 am
Location: Australia

Post by Ulf »

I didn't mean possible in the technical sense ;-)
If you didn't mean in a technical sense, then what is not possible?
Pleasing your idea of how it should be done and implementing this at the same time?
Not being rude, just asking what you meant.
CuteAlien wrote:I don't know any operating system offering that .
Really? I do. Its' Windows and here are the defines.
You will notice double click variable for each button.

Code: Select all

#define WM_MOUSEFIRST                   0x0200
#define WM_MOUSEMOVE                    0x0200
#define WM_LBUTTONDOWN                  0x0201
#define WM_LBUTTONUP                    0x0202
#define WM_LBUTTONDBLCLK                0x0203
#define WM_RBUTTONDOWN                  0x0204
#define WM_RBUTTONUP                    0x0205
#define WM_RBUTTONDBLCLK                0x0206
#define WM_MBUTTONDOWN                  0x0207
#define WM_MBUTTONUP                    0x0208
#define WM_MBUTTONDBLCLK                0x0209
CuteAlien wrote:Somehow I'd rather add functions to allow switching the double-click behaviour to another mouse-button (or to using OS system events instead)
There are the OS events up there ^^^ ..
CuteAlien wrote:and I don't know any application using that and therefore I don't really see why we should offer it in Irrlicht.
You haven't used every application available, that's why you haven't seen it in an app.
CuteAlien wrote:Just because it's easy to implement doesn't mean it's also good
True. But it's no reason to doubt its usefulness either.
CuteAlien wrote:So far I haven't seen a good use-case for more events. Are there really any or is this just something you think somebody might find useful, but isn't actually a real case?
I'm not sure how to answer this, but I will think about it.
For now... I'll say

What is the use-case for a left mouse double click?
Is a left mouse button somehow inherently associated with a type of event?
Like making something open?
Or is it able to be applied to whatever event you want in an application?
That's my take on it.
I don't want to add events just to keep some symetry that pleases programmers.
I take that as a valid point.

Windows has it and I'm used to that I suppose.
I think it's a good idea, or I can't really understand why would 1 button have a double click but not the others.
Whatever happens, that's how I think.
I can hear birds chirping
:twisted:

I live in the Eye of Insanity.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

Ulf wrote:
I didn't mean possible in the technical sense ;-)
If you didn't mean in a technical sense, then what is not possible?
Pleasing your idea of how it should be done and implementing this at the same time?
Not being rude, just asking what you meant.
Uhm - I just mean possible as in "something that could be done". That it's not a technical problem is rather obvious.
Ulf wrote:
CuteAlien wrote:I don't know any operating system offering that .
Really? I do. Its' Windows and here are the defines.
You will notice double click variable for each button.
I was so sure that they have only one message for that, that I didn't even look it up again :-( I remembered that obviously completely wrong and made a complete fool of myself. Sorry, my apologies.
Ulf wrote:
CuteAlien wrote:So far I haven't seen a good use-case for more events. Are there really any or is this just something you think somebody might find useful, but isn't actually a real case?
I'm not sure how to answer this, but I will think about it.
For now... I'll say

What is the use-case for a left mouse double click?
Is a left mouse button somehow inherently associated with a type of event?
Like making something open?
Or is it able to be applied to whatever event you want in an application?
That's my take on it.
Well, yes that was my point. That double-click is an action, not a state of mousebuttons. But as you did show I was wrong and Windows indeed just uses this as a state of mousebuttons.

Well - basically that means that yeah - in this case it should have been implemented for all buttons. Don't know why I missed that so completely back then.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply