Example #1
0
		static void EllipseAndCurveTest(Graphics graphics)
		{
			var path = new GraphicsPath();
			path.FillMode = FillMode.Winding;
			path.AddBezier(new PointF(10f, 6f), new PointF(10f, 4f), new PointF(8f, 2f), new PointF(6f, 2f));
			path.CloseFigure();
			var m = Matrix.Create();
			m.Scale(60f, 60f);
			graphics.SaveTransform();
			graphics.MultiplyTransform(m);
			var brush = new SolidBrush(Colors.Black);
			var pen = new Pen(Colors.Red, 0.1f);
			graphics.FillPath(brush, path);
			graphics.DrawPath(pen, path);
			brush.Dispose();
			pen.Dispose();
			var brushY = new SolidBrush(Color.FromArgb(0xFF, 0xFF, 0x00, 0x9F));
			var penB = new Pen(Color.FromArgb(0x00, 0x00, 0xFF, 0x9F), 0.1f);
			graphics.DrawEllipse(penB, 10f, 6f, 0.5f, 0.5f);
			graphics.FillEllipse(brushY, 10f, 6f, 0.5f, 0.5f);
			graphics.DrawEllipse(penB, 6f, 2f, 0.5f, 0.5f);
			graphics.FillEllipse(brushY, 6f, 2f, 0.5f, 0.5f);
			graphics.RestoreTransform();
		}
Example #2
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();
			}
		}
Example #3
0
		static void ScissorsTest(Graphics graphics)
		{
			var t = new
			{
				CenterX = 0f,
				CenterY = 0f,
				OffsetX = 200f,
				OffsetY = 50f,
				RotateAngle = 0f,
				SkewAngleY = 10f,
				SkewAngleX = 10f,
				ScaleX = 16f,
				ScaleY = 16f
			};

			var path = new GraphicsPath();
			path.FillMode = FillMode.Winding;
			// draw some scissors
			path.AddBezier(new PointF(9.64f, 7.64f), new PointF(9.87f, 7.14f), new PointF(10f, 6.59f), new PointF(10f, 6f));
			path.AddBezier(new PointF(10f, 6f), new PointF(10f, 3.79f), new PointF(8.21f, 2f), new PointF(6f, 2f));
			path.AddBezier(new PointF(6f, 2f), new PointF(3.79f, 2f), new PointF(2f, 3.79f), new PointF(2f, 6f));
			path.AddBezier(new PointF(2f, 6f), new PointF(2f, 8.21f), new PointF(3.79f, 10f), new PointF(6f, 10f));
			path.AddBezier(new PointF(6f, 10f), new PointF(6.59f, 10f), new PointF(7.14f, 9.87f), new PointF(7.64f, 9.64f));
			path.AddLine(7.64f, 9.64f, 10f, 12f);
			path.AddLine(10f, 12f, 7.64f, 14.36f);
			path.AddBezier(new PointF(7.64f, 14.36f), new PointF(7.14f, 14.13f), new PointF(6.59f, 14f), new PointF(6f, 14f));
			path.AddBezier(new PointF(6f, 14f), new PointF(3.79f, 14f), new PointF(2f, 15.79f), new PointF(2f, 18f));
			path.AddBezier(new PointF(2f, 18f), new PointF(2f, 20.21f), new PointF(3.79f, 22f), new PointF(6f, 22f));
			path.AddBezier(new PointF(6f, 22f), new PointF(8.21f, 22f), new PointF(10f, 20.21f), new PointF(10f, 18f));
			path.AddBezier(new PointF(10f, 18f), new PointF(10f, 17.41f), new PointF(9.87f, 16.86f), new PointF(9.64f, 16.36f));
			path.AddLine(9.64f, 16.36f, 12f, 14f);
			path.AddLine(12f, 14f, 19f, 21f);
			path.AddLine(19f, 21f, 22f, 21f);
			path.AddLine(22f, 21f, 22f, 20f);
			path.AddLine(22f, 20f, 9.64f, 7.64f);
			path.CloseFigure();
			path.AddBezier(new PointF(6f, 8f), new PointF(4.9f, 8f), new PointF(4f, 7.11f), new PointF(4f, 6f));
			path.AddBezier(new PointF(4f, 6f), new PointF(4f, 4.89f), new PointF(4.9f, 4f), new PointF(6f, 4f));
			path.AddBezier(new PointF(6f, 4f), new PointF(7.1f, 4f), new PointF(8f, 4.89f), new PointF(8f, 6f));
			path.AddBezier(new PointF(8f, 6f), new PointF(8f, 7.11f), new PointF(7.1f, 8f), new PointF(6f, 8f));
			path.CloseFigure();
			path.AddBezier(new PointF(6f, 20f), new PointF(4.9f, 20f), new PointF(4f, 19.11f), new PointF(4f, 18f));
			path.AddBezier(new PointF(4f, 18f), new PointF(4f, 16.89f), new PointF(4.9f, 16f), new PointF(6f, 16f));
			path.AddBezier(new PointF(6f, 16f), new PointF(7.1f, 16f), new PointF(8f, 16.89f), new PointF(8f, 18f));
			path.AddBezier(new PointF(8f, 18f), new PointF(8f, 19.11f), new PointF(7.1f, 20f), new PointF(6f, 20f));
			path.CloseFigure();
			path.AddBezier(new PointF(12f, 12.5f), new PointF(11.72f, 12.5f), new PointF(11.5f, 12.28f), new PointF(11.5f, 12f));
			path.AddBezier(new PointF(11.5f, 12f), new PointF(11.5f, 11.72f), new PointF(11.72f, 11.5f), new PointF(12f, 11.5f));
			path.AddBezier(new PointF(12f, 11.5f), new PointF(12.28f, 11.5f), new PointF(12.5f, 11.72f), new PointF(12.5f, 12f));
			path.AddBezier(new PointF(12.5f, 12f), new PointF(12.5f, 12.28f), new PointF(12.28f, 12.5f), new PointF(12f, 12.5f));
			path.CloseFigure();
			path.AddLine(19f, 3f, 13f, 9f);
			path.AddLine(13f, 9f, 15f, 11f);
			path.AddLine(15f, 11f, 22f, 4f);
			path.AddLine(22f, 4f, 22f, 3f);
			path.CloseFigure();
			path.AddBezier(new PointF(9.64f, 7.64f), new PointF(9.87f, 7.14f), new PointF(10f, 6.59f), new PointF(10f, 6f));
			path.AddBezier(new PointF(10f, 6f), new PointF(10f, 3.79f), new PointF(8.21f, 2f), new PointF(6f, 2f));
			path.AddBezier(new PointF(6f, 2f), new PointF(3.79f, 2f), new PointF(2f, 3.79f), new PointF(2f, 6f));
			path.AddBezier(new PointF(2f, 6f), new PointF(2f, 8.21f), new PointF(3.79f, 10f), new PointF(6f, 10f));
			path.AddBezier(new PointF(6f, 10f), new PointF(6.59f, 10f), new PointF(7.14f, 9.87f), new PointF(7.64f, 9.64f));
			path.AddLine(7.64f, 9.64f, 10f, 12f);
			path.AddLine(10f, 12f, 7.64f, 14.36f);
			path.AddBezier(new PointF(7.64f, 14.36f), new PointF(7.14f, 14.13f), new PointF(6.59f, 14f), new PointF(6f, 14f));
			path.AddBezier(new PointF(6f, 14f), new PointF(3.79f, 14f), new PointF(2f, 15.79f), new PointF(2f, 18f));
			path.AddBezier(new PointF(2f, 18f), new PointF(2f, 20.21f), new PointF(3.79f, 22f), new PointF(6f, 22f));
			path.AddBezier(new PointF(6f, 22f), new PointF(8.21f, 22f), new PointF(10f, 20.21f), new PointF(10f, 18f));
			path.AddBezier(new PointF(10f, 18f), new PointF(10f, 17.41f), new PointF(9.87f, 16.86f), new PointF(9.64f, 16.36f));
			path.AddLine(9.64f, 16.36f, 12f, 14f);
			path.AddLine(12f, 14f, 19f, 21f);
			path.AddLine(19f, 21f, 22f, 21f);
			path.AddLine(22f, 21f, 22f, 20f);
			path.AddLine(22f, 20f, 9.64f, 7.64f);
			path.CloseFigure();
			path.AddBezier(new PointF(6f, 8f), new PointF(4.9f, 8f), new PointF(4f, 7.11f), new PointF(4f, 6f));
			path.AddBezier(new PointF(4f, 6f), new PointF(4f, 4.89f), new PointF(4.9f, 4f), new PointF(6f, 4f));
			path.AddBezier(new PointF(6f, 4f), new PointF(7.1f, 4f), new PointF(8f, 4.89f), new PointF(8f, 6f));
			path.AddBezier(new PointF(8f, 6f), new PointF(8f, 7.11f), new PointF(7.1f, 8f), new PointF(6f, 8f));
			path.CloseFigure();
			path.AddBezier(new PointF(6f, 20f), new PointF(4.9f, 20f), new PointF(4f, 19.11f), new PointF(4f, 18f));
			path.AddBezier(new PointF(4f, 18f), new PointF(4f, 16.89f), new PointF(4.9f, 16f), new PointF(6f, 16f));
			path.AddBezier(new PointF(6f, 16f), new PointF(7.1f, 16f), new PointF(8f, 16.89f), new PointF(8f, 18f));
			path.AddBezier(new PointF(8f, 18f), new PointF(8f, 19.11f), new PointF(7.1f, 20f), new PointF(6f, 20f));
			path.CloseFigure();
			path.AddBezier(new PointF(12f, 12.5f), new PointF(11.72f, 12.5f), new PointF(11.5f, 12.28f), new PointF(11.5f, 12f));
			path.AddBezier(new PointF(11.5f, 12f), new PointF(11.5f, 11.72f), new PointF(11.72f, 11.5f), new PointF(12f, 11.5f));
			path.AddBezier(new PointF(12f, 11.5f), new PointF(12.28f, 11.5f), new PointF(12.5f, 11.72f), new PointF(12.5f, 12f));
			path.AddBezier(new PointF(12.5f, 12f), new PointF(12.5f, 12.28f), new PointF(12.28f, 12.5f), new PointF(12f, 12.5f));
			path.CloseFigure();
			path.AddLine(19f, 3f, 13f, 9f);
			path.AddLine(13f, 9f, 15f, 11f);
			path.AddLine(15f, 11f, 22f, 4f);
			path.AddLine(22f, 4f, 22f, 3f);
			path.CloseFigure();
			var m = Matrix.Create();
			var c = new PointF((float)t.CenterX, (float)t.CenterY);
			// translate
			m.Translate((float)t.OffsetX, (float)t.OffsetY);
			// rotate
			m.RotateAt((float)t.RotateAngle, c);
			// skew
			m.Translate(-c.X, -c.Y);
			m.Prepend(Matrix.Create(1, (float)Math.Tan(Math.PI * t.SkewAngleY / 180.0), (float)Math.Tan(Math.PI * t.SkewAngleX / 180.0), 1, 0, 0));
			m.Translate(c.X, c.Y);
			// scale
			m.ScaleAt((float)t.ScaleX, (float)t.ScaleY, (float)t.CenterX, (float)t.CenterY);
			graphics.SaveTransform();
			graphics.MultiplyTransform(m);
			var brush = new SolidBrush(Colors.Black);
			var pen = new Pen(Colors.Red, 0.5f);
			graphics.FillPath(brush, path);
			graphics.DrawPath(pen, path);
			brush.Dispose();
			pen.Dispose();
			graphics.RestoreTransform();
		}