public static void DrawTo(Graphics2D graphics2D, Mesh meshToDraw, Vector2 offset, double scale, RGBA_Bytes silhouetteColor)
		{
			graphics2D.Rasterizer.gamma(new gamma_power(.3));
			PathStorage polygonProjected = new PathStorage();
			foreach (Face face in meshToDraw.Faces)
			{
				if (face.normal.z > 0)
				{
					polygonProjected.remove_all();
					bool first = true;
					foreach (FaceEdge faceEdge in face.FaceEdges())
					{
						Vector2 position = new Vector2(faceEdge.firstVertex.Position.x, faceEdge.firstVertex.Position.y);
						position += offset;
						position *= scale;
						if (first)
						{
							polygonProjected.MoveTo(position.x, position.y);
							first = false;
						}
						else
						{
							polygonProjected.LineTo(position.x, position.y);
						}
					}
					graphics2D.Render(polygonProjected, silhouetteColor);
				}
			}
			graphics2D.Rasterizer.gamma(new gamma_none());
		}
Exemplo n.º 2
0
		protected override void DoDrawDirectionalArrow(Graphics2D graphics2D)
		{
			PathStorage littleArrow = new PathStorage();
			if (this.MenuDirection == Direction.Down)
			{
				littleArrow.MoveTo(-4, 0);
				littleArrow.LineTo(4, 0);
				littleArrow.LineTo(0, -5);
			}
			else if (this.MenuDirection == Direction.Up)
			{
				littleArrow.MoveTo(-4, -5);
				littleArrow.LineTo(4, -5);
				littleArrow.LineTo(0, 0);
			}
			else
			{
				throw new NotImplementedException("Pulldown direction has not been implemented");
			}

			if (!hasText)
			{
				if (UnderMouseState != UI.UnderMouseState.NotUnderMouse)
				{
					graphics2D.Render(littleArrow, LocalBounds.Right / 2, LocalBounds.Bottom + Height / 2 + 4, NormalArrowColor);
				}
				else
				{
					graphics2D.Render(littleArrow, LocalBounds.Right / 2, LocalBounds.Bottom + Height / 2 + 4, HoverArrowColor);
				}
			}
			else
			{
				base.DoDrawDirectionalArrow(graphics2D);
			}
		}
Exemplo n.º 3
0
 private void DrawDirectionalArrow(Graphics2D graphics2D)
 {
     PathStorage littleArrow = new PathStorage();
     if (this.MenuDirection == Direction.Down)
     {
         littleArrow.MoveTo(-4, 0);
         littleArrow.LineTo(4, 0);
         littleArrow.LineTo(0, -5);
     }
     else if (this.MenuDirection == Direction.Up)
     {
         littleArrow.MoveTo(-4, -5);
         littleArrow.LineTo(4, -5);
         littleArrow.LineTo(0, 0);
     }
     else
     {
         throw new NotImplementedException("Pulldown direction has not been implemented");
     }
     graphics2D.Render(littleArrow, LocalBounds.Right - 8, LocalBounds.Top - 4, borderColor);
 }
Exemplo n.º 4
0
 //直线
 public UIGraphic AddLine(float x1, float y1, float x2, float y2, CCColor4B stroke, double strokeThickness = 1)
 {
     if (stroke.A > 0)
     {
         //g.Line没有厚度
         PathStorage linesToDraw = new PathStorage();
         linesToDraw.remove_all();
         linesToDraw.MoveTo(x1, y1);
         linesToDraw.LineTo(x2, y2);
         Stroke StrockedLineToDraw = new Stroke(linesToDraw, strokeThickness);
         this.graphics2D.Render(StrockedLineToDraw, new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A));
     }
     return this;
 }
Exemplo n.º 5
0
        public void DrawLine(Pen pen, int x1, int y1, int x2, int y2)
        {
            var path = new PathStorage();
            path.MoveTo(x1,y1);
            path.LineTo(x2,y2);
            var stroke = new Stroke(path, (double)pen.Width);

            _InternalRender(stroke, new RGBA_Bytes((uint)pen.Color.ToArgb()) );
        }
Exemplo n.º 6
0
		private void DrawStuffForSelectedPart(Graphics2D graphics2D)
		{
			if (SelectedMeshGroup != null)
			{
				AxisAlignedBoundingBox selectedBounds = SelectedMeshGroup.GetAxisAlignedBoundingBox(SelectedMeshGroupTransform.TotalTransform);
				Vector3 boundsCenter = selectedBounds.Center;
				Vector3 centerTop = new Vector3(boundsCenter.x, boundsCenter.y, selectedBounds.maxXYZ.z);

				Vector2 centerTopScreenPosition = meshViewerWidget.TrackballTumbleWidget.GetScreenPosition(centerTop);
				centerTopScreenPosition = meshViewerWidget.TransformToParentSpace(this, centerTopScreenPosition);
				//graphics2D.Circle(screenPosition.x, screenPosition.y, 5, RGBA_Bytes.Cyan);

				PathStorage zArrow = new PathStorage();
				zArrow.MoveTo(-6, -2);
				zArrow.curve3(0, -4);
				zArrow.LineTo(6, -2);
				zArrow.LineTo(0, 12);
				zArrow.LineTo(-6, -2);

				VertexSourceApplyTransform translate = new VertexSourceApplyTransform(zArrow, Affine.NewTranslation(centerTopScreenPosition));

				//graphics2D.Render(translate, RGBA_Bytes.Black);
			}
		}
Exemplo n.º 7
0
		private static void DrawBorderBounds(Graphics2D graphics2D, RectangleDouble bounds, BorderDouble border, RGBA_Bytes color)
		{
			if (border.Width != 0
				|| border.Height != 0)
			{
				PathStorage borderPath = new PathStorage();
				borderPath.MoveTo(bounds.Left, bounds.Bottom);
				borderPath.LineTo(bounds.Left, bounds.Top);
				borderPath.LineTo(bounds.Right, bounds.Top);
				borderPath.LineTo(bounds.Right, bounds.Bottom);
				borderPath.LineTo(bounds.Left, bounds.Bottom);

				borderPath.MoveTo(bounds.Left + border.Left, bounds.Bottom + border.Bottom);
				borderPath.LineTo(bounds.Right - border.Right, bounds.Bottom + border.Bottom);
				borderPath.LineTo(bounds.Right - border.Right, bounds.Top - border.Top);
				borderPath.LineTo(bounds.Left + border.Left, bounds.Top - border.Top);
				borderPath.LineTo(bounds.Left + border.Left, bounds.Bottom + border.Bottom);
				graphics2D.Render(borderPath, color);
			}
		}
Exemplo n.º 8
0
		private void make_arrows(PathStorage ps)
		{
			ps.remove_all();

			ps.MoveTo(1330.599999999999909, 1282.399999999999864);
			ps.LineTo(1377.400000000000091, 1282.399999999999864);
			ps.LineTo(1361.799999999999955, 1298.000000000000000);
			ps.LineTo(1393.000000000000000, 1313.599999999999909);
			ps.LineTo(1361.799999999999955, 1344.799999999999955);
			ps.LineTo(1346.200000000000045, 1313.599999999999909);
			ps.LineTo(1330.599999999999909, 1329.200000000000045);
			ps.ClosePolygon();

			ps.MoveTo(1330.599999999999909, 1266.799999999999955);
			ps.LineTo(1377.400000000000091, 1266.799999999999955);
			ps.LineTo(1361.799999999999955, 1251.200000000000045);
			ps.LineTo(1393.000000000000000, 1235.599999999999909);
			ps.LineTo(1361.799999999999955, 1204.399999999999864);
			ps.LineTo(1346.200000000000045, 1235.599999999999909);
			ps.LineTo(1330.599999999999909, 1220.000000000000000);
			ps.ClosePolygon();

			ps.MoveTo(1315.000000000000000, 1282.399999999999864);
			ps.LineTo(1315.000000000000000, 1329.200000000000045);
			ps.LineTo(1299.400000000000091, 1313.599999999999909);
			ps.LineTo(1283.799999999999955, 1344.799999999999955);
			ps.LineTo(1252.599999999999909, 1313.599999999999909);
			ps.LineTo(1283.799999999999955, 1298.000000000000000);
			ps.LineTo(1268.200000000000045, 1282.399999999999864);
			ps.ClosePolygon();

			ps.MoveTo(1268.200000000000045, 1266.799999999999955);
			ps.LineTo(1315.000000000000000, 1266.799999999999955);
			ps.LineTo(1315.000000000000000, 1220.000000000000000);
			ps.LineTo(1299.400000000000091, 1235.599999999999909);
			ps.LineTo(1283.799999999999955, 1204.399999999999864);
			ps.LineTo(1252.599999999999909, 1235.599999999999909);
			ps.LineTo(1283.799999999999955, 1251.200000000000045);
			ps.ClosePolygon();
		}
Exemplo n.º 9
0
		public void DrawSegments(Graphics2D graphics2D)
		{
			foreach (LineSegment lineSegment in LineSegments)
			{
				PathStorage m_LinesToDraw = new PathStorage();
				m_LinesToDraw.remove_all();
				m_LinesToDraw.MoveTo(lineSegment.start.x, lineSegment.start.y);
				m_LinesToDraw.LineTo(lineSegment.end.x, lineSegment.end.y);
				Stroke StrockedLineToDraw = new Stroke(m_LinesToDraw, .25);
				graphics2D.Render(StrockedLineToDraw, lineSegment.color);
			}
		}
Exemplo n.º 10
0
		public void DrawTo(Graphics2D graphics2D, Mesh meshToDraw, RGBA_Bytes partColorIn, double minZ, double maxZ)
		{
			RGBA_Floats partColor = partColorIn.GetAsRGBA_Floats();
			graphics2D.Rasterizer.gamma(new gamma_power(.3));
			PathStorage polygonProjected = new PathStorage();

			foreach (Face face in meshToDraw.Faces)
			{
				double averageZ = 0;
				Vector3 normal = Vector3.TransformVector(face.normal, trackballTumbleWidget.ModelviewMatrix).GetNormal();
				if (normal.z > 0)
				{
					polygonProjected.remove_all();
					bool first = true;
					foreach (FaceEdge faceEdge in face.FaceEdges())
					{
						Vector2 screenPosition = trackballTumbleWidget.GetScreenPosition(faceEdge.firstVertex.Position);
						if (first)
						{
							polygonProjected.MoveTo(screenPosition.x, screenPosition.y);
							first = false;
						}
						else
						{
							polygonProjected.LineTo(screenPosition.x, screenPosition.y);
						}

						Vector3 transsformedPosition = Vector3.TransformPosition(faceEdge.firstVertex.Position, trackballTumbleWidget.ModelviewMatrix);
						averageZ += transsformedPosition.z;
					}

					averageZ /= 3;

					RGBA_Floats polyDrawColor = new RGBA_Floats();
					double L = Vector3.Dot(lightNormal, normal);
					if (L > 0.0f)
					{
						polyDrawColor = partColor * lightIllumination * L;
					}

					polyDrawColor = RGBA_Floats.ComponentMax(polyDrawColor, partColor * ambiantIllumination);
					double ratio = (averageZ - minZ) / (maxZ - minZ);
					int ratioInt16 = (int)(ratio * 65536);

					//RGBA_Bytes renderColor = new RGBA_Bytes(polyDrawColor.Red0To255, ratioInt16 >> 8, ratioInt16 & 256);
					RGBA_Bytes renderColor = new RGBA_Bytes(ratioInt16 >> 8, ratioInt16 >> 8, ratioInt16 >> 8);

					//IRecieveBlenderByte oldBlender = graphics2D.DestImage.GetRecieveBlender();
					//graphics2D.DestImage.SetRecieveBlender(new BlenderZBuffer());
					graphics2D.Render(polygonProjected, renderColor);
					//graphics2D.DestImage.SetRecieveBlender(oldBlender);

					byte[] buffer = graphics2D.DestImage.GetBuffer();
					int pixels = graphics2D.DestImage.Width * graphics2D.DestImage.Height;
					for (int i = 0; i < pixels; i++)
					{
						//buffer[i * 4 + 0] = buffer[i * 4 + 2];
						//buffer[i * 4 + 1] = buffer[i * 4 + 2];
					}
				}
			}
		}
Exemplo n.º 11
0
		private static void CreateButtonImages(out ImageBuffer togetherBig, out ImageBuffer appartBig)
		{
			PathStorage upArrow = new PathStorage();
			upArrow.MoveTo(0, 0);
			upArrow.LineTo(.5, -.5);
			upArrow.LineTo(.25, -.5);
			upArrow.LineTo(.25, -1);
			upArrow.LineTo(-.25, -1);
			upArrow.LineTo(-.25, -.5);
			upArrow.LineTo(-.5, -.5);

			int buttonSize = 32;
			int arrowSize = buttonSize / 3;
			togetherBig = new ImageBuffer(buttonSize, buttonSize, 32, new BlenderBGRA());
			Graphics2D togetherBigGraphics = togetherBig.NewGraphics2D();
			togetherBigGraphics.Clear(RGBA_Bytes.White);

			int margin = buttonSize / 16;
			int lineWidth = buttonSize / 16;
			togetherBigGraphics.FillRectangle(margin, buttonSize / 2 + margin, buttonSize - margin, buttonSize / 2 + margin + lineWidth, RGBA_Bytes.Black);
			togetherBigGraphics.FillRectangle(margin, buttonSize / 2 - margin, buttonSize - margin, buttonSize / 2 - margin - lineWidth, RGBA_Bytes.Black);

			appartBig = new ImageBuffer(togetherBig);

			// point up
			Affine totalTransform = Affine.NewScaling(arrowSize, arrowSize);
			totalTransform *= Affine.NewTranslation(buttonSize / 2, buttonSize / 2 - margin - lineWidth);
			togetherBigGraphics.Render(new VertexSourceApplyTransform(upArrow, totalTransform), RGBA_Bytes.Black);

			// point down
			totalTransform = Affine.NewRotation(MathHelper.Tau / 2);
			totalTransform *= Affine.NewScaling(arrowSize, arrowSize);
			totalTransform *= Affine.NewTranslation(buttonSize / 2, buttonSize / 2 + margin + lineWidth);
			togetherBigGraphics.Render(new VertexSourceApplyTransform(upArrow, totalTransform), RGBA_Bytes.Black);

			Graphics2D appartBigGraphics = appartBig.NewGraphics2D();

			// point up
			totalTransform = Affine.NewScaling(arrowSize, arrowSize);
			totalTransform *= Affine.NewTranslation(buttonSize / 2, buttonSize / 2 + margin + lineWidth + arrowSize + 1);
			appartBigGraphics.Render(new VertexSourceApplyTransform(upArrow, totalTransform), RGBA_Bytes.Black);

			// point down
			totalTransform = Affine.NewRotation(MathHelper.Tau / 2);
			totalTransform *= Affine.NewScaling(arrowSize, arrowSize);
			totalTransform *= Affine.NewTranslation(buttonSize / 2, buttonSize / 2 - margin - lineWidth - arrowSize - 1);
			appartBigGraphics.Render(new VertexSourceApplyTransform(upArrow, totalTransform), RGBA_Bytes.Black);
		}
Exemplo n.º 12
0
		private void MeshViewerToDrawWith_Draw(GuiWidget drawingWidget, DrawEventArgs drawEvent)
		{
			if (Visible)
			{
				if (drawEvent != null)
				{
					// draw the line that is on the ground
					double yGround = (int)(startLineGroundPos.y + .5) + .5;
					drawEvent.graphics2D.Line(startLineGroundPos.x, yGround, startLineGroundPos.x + HorizontalLineLength - 5, yGround, RGBA_Bytes.Black);
					// and the line that is at the base of the selection
					double ySelection = (int)(startLineSelectionPos.y + .5) + .5;
					drawEvent.graphics2D.Line(startLineSelectionPos.x, ySelection, startLineSelectionPos.x + HorizontalLineLength - 5, ySelection, RGBA_Bytes.Black);

					// draw the verticle line that shows the measurment
					Vector2 pointerBottom = new Vector2(startLineGroundPos.x + HorizontalLineLength / 2, yGround);
					Vector2 pointerTop = new Vector2(startLineSelectionPos.x + HorizontalLineLength / 2, ySelection);
					drawEvent.graphics2D.Line(pointerBottom, pointerTop, RGBA_Bytes.Black);

					Vector2 direction = pointerTop - pointerBottom;
					if (direction.LengthSquared > 0)
					{
						PathStorage arrow = new PathStorage();
						arrow.MoveTo(-3, -5);
						arrow.LineTo(0, 0);
						arrow.LineTo(3, -5);
						double rotation = Math.Atan2(direction.y, direction.x);
						IVertexSource correctRotation = new VertexSourceApplyTransform(arrow, Affine.NewRotation(rotation - MathHelper.Tau / 4));
						IVertexSource inPosition = new VertexSourceApplyTransform(correctRotation, Affine.NewTranslation(pointerTop));
						drawEvent.graphics2D.Render(inPosition, RGBA_Bytes.Black);
					}
				}
			}
		}
Exemplo n.º 13
0
        public void FillRectangle(Brush brush, float x, float y, float width, float height)
        {
            SolidBrush solidBrush = brush as SolidBrush;

            var path = new PathStorage();
            path.MoveTo(x,y);
            path.LineTo(x,y+height);
            path.LineTo(x+width,y+height);
            path.LineTo(x+width,y);
            path.LineTo(x,y);

            _InternalRender(path, new RGBA_Bytes((uint)solidBrush.Color.ToArgb()) );
        }
Exemplo n.º 14
0
        public void FillPie(Brush brush, System.Drawing.Rectangle rect, float startAngleDeg, float endAngleDeg)
        {
            SolidBrush solidBrush = brush as SolidBrush;
            // throw new NotImplementedException();
            double originX = (rect.Left + rect.Right) / 2.0;
            double originY = (rect.Top + rect.Bottom) / 2.0;
            double radiusX = (rect.Height) / 2.0;
            double radiusY = (rect.Width) / 2.0;

            IVertexSource arcpath;

            if (Math.Abs (endAngleDeg - startAngleDeg) >= 360.0) {
                // if it's a full circle, we don't need to connect to the origin
                arcpath = new arc(originX,originY,radiusX,radiusY,DegreesToRadians(startAngleDeg),DegreesToRadians(endAngleDeg),moveToStart:true);
            } else {
                // if it's a partial arc, we need to connect to the origin
                var path = new PathStorage();
                path.MoveTo(originX,originY);
                path.concat_path(new arc(originX,originY,radiusX,radiusY,DegreesToRadians(startAngleDeg),DegreesToRadians(endAngleDeg),moveToStart:false));
                path.LineTo(originX,originY);
                arcpath = path;
            }

            _InternalRender(arcpath, new RGBA_Bytes((uint)solidBrush.Color.ToArgb()));
        }
Exemplo n.º 15
0
        public void DrawRectangle(Pen pen, float x, float y, float width, float height)
        {
            var path = new PathStorage();
            path.MoveTo(x,y);
            path.LineTo(x,y+height);
            path.LineTo(x+width,y+height);
            path.LineTo(x+width,y);
            path.LineTo(x,y);
            var stroke = new Stroke(path, (double)pen.Width);

            _InternalRender(stroke, new RGBA_Bytes((uint)pen.Color.ToArgb()));
        }
Exemplo n.º 16
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			RectangleDouble backgroundRect = new RectangleDouble(LocalBounds.Left - m_border_extra,
				LocalBounds.Bottom - m_border_extra,
				LocalBounds.Right + m_border_extra,
				LocalBounds.Top + m_border_extra);
			graphics2D.FillRectangle(backgroundRect, m_background_color);

			PathStorage border = new PathStorage();
			border.LineTo(LocalBounds.Left, LocalBounds.Bottom);
			border.LineTo(LocalBounds.Right, LocalBounds.Bottom);
			border.LineTo(LocalBounds.Right, LocalBounds.Top);
			border.LineTo(LocalBounds.Left, LocalBounds.Top);
			border.LineTo(LocalBounds.Left + m_border_width, LocalBounds.Bottom + m_border_width);
			border.LineTo(LocalBounds.Left + m_border_width, LocalBounds.Top - m_border_width);
			border.LineTo(LocalBounds.Right - m_border_width, LocalBounds.Top - m_border_width);
			border.LineTo(LocalBounds.Right - m_border_width, LocalBounds.Bottom + m_border_width);

			graphics2D.Render(border, m_border_color);

			rewind(0);
			graphics2D.Render(this, m_curve_color);
			rewind(1);
			graphics2D.Render(this, m_grid_color);
			rewind(2);
			graphics2D.Render(this, m_inactive_pnt_color);
			rewind(3);
			graphics2D.Render(this, m_active_pnt_color);
			rewind(4);
			graphics2D.Render(this, m_text_color);

			base.OnDraw(graphics2D);
		}
Exemplo n.º 17
0
		public void Line(double x1, double y1, double x2, double y2, RGBA_Bytes color, double strokeWidth = 1)
		{
			PathStorage m_LinesToDraw = new PathStorage();
			m_LinesToDraw.remove_all();
			m_LinesToDraw.MoveTo(x1, y1);
			m_LinesToDraw.LineTo(x2, y2);
			Stroke StrockedLineToDraw = new Stroke(m_LinesToDraw, strokeWidth);
			Render(StrockedLineToDraw, color);
		}
Exemplo n.º 18
0
        public static IVertexSource PathStorageFromD(String DFromSVGFile, double xOffset, double yOffset)
        {
            PathStorage path = new PathStorage();
            string[] splitOnSpace = DFromSVGFile.Split(' ');
            string[] splitOnComma;
            double xc1, yc1, xc2, yc2, x, y;
            for (int i = 0; i < splitOnSpace.Length; i++)
            {
                switch (splitOnSpace[i++])
                {
                    case "M":
                        {
                            splitOnComma = splitOnSpace[i].Split(',');
                            double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x);
                            double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y);
                            path.MoveTo(x, y + yOffset);
                        }
                        break;

                    case "L":
                        {
                            splitOnComma = splitOnSpace[i].Split(',');
                            double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x);
                            double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y);
                            path.LineTo(x, y + yOffset);
                        }
                        break;

                    case "C":
                        {
                            splitOnComma = splitOnSpace[i++].Split(',');
                            double.TryParse(splitOnComma[0], NumberStyles.Number, null, out xc1);
                            double.TryParse(splitOnComma[1], NumberStyles.Number, null, out yc1);

                            splitOnComma = splitOnSpace[i++].Split(',');
                            double.TryParse(splitOnComma[0], NumberStyles.Number, null, out xc2);
                            double.TryParse(splitOnComma[1], NumberStyles.Number, null, out yc2);

                            splitOnComma = splitOnSpace[i].Split(',');
                            double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x);
                            double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y);
                            path.curve4(xc1, yc1 + yOffset, xc2, yc2 + yOffset, x, y + yOffset);
                        }
                        break;

                    case "z":
                        if (i < splitOnSpace.Length)
                        {
                            throw new Exception();
                        }
                        break;

                    default:
                        throw new NotImplementedException();
                }
            }

            path.arrange_orientations_all_paths(AGG.Path.FlagsAndCommand.FlagCW);
            VertexSourceApplyTransform flipped = new VertexSourceApplyTransform(path, Affine.NewScaling(1, -1));
            return flipped;
        }
Exemplo n.º 19
0
		private void render_gpc(Graphics2D graphics2D)
		{
			switch (m_polygons.SelectedIndex)
			{
				case 0:
					{
						//------------------------------------
						// Two simple paths
						//
						PathStorage ps1 = new PathStorage();
						PathStorage ps2 = new PathStorage();

						double x = m_x - Width / 2 + 100;
						double y = m_y - Height / 2 + 100;
						ps1.MoveTo(x + 140, y + 145);
						ps1.LineTo(x + 225, y + 44);
						ps1.LineTo(x + 296, y + 219);
						ps1.ClosePolygon();

						ps1.LineTo(x + 226, y + 289);
						ps1.LineTo(x + 82, y + 292);

						ps1.MoveTo(x + 220, y + 222);
						ps1.LineTo(x + 363, y + 249);
						ps1.LineTo(x + 265, y + 331);

						ps1.MoveTo(x + 242, y + 243);
						ps1.LineTo(x + 268, y + 309);
						ps1.LineTo(x + 325, y + 261);

						ps1.MoveTo(x + 259, y + 259);
						ps1.LineTo(x + 273, y + 288);
						ps1.LineTo(x + 298, y + 266);

						ps2.MoveTo(100 + 32, 100 + 77);
						ps2.LineTo(100 + 473, 100 + 263);
						ps2.LineTo(100 + 351, 100 + 290);
						ps2.LineTo(100 + 354, 100 + 374);

						graphics2D.Render(ps1, new RGBA_Floats(0, 0, 0, 0.1).GetAsRGBA_Bytes());
						graphics2D.Render(ps2, new RGBA_Floats(0, 0.6, 0, 0.1).GetAsRGBA_Bytes());

						CreateAndRenderCombined(graphics2D, ps1, ps2);
					}
					break;

				case 1:
					{
						//------------------------------------
						// Closed stroke
						//
						PathStorage ps1 = new PathStorage();
						PathStorage ps2 = new PathStorage();
						Stroke stroke = new Stroke(ps2);
						stroke.width(10.0);

						double x = m_x - Width / 2 + 100;
						double y = m_y - Height / 2 + 100;
						ps1.MoveTo(x + 140, y + 145);
						ps1.LineTo(x + 225, y + 44);
						ps1.LineTo(x + 296, y + 219);
						ps1.ClosePolygon();

						ps1.LineTo(x + 226, y + 289);
						ps1.LineTo(x + 82, y + 292);

						ps1.MoveTo(x + 220 - 50, y + 222);
						ps1.LineTo(x + 265 - 50, y + 331);
						ps1.LineTo(x + 363 - 50, y + 249);
						ps1.close_polygon(ShapePath.FlagsAndCommand.FlagCCW);

						ps2.MoveTo(100 + 32, 100 + 77);
						ps2.LineTo(100 + 473, 100 + 263);
						ps2.LineTo(100 + 351, 100 + 290);
						ps2.LineTo(100 + 354, 100 + 374);
						ps2.ClosePolygon();

						graphics2D.Render(ps1, new RGBA_Floats(0, 0, 0, 0.1).GetAsRGBA_Bytes());
						graphics2D.Render(stroke, new RGBA_Floats(0, 0.6, 0, 0.1).GetAsRGBA_Bytes());

						CreateAndRenderCombined(graphics2D, ps1, stroke);
					}
					break;

				case 2:
					{
						//------------------------------------
						// Great Britain and Arrows
						//
						PathStorage gb_poly = new PathStorage();
						PathStorage arrows = new PathStorage();
						GreatBritanPathStorage.Make(gb_poly);
						make_arrows(arrows);

						Affine mtx1 = Affine.NewIdentity();
						Affine mtx2 = Affine.NewIdentity();
						mtx1 *= Affine.NewTranslation(-1150, -1150);
						mtx1 *= Affine.NewScaling(2.0);

						mtx2 = mtx1;
						mtx2 *= Affine.NewTranslation(m_x - Width / 2, m_y - Height / 2);

						VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx1);
						VertexSourceApplyTransform trans_arrows = new VertexSourceApplyTransform(arrows, mtx2);

						graphics2D.Render(trans_gb_poly, new RGBA_Floats(0.5, 0.5, 0, 0.1).GetAsRGBA_Bytes());

						Stroke stroke_gb_poly = new Stroke(trans_gb_poly);
						stroke_gb_poly.Width = 0.1;
						graphics2D.Render(stroke_gb_poly, new RGBA_Floats(0, 0, 0).GetAsRGBA_Bytes());

						graphics2D.Render(trans_arrows, new RGBA_Floats(0.0, 0.5, 0.5, 0.1).GetAsRGBA_Bytes());

						CreateAndRenderCombined(graphics2D, trans_gb_poly, trans_arrows);
					}
					break;

				case 3:
					{
						//------------------------------------
						// Great Britain and a Spiral
						//
						spiral sp = new spiral(m_x, m_y, 10, 150, 30, 0.0);
						Stroke stroke = new Stroke(sp);
						stroke.width(15.0);

						PathStorage gb_poly = new PathStorage();
						GreatBritanPathStorage.Make(gb_poly);

						Affine mtx = Affine.NewIdentity(); ;
						mtx *= Affine.NewTranslation(-1150, -1150);
						mtx *= Affine.NewScaling(2.0);

						VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx);

						graphics2D.Render(trans_gb_poly, new RGBA_Floats(0.5, 0.5, 0, 0.1).GetAsRGBA_Bytes());

						Stroke stroke_gb_poly = new Stroke(trans_gb_poly);
						stroke_gb_poly.width(0.1);
						graphics2D.Render(stroke_gb_poly, new RGBA_Floats(0, 0, 0).GetAsRGBA_Bytes());

						graphics2D.Render(stroke, new RGBA_Floats(0.0, 0.5, 0.5, 0.1).GetAsRGBA_Bytes());

						CreateAndRenderCombined(graphics2D, trans_gb_poly, stroke);
					}
					break;

				case 4:
					{
						//------------------------------------
						// Spiral and glyph
						//
						spiral sp = new spiral(m_x, m_y, 10, 150, 30, 0.0);
						Stroke stroke = new Stroke(sp);
						stroke.width(15.0);

						PathStorage glyph = new PathStorage();
						glyph.MoveTo(28.47, 6.45);
						glyph.curve3(21.58, 1.12, 19.82, 0.29);
						glyph.curve3(17.19, -0.93, 14.21, -0.93);
						glyph.curve3(9.57, -0.93, 6.57, 2.25);
						glyph.curve3(3.56, 5.42, 3.56, 10.60);
						glyph.curve3(3.56, 13.87, 5.03, 16.26);
						glyph.curve3(7.03, 19.58, 11.99, 22.51);
						glyph.curve3(16.94, 25.44, 28.47, 29.64);
						glyph.LineTo(28.47, 31.40);
						glyph.curve3(28.47, 38.09, 26.34, 40.58);
						glyph.curve3(24.22, 43.07, 20.17, 43.07);
						glyph.curve3(17.09, 43.07, 15.28, 41.41);
						glyph.curve3(13.43, 39.75, 13.43, 37.60);
						glyph.LineTo(13.53, 34.77);
						glyph.curve3(13.53, 32.52, 12.38, 31.30);
						glyph.curve3(11.23, 30.08, 9.38, 30.08);
						glyph.curve3(7.57, 30.08, 6.42, 31.35);
						glyph.curve3(5.27, 32.62, 5.27, 34.81);
						glyph.curve3(5.27, 39.01, 9.57, 42.53);
						glyph.curve3(13.87, 46.04, 21.63, 46.04);
						glyph.curve3(27.59, 46.04, 31.40, 44.04);
						glyph.curve3(34.28, 42.53, 35.64, 39.31);
						glyph.curve3(36.52, 37.21, 36.52, 30.71);
						glyph.LineTo(36.52, 15.53);
						glyph.curve3(36.52, 9.13, 36.77, 7.69);
						glyph.curve3(37.01, 6.25, 37.57, 5.76);
						glyph.curve3(38.13, 5.27, 38.87, 5.27);
						glyph.curve3(39.65, 5.27, 40.23, 5.62);
						glyph.curve3(41.26, 6.25, 44.19, 9.18);
						glyph.LineTo(44.19, 6.45);
						glyph.curve3(38.72, -0.88, 33.74, -0.88);
						glyph.curve3(31.35, -0.88, 29.93, 0.78);
						glyph.curve3(28.52, 2.44, 28.47, 6.45);
						glyph.ClosePolygon();

						glyph.MoveTo(28.47, 9.62);
						glyph.LineTo(28.47, 26.66);
						glyph.curve3(21.09, 23.73, 18.95, 22.51);
						glyph.curve3(15.09, 20.36, 13.43, 18.02);
						glyph.curve3(11.77, 15.67, 11.77, 12.89);
						glyph.curve3(11.77, 9.38, 13.87, 7.06);
						glyph.curve3(15.97, 4.74, 18.70, 4.74);
						glyph.curve3(22.41, 4.74, 28.47, 9.62);
						glyph.ClosePolygon();

						Affine mtx = Affine.NewIdentity();
						mtx *= Affine.NewScaling(4.0);
						mtx *= Affine.NewTranslation(220, 200);
						VertexSourceApplyTransform trans = new VertexSourceApplyTransform(glyph, mtx);
						FlattenCurves curve = new FlattenCurves(trans);

						CreateAndRenderCombined(graphics2D, stroke, curve);

						graphics2D.Render(stroke, new RGBA_Floats(0, 0, 0, 0.1).GetAsRGBA_Bytes());

						graphics2D.Render(curve, new RGBA_Floats(0, 0.6, 0, 0.1).GetAsRGBA_Bytes());
					}
					break;
			}
		}
Exemplo n.º 20
0
		public static void Make(PathStorage ps)
		{
			ps.remove_all();
			ps.MoveTo(poly1[0], poly1[1]);
			for (int i = 1; i < poly1.Length / 2; i++)
			{
				ps.LineTo(poly1[i * 2 + 0], poly1[i * 2 + 1]);
			}
			ps.ClosePolygon();

			ps.MoveTo(poly2[0], poly2[1]);
			for (int i = 1; i < poly2.Length / 2; i++)
			{
				ps.LineTo(poly2[i * 2 + 0], poly2[i * 2 + 1]);
			}
			ps.ClosePolygon();
		}
Exemplo n.º 21
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

			GammaLookUpTable gamma = new GammaLookUpTable(gammaSlider.Value);
			IRecieveBlenderByte NormalBlender = new BlenderBGRA();
			IRecieveBlenderByte GammaBlender = new BlenderGammaBGRA(gamma);
			ImageBuffer rasterGamma = new ImageBuffer();
			rasterGamma.Attach(widgetsSubImage, GammaBlender);
			ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(widgetsSubImage);
			ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma);

			clippingProxyNormal.clear(new RGBA_Floats(1, 1, 1));

			ScanlineRasterizer rasterizer = new ScanlineRasterizer();
			scanline_unpacked_8 sl = new scanline_unpacked_8();

			int size_mul = (int)pixelSizeSlider.Value;

			renderer_enlarged ren_en = new renderer_enlarged(size_mul);

			rasterizer.reset();
			rasterizer.move_to_d(m_x[0] / size_mul, m_y[0] / size_mul);
			rasterizer.line_to_d(m_x[1] / size_mul, m_y[1] / size_mul);
			rasterizer.line_to_d(m_x[2] / size_mul, m_y[2] / size_mul);
			ren_en.RenderSolid(clippingProxyGamma, rasterizer, sl, RGBA_Bytes.Black);

			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			scanlineRenderer.RenderSolid(clippingProxyGamma, rasterizer, sl, RGBA_Bytes.Black);

			rasterizer.gamma(new gamma_none());

			PathStorage ps = new PathStorage();
			Stroke pg = new Stroke(ps);
			pg.width(2);

			ps.remove_all();
			ps.MoveTo(m_x[0], m_y[0]);
			ps.LineTo(m_x[1], m_y[1]);
			ps.LineTo(m_x[2], m_y[2]);
			ps.LineTo(m_x[0], m_y[0]);
			rasterizer.add_path(pg);
			scanlineRenderer.RenderSolid(clippingProxyNormal, rasterizer, sl, new RGBA_Bytes(0, 150, 160, 200));

			base.OnDraw(graphics2D);
		}
Exemplo n.º 22
0
 public static CCSprite CreateLine(
     int width, int height,
     CCColor4B stroke,
     double strokeThickness = 1
     )
 {
     ImageBuffer buffer = new ImageBuffer(width, height, 32, new BlenderRGBA());
     Graphics2D g = buffer.NewGraphics2D();
     if (stroke.A > 0)
     {
         //g.Line没有厚度
         PathStorage linesToDraw = new PathStorage();
         linesToDraw.remove_all();
         linesToDraw.MoveTo(0, 0);
         linesToDraw.LineTo(width, height);
         Stroke StrockedLineToDraw = new Stroke(linesToDraw, strokeThickness);
         g.Render(StrockedLineToDraw, new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A));
     }
     Texture2D xnaTexture = XnaTexture((int)width, (int)height);
     xnaTexture.SetData<byte>(buffer.GetBuffer());
     CCTexture2D ccTexture = new CCTexture2D();
     ccTexture.InitWithTexture(xnaTexture);
     return new CCSprite(ccTexture);
 }
Exemplo n.º 23
0
		static public int parse_lion(PathStorage path, RGBA_Bytes[] colors, int[] path_idx)
		{
			// Parse the lion and then detect its bounding
			// box and arrange polygons orientations (make all polygons
			// oriented clockwise or counterclockwise)

			int npaths = 0;
			string[] splitOnNL = g_lion.Split('\n');
			foreach (string LineString in splitOnNL)
			{
				int c;
				if (LineString.Length > 0
					&& LineString[0] != 'M'
					&& Int32.TryParse(LineString, NumberStyles.HexNumber, null, out c))
				{
					// New color. Every new color creates new path in the path object.
					path.ClosePolygon();
					colors[npaths] = RGBA_Bytes.rgb8_packed((int)c);
					path_idx[npaths] = path.start_new_path();
					npaths++;
				}
				else
				{
					bool startedPoly = false;
					string[] splitOnSpace = LineString.Split(' ');
					for (int i = 0; i < splitOnSpace.Length; i++)
					{
						string[] splitOnComma = splitOnSpace[i].Split(',');
						if (splitOnComma.Length > 1)
						{
							double x = 0.0;
							double y = 0.0;
							double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x);
							double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y);

							if (!startedPoly)
							{
								startedPoly = true;
								path.ClosePolygon();
								path.MoveTo(x, y);
							}
							else
							{
								path.LineTo(x, y);
							}
						}
					}
				}
			}

			path.arrange_orientations_all_paths(ShapePath.FlagsAndCommand.FlagCW);
			return npaths;
		}
Exemplo n.º 24
0
        public static IVertexSource CreatePathStorage(string data)
        {
            PathStorage path = new PathStorage();
            bool hasCurves = false;

            //todo   依次输入多个同一类型的命令时,可以省略重复的命令项;例如,L 100,200 300,400 等同于 L 100,200 L 300,400。
            StringBuilder buffer = new StringBuilder();
            for (int i = 0; i < data.Length; i++)
            {
                if (data[i] == '-' && i > 0 && data[i - 1] != ',' && data[i - 1] != ' ' && char.IsLetter(data[i - 1]) == false)
                {
                    buffer.Append(',');
                }
                if (data[i] != 'F' && (char.IsLetter(data[i])))
                {
                    buffer.Append(',');
                    buffer.Append(data[i]);
                    if (i < data.Length - 1 && data[i + 1] != ' ')
                        buffer.Append(',');
                }
                else
                {
                    buffer.Append(data[i]);
                }
            }
            string[] commands = buffer.ToString().Split(new char[] { ' ', ',' });

            MatterHackers.VectorMath.Vector2 polyStart = new MatterHackers.VectorMath.Vector2(0, 0);
            MatterHackers.VectorMath.Vector2 lastXY = new MatterHackers.VectorMath.Vector2(0, 0);
            MatterHackers.VectorMath.Vector2 curXY = new MatterHackers.VectorMath.Vector2();
            for (int i = 0; i < commands.Length; i++)
            {
                switch (commands[i])
                {
                    // F0 指定 EvenOdd 填充规则。F1 指定 Nonzero 填充规则。
                    // 如果省略此命令,则子路径使用默认行为,即 EvenOdd。 如果指定此命令,则必须将其置于最前面。
                    case "F1": break;
                    case " ": break;

                    case "m":
                    case "M":
                        {
                            curXY.x = double.Parse(commands[i + 1]);
                            curXY.y = double.Parse(commands[i + 2]);
                            if (commands[i] == "m")
                            {
                                curXY += lastXY;
                            }
                            path.MoveTo(curXY.x, curXY.y);
                            polyStart = curXY;
                            i += 2;
                        }
                        break;
                    case "l":
                    case "L":
                        {
                            curXY.x = double.Parse(commands[i + 1]);
                            curXY.y = double.Parse(commands[i + 2]);
                            if (commands[i] == "l")
                            {
                                curXY += lastXY;
                            }
                            path.LineTo(curXY.x, curXY.y);
                        }
                        break;
                    case "h":
                    case "H":
                        {
                            curXY.y = lastXY.y;
                            curXY.x = double.Parse(commands[i + 1]);
                            if (commands[i] == "h")
                            {
                                curXY.x += lastXY.x;
                            }
                            path.HorizontalLineTo(curXY.x);
                            i += 1;
                        }
                        break;

                    case "v":
                    case "V":
                        {
                            curXY.x = lastXY.x;
                            curXY.y = double.Parse(commands[i + 1]);
                            if (commands[i] == "v")
                            {
                                curXY.y += lastXY.y;
                            }
                            path.VerticalLineTo(curXY.y);
                            i += 1;
                        }
                        break;

                    //三次方贝塞尔曲线命令。通过使用两个指定的控制点(controlPoint1 和 controlPoint2)在当前点与指定的终点之间创建一条三次方贝塞尔曲线
                    case "c":
                    case "C":
                        {
                            MatterHackers.VectorMath.Vector2 controlPoint1;
                            MatterHackers.VectorMath.Vector2 controlPoint2;
                            controlPoint1.x = double.Parse(commands[i + 1]);
                            controlPoint1.y = double.Parse(commands[i + 2]);
                            controlPoint2.x = double.Parse(commands[i + 3]);
                            controlPoint2.y = double.Parse(commands[i + 4]);
                            curXY.x = double.Parse(commands[i + 5]);
                            curXY.y = double.Parse(commands[i + 6]);
                            if (commands[i] == "c")
                            {
                                controlPoint1 += lastXY;
                                controlPoint2 += lastXY;
                                curXY += lastXY;
                            }
                            path.curve4(controlPoint1.x, controlPoint1.y, controlPoint2.x, controlPoint2.y, curXY.x, curXY.y);
                            i += 6;
                            hasCurves = true;
                        }
                        break;

                    //二次贝塞尔曲线命令。通过使用指定的控制点 (controlPoint) 在当前点与指定的终点之间创建一条二次贝塞尔曲线。
                    case "q":
                    case "Q":
                        {
                            MatterHackers.VectorMath.Vector2 controlPoint;
                            controlPoint.x = double.Parse(commands[i + 1]);
                            controlPoint.y = double.Parse(commands[i + 2]);
                            curXY.x = double.Parse(commands[i + 3]);
                            curXY.y = double.Parse(commands[i + 4]);
                            if (commands[i] == "q")
                            {
                                controlPoint += lastXY;
                                curXY += lastXY;
                            }
                            path.curve3(controlPoint.x, controlPoint.y, curXY.x, curXY.y);
                            i += 4;
                            hasCurves = true;
                        }
                        break;

                    //在当前点与指定的终点之间创建一条三次方贝塞尔曲线。
                    //第一个控制点假定为前一个命令的第二个控制点相对于当前点的反射。
                    //如果前一个命令不存在,或者前一个命令不是三次方贝塞尔曲线命令或平滑的三次方贝塞尔曲线命令,则假定第一个控制点就是当前点。
                    //第二个控制点,即曲线终端的控制点,由 controlPoint2 指定。
                    case "s":
                    case "S":
                        {
                            MatterHackers.VectorMath.Vector2 controlPoint2;
                            controlPoint2.x = double.Parse(commands[i + 1]);
                            controlPoint2.y = double.Parse(commands[i + 2]);
                            curXY.x = double.Parse(commands[i + 3]);
                            curXY.y = double.Parse(commands[i + 4]);
                            if (commands[i] == "s")
                            {
                                controlPoint2 += lastXY;
                                curXY += lastXY;
                            }
                            path.curve4(controlPoint2.x, controlPoint2.y, curXY.x, curXY.y);
                            i += 4;
                            hasCurves = true;
                        }
                        break;

                    //二次贝塞尔曲线命令。在当前点与指定的终点之间创建一条二次贝塞尔曲线。
                    //控制点假定为前一个命令的控制点相对于当前点的反射。
                    //如果前一个命令不存在,或者前一个命令不是二次贝塞尔曲线命令或平滑的二次贝塞尔曲线命令,则此控制点就是当前点。
                    case "t":
                    case "T":
                        {
                            curXY.x = double.Parse(commands[i + 1]);
                            curXY.y = double.Parse(commands[i + 2]);
                            if (commands[i] == "t")
                            {
                                curXY += lastXY;
                            }
                            path.curve3(curXY.x, curXY.y);
                            i += 2;
                            hasCurves = true;
                        }
                        break;

                    case "z":
                    case "Z":
                        {
                            curXY = lastXY; // value not used this is to remove an error.
                            path.ClosePolygon();
                            // svg fonts are stored cw and agg expects its shapes to be ccw.  cw shapes are holes.
                            // We stored the position of the start of this polygon, no we flip it as we colse it.
                            //path.invert_polygon(0);
                        }
                        break;

                    case "\r":
                        {
                            curXY = lastXY; // value not used this is to remove an error.
                        }
                        break;
                }
                lastXY = curXY;
            }
            if (hasCurves == true)
                return new FlattenCurves(path);
            return path;
        }
Exemplo n.º 25
0
		public static void Main(string[] args)
		{
			// first we will show how to use the simple drawing functions in graphics 2D
			{
				ImageBuffer simpleImage = new ImageBuffer(640, 480, 32, new BlenderBGRA());
				Graphics2D simpleImageGraphics2D = simpleImage.NewGraphics2D();
				// clear the image to white
				simpleImageGraphics2D.Clear(RGBA_Bytes.White);
				// draw a circle
				simpleImageGraphics2D.Circle(50, 50, 30, RGBA_Bytes.Blue);
				// draw a line
				simpleImageGraphics2D.Line(10, 100, 520, 50, new RGBA_Bytes(20, 200, 200));
				// draw a filled box
				simpleImageGraphics2D.FillRectangle(60, 260, 200, 280, RGBA_Bytes.Yellow);
				// and an outline around it
				simpleImageGraphics2D.Rectangle(60, 260, 200, 280, RGBA_Bytes.Magenta);
				// draw some text
				simpleImageGraphics2D.DrawString("A Simple Example", 300, 400, 20);

				// and save this image out
				ImageTgaIO.Save(simpleImage, "SimpleDrawAndSave.tga");
			}

			// now we will we will show how to use the render function to draw more complex things
			{
				ImageBuffer lessSimpleImage = new ImageBuffer(640, 480, 32, new BlenderBGRA());
				Graphics2D lessSimpleImageGraphics2D = lessSimpleImage.NewGraphics2D();
				// clear the image to white
				lessSimpleImageGraphics2D.Clear(RGBA_Bytes.White);
				// draw a circle
				Ellipse ellipseTest = new Ellipse(0, 0, 100, 50);
				for (double angleDegrees = 0; angleDegrees < 180; angleDegrees += 22.5)
				{
					VertexSourceApplyTransform rotatedTransform = new VertexSourceApplyTransform(ellipseTest, Affine.NewRotation(MathHelper.DegreesToRadians(angleDegrees)));
					VertexSourceApplyTransform rotatedAndTranslatedTransform = new VertexSourceApplyTransform(rotatedTransform, Affine.NewTranslation(lessSimpleImage.Width / 2, 150));
					lessSimpleImageGraphics2D.Render(rotatedAndTranslatedTransform, RGBA_Bytes.Yellow);
					Stroke ellipseOutline = new Stroke(rotatedAndTranslatedTransform, 3);
					lessSimpleImageGraphics2D.Render(ellipseOutline, RGBA_Bytes.Blue);
				}

				// and a little polygon
				PathStorage littlePoly = new PathStorage();
				littlePoly.MoveTo(50, 50);
				littlePoly.LineTo(150, 50);
				littlePoly.LineTo(200, 200);
				littlePoly.LineTo(50, 150);
				littlePoly.LineTo(50, 50);
				lessSimpleImageGraphics2D.Render(littlePoly, RGBA_Bytes.Cyan);

				// draw some text
				TypeFacePrinter textPrinter = new TypeFacePrinter("Printing from a printer", 30, justification: Justification.Center);
				IVertexSource translatedText = new VertexSourceApplyTransform(textPrinter, Affine.NewTranslation(new Vector2(lessSimpleImage.Width / 2, lessSimpleImage.Height / 4 * 3)));
				lessSimpleImageGraphics2D.Render(translatedText, RGBA_Bytes.Red);
				Stroke strokedText = new Stroke(translatedText);
				lessSimpleImageGraphics2D.Render(strokedText, RGBA_Bytes.Black);

				IVertexSource rotatedText = new VertexSourceApplyTransform(textPrinter, Affine.NewRotation(MathHelper.DegreesToRadians(90)));
				IVertexSource rotatedTranslatedText = new VertexSourceApplyTransform(rotatedText, Affine.NewTranslation(new Vector2(40, lessSimpleImage.Height / 2)));
				lessSimpleImageGraphics2D.Render(rotatedTranslatedText, RGBA_Bytes.Black);

				// and save this image out
				ImageTgaIO.Save(lessSimpleImage, "LessSimpleDrawAndSave.tga");
			}
		}
Exemplo n.º 26
0
        private void RenderPolygonToPathAgainst(Graphics2D graphics2D)
        {
            IVertexSource pathToUse = null;
            switch (shapeTypeRadioGroup.SelectedIndex)
            {
                case 0:// simple polygon map
                    {
                        PathStorage ps1 = new PathStorage();

                        ps1.MoveTo(85, 417);
                        ps1.LineTo(338, 428);
                        ps1.LineTo(344, 325);
                        ps1.LineTo(399, 324);
                        ps1.LineTo(400, 421);
                        ps1.LineTo(644, 415);
                        ps1.LineTo(664, 75);
                        ps1.LineTo(98, 81);
                        ps1.ClosePolygon();

                        ps1.MoveTo(343, 290);
                        ps1.LineTo(159, 235);
                        ps1.LineTo(154, 162);
                        ps1.LineTo(340, 114);
                        ps1.ClosePolygon();

                        ps1.MoveTo(406, 121);
                        ps1.LineTo(587, 158);
                        ps1.LineTo(591, 236);
                        ps1.LineTo(404, 291);
                        ps1.ClosePolygon();

                        pathToUse = ps1;
                    }
                    break;

                case 1: // multiple pegs
                    {
                        PathStorage ps2 = new PathStorage();

                        double x = 0;
                        double y = 0;

                        ps2.MoveTo(100 + 32, 100 + 77);
                        ps2.LineTo(100 + 473, 100 + 263);
                        ps2.LineTo(100 + 351, 100 + 290);
                        ps2.LineTo(100 + 354, 100 + 374);

                        pathToUse = ps2;
                    }
                    break;

                case 2:
                    {
                        // circle holes
                        PathStorage ps1 = new PathStorage();

                        double x = 0;
                        double y = 0;
                        ps1.MoveTo(x + 140, y + 145);
                        ps1.LineTo(x + 225, y + 44);
                        ps1.LineTo(x + 296, y + 219);
                        ps1.ClosePolygon();

                        ps1.LineTo(x + 226, y + 289);
                        ps1.LineTo(x + 82, y + 292);
                        ps1.ClosePolygon();

                        ps1.MoveTo(x + 220 - 50, y + 222);
                        ps1.LineTo(x + 265 - 50, y + 331);
                        ps1.LineTo(x + 363 - 50, y + 249);
                        ps1.ClosePolygon();

                        pathToUse = ps1;
                    }
                    break;

                case 3: // Great Britain
                    {
                        PathStorage gb_poly = new PathStorage();
                        GreatBritanPathStorage.Make(gb_poly);

                        Affine mtx1 = Affine.NewIdentity();
                        Affine mtx2 = Affine.NewIdentity();
                        mtx1 *= Affine.NewTranslation(-1150, -1150);
                        mtx1 *= Affine.NewScaling(2.0);

                        mtx2 = mtx1;
                        mtx2 *= Affine.NewTranslation(Width / 2, Height / 2);

                        VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx1);

                        pathToUse = trans_gb_poly;
                    }
                    break;

                case 4: // Arrows
                    {
                        PathStorage arrows = new PathStorage();
                        make_arrows(arrows);

                        Affine mtx1 = Affine.NewIdentity();
                        mtx1 *= Affine.NewTranslation(-1150, -1150);
                        mtx1 *= Affine.NewScaling(2.0);

                        VertexSourceApplyTransform trans_arrows = new VertexSourceApplyTransform(arrows, mtx1);

                        pathToUse = trans_arrows;
                    }
                    break;

                case 5: // Spiral
                    {
                        spiral sp = new spiral(Width / 2, Height / 2, 10, 150, 30, 0.0);
                        Stroke stroke = new Stroke(sp);
                        stroke.width(15.0);

                        Affine mtx = Affine.NewIdentity(); ;
                        mtx *= Affine.NewTranslation(-1150, -1150);
                        mtx *= Affine.NewScaling(2.0);

                        pathToUse = stroke;
                    }
                    break;

                case 6: // Glyph
                    {
                        //------------------------------------
                        // Spiral and glyph
                        //
                        PathStorage glyph = new PathStorage();
                        glyph.MoveTo(28.47, 6.45);
                        glyph.curve3(21.58, 1.12, 19.82, 0.29);
                        glyph.curve3(17.19, -0.93, 14.21, -0.93);
                        glyph.curve3(9.57, -0.93, 6.57, 2.25);
                        glyph.curve3(3.56, 5.42, 3.56, 10.60);
                        glyph.curve3(3.56, 13.87, 5.03, 16.26);
                        glyph.curve3(7.03, 19.58, 11.99, 22.51);
                        glyph.curve3(16.94, 25.44, 28.47, 29.64);
                        glyph.LineTo(28.47, 31.40);
                        glyph.curve3(28.47, 38.09, 26.34, 40.58);
                        glyph.curve3(24.22, 43.07, 20.17, 43.07);
                        glyph.curve3(17.09, 43.07, 15.28, 41.41);
                        glyph.curve3(13.43, 39.75, 13.43, 37.60);
                        glyph.LineTo(13.53, 34.77);
                        glyph.curve3(13.53, 32.52, 12.38, 31.30);
                        glyph.curve3(11.23, 30.08, 9.38, 30.08);
                        glyph.curve3(7.57, 30.08, 6.42, 31.35);
                        glyph.curve3(5.27, 32.62, 5.27, 34.81);
                        glyph.curve3(5.27, 39.01, 9.57, 42.53);
                        glyph.curve3(13.87, 46.04, 21.63, 46.04);
                        glyph.curve3(27.59, 46.04, 31.40, 44.04);
                        glyph.curve3(34.28, 42.53, 35.64, 39.31);
                        glyph.curve3(36.52, 37.21, 36.52, 30.71);
                        glyph.LineTo(36.52, 15.53);
                        glyph.curve3(36.52, 9.13, 36.77, 7.69);
                        glyph.curve3(37.01, 6.25, 37.57, 5.76);
                        glyph.curve3(38.13, 5.27, 38.87, 5.27);
                        glyph.curve3(39.65, 5.27, 40.23, 5.62);
                        glyph.curve3(41.26, 6.25, 44.19, 9.18);
                        glyph.LineTo(44.19, 6.45);
                        glyph.curve3(38.72, -0.88, 33.74, -0.88);
                        glyph.curve3(31.35, -0.88, 29.93, 0.78);
                        glyph.curve3(28.52, 2.44, 28.47, 6.45);
                        glyph.ClosePolygon();

                        glyph.MoveTo(28.47, 9.62);
                        glyph.LineTo(28.47, 26.66);
                        glyph.curve3(21.09, 23.73, 18.95, 22.51);
                        glyph.curve3(15.09, 20.36, 13.43, 18.02);
                        glyph.curve3(11.77, 15.67, 11.77, 12.89);
                        glyph.curve3(11.77, 9.38, 13.87, 7.06);
                        glyph.curve3(15.97, 4.74, 18.70, 4.74);
                        glyph.curve3(22.41, 4.74, 28.47, 9.62);
                        glyph.ClosePolygon();

                        Affine mtx = Affine.NewIdentity();
                        mtx *= Affine.NewScaling(4.0);
                        mtx *= Affine.NewTranslation(220, 200);
                        VertexSourceApplyTransform trans = new VertexSourceApplyTransform(glyph, mtx);
                        FlattenCurves curve = new FlattenCurves(trans);

                        pathToUse = curve;
                    }
                    break;
            }

            graphics2D.Render(pathToUse, fillColor);

            PathStorage travelLine = new PathStorage();
            travelLine.MoveTo(lineStart);
            travelLine.LineTo(mousePosition);

            Polygons polygonsToPathAround = VertexSourceToClipperPolygons.CreatePolygons(pathToUse, 1);
            polygonsToPathAround = FixWinding(polygonsToPathAround);

            Polygons travelPolysLine = VertexSourceToClipperPolygons.CreatePolygons(travelLine, 1);

            CreateAndRenderPathing(graphics2D, polygonsToPathAround, travelPolysLine);
        }