using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VisiMath;

namespace VisimBuilder.ObjectCreation
{
    public partial class PhysSettingsEdit : UserControl
    {
        public PhysSettingsEdit()
        {
            InitializeComponent();
        }

        public float Mass
        {
            get
            {
                return (float)numericUpDownMass.Value;
            }
            set
            {
                numericUpDownMass.Value = (decimal)value;
            }
        }

        public bool Sleeping
        {
            get
            {
                return checkBoxSleeping.Checked;
            }

            set
            {
                checkBoxSleeping.Checked = value;
            }
        }

        protected bool _staystatic;
        public bool StayStatic
        {
            get {return _staystatic;}
            set
            {
                _staystatic = value;
                if (value)
                    checkBoxStatic.Enabled = false;
                else
                    checkBoxStatic.Enabled = true;
            }
        }

        public bool StaticCol
        {
            get
            {
                return checkBoxStatic.Checked;
            }

            set
            {
                if (!value && StayStatic)
                    return;
                checkBoxStatic.Checked = value;

                
                checkBoxSleeping.Enabled = ! value;
                checkBoxGravity.Enabled = !value;
                numericUpDownMass.Enabled = !value;
                numericUpDownDamping.Enabled = !value;
                numericUpDownAngDamping.Enabled = ! value;
                vectorEditingAcc.Enabled = !value;
                vectorEditingAngular.Enabled = !value;
                vectorEditingAngularAcc.Enabled = !value;
                vectorEditingVelocity.Enabled = !value;

            }
        }

        public bool GravityEnabled
        {
            get
            {
                return checkBoxGravity.Checked;
            }
            set
            {
                checkBoxGravity.Checked = value;
            }
        }

        public float StaticFriction
        {
            get
            {
                return (float)numericUpDownStatic.Value;
            }

            set
            {
                MathTools.Clamp(ref value, 0, 1);
                numericUpDownStatic.Value = (decimal)value;
            }
        }

        public float DynamicFriction
        {
            get
            {
                return (float)numericUpDownDynamic.Value;
            }

            set
            {
                MathTools.Clamp(ref value, 0, 1);
                numericUpDownDynamic.Value = (decimal)value;
            }
        }

        public float Restitution
        {
            get
            {
                return (float)numericUpDownRestitution.Value;
            }

            set
            {
                MathTools.Clamp(ref value, 0, 1);
                numericUpDownRestitution.Value = (decimal)value;
            }
        }

        public float Damping
        {
            get
            {
                return (float)numericUpDownDamping.Value;
            }

            set
            {
                MathTools.Clamp(ref value, 0, 1);
                numericUpDownDamping.Value = (decimal)value;
            }
        }

        public float AngDamping
        {
            get
            {
                return (float)numericUpDownAngDamping.Value;
            }

            set
            {
                MathTools.Clamp(ref value, 0, 1);
                numericUpDownAngDamping.Value = (decimal)value;
            }
        }

        public Vector3 Velocity
        {
            get
            {
                return vectorEditingVelocity.EditedVector;
            }

            set
            {
                vectorEditingVelocity.EditedVector = value;
            }
        }


        public Vector3 Acceleration
        {
            get
            {
                return vectorEditingAcc.EditedVector;
            }

            set
            {
                vectorEditingAcc.EditedVector = value;
            }
        }

        public Vector3 AngularVelocity
        {
            get
            {
                return vectorEditingAngular.EditedVector;
            }

            set
            {
                vectorEditingAngular.EditedVector = value;
            }
        }

        public Vector3 AngularAcceleration
        {
            get
            {
                return vectorEditingAngularAcc.EditedVector;
            }

            set
            {
                vectorEditingAngularAcc.EditedVector = value;
            }
        }


    }
}
