예제 #1
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        public override void Draw(Graphics g)
        {
            if (_transform == null)
            {
                return;
            }

            PointF screenPos = Misc.TransformPoint(_transform, (V2)this.Attr.GetValue()).AsPointF();

            GraphicsState gs = g.Save();

            g.ResetClip();
            g.ResetTransform();

            Color colour;

            if (_hot)
            {
                colour = Color.LightGray;
            }
            else
            {
                colour = Color.Black;
            }

            colour = Color.FromArgb(128, colour.R, colour.G, colour.B);

            g.FillEllipse(new SolidBrush(colour), screenPos.X - _radius, screenPos.Y - _radius, _radius * 2, _radius * 2);

            g.Restore(gs);
        }
예제 #2
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        private void text(V2 pos, string text)
        {
            if (_graphics == null)
            {
                return;
            }

            Matrix oldTransform = _graphics.Transform;

            _graphics.Transform = identityMatrix;

            V2 screenPos = Misc.TransformPoint(oldTransform, pos);

            _graphics.DrawString(text, SystemFonts.DefaultFont, _drawBrush, screenPos.AsPointF());

            _graphics.Transform = oldTransform;
        }
예제 #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);
        }
예제 #4
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        public override bool HandleMouseEvent(object sender, MouseEventArgs mea, V2 mouseScenePos)
        {
            if (_transform == null)
            {
                _dragging = false;
                return(false);
            }

            V2 mouseScreenPos = new V2(mea.Location.X, mea.Location.Y);

            bool hover = false;
            V2   delta = V2.V00;

            if (!_dragging)
            {
                V2 screenPos = Misc.TransformPoint(_transform, (V2)this.Attr.GetValue());

                delta = screenPos - mouseScreenPos;

                if (delta.lensq() < _radius * _radius)
                {
                    hover = true;
                }
            }

            if ((mea.Button & MouseButtons.Left) != 0)
            {
                if (!_dragging)
                {
                    if (hover)
                    {
                        _dragDelta = delta;
                        _dragging  = true;
                    }
                }
                else
                {
                    Matrix invTransform = _transform.Clone();
                    invTransform.Invert();

                    V2 screenPos = mouseScreenPos + _dragDelta;
                    V2 scenePos  = Misc.TransformPoint(invTransform, screenPos);

                    this.Attr.SetValue(scenePos);
                }
            }
            else
            {
                _dragging = false;
            }

            if (hover)
            {
                _hot = true;
            }
            else if (_dragging)
            {
                _hot = true;
            }
            else
            {
                _hot = false;
            }

            return(_dragging);
        }