diff --git a/include/maker/presenter.hpp b/include/maker/presenter.hpp index db2a6ed86340822aa18c940c750daced420ce8e5..c1db75049fb0d616e3f95d5643eadb56ecd1e6ac 100644 --- a/include/maker/presenter.hpp +++ b/include/maker/presenter.hpp @@ -26,6 +26,7 @@ protected: void init_scene2(gfx::Camera* camera); void init_scene3(gfx::Camera* camera); void init_scene4(gfx::Camera* camera); + void init_3d_ui(); void release() override; }; diff --git a/src/presenter.cpp b/src/presenter.cpp index 4036f0e0aff0a4602194d78a946c9abb62208a92..415383664f2938617e85ff8b113347d2ec8666b7 100644 --- a/src/presenter.cpp +++ b/src/presenter.cpp @@ -9,6 +9,8 @@ #include <fstream> #include <glm/gtx/string_cast.hpp> +#include "maker/handlers/buffer_handler.hpp" + namespace mak { typedef gfx::ShaderGraph::Node::DataType::ElementType ElementType; @@ -37,38 +39,18 @@ void Presenter::initialize() { osi::presenters()->push_back<com::Folder>("maker")->push_back<com::Link>(self_name() + ".link", this); - auto* default_shader = dynamic_cast<Graph*>(shader_system()->default_shader()); + Material* tex_material = material_system()->insert_material("box_material", shader_system()->default_shader(), {"materials"}); - Material* tex_material = material_system()->insert_material("box_material", default_shader, {"materials"}); ui_system()->insert_default_materials(); - gfx::object_system()->push_frame_back( - gfx::object_system()->insert_object( + object_system()->push_frame_back( + object_system()->insert_object( { "grid" }, tex_material, - gfx::buffer_generators()->insert_procedural_grid() + buffer_generators()->insert_procedural_grid() ), grid_frame() ); - - // --- BEGIN test_box --- - //com::Folder* const test_box = gfx::object_system()->insert_object( - //{ "maker", "test_box" }, - //tex_material, - //gfx::buffer_generators()->insert_procedural_box_solid({ 0.5f, 0.5f, 0.5f } , "test_box", { "maker" }) - //); - //gfx::object_system()->push_frame_back( - //test_box , - //root()->push_back<com::Folder>("test_box")->push_back<com::Frame>() - //); - //gfx::object_system()->get_uniforms(test_box)->push_back<com::FileVec3>("material_ambient_color", vec3{ 0.75f, 0.75f, 0 }); - - //// The second instance - //com::Frame* const frame2 = root()->push_back<com::Folder>("test_box_2")->push_back<com::Frame>(); - //frame2->move_origin({ 0.5f, 0, 1.5f }); - //gfx::object_system()->push_frame_back(test_box, frame2); - - // --- END test_box --- camera_system()->set_frame(camera_system()->default_camera_folder(), camera_frame()); // UI @@ -77,11 +59,15 @@ void Presenter::initialize() ui_camera->set_perspective(false); camera_system()->set_frame(ui_camera->folder(), ui_system()->get_default_camera_frame()); + auto* handlers_folder = root()->push_back<com::Folder>("handlers"); + auto* buffer_handler = handlers_folder->push_back<BufferHandler>(); + // Initialize scenes init_scene1(ui_camera); init_scene2(ui_camera); init_scene3(ui_camera); init_scene4(ui_camera); + init_3d_ui(); ui_system()->set_current_scene("scene1"); @@ -118,12 +104,15 @@ void Presenter::init_scene1(Camera* camera) { ui_system()->assign_camera_to_scene(scene1, camera); auto* scene1_camera_bottom_left_frame = ui_system()->get_scene_frame(scene1); + auto* buffer_handler = root()->find<com::Folder>("handlers")->find<BufferHandler>(BufferHandler::self_name()); + auto* check_box = ui_system()->insert_element<CheckBox>("checkbox", scene1, scene1_default_layer, vec2i{50.0f, 50.0f}); auto* slider = ui_system()->insert_element<Slider>("slider", scene1, scene1_default_layer, vec2i{20.0f, 200.0f}, VERTICAL); auto* h_slider = ui_system()->insert_element<Slider>("h_slider", scene1, scene1_default_layer, vec2i{200.0f, 20.0f}, HORIZONTAL); auto* progress_bar = ui_system()->insert_element<ProgressBar>("progress_bar", scene1, scene1_default_layer, vec2i{200.0f, 20.0f}, 0.4f); Button* button1 = ui_generators()->create_ui_button("ui_elem1", vec2i{100, 50}, scene1, scene1_layer1, "button1"); - // todo maybe move this function into ui generators + button1->register_handler(buffer_handler); + button1->get_transform()->set_anchor(Anchor{0.7f, 0.2f, 0.1f, 0.2f}); button1->request_fonts_to_load("OpenSans", 48U, false, false); Button* button2 = ui_generators()->create_ui_button("ui_elem2", vec2i{100,100}, scene1, scene1_default_layer, "button2"); button2->request_fonts_to_load("OpenSans", 48U, false, false); @@ -144,7 +133,7 @@ void Presenter::init_scene1(Camera* camera) { auto* edit_text_line = ui_system()->insert_element<LineTextEdit>("line_text_edit", scene1, scene1_default_layer, vec2i{100, 48}, "text_edit"); edit_text_line->request_fonts_to_load("OpenSans", 48U, false, false); - auto* handlers_folder = root()->push_back<com::Folder>("handlers"); + auto* handlers_folder = root()->find<com::Folder>("handlers"); auto* button_handler = handlers_folder->push_back<ButtonHandler>("button_handler"); auto* check_box_handler = handlers_folder->push_back<CheckBoxHandler>("check_box_handler"); auto* interval_handler = handlers_folder->push_back<IntervalHandler>("interval_handler"); @@ -191,7 +180,7 @@ void Presenter::init_scene2(Camera* camera) { auto* tab_bar_static_text1 = ui_system()->insert_child_element<StaticText>("tab_bar_text1", tab_bar, scene2, scene2_default_layer, vec2i{500, 400}, "tab bar text1"); tab_bar_static_text1->request_fonts_to_load("OpenSans", 48U, true, true); auto* tab_bar_static_text2 = ui_system()->insert_child_element<StaticText>("tab_bar_text2", tab_bar, scene2, scene2_default_layer, vec2i{500, 300}, "tab bar text2"); - tab_bar_static_text2->request_fonts_to_load("OpenSans", 48U, true, true); + tab_bar_static_text2->request_fonts_to_load("OpenSans", 12U, true, true); // Composite element auto* tab_bar_elem1 = ui_system()->insert_child_element<UiElement>("tab_bar_elem1", tab_bar, scene2, scene2_default_layer, vec2i{600, 450}); std::string button_text = "sub_element_text"; @@ -199,7 +188,7 @@ void Presenter::init_scene2(Camera* camera) { tab_bar_elem1_button->request_fonts_to_load("OpenSans", 48U, false, false); // List box auto* tab_bar_elem1_list_box = ui_system()->insert_child_element<ListBox>("tab_bar_elem1_list_box", tab_bar_elem1, scene2, scene2_default_layer, vec2i{100,300}, vec2i{100, 30}); - tab_bar_elem1_list_box->insert_item(scene2, scene2_default_layer, "text", 0.3f, "OpenSans", 48); + tab_bar_elem1_list_box->insert_item(scene2, scene2_default_layer, "text", 0.3f, "OpenSans", 12U); // Tabs auto* tab1 = tab_bar->add_tab(".", scene2, scene2_default_layer, "OpenSans", 48u); auto* tab2 = tab_bar->add_tab("..", scene2, scene2_default_layer, "OpenSans", 48u); @@ -224,9 +213,14 @@ void Presenter::init_scene3(Camera* camera) { ui_system()->assign_camera_to_scene(scene3, camera); auto* scene3_camera_bottom_left_frame = ui_system()->get_scene_frame(scene3); - std::string text_static = "Test 123 \\c[128,0,0]i{Ja fajn} fiwasd \\c[0,128,0]b{dfsgndfugrefhewhfjkewjfdsjhjfhdsfjgkdffhjdsfjsdjfhdsjhfdsjhf} fawdsaf \\c[0,0,128]i{dwafsaf}dfwafsaffewfsdddddddddddddddddddddddddssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssassssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssassssssssssssssssssssssssssssss"; + auto* buffer_handler = root()->find<com::Folder>("handlers")->find<BufferHandler>(BufferHandler::self_name()); + + std::string text_static = "Test 123 \\c[128,0,0]i{Ja fajn} f\niwasd \\c[0,128,0]b{dfsgndfugrefhewhfjkewjfdsjhjfhdsfjgkdffhjdsfjsdjfhdsjhfdsjhf} fawdsaf \\c[0,0,128]i{dwafsaf}dfwafsaffewfsdddddddddddddddddddddddddssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssassssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssassssssssssssssssssssssssssssss"; auto* static_text = ui_system()->insert_element<StaticText>("static_text", scene3, scene3_default_layer, vec2i{600, 600}, text_static, true); + static_text->get_transform()->set_anchor(Anchor{.2f, .2f, .2f, 0.2f}); + static_text->register_handler(buffer_handler); auto* static_text_scroll_bar = ui_system()->insert_child_element<Slider>("static_text_slider", static_text, scene3, scene3_default_layer, vec2i(20, 300), 1.0f, VERTICAL); + static_text_scroll_bar->register_handler(buffer_handler); static_text_scroll_bar->get_transform()->set_anchor(Anchor{0.f, 1.0f, 0.0f, 0.0f}); static_text->request_fonts_to_load("OpenSans", 48U, true, true); @@ -262,6 +256,13 @@ void Presenter::init_scene4(Camera* camera) button6->request_fonts_to_load("OpenSans", 48U, true, true); button7->request_fonts_to_load("OpenSans", 48U, true, true); + auto* buffer_handler = root()->find<com::Folder>("handlers")->find<BufferHandler>(BufferHandler::self_name()); + button3->register_handler(buffer_handler); + button4->register_handler(buffer_handler); + button5->register_handler(buffer_handler); + button6->register_handler(buffer_handler); + button7->register_handler(buffer_handler); + ui_system()->set_parent_frame(button3, scene4_camera_bottom_left_frame); ui_system()->set_parent_frame(button4, scene4_camera_bottom_left_frame); ui_system()->set_parent_frame(button5, scene4_camera_bottom_left_frame); @@ -292,6 +293,42 @@ void Presenter::init_scene4(Camera* camera) // } } +void Presenter::init_3d_ui() +{ + auto* objects = ui_system()->create_scene("object"); + auto* objects_frame = ui_system()->get_scene_frame(objects); + + auto* box_frame = root()->push_back<com::Folder>("test_box")->push_back<com::Frame>(); + + ui_system()->assign_object_to_scene(objects, box_frame); + objects_frame->set_origin(vec3{-0.5f, 0.0f, 0.6f}); + + com::Folder* const test_box = object_system()->insert_object( + { "maker", "test_box" }, + ui_system()->get_default_pressed_material(), + buffer_generators()->insert_procedural_box_solid({ 0.5f, 0.5f, 0.5f } , "test_box", { "maker" }) + ); + object_system()->push_frame_back( + test_box, + box_frame + ); + + auto* progress_bar = ui_system()->insert_element<ProgressBar>("object_progress_bar", objects, ui_system()->get_default_scene_layer(objects), ui_system()->get_size_in_pixels(vec2(0.4, 0.1)), 0.5f); + auto* button = ui_system()->insert_element<Button>("object_button", objects, ui_system()->get_default_scene_layer(objects), ui_system()->get_size_in_pixels(vec2(0.1, 0.1)), "text"); + button->request_fonts_to_load("OpenSans", 48U, false, false); + ui_system()->set_parent_frame(progress_bar, objects_frame); + ui_system()->set_parent_frame(button, objects_frame); + button->get_frame()->set_origin(vec3{0.5f, 0.f, 0.7f}); + progress_bar->get_frame()->set_origin(vec3{0.6f, 0.f, 0.2f}); + progress_bar->get_frame()->move_rotation(to_quat(glm::radians(90.f), vec3{1.0f, 0.0f, 0.0f})); + progress_bar->get_frame()->move_rotation(to_quat(glm::radians(90.f), vec3{.0f, 0.0f, 1.0f})); + button->get_frame()->move_rotation(to_quat(glm::radians(90.f), vec3{1.0f, 0.0f, 0.0f})); + button->get_frame()->move_rotation(to_quat(glm::radians(90.f), vec3{.0f, 0.0f, 1.0f})); + + ui_system()->insert_objects(progress_bar, objects); + ui_system()->insert_objects(button, objects); +} + void Presenter::release() { osi::presenters()->find<com::Folder>("maker")->erase(self_name() + ".link"); @@ -318,12 +355,18 @@ void Presenter::next_round() camera_system()->activate_default_camera(); camera_system()->set_frame(camera_system()->default_camera_folder(), camera_frame()); renderer()->present_collection(object_system()->objects()->find<com::Folder>("grid"), Renderer::pipeline::FORWARD); + renderer()->present_collection(gfx::object_system()->objects()->find<com::Folder>("maker"), gfx::Renderer::pipeline::FORWARD); // Present ui scene - ui_system()->present_current_scene(); + if (ui_system()->get_current_scene()->name() == "object") + { + ui_system()->present_current_scene(false); + } else + { + ui_system()->present_current_scene(true); + } //gfx::renderer()->present_collection(gfx::object_system()->objects(), gfx::Renderer::pipeline::FORWARD); - //gfx::renderer()->present_collection(gfx::object_system()->objects()->find<com::Folder>("maker"), gfx::Renderer::pipeline::FORWARD); } }