10#include "misc/Error.h"
11#include "game/GameManager.h"
12#include "render/Renderer.h"
13#include "window/GLFW.hpp"
14#include "game/GameInstance.h"
15#include "input/KeyboardKey.hpp"
16#include "input/MouseButton.hpp"
52 static std::variant<std::unique_ptr<WindowCursor>,
Error>
53 create(
const std::filesystem::path& pathToIcon);
190 std::variant<std::unique_ptr<Window>,
Error>
build();
246 template <
typename MyGameInstance>
247 requires std::derived_from<MyGameInstance, GameInstance>
263 void setTitle(
const std::string& sNewTitle);
277 [[nodiscard]] std::optional<Error>
setIcon(
const std::filesystem::path& pathToIcon)
const;
294 std::variant<WindowCursor*, Error>
createCursor(
const std::filesystem::path& pathToIcon);
379 std::pair<int, int>
getSize()
const;
419 HWND getWindowHandle()
const;
605 template <
typename MyGameInstance>
606 requires std::derived_from<MyGameInstance, GameInstance>
611 if (optionalError.has_value()) [[unlikely]] {
612 optionalError->addCurrentLocationToErrorStack();
613 optionalError->showError();
614 throw std::runtime_error(optionalError->getFullErrorMessage());
633 float currentTimeInSec = 0.0f;
634 float prevTimeInSec =
static_cast<float>(glfwGetTime());
646 currentTimeInSec =
static_cast<float>(glfwGetTime());
647 pGameManager->onBeforeNewFrame(currentTimeInSec - prevTimeInSec);
648 prevTimeInSec = currentTimeInSec;
651 pRenderer->drawNextFrame();
Definition: GameManager.h:34
Definition: KeyboardKey.hpp:10
void info(std::string_view sText, const std::source_location location=std::source_location::current()) const
Definition: Logger.cpp:50
static Logger & get()
Definition: Logger.cpp:41
Definition: Renderer.h:43
WindowBuilder & withTitle(std::string_view sWindowTitle)
Definition: Window.cpp:27
WindowBuilder & withFullscreenMode(bool bEnableFullscreen)
Definition: Window.cpp:57
WindowBuilderParameters params
Definition: Window.h:194
WindowBuilder & withVisibility(bool bShow)
Definition: Window.cpp:39
std::variant< std::unique_ptr< Window >, Error > build()
Definition: Window.cpp:63
WindowBuilder & withMaximizedState(bool bMaximized)
Definition: Window.cpp:45
WindowBuilder & withIcon(const std::filesystem::path &pathToIcon)
Definition: Window.cpp:33
WindowBuilder & withSize(int iWidth, int iHeight)
Definition: Window.cpp:20
WindowBuilder & withSplashScreenMode(bool bIsSplashScreen)
Definition: Window.cpp:51
void releaseCursor()
Definition: Window.cpp:526
static std::variant< std::unique_ptr< WindowCursor >, Error > create(const std::filesystem::path &pathToIcon)
Definition: Window.cpp:503
GLFWcursor * pCursor
Definition: Window.h:78
GLFWcursor * getCursor() const
Definition: Window.cpp:531
~WindowCursor()
Definition: Window.cpp:494
std::unique_ptr< GameManager > pGameManager
Definition: Window.h:581
Renderer * getRenderer() const
Definition: Window.cpp:104
void bindToWindowEvents()
Definition: Window.cpp:207
std::string getTitle() const
Definition: Window.cpp:100
std::vector< std::unique_ptr< WindowCursor > > vCreatedCursors
Definition: Window.h:587
void setPreferredRenderer(const std::optional< RendererType > &preferredRenderer)
Definition: Window.cpp:394
std::pair< int, int > getSize() const
Definition: Window.cpp:72
void onMouseMove(double xPos, double yPos)
Definition: Window.cpp:126
std::variant< WindowCursor *, Error > createCursor(const std::filesystem::path &pathToIcon)
Definition: Window.cpp:428
void unbindFromWindowEvents()
Definition: Window.cpp:251
double lastMouseXPos
Definition: Window.h:599
static void glfwWindowFocusCallback(GLFWwindow *pGlfwWindow, int iFocused)
Definition: Window.cpp:171
void restore() const
Definition: Window.cpp:481
static void glfwWindowMouseScrollCallback(GLFWwindow *pGlfwWindow, double xOffset, double yOffset)
Definition: Window.cpp:189
void show() const
Definition: Window.cpp:398
void setDefaultCursor()
Definition: Window.cpp:453
void hide() const
Definition: Window.cpp:65
void setCursor(WindowCursor *pCursor)
Definition: Window.cpp:447
GLFWwindow * getGlfwWindow() const
Definition: Window.cpp:116
std::pair< double, double > getCursorPosition() const
Definition: Window.cpp:83
void setOpacity(float opacity) const
Definition: Window.cpp:400
static WindowBuilder getBuilder()
Definition: Window.cpp:392
void setCursorVisibility(bool bIsVisible) const
Definition: Window.cpp:455
float getOpacity() const
Definition: Window.cpp:102
void onFramebufferSizeChanged(int iWidth, int iHeight) const
Definition: Window.cpp:141
void showErrorIfNotOnMainThread() const
Definition: Window.cpp:292
void onWindowFocusChanged(bool bIsFocused) const
Definition: Window.cpp:137
std::string sWindowTitle
Definition: Window.h:593
void onMouseScrollMove(int iOffset) const
Definition: Window.cpp:135
static std::variant< std::unique_ptr< Window >, Error > create(WindowBuilderParameters ¶ms)
Definition: Window.cpp:305
std::optional< RendererType > preferredRenderer
Definition: Window.h:596
void processEvents()
Definition: Window.h:607
static void glfwWindowMouseCallback(GLFWwindow *pGlfwWindow, int iButton, int iAction, int iMods)
Definition: Window.cpp:161
void close() const
Definition: Window.cpp:70
void onKeyboardInput(KeyboardKey key, KeyboardModifiers modifiers, bool bIsPressedDown) const
Definition: Window.cpp:118
static void glfwWindowMouseCursorPosCallback(GLFWwindow *pGlfwWindow, double xPos, double yPos)
Definition: Window.cpp:180
std::thread::id mainThreadId
Definition: Window.h:590
void minimize() const
Definition: Window.cpp:471
static void glfwFramebufferResizeCallback(GLFWwindow *pGlfwWindow, int iWidth, int iHeight)
Definition: Window.cpp:198
void onMouseInput(MouseButton button, KeyboardModifiers modifiers, bool bIsPressedDown) const
Definition: Window.cpp:122
GLFWwindow * pGlfwWindow
Definition: Window.h:584
static void glfwWindowKeyboardCallback(GLFWwindow *pGlfwWindow, int iKey, int iScancode, int iAction, int iMods)
Definition: Window.cpp:146
void setTitle(const std::string &sNewTitle)
Definition: Window.cpp:402
void maximize() const
Definition: Window.cpp:476
double lastMouseYPos
Definition: Window.h:602
std::optional< Error > setIcon(const std::filesystem::path &pathToIcon) const
Definition: Window.cpp:407
bool bShowWindow
Definition: Window.h:94
std::filesystem::path pathToWindowIcon
Definition: Window.h:92
int iWindowWidth
Definition: Window.h:86
bool bIsSplashScreen
Definition: Window.h:100
std::string_view sWindowTitle
Definition: Window.h:90
int iWindowHeight
Definition: Window.h:88
bool bMaximized
Definition: Window.h:96
bool bFullscreen
Definition: Window.h:98