Fix ColorButton color picking dragging the mouse without multiple displays

This commit is contained in:
David Capello 2021-04-20 13:01:49 -03:00
parent 0c932779fb
commit c1be8f6727

View File

@ -151,20 +151,15 @@ bool ColorButton::onProcessMessage(Message* msg)
gfx::Point mousePos = static_cast<MouseMessage*>(msg)->position();
app::Color color = m_color;
// Pick a color from a IColorSource
Widget* picked = window()->pick(mousePos);
IColorSource* colorSource = (picked != this ? dynamic_cast<IColorSource*>(picked): nullptr);
// If there is no color source, get the color from the display
// surface, and finally from the desktop. The desktop must be
// a last resource method, because in macOS it will ask for
// permissions to record the screen.
if (!colorSource && get_multiple_displays()) {
os::Window* nativeWindow = display()->nativeWindow();
// Try to pick a color from a IColorSource, then get the color
// from the display surface, and finally from the desktop. The
// desktop must be a last resource method, because in macOS it
// will ask for permissions to record the screen.
os::Window* nativeWindow = msg->display()->nativeWindow();
gfx::Point screenPos = nativeWindow->pointToScreen(mousePos);
picked = manager()->pickFromScreenPos(screenPos);
colorSource = (picked != this ? dynamic_cast<IColorSource*>(picked): nullptr);
Widget* picked = manager()->pickFromScreenPos(screenPos);
IColorSource* colorSource = (picked != this ? dynamic_cast<IColorSource*>(picked): nullptr);
if (colorSource) {
nativeWindow = picked->display()->nativeWindow();
mousePos = nativeWindow->pointFromScreen(screenPos);
@ -189,7 +184,6 @@ bool ColorButton::onProcessMessage(Message* msg)
gfx::getb(gfxColor),
gfx::geta(gfxColor));
}
}
if (colorSource) {
color = colorSource->getColorByPosition(mousePos);