Skip to content

MouseEvent

Represents a mouse input event.

A mouse event is dispatched when the cursor moves, a button is pressed or released, or the scroll wheel is used. It extends the base Event with data specific to mouse input: the interaction type, the cursor position, and optional button information.

Events are dispatched through the Scene hierarchy where nodes can override the Node::OnMouseEvent handler and optionally mark the event as handled. When handled is set to true, the event stops propagating to other nodes.

cpp
class MyNode : public vglx::Node {
public:
  auto OnMouseEvent(vglx::MouseEvent* event) -> void override {
    if (event->type == vglx::MouseEvent::Type::ButtonPressed) {
      if (event->button == vglx::MouseButton::Left) {
        // do something...
        event->handled = true; // stop propagation
      }
    }
  }
};

INFO

Derives from Event and inherits all public properties and methods.

Types

MouseEvent::Type enum

Enumerates all mouse event types.

Distinguishes between cursor movement, button transitions, and scroll actions. Engines that support continuous mouse tracking or gesture recognition should implement those behaviors at a higher layer.

ValueDescription
MovedCursor moved.
ButtonPressedButton transitioned to the down state.
ButtonReleasedButton transitioned to the up state.
ScrolledScroll wheel moved.

Properties

button MouseButton

Mouse button associated with the event, if any. Identifies which button triggered the event using the mouse button enumeration. Refer to the source code for enum details.

cpp
MouseButton button {};

position Vector2

Current cursor position in window coordinates. The coordinate origin is always the top-left corner of the window: X increases to the right and Y increases downward.

cpp
Vector2 position {};

scroll Vector2

Scroll delta since the last scroll event. The delta is expressed in abstract scroll units normalized such that positive Y values represent upward scrolling.

cpp
Vector2 scroll {};

The interaction type for this event.

cpp
MouseEvent::Type type {};

Functions

GetType() Event::Type virtual

Identifies this event as Event::Type::Mouse.

cpp
Type vglx::MouseEvent::GetType() const override;

Released under the MIT License.