Adding basic keyboard input

This commit is contained in:
Dynamitos
2023-11-17 22:31:26 +01:00
parent 897eda18b0
commit ec760e8deb
18 changed files with 167 additions and 90 deletions
+51
View File
@@ -0,0 +1,51 @@
#include "KeyboardInput.h"
using namespace Seele;
using namespace Seele::System;
KeyboardInput::KeyboardInput(PScene scene)
: ComponentSystem<Component::KeyboardInput>(scene)
{
}
KeyboardInput::~KeyboardInput()
{
}
void KeyboardInput::update(Component::KeyboardInput& input)
{
std::memcpy(input.keys.data(), keys.data(), sizeof(keys));
input.deltaX = deltaX;
input.deltaY = deltaY;
input.mouseX = mouseX;
input.mouseY = mouseY;
input.mouse1 = mouse1;
input.mouse2 = mouse2;
}
void KeyboardInput::keyCallback(KeyCode code, InputAction action, KeyModifier modifier)
{
keys[code] = action != InputAction::RELEASE;
}
void KeyboardInput::mouseCallback(double x, double y)
{
mouseX = x;
mouseY = y;
deltaX = x - lastMouseX;
deltaY = y - lastMouseY;
lastMouseX = x;
lastMouseY = y;
}
void KeyboardInput::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier modifier)
{
if (button == MouseButton::MOUSE_BUTTON_1)
{
mouse1 = action != InputAction::RELEASE;
}
if (button == MouseButton::MOUSE_BUTTON_2)
{
mouse2 = action != InputAction::RELEASE;
}
}