Beispiel #1
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Adds tweaks as appropriate for the given list of attributes.
        /// </summary>
        /// <param name="attrs"></param>
        private void tweaks(Attr[] attrs)
        {
            for (int i = 0; i < attrs.Length; ++i)
            {
                Attr attr = attrs[i];

                TweakControl tweakControl = null;

                object attrValue = attr.GetValue();

                // Check...
                if (attrValue is string)
                {
                    tweakControl = new TweakStringControl(attr);
                }
                else if (attrValue is V2)
                {
                    tweakControl = new TweakV2Control(attr);
                }
                else if (attrValue is float || attrValue is double)
                {
                    tweakControl = new TweakFloatControl(attr);
                }
                else
                {
                    throw new ArgumentException(string.Format("Attr {0} - no tweaker for type {1}.", attr.Name, attrValue.GetType()));
                }

                _mainForm.TweaksPanel.AddTweakControl(tweakControl);
            }
        }
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        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;
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }