Пример #1
0
        public void AddVisual(Visual visual)
        {
            visuals.Add(visual);

            base.AddVisualChild(visual);
            base.AddLogicalChild(visual);
        }
Пример #2
0
        //-------------------------------------------------------------------
        //
        //  Constructors
        //
        //-------------------------------------------------------------------

        #region Constructors

        /// <summary>
        /// Public constructor.
        /// </summary>
        /// <param name="visual">The visual representation of this page.</param>
        public DocumentPage(Visual visual)
        {
            _visual = visual;
            _pageSize = Size.Empty;
            _bleedBox = Rect.Empty;
            _contentBox = Rect.Empty;
        }
Пример #3
0
        public MemoryStream GenerateImage(Visual vsual, int widhth, int height, ImageFormat format)
        {
            BitmapEncoder encoder = null;

            switch (format)
            {
                case ImageFormat.JPG :
                    encoder = new JpegBitmapEncoder();
                    break;
                case ImageFormat.PNG:
                    encoder = new PngBitmapEncoder();
                    break;
                case ImageFormat.BMP:
                    encoder = new BmpBitmapEncoder();
                    break;
                case ImageFormat.GIF:
                    encoder = new GifBitmapEncoder();
                    break;
                case ImageFormat.TIF:
                    encoder = new TiffBitmapEncoder();
                    break;

            }

            if (encoder == null) return null;

            RenderTargetBitmap rtb = this.RenderVisaulToBitmap(vsual, widhth, height);
            MemoryStream file = new MemoryStream();
            encoder.Frames.Add(BitmapFrame.Create(rtb));
            encoder.Save(file);

            return file;
        }
Пример #4
0
        /// <summary>
        /// Ensures that the contents of the LoopingPanel are scrolled such that a specified visual
        /// element is visible.
        /// </summary>
        /// <param name="visual">A Visual that becomes visible.</param>
        /// <param name="rectangle">A bounding rectangle that identifies the coordinate space to make visible.</param>
        /// <returns>A Rect that is visible.</returns>
        public Rect MakeVisible(System.Windows.Media.Visual visual, System.Windows.Rect rectangle)
        {
            int    itemIndex  = Children.IndexOf((UIElement)visual);
            int    index      = firstItem;
            double itemOffset = firstItemOffset;

            // Get the offset for the item that should be visible
            while (index != itemIndex)
            {
                itemOffset += Children[index].DesiredSize.Width;
                index++;
                if (index >= Children.Count)
                {
                    index = 0;
                }
            }

            // If the item is not fully in view on the left side, then adjust the offset to bring it into view
            if (itemOffset < viewportOffset.X)
            {
                ScrollContent(viewportOffset.X - itemOffset);
            }

            // If the item is not fully in view on the right side, then adjust the offset to bring it into view
            if (itemOffset + rectangle.Width > viewportOffset.X + ViewportWidth)
            {
                ScrollContent((viewportOffset.X + ViewportWidth) - (itemOffset + rectangle.Width));
            }

            return(rectangle);
        }
 public void OnRootChanged(Visual oldRoot, Visual newRoot)
 {
     if(_active && newRoot != null) 
     {
         Keyboard.Focus(null); // internally we will set the focus to the root. 
     } 
 }
Пример #6
0
        public static System.Windows.Forms.IWin32Window GetIWin32Window(this System.Windows.Media.Visual visual)
        {
            var source = (System.Windows.Interop.HwndSource)PresentationSource.FromVisual(visual);

            System.Windows.Forms.IWin32Window win = new OldWindow(source.Handle);
            return(win);
        }
Пример #7
0
        public static void Init(System.Windows.Media.Visual visual)
        {
            Matrix transformToDevice = System.Windows.PresentationSource.FromVisual(visual).CompositionTarget.TransformToDevice;

            DPIUtils._dpiX = transformToDevice.M11;
            DPIUtils._dpiY = transformToDevice.M22;
        }
Пример #8
0
 /// <summary>
 /// Public constructor.
 /// </summary>
 /// <param name="visual">The visual representation of this page.</param>
 /// <param name="pageSize">The size of the page, including margins.</param>
 /// <param name="bleedBox">The bounds the ink drawn by the page.</param>
 /// <param name="contentBox">The bounds of the content within the page.</param>
 public DocumentPage(Visual visual, Size pageSize, Rect bleedBox, Rect contentBox)
 {
     _visual = visual;
     _pageSize = pageSize;
     _bleedBox = bleedBox;
     _contentBox = contentBox;
 }
 public static System.Windows.Media.Effects.BitmapEffectInput GetBitmapEffectInput(Visual reference)
 {
   Contract.Requires(reference != null);
   
   // May return null
   return default(System.Windows.Media.Effects.BitmapEffectInput);
 }
Пример #10
0
 /// <summary>
 /// Adds given visual as a root of Snoop visual tree.
 /// </summary>
 internal static void AddSnoopVisualTreeRoot(Visual root)
 {
     if (!_registeredSnoopVisualTreeRoots.Contains(root))
     {
         _registeredSnoopVisualTreeRoots.Add(root);
     }
 }
        internal PrintPreviewWindow(
			Visual mainPrintContent,
			IEnumerable<PrintContent> additionalPrintContent,
			IViewDrawingState viewDrawingState)
        {
            _mainPrintContent = mainPrintContent;
            _additionalPrintContent = additionalPrintContent;
            _viewDrawingState = viewDrawingState;

            PrintCommand = new RelayCommand(DoPrint);

            PaperFormats = new[]
                {
                    new PaperFormatViewModel("DIN A3", PaperFormat.A3),
                    new PaperFormatViewModel("DIN A4", PaperFormat.A4),
                };
            _selectedPaperFormat = PaperFormats.ElementAt(1);

            PaperOrientations = new[]
                {
                    new PaperOrientationViewModel(MlResources.PaperOrientationPortrait, PaperOrientation.Portrait),
                    new PaperOrientationViewModel(MlResources.PaperOrientationLandscape, PaperOrientation.Landscape),
                };
            _selectedPaperOrientation = PaperOrientations.ElementAt(1);

            InitializeComponent();
        }
Пример #12
0
        public void DeleteVisual(Visual visual)
        {
            visuals.Remove(visual);

            base.RemoveVisualChild(visual);
            base.RemoveLogicalChild(visual);
        }
Пример #13
0
 // -- Many thanks to Bea Stollnitz, on whose blog I found the original C# version of below in a drag-drop helper class...
 public static FrameworkElement FindVisualAncestor(System.Type ancestorType, System.Windows.Media.Visual visual)
 {
     while ((visual != null && !ancestorType.IsInstanceOfType(visual)))
     {
         visual = (System.Windows.Media.Visual)System.Windows.Media.VisualTreeHelper.GetParent(visual);
     }
     return((FrameworkElement)visual);
 }
 /// <summary>
 /// Creates a VisualCollection.
 /// </summary>
 public VisualCollection(Visual parent)
 {
     if (parent == null)
     {
         throw new ArgumentNullException("parent");
     }
     _owner = parent;
 }
    public static Geometry GetClip(Visual reference)
    {
      Contract.Requires(reference != null);

      // May return null

      return default(Geometry);
    }
Пример #16
0
 /// <summary>
 /// Make the given visual at the given bounds visible.
 /// </summary>
 /// <param name="visual">The visual that will become visible</param>
 /// <param name="rectangle">The bounds of that visual</param>
 /// <returns>The bounds that is actually visible.</returns>
 public Rect MakeVisible(System.Windows.Media.Visual visual, Rect rectangle)
 {
     if (_zoom != null && visual != this)
     {
         return(_zoom.ScrollIntoView(visual as FrameworkElement));
     }
     return(rectangle);
 }
Пример #17
0
        public static PopupLayer GetPopupLayer(Visual target)
        {
            if (target == null)
            {
                return null;
            }

            return target is IPopupLayerHost ? ((IPopupLayerHost)target).PopupLayer : GetPopupLayer(target.VisualParent);
        }
Пример #18
0
		static void UpdateReferences(Visual visual)
		{
			foreach (var glyph in visual.FindVisualChildren<Glyphs>())
				if (!glyph.FontUri.IsAbsoluteUri)
				{
					var glyphGuid = glyph.FontUri.ToString();
					glyph.FontUri = new Uri(ServiceFactoryBase.ContentService.GetContentFileName(glyphGuid), UriKind.Absolute);
				}
		}
Пример #19
0
 public void CreateFromImage(Bitmap image)
 {
     this.image  = image;
     initialClip = new RectangleF(0, 0, image.Width, image.Height);
     bounds      = initialClip.ToWpf();
     visual      = drawingVisual = new swm.DrawingVisual();
     Control     = drawingVisual.RenderOpen();
     Control.DrawImage(image.ToWpf(1), bounds);
 }
Пример #20
0
 public static void Initialize(System.Windows.Media.Visual visual)
 {
     if (_initialized)
     {
         return;
     }
     _initialized = true;
     Set(visual);
 }
Пример #21
0
        public void CreateFromImage(Bitmap image)
        {
            this.image    = image;
            drawingVisual = new swm.DrawingVisual();
            Control       = drawingVisual.RenderOpen();
            Control.DrawImage(image.ControlObject as swm.ImageSource, new sw.Rect(0, 0, image.Size.Width, image.Size.Height));

            visual = drawingVisual;
            this.ImageInterpolation = Eto.Drawing.ImageInterpolation.Default;
        }
Пример #22
0
        public static void Set(System.Windows.Media.Visual visual)
        {
            PresentationSource x = PresentationSource.FromVisual(visual);

            if (x?.CompositionTarget != null)
            {
                TransformFromDevice = x.CompositionTarget.TransformFromDevice;
                TransformToDevice   = x.CompositionTarget.TransformToDevice;
            }
        }
Пример #23
0
        public static System.Windows.Point PointToScreenDpiAware(this SWM.Visual visual, System.Windows.Point point)
        {
            point = visual.PointToScreen(point);

            PresentationSource source = PresentationSource.FromVisual(visual);

            double scaleFactorX = source.CompositionTarget.TransformToDevice.M11;
            double scaleFactorY = source.CompositionTarget.TransformToDevice.M22;

            return(new System.Windows.Point(point.X / scaleFactorX, point.Y / scaleFactorY));
        }
Пример #24
0
        public DirectPrinter(
			Visual mainPrintContent, 
			IEnumerable<PrintContent> additionalPrintContent, 
			IViewDrawingState viewDrawingState, 
			int pageMargin)
        {
            _mainPrintContent = mainPrintContent;
            _additionalPrintContent = additionalPrintContent;
            _viewDrawingState = viewDrawingState;
            _pageMargin = pageMargin;
        }
Пример #25
0
 Rect IScrollInfo.MakeVisible(System.Windows.Media.Visual visual, Rect rectangle)
 {
     if (scrollInfo != null)
     {
         return(scrollInfo.MakeVisible(visual, rectangle));
     }
     else
     {
         return(Rect.Empty);
     }
 }
Пример #26
0
        /// <summary>
        /// 指定したコントロールに対するマウスカーソルの相対位置を返します
        /// </summary>
        /// <param name="v"></param>
        /// <returns></returns>
        public static Point GetPosition(System.Windows.Media.Visual v)
        {
            POINT p;

            GetCursorPos(out p);

            Point converted = v.PointFromScreen(new Point(p.X, p.Y));

            //System.Diagnostics.Debug.WriteLine("GetNowPosition PointFromScreen ({0},{1}) => ({2},{3})",
            //    p.X, p.Y, converted.X, converted.Y);
            return(converted);
        }
Пример #27
0
 private static DependencyObject FirstVisualChild(System.Windows.Media.Visual visual)
 {
     if (visual == null)
     {
         return(null);
     }
     if (VisualTreeHelper.GetChildrenCount(visual) == 0)
     {
         return(null);
     }
     return(VisualTreeHelper.GetChild(visual, 0));
 }
Пример #28
0
        public static Size GetPixelRatios(this SWM.Visual self)
        {
            var source = PresentationSource.FromVisual(self);

            if (source == null)
            {
                return(new Size(1, 1));
            }

            SWM.Matrix m = source.CompositionTarget.TransformToDevice;
            return(new Size(m.M11, m.M22));
        }
Пример #29
0
        public static Point GetMousePosition(System.Windows.Media.Visual visual)
        {
            POINT point;

            GetCursorPos(out point);

            HwndSource source = (HwndSource)HwndSource.FromVisual(visual);
            IntPtr     hwnd   = source.Handle;

            ScreenToClient(hwnd, ref point);
            return(new Point(point.X, point.Y));
        }
Пример #30
0
		private ModelUIElement3D CreateMeshModel(Visual visual)
		{
			var model3d = InternalResources["ElementModel"] as ModelUIElement3D;
			VisualBrush brush = new VisualBrush(visual);
			RenderOptions.SetCachingHint(brush, CachingHint.Cache);

			var geom3D = model3d.Model as GeometryModel3D;
			(geom3D.Material as DiffuseMaterial).Brush = brush;
			(geom3D.Geometry as MeshGeometry3D).Positions = CreateMeshPositions();

			return model3d;
		}
Пример #31
0
        public static double GetScaleFactor(this SWM.Visual self)
        {
            PresentationSource source = PresentationSource.FromVisual(self);

            if (source == null)
            {
                return(1);
            }

            SWM.Matrix m = source.CompositionTarget.TransformToDevice;
            return(m.M11);
        }
Пример #32
0
        public GraphicsHandler(swm.Visual visual, swm.DrawingContext context, sw.Rect bounds, RectangleF initialClip, bool shouldDispose = true)
        {
            disposeControl = shouldDispose;
            this.visual    = visual;
            drawingVisual  = visual as swm.DrawingVisual;

            Control = context;

            this.bounds      = bounds;
            this.initialClip = initialClip;

            Control.PushClip(new swm.RectangleGeometry(bounds));
        }
Пример #33
0
        public void CreateFromImage(Bitmap image)
        {
            this.image    = image;
            bounds        = new sw.Rect(0, 0, image.Size.Width, image.Size.Height);
            drawingVisual = new swm.DrawingVisual();
            visual        = drawingVisual;
            Control       = drawingVisual.RenderOpen();
            Control.DrawImage(image.ControlObject as swm.ImageSource, bounds);

            PushGuideLines(bounds);

            ImageInterpolation = ImageInterpolation.Default;
        }
Пример #34
0
		private ModelUIElement3D CreateMeshModel(Visual visual)
		{
			var model3D = ((GeometryModel3D) InternalResources["ElementModel"]).Clone();
			var brush = new VisualBrush(visual);
			RenderOptions.SetCachingHint(brush, CachingHint.Cache);
            RenderOptions.SetBitmapScalingMode(brush, BitmapScalingMode.LowQuality);
			((DiffuseMaterial) model3D.Material).Brush = brush;
			((MeshGeometry3D) model3D.Geometry).Positions = CreateMeshPositions();

			var model = new ModelUIElement3D {Model = model3D};

		    return model;
		}
Пример #35
0
        private ModelUIElement3D CreateMeshModel(Visual visual)
        {
            GeometryModel3D model3d = (InternalResources["ElementModel"] as GeometryModel3D).Clone();
            VisualBrush brush = new VisualBrush(visual);
            RenderOptions.SetCachingHint(brush, CachingHint.Cache);
            (model3d.Material as DiffuseMaterial).Brush = brush;
            (model3d.Geometry as MeshGeometry3D).Positions = CreateMeshPositions();

            ModelUIElement3D model = new ModelUIElement3D();
            model.Model = model3d;

            return model;
        }
Пример #36
0
        /// <summary>
        /// Scrolls a child of the panel (Visual) into view.
        /// </summary>
        public System.Windows.Rect MakeVisible(System.Windows.Media.Visual visual, System.Windows.Rect rectangle)
        {
            if (rectangle.IsEmpty || visual == null ||
                visual == this || !base.IsAncestorOf(visual))
            {
                return(Rect.Empty);
            }

            double    dblOffsetX = 0;
            UIElement uieControlToMakeVisible = null;

            for (int i = 0; i < this.InternalChildren.Count; i++)
            {
                if ((Visual)this.InternalChildren[i] == visual)
                {
                    uieControlToMakeVisible = this.InternalChildren[i];
                    dblOffsetX = getLeftEdge(this.InternalChildren[i]);
                    break;
                }
            }

            //Set the offset only if the desired element is not already completely visible.
            if (uieControlToMakeVisible != null)
            {
                if (uieControlToMakeVisible == this.InternalChildren[0])
                {
                    //If the first child has been selected, go to the very beginning of the scrollable area
                    dblOffsetX = 0;
                }
                else if (uieControlToMakeVisible == this.InternalChildren[this.InternalChildren.Count - 1])
                {
                    //If the last child has been selected, go to the very end of the scrollable area
                    dblOffsetX = this.ExtentWidth - this.Viewport.Width;
                }
                else
                {
                    dblOffsetX = CalculateNewScrollOffset(
                        this.HorizontalOffset,
                        this.HorizontalOffset + this.Viewport.Width,
                        dblOffsetX,
                        dblOffsetX + uieControlToMakeVisible.DesiredSize.Width
                        );
                }

                SetHorizontalOffset(dblOffsetX);
                rectangle = new Rect(this.HorizontalOffset, 0, uieControlToMakeVisible.DesiredSize.Width, this.Viewport.Height);
            }

            return(rectangle);
        }
Пример #37
0
        public static AdornerLayer GetAdornerLayer(Visual visual)
        {
            while (visual != null)
            {
                if (visual is IAdornerLayerHost)
                {
                    return ((IAdornerLayerHost)visual).AdornerLayer;
                }

                visual = visual.VisualParent;
            }

            return null;
        }
Пример #38
0
        /// <summary>
        /// If the mouse is moved (dragged) a minimum distance
        /// over a supported SourceContainer/SourceObject,
        /// initiate a drag operation.
        /// </summary>
        private void DragSource_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if ((this._dragDropObject != null) && !this._dragInProgress && this._dragDropObject.IsSupportedContainerAndObject(false, sender, e.Source, e.OriginalSource))
            {
                Point currentPosition = e.GetPosition(sender as IInputElement);
                if (((Math.Abs(currentPosition.X - this._startPosition.X) > SystemParameters.MinimumHorizontalDragDistance) ||
                     (Math.Abs(currentPosition.Y - this._startPosition.Y) > SystemParameters.MinimumVerticalDragDistance)))
                {
                    // NOTE:
                    //      While dragging a ListBoxItem, another one can be selected
                    //      This doesn't seem to happen with TreeView or TabControl
                    if (sender is ListBox)
                    {
                        this._dragDropObject.SourceObject = e.Source;
                    }

                    this._dragInProgress = true;

                    if (this._dragDropObject.AddAdorner)
                    {
                        this._dragDropObject.DragAdorner = new DefaultAdorner(
                            (UIElement)Application.Current.MainWindow.Content,
                            (UIElement)this._dragDropObject.SourceObject,
                            this._dragDropObject.StartPosition);
                        System.Windows.Media.Visual visual = Application.Current.MainWindow.Content as Visual;
                        AdornerLayer.GetAdornerLayer(visual).Add(this._dragDropObject.DragAdorner);
                    }

                    DragDropEffects resultEffects = DoDragDrop_Start(e);

                    if (this._dragDropObject.NeedsCaptureMouse)
                    {
                        this._dragSource.ReleaseMouseCapture();
                    }

                    this.DoDragDrop_Done(resultEffects);

                    if (this._dragDropObject.AddAdorner)
                    {
                        AdornerLayer.GetAdornerLayer((Visual)Application.Current.MainWindow.Content).Remove(this._dragDropObject.DragAdorner);
                    }

                    Mouse.OverrideCursor = null;

                    this._dragDropObject = null;
                    this._dragInProgress = false;
                }
            }
        }
Пример #39
0
        /// <summary>
        /// Returns the mouse cursor location.  This method is necessary during
        /// a drag-drop operation because the WPF mechanisms for retrieving the
        /// cursor coordinates are unreliable.
        /// </summary>
        /// <param name="relativeTo">The Visual to which the mouse coordinates will be relative.</param>
        public static Point GetMousePosition(System.Windows.Media.Visual relativeTo)
        {
            var mousePoint = GetMousePosition();

            return(relativeTo.PointFromScreen(mousePoint));

            #region Commented Out
            //System.Windows.Interop.HwndSource presentationSource =
            //    (System.Windows.Interop.HwndSource)PresentationSource.FromVisual( relativeTo );
            //ScreenToClient( presentationSource.Handle, ref mouse );
            //GeneralTransform transform = relativeTo.TransformToAncestor( presentationSource.RootVisual );
            //Point offset = transform.Transform( new Point( 0, 0 ) );
            //return new Point( mouse.X - offset.X, mouse.Y - offset.Y );
            #endregion // Commented Out
        }
Пример #40
0
        public GraphicsHandler(swm.Visual visual, swm.DrawingContext context, sw.Rect bounds, bool shouldDispose = true)
        {
            this.disposeControl = shouldDispose;
            this.visual         = visual;
            this.drawingVisual  = visual as swm.DrawingVisual;

            this.Control = context;

            this.bounds = bounds;

            PushGuideLines(bounds);

            this.Control.PushClip(new swm.RectangleGeometry(bounds));

            this.ImageInterpolation = Eto.Drawing.ImageInterpolation.Default;
        }
        public static void SaveToImage(Visual visual, int width, int height)
        {
            Debug.WriteLine($"width: {width}, height: {height}");
            var filePath = ChoosePathToSave();
            if (filePath == null) return;

            using (var fs = new FileStream(filePath, FileMode.Create))
            {
                var renderer = new RenderTargetBitmap(width, height, Dpi, Dpi, PixelFormat);
                renderer.Render(visual);
                var encoder = ChooseBitmapEncoder(Path.GetExtension(filePath));
                encoder.Frames.Add(BitmapFrame.Create(renderer));
                encoder.Save(fs);
            }
            SelectFileInExplorer(filePath);
        }
Пример #42
0
        public void Clear(SolidBrush brush)
        {
            var rect = clipBounds ?? initialClip;

            if (drawingVisual != null)
            {
                CloseGroup();
                // bitmap
                Control.Close();
                var newbmp = new swmi.RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, 96, 96, swm.PixelFormats.Pbgra32);
                newbmp.RenderWithCollect(visual);

                swm.Geometry maskgeometry;
                if (clipPath != null)
                {
                    maskgeometry = clipPath;
                }
                else
                {
                    maskgeometry = new swm.RectangleGeometry(rect.ToWpf());
                }
                var boundsgeometry = new swm.RectangleGeometry(bounds);
                maskgeometry = swm.Geometry.Combine(boundsgeometry, maskgeometry, swm.GeometryCombineMode.Exclude, null);
                var dr = new swm.GeometryDrawing(swm.Brushes.Black, null, maskgeometry);
                var db = new swm.DrawingBrush(dr);

                visual  = drawingVisual = new swm.DrawingVisual();
                Control = drawingVisual.RenderOpen();
                Control.PushOpacityMask(db);
                Control.DrawImage(newbmp, bounds);
                Control.Pop();

                ApplyAll();
            }
            else
            {
                // drawable
                if (brush == null || brush.Color.A < 1.0f)
                {
                    Widget.FillRectangle(Brushes.Black, rect);
                }
            }
            if (brush != null)
            {
                Widget.FillRectangle(brush, rect);
            }
        }
Пример #43
0
        public System.Windows.Rect MakeVisible(System.Windows.Media.Visual visual, System.Windows.Rect rectangle)
        {
            if (rectangle.IsEmpty || visual == null ||
                visual == this || !base.IsAncestorOf(visual))
            {
                return(Rect.Empty);
            }

            double    dblOffsetX = 0;
            UIElement uieControlToMakeVisible = null;

            for (int i = 0; i < this.InternalChildren.Count; i++)
            {
                if ((Visual)this.InternalChildren[i] == visual)
                {
                    uieControlToMakeVisible = this.InternalChildren[i];
                    dblOffsetX = getLeftEdge(this.InternalChildren[i]);
                    break;
                }
            }

            if (uieControlToMakeVisible != null)
            {
                if (uieControlToMakeVisible == this.InternalChildren[0])
                {
                    dblOffsetX = 0;
                }
                else if (uieControlToMakeVisible == this.InternalChildren[this.InternalChildren.Count - 1])
                {
                    dblOffsetX = this.ExtentWidth - this.Viewport.Width;
                }
                else
                {
                    dblOffsetX = CalculateNewScrollOffset(
                        this.HorizontalOffset,
                        this.HorizontalOffset + this.Viewport.Width,
                        dblOffsetX,
                        dblOffsetX + uieControlToMakeVisible.DesiredSize.Width
                        );
                }

                SetHorizontalOffset(dblOffsetX);
                rectangle = new Rect(this.HorizontalOffset, 0, uieControlToMakeVisible.DesiredSize.Width, this.Viewport.Height);
            }

            return(rectangle);
        }
Пример #44
0
        public GraphicsHandler(swm.Visual visual, swm.DrawingContext context, sw.Rect?clipRect)
        {
            this.visual = visual;

            this.Control = context;

            if (DPI != 1.0)
            {
                this.Control.PushTransform(new swm.ScaleTransform(DPI, DPI));
            }

            if (clipRect != null)
            {
                this.Control.PushClip(new swm.RectangleGeometry(clipRect.Value));
            }
            this.ImageInterpolation = Eto.Drawing.ImageInterpolation.Default;
        }
Пример #45
0
        public GraphicsHandler(swm.Visual visual, swm.DrawingContext context, sw.Rect bounds, RectangleF initialClip, bool shouldDispose = true)
        {
            disposeControl = shouldDispose;
            this.visual    = visual;
            drawingVisual  = visual as swm.DrawingVisual;

            Control = context;

            this.bounds      = bounds;
            this.initialClip = initialClip;

            PushGuideLines(bounds);

            Control.PushClip(new swm.RectangleGeometry(bounds));

            ImageInterpolation = ImageInterpolation.Default;
        }
        internal XpsDocumentGenerator(
			Visual mainPrintContent,
			IEnumerable<PrintContent> additionalPrintContent,
			IViewDrawingState viewDrawingState,
			int width,
			int height,
			int pageMargin)
        {
            _mainPrintContent = mainPrintContent;
            _additionalPrintContent = additionalPrintContent;
            _viewDrawingState = viewDrawingState;
            PageMargin = pageMargin;
            Width = width;
            Height = height;

            InitializeComponent();
        }
Пример #47
0
        public GraphicsHandler(swm.Visual visual, swm.DrawingContext context, sw.Rect bounds, bool shouldDispose = true)
        {
            this.disposeControl = shouldDispose;
            this.visual         = visual;
            this.drawingVisual  = visual as swm.DrawingVisual;

            this.Control = context;

            //if (DPI != new sw.Size(1.0, 1.0))
            //	this.Control.PushTransform (new swm.ScaleTransform (DPI.Width, DPI.Height));
            var dpi = DPI;

            this.bounds = bounds;

            this.Control.PushClip(new swm.RectangleGeometry(bounds));

            PushGuideLines(bounds);

            this.ImageInterpolation = Eto.Drawing.ImageInterpolation.Default;
        }
Пример #48
0
        public void zapiszRysunek(String nazwaPliku, int width, int height, System.Windows.Media.Visual MyCanvas)
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.FileName = "savedimage.jpg";
            int    krotnoscPliku = 0;
            string filename;

            if (nazwaPliku != "savedimage")
            {
                if (File.Exists(@"litery\" + nazwaPliku + ".jpg"))
                {
                    do
                    {
                        krotnoscPliku++;
                    } while (File.Exists(@"litery\" + nazwaPliku + krotnoscPliku + ".jpg")); // sprawdza czy plik o danej nazwie istnieje
                }
                filename = @"litery\" + nazwaPliku + krotnoscPliku + ".jpg";
            }
            else
            {
                filename = dlg.FileName;
            }

            RenderTargetBitmap rtb =
                new RenderTargetBitmap(width, height, 96d, 96d, PixelFormats.Default);

            rtb.Render(MyCanvas);

            using (FileStream fs = new FileStream(filename, FileMode.Create))
            {
                File.SetAttributes(filename, FileAttributes.Normal);
                BmpBitmapEncoder encoder = new BmpBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(rtb));
                encoder.Save(fs);
                fs.Close();
            }
        }
Пример #49
0
        public void SetCover(System.Windows.Media.Visual visualCover)
        {
            GenerateRootPath();

            RenderTargetBitmap bmp = new RenderTargetBitmap(400, 400, 96, 96, PixelFormats.Pbgra32);

            bmp.Render(visualCover);
            PngBitmapEncoder png = new PngBitmapEncoder();

            png.Frames.Add(BitmapFrame.Create(bmp));

            string fileName = Guid.NewGuid().ToString() + ".png";

            string path = RootPath + "\\" + fileName;

            using (Stream stm = File.Create(path))
            {
                png.Save(stm);
            }

            CoverImageSource   = path;
            DisplayCoverSource = fileName;
        }
Пример #50
0
        private static Rectangle GetTopLevelClientRelativeRect(
            UIElement element)
        {
            // Get top-most visual.
            System.Windows.Media.Visual parent = element;
            while (System.Windows.Media.VisualTreeHelper.GetParent(parent) != null)
            {
                parent = (System.Windows.Media.Visual)System.Windows.Media.VisualTreeHelper.GetParent(parent);
            }

            // Get the points for the rectangle and transform them.
            double height = element.RenderSize.Height;
            double width  = element.RenderSize.Width;

            System.Windows.Point[] points = new System.Windows.Point[4];
            points[0] = new System.Windows.Point(0, 0);
            points[1] = new System.Windows.Point(width, 0);
            points[2] = new System.Windows.Point(0, height);
            points[3] = new System.Windows.Point(width, height);

            System.Windows.Media.Matrix           m;
            System.Windows.Media.GeneralTransform gt = element.TransformToAncestor(parent);
            System.Windows.Media.Transform        t  = gt as System.Windows.Media.Transform;
            if (t == null)
            {
                //throw new System.ApplicationException("//
                GlobalLog.LogEvidence(new System.ApplicationException("//TODO: Handle GeneralTransform Case - introduced by Transforms Breaking Change"));
            }
            m = t.Value;
            m.Transform(points);
            System.Windows.Point topLeft, bottomRight;
            CalculateBoundingPoints(points, out topLeft, out bottomRight);
            return(new Rectangle(
                       (int)topLeft.X, (int)topLeft.Y,
                       (int)bottomRight.X - (int)topLeft.X,
                       (int)bottomRight.Y - (int)topLeft.Y));
        }
 internal Enumerator(VisualCollection collection)
 {
     _collection = collection;
     _index = -1; // not started.
     _version = _collection.Version;
     _currentElement = null;
 }
Пример #52
0
 /// <summary> 
 /// This constructor takes a visual and point respresenting a hit.
 /// </summary> 
 public GeometryHitTestResult(
     Visual visualHit,
     IntersectionDetail intersectionDetail) : base(visualHit)
 { 
     _intersectionDetail = intersectionDetail;
 } 
 public abstract void WriteAsync(Visual visual, PrintTicket printTicket, object userState);
            /// <summary>
            /// Advances the enumerator to the next element of the collection.
            /// </summary>
            public bool MoveNext()
            {
                _collection.VerifyAPIReadOnly();

                if (_version == _collection.Version)
                {
                    if ((_index > -2) && (_index < (_collection.InternalCount - 1)))
                    {
                        _index++;
                        _currentElement = _collection[_index];
                        return true;
                    }
                    else
                    {
                        _currentElement = null;
                        _index = -2; // -2 <=> reached the end.
                        return false;
                    }
                }
                else
                {
                    throw new InvalidOperationException(SR.Get(SRID.Enumerator_CollectionChanged));
                }
            }
 public abstract void WriteAsync(Visual visual, PrintTicket printTicket);
 /// <summary>
 /// Asynchronous Write a single Visual and close package
 /// </summary>
 public abstract void WriteAsync(Visual visual, object userState);
 /// <summary>
 /// Asynchronous Write a single Visual and close package
 /// </summary>
 public abstract void WriteAsync(Visual visual);
 /// <summary>
 /// Write a single Visual and close package
 /// </summary>
 public abstract void Write(Visual visual);
 internal void VerifyAPIReadOnly(Visual other)
 {
     Debug.Assert(_owner != null);
     _owner.VerifyAPIReadOnly(other);
 }
Пример #60
-1
        public void Print(Visual visual, string description)
        {
            PrintDialog dialog = new PrintDialog();

            if (dialog.ShowDialog().GetValueOrDefault())
            {
                dialog.PrintVisual(visual, description);
            }
        }