mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
implementing mouse move and get screen size, removing warnings
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
#ifndef __MLX_FORMAT__
|
||||
#define __MLX_FORMAT__
|
||||
|
||||
#include <type_traits>
|
||||
#include <string_view>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
template<typename T, typename = void>
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
#include <Core/Format.h>
|
||||
#include <sstream>
|
||||
#include <ostream>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -16,6 +16,9 @@ namespace mlx
|
||||
inline int GetHeight() const noexcept { return m_height; }
|
||||
inline std::uint32_t GetID() const noexcept { return m_id; }
|
||||
|
||||
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 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); }
|
||||
inline Vec2ui GetVulkanDrawableSize() const noexcept { return SDLManager::Get().GetVulkanDrawableSize(p_window); }
|
||||
|
||||
@@ -42,6 +42,10 @@
|
||||
#include <iterator>
|
||||
#include <stb_truetype.h>
|
||||
#include <variant>
|
||||
#include <type_traits>
|
||||
#include <string_view>
|
||||
#include <sstream>
|
||||
#include <ostream>
|
||||
|
||||
#ifndef MLX_PLAT_WINDOWS
|
||||
#include <dlfcn.h>
|
||||
|
||||
@@ -7,10 +7,14 @@
|
||||
|
||||
static void* __mlx_ptr = nullptr;
|
||||
|
||||
#define MLX_CHECK_APPLICATION_POINTER(ptr) \
|
||||
if(ptr != __mlx_ptr || ptr == NULL) \
|
||||
mlx::FatalError("invalid mlx pointer passed to '%'", MLX_FUNC_SIG); \
|
||||
else {} // just to avoid issues with possible if-else statements outside this macro
|
||||
#ifndef DISABLE_ALL_SAFETIES
|
||||
#define MLX_CHECK_APPLICATION_POINTER(ptr) \
|
||||
if(ptr != __mlx_ptr || ptr == NULL) \
|
||||
mlx::FatalError("invalid mlx pointer passed to '%'", MLX_FUNC_SIG); \
|
||||
else {} // just to avoid issues with possible if-else statements outside this macro
|
||||
#else
|
||||
#define MLX_CHECK_APPLICATION_POINTER(ptr)
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
@@ -6,8 +6,6 @@ namespace mlx
|
||||
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, NonOwningPtr<Texture> render_target, int id) :
|
||||
m_put_pixel_manager(&m_renderer),
|
||||
p_window(nullptr),
|
||||
m_width(w),
|
||||
m_height(h),
|
||||
m_id(id),
|
||||
m_has_window(false)
|
||||
{
|
||||
@@ -24,8 +22,6 @@ namespace mlx
|
||||
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, std::string title, int id) :
|
||||
m_put_pixel_manager(&m_renderer),
|
||||
p_window(std::make_shared<Window>(w, h, title)),
|
||||
m_width(w),
|
||||
m_height(h),
|
||||
m_id(id),
|
||||
m_has_window(true)
|
||||
{
|
||||
|
||||
@@ -159,6 +159,20 @@ namespace mlx
|
||||
return Vec2ui{ extent };
|
||||
}
|
||||
|
||||
void SDLManager::MoveMouseOnWindow(Handle window, int x, int y) const noexcept
|
||||
{
|
||||
SDL_WarpMouseInWindow(static_cast<SDL_Window*>(window), x, y);
|
||||
SDL_PumpEvents();
|
||||
}
|
||||
|
||||
void SDLManager::GetScreenSizeWindowIsOn(Handle window, int* x, int* y) const noexcept
|
||||
{
|
||||
SDL_DisplayMode DM;
|
||||
SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(static_cast<SDL_Window*>(window)), &DM);
|
||||
*x = DM.w;
|
||||
*y = DM.h;
|
||||
}
|
||||
|
||||
std::int32_t SDLManager::GetX() const noexcept
|
||||
{
|
||||
int dummy;
|
||||
|
||||
Reference in New Issue
Block a user