SpiecsEngine
 
Loading...
Searching...
No Matches
VulkanWindows.cpp
Go to the documentation of this file.
1/**
2* @file VulkanWindows.cpp.
3* @brief The VulkanWindows Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
9
10#include "Core/Event/KeyEvent.h"
11#include "Core/Event/MouseEvent.h"
12#include "Core/Event/WindowEvent.h"
13
14namespace Spices {
15
16 VulkanWindows::VulkanWindows(VulkanState& vulkanState, const WindowInfo& initInfo)
18 {
20
21 /**
22 * @brief glfw initialize.
23 */
24 glfwInit();
25
26 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); /* @brief Set glfw not use OpenGl api. */
27 glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); /* @brief Set glfw enable resize feature. */
28 glfwWindowHint(GLFW_DECORATED, GLFW_TRUE); /* @brief Set glfw enable title tab. */
29
30 const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
31
32 glfwWindowHint(GLFW_RED_BITS , mode->redBits );
33 glfwWindowHint(GLFW_GREEN_BITS , mode->greenBits );
34 glfwWindowHint(GLFW_BLUE_BITS , mode->blueBits );
35 glfwWindowHint(GLFW_REFRESH_RATE , mode->refreshRate );
36
37 /**
38 * @brief Create glfwWindow.
39 * Display in Main monitor.
40 */
41 vulkanState.m_Windows = glfwCreateWindow(initInfo.width, initInfo.height, initInfo.name.c_str(), nullptr, nullptr);
42
43 /**
44 * @brief Set glfwWindow Icon.
45 */
46 glfwSetWindowIcon(vulkanState.m_Windows, 1, &initInfo.icon->image);
47
48 /*HWND hwndGLFW = glfwGetWin32Window(vulkanState.m_Windows);
49 LONG ret = ::GetWindowLong(hwndGLFW, GWL_EXSTYLE);
50 ret = ret | WS_EX_LAYERED;
51 ::SetWindowLong(hwndGLFW, GWL_EXSTYLE, ret);
52 ::SetLayeredWindowAttributes(hwndGLFW, RGB(255, 0, 0), 255, LWA_COLORKEY | LWA_ALPHA);*/
53
54 /**
55 * @brief Set glfw call back object pointer.
56 */
57 glfwSetWindowUserPointer(vulkanState.m_Windows, this);
58
59 /**
60 * @brief Set all needed GLFW events call back.
61 */
63 }
64
66 {
68
69 /**
70 * @brief Destroy glfw window.
71 */
72 glfwDestroyWindow(m_VulkanState.m_Windows);
73
74 /**
75 * @brief Destroy glfw relative object.
76 */
77 glfwTerminate();
78 }
79
81 {
83
84 /**
85 * @brief Error event Callback.
86 * @todo Butter Log.
87 */
88 glfwSetErrorCallback([](int error, const char* description)
89 {
90 //SPICES_CORE_INFO(error);
91 SPICES_CORE_INFO(description);
92 });
93
94 /**
95 * @brief Framebuffer resize event Callback.
96 * @note Not in use now.
97 */
98 //glfwSetFramebufferSizeCallback(vulkanState.m_Windows, WindowsResizeCallback);
99
100 /**
101 * @brief Window resize event Callback.
102 */
103 glfwSetWindowSizeCallback(m_VulkanState.m_Windows, [](GLFWwindow* window, int width, int height)
104 {
105 /**
106 * @brief Reinterpretate the pointer to this class.
107 */
108 const auto vulkanWindow = static_cast<VulkanWindows*>(glfwGetWindowUserPointer(window));
109
110 /**
111 * @brief Set this class's variable.
112 */
113 vulkanWindow->m_WindowsResized = true;
114 vulkanWindow->m_WindowInfo.width = width;
115 vulkanWindow->m_WindowInfo.height = height;
116
117 /**
118 * @brief Create an specific event.
119 */
120 WindowResizeEvent event(width, height);
121
122 /**
123 * @brief Execute the global event function pointer by passing the specific event.
124 */
126 });
127
128 /**
129 * @brief Window close event Callback.
130 */
131 glfwSetWindowCloseCallback(m_VulkanState.m_Windows, [](GLFWwindow* window)
132 {
133 /**
134 * @brief Create an specific event.
135 */
136 WindowCloseEvent event;
137
138 /**
139 * @brief Execute the global event function pointer by passing the specific event.
140 */
142 });
143
144 /**
145 * @brief Key event Callback.
146 */
147 glfwSetKeyCallback(m_VulkanState.m_Windows, [](GLFWwindow* window, int key, int scancode, int action, int mods)
148 {
149 switch (action)
150 {
151 case GLFW_PRESS:
152 {
153 /**
154 * @brief Create an specific event.
155 */
156 KeyPressedEvent event(key, 0);
157
158 /**
159 * @brief Execute the global event function pointer by passing the specific event.
160 */
162
163 break;
164 }
165 case GLFW_RELEASE:
166 {
167 /**
168 * @brief Create an specific event.
169 */
170 KeyReleasedEvent event(key);
171
172 /**
173 * @brief Execute the global event function pointer by passing the specific event.
174 */
176
177 break;
178 }
179 case GLFW_REPEAT:
180 {
181 /**
182 * @brief Create an specific event.
183 */
184 KeyPressedEvent event(key, 1);
185
186 /**
187 * @brief Execute the global event function pointer by passing the specific event.
188 */
190
191 break;
192 }
193 }
194 });
195
196 /**
197 * @brief Key Input event Callback.
198 */
199 glfwSetCharCallback(m_VulkanState.m_Windows, [](GLFWwindow* window, unsigned int keycode)
200 {
201 /**
202 * @brief Create an specific event.
203 */
204 KeyTypedEvent event(static_cast<int>(keycode));
205
206 /**
207 * @brief Execute the global event function pointer by passing the specific event.
208 */
210 });
211
212 /**
213 * @brief Mouse Button event Callback.
214 */
215 glfwSetMouseButtonCallback(m_VulkanState.m_Windows, [](GLFWwindow* window, int button, int action, int mods)
216 {
217 switch (action)
218 {
219 case GLFW_PRESS:
220 {
221 /**
222 * @brief Create an specific event.
223 */
224 MouseButtonPressedEvent event(button);
225
226 /**
227 * @brief Execute the global event function pointer by passing the specific event.
228 */
230
231 break;
232 }
233 case GLFW_RELEASE:
234 {
235 /**
236 * @brief Create an specific event.
237 */
238 MouseButtonReleasedEvent event(button);
239
240 /**
241 * @brief Execute the global event function pointer by passing the specific event.
242 */
244
245 break;
246 }
247 }
248 });
249
250 /**
251 * @brief Mouse Scroll event Callback.
252 */
253 glfwSetScrollCallback(m_VulkanState.m_Windows, [](GLFWwindow* window, double xOffset, double yOffset)
254 {
255 /**
256 * @brief Create an specific event.
257 */
258 MouseScrolledEvent event(static_cast<float>(xOffset), static_cast<float>(yOffset));
259
260 /**
261 * @brief Execute the global event function pointer by passing the specific event.
262 */
264 });
265
266 /**
267 * @brief Mouse Move event Callback.
268 */
269 glfwSetCursorPosCallback(m_VulkanState.m_Windows, [](GLFWwindow* window, double xPos, double yPos)
270 {
271 /**
272 * @brief Create an specific event.
273 */
274 MouseMovedEvent event(static_cast<float>(xPos), static_cast<float>(yPos));
275
276 /**
277 * @brief Execute the global event function pointer by passing the specific event.
278 */
280 });
281 }
282}
#define SPICES_PROFILE_ZONE
static EventCallbackFn GetEventCallbackFn()
Get Global Root Event Function Pointer.
Definition Event.cpp:17
This Class is the basic Event Class. Inherit from it and create specific event class.
Definition Event.h:96
KeyPressedEvent(int keycode, int repeatCount)
Constructor Function.
Definition KeyEvent.h:65
This Class is inherited from KeyEvent Class.
Definition KeyEvent.h:57
KeyReleasedEvent(int keycode)
Constructor Function.
Definition KeyEvent.h:117
This Class is inherited from KeyEvent Class.
Definition KeyEvent.h:110
KeyTypedEvent(int keycode)
Constructor Function.
Definition KeyEvent.h:155
This Class is inherited from KeyEvent Class.
Definition KeyEvent.h:148
MouseButtonPressedEvent(int button)
Constructor Function.
Definition MouseEvent.h:201
This Class is inherited from Event Class.
Definition MouseEvent.h:194
MouseButtonReleasedEvent(int button)
Constructor Function.
Definition MouseEvent.h:239
This Class is inherited from Event Class.
Definition MouseEvent.h:232
MouseMovedEvent(float x, float y)
Constructor Function.
Definition MouseEvent.h:25
This Class is inherited from Event Class.
Definition MouseEvent.h:17
MouseScrolledEvent(float xOffset, float yOffset)
Constructor Function.
Definition MouseEvent.h:94
This Class is inherited from Event Class.
Definition MouseEvent.h:86
VulkanState & m_VulkanState
The global VulkanState Referenced from VulkanRenderBackend.
VulkanObject(VulkanState &vulkanState)
Constructor Function. Init member variables.
VulkanObject Class. This class defines the basic behaves of VulkanObject. When we create an new Vulka...
VulkanWindows(VulkanState &vulkanState, const WindowInfo &initInfo)
Constructor Function. Create Windows.
virtual ~VulkanWindows() override
Destructor Function.
void SetInternalCallBack() const
Set all needed GLFW events call back.
VulkanWindows Class. This class defines the windows behaves.
This Class is inherited from Event Class.
Definition WindowEvent.h:88
WindowResizeEvent(uint32_t width, uint32_t height)
Constructor Function.
Definition WindowEvent.h:27
This Class is inherited from Event Class. Called when window resized. This Event register by glfw win...
Definition WindowEvent.h:19
This struct contains all Vulkan object in used global.
Definition VulkanUtils.h:74
std::string name
Window's name.
int width
Window's width.
int height
Window's height.
This struct defines the basic information of window.