mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-06 14:59:50 +00:00
Select the initial ColorButton color when we go back to the button
If start dragging from the ColorButton, we go outside the button, and then we go back to the same button, we should select the original color when the whole drag-and-drop process started. We have also improved the look of the button in that case: the original color is displayed (instead of the inverted color, which is when the button is selected, in this way is less confusing).
This commit is contained in:
parent
b26d3dc7b6
commit
89fcd44394
@ -160,9 +160,12 @@ bool ColorButton::onProcessMessage(Message* msg)
|
||||
|
||||
Widget* picked = manager()->pickFromScreenPos(screenPos);
|
||||
if (picked == this) {
|
||||
// Do nothing
|
||||
setColor(m_startDragColor);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
m_mouseLeft = true;
|
||||
}
|
||||
|
||||
IColorSource* colorSource = dynamic_cast<IColorSource*>(picked);
|
||||
if (colorSource) {
|
||||
@ -302,6 +305,20 @@ void ColorButton::onClick(Event& ev)
|
||||
}
|
||||
}
|
||||
|
||||
void ColorButton::onStartDrag()
|
||||
{
|
||||
m_startDragColor = m_color;
|
||||
m_mouseLeft = false;
|
||||
}
|
||||
|
||||
void ColorButton::onSelectWhenDragging()
|
||||
{
|
||||
if (m_mouseLeft)
|
||||
setSelected(false);
|
||||
else
|
||||
ButtonBase::onSelectWhenDragging();
|
||||
}
|
||||
|
||||
void ColorButton::onLoadLayout(ui::LoadLayoutEvent& ev)
|
||||
{
|
||||
if (canPin()) {
|
||||
|
@ -58,6 +58,8 @@ namespace app {
|
||||
void onSizeHint(ui::SizeHintEvent& ev) override;
|
||||
void onPaint(ui::PaintEvent& ev) override;
|
||||
void onClick(ui::Event& ev) override;
|
||||
void onStartDrag() override;
|
||||
void onSelectWhenDragging() override;
|
||||
void onLoadLayout(ui::LoadLayoutEvent& ev) override;
|
||||
void onSaveLayout(ui::SaveLayoutEvent& ev) override;
|
||||
|
||||
@ -75,12 +77,14 @@ namespace app {
|
||||
gfx::Rect convertBounds(const gfx::Rect& bounds) const;
|
||||
|
||||
app::Color m_color;
|
||||
app::Color m_startDragColor;
|
||||
PixelFormat m_pixelFormat;
|
||||
ColorPopup* m_window;
|
||||
gfx::Rect m_windowDefaultBounds;
|
||||
gfx::Rect m_hiddenPopupBounds;
|
||||
bool m_desktopCoords; // True if m_windowDefault/hiddenPopupBounds are screen coordinates
|
||||
bool m_dependOnLayer;
|
||||
bool m_mouseLeft;
|
||||
ColorButtonOptions m_options;
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2019 Igara Studio S.A.
|
||||
// Copyright (C) 2019-2021 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -165,6 +165,8 @@ bool ButtonBase::onProcessMessage(Message* msg)
|
||||
|
||||
m_pressedStatus = isSelected();
|
||||
captureMouse();
|
||||
|
||||
onStartDrag();
|
||||
}
|
||||
return true;
|
||||
|
||||
@ -174,6 +176,8 @@ bool ButtonBase::onProcessMessage(Message* msg)
|
||||
|
||||
m_pressedStatus = isSelected();
|
||||
captureMouse();
|
||||
|
||||
onStartDrag();
|
||||
}
|
||||
return true;
|
||||
|
||||
@ -186,6 +190,8 @@ bool ButtonBase::onProcessMessage(Message* msg)
|
||||
|
||||
m_pressedStatus = isSelected();
|
||||
captureMouse();
|
||||
|
||||
onStartDrag();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -231,19 +237,8 @@ bool ButtonBase::onProcessMessage(Message* msg)
|
||||
|
||||
case kMouseMoveMessage:
|
||||
if (isEnabled() && hasCapture()) {
|
||||
bool hasMouse = hasMouseOver();
|
||||
|
||||
m_handleSelect = false;
|
||||
|
||||
// Switch state when the mouse go out
|
||||
if ((hasMouse && isSelected() != m_pressedStatus) ||
|
||||
(!hasMouse && isSelected() == m_pressedStatus)) {
|
||||
if (hasMouse)
|
||||
setSelected(m_pressedStatus);
|
||||
else
|
||||
setSelected(!m_pressedStatus);
|
||||
}
|
||||
|
||||
onSelectWhenDragging();
|
||||
m_handleSelect = true;
|
||||
}
|
||||
break;
|
||||
@ -269,6 +264,25 @@ void ButtonBase::generateButtonSelectSignal()
|
||||
onClick(ev);
|
||||
}
|
||||
|
||||
void ButtonBase::onStartDrag()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void ButtonBase::onSelectWhenDragging()
|
||||
{
|
||||
bool hasMouse = hasMouseOver();
|
||||
|
||||
// Switch state when the mouse go out
|
||||
if ((hasMouse && isSelected() != m_pressedStatus) ||
|
||||
(!hasMouse && isSelected() == m_pressedStatus)) {
|
||||
if (hasMouse)
|
||||
setSelected(m_pressedStatus);
|
||||
else
|
||||
setSelected(!m_pressedStatus);
|
||||
}
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
// Button class
|
||||
// ======================================================================
|
||||
|
@ -1,4 +1,5 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2021 Igara Studio S.A.
|
||||
// Copyright (C) 2001-2018 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
@ -40,6 +41,8 @@ namespace ui {
|
||||
|
||||
// New events
|
||||
virtual void onClick(Event& ev);
|
||||
virtual void onStartDrag();
|
||||
virtual void onSelectWhenDragging();
|
||||
|
||||
private:
|
||||
void generateButtonSelectSignal();
|
||||
|
Loading…
Reference in New Issue
Block a user