예제 #1
0
        /// <summary>
        /// Here we recalculate the freehand path by smoothing out the lines with Beziers.
        /// </summary>
        private void RecalculatePath()
        {
            lock (_freehandPathLock)
            {
                isRecalculated = true;
                // Dispose the previous path, if we have one
                freehandPath?.Dispose();
                freehandPath = new GraphicsPath();

                // Here we can put some cleanup... like losing all the uninteresting  points.
                if (capturePoints.Count >= 3)
                {
                    int index = 0;
                    while ((capturePoints.Count - 1) % 3 != 0)
                    {
                        // duplicate points, first at 50% than 25% than 75%
                        capturePoints.Insert((int)(capturePoints.Count * PointOffset[index]), capturePoints[(int)(capturePoints.Count * PointOffset[index++])]);
                    }
                    freehandPath.AddBeziers(capturePoints.Cast <PointF>().ToArray());
                }
                else if (capturePoints.Count == 2)
                {
                    freehandPath.AddLine(capturePoints[0], capturePoints[1]);
                }

                // Recalculate the bounds
                NativeRectFloat rect = freehandPath.GetBounds();
                myBounds = rect.Round();
            }
        }
예제 #2
0
        /// <summary>
        /// Called from Surface (the parent) if a mouse move is made while drawing
        /// </summary>
        /// <returns>true if the surface doesn't need to handle the event</returns>
        public override bool HandleMouseMove(int mouseX, int mouseY)
        {
            NativePoint previousPoint = capturePoints[capturePoints.Count - 1];

            if (GeometryHelper.Distance2D(previousPoint.X, previousPoint.Y, mouseX, mouseY) >= 2 * EditorConfig.FreehandSensitivity)
            {
                capturePoints.Add(new NativePoint(mouseX, mouseY));
            }
            if (GeometryHelper.Distance2D(lastMouse.X, lastMouse.Y, mouseX, mouseY) < EditorConfig.FreehandSensitivity)
            {
                return(true);
            }
            //path.AddCurve(new NativePoint[]{lastMouse, new NativePoint(mouseX, mouseY)});
            lastMouse = new NativePoint(mouseX, mouseY);
            lock (_freehandPathLock)
            {
                freehandPath.AddLine(lastMouse, new NativePoint(mouseX, mouseY));
                // Only re-calculate the bounds & redraw when we added something to the path
                NativeRectFloat rect = freehandPath.GetBounds();
                myBounds = rect.Round();
            }

            Invalidate();
            return(true);
        }
예제 #3
0
        /// <summary>
        ///     A handler for the MouseMove, used if you don't want the surface to handle this for you
        /// </summary>
        /// <param name="x">current mouse x</param>
        /// <param name="y">current mouse y</param>
        /// <returns>true if the event is handled, false if the surface needs to handle it</returns>
        public virtual bool HandleMouseMove(int x, int y)
        {
            Invalidate();

            // reset "workrbench" rectangle to current bounds
            _boundsAfterResize = _boundsBeforeResize;
            ScaleHelper.Scale(_boundsBeforeResize, x, y, ref _boundsAfterResize, GetAngleRoundProcessor());

            // apply scaled bounds to this DrawableContainer
            ApplyBounds(_boundsAfterResize.Round());

            Invalidate();
            return(true);
        }
예제 #4
0
        /// <summary>
        ///     Handle the mouse move
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="mouseEventArgs"></param>
        public override void MouseMove(object sender, MouseEventArgs mouseEventArgs)
        {
            if (EditStatus != EditStatus.RESIZING)
            {
                return;
            }
            Owner.Invalidate();
            Owner.MakeBoundsChangeUndoable(false);

            // reset "workbench" rectangle to current bounds
            _boundsAfterResize = _boundsBeforeResize;

            // calculate scaled rectangle
            ScaleHelper.Scale(ref _boundsAfterResize, Position, new NativePointFloat(mouseEventArgs.X, mouseEventArgs.Y), ScaleHelper.GetScaleOptions());

            // apply scaled bounds to this DrawableContainer
            Owner.ApplyBounds(_boundsAfterResize.Round());

            Owner.Invalidate();
        }