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.

Mouse 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 {};

mods int ​

Modifier keys active during this mouse event.

Indicates which keyboard modifiers were held at the time the event was generated. Multiple modifiers may be active depending on platform and input backend. Refer to the source code for enum details.

cpp
int mods {};

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 {0.0f, 0.0f};

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 {0.0f, 0.0f};

The interaction type for this event.

cpp
MouseEvent::Type type {};

window_size Vector2 ​

Size of the window's client area in window coordinates.

Shares the coordinate space of position, so it can be used to normalize cursor positions or drag deltas.

cpp
Vector2 window_size {0.0f, 0.0f};

Functions ​

GetType() Event::Type virtual ​

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

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

Released under the MIT License.