// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // This file contains procedures relating to the Curve Colors window, // invoked from the Graph Editor's Edit/Set Curve Colors menu item. // global proc showCurveColorWindow( string $editor ) // // Description: // Creates and shows the Curve Colors window. // // Parameters: // editor - The editor that the window relates to (typically the Graph Editor's Outliner) // { // delete the window if it already exists if ( `window -ex curveColorWindow` == true ) { deleteUI curveColorWindow; } // create the window window -title (uiRes("m_showCurveColorWindow.kCurveColorsTitle")) -mxb true -mnb true -s true curveColorWindow; // create the controls string $form = `formLayout`; // scroll list for attributes string $list = `textScrollList -allowMultiSelection off`; string $column = `columnLayout -rs 10 -cw 150 -cat "both" 10`; // color swatch string $colorEd = `colorSliderGrp -cw3 1 50 50 -label ""`; // buttons string $buttonAdd = `button -label (uiRes("m_showCurveColorWindow.kAdd"))`; string $buttonRemove = `button -label (uiRes("m_showCurveColorWindow.kRemove"))`; button -e -en off $buttonRemove; setParent ..; // lay out the form formLayout -e -af $list "top" 10 -af $list "bottom" 10 -af $list "left" 10 -ac $list "right" 0 $column -af $column "top" 10 -af $column "bottom" 10 -af $column "right" 10 $form; // set the commands button -e -c ( "curveColorWindowAdd " + $editor + " " + $list + " " + $colorEd + " " + $buttonRemove ) $buttonAdd; button -e -c ( "curveColorWindowRemove " + $list + " " + $buttonRemove ) $buttonRemove; textScrollList -e -sc ( "curveColorWindowSelect " + $list + " " + $colorEd + " " + $buttonRemove ) $list; colorSliderGrp -e -cc ( "curveColorWindowColorChanged " + $colorEd ) $colorEd; // populate the list string $name, $names[] = `curveRGBColor -ln`; $names = `sort $names`; for ( $name in $names ) { textScrollList -e -a $name $list; } // when opening the window, automatically add anything selected in the outliner curveColorWindowAdd $editor $list $colorEd $buttonRemove; // set up a scriptJob so that the curveRGBColor command can cause UI updates scriptJob -protected -parent curveColorWindow -event "CurveRGBColorChanged" ( "curveColorWindowUpdate " + $list + " " + $colorEd + " " + $buttonRemove ); // finally show the window showWindow curveColorWindow; } global proc curveColorWindowAdd( string $editor, string $list, string $colorEd, string $buttonRemove ) // // Description: // Handles the 'Add' button in the Curve Colors window. // Adds any channels selected in the editor to the list of custom curve colours. // // Parameters: // editor - The editor that the window relates to (typically the Graph Editor's Outliner) // list - The Curve Colors window's textScrollList // colorEd - The Curve Colors window's colorSliderGrp // buttonRemove - The Curve Colors window's 'Remove' button // { if ( `editor -exists $editor` ) { // Get the editor's selection connection. string $selectionConnection, $selectionList[]; $selectionConnection = `editor -query -selectionConnection $editor`; if ( "" == $selectionConnection ) { // Editor does not have a selection connection - assume it is // using the active list. $selectionConnection = "activeList"; } // Get the items selected in the editor. $selectionList = `selectionConnection -query -object $selectionConnection`; // Get the items currently in the list. string $item, $items[] = `textScrollList -q -ai $list`; string $toSelect = ""; // Look for selected channels (i.e. not selected objects). string $selectionItem, $tokens[]; for ( $selectionItem in $selectionList ) { // Attributes are recognised by the dot that separates node and attribute names. if ( 2 == tokenize( $selectionItem, ".", $tokens ) ) { string $attr = $tokens[1]; // Don't add items already in the list. if ( !`stringArrayContains $attr $items` ) { $items[ size($items) ] = $attr; // Set up the custom colour. curveRGBColor $attr 1 0 1; $toSelect = $attr; } } } // Sort the list, and recreate the list in the control. $items = `sort $items`; textScrollList -e -ra $list; for ( $item in $items ) { textScrollList -e -a $item $list; } // Select the last attribute we added, if any. if ( size($toSelect) > 0 ) { textScrollList -e -si $toSelect $list; curveColorWindowSelect $list $colorEd $buttonRemove; } } } global proc curveColorWindowRemove( string $list, string $buttonRemove ) // // Description: // Handles the 'Remove' button in the Curve Colors window. // Removes any channels selected in the list from the list of custom curve colours. // // Parameters: // list - The Curve Colors window's textScrollList // buttonRemove - The Curve Colors window's 'Remove' button // { // Get the selected item(s). string $item, $items[] = `textScrollList -q -si $list`; for ( $item in $items ) { // Remove from the list. textScrollList -e -ri $item $list; // Remove from the custom colours. curveRGBColor -r $item; } // Disable the 'Remove' button, since nothing is selected. button -e -en off $buttonRemove; } global proc curveColorWindowSelect( string $list, string $colorEd, string $buttonRemove ) // // Description: // Handles the selection of a name in the Curve Colors window's textScrollList. // // Parameters: // list - The Curve Colors window's textScrollList // colorEd - The Curve Colors window's colorSliderGrp // buttonRemove - The Curve Colors window's 'Remove' button // { // Get the selected item(s). string $item, $items[] = `textScrollList -q -si $list`; if ( size($items) > 0 ) { $item = $items[0]; // Get the colour for this item. float $rgb[] = `curveRGBColor -q $item`; // Update the colour editor. colorSliderGrp -e -rgbValue $rgb[0] $rgb[1] $rgb[2] $colorEd; // Record the custom colour name that we're editing. colorSliderGrp -e -ann $item $colorEd; // Enable the 'Remove' button, since we now have a selection. button -e -en on $buttonRemove; } } global proc curveColorWindowColorChanged( string $colorEd ) // // Description: // Handles a change in the Curve Colors window's colour editor. // // Parameters: // colorEd - The Curve Colors window's colorSliderGrp // { // Get the custom colour name that we're editing. string $item = `colorSliderGrp -q -ann $colorEd`; // Get the colour from the editor. float $rgb[] = `colorSliderGrp -q -rgbValue $colorEd`; // Update the custom colour. curveRGBColor $item $rgb[0] $rgb[1] $rgb[2]; } global proc curveColorWindowUpdate( string $list, string $colorEd, string $buttonRemove ) // // Description: // Updates the Curve Colors window (typically in response to a trigger from // the curveRGBColor command). // // Parameters: // list - The Curve Colors window's textScrollList // colorEd - The Curve Colors window's colorSliderGrp // buttonRemove - The Curve Colors window's 'Remove' button // { // store the selection string $sel, $sels[] = `textScrollList -q -si $list`; // populate the list textScrollList -e -ra $list; string $name, $names[] = `curveRGBColor -ln`; $names = `sort $names`; for ( $name in $names ) { textScrollList -e -a $name $list; } // restore the selection string $items[] = `textScrollList -q -ai $list`; for ( $sel in $sels ) { if ( `stringArrayContains $sel $items` ) textScrollList -e -si $sel $list; } // update the colour editor and 'remove' button curveColorWindowSelect $list $colorEd $buttonRemove; }