diff --git a/Engine/Src/Imp/CPP/InputManager.cpp b/Engine/Src/Imp/CPP/InputManager.cpp index eabc26b..4db4a9f 100644 --- a/Engine/Src/Imp/CPP/InputManager.cpp +++ b/Engine/Src/Imp/CPP/InputManager.cpp @@ -46,7 +46,7 @@ namespace ia::iae case SDL_EVENT_KEY_DOWN: s_keys[event->key.scancode] = true; break; - + case SDL_EVENT_KEY_UP: s_keys[event->key.scancode] = false; break; @@ -62,10 +62,8 @@ 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 - }; + return Vec2{IsKeyDown(s_axisInputs[3]) + IsKeyDown(s_axisInputs[2]) * -1, + IsKeyDown(s_axisInputs[1]) + IsKeyDown(s_axisInputs[0]) * -1}; } VOID InputManager::SwitchModeToText() @@ -100,42 +98,42 @@ namespace ia::iae BOOL InputManager::IsActionDown(IN Handle action) { - const auto& t = s_actions[action]; - for(const auto& k : t) - if(IsKeyDown(k)) + const auto &t = s_actions[action]; + for (const auto &k : t) + if (IsKeyDown(k)) return true; return false; } BOOL InputManager::WasActionPressed(IN Handle action) { - const auto& t = s_actions[action]; - for(const auto& k : t) - if(WasKeyPressed(k)) + const auto &t = s_actions[action]; + for (const auto &k : t) + if (WasKeyPressed(k)) return true; return false; } BOOL InputManager::WasActionReleased(IN Handle action) { - const auto& t = s_actions[action]; - for(const auto& k : t) - if(WasKeyReleased(k)) + const auto &t = s_actions[action]; + for (const auto &k : t) + if (WasKeyReleased(k)) return true; return false; } - BOOL InputManager::IsActionDown(IN CONST String& action) + BOOL InputManager::IsActionDown(IN CONST String &action) { return IsActionDown(s_actionNames[action]); } - BOOL InputManager::WasActionPressed(IN CONST String& action) + BOOL InputManager::WasActionPressed(IN CONST String &action) { return WasActionPressed(s_actionNames[action]); } - BOOL InputManager::WasActionReleased(IN CONST String& action) + BOOL InputManager::WasActionReleased(IN CONST String &action) { return WasActionReleased(s_actionNames[action]); } @@ -144,7 +142,7 @@ namespace ia::iae { s_actions.pushBack({key}); const auto handle = s_actions.size() - 1; - s_actionNames[name] = handle; + s_actionNames[name] = handle; return handle; } @@ -155,6 +153,39 @@ namespace ia::iae s_axisInputs[2] = leftKey; s_axisInputs[3] = rightKey; } + + VOID InputManager::SetKey(IN InputKey key, IN BOOL state) + { + s_keys[(UINT8) key] = state; + } + + VOID InputManager::SetAxis(IN BOOL up, IN BOOL down, IN BOOL left, IN BOOL right) + { + 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; + } + + VOID InputManager::SetAxisUp(IN BOOL v) + { + s_keys[(UINT8) s_axisInputs[0]] = v; + } + + VOID InputManager::SetAxisDown(IN BOOL v) + { + s_keys[(UINT8) s_axisInputs[1]] = v; + } + + VOID InputManager::SetAxisLeft(IN BOOL v) + { + s_keys[(UINT8) s_axisInputs[2]] = v; + } + + VOID InputManager::SetAxisRight(IN BOOL v) + { + s_keys[(UINT8) s_axisInputs[3]] = v; + } } // namespace ia::iae namespace ia::iae @@ -209,17 +240,17 @@ namespace ia::iae return InputManager::WasActionReleased(action); } - BOOL Engine::IsInputActionDown(IN CONST String& action) + BOOL Engine::IsInputActionDown(IN CONST String &action) { return InputManager::IsActionDown(action); } - BOOL Engine::WasInputActionPressed(IN CONST String& action) + BOOL Engine::WasInputActionPressed(IN CONST String &action) { return InputManager::WasActionPressed(action); } - BOOL Engine::WasInputActionReleased(IN CONST String& action) + BOOL Engine::WasInputActionReleased(IN CONST String &action) { return InputManager::WasActionReleased(action); } @@ -233,4 +264,34 @@ namespace ia::iae { InputManager::BindAxis(upKey, downKey, leftKey, rightKey); } + + VOID Engine::SetKey(IN InputKey key, IN BOOL state) + { + InputManager::SetKey(key, state); + } + + VOID Engine::SetAxis(IN BOOL up, IN BOOL down, IN BOOL left, IN BOOL right) + { + InputManager::SetAxis(up, down, left, right); + } + + VOID Engine::SetAxisUp(IN BOOL v) + { + InputManager::SetAxisUp(v); + } + + VOID Engine::SetAxisDown(IN BOOL v) + { + InputManager::SetAxisDown(v); + } + + VOID Engine::SetAxisLeft(IN BOOL v) + { + InputManager::SetAxisLeft(v); + } + + VOID Engine::SetAxisRight(IN BOOL v) + { + InputManager::SetAxisRight(v); + } } // namespace ia::iae \ No newline at end of file diff --git a/Engine/Src/Imp/CPP/UI.cpp b/Engine/Src/Imp/CPP/UI.cpp index 5e66397..3366e72 100644 --- a/Engine/Src/Imp/CPP/UI.cpp +++ b/Engine/Src/Imp/CPP/UI.cpp @@ -57,33 +57,33 @@ namespace ia::iae VOID AddClickListener(IN Rml::Element *element, IN std::function callback) { - element->AddEventListener("click", this); + element->AddEventListener(Rml::EventId::Click, this); m_clickCallbacks[element->GetId().c_str()] = callback; } - // VOID AddHoverEnterListener(IN PCCHAR elementId, IN std::function callback) - //{ - // m_document->GetElementById(elementId)->AddEventListener("mouseover", this); - // m_hoverEnterCallbacks[elementId] = callback; - // } - // - // VOID AddHoverExitListener(IN PCCHAR elementId, IN std::function callback) - //{ - // m_document->GetElementById(elementId)->AddEventListener("mouseout", this); - // m_hoverExitCallbacks[elementId] = callback; - //} - // - // VOID AddPointerDownListener(IN PCCHAR elementId, IN std::function callback) - //{ - // m_document->GetElementById(elementId)->AddEventListener("mousedown", this); - // m_pointerDownCallbacks[elementId] = callback; - //} - // - // VOID AddPointerUpListener(IN PCCHAR elementId, IN std::function callback) - //{ - // m_document->GetElementById(elementId)->AddEventListener("mouseup", this); - // m_pointerUpCallbacks[elementId] = callback; - //} + VOID AddPointerDownListener(IN Rml::Element *element, IN std::function callback) + { + element->AddEventListener(Rml::EventId::Mousedown, this); + m_pointerDownCallbacks[element->GetId().c_str()] = callback; + } + + VOID AddPointerUpListener(IN Rml::Element *element, IN std::function callback) + { + element->AddEventListener(Rml::EventId::Mouseup, this); + m_pointerUpCallbacks[element->GetId().c_str()] = callback; + } + + VOID AddPointerEnterListener(IN Rml::Element *element, IN std::function callback) + { + element->AddEventListener(Rml::EventId::Mouseover, this); + m_hoverEnterCallbacks[element->GetId().c_str()] = callback; + } + + VOID AddPointerExitListener(IN Rml::Element *element, IN std::function callback) + { + element->AddEventListener(Rml::EventId::Mouseout, this); + m_hoverExitCallbacks[element->GetId().c_str()] = callback; + } VOID ProcessEvent(IN Rml::Event &event) { @@ -101,13 +101,15 @@ namespace ia::iae m_hoverExitCallbacks[event.GetTargetElement()->GetId().c_str()](); break; - case Rml::EventId::Mousedown: + case Rml::EventId::Mousedown: { m_pointerDownCallbacks[event.GetTargetElement()->GetId().c_str()](); - break; + } + break; - case Rml::EventId::Mouseup: + case Rml::EventId::Mouseup: { m_pointerUpCallbacks[event.GetTargetElement()->GetId().c_str()](); - break; + } + break; default: break; @@ -490,6 +492,26 @@ namespace ia::iae { g_eventListener.AddClickListener(g_document->GetElementById(elementId), callback); } + + VOID UI::AddPointerUpEvent(IN PCCHAR elementId, IN std::function callback) + { + g_eventListener.AddPointerUpListener(g_document->GetElementById(elementId), callback); + } + + VOID UI::AddPointerDownEvent(IN PCCHAR elementId, IN std::function callback) + { + g_eventListener.AddPointerDownListener(g_document->GetElementById(elementId), callback); + } + + VOID UI::AddPointerExitEvent(IN PCCHAR elementId, IN std::function callback) + { + g_eventListener.AddPointerExitListener(g_document->GetElementById(elementId), callback); + } + + VOID UI::AddPointerEnterEvent(IN PCCHAR elementId, IN std::function callback) + { + g_eventListener.AddPointerEnterListener(g_document->GetElementById(elementId), callback); + } } // namespace ia::iae namespace ia::iae diff --git a/Engine/Src/Imp/HPP/InputManager.hpp b/Engine/Src/Imp/HPP/InputManager.hpp index d3de52f..8d09c2d 100644 --- a/Engine/Src/Imp/HPP/InputManager.hpp +++ b/Engine/Src/Imp/HPP/InputManager.hpp @@ -46,6 +46,13 @@ namespace ia::iae STATIC Handle BindAction(IN CONST String &name, IN InputKey key); STATIC VOID BindAxis(IN InputKey upKey, IN InputKey downKey, IN InputKey leftKey, IN InputKey rightKey); + STATIC VOID SetAxisUp(IN BOOL v); + STATIC VOID SetAxisDown(IN BOOL v); + STATIC VOID SetAxisLeft(IN BOOL v); + STATIC VOID SetAxisRight(IN BOOL v); + STATIC VOID SetKey(IN InputKey key, IN BOOL state); + STATIC VOID SetAxis(IN BOOL up, IN BOOL down, IN BOOL left, IN BOOL right); + private: STATIC BOOL s_keys[256]; STATIC BOOL s_prevKeys[256]; diff --git a/Engine/Src/Inc/IAEngine/Engine.hpp b/Engine/Src/Inc/IAEngine/Engine.hpp index 242262f..9992e17 100644 --- a/Engine/Src/Inc/IAEngine/Engine.hpp +++ b/Engine/Src/Inc/IAEngine/Engine.hpp @@ -117,6 +117,12 @@ namespace ia::iae STATIC BOOL WasInputActionReleased(IN CONST String &action); STATIC Handle BindInputAction(IN CONST String &name, IN InputKey key); STATIC VOID BindInputAxis(IN InputKey upKey, IN InputKey downKey, IN InputKey leftKey, IN InputKey rightKey); + STATIC VOID SetAxisUp(IN BOOL v); + STATIC VOID SetAxisDown(IN BOOL v); + STATIC VOID SetAxisLeft(IN BOOL v); + STATIC VOID SetAxisRight(IN BOOL v); + STATIC VOID SetKey(IN InputKey key, IN BOOL state); + STATIC VOID SetAxis(IN BOOL up, IN BOOL down, IN BOOL left, IN BOOL right); // Utility Functions STATIC String ReadTextAsset(IN CONST String& path); diff --git a/Engine/Src/Inc/IAEngine/UI.hpp b/Engine/Src/Inc/IAEngine/UI.hpp index 16a07cb..7392ec3 100644 --- a/Engine/Src/Inc/IAEngine/UI.hpp +++ b/Engine/Src/Inc/IAEngine/UI.hpp @@ -28,6 +28,10 @@ namespace ia::iae STATIC VOID SetMarkup(IN CONST String &markup, IN CONST String &styles); STATIC VOID AddClickEvent(IN PCCHAR elementId, IN std::function callback); + STATIC VOID AddPointerUpEvent(IN PCCHAR elementId, IN std::function callback); + STATIC VOID AddPointerDownEvent(IN PCCHAR elementId, IN std::function callback); + STATIC VOID AddPointerExitEvent(IN PCCHAR elementId, IN std::function callback); + STATIC VOID AddPointerEnterEvent(IN PCCHAR elementId, IN std::function callback); public: STATIC VOID Initialize(); diff --git a/Resources/HUD/gamepad_dir_down.png b/Resources/HUD/gamepad_dir_down.png new file mode 100644 index 0000000..294393f Binary files /dev/null and b/Resources/HUD/gamepad_dir_down.png differ diff --git a/Resources/HUD/gamepad_dir_left.png b/Resources/HUD/gamepad_dir_left.png new file mode 100644 index 0000000..f1b46e4 Binary files /dev/null and b/Resources/HUD/gamepad_dir_left.png differ diff --git a/Resources/HUD/gamepad_dir_right.png b/Resources/HUD/gamepad_dir_right.png new file mode 100644 index 0000000..9eaee23 Binary files /dev/null and b/Resources/HUD/gamepad_dir_right.png differ diff --git a/Resources/HUD/gamepad_dir_up.png b/Resources/HUD/gamepad_dir_up.png new file mode 100644 index 0000000..a4994cb Binary files /dev/null and b/Resources/HUD/gamepad_dir_up.png differ diff --git a/Vendor/CMakeLists.txt b/Vendor/CMakeLists.txt index 2f5eb94..8af028c 100644 --- a/Vendor/CMakeLists.txt +++ b/Vendor/CMakeLists.txt @@ -1,3 +1,5 @@ +set(BUILD_SHARED_LIBS OFF) + # ----------------------------------------------- # IACore # ----------------------------------------------- @@ -7,7 +9,6 @@ add_subdirectory(IACore/) # SDL3 # ----------------------------------------------- set(SDL_TEST_LIBRARY OFF) -set(BUILD_SHARED_LIBS OFF) add_subdirectory(SDL/) # ----------------------------------------------- @@ -22,10 +23,15 @@ add_subdirectory(SDL_mixer/) add_subdirectory(freetype/) add_library(Freetype::Freetype ALIAS freetype) +# ----------------------------------------------- +# LunaSVG +# ----------------------------------------------- +set(LUNASVG_BUILD_EXAMPLES OFF) +add_subdirectory(lunasvg/) + # ----------------------------------------------- # RmlUI # ----------------------------------------------- -add_subdirectory(lunasvg/) set(RMLUI_SVG_PLUGIN ON) add_subdirectory(RmlUI/)