public void ScrollingToEndShowsEnd() { GuiWidget container = new GuiWidget(); container.DoubleBuffer = true; container.LocalBounds = new RectangleDouble(0, 0, 110, 30); TextEditWidget editField1 = new TextEditWidget("This is a nice long text string", 0, 0, pixelWidth: 100); container.AddChild(editField1); TextWidget firstWordText = new TextWidget("This"); RectangleDouble bounds = firstWordText.LocalBounds; bounds.Offset(bounds.Left, bounds.Bottom); firstWordText.LocalBounds = bounds; firstWordText.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White); firstWordText.OnDraw(firstWordText.BackBuffer.NewGraphics2D()); TextWidget lastWordText = new TextWidget("string"); bounds = lastWordText.LocalBounds; bounds.Offset(bounds.Left, bounds.Bottom); lastWordText.LocalBounds = bounds; lastWordText.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White); lastWordText.OnDraw(lastWordText.BackBuffer.NewGraphics2D()); container.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White); container.BackgroundColor = RGBA_Bytes.White; container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0)); container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 0, 1, 1, 0)); Assert.IsTrue(editField1.ContainsFocus == true); container.OnDraw(container.BackBuffer.NewGraphics2D()); OutputImage(firstWordText.BackBuffer, "Control - Left.tga"); OutputImage(lastWordText.BackBuffer, "Control - Right.tga"); OutputImage(container.BackBuffer, "Test - Start.tga"); Vector2 bestPosition; double bestLeastSquares; container.BackBuffer.FindLeastSquaresMatch(firstWordText.BackBuffer, out bestPosition, out bestLeastSquares); Assert.IsTrue(bestLeastSquares < 2000000); container.BackBuffer.FindLeastSquaresMatch(lastWordText.BackBuffer, out bestPosition, out bestLeastSquares); Assert.IsTrue(bestLeastSquares > 2000000); SendKeyDown(Keys.End, container); container.OnDraw(container.BackBuffer.NewGraphics2D()); OutputImage(container.BackBuffer, "Test - Scrolled.tga"); container.BackBuffer.FindLeastSquaresMatch(firstWordText.BackBuffer, out bestPosition, out bestLeastSquares); Assert.IsTrue(bestLeastSquares > 2000000); container.BackBuffer.FindLeastSquaresMatch(lastWordText.BackBuffer, out bestPosition, out bestLeastSquares); Assert.IsTrue(bestLeastSquares < 2000000); container.Close(); }
private double PrintTopOfPage(ImageBuffer plateInventoryImage, Graphics2D plateGraphics) { plateGraphics.Clear(Color.White); double currentlyPrintingHeightPixels = plateInventoryImage.Height - PageMarginMM.Top * PixelPerMM; string logoPathAndFile = Path.Combine("Images", "PartSheetLogo.png"); if (StaticData.Instance.FileExists(logoPathAndFile)) { ImageBuffer logoImage = StaticData.Instance.LoadImage(logoPathAndFile); currentlyPrintingHeightPixels -= logoImage.Height; plateGraphics.Render(logoImage, (plateInventoryImage.Width - logoImage.Width) / 2, currentlyPrintingHeightPixels); } currentlyPrintingHeightPixels -= PartPaddingPixels; double underlineHeightMM = 1; var lineBounds = new RectangleDouble(0, 0, plateInventoryImage.Width - PageMarginPixels.Left * 2, underlineHeightMM * PixelPerMM); lineBounds.Offset(PageMarginPixels.Left, currentlyPrintingHeightPixels - lineBounds.Height); plateGraphics.FillRectangle(lineBounds, Color.Black); return(currentlyPrintingHeightPixels - (lineBounds.Height + PartPaddingPixels)); }
private double PrintTopOfPage(ImageBuffer plateInventoryImage, Graphics2D plateGraphics) { plateGraphics.Clear(RGBA_Bytes.White); double currentlyPrintingHeightPixels = plateInventoryImage.Height - PageMarginMM.Top * PixelPerMM; string logoPathAndFile = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "PartSheetLogo.png"); if (File.Exists(logoPathAndFile)) { ImageBuffer logoImage = new ImageBuffer(); ImageBMPIO.LoadImageData(logoPathAndFile, logoImage); currentlyPrintingHeightPixels -= logoImage.Height; plateGraphics.Render(logoImage, (plateInventoryImage.Width - logoImage.Width) / 2, currentlyPrintingHeightPixels); } currentlyPrintingHeightPixels -= PartPaddingPixels; double underlineHeightMM = 1; RectangleDouble lineBounds = new RectangleDouble(0, 0, plateInventoryImage.Width - PageMarginPixels.Left * 2, underlineHeightMM * PixelPerMM); lineBounds.Offset(PageMarginPixels.Left, currentlyPrintingHeightPixels - lineBounds.Height); plateGraphics.FillRectangle(lineBounds, RGBA_Bytes.Black); return(currentlyPrintingHeightPixels - (lineBounds.Height + PartPaddingPixels)); }
private double PrintTopOfPage(ImageBuffer plateInventoryImage, Graphics2D plateGraphics) { plateGraphics.Clear(RGBA_Bytes.White); double currentlyPrintingHeightPixels = plateInventoryImage.Height - PageMarginMM.Top * PixelPerMM; // TODO: Application should not save data back to StaticDataPath - use application data dir instead string logoPathAndFile = "PartSheetLogo.png"; if (StaticData.Instance.FileExists(logoPathAndFile)) { ImageBuffer logoImage = StaticData.Instance.LoadImage(logoPathAndFile); currentlyPrintingHeightPixels -= logoImage.Height; plateGraphics.Render(logoImage, (plateInventoryImage.Width - logoImage.Width) / 2, currentlyPrintingHeightPixels); } currentlyPrintingHeightPixels -= PartPaddingPixels; double underlineHeightMM = 1; RectangleDouble lineBounds = new RectangleDouble(0, 0, plateInventoryImage.Width - PageMarginPixels.Left * 2, underlineHeightMM * PixelPerMM); lineBounds.Offset(PageMarginPixels.Left, currentlyPrintingHeightPixels - lineBounds.Height); plateGraphics.FillRectangle(lineBounds, RGBA_Bytes.Black); return(currentlyPrintingHeightPixels - (lineBounds.Height + PartPaddingPixels)); }
public void CenterBothOffsetBoundsTest(BorderDouble controlPadding, BorderDouble buttonMargin) { GuiWidget containerControl = new GuiWidget(200, 300); containerControl.Padding = controlPadding; containerControl.DoubleBuffer = true; GuiWidget controlRectangle = new GuiWidget(100, 100); controlRectangle.BackgroundColor = RGBA_Bytes.Red; controlRectangle.Margin = buttonMargin; double controlCenterX = controlPadding.Left + (containerControl.Width - controlPadding.Left - controlPadding.Right) / 2; double buttonX = controlCenterX - (controlRectangle.Width + controlRectangle.Margin.Left + controlRectangle.Margin.Right) / 2 + controlRectangle.Margin.Left; double controlCenterY = controlPadding.Bottom + (containerControl.Height - controlPadding.Bottom - controlPadding.Top) / 2 + controlRectangle.Margin.Bottom; double buttonY = controlCenterY - (controlRectangle.Height + controlRectangle.Margin.Bottom + controlRectangle.Margin.Top) / 2; controlRectangle.OriginRelativeParent = new VectorMath.Vector2(buttonX, buttonY); containerControl.AddChild(controlRectangle); containerControl.OnDraw(containerControl.NewGraphics2D()); GuiWidget containerTest = new GuiWidget(200, 300); containerTest.Padding = controlPadding; containerTest.DoubleBuffer = true; GuiWidget testRectangle = new GuiWidget(100, 100); RectangleDouble offsetBounds = testRectangle.LocalBounds; offsetBounds.Offset(-10, -10); testRectangle.LocalBounds = offsetBounds; testRectangle.BackgroundColor = RGBA_Bytes.Red; testRectangle.Margin = buttonMargin; testRectangle.VAnchor = VAnchor.ParentCenter; testRectangle.HAnchor = HAnchor.ParentCenter; containerTest.AddChild(testRectangle); containerTest.OnDraw(containerTest.NewGraphics2D()); OutputImages(containerControl, containerTest); Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one."); Assert.IsTrue(containerControl.BackBuffer == containerTest.BackBuffer, "The Anchored widget should be in the correct place."); }
public RectangleDouble TransformToScreenSpace(RectangleDouble rectangleToTransform) { GuiWidget prevGUIWidget = this; while (prevGUIWidget != null) { rectangleToTransform.Offset(prevGUIWidget.OriginRelativeParent); prevGUIWidget = prevGUIWidget.Parent; } return rectangleToTransform; }
public RectangleDouble TransformToParentSpace(GuiWidget parentToGetRelativeTo, RectangleDouble rectangleToTransform) { GuiWidget widgetToTransformBy = this; while (widgetToTransformBy != null && widgetToTransformBy != parentToGetRelativeTo) { rectangleToTransform.Offset(widgetToTransformBy.OriginRelativeParent); widgetToTransformBy = widgetToTransformBy.Parent; } return rectangleToTransform; }
public virtual void Invalidate(RectangleDouble rectToInvalidate) { isCurrentlyInvalid = true; if (Parent != null) { rectToInvalidate.Offset(OriginRelativeParent); Parent.Invalidate(rectToInvalidate); } if (Invalidated != null) { Invalidated(this, new InvalidateEventArgs(rectToInvalidate)); } }
public void BuildTemplate(GCodeSketch gcodeSketch, bool verticalLayout) { gcodeSketch.SetTool("T0"); gcodeSketch.WriteRaw($"G1 Z0.2 F{firstLayerSpeed}"); if (verticalLayout) { gcodeSketch.Transform = Affine.NewRotation(MathHelper.DegreesToRadians(90)) * Affine.NewTranslation(105, 45); } else { gcodeSketch.Transform = Affine.NewTranslation(75, 175); } var rect = new RectangleDouble(0, 0, 123, 30); var originalRect = rect; int towerSize = 10; gcodeSketch.Speed = firstLayerSpeed; double y1 = rect.Bottom; gcodeSketch.MoveTo(rect.Left, y1); var towerRect = new RectangleDouble(0, 0, towerSize, towerSize); towerRect.Offset(originalRect.Left - towerSize, originalRect.Bottom); // Prime this.PrimeHotend(gcodeSketch, towerRect); // Perimeters rect = this.CreatePerimeters(gcodeSketch, rect); double x, y2, y3; double sectionHeight = rect.Height / 2; bool up = true; var step = (rect.Width - 3) / 40; if (!this.DebugMode) { y1 = rect.YCenter + (nozzleWidth / 2); // Draw centerline gcodeSketch.MoveTo(rect.Left, y1); gcodeSketch.LineTo(rect.Right, y1); y1 += nozzleWidth; gcodeSketch.MoveTo(rect.Right, y1); gcodeSketch.LineTo(rect.Left, y1); y1 -= nozzleWidth / 2; x = rect.Left + 1.5; y2 = y1 - sectionHeight - (nozzleWidth * 1.5); y3 = y2 - 5; bool drawGlpyphs = false; // Draw calibration lines for (var i = 0; i <= 40; i++) { gcodeSketch.MoveTo(x, up ? y1 : y2); if ((i % 5 == 0)) { gcodeSketch.LineTo(x, y3); var currentPos = gcodeSketch.CurrentPosition; gcodeSketch.Speed = 500; PrintLineEnd(gcodeSketch, drawGlpyphs, i, currentPos); gcodeSketch.Speed = 1800; gcodeSketch.MoveTo(x, y3); gcodeSketch.MoveTo(x, y2); } gcodeSketch.LineTo(x, up ? y2 : y1); x = x + step; up = !up; } } x = rect.Left + 1.5; y1 = rect.Top + (nozzleWidth * .5); y2 = y1 - sectionHeight + (nozzleWidth * .5); gcodeSketch.SetTool("T1"); gcodeSketch.MoveTo(rect.Left, rect.Top); gcodeSketch.PenDown(); towerRect = new RectangleDouble(0, 0, towerSize, towerSize); towerRect.Offset(originalRect.Left - towerSize, originalRect.Top - towerSize); // Prime this.PrimeHotend(gcodeSketch, towerRect); if (this.DebugMode) { // Perimeters rect = this.CreatePerimeters(gcodeSketch, rect); } else { up = true; // Draw calibration lines for (var i = 0; i <= 40; i++) { gcodeSketch.MoveTo(x + activeOffsets[i], up ? y1 : y2, retract: true); gcodeSketch.LineTo(x + activeOffsets[i], up ? y2 : y1); x = x + step; up = !up; } } gcodeSketch.PenUp(); }
public void AnchorLeftBottomTests() { // bottom left. this is the easiest as there should be nothing to it. { GuiWidget containerNoAnchor = new GuiWidget(300, 200); containerNoAnchor.DoubleBuffer = true; Button positionedButton = new Button("button"); containerNoAnchor.AddChild(positionedButton); containerNoAnchor.OnDraw(containerNoAnchor.NewGraphics2D()); GuiWidget containerAnchor = new GuiWidget(300, 200); containerAnchor.DoubleBuffer = true; Button anchoredButton = new Button("button"); anchoredButton.Margin = new BorderDouble(); // make sure we have no margin containerAnchor.AddChild(anchoredButton); anchoredButton.HAnchor = HAnchor.ParentLeft; anchoredButton.VAnchor = VAnchor.ParentBottom; containerAnchor.OnDraw(containerAnchor.NewGraphics2D()); OutputImages(containerNoAnchor, containerAnchor); Assert.IsTrue(containerNoAnchor.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one."); Assert.IsTrue(containerNoAnchor.BackBuffer == containerAnchor.BackBuffer, "The Anchored widget should be in the correct place."); } // bottom left with some crazy localBounds. { GuiWidget containerNoAnchor = new GuiWidget(300, 200); containerNoAnchor.DoubleBuffer = true; Button positionedButton = new Button("button"); RectangleDouble positionedButtonBounds = positionedButton.LocalBounds; positionedButtonBounds.Offset(-10, -10); positionedButton.LocalBounds = positionedButtonBounds; positionedButton.OriginRelativeParent = new VectorMath.Vector2(10, 10); containerNoAnchor.AddChild(positionedButton); containerNoAnchor.OnDraw(containerNoAnchor.NewGraphics2D()); GuiWidget containerAnchor = new GuiWidget(300, 200); containerAnchor.DoubleBuffer = true; Button anchoredButton = new Button("button"); RectangleDouble anchoredButtonBounds = anchoredButton.LocalBounds; anchoredButtonBounds.Offset(-10, -10); anchoredButton.LocalBounds = anchoredButtonBounds; anchoredButton.Margin = new BorderDouble(); // make sure we have no margin containerAnchor.AddChild(anchoredButton); anchoredButton.HAnchor = HAnchor.ParentLeft; anchoredButton.VAnchor = VAnchor.ParentBottom; containerAnchor.OnDraw(containerAnchor.NewGraphics2D()); OutputImages(containerNoAnchor, containerAnchor); Assert.IsTrue(containerNoAnchor.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one."); Assert.IsTrue(containerNoAnchor.BackBuffer == containerAnchor.BackBuffer, "The Anchored widget should be in the correct place."); } // bottom left, respect margin. this is the easiest as there should be nothing to it. { GuiWidget containerNoAnchor = new GuiWidget(300, 200); containerNoAnchor.DoubleBuffer = true; Button positionedButton = new Button("button"); containerNoAnchor.AddChild(positionedButton); positionedButton.OriginRelativeParent = new VectorMath.Vector2(5, 5); containerNoAnchor.OnDraw(containerNoAnchor.NewGraphics2D()); GuiWidget containerAnchor = new GuiWidget(300, 200); containerAnchor.DoubleBuffer = true; Button anchoredButton = new Button("button"); containerAnchor.AddChild(anchoredButton); anchoredButton.Margin = new BorderDouble(5); anchoredButton.HAnchor = HAnchor.ParentLeft; anchoredButton.VAnchor = VAnchor.ParentBottom; containerAnchor.OnDraw(containerAnchor.NewGraphics2D()); OutputImages(containerNoAnchor, containerAnchor); Assert.IsTrue(containerNoAnchor.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one."); Assert.IsTrue(containerNoAnchor.BackBuffer == containerAnchor.BackBuffer, "The Anchored widget should be in the correct place."); } // bottom left, respect margin and padding. this is the easiest as there should be nothing to it. { GuiWidget containerNoAnchor = new GuiWidget(300, 200); containerNoAnchor.DoubleBuffer = true; Button positionedButton = new Button("button"); containerNoAnchor.AddChild(positionedButton); positionedButton.OriginRelativeParent = new VectorMath.Vector2(8, 8); containerNoAnchor.OnDraw(containerNoAnchor.NewGraphics2D()); GuiWidget containerAnchor = new GuiWidget(300, 200); containerAnchor.Padding = new BorderDouble(3); containerAnchor.DoubleBuffer = true; Button anchoredButton = new Button("button"); containerAnchor.AddChild(anchoredButton); anchoredButton.Margin = new BorderDouble(5); anchoredButton.HAnchor = HAnchor.ParentLeft; anchoredButton.VAnchor = VAnchor.ParentBottom; containerAnchor.OnDraw(containerAnchor.NewGraphics2D()); OutputImages(containerNoAnchor, containerAnchor); Assert.IsTrue(containerNoAnchor.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one."); Assert.IsTrue(containerNoAnchor.BackBuffer == containerAnchor.BackBuffer, "The Anchored widget should be in the correct place."); } // bottom left, respect margin. This time we set the Margin after the AnchorFlags. { GuiWidget containerNoAnchor = new GuiWidget(300, 200); containerNoAnchor.DoubleBuffer = true; Button positionedButton = new Button("button"); containerNoAnchor.AddChild(positionedButton); positionedButton.OriginRelativeParent = new VectorMath.Vector2(5, 5); containerNoAnchor.OnDraw(containerNoAnchor.NewGraphics2D()); GuiWidget containerAnchor = new GuiWidget(300, 200); containerAnchor.DoubleBuffer = true; Button anchoredButton = new Button("button"); containerAnchor.AddChild(anchoredButton); anchoredButton.HAnchor = HAnchor.ParentLeft; anchoredButton.VAnchor = VAnchor.ParentBottom; anchoredButton.Margin = new BorderDouble(5); containerAnchor.OnDraw(containerAnchor.NewGraphics2D()); OutputImages(containerNoAnchor, containerAnchor); Assert.IsTrue(containerNoAnchor.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one."); Assert.IsTrue(containerNoAnchor.BackBuffer == containerAnchor.BackBuffer, "The Anchored widget should be in the correct place."); } }
public RectangleDouble TransformToParentSpace(GuiWidget parentToGetRelativeTo, RectangleDouble rectangleToTransform) { GuiWidget parent = Parent; while (parent != null && parent != parentToGetRelativeTo) { rectangleToTransform.Offset(parent.OriginRelativeParent); parent = parent.Parent; } return rectangleToTransform; }