/
d.vision
/
division_engine_cpp
Обзор
Документация
Войти
/
d.vision
/
division_engine_cpp
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
include/division_engine/ffi/ffi.hpp
163 строки
7 KB
den163
Added SDF font support
05 дек 2024, 01:01
05 дек 2024, 01:01
a1df803
Код
Авторство
О чём код?
#pragma once #include "canvas/components/text_bounds.hpp" #include "division_engine/canvas/box_constraints.hpp" #include "division_engine/canvas/components.hpp" #include "division_engine/canvas/components/tags.hpp" #include "division_engine/rect.hpp" #include "division_engine/canvas/rect_drawer.hpp" #include "division_engine/canvas/render_manager.hpp" #include "division_engine/canvas/state.hpp" #include "division_engine_core/types/id.h" #include <flecs.h> #include <stdint.h> namespace { using division_engine::Rect; using namespace division_engine::canvas::components; using namespace division_engine::canvas::components::tags; } struct division_c_renderable_text_t { const char* text; glm::vec4 color; float font_size; }; // NOLINTBEGIN(cppcoreguidelines-macro-usage) #define DIVISION_DECLARE_C_GET_COMPONENT(component_type) \ component_type division_ffi_get_##component_type( \ division_engine::canvas::State* state, uint64_t entity_id \ ) #define DIVISION_DECLARE_C_SET_COMPONENT(component_type) \ void division_ffi_set_##component_type( \ division_engine::canvas::State* state, uint64_t entity_id, component_type component \ ) #define DIVISION_DECLARE_C_GET_SET_COMPONENT(component_type) \ DIVISION_DECLARE_C_GET_COMPONENT(component_type); \ DIVISION_DECLARE_C_SET_COMPONENT(component_type); #define DIVISION_IMPL_C_GET_COMPONENT(component_type) \ DIVISION_DECLARE_C_GET_COMPONENT(component_type) \ { \ return *(flecs::entity { state->world, entity_id }.get<component_type>()); \ } #define DIVISION_IMPL_C_SET_COMPONENT(component_type) \ DIVISION_DECLARE_C_SET_COMPONENT(component_type) \ { \ flecs::entity { state->world, entity_id }.set(component); \ } #define DIVISION_IMPL_C_GET_SET_COMPONENT(component_type) \ DIVISION_IMPL_C_GET_COMPONENT(component_type) \ DIVISION_IMPL_C_SET_COMPONENT(component_type) #define DIVISION_IMPL_C_ADD_REMOVE_TAG(component_type) \ void division_ffi_add_tag_##component_type( \ division_engine::canvas::State* state, uint64_t entity_id \ ) \ { \ flecs::entity { state->world, entity_id }.add<component_type>(flecs::Tag); \ } \ \ void division_ffi_remove_tag_##component_type( \ division_engine::canvas::State* state, uint64_t entity_id \ ) \ { \ flecs::entity { state->world, entity_id }.remove<component_type>(flecs::Tag); \ } extern "C" { uint64_t division_ffi_create_drawable_rect( division_engine::canvas::State* state, division_engine::canvas::RenderManager* render_manager, uint64_t batch_id ); uint64_t division_ffi_create_drawable_text( division_engine::canvas::State* state, division_engine::canvas::RenderManager* render_manager ); uint64_t division_ffi_create_selectable( division_engine::canvas::State* state, division_engine::canvas::RenderManager* render_manager ); bool division_ffi_has_selected_id(division_engine::canvas::State* state) { return state->selected_id.has_value(); } uint64_t division_ffi_get_selected_id(division_engine::canvas::State* state) { return state->selected_id.value(); } uint64_t division_ffi_get_white_texture_batch_id(division_engine::canvas::State* state) { return state->white_texture_batch; } DivisionId division_ffi_create_texture(division_engine::canvas::State* state, const char* texture_path); uint64_t division_ffi_create_texture_batch( division_engine::canvas::State* state, DivisionId texture_id ); void division_ffi_destroy_texture( division_engine::canvas::State* state, DivisionId texture_id ); void division_ffi_destroy_entity(division_engine::canvas::State* state, uint64_t entity_id); DIVISION_IMPL_C_GET_SET_COMPONENT(CollisionRect); DIVISION_IMPL_C_GET_SET_COMPONENT(RenderableRect); DIVISION_IMPL_C_GET_SET_COMPONENT(RenderBounds); DIVISION_IMPL_C_GET_COMPONENT(TextBounds); DIVISION_IMPL_C_ADD_REMOVE_TAG(Selectable); division_c_renderable_text_t division_ffi_get_c_renderable_text(division_engine::canvas::State* state, uint64_t entity_id) { return *flecs::entity { state->world, entity_id }.get<division_c_renderable_text_t>(); } void division_ffi_set_c_renderable_text( division_engine::canvas::State* state, uint64_t entity_id, division_c_renderable_text_t component ) { flecs::entity { state->world, entity_id }.set(RenderableText { std::string { component.text }, component.color, component.font_size, }); } glm::vec2 division_ffi_get_screen_size(division_engine::canvas::State* state) { return state->context.get_screen_size(); } glm::vec2 division_ffi_get_mouse_position(division_engine::canvas::State* state) { return state->context.get_mouse_position(); } bool division_ffi_is_mouse_button_pressed(division_engine::canvas::State* state, int button) { return state->context.is_mouse_button_pressed(button); } } // NOLINTEND(cppcoreguidelines-macro-usage)