Pixels, Surfaces, Renderer, oh my...
This commit is contained in:
@@ -1,62 +1,35 @@
|
||||
#pragma once
|
||||
/**
|
||||
* @file Window.hpp
|
||||
* @brief HDK sdl video header only wrapper for SDL_Window struct & related functions
|
||||
*/
|
||||
/// @file Window.hpp
|
||||
/// For complete documentation, see src/video/Window.cpp
|
||||
#include <SDL3/SDL.h>
|
||||
#include <hdk/grid/SharedPtrWrapper.hpp>
|
||||
#include <hdk/sdl/Properties.hpp>
|
||||
/** Windows are the primary interface for rendering and interacting with the user in SDL */
|
||||
namespace hdk::sdl {
|
||||
class Renderer;
|
||||
namespace evt {
|
||||
class EventConduit;
|
||||
}
|
||||
class Window : public hdk::grid::SharedPtrWrapper<SDL_Window> {
|
||||
public:
|
||||
friend class Renderer;
|
||||
friend class evt::EventConduit;
|
||||
friend std::pair<Window, Renderer> CreateWindowAndRenderer(const char* title, int width, int height, SDL_WindowFlags window_flags);
|
||||
/** Inherit constructors from SharedPtrWrapper */
|
||||
using hdk::grid::SharedPtrWrapper<SDL_Window>::SharedPtrWrapper;
|
||||
/**
|
||||
* https://wiki.libsdl.org/SDL3/SDL_CreateWindow
|
||||
* https://wiki.libsdl.org/SDL3/SDL_DestroyWindowSurface
|
||||
*
|
||||
* @param title The title of the window
|
||||
* @param w The width of the window in pixels.
|
||||
* @param h The height of the window in pixels.
|
||||
* @param flags 0, or one or more SDL_WindowFlags OR'd together.
|
||||
* @return A Window instance that manages the created SDL_Window. If window creation fails, the returned Window
|
||||
* will evaluate to false (i.e., it will be null).
|
||||
*/
|
||||
using hdk::grid::SharedPtrWrapper<SDL_Window>::get_or_cache;
|
||||
using hdk::grid::SharedPtrWrapper<SDL_Window>::get_or_view;
|
||||
static Window Create(const char* title, int w, int h, SDL_WindowFlags flags) {
|
||||
return Window(get_or_cache(SDL_CreateWindow(title, w, h, flags), SDL_DestroyWindow));
|
||||
}
|
||||
/** @see SDL_CreateWindowWithProperties
|
||||
* https://wiki.libsdl.org/SDL3/SDL_CreateWindowWithProperties
|
||||
* @brief Create a window with properties.
|
||||
* @param propertiesID The ID of the properties set to use for the window.
|
||||
* @return Window The created window. If the creation fails, returns an invalid window.
|
||||
*/
|
||||
static Window CreateWithProperties(
|
||||
SDL_PropertiesID propertiesID) {
|
||||
return Window(
|
||||
get_or_cache(SDL_CreateWindowWithProperties(propertiesID), SDL_DestroyWindow));
|
||||
}
|
||||
/**
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowFromID
|
||||
* @brief Get window for WindowID
|
||||
* @param id The ID of the window.
|
||||
* @return A Window instance that wraps the SDL_Window. If no window with the given ID exists, the returned Window
|
||||
* will evaluate to false (i.e., it will be null).
|
||||
*/
|
||||
static Window GetFromID(SDL_WindowID id) {
|
||||
/** Because it is possible windows were created by other means, we use get_or_view to wrap the SDL_Window
|
||||
* without taking ownership */
|
||||
return Window(get_or_view(SDL_GetWindowFromID(id)));
|
||||
}
|
||||
/**
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetGrabbedWindow
|
||||
* @brief Get the currently grabbed window, if any.
|
||||
* @return A Window instance that wraps the currently grabbed SDL_Window. If no window is
|
||||
*/
|
||||
static Window GetGrabbed() {
|
||||
/** Because it is possible windows were created by other means, we use get_or_view to wrap the SDL_Window
|
||||
* without taking ownership */
|
||||
@@ -64,138 +37,29 @@ namespace hdk::sdl {
|
||||
}
|
||||
|
||||
public: // Instance Properties
|
||||
/**
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowAspectRatio
|
||||
* @brief Get the aspect ratio of the window.
|
||||
* @param min_aspect_ratio A pointer to a float that will be filled with the minimum aspect ratio of the window.
|
||||
* @param max_aspect_ratio A pointer to a float that will be filled with the
|
||||
* @return bool True if the aspect ratio was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetAspectRatio(float* min_aspect_ratio, float* max_aspect_ratio) const {
|
||||
return SDL_GetWindowAspectRatio(*this, min_aspect_ratio, max_aspect_ratio);
|
||||
}
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowBordersSize
|
||||
* @brief Get the size of the window borders.
|
||||
* @param top A pointer to an int that will be filled with the size of the top border of the window.
|
||||
* @param left A pointer to an int that will be filled with the size of the left border of the window.
|
||||
* @param bottom A pointer to an int that will be filled with the size of the bottom border of the window.
|
||||
* @param right A pointer to an int that will be filled with the size of the right border of the window.
|
||||
* @return bool True if the border sizes were successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetBordersSize(int* top, int* left, int* bottom, int* right) const {
|
||||
return SDL_GetWindowBordersSize(*this, top, left, bottom, right);
|
||||
}
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowDisplayScale
|
||||
* @brief Get the display scale of the window.
|
||||
* @return float The display scale of the window. If the window is invalid, returns 0.0f.
|
||||
*/
|
||||
float GetDisplayScale() const { return SDL_GetWindowDisplayScale(*this); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowFlags
|
||||
* @brief Get the flags of the window.
|
||||
* @return SDL_WindowFlags The flags of the window. If the window is invalid, returns 0.
|
||||
*/
|
||||
SDL_WindowFlags GetFlags() const { return SDL_GetWindowFlags(*this); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowFullscreenMode
|
||||
* @brief Get the fullscreen mode of the window.
|
||||
* @return const SDL_DisplayMode* A pointer to an SDL_DisplayMode structure that will be filled with the
|
||||
* fullscreen mode of the window. If the window is not in fullscreen mode or is invalid, returns nullptr.
|
||||
*/
|
||||
const SDL_DisplayMode* GetFullscreenMode() const { return SDL_GetWindowFullscreenMode(*this); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowID
|
||||
* @brief Get the ID of the window.
|
||||
* @return SDL_WindowID The ID of the window. If the window is invalid, returns 0.
|
||||
*/
|
||||
SDL_WindowID GetID() const { return SDL_GetWindowID(*this); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowKeyboardGrab
|
||||
* @brief Get the keyboard grab state of the window.
|
||||
* @return SDL_bool True if the window has grabbed the keyboard, false otherwise.
|
||||
*/
|
||||
bool GetKeyboardGrab() const { return SDL_GetWindowKeyboardGrab(*this); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_SetWindowKeyboardGrab
|
||||
* @brief Set the keyboard grab state of the window.
|
||||
* @param grabbed True to grab the keyboard, false to release it.
|
||||
* @return bool True if the keyboard grab state was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetKeyboardGrab(bool grabbed) const { return SDL_SetWindowKeyboardGrab(*this, grabbed); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowMouseGrab
|
||||
* @brief Get the mouse grab state of the window.
|
||||
* @return SDL_bool True if the window has grabbed the mouse, false otherwise.
|
||||
*/
|
||||
bool GetMouseGrab() const { return SDL_GetWindowMouseGrab(*this); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_SetWindowMouseGrab
|
||||
* @brief Set the mouse grab state of the window.
|
||||
* @param grabbed True to grab the mouse, false to release it.
|
||||
* @return bool True if the mouse grab state was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetMouseGrab(bool grabbed) const { return SDL_SetWindowMouseGrab(*this, grabbed); }
|
||||
/** SDL_GetWindowMouseRect
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowMouseRect
|
||||
* @brief Get the mouse rectangle of the window.
|
||||
* @return const SDL_Rect* A pointer to an SDL_Rect structure that will be filled with the mouse rectangle of the
|
||||
* window. If the window is invalid, returns nullptr.
|
||||
*/
|
||||
const SDL_Rect* GetMouseRect() const { return SDL_GetWindowMouseRect(*this); }
|
||||
/** @see SDL_SetWindowMouseRect
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetWindowMouseRect
|
||||
* @brief Set the mouse rectangle of the window.
|
||||
* @param rect A pointer to an SDL_Rect structure that defines the mouse rectangle of the window.
|
||||
* @return bool True if the mouse rectangle was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetMouseRect(const SDL_Rect* rect) const { return SDL_SetWindowMouseRect(*this, rect); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowMaximumSize
|
||||
* @brief Get the maximum size of the window.
|
||||
* @param w A pointer to an int that will be filled with the maximum width of the window.
|
||||
* @param h A pointer to an int that will be filled with the maximum height of the window.
|
||||
* @return bool True if the maximum size was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetMaximumSize(int* w, int* h) const { return SDL_GetWindowMaximumSize(*this, w, h); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_SetWindowMaximumSize
|
||||
* @brief Set the maximum size of the window.
|
||||
* @param w The maximum width of the window in pixels.
|
||||
* @param h The maximum height of the window in pixels.
|
||||
* @return bool True if the maximum size was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetMaximumSize(int w, int h) const { return SDL_SetWindowMaximumSize(*this, w, h); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowMinimumSize
|
||||
* @brief Get the minimum size of the window.
|
||||
* @param w A pointer to an int that will be filled with the minimum width of the window.
|
||||
* @param h A pointer to an int that will be filled with the minimum height of the window.
|
||||
* @return bool True if the minimum size was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetMinimumSize(int* w, int* h) const { return SDL_GetWindowMinimumSize(*this, w, h); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_SetWindowMinimumSize
|
||||
* @brief Set the minimum size of the window.
|
||||
* @param w The minimum width of the window in pixels.
|
||||
* @param h The minimum height of the window in pixels.
|
||||
* @return bool True if the minimum size was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetMinimumSize(int w, int h) const { return SDL_SetWindowMinimumSize(*this, w, h); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_SetWindowSize
|
||||
* @brief Set the size of the window.
|
||||
* @param w The width of the window in pixels.
|
||||
* @param h The height of the window in pixels.
|
||||
* @return bool True if the size was successfully set, false otherwise.
|
||||
*/
|
||||
bool SetSize(int w, int h) const { return SDL_SetWindowSize(*this, w, h); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowSize
|
||||
* @brief Get the size of the window.
|
||||
* @param w A pointer to an int that will be filled with the width of the window.
|
||||
* @param h A pointer to an int that will be filled with the height of the window.
|
||||
* @return bool True if the size was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetSize(int* w, int* h) const { return SDL_GetWindowSize(*this, w, h); }
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetWindowSafeArea
|
||||
* @brief Get the safe area of the window.
|
||||
* @param rect A pointer to an SDL_Rect structure that will be filled with the safe area of the window. If the
|
||||
* window is invalid, the rect will be set to {0, 0, 0, 0}.
|
||||
* @return bool True if the safe area was successfully retrieved, false otherwise.
|
||||
*/
|
||||
bool GetSafeArea(SDL_Rect* rect) const { return SDL_GetWindowSafeArea(*this, rect); }
|
||||
/** @see SDL_GetWindowOpacity
|
||||
* https://wiki.libsdl.org/SDL3/SDL_GetWindowOpacity
|
||||
* @brief Get the opacity of the window.
|
||||
* @return float The opacity of the window. If the window is invalid, returns 0.0f.
|
||||
*/
|
||||
float GetOpacity() const { return SDL_GetWindowOpacity(*this); }
|
||||
/** @see SDL_SetWindowOpacity
|
||||
* https://wiki.libsdl.org/SDL3/SDL_SetWindowOpacity
|
||||
|
||||
Reference in New Issue
Block a user