Fixed Windows

This commit is contained in:
Light 2021-09-24 17:20:19 +03:30
parent f0e127dbd0
commit b24c94a718
2 changed files with 81 additions and 54 deletions

View file

@ -5,7 +5,10 @@ project(Light VERSION 1.0.0)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
set(SPIRV_CROSS_ENABLE_TESTS OFF) set(SPIRV_CROSS_ENABLE_TESTS OFF)
set(INSTALL_GTEST OFF) set(INSTALL_GTEST OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error")
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error")
endif()
add_subdirectory(Dependencies/ShaderConductor) # <-- this project should not use "cxx_standard 17" add_subdirectory(Dependencies/ShaderConductor) # <-- this project should not use "cxx_standard 17"
# directories # directories

View file

@ -134,88 +134,112 @@ namespace Light {
//============================== MOUSE_EVENTS ==============================// //============================== MOUSE_EVENTS ==============================//
/* cursor position */ /* cursor position */
glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xpos, double ypos) glfwSetCursorPosCallback(m_Handle, [](GLFWwindow* window, double xpos, double ypos)
{ {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
callback(MouseMovedEvent(xpos, ypos));
}); MouseMovedEvent event(xpos, ypos);
callback(event);
});
/* mouse button */ /* mouse button */
glfwSetMouseButtonCallback(m_Handle, [](GLFWwindow* window, int button, int action, int mods) glfwSetMouseButtonCallback(m_Handle, [](GLFWwindow* window, int button, int action, int mods)
{ {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
if (action == GLFW_PRESS) if (action == GLFW_PRESS)
callback(ButtonPressedEvent(button)); {
else ButtonPressedEvent event(button);
callback(ButtonReleasedEvent (button)); callback(event);
}); }
else if (action == GLFW_RELEASE)
{
ButtonReleasedEvent event(button);
callback(event);
}
});
/* scroll */ /* scroll */
glfwSetScrollCallback(m_Handle, [](GLFWwindow* window, double xoffset, double yoffset) glfwSetScrollCallback(m_Handle, [](GLFWwindow* window, double xoffset, double yoffset)
{ {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
callback(WheelScrolledEvent (yoffset));
}); WheelScrolledEvent event(yoffset);
callback(event);
});
//============================== MOUSE_EVENTS ==============================// //============================== MOUSE_EVENTS ==============================//
//============================== KEYBOARD_EVENTS ==============================// //============================== KEYBOARD_EVENTS ==============================//
/* key */ /* key */
glfwSetKeyCallback(m_Handle, [](GLFWwindow* window, int key, int scancode, int action, int mods) glfwSetKeyCallback(m_Handle, [](GLFWwindow* window, int key, int scancode, int action, int mods)
{ {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
if (action == GLFW_PRESS)
callback(KeyPressedEvent(key));
else if (action == GLFW_RELEASE)
callback(KeyReleasedEvent(key));
else if (action == GLFW_REPEAT)
callback(KeyRepeatEvent(key));
});
if (action == GLFW_PRESS)
{
KeyPressedEvent event(key);
callback(event);
}
else if (action == GLFW_RELEASE)
{
KeyReleasedEvent event(key);
callback(event);
}
});
/* char */ /* char */
glfwSetCharCallback(m_Handle, [](GLFWwindow* window, unsigned int character) glfwSetCharCallback(m_Handle, [](GLFWwindow* window, unsigned int character)
{ {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
callback(SetCharEvent(character));
});
// ImGuiIO& io = ImGui::GetIO(); SetCharEvent event(character);
// io.AddInputCharacter(c); callback(event);
});
//============================== KEYBOARD_EVENTS ==============================// //============================== KEYBOARD_EVENTS ==============================//
//============================== WINDOW_EVENTS ==============================// //============================== WINDOW_EVENTS ==============================//
/* window position */ /* window position */
glfwSetWindowPosCallback(m_Handle, [](GLFWwindow* window, int xpos, int ypos) glfwSetWindowPosCallback(m_Handle, [](GLFWwindow* window, int xpos, int ypos)
{ {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
callback(WindowMovedEvent(xpos, ypos)); WindowMovedEvent event(xpos, ypos);
});
callback(event);
});
/* window size */ /* window size */
glfwSetWindowSizeCallback(m_Handle, [](GLFWwindow* window, int width, int height) glfwSetWindowSizeCallback(m_Handle, [](GLFWwindow* window, int width, int height)
{ {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
callback(WindowResizedEvent(width, height)); WindowResizedEvent event(width, height);
});
callback(event);
});
/* window close */ /* window close */
glfwSetWindowCloseCallback(m_Handle, [](GLFWwindow* window) glfwSetWindowCloseCallback(m_Handle, [](GLFWwindow* window)
{ {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
callback(WindowClosedEvent()); WindowClosedEvent event;
});
callback(event);
});
/* window focus */ /* window focus */
glfwSetWindowFocusCallback(m_Handle, [](GLFWwindow* window, int focus) glfwSetWindowFocusCallback(m_Handle, [](GLFWwindow* window, int focus)
{ {
std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window); std::function<void(Event&)> callback = *(std::function<void(Event&)>*)glfwGetWindowUserPointer(window);
if(focus == GLFW_TRUE) if (focus == GLFW_TRUE)
callback(WindowGainFocusEvent()); {
else WindowGainFocusEvent event;
callback(WindowLostFocusEvent()); callback(event);
}); }
//============================== WINDOW_EVENTS ==============================// else
{
WindowLostFocusEvent event;
callback(event);
}
});
//============================== WINDOW_EVENTS ==============================// }
} }
} }