public static IEnumerable <InputMessage> TranslateInputMessages( Rectangle panelFrame, IEnumerable <InputMessage> inputMessages) { foreach (var message in inputMessages) { Point2D getPositionInPanel() { var pos = message.Value.MousePosition; pos = new Point2D(pos.X - panelFrame.X, pos.Y - panelFrame.Y); pos = new Point2D( MathUtility.Clamp(pos.X, 0, panelFrame.Width), MathUtility.Clamp(pos.Y, 0, panelFrame.Height)); return(pos); } var translatedMessage = message; switch (message.MessageType) { case InputMessageType.MouseLeftButtonDown: case InputMessageType.MouseLeftButtonUp: case InputMessageType.MouseMiddleButtonDown: case InputMessageType.MouseMiddleButtonUp: case InputMessageType.MouseRightButtonDown: case InputMessageType.MouseRightButtonUp: translatedMessage = InputMessage.CreateMouseButton( message.MessageType, getPositionInPanel()); break; case InputMessageType.MouseMove: translatedMessage = InputMessage.CreateMouseMove( getPositionInPanel()); break; } yield return(translatedMessage); } }
private void OnInputMessageReceived(object sender, InputMessageEventArgs e) { if (!IsGameViewActive) { return; } Point2D getPositionInPanel() { var pos = e.Message.Value.MousePosition; pos.X -= _frame.X; pos.Y -= _frame.Y; return(pos); } switch (e.Message.MessageType) { case InputMessageType.MouseLeftButtonDown: case InputMessageType.MouseLeftButtonUp: case InputMessageType.MouseMiddleButtonDown: case InputMessageType.MouseMiddleButtonUp: case InputMessageType.MouseRightButtonDown: case InputMessageType.MouseRightButtonUp: e = new InputMessageEventArgs(InputMessage.CreateMouseButton( e.Message.MessageType, getPositionInPanel())); break; case InputMessageType.MouseMove: e = new InputMessageEventArgs(InputMessage.CreateMouseMove( getPositionInPanel())); break; } InputMessageReceived?.Invoke(this, e); }