Author Topic: GuiBitmapButtonCtrl::onMouseEnter  (Read 1125 times)

Code: [Select]
package BaseRaiders_Client
{
function GuiBitmapButtonCtrl::onMouseEnter(%obj)
{
echo("Stuff");

parent::onMouseEnter(%obj);

echo("ENTER.");
}
};
activatePackage(BaseRaiders_Client);
This function is called when your mouse hovers over the bricks in the brick selector GUI. Why is it that the echoes never show up and nothing else I try to do happens?

Alright guys listen up, there are a lot of weird things you are going to encounter with guiMouseEventCtrl and I only discovered all of this by using them extensively for the last couple of years.

Bug 1: guiControl::setName() does not automatically associate a guiMouseEventCtrl with the various ::onMoulove() functions that you would expect to be called.  This means that if you create a guiMouseEventCtrl in the gui editor, and then name it "mymousecontrol" or whatever, it will not call mymousecontrol::onMoulove() for that mouse control.  You can fix this by doing a cut-paste of the mouse control in place.  That way it is created already with a name, and will work correctly.

Bug 2: guiMouseEventCtrl::onMouseMove() and the drag functions are only called on one axis at a time.  This means that if you move your mouse on a diagonal, you will get two calls for ::onMouseMove() in a row.  One of them will be for the change in x, one for the change in y.  This means that if you try to make a paint program or something, the user will see something that looks like steps when they try to draw a diagonal line.

There are also a lot of subtle ways the mouse controls handle entering and leaving that may or may not be considered bugs but are extremely complex.

You should also probably stick to using mouse event controls and making sure you are just writing the function for some specific class and not all bitmap buttons.

It's very odd of how the entire onMouseBlah works.

onMouseEnter and the like are only called on a GuiMouseEventCtrl

onMouseEnter and the like are only called on a GuiMouseEventCtrl
Nope. Dump one of the GuiBitmapButtonCtrls used for the brick selector GUI.

Nope. Dump one of the GuiBitmapButtonCtrls used for the brick selector GUI.
One of your add-ons created that, it's never actually called.

Default, onMouseBlah is never called for any class controls. Although, some bitmaps or some buttons might have it, but it's not in the class by default.

What I would do is make the bitmap button controls with names and use ::onMouseEnter with them, see this discussion here.
« Last Edit: September 07, 2015, 06:58:10 PM by Kyuande »

object.dump() will not reveal engine callbacks such as object::onMouseEnter() if they have not been defined already.  However, if you do define one of these particular callbacks, then the engine will call it for you appropriately.  The callback ::onMouseEnter() is not restricted to GuiMouseEventCtrl objects.

Here is a snippet from guiControl.h from the Torque2D engine

Code: [Select]
// Copyright (c) 2013 GarageGames, LLC
#ifndef _GUICONTROL_H_
#define _GUICONTROL_H_

/// @defgroup gui_group Gui System
/// The GUI system in Torque provides a powerful way of creating
/// WYSIWYG User Interfaces for your Game or Application written
/// in Torque. 
///
/// The GUI Provides a range of different controls that you may use
/// to arrange and layout your GUI's, including Buttons, Lists, Bitmaps
/// Windows, Containers, and HUD elements.
///
/// The Base Control Class GuiControl provides a basis upon which to
/// write GuiControl's that may be specific to your particular type
/// of game. 


/// @addtogroup gui_core_group Core
/// @section GuiControl_Intro Introduction
///
/// GuiControl is the base class for GUI controls in Torque. It provides these
/// basic areas of functionality:
///      - Inherits from SimGroup, so that controls can have children.
///      - Interfacing with a GuiControlProfile.
///      - An abstraction from the details of handling user input
///        and so forth, providing friendly hooks like onMouseEnter(), onMouseMove(),
///        and onMouseLeave(), onKeyDown(), and so forth.
///      - An abstraction from the details of rendering and resizing.
///      - Helper functions to manipulate the mouse (mouseLock and
///        mouseUnlock), and convert coordinates (localToGlobalCoord() and
///        globalToLocalCoord()).
///
/// @ref GUI has an overview of the GUI system.
///
///
/// @ingroup gui_group Gui System
/// @{
class GuiControl : public SimGroup
{
private:
   typedef SimGroup Parent;
   typedef GuiControl Children;

public:

    /// Called when a child control of the object is resized
    /// @param   child   Child object
    virtual void childResized(GuiControl *child);

    /// @name Rendering

    /// Called when this control is to render itself
    /// @param   offset   The location this control is to begin rendering
    /// @param   updateRect   The screen area this control has drawing access to
    virtual void onRender(Point2I offset, const RectI &updateRect);

    /// @name Events
    ///
    /// If you subclass these, make sure to call the Parent::'s versions.

    /// Called when this object is asked to wake up returns true if it's actually awake at the end
    virtual bool onWake();

    /// Called when this object is asked to sleep
    virtual void onSleep();

    /// Do special pre-render proecessing
    virtual void onPreRender();

    /// Called when this object is removed
    virtual void onRemove();

    /// Called when one of this objects children is removed
    virtual void onChildRemoved( GuiControl *child );

    /// Called when this object is added to the scene
    bool onAdd();

    /// Called when this object has a new child
    virtual void onChildAdded( GuiControl *child );


    /// General input handler.
    virtual bool onInputEvent(const InputEvent &event);

    /// @name Mouse Events
    /// These functions are called when the input event which is
    /// in the name of the function occurs.

    virtual void onMouseUp(const GuiEvent &event);
    virtual void onMouseDown(const GuiEvent &event);
    virtual void onMouseMove(const GuiEvent &event);
    virtual void onMouseDragged(const GuiEvent &event);
    virtual void onMouseEnter(const GuiEvent &event);
    virtual void onMouseLeave(const GuiEvent &event);

    virtual bool onMouseWheelUp(const GuiEvent &event);
    virtual bool onMouseWheelDown(const GuiEvent &event);

    virtual void onRightMouseDown(const GuiEvent &event);
    virtual void onRightMouseUp(const GuiEvent &event);
    virtual void onRightMouseDragged(const GuiEvent &event);

    virtual void onMiddleMouseDown(const GuiEvent &event);
    virtual void onMiddleMouseUp(const GuiEvent &event);
    virtual void onMiddleMouseDragged(const GuiEvent &event);

    /// @name Editor Mouse Events
    ///
    /// These functions are called when the input event which is
    /// in the name of the function occurs.  Conversly from normal
    /// mouse events, these have a boolean return value that, if
    /// they return true, the editor will NOT act on them or be able
    /// to respond to this particular event.
    ///
    /// This is particularly useful for when writing controls so that
    /// they may become aware of the editor and allow customization
    /// of their data or appearance as if they were actually in use.
    /// For example, the GuiTabBookCtrl catches on mouse down to select
    /// a tab and NOT let the editor do any instant group manipulation.

    /// Called when a mouseDown event occurs on a control and the GUI editor is active
    /// @param   event   the GuiEvent which caused the call to this function
    /// @param   offset   the offset which is representative of the units x and y that the editor takes up on screen
    virtual bool onMouseDownEditor(const GuiEvent &event, Point2I offset) { return false; };

    /// Called when a mouseUp event occurs on a control and the GUI editor is active
    /// @param   event   the GuiEvent which caused the call to this function
    /// @param   offset   the offset which is representative of the units x and y that the editor takes up on screen
    virtual bool onMouseUpEditor(const GuiEvent &event, Point2I offset) { return false; };

    /// Called when a rightMouseDown event occurs on a control and the GUI editor is active
    /// @param   event   the GuiEvent which caused the call to this function
    /// @param   offset   the offset which is representative of the units x and y that the editor takes up on screen
    virtual bool onRightMouseDownEditor(const GuiEvent &event, Point2I offset) { return false; };

    /// Called when a mouseDragged event occurs on a control and the GUI editor is active
    /// @param   event   the GuiEvent which caused the call to this function
    /// @param   offset   the offset which is representative of the units x and y that the editor takes up on screen
    virtual bool onMouseDraggedEditor(const GuiEvent &event, Point2I offset) { return false; };

    /// Occurs when the first responder for this chain is lost
    virtual void onLoseFirstResponder();

    /// @name Keyboard Events

    /// Happens when a key is depressed
    /// @param   event   Event descriptor (which contains the key)
    virtual bool onKeyDown(const GuiEvent &event);

    /// Happens when a key is released
    /// @param   event   Event descriptor (which contains the key)
    virtual bool onKeyUp(const GuiEvent &event);

    /// Happens when a key is held down, resulting in repeated keystrokes.
    /// @param   event   Event descriptor (which contains the key)
    virtual bool onKeyRepeat(const GuiEvent &event);

    /// Occurs when this control performs its "action"
    virtual void onAction();

    /// @name Peer Messaging
    virtual void onMessage(GuiControl *sender, S32 msg);    ///< Receive a message from another control

    /// Called if this object is a dialog, when it is added to the visible layers
    virtual void onDialogPush();

    /// Called if this object is a dialog, when it is removed from the visible layers
    virtual void onDialogPop();
};
/// @}

#endif

The callback ::onMouseEnter() is not restricted to GuiMouseEventCtrl objects.

Well, that those functions are used in c++ doesn't automatically call them in torkscript.

If you look at the mouse event ctrl

Code: guiMouseEventCtrl.cc (43 lines)
-snip-

void GuiMouseEventCtrl::sendMouseEvent(const char * name, const GuiEvent & event)
{
   char buf[3][32];
   dSprintf(buf[0], 32, "%d", event.modifier);
   dSprintf(buf[1], 32, "%d %d", event.mousePoint.x, event.mousePoint.y);
   dSprintf(buf[2], 32, "%d", event.mouseClickCount);
   Con::executef(this, 4, name, buf[0], buf[1], buf[2]);
}

-snip-

void GuiMouseEventCtrl::onMouseDown(const GuiEvent & event)
{
   if(mLockMouse)
      mouseLock();
   sendMouseEvent("onMouseDown", event);
}

void GuiMouseEventCtrl::onMouseUp(const GuiEvent & event)
{
   if(mLockMouse)
      mouseUnlock();
   sendMouseEvent("onMouseUp", event);
}

void GuiMouseEventCtrl::onMouseMove(const GuiEvent & event)
{
   sendMouseEvent("onMouseMove", event);
}

void GuiMouseEventCtrl::onMouseDragged(const GuiEvent & event)
{
   sendMouseEvent("onMouseDragged", event);
}

void GuiMouseEventCtrl::onMouseEnter(const GuiEvent & event)
{
   sendMouseEvent("onMouseEnter", event);
}

-more snip-


Con::executef calls a member function in torkscript. They have to be manually called, and by default only the mouseeventctrl does this.

However, looks like I was slightly wrong in the posts above, Badspot also changed GuiButtonBaseCtrl to call onMouseEnter (and nothing else ...?) in torkscript. Default scripts never use this, so I'm not sure what the point was. Maybe something for RTB?


So on any control that inherits GuiButtonBaseCtrl (like GuiBitmapButtonCtrl) it should actually call onMouseEnter, but onMouseDown, onMouseLeave etc. won't be called.
« Last Edit: September 08, 2015, 06:46:50 AM by Zeblote »