From 5bab4793255f353172b74969770fb2edc5340019 Mon Sep 17 00:00:00 2001 From: Jaex Date: Mon, 13 Jun 2016 19:48:41 +0300 Subject: [PATCH] Added configurable mouse click actions for region capture --- ShareX.ScreenCaptureLib/Enums.cs | 20 ++++++ .../Shapes/ShapeManager.cs | 61 ++++++++++++++++--- ShareX.ScreenCaptureLib/SurfaceOptions.cs | 12 ++++ ShareX/Forms/TaskSettingsForm.Designer.cs | 1 + ShareX/Forms/TaskSettingsForm.resx | 8 +-- 5 files changed, 90 insertions(+), 12 deletions(-) diff --git a/ShareX.ScreenCaptureLib/Enums.cs b/ShareX.ScreenCaptureLib/Enums.cs index 0d7405b3f..bfd7341ce 100644 --- a/ShareX.ScreenCaptureLib/Enums.cs +++ b/ShareX.ScreenCaptureLib/Enums.cs @@ -155,6 +155,26 @@ public enum RectangleRegionMode OneClick } + public enum RegionCaptureAction + { + [Description("Do nothing")] + None, + [Description("Cancel capture")] + CancelCapture, + [Description("Remove shape or cancel capture")] + RemoveShapeCancelCapture, + [Description("Remove shape")] + RemoveShape, + [Description("Open options menu")] + OpenOptionsMenu, + [Description("Swap tool type")] + SwapToolType, + [Description("Capture fullscreen")] + CaptureFullscreen, + [Description("Capture active monitor")] + CaptureActiveMonitor + } + public enum ShapeType { [Description("Region: Rectangle")] diff --git a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs index c2669510f..8e647e5bd 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs @@ -827,10 +827,9 @@ private void form_MouseUp(object sender, MouseEventArgs e) DeleteCurrentShape(); EndRegionSelection(); } - else if (form.Mode == RectangleRegionMode.Annotation && cmsContextMenu != null) + else if (form.Mode == RectangleRegionMode.Annotation) { - cmsContextMenu.Show(form, e.Location.Add(-10, -10)); - Config.ShowMenuTip = false; + RunRegionCaptureAction(Config.MouseRightClickAction); } else if (IsShapeIntersect()) { @@ -843,14 +842,15 @@ private void form_MouseUp(object sender, MouseEventArgs e) } else if (e.Button == MouseButtons.Middle) { - form.Close(RegionResult.Close); + RunRegionCaptureAction(Config.MouseMiddleClickAction); } else if (e.Button == MouseButtons.XButton1) { - if (form.Mode == RectangleRegionMode.Annotation) - { - SwapShapeType(); - } + RunRegionCaptureAction(Config.Mouse4ClickAction); + } + else if (e.Button == MouseButtons.XButton2) + { + RunRegionCaptureAction(Config.Mouse5ClickAction); } } @@ -993,6 +993,51 @@ private void form_KeyUp(object sender, KeyEventArgs e) } } + private void RunRegionCaptureAction(RegionCaptureAction action) + { + switch (action) + { + case RegionCaptureAction.CancelCapture: + form.Close(RegionResult.Close); + break; + case RegionCaptureAction.RemoveShapeCancelCapture: + if (IsShapeIntersect()) + { + DeleteIntersectShape(); + } + else + { + form.Close(RegionResult.Close); + } + break; + case RegionCaptureAction.RemoveShape: + if (IsShapeIntersect()) + { + DeleteIntersectShape(); + } + break; + case RegionCaptureAction.OpenOptionsMenu: + if (form.Mode == RectangleRegionMode.Annotation && cmsContextMenu != null) + { + cmsContextMenu.Show(form, InputManager.MousePosition0Based.Add(-10, -10)); + Config.ShowMenuTip = false; + } + break; + case RegionCaptureAction.SwapToolType: + if (form.Mode == RectangleRegionMode.Annotation) + { + SwapShapeType(); + } + break; + case RegionCaptureAction.CaptureFullscreen: + form.Close(RegionResult.Fullscreen); + break; + case RegionCaptureAction.CaptureActiveMonitor: + form.Close(RegionResult.ActiveMonitor); + break; + } + } + public void Update() { BaseShape shape = CurrentShape; diff --git a/ShareX.ScreenCaptureLib/SurfaceOptions.cs b/ShareX.ScreenCaptureLib/SurfaceOptions.cs index eca8fa9cd..fa42a815d 100644 --- a/ShareX.ScreenCaptureLib/SurfaceOptions.cs +++ b/ShareX.ScreenCaptureLib/SurfaceOptions.cs @@ -37,6 +37,18 @@ public class SurfaceOptions [DefaultValue(true), Description("Allow screenshot capture as soon as the mouse is released. This disables the ability to capture multiple shapes and to move and/or resize them.")] public bool QuickCrop { get; set; } + [DefaultValue(RegionCaptureAction.OpenOptionsMenu), Description("What should happen when you right click in region capture?"), TypeConverter(typeof(EnumDescriptionConverter))] + public RegionCaptureAction MouseRightClickAction { get; set; } + + [DefaultValue(RegionCaptureAction.CancelCapture), Description("What should happen when you middle click in region capture?"), TypeConverter(typeof(EnumDescriptionConverter))] + public RegionCaptureAction MouseMiddleClickAction { get; set; } + + [DefaultValue(RegionCaptureAction.SwapToolType), Description("What should happen when you mouse 4 click in region capture?"), TypeConverter(typeof(EnumDescriptionConverter))] + public RegionCaptureAction Mouse4ClickAction { get; set; } + + [DefaultValue(RegionCaptureAction.CaptureFullscreen), Description("What should happen when you mouse 5 click in region capture?"), TypeConverter(typeof(EnumDescriptionConverter))] + public RegionCaptureAction Mouse5ClickAction { get; set; } + [DefaultValue(true), Description("If annotation is disabled then right click will cancel screen capture instead of opening options menu.")] public bool AnnotationEnabled { get; set; } diff --git a/ShareX/Forms/TaskSettingsForm.Designer.cs b/ShareX/Forms/TaskSettingsForm.Designer.cs index a26cabfd2..29cbcb92f 100644 --- a/ShareX/Forms/TaskSettingsForm.Designer.cs +++ b/ShareX/Forms/TaskSettingsForm.Designer.cs @@ -1616,6 +1616,7 @@ private void InitializeComponent() this.Controls.Add(this.tcTaskSettings); this.Controls.Add(this.tttvMain); this.Name = "TaskSettingsForm"; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.Resize += new System.EventHandler(this.TaskSettingsForm_Resize); this.tcTaskSettings.ResumeLayout(false); this.tpTask.ResumeLayout(false); diff --git a/ShareX/Forms/TaskSettingsForm.resx b/ShareX/Forms/TaskSettingsForm.resx index 22a646843..c17178931 100644 --- a/ShareX/Forms/TaskSettingsForm.resx +++ b/ShareX/Forms/TaskSettingsForm.resx @@ -1067,7 +1067,7 @@ 0 - 100 - @Invariant + lblImageJPEGQualityHint @@ -1811,7 +1811,7 @@ Y - @Invariant + lblCaptureCustomRegionY @@ -1841,7 +1841,7 @@ X - @Invariant + lblCaptureCustomRegionX @@ -3020,7 +3020,7 @@ 0 - @Invariant + lblAutoIncrementNumber