예제 #1
0
        private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            x = Convert.ToInt32((e.X - p.StagePos.X) / p.dpi);
            y = Convert.ToInt32((e.Y - p.StagePos.Y) / p.dpi);

            //hittest states
            hitState = stateList.FirstOrDefault(x => x.Bounds.Contains(new Point(this.x, this.y)));

            #region drag bezier handles
            if (dragState != null && e.Button == MouseButtons.Left)
            {
                //FLogger.Log(LogType.Debug, "bezierHandleStart");
                Lines.EdgePoints myEdgePoints = Lines.GetEdgePoints(State.Center(p.bezierEdit.highlightTransition.startState.Bounds), State.Center(p.bezierEdit.highlightTransition.endState.Bounds), 40, 40, 0.0);
                if (dragState == "bezierStart")
                {
                    p.bezierEdit.highlightTransition.startBezierPoint = new Point(this.x - myEdgePoints.A.X, this.y - myEdgePoints.A.Y);
                }
                if (dragState == "bezierEnd")
                {
                    p.bezierEdit.highlightTransition.endBezierPoint = new Point(this.x - myEdgePoints.B.X, this.y - myEdgePoints.B.Y);
                }
            }
            #endregion

            #region drag states
            if (selectedState == null && e.Button == MouseButtons.Right)
            {
                Point mousePos = MousePosition;
                int   deltaX   = (mousePos.X - previousPosition.X);
                int   deltaY   = (mousePos.Y - previousPosition.Y);
                previousPosition = MousePosition;
                p.StagePos.X    += deltaX;
                p.StagePos.Y    += deltaY;
            }

            if (selectedState != null && e.Button == MouseButtons.Left && dragState == null)
            {
                selectedState.Move(new Point(Convert.ToInt32(e.X / p.dpi) - (p.StateSize / 2) - Convert.ToInt32(p.StagePos.X / p.dpi), Convert.ToInt32(e.Y / p.dpi) - (p.StateSize / 2) - Convert.ToInt32(p.StagePos.Y / p.dpi)));
            }

            #endregion

            #region startConnection

            if (startConnectionState != null && hitState != null)
            {
                targetConnectionState = hitState;
            }
            else
            {
                targetConnectionState = null;
            }
            #endregion

            this.Invalidate(); //redraw
        }
예제 #2
0
        private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            bool redraw = false;

            x = Convert.ToInt32((e.X - p.StagePos.X) / p.dpi);
            y = Convert.ToInt32((e.Y - p.StagePos.Y) / p.dpi);

            //hittest states
            hitState = stateList.FirstOrDefault(x => x.Bounds.Contains(new Point(this.x, this.y)));

            #region drag bezier handles
            if (dragState != null && e.Button == MouseButtons.Left)
            {
                //FLogger.Log(LogType.Debug, "bezierHandleStart");
                Lines.EdgePoints myEdgePoints = Lines.GetEdgePoints(State.Center(p.bezierEdit.highlightTransition.startState.Bounds), State.Center(p.bezierEdit.highlightTransition.endState.Bounds), 40, 40, 0.0);
                if (dragState == "bezierStart")
                {
                    p.bezierEdit.highlightTransition.startBezierPoint = new Point(this.x - myEdgePoints.A.X, this.y - myEdgePoints.A.Y);
                }
                if (dragState == "bezierEnd")
                {
                    p.bezierEdit.highlightTransition.endBezierPoint = new Point(this.x - myEdgePoints.B.X, this.y - myEdgePoints.B.Y);
                }
                redraw = true;
            }
            #endregion

            #region drag things

            //drag stage
            if (selectedState == null && e.Button == MouseButtons.Right)
            {
                Point mousePos = MousePosition;
                int   deltaX   = (mousePos.X - previousPosition.X);
                int   deltaY   = (mousePos.Y - previousPosition.Y);
                previousPosition = MousePosition;
                p.StagePos.X    += deltaX;
                p.StagePos.Y    += deltaY;
                redraw           = true;
            }

            //drag state
            if (selectedState != null && Form.ModifierKeys != Keys.Control && e.Button == MouseButtons.Left && dragState == null)
            {
                selectedState.Move(new Point(Convert.ToInt32(e.X / p.dpi) - (p.StateSize / 2) - Convert.ToInt32(p.StagePos.X / p.dpi), Convert.ToInt32(e.Y / p.dpi) - (p.StateSize / 2) - Convert.ToInt32(p.StagePos.Y / p.dpi)));
                redraw = true;
            }

            //drag region
            if (selectedState == null && Form.ModifierKeys != Keys.Control && hitRegion != null && e.Button == MouseButtons.Left && hitsizeHandle == null && dragState == null)
            {
                Point mousePos = MousePosition;
                int   deltaX   = (mousePos.X - previousPosition.X);
                int   deltaY   = (mousePos.Y - previousPosition.Y);
                previousPosition     = MousePosition;
                hitRegion.Bounds     = new Rectangle(hitRegion.Bounds.X + deltaX, hitRegion.Bounds.Y + deltaY, hitRegion.Bounds.Width, hitRegion.Bounds.Height);
                hitRegion.SizeHandle = new Rectangle(hitRegion.SizeHandle.X + deltaX, hitRegion.SizeHandle.Y + deltaY, 10, 10);
                redraw = true;
            }

            //drag size

            if (e.Button == MouseButtons.Left && hitsizeHandle != null)
            {
                Point mousePos = MousePosition;
                int   deltaX   = (mousePos.X - previousPosition.X);
                int   deltaY   = (mousePos.Y - previousPosition.Y);
                previousPosition = MousePosition;


                int sizeX = hitsizeHandle.SizeHandle.X + deltaX;
                int sizeY = hitsizeHandle.SizeHandle.Y + deltaY;

                if ((sizeX - hitsizeHandle.Bounds.X + 10) < 100)
                {
                    sizeX = hitsizeHandle.Bounds.X + 90;
                }
                if ((sizeY - hitsizeHandle.Bounds.Y + 10) < 100)
                {
                    sizeY = hitsizeHandle.Bounds.Y + 90;
                }

                hitsizeHandle.SizeHandle = new Rectangle(sizeX, sizeY, 10, 10);
                hitsizeHandle.Bounds     = new Rectangle(hitsizeHandle.Bounds.X, hitsizeHandle.Bounds.Y, sizeX - hitsizeHandle.Bounds.X + 10, sizeY - hitsizeHandle.Bounds.Y + 10);
                redraw = true;
            }


            #endregion

            #region startConnection

            if (startConnectionState != null)
            {
                redraw = true;
            }

            if (startConnectionState != null && hitState != null)
            {
                targetConnectionState = hitState;
            }
            else
            {
                targetConnectionState = null;
            }
            #endregion

            SetSelectionRectangle(e);

            //redraw
            if (redraw)
            {
                this.Invalidate();
            }
        }