Ejemplo n.º 1
0
        private void addStandardParameterButton_Click(object sender, EventArgs e)
        {
            EffectParameterDefinition param =
                (EffectParameterDefinition)standardParametersList.SelectedItem;

            mEffectDefinition.Parameters.Add(param);

            effectParametersList.Parameters = mEffectDefinition.Parameters;
            UpdateStandardParameters();
        }
        public void AddParameter(EffectParameterDefinition param)
        {
            mParameters.Add(param);
            mParameters.Sort();

            UpdateList();

            parameterListBox.SelectedItem = param;

            DoParametersChanged();
        }
        private void UpdateList()
        {
            int selectIndex      = parameterListBox.SelectedIndex;
            int nameSelectStart  = paramNameBox.SelectionStart;
            int nameSelectLength = paramNameBox.SelectionLength;

            if (selectIndex >= 0 && parameterListBox.Items.Count > 0)
            {
                EffectParameterDefinition param = mParameters[parameterListBox.SelectedIndex];
                mParameters.Sort();
                selectIndex = mParameters.IndexOf(param);
            }

            parameterListBox.DataSource = null;
            parameterListBox.DataSource = mParameters;

            if (selectIndex >= 0 && parameterListBox.Items.Count > 0)
            {
                parameterListBox.SelectedIndex = selectIndex;
                paramNameBox.SelectionStart    = nameSelectStart;
                paramNameBox.SelectionLength   = nameSelectLength;
            }
        }
        public void EditParameter(EffectParameterDefinition param)
        {
            // populate the editing panel
            paramNameBox.Text         = param.Name;
            paramTypeBox.SelectedItem = param.Type.Type.ToString();

            if (param.Name != HlslType.Texture.ToString())
            {
                if (param.Type.IsVector)
                {
                    paramTypeSizeBox.SelectedItem = "Vector";
                    paramTypeSizeA.Value          = param.Type.Size;
                }
                else if (param.Type.IsArray)
                {
                    paramTypeSizeBox.SelectedItem = "Array";
                    paramTypeSizeA.Value          = param.Type.Size;
                }
                else if (param.Type.IsMatrix)
                {
                    paramTypeSizeBox.SelectedItem = "Matrix";
                    paramTypeSizeA.Value          = param.Type.Size;
                    paramTypeSizeB.Value          = param.Type.MatrixColumns;
                }
                else
                {
                    paramTypeSizeBox.SelectedItem = "Scalar";
                }
            }

            bool semanticChanged = false;

            if (mSemanticEnabled)
            {
                if (param.Semantic.Name == null || param.Semantic.Name == String.Empty)
                {
                    param.Semantic = mSemantics[0];
                    param.Semantic.ResourceNumber = 0;
                    semanticChanged = true;
                }

                // Find the index to select
                int index = -1;
                if (semanticBox.Items.Contains(param.Semantic))
                {
                    index = semanticBox.Items.IndexOf(param.Semantic);
                }
                else
                {
                    for (int i = 0; i < semanticBox.Items.Count; i++)
                    {
                        if (param.Semantic.Name.Equals(((HlslSemantic)semanticBox.Items[i]).Name))
                        {
                            index = i;
                        }
                    }
                }
                if (index == -1)
                {
                    index = 0;
                }

                semanticBox.SelectedIndex = index;
            }

            if (mStorageClassEnabled)
            {
                storageClassBox.Text = (param.StorageClass == StorageClass.None) ?
                                       String.Empty : param.StorageClass.ToString();
            }

            if (semanticChanged)
            {
                EditParameter(parameterListBox.SelectedIndex);
            }
        }
        /// <summary>
        /// Edits the parameter in the list with the selected index
        /// </summary>
        #endregion
        private void EditParameter(int index)
        {
            // updates the parameter in the list
            EffectParameterDefinition param = (EffectParameterDefinition)mParameters[index];

            param.Name      = paramNameBox.Text;
            param.Type.Type = (HlslType)Enum.Parse(typeof(HlslType), (string)paramTypeBox.SelectedItem);

            if (param.Type.Type == HlslType.Texture || (string)paramTypeSizeBox.SelectedItem == "Scalar")
            {
                param.Type.IsVector = false;
                param.Type.IsArray  = false;
                param.Type.IsMatrix = false;
            }
            else if ((string)paramTypeSizeBox.SelectedItem == "Vector")
            {
                param.Type.IsVector = true;
                param.Type.IsArray  = false;
                param.Type.IsMatrix = false;
                param.Type.Size     = (int)paramTypeSizeA.Value;
            }
            else if ((string)paramTypeSizeBox.SelectedItem == "Array")
            {
                param.Type.IsVector = false;
                param.Type.IsArray  = true;
                param.Type.IsMatrix = false;
                param.Type.Size     = (int)paramTypeSizeA.Value;
            }
            else if ((string)paramTypeSizeBox.SelectedItem == "Matrix")
            {
                param.Type.IsVector      = false;
                param.Type.IsArray       = false;
                param.Type.IsMatrix      = true;
                param.Type.Size          = (int)paramTypeSizeA.Value;
                param.Type.MatrixColumns = (int)paramTypeSizeB.Value;
            }

            // semantic
            param.HasSemantic = mSemanticEnabled;
            if (mSemanticEnabled)
            {
                param.Semantic = mSemantics[semanticBox.SelectedIndex];
                param.Semantic.ResourceNumber = (int)semanticNumberBox.Value;
            }

            // storage class
            param.HasStorageClass = mStorageClassEnabled;
            if (mStorageClassEnabled)
            {
                if (storageClassBox.SelectedItem == null || storageClassBox.SelectedText == String.Empty)
                {
                    param.StorageClass = StorageClass.None;
                }
                else
                {
                    param.StorageClass = (StorageClass)Enum.Parse(typeof(StorageClass), storageClassBox.SelectedText, true);
                }
            }

            mParameters[index] = param;

            UpdateList();

            parameterListBox.SelectedItem = param;
        }