Skip to content

Commit

Permalink
fixup! LightPositionTool : Add tool for placing shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmehl committed Nov 22, 2023
1 parent d5254ab commit 3eb722a
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/GafferSceneUI/LightPositionTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,10 @@ size_t LightPositionTool::g_firstPlugIndex = 0;

LightPositionTool::LightPositionTool( SceneView *view, const std::string &name ) :
TransformTool( view, name ),
m_positionMode( PositionMode::ShadowPoint ),
m_shadowPivot( std::nullopt ),
m_shadowPoint( std::nullopt )
{
SceneGadget *sg = runTimeCast<SceneGadget>( this->view()->viewportGadget()->getPrimaryChild() );
sg->keyPressSignal().connect( boost::bind( &LightPositionTool::keyPress, this, ::_2 ) );
sg->keyReleaseSignal().connect( boost::bind( &LightPositionTool::keyRelease, this, ::_2 ) );
// We have to insert this before the underlying SelectionTool connections or it starts an object drag.
sg->buttonPressSignal().connectFront( boost::bind( &LightPositionTool::buttonPress, this, ::_2 ) );

Expand All @@ -90,6 +87,8 @@ LightPositionTool::LightPositionTool( SceneView *view, const std::string &name )

view->plugInputChangedSignal().connect( boost::bind( &LightPositionTool::plugInputChanged, this, ::_1 ) );

selectionChangedSignal().connect( boost::bind( &LightPositionTool::selectionChanged, this, ::_1 ) );

storeIndexOfNextChild( g_firstPlugIndex );
}

Expand Down Expand Up @@ -196,15 +195,10 @@ bool LightPositionTool::keyRelease( const KeyEvent &event )

void LightPositionTool::plugSet( Plug *plug )
{
if( plug == activePlug() )
if( plug == activePlug() && !activePlug()->getValue() )
{
m_positionMode = PositionMode::None;
if( !activePlug()->getValue() )
{
m_shadowPivot = std::nullopt;
m_shadowPoint = std::nullopt;
}

m_shadowPivot = std::nullopt;
m_shadowPoint = std::nullopt;
}
}

Expand All @@ -219,7 +213,14 @@ void LightPositionTool::plugInputChanged( Plug *plug )

bool LightPositionTool::buttonPress( const ButtonEvent &event )
{
if( event.button != ButtonEvent::Left || !activePlug()->getValue() || m_positionMode == PositionMode::None )
if(
event.button != ButtonEvent::Left ||
!activePlug()->getValue() ||
!(
event.modifiers == ButtonEvent::Control ||
event.modifiers == ButtonEvent::Shift
)
)
{
return false;
}
Expand All @@ -238,11 +239,11 @@ bool LightPositionTool::buttonPress( const ButtonEvent &event )
return true;
}

if( m_positionMode == PositionMode::ShadowPivot )
if( event.modifiers == ButtonEvent::Control )
{
m_shadowPivot = targetPos * sceneGadget->fullTransform();
}
else if( m_positionMode == PositionMode::ShadowPoint )
else if( event.modifiers == ButtonEvent::Shift )
{
m_shadowPoint = targetPos * sceneGadget->fullTransform();
}
Expand All @@ -266,7 +267,6 @@ void LightPositionTool::contextChanged( const InternedString &name )
{
if( ContextAlgo::affectsSelectedPaths( name ) )
{
m_positionMode = PositionMode::None;
m_shadowPivot = std::nullopt;
m_shadowPoint = std::nullopt;
}
Expand Down

0 comments on commit 3eb722a

Please sign in to comment.