Skip to content

Commit

Permalink
Merge pull request #6206 from murraystevenson/sceneViewShadingToggle
Browse files Browse the repository at this point in the history
SceneViewUI : Shading mode menu improvements
  • Loading branch information
johnhaddon authored Jan 13, 2025
2 parents 0cd95e7 + 37e2cab commit 4abc2fb
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Improvements

- VisualiserTool : Changed `dataName` input widget for choosing the primitive variable to visualise to a list of available variable names for the current selection.
- Tweaks nodes : Moved list of tweaks to a collapsible "Tweaks" section in the NodeEditor.
- Viewer :
- The shading mode menu icon now updates to indicate when a non-default shading mode is in use.
- Added the ability to toggle between default shading and the last selected shading mode by <kbd>Ctrl</kbd> + clicking the shading mode menu button.

Fixes
-----
Expand Down
52 changes: 50 additions & 2 deletions python/GafferSceneUI/SceneViewUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import GafferSceneUI
import GafferImage

from GafferUI.PlugValueWidget import sole
from ._SceneViewInspector import _SceneViewInspector

def __rendererPlugActivator( plug ) :
Expand Down Expand Up @@ -548,18 +549,44 @@ class _ShadingModePlugValueWidget( GafferUI.PlugValueWidget ) :

def __init__( self, plug, **kw ) :

menuButton = GafferUI.MenuButton(
self.__menuButton = GafferUI.MenuButton(
image = "shading.png",
menu = GafferUI.Menu( Gaffer.WeakMethod( self.__menuDefinition ), title="Shading" ),
hasFrame = False,
)

GafferUI.PlugValueWidget.__init__( self, menuButton, plug, **kw )
GafferUI.PlugValueWidget.__init__( self, self.__menuButton, plug, **kw )

self.__menuButton.buttonPressSignal().connect( Gaffer.WeakMethod( self.__buttonPress ) )
self.__menuButton.buttonDoubleClickSignal().connect( Gaffer.WeakMethod( self.__buttonDoubleClick ) )

self.__shadingModeToggle = Gaffer.Metadata.value( plug, "shadingModePlugValueWidget:defaultShadingModeToggle" )

def hasLabel( self ) :

return True

def getToolTip( self ) :

result = GafferUI.PlugValueWidget.getToolTip( self )

if self.__shadingModeToggle is not None :
if result :
result += "\n"
result += "## Actions\n\n"
result += "- <kbd>Ctrl</kbd> + click to toggle shading to `{}`\n".format( self.__shadingModeToggle if self.getPlug().isSetToDefault() else "Default" )

return result

def _updateFromValues( self, values, exception ) :

value = sole( values )
if value != self.getPlug().defaultValue() :
self.__shadingModeToggle = value
self.__menuButton.setImage( "shadingOn.png" )
else :
self.__menuButton.setImage( "shading.png" )

def __menuDefinition( self ) :

m = IECore.MenuDefinition()
Expand All @@ -583,6 +610,27 @@ def __setValue( self, value, *unused ) :

self.getPlug().setValue( value )

def __buttonPress( self, widget, event ) :

if event.buttons == event.Buttons.Left and event.modifiers == event.Modifiers.Control :

if not self.getPlug().isSetToDefault() :
self.getPlug().setToDefault()
elif self.__shadingModeToggle is not None :
self.getPlug().setValue( self.__shadingModeToggle )

return True

return False

def __buttonDoubleClick( self, widget, event ) :

if event.buttons == event.Buttons.Left and event.modifiers == event.Modifiers.Control :
# Prevent menu from opening when Control is held.
return True

return False

##########################################################################
# _ExpansionPlugValueWidget
##########################################################################
Expand Down
3 changes: 2 additions & 1 deletion resources/graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@
'grid', # \todo rename to 'sceneViewGadgets'
'selectionMaskOff',
'selectionMaskOn',
'shading'
'shading',
'shadingOn',
]

},
Expand Down
57 changes: 43 additions & 14 deletions resources/graphics.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4abc2fb

Please sign in to comment.