Skip to content

Commit

Permalink
ColorChooser : Use hollow circle for color sliders
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmehl committed Oct 16, 2024
1 parent f2b64a3 commit aa9ac38
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Improvements

- Light Editor : Added `is_sphere` column for Cycles lights.
- Windows : Gaffer now uses the TBB memory allocator for significantly better performance.
- ColorChooser : Changed color field indicator to a hollow circle so the chosen color is visible.
- ColorChooser : Changed color field and color slider indicators to a hollow circle so the chosen color is visible.

Breaking Changes
----------------
Expand Down
25 changes: 21 additions & 4 deletions python/GafferUI/ColorChooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ def _rgbToTMI( c ) :
"i" : __Range( 0, 1, -sys.float_info.max, sys.float_info.max ),
}

def _indicator( radius ) :

circle = QtGui.QPainterPath()
circle.addEllipse( -radius, -radius, radius * 2.0, radius * 2.0 )
circle.addEllipse( -radius + 2.0, -radius + 2.0, radius * 2.0 - 4.0, radius * 2.0 - 4.0 )

return circle

# A custom slider for drawing the backgrounds.
class _ComponentSlider( GafferUI.Slider ) :

Expand All @@ -114,6 +122,7 @@ def __init__( self, color, component, **kw ) :

self.color = color
self.component = component
self.__indicatorPainterPath = None

# Sets the slider color in RGB space for RGBA channels,
# HSV space for HSV channels and TMI space for TMI channels.
Expand Down Expand Up @@ -158,6 +167,17 @@ def _drawBackground( self, painter ) :
brush = QtGui.QBrush( grad )
painter.fillRect( 0, 0, size.x, size.y, brush )

def _indicatorPainterPath( self, radius ) :

if self.__indicatorPainterPath is None :
self.__indicatorPainterPath = _indicator( radius )

return self.__indicatorPainterPath

def _indicatorColor( self, state ) :

return QtGui.QColor( 255, 255, 255, 255 )

def _displayTransformChanged( self ) :

GafferUI.Slider._displayTransformChanged( self )
Expand All @@ -184,10 +204,7 @@ def __init__( self, color = imath.Color3f( 1.0 ), staticComponent = "s", **kw )
self.__colorFieldToDraw = None
self.setColor( color, staticComponent )

self.__indicatorPainterPath = QtGui.QPainterPath()
radius = 4.5
self.__indicatorPainterPath.addEllipse( -radius, -radius, radius * 2.0, radius * 2.0 )
self.__indicatorPainterPath.addEllipse( -radius + 2.0, -radius + 2.0, radius * 2.0 - 4.0, radius * 2.0 - 4.0 )
self.__indicatorPainterPath = _indicator( 4.5 )

# Sets the color and the static component. `color` is in
# RGB space for RGB static components, HSV space for
Expand Down
29 changes: 24 additions & 5 deletions python/GafferUI/Slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def __init__( self, values=0.5, min=0, max=1, hardMin=None, hardMax=None, **kw )
self.__hoverPositionVisible = False
self.__hoverEvent = None # The mouseMove event that gives us hover status

self.__indicatorPainterPath = None # Created in `_drawValue()` where we know the size

self.leaveSignal().connect( Gaffer.WeakMethod( self.__leave ) )
self.mouseMoveSignal().connect( Gaffer.WeakMethod( self.__mouseMove ) )
self.buttonPressSignal().connect( Gaffer.WeakMethod( self.__buttonPress ) )
Expand Down Expand Up @@ -333,10 +335,7 @@ def _drawValue( self, painter, value, position, state ) :
pen.setWidth( 1 )
painter.setPen( pen )

if state == state.NormalState :
color = QtGui.QColor( 128, 128, 128, 255 )
else :
color = QtGui.QColor( 119, 156, 255, 255 )
color = self._indicatorColor( state )
painter.setBrush( QtGui.QBrush( color ) )

if state == state.DisabledState :
Expand All @@ -363,7 +362,27 @@ def _drawValue( self, painter, value, position, state ) :
)
)
else :
painter.drawEllipse( QtCore.QPoint( position, size.y / 2 ), size.y / 4, size.y / 4 )
painter.drawPath( self._indicatorPainterPath( size.y / 4 ).translated( position, size.y / 2 ) )

## May be overriden by derived classes to customise the
# value indicator when it is within the min / max values.
# This will be called once for each `paintEvent`, derived
# classes should consider caching the path for better performance.
def _indicatorPainterPath( self, radius ) :

if self.__indicatorPainterPath is None :
self.__indicatorPainterPath = QtGui.QPainterPath()
self.__indicatorPainterPath.addEllipse( -radius, -radius, radius * 2.0, radius * 2.0 )

return self.__indicatorPainterPath

## May be overridden by derived classes to customize the
# color of the indicator.
def _indicatorColor( self, state ) :

if state == state.NormalState :
return QtGui.QColor( 128, 128, 128, 255 )
return QtGui.QColor( 119, 156, 255, 255 )

def __indexUnderMouse( self ) :

Expand Down

0 comments on commit aa9ac38

Please sign in to comment.