Game Development Community

onMouseDown() issue

by Amjad Yahya · in Torque 2D Beginner · 10/02/2013 (3:04 am) · 6 replies

It seems that onMouseDown() does not get triggered at all, I set:
mySceneWindow.setUseObjectInputEvents(true);
object.setUseInputEvents(true);
onRightMouseDown() also behaves the same way.

I usually use onTouchDown() which works fine, then I needed to use the right mouse button, that's when I discovered it does not work.

#1
10/02/2013 (6:53 am)
See SceneWindow.cc, line 103. They're there, except that all left mouse functions are called "touch" instead and are assigned to input events, whereas the right mouse events are called "mouse" and assigned to mouse events. So not sure what's going on without sitting down with a debugger....
#2
10/02/2013 (7:04 am)
SceneWindow.cc is the right place to look.

Towards the top of the file:

// Input event names.
static StringTableEntry inputEventEnterName  = StringTable->insert("onTouchEnter");
static StringTableEntry inputEventLeaveName  = StringTable->insert("onTouchLeave");
static StringTableEntry inputEventDownName = StringTable->insert("onTouchDown");
static StringTableEntry inputEventUpName = StringTable->insert("onTouchUp");
static StringTableEntry inputEventMovedName = StringTable->insert("onTouchMoved");
static StringTableEntry inputEventDraggedName = StringTable->insert("onTouchDragged");

static StringTableEntry mouseEventMiddleMouseDownName = StringTable->insert("onMiddleMouseDown");
static StringTableEntry mouseEventMiddleMouseUpName = StringTable->insert("onMiddleMouseUp");
static StringTableEntry mouseEventMiddleMouseDraggedName = StringTable->insert("onMiddleMouseDragged");

static StringTableEntry mouseEventRightMouseDownName = StringTable->insert("onRightMouseDown");
static StringTableEntry mouseEventRightMouseUpName = StringTable->insert("onRightMouseUp");
static StringTableEntry mouseEventRightMouseDraggedName = StringTable->insert("onRightMouseDragged");

static StringTableEntry mouseEventWheelUpName = StringTable->insert("onMouseWheelUp");
static StringTableEntry mouseEventWheelDownName = StringTable->insert("onMouseWheelDown");

static StringTableEntry mouseEventEnterName = StringTable->insert("onMouseEnter");
static StringTableEntry mouseEventLeaveName = StringTable->insert("onMouseLeave");

Those are all the input event names. onMouseDown/Up/Dragged don't exist anymore, they were replaced with the onTouch callbacks. At the SceneWindow level, there are functions that pass the onMouseDown to onTouchDown which is why that still works, but not for SceneObject input events.

In this function is a "white list" with the allowable input event names for SceneObjects:
void SceneWindow::sendObjectInputEvent( StringTableEntry name, const GuiEvent& event )
{
    // Debug Profiling.
    PROFILE_SCOPE(SceneWindow_SendObjectInputEvent);

    // Finish if we're not bound to a scene?
    if ( !getScene() ) return;

    // Only process appropriate input events.
    if ( !( name == inputEventDownName ||
            name == inputEventUpName ||
            name == inputEventMovedName ||
            name == inputEventDraggedName ) )
        return;

Inside the if statement you would need to re-add the right mouse event names for it to work again.
#3
10/02/2013 (8:11 am)
Thanks Richard and Mike. It's a total success.

I've changed the code to
// Debug Profiling.
    PROFILE_SCOPE(SceneWindow_SendObjectInputEvent);

    // Finish if we're not bound to a scene?
    if ( !getScene() ) return;

    // Only process appropriate input events.
    if ( !( name == inputEventDownName ||
            name == inputEventUpName ||
            name == inputEventMovedName ||
            name == inputEventDraggedName ||
	    name == mouseEventRightMouseDownName ||
            name == mouseEventRightMouseUpName ||
            name == mouseEventRightMouseDraggedName ) )
        return;

I wonder why the right mouse was omitted in the first place!!
#4
10/02/2013 (8:19 am)
My guess is that that section of the code came from iT2D instead of TGB when both codebases were merged for the MIT version.
#5
10/02/2013 (8:44 am)
Ah, that makes sense, I hope you won't forget to update it in the development branch for everyone to benefit from.
#6
10/02/2013 (12:48 pm)
Thanks Mike - I don't have much free time these days so I'm glad you knew where to find the other half of that puzzle!