// Copyright (C) 1997-2004 Alias Systems Corp.
// 
// The information in this file is provided for the exclusive use of the
// licensees of Alias.  Such users have the right to use, modify,
// and incorporate this code into other products for purposes authorized
// by the Alias license agreement, without fee.
// 
// ALIAS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
// INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
// EVENT SHALL ALIAS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
// CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
// DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
// TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.

//
//  Alias Script File
//
//  Creation Date:	October 29, 1998
//
//  Procedure Name:
//	AEdisplayLayerNoScroll
//
//  Description Name;
//	Creates the attribute editor controls for the displayLayer Node
//
//  Input Value:
//	nodeName 
//
//  Output Value:
//	None
// 

global proc int getCurrentColor( string $layerColorAttr )
{
	int $color = `getAttr $layerColorAttr`;
	if ( $color < 1 ) {
		$color = 0;	// If out of range select the invisible color
	} else if ( $color > 31 ) {
		$color = 31;
	}
	return $color + 1;
}

global proc changeObjColor ( string $layerColorAttr, string $colorCtrl )
{

	int $color = `colorIndexSliderGrp -q -v $colorCtrl` - 1;

	if( catch(`setAttr $layerColorAttr $color`) )
	{
		int $oldColor = getCurrentColor( $layerColorAttr );
		colorIndexSliderGrp -e -v $oldColor $colorCtrl;
	}
}

global proc updateLayerColor (string $layerColorAttr, string $colorCtrl)
{
	// check to set the correct initial settings
	int $color = getCurrentColor( $layerColorAttr );
	colorIndexSliderGrp -e -v $color $colorCtrl;
}

//
//	drawInfoObjColorReplace
//
global proc drawInfoObjColorReplace (string $layerColorAttr)
{
	// There are more then one instance of this slider so to
	// be safe get its full name.
	string $colorCtrl = (`setParent -query` + "|objIndexColorSlider");
	
	colorIndexSliderGrp -e  
			-cc ("changeObjColor " + $layerColorAttr + " "+ $colorCtrl )
			objIndexColorSlider;

	updateLayerColor $layerColorAttr $colorCtrl;
	
	scriptJob -p objIndexColorSlider -rp 
		-attributeChange $layerColorAttr 
		("updateLayerColor " + $layerColorAttr + " " + $colorCtrl);

}

//
//	drawInfoObjColorNew
//
global proc drawInfoObjColorNew ( string $layerColorAttr )
{
	setUITemplate -pst attributeEditorTemplate;
	colorIndexSliderGrp  -l "Color" 
			-invisible 1
			-v 1			// Color index 1 is taken as the invisible one
			-min 1 -max 32	// Enable the entire (dormant) colour palette
			objIndexColorSlider;
	setUITemplate -ppt;

	drawInfoObjColorReplace  $layerColorAttr;
}


// On incoming connections from the layers to the objects turning off
// the "enabled" flag should gray out the other controls as they will be
// ignored from then on.  The outgoing connections can still modify the
// values although they will not have immediate effect.
//
global proc checkDrawEnabled(
	string	$enabledName,
	string	$displayTypeName,
	string	$levelOfDetailName,
	string	$shadingName,
	string	$texturingName,
	string	$playbackName,
	string	$visibleName,
	string  $colourName,
	string	$nodeName )
{
	string $nodeAttr = $nodeName + "." + $enabledName;
	int $value = 1 - `getAttr $nodeAttr`;

	// Disable everything for the default layer.  It has no effect
	// on its members anyway so no sense in misleading the user.
	//
	string $mgr[] = `ls -type displayLayerManager`;
	if( size($mgr) > 0 )
	{
		string $def[] = `listConnections ($mgr[0] + ".displayLayerId[0]")`;
		if( (size($def) > 0)
		&&  ($def[0] == $nodeName) )
		{
			$value = 1;
		}
	}

	editorTemplate -dimControl $nodeName $displayTypeName ($value);
	editorTemplate -dimControl $nodeName $levelOfDetailName ($value);
	editorTemplate -dimControl $nodeName $shadingName ($value);
	editorTemplate -dimControl $nodeName $texturingName ($value);
	editorTemplate -dimControl $nodeName $playbackName ($value);
	editorTemplate -dimControl $nodeName $visibleName ($value);

	if (`colorIndexSliderGrp -exists objIndexColorSlider`) {
		// replaced slider control with dimControls
		editorTemplate -dimControl $nodeName $colourName ($value);	
	}
}

//	AEdrawInfo
//
global proc AEdrawInfo (
	string $displayTypeName
,	string $levelOfDetailName
,	string $shadingName
,	string $texturingName
,	string $playbackName
,	string $enabledName
,	string $visibleName
,	string $colourName
)
{
	editorTemplate -beginNoOptimize;

	// Make a callback for the incoming end of the enabled flag so that
	// disabling it shuts off the ability to change the other (ignored)
	// values.
	//
	editorTemplate -label "Enable Overrides" -addControl $enabledName
					("checkDrawEnabled "   + $enabledName + " " +
					$displayTypeName + " " + $levelOfDetailName + " " +
					$shadingName	 + " " + $texturingName + " " +
					$playbackName	 + " " + $visibleName + " " +
					 $colourName);

	editorTemplate -label "Display Type" -addControl $displayTypeName;
	editorTemplate -label "Level of Detail" -addControl $levelOfDetailName;
	editorTemplate -label "Shading" -addControl $shadingName;
	editorTemplate -label "Texturing" -addControl $texturingName;
	editorTemplate -label "Playback" -addControl $playbackName;
	editorTemplate -label "Visible" -addControl $visibleName;
	editorTemplate -endNoOptimize;
	editorTemplate -callCustom "drawInfoObjColorNew" "drawInfoObjColorReplace"
				$colourName;
}
