6#include <GLFW/glfw3native.h>
8#include <unordered_map>
88 case GLFW_KEY_LEFT_SHIFT:
90 case GLFW_KEY_RIGHT_SHIFT:
92 case GLFW_KEY_LEFT_CONTROL:
94 case GLFW_KEY_RIGHT_CONTROL:
96 case GLFW_KEY_LEFT_ALT:
98 case GLFW_KEY_RIGHT_ALT:
100 case GLFW_KEY_LEFT_SUPER:
102 case GLFW_KEY_RIGHT_SUPER:
104 case GLFW_KEY_CAPS_LOCK:
119 case GLFW_KEY_PAGE_UP:
121 case GLFW_KEY_PAGE_DOWN:
126 case GLFW_KEY_BACKSPACE:
132 case GLFW_KEY_DELETE:
134 case GLFW_KEY_INSERT:
162 case GLFW_KEY_ESCAPE:
164 case GLFW_KEY_PRINT_SCREEN:
178 auto *self =
static_cast<GLFW *
>(glfwGetWindowUserPointer(window));
185 if (action == GLFW_PRESS)
189 else if (action == GLFW_RELEASE)
199 self->m_eventQueue.push(e);
204 auto *self =
static_cast<GLFW *
>(glfwGetWindowUserPointer(window));
213 e.mouseButton.button =
static_cast<MouseButton>(button);
214 self->m_eventQueue.push(e);
219 auto *self =
static_cast<GLFW *
>(glfwGetWindowUserPointer(window));
227 e.mouseMove.x =
static_cast<int>(x);
228 e.mouseMove.y =
static_cast<int>(y);
230 self->m_eventQueue.push(e);
235 auto *self =
static_cast<GLFW *
>(glfwGetWindowUserPointer(window));
243 e.scroll.x =
static_cast<float>(xoffset);
244 e.scroll.y =
static_cast<float>(yoffset);
246 self->m_eventQueue.push(e);
251 auto *self =
static_cast<GLFW *
>(glfwGetWindowUserPointer(window));
258 self->m_frameBufferSize = {.width =
static_cast<uint16_t
>(width), .height =
static_cast<uint16_t
>(height)};
262 e.resize.w = self->m_frameBufferSize.width;
263 e.resize.h = self->m_frameBufferSize.height;
265 self->m_eventQueue.push(e);
278 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
281 m_window = glfwCreateWindow(size.
width, size.
height, name.c_str(),
nullptr,
nullptr);
282 if (m_window ==
nullptr)
289 glfwSetWindowUserPointer(m_window,
this);
291 glfwSetFramebufferSizeCallback(m_window, frameBufferResizeCallback);
292 glfwSetKeyCallback(m_window, keyCallback);
293 glfwSetMouseButtonCallback(m_window, mouseButtonCallback);
294 glfwSetCursorPosCallback(m_window, cursorPosCallback);
295 glfwSetScrollCallback(m_window, scrollCallback);
297 glfwMakeContextCurrent((GLFWwindow *)m_window);
304 if (m_window !=
nullptr)
306 glfwDestroyWindow(m_window);
316 glfwGetWindowSize(m_window, &width, &height);
317 return {.width =
static_cast<uint16_t
>(width), .height =
static_cast<uint16_t
>(height)};
324 handle.
window = glfwGetWin32Window(m_window);
325 handle.display = GetModuleHandle(
nullptr);
327 handle.window =
reinterpret_cast<void *
>(glfwGetX11Window(m_window));
328 handle.display = glfwGetX11Display();
330 handle.window = glfwGetCocoaWindow(m_window);
331 handle.display =
nullptr;
339 if (image.
pixels ==
nullptr)
344 static const GLFWimage appIcon{.width = image.
width, .height = image.
height, .pixels = image.
pixels};
345 glfwSetWindowIcon(m_window, 1, &appIcon);
350 if (m_eventQueue.empty())
355 event = m_eventQueue.front();
This file contains the GLFW class declaration.
This file contains image struct.
This file contains the Logger class.
Class for the GLFW plugin.
bool create(const std::string &name, WindowSize size) override
Create a window with the given name and size.
void setIcon(const std::string &path) const override
Set the window icon from the given image path.
static void cursorPosCallback(GLFWwindow *window, double x, double y)
void close() override
Close the window.
bool m_frameBufferResized
static void scrollCallback(GLFWwindow *window, double xoffset, double yoffset)
static void frameBufferResizeCallback(GLFWwindow *window, int width, int height)
WindowSize getWindowSize() const override
Get the current window size.
bool pollEvent(WindowEvent &event) override
Poll window events into outEvent.
NativeWindowHandle getNativeHandle() const override
Get the native window handle.
static void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
static void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
static void log(const std::string &message, const LogLevel &logLevel)
Log a message with a specific log level.
static cae::KeyCode translateKey(const int key)
Struct for native window handle.
Struct for window events.