raylib-cpp
C++ object-oriented wrapper library for raylib.
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
raylib::Window Class Reference

Window and Graphics Device Functions. More...

#include <Window.hpp>

Public Member Functions

 Window ()=default
 Build a Window object, but defer the initialization. More...
 
 Window (int width, int height, const std::string_view title="raylib", unsigned int flags=0)
 Initialize window and OpenGL context. More...
 
 ~Window ()
 Close window and unload OpenGL context. More...
 
WindowBeginDrawing ()
 Setup canvas (framebuffer) to start drawing. More...
 
WindowClearBackground (const ::Color &color=BLACK)
 Clear window with given color. More...
 
WindowClearState (unsigned int flag)
 Clear window configuration state flags. More...
 
bool Drawing ()
 Alternates between calling BeginDrawing() and EndDrawing(). More...
 
WindowEndDrawing ()
 End canvas drawing and swap buffers (double buffering) More...
 
void Init (int width=800, int height=450, const std::string_view title="raylib", unsigned int flags=0)
 Initializes the window. More...
 
WindowMaximize ()
 Set window state: maximized, if resizable (only PLATFORM_DESKTOP) More...
 
WindowMinimize ()
 Set window state: minimized, if resizable (only PLATFORM_DESKTOP) More...
 
WindowRestore ()
 Set window state: not minimized/maximized (only PLATFORM_DESKTOP) More...
 
void SetClipboardText (const std::string_view text)
 Set clipboard text content. More...
 
WindowSetFocused ()
 Set window focused (only PLATFORM_DESKTOP) More...
 
WindowSetFullscreen (bool fullscreen)
 Set whether or not the application should be fullscreen. More...
 
WindowSetIcon (const ::Image &image)
 Set icon for window. More...
 
WindowSetIcons (Image *images, int count)
 Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP) More...
 
WindowSetIcons (std::span< Image > images)
 Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP) More...
 
WindowSetMinSize (const ::Vector2 &size)
 Set window minimum dimensions. More...
 
WindowSetMinSize (int width, int height)
 Set window minimum dimensions. More...
 
WindowSetMonitor (int monitor)
 Set monitor for the current window. More...
 
WindowSetOpacity (float opacity)
 Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP) More...
 
WindowSetPosition (const ::Vector2 &position)
 Set window position on screen. More...
 
WindowSetPosition (int x, int y)
 Set window position on screen. More...
 
WindowSetSize (const ::Vector2 &size)
 Set window dimensions. More...
 
WindowSetSize (int width, int height)
 Set window dimensions. More...
 
WindowSetState (unsigned int flag)
 Set window configuration state using flags. More...
 
WindowSetTargetFPS (int fps)
 Set target FPS (maximum) More...
 
WindowSetTitle (const std::string_view title)
 Set title for window. More...
 
WindowToggleBorderless ()
 Toggle window state: borderless/windowed. More...
 
WindowToggleFullscreen ()
 Toggle window state: fullscreen/windowed. More...
 

Static Public Member Functions

static void Close ()
 Close window and unload OpenGL context. More...
 
static void DrawFPS (int posX=10, int posY=10)
 Draw current FPS. More...
 
static std::string GetClipboardText ()
 Get clipboard text content. More...
 
static int GetFPS ()
 Returns current FPS. More...
 
static float GetFrameTime ()
 Returns time in seconds for last frame drawn. More...
 
static void * GetHandle ()
 Get native window handle. More...
 
static int GetHeight ()
 Get current screen height. More...
 
static int GetMonitor ()
 
static Vector2 GetPosition ()
 Get window position XY on monitor. More...
 
static int GetRenderHeight ()
 Get current render height (it considers HiDPI) More...
 
static int GetRenderWidth ()
 Get current render width (it considers HiDPI) More...
 
static Vector2 GetScaleDPI ()
 Get window scale DPI factor. More...
 
static Vector2 GetSize ()
 Get the screen's width and height. More...
 
static double GetTime ()
 Returns elapsed time in seconds since InitWindow() More...
 
static int GetWidth ()
 Get current screen width. More...
 
static void HideCursor ()
 Hides cursor. More...
 
static bool IsCursorHidden ()
 Check if cursor is not visible. More...
 
static bool IsCursorOnScreen ()
 Check if cursor is on the current screen. More...
 
static bool IsFocused ()
 Check if window is currently focused. More...
 
static bool IsFullscreen ()
 Check if window is currently fullscreen. More...
 
static bool IsHidden ()
 Check if window is currently hidden. More...
 
static bool IsMaximized ()
 Check if window is currently minimized. More...
 
static bool IsMinimized ()
 Check if window is currently minimized. More...
 
static bool IsResized ()
 Check if window has been resized last frame. More...
 
static bool IsState (unsigned int flag)
 Check if one specific window flag is enabled. More...
 
static bool IsValid ()
 Check if window has been initialized successfully. More...
 
static void SetConfigFlags (unsigned int flags)
 Sets the configuration flags for raylib. More...
 
static void SetExitKey (int key)
 Set a custom key to exit program (default is ESC) More...
 
static bool ShouldClose ()
 Check if KEY_ESCAPE pressed or Close icon pressed. More...
 
static void ShowCursor ()
 Shows cursor. More...
 

Protected Attributes

bool m_drawing = false
 Handles the internal drawing state for calling either BeginDrawing() or EndDrawing() from the Drawing() function. More...
 

Detailed Description

Window and Graphics Device Functions.

Definition at line 16 of file Window.hpp.

Constructor & Destructor Documentation

◆ Window() [1/2]

raylib::Window::Window ( )
default

Build a Window object, but defer the initialization.

Ensure you call Init() manually.

See also
Init()

◆ Window() [2/2]

raylib::Window::Window ( int  width,
int  height,
const std::string_view  title = "raylib",
unsigned int  flags = 0 
)
inline

Initialize window and OpenGL context.

Parameters
widthThe width of the window.
heightThe height of the window.
titleThe desired title of the window.
flagsThe ConfigFlags to set prior to initializing the window. See SetConfigFlags for more details.
logLevelThe the current threshold (minimum) log level
See also
SetConfigFlags()
ConfigFlags
Exceptions
raylib::RaylibExceptionThrown if the window failed to initiate.

Definition at line 39 of file Window.hpp.

References Init().

◆ ~Window()

raylib::Window::~Window ( )
inline

Close window and unload OpenGL context.

Definition at line 46 of file Window.hpp.

References Close().

Member Function Documentation

◆ BeginDrawing()

Window & raylib::Window::BeginDrawing ( )
inline

Setup canvas (framebuffer) to start drawing.

Definition at line 340 of file Window.hpp.

References BeginDrawing().

Referenced by BeginDrawing(), and Drawing().

◆ ClearBackground()

Window & raylib::Window::ClearBackground ( const ::Color &  color = BLACK)
inline

Clear window with given color.

Definition at line 164 of file Window.hpp.

References ClearBackground().

Referenced by ClearBackground().

◆ ClearState()

Window & raylib::Window::ClearState ( unsigned int  flag)
inline

Clear window configuration state flags.

Definition at line 156 of file Window.hpp.

◆ Close()

static void raylib::Window::Close ( )
inlinestatic

Close window and unload OpenGL context.

Definition at line 84 of file Window.hpp.

Referenced by ~Window().

◆ DrawFPS()

static void raylib::Window::DrawFPS ( int  posX = 10,
int  posY = 10 
)
inlinestatic

Draw current FPS.

Definition at line 416 of file Window.hpp.

References DrawFPS().

Referenced by DrawFPS().

◆ Drawing()

bool raylib::Window::Drawing ( )
inline

Alternates between calling BeginDrawing() and EndDrawing().

while (window.Drawing()) {
DrawRectangle();
}
Returns
True if we're within the BeginDrawing() scope.

Definition at line 453 of file Window.hpp.

References BeginDrawing(), EndDrawing(), and m_drawing.

◆ EndDrawing()

Window & raylib::Window::EndDrawing ( )
inline

End canvas drawing and swap buffers (double buffering)

Definition at line 348 of file Window.hpp.

References EndDrawing().

Referenced by Drawing(), and EndDrawing().

◆ GetClipboardText()

static std::string raylib::Window::GetClipboardText ( )
inlinestatic

Get clipboard text content.

Definition at line 398 of file Window.hpp.

◆ GetFPS()

static int raylib::Window::GetFPS ( )
inlinestatic

Returns current FPS.

Definition at line 411 of file Window.hpp.

◆ GetFrameTime()

static float raylib::Window::GetFrameTime ( )
inlinestatic

Returns time in seconds for last frame drawn.

Definition at line 421 of file Window.hpp.

◆ GetHandle()

static void * raylib::Window::GetHandle ( )
inlinestatic

Get native window handle.

Definition at line 335 of file Window.hpp.

◆ GetHeight()

static int raylib::Window::GetHeight ( )
inlinestatic

Get current screen height.

Definition at line 361 of file Window.hpp.

Referenced by GetSize().

◆ GetMonitor()

static int raylib::Window::GetMonitor ( )
inlinestatic

Definition at line 381 of file Window.hpp.

◆ GetPosition()

static Vector2 raylib::Window::GetPosition ( )
inlinestatic

Get window position XY on monitor.

Definition at line 376 of file Window.hpp.

◆ GetRenderHeight()

static int raylib::Window::GetRenderHeight ( )
inlinestatic

Get current render height (it considers HiDPI)

Definition at line 371 of file Window.hpp.

◆ GetRenderWidth()

static int raylib::Window::GetRenderWidth ( )
inlinestatic

Get current render width (it considers HiDPI)

Definition at line 366 of file Window.hpp.

◆ GetScaleDPI()

static Vector2 raylib::Window::GetScaleDPI ( )
inlinestatic

Get window scale DPI factor.

Definition at line 386 of file Window.hpp.

◆ GetSize()

static Vector2 raylib::Window::GetSize ( )
inlinestatic

Get the screen's width and height.

Definition at line 330 of file Window.hpp.

References GetHeight(), and GetWidth().

◆ GetTime()

static double raylib::Window::GetTime ( )
inlinestatic

Returns elapsed time in seconds since InitWindow()

Definition at line 426 of file Window.hpp.

◆ GetWidth()

static int raylib::Window::GetWidth ( )
inlinestatic

Get current screen width.

Definition at line 356 of file Window.hpp.

Referenced by GetSize().

◆ HideCursor()

static void raylib::Window::HideCursor ( )
inlinestatic

Hides cursor.

Definition at line 103 of file Window.hpp.

References HideCursor().

Referenced by HideCursor().

◆ Init()

void raylib::Window::Init ( int  width = 800,
int  height = 450,
const std::string_view  title = "raylib",
unsigned int  flags = 0 
)
inline

Initializes the window.

Parameters
widthThe width of the window.
heightThe height of the window.
titleThe desired title of the window.
flagsThe ConfigFlags to set prior to initializing the window. See SetConfigFlags for more details.
See also
SetConfigFlags()
ConfigFlags
Exceptions
raylib::RaylibExceptionThrown if the window failed to initiate.

Definition at line 61 of file Window.hpp.

References raylib::InitWindow(), and SetConfigFlags().

Referenced by Window().

◆ IsCursorHidden()

static bool raylib::Window::IsCursorHidden ( )
inlinestatic

Check if cursor is not visible.

Definition at line 98 of file Window.hpp.

◆ IsCursorOnScreen()

static bool raylib::Window::IsCursorOnScreen ( )
inlinestatic

Check if cursor is on the current screen.

Definition at line 93 of file Window.hpp.

◆ IsFocused()

static bool raylib::Window::IsFocused ( )
inlinestatic

Check if window is currently focused.

Definition at line 133 of file Window.hpp.

◆ IsFullscreen()

static bool raylib::Window::IsFullscreen ( )
inlinestatic

Check if window is currently fullscreen.

Definition at line 113 of file Window.hpp.

Referenced by SetFullscreen().

◆ IsHidden()

static bool raylib::Window::IsHidden ( )
inlinestatic

Check if window is currently hidden.

Definition at line 118 of file Window.hpp.

◆ IsMaximized()

static bool raylib::Window::IsMaximized ( )
inlinestatic

Check if window is currently minimized.

Definition at line 128 of file Window.hpp.

◆ IsMinimized()

static bool raylib::Window::IsMinimized ( )
inlinestatic

Check if window is currently minimized.

Definition at line 123 of file Window.hpp.

◆ IsResized()

static bool raylib::Window::IsResized ( )
inlinestatic

Check if window has been resized last frame.

Definition at line 138 of file Window.hpp.

◆ IsState()

static bool raylib::Window::IsState ( unsigned int  flag)
inlinestatic

Check if one specific window flag is enabled.

Definition at line 143 of file Window.hpp.

◆ IsValid()

static bool raylib::Window::IsValid ( )
inlinestatic

Check if window has been initialized successfully.

Definition at line 431 of file Window.hpp.

◆ Maximize()

Window & raylib::Window::Maximize ( )
inline

Set window state: maximized, if resizable (only PLATFORM_DESKTOP)

Definition at line 206 of file Window.hpp.

◆ Minimize()

Window & raylib::Window::Minimize ( )
inline

Set window state: minimized, if resizable (only PLATFORM_DESKTOP)

Definition at line 214 of file Window.hpp.

◆ Restore()

Window & raylib::Window::Restore ( )
inline

Set window state: not minimized/maximized (only PLATFORM_DESKTOP)

Definition at line 222 of file Window.hpp.

◆ SetClipboardText()

void raylib::Window::SetClipboardText ( const std::string_view  text)
inline

Set clipboard text content.

Definition at line 391 of file Window.hpp.

References SetClipboardText().

Referenced by SetClipboardText().

◆ SetConfigFlags()

static void raylib::Window::SetConfigFlags ( unsigned int  flags)
inlinestatic

Sets the configuration flags for raylib.

Parameters
flagsThe ConfigFlags to apply to the configuration.
See also
SetConfigFlags

Definition at line 440 of file Window.hpp.

References SetConfigFlags().

Referenced by Init(), and SetConfigFlags().

◆ SetExitKey()

static void raylib::Window::SetExitKey ( int  key)
inlinestatic

Set a custom key to exit program (default is ESC)

Definition at line 79 of file Window.hpp.

References SetExitKey().

Referenced by SetExitKey().

◆ SetFocused()

Window & raylib::Window::SetFocused ( )
inline

Set window focused (only PLATFORM_DESKTOP)

Definition at line 317 of file Window.hpp.

◆ SetFullscreen()

Window & raylib::Window::SetFullscreen ( bool  fullscreen)
inline

Set whether or not the application should be fullscreen.

Definition at line 180 of file Window.hpp.

References IsFullscreen(), and ToggleFullscreen().

◆ SetIcon()

Window & raylib::Window::SetIcon ( const ::Image &  image)
inline

Set icon for window.

Definition at line 230 of file Window.hpp.

◆ SetIcons() [1/2]

Window & raylib::Window::SetIcons ( Image images,
int  count 
)
inline

Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP)

Definition at line 238 of file Window.hpp.

◆ SetIcons() [2/2]

Window & raylib::Window::SetIcons ( std::span< Image images)
inline

Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP)

Definition at line 246 of file Window.hpp.

◆ SetMinSize() [1/2]

Window & raylib::Window::SetMinSize ( const ::Vector2 &  size)
inline

Set window minimum dimensions.

Definition at line 293 of file Window.hpp.

◆ SetMinSize() [2/2]

Window & raylib::Window::SetMinSize ( int  width,
int  height 
)
inline

Set window minimum dimensions.

Definition at line 285 of file Window.hpp.

◆ SetMonitor()

Window & raylib::Window::SetMonitor ( int  monitor)
inline

Set monitor for the current window.

Definition at line 277 of file Window.hpp.

◆ SetOpacity()

Window & raylib::Window::SetOpacity ( float  opacity)
inline

Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP)

Definition at line 309 of file Window.hpp.

◆ SetPosition() [1/2]

Window & raylib::Window::SetPosition ( const ::Vector2 &  position)
inline

Set window position on screen.

Definition at line 270 of file Window.hpp.

References SetPosition().

◆ SetPosition() [2/2]

Window & raylib::Window::SetPosition ( int  x,
int  y 
)
inline

Set window position on screen.

Definition at line 262 of file Window.hpp.

Referenced by SetPosition().

◆ SetSize() [1/2]

Window & raylib::Window::SetSize ( const ::Vector2 &  size)
inline

Set window dimensions.

Definition at line 325 of file Window.hpp.

References SetSize().

Referenced by SetSize().

◆ SetSize() [2/2]

Window & raylib::Window::SetSize ( int  width,
int  height 
)
inline

Set window dimensions.

Definition at line 301 of file Window.hpp.

◆ SetState()

Window & raylib::Window::SetState ( unsigned int  flag)
inline

Set window configuration state using flags.

Definition at line 148 of file Window.hpp.

◆ SetTargetFPS()

Window & raylib::Window::SetTargetFPS ( int  fps)
inline

Set target FPS (maximum)

Definition at line 403 of file Window.hpp.

References SetTargetFPS().

Referenced by SetTargetFPS().

◆ SetTitle()

Window & raylib::Window::SetTitle ( const std::string_view  title)
inline

Set title for window.

Definition at line 254 of file Window.hpp.

References raylib::SetWindowTitle().

◆ ShouldClose()

static bool raylib::Window::ShouldClose ( )
inlinestatic

Check if KEY_ESCAPE pressed or Close icon pressed.

Definition at line 74 of file Window.hpp.

◆ ShowCursor()

static void raylib::Window::ShowCursor ( )
inlinestatic

Shows cursor.

Definition at line 108 of file Window.hpp.

References ShowCursor().

Referenced by ShowCursor().

◆ ToggleBorderless()

Window & raylib::Window::ToggleBorderless ( )
inline

Toggle window state: borderless/windowed.

Definition at line 198 of file Window.hpp.

◆ ToggleFullscreen()

Window & raylib::Window::ToggleFullscreen ( )
inline

Toggle window state: fullscreen/windowed.

Definition at line 172 of file Window.hpp.

References ToggleFullscreen().

Referenced by SetFullscreen(), and ToggleFullscreen().

Member Data Documentation

◆ m_drawing

bool raylib::Window::m_drawing = false
protected

Handles the internal drawing state for calling either BeginDrawing() or EndDrawing() from the Drawing() function.

See also
Drawing()

Definition at line 472 of file Window.hpp.

Referenced by Drawing().