In context menu updated selected control options properly

This commit is contained in:
Jaex 2016-05-21 00:09:09 +03:00
parent fa2c5c73c3
commit de14669306
9 changed files with 145 additions and 26 deletions

View file

@ -99,6 +99,10 @@ public virtual void UpdateShapeConfig()
{
}
public virtual void ApplyShapeConfig()
{
}
public virtual void OnShapeCreated()
{
}

View file

@ -36,8 +36,8 @@ namespace ShareX.ScreenCaptureLib
public abstract class BaseDrawingShape : BaseShape
{
public Color BorderColor { get; set; }
public Color FillColor { get; set; }
public int BorderSize { get; set; }
public Color FillColor { get; set; }
public override void UpdateShapeConfig()
{
@ -46,6 +46,13 @@ public override void UpdateShapeConfig()
FillColor = AnnotationOptions.FillColor;
}
public override void ApplyShapeConfig()
{
AnnotationOptions.BorderColor = BorderColor;
AnnotationOptions.BorderSize = BorderSize;
AnnotationOptions.FillColor = FillColor;
}
public virtual void Draw(Graphics g)
{
using (Pen borderPen = new Pen(Color.Black))

View file

@ -45,6 +45,12 @@ public override void UpdateShapeConfig()
Radius = AnnotationOptions.RoundedRectangleRadius;
}
public override void ApplyShapeConfig()
{
base.ApplyShapeConfig();
AnnotationOptions.RoundedRectangleRadius = (int)Radius;
}
public override void Draw(Graphics g)
{
Brush brush = null;

View file

@ -41,16 +41,21 @@ public class TextDrawingShape : BaseDrawingShape
public string Text { get; set; }
public TextDrawingOptions Options { get; set; }
public Color TextBorderColor { get; set; }
public int TextBorderSize { get; set; }
public Color TextFillColor { get; set; }
public override void UpdateShapeConfig()
{
Options = AnnotationOptions.TextOptions.Copy();
TextBorderColor = AnnotationOptions.TextBorderColor;
TextBorderSize = AnnotationOptions.TextBorderSize;
TextFillColor = AnnotationOptions.TextFillColor;
BorderColor = AnnotationOptions.TextBorderColor;
BorderSize = AnnotationOptions.TextBorderSize;
FillColor = AnnotationOptions.TextFillColor;
}
public override void ApplyShapeConfig()
{
AnnotationOptions.TextOptions = Options;
AnnotationOptions.TextBorderColor = BorderColor;
AnnotationOptions.TextBorderSize = BorderSize;
AnnotationOptions.TextFillColor = FillColor;
}
public override void Draw(Graphics g)
@ -72,19 +77,19 @@ public override void DrawFinal(Graphics g, Bitmap bmp)
}
}
if (TextFillColor.A > 0)
if (FillColor.A > 0)
{
using (Brush brush = new SolidBrush(TextFillColor))
using (Brush brush = new SolidBrush(FillColor))
{
g.FillRectangle(brush, Rectangle);
}
}
if (TextBorderSize > 0 && TextBorderColor.A > 0)
if (BorderSize > 0 && BorderColor.A > 0)
{
Rectangle rect = Rectangle.Offset(TextBorderSize - 1);
Rectangle rect = Rectangle.Offset(BorderSize - 1);
using (Pen pen = new Pen(TextBorderColor, TextBorderSize) { Alignment = PenAlignment.Inset })
using (Pen pen = new Pen(BorderColor, BorderSize) { Alignment = PenAlignment.Inset })
{
g.DrawRectangleProper(pen, rect);
}
@ -99,7 +104,7 @@ private void UpdateText()
{
inputBox.ShowDialog();
Text = inputBox.InputText;
AnnotationOptions.TextOptions = Options;
ApplyShapeConfig();
}
Manager.ResumeForm();

View file

@ -45,6 +45,11 @@ public override void UpdateShapeConfig()
BlurRadius = AnnotationOptions.BlurRadius;
}
public override void ApplyShapeConfig()
{
AnnotationOptions.BlurRadius = BlurRadius;
}
public override void Draw(Graphics g)
{
if (BlurRadius > 1)

View file

@ -45,6 +45,11 @@ public override void UpdateShapeConfig()
HighlightColor = AnnotationOptions.HighlightColor;
}
public override void ApplyShapeConfig()
{
AnnotationOptions.HighlightColor = HighlightColor;
}
public override void Draw(Graphics g)
{
using (Brush brush = new SolidBrush(Color.FromArgb(100, HighlightColor)))

View file

@ -45,6 +45,11 @@ public override void UpdateShapeConfig()
PixelSize = AnnotationOptions.PixelateSize;
}
public override void ApplyShapeConfig()
{
AnnotationOptions.PixelateSize = PixelSize;
}
public override void Draw(Graphics g)
{
if (PixelSize > 1)

View file

@ -44,6 +44,11 @@ public override void UpdateShapeConfig()
Radius = AnnotationOptions.RoundedRectangleRadius;
}
public override void ApplyShapeConfig()
{
AnnotationOptions.RoundedRectangleRadius = (int)Radius;
}
public override void AddShapePath(GraphicsPath gp, Rectangle rect)
{
gp.AddRoundedRectangle(rect, Radius);

View file

@ -48,6 +48,12 @@ public BaseShape CurrentShape
private set
{
currentShape = value;
if (currentShape != null)
{
currentShape.ApplyShapeConfig();
}
OnCurrentShapeChanged(currentShape);
}
}
@ -205,6 +211,8 @@ private void CreateContextMenu()
{
cmsContextMenu = new ContextMenuStrip(form.components);
#region Main
ToolStripMenuItem tsmiCancelCapture = new ToolStripMenuItem("Cancel capture");
tsmiCancelCapture.Image = Resources.prohibition;
tsmiCancelCapture.Click += (sender, e) => form.Close(RegionResult.Close);
@ -215,6 +223,10 @@ private void CreateContextMenu()
tsmiCloseMenu.Click += (sender, e) => cmsContextMenu.Close();
cmsContextMenu.Items.Add(tsmiCloseMenu);
#endregion Main
#region Selected object
ToolStripSeparator tssObjectOptions = new ToolStripSeparator();
cmsContextMenu.Items.Add(tssObjectOptions);
@ -228,6 +240,10 @@ private void CreateContextMenu()
tsmiDeleteAll.Click += (sender, e) => ClearAll();
cmsContextMenu.Items.Add(tsmiDeleteAll);
#endregion Selected object
#region Tools
cmsContextMenu.Items.Add(new ToolStripSeparator());
foreach (ShapeType shapeType in Helpers.GetEnums<ShapeType>())
@ -288,6 +304,10 @@ private void CreateContextMenu()
cmsContextMenu.Items.Add(tsmiShapeType);
}
#endregion Tools
#region Shape options
ToolStripSeparator tssShapeOptions = new ToolStripSeparator();
cmsContextMenu.Items.Add(tssShapeOptions);
@ -309,14 +329,12 @@ private void CreateContextMenu()
ResumeForm();
};
tsmiBorderColor.Image = ImageHelpers.CreateColorPickerIcon(AnnotationOptions.BorderColor, new Rectangle(0, 0, 16, 16));
cmsContextMenu.Items.Add(tsmiBorderColor);
ToolStripLabeledNumericUpDown tslnudBorderSize = new ToolStripLabeledNumericUpDown();
tslnudBorderSize.LabeledNumericUpDownControl.Text = "Border size:";
tslnudBorderSize.LabeledNumericUpDownControl.Minimum = 0;
tslnudBorderSize.LabeledNumericUpDownControl.Maximum = 20;
tslnudBorderSize.LabeledNumericUpDownControl.Value = AnnotationOptions.BorderSize;
tslnudBorderSize.LabeledNumericUpDownControl.ValueChanged = (sender, e) =>
{
AnnotationOptions.BorderSize = (int)tslnudBorderSize.LabeledNumericUpDownControl.Value;
@ -342,7 +360,6 @@ private void CreateContextMenu()
ResumeForm();
};
tsmiFillColor.Image = ImageHelpers.CreateColorPickerIcon(AnnotationOptions.FillColor, new Rectangle(0, 0, 16, 16));
cmsContextMenu.Items.Add(tsmiFillColor);
ToolStripLabeledNumericUpDown tslnudRoundedRectangleRadius = new ToolStripLabeledNumericUpDown();
@ -350,7 +367,6 @@ private void CreateContextMenu()
tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Minimum = 0;
tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Maximum = 150;
tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Increment = 3;
tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Value = AnnotationOptions.RoundedRectangleRadius;
tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.ValueChanged = (sender, e) =>
{
AnnotationOptions.RoundedRectangleRadius = (int)tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Value;
@ -362,7 +378,6 @@ private void CreateContextMenu()
tslnudBlurRadius.LabeledNumericUpDownControl.Text = "Blur radius:";
tslnudBlurRadius.LabeledNumericUpDownControl.Minimum = 2;
tslnudBlurRadius.LabeledNumericUpDownControl.Maximum = 100;
tslnudBlurRadius.LabeledNumericUpDownControl.Value = AnnotationOptions.BlurRadius;
tslnudBlurRadius.LabeledNumericUpDownControl.ValueChanged = (sender, e) =>
{
AnnotationOptions.BlurRadius = (int)tslnudBlurRadius.LabeledNumericUpDownControl.Value;
@ -374,7 +389,6 @@ private void CreateContextMenu()
tslnudPixelateSize.LabeledNumericUpDownControl.Text = "Pixel size:";
tslnudPixelateSize.LabeledNumericUpDownControl.Minimum = 2;
tslnudPixelateSize.LabeledNumericUpDownControl.Maximum = 100;
tslnudPixelateSize.LabeledNumericUpDownControl.Value = AnnotationOptions.RoundedRectangleRadius;
tslnudPixelateSize.LabeledNumericUpDownControl.ValueChanged = (sender, e) =>
{
AnnotationOptions.PixelateSize = (int)tslnudPixelateSize.LabeledNumericUpDownControl.Value;
@ -400,9 +414,12 @@ private void CreateContextMenu()
ResumeForm();
};
tsmiHighlightColor.Image = ImageHelpers.CreateColorPickerIcon(AnnotationOptions.HighlightColor, new Rectangle(0, 0, 16, 16));
cmsContextMenu.Items.Add(tsmiHighlightColor);
#endregion Shape options
#region Capture
cmsContextMenu.Items.Add(new ToolStripSeparator());
ToolStripMenuItem tsmiFullscreenCapture = new ToolStripMenuItem("Capture fullscreen");
@ -437,6 +454,10 @@ private void CreateContextMenu()
tsmiMonitorCapture.DropDownItems.Add(tsmi);
}
#endregion Capture
#region Options
cmsContextMenu.Items.Add(new ToolStripSeparator());
ToolStripMenuItem tsmiOptions = new ToolStripMenuItem("Options");
@ -496,11 +517,7 @@ private void CreateContextMenu()
tsmiShowFPS.Click += (sender, e) => Config.ShowFPS = tsmiShowFPS.Checked;
tsmiOptions.DropDownItems.Add(tsmiShowFPS);
CurrentShapeChanged += shape =>
{
tssObjectOptions.Visible = tsmiDeleteAll.Visible = Shapes.Count > 0;
tsmiDeleteSelected.Visible = shape != null;
};
#endregion Options
CurrentShapeTypeChanged += shapeType =>
{
@ -512,6 +529,61 @@ private void CreateContextMenu()
break;
}
}
};
cmsContextMenu.Opening += (sender, e) =>
{
tssObjectOptions.Visible = tsmiDeleteAll.Visible = Shapes.Count > 0;
tsmiDeleteSelected.Visible = CurrentShape != null;
ShapeType shapeType = CurrentShapeType;
Color borderColor;
if (shapeType == ShapeType.DrawingText)
{
borderColor = AnnotationOptions.TextBorderColor;
}
else
{
borderColor = AnnotationOptions.BorderColor;
}
tsmiBorderColor.Image = ImageHelpers.CreateColorPickerIcon(borderColor, new Rectangle(0, 0, 16, 16));
int borderSize;
if (shapeType == ShapeType.DrawingText)
{
borderSize = AnnotationOptions.TextBorderSize;
}
else
{
borderSize = AnnotationOptions.BorderSize;
}
tslnudBorderSize.LabeledNumericUpDownControl.Value = borderSize;
Color fillColor;
if (shapeType == ShapeType.DrawingText)
{
fillColor = AnnotationOptions.TextFillColor;
}
else
{
fillColor = AnnotationOptions.FillColor;
}
tsmiFillColor.Image = ImageHelpers.CreateColorPickerIcon(fillColor, new Rectangle(0, 0, 16, 16));
tslnudRoundedRectangleRadius.LabeledNumericUpDownControl.Value = AnnotationOptions.RoundedRectangleRadius;
tslnudBlurRadius.LabeledNumericUpDownControl.Value = AnnotationOptions.BlurRadius;
tslnudPixelateSize.LabeledNumericUpDownControl.Value = AnnotationOptions.PixelateSize;
tsmiHighlightColor.Image = ImageHelpers.CreateColorPickerIcon(AnnotationOptions.HighlightColor, new Rectangle(0, 0, 16, 16));
switch (shapeType)
{
@ -1005,7 +1077,12 @@ public BaseShape CreateShape(Rectangle rect)
private void UpdateCurrentShape()
{
CurrentShape.UpdateShapeConfig();
BaseShape shape = CurrentShape;
if (shape != null)
{
shape.UpdateShapeConfig();
}
}
public Image RenderOutputImage(Image img)