예제 #1
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);
        }
예제 #2
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);
        }