protected sealed override void OnPaint(PaintEventArgs e)
		{
			if (EnableDoubleBuffering)
			{
				var screen = ParentWindow.Screen;
				var scale = screen.RealScale / screen.Scale;
				renderSize = Size.Round(e.ClipRectangle.Size * scale);
				if (bitmap == null ||
					bitmap.Size.Width < renderSize.Width ||
					bitmap.Size.Height < renderSize.Height)
				{
					if (bitmap != null)
						bitmap.Dispose();

					bitmap = new Bitmap(renderSize, PixelFormat.Format32bppRgba);
				}
				var bitmapGraphics = new Graphics(bitmap);
				bitmapGraphics.Clear(Brushes.Cached(BackgroundColor));
				bitmapGraphics.ScaleTransform(scale);
				bitmapGraphics.TranslateTransform(-e.ClipRectangle.Location);
				bitmapGraphics.SetClip(e.ClipRectangle * scale); // should be affected by transform

				var childArgs = new PaintEventArgs(bitmapGraphics, e.ClipRectangle);
				base.OnPaint(childArgs);

				OnBufferedPaint(childArgs);

				bitmapGraphics.Dispose();
				bitmapGraphics = null;
				e.Graphics.DrawImage(bitmap, new RectangleF(renderSize), e.ClipRectangle);
				if (Platform.IsWpf)
				{
					// wpf runs out of resources fast here, so we garbage collect
					GC.Collect();
				}
			}
			else
			{
				base.OnPaint(e);
				OnBufferedPaint(e);
			}
		}
Exemple #2
0
		void DrawSample(Graphics graphics)
		{
			using (graphics.Platform.Context)
			{
				graphics.FillRectangle(Brushes.Green, 0, 0, 200, 200);
				if (UseGraphicsPathClip)
				{
					var path = GraphicsPath.GetRoundRect(new RectangleF(10, 10, 180, 180), 20);
					graphics.SetClip(path);
				}
				else
					graphics.SetClip(new RectangleF(10, 10, 180, 180));

				if (UseClearColor)
					graphics.Clear(new SolidBrush(new Color(Colors.Red, 0.5f)));
				else
					graphics.Clear();
				graphics.FillEllipse(Brushes.Blue, 25, 25, 150, 150);
			}
		}
		public Graphics BeginDraw(PaintEventArgs e)
		{
			if (UseOffScreenBitmap)
			{
				if (OffscreenBitmap == null ||
					OffscreenBitmap.Size.Width < e.ClipRectangle.Width ||
					OffscreenBitmap.Size.Height < e.ClipRectangle.Height)
				{
					if (OffscreenBitmap != null)
						OffscreenBitmap.Dispose();

					OffscreenBitmap = new Bitmap(Size.Round(e.ClipRectangle.Size), PixelFormat.Format32bppRgba);
				}
				bitmapGraphics = new Graphics(OffscreenBitmap);
				bitmapGraphics.TranslateTransform(-e.ClipRectangle.Location);
				bitmapGraphics.SetClip(e.ClipRectangle);
				bitmapGraphics.Clear(Brushes.Cached(drawable.BackgroundColor));
				return bitmapGraphics;
			}
			return e.Graphics;
		}
Exemple #4
0
		Control DrawImageToRect()
		{
			var image64 = new Bitmap(new Size(64, 64), PixelFormat.Format32bppRgba);
			var image32 = new Bitmap(new Size(32, 32), PixelFormat.Format32bppRgba);

			using (var g = new Graphics(image64))
				g.Clear(Brushes.Cached(Colors.Green) as SolidBrush);

			using (var g = new Graphics(image32))
				g.Clear(Brushes.Cached(Colors.Blue) as SolidBrush);

			var bitmap = new Bitmap(new Size(105, 105), PixelFormat.Format32bppRgba);
			using (var g = new Graphics(bitmap))
			{
				// draw the big image at the origin, but with a smaller dest rect
				g.DrawImage(image64, new RectangleF(0, 0, 32, 32), new RectangleF(0, 0, 32, 32));
				// draw two guide images to indicate how big the green image should be
				g.DrawImage(image32, new PointF(70, 0));
				g.DrawImage(image32, new PointF(0, 70));
			}
			return new DrawableImageView { Image = bitmap };
		}
Exemple #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="g"></param>
        private void Draw(Graphics g)
        {
            g.AntiAlias = false;
            g.PixelOffsetMode = PixelOffsetMode.Half;

            g.TranslateTransform(_state.PanX, _state.PanY);
            g.ScaleTransform(_state.Zoom);

            var brush = new SolidBrush(_background);
            g.Clear(brush);
            brush.Dispose();

            var renderer = _context.Editor.Renderers[0];

            if (_context.Editor.Project == null)
                return;

            var container = _context.Editor.Project.CurrentContainer;

            if (container.Template != null)
            {
                DrawBackground(
                    g,
                    container.Template.Background,
                    container.Width,
                    container.Height);

                renderer.Draw(
                    g,
                    container.Template,
                    container.Properties,
                    null);
            }

            DrawBackground(
                g,
                container.Background,
                container.Width,
                container.Height);

            renderer.Draw(
                g,
                container,
                container.Properties,
                null);

            if (container.WorkingLayer != null)
            {
                renderer.Draw(
                    g,
                    container.WorkingLayer,
                    container.Properties,
                    null);
            }

            if (container.HelperLayer != null)
            {
                renderer.Draw(
                    g,
                    container.HelperLayer,
                    container.Properties,
                    null);
            }
        }