void Update() { // Dash if (Input.GetKeyDown(KeyCode.Space)) { // Positions Vector3 mousepos = MouseUtil.GetMousePosition(); Vector3 playerpos = transform.position; // Ignore z mousepos.z = 0; playerpos.z = 0; // Direction Vector2 dashDir = (mousepos - playerpos).normalized; // Dash motion.jumpForce = dashDir * dashPower; motion.Jump(); transform.DORotate(new Vector3(0, 0, 360), 1); // Tween down this.tt("DashSlowDown").ttReset().ttAdd(0.1f).ttLoop(0.2f, (ttHandler t) => { motion.currentJump = Vector2.Lerp(motion.currentJump, Vector2.zero, t.deltaTime); }); } }
private void gridTitleBar_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (TitleBarMouseLeftUp != null) { TitleBarLeftUp(e); } else { mousePositionYStart = double.NaN; } if (moving && parentWindow.WindowState == WindowState.Normal) { System.Drawing.Point mousePosition = MouseUtil.GetMousePosition(); List <ScreenInfo> screens = ScreenUtil.AllScreens; foreach (ScreenInfo siItem in screens) { if (mousePosition.X >= siItem.Bounds.X && mousePosition.X <= siItem.Bounds.X + siItem.Bounds.Size.Width && mousePosition.Y <= siItem.Bounds.Y + this.ActualHeight / 2) { parentWindow.WindowState = WindowState.Maximized; } } moving = false; } }
private void Window_MouseDown(object sender, MouseButtonEventArgs e) { var mouse = MouseUtil.GetMousePosition(); var compensatedX = mouse.X - SystemInformation.VirtualScreen.Left; // Compensate for potential negative position on multi-monitor var compensatedY = mouse.Y - SystemInformation.VirtualScreen.Top; // Compensate for potential negative position on multi-monitor var rgb = BitmapUtil.PixelToRgb(FreezeFrame.Instance.BitmapSource, compensatedX, compensatedY); _vm.RefreshFromRgb(rgb); ColorPicked?.Invoke(this, EventArgs.Empty); Close(); }
void Update() { Vector3 mousepos = MouseUtil.GetMousePosition(); mousepos.z = -9; transform.position = mousepos; if (rotateUponOrigin) { Vector3 source = mousepos - origin.position; float angle = Mathf.Atan2(source.y, source.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(0, 0, angle); } }
private void UserControl_MouseMove(object sender, MouseEventArgs e) { if (mousePositionYStart != double.NaN && Mouse.LeftButton == MouseButtonState.Pressed && parentWindow.WindowState == WindowState.Maximized) { System.Drawing.Point mousePosition = MouseUtil.GetMousePosition(); double delta = mousePositionYStart - mousePosition.Y; if (delta < -5) { Maximize_EventHandler(sender, e); parentWindow.Left = mousePosition.X - this.ActualWidth / 2; parentWindow.Top = mousePosition.Y - titleBar.ActualHeight / 2; parentWindow.DragMove(); } } }
private void titleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (TitleBarMouseLeftDown != null) { ExecuteTitleBarLeftDown(e); } else { mousePositionYStart = parentWindow.WindowState == WindowState.Maximized ? MouseUtil.GetMousePosition().Y : double.NaN; if (e.ClickCount == 1) { if (System.Windows.Input.Mouse.LeftButton == MouseButtonState.Pressed) { try { parentWindow.DragMove(); } catch (Exception ex) { LogWriter.Instance.WriteToLog(ex, "Error dragging windows"); } } } else if (IsMouseDirectlyOver) { Maximize_EventHandler(sender, e); } } }
public CursorTrailWindow() { InitializeComponent(); var vm = new CursorTrailWindowViewModel(); DataContext = vm; RenderOptions.SetBitmapScalingMode(PreviewImage, BitmapScalingMode.NearestNeighbor); const int winBorderWidth = 2; // Must have odd number of columns to have a center column. const int numColumns = 9; const int columnWidth = 13; const double segmentWidth = (double)columnWidth / 2; const int gridWidth = (columnWidth * numColumns) + (numColumns - 1); const int winWidth = (winBorderWidth * 2) + gridWidth; Width = winWidth; PreviewContainer.Width = gridWidth; PreviewContainer.Height = gridWidth; #region Draw grid lines for (var x = 1; x < numColumns; x += 1) { var vLine = new Line { Style = PreviewContainer.Resources["GridLine"] as Style, X1 = x * columnWidth + x, X2 = x * columnWidth + x, Y1 = 0, Y2 = gridWidth }; PreviewContainer.Children.Add(vLine); var hLine = new Line { Style = PreviewContainer.Resources["GridLine"] as Style, X1 = 0, X2 = gridWidth, Y1 = x * columnWidth + x, Y2 = x * columnWidth + x }; PreviewContainer.Children.Add(hLine); } const double pxCenter = (double)gridWidth / 2; var vLineCrosshair = new Line { Style = PreviewContainer.Resources["Crosshair"] as Style, X1 = pxCenter, X2 = pxCenter, Y1 = pxCenter - segmentWidth + 2, Y2 = pxCenter + segmentWidth - 2 }; PreviewContainer.Children.Add(vLineCrosshair); var hLineCrosshair = new Line { Style = PreviewContainer.Resources["Crosshair"] as Style, X1 = pxCenter - segmentWidth + 2, X2 = pxCenter + segmentWidth - 2, Y1 = pxCenter, Y2 = pxCenter }; PreviewContainer.Children.Add(hLineCrosshair); #endregion #region Render the color preview var winHeight = (int)Height; _timer = new DispatcherTimer(DispatcherPriority.Render) { Interval = TimeSpan.FromMilliseconds(16) }; _timer.Tick += (sender, e) => { var mouse = MouseUtil.GetMousePosition(); const int pxFromCursor = 30; var winX = mouse.X + pxFromCursor; var winY = mouse.Y; var screenBounds = Screen.FromPoint(new Point(mouse.X, mouse.Y)).Bounds; if (winX + winWidth > screenBounds.Right) { winX = mouse.X - pxFromCursor - winWidth; } if (winY + winHeight > screenBounds.Bottom) { winY -= (winY + winHeight) - screenBounds.Bottom; } Left = winX; Top = winY; // // Generate preview // var sourceX = mouse.X - (numColumns - 1) / 2; // Make cursor the center var sourceY = mouse.Y - (numColumns - 1) / 2; // Make cursor the center var compensatedX = sourceX - SystemInformation.VirtualScreen.Left; // Compensate for potential negative position on multi-monitor var compensatedY = sourceY - SystemInformation.VirtualScreen.Top; // Compensate for potential negative position on multi-monitor var previewImageSource = BitmapUtil.CropBitmapSource( FreezeFrame.Instance.BitmapSource, compensatedX, compensatedY, numColumns, numColumns, FreezeFrame.Instance.PixelBuffer ); PreviewImage.Source = previewImageSource; var rgb = BitmapUtil.PixelToRgb( previewImageSource, (numColumns - 1) / 2, (numColumns - 1) / 2 ); vm.Hex = rgb.ToHex().ToString(); vm.HexTextColor = rgb.ContrastingTextColor().ToHex().ToString(); var averageRgb = BitmapUtil.AverageColor(previewImageSource); vm.GridLineColor = averageRgb.ContrastingTextColor().ToHex().ToString(); }; _timer.Start(); #endregion }