diff --git a/ShareX.ScreenCaptureLib/Forms/SurfaceForm.cs b/ShareX.ScreenCaptureLib/Forms/SurfaceForm.cs index 13c97a24d..59c36f0b1 100644 --- a/ShareX.ScreenCaptureLib/Forms/SurfaceForm.cs +++ b/ShareX.ScreenCaptureLib/Forms/SurfaceForm.cs @@ -94,6 +94,8 @@ public SurfaceForm() private void InitializeComponent() { + components = new Container(); + SuspendLayout(); AutoScaleDimensions = new SizeF(6F, 13F); AutoScaleMode = AutoScaleMode.Font; @@ -413,7 +415,7 @@ protected void HideNodes() } } - private IContainer components = null; + public IContainer components = null; protected override void Dispose(bool disposing) { diff --git a/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs b/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs index fb9a01614..a59e5b457 100644 --- a/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs +++ b/ShareX.ScreenCaptureLib/RegionHelpers/AreaManager.cs @@ -51,7 +51,7 @@ private set currentShapeType = value; config.CurrentShapeType = CurrentShapeType; DeselectArea(); - UpdateMenuShapeType(); + OnCurrentShapeTypeChanged(CurrentShapeType); } } @@ -141,6 +141,8 @@ public bool IsResizing public bool IncludeControls { get; set; } public int MinimumSize { get; set; } = 3; + public event Action CurrentShapeTypeChanged; + private RectangleRegionForm surface; private SurfaceOptions config; private ContextMenuStrip cmsContextMenu; @@ -150,8 +152,6 @@ public AreaManager(RectangleRegionForm surface) this.surface = surface; config = surface.Config; - //CurrentShapeType = config.CurrentShapeType; - ResizeManager = new ResizeManager(surface, this); surface.MouseDown += surface_MouseDown; @@ -161,6 +161,9 @@ public AreaManager(RectangleRegionForm surface) surface.MouseWheel += surface_MouseWheel; CreateContextMenu(); + + //CurrentShapeType = config.CurrentShapeType; + CurrentShapeType = ShapeType.RegionRectangle; } private void surface_MouseWheel(object sender, MouseEventArgs e) @@ -177,7 +180,7 @@ private void surface_MouseWheel(object sender, MouseEventArgs e) private void CreateContextMenu() { - cmsContextMenu = new ContextMenuStrip(); + cmsContextMenu = new ContextMenuStrip(surface.components); ToolStripMenuItem tsmiCancelCapture = new ToolStripMenuItem("Cancel capture"); tsmiCancelCapture.Click += (sender, e) => surface.Close(SurfaceResult.Close); @@ -393,9 +396,18 @@ private void CreateContextMenu() tsmiShowCrosshair.Click += (sender, e) => config.ShowCrosshair = tsmiShowCrosshair.Checked; tsmiOptions.DropDownItems.Add(tsmiShowCrosshair); - cmsContextMenu.Opening += (sender, e) => + CurrentShapeTypeChanged += shapeType => { - switch (CurrentShapeType) + foreach (ToolStripMenuItem tsmi in cmsContextMenu.Items.OfType().Where(x => x.Tag is ShapeType)) + { + if ((ShapeType)tsmi.Tag == shapeType) + { + tsmi.RadioCheck(); + break; + } + } + + switch (shapeType) { default: tssShapeOptions.Visible = false; @@ -413,7 +425,7 @@ private void CreateContextMenu() break; } - switch (CurrentShapeType) + switch (shapeType) { default: tsmiBorderColor.Visible = false; @@ -429,7 +441,7 @@ private void CreateContextMenu() break; } - switch (CurrentShapeType) + switch (shapeType) { default: tsmiFillColor.Visible = false; @@ -441,10 +453,10 @@ private void CreateContextMenu() break; } - tslnudRoundedRectangleRadius.Visible = CurrentShapeType == ShapeType.RegionRoundedRectangle || CurrentShapeType == ShapeType.DrawingRoundedRectangle; - tslnudBlurRadius.Visible = CurrentShapeType == ShapeType.DrawingBlur; - tslnudPixelateSize.Visible = CurrentShapeType == ShapeType.DrawingPixelate; - tsmiHighlightColor.Visible = CurrentShapeType == ShapeType.DrawingHighlight; + tslnudRoundedRectangleRadius.Visible = shapeType == ShapeType.RegionRoundedRectangle || shapeType == ShapeType.DrawingRoundedRectangle; + tslnudBlurRadius.Visible = shapeType == ShapeType.DrawingBlur; + tslnudPixelateSize.Visible = shapeType == ShapeType.DrawingPixelate; + tsmiHighlightColor.Visible = shapeType == ShapeType.DrawingHighlight; }; } @@ -848,20 +860,6 @@ private void UpdateShape(BaseShape shape) } } - private void UpdateMenuShapeType() - { - foreach (ToolStripMenuItem tsmi in cmsContextMenu.Items.OfType().Where(x => x.Tag is ShapeType)) - { - ShapeType shapeType = (ShapeType)tsmi.Tag; - - if (shapeType == CurrentShapeType) - { - tsmi.RadioCheck(); - return; - } - } - } - private void SelectArea() { if (!CurrentRectangle.IsEmpty && !config.IsFixedSize) @@ -958,5 +956,13 @@ public Rectangle CombineAreas() return Rectangle.Empty; } + + private void OnCurrentShapeTypeChanged(ShapeType shapeType) + { + if (CurrentShapeTypeChanged != null) + { + CurrentShapeTypeChanged(shapeType); + } + } } } \ No newline at end of file