mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 07:03:34 +00:00
fixing compatibility, workign on renderer
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
|
||||
/* Updated: 2022/10/05 16:58:11 by maldavid ### ########.fr */
|
||||
/* Updated: 2022/12/18 02:49:45 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace mlx::core
|
||||
while(_in.is_running())
|
||||
{
|
||||
_in.update();
|
||||
if(_loop_hook)
|
||||
_loop_hook(_param);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
|
||||
/* Updated: 2022/10/05 19:23:15 by maldavid ### ########.fr */
|
||||
/* Updated: 2022/12/18 03:45:13 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <functional>
|
||||
|
||||
#include "errors.h"
|
||||
|
||||
@@ -31,26 +32,32 @@ namespace mlx::core
|
||||
|
||||
inline void* new_window(std::size_t w, std::size_t h, std::string title)
|
||||
{
|
||||
_wins.emplace_back(std::make_shared<Window>(w, h, std::move(title), _wins.size()));
|
||||
return reinterpret_cast<void*>(&_wins.back()->get_id());
|
||||
_wins.emplace_back(std::make_shared<MLX_Window>(w, h, std::move(title), _wins.size()));
|
||||
return static_cast<void*>(&_wins.back()->get_id());
|
||||
}
|
||||
|
||||
inline int get_mouse_pos(void* win_ptr, int* x, int* y) noexcept
|
||||
{
|
||||
if(*reinterpret_cast<int*>(win_ptr) > _wins.size())
|
||||
{
|
||||
error::report(e_kind::error, "Invalid window pointer");
|
||||
if(*static_cast<int*>(win_ptr) > _wins.size())
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
inline void loop_hook(int (*f)(void*), void* param) { _loop_hook = f; _param = param; }
|
||||
inline void loop_end() noexcept { _in.finish(); }
|
||||
|
||||
inline void pixel_put(void* win_ptr, int x, int y, int color) const noexcept { _wins[*static_cast<int*>(win_ptr)]->pixel_put(x, y, color); }
|
||||
|
||||
inline void destroy_window(void* win_ptr) { _wins[*static_cast<int*>(win_ptr)].reset(); }
|
||||
|
||||
void run() noexcept;
|
||||
|
||||
~Application() = default;
|
||||
|
||||
private:
|
||||
Input _in;
|
||||
std::vector<std::shared_ptr<Window>> _wins;
|
||||
std::vector<std::shared_ptr<MLX_Window>> _wins;
|
||||
std::function<int(void*)> _loop_hook;
|
||||
void* _param = nullptr;
|
||||
bool _is_loop_running = false;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
|
||||
/* Updated: 2022/10/05 18:45:52 by maldavid ### ########.fr */
|
||||
/* Updated: 2022/12/18 03:42:18 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -17,52 +17,67 @@
|
||||
|
||||
extern "C"
|
||||
{
|
||||
static std::unique_ptr<mlx::core::Application> __main_app = nullptr;
|
||||
|
||||
void mlx_init()
|
||||
void* mlx_init()
|
||||
{
|
||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
|
||||
mlx::core::error::report(e_kind::fatal_error, "Unable to init the SDL2");
|
||||
__main_app.reset(new mlx::core::Application());
|
||||
return new mlx::core::Application();
|
||||
}
|
||||
|
||||
void* mlx_new_window(int w, int h, const char* title)
|
||||
void* mlx_new_window(void* mlx, int w, int h, const char* title)
|
||||
{
|
||||
if(__main_app == nullptr)
|
||||
mlx::core::error::report(e_kind::fatal_error, "You must initialize the mlx before you can create new windows");
|
||||
return __main_app->new_window(w, h, title);
|
||||
return static_cast<mlx::core::Application*>(mlx)->new_window(w, h, title);
|
||||
}
|
||||
|
||||
int mlx_loop()
|
||||
int mlx_loop_hook(void* mlx, int (*f)(void*), void* param)
|
||||
{
|
||||
if(__main_app == nullptr)
|
||||
mlx::core::error::report(e_kind::fatal_error, "You must initialize the mlx before you can run the main loop");
|
||||
__main_app->run();
|
||||
static_cast<mlx::core::Application*>(mlx)->loop_hook(f, param);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_loop(void* mlx)
|
||||
{
|
||||
static_cast<mlx::core::Application*>(mlx)->run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_loop_end(void* mlx)
|
||||
{
|
||||
static_cast<mlx::core::Application*>(mlx)->loop_end();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_mouse_show()
|
||||
{
|
||||
if(__main_app == nullptr)
|
||||
mlx::core::error::report(e_kind::fatal_error, "You must initialize the mlx before you can modify the cursor");
|
||||
return SDL_ShowCursor(SDL_ENABLE);
|
||||
}
|
||||
|
||||
int mlx_mouse_hide()
|
||||
{
|
||||
if(__main_app == nullptr)
|
||||
mlx::core::error::report(e_kind::fatal_error, "You must initialize the mlx before you can modify the cursor");
|
||||
return SDL_ShowCursor(SDL_DISABLE);
|
||||
}
|
||||
|
||||
int mlx_mouse_move(void* win_ptr, int x, int y)
|
||||
{
|
||||
if(__main_app == nullptr)
|
||||
mlx::core::error::report(e_kind::fatal_error, "You must initialize the mlx before you can modify the mouse");
|
||||
}
|
||||
|
||||
int mlx_mouse_get_pos(void* win_ptr, int* x, int* y)
|
||||
{
|
||||
if(__main_app == nullptr)
|
||||
mlx::core::error::report(e_kind::fatal_error, "You must initialize the mlx before you can access to the mouse");
|
||||
}
|
||||
|
||||
int mlx_pixel_put(void* mlx, void* win_ptr, int x, int y, int color)
|
||||
{
|
||||
static_cast<mlx::core::Application*>(mlx)->pixel_put(win_ptr, x, y, color);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_destroy_window(void* mlx, void* win_ptr)
|
||||
{
|
||||
static_cast<mlx::core::Application*>(mlx)->destroy_window(win_ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mlx_destroy_display(void* mlx)
|
||||
{
|
||||
delete static_cast<mlx::core::Application*>(mlx);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,26 +6,35 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 17:48:06 by maldavid #+# #+# */
|
||||
/* Updated: 2022/10/04 21:18:35 by maldavid ### ########.fr */
|
||||
/* Updated: 2022/12/17 23:28:22 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <cstdarg>
|
||||
#include <utility>
|
||||
|
||||
#include "errors.h"
|
||||
|
||||
namespace mlx::core::error
|
||||
{
|
||||
void report(e_kind kind, std::string msg)
|
||||
void report(e_kind kind, std::string msg, ...)
|
||||
{
|
||||
char buffer[1024];
|
||||
|
||||
va_list al;
|
||||
va_start(al, msg);
|
||||
std::vsprintf(buffer, std::move(msg).c_str(), al);
|
||||
va_end(al);
|
||||
|
||||
switch(kind)
|
||||
{
|
||||
case e_kind::message: std::cout << "[MicroLibX] Message : " << msg << std::endl; break;
|
||||
case e_kind::warning: std::cout << "[MicroLibX] Warning : " << msg << std::endl; break;
|
||||
case e_kind::error: std::cerr << "[MicroLibX] Error : " << msg << std::endl; break;
|
||||
case e_kind::message: std::cout << "[MicroLibX] Message : " << buffer << std::endl; break;
|
||||
case e_kind::warning: std::cout << "[MicroLibX] Warning : " << buffer << std::endl; break;
|
||||
case e_kind::error: std::cerr << "[MicroLibX] Error : " << buffer << std::endl; break;
|
||||
case e_kind::fatal_error:
|
||||
std::cerr << "[MicroLibX] Fatal Error : " << msg << std::endl;
|
||||
std::cerr << "[MicroLibX] Fatal Error : " << buffer << std::endl;
|
||||
std::exit(EXIT_SUCCESS);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 17:42:32 by maldavid #+# #+# */
|
||||
/* Updated: 2022/10/04 21:51:42 by maldavid ### ########.fr */
|
||||
/* Updated: 2022/10/08 19:06:41 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -25,7 +25,7 @@ enum class e_kind
|
||||
|
||||
namespace mlx::core::error
|
||||
{
|
||||
void report(e_kind kind, std::string msg);
|
||||
void report(e_kind kind, std::string msg, ...);
|
||||
}
|
||||
|
||||
#endif // __MLX_ERRORS__
|
||||
|
||||
Reference in New Issue
Block a user