1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-22 17:15:08 +00:00

LibGUI: Fix ColorPicker custom color offset

Previously the ColorPicker would get the custom color directly from the
window, this was changed in d7d5788469 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.
This commit is contained in:
Linus Groh 2020-08-13 16:44:37 +02:00 committed by Andreas Kling
parent 728d4649e4
commit 675d8eec60

View file

@ -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)