Skip to content

Commit

Permalink
VisualiserTool : Drag value from buttonPress()
Browse files Browse the repository at this point in the history
Previously, we were returning the cursor value at `dragBegin()`, which
would be slightly different from what the user would expect from
pressing and holding the cursor and noting the value shown on hover.

This is due to updating the cursor value during the small movement
required to signal a drag. Holding the cursor value at the time of
`buttonPress()`, allows us to use that as the drag value.

Fixes #6191.
  • Loading branch information
ericmehl committed Jan 6, 2025
1 parent feb37d0 commit e99d893
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
4 changes: 4 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
1.5.x.x (relative to 1.5.2.0)
=======

Fixes
-----

- VisualiserTool : Fixed bug where the value dragged from the visualiser would be slightly different from the initial value on button press. (#6191)


1.5.2.0 (relative to 1.5.1.0)
Expand Down
2 changes: 1 addition & 1 deletion include/GafferSceneUI/Private/VisualiserTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class GAFFERSCENEUI_API VisualiserTool : public SelectionTool
bool m_gadgetDirty;
mutable bool m_selectionDirty;
bool m_priorityPathsDirty;
bool m_acceptedButtonPress;
IECore::DataPtr m_valueAtButtonPress;
bool m_initiatedDrag;

static ToolDescription<VisualiserTool, SceneView> m_toolDescription;
Expand Down
33 changes: 14 additions & 19 deletions src/GafferSceneUI/VisualiserTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ VisualiserTool::VisualiserTool( SceneView *view, const std::string &name ) : Sel
m_gadgetDirty( true ),
m_selectionDirty( true ),
m_priorityPathsDirty( true ),
m_acceptedButtonPress( false ),
m_valueAtButtonPress(),
m_initiatedDrag( false )
{
view->viewportGadget()->addChild( m_gadget );
Expand Down Expand Up @@ -956,15 +956,15 @@ bool VisualiserTool::keyPress( const KeyEvent &event )
bool VisualiserTool::buttonPress( const ButtonEvent &event )
{
m_acceptedButtonPress = false;
m_valueAtButtonPress.reset();
m_initiatedDrag = false;
if( event.button & ButtonEvent::Left && !( event.modifiers & GafferUI::ButtonEvent::Modifiers::Control ) )
{
updateCursorValue();
if( m_cursorValue )
{
m_acceptedButtonPress = true;
m_valueAtButtonPress = m_cursorValue->copy();
return true;
}
}
Expand All @@ -974,7 +974,7 @@ bool VisualiserTool::buttonPress( const ButtonEvent &event )
bool VisualiserTool::buttonRelease( const ButtonEvent &event )
{
m_acceptedButtonPress = false;
m_valueAtButtonPress.reset();
m_initiatedDrag = false;
return false;
Expand All @@ -984,27 +984,22 @@ RunTimeTypedPtr VisualiserTool::dragBegin( const DragDropEvent &event )
{
m_initiatedDrag = false;
if( !m_acceptedButtonPress )
if( !m_valueAtButtonPress )
{
return RunTimeTypedPtr();
}
m_acceptedButtonPress = false;
// NOTE : There is a possibility that the tool has become inactive since the button
// press event that triggered the drag was accepted, the cutoff point is the
// button press event, so any change to the active state after that does not
// affect an ongoing drag operation. We therefore always request a redraw
// here so that the displayed value is cleared.
if( m_cursorValue )
{
// NOTE : There is a possibility that the tool has become inactive since the button
// press event that triggered the drag was accepted, the cutoff point is the
// button press event, so any change to the active state after that does not
// affect an ongoing drag operation. We therefore always request a redraw
// here so that the displayed value is cleared.
m_initiatedDrag = true;
view()->viewportGadget()->renderRequestSignal()( view()->viewportGadget() );
Pointer::setCurrent( "values" );
}
m_initiatedDrag = true;
view()->viewportGadget()->renderRequestSignal()( view()->viewportGadget() );
Pointer::setCurrent( "values" );
return m_cursorValue;
return m_valueAtButtonPress;
}
bool VisualiserTool::dragEnd( const DragDropEvent &event )
Expand Down

0 comments on commit e99d893

Please sign in to comment.