Brenta Engine 1.2
Loading...
Searching...
No Matches
brenta::input Class Reference

Input subsystem. More...

#include <input.hpp>

Inheritance diagram for brenta::input:
brenta::subsystem

Data Structures

class  builder
 

Public Member Functions

std::expected< void, subsystem::error > initialize () override
 Initialize the input system.
 
std::expected< void, subsystem::error > terminate () override
 Cleans up resources.
 
std::string name () override
 Returns the name of the sybsystem.
 
bool is_initialized () override
 Returns true if the subsystem is initialized.
 
- Public Member Functions inherited from brenta::subsystem

Static Public Member Functions

static inputinstance ()
 
static void add_keyboard_callback (int key, std::function< void()> callback)
 Add a keyboard callback.
 
static void remove_keyboard_callback (int key)
 Remove a keyboard callback.
 
static void key_callback (GLFWwindow *window, int key, int scancode, int action, int mods)
 Keyboard callback.
 
static void add_mouse_pos_callback (types::mouse_callback_name_t name, std::function< void(double, double)> callback)
 Add a mouse position callback.
 
static void remove_mouse_pos_callback (types::mouse_callback_name_t callback_name)
 Remove a mouse position callback.
 
static void mouse_pos_callback (GLFWwindow *window, double xpos, double ypos)
 Mouse position callback.
 

Static Public Attributes

static const std::string subsystem_name = "input"
 

Additional Inherited Members

- Public Types inherited from brenta::subsystem
using error = std::string
 

Detailed Description

Input subsystem.

This subsystem is used to add and remove callbacks for keyboard and mouse events. You can define your own callbacks and register them with the input subsystem.

Definition at line 34 of file input.hpp.

Member Function Documentation

◆ add_keyboard_callback()

void input::add_keyboard_callback ( int key,
std::function< void()> callback )
static

Add a keyboard callback.

This function adds a callback to a key press event. The callback is a function that takes no arguments and returns void. The key enum is defined in GLFW. When the key is pressed, the callback is called.

Parameters
keyThe key to add the callback to
callbackThe callback function

Definition at line 67 of file input.cpp.

◆ add_mouse_pos_callback()

void input::add_mouse_pos_callback ( types::mouse_callback_name_t name,
std::function< void(double, double)> callback )
static

Add a mouse position callback.

This function adds a callback to a mouse position event. The callback is a function that takes two doubles and returns void. The two doubles are the x and y position of the mouse. When the mouse is moved, the callback is called.

Parameters
nameThe name of the callback
callbackThe callback function

Definition at line 100 of file input.cpp.

◆ initialize()

std::expected< void, subsystem::error > input::initialize ( )
overridevirtual

Initialize the input system.

This function initializes the input subsystem. It should be called before any other input function is called.

Implements brenta::subsystem.

Definition at line 26 of file input.cpp.

◆ instance()

input & input::instance ( )
static

Definition at line 61 of file input.cpp.

◆ is_initialized()

bool input::is_initialized ( )
overridevirtual

Returns true if the subsystem is initialized.

Implements brenta::subsystem.

Definition at line 52 of file input.cpp.

◆ key_callback()

void input::key_callback ( GLFWwindow * window,
int key,
int scancode,
int action,
int mods )
static

Keyboard callback.

This function is called when a key is pressed. It calls the callback function associated with the key.

Parameters
windowThe window that received the event
keyThe key that was pressed or released
scancodeThe system-specific scancode of the key
actionThe GLFW key action (GLFW_PRESS...)
modsBit field describing which modifier keys were held down

Definition at line 86 of file input.cpp.

◆ mouse_pos_callback()

void input::mouse_pos_callback ( GLFWwindow * window,
double xpos,
double ypos )
static

Mouse position callback.

This function is called when the mouse is moved. It calls the callback function associated with the mouse position.

Parameters
windowThe window that received the event
xposThe new x-coordinate, in screen coordinates, of the cursor
yposThe new y-coordinate, in screen coordinates, of the cursor

Definition at line 123 of file input.cpp.

◆ name()

std::string input::name ( )
overridevirtual

Returns the name of the sybsystem.

Implements brenta::subsystem.

Definition at line 47 of file input.cpp.

◆ remove_keyboard_callback()

void input::remove_keyboard_callback ( int key)
static

Remove a keyboard callback.

This function removes a callback from a key press event. The key enum is defined in GLFW. When the key is pressed, the callback is removed.

Parameters
keyThe key to remove the callback from

Definition at line 74 of file input.cpp.

◆ remove_mouse_pos_callback()

void input::remove_mouse_pos_callback ( types::mouse_callback_name_t callback_name)
static

Remove a mouse position callback.

This function removes a callback from a mouse position event. When the mouse is moved, the callback is removed.

Parameters
callback_nameThe name of the callback

Definition at line 108 of file input.cpp.

◆ terminate()

std::expected< void, subsystem::error > input::terminate ( )
overridevirtual

Cleans up resources.

Implements brenta::subsystem.

Definition at line 38 of file input.cpp.

Field Documentation

◆ subsystem_name

const std::string input::subsystem_name = "input"
static

Definition at line 40 of file input.hpp.


The documentation for this class was generated from the following files: