From ccd02fa9ef2fee7bd84f7fffe2c80d11a1f2c76d Mon Sep 17 00:00:00 2001 From: Noel Berry Date: Tue, 25 Jan 2022 22:50:20 -0800 Subject: [PATCH] added App::focused and System::open_url apis --- include/blah/app.h | 9 +++++++++ src/app.cpp | 10 ++++++++++ src/filesystem.cpp | 7 ++++++- src/internal/platform.h | 6 ++++++ src/internal/platform_sdl2.cpp | 11 +++++++++++ 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/include/blah/app.h b/include/blah/app.h index 45b03a6..b4c2a22 100644 --- a/include/blah/app.h +++ b/include/blah/app.h @@ -149,6 +149,9 @@ namespace Blah // macOS is usually 2.0, other platforms vary. float content_scale(); + // If the window is currently focused or has mouse input + bool focused(); + // Toggles fullscreen if supported on the platform. // Otherwise this function does nothing. void fullscreen(bool enabled); @@ -162,4 +165,10 @@ namespace Blah // Reference to the window's back buffer extern const TargetRef backbuffer; } + + namespace System + { + // Tries to open the given URL in a web browser + void open_url(const char* url); + } } \ No newline at end of file diff --git a/src/app.cpp b/src/app.cpp index 99b9793..9bc327e 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -274,6 +274,11 @@ void App::fullscreen(bool enabled) Platform::set_fullscreen(enabled); } +bool App::focused() +{ + return Platform::get_focused(); +} + Renderer App::renderer() { return Graphics::renderer(); @@ -284,6 +289,11 @@ const RendererFeatures& Blah::App::renderer_features() return Graphics::features(); } +void System::open_url(const char* url) +{ + Platform::open_url(url); +} + namespace { // A dummy Frame Buffer that represents the Back Buffer diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 9322513..9c4f8d4 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -146,5 +146,10 @@ FilePath Path::normalize(const FilePath& path) FilePath Path::join(const FilePath& a, const FilePath& b) { - return normalize(FilePath(a).append("/").append(b)); + if (a.length() <= 0) + return normalize(b); + else if (b.length() <= 0) + return normalize(a); + else + return normalize(FilePath(a).append("/").append(b)); } \ No newline at end of file diff --git a/src/internal/platform.h b/src/internal/platform.h index d24893b..49bbfdd 100644 --- a/src/internal/platform.h +++ b/src/internal/platform.h @@ -43,6 +43,9 @@ namespace Blah // Sets the Application Window Position, in Screen Coordinates void set_position(int x, int y); + // Gets whether the Window has focus + bool get_focused(); + // Sets the Window Fullscreen if enabled is not 0 void set_fullscreen(bool enabled); @@ -102,5 +105,8 @@ namespace Blah // D3D11 Methods void* d3d11_get_hwnd(); + + // Tries to open a URL in a web browser + void open_url(const char* url); } } \ No newline at end of file diff --git a/src/internal/platform_sdl2.cpp b/src/internal/platform_sdl2.cpp index df55ca2..5b17ad2 100644 --- a/src/internal/platform_sdl2.cpp +++ b/src/internal/platform_sdl2.cpp @@ -494,6 +494,12 @@ void Platform::set_position(int x, int y) SDL_SetWindowPosition(g_platform.window, x, y); } +bool Platform::get_focused() +{ + auto flags = SDL_GetWindowFlags(g_platform.window); + return (flags & SDL_WINDOW_INPUT_FOCUS) != 0 && (flags & SDL_WINDOW_MINIMIZED) == 0; +} + void Platform::set_fullscreen(bool enabled) { if (enabled) @@ -768,4 +774,9 @@ void* Platform::d3d11_get_hwnd() #endif } +void Platform::open_url(const char* url) +{ + SDL_OpenURL(url); +} + #endif // BLAH_PLATFORM_SDL2