Game Development Community

Adding scenewindow2d onMiddleMouse Events

by Unk · in Torque Game Builder · 07/28/2006 (7:55 pm) · 1 replies

For future reference, you can easily add onMiddleMouseDown, onMiddleMouseUp, and onMiddleMouseDragged events to scenewindow2d by making the following minor code changes and building TGB again. The middle mouse is already being captured by the gui but just isn't included in scenewindow2D by default.

-Unk

--------------------

Insert this into t2dSceneWindow.h [line 238]:
void onMiddleMouseDown( const GuiEvent& event );
    void onMiddleMouseUp( const GuiEvent& event );
    void onMiddleMouseDragged( const GuiEvent& event );

Insert this into t2dSceneWindow.cc [line 2302]:
//-----------------------------------------------------------------------------
// Mouse Event Handler.
//-----------------------------------------------------------------------------
void t2dSceneWindow::onMiddleMouseDown( const GuiEvent& event )
{
    // Lock Mouse (if necessary).
    if(mLockMouse)
        mouseLock();

    // Dispatch Mouse Event.
    dispatchMouseEvent("onMiddleMouseDown", event);
}


//-----------------------------------------------------------------------------
// Mouse Event Handler.
//-----------------------------------------------------------------------------
void t2dSceneWindow::onMiddleMouseUp( const GuiEvent& event )
{
    // Lock Mouse (if necessary).
    if(mLockMouse)
        mouseUnlock();

    // Dispatch Mouse Event.
    dispatchMouseEvent("onMiddleMouseUp", event);
}

//-----------------------------------------------------------------------------
// Mouse Event Handler.
//-----------------------------------------------------------------------------
void t2dSceneWindow::onMiddleMouseDragged( const GuiEvent& event )
{
    // Lock Mouse (if necessary).
    if(mLockMouse)
        mouseUnlock();

    // Dispatch Mouse Event.
    dispatchMouseEvent("onMiddleMouseDragged", event);
}

Then in your keybinds.cs file you can use the following:
function sceneWindow2D::onMiddleMouseDown( %this, %modifier, %worldPos, %mouseClicks )
{
   echo("========= EVENT - Keybinds - Middle Mouse Down() =========");
}

function sceneWindow2D::onMiddleMouseUp( %this, %modifier, %worldPos, %mouseClicks )
{
   echo("========= EVENT - Keybinds - Middle Mouse Up() =========");
}

function sceneWindow2D::onMiddleMouseDragged( %this, %modifier, %worldPos, %mouseClicks )
{
   echo("========= EVENT - Keybinds - Middle Mouse Dragged() =========");
}

Edit: Went back and added the onMouseDragged bit.

#1
06/02/2007 (8:41 am)
Anyone able to get middle mouse events to work with behaviors on objects?

I followed this post and added this to my behavior:

function MyBehavior::onMiddleMouseDown(%this, %modifier, %worldPos)

but the onMiddleMouseDown never gets triggered in the behavior right below the onMouseDown and onRightMousDown that do get triggered.