implementing mouse move and get screen size, removing warnings

This commit is contained in:
2024-09-15 08:56:22 +02:00
parent 2b9b026d68
commit 596393ed20
14 changed files with 85 additions and 41 deletions

View File

@@ -1,29 +1,34 @@
#pragma once
#include <Core/Application.h>
#define CHECK_WINDOW_PTR(win) \
if(win == nullptr) \
{ \
Error("invalid window ptr (NULL)"); \
return; \
} \
else if(*static_cast<int*>(win) < 0 || *static_cast<int*>(win) > static_cast<int>(m_graphics.size()))\
{ \
Error("invalid window ptr"); \
return; \
} else {}
#ifndef DISABLE_ALL_SAFETIES
#define CHECK_WINDOW_PTR(win) \
if(win == nullptr) \
{ \
Error("invalid window ptr (NULL)"); \
return; \
} \
else if(std::find_if(m_graphics.begin(), m_graphics.end(), [win](const std::unique_ptr<GraphicsSupport>& gs){ return *static_cast<int*>(win) == gs->GetID(); } != m_graphics.end())) \
{ \
Error("invalid window ptr"); \
return; \
} else {}
#define CHECK_IMAGE_PTR(img, retval) \
if(img == nullptr) \
{ \
Error("invalid image ptr (NULL)"); \
retval; \
} \
else if(!m_image_registry.IsTextureKnown(static_cast<Texture*>(img))) \
{ \
Error("invalid image ptr"); \
retval; \
} else {}
#define CHECK_IMAGE_PTR(img, retval) \
if(img == nullptr) \
{ \
Error("invalid image ptr (NULL)"); \
retval; \
} \
else if(!m_image_registry.IsTextureKnown(static_cast<Texture*>(img))) \
{ \
Error("invalid image ptr"); \
retval; \
} else {}
#else
#define CHECK_WINDOW_PTR(win)
#define CHECK_IMAGE_PTR(img, retval)
#endif
namespace mlx
{
@@ -41,6 +46,7 @@ namespace mlx
Warning("trying to move the mouse relative to a window that is targeting an image and not a real window, this is not allowed (move ignored)");
return;
}
m_graphics[*static_cast<int*>(win)]->GetWindow()->MoveMouse(x, y);
}
void Application::OnEvent(Handle win, int event, int (*funct_ptr)(int, void*), void* param) noexcept
@@ -57,8 +63,7 @@ namespace mlx
void Application::GetScreenSize(Handle win, int* w, int* h) noexcept
{
CHECK_WINDOW_PTR(win);
*w = 0;
*h = 0;
m_graphics[*static_cast<int*>(win)]->GetWindow()->GetScreenSizeWindowIsOn(x, y);
}
void Application::SetFPSCap(std::uint32_t fps) noexcept
@@ -96,6 +101,7 @@ namespace mlx
MLX_PROFILE_FUNCTION();
CHECK_WINDOW_PTR(win);
m_graphics[*static_cast<int*>(win)].reset();
m_graphics.erase(m_graphics.begin() + *static_cast<int*>(win));
}
void Application::PixelPut(Handle win, int x, int y, std::uint32_t color) const noexcept

View File

@@ -1,9 +1,6 @@
#ifndef __MLX_FORMAT__
#define __MLX_FORMAT__
#include <type_traits>
#include <string_view>
namespace mlx
{
template<typename T, typename = void>

View File

@@ -1,7 +1,5 @@
#pragma once
#include <Core/Format.h>
#include <sstream>
#include <ostream>
namespace mlx
{

View File

@@ -46,9 +46,6 @@ namespace mlx
std::uint64_t m_current_depth = 0;
std::size_t m_width = 0;
std::size_t m_height = 0;
int m_id;
bool m_has_window;

View File

@@ -25,6 +25,10 @@ namespace mlx
void GraphicsSupport::StringPut(int x, int y, std::uint32_t color, std::string str)
{
MLX_PROFILE_FUNCTION();
(void)x;
(void)y;
(void)color;
(void)str;
}
void GraphicsSupport::TexturePut(NonOwningPtr<Texture> texture, int x, int y)
@@ -44,6 +48,8 @@ namespace mlx
void GraphicsSupport::LoadFont(const std::filesystem::path& filepath, float scale)
{
MLX_PROFILE_FUNCTION();
(void)filepath;
(void)scale;
}
void GraphicsSupport::TryEraseSpritesInScene(NonOwningPtr<Texture> texture) noexcept

View File

@@ -39,7 +39,7 @@ namespace mlx
void Assert(bool cond, unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args);
#else
template<typename... Args>
void Assert(bool cond, unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args) {}
void Assert([[maybe_unused]] bool cond, [[maybe_unused]] unsigned int line, [[maybe_unused]] std::string_view file, [[maybe_unused]] std::string_view function, [[maybe_unused]] std::string message, [[maybe_unused]] const Args&... args) {}
#endif
}

View File

@@ -19,6 +19,8 @@ namespace mlx
VkSurfaceKHR CreateVulkanSurface(Handle window, VkInstance instance) const noexcept;
std::vector<const char*> GetRequiredVulkanInstanceExtentions(Handle window) const noexcept;
Vec2ui GetVulkanDrawableSize(Handle window) const noexcept;
void MoveMouseOnWindow(Handle window, int x, int y) const noexcept;
void GetScreenSizeWindowIsOn(Handle window, int* x, int* y) const noexcept;
inline void SetEventCallback(func::function<void(mlx_event_type, int, int, void*)> functor, void* userdata) { f_callback = std::move(functor); p_callback_data = userdata; }