Can update mouse mode from lua

This commit is contained in:
Dane Johnson
2021-08-02 14:34:49 -05:00
parent 44e8f784f5
commit 2fbbf39e9a
5 changed files with 33 additions and 6 deletions

View File

@@ -14,10 +14,26 @@ Input *Input::GetInstance() {
}
void Input::Use(Window window){
glfwSetInputMode(window.glfwWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
glfwSetKeyCallback(window.glfwWindow, (GLFWkeyfun)HandleKeys);
glfwSetCursorPosCallback(window.glfwWindow, (GLFWcursorposfun)HandleMousePosition);
void Input::Use(Window *window){
this->window = window;
glfwSetKeyCallback(window->glfwWindow, (GLFWkeyfun)HandleKeys);
glfwSetCursorPosCallback(window->glfwWindow, (GLFWcursorposfun)HandleMousePosition);
}
void Input::SetMouseMode(MouseMode mouseMode) {
this->mouseMode = mouseMode;
switch(mouseMode) {
case MouseMode::VISIBLE:
glfwSetInputMode(window->glfwWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
break;
case MouseMode::CAPTURED:
glfwSetInputMode(window->glfwWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
break;
case MouseMode::HIDDEN:
glfwSetInputMode(window->glfwWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
break;
}
}
void Input::HandleKeys(GLFWwindow *_, int keys, int code, int action, int mods) {

View File

@@ -13,13 +13,20 @@ typedef void (*MousePositionHandler)(double xpos, double ypos, double xrel, doub
class Input {
public:
enum MouseMode {
VISIBLE, HIDDEN, CAPTURED
};
static Input *GetInstance();
void Use(Window window);
void Use(Window *window);
void SetMouseMode(MouseMode mouseMode);
std::vector<KeyHandler> keyHandlers;
std::vector<MousePositionHandler> mousePositionHandlers;
private:
bool firstMousePositionUpdate = true;
double lastx, lasty;
MouseMode mouseMode;
Window *window;
Input();
static void HandleKeys(GLFWwindow *_, int key, int code, int action, int mods);
static void HandleMousePosition(GLFWwindow *_, double xpos, double ypos);

View File

@@ -69,7 +69,7 @@ int main(int argc, char *argv[]) {
root = Node::GetRoot();
Input *input = Input::GetInstance();
input->Use(window);
input->Use(&window);
Camera defaultCamera;