Skip to content

Commit

Permalink
fixup! LightTool : Refactor WidthHeightHandle
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmehl committed Oct 4, 2023
1 parent 0b95883 commit 9dfef01
Showing 1 changed file with 35 additions and 37 deletions.
72 changes: 35 additions & 37 deletions src/GafferSceneUI/LightTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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();
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
Expand All @@ -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<float, std::optional<float>> handleAngles() const
{
Inspector::ResultPtr coneHandleInspection = handleInspection( g_coneAngleParameter );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<float>( 0.f ), oppositeInspection->typedValue<float>( 0.f ) );
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2213,8 +2215,6 @@ class CornerHandle : public LightToolHandle
xMult = std::max( xMult, 0.f );
yMult = std::max( yMult, 0.f );

setTooltipPosition( edgeTooltipPosition( widthInspection->typedValue<float>( 0.f ) * xMult, heightInspection->typedValue<float>( 0.f ) * yMult ) );

applyMultiplier( m_widthParameter, xMult );
applyMultiplier( m_heightParameter, yMult );

Expand Down Expand Up @@ -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<float>( 0.f ), heightInspection->typedValue<float>( 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;
Expand Down

0 comments on commit 9dfef01

Please sign in to comment.