Compilation fixes related to ui_legacy lib

This commit is contained in:
Nikita Lisitsa 2025-01-21 14:08:12 +03:00
parent b967af7ddd
commit 3940766f7d
23 changed files with 47 additions and 266 deletions

View file

@ -1520,7 +1520,7 @@ void animation_2d_app::present()
opts.c = gfx::black; opts.c = gfx::black;
opts.x = gfx::painter::x_align::left; opts.x = gfx::painter::x_align::left;
opts.y = gfx::painter::y_align::top; 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, 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, 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); painter.text({40.f, 88.f}, util::to_string("Model: ", test_id, "/", population.size(), ", gen ", population[test_id].generation), opts);

View file

@ -158,7 +158,7 @@ struct audio_app
float y = state().size[1] / 2.f + size * std::size(key_rows) / 2.f; float y = state().size[1] / 2.f + size * std::size(key_rows) / 2.f;
gfx::painter::text_options opts; gfx::painter::text_options opts;
opts.scale = 2.f; opts.scale = {2.f, 2.f};
opts.c = {0, 0, 0, 255}; opts.c = {0, 0, 0, 255};
opts.x = gfx::painter::x_align::center; opts.x = gfx::painter::x_align::center;
opts.y = gfx::painter::y_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}; 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); painter_.text({state().size[0] / 2.f, state().size[1] - 200.f}, pause_control_->paused() ? "PAUSED" : "PLAYING", opts);

View file

@ -51,7 +51,7 @@ auto barycenter(Iterator begin, Iterator end)
template <typename Container> template <typename Container>
auto barycenter(Container const & c) auto barycenter(Container const & c)
{ {
return barycenter(util::begin(c), util::end(c)); return barycenter(util::xbegin(c), util::xend(c));
} }
std::vector<math::point<float, 3>> intersection(math::vector<float, 4> const & f, std::vector<math::point<float, 3>> const & vertices, std::vector<math::segment<std::uint32_t>> const & edges) std::vector<math::point<float, 3>> intersection(math::vector<float, 4> const & f, std::vector<math::point<float, 3>> const & vertices, std::vector<math::segment<std::uint32_t>> const & edges)

View file

@ -484,7 +484,7 @@ void deferred_app::present()
{ {
gfx::painter::text_options opts; gfx::painter::text_options opts;
opts.scale = 2.f; opts.scale = {2.f, 2.f};
opts.f = gfx::painter::font::font_9x12; opts.f = gfx::painter::font::font_9x12;
opts.x = gfx::painter::x_align::left; opts.x = gfx::painter::x_align::left;
opts.y = gfx::painter::y_align::top; opts.y = gfx::painter::y_align::top;

View file

@ -1211,7 +1211,7 @@ struct myapp
{ {
gfx::painter::text_options opts; gfx::painter::text_options opts;
opts.scale = 3.f; opts.scale = {3.f, 3.f};
opts.c = {0, 0, 0, 255}; opts.c = {0, 0, 0, 255};
opts.x = gfx::painter::x_align::center; opts.x = gfx::painter::x_align::center;
opts.y = gfx::painter::y_align::top; opts.y = gfx::painter::y_align::top;

View file

@ -844,7 +844,7 @@ void physics_demo_app::present()
opts.y = gfx::painter::y_align::top; opts.y = gfx::painter::y_align::top;
opts.c = gfx::black; opts.c = gfx::black;
opts.f = gfx::painter::font::font_9x12; opts.f = gfx::painter::font::font_9x12;
opts.scale = 2.f; opts.scale = {2.f, 2.f};
float y = 10.f; float y = 10.f;
for (std::size_t i = 0;;) for (std::size_t i = 0;;)

View file

@ -611,7 +611,7 @@ struct soft_creatures_2d_app
float scale = 2.f * view_box[0].length() / state().size[0]; 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_.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<float, 3>({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<float, 3>({1.f, -1.f, 1.f}).linear_matrix());
} }
draw(painter_, display_creatures_[c]); draw(painter_, display_creatures_[c]);
@ -625,8 +625,8 @@ struct soft_creatures_2d_app
int text_row = 0; int text_row = 0;
auto put_line = [&](std::string const & line) 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({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, .x = gfx::painter::x_align::left, .y = gfx::painter::y_align::top, .c = {255, 255, 255, 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; ++text_row;
}; };
@ -654,15 +654,15 @@ struct soft_creatures_2d_app
float y = (c * state().size[1] * 1.f) / display_creatures_.size() + 9.f; float y = (c * state().size[1] * 1.f) / display_creatures_.size() + 9.f;
auto text = util::to_string("Gen ", display_creatures_[c].generation); 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 + 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, .x = gfx::painter::x_align::right, .y = gfx::painter::y_align::top, .c = {255, 255, 255, 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) if (display_creatures_[c].score)
{ {
y += 24.f; y += 24.f;
auto text = util::to_string("Score ", *display_creatures_[c].score); 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 + 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, .x = gfx::painter::x_align::right, .y = gfx::painter::y_align::top, .c = {255, 255, 255, 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}});
} }
} }

View file

@ -1024,8 +1024,8 @@ struct soft_creatures_2d_app
int text_row = 0; int text_row = 0;
auto put_line = [&](std::string const & line) 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({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, .x = gfx::painter::x_align::left, .y = gfx::painter::y_align::top, .c = {255, 255, 255, 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; ++text_row;
}; };

View file

@ -1007,7 +1007,7 @@ void srtm_app::present()
opts.y = gfx::painter::y_align::top; opts.y = gfx::painter::y_align::top;
opts.f = gfx::painter::font::font_9x12; opts.f = gfx::painter::font::font_9x12;
opts.c = gfx::gray; opts.c = gfx::gray;
opts.scale = 2.f; opts.scale = {2.f, 2.f};
for (int l = 0; l < info.size(); ++l) for (int l = 0; l < info.size(); ++l)
{ {

View file

@ -174,7 +174,7 @@ struct triangulation_app
opts.c = {0, 0, 0, 255}; opts.c = {0, 0, 0, 255};
opts.x = gfx::painter::x_align::left; opts.x = gfx::painter::x_align::left;
opts.y = gfx::painter::y_align::bottom; 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])))); 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[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]); p[1] = std::round((0.5f - p[1] * 0.5f) * state().size[1]);

View file

@ -1,11 +1,6 @@
file(GLOB_RECURSE PSEMEK_APP_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "include/*.hpp") 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") 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}) psemek_add_library(psemek-app ${PSEMEK_APP_HEADERS} ${PSEMEK_APP_SOURCES})
target_include_directories(psemek-app PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include") target_include_directories(psemek-app PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_link_libraries(psemek-app PUBLIC psemek-log psemek-util psemek-gfx) target_link_libraries(psemek-app PUBLIC psemek-log psemek-util psemek-gfx)

View file

@ -3,8 +3,6 @@
#include <psemek/app/application.hpp> #include <psemek/app/application.hpp>
#include <psemek/app/event_state.hpp> #include <psemek/app/event_state.hpp>
#include <vector>
namespace psemek::app namespace psemek::app
{ {

View file

@ -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}) 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_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) psemek_glob_resources(psemek-ui_legacy resources psemek/ui/resources)

View file

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <psemek/ui/element.hpp> #include <psemek/ui/element.hpp>
#include <psemek/ui/font.hpp>
#include <psemek/gfx/render_target.hpp> #include <psemek/gfx/render_target.hpp>
#include <psemek/util/pimpl.hpp> #include <psemek/util/pimpl.hpp>
#include <psemek/util/function.hpp> #include <psemek/util/function.hpp>

View file

@ -150,7 +150,7 @@ namespace psemek::ui
std::vector<batch> batches; std::vector<batch> batches;
math::vector<float, 2> size{0.f, 0.f}; math::vector<float, 2> 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; float sdf_scale = 0.f;
std::vector<std::pair<math::box<float, 2>, std::string>> link_bboxes; std::vector<std::pair<math::box<float, 2>, std::string>> link_bboxes;

View file

@ -1,6 +1,5 @@
#pragma once #pragma once
#include <psemek/ui/font.hpp>
#include <psemek/gfx/color.hpp> #include <psemek/gfx/color.hpp>
#include <psemek/gfx/texture.hpp> #include <psemek/gfx/texture.hpp>
#include <psemek/gfx/texture_view.hpp> #include <psemek/gfx/texture_view.hpp>

View file

@ -1,7 +1,7 @@
#pragma once #pragma once
#include <psemek/util/flag_set.hpp> #include <psemek/util/flag_set.hpp>
#include <psemek/ui/font.hpp> #include <psemek/fonts/font.hpp>
#include <psemek/gfx/color.hpp> #include <psemek/gfx/color.hpp>
#include <optional> #include <optional>
@ -70,8 +70,8 @@ namespace psemek::ui
std::optional<gfx::color_rgba> link_click_color; std::optional<gfx::color_rgba> link_click_color;
std::optional<ui::text_style> link_click_style; std::optional<ui::text_style> link_click_style;
std::shared_ptr<struct font> font; std::shared_ptr<fonts::font> font;
std::shared_ptr<struct font> bold_font; std::shared_ptr<fonts::font> bold_font;
mutable std::unordered_set<element *> use_as_style; mutable std::unordered_set<element *> use_as_style;
mutable std::unordered_set<element *> use_as_own_style; mutable std::unordered_set<element *> use_as_own_style;

View file

@ -1073,7 +1073,7 @@ namespace psemek::ui
default_element_factory::impl::impl() default_element_factory::impl::impl()
{ {
close_icon = std::make_shared<gfx::texture_2d>(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>(gfx::texture_2d::from_pixmap(gfx::read_image<gfx::color_rgba>(io::memory_istream{resources::cross_red_16x16_png.data})));
close_icon->nearest_filter(); close_icon->nearest_filter();
} }

View file

@ -1,97 +0,0 @@
#include <psemek/ui/font.hpp>
#include <psemek/ui/monospace_font.hpp>
#include <psemek/ui/kerned_font.hpp>
#include <psemek/gfx/resource/font_9x12_png.hpp>
#include <psemek/ui/resources/font_9x12_glyphs_txt.hpp>
#include <psemek/gfx/resource/font_10x12_bold_png.hpp>
#include <psemek/ui/resources/font_10x12_bold_glyphs_txt.hpp>
#include <psemek/io/memory_stream.hpp>
#include <sstream>
namespace psemek::ui
{
std::unique_ptr<font> make_default_monospace_9x12_font()
{
character_range range{32, 128};
std::string_view name = "default_monospace_9x12";
math::vector<int, 2> 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<math::box<float, 2>> 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<float, 2> 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<monospace_font>(range, name, size, std::move(atlas), std::move(texcoords));
}
static std::unique_ptr<font> make_default_font(std::string_view name, math::vector<int, 2> 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<kerned_font>(std::move(data), std::move(atlas));
}
std::unique_ptr<font> 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<font> 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);
}
}

View file

@ -101,14 +101,17 @@ namespace psemek::ui
bool edit::on_event(mouse_move const & e) 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<float>(e.position); auto m = math::cast<float>(e.position);
mouse_x_ = m[0]; mouse_x_ = m[0];
bool new_mouseover = shape_.contains(m); bool new_mouseover = shape_.contains(m);
if (!mouseover_ && new_mouseover) if (!mouseover_ && new_mouseover)
sdl2::set_cursor(sdl2::cursor_type::beam); sdl2::set_cursor(*beam_cursor);
else if (mouseover_ && !new_mouseover) else if (mouseover_ && !new_mouseover)
sdl2::set_cursor(sdl2::cursor_type::arrow); sdl2::set_cursor(*arrow_cursor);
mouseover_ = new_mouseover; mouseover_ = new_mouseover;
return false; return false;
@ -393,7 +396,7 @@ namespace psemek::ui
cached_state state; cached_state state;
state.texture = &font->atlas(); state.texture = &font->atlas();
shape_options options; fonts::shape_options options;
options.scale = *st->text_scale; options.scale = *st->text_scale;
auto glyphs = font->shape(text_, options); auto glyphs = font->shape(text_, options);

View file

@ -73,13 +73,13 @@ namespace psemek::ui
{ {
file_dialog_image_provider() file_dialog_image_provider()
{ {
back_.load(gfx::read_png(io::memory_istream(resources::back_png.data))); back_.load(gfx::read_image<gfx::color_rgba>(io::memory_istream(resources::back_png.data)));
back_.linear_filter(); back_.linear_filter();
folder_.load(gfx::read_png(io::memory_istream(resources::folder_png.data))); folder_.load(gfx::read_image<gfx::color_rgba>(io::memory_istream(resources::folder_png.data)));
folder_.linear_filter(); folder_.linear_filter();
file_.load(gfx::read_png(io::memory_istream(resources::file_png.data))); file_.load(gfx::read_image<gfx::color_rgba>(io::memory_istream(resources::file_png.data)));
file_.linear_filter(); file_.linear_filter();
} }

View file

@ -20,7 +20,8 @@ namespace psemek::ui
{ {
if (selected_link_) 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; selected_link_ = std::nullopt;
} }
text_ = std::move(text); text_ = std::move(text);
@ -66,7 +67,8 @@ namespace psemek::ui
{ {
if (selected_link_) 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; selected_link_ = std::nullopt;
} }
text_ = std::move(text); text_ = std::move(text);
@ -232,10 +234,13 @@ namespace psemek::ui
if (new_selected_link != selected_link_) 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) if (new_selected_link)
sdl2::set_cursor(sdl2::cursor_type::hand); sdl2::set_cursor(*hand_cursor);
else else
sdl2::set_cursor(sdl2::cursor_type::arrow); sdl2::set_cursor(*arrow_cursor);
if (link_mouseover_callback_) if (link_mouseover_callback_)
post([cb = link_mouseover_callback_, value = new_selected_link]{ 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; color[3] = (color[3] * 1.f * batch.color[3]) / 255.f;
for (auto const & image : batch.images) 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}); 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}); 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) 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}); 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}); 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<float, 2> pen{0.f, 0.f}; math::point<float, 2> pen{0.f, 0.f};
shape_options opts; fonts::shape_options opts;
opts.scale = *st->text_scale; opts.scale = *st->text_scale;
for (auto const & chunk : chunks_) for (auto const & chunk : chunks_)

View file

@ -1,121 +0,0 @@
#include <psemek/app/ui_scene.hpp>
#include <psemek/log/log.hpp>
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::element> ui)
{
ui_ = std::move(ui);
if (active())
controller_.set_root(ui_);
}
}