private void PictureBox1MouseDown(object sender, MouseEventArgs e) { itemSelected = false; HoldRedraw = true; PointF pos = new PointF(e.X / zoom, e.Y / zoom); if (this.multiSelectPhase == MultiObjectSelect.AREA_SELECTED) { if (GraphUltility.IsBelongRectangle(this.selectedArea, pos)) { this.multiSelectPhase = MultiObjectSelect.START_MOVING; foreach (CanvasItemData selectedItem in this.selectedItems) { selectedItem.JustGainedFocus = true; selectedItem.Focused = true; itemsList.Remove(selectedItem); itemsList.Add(selectedItem); selectedItem.Item.HandleMouseDown(new PointF(selectedItem.Item.X, selectedItem.Item.Y)); } this.CanvasItemsSelected(this, new CanvasItemsEventArgs(this.selectedItems)); } else { this.multiSelectPhase = MultiObjectSelect.STAR; } } lastMouseDownPosition = pos; lastMouseClickPosition = pos; if (e.Button == MouseButtons.Right) { this.lastRightClickPosition = pos; } CanvasItemData itemNode = FindCanvasItemNode(pos); dragItemNode = itemNode; if (!ctrlDown) { foreach (CanvasItemData item in itemsList) { item.Item.StopEditing(); if (itemNode == null || item != itemNode) { item.Focused = false; if (item.Item is StateItem) { (item.Item as StateItem).CurrentState = ItemState.Free; } } } } foreach (Route route in diagramRouter.Routes) { route.CurrentState = ItemState.Free; } if (itemNode != null) { if (!itemNode.Focused) { itemNode.JustGainedFocus = true; itemNode.Focused = true; itemsList.Remove(itemNode); itemsList.Add(itemNode); itemNode.Item.HandleMouseDown(pos); itemSelected = true; CanvasItemSelected(this, new CanvasItemEventArgs(itemNode)); } else { itemSelected = true; itemNode.Item.HandleMouseDown(pos); CanvasItemSelected(this, new CanvasItemEventArgs(itemNode)); } } else { foreach (Route route in diagramRouter.Routes) { if (route.IsBelongRoute(pos)) { route.CurrentState = ItemState.Selected; CanvasRouteSelected(this, new CanvasRouteEventArgs(route)); this.itemSelected = true; break; } } if (!this.itemSelected) { CanvasItemSelected(this, new CanvasItemEventArgs(null)); } } HoldRedraw = false; this.RefreshPictureBox(); }
private void PictureBox1MouseUp(object sender, MouseEventArgs e) { PointF pos = new PointF(e.X / zoom, e.Y / zoom); switch (this.multiSelectPhase) { case MultiObjectSelect.STAR: if (!(pos.X == lastMouseDownPosition.X && pos.Y == lastMouseDownPosition.Y)) { this.multiSelectPhase = MultiObjectSelect.AREA_SELECTED; this.selectedArea.X = (int)Math.Min(lastMouseDownPosition.X, pos.X); this.selectedArea.Y = (int)Math.Min(lastMouseDownPosition.Y, pos.Y); this.selectedArea.Width = (int)Math.Abs(lastMouseDownPosition.X - pos.X); this.selectedArea.Height = (int)Math.Abs(lastMouseDownPosition.Y - pos.Y); List <CanvasItemData> selectedItems = new List <CanvasItemData>(); foreach (CanvasItemData item in itemsList) { if (GraphUltility.IsBelongRectangle(this.selectedArea, new PointF(item.Item.X, item.Item.Y))) { selectedItems.Add(item); } } this.selectedItems.Clear(); this.selectedItems.AddRange(selectedItems); foreach (CanvasItemData selectedItem in this.selectedItems) { selectedItem.Item.HandleMouseDown(new PointF(selectedItem.Item.X, selectedItem.Item.Y)); } CanvasItemsSelected(this, new CanvasItemsEventArgs(selectedItems)); this.Refresh(); this.RefreshPictureBox(); } break; case MultiObjectSelect.START_MOVING: this.SaveCurrentCanvas(this, EventArgs.Empty); FinishMultiObjectAction(); break; default: break; } if (dragItemNode != null) { dragItemNode.Item.HandleMouseUp(pos); if (this.lastMouseDownPosition != pos) { this.SaveCurrentCanvas(this, EventArgs.Empty); } } dragItemNode = null; CanvasItemData itemNode = FindCanvasItemNode(pos); if (itemNode != null) { itemNode.Item.HandleMouseUp(pos); } }
public void FinishMultiObjectAction() { this.multiSelectPhase = MultiObjectSelect.STAR; this.selectedItems.Clear(); this.Refresh(); }