Example #1
0
        /// <summary>
        /// Returns list of Attr, one for each mentioned attribute on the given
        /// object.
        /// </summary>
        /// <param name="pyobj"></param>
        /// <param name="names"></param>
        /// <returns></returns>
        private Attr[] attrs(object pyobj, params string[] names)
        {
            Attr[] attrs = new Attr[names.Length];

            for (int i = 0; i < names.Length; ++i)
            {
                attrs[i] = attr(pyobj, names[i]);
            }

            return(attrs);
        }
Example #2
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        public TweakStringControl(Attr attr = null)
            : base(attr)
        {
            InitializeComponent();

            _textBox.TextChanged += HandleTextBoxDirty;

            EnterPressed += HandleScriptValueDirty;

            AddAttrValueSetHandler(HandleAttrValueSet);
        }
Example #3
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        public RotateHandle(Attr attr)
            : base(attr)
        {
            _transform = null;
            _pos       = V2.V00;

            _radius       = 25f;
            _handleRadius = 5f;

            _dragging = false;
            _hot      = false;
        }
Example #4
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        public bool IsEquivalent(Attr rhs)
        {
            if (!object.ReferenceEquals(_pyobj, rhs._pyobj))
            {
                return(false);
            }

            if (_name != rhs._name)
            {
                return(false);
            }

            return(true);
        }
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        private void HandleScriptValueDirty(object sender, System.EventArgs e)
        {
            double value;

            if (double.TryParse(_textBox.Text, out value))
            {
                Attr.SilentSetValue(_isFloat ? (float)value : value);

                Misc.SetCleanColour(_textBox);
            }
            else
            {
                Misc.SetBadColour(_textBox);
            }
        }
Example #6
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        private void HandleScriptValueDirty(object sender, System.EventArgs e)
        {
            double x, y;

            bool goodX = double.TryParse(_xTextBox.Text, out x);
            bool goodY = double.TryParse(_yTextBox.Text, out y);

            if (goodX && goodY)
            {
                Attr.SilentSetValue(new V2(x, y));

                Misc.SetCleanColour(_xTextBox, _yTextBox);
            }
            else
            {
                Misc.SetBadColour(goodX ? null : _xTextBox, goodY ? null : _yTextBox);
            }
        }
Example #7
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        public TranslateHandle(Attr attr)
            : base(attr)
        {
            if (attr == null)
            {
                throw new ArgumentNullException("Attr for TranslateHandle may not be null.");
            }

            if (!(attr.GetValue() is V2))
            {
                throw new ArgumentException("Attr for TranslateHandle must be V2, not " + attr.GetValue().GetType());
            }

            _radius    = 10;//in pixels.
            _transform = null;
            _dragging  = false;
            _hot       = false;
        }
Example #8
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        public TweakV2Control(Attr attr = null)
            : base(attr)
        {
            InitializeComponent();

            _xTextBox.TextChanged += HandleTextBoxTextChanged;
            _yTextBox.TextChanged += HandleTextBoxTextChanged;

            FloatMouseDragHandler fmdh = new FloatMouseDragHandler(.1f);

            fmdh.TextBoxChanged += HandleScriptValueDirty;

            _xTextBox.MouseMove += fmdh.HandleMouseMove;
            _yTextBox.MouseMove += fmdh.HandleMouseMove;

            EnterPressed += HandleScriptValueDirty;

            AddAttrValueSetHandler(HandleAttrValueSet);
        }
Example #9
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        public override bool HandleMouseEvent(object sender, MouseEventArgs mea, V2 mouseScenePos)
        {
            _hot = false;

            PointF screenPos, handlePos;
            double thetaOffset;

            if (GetPositions(out screenPos, out handlePos, out thetaOffset))
            {
                if (Misc.ArePointsCloser(mea.Location, handlePos, _handleRadius))
                {
                    _hot = true;
                }
            }

            if ((mea.Button & MouseButtons.Left) != 0)
            {
                if (_dragging)
                {
                    float dx = (float)mea.Location.X - screenPos.X;
                    float dy = (float)mea.Location.Y - screenPos.Y;

                    Attr.SetValue(Math.Atan2(dy, dx) - thetaOffset);
                }
                else
                {
                    if (_hot)
                    {
                        _dragging = true;
                    }
                }
            }
            else
            {
                _dragging = false;
            }

            return(false);
        }
Example #10
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        private bool GetPositions(out PointF screenPos, out PointF handlePos, out double thetaOffset)
        {
            screenPos   = PointF.Empty;
            handlePos   = PointF.Empty;
            thetaOffset = 0.0;

            if (_transform == null)
            {
                return(false);
            }

            screenPos = Misc.TransformPoint(_transform, _pos).AsPointF();

            double theta = Convert.ToDouble(Attr.GetValue());

            float[] elements = _transform.Elements;
            thetaOffset = Math.Atan2(elements[1], elements[0]);

            handlePos = new PointF((float)(screenPos.X + Math.Cos(theta + thetaOffset) * _radius),
                                   (float)(screenPos.Y + Math.Sin(theta + thetaOffset) * _radius));

            return(true);
        }
Example #11
0
 public TweakControl(Attr attr)
 {
     _attr = attr;
 }
Example #12
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        public Handle(Attr attr)
        {
            _attr = attr;
        }
Example #13
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        private void HandleScriptValueDirty(object sender, System.EventArgs e)
        {
            Attr.SilentSetValue(_textBox.Text);

            Misc.SetCleanColour(_textBox);
        }
Example #14
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// returns Attr for the given attribute on the given object.
        /// </summary>
        /// <param name="pyobj"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private Attr attr(object pyobj, string name)
        {
            Attr newAttr = new Attr(this, pyobj, name);

            foreach (Attr attr in _attrPool)
            {
                if (attr.IsEquivalent(newAttr))
                {
                    return(attr);
                }
            }

            _attrPool.Add(newAttr);

            // Got an equivalent in the saved attributes list?
            if (_savedAttrValues != null)
            {
                Type   valueType = null;
                object value     = newAttr.GetValue();
                if (value != null)
                {
                    valueType = value.GetType();
                }

                int index = -1;

                for (int i = 0; i < _savedAttrValues.Count; ++i)
                {
                    SavedAttrValue sav = _savedAttrValues[i];

                    if (sav.Name == name)
                    {
                        Type savedType = null;
                        if (sav.Value != null)
                        {
                            savedType = sav.Value.GetType();
                        }

                        bool match = false;

                        if (valueType == savedType)
                        {
                            match = true;
                        }
                        else if ((valueType == typeof(float) || valueType == typeof(double)) &&
                                 (savedType == typeof(float) || savedType == typeof(double)))
                        {
                            // float, double, float, double... *shrug*
                            match = true;
                        }

                        if (match)
                        {
                            index = i;
                            break;
                        }
                    }
                }

                if (index >= 0)
                {
                    newAttr.SetValue(_savedAttrValues[index].Value);

                    _savedAttrValues.RemoveAt(index);
                }
            }

            return(newAttr);
        }