public static void AssemblyCleanup() { if (g2d != null) { g2d.Dispose (); g2d = null; } }
public override void OnDraw(Graphics2D graphics2D) { TypeFacePrinter printer = new TypeFacePrinter(); printer.DrawFromHintedCache = true; RectangleDouble Bounds = LocalBounds; double y = LocalBounds.Bottom + printer.TypeFaceStyle.EmSizeInPixels * (TOTOL_POW2 - 1) + 5; for (int index = lineCount; index < lineCount + TOTOL_POW2; index++) { if (y > LocalBounds.Top) { y -= printer.TypeFaceStyle.EmSizeInPixels; continue; } int arrayIndex = (index % TOTOL_POW2); if (lines[arrayIndex] != null) { printer.Text = lines[arrayIndex]; printer.Origin = new Vector2(Bounds.Left + 2, y); printer.Render(graphics2D, TextColor); } y -= printer.TypeFaceStyle.EmSizeInPixels; if (y < -printer.TypeFaceStyle.EmSizeInPixels) { break; } } base.OnDraw(graphics2D); }
public void Draw(Graphics2D graphics) { Fill f = GetFill(); Dimension pg = Sheet.GetSlideShow().GetPageSize(); Rectangle anchor = new Rectangle(0, 0, pg.width, pg.height); switch (f.GetFillType()) { case Fill.FILL_SOLID: Color color = f.GetForegroundColor(); graphics.SetPaint(color); graphics.Fill(anchor); break; case Fill.FILL_PICTURE: PictureData data = f.GetPictureData(); if (data is Bitmap) { BufferedImage img = null; try { img = ImageIO.Read(new MemoryStream(data.Data)); } catch (Exception e) { logger.log(POILogger.WARN, "ImageIO failed to create image. image.type: " + data.GetType()); return; } Image scaledImg = img.GetScaledInstance(anchor.width, anchor.height, Image.SCALE_SMOOTH); graphics.DrawImage(scaledImg, anchor.x, anchor.y, null); } break; default: logger.log(POILogger.WARN, "unsuported fill type: " + f.GetFillType()); break; } }
public void DoDrawBeforeChildren(Graphics2D graphics2D) { RadioButton radioButton = Parent as RadioButton; if (radioButton == null) { return; } Vector2 center = new Vector2(boxWidth / 2 + 1, boxWidth / 2 - labelTextWidget.Printer.TypeFaceStyle.DescentInPixels); // the check if (radioButton.Checked) { graphics2D.Circle(center, boxWidth / 4, radioButton.TextColor); } if (radioButton.MouseDownOnButton && radioButton.FirstWidgetUnderMouse) { // extra frame graphics2D.Render(new Stroke(new Ellipse(center, boxWidth / 2, boxWidth / 2), 2), radioButton.TextColor); } else { // the frame graphics2D.Render(new Stroke(new Ellipse(center, boxWidth / 2, boxWidth / 2)), radioButton.TextColor); } }
public override void OnDraw(Graphics2D graphics2D) { RoundedRect rect = new RoundedRect(LocalBounds, 0); //RoundedRect rect = new RoundedRect(LocalBounds, 0); graphics2D.Render(rect, ThumbColor); base.OnDraw(graphics2D); }
public override void OnDraw(Graphics2D graphics2D) { CheckBox checkBox = (CheckBox)Parent; double bottom = 0; // the check if (checkBox.Checked) { graphics2D.Line(new Vector2(1, CheckBoxWidth + bottom), new Vector2(1 + CheckBoxWidth, 0 + bottom), this.TextColor); graphics2D.Line(new Vector2(1, 0 + bottom), new Vector2(1 + CheckBoxWidth, CheckBoxWidth + bottom), this.TextColor); } // the frame RectangleDouble clampedRect = new RectangleDouble(1, Math.Floor(0 + bottom), 1 + Math.Ceiling(CheckBoxWidth), Math.Ceiling(CheckBoxWidth + bottom)); graphics2D.Rectangle(clampedRect, this.TextColor); // extra frame if (checkBox.MouseDownOnButton && checkBox.FirstWidgetUnderMouse) { clampedRect.Inflate(1); graphics2D.Rectangle(clampedRect, this.TextColor); } base.OnDraw(graphics2D); }
public override void OnDraw(Graphics2D graphics2D) { Button parentButton = (Button)Parent; RectangleDouble Bounds = LocalBounds; RoundedRect rectBorder = new RoundedRect(Bounds, BorderRadius); if (parentButton.Enabled == true) { graphics2D.Render(rectBorder, new RGBA_Bytes(0, 0, 0)); } else { graphics2D.Render(rectBorder, new RGBA_Bytes(128, 128, 128)); } RectangleDouble insideBounds = Bounds; insideBounds.Inflate(-BorderWidth); RoundedRect rectInside = new RoundedRect(insideBounds, Math.Max(BorderRadius - BorderWidth, 0)); RGBA_Bytes insideColor = new RGBA_Bytes(1.0, 1.0, 1.0); if (parentButton.FirstWidgetUnderMouse) { if (parentButton.MouseDownOnButton) { insideColor = DefaultViewFactory.DefaultBlue; } else { insideColor = DefaultViewFactory.DefaultBlue.GetAsRGBA_Floats().Blend(RGBA_Floats.White, .75).GetAsRGBA_Bytes(); } } graphics2D.Render(rectInside, insideColor); base.OnDraw(graphics2D); }
public override void OnDraw(Graphics2D graphics2D) { graphics2D.Rectangle(LocalBounds, RGBA_Bytes.Black); RoundedRect boundsRect = new RoundedRect(dragBar.BoundsRelativeToParent, 0); graphics2D.Render(boundsRect, DragBarColor); base.OnDraw(graphics2D); }
public override void OnDraw(Graphics2D graphics2D) { RoundedRect backgroundRect = new RoundedRect(LocalBounds, 4); graphics2D.Render(backgroundRect, backgroundColor.GetAsRGBA_Bytes()); graphics2D.Render(new Stroke(backgroundRect), borderColor.GetAsRGBA_Bytes()); base.OnDraw(graphics2D); }
public override void OnDraw(Graphics2D graphics2D) { switch (FlowDirection) { case UI.FlowDirection.LeftToRight: graphics2D.Line(LocalBounds.Left, LocalBounds.Bottom, LocalBounds.Right, LocalBounds.Bottom, this.BorderColor); break; case UI.FlowDirection.TopToBottom: graphics2D.Line(LocalBounds.Right, LocalBounds.Bottom, LocalBounds.Right, LocalBounds.Top, this.BorderColor); break; } base.OnDraw(graphics2D); }
public override void OnDraw(Graphics2D graphics2D) { if (image != null) { RectangleDouble screenBounds = TransformRectangleToScreenSpace(LocalBounds); double pixelAlignXAdjust = 0; double pixelAlignYAdjust = 0; if (ForcePixelAlignment) { pixelAlignXAdjust = screenBounds.Left - (int)screenBounds.Left; pixelAlignYAdjust = screenBounds.Bottom - (int)screenBounds.Bottom; } graphics2D.Render(image, -pixelAlignXAdjust, -pixelAlignYAdjust); } base.OnDraw(graphics2D); }
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); } }
public override void OnDraw(Graphics2D graphics2D) { base.OnDraw(graphics2D); this.DrawBorder(graphics2D); this.DrawDirectionalArrow(graphics2D); }
public override void OnDraw(Graphics2D graphics2D) { graphics2D.FillRectangle(0, 0, Width * currentPercent / 100, Height, completeColor); base.OnDraw(graphics2D); }
// Draws the item inside the inventory. public override void DrawSlot(Graphics2D g, Point2I position, int lightOrDark) { DrawSprite(g, position, lightOrDark); DrawAmmo(g, position, lightOrDark); g.DrawSprite(ammo[currentAmmo].Sprite, lightOrDark, position + new Point2I(8, 0)); }
public override void OnDraw(Graphics2D graphics2D) { View.DoDrawBeforeChildren(graphics2D); base.OnDraw(graphics2D); View.DoDrawAfterChildren(graphics2D); }
public override void Draw(CanvasPainter p) { if (p is GdiPlusCanvasPainter) { DrawWithWinGdi((GdiPlusCanvasPainter)p); return; } AggCanvasPainter p2 = (AggCanvasPainter)p; Graphics2D gx = p2.Graphics; var widgetsSubImage = gx.DestImage; var scline = gx.ScanlinePacked8; int width = (int)widgetsSubImage.Width; int height = (int)widgetsSubImage.Height; //change value *** if (isMaskSliderValueChanged) { generate_alpha_mask(gx.ScanlineRasToDestBitmap, gx.ScanlinePacked8, gx.ScanlineRasterizer, width, height); this.isMaskSliderValueChanged = false; } var rasterizer = gx.ScanlineRasterizer; rasterizer.SetClipBox(0, 0, width, height); //alphaMaskImageBuffer.AttachBuffer(alphaByteArray, 0, width, height, width, 8, 1); PixelFarm.Agg.Image.AlphaMaskAdaptor imageAlphaMaskAdaptor = new PixelFarm.Agg.Image.AlphaMaskAdaptor(widgetsSubImage, alphaMask); ClipProxyImage alphaMaskClippingProxy = new ClipProxyImage(imageAlphaMaskAdaptor); ClipProxyImage clippingProxy = new ClipProxyImage(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); Affine transform = Affine.NewMatix( AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y), AffinePlan.Scale(lionScale, lionScale), AffinePlan.Rotate(angle + Math.PI), AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0), AffinePlan.Translate(width / 2, height / 2)); clippingProxy.Clear(ColorRGBA.White); ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap; // draw a background to show how the mask is working better int rect_w = 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 * rect_w, j * rect_w, (i + 1) * rect_w, (j + 1) * rect_w, 0); rect.NormalizeRadius(); // Drawing as an outline rasterizer.AddPath(rect.MakeVxs()); sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, scline, ColorRGBA.Make(.9f, .9f, .9f)); } } } ////int x, y; //// Render the lion ////VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform); ////var vxlist = new System.Collections.Generic.List<VertexData>(); ////trans.DoTransform(vxlist); sclineRasToBmp.RenderSolidAllPaths(alphaMaskClippingProxy, rasterizer, scline, transform.TransformToVxs(lionShape.Path.Vxs), lionShape.Colors, lionShape.PathIndexList, 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); }
public void SavingFunction() { currentlySaving = true; countThatHaveBeenSaved = 0; // first create images for all the parts foreach (string stlFileName in stlFilesToPrint) { Mesh loadedMesh = StlProcessing.Load(stlFileName); if (loadedMesh != null) { AxisAlignedBoundingBox aabb = loadedMesh.GetAxisAlignedBoundingBox(); RectangleDouble bounds2D = new RectangleDouble(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.x, aabb.maxXYZ.y); double widthInMM = bounds2D.Width + PartMarginMM * 2; double textSpaceMM = 5; double heightMM = textSpaceMM + bounds2D.Height + PartMarginMM * 2; string partName = System.IO.Path.GetFileName(System.IO.Path.GetFileName(stlFileName)); TypeFacePrinter typeFacePrinter = new TypeFacePrinter(partName, 28, Vector2.Zero, Justification.Center, Baseline.BoundsCenter); double sizeOfNameX = typeFacePrinter.GetSize().x + PartMarginPixels * 2; Vector2 sizeOfRender = new Vector2(widthInMM * PixelPerMM, heightMM * PixelPerMM); ImageBuffer imageOfPart = new ImageBuffer((int)(Math.Max(sizeOfNameX, sizeOfRender.x)), (int)(sizeOfRender.y), 32, new BlenderBGRA()); typeFacePrinter.Origin = new Vector2(imageOfPart.Width / 2, (textSpaceMM / 2) * PixelPerMM); Graphics2D partGraphics2D = imageOfPart.NewGraphics2D(); RectangleDouble rectBounds = new RectangleDouble(0, 0, imageOfPart.Width, imageOfPart.Height); double strokeWidth = .5 * PixelPerMM; rectBounds.Inflate(-strokeWidth / 2); RoundedRect rect = new RoundedRect(rectBounds, PartMarginMM * PixelPerMM); partGraphics2D.Render(rect, RGBA_Bytes.LightGray); Stroke rectOutline = new Stroke(rect, strokeWidth); partGraphics2D.Render(rectOutline, RGBA_Bytes.DarkGray); PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, loadedMesh, new Vector2(-bounds2D.Left + PartMarginMM, -bounds2D.Bottom + textSpaceMM + PartMarginMM), PixelPerMM, RGBA_Bytes.Black); partGraphics2D.Render(typeFacePrinter, RGBA_Bytes.Black); partImagesToPrint.Add(new PartImage(imageOfPart)); } countThatHaveBeenSaved++; if (UpdateRemainingItems != null) { UpdateRemainingItems(this, new StringEventArgs(Path.GetFileName(stlFileName))); } } partImagesToPrint.Sort(BiggestToLittlestImages); PdfDocument document = new PdfDocument(); document.Info.Title = "MatterHackers Parts Sheet"; document.Info.Author = "MatterHackers Inc."; document.Info.Subject = "This is a list of the parts that are in a queue from MatterControl."; document.Info.Keywords = "MatterControl, STL, 3D Printing"; int nextPartToPrintIndex = 0; int plateNumber = 1; bool done = false; while (!done && nextPartToPrintIndex < partImagesToPrint.Count) { PdfPage pdfPage = document.AddPage(); CreateOnePage(plateNumber++, ref nextPartToPrintIndex, pdfPage); } try { // save the final document document.Save(pathAndFileToSaveTo); // Now try and open the document. This will lanch whatever PDF viewer is on the system and ask it // to show the file (at least on Windows). Process.Start(pathAndFileToSaveTo); } catch (Exception) { } OnDoneSaving(); currentlySaving = false; }
public virtual void OnDraw(Graphics2D graphics2D) { #if DEBUG && DUMP_SLOW_TIMES using (new DumpCallStackIfSlow(dumpIfLongerThanTime, "OnDraw")) #endif { DrawCount++; if (DrawBefore != null) { DrawBefore(this, new DrawEventArgs(graphics2D)); } for (int i = 0; i < Children.Count; i++) { GuiWidget child = Children[i]; if (child.Visible) { if (child.DebugShowBounds) { // draw the margin BorderDouble invertedMargin = child.Margin; invertedMargin.Left = -invertedMargin.Left; invertedMargin.Bottom = -invertedMargin.Bottom; invertedMargin.Right = -invertedMargin.Right; invertedMargin.Top = -invertedMargin.Top; DrawBorderBounds(graphics2D, child.BoundsRelativeToParent, invertedMargin, new RGBA_Bytes(RGBA_Bytes.Red, 128)); } RectangleDouble oldClippingRect = graphics2D.GetClippingRect(); graphics2D.PushTransform(); { Affine currentGraphics2DTransform = graphics2D.GetTransform(); Affine accumulatedTransform = currentGraphics2DTransform * child.ParentToChildTransform; graphics2D.SetTransform(accumulatedTransform); RectangleDouble currentScreenClipping; if (child.CurrentScreenClipping(out currentScreenClipping)) { currentScreenClipping.Left = Math.Floor(currentScreenClipping.Left); currentScreenClipping.Right = Math.Ceiling(currentScreenClipping.Right); currentScreenClipping.Bottom = Math.Floor(currentScreenClipping.Bottom); currentScreenClipping.Top = Math.Ceiling(currentScreenClipping.Top); if (currentScreenClipping.Right < currentScreenClipping.Left || currentScreenClipping.Top < currentScreenClipping.Bottom) { BreakInDebugger("Right is less than Left or Top is less than Bottom"); } graphics2D.SetClippingRect(currentScreenClipping); if (child.DoubleBuffer) { Vector2 offsetToRenderSurface = new Vector2(currentGraphics2DTransform.tx, currentGraphics2DTransform.ty); offsetToRenderSurface += child.OriginRelativeParent; double yFraction = offsetToRenderSurface.y - (int)offsetToRenderSurface.y; double xFraction = offsetToRenderSurface.x - (int)offsetToRenderSurface.x; int xOffset = (int)Math.Floor(child.LocalBounds.Left); int yOffset = (int)Math.Floor(child.LocalBounds.Bottom); if (child.isCurrentlyInvalid) { Graphics2D childBackBufferGraphics2D = child.backBuffer.NewGraphics2D(); childBackBufferGraphics2D.Clear(new RGBA_Bytes(0, 0, 0, 0)); Affine transformToBuffer = Affine.NewTranslation(-xOffset + xFraction, -yOffset + yFraction); childBackBufferGraphics2D.SetTransform(transformToBuffer); child.OnDrawBackground(childBackBufferGraphics2D); child.OnDraw(childBackBufferGraphics2D); child.backBuffer.MarkImageChanged(); child.isCurrentlyInvalid = false; } offsetToRenderSurface.x = (int)offsetToRenderSurface.x + xOffset; offsetToRenderSurface.y = (int)offsetToRenderSurface.y + yOffset; // The transform to draw the backbuffer to the graphics2D must not have a factional amount // or we will get aliasing in the image and we want our back buffer pixels to map 1:1 to the next buffer if (offsetToRenderSurface.x - (int)offsetToRenderSurface.x != 0 || offsetToRenderSurface.y - (int)offsetToRenderSurface.y != 0) { BreakInDebugger("The transform for a back buffer must be integer to avoid aliasing."); } graphics2D.SetTransform(Affine.NewTranslation(offsetToRenderSurface)); graphics2D.Render(child.backBuffer, 0, 0); } else { child.OnDrawBackground(graphics2D); child.OnDraw(graphics2D); } } } graphics2D.PopTransform(); graphics2D.SetClippingRect(oldClippingRect); } } if (DrawAfter != null) { DrawAfter(this, new DrawEventArgs(graphics2D)); } if (DebugShowBounds) { // draw the padding DrawBorderBounds(graphics2D, LocalBounds, Padding, new RGBA_Bytes(RGBA_Bytes.Cyan, 128)); // show the bounds and inside with an x graphics2D.Line(LocalBounds.Left, LocalBounds.Bottom, LocalBounds.Right, LocalBounds.Top, RGBA_Bytes.Green); graphics2D.Line(LocalBounds.Left, LocalBounds.Top, LocalBounds.Right, LocalBounds.Bottom, RGBA_Bytes.Green); graphics2D.Rectangle(LocalBounds, RGBA_Bytes.Red); } if (debugShowSize) { graphics2D.DrawString(string.Format("{4} {0}, {1} : {2}, {3}", (int)MinimumSize.x, (int)MinimumSize.y, (int)LocalBounds.Width, (int)LocalBounds.Height, Name), Width / 2, Math.Max(Height - 16, Height / 2 - 16 * graphics2D.TransformStackCount), color: RGBA_Bytes.Magenta, justification: Font.Justification.Center); } } }
public abstract void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo);
public override void OnDraw(Graphics2D graphics2D) { graphics2D.Line(Width / 2, 0, Width / 2, Height, RGBA_Bytes.Black); base.OnDraw(graphics2D); }
public override void OnDraw(Graphics2D graphics2D) { //activeView.OnDraw(graphics2D); base.OnDraw(graphics2D); }
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); }
//template<class Scanline, class Ras> public void RenderGourand(Graphics2D gx) { float alpha = this.AlphaValue; float brc = 1; #if SourceDepth24 pixfmt_alpha_blend_rgb pf = new pixfmt_alpha_blend_rgb(backBuffer, new blender_bgr()); #else #endif var destImage = gx.DestImage; //span_allocator span_alloc = new span_allocator(); CanvasPainter painter = new CanvasPainter(gx); SpanGenGouraudRGBA gouraudSpanGen = new SpanGenGouraudRGBA(); gx.ScanlineRasterizer.ResetGamma(new GammaLinear(0.0f, this.LinearGamma)); double d = this.DilationValue; // Six triangles double xc = (m_x[0] + m_x[1] + m_x[2]) / 3.0; double yc = (m_y[0] + m_y[1] + m_y[2]) / 3.0; double x1 = (m_x[1] + m_x[0]) / 2 - (xc - (m_x[1] + m_x[0]) / 2); double y1 = (m_y[1] + m_y[0]) / 2 - (yc - (m_y[1] + m_y[0]) / 2); double x2 = (m_x[2] + m_x[1]) / 2 - (xc - (m_x[2] + m_x[1]) / 2); double y2 = (m_y[2] + m_y[1]) / 2 - (yc - (m_y[2] + m_y[1]) / 2); double x3 = (m_x[0] + m_x[2]) / 2 - (xc - (m_x[0] + m_x[2]) / 2); double y3 = (m_y[0] + m_y[2]) / 2 - (yc - (m_y[0] + m_y[2]) / 2); gouraudSpanGen.SetColor(ColorRGBA.Make(1, 0, 0, alpha), ColorRGBA.Make(0, 1, 0, alpha), ColorRGBA.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[0], m_y[0], m_x[1], m_y[1], xc, yc, d); painter.Fill(gouraudSpanGen.MakeVxs(), gouraudSpanGen); gouraudSpanGen.SetColor(ColorRGBA.Make(0, 1, 0, alpha), ColorRGBA.Make(0, 0, 1, alpha), ColorRGBA.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[1], m_y[1], m_x[2], m_y[2], xc, yc, d); painter.Fill(gouraudSpanGen.MakeVxs(), gouraudSpanGen); gouraudSpanGen.SetColor(ColorRGBA.Make(0, 0, 1, alpha), ColorRGBA.Make(1, 0, 0, alpha), ColorRGBA.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[2], m_y[2], m_x[0], m_y[0], xc, yc, d); painter.Fill(gouraudSpanGen.MakeVxs(), gouraudSpanGen); brc = 1 - brc; gouraudSpanGen.SetColor(ColorRGBA.Make(1, 0, 0, alpha), ColorRGBA.Make(0, 1, 0, alpha), ColorRGBA.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[0], m_y[0], m_x[1], m_y[1], x1, y1, d); painter.Fill(gouraudSpanGen.MakeVxs(), gouraudSpanGen); gouraudSpanGen.SetColor(ColorRGBA.Make(0, 1, 0, alpha), ColorRGBA.Make(0, 0, 1, alpha), ColorRGBA.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[1], m_y[1], m_x[2], m_y[2], x2, y2, d); painter.Fill(gouraudSpanGen.MakeVxs(), gouraudSpanGen); gouraudSpanGen.SetColor(ColorRGBA.Make(0, 0, 1, alpha), ColorRGBA.Make(1, 0, 0, alpha), ColorRGBA.Make(brc, brc, brc, alpha)); gouraudSpanGen.SetTriangle(m_x[2], m_y[2], m_x[0], m_y[0], x3, y3, d); painter.Fill(gouraudSpanGen.MakeVxs(), gouraudSpanGen); }
private void DrawBorder(Graphics2D graphics2D) { RectangleDouble Bounds = LocalBounds; RoundedRect borderRect = new RoundedRect(this.LocalBounds, 0); Stroke strokeRect = new Stroke(borderRect, borderWidth); graphics2D.Render(strokeRect, borderColor); }
void CreateOnePage(int plateNumber, ref int nextPartToPrintIndex, PdfPage pdfPage) { ImageBuffer plateInventoryImage = new ImageBuffer((int)(300 * 8.5), 300 * 11, 32, new BlenderBGRA()); Graphics2D plateGraphics = plateInventoryImage.NewGraphics2D(); double currentlyPrintingHeightPixels = PrintTopOfPage(plateInventoryImage, plateGraphics); Vector2 offset = new Vector2(PageMarginPixels.Left, currentlyPrintingHeightPixels); double tallestHeight = 0; List <PartImage> partsOnLine = new List <PartImage>(); while (nextPartToPrintIndex < partImagesToPrint.Count) { ImageBuffer image = partImagesToPrint[nextPartToPrintIndex].image; tallestHeight = Math.Max(tallestHeight, image.Height); if (partsOnLine.Count > 0 && offset.x + image.Width > plateInventoryImage.Width - PageMarginPixels.Right) { if (partsOnLine.Count == 1) { plateGraphics.Render(partsOnLine[0].image, plateInventoryImage.Width / 2 - partsOnLine[0].image.Width / 2, offset.y - tallestHeight); } else { foreach (PartImage partToDraw in partsOnLine) { plateGraphics.Render(partToDraw.image, partToDraw.xOffset, offset.y - tallestHeight); } } offset.x = PageMarginPixels.Left; offset.y -= (tallestHeight + PartPaddingPixels * 2); tallestHeight = 0; partsOnLine.Clear(); if (offset.y - image.Height < PageMarginPixels.Bottom) { break; } } else { partImagesToPrint[nextPartToPrintIndex].xOffset = offset.x; partsOnLine.Add(partImagesToPrint[nextPartToPrintIndex]); //plateGraphics.Render(image, offset.x, offset.y - image.Height); offset.x += image.Width + PartPaddingPixels * 2; nextPartToPrintIndex++; } } // print the last line of parts foreach (PartImage partToDraw in partsOnLine) { plateGraphics.Render(partToDraw.image, partToDraw.xOffset, offset.y - tallestHeight); } TypeFacePrinter printer = new TypeFacePrinter(string.Format("{0}", Path.GetFileNameWithoutExtension(pathAndFileToSaveTo)), 32, justification: Justification.Center); printer.Origin = new Vector2(plateGraphics.DestImage.Width / 2, 110); plateGraphics.Render(printer, RGBA_Bytes.Black); printer = new TypeFacePrinter(string.Format("Page {0}", plateNumber), 28, justification: Justification.Center); printer.Origin = new Vector2(plateGraphics.DestImage.Width / 2, 60); plateGraphics.Render(printer, RGBA_Bytes.Black); string applicationUserDataPath = ApplicationDataStorage.Instance.ApplicationUserDataPath; string folderToSavePrintsTo = Path.Combine(applicationUserDataPath, "data", "temp", "plateImages"); string jpegFileName = System.IO.Path.Combine(folderToSavePrintsTo, plateNumber.ToString() + ".jpeg"); if (!Directory.Exists(folderToSavePrintsTo)) { Directory.CreateDirectory(folderToSavePrintsTo); } ImageBMPIO.SaveImageData(jpegFileName, plateInventoryImage); XGraphics gfx = XGraphics.FromPdfPage(pdfPage); XImage jpegImage = XImage.FromFile(jpegFileName); //double width = jpegImage.PixelWidth * 72 / jpegImage.HorizontalResolution; //double height = jpegImage.PixelHeight * 72 / jpegImage. .HorizontalResolution; gfx.DrawImage(jpegImage, 0, 0, pdfPage.Width, pdfPage.Height); }
/// <summary> /// Called when we've to draw the image. /// </summary> /// <param name="graphics">The graphics.</param> private void OnDraw(Graphics2D graphics) { if (IsDisposed) { throw new ObjectDisposedException("ImageDataFlowHelper"); } if (this.SyncBuffer == null) { return; } // Change bitmap contents if needed if (this.SyncBufferChanged) { lock (this.SyncBufferLock) { // Recreate bitmap on need if ((this.BitmapSize != this.SyncBufferSize) || (this.Bitmap == null)) { CommonTools.SafeDispose(ref this.Bitmap); this.Bitmap = new WriteableBitmapResource( new Size2(this.SyncBufferSize.Width, this.SyncBufferSize.Height), BitmapFormat.Bgra, AlphaMode.Ignore); this.BitmapSize = this.SyncBufferSize; } // Write data from SyncBuffer to bitmap this.Bitmap.SetBitmapContent( graphics, this.SyncBuffer.Pointer, this.SyncBuffer.Pitch); } } // Draw the bitmap on the screen if ((this.Bitmap != null) && (this.BitmapSize.Width > 0) && (this.BitmapSize.Height > 0)) { graphics.Clear(Color4.Transparent); // Draw the current contents of the stream RectangleF viewBounds = new RectangleF( 0f, 0f, graphics.ScreenSize.Width, graphics.ScreenSize.Height); graphics.DrawBitmap(this.Bitmap, viewBounds); // Draw the stream's name RectangleF titleBounds = new RectangleF( viewBounds.Width / 2f - 100f, 10f, 200f, 30f); graphics.FillRoundedRectangle(titleBounds, 5f, 5f, this.TextBackground); graphics.DrawText( this.StreamName, this.TextFormat, titleBounds, this.TextForeground); } }
public override void OnDraw(Graphics2D graphics2D) { if (loadedGCode != null) { //using (new PerformanceTimer("GCode Timer", "Total")) { Affine transform = TotalTransform; if (RenderGrid) { //using (new PerformanceTimer("GCode Timer", "Render Grid")) { double gridLineWidths = 0.2 * layerScale; Graphics2DOpenGL graphics2DGl = graphics2D as Graphics2DOpenGL; if (graphics2DGl != null) { GlRenderGrid(graphics2DGl, transform, gridLineWidths); } else { CreateGrid(transform); Stroke stroke = new Stroke(grid, gridLineWidths); graphics2D.Render(stroke, gridColor); } } } RenderType renderType = RenderType.Extrusions; if (RenderMoves) { renderType |= RenderType.Moves; } if (RenderRetractions) { renderType |= RenderType.Retractions; } if (RenderSpeeds) { renderType |= RenderType.SpeedColors; } if (SimulateExtrusion) { renderType |= RenderType.SimulateExtrusion; } if (HideExtruderOffsets) { renderType |= RenderType.HideExtruderOffsets; } GCodeRenderInfo renderInfo = new GCodeRenderInfo(activeLayerIndex, activeLayerIndex, transform, layerScale, renderType, FeatureToStartOnRatio0To1, FeatureToEndOnRatio0To1, new Vector2[] { ActiveSliceSettings.Instance.GetOffset(0), ActiveSliceSettings.Instance.GetOffset(1) }); //using (new PerformanceTimer("GCode Timer", "Render")) { gCodeRenderer.Render(graphics2D, renderInfo); } } } base.OnDraw(graphics2D); }
public override void Draw(Graphics2D g) { }
public override void Render(Graphics2D graphics2D, GCodeRenderInfo renderInfo, bool highlightFeature = false) { if (renderInfo.CurrentRenderType.HasFlag(RenderType.Extrusions)) { double extrusionLineWidths = GetExtrusionWidth(renderInfo.CurrentRenderType) * 2 * renderInfo.LayerScale; Color extrusionColor = Color.Black; if (highlightFeature) { extrusionColor = RenderFeatureBase.HighlightColor; } else 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); } 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); var eWidth = extrusionLineWidths / 2; graphics2DGl.DrawAALineRounded(startPoint, endPoint, eWidth, extrusionColor); if (highlightFeature) { Render3DStartEndMarkers(graphics2DGl, eWidth / 2, startPoint, endPoint); } } else { // render using agg var pathStorage = new VertexStorage(); var transformedPathStorage = new VertexSourceApplyTransform(pathStorage, renderInfo.Transform); var stroke = new Stroke(transformedPathStorage, extrusionLineWidths / 2) { LineCap = LineCap.Round, LineJoin = LineJoin.Round }; pathStorage.Add(start.X, start.Y, ShapePath.FlagsAndCommand.MoveTo); pathStorage.Add(end.X, end.Y, ShapePath.FlagsAndCommand.LineTo); graphics2D.Render(stroke, extrusionColor); } } }
public override void OnDraw(Graphics2D graphics2D) { if(CheckGlControl()) base.OnDraw(graphics2D); CheckGlControl(); }
public void DoDrawBeforeChildren(Graphics2D graphics2D) { // erase to the background color graphics2D.FillRectangle(GetTotalBounds(), BackgroundColor); }
public override void OnDraw(Graphics2D graphics2D) { haveDrawn = true; base.OnDraw(graphics2D); }
public void Draw(Graphics2D graphics){ MasterSheet master = GetMasterSheet(); if(getFollowMasterBackground()) master.GetBackground().Draw(graphics); if(getFollowMasterObjects()){ Shape[] sh = master.GetShapes(); for (int i = 0; i < sh.Length; i++) { if(MasterSheet.IsPlaceholder(sh[i])) continue; sh[i].Draw(graphics); } } Shape[] sh = GetShapes(); for (int i = 0; i < sh.Length; i++) { sh[i].Draw(graphics); } }
public void ShowDebugInfo(Graphics2D graphics2D) { Color boundingBoxColor = new Color(0, 0, 0); var typeFaceNameStyle = new StyledTypeFace(this, 50); var fontNamePrinter = new TypeFacePrinter(this.fontFamily + " - 50 point", typeFaceNameStyle); double x = 30 + typeFaceNameStyle.EmSizeInPoints * 1.5; double y = 40 - typeFaceNameStyle.DescentInPixels; int width = 150; var originColor = new Color(0, 0, 0); var ascentColor = new Color(255, 0, 0); var descentColor = new Color(255, 0, 0); var xHeightColor = new Color(12, 25, 200); var capHeightColor = new Color(12, 25, 200); var underlineColor = new Color(0, 150, 55); // the origin RectangleDouble bounds = typeFaceNameStyle.BoundingBoxInPixels; graphics2D.Rectangle(x + bounds.Left, y + bounds.Bottom, x + bounds.Right, y + bounds.Top, boundingBoxColor); graphics2D.Line(x - 10, y, x + width / 2, y, originColor); 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(x, y); var transformedText = new VertexSourceApplyTransform(textTransform); fontNamePrinter.Render(graphics2D, Color.Black, transformedText); graphics2D.Render(transformedText, Color.Black); // render the legend var legendFont = new StyledTypeFace(this, 12); var textPos = new Vector2(x + width / 2, y + typeFaceNameStyle.EmSizeInPixels * 1.5); graphics2D.Render(new TypeFacePrinter("Bounding Box"), textPos, boundingBoxColor); textPos.Y += legendFont.EmSizeInPixels; 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("Origin"), textPos, originColor); 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; }
public void BackBuffersAreScreenAligned() { // make sure draw string and a text widget produce the same result when drawn to the same spot { ImageBuffer drawStringImage = new ImageBuffer(100, 20, 24, new BlenderBGR()); { Graphics2D drawStringGraphics = drawStringImage.NewGraphics2D(); drawStringGraphics.Clear(RGBA_Bytes.White); drawStringGraphics.DrawString("test", 0, 0); SaveImage(drawStringImage, "z draw string.tga"); } ImageBuffer textWidgetImage = new ImageBuffer(100, 20, 24, new BlenderBGR()); { TextWidget textWidget = new TextWidget("test"); Graphics2D textWidgetGraphics = textWidgetImage.NewGraphics2D(); textWidgetGraphics.Clear(RGBA_Bytes.White); textWidget.OnDraw(textWidgetGraphics); } Assert.IsTrue(drawStringImage == textWidgetImage); } // make sure that a back buffer is always trying to draw 1:1 pixels to the buffer above { ImageBuffer drawStringOffsetImage = new ImageBuffer(100, 20, 32, new BlenderBGRA()); { Graphics2D drawStringGraphics = drawStringOffsetImage.NewGraphics2D(); drawStringGraphics.Clear(RGBA_Bytes.White); drawStringGraphics.DrawString("test", 23.3, 0); SaveImage(drawStringOffsetImage, "z draw offset string.tga"); } GuiWidget container = new GuiWidget(100, 20); container.DoubleBuffer = true; { TextWidget textWidget = new TextWidget("test", 23.3); container.AddChild(textWidget); container.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White); container.OnDraw(container.BackBuffer.NewGraphics2D()); SaveImage(container.BackBuffer, "z offset text widget.tga"); } Vector2 bestPosition; double bestLeastSquares; double maxError = 10; container.BackBuffer.FindLeastSquaresMatch(drawStringOffsetImage, out bestPosition, out bestLeastSquares, maxError); Assert.IsTrue(bestLeastSquares < maxError); } { ImageBuffer drawStringOffsetImage = new ImageBuffer(100, 20, 32, new BlenderBGRA()); { Graphics2D drawStringGraphics = drawStringOffsetImage.NewGraphics2D(); drawStringGraphics.Clear(RGBA_Bytes.White); drawStringGraphics.DrawString("test", 23.8, 0); SaveImage(drawStringOffsetImage, "z draw offset string.tga"); } GuiWidget container1 = new GuiWidget(100, 20); container1.DoubleBuffer = true; GuiWidget container2 = new GuiWidget(90, 20); container2.OriginRelativeParent = new Vector2(.5, 0); container1.AddChild(container2); { TextWidget textWidget = new TextWidget("test", 23.3); container2.AddChild(textWidget); container1.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White); container1.OnDraw(container1.BackBuffer.NewGraphics2D()); SaveImage(container1.BackBuffer, "z offset text widget.tga"); } Assert.IsTrue(container1.BackBuffer.FindLeastSquaresMatch(drawStringOffsetImage, 5)); } }
public override void OnDraw(Graphics2D graphics2D) { base.OnDraw(graphics2D); if (content.OriginRelativeParent.y != 0) { graphics2D.FillRectangle(0, 0, Width, KeyboardHeight, RGBA_Bytes.Black); } }
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 OnDraw(Graphics2D graphics2D) { RectangleDouble Bounds = LocalBounds; RoundedRect rectBorder = new RoundedRect(Bounds, this.borderRadius); graphics2D.Render(rectBorder, BorderColor); RectangleDouble insideBounds = Bounds; insideBounds.Inflate(-this.borderWidth); RoundedRect rectInside = new RoundedRect(insideBounds, Math.Max(this.borderRadius - this.borderWidth, 0)); graphics2D.Render(rectInside, this.BackgroundColor); base.OnDraw(graphics2D); }
public override void OnDraw(Graphics2D graphics2D) { DoDrawBeforeChildren(graphics2D); base.OnDraw(graphics2D); }
public void Draw(Graphics2D graphics){ AffineTransform at = graphics.GetTransform(); ShapePainter.paint(this, graphics); new TextPainter(this).paint(graphics); graphics.SetTransform(at); }
public override void OnDraw(Graphics2D graphics2D) { double fontHeight = internalTextWidget.Printer.TypeFaceStyle.EmSizeInPixels; if (Selecting && SelectionIndexToStartBefore != CharIndexToInsertBefore) { Vector2 selectPosition = internalTextWidget.Printer.GetOffsetLeftOfCharacterIndex(SelectionIndexToStartBefore); // for each selected line draw a rect for the chars of that line if (selectPosition.Y == InsertBarPosition.Y) { RectangleDouble bar = new RectangleDouble(Math.Ceiling(selectPosition.X), Math.Ceiling(internalTextWidget.Height + selectPosition.Y), Math.Ceiling(InsertBarPosition.X + 1), Math.Ceiling(internalTextWidget.Height + InsertBarPosition.Y - fontHeight)); RoundedRect selectCursorRect = new RoundedRect(bar, 0); graphics2D.Render(selectCursorRect, this.HighlightColor); } else { int firstCharToHighlight = Math.Min(CharIndexToInsertBefore, SelectionIndexToStartBefore); int lastCharToHighlight = Math.Max(CharIndexToInsertBefore, SelectionIndexToStartBefore); int lineStart = firstCharToHighlight; Vector2 lineStartPos = internalTextWidget.Printer.GetOffsetLeftOfCharacterIndex(lineStart); int lineEnd = lineStart + 1; Vector2 lineEndPos = internalTextWidget.Printer.GetOffsetLeftOfCharacterIndex(lineEnd); if (lineEndPos.Y != lineStartPos.Y) { // we are starting on a '\n', adjust so we will show the cr at the end of the line lineEndPos = lineStartPos; } bool firstCharOfLine = false; for (int i = lineEnd; i < lastCharToHighlight + 1; i++) { Vector2 nextPos = internalTextWidget.Printer.GetOffsetLeftOfCharacterIndex(i); if (firstCharOfLine) { if (lineEndPos.Y != lineStartPos.Y) { // we are starting on a '\n', adjust so we will show the cr at the end of the line lineEndPos = lineStartPos; } firstCharOfLine = false; } if (nextPos.Y != lineStartPos.Y) { if (lineEndPos.X == lineStartPos.X) { lineEndPos.X += Printer.TypeFaceStyle.GetAdvanceForCharacter(' '); } RectangleDouble bar = new RectangleDouble(Math.Ceiling(lineStartPos.X), Math.Ceiling(internalTextWidget.Height + lineStartPos.Y), Math.Ceiling(lineEndPos.X + 1), Math.Ceiling(internalTextWidget.Height + lineEndPos.Y - fontHeight)); RoundedRect selectCursorRect = new RoundedRect(bar, 0); graphics2D.Render(selectCursorRect, this.HighlightColor); lineStartPos = nextPos; firstCharOfLine = true; } else { lineEndPos = nextPos; } } if (lineEndPos.X != lineStartPos.X) { RectangleDouble bar = new RectangleDouble(Math.Ceiling(lineStartPos.X), Math.Ceiling(internalTextWidget.Height + lineStartPos.Y), Math.Ceiling(lineEndPos.X + 1), Math.Ceiling(internalTextWidget.Height + lineEndPos.Y - fontHeight)); RoundedRect selectCursorRect = new RoundedRect(bar, 0); graphics2D.Render(selectCursorRect, this.HighlightColor); } } } if (this.Focused && BarIsShowing) { double xFraction = graphics2D.GetTransform().tx; xFraction = xFraction - (int)xFraction; RectangleDouble bar2 = new RectangleDouble(Math.Ceiling(InsertBarPosition.X) - xFraction, Math.Ceiling(internalTextWidget.Height + InsertBarPosition.Y - fontHeight), Math.Ceiling(InsertBarPosition.X + 1) - xFraction, Math.Ceiling(internalTextWidget.Height + InsertBarPosition.Y)); RoundedRect cursorRect = new RoundedRect(bar2, 0); graphics2D.Render(cursorRect, this.CursorColor); } RectangleDouble boundsPlusPoint5 = LocalBounds; boundsPlusPoint5.Inflate(-.5); RoundedRect borderRect = new RoundedRect(boundsPlusPoint5, 0); Stroke borderLine = new Stroke(borderRect); base.OnDraw(graphics2D); }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 21JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Get the graphics2D instance. the graphics 2D shall be protected by * graphic2DMutex to support multi-threading. * @return the shared the graphics2D objects. */ private static void GetGraphics2DInstance() { lock (GRAPHICS_MUTEX) { if (SharedGraphics2D == null) { SharedGraphics2D = new Graphics2D(MapLayer.MAP_TILE_WIDTH, MapLayer.MAP_TILE_WIDTH); } } return; }
private static ImageBuffer CreateCircularBedGridImage(PrinterConfig printer) { Vector3 displayVolumeToBuild = Vector3.ComponentMax(printer.Bed.ViewerVolume, new Vector3(1, 1, 1)); double sizeForMarking = Math.Max(displayVolumeToBuild.X, displayVolumeToBuild.Y); double cmPerLine = 10; int skip = 1; if (sizeForMarking > 1000) { cmPerLine = 100; skip = 10; } else if (sizeForMarking > 300) { cmPerLine = 50; skip = 5; } var bedplateImage = new ImageBuffer(1024, 1024); Graphics2D graphics2D = bedplateImage.NewGraphics2D(); var originPixels = new Vector2(); { double lineSpacePixels = bedplateImage.Width / (displayVolumeToBuild.X / cmPerLine); double xPositionLines = (-(printer.Bed.ViewerVolume.X / 2.0) + printer.Bed.BedCenter.X) / cmPerLine; int xPositionCmInt = (int)Math.Round(xPositionLines); double fraction = xPositionLines - xPositionCmInt; for (double linePos = lineSpacePixels * (1 - fraction); linePos < bedplateImage.Width; linePos += lineSpacePixels) { xPositionCmInt++; if (xPositionCmInt == 0) { originPixels.X = linePos; } } } { double lineDist = bedplateImage.Height / (displayVolumeToBuild.Y / cmPerLine); double yPositionCm = (-(printer.Bed.ViewerVolume.Y / 2.0) + printer.Bed.BedCenter.Y) / cmPerLine; int yPositionCmInt = (int)Math.Round(yPositionCm); double fraction = yPositionCm - yPositionCmInt; for (double linePos = lineDist * (1 - fraction); linePos < bedplateImage.Height; linePos += lineDist) { yPositionCmInt++; int linePosInt = (int)linePos; if (yPositionCmInt == 0) { originPixels.Y = linePos; } } } Ellipse bedCircle = new Ellipse(bedplateImage.Width / 2, bedplateImage.Height / 2, bedplateImage.Width / 2, bedplateImage.Height / 2); graphics2D.Render(bedCircle, bedBaseColor); //graphics2D.Clear(bedBaseColor); { double lineSpacePixels = bedplateImage.Width / (displayVolumeToBuild.X / cmPerLine); double xPositionLines = (-(printer.Bed.ViewerVolume.X / 2.0) + printer.Bed.BedCenter.X) / cmPerLine; int xPositionCmInt = (int)Math.Round(xPositionLines); double fraction = xPositionLines - xPositionCmInt; int pointSize = 20; graphics2D.DrawString((xPositionCmInt * skip).ToString(), 4, originPixels.Y + 4, pointSize, color: bedMarkingsColor); for (double linePos = lineSpacePixels * (1 - fraction); linePos < bedplateImage.Width; linePos += lineSpacePixels) { xPositionCmInt++; int linePosInt = (int)linePos; int lineWidth = 1; if (xPositionCmInt == 0) { lineWidth = 2; graphics2D.Line(linePosInt, 0, linePosInt, bedplateImage.Height, bedMarkingsColor, lineWidth); } graphics2D.DrawString((xPositionCmInt * skip).ToString(), linePos + 4, originPixels.Y + 4, pointSize, color: bedMarkingsColor); Ellipse circle = new Ellipse(originPixels, linePos - originPixels.X); Stroke outline = new Stroke(circle); graphics2D.Render(outline, bedMarkingsColor); } } { double lineDist = bedplateImage.Height / (displayVolumeToBuild.Y / cmPerLine); double yPositionCm = (-(printer.Bed.ViewerVolume.Y / 2.0) + printer.Bed.BedCenter.Y) / cmPerLine; int yPositionCmInt = (int)Math.Round(yPositionCm); double fraction = yPositionCm - yPositionCmInt; int pointSize = 20; for (double linePos = lineDist * (1 - fraction); linePos < bedplateImage.Height; linePos += lineDist) { yPositionCmInt++; int linePosInt = (int)linePos; int lineWidth = 1; if (yPositionCmInt == 0) { lineWidth = 2; originPixels.Y = linePos; graphics2D.Line(0, linePosInt, bedplateImage.Height, linePosInt, bedMarkingsColor, lineWidth); } graphics2D.DrawString((yPositionCmInt * skip).ToString(), originPixels.X + 4, linePos + 4, pointSize, color: bedMarkingsColor); } } ApplyOemBedImage(bedplateImage, printer); return(bedplateImage); }
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); }
private static ImageBuffer CreateRectangularBedGridImage(PrinterConfig printer) { Vector3 displayVolumeToBuild = Vector3.ComponentMax(printer.Bed.ViewerVolume, new Vector3(1, 1, 1)); double sizeForMarking = Math.Max(displayVolumeToBuild.X, displayVolumeToBuild.Y); double divisor = 10; int skip = 1; if (sizeForMarking > 1000) { divisor = 100; skip = 10; } else if (sizeForMarking > 300) { divisor = 50; skip = 5; } var bedplateImage = new ImageBuffer(1024, 1024); Graphics2D graphics2D = bedplateImage.NewGraphics2D(); graphics2D.Clear(bedBaseColor); { double lineDist = bedplateImage.Width / (displayVolumeToBuild.X / divisor); double xPositionCm = (-(printer.Bed.ViewerVolume.X / 2.0) + printer.Bed.BedCenter.X) / divisor; int xPositionCmInt = (int)Math.Round(xPositionCm); double fraction = xPositionCm - xPositionCmInt; int pointSize = 20; graphics2D.DrawString((xPositionCmInt * skip).ToString(), 4, 4, pointSize, color: bedMarkingsColor); for (double linePos = lineDist * (1 - fraction); linePos < bedplateImage.Width; linePos += lineDist) { xPositionCmInt++; int linePosInt = (int)linePos; int lineWidth = 1; if (xPositionCmInt == 0) { lineWidth = 2; } graphics2D.Line(linePosInt, 0, linePosInt, bedplateImage.Height, bedMarkingsColor, lineWidth); graphics2D.DrawString((xPositionCmInt * skip).ToString(), linePos + 4, 4, pointSize, color: bedMarkingsColor); } } { double lineDist = bedplateImage.Height / (displayVolumeToBuild.Y / divisor); double yPositionCm = (-(printer.Bed.ViewerVolume.Y / 2.0) + printer.Bed.BedCenter.Y) / divisor; int yPositionCmInt = (int)Math.Round(yPositionCm); double fraction = yPositionCm - yPositionCmInt; int pointSize = 20; for (double linePos = lineDist * (1 - fraction); linePos < bedplateImage.Height; linePos += lineDist) { yPositionCmInt++; int linePosInt = (int)linePos; int lineWidth = 1; if (yPositionCmInt == 0) { lineWidth = 2; } graphics2D.Line(0, linePosInt, bedplateImage.Height, linePosInt, bedMarkingsColor, lineWidth); graphics2D.DrawString((yPositionCmInt * skip).ToString(), 4, linePos + 4, pointSize, color: bedMarkingsColor); } } ApplyOemBedImage(bedplateImage, printer); return(bedplateImage); }
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); }
public override void OnDraw(Graphics2D graphics2D) { base.OnDraw(graphics2D); }
/// <summary> /// This is called before the OnDraw method. /// When overriding OnPaintBackground in a derived class it is not necessary to call the base class's OnPaintBackground. /// </summary> /// <param name="graphics2D"></param> public virtual void OnDrawBackground(Graphics2D graphics2D) { if (BackgroundColor.Alpha0To255 > 0) { graphics2D.FillRectangle(LocalBounds, BackgroundColor); } }
protected override void PaintComponent(Graphics g) { base.PaintComponent(g); // Dimensions Graphics2D g2d = (Graphics2D)g.Create(); g.SetFont(new Font("Arial", Font.Plain, 10)); int width = this.GetWidth(); int height = this.GetHeight(); int cellWidth = width / this.columnCount; int cellHeight = height / this.rowCount; int xOffset = (width - (this.columnCount * cellWidth)) / 2; int yOffset = (height - (this.rowCount * cellHeight)) / 2; // Get label index IList <U> labels = this._enclosing._enclosing.UniqueLabels().Stream().Collect(Collectors.ToList()); // Get color gradient int maxDiag = 0; int maxOffdiag = 0; foreach (KeyValuePair <Pair <U, U>, int> entry in this._enclosing._enclosing.confTable) { if (entry.Key.first == entry.Key.second) { maxDiag = Math.Max(maxDiag, entry.Value); } else { maxOffdiag = Math.Max(maxOffdiag, entry.Value); } } // Render the grid float[] hsb = new float[3]; for (int row = 0; row < this.rowCount; row++) { for (int col = 0; col < this.columnCount; col++) { // Position int x = xOffset + (col * cellWidth); int y = yOffset + (row * cellHeight); float xCenter = xOffset + (col * cellWidth) + cellWidth / 3.0f; float yCenter = yOffset + (row * cellHeight) + cellHeight / 2.0f; // Get text + Color string text; Color bg = Color.White; if (row == 0 && col == 0) { text = "V guess | gold >"; } else { if (row == 0) { text = labels[col - 1].ToString(); } else { if (col == 0) { text = labels[row - 1].ToString(); } else { // Set value int count = this._enclosing._enclosing.confTable[Pair.MakePair(labels[row - 1], labels[col - 1])]; if (count == null) { count = 0; } text = string.Empty + count; // Get color if (row == col) { double percentGood = ((double)count) / ((double)maxDiag); hsb = Color.RGBtoHSB((int)(255 - (255.0 * percentGood)), (int)(255 - (255.0 * percentGood / 2.0)), (int)(255 - (255.0 * percentGood)), hsb); bg = Color.GetHSBColor(hsb[0], hsb[1], hsb[2]); } else { double percentBad = ((double)count) / ((double)maxOffdiag); hsb = Color.RGBtoHSB((int)(255 - (255.0 * percentBad / 2.0)), (int)(255 - (255.0 * percentBad)), (int)(255 - (255.0 * percentBad)), hsb); bg = Color.GetHSBColor(hsb[0], hsb[1], hsb[2]); } } } } // Draw Rectangle cell = new Rectangle(x, y, cellWidth, cellHeight); g2d.SetColor(bg); g2d.Fill(cell); g2d.SetColor(Color.Black); g2d.DrawString(text, xCenter, yCenter); this.cells.Add(cell); } } // Mouse over if (this.selectedCell != null && this.selectedCell.x > 0 && this.selectedCell.y > 0) { int index = this.selectedCell.x + (this.selectedCell.y * this.columnCount); Rectangle cell = this.cells[index]; this.OnMouseOver(g2d, cell, labels[this.selectedCell.y - 1], labels[this.selectedCell.x - 1]); } // Clean up g2d.Dispose(); }
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); } }
public DrawEventArgs(Graphics2D graphics2D) { this.graphics2D = graphics2D; }
public void OnDraw(Graphics2D gx) { CanvasPainter painter = new CanvasPainter(gx); IImageReaderWriter backBuffer = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect()); if (!didInit) { didInit = true; OnInitialize(); } ChildImage image; if (backBuffer.BitDepth == 32) { image = new ChildImage(backBuffer, new PixelBlenderBGRA()); } else { if (backBuffer.BitDepth != 24) { throw new System.NotSupportedException(); } image = new ChildImage(backBuffer, new PixelBlenderBGR()); } painter.Clear(ColorRGBA.White); //ClipProxyImage dest = new ClipProxyImage(image); //gx.Clear(ColorRGBA.White); //gx.SetClippingRect(new RectInt(0, 0, Width, Height)); //ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap; if (this.PerspectiveTransformType == Sample_Perspective.PerspectiveTransformType.Bilinear) { var bound = lionShape.Bounds; Bilinear txBilinear = Bilinear.RectToQuad(bound.Left, bound.Bottom, bound.Right, bound.Top, quadPolygonControl.GetInnerCoords()); if (txBilinear.IsValid) { painter.PaintSeries(txBilinear.TransformToVxs(lionShape.Path.Vxs), lionShape.Colors, lionShape.PathIndexList, lionShape.NumPaths); RectD lionBound = lionShape.Bounds; Ellipse ell = new Ellipse((lionBound.Left + lionBound.Right) * 0.5, (lionBound.Bottom + lionBound.Top) * 0.5, (lionBound.Right - lionBound.Left) * 0.5, (lionBound.Top - lionBound.Bottom) * 0.5, 200); VertexStore trans_ell = txBilinear.TransformToVxs(ell.MakeVxs()); painter.FillColor = ColorRGBA.Make(0.5f, 0.3f, 0.0f, 0.3f); painter.Fill(trans_ell); //------------------------------------------------------------- //outline double prevStrokeWidth = painter.StrokeWidth; painter.StrokeWidth = 3; painter.StrokeColor = ColorRGBA.Make(0.0f, 0.3f, 0.2f, 1.0f); painter.Draw(trans_ell); painter.StrokeWidth = prevStrokeWidth; } } else { var txPerspective = new Perspective( lionShape.Bounds, quadPolygonControl.GetInnerCoords()); if (txPerspective.IsValid) { painter.PaintSeries(txPerspective.TransformToVxs(lionShape.Path.Vxs), lionShape.Colors, lionShape.PathIndexList, lionShape.NumPaths); //-------------------------------------------------------------------------------------- //filled Ellipse //1. create original fill ellipse RectD lionBound = lionShape.Bounds; var filledEllipse = new Ellipse((lionBound.Left + lionBound.Right) * 0.5, (lionBound.Bottom + lionBound.Top) * 0.5, (lionBound.Right - lionBound.Left) * 0.5, (lionBound.Top - lionBound.Bottom) * 0.5, 200); VertexStore transformedEll = txPerspective.TransformToVxs(filledEllipse.MakeVxs()); painter.FillColor = ColorRGBA.Make(0.5f, 0.3f, 0.0f, 0.3f); painter.Fill(transformedEll); //-------------------------------------------------------- var prevStrokeW = painter.StrokeWidth; painter.StrokeWidth = 3; painter.StrokeColor = ColorRGBA.Make(0.0f, 0.3f, 0.2f, 1.0f); painter.Draw(transformedEll); painter.StrokeWidth = prevStrokeW; } } //-------------------------- // Render the "quad" tool and controls painter.FillColor = ColorRGBA.Make(0f, 0.3f, 0.5f, 0.6f); painter.Fill(quadPolygonControl.MakeVxs()); }
public override void OnDraw(Graphics2D graphics2D) { graphics2D.PushTransform(); int numLines = Text.Split('\n').Length - 1; if (Text.Contains("\r")) { throw new Exception("These should have be converted to \n."); } double yOffsetForText = Printer.TypeFaceStyle.EmSizeInPixels * numLines; double xOffsetForText = 0; switch (printer.Justification) { case Justification.Left: break; case Justification.Center: xOffsetForText = (Width - Printer.LocalBounds.Width) / 2; break; case Justification.Right: xOffsetForText = Width - Printer.LocalBounds.Width; break; default: throw new NotImplementedException(); } graphics2D.SetTransform(graphics2D.GetTransform() * Affine.NewTranslation(xOffsetForText, yOffsetForText)); RGBA_Bytes currentColor = this.textColor; if (EllipsisIfClipped && Printer.LocalBounds.Width > LocalBounds.Width) // only do this if it's static text { TypeFacePrinter shortTextPrinter = Printer; shortTextPrinter.DrawFromHintedCache = Printer.DrawFromHintedCache; while (shortTextPrinter.LocalBounds.Width > LocalBounds.Width && shortTextPrinter.Text.Length > 4) { shortTextPrinter = new TypeFacePrinter(shortTextPrinter.Text.Substring(0, shortTextPrinter.Text.Length - 4).TrimEnd(spaceTrim) + "...", Printer); } shortTextPrinter.Render(graphics2D, currentColor); } else { // it all fits or it's editable (if editable it will need to be offset/scrolled sometimes). Printer.Render(graphics2D, currentColor); } if (debugIt) { graphics2D.Line(-5, 0, 5, 0, RGBA_Bytes.Blue); graphics2D.Line(0, -5, 0, 5, RGBA_Bytes.Blue); } graphics2D.PopTransform(); if (debugIt) { graphics2D.Line(-5, 0, 5, 0, RGBA_Bytes.Red); graphics2D.Line(0, -5, 0, 5, RGBA_Bytes.Red); } base.OnDraw(graphics2D); }
public static Mesh[] SplitIntoMeshes(Mesh meshToSplit, Vector3 buildVolume, BackgroundWorker backgroundWorker, int startPercent, int endPercent) { int lengthPercent = endPercent - startPercent; // check if the part is bigger than the build plate (if it is we need to use that as our size) AxisAlignedBoundingBox partBounds = meshToSplit.GetAxisAlignedBoundingBox(); buildVolume.x = Math.Max(buildVolume.x, partBounds.XSize + 2); buildVolume.y = Math.Max(buildVolume.y, partBounds.YSize + 2); buildVolume.z = Math.Max(buildVolume.z, partBounds.ZSize + 2); // Find all the separate objects that are on the plate // Create a 2D image the size of the printer bed at some scale with the parts draw on it top down double scaleFactor = 5; ImageBuffer partPlate = new ImageBuffer((int)(buildVolume.x * scaleFactor), (int)(buildVolume.y * scaleFactor), 32, new BlenderBGRA()); Vector2 renderOffset = new Vector2(buildVolume.x / 2, buildVolume.y / 2) - new Vector2(partBounds.Center.x, partBounds.Center.y); PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partPlate.NewGraphics2D(), meshToSplit, renderOffset, scaleFactor, RGBA_Bytes.White); if (backgroundWorker != null) { backgroundWorker.ReportProgress(startPercent + (int)(lengthPercent * .2)); } //ImageBMPIO.SaveImageData("test part plate 0.png", partPlate); // expand the bounds a bit so that we can collect all the vertices and polygons within each bound Dilate.DoDilate3x3Binary(partPlate, 1); //ImageBMPIO.SaveImageData("test part plate 1.png", partPlate); // trace all the bounds of the objects on the plate PolyTree polyTreeForPlate = FindDistictObjectBounds(partPlate); if (polyTreeForPlate == null) { Mesh[] singleMesh = new Mesh[1]; singleMesh[0] = meshToSplit; return(singleMesh); } // get all the discrete areas that are polygons so we can search them Polygons discreteAreas = new Polygons(); GetAreasRecursive(polyTreeForPlate, discreteAreas); if (discreteAreas.Count == 0) { return(null); } else if (discreteAreas.Count == 1) { Mesh[] singleMesh = new Mesh[1]; singleMesh[0] = meshToSplit; return(singleMesh); } Graphics2D graphics2D = partPlate.NewGraphics2D(); graphics2D.Clear(RGBA_Bytes.Black); Random rand = new Random(); foreach (Polygon polygon in discreteAreas) { graphics2D.Render(PlatingHelper.PolygonToPathStorage(polygon), new RGBA_Bytes(rand.Next(128, 255), rand.Next(128, 255), rand.Next(128, 255))); } if (backgroundWorker != null) { backgroundWorker.ReportProgress(startPercent + (int)(lengthPercent * .50)); } //ImageBMPIO.SaveImageData("test part plate 2.png", partPlate); // add each of the separate bounds polygons to new meshes Mesh[] discreteMeshes = new Mesh[discreteAreas.Count]; for (int i = 0; i < discreteAreas.Count; i++) { discreteMeshes[i] = new Mesh(); } foreach (Face face in meshToSplit.Faces) { bool faceDone = false; // figure out which area one or more of the vertices are in add the face to the right new mesh foreach (FaceEdge faceEdge in face.FaceEdgeIterator()) { Vector2 position = new Vector2(faceEdge.vertex.Position.x, faceEdge.vertex.Position.y); position += renderOffset; position *= scaleFactor; for (int areaIndex = discreteAreas.Count - 1; areaIndex >= 0; areaIndex--) { if (PointInPolygon(discreteAreas[areaIndex], new IntPoint((int)position.x, (int)position.y))) { List <Vertex> faceVertices = new List <Vertex>(); foreach (FaceEdge faceEdgeToAdd in face.FaceEdgeIterator()) { Vertex newVertex = discreteMeshes[areaIndex].CreateVertex(faceEdgeToAdd.vertex.Position); faceVertices.Add(newVertex); } discreteMeshes[areaIndex].CreateFace(faceVertices.ToArray()); faceDone = true; break; } } if (faceDone) { break; } } } if (backgroundWorker != null) { backgroundWorker.ReportProgress(startPercent + (int)(lengthPercent)); } for (int i = 0; i < discreteMeshes.Count(); i++) { Mesh mesh = discreteMeshes[i]; } return(discreteMeshes); }
public override void Draw(Graphics2D g) { OnDraw(g); }
protected internal void doPaint(Graphics2D param1Graphics2D, JXPanel param1JXPanel, int param1Int1, int param1Int2) { outerInstance.doPaintComponent(param1Graphics2D); }