Ejemplo n.º 1
0
        /// <summary>
        /// Scales the sketch to fit the current panel dimensions.
        /// </summary>
        public void ZoomToFit()
        {
            Rectangle inkRect = inkPic.Ink.GetBoundingBox();

            // Move the Ink's origin to the upper top-left corner and update InkSketch
            float moveX = -1.0F * inkRect.X + SketchPanelConstants.SketchPaddingInk;
            float moveY = -1.0F * inkRect.Y + SketchPanelConstants.SketchPaddingInk;

            inkPic.Ink.Strokes.Move(moveX, moveY);
            inkRect.Offset((int)moveX, (int)moveY);

            //foreach (Microsoft.Ink.Stroke iStroke in inkPic.Ink.Strokes)
            //{
            //    inkSketch.TransformInkStroke(iStroke);
            //}

            // Scale the sketch to fill the InkImage
            System.Drawing.Point rightBottom = new System.Drawing.Point(inkRect.Right, inkRect.Bottom);
            using (Graphics g = inkPic.CreateGraphics())
            {
                inkPic.Renderer.InkSpaceToPixel(g, ref rightBottom);
            }

            System.Drawing.Point scalePt = new System.Drawing.Point(rightBottom.X - this.Left,
                                                                    rightBottom.Y - this.Top);

            // Scale the rendered strokes by the smallest (x or y) scaling factor
            float xScale = (float)(this.Width - SketchPanelConstants.SketchPaddingScreen) / (float)scalePt.X;
            float yScale = (float)(this.Height - SketchPanelConstants.SketchPaddingScreen) / (float)scalePt.Y;

            float scale = xScale < yScale ? xScale : yScale;

            inkPic.Renderer.Scale(scale, scale, true);

            // Notify subscribers
            InkTransformedEventHandler xformEvent = InkTransformed;

            if (xformEvent != null)
            {
                xformEvent(new RectangleF(inkRect.X, inkRect.Y, inkRect.Width, inkRect.Height),
                           new RectangleF(moveX, moveY, scale, scale),
                           inkPic.Ink.Strokes, InkTransformEventType.ZoomTransform);
            }

            // Fix the InkPicture
            resizeInkPicture();
            inkPic.Refresh();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Resizes InkPicture when necessary (for scrolling) and notifies subscribers
        /// </summary>
        protected void inkPic_SelectionMoved(object sender, InkOverlaySelectionMovedEventArgs e)
        {
            Rectangle oldBB = e.OldSelectionBoundingRect;
            Rectangle newBB = inkPic.Selection.GetBoundingBox();

            InkTransformedEventHandler xformEvent = InkTransformed;

            if (xformEvent != null)
            {
                xformEvent(oldBB, newBB, inkPic.Selection, InkTransformEventType.SelectionToolTransform);
            }

            this.resizeInkPicture();

            updateFocus();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Unmagnifies the sketch by a preset amount and notifies listerners.
        /// </summary>
        public void ZoomOut()
        {
            Rectangle oldBB = inkPic.Ink.GetBoundingBox();

            inkPic.Renderer.Scale(SketchPanelConstants.ZoomOutFactor, SketchPanelConstants.ZoomOutFactor, true);

            InkTransformedEventHandler zoomEvent = InkTransformed;

            if (zoomEvent != null)
            {
                zoomEvent(new RectangleF(oldBB.X, oldBB.Y, oldBB.Width, oldBB.Height),
                          new RectangleF(0.0F, 0.0F, SketchPanelConstants.ZoomOutFactor, SketchPanelConstants.ZoomOutFactor),
                          inkPic.Ink.Strokes, InkTransformEventType.ZoomTransform);
            }

            resizeInkPicture();
            inkPic.Refresh();
        }