Skip to content

Commit

Permalink
adding missing function implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbz-8 committed Dec 15, 2024
1 parent 323b16f commit 11ccc04
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 2 deletions.
5 changes: 5 additions & 0 deletions runtime/Includes/Core/SDLManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 9 additions & 2 deletions runtime/Includes/Platform/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char*> GetRequiredVulkanInstanceExtentions() const noexcept { return SDLManager::Get().GetRequiredVulkanInstanceExtentions(p_window); }
Expand Down
45 changes: 45 additions & 0 deletions runtime/Sources/Core/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<mlx::GraphicsSupport> 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<mlx::GraphicsSupport> 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<mlx::GraphicsSupport> 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<mlx::GraphicsSupport> 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<mlx::GraphicsSupport> 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);
Expand Down
25 changes: 25 additions & 0 deletions runtime/Sources/Core/SDLManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,31 @@ namespace mlx
SDL_SetWindowPosition(static_cast<Internal::WindowInfos*>(window)->window, x, y);
}

void SDLManager::SetWindowSize(Handle window, int x, int y) const noexcept
{
SDL_SetWindowSize(static_cast<Internal::WindowInfos*>(window)->window, x, y);
}

void SDLManager::SetWindowTitle(Handle window, std::string_view title) const noexcept
{
SDL_SetWindowTitle(static_cast<Internal::WindowInfos*>(window)->window, title.data());
}

void SDLManager::SetWindowFullscreen(Handle window, bool enable) const noexcept
{
SDL_SetWindowFullscreen(static_cast<Internal::WindowInfos*>(window)->window, (enable ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0));
}

void SDLManager::GetWindowPosition(Handle window, int* x, int* y) const noexcept
{
SDL_GetWindowPosition(static_cast<Internal::WindowInfos*>(window)->window, x, y);
}

void SDLManager::GetWindowSize(Handle window, int* x, int* y) const noexcept
{
SDL_GetWindowSize(static_cast<Internal::WindowInfos*>(window)->window, x, y);
}

void SDLManager::HideCursor() noexcept
{
SDL_ShowCursor(SDL_DISABLE);
Expand Down
1 change: 1 addition & 0 deletions runtime/Sources/Renderer/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 11ccc04

Please sign in to comment.