Example #1
0
        private void BezierContainer_MouseMove(object sender, MouseEventArgs e)
        {
            Point temp = new Point();

            temp.X = Control.MousePosition.X;
            temp.Y = Control.MousePosition.Y;

            temp.X -= BezierContainer.Left;
            temp.Y -= BezierContainer.Top;

            temp = PointToClient(temp);

            // System.Console.Out.WriteLine("Pos : " + temp.X + "," + temp.Y);

            if (isDown)
            {
                Point mapPoint = new Point(BezierContainer.Left, BezierContainer.Top);

                mapPoint = PointToScreen(mapPoint);

                Rectangle rect = new Rectangle(mapPoint.X, mapPoint.Y, BezierContainer.Width, BezierContainer.Height);

                Cursor.Clip = rect;

                currentDistance += distanceTo(temp, currentPos);

                if (currentDistance >= halfDis && !isMiddle)
                {
                    midPoint = new Point(temp.X, temp.Y);
                    isMiddle = true;
                }
                else if (currentDistance >= 2 * halfDis && isMiddle)
                {
                    p3 = temp;

                    p2 = getSecondPoint(midPoint, p1, p3);

                    Bezier bezier = new Bezier(p1, p2, p3);

                    currentDistance = 0;

                    p1 = new Point(p3.X, p3.Y);

                    beziers.Add(bezier);

                    isMiddle = false;
                }

                currentPos = temp;
            }
        }
Example #2
0
        private void BezierContainer_MouseUp(object sender, MouseEventArgs e)
        {
            isDown = false;
            Cursor.Clip = Screen.PrimaryScreen.Bounds;

            if (isMiddle)
            {
                Point temp = new Point();

                temp.X = Control.MousePosition.X;
                temp.Y = Control.MousePosition.Y;

                temp.X -= BezierContainer.Left;
                temp.Y -= BezierContainer.Top;

                temp = PointToClient(temp);

                p3 = temp;

                p2 = getSecondPoint(midPoint, p1, p3);

                Bezier bezier = new Bezier(p1, p2, p3);

                currentDistance = 0;

                isMiddle = false;
            }

            endPoint = new Point(Control.MousePosition.X, Control.MousePosition.Y);

            endPoint = PointToClient(endPoint);

            endPoint.X -= BezierContainer.Left;
            endPoint.Y -= BezierContainer.Top;

            Graphics graphics = BezierContainer.CreateGraphics();

            Bitmap bm = new Bitmap(BezierContainer.Image, BezierContainer.Image.Width, BezierContainer.Image.Height);
            bm.SetResolution(graphics.DpiX, graphics.DpiY);

            for (int i = 0; i != beziers.Count; i++)
            {
                beziers.ElementAt(i).draw(graphics, bm, offsetX, offsetY);
            }

            graphics.Dispose();
        }