Skip to content

Commit

Permalink
fixup! ColorChooser : Maintain hue, saturation at zero
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmehl committed Jun 20, 2024
1 parent ffeeb77 commit f2fd617
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions python/GafferUI/ColorChooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,34 +235,39 @@ def __componentValueChanged( self, componentWidget, reason ) :

if componentWidget.component in ( "r", "g", "b", "a" ) :
newColor = self.__color.__class__( self.__color )

a = { "r" : 0, "g" : 1, "b" : 2, "a" : 3 }[componentWidget.component]
newColor[a] = componentValue

self.__setColorInternal( newColor, reason )
else :
newColor = self.__colorHSV.__class__( self.__colorHSV )

a = { "h" : 0, "s" : 1, "v" : 2 }[componentWidget.component]
newColor[a] = componentValue
newColor = newColor.hsv2rgb()

self.__setColorInternal( newColor, reason )
self.__setColorInternal( newColor, reason, True )

def __setColorInternal( self, color, reason ) :
def __setColorInternal( self, color, reason, hsv = False ) :

dragBeginOrEnd = reason in (
GafferUI.Slider.ValueChangedReason.DragBegin,
GafferUI.Slider.ValueChangedReason.DragEnd,
GafferUI.NumericWidget.ValueChangedReason.DragBegin,
GafferUI.NumericWidget.ValueChangedReason.DragEnd,
)
if color != self.__color or dragBeginOrEnd :

previousColor = self.__colorHSV if hsv else self.__color

if color != previousColor or dragBeginOrEnd :
# we never optimise away drag begin or end, because it's important
# that they emit in pairs.
self.__color = color
self.__colorSwatch.setColor( color )
colorRGB = color.hsv2rgb() if hsv else color
self.__color = colorRGB
self.__colorSwatch.setColor( colorRGB )
self.__colorChangedSignal( self, reason )

hsv = self.__color.rgb2hsv()
hsv = color if hsv else color.rgb2hsv()

hsv[0] = hsv[0] if hsv[1] > 1e-7 and hsv[2] > 1e-7 else self.__colorHSV[0]
hsv[1] = hsv[1] if hsv[2] > 1e-7 else self.__colorHSV[1]
Expand Down

0 comments on commit f2fd617

Please sign in to comment.