示例#1
0
        private void EditCanvas_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            DesignerBaseCanvas it1 = sender as DesignerBaseCanvas;

            if (it1 == null)
            {
                return;
            }

            if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
            {
                IPagePropertyData page = this.DataContext as IPagePropertyData;
                Rect selectWdgBounding = page.BoundingRect;

                if (e.Delta > 0)
                {
                    //ExternCanvas.
                    ScaleTransform scaletransform = ExternCanvasBorder.RenderTransform as ScaleTransform;

                    scaletransform.ScaleX = PageScaleEnumerator.GetValue(scaletransform.ScaleX, true);// Math.Min(1.7, scaletransform.ScaleX + 0.01);

                    double hOffset = (selectWdgBounding.Left + selectWdgBounding.Width / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualWidth / 2;
                    double vOffset = (selectWdgBounding.Top + selectWdgBounding.Height / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualHeight / 2;
                    DesignerScrollViewer.ScrollToHorizontalOffset(hOffset);
                    DesignerScrollViewer.ScrollToVerticalOffset(vOffset);

                    NLogger.Debug("e.Delta: " + e.Delta + " Scale: " + scaletransform.ScaleX + " view width: " + viewWidth + " view height: " + viewHeight + " horizontalOffset: " + hOffset + " verticalOffset:" + vOffset + " DesignerScrollViewer.ActualWidth:" + DesignerScrollViewer.ActualWidth);
                }
                else if (e.Delta < 0)
                {
                    ScaleTransform scaletransform = ExternCanvasBorder.RenderTransform as ScaleTransform;
                    scaletransform.ScaleX = PageScaleEnumerator.GetValue(scaletransform.ScaleX, false); //Math.Max(0.3, scaletransform.ScaleX - 0.01);
                    //scaletransform.ScaleY = PageScaleEnumerator.GetValue(scaletransform.ScaleY, false); //Math.Max(0.3, scaletransform.ScaleY - 0.01);
                    double hOffset = (selectWdgBounding.Left + selectWdgBounding.Width / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualWidth / 2;
                    double vOffset = (selectWdgBounding.Top + selectWdgBounding.Height / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualHeight / 2;
                    DesignerScrollViewer.ScrollToHorizontalOffset(hOffset);
                    DesignerScrollViewer.ScrollToVerticalOffset(vOffset);

                    NLogger.Debug("e.Delta: " + e.Delta + " Scale: " + scaletransform.ScaleX + " view width: " + viewWidth + " view height: " + viewHeight + " horizontalOffset: " + hOffset + " verticalOffset:" + vOffset + " DesignerScrollViewer.ActualWidth:" + DesignerScrollViewer.ActualWidth);
                }

                e.Handled = true;
            }
        }
示例#2
0
        private void EditCanvas_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            DesignerBaseCanvas it = sender as DesignerBaseCanvas;

            if (it == null)
            {
                return;
            }

            if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
            {
                IPagePropertyData page = this.DataContext as IPagePropertyData;
                Rect selectWdgBounding = page.BoundingRect;

                if (e.Delta > 0)
                {
                    //ExternCanvas.
                    ScaleTransform scaletransform = ExternCanvasBorder.RenderTransform as ScaleTransform;
                    //scaletransform.ScaleX = Math.Min(1.7, scaletransform.ScaleX + 0.01);
                    //scaletransform.ScaleY = Math.Min(1.7, scaletransform.ScaleY + 0.01);
                    scaletransform.ScaleX = PageScaleEnumerator.GetValue(scaletransform.ScaleX, true);

                    DesignerScrollViewer.ScrollToHorizontalOffset((selectWdgBounding.Left + selectWdgBounding.Width / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualWidth / 2);
                    DesignerScrollViewer.ScrollToVerticalOffset((selectWdgBounding.Top + selectWdgBounding.Height / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualHeight / 2);
                }
                else if (e.Delta < 0)
                {
                    ScaleTransform scaletransform = ExternCanvasBorder.RenderTransform as ScaleTransform;
                    //scaletransform.ScaleX = Math.Max(0.3, scaletransform.ScaleX - 0.01);
                    //scaletransform.ScaleY = Math.Max(0.3, scaletransform.ScaleY - 0.01);
                    scaletransform.ScaleX = PageScaleEnumerator.GetValue(scaletransform.ScaleX, false);
                    DesignerScrollViewer.ScrollToHorizontalOffset((selectWdgBounding.Left + selectWdgBounding.Width / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualWidth / 2);
                    DesignerScrollViewer.ScrollToVerticalOffset((selectWdgBounding.Top + selectWdgBounding.Height / 2) * scaletransform.ScaleX - DesignerScrollViewer.ActualHeight / 2);
                }
                e.Handled = true;
            }
        }
示例#3
0
        public bool ExportPage2Image()
        {
            Rect rec = GetPageActualSize();

            if (rec.Height <= 0 || rec.Width <= 0)
            {
                return(false);
            }

            try
            {
                //render the canvas
                RenderTargetBitmap bmp    = new RenderTargetBitmap((int)rec.Width, (int)rec.Height, 96, 96, PixelFormats.Pbgra32);
                DesignerBaseCanvas canvas = EditorCanvas as DesignerBaseCanvas;
                if (canvas == null)
                {
                    return(false);
                }
                canvas.UpdateLayout();
                bmp.Render(canvas);

                //show file save dialog
                string         imagFile       = "";
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                //saveFileDialog.Filter = "PNG File(*.png)|*.png|JPG File(*.jpg)|*.jpg|BMP File(*.bmp)|*.bmp|GIF File(*.gif)|*.gif|TIF File(*.tif)|*.tif";
                saveFileDialog.Filter   = "PNG File(*.png)|*.png";
                saveFileDialog.FileName = this.Title;
                if (saveFileDialog.ShowDialog() == true)
                {
                    imagFile = saveFileDialog.FileName;
                }
                else
                {
                    return(false);
                }

                //export image
                string        extensionString = Path.GetExtension(imagFile);
                BitmapEncoder encoder         = null;
                switch (extensionString)
                {
                case ".jpg":
                    encoder = new JpegBitmapEncoder();
                    break;

                case ".png":
                    encoder = new PngBitmapEncoder();
                    break;

                case ".bmp":
                    encoder = new BmpBitmapEncoder();
                    break;

                case ".gif":
                    encoder = new GifBitmapEncoder();
                    break;

                case ".tif":
                    encoder = new TiffBitmapEncoder();
                    break;

                default:
                    throw new InvalidOperationException();
                }
                encoder.Frames.Add(BitmapFrame.Create(bmp));
                using (Stream stm = File.Create(imagFile))
                {
                    encoder.Save(stm);
                }
            }
            catch (Exception exp)
            {
                NLogger.Warn("Export page into a image : " + exp.Message);
                return(false);
            }
            return(true);
        }