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(); }
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)); } }