예제 #1
0
파일: ClipSection.cs 프로젝트: mhusen/Eto
		Control PathClip()
		{
			var control = new Drawable { Size = new Size(350, 250) };
			control.Paint += (sender, e) =>
			{
				var path = new GraphicsPath();
				path.AddEllipse(25, 25, 50, 50);
				path.AddRectangle(125, 25, 50, 50);
				path.AddLines(new PointF(225, 25), new PointF(225, 75), new PointF(275, 50));
				path.CloseFigure();

				e.Graphics.SetClip(path);
				if (ResetClip)
					e.Graphics.ResetClip();
				e.Graphics.FillRectangle(Brushes.Blue, path.Bounds);

				path.Transform(Matrix.FromTranslation(0, 75));
				e.Graphics.SetClip(path);
				if (ResetClip)
					e.Graphics.ResetClip();
				e.Graphics.FillRectangle(Brushes.Red, path.Bounds);

				path.Transform(Matrix.FromTranslation(0, 75));
				e.Graphics.SetClip(path);
				if (ResetClip)
					e.Graphics.ResetClip();
				e.Graphics.FillRectangle(Brushes.Green, path.Bounds);
			};
			PropertyChanged += (sender, e) =>
			{
				if (e.PropertyName == "ResetClip")
					control.Invalidate();
			};
			return control;
		}
예제 #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();
			}
		}
예제 #3
0
		/// <summary>
		/// Draws a polygon with the specified <paramref name="points"/>
		/// </summary>
		/// <param name="color">Color to draw the polygon lines</param>
		/// <param name="points">Points of the polygon</param>
		public void DrawPolygon (Color color, IEnumerable<Point> points)
		{
			var path = new GraphicsPath (Generator);
			path.AddLines (points);
			DrawPath (color, path);
		}
예제 #4
0
		GraphicsPath CreatePath()
		{
			var newPath = new GraphicsPath();
			var start = StartFigures;
			var close = CloseFigures;

			// connected segments

			newPath.MoveTo(10, 10);
			newPath.LineTo(20, 90);
			newPath.LineTo(10, 60);
			newPath.LineTo(90, 80);
			newPath.LineTo(60, 30);
			if (close && start)
				newPath.CloseFigure();

			if (start)
				newPath.StartFigure();
			newPath.AddArc(100, 0, 100, 50, 200, -160);
			if (close && start)
				newPath.CloseFigure();

			if (start)
				newPath.StartFigure();
			newPath.AddBezier(new PointF(200, 10), new PointF(285, 20), new PointF(210, 85), new PointF(300, 90));
			if (close && start)
				newPath.CloseFigure();

			if (start)
				newPath.StartFigure();
			newPath.AddCurve(new PointF(310, 90), new PointF(390, 90), new PointF(390, 10), new PointF(310, 10));
			if (close && start)
				newPath.CloseFigure();

			if (start)
				newPath.StartFigure();
			newPath.AddLine(410, 10, 410, 90);
			if (close && start)
				newPath.CloseFigure();

			if (start)
				newPath.StartFigure();
			newPath.AddLines(new PointF(420, 10), new PointF(420, 90));
			if (close && start)
				newPath.CloseFigure();

			if (start)
				newPath.StartFigure();
			newPath.AddLines(new PointF(430, 10), new PointF(430, 90));
			if (close)
				newPath.CloseFigure();

			// separate segments

			if (start)
				newPath.StartFigure();
			newPath.AddEllipse(100, 100, 100, 45);
			if (close)
				newPath.CloseFigure();

			if (start)
				newPath.StartFigure();
			newPath.AddRectangle(10, 110, 80, 80);
			if (close)
				newPath.CloseFigure();

			// at the end, draw a line so we can potentially connect to parent path
			if (start)
				newPath.StartFigure();
			newPath.AddLines(new PointF(440, 10), new PointF(440, 90));
			if (close)
				newPath.CloseFigure();

			return newPath;
		}
예제 #5
0
		/// <summary>
		/// Draws an outline of a polygon with the specified <paramref name="points"/>
		/// </summary>
		/// <param name="pen">Color to draw the polygon lines</param>
		/// <param name="points">Points of the polygon</param>
		public void DrawPolygon (Pen pen, params PointF[] points)
		{
			var path = new GraphicsPath (Generator);
			path.AddLines (points);
			DrawPath (pen, path);
		}
예제 #6
0
		/// <summary>
		/// Draws a 1 pixel wide outline of a polygon with the specified <paramref name="points"/>
		/// </summary>
		/// <param name="color">Color to draw the polygon lines</param>
		/// <param name="points">Points of the polygon</param>
		public void DrawPolygon (Color color, params PointF[] points)
		{
			var path = new GraphicsPath (Generator);
			path.AddLines (points);
			using (var pen = new Pen (color, 1f, Generator))
				DrawPath (pen, path);
		}
예제 #7
0
		/// <summary>
		/// Fills a polygon defined by <paramref name="points"/> with the specified <paramref name="brush"/>
		/// </summary>
		/// <param name="brush">Brush to fill the polygon</param>
		/// <param name="points">Points of the polygon</param>
		public void FillPolygon (Brush brush, params PointF[] points)
		{
			var path = new GraphicsPath (Generator);
			path.AddLines (points);
			FillPath (brush, path);
		}
예제 #8
0
		/// <summary>
		/// Fills a polygon defined by <paramref name="points"/> with the specified <paramref name="color"/>
		/// </summary>
		/// <param name="color">Fill color</param>
		/// <param name="points">Points of the polygon</param>
		public void FillPolygon (Color color, params PointF[] points)
		{
			var path = new GraphicsPath (Generator);
			path.AddLines (points);
			using (var brush = new SolidBrush (color, Generator))
				FillPath (brush, path);
		}
예제 #9
0
파일: Graphics.cs 프로젝트: mhusen/Eto
		/// <summary>
		/// Draws an outline of a polygon with the specified <paramref name="points"/>
		/// </summary>
		/// <param name="pen">Color to draw the polygon lines</param>
		/// <param name="points">Points of the polygon</param>
		public void DrawPolygon(Pen pen, params PointF[] points)
		{
			var path = new GraphicsPath();
			path.AddLines(points);
			path.LineTo(points[0]);
			DrawPath(pen, path);
		}