new feature, font loading

This commit is contained in:
Kbz-8
2023-11-23 14:37:42 +01:00
parent c125dde951
commit d6b6dd955c
12 changed files with 127 additions and 15 deletions

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
/* Updated: 2023/11/17 11:57:42 by maldavid ### ########.fr */
/* Updated: 2023/11/23 14:25:43 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -56,6 +56,8 @@ namespace mlx::core
inline void loopHook(int (*f)(void*), void* param);
inline void loopEnd() noexcept;
inline void loadFont(void* win, const std::filesystem::path& filepath, float scale);
void run() noexcept;
~Application();

View File

@@ -67,6 +67,11 @@ namespace mlx::core
_graphics[*static_cast<int*>(win)]->stringPut(x, y, color, str);
}
void Application::loadFont(void* win, const std::filesystem::path& filepath, float scale)
{
_graphics[*static_cast<int*>(win)]->loadFont(filepath, scale);
}
void Application::texturePut(void* win, void* img, int x, int y)
{
Texture* texture = static_cast<Texture*>(img);

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
/* Updated: 2023/11/14 11:43:30 by maldavid ### ########.fr */
/* Updated: 2023/11/23 14:32:41 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -27,8 +27,11 @@ extern "C"
return NULL;
}
mlx::Render_Core::get().init();
mlx::core::Application* app = new mlx::core::Application;
if(app == nullptr)
mlx::core::error::report(e_kind::fatal_error, "Tout a pété");
init = true;
return new mlx::core::Application();
return app;
}
void* mlx_new_window(mlx::core::Application* mlx, int w, int h, const char* title)
@@ -169,6 +172,28 @@ extern "C"
return 0;
}
void mlx_set_font(mlx::core::Application* mlx, void* win, char* filepath)
{
std::filesystem::path file(filepath);
if(file.extension() != ".ttf" && file.extension() != ".tte")
{
mlx::core::error::report(e_kind::error, "TTF loader : not a truetype font file '%s'", filepath);
return;
}
mlx->loadFont(win, file, 16.f);
}
void mlx_set_font_scale(mlx::core::Application* mlx, void* win, char* filepath, float scale)
{
std::filesystem::path file(filepath);
if(file.extension() != ".ttf" && file.extension() != ".tte")
{
mlx::core::error::report(e_kind::error, "TTF loader : not a truetype font file '%s'", filepath);
return;
}
mlx->loadFont(win, file, scale);
}
int mlx_clear_window(mlx::core::Application* mlx, void* win)
{
mlx->clearGraphicsSupport(win);

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
/* Updated: 2023/11/14 11:39:55 by maldavid ### ########.fr */
/* Updated: 2023/11/23 14:26:06 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -44,6 +44,7 @@ namespace mlx
inline void pixelPut(int x, int y, uint32_t color) noexcept;
inline void stringPut(int x, int y, int color, std::string str);
inline void texturePut(Texture* texture, int x, int y);
inline void loadFont(const std::filesystem::path& filepath, float scale);
~GraphicsSupport();

View File

@@ -46,4 +46,9 @@ namespace mlx
{
_textures_to_render.emplace(texture, x, y);
}
void GraphicsSupport::loadFont(const std::filesystem::path& filepath, float scale)
{
_text_put_pipeline->loadFont(filepath, scale);
}
}