diff --git a/examples/animation_2d.cpp b/examples/animation_2d.cpp index 897db894..45bf94df 100644 --- a/examples/animation_2d.cpp +++ b/examples/animation_2d.cpp @@ -1520,7 +1520,7 @@ void animation_2d_app::present() opts.c = gfx::black; opts.x = gfx::painter::x_align::left; opts.y = gfx::painter::y_align::top; - opts.scale = 2.f; + opts.scale = {2.f, 2.f}; painter.text({40.f, 40.f}, util::to_string(train_iterations, "/", max_train_iterations), opts); painter.text({40.f, 64.f}, util::to_string("Best score: ", std::setprecision(10), best_score), opts); painter.text({40.f, 88.f}, util::to_string("Model: ", test_id, "/", population.size(), ", gen ", population[test_id].generation), opts); diff --git a/examples/audio.cpp b/examples/audio.cpp index 9841ac39..f9d3ae47 100644 --- a/examples/audio.cpp +++ b/examples/audio.cpp @@ -158,7 +158,7 @@ struct audio_app float y = state().size[1] / 2.f + size * std::size(key_rows) / 2.f; gfx::painter::text_options opts; - opts.scale = 2.f; + opts.scale = {2.f, 2.f}; opts.c = {0, 0, 0, 255}; opts.x = gfx::painter::x_align::center; opts.y = gfx::painter::y_align::center; @@ -185,7 +185,7 @@ struct audio_app } } - opts.scale = 4.f; + opts.scale = {4.f, 4.f}; opts.c = pause_control_->paused() ? gfx::color_rgba{255, 0, 0, 255} : gfx::color_rgba{0, 127, 0, 255}; painter_.text({state().size[0] / 2.f, state().size[1] - 200.f}, pause_control_->paused() ? "PAUSED" : "PLAYING", opts); diff --git a/examples/cloud.cpp b/examples/cloud.cpp index dec588fe..274d5b3c 100644 --- a/examples/cloud.cpp +++ b/examples/cloud.cpp @@ -51,7 +51,7 @@ auto barycenter(Iterator begin, Iterator end) template auto barycenter(Container const & c) { - return barycenter(util::begin(c), util::end(c)); + return barycenter(util::xbegin(c), util::xend(c)); } std::vector> intersection(math::vector const & f, std::vector> const & vertices, std::vector> const & edges) diff --git a/examples/deferred.cpp b/examples/deferred.cpp index 1455c059..19c937ec 100644 --- a/examples/deferred.cpp +++ b/examples/deferred.cpp @@ -484,7 +484,7 @@ void deferred_app::present() { gfx::painter::text_options opts; - opts.scale = 2.f; + opts.scale = {2.f, 2.f}; opts.f = gfx::painter::font::font_9x12; opts.x = gfx::painter::x_align::left; opts.y = gfx::painter::y_align::top; diff --git a/examples/gravity.cpp b/examples/gravity.cpp index a7d3da03..b31cc3a0 100644 --- a/examples/gravity.cpp +++ b/examples/gravity.cpp @@ -1211,7 +1211,7 @@ struct myapp { gfx::painter::text_options opts; - opts.scale = 3.f; + opts.scale = {3.f, 3.f}; opts.c = {0, 0, 0, 255}; opts.x = gfx::painter::x_align::center; opts.y = gfx::painter::y_align::top; diff --git a/examples/physics.cpp b/examples/physics.cpp index e58f7ed9..6a80550d 100644 --- a/examples/physics.cpp +++ b/examples/physics.cpp @@ -844,7 +844,7 @@ void physics_demo_app::present() opts.y = gfx::painter::y_align::top; opts.c = gfx::black; opts.f = gfx::painter::font::font_9x12; - opts.scale = 2.f; + opts.scale = {2.f, 2.f}; float y = 10.f; for (std::size_t i = 0;;) diff --git a/examples/soft_creatures_2d.cpp b/examples/soft_creatures_2d.cpp index 6d0e4125..bc1664b1 100644 --- a/examples/soft_creatures_2d.cpp +++ b/examples/soft_creatures_2d.cpp @@ -611,7 +611,7 @@ struct soft_creatures_2d_app float scale = 2.f * view_box[0].length() / state().size[0]; painter_.line({x, 0.f}, {x, y}, 0.125f, {255, 255, 255, 255}, false); - painter_.text3d({x + 0.1f, -0.5f, 0.f}, util::to_string(r * 5), {.scale = scale, .x = gfx::painter::x_align::left, .c = {255, 255, 255, 127}}, math::scale({1.f, -1.f, 1.f}).linear_matrix()); + painter_.text3d({x + 0.1f, -0.5f, 0.f}, util::to_string(r * 5), {.scale = {scale, scale}, .x = gfx::painter::x_align::left, .c = {255, 255, 255, 127}}, math::scale({1.f, -1.f, 1.f}).linear_matrix()); } draw(painter_, display_creatures_[c]); @@ -625,8 +625,8 @@ struct soft_creatures_2d_app int text_row = 0; auto put_line = [&](std::string const & line) { - painter_.text({13.f, 10.f + text_row * 24.f}, line, {.scale = 2.f, .x = gfx::painter::x_align::left, .y = gfx::painter::y_align::top, .c = {0, 0, 0, 255}}); - painter_.text({12.f, 9.f + text_row * 24.f}, line, {.scale = 2.f, .x = gfx::painter::x_align::left, .y = gfx::painter::y_align::top, .c = {255, 255, 255, 255}}); + painter_.text({13.f, 10.f + text_row * 24.f}, line, {.scale = {2.f, 2.f}, .x = gfx::painter::x_align::left, .y = gfx::painter::y_align::top, .c = {0, 0, 0, 255}}); + painter_.text({12.f, 9.f + text_row * 24.f}, line, {.scale = {2.f, 2.f}, .x = gfx::painter::x_align::left, .y = gfx::painter::y_align::top, .c = {255, 255, 255, 255}}); ++text_row; }; @@ -654,15 +654,15 @@ struct soft_creatures_2d_app float y = (c * state().size[1] * 1.f) / display_creatures_.size() + 9.f; auto text = util::to_string("Gen ", display_creatures_[c].generation); - painter_.text({x + 1.f, y + 1.f}, text, {.scale = 2.f, .x = gfx::painter::x_align::right, .y = gfx::painter::y_align::top, .c = {0, 0, 0, 255}}); - painter_.text({x, y}, text, {.scale = 2.f, .x = gfx::painter::x_align::right, .y = gfx::painter::y_align::top, .c = {255, 255, 255, 255}}); + painter_.text({x + 1.f, y + 1.f}, text, {.scale = {2.f, 2.f}, .x = gfx::painter::x_align::right, .y = gfx::painter::y_align::top, .c = {0, 0, 0, 255}}); + painter_.text({x, y}, text, {.scale = {2.f, 2.f}, .x = gfx::painter::x_align::right, .y = gfx::painter::y_align::top, .c = {255, 255, 255, 255}}); if (display_creatures_[c].score) { y += 24.f; auto text = util::to_string("Score ", *display_creatures_[c].score); - painter_.text({x + 1.f, y + 1.f}, text, {.scale = 2.f, .x = gfx::painter::x_align::right, .y = gfx::painter::y_align::top, .c = {0, 0, 0, 255}}); - painter_.text({x, y}, text, {.scale = 2.f, .x = gfx::painter::x_align::right, .y = gfx::painter::y_align::top, .c = {255, 255, 255, 255}}); + painter_.text({x + 1.f, y + 1.f}, text, {.scale = {2.f, 2.f}, .x = gfx::painter::x_align::right, .y = gfx::painter::y_align::top, .c = {0, 0, 0, 255}}); + painter_.text({x, y}, text, {.scale = {2.f, 2.f}, .x = gfx::painter::x_align::right, .y = gfx::painter::y_align::top, .c = {255, 255, 255, 255}}); } } diff --git a/examples/soft_plants_2d.cpp b/examples/soft_plants_2d.cpp index 7ff04e87..42a59a86 100644 --- a/examples/soft_plants_2d.cpp +++ b/examples/soft_plants_2d.cpp @@ -1024,8 +1024,8 @@ struct soft_creatures_2d_app int text_row = 0; auto put_line = [&](std::string const & line) { - painter_.text({13.f, 10.f + text_row * 24.f}, line, {.scale = 2.f, .x = gfx::painter::x_align::left, .y = gfx::painter::y_align::top, .c = {0, 0, 0, 255}}); - painter_.text({12.f, 9.f + text_row * 24.f}, line, {.scale = 2.f, .x = gfx::painter::x_align::left, .y = gfx::painter::y_align::top, .c = {255, 255, 255, 255}}); + painter_.text({13.f, 10.f + text_row * 24.f}, line, {.scale = {2.f, 2.f}, .x = gfx::painter::x_align::left, .y = gfx::painter::y_align::top, .c = {0, 0, 0, 255}}); + painter_.text({12.f, 9.f + text_row * 24.f}, line, {.scale = {2.f, 2.f}, .x = gfx::painter::x_align::left, .y = gfx::painter::y_align::top, .c = {255, 255, 255, 255}}); ++text_row; }; diff --git a/examples/srtm.cpp b/examples/srtm.cpp index 0454d87b..cec65db4 100644 --- a/examples/srtm.cpp +++ b/examples/srtm.cpp @@ -1007,7 +1007,7 @@ void srtm_app::present() opts.y = gfx::painter::y_align::top; opts.f = gfx::painter::font::font_9x12; opts.c = gfx::gray; - opts.scale = 2.f; + opts.scale = {2.f, 2.f}; for (int l = 0; l < info.size(); ++l) { diff --git a/examples/triangulation.cpp b/examples/triangulation.cpp index 195cb69c..e0cf611e 100644 --- a/examples/triangulation.cpp +++ b/examples/triangulation.cpp @@ -174,7 +174,7 @@ struct triangulation_app opts.c = {0, 0, 0, 255}; opts.x = gfx::painter::x_align::left; opts.y = gfx::painter::y_align::bottom; - opts.scale = 2.f; + opts.scale = {2.f, 2.f}; auto p = math::swizzle<0, 1>(math::as_point(camera_transform * math::homogeneous(math::swizzle<0, 1, -1>(points_[i])))); p[0] = std::round((p[0] * 0.5f + 0.5f) * state().size[0]); p[1] = std::round((0.5f - p[1] * 0.5f) * state().size[1]); diff --git a/libs/app/CMakeLists.txt b/libs/app/CMakeLists.txt index 54c3ade2..50d95f97 100644 --- a/libs/app/CMakeLists.txt +++ b/libs/app/CMakeLists.txt @@ -1,11 +1,6 @@ file(GLOB_RECURSE PSEMEK_APP_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "include/*.hpp") file(GLOB_RECURSE PSEMEK_APP_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "source/*.cpp") -if(NOT PSEMEK_LEGACY_UI) - list(REMOVE_ITEM PSEMEK_APP_HEADERS "include/psemek/app/ui_scene_legacy.hpp") - list(REMOVE_ITEM PSEMEK_APP_SOURCES "source/ui_scene_legacy.cpp") -endif() - psemek_add_library(psemek-app ${PSEMEK_APP_HEADERS} ${PSEMEK_APP_SOURCES}) target_include_directories(psemek-app PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(psemek-app PUBLIC psemek-log psemek-util psemek-gfx) diff --git a/libs/app/include/psemek/app/application_base.hpp b/libs/app/include/psemek/app/application_base.hpp index 26fbb14a..2dfa0448 100644 --- a/libs/app/include/psemek/app/application_base.hpp +++ b/libs/app/include/psemek/app/application_base.hpp @@ -3,8 +3,6 @@ #include #include -#include - namespace psemek::app { diff --git a/libs/ui_legacy/CMakeLists.txt b/libs/ui_legacy/CMakeLists.txt index f2e526c4..21468b5e 100644 --- a/libs/ui_legacy/CMakeLists.txt +++ b/libs/ui_legacy/CMakeLists.txt @@ -3,7 +3,7 @@ file(GLOB_RECURSE PSEMEK_UI_SOURCES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "sour psemek_add_library(psemek-ui_legacy ${PSEMEK_UI_HEADERS} ${PSEMEK_UI_SOURCES}) target_include_directories(psemek-ui_legacy PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") -target_link_libraries(psemek-ui_legacy PUBLIC psemek-util psemek-log psemek-geom psemek-cg psemek-gfx psemek-async psemek-sdl2 rapidjson) +target_link_libraries(psemek-ui_legacy PUBLIC psemek-util psemek-log psemek-math psemek-cg psemek-gfx psemek-fonts psemek-async psemek-sdl2 rapidjson) psemek_glob_resources(psemek-ui_legacy resources psemek/ui/resources) diff --git a/libs/ui_legacy/include/psemek/ui/controller.hpp b/libs/ui_legacy/include/psemek/ui/controller.hpp index e155ac25..ab8169a5 100644 --- a/libs/ui_legacy/include/psemek/ui/controller.hpp +++ b/libs/ui_legacy/include/psemek/ui/controller.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include #include diff --git a/libs/ui_legacy/include/psemek/ui/label.hpp b/libs/ui_legacy/include/psemek/ui/label.hpp index 4b9573ba..fbda65d7 100644 --- a/libs/ui_legacy/include/psemek/ui/label.hpp +++ b/libs/ui_legacy/include/psemek/ui/label.hpp @@ -150,7 +150,7 @@ namespace psemek::ui std::vector batches; math::vector size{0.f, 0.f}; - ui::font_type font_type = ui::font_type::bitmap; + fonts::font_type font_type = fonts::font_type::bitmap; float sdf_scale = 0.f; std::vector, std::string>> link_bboxes; diff --git a/libs/ui_legacy/include/psemek/ui/painter.hpp b/libs/ui_legacy/include/psemek/ui/painter.hpp index 7051e010..e2230cd2 100644 --- a/libs/ui_legacy/include/psemek/ui/painter.hpp +++ b/libs/ui_legacy/include/psemek/ui/painter.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include diff --git a/libs/ui_legacy/include/psemek/ui/style.hpp b/libs/ui_legacy/include/psemek/ui/style.hpp index d47e48ad..e7b3925c 100644 --- a/libs/ui_legacy/include/psemek/ui/style.hpp +++ b/libs/ui_legacy/include/psemek/ui/style.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include @@ -70,8 +70,8 @@ namespace psemek::ui std::optional link_click_color; std::optional link_click_style; - std::shared_ptr font; - std::shared_ptr bold_font; + std::shared_ptr font; + std::shared_ptr bold_font; mutable std::unordered_set use_as_style; mutable std::unordered_set use_as_own_style; diff --git a/libs/ui_legacy/source/default_element_factory.cpp b/libs/ui_legacy/source/default_element_factory.cpp index 05ac9d06..baccad75 100644 --- a/libs/ui_legacy/source/default_element_factory.cpp +++ b/libs/ui_legacy/source/default_element_factory.cpp @@ -1073,7 +1073,7 @@ namespace psemek::ui default_element_factory::impl::impl() { - close_icon = std::make_shared(gfx::texture_2d::from_pixmap(gfx::read_png(io::memory_istream{resources::cross_red_16x16_png.data}))); + close_icon = std::make_shared(gfx::texture_2d::from_pixmap(gfx::read_image(io::memory_istream{resources::cross_red_16x16_png.data}))); close_icon->nearest_filter(); } diff --git a/libs/ui_legacy/source/default_fonts.cpp b/libs/ui_legacy/source/default_fonts.cpp deleted file mode 100644 index b4305c4b..00000000 --- a/libs/ui_legacy/source/default_fonts.cpp +++ /dev/null @@ -1,97 +0,0 @@ -#include -#include -#include - -#include -#include -#include -#include - -#include - -#include - -namespace psemek::ui -{ - - std::unique_ptr make_default_monospace_9x12_font() - { - character_range range{32, 128}; - std::string_view name = "default_monospace_9x12"; - math::vector size{9, 12}; - - gfx::texture_2d atlas = gfx::texture_2d::from_pixmap(gfx::read_png_monochrome(io::memory_istream{gfx::resource::font_9x12_png.data})); - atlas.nearest_filter(); - atlas.clamp(); - gl::TexParameteri(atlas.target, gl::TEXTURE_SWIZZLE_G, gl::RED); - gl::TexParameteri(atlas.target, gl::TEXTURE_SWIZZLE_B, gl::RED); - gl::TexParameteri(atlas.target, gl::TEXTURE_SWIZZLE_A, gl::RED); - - std::vector> texcoords(range.end - range.begin); - - for (char32_t c = range.begin; c < range.end; ++c) - { - int const row = 16; - int x = (c - range.begin) % row; - int y = (c - range.begin) / row; - - math::box b; - b[0].min = x * 11 + 1; - b[0].max = b[0].min + 9; - b[1].min = y * 14 + 1; - b[1].max = b[1].min + 12; - texcoords[c - range.begin] = b; - } - - return std::make_unique(range, name, size, std::move(atlas), std::move(texcoords)); - } - - static std::unique_ptr make_default_font(std::string_view name, math::vector const & size, rs::resource const & atlas_resource, rs::resource const & glyphs_resource) - { - gfx::texture_2d atlas = gfx::texture_2d::from_pixmap(gfx::read_png_monochrome(io::memory_istream{atlas_resource.data})); - atlas.nearest_filter(); - atlas.clamp(); - gl::TexParameteri(atlas.target, gl::TEXTURE_SWIZZLE_G, gl::RED); - gl::TexParameteri(atlas.target, gl::TEXTURE_SWIZZLE_B, gl::RED); - gl::TexParameteri(atlas.target, gl::TEXTURE_SWIZZLE_A, gl::RED); - - bmfont_data data; - data.name = name; - data.size = size; - data.baseline = 2; - - { - std::istringstream is{std::string(glyphs_resource.data)}; - - std::string line; - while (std::getline(is, line)) - { - if (auto pos = line.find('#'); pos != std::string::npos) - line = line.substr(0, pos); - - if (line.empty()) continue; - - std::istringstream is{std::move(line)}; - - int c; - is >> c; - auto & glyph = data.glyphs[c]; - - is >> glyph.start_x >> glyph.start_y >> glyph.size_x >> glyph.size_y >> glyph.offset_x >> glyph.offset_y >> glyph.advance; - } - } - - return std::make_unique(std::move(data), std::move(atlas)); - } - - std::unique_ptr make_default_9x12_font() - { - return make_default_font("default_9x12", {9, 12}, gfx::resource::font_9x12_png, ui::resources::font_9x12_glyphs_txt); - } - - std::unique_ptr make_default_10x12_bold_font() - { - return make_default_font("default_10x12_bold", {10, 12}, gfx::resource::font_10x12_bold_png, ui::resources::font_10x12_bold_glyphs_txt); - } - -} diff --git a/libs/ui_legacy/source/edit.cpp b/libs/ui_legacy/source/edit.cpp index beb83673..17a4e8bb 100644 --- a/libs/ui_legacy/source/edit.cpp +++ b/libs/ui_legacy/source/edit.cpp @@ -101,14 +101,17 @@ namespace psemek::ui bool edit::on_event(mouse_move const & e) { + static auto beam_cursor = sdl2::get_default_cursor(sdl2::default_cursor_type::beam); + static auto arrow_cursor = sdl2::get_default_cursor(sdl2::default_cursor_type::arrow); + auto m = math::cast(e.position); mouse_x_ = m[0]; bool new_mouseover = shape_.contains(m); if (!mouseover_ && new_mouseover) - sdl2::set_cursor(sdl2::cursor_type::beam); + sdl2::set_cursor(*beam_cursor); else if (mouseover_ && !new_mouseover) - sdl2::set_cursor(sdl2::cursor_type::arrow); + sdl2::set_cursor(*arrow_cursor); mouseover_ = new_mouseover; return false; @@ -393,7 +396,7 @@ namespace psemek::ui cached_state state; state.texture = &font->atlas(); - shape_options options; + fonts::shape_options options; options.scale = *st->text_scale; auto glyphs = font->shape(text_, options); diff --git a/libs/ui_legacy/source/file_dialog.cpp b/libs/ui_legacy/source/file_dialog.cpp index ac3e12dc..eb6c01d5 100644 --- a/libs/ui_legacy/source/file_dialog.cpp +++ b/libs/ui_legacy/source/file_dialog.cpp @@ -73,13 +73,13 @@ namespace psemek::ui { file_dialog_image_provider() { - back_.load(gfx::read_png(io::memory_istream(resources::back_png.data))); + back_.load(gfx::read_image(io::memory_istream(resources::back_png.data))); back_.linear_filter(); - folder_.load(gfx::read_png(io::memory_istream(resources::folder_png.data))); + folder_.load(gfx::read_image(io::memory_istream(resources::folder_png.data))); folder_.linear_filter(); - file_.load(gfx::read_png(io::memory_istream(resources::file_png.data))); + file_.load(gfx::read_image(io::memory_istream(resources::file_png.data))); file_.linear_filter(); } diff --git a/libs/ui_legacy/source/label.cpp b/libs/ui_legacy/source/label.cpp index 5d3b4db3..45f62066 100644 --- a/libs/ui_legacy/source/label.cpp +++ b/libs/ui_legacy/source/label.cpp @@ -20,7 +20,8 @@ namespace psemek::ui { if (selected_link_) { - sdl2::set_cursor(sdl2::cursor_type::arrow); + static auto arrow_cursor = sdl2::get_default_cursor(sdl2::default_cursor_type::arrow); + sdl2::set_cursor(*arrow_cursor); selected_link_ = std::nullopt; } text_ = std::move(text); @@ -66,7 +67,8 @@ namespace psemek::ui { if (selected_link_) { - sdl2::set_cursor(sdl2::cursor_type::arrow); + static auto arrow_cursor = sdl2::get_default_cursor(sdl2::default_cursor_type::arrow); + sdl2::set_cursor(*arrow_cursor); selected_link_ = std::nullopt; } text_ = std::move(text); @@ -232,10 +234,13 @@ namespace psemek::ui if (new_selected_link != selected_link_) { + static auto arrow_cursor = sdl2::get_default_cursor(sdl2::default_cursor_type::arrow); + static auto hand_cursor = sdl2::get_default_cursor(sdl2::default_cursor_type::hand); + if (new_selected_link) - sdl2::set_cursor(sdl2::cursor_type::hand); + sdl2::set_cursor(*hand_cursor); else - sdl2::set_cursor(sdl2::cursor_type::arrow); + sdl2::set_cursor(*arrow_cursor); if (link_mouseover_callback_) post([cb = link_mouseover_callback_, value = new_selected_link]{ @@ -340,9 +345,9 @@ namespace psemek::ui color[3] = (color[3] * 1.f * batch.color[3]) / 255.f; for (auto const & image : batch.images) { - if (cached_state_->font_type == font_type::bitmap) + if (cached_state_->font_type == fonts::font_type::bitmap) p.draw_image(image.position + offset, gfx::texture_view_2d{batch.texture, image.texcoords}, {color, painter::color_mode::multiply}); - else if (cached_state_->font_type == font_type::msdf) + else if (cached_state_->font_type == fonts::font_type::msdf) p.draw_msdf_glyph(image.position + offset, gfx::texture_view_2d{batch.texture, image.texcoords}, cached_state_->sdf_scale, {color}); } } @@ -352,9 +357,9 @@ namespace psemek::ui { for (auto const & image : batch.images) { - if (cached_state_->font_type == font_type::bitmap) + if (cached_state_->font_type == fonts::font_type::bitmap) p.draw_image(image.position, gfx::texture_view_2d{batch.texture, image.texcoords}, {batch.color, batch.text ? painter::color_mode::multiply : painter::color_mode::mix}); - else if (cached_state_->font_type == font_type::msdf) + else if (cached_state_->font_type == fonts::font_type::msdf) p.draw_msdf_glyph(image.position, gfx::texture_view_2d{batch.texture, image.texcoords}, cached_state_->sdf_scale, {batch.color}); } } @@ -414,7 +419,7 @@ namespace psemek::ui { math::point pen{0.f, 0.f}; - shape_options opts; + fonts::shape_options opts; opts.scale = *st->text_scale; for (auto const & chunk : chunks_) diff --git a/libs/ui_legacy/source/ui_scene_legacy.cpp b/libs/ui_legacy/source/ui_scene_legacy.cpp deleted file mode 100644 index 22fbd7bd..00000000 --- a/libs/ui_legacy/source/ui_scene_legacy.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include - -#include - -namespace psemek::app -{ - - ui_scene::ui_scene(ui::controller & controller) - : controller_(controller) - {} - - void ui_scene::on_scene_enter(app * parent) - { - scene_base::on_scene_enter(parent); - controller_.set_root(ui_); - update_clock_.restart(); - } - - void ui_scene::on_scene_exit() - { - scene_base::on_scene_exit(); - controller_.set_root(nullptr); - } - - void ui_scene::on_resize(int width, int height) - { - scene_base::on_resize(width, height); - controller_.reshape({{{0.f, width}, {0.f, height}}}); - } - - void ui_scene::on_mouse_move(int x, int y, int dx, int dy) - { - scene_base::on_mouse_move(x, y, dx, dy); - controller_.event(ui::mouse_move{{x, y}}); - } - - void ui_scene::on_mouse_wheel(int delta) - { - scene_base::on_mouse_wheel(delta); - controller_.event(ui::mouse_wheel{delta}); - } - - void ui_scene::on_left_button_down() - { - scene_base::on_left_button_down(); - controller_.event(ui::mouse_click{ui::mouse_button::left, true}); - } - - void ui_scene::on_left_button_up() - { - scene_base::on_left_button_up(); - controller_.event(ui::mouse_click{ui::mouse_button::left, false}); - } - - void ui_scene::on_middle_button_down() - { - scene_base::on_left_button_down(); - controller_.event(ui::mouse_click{ui::mouse_button::middle, true}); - } - - void ui_scene::on_middle_button_up() - { - scene_base::on_left_button_down(); - controller_.event(ui::mouse_click{ui::mouse_button::middle, false}); - } - - void ui_scene::on_right_button_down() - { - scene_base::on_right_button_down(); - controller_.event(ui::mouse_click{ui::mouse_button::right, true}); - } - - void ui_scene::on_right_button_up() - { - scene_base::on_right_button_down(); - controller_.event(ui::mouse_click{ui::mouse_button::right, false}); - } - - void ui_scene::on_key_down(SDL_Keycode key) - { - scene_base::on_key_down(key); - controller_.event(ui::key_press{key, true}); - } - - void ui_scene::on_key_up(SDL_Keycode key) - { - scene_base::on_key_up(key); - controller_.event(ui::key_press{key, false}); - } - - void ui_scene::on_text_input(std::string_view text) - { - scene_base::on_text_input(text); - controller_.event(ui::text_input{text}); - } - - void ui_scene::update() - { - controller_.update(update_clock_.restart().count()); - std::size_t events = controller_.loop()->pump(max_events_per_frame_); - if (max_events_per_frame_ && events == *max_events_per_frame_) - log::warning() << "UI event loop had more than " << *max_events_per_frame_ << " events, delaying others"; - } - - void ui_scene::present() - { - gfx::render_target rt; - rt.viewport = {{{0, width()}, {0, height()}}}; - rt.framebuffer = &gfx::framebuffer::null(); - rt.draw_buffer = gl::BACK_LEFT; - controller_.render(rt); - } - - void ui_scene::set_ui(std::shared_ptr ui) - { - ui_ = std::move(ui); - if (active()) - controller_.set_root(ui_); - } - -}