home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / DirectX / dxsdk_oct2004.exe / dxsdk.exe / Samples / Managed / DirectInput / Feedback / frmMain.cs < prev    next >
Encoding:
Text File  |  2004-09-27  |  89.8 KB  |  1,825 lines

  1. //-----------------------------------------------------------------------------
  2. // File: frmMain.cs
  3. //
  4. // Desc: The Feedback sample shows Force Feedback via devices that support it.
  5. //
  6. // Copyright (c) Microsoft Corporation. All rights reserved
  7. //-----------------------------------------------------------------------------
  8. using System;
  9. using System.Drawing;
  10. using System.Collections;
  11. using System.ComponentModel;
  12. using System.Windows.Forms;
  13. using Microsoft.DirectX;
  14. using Microsoft.DirectX.DirectInput;
  15.  
  16. namespace Feedback
  17. {
  18.     public class frmMain : System.Windows.Forms.Form
  19.     {
  20.         /// <summary>
  21.         /// This structure will contain information about an effect,
  22.         /// its Effect structure, and the DirectInputEffect object.
  23.         /// </summary>
  24.         private struct EffectDescription
  25.         {           
  26.             public EffectInformation info;
  27.             public EffectObject effectSelected;
  28.             public override string ToString() 
  29.             {
  30.                 return info.Name;
  31.             }
  32.         }
  33.         
  34.         private Device applicationDevice; //DirectInput device object.
  35.         private EffectObject effectSelected; //The currently selected effect.
  36.         private int[] axis; //Holds the FF axes offsets.
  37.         private bool isChanging; // Flag that is set when that app is changing control values.
  38.  
  39.         #region Window control declarations
  40.         internal System.Windows.Forms.Label Label1;
  41.         internal System.Windows.Forms.GroupBox gbGeneralParams;
  42.         internal System.Windows.Forms.TrackBar GeneralPeriod;
  43.         internal System.Windows.Forms.Label GeneralPeriodLabel;
  44.         internal System.Windows.Forms.TrackBar GeneralGain;
  45.         internal System.Windows.Forms.Label GeneralGainLabel;
  46.         internal System.Windows.Forms.TrackBar GeneralDuration;
  47.         internal System.Windows.Forms.Label GeneralDurationLabel;
  48.         internal System.Windows.Forms.ListBox lstEffects;
  49.         internal System.Windows.Forms.GroupBox gbTypeContainer;
  50.         internal System.Windows.Forms.GroupBox GroupPeriodForce;
  51.         internal System.Windows.Forms.Label PeriodicPeriodLabel;
  52.         internal System.Windows.Forms.TrackBar PeriodicPeriod;
  53.         internal System.Windows.Forms.Label PeriodicPhaseLabel;
  54.         internal System.Windows.Forms.TrackBar PeriodicPhase;
  55.         internal System.Windows.Forms.Label PeriodicOffsetLabel;
  56.         internal System.Windows.Forms.TrackBar PeriodicOffset;
  57.         internal System.Windows.Forms.Label PeriodicMagnitudeLabel;
  58.         internal System.Windows.Forms.TrackBar PeriodicMagnitude;
  59.         internal System.Windows.Forms.GroupBox GroupConstantForce;
  60.         internal System.Windows.Forms.Label Magnitude;
  61.         internal System.Windows.Forms.TrackBar ConstantForceMagnitude;
  62.         internal System.Windows.Forms.GroupBox GroupConditionalForce;
  63.         internal System.Windows.Forms.RadioButton rbConditionalAxis2;
  64.         internal System.Windows.Forms.RadioButton ConditionalAxis1;
  65.         internal System.Windows.Forms.Label ConditionalPositiveSaturationLabel;
  66.         internal System.Windows.Forms.TrackBar ConditionalPositiveSaturation;
  67.         internal System.Windows.Forms.Label ConditionalNegativeSaturationLabel;
  68.         internal System.Windows.Forms.TrackBar ConditionalNegativeSaturation;
  69.         internal System.Windows.Forms.Label ConditionalPositiveCoefficientLabel;
  70.         internal System.Windows.Forms.TrackBar ConditionalPositiveCoefficient;
  71.         internal System.Windows.Forms.Label ConditionalNegativeCoeffcientLabel;
  72.         internal System.Windows.Forms.TrackBar ConditionalNegativeCoeffcient;
  73.         internal System.Windows.Forms.Label ConditionalOffsetLabel;
  74.         internal System.Windows.Forms.TrackBar ConditionalOffset;
  75.         internal System.Windows.Forms.Label ConditionalDeadBandLabel;
  76.         internal System.Windows.Forms.TrackBar ConditionalDeadBand;
  77.         internal System.Windows.Forms.GroupBox GroupRampForce;
  78.         internal System.Windows.Forms.Label RangeEndLabel;
  79.         internal System.Windows.Forms.TrackBar RangeEnd;
  80.         internal System.Windows.Forms.Label RangeStartLabel;
  81.         internal System.Windows.Forms.TrackBar RangeStart;
  82.         internal System.Windows.Forms.GroupBox EnvelopeGroupBox;
  83.         internal System.Windows.Forms.TrackBar EnvelopeFadeTime;
  84.         internal System.Windows.Forms.Label EnvelopeFadeTimeLabel;
  85.         internal System.Windows.Forms.TrackBar EnvelopeFadeLevel;
  86.         internal System.Windows.Forms.Label EnvelopeFadeLevelLabel;
  87.         internal System.Windows.Forms.TrackBar EnvelopeAttackTime;
  88.         internal System.Windows.Forms.Label EnvelopeAttackTimeLabel;
  89.         internal System.Windows.Forms.TrackBar EnvelopeAttackLevel;
  90.         internal System.Windows.Forms.Label EnvelopeAttackLevelLabel;
  91.         internal System.Windows.Forms.CheckBox chkUseEnvelope;
  92.         internal System.Windows.Forms.GroupBox DirectionGroupBox;
  93.         internal System.Windows.Forms.RadioButton NorthEast;
  94.         internal System.Windows.Forms.RadioButton East;
  95.         internal System.Windows.Forms.RadioButton SouthEast;
  96.         internal System.Windows.Forms.RadioButton South;
  97.         internal System.Windows.Forms.RadioButton SouthWest;
  98.         internal System.Windows.Forms.RadioButton West;
  99.         internal System.Windows.Forms.RadioButton NorthWest;
  100.         internal System.Windows.Forms.RadioButton North;
  101.         #endregion
  102.         private System.ComponentModel.Container components = null;
  103.  
  104.  
  105.         
  106.         
  107.         public frmMain()
  108.         {
  109.             try
  110.             {
  111.                 // Load the icon from our resources
  112.                 System.Resources.ResourceManager resources = new System.Resources.ResourceManager(this.GetType());
  113.                 this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  114.             }
  115.             catch
  116.             {
  117.                 // It's no big deal if we can't load our icons, but try to load the embedded one
  118.                 try { this.Icon = new System.Drawing.Icon(this.GetType(), "directx.ico"); } 
  119.                 catch {}
  120.             }
  121.             //
  122.             // Required for Windows Form Designer support
  123.             //
  124.             InitializeComponent();            
  125.         }
  126.  
  127.         
  128.         
  129.         
  130.         /// <summary>
  131.         /// Initializes DirectInput.
  132.         /// </summary>
  133.         private bool InitializeDirectInput()
  134.         {
  135.             try
  136.             {
  137.                 //Enumerate all joysticks that are attached to the system and have FF capabilities
  138.                 foreach (DeviceInstance instanceDevice in Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.ForceFeeback | EnumDevicesFlags.AttachedOnly))
  139.                 {
  140.                     applicationDevice = new Device(instanceDevice.InstanceGuid);
  141.                     foreach (DeviceObjectInstance instanceObject in applicationDevice.GetObjects(DeviceObjectTypeFlags.Axis))  // Get info about all the FF axis on the device
  142.                     {
  143.                         int[] temp;
  144.  
  145.                         if ((instanceObject.Flags & (int)ObjectInstanceFlags.Actuator) != 0)
  146.                         {
  147.                             if (null != axis)
  148.                             {
  149.                                 temp = new int[axis.Length + 1];                   
  150.                                 axis.CopyTo(temp,0);
  151.                                 axis = temp;
  152.                             }
  153.                             else
  154.                             {
  155.                                 axis = new int[1];
  156.                             }
  157.                             // Store the offset of each axis.
  158.                             axis[axis.Length - 1] = instanceObject.Offset;
  159.                             // Don't need to enumerate any more if 2 were found.
  160.                             if (2 == axis.Length)
  161.                                 break;
  162.                         }
  163.                     }
  164.  
  165.                     if (null == applicationDevice)
  166.                     {
  167.                         MessageBox.Show("No force feedback devices found attached to the system. Sample will now exit.", "No suitable device", 
  168.                             MessageBoxButtons.OK, MessageBoxIcon.Error);
  169.                         return false;
  170.                     }
  171.  
  172.                     if (axis.Length - 1 >= 1)
  173.                         // Grab any device that contains at least one axis.
  174.                         break;
  175.                     else
  176.                     {
  177.                         axis = null;
  178.                         applicationDevice.Dispose();
  179.                         applicationDevice = null;
  180.                     }
  181.                 }
  182.  
  183.                 //Turn off autocenter
  184.                 applicationDevice.Properties.AutoCenter = false;
  185.  
  186.                 //Set the format of the device to that of a joystick
  187.                 applicationDevice.SetDataFormat(DeviceDataFormat.Joystick);
  188.  
  189.                 //Enumerate all the effects on the device
  190.                 foreach (EffectInformation ei in applicationDevice.GetEffects(EffectType.All))
  191.                 {
  192.                     // Handles the enumeration of effects.
  193.  
  194.                     EffectObject effectSelected; 
  195.                     EffectDescription description = new EffectDescription(); 
  196.                     Effect eff;
  197.  
  198.                     if (DInputHelper.GetTypeCode(ei.EffectType) == (int)EffectType.CustomForce)
  199.                     {
  200.                         // Can't create a custom force without info from the hardware vendor, so skip this effect.
  201.                         continue;
  202.                     }
  203.                     else if (DInputHelper.GetTypeCode(ei.EffectType) == (int)EffectType.Periodic)
  204.                     {
  205.                         // This is to filter out any Periodic effects. There are known
  206.                         // issues with Periodic effects that will be addressed post-developer preview.
  207.                         continue;
  208.                     }
  209.                     else if (DInputHelper.GetTypeCode(ei.EffectType) == (int)EffectType.Hardware)
  210.                     {
  211.                         if ((ei.StaticParams & (int)EffectParameterFlags.TypeSpecificParams) != 0)
  212.                             // Can't create a hardware force without info from the hardware vendor.
  213.                             continue;
  214.                     }
  215.  
  216.                     // Fill in some generic values for the effect.
  217.                     eff = FillEffStruct((EffectType)ei.EffectType);
  218.  
  219.                     // Create the effect, using the passed in guid.
  220.                     effectSelected = new EffectObject(ei.EffectGuid, eff, applicationDevice);
  221.  
  222.                     // Fill in the EffectDescription structure.
  223.                     description.effectSelected = effectSelected;
  224.                     description.info = ei;
  225.  
  226.                     // Add this effect to the listbox, displaying the name of the effect.
  227.                     lstEffects.Items.Add(description);
  228.                 }
  229.  
  230.                 if (0 == lstEffects.Items.Count)
  231.                 {
  232.                     // If this device has no downloadable effects, end the app.
  233.                     MessageBox.Show("This device does not contain any downloadable effects, app will exit.");
  234.                     // The app will validate all DirectInput objects in the frmMain_Load() event.
  235.                     // When one is found missing, this will cause the app to exit.
  236.                 }
  237.  
  238.                 // Set the cooperative level of the device as an exclusive
  239.                 // foreground device, and attach it to the form's window handle.
  240.                 applicationDevice.SetCooperativeLevel(this, CooperativeLevelFlags.Foreground | CooperativeLevelFlags.Exclusive);
  241.  
  242.                 // Make the first index of the listbox selected
  243.                 lstEffects.SelectedIndex = 0;
  244.                 return true;
  245.             }
  246.             catch
  247.             {
  248.                 MessageBox.Show("No force feedback devices found attached to the system. Sample will now exit.", "No suitable device", 
  249.                     MessageBoxButtons.OK, MessageBoxIcon.Error);
  250.                 return false;
  251.             }
  252.         }
  253.         
  254.         
  255.         
  256.         
  257.         /// <summary>
  258.         /// Fills in generic values in an effect struct.
  259.         /// </summary>
  260.         private Effect FillEffStruct(EffectType eif)
  261.         {
  262.             Effect eff = new Effect();
  263.  
  264.             // Allocate some memory for directions and axis.
  265.             eff.SetDirection(new int[axis.Length]);
  266.             eff.SetAxes(new int[axis.Length]);
  267.  
  268.             eff.EffectType = eif;           
  269.             eff.ConditionStruct =  new Condition[axis.Length];
  270.             eff.Duration = (int)DI.Infinite;
  271.             eff.Gain = 10000;
  272.             eff.SamplePeriod = 0;
  273.             eff.TriggerButton = (int)Microsoft.DirectX.DirectInput.Button.NoTrigger;
  274.             eff.TriggerRepeatInterval = (int)DI.Infinite;
  275.             eff.Flags = EffectFlags.ObjectOffsets | EffectFlags.Cartesian;
  276.             eff.SetAxes(axis);
  277.  
  278.             return eff;
  279.         }
  280.         
  281.         
  282.         
  283.         
  284.         /// <summary>
  285.         /// Clean up any resources being used.
  286.         /// </summary>
  287.         protected override void Dispose(bool disposing)
  288.         {
  289.             if (disposing)
  290.             {
  291.                 if (components != null) 
  292.                 {
  293.                     components.Dispose();
  294.                 }
  295.             }
  296.             base.Dispose(disposing);
  297.         }
  298.  
  299.         
  300.         
  301.         
  302.         #region Windows Form Designer generated code
  303.         /// <summary>
  304.         /// Required method for Designer support - do not modify
  305.         /// the contents of this method with the code editor.
  306.         /// </summary>
  307.         private void InitializeComponent()
  308.         {
  309.             this.Label1 = new System.Windows.Forms.Label();
  310.             this.gbGeneralParams = new System.Windows.Forms.GroupBox();
  311.             this.GeneralPeriod = new System.Windows.Forms.TrackBar();
  312.             this.GeneralPeriodLabel = new System.Windows.Forms.Label();
  313.             this.GeneralGain = new System.Windows.Forms.TrackBar();
  314.             this.GeneralGainLabel = new System.Windows.Forms.Label();
  315.             this.GeneralDuration = new System.Windows.Forms.TrackBar();
  316.             this.GeneralDurationLabel = new System.Windows.Forms.Label();
  317.             this.lstEffects = new System.Windows.Forms.ListBox();
  318.             this.gbTypeContainer = new System.Windows.Forms.GroupBox();
  319.             this.GroupConditionalForce = new System.Windows.Forms.GroupBox();
  320.             this.rbConditionalAxis2 = new System.Windows.Forms.RadioButton();
  321.             this.ConditionalAxis1 = new System.Windows.Forms.RadioButton();
  322.             this.ConditionalPositiveSaturationLabel = new System.Windows.Forms.Label();
  323.             this.ConditionalPositiveSaturation = new System.Windows.Forms.TrackBar();
  324.             this.ConditionalNegativeSaturationLabel = new System.Windows.Forms.Label();
  325.             this.ConditionalNegativeSaturation = new System.Windows.Forms.TrackBar();
  326.             this.ConditionalPositiveCoefficientLabel = new System.Windows.Forms.Label();
  327.             this.ConditionalPositiveCoefficient = new System.Windows.Forms.TrackBar();
  328.             this.ConditionalNegativeCoeffcientLabel = new System.Windows.Forms.Label();
  329.             this.ConditionalNegativeCoeffcient = new System.Windows.Forms.TrackBar();
  330.             this.ConditionalOffsetLabel = new System.Windows.Forms.Label();
  331.             this.ConditionalOffset = new System.Windows.Forms.TrackBar();
  332.             this.ConditionalDeadBandLabel = new System.Windows.Forms.Label();
  333.             this.ConditionalDeadBand = new System.Windows.Forms.TrackBar();
  334.             this.GroupPeriodForce = new System.Windows.Forms.GroupBox();
  335.             this.PeriodicPeriodLabel = new System.Windows.Forms.Label();
  336.             this.PeriodicPeriod = new System.Windows.Forms.TrackBar();
  337.             this.PeriodicPhaseLabel = new System.Windows.Forms.Label();
  338.             this.PeriodicPhase = new System.Windows.Forms.TrackBar();
  339.             this.PeriodicOffsetLabel = new System.Windows.Forms.Label();
  340.             this.PeriodicOffset = new System.Windows.Forms.TrackBar();
  341.             this.PeriodicMagnitudeLabel = new System.Windows.Forms.Label();
  342.             this.PeriodicMagnitude = new System.Windows.Forms.TrackBar();
  343.             this.GroupRampForce = new System.Windows.Forms.GroupBox();
  344.             this.RangeEndLabel = new System.Windows.Forms.Label();
  345.             this.RangeEnd = new System.Windows.Forms.TrackBar();
  346.             this.RangeStartLabel = new System.Windows.Forms.Label();
  347.             this.RangeStart = new System.Windows.Forms.TrackBar();
  348.             this.GroupConstantForce = new System.Windows.Forms.GroupBox();
  349.             this.Magnitude = new System.Windows.Forms.Label();
  350.             this.ConstantForceMagnitude = new System.Windows.Forms.TrackBar();
  351.             this.EnvelopeGroupBox = new System.Windows.Forms.GroupBox();
  352.             this.EnvelopeFadeTime = new System.Windows.Forms.TrackBar();
  353.             this.EnvelopeFadeTimeLabel = new System.Windows.Forms.Label();
  354.             this.EnvelopeFadeLevel = new System.Windows.Forms.TrackBar();
  355.             this.EnvelopeFadeLevelLabel = new System.Windows.Forms.Label();
  356.             this.EnvelopeAttackTime = new System.Windows.Forms.TrackBar();
  357.             this.EnvelopeAttackTimeLabel = new System.Windows.Forms.Label();
  358.             this.EnvelopeAttackLevel = new System.Windows.Forms.TrackBar();
  359.             this.EnvelopeAttackLevelLabel = new System.Windows.Forms.Label();
  360.             this.chkUseEnvelope = new System.Windows.Forms.CheckBox();
  361.             this.DirectionGroupBox = new System.Windows.Forms.GroupBox();
  362.             this.NorthEast = new System.Windows.Forms.RadioButton();
  363.             this.East = new System.Windows.Forms.RadioButton();
  364.             this.SouthEast = new System.Windows.Forms.RadioButton();
  365.             this.South = new System.Windows.Forms.RadioButton();
  366.             this.SouthWest = new System.Windows.Forms.RadioButton();
  367.             this.West = new System.Windows.Forms.RadioButton();
  368.             this.NorthWest = new System.Windows.Forms.RadioButton();
  369.             this.North = new System.Windows.Forms.RadioButton();
  370.             this.gbGeneralParams.SuspendLayout();
  371.             ((System.ComponentModel.ISupportInitialize)(this.GeneralPeriod)).BeginInit();
  372.             ((System.ComponentModel.ISupportInitialize)(this.GeneralGain)).BeginInit();
  373.             ((System.ComponentModel.ISupportInitialize)(this.GeneralDuration)).BeginInit();
  374.             this.gbTypeContainer.SuspendLayout();
  375.             this.GroupConditionalForce.SuspendLayout();
  376.             ((System.ComponentModel.ISupportInitialize)(this.ConditionalPositiveSaturation)).BeginInit();
  377.             ((System.ComponentModel.ISupportInitialize)(this.ConditionalNegativeSaturation)).BeginInit();
  378.             ((System.ComponentModel.ISupportInitialize)(this.ConditionalPositiveCoefficient)).BeginInit();
  379.             ((System.ComponentModel.ISupportInitialize)(this.ConditionalNegativeCoeffcient)).BeginInit();
  380.             ((System.ComponentModel.ISupportInitialize)(this.ConditionalOffset)).BeginInit();
  381.             ((System.ComponentModel.ISupportInitialize)(this.ConditionalDeadBand)).BeginInit();
  382.             this.GroupPeriodForce.SuspendLayout();
  383.             ((System.ComponentModel.ISupportInitialize)(this.PeriodicPeriod)).BeginInit();
  384.             ((System.ComponentModel.ISupportInitialize)(this.PeriodicPhase)).BeginInit();
  385.             ((System.ComponentModel.ISupportInitialize)(this.PeriodicOffset)).BeginInit();
  386.             ((System.ComponentModel.ISupportInitialize)(this.PeriodicMagnitude)).BeginInit();
  387.             this.GroupRampForce.SuspendLayout();
  388.             ((System.ComponentModel.ISupportInitialize)(this.RangeEnd)).BeginInit();
  389.             ((System.ComponentModel.ISupportInitialize)(this.RangeStart)).BeginInit();
  390.             this.GroupConstantForce.SuspendLayout();
  391.             ((System.ComponentModel.ISupportInitialize)(this.ConstantForceMagnitude)).BeginInit();
  392.             this.EnvelopeGroupBox.SuspendLayout();
  393.             ((System.ComponentModel.ISupportInitialize)(this.EnvelopeFadeTime)).BeginInit();
  394.             ((System.ComponentModel.ISupportInitialize)(this.EnvelopeFadeLevel)).BeginInit();
  395.             ((System.ComponentModel.ISupportInitialize)(this.EnvelopeAttackTime)).BeginInit();
  396.             ((System.ComponentModel.ISupportInitialize)(this.EnvelopeAttackLevel)).BeginInit();
  397.             this.DirectionGroupBox.SuspendLayout();
  398.             this.SuspendLayout();
  399.             // 
  400.             // Label1
  401.             // 
  402.             this.Label1.AutoSize = true;
  403.             this.Label1.Location = new System.Drawing.Point(6, 6);
  404.             this.Label1.Name = "Label1";
  405.             this.Label1.Size = new System.Drawing.Size(91, 13);
  406.             this.Label1.TabIndex = 7;
  407.             this.Label1.Text = "Available Effects:";
  408.             // 
  409.             // gbGeneralParams
  410.             // 
  411.             this.gbGeneralParams.Controls.AddRange(new System.Windows.Forms.Control[] {
  412.                                                                                           this.GeneralPeriod,
  413.                                                                                           this.GeneralPeriodLabel,
  414.                                                                                           this.GeneralGain,
  415.                                                                                           this.GeneralGainLabel,
  416.                                                                                           this.GeneralDuration,
  417.                                                                                           this.GeneralDurationLabel});
  418.             this.gbGeneralParams.Location = new System.Drawing.Point(6, 262);
  419.             this.gbGeneralParams.Name = "gbGeneralParams";
  420.             this.gbGeneralParams.Size = new System.Drawing.Size(224, 216);
  421.             this.gbGeneralParams.TabIndex = 11;
  422.             this.gbGeneralParams.TabStop = false;
  423.             this.gbGeneralParams.Text = "General Parameters";
  424.             // 
  425.             // GeneralPeriod
  426.             // 
  427.             this.GeneralPeriod.AutoSize = false;
  428.             this.GeneralPeriod.Location = new System.Drawing.Point(8, 152);
  429.             this.GeneralPeriod.Maximum = 100000;
  430.             this.GeneralPeriod.Name = "GeneralPeriod";
  431.             this.GeneralPeriod.Size = new System.Drawing.Size(208, 45);
  432.             this.GeneralPeriod.TabIndex = 5;
  433.             this.GeneralPeriod.TickFrequency = 5000;
  434.             this.GeneralPeriod.Scroll += new System.EventHandler(this.GenScroll);
  435.             // 
  436.             // GeneralPeriodLabel
  437.             // 
  438.             this.GeneralPeriodLabel.Location = new System.Drawing.Point(16, 136);
  439.             this.GeneralPeriodLabel.Name = "GeneralPeriodLabel";
  440.             this.GeneralPeriodLabel.Size = new System.Drawing.Size(192, 16);
  441.             this.GeneralPeriodLabel.TabIndex = 4;
  442.             this.GeneralPeriodLabel.Text = "Sample Period: Default";
  443.             // 
  444.             // GeneralGain
  445.             // 
  446.             this.GeneralGain.AutoSize = false;
  447.             this.GeneralGain.Location = new System.Drawing.Point(8, 96);
  448.             this.GeneralGain.Maximum = 10000;
  449.             this.GeneralGain.Name = "GeneralGain";
  450.             this.GeneralGain.Size = new System.Drawing.Size(208, 45);
  451.             this.GeneralGain.TabIndex = 3;
  452.             this.GeneralGain.TickFrequency = 1000;
  453.             this.GeneralGain.Value = 10000;
  454.             this.GeneralGain.Scroll += new System.EventHandler(this.GenScroll);
  455.             // 
  456.             // GeneralGainLabel
  457.             // 
  458.             this.GeneralGainLabel.Location = new System.Drawing.Point(16, 84);
  459.             this.GeneralGainLabel.Name = "GeneralGainLabel";
  460.             this.GeneralGainLabel.Size = new System.Drawing.Size(192, 16);
  461.             this.GeneralGainLabel.TabIndex = 2;
  462.             this.GeneralGainLabel.Text = "Effect Gain: 10000";
  463.             // 
  464.             // GeneralDuration
  465.             // 
  466.             this.GeneralDuration.AutoSize = false;
  467.             this.GeneralDuration.LargeChange = 2;
  468.             this.GeneralDuration.Location = new System.Drawing.Point(8, 48);
  469.             this.GeneralDuration.Minimum = 1;
  470.             this.GeneralDuration.Name = "GeneralDuration";
  471.             this.GeneralDuration.Size = new System.Drawing.Size(208, 45);
  472.             this.GeneralDuration.TabIndex = 1;
  473.             this.GeneralDuration.Value = 10;
  474.             this.GeneralDuration.Scroll += new System.EventHandler(this.GenScroll);
  475.             // 
  476.             // GeneralDurationLabel
  477.             // 
  478.             this.GeneralDurationLabel.Location = new System.Drawing.Point(16, 32);
  479.             this.GeneralDurationLabel.Name = "GeneralDurationLabel";
  480.             this.GeneralDurationLabel.Size = new System.Drawing.Size(192, 16);
  481.             this.GeneralDurationLabel.TabIndex = 0;
  482.             this.GeneralDurationLabel.Text = "Effect Duration: Infinite";
  483.             // 
  484.             // lstEffects
  485.             // 
  486.             this.lstEffects.Location = new System.Drawing.Point(6, 22);
  487.             this.lstEffects.Name = "lstEffects";
  488.             this.lstEffects.Size = new System.Drawing.Size(225, 225);
  489.             this.lstEffects.TabIndex = 6;
  490.             this.lstEffects.SelectedIndexChanged += new System.EventHandler(this.lstEffects_SelectedIndexChanged);
  491.             // 
  492.             // gbTypeContainer
  493.             // 
  494.             this.gbTypeContainer.Controls.AddRange(new System.Windows.Forms.Control[] {
  495.                                                                                           this.GroupConditionalForce,
  496.                                                                                           this.GroupPeriodForce,
  497.                                                                                           this.GroupRampForce,
  498.                                                                                           this.GroupConstantForce});
  499.             this.gbTypeContainer.Location = new System.Drawing.Point(246, 14);
  500.             this.gbTypeContainer.Name = "gbTypeContainer";
  501.             this.gbTypeContainer.Size = new System.Drawing.Size(361, 233);
  502.             this.gbTypeContainer.TabIndex = 8;
  503.             this.gbTypeContainer.TabStop = false;
  504.             this.gbTypeContainer.Text = "Type-Specific Parameters";
  505.             // 
  506.             // GroupConditionalForce
  507.             // 
  508.             this.GroupConditionalForce.Controls.AddRange(new System.Windows.Forms.Control[] {
  509.                                                                                                 this.rbConditionalAxis2,
  510.                                                                                                 this.ConditionalAxis1,
  511.                                                                                                 this.ConditionalPositiveSaturationLabel,
  512.                                                                                                 this.ConditionalPositiveSaturation,
  513.                                                                                                 this.ConditionalNegativeSaturationLabel,
  514.                                                                                                 this.ConditionalNegativeSaturation,
  515.                                                                                                 this.ConditionalPositiveCoefficientLabel,
  516.                                                                                                 this.ConditionalPositiveCoefficient,
  517.                                                                                                 this.ConditionalNegativeCoeffcientLabel,
  518.                                                                                                 this.ConditionalNegativeCoeffcient,
  519.                                                                                                 this.ConditionalOffsetLabel,
  520.                                                                                                 this.ConditionalOffset,
  521.                                                                                                 this.ConditionalDeadBandLabel,
  522.                                                                                                 this.ConditionalDeadBand});
  523.             this.GroupConditionalForce.Location = new System.Drawing.Point(8, 16);
  524.             this.GroupConditionalForce.Name = "GroupConditionalForce";
  525.             this.GroupConditionalForce.Size = new System.Drawing.Size(344, 200);
  526.             this.GroupConditionalForce.TabIndex = 3;
  527.             this.GroupConditionalForce.TabStop = false;
  528.             this.GroupConditionalForce.Tag = "";
  529.             this.GroupConditionalForce.Text = "Conditional Force";
  530.             this.GroupConditionalForce.Visible = false;
  531.             // 
  532.             // rbConditionalAxis2
  533.             // 
  534.             this.rbConditionalAxis2.Location = new System.Drawing.Point(160, 176);
  535.             this.rbConditionalAxis2.Name = "rbConditionalAxis2";
  536.             this.rbConditionalAxis2.Size = new System.Drawing.Size(56, 16);
  537.             this.rbConditionalAxis2.TabIndex = 13;
  538.             this.rbConditionalAxis2.Text = "Axis 2";
  539.             this.rbConditionalAxis2.CheckedChanged += new System.EventHandler(this.ConditionalAxisChanged);
  540.             // 
  541.             // ConditionalAxis1
  542.             // 
  543.             this.ConditionalAxis1.Checked = true;
  544.             this.ConditionalAxis1.Location = new System.Drawing.Point(160, 160);
  545.             this.ConditionalAxis1.Name = "ConditionalAxis1";
  546.             this.ConditionalAxis1.Size = new System.Drawing.Size(56, 16);
  547.             this.ConditionalAxis1.TabIndex = 12;
  548.             this.ConditionalAxis1.TabStop = true;
  549.             this.ConditionalAxis1.Text = "Axis 1";
  550.             this.ConditionalAxis1.CheckedChanged += new System.EventHandler(this.ConditionalAxisChanged);
  551.             // 
  552.             // ConditionalPositiveSaturationLabel
  553.             // 
  554.             this.ConditionalPositiveSaturationLabel.AutoSize = true;
  555.             this.ConditionalPositiveSaturationLabel.Location = new System.Drawing.Point(192, 120);
  556.             this.ConditionalPositiveSaturationLabel.Name = "ConditionalPositiveSaturationLabel";
  557.             this.ConditionalPositiveSaturationLabel.Size = new System.Drawing.Size(136, 13);
  558.             this.ConditionalPositiveSaturationLabel.TabIndex = 11;
  559.             this.ConditionalPositiveSaturationLabel.Text = "Positive Saturation: 10000";
  560.             // 
  561.             // ConditionalPositiveSaturation
  562.             // 
  563.             this.ConditionalPositiveSaturation.AutoSize = false;
  564.             this.ConditionalPositiveSaturation.LargeChange = 1000;
  565.             this.ConditionalPositiveSaturation.Location = new System.Drawing.Point(192, 136);
  566.             this.ConditionalPositiveSaturation.Maximum = 10000;
  567.             this.ConditionalPositiveSaturation.Name = "ConditionalPositiveSaturation";
  568.             this.ConditionalPositiveSaturation.Size = new System.Drawing.Size(136, 45);
  569.             this.ConditionalPositiveSaturation.SmallChange = 100;
  570.             this.ConditionalPositiveSaturation.TabIndex = 10;
  571.             this.ConditionalPositiveSaturation.TickFrequency = 1000;
  572.             this.ConditionalPositiveSaturation.Value = 10000;
  573.             this.ConditionalPositiveSaturation.Scroll += new System.EventHandler(this.ConditionalScroll);
  574.             // 
  575.             // ConditionalNegativeSaturationLabel
  576.             // 
  577.             this.ConditionalNegativeSaturationLabel.AutoSize = true;
  578.             this.ConditionalNegativeSaturationLabel.Location = new System.Drawing.Point(24, 120);
  579.             this.ConditionalNegativeSaturationLabel.Name = "ConditionalNegativeSaturationLabel";
  580.             this.ConditionalNegativeSaturationLabel.Size = new System.Drawing.Size(141, 13);
  581.             this.ConditionalNegativeSaturationLabel.TabIndex = 9;
  582.             this.ConditionalNegativeSaturationLabel.Text = "Negative Saturation: 10000";
  583.             // 
  584.             // ConditionalNegativeSaturation
  585.             // 
  586.             this.ConditionalNegativeSaturation.AutoSize = false;
  587.             this.ConditionalNegativeSaturation.LargeChange = 1000;
  588.             this.ConditionalNegativeSaturation.Location = new System.Drawing.Point(24, 136);
  589.             this.ConditionalNegativeSaturation.Maximum = 10000;
  590.             this.ConditionalNegativeSaturation.Name = "ConditionalNegativeSaturation";
  591.             this.ConditionalNegativeSaturation.Size = new System.Drawing.Size(136, 45);
  592.             this.ConditionalNegativeSaturation.SmallChange = 100;
  593.             this.ConditionalNegativeSaturation.TabIndex = 8;
  594.             this.ConditionalNegativeSaturation.TickFrequency = 1000;
  595.             this.ConditionalNegativeSaturation.Value = 10000;
  596.             this.ConditionalNegativeSaturation.Scroll += new System.EventHandler(this.ConditionalScroll);
  597.             // 
  598.             // ConditionalPositiveCoefficientLabel
  599.             // 
  600.             this.ConditionalPositiveCoefficientLabel.AutoSize = true;
  601.             this.ConditionalPositiveCoefficientLabel.Location = new System.Drawing.Point(192, 72);
  602.             this.ConditionalPositiveCoefficientLabel.Name = "ConditionalPositiveCoefficientLabel";
  603.             this.ConditionalPositiveCoefficientLabel.Size = new System.Drawing.Size(113, 13);
  604.             this.ConditionalPositiveCoefficientLabel.TabIndex = 7;
  605.             this.ConditionalPositiveCoefficientLabel.Text = "Positive Coefficient: 0";
  606.             // 
  607.             // ConditionalPositiveCoefficient
  608.             // 
  609.             this.ConditionalPositiveCoefficient.AutoSize = false;
  610.             this.ConditionalPositiveCoefficient.LargeChange = 1000;
  611.             this.ConditionalPositiveCoefficient.Location = new System.Drawing.Point(192, 88);
  612.             this.ConditionalPositiveCoefficient.Maximum = 10000;
  613.             this.ConditionalPositiveCoefficient.Minimum = -10000;
  614.             this.ConditionalPositiveCoefficient.Name = "ConditionalPositiveCoefficient";
  615.             this.ConditionalPositiveCoefficient.Size = new System.Drawing.Size(136, 45);
  616.             this.ConditionalPositiveCoefficient.SmallChange = 100;
  617.             this.ConditionalPositiveCoefficient.TabIndex = 6;
  618.             this.ConditionalPositiveCoefficient.TickFrequency = 1000;
  619.             this.ConditionalPositiveCoefficient.Scroll += new System.EventHandler(this.ConditionalScroll);
  620.             // 
  621.             // ConditionalNegativeCoeffcientLabel
  622.             // 
  623.             this.ConditionalNegativeCoeffcientLabel.AutoSize = true;
  624.             this.ConditionalNegativeCoeffcientLabel.Location = new System.Drawing.Point(24, 72);
  625.             this.ConditionalNegativeCoeffcientLabel.Name = "ConditionalNegativeCoeffcientLabel";
  626.             this.ConditionalNegativeCoeffcientLabel.Size = new System.Drawing.Size(118, 13);
  627.             this.ConditionalNegativeCoeffcientLabel.TabIndex = 5;
  628.             this.ConditionalNegativeCoeffcientLabel.Text = "Negative Coefficient: 0";
  629.             // 
  630.             // ConditionalNegativeCoeffcient
  631.             // 
  632.             this.ConditionalNegativeCoeffcient.AutoSize = false;
  633.             this.ConditionalNegativeCoeffcient.LargeChange = 1000;
  634.             this.ConditionalNegativeCoeffcient.Location = new System.Drawing.Point(24, 88);
  635.             this.ConditionalNegativeCoeffcient.Maximum = 10000;
  636.             this.ConditionalNegativeCoeffcient.Minimum = -10000;
  637.             this.ConditionalNegativeCoeffcient.Name = "ConditionalNegativeCoeffcient";
  638.             this.ConditionalNegativeCoeffcient.Size = new System.Drawing.Size(136, 45);
  639.             this.ConditionalNegativeCoeffcient.SmallChange = 100;
  640.             this.ConditionalNegativeCoeffcient.TabIndex = 4;
  641.             this.ConditionalNegativeCoeffcient.TickFrequency = 1000;
  642.             this.ConditionalNegativeCoeffcient.Scroll += new System.EventHandler(this.ConditionalScroll);
  643.             // 
  644.             // ConditionalOffsetLabel
  645.             // 
  646.             this.ConditionalOffsetLabel.AutoSize = true;
  647.             this.ConditionalOffsetLabel.Location = new System.Drawing.Point(192, 24);
  648.             this.ConditionalOffsetLabel.Name = "ConditionalOffsetLabel";
  649.             this.ConditionalOffsetLabel.Size = new System.Drawing.Size(47, 13);
  650.             this.ConditionalOffsetLabel.TabIndex = 3;
  651.             this.ConditionalOffsetLabel.Text = "Offset: 0";
  652.             // 
  653.             // ConditionalOffset
  654.             // 
  655.             this.ConditionalOffset.AutoSize = false;
  656.             this.ConditionalOffset.LargeChange = 1000;
  657.             this.ConditionalOffset.Location = new System.Drawing.Point(192, 40);
  658.             this.ConditionalOffset.Maximum = 10000;
  659.             this.ConditionalOffset.Minimum = -10000;
  660.             this.ConditionalOffset.Name = "ConditionalOffset";
  661.             this.ConditionalOffset.Size = new System.Drawing.Size(136, 45);
  662.             this.ConditionalOffset.SmallChange = 100;
  663.             this.ConditionalOffset.TabIndex = 2;
  664.             this.ConditionalOffset.TickFrequency = 1000;
  665.             this.ConditionalOffset.Scroll += new System.EventHandler(this.ConditionalScroll);
  666.             // 
  667.             // ConditionalDeadBandLabel
  668.             // 
  669.             this.ConditionalDeadBandLabel.AutoSize = true;
  670.             this.ConditionalDeadBandLabel.Location = new System.Drawing.Point(24, 24);
  671.             this.ConditionalDeadBandLabel.Name = "ConditionalDeadBandLabel";
  672.             this.ConditionalDeadBandLabel.Size = new System.Drawing.Size(73, 13);
  673.             this.ConditionalDeadBandLabel.TabIndex = 1;
  674.             this.ConditionalDeadBandLabel.Text = "Dead Band: 0";
  675.             // 
  676.             // ConditionalDeadBand
  677.             // 
  678.             this.ConditionalDeadBand.AutoSize = false;
  679.             this.ConditionalDeadBand.LargeChange = 1000;
  680.             this.ConditionalDeadBand.Location = new System.Drawing.Point(24, 40);
  681.             this.ConditionalDeadBand.Maximum = 10000;
  682.             this.ConditionalDeadBand.Name = "ConditionalDeadBand";
  683.             this.ConditionalDeadBand.Size = new System.Drawing.Size(136, 45);
  684.             this.ConditionalDeadBand.SmallChange = 100;
  685.             this.ConditionalDeadBand.TabIndex = 0;
  686.             this.ConditionalDeadBand.TickFrequency = 1000;
  687.             this.ConditionalDeadBand.Scroll += new System.EventHandler(this.ConditionalScroll);
  688.             // 
  689.             // GroupPeriodForce
  690.             // 
  691.             this.GroupPeriodForce.Controls.AddRange(new System.Windows.Forms.Control[] {
  692.                                                                                            this.PeriodicPeriodLabel,
  693.                                                                                            this.PeriodicPeriod,
  694.                                                                                            this.PeriodicPhaseLabel,
  695.                                                                                            this.PeriodicPhase,
  696.                                                                                            this.PeriodicOffsetLabel,
  697.                                                                                            this.PeriodicOffset,
  698.                                                                                            this.PeriodicMagnitudeLabel,
  699.                                                                                            this.PeriodicMagnitude});
  700.             this.GroupPeriodForce.Location = new System.Drawing.Point(8, 16);
  701.             this.GroupPeriodForce.Name = "GroupPeriodForce";
  702.             this.GroupPeriodForce.Size = new System.Drawing.Size(344, 200);
  703.             this.GroupPeriodForce.TabIndex = 2;
  704.             this.GroupPeriodForce.TabStop = false;
  705.             this.GroupPeriodForce.Tag = "";
  706.             this.GroupPeriodForce.Text = "Periodic Force";
  707.             this.GroupPeriodForce.Visible = false;
  708.             // 
  709.             // PeriodicPeriodLabel
  710.             // 
  711.             this.PeriodicPeriodLabel.AutoSize = true;
  712.             this.PeriodicPeriodLabel.Location = new System.Drawing.Point(96, 142);
  713.             this.PeriodicPeriodLabel.Name = "PeriodicPeriodLabel";
  714.             this.PeriodicPeriodLabel.Size = new System.Drawing.Size(49, 13);
  715.             this.PeriodicPeriodLabel.TabIndex = 7;
  716.             this.PeriodicPeriodLabel.Text = "Period: 0";
  717.             // 
  718.             // PeriodicPeriod
  719.             // 
  720.             this.PeriodicPeriod.LargeChange = 1000;
  721.             this.PeriodicPeriod.Location = new System.Drawing.Point(24, 153);
  722.             this.PeriodicPeriod.Maximum = 500000;
  723.             this.PeriodicPeriod.Name = "PeriodicPeriod";
  724.             this.PeriodicPeriod.Size = new System.Drawing.Size(304, 45);
  725.             this.PeriodicPeriod.SmallChange = 100;
  726.             this.PeriodicPeriod.TabIndex = 6;
  727.             this.PeriodicPeriod.TickFrequency = 20000;
  728.             this.PeriodicPeriod.Scroll += new System.EventHandler(this.PeriodicScroll);
  729.             // 
  730.             // PeriodicPhaseLabel
  731.             // 
  732.             this.PeriodicPhaseLabel.AutoSize = true;
  733.             this.PeriodicPhaseLabel.Location = new System.Drawing.Point(96, 100);
  734.             this.PeriodicPhaseLabel.Name = "PeriodicPhaseLabel";
  735.             this.PeriodicPhaseLabel.Size = new System.Drawing.Size(49, 13);
  736.             this.PeriodicPhaseLabel.TabIndex = 5;
  737.             this.PeriodicPhaseLabel.Text = "Phase: 0";
  738.             // 
  739.             // PeriodicPhase
  740.             // 
  741.             this.PeriodicPhase.LargeChange = 100;
  742.             this.PeriodicPhase.Location = new System.Drawing.Point(24, 110);
  743.             this.PeriodicPhase.Maximum = 35999;
  744.             this.PeriodicPhase.Name = "PeriodicPhase";
  745.             this.PeriodicPhase.Size = new System.Drawing.Size(304, 45);
  746.             this.PeriodicPhase.SmallChange = 10;
  747.             this.PeriodicPhase.TabIndex = 4;
  748.             this.PeriodicPhase.TickFrequency = 1000;
  749.             this.PeriodicPhase.Scroll += new System.EventHandler(this.PeriodicScroll);
  750.             // 
  751.             // PeriodicOffsetLabel
  752.             // 
  753.             this.PeriodicOffsetLabel.AutoSize = true;
  754.             this.PeriodicOffsetLabel.Location = new System.Drawing.Point(96, 58);
  755.             this.PeriodicOffsetLabel.Name = "PeriodicOffsetLabel";
  756.             this.PeriodicOffsetLabel.Size = new System.Drawing.Size(47, 13);
  757.             this.PeriodicOffsetLabel.TabIndex = 3;
  758.             this.PeriodicOffsetLabel.Text = "Offset: 0";
  759.             // 
  760.             // PeriodicOffset
  761.             // 
  762.             this.PeriodicOffset.LargeChange = 100;
  763.             this.PeriodicOffset.Location = new System.Drawing.Point(24, 67);
  764.             this.PeriodicOffset.Maximum = 10000;
  765.             this.PeriodicOffset.Minimum = -10000;
  766.             this.PeriodicOffset.Name = "PeriodicOffset";
  767.             this.PeriodicOffset.Size = new System.Drawing.Size(304, 45);
  768.             this.PeriodicOffset.SmallChange = 10;
  769.             this.PeriodicOffset.TabIndex = 2;
  770.             this.PeriodicOffset.TickFrequency = 1000;
  771.             this.PeriodicOffset.Scroll += new System.EventHandler(this.PeriodicScroll);
  772.             // 
  773.             // PeriodicMagnitudeLabel
  774.             // 
  775.             this.PeriodicMagnitudeLabel.AutoSize = true;
  776.             this.PeriodicMagnitudeLabel.Location = new System.Drawing.Point(96, 16);
  777.             this.PeriodicMagnitudeLabel.Name = "PeriodicMagnitudeLabel";
  778.             this.PeriodicMagnitudeLabel.Size = new System.Drawing.Size(70, 13);
  779.             this.PeriodicMagnitudeLabel.TabIndex = 1;
  780.             this.PeriodicMagnitudeLabel.Text = "Magnitude: 0";
  781.             // 
  782.             // PeriodicMagnitude
  783.             // 
  784.             this.PeriodicMagnitude.LargeChange = 1000;
  785.             this.PeriodicMagnitude.Location = new System.Drawing.Point(24, 24);
  786.             this.PeriodicMagnitude.Maximum = 10000;
  787.             this.PeriodicMagnitude.Name = "PeriodicMagnitude";
  788.             this.PeriodicMagnitude.Size = new System.Drawing.Size(304, 45);
  789.             this.PeriodicMagnitude.SmallChange = 100;
  790.             this.PeriodicMagnitude.TabIndex = 0;
  791.             this.PeriodicMagnitude.TickFrequency = 1000;
  792.             this.PeriodicMagnitude.Value = 5000;
  793.             this.PeriodicMagnitude.Scroll += new System.EventHandler(this.PeriodicScroll);
  794.             // 
  795.             // GroupRampForce
  796.             // 
  797.             this.GroupRampForce.Controls.AddRange(new System.Windows.Forms.Control[] {
  798.                                                                                          this.RangeEndLabel,
  799.                                                                                          this.RangeEnd,
  800.                                                                                          this.RangeStartLabel,
  801.                                                                                          this.RangeStart});
  802.             this.GroupRampForce.Location = new System.Drawing.Point(8, 16);
  803.             this.GroupRampForce.Name = "GroupRampForce";
  804.             this.GroupRampForce.Size = new System.Drawing.Size(344, 200);
  805.             this.GroupRampForce.TabIndex = 1;
  806.             this.GroupRampForce.TabStop = false;
  807.             this.GroupRampForce.Tag = "";
  808.             this.GroupRampForce.Text = "Ramp Force";
  809.             this.GroupRampForce.Visible = false;
  810.             // 
  811.             // RangeEndLabel
  812.             // 
  813.             this.RangeEndLabel.AutoSize = true;
  814.             this.RangeEndLabel.Location = new System.Drawing.Point(93, 120);
  815.             this.RangeEndLabel.Name = "RangeEndLabel";
  816.             this.RangeEndLabel.Size = new System.Drawing.Size(73, 13);
  817.             this.RangeEndLabel.TabIndex = 3;
  818.             this.RangeEndLabel.Text = "Range End: 0";
  819.             // 
  820.             // RangeEnd
  821.             // 
  822.             this.RangeEnd.LargeChange = 100;
  823.             this.RangeEnd.Location = new System.Drawing.Point(28, 144);
  824.             this.RangeEnd.Maximum = 10000;
  825.             this.RangeEnd.Minimum = -10000;
  826.             this.RangeEnd.Name = "RangeEnd";
  827.             this.RangeEnd.Size = new System.Drawing.Size(304, 45);
  828.             this.RangeEnd.SmallChange = 10;
  829.             this.RangeEnd.TabIndex = 2;
  830.             this.RangeEnd.TickFrequency = 1000;
  831.             this.RangeEnd.Scroll += new System.EventHandler(this.RangeScroll);
  832.             // 
  833.             // RangeStartLabel
  834.             // 
  835.             this.RangeStartLabel.AutoSize = true;
  836.             this.RangeStartLabel.Location = new System.Drawing.Point(93, 24);
  837.             this.RangeStartLabel.Name = "RangeStartLabel";
  838.             this.RangeStartLabel.Size = new System.Drawing.Size(77, 13);
  839.             this.RangeStartLabel.TabIndex = 1;
  840.             this.RangeStartLabel.Text = "Range Start: 0";
  841.             // 
  842.             // RangeStart
  843.             // 
  844.             this.RangeStart.LargeChange = 100;
  845.             this.RangeStart.Location = new System.Drawing.Point(28, 48);
  846.             this.RangeStart.Maximum = 10000;
  847.             this.RangeStart.Minimum = -10000;
  848.             this.RangeStart.Name = "RangeStart";
  849.             this.RangeStart.Size = new System.Drawing.Size(304, 45);
  850.             this.RangeStart.SmallChange = 10;
  851.             this.RangeStart.TabIndex = 0;
  852.             this.RangeStart.TickFrequency = 1000;
  853.             this.RangeStart.Scroll += new System.EventHandler(this.RangeScroll);
  854.             // 
  855.             // GroupConstantForce
  856.             // 
  857.             this.GroupConstantForce.Controls.AddRange(new System.Windows.Forms.Control[] {
  858.                                                                                              this.Magnitude,
  859.                                                                                              this.ConstantForceMagnitude});
  860.             this.GroupConstantForce.Location = new System.Drawing.Point(8, 16);
  861.             this.GroupConstantForce.Name = "GroupConstantForce";
  862.             this.GroupConstantForce.Size = new System.Drawing.Size(344, 200);
  863.             this.GroupConstantForce.TabIndex = 0;
  864.             this.GroupConstantForce.TabStop = false;
  865.             this.GroupConstantForce.Tag = "";
  866.             this.GroupConstantForce.Text = "Constant Force";
  867.             this.GroupConstantForce.Visible = false;
  868.             // 
  869.             // Magnitude
  870.             // 
  871.             this.Magnitude.AutoSize = true;
  872.             this.Magnitude.Location = new System.Drawing.Point(89, 72);
  873.             this.Magnitude.Name = "Magnitude";
  874.             this.Magnitude.Size = new System.Drawing.Size(175, 13);
  875.             this.Magnitude.TabIndex = 1;
  876.             this.Magnitude.Text = "Constant Force Magnitude: 10000";
  877.             // 
  878.             // ConstantForceMagnitude
  879.             // 
  880.             this.ConstantForceMagnitude.LargeChange = 100;
  881.             this.ConstantForceMagnitude.Location = new System.Drawing.Point(24, 96);
  882.             this.ConstantForceMagnitude.Maximum = 10000;
  883.             this.ConstantForceMagnitude.Name = "ConstantForceMagnitude";
  884.             this.ConstantForceMagnitude.Size = new System.Drawing.Size(304, 45);
  885.             this.ConstantForceMagnitude.SmallChange = 10;
  886.             this.ConstantForceMagnitude.TabIndex = 0;
  887.             this.ConstantForceMagnitude.TickFrequency = 1000;
  888.             this.ConstantForceMagnitude.Value = 10000;
  889.             this.ConstantForceMagnitude.Scroll += new System.EventHandler(this.ConstantForceMagnitudeScroll);
  890.             // 
  891.             // EnvelopeGroupBox
  892.             // 
  893.             this.EnvelopeGroupBox.Controls.AddRange(new System.Windows.Forms.Control[] {
  894.                                                                                            this.EnvelopeFadeTime,
  895.                                                                                            this.EnvelopeFadeTimeLabel,
  896.                                                                                            this.EnvelopeFadeLevel,
  897.                                                                                            this.EnvelopeFadeLevelLabel,
  898.                                                                                            this.EnvelopeAttackTime,
  899.                                                                                            this.EnvelopeAttackTimeLabel,
  900.                                                                                            this.EnvelopeAttackLevel,
  901.                                                                                            this.EnvelopeAttackLevelLabel,
  902.                                                                                            this.chkUseEnvelope});
  903.             this.EnvelopeGroupBox.Location = new System.Drawing.Point(246, 262);
  904.             this.EnvelopeGroupBox.Name = "EnvelopeGroupBox";
  905.             this.EnvelopeGroupBox.Size = new System.Drawing.Size(168, 216);
  906.             this.EnvelopeGroupBox.TabIndex = 9;
  907.             this.EnvelopeGroupBox.TabStop = false;
  908.             this.EnvelopeGroupBox.Text = "Envelope";
  909.             // 
  910.             // EnvelopeFadeTime
  911.             // 
  912.             this.EnvelopeFadeTime.AutoSize = false;
  913.             this.EnvelopeFadeTime.LargeChange = 10000;
  914.             this.EnvelopeFadeTime.Location = new System.Drawing.Point(16, 172);
  915.             this.EnvelopeFadeTime.Maximum = 5000000;
  916.             this.EnvelopeFadeTime.Name = "EnvelopeFadeTime";
  917.             this.EnvelopeFadeTime.Size = new System.Drawing.Size(144, 45);
  918.             this.EnvelopeFadeTime.SmallChange = 1000;
  919.             this.EnvelopeFadeTime.TabIndex = 8;
  920.             this.EnvelopeFadeTime.TickFrequency = 1000000;
  921.             this.EnvelopeFadeTime.Scroll += new System.EventHandler(this.EnvChanged);
  922.             // 
  923.             // EnvelopeFadeTimeLabel
  924.             // 
  925.             this.EnvelopeFadeTimeLabel.AutoSize = true;
  926.             this.EnvelopeFadeTimeLabel.Location = new System.Drawing.Point(16, 160);
  927.             this.EnvelopeFadeTimeLabel.Name = "EnvelopeFadeTimeLabel";
  928.             this.EnvelopeFadeTimeLabel.Size = new System.Drawing.Size(71, 13);
  929.             this.EnvelopeFadeTimeLabel.TabIndex = 7;
  930.             this.EnvelopeFadeTimeLabel.Text = "Fade Time: 0";
  931.             // 
  932.             // EnvelopeFadeLevel
  933.             // 
  934.             this.EnvelopeFadeLevel.AutoSize = false;
  935.             this.EnvelopeFadeLevel.LargeChange = 1000;
  936.             this.EnvelopeFadeLevel.Location = new System.Drawing.Point(16, 128);
  937.             this.EnvelopeFadeLevel.Maximum = 10000;
  938.             this.EnvelopeFadeLevel.Name = "EnvelopeFadeLevel";
  939.             this.EnvelopeFadeLevel.Size = new System.Drawing.Size(144, 45);
  940.             this.EnvelopeFadeLevel.SmallChange = 100;
  941.             this.EnvelopeFadeLevel.TabIndex = 6;
  942.             this.EnvelopeFadeLevel.TickFrequency = 1000;
  943.             this.EnvelopeFadeLevel.Scroll += new System.EventHandler(this.EnvChanged);
  944.             // 
  945.             // EnvelopeFadeLevelLabel
  946.             // 
  947.             this.EnvelopeFadeLevelLabel.AutoSize = true;
  948.             this.EnvelopeFadeLevelLabel.Location = new System.Drawing.Point(16, 116);
  949.             this.EnvelopeFadeLevelLabel.Name = "EnvelopeFadeLevelLabel";
  950.             this.EnvelopeFadeLevelLabel.Size = new System.Drawing.Size(73, 13);
  951.             this.EnvelopeFadeLevelLabel.TabIndex = 5;
  952.             this.EnvelopeFadeLevelLabel.Text = "Fade Level: 0";
  953.             // 
  954.             // EnvelopeAttackTime
  955.             // 
  956.             this.EnvelopeAttackTime.AutoSize = false;
  957.             this.EnvelopeAttackTime.LargeChange = 50000;
  958.             this.EnvelopeAttackTime.Location = new System.Drawing.Point(16, 88);
  959.             this.EnvelopeAttackTime.Maximum = 5000000;
  960.             this.EnvelopeAttackTime.Name = "EnvelopeAttackTime";
  961.             this.EnvelopeAttackTime.Size = new System.Drawing.Size(144, 45);
  962.             this.EnvelopeAttackTime.SmallChange = 1000;
  963.             this.EnvelopeAttackTime.TabIndex = 4;
  964.             this.EnvelopeAttackTime.TickFrequency = 1000000;
  965.             this.EnvelopeAttackTime.Scroll += new System.EventHandler(this.EnvChanged);
  966.             // 
  967.             // EnvelopeAttackTimeLabel
  968.             // 
  969.             this.EnvelopeAttackTimeLabel.AutoSize = true;
  970.             this.EnvelopeAttackTimeLabel.Location = new System.Drawing.Point(16, 76);
  971.             this.EnvelopeAttackTimeLabel.Name = "EnvelopeAttackTimeLabel";
  972.             this.EnvelopeAttackTimeLabel.Size = new System.Drawing.Size(76, 13);
  973.             this.EnvelopeAttackTimeLabel.TabIndex = 3;
  974.             this.EnvelopeAttackTimeLabel.Text = "Attack Time: 0";
  975.             // 
  976.             // EnvelopeAttackLevel
  977.             // 
  978.             this.EnvelopeAttackLevel.AutoSize = false;
  979.             this.EnvelopeAttackLevel.LargeChange = 1000;
  980.             this.EnvelopeAttackLevel.Location = new System.Drawing.Point(16, 44);
  981.             this.EnvelopeAttackLevel.Maximum = 10000;
  982.             this.EnvelopeAttackLevel.Name = "EnvelopeAttackLevel";
  983.             this.EnvelopeAttackLevel.Size = new System.Drawing.Size(144, 45);
  984.             this.EnvelopeAttackLevel.SmallChange = 100;
  985.             this.EnvelopeAttackLevel.TabIndex = 2;
  986.             this.EnvelopeAttackLevel.TickFrequency = 1000;
  987.             this.EnvelopeAttackLevel.Scroll += new System.EventHandler(this.EnvChanged);
  988.             // 
  989.             // EnvelopeAttackLevelLabel
  990.             // 
  991.             this.EnvelopeAttackLevelLabel.AutoSize = true;
  992.             this.EnvelopeAttackLevelLabel.Location = new System.Drawing.Point(16, 32);
  993.             this.EnvelopeAttackLevelLabel.Name = "EnvelopeAttackLevelLabel";
  994.             this.EnvelopeAttackLevelLabel.Size = new System.Drawing.Size(78, 13);
  995.             this.EnvelopeAttackLevelLabel.TabIndex = 1;
  996.             this.EnvelopeAttackLevelLabel.Text = "Attack Level: 0";
  997.             // 
  998.             // chkUseEnvelope
  999.             // 
  1000.             this.chkUseEnvelope.Location = new System.Drawing.Point(16, 12);
  1001.             this.chkUseEnvelope.Name = "chkUseEnvelope";
  1002.             this.chkUseEnvelope.Size = new System.Drawing.Size(96, 24);
  1003.             this.chkUseEnvelope.TabIndex = 0;
  1004.             this.chkUseEnvelope.Text = "Use Envelope";
  1005.             this.chkUseEnvelope.CheckedChanged += new System.EventHandler(this.EnvChanged);
  1006.             // 
  1007.             // DirectionGroupBox
  1008.             // 
  1009.             this.DirectionGroupBox.Controls.AddRange(new System.Windows.Forms.Control[] {
  1010.                                                                                             this.NorthEast,
  1011.                                                                                             this.East,
  1012.                                                                                             this.SouthEast,
  1013.                                                                                             this.South,
  1014.                                                                                             this.SouthWest,
  1015.                                                                                             this.West,
  1016.                                                                                             this.NorthWest,
  1017.                                                                                             this.North});
  1018.             this.DirectionGroupBox.Location = new System.Drawing.Point(438, 262);
  1019.             this.DirectionGroupBox.Name = "DirectionGroupBox";
  1020.             this.DirectionGroupBox.Size = new System.Drawing.Size(168, 216);
  1021.             this.DirectionGroupBox.TabIndex = 10;
  1022.             this.DirectionGroupBox.TabStop = false;
  1023.             this.DirectionGroupBox.Text = "Direction";
  1024.             // 
  1025.             // NorthEast
  1026.             // 
  1027.             this.NorthEast.Location = new System.Drawing.Point(120, 64);
  1028.             this.NorthEast.Name = "NorthEast";
  1029.             this.NorthEast.Size = new System.Drawing.Size(16, 24);
  1030.             this.NorthEast.TabIndex = 7;
  1031.             this.NorthEast.Tag = "1,-1";
  1032.             this.NorthEast.CheckedChanged += new System.EventHandler(this.DirectionChanged);
  1033.             // 
  1034.             // East
  1035.             // 
  1036.             this.East.Checked = true;
  1037.             this.East.Location = new System.Drawing.Point(136, 104);
  1038.             this.East.Name = "East";
  1039.             this.East.Size = new System.Drawing.Size(16, 24);
  1040.             this.East.TabIndex = 6;
  1041.             this.East.TabStop = true;
  1042.             this.East.Tag = "2,0";
  1043.             this.East.CheckedChanged += new System.EventHandler(this.DirectionChanged);
  1044.             // 
  1045.             // SouthEast
  1046.             // 
  1047.             this.SouthEast.Location = new System.Drawing.Point(120, 144);
  1048.             this.SouthEast.Name = "SouthEast";
  1049.             this.SouthEast.Size = new System.Drawing.Size(16, 24);
  1050.             this.SouthEast.TabIndex = 5;
  1051.             this.SouthEast.Tag = "1,1";
  1052.             this.SouthEast.CheckedChanged += new System.EventHandler(this.DirectionChanged);
  1053.             // 
  1054.             // South
  1055.             // 
  1056.             this.South.Location = new System.Drawing.Point(80, 168);
  1057.             this.South.Name = "South";
  1058.             this.South.Size = new System.Drawing.Size(16, 24);
  1059.             this.South.TabIndex = 4;
  1060.             this.South.Tag = "0,2";
  1061.             this.South.CheckedChanged += new System.EventHandler(this.DirectionChanged);
  1062.             // 
  1063.             // SouthWest
  1064.             // 
  1065.             this.SouthWest.Location = new System.Drawing.Point(40, 144);
  1066.             this.SouthWest.Name = "SouthWest";
  1067.             this.SouthWest.Size = new System.Drawing.Size(16, 24);
  1068.             this.SouthWest.TabIndex = 3;
  1069.             this.SouthWest.Tag = "-1,1";
  1070.             this.SouthWest.CheckedChanged += new System.EventHandler(this.DirectionChanged);
  1071.             // 
  1072.             // West
  1073.             // 
  1074.             this.West.Location = new System.Drawing.Point(24, 104);
  1075.             this.West.Name = "West";
  1076.             this.West.Size = new System.Drawing.Size(16, 24);
  1077.             this.West.TabIndex = 2;
  1078.             this.West.Tag = "-2,0";
  1079.             this.West.CheckedChanged += new System.EventHandler(this.DirectionChanged);
  1080.             // 
  1081.             // NorthWest
  1082.             // 
  1083.             this.NorthWest.Location = new System.Drawing.Point(40, 64);
  1084.             this.NorthWest.Name = "NorthWest";
  1085.             this.NorthWest.Size = new System.Drawing.Size(16, 24);
  1086.             this.NorthWest.TabIndex = 1;
  1087.             this.NorthWest.Tag = "-1,-1";
  1088.             this.NorthWest.CheckedChanged += new System.EventHandler(this.DirectionChanged);
  1089.             // 
  1090.             // North
  1091.             // 
  1092.             this.North.Location = new System.Drawing.Point(80, 40);
  1093.             this.North.Name = "North";
  1094.             this.North.Size = new System.Drawing.Size(16, 24);
  1095.             this.North.TabIndex = 0;
  1096.             this.North.Tag = "0,-2";
  1097.             this.North.CheckedChanged += new System.EventHandler(this.DirectionChanged);
  1098.             // 
  1099.             // frmMain
  1100.             // 
  1101.             this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  1102.             this.ClientSize = new System.Drawing.Size(613, 485);
  1103.             this.Controls.AddRange(new System.Windows.Forms.Control[] {
  1104.                                                                           this.Label1,
  1105.                                                                           this.gbGeneralParams,
  1106.                                                                           this.lstEffects,
  1107.                                                                           this.gbTypeContainer,
  1108.                                                                           this.EnvelopeGroupBox,
  1109.                                                                           this.DirectionGroupBox});
  1110.             this.Name = "frmMain";
  1111.             this.Text = "Feedback";
  1112.             this.Closing += new System.ComponentModel.CancelEventHandler(this.frmMain_Closing);
  1113.             this.Load += new System.EventHandler(this.frmMain_Load);
  1114.             this.Activated += new System.EventHandler(this.frmMain_Activated);
  1115.             this.gbGeneralParams.ResumeLayout(false);
  1116.             ((System.ComponentModel.ISupportInitialize)(this.GeneralPeriod)).EndInit();
  1117.             ((System.ComponentModel.ISupportInitialize)(this.GeneralGain)).EndInit();
  1118.             ((System.ComponentModel.ISupportInitialize)(this.GeneralDuration)).EndInit();
  1119.             this.gbTypeContainer.ResumeLayout(false);
  1120.             this.GroupConditionalForce.ResumeLayout(false);
  1121.             ((System.ComponentModel.ISupportInitialize)(this.ConditionalPositiveSaturation)).EndInit();
  1122.             ((System.ComponentModel.ISupportInitialize)(this.ConditionalNegativeSaturation)).EndInit();
  1123.             ((System.ComponentModel.ISupportInitialize)(this.ConditionalPositiveCoefficient)).EndInit();
  1124.             ((System.ComponentModel.ISupportInitialize)(this.ConditionalNegativeCoeffcient)).EndInit();
  1125.             ((System.ComponentModel.ISupportInitialize)(this.ConditionalOffset)).EndInit();
  1126.             ((System.ComponentModel.ISupportInitialize)(this.ConditionalDeadBand)).EndInit();
  1127.             this.GroupPeriodForce.ResumeLayout(false);
  1128.             ((System.ComponentModel.ISupportInitialize)(this.PeriodicPeriod)).EndInit();
  1129.             ((System.ComponentModel.ISupportInitialize)(this.PeriodicPhase)).EndInit();
  1130.             ((System.ComponentModel.ISupportInitialize)(this.PeriodicOffset)).EndInit();
  1131.             ((System.ComponentModel.ISupportInitialize)(this.PeriodicMagnitude)).EndInit();
  1132.             this.GroupRampForce.ResumeLayout(false);
  1133.             ((System.ComponentModel.ISupportInitialize)(this.RangeEnd)).EndInit();
  1134.             ((System.ComponentModel.ISupportInitialize)(this.RangeStart)).EndInit();
  1135.             this.GroupConstantForce.ResumeLayout(false);
  1136.             ((System.ComponentModel.ISupportInitialize)(this.ConstantForceMagnitude)).EndInit();
  1137.             this.EnvelopeGroupBox.ResumeLayout(false);
  1138.             ((System.ComponentModel.ISupportInitialize)(this.EnvelopeFadeTime)).EndInit();
  1139.             ((System.ComponentModel.ISupportInitialize)(this.EnvelopeFadeLevel)).EndInit();
  1140.             ((System.ComponentModel.ISupportInitialize)(this.EnvelopeAttackTime)).EndInit();
  1141.             ((System.ComponentModel.ISupportInitialize)(this.EnvelopeAttackLevel)).EndInit();
  1142.             this.DirectionGroupBox.ResumeLayout(false);
  1143.             this.ResumeLayout(false);
  1144.  
  1145.         }
  1146.         #endregion
  1147.  
  1148.         
  1149.         
  1150.         
  1151.         /// <summary>
  1152.         /// The main entry point for the application.
  1153.         /// </summary>
  1154.         static void Main() 
  1155.         {            
  1156.             frmMain main = new frmMain();
  1157.             if (!main.IsDisposed)
  1158.                 Application.Run(main);
  1159.         }
  1160.  
  1161.         
  1162.         
  1163.         
  1164.         /// <summary>
  1165.         /// Handles the changing of an effect.
  1166.         /// </summary>
  1167.         private void lstEffects_SelectedIndexChanged(object sender, System.EventArgs e)
  1168.         {
  1169.             EffectDescription description;
  1170.  
  1171.             if (null != effectSelected)
  1172.                 effectSelected.Unload();
  1173.  
  1174.             description = (EffectDescription)lstEffects.Items[lstEffects.SelectedIndex];
  1175.             effectSelected = description.effectSelected;
  1176.             UpdateVisibilty();
  1177.             
  1178.             try
  1179.             {
  1180.                 effectSelected.Start(1);
  1181.             }
  1182.             catch(InputException){}
  1183.         }
  1184.         
  1185.         
  1186.         
  1187.         
  1188.         /// <summary>
  1189.         /// Changes the parameters of an effect.
  1190.         /// </summary>
  1191.         private Effect ChangeParameter()
  1192.         {
  1193.             Effect eff = GetEffectParameters();
  1194.             int flags = (int)EffectParameterFlags.Start;
  1195.             int i = 0;
  1196.  
  1197.             switch (eff.EffectType)
  1198.             {
  1199.                 case EffectType.ConstantForce:
  1200.                     eff.Constant.Magnitude = ConstantForceMagnitude.Value;
  1201.                     flags = flags | (int)EffectParameterFlags.TypeSpecificParams;
  1202.                     break;
  1203.                 case EffectType.RampForce:
  1204.                     eff.RampStruct.Start= RangeStart.Value;
  1205.                     eff.RampStruct.End  = RangeEnd.Value;
  1206.                     flags = (int)EffectParameterFlags.TypeSpecificParams;
  1207.                     if ((int)DI.Infinite == eff.Duration)
  1208.                     {
  1209.                         // Default to a 2 second ramp effect
  1210.                         // if DI.Infinite is passed in.
  1211.                         // DI.Infinite is invalid for ramp forces.
  1212.                         eff.Duration = 2 * (int)DI.Seconds;
  1213.                         flags = flags | (int)EffectParameterFlags.Duration;
  1214.                     }
  1215.                     flags = flags | (int)EffectParameterFlags.Start;
  1216.                     break;
  1217.                 case EffectType.Periodic:
  1218.                         
  1219.                     eff.Periodic.Magnitude= PeriodicMagnitude.Value;
  1220.                     eff.Periodic.Offset = PeriodicOffset.Value;
  1221.                     eff.Periodic.Period = PeriodicPeriod.Value;
  1222.                     eff.Periodic.Phase  = PeriodicPhase.Value;
  1223.                         
  1224.                     flags = flags | (int)EffectParameterFlags.TypeSpecificParams;
  1225.                     break;
  1226.                 case EffectType.Condition:
  1227.                     if (ConditionalAxis1.Checked == true)
  1228.                         i = 0;
  1229.                     else                                                                    
  1230.                         i = 1;          
  1231.                 
  1232.                     eff.ConditionStruct[i].DeadBand             = ConditionalDeadBand.Value;
  1233.                     eff.ConditionStruct[i].NegativeCoefficient  = ConditionalNegativeCoeffcient.Value;
  1234.                     eff.ConditionStruct[i].NegativeSaturation   = ConditionalNegativeSaturation.Value;
  1235.                     eff.ConditionStruct[i].Offset               = ConditionalOffset.Value;
  1236.                     eff.ConditionStruct[i].PositiveCoefficient  = ConditionalPositiveCoefficient.Value;
  1237.                     eff.ConditionStruct[i].PositiveSaturation   = ConditionalPositiveSaturation.Value;
  1238.                                                                                                                                                             
  1239.                     flags = flags | (int)EffectParameterFlags.TypeSpecificParams;
  1240.                     break;
  1241.             }
  1242.             
  1243.             // Some feedback drivers will fail when setting parameters that aren't supported by
  1244.             // an effect. DirectInput will will in turn pass back the driver error to the application.
  1245.             // Since these are hardware specific error messages that can't be handled individually, 
  1246.             // the app will ignore any failures returned to SetParameters().
  1247.             try
  1248.             {
  1249.                 effectSelected.SetParameters(eff, EffectParameterFlags.TypeSpecificParams);
  1250.             }
  1251.             catch
  1252.             {
  1253.                 eff = GetEffectParameters();
  1254.             }
  1255.  
  1256.             return eff;
  1257.         }
  1258.         
  1259.         
  1260.         
  1261.         
  1262.         /// <summary>
  1263.         /// Changes the direction of an effect.
  1264.         /// </summary>
  1265.         private void ChangeDirection(int[] direction)
  1266.         {
  1267.             Effect eff = new Effect();
  1268.             
  1269.             eff.Flags = EffectFlags.Cartesian | EffectFlags.ObjectOffsets;
  1270.             effectSelected.GetParameters(ref eff, EffectParameterFlags.AllParams);
  1271.             eff.SetDirection(direction);
  1272.             
  1273.             // Some feedback drivers will fail when setting parameters that aren't supported by
  1274.             // an effect. DirectInput will will in turn pass back the driver error to the application.
  1275.             // Since these are hardware specific error messages that can't be handled individually, 
  1276.             // the app will ignore any failures returned to SetParameters().
  1277.             try
  1278.             {
  1279.                 effectSelected.SetParameters(eff, EffectParameterFlags.Direction | EffectParameterFlags.Start);
  1280.             }
  1281.             catch(InputException){}
  1282.         }
  1283.         
  1284.         
  1285.         
  1286.         
  1287.         /// <summary>
  1288.         /// Changes the envelope of an effect.
  1289.         /// </summary>
  1290.         private Effect ChangeEnvelope()
  1291.         {
  1292.             Effect eff = GetEffectParameters();
  1293.  
  1294.             if (!isChanging)
  1295.             {
  1296.                 eff.UsesEnvelope = chkUseEnvelope.Checked;
  1297.                 eff.EnvelopeStruct.AttackLevel = EnvelopeAttackLevel.Value;
  1298.                 eff.EnvelopeStruct.AttackTime = EnvelopeAttackTime.Value;
  1299.                 eff.EnvelopeStruct.FadeLevel = EnvelopeFadeLevel.Value;
  1300.                 eff.EnvelopeStruct.FadeTime = EnvelopeFadeTime.Value;
  1301.  
  1302.                 // Some feedback drivers will fail when setting parameters that aren't supported by
  1303.                 // an effect. DirectInput will will in turn pass back the driver error to the application.
  1304.                 // Since these are hardware specific error messages that can't be handled individually, 
  1305.                 // the app will ignore any failures returned to SetParameters().
  1306.                 try
  1307.                 {
  1308.                     effectSelected.SetParameters(eff, EffectParameterFlags.Envelope | EffectParameterFlags.Start);
  1309.                 }
  1310.                 catch(InputException){}
  1311.             }
  1312.             return eff;
  1313.         }
  1314.         
  1315.         
  1316.         
  1317.         
  1318.         /// <summary>
  1319.         /// Fills in an Effect structure with effect information.
  1320.         /// </summary>
  1321.         private Effect GetEffectParameters()
  1322.         {
  1323.             Effect eff = new Effect();
  1324.  
  1325.             eff.Flags = EffectFlags.ObjectIds | EffectFlags.Cartesian;
  1326.             effectSelected.GetParameters(ref eff, EffectParameterFlags.AllParams);
  1327.  
  1328.             // If this is a condition effect, see if the Effect.Condition member
  1329.             // array length that was returned from GetParameters() has enough elements 
  1330.             // to cover 2 axes if this is a two axis device. In most cases, conditional 
  1331.             // effects will return 1 Condition element that can be applied across 
  1332.             // all force-feedback axes.
  1333.             if ((eff.EffectType == EffectType.Condition) && (eff.ConditionStruct != null))
  1334.                                                         {
  1335.                 if ((rbConditionalAxis2.Enabled) && (eff.ConditionStruct.Length < 2))
  1336.                 {
  1337.                     // Resize the array for two axes.
  1338.                     Condition[] temp = new Condition[2];
  1339.                     eff.ConditionStruct.CopyTo(temp,0);
  1340.                     eff.ConditionStruct = temp;
  1341.                     // Copy the conditional effect info from one struct to the other.
  1342.                     eff.ConditionStruct[1] = eff.ConditionStruct[0];
  1343.                 }
  1344.             }
  1345.             return eff;
  1346.         }
  1347.         
  1348.         
  1349.         
  1350.         
  1351.         /// <summary>
  1352.         /// Updates the visibility of each
  1353.         /// effect parameters group box, as well
  1354.         /// as general parameter, envelope, and
  1355.         /// direction group boxes.
  1356.         /// </summary>
  1357.         private void UpdateVisibilty()
  1358.         {
  1359.             isChanging = true;
  1360.  
  1361.             if (null == effectSelected) 
  1362.                 return;
  1363.  
  1364.             EffectDescription description = (EffectDescription)lstEffects.Items[lstEffects.SelectedIndex];
  1365.             Effect eff = GetEffectParameters();
  1366.  
  1367.             GroupBox Current = new GroupBox();
  1368.  
  1369.             // Check to see what type of effect this is,
  1370.             // and then change the visibilty of the
  1371.             // group boxes accordingly.
  1372.             switch (DInputHelper.GetTypeCode((int)eff.EffectType))
  1373.             {
  1374.                 case (int)EffectType.Condition:
  1375.                     Current = GroupConditionalForce;
  1376.                     UpdateConditionalGroupBox(eff);
  1377.                     break;
  1378.                 case (int)EffectType.ConstantForce:
  1379.                     Current = GroupConstantForce;
  1380.                     UpdateConstantGroupBox(eff);
  1381.                     break;
  1382.                 case (int)EffectType.Periodic:
  1383.                     Current = GroupPeriodForce;
  1384.                     UpdatePeriodicGroupBox(eff);
  1385.                     break;
  1386.                 case (int)EffectType.RampForce:
  1387.                     Current = GroupRampForce;
  1388.                     UpdateRampGroupBox(eff);
  1389.                     break;
  1390.             }
  1391.  
  1392.             foreach (GroupBox target in gbTypeContainer.Controls)
  1393.             {
  1394.                 if (Current == target)
  1395.                     target.Visible = true;
  1396.                 else
  1397.                     target.Visible = false;
  1398.             }
  1399.  
  1400.             // Check the effect info and update the controls
  1401.             // to show whether the parameters are supported.
  1402.             if (0 == (description.info.StaticParams & (int)EffectParameterFlags.Direction))
  1403.                 DirectionGroupBox.Enabled = false;
  1404.             else
  1405.                 DirectionGroupBox.Enabled = true;
  1406.  
  1407.             if (0 == (description.info.StaticParams & (int)EffectParameterFlags.Duration))
  1408.                 GeneralDurationLabel.Enabled = GeneralDuration.Enabled = false;
  1409.             else
  1410.                 GeneralDurationLabel.Enabled = GeneralDuration.Enabled = true;
  1411.  
  1412.             if (0 == (description.info.StaticParams & (int)EffectParameterFlags.Gain))
  1413.                 GeneralGainLabel.Enabled = GeneralGain.Enabled = false;
  1414.             else
  1415.                 GeneralGainLabel.Enabled = GeneralGain.Enabled = true;
  1416.  
  1417.             if (0 == (description.info.StaticParams & (int)EffectParameterFlags.SamplePeriod))
  1418.                 GeneralPeriodLabel.Enabled = GeneralPeriod.Enabled = false;
  1419.             else
  1420.                 GeneralPeriodLabel.Enabled = GeneralPeriod.Enabled = true;
  1421.  
  1422.             // Update the general parameter
  1423.             // and envelope controls.
  1424.             UpdateGeneralParamsGroupBox(eff);
  1425.  
  1426.             // Reflect support for envelopes on this effect.
  1427.             UpdateEnvParamsGroupBox(eff);
  1428.             EnvelopeGroupBox.Enabled = ((description.info.StaticParams & (int)EffectParameterFlags.Envelope) != 0) ? true : false;
  1429.  
  1430.             // Update direction radio buttons.
  1431.             if (1 == axis.Length)
  1432.             {
  1433.                 if (2 == eff.GetDirection()[0])
  1434.                     East.Checked = true;
  1435.                 else
  1436.                     West.Checked = true;
  1437.             }
  1438.             else if (2 >= axis.Length)
  1439.             {
  1440.                 if (2 == eff.GetDirection()[0] && 0 == eff.GetDirection()[1])
  1441.                     East.Checked = true;
  1442.                 else if (-2 == eff.GetDirection()[0] && 0 == eff.GetDirection()[1])
  1443.                     West.Checked = true;
  1444.                 else if (0 == eff.GetDirection()[0] && -2 == eff.GetDirection()[1])
  1445.                     North.Checked = true;
  1446.                 else if (0 == eff.GetDirection()[0] && 2 == eff.GetDirection()[1])
  1447.                     South.Checked = true;
  1448.                 else if (1 == eff.GetDirection()[0] && -1 == eff.GetDirection()[1])
  1449.                     NorthEast.Checked = true;
  1450.                 else if (1 == eff.GetDirection()[0] && 1 == eff.GetDirection()[1])
  1451.                     SouthEast.Checked = true;
  1452.                 else if (-1 == eff.GetDirection()[0] && 1 == eff.GetDirection()[1])
  1453.                     SouthWest.Checked = true;
  1454.                 else if (-1 == eff.GetDirection()[0] && -1 == eff.GetDirection()[1])
  1455.                     NorthWest.Checked = true;
  1456.                 else if (0 == eff.GetDirection()[0] && 0 == eff.GetDirection()[1])
  1457.                     East.Checked = true;
  1458.             }
  1459.  
  1460.             isChanging = false;
  1461.         }
  1462.         
  1463.         
  1464.         
  1465.         
  1466.         /// <summary>
  1467.         /// Updates the general parameters controls and labels.
  1468.         /// </summary>
  1469.         private void UpdateGeneralParamsGroupBox(Effect eff)
  1470.         {
  1471.             if (((eff.Duration / (int)DI.Seconds) > GeneralDuration.Maximum) || (eff.Duration <  0))
  1472.                 GeneralDuration.Value = GeneralDuration.Maximum;
  1473.             else
  1474.                 GeneralDuration.Value = eff.Duration / (int)DI.Seconds;
  1475.  
  1476.             if (eff.Gain > GeneralGain.Maximum)
  1477.                 GeneralGain.Value = GeneralGain.Maximum;
  1478.             else
  1479.                 GeneralGain.Value = eff.Gain;
  1480.             
  1481.             if (eff.SamplePeriod > GeneralPeriod.Maximum)
  1482.                 GeneralPeriod.Value = GeneralPeriod.Maximum;
  1483.             else
  1484.                 GeneralPeriod.Value = eff.SamplePeriod;
  1485.                      
  1486.             if ((int)DI.Infinite == eff.Duration)
  1487.                 GeneralDurationLabel.Text = "Effect Duration: Infinite";
  1488.             else
  1489.                 GeneralDurationLabel.Text = "Effect Duration: " + (eff.Duration / (int)DI.Seconds) + " seconds";
  1490.             
  1491.             GeneralGainLabel.Text = "Effect Gain: " + GeneralGain.Value;
  1492.  
  1493.             if (0 == eff.SamplePeriod)
  1494.                 GeneralPeriodLabel.Text = "Sample Rate: Default";
  1495.             else 
  1496.                 GeneralPeriodLabel.Text = "Sample Period: " + eff.SamplePeriod;
  1497.  
  1498.         }
  1499.         
  1500.         
  1501.         
  1502.         
  1503.         /// <summary>
  1504.         /// Updates the controls and labels for constant force effects.
  1505.         /// </summary>
  1506.         private void UpdateConstantGroupBox(Effect eff)
  1507.         {
  1508.             ConstantForceMagnitude.Value = eff.Constant.Magnitude;
  1509.             Magnitude.Text = "Constant Force Magnitude: " + ConstantForceMagnitude.Value;
  1510.         }
  1511.         
  1512.         
  1513.         
  1514.         
  1515.         /// <summary>
  1516.         /// Updates the controls and labels for ramp effects.
  1517.         /// </summary>
  1518.         private void UpdateRampGroupBox(Effect eff)
  1519.         {
  1520.             RangeStart.Value = eff.RampStruct.Start;
  1521.             RangeEnd.Value = eff.RampStruct.End; 
  1522.             RangeStartLabel.Text = "Range Start: " + RangeStart.Value;
  1523.             RangeEndLabel.Text = "Range End: " + RangeEnd.Value;
  1524.         }
  1525.         
  1526.         
  1527.         
  1528.         
  1529.         /// <summary>
  1530.         /// Updates the controls and labels for periodic effects.
  1531.         /// </summary>
  1532.         private void UpdatePeriodicGroupBox(Effect eff)
  1533.         {
  1534.             if (eff.Periodic.Magnitude < PeriodicMagnitude.Maximum)
  1535.                 PeriodicMagnitude.Value = eff.Periodic.Magnitude;
  1536.             else
  1537.                 PeriodicMagnitude.Value = PeriodicMagnitude.Maximum;
  1538.  
  1539.             if (eff.Periodic.Offset < PeriodicOffset.Maximum)
  1540.                 PeriodicOffset.Value = eff.Periodic.Offset;
  1541.             else
  1542.                 PeriodicOffset.Value = PeriodicOffset.Maximum;
  1543.             
  1544.             if (eff.Periodic.Period < PeriodicPeriod.Maximum)
  1545.                 PeriodicPeriod.Value = eff.Periodic.Period;
  1546.             else
  1547.                 PeriodicPeriod.Value = PeriodicPeriod.Maximum;
  1548.             
  1549.             if (eff.Periodic.Phase < PeriodicPhase.Maximum)
  1550.                 PeriodicPhase.Value = eff.Periodic.Phase;
  1551.             else
  1552.                 PeriodicPhase.Value = PeriodicPhase.Maximum;
  1553.             
  1554.             PeriodicMagnitudeLabel.Text = "Magnitude: " + PeriodicMagnitude.Value;
  1555.             PeriodicOffsetLabel.Text = "Offset: " + PeriodicOffset.Value;
  1556.             PeriodicPeriodLabel.Text = "Period: " + PeriodicPeriod.Value;
  1557.             PeriodicPhaseLabel.Text = "Phase: " + PeriodicPhase.Value;
  1558.         }
  1559.         
  1560.         
  1561.         
  1562.         
  1563.         /// <summary>
  1564.         /// Updates the controls in the Conditional group box.
  1565.         /// </summary>
  1566.         private void UpdateConditionalGroupBox(Effect eff)
  1567.         {
  1568.             int i;
  1569.  
  1570.             if (true == ConditionalAxis1.Checked)
  1571.                 i = 0;
  1572.             else
  1573.                 i = 1;
  1574.             
  1575.             ConditionalDeadBand.Value = eff.ConditionStruct[i].DeadBand;
  1576.             ConditionalOffset.Value = eff.ConditionStruct[i].Offset;
  1577.             ConditionalNegativeCoeffcient.Value = eff.ConditionStruct[i].NegativeCoefficient;
  1578.             ConditionalNegativeSaturation.Value = eff.ConditionStruct[i].NegativeSaturation;
  1579.             ConditionalPositiveCoefficient.Value = eff.ConditionStruct[i].PositiveCoefficient;
  1580.             ConditionalPositiveSaturation.Value = eff.ConditionStruct[i].PositiveSaturation;
  1581.  
  1582.             ConditionalDeadBandLabel.Text = "Dead Band: " + ConditionalDeadBand.Value;
  1583.             ConditionalOffsetLabel.Text = "Offset: " + ConditionalOffset.Value;
  1584.             ConditionalNegativeCoeffcientLabel.Text = "Negative Coefficient: " + ConditionalNegativeCoeffcient.Value;
  1585.             ConditionalNegativeSaturationLabel.Text = "Negative Saturation: " + ConditionalNegativeSaturation.Value;
  1586.             ConditionalPositiveCoefficientLabel.Text = "Positive Coefficient: " + ConditionalPositiveCoefficient.Value;
  1587.             ConditionalPositiveSaturationLabel.Text = "Positive Saturation: " + ConditionalPositiveSaturation.Value;            
  1588.  
  1589.         }
  1590.         
  1591.         
  1592.         
  1593.         
  1594.         /// <summary>
  1595.         /// Updates the env params group box
  1596.         /// </summary>
  1597.         private void UpdateEnvParamsGroupBox(Effect eff)
  1598.         {
  1599.             chkUseEnvelope.Checked = (eff.UsesEnvelope) ? true: false;
  1600.  
  1601.             if (eff.EnvelopeStruct.AttackLevel > EnvelopeAttackLevel.Maximum)
  1602.                 EnvelopeAttackLevel.Value = EnvelopeAttackLevel.Maximum;
  1603.             else
  1604.                 EnvelopeAttackLevel.Value = eff.EnvelopeStruct.AttackLevel;
  1605.             
  1606.             if (eff.EnvelopeStruct.AttackTime > EnvelopeAttackTime.Maximum)
  1607.                 EnvelopeAttackTime.Value = EnvelopeAttackTime.Maximum;
  1608.             else
  1609.                 EnvelopeAttackTime.Value = eff.EnvelopeStruct.AttackTime;
  1610.             
  1611.             if (eff.EnvelopeStruct.FadeLevel > EnvelopeFadeLevel.Maximum)
  1612.                 EnvelopeFadeLevel.Value = EnvelopeFadeLevel.Maximum;
  1613.             else
  1614.                 EnvelopeFadeLevel.Value = eff.EnvelopeStruct.FadeLevel;
  1615.             
  1616.             if (eff.EnvelopeStruct.FadeTime > EnvelopeFadeTime.Maximum)
  1617.                 EnvelopeFadeTime.Value = EnvelopeFadeTime.Maximum;
  1618.             else
  1619.                 EnvelopeFadeTime.Value = eff.EnvelopeStruct.FadeTime;
  1620.             
  1621.             EnvelopeAttackLevelLabel.Text = "Attack Level: " + eff.EnvelopeStruct.AttackLevel;
  1622.             EnvelopeAttackTimeLabel.Text = "Attack Time: " + eff.EnvelopeStruct.AttackTime / 1000;
  1623.             EnvelopeFadeLevelLabel.Text = "Fade Level: " + eff.EnvelopeStruct.FadeLevel;
  1624.             EnvelopeFadeTimeLabel.Text = "Fade Time: " + eff.EnvelopeStruct.FadeTime / 1000;
  1625.         }
  1626.  
  1627.         
  1628.         
  1629.         
  1630.         /// <summary>
  1631.         /// Handles changing the axis on a conditional effect.
  1632.         /// </summary>
  1633.         private void ConditionalAxisChanged(object sender, System.EventArgs e)
  1634.         {
  1635.             Effect eff = GetEffectParameters();
  1636.             UpdateConditionalGroupBox(eff);
  1637.         
  1638.         }
  1639.  
  1640.         
  1641.         
  1642.         
  1643.         /// <summary>
  1644.         /// Handles the trackbar scroll events for constant effects.
  1645.         /// </summary>
  1646.         private void ConstantForceMagnitudeScroll(object sender, System.EventArgs e)
  1647.         {
  1648.             Effect eff = ChangeParameter();
  1649.             UpdateConstantGroupBox(eff);
  1650.         
  1651.         }
  1652.  
  1653.         
  1654.         
  1655.         
  1656.         /// <summary>
  1657.         /// Handles the trackbar scroll events for ramp effects.
  1658.         /// </summary>
  1659.         private void RangeScroll(object sender, System.EventArgs e)
  1660.         {
  1661.             Effect eff = ChangeParameter();
  1662.             UpdateRampGroupBox(eff);
  1663.         
  1664.         }
  1665.  
  1666.         
  1667.         
  1668.         
  1669.         /// <summary>
  1670.         /// Handles the trackbar scroll events for periodic effects.
  1671.         /// </summary>
  1672.         private void PeriodicScroll(object sender, System.EventArgs e)
  1673.         {
  1674.             Effect eff = ChangeParameter();
  1675.             UpdatePeriodicGroupBox(eff);
  1676.         
  1677.         }
  1678.  
  1679.         
  1680.         
  1681.         
  1682.         /// <summary>
  1683.         /// Handles the trackbar scroll events for conditional effects.
  1684.         /// </summary>
  1685.         private void ConditionalScroll(object sender, System.EventArgs e)
  1686.         {
  1687.             Effect eff = new Effect();
  1688.  
  1689.             if (1 <= axis.Length)
  1690.                 rbConditionalAxis2.Enabled = true;
  1691.             else
  1692.                 rbConditionalAxis2.Enabled = false;
  1693.             
  1694.             eff = ChangeParameter();
  1695.             UpdateConditionalGroupBox(eff);
  1696.         
  1697.         }
  1698.  
  1699.         
  1700.         
  1701.         
  1702.         /// <summary>
  1703.         /// Handles direction changes.
  1704.         /// </summary>
  1705.         private void DirectionChanged(object sender, System.EventArgs e)
  1706.         {
  1707.             int[] direction = new int[2];
  1708.             string[] values;
  1709.  
  1710.             foreach (RadioButton rb in DirectionGroupBox.Controls)
  1711.             {
  1712.                 if (rb.Checked)
  1713.                 {
  1714.                     values = rb.Tag.ToString().Split(',');
  1715.                     direction[0] = Convert.ToInt32(values[0]);
  1716.                     direction[1] = Convert.ToInt32(values[1]);
  1717.                     ChangeDirection(direction);
  1718.                     return;
  1719.                 }
  1720.             }
  1721.         }
  1722.  
  1723.         
  1724.         
  1725.         
  1726.         /// <summary>
  1727.         /// Handles general parameter changes.
  1728.         /// </summary>
  1729.         private void GenScroll(object sender, System.EventArgs e)
  1730.         {
  1731.             Effect eff = GetEffectParameters();
  1732.  
  1733.             if (GeneralDuration.Value == GeneralDuration.Maximum)
  1734.                 eff.Duration = (int)DI.Infinite;
  1735.             else
  1736.                 eff.Duration = GeneralDuration.Value * (int)DI.Seconds;
  1737.             
  1738.             eff.Gain = GeneralGain.Value;
  1739.             eff.SamplePeriod = GeneralPeriod.Value;
  1740.  
  1741.             UpdateGeneralParamsGroupBox(eff);
  1742.             
  1743.             // Some feedback drivers will fail when setting parameters that aren't supported by
  1744.             // an effect. DirectInput will will in turn pass back the driver error to the application.
  1745.             // Since these are hardware specific error messages that can't be handled individually, 
  1746.             // the app will ignore any failures returned to SetParameters().
  1747.             try
  1748.             {
  1749.                 effectSelected.SetParameters(eff, EffectParameterFlags.Duration | EffectParameterFlags.Gain | EffectParameterFlags.SamplePeriod | EffectParameterFlags.Start);
  1750.             }
  1751.             catch(DirectXException){}       
  1752.         }
  1753.  
  1754.         
  1755.         
  1756.         
  1757.         private void EnvChanged(object sender, System.EventArgs e)
  1758.         {
  1759.             Effect eff = new Effect();
  1760.  
  1761.             eff = ChangeEnvelope();
  1762.             UpdateEnvParamsGroupBox(eff);
  1763.         }
  1764.  
  1765.         
  1766.         
  1767.         
  1768.         private void frmMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  1769.         {
  1770.             DestroyObjects();
  1771.         }
  1772.  
  1773.         
  1774.         
  1775.         
  1776.         private void frmMain_Load(object sender, System.EventArgs e)
  1777.         {
  1778.             //Initialize the DirectInput objects
  1779.             if (!InitializeDirectInput())
  1780.                 Close();
  1781.         }
  1782.         
  1783.         
  1784.         
  1785.         
  1786.         /// <summary>
  1787.         /// Destroys all objects.
  1788.         /// </summary>
  1789.         private void DestroyObjects()
  1790.         {
  1791.             if (null == applicationDevice)
  1792.                 return;
  1793.  
  1794.             try
  1795.             {
  1796.                 if (null != effectSelected)
  1797.                     effectSelected.Stop();
  1798.             
  1799.                 foreach (EffectDescription description in lstEffects.Items)
  1800.                 {
  1801.                     if (null != description.effectSelected)
  1802.                         description.effectSelected.Dispose();
  1803.                 }
  1804.  
  1805.                 applicationDevice.Unacquire();
  1806.                 applicationDevice.Properties.AutoCenter = true;
  1807.  
  1808.             }
  1809.             catch(InputException){}
  1810.         }
  1811.  
  1812.         private void frmMain_Activated(object sender, System.EventArgs e)
  1813.         {
  1814.             try
  1815.             {
  1816.                 // Aquire the device
  1817.                 applicationDevice.Acquire();
  1818.             }
  1819.             catch(InputException){}
  1820.  
  1821.             lstEffects_SelectedIndexChanged(null, EventArgs.Empty);
  1822.         }
  1823.     }
  1824. }
  1825.