adding missing function implementation

This commit is contained in:
2024-12-15 03:53:56 +01:00
parent 5a36b90a72
commit 5b726fe74a
5 changed files with 85 additions and 2 deletions

View File

@@ -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;

View File

@@ -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); }

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;