private void buttonMakeCensor_Click(object sender, RoutedEventArgs e) { //translate global positioning into imageVideoPreview positioning Point selectionStart = SelectionRectangle.TranslatePoint( new Point(0, 0), imageVideoPreview); int beginY = (int)selectionStart.Y; int endY = beginY + (int)SelectionRectangle.Height; int beginX = (int)selectionStart.X; int endX = beginX + (int)SelectionRectangle.Width; int beginSelection = (int)sliderCensorStart.Value; int endSelection = (int)sliderCensorStop.Value; if (sliderCensorStop.Value > sliderCensorStart.Value) { Selections selectedCensor = new Selections( beginX, endX, beginY, endY, beginSelection, endSelection, temporaryFilesPath); buttonMakeCensor.IsEnabled = false; censoredSelections.Add(selectedCensor); workToDo = Work.MakeCensor; bw.RunWorkerAsync(); } else { MessageBoxResult result = MessageBox.Show("Censor start must be greater than Censor stop"); } }
//Switch between Rectangle Snapping and Painting private void SwitchMode() { SelectionRectangle.IsEnabled = !SelectionRectangle.IsEnabled; PaintSurface.IsEnabled = !PaintSurface.IsEnabled; _currentPath = null; //"Hide" Selection Rectangle SelectionRectangle.Margin = new Thickness(99999); //Stop animations by setting AnimationTimeline to null SelectedMode.BeginAnimation(OpacityProperty, null); //Set correct Selected Mode Indicator if (SelectionRectangle.IsEnabled) { //Prevent Painting in Capture Rectangle mode SelectionRectangle.CaptureMouse(); Cursor = Cursors.Cross; CropIcon.Background = Brushes.Gray; DrawIcon.Background = Brushes.Transparent; } else { //Prevent Capturing Rectangle in Paint Mode PaintSurface.CaptureMouse(); Cursor = Cursors.Pen; DrawIcon.Background = Brushes.Gray; CropIcon.Background = Brushes.Transparent; } //Fade Selected Mode View in FadeSelectedModeIn(); }
public void FinishSelection(Point point) { SelectionRectangle.SetFinish(GetIndexCoords(point)); Rectangle selectionRectangle = SelectionRectangle.GetRectangle(Viewer.TileSize); List <int> selectionList = Viewer.GetTileIdList(selectionRectangle); if (SelectMode == SelectModeEnum.Select) { if (!MultiSelect) { ClearSelection(); } AddSelection(selectionList); } else if (SelectMode == SelectModeEnum.Deselect) { RemoveSelection(selectionList); } if (!IsEmpty) { CalculateSelectionCenter(); } SelectMode = SelectModeEnum.Nothing; }
// Constructor public Form1() { InitializeComponent(); _selection = new SelectionRectangle(imageBox_Main); _imFilter = new ProbabilisticImageFiltering(); _imFilter.ImageFiltered += OnImageFiltered; }
private void imageVideoPreview_MouseMove(object sender, MouseEventArgs e) { if (isDragging) { //selection starting position SelectionRectangle.SetValue(Canvas.LeftProperty, mouseDownFrame.X); SelectionRectangle.SetValue(Canvas.TopProperty, mouseDownFrame.Y); //selection draging position double x = e.GetPosition(Selection).X; double y = e.GetPosition(Selection).Y; //setting width double xWidth = x - mouseDownFrame.X; if (xWidth <= 0) { xWidth = 0; } double yWidth = y - mouseDownFrame.Y; if (yWidth <= 0) { yWidth = 0; } SelectionRectangle.Width = xWidth; SelectionRectangle.Height = yWidth; //making selection visible if (SelectionRectangle.Visibility != Visibility.Visible) { SelectionRectangle.Visibility = Visibility.Visible; } } }
public void Draw(DrawingContext2D context) { if (SelectionBoxVisible) { context.FillRectangle(SelectionRectangle, new ColorRgbaF(1, 1, 1, 0.1f)); context.DrawRectangle(SelectionRectangle.ToRectangleF(), ColorRgbaF.Black, 2); } }
public TilesSelector(TileSetViewerVM viewer) { Viewer = viewer; SelectedIndexes = new List <int>(); SelectionRectangle = new SelectionRectangle(); SelectMode = SelectModeEnum.Nothing; MultiSelect = false; }
public void CursorDown(Point location) { SelectionRectangle = new SelectionRectangle(); location = GetSnapped(location); SelectionRectangle.SetStart(location); SpriteRectangle = SelectionRectangle.GetRectangle(); RefreshAction?.Invoke(); }
private void DrawRectangle(Graphics g) { using (Pen pen = new Pen(Options.DrawingPenColor, Options.DrawingRectangleBorderSize) { Alignment = PenAlignment.Inset }) { g.DrawRectangleProper(pen, SelectionRectangle.Offset(Options.DrawingRectangleBorderSize - 1)); } }
public void StartSelection(SelectModeEnum selectMode, Point point) { SelectMode = selectMode; SelectionRectangle.SetStart(GetIndexCoords(point)); if (!MultiSelect && selectMode == SelectModeEnum.Select) { ClearSelection(); } }
public MapEditorTilesSelectorVM(MapEditorTilesToolVM parent, TilesSelectorRenderer renderer, RenderTarget renderTarget) { Parent = parent; this.renderer = renderer; RenderTarget = renderTarget; SelectedIndexes = new List <int>(); SelectionRectangle = new SelectionRectangle(); SelectMode = SelectModeEnum.Nothing; MultiSelect = false; }
// Display the selection rectangle void OnGUI() { if (isSelecting) { // Create a rect from both mouse positions var rect = SelectionRectangle.GetScreenRectangle(mousePositionBegin, Input.mousePosition); SelectionRectangle.DrawScreenRectangle(rect, new Color(0.8f, 0.8f, 0.95f, 0.25f)); SelectionRectangle.DrawScreenRectBorder(rect, 2, new Color(0.8f, 0.8f, 0.95f)); } }
public void CursorMove(Point location) { if (SelectionRectangle == null) { return; } location = GetSnapped(location); SelectionRectangle.Update(location); SpriteRectangle = SelectionRectangle.GetRectangle(); RefreshAction?.Invoke(); }
// Check if a gameobject is within the rectangle bounds public bool IsWithinSelectionBounds(GameObject gameObject) { if (!isSelecting) { return(false); } var camera = Camera.main; var viewportBounds = SelectionRectangle.GetViewportBounds(camera, mousePositionBegin, Input.mousePosition); return(viewportBounds.Contains(camera.WorldToViewportPoint(gameObject.transform.position))); }
public void CursorUp(Point location) { if (SelectionRectangle == null) { return; } location = GetSnapped(location); SelectionRectangle.SetFinish(location); SpriteRectangle = SelectionRectangle.GetRectangle(); SelectionRectangle = null; RefreshAction?.Invoke(); UpdateControls(); }
public void Draw(DrawingContext2D context, CameraComponent camera) { foreach (var collider in SelectedObjects) { var rect = collider.GetBoundingRectangle(camera); context.FillRectangle(rect, new ColorRgbaF(1, 0, 0, 0.2f)); context.DrawRectangle(rect.ToRectangleF(), ColorRgbaF.Black, 2); } if (SelectionBoxVisible) { context.FillRectangle(SelectionRectangle, new ColorRgbaF(1, 1, 1, 0.1f)); context.DrawRectangle(SelectionRectangle.ToRectangleF(), ColorRgbaF.Black, 2); } }
private void WindowLoaded(object sender, RoutedEventArgs e) { SelectionRectangle.CaptureMouse(); Activate(); Focus(); //Hide in Alt + Tab Switcher View WindowInteropHelper wndHelper = new WindowInteropHelper(this); int exStyle = (int)NativeMethods.GetWindowLong(wndHelper.Handle, (int)NativeMethods.GetWindowLongFields.GwlExstyle); exStyle |= (int)NativeMethods.ExtendedWindowStyles.WsExToolwindow; NativeMethods.SetWindowLong(wndHelper.Handle, (int)NativeMethods.GetWindowLongFields.GwlExstyle, (IntPtr)exStyle); }
private void WindowLoaded(object sender, RoutedEventArgs e) { SelectionRectangle.CaptureMouse(); //Set Position for Spacebar Menu Rectangle bounds = Screen.PrimaryScreen.Bounds; SelectedMode.Margin = new Thickness( bounds.Width / 2 - 50, bounds.Height / 2 - 25, bounds.Width / 2 - 50, bounds.Height / 2 - 25); WindowHelper.WindowLoaded(this); }
private void UpdateDragRect() { _dragRect = GetDragRect(); var action = GetMouseAction(); if (action == MouseAction.DragSelect && DragRectThresholdExceeded) { SelectionRectangle.Visibility = Visibility.Visible; SelectionRectangle.SetValue(Canvas.LeftProperty, _dragRect.X); SelectionRectangle.SetValue(Canvas.TopProperty, _dragRect.Y); SelectionRectangle.SetValue(Canvas.WidthProperty, _dragRect.Width); SelectionRectangle.SetValue(Canvas.HeightProperty, _dragRect.Height); } else { SelectionRectangle.Visibility = Visibility.Hidden; } }
private void SelectionCanvas_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e) { _mouseDown = false; SelectionCanvas.ReleaseMouseCapture(); var position = SelectionRectangle.TranslatePoint(new System.Windows.Point(0, 0), SelectionCanvas); var top = position.Y; var left = position.X; var bottom = top + SelectionRectangle.ActualHeight; var right = left + SelectionRectangle.ActualWidth; RemoveContoursSelected(top, left, bottom, right); DrawContours(_contours); SelectionRectangle.Visibility = Visibility.Collapsed; }
public void DrawSelection(Graphics gfx) { Pen selectedPen = new Pen(Color.LightGreen); Pen selectPen = new Pen(Color.LightBlue); Pen deselectPen = new Pen(Color.Red); for (int index = 0; index < SelectedIndexes.Count; index++) { Rectangle rectangle = Viewer.Items[SelectedIndexes[index]].Rectangle; gfx.DrawRectangle(selectedPen, rectangle); } if (SelectMode == SelectModeEnum.Select) { gfx.DrawRectangle(selectPen, SelectionRectangle.GetRectangle(Viewer.TileSize)); } else if (SelectMode == SelectModeEnum.Deselect) { gfx.DrawRectangle(deselectPen, SelectionRectangle.GetRectangle(Viewer.TileSize)); } }
public void Update() { int mX = InputManager.CurrentMouseState.X; int mY = InputManager.CurrentMouseState.Y; if (!transforming) { HoverShapes(); } SelectShapes(); if (transformingShape != null) { rect = transformingShape.SelectionRect; } if (leftClicked && InputManager.IsReleased(MouseInput.LeftButton) && transformingShape != null) { UpdateShapes(); } else if (leftClicked && transformingShape != null) { ChangeWithBottomLeft(mX, mY); ChangeWithBottomRight(mX, mY); ChangeWithTopLeft(mX, mY); ChangeWithTopRight(mX, mY); } if (InputManager.IsPressed(MouseInput.LeftButton)) { leftClicked = true; } if (InputManager.IsReleased(Input.MouseInput.LeftButton)) { leftClicked = false; } }
//Close Window with fade out animation private async void CloseSnap(bool result, int delay = 0) { int duration = 70; this.Animate(OpacityProperty, Opacity, 1, duration, delay); SelectionRectangle.Animate(OpacityProperty, 0.3, 0, duration, delay); await PaintSurface.AnimateAsync(OpacityProperty, 1, 0, duration, delay); WindowState = WindowState.Minimized; try { if (result) { //Send frozen window to back NativeMethods.SetWindowPos(new WindowInteropHelper(this).Handle, NativeMethods.HwndBottom, 0, 0, 0, 0, NativeMethods.SwpNomove | NativeMethods.SwpNosize | NativeMethods.SwpNoactivate); Focusable = false; //Finish await ScreenshotHelper.FinishScreenshot(SelectionStream, HwndName); DialogResult = true; return; } if (Error) { await Statics.ShowNotificationAsync(strings.uploadingError, NotificationWindow.NotificationType.Error); } } catch { // could not finish screenshot } await Task.Delay(duration * 3); DialogResult = false; }
private void Gridimage1_MouseMove(object sender, MouseEventArgs e) { try { if (isDragging) { double x = e.GetPosition(CropPanel).X; double y = e.GetPosition(CropPanel).Y; SelectionRectangle.SetValue(Canvas.LeftProperty, Math.Min(x, anchorPoint.X)); SelectionRectangle.SetValue(Canvas.TopProperty, Math.Min(y, anchorPoint.Y)); SelectionRectangle.Width = Math.Abs(x - anchorPoint.X); SelectionRectangle.Height = Math.Abs(y - anchorPoint.Y); if (SelectionRectangle.Visibility != Visibility.Visible) { SelectionRectangle.Visibility = Visibility.Visible; } } } catch (Exception) { MessageBox.Show("There is an error while selecting area for cropping", "Crop", MessageBoxButton.OK, MessageBoxImage.Error); } }
public async Task MouseDown(Point position, MouseButton button) { var sp = await GetActiveModelPointNowAsync(position, CancellationToken.None); if (button == MouseButton.Left) { if (panCommand.IsPanning == true) { panning = true; lastPanPoint = position; } else if ((_workspace.InputService.AllowedInputTypes & InputType.Point) == InputType.Point) { _workspace.InputService.PushPoint(sp.WorldPoint); } else if ((_workspace.InputService.AllowedInputTypes & InputType.Entity) == InputType.Entity) { var selected = GetHitEntity(position); if (selected != null) { _workspace.InputService.PushEntity(selected); } } else if ((_workspace.InputService.AllowedInputTypes & InputType.Entities) == InputType.Entities || selectingRectangle || !_workspace.IsCommandExecuting) { if (selecting) { // finish selection IEnumerable <Entity> entities = null; if (selectingRectangle) { selectingRectangle = false; SetCursorVisibility(); var topLeftScreen = new Point(Math.Min(firstSelectionPoint.X, sp.ControlPoint.X), Math.Min(firstSelectionPoint.Y, sp.ControlPoint.Y), 0.0); var bottomRightScreen = new Point(Math.Max(firstSelectionPoint.X, sp.ControlPoint.X), Math.Max(firstSelectionPoint.Y, sp.ControlPoint.Y), 0.0); var selection = new SelectionRectangle( topLeftScreen, bottomRightScreen, Unproject(topLeftScreen), Unproject(bottomRightScreen)); selectionDone.SetResult(selection); } else { var rect = new Rect( Math.Min(firstSelectionPoint.X, currentSelectionPoint.X), Math.Min(firstSelectionPoint.Y, currentSelectionPoint.Y), Math.Abs(firstSelectionPoint.X - currentSelectionPoint.X), Math.Abs(firstSelectionPoint.Y - currentSelectionPoint.Y)); entities = GetContainedEntities(rect, currentSelectionPoint.X < firstSelectionPoint.X); } selecting = false; UpdateSelectionRectangle(null); if (entities != null) { if (!_workspace.IsCommandExecuting) { _workspace.SelectedEntities.AddRange(entities); } else { _workspace.InputService.PushEntities(entities); } } } else { SelectedEntity selected = null; if (selectingRectangle) { _workspace.OutputService.WriteLine("Select second point"); } else { selected = GetHitEntity(position); } if (selected != null) { if (!_workspace.IsCommandExecuting) { _workspace.SelectedEntities.Add(selected.Entity); } else { _workspace.InputService.PushEntities(new[] { selected.Entity }); } } else { selecting = true; firstSelectionPoint = sp.ControlPoint; currentSelectionPoint = position; } } } else if (_workspace.InputService.AllowedInputTypes == InputType.None || !_workspace.IsCommandExecuting) { // do hot-point tracking var selected = GetHitEntity(position); if (selected != null) { _workspace.SelectedEntities.Add(selected.Entity); } } } else if (button == MouseButton.Middle) { panning = true; lastPanPoint = position; } else if (button == MouseButton.Right) { _workspace.InputService.PushNone(); } }
public SelectState(BlackboardBehaviour blackboard) : base(blackboard) { _selectionRectangle = new SelectionRectangle((Editor.Blackboard)blackboard.Blackboard); }
private async void OnMouseDown(object sender, PointerButtonEventArgs e) { var cursor = GetPointerPosition(e); var sp = await GetActiveModelPointNowAsync(cursor, CancellationToken.None); if (IsLeftButtonPressed(e)) { if ((Workspace.InputService.AllowedInputTypes & InputType.Point) == InputType.Point) { Workspace.InputService.PushPoint(sp.WorldPoint); } else if ((Workspace.InputService.AllowedInputTypes & InputType.Entity) == InputType.Entity) { var selected = GetHitEntity(cursor); if (selected != null) { Workspace.InputService.PushEntity(selected); } } else if ((Workspace.InputService.AllowedInputTypes & InputType.Entities) == InputType.Entities || selectingRectangle || !Workspace.IsCommandExecuting) { if (selecting) { // finish selection IEnumerable <Entity> entities = null; if (selectingRectangle) { selectingRectangle = false; ClearSnapPoints(); SetCursorVisibility(); var topLeftScreen = new Point(Math.Min(firstSelectionPoint.X, sp.ControlPoint.X), Math.Min(firstSelectionPoint.Y, sp.ControlPoint.Y), 0.0); var bottomRightScreen = new Point(Math.Max(firstSelectionPoint.X, sp.ControlPoint.X), Math.Max(firstSelectionPoint.Y, sp.ControlPoint.Y), 0.0); var selection = new SelectionRectangle( topLeftScreen, bottomRightScreen, Unproject(topLeftScreen), Unproject(bottomRightScreen)); selectionDone.SetResult(selection); } else { var rect = new Rect( Math.Min(firstSelectionPoint.X, currentSelectionPoint.X), Math.Min(firstSelectionPoint.Y, currentSelectionPoint.Y), Math.Abs(firstSelectionPoint.X - currentSelectionPoint.X), Math.Abs(firstSelectionPoint.Y - currentSelectionPoint.Y)); entities = GetContainedEntities(rect, currentSelectionPoint.X < firstSelectionPoint.X); } selecting = false; SetSelectionLineVisibility(Visibility.Collapsed); if (entities != null) { if (!Workspace.IsCommandExecuting) { Workspace.SelectedEntities.AddRange(entities); } else { Workspace.InputService.PushEntities(entities); } } } else { SelectedEntity selected = null; if (selectingRectangle) { Workspace.OutputService.WriteLine("Select second point"); } else { selected = GetHitEntity(cursor); } if (selected != null) { if (!Workspace.IsCommandExecuting) { Workspace.SelectedEntities.Add(selected.Entity); } else { Workspace.InputService.PushEntities(new[] { selected.Entity }); } } else { selecting = true; firstSelectionPoint = sp.ControlPoint; currentSelectionPoint = cursor; SetSelectionLineVisibility(Visibility.Visible); } } } else if (Workspace.InputService.AllowedInputTypes == InputType.None || !Workspace.IsCommandExecuting) { // do hot-point tracking var selected = GetHitEntity(cursor); if (selected != null) { Workspace.SelectedEntities.Add(selected.Entity); } } } else if (IsMiddleButtonPressed(e)) { panning = true; lastPanPoint = cursor; } else if (IsRightButtonPressed(e)) { Workspace.InputService.PushNone(); } }
public void UpdateSelection(Point point) { SelectionRectangle.Update(GetIndexCoords(point)); }