mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 01:47:34 +00:00
WindowServer: Support windows with alpha channels. And per-WSWindow opacity.
This patch also adds a Format concept to GraphicsBitmap. For now there are only two formats: RGB32 and RGBA32. Windows with alpha channel have their backing stores created in the RGBA32 format. Use this to make Terminal windows semi-transparent for that comfy rice look. There is one problem here, in that window compositing overdraw incurs multiple passes of blending of the same pixels. This leads to a mismatch in opacity which is obviously not good. I will work on this in a later patch. The alpha blending is currently straight C++. It should be relatively easy to optimize this using SSE instructions. For now I'm just happy with the cute effect. :^)
This commit is contained in:
parent
d4973842c9
commit
9b71307d49
25 changed files with 244 additions and 71 deletions
|
@ -17,7 +17,7 @@ int main(int argc, char** argv)
|
|||
window->set_main_widget(widget);
|
||||
|
||||
auto* icon_label = new GLabel(widget);
|
||||
icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/Serenity.rgb", { 32, 32 }));
|
||||
icon_label->set_icon(GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/Serenity.rgb", { 32, 32 }));
|
||||
icon_label->set_relative_rect(
|
||||
widget->rect().center().x() - 16,
|
||||
10,
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
DirectoryView::DirectoryView(GWidget* parent)
|
||||
: GWidget(parent)
|
||||
{
|
||||
m_directory_icon = GraphicsBitmap::load_from_file("/res/icons/folder16.rgb", { 16, 16 });
|
||||
m_file_icon = GraphicsBitmap::load_from_file("/res/icons/file16.rgb", { 16, 16 });
|
||||
m_symlink_icon = GraphicsBitmap::load_from_file("/res/icons/link16.rgb", { 16, 16 });
|
||||
m_directory_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/folder16.rgb", { 16, 16 });
|
||||
m_file_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/file16.rgb", { 16, 16 });
|
||||
m_symlink_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/link16.rgb", { 16, 16 });
|
||||
|
||||
m_scrollbar = new GScrollBar(Orientation::Vertical, this);
|
||||
m_scrollbar->set_step(4);
|
||||
|
@ -142,7 +142,7 @@ void DirectoryView::paint_event(GPaintEvent&)
|
|||
Rect name_rect(icon_rect.right() + horizontal_padding, y, 100, item_height());
|
||||
Rect size_rect(name_rect.right() + horizontal_padding, y, 64, item_height());
|
||||
painter.fill_rect(row_rect(painted_item_index), i % 2 ? Color(210, 210, 210) : Color::White);
|
||||
painter.blit_with_alpha(icon_rect.location(), icon_for(entry), { 0, 0, icon_size, icon_size });
|
||||
painter.blit(icon_rect.location(), icon_for(entry), { 0, 0, icon_size, icon_size });
|
||||
painter.draw_text(name_rect, entry.name, TextAlignment::CenterLeft, Color::Black);
|
||||
if (should_show_size_for(entry))
|
||||
painter.draw_text(size_rect, pretty_byte_size(entry.size), TextAlignment::CenterRight, Color::Black);
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
: GButton(parent)
|
||||
, m_executable_path(exec_path)
|
||||
{
|
||||
set_icon(GraphicsBitmap::load_from_file(icon_path, { 32, 32 }));
|
||||
set_icon(GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, icon_path, { 32, 32 }));
|
||||
resize(50, 50);
|
||||
on_click = [this] (GButton&) {
|
||||
pid_t child_pid = fork();
|
||||
|
|
|
@ -143,7 +143,7 @@ unsigned parse_uint(const String& str, bool& ok)
|
|||
|
||||
static inline Color lookup_color(unsigned color)
|
||||
{
|
||||
return xterm_colors[color];
|
||||
return Color::from_rgb(xterm_colors[color]);
|
||||
}
|
||||
|
||||
void Terminal::escape$m(const Vector<unsigned>& params)
|
||||
|
@ -668,10 +668,14 @@ void Terminal::keydown_event(GKeyEvent& event)
|
|||
}
|
||||
|
||||
void Terminal::paint_event(GPaintEvent&)
|
||||
{
|
||||
Rect rect { 0, 0, m_pixel_width, m_pixel_height };
|
||||
{
|
||||
Painter painter(*this);
|
||||
|
||||
if (m_needs_background_fill) {
|
||||
m_needs_background_fill = false;
|
||||
painter.fill_rect(rect(), Color(Color::Black).with_alpha(255 * m_opacity));
|
||||
}
|
||||
|
||||
if (m_rows_to_scroll_backing_store && m_rows_to_scroll_backing_store < m_rows) {
|
||||
int first_scanline = m_inset;
|
||||
int second_scanline = m_inset + (m_rows_to_scroll_backing_store * m_line_height);
|
||||
|
@ -695,7 +699,7 @@ void Terminal::paint_event(GPaintEvent&)
|
|||
line.dirty = false;
|
||||
bool has_only_one_background_color = line.has_only_one_background_color();
|
||||
if (has_only_one_background_color) {
|
||||
painter.fill_rect(row_rect(row), lookup_color(line.attributes[0].background_color));
|
||||
painter.fill_rect(row_rect(row), lookup_color(line.attributes[0].background_color).with_alpha(255 * m_opacity));
|
||||
}
|
||||
for (word column = 0; column < m_columns; ++column) {
|
||||
bool should_reverse_fill_for_cursor = m_in_active_window && row == m_cursor_row && column == m_cursor_column;
|
||||
|
@ -704,7 +708,7 @@ void Terminal::paint_event(GPaintEvent&)
|
|||
auto character_rect = glyph_rect(row, column);
|
||||
if (!has_only_one_background_color || should_reverse_fill_for_cursor) {
|
||||
auto cell_rect = character_rect.inflated(0, m_line_spacing);
|
||||
painter.fill_rect(cell_rect, lookup_color(should_reverse_fill_for_cursor ? attribute.foreground_color : attribute.background_color));
|
||||
painter.fill_rect(cell_rect, lookup_color(should_reverse_fill_for_cursor ? attribute.foreground_color : attribute.background_color).with_alpha(255 * m_opacity));
|
||||
}
|
||||
if (ch == ' ')
|
||||
continue;
|
||||
|
@ -718,7 +722,7 @@ void Terminal::paint_event(GPaintEvent&)
|
|||
}
|
||||
|
||||
if (m_belling)
|
||||
painter.draw_rect(rect, Color::Red);
|
||||
painter.draw_rect(rect(), Color::Red);
|
||||
}
|
||||
|
||||
void Terminal::set_window_title(String&& title)
|
||||
|
|
|
@ -144,4 +144,7 @@ private:
|
|||
RetainPtr<Font> m_font;
|
||||
|
||||
GNotifier m_notifier;
|
||||
|
||||
float m_opacity { 0.8f };
|
||||
bool m_needs_background_fill { true };
|
||||
};
|
||||
|
|
|
@ -89,6 +89,7 @@ int main(int argc, char** argv)
|
|||
window->set_should_exit_app_on_close(true);
|
||||
|
||||
Terminal terminal(ptm_fd);
|
||||
window->set_has_alpha_channel(true);
|
||||
window->set_main_widget(&terminal);
|
||||
window->move_to(300, 300);
|
||||
window->show();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue