public void CompareToLionTGA() { LionShape lionShape = new LionShape(); ImageBuffer renderedImage = new ImageBuffer(512, 400, 24, new BlenderBGR()); byte alpha = (byte)(.1 * 255); for (int i = 0; i < lionShape.NumPaths; i++) { lionShape.Colors[i].Alpha0To255 = alpha; } Affine transform = Affine.NewIdentity(); transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y); transform *= Affine.NewTranslation(renderedImage.Width / 2, renderedImage.Height / 2); // This code renders the lion: VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(lionShape.Path, transform); Graphics2D renderer = renderedImage.NewGraphics2D(); renderer.Clear(new RGBA_Floats(1.0, 1.0, 1.0, 1.0)); renderer.Render(transformedPathStorage, lionShape.Colors, lionShape.PathIndex, lionShape.NumPaths); ImageTgaIO.Save(renderedImage, "TestOutput.tga"); Stream imageStream = File.Open("LionRenderMaster.tga", FileMode.Open); ImageBuffer masterImage = new ImageBuffer(); ImageTgaIO.LoadImageData(masterImage, imageStream, 24); bool sameWidth = masterImage.Width == renderedImage.Width; bool sameHeight = masterImage.Height == renderedImage.Height; Assert.IsTrue(sameWidth && sameHeight); Assert.IsTrue(masterImage.BitDepth == renderedImage.BitDepth); int unused; byte[] masterBuffer = masterImage.GetBuffer(out unused); byte[] renderedBuffer = renderedImage.GetBuffer(out unused); Assert.IsTrue(masterBuffer.Length == renderedBuffer.Length); for (int i = 0; i < masterBuffer.Length; i++) { if (masterBuffer[i] != renderedBuffer[i]) { Assert.IsTrue(false); } } }
public override void Render(IVertexSource vertexSource, int pathIndexToRender, IColorType colorBytes) { rasterizer.reset(); Affine transform = GetTransform(); if (!transform.is_identity()) { vertexSource = new VertexSourceApplyTransform(vertexSource, transform); } rasterizer.add_path(vertexSource, pathIndexToRender); if (destImageByte != null) { scanlineRenderer.RenderSolid(destImageByte, rasterizer, m_ScanlineCache, colorBytes.GetAsRGBA_Bytes()); DestImage.MarkImageChanged(); } else { scanlineRenderer.RenderSolid(destImageFloat, rasterizer, m_ScanlineCache, colorBytes.GetAsRGBA_Floats()); destImageFloat.MarkImageChanged(); } }
public override void OnDraw(Graphics2D graphics2D) { byte alpha = (byte)(alphaSlider.Value * 255); for (int i = 0; i < lionShape.NumPaths; i++) { lionShape.Colors[i].Alpha0To255 = alpha; } Affine transform = Affine.NewIdentity(); transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y); transform *= Affine.NewScaling(lionScale, lionScale); transform *= Affine.NewRotation(angle + Math.PI); transform *= Affine.NewSkewing(skewX / 1000.0, skewY / 1000.0); transform *= Affine.NewTranslation(Width / 2, Height / 2); // This code renders the lion: VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(lionShape.Path, transform); graphics2D.Render(transformedPathStorage, lionShape.Colors, lionShape.PathIndex, lionShape.NumPaths); base.OnDraw(graphics2D); }
public void DrawAAShape(IVertexSource vertexSource, IColorType colorIn) { vertexSource.rewind(0); Affine transform = GetTransform(); if (!transform.is_identity()) { vertexSource = new VertexSourceApplyTransform(vertexSource, transform); } RGBA_Bytes colorBytes = colorIn.GetAsRGBA_Bytes(); GL.Color4(colorBytes.red, colorBytes.green, colorBytes.blue, colorBytes.alpha); triangleEddgeInfo.Clear(); VertexSourceToTesselator.SendShapeToTesselator(triangleEddgeInfo, vertexSource); // now render it triangleEddgeInfo.RenderLastToGL(); }
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); } }
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; } }
private void DrawImage(IImageByte sourceImage, ISpanGenerator spanImageFilter, Affine destRectTransform) { if (destImageByte.OriginOffset.x != 0 || destImageByte.OriginOffset.y != 0) { destRectTransform *= Affine.NewTranslation(-destImageByte.OriginOffset.x, -destImageByte.OriginOffset.y); } VertexSourceApplyTransform transformedRect = new VertexSourceApplyTransform(drawImageRectPath, destRectTransform); Rasterizer.add_path(transformedRect); { ImageClippingProxy destImageWithClipping = new ImageClippingProxy(destImageByte); scanlineRenderer.GenerateAndRender(Rasterizer, drawImageScanlineCache, destImageWithClipping, destImageSpanAllocatorCache, spanImageFilter); } }
public void ShowDebugInfo(Graphics2D graphics2D) { StyledTypeFace typeFaceNameStyle = new StyledTypeFace(this, 30); TypeFacePrinter fontNamePrinter = new TypeFacePrinter(this.fontFamily + " - 30 point", typeFaceNameStyle); RectangleDouble bounds = typeFaceNameStyle.BoundingBoxInPixels; double origX = 10 - bounds.Left; double x = origX; double y = 10 - typeFaceNameStyle.DescentInPixels; int width = 50; RGBA_Bytes boundingBoxColor = new RGBA_Bytes(0, 0, 0); RGBA_Bytes originColor = new RGBA_Bytes(0, 0, 0); RGBA_Bytes ascentColor = new RGBA_Bytes(255, 0, 0); RGBA_Bytes descentColor = new RGBA_Bytes(255, 0, 0); RGBA_Bytes xHeightColor = new RGBA_Bytes(12, 25, 200); RGBA_Bytes capHeightColor = new RGBA_Bytes(12, 25, 200); RGBA_Bytes underlineColor = new RGBA_Bytes(0, 150, 55); // the origin graphics2D.Line(x, y, x + width, y, originColor); graphics2D.Rectangle(x + bounds.Left, y + bounds.Bottom, x + bounds.Right, y + bounds.Top, boundingBoxColor); x += typeFaceNameStyle.BoundingBoxInPixels.Width * 1.5; width = width * 3; double temp = typeFaceNameStyle.AscentInPixels; graphics2D.Line(x, y + temp, x + width, y + temp, ascentColor); temp = typeFaceNameStyle.DescentInPixels; graphics2D.Line(x, y + temp, x + width, y + temp, descentColor); temp = typeFaceNameStyle.XHeightInPixels; graphics2D.Line(x, y + temp, x + width, y + temp, xHeightColor); temp = typeFaceNameStyle.CapHeightInPixels; graphics2D.Line(x, y + temp, x + width, y + temp, capHeightColor); temp = typeFaceNameStyle.UnderlinePositionInPixels; graphics2D.Line(x, y + temp, x + width, y + temp, underlineColor); Affine textTransform; textTransform = Affine.NewIdentity(); textTransform *= Affine.NewTranslation(10, origX); VertexSourceApplyTransform transformedText = new VertexSourceApplyTransform(textTransform); fontNamePrinter.Render(graphics2D, RGBA_Bytes.Black, transformedText); graphics2D.Render(transformedText, RGBA_Bytes.Black); // render the legend StyledTypeFace legendFont = new StyledTypeFace(this, 12); Vector2 textPos = new Vector2(x + width / 2, y + typeFaceNameStyle.EmSizeInPixels * 1.5); graphics2D.Render(new TypeFacePrinter("Descent"), textPos, descentColor); textPos.y += legendFont.EmSizeInPixels; graphics2D.Render(new TypeFacePrinter("Underline"), textPos, underlineColor); textPos.y += legendFont.EmSizeInPixels; graphics2D.Render(new TypeFacePrinter("X Height"), textPos, xHeightColor); textPos.y += legendFont.EmSizeInPixels; graphics2D.Render(new TypeFacePrinter("CapHeight"), textPos, capHeightColor); textPos.y += legendFont.EmSizeInPixels; graphics2D.Render(new TypeFacePrinter("Ascent"), textPos, ascentColor); textPos.y += legendFont.EmSizeInPixels; graphics2D.Render(new TypeFacePrinter("Origin"), textPos, originColor); textPos.y += legendFont.EmSizeInPixels; graphics2D.Render(new TypeFacePrinter("Bounding Box"), textPos, boundingBoxColor); }
public IVertexSource GetGlyphForCharacter(char character) { // scale it to the correct size. IVertexSource sourceGlyph = TypeFace.GetGlyphForCharacter(character); if (sourceGlyph != null) { if (DoUnderline) { sourceGlyph = new GlyphWithUnderline(sourceGlyph, TypeFace.GetAdvanceForCharacter(character), TypeFace.Underline_position, TypeFace.Underline_thickness); } Affine glyphTransform = Affine.NewIdentity(); glyphTransform *= Affine.NewScaling(currentEmScaling); IVertexSource characterGlyph = new VertexSourceApplyTransform(sourceGlyph, glyphTransform); if (FlatenCurves) { characterGlyph = new FlattenCurves(characterGlyph); } return characterGlyph; } return null; }
//矩形 public UIGraphic AddRectangle(double x, double y, double width, double height, CCColor4B fill, CCColor4B stroke, double radiusX = 0, double radiusY = 0, double strokeThickness = 1) { IVertexSource path; if (stroke.A > 0) //有border { //border是以线的中间对齐,所以转换成int,如果是1个像素,有圆角变成1,没圆角变成0 int halfThickness = (radiusX != 0 || radiusY != 0) ? (int)((strokeThickness + 1) / 2) : (int)(strokeThickness / 2); path = new RoundedRect(halfThickness, halfThickness, width - halfThickness, height - halfThickness, Math.Min(radiusX, radiusY)); } else { path = new RoundedRect(0, 0, width, height, Math.Min(radiusX, radiusY)); } if (x != 0 || y != 0) path = new VertexSourceApplyTransform(path, Affine.NewTranslation(x, y)); if (fill.A > 0) this.graphics2D.Render(path, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A)); if (stroke.A > 0) this.graphics2D.Render(new Stroke(path, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A)); return this; }
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; }
public void Draw(MatterHackers.Agg.Transform.ITransform Position, Graphics2D renderer) { double TextHeight = m_Position.y - 20; double Range = (m_DataViewMaxY - m_DataViewMinY); VertexSourceApplyTransform TransformedLinesToDraw; Stroke StrockedTransformedLinesToDraw; RoundedRect BackGround = new RoundedRect(m_Position.x, m_Position.y - 1, m_Position.x + m_Width, m_Position.y - 1 + m_Height + 2, 5); VertexSourceApplyTransform TransformedBackGround = new VertexSourceApplyTransform(BackGround, Position); renderer.Render(TransformedBackGround, new RGBA_Bytes(0, 0, 0, .5)); // if the 0 line is within the window than draw it. if (m_DataViewMinY < 0 && m_DataViewMaxY > 0) { m_LinesToDraw.remove_all(); m_LinesToDraw.MoveTo(m_Position.x, m_Position.y + ((0 - m_DataViewMinY) * m_Height / Range)); m_LinesToDraw.LineTo(m_Position.x + m_Width, m_Position.y + ((0 - m_DataViewMinY) * m_Height / Range)); TransformedLinesToDraw = new VertexSourceApplyTransform(m_LinesToDraw, Position); StrockedTransformedLinesToDraw = new Stroke(TransformedLinesToDraw); renderer.Render(StrockedTransformedLinesToDraw, new RGBA_Bytes(0, 0, 0, 1)); } double MaxMax = -999999999; double MinMin = 999999999; double MaxAverage = 0; foreach (KeyValuePair<String, HistoryData> historyKeyValue in m_DataHistoryArray) { HistoryData history = historyKeyValue.Value; m_LinesToDraw.remove_all(); MaxMax = System.Math.Max(MaxMax, history.GetMaxValue()); MinMin = System.Math.Min(MinMin, history.GetMinValue()); MaxAverage = System.Math.Max(MaxAverage, history.GetAverageValue()); for(int i = 0; i < m_Width - 1; i++) { if(i==0) { m_LinesToDraw.MoveTo(m_Position.x + i, m_Position.y + ((history.GetItem(i) - m_DataViewMinY) * m_Height / Range)); } else { m_LinesToDraw.LineTo(m_Position.x + i, m_Position.y + ((history.GetItem(i) - m_DataViewMinY) * m_Height / Range)); } } TransformedLinesToDraw = new VertexSourceApplyTransform(m_LinesToDraw, Position); StrockedTransformedLinesToDraw = new Stroke(TransformedLinesToDraw); renderer.Render(StrockedTransformedLinesToDraw, history.m_Color); String Text = historyKeyValue.Key + ": Min:" + MinMin.ToString("0.0") + " Max:" + MaxMax.ToString("0.0"); renderer.DrawString(Text, m_Position.x, TextHeight - m_Height); TextHeight -= 20; } RoundedRect BackGround2 = new RoundedRect(m_Position.x, m_Position.y - 1, m_Position.x + m_Width, m_Position.y - 1 + m_Height + 2, 5); VertexSourceApplyTransform TransformedBackGround2 = new VertexSourceApplyTransform(BackGround2, Position); Stroke StrockedTransformedBackGround = new Stroke(TransformedBackGround2); renderer.Render(StrockedTransformedBackGround, new RGBA_Bytes(0.0, 0, 0, 1)); //renderer.Color = BoxColor; //renderer.DrawRect(m_Position.x, m_Position.y - 1, m_Width, m_Height + 2); }
public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo) { if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves) { double movementLineWidth = 0.35 * renderInfo.LayerScale; RGBA_Bytes movementColor = new RGBA_Bytes(10, 190, 15); PathStorage pathStorage = new PathStorage(); VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform); Stroke stroke = new Stroke(transformedPathStorage, movementLineWidth); stroke.line_cap(LineCap.Round); stroke.line_join(LineJoin.Round); Vector3Float start = this.GetStart(renderInfo); Vector3Float end = this.GetEnd(renderInfo); pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.CommandMoveTo); if (end.x != start.x || end.y != start.y) { pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo); } else { pathStorage.Add(end.x + .01, end.y, ShapePath.FlagsAndCommand.CommandLineTo); } graphics2D.Render(stroke, 0, movementColor); } }
public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo) { if (renderInfo.CurrentRenderType.HasFlag(RenderType.Extrusions)) { double extrusionLineWidths = GetExtrusionWidth(renderInfo.CurrentRenderType) * 2 * renderInfo.LayerScale; RGBA_Bytes extrusionColor = RGBA_Bytes.Black; if (extruderIndex > 0) { extrusionColor = MeshViewerWidget.GetMaterialColor(extruderIndex + 1); } if (renderInfo.CurrentRenderType.HasFlag(RenderType.SpeedColors)) { extrusionColor = color; } if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion)) { extrusionColor = new RGBA_Bytes(extrusionColor, 200); } // render the part using opengl Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL; if (graphics2DGl != null) { Vector3Float startF = this.GetStart(renderInfo); Vector3Float endF = this.GetEnd(renderInfo); Vector2 start = new Vector2(startF.x, startF.y); renderInfo.Transform.transform(ref start); Vector2 end = new Vector2(endF.x, endF.y); renderInfo.Transform.transform(ref end); graphics2DGl.DrawAALineRounded(start, end, extrusionLineWidths/2, extrusionColor); } else { PathStorage pathStorage = new PathStorage(); VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform); Stroke stroke = new Stroke(transformedPathStorage, extrusionLineWidths/2); stroke.line_cap(LineCap.Round); stroke.line_join(LineJoin.Round); Vector3Float start = this.GetStart(renderInfo); Vector3Float end = this.GetEnd(renderInfo); pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.CommandMoveTo); pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo); graphics2D.Render(stroke, 0, extrusionColor); } } }
public override void Render(IVertexSource vertexSource, int pathIndexToRender, IColorType colorIn) { PreRender(); if (DoEdgeAntiAliasing) { DrawAAShape(vertexSource, colorIn); } else { vertexSource.rewind(pathIndexToRender); Affine transform = GetTransform(); if (!transform.is_identity()) { vertexSource = new VertexSourceApplyTransform(vertexSource, transform); } RGBA_Bytes colorBytes = colorIn.GetAsRGBA_Bytes(); GL.Color4(colorBytes.red, colorBytes.green, colorBytes.blue, colorBytes.alpha); renderNowTesselator.Clear(); VertexSourceToTesselator.SendShapeToTesselator(renderNowTesselator, vertexSource); } PopOrthoProjection(); }
//圆形 public UIGraphic AddEllipse(double x, double y, double width, double height, CCColor4B fill, CCColor4B stroke, double strokeThickness = 1) { IVertexSource path; if (stroke.A > 0) //有border { //border是以线的中间对齐,所以转换成int,如果是1个像素变成1 int halfThickness = (int)((strokeThickness + 1) / 2); path = new MatterHackers.Agg.VertexSource.Ellipse(width / 2, height / 2, width / 2 - halfThickness, height / 2 - halfThickness); } else { path = new MatterHackers.Agg.VertexSource.Ellipse(width / 2, height / 2, width / 2, height / 2); } if (x != 0 || y != 0) path = new VertexSourceApplyTransform(path, Affine.NewTranslation(x, y)); if (fill.A > 0) this.graphics2D.Render(path, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A)); if (stroke.A > 0) this.graphics2D.Render(new Stroke(path, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A)); return this; }
public UIGraphic AddPaths( double x, double y, double width, double height, string[] paths, double contentX, double contentY, double contentWidth, double contentHeight, CCColor4B fill, CCColor4B stroke, double strokeThickness = 1, Stretch stretch = Stretch.StretchFill ) { if (width == 0) width = contentWidth; if (height == 0) height = contentHeight; double scalex = 1.0; double scaley = 1.0; //if (stretch == Stretch.StretchNone) { } else if (stretch == Stretch.StretchFill) { if (width != contentWidth || height != contentHeight) { scalex = width / contentWidth; scaley = height / contentHeight; } } else if (stretch == Stretch.StretchUniformToFill) { scalex = scaley = Math.Min(width / contentWidth, height / contentHeight); } foreach (string path in paths) { IVertexSource vertexs = MiniLanguage.CreatePathStorage(path); //先缩放再平移 if (scalex != 1.0 || scaley != 1.0) vertexs = new VertexSourceApplyTransform(vertexs, Affine.NewScaling(scalex, scaley)); if (x != 0 || y != 0 || contentX != 0 || contentY != 0) vertexs = new VertexSourceApplyTransform(vertexs, Affine.NewTranslation(x - contentX, y - contentY)); if (fill.A > 0) this.graphics2D.Render(vertexs, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A)); if (stroke.A > 0) this.graphics2D.Render(new Stroke(vertexs, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A)); } return this; }
public override void OnDraw(Graphics2D graphics2D) { ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect()); int width = (int)widgetsSubImage.Width; int height = (int)widgetsSubImage.Height; if (numMasksSlider.Value != sliderValue) { generate_alpha_mask(width, height); sliderValue = numMasksSlider.Value; } rasterizer.SetVectorClipBox(0, 0, width, height); unsafe { alphaMaskImageBuffer.AttachBuffer(alphaByteArray, 0, width, height, width, 8, 1); MatterHackers.Agg.Image.AlphaMaskAdaptor imageAlphaMaskAdaptor = new MatterHackers.Agg.Image.AlphaMaskAdaptor(widgetsSubImage, alphaMask); ImageClippingProxy alphaMaskClippingProxy = new ImageClippingProxy(imageAlphaMaskAdaptor); ImageClippingProxy clippingProxy = new ImageClippingProxy(widgetsSubImage); Affine transform = Affine.NewIdentity(); transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y); transform *= Affine.NewScaling(lionScale, lionScale); transform *= Affine.NewRotation(angle + Math.PI); transform *= Affine.NewSkewing(skewX / 1000.0, skewY / 1000.0); transform *= Affine.NewTranslation(Width / 2, Height / 2); clippingProxy.clear(new RGBA_Floats(1, 1, 1)); ScanlineRenderer scanlineRenderer = new ScanlineRenderer(); // draw a background to show how the mask is working better int RectWidth = 30; for (int i = 0; i < 40; i++) { for (int j = 0; j < 40; j++) { if ((i + j) % 2 != 0) { VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * RectWidth, j * RectWidth, (i + 1) * RectWidth, (j + 1) * RectWidth, 0); rect.normalize_radius(); // Drawing as an outline rasterizer.add_path(rect); scanlineRenderer.render_scanlines_aa_solid(clippingProxy, rasterizer, scanlineCache, new RGBA_Bytes(.9, .9, .9)); } } } //int x, y; // Render the lion VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform); scanlineRenderer.RenderSolidAllPaths(alphaMaskClippingProxy, rasterizer, scanlineCache, trans, lionShape.Colors, lionShape.PathIndex, lionShape.NumPaths); /* // Render random Bresenham lines and markers agg::renderer_markers<amask_ren_type> m(r); for(i = 0; i < 50; i++) { m.line_color(agg::rgba8(randGenerator.Next() & 0x7F, randGenerator.Next() & 0x7F, randGenerator.Next() & 0x7F, (randGenerator.Next() & 0x7F) + 0x7F)); m.fill_color(agg::rgba8(randGenerator.Next() & 0x7F, randGenerator.Next() & 0x7F, randGenerator.Next() & 0x7F, (randGenerator.Next() & 0x7F) + 0x7F)); m.line(m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height), m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height)); m.marker(randGenerator.Next() % width, randGenerator.Next() % height, randGenerator.Next() % 10 + 5, agg::marker_e(randGenerator.Next() % agg::end_of_markers)); } // Render random anti-aliased lines double w = 5.0; agg::line_profile_aa profile; profile.width(w); typedef agg::renderer_outline_aa<amask_ren_type> renderer_type; renderer_type ren(r, profile); typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type; rasterizer_type ras(ren); ras.round_cap(true); for(i = 0; i < 50; i++) { ren.Color = agg::rgba8(randGenerator.Next() & 0x7F, randGenerator.Next() & 0x7F, randGenerator.Next() & 0x7F, //255)); (randGenerator.Next() & 0x7F) + 0x7F); ras.move_to_d(randGenerator.Next() % width, randGenerator.Next() % height); ras.line_to_d(randGenerator.Next() % width, randGenerator.Next() % height); ras.render(false); } // Render random circles with gradient typedef agg::gradient_linear_color<color_type> grad_color; typedef agg::gradient_circle grad_func; typedef agg::span_interpolator_linear<> interpolator_type; typedef agg::span_gradient<color_type, interpolator_type, grad_func, grad_color> span_grad_type; agg::trans_affine grm; grad_func grf; grad_color grc(agg::rgba8(0,0,0), agg::rgba8(0,0,0)); agg::ellipse ell; agg::span_allocator<color_type> sa; interpolator_type inter(grm); span_grad_type sg(inter, grf, grc, 0, 10); agg::renderer_scanline_aa<amask_ren_type, agg::span_allocator<color_type>, span_grad_type> rg(r, sa, sg); for(i = 0; i < 50; i++) { x = randGenerator.Next() % width; y = randGenerator.Next() % height; double r = randGenerator.Next() % 10 + 5; grm.reset(); grm *= agg::trans_affine_scaling(r / 10.0); grm *= agg::trans_affine_translation(x, y); grm.invert(); grc.colors(agg::rgba8(255, 255, 255, 0), agg::rgba8(randGenerator.Next() & 0x7F, randGenerator.Next() & 0x7F, randGenerator.Next() & 0x7F, 255)); sg.color_function(grc); ell.init(x, y, r, r, 32); g_rasterizer.add_path(ell); agg::render_scanlines(g_rasterizer, g_scanline, rg); } */ //m_num_cb.Render(g_rasterizer, g_scanline, clippingProxy); } alphaMaskImageBuffer.DettachBuffer(); base.OnDraw(graphics2D); }
public UIGraphic AddText(double x, double y, string text, CCColor4B fill, CCColor4B stroke, TypeFace font, double emSizeInPoints, bool underline = false, bool flatenCurves = true, double strokeThickness = 1) { TypeFacePrinter printer; if (font != null) printer = new TypeFacePrinter(text, new StyledTypeFace(font, emSizeInPoints, underline, flatenCurves)); else printer = new TypeFacePrinter(text, emSizeInPoints); RectangleDouble rect = new RectangleDouble(); bounding_rect.bounding_rect_single(printer, 0, ref rect); VertexSourceApplyTransform path = path = new VertexSourceApplyTransform(printer, Affine.NewTranslation(x - rect.Left, y - rect.Bottom)); if (fill.A > 0) this.graphics2D.Render(path, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A)); if (stroke.A > 0) this.graphics2D.Render(new Stroke(path, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A)); return this; }
public override void OnDraw(Graphics2D graphics2D) { ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect()); ImageClippingProxy clippingProxy = new ImageClippingProxy(widgetsSubImage); clippingProxy.clear(new RGBA_Floats(1, 1, 1)); m_ras.SetVectorClipBox(0, 0, Width, Height); Affine move = Affine.NewTranslation(10, 10); Perspective shadow_persp = new Perspective(m_shape_bounds.Left, m_shape_bounds.Bottom, m_shape_bounds.Right, m_shape_bounds.Top, m_shadow_ctrl.polygon()); IVertexSource shadow_trans; if (m_FlattenCurves.Checked) { shadow_trans = new VertexSourceApplyTransform(m_shape, shadow_persp); } else { shadow_trans = new VertexSourceApplyTransform(m_path, shadow_persp); // this will make it very smooth after the transform //shadow_trans = new conv_curve(shadow_trans); } // Render shadow m_ras.add_path(shadow_trans); ScanlineRenderer scanlineRenderer = new ScanlineRenderer(); scanlineRenderer.RenderSolid(clippingProxy, m_ras, m_sl, new RGBA_Floats(0.2, 0.3, 0).GetAsRGBA_Bytes()); // Calculate the bounding box and extend it by the blur radius RectangleDouble bbox = new RectangleDouble(); bounding_rect.bounding_rect_single(shadow_trans, 0, ref bbox); bbox.Left -= m_radius.Value; bbox.Bottom -= m_radius.Value; bbox.Right += m_radius.Value; bbox.Top += m_radius.Value; if (m_method.SelectedIndex == 1) { // The recursive blur method represents the true Gaussian Blur, // with theoretically infinite kernel. The restricted window size // results in extra influence of edge pixels. It's impossible to // solve correctly, but extending the right and top areas to another // radius value produces fair result. //------------------ bbox.Right += m_radius.Value; bbox.Top += m_radius.Value; } stopwatch.Restart(); if (m_method.SelectedIndex != 2) { // Create a new pixel renderer and attach it to the main one as a child image. // It returns true if the attachment succeeded. It fails if the rectangle // (bbox) is fully clipped. //------------------ #if SourceDepth24 ImageBuffer image2 = new ImageBuffer(new BlenderBGR()); #else ImageBuffer image2 = new ImageBuffer(new BlenderBGRA()); #endif if (image2.Attach(widgetsSubImage, (int)bbox.Left, (int)bbox.Bottom, (int)bbox.Right, (int)bbox.Top)) { // Blur it if (m_method.SelectedIndex == 0) { // More general method, but 30-40% slower. //------------------ //m_stack_blur.blur(pixf2, agg::uround(m_radius.Value)); // Faster, but bore specific. // Works only for 8 bits per channel and only with radii <= 254. //------------------ stack_blur test = new stack_blur(); test.Blur(image2, agg_basics.uround(m_radius.Value), agg_basics.uround(m_radius.Value)); } else { // True Gaussian Blur, 3-5 times slower than Stack Blur, // but still constant time of radius. Very sensitive // to precision, doubles are must here. //------------------ m_recursive_blur.blur(image2, m_radius.Value); } } } else { /* // Blur separate channels //------------------ if(m_channel_r.Checked) { typedef agg::pixfmt_alpha_blend_gray< agg::blender_gray8, agg::rendering_buffer, 3, 2> pixfmt_gray8r; pixfmt_gray8r pixf2r(m_rbuf2); if(pixf2r.attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2))) { agg::stack_blur_gray8(pixf2r, agg::uround(m_radius.Value), agg::uround(m_radius.Value)); } } if(m_channel_g.Checked) { typedef agg::pixfmt_alpha_blend_gray< agg::blender_gray8, agg::rendering_buffer, 3, 1> pixfmt_gray8g; pixfmt_gray8g pixf2g(m_rbuf2); if(pixf2g.attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2))) { agg::stack_blur_gray8(pixf2g, agg::uround(m_radius.Value), agg::uround(m_radius.Value)); } } if(m_channel_b.Checked) { typedef agg::pixfmt_alpha_blend_gray< agg::blender_gray8, agg::rendering_buffer, 3, 0> pixfmt_gray8b; pixfmt_gray8b pixf2b(m_rbuf2); if(pixf2b.attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2))) { agg::stack_blur_gray8(pixf2b, agg::uround(m_radius.Value), agg::uround(m_radius.Value)); } } */ } double tm = stopwatch.ElapsedMilliseconds; // Render the shape itself //------------------ if (m_FlattenCurves.Checked) { m_ras.add_path(m_shape); } else { m_ras.add_path(m_path); } scanlineRenderer.RenderSolid(clippingProxy, m_ras, m_sl, new RGBA_Floats(0.6, 0.9, 0.7, 0.8).GetAsRGBA_Bytes()); graphics2D.DrawString(string.Format("{0:F2} ms", tm), 140, 30); base.OnDraw(graphics2D); }
private void DrawBigA(Graphics2D graphics2D) { ScanlineRasterizer m_ras = new ScanlineRasterizer(); m_ras.SetVectorClipBox(0, 0, Width, Height); TypeFacePrinter bigAPrinter = new TypeFacePrinter("a", 150); FlattenCurves flattenedBigA = new FlattenCurves(bigAPrinter); VertexSourceApplyTransform scaleAndTranslate = new VertexSourceApplyTransform(flattenedBigA, Affine.NewTranslation(155, 55)); ScanlineCachePacked8 m_sl = new ScanlineCachePacked8(); ScanlineRenderer scanlineRenderer = new ScanlineRenderer(); #if false ImageProxySubpxelLcd24 clippingProxy = new ImageProxySubpxelLcd24(graphics2D.DestImage, new lcd_distribution_lut()); VertexSourceApplyTransform scaledWide = new VertexSourceApplyTransform(scaleAndTranslate, Affine.NewScaling(3, 1)); m_ras.add_path(scaledWide); scanlineRenderer.render_scanlines_aa_solid(clippingProxy, m_ras, m_sl, RGBA_Bytes.Black); #else m_ras.add_path(scaleAndTranslate); ImageClippingProxy clippingProxy = new ImageClippingProxy(graphics2D.DestImage); scanlineRenderer.RenderSolid(clippingProxy, m_ras, m_sl, RGBA_Bytes.Black); #endif }
public override void Render(IVertexSource vertexSource, int pathIndexToRender, IColorType colorIn) { PushOrthoProjection(); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.Blend); vertexSource.rewind(pathIndexToRender); RGBA_Bytes colorBytes = colorIn.GetAsRGBA_Bytes(); GL.Color4(colorBytes.red, colorBytes.green, colorBytes.blue, colorBytes.alpha); Affine transform = GetTransform(); if (!transform.is_identity()) { vertexSource = new VertexSourceApplyTransform(vertexSource, transform); } if (DoEdgeAntiAliasing) { DrawAAShape(vertexSource); } else { renderNowTesselator.Clear(); Graphics2DOpenGL.SendShapeToTesselator(renderNowTesselator, vertexSource); } PopOrthoProjection(); }
public override void OnDraw(Graphics2D graphics2D) { ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect()); if (orignialSize.x == 0) { orignialSize.x = WindowSize.x; orignialSize.y = WindowSize.y; } ImageBuffer destImageWithPreMultBlender = new ImageBuffer(); switch (widgetsSubImage.BitDepth) { case 24: destImageWithPreMultBlender.Attach(widgetsSubImage, new BlenderPreMultBGR()); break; case 32: destImageWithPreMultBlender.Attach(widgetsSubImage, new BlenderPreMultBGRA()); break; default: throw new Exception("Unknown bit depth"); } ImageClippingProxy clippingProxy_pre = new ImageClippingProxy(destImageWithPreMultBlender); clippingProxy_pre.clear(new RGBA_Floats(1.0, 1.0, 1.0)); Affine src_mtx = Affine.NewIdentity(); src_mtx *= Affine.NewTranslation(-orignialSize.x / 2 - 10, -orignialSize.y / 2 - 20 - 10); src_mtx *= Affine.NewRotation(drawAngle.Value * Math.PI / 180.0); src_mtx *= Affine.NewScaling(drawScale.Value); src_mtx *= Affine.NewTranslation(orignialSize.x / 2, orignialSize.y / 2 + 20); Affine img_mtx = Affine.NewIdentity(); img_mtx *= Affine.NewTranslation(-orignialSize.x / 2 + 10, -orignialSize.y / 2 + 20 + 10); img_mtx *= Affine.NewRotation(drawAngle.Value * Math.PI / 180.0); img_mtx *= Affine.NewScaling(drawScale.Value); img_mtx *= Affine.NewTranslation(orignialSize.x / 2, orignialSize.y / 2 + 20); img_mtx.invert(); MatterHackers.Agg.span_allocator sa = new span_allocator(); span_interpolator_linear interpolator = new span_interpolator_linear(img_mtx); span_image_filter sg; switch (sourceImage.BitDepth) { case 24: { ImageBufferAccessorClip source = new ImageBufferAccessorClip(sourceImage, RGBA_Floats.rgba_pre(0, 0, 0, 0).GetAsRGBA_Bytes()); sg = new span_image_filter_rgb_bilinear_clip(source, RGBA_Floats.rgba_pre(0, 0.4, 0, 0.5), interpolator); } break; case 32: { ImageBufferAccessorClip source = new ImageBufferAccessorClip(sourceImage, RGBA_Floats.rgba_pre(0, 0, 0, 0).GetAsRGBA_Bytes()); sg = new span_image_filter_rgba_bilinear_clip(source, RGBA_Floats.rgba_pre(0, 0.4, 0, 0.5), interpolator); } break; default: throw new Exception("Bad sourc depth"); } ScanlineRasterizer ras = new ScanlineRasterizer(); ras.SetVectorClipBox(0, 0, Width, Height); ScanlineCachePacked8 sl = new ScanlineCachePacked8(); //scanline_unpacked_8 sl = new scanline_unpacked_8(); double r = orignialSize.x; if (orignialSize.y - 60 < r) { r = orignialSize.y - 60; } VertexSource.Ellipse ell = new VertexSource.Ellipse(orignialSize.x / 2.0 + 10, orignialSize.y / 2.0 + 20 + 10, r / 2.0 + 16.0, r / 2.0 + 16.0, 200); VertexSourceApplyTransform tr = new VertexSourceApplyTransform(ell, src_mtx); ras.add_path(tr); //clippingProxy_pre.SetClippingBox(30, 0, (int)width(), (int)height()); ScanlineRenderer scanlineRenderer = new ScanlineRenderer(); scanlineRenderer.GenerateAndRender(ras, sl, clippingProxy_pre, sa, sg); base.OnDraw(graphics2D); }
public override void Render(Graphics2D graphics2D, Affine transform, double layerScale, RenderType renderType) { if ((renderType & RenderType.Moves) == RenderType.Moves) { double movementLineWidth = 0.35 * layerScale; RGBA_Bytes movementColor = new RGBA_Bytes(10, 190, 15); PathStorage pathStorage = new PathStorage(); VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, transform); Stroke stroke = new Stroke(transformedPathStorage, movementLineWidth); stroke.line_cap(LineCap.Round); stroke.line_join(LineJoin.Round); pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.CommandMoveTo); if (end.x != start.x || end.y != start.y) { pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo); } else { pathStorage.Add(end.x + .01, end.y, ShapePath.FlagsAndCommand.CommandLineTo); } graphics2D.Render(stroke, 0, movementColor); } }
public override void Render(Graphics2D graphics2D, Affine transform, double layerScale, RenderType renderType) { if ((renderType & RenderType.Extrusions) == RenderType.Extrusions) { double extrusionLineWidths = 0.2 * layerScale; RGBA_Bytes extrusionColor = RGBA_Bytes.Black; //extrusionColor = color; PathStorage pathStorage = new PathStorage(); VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, transform); Stroke stroke = new Stroke(transformedPathStorage, extrusionLineWidths); stroke.line_cap(LineCap.Round); stroke.line_join(LineJoin.Round); pathStorage.Add(start.x, start.y, ShapePath.FlagsAndCommand.CommandMoveTo); pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.CommandLineTo); graphics2D.Render(stroke, 0, extrusionColor); } }
//路径 public static CCSprite CreatePath( double width, double height, string[] paths, double contentX, double contentY, double contentWidth, double contentHeight, CCColor4B fill, CCColor4B stroke, double strokeThickness = 1, UIGraphic.Stretch stretch = UIGraphic.Stretch.StretchNone ) { if (width == 0) width = contentWidth; if (height == 0) height = contentHeight; ImageBuffer buffer = new ImageBuffer((int)width, (int)height, 32, new BlenderRGBA()); Graphics2D g = buffer.NewGraphics2D(); double scalex = 0; double scaley = 0; //if (stretch == Stretch.StretchNone) { } else if (stretch == UIGraphic.Stretch.StretchFill) { if (width != contentWidth || height != contentHeight) { scalex = width / contentWidth; scaley = height / contentHeight; } } else if (stretch == UIGraphic.Stretch.StretchUniformToFill) { scalex = scaley = Math.Min(width / contentWidth, height / contentHeight); } foreach (string path in paths) { IVertexSource vertexs = MiniLanguage.CreatePathStorage(path); if (contentX != 0 || contentY != 0) vertexs = new VertexSourceApplyTransform(vertexs, Affine.NewTranslation(-contentX, -contentY)); if (scalex != 0 || scaley != 0) vertexs = new VertexSourceApplyTransform(vertexs, Affine.NewScaling(scalex, scaley)); if (fill.A > 0) g.Render(vertexs, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A)); if (stroke.A > 0) g.Render(new Stroke(vertexs, strokeThickness), 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); }
public override void OnDraw(Graphics2D graphics2D) { ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect()); ScanlineRasterizer ras = new ScanlineRasterizer(); scanline_unpacked_8 sl = new scanline_unpacked_8(); ImageClippingProxy clippingProxy = new ImageClippingProxy(widgetsSubImage); clippingProxy.clear(new RGBA_Floats(0, 0, 0)); m_profile.text_size(8.0); // draw a background to show how the alpha is working int RectWidth = 32; int xoffset = 238; int yoffset = 171; ScanlineRenderer scanlineRenderer = new ScanlineRenderer(); for (int i = 0; i < 7; i++) { for (int j = 0; j < 7; j++) { if ((i + j) % 2 != 0) { VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * RectWidth + xoffset, j * RectWidth + yoffset, (i + 1) * RectWidth + xoffset, (j + 1) * RectWidth + yoffset, 2); rect.normalize_radius(); ras.add_path(rect); scanlineRenderer.RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(.9, .9, .9)); } } } double ini_scale = 1.0; Transform.Affine mtx1 = Affine.NewIdentity(); mtx1 *= Affine.NewScaling(ini_scale, ini_scale); mtx1 *= Affine.NewTranslation(center_x, center_y); VertexSource.Ellipse e1 = new MatterHackers.Agg.VertexSource.Ellipse(); e1.init(0.0, 0.0, 110.0, 110.0, 64); Transform.Affine mtx_g1 = Affine.NewIdentity(); mtx_g1 *= Affine.NewScaling(ini_scale, ini_scale); mtx_g1 *= Affine.NewScaling(m_SaveData.m_scale, m_SaveData.m_scale); mtx_g1 *= Affine.NewScaling(m_scale_x, m_scale_y); mtx_g1 *= Affine.NewRotation(m_SaveData.m_angle); mtx_g1 *= Affine.NewTranslation(m_SaveData.m_center_x, m_SaveData.m_center_y); mtx_g1.invert(); RGBA_Bytes[] color_profile = new RGBA_Bytes[256]; // color_type is defined in pixel_formats.h for (int i = 0; i < 256; i++) { color_profile[i] = new RGBA_Bytes(m_spline_r.spline()[i], m_spline_g.spline()[i], m_spline_b.spline()[i], m_spline_a.spline()[i]); } VertexSourceApplyTransform t1 = new VertexSourceApplyTransform(e1, mtx1); IGradient innerGradient = null; switch (m_GradTypeRBox.SelectedIndex) { case 0: innerGradient = new gradient_radial(); break; case 1: innerGradient = new gradient_diamond(); break; case 2: innerGradient = new gradient_x(); break; case 3: innerGradient = new gradient_xy(); break; case 4: innerGradient = new gradient_sqrt_xy(); break; case 5: innerGradient = new gradient_conic(); break; } IGradient outerGradient = null; switch (m_GradWrapRBox.SelectedIndex) { case 0: outerGradient = new gradient_reflect_adaptor(innerGradient); break; case 1: outerGradient = new gradient_repeat_adaptor(innerGradient); break; case 2: outerGradient = new gradient_clamp_adaptor(innerGradient); break; } span_allocator span_alloc = new span_allocator(); color_function_profile colors = new color_function_profile(color_profile, m_profile.gamma()); span_interpolator_linear inter = new span_interpolator_linear(mtx_g1); span_gradient span_gen = new span_gradient(inter, outerGradient, colors, 0, 150); ras.add_path(t1); scanlineRenderer.GenerateAndRender(ras, sl, clippingProxy, span_alloc, span_gen); base.OnDraw(graphics2D); }
public static CCSprite CreateText(string text, CCColor4B fill, CCColor4B stroke, TypeFace font, double emSizeInPoints, bool underline = false, bool flatenCurves = true, double strokeThickness = 1) { TypeFacePrinter printer = new TypeFacePrinter(text, new StyledTypeFace(font, emSizeInPoints, underline, flatenCurves)); double width = printer.LocalBounds.Width; double height = printer.LocalBounds.Height; RectangleDouble rect = new RectangleDouble(); bounding_rect.bounding_rect_single(printer, 0, ref rect); VertexSourceApplyTransform path = new VertexSourceApplyTransform(printer, Affine.NewTranslation(-rect.Left, -rect.Bottom)); ImageBuffer buffer = new ImageBuffer((int)width, (int)height, 32, new BlenderRGBA()); Graphics2D g = buffer.NewGraphics2D(); if (fill.A > 0) g.Render(path, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A)); if (stroke.A > 0) g.Render(new Stroke(path, strokeThickness), 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); }
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"); } }
public override void OnDraw(Graphics2D graphics2D) { ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect()); IImageByte backBuffer = widgetsSubImage; if (!didInit) { didInit = true; OnInitialize(); } ImageBuffer image; if (backBuffer.BitDepth == 32) { image = new ImageBuffer(); image.Attach(backBuffer, new BlenderBGRA()); } else { if (backBuffer.BitDepth != 24) { throw new System.NotSupportedException(); } image = new ImageBuffer(); image.Attach(backBuffer, new BlenderBGR()); } ImageClippingProxy clippingProxy = new ImageClippingProxy(image); clippingProxy.clear(new RGBA_Floats(1, 1, 1)); g_rasterizer.SetVectorClipBox(0, 0, Width, Height); ScanlineRenderer scanlineRenderer = new ScanlineRenderer(); if (transformationTypeRadioButton.SelectedIndex == 0) { Bilinear tr = new Bilinear(lionShape.Bounds.Left, lionShape.Bounds.Bottom, lionShape.Bounds.Right, lionShape.Bounds.Top, quadPolygonControl.polygon()); if (tr.is_valid()) { //-------------------------- // Render transformed lion // VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, tr); scanlineRenderer.RenderSolidAllPaths(clippingProxy, g_rasterizer, g_scanline, trans, lionShape.Colors, lionShape.PathIndex, lionShape.NumPaths); //-------------------------- //-------------------------- // Render transformed ellipse // VertexSource.Ellipse ell = new MatterHackers.Agg.VertexSource.Ellipse((lionShape.Bounds.Left + lionShape.Bounds.Right) * 0.5, (lionShape.Bounds.Bottom + lionShape.Bounds.Top) * 0.5, (lionShape.Bounds.Right - lionShape.Bounds.Left) * 0.5, (lionShape.Bounds.Top - lionShape.Bounds.Bottom) * 0.5, 200); Stroke ell_stroke = new Stroke(ell); ell_stroke.width(3.0); VertexSourceApplyTransform trans_ell = new VertexSourceApplyTransform(ell, tr); VertexSourceApplyTransform trans_ell_stroke = new VertexSourceApplyTransform(ell_stroke, tr); g_rasterizer.add_path(trans_ell); scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.5, 0.3, 0.0, 0.3)); g_rasterizer.add_path(trans_ell_stroke); scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.0, 0.3, 0.2, 1.0)); } } else { Perspective tr = new Perspective(lionShape.Bounds.Left, lionShape.Bounds.Bottom, lionShape.Bounds.Right, lionShape.Bounds.Top, quadPolygonControl.polygon()); if (tr.is_valid()) { // Render transformed lion VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, tr); scanlineRenderer.RenderSolidAllPaths(clippingProxy, g_rasterizer, g_scanline, trans, lionShape.Colors, lionShape.PathIndex, lionShape.NumPaths); // Render transformed ellipse VertexSource.Ellipse FilledEllipse = new MatterHackers.Agg.VertexSource.Ellipse((lionShape.Bounds.Left + lionShape.Bounds.Right) * 0.5, (lionShape.Bounds.Bottom + lionShape.Bounds.Top) * 0.5, (lionShape.Bounds.Right - lionShape.Bounds.Left) * 0.5, (lionShape.Bounds.Top - lionShape.Bounds.Bottom) * 0.5, 200); Stroke EllipseOutline = new Stroke(FilledEllipse); EllipseOutline.width(3.0); VertexSourceApplyTransform TransformedFilledEllipse = new VertexSourceApplyTransform(FilledEllipse, tr); VertexSourceApplyTransform TransformedEllipesOutline = new VertexSourceApplyTransform(EllipseOutline, tr); g_rasterizer.add_path(TransformedFilledEllipse); scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.5, 0.3, 0.0, 0.3)); g_rasterizer.add_path(TransformedEllipesOutline); scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.0, 0.3, 0.2, 1.0)); } } //-------------------------- // Render the "quad" tool and controls g_rasterizer.add_path(quadPolygonControl); scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0, 0.3, 0.5, 0.6)); //m_trans_type.Render(g_rasterizer, g_scanline, clippingProxy); base.OnDraw(graphics2D); }