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

Static Public Member Functions

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

Protected Attributes

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

Detailed Description

Window and Graphics Device Functions.

Definition at line 14 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 &  title = "raylib",
unsigned int  flags = 0,
TraceLogLevel  logLevel = LOG_ALL 
)
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 37 of file Window.hpp.

References Init().

◆ ~Window()

raylib::Window::~Window ( )
inline

Close window and unload OpenGL context.

Definition at line 44 of file Window.hpp.

References Close().

Member Function Documentation

◆ BeginDrawing()

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

Setup canvas (framebuffer) to start drawing.

Definition at line 331 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 163 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 155 of file Window.hpp.

◆ Close()

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

Close window and unload OpenGL context.

Definition at line 83 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 405 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 442 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 339 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 387 of file Window.hpp.

◆ GetFPS()

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

Returns current FPS.

Definition at line 400 of file Window.hpp.

◆ GetFrameTime()

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

Returns time in seconds for last frame drawn.

Definition at line 410 of file Window.hpp.

◆ GetHandle()

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

Get native window handle.

Definition at line 326 of file Window.hpp.

◆ GetHeight()

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

Get current screen height.

Definition at line 352 of file Window.hpp.

Referenced by GetSize().

◆ GetMonitor()

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

Definition at line 372 of file Window.hpp.

◆ GetPosition()

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

Get window position XY on monitor.

Definition at line 367 of file Window.hpp.

◆ GetRenderHeight()

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

Get current render height (it considers HiDPI)

Definition at line 362 of file Window.hpp.

◆ GetRenderWidth()

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

Get current render width (it considers HiDPI)

Definition at line 357 of file Window.hpp.

◆ GetScaleDPI()

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

Get window scale DPI factor.

Definition at line 377 of file Window.hpp.

◆ GetSize()

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

Get the screen's width and height.

Definition at line 321 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 415 of file Window.hpp.

◆ GetWidth()

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

Get current screen width.

Definition at line 347 of file Window.hpp.

Referenced by GetSize().

◆ HideCursor()

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

Hides cursor.

Definition at line 102 of file Window.hpp.

References HideCursor().

Referenced by HideCursor().

◆ Init()

static void raylib::Window::Init ( int  width = 800,
int  height = 450,
const std::string &  title = "raylib",
unsigned int  flags = 0,
TraceLogLevel  logLevel = LOG_ALL 
)
inlinestatic

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 59 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 97 of file Window.hpp.

◆ IsCursorOnScreen()

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

Check if cursor is on the current screen.

Definition at line 92 of file Window.hpp.

◆ IsFocused()

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

Check if window is currently focused.

Definition at line 132 of file Window.hpp.

◆ IsFullscreen()

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

Check if window is currently fullscreen.

Definition at line 112 of file Window.hpp.

Referenced by SetFullscreen().

◆ IsHidden()

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

Check if window is currently hidden.

Definition at line 117 of file Window.hpp.

◆ IsMaximized()

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

Check if window is currently minimized.

Definition at line 127 of file Window.hpp.

◆ IsMinimized()

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

Check if window is currently minimized.

Definition at line 122 of file Window.hpp.

◆ IsReady()

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

Check if window has been initialized successfully.

Definition at line 420 of file Window.hpp.

◆ IsResized()

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

Check if window has been resized last frame.

Definition at line 137 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 142 of file Window.hpp.

◆ Maximize()

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

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

Definition at line 205 of file Window.hpp.

◆ Minimize()

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

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

Definition at line 213 of file Window.hpp.

◆ Restore()

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

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

Definition at line 221 of file Window.hpp.

◆ SetClipboardText()

static void raylib::Window::SetClipboardText ( const std::string &  text)
inlinestatic

Set clipboard text content.

Definition at line 382 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 429 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 78 of file Window.hpp.

References SetExitKey().

Referenced by SetExitKey().

◆ SetFocused()

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

Set window focused (only PLATFORM_DESKTOP)

Definition at line 308 of file Window.hpp.

◆ SetFullscreen()

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

Set whether or not the application should be fullscreen.

Definition at line 179 of file Window.hpp.

References IsFullscreen(), and ToggleFullscreen().

◆ SetIcon()

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

Set icon for window.

Definition at line 229 of file Window.hpp.

◆ SetIcons()

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

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

Definition at line 237 of file Window.hpp.

◆ SetMinSize() [1/2]

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

Set window minimum dimensions.

Definition at line 284 of file Window.hpp.

◆ SetMinSize() [2/2]

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

Set window minimum dimensions.

Definition at line 276 of file Window.hpp.

◆ SetMonitor()

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

Set monitor for the current window.

Definition at line 268 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 300 of file Window.hpp.

◆ SetPosition() [1/2]

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

Set window position on screen.

Definition at line 261 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 253 of file Window.hpp.

Referenced by SetPosition().

◆ SetSize() [1/2]

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

Set window dimensions.

Definition at line 316 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 292 of file Window.hpp.

◆ SetState()

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

Set window configuration state using flags.

Definition at line 147 of file Window.hpp.

◆ SetTargetFPS()

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

Set target FPS (maximum)

Definition at line 392 of file Window.hpp.

References SetTargetFPS().

Referenced by SetTargetFPS().

◆ SetTitle()

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

Set title for window.

Definition at line 245 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 73 of file Window.hpp.

◆ ShowCursor()

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

Shows cursor.

Definition at line 107 of file Window.hpp.

References ShowCursor().

Referenced by ShowCursor().

◆ ToggleBorderless()

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

Toggle window state: borderless/windowed.

Definition at line 197 of file Window.hpp.

◆ ToggleFullscreen()

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

Toggle window state: fullscreen/windowed.

Definition at line 171 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 461 of file Window.hpp.

Referenced by Drawing().