diff --git a/libs/ui/include/psemek/ui/painter.hpp b/libs/ui/include/psemek/ui/painter.hpp index 04576318..f5656d86 100644 --- a/libs/ui/include/psemek/ui/painter.hpp +++ b/libs/ui/include/psemek/ui/painter.hpp @@ -15,9 +15,7 @@ namespace psemek::ui virtual void draw_rect(geom::box const & rect, gfx::color_rgba const & color) = 0; virtual void draw_triangle(geom::triangle> const & tri, gfx::color_rgba const & color) = 0; virtual void draw_glyph(font const & f, char32_t c, geom::box const & rect, gfx::color_rgba const & color) = 0; - virtual void draw_image(geom::box const & rect, gfx::texture_2d const & tex, gfx::color_rgba const & color = {0, 0, 0, 0}) = 0; virtual void draw_image(geom::box const & rect, gfx::texture_view_2d const & tex, gfx::color_rgba const & color = {0, 0, 0, 0}, float rotation = 0.f) = 0; - virtual void draw_subimage(geom::box const & rect, gfx::texture_2d const & tex, geom::box const & part, gfx::color_rgba const & color = {0, 0, 0, 0}, float rotation = 0.f) = 0; virtual void begin_stencil() = 0; virtual void commit_stencil() = 0; diff --git a/libs/ui/include/psemek/ui/painter_impl.hpp b/libs/ui/include/psemek/ui/painter_impl.hpp index 2664f9b8..f8c134d2 100644 --- a/libs/ui/include/psemek/ui/painter_impl.hpp +++ b/libs/ui/include/psemek/ui/painter_impl.hpp @@ -18,9 +18,7 @@ namespace psemek::ui void draw_rect(geom::box const & rect, gfx::color_rgba const & color) override; void draw_triangle(geom::triangle> const & tri, gfx::color_rgba const & color) override; void draw_glyph(font const & f, char32_t c, geom::box const & rect, gfx::color_rgba const & color) override; - void draw_image(geom::box const & rect, gfx::texture_2d const & tex, gfx::color_rgba const & color) override; void draw_image(geom::box const & rect, gfx::texture_view_2d const & tex, gfx::color_rgba const & color = {0, 0, 0, 0}, float rotation = 0.f) override; - void draw_subimage(geom::box const & rect, gfx::texture_2d const & tex, geom::box const & part, gfx::color_rgba const & color = {0, 0, 0, 0}, float rotation = 0.f) override; void begin_stencil() override; void commit_stencil() override; diff --git a/libs/ui/source/painter_impl.cpp b/libs/ui/source/painter_impl.cpp index d56a08bf..fc28e3fc 100644 --- a/libs/ui/source/painter_impl.cpp +++ b/libs/ui/source/painter_impl.cpp @@ -342,22 +342,9 @@ void main() impl().draw_bbox |= rect; } - void painter_impl::draw_image(geom::box const & rect, gfx::texture_2d const & tex, gfx::color_rgba const & color) - { - geom::box part; - part[0] = {0.f, tex.width()}; - part[1] = {0.f, tex.height()}; - draw_subimage(rect, tex, part, color); - } - void painter_impl::draw_image(geom::box const & rect, gfx::texture_view_2d const & tex, gfx::color_rgba const & color, float rotation) { - draw_subimage(rect, *tex.texture, geom::cast(tex.part), color, rotation); - } - - void painter_impl::draw_subimage(geom::box const & rect, gfx::texture_2d const & tex, geom::box const & part, gfx::color_rgba const & color, float rotation) - { - auto & batch = impl().batch(textured_batch{&tex}); + auto & batch = impl().batch(textured_batch{tex.texture}); std::uint32_t const depth = impl().depth++; std::uint32_t const base = batch.vertices.size(); @@ -377,6 +364,8 @@ void main() p11 = c + geom::rotate(p11 - c, rotation); } + auto part = geom::cast(tex.part); + batch.vertices.push_back({p00, depth, color, part.corner(0.f, 0.f)}); batch.vertices.push_back({p10, depth, color, part.corner(1.f, 0.f)}); batch.vertices.push_back({p01, depth, color, part.corner(0.f, 1.f)}); diff --git a/libs/ui/source/rich_image_view.cpp b/libs/ui/source/rich_image_view.cpp index 7d12f56f..07040b3d 100644 --- a/libs/ui/source/rich_image_view.cpp +++ b/libs/ui/source/rich_image_view.cpp @@ -177,7 +177,7 @@ namespace psemek::ui if (*st->shadow_offset != geom::vector{0, 0}) p.draw_rect(box + geom::cast(*st->shadow_offset), *st->shadow_color); - p.draw_subimage(box, *image_, reg, color_); + p.draw_image(box, {image_.get(), geom::cast(reg)}, color_); } }