protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); isMouseDown = false; if (interactionState == InteractionState.Selection) { selectedElements = GetElementsByRectangle(SelectionRectangle); interactionState = InteractionState.None; Cursor = Cursors.Default; } else if (interactionState == InteractionState.Pan) { if (panSource == PanSource.Mouse) { interactionState = InteractionState.None; panSource = PanSource.None; Cursor = Cursors.Default; } else if (panSource == PanSource.Keyboard) { Cursor = CursorHelper.LoadFromResource(Properties.Resources.grab); } } else { interactionState = InteractionState.None; Cursor = Cursors.Default; } Refresh(); }
protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if (e.KeyData == Keys.Space) { if (interactionState == InteractionState.None) { interactionState = InteractionState.Pan; panSource = PanSource.Keyboard; Cursor = CursorHelper.LoadFromResource(Properties.Resources.grab); Refresh(); } } }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); controlMouseDownLocation = e.Location; isMouseDown = true; bool needsRefresh = false; mouseHitsSelection = false; if (e.Button == MouseButtons.Left) { // resize if (interactionState == InteractionState.None && selectedElements != null && selectedElements.Count == 1) { LayoutProperties layoutProperties = new LayoutProperties(); layoutProperties.DesignAreaLocation = DesignAreaLocation; layoutProperties.DesignAreaSize = DesignAreaSize; layoutProperties.ViewportLocation = ViewportLocation; layoutProperties.ViewportSize = ViewportSize; layoutProperties.ZoomRatio = ZoomRatio; foreach (LayoutElement selectedElement in selectedElements) { TransformHandle transformHandle = DesignerHelper.GetTransformHandleType(selectedElement, layoutProperties, e.Location); if (transformHandle != TransformHandle.None) { this.transformHandle = transformHandle; interactionState = InteractionState.SizeAttempt; needsRefresh = true; } } } // click selection if (interactionState == InteractionState.None) { LayoutElement element = GetElementByLocation(controlMouseDownLocation); if (element != null) { mouseHitsSelection = true; if (KeyboardHelper.IsShiftKeyPressed) { if (!IsElementInSelection(element)) { AddElementToSelection(element); } else { RemoveElementFromSelection(element); } } else { if (!IsElementInSelection(element)) { ClearSelection(); AddElementToSelection(element); } } needsRefresh = true; } else { if (!KeyboardHelper.IsShiftKeyPressed) { ClearSelection(); needsRefresh = true; } } } } if (e.Button == MouseButtons.Middle || interactionState == InteractionState.Pan) { interactionState = InteractionState.Pan; if (panSource == PanSource.None) { panSource = PanSource.Mouse; } oldViewportLocation = ViewportLocation; Cursor = CursorHelper.LoadFromResource(Properties.Resources.grabbing); needsRefresh = true; } if (needsRefresh) { Refresh(); } }