public void TestMouseOverWithThumbLocator()
        {
            Screen screen = new Screen(100, 100);
            HorizontalSliderControl slider = new HorizontalSliderControl();

            slider.Bounds        = new UniRectangle(10, 10, 100, 100);
            slider.ThumbSize     = 0.33f;
            slider.ThumbPosition = 0.0f;
            screen.Desktop.Children.Add(slider);

            // The thumb would normally be at the top of the control, but this
            // the thumb locator will tell the control that its thumb is at the bottom.
            slider.ThumbLocator = new DummyThumbLocator(
                new RectangleF(66.6f, 0.0f, 33.3f, 100.0f)
                );

            // Position above the thumb should be reported as outside of the thumb.
            slider.ProcessMouseMove(100, 100, 15, 50);
            Assert.IsFalse(slider.MouseOverThumb);

            // Move the mouse over the thumb. The property should now return true.
            slider.ProcessMouseMove(100, 100, 85, 50);
            Assert.IsTrue(slider.MouseOverThumb);

            // Move the mouse away from the thumb, but stay over the control.
            // The property should now return false again.
            slider.ProcessMouseMove(100, 100, 50, 50);
            Assert.IsFalse(slider.MouseOverThumb);
        }
        public void TestMouseOverThumb()
        {
            Screen screen = new Screen(100, 100);
            HorizontalSliderControl slider = new HorizontalSliderControl();

            slider.Bounds        = new UniRectangle(10, 10, 100, 100);
            slider.ThumbSize     = 0.33f;
            slider.ThumbPosition = 0.25f;
            screen.Desktop.Children.Add(slider);

            float movableRange = 1.0f - slider.ThumbSize;
            float left         = movableRange * slider.ThumbPosition;
            float right        = left + slider.ThumbSize;

            left  *= slider.Bounds.Size.X.Offset;
            right *= slider.Bounds.Size.X.Offset;
            float thumbWidth = right - left;

            // Position above the thumb should be reported as outside of the thumb.
            slider.ProcessMouseMove(100, 100, left - thumbWidth / 2.0f, 50);
            Assert.IsFalse(slider.MouseOverThumb);

            // Move the mouse over the thumb. The property should now return true.
            slider.ProcessMouseMove(100, 100, left + thumbWidth / 2.0f, 50);
            Assert.IsTrue(slider.MouseOverThumb);

            // Move the mouse away from the thumb, but stay over the control.
            // The property should now return false again.
            slider.ProcessMouseMove(100, 100, right + thumbWidth / 2.0f, 50);
            Assert.IsFalse(slider.MouseOverThumb);
        }
    public void TestMouseOverThumb() {
      Screen screen = new Screen(100, 100);
      HorizontalSliderControl slider = new HorizontalSliderControl();
      slider.Bounds = new UniRectangle(10, 10, 100, 100);
      slider.ThumbSize = 0.33f;
      slider.ThumbPosition = 0.25f;
      screen.Desktop.Children.Add(slider);

      float movableRange = 1.0f - slider.ThumbSize;
      float left = movableRange * slider.ThumbPosition;
      float right = left + slider.ThumbSize;

      left *= slider.Bounds.Size.X.Offset;
      right *= slider.Bounds.Size.X.Offset;
      float thumbWidth = right - left;

      // Position above the thumb should be reported as outside of the thumb.
      slider.ProcessMouseMove(100, 100, left - thumbWidth / 2.0f, 50);
      Assert.IsFalse(slider.MouseOverThumb);

      // Move the mouse over the thumb. The property should now return true.
      slider.ProcessMouseMove(100, 100, left + thumbWidth / 2.0f, 50);
      Assert.IsTrue(slider.MouseOverThumb);

      // Move the mouse away from the thumb, but stay over the control.
      // The property should now return false again.      
      slider.ProcessMouseMove(100, 100, right + thumbWidth / 2.0f, 50);
      Assert.IsFalse(slider.MouseOverThumb);
    }
        public void TestFullSizeThumbDragging()
        {
            Screen screen = new Screen(100, 100);
            HorizontalSliderControl slider = new HorizontalSliderControl();

            slider.Bounds    = new UniRectangle(10, 10, 100, 100);
            slider.ThumbSize = 1.0f;
            screen.Desktop.Children.Add(slider);

            // Move the mouse over the thumb, press the left mouse button and drag
            // it to a new location
            slider.ProcessMouseMove(100, 100, 50, 50);
            slider.ProcessMousePress(MouseButtons.Left);
            slider.ProcessMouseMove(100, 100, 60, 50);
            Assert.That(slider.ThumbPosition, Is.EqualTo(0.0f).Within(16).Ulps);
        }
        public void TestThumbDragging()
        {
            Screen screen = new Screen(100, 100);
            HorizontalSliderControl slider = new HorizontalSliderControl();

            slider.Bounds        = new UniRectangle(10, 10, 100, 100);
            slider.ThumbSize     = 0.33f;
            slider.ThumbPosition = 0.25f;
            screen.Desktop.Children.Add(slider);

            float movableRange = 1.0f - slider.ThumbSize;
            float left         = movableRange * slider.ThumbPosition;
            float right        = left + slider.ThumbSize;

            left  *= slider.Bounds.Size.X.Offset;
            right *= slider.Bounds.Size.X.Offset;
            float thumbWidth = right - left;

            float target = movableRange * (1.0f - slider.ThumbPosition);

            target *= slider.Bounds.Size.X.Offset;

            // Move the mouse over the thumb, press the left mouse button and drag
            // it to a new location
            slider.ProcessMouseMove(100, 100, left + thumbWidth / 2.0f, 50);
            slider.ProcessMousePress(MouseButtons.Left);
            slider.ProcessMouseMove(100, 100, target + thumbWidth / 2.0f, 50);
            Assert.That(slider.ThumbPosition, Is.EqualTo(0.75f).Within(16).Ulps);

            slider.ProcessMouseMove(100, 100, slider.Bounds.Location.X.Offset, 50);
            Assert.That(slider.ThumbPosition, Is.EqualTo(0.0f).Within(16).Ulps);

            slider.ProcessMouseMove(
                100, 100, slider.Bounds.Location.X.Offset + slider.Bounds.Size.X.Offset, 50
                );
            Assert.That(slider.ThumbPosition, Is.EqualTo(1.0f).Within(16).Ulps);
        }
    public void TestFullSizeThumbDragging() {
      Screen screen = new Screen(100, 100);
      HorizontalSliderControl slider = new HorizontalSliderControl();
      slider.Bounds = new UniRectangle(10, 10, 100, 100);
      slider.ThumbSize = 1.0f;
      screen.Desktop.Children.Add(slider);

      // Move the mouse over the thumb, press the left mouse button and drag
      // it to a new location
      slider.ProcessMouseMove(100, 100, 50, 50);
      slider.ProcessMousePress(MouseButtons.Left);
      slider.ProcessMouseMove(100, 100, 60, 50);
      Assert.That(slider.ThumbPosition, Is.EqualTo(0.0f).Within(16).Ulps);
    }
    public void TestThumbDragging() {
      Screen screen = new Screen(100, 100);
      HorizontalSliderControl slider = new HorizontalSliderControl();
      slider.Bounds = new UniRectangle(10, 10, 100, 100);
      slider.ThumbSize = 0.33f;
      slider.ThumbPosition = 0.25f;
      screen.Desktop.Children.Add(slider);

      float movableRange = 1.0f - slider.ThumbSize;
      float left = movableRange * slider.ThumbPosition;
      float right = left + slider.ThumbSize;

      left *= slider.Bounds.Size.X.Offset;
      right *= slider.Bounds.Size.X.Offset;
      float thumbWidth = right - left;

      float target = movableRange * (1.0f - slider.ThumbPosition);
      target *= slider.Bounds.Size.X.Offset;

      // Move the mouse over the thumb, press the left mouse button and drag
      // it to a new location
      slider.ProcessMouseMove(100, 100, left + thumbWidth / 2.0f, 50);
      slider.ProcessMousePress(MouseButtons.Left);
      slider.ProcessMouseMove(100, 100, target + thumbWidth / 2.0f, 50);
      Assert.That(slider.ThumbPosition, Is.EqualTo(0.75f).Within(16).Ulps);

      slider.ProcessMouseMove(100, 100, slider.Bounds.Location.X.Offset, 50);
      Assert.That(slider.ThumbPosition, Is.EqualTo(0.0f).Within(16).Ulps);

      slider.ProcessMouseMove(
        100, 100, slider.Bounds.Location.X.Offset + slider.Bounds.Size.X.Offset, 50
      );
      Assert.That(slider.ThumbPosition, Is.EqualTo(1.0f).Within(16).Ulps);
    }
    public void TestMouseOverWithThumbLocator() {
      Screen screen = new Screen(100, 100);
      HorizontalSliderControl slider = new HorizontalSliderControl();
      slider.Bounds = new UniRectangle(10, 10, 100, 100);
      slider.ThumbSize = 0.33f;
      slider.ThumbPosition = 0.0f;
      screen.Desktop.Children.Add(slider);

      // The thumb would normally be at the top of the control, but this
      // the thumb locator will tell the control that its thumb is at the bottom.
      slider.ThumbLocator = new DummyThumbLocator(
        new RectangleF(66.6f, 0.0f, 33.3f, 100.0f)
      );

      // Position above the thumb should be reported as outside of the thumb.
      slider.ProcessMouseMove(100, 100, 15, 50);
      Assert.IsFalse(slider.MouseOverThumb);

      // Move the mouse over the thumb. The property should now return true.
      slider.ProcessMouseMove(100, 100, 85, 50);
      Assert.IsTrue(slider.MouseOverThumb);

      // Move the mouse away from the thumb, but stay over the control.
      // The property should now return false again.      
      slider.ProcessMouseMove(100, 100, 50, 50);
      Assert.IsFalse(slider.MouseOverThumb);
    }
Exemple #9
0
        /// <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);
        }