public void TestParentAssignment() {
      Control parent = new Control();
      Control child = new Control();

      parent.Children.Add(child);

      Assert.AreSame(parent, child.Parent);
    }
    public void TestThrowOnRingParentage() {
      Control parent = new Control();
      Control child = new Control();

      parent.Children.Add(child);
      Assert.Throws<InvalidOperationException>(
        delegate() { child.Children.Add(parent); }
      );
    }
    public void TestThrowOnMultipleParents() {
      Control parent1 = new Control();
      Control parent2 = new Control();
      Control child = new Control();

      parent1.Children.Add(child);
      Assert.Throws<InvalidOperationException>(
        delegate() { parent2.Children.Add(child); }
      );
    }
        private void InitializeComponent()
        {
            Bounds = new Nuclex.UserInterface.UniRectangle(200, 200, 200, 400);

            _itemList = new ListControl();
            _itemList.Bounds = new UniRectangle(
                new UniScalar(0, 10), new UniScalar(0, 10),
                new UniScalar(1, -20), new UniScalar(1, -65)
            );
            Children.Add(_itemList);

            var cancelButton = new ButtonControl();
            cancelButton.Text = "Cancel";
            cancelButton.Pressed += (s, a) => { ItemCancelled.Invoke(); };
            cancelButton.Bounds = new UniRectangle(
                new UniScalar(0, 10), new UniScalar(1, -45),
                new UniScalar(1, -20), new UniScalar(35)
            );
            Children.Add(cancelButton);
        }
Example #5
0
        protected void ShowGui(Control control)
        {
            if (Gui.Screen.Desktop.Children.Contains(control)) return;

            Gui.Screen.Desktop.Children.Add(control);
        }
Example #6
0
    public void TestButtonPressWithActivatedControl() {
      Control parent = new Control();
      parent.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);
      GamePadTestControl child1 = new GamePadTestControl(true);
      GamePadTestControl child2 = new GamePadTestControl(true);
      child2.Bounds = new UniRectangle(10.0f, 10.0f, 25.0f, 60.0f);

      parent.Children.Add(child1);
      parent.Children.Add(child2);

      parent.ProcessMouseMove(100.0f, 100.0f, 20.0f, 30.0f);
      parent.ProcessMousePress(MouseButtons.Left);

      Assert.AreEqual(0, child1.HeldButtonCount);
      Assert.AreEqual(0, child2.HeldButtonCount);
      parent.ProcessButtonPress(Buttons.A);
      Assert.AreEqual(0, child1.HeldButtonCount);
      Assert.AreEqual(1, child2.HeldButtonCount); // Because child 1 was activated
      parent.ProcessButtonRelease(Buttons.A);
      Assert.AreEqual(0, child1.HeldButtonCount);
      Assert.AreEqual(0, child2.HeldButtonCount);
    }
Example #7
0
    public void TestKeyPressWithActivatedControl() {
      Control parent = new Control();
      parent.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);
      KeyboardTestControl child1 = new KeyboardTestControl(true);
      KeyboardTestControl child2 = new KeyboardTestControl(true);
      child2.Bounds = new UniRectangle(10.0f, 10.0f, 25.0f, 60.0f);

      parent.Children.Add(child1);
      parent.Children.Add(child2);

      parent.ProcessMouseMove(100.0f, 100.0f, 20.0f, 30.0f);
      parent.ProcessMousePress(MouseButtons.Left);
      
      Assert.AreEqual(0, child1.HeldKeyCount);
      Assert.AreEqual(0, child2.HeldKeyCount);
      parent.ProcessKeyPress(Keys.A, false);
      Assert.AreEqual(0, child1.HeldKeyCount);
      Assert.AreEqual(1, child2.HeldKeyCount); // Because child 1 was activated
      parent.ProcessKeyRelease(Keys.A);
      Assert.AreEqual(0, child1.HeldKeyCount);
      Assert.AreEqual(0, child2.HeldKeyCount);
    }
Example #8
0
    public void TestMouseWheelWithActivatedControl() {
      Control parent = new Control();
      MouseWheelTestControl child = new MouseWheelTestControl();
      child.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);
      parent.Children.Add(child);

      parent.ProcessMouseMove(100.0f, 100.0f, 50.0f, 50.0f);
      parent.ProcessMousePress(MouseButtons.Left);
      parent.ProcessMouseMove(100.0f, 100.0f, -1.0f, -1.0f);
      
      Assert.AreEqual(0.0f, child.Ticks);
      parent.ProcessMouseWheel(12.34f);
      Assert.AreEqual(12.34f, child.Ticks);
    }
Example #9
0
    public void TestIgnoreMousePress() {
      Control control = new Control();
      control.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);

      control.ProcessMouseMove(100.0f, 100.0f, 20.0f, 20.0f);
      control.ProcessMousePress(MouseButtons.Left);
      control.ProcessMouseRelease(MouseButtons.Left);
    }
Example #10
0
    public void TestMouseOverChildren() {
      Control parent = new Control();
      parent.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);
      MouseOverTestControl child1 = new MouseOverTestControl();
      child1.Bounds = new UniRectangle(10.0f, 10.0f, 25.0f, 60.0f);
      MouseOverTestControl child2 = new MouseOverTestControl();
      child2.Bounds = new UniRectangle(45.0f, 10.0f, 25.0f, 60.0f);
      
      parent.Children.Add(child1);
      parent.Children.Add(child2);

      Assert.IsFalse(child1.MouseOver);
      Assert.IsFalse(child2.MouseOver);
      parent.ProcessMouseMove(100.0f, 100.0f, 20.0f, 30.0f);
      Assert.IsTrue(child1.MouseOver);
      Assert.IsFalse(child2.MouseOver);
      parent.ProcessMouseMove(100.0f, 100.0f, 60.0f, 30.0f);
      Assert.IsFalse(child1.MouseOver);
      Assert.IsTrue(child2.MouseOver);
    }
Example #11
0
    public void TestBringToFront() {
      // Create this:
      //
      //   Root
      //    |- Child 1
      //    |- Child 2
      //         |- Child 2 Child 1
      //         |- Child 2 Child 2
      Control root = new Control();
      Control child1 = new Control();
      Control child2 = new Control();
      Control child2Child1 = new Control();
      Control child2Child2 = new Control();
      root.Children.Add(child1);
      root.Children.Add(child2);
      child2.Children.Add(child2Child1);
      child2.Children.Add(child2Child2);

      // The second child of each control should not be on top
      Assert.AreNotSame(child2, root.Children[0]);
      Assert.AreNotSame(child2Child2, child2.Children[0]);

      // Bring the control to the top. This should recursively move its parents
      // to the top of the siblings so the control ends up in the foreground.
      child2Child2.BringToFront();

      // Make sure the control and its parent are the first one in each list
      Assert.AreSame(child2, root.Children[0]);
      Assert.AreSame(child2Child2, child2.Children[0]);
    }
 public void TestThrowOnSelfParentage() {
   Control testControl = new Control();
   Assert.Throws<InvalidOperationException>(
     delegate() { testControl.Children.Add(testControl); }
   );
 }
    public void TestMoveToEnd() {
      Control parent = new Control();
      Control child1 = new Control();
      Control child2 = new Control();
      Control child3 = new Control();

      parent.Children.Add(child1);
      parent.Children.Add(child2);
      parent.Children.Add(child3);

      Assert.AreSame(child1, parent.Children[0]);
      Assert.AreSame(child2, parent.Children[1]);
      Assert.AreSame(child3, parent.Children[2]);

      child3.BringToFront();

      Assert.AreSame(child3, parent.Children[0]);
      Assert.AreSame(child1, parent.Children[1]);
      Assert.AreSame(child2, parent.Children[2]);
    }
    public void TestItemReplacement() {
      Control parent = new Control();
      Control child1 = new Control();
      Control child2 = new Control();

      parent.Children.Add(child1);

      Assert.AreSame(parent, child1.Parent);
      Assert.IsNull(child2.Parent);

      parent.Children[0] = child2;

      Assert.IsNull(child1.Parent);
      Assert.AreSame(parent, child2.Parent);
    }
Example #15
0
    /// <summary>Assigns a new parent to the control</summary>
    /// <param name="parent">New parent to assign to the control</param>
    internal void SetParent(Control parent) {
      this.parent = parent;

      // Have we been assigned to a parent?
      if(this.parent != null) {

        // If this ownership change transferred us to a different gui, we will
        // have to migrate our visual and also the visuals of all our children.
        if(!ReferenceEquals(this.screen, parent.screen))
          SetScreen(parent.screen);

      } else { // No parent, we're now officially an orphan ;)

        // Orphans don't have screens!
        SetScreen(null);

      }
    }
Example #16
0
    public void TestAbsoluteCoordinateTransformation() {

      // Create a test control that occupies 80 percent of the space in its
      // parent using unified coordinates
      Control myControl = new Control();
      myControl.Bounds.Left = new UniScalar(0.1f, 0);
      myControl.Bounds.Top = new UniScalar(0.1f, 0);
      myControl.Bounds.Right = new UniScalar(0.9f, 0);
      myControl.Bounds.Bottom = new UniScalar(0.9f, 0);

      // Place the test control on a screen sized 1000 x 1000 pixels
      Screen myScreen = new Screen(1000.0f, 1000.0f);
      myScreen.Desktop.Children.Add(myControl);

      // Verify that the test control's absolute coordinates reflect its size
      // given in unified coordinates
      RectangleF absoluteBoundaries = myControl.GetAbsoluteBounds();
      assertAlmostEqual(100.0f, absoluteBoundaries.Left);
      assertAlmostEqual(100.0f, absoluteBoundaries.Top);
      assertAlmostEqual(900.0f, absoluteBoundaries.Right);
      assertAlmostEqual(900.0f, absoluteBoundaries.Bottom);

      // Now change the size of the desktop to only one fourth of the screen
      myScreen.Desktop.Bounds.Location.X.Fraction = 0.5f;
      myScreen.Desktop.Bounds.Location.Y.Fraction = 0.5f;
      myScreen.Desktop.Bounds.Size.X.Fraction = 0.5f;
      myScreen.Desktop.Bounds.Size.Y.Fraction = 0.5f;

      // Verify that the desktop size change is reflected in the absolute
      // coordinates that control's GetAbsoluteBounds() method hands out
      absoluteBoundaries = myControl.GetAbsoluteBounds();
      assertAlmostEqual(550.0f, absoluteBoundaries.Left);
      assertAlmostEqual(550.0f, absoluteBoundaries.Top);
      assertAlmostEqual(950.0f, absoluteBoundaries.Right);
      assertAlmostEqual(950.0f, absoluteBoundaries.Bottom);

    }
Example #17
0
 public void TestThrowsOnGetAbsolutePositionWithoutScreen() {
   Control control = new Control();
   Assert.Throws<InvalidOperationException>(
     delegate() { control.GetAbsoluteBounds(); }
   );
 }
    public void TestClearing() {
      Control parent = new Control();
      Control child = new Control();

      parent.Children.Add(child);
      Assert.AreSame(parent, child.Parent);

      parent.Children.Clear();
      Assert.IsNull(child.Parent);
    }
Example #19
0
 public void TestInitialMousePressOutsideOfControl() {
   Control control = new Control();
   control.ProcessMousePress(MouseButtons.Left);
   control.ProcessMouseRelease(MouseButtons.Left);
 }
    public void TestNormalControl() {
      Control testControl = new Control();
      ControlEventArgs testArgs = new ControlEventArgs(testControl);

      Assert.AreSame(testControl, testArgs.Control);
    }
Example #21
0
    public void TestMouseOverWithActivatedControl() {
      Control parent = new Control();
      parent.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);
      MouseOverTestControl child = new MouseOverTestControl();
      child.Bounds = new UniRectangle(10.0f, 10.0f, 25.0f, 60.0f);
      parent.Children.Add(child);

      parent.ProcessMouseMove(100.0f, 100.0f, 20.0f, 30.0f);
      Assert.IsTrue(child.MouseOver);

      parent.ProcessMousePress(MouseButtons.Left);
      parent.ProcessMouseMove(100.0f, 100.0f, -1.0f, -1.0f);
      
      Assert.IsFalse(child.MouseOver);
    }
Example #22
0
    /// <summary>Switches the mouse over control to a different control</summary>
    /// <param name="newMouseOverControl">New control the mouse is hovering over</param>
    private void switchMouseOverControl(Control newMouseOverControl) {
      if(this.mouseOverControl != newMouseOverControl) {

        // Tell the previous mouse-over control that the mouse is no longer
        // hovering over it
        if(this.mouseOverControl != null) {
          this.mouseOverControl.ProcessMouseLeave();
        }

        this.mouseOverControl = newMouseOverControl;

        // Inform the new mouse-over control that the mouse is now over it
        newMouseOverControl.OnMouseEntered();

      }
    }
Example #23
0
    public void TestReorderControlsOnMousePress() {
      Control parent = new Control();
      parent.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);
      Controls.Desktop.WindowControl child1 = new Controls.Desktop.WindowControl();
      child1.Bounds = new UniRectangle(10.0f, 10.0f, 25.0f, 60.0f);
      Controls.Desktop.WindowControl child2 = new Controls.Desktop.WindowControl();
      child2.Bounds = new UniRectangle(45.0f, 10.0f, 25.0f, 60.0f);

      parent.Children.Add(child1);
      parent.Children.Add(child2);

      Assert.AreSame(child1, parent.Children[0]);
      Assert.AreSame(child2, parent.Children[1]);
      
      parent.ProcessMouseMove(100.0f, 100.0f, 60.0f, 30.0f);
      parent.ProcessMousePress(MouseButtons.Left);

      Assert.AreSame(child2, parent.Children[0]);
      Assert.AreSame(child1, parent.Children[1]);
    }
Example #24
0
        protected void InitializeComponents()
        {
            this.callsignLabel = new LabelControl();
            this.tagLabel = new LabelControl();
            this.hostLabel = new LabelControl();
            this.teamLabel = new LabelControl();

            this.callsignInput = new InputControl();
            this.tagInput = new InputControl();
            this.hostInput = new InputControl();

            this.joinButton = new ButtonControl();
            this.backButton = new ButtonControl();
            this.teamChoice = new Control();

            this.redTeam = new ChoiceControl();
            this.blueTeam = new ChoiceControl();
            this.greenTeam = new ChoiceControl();

            this.callsignLabel.Text = "Callsign: ";
            this.callsignLabel.Bounds = new UniRectangle(new UniScalar(.7f, 0f), new UniScalar(.2f, 0f), 50, 24);

            this.callsignInput.Bounds = new UniRectangle(new UniScalar(.7f, 80f), new UniScalar(0.2f, 0f), 150, 24);
            this.callsignInput.Enabled = true;
            
            this.tagLabel.Text = "Tag: ";
            this.tagLabel.Bounds = new UniRectangle(new UniScalar(0.7f, 0f), new UniScalar(0.3f, 0f), 50, 24);

            this.tagInput.Bounds = new UniRectangle(new UniScalar(0.7f, 80f), new UniScalar(0.3f, 0f), 150, 24);
            this.tagInput.Enabled = true;

            this.hostLabel.Text = "Host: ";
            this.hostLabel.Bounds = new UniRectangle(new UniScalar(0.7f, 0f), new UniScalar(0.4f, 0f), 50, 24);

            this.hostInput.Bounds = new UniRectangle(new UniScalar(0.7f, 80f), new UniScalar(0.4f, 0f), 150, 24);
            this.hostInput.Enabled = true;

            this.teamLabel.Text = "Team: ";
            this.teamLabel.Bounds = new UniRectangle(new UniScalar(0.7f, 0f), new UniScalar(0.5f, 0f), 50, 24);

            this.teamChoice.Bounds = new UniRectangle(new UniScalar(0.7f, 0f), new UniScalar(0.5f, 0f), 150, 94);

            this.redTeam.Text = "Red Team";
            this.redTeam.Bounds = new UniRectangle(new UniScalar(0.0f, 80f), new UniScalar(0.0f, 10f), 10, 10);
            this.redTeam.Enabled = true;

            this.blueTeam.Text = "Blue Team";
            this.blueTeam.Bounds = new UniRectangle(new UniScalar(0.0f, 80f), new UniScalar(0.0f, 30f), 10, 10);
            this.blueTeam.Enabled = true;

            this.greenTeam.Text = "Green Team";
            this.greenTeam.Bounds = new UniRectangle(new UniScalar(0.0f, 80f), new UniScalar(0.0f, 50f), 10, 10);
            this.greenTeam.Enabled = true;

            this.joinButton.Text = "Join!";
            this.joinButton.Bounds = new UniRectangle(new UniScalar(.7f, 80f), new UniScalar(0.7f, 0f), 150, 72);
            // 80, 24 for regular button

            this.backButton.Text = "Back";
            this.backButton.Bounds = new UniRectangle(new UniScalar(0.1f, 0.0f), new UniScalar(0.9f, 0f), 80, 24);

            joinScreen.Desktop.Children.Add(callsignLabel);
            joinScreen.Desktop.Children.Add(callsignInput);
            joinScreen.Desktop.Children.Add(tagLabel);
            joinScreen.Desktop.Children.Add(tagInput);
            joinScreen.Desktop.Children.Add(hostLabel);
            joinScreen.Desktop.Children.Add(hostInput);
            joinScreen.Desktop.Children.Add(teamLabel);
            joinScreen.Desktop.Children.Add(teamChoice);
            joinScreen.Desktop.Children.Add(joinButton);
            joinScreen.Desktop.Children.Add(backButton);

            teamChoice.Children.Add(redTeam);
            teamChoice.Children.Add(blueTeam);
            teamChoice.Children.Add(greenTeam);
        }
Example #25
0
    public void TestMouseWheelWithMouseOverControl() {
      Control parent = new Control();
      MouseWheelTestControl child = new MouseWheelTestControl();
      child.Bounds = new UniRectangle(10.0f, 10.0f, 80.0f, 80.0f);
      parent.Children.Add(child);

      parent.ProcessMouseMove(100.0f, 100.0f, 50.0f, 50.0f);

      Assert.AreEqual(0.0f, child.Ticks);
      parent.ProcessMouseWheel(12.34f);
      Assert.AreEqual(12.34f, child.Ticks);
    }
Example #26
0
    public void TestNameCollisionOnInsertion() {
      Control parent = new Control();
      Control child1 = new Control();
      Control child2 = new Control();

      child1.Name = "DuplicateName";
      child2.Name = "DuplicateName";

      parent.Children.Add(child1);
      Assert.Throws<DuplicateNameException>(
        delegate() { parent.Children.Add(child2); }
      );
    }
Example #27
0
    public void TestKeyPressOnFocusAffectingControl() {
      Control parent = new Control();
      Controls.Desktop.WindowControl child1 = new Controls.Desktop.WindowControl();
      Controls.Desktop.WindowControl child2 = new Controls.Desktop.WindowControl();
      KeyboardTestControl child3 = new KeyboardTestControl(true);
      parent.Children.Add(child1);
      parent.Children.Add(child2);
      parent.Children.Add(child3);
      KeyboardTestControl child1child1 = new KeyboardTestControl(false);
      KeyboardTestControl child1child2 = new KeyboardTestControl(false);
      KeyboardTestControl child2child1 = new KeyboardTestControl(false);
      child1.Children.Add(child1child1);
      child1.Children.Add(child1child2);
      child2.Children.Add(child2child1);

      parent.ProcessKeyPress(Keys.A, false);
      Assert.AreEqual(1, child1child1.HeldKeyCount);
      Assert.AreEqual(1, child1child2.HeldKeyCount); // because child 1 returned false
      Assert.AreEqual(0, child2child1.HeldKeyCount); // because its parent affects focus
      Assert.AreEqual(1, child3.HeldKeyCount); // because it doesn't affect focus
    }
Example #28
0
 public void TestUnsupportedCommands() {
   Control control = new Control();
   
   // These will never be acknowledged
   Assert.IsFalse(control.ProcessCommand(Command.SelectPrevious));
   Assert.IsFalse(control.ProcessCommand(Command.SelectNext));
 }
Example #29
0
    public void TestButtonPressOnFocusAffectingControl() {
      Control parent = new Control();
      Controls.Desktop.WindowControl child1 = new Controls.Desktop.WindowControl();
      Controls.Desktop.WindowControl child2 = new Controls.Desktop.WindowControl();
      GamePadTestControl child3 = new GamePadTestControl(true);
      parent.Children.Add(child1);
      parent.Children.Add(child2);
      parent.Children.Add(child3);
      GamePadTestControl child1child1 = new GamePadTestControl(false);
      GamePadTestControl child1child2 = new GamePadTestControl(false);
      GamePadTestControl child2child1 = new GamePadTestControl(false);
      child1.Children.Add(child1child1);
      child1.Children.Add(child1child2);
      child2.Children.Add(child2child1);

      parent.ProcessButtonPress(Buttons.A);
      Assert.AreEqual(1, child1child1.HeldButtonCount);
      Assert.AreEqual(1, child1child2.HeldButtonCount); // because child 1 returned false
      Assert.AreEqual(0, child2child1.HeldButtonCount); // because its parent affects focus
      Assert.AreEqual(1, child3.HeldButtonCount); // because it doesn't affect focus
    }
Example #30
0
    public void TestSupportedCommands() {
      Control control = new Control();

      // False because the control doesn't acknowledge them
      Assert.IsFalse(control.ProcessCommand(Command.Up));
      Assert.IsFalse(control.ProcessCommand(Command.Down));
      Assert.IsFalse(control.ProcessCommand(Command.Left));
      Assert.IsFalse(control.ProcessCommand(Command.Right));
      Assert.IsFalse(control.ProcessCommand(Command.Accept));
      Assert.IsFalse(control.ProcessCommand(Command.Cancel));
    }