本文整理汇总了C#中GuiWidget.OnMouseMove方法的典型用法代码示例。如果您正苦于以下问题:C# GuiWidget.OnMouseMove方法的具体用法?C# GuiWidget.OnMouseMove怎么用?C# GuiWidget.OnMouseMove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuiWidget
的用法示例。
在下文中一共展示了GuiWidget.OnMouseMove方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DropDownListTests
//.........这里部分代码省略.........
MenuItem copyMenuItem = new MenuItem(new TextWidget("Copy"));
copyMenuItem.Selected += (sender, e) => { menuSelected = "Copy"; };
listMenu.MenuItems.Add(copyMenuItem);
MenuItem pastMenuItem = new MenuItem(new TextWidget("Paste"));
pastMenuItem.Selected += (sender, e) => { menuSelected = "Paste"; };
listMenu.MenuItems.Add(pastMenuItem);
container.AddChild(listMenu);
Assert.IsTrue(!listMenu.IsOpen);
// open the menu
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(listMenu.IsOpen);
// click on menu again to close
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
// open the menu
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(listMenu.IsOpen);
// click off menu to close
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 5, 299, 0));
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 5, 299, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
// open the menu
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(listMenu.IsOpen);
// select the first item
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 290, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(listMenu.IsOpen);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 290, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
Assert.IsTrue(menuSelected == "Cut");
// open the menu
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(listMenu.IsOpen);
// select the second item
menuSelected = "";
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 275, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(listMenu.IsOpen);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 275, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
Assert.IsTrue(menuSelected == "Copy");
// make sure click down then move off item does not select it.
menuSelected = "";
// open the menu
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(listMenu.IsOpen);
// click down on the first item
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 290, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(listMenu.IsOpen);
// move off of it
container.OnMouseMove(new MouseEventArgs(MouseButtons.None, 1, 5, 290, 0));
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 5, 290, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
Assert.IsTrue(menuSelected == "");
// make sure click down and then move to new items selects the new item.
// click and draw down to item should work as well
}
示例2: ListMenuTests
//.........这里部分代码省略.........
Assert.IsTrue(!listMenu.IsOpen);
// all the mune itmes should be removed from the closed menu
Assert.IsTrue(cutMenuItem.Parent == null);
Assert.IsTrue(copyMenuItem.Parent == null);
Assert.IsTrue(pastMenuItem.Parent == null);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
// all the menu itmes should be removed from the closed menu
Assert.IsTrue(cutMenuItem.Parent == null);
Assert.IsTrue(copyMenuItem.Parent == null);
Assert.IsTrue(pastMenuItem.Parent == null);
// open the menu
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(listMenu.IsOpen);
// all the menu itmes should be added to the open menu
Assert.IsTrue(cutMenuItem.Parent != null);
Assert.IsTrue(copyMenuItem.Parent != null);
Assert.IsTrue(pastMenuItem.Parent != null);
// click off menu to close
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 5, 299, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
// all the mune itmes should be removed from the closed menu
Assert.IsTrue(cutMenuItem.Parent == null);
Assert.IsTrue(copyMenuItem.Parent == null);
Assert.IsTrue(pastMenuItem.Parent == null);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 5, 299, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
// open the menu again
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(listMenu.IsOpen);
// select the first item
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 290, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(listMenu.IsOpen);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 290, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
Assert.IsTrue(menuSelected == "Cut");
// open the menu
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(listMenu.IsOpen);
// select the second item
menuSelected = "";
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 275, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(listMenu.IsOpen);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 275, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
Assert.IsTrue(menuSelected == "Copy");
// make sure click down then move off item does not select it.
menuSelected = "";
// open the menu
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 11, 300, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(listMenu.IsOpen);
// click down on the first item
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 11, 290, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(listMenu.IsOpen);
// move off of it
container.OnMouseMove(new MouseEventArgs(MouseButtons.None, 1, 5, 290, 0));
UiThread.DoRunAllPending();
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 5, 290, 0));
UiThread.DoRunAllPending();
Assert.IsTrue(!listMenu.IsOpen);
Assert.IsTrue(menuSelected == "");
// make sure click down and then move to new items selects the new item.
// click and draw down to item should work as well
}
示例3: TextEditGetsFocusTests
public void TextEditGetsFocusTests()
{
GuiWidget container = new GuiWidget();
container.Name = "container";
container.LocalBounds = new RectangleDouble(0, 0, 200, 200);
TextEditWidget editField1 = new TextEditWidget("", 0, 0, pixelWidth: 160);
editField1.Name = "editField1";
container.AddChild(editField1);
TextEditWidget editField2 = new TextEditWidget("", 0, 20, pixelWidth: 160);
editField2.Name = "editField2";
container.AddChild(editField2);
// select no edit field
Assert.IsTrue(editField1.Text == "");
SendKey(Keys.D, 'a', container);
Assert.IsTrue(editField1.Text == "");
Assert.IsTrue(editField2.Text == "");
// select edit field 1
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0)); // we move into the widget to make sure we have seprated focus and enter events.
Assert.IsTrue(editField1.ContainsFocus == false);
Assert.IsTrue(editField1.Focused == false);
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0));
Assert.IsTrue(editField1.ContainsFocus == true);
Assert.IsTrue(editField1.Focused == false, "The internal text widget must be focused.");
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0));
Assert.IsTrue(editField1.ContainsFocus == true);
Assert.IsTrue(editField1.Focused == false);
SendKey(Keys.B, 'b', container);
Assert.IsTrue(editField1.Text == "b", "It should have b a in it.");
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 150, 1, 0));
Assert.IsTrue(editField1.ContainsFocus == true);
Assert.IsTrue(editField1.Focused == false, "The internal text widget must be focused.");
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 150, 1, 0));
Assert.IsTrue(editField1.ContainsFocus == true);
Assert.IsTrue(editField1.Focused == false);
SendKey(Keys.D, 'c', container);
Assert.IsTrue(editField1.Text == "bc", "It should have b a in it.");
// select edit field 2
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 1, 21, 0));
Assert.IsTrue(editField2.ContainsFocus == true);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, 21, 0));
SendKey(Keys.D, 'd', container);
Assert.IsTrue(editField1.Text == "bc", "It should have a bc in it.");
Assert.IsTrue(editField2.Text == "d", "It should have d in it.");
container.Close();
}
示例4: TextEditTextSelectionTests
public void TextEditTextSelectionTests()
{
GuiWidget container = new GuiWidget();
container.LocalBounds = new RectangleDouble(0, 0, 200, 200);
TextEditWidget editField1 = new TextEditWidget("", 0, 0, pixelWidth: 51);
container.AddChild(editField1);
// select the conrol and type something in it
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
SendKey(Keys.A, 'a', container);
Assert.IsTrue(editField1.Text == "a", "It should have a in it.");
// select the begining again and type something else in it
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
SendKey(Keys.B, 'b', container);
Assert.IsTrue(editField1.Text == "ba", "It should have ba in it.");
// select the ba and delete them
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 0, 15, 0, 0));
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 0, 15, 0, 0));
SendKey(Keys.Back, ' ', container);
Assert.IsTrue(editField1.Text == "", "It should have nothing in it.");
// select the other way
editField1.Text = "ab";
Assert.IsTrue(editField1.Text == "ab", "It should have ab in it.");
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 15, 0, 0));
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
SendKey(Keys.Back, ' ', container);
Assert.IsTrue(editField1.Text == "", "It should have nothing in it.");
// select the other way but start far to the right
editField1.Text = "abc";
Assert.IsTrue(editField1.Text == "abc", "It should have abc in it.");
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 30, 0, 0));
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 0, 0, 0, 0));
SendKey(Keys.Back, ' ', container);
Assert.IsTrue(editField1.Text == "", "It should have nothing in it.");
container.Close();
}
示例5: MouseCapturedSpressesLeaveEvents
public void MouseCapturedSpressesLeaveEvents()
{
GuiWidget container = new GuiWidget();
container.Name = "continer";
container.LocalBounds = new RectangleDouble(0, 0, 200, 200);
GuiWidget regionA = new GuiWidget();
regionA.Name = "regionA";
regionA.BoundsRelativeToParent = new RectangleDouble(10, 10, 190, 190);
container.AddChild(regionA);
int aGotEnter = 0;
int aGotLeave = 0;
int aGotEnterBounds = 0;
int aGotLeaveBounds = 0;
int aGotMove = 0;
int aGotUp = 0;
regionA.MouseEnter += (sender, e) => { if (regionA.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); aGotEnter++; };
regionA.MouseLeave += (sender, e) => { if (regionA.UnderMouseState == UnderMouseState.FirstUnderMouse) throw new Exception("It must not be under the mouse."); aGotLeave++; };
regionA.MouseEnterBounds += (sender, e) => { if (regionA.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); aGotEnterBounds++; };
regionA.MouseLeaveBounds += (sender, e) => { if (regionA.UnderMouseState != UnderMouseState.NotUnderMouse) throw new Exception("It must not be under the mouse."); aGotLeaveBounds++; };
regionA.MouseMove += (sender, e) => { aGotMove++; };
regionA.MouseUp += (sender, e) => { aGotUp++; };
// make sure we know we are entered and captued on a down event
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 15, 15, 0));
Assert.IsTrue(regionA.FirstWidgetUnderMouse == true);
Assert.IsTrue(regionA.MouseCaptured == true);
Assert.IsTrue(aGotEnter == 1);
Assert.IsTrue(aGotLeave == 0);
Assert.IsTrue(aGotEnterBounds == 1);
Assert.IsTrue(aGotLeaveBounds == 0);
Assert.IsTrue(aGotMove == 0);
// make sure we stay on top when internal moves occure
aGotEnter = aGotLeave = aGotEnterBounds = aGotLeaveBounds = aGotMove = 0;
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 16, 16, 0));
Assert.IsTrue(regionA.FirstWidgetUnderMouse == true);
Assert.IsTrue(regionA.MouseCaptured == true);
Assert.IsTrue(aGotEnter == 0);
Assert.IsTrue(aGotLeave == 0);
Assert.IsTrue(aGotEnterBounds == 0);
Assert.IsTrue(aGotLeaveBounds == 0);
Assert.IsTrue(aGotMove == 1);
// make sure we see leave events when captured
aGotUp = aGotEnter = aGotLeave = aGotEnterBounds = aGotLeaveBounds = aGotMove = 0;
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0));
Assert.IsTrue(container.FirstWidgetUnderMouse == false);
Assert.IsTrue(regionA.FirstWidgetUnderMouse == false);
Assert.IsTrue(regionA.MouseCaptured == true);
Assert.IsTrue(aGotEnter == 0);
Assert.IsTrue(aGotLeave == 1);
Assert.IsTrue(aGotEnterBounds == 0);
Assert.IsTrue(aGotLeaveBounds == 1);
Assert.IsTrue(aGotMove == 1);
// make sure we see enter events when captured
aGotUp = aGotEnter = aGotLeave = aGotEnterBounds = aGotLeaveBounds = aGotMove = 0;
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 15, 15, 0));
Assert.IsTrue(regionA.FirstWidgetUnderMouse == true);
Assert.IsTrue(regionA.MouseCaptured == true);
Assert.IsTrue(aGotEnter == 1);
Assert.IsTrue(aGotLeave == 0);
Assert.IsTrue(aGotEnterBounds == 1);
Assert.IsTrue(aGotLeaveBounds == 0);
Assert.IsTrue(aGotMove == 1);
// and we are not captured after mouseup above region
aGotUp = aGotEnter = aGotLeave = aGotEnterBounds = aGotLeaveBounds = aGotMove = 0;
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 15, 15, 0));
Assert.IsTrue(regionA.MouseCaptured == false);
Assert.IsTrue(aGotEnter == 0);
Assert.IsTrue(aGotLeave == 0);
Assert.IsTrue(aGotEnterBounds == 0);
Assert.IsTrue(aGotLeaveBounds == 0);
Assert.IsTrue(aGotMove == 0);
Assert.IsTrue(aGotUp == 1, "When we are captured we need to see mouse up messages.");
// make sure we are not captured after mouseup above off region
aGotUp = aGotEnter = aGotLeave = aGotEnterBounds = aGotLeaveBounds = aGotMove = 0;
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 15, 15, 0));
Assert.IsTrue(regionA.MouseCaptured == true);
Assert.IsTrue(aGotEnter == 0, "we are already in the button from the last move");
Assert.IsTrue(aGotLeave == 0);
Assert.IsTrue(aGotEnterBounds == 0, "we are already in the button from the last move");
Assert.IsTrue(aGotLeaveBounds == 0);
Assert.IsTrue(aGotMove == 0);
container.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0));
Assert.IsTrue(regionA.MouseCaptured == false);
Assert.IsTrue(aGotEnter == 0);
Assert.IsTrue(aGotLeave == 1, "During the mouse up we also happen to be off the widget. Need to get a mouse leave event.");
Assert.IsTrue(aGotEnterBounds == 0);
Assert.IsTrue(aGotLeaveBounds == 1, "During the mouse up we also happen to be off the widget. Need to get a mouse leave event.");
Assert.IsTrue(aGotMove == 0);
Assert.IsTrue(aGotUp == 1, "When we are captured we need to see mouse up messages.");
// when captured make sure we see move events even when they are not above us.
GuiWidget regionB = new GuiWidget();
regionB.Name = "regionB";
regionB.BoundsRelativeToParent = new RectangleDouble(20, 20, 180, 180);
//.........这里部分代码省略.........
示例6: ValidateEnterAndLeaveInOverlapArea
public void ValidateEnterAndLeaveInOverlapArea()
{
GuiWidget container = new GuiWidget();
container.Name = "container";
container.LocalBounds = new RectangleDouble(0, 0, 200, 200);
GuiWidget bottomWidget = new GuiWidget();
bottomWidget.Name = "bottom";
bottomWidget.BoundsRelativeToParent = new RectangleDouble(10, 10, 190, 190);
int bottomGotEnter = 0;
int bottomGotLeave = 0;
bottomWidget.MouseEnter += (sender, e) => { if (bottomWidget.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); bottomGotEnter++; };
bottomWidget.MouseLeave += (sender, e) => { if (bottomWidget.UnderMouseState == UnderMouseState.FirstUnderMouse) throw new Exception("It must not be the first under the mouse."); bottomGotLeave++; };
int bottomGotEnterBounds = 0;
int bottomGotLeaveBounds = 0;
bottomWidget.MouseEnterBounds += (sender, e) => { if (bottomWidget.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); bottomGotEnterBounds++; };
bottomWidget.MouseLeaveBounds += (sender, e) => { if (bottomWidget.UnderMouseState != UnderMouseState.NotUnderMouse) throw new Exception("It must not be under the mouse."); bottomGotLeaveBounds++; };
container.AddChild(bottomWidget);
GuiWidget topWidget = new GuiWidget();
topWidget.Name = "top";
topWidget.BoundsRelativeToParent = new RectangleDouble(5, 20, 190, 190);
int topGotEnter = 0;
int topGotLeave = 0;
topWidget.MouseEnter += (sender, e) => { if (topWidget.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); topGotEnter++; };
topWidget.MouseLeave += (sender, e) => { if (topWidget.UnderMouseState == UnderMouseState.FirstUnderMouse) throw new Exception("It must not be the first under the mouse."); topGotLeave++; };
int topGotEnterBounds = 0;
int topGotLeaveBounds = 0;
topWidget.MouseEnterBounds += (sender, e) => { if (topWidget.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); topGotEnterBounds++; };
topWidget.MouseLeaveBounds += (sender, e) => { if (topWidget.UnderMouseState != UnderMouseState.NotUnderMouse) throw new Exception("It must not be under the mouse."); topGotLeaveBounds++; };
container.AddChild(topWidget);
Assert.IsTrue(topGotEnter == 0);
Assert.IsTrue(topGotLeave == 0);
Assert.IsTrue(topGotEnterBounds == 0);
Assert.IsTrue(topGotLeaveBounds == 0);
// move into the bottom widget only
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 1, 15, 0));
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 15, 15, 0));
Assert.IsTrue(bottomGotLeave == 0);
Assert.IsTrue(bottomGotEnter == 1);
Assert.IsTrue(bottomGotLeaveBounds == 0);
Assert.IsTrue(bottomGotEnterBounds == 1);
Assert.IsTrue(topGotLeave == 0);
Assert.IsTrue(topGotEnter == 0);
Assert.IsTrue(topGotLeaveBounds == 0);
Assert.IsTrue(topGotEnterBounds == 0);
// clear our states
bottomGotEnter = bottomGotLeave = bottomGotEnterBounds = bottomGotLeaveBounds = 0;
topGotEnter = topGotLeave = topGotEnterBounds = topGotLeaveBounds = 0;
// move out of the bottom widget only
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 1, 15, 0));
Assert.IsTrue(bottomGotLeave == 1);
Assert.IsTrue(bottomGotEnter == 0);
Assert.IsTrue(bottomGotLeaveBounds == 1);
Assert.IsTrue(bottomGotEnterBounds == 0);
Assert.IsTrue(topGotLeave == 0);
Assert.IsTrue(topGotEnter == 0);
Assert.IsTrue(topGotLeaveBounds == 0);
Assert.IsTrue(topGotEnterBounds == 0);
// move to just outside both widgets
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 1, 25, 0));
Assert.IsTrue(bottomWidget.TransformToScreenSpace(bottomWidget.LocalBounds).Contains(1, 25) == false);
Assert.IsTrue(topWidget.TransformToScreenSpace(topWidget.LocalBounds).Contains(1, 25) == false);
// clear our states
bottomGotEnter = bottomGotLeave = bottomGotEnterBounds = bottomGotLeaveBounds = 0;
topGotEnter = topGotLeave = topGotEnterBounds = topGotLeaveBounds = 0;
// move over the top widget when it is over the bottom widget (only the top should see this)
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 15, 25, 0));
Assert.IsTrue(bottomGotEnter == 0);
Assert.IsTrue(bottomGotLeave == 0);
Assert.IsTrue(bottomGotEnterBounds == 1);
Assert.IsTrue(bottomGotLeaveBounds == 0);
Assert.IsTrue(topGotEnter == 1);
Assert.IsTrue(topGotLeave == 0);
Assert.IsTrue(topGotEnterBounds == 1);
Assert.IsTrue(topGotLeaveBounds == 0);
// clear our states
bottomGotEnter = bottomGotLeave = bottomGotEnterBounds = bottomGotLeaveBounds = 0;
topGotEnter = topGotLeave = topGotEnterBounds = topGotLeaveBounds = 0;
// move out of the top widget into the bottom
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 15, 15, 0));
Assert.IsTrue(bottomGotEnter == 1);
Assert.IsTrue(bottomGotLeave == 0);
Assert.IsTrue(bottomGotEnterBounds == 0);
Assert.IsTrue(bottomGotLeaveBounds == 0);
Assert.IsTrue(topGotEnter == 0);
Assert.IsTrue(topGotLeave == 1);
Assert.IsTrue(topGotEnterBounds == 0);
Assert.IsTrue(topGotLeaveBounds == 1);
// clear our states
bottomGotEnter = bottomGotLeave = bottomGotEnterBounds = bottomGotLeaveBounds = 0;
topGotEnter = topGotLeave = topGotEnterBounds = topGotLeaveBounds = 0;
// move back up into the top and make sure we see the leave in the bottom
//.........这里部分代码省略.........
示例7: ValidateEnterAndLeaveEventsWhenCoverd
public void ValidateEnterAndLeaveEventsWhenCoverd()
{
// A widget contains two children the second completely covering the first.
// When the mouse moves into the first it should not recieve an enter event only a bounds enter event.
// When the mouse move out of the first it should recieve only a bounds exit, not an exit.
GuiWidget container = new GuiWidget();
container.Name = "continer";
container.LocalBounds = new RectangleDouble(0, 0, 200, 200);
GuiWidget coveredWidget = new GuiWidget();
coveredWidget.Name = "coveredWidget";
coveredWidget.BoundsRelativeToParent = new RectangleDouble(20, 20, 180, 180);
int gotEnterCovered = 0;
int gotLeaveCovered = 0;
coveredWidget.MouseEnter += (sender, e) => { if (coveredWidget.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); gotEnterCovered++; };
coveredWidget.MouseLeave += (sender, e) => { if (coveredWidget.UnderMouseState == UnderMouseState.FirstUnderMouse) throw new Exception("It must not be under the mouse."); gotLeaveCovered++; };
int gotEnterBoundsCovered = 0;
int gotLeaveBoundsCovered = 0;
coveredWidget.MouseEnterBounds += (sender, e) => { if (coveredWidget.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); gotEnterBoundsCovered++; };
coveredWidget.MouseLeaveBounds += (sender, e) => { if (coveredWidget.UnderMouseState != UnderMouseState.NotUnderMouse) throw new Exception("It must not be under the mouse."); gotLeaveBoundsCovered++; };
container.AddChild(coveredWidget);
GuiWidget coveredChildWidget = new GuiWidget();
coveredChildWidget.Name = "coveredChildWidget";
int gotEnterCoveredChild = 0;
int gotLeaveCoveredChild = 0;
coveredChildWidget.MouseEnter += (sender, e) => { if (coveredChildWidget.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); gotEnterCoveredChild++; };
coveredChildWidget.MouseLeave += (sender, e) => { if (coveredChildWidget.UnderMouseState == UnderMouseState.FirstUnderMouse) throw new Exception("It must not be under the mouse."); gotLeaveCoveredChild++; };
int gotEnterBoundsCoveredChild = 0;
int gotLeaveBoundsCoveredChild = 0;
coveredChildWidget.MouseEnterBounds += (sender, e) => { if (coveredChildWidget.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); gotEnterBoundsCoveredChild++; };
coveredChildWidget.MouseLeaveBounds += (sender, e) => { if (coveredChildWidget.UnderMouseState != UnderMouseState.NotUnderMouse) throw new Exception("It must not be under the mouse."); gotLeaveBoundsCoveredChild++; };
coveredWidget.AddChild(coveredChildWidget);
coveredChildWidget.BoundsRelativeToParent = coveredWidget.LocalBounds;
GuiWidget coverWidget = new GuiWidget();
coverWidget.Name = "coverWidget";
coverWidget.BoundsRelativeToParent = new RectangleDouble(10, 10, 190, 190);
int gotEnterCover = 0;
int gotLeaveCover = 0;
coverWidget.MouseEnter += (sender, e) => { if (coverWidget.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); gotEnterCover++; };
coverWidget.MouseLeave += (sender, e) => { if (coverWidget.UnderMouseState == UnderMouseState.FirstUnderMouse) throw new Exception("It must not be under the mouse."); gotLeaveCover++; };
int gotEnterBoundsCover = 0;
int gotLeaveBoundsCover = 0;
coverWidget.MouseEnterBounds += (sender, e) => { if (coverWidget.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); gotEnterBoundsCover++; };
coverWidget.MouseLeaveBounds += (sender, e) => { if (coverWidget.UnderMouseState != UnderMouseState.NotUnderMouse) throw new Exception("It must not be under the mouse."); gotLeaveBoundsCover++; };
container.AddChild(coverWidget);
Assert.IsTrue(gotLeaveCover == 0);
Assert.IsTrue(gotEnterCover == 0);
Assert.IsTrue(gotLeaveCovered == 0);
Assert.IsTrue(gotEnterCovered == 0);
Assert.IsTrue(gotLeaveCoveredChild == 0);
Assert.IsTrue(gotEnterCoveredChild == 0);
// put the mouse into the widget but outside the children
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 5, 5, 0));
Assert.IsTrue(gotLeaveCover == 0);
Assert.IsTrue(gotEnterCover == 0);
Assert.IsTrue(gotLeaveBoundsCover == 0);
Assert.IsTrue(gotEnterBoundsCover == 0);
Assert.IsTrue(gotLeaveCovered == 0);
Assert.IsTrue(gotEnterCovered == 0);
Assert.IsTrue(gotLeaveBoundsCovered == 0);
Assert.IsTrue(gotEnterBoundsCovered == 0);
Assert.IsTrue(gotLeaveCoveredChild == 0);
Assert.IsTrue(gotEnterCoveredChild == 0);
Assert.IsTrue(gotLeaveBoundsCoveredChild == 0);
Assert.IsTrue(gotEnterBoundsCoveredChild == 0);
// move it into the cover
gotEnterCover = 0; gotEnterBoundsCover = 0; gotLeaveCover = 0; gotLeaveBoundsCover = 0;
gotEnterCovered = 0; gotEnterBoundsCovered = 0; gotLeaveCovered = 0; gotLeaveBoundsCovered = 0;
gotEnterCoveredChild = 0; gotEnterBoundsCoveredChild = 0; gotLeaveCoveredChild = 0; gotLeaveBoundsCoveredChild = 0;
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 15, 15, 0));
Assert.IsTrue(gotLeaveCover == 0);
Assert.IsTrue(gotEnterCover == 1);
Assert.IsTrue(gotLeaveBoundsCover == 0);
Assert.IsTrue(gotEnterBoundsCover == 1);
Assert.IsTrue(gotLeaveCovered == 0);
Assert.IsTrue(gotEnterCovered == 0);
Assert.IsTrue(gotLeaveBoundsCovered == 0);
Assert.IsTrue(gotEnterBoundsCovered == 0);
Assert.IsTrue(gotLeaveCoveredChild == 0);
Assert.IsTrue(gotEnterCoveredChild == 0);
Assert.IsTrue(gotLeaveBoundsCoveredChild == 0);
Assert.IsTrue(gotEnterBoundsCoveredChild == 0);
// now move it inside cover and make sure it does not re-trigger either event
gotEnterCover = 0; gotEnterBoundsCover = 0; gotLeaveCover = 0; gotLeaveBoundsCover = 0;
gotEnterCovered = 0; gotEnterBoundsCovered = 0; gotLeaveCovered = 0; gotLeaveBoundsCovered = 0;
gotEnterCoveredChild = 0; gotEnterBoundsCoveredChild = 0; gotLeaveCoveredChild = 0; gotLeaveBoundsCoveredChild = 0;
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 16, 15, 0));
Assert.IsTrue(gotLeaveCover == 0);
Assert.IsTrue(gotEnterCover == 0);
Assert.IsTrue(gotLeaveBoundsCover == 0);
Assert.IsTrue(gotEnterBoundsCover == 0);
Assert.IsTrue(gotLeaveCovered == 0);
Assert.IsTrue(gotEnterCovered == 0);
Assert.IsTrue(gotLeaveBoundsCovered == 0);
//.........这里部分代码省略.........
示例8: ValidateEnterAndLeaveEventsWhenNested
public void ValidateEnterAndLeaveEventsWhenNested()
{
GuiWidget container = new GuiWidget();
container.Name = "continer";
container.LocalBounds = new RectangleDouble(0, 0, 200, 200);
GuiWidget regionA = new GuiWidget();
regionA.Name = "regionA";
regionA.BoundsRelativeToParent = new RectangleDouble(10, 10, 190, 190);
int gotEnterA = 0;
int gotLeaveA = 0;
regionA.MouseEnter += (sender, e) => { if (regionA.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); gotEnterA++; };
regionA.MouseLeave += (sender, e) => { if (regionA.UnderMouseState == UnderMouseState.FirstUnderMouse) throw new Exception("It must not be under the mouse."); gotLeaveA++; };
int gotEnterBoundsA = 0;
int gotLeaveBoundsA = 0;
regionA.MouseEnterBounds += (sender, e) => { if (regionA.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); gotEnterBoundsA++; };
regionA.MouseLeaveBounds += (sender, e) => { if (regionA.UnderMouseState != UnderMouseState.NotUnderMouse) throw new Exception("It must not be under the mouse."); gotLeaveBoundsA++; };
GuiWidget regionB = new GuiWidget();
regionB.Name = "regionB";
regionB.AddChild(regionA);
regionB.SetBoundsToEncloseChildren();
container.AddChild(regionB);
int gotEnterB = 0;
int gotLeaveB = 0;
regionB.MouseEnter += (sender, e) => { if (regionB.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); gotEnterB++; };
regionB.MouseLeave += (sender, e) => { if (regionB.UnderMouseState == UnderMouseState.FirstUnderMouse) throw new Exception("It must not be under the mouse."); gotLeaveB++; };
int gotEnterBoundsB = 0;
int gotLeaveBoundsB = 0;
regionB.MouseEnterBounds += (sender, e) => { if (regionB.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); gotEnterBoundsB++; };
regionB.MouseLeaveBounds += (sender, e) => { if (regionB.UnderMouseState != UnderMouseState.NotUnderMouse) throw new Exception("It must not be under the mouse."); gotLeaveBoundsB++; };
Assert.IsTrue(gotLeaveA == 0);
Assert.IsTrue(gotEnterA == 0);
Assert.IsTrue(gotLeaveB == 0);
Assert.IsTrue(gotEnterB == 0);
// put the mouse into the widget but outside regionA and region B
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 5, 5, 0));
Assert.IsTrue(gotLeaveA == 0);
Assert.IsTrue(gotEnterA == 0);
Assert.IsTrue(gotLeaveBoundsA == 0);
Assert.IsTrue(gotEnterBoundsA == 0);
Assert.IsTrue(gotLeaveB == 0);
Assert.IsTrue(gotEnterB == 0);
Assert.IsTrue(gotLeaveBoundsB == 0);
Assert.IsTrue(gotEnterBoundsB == 0);
// move it into regionA
gotEnterA = 0; gotEnterBoundsA = 0; gotLeaveA = 0; gotLeaveBoundsA = 0;
gotEnterB = 0; gotEnterBoundsB = 0; gotLeaveB = 0; gotLeaveBoundsB = 0;
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 15, 15, 0));
Assert.IsTrue(gotLeaveA == 0);
Assert.IsTrue(gotEnterA == 1);
Assert.IsTrue(gotLeaveBoundsA == 0);
Assert.IsTrue(gotEnterBoundsA == 1);
Assert.IsTrue(gotLeaveB == 0);
Assert.IsTrue(gotEnterB == 0);
Assert.IsTrue(gotLeaveBoundsB == 0);
Assert.IsTrue(gotEnterBoundsB == 1);
// now move it inside regionA and make sure it does not re-trigger either event
gotEnterA = 0; gotEnterBoundsA = 0; gotLeaveA = 0; gotLeaveBoundsA = 0;
gotEnterB = 0; gotEnterBoundsB = 0; gotLeaveB = 0; gotLeaveBoundsB = 0;
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 16, 15, 0));
Assert.IsTrue(gotLeaveA == 0);
Assert.IsTrue(gotEnterA == 0);
Assert.IsTrue(gotLeaveBoundsA == 0);
Assert.IsTrue(gotEnterBoundsA == 0);
Assert.IsTrue(gotLeaveB == 0);
Assert.IsTrue(gotEnterB == 0);
Assert.IsTrue(gotLeaveBoundsB == 0);
Assert.IsTrue(gotEnterBoundsB == 0);
// now leave and make sure we see the leave
gotEnterA = 0; gotEnterBoundsA = 0; gotLeaveA = 0; gotLeaveBoundsA = 0;
gotEnterB = 0; gotEnterBoundsB = 0; gotLeaveB = 0; gotLeaveBoundsB = 0;
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, -5, -5, 0));
Assert.IsTrue(gotLeaveA == 1);
Assert.IsTrue(gotEnterA == 0);
Assert.IsTrue(gotLeaveBoundsA == 1);
Assert.IsTrue(gotEnterBoundsA == 0);
Assert.IsTrue(gotLeaveB == 0);
Assert.IsTrue(gotEnterB == 0);
Assert.IsTrue(gotLeaveBoundsB == 1);
Assert.IsTrue(gotEnterBoundsB == 0);
// move back on
gotEnterA = 0; gotEnterBoundsA = 0; gotLeaveA = 0; gotLeaveBoundsA = 0;
gotEnterB = 0; gotEnterBoundsB = 0; gotLeaveB = 0; gotLeaveBoundsB = 0;
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 16, 15, 0));
// now leave only the inside widget and make sure we see the leave
Assert.IsTrue(gotEnterA == 1);
Assert.IsTrue(gotLeaveA == 0);
Assert.IsTrue(gotLeaveBoundsA == 0);
Assert.IsTrue(gotEnterBoundsA == 1);
Assert.IsTrue(gotLeaveB == 0);
Assert.IsTrue(gotEnterB == 0);
Assert.IsTrue(gotLeaveBoundsB == 0);
Assert.IsTrue(gotEnterBoundsB == 1);
//.........这里部分代码省略.........
示例9: MouseCapturedSpressesLeaveEventsInButtonsSameAsRectangles
public void MouseCapturedSpressesLeaveEventsInButtonsSameAsRectangles()
{
GuiWidget container = new GuiWidget();
container.Name = "continer";
container.LocalBounds = new RectangleDouble(0, 0, 200, 200);
Button buttonA = new Button();
buttonA.Name = "buttonA";
buttonA.BoundsRelativeToParent = new RectangleDouble(0, 0, 180, 180);
buttonA.OriginRelativeParent = new VectorMath.Vector2(10, 10);
container.AddChild(buttonA);
bool aGotEnter = false;
bool aGotLeave = false;
bool aGotMove = false;
double aMoveX = 0;
double aMoveY = 0;
buttonA.MouseEnter += (sender, e) => { aGotEnter = true; };
buttonA.MouseLeave += (sender, e) => { aGotLeave = true; };
buttonA.MouseMove += (sender, mouseEvent) => { aGotMove = true; aMoveX = mouseEvent.X; aMoveY = mouseEvent.Y; };
// make sure we know we are entered and captued on a down event
container.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, 15, 15, 0));
Assert.IsTrue(buttonA.FirstWidgetUnderMouse == true);
Assert.IsTrue(buttonA.MouseCaptured == true);
Assert.IsTrue(aGotEnter == true);
Assert.IsTrue(aGotLeave == false);
Assert.IsTrue(aGotMove == false);
// make sure we stay on top when internal moves occure
aGotEnter = aGotLeave = aGotMove = false;
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 0, 16, 16, 0));
Assert.IsTrue(buttonA.FirstWidgetUnderMouse == true);
Assert.IsTrue(buttonA.MouseCaptured == true);
Assert.IsTrue(aGotEnter == false);
Assert.IsTrue(aGotLeave == false);
Assert.IsTrue(aGotMove == true);
aGotEnter = aGotLeave = aGotMove = false;
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 0, 20, 20, 0));
// lets prove that the move has been transformed into the correct coordinate system
Assert.IsTrue(aMoveX == 10 && aMoveY == 10);
Assert.IsTrue(buttonA.FirstWidgetUnderMouse == true);
Assert.IsTrue(buttonA.MouseCaptured == true);
Assert.IsTrue(aGotEnter == false);
Assert.IsTrue(aGotLeave == false);
Assert.IsTrue(aGotMove == true);
// make sure we see leave events when captured
aGotEnter = aGotLeave = aGotMove = false;
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 0));
Assert.IsTrue(container.FirstWidgetUnderMouse == false);
Assert.IsTrue(buttonA.FirstWidgetUnderMouse == false);
Assert.IsTrue(buttonA.MouseCaptured == true);
Assert.IsTrue(aGotEnter == false);
Assert.IsTrue(aGotLeave == true);
Assert.IsTrue(aGotMove == true);
// make sure we see enter events when captured
aGotEnter = aGotLeave = aGotMove = false;
container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 15, 15, 0));
Assert.IsTrue(buttonA.FirstWidgetUnderMouse == true);
Assert.IsTrue(buttonA.MouseCaptured == true);
Assert.IsTrue(aGotEnter == true);
Assert.IsTrue(aGotLeave == false);
Assert.IsTrue(aGotMove == true);
}