public void ToolTipCloseOnLeave() { TempData tempData = new TempData(); SystemWindow systemWindow = CreateTwoChildWindow(tempData); // move into the first widget systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, 11, 11, 0)); UiThread.InvokePendingActions(); // sleep long enough to show the tool tip Thread.Sleep((int)(systemWindow.ToolTipManager.InitialDelay * 1000 + minMsToBias)); UiThread.InvokePendingActions(); // make sure the tool tip came up Assert.IsTrue(systemWindow.Children.Count == 3); Assert.IsTrue(tempData.showCount == 1); Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == toolTip1Text); // move off the first widget systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, 9, 9, 0)); Thread.Sleep(minMsTimeToRespond); // sleep enough for the tool tip to want to respond UiThread.InvokePendingActions(); // make sure the tool tip went away Assert.IsTrue(systemWindow.Children.Count == 2); Assert.IsTrue(tempData.popCount == 1); Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == ""); }
public override void SetCursorPosition(int x, int y) { SystemWindow systemWindow = SystemWindow.AllOpenSystemWindows[SystemWindow.AllOpenSystemWindows.Count - 1]; if (currentlyHookedWindow != systemWindow) { if (currentlyHookedWindow != null) { currentlyHookedWindow.DrawAfter -= DrawMouse; } currentlyHookedWindow = systemWindow; if (currentlyHookedWindow != null) { currentlyHookedWindow.DrawAfter += DrawMouse; } } currentMousePosition = new Point2D(x, y); Point2D windowPosition = AutomationRunner.ScreenToSystemWindow(currentMousePosition, systemWindow); if (LeftButtonDown) { MouseEventArgs aggEvent = new MouseEventArgs(MouseButtons.Left, 1, windowPosition.x, windowPosition.y, 0); UiThread.RunOnIdle(() => systemWindow.OnMouseMove(aggEvent)); } else { MouseEventArgs aggEvent = new MouseEventArgs(MouseButtons.None, 1, windowPosition.x, windowPosition.y, 0); UiThread.RunOnIdle(() => systemWindow.OnMouseMove(aggEvent)); } }
public void MoveFastFromToolTipToToolTip() { TempData tempData = new TempData(); SystemWindow systemWindow = CreateTwoChildWindow(tempData); // move into the first widget systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, 11, 11, 0)); UiThread.InvokePendingActions(); // sleep long enough to show the tool tip Thread.Sleep((int)(systemWindow.ToolTipManager.InitialDelay * 1000 + minMsToBias)); UiThread.InvokePendingActions(); // make sure the tool tip came up Assert.IsTrue(systemWindow.Children.Count == 3); Assert.IsTrue(tempData.showCount == 1); Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == toolTip1Text); // wait 1/2 long enough for the tool tip to go away Thread.Sleep((int)(systemWindow.ToolTipManager.AutoPopDelay * 1000 / 2 + minMsToBias)); UiThread.InvokePendingActions(); // move onto the other widget systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, 31, 31, 0)); Thread.Sleep(minMsTimeToRespond); // sleep enough for the tool tip to want to respond UiThread.InvokePendingActions(); // make sure the first tool tip went away Assert.IsTrue(systemWindow.Children.Count == 2); Assert.IsTrue(tempData.popCount == 1); Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == ""); // wait long enough for the second tool tip to come up Thread.Sleep((int)(systemWindow.ToolTipManager.ReshowDelay * 1000 + minMsToBias)); UiThread.InvokePendingActions(); // make sure the tool tip 2 came up Assert.IsTrue(systemWindow.Children.Count == 3); Assert.IsTrue(tempData.showCount == 2); Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == toolTip2Text); }
public void ToolTipInitialOpenTests() { TempData tempData = new TempData(); // test simple open then wait for pop SystemWindow systemWindow = CreateTwoChildWindow(tempData); // move into the first widget systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, 11, 11, 0)); UiThread.InvokePendingActions(); // show that initialy we don't have a tooltip Assert.IsTrue(systemWindow.Children.Count == 2); // sleep 1/2 long enough to show the tool tip Thread.Sleep((int)(systemWindow.ToolTipManager.InitialDelay / 2 * 1000 + minMsToBias)); UiThread.InvokePendingActions(); // make sure it is still not up Assert.IsTrue(systemWindow.Children.Count == 2); Assert.IsTrue(tempData.showCount == 0); Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == ""); // sleep 1/2 long enough to show the tool tip Thread.Sleep((int)(systemWindow.ToolTipManager.InitialDelay / 2 * 1000 + minMsToBias)); UiThread.InvokePendingActions(); // make sure the tool tip came up Assert.IsTrue(systemWindow.Children.Count == 3); Assert.IsTrue(tempData.showCount == 1); Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == toolTip1Text); // wait 1/2 long enough for the tool tip to go away Thread.Sleep((int)(systemWindow.ToolTipManager.AutoPopDelay * 1000 / 2 + minMsToBias)); UiThread.InvokePendingActions(); // make sure the tool did not go away Assert.IsTrue(systemWindow.Children.Count == 3); Assert.IsTrue(tempData.popCount == 0); Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == toolTip1Text); // wait 1/2 long enough for the tool tip to go away Thread.Sleep((int)(systemWindow.ToolTipManager.AutoPopDelay * 1000 / 2 + minMsToBias)); UiThread.InvokePendingActions(); // make sure the tool tip went away Assert.IsTrue(systemWindow.Children.Count == 2); Assert.IsTrue(tempData.popCount == 1); Assert.IsTrue(systemWindow.ToolTipManager.CurrentText == ""); }
public override void CreateMouseEvent(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo) { // figure out where this is on our agg windows // for now only send mouse events to the top most window //foreach (SystemWindow systemWindow in SystemWindow.OpenWindows) SystemWindow systemWindow = SystemWindow.AllOpenSystemWindows[SystemWindow.AllOpenSystemWindows.Count - 1]; { Point2D windowPosition = AutomationRunner.ScreenToSystemWindow(currentMousePosition, systemWindow); if (systemWindow.LocalBounds.Contains(windowPosition)) { MouseButtons mouseButtons = MapButtons(cButtons); // create the agg event if (dwFlags == MOUSEEVENTF_LEFTDOWN) { MouseEventArgs aggEvent = new MouseEventArgs(mouseButtons, 1, windowPosition.x, windowPosition.y, 0); // send it to the window if (LeftButtonDown) { UiThread.RunOnIdle(() => systemWindow.OnMouseMove(aggEvent)); } else { UiThread.RunOnIdle(() => systemWindow.OnMouseDown(aggEvent)); } } else if (dwFlags == MOUSEEVENTF_LEFTUP) { MouseEventArgs aggEvent = new MouseEventArgs(mouseButtons, 0, windowPosition.x, windowPosition.y, 0); // send it to the window UiThread.RunOnIdle(() => systemWindow.OnMouseUp(aggEvent)); } else if (dwFlags == MOUSEEVENTF_RIGHTDOWN) { } else if (dwFlags == MOUSEEVENTF_RIGHTUP) { } else if (dwFlags == MOUSEEVENTF_MIDDLEDOWN) { } else if (dwFlags == MOUSEEVENTF_MIDDLEUP) { } } } base.CreateMouseEvent(dwFlags, dx, dy, cButtons, dwExtraInfo); }
private static SystemWindow CreateTwoChildWindow(TempData tempData) { SystemWindow systemWindow = new SystemWindow(200, 200); GuiWidget toolTip1 = new GuiWidget() { LocalBounds = new RectangleDouble(10, 10, 20, 20), ToolTipText = toolTip1Text, }; GuiWidget toolTip2 = new GuiWidget() { LocalBounds = new RectangleDouble(30, 30, 40, 40), ToolTipText = toolTip2Text, }; systemWindow.ToolTipManager.ToolTipShown += (sender, stringEvent) => { tempData.showCount++; tempData.lastShownText = stringEvent.Data; }; systemWindow.ToolTipManager.ToolTipPop += (sender, e) => { tempData.popCount++; }; systemWindow.AddChild(toolTip1); systemWindow.AddChild(toolTip2); Assert.IsTrue(systemWindow.Children.Count == 2); // make sure we start out with only the widgets (no tool tip) systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, 0, 0, 0)); UiThread.InvokePendingActions(); Assert.IsTrue(systemWindow.Children.Count == 2); tempData.lastShownText = ""; tempData.showCount = 0; tempData.popCount = 0; return(systemWindow); }
/// <summary> /// Creates or connects a PlatformWindow to the given SystemWindow /// </summary> public void ShowSystemWindow(SystemWindow systemWindow) { if (_graphicsDevice == null) { WindowCreateInfo windowCI = new WindowCreateInfo() { X = 100, Y = 100, WindowWidth = 960, WindowHeight = 540, WindowTitle = "Veldrid Tutorial", }; Sdl2Window window = VeldridStartup.CreateWindow(ref windowCI); veldridPlatformWindow = new VeldridSystemWindow(this); systemWindow.PlatformWindow = veldridPlatformWindow; _graphicsDevice = VeldridStartup.CreateGraphicsDevice(window, GraphicsBackend.OpenGL); window.KeyDown += (KeyEvent keyEvent) => { systemWindow.OnKeyDown( new KeyEventArgs((Keys)keyEvent.Key)); }; window.KeyUp += (KeyEvent keyEvent) => { systemWindow.OnKeyUp( new KeyEventArgs((Keys)keyEvent.Key)); }; // setup our veldrid gl immediate mode emulator var veldridGl = new VeldridGL(); MatterHackers.RenderOpenGl.OpenGl.GL.Instance = veldridGl; veldridGl.CreateResources(_graphicsDevice); ShaderData.Instance.CreateResources(_graphicsDevice); long runNextMs = 0; VectorMath.Vector2 lastPosition = VectorMath.Vector2.Zero; while (window.Exists) { InputSnapshot inputSnapshot = window.PumpEvents(); var position = new VectorMath.Vector2(inputSnapshot.MousePosition.X, window.Height - inputSnapshot.MousePosition.Y); if (lastPosition != position) { systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, position.X, position.Y, 0)); } if (inputSnapshot.WheelDelta != 0) { systemWindow.OnMouseWheel(new MouseEventArgs(MouseButtons.None, 0, position.X, position.Y, (int)inputSnapshot.WheelDelta * 120)); } if (runNextMs <= UiThread.CurrentTimerMs) { UiThread.InvokePendingActions(); runNextMs = UiThread.CurrentTimerMs + 10; } foreach (var mouseEvent in inputSnapshot.MouseEvents) { MouseButtons buttons = MapMouseButtons(mouseEvent.MouseButton); if (inputSnapshot.IsMouseDown(mouseEvent.MouseButton)) { systemWindow.OnMouseDown(new MouseEventArgs(buttons, 1, position.X, position.Y, 0)); } else { systemWindow.OnMouseUp(new MouseEventArgs(buttons, 0, position.X, position.Y, 0)); } } systemWindow.Width = veldridPlatformWindow.Width = window.Width; systemWindow.Height = veldridPlatformWindow.Height = window.Height; var graphics2D = veldridPlatformWindow.NewGraphics2D(); // We must call on draw background as this is effectively our child and that is the way it is done in GuiWidget. // Parents call child OnDrawBackground before they call OnDraw systemWindow.OnDrawBackground(graphics2D); systemWindow.OnDraw(graphics2D); _graphicsDevice.SwapBuffers(); // Copy to screen/backbuffer //window.PumpEvents(); } // MyOpenGLView.RootGLView.ShowSystemWindow(systemWindow); veldridGl.DisposeResources(); ShaderData.Instance.DisposeResources(); } MouseButtons MapMouseButtons(MouseButton mouseButton) { switch (mouseButton) { case MouseButton.Left: return(MouseButtons.Left); case MouseButton.Middle: break; case MouseButton.Right: break; case MouseButton.Button1: break; case MouseButton.Button2: break; case MouseButton.Button3: break; case MouseButton.Button4: break; case MouseButton.Button5: break; case MouseButton.Button6: break; case MouseButton.Button7: break; case MouseButton.Button8: break; case MouseButton.Button9: break; case MouseButton.LastButton: break; } return(MouseButtons.None); } }
private static SystemWindow CreateTwoChildWindow(TempData tempData) { SystemWindow systemWindow = new SystemWindow(200, 200); GuiWidget toolTip1 = new GuiWidget() { LocalBounds = new RectangleDouble(10, 10, 20, 20), ToolTipText = toolTip1Text, }; GuiWidget toolTip2 = new GuiWidget() { LocalBounds = new RectangleDouble(30, 30, 40, 40), ToolTipText = toolTip2Text, }; systemWindow.ToolTipManager.ToolTipShown += (sender, stringEvent) => { tempData.showCount++; tempData.lastShownText = stringEvent.Data; }; systemWindow.ToolTipManager.ToolTipPop += (sender, e) => { tempData.popCount++; }; systemWindow.AddChild(toolTip1); systemWindow.AddChild(toolTip2); Assert.IsTrue(systemWindow.Children.Count == 2); // make sure we start out with only the widgets (no tool tip) systemWindow.OnMouseMove(new MouseEventArgs(MouseButtons.None, 0, 0, 0, 0)); UiThread.DoRunAllPending(); Assert.IsTrue(systemWindow.Children.Count == 2); tempData.lastShownText = ""; tempData.showCount = 0; tempData.popCount = 0; return systemWindow; }
public void ValidateEnterLeaveOnWidgetBoundsChange() { GuiWidget container = new SystemWindow(200, 200); container.Name = "container"; GuiWidget regionA = new GuiWidget(); regionA.Name = "regionA"; regionA.BoundsRelativeToParent = new RectangleDouble(10, 10, 190, 190); int gotEnter = 0; int gotLeave = 0; regionA.MouseEnter += (sender, e) => { if (regionA.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); gotEnter++; }; regionA.MouseLeave += (sender, e) => { if (regionA.UnderMouseState == UnderMouseState.FirstUnderMouse) throw new Exception("It must not be under the mouse."); gotLeave++; }; int gotEnterBounds = 0; int gotLeaveBounds = 0; regionA.MouseEnterBounds += (sender, e) => { if (regionA.UnderMouseState == UnderMouseState.NotUnderMouse) throw new Exception("It must be under the mouse."); gotEnterBounds++; }; regionA.MouseLeaveBounds += (sender, e) => { if (regionA.UnderMouseState != UnderMouseState.NotUnderMouse) throw new Exception("It must not be under the mouse."); gotLeaveBounds++; }; container.AddChild(regionA); Assert.IsTrue(gotLeave == 0); Assert.IsTrue(gotEnter == 0); Assert.IsTrue(gotLeaveBounds == 0); Assert.IsTrue(gotEnterBounds == 0); // put the mouse into the widget but outside regionA container.OnMouseMove(new MouseEventArgs(MouseButtons.Left, 1, 5, 5, 0)); Assert.IsTrue(regionA.UnderMouseState == UnderMouseState.NotUnderMouse); Assert.IsTrue(gotLeave == 0); Assert.IsTrue(gotEnter == 0); Assert.IsTrue(gotLeaveBounds == 0); Assert.IsTrue(gotEnterBounds == 0); // move regionA under mouse regionA.BoundsRelativeToParent = new RectangleDouble(0, 0, 180, 180); Assert.IsTrue(regionA.UnderMouseState == UnderMouseState.FirstUnderMouse); Assert.IsTrue(gotLeave == 0); Assert.IsTrue(gotEnter == 1); Assert.IsTrue(gotLeaveBounds == 0); Assert.IsTrue(gotEnterBounds == 1); // now regionA and make sure it does not re-trigger either event gotEnter = 0; gotEnterBounds = 0; regionA.BoundsRelativeToParent = new RectangleDouble(1, 1, 181, 181); Assert.IsTrue(regionA.UnderMouseState == UnderMouseState.FirstUnderMouse); Assert.IsTrue(gotLeave == 0); Assert.IsTrue(gotEnter == 0); Assert.IsTrue(gotLeaveBounds == 0); Assert.IsTrue(gotEnterBounds == 0); // now move out from under mouse and make sure we see the leave regionA.BoundsRelativeToParent = new RectangleDouble(10, 10, 190, 190); Assert.IsTrue(gotLeave == 1); Assert.IsTrue(gotEnter == 0); Assert.IsTrue(gotLeaveBounds == 1); Assert.IsTrue(gotEnterBounds == 0); // move back under gotLeave = gotEnter = gotLeaveBounds = gotEnterBounds = 0; regionA.BoundsRelativeToParent = new RectangleDouble(0, 0, 180, 180); Assert.IsTrue(gotEnter == 1); Assert.IsTrue(gotLeave == 0); Assert.IsTrue(gotLeaveBounds == 0); Assert.IsTrue(gotEnterBounds == 1); }