The Table Engine
input.cpp
Go to the documentation of this file.
1 #include "input.h"
2 #include <iostream>
3 
4 #include <SDL2/SDL.h>
5 
7 {
8  setName("input");
9  m_mouseX = 0;
10  m_mouseY = 0;
11 }
12 
14 {
15 }
16 
18 {
19  auto state = SDL_GetKeyboardState(NULL);
20 
21  spacePressed = state[SDL_SCANCODE_SPACE];
22  leftPressed = state[SDL_SCANCODE_LEFT] || state[SDL_SCANCODE_A];
23  rightPressed = state[SDL_SCANCODE_RIGHT] || state[SDL_SCANCODE_D];
24  upPressed = state[SDL_SCANCODE_UP] || state[SDL_SCANCODE_W];
25  downPressed = state[SDL_SCANCODE_DOWN] || state[SDL_SCANCODE_S];
26 
27  SDL_GetMouseState(&m_mouseX, &m_mouseY);
28 
29  mouseLeftPressed = SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_LEFT);
30  mouseRightPressed = SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT);
31  mouseMiddlePressed = SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_MIDDLE);
32 }
void setName(std::string name)
Sets the name of the component.
Definition: component.cpp:19
bool mouseLeftPressed
True if the left mouse button is pressed, false otherwise.
Definition: input.h:31
int m_mouseY
Current position of the mouse cursor.
Definition: input.h:29
bool upPressed
True if the up arrow key is pressed, false otherwise.
Definition: input.h:26
bool mouseRightPressed
True if the right mouse button is pressed, false otherwise.
Definition: input.h:32
void update() override
Updates the state of the input based on the latest user interactions.
Definition: input.cpp:17
bool spacePressed
True if the space bar is pressed, false otherwise.
Definition: input.h:22
bool mouseMiddlePressed
True if the middle mouse button is pressed, false otherwise.
Definition: input.h:33
bool rightPressed
True if the right arrow key is pressed, false otherwise.
Definition: input.h:25
bool leftPressed
True if the left arrow key is pressed, false otherwise.
Definition: input.h:24
bool downPressed
True if the down arrow key is pressed, false otherwise.
Definition: input.h:27
Input()
Constructor for the Input component.
Definition: input.cpp:6
~Input()
Destructor for the Input component.
Definition: input.cpp:13
int m_mouseX
Definition: input.h:29
Defines the Input component for handling input operations in the game engine.