//
// Created by sebastian on 07.02.26.
//

#include "InputManager.h"

#include "../../core/Application.h"
#include "GLFW/glfw3.h"

bool InputManager::isKeyPressed(int keycode) {
    auto window = static_cast<GLFWwindow*>(Application::getInstance().getWindow().GetNativeWindow());
    return glfwGetKey(window, keycode) == GLFW_PRESS;
}

bool InputManager::isMouseButtonPressed(int button) {
    auto window = static_cast<GLFWwindow*>(Application::getInstance().getWindow().GetNativeWindow());
    return glfwGetMouseButton(window, button) == GLFW_PRESS;
}

glm::vec2 InputManager::getMousePosition() {
    auto window = static_cast<GLFWwindow*>(Application::getInstance().getWindow().GetNativeWindow());
    double xpos, ypos;
    glfwGetCursorPos(window, &xpos, &ypos);
    return {xpos, ypos};
}

glm::vec2 InputManager::getMouseDelta() {
    static double lastX = 0, lastY = 0;
    double xpos, ypos;
    auto window = static_cast<GLFWwindow*>(Application::getInstance().getWindow().GetNativeWindow());
    glfwGetCursorPos(window, &xpos, &ypos);
    glm::vec2 delta(xpos - lastX, ypos - lastY);
    lastX = xpos;
    lastY = ypos;
    return delta;
}

