Updated raylib-cpp header files
This commit is contained in:
@@ -3,24 +3,22 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "./raylib.hpp"
|
||||
#include "./RaylibException.hpp"
|
||||
#include "./Vector2.hpp"
|
||||
#include "./raylib.hpp"
|
||||
|
||||
namespace raylib {
|
||||
/**
|
||||
* Window and Graphics Device Functions.
|
||||
*/
|
||||
class Window {
|
||||
public:
|
||||
public:
|
||||
/**
|
||||
* Build a Window object, but defer the initialization. Ensure you call Init() manually.
|
||||
*
|
||||
* @see Init()
|
||||
*/
|
||||
Window() {
|
||||
// Nothing.
|
||||
}
|
||||
Window() = default;
|
||||
|
||||
/**
|
||||
* Initialize window and OpenGL context.
|
||||
@@ -29,22 +27,21 @@ class Window {
|
||||
* @param height The height of the window.
|
||||
* @param title The desired title of the window.
|
||||
* @param flags The ConfigFlags to set prior to initializing the window. See SetConfigFlags for more details.
|
||||
* @param logLevel The the current threshold (minimum) log level
|
||||
*
|
||||
* @see ::SetConfigFlags()
|
||||
* @see ConfigFlags
|
||||
*
|
||||
* @throws raylib::RaylibException Thrown if the window failed to initiate.
|
||||
*/
|
||||
Window(int width, int height, const std::string& title = "raylib", unsigned int flags = 0) {
|
||||
Init(width, height, title, flags);
|
||||
Window(int width, int height, const std::string& title = "raylib", unsigned int flags = 0, TraceLogLevel logLevel = LOG_ALL) {
|
||||
Init(width, height, title, flags, logLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close window and unload OpenGL context
|
||||
*/
|
||||
~Window() {
|
||||
Close();
|
||||
}
|
||||
~Window() { Close(); }
|
||||
|
||||
/**
|
||||
* Initializes the window.
|
||||
@@ -59,10 +56,11 @@ class Window {
|
||||
*
|
||||
* @throws raylib::RaylibException Thrown if the window failed to initiate.
|
||||
*/
|
||||
inline void Init(int width = 800, int height = 450, const std::string& title = "raylib", unsigned int flags = 0) {
|
||||
static void Init(int width = 800, int height = 450, const std::string& title = "raylib", unsigned int flags = 0, TraceLogLevel logLevel = LOG_ALL) {
|
||||
if (flags != 0) {
|
||||
::SetConfigFlags(flags);
|
||||
}
|
||||
::SetTraceLogLevel(logLevel);
|
||||
::InitWindow(width, height, title.c_str());
|
||||
if (!::IsWindowReady()) {
|
||||
throw RaylibException("Failed to create Window");
|
||||
@@ -72,14 +70,17 @@ class Window {
|
||||
/**
|
||||
* Check if KEY_ESCAPE pressed or Close icon pressed
|
||||
*/
|
||||
inline bool ShouldClose() const {
|
||||
return ::WindowShouldClose();
|
||||
}
|
||||
static bool ShouldClose() { return ::WindowShouldClose(); }
|
||||
|
||||
/**
|
||||
* Set a custom key to exit program (default is ESC)
|
||||
*/
|
||||
static void SetExitKey(int key) { ::SetExitKey(key); }
|
||||
|
||||
/**
|
||||
* Close window and unload OpenGL context
|
||||
*/
|
||||
inline void Close() {
|
||||
static void Close() {
|
||||
if (::IsWindowReady()) {
|
||||
::CloseWindow();
|
||||
}
|
||||
@@ -88,63 +89,62 @@ class Window {
|
||||
/**
|
||||
* Check if cursor is on the current screen
|
||||
*/
|
||||
inline bool IsCursorOnScreen() const {
|
||||
return ::IsCursorOnScreen();
|
||||
}
|
||||
static bool IsCursorOnScreen() { return ::IsCursorOnScreen(); }
|
||||
|
||||
/**
|
||||
* Check if cursor is not visible
|
||||
*/
|
||||
static bool IsCursorHidden() { return ::IsCursorHidden(); }
|
||||
|
||||
/**
|
||||
* Hides cursor
|
||||
*/
|
||||
static void HideCursor() { ::HideCursor(); }
|
||||
|
||||
/**
|
||||
* Shows cursor
|
||||
*/
|
||||
static void ShowCursor() { ::ShowCursor(); }
|
||||
|
||||
/**
|
||||
* Check if window is currently fullscreen
|
||||
*/
|
||||
inline bool IsFullscreen() const {
|
||||
return ::IsWindowFullscreen();
|
||||
}
|
||||
static bool IsFullscreen() { return ::IsWindowFullscreen(); }
|
||||
|
||||
/**
|
||||
* Check if window is currently hidden
|
||||
*/
|
||||
inline bool IsHidden() const {
|
||||
return ::IsWindowHidden();
|
||||
}
|
||||
static bool IsHidden() { return ::IsWindowHidden(); }
|
||||
|
||||
/**
|
||||
* Check if window is currently minimized
|
||||
*/
|
||||
inline bool IsMinimized() const {
|
||||
return ::IsWindowMinimized();
|
||||
}
|
||||
static bool IsMinimized() { return ::IsWindowMinimized(); }
|
||||
|
||||
/**
|
||||
* Check if window is currently minimized
|
||||
*/
|
||||
inline bool IsMaximized() const {
|
||||
return ::IsWindowMaximized();
|
||||
}
|
||||
static bool IsMaximized() { return ::IsWindowMaximized(); }
|
||||
|
||||
/**
|
||||
* Check if window is currently focused
|
||||
*/
|
||||
inline bool IsFocused() const {
|
||||
return ::IsWindowFocused();
|
||||
}
|
||||
static bool IsFocused() { return ::IsWindowFocused(); }
|
||||
|
||||
/**
|
||||
* Check if window has been resized last frame
|
||||
*/
|
||||
inline bool IsResized() const {
|
||||
return ::IsWindowResized();
|
||||
}
|
||||
static bool IsResized() { return ::IsWindowResized(); }
|
||||
|
||||
/**
|
||||
* Check if one specific window flag is enabled
|
||||
*/
|
||||
inline bool IsState(unsigned int flag) const {
|
||||
return ::IsWindowState(flag);
|
||||
}
|
||||
static bool IsState(unsigned int flag) { return ::IsWindowState(flag); }
|
||||
|
||||
/**
|
||||
* Set window configuration state using flags
|
||||
*/
|
||||
inline Window& SetState(unsigned int flag) {
|
||||
Window& SetState(unsigned int flag) {
|
||||
::SetWindowState(flag);
|
||||
return *this;
|
||||
}
|
||||
@@ -152,7 +152,7 @@ class Window {
|
||||
/**
|
||||
* Clear window configuration state flags
|
||||
*/
|
||||
inline Window& ClearState(unsigned int flag) {
|
||||
Window& ClearState(unsigned int flag) {
|
||||
::ClearWindowState(flag);
|
||||
return *this;
|
||||
}
|
||||
@@ -160,7 +160,7 @@ class Window {
|
||||
/**
|
||||
* Clear window with given color.
|
||||
*/
|
||||
inline Window& ClearBackground(const ::Color& color = BLACK) {
|
||||
Window& ClearBackground(const ::Color& color = BLACK) {
|
||||
::ClearBackground(color);
|
||||
return *this;
|
||||
}
|
||||
@@ -168,7 +168,7 @@ class Window {
|
||||
/**
|
||||
* Toggle window state: fullscreen/windowed
|
||||
*/
|
||||
inline Window& ToggleFullscreen() {
|
||||
Window& ToggleFullscreen() {
|
||||
::ToggleFullscreen();
|
||||
return *this;
|
||||
}
|
||||
@@ -176,12 +176,13 @@ class Window {
|
||||
/**
|
||||
* Set whether or not the application should be fullscreen.
|
||||
*/
|
||||
inline Window& SetFullscreen(bool fullscreen) {
|
||||
Window& SetFullscreen(bool fullscreen) {
|
||||
if (fullscreen) {
|
||||
if (!IsFullscreen()) {
|
||||
ToggleFullscreen();
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (IsFullscreen()) {
|
||||
ToggleFullscreen();
|
||||
}
|
||||
@@ -192,8 +193,8 @@ class Window {
|
||||
|
||||
/**
|
||||
* Toggle window state: borderless/windowed
|
||||
*/
|
||||
inline Window& ToggleBorderless() {
|
||||
*/
|
||||
Window& ToggleBorderless() {
|
||||
::ToggleBorderlessWindowed();
|
||||
return *this;
|
||||
}
|
||||
@@ -201,7 +202,7 @@ class Window {
|
||||
/**
|
||||
* Set window state: maximized, if resizable (only PLATFORM_DESKTOP)
|
||||
*/
|
||||
inline Window& Maximize() {
|
||||
Window& Maximize() {
|
||||
::MaximizeWindow();
|
||||
return *this;
|
||||
}
|
||||
@@ -209,7 +210,7 @@ class Window {
|
||||
/**
|
||||
* Set window state: minimized, if resizable (only PLATFORM_DESKTOP)
|
||||
*/
|
||||
inline Window& Minimize() {
|
||||
Window& Minimize() {
|
||||
::MinimizeWindow();
|
||||
return *this;
|
||||
}
|
||||
@@ -217,7 +218,7 @@ class Window {
|
||||
/**
|
||||
* Set window state: not minimized/maximized (only PLATFORM_DESKTOP)
|
||||
*/
|
||||
inline Window& Restore() {
|
||||
Window& Restore() {
|
||||
::RestoreWindow();
|
||||
return *this;
|
||||
}
|
||||
@@ -225,7 +226,7 @@ class Window {
|
||||
/**
|
||||
* Set icon for window
|
||||
*/
|
||||
inline Window& SetIcon(const ::Image& image) {
|
||||
Window& SetIcon(const ::Image& image) {
|
||||
::SetWindowIcon(image);
|
||||
return *this;
|
||||
}
|
||||
@@ -233,7 +234,7 @@ class Window {
|
||||
/**
|
||||
* Set icon for window (multiple images, RGBA 32bit, only PLATFORM_DESKTOP)
|
||||
*/
|
||||
inline Window& SetIcons(Image* images, int count) {
|
||||
Window& SetIcons(Image* images, int count) {
|
||||
::SetWindowIcons(images, count);
|
||||
return *this;
|
||||
}
|
||||
@@ -241,7 +242,7 @@ class Window {
|
||||
/**
|
||||
* Set title for window
|
||||
*/
|
||||
inline Window& SetTitle(const std::string& title) {
|
||||
Window& SetTitle(const std::string& title) {
|
||||
::SetWindowTitle(title.c_str());
|
||||
return *this;
|
||||
}
|
||||
@@ -249,7 +250,7 @@ class Window {
|
||||
/**
|
||||
* Set window position on screen
|
||||
*/
|
||||
inline Window& SetPosition(int x, int y) {
|
||||
Window& SetPosition(int x, int y) {
|
||||
::SetWindowPosition(x, y);
|
||||
return *this;
|
||||
}
|
||||
@@ -257,14 +258,14 @@ class Window {
|
||||
/**
|
||||
* Set window position on screen
|
||||
*/
|
||||
inline Window& SetPosition(const ::Vector2& position) {
|
||||
Window& SetPosition(const ::Vector2& position) {
|
||||
return SetPosition(static_cast<int>(position.x), static_cast<int>(position.y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set monitor for the current window
|
||||
*/
|
||||
inline Window& SetMonitor(int monitor) {
|
||||
Window& SetMonitor(int monitor) {
|
||||
::SetWindowMonitor(monitor);
|
||||
return *this;
|
||||
}
|
||||
@@ -272,7 +273,7 @@ class Window {
|
||||
/**
|
||||
* Set window minimum dimensions
|
||||
*/
|
||||
inline Window& SetMinSize(int width, int height) {
|
||||
Window& SetMinSize(int width, int height) {
|
||||
::SetWindowMinSize(width, height);
|
||||
return *this;
|
||||
}
|
||||
@@ -280,7 +281,7 @@ class Window {
|
||||
/**
|
||||
* Set window minimum dimensions
|
||||
*/
|
||||
inline Window& SetMinSize(const ::Vector2& size) {
|
||||
Window& SetMinSize(const ::Vector2& size) {
|
||||
::SetWindowMinSize(static_cast<int>(size.x), static_cast<int>(size.y));
|
||||
return *this;
|
||||
}
|
||||
@@ -288,7 +289,7 @@ class Window {
|
||||
/**
|
||||
* Set window dimensions
|
||||
*/
|
||||
inline Window& SetSize(int width, int height) {
|
||||
Window& SetSize(int width, int height) {
|
||||
::SetWindowSize(width, height);
|
||||
return *this;
|
||||
}
|
||||
@@ -296,7 +297,7 @@ class Window {
|
||||
/**
|
||||
* Set window opacity [0.0f..1.0f] (only PLATFORM_DESKTOP)
|
||||
*/
|
||||
inline Window& SetOpacity(float opacity) {
|
||||
Window& SetOpacity(float opacity) {
|
||||
::SetWindowOpacity(opacity);
|
||||
return *this;
|
||||
}
|
||||
@@ -304,7 +305,7 @@ class Window {
|
||||
/**
|
||||
* Set window focused (only PLATFORM_DESKTOP)
|
||||
*/
|
||||
inline Window& SetFocused() {
|
||||
Window& SetFocused() {
|
||||
::SetWindowFocused();
|
||||
return *this;
|
||||
}
|
||||
@@ -312,28 +313,22 @@ class Window {
|
||||
/**
|
||||
* Set window dimensions
|
||||
*/
|
||||
inline Window& SetSize(const ::Vector2& size) {
|
||||
return SetSize(static_cast<int>(size.x), static_cast<int>(size.y));
|
||||
}
|
||||
Window& SetSize(const ::Vector2& size) { return SetSize(static_cast<int>(size.x), static_cast<int>(size.y)); }
|
||||
|
||||
/**
|
||||
* Get the screen's width and height.
|
||||
*/
|
||||
inline Vector2 GetSize() const {
|
||||
return {static_cast<float>(GetWidth()), static_cast<float>(GetHeight())};
|
||||
}
|
||||
static Vector2 GetSize() { return {static_cast<float>(GetWidth()), static_cast<float>(GetHeight())}; }
|
||||
|
||||
/**
|
||||
* Get native window handle
|
||||
*/
|
||||
inline void* GetHandle() const {
|
||||
return ::GetWindowHandle();
|
||||
}
|
||||
static void* GetHandle() { return ::GetWindowHandle(); }
|
||||
|
||||
/**
|
||||
* Setup canvas (framebuffer) to start drawing
|
||||
*/
|
||||
inline Window& BeginDrawing() {
|
||||
Window& BeginDrawing() {
|
||||
::BeginDrawing();
|
||||
return *this;
|
||||
}
|
||||
@@ -341,7 +336,7 @@ class Window {
|
||||
/**
|
||||
* End canvas drawing and swap buffers (double buffering)
|
||||
*/
|
||||
inline Window& EndDrawing() {
|
||||
Window& EndDrawing() {
|
||||
::EndDrawing();
|
||||
return *this;
|
||||
}
|
||||
@@ -349,63 +344,52 @@ class Window {
|
||||
/**
|
||||
* Get current screen width
|
||||
*/
|
||||
inline int GetWidth() const {
|
||||
return ::GetScreenWidth();
|
||||
}
|
||||
static int GetWidth() { return ::GetScreenWidth(); }
|
||||
|
||||
/**
|
||||
* Get current screen height
|
||||
*/
|
||||
inline int GetHeight() const {
|
||||
return ::GetScreenHeight();
|
||||
}
|
||||
static int GetHeight() { return ::GetScreenHeight(); }
|
||||
|
||||
/**
|
||||
* Get current render width (it considers HiDPI)
|
||||
*/
|
||||
inline int GetRenderWidth() const {
|
||||
return ::GetRenderWidth();
|
||||
}
|
||||
static int GetRenderWidth() { return ::GetRenderWidth(); }
|
||||
|
||||
/**
|
||||
* Get current render height (it considers HiDPI)
|
||||
*/
|
||||
inline int GetRenderHeight() const {
|
||||
return ::GetRenderHeight();
|
||||
}
|
||||
static int GetRenderHeight() { return ::GetRenderHeight(); }
|
||||
|
||||
/**
|
||||
* Get window position XY on monitor
|
||||
*/
|
||||
inline Vector2 GetPosition() const {
|
||||
return ::GetWindowPosition();
|
||||
}
|
||||
static Vector2 GetPosition() { return ::GetWindowPosition(); }
|
||||
|
||||
/*
|
||||
* Get current window monitor
|
||||
*/
|
||||
static int GetMonitor() { return ::GetCurrentMonitor(); }
|
||||
|
||||
/**
|
||||
* Get window scale DPI factor
|
||||
*/
|
||||
inline Vector2 GetScaleDPI() const {
|
||||
return ::GetWindowScaleDPI();
|
||||
}
|
||||
static Vector2 GetScaleDPI() { return ::GetWindowScaleDPI(); }
|
||||
|
||||
/**
|
||||
* Set clipboard text content
|
||||
*/
|
||||
inline void SetClipboardText(const std::string& text) {
|
||||
::SetClipboardText(text.c_str());
|
||||
}
|
||||
static void SetClipboardText(const std::string& text) { ::SetClipboardText(text.c_str()); }
|
||||
|
||||
/**
|
||||
* Get clipboard text content
|
||||
*/
|
||||
inline const std::string GetClipboardText() {
|
||||
return ::GetClipboardText();
|
||||
}
|
||||
static std::string GetClipboardText() { return ::GetClipboardText(); }
|
||||
|
||||
/**
|
||||
* Set target FPS (maximum)
|
||||
*/
|
||||
inline Window& SetTargetFPS(int fps) {
|
||||
Window& SetTargetFPS(int fps) {
|
||||
::SetTargetFPS(fps);
|
||||
return *this;
|
||||
}
|
||||
@@ -413,37 +397,27 @@ class Window {
|
||||
/**
|
||||
* Returns current FPS
|
||||
*/
|
||||
inline int GetFPS() const {
|
||||
return ::GetFPS();
|
||||
}
|
||||
static int GetFPS() { return ::GetFPS(); }
|
||||
|
||||
/**
|
||||
* Draw current FPS
|
||||
*/
|
||||
inline void DrawFPS(int posX = 10, int posY = 10) const {
|
||||
::DrawFPS(posX, posY);
|
||||
}
|
||||
static void DrawFPS(int posX = 10, int posY = 10) { ::DrawFPS(posX, posY); }
|
||||
|
||||
/**
|
||||
* Returns time in seconds for last frame drawn
|
||||
*/
|
||||
inline float GetFrameTime() const {
|
||||
return ::GetFrameTime();
|
||||
}
|
||||
static float GetFrameTime() { return ::GetFrameTime(); }
|
||||
|
||||
/**
|
||||
* Returns elapsed time in seconds since InitWindow()
|
||||
*/
|
||||
inline double GetTime() const {
|
||||
return ::GetTime();
|
||||
}
|
||||
static double GetTime() { return ::GetTime(); }
|
||||
|
||||
/**
|
||||
* Check if window has been initialized successfully
|
||||
*/
|
||||
inline static bool IsReady() {
|
||||
return ::IsWindowReady();
|
||||
}
|
||||
static bool IsReady() { return ::IsWindowReady(); }
|
||||
|
||||
/**
|
||||
* Sets the configuration flags for raylib.
|
||||
@@ -452,12 +426,42 @@ class Window {
|
||||
*
|
||||
* @see ::SetConfigFlags
|
||||
*/
|
||||
inline void SetConfigFlags(unsigned int flags) {
|
||||
::SetConfigFlags(flags);
|
||||
static void SetConfigFlags(unsigned int flags) { ::SetConfigFlags(flags); }
|
||||
|
||||
/**
|
||||
* Alternates between calling `BeginDrawing()` and `EndDrawing()`.
|
||||
*
|
||||
* @code
|
||||
* while (window.Drawing()) {
|
||||
* DrawRectangle();
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @return True if we're within the `BeginDrawing()` scope.
|
||||
*/
|
||||
bool Drawing() {
|
||||
if (m_drawing) {
|
||||
EndDrawing();
|
||||
m_drawing = false;
|
||||
}
|
||||
else {
|
||||
BeginDrawing();
|
||||
m_drawing = true;
|
||||
}
|
||||
|
||||
return m_drawing;
|
||||
}
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Handles the internal drawing state for calling either `BeginDrawing()` or `EndDrawing()` from the `Drawing()` function.
|
||||
*
|
||||
* @see Drawing()
|
||||
*/
|
||||
bool m_drawing = false;
|
||||
};
|
||||
} // namespace raylib
|
||||
} // namespace raylib
|
||||
|
||||
using RWindow = raylib::Window;
|
||||
|
||||
#endif // RAYLIB_CPP_INCLUDE_WINDOW_HPP_
|
||||
#endif // RAYLIB_CPP_INCLUDE_WINDOW_HPP_
|
||||
|
Reference in New Issue
Block a user