当前位置: 首页>>代码示例>>C#>>正文


C# GuiWidget.SetBoundsToEncloseChildren方法代码示例

本文整理汇总了C#中GuiWidget.SetBoundsToEncloseChildren方法的典型用法代码示例。如果您正苦于以下问题:C# GuiWidget.SetBoundsToEncloseChildren方法的具体用法?C# GuiWidget.SetBoundsToEncloseChildren怎么用?C# GuiWidget.SetBoundsToEncloseChildren使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GuiWidget的用法示例。


在下文中一共展示了GuiWidget.SetBoundsToEncloseChildren方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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);
//.........这里部分代码省略.........
开发者ID:CNCBrasil,项目名称:agg-sharp,代码行数:101,代码来源:MouseInteractionTests.cs


注:本文中的GuiWidget.SetBoundsToEncloseChildren方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。