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);
			}
		}
		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;
		}
示例#3
0
		void Draw(Graphics g, Action<Pen> action)
		{
			var path = new GraphicsPath();
			path.AddLines(new PointF(0, 0), new PointF(100, 40), new PointF(0, 30), new PointF(50, 70));

			for (int i = 0; i < 4; i++)
			{
				float thickness = 1f + i * PenThickness;
				var pen = new Pen(Colors.Black, thickness);
				pen.LineCap = this.LineCap;
				pen.LineJoin = this.LineJoin;
				pen.DashStyle = this.DashStyle;
				if (action != null)
					action(pen);
				var y = i * 20;
				g.DrawLine(pen, 10, y, 110, y);
				
				y = 80 + i * 50;
				g.DrawRectangle(pen, 10, y, 100, 30);

				y = i * 70;
				g.DrawArc(pen, 140, y, 100, 80, 160, 160);
				
				y = i * 70;
				g.DrawEllipse(pen, 260, y, 100, 50);
				
				g.SaveTransform();
				y = i * 70;
				g.TranslateTransform(400, y);
				g.DrawPath(pen, path);
				g.RestoreTransform();
			}
		}
示例#4
0
		void DrawShapes(Brush brush, PointF location, Size size, Graphics g)
		{
			g.SaveTransform();
			g.TranslateTransform(location);
			g.RotateTransform(20);

			// rectangle
			g.FillRectangle(brush, new RectangleF(size));

			// ellipse
			g.TranslateTransform(0, size.Height + 20);
			g.FillEllipse(brush, new RectangleF(size));

			// pie
			g.TranslateTransform(0, size.Height + 20);
			g.FillPie(brush, new RectangleF(new SizeF(size.Width * 2, size.Height)), 0, 360);

			// polygon
			g.TranslateTransform(0, size.Height + 20);
			var polygon = GetPolygon();
			g.FillPolygon(brush, polygon);

			g.RestoreTransform();
		}
示例#5
0
		void DirectTests(Graphics g)
		{
			// test translate/rotate
			DrawRotatedLines(g, Colors.SkyBlue, rotatedLineCenter, (center, angle) => {
				g.TranslateTransform(center);
				g.RotateTransform(angle);
				g.TranslateTransform(-center);
			});

			// test translate/rotate/scale
			DrawRotatedLines(g, Colors.Salmon, rotatedLineCenter, (center, angle) => {
				g.TranslateTransform(center);
				g.RotateTransform(angle);
				g.TranslateTransform(-center);
				g.ScaleTransform(.4f);
			});

			// test rotating arcs
			DrawRotatedArcs(g, Colors.LightBlue, rotatedLineCenter, (center, angle) => {
				g.TranslateTransform(center);
				g.RotateTransform(angle);
				g.TranslateTransform(-center);
			});

			// test transformed text
			DrawRotatedText(g, Colors.Lime, rotatedTextCenter, (center, angle) => {
				g.TranslateTransform(center - 40);
				g.RotateTransform(angle);
				g.TranslateTransform(-center + 40);
			});

			// Test image drawing
			g.SaveTransform();
			g.TranslateTransform(imageScaleLocation + image.Size / 2);
			g.ScaleTransform(1, -1);
			g.TranslateTransform(-imageScaleLocation - image.Size / 2);
			g.DrawImage(image, imageScaleLocation);

			g.TranslateTransform(0, -50);
			g.TranslateTransform(imageScaleLocation + image.Size / 2);
			g.ScaleTransform(0.3f);
			g.TranslateTransform(-imageScaleLocation - image.Size / 2);
			g.DrawImage(image, imageScaleLocation);
			g.RestoreTransform();

			// test skewing
			g.SaveTransform();
			g.MultiplyTransform(Matrix.FromSkew(20, 20));
			var textSize = g.MeasureString(font, "Skewed Text");
			g.DrawText(font, Colors.White, new PointF(110, 0), "Skewed Text");
			g.DrawLine(Pens.White, 110, textSize.Height + 2, 110 + textSize.Width, textSize.Height + 2);
			
			g.RestoreTransform();

			// test more drawing operations
			g.SaveTransform();
			g.TranslateTransform(480, 20);
			g.ScaleTransform(0.4f);
			g.RotateTransform(90);
			PixelOffsetSection.Draw(g);
			g.RestoreTransform();
		}
示例#6
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);
            }
        }