Mouse Manager - Horizon-NTH/HorizonGUI GitHub Wiki
The MouseManager
class in the hgui
namespace provides a convenient interface for handling various mouse-related
input actions and events in your graphical application. This class is responsible for managing mouse button clicks,
scroll actions, and cursor position tracking.
The class can be found in the header file MouseManager.h
.
-
typedef std::pair<buttons, actions> MouseAction
: Represents a mouse click with specific actions. -
typedef std::tuple<inputs, buttons, actions> MouseCombinationAction
: Represents a combination of mouse inputs alongside a mouse click, and it's associated action.
-
void bind(const std::variant<inputs, std::pair<buttons, actions>, std::tuple<inputs, buttons, actions>& action, const std::function<void()>& function)
: Binds one of the mouses inputs or actions to a user-defined function. -
bool is_bind(const std::variant<inputs, std::pair<buttons, actions>, std::tuple<inputs, buttons, actions>>& action)
: Retrieve if one of the mouses inputs or actions is already bind. -
void unbind(const std::variant<inputs, std::pair<buttons, actions>, std::tuple<inputs, buttons, actions>& action)
: Unbinds a previously bound one of the mouses inputs or actions. -
void bind_click_callback(const std::variant<std::function<void()>, std::function<void(buttons, actions)>>& function)
: Binds a callback function for handling mouse button clicks. -
void bind_scroll_callback(const std::variant<std::function<void()>, std::function<void(double, double)>>& function)
: Binds a callback function for handling mouse scroll events. -
kernel::Point<HGUI_PRECISION> get_position()
: Retrieves the current cursor position as a point vector.
#include <hgui/header/MouseManager.h>
// Example Usage of MouseManager class
hgui::MouseManager::bind(hgui::MouseAction(hgui::buttons::LEFT, hgui::actions::PRESS), [] {
// Handle left mouse button press
});
hgui::MouseManager::bind_clickcallback([](hgui::buttons button, hgui::actions action) {
// Handle mouse button click event
});
hgui::MouseManager::bind_scrollcallback([](double xOffset, double yOffset) {
// Handle mouse scroll event with scroll offsets
});
hgui::dvec2 cursorPosition = hgui::MouseManager::get_position();
// Use cursorPosition as needed
// Unbind mouse input action
hgui::MouseManager::unbind(hgui::MouseAction(hgui::buttons::LEFT, hgui::actions::PRESS));
Note: In the "Example Usage" section, we demonstrate how to bind and unbind mouse input actions, set up callback functions for mouse button clicks and scroll events, and retrieve the cursor position using the
MouseManager
class. This class enables effective handling of mouse-related interactions within your application.