Text Rendering
This commit is contained in:
@ -23,10 +23,18 @@ namespace ia::iae
|
||||
|
||||
BOOL InputManager::s_keys[256];
|
||||
BOOL InputManager::s_prevKeys[256];
|
||||
InputKey InputManager::s_axisInputs[4];
|
||||
Vec2 InputManager::s_pointerPosition{};
|
||||
Map<String, Handle> InputManager::s_actionNames;
|
||||
Vector<Vector<InputKey>> InputManager::s_actions;
|
||||
InputManager::KeyboardGamePadMapping InputManager::s_keyboardGamePadMapping{};
|
||||
|
||||
BOOL InputManager::s_buttonA{};
|
||||
BOOL InputManager::s_buttonB{};
|
||||
BOOL InputManager::s_buttonC{};
|
||||
BOOL InputManager::s_buttonD{};
|
||||
INT16 InputManager::s_verticalAxis{};
|
||||
INT16 InputManager::s_horizontalAxis{};
|
||||
|
||||
BOOL InputManager::s_onScreenGamePadEnabled{};
|
||||
BOOL InputManager::s_keyboardGamePadEnabled{};
|
||||
|
||||
VOID InputManager::Initialize()
|
||||
{
|
||||
@ -60,12 +68,6 @@ namespace ia::iae
|
||||
}
|
||||
}
|
||||
|
||||
Vec2 InputManager::GetAxis()
|
||||
{
|
||||
return Vec2{IsKeyDown(s_axisInputs[3]) + IsKeyDown(s_axisInputs[2]) * -1,
|
||||
IsKeyDown(s_axisInputs[1]) + IsKeyDown(s_axisInputs[0]) * -1};
|
||||
}
|
||||
|
||||
VOID InputManager::SwitchModeToText()
|
||||
{
|
||||
SDL_StartTextInput(g_windowHandle);
|
||||
@ -96,202 +98,232 @@ namespace ia::iae
|
||||
return s_prevKeys[(UINT8) key] && !s_keys[(UINT8) key];
|
||||
}
|
||||
|
||||
BOOL InputManager::IsActionDown(IN Handle action)
|
||||
VOID InputManager::SetupOnScreenGamePad()
|
||||
{
|
||||
const auto &t = s_actions[action];
|
||||
for (const auto &k : t)
|
||||
if (IsKeyDown(k))
|
||||
return true;
|
||||
return false;
|
||||
s_onScreenGamePadEnabled = true;
|
||||
}
|
||||
|
||||
BOOL InputManager::WasActionPressed(IN Handle action)
|
||||
VOID InputManager::SetupKeyboardGamePad(IN CONST KeyboardGamePadMapping &mapping)
|
||||
{
|
||||
const auto &t = s_actions[action];
|
||||
for (const auto &k : t)
|
||||
if (WasKeyPressed(k))
|
||||
return true;
|
||||
return false;
|
||||
s_keyboardGamePadEnabled = true;
|
||||
s_keyboardGamePadMapping = mapping;
|
||||
}
|
||||
|
||||
BOOL InputManager::WasActionReleased(IN Handle action)
|
||||
BOOL InputManager::GetButtonA()
|
||||
{
|
||||
const auto &t = s_actions[action];
|
||||
for (const auto &k : t)
|
||||
if (WasKeyReleased(k))
|
||||
return true;
|
||||
return false;
|
||||
return s_buttonA;
|
||||
}
|
||||
|
||||
BOOL InputManager::IsActionDown(IN CONST String &action)
|
||||
BOOL InputManager::GetButtonB()
|
||||
{
|
||||
return IsActionDown(s_actionNames[action]);
|
||||
return s_buttonB;
|
||||
}
|
||||
|
||||
BOOL InputManager::WasActionPressed(IN CONST String &action)
|
||||
BOOL InputManager::GetButtonC()
|
||||
{
|
||||
return WasActionPressed(s_actionNames[action]);
|
||||
return s_buttonC;
|
||||
}
|
||||
|
||||
BOOL InputManager::WasActionReleased(IN CONST String &action)
|
||||
BOOL InputManager::GetButtonD()
|
||||
{
|
||||
return WasActionReleased(s_actionNames[action]);
|
||||
return s_buttonD;
|
||||
}
|
||||
|
||||
Handle InputManager::BindAction(IN CONST String &name, IN InputKey key)
|
||||
INT16 InputManager::GetVerticalAxis()
|
||||
{
|
||||
s_actions.pushBack({key});
|
||||
const auto handle = s_actions.size() - 1;
|
||||
s_actionNames[name] = handle;
|
||||
return handle;
|
||||
return s_verticalAxis;
|
||||
}
|
||||
|
||||
VOID InputManager::BindAxis(IN InputKey upKey, IN InputKey downKey, IN InputKey leftKey, IN InputKey rightKey)
|
||||
INT16 InputManager::GetHorizontalAxis()
|
||||
{
|
||||
s_axisInputs[0] = upKey;
|
||||
s_axisInputs[1] = downKey;
|
||||
s_axisInputs[2] = leftKey;
|
||||
s_axisInputs[3] = rightKey;
|
||||
return s_horizontalAxis;
|
||||
}
|
||||
|
||||
VOID InputManager::SetKey(IN InputKey key, IN BOOL state)
|
||||
IVec2 InputManager::GetDirectionalInput()
|
||||
{
|
||||
s_keys[(UINT8) key] = state;
|
||||
return IVec2{GetHorizontalAxis(), GetVerticalAxis()};
|
||||
}
|
||||
|
||||
VOID InputManager::SetAxis(IN BOOL up, IN BOOL down, IN BOOL left, IN BOOL right)
|
||||
VOID InputManager::SetButtonA(IN BOOL value)
|
||||
{
|
||||
s_keys[(UINT8) s_axisInputs[0]] = up;
|
||||
s_keys[(UINT8) s_axisInputs[1]] = down;
|
||||
s_keys[(UINT8) s_axisInputs[2]] = left;
|
||||
s_keys[(UINT8) s_axisInputs[3]] = right;
|
||||
s_buttonA = value;
|
||||
}
|
||||
|
||||
VOID InputManager::SetAxisUp(IN BOOL v)
|
||||
VOID InputManager::SetButtonB(IN BOOL value)
|
||||
{
|
||||
s_keys[(UINT8) s_axisInputs[0]] = v;
|
||||
s_buttonB = value;
|
||||
}
|
||||
|
||||
VOID InputManager::SetAxisDown(IN BOOL v)
|
||||
VOID InputManager::SetButtonC(IN BOOL value)
|
||||
{
|
||||
s_keys[(UINT8) s_axisInputs[1]] = v;
|
||||
s_buttonC = value;
|
||||
}
|
||||
|
||||
VOID InputManager::SetAxisLeft(IN BOOL v)
|
||||
VOID InputManager::SetButtonD(IN BOOL value)
|
||||
{
|
||||
s_keys[(UINT8) s_axisInputs[2]] = v;
|
||||
s_buttonD = value;
|
||||
}
|
||||
|
||||
VOID InputManager::SetAxisRight(IN BOOL v)
|
||||
VOID InputManager::SetVerticalAxis(IN INT16 value)
|
||||
{
|
||||
s_keys[(UINT8) s_axisInputs[3]] = v;
|
||||
s_verticalAxis = value;
|
||||
}
|
||||
|
||||
VOID InputManager::SetHorizontalAxis(IN INT16 value)
|
||||
{
|
||||
s_horizontalAxis = value;
|
||||
}
|
||||
|
||||
VOID InputManager::Draw()
|
||||
{
|
||||
if (s_onScreenGamePadEnabled)
|
||||
{
|
||||
//Engine::SetRenderState_Texture(0);
|
||||
//Engine::SetRenderState_FlippedH(false);
|
||||
//Engine::SetRenderState_FlippedV(false);
|
||||
//Engine::SetRenderState_ColorOverlay({0xFF, 0xFF, 0xFF, 0xFF});
|
||||
//Engine::SetRenderState_TextureOffset({0, 0});
|
||||
//Engine::SetRenderState_CameraRelative(false);
|
||||
//Engine::SetRenderState_Transform({300.0f, 500.0f},
|
||||
// {100.0f, 100.0f},
|
||||
// 0);
|
||||
//Engine::DrawGeometry(Engine::GetGeometry_Circle(), 0xFF, 0);
|
||||
}
|
||||
}
|
||||
|
||||
VOID InputManager::Update()
|
||||
{
|
||||
s_buttonA = false;
|
||||
s_buttonB = false;
|
||||
s_buttonC = false;
|
||||
s_buttonD = false;
|
||||
s_verticalAxis = 0;
|
||||
s_horizontalAxis = 0;
|
||||
|
||||
if (s_onScreenGamePadEnabled)
|
||||
{
|
||||
}
|
||||
|
||||
if (s_keyboardGamePadEnabled)
|
||||
{
|
||||
s_buttonA |= IsKeyDown(s_keyboardGamePadMapping.ButtonA);
|
||||
s_buttonB |= IsKeyDown(s_keyboardGamePadMapping.ButtonB);
|
||||
s_buttonC |= IsKeyDown(s_keyboardGamePadMapping.ButtonC);
|
||||
s_buttonD |= IsKeyDown(s_keyboardGamePadMapping.ButtonD);
|
||||
s_verticalAxis +=
|
||||
IsKeyDown(s_keyboardGamePadMapping.AxisDown) + IsKeyDown(s_keyboardGamePadMapping.AxisUp) * -1;
|
||||
s_horizontalAxis +=
|
||||
IsKeyDown(s_keyboardGamePadMapping.AxisRight) + IsKeyDown(s_keyboardGamePadMapping.AxisLeft) * -1;
|
||||
}
|
||||
}
|
||||
} // namespace ia::iae
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
Vec2 Engine::GetInputAxis()
|
||||
{
|
||||
return InputManager::GetAxis();
|
||||
}
|
||||
|
||||
VOID Engine::SwitchInputModeToText()
|
||||
VOID Engine::Input_SwitchModeToText()
|
||||
{
|
||||
InputManager::SwitchModeToText();
|
||||
}
|
||||
|
||||
VOID Engine::SwitchInputModeToAction()
|
||||
VOID Engine::Input_SwitchModeToAction()
|
||||
{
|
||||
InputManager::SwitchModeToAction();
|
||||
}
|
||||
|
||||
Vec2 Engine::GetInputPointerPosition()
|
||||
Vec2 Engine::Input_GetPointerPosition()
|
||||
{
|
||||
return InputManager::GetPointerPosition();
|
||||
}
|
||||
|
||||
BOOL Engine::IsInputKeyDown(IN InputKey key)
|
||||
BOOL Engine::Input_IsKeyDown(IN InputKey key)
|
||||
{
|
||||
return InputManager::IsKeyDown(key);
|
||||
}
|
||||
|
||||
BOOL Engine::WasInputKeyPressed(IN InputKey key)
|
||||
BOOL Engine::Input_WasKeyPressed(IN InputKey key)
|
||||
{
|
||||
return InputManager::WasKeyPressed(key);
|
||||
}
|
||||
|
||||
BOOL Engine::WasInputKeyReleased(IN InputKey key)
|
||||
BOOL Engine::Input_WasKeyReleased(IN InputKey key)
|
||||
{
|
||||
return InputManager::WasKeyReleased(key);
|
||||
}
|
||||
|
||||
BOOL Engine::IsInputActionDown(IN Handle action)
|
||||
VOID Engine::Input_SetupOnScreenGamePad()
|
||||
{
|
||||
return InputManager::IsActionDown(action);
|
||||
InputManager::SetupOnScreenGamePad();
|
||||
}
|
||||
|
||||
BOOL Engine::WasInputActionPressed(IN Handle action)
|
||||
VOID Engine::Input_SetupKeyboardGamePad(IN InputKey axisLeft, IN InputKey axisRight, IN InputKey axisDown,
|
||||
IN InputKey axisUp, IN InputKey buttonA, IN InputKey buttonB,
|
||||
IN InputKey buttonC, IN InputKey buttonD)
|
||||
{
|
||||
return InputManager::WasActionPressed(action);
|
||||
InputManager::SetupKeyboardGamePad({axisLeft, axisRight, axisDown, axisUp, buttonA, buttonB, buttonC, buttonD});
|
||||
}
|
||||
|
||||
BOOL Engine::WasInputActionReleased(IN Handle action)
|
||||
BOOL Engine::Input_GetButtonA()
|
||||
{
|
||||
return InputManager::WasActionReleased(action);
|
||||
return InputManager::GetButtonA();
|
||||
}
|
||||
|
||||
BOOL Engine::IsInputActionDown(IN CONST String &action)
|
||||
BOOL Engine::Input_GetButtonB()
|
||||
{
|
||||
return InputManager::IsActionDown(action);
|
||||
return InputManager::GetButtonB();
|
||||
}
|
||||
|
||||
BOOL Engine::WasInputActionPressed(IN CONST String &action)
|
||||
BOOL Engine::Input_GetButtonC()
|
||||
{
|
||||
return InputManager::WasActionPressed(action);
|
||||
return InputManager::GetButtonC();
|
||||
}
|
||||
|
||||
BOOL Engine::WasInputActionReleased(IN CONST String &action)
|
||||
BOOL Engine::Input_GetButtonD()
|
||||
{
|
||||
return InputManager::WasActionReleased(action);
|
||||
return InputManager::GetButtonD();
|
||||
}
|
||||
|
||||
Handle Engine::BindInputAction(IN CONST String &name, IN InputKey key)
|
||||
INT16 Engine::Input_GetVerticalAxis()
|
||||
{
|
||||
return InputManager::BindAction(name, key);
|
||||
return InputManager::GetVerticalAxis();
|
||||
}
|
||||
|
||||
VOID Engine::BindInputAxis(IN InputKey upKey, IN InputKey downKey, IN InputKey leftKey, IN InputKey rightKey)
|
||||
INT16 Engine::Input_GetHorizontalAxis()
|
||||
{
|
||||
InputManager::BindAxis(upKey, downKey, leftKey, rightKey);
|
||||
return InputManager::GetHorizontalAxis();
|
||||
}
|
||||
|
||||
VOID Engine::SetKey(IN InputKey key, IN BOOL state)
|
||||
IVec2 Engine::Input_GetDirectionalInput()
|
||||
{
|
||||
InputManager::SetKey(key, state);
|
||||
return InputManager::GetDirectionalInput();
|
||||
}
|
||||
|
||||
VOID Engine::SetAxis(IN BOOL up, IN BOOL down, IN BOOL left, IN BOOL right)
|
||||
VOID Engine::Input_SetButtonA(IN BOOL value)
|
||||
{
|
||||
InputManager::SetAxis(up, down, left, right);
|
||||
InputManager::SetButtonA(value);
|
||||
}
|
||||
|
||||
VOID Engine::SetAxisUp(IN BOOL v)
|
||||
VOID Engine::Input_SetButtonB(IN BOOL value)
|
||||
{
|
||||
InputManager::SetAxisUp(v);
|
||||
InputManager::SetButtonB(value);
|
||||
}
|
||||
|
||||
VOID Engine::SetAxisDown(IN BOOL v)
|
||||
VOID Engine::Input_SetButtonC(IN BOOL value)
|
||||
{
|
||||
InputManager::SetAxisDown(v);
|
||||
InputManager::SetButtonC(value);
|
||||
}
|
||||
|
||||
VOID Engine::SetAxisLeft(IN BOOL v)
|
||||
VOID Engine::Input_SetButtonD(IN BOOL value)
|
||||
{
|
||||
InputManager::SetAxisLeft(v);
|
||||
InputManager::SetButtonD(value);
|
||||
}
|
||||
|
||||
VOID Engine::SetAxisRight(IN BOOL v)
|
||||
VOID Engine::Input_SetVerticalAxis(IN INT16 value)
|
||||
{
|
||||
InputManager::SetAxisRight(v);
|
||||
InputManager::SetVerticalAxis(value);
|
||||
}
|
||||
|
||||
VOID Engine::Input_SetHorizontalAxis(IN INT16 value)
|
||||
{
|
||||
InputManager::SetHorizontalAxis(value);
|
||||
}
|
||||
} // namespace ia::iae
|
||||
Reference in New Issue
Block a user