Skip to content

Commit 22d52df

Browse files
committed
Shifted GLFW specifics to within window class
1 parent 80af942 commit 22d52df

File tree

10 files changed

+178
-81
lines changed

10 files changed

+178
-81
lines changed

engine/render/renderer/platform/vulkan/Context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
#include "Context.h"
1111

12-
#include <utils/Logging.h>
1312
#include <GLFW/glfw3.h>
13+
#include <utils/Logging.h>
1414

1515
#include "render/renderer/Renderer.h"
1616

engine/window/Key.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//
2+
// Copyright (c) 2022 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
3+
//
4+
// This code is released under an unmodified zlib license.
5+
// For conditions of distribution and use, please see:
6+
// https://opensource.org/licenses/Zlib
7+
//
8+
19
#ifndef SIEGE_ENGINE_KEY_H
210
#define SIEGE_ENGINE_KEY_H
311

engine/window/Window.cpp

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,120 @@
88

99
#include "Window.h"
1010

11+
#include "window/platform/glfw/Window.h"
12+
13+
static Siege::Glfw::Window AsGlfwWindow(void* window)
14+
{
15+
return reinterpret_cast<Siege::Glfw::Window>(window);
16+
}
17+
1118
namespace Siege
1219
{
20+
Window::Window(const char* name, WindowExtents extents) : extents(extents)
21+
{
22+
Glfw::Initialize();
23+
24+
if (!window) window = Glfw::CreateWindow(name, extents.width, extents.height, this);
25+
26+
Glfw::SetIsMouseMotionRaw(AsGlfwWindow(window), true);
27+
28+
Glfw::SetWindowMinimisedCallback(
29+
AsGlfwWindow(window),
30+
[](Glfw::Window pWindow, int isMinimised) {
31+
reinterpret_cast<Window*>(Glfw::GetUserPtr(pWindow))->isVisible = !isMinimised;
32+
});
33+
34+
Glfw::SetWindowResizedCallback(
35+
AsGlfwWindow(window),
36+
[](Glfw::Window pWindow, int width, int height) {
37+
auto windowContext = reinterpret_cast<Window*>(Glfw::GetUserPtr(pWindow));
38+
windowContext->wasResized = true;
39+
windowContext->extents = {static_cast<uint32_t>(width), static_cast<uint32_t>(height)};
40+
});
41+
42+
DPI = Glfw::GetWindowDPI();
43+
}
44+
45+
Window::~Window()
46+
{
47+
Glfw::FreeWindow(AsGlfwWindow(window));
48+
Glfw::FreeGlfw();
49+
}
50+
51+
int Window::GetHeight() const
52+
{
53+
return extents.height;
54+
}
55+
56+
int Window::GetWidth() const
57+
{
58+
return extents.width;
59+
}
60+
61+
bool Window::IsVisible() const
62+
{
63+
return isVisible;
64+
}
65+
66+
unsigned int Window::GetDPI() const
67+
{
68+
// NOTE(Aryeh): Need to find a better solution when the DPI in different axes are not the
69+
// same
70+
return DPI.width;
71+
}
72+
73+
WindowExtents Window::GetExtents() const
74+
{
75+
return extents;
76+
}
77+
78+
void* Window::GetRawWindow()
79+
{
80+
return window;
81+
}
82+
1383
void Window::Update()
1484
{
1585
Glfw::GetEvents();
1686
}
1787

1888
bool Window::WindowShouldClose()
1989
{
20-
return Glfw::WindowShouldClose(window);
90+
return Glfw::WindowShouldClose(AsGlfwWindow(window));
91+
}
92+
93+
bool Window::WasResized() const
94+
{
95+
return wasResized;
96+
}
97+
98+
void Window::ResetWindowResized()
99+
{
100+
wasResized = false;
101+
}
102+
103+
void Window::EnableCursor()
104+
{
105+
Glfw::SetIsCursorVisible(AsGlfwWindow(window), true);
106+
}
107+
108+
void Window::DisableCursor()
109+
{
110+
Glfw::SetIsCursorVisible(AsGlfwWindow(window), false);
21111
}
22112

23113
MHArray<const char*> Window::GetRequiredExtensions()
24114
{
25115
return Glfw::GetRequiredExtensions();
26116
}
117+
118+
void Window::ToggleCursor(bool state)
119+
{
120+
state ? DisableCursor() : EnableCursor();
121+
}
122+
123+
void Window::WaitEvents()
124+
{
125+
Glfw::WaitEvents();
126+
}
27127
} // namespace Siege

engine/window/Window.h

Lines changed: 20 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#ifndef SIEGE_ENGINE_RENDERER_WINDOW_H
1010
#define SIEGE_ENGINE_RENDERER_WINDOW_H
1111

12-
#include "window/platform/glfw/Window.h"
12+
#include <utils/collections/HeapArray.h>
13+
14+
#include "window/utils/Types.h"
1315

1416
namespace Siege
1517
{
@@ -20,112 +22,51 @@ class Window
2022

2123
// 'Structors
2224

23-
Window(char const* name, WindowExtents extents) : extents(extents)
24-
{
25-
Glfw::Initialize();
25+
Window(char const* name, WindowExtents extents);
2626

27-
if (!window) window = Glfw::CreateWindow(name, extents.width, extents.height, this);
27+
Window() : Window("Window", {800, 600}) {}
2828

29-
Glfw::SetIsMouseMotionRaw(window, true);
29+
~Window();
3030

31-
Glfw::SetWindowMinimisedCallback(window, [](Glfw::Window pWindow, int isMinimised) {
32-
reinterpret_cast<Window*>(Glfw::GetUserPtr(pWindow))->isVisible = !isMinimised;
33-
});
31+
// Public Getters
3432

35-
Glfw::SetWindowResizedCallback(window, [](Glfw::Window pWindow, int width, int height) {
36-
auto windowContext = reinterpret_cast<Window*>(Glfw::GetUserPtr(pWindow));
37-
windowContext->wasResized = true;
38-
windowContext->extents = {static_cast<uint32_t>(width), static_cast<uint32_t>(height)};
39-
});
33+
int GetHeight() const;
4034

41-
DPI = Glfw::GetWindowDPI();
42-
}
35+
int GetWidth() const;
4336

44-
Window() : Window("Window", {800, 600}) {}
37+
bool IsVisible() const;
4538

46-
~Window()
47-
{
48-
Glfw::FreeWindow(window);
49-
Glfw::FreeGlfw();
50-
}
39+
unsigned int GetDPI() const;
5140

52-
// Public Getters
41+
WindowExtents GetExtents() const;
5342

54-
const int GetHeight() const
55-
{
56-
return extents.height;
57-
}
58-
59-
const int GetWidth() const
60-
{
61-
return extents.width;
62-
}
63-
64-
const bool IsVisible() const
65-
{
66-
return isVisible;
67-
}
68-
69-
const unsigned int GetDPI() const
70-
{
71-
// NOTE(Aryeh): Need to find a better solution when the DPI in different axes are not the
72-
// same
73-
return DPI.width;
74-
}
75-
76-
WindowExtents GetExtents() const
77-
{
78-
return extents;
79-
}
80-
81-
Glfw::Window GetRawWindow()
82-
{
83-
return window;
84-
}
43+
void* GetRawWindow();
8544

8645
// Public Functions
8746

8847
void Update();
8948

9049
bool WindowShouldClose();
9150

92-
bool WasResized() const
93-
{
94-
return wasResized;
95-
}
51+
bool WasResized() const;
9652

97-
void ResetWindowResized()
98-
{
99-
wasResized = false;
100-
}
53+
void ResetWindowResized();
10154

102-
void EnableCursor()
103-
{
104-
Glfw::SetIsCursorVisible(window, true);
105-
}
55+
void EnableCursor();
10656

107-
void DisableCursor()
108-
{
109-
Glfw::SetIsCursorVisible(window, false);
110-
}
57+
void DisableCursor();
11158

11259
static MHArray<const char*> GetRequiredExtensions();
11360

114-
void ToggleCursor(bool state)
115-
{
116-
state ? DisableCursor() : EnableCursor();
117-
}
61+
void ToggleCursor(bool state);
11862

119-
void WaitEvents()
120-
{
121-
Glfw::WaitEvents();
122-
}
63+
void WaitEvents();
12364

12465
private:
12566

12667
// Private variables
12768

128-
Glfw::Window window {nullptr};
69+
void* window {nullptr};
12970

13071
WindowExtents extents;
13172
MonitorPixelScale DPI {};

engine/window/platform/glfw/Input.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//
2+
// Copyright (c) 2022 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
3+
//
4+
// This code is released under an unmodified zlib license.
5+
// For conditions of distribution and use, please see:
6+
// https://opensource.org/licenses/Zlib
7+
//
8+
19
#include "Input.h"
210

311
#include <GLFW/glfw3.h>

engine/window/platform/glfw/Input.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//
2+
// Copyright (c) 2022 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
3+
//
4+
// This code is released under an unmodified zlib license.
5+
// For conditions of distribution and use, please see:
6+
// https://opensource.org/licenses/Zlib
7+
//
8+
19
#ifndef SIEGE_ENGINE_GLFW_INPUT_H
210
#define SIEGE_ENGINE_GLFW_INPUT_H
311

engine/window/platform/glfw/Types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//
2+
// Copyright (c) 2022 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
3+
//
4+
// This code is released under an unmodified zlib license.
5+
// For conditions of distribution and use, please see:
6+
// https://opensource.org/licenses/Zlib
7+
//
8+
19
#ifndef SIEGE_ENGINE_GLFW_TYPES_H
210
#define SIEGE_ENGINE_GLFW_TYPES_H
311

engine/window/platform/glfw/Window.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//
2+
// Copyright (c) 2022 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
3+
//
4+
// This code is released under an unmodified zlib license.
5+
// For conditions of distribution and use, please see:
6+
// https://opensource.org/licenses/Zlib
7+
//
8+
19
#include "Window.h"
210

311
#include <GLFW/glfw3.h>

engine/window/platform/glfw/Window.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//
2+
// Copyright (c) 2022 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
3+
//
4+
// This code is released under an unmodified zlib license.
5+
// For conditions of distribution and use, please see:
6+
// https://opensource.org/licenses/Zlib
7+
//
8+
19
#ifndef SIEGE_ENGINE_GLFW_WINDOW_H
210
#define SIEGE_ENGINE_GLFW_WINDOW_H
311

engine/window/utils/Types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
//
2+
// Copyright (c) 2022 Jonathan Moallem (@J-Mo63) & Aryeh Zinn (@Raelr)
3+
//
4+
// This code is released under an unmodified zlib license.
5+
// For conditions of distribution and use, please see:
6+
// https://opensource.org/licenses/Zlib
7+
//
8+
19
#ifndef SIEGE_ENGINE_WINDOW_TYPES_H
210
#define SIEGE_ENGINE_WINDOW_TYPES_H
311

0 commit comments

Comments
 (0)