// =========================================================================== // 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. // =========================================================================== // // // Creation Date: 18 April 1997 // // Description: // spotLight default options box. The content for each tab // is not created until it is accessed for the first time. // ////////////////////////////////////////////////////////////////////// // // Procedure Name: // setOptionVars // // Description: // Initialize the option values. // // Input Arguments: // Whether to set the options to default values. // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { // Intensity. // if ($forceFactorySettings || !`optionVar -exists spotLightIntensity`) { optionVar -floatValue spotLightIntensity 1; } // Color. // if ($forceFactorySettings || !`optionVar -exists spotLightColor`) { optionVar -floatValue spotLightColor 1 -floatValueAppend spotLightColor 1 -floatValueAppend spotLightColor 1; } // Decay Rate. // if ($forceFactorySettings || !`optionVar -exists spotLightDecay`) { optionVar -intValue spotLightDecay 0; } // ConeAngle. // if ($forceFactorySettings || !`optionVar -exists spotLightConeAngle`) { optionVar -floatValue spotLightConeAngle 40.0; } // Dropoff. // if ($forceFactorySettings || !`optionVar -exists spotLightDropoff`) { optionVar -floatValue spotLightDropoff 0; } // Penumbra Angle. // if ($forceFactorySettings || !`optionVar -exists spotLightPenumbra`) { optionVar -floatValue spotLightPenumbra 0; } // Shadows. // if ($forceFactorySettings || !`optionVar -exists spotLightShadows`) { optionVar -intValue spotLightShadows false; } // Shadow Color. // if ($forceFactorySettings || !`optionVar -exists spotLightShadowColor`) { optionVar -floatValue spotLightShadowColor 0 -floatValueAppend spotLightShadowColor 0 -floatValueAppend spotLightShadowColor 0; } // Interactive Placement. // if ($forceFactorySettings || !`optionVar -exists spotLightInteractivePlacement`) { optionVar -intValue spotLightInteractivePlacement 0; } } // // Procedure Name: // spotLightSetup // // Description: // Update the state of the option box UI to reflect the option values. // // Input Arguments: // parent - Top level parent layout of the option box UI. // Required so that UI object names can be // successfully resolved. // // forceFactorySettings - Whether the option values should be set to // default values. // // Return Value: // None. // global proc spotLightSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; float $rgb[3]; // Query the optionVar's and set the values into the controls. // Intensity. // if (`floatSliderGrp -exists spotLightIntensity`) { floatSliderGrp -edit -value `optionVar -query spotLightIntensity` spotLightIntensity; } // Color. // if (`colorSliderGrp -exists spotLightColor`) { $rgb = `optionVar -query spotLightColor`; colorSliderGrp -edit -rgb $rgb[0] $rgb[1] $rgb[2] spotLightColor; } // Decay Rate. // if (`optionMenuGrp -exists spotLightDecay`) { optionMenuGrp -edit -sl (1+`optionVar -query spotLightDecay`) spotLightDecay; } // ConeAngle. // if (`floatSliderGrp -exists spotLightConeAngle`) { floatSliderGrp -edit -value `optionVar -query spotLightConeAngle` spotLightConeAngle; } // Dropoff. // if (`floatSliderGrp -exists spotLightDropoff`) { floatSliderGrp -edit -value `optionVar -query spotLightDropoff` spotLightDropoff; } // Penumbra Angle. // if (`floatSliderGrp -exists spotLightPenumbra`) { floatSliderGrp -edit -value `optionVar -query spotLightPenumbra` spotLightPenumbra; } // Shadows. // if (`checkBoxGrp -exists spotLightShadows`) { checkBoxGrp -edit -value1 `optionVar -query spotLightShadows` spotLightShadows; } // Shadow Color. // if (`colorSliderGrp -exists spotLightShadowColor`) { $rgb = `optionVar -query spotLightShadowColor`; colorSliderGrp -edit -rgb $rgb[0] $rgb[1] $rgb[2] spotLightShadowColor; } // Interactive Placement. // if (`checkBoxGrp -exists spotLightInteractivePlacement`) { checkBoxGrp -edit -value1 `optionVar -query spotLightInteractivePlacement` spotLightInteractivePlacement; } } // // Procedure Name: // spotLightCallback // // Description: // Update the option values with the current state of the option box UI. // // Input Arguments: // parent - Top level parent layout of the option box UI. Required so // that UI object names can be successfully resolved. // // doIt - Whether the command should execute. // // Return Value: // None. // global proc spotLightCallback(string $parent, int $doIt) { setParent $parent; float $rgb[3]; // Set the optionVar's from the control values, and then // perform the command. // Intensity. // if (`floatSliderGrp -exists spotLightIntensity`) { optionVar -floatValue spotLightIntensity `floatSliderGrp -query -value spotLightIntensity`; } // Color. // if (`colorSliderGrp -exists spotLightColor`) { $rgb = `colorSliderGrp -query -rgb spotLightColor`; optionVar -floatValue spotLightColor $rgb[0]; optionVar -floatValueAppend spotLightColor $rgb[1]; optionVar -floatValueAppend spotLightColor $rgb[2]; } // Decay Rate. // if (`optionMenuGrp -exists spotLightDecay`) { optionVar -intValue spotLightDecay (`optionMenuGrp -query -sl spotLightDecay`-1); } // ConeAngle. // if (`floatSliderGrp -exists spotLightConeAngle`) { optionVar -floatValue spotLightConeAngle `floatSliderGrp -query -value spotLightConeAngle`; } // Dropoff. // if (`floatSliderGrp -exists spotLightDropoff`) { optionVar -floatValue spotLightDropoff `floatSliderGrp -query -value spotLightDropoff`; } // Penumbra Angle. // if (`floatSliderGrp -exists spotLightPenumbra`) { optionVar -floatValue spotLightPenumbra `floatSliderGrp -query -value spotLightPenumbra`; } // Shadow. // if (`checkBoxGrp -exists spotLightShadows`) { optionVar -intValue spotLightShadows `checkBoxGrp -query -value1 spotLightShadows`; } // Shadow Color. // if (`colorSliderGrp -exists spotLightShadowColor`) { $rgb = `colorSliderGrp -query -rgb spotLightShadowColor`; optionVar -floatValue spotLightShadowColor $rgb[0]; optionVar -floatValueAppend spotLightShadowColor $rgb[1]; optionVar -floatValueAppend spotLightShadowColor $rgb[2]; } // Interactive Placement. // if (`checkBoxGrp -exists spotLightInteractivePlacement`) { optionVar -intValue spotLightInteractivePlacement `checkBoxGrp -query -value1 spotLightInteractivePlacement`; } if ($doIt) { performSpotLight 0; addToRecentCommandQueue "performSpotLight 0" "SpotLight"; } } // // Procedure Name: // createSpotLightTabUI // // Description: // Create the tab UI. The contents of each tab are created only // when it is required, ie. if the tab is initially visible or // if the tab is selected by the user. // // Input Arguments: // The name of the tab layout. // // Return Value: // None. // global proc createSpotLightTabUI(string $tabLayout) { string $tab[] = `tabLayout -query -childArray $tabLayout`; int $currentTabIndex = `tabLayout -query -selectTabIndex $tabLayout`; // Determine if the UI for this tab has been created yet. // This is accomplished by querying the number of children // in the current tab. If the tab has no children then the UI // must be created. // if (0 == `columnLayout -query -numberOfChildren $tab[$currentTabIndex-1]`) { setParent $tab[$currentTabIndex-1]; string $label; int $index; // Activate the default UI template so that the layout of this // option box is consistent with the layout of the rest of the // application. // setUITemplate -pushTemplate DefaultTemplate; // Turn on the wait cursor. // waitCursor -state 1; // The current tab has no children. Determine which tab is // active and create its UI. // // RECOMMENDATION: Use the 'Grp' commands where possible because // they obey the formatting specified in the default template. // This will result in a more consistent look throughout the // application. // if (1 == $currentTabIndex) { // Create UI for the first tab. // floatSliderGrp -label (uiRes("m_performSpotLight.kIntensity")) -fieldMaxValue 100 spotLightIntensity; colorSliderGrp -label (uiRes("m_performSpotLight.kColor")) spotLightColor; separator; // Create UI for the second tab. // floatSliderGrp -label (uiRes("m_performSpotLight.kConeAngle")) -min 0.5 -max 179.5 spotLightConeAngle; floatSliderGrp -label (uiRes("m_performSpotLight.kPenumbraAngle")) -min -179.5 -max 179.5 spotLightPenumbra; floatSliderGrp -label (uiRes("m_performSpotLight.kDropoff")) spotLightDropoff; optionMenuGrp -label (uiRes("m_performSpotLight.kDecayRate")) spotLightDecay; menuItem -label (uiRes("m_performSpotLight.kNone")) ; menuItem -label (uiRes("m_performSpotLight.kLinear")) ; menuItem -label (uiRes("m_performSpotLight.kQuadratic")) ; menuItem -label (uiRes("m_performSpotLight.kCubic")) ; setParent -menu ..; separator; // Create UI for the third tab. // checkBoxGrp -ncb 1 -label1 (uiRes("m_performSpotLight.kCastShadows")) spotLightShadows; colorSliderGrp -label (uiRes("m_performSpotLight.kShadowColor")) spotLightShadowColor; separator; // Create UI for the fourth tab. // checkBoxGrp -ncb 1 -label1 (uiRes("m_performSpotLight.kInteractivePlacement")) spotLightInteractivePlacement; setParent ..; } // Update the control values to match the options. // eval (("spotLightSetup " + $tabLayout + " " + 0)); // Turn off the wait cursor. // waitCursor -state 0; // Deactivate the default UI template. // setUITemplate -popTemplate; } } // // Procedure Name: // spotLightOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // // ********* Change 'spotLight' in this proc to be the name of your command proc spotLightOptions() { // Name of the command for this option box. // string $commandName = "spotLight"; // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // STEP 1: Get the option box. // ============================ // // The value returned is the name of the layout to be used as // the parent for the option box UI. // string $layout = getOptionBox(); setParent $layout; // STEP 2: Pass the command name to the option box. // ================================================= // // Any default option box behaviour based on the command name is set // up with this call. For example, updating the 'Help' menu item with // the name of the command. // setOptionBoxCommandName($commandName); // STEP 3: Activate the default UI template. // ========================================== // // Activate the default UI template so that the layout of this // option box is consistent with the layout of the rest of the // application. // // Note: this option box example delays the creation of the UI // until it is required. Therefore this step is moved to the // procedure where the UI is actually created. // //setUITemplate -pushTemplate DefaultTemplate; // STEP 4: Create option box contents. // =================================== // // This, of course, will vary from option box to option box. // Demonstrate the delaying of UI creation via tab layouts. // Instead of creating all of the option box UI initially, only // create that which is initially visible. Wait, until the // other tabs are selected to create the remaining UI. // string $tabLayout = `tabLayout -scrollable 1`; // Attach an action that will be invoked before a tab is selected. // tabLayout -edit -tabsVisible false -preSelectCommand ("createSpotLightTabUI " + $tabLayout) $tabLayout; // Create just the immediate children of the tab layout so that // the tabs appear. // columnLayout -adj true; setParent ..; // Set the tab labels. // tabLayout -edit $tabLayout; // Create the UI for the tab that is initially visible. // createSpotLightTabUI($tabLayout); // Step 5: Deactivate the default UI template. // =========================================== // // Note: this option box example delays the creation of the UI // until it is required. Therefore this step is moved to the // procedure where the UI is actually created. // // See also Step 2. // //setUITemplate -popTemplate; // Step 6: Customize the buttons. // ============================== // // Provide more descriptive labels for the buttons. This is not // necessary, but in some cases, for example, a button labelled // 'Create' may be more meaningful to the user than one labelled // 'Apply'. // // Disable those buttons that are not applicable to the option box. // // Attach actions to those buttons that are applicable to the option // box. Note that the 'Close' button has a default action attached // to it that will hide the window. If a a custom action is // attached to the 'Close' button then be sure to call the 'hide the // option box' procedure within the custom action so that the option // box is hidden properly. // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performSpotLight.kCreate")) -command ($callback + " " + $tabLayout + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $tabLayout + " " + 0 + "; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $tabLayout + " " + 1) $resetBtn; // Step 7: Set the option box title. // ================================= // setOptionBoxTitle (uiRes("m_performSpotLight.kCreateSpotLightOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "SpotLight" ); // Step 9: Set the current values of the option box. // ================================================= // // NOTE: Cannot do this here since we do not know what UI is // currently visible. This is moved to where the UI is created. // //eval (($setup + " " + $tabLayout + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); } // // Procedure Name: // optionBoxExample1Help // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string spotLightHelp() { return " Command: spotLight - creates a spotLight\n" + "Selection: None."; } proc string getCmd() { string $cmd = "defaultSpotLight("; $cmd = $cmd + `optionVar -query spotLightIntensity`; float $rgb[3] = `optionVar -query spotLightColor`; $cmd = $cmd + ", " + $rgb[0] + "," + $rgb[1] + "," + $rgb[2]; $cmd = $cmd + ", " + `optionVar -query spotLightDecay`; $cmd = $cmd + ", " + `optionVar -query spotLightConeAngle`; $cmd = $cmd + ", " + `optionVar -query spotLightDropoff`; $cmd = $cmd + ", " + `optionVar -query spotLightPenumbra`; $cmd = $cmd + ", " + `optionVar -query spotLightShadows`; $rgb = `optionVar -query spotLightShadowColor`; $cmd = $cmd + ", " + $rgb[0] + "," + $rgb[1] + "," + $rgb[2]; $cmd = $cmd + ", 1"; $cmd = $cmd + ", " + `optionVar -query spotLightInteractivePlacement`; $cmd = $cmd + ");"; return $cmd; } // // Procedure Name: // performSpotLight // // Description: // Perform the spotLight command using the corresponding // option values. This procedure will also show the option box // window if necessary as well as construct the command string // that will invoke the spotLight command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // // Return Value: // None. // global proc string performSpotLight(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Retrieve the option settings // setOptionVars(false); // Get the command. // $cmd = getCmd(); // Execute the command with the option settings. // evalEcho($cmd); break; // Show the option box. // case 1: spotLightOptions; break; // Return the command string. // case 2: // Retrieve the option settings. // setOptionVars (false); // Get the command. // $cmd = getCmd(); break; } return $cmd; }