cae  0.0.0
Cross-API graphics engine
Loading...
Searching...
No Matches
GLFW.hpp
Go to the documentation of this file.
1///
2/// @file GLFW.hpp
3/// @brief This file contains the GLFW class declaration
4/// @namespace cae
5///
6
7#pragma once
8
10
11#ifdef _WIN32
12#define GLFW_EXPOSE_NATIVE_WIN32
13#elifdef __linux__
14#define GLFW_EXPOSE_NATIVE_X11
15#elifdef __APPLE__
16#define GLFW_EXPOSE_NATIVE_COCOA
17#endif
18#include <GLFW/glfw3.h>
19
20#include <queue>
21
22namespace cae
23{
24
25 ///
26 /// @class GLFW
27 /// @brief Class for the GLFW plugin
28 /// @namespace cae
29 ///
30 class GLFW final : public AWindow
31 {
32
33 public:
34 GLFW() = default;
35 ~GLFW() override = default;
36
37 GLFW(const GLFW &) = delete;
38 GLFW &operator=(const GLFW &) = delete;
39 GLFW(GLFW &&) = delete;
40 GLFW &operator=(GLFW &&) = delete;
41
42 [[nodiscard]] std::string getName() const override { return "GLFW"; }
43 [[nodiscard]] utl::PluginType getType() const override { return utl::PluginType::WINDOW; }
44 [[nodiscard]] utl::PluginPlatform getPlatform() const override { return utl::PluginPlatform::ALL; }
45
46 bool create(const std::string &name, WindowSize size) override;
47 void close() override;
48
49 [[nodiscard]] NativeWindowHandle getNativeHandle() const override;
50 [[nodiscard]] WindowSize getWindowSize() const override;
51
52 void setIcon(const std::string &path) const override;
53
54 [[nodiscard]] bool shouldClose() const override { return glfwWindowShouldClose(m_window) != 0; }
55 void pollEvents() override { glfwPollEvents(); }
56 bool pollEvent(WindowEvent &event) override;
57
58 [[nodiscard]] bool wasResized() const override { return m_frameBufferResized; }
59 void resetResizedFlag() override { m_frameBufferResized = false; }
60
61 private:
62 static void frameBufferResizeCallback(GLFWwindow *window, int width, int height);
63 static void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods);
64 static void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods);
65 static void cursorPosCallback(GLFWwindow *window, double x, double y);
66 static void scrollCallback(GLFWwindow *window, double xoffset, double yoffset);
67
68 std::queue<WindowEvent> m_eventQueue;
69
70 GLFWwindow *m_window = nullptr;
73
74 }; // class GLFW
75
76} // namespace cae
This file contains the Window abstract class.
Class for the GLFW plugin.
Definition GLFW.hpp:31
bool create(const std::string &name, WindowSize size) override
Create a window with the given name and size.
Definition glfw.cpp:268
void setIcon(const std::string &path) const override
Set the window icon from the given image path.
Definition glfw.cpp:336
static void cursorPosCallback(GLFWwindow *window, double x, double y)
Definition glfw.cpp:217
void close() override
Close the window.
Definition glfw.cpp:302
GLFW(const GLFW &)=delete
utl::PluginType getType() const override
Get the type of the plugin.
Definition GLFW.hpp:43
bool m_frameBufferResized
Definition GLFW.hpp:72
utl::PluginPlatform getPlatform() const override
Get the handled platform of the plugin.
Definition GLFW.hpp:44
bool wasResized() const override
Check if the window was resized.
Definition GLFW.hpp:58
~GLFW() override=default
static void scrollCallback(GLFWwindow *window, double xoffset, double yoffset)
Definition glfw.cpp:233
GLFW()=default
GLFW & operator=(const GLFW &)=delete
static void frameBufferResizeCallback(GLFWwindow *window, int width, int height)
Definition glfw.cpp:249
GLFWwindow * m_window
Definition GLFW.hpp:70
WindowSize getWindowSize() const override
Get the current window size.
Definition glfw.cpp:312
bool pollEvent(WindowEvent &event) override
Poll window events into outEvent.
Definition glfw.cpp:348
NativeWindowHandle getNativeHandle() const override
Get the native window handle.
Definition glfw.cpp:320
std::string getName() const override
Get the name of the plugin.
Definition GLFW.hpp:42
void pollEvents() override
Poll window events.
Definition GLFW.hpp:55
std::queue< WindowEvent > m_eventQueue
Definition GLFW.hpp:68
WindowSize m_frameBufferSize
Definition GLFW.hpp:71
static void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
Definition glfw.cpp:202
void resetResizedFlag() override
Reset the resized flag.
Definition GLFW.hpp:59
GLFW & operator=(GLFW &&)=delete
GLFW(GLFW &&)=delete
static void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
Definition glfw.cpp:176
bool shouldClose() const override
Check if the window should close.
Definition GLFW.hpp:54
PluginPlatform
Definition IPlugin.hpp:33
PluginType
Definition IPlugin.hpp:22
Struct for native window handle.
Definition IWindow.hpp:34
Struct for window events.
Definition IWindow.hpp:63
Struct for window size.
Definition IWindow.hpp:23