From 9dfef01e9d2d8f8833f839228003902ae593d50b Mon Sep 17 00:00:00 2001 From: Eric Mehl Date: Wed, 4 Oct 2023 09:37:20 -0400 Subject: [PATCH] fixup! LightTool : Refactor WidthHeightHandle --- src/GafferSceneUI/LightTool.cpp | 72 ++++++++++++++++----------------- 1 file changed, 35 insertions(+), 37 deletions(-) diff --git a/src/GafferSceneUI/LightTool.cpp b/src/GafferSceneUI/LightTool.cpp index f688bf3e028..38d8b722517 100644 --- a/src/GafferSceneUI/LightTool.cpp +++ b/src/GafferSceneUI/LightTool.cpp @@ -826,7 +826,10 @@ class LightToolHandle : public Handle return true; } - return handleDragMoveInternal( event ); + const bool result = handleDragMoveInternal( event ); + updateTooltipPosition( event.line ); + + return result; } // Called by `LightTool` at the end of a drag event. @@ -896,7 +899,7 @@ class LightToolHandle : public Handle m_tooltipPosition(), m_lookThroughLight( false ) { - + mouseMoveSignal().connect( boost::bind( &LightToolHandle::mouseMove, this, ::_2 ) ); } // Returns true if `shaderAttribute` refers to the same light type @@ -1045,6 +1048,10 @@ class LightToolHandle : public Handle return ""; } + // Must be overriden to set the tooltip position in gadget space based + // on `eventLine` from a `DragDropEvent` or `ButtonEvent`. + virtual void updateTooltipPosition( const LineSegment3f &eventLine ) = 0; + // Must be overriden to make edits to the inspections in `handleDragMove()`. virtual bool handleDragMoveInternal( const GafferUI::DragDropEvent &event ) = 0; @@ -1062,6 +1069,14 @@ class LightToolHandle : public Handle private : + bool mouseMove( const ButtonEvent &event ) + { + updateTooltipPosition( event.line ); + dirty( DirtyType::Render ); + + return false; + } + void renderHandle( const Style *style, Style::State state ) const override { State::bindBaseState(); @@ -1212,9 +1227,6 @@ class SpotLightHandle : public LightToolHandle m_frustumScale( 1.f ), m_lensRadius( 0 ) { - - mouseMoveSignal().connect( boost::bind( &SpotLightHandle::mouseMove, this, ::_2 ) ); - } ~SpotLightHandle() override { @@ -1717,13 +1729,11 @@ class SpotLightHandle : public LightToolHandle return result; } - private : - - bool mouseMove( const ButtonEvent &event ) + void updateTooltipPosition( const LineSegment3f &eventLine ) { - if( !hasInspectors() || m_drag ) + if( !hasInspectors() ) { - return false; + return; } const auto &[coneHandleAngle, penumbraHandleAngle] = handleAngles(); @@ -1735,15 +1745,13 @@ class SpotLightHandle : public LightToolHandle V3f( 0 ), V3f( 0, 0, m_visualiserScale * m_frustumScale * -10.f ) * r ); - const V3f dragPoint = rayLine.closestPointTo( Line3f( event.line.p0, event.line.p1 ) ); + const V3f dragPoint = rayLine.closestPointTo( Line3f( eventLine.p0, eventLine.p1 ) ); setTooltipPosition( dragPoint ); m_arcRadius = dragPoint.length(); - - dirty( DirtyType::Render ); - - return false; } + private : + std::pair> handleAngles() const { Inspector::ResultPtr coneHandleInspection = handleInspection( g_coneAngleParameter ); @@ -1893,7 +1901,6 @@ class EdgeHandle : public LightToolHandle m_oppositeToHandleRatio( oppositeToHandleRatio ), m_scale( 1.f ) { - mouseMoveSignal().connect( boost::bind( &EdgeHandle::mouseMove, this, ::_2 ) ); } ~EdgeHandle() override @@ -2025,20 +2032,18 @@ class EdgeHandle : public LightToolHandle return ""; } - private : - - bool mouseMove( const ButtonEvent &event ) + void updateTooltipPosition( const LineSegment3f &eventLine ) { if( !hasInspectors() ) { - return false; + return; } Inspector::ResultPtr edgeInspection = handleInspection( m_edgeParameter ); Inspector::ResultPtr oppositeInspection = handleInspection( m_oppositeParameter ); if( !edgeInspection || !oppositeInspection ) { - return false; + return; } LineSegment3f edgeSegment = this->edgeSegment( edgeInspection->typedValue( 0.f ), oppositeInspection->typedValue( 0.f ) ); @@ -2047,13 +2052,11 @@ class EdgeHandle : public LightToolHandle edgeSegment.p1 += offset; V3f eventClosest; - setTooltipPosition( edgeSegment.closestPoints( LineSegment3f( event.line.p0, event.line.p1 ), eventClosest ) ); - - dirty( DirtyType::Render ); - - return false; + setTooltipPosition( edgeSegment.closestPoints( LineSegment3f( eventLine.p0, eventLine.p1 ), eventClosest ) ); } + private : + V3f edgeToGadgetSpace( const float edge ) const { const float scale = m_lightAxis == LightAxis::Width ? m_scale.x : m_scale.y; @@ -2167,7 +2170,6 @@ class CornerHandle : public LightToolHandle m_scale( V2f( 1.f ) ), m_drag() { - mouseMoveSignal().connect( boost::bind( &CornerHandle::mouseMove, this, ::_2 ) ); } ~CornerHandle() override @@ -2213,8 +2215,6 @@ class CornerHandle : public LightToolHandle xMult = std::max( xMult, 0.f ); yMult = std::max( yMult, 0.f ); - setTooltipPosition( edgeTooltipPosition( widthInspection->typedValue( 0.f ) * xMult, heightInspection->typedValue( 0.f ) * yMult ) ); - applyMultiplier( m_widthParameter, xMult ); applyMultiplier( m_heightParameter, yMult ); @@ -2312,30 +2312,28 @@ class CornerHandle : public LightToolHandle return "Hold Ctrl to maintain aspect ratio"; } - private : - - bool mouseMove( const ButtonEvent &event ) + void updateTooltipPosition( const LineSegment3f &eventLine ) { if( !hasInspectors() ) { - return false; + return; } Inspector::ResultPtr widthInspection = handleInspection( m_widthParameter ); Inspector::ResultPtr heightInspection = handleInspection( m_heightParameter ); if( !widthInspection || !heightInspection ) { - return false; + return; } setTooltipPosition( edgeTooltipPosition( widthInspection->typedValue( 0.f ), heightInspection->typedValue( 0.f ) ) ); - - return false; } + private : + V3f edgeTooltipPosition( const float width, const float height ) const { - return ( width * 0.5f * m_widthAxis ) + ( height * 0.5f * m_heightAxis ); + return ( width * 0.5f * m_widthAxis * m_scale.x ) + ( height * 0.5f * m_heightAxis * m_scale.y ); } const InternedString m_widthParameter;