コード例 #1
0
        public override VerbResult OtherVerb(EditableView.ClickPosition position, SAW.Functions.Codes code)
        {
            switch (code)
            {
            case SAW.Functions.Codes.Increment:
            case SAW.Functions.Codes.Decrement:
                int   delta = code == SAW.Functions.Codes.Increment ? 1 : -1;
                float step  = position.ScalarSnapStep(0);
                if (step <= 0)
                {
                    step = delta * Globals.Root.CurrentConfig.ReadSingle(Config.Radius_Step, 1);
                }
                else
                {
                    step *= delta;
                }
                SizeF vector = Vertices[0].VectorTo(Vertices[1]);
                float length = vector.Length();
                if (length + step < 5 || length < Geometry.NEGLIGIBLESMALL)
                {
                    return(VerbResult.Rejected);
                }
                Vertices[1] = Vertices[0] + vector.ChangeLength(length + step);
                m_Bounds    = RectangleF.Empty;
                return(VerbResult.Continuing);

            default:
                return(VerbResult.Rejected);
            }
        }
コード例 #2
0
        private bool AdjustPoint(int index, EditableView.ClickPosition position)
        {
            // Used by both Float and DoGrabMove.  Returns true if the point is valid
            PointF pt = position.Snapped;
            // the main task is to restrict the line to the correct directions
            float angularStep = GetAngularStep(position.Page);
            SizeF vector      = Vertices[1 - index].VectorTo(pt);

            if (vector.IsEmpty)
            {
                return(false);
            }
            // the following calculations will fail if the two points are on top of each other
            // but there is no need to do any of this - the position of point(0) is a valid position (ish)
            // calculate the angle in radians of this line counting clockwise from vertically up (must count from vertically in order to match the isometric paper)
            float angle  = vector.VectorAngle();
            float length = vector.Length();

            angle = (float)(Math.Round(angle / angularStep) * angularStep);
            // angle changed to the closest of the allowed angles
            // now snapped the length so that it will hit a grid point
            // the complication is if we are going diagonally on squared paper, in which case the incremental length is sqrt(2) * spacing.
            // the following function should take care of this
            float step = position.ScalarSnapStep(angle);

            if (step > 0)
            {
                length = (float)Math.Round(length / step) * step;                 // make it a multiple of a grid unit
            }
            vector = Geometry.ScalarToVector(length, angle);
            pt     = PointF.Add(Vertices[1 - index], vector);
            // and finally we snap the resulting point back to the page grid - it should already be on this, but just in case
            // of any rounding errors
            if (position.RequestedSnap == SnapModes.Grid)
            {
                position.Snapped = position.Page.Paper.SnapPoint2(pt);
            }
            else
            {
                position.Snapped = pt;
            }
            // in order to avoid flickering it is worth checking if the target has actually moved - because this line is very constrained often it does not move at all, or and repainting a completely unchanged line is the most flickery situation
            return(true);
        }