#include <Window.h>
|
static void | glfwWindowKeyboardCallback (GLFWwindow *pGlfwWindow, int iKey, int iScancode, int iAction, int iMods) |
|
static void | glfwWindowMouseCallback (GLFWwindow *pGlfwWindow, int iButton, int iAction, int iMods) |
|
static void | glfwWindowFocusCallback (GLFWwindow *pGlfwWindow, int iFocused) |
|
static void | glfwWindowMouseCursorPosCallback (GLFWwindow *pGlfwWindow, double xPos, double yPos) |
|
static void | glfwWindowMouseScrollCallback (GLFWwindow *pGlfwWindow, double xOffset, double yOffset) |
|
static void | glfwFramebufferResizeCallback (GLFWwindow *pGlfwWindow, int iWidth, int iHeight) |
|
static std::variant< std::unique_ptr< Window >, Error > | create (WindowBuilderParameters ¶ms) |
|
◆ Window()
ne::Window::Window |
( |
GLFWwindow * |
pGlfwWindow, |
|
|
const std::string & |
sWindowTitle |
|
) |
| |
|
private |
Default constructor.
- Parameters
-
pGlfwWindow | Created GLFW window. |
sWindowTitle | Title of this window. |
◆ bindToWindowEvents()
void ne::Window::bindToWindowEvents |
( |
| ) |
|
|
private |
Binds to various window events such as user input events.
◆ close()
void ne::Window::close |
( |
| ) |
const |
Closes this window causing game instance, audio engine and etc to be destroyed.
◆ create()
Creates a new window.
- Parameters
-
params | Parameters that define initial window state. |
- Returns
- Returns error if something went wrong or created window otherwise.
◆ createCursor()
std::variant< WindowCursor *, Error > ne::Window::createCursor |
( |
const std::filesystem::path & |
pathToIcon | ) |
|
Loads the image and creates a new cursor, note that in order for this new cursor to be visible you have to call setCursor.
- Warning
- This function must only be called from the main thread. If this function is called outside of the main thread an error will be shown.
- Parameters
-
pathToIcon | Path to the image (.png). The image data should be 32-bit, little-endian, non-premultiplied RGBA, i.e. eight bits per channel with the red channel first. |
- Returns
- Error if something went wrong, otherwise a non-owning pointer to the created cursor that is managed by the window. Do not delete returned pointer, the window owns this cursor and will automatically delete it when the window is closed.
◆ getBuilder()
Returns a builder for a new window. Use can use this static function to receive a WindowBuilder or create an instance of WindowBuilder manually.
- Returns
- Builder for a new window.
◆ getCursorPosition()
std::pair< double, double > ne::Window::getCursorPosition |
( |
| ) |
const |
Returns the current cursor position on window.
- Warning
- This function must only be called from the main thread. If this function is called outside of the main thread an error will be shown.
- Returns
- A pair of X and Y coordinates in range [0.0; 1.0] relative to the upper-left corner of the window.
◆ getGlfwWindow()
GLFWwindow * ne::Window::getGlfwWindow |
( |
| ) |
const |
Returns internal GLFW window pointer.
- Returns
- GLFW window.
◆ getOpacity()
float ne::Window::getOpacity |
( |
| ) |
const |
Returns window opacity.
- Returns
- Window opacity.
◆ getRenderer()
Renderer * ne::Window::getRenderer |
( |
| ) |
const |
Returns renderer used for this window.
- Returns
- nullptr if renderer was not created yet, valid pointer otherwise.
◆ getSize()
std::pair< int, int > ne::Window::getSize |
( |
| ) |
const |
Returns the current window size in pixels.
- Warning
- This function must only be called from the main thread. If this function is called outside of the main thread an error will be shown.
- Returns
- A pair of width and height in pixels.
◆ getTitle()
std::string ne::Window::getTitle |
( |
| ) |
const |
Returns the title of this window.
- Returns
- Title of the window.
◆ glfwFramebufferResizeCallback()
void ne::Window::glfwFramebufferResizeCallback |
( |
GLFWwindow * |
pGlfwWindow, |
|
|
int |
iWidth, |
|
|
int |
iHeight |
|
) |
| |
|
staticprivate |
GLFW callback.
- Parameters
-
pGlfwWindow | Window. |
iWidth | New width of the framebuffer (in pixels). |
iHeight | New height of the framebuffer (in pixels). |
◆ glfwWindowFocusCallback()
void ne::Window::glfwWindowFocusCallback |
( |
GLFWwindow * |
pGlfwWindow, |
|
|
int |
iFocused |
|
) |
| |
|
staticprivate |
GLFW callback.
- Parameters
-
pGlfwWindow | The window that received the event. |
iFocused | GLFW_TRUE if the window was given input focus, or GLFW_FALSE if it lost it. |
◆ glfwWindowKeyboardCallback()
void ne::Window::glfwWindowKeyboardCallback |
( |
GLFWwindow * |
pGlfwWindow, |
|
|
int |
iKey, |
|
|
int |
iScancode, |
|
|
int |
iAction, |
|
|
int |
iMods |
|
) |
| |
|
staticprivate |
GLFW callback.
- Parameters
-
pGlfwWindow | The window that received the event. |
iKey | The keyboard key that was pressed or released. |
iScancode | The system-specific scancode of the key. |
iAction | GLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT. |
iMods | Bit field describing which modifier keys were held down. |
◆ glfwWindowMouseCallback()
void ne::Window::glfwWindowMouseCallback |
( |
GLFWwindow * |
pGlfwWindow, |
|
|
int |
iButton, |
|
|
int |
iAction, |
|
|
int |
iMods |
|
) |
| |
|
staticprivate |
GLFW callback.
- Parameters
-
pGlfwWindow | The window that received the event. |
iButton | The mouse button that was pressed or released. |
iAction | One of GLFW_PRESS or GLFW_RELEASE. |
iMods | Bit field describing which modifier keys were held down. |
◆ glfwWindowMouseCursorPosCallback()
void ne::Window::glfwWindowMouseCursorPosCallback |
( |
GLFWwindow * |
pGlfwWindow, |
|
|
double |
xPos, |
|
|
double |
yPos |
|
) |
| |
|
staticprivate |
GLFW callback.
- Parameters
-
pGlfwWindow | The window that received the event. |
xPos | The new x-coordinate, in screen coordinates, of the cursor. |
yPos | The new y-coordinate, in screen coordinates, of the cursor. |
◆ glfwWindowMouseScrollCallback()
void ne::Window::glfwWindowMouseScrollCallback |
( |
GLFWwindow * |
pGlfwWindow, |
|
|
double |
xOffset, |
|
|
double |
yOffset |
|
) |
| |
|
staticprivate |
GLFW callback.
- Parameters
-
pGlfwWindow | The window that received the event. |
xOffset | The scroll offset along the x-axis. |
yOffset | The scroll offset along the y-axis. |
◆ hide()
void ne::Window::hide |
( |
| ) |
const |
Hides the windows (makes it invisible). Does nothing for fullscreen windows.
- Warning
- This function must only be called from the main thread. If this function is called outside of the main thread an error will be shown.
◆ maximize()
void ne::Window::maximize |
( |
| ) |
const |
Maximizes the window.
- Warning
- This function must only be called from the main thread. If this function is called outside of the main thread an error will be shown.
◆ minimize()
void ne::Window::minimize |
( |
| ) |
const |
Minimizes the window.
- Warning
- This function must only be called from the main thread. If this function is called outside of the main thread an error will be shown.
◆ onFramebufferSizeChanged()
void ne::Window::onFramebufferSizeChanged |
( |
int |
iWidth, |
|
|
int |
iHeight |
|
) |
| const |
|
private |
Called when the framebuffer size was changed.
- Parameters
-
iWidth | New width of the framebuffer (in pixels). |
iHeight | New height of the framebuffer (in pixels). |
◆ onKeyboardInput()
void ne::Window::onKeyboardInput |
( |
KeyboardKey |
key, |
|
|
KeyboardModifiers |
modifiers, |
|
|
bool |
bIsPressedDown |
|
) |
| const |
Called when the window receives keyboard input.
- Parameters
-
key | Keyboard key. |
modifiers | Keyboard modifier keys. |
bIsPressedDown | Whether the key down event occurred or key up. |
◆ onMouseInput()
void ne::Window::onMouseInput |
( |
MouseButton |
button, |
|
|
KeyboardModifiers |
modifiers, |
|
|
bool |
bIsPressedDown |
|
) |
| const |
Called when the window receives mouse input.
- Parameters
-
button | Mouse button. |
modifiers | Keyboard modifier keys. |
bIsPressedDown | Whether the button down event occurred or button up. |
◆ onMouseMove()
void ne::Window::onMouseMove |
( |
double |
xPos, |
|
|
double |
yPos |
|
) |
| |
|
private |
Called when the window receives mouse movement.
- Parameters
-
xPos | Mouse X position in pixels. |
yPos | Mouse Y position in pixels. |
◆ onMouseScrollMove()
void ne::Window::onMouseScrollMove |
( |
int |
iOffset | ) |
const |
Called when the window receives mouse scroll movement.
- Parameters
-
◆ onWindowFocusChanged()
void ne::Window::onWindowFocusChanged |
( |
bool |
bIsFocused | ) |
const |
|
private |
Called when the window focus was changed.
- Parameters
-
bIsFocused | Whether the window has gained or lost the focus. |
◆ processEvents()
template<typename MyGameInstance >
requires std::derived_from<MyGameInstance,
GameInstance>
void ne::Window::processEvents |
Starts the message queue, rendering and game logic. Set GameInstance derived class to react to user inputs, window events and etc.
Will return control after the window was closed.
◆ restore()
void ne::Window::restore |
( |
| ) |
const |
Restores the window (makes it visible with normal size). Does nothing for fullscreen windows.
- Warning
- This function must only be called from the main thread. If this function is called outside of the main thread an error will be shown.
◆ setCursor()
Changes the cursor.
Use createCursor to create a new cursor.
- Warning
- This function must only be called from the main thread. If this function is called outside of the main thread an error will be shown.
- Parameters
-
◆ setCursorVisibility()
void ne::Window::setCursorVisibility |
( |
bool |
bIsVisible | ) |
const |
Whether the cursor is visible or not (locked in this window).
- Parameters
-
bIsVisible | 'true' shows cursor (normal behavior), 'false' will hide the cursor and lock it to the window. |
◆ setDefaultCursor()
void ne::Window::setDefaultCursor |
( |
| ) |
|
Changes the cursor icon to be system default cursor icon.
This function can be used to revert changes made by setCursor function.
◆ setIcon()
std::optional< Error > ne::Window::setIcon |
( |
const std::filesystem::path & |
pathToIcon | ) |
const |
Sets new window icon.
- Warning
- This function must only be called from the main thread. If this function is called outside of the main thread an error will be shown.
- Parameters
-
pathToIcon | Path to the image (.png). The image data should be 32-bit, little-endian, non-premultiplied RGBA, i.e. eight bits per channel with the red channel first. |
- Returns
- Error if file not found.
◆ setOpacity()
void ne::Window::setOpacity |
( |
float |
opacity | ) |
const |
Sets the window opacity (1.0f for opaque, 0.0f for transparent). Does nothing if the OS does not support transparent windows.
- Parameters
-
opacity | Opacity value between 0.0 and 1.0. |
◆ setPreferredRenderer()
void ne::Window::setPreferredRenderer |
( |
const std::optional< RendererType > & |
preferredRenderer | ) |
|
Saves the type of the preferred renderer to use for the next game created using this window (when processEvents is called).
- Parameters
-
preferredRenderer | Renderer that should be preferred to be used although there is no guarantee that it will actually be used because of OS/hardware support. The specified renderer will be the first one to test OS/hardware support. Specify empty value to clear your previously specified preference. |
◆ setTitle()
void ne::Window::setTitle |
( |
const std::string & |
sNewTitle | ) |
|
Sets new window title.
- Parameters
-
sNewTitle | New window title. |
◆ show()
void ne::Window::show |
( |
| ) |
const |
Shows the hidden window on screen.
- Warning
- This function must only be called from the main thread. If this function is called outside of the main thread an error will be shown.
◆ showErrorIfNotOnMainThread()
void ne::Window::showErrorIfNotOnMainThread |
( |
| ) |
const |
|
private |
Checks whether the current thread is the main thread or not and if not shows an error.
◆ unbindFromWindowEvents()
void ne::Window::unbindFromWindowEvents |
( |
| ) |
|
|
private |
◆ lastMouseXPos
double ne::Window::lastMouseXPos = 0.0 |
|
private |
Last mouse X position, used for calculating delta movement.
◆ lastMouseYPos
double ne::Window::lastMouseYPos = 0.0 |
|
private |
Last mouse Y position, used for calculating delta movement.
◆ mainThreadId
std::thread::id ne::Window::mainThreadId |
|
private |
◆ pGameManager
◆ pGlfwWindow
GLFWwindow* ne::Window::pGlfwWindow = nullptr |
|
private |
◆ preferredRenderer
std::optional<RendererType> ne::Window::preferredRenderer |
|
private |
Renderer that the developer wants to use.
◆ sWindowTitle
std::string ne::Window::sWindowTitle |
|
private |
◆ vCreatedCursors
std::vector<std::unique_ptr<WindowCursor> > ne::Window::vCreatedCursors |
|
private |
Array of created cursors using createCursor. Should be used with the mutex.
The documentation for this class was generated from the following files:
- src/engine_lib/public/game/Window.h
- src/engine_lib/private/window/Window.cpp