1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:07:35 +00:00

LibGUI: Move frame painting from GFrame to StylePainter.

This way it can be used by others who might not have a GFrame object.
This commit is contained in:
Andreas Kling 2019-04-10 03:43:46 +02:00
parent e61dd994df
commit 4ab0cd5d4c
16 changed files with 93 additions and 88 deletions

View file

@ -103,3 +103,54 @@ void StylePainter::paint_surface(Painter& painter, const Rect& rect, bool paint_
painter.draw_line(rect.top_right(), rect.bottom_right().translated(0, -1), Color::MidGray);
}
}
void StylePainter::paint_frame(Painter& painter, const Rect& rect, FrameShape shape, FrameShadow shadow, int thickness, bool skip_vertical_lines)
{
Color top_left_color;
Color bottom_right_color;
Color dark_shade = Color::from_rgb(0x808080);
Color light_shade = Color::from_rgb(0xffffff);
if (shadow == FrameShadow::Raised) {
top_left_color = light_shade;
bottom_right_color = dark_shade;
} else if (shadow == FrameShadow::Sunken) {
top_left_color = dark_shade;
bottom_right_color = light_shade;
} else if (shadow == FrameShadow::Plain) {
top_left_color = dark_shade;
bottom_right_color = dark_shade;
}
if (thickness >= 1) {
painter.draw_line(rect.top_left(), rect.top_right(), top_left_color);
painter.draw_line(rect.bottom_left(), rect.bottom_right(), bottom_right_color);
if (shape != FrameShape::Panel || !skip_vertical_lines) {
painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left().translated(0, -1), top_left_color);
painter.draw_line(rect.top_right(), rect.bottom_right().translated(0, -1), bottom_right_color);
}
}
if (shape == FrameShape::Container && thickness >= 2) {
Color top_left_color;
Color bottom_right_color;
Color dark_shade = Color::from_rgb(0x404040);
Color light_shade = Color::from_rgb(0xc0c0c0);
if (shadow == FrameShadow::Raised) {
top_left_color = light_shade;
bottom_right_color = dark_shade;
} else if (shadow == FrameShadow::Sunken) {
top_left_color = dark_shade;
bottom_right_color = light_shade;
} else if (shadow == FrameShadow::Plain) {
top_left_color = dark_shade;
bottom_right_color = dark_shade;
}
Rect inner_container_frame_rect = rect.shrunken(2, 2);
painter.draw_line(inner_container_frame_rect.top_left(), inner_container_frame_rect.top_right(), top_left_color);
painter.draw_line(inner_container_frame_rect.bottom_left(), inner_container_frame_rect.bottom_right(), bottom_right_color);
painter.draw_line(inner_container_frame_rect.top_left().translated(0, 1), inner_container_frame_rect.bottom_left().translated(0, -1), top_left_color);
painter.draw_line(inner_container_frame_rect.top_right(), inner_container_frame_rect.bottom_right().translated(0, -1), bottom_right_color);
}
}