diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-19 01:42:53 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-19 01:42:53 +0100 |
commit | 9b71307d499924834d029adc91baf9689bfa49fd (patch) | |
tree | 910481262bce702d78f3af9a806965a769d4c644 /Applications | |
parent | d4973842c913ca79e21f7dd53fe1a4d5720886e3 (diff) | |
download | serenity-9b71307d499924834d029adc91baf9689bfa49fd.zip |
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. :^)
Diffstat (limited to 'Applications')
-rw-r--r-- | Applications/About/main.cpp | 2 | ||||
-rw-r--r-- | Applications/FileManager/DirectoryView.cpp | 8 | ||||
-rw-r--r-- | Applications/Launcher/main.cpp | 2 | ||||
-rw-r--r-- | Applications/Terminal/Terminal.cpp | 16 | ||||
-rw-r--r-- | Applications/Terminal/Terminal.h | 3 | ||||
-rw-r--r-- | Applications/Terminal/main.cpp | 1 |
6 files changed, 20 insertions, 12 deletions
diff --git a/Applications/About/main.cpp b/Applications/About/main.cpp index bd405bd719..64dfdd7766 100644 --- a/Applications/About/main.cpp +++ b/Applications/About/main.cpp @@ -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, diff --git a/Applications/FileManager/DirectoryView.cpp b/Applications/FileManager/DirectoryView.cpp index a50fb4b41b..cb0ca5e201 100644 --- a/Applications/FileManager/DirectoryView.cpp +++ b/Applications/FileManager/DirectoryView.cpp @@ -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); diff --git a/Applications/Launcher/main.cpp b/Applications/Launcher/main.cpp index 9d765cb484..2b9f0ab898 100644 --- a/Applications/Launcher/main.cpp +++ b/Applications/Launcher/main.cpp @@ -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(); diff --git a/Applications/Terminal/Terminal.cpp b/Applications/Terminal/Terminal.cpp index 70721af153..e9f63cf551 100644 --- a/Applications/Terminal/Terminal.cpp +++ b/Applications/Terminal/Terminal.cpp @@ -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) diff --git a/Applications/Terminal/Terminal.h b/Applications/Terminal/Terminal.h index 298596a479..a51c7b3ad9 100644 --- a/Applications/Terminal/Terminal.h +++ b/Applications/Terminal/Terminal.h @@ -144,4 +144,7 @@ private: RetainPtr<Font> m_font; GNotifier m_notifier; + + float m_opacity { 0.8f }; + bool m_needs_background_fill { true }; }; diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp index f1dc759dc8..e27d2c0f35 100644 --- a/Applications/Terminal/main.cpp +++ b/Applications/Terminal/main.cpp @@ -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(); |