void EditorDraw(Graphics2D pDestFrame) { Vector2 WayPointPos = m_pCurWayPoint.GetPosition(); if (m_pParent != null) { RGBA_Bytes LineColor = new RGBA_Bytes(128, 128, 128); Vector2 ParentPos = m_pParent.m_pCurWayPoint.GetPosition(); // draw a line back to your parent pDestFrame.Line(WayPointPos.x, WayPointPos.y, ParentPos.x, ParentPos.y, LineColor); } // print out the stats for this point int LineSpacing = 12; int LineOffset = -LineSpacing; string Text = ""; Text.FormatWith("G: {0:0.0}", m_AccumulatedCostFromStartG); pDestFrame.DrawString(Text, WayPointPos.x, WayPointPos.y + LineOffset, justification: Justification.Center); LineOffset += LineSpacing; Text.FormatWith("H: {0:0.0}", m_EstimatedCostToDestH); pDestFrame.DrawString(Text, WayPointPos.x, WayPointPos.y + LineOffset, justification: Justification.Center); LineOffset += LineSpacing; Text.FormatWith("F: {0:0.0}", m_TotalCostForThisNodeF); pDestFrame.DrawString(Text, WayPointPos.x, WayPointPos.y + LineOffset, justification: Justification.Center); LineOffset += LineSpacing; }
private void CreateCircularBedGridImage(int linesInX, int linesInY, int increment = 1) { Vector2 bedImageCentimeters = new Vector2(linesInX, linesInY); BedImage = new ImageBuffer(1024, 1024); Graphics2D graphics2D = BedImage.NewGraphics2D(); graphics2D.Clear(bedBaseColor); { double lineDist = BedImage.Width / (double)linesInX; int count = 1; int pointSize = 16; graphics2D.DrawString(count.ToString(), 4, 4, pointSize, color: bedMarkingsColor); double currentRadius = lineDist; Vector2 bedCenter = new Vector2(BedImage.Width / 2, BedImage.Height / 2); for (double linePos = lineDist + BedImage.Width / 2; linePos < BedImage.Width; linePos += lineDist) { int linePosInt = (int)linePos; graphics2D.DrawString((count * increment).ToString(), linePos + 2, BedImage.Height / 2, pointSize, color: bedMarkingsColor); Ellipse circle = new Ellipse(bedCenter, currentRadius); Stroke outline = new Stroke(circle); graphics2D.Render(outline, bedMarkingsColor); currentRadius += lineDist; count++; } graphics2D.Line(0, BedImage.Height / 2, BedImage.Width, BedImage.Height / 2, bedMarkingsColor); graphics2D.Line(BedImage.Width / 2, 0, BedImage.Width / 2, BedImage.Height, bedMarkingsColor); } }
private void CreateRectangularBedGridImage(Vector3 displayVolumeToBuild, Vector2 bedCenter) { int linesInX = (int)Math.Ceiling(displayVolumeToBuild.x / 10); int linesInY = (int)Math.Ceiling(displayVolumeToBuild.y / 10); lock (lastCreatedBedImage) { Vector2 bedImageCentimeters = new Vector2(linesInX, linesInY); BedImage = new ImageBuffer(1024, 1024, 32, new BlenderBGRA()); Graphics2D graphics2D = BedImage.NewGraphics2D(); graphics2D.Clear(bedBaseColor); { double lineDist = BedImage.Width / (displayVolumeToBuild.x / 10.0); double xPositionCm = (-(displayVolume.x / 2.0) + bedCenter.x) / 10.0; int xPositionCmInt = (int)Math.Round(xPositionCm); double fraction = xPositionCm - xPositionCmInt; int pointSize = 20; graphics2D.DrawString(xPositionCmInt.ToString(), 4, 4, pointSize, color: bedMarkingsColor); for (double linePos = lineDist * (1 - fraction); linePos < BedImage.Width; linePos += lineDist) { xPositionCmInt++; int linePosInt = (int)linePos; int lineWidth = 1; if (xPositionCmInt == 0) { lineWidth = 2; } graphics2D.Line(linePosInt, 0, linePosInt, BedImage.Height, bedMarkingsColor, lineWidth); graphics2D.DrawString(xPositionCmInt.ToString(), linePos + 4, 4, pointSize, color: bedMarkingsColor); } } { double lineDist = BedImage.Height / (displayVolumeToBuild.y / 10.0); double yPositionCm = (-(displayVolume.y / 2.0) + bedCenter.y) / 10.0; int yPositionCmInt = (int)Math.Round(yPositionCm); double fraction = yPositionCm - yPositionCmInt; int pointSize = 20; for (double linePos = lineDist * (1 - fraction); linePos < BedImage.Height; linePos += lineDist) { yPositionCmInt++; int linePosInt = (int)linePos; int lineWidth = 1; if (yPositionCmInt == 0) { lineWidth = 2; } graphics2D.Line(0, linePosInt, BedImage.Height, linePosInt, bedMarkingsColor, lineWidth); graphics2D.DrawString(yPositionCmInt.ToString(), 4, linePos + 4, pointSize, color: bedMarkingsColor); } } lastCreatedBedImage = BedImage; lastLinesCount = new Point2D(linesInX, linesInY); } }
private void CreateRectangularBedGridImage(Vector3 displayVolumeToBuild, Vector2 bedCenter, double divisor, double skip) { lock (lastCreatedBedImage) { BedImage = new ImageBuffer(1024, 1024); Graphics2D graphics2D = BedImage.NewGraphics2D(); graphics2D.Clear(bedBaseColor); { double lineDist = BedImage.Width / (displayVolumeToBuild.X / divisor); double xPositionCm = (-(displayVolume.X / 2.0) + 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 < BedImage.Width; linePos += lineDist) { xPositionCmInt++; int linePosInt = (int)linePos; int lineWidth = 1; if (xPositionCmInt == 0) { lineWidth = 2; } graphics2D.Line(linePosInt, 0, linePosInt, BedImage.Height, bedMarkingsColor, lineWidth); graphics2D.DrawString((xPositionCmInt * skip).ToString(), linePos + 4, 4, pointSize, color: bedMarkingsColor); } } { double lineDist = BedImage.Height / (displayVolumeToBuild.Y / divisor); double yPositionCm = (-(displayVolume.Y / 2.0) + bedCenter.Y) / divisor; int yPositionCmInt = (int)Math.Round(yPositionCm); double fraction = yPositionCm - yPositionCmInt; int pointSize = 20; for (double linePos = lineDist * (1 - fraction); linePos < BedImage.Height; linePos += lineDist) { yPositionCmInt++; int linePosInt = (int)linePos; int lineWidth = 1; if (yPositionCmInt == 0) { lineWidth = 2; } graphics2D.Line(0, linePosInt, BedImage.Height, linePosInt, bedMarkingsColor, lineWidth); graphics2D.DrawString((yPositionCmInt * skip).ToString(), 4, linePos + 4, pointSize, color: bedMarkingsColor); } } lastCreatedBedImage = BedImage; } }
public void TakePhoto(string imageFileName) { ImageBuffer noCameraImage = new ImageBuffer(640, 480); Graphics2D graphics = noCameraImage.NewGraphics2D(); graphics.Clear(Color.White); graphics.DrawString("No Camera Detected", 320, 240, pointSize: 24, justification: Agg.Font.Justification.Center); graphics.DrawString(DateTime.Now.ToString(), 320, 200, pointSize: 12, justification: Agg.Font.Justification.Center); AggContext.ImageIO.SaveImageData(imageFileName, noCameraImage); PictureTaken?.Invoke(null, null); }
public override void Draw(Graphics2D g) { // Draw2(g); ////1. //// clear the image to white g.Clear(ColorRGBA.White); //------------------------------------ g.UseSubPixelRendering = true; // draw some text string teststr = "ABCDE abcd 1230 Hello!"; g.DrawString(teststr, 300, 400, 22); g.UseSubPixelRendering = false; g.DrawString(teststr, 300, 422, 22); }
public void DrawDebug() { int dx = 4, dy = SVGA.height - 13; Graphics2D.DrawString(dx, dy, SVGA.fpsString, Color.white, Fonts.FONT_MONO); dy -= 10; Graphics2D.DrawString(dx, dy, SVGA.deltaString, Color.white, Fonts.FONT_MONO); dy -= 10; Graphics2D.DrawString(dx, dy, "SEL_WIN: " + ProcessManager.selWindowID.ToString() + " MOVE_WIN: " + ProcessManager.moveID.ToString(), Color.white, Fonts.FONT_MONO); dy -= 10; string cpu = Kernel.cpuUsage.ToString(); if (cpu.Length > 5) { cpu = cpu.Substring(0, 5); } Graphics2D.DrawString(dx, dy, "CPU: " + cpu + "% PROCESSES: " + ProcessManager.GetCount().ToString(), Color.white, Fonts.FONT_MONO); dy -= 10; Graphics2D.DrawString(dx, dy, "RAM TOTAL: " + Kernel.GetTotalRAM().ToString() + "MB", Color.white, Fonts.FONT_MONO); dy -= 10; string mem = "RAM: " + Kernel.GetUsedRAM().ToString() + "/" + Kernel.GetFreeRAM().ToString() + "MB"; Graphics2D.DrawString(dx, dy, mem, Color.white, Fonts.FONT_MONO); dy -= 10; }
public override void OnDraw(Graphics2D graphics2D) { if (NeedRedraw) { NeedRedraw = false; Stopwatch traceTime = new Stopwatch(); traceTime.Start(); rayTraceScene(); traceTime.Stop(); timingStrings.Add("Time to trace BVH {0:0.0}s".FormatWith(traceTime.Elapsed.TotalSeconds)); } trackBallTransform.AxisToWorld = trackBallController.GetTransform4X4(); graphics2D.FillRectangle(new RectangleDouble(0, 0, 1000, 1000), RGBA_Bytes.Red); graphics2D.Render(destImage, 0, 0); //trackBallController.DrawRadius(graphics2D); totalTime.Stop(); timingStrings.Add("Total Time {0:0.0}s".FormatWith(totalTime.Elapsed.TotalSeconds)); if (!SavedTimes) { SavedTimes = true; File.WriteAllLines("timing.txt", timingStrings.ToArray()); } graphics2D.DrawString("Ray Trace: " + renderTime.ElapsedMilliseconds.ToString(), 20, 10); base.OnDraw(graphics2D); }
public override void Draw() { // draw bg if (backColor != SVGA.color) { Graphics2D.FillRectangle(bounds, backColor); } // draw border int bs = this.style.SIZE_BORDER; uint bord = this.style.C_BORDER; if (bs > 0) { Graphics2D.DrawRectangle(bounds, bs, bord); } // draw text int shadSize = this.style.SIZE_TEXT_SHADOW; uint shadCol = this.style.C_TEXT_SHADOW; if (text.Length > 0) { if (shadSize > 0 && shadCol != SVGA.color) { Graphics2D.DrawStringShadow(x, y, text, textColor, shadCol, shadSize, Fonts.FONT_MONO); } else { Graphics2D.DrawString(x, y, text, textColor, Fonts.FONT_MONO); } } }
public virtual void OnMouseOver(Graphics2D g2d, Rectangle cell, U guess, U gold) { // Compute values int x = (int)(cell.GetLocation().x + cell.GetWidth() / 5.0); int y = (int)(cell.GetLocation().y + cell.GetHeight() / 5.0); // Compute the text int value = this._enclosing._enclosing.confTable[Pair.MakePair(guess, gold)]; if (value == null) { value = 0; } string text = "Guess: " + guess.ToString() + "\n" + "Gold: " + gold.ToString() + "\n" + "Value: " + value; // Set the font Font bak = g2d.GetFont(); g2d.SetFont(bak.DeriveFont(bak.GetSize() * 2.0f)); // Render g2d.SetColor(Color.White); g2d.Fill(cell); g2d.SetColor(Color.Black); foreach (string line in text.Split("\n")) { g2d.DrawString(line, x, y += g2d.GetFontMetrics().GetHeight()); } // Reset g2d.SetFont(bak); }
public void RenderMouse(GuiWidget targetWidget, Graphics2D graphics2D) { GuiWidget parentSystemWindow = targetWidget; while (parentSystemWindow != null && parentSystemWindow as SystemWindow == null) { parentSystemWindow = parentSystemWindow.Parent; } if (parentSystemWindow != null) { Point2D mousePosOnWindow = ScreenToSystemWindow(inputSystem.CurrentMousePosition(), (SystemWindow)parentSystemWindow); Ellipse circle = new Ellipse(new Vector2(mousePosOnWindow.x, mousePosOnWindow.y), 10); if (inputSystem.LeftButtonDown) { graphics2D.Render(circle, Color.Green); if (inputSystem.ClickCount > 1) { graphics2D.DrawString(inputSystem.ClickCount.ToString(), mousePosOnWindow.x, mousePosOnWindow.y, 8, justification: Justification.Center, baseline: Baseline.BoundsCenter); } } graphics2D.Render(new Stroke(circle, 3), Color.Black); graphics2D.Render(new Stroke(circle, 2), Color.White); } }
protected virtual void DrawLevel(Graphics2D g, Point2I position, int lightOrDark) { Color color = (lightOrDark == GameData.VARIANT_LIGHT ? new Color(16, 16, 16) : Color.Black); g.DrawSprite(GameData.SPR_HUD_LEVEL, lightOrDark, position + new Point2I(8, 8)); g.DrawString(GameData.FONT_SMALL, (level + 1).ToString(), position + new Point2I(16, 8), color); }
public override void OnDraw(Graphics2D graphics2D) { Matrix4X4 currentRenderMatrix = trackballTumbleWidget.ModelviewMatrix; if (lastRenderedMatrix != currentRenderMatrix) { Stopwatch traceTime = new Stopwatch(); traceTime.Start(); rayTraceScene(); traceTime.Stop(); timingStrings.Add("Time to trace BVH {0:0.0}s".FormatWith(traceTime.Elapsed.TotalSeconds)); } //allObjectsHolder.AxisToWorld = trackBallController.GetTransform4X4(); graphics2D.FillRectangle(new RectangleDouble(0, 0, 1000, 1000), RGBA_Bytes.Red); graphics2D.Render(destImage, 0, 0); //trackBallController.DrawRadius(graphics2D); totalTime.Stop(); timingStrings.Add("Total Time {0:0.0}s".FormatWith(totalTime.Elapsed.TotalSeconds)); if (!SavedTimes) { SavedTimes = true; File.WriteAllLines("timing.txt", timingStrings.ToArray()); } graphics2D.DrawString("Ray Trace: " + renderTime.ElapsedMilliseconds.ToString(), 20, 10); base.OnDraw(graphics2D); currentRenderMatrix = lastRenderedMatrix; }
private void CreateRectangularBedGridImage(int linesInX, int linesInY) { using (TimedLock.Lock(lastCreatedBedImage, "CreateRectangularBedGridImage")) { if (linesInX == lastLinesCount.x && linesInY == lastLinesCount.y) { BedImage = lastCreatedBedImage; return; } Vector2 bedImageCentimeters = new Vector2(linesInX, linesInY); BedImage = new ImageBuffer(1024, 1024, 32, new BlenderBGRA()); Graphics2D graphics2D = BedImage.NewGraphics2D(); graphics2D.Clear(bedBaseColor); { double lineDist = BedImage.Width / (double)linesInX; int count = 1; int pointSize = 20; graphics2D.DrawString(count.ToString(), 4, 4, pointSize, color: bedMarkingsColor); for (double linePos = lineDist; linePos < BedImage.Width; linePos += lineDist) { count++; int linePosInt = (int)linePos; graphics2D.Line(linePosInt, 0, linePosInt, BedImage.Height, bedMarkingsColor); graphics2D.DrawString(count.ToString(), linePos + 4, 4, pointSize, color: bedMarkingsColor); } } { double lineDist = BedImage.Height / (double)linesInY; int count = 1; int pointSize = 16; for (double linePos = lineDist; linePos < BedImage.Height; linePos += lineDist) { count++; int linePosInt = (int)linePos; graphics2D.Line(0, linePosInt, BedImage.Height, linePosInt, bedMarkingsColor); graphics2D.DrawString(count.ToString(), 4, linePos + 4, pointSize, color: bedMarkingsColor); } } lastCreatedBedImage = BedImage; lastLinesCount = new Point2D(linesInX, linesInY); } }
// Draws the ruppes and dungeon keys. private void DrawRupees(Graphics2D g, int lightDark) { Color black = (lightDark == GameData.VARIANT_LIGHT ? new Color(16, 16, 16) : Color.Black); int advancedOffset = (gameControl.IsAdvancedGame ? 8 : 0); Dungeon dungeon = gameControl.RoomControl.Dungeon; if (dungeon != null) { // Display the small key count. g.DrawSprite(GameData.SPR_HUD_KEY, lightDark, new Point2I(80 - advancedOffset, 0)); g.DrawSprite(GameData.SPR_HUD_X, lightDark, new Point2I(88 - advancedOffset, 0)); g.DrawString(GameData.FONT_SMALL, dungeon.NumSmallKeys.ToString(), new Point2I(96 - advancedOffset, 0), black); } else { // Display rupee icon. g.DrawSprite(GameData.SPR_HUD_RUPEE, lightDark, new Point2I(80 - advancedOffset, 0)); } g.DrawString(GameData.FONT_SMALL, dynamicRupees.ToString("000"), new Point2I(80 - advancedOffset, 8), black); }
public override void Draw() { // get style colors uint bg = style.C_BG; uint fg = style.C_TEXT; uint bord = style.C_BORDER; uint bordOuter = style.C_BORDER_OUTER; uint bordInner = style.C_BORDER_INNER; uint fgShadow = style.C_TEXT_SHADOW; uint fgHover = style.C_TEXT_HOVER; uint fgDown = style.C_TEXT_DOWN; uint dis = style.C_DISABLED; uint shadow = style.C_SHADOW; uint hov = style.C_HOVER; uint dwn = style.C_DOWN; // get style sizes int bordSize = style.SIZE_BORDER; int shadowSize = style.SIZE_SHADOW; int fgShadowSize = style.SIZE_TEXT_SHADOW; int borderStyle = style.BORDER_STYLE; // draw bg Graphics2D.FillRectangle(bounds, bg); // draw border Graphics2D.DrawRectangle(bounds, bordSize, bord); // text if (text.Length > 0) { if (!passwordFilter) { Graphics2D.DrawString(x + 4, y + (height / 2) - 4, text, fg, Fonts.FONT_MONO); } else { int sx = x + 4; for (int i = 0; i < text.Length; i++) { Graphics2D.DrawChar(sx, y + (height / 2) - 4, '*', fg, Fonts.FONT_MONO); sx += Fonts.FONT_MONO.characterWidth + Graphics2D.FONT_SPACING; } } } if (cursor) { int xadd = textW; if (text.Length == 0) { xadd = 2; } Graphics2D.DrawChar(x + xadd + 2, y + (height / 2) - 4, '|', fg, Fonts.FONT_MONO); } }
private void LoadStl_Click(object sender, EventArgs e) { OpenFileDialogParams opeParams = new OpenFileDialogParams("STL Files|*.stl"); FileDialog.OpenFileDialog(opeParams, (openParams) => { var streamToLoadFrom = File.Open(openParams.FileName, FileMode.Open); if (streamToLoadFrom != null) { var loadedFileName = openParams.FileName; meshToRender = StlProcessing.Load(streamToLoadFrom); ImageBuffer plateInventory = new ImageBuffer((int)(300 * 8.5), 300 * 11, 32, new BlenderBGRA()); Graphics2D plateGraphics = plateInventory.NewGraphics2D(); plateGraphics.Clear(RGBA_Bytes.White); double inchesPerMm = 0.0393701; double pixelsPerInch = 300; double pixelsPerMm = inchesPerMm * pixelsPerInch; AxisAlignedBoundingBox aabb = meshToRender.GetAxisAlignedBoundingBox(); Vector2 lowerLeftInMM = new Vector2(-aabb.minXYZ.x, -aabb.minXYZ.y); Vector3 centerInMM = (aabb.maxXYZ - aabb.minXYZ) / 2; Vector2 offsetInMM = new Vector2(20, 30); { RectangleDouble bounds = new RectangleDouble(offsetInMM.x * pixelsPerMm, offsetInMM.y * pixelsPerMm, (offsetInMM.x + aabb.maxXYZ.x - aabb.minXYZ.x) * pixelsPerMm, (offsetInMM.y + aabb.maxXYZ.y - aabb.minXYZ.y) * pixelsPerMm); bounds.Inflate(3 * pixelsPerMm); RoundedRect rect = new RoundedRect(bounds, 3 * pixelsPerMm); plateGraphics.Render(rect, RGBA_Bytes.LightGray); Stroke rectOutline = new Stroke(rect, .5 * pixelsPerMm); plateGraphics.Render(rectOutline, RGBA_Bytes.DarkGray); } OrthographicZProjection.DrawTo(plateGraphics, meshToRender, lowerLeftInMM + offsetInMM, pixelsPerMm); plateGraphics.DrawString(Path.GetFileName(openParams.FileName), (offsetInMM.x + centerInMM.x) * pixelsPerMm, (offsetInMM.y - 10) * pixelsPerMm, 50, Agg.Font.Justification.Center); //ImageBuffer logoImage = new ImageBuffer(); //ImageIO.LoadImageData("Logo.png", logoImage); //plateGraphics.Render(logoImage, (plateInventory.Width - logoImage.Width) / 2, plateInventory.Height - logoImage.Height - 10 * pixelsPerMm); //ImageIO.SaveImageData("plate Inventory.jpeg", plateInventory); } }); }
private static double PaintTree(Tree t, Point2D start, Graphics2D g2, FontMetrics fM) { if (t == null) { return(0.0); } string nodeStr = NodeToString(t); double nodeWidth = fM.StringWidth(nodeStr); double nodeHeight = fM.GetHeight(); double nodeAscent = fM.GetAscent(); TreeJPanel.WidthResult wr = WidthResult(t, fM); double treeWidth = wr.width; double nodeTab = wr.nodeTab; double childTab = wr.childTab; double nodeCenter = wr.nodeCenter; //double treeHeight = height(t, fM); // draw root g2.DrawString(nodeStr, (float)(nodeTab + start.GetX()), (float)(start.GetY() + nodeAscent)); if (t.IsLeaf()) { return(nodeWidth); } double layerMultiplier = (1.0 + belowLineSkip + aboveLineSkip + parentSkip); double layerHeight = nodeHeight * layerMultiplier; double childStartX = start.GetX() + childTab; double childStartY = start.GetY() + layerHeight; double lineStartX = start.GetX() + nodeCenter; double lineStartY = start.GetY() + nodeHeight * (1.0 + belowLineSkip); double lineEndY = lineStartY + nodeHeight * parentSkip; // recursively draw children for (int i = 0; i < t.Children().Length; i++) { Tree child = t.Children()[i]; double cWidth = PaintTree(child, new Point2D.Double(childStartX, childStartY), g2, fM); // draw connectors wr = WidthResult(child, fM); double lineEndX = childStartX + wr.nodeCenter; g2.Draw(new Line2D.Double(lineStartX, lineStartY, lineEndX, lineEndY)); childStartX += cWidth; if (i < t.Children().Length - 1) { childStartX += sisterSkip * fM.StringWidth(" "); } } return(treeWidth); }
void CreateBedGridImage(int linesInX, int linesInY) { Vector2 bedImageCentimeters = new Vector2(linesInX, linesInY); bedCentimeterGridImage = new ImageBuffer(1024, 1024, 32, new BlenderBGRA()); Graphics2D graphics2D = bedCentimeterGridImage.NewGraphics2D(); graphics2D.Clear(RGBA_Bytes.White); { double lineDist = bedCentimeterGridImage.Width / (double)linesInX; int count = 1; int pointSize = 20; graphics2D.DrawString(count.ToString(), 0, 0, pointSize); for (double linePos = lineDist; linePos < bedCentimeterGridImage.Width; linePos += lineDist) { count++; int linePosInt = (int)linePos; graphics2D.Line(linePosInt, 0, linePosInt, bedCentimeterGridImage.Height, RGBA_Bytes.Black); graphics2D.DrawString(count.ToString(), linePos, 0, pointSize); } } { double lineDist = bedCentimeterGridImage.Height / (double)linesInY; int count = 1; int pointSize = 20; for (double linePos = lineDist; linePos < bedCentimeterGridImage.Height; linePos += lineDist) { count++; int linePosInt = (int)linePos; graphics2D.Line(0, linePosInt, bedCentimeterGridImage.Height, linePosInt, RGBA_Bytes.Black); graphics2D.DrawString(count.ToString(), 0, linePos, pointSize); } } }
void CreateRectangularBedGridImage(int linesInX, int linesInY) { Vector2 bedImageCentimeters = new Vector2(linesInX, linesInY); BedImage = new ImageBuffer(1024, 1024, 32, new BlenderBGRA()); Graphics2D graphics2D = BedImage.NewGraphics2D(); graphics2D.Clear(bedBaseColor); { double lineDist = BedImage.Width / (double)linesInX; int count = 1; int pointSize = 20; graphics2D.DrawString(count.ToString(), 4, 4, pointSize, color: bedMarkingsColor); for (double linePos = lineDist; linePos < BedImage.Width; linePos += lineDist) { count++; int linePosInt = (int)linePos; graphics2D.Line(linePosInt, 0, linePosInt, BedImage.Height, bedMarkingsColor); graphics2D.DrawString(count.ToString(), linePos + 4, 4, pointSize, color: bedMarkingsColor); } } { double lineDist = BedImage.Height / (double)linesInY; int count = 1; int pointSize = 16; for (double linePos = lineDist; linePos < BedImage.Height; linePos += lineDist) { count++; int linePosInt = (int)linePos; graphics2D.Line(0, linePosInt, BedImage.Height, linePosInt, bedMarkingsColor); graphics2D.DrawString(count.ToString(), 4, linePos + 4, pointSize, color: bedMarkingsColor); } } }
//----------------------------------------------------------------------------- // Drawing //----------------------------------------------------------------------------- public void DrawHeartPieces(Graphics2D g) { for (int i = 0; i < 4; i++) { if (i < GameControl.Inventory.PiecesOfHeart) { g.DrawSprite(GameData.SPR_HUD_HEART_PIECES_FULL[i], new Point2I(112, 8)); } else { g.DrawSprite(GameData.SPR_HUD_HEART_PIECES_EMPTY[i], new Point2I(112, 8)); } } g.DrawString(GameData.FONT_SMALL, GameControl.Inventory.PiecesOfHeart.ToString() + "/4", new Point2I(120, 40), new Color(16, 16, 16)); }
public override void OnDraw(Graphics2D graphics2D) { if (needRedraw) { needRedraw = false; rayTraceScene(); } trackBallTransform.AxisToWorld = trackBallController.GetTransform4X4(); graphics2D.FillRectangle(new rect_d(0, 0, 1000, 1000), RGBA_Bytes.Red); graphics2D.Render(destImage, 0, 0); trackBallController.DrawRadius(graphics2D); graphics2D.DrawString("Ray Trace: " + renderTime.ElapsedMilliseconds.ToString(), 20, 10); base.OnDraw(graphics2D); }
public override void Draw() { // draw base DrawWindow(); // draw buttons btnLogon.Draw(); btnRestart.Draw(); btnShutdown.Draw(); txtUser.Draw(); txtPass.Draw(); // draw username text Graphics2D.DrawString(x + 12, y + 36, "Username:"******"Password:", Color.white, Fonts.FONT_MONO); }
//**************************************************************** // Painting - Methods for painting a PText. //**************************************************************** /// <summary> /// Overridden. See <see cref="PNode.Paint">PNode.Paint</see>. /// </summary> protected override void Paint(UMD.HCIL.PocketPiccolo.Util.PPaintContext paintContext) { base.Paint(paintContext); if (text != null && textBrush != null && font != null) { Graphics2D g = paintContext.Graphics; float renderedFontSize = font.Size * paintContext.Scale; //font.SizeInPoints * paintContext.Scale; if (renderedFontSize < PUtil.GreekThreshold) { // .NET bug: DrawString throws a generic gdi+ exception when // the scaled font size is very small. So, we will render // the text as a simple rectangle for small fonts g.FillRectangle(textBrush, Bounds); } else if (renderedFontSize < PUtil.MaxFontSize) { g.DrawString(text, font, textBrush, Bounds); //, stringFormat); } } }
public override void Draw() { // draw base DrawWindow(); // draw msg if (msg.Length > 0) { Graphics2D.DrawString(x + (width / 2) - (textW / 2), this.y + (height / 2) - 5, msg, Color.white, Fonts.FONT_MONO); } if (resultType == DialogResult.okCancel) { btnOK.Draw(); btnCancel.Draw(); } if (resultType == DialogResult.ok) { btnOK.Draw(); } if (resultType == DialogResult.yesNo) { btnYes.Draw(); btnNo.Draw(); } }
public void DrawWindow() { if (state == WindowState.maximized) { } if (state != WindowState.minimized) { // draw bg Graphics2D.FillRectangle(boundsUsable, backColor); Graphics2D.DrawRectangle(new Rectangle(boundsUsable.x, boundsUsable.y, boundsUsable.width, boundsUsable.height + 1), 1, Color.silver); // draw title bar Graphics2D.FillRectangle(tbBounds, Color.gray32); // draw title Graphics2D.DrawString(x + 8, y + 6, title, Color.white, Fonts.FONT_MONO); // draw buttons if (exitBox) { btnClose.Draw(); } if (maximizeBox) { btnMax.Draw(); } if (minimizeBox) { btnMin.Draw(); } // draw title bar border Graphics2D.DrawRectangle(tbBounds, 1, Color.silver); } }
public void Draw(Graphics2D graphics2D, double x, double y) { graphics2D.DrawString("{0}ms {1:0.0}mb".FormatWith(GetAverage(), GC.GetTotalMemory(false) / 1000000), x, y, 16, color: RGBA_Bytes.White, drawFromHintedCach: true); }
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); } } }
void createThumbnailWorker_DoWork(object sender, DoWorkEventArgs e) { PartThumbnailWidget thumbnailWidget = e.Argument as PartThumbnailWidget; if (thumbnailWidget != null) { if (thumbnailWidget.printItem == null) { thumbnailWidget.thumbnailImage = new ImageBuffer(thumbnailWidget.noThumbnailImage); thumbnailWidget.Invalidate(); return; } if (thumbnailWidget.PrintItem.FileLocation == QueueData.SdCardFileName) { switch (thumbnailWidget.Size) { case ImageSizes.Size115x115: { StaticData.Instance.LoadIcon(Path.ChangeExtension("icon_sd_card_115x115", partExtension), thumbnailWidget.thumbnailImage); } break; case ImageSizes.Size50x50: { StaticData.Instance.LoadIcon(Path.ChangeExtension("icon_sd_card_50x50", partExtension), thumbnailWidget.thumbnailImage); } break; default: throw new NotImplementedException(); } thumbnailWidget.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA()); Graphics2D graphics = thumbnailWidget.thumbnailImage.NewGraphics2D(); Ellipse outline = new Ellipse(new Vector2(Width / 2.0, Height / 2.0), Width / 2 - Width / 12); graphics.Render(new Stroke(outline, Width / 12), RGBA_Bytes.White); UiThread.RunOnIdle(thumbnailWidget.EnsureImageUpdated); return; } else if (Path.GetExtension(thumbnailWidget.PrintItem.FileLocation).ToUpper() == ".GCODE") { CreateImage(thumbnailWidget, Width, Height); thumbnailWidget.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA()); Graphics2D graphics = thumbnailWidget.thumbnailImage.NewGraphics2D(); Vector2 center = new Vector2(Width / 2.0, Height / 2.0); Ellipse outline = new Ellipse(center, Width / 2 - Width / 12); graphics.Render(new Stroke(outline, Width / 12), RGBA_Bytes.White); graphics.DrawString("GCode", center.x, center.y, 8 * Width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White); UiThread.RunOnIdle(thumbnailWidget.EnsureImageUpdated); return; } else if (!File.Exists(thumbnailWidget.PrintItem.FileLocation)) { CreateImage(thumbnailWidget, Width, Height); thumbnailWidget.thumbnailImage.SetRecieveBlender(new BlenderPreMultBGRA()); Graphics2D graphics = thumbnailWidget.thumbnailImage.NewGraphics2D(); Vector2 center = new Vector2(Width / 2.0, Height / 2.0); graphics.DrawString("Missing", center.x, center.y, 8 * Width / 50, Agg.Font.Justification.Center, Agg.Font.Baseline.BoundsCenter, color: RGBA_Bytes.White); UiThread.RunOnIdle(thumbnailWidget.EnsureImageUpdated); return; } string stlHashCode = thumbnailWidget.PrintItem.FileHashCode.ToString(); Point2D bigRenderSize = new Point2D(460, 460); ImageBuffer bigRender = LoadImageFromDisk(thumbnailWidget, stlHashCode, bigRenderSize); if (bigRender == null) { if (!File.Exists(thumbnailWidget.PrintItem.FileLocation)) { return; } List <MeshGroup> loadedMeshGroups = MeshFileIo.Load(thumbnailWidget.PrintItem.FileLocation); thumbnailWidget.thumbnailImage = new ImageBuffer(thumbnailWidget.buildingThumbnailImage); thumbnailWidget.thumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); bigRender = BuildImageFromMeshGroups(loadedMeshGroups, stlHashCode, bigRenderSize); if (bigRender == null) { bigRender = new ImageBuffer(thumbnailWidget.noThumbnailImage); } } switch (thumbnailWidget.Size) { case ImageSizes.Size50x50: { ImageBuffer halfWay1 = new ImageBuffer(200, 200, 32, new BlenderBGRA()); halfWay1.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); halfWay1.NewGraphics2D().Render(bigRender, 0, 0, 0, (double)halfWay1.Width / bigRender.Width, (double)halfWay1.Height / bigRender.Height); ImageBuffer halfWay2 = new ImageBuffer(100, 100, 32, new BlenderBGRA()); halfWay2.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); halfWay2.NewGraphics2D().Render(halfWay1, 0, 0, 0, (double)halfWay2.Width / halfWay1.Width, (double)halfWay2.Height / halfWay1.Height); thumbnailWidget.thumbnailImage = new ImageBuffer((int)Width, (int)Height, 32, new BlenderBGRA()); thumbnailWidget.thumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); thumbnailWidget.thumbnailImage.NewGraphics2D().Render(halfWay2, 0, 0, 0, (double)thumbnailWidget.thumbnailImage.Width / halfWay2.Width, (double)thumbnailWidget.thumbnailImage.Height / halfWay2.Height); } break; case ImageSizes.Size115x115: { ImageBuffer halfWay1 = new ImageBuffer(230, 230, 32, new BlenderBGRA()); halfWay1.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); halfWay1.NewGraphics2D().Render(bigRender, 0, 0, 0, (double)halfWay1.Width / bigRender.Width, (double)halfWay1.Height / bigRender.Height); thumbnailWidget.thumbnailImage = new ImageBuffer((int)Width, (int)Height, 32, new BlenderBGRA()); thumbnailWidget.thumbnailImage.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255, 0)); thumbnailWidget.thumbnailImage.NewGraphics2D().Render(halfWay1, 0, 0, 0, (double)thumbnailWidget.thumbnailImage.Width / halfWay1.Width, (double)thumbnailWidget.thumbnailImage.Height / halfWay1.Height); } break; default: throw new NotImplementedException(); } UiThread.RunOnIdle(thumbnailWidget.EnsureImageUpdated); } }
//----------------------------------------------------------------------------- // Virtual //----------------------------------------------------------------------------- // Draws the item inside the inventory. public override void DrawSlot(Graphics2D g, Point2I position, int lightOrDark) { g.DrawSprite(sprite, position + new Point2I(4, 0)); g.DrawString(GameData.FONT_SMALL, Amount.ToString("00"), position + new Point2I(0, 12), new Color(248, 248, 248)); }
public void paint(Graphics2D graphics){ Rectangle2D anchor = _shape.GetLogicalAnchor2D(); TextElement[] elem = GetTextElements((float)anchor.Width, graphics.GetFontRenderContext()); if(elem == null) return; float textHeight = 0; for (int i = 0; i < elem.Length; i++) { textHeight += elem[i].ascent + elem[i].descent; } int valign = _shape.GetVerticalAlignment(); double y0 = anchor.GetY(); switch (valign){ case TextShape.AnchorTopBaseline: case TextShape.AnchorTop: y0 += _shape.GetMarginTop(); break; case TextShape.AnchorBottom: y0 += anchor.Height - textHeight - _shape.GetMarginBottom(); break; default: case TextShape.AnchorMiddle: float delta = (float)anchor.Height - textHeight - _shape.GetMarginTop() - _shape.GetMarginBottom(); y0 += _shape.GetMarginTop() + delta/2; break; } //finally Draw the text fragments for (int i = 0; i < elem.Length; i++) { y0 += elem[i].ascent; Point2D.Double pen = new Point2D.Double(); pen.y = y0; switch (elem[i]._align) { default: case TextShape.AlignLeft: pen.x = anchor.GetX() + _shape.GetMarginLeft(); break; case TextShape.AlignCenter: pen.x = anchor.GetX() + _shape.GetMarginLeft() + (anchor.Width - elem[i].advance - _shape.GetMarginLeft() - _shape.GetMarginRight()) / 2; break; case TextShape.AlignRight: pen.x = anchor.GetX() + _shape.GetMarginLeft() + (anchor.Width - elem[i].advance - _shape.GetMarginLeft() - _shape.GetMarginRight()); break; } if(elem[i]._bullet != null){ graphics.DrawString(elem[i]._bullet.GetIterator(), (float)(pen.x + elem[i]._bulletOffset), (float)pen.y); } AttributedCharacterIterator chIt = elem[i]._text.GetIterator(); if(chIt.GetEndIndex() > chIt.GetBeginIndex()) { graphics.DrawString(chIt, (float)(pen.x + elem[i]._textOffset), (float)pen.y); } y0 += elem[i].descent; } }
public override void OnDraw(Graphics2D graphics2D) { var inverseScale = 1 / scalingFactor; var offset = Vector2.Zero; //graphics2D.PushTransform(); // Reset to zero var existing = graphics2D.GetTransform(); existing.translation(out double x, out double y); offset.X += x; offset.Y += y; // Center if (this.Width > this.Height) { offset.X += (this.Width / 2) - (bedBounds.Width * scalingFactor / 2); } else { offset.Y += (this.Height / 2) - (bedBounds.Height * scalingFactor / 2); } // Offset considering bed bounds offset.X -= bedBounds.Left * scalingFactor; offset.Y -= bedBounds.Bottom * scalingFactor; // Apply transform graphics2D.SetTransform(Affine.NewScaling(scalingFactor) * Affine.NewTranslation(offset)); // Draw the bed this.RenderBed(graphics2D); // Build hotend path if (this.RenderProbePath) { this.RenderProbingPath(graphics2D); } if (this.RenderLevelingData) { if (currentLevelingFunctions == null) { PrintLevelingData levelingData = printer.Settings.Helpers.GetPrintLevelingData(); currentLevelingFunctions = new LevelingFunctions(printer, levelingData); } var levelingTriangles = new VertexStorage(); foreach (var region in currentLevelingFunctions.Regions) { levelingTriangles.MoveTo(region.V0.X, region.V0.Y); levelingTriangles.LineTo(region.V1.X, region.V1.Y); levelingTriangles.LineTo(region.V2.X, region.V2.Y); levelingTriangles.LineTo(region.V0.X, region.V0.Y); } graphics2D.Render( new Stroke(levelingTriangles), opaqueMinimumAccent); } // Render probe points int i = 0; foreach (var position in probePoints) { var center = new Vector2(position.X, position.Y); var circleColor = lightColor; if (this.SimplePoints) { graphics2D.Render( new Ellipse(center, 4 * inverseScale), opaqueMinimumAccent); } else { if (i < this.ActiveProbeIndex) { circleColor = opaqueMinimumAccent; } else if (i == this.ActiveProbeIndex) { circleColor = opaqueAccent; } graphics2D.Render( new Ellipse(center, 8 * inverseScale), circleColor); graphics2D.DrawString( $"{1 + i++}", center.X, center.Y, justification: Agg.Font.Justification.Center, baseline: Agg.Font.Baseline.BoundsCenter, pointSize: theme.FontSize7 * inverseScale, color: theme.TextColor); } } //graphics2D.PopTransform(); base.OnDraw(graphics2D); }
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); }