From 9b0ff229e378bc7b01758ba3f094eeb46d75625a Mon Sep 17 00:00:00 2001 From: Aziz Berkay Yesilyurt Date: Fri, 9 Jul 2021 11:42:03 +0200 Subject: [PATCH] Utilities: Use alpha channel instead of opacity in shot The way overlay was drawn is not the correct way to achieve window transparency in selection mode. With this change, shot window becomes truely transparent. --- Userland/Utilities/shot.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Userland/Utilities/shot.cpp b/Userland/Utilities/shot.cpp index 6ccd4e9433..f920e7b577 100644 --- a/Userland/Utilities/shot.cpp +++ b/Userland/Utilities/shot.cpp @@ -25,7 +25,7 @@ class SelectableLayover final : public GUI::Widget { public: SelectableLayover(GUI::Window* window) : m_window(window) - , m_background_color(palette().threed_highlight()) + , m_background_color(palette().threed_highlight().with_alpha(128)) { set_override_cursor(Gfx::StandardCursor::Crosshair); } @@ -60,16 +60,14 @@ private: virtual void paint_event(GUI::PaintEvent&) override { - if (m_region.is_empty()) { - GUI::Painter painter(*this); - painter.fill_rect(m_window->rect(), m_background_color); - return; - } - GUI::Painter painter(*this); - painter.fill_rect(m_region, Gfx::Color::Transparent); - for (auto rect : m_window->rect().shatter(m_region)) - painter.fill_rect(rect, m_background_color); + painter.clear_rect(m_window->rect(), Gfx::Color::Transparent); + painter.fill_rect(m_window->rect(), m_background_color); + + if (m_region.is_empty()) + return; + + painter.clear_rect(m_region, Gfx::Color::Transparent); } virtual void keydown_event(GUI::KeyEvent& event) override @@ -113,10 +111,9 @@ int main(int argc, char** argv) if (select_region) { auto window = GUI::Window::construct(); auto& container = window->set_main_widget(window); - container.set_fill_with_background_color(true); window->set_title("shot"); - window->set_opacity(0.2); + window->set_has_alpha_channel(true); window->set_fullscreen(true); window->show(); app->exec();