FreeformShapeTool.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Drawing;
  2. using System.Windows.Forms;
  3. namespace PaintDotNet.Measurement.Tools
  4. {
  5. public class FreeformShapeTool : ShapeTool
  6. {
  7. private Cursor freeformShapeToolCursor;
  8. protected override RectangleF[] GetOptimizedShapeOutlineRegion(PointF[] points, PdnGraphicsPath path)
  9. {
  10. return Utility.SimplifyTrace(path.PathPoints);
  11. }
  12. protected override PdnGraphicsPath CreateShapePath(PointF[] points)
  13. {
  14. // make sure we don't screw them up
  15. if (points.Length < 2)
  16. {
  17. return null;
  18. }
  19. // make sure the shape has an area of at least 1
  20. // we can determine this by making sure that all the Points in points are not all the same
  21. bool allTheSame = true;
  22. foreach (PointF pt in points)
  23. {
  24. if (pt != points[0])
  25. {
  26. allTheSame = false;
  27. break;
  28. }
  29. }
  30. if (allTheSame)
  31. {
  32. return null;
  33. }
  34. PdnGraphicsPath path = new PdnGraphicsPath();
  35. path.AddLines(points);
  36. path.AddLine(points[points.Length - 1], points[0]);
  37. path.CloseAllFigures();
  38. return path;
  39. }
  40. protected override void OnActivate()
  41. {
  42. this.freeformShapeToolCursor = new Cursor(PdnResources.GetResourceStream("Cursors.FreeformShapeToolCursor.cur"));
  43. this.Cursor = this.freeformShapeToolCursor;
  44. base.OnActivate();
  45. }
  46. protected override void OnDeactivate()
  47. {
  48. if (this.freeformShapeToolCursor != null)
  49. {
  50. this.freeformShapeToolCursor.Dispose();
  51. this.freeformShapeToolCursor = null;
  52. }
  53. base.OnDeactivate();
  54. }
  55. public FreeformShapeTool(IDocumentWorkspace documentWorkspace)
  56. : base(documentWorkspace,
  57. PdnResources.GetImageResource("Icons.FreeformShapeToolIcon.png"),
  58. PdnResources.GetString("FreeformShapeTool.Name"),
  59. PdnResources.GetString("FreeformShapeTool.HelpText"))
  60. {
  61. }
  62. }
  63. }