예제 #1
0
        protected override void InternalUpdateBounds(float x, float y, float width, float height)
        {
            if (updatingBoundsFromPath || points.Count == 0)
            {
                return;
            }

            if (resizePoints != null)
            {
                points.Clear();
                points.AddRange(resizePoints);
            }

            RectangleF pathBounds = PathBounds;

            TEMP_MATRIX.Reset();
            TEMP_MATRIX.TranslateBy(x, y);
            TEMP_MATRIX.ScaleBy(width / pathBounds.Width, height / pathBounds.Height);
            TEMP_MATRIX.TranslateBy(-pathBounds.X, -pathBounds.Y);

            for (int i = 0; i < points.Count; i++)
            {
                points[i] = TEMP_MATRIX.Transform((PointF)points[i]);
            }
        }
예제 #2
0
        /// <summary>
        /// Returns true if this path intersects the given rectangle.
        /// </summary>
        /// <remarks>
        /// This method first checks if the interior of the path intersects with the rectangle.
        /// If not, the method then checks if the path bounding the pen stroke intersects with
        /// the rectangle.  If either of these cases are true, this method returns true.
        /// <para>
        /// <b>Performance Note</b>:  For some paths, this method can be very slow.  This is due
        /// to the implementation of IsVisible.  The problem usually occurs when many lines are
        /// joined at very steep angles.  See the documentation above for workarounds.
        /// </para>
        /// </remarks>
        /// <param name="bounds">The rectangle to check for intersection.</param>
        /// <param name="matrix">
        /// A matrix object that specifies a transform to apply to the path and bounds before
        /// checking for an intersection.
        /// </param>
        /// <returns>True if this path intersects the given rectangle; otherwise, false.</returns>
        public virtual bool Intersects(RectangleF bounds, PMatrix matrix)
        {
            if (base.Intersects(bounds))
            {
                // Transform the bounds.
                if (!matrix.IsIdentity)
                {
                    bounds = matrix.Transform(bounds);
                }

                // Set the temp region to the transformed path.
                SetTempRegion(path, matrix, false);

                if (Brush != null && TEMP_REGION.IsVisible(bounds))
                {
                    return(true);
                }
                else if (pen != null)
                {
                    // Set the temp region to the transformed, widened path.
                    SetTempRegion(path, matrix, true);
                    return(TEMP_REGION.IsVisible(bounds));
                }
            }

            return(false);
        }
        public override void SetViewPosition(float x, float y)
        {
            if (camera != null)
            {
                // If a scroll is in progress - we ignore new scrolls -
                // if we didn't, since the scrollbars depend on the camera location
                // we can end up with an infinite loo
                if (!scrollInProgress)
                {
                    scrollInProgress = true;

                    // Get the union of all the layers' bounds
                    RectangleF layerBounds = camera.UnionOfLayerFullBounds;

                    PMatrix matrix = camera.ViewMatrix;
                    layerBounds = matrix.Transform(layerBounds);

                    // Union the camera view bounds
                    RectangleF viewBounds = camera.Bounds;
                    layerBounds = RectangleF.Union(layerBounds, viewBounds);

                    // Now find the new view position in view coordinates -
                    // This is basically the distance from the lower right
                    // corner of the window to the upper left corner of the
                    // document
                    // We then measure the offset from the lower right corner
                    // of the document
                    PointF newPoint =
                        new PointF(
                            layerBounds.X + layerBounds.Width - (x + viewBounds.Width),
                            layerBounds.Y + layerBounds.Height - (y + viewBounds.Height));

                    // Now transform the new view position into global coords
                    newPoint = camera.LocalToView(newPoint);

                    // Compute the new matrix values to put the camera at the
                    // correct location
                    float[] elements = matrix.Elements;
                    elements[4] = -(elements[0] * newPoint.X + elements[1] * newPoint.Y);
                    elements[5] = -(elements[2] * newPoint.X + elements[3] * newPoint.Y);

                    matrix = new PMatrix(elements[0], elements[1], elements[2], elements[3], elements[4], elements[5]);

                    // Now actually set the camera's transform
                    camera.ViewMatrix = matrix;
                    scrollInProgress  = false;
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Overridden.  See <see cref="PNode.Paint">PNode.Paint</see>.
        /// </summary>
        protected override void Paint(PPaintContext paintContext)
        {
            base.Paint(paintContext);

            Graphics   g          = paintContext.Graphics;
            PMatrix    matrix     = new PMatrix(g.Transform);
            RectangleF transRectF = matrix.Transform(bounds);
            Rectangle  transRect  = new Rectangle((int)transRectF.X, (int)transRectF.Y, (int)transRectF.Width, (int)transRectF.Height);

            // Draw the image if the control node is not in editing mode or
            // if the control is being rendered in a view other than the one
            // that owns the control.
            if (!Editing || control.Bounds != transRect || paintContext.Canvas != currentCanvas)
            {
                if (Image != null)
                {
                    g.DrawImage(Image, bounds);
                }
            }
        }
        /// <summary>
        /// Sets the view position in a manner consistent with standardized scrolling.
        /// </summary>
        /// <param name="x">The x coordinate of the new position.</param>
        /// <param name="y">The y coordinate of the new position.</param>
        public virtual void SetViewPosition(float x, float y)
        {
            if (camera != null)
            {
                // Only process this scroll if a scroll is not already in progress;
                // otherwise, we could end up with an infinite loop, since the
                // scrollbars depend on the camera location.
                if (!scrollInProgress)
                {
                    scrollInProgress = true;

                    // Get the union of all the layers' bounds
                    RectangleF layerBounds = UnionOfLayerFullBounds;

                    PMatrix matrix = camera.ViewMatrix;
                    layerBounds = matrix.Transform(layerBounds);

                    // Union the camera bounds
                    RectangleF viewBounds = camera.Bounds;
                    layerBounds = RectangleF.Union(layerBounds, viewBounds);

                    // Now find the new view position in view coordinates
                    PointF newPoint = new PointF(layerBounds.X + x, layerBounds.Y + y);

                    // Now transform the new view position into global coords
                    newPoint = camera.LocalToView(newPoint);

                    // Compute the new matrix values to put the camera at the
                    // correct location
                    float[] elements = matrix.Elements;
                    elements[4] = -(elements[0] * newPoint.X + elements[1] * newPoint.Y);
                    elements[5] = -(elements[2] * newPoint.X + elements[3] * newPoint.Y);

                    matrix = new PMatrix(elements[0], elements[1], elements[2], elements[3], elements[4], elements[5]);

                    // Now actually set the camera's transform
                    camera.ViewMatrix = matrix;
                    scrollInProgress  = false;
                }
            }
        }
예제 #6
0
        //****************************************************************
        // Camera View Coordinate System Conversions - Methods to
        // translate from the camera's local coordinate system (above the
        // camera's view matrix) to the camera view coordinate system
        // (below the camera's view matrix). When converting geometry from
        // one of the canvas’s layers you must go through the view matrix.
        //****************************************************************

        /// <summary>
        /// Transform the point from the camera's view coordinate system to the camera's
        /// local coordinate system.
        /// </summary>
        /// <param name="point">
        /// The point in the camera's view coordinate system to be transformed.
        /// </param>
        /// <returns>The point in the camera's local coordinate system.</returns>
        public virtual PointF ViewToLocal(PointF point)
        {
            return(viewMatrix.Transform(point));
        }