mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:57:46 +00:00
LibGfx+LibGUI+WindowServer+Apps+Demos: Replace ToolWindows
with the RenderAbove WindowMode. This mode will ensure child windows always draw above their parents, even when focus is lost. RenderAbove modals are automatically themed the same as the old ToolWindows. Fixes ToolWindows rendering above ALL normal windows, regardless of parent. We can't rely on WindowType to create these sort of effects because of WindowManager's strict display hierarchy.
This commit is contained in:
parent
589572cfa4
commit
0d4fd4e2a6
15 changed files with 106 additions and 144 deletions
|
@ -16,12 +16,12 @@ namespace Gfx {
|
|||
|
||||
static constexpr int menubar_height = 20;
|
||||
|
||||
Gfx::IntRect ClassicWindowTheme::titlebar_icon_rect(WindowType window_type, IntRect const& window_rect, Palette const& palette) const
|
||||
Gfx::IntRect ClassicWindowTheme::titlebar_icon_rect(WindowType window_type, WindowMode window_mode, IntRect const& window_rect, Palette const& palette) const
|
||||
{
|
||||
if (window_type == WindowType::ToolWindow)
|
||||
if (window_mode == WindowMode::RenderAbove)
|
||||
return {};
|
||||
|
||||
auto titlebar_rect = this->titlebar_rect(window_type, window_rect, palette);
|
||||
auto titlebar_rect = this->titlebar_rect(window_type, window_mode, window_rect, palette);
|
||||
Gfx::IntRect icon_rect {
|
||||
titlebar_rect.x() + 2,
|
||||
titlebar_rect.y(),
|
||||
|
@ -33,10 +33,10 @@ Gfx::IntRect ClassicWindowTheme::titlebar_icon_rect(WindowType window_type, IntR
|
|||
return icon_rect;
|
||||
}
|
||||
|
||||
Gfx::IntRect ClassicWindowTheme::titlebar_text_rect(WindowType window_type, IntRect const& window_rect, Palette const& palette) const
|
||||
Gfx::IntRect ClassicWindowTheme::titlebar_text_rect(WindowType window_type, WindowMode window_mode, IntRect const& window_rect, Palette const& palette) const
|
||||
{
|
||||
auto titlebar_rect = this->titlebar_rect(window_type, window_rect, palette);
|
||||
auto titlebar_icon_rect = this->titlebar_icon_rect(window_type, window_rect, palette);
|
||||
auto titlebar_rect = this->titlebar_rect(window_type, window_mode, window_rect, palette);
|
||||
auto titlebar_icon_rect = this->titlebar_icon_rect(window_type, window_mode, window_rect, palette);
|
||||
return {
|
||||
titlebar_rect.x() + 3 + (titlebar_icon_rect.is_empty() ? 0 : (titlebar_icon_rect.width() + 2)),
|
||||
titlebar_rect.y(),
|
||||
|
@ -45,17 +45,17 @@ Gfx::IntRect ClassicWindowTheme::titlebar_text_rect(WindowType window_type, IntR
|
|||
};
|
||||
}
|
||||
|
||||
void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window_state, IntRect const& window_rect, StringView window_title, Bitmap const& icon, Palette const& palette, IntRect const& leftmost_button_rect, int menu_row_count, [[maybe_unused]] bool window_modified) const
|
||||
void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window_state, WindowMode window_mode, IntRect const& window_rect, StringView window_title, Bitmap const& icon, Palette const& palette, IntRect const& leftmost_button_rect, int menu_row_count, [[maybe_unused]] bool window_modified) const
|
||||
{
|
||||
auto frame_rect = frame_rect_for_window(WindowType::Normal, window_rect, palette, menu_row_count);
|
||||
auto frame_rect = frame_rect_for_window(WindowType::Normal, window_mode, window_rect, palette, menu_row_count);
|
||||
frame_rect.set_location({ 0, 0 });
|
||||
Gfx::StylePainter::paint_window_frame(painter, frame_rect, palette);
|
||||
|
||||
auto& title_font = FontDatabase::window_title_font();
|
||||
|
||||
auto titlebar_rect = this->titlebar_rect(WindowType::Normal, window_rect, palette);
|
||||
auto titlebar_icon_rect = this->titlebar_icon_rect(WindowType::Normal, window_rect, palette);
|
||||
auto titlebar_inner_rect = titlebar_text_rect(WindowType::Normal, window_rect, palette);
|
||||
auto titlebar_rect = this->titlebar_rect(WindowType::Normal, window_mode, window_rect, palette);
|
||||
auto titlebar_icon_rect = this->titlebar_icon_rect(WindowType::Normal, window_mode, window_rect, palette);
|
||||
auto titlebar_inner_rect = titlebar_text_rect(WindowType::Normal, window_mode, window_rect, palette);
|
||||
auto titlebar_title_rect = titlebar_inner_rect;
|
||||
titlebar_title_rect.set_width(title_font.width(window_title));
|
||||
|
||||
|
@ -69,6 +69,18 @@ void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window
|
|||
auto title_alignment = palette.title_alignment();
|
||||
|
||||
int stripe_right = leftmost_button_rect.left() - 3;
|
||||
|
||||
auto clipped_title_rect = titlebar_title_rect;
|
||||
clipped_title_rect.set_width(stripe_right - clipped_title_rect.x());
|
||||
if (!clipped_title_rect.is_empty()) {
|
||||
painter.draw_text(clipped_title_rect.translated(1, 2), window_title, title_font, title_alignment, shadow_color, Gfx::TextElision::Right);
|
||||
// FIXME: The translated(0, 1) wouldn't be necessary if we could center text based on its baseline.
|
||||
painter.draw_text(clipped_title_rect.translated(0, 1), window_title, title_font, title_alignment, title_color, Gfx::TextElision::Right);
|
||||
}
|
||||
|
||||
if (window_mode == WindowMode::RenderAbove)
|
||||
return;
|
||||
|
||||
if (stripes_color.alpha() > 0) {
|
||||
switch (title_alignment) {
|
||||
case Gfx::TextAlignment::CenterLeft: {
|
||||
|
@ -101,59 +113,20 @@ void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window
|
|||
}
|
||||
}
|
||||
|
||||
auto clipped_title_rect = titlebar_title_rect;
|
||||
clipped_title_rect.set_width(stripe_right - clipped_title_rect.x());
|
||||
if (!clipped_title_rect.is_empty()) {
|
||||
painter.draw_text(clipped_title_rect.translated(1, 2), window_title, title_font, title_alignment, shadow_color, Gfx::TextElision::Right);
|
||||
// FIXME: The translated(0, 1) wouldn't be necessary if we could center text based on its baseline.
|
||||
painter.draw_text(clipped_title_rect.translated(0, 1), window_title, title_font, title_alignment, title_color, Gfx::TextElision::Right);
|
||||
}
|
||||
|
||||
painter.draw_scaled_bitmap(titlebar_icon_rect, icon, icon.rect());
|
||||
}
|
||||
|
||||
void ClassicWindowTheme::paint_tool_window_frame(Painter& painter, WindowState window_state, IntRect const& window_rect, StringView title_text, Palette const& palette, IntRect const& leftmost_button_rect) const
|
||||
{
|
||||
auto frame_rect = frame_rect_for_window(WindowType::ToolWindow, window_rect, palette, 0);
|
||||
frame_rect.set_location({ 0, 0 });
|
||||
Gfx::StylePainter::paint_window_frame(painter, frame_rect, palette);
|
||||
|
||||
auto& title_font = FontDatabase::window_title_font();
|
||||
|
||||
auto titlebar_rect = this->titlebar_rect(WindowType::ToolWindow, window_rect, palette);
|
||||
auto titlebar_inner_rect = titlebar_text_rect(WindowType::ToolWindow, window_rect, palette);
|
||||
auto titlebar_title_rect = titlebar_inner_rect;
|
||||
titlebar_title_rect.set_width(title_font.width(title_text));
|
||||
|
||||
auto [title_color, border_color, border_color2, stripes_color, shadow_color] = compute_frame_colors(window_state, palette);
|
||||
|
||||
painter.draw_line(titlebar_rect.bottom_left().translated(0, 1), titlebar_rect.bottom_right().translated(0, 1), palette.button());
|
||||
painter.draw_line(titlebar_rect.bottom_left().translated(0, 2), titlebar_rect.bottom_right().translated(0, 2), palette.button());
|
||||
|
||||
painter.fill_rect_with_gradient(titlebar_rect, border_color, border_color2);
|
||||
|
||||
int stripe_right = leftmost_button_rect.left() - 3;
|
||||
|
||||
auto clipped_title_rect = titlebar_title_rect;
|
||||
clipped_title_rect.set_width(stripe_right - clipped_title_rect.x());
|
||||
if (!clipped_title_rect.is_empty()) {
|
||||
painter.draw_text(clipped_title_rect.translated(1, 2), title_text, title_font, Gfx::TextAlignment::CenterLeft, shadow_color, Gfx::TextElision::Right);
|
||||
// FIXME: The translated(0, 1) wouldn't be necessary if we could center text based on its baseline.
|
||||
painter.draw_text(clipped_title_rect.translated(0, 1), title_text, title_font, Gfx::TextAlignment::CenterLeft, title_color, Gfx::TextElision::Right);
|
||||
}
|
||||
}
|
||||
|
||||
IntRect ClassicWindowTheme::menubar_rect(WindowType window_type, IntRect const& window_rect, Palette const& palette, int menu_row_count) const
|
||||
IntRect ClassicWindowTheme::menubar_rect(WindowType window_type, WindowMode window_mode, IntRect const& window_rect, Palette const& palette, int menu_row_count) const
|
||||
{
|
||||
if (window_type != WindowType::Normal)
|
||||
return {};
|
||||
return { palette.window_border_thickness(), palette.window_border_thickness() - 1 + titlebar_height(window_type, palette) + 2, window_rect.width(), menubar_height * menu_row_count };
|
||||
return { palette.window_border_thickness(), palette.window_border_thickness() - 1 + titlebar_height(window_type, window_mode, palette) + 2, window_rect.width(), menubar_height * menu_row_count };
|
||||
}
|
||||
|
||||
IntRect ClassicWindowTheme::titlebar_rect(WindowType window_type, IntRect const& window_rect, Palette const& palette) const
|
||||
IntRect ClassicWindowTheme::titlebar_rect(WindowType window_type, WindowMode window_mode, IntRect const& window_rect, Palette const& palette) const
|
||||
{
|
||||
auto& title_font = FontDatabase::window_title_font();
|
||||
auto window_titlebar_height = titlebar_height(window_type, palette);
|
||||
auto window_titlebar_height = titlebar_height(window_type, window_mode, palette);
|
||||
// FIXME: The top of the titlebar doesn't get redrawn properly if this padding is different
|
||||
int total_vertical_padding = title_font.glyph_height() - 1;
|
||||
|
||||
|
@ -178,13 +151,13 @@ ClassicWindowTheme::FrameColors ClassicWindowTheme::compute_frame_colors(WindowS
|
|||
}
|
||||
}
|
||||
|
||||
void ClassicWindowTheme::paint_notification_frame(Painter& painter, IntRect const& window_rect, Palette const& palette, IntRect const& close_button_rect) const
|
||||
void ClassicWindowTheme::paint_notification_frame(Painter& painter, WindowMode window_mode, IntRect const& window_rect, Palette const& palette, IntRect const& close_button_rect) const
|
||||
{
|
||||
auto frame_rect = frame_rect_for_window(WindowType::Notification, window_rect, palette, 0);
|
||||
auto frame_rect = frame_rect_for_window(WindowType::Notification, window_mode, window_rect, palette, 0);
|
||||
frame_rect.set_location({ 0, 0 });
|
||||
Gfx::StylePainter::paint_window_frame(painter, frame_rect, palette);
|
||||
|
||||
auto titlebar_rect = this->titlebar_rect(WindowType::Notification, window_rect, palette);
|
||||
auto titlebar_rect = this->titlebar_rect(WindowType::Notification, window_mode, window_rect, palette);
|
||||
painter.fill_rect_with_gradient(Gfx::Orientation::Vertical, titlebar_rect, palette.active_window_border1(), palette.active_window_border2());
|
||||
|
||||
if (palette.active_window_title_stripes().alpha() > 0) {
|
||||
|
@ -198,14 +171,13 @@ void ClassicWindowTheme::paint_notification_frame(Painter& painter, IntRect cons
|
|||
}
|
||||
}
|
||||
|
||||
IntRect ClassicWindowTheme::frame_rect_for_window(WindowType window_type, IntRect const& window_rect, Gfx::Palette const& palette, int menu_row_count) const
|
||||
IntRect ClassicWindowTheme::frame_rect_for_window(WindowType window_type, WindowMode window_mode, IntRect const& window_rect, Gfx::Palette const& palette, int menu_row_count) const
|
||||
{
|
||||
auto window_titlebar_height = titlebar_height(window_type, palette);
|
||||
auto window_titlebar_height = titlebar_height(window_type, window_mode, palette);
|
||||
auto border_thickness = palette.window_border_thickness();
|
||||
|
||||
switch (window_type) {
|
||||
case WindowType::Normal:
|
||||
case WindowType::ToolWindow:
|
||||
return {
|
||||
window_rect.x() - border_thickness,
|
||||
window_rect.y() - window_titlebar_height - border_thickness - 1 - menu_row_count * menubar_height,
|
||||
|
@ -224,43 +196,45 @@ IntRect ClassicWindowTheme::frame_rect_for_window(WindowType window_type, IntRec
|
|||
}
|
||||
}
|
||||
|
||||
Vector<IntRect> ClassicWindowTheme::layout_buttons(WindowType window_type, IntRect const& window_rect, Palette const& palette, size_t buttons) const
|
||||
Vector<IntRect> ClassicWindowTheme::layout_buttons(WindowType window_type, WindowMode window_mode, IntRect const& window_rect, Palette const& palette, size_t buttons) const
|
||||
{
|
||||
int window_button_width = palette.window_title_button_width();
|
||||
int window_button_height = palette.window_title_button_height();
|
||||
int pos;
|
||||
Vector<IntRect> button_rects;
|
||||
if (window_type == WindowType::Notification)
|
||||
pos = titlebar_rect(window_type, window_rect, palette).top() + 2;
|
||||
pos = titlebar_rect(window_type, window_mode, window_rect, palette).top() + 2;
|
||||
else
|
||||
pos = titlebar_text_rect(window_type, window_rect, palette).right() + 1;
|
||||
pos = titlebar_text_rect(window_type, window_mode, window_rect, palette).right() + 1;
|
||||
|
||||
for (size_t i = 0; i < buttons; i++) {
|
||||
if (window_type == WindowType::Notification) {
|
||||
// The button height & width have to be equal or it leaks out of its area
|
||||
Gfx::IntRect rect { 0, pos, window_button_height, window_button_height };
|
||||
rect.center_horizontally_within(titlebar_rect(window_type, window_rect, palette));
|
||||
rect.center_horizontally_within(titlebar_rect(window_type, window_mode, window_rect, palette));
|
||||
button_rects.append(rect);
|
||||
pos += window_button_height;
|
||||
} else {
|
||||
pos -= window_button_width;
|
||||
Gfx::IntRect rect { pos, 0, window_button_width, window_button_height };
|
||||
rect.center_vertically_within(titlebar_text_rect(window_type, window_rect, palette));
|
||||
rect.center_vertically_within(titlebar_text_rect(window_type, window_mode, window_rect, palette));
|
||||
button_rects.append(rect);
|
||||
}
|
||||
}
|
||||
return button_rects;
|
||||
}
|
||||
|
||||
int ClassicWindowTheme::titlebar_height(WindowType window_type, Palette const& palette) const
|
||||
int ClassicWindowTheme::titlebar_height(WindowType window_type, WindowMode window_mode, Palette const& palette) const
|
||||
{
|
||||
auto& title_font = FontDatabase::window_title_font();
|
||||
switch (window_type) {
|
||||
case WindowType::Normal:
|
||||
case WindowType::Notification:
|
||||
return max(palette.window_title_height(), title_font.glyph_height() + 8);
|
||||
case WindowType::ToolWindow:
|
||||
return max(palette.window_title_height() - 4, title_font.glyph_height() + 4);
|
||||
case WindowType::Notification: {
|
||||
if (window_mode == WindowMode::RenderAbove)
|
||||
return max(palette.window_title_height() - 4, title_font.glyph_height() + 4);
|
||||
else
|
||||
return max(palette.window_title_height(), title_font.glyph_height() + 8);
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue