public void TestOpenCloseWindow() { Screen screen = new Screen(100, 100); WindowControl window = new WindowControl(); // A window not in a screen's control hierarchy is considered closed Assert.IsFalse(window.IsOpen); // Once the window is added to a screen, meaning it will be drawn and // can be interacted with by the user, it is considered open screen.Desktop.Children.Add(window); Assert.IsTrue(window.IsOpen); // Close the window. Essentially just syntactic sugar for removing // the window from the control hierarchy window.Close(); Assert.IsFalse(window.IsOpen); }
public void TestWindowDragging() { WindowControl window = new WindowControl(); window.Bounds = new UniRectangle(10, 10, 100, 100); window.ProcessMouseMove(100, 100, 50, 50); window.ProcessMousePress(MouseButtons.Left); window.ProcessMouseMove(100, 100, 60, 50); Assert.AreEqual(20, window.Bounds.Location.X.Offset); window.ProcessMouseMove(100, 100, 40, 40); Assert.AreEqual(0, window.Bounds.Location.X.Offset); Assert.AreEqual(0, window.Bounds.Location.Y.Offset); window.ProcessMouseRelease(MouseButtons.Left); window.ProcessMouseMove(100, 100, 70, 70); Assert.AreEqual(0, window.Bounds.Location.X.Offset); Assert.AreEqual(0, window.Bounds.Location.Y.Offset); }
public void DisableDragging() { WindowControl window = new WindowControl(); window.Bounds = new UniRectangle(10, 10, 100, 100); // By default, dragging should be enabled Assert.IsTrue(window.EnableDragging); // Turn it off window.EnableDragging = false; // Now it should be off ;-) Assert.IsFalse(window.EnableDragging); // Try to drag the window window.ProcessMouseMove(100, 100, 50, 50); window.ProcessMousePress(MouseButtons.Left); window.ProcessMouseMove(100, 100, 60, 50); // Make sure the window has not moved Assert.AreEqual(10, window.Bounds.Location.X.Offset); }
public void TestCloseUnopenedWindow() { WindowControl window = new WindowControl(); window.Close(); // No exception means success }
/// <summary> /// Create gui controls /// </summary> /// <param name="mainScreen"> /// Screen to whose desktop the controls will be added /// </param> private void createDesktopControls(Screen mainScreen) { WindowControl options = new WindowControl(); options.Title = "Options"; options.EnableDragging = true; options.Bounds = new UniRectangle( new UniScalar(1.0f, -210.0f), 10, 200, 275); mainScreen.Desktop.Children.Add(options); OptionControl wireFrameToggle = new OptionControl(); wireFrameToggle.Text = "Wireframe"; wireFrameToggle.Bounds = new UniRectangle(10, 30, 100, 32); wireFrameToggle.Selected = Wireframe; wireFrameToggle.Changed += delegate(object sender, EventArgs arguments) { Wireframe = wireFrameToggle.Selected; }; options.Children.Add(wireFrameToggle); /* OptionControl fogToggle = new OptionControl(); fogToggle.Text = "Fog"; fogToggle.Bounds = new UniRectangle(10, 65, 100, 32); fogToggle.Selected = terrainDrawContext.BasicEffect.FogEnabled; fogToggle.Changed += delegate(object sender, EventArgs arguments) { terrainDrawContext.BasicEffect.FogEnabled = fogToggle.Selected; }; options.Children.Add(fogToggle); LabelControl fogNearLabel = new LabelControl("Near"); fogNearLabel.Bounds = new UniRectangle(10, 100, 20, 24); options.Children.Add(fogNearLabel); const float fogRange = 1000f; HorizontalSliderControl fogNear = new HorizontalSliderControl(); fogNear.Bounds = new UniRectangle(50, 100, 140, 24); fogNear.ThumbSize = 0.1f; fogNear.ThumbPosition = terrainDrawContext.BasicEffect.FogStart / fogRange; fogNear.Moved += delegate(object sender, EventArgs arguments) { terrainDrawContext.BasicEffect.FogStart = fogNear.ThumbPosition * fogRange; }; options.Children.Add(fogNear); LabelControl fogFarLabel = new LabelControl("Far"); fogFarLabel.Bounds = new UniRectangle(10, 125, 20, 24); options.Children.Add(fogFarLabel); HorizontalSliderControl fogFar = new HorizontalSliderControl(); fogFar.Bounds = new UniRectangle(50, 125, 140, 24); fogFar.ThumbSize = 0.1f; fogFar.ThumbPosition = terrainDrawContext.BasicEffect.FogEnd / fogRange; fogFar.Moved += delegate(object sender, EventArgs arguments) { terrainDrawContext.BasicEffect.FogEnd = fogFar.ThumbPosition * fogRange; }; options.Children.Add(fogFar); */ LabelControl cellGapLabel = new LabelControl("Gap"); cellGapLabel.Bounds = new UniRectangle(10, 65, 20, 24); options.Children.Add(cellGapLabel); HorizontalSliderControl cellGapControl = new HorizontalSliderControl(); cellGapControl.Bounds = new UniRectangle(50, 65, 140, 24); cellGapControl.ThumbSize = 0.1f; const float cellGapRange = 5.0f; cellGapControl.ThumbPosition = cellGap / cellGapRange; cellGapControl.Moved += delegate(object sender, EventArgs arguments) { cellGap = cellGapControl.ThumbPosition * cellGapRange; }; options.Children.Add(cellGapControl); LabelControl densityLabel = new LabelControl("Density"); densityLabel.Bounds = new UniRectangle(10, 90, 20, 24); options.Children.Add(densityLabel); const float densityRange = 100.0f; HorizontalSliderControl densityControl = new HorizontalSliderControl(); densityControl.Bounds = new UniRectangle(60, 90, 130, 24); densityControl.ThumbSize = 0.1f; densityControl.ThumbPosition = terrainNoiseDensity / densityRange; densityControl.Moved += delegate(object sender, EventArgs arguments) { terrainNoiseDensity = densityControl.ThumbPosition * densityRange; }; options.Children.Add(densityControl); LabelControl cellResLabel = new LabelControl("CellRes"); cellResLabel.Bounds = new UniRectangle(10, 115, 20, 24); options.Children.Add(cellResLabel); const float cellResRange = 5.0f; HorizontalSliderControl cellResControl = new HorizontalSliderControl(); cellResControl.Bounds = new UniRectangle(60, 115, 130, 24); cellResControl.ThumbSize = 0.1f; cellResControl.ThumbPosition = cellRes / (float)Math.Pow(2, cellResRange); cellResControl.Moved += delegate(object sender, EventArgs arguments) { cellRes = (float)Math.Pow(2, (int)(cellResControl.ThumbPosition * cellResRange)); }; options.Children.Add(cellResControl); LabelControl terrainResLabel = new LabelControl("TerRes"); terrainResLabel.Bounds = new UniRectangle(10, 140, 20, 24); options.Children.Add(terrainResLabel); const float terrainResRange = 5.0f; HorizontalSliderControl terrainResControl = new HorizontalSliderControl(); terrainResControl.Bounds = new UniRectangle(60, 140, 130, 24); terrainResControl.ThumbSize = 0.1f; terrainResControl.ThumbPosition = terrainRes / (float)Math.Pow(2, terrainResRange); terrainResControl.Moved += delegate(object sender, EventArgs arguments) { terrainRes = (float)Math.Pow(2, (int)(terrainResControl.ThumbPosition * terrainResRange)); }; options.Children.Add(terrainResControl); OptionControl cubicToggle = new OptionControl(); cubicToggle.Text = "Cubic (requires regen)"; cubicToggle.Bounds = new UniRectangle(10, 165, 100, 32); cubicToggle.Selected = cubicTerrain; cubicToggle.Changed += delegate(object sender, EventArgs arguments) { cubicTerrain = cubicToggle.Selected; }; options.Children.Add(cubicToggle); ButtonControl regenerateButton = new ButtonControl(); regenerateButton.Text = "Regenerate"; regenerateButton.Bounds = new UniRectangle( new UniScalar(1.0f, -190.0f), new UniScalar(1.0f, -75.0f), 110, 32); regenerateButton.Pressed += delegate(object sender, EventArgs arguments) { GenerateTerrain(random.Next(255)); }; options.Children.Add(regenerateButton); ButtonControl resetButton = new ButtonControl(); resetButton.Text = "Reset Camera"; resetButton.Bounds = new UniRectangle( new UniScalar(1.0f, -190.0f), new UniScalar(1.0f, -40.0f), 110, 32); resetButton.Pressed += delegate(object sender, EventArgs arguments) { ResetCamera(); }; options.Children.Add(resetButton); // Button through which the user can quit the application ButtonControl quitButton = new ButtonControl(); quitButton.Text = "Quit"; quitButton.Bounds = new UniRectangle( new UniScalar(1.0f, -70.0f), new UniScalar(1.0f, -40.0f), 60, 32); quitButton.Pressed += delegate(object sender, EventArgs arguments) { Exit(); }; options.Children.Add(quitButton); }