Vigilante Game Framework  1.0.0.8
A 2D/3D C++ Game Framework using SFML.
Classes | Public Member Functions | Protected Attributes | List of all members
VInputHandler Class Reference

Processes inputs from keyboard, mouse and gamepad controllers. More...

#include <VInputHandler.h>

Classes

struct  AxisInput
 Axis Input Data. More...
 
struct  ButtonInput
 Button Input Data. More...
 

Public Member Functions

 VInputHandler (sf::Window *window)
 
void SetButtonInput (const sf::String &name, int key=-1, int gamepad=-1, int mouse=-1)
 
void SetAxisInput (const sf::String &name, int keyA=-1, int keyB=-1, int gamepad=-1)
 
bool GetButtonInput (const sf::String &name, ButtonInput &input)
 
bool GetAxisInput (const sf::String &name, AxisInput &input)
 
bool IsGamepadActive ()
 
bool IsButtonPressed (const sf::String &name, int ControllerIndex=0)
 
bool IsButtonDown (const sf::String &name, int ControllerIndex=0)
 
bool IsButtonUp (const sf::String &name, int ControllerIndex=0)
 
bool IsButtonReleased (const sf::String &name, int ControllerIndex=0)
 
float CurrentAxisValue (const sf::String &name, int ControllerIndex=0)
 
float LastAxisValue (const sf::String &name, int ControllerIndex=0)
 
float ScrollWheelDelta ()
 
void ResetScrollWheel ()
 Resets the scroll wheel delta to 0.
 
void HandleEvents (const sf::Event &event)
 
void Update (float dt)
 

Protected Attributes

std::map< sf::String, ButtonInputbuttonInputs
 Set of button inputs.
 
std::map< sf::String, AxisInputaxisInputs
 Set of axis inputs.
 
bool isGamepadActive = false
 Defines if gamepads are currently active.
 
float scrollWheel = 0
 Current scroll wheel amount.
 
sf::Vector2i lastMousePos = sf::Vector2i()
 Previous mouse position, useful for testing mouse movement.
 
sf::Window * window = nullptr
 Reference to window for mouse inputs.
 

Detailed Description

Processes inputs from keyboard, mouse and gamepad controllers.

Constructor & Destructor Documentation

◆ VInputHandler()

VInputHandler::VInputHandler ( sf::Window *  window)
Parameters
windowThe Window object, used for testing if mouse input is out of bounds.

Member Function Documentation

◆ CurrentAxisValue()

float VInputHandler::CurrentAxisValue ( const sf::String &  name,
int  ControllerIndex = 0 
)

Gets the Axis value of the current frame.

Parameters
nameName of Input.
ControllerIndexPlayer Index for specific controller. (e.g. 0 = Player 1, 1 = Player 2 ect)
Returns
Axis value with range [-100 - 100], 0 if controller is not index.

◆ GetAxisInput()

bool VInputHandler::GetAxisInput ( const sf::String &  name,
AxisInput input 
)

Gets specific Axis input data.

Parameters
nameName of input.
inputReference to Axis Input.
Returns
True if reference has been found and set to the input parameter.

◆ GetButtonInput()

bool VInputHandler::GetButtonInput ( const sf::String &  name,
ButtonInput input 
)

Gets specific Button input data.

Parameters
nameName of input.
inputReference to Button Input.
Returns
True if reference has been found and set to the input parameter.

◆ HandleEvents()

void VInputHandler::HandleEvents ( const sf::Event &  event)
Parameters
eventThe current event that can be processed.

◆ IsButtonDown()

bool VInputHandler::IsButtonDown ( const sf::String &  name,
int  ControllerIndex = 0 
)

Checks if a button is pushed down.

Parameters
nameName of Input.
ControllerIndexPlayer Index for specific controller. (e.g. 0 = Player 1, 1 = Player 2 ect)
Returns
True if button is down.

◆ IsButtonPressed()

bool VInputHandler::IsButtonPressed ( const sf::String &  name,
int  ControllerIndex = 0 
)

Checks if a button has applied a press for a single frame.

Parameters
nameName of Input.
ControllerIndexPlayer Index for specific controller. (e.g. 0 = Player 1, 1 = Player 2 ect)
Returns
True if button has been pressed.

◆ IsButtonReleased()

bool VInputHandler::IsButtonReleased ( const sf::String &  name,
int  ControllerIndex = 0 
)

Checks if a button has applied a release for a single frame.

Parameters
nameName of Input.
ControllerIndexPlayer Index for specific controller. (e.g. 0 = Player 1, 1 = Player 2 ect)
Returns
True if button has been released.

◆ IsButtonUp()

bool VInputHandler::IsButtonUp ( const sf::String &  name,
int  ControllerIndex = 0 
)

Checks if a button is not pushed down.

Parameters
nameName of Input.
ControllerIndexPlayer Index for specific controller. (e.g. 0 = Player 1, 1 = Player 2 ect)
Returns
True if button is up.

◆ IsGamepadActive()

bool VInputHandler::IsGamepadActive ( )
Returns
True if any gamepad input is recieved, returns false if other input is recieved.

◆ LastAxisValue()

float VInputHandler::LastAxisValue ( const sf::String &  name,
int  ControllerIndex = 0 
)

Gets the Axis value of the last frame.

Parameters
nameName of Input.
ControllerIndexPlayer Index for specific controller. (e.g. 0 = Player 1, 1 = Player 2 ect)
Returns
Axis value with range [-100 - 100], 0 if controller is not index.

◆ ScrollWheelDelta()

float VInputHandler::ScrollWheelDelta ( )
Returns
The scroll wheel delta from the mouse.

◆ SetAxisInput()

void VInputHandler::SetAxisInput ( const sf::String &  name,
int  keyA = -1,
int  keyB = -1,
int  gamepad = -1 
)

Sets the input values for a game axis. (i.e. analog sticks)

Parameters
nameName of input type.
keyAKey Code for the negative axis input.
keyBKey Code for the positive axis input.
gamepadGamepad value for axis Input.

◆ SetButtonInput()

void VInputHandler::SetButtonInput ( const sf::String &  name,
int  key = -1,
int  gamepad = -1,
int  mouse = -1 
)

Set the input values for a game button.

Parameters
nameName of input type.
keyKey Code for Input.
gamepadGamepad value for Input.
mouseMouse value for Input.

◆ Update()

void VInputHandler::Update ( float  dt)

Updates the inputs.

Parameters
dtDelta Time between the current and previous frames of the game.

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