public void SetCursorPositionToCenter() { _ignoreNextMouseMoveEvent = true; var loc = _form.PointToScreen(new Point(0, 0)); Cursor.Position = new Point(loc.X + ClientWidth / 2, loc.Y + ClientHeight / 2); }
public RenderFormSurface(RenderForm renderForm) { Point topLeft = renderForm.PointToScreen(new Point(0, 0)); m_hwnd = renderForm.Handle; m_width = renderForm.ClientSize.Width; m_height = renderForm.ClientSize.Height; }
private void HandleMouseMove(object sender, MouseEventArgs e) { var cent = new System.Drawing.Point(renderForm.Width / 2, renderForm.Height / 2); if (!firstMouseMove) { deltaMouseX -= cent.X - e.X; deltaMouseY -= cent.Y - e.Y; } firstMouseMove = false; Cursor.Position = renderForm.PointToScreen(cent); }
private void Update() { Time += 0.001f; if (Time > Math.PI * 2.0) { Time -= (float)(Math.PI * 2.0); } Log.Instance.Update(); // get input Input.Instance.Update(); // gui scaling GuiScaling.Instance.Update(); // handle input KeyboardState keyboardState = Input.Instance.CurrentInput.KeyboardState; KeyboardState prevKeyboardState = Input.Instance.LastInput.KeyboardState; MouseState mouseState = Input.Instance.CurrentInput.MouseState; if (prevKeyboardState.IsPressed(Key.O) && keyboardState.IsReleased(Key.O)) { OpenGui(new GuiOptionsForm()); } if (prevKeyboardState.IsPressed(Key.P) && keyboardState.IsReleased(Key.P)) { OpenGui(new GuiDebugForm()); } if (prevKeyboardState.IsPressed(Key.F11) && keyboardState.IsReleased(Key.F11)) { GlobalRenderer.Instance.ToggleFullScreen(); } if (prevKeyboardState.IsPressed(Key.Escape) && keyboardState.IsReleased(Key.Escape) && Mode == GameMode.Gui) { CloseGui(); } else if (keyboardState.IsReleased(Key.V) && prevKeyboardState.IsPressed(Key.V)) { p.ToggleReport(); } else if (keyboardState.IsReleased(Key.C) && prevKeyboardState.IsPressed(Key.C)) { showProfiler = !showProfiler; } else if (keyboardState.IsReleased(Key.Z) && prevKeyboardState.IsPressed(Key.Z)) { p.ToggleMarkedSection(); } else if (keyboardState.IsReleased(Key.X) && prevKeyboardState.IsPressed(Key.X)) { p.SelectedSection = p.MarkedSection; } else if (keyboardState.IsReleased(Key.Backspace) && prevKeyboardState.IsPressed(Key.Backspace)) { int index = p.SelectedSection.LastIndexOf("."); if (index >= 0) { p.SelectedSection = p.SelectedSection.Substring(0, index); } } p.StartSection("2dgui"); if (ActiveGui != null) { ActiveGui.Update(); } p.EndSection(); // update world World.Instance.Update(); // reset mouse System.Windows.Forms.Cursor.Position = form.PointToScreen(new Point(Width / 2, Height / 2)); System.Windows.Forms.Cursor.Hide(); // update global game clock CurrentTick++; }