Implement bevels in default_element_factory frame

This commit is contained in:
Nikita Lisitsa 2021-10-13 23:16:25 +03:00
parent 89db5ec3ea
commit 3a5e29835f

View file

@ -113,7 +113,7 @@ namespace psemek::ui
auto st = merged_own_style();
if (!st) return;
for (auto c : children())
if (c) c->reshape(geom::shrink(bbox, 1.f * (*st->border_width + *st->outer_margin)));
if (c) c->reshape(geom::shrink(bbox, 1.f * (*st->border_width + *st->bevel_width + *st->outer_margin)));
}
geom::box<float, 2> size_constraints() const override
@ -127,7 +127,7 @@ namespace psemek::ui
auto st = merged_own_style();
if (st)
{
float extra = 2.f * (*st->border_width + *st->outer_margin);
float extra = 2.f * (*st->border_width + *st->bevel_width + *st->outer_margin);
r[0] += extra;
r[1] += extra;
}
@ -159,7 +159,44 @@ namespace psemek::ui
if (st->border_width > 0)
p.draw_rect(shape_.box, *st->border_color);
p.draw_rect(geom::shrink(shape_.box, 1.f * (*st->border_width)), *st->bg_color);
if (st->bevel_width > 0)
{
geom::point<float, 2> corners[4];
geom::point<float, 2> corners_in[4];
auto box = geom::shrink<float>(shape_.box, *st->border_width);
corners[0] = box.corner(0, 0);
corners[1] = box.corner(1, 0);
corners[2] = box.corner(1, 1);
corners[3] = box.corner(0, 1);
auto box_in = geom::shrink<float>(box, *st->bevel_width);
corners_in[0] = box_in.corner(0, 0);
corners_in[1] = box_in.corner(1, 0);
corners_in[2] = box_in.corner(1, 1);
corners_in[3] = box_in.corner(0, 1);
auto c1 = *st->bevel_light_color;
auto c2 = *st->bevel_dark_color;
if (*st->bevel_type == bevel_type::down)
std::swap(c1, c2);
p.draw_triangle({corners[0], corners_in[0], corners[1]}, c1);
p.draw_triangle({corners[1], corners_in[0], corners_in[1]}, c1);
p.draw_triangle({corners[1], corners_in[1], corners[2]}, c1);
p.draw_triangle({corners[2], corners_in[1], corners_in[2]}, c1);
p.draw_triangle({corners[2], corners_in[2], corners[3]}, c2);
p.draw_triangle({corners[3], corners_in[2], corners_in[3]}, c2);
p.draw_triangle({corners[3], corners_in[3], corners[0]}, c2);
p.draw_triangle({corners[0], corners_in[3], corners_in[0]}, c2);
}
p.draw_rect(geom::shrink(shape_.box, 1.f * (*st->border_width + *st->bevel_width)), *st->bg_color);
}
private: