本文整理汇总了C#中GuiWidget.OnDraw方法的典型用法代码示例。如果您正苦于以下问题:C# GuiWidget.OnDraw方法的具体用法?C# GuiWidget.OnDraw怎么用?C# GuiWidget.OnDraw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuiWidget
的用法示例。
在下文中一共展示了GuiWidget.OnDraw方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BottomAndTopTextControl
public void BottomAndTopTextControl(double controlPadding, double buttonMargin)
{
GuiWidget containerControl = new GuiWidget(200, 300);
containerControl.DoubleBuffer = true;
containerControl.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
TextWidget controlButton1 = new TextWidget("text1");
controlButton1.Margin = new BorderDouble(buttonMargin);
controlButton1.OriginRelativeParent = new VectorMath.Vector2(-controlButton1.LocalBounds.Left, -controlButton1.LocalBounds.Bottom + controlPadding + buttonMargin);
controlButton1.LocalBounds = new RectangleDouble(controlButton1.LocalBounds.Left, controlButton1.LocalBounds.Bottom, controlButton1.LocalBounds.Right, controlButton1.LocalBounds.Bottom + containerControl.Height - (controlPadding + buttonMargin) * 2);
containerControl.AddChild(controlButton1);
containerControl.OnDraw(containerControl.NewGraphics2D());
GuiWidget containerTest = new GuiWidget(200, 200);
containerTest.Padding = new BorderDouble(controlPadding);
containerTest.DoubleBuffer = true;
containerTest.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
TextWidget testButton1 = new TextWidget("text1");
testButton1.Margin = new BorderDouble(buttonMargin);
testButton1.VAnchor = VAnchor.ParentBottom | VAnchor.ParentTop;
containerTest.AddChild(testButton1);
containerTest.OnDraw(containerTest.NewGraphics2D());
OutputImages(containerControl, containerTest);
// now change it's size
containerTest.LocalBounds = containerControl.LocalBounds;
containerTest.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
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.");
}
示例2: TextWidgetVisibleTest
public void TextWidgetVisibleTest()
{
{
GuiWidget rectangleWidget = new GuiWidget(100, 50);
TextWidget itemToAdd = new TextWidget("test Item", 10, 10);
rectangleWidget.AddChild(itemToAdd);
rectangleWidget.DoubleBuffer = true;
rectangleWidget.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
rectangleWidget.OnDraw(rectangleWidget.BackBuffer.NewGraphics2D());
ImageBuffer textOnly = new ImageBuffer(75, 20, 32, new BlenderBGRA());
textOnly.NewGraphics2D().Clear(RGBA_Bytes.White);
textOnly.NewGraphics2D().DrawString("test Item", 1, 1);
if (saveImagesForDebug)
{
ImageTgaIO.Save(rectangleWidget.BackBuffer, "-rectangleWidget.tga");
//ImageTgaIO.Save(itemToAdd.Children[0].BackBuffer, "-internalTextWidget.tga");
ImageTgaIO.Save(textOnly, "-textOnly.tga");
}
Assert.IsTrue(rectangleWidget.BackBuffer.FindLeastSquaresMatch(textOnly, 1), "TextWidgets need to be drawing.");
rectangleWidget.Close();
}
{
GuiWidget rectangleWidget = new GuiWidget(100, 50);
TextEditWidget itemToAdd = new TextEditWidget("test Item", 10, 10);
rectangleWidget.AddChild(itemToAdd);
rectangleWidget.DoubleBuffer = true;
rectangleWidget.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
rectangleWidget.OnDraw(rectangleWidget.BackBuffer.NewGraphics2D());
ImageBuffer textOnly = new ImageBuffer(75, 20, 32, new BlenderBGRA());
textOnly.NewGraphics2D().Clear(RGBA_Bytes.White);
TypeFacePrinter stringPrinter = new TypeFacePrinter("test Item", 12);
IVertexSource offsetText = new VertexSourceApplyTransform(stringPrinter, Affine.NewTranslation(1, -stringPrinter.LocalBounds.Bottom));
textOnly.NewGraphics2D().Render(offsetText, RGBA_Bytes.Black);
if (saveImagesForDebug)
{
ImageTgaIO.Save(rectangleWidget.BackBuffer, "-rectangleWidget.tga");
//ImageTgaIO.Save(itemToAdd.Children[0].BackBuffer, "-internalTextWidget.tga");
ImageTgaIO.Save(textOnly, "-textOnly.tga");
}
Assert.IsTrue(rectangleWidget.BackBuffer.FindLeastSquaresMatch(textOnly, 1), "TextWidgets need to be drawing.");
rectangleWidget.Close();
}
}
示例3: LimitScrolToContetsTests
public void LimitScrolToContetsTests()
{
GuiWidget containerControl = new GuiWidget(200, 200);
containerControl.DoubleBuffer = true;
containerControl.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
containerControl.OnDraw(containerControl.NewGraphics2D());
ScrollableWidget containerTest = new ScrollableWidget(200, 200);
containerTest.DoubleBuffer = true;
containerTest.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
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.");
}
示例4: TopBottomWithAnchorBottomTopChildTest
public void TopBottomWithAnchorBottomTopChildTest(BorderDouble controlPadding, BorderDouble buttonMargin)
{
double buttonSize = 40;
GuiWidget containerControl = new GuiWidget(buttonSize * 3, buttonSize * 8);
containerControl.Padding = controlPadding;
containerControl.DoubleBuffer = true;
RectangleDouble[] eightControlRectangles = new RectangleDouble[8];
RGBA_Bytes[] eightColors = new RGBA_Bytes[] { RGBA_Bytes.Red, RGBA_Bytes.Orange, RGBA_Bytes.Yellow, RGBA_Bytes.YellowGreen, RGBA_Bytes.Green, RGBA_Bytes.Blue, RGBA_Bytes.Indigo, RGBA_Bytes.Violet };
{
double currentBottom = containerControl.Height - controlPadding.Top - buttonMargin.Top - buttonSize;
double buttonWidthWithMargin = buttonSize + buttonMargin.Width;
double scalledHeight = (containerControl.Height - controlPadding.Height - buttonMargin.Height * 8 - buttonSize * 2) / 6;
// the bottom unsized rect
eightControlRectangles[0] = new RectangleDouble(
0,
currentBottom,
buttonSize,
currentBottom + buttonSize);
// left anchor
currentBottom -= scalledHeight + buttonMargin.Height;
double leftAnchorX = controlPadding.Left + buttonMargin.Left;
eightControlRectangles[1] = new RectangleDouble(leftAnchorX, currentBottom, leftAnchorX + buttonSize, currentBottom + scalledHeight);
// center anchor
double centerXOfContainer = controlPadding.Left + (containerControl.Width - controlPadding.Width) / 2;
currentBottom -= scalledHeight + buttonMargin.Height;
eightControlRectangles[2] = new RectangleDouble(centerXOfContainer - buttonWidthWithMargin / 2 + buttonMargin.Left, currentBottom, centerXOfContainer + buttonWidthWithMargin / 2 - buttonMargin.Right, currentBottom + scalledHeight);
// right anchor
double rightAnchorX = containerControl.Width - controlPadding.Right - buttonMargin.Right;
currentBottom -= scalledHeight + buttonMargin.Height;
eightControlRectangles[3] = new RectangleDouble(rightAnchorX - buttonSize, currentBottom, rightAnchorX, currentBottom + scalledHeight);
// left center anchor
currentBottom -= scalledHeight + buttonMargin.Height;
eightControlRectangles[4] = new RectangleDouble(leftAnchorX, currentBottom, centerXOfContainer - buttonMargin.Right, currentBottom + scalledHeight);
// center right anchor
currentBottom -= scalledHeight + buttonMargin.Height;
eightControlRectangles[5] = new RectangleDouble(centerXOfContainer + buttonMargin.Left, currentBottom, rightAnchorX, currentBottom + scalledHeight);
// left right anchor
currentBottom -= scalledHeight + buttonMargin.Height;
eightControlRectangles[6] = new RectangleDouble(leftAnchorX, currentBottom, rightAnchorX, currentBottom + scalledHeight);
// top anchor
currentBottom -= buttonSize + buttonMargin.Height;
eightControlRectangles[7] = new RectangleDouble(0, currentBottom, buttonSize, currentBottom + buttonSize);
Graphics2D graphics = containerControl.NewGraphics2D();
for (int i = 0; i < 8; i++)
{
graphics.FillRectangle(eightControlRectangles[i], eightColors[i]);
}
}
GuiWidget containerTest = new GuiWidget(containerControl.Width, containerControl.Height);
FlowLayoutWidget bottomToTopFlowLayoutAll = new FlowLayoutWidget(FlowDirection.TopToBottom);
containerTest.DoubleBuffer = true;
{
bottomToTopFlowLayoutAll.AnchorAll();
bottomToTopFlowLayoutAll.Padding = controlPadding;
{
GuiWidget top = new GuiWidget(buttonSize, buttonSize);
top.BackgroundColor = RGBA_Bytes.Red;
top.Margin = buttonMargin;
bottomToTopFlowLayoutAll.AddChild(top);
bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentLeft, RGBA_Bytes.Orange));
bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentCenter, RGBA_Bytes.Yellow));
bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentRight, RGBA_Bytes.YellowGreen));
bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentLeftCenter, RGBA_Bytes.Green));
bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentCenterRight, RGBA_Bytes.Blue));
bottomToTopFlowLayoutAll.AddChild(CreateBottomToTopMiddleWidget(buttonMargin, buttonSize, HAnchor.ParentLeftRight, RGBA_Bytes.Indigo));
GuiWidget bottom = new GuiWidget(buttonSize, buttonSize);
bottom.BackgroundColor = RGBA_Bytes.Violet;
bottom.Margin = buttonMargin;
bottomToTopFlowLayoutAll.AddChild(bottom);
}
containerTest.AddChild(bottomToTopFlowLayoutAll);
}
containerTest.OnDraw(containerTest.NewGraphics2D());
OutputImages(containerControl, containerTest);
for (int i = 0; i < 8; i++)
{
Assert.IsTrue(eightControlRectangles[i].Equals(bottomToTopFlowLayoutAll.Children[i].BoundsRelativeToParent, .001));
}
Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
// we use a least squares match because the erase background that is setting the widgets is integer pixel based and the fill rectangle is not.
Assert.IsTrue(containerControl.BackBuffer.FindLeastSquaresMatch(containerTest.BackBuffer, 0), "The test and control need to match.");
}
示例5: SingleItemVisibleTest
public void SingleItemVisibleTest()
{
{
ListBox containerListBox = new ListBox(new RectangleDouble(0, 0, 100, 100));
ListBoxTextItem itemToAddToList = new ListBoxTextItem("test Item", "test data for item");
itemToAddToList.Name = "list item";
containerListBox.AddChild(itemToAddToList);
containerListBox.DoubleBuffer = true;
containerListBox.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
containerListBox.OnDraw(containerListBox.BackBuffer.NewGraphics2D());
ImageBuffer textImage = new ImageBuffer(80, 16, 32, new BlenderBGRA());
textImage.NewGraphics2D().Clear(RGBA_Bytes.White);
textImage.NewGraphics2D().DrawString("test Item", 1, 1);
OutputImage(containerListBox.BackBuffer, "test.tga");
OutputImage(textImage, "control.tga");
double maxError = 20000000;
Vector2 bestPosition;
double leastSquares;
containerListBox.BackBuffer.FindLeastSquaresMatch(textImage, out bestPosition, out leastSquares, maxError);
Assert.IsTrue(leastSquares < maxError, "The list box need to be showing the item we added to it.");
}
{
GuiWidget container = new GuiWidget(202, 302);
container.DoubleBuffer = true;
container.NewGraphics2D().Clear(RGBA_Bytes.White);
FlowLayoutWidget leftToRightLayout = new FlowLayoutWidget();
leftToRightLayout.AnchorAll();
{
{
ListBox listBox = new ListBox(new RectangleDouble(0, 0, 200, 300));
//listBox.BackgroundColor = RGBA_Bytes.Red;
listBox.Name = "listBox";
listBox.VAnchor = UI.VAnchor.ParentTop;
listBox.ScrollArea.Margin = new BorderDouble(15);
leftToRightLayout.AddChild(listBox);
for (int i = 0; i < 1; i++)
{
ListBoxTextItem newItem = new ListBoxTextItem("hand" + i.ToString() + ".stl", "c:\\development\\hand" + i.ToString() + ".stl");
newItem.Name = "ListBoxItem" + i.ToString();
listBox.AddChild(newItem);
}
}
}
container.AddChild(leftToRightLayout);
container.OnDraw(container.NewGraphics2D());
ImageBuffer textImage = new ImageBuffer(80, 16, 32, new BlenderBGRA());
textImage.NewGraphics2D().Clear(RGBA_Bytes.White);
textImage.NewGraphics2D().DrawString("hand0.stl", 1, 1);
OutputImage(container.BackBuffer, "control.tga");
OutputImage(textImage, "test.tga");
double maxError = 1000000;
Vector2 bestPosition;
double leastSquares;
container.BackBuffer.FindLeastSquaresMatch(textImage, out bestPosition, out leastSquares, maxError);
Assert.IsTrue(leastSquares < maxError, "The list box need to be showing the item we added to it.");
}
}
示例6: TopToBottomContainerAppliesExpectedMargin
public void TopToBottomContainerAppliesExpectedMargin()
{
int marginSize = 40;
int dimensions = 300;
GuiWidget outerContainer = new GuiWidget(dimensions, dimensions);
FlowLayoutWidget topToBottomContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
{
HAnchor = HAnchor.ParentLeftRight,
VAnchor = UI.VAnchor.ParentBottomTop,
};
outerContainer.AddChild(topToBottomContainer);
GuiWidget childWidget = new GuiWidget()
{
HAnchor = HAnchor.ParentLeftRight,
VAnchor = VAnchor.ParentBottomTop,
Margin = new BorderDouble(marginSize),
BackgroundColor = RGBA_Bytes.Red,
};
topToBottomContainer.AddChild(childWidget);
topToBottomContainer.AnchorAll();
topToBottomContainer.PerformLayout();
outerContainer.DoubleBuffer = true;
outerContainer.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
outerContainer.OnDraw(outerContainer.NewGraphics2D());
// For troubleshooting or visual validation
//saveImagesForDebug = true;
//OutputImages(outerContainer, outerContainer);
var bounds = childWidget.BoundsRelativeToParent;
Assert.IsTrue(bounds.Left == marginSize, "Left margin is incorrect");
Assert.IsTrue(bounds.Right == dimensions - marginSize, "Right margin is incorrect");
Assert.IsTrue(bounds.Top == dimensions - marginSize, "Top margin is incorrect");
Assert.IsTrue(bounds.Bottom == marginSize, "Bottom margin is incorrect");
}
示例7: AddThenDeleteCausesNoVisualChange
public void AddThenDeleteCausesNoVisualChange()
{
GuiWidget container = new GuiWidget();
container.DoubleBuffer = true;
container.LocalBounds = new RectangleDouble(0, 0, 200, 200);
TextEditWidget editField1 = new TextEditWidget("Test", 10, 10, pixelWidth: 50);
container.AddChild(editField1);
container.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
container.OnDraw(container.BackBuffer.NewGraphics2D());
ImageBuffer beforeEditImage = new ImageBuffer(container.BackBuffer);
RectangleDouble beforeLocalBounds = editField1.LocalBounds;
Vector2 beforeOrigin = editField1.OriginRelativeParent;
OutputImage(beforeEditImage, "z text un-edited.tga");
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 10, 10, 0));
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 10, 10, 0));
Assert.IsTrue(editField1.ContainsFocus == true);
SendKey(Keys.B, 'b', container);
Assert.IsTrue(editField1.Text == "bTest", "It should have b a in it.");
RectangleDouble afterBLocalBounds = editField1.LocalBounds;
Assert.IsTrue(beforeLocalBounds.Bottom == afterBLocalBounds.Bottom && beforeLocalBounds.Top == afterBLocalBounds.Top);
SendKey(Keys.Back, ' ', container);
Assert.IsTrue(editField1.Text == "Test", "It should not have b a in it.");
RectangleDouble afterLocalBounds = editField1.LocalBounds;
Vector2 afterOrigin = editField1.OriginRelativeParent;
Assert.IsTrue(beforeLocalBounds == afterLocalBounds);
Assert.IsTrue(beforeOrigin == afterOrigin);
// click off it so the cursor is not in it.
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0));
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0));
Assert.IsTrue(editField1.Focused == false);
container.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
container.OnDraw(container.BackBuffer.NewGraphics2D());
OutputImage(container.BackBuffer, "z text edited.tga");
Assert.IsTrue(container.BackBuffer == beforeEditImage);
}
示例8: NestedLayoutTopToBottomTest
public void NestedLayoutTopToBottomTest(BorderDouble controlPadding, BorderDouble buttonMargin)
{
GuiWidget containerControl = new GuiWidget(300, 200);
containerControl.DoubleBuffer = true;
containerControl.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
{
Button topButtonC = new Button("top button");
Button bottomButtonC = new Button("bottom wide button");
topButtonC.LocalBounds = new RectangleDouble(0, 0, bottomButtonC.LocalBounds.Width, 40);
topButtonC.OriginRelativeParent = new Vector2(bottomButtonC.OriginRelativeParent.x + buttonMargin.Left, containerControl.Height - controlPadding.Top - topButtonC.Height - buttonMargin.Top);
containerControl.AddChild(topButtonC);
bottomButtonC.OriginRelativeParent = new Vector2(bottomButtonC.OriginRelativeParent.x + buttonMargin.Left, topButtonC.OriginRelativeParent.y - buttonMargin.Height - bottomButtonC.Height);
containerControl.AddChild(bottomButtonC);
}
containerControl.OnDraw(containerControl.NewGraphics2D());
GuiWidget containerTest = new GuiWidget(300, 200);
containerTest.DoubleBuffer = true;
containerTest.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
FlowLayoutWidget allButtons = new FlowLayoutWidget(FlowDirection.TopToBottom);
allButtons.AnchorAll();
Button topButtonT;
Button bottomButtonT;
FlowLayoutWidget topButtonBar;
FlowLayoutWidget bottomButtonBar;
allButtons.Padding = controlPadding;
{
bottomButtonT = new Button("bottom wide button");
topButtonBar = new FlowLayoutWidget();
{
topButtonT = new Button("top button");
topButtonT.LocalBounds = new RectangleDouble(0, 0, bottomButtonT.LocalBounds.Width, 40);
topButtonT.Margin = buttonMargin;
topButtonBar.AddChild(topButtonT);
}
allButtons.AddChild(topButtonBar);
bottomButtonBar = new FlowLayoutWidget();
{
bottomButtonT.Margin = buttonMargin;
bottomButtonBar.AddChild(bottomButtonT);
}
allButtons.AddChild(bottomButtonBar);
}
containerTest.AddChild(allButtons);
containerTest.OnDraw(containerTest.NewGraphics2D());
OutputImages(containerControl, containerTest);
Assert.IsTrue(containerTest.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
Assert.IsTrue(containerTest.BackBuffer.Equals(containerControl.BackBuffer, 1), "The test should contain the same image as the control.");
}
示例9: NestedFitToChildrenParentWidth
public void NestedFitToChildrenParentWidth()
{
// child of flow layout is ParentLeftRight
{
// _________________________________________
// | containerControl |
// | _____________________________________ |
// | | Max_FitToChildren_ParentWidth | |
// | | ________________________ ________ | |
// | | | | | | | |
// | | | ParentLeftRight | | 10x10 | | |
// | | |______________________| |_______| | |
// | |____________________________________| |
// |________________________________________|
//
GuiWidget containerControl = new GuiWidget(300, 200); // containerControl = 0, 0, 300, 200
containerControl.DoubleBuffer = true;
FlowLayoutWidget flowWidget = new FlowLayoutWidget()
{
HAnchor = HAnchor.Max_FitToChildren_ParentWidth,
};
containerControl.AddChild(flowWidget); // flowWidget = 0, 0, 300, 0
GuiWidget fitToChildrenOrParent = new GuiWidget(20, 20)
{
HAnchor = HAnchor.ParentLeftRight,
};
flowWidget.AddChild(fitToChildrenOrParent); // flowWidget = 0, 0, 300, 20 fitToChildrenOrParent = 0, 0, 300, 20
GuiWidget fixed10x10 = new GuiWidget(10, 10);
flowWidget.AddChild(fixed10x10); // flowWidget = 0, 0, 300, 20 fitToChildrenOrParent = 0, 0, 290, 20
containerControl.OnDraw(containerControl.NewGraphics2D());
//OutputImage(containerControl, "countainer");
Assert.IsTrue(flowWidget.Width == containerControl.Width);
Assert.IsTrue(fitToChildrenOrParent.Width + fixed10x10.Width == containerControl.Width);
containerControl.Width = 350;
Assert.IsTrue(flowWidget.Width == containerControl.Width);
Assert.IsTrue(fitToChildrenOrParent.Width + fixed10x10.Width == containerControl.Width);
containerControl.Width = 310;
Assert.IsTrue(flowWidget.Width == containerControl.Width);
Assert.IsTrue(fitToChildrenOrParent.Width + fixed10x10.Width == containerControl.Width);
}
// child of flow layout is Max_FitToChildren_ParentWidth
{
// ___________________________________________________
// | containerControl |
// | _______________________________________________ |
// | | Max_FitToChildren_ParentWidth | |
// | | _________________________________ _______ | |
// | | | | | | | |
// | | | Max_FitToChildren_ParentWidth | | 10x10 | | |
// | | |________________________________| |_______| | |
// | |______________________________________________| |
// |__________________________________________________|
//
GuiWidget containerControl = new GuiWidget(300, 200); // containerControl = 0, 0, 300, 200
containerControl.DoubleBuffer = true;
FlowLayoutWidget flowWidget = new FlowLayoutWidget()
{
HAnchor = HAnchor.Max_FitToChildren_ParentWidth,
};
containerControl.AddChild(flowWidget);
GuiWidget fitToChildrenOrParent = new GuiWidget(20, 20)
{
Name = "fitToChildrenOrParent",
HAnchor = HAnchor.Max_FitToChildren_ParentWidth,
};
flowWidget.AddChild(fitToChildrenOrParent); // flowWidget = 0, 0, 300, 20 fitToChildrenOrParent = 0, 0, 300, 20
GuiWidget fixed10x10 = new GuiWidget(10, 10);
flowWidget.AddChild(fixed10x10); // flowWidget = 0, 0, 300, 20 fitToChildrenOrParent = 0, 0, 290, 20
containerControl.OnDraw(containerControl.NewGraphics2D());
//OutputImage(containerControl, "countainer");
Assert.IsTrue(flowWidget.Width == containerControl.Width);
Assert.IsTrue(fitToChildrenOrParent.Width + fixed10x10.Width == containerControl.Width);
containerControl.Width = 350;
Assert.IsTrue(flowWidget.Width == containerControl.Width);
Assert.IsTrue(fitToChildrenOrParent.Width + fixed10x10.Width == containerControl.Width);
containerControl.Width = 310;
Assert.IsTrue(flowWidget.Width == containerControl.Width);
Assert.IsTrue(fitToChildrenOrParent.Width + fixed10x10.Width == containerControl.Width);
}
}
示例10: AnchorAllTests
internal void AnchorAllTests()
{
{
GuiWidget containerNoAnchor = new GuiWidget(300, 200);
containerNoAnchor.DoubleBuffer = true;
Button positionedButton = new Button("button");
positionedButton.LocalBounds = containerNoAnchor.LocalBounds;
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 | HAnchor.ParentRight;
anchoredButton.VAnchor = VAnchor.ParentBottom | VAnchor.ParentTop;
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.");
}
}
示例11: CenterBothTest
public void CenterBothTest(BorderDouble controlPadding, BorderDouble buttonMargin)
{
GuiWidget containerControl = new GuiWidget(200, 300);
containerControl.Padding = controlPadding;
containerControl.DoubleBuffer = true;
Button controlButton1 = new Button("button1");
controlButton1.Margin = buttonMargin;
double controlCenterX = controlPadding.Left + (containerControl.Width - controlPadding.Left - controlPadding.Right) / 2;
double buttonX = controlCenterX - (controlButton1.Width + controlButton1.Margin.Left + controlButton1.Margin.Right) / 2 + controlButton1.Margin.Left;
double controlCenterY = controlPadding.Bottom + (containerControl.Height - controlPadding.Bottom - controlPadding.Top) / 2 + controlButton1.Margin.Bottom;
double buttonY = controlCenterY - (controlButton1.Height + controlButton1.Margin.Bottom + controlButton1.Margin.Top) / 2;
controlButton1.OriginRelativeParent = new VectorMath.Vector2(buttonX, buttonY);
containerControl.AddChild(controlButton1);
containerControl.OnDraw(containerControl.NewGraphics2D());
GuiWidget containerTest = new GuiWidget(200, 300);
containerTest.Padding = controlPadding;
containerTest.DoubleBuffer = true;
Button testButton1 = new Button("button1");
testButton1.Margin = buttonMargin;
testButton1.VAnchor = VAnchor.ParentCenter;
testButton1.HAnchor = HAnchor.ParentCenter;
containerTest.AddChild(testButton1);
containerTest.OnDraw(containerTest.NewGraphics2D());
OutputImages(containerControl, containerTest);
Assert.IsTrue(containerControl.BackBuffer != null, "When we set a guiWidget to DoubleBuffer it needs to create one.");
OutputImages(containerControl, containerTest);
Assert.IsTrue(containerControl.BackBuffer.Equals(containerTest.BackBuffer, 1), "The Anchored widget should be in the correct place.");
}
示例12: AnchorRightBottomTests
public void AnchorRightBottomTests()
{
// bottom right.
{
GuiWidget containerNoAnchor = new GuiWidget(300, 200);
containerNoAnchor.DoubleBuffer = true;
Button positionedButton = new Button("button");
containerNoAnchor.AddChild(positionedButton);
positionedButton.OriginRelativeParent = new VectorMath.Vector2(containerNoAnchor.Width - positionedButton.Width, 0);
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.ParentRight;
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 right, 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(containerNoAnchor.Width - positionedButton.Width - 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.ParentRight;
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 right, 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(containerNoAnchor.Width - positionedButton.Width - 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.ParentRight;
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.");
}
}
示例13: AnchorRightTopTests
public void AnchorRightTopTests()
{
// bottom Top.
{
GuiWidget containerNoAnchor = new GuiWidget(300, 200);
containerNoAnchor.DoubleBuffer = true;
Button positionedButton = new Button("button");
containerNoAnchor.AddChild(positionedButton);
positionedButton.OriginRelativeParent = new VectorMath.Vector2(containerNoAnchor.Width - positionedButton.Width, containerNoAnchor.Height - positionedButton.Height);
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.ParentRight;
anchoredButton.VAnchor = VAnchor.ParentTop;
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.");
}
}
示例14: AnchorLeftBottomTests
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.");
//.........这里部分代码省略.........
示例15: BottomAndTopSetAnchorBeforAddChild
public void BottomAndTopSetAnchorBeforAddChild(double controlPadding, double buttonMargin)
{
GuiWidget containerControl = new GuiWidget(200, 300);
containerControl.Padding = new BorderDouble(controlPadding);
containerControl.DoubleBuffer = true;
Button controlButton1 = new Button("button1");
controlButton1.Margin = new BorderDouble(buttonMargin);
controlButton1.OriginRelativeParent = new VectorMath.Vector2(0, controlPadding + buttonMargin);
controlButton1.LocalBounds = new RectangleDouble(0, 0, controlButton1.LocalBounds.Width, containerControl.LocalBounds.Height - (controlPadding + buttonMargin) * 2);
containerControl.AddChild(controlButton1);
containerControl.OnDraw(containerControl.NewGraphics2D());
GuiWidget containerTest = new GuiWidget(200, 300);
containerTest.Padding = new BorderDouble(controlPadding);
containerTest.DoubleBuffer = true;
Button testButton1 = new Button("button1");
testButton1.Margin = new BorderDouble(buttonMargin);
testButton1.VAnchor = VAnchor.ParentBottom | VAnchor.ParentTop;
containerTest.AddChild(testButton1);
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.");
}