From 675d8eec60bfaa81eb8dedddcf6f8085bbafce3d Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Thu, 13 Aug 2020 16:44:37 +0200 Subject: [PATCH] LibGUI: Fix ColorPicker custom color offset Previously the ColorPicker would get the custom color directly from the window, this was changed in d7d57884694ad5fda53e865f1b92ef48fddc9ca8 to get the color from the underlying bitmap instead - without taking the bitmap's scaling into effect though, so resulting colors were off by quite a bit. Fixes #3113. --- Libraries/LibGUI/ColorPicker.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Libraries/LibGUI/ColorPicker.cpp b/Libraries/LibGUI/ColorPicker.cpp index db5279dfc5..ee17e86870 100644 --- a/Libraries/LibGUI/ColorPicker.cpp +++ b/Libraries/LibGUI/ColorPicker.cpp @@ -418,7 +418,10 @@ void CustomColorWidget::pick_color_at_position(GUI::MouseEvent& event) if (!frame_inner_rect().contains(position)) return; - auto color = m_custom_colors->get_pixel(position); + // Map actual event position onto scaled bitmap to get the right pixel + auto pixel_x = min(position.x() * m_custom_colors->width() / frame_inner_rect().width(), m_custom_colors->width() - 1); + auto pixel_y = min(position.y() * m_custom_colors->height() / frame_inner_rect().height(), m_custom_colors->height() - 1); + auto color = m_custom_colors->get_pixel({ pixel_x, pixel_y }); m_last_position = position; if (on_pick)