MouseEvent
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.
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.
| Value | Description |
|---|---|
| Moved | Cursor moved. |
| ButtonPressed | Button transitioned to the down state. |
| ButtonReleased | Button transitioned to the up state. |
| Scrolled | Scroll 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.
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.
int mods {};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.
Vector2 position {};Scroll delta since the last scroll event. The delta is expressed in abstract scroll units normalized such that positive Y values represent upward scrolling.
Vector2 scroll {};type MouseEvent::Type
The interaction type for this event.
MouseEvent::Type type {};Functions
GetType() Event::Type virtual
Identifies this event as Event::Type::Mouse.
Type vglx::MouseEvent::GetType() const override;