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 void TextWidgetVisibleTest() { GuiWidget rectangleWidget = new GuiWidget(100, 50); TextEditWidget itemToAdd = new TextEditWidget("test Item", 10, 10); rectangleWidget.AddChild(itemToAdd); rectangleWidget.DoubleBuffer = true; rectangleWidget.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White); rectangleWidget.OnDraw(rectangleWidget.BackBuffer.NewGraphics2D()); ImageBuffer textOnly = new ImageBuffer(75, 20, 32, new BlenderBGRA()); textOnly.NewGraphics2D().Clear(RGBA_Bytes.White); #if true TypeFacePrinter stringPrinter = new TypeFacePrinter("test Item", 12); IVertexSource offsetText = new VertexSourceApplyTransform(stringPrinter, Affine.NewTranslation(1, -stringPrinter.LocalBounds.Bottom)); textOnly.NewGraphics2D().Render(offsetText, RGBA_Bytes.Black); #else textOnly.NewGraphics2D().DrawString("test Item", 1, 1); #endif if (saveImagesForDebug) { ImageTgaIO.Save(rectangleWidget.BackBuffer, "-rectangleWidget.tga"); //ImageTgaIO.Save(itemToAdd.Children[0].BackBuffer, "-internalTextWidget.tga"); ImageTgaIO.Save(textOnly, "-textOnly.tga"); } Assert.IsTrue(rectangleWidget.BackBuffer.FindLeastSquaresMatch(textOnly, 1), "TextWidgets need to be drawing."); rectangleWidget.Close(); }
public override void OnDraw(Graphics2D graphics2D) { byte alpha = (byte)(alphaSlider.Value * 255); foreach (var shape in lionShape.Shapes) { shape.Color = new Color(shape.Color, 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: foreach (var shape in lionShape.Shapes) { VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(shape.VertexStorage, transform); graphics2D.Render(transformedPathStorage, shape.Color); } graphics2D.DrawString("test", 40, 40, 50); base.OnDraw(graphics2D); }
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); graphics2D.DrawString("test", 40, 40, 50); base.OnDraw(graphics2D); }
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 static void DrawMeasureLine(this Graphics2D graphics2D, Vector2 lineStart, Vector2 lineEnd, LineArrows arrows, ThemeConfig theme) { graphics2D.Line(lineStart, lineEnd, theme.TextColor); Vector2 direction = lineEnd - lineStart; if (direction.LengthSquared > 0 && (arrows.HasFlag(LineArrows.Start) || arrows.HasFlag(LineArrows.End))) { var arrow = new VertexStorage(); arrow.MoveTo(-3, -5); arrow.LineTo(0, 0); arrow.LineTo(3, -5); if (arrows.HasFlag(LineArrows.End)) { 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(lineEnd)); graphics2D.Render(inPosition, theme.TextColor); } if (arrows.HasFlag(LineArrows.Start)) { double rotation = Math.Atan2(direction.Y, direction.X) + MathHelper.Tau / 2; IVertexSource correctRotation = new VertexSourceApplyTransform(arrow, Affine.NewRotation(rotation - MathHelper.Tau / 4)); IVertexSource inPosition = new VertexSourceApplyTransform(correctRotation, Affine.NewTranslation(lineStart)); graphics2D.Render(inPosition, theme.TextColor); } } }
void Update() { // update animation counter x += Time.deltaTime; while (x > 1.0f) { x -= 1.0f; } // clear background with white Graphics2D g = buffer.NewGraphics2D(); g.Clear(RGBA_Bytes.White); // draw some lines float w = buffer.Width * x; for (int i = 0; i < 10; i++) { g.Line(x1: 0, y1: buffer.Height * i / 10, x2: w - w * i / 10, y2: 0, color: RGBA_Bytes.Black, strokeWidth: 3); } // draw some text TypeFacePrinter textPrinter = new TypeFacePrinter("Hello World!", 30, justification: Justification.Center); IVertexSource translatedText = new VertexSourceApplyTransform(textPrinter, Affine.NewTranslation(buffer.Width / 2, 5)); g.Render(translatedText, RGBA_Bytes.Blue); // update texture data byte[] pixels = buffer.GetBuffer(); texture.LoadRawTextureData(pixels); texture.Apply(); }
private void _InternalRender(IVertexSource vertexSource, RGBA_Bytes color) { if (_clipBuffer != null) { // DEBUG_saveImageBuffer(_clipBuffer); // DEBUG_saveImageBuffer(this.imb); IAlphaMask alphaMask = new AlphaMaskByteClipped(_clipBuffer, 1, 0); AlphaMaskAdaptor imageAlphaMaskAdaptor = new AlphaMaskAdaptor(aggGc.DestImage, alphaMask); ImageClippingProxy alphaMaskClippingProxy = new ImageClippingProxy(imageAlphaMaskAdaptor); var scanlineRenderer = new ScanlineRenderer(); var rasterizer = new ScanlineRasterizer(); var scanlineCache = new ScanlineCachePacked8(); VertexSourceApplyTransform trans = new VertexSourceApplyTransform(vertexSource, aggGc.GetTransform()); rasterizer.add_path(trans); scanlineRenderer.render_scanlines_aa_solid(alphaMaskClippingProxy, rasterizer, scanlineCache, color); aggGc.DestImage.MarkImageChanged(); } else { aggGc.Render(vertexSource, color); } }
public DockingTabButton(string tabTitle, ThemeConfig theme) { this.grayBorder = theme.GetBorderColor(theme.IsDarkTheme ? 45 : 55); this.theme = theme; this.HAnchor = HAnchor.Fit; this.VAnchor = VAnchor.Fit | VAnchor.Center; this.AlignToRightEdge = true; this.MakeScrollable = false; this.Border = new BorderDouble(right: 6); this.BorderColor = grayBorder; this.Margin = new BorderDouble(2, 8, 0, 0); this.HoverColor = Color.Transparent; var printer = new TypeFacePrinter(tabTitle, theme.DefaultFontSize * GuiWidget.DeviceScale); var rotatedLabel = new VertexSourceApplyTransform( printer, Affine.NewRotation(MathHelper.DegreesToRadians(-90))); var textBounds = rotatedLabel.GetBounds(); var bounds = new RectangleDouble(printer.TypeFaceStyle.DescentInPixels, textBounds.Bottom, printer.TypeFaceStyle.AscentInPixels, textBounds.Top); rotatedLabel.Transform = ((Affine)rotatedLabel.Transform) * Affine.NewTranslation(new Vector2(-printer.TypeFaceStyle.DescentInPixels, -bounds.Bottom)); this.AddChild(buttonView = new GuiWidget(bounds.Width, bounds.Height) { DoubleBuffer = true, Margin = new BorderDouble(3, 1), Selectable = false }); buttonView.AfterDraw += (s, e) => { e.Graphics2D.Render(rotatedLabel, theme.TextColor); }; }
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); } } } }
private void DrawSnappingMarks(DrawGlContentEventArgs drawEventArgs, double mouseAngle, double alphaValue, Matrix4X4 rotationCenterTransform, double distanceFromCenter, int numSnapPoints, int markToSnapTo) { var graphics2DOpenGL = new Graphics2DOpenGL(GuiWidget.DeviceScale); double snappingRadians = MathHelper.Tau / numSnapPoints; for (int i = 0; i < numSnapPoints; i++) { double startAngle = i * snappingRadians + mouseAngle; var snapShape = new VertexStorage(); var scale = GuiWidget.DeviceScale; snapShape.MoveTo(-10 * scale, 0); snapShape.LineTo(5 * scale, 7 * scale); snapShape.LineTo(5 * scale, -7 * scale); snapShape.ClosePolygon(); var transformed = new VertexSourceApplyTransform(snapShape, Affine.NewTranslation(distanceFromCenter, 0) * Affine.NewRotation(startAngle)); // new Ellipse(startPosition.x, startPosition.y, dotRadius, dotRadius); var color = theme.TextColor; if (i == markToSnapTo) { color = theme.PrimaryAccentColor; } graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, transformed, new Color(color, (int)(254 * alphaValue)), drawEventArgs.ZBuffered); } }
public void GenerateBase(Polygons polygonShape, double bottomWithoutBase) { if (polygonShape != null && polygonShape.Select(p => p.Count).Sum() > 3) { Polygons polysToOffset = new Polygons(); switch (BaseType) { case BaseTypes.Rectangle: polysToOffset.Add(GetBoundingPolygon(polygonShape)); break; case BaseTypes.Circle: polysToOffset.Add(GetBoundingCircle(polygonShape)); break; case BaseTypes.Outline: PolyTree polyTreeForBase = GetPolyTree(polygonShape); foreach (PolyNode polyToOffset in polyTreeForBase.Childs) { polysToOffset.Add(polyToOffset.Contour); } break; } if (polysToOffset.Count > 0) { Polygons basePolygons; if (BaseType == BaseTypes.Outline && InfillAmount > 0) { basePolygons = Offset(polysToOffset, (BaseSize + InfillAmount) * scalingForClipper); basePolygons = Offset(basePolygons, -InfillAmount * scalingForClipper); } else { basePolygons = Offset(polysToOffset, BaseSize * scalingForClipper); } basePolygons = ClipperLib.Clipper.CleanPolygons(basePolygons, 10); VertexStorage rawVectorShape = basePolygons.PolygonToPathStorage(); var vectorShape = new VertexSourceApplyTransform(rawVectorShape, Affine.NewScaling(1.0 / scalingForClipper)); var baseObject = new Object3D() { Mesh = VertexSourceToMesh.Extrude(vectorShape, zHeight: ExtrusionHeight) }; Children.Add(baseObject); baseObject.Mesh.Translate(new Vector3(0, 0, -ExtrusionHeight + bottomWithoutBase)); } else { // clear the mesh Mesh = null; } } }
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 Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo) { if ((renderInfo.CurrentRenderType & RenderType.Extrusions) == RenderType.Extrusions) { double extrusionLineWidths = GetRadius(renderInfo.CurrentRenderType) * 2 * renderInfo.LayerScale; RGBA_Bytes extrusionColor = RGBA_Bytes.Black; if (extruderIndex > 0) { extrusionColor = MeshViewerWidget.GetMaterialColor(extruderIndex + 1); } if ((renderInfo.CurrentRenderType & RenderType.SpeedColors) == RenderType.SpeedColors) { extrusionColor = color; } PathStorage pathStorage = new PathStorage(); VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform); Stroke stroke = new Stroke(transformedPathStorage, extrusionLineWidths); 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 static void DrawMeasureLine(Graphics2D graphics2D, Vector2 lineStart, Vector2 lineEnd, RGBA_Bytes color, LineArrows arrows) { graphics2D.Line(lineStart, lineEnd, RGBA_Bytes.Black); Vector2 direction = lineEnd - lineStart; if (direction.LengthSquared > 0 && (arrows.HasFlag(LineArrows.Start) || arrows.HasFlag(LineArrows.End))) { PathStorage arrow = new PathStorage(); arrow.MoveTo(-3, -5); arrow.LineTo(0, 0); arrow.LineTo(3, -5); if (arrows.HasFlag(LineArrows.End)) { 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(lineEnd)); graphics2D.Render(inPosition, RGBA_Bytes.Black); } if (arrows.HasFlag(LineArrows.Start)) { double rotation = Math.Atan2(direction.y, direction.x) + MathHelper.Tau / 2; IVertexSource correctRotation = new VertexSourceApplyTransform(arrow, Affine.NewRotation(rotation - MathHelper.Tau / 4)); IVertexSource inPosition = new VertexSourceApplyTransform(correctRotation, Affine.NewTranslation(lineStart)); graphics2D.Render(inPosition, RGBA_Bytes.Black); } } }
private static Affine GetCenteringTransformVisualCenter(IVertexSource vertexSource, double goalRadius) { var outsidePolygons = new List <List <IntPoint> >(); // remove all holes from the polygons so we only center the major outlines var polygons = vertexSource.CreatePolygons(); foreach (var polygon in polygons) { if (polygon.GetWindingDirection() == 1) { outsidePolygons.Add(polygon); } } IVertexSource outsideSource = outsidePolygons.CreateVertexStorage(); Vector2 center = outsideSource.GetWeightedCenter(); outsideSource = new VertexSourceApplyTransform(outsideSource, Affine.NewTranslation(-center)); double radius = MaxXyDistFromCenter(outsideSource); double scale = goalRadius / radius; var scalling = Affine.NewScaling(scale); var centering = Affine.NewTranslation(-center); return(centering * scalling); }
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); }
private void DrawSnappingMarks(DrawGlContentEventArgs drawEventArgs, double mouseAngle, double alphaValue, Matrix4X4 rotationCenterTransform, double distanceFromCenter, double dotRadius, int numSnapPoints, int markToSnapTo) { var graphics2DOpenGL = new Graphics2DOpenGL(); double snappingRadians = MathHelper.Tau / numSnapPoints; var clippingFrustum = GLHelper.GetClippingFrustum(InteractionContext.World); for (int i = 0; i < numSnapPoints; i++) { double startAngle = i * snappingRadians + mouseAngle; VertexStorage snapShape = new VertexStorage(); snapShape.MoveTo(-10, 0); snapShape.LineTo(5, 7); snapShape.LineTo(5, -7); snapShape.ClosePolygon(); var transformed = new VertexSourceApplyTransform(snapShape, Affine.NewTranslation(distanceFromCenter, 0) * Affine.NewRotation(startAngle)); // new Ellipse(startPosition.x, startPosition.y, dotRadius, dotRadius); var color = Color.Black; if (i == markToSnapTo) { color = Color.Red; } graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, transformed, new Color(color, (int)(254 * alphaValue)), drawEventArgs.ZBuffered); } }
public override void OnDraw(Graphics2D graphics2D) { ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect()); int width = (int)widgetsSubImage.Width; int height = (int)widgetsSubImage.Height; ImageBuffer clippedSubImage = new ImageBuffer(); clippedSubImage.Attach(widgetsSubImage, new BlenderBGRA()); ImageClippingProxy imageClippingProxy = new ImageClippingProxy(clippedSubImage); imageClippingProxy.clear(new ColorF(1, 1, 1)); 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); if (renderAsScanlineCheckBox.Checked) { rasterizer.SetVectorClipBox(0, 0, width, height); foreach (var shape in lionShape.Shapes) { Stroke stroke = new Stroke(shape.VertexStorage); stroke.Width = widthSlider.Value; stroke.LineJoin = LineJoin.Round; VertexSourceApplyTransform trans = new VertexSourceApplyTransform(stroke, transform); ScanlineRenderer scanlineRenderer = new ScanlineRenderer(); rasterizer.add_path(trans); scanlineRenderer.RenderSolid(imageClippingProxy, rasterizer, scanlineCache, shape.Color); } } else { double w = widthSlider.Value * transform.GetScale(); LineProfileAnitAlias lineProfile = new LineProfileAnitAlias(w, new gamma_none()); OutlineRenderer outlineRenderer = new OutlineRenderer(imageClippingProxy, lineProfile); rasterizer_outline_aa rasterizer = new rasterizer_outline_aa(outlineRenderer); rasterizer.line_join(renderAccurateJoinsCheckBox.Checked ? rasterizer_outline_aa.outline_aa_join_e.outline_miter_accurate_join : rasterizer_outline_aa.outline_aa_join_e.outline_round_join); rasterizer.round_cap(true); foreach (var shape in lionShape.Shapes) { VertexSourceApplyTransform trans = new VertexSourceApplyTransform(shape.VertexStorage, transform); rasterizer.RenderAllPaths(trans, new Color[] { shape.Color }, new int[] { 0 }, 1); } } base.OnDraw(graphics2D); }
public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo) { if (renderInfo.CurrentRenderType.HasFlag(RenderType.Extrusions)) { double extrusionLineWidths = GetExtrusionWidth(renderInfo.CurrentRenderType) * 2 * renderInfo.LayerScale; Color extrusionColor = Color.Black; if (renderInfo.CurrentRenderType.HasFlag(RenderType.SpeedColors)) { extrusionColor = color; } else if (renderInfo.CurrentRenderType.HasFlag(RenderType.GrayColors)) { extrusionColor = Color.Gray; } else { extrusionColor = renderInfo.GetMaterialColor(extruderIndex); } if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion)) { extrusionColor = new Color(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 { VertexStorage pathStorage = new VertexStorage(); 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.MoveTo); pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.LineTo); graphics2D.Render(stroke, 0, extrusionColor); } } }
public override Task Rebuild() { this.DebugDepth("Rebuild"); var rebuildLock = RebuildLock(); return(Task.Run(() => { using (new CenterAndHeightMaintainer(this)) { bool valuesChanged = false; var height = Height.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged); var nameToWrite = NameToWrite.Value(this); if (string.IsNullOrWhiteSpace(nameToWrite)) { Mesh = PlatonicSolids.CreateCube(20, 10, height); } else { Mesh = null; this.Children.Modify(list => { list.Clear(); var offest = 0.0; double pointsToMm = 0.352778; foreach (var letter in nameToWrite.ToCharArray()) { var style = new StyledTypeFace(ApplicationController.GetTypeFace(this.Font), PointSize.Value(this)); var letterPrinter = new TypeFacePrinter(letter.ToString(), style) { ResolutionScale = 10 }; var scaledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm)); list.Add(new Object3D() { Mesh = VertexSourceToMesh.Extrude(scaledLetterPrinter, this.Height.Value(this)), Matrix = Matrix4X4.CreateTranslation(offest, 0, 0), Name = letter.ToString() }); offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm; } }); } } UiThread.RunOnIdle(() => { rebuildLock.Dispose(); Invalidate(InvalidateType.DisplayValues); Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); }); })); }
private Matrix4X4 GetCenteringTransformVisualCenter(IEnumerable <IObject3D> items, double goalRadius) { IEnumerable <(Vector2, Vector2, Vector2)> GetPolygons() { foreach (var item in items) { foreach (var meshItem in item.VisibleMeshes()) { var worldMatrix = meshItem.WorldMatrix(this); var faces = meshItem.Mesh.Faces; var vertices = meshItem.Mesh.Vertices; foreach (var face in faces) { if (face.normal.TransformNormal(worldMatrix).Z > 0) { yield return( new Vector2(vertices[face.v0].Transform(worldMatrix)), new Vector2(vertices[face.v1].Transform(worldMatrix)), new Vector2(vertices[face.v2].Transform(worldMatrix)) ); } } } } } var outsidePolygons = new List <List <IntPoint> >(); var projection = new Polygons(); // remove all holes from the polygons so we only center the major outlines var polygons = OrthographicZProjection.GetClipperPolygons(GetPolygons()); foreach (var polygon in polygons) { if (polygon.GetWindingDirection() == 1) { outsidePolygons.Add(polygon); } } IVertexSource outsideSource = outsidePolygons.CreateVertexStorage(); Vector2 center = outsideSource.GetWeightedCenter(); outsideSource = new VertexSourceApplyTransform(outsideSource, Affine.NewTranslation(-center)); double radius = MaxXyDistFromCenter(outsideSource); double scale = goalRadius / radius; var scalling = Matrix4X4.CreateScale(scale, scale, 1); var centering = Matrix4X4.CreateTranslation(-center.X, -center.Y, 0); return(centering * scalling); }
protected override void DoDraw(Graphics2D destRenderer) { Affine Final = Affine.NewIdentity(); Final *= Affine.NewRotation(m_Rotation); Final *= Affine.NewTranslation(m_Position.X, m_Position.Y); var TransformedShip = new VertexSourceApplyTransform(ellipseShape, Final); destRenderer.Render(TransformedShip, new Color(.9, .4, .2, 1)); }
public override Task Rebuild() { this.DebugDepth("Rebuild"); var rebuildLock = RebuildLock(); return(ApplicationController.Instance.Tasks.Execute( "Generating Text Meshes".Localize(), null, (reporter, cancellationToken) => { using (new CenterAndHeightMaintainer(this)) { if (string.IsNullOrWhiteSpace(NameToWrite)) { Mesh = PlatonicSolids.CreateCube(20, 10, Height); } else { Mesh = null; this.Children.Modify(list => { list.Clear(); var offest = 0.0; double pointsToMm = 0.352778; foreach (var letter in this.NameToWrite.ToCharArray()) { var letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(ApplicationController.GetTypeFace(this.Font), this.PointSize)) { ResolutionScale = 10 }; var scaledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm)); list.Add(new Object3D() { Mesh = VertexSourceToMesh.Extrude(scaledLetterPrinter, this.Height), Matrix = Matrix4X4.CreateTranslation(offest, 0, 0), Name = letter.ToString() }); offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm; } }); } } rebuildLock.Dispose(); Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children)); return Task.CompletedTask; })); }
public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo, bool highlightFeature = false) { if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves) { double movementLineWidth = 0.2 * renderInfo.LayerScale; Color movementColor = (highlightFeature) ? RenderFeatureBase.HighlightColor : new Color(10, 190, 15); if (graphics2D is Graphics2DOpenGL graphics2DGl) { // render using opengl var startPoint = new Vector2(start.X, start.Y); renderInfo.Transform.transform(ref startPoint); var endPoint = new Vector2(end.X, end.Y); renderInfo.Transform.transform(ref endPoint); if (retractionTravel) { movementColor = GCodeRenderer.RetractionColor; } if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion)) { movementColor = movementColor.WithAlpha(120); } graphics2DGl.DrawAALineRounded(startPoint, endPoint, movementLineWidth, movementColor); } else { // render using agg var pathStorage = new VertexStorage(); var transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform); var stroke = new Stroke(transformedPathStorage, movementLineWidth) { LineCap = LineCap.Round, LineJoin = LineJoin.Round }; pathStorage.Add(start.X, start.Y, ShapePath.FlagsAndCommand.MoveTo); if (end.X != start.X || end.Y != start.Y) { pathStorage.Add(end.X, end.Y, ShapePath.FlagsAndCommand.LineTo); } else { pathStorage.Add(end.X + .01, end.Y, ShapePath.FlagsAndCommand.LineTo); } graphics2D.Render(stroke, movementColor); } } }
public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo) { if ((renderInfo.CurrentRenderType & RenderType.Moves) == RenderType.Moves) { double movementLineWidth = 0.35 * renderInfo.LayerScale; Color movementColor = new Color(10, 190, 15); // 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); if (renderInfo.CurrentRenderType.HasFlag(RenderType.TransparentExtrusion)) { movementColor = new Color(movementColor, 200); } graphics2DGl.DrawAALineRounded(start, end, movementLineWidth, movementColor); } else { VertexStorage pathStorage = new VertexStorage(); 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.MoveTo); if (end.x != start.x || end.y != start.y) { pathStorage.Add(end.x, end.y, ShapePath.FlagsAndCommand.LineTo); } else { pathStorage.Add(end.x + .01, end.y, ShapePath.FlagsAndCommand.LineTo); } graphics2D.Render(stroke, movementColor); } } }
private void DrawImage(ISpanGenerator spanImageFilter, Affine destRectTransform) { if (destImageByte.OriginOffset.X != 0 || destImageByte.OriginOffset.Y != 0) { destRectTransform *= Affine.NewTranslation(-destImageByte.OriginOffset.X, -destImageByte.OriginOffset.Y); } var transformedRect = new VertexSourceApplyTransform(drawImageRectPath, destRectTransform); Rasterizer.add_path(transformedRect); { var destImageWithClipping = new ImageClippingProxy(destImageByte); scanlineRenderer.GenerateAndRender(Rasterizer, drawImageScanlineCache, destImageWithClipping, destImageSpanAllocatorCache, spanImageFilter); } }
public void DrawString(string text, Font font, Brush brush, float x, float y) { // TODO: handle different brushes // TODO: emulate GDI "bordering" of text? SolidBrush colorBrush = brush as SolidBrush; var s1 = new TypeFacePrinter(text, font.SizeInPoints, new MatterHackers.VectorMath.Vector2(0, 0), Justification.Left, Baseline.BoundsTop); var s2 = new VertexSourceApplyTransform(s1, Affine.NewScaling(1, -1)); if (x != 0.0f || y != 0.0f) { s2 = new VertexSourceApplyTransform(s2, Affine.NewTranslation(x, y)); } _InternalRender(s2, new RGBA_Bytes((uint)colorBrush.Color.ToArgb())); }
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 void DrawString(string text, Font font, TypeFace typeFace, Brush brush, float x, float y, Justification justification = Justification.Left, Baseline baseline = Baseline.BoundsTop) { SolidBrush colorBrush = brush as SolidBrush; //var s1 = new TypeFacePrinter (text, font.SizeInPoints, new MatterHackers.VectorMath.Vector2 (0, 0), Justification.Left, Baseline.BoundsTop); var s1 = new TypeFacePrinter(text, new StyledTypeFace(typeFace, font.SizeInPoints, font.Underline), new MatterHackers.VectorMath.Vector2(0, 0), justification, baseline); var s2 = new VertexSourceApplyTransform(s1, Affine.NewScaling(1, -1)); if (x != 0.0f || y != 0.0f) { s2 = new VertexSourceApplyTransform(s2, Affine.NewTranslation(x, y)); } _InternalRender(s2, new RGBA_Bytes((uint)colorBrush.Color.ToArgb())); }