private void SetSelectedRectangle(Point beginPoint, Point endPoint) { // Make sure x/y are top-left, and width/height is bottom-right Point a = Utils.Min(beginPoint, endPoint); Point b = Utils.Max(beginPoint, endPoint); var newRect = Rectangle.FromLTRB(a.X, a.Y, b.X, b.Y); // Determine if there is a need to update shapes if (selectedRectangle == newRect) { return; } // Update selected rectangle selectedRectangle = newRect; // Update selected shapes var shapes = Canvas.Instance.GetShapesByRectangle(selectedRectangle); ClickData.Clear(true); ClickData.Set(shapes); // Update borders of selected shapes // This may be needed Canvas.Instance.Invalidate(); }
private void OnMouseDown_HandleDragSelection(object sender, MouseEventArgs e, Point mouseLocation, Point snappedLocation, bool setShapes) { if (IsMouseOverSelectedRectangle(mouseLocation)) { if (setShapes) { var shapes = Canvas.Instance.GetShapesByRectangle(selectedRectangle); ClickData.Set(shapes); } mouseDownLocation = snappedLocation; ClickData.Set(snappedLocation, ShapeClickAction.Drag); selectedRectangleDownLocation = selectedRectangle.Location; action = SelectorAction.BeginMoveSelectedShapes; OnMouseMove(sender, e); } else { if (!MouseWasDown) { action = SelectorAction.BeginSelectionRectangle; mouseDownLocation = new Point(); selectedRectangleDownLocation = new Point(); ClickData.Clear(true); OnMouseDown(sender, e); } } }
private void ClearSelectedRectangle() { selectedRectangle = new Rectangle(); selectedRectangleDownLocation = new Point(); mouseDownLocation = new Point(); ClickData.Clear(true); action = SelectorAction.None; }
public override void OnUnloadTool() { ClearSelectedRectangle(); ClickData.Clear(false); action = SelectorAction.None; if (OutlinePen != null) { OutlinePen.Dispose(); } }
/// <summary> /// Unloads the current tool and switches to the new tool, e.g. "SwitchToTool(new MainTool());" /// </summary> /// <param name="newTool">The tool to switch to. Usually "new SomeToolDerivedFromToolBase()"</param> internal static void SwitchToTool(ToolBase newTool) { if (Current != null) { Current.UnloadTool(); ClickData.Clear(true); Current = null; } Current = newTool; }
public override void OnMouseUp(object sender, MouseEventArgs e) { if (ClickData.Action == ShapeClickAction.None) { return; } ClickData.ShapeApplyOffset(); // Reset click data ClickData.Clear(false); Canvas.Instance.Invalidate(); }
public override void OnMouseUp(object sender, MouseEventArgs e) { var mouseLocation = e.Location; var snappedLocation = Grid.SnapToGrid(mouseLocation); switch (action) { case SelectorAction.BeginSelectionRectangle: // Redirect to MouseUp:EndSelectionRectangle action = SelectorAction.EndSelectionRectangle; OnMouseUp(sender, e); break; case SelectorAction.EndSelectionRectangle: SetSelectedRectangle(mouseDownLocation, mouseLocation); break; case SelectorAction.BeginMoveSelectedShapes: // Redirect to MouseUp:EndMoveSelectedShapes action = SelectorAction.EndMoveSelectedShapes; OnMouseUp(sender, e); break; case SelectorAction.EndMoveSelectedShapes: ClickData.ShapeApplyOffset(); // Reset click data ClickData.Clear(false); selectedRectangleDownLocation = new Point(); mouseDownLocation = new Point(); break; case SelectorAction.None: break; default: throw EnumNotImplementedException.Throw(action, ExceptionMessages.MSG_NOT_YET_IMPLEMENTED); } Canvas.Instance.Invalidate(); }
private static bool ExportToImage(string path) { bool result = true; ClickData.Clear(true); Canvas canvas = Canvas.Instance; // Hide borders when saving image var prevBorder = canvas.BorderStyle; canvas.BorderStyle = BorderStyle.None; IsExportingImage = true; canvas.Invalidate(); var bounds = canvas.layer.GetAllShapesBoundary(); ImageFormat imageFormat = Utils.GetImageFormatByExtension(path); if (bounds.Width == 0 && bounds.Height == 0) { MessageBox.Show("Nothing to save. Try placing some shapes before exporting to image."); result = false; } using (var bitmap = new Bitmap(bounds.Width, bounds.Height)) { canvas.DrawToBitmap(bitmap, bounds); bitmap.Save(path, imageFormat); } // Restore border canvas.BorderStyle = prevBorder; IsExportingImage = false; canvas.Invalidate(); return(result); }