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:
10
Makefile
10
Makefile
@@ -8,6 +8,8 @@ IMAGES_OPTIMIZED ?= true
|
|||||||
FORCE_INTEGRATED_GPU ?= false
|
FORCE_INTEGRATED_GPU ?= false
|
||||||
GRAPHICS_MEMORY_DUMP ?= false
|
GRAPHICS_MEMORY_DUMP ?= false
|
||||||
PROFILER ?= false
|
PROFILER ?= false
|
||||||
|
FORCE_WAYLAND ?= false
|
||||||
|
DISABLE_ALL_SAFETIES ?= false
|
||||||
_ENABLEDFLAGS =
|
_ENABLEDFLAGS =
|
||||||
|
|
||||||
SRCS = $(wildcard $(addsuffix /*.cpp, runtime/Sources/Core))
|
SRCS = $(wildcard $(addsuffix /*.cpp, runtime/Sources/Core))
|
||||||
@@ -57,6 +59,14 @@ ifeq ($(PROFILER), true)
|
|||||||
_ENABLEDFLAGS += PROFILER
|
_ENABLEDFLAGS += PROFILER
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(FORCE_WAYLAND), true)
|
||||||
|
_ENABLEDFLAGS += FORCE_WAYLAND
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(DISABLE_ALL_SAFETIES), true)
|
||||||
|
_ENABLEDFLAGS += DISABLE_ALL_SAFETIES
|
||||||
|
endif
|
||||||
|
|
||||||
CXXFLAGS += $(addprefix -D, $(_ENABLEDFLAGS))
|
CXXFLAGS += $(addprefix -D, $(_ENABLEDFLAGS))
|
||||||
|
|
||||||
RM = rm -rf
|
RM = rm -rf
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Core/Application.h>
|
#include <Core/Application.h>
|
||||||
|
|
||||||
|
#ifndef DISABLE_ALL_SAFETIES
|
||||||
#define CHECK_WINDOW_PTR(win) \
|
#define CHECK_WINDOW_PTR(win) \
|
||||||
if(win == nullptr) \
|
if(win == nullptr) \
|
||||||
{ \
|
{ \
|
||||||
Error("invalid window ptr (NULL)"); \
|
Error("invalid window ptr (NULL)"); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
else if(*static_cast<int*>(win) < 0 || *static_cast<int*>(win) > static_cast<int>(m_graphics.size()))\
|
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"); \
|
Error("invalid window ptr"); \
|
||||||
return; \
|
return; \
|
||||||
@@ -24,6 +25,10 @@
|
|||||||
Error("invalid image ptr"); \
|
Error("invalid image ptr"); \
|
||||||
retval; \
|
retval; \
|
||||||
} else {}
|
} else {}
|
||||||
|
#else
|
||||||
|
#define CHECK_WINDOW_PTR(win)
|
||||||
|
#define CHECK_IMAGE_PTR(img, retval)
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace mlx
|
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)");
|
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;
|
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
|
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
|
void Application::GetScreenSize(Handle win, int* w, int* h) noexcept
|
||||||
{
|
{
|
||||||
CHECK_WINDOW_PTR(win);
|
CHECK_WINDOW_PTR(win);
|
||||||
*w = 0;
|
m_graphics[*static_cast<int*>(win)]->GetWindow()->GetScreenSizeWindowIsOn(x, y);
|
||||||
*h = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::SetFPSCap(std::uint32_t fps) noexcept
|
void Application::SetFPSCap(std::uint32_t fps) noexcept
|
||||||
@@ -96,6 +101,7 @@ namespace mlx
|
|||||||
MLX_PROFILE_FUNCTION();
|
MLX_PROFILE_FUNCTION();
|
||||||
CHECK_WINDOW_PTR(win);
|
CHECK_WINDOW_PTR(win);
|
||||||
m_graphics[*static_cast<int*>(win)].reset();
|
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
|
void Application::PixelPut(Handle win, int x, int y, std::uint32_t color) const noexcept
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
#ifndef __MLX_FORMAT__
|
#ifndef __MLX_FORMAT__
|
||||||
#define __MLX_FORMAT__
|
#define __MLX_FORMAT__
|
||||||
|
|
||||||
#include <type_traits>
|
|
||||||
#include <string_view>
|
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
template<typename T, typename = void>
|
template<typename T, typename = void>
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Core/Format.h>
|
#include <Core/Format.h>
|
||||||
#include <sstream>
|
|
||||||
#include <ostream>
|
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,9 +46,6 @@ namespace mlx
|
|||||||
|
|
||||||
std::uint64_t m_current_depth = 0;
|
std::uint64_t m_current_depth = 0;
|
||||||
|
|
||||||
std::size_t m_width = 0;
|
|
||||||
std::size_t m_height = 0;
|
|
||||||
|
|
||||||
int m_id;
|
int m_id;
|
||||||
|
|
||||||
bool m_has_window;
|
bool m_has_window;
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ namespace mlx
|
|||||||
void GraphicsSupport::StringPut(int x, int y, std::uint32_t color, std::string str)
|
void GraphicsSupport::StringPut(int x, int y, std::uint32_t color, std::string str)
|
||||||
{
|
{
|
||||||
MLX_PROFILE_FUNCTION();
|
MLX_PROFILE_FUNCTION();
|
||||||
|
(void)x;
|
||||||
|
(void)y;
|
||||||
|
(void)color;
|
||||||
|
(void)str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsSupport::TexturePut(NonOwningPtr<Texture> texture, int x, int y)
|
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)
|
void GraphicsSupport::LoadFont(const std::filesystem::path& filepath, float scale)
|
||||||
{
|
{
|
||||||
MLX_PROFILE_FUNCTION();
|
MLX_PROFILE_FUNCTION();
|
||||||
|
(void)filepath;
|
||||||
|
(void)scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsSupport::TryEraseSpritesInScene(NonOwningPtr<Texture> texture) noexcept
|
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);
|
void Assert(bool cond, unsigned int line, std::string_view file, std::string_view function, std::string message, const Args&... args);
|
||||||
#else
|
#else
|
||||||
template<typename... Args>
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ namespace mlx
|
|||||||
VkSurfaceKHR CreateVulkanSurface(Handle window, VkInstance instance) const noexcept;
|
VkSurfaceKHR CreateVulkanSurface(Handle window, VkInstance instance) const noexcept;
|
||||||
std::vector<const char*> GetRequiredVulkanInstanceExtentions(Handle window) const noexcept;
|
std::vector<const char*> GetRequiredVulkanInstanceExtentions(Handle window) const noexcept;
|
||||||
Vec2ui GetVulkanDrawableSize(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; }
|
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 int GetHeight() const noexcept { return m_height; }
|
||||||
inline std::uint32_t GetID() const noexcept { return m_id; }
|
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 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 std::vector<const char*> GetRequiredVulkanInstanceExtentions() const noexcept { return SDLManager::Get().GetRequiredVulkanInstanceExtentions(p_window); }
|
||||||
inline Vec2ui GetVulkanDrawableSize() const noexcept { return SDLManager::Get().GetVulkanDrawableSize(p_window); }
|
inline Vec2ui GetVulkanDrawableSize() const noexcept { return SDLManager::Get().GetVulkanDrawableSize(p_window); }
|
||||||
|
|||||||
@@ -42,6 +42,10 @@
|
|||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <stb_truetype.h>
|
#include <stb_truetype.h>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <string_view>
|
||||||
|
#include <sstream>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
#ifndef MLX_PLAT_WINDOWS
|
#ifndef MLX_PLAT_WINDOWS
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
|||||||
@@ -7,10 +7,14 @@
|
|||||||
|
|
||||||
static void* __mlx_ptr = nullptr;
|
static void* __mlx_ptr = nullptr;
|
||||||
|
|
||||||
|
#ifndef DISABLE_ALL_SAFETIES
|
||||||
#define MLX_CHECK_APPLICATION_POINTER(ptr) \
|
#define MLX_CHECK_APPLICATION_POINTER(ptr) \
|
||||||
if(ptr != __mlx_ptr || ptr == NULL) \
|
if(ptr != __mlx_ptr || ptr == NULL) \
|
||||||
mlx::FatalError("invalid mlx pointer passed to '%'", MLX_FUNC_SIG); \
|
mlx::FatalError("invalid mlx pointer passed to '%'", MLX_FUNC_SIG); \
|
||||||
else {} // just to avoid issues with possible if-else statements outside this macro
|
else {} // just to avoid issues with possible if-else statements outside this macro
|
||||||
|
#else
|
||||||
|
#define MLX_CHECK_APPLICATION_POINTER(ptr)
|
||||||
|
#endif
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ namespace mlx
|
|||||||
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, NonOwningPtr<Texture> render_target, int id) :
|
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, NonOwningPtr<Texture> render_target, int id) :
|
||||||
m_put_pixel_manager(&m_renderer),
|
m_put_pixel_manager(&m_renderer),
|
||||||
p_window(nullptr),
|
p_window(nullptr),
|
||||||
m_width(w),
|
|
||||||
m_height(h),
|
|
||||||
m_id(id),
|
m_id(id),
|
||||||
m_has_window(false)
|
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) :
|
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, std::string title, int id) :
|
||||||
m_put_pixel_manager(&m_renderer),
|
m_put_pixel_manager(&m_renderer),
|
||||||
p_window(std::make_shared<Window>(w, h, title)),
|
p_window(std::make_shared<Window>(w, h, title)),
|
||||||
m_width(w),
|
|
||||||
m_height(h),
|
|
||||||
m_id(id),
|
m_id(id),
|
||||||
m_has_window(true)
|
m_has_window(true)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -159,6 +159,20 @@ namespace mlx
|
|||||||
return Vec2ui{ extent };
|
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
|
std::int32_t SDLManager::GetX() const noexcept
|
||||||
{
|
{
|
||||||
int dummy;
|
int dummy;
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ option("force_wayland")
|
|||||||
add_defines("FORCE_WAYLAND")
|
add_defines("FORCE_WAYLAND")
|
||||||
option_end()
|
option_end()
|
||||||
|
|
||||||
|
option("disable_all_safeties")
|
||||||
|
set_default(false)
|
||||||
|
add_defines("DISABLE_ALL_SAFETIES")
|
||||||
|
option_end()
|
||||||
|
|
||||||
-- Targets
|
-- Targets
|
||||||
|
|
||||||
target("mlx")
|
target("mlx")
|
||||||
@@ -48,6 +53,8 @@ target("mlx")
|
|||||||
add_options("graphics_memory_dump")
|
add_options("graphics_memory_dump")
|
||||||
add_options("profiler")
|
add_options("profiler")
|
||||||
add_options("force_wayland")
|
add_options("force_wayland")
|
||||||
|
add_options("disable_all_safeties")
|
||||||
|
|
||||||
add_includedirs("runtime/Includes", "runtime/Sources", "includes", "third_party")
|
add_includedirs("runtime/Includes", "runtime/Sources", "includes", "third_party")
|
||||||
|
|
||||||
set_pcxxheader("runtime/Includes/PreCompiled.h")
|
set_pcxxheader("runtime/Includes/PreCompiled.h")
|
||||||
|
|||||||
Reference in New Issue
Block a user