private void UserControl_MouseWheel(object sender, MouseWheelEventArgs e) { if (enableScrollWheelZoom == false) { return; } var mousePixel = GetPixelPosition(e); // DPI-scaling aware var mouseCoordinate = plt.CoordinateFromPixel(mousePixel.X, mousePixel.Y); double xFrac = (e.Delta > 0) ? 1.15 : 0.85; double yFrac = (e.Delta > 0) ? 1.15 : 0.85; if (isVerticalLocked) { yFrac = 1; } if (isHorizontalLocked) { xFrac = 1; } plt.AxisZoom(xFrac, yFrac, mouseCoordinate.X, mouseCoordinate.Y); AxisChanged?.Invoke(null, null); Render(recalculateLayout: true); }
private void ProcessValues(byte[] message) { if (message.IsButton()) { var oldValue = Buttons[message.GetAddress()]; var newValue = message.IsButtonPressed(); if (oldValue != newValue) { Buttons[message.GetAddress()] = message.IsButtonPressed(); ButtonChanged?.Invoke(this, new ButtonEventArgs { Button = message.GetAddress(), Pressed = newValue }); } } else if (message.IsAxis()) { var oldValue = Axis[message.GetAddress()]; var newValue = message.GetAxisValue(); if (oldValue != newValue) { Axis[message.GetAddress()] = message.GetAxisValue(); AxisChanged?.Invoke(this, new AxisEventArgs { Axis = message.GetAddress(), Value = newValue }); } } }
private void PlotAxis_MouseMove(object sender, MouseEventArgs e) { if (Axis == null) { return; } switch (_mouseMode) { case MouseMode.None: if (_regionLower.Contains(e.Location)) { _mouseMode = MouseMode.OverLowerRegion; Invalidate(); } else if (_regionUpper.Contains(e.Location)) { _mouseMode = MouseMode.OverUpperRegion; Invalidate(); } break; case MouseMode.OverLowerRegion: case MouseMode.OverUpperRegion: if (!_regionLower.Contains(e.Location) && !_regionUpper.Contains(e.Location)) { _mouseMode = MouseMode.None; Invalidate(); } break; case MouseMode.DragLower: case MouseMode.DragUpper: { double delta = 0.0; if (Axis.Orientation == Axis.AxisOrientation.Horizontal) { delta = (e.Location.X - _dragStart.X) / Axis.Length * _oldAxisInterval.Range; } else { delta = -(e.Location.Y - _dragStart.Y) / Axis.Length * _oldAxisInterval.Range; } if (_mouseMode == MouseMode.DragLower) { Axis.VisibleMinimum = _oldAxisInterval.Left - delta; } if (_mouseMode == MouseMode.DragUpper) { Axis.VisibleMaximum = _oldAxisInterval.Right - delta; } AxisChanged?.Invoke(this, new AxisChangedEventArgs { Minimum = Axis.VisibleMinimum, Maximum = Axis.VisibleMaximum }); } break; } }
public void MouseWheel(double yScroll) { if (enableScrollWheelZoom == false) { return; } double xFrac = (yScroll > 0) ? 1.15 : 0.85; double yFrac = (yScroll > 0) ? 1.15 : 0.85; if (isCtrlPressed) { yFrac = 1; } if (isShiftPressed) { xFrac = 1; } plt.AxisZoom(xFrac, yFrac, plt.CoordinateFromPixelX(mouseLocation.X), plt.CoordinateFromPixelY(mouseLocation.Y)); AxisChanged?.Invoke(null, null); bool shouldRecalculate = recalculateLayoutOnMouseUp ?? !plotContainsHeatmap; Render(recalculateLayout: shouldRecalculate); }
private void OnAxisChanged(JoystickUpdate state) { AxisChanged?.Invoke(this, new AxisChangedEventArgs() { AxisId = (int)state.Offset, Value = state.Value, Device = null }); }
private void UserControl_MouseWheel(object sender, MouseWheelEventArgs e) { if (enableScrollWheelZoom == false) { return; } var mousePixel = GetPixelPosition(e, applyDpiScaling: false); // DPI-scaling aware double xFrac = (e.Delta > 0) ? 1.15 : 0.85; double yFrac = (e.Delta > 0) ? 1.15 : 0.85; if (isCtrlPressed) { yFrac = 1; } if (isShiftPressed) { xFrac = 1; } plt.AxisZoom(xFrac, yFrac, plt.CoordinateFromPixelX(mousePixel.X), plt.CoordinateFromPixelY(mousePixel.Y)); AxisChanged?.Invoke(null, null); bool shouldRecalculate = recalculateLayoutOnMouseUp ?? plotContainsHeatmap == false; Render(recalculateLayout: shouldRecalculate); }
/// <summary> /// Pans the specified axis. /// </summary> /// <param name="delta">The delta.</param> public virtual void Pan(double delta) { var oldMinimum = ActualMinimum; var oldMaximum = ActualMaximum; var dx = delta / Scale; var newMinimum = ActualMinimum - dx; var newMaximum = ActualMaximum - dx; if (newMinimum < AbsoluteMinimum) { newMinimum = AbsoluteMinimum; newMaximum = Math.Min(newMinimum + ActualMaximum - ActualMinimum, AbsoluteMaximum); } if (newMaximum > AbsoluteMaximum) { newMaximum = AbsoluteMaximum; newMinimum = Math.Max(newMaximum - (ActualMaximum - ActualMinimum), AbsoluteMinimum); } ViewMinimum = newMinimum; ViewMaximum = newMaximum; UpdateActualMaxMin(); var deltaMinimum = ActualMinimum - oldMinimum; var deltaMaximum = ActualMaximum - oldMaximum; AxisChanged?.Invoke(this, new AxisChangedEventArgs(AxisChangeTypes.Pan, deltaMinimum, deltaMaximum)); }
private void OnAxisChanged(uint index, float value) { if (!m_axisToControllerInput.TryGetValue((int)index, out ControllerInput input)) { return; } float p = m_axisPrevious[index]; float c = value; float delta = c - p; if (p > 0.9f && c < -0.9f) { delta = m_axisAverageDelta[index]; } else if (p < -0.9f && c > 0.9f) { delta = -m_axisAverageDelta[index]; } else if (delta > 0) { m_axisAverageDelta[index] = (m_axisAverageDelta[index] + delta) * 0.5f; } m_axisPrevious[index] = value; m_nextDelta[input - ControllerInput.Laser0Axis] = delta; AxisChanged?.Invoke(input, delta); }
private void UserControl_MouseWheel(object sender, MouseWheelEventArgs e) { // note: AxisZoom's zoomCenter argument could be used to zoom to the cursor (see code in FormsPlot.cs). // However, this requires some work and testing to ensure it works if DPI scaling is used too. // Currently, scroll-wheel zooming simply zooms in and out of the center of the plot. double zoomAmountY = 0.15; double zoomAmountX = 0.15; if (isVerticalLocked) { zoomAmountY = 0; } if (isHorizontalLocked) { zoomAmountX = 0; } if (e.Delta > 1) { plt.AxisZoom(1 + zoomAmountX, 1 + zoomAmountY); AxisChanged?.Invoke(null, null); } else { plt.AxisZoom(1 - zoomAmountX, 1 - zoomAmountY); AxisChanged?.Invoke(null, null); } Render(skipIfCurrentlyRendering: false); }
public void OnEndDrag(PointerEventData eventData) { _down = false; _hold = false; _handleRectTransform.anchoredPosition = Vector2.zero; _inputAxis = Vector2.zero; AxisChanged?.Invoke(_inputAxis); }
private void MouseMovedToPanOrZoom(MouseEventArgs e) { plt.Axis(axisLimitsOnMouseDown); var mouseLocation = GetPixelPosition(e); if (mouseLeftDownLocation != null) { // left-click-drag panning double deltaX = ((Point)mouseLeftDownLocation).X - mouseLocation.X; double deltaY = mouseLocation.Y - ((Point)mouseLeftDownLocation).Y; if (isVerticalLocked) { deltaY = 0; } if (isHorizontalLocked) { deltaX = 0; } settings.AxesPanPx((int)deltaX, (int)deltaY); AxisChanged?.Invoke(null, null); } else if (mouseRightDownLocation != null) { // right-click-drag panning double deltaX = ((Point)mouseRightDownLocation).X - mouseLocation.X; double deltaY = mouseLocation.Y - ((Point)mouseRightDownLocation).Y; if (isVerticalLocked) { deltaY = 0; } if (isHorizontalLocked) { deltaX = 0; } settings.AxesZoomPx(-(int)deltaX, -(int)deltaY); AxisChanged?.Invoke(null, null); } else if (mouseMiddleDownLocation != null) { // middle-click-drag zooming to rectangle double x1 = Math.Min(mouseLocation.X, ((Point)mouseMiddleDownLocation).X); double x2 = Math.Max(mouseLocation.X, ((Point)mouseMiddleDownLocation).X); double y1 = Math.Min(mouseLocation.Y, ((Point)mouseMiddleDownLocation).Y); double y2 = Math.Max(mouseLocation.Y, ((Point)mouseMiddleDownLocation).Y); var origin = new System.Drawing.Point((int)x1 - settings.dataOrigin.X, (int)y1 - settings.dataOrigin.Y); var size = new System.Drawing.Size((int)(x2 - x1), (int)(y2 - y1)); settings.mouseMiddleRect = new System.Drawing.Rectangle(origin, size); } Render(true, lowQuality: lowQualityWhileDragging); return; }
/// <summary> /// Zoom to the specified scale. /// </summary> /// <param name="newScale">The new scale.</param> public virtual void Zoom(double newScale) { var oldMinimum = ActualMinimum; var oldMaximum = ActualMaximum; var sx1 = Transform(ActualMaximum); var sx0 = Transform(ActualMinimum); var sgn = Math.Sign(Scale); var mid = (ActualMaximum + ActualMinimum) / 2; var dx = (Offset - mid) * Scale; var newOffset = (dx / (sgn * newScale)) + mid; SetTransform(sgn * newScale, newOffset); var newMaximum = InverseTransform(sx1); var newMinimum = InverseTransform(sx0); if (newMinimum < AbsoluteMinimum && newMaximum > AbsoluteMaximum) { newMinimum = AbsoluteMinimum; newMaximum = AbsoluteMaximum; } else { if (newMinimum < AbsoluteMinimum) { var d = newMaximum - newMinimum; newMinimum = AbsoluteMinimum; newMaximum = AbsoluteMinimum + d; if (newMaximum > AbsoluteMaximum) { newMaximum = AbsoluteMaximum; } } else if (newMaximum > AbsoluteMaximum) { var d = newMaximum - newMinimum; newMaximum = AbsoluteMaximum; newMinimum = AbsoluteMaximum - d; if (newMinimum < AbsoluteMinimum) { newMinimum = AbsoluteMinimum; } } } ViewMaximum = newMaximum; ViewMinimum = newMinimum; UpdateActualMaxMin(); var deltaMinimum = ActualMinimum - oldMinimum; var deltaMaximum = ActualMaximum - oldMaximum; AxisChanged?.Invoke(this, new AxisChangedEventArgs(AxisChangeTypes.Zoom, deltaMinimum, deltaMaximum)); }
private void UserControl_MouseUp(object sender, MouseButtonEventArgs e) { ReleaseMouseCapture(); var mouseLocation = GetPixelPosition(e); plottableBeingDragged = null; if (mouseMiddleDownLocation != null) { double x1 = Math.Min(mouseLocation.X, ((Point)mouseMiddleDownLocation).X); double x2 = Math.Max(mouseLocation.X, ((Point)mouseMiddleDownLocation).X); double y1 = Math.Min(mouseLocation.Y, ((Point)mouseMiddleDownLocation).Y); double y2 = Math.Max(mouseLocation.Y, ((Point)mouseMiddleDownLocation).Y); Point topLeft = new Point(x1, y1); Size size = new Size(x2 - x1, y2 - y1); Point botRight = new Point(topLeft.X + size.Width, topLeft.Y + size.Height); if ((size.Width > 2) && (size.Height > 2)) { // only change axes if suffeciently large square was drawn plt.Axis( x1: plt.CoordinateFromPixel((int)topLeft.X, (int)topLeft.Y).X, x2: plt.CoordinateFromPixel((int)botRight.X, (int)botRight.Y).X, y1: plt.CoordinateFromPixel((int)botRight.X, (int)botRight.Y).Y, y2: plt.CoordinateFromPixel((int)topLeft.X, (int)topLeft.Y).Y ); AxisChanged?.Invoke(null, null); } else { plt.AxisAuto(); AxisChanged?.Invoke(null, null); } } if (mouseRightDownLocation != null) { double deltaX = Math.Abs(mouseLocation.X - mouseRightDownLocation.Value.X); double deltaY = Math.Abs(mouseLocation.Y - mouseRightDownLocation.Value.Y); bool mouseDraggedFar = (deltaX > 3 || deltaY > 3); ContextMenu.Visibility = (mouseDraggedFar) ? Visibility.Hidden : Visibility.Visible; ContextMenu.IsOpen = (!mouseDraggedFar); } else { ContextMenu.IsOpen = false; } mouseLeftDownLocation = null; mouseRightDownLocation = null; mouseMiddleDownLocation = null; axisLimitsOnMouseDown = null; settings.mouseMiddleRect = null; Render(recalculateLayout: true); }
internal void HandleAxisEvent(uint axisIndex, short newValue) { float value = newValue / (float)0x7FFF; axisStates[axisIndex] = value; AxisChanged?.Invoke(axisIndex, value); Host.AxisChanged(new AnalogInfo() { DeviceIndex = DeviceIndex, Axis = axisIndex, Value = value, }); }
void Update() { InputState newInputState = new InputState(); if (!isAR) { newInputState.fire = FireControlActive(PreferedHand()); newInputState.nav = GetButtonDown(ButtonAlias.AXIS_CLICK, PreferedHand()); newInputState.xy = new Vector2(GetAxis(AxisAlias.X, PreferedHand()), GetAxis(AxisAlias.Y, PreferedHand())); newInputState.xyIgnoreSDKLeftHand = new Vector2(GetAxis(AxisAlias.X, Handedness.LEFT, true), GetAxis(AxisAlias.Y, Handedness.LEFT, true)); newInputState.xyIgnoreSDKRightHand = new Vector2(GetAxis(AxisAlias.X, Handedness.RIGHT, true), GetAxis(AxisAlias.Y, Handedness.RIGHT, true)); } else { newInputState = newARInputState; if (newARFrame)// isAR { if (newARInputState.nav) { newARInputState.nav = false; // nav should persist for one frame, then be unset } else { newARFrame = false; } } } if (newInputState.fire != previousInputState.fire && newInputState.fire) { FireActive?.Invoke(); } if (newInputState.fire != previousInputState.fire && !newInputState.fire) { FireInactive?.Invoke(); } if (newInputState.nav != previousInputState.nav && newInputState.nav) { NavActive?.Invoke(); } if (newInputState.xy != previousInputState.xy) { AxisChanged?.Invoke(newInputState.xy); AxisChangedIgnoreSDKLeft?.Invoke(newInputState.xyIgnoreSDKLeftHand); AxisChangedIgnoreSDKRight?.Invoke(newInputState.xyIgnoreSDKRightHand); } previousInputState = newInputState; }
public void MouseUp() { plottableBeingDragged = null; if (mouseMiddleDownLocation != null) { double x1 = Math.Min(mouseLocation.X, mouseMiddleDownLocation.Value.X); double x2 = Math.Max(mouseLocation.X, mouseMiddleDownLocation.Value.X); double y1 = Math.Min(mouseLocation.Y, mouseMiddleDownLocation.Value.Y); double y2 = Math.Max(mouseLocation.Y, mouseMiddleDownLocation.Value.Y); PointF topLeft = new PointF((float)x1, (float)y1); SizeF size = new SizeF((float)(x2 - x1), (float)(y2 - y1)); PointF botRight = new PointF(topLeft.X + size.Width, topLeft.Y + size.Height); if ((size.Width > 2) && (size.Height > 2)) { // only change axes if suffeciently large square was drawn if (!lockHorizontalAxis) { plt.Axis( x1: plt.CoordinateFromPixelX(topLeft.X), x2: plt.CoordinateFromPixelX(botRight.X)); } if (!lockVerticalAxis) { plt.Axis( y1: plt.CoordinateFromPixelY(botRight.Y), y2: plt.CoordinateFromPixelY(topLeft.Y)); } AxisChanged?.Invoke(null, null); } else { bool shouldTighten = recalculateLayoutOnMouseUp ?? !plotContainsHeatmap; plt.AxisAuto(middleClickMarginX, middleClickMarginY); AxisChanged?.Invoke(null, null); } } mouseLeftDownLocation = null; mouseRightDownLocation = null; mouseMiddleDownLocation = null; rememberingAxisLimits = false; settings.ZoomRectangle.Clear(); bool shouldRecalculate = recalculateLayoutOnMouseUp ?? !plotContainsHeatmap; Render(recalculateLayout: shouldRecalculate); }
/// <summary> /// Resets the user's modification (zooming/panning) to minimum and maximum of this axis. /// </summary> public virtual void Reset() { var oldMinimum = ActualMinimum; var oldMaximum = ActualMaximum; ViewMinimum = double.NaN; ViewMaximum = double.NaN; UpdateActualMaxMin(); var deltaMinimum = ActualMinimum - oldMinimum; var deltaMaximum = ActualMaximum - oldMaximum; AxisChanged?.Invoke(this, new AxisChangedEventArgs(AxisChangeTypes.Reset, deltaMinimum, deltaMaximum)); }
private void Update() { if (_down || _hold) { Vector2 pos = (_eventData.position - _centerPos); if (pos.magnitude > _maxRadiusPixel) { pos = pos.normalized * _maxRadiusPixel; } _handleRectTransform.anchoredPosition = pos; _inputAxis = pos / _maxRadiusPixel; AxisChanged?.Invoke(_inputAxis); } }
private void Mouse_Move(int xDelta, int yDelta) { if (xDelta != 0) { var inputKind = m_mouseToControllerInput[Axes.X]; m_nextDelta[inputKind - ControllerInput.Laser0Axis] = xDelta * m_sensitivity; m_rawValues[inputKind - ControllerInput.Laser0Axis] += xDelta * m_sensitivity; AxisChanged?.Invoke(inputKind, xDelta * m_sensitivity); } if (yDelta != 0) { var inputKind = m_mouseToControllerInput[Axes.Y]; m_nextDelta[inputKind - ControllerInput.Laser0Axis] = yDelta * m_sensitivity; m_rawValues[inputKind - ControllerInput.Laser0Axis] += yDelta * m_sensitivity; AxisChanged?.Invoke(inputKind, yDelta * m_sensitivity); } }
public async void ScrollWheelProcessor() { ScrollWheelTimer.Start(); while (ScrollWheelTimer.ElapsedMilliseconds < lowQualityScrollWheelDelay) { // if no new mouse events, sleep until the timer is up if (MouseWheelEvents.Count == 0) { await Task.Delay(30); continue; } // if new mouse events, apply them and reset the timer while (MouseWheelEvents.Count > 0) { MouseWheelEventArgs e = MouseWheelEvents.Dequeue(); var mousePixel = GetPixelPosition(e, applyDpiScaling: false); // DPI-scaling aware double xFrac = (e.Delta > 0) ? 1.15 : 0.85; double yFrac = (e.Delta > 0) ? 1.15 : 0.85; if (isCtrlPressed) { yFrac = 1; } if (isShiftPressed) { xFrac = 1; } plt.AxisZoom(xFrac, yFrac, plt.CoordinateFromPixelX(mousePixel.X), plt.CoordinateFromPixelY(mousePixel.Y)); AxisChanged?.Invoke(null, null); } bool shouldRecalculate = recalculateLayoutOnMouseUp ?? plotContainsHeatmap == false; Render(lowQuality: lowQualityOnScrollWheel, recalculateLayout: shouldRecalculate, processEvents: true); ScrollWheelTimer.Restart(); } // after the scrollwheel timer runs out, perform a final delayed HQ render if (lowQualityOnScrollWheel) { Render(recalculateLayout: false, processEvents: true); } ScrollWheelTimer.Reset(); }
/// <summary> /// Zooms the axis to the range [x0,x1]. /// </summary> /// <param name="x0">The new minimum.</param> /// <param name="x1">The new maximum.</param> public virtual void Zoom(double x0, double x1) { var oldMinimum = ActualMinimum; var oldMaximum = ActualMaximum; var newMinimum = Math.Max(Math.Min(x0, x1), AbsoluteMinimum); var newMaximum = Math.Min(Math.Max(x0, x1), AbsoluteMaximum); ViewMinimum = newMinimum; ViewMaximum = newMaximum; UpdateActualMaxMin(); var deltaMinimum = ActualMinimum - oldMinimum; var deltaMaximum = ActualMaximum - oldMaximum; AxisChanged?.Invoke(this, new AxisChangedEventArgs(AxisChangeTypes.Zoom, deltaMinimum, deltaMaximum)); }
public override void Update() { int dir0 = m_directions[ControllerInput.Laser0Positive].Count - m_directions[ControllerInput.Laser0Negative].Count; int dir1 = m_directions[ControllerInput.Laser1Positive].Count - m_directions[ControllerInput.Laser1Negative].Count; m_rawValues[0] += dir0 * m_sensitivity; m_rawValues[1] += dir1 * m_sensitivity; if (dir0 != 0) { AxisChanged?.Invoke(ControllerInput.Laser0Axis, dir0 * m_sensitivity); } if (dir1 != 0) { AxisChanged?.Invoke(ControllerInput.Laser1Axis, dir1 * m_sensitivity); } }
private void UserControl_MouseUp(object sender, MouseButtonEventArgs e) { ReleaseMouseCapture(); var mouseLocation = GetPixelPosition(e); plottableBeingDragged = null; if (mouseMiddleDownLocation != null) { double x1 = Math.Min(mouseLocation.X, ((Point)mouseMiddleDownLocation).X); double x2 = Math.Max(mouseLocation.X, ((Point)mouseMiddleDownLocation).X); double y1 = Math.Min(mouseLocation.Y, ((Point)mouseMiddleDownLocation).Y); double y2 = Math.Max(mouseLocation.Y, ((Point)mouseMiddleDownLocation).Y); Point topLeft = new Point(x1, y1); Size size = new Size(x2 - x1, y2 - y1); Point botRight = new Point(topLeft.X + size.Width, topLeft.Y + size.Height); if ((size.Width > 2) && (size.Height > 2)) { // only change axes if suffeciently large square was drawn plt.Axis( x1: plt.CoordinateFromPixel((int)topLeft.X, (int)topLeft.Y).X, x2: plt.CoordinateFromPixel((int)botRight.X, (int)botRight.Y).X, y1: plt.CoordinateFromPixel((int)botRight.X, (int)botRight.Y).Y, y2: plt.CoordinateFromPixel((int)topLeft.X, (int)topLeft.Y).Y ); AxisChanged?.Invoke(null, null); } else { plt.AxisAuto(); AxisChanged?.Invoke(null, null); } } mouseLeftDownLocation = null; mouseRightDownLocation = null; mouseMiddleDownLocation = null; axisLimitsOnMouseDown = null; settings.mouseMiddleRect = null; Render(); }
/// <summary> /// Zooms the axis at the specified coordinate. /// </summary> /// <param name="factor">The zoom factor.</param> /// <param name="x">The coordinate to zoom at.</param> public virtual void ZoomAt(double factor, double x) { var oldMinimum = ActualMinimum; var oldMaximum = ActualMaximum; var dx0 = (ActualMinimum - x) * Scale; var dx1 = (ActualMaximum - x) * Scale; SetTransform(Scale * factor, Offset); var newMinimum = (dx0 / Scale) + x; var newMaximum = (dx1 / Scale) + x; if (newMaximum - newMinimum > MaximumRange) { var mid = (newMinimum + newMaximum) * 0.5; newMaximum = mid + MaximumRange * 0.5; newMinimum = mid - MaximumRange * 0.5; } if (newMaximum - newMinimum < MinimumRange) { var mid = (newMinimum + newMaximum) * 0.5; newMaximum = mid + MinimumRange * 0.5; newMinimum = mid - MinimumRange * 0.5; } newMinimum = Math.Max(newMinimum, AbsoluteMinimum); newMaximum = Math.Min(newMaximum, AbsoluteMaximum); ViewMinimum = newMinimum; ViewMaximum = newMaximum; UpdateActualMaxMin(); var deltaMinimum = ActualMinimum - oldMinimum; var deltaMaximum = ActualMaximum - oldMaximum; AxisChanged?.Invoke(this, new AxisChangedEventArgs(AxisChangeTypes.Zoom, deltaMinimum, deltaMaximum)); }
private void UserControl_MouseUp(object sender, MouseButtonEventArgs e) { ReleaseMouseCapture(); var mouseLocation = GetPixelPosition(e); plottableBeingDragged = null; if (mouseMiddleDownLocation != null) { double x1 = Math.Min(mouseLocation.X / dpiScale, ((Point)mouseMiddleDownLocation).X / dpiScale); double x2 = Math.Max(mouseLocation.X / dpiScale, ((Point)mouseMiddleDownLocation).X / dpiScale); double y1 = Math.Min(mouseLocation.Y / dpiScale, ((Point)mouseMiddleDownLocation).Y / dpiScale); double y2 = Math.Max(mouseLocation.Y / dpiScale, ((Point)mouseMiddleDownLocation).Y / dpiScale); Point topLeft = new Point(x1, y1); Size size = new Size(x2 - x1, y2 - y1); Point botRight = new Point(topLeft.X + size.Width, topLeft.Y + size.Height); if ((size.Width > 2) && (size.Height > 2)) { // only change axes if suffeciently large square was drawn if (!lockHorizontalAxis) { plt.Axis( x1: plt.CoordinateFromPixelX(topLeft.X), x2: plt.CoordinateFromPixelX(botRight.X)); } if (!lockVerticalAxis) { plt.Axis( y1: plt.CoordinateFromPixelY(botRight.Y), y2: plt.CoordinateFromPixelY(topLeft.Y)); } AxisChanged?.Invoke(null, null); } else { bool shouldTighten = recalculateLayoutOnMouseUp ?? plotContainsHeatmap == false; plt.AxisAuto(middleClickMarginX, middleClickMarginY, tightenLayout: shouldTighten); AxisChanged?.Invoke(null, null); } } if (mouseRightDownLocation != null) { double deltaX = Math.Abs(mouseLocation.X - mouseRightDownLocation.Value.X); double deltaY = Math.Abs(mouseLocation.Y - mouseRightDownLocation.Value.Y); bool mouseDraggedFar = (deltaX > 3 || deltaY > 3); if (ContextMenu != null) { ContextMenu.Visibility = (mouseDraggedFar) ? Visibility.Hidden : Visibility.Visible; ContextMenu.IsOpen = (!mouseDraggedFar); } } else { if (ContextMenu != null) { ContextMenu.IsOpen = false; } } mouseLeftDownLocation = null; mouseRightDownLocation = null; mouseMiddleDownLocation = null; axisLimitsOnMouseDown = null; settings.mouseMiddleRect = null; bool shouldRecalculate = recalculateLayoutOnMouseUp ?? plotContainsHeatmap == false; Render(recalculateLayout: shouldRecalculate); }
/// <summary> /// Raises the AxisChanged event. /// </summary> /// <param name="axis">The <see cref="GamePadAxis"/> value that represents the axis that changed.</param> /// <param name="value">The axis' value.</param> protected virtual void OnAxisChanged(GamePadAxis axis, Single value) => AxisChanged?.Invoke(this, axis, value);
private void MouseMovedToPanOrZoom() { plt.GetSettings(false).RecallAxisLimits(); if (mouseLeftDownLocation != null) { // left-click-drag panning double deltaX = mouseLeftDownLocation.Value.X - mouseLocation.X; double deltaY = mouseLocation.Y - mouseLeftDownLocation.Value.Y; if (isCtrlPressed || lockVerticalAxis) { deltaY = 0; } if (isShiftPressed || lockHorizontalAxis) { deltaX = 0; } settings.AxesPanPx((int)deltaX, (int)deltaY); AxisChanged?.Invoke(null, null); } else if (mouseRightDownLocation != null) { // right-click-drag zooming double deltaX = mouseRightDownLocation.Value.X - mouseLocation.X; double deltaY = mouseLocation.Y - mouseRightDownLocation.Value.Y; if (isCtrlPressed == true && isShiftPressed == false) { deltaY = 0; } if (isShiftPressed == true && isCtrlPressed == false) { deltaX = 0; } settings.AxesZoomPx(-(int)deltaX, -(int)deltaY, lockRatio: isCtrlPressed && isShiftPressed); AxisChanged?.Invoke(null, null); } else if (mouseMiddleDownLocation != null) { // middle-click-drag zooming to rectangle double x1 = Math.Min(mouseLocation.X, mouseMiddleDownLocation.Value.X); double x2 = Math.Max(mouseLocation.X, mouseMiddleDownLocation.Value.X); double y1 = Math.Min(mouseLocation.Y, mouseMiddleDownLocation.Value.Y); double y2 = Math.Max(mouseLocation.Y, mouseMiddleDownLocation.Value.Y); var origin = new System.Drawing.Point((int)x1 - (int)settings.DataOffsetX, (int)y1 - (int)settings.DataOffsetY); var size = new System.Drawing.Size((int)(x2 - x1), (int)(y2 - y1)); if (lockVerticalAxis) { origin.Y = 0; size.Height = (int)settings.DataHeight - 1; } if (lockHorizontalAxis) { origin.X = 0; size.Width = (int)settings.DataWidth - 1; } settings.ZoomRectangle.Set(origin.X, origin.Y, size.Width, size.Height); } Render(true, lowQuality: lowQualityWhileDragging); return; }
private void Device_AxisChanged(object sender, AxisChangedEventArgs e) { _selectedDevice = e.Device; AxisChanged?.Invoke(sender, e); }
private void ProcessData() { // First, process buttons Debug.WriteLine(BitConverter.ToString(m_State)); // First, process the buttons byte newButtonA = (byte)((m_State[0] >> 2) & 1); // A byte newButtonB = (byte)((m_State[0] >> 1) & 1); // B byte newButtonX = (byte)((m_State[0] >> 3) & 1); // X byte newButtonY = (byte)((m_State[0] >> 0) & 1); // Y byte newButtonL1 = (byte)((m_State[0] >> 6) & 1); // L1 byte newButtonR1 = (byte)((m_State[0] >> 7) & 1); // R1 byte newButtonL2 = (byte)((m_State[1] >> 4) & 1); // L2 byte newButtonR2 = (byte)((m_State[1] >> 5) & 1); // R2 byte newButtonSelect = (byte)((m_State[0] >> 5) & 1); // Select byte newButtonStart = (byte)((m_State[0] >> 4) & 1); // Start byte newButtonDPadUp = (byte)(m_State[1] & 1); // DPad Up byte newButtonDPadDown = (byte)((m_State[1] >> 1) & 1); // DPad Down byte newButtonDPadLeft = (byte)((m_State[1] >> 2) & 1); // DPad Left byte newButtonDPadRight = (byte)((m_State[1] >> 3) & 1); // DPad Right if (buttonA != newButtonA) { KeyChanged?.Invoke(new KeyEvent(KeyCode.A, newButtonA > 0 ? ControllerAction.Pressed : ControllerAction.Unpressed)); } if (buttonB != newButtonB) { KeyChanged?.Invoke(new KeyEvent(KeyCode.B, newButtonB > 0 ? ControllerAction.Pressed : ControllerAction.Unpressed)); } if (buttonX != newButtonX) { KeyChanged?.Invoke(new KeyEvent(KeyCode.X, newButtonX > 0 ? ControllerAction.Pressed : ControllerAction.Unpressed)); } if (buttonY != newButtonY) { KeyChanged?.Invoke(new KeyEvent(KeyCode.Y, newButtonY > 0 ? ControllerAction.Pressed : ControllerAction.Unpressed)); } if (buttonL1 != newButtonL1) { KeyChanged?.Invoke(new KeyEvent(KeyCode.L1, newButtonL1 > 0 ? ControllerAction.Pressed : ControllerAction.Unpressed)); } if (buttonR1 != newButtonR1) { KeyChanged?.Invoke(new KeyEvent(KeyCode.R1, newButtonR1 > 0 ? ControllerAction.Pressed : ControllerAction.Unpressed)); } if (buttonL2 != newButtonL2) { KeyChanged?.Invoke(new KeyEvent(KeyCode.L2, newButtonL2 > 0 ? ControllerAction.Pressed : ControllerAction.Unpressed)); } if (buttonR2 != newButtonR2) { KeyChanged?.Invoke(new KeyEvent(KeyCode.R2, newButtonR2 > 0 ? ControllerAction.Pressed : ControllerAction.Unpressed)); } if (buttonSelect != newButtonSelect) { KeyChanged?.Invoke(new KeyEvent(KeyCode.Select, newButtonSelect > 0 ? ControllerAction.Pressed : ControllerAction.Unpressed)); } if (buttonStart != newButtonStart) { KeyChanged?.Invoke(new KeyEvent(KeyCode.Start, newButtonStart > 0 ? ControllerAction.Pressed : ControllerAction.Unpressed)); } if (buttonDPadUp != newButtonDPadUp) { KeyChanged?.Invoke(new KeyEvent(KeyCode.DPadUp, newButtonDPadUp > 0 ? ControllerAction.Pressed : ControllerAction.Unpressed)); } if (buttonDPadDown != newButtonDPadDown) { KeyChanged?.Invoke(new KeyEvent(KeyCode.DPadDown, newButtonDPadDown > 0 ? ControllerAction.Pressed : ControllerAction.Unpressed)); } if (buttonDPadLeft != newButtonDPadLeft) { KeyChanged?.Invoke(new KeyEvent(KeyCode.DPadLeft, newButtonDPadLeft > 0 ? ControllerAction.Pressed : ControllerAction.Unpressed)); } if (buttonDPadRight != newButtonDPadRight) { KeyChanged?.Invoke(new KeyEvent(KeyCode.DPadRight, newButtonDPadRight > 0 ? ControllerAction.Pressed : ControllerAction.Unpressed)); } buttonA = newButtonA; buttonB = newButtonB; buttonX = newButtonX; buttonY = newButtonY; buttonL1 = newButtonL1; buttonR1 = newButtonR1; buttonL2 = newButtonL2; buttonR2 = newButtonR2; buttonSelect = newButtonSelect; buttonStart = newButtonStart; buttonDPadUp = newButtonDPadUp; buttonDPadDown = newButtonDPadDown; buttonDPadLeft = newButtonDPadLeft; buttonDPadRight = newButtonDPadRight; // Is it "Moga Mobile" controller? if (ControllerName.Equals("BD&A")) { // Next, process joystick/d-pad axes int newAxisX = 0; sbyte newDataX = (sbyte)m_State[2]; if ((byte)(m_State[1] & 0x04) == 0x04 || (byte)(m_State[1] & 0x08) == 0x08) { newAxisX = (byte)(m_State[1] & 0x04) == 0x04 ? 1 : -1; } if (axisX != newAxisX || (newAxisX != 0 && dataX != newDataX) || (axisX != 0 && newAxisX == 0)) { AxisChanged?.Invoke(new MotionEvent(Axis.X, newAxisX == 0 ? 0 : newDataX)); } axisX = newAxisX; dataX = newDataX; int newAxisY = 0; sbyte newDataY = (sbyte)m_State[3]; if ((byte)(m_State[1] & 0x01) == 0x01 || (byte)(m_State[1] & 0x02) == 2) { newAxisY = (byte)(m_State[1] & 0x01) == 0x01 ? 1 : -1; } if (axisY != newAxisY || (newAxisY != 0 && dataY != newDataY) || (axisY != 0 && newAxisY == 0)) { AxisChanged?.Invoke(new MotionEvent(Axis.Y, newAxisY == 0 ? 0 : newDataY)); } axisY = newAxisY; dataY = newDataY; int newAxisZ = 0; sbyte newDataZ = (sbyte)m_State[5]; if ((byte)(m_State[1] & 0x10) == 0x10 || (byte)(m_State[1] & 0x20) == 0x20) { newAxisZ = (byte)(m_State[1] & 0x10) == 0x10 ? 1 : -1; } if (axisZ != newAxisZ || (newAxisZ != 0 && dataZ != newDataZ) || (axisZ != 0 && newAxisZ == 0)) { AxisChanged?.Invoke(new MotionEvent(Axis.Z, newAxisZ == 0 ? 0 : newDataZ)); } axisZ = newAxisZ; dataZ = newDataZ; int newAxisRZ = 0; sbyte newDataRZ = (sbyte)m_State[4]; if ((byte)(m_State[1] & 0x40) == 0x40 || (byte)(m_State[1] & 0x80) == 0x80) { newAxisRZ = (byte)(m_State[1] & 0x40) == 0x40 ? 1 : -1; } if (axisRZ != newAxisRZ || (newAxisRZ != 0 && dataRZ != newDataRZ) || (axisRZ != 0 && newAxisRZ == 0)) { AxisChanged?.Invoke(new MotionEvent(Axis.RZ, newAxisRZ == 0 ? 0 : newDataRZ)); } axisRZ = newAxisRZ; dataRZ = newDataRZ; } else { // Next, process joystick/d-pad axes int newAxisX = 0; sbyte newDataX = (sbyte)m_State[2]; if ((byte)(m_State[2] & 0x80) == 0x80 || (byte)(m_State[2] & 0x40) == 0x40) { newAxisX = (byte)(m_State[2] & 0x80) == 0x80 ? 1 : -1; } if (axisX != newAxisX || (newAxisX != 0 && dataX != newDataX) || (axisX != 0 && newAxisX == 0)) { AxisChanged?.Invoke(new MotionEvent(Axis.X, newDataX)); } axisX = newAxisX; dataX = newDataX; int newAxisY = 0; sbyte newDataY = (sbyte)m_State[3]; if ((byte)(m_State[3] & 0x80) == 0x80 || (byte)(m_State[3] & 0x40) == 0x40) { newAxisY = (byte)(m_State[3] & 0x80) == 0x80 ? 1 : -1; } if (axisY != newAxisY || (newAxisY != 0 && dataY != newDataY) || (axisY != 0 && newAxisY == 0)) { AxisChanged?.Invoke(new MotionEvent(Axis.Y, newDataY)); } axisY = newAxisY; dataY = newDataY; int newAxisZ = 0; sbyte newDataZ = (sbyte)m_State[5]; if ((byte)(m_State[5] & 0x80) == 0x80 || (byte)(m_State[5] & 0x40) == 0x40) { newAxisZ = (byte)(m_State[5] & 0x80) == 0x80 ? 1 : -1; } if (axisZ != newAxisZ || (newAxisZ != 0 && dataZ != newDataZ) || (axisZ != 0 && newAxisZ == 0)) { AxisChanged?.Invoke(new MotionEvent(Axis.Z, newAxisZ == 0 ? 0 : newDataZ)); } axisZ = newAxisZ; dataZ = newDataZ; int newAxisRZ = 0; sbyte newDataRZ = (sbyte)m_State[4]; if ((byte)(m_State[4] & 0x80) == 0x80 || (byte)(m_State[4] & 0x40) == 0x40) { newAxisRZ = (byte)(m_State[4] & 0x80) == 0x80 ? 1 : -1; } if (axisRZ != newAxisRZ || (newAxisRZ != 0 && dataRZ != newDataRZ) || (axisRZ != 0 && newAxisRZ == 0)) { AxisChanged?.Invoke(new MotionEvent(Axis.RZ, newAxisRZ == 0 ? 0 : newDataRZ)); } axisRZ = newAxisRZ; dataRZ = newDataRZ; } }
private void OnAxisChanged(object sender, AxisChangedEventArgs e) { e.Device = this; AxisChanged?.Invoke(this, e); }