Added options sub menu to region capture

This commit is contained in:
Jaex 2016-05-04 14:04:26 +03:00
parent 61887a6b32
commit 9531740b2d
4 changed files with 108 additions and 54 deletions

View file

@ -37,11 +37,12 @@ private void InitializeComponent()
// //
// flpMain // flpMain
// //
this.flpMain.AutoSize = true;
this.flpMain.Controls.Add(this.lblText); this.flpMain.Controls.Add(this.lblText);
this.flpMain.Controls.Add(this.nudValue); this.flpMain.Controls.Add(this.nudValue);
this.flpMain.Location = new System.Drawing.Point(0, 0); this.flpMain.Location = new System.Drawing.Point(0, 0);
this.flpMain.Name = "flpMain"; this.flpMain.Name = "flpMain";
this.flpMain.Size = new System.Drawing.Size(173, 26); this.flpMain.Size = new System.Drawing.Size(99, 26);
this.flpMain.TabIndex = 0; this.flpMain.TabIndex = 0;
this.flpMain.WrapContents = false; this.flpMain.WrapContents = false;
// //
@ -58,10 +59,10 @@ private void InitializeComponent()
// //
// nudValue // nudValue
// //
this.nudValue.Anchor = System.Windows.Forms.AnchorStyles.None; this.nudValue.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.nudValue.Location = new System.Drawing.Point(41, 3); this.nudValue.Location = new System.Drawing.Point(41, 3);
this.nudValue.Name = "nudValue"; this.nudValue.Name = "nudValue";
this.nudValue.Size = new System.Drawing.Size(68, 20); this.nudValue.Size = new System.Drawing.Size(55, 20);
this.nudValue.TabIndex = 1; this.nudValue.TabIndex = 1;
this.nudValue.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; this.nudValue.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
// //
@ -72,11 +73,12 @@ private void InitializeComponent()
this.BackColor = System.Drawing.Color.Transparent; this.BackColor = System.Drawing.Color.Transparent;
this.Controls.Add(this.flpMain); this.Controls.Add(this.flpMain);
this.Name = "LabeledNumericUpDown"; this.Name = "LabeledNumericUpDown";
this.Size = new System.Drawing.Size(173, 26); this.Size = new System.Drawing.Size(100, 26);
this.flpMain.ResumeLayout(false); this.flpMain.ResumeLayout(false);
this.flpMain.PerformLayout(); this.flpMain.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudValue)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nudValue)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }

View file

@ -84,6 +84,18 @@ public decimal Minimum
} }
} }
public decimal Increment
{
get
{
return nudValue.Increment;
}
set
{
nudValue.Increment = value;
}
}
public EventHandler ValueChanged; public EventHandler ValueChanged;
public LabeledNumericUpDown() public LabeledNumericUpDown()

View file

@ -77,8 +77,6 @@ public Color CurrentColor
public RectangleRegionForm() public RectangleRegionForm()
{ {
AreaManager = new AreaManager(this);
KeyDown += RectangleRegion_KeyDown; KeyDown += RectangleRegion_KeyDown;
MouseDown += RectangleRegion_MouseDown; MouseDown += RectangleRegion_MouseDown;
MouseWheel += RectangleRegion_MouseWheel; MouseWheel += RectangleRegion_MouseWheel;
@ -170,6 +168,7 @@ public override void Prepare()
if (Config != null) if (Config != null)
{ {
AreaManager = new AreaManager(this);
AreaManager.WindowCaptureMode = Config.DetectWindows; AreaManager.WindowCaptureMode = Config.DetectWindows;
AreaManager.IncludeControls = Config.DetectControls; AreaManager.IncludeControls = Config.DetectControls;
@ -185,11 +184,11 @@ public override void Prepare()
AreaManager.Windows = wla.GetWindowInfoListAsync(5000); AreaManager.Windows = wla.GetWindowInfoListAsync(5000);
}); });
} }
}
if (Config.UseCustomInfoText || ScreenColorPickerMode) if (Config.UseCustomInfoText || ScreenColorPickerMode)
{ {
bmpSurfaceImage = new Bitmap(SurfaceImage); bmpSurfaceImage = new Bitmap(SurfaceImage);
}
} }
} }

View file

@ -112,7 +112,7 @@ public bool IsCurrentShapeTypeRegion
} }
public Color BorderColor { get; set; } = Color.Red; public Color BorderColor { get; set; } = Color.Red;
public int BorderSize { get; set; } = 1; public int BorderSize { get; set; } = 2;
public Color FillColor { get; set; } = Color.Transparent; public Color FillColor { get; set; } = Color.Transparent;
public float RoundedRectangleRadius { get; set; } = 15; public float RoundedRectangleRadius { get; set; } = 15;
@ -143,13 +143,15 @@ public bool IsResizing
public int MinimumSize { get; set; } = 3; public int MinimumSize { get; set; } = 3;
private RectangleRegionForm surface; private RectangleRegionForm surface;
private ContextMenuStrip cmsShapeMenu; private SurfaceOptions config;
private ContextMenuStrip cmsContextMenu;
public AreaManager(RectangleRegionForm surface) public AreaManager(RectangleRegionForm surface)
{ {
this.surface = surface; this.surface = surface;
config = surface.Config;
CurrentShapeType = surface.Config.CurrentShapeType; //CurrentShapeType = config.CurrentShapeType;
ResizeManager = new ResizeManager(surface, this); ResizeManager = new ResizeManager(surface, this);
@ -158,17 +160,17 @@ public AreaManager(RectangleRegionForm surface)
surface.KeyDown += surface_KeyDown; surface.KeyDown += surface_KeyDown;
surface.KeyUp += surface_KeyUp; surface.KeyUp += surface_KeyUp;
CreateShapeMenu(); CreateContextMenu();
} }
private void CreateShapeMenu() private void CreateContextMenu()
{ {
cmsShapeMenu = new ContextMenuStrip(); cmsContextMenu = new ContextMenuStrip();
cmsShapeMenu.KeyDown += (sender, e) => cmsContextMenu.KeyDown += (sender, e) =>
{ {
if (e.KeyCode == Keys.Space) if (e.KeyCode == Keys.Space)
{ {
cmsShapeMenu.Close(); cmsContextMenu.Close();
} }
}; };
@ -181,10 +183,10 @@ private void CreateShapeMenu()
tsmiShapeType.RadioCheck(); tsmiShapeType.RadioCheck();
ChangeCurrentShapeType(shapeType); ChangeCurrentShapeType(shapeType);
}; };
cmsShapeMenu.Items.Add(tsmiShapeType); cmsContextMenu.Items.Add(tsmiShapeType);
} }
cmsShapeMenu.Items.Add(new ToolStripSeparator()); cmsContextMenu.Items.Add(new ToolStripSeparator());
ToolStripMenuItem tsmiChangeBorderColor = new ToolStripMenuItem("Border color..."); ToolStripMenuItem tsmiChangeBorderColor = new ToolStripMenuItem("Border color...");
tsmiChangeBorderColor.Click += (sender, e) => tsmiChangeBorderColor.Click += (sender, e) =>
@ -203,22 +205,15 @@ private void CreateShapeMenu()
surface.Resume(); surface.Resume();
}; };
tsmiChangeBorderColor.Image = ImageHelpers.CreateColorPickerIcon(BorderColor, new Rectangle(0, 0, 16, 16)); tsmiChangeBorderColor.Image = ImageHelpers.CreateColorPickerIcon(BorderColor, new Rectangle(0, 0, 16, 16));
cmsShapeMenu.Items.Add(tsmiChangeBorderColor); cmsContextMenu.Items.Add(tsmiChangeBorderColor);
ToolStripLabel tslChangeBorderSize = new ToolStripLabel("Border size:"); ToolStripLabeledNumericUpDown tslnudBorderSize = new ToolStripLabeledNumericUpDown();
cmsShapeMenu.Items.Add(tslChangeBorderSize); tslnudBorderSize.LabeledNumericUpDownControl.Text = "Border size:";
tslnudBorderSize.LabeledNumericUpDownControl.Minimum = 1;
ToolStripComboBox tscbBorderSize = new ToolStripComboBox(); tslnudBorderSize.LabeledNumericUpDownControl.Maximum = 20;
tscbBorderSize.DropDownStyle = ComboBoxStyle.DropDownList; tslnudBorderSize.LabeledNumericUpDownControl.Value = BorderSize;
tslnudBorderSize.LabeledNumericUpDownControl.ValueChanged = (sender, e) => BorderSize = (int)tslnudBorderSize.LabeledNumericUpDownControl.Value;
for (int i = 1; i <= 10; i++) cmsContextMenu.Items.Add(tslnudBorderSize);
{
tscbBorderSize.Items.Add(i);
}
tscbBorderSize.SelectedIndexChanged += (sender, e) => BorderSize = tscbBorderSize.SelectedIndex + 1;
tscbBorderSize.SelectedIndex = (BorderSize - 1).Between(0, tscbBorderSize.Items.Count - 1);
cmsShapeMenu.Items.Add(tscbBorderSize);
ToolStripMenuItem tsmiChangeFillColor = new ToolStripMenuItem("Fill color..."); ToolStripMenuItem tsmiChangeFillColor = new ToolStripMenuItem("Fill color...");
tsmiChangeFillColor.Click += (sender, e) => tsmiChangeFillColor.Click += (sender, e) =>
@ -237,16 +232,16 @@ private void CreateShapeMenu()
surface.Resume(); surface.Resume();
}; };
tsmiChangeFillColor.Image = ImageHelpers.CreateColorPickerIcon(FillColor, new Rectangle(0, 0, 16, 16)); tsmiChangeFillColor.Image = ImageHelpers.CreateColorPickerIcon(FillColor, new Rectangle(0, 0, 16, 16));
cmsShapeMenu.Items.Add(tsmiChangeFillColor); cmsContextMenu.Items.Add(tsmiChangeFillColor);
cmsShapeMenu.Items.Add(new ToolStripSeparator()); cmsContextMenu.Items.Add(new ToolStripSeparator());
ToolStripMenuItem tsmiFullscreenCapture = new ToolStripMenuItem("Capture fullscreen"); ToolStripMenuItem tsmiFullscreenCapture = new ToolStripMenuItem("Capture fullscreen");
tsmiFullscreenCapture.Click += (sender, e) => surface.Close(SurfaceResult.Fullscreen); tsmiFullscreenCapture.Click += (sender, e) => surface.Close(SurfaceResult.Fullscreen);
cmsShapeMenu.Items.Add(tsmiFullscreenCapture); cmsContextMenu.Items.Add(tsmiFullscreenCapture);
ToolStripMenuItem tsmiMonitorCapture = new ToolStripMenuItem("Capture monitor"); ToolStripMenuItem tsmiMonitorCapture = new ToolStripMenuItem("Capture monitor");
cmsShapeMenu.Items.Add(tsmiMonitorCapture); cmsContextMenu.Items.Add(tsmiMonitorCapture);
tsmiMonitorCapture.DropDownItems.Clear(); tsmiMonitorCapture.DropDownItems.Clear();
@ -266,13 +261,59 @@ private void CreateShapeMenu()
ToolStripMenuItem tsmiActiveMonitorCapture = new ToolStripMenuItem("Capture active monitor"); ToolStripMenuItem tsmiActiveMonitorCapture = new ToolStripMenuItem("Capture active monitor");
tsmiActiveMonitorCapture.Click += (sender, e) => surface.Close(SurfaceResult.ActiveMonitor); tsmiActiveMonitorCapture.Click += (sender, e) => surface.Close(SurfaceResult.ActiveMonitor);
cmsShapeMenu.Items.Add(tsmiActiveMonitorCapture); cmsContextMenu.Items.Add(tsmiActiveMonitorCapture);
cmsShapeMenu.Items.Add(new ToolStripSeparator()); cmsContextMenu.Items.Add(new ToolStripSeparator());
ToolStripMenuItem tsmiCloseMenu = new ToolStripMenuItem("Close"); ToolStripMenuItem tsmiOptions = new ToolStripMenuItem("Options");
tsmiCloseMenu.Click += (sender, e) => cmsShapeMenu.Close(); cmsContextMenu.Items.Add(tsmiOptions);
cmsShapeMenu.Items.Add(tsmiCloseMenu);
ToolStripMenuItem tsmiQuickCrop = new ToolStripMenuItem("Multi region mode");
tsmiQuickCrop.Checked = !config.QuickCrop;
tsmiQuickCrop.CheckOnClick = true;
tsmiQuickCrop.Click += (sender, e) => config.QuickCrop = !tsmiQuickCrop.Checked;
tsmiOptions.DropDownItems.Add(tsmiQuickCrop);
ToolStripMenuItem tsmiShowInfo = new ToolStripMenuItem("Position and size info");
tsmiShowInfo.Checked = config.ShowInfo;
tsmiShowInfo.CheckOnClick = true;
tsmiShowInfo.Click += (sender, e) => config.ShowInfo = tsmiShowInfo.Checked;
tsmiOptions.DropDownItems.Add(tsmiShowInfo);
ToolStripMenuItem tsmiShowMagnifier = new ToolStripMenuItem("Magnifier");
tsmiShowMagnifier.Checked = config.ShowMagnifier;
tsmiShowMagnifier.CheckOnClick = true;
tsmiShowMagnifier.Click += (sender, e) => config.ShowMagnifier = tsmiShowMagnifier.Checked;
tsmiOptions.DropDownItems.Add(tsmiShowMagnifier);
ToolStripLabeledNumericUpDown tslnudMagnifierPixelCount = new ToolStripLabeledNumericUpDown();
tslnudMagnifierPixelCount.LabeledNumericUpDownControl.Text = "Magnifier pixel count:";
tslnudMagnifierPixelCount.LabeledNumericUpDownControl.Minimum = 1;
tslnudMagnifierPixelCount.LabeledNumericUpDownControl.Maximum = 35;
tslnudMagnifierPixelCount.LabeledNumericUpDownControl.Increment = 2;
tslnudMagnifierPixelCount.LabeledNumericUpDownControl.Value = config.MagnifierPixelCount;
tslnudMagnifierPixelCount.LabeledNumericUpDownControl.ValueChanged = (sender, e) => config.MagnifierPixelCount = (int)tslnudMagnifierPixelCount.LabeledNumericUpDownControl.Value;
tsmiOptions.DropDownItems.Add(tslnudMagnifierPixelCount);
ToolStripLabeledNumericUpDown tslnudMagnifierPixelSize = new ToolStripLabeledNumericUpDown();
tslnudMagnifierPixelSize.LabeledNumericUpDownControl.Text = "Magnifier pixel size:";
tslnudMagnifierPixelSize.LabeledNumericUpDownControl.Minimum = 2;
tslnudMagnifierPixelSize.LabeledNumericUpDownControl.Maximum = 30;
tslnudMagnifierPixelSize.LabeledNumericUpDownControl.Value = config.MagnifierPixelSize;
tslnudMagnifierPixelSize.LabeledNumericUpDownControl.ValueChanged = (sender, e) => config.MagnifierPixelSize = (int)tslnudMagnifierPixelSize.LabeledNumericUpDownControl.Value;
tsmiOptions.DropDownItems.Add(tslnudMagnifierPixelSize);
ToolStripMenuItem tsmiShowCrosshair = new ToolStripMenuItem("Screen wide crosshair");
tsmiShowCrosshair.Checked = config.ShowCrosshair;
tsmiShowCrosshair.CheckOnClick = true;
tsmiShowCrosshair.Click += (sender, e) => config.ShowCrosshair = tsmiShowCrosshair.Checked;
tsmiOptions.DropDownItems.Add(tsmiShowCrosshair);
cmsContextMenu.Items.Add(new ToolStripSeparator());
ToolStripMenuItem tsmiCloseMenu = new ToolStripMenuItem("Close menu");
tsmiCloseMenu.Click += (sender, e) => cmsContextMenu.Close();
cmsContextMenu.Items.Add(tsmiCloseMenu);
} }
private void surface_KeyDown(object sender, KeyEventArgs e) private void surface_KeyDown(object sender, KeyEventArgs e)
@ -365,7 +406,7 @@ private void surface_KeyDown(object sender, KeyEventArgs e)
} }
break; break;
case Keys.Space: case Keys.Space:
cmsShapeMenu.Show(Cursor.Position.X, Cursor.Position.Y); cmsContextMenu.Show(Cursor.Position.X, Cursor.Position.Y);
break; break;
} }
} }
@ -373,7 +414,7 @@ private void surface_KeyDown(object sender, KeyEventArgs e)
private void ChangeCurrentShapeType(ShapeType shapeType) private void ChangeCurrentShapeType(ShapeType shapeType)
{ {
CurrentShapeType = shapeType; CurrentShapeType = shapeType;
surface.Config.CurrentShapeType = shapeType; //config.CurrentShapeType = shapeType;
DeselectArea(); DeselectArea();
} }
@ -462,10 +503,10 @@ private Point SnapPosition(Point posOnClick, Point posCurrent)
Rectangle currentRect = CaptureHelpers.CreateRectangle(posOnClick, posCurrent); Rectangle currentRect = CaptureHelpers.CreateRectangle(posOnClick, posCurrent);
Point newPosition = posCurrent; Point newPosition = posCurrent;
foreach (SnapSize size in surface.Config.SnapSizes) foreach (SnapSize size in config.SnapSizes)
{ {
if (currentRect.Width.IsBetween(size.Width - surface.Config.SnapDistance, size.Width + surface.Config.SnapDistance) || if (currentRect.Width.IsBetween(size.Width - config.SnapDistance, size.Width + config.SnapDistance) ||
currentRect.Height.IsBetween(size.Height - surface.Config.SnapDistance, size.Height + surface.Config.SnapDistance)) currentRect.Height.IsBetween(size.Height - config.SnapDistance, size.Height + config.SnapDistance))
{ {
newPosition = CaptureHelpers.CalculateNewPosition(posOnClick, posCurrent, size); newPosition = CaptureHelpers.CalculateNewPosition(posOnClick, posCurrent, size);
break; break;
@ -586,10 +627,10 @@ private void RegionSelection(Point location)
Rectangle rect; Rectangle rect;
if (surface.Config.IsFixedSize) if (config.IsFixedSize)
{ {
IsMoving = true; IsMoving = true;
rect = new Rectangle(new Point(location.X - surface.Config.FixedSize.Width / 2, location.Y - surface.Config.FixedSize.Height / 2), surface.Config.FixedSize); rect = new Rectangle(new Point(location.X - config.FixedSize.Width / 2, location.Y - config.FixedSize.Height / 2), config.FixedSize);
} }
else else
{ {
@ -613,7 +654,7 @@ private void EndRegionSelection()
RemoveCurrentArea(); RemoveCurrentArea();
CheckHover(); CheckHover();
} }
else if (surface.Config.QuickCrop && IsCurrentShapeTypeRegion) else if (config.QuickCrop && IsCurrentShapeTypeRegion)
{ {
surface.UpdateRegionPath(); surface.UpdateRegionPath();
surface.Close(SurfaceResult.Region); surface.Close(SurfaceResult.Region);
@ -628,7 +669,7 @@ private void EndRegionSelection()
{ {
AddRegionShape(CurrentHoverRectangle); AddRegionShape(CurrentHoverRectangle);
if (surface.Config.QuickCrop && IsCurrentShapeTypeRegion) if (config.QuickCrop && IsCurrentShapeTypeRegion)
{ {
surface.UpdateRegionPath(); surface.UpdateRegionPath();
surface.Close(SurfaceResult.Region); surface.Close(SurfaceResult.Region);
@ -716,7 +757,7 @@ public BaseShape CreateRegionShape(Rectangle rect)
private void SelectArea() private void SelectArea()
{ {
if (!CurrentRectangle.IsEmpty && !surface.Config.IsFixedSize) if (!CurrentRectangle.IsEmpty && !config.IsFixedSize)
{ {
ResizeManager.Show(); ResizeManager.Show();
} }