diff --git a/runtime/Includes/Core/SDLManager.h b/runtime/Includes/Core/SDLManager.h index 2d2e57a..952ccc4 100644 --- a/runtime/Includes/Core/SDLManager.h +++ b/runtime/Includes/Core/SDLManager.h @@ -22,6 +22,11 @@ namespace mlx void MoveMouseOnWindow(Handle window, int x, int y) const noexcept; void GetScreenSizeWindowIsOn(Handle window, int* x, int* y) const noexcept; void SetWindowPosition(Handle window, int x, int y) const noexcept; + void SetWindowSize(Handle window, int x, int y) const noexcept; + void SetWindowTitle(Handle window, std::string_view title) const noexcept; + void SetWindowFullscreen(Handle window, bool enable) const noexcept; + void GetWindowPosition(Handle window, int* x, int* y) const noexcept; + void GetWindowSize(Handle window, int* x, int* y) const noexcept; static void HideCursor() noexcept; static void ShowCursor() noexcept; diff --git a/runtime/Includes/Platform/Window.h b/runtime/Includes/Platform/Window.h index 5bbd628..b837820 100644 --- a/runtime/Includes/Platform/Window.h +++ b/runtime/Includes/Platform/Window.h @@ -13,14 +13,21 @@ namespace mlx Window(const mlx_window_create_info* info, bool hidden = false); inline Handle GetWindowHandle() const noexcept { return p_window; } - inline int GetWidth() const noexcept { return m_width; } - inline int GetHeight() const noexcept { return m_height; } + inline int GetWidth() noexcept { SDLManager::Get().GetWindowSize(p_window, &m_width, &m_height); return m_width; } + inline int GetHeight() noexcept { SDLManager::Get().GetWindowSize(p_window, &m_width, &m_height); return m_height; } inline std::uint32_t GetID() const noexcept { return m_id; } inline const std::string& GetName() const { return m_name; } inline void MoveMouse(int x, int y) { SDLManager::Get().MoveMouseOnWindow(p_window, x, y); } inline void GetScreenSizeWindowIsOn(int* x, int* y) { SDLManager::Get().GetScreenSizeWindowIsOn(p_window, x, y); } + inline void SetPosition(int x, int y) { SDLManager::Get().SetWindowPosition(p_window, x, y); } + inline void SetSize(int x, int y) { SDLManager::Get().SetWindowSize(p_window, x, y); m_width = x; m_height = y; } + inline void SetTitle(std::string title) { SDLManager::Get().SetWindowTitle(p_window, title); m_name = std::move(title); } + inline void SetFullscreen(bool enable) { SDLManager::Get().SetWindowFullscreen(p_window, enable); } + + inline void GetPosition(int* x, int* y) { SDLManager::Get().GetWindowPosition(p_window, x, y); } + inline void GetSize(int* x, int* y) { *x = GetWidth(); *y = GetHeight(); } inline VkSurfaceKHR CreateVulkanSurface(VkInstance instance) const noexcept { return SDLManager::Get().CreateVulkanSurface(p_window, instance); } inline std::vector GetRequiredVulkanInstanceExtentions() const noexcept { return SDLManager::Get().GetRequiredVulkanInstanceExtentions(p_window); } diff --git a/runtime/Sources/Core/Bridge.cpp b/runtime/Sources/Core/Bridge.cpp index d556b88..a178420 100644 --- a/runtime/Sources/Core/Bridge.cpp +++ b/runtime/Sources/Core/Bridge.cpp @@ -80,6 +80,51 @@ extern "C" gs->GetWindow()->SetPosition(x, y); } + void mlx_set_window_size(mlx_context mlx, mlx_window win, int width, int height) + { + MLX_CHECK_APPLICATION_POINTER(mlx); + mlx::NonOwningPtr gs = mlx->app->GetGraphicsSupport(win); + if(!gs && !gs->HasWindow()) + return; + gs->GetWindow()->SetSize(width, height); + } + + void mlx_set_window_title(mlx_context mlx, mlx_window win, const char* title) + { + MLX_CHECK_APPLICATION_POINTER(mlx); + mlx::NonOwningPtr gs = mlx->app->GetGraphicsSupport(win); + if(!gs && !gs->HasWindow()) + return; + gs->GetWindow()->SetTitle(title); + } + + void mlx_set_window_fullscreen(mlx_context mlx, mlx_window win, bool enable) + { + MLX_CHECK_APPLICATION_POINTER(mlx); + mlx::NonOwningPtr gs = mlx->app->GetGraphicsSupport(win); + if(!gs && !gs->HasWindow()) + return; + gs->GetWindow()->SetFullscreen(enable); + } + + void mlx_get_window_position(mlx_context mlx, mlx_window win, int* x, int* y) + { + MLX_CHECK_APPLICATION_POINTER(mlx); + mlx::NonOwningPtr gs = mlx->app->GetGraphicsSupport(win); + if(!gs && !gs->HasWindow()) + return; + gs->GetWindow()->GetPosition(x, y); + } + + void mlx_get_window_size(mlx_context mlx, mlx_window win, int* x, int* y) + { + MLX_CHECK_APPLICATION_POINTER(mlx); + mlx::NonOwningPtr gs = mlx->app->GetGraphicsSupport(win); + if(!gs && !gs->HasWindow()) + return; + gs->GetWindow()->GetSize(x, y); + } + void mlx_clear_window(mlx_context mlx, mlx_window win, int color) { MLX_CHECK_APPLICATION_POINTER(mlx); diff --git a/runtime/Sources/Core/SDLManager.cpp b/runtime/Sources/Core/SDLManager.cpp index 707a48f..cd66caa 100644 --- a/runtime/Sources/Core/SDLManager.cpp +++ b/runtime/Sources/Core/SDLManager.cpp @@ -133,6 +133,31 @@ namespace mlx SDL_SetWindowPosition(static_cast(window)->window, x, y); } + void SDLManager::SetWindowSize(Handle window, int x, int y) const noexcept + { + SDL_SetWindowSize(static_cast(window)->window, x, y); + } + + void SDLManager::SetWindowTitle(Handle window, std::string_view title) const noexcept + { + SDL_SetWindowTitle(static_cast(window)->window, title.data()); + } + + void SDLManager::SetWindowFullscreen(Handle window, bool enable) const noexcept + { + SDL_SetWindowFullscreen(static_cast(window)->window, (enable ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)); + } + + void SDLManager::GetWindowPosition(Handle window, int* x, int* y) const noexcept + { + SDL_GetWindowPosition(static_cast(window)->window, x, y); + } + + void SDLManager::GetWindowSize(Handle window, int* x, int* y) const noexcept + { + SDL_GetWindowSize(static_cast(window)->window, x, y); + } + void SDLManager::HideCursor() noexcept { SDL_ShowCursor(SDL_DISABLE); diff --git a/runtime/Sources/Renderer/Image.cpp b/runtime/Sources/Renderer/Image.cpp index 95ef3ef..892629d 100644 --- a/runtime/Sources/Renderer/Image.cpp +++ b/runtime/Sources/Renderer/Image.cpp @@ -214,6 +214,7 @@ namespace mlx return; if(!m_staging_buffer.has_value()) OpenCPUBuffer(); + // Needs to reverse bytes order because why not unsigned char bytes[4]; bytes[0] = (color >> 24) & 0xFF; bytes[1] = (color >> 16) & 0xFF;