8#define NK_GLFW_GL4_IMPLEMENTATION
10#include <entt/entity/registry.hpp>
13#include "galaxy/core/ServiceLocator.hpp"
14#include "galaxy/core/Window.hpp"
17#include "galaxy/utils/Globals.hpp"
28 , m_viewport_backup {0, 0, 0, 0}
30 auto& window = core::ServiceLocator<core::Window>::ref();
32 m_ctx = nk_glfw3_init(window.handle(), NK_GLFW3_DEFAULT, NK_MAX_VERTEX_BUFFER, NK_MAX_ELEMENT_BUFFER);
35 scale(window.get_content_scale_max());
49 nk_glfw3_mouse_button_callback(
nullptr,
static_cast<int>(e.button), GLFW_PRESS,
static_cast<int>(e.mod));
58 nk_gflw3_scroll_callback(
nullptr, e.xoff, e.yoff);
67 nk_glfw3_char_callback(
nullptr, e.codepoint);
76 int action = GLFW_RELEASE;
78 if (e.pressed ==
true)
82 else if (e.repeat ==
true)
87 nk_glfw3_key_button_callback(
nullptr, input::key_to_int(e.keycode), e.scancode, action, input::mod_to_int(e.mod));
94 scale(std::max(e.xscale, e.yscale));
101 nk_input_begin(
ctx());
109 for (
auto i = 0; i < glfw.text_len; ++i)
111 nk_input_unicode(&glfw.ctx, glfw.text[i]);
114 double x = 0.0, y = 0.0;
115 glfwGetCursorPos(glfw.win, &x, &y);
116 nk_input_motion(&glfw.ctx,
static_cast<int>(x),
static_cast<int>(y));
118 nk_input_button(&glfw.ctx,
120 static_cast<int>(glfw.double_click_pos.x),
121 static_cast<int>(glfw.double_click_pos.y),
122 glfw.is_double_click_down);
123 nk_input_scroll(&glfw.ctx, glfw.scroll);
126 glfw.scroll = nk_vec2(0, 0);
139 nk_glfw3_new_frame();
146 nk_glfw3_render(NK_ANTI_ALIASING_ON);
149 glBindVertexArray(0);
150 glBindTexture(GL_TEXTURE_2D, 0);
151 glDisable(GL_SCISSOR_TEST);
152 glEnable(GL_DEPTH_TEST);
161 nk_style_set_font(
ctx(), &
m_fonts[
id]->handle);
167 m_ctx->do_input = enable;
171 m_ctx->mod_held =
false;
177 auto& window = core::ServiceLocator<core::Window>::ref();
181 nk_rect((window.get_widthf() / 2.0f) - 200, (window.get_heightf() / 2.0f) - 30, 400, 60),
182 NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR))
184 nk_layout_row_dynamic(
ctx(), 20, 1);
185 nk_label(
ctx(), text, NK_TEXT_CENTERED);
186 nk_layout_row_static(
ctx(), 20, 400, 1);
187 nk_progress(
ctx(), ¤t, total, NK_FIXED);
195 auto& window = core::ServiceLocator<core::Window>::ref();
199 nk_rect((window.get_widthf() / 2.0f) - 200, (window.get_heightf() / 2.0f) - 20, 400, 40),
200 NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR))
202 nk_layout_row_dynamic(
ctx(), 20, 1);
203 nk_label(
ctx(),
"Building Textures...", NK_TEXT_CENTERED);
216 auto& fs = core::ServiceLocator<fs::VirtualFileSystem>::ref();
217 auto& config = core::ServiceLocator<core::Config>::ref();
224 nk_glfw3_font_stash_begin(&
m_atlas);
226 for (
const auto& file : fs.list(GALAXY_UI_FONTS_DIR))
228 auto data = fs.read_binary(file);
231 const auto size =
scale * config.get<
float>(
"ui_font_size");
233 auto font_cfg = nk_font_config(size);
234 font_cfg.pixel_snap =
true;
236 auto font = nk_font_atlas_add_from_memory(
m_atlas, data.data(), data.size(), size, &font_cfg);
241 nk_glfw3_font_stash_end();
242 nk_style_default(
ctx());
void on_mouse_pressed(events::MousePressed &e)
On mouse pressed event handler.
void show_building_atlas()
Part of the loading screen. Informs the user that the atlas is being built.
void on_mouse_wheel(events::MouseWheel &e)
On mouse wheel event handler.
void poll_input() const
Calls begin, end and glfwPollEvents.
void toggle_input(const bool enable)
Control the input.
void show_loading_bar(const char *text, nk_size total, nk_size current)
Shows a progress bar for loading screens.
void on_key_press(events::KeyPress &e)
On keyboad press event.
void end_input() const
Called after glfwPollEvents.
void scale(const float scale)
Scale UI to monitor/window.
void on_content_scale(const events::ContentScale &e)
On content scale event.
void on_key_char(events::KeyChar &e)
On typing event handler.
nk_context * ctx() const
Nuklear Context.
nk_font_atlas * m_atlas
Nuklear atlas pointer.
ankerl::unordered_dense::map< std::string, nk_font * > m_fonts
Fonts used by nuklear.
void begin_input() const
Called before glfwPollEvents.
nk_glfw * m_ctx
Nuklear context pointer.
void new_frame()
Called before any nuklear code.
void render()
Render nuklear.
std::array< int, 4 > m_viewport_backup
Viewport backup when rendering.
void set_font(const std::string &id)
Change the active font.