Example #1
0
        public static ImageSource GetImage(LineCapExtension join, bool isForEndCap)
        {
            const int    bmpHeight = 24;
            const int    bmpWidth  = 48;
            const double lineWidth = bmpHeight * 0.4;

            if (null == _interopBitmap)
            {
                _interopBitmap = new GdiToWpfBitmap(bmpWidth, bmpHeight);
            }

            using (var grfx = _interopBitmap.BeginGdiPainting())
            {
                grfx.CompositingMode = sdd.CompositingMode.SourceCopy;
                grfx.FillRectangle(System.Drawing.Brushes.Transparent, 0, 0, bmpWidth, bmpHeight);

                var linePen = new System.Drawing.Pen(System.Drawing.Brushes.Black, (float)Math.Ceiling(lineWidth));
                if (isForEndCap)
                {
                    join.SetEndCap(linePen);
                    grfx.DrawLine(linePen, 0, 0.5f * bmpHeight, bmpWidth * (1 - 0.25f), 0.5f * bmpHeight);
                }
                else
                {
                    join.SetStartCap(linePen);
                    grfx.DrawLine(linePen, 0.25f * bmpWidth, 0.5f * bmpHeight, bmpWidth, 0.5f * bmpHeight);
                }
                _interopBitmap.EndGdiPainting();
            }

            var img = new WriteableBitmap(_interopBitmap.WpfBitmap);

            img.Freeze();
            return(img);
        }
Example #2
0
        /// <summary>
        /// Renders the overlay (the drawing that designates selected rectangles, handles and so on) immediately in the current thread. Then it is stored
        /// in cachedGraphImage and is also immediatly assigned to be shown in the view.
        /// Attention: if there is no cached bitmap, a new bitmap is created, but this must be done in the Gui context, so this can lead to deadlocks.
        /// </summary>
        private void RenderOverlayAndShowImmediately()
        {
            var         controller       = Controller;
            var         cachedGraphImage = _cachedGraphImage;
            ImageSource overlay          = null;

            if (
                null != controller &&
                controller.IsOverlayPaintingRequired &&
                null != cachedGraphImage &&
                cachedGraphImage.BitmapSize_Pixel.Width > 1 &&
                cachedGraphImage.BitmapSize_Pixel.Height > 1)
            {
                var size = cachedGraphImage.BitmapSize_Pixel;

                if (!_gdiWpfBitmapManager.TryTake(size, out var bmp))
                {
                    Current.Dispatcher.InvokeIfRequired(() => bmp = new GdiToWpfBitmap(size.Width, size.Height));
                }

                try
                {
                    overlay = GetImageSourceByRenderingOverlay(controller, bmp, cachedGraphImage);
                }
                finally
                {
                    _gdiWpfBitmapManager.Add(bmp.GdiSize, bmp);
                }
            }
            if (null != _cachedGraphImage)
            {
                _cachedGraphImage.CachedOverlayImageSource = overlay;
            }
            _graphOverlay.Source = overlay;
        }
Example #3
0
        /// <summary>
        /// Causes a complete redrawing of the graph. The cached graph bitmap will be marked as dirty and a repainting of the graph area is triggered with Gui render priority.
        /// Note: it is save to call this function from non-Gui threads.
        /// </summary>
        private void StartCompleteRepaint()
        {
            var controller = Controller;

            if (null == controller)
            {
                return;
            }

            // rendering in the background
            Altaxo.Graph.Gdi.GraphDocumentRenderManager.Instance.AddTask(
                controller,
                controller.Doc,
                (graphDocument, token) =>
            {
                if (graphDocument.IsDisposeInProgress)
                {
                    return;
                }

                var size = _cachedGraphSize_Pixels;

                if (size.Width > 1 && size.Height > 1)
                {
                    if (!_gdiWpfBitmapManager.TryTake(size, out var bmp))
                    {
                        Current.Dispatcher.InvokeIfRequired((Action)(() => bmp = new GdiToWpfBitmap(size.Width, size.Height)));
                    }

                    var grfx = GetGraphicsContextFromWpfGdiBitmap(bmp);
                    controller.ScaleForPaintingGraphDocument(grfx);
                    var cachedGraphImage = new CachedGraphImage {
                        ZoomFactor = controller.ZoomFactor, ViewPortsUpperLeftCornerInGraphCoordinates = controller.PositionOfViewportsUpperLeftCornerInGraphCoordinates, Size = _cachedGraphSize_96thInch, BitmapSize_Pixel = size
                    };

                    if (!graphDocument.IsDisposeInProgress)
                    {
                        graphDocument.Paint(grfx, false);
                    }

                    Current.Dispatcher.InvokeIfRequired(() =>
                    {
                        var bmpSource = bmp.WpfBitmapSource;
                        cachedGraphImage.CachedGraphImageSource = bmpSource;
                        _cachedGraphImage  = cachedGraphImage;
                        _graphImage.Source = bmpSource;
                        _isGraphUpToDate   = true;
                        grfx.Dispose();

                        var overlay          = GetImageSourceByRenderingOverlay(controller, bmp, cachedGraphImage);
                        _graphOverlay.Source = overlay;
                        cachedGraphImage.CachedOverlayImageSource = overlay;
                        _gdiWpfBitmapManager.Add(bmp.GdiSize, bmp);

                        ShowCachedGraphImage();
                    });
                }
            }
                );
        }
Example #4
0
        /// <summary>
        /// Called by the PresentationGraphController to get a new graphics context for painting.
        /// </summary>
        /// <returns></returns>
        public static System.Drawing.Graphics GetGraphicsContextFromWpfGdiBitmap(GdiToWpfBitmap gdiWpfBitmap)
        {
            var grfx = gdiWpfBitmap.BeginGdiPainting();

            grfx.ResetTransform();
            grfx.PageScale = 1;
            grfx.PageUnit  = System.Drawing.GraphicsUnit.Pixel;
            return(grfx);
        }
Example #5
0
		public TextGraphicControl()
		{
			InitializeComponent();

			_backgroundGlue = new BackgroundControlsGlue();
			_backgroundGlue.CbStyle = _cbBackgroundStyle;
			_backgroundGlue.CbBrush = _cbBackgroundBrush;
			_backgroundGlue.BackgroundStyleChanged += new EventHandler(EhBackgroundStyleChanged);
			_backgroundGlue.BackgroundBrushChanged += new EventHandler(EhBackgroundStyleChanged);

			_previewBitmap = new GdiToWpfBitmap(16, 16);
			m_pnPreview.Source = _previewBitmap.WpfBitmap;
		}
Example #6
0
        public void UpdatePreview(BrushX brush)
        {
            if (null == _previewPanel || null == brush)
            {
                return;
            }

            int height = (int)_previewPanel.ActualHeight;
            int width  = (int)_previewPanel.ActualWidth;

            if (height <= 0)
            {
                height = 64;
            }
            if (width <= 0)
            {
                width = 64;
            }

            if (null == _previewBitmap)
            {
                _previewBitmap       = new GdiToWpfBitmap(width, height);
                _previewPanel.Source = _previewBitmap.WpfBitmap;
            }

            if (width != _previewBitmap.GdiRectangle.Width || height != _previewBitmap.GdiRectangle.Height)
            {
                _previewBitmap.Resize(width, height);
                _previewPanel.Source = _previewBitmap.WpfBitmap;
            }

            using (var grfx = _previewBitmap.BeginGdiPainting())
            {
                var fullRect = _previewBitmap.GdiRectangle;

                grfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                grfx.FillRectangle(System.Drawing.Brushes.Transparent, fullRect);
                grfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

                var r2 = fullRect;
                r2.Inflate(-r2.Width / 4, -r2.Height / 4);
                //grfx.FillRectangle(System.Drawing.Brushes.Black, r2);

                brush.SetEnvironment(fullRect, BrushX.GetEffectiveMaximumResolution(grfx));
                grfx.FillRectangle(brush, fullRect);

                _previewBitmap.EndGdiPainting();
            }
        }
Example #7
0
        public TextGraphicControl()
        {
            InitializeComponent();

            _backgroundGlue = new BackgroundControlsGlue
            {
                CbStyle = _cbBackgroundStyle,
                CbBrush = _cbBackgroundBrush
            };
            _backgroundGlue.BackgroundStyleChanged += new EventHandler(EhBackgroundStyleChanged);
            _backgroundGlue.BackgroundBrushChanged += new EventHandler(EhBackgroundStyleChanged);

            _previewBitmap     = new GdiToWpfBitmap(16, 16);
            m_pnPreview.Source = _previewBitmap.WpfBitmap;
        }
Example #8
0
 private void EhPreviewImageSizeChanged(object sender, SizeChangedEventArgs e)
 {
     _previewImage.Width  = e.NewSize.Width;
     _previewImage.Height = e.NewSize.Height;
     if (null == _previewBitmap)
     {
         _previewBitmap       = new GdiToWpfBitmap((int)e.NewSize.Width, (int)e.NewSize.Height);
         _previewImage.Source = _previewBitmap.WpfBitmap;
     }
     else
     {
         _previewBitmap.Resize((int)e.NewSize.Width, (int)e.NewSize.Height);
         _previewImage.Source = _previewBitmap.WpfBitmap;
     }
     UpdatePreview();
 }
Example #9
0
        private void UpdatePreviewPanel()
        {
            if (null == _previewPanel || null == _pen)
            {
                return;
            }

            int height = (int)_previewPanel.ActualHeight;
            int width  = (int)_previewPanel.ActualWidth;

            if (height <= 0)
            {
                height = 64;
            }
            if (width <= 0)
            {
                width = 64;
            }

            if (null == _previewBitmap)
            {
                _previewBitmap       = new GdiToWpfBitmap(width, height);
                _previewPanel.Source = _previewBitmap.WpfBitmap;
            }

            if (width != _previewBitmap.GdiRectangle.Width || height != _previewBitmap.GdiRectangle.Height)
            {
                _previewBitmap.Resize(width, height);
                _previewPanel.Source = _previewBitmap.WpfBitmap;
            }

            using (var grfx = _previewBitmap.BeginGdiPainting())
            {
                var fullRect = _previewBitmap.GdiRectangle;
                grfx.FillRectangle(System.Drawing.Brushes.White, fullRect);
                _pen.BrushHolder.SetEnvironment(fullRect, BrushX.GetEffectiveMaximumResolution(grfx));
                grfx.DrawLine(_pen, fullRect.Width / 6, fullRect.Height / 2, (fullRect.Width * 5) / 6, fullRect.Height / 2);

                _previewBitmap.EndGdiPainting();
            }
        }
Example #10
0
		/// <summary>
		/// Causes a complete redrawing of the graph. The cached graph bitmap will be marked as dirty and a repainting of the graph area is triggered with Gui render priority.
		/// Note: it is save to call this function from non-Gui threads.
		/// </summary>
		private void StartCompleteRepaint()
		{
			var controller = Controller;
			if (null == controller)
				return;

			// rendering in the background
			Altaxo.Graph.Gdi.GraphDocumentRenderManager.Instance.AddTask(
				controller,
				controller.Doc,
				(graphDocument, token) =>
				{
					if (graphDocument.IsDisposeInProgress)
						return;

					var size = _cachedGraphSize_Pixels;

					if (size.Width > 1 && size.Height > 1)
					{
						GdiToWpfBitmap bmp;
						if (!_gdiWpfBitmapManager.TryTake(size, out bmp))
							Current.Gui.Execute(() => bmp = new GdiToWpfBitmap(size.Width, size.Height));

						var grfx = GetGraphicsContextFromWpfGdiBitmap(bmp);
						controller.ScaleForPaintingGraphDocument(grfx);
						var cachedGraphImage = new CachedGraphImage { ZoomFactor = controller.ZoomFactor, ViewPortsUpperLeftCornerInGraphCoordinates = controller.PositionOfViewportsUpperLeftCornerInGraphCoordinates, Size = _cachedGraphSize_96thInch, BitmapSize_Pixel = size };

						if (!graphDocument.IsDisposeInProgress)
							graphDocument.Paint(grfx, false);

						Current.Gui.Execute(() =>
						{
							var bmpSource = bmp.WpfBitmapSource;
							cachedGraphImage.CachedGraphImageSource = bmpSource;
							_cachedGraphImage = cachedGraphImage;
							_graphImage.Source = bmpSource;
							_isGraphUpToDate = true;
							grfx.Dispose();

							var overlay = GetImageSourceByRenderingOverlay(controller, bmp, cachedGraphImage);
							_graphOverlay.Source = overlay;
							cachedGraphImage.CachedOverlayImageSource = overlay;
							_gdiWpfBitmapManager.Add(bmp.GdiSize, bmp);

							ShowCachedGraphImage();
						});
					}
				}
				);
		}
Example #11
0
		/// <summary>
		/// Called by the PresentationGraphController to get a new graphics context for painting.
		/// </summary>
		/// <returns></returns>
		public static System.Drawing.Graphics GetGraphicsContextFromWpfGdiBitmap(GdiToWpfBitmap gdiWpfBitmap)
		{
			var grfx = gdiWpfBitmap.BeginGdiPainting();
			grfx.ResetTransform();
			grfx.PageScale = 1;
			grfx.PageUnit = System.Drawing.GraphicsUnit.Pixel;
			return grfx;
		}
Example #12
0
		private void UpdatePreviewPanel()
		{
			if (null == _previewPanel || null == _pen)
				return;

			int height = (int)_previewPanel.ActualHeight;
			int width = (int)_previewPanel.ActualWidth;
			if (height <= 0)
				height = 64;
			if (width <= 0)
				width = 64;

			if (null == _previewBitmap)
			{
				_previewBitmap = new GdiToWpfBitmap(width, height);
				_previewPanel.Source = _previewBitmap.WpfBitmap;
			}

			if (width != _previewBitmap.GdiRectangle.Width || height != _previewBitmap.GdiRectangle.Height)
			{
				_previewBitmap.Resize(width, height);
				_previewPanel.Source = _previewBitmap.WpfBitmap;
			}

			using (var grfx = _previewBitmap.BeginGdiPainting())
			{
				var fullRect = _previewBitmap.GdiRectangle;
				grfx.FillRectangle(System.Drawing.Brushes.White, fullRect);
				_pen.BrushHolder.SetEnvironment(fullRect, BrushX.GetEffectiveMaximumResolution(grfx));
				grfx.DrawLine(_pen, fullRect.Width / 6, fullRect.Height / 2, (fullRect.Width * 5) / 6, fullRect.Height / 2);

				_previewBitmap.EndGdiPainting();
			}
		}
Example #13
0
		private void EhPreviewImageSizeChanged(object sender, SizeChangedEventArgs e)
		{
			_previewImage.Width = e.NewSize.Width;
			_previewImage.Height = e.NewSize.Height;
			if (null == _previewBitmap)
			{
				_previewBitmap = new GdiToWpfBitmap((int)e.NewSize.Width, (int)e.NewSize.Height);
				_previewImage.Source = _previewBitmap.WpfBitmap;
			}
			else
			{
				_previewBitmap.Resize((int)e.NewSize.Width, (int)e.NewSize.Height);
				_previewImage.Source = _previewBitmap.WpfBitmap;
			}
			UpdatePreview();
		}
		public void UpdatePreview(BrushX brush)
		{
			if (null == _previewPanel || null == brush)
				return;

			int height = (int)_previewPanel.ActualHeight;
			int width = (int)_previewPanel.ActualWidth;
			if (height <= 0)
				height = 64;
			if (width <= 0)
				width = 64;

			if (null == _previewBitmap)
			{
				_previewBitmap = new GdiToWpfBitmap(width, height);
				_previewPanel.Source = _previewBitmap.WpfBitmap;
			}

			if (width != _previewBitmap.GdiRectangle.Width || height != _previewBitmap.GdiRectangle.Height)
			{
				_previewBitmap.Resize(width, height);
				_previewPanel.Source = _previewBitmap.WpfBitmap;
			}

			using (var grfx = _previewBitmap.BeginGdiPainting())
			{
				var fullRect = _previewBitmap.GdiRectangle;

				grfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
				grfx.FillRectangle(System.Drawing.Brushes.Transparent, fullRect);
				grfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

				var r2 = fullRect;
				r2.Inflate(-r2.Width / 4, -r2.Height / 4);
				//grfx.FillRectangle(System.Drawing.Brushes.Black, r2);

				brush.SetEnvironment(fullRect, BrushX.GetEffectiveMaximumResolution(grfx));
				grfx.FillRectangle(brush, fullRect);

				_previewBitmap.EndGdiPainting();
			}
		}
Example #15
0
 /// <summary>
 /// Renders the overlay (the drawing that designates selected rectangles, handles and so on) immediately in the current thread.
 /// Attention: if there is no cached bitmap, a new bitmap is created, but this must be done in the Gui context, so this can lead to deadlocks.
 /// </summary>
 private static ImageSource GetImageSourceByRenderingOverlay(GraphController controller, GdiToWpfBitmap bmp, CachedGraphImage cachedGraphImage)
 {
     if (controller.IsOverlayPaintingRequired)
     {
         using (var grfx = GetGraphicsContextFromWpfGdiBitmap(bmp))
         {
             controller.DoPaintOverlay(grfx, cachedGraphImage.ZoomFactor, cachedGraphImage.ViewPortsUpperLeftCornerInGraphCoordinates);
             return(bmp.WpfBitmapSource);
         }
     }
     else
     {
         return(null);
     }
 }
Example #16
0
		/// <summary>
		/// Renders the overlay (the drawing that designates selected rectangles, handles and so on) immediately in the current thread. Then it is stored
		/// in cachedGraphImage and is also immediatly assigned to be shown in the view.
		/// Attention: if there is no cached bitmap, a new bitmap is created, but this must be done in the Gui context, so this can lead to deadlocks.
		/// </summary>
		private void RenderOverlayAndShowImmediately()
		{
			var controller = Controller;
			var cachedGraphImage = _cachedGraphImage;
			ImageSource overlay = null;

			if (
				null != controller &&
				controller.IsOverlayPaintingRequired &&
				null != cachedGraphImage &&
				cachedGraphImage.BitmapSize_Pixel.Width > 1 &&
				cachedGraphImage.BitmapSize_Pixel.Height > 1)
			{
				var size = cachedGraphImage.BitmapSize_Pixel;

				GdiToWpfBitmap bmp;
				if (!_gdiWpfBitmapManager.TryTake(size, out bmp))
					Current.Gui.Execute(() => bmp = new GdiToWpfBitmap(size.Width, size.Height));

				try
				{
					overlay = GetImageSourceByRenderingOverlay(controller, bmp, cachedGraphImage);
				}
				finally
				{
					_gdiWpfBitmapManager.Add(bmp.GdiSize, bmp);
				}
			}
			if (null != _cachedGraphImage)
				_cachedGraphImage.CachedOverlayImageSource = overlay;
			_graphOverlay.Source = overlay;
		}
Example #17
0
		/// <summary>
		/// Renders the overlay (the drawing that designates selected rectangles, handles and so on) immediately in the current thread.
		/// Attention: if there is no cached bitmap, a new bitmap is created, but this must be done in the Gui context, so this can lead to deadlocks.
		/// </summary>
		private static ImageSource GetImageSourceByRenderingOverlay(GraphControllerWpf controller, GdiToWpfBitmap bmp, CachedGraphImage cachedGraphImage)
		{
			if (controller.IsOverlayPaintingRequired)
			{
				using (var grfx = GetGraphicsContextFromWpfGdiBitmap(bmp))
				{
					controller.DoPaintOverlay(grfx, cachedGraphImage.ZoomFactor, cachedGraphImage.ViewPortsUpperLeftCornerInGraphCoordinates);
					return bmp.WpfBitmapSource;
				}
			}
			else
			{
				return null;
			}
		}
Example #18
0
		public static ImageSource GetImage(ILineCap join, bool isForEndCap)
		{
			const int bmpHeight = 24;
			const int bmpWidth = 48;
			const double lineWidth = bmpHeight * 0.4;

			if (null == _interopBitmap)
				_interopBitmap = new GdiToWpfBitmap(bmpWidth, bmpHeight);

			using (var grfx = _interopBitmap.BeginGdiPainting())
			{
				grfx.CompositingMode = sdd.CompositingMode.SourceCopy;
				grfx.FillRectangle(System.Drawing.Brushes.Transparent, 0, 0, bmpWidth, bmpHeight);

				var linePen = new System.Drawing.Pen(System.Drawing.Brushes.Black, (float)Math.Ceiling(lineWidth));
				if (isForEndCap)
				{
					//join.SetEndCap(linePen);
					//grfx.DrawLine(linePen, 0, 0.5f * bmpHeight, bmpWidth * (1 - 0.25f), 0.5f * bmpHeight);
				}
				else
				{
					//join.SetStartCap(linePen);
					//grfx.DrawLine(linePen, 0.25f * bmpWidth, 0.5f * bmpHeight, bmpWidth, 0.5f * bmpHeight);
				}
				_interopBitmap.EndGdiPainting();
			}

			var img = new WriteableBitmap(_interopBitmap.WpfBitmap);
			img.Freeze();
			return img;
		}