diff --git a/include/ekg/animation/animation.hpp b/include/ekg/animation/animation.hpp deleted file mode 100644 index 06f90ac3..00000000 --- a/include/ekg/animation/animation.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef EKG_ANIMATION_HPP -#define EKG_ANIMATION_HPP - -#include "ekg/util/geometry.hpp" - -#include - -namespace ekg::animation { - struct list { - protected: - std::vector rect_list {}; - public: - - }; -} - -#endif \ No newline at end of file diff --git a/include/ekg/core/context.hpp b/include/ekg/core/context.hpp index 84dd2d40..aad9aec1 100644 --- a/include/ekg/core/context.hpp +++ b/include/ekg/core/context.hpp @@ -4,6 +4,7 @@ #include "ekg/math/geometry.hpp" namespace ekg { + extern } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/core/oldruntime.hpp b/include/ekg/core/oldruntime.hpp deleted file mode 100644 index e0154ca6..00000000 --- a/include/ekg/core/oldruntime.hpp +++ /dev/null @@ -1,136 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-2024 Rina Wilk / vokegpu@gmail.com - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#ifndef EKG_CORE_H -#define EKG_CORE_H - -#include - -#include "ekg/ui/abstract/ui_abstract_widget.hpp" -#include "ekg/service/handler.hpp" -#include "ekg/draw/font_renderer.hpp" -#include "ekg/service/theme.hpp" -#include "ekg/service/input.hpp" -#include "ekg/util/io.hpp" -#include "ekg/util/gui.hpp" -#include "ekg/gpu/api.hpp" -#include "ekg/layout/docknize.hpp" - -namespace ekg { - extern struct current_hovered_state { - public: - int32_t id {}; - int32_t up {}; - int32_t down {}; - ekg::type type {}; - ekg::type down_type {}; - ekg::type up_type {}; - int32_t swap {}; - int32_t last {}; - } hovered; - - class runtime { - private: - static ekg::stack collect; - static ekg::stack back; - static ekg::stack front; - private: - std::unordered_map widget_map {}; - - std::vector update_widget_list {}; - std::vector loaded_widget_list {}; - std::vector refresh_widget_list {}; - - std::vector reload_widget_list {}; - uint64_t reload_widget_counter {}; - - std::vector synclayout_widget_list {}; - uint64_t synclayout_widget_counter {}; - - ekg::ui::abstract *p_current_ui_container {}; - ekg::ui::abstract_widget *p_abs_activity_widget {}; - ekg::stack *p_current_stack {}; - - int32_t token_id {}; - bool enable_high_priority_frequency {}; - public: - ekg::service::input service_input {}; - ekg::service::theme service_theme {}; - ekg::service::handler service_handler {}; - public: - ekg::draw::font_renderer f_renderer_small {}; - ekg::draw::font_renderer f_renderer_normal {}; - ekg::draw::font_renderer f_renderer_big {}; - - ekg::timing ui_scroll_timing {}; - ekg::timing ui_timing {}; - ekg::os::io_event_serial io_event_serial {}; - - ekg::os::platform *p_os_platform {}; - ekg::gpu::api *p_gpu_api {}; - ekg::gpu::allocator gpu_allocator {}; - - ekg::layout::mask mask {}; - protected: - void prepare_tasks(); - - void prepare_ui_env(); - - void erase(int32_t id); - public: - void set_current_stack(ekg::stack *p_stack); - - ekg::ui::abstract_widget *get_fast_widget_by_id(int32_t id); - - void gen_widget(ekg::ui::abstract *p_ui); - - void do_task_reload(ekg::ui::abstract_widget *widget); - - void do_task_synclayout(ekg::ui::abstract_widget *widget); - - void do_task_refresh(ekg::ui::abstract_widget *widget); - - void set_update_high_frequency(ekg::ui::abstract_widget *widget); - - bool has_bind_group_flag(); - - void end_group_flag(); - - void end_group_parent_flag(); - - void update_size_changed(); - - void init(); - - void quit(); - - void process_event(); - - void process_update(); - - void process_render(); - }; -}; - -#endif \ No newline at end of file diff --git a/include/ekg/core/runtime.hpp b/include/ekg/core/runtime.hpp index 627eff52..c7e1379b 100644 --- a/include/ekg/core/runtime.hpp +++ b/include/ekg/core/runtime.hpp @@ -75,6 +75,14 @@ namespace ekg { void render(); void poll_events(); }; + + struct runtime_property_t { + public: + std::string font_path {}; + std::string font_path_emoji {}; + ekg::gpu::api *p_gpu_api {}; + ekg::os::platform *p_os_platform {}; + }; } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/draw/draw.hpp b/include/ekg/draw/draw.hpp index cacd3fc3..0238fcc9 100644 --- a/include/ekg/draw/draw.hpp +++ b/include/ekg/draw/draw.hpp @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef EKG_DRAW_H -#define EKG_DRAW_H +#ifndef EKG_DRAW_HPP +#define EKG_DRAW_HPP #include #include @@ -83,4 +83,4 @@ namespace ekg::draw { void disable_high_priority(); } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/draw/font_renderer.hpp b/include/ekg/draw/font_renderer.hpp index 01498210..9cc2e86b 100644 --- a/include/ekg/draw/font_renderer.hpp +++ b/include/ekg/draw/font_renderer.hpp @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef EKG_DRAW_FONT_RENDERER_H -#define EKG_DRAW_FONT_RENDERER_H +#ifndef EKG_DRAW_FONT_RENDERER_HPP +#define EKG_DRAW_FONT_RENDERER_HPP #include @@ -64,12 +64,6 @@ if (!char_data.was_sampled) { \ #define ekg_generate_factor_hash(axis, c32, char_data_x) static_cast(axis + c32 + char_data_x * 100) namespace ekg::draw { - enum font_face_type { - text, - emojis, - kanjis - }; - class font_renderer { public: static FT_Library ft_library; @@ -160,6 +154,8 @@ namespace ekg::draw { **/ void flush(); }; + + } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/ekg.hpp b/include/ekg/ekg.hpp index 0294be2d..767dd6e3 100644 --- a/include/ekg/ekg.hpp +++ b/include/ekg/ekg.hpp @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef EKG_H -#define EKG_H +#ifndef EKG_HPP +#define EKG_HPP #pragma STDC FENV_ACCESS ON @@ -57,19 +57,10 @@ namespace ekg { /** * The runtime core of ekg. */ - extern ekg::runtime *core; - extern bool running; + extern ekg::runtime *p_core; /** The setup and handling functions of ekg **/ - struct runtime_property { - public: - const char *p_font_path {""}; - const char *p_font_path_emoji {""}; - ekg::gpu::api *p_gpu_api {}; - ekg::os::platform *p_os_platform {}; - }; - /** * The initialization of EKG, * initialize `ekg::runtime_property` correct before calling this. diff --git a/include/ekg/gpu/allocator.hpp b/include/ekg/gpu/allocator.hpp index 8f4854e6..c2f2b1db 100644 --- a/include/ekg/gpu/allocator.hpp +++ b/include/ekg/gpu/allocator.hpp @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef EKG_GPU_ALLOCATOR_H -#define EKG_GPU_ALLOCATOR_H +#ifndef EKG_GPU_ALLOCATOR_HPP +#define EKG_GPU_ALLOCATOR_HPP #include #include @@ -152,4 +152,4 @@ namespace ekg::gpu { }; } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/gpu/api.hpp b/include/ekg/gpu/api.hpp index dfd6f503..bfae04ed 100644 --- a/include/ekg/gpu/api.hpp +++ b/include/ekg/gpu/api.hpp @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef EKG_GPU_BASE_IMPL_H -#define EKG_GPU_BASE_IMPL_H +#ifndef EKG_GPU_BASE_IMPL_HPP +#define EKG_GPU_BASE_IMPL_HPP #include #include @@ -94,4 +94,4 @@ namespace ekg::gpu { }; } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/gpu/opengl_pipeline_template.hpp b/include/ekg/gpu/opengl_pipeline_template.hpp index cf0f9ce7..9d675f93 100644 --- a/include/ekg/gpu/opengl_pipeline_template.hpp +++ b/include/ekg/gpu/opengl_pipeline_template.hpp @@ -17,4 +17,4 @@ namespace ekg::gpu { ); } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/io/text.hpp b/include/ekg/io/text.hpp new file mode 100644 index 00000000..166df454 --- /dev/null +++ b/include/ekg/io/text.hpp @@ -0,0 +1,107 @@ +/** + * MIT License + * + * Copyright (c) 2022-2024 Rina Wilk / vokegpu@gmail.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef EKG_UTIL_TEXT_HPP +#define EKG_UTIL_TEXT_HPP + +#include +#include +#include + +namespace ekg { + /** + * Returns a UTF string by `char32` converting + * the UTF-32 unique char into a sequence of UTF-8 + * chars. + */ + std::string utf_char32_to_string(char32_t char32); + + /** + * Returns a string subtracted by stride begin `offset` + * and end index `size`. If string is empty, return + * empty. + */ + std::string utf_substr(std::string_view string, uint64_t offset, uint64_t size); + + /** + * Returns the `string` length considering UTF chars. + */ + uint64_t utf_length(std::string_view string); + + /** + * Returns index size that represent an UTF-8 char. + * Possibles: + * 3, 2, 1, and 0. + */ + uint64_t utf_check_sequence( + uint8_t &char8, + char32_t &char32, + std::string &utf_string, + std::string_view string, + uint64_t index + ); + + /** + * Returns a UTF-32 char32 based on UTF-8 sequence. + */ + char32_t utf_string_to_char32(std::string_view string); + + /** + * Fast splitter specialized in `\n` or `\r\n` (non OS unix-based). + * UTF to sinalize the string unicode-like suggested by EKG. + */ + void utf_decode(std::string_view string, std::vector &utf_decoded); + + /** + * Returns a customised float64 precision as a string. + **/ + std::string string_float64_precision(double number, int32_t precision); + + /** + * Returns a customised float precision as a string. + **/ + std::string string_float_precision(float number, int32_t precision); + + /** + * Return the index of last attribute-token and insert bits. + */ + uint8_t check_attribute_flags(std::string_view text, ekg::flags &flags); + + /** + * Return true if `string` contains `find_char`, + * then it must allocate and insert elements to + * `p_string_split_list` ptr. + */ + bool split(std::vector *p_string_split_list, const std::string &string, char find_char); +} + +namespace ekg::io { + enum font_face_type { + text, + emojis, + kanjis + }; +} + +#endif diff --git a/include/ekg/draw/typography.hpp b/include/ekg/io/typography.hpp similarity index 88% rename from include/ekg/draw/typography.hpp rename to include/ekg/io/typography.hpp index 9181c31d..3004c0bb 100644 --- a/include/ekg/draw/typography.hpp +++ b/include/ekg/io/typography.hpp @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef EKG_DRAW_TYPOGRAPHY_H -#define EKG_DRAW_TYPOGRAPHY_H +#ifndef EKG_IO_TYPOGRAPHY_HPP +#define EKG_IO_TYPOGRAPHY_HPP #include #include FT_FREETYPE_H @@ -31,7 +31,7 @@ // TODO: ref all and make like a diff way -namespace ekg::draw { +namespace ekg::io { struct glyph_char_t { public: float x {}; @@ -53,12 +53,6 @@ namespace ekg::draw { bool was_loaded {}; FT_Vector highest_glyph_size {}; }; - - ekg::flags_t reload_font_face( - ekg::draw::font_face_t *p_font_face, - bool was_size_changed, - uint32_t font_size - ); } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/layout/docknize.hpp b/include/ekg/layout/docknize.hpp index 4fb7fa9b..87256320 100644 --- a/include/ekg/layout/docknize.hpp +++ b/include/ekg/layout/docknize.hpp @@ -1,5 +1,5 @@ -#ifndef EKG_LAYOUT_DOCKNIZE_H -#define EKG_LAYOUT_DOCKNIZE_H +#ifndef EKG_LAYOUT_DOCKNIZE_HPP +#define EKG_LAYOUT_DOCKNIZE_HPP #include "ekg/ui/abstract.hpp" #include "ekg/math/geometry.hpp" diff --git a/include/ekg/layout/scale.hpp b/include/ekg/layout/scale.hpp index b6f220de..686fe120 100644 --- a/include/ekg/layout/scale.hpp +++ b/include/ekg/layout/scale.hpp @@ -1,9 +1,9 @@ -#ifndef EKG_LAYOUT_SCALE_H -#define EKG_LAYOUT_SCALE_H +#ifndef EKG_LAYOUT_SCALE_HPP +#define EKG_LAYOUT_SCALE_HPP namespace ekg::layout { extern float scale_factor; void scale_calculate(); }; -#endif \ No newline at end of file +#endif diff --git a/include/ekg/os/ekg_glfw.hpp b/include/ekg/os/ekg_glfw.hpp index e93fbac8..84fb3abe 100644 --- a/include/ekg/os/ekg_glfw.hpp +++ b/include/ekg/os/ekg_glfw.hpp @@ -1,5 +1,5 @@ -#ifndef EKG_OS_GLFW_H -#define EKG_OS_GLFW_H +#ifndef EKG_OS_GLFW_HPP +#define EKG_OS_GLFW_HPP #include "platform.hpp" @@ -9,32 +9,62 @@ #include #endif -namespace ekg::os { +namespace ekg { class glfw : public ekg::os::platform { protected: GLFWcursor *loaded_system_cursor_list[12] {}; GLFWwindow *p_glfw_win {}; public: - explicit glfw(GLFWwindow *p_glfw_win); + ekg::flags_t modes {}; + public: + explicit glfw( + GLFWwindow *p_glfw_win, + ekg::flags_t modes = static_cast(0) + ); public: void init() override; void quit() override; void update_monitor_resolution() override; - void update_cursor(ekg::system_cursor system_cursor) override; - void get_key_name(io_key &key, std::string &name) override; - void get_special_key(io_key &key, ekg::special_key &special_key) override; + void update_cursor(ekg::system_cursor_type system_cursor) override; + void get_key_name(ekg::io::input_key_t &key, std::string &name) override; + void get_special_key(ekg::io::input_key_t &key, ekg::special_key_type &special_key) override; const char *get_clipboard_text() override; void set_clipboard_text(const char *p_text) override; bool has_clipboard_text() override; uint64_t get_ticks() override; }; - void glfw_window_size_callback(int32_t w, int32_t h); - void glfw_char_callback(uint32_t codepoint); - void glfw_key_callback(int32_t key, int32_t scancode, int32_t action, int32_t mods); - void glfw_cursor_pos_callback(double x, double y); - void glfw_scroll_callback(double dx, double dy); - void glfw_mouse_button_callback(int32_t button, int32_t action, int32_t mods); + void glfw_window_size_callback( + int32_t w, + int32_t h + ); + + void glfw_char_callback( + uint32_t codepoint + ); + + void glfw_key_callback( + int32_t key, + int32_t scancode, + int32_t action, + int32_t mods + ); + + void glfw_cursor_pos_callback( + double x, + double y + ); + + void glfw_scroll_callback( + double dx, + double dy + ); + + void glfw_mouse_button_callback( + int32_t button, + int32_t action, + int32_t mods + ); } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/os/ekg_opengl.hpp b/include/ekg/os/ekg_opengl.hpp index 06885aff..f9507e8e 100644 --- a/include/ekg/os/ekg_opengl.hpp +++ b/include/ekg/os/ekg_opengl.hpp @@ -26,8 +26,8 @@ // TODO: remove useless macros // TODO: add some comments if necessary -#ifndef EKG_OS_OPENGL_H -#define EKG_OS_OPENGL_H +#ifndef EKG_OS_OPENGL_HPP +#define EKG_OS_OPENGL_HPP #if defined(__ANDROID__) #include @@ -126,4 +126,4 @@ namespace ekg { }; } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/os/ekg_sdl.hpp b/include/ekg/os/ekg_sdl.hpp index dff528f0..832f9714 100644 --- a/include/ekg/os/ekg_sdl.hpp +++ b/include/ekg/os/ekg_sdl.hpp @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef EKG_OS_SDL_H -#define EKG_OS_SDL_H +#ifndef EKG_OS_SDL_HPP +#define EKG_OS_SDL_HPP #if defined(__ANDROID__) #include "SDL.h" @@ -61,4 +61,4 @@ namespace ekg { void sdl_poll_event(SDL_Event &sdl_event); } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/os/ekg_vulkan.hpp b/include/ekg/os/ekg_vulkan.hpp index 7968d944..abc3ce5b 100644 --- a/include/ekg/os/ekg_vulkan.hpp +++ b/include/ekg/os/ekg_vulkan.hpp @@ -22,16 +22,16 @@ * SOFTWARE. */ -#ifndef EKG_OS_VULKAN_H -#define EKG_OS_VULKAN_H +#ifndef EKG_OS_VULKAN_HPP +#define EKG_OS_VULKAN_HPP #include "ekg/gpu/api.hpp" -namespace ekg::os { +namespace ekg { class vulkan : public ekg::gpu::api { protected: // VkDescriptorPool *p_descriptor_pool {}; }; } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/os/ekg_wayland_server.hpp b/include/ekg/os/ekg_wayland_server.hpp index 1b63ed5d..01a26418 100644 --- a/include/ekg/os/ekg_wayland_server.hpp +++ b/include/ekg/os/ekg_wayland_server.hpp @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef EKG_OS_WAYLAND_SERVER_H -#define EKG_OS_WAYLAND_SERVER_H +#ifndef EKG_OS_WAYLAND_SERVER_HPP +#define EKG_OS_WAYLAND_SERVER_HPP #include "platform.hpp" @@ -31,4 +31,4 @@ namespace ekg { class wayland_server : public ekg::os::platform {}; } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/os/platform.hpp b/include/ekg/os/platform.hpp index 3ef3e7fb..c8d2c322 100644 --- a/include/ekg/os/platform.hpp +++ b/include/ekg/os/platform.hpp @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef EKG_OS_PLATFORM_H -#define EKG_OS_PLATFORM_H +#ifndef EKG_OS_PLATFORM_HPP +#define EKG_OS_PLATFORM_HPP #include "ekg/io/input.hpp" #include "ekg/math/geometry.hpp" @@ -48,4 +48,4 @@ namespace ekg::os { }; } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/service/handler.hpp b/include/ekg/service/handler.hpp index d4026326..1a12ffd2 100644 --- a/include/ekg/service/handler.hpp +++ b/include/ekg/service/handler.hpp @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef EKG_SERVICE_HANDLER_H -#define EKG_SERVICE_HANDLER_H +#ifndef EKG_SERVICE_HANDLER_HPP +#define EKG_SERVICE_HANDLER_HPP #include #include @@ -50,4 +50,4 @@ namespace ekg::service { }; } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/service/input.hpp b/include/ekg/service/input.hpp index 1f220e2d..bb68f3e6 100644 --- a/include/ekg/service/input.hpp +++ b/include/ekg/service/input.hpp @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef EKG_SERVICE_INPUT_H -#define EKG_SERVICE_INPUT_H +#ifndef EKG_SERVICE_INPUT_HPP +#define EKG_SERVICE_INPUT_HPP #include #include @@ -109,4 +109,4 @@ namespace ekg::service { }; } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/service/theme.hpp b/include/ekg/service/theme.hpp index 97c58407..df5dc5f4 100644 --- a/include/ekg/service/theme.hpp +++ b/include/ekg/service/theme.hpp @@ -23,8 +23,8 @@ * SOFTWARE. */ -#ifndef EKG_SERVICE_THEME_H -#define EKG_SERVICE_THEME_H +#ifndef EKG_SERVICE_THEME_HPP +#define EKG_SERVICE_THEME_HPP #include #include diff --git a/include/ekg/ui/display.hpp b/include/ekg/ui/display.hpp index f0c46f1f..5810b521 100644 --- a/include/ekg/ui/display.hpp +++ b/include/ekg/ui/display.hpp @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef EKG_UI_DISPLAY_H -#define EKG_UI_DISPLAY_H +#ifndef EKG_UI_DISPLAY_HPP +#define EKG_UI_DISPLAY_HPP #include "ekg/util/geometry.hpp" @@ -116,4 +116,4 @@ namespace ekg::ui { extern bool redraw; } -#endif \ No newline at end of file +#endif diff --git a/include/ekg/util/text.hpp b/include/ekg/util/text.hpp index a6e27504..a989535c 100644 --- a/include/ekg/util/text.hpp +++ b/include/ekg/util/text.hpp @@ -22,8 +22,8 @@ * SOFTWARE. */ -#ifndef EKG_UTIL_TEXT_H -#define EKG_UTIL_TEXT_H +#ifndef EKG_UTIL_TEXT_HPP +#define EKG_UTIL_TEXT_HPP #include #include @@ -98,4 +98,4 @@ namespace ekg { bool split(std::vector *p_string_split_list, const std::string &string, char find_char); } -#endif \ No newline at end of file +#endif diff --git a/src/core/oldruntime.cpp b/src/core/oldruntime.cpp deleted file mode 100644 index 298ec194..00000000 --- a/src/core/oldruntime.cpp +++ /dev/null @@ -1,826 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2022-2024 Rina Wilk / vokegpu@gmail.com - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include -#include - -#include "ekg/core/runtime.hpp" -#include "ekg/core/user_input_register.hpp" -#include "ekg/ui/abstract/ui_abstract_widget.hpp" -#include "ekg/ui/display.hpp" -#include "ekg/ui/frame/ui_frame.hpp" -#include "ekg/ui/frame/ui_frame_widget.hpp" -#include "ekg/ui/button/ui_button_widget.hpp" -#include "ekg/ui/label/ui_label_widget.hpp" -#include "ekg/ui/checkbox/ui_checkbox_widget.hpp" -#include "ekg/ui/slider/ui_slider_widget.hpp" -#include "ekg/ui/popup/ui_popup_widget.hpp" -#include "ekg/ui/textbox/ui_textbox_widget.hpp" -#include "ekg/ui/listbox/ui_listbox_widget.hpp" -#include "ekg/ui/scrollbar/ui_scrollbar_widget.hpp" -#include "ekg/ui/scrollbar/ui_scrollbar.hpp" -#include "ekg/draw/draw.hpp" -#include "ekg/ekg.hpp" -#include "ekg/util/gui.hpp" -#include "ekg/layout/scale.hpp" - -ekg::stack ekg::runtime::collect {}; -ekg::stack ekg::runtime::back {}; -ekg::stack ekg::runtime::front {}; - -ekg::current_hovered_state ekg::hovered {}; - -void ekg::runtime::update_size_changed() { - ekg::log() << "Refreshing layout and font sizes!"; - ekg::layout::scale_calculate(); - - uint32_t font_size { - static_cast(ekg_clamp(static_cast(18.0f * ekg::layout::scale_factor), 0, 256)) - }; - - if (this->f_renderer_normal.font_size != font_size) { - this->f_renderer_small.set_size(EKG_FONT_SMALL_SIZE(font_size)); - this->f_renderer_normal.set_size(EKG_FONT_NORMAL_SIZE(font_size)); - this->f_renderer_big.set_size(EKG_FONT_BIG_SIZE(font_size)); - } - - for (ekg::ui::abstract_widget *&p_widgets: this->loaded_widget_list) { - p_widgets->on_reload(); - if (!p_widgets->p_data->has_parent() && p_widgets->p_data->has_children()) { - this->do_task_synclayout(p_widgets); - } - } - - ekg::dispatch(ekg::env::redraw); -} - -void ekg::runtime::init() { - this->gpu_allocator.init(); - this->prepare_tasks(); - this->prepare_ui_env(); - this->service_theme.init(); - this->service_input.init(); -} - -void ekg::runtime::quit() { - this->gpu_allocator.quit(); -} - -void ekg::runtime::process_event() { - this->service_input.on_event(this->io_event_serial); - - bool pressed {ekg::input::pressed()}; - bool released {ekg::input::released()}; - bool motion {ekg::input::motion()}; - bool is_on_scrolling_timeout {!ekg::reach(this->ui_scroll_timing, 250)}; - - ekg::hovered.id *= !(pressed || released || motion); - - if ( - this->p_abs_activity_widget != nullptr && - (this->p_abs_activity_widget->flag.absolute || is_on_scrolling_timeout) - ) { - - this->p_abs_activity_widget->on_pre_event(this->io_event_serial); - this->p_abs_activity_widget->on_event(this->io_event_serial); - - if (this->p_abs_activity_widget->flag.scrolling) { - ekg::reset(this->ui_scroll_timing); - } - - this->p_abs_activity_widget->on_post_event(this->io_event_serial); - return; - } - - if (is_on_scrolling_timeout) { - return; - } - - this->p_abs_activity_widget = nullptr; - - bool hovered {}; - bool first_absolute {}; - - ekg::ui::abstract_widget *p_widget_focused {}; - - for (ekg::ui::abstract_widget *&p_widgets: this->loaded_widget_list) { - if (p_widgets == nullptr || !p_widgets->p_data->is_alive()) { - continue; - } - - p_widgets->on_pre_event(this->io_event_serial); - - /** - * Text input like textbox and keyboard events should not update stack, instead just mouse events. - **/ - hovered = ( - !( - this->io_event_serial.event_type == ekg::platform_event_type::key_down || - this->io_event_serial.event_type == ekg::platform_event_type::key_up || - this->io_event_serial.event_type == ekg::platform_event_type::text_input - ) - && p_widgets->flag.hovered - && p_widgets->p_data->is_visible() - && p_widgets->p_data->get_state() != ekg::state::disable - ); - - if (hovered) { - p_widget_focused != nullptr && (p_widget_focused->flag.was_hovered = false); - ekg::hovered.id = p_widgets->p_data->get_id(); - p_widget_focused = p_widgets; - first_absolute = false; - } - - /** - * The absolute/top-level system check for the first absolute fired widget, - * everytime a widget is hovered then reset again the checking state. - * - * The order of scrollable widgets like scroll widget is not sequentially, - * e.g, the mouse is hovering some children of frame 2 and absolute widget scroll from frame 2 is fired: - * - * frame 1 // hovered, check for the first absolute - * - * frame 2 (frame 1) // hovered, then reset and find for the first absolute again - * widgets... // hovering some of children widgets, then reset over again - * scroll (frame 2) // found the first absolute, target it - * - * frame 3 (frame 1) // not hovering, then does not reset any absolute checking - * ... - * - * scroll (frame 1) // do not target this fired absolute widget. - * end of e.g. - **/ - if (p_widgets->flag.absolute && !first_absolute) { - p_widget_focused = p_widgets; - first_absolute = true; - } - - p_widgets->on_post_event(this->io_event_serial); - if (!hovered && !p_widgets->flag.absolute) { - p_widgets->flag.was_hovered = false; - p_widgets->on_event(this->io_event_serial); - } - } - - ekg::hovered.type = ekg::type::abstract; - - if (p_widget_focused != nullptr) { - p_widget_focused->on_pre_event(this->io_event_serial); - p_widget_focused->on_event(this->io_event_serial); - p_widget_focused->on_post_event(this->io_event_serial); - - if (p_widget_focused->flag.absolute) { - this->p_abs_activity_widget = p_widget_focused; - } - - ekg::hovered.type = p_widget_focused->p_data->get_type(); - } - - if (pressed) { - ekg::hovered.down = ekg::hovered.id; - ekg::hovered.down_type = p_widget_focused != nullptr ? p_widget_focused->p_data->get_type() : ekg::type::abstract; - } else if (released) { - ekg::hovered.up = ekg::hovered.id; - ekg::hovered.down_type = p_widget_focused != nullptr ? p_widget_focused->p_data->get_type() : ekg::type::abstract; - } - - if ( - ekg::hovered.last != ekg::hovered.id && - ekg::hovered.id != 0 && - (pressed || released) - ) { - - ekg::hovered.swap = ekg::hovered.id; - ekg::hovered.last = ekg::hovered.id; - - ekg::dispatch(ekg::env::swap); - ekg::dispatch(ekg::env::redraw); - } -} - -void ekg::runtime::process_update() { - ekg::timing::ticks = this->p_os_platform->get_ticks(); - ekg::reach(this->ui_timing, 1000) && ekg::reset(this->ui_timing); - ekg::timing::second = this->ui_timing.current_ticks; - - this->service_input.on_update(); - - if (!this->update_widget_list.empty()) { - uint64_t size {}; - for (uint64_t it {}; it < (size = this->update_widget_list.size()); it++) { - if (it >= size) { - break; - } - - ekg::ui::abstract_widget *&p_widgets {this->update_widget_list.at(it)}; - p_widgets->on_update(); - - if (!p_widgets->is_high_frequency) { - this->update_widget_list.erase( - this->update_widget_list.begin() + it - ); - } - } - } - - this->service_handler.on_update(); - ekg::log::flush(); -} - -void ekg::runtime::process_render() { - if (ekg::ui::redraw) { - ekg::ui::redraw = false; - - /** - * The allocator starts here, the GPU data instance - * and geometry resources are clear/reseted here. - **/ - this->gpu_allocator.invoke(); - - for (ekg::ui::abstract_widget *&p_widgets : this->loaded_widget_list) { - if (p_widgets != nullptr && p_widgets->p_data->is_alive() && p_widgets->p_data->is_visible()) { - /** - * Each time this statement is called, one GPU data is - * allocated/filled. - * - * The order of rendering depends on which are functions are invoked first. - * - * E.g: - * gpu-data-group-1 (on_draw_refresh()) - * gpu-data-group-2 - * gpu-data-group-3 - * - * `gpu-data-group-3` is always hovering all the previous GPU data groups. - **/ - p_widgets->on_draw_refresh(); - } - } - - /** - * The allocator does not need to be called all the time, - * cause it is require more CPU-side calls and GPU-communication/synchronization. - * - * The use of the word "revoke" means that the `invoked signal` ended with a - * possible `revoke`, i.e all the generated/populated/filled GPU-data is processed and - * converted to a geometry GPU-buffer. Removing all the unnecessary GPU-data. - **/ - this->gpu_allocator.revoke(); - } - - /** - * The allocator renderize an serialized GPU data-list. - * With some conditions: - * - * 1- A concave shape does not have a rectangle form, and can render text(s) and - * batched quad(s) at once. - * 2- A convex shape have a unique form: rectangle. - * - * The convex form is rendered one per one draw call. It is stupid I know, but with this is possible add cool effects. - * While concave have the possibility of rendering a lot of shapes at once, is not viable to add many custom effects. - * - * The native GPU API calls are apart from allocator, depends on current GPU API selected. - * Rendering-hardware interface also known as RHI implements different each GPU API. - * OpenGL 3/4/ES 3, Vulkan, MoltenVK, DirectX11/12. - * May differ the features or runtime. - * - * But check all allocator comments. - **/ - this->gpu_allocator.draw(); -} - -void ekg::runtime::prepare_tasks() { - ekg::log() << "Preparing internal EKG core"; - - this->service_handler.allocate() = new ekg::task { - .info = { - .tag = "refresh", - .p_data = nullptr - }, - .function = [this](ekg::info &info) { - bool should_call_gc {}; - - for (ekg::ui::abstract_widget *&p_widgets : this->refresh_widget_list) { - if (p_widgets == nullptr || !p_widgets->was_refreshed) { - continue; - } - - p_widgets->was_refreshed = false; - - if (p_widgets == nullptr || !p_widgets->p_data->is_alive()) { - should_call_gc = true; - continue; - } - - this->loaded_widget_list.push_back(p_widgets); - } - - this->refresh_widget_list.clear(); - - if (should_call_gc) { - ekg::dispatch(ekg::env::gc); - } - } - }; - - this->service_handler.allocate() = new ekg::task { - .info = { - .tag = "swap", - .p_data = nullptr - }, - .function = [this](ekg::info &info) { - if (!ekg::hovered.swap) { - return; - } - - ekg::runtime::collect.target_id = ekg::hovered.swap; - - for (ekg::ui::abstract_widget *&p_widgets: this->loaded_widget_list) { - if (p_widgets == nullptr || p_widgets->p_data->has_parent()) { - continue; - } - - ekg::runtime::collect.clear(); - ekg::push_back_stack(p_widgets, ekg::runtime::collect); - - if (ekg::runtime::collect.target_id_found) { - ekg::runtime::front.ordered_list.insert( - ekg::runtime::front.ordered_list.end(), - ekg::runtime::collect.ordered_list.begin(), - ekg::runtime::collect.ordered_list.end() - ); - } else { - ekg::runtime::back.ordered_list.insert( - ekg::runtime::back.ordered_list.end(), - ekg::runtime::collect.ordered_list.begin(), - ekg::runtime::collect.ordered_list.end() - ); - } - } - - ekg::hovered.swap = 0; - - std::copy( - ekg::runtime::back.ordered_list.begin(), - ekg::runtime::back.ordered_list.end(), - this->loaded_widget_list.begin() - ); - - std::copy( - ekg::runtime::front.ordered_list.begin(), - ekg::runtime::front.ordered_list.end(), - this->loaded_widget_list.begin() + ekg::runtime::back.ordered_list.size() - ); - - ekg::runtime::front.clear(); - ekg::runtime::back.clear(); - ekg::runtime::collect.clear(); - - // idk may i idk - } - }; - - this->service_handler.allocate() = new ekg::task { - .info = { - .tag = "reload", - .p_data = nullptr - }, - .function = [this](ekg::info &info) { - bool must_set_x {}; - bool must_set_y {}; - bool has_parent {}; - - for (uint64_t it {}; it < this->reload_widget_counter; it++) { - ekg::ui::abstract_widget *&p_widgets { - this->reload_widget_list.at(it) - }; - - if (p_widgets == nullptr || !p_widgets->was_reloaded) { - continue; - } - - p_widgets->was_reloaded = false; - ekg::flags &sync_flags {p_widgets->p_data->get_sync()}; - - if (ekg_bitwise_contains(sync_flags, static_cast(ekg::ui_sync::dimension))) { - ekg_bitwise_remove(sync_flags, static_cast(ekg::ui_sync::dimension)); - - ekg::rect &rect {p_widgets->p_data->ui()}; - switch (p_widgets->p_data->get_level()) { - case ekg::level::top_level: { - if (ekg_bitwise_contains(sync_flags, static_cast(ekg::ui_sync::set_width))) { - ekg_bitwise_remove(sync_flags, static_cast(ekg::ui_sync::set_width)); - p_widgets->dimension.w = rect.w; - } - - if (ekg_bitwise_contains(sync_flags, static_cast(ekg::ui_sync::set_x))) { - ekg_bitwise_remove(sync_flags, static_cast(ekg::ui_sync::set_x)); - p_widgets->p_parent->x = rect.x; - } - - if (ekg_bitwise_contains(sync_flags, static_cast(ekg::ui_sync::set_y))) { - ekg_bitwise_remove(sync_flags, static_cast(ekg::ui_sync::set_y)); - p_widgets->p_parent->x = rect.y; - } - - break; - } - - default: { - if (ekg_bitwise_contains(sync_flags, static_cast(ekg::ui_sync::set_width))) { - ekg_bitwise_remove(sync_flags, static_cast(ekg::ui_sync::set_width)); - p_widgets->dimension.w = rect.w; - } - - if (ekg_bitwise_contains(sync_flags, static_cast(ekg::ui_sync::set_height))) { - ekg_bitwise_remove(sync_flags, static_cast(ekg::ui_sync::set_height)); - p_widgets->dimension.h = rect.h; - } - - must_set_x = ( - static_cast( - ekg_bitwise_contains(sync_flags, static_cast(ekg::ui_sync::set_x)) - ) - ); - - must_set_y = ( - static_cast( - ekg_bitwise_contains(sync_flags, static_cast(ekg::ui_sync::set_y)) - ) - ); - - has_parent = p_widgets->p_data->has_parent(); - - if (must_set_x && has_parent) { - p_widgets->dimension.x = rect.x - p_widgets->p_parent->x; - } else if (must_set_x) { - p_widgets->p_parent->x = rect.x; - } - - if (must_set_y && has_parent) { - p_widgets->dimension.y = rect.y - p_widgets->p_parent->y; - } else if (must_set_y) { - p_widgets->p_parent->y = rect.y; - } - - break; - } - } - } - - p_widgets->on_reload(); - } - - this->reload_widget_counter = 0; - } - }; - - this->service_handler.allocate() = new ekg::task { - .info = { - .tag = "synclayout", - .p_data = nullptr - }, - .function = [this](ekg::info &info) { - for (uint64_t it {}; it < this->synclayout_widget_counter; it++) { - ekg::ui::abstract_widget *& p_widgets { - this->synclayout_widget_list.at(it) - }; - - if (p_widgets == nullptr || !p_widgets->was_syncedlayout) { - continue; - } - - p_widgets->was_syncedlayout = false; - ekg::layout::docknize(p_widgets); - } - - this->synclayout_widget_counter = 0; - ekg::dispatch(ekg::env::redraw); - } - }; - - this->service_handler.allocate() = new ekg::task { - .info = { - .tag = "gc", - .p_data = nullptr, - }, - .function = [this](ekg::info &info) { - this->update_widget_list.clear(); - std::vector new_list {}; - int32_t element_id {}; - - for (ekg::ui::abstract_widget *&p_widgets: this->loaded_widget_list) { - if (p_widgets == nullptr || p_widgets->p_data == nullptr) { - continue; - } - - if (!p_widgets->p_data->is_alive()) { - element_id = p_widgets->p_data->get_id(); - - /** - * Reset the hovered states if the current being deleted is hovered. - **/ - ekg::hovered.id *= ekg::hovered.id != element_id; - ekg::hovered.up *= ekg::hovered.up != element_id; - ekg::hovered.down *= ekg::hovered.down != element_id; - - delete p_widgets->p_data; - delete p_widgets; - - continue; - } - - if (p_widgets->is_high_frequency) { - this->update_widget_list.push_back(p_widgets); - } - - new_list.push_back(p_widgets); - } - - this->loaded_widget_list = new_list; - } - }; -} - -void ekg::runtime::set_current_stack(ekg::stack *p_stack) { - this->p_current_stack = p_stack; -} - -ekg::ui::abstract_widget *ekg::runtime::get_fast_widget_by_id(int32_t id) { - /* widget ID 0 is defined as none, or be, ID token accumulation start with 1 and not 0 */ - return id ? this->widget_map[id] : nullptr; -} - -void ekg::runtime::prepare_ui_env() { - ekg::log() << "Preparing internal user interface environment"; - - this->f_renderer_small.sampler_texture.gl_protected_active_index = true; - this->f_renderer_small.set_size(16); - this->f_renderer_small.bind_allocator(&this->gpu_allocator); - - this->f_renderer_normal.sampler_texture.gl_protected_active_index = true; - this->f_renderer_normal.set_size(18); - this->f_renderer_normal.bind_allocator(&this->gpu_allocator); - - this->f_renderer_big.sampler_texture.gl_protected_active_index = true; - this->f_renderer_big.set_size(24); - this->f_renderer_big.bind_allocator(&this->gpu_allocator); - this->update_size_changed(); - - ekg::log() << "Registering user interface input bindings"; - ekg::user_input_register(); -} - -void ekg::runtime::gen_widget(ekg::ui::abstract *p_ui) { - p_ui->unsafe_set_id(++this->token_id); - - ekg::hovered.swap = p_ui->get_id(); - ekg::ui::abstract_widget *p_widget_created {}; - - bool update_layout {}; - bool append_group {}; - bool switch_groups {}; - - switch (p_ui->get_type()) { - case ekg::type::abstract: { - ekg::ui::abstract_widget *p_widget {new ekg::ui::abstract_widget()}; - p_widget->p_data = p_ui; - p_widget_created = p_widget; - break; - } - - case ekg::type::frame: { - ekg::ui::frame_widget *p_widget {new ekg::ui::frame_widget()}; - p_widget->p_data = p_ui; - update_layout = true; - p_widget_created = p_widget; - - if (p_ui->get_place_dock() == ekg::dock::free) { - this->p_current_ui_container = p_ui; - } else { - append_group = true; - switch_groups = true; - } - - break; - } - - case ekg::type::button: { - ekg::ui::button_widget *p_widget {new ekg::ui::button_widget()}; - p_widget->p_data = p_ui; - p_widget_created = p_widget; - append_group = true; - break; - } - - case ekg::type::label: { - ekg::ui::label_widget *p_widget {new ekg::ui::label_widget()}; - p_widget->p_data = p_ui; - p_widget_created = p_widget; - append_group = true; - break; - } - - case ekg::type::checkbox: { - ekg::ui::checkbox_widget *p_widget {new ekg::ui::checkbox_widget()}; - p_widget->p_data = p_ui; - p_widget_created = p_widget; - append_group = true; - break; - } - - case ekg::type::slider: { - ekg::ui::slider_widget *p_widget {new ekg::ui::slider_widget()}; - p_widget->p_data = p_ui; - p_widget_created = p_widget; - append_group = true; - break; - } - - case ekg::type::popup: { - ekg::ui::popup_widget *p_widget {new ekg::ui::popup_widget()}; - p_widget->p_data = p_ui; - p_widget_created = p_widget; - update_layout = false; - break; - } - - case ekg::type::textbox: { - ekg::ui::textbox_widget *p_widget {new ekg::ui::textbox_widget()}; - p_widget->p_data = p_ui; - p_widget_created = p_widget; - append_group = true; - break; - } - - case ekg::type::listbox: { - ekg::ui::listbox_widget *p_widget {new ekg::ui::listbox_widget()}; - p_widget->p_data = p_ui; - p_widget_created = p_widget; - append_group = true; - break; - } - - case ekg::type::scrollbar: { - ekg::ui::scrollbar_widget *p_widget {new ekg::ui::scrollbar_widget()}; - p_widget->p_data = p_ui; - p_widget_created = p_widget; - append_group = true; - break; - } - - default: { - break; - } - } - - this->widget_map[p_ui->get_id()] = p_widget_created; - this->do_task_refresh(p_widget_created); - this->do_task_reload(p_widget_created); - p_widget_created->on_create(); - - if (append_group && this->p_current_ui_container != nullptr) { - this->p_current_ui_container->add_child(p_ui->get_id()); - - if (switch_groups) { - this->p_current_ui_container = p_widget_created->p_data; - } - } - - if (update_layout) { - this->do_task_synclayout(p_widget_created); - } - - if (this->p_current_stack) { - this->p_current_stack->ordered_list.emplace_back(p_widget_created); - } - - ekg::dispatch(ekg::env::swap); -} - -void ekg::runtime::do_task_reload(ekg::ui::abstract_widget *p_widget) { - if (!p_widget || p_widget->was_reloaded) { - return; - } - - if (this->reload_widget_counter >= this->reload_widget_list.size()) { - this->reload_widget_list.emplace_back(); - } - - p_widget->was_reloaded = true; - this->reload_widget_list.at(this->reload_widget_counter++) = ( - p_widget - ); - - ekg::dispatch(ekg::env::reload); -} - -void ekg::runtime::do_task_synclayout(ekg::ui::abstract_widget *p_widget) { - if (!p_widget) { - return; - } - - if (this->synclayout_widget_counter >= this->synclayout_widget_list.size()) { - this->synclayout_widget_list.emplace_back(); - } - - bool is_group {p_widget->p_data->get_type() == ekg::type::frame}; - bool check_parent {is_group == false && p_widget->p_data->has_parent()}; - - if (check_parent) { - p_widget = this->get_fast_widget_by_id(p_widget->p_data->get_parent_id()); - } - - if (p_widget->was_syncedlayout) { - return; - } - - p_widget->was_syncedlayout = true; - this->synclayout_widget_list.at(this->synclayout_widget_counter++) = ( - p_widget - ); - - ekg::dispatch(ekg::env::synclayout); -} - -void ekg::runtime::do_task_refresh(ekg::ui::abstract_widget *p_widget) { - if (p_widget != nullptr && !p_widget->was_refreshed) { - this->refresh_widget_list.emplace_back(p_widget); - ekg::dispatch(ekg::env::refresh); - ekg::dispatch(ekg::env::redraw); - p_widget->was_refreshed = true; - } -} - -bool ekg::runtime::has_bind_group_flag() { - return this->p_current_ui_container != nullptr; -} - -void ekg::runtime::end_group_flag() { - this->p_current_ui_container = nullptr; -} - -void ekg::runtime::end_group_parent_flag() { - ekg::ui::abstract_widget *p_parent_widget {}; - if ( - this->p_current_ui_container != nullptr && - (p_parent_widget = this->get_fast_widget_by_id(this->p_current_ui_container->get_parent_id())) != nullptr - ) { - this->p_current_ui_container = p_parent_widget->p_data; - } -} - -void ekg::runtime::erase(int32_t id) { - std::vector &all {this->loaded_widget_list}; - - for (size_t it {}; it < all.size(); it++) { - ekg::ui::abstract_widget *&p_widget {all[it]}; - - if (p_widget != nullptr && p_widget->p_data->get_id() == id) { - this->widget_map.erase(p_widget->p_data->get_id()); - all.erase(all.begin() + it); - break; - } - } -} - -void ekg::runtime::set_update_high_frequency(ekg::ui::abstract_widget *p_widget) { - if (p_widget != nullptr && !p_widget->is_high_frequency) { - this->enable_high_priority_frequency = true; - - std::vector &update {this->update_widget_list}; - bool contains {}; - - for (ekg::ui::abstract_widget *&p_widgets: update) { - contains = p_widgets == p_widget; - if (contains) { - break; - } - } - - if (!contains) { - update.push_back(p_widget); - p_widget->is_high_frequency = true; - } - } -} \ No newline at end of file diff --git a/src/draw/draw.cpp b/src/draw/draw.cpp index 02be857d..bf4be86a 100644 --- a/src/draw/draw.cpp +++ b/src/draw/draw.cpp @@ -44,7 +44,7 @@ void ekg::draw::rect( return; } - ekg::gpu::data_t &data {ekg::core->gpu_allocator.bind_current_data()}; + ekg::gpu::data_t &data {ekg::p_core->gpu_allocator.bind_current_data()}; data.buffer_content[0] = x; data.buffer_content[1] = y; @@ -58,8 +58,8 @@ void ekg::draw::rect( data.line_thickness = static_cast(line_thickness); data.factor = 1; - ekg::core->gpu_allocator.bind_texture(p_sampler); - ekg::core->gpu_allocator.dispatch(); + ekg::p_core->gpu_allocator.bind_texture(p_sampler); + ekg::p_core->gpu_allocator.dispatch(); } void ekg::draw::sync_scissor( @@ -67,7 +67,7 @@ void ekg::draw::sync_scissor( ekg::rect_t &rect_child, ekg::rect_t *p_parent_scissor ) { - ekg::core->gpu_allocator.sync_scissor(scissor, rect_child, p_parent_scissor); + ekg::p_core->gpu_allocator.sync_scissor(scissor, rect_child, p_parent_scissor); } void ekg::draw::scissor( @@ -76,7 +76,7 @@ void ekg::draw::scissor( float w, float h ) { - ekg::core->gpu_allocator.unsafe_set_scissor_placement( + ekg::p_core->gpu_allocator.unsafe_set_scissor_placement( x, y, w, h ); } @@ -87,4 +87,4 @@ void ekg::draw::enable_high_priority() { void ekg::draw::disable_high_priority() { ekg::gpu::allocator::high_priority = false; -} \ No newline at end of file +} diff --git a/src/draw/font_renderer.cpp b/src/draw/font_renderer.cpp index 20977f83..2f15e92a 100644 --- a/src/draw/font_renderer.cpp +++ b/src/draw/font_renderer.cpp @@ -285,7 +285,7 @@ void ekg::draw::font_renderer::reload() { this->text_height = static_cast(this->font_size); this->offset_text_height = static_cast(this->text_height / 6) / 2; - ekg::core->p_gpu_api->gen_font_atlas_and_map_glyph( + ekg::p_core->p_gpu_api->gen_font_atlas_and_map_glyph( &this->sampler_texture, &this->faces[ekg::draw::font_face_type::text], &this->faces[ekg::draw::font_face_type::emojis], @@ -492,4 +492,4 @@ void ekg::draw::font_renderer::quit() { FT_Done_Face(this->faces[ekg::draw::font_face_type::emojis].ft_face); this->faces[ekg::draw::font_face_type::emojis].was_loaded = false; } -} \ No newline at end of file +} diff --git a/src/ekg.cpp b/src/ekg.cpp index ddbb61ca..91bed739 100644 --- a/src/ekg.cpp +++ b/src/ekg.cpp @@ -26,33 +26,32 @@ #include "ekg/os/platform.hpp" #include "ekg/util/geometry.hpp" -ekg::runtime *ekg::core {}; -bool ekg::running {}; +ekg::runtime *ekg::p_core {}; ekg::service::theme_scheme_t &ekg::current_theme_scheme() { - return ekg::core->service_theme.get_current_theme_scheme(); + return ekg::p_core->service_theme.get_current_theme_scheme(); } ekg::service::theme &ekg::theme() { - return ekg::core->service_theme; + return ekg::p_core->service_theme; } ekg::draw::font_renderer &ekg::f_renderer(ekg::font font_size) { switch (font_size) { case ekg::font::big: { - return ekg::core->f_renderer_big; + return ekg::p_core->f_renderer_big; } case ekg::font::normal: { - return ekg::core->f_renderer_normal; + return ekg::p_core->f_renderer_normal; } case ekg::font::small: { - return ekg::core->f_renderer_small; + return ekg::p_core->f_renderer_small; } } - return ekg::core->f_renderer_normal; + return ekg::p_core->f_renderer_normal; } void ekg::init( @@ -78,41 +77,41 @@ void ekg::init( ekg::log() << "Initializing EKG"; - ekg::core = p_ekg_runtime; + ekg::p_core = p_ekg_runtime; ekg::running = true; - ekg::core->f_renderer_small.init(); - ekg::core->f_renderer_small.set_font(p_ekg_runtime_property->p_font_path); - ekg::core->f_renderer_small.set_font_emoji(p_ekg_runtime_property->p_font_path_emoji); + ekg::p_core->f_renderer_small.init(); + ekg::p_core->f_renderer_small.set_font(p_ekg_runtime_property->p_font_path); + ekg::p_core->f_renderer_small.set_font_emoji(p_ekg_runtime_property->p_font_path_emoji); - ekg::core->f_renderer_normal.init(); - ekg::core->f_renderer_normal.set_font(p_ekg_runtime_property->p_font_path); - ekg::core->f_renderer_normal.set_font_emoji(p_ekg_runtime_property->p_font_path_emoji); + ekg::p_core->f_renderer_normal.init(); + ekg::p_core->f_renderer_normal.set_font(p_ekg_runtime_property->p_font_path); + ekg::p_core->f_renderer_normal.set_font_emoji(p_ekg_runtime_property->p_font_path_emoji); - ekg::core->f_renderer_big.init(); - ekg::core->f_renderer_big.set_font(p_ekg_runtime_property->p_font_path); - ekg::core->f_renderer_big.set_font_emoji(p_ekg_runtime_property->p_font_path_emoji); + ekg::p_core->f_renderer_big.init(); + ekg::p_core->f_renderer_big.set_font(p_ekg_runtime_property->p_font_path); + ekg::p_core->f_renderer_big.set_font_emoji(p_ekg_runtime_property->p_font_path_emoji); - ekg::core->init(); + ekg::p_core->init(); } void ekg::quit() { - ekg::core->p_os_platform->quit(); - ekg::core->p_gpu_api->quit(); - ekg::core->quit(); + ekg::p_core->p_os_platform->quit(); + ekg::p_core->p_gpu_api->quit(); + ekg::p_core->quit(); ekg::running = false; ekg::log() << "Shutdown complete - Thank you for using EKG ;) <3"; } void ekg::update() { - ekg::core->update(); - ekg::core->p_os_platform->update_cursor(); - ekg::core->p_os_platform->serialized_input_event.type = ekg::platform_event_type::none; + ekg::p_core->update(); + ekg::p_core->p_os_platform->update_cursor(); + ekg::p_core->p_os_platform->serialized_input_event.type = ekg::platform_event_type::none; } void ekg::render() { - ekg::core->render(); + ekg::p_core->render(); } ekg::ui::frame *ekg::frame(std::string_view tag, ekg::rect rect) { @@ -125,7 +124,7 @@ ekg::ui::frame *ekg::frame(std::string_view tag, ekg::rect rect) { p_ui->set_tag(tag); p_ui->unsafe_set_type(ekg::type::frame); p_ui->set_place(ekg::dock::free); - ekg::core->gen_widget(p_ui); + ekg::p_core->gen_widget(p_ui); p_ui->ui() = { rect.x, @@ -153,14 +152,14 @@ ekg::ui::frame *ekg::frame(std::string_view tag, ekg::rect rect, ekg::flags dock bool is_w_set {!ekg_equals_float(rect.w, ekg_no_update_placement)}; bool is_h_set {!ekg_equals_float(rect.h, ekg_no_update_placement)}; - if (!ekg::core->has_bind_group_flag()) { + if (!ekg::p_core->has_bind_group_flag()) { dock = ekg::dock::free; } p_ui->set_tag(tag); p_ui->unsafe_set_type(ekg::type::frame); p_ui->set_place(dock); - ekg::core->gen_widget(p_ui); + ekg::p_core->gen_widget(p_ui); p_ui->ui() = { rect.x, @@ -185,7 +184,7 @@ ekg::ui::button *ekg::button(std::string_view text, ekg::flags dock) { p_ui->registry(p_ui); p_ui->reset_ownership(); p_ui->unsafe_set_type(ekg::type::button); - ekg::core->gen_widget(p_ui); + ekg::p_core->gen_widget(p_ui); p_ui->set_text(text); p_ui->set_place(dock); @@ -202,7 +201,7 @@ ekg::ui::label *ekg::label(std::string_view text, ekg::flags dock) { p_ui->registry(p_ui); p_ui->reset_ownership(); p_ui->unsafe_set_type(ekg::type::label); - ekg::core->gen_widget(p_ui); + ekg::p_core->gen_widget(p_ui); p_ui->set_value(std::string(text)); p_ui->set_place(dock); @@ -219,7 +218,7 @@ ekg::ui::checkbox *ekg::checkbox(std::string_view text, bool value, ekg::flags d p_ui->registry(p_ui); p_ui->reset_ownership(); p_ui->unsafe_set_type(ekg::type::checkbox); - ekg::core->gen_widget(p_ui); + ekg::p_core->gen_widget(p_ui); p_ui->set_text(text); p_ui->set_place(dock); @@ -241,7 +240,7 @@ ekg::popup(std::string_view tag, const std::vector &component_list, ekg::ui::popup *p_ui {new ekg::ui::popup()}; p_ui->unsafe_set_type(ekg::type::popup); - ekg::core->gen_widget(p_ui); + ekg::p_core->gen_widget(p_ui); if (interact_position) { ekg::vec4 &interact {ekg::input::interact()}; @@ -263,7 +262,7 @@ ekg::ui::textbox *ekg::textbox(std::string_view tag, std::string_view text, ekg: p_ui->registry(p_ui); p_ui->reset_ownership(); p_ui->unsafe_set_type(ekg::type::textbox); - ekg::core->gen_widget(p_ui); + ekg::p_core->gen_widget(p_ui); p_ui->set_tag(tag); p_ui->set_place(dock); @@ -285,7 +284,7 @@ ekg::ui::listbox *ekg::listbox( p_ui->registry(p_ui); p_ui->reset_ownership(); p_ui->unsafe_set_type(ekg::type::listbox); - ekg::core->gen_widget(p_ui); + ekg::p_core->gen_widget(p_ui); p_ui->set_tag(tag); p_ui->set_place(dock); @@ -301,20 +300,20 @@ ekg::ui::listbox *ekg::listbox( ekg::ui::scrollbar *ekg::scrollbar(std::string_view tag) { ekg::ui::scrollbar *p_ui {new ekg::ui::scrollbar()}; p_ui->unsafe_set_type(ekg::type::scrollbar); - ekg::core->gen_widget(p_ui); + ekg::p_core->gen_widget(p_ui); p_ui->set_tag(tag); return p_ui; } bool ekg::has_bind_group_flag() { - return ekg::core->has_bind_group_flag(); + return ekg::p_core->has_bind_group_flag(); } void ekg::pop_group() { - ekg::core->end_group_flag(); + ekg::p_core->end_group_flag(); } void ekg::pop_group_parent() { - ekg::core->end_group_parent_flag(); + ekg::p_core->end_group_parent_flag(); } diff --git a/src/gpu/allocator.cpp b/src/gpu/allocator.cpp index fd269e05..b5e4b8d8 100644 --- a/src/gpu/allocator.cpp +++ b/src/gpu/allocator.cpp @@ -58,7 +58,7 @@ void ekg::gpu::allocator::bind_texture(ekg::sampler_t *p_sampler) { } ekg::io::gpu_data_t &data {this->data_list.at(this->data_instance_index)}; - data.sampler_index = ekg::core->p_gpu_api->bind_sampler(p_sampler); + data.sampler_index = ekg::p_core->p_gpu_api->bind_sampler(p_sampler); } void ekg::gpu::allocator::dispatch() { @@ -163,7 +163,7 @@ void ekg::gpu::allocator::revoke() { } if (should_re_alloc_buffers || this->factor_changed) { - ekg::core->p_gpu_api->re_alloc_geometry_resources( + ekg::p_core->p_gpu_api->re_alloc_geometry_resources( this->geometry_resource_list.data(), this->geometry_resource_list.size() ); @@ -186,7 +186,7 @@ void ekg::gpu::allocator::on_update() { } void ekg::gpu::allocator::draw() { - ekg::core->p_gpu_api->draw( + ekg::p_core->p_gpu_api->draw( this->data_list.data(), this->data_list.size() ); diff --git a/src/io/design.cpp b/src/io/design.cpp index c3e8498f..a5ee8f4e 100644 --- a/src/io/design.cpp +++ b/src/io/design.cpp @@ -1,21 +1,21 @@ #include "ekg/io/design.hpp" std::map &ekg::themes() { - return ekg::core->service_theme.get_theme_map(); + return ekg::p_core->service_theme.get_theme_map(); } ekg::theme_t &ekg::theme(std::string_view name) { if (name.empty()) { - return ekg::core->service_theme.get_current_theme(); + return ekg::p_core->service_theme.get_current_theme(); } return ekg::themes()[name]; } ekg::theme_t &ekg::theme(ekg::theme_t theme) { - return ekg::core->service_theme.add(theme.name, theme); + return ekg::p_core->service_theme.add(theme.name, theme); } ekg::flags_t ekg::set_current_theme(std::string_view name) { - return ekg::core->service_theme.set_current_theme(name); + return ekg::p_core->service_theme.set_current_theme(name); } diff --git a/src/io/gpu.cpp b/src/io/gpu.cpp index c465fadc..31a0d902 100644 --- a/src/io/gpu.cpp +++ b/src/io/gpu.cpp @@ -4,7 +4,7 @@ ekg::flags_t ekg::gpu_allocate_sampler( ekg::sampler_allocate_info_t *p_sampler_allocate_info, ekg::sampler_t *p_sampler ) { - return ekg::core->p_gpu_api->gpu_allocate_sampler( + return ekg::p_core->p_gpu_api->gpu_allocate_sampler( p_sampler_allocate_info, p_sampler ); @@ -14,8 +14,8 @@ ekg::flags_t ekg::gpu_fill_sampler( ekg::sampler_fill_info_t *p_sampler_fill_info, ekg::sampler_t *p_sampler ) { - return ekg::core->p_gpu_api->fill_sampler( + return ekg::p_core->p_gpu_api->fill_sampler( p_sampler_fill_info, p_sampler ); -} \ No newline at end of file +} diff --git a/src/io/input.cpp b/src/io/input.cpp index 4bac1396..678aa300 100644 --- a/src/io/input.cpp +++ b/src/io/input.cpp @@ -2,23 +2,23 @@ #include "ekg/ekg.hpp" ekg::input_t &ekg::input() { - return ekg::core->service_input.input; + return ekg::p_core->service_input.input; } bool ekg::fire(std::string_view tag) { - return ekg::core->service_input.get_input_bind_state(tag); + return ekg::p_core->service_input.get_input_bind_state(tag); } bool ekg::input(std::string_view input) { - return ekg::core->service_input.get_input_state(input); + return ekg::p_core->service_input.get_input_state(input); } void ekg::bind(std::string_view tag, std::string_view input) { - ekg::core->service_input.insert_input_bind(tag, input); + ekg::p_core->service_input.insert_input_bind(tag, input); } void ekg::bind(std::string_view tag, std::vector inputs) { for (std::string_view &input : inputs) { ekg::bind(tag, inputs); } -} \ No newline at end of file +} diff --git a/src/io/task.cpp b/src/io/task.cpp index d7e57715..7ba2a8c4 100644 --- a/src/io/task.cpp +++ b/src/io/task.cpp @@ -27,12 +27,12 @@ void ekg::io::dispatch(ekg::io::runtime_task_operation op) { switch (op) { case ekg::runtime_task_operation::redraw: - ekg::core->must_redraw = true; + ekg::p_core->must_redraw = true; break; default: - ekg::core->service_handler.dispatch_pre_allocated_task( + ekg::p_core->service_handler.dispatch_pre_allocated_task( static_cast(op) ); break; } -} \ No newline at end of file +} diff --git a/src/io/typography.cpp b/src/io/typography.cpp new file mode 100644 index 00000000..66ebcfcb --- /dev/null +++ b/src/io/typography.cpp @@ -0,0 +1,65 @@ +/** + * MIT License + * + * Copyright (c) 2022-2024 Rina Wilk / vokegpu@gmail.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "ekg/draw/font_renderer.hpp" + +ekg::flags_t ekg::draw::reload_font_face( + ekg::draw::font_face_t *p_font_face, + bool was_size_changed, + uint32_t font_size +) { + if (p_font_face == nullptr) { + return ekg::result::failed; + } + + if (p_font_face->was_changed) { + if (p_font_face->was_loaded) { + FT_Done_Face(p_font_face->ft_face); + p_font_face->was_loaded = false; + } + + p_font_face->was_loaded = FT_New_Face( + ekg::draw::font_renderer::ft_library, + p_font_face->font_path.data(), + 0, + &p_font_face->ft_face + ); + + if (p_font_face->was_loaded) { + ekg::log() << "Could not load font " << p_font_face->font_path; + return ekg::result::failed; + } + + ekg::log() << "Font '" << p_font_face->font_path << "' loaded!"; + + p_font_face->was_loaded = true; + p_font_face->was_changed = false; + } + + if (p_font_face->was_loaded && was_size_changed) { + FT_Set_Pixel_Sizes(p_font_face->ft_face, 0, font_size); + } + + return ekg::result::success; +} diff --git a/src/layout/dimension.cpp b/src/layout/dimension.cpp index ed581789..61f7b474 100644 --- a/src/layout/dimension.cpp +++ b/src/layout/dimension.cpp @@ -13,7 +13,7 @@ float ekg::layout::estimate_height( float height {}; for (int32_t &ids : p_parent_widget->p_data->get_child_id_list()) { - if (ids == 0 || (p_widgets = ekg::core->get_fast_widget_by_id(ids)) == nullptr) { + if (ids == 0 || (p_widgets = ekg::p_core->get_fast_widget_by_id(ids)) == nullptr) { continue; } diff --git a/src/layout/scale.cpp b/src/layout/scale.cpp index d969dcc4..8a8af1d8 100644 --- a/src/layout/scale.cpp +++ b/src/layout/scale.cpp @@ -8,9 +8,9 @@ void ekg::layout::scale_calculate() { ekg::vec2 input_resolution {static_cast(ekg::ui::width), static_cast(ekg::ui::height)}; if (ekg::ui::auto_scale) { - ekg::core->p_os_platform->update_monitor_resolution(); - monitor_resolution.x = static_cast(ekg::core->p_os_platform->monitor_resolution[0]); - monitor_resolution.y = static_cast(ekg::core->p_os_platform->monitor_resolution[1]); + ekg::p_core->p_os_platform->update_monitor_resolution(); + monitor_resolution.x = static_cast(ekg::p_core->p_os_platform->monitor_resolution[0]); + monitor_resolution.y = static_cast(ekg::p_core->p_os_platform->monitor_resolution[1]); ekg::ui::scale = {1920.0f, 1080.0f}; input_resolution = monitor_resolution; } @@ -56,4 +56,4 @@ void ekg::layout::scale_calculate() { ); ekg::layout::scale_factor = ekg_clamp(factor, 0.5f, 2.0f); -} \ No newline at end of file +} diff --git a/src/math/geometry.cpp b/src/math/geometry.cpp index a3765118..61d664ec 100644 --- a/src/math/geometry.cpp +++ b/src/math/geometry.cpp @@ -32,4 +32,4 @@ void ekg::ortho( p_mat4x4[13] = -(top + bottom) * y_inv; p_mat4x4[14] = -(depth_far + depth_near) * depth_inv; p_mat4x4[15] = 1.0f; -} \ No newline at end of file +} diff --git a/src/os/ekg_glfw.cpp b/src/os/ekg_glfw.cpp index ab3aa5fb..85d2cf13 100644 --- a/src/os/ekg_glfw.cpp +++ b/src/os/ekg_glfw.cpp @@ -323,12 +323,12 @@ void ekg::os::glfw_window_size_callback(int32_t w, int32_t h) { ekg::ui::width = w; ekg::ui::height = h; - ekg::core->p_gpu_api->update_viewport(ekg::ui::width, ekg::ui::height); - ekg::core->update_size_changed(); + ekg::p_core->p_gpu_api->update_viewport(ekg::ui::width, ekg::ui::height); + ekg::p_core->update_size_changed(); } void ekg::os::glfw_scroll_callback(double dx, double dy) { - ekg::os::io_event_serial &serialized {ekg::core->io_event_serial}; + ekg::os::io_event_serial &serialized {ekg::p_core->io_event_serial}; serialized.event_type = ekg::platform_event_type::mouse_wheel; serialized.mouse_wheel_x = static_cast(dx); serialized.mouse_wheel_y = static_cast(dy); @@ -337,12 +337,12 @@ void ekg::os::glfw_scroll_callback(double dx, double dy) { ekg::poll_io_event = true; ekg::cursor = ekg::system_cursor::arrow; - ekg::core->process_event(); + ekg::p_core->process_event(); ekg::poll_io_event = false; } void ekg::os::glfw_char_callback(uint32_t codepoint) { - ekg::os::io_event_serial &serialized {ekg::core->io_event_serial}; + ekg::os::io_event_serial &serialized {ekg::p_core->io_event_serial}; serialized.event_type = ekg::platform_event_type::text_input; // idk it seems pretty much a workaround, predictable crash if codepoint @@ -352,12 +352,12 @@ void ekg::os::glfw_char_callback(uint32_t codepoint) { ekg::poll_io_event = true; ekg::cursor = ekg::system_cursor::arrow; - ekg::core->process_event(); + ekg::p_core->process_event(); ekg::poll_io_event = false; } void ekg::os::glfw_key_callback(int32_t key, int32_t scancode, int32_t action, int32_t mods) { - ekg::os::io_event_serial &serialized {ekg::core->io_event_serial}; + ekg::os::io_event_serial &serialized {ekg::p_core->io_event_serial}; std::string a {}; switch (action) { @@ -384,12 +384,12 @@ void ekg::os::glfw_key_callback(int32_t key, int32_t scancode, int32_t action, i } ekg::cursor = ekg::system_cursor::arrow; - ekg::core->process_event(); + ekg::p_core->process_event(); ekg::poll_io_event = false; } void ekg::os::glfw_mouse_button_callback(int32_t button, int32_t action, int32_t mods) { - ekg::os::io_event_serial &serialized {ekg::core->io_event_serial}; + ekg::os::io_event_serial &serialized {ekg::p_core->io_event_serial}; /** * The mouse button number on GLFW is different from SDL2, @@ -421,18 +421,18 @@ void ekg::os::glfw_mouse_button_callback(int32_t button, int32_t action, int32_t } ekg::cursor = ekg::system_cursor::arrow; - ekg::core->process_event(); + ekg::p_core->process_event(); ekg::poll_io_event = false; } void ekg::os::glfw_cursor_pos_callback(double x, double y) { - ekg::os::io_event_serial &serialized {ekg::core->io_event_serial}; + ekg::os::io_event_serial &serialized {ekg::p_core->io_event_serial}; serialized.event_type = ekg::platform_event_type::mouse_motion; serialized.mouse_motion_x = static_cast(x); serialized.mouse_motion_y = static_cast(y); ekg::poll_io_event = true; ekg::cursor = ekg::system_cursor::arrow; - ekg::core->process_event(); + ekg::p_core->process_event(); ekg::poll_io_event = false; -} \ No newline at end of file +} diff --git a/src/os/ekg_opengl.cpp b/src/os/ekg_opengl.cpp index 587d295f..a68856ba 100644 --- a/src/os/ekg_opengl.cpp +++ b/src/os/ekg_opengl.cpp @@ -609,5 +609,5 @@ void ekg::opengl::draw( } ekg::opengl *ekg::os::get_opengl() { - return static_cast(ekg::core->p_gpu_api); -} \ No newline at end of file + return static_cast(ekg::p_core->p_gpu_api); +} diff --git a/src/os/ekg_sdl.cpp b/src/os/ekg_sdl.cpp index 3647a0cd..c4e413c1 100644 --- a/src/os/ekg_sdl.cpp +++ b/src/os/ekg_sdl.cpp @@ -192,8 +192,8 @@ void ekg::sdl_poll_event(SDL_Event &sdl_event) { ekg::viewport.w = sdl_event.window.data1; ekg::viewport.h = sdl_event.window.data2; - ekg::core->p_gpu_api->update_viewport(ekg::viewport.w, ekg::viewport.h); - ekg::core->update_size_changed(); + ekg::p_core->p_gpu_api->update_viewport(ekg::viewport.w, ekg::viewport.h); + ekg::p_core->update_size_changed(); break; } @@ -261,7 +261,7 @@ void ekg::sdl_poll_event(SDL_Event &sdl_event) { if (must_poll_events) { this->system_cursor = ekg::system_cursor::arrow; - ekg::core->poll_events(); + ekg::p_core->poll_events(); must_poll_events = false; } -} \ No newline at end of file +} diff --git a/src/service/input.cpp b/src/service/input.cpp index 6511da10..7b8527c4 100644 --- a/src/service/input.cpp +++ b/src/service/input.cpp @@ -28,7 +28,7 @@ #include "ekg/ekg.hpp" ekg::input_t &ekg::input() { - return ekg::core->service_input.input; + return ekg::p_core->service_input.input; } void ekg::service::input::init() { @@ -200,7 +200,7 @@ void ekg::service::input::on_event() { float wheel_precise_interval {}; ekg::io::serialized_input_event_t &serialized_input_event { - ekg::core->p_os_platform->serialized_input_event + ekg::p_core->p_os_platform->serialized_input_event }; switch (serialized_input_event.event_type) { @@ -216,13 +216,13 @@ void ekg::service::input::on_event() { std::string key_name {}; std::string string_builder {}; - ekg::core->p_os_platform->get_key_name( + ekg::p_core->p_os_platform->get_key_name( serialized_input_event.key, key_name ); ekg::special_key_type special_key {ekg::special_key_type::unknown}; - ekg::core->p_os_platform->get_special_key(serialized_input_event.key, special_key); + ekg::p_core->p_os_platform->get_special_key(serialized_input_event.key, special_key); if (special_key != ekg::special_key_type::unknown) { this->special_keys[static_cast(special_key)][0] = key_name[0]; @@ -256,13 +256,13 @@ void ekg::service::input::on_event() { std::string key_name {}; std::string string_builder {}; - ekg::core->p_os_platform->get_key_name( + ekg::p_core->p_os_platform->get_key_name( serialized_input_event.key, key_name ); ekg::special_key_type special_key {ekg::special_key_type::unknown}; - ekg::core->p_os_platform->get_special_key(serialized_input_event.key, special_key); + ekg::p_core->p_os_platform->get_special_key(serialized_input_event.key, special_key); if (special_key != ekg::special_key_type::unknown) { this->special_keys[static_cast(special_key)][0] = '\0'; @@ -654,4 +654,4 @@ bool ekg::service::input::get_input_bind_state( std::string_view tag ) { return this->input_bind_map[tag.data()].state; -} \ No newline at end of file +}