group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
InputBindings Class Reference

Stores action-to-input bindings and helper conversions for UI and persistence. More...

#include <InputBindings.hpp>

Public Member Functions

Binding get (Action a, BindingDevice device=BindingDevice::KeyboardMouse, std::size_t slot=0) const
 Return the binding assigned to an action/device/slot.
void rebind (Action a, Binding b, BindingDevice device=BindingDevice::KeyboardMouse, std::size_t slot=0)
 Assign a binding to an action/device/slot, clearing any duplicate action use on that device.
bool pressed (Action a, const bool *keyStates, SDL_MouseButtonFlags mouseState) const
 Test whether an action is currently pressed using SDL keyboard and mouse state.
bool controllerPressed (Action a, SDL_Gamepad *gamepad) const
 Test whether an action is currently pressed on a controller.
bool eventMatches (Action a, const SDL_Event &event, bool &down) const
 Match a key/button/wheel/axis SDL event against any binding for an action.

Static Public Member Functions

static InputBindings defaults ()
 Return bindings matching the game's historical default controls.
static constexpr std::array< Action, size_t(Action::Count)> actions ()
 Return every configurable action in stable UI/config order.
static std::string_view actionLabel (Action a)
 Human-readable action label shown in settings UI.
static std::string_view configKey (Action a)
 Stable TOML key for an action.
static bool actionFromConfigKey (std::string_view key, Action &out)
 Parse a TOML action key.
static std::string bindingLabel (Binding b)
 Human-readable binding label shown in settings UI.
static std::string bindingConfigValue (Binding b)
 Stable TOML value for a binding.
static bool bindingFromConfigValue (std::string_view value, Binding &out)
 Parse a TOML binding value.

Static Public Attributes

static constexpr std::size_t kBindingSlots = 2

Private Types

using BindingRow = std::array<Binding, kBindingSlots>
using BindingTable = std::array<BindingRow, size_t(Action::Count)>

Private Member Functions

BindingTabletableFor (BindingDevice device)
const BindingTabletableFor (BindingDevice device) const

Private Attributes

BindingTable keyboardMouseBindings {}
 Keyboard/mouse binding table indexed by Action and slot.
BindingTable controllerBindings {}
 Controller binding table indexed by Action and slot.

Detailed Description

Stores action-to-input bindings and helper conversions for UI and persistence.

Member Typedef Documentation

◆ BindingRow

using InputBindings::BindingRow = std::array<Binding, kBindingSlots>
private

◆ BindingTable

using InputBindings::BindingTable = std::array<BindingRow, size_t(Action::Count)>
private

Member Function Documentation

◆ actionFromConfigKey()

bool InputBindings::actionFromConfigKey ( std::string_view key,
Action & out )
static

Parse a TOML action key.

Here is the call graph for this function:

◆ actionLabel()

std::string_view InputBindings::actionLabel ( Action a)
static

Human-readable action label shown in settings UI.

Here is the caller graph for this function:

◆ actions()

constexpr std::array< Action, size_t(Action::Count)> InputBindings::actions ( )
inlinestaticconstexpr

Return every configurable action in stable UI/config order.

Here is the caller graph for this function:

◆ bindingConfigValue()

std::string InputBindings::bindingConfigValue ( Binding b)
static

Stable TOML value for a binding.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bindingFromConfigValue()

bool InputBindings::bindingFromConfigValue ( std::string_view value,
Binding & out )
static

Parse a TOML binding value.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bindingLabel()

std::string InputBindings::bindingLabel ( Binding b)
static

Human-readable binding label shown in settings UI.

Here is the caller graph for this function:

◆ configKey()

std::string_view InputBindings::configKey ( Action a)
static

Stable TOML key for an action.

Here is the caller graph for this function:

◆ controllerPressed()

bool InputBindings::controllerPressed ( Action a,
SDL_Gamepad * gamepad ) const

Test whether an action is currently pressed on a controller.

Here is the caller graph for this function:

◆ defaults()

InputBindings InputBindings::defaults ( )
static

Return bindings matching the game's historical default controls.

Here is the call graph for this function:

◆ eventMatches()

bool InputBindings::eventMatches ( Action a,
const SDL_Event & event,
bool & down ) const

Match a key/button/wheel/axis SDL event against any binding for an action.

Here is the caller graph for this function:

◆ get()

Binding InputBindings::get ( Action a,
BindingDevice device = BindingDevice::KeyboardMouse,
std::size_t slot = 0 ) const
nodiscard

Return the binding assigned to an action/device/slot.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pressed()

bool InputBindings::pressed ( Action a,
const bool * keyStates,
SDL_MouseButtonFlags mouseState ) const

Test whether an action is currently pressed using SDL keyboard and mouse state.

Here is the caller graph for this function:

◆ rebind()

void InputBindings::rebind ( Action a,
Binding b,
BindingDevice device = BindingDevice::KeyboardMouse,
std::size_t slot = 0 )

Assign a binding to an action/device/slot, clearing any duplicate action use on that device.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tableFor() [1/2]

InputBindings::BindingTable & InputBindings::tableFor ( BindingDevice device)
nodiscardprivate
Here is the caller graph for this function:

◆ tableFor() [2/2]

const InputBindings::BindingTable & InputBindings::tableFor ( BindingDevice device) const
nodiscardprivate

Member Data Documentation

◆ controllerBindings

BindingTable InputBindings::controllerBindings {}
private

Controller binding table indexed by Action and slot.

◆ kBindingSlots

std::size_t InputBindings::kBindingSlots = 2
staticconstexpr

◆ keyboardMouseBindings

BindingTable InputBindings::keyboardMouseBindings {}
private

Keyboard/mouse binding table indexed by Action and slot.


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