Skip to content

Commit

Permalink
ColorChooser : Use unfilled circle for indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmehl committed Oct 17, 2024
1 parent 421eff8 commit cc49449
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ Improvements

- Light Editor : Added `is_sphere` column for Cycles lights.
- Windows : Gaffer now uses the TBB memory allocator for significantly better performance.
- ColorChooser : Changed the color field widget to a color wheel when hue is one of the varying components. [^1]
- ColorChooser :
- Changed the color field widget to a color wheel when hue is one of the varying components. [^1]
- Changed the indicator for the color field and color sliders to an unfilled circle so the chosen color is visible in the center.

API
---
Expand Down
66 changes: 57 additions & 9 deletions python/GafferUI/ColorChooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ def _rgbToTMI( c ) :
"i" : __Range( 0, 1, -sys.float_info.max, sys.float_info.max ),
}

def _drawIndicator( painter, position ) :

painter.setBrush( QtCore.Qt.transparent )

pen = QtGui.QPen( QtGui.QColor( 0, 0, 0, 255 ) )
pen.setWidth( 1 )
painter.setPen( pen )

painter.drawEllipse( position, 4.5, 4.5 )

pen.setColor( QtGui.QColor( 255, 255, 255, 255 ) )
painter.setPen( pen )
painter.drawEllipse( position, 3.5, 3.5 )

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

Expand Down Expand Up @@ -158,6 +172,40 @@ def _drawBackground( self, painter ) :
brush = QtGui.QBrush( grad )
painter.fillRect( 0, 0, size.x, size.y, brush )

def _drawValue( self, painter, value, position, state ) :

size = self.size()

if position >= 0 and position <= size.x :
_drawIndicator( painter, QtCore.QPoint( position, size.y / 2 ) )
return

pen = QtGui.QPen( QtGui.QColor( 0, 0, 0, 255 ) )
pen.setWidth( 1 )
painter.setPen( pen )
painter.setBrush( QtGui.QColor( 255, 255, 255, 255 ) )

if position < 0 :
painter.drawPolygon(
QtGui.QPolygonF(
[
QtCore.QPointF( 8, 4 ),
QtCore.QPointF( 8, size.y - 4 ),
QtCore.QPointF( 2, size.y / 2 ),
]
)
)
elif position > size.x :
painter.drawPolygon(
QtGui.QPolygonF(
[
QtCore.QPointF( size.x - 8, 4 ),
QtCore.QPointF( size.x - 8, size.y - 4 ),
QtCore.QPointF( size.x - 2, size.y / 2 ),
]
)
)

def _displayTransformChanged( self ) :

GafferUI.Slider._displayTransformChanged( self )
Expand Down Expand Up @@ -429,27 +477,27 @@ def __drawValue( self, painter ) :

position = self.__colorToPosition( self.__color )

pen = QtGui.QPen( QtGui.QColor( 0, 0, 0, 255 ) )
pen.setWidth( 1 )
painter.setPen( pen )

color = QtGui.QColor( 119, 156, 255, 255 )

painter.setBrush( QtGui.QBrush( color ) )

size = self.size()

# Use a dot when both axes are a valid value.
positionClamped = self.__clampPosition( position )
delta = position - positionClamped

if abs( delta.x ) < 1e-3 and abs( delta.y ) < 1e-3 :
painter.drawEllipse( QtCore.QPoint( position.x, position.y ), 4.5, 4.5 )
_drawIndicator( painter, QtCore.QPoint( position.x, position.y ) )
return

triangleWidth = 5.0
triangleSpacing = 2.0

pen = QtGui.QPen( QtGui.QColor( 0, 0, 0, 255 ) )
pen.setWidth( 1 )
painter.setPen( pen )

color = QtGui.QColor( 255, 255, 255, 255 )

painter.setBrush( QtGui.QBrush( color ) )

offset = imath.V2f( 0 )

if self.__useWheel() :
Expand Down

0 comments on commit cc49449

Please sign in to comment.