コード例 #1
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        private void fellipse(V2 c, float rx, float ry)
        {
            if (_graphics == null)
            {
                return;
            }

            RectangleF rect = new RectangleF((float)c.x - rx, (float)c.y - ry, rx * 2, ry * 2);

            _graphics.FillEllipse(_drawBrush, rect);
        }
コード例 #2
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

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

            _radius       = 25f;
            _handleRadius = 5f;

            _dragging = false;
            _hot      = false;
        }
コード例 #3
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        public void tick(V2 pos)
        {
            Graphics        g  = this.Attr.Module.Graphics;
            GraphicsControl gc = this.Attr.Module.GraphicsControl;

            if (g != null && gc != null)
            {
                _transform = g.Transform;
                _pos       = pos;

                gc.AddHandle(this);
            }
        }
コード例 #4
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        private void HandleAttrValueSet(object sender, EventArgs e)
        {
            object newValue = ((Attr)sender).GetValue();

            if (newValue is V2)
            {
                V2 v2 = (V2)newValue;

                _xTextBox.Text = v2.x.ToString();
                _yTextBox.Text = v2.y.ToString();

                Misc.SetCleanColour(_xTextBox, _yTextBox);
            }
        }
コード例 #5
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;
        }
コード例 #6
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);
        }
コード例 #7
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        private void HandleMouseMove(object sender, MouseEventArgs e)
        {
            //_mouseState = new MouseState(e.Location, GetScenePosForLocation(e.Location), e.Button);

            switch (_dragState)
            {
            case DragState.None:
            {
                switch (e.Button)
                {
                case MouseButtons.None:
                {
                    V2 scenePos = GetScenePosForLocation(e.Location);

                    foreach (Handle handle in _handles)
                    {
                        handle.HandleMouseEvent(sender, e, scenePos);
                    }
                }
                break;

                case MouseButtons.Left:
                {
                    V2 scenePos = GetScenePosForLocation(e.Location);

                    foreach (Handle handle in _handles)
                    {
                        if (handle.HandleMouseEvent(sender, e, scenePos))
                        {
                            _dragState  = DragState.Handle;
                            _dragHandle = handle;
                            break;
                        }
                    }
                }
                break;

                case MouseButtons.Middle:
                {
                    _dragControlPos = e.Location;
                    _dragScenePos   = GetScenePosForLocation(e.Location);

                    if ((Control.ModifierKeys & Keys.Alt) != 0)
                    {
                        _dragState = DragState.Translate;
                    }
                    else if ((Control.ModifierKeys & Keys.Control) != 0)
                    {
                        _dragState = DragState.Rotate;
                    }
                }
                break;
                }
            }
            break;

            case DragState.Rotate:
            {
                if ((e.Button & MouseButtons.Middle) != 0)
                {
                    float theta = (float)((e.Location.X - _dragControlPos.X) / 10.0 * Math.PI);

                    _matrix.RotateAt(theta, _dragScenePos.AsPointF());

                    _dragControlPos = e.Location;

                    Invalidate();
                }
                else
                {
                    _dragState = DragState.None;
                }
            }
            break;

            case DragState.Translate:
            {
                if ((e.Button & MouseButtons.Middle) != 0)
                {
                    _matrix.Translate(e.Location.X - _dragControlPos.X, e.Location.Y - _dragControlPos.Y, MatrixOrder.Append);

                    _dragControlPos = e.Location;

                    Invalidate();
                }
                else
                {
                    _dragState = DragState.None;
                }
            }
            break;

            case DragState.Handle:
            {
                _dragHandle.HandleMouseEvent(sender, e, GetScenePosForLocation(e.Location));

                if ((e.Button & MouseButtons.Left) == 0)
                {
                    _dragHandle = null;

                    _dragState = DragState.None;
                }
            }
            break;
            }
        }
コード例 #8
0
ファイル: Handle.cs プロジェクト: resonancellc/PyDoodle
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        public abstract bool HandleMouseEvent(object sender, MouseEventArgs mea, V2 mouseScenePos);
コード例 #9
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);
        }
コード例 #10
0
 public static double dot(V2 a, V2 b)
 {
     return(a.x * b.x + a.y * b.y);
 }
コード例 #11
0
 public static V2 Max(V2 a, V2 b)
 {
     return(new V2(Math.Max(a.x, b.y), Math.Max(a.y, b.y)));
 }
コード例 #12
0
        //         public PointF GetPointF()
        //         {
        //             return new PointF((float)x, (float)y);
        //         }

        //         public SizeF GetSizeF()
        //         {
        //             return new SizeF((float)x, (float)y);
        //         }

        public static V2 lerp(V2 a, V2 b, float t)
        {
            return(new V2(a.x + t * (b.x - a.x), a.y + t * (b.y - a.y)));
        }
コード例 #13
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        private RectangleF GetBoxRect(V2 a, V2 b)
        {
            V2 d = b - a;

            return(new RectangleF((float)Math.Min(a.x, b.x), (float)Math.Min(a.y, b.y), (float)Math.Abs(d.x), (float)Math.Abs(d.y)));
        }
コード例 #14
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        private void fcircle(V2 c, float r)
        {
            fellipse(c, r, r);
        }
コード例 #15
0
        //-///////////////////////////////////////////////////////////////////////
        //-///////////////////////////////////////////////////////////////////////

        private void fcirclearc(V2 c, float r, float theta0, float theta1)
        {
            fellipsearc(c, r, r, theta0, theta1);
        }