public override MainFormState UpdateState(Point location, StateChangingTrigger trigger) { switch (trigger) { case StateChangingTrigger.MouseDown: return(new MovingSelectionState(_selectionManager, this.ComponentAtCursorPoint, location)); case StateChangingTrigger.MouseMove: var activeSelectionComponent = _selectionManager .GetSelectionComponentNearPoint(location, _buffer); if (activeSelectionComponent == null) { return(new IdleState(_selectionManager, location)); } else if (activeSelectionComponent.Equals(this.ComponentAtCursorPoint)) { return(this); } else if (activeSelectionComponent.SelectionComponentType != SelectionComponentType.Inside) { return(new OverEdgeState(_selectionManager, activeSelectionComponent)); } else { return(new OverSelectionState(_selectionManager, activeSelectionComponent)); } default: return(this); } }
private void HandleMouseEvent(Point location, MouseButtons mouseButtons, StateChangingTrigger mouseTrigger) { if (IsStateChanging(location, mouseTrigger, out MainFormState state)) { _currentState = state; RaiseStateChange(); } }
private bool IsStateChanging(Point location, StateChangingTrigger trigger, out MainFormState state) { var newState = _currentState.UpdateState(location, trigger); var isStateChanging = _currentState != newState; if (isStateChanging) { _currentState = newState; } state = _currentState; return(isStateChanging); }
public override MainFormState UpdateState(Point location, StateChangingTrigger trigger) { switch (trigger) { case StateChangingTrigger.MouseUp: return(new OverEdgeState(_selectionManager, ComponentAtCursorPoint)); case StateChangingTrigger.MouseMove: var resized = ResizeActiveSelection(location); return(new ResizingSelectionState(_selectionManager, resized.GetSelectionComponentByType(ComponentAtCursorPoint.SelectionComponentType), location)); case StateChangingTrigger.MouseDown: default: return(this); } }
public override MainFormState UpdateState(Point location, StateChangingTrigger trigger) { switch (trigger) { case StateChangingTrigger.MouseDown: return(this); case StateChangingTrigger.MouseUp: return(new OverSelectionState(_selectionManager, _activeSelection.Inside)); case StateChangingTrigger.MouseMove: // Calculate the move coordinates from the _actionStartLocation. var offset = new Size(location.X - _actionStartLocation.X, location.Y - _actionStartLocation.Y); Point newLocation = _activeSelection.NWCorner.Coordinates + offset; var s = _selectionManager.MoveSelection(_activeSelection, newLocation); return(new MovingSelectionState(_selectionManager, s.Inside, location)); default: break; } throw new NotImplementedException(); }
public override MainFormState UpdateState(Point location, StateChangingTrigger trigger) { switch (trigger) { case StateChangingTrigger.MouseDown: { var component = _selectionManager.GetSelectionComponentNearPoint(location, _buffer); if (component != null && component.SelectionComponentType == SelectionComponentType.Inside) { return(new MovingSelectionState(_selectionManager, component, location)); } return(new SelectingState(_selectionManager, location)); } case StateChangingTrigger.MouseMove: { // Check whether the location is over edge or selection or nothing. // _selectionManager.GetSelectionComponentNearPoint(location, _buffer); var component = _selectionManager.GetSelectionComponentNearPoint(location, _buffer); if (component == null) { return(this); } else if (component.SelectionComponentType == SelectionComponentType.Inside) { return(new OverSelectionState(_selectionManager, component)); } else { return(new OverEdgeState(_selectionManager, component)); } } default: return(this); } }
public override MainFormState UpdateState(Point location, StateChangingTrigger trigger) { _activeSelection = _selectionManager.CreateSelection( Math.Min(location.X, _start.X), Math.Min(location.Y, _start.Y), Math.Abs(location.X - _start.X), Math.Abs(location.Y - _start.Y)); switch (trigger) { case StateChangingTrigger.MouseUp: if (_activeSelection.LeftEdge.Length > _buffer && _activeSelection.TopEdge.Length > _buffer) { _selectionManager.AddSelection(_activeSelection); } return(new IdleState(_selectionManager, location)); case StateChangingTrigger.MouseMove: return(this); default: return(this); } }
public abstract MainFormState UpdateState(Point location, StateChangingTrigger trigger);