mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 15:13:34 +00:00
working on window manager
This commit is contained in:
@@ -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 16:58:25 by maldavid ### ########.fr */
|
||||
/* Updated: 2022/10/05 19:23:15 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "errors.h"
|
||||
|
||||
#include <platform/inputs.h>
|
||||
#include <platform/window.h>
|
||||
|
||||
@@ -25,11 +27,21 @@ namespace mlx::core
|
||||
class Application
|
||||
{
|
||||
public:
|
||||
Application() = default;
|
||||
Application() : _in(_wins) {}
|
||||
|
||||
inline void new_window(std::size_t w, std::size_t h, std::string title)
|
||||
inline void* new_window(std::size_t w, std::size_t h, std::string title)
|
||||
{
|
||||
_wins.emplace_back(std::make_unique<Window>(w, h, std::move(title)));
|
||||
_wins.emplace_back(std::make_shared<Window>(w, h, std::move(title), _wins.size()));
|
||||
return reinterpret_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");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void run() noexcept;
|
||||
@@ -38,7 +50,7 @@ namespace mlx::core
|
||||
|
||||
private:
|
||||
Input _in;
|
||||
std::vector<std::unique_ptr<Window>> _wins;
|
||||
std::vector<std::shared_ptr<Window>> _wins;
|
||||
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 14:02:27 by maldavid ### ########.fr */
|
||||
/* Updated: 2022/10/05 18:45:52 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -26,11 +26,11 @@ extern "C"
|
||||
__main_app.reset(new mlx::core::Application());
|
||||
}
|
||||
|
||||
void mlx_new_window(int w, int h, const char* title)
|
||||
void* mlx_new_window(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");
|
||||
__main_app->new_window(w, h, title);
|
||||
return __main_app->new_window(w, h, title);
|
||||
}
|
||||
|
||||
int mlx_loop()
|
||||
@@ -39,4 +39,30 @@ extern "C"
|
||||
mlx::core::error::report(e_kind::fatal_error, "You must initialize the mlx before you can run the main loop");
|
||||
__main_app->run();
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user