public void MouseWheel(UserCommandArgs userCommandArgs, KeyModifiers modifiers) { if (userCommandArgs is ScrollCommandArgs mouseWheelCommandArgs) { contentArea?.UpdateScaleAt(mouseWheelCommandArgs.Position, Math.Sign(mouseWheelCommandArgs.Delta) * ZoomAmplifier(modifiers)); } }
public void MouseDragging(UserCommandArgs userCommandArgs) { if (userCommandArgs is PointerMoveCommandArgs mouseMoveCommandArgs) { contentArea?.UpdatePosition(mouseMoveCommandArgs.Delta); } }
private void MousePressedEvent(UserCommandArgs userCommandArgs, KeyModifiers keyModifiers) { if (userCommandArgs is PointerCommandArgs pointerCommandArgs) { SuppressDrawing = false; Point mouseDownPosition = pointerCommandArgs.Position; mouseActiveWindow = windows.LastOrDefault(w => w.Interactive && w.Borders.Contains(pointerCommandArgs.Position)); if (modalWindow != null && mouseActiveWindow != modalWindow) { userCommandArgs.Handled = true; } else if (mouseActiveWindow != null) { userCommandArgs.Handled = true; if (mouseActiveWindow != windows.Last()) { List <WindowBase> updatedWindowList = windows.ToList(); if (updatedWindowList.Remove(mouseActiveWindow)) { updatedWindowList.Add(mouseActiveWindow); windows = updatedWindowList; } } } } }
private protected override void DirectionHandleCommand(UserCommandArgs commandArgs, GameTime gameTime) { if (commandArgs is UserCommandArgs <float> handleCommandArgs) { SteamLocomotive.SetCutoffPercent(handleCommandArgs.Value); } base.DirectionHandleCommand(commandArgs, gameTime); }
private void WindowScrollEvent(UserCommandArgs userCommandArgs, KeyModifiers keyModifiers) { if (modalWindow != null && modalWindow != mouseActiveWindow) { SuppressDrawing = false; userCommandArgs.Handled = true; } }
private void MouseReleasedEvent(UserCommandArgs userCommandArgs, KeyModifiers keyModifiers) { if (userCommandArgs is PointerCommandArgs pointerCommandArgs) { mouseActiveWindow = VisibleWindows.LastOrDefault(w => w.Interactive && w.Location.Contains(pointerCommandArgs.Position)); mouseActiveWindow?.MouseReleased(pointerCommandArgs.Position, keyModifiers); } mouseActiveWindow = null; }
private void MouseDraggingEvent(UserCommandArgs userCommandArgs, KeyModifiers keyModifiers) { if (userCommandArgs is PointerMoveCommandArgs moveCommandArgs) { if (null == mouseActiveWindow) { mouseActiveWindow = VisibleWindows.LastOrDefault(w => w.Interactive && w.Location.Contains(moveCommandArgs.Position)); } mouseActiveWindow?.MouseDrag(moveCommandArgs.Position, moveCommandArgs.Delta, keyModifiers); } }
private void WindowScrollEvent(UserCommandArgs userCommandArgs, KeyModifiers keyModifiers) { if (userCommandArgs is ScrollCommandArgs scrollCommandArgs) { mouseActiveWindow = VisibleWindows.LastOrDefault(w => w.Interactive && w.Location.Contains(scrollCommandArgs.Position)); if (mouseActiveWindow != null) { mouseActiveWindow.MouseScroll(scrollCommandArgs.Position, scrollCommandArgs.Delta, keyModifiers); } } }
private void MouseClickedEvent(UserCommandArgs userCommandArgs, KeyModifiers keyModifiers) { if (userCommandArgs is PointerCommandArgs pointerCommandArgs) { mouseDownPosition = pointerCommandArgs.Position; mouseActiveWindow = VisibleWindows.LastOrDefault(w => w.Interactive && w.Location.Contains(pointerCommandArgs.Position)); if ((mouseActiveWindow != null) && (mouseActiveWindow != WindowsZOrder.Last())) { BringWindowToTop(mouseActiveWindow); } mouseActiveWindow?.MousePressed(pointerCommandArgs.Position, keyModifiers); } }
private void MouseReleasedEvent(UserCommandArgs userCommandArgs, KeyModifiers keyModifiers) { if (userCommandArgs is PointerCommandArgs pointerCommandArgs) { SuppressDrawing = false; if (modalWindow != null && mouseActiveWindow != modalWindow) { userCommandArgs.Handled = true; } else if (mouseActiveWindow != null) { userCommandArgs.Handled = true; mouseActiveWindow.HandleMouseReleased(pointerCommandArgs.Position, keyModifiers); } } }
private static int ZoomAmplifier(UserCommandArgs commandArgs) { int amplifier = 3; if (commandArgs is ModifiableKeyCommandArgs modifiableKeyCommand) { if ((modifiableKeyCommand.AdditionalModifiers & KeyModifiers.Control) == KeyModifiers.Control) { amplifier = 1; } else if ((modifiableKeyCommand.AdditionalModifiers & KeyModifiers.Shift) == KeyModifiers.Shift) { amplifier = 5; } } return(amplifier); }
private static float MovementAmplifier(UserCommandArgs commandArgs) { float amplifier = 5; if (commandArgs is ModifiableKeyCommandArgs modifiableKeyCommand) { if ((modifiableKeyCommand.AdditionalModifiers & KeyModifiers.Control) == KeyModifiers.Control) { amplifier = 1; } else if ((modifiableKeyCommand.AdditionalModifiers & KeyModifiers.Shift) == KeyModifiers.Shift) { amplifier = 10; } } return(amplifier); }
private void MouseDraggingEvent(UserCommandArgs userCommandArgs, KeyModifiers keyModifiers) { if (userCommandArgs is PointerMoveCommandArgs moveCommandArgs) { SuppressDrawing = false; if (modalWindow != null && modalWindow != mouseActiveWindow) { userCommandArgs.Handled = true; } else if (mouseActiveWindow != null) { userCommandArgs.Handled = true; mouseActiveWindow.HandleMouseDrag(moveCommandArgs.Position, moveCommandArgs.Delta, keyModifiers); } else if (windows.LastOrDefault(w => w.Interactive && w.Borders.Contains(moveCommandArgs.Position)) != null) { userCommandArgs.Handled = true; } } }
private static int ZoomAmplifier(UserCommandArgs commandArgs) { return(commandArgs is ModifiableKeyCommandArgs modifiableKeyCommand?ZoomAmplifier(modifiableKeyCommand.AdditionalModifiers) : zoomAmplifier); }
private void ZoomIn(UserCommandArgs commandArgs) { Zoom(ZoomAmplifier(commandArgs)); }
private void ZoomOut(UserCommandArgs commandArgs) { Zoom(-ZoomAmplifier(commandArgs)); }
private void MoveByKeyDown(UserCommandArgs commandArgs) { contentArea?.UpdatePosition(moveDown * MovementAmplifier(commandArgs)); }
private void MouseDownEvent(UserCommandArgs userCommandArgs, KeyModifiers keyModifiers) { }
/// <summary> /// Raises the <see cref="ReceivedUserCommandResponse"/> event. /// </summary> /// <param name="command">The code for the user command.</param> /// <param name="response">The code for the server's response.</param> /// <param name="buffer">Buffer containing the message from the server.</param> /// <param name="startIndex">Index into the buffer used to skip the header.</param> /// <param name="length">The length of the message in the buffer, including the header.</param> protected void OnReceivedUserCommandResponse(ServerCommand command, ServerResponse response, byte[] buffer, int startIndex, int length) { try { UserCommandArgs args = new UserCommandArgs(command, response, buffer, startIndex, length); ReceivedUserCommandResponse?.Invoke(this, args); } catch (Exception ex) { // We protect our code from consumer thrown exceptions OnProcessException(MessageLevel.Info, new InvalidOperationException($"Exception in consumer handler for UserCommandResponse event: {ex.Message}", ex), "ConsumerEventException"); } }