public void Render(RenderInfo renderInfo, MouseMode mouseMode, Control control, InputState inputState) { using (_canvas.SetUpFrame(renderInfo, mouseMode)) { if (inputState.Mouse != null) { /* Convert the screen coordinates into virtual canvas coordinates. */ inputState.Mouse.Position.X *= _canvas.Width / renderInfo.Width; inputState.Mouse.Position.Y *= _canvas.Height / renderInfo.Height; } control.HandleInput(inputState); control.Render(_canvas); DrawFps(_canvas); } }
protected override void OnInput(InputState input) { /* * This should behave like standard button on Windows. * * If you press and release the mouse button INSIDE the Button area, * raise a click event. * * If you press the mouse button, move OUTSIDE the Button area, and release * it there, DON'T raise a click event. * * If you press the mouse button outside the Button area, don't raise anything. * * Also, if the mouse is inside the Button area, set IsHovered. */ IsHovered = input.Mouse != null && Left != null && Top != null && Rectangle.FromSize(Left.Value, Top.Value, Width, Height).Contains(input.Mouse.Position); if (!input.Mouse.LeftButtonPressed) { if (IsPressed) { if (IsHovered) { Click?.Invoke(); } IsPressed = false; } } else if (IsHovered && !_wasLeftMouseButtonPressed) { IsPressed = true; } _wasLeftMouseButtonPressed = input.Mouse.LeftButtonPressed; }
private InputState GetInputState() { System.Drawing.Point mousePoint; NativeMethods.GetCursorPos(out mousePoint); mousePoint = _gameWindow.PointToClient(mousePoint); var inputState = new InputState(); inputState.Mouse = new Ui.Framework.Input.MouseState() { Position = new Point(mousePoint.X, mousePoint.Y), LeftButtonPressed = _mouseState.LeftButton == ButtonState.Pressed, }; inputState.Keyboard = new Ui.Framework.Input.KeyboardState(_uiKeyboardState); return inputState; }