mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 00:07:35 +00:00
WindowServer+LibGUI+LibGfx: Add WindowType::ToolWindow
Tool windows are secondary windows with a smaller title bar. The sit on the layer above normal windows, and cannot be minimized. These are intended for complex yet non-modal interactions with the content of a primary window, such as find/replace windows, property windows, etc.
This commit is contained in:
parent
15c1f7a40d
commit
11c8596ad3
12 changed files with 105 additions and 37 deletions
|
@ -299,7 +299,7 @@ void Window::set_window_type(WindowType window_type)
|
|||
|
||||
if (!m_minimum_size_modified) {
|
||||
// Apply minimum size defaults.
|
||||
if (m_window_type == WindowType::Normal)
|
||||
if (m_window_type == WindowType::Normal || m_window_type == WindowType::ToolWindow)
|
||||
m_minimum_size_when_windowless = { 50, 50 };
|
||||
else
|
||||
m_minimum_size_when_windowless = { 1, 1 };
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -40,6 +40,7 @@ enum class WindowType {
|
|||
MenuApplet,
|
||||
Notification,
|
||||
Desktop,
|
||||
ToolWindow,
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/ClassicWindowTheme.h>
|
||||
#include <LibGfx/Font.h>
|
||||
#include <LibGfx/FontDatabase.h>
|
||||
#include <LibGfx/Painter.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
|
@ -44,6 +43,9 @@ ClassicWindowTheme::~ClassicWindowTheme()
|
|||
|
||||
Gfx::IntRect ClassicWindowTheme::title_bar_icon_rect(WindowType window_type, const IntRect& window_rect, const Palette& palette) const
|
||||
{
|
||||
if (window_type == WindowType::ToolWindow)
|
||||
return {};
|
||||
|
||||
auto titlebar_rect = title_bar_rect(window_type, window_rect, palette);
|
||||
Gfx::IntRect icon_rect {
|
||||
titlebar_rect.x() + 2,
|
||||
|
@ -61,9 +63,9 @@ Gfx::IntRect ClassicWindowTheme::title_bar_text_rect(WindowType window_type, con
|
|||
auto titlebar_rect = title_bar_rect(window_type, window_rect, palette);
|
||||
auto titlebar_icon_rect = title_bar_icon_rect(window_type, window_rect, palette);
|
||||
return {
|
||||
titlebar_rect.x() + 3 + titlebar_icon_rect.width() + 2,
|
||||
titlebar_rect.x() + 3 + (titlebar_icon_rect.is_empty() ? 0 : titlebar_icon_rect.width() + 2),
|
||||
titlebar_rect.y(),
|
||||
titlebar_rect.width() - 5 - titlebar_icon_rect.width() - 2,
|
||||
titlebar_rect.width() - 5 - (titlebar_icon_rect.is_empty() ? 0 : titlebar_icon_rect.width() - 2),
|
||||
titlebar_rect.height()
|
||||
};
|
||||
}
|
||||
|
@ -110,10 +112,41 @@ void ClassicWindowTheme::paint_normal_frame(Painter& painter, WindowState window
|
|||
painter.blit(titlebar_icon_rect.location(), icon, icon.rect());
|
||||
}
|
||||
|
||||
void ClassicWindowTheme::paint_tool_window_frame(Painter& painter, WindowState window_state, const IntRect& window_rect, const StringView& title_text, const Palette& palette, const IntRect& leftmost_button_rect) const
|
||||
{
|
||||
auto frame_rect = frame_rect_for_window(WindowType::ToolWindow, window_rect, palette);
|
||||
frame_rect.set_location({ 0, 0 });
|
||||
Gfx::StylePainter::paint_window_frame(painter, frame_rect, palette);
|
||||
|
||||
auto& title_font = FontDatabase::default_bold_font();
|
||||
|
||||
auto titlebar_rect = title_bar_rect(WindowType::ToolWindow, window_rect, palette);
|
||||
auto titlebar_inner_rect = title_bar_text_rect(WindowType::ToolWindow, window_rect, palette);
|
||||
auto titlebar_title_rect = titlebar_inner_rect;
|
||||
titlebar_title_rect.set_width(FontDatabase::default_bold_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::title_bar_rect(WindowType window_type, const IntRect& window_rect, const Palette& palette) const
|
||||
{
|
||||
auto& title_font = FontDatabase::default_bold_font();
|
||||
auto window_titlebar_height = title_bar_height(palette);
|
||||
auto window_titlebar_height = title_bar_height(window_type, 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;
|
||||
|
||||
|
@ -160,10 +193,11 @@ void ClassicWindowTheme::paint_notification_frame(Painter& painter, const IntRec
|
|||
|
||||
IntRect ClassicWindowTheme::frame_rect_for_window(WindowType window_type, const IntRect& window_rect, const Gfx::Palette& palette) const
|
||||
{
|
||||
auto window_titlebar_height = title_bar_height(palette);
|
||||
auto window_titlebar_height = title_bar_height(window_type, palette);
|
||||
|
||||
switch (window_type) {
|
||||
case WindowType::Normal:
|
||||
case WindowType::ToolWindow:
|
||||
return {
|
||||
window_rect.x() - 4,
|
||||
window_rect.y() - window_titlebar_height - 6,
|
||||
|
@ -210,10 +244,18 @@ Vector<IntRect> ClassicWindowTheme::layout_buttons(WindowType window_type, const
|
|||
return button_rects;
|
||||
}
|
||||
|
||||
int ClassicWindowTheme::title_bar_height(const Palette& palette) const
|
||||
int ClassicWindowTheme::title_bar_height(WindowType window_type, const Palette& palette) const
|
||||
{
|
||||
auto& title_font = FontDatabase::default_bold_font();
|
||||
return max(palette.window_title_height(), title_font.glyph_height() + 8);
|
||||
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);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,9 +37,10 @@ public:
|
|||
virtual ~ClassicWindowTheme() override;
|
||||
|
||||
virtual void paint_normal_frame(Painter&, WindowState, const IntRect& window_rect, const StringView& title, const Bitmap& icon, const Palette&, const IntRect& leftmost_button_rect) const override;
|
||||
virtual void paint_tool_window_frame(Painter&, WindowState, const IntRect& window_rect, const StringView& title, const Palette&, const IntRect& leftmost_button_rect) const override;
|
||||
virtual void paint_notification_frame(Painter&, const IntRect& window_rect, const Palette&, const IntRect& close_button_rect) const override;
|
||||
|
||||
virtual int title_bar_height(const Palette&) const override;
|
||||
virtual int title_bar_height(WindowType, const Palette&) const override;
|
||||
virtual IntRect title_bar_rect(WindowType, const IntRect& window_rect, const Palette&) const override;
|
||||
virtual IntRect title_bar_icon_rect(WindowType, const IntRect& window_rect, const Palette&) const override;
|
||||
virtual IntRect title_bar_text_rect(WindowType, const IntRect& window_rect, const Palette&) const override;
|
||||
|
|
|
@ -35,6 +35,7 @@ class WindowTheme {
|
|||
public:
|
||||
enum class WindowType {
|
||||
Normal,
|
||||
ToolWindow,
|
||||
Notification,
|
||||
Other,
|
||||
};
|
||||
|
@ -51,9 +52,10 @@ public:
|
|||
static WindowTheme& current();
|
||||
|
||||
virtual void paint_normal_frame(Painter&, WindowState, const IntRect& window_rect, const StringView& title, const Bitmap& icon, const Palette&, const IntRect& leftmost_button_rect) const = 0;
|
||||
virtual void paint_tool_window_frame(Painter&, WindowState, const IntRect& window_rect, const StringView& title, const Palette&, const IntRect& leftmost_button_rect) const = 0;
|
||||
virtual void paint_notification_frame(Painter&, const IntRect& window_rect, const Palette&, const IntRect& close_button_rect) const = 0;
|
||||
|
||||
virtual int title_bar_height(const Palette&) const = 0;
|
||||
virtual int title_bar_height(WindowType, const Palette&) const = 0;
|
||||
virtual IntRect title_bar_rect(WindowType, const IntRect& window_rect, const Palette&) const = 0;
|
||||
virtual IntRect title_bar_icon_rect(WindowType, const IntRect& window_rect, const Palette&) const = 0;
|
||||
virtual IntRect title_bar_text_rect(WindowType, const IntRect& window_rect, const Palette&) const = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue