/// <summary>
        /// Loads a sketch into this Panel.  Possibly rescales the sketch to fit
        /// the current display and/or resets this panel entirely.  This method helps
        /// both display recognition results and new sketch files.
        /// </summary>
        /// <param name="newSketch">The Skech to load</param>
        /// <param name="rescale">True iff the sketch should be resized</param>
        /// <param name="reset">True iff the panel should be reinitialized</param>
        private void loadSketch(object newSketch, bool rescale, bool reset)
        {
            // Reinitialize the sketch panel if necessary
            if (reset)
            {
                this.setDefaultInkPicProps();
            }

            // Load the Sketch into the InkPicture
            inkPic.Enabled = false;
            if (newSketch is string)
            {
                inkSketch.LoadSketch((string)newSketch);
            }
            else if (newSketch is Sketch.Sketch)
            {
                inkSketch.LoadSketch((Sketch.Sketch)newSketch);
            }

            // Rescale the ink if needed
            if (rescale)
            {
                inkSketch.Recording = false;

                // Move the Ink's origin to the upper top-left corner.
                //inkPic.Ink.Strokes.Move(-1 * inkPic.Ink.GetBoundingBox().X + SketchPanelConstants.SketchPadding,
                //    -1 * inkPic.Ink.GetBoundingBox().Y + SketchPanelConstants.SketchPadding);

                // Scale the sketch to fill the InkImage
                Rectangle            inkRect     = inkPic.Ink.GetBoundingBox();
                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);

                inkSketch.Recording = true;
            }

            inkPic.Enabled = true;

            // Resize the InkPicture
            this.resizeInkPicture();
        }
Esempio n. 2
0
        /// <summary>
        /// Loads a sketch into this Panel.  Possibly rescales the sketch to fit
        /// the current display and/or resets this panel entirely.  This method helps
        /// both display recognition results and new sketch files.
        ///
        /// Precondition: newSketch is not null
        /// </summary>
        /// <param name="newSketch">The Skech to load</param>
        /// <param name="rescale">True iff the sketch should be resized</param>
        /// <param name="reset">True iff the panel should be reinitialized</param>
        private void loadSketch(object newSketch, bool rescale, bool reset)
        {
            // Reinitialize the sketch panel if necessary
            if (reset)
            {
                this.setDefaultInkPicProps();
            }

            // Load the Sketch into the InkPicture
            inkPic.Enabled = false;
            if (newSketch is string)
            {
                inkSketch.LoadSketch((string)newSketch);
            }
            else if (newSketch is Sketch.Sketch)
            {
                inkSketch.LoadSketch((Sketch.Sketch)newSketch);
            }
            else if (newSketch == null)
            {
                // We should never get here; fail quietly
                Console.WriteLine("Error in SketchPanel#loadSketch(): "
                                  + "given null sketch. Breaking load operation");
                return;
            }

            // Rescale the ink if needed
            if (rescale)
            {
                ZoomToFit();
            }

            inkPic.Enabled = true;

            // Resize the InkPicture
            this.resizeInkPicture();
        }