public void Element_MouseButtonDown_Test() { var element = new ElementMock(new TestHelpers.RootElement(), AssetManager) { DestRect = new Rectangle(0.5f, 0.5f, 0.5f, 0.5f) }; bool leftDown = false, rightDown = false, middleDown = false; element.MouseDown += ((o, e) => { switch (e.ChangedButton) { case MouseButton.Left: leftDown = true; break; case MouseButton.Right: rightDown = true; break; case MouseButton.Middle: middleDown = true; break; } e.Handled = true; }); element.InjectMouseDownEvent(element.AbsRect.Left - 1, element.AbsRect.Top - 1, MouseButton.Left); Assert.IsFalse(leftDown); element.InjectMouseDownEvent(element.AbsRect.Left, element.AbsRect.Top, MouseButton.Left); Assert.IsTrue(leftDown); element.InjectMouseDownEvent(element.AbsRect.Left - 1, element.AbsRect.Top - 1, MouseButton.Right); Assert.IsFalse(rightDown); element.InjectMouseDownEvent(element.AbsRect.Left, element.AbsRect.Top, MouseButton.Right); Assert.IsTrue(rightDown); element.InjectMouseDownEvent(element.AbsRect.Left - 1, element.AbsRect.Top - 1, MouseButton.Middle); Assert.IsFalse(middleDown); element.InjectMouseDownEvent(element.AbsRect.Left, element.AbsRect.Top, MouseButton.Middle); Assert.IsTrue(middleDown); }
public void Element_OnlyLastestChildFiresEvent_Test() { // Direct routing strategy bool parentFired = false; var element = new ElementMock(new TestHelpers.RootElement(), AssetManager); element.MouseDown += ((o, e) => parentFired = true); bool childFired = false; var child = new ElementMock(element, AssetManager); child.MouseDown += (o, e) => { childFired = true; e.Handled = true; }; element.InjectMouseDownEvent(0.0f, 0.0f, MouseButton.Left); Assert.IsFalse(parentFired); Assert.IsTrue(childFired); }