コード例 #1
0
ファイル: PropertyPanel.cs プロジェクト: AsehesL/RayTracer
            private void OnPositionChanged(object sender, int axis)
            {
                double x = 0, y = 0, z = 0;

                if (type == VectorPropertyType.Vector2)
                {
                    RayTracerNet.Vector2 vector = (RayTracerNet.Vector2)property.GetValue(propertyTarget);
                    x = vector.x;
                    y = vector.y;
                }
                else if (type == VectorPropertyType.Vector3)
                {
                    RayTracerNet.Vector3 vector = (RayTracerNet.Vector3)property.GetValue(propertyTarget);
                    x = vector.x;
                    y = vector.y;
                    z = vector.z;
                }
                TextBox textBox = sender as TextBox;

                try
                {
                    double num = double.Parse(textBox.Text);
                    if (axis == 0)
                    {
                        x = num;
                    }
                    else if (axis == 1)
                    {
                        y = num;
                    }
                    else
                    {
                        z = num;
                    }
                    if (type == VectorPropertyType.Vector2)
                    {
                        RayTracerNet.Vector2 vector = new Vector2(x, y);
                        property.SetValue(propertyTarget, vector);
                    }
                    else if (type == VectorPropertyType.Vector3)
                    {
                        RayTracerNet.Vector3 vector = new Vector3(x, y, z);
                        property.SetValue(propertyTarget, vector);
                    }
                    return;
                }
                catch (System.Exception exp)
                {
                    if (axis == 0)
                    {
                        textBox.Text = x.ToString();
                    }
                    else if (axis == 1)
                    {
                        textBox.Text = y.ToString();
                    }
                    else
                    {
                        textBox.Text = z.ToString();
                    }
                }
            }
コード例 #2
0
ファイル: PropertyPanel.cs プロジェクト: AsehesL/RayTracer
            public override int SetProperty(object propertyTarget, PropertyInfo property, Attribute attribute, int height)
            {
                this.property       = property;
                this.propertyTarget = propertyTarget;
                this.type           = ((RayTracerNet.VectorPropertyDisplayAttribute)attribute).type;

                double x = 0, y = 0, z = 0;

                if (type == VectorPropertyType.Vector2)
                {
                    RayTracerNet.Vector2 vector = (RayTracerNet.Vector2)property.GetValue(propertyTarget);
                    x = vector.x;
                    y = vector.y;
                }
                else if (type == VectorPropertyType.Vector3)
                {
                    RayTracerNet.Vector3 vector = (RayTracerNet.Vector3)property.GetValue(propertyTarget);
                    x = vector.x;
                    y = vector.y;
                    z = vector.z;
                }

                this.propertyNameLabel.Visible  = true;
                this.propertyNameLabel.Location = new System.Drawing.Point(7, height + 6);
                this.propertyNameLabel.Name     = "positionLabel_" + propertyTarget.GetHashCode();
                this.propertyNameLabel.Size     = new System.Drawing.Size(53, 12);
                this.propertyNameLabel.Text     = ((RayTracerNet.VectorPropertyDisplayAttribute)attribute).propertyName + ":";

                this.propertyXLabel.Visible  = true;
                this.propertyXLabel.Location = new System.Drawing.Point(20, height + 28);
                this.propertyXLabel.Name     = "positionXLabel_" + propertyTarget.GetHashCode();
                this.propertyXLabel.Size     = new System.Drawing.Size(11, 12);
                this.propertyXLabel.Text     = "X";

                this.propertyYLabel.Visible  = true;
                this.propertyYLabel.Location = new System.Drawing.Point(90, height + 28);
                this.propertyYLabel.Name     = "positionYLabel_" + propertyTarget.GetHashCode();
                this.propertyYLabel.Size     = new System.Drawing.Size(11, 12);
                this.propertyYLabel.Text     = "Y";

                if (((RayTracerNet.VectorPropertyDisplayAttribute)attribute).type == VectorPropertyType.Vector3)
                {
                    this.propertyZLabel.Visible  = true;
                    this.propertyZLabel.Location = new System.Drawing.Point(160, height + 28);
                    this.propertyZLabel.Name     = "positionZLabel_" + propertyTarget.GetHashCode();
                    this.propertyZLabel.Size     = new System.Drawing.Size(11, 12);
                    this.propertyZLabel.Text     = "Z";
                }
                else
                {
                    this.propertyZLabel.Visible = false;
                }

                this.propertyXTextBox.Visible  = true;
                this.propertyXTextBox.Location = new System.Drawing.Point(35, height + 24);
                this.propertyXTextBox.Name     = "positionXTextBox_" + propertyTarget.GetHashCode();
                this.propertyXTextBox.Size     = new System.Drawing.Size(52, 21);
                this.propertyXTextBox.Text     = x.ToString();

                this.propertyYTextBox.Visible  = true;
                this.propertyYTextBox.Location = new System.Drawing.Point(105, height + 24);
                this.propertyYTextBox.Name     = "positionYTextBox_" + propertyTarget.GetHashCode();
                this.propertyYTextBox.Size     = new System.Drawing.Size(52, 21);
                this.propertyYTextBox.Text     = y.ToString();

                if (((RayTracerNet.VectorPropertyDisplayAttribute)attribute).type == VectorPropertyType.Vector3)
                {
                    this.propertyZTextBox.Visible  = true;
                    this.propertyZTextBox.Location = new System.Drawing.Point(175, height + 24);
                    this.propertyZTextBox.Name     = "positionZTextBox_" + propertyTarget.GetHashCode();
                    this.propertyZTextBox.Size     = new System.Drawing.Size(52, 21);
                    this.propertyZTextBox.Text     = z.ToString();
                }
                else
                {
                    this.propertyZTextBox.Visible = false;
                }

                return(height + 50);
            }