MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ mouse_pressed()

MAYAFLUX_API Vruta::Event MayaFlux::Kriya::mouse_pressed ( std::shared_ptr< Core::Window window,
IO::MouseButtons  button,
std::function< void(double, double)>  callback 
)

Creates an Event coroutine that triggers on specific mouse button press.

Parameters
windowWindow to listen to
buttonMouse button to wait for
callbackFunction to call on button press
Returns
Event coroutine that can be added to EventManager

Example:

[](double x, double y) {
// Handle left mouse button press at (x, y)
});
Vruta::Event mouse_pressed(std::shared_ptr< Core::Window > window, IO::MouseButtons button, std::function< void(double, double)> callback)
Creates an Event coroutine that triggers on specific mouse button press.

Definition at line 77 of file InputEvents.cpp.

81{
82 auto& promise = co_await GetEventPromise {};
83 auto& source = window->get_event_source();
84
85 Vruta::EventFilter filter;
86 filter.event_type = Core::WindowEventType::MOUSE_BUTTON_PRESSED;
87 filter.button = button;
88
89 while (true) {
90 if (promise.should_terminate) {
91 break;
92 }
93
94 co_await EventAwaiter(source, filter);
95
96 auto [x, y] = source.get_mouse_position();
97 callback(x, y);
98 }
99}
Templated awaitable for accessing a coroutine's promise object.
std::optional< IO::MouseButtons > button
std::optional< Core::WindowEventType > event_type
Filter criteria for window events.

References MayaFlux::Vruta::EventFilter::button, MayaFlux::Vruta::EventFilter::event_type, and MayaFlux::Core::MOUSE_BUTTON_PRESSED.

Referenced by MayaFlux::on_mouse_pressed().

+ Here is the caller graph for this function: