diff --git a/Greenshot/Forms/TornEdgeSettingsForm.Designer.cs b/Greenshot/Forms/TornEdgeSettingsForm.Designer.cs index 94fa80b11..66146755f 100644 --- a/Greenshot/Forms/TornEdgeSettingsForm.Designer.cs +++ b/Greenshot/Forms/TornEdgeSettingsForm.Designer.cs @@ -47,7 +47,7 @@ namespace Greenshot.Forms { this.offsetX = new System.Windows.Forms.NumericUpDown(); this.label3 = new System.Windows.Forms.Label(); this.offsetY = new System.Windows.Forms.NumericUpDown(); - this.trackBar1 = new System.Windows.Forms.TrackBar(); + this.shadowDarkness = new System.Windows.Forms.TrackBar(); this.buttonOK = new GreenshotPlugin.Controls.GreenshotButton(); this.buttonCancel = new GreenshotPlugin.Controls.GreenshotButton(); this.labelDarkness = new GreenshotPlugin.Controls.GreenshotLabel(); @@ -63,10 +63,11 @@ namespace Greenshot.Forms { this.right = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.bottom = new GreenshotPlugin.Controls.GreenshotCheckBox(); this.left = new GreenshotPlugin.Controls.GreenshotCheckBox(); + this.shadowCheckbox = new GreenshotPlugin.Controls.GreenshotCheckBox(); ((System.ComponentModel.ISupportInitialize)(this.thickness)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.offsetX)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.offsetY)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.shadowDarkness)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.toothsize)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.horizontaltoothrange)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.verticaltoothrange)).BeginInit(); @@ -74,7 +75,7 @@ namespace Greenshot.Forms { // // thickness // - this.thickness.Location = new System.Drawing.Point(173, 7); + this.thickness.Location = new System.Drawing.Point(173, 35); this.thickness.Maximum = new decimal(new int[] { 20, 0, @@ -96,7 +97,7 @@ namespace Greenshot.Forms { // // offsetX // - this.offsetX.Location = new System.Drawing.Point(102, 33); + this.offsetX.Location = new System.Drawing.Point(102, 61); this.offsetX.Maximum = new decimal(new int[] { 20, 0, @@ -119,7 +120,7 @@ namespace Greenshot.Forms { // label3 // this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(153, 35); + this.label3.Location = new System.Drawing.Point(153, 63); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(14, 13); this.label3.TabIndex = 5; @@ -127,7 +128,7 @@ namespace Greenshot.Forms { // // offsetY // - this.offsetY.Location = new System.Drawing.Point(173, 33); + this.offsetY.Location = new System.Drawing.Point(173, 61); this.offsetY.Maximum = new decimal(new int[] { 20, 0, @@ -147,20 +148,20 @@ namespace Greenshot.Forms { 0, -2147483648}); // - // trackBar1 + // shadowDarkness // - this.trackBar1.Location = new System.Drawing.Point(102, 59); - this.trackBar1.Maximum = 40; - this.trackBar1.Minimum = 1; - this.trackBar1.Name = "trackBar1"; - this.trackBar1.Size = new System.Drawing.Size(116, 45); - this.trackBar1.TabIndex = 7; - this.trackBar1.Value = 40; + this.shadowDarkness.Location = new System.Drawing.Point(102, 87); + this.shadowDarkness.Maximum = 40; + this.shadowDarkness.Minimum = 1; + this.shadowDarkness.Name = "shadowDarkness"; + this.shadowDarkness.Size = new System.Drawing.Size(116, 45); + this.shadowDarkness.TabIndex = 7; + this.shadowDarkness.Value = 40; // // buttonOK // this.buttonOK.LanguageKey = "OK"; - this.buttonOK.Location = new System.Drawing.Point(62, 292); + this.buttonOK.Location = new System.Drawing.Point(62, 320); this.buttonOK.Name = "buttonOK"; this.buttonOK.Size = new System.Drawing.Size(75, 23); this.buttonOK.TabIndex = 11; @@ -172,7 +173,7 @@ namespace Greenshot.Forms { // this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.buttonCancel.LanguageKey = "CANCEL"; - this.buttonCancel.Location = new System.Drawing.Point(143, 292); + this.buttonCancel.Location = new System.Drawing.Point(143, 320); this.buttonCancel.Name = "buttonCancel"; this.buttonCancel.Size = new System.Drawing.Size(75, 23); this.buttonCancel.TabIndex = 12; @@ -183,7 +184,7 @@ namespace Greenshot.Forms { // this.labelDarkness.AutoSize = true; this.labelDarkness.LanguageKey = "editor_dropshadow_darkness"; - this.labelDarkness.Location = new System.Drawing.Point(12, 69); + this.labelDarkness.Location = new System.Drawing.Point(12, 97); this.labelDarkness.Name = "labelDarkness"; this.labelDarkness.Size = new System.Drawing.Size(92, 13); this.labelDarkness.TabIndex = 13; @@ -193,7 +194,7 @@ namespace Greenshot.Forms { // this.labelOffset.AutoSize = true; this.labelOffset.LanguageKey = "editor_dropshadow_offset"; - this.labelOffset.Location = new System.Drawing.Point(12, 35); + this.labelOffset.Location = new System.Drawing.Point(12, 63); this.labelOffset.Name = "labelOffset"; this.labelOffset.Size = new System.Drawing.Size(75, 13); this.labelOffset.TabIndex = 14; @@ -203,7 +204,7 @@ namespace Greenshot.Forms { // this.labelThickness.AutoSize = true; this.labelThickness.LanguageKey = "editor_dropshadow_thickness"; - this.labelThickness.Location = new System.Drawing.Point(12, 9); + this.labelThickness.Location = new System.Drawing.Point(12, 37); this.labelThickness.Name = "labelThickness"; this.labelThickness.Size = new System.Drawing.Size(94, 13); this.labelThickness.TabIndex = 15; @@ -211,7 +212,7 @@ namespace Greenshot.Forms { // // toothsize // - this.toothsize.Location = new System.Drawing.Point(173, 110); + this.toothsize.Location = new System.Drawing.Point(173, 138); this.toothsize.Maximum = new decimal(new int[] { 40, 0, @@ -235,7 +236,7 @@ namespace Greenshot.Forms { // this.label_toothsize.AutoSize = true; this.label_toothsize.LanguageKey = "editor_tornedge_toothsize"; - this.label_toothsize.Location = new System.Drawing.Point(12, 112); + this.label_toothsize.Location = new System.Drawing.Point(12, 140); this.label_toothsize.Name = "label_toothsize"; this.label_toothsize.Size = new System.Drawing.Size(56, 13); this.label_toothsize.TabIndex = 17; @@ -245,7 +246,7 @@ namespace Greenshot.Forms { // this.label_horizontaltoothrange.AutoSize = true; this.label_horizontaltoothrange.LanguageKey = "editor_tornedge_horizontaltoothrange"; - this.label_horizontaltoothrange.Location = new System.Drawing.Point(12, 138); + this.label_horizontaltoothrange.Location = new System.Drawing.Point(12, 166); this.label_horizontaltoothrange.Name = "label_horizontaltoothrange"; this.label_horizontaltoothrange.Size = new System.Drawing.Size(111, 13); this.label_horizontaltoothrange.TabIndex = 19; @@ -253,7 +254,7 @@ namespace Greenshot.Forms { // // horizontaltoothrange // - this.horizontaltoothrange.Location = new System.Drawing.Point(173, 136); + this.horizontaltoothrange.Location = new System.Drawing.Point(173, 164); this.horizontaltoothrange.Maximum = new decimal(new int[] { 40, 0, @@ -277,7 +278,7 @@ namespace Greenshot.Forms { // this.labelVerticaltoothrange.AutoSize = true; this.labelVerticaltoothrange.LanguageKey = "editor_tornedge_verticaltoothrange"; - this.labelVerticaltoothrange.Location = new System.Drawing.Point(12, 164); + this.labelVerticaltoothrange.Location = new System.Drawing.Point(12, 192); this.labelVerticaltoothrange.Name = "labelVerticaltoothrange"; this.labelVerticaltoothrange.Size = new System.Drawing.Size(99, 13); this.labelVerticaltoothrange.TabIndex = 21; @@ -285,7 +286,7 @@ namespace Greenshot.Forms { // // verticaltoothrange // - this.verticaltoothrange.Location = new System.Drawing.Point(173, 162); + this.verticaltoothrange.Location = new System.Drawing.Point(173, 190); this.verticaltoothrange.Maximum = new decimal(new int[] { 40, 0, @@ -308,7 +309,7 @@ namespace Greenshot.Forms { // top // this.top.AutoSize = true; - this.top.Location = new System.Drawing.Point(15, 194); + this.top.Location = new System.Drawing.Point(15, 222); this.top.Name = "top"; this.top.Size = new System.Drawing.Size(88, 17); this.top.TabIndex = 22; @@ -318,7 +319,7 @@ namespace Greenshot.Forms { // right // this.right.AutoSize = true; - this.right.Location = new System.Drawing.Point(15, 217); + this.right.Location = new System.Drawing.Point(15, 245); this.right.Name = "right"; this.right.Size = new System.Drawing.Size(93, 17); this.right.TabIndex = 23; @@ -328,7 +329,7 @@ namespace Greenshot.Forms { // bottom // this.bottom.AutoSize = true; - this.bottom.Location = new System.Drawing.Point(15, 240); + this.bottom.Location = new System.Drawing.Point(15, 268); this.bottom.Name = "bottom"; this.bottom.Size = new System.Drawing.Size(105, 17); this.bottom.TabIndex = 24; @@ -338,21 +339,33 @@ namespace Greenshot.Forms { // left // this.left.AutoSize = true; - this.left.Location = new System.Drawing.Point(15, 263); + this.left.Location = new System.Drawing.Point(15, 291); this.left.Name = "left"; this.left.Size = new System.Drawing.Size(87, 17); this.left.TabIndex = 25; this.left.Text = "Tear left side"; this.left.UseVisualStyleBackColor = true; // + // shadowCheckbox + // + this.shadowCheckbox.AutoSize = true; + this.shadowCheckbox.Location = new System.Drawing.Point(12, 12); + this.shadowCheckbox.Name = "shadowCheckbox"; + this.shadowCheckbox.Size = new System.Drawing.Size(110, 17); + this.shadowCheckbox.TabIndex = 26; + this.shadowCheckbox.Text = "Generate shadow"; + this.shadowCheckbox.UseVisualStyleBackColor = true; + this.shadowCheckbox.CheckedChanged += new System.EventHandler(this.shadowCheckbox_CheckedChanged); + // // TornEdgeSettingsForm // this.AcceptButton = this.buttonOK; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.buttonCancel; - this.ClientSize = new System.Drawing.Size(230, 324); + this.ClientSize = new System.Drawing.Size(230, 353); this.ControlBox = false; + this.Controls.Add(this.shadowCheckbox); this.Controls.Add(this.left); this.Controls.Add(this.bottom); this.Controls.Add(this.right); @@ -368,7 +381,7 @@ namespace Greenshot.Forms { this.Controls.Add(this.labelDarkness); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonOK); - this.Controls.Add(this.trackBar1); + this.Controls.Add(this.shadowDarkness); this.Controls.Add(this.offsetY); this.Controls.Add(this.label3); this.Controls.Add(this.offsetX); @@ -383,7 +396,7 @@ namespace Greenshot.Forms { ((System.ComponentModel.ISupportInitialize)(this.thickness)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.offsetX)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.offsetY)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.shadowDarkness)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.toothsize)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.horizontaltoothrange)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.verticaltoothrange)).EndInit(); @@ -398,7 +411,7 @@ namespace Greenshot.Forms { private System.Windows.Forms.NumericUpDown offsetX; private System.Windows.Forms.Label label3; private System.Windows.Forms.NumericUpDown offsetY; - private System.Windows.Forms.TrackBar trackBar1; + private System.Windows.Forms.TrackBar shadowDarkness; private GreenshotPlugin.Controls.GreenshotButton buttonOK; private GreenshotPlugin.Controls.GreenshotButton buttonCancel; private GreenshotPlugin.Controls.GreenshotLabel labelDarkness; @@ -414,5 +427,6 @@ namespace Greenshot.Forms { private GreenshotPlugin.Controls.GreenshotCheckBox right; private GreenshotPlugin.Controls.GreenshotCheckBox bottom; private GreenshotPlugin.Controls.GreenshotCheckBox left; + private GreenshotPlugin.Controls.GreenshotCheckBox shadowCheckbox; } } \ No newline at end of file diff --git a/Greenshot/Forms/TornEdgeSettingsForm.cs b/Greenshot/Forms/TornEdgeSettingsForm.cs index e70b1fb29..d2a7aab72 100644 --- a/Greenshot/Forms/TornEdgeSettingsForm.cs +++ b/Greenshot/Forms/TornEdgeSettingsForm.cs @@ -31,7 +31,8 @@ namespace Greenshot.Forms { this.effect = effect; InitializeComponent(); this.Icon = GreenshotResources.getGreenshotIcon(); - trackBar1.Value = (int)(effect.Darkness * 40); + shadowCheckbox.Checked = effect.GenerateShadow; + shadowDarkness.Value = (int)(effect.Darkness * 40); offsetX.Value = effect.ShadowOffset.X; offsetY.Value = effect.ShadowOffset.Y; toothsize.Value = effect.ToothHeight; @@ -44,14 +45,22 @@ namespace Greenshot.Forms { } private void buttonOK_Click(object sender, EventArgs e) { - effect.Darkness = (float)trackBar1.Value / (float)40; + effect.Darkness = (float)shadowDarkness.Value / (float)40; effect.ShadowOffset = new Point((int)offsetX.Value, (int)offsetY.Value); effect.ShadowSize = (int)thickness.Value; effect.ToothHeight = (int)toothsize.Value; effect.VerticalToothRange = (int)verticaltoothrange.Value; effect.HorizontalToothRange = (int)horizontaltoothrange.Value; effect.Edges = new bool[] { top.Checked, right.Checked, bottom.Checked, left.Checked }; + effect.GenerateShadow = shadowCheckbox.Checked; DialogResult = DialogResult.OK; } + + private void shadowCheckbox_CheckedChanged(object sender, EventArgs e) { + thickness.Enabled = shadowCheckbox.Checked; + offsetX.Enabled = shadowCheckbox.Checked; + offsetY.Enabled = shadowCheckbox.Checked; + shadowDarkness.Enabled = shadowCheckbox.Checked; + } } } diff --git a/GreenshotPlugin/Core/Effects.cs b/GreenshotPlugin/Core/Effects.cs index 0a5ea4c57..298d52f0e 100644 --- a/GreenshotPlugin/Core/Effects.cs +++ b/GreenshotPlugin/Core/Effects.cs @@ -70,6 +70,7 @@ namespace Greenshot.Core { HorizontalToothRange = 20; VerticalToothRange = 20; Edges = new bool[] {true, true, true, true}; + GenerateShadow = true; } public int ToothHeight { get; @@ -87,10 +88,19 @@ namespace Greenshot.Core { get; set; } + public bool GenerateShadow { + get; + set; + } + public override Image Apply(Image sourceImage, Matrix matrix) { - using (Image tmpTornImage = ImageHelper.CreateTornEdge(sourceImage, ToothHeight, HorizontalToothRange, VerticalToothRange, Edges)) { - return ImageHelper.CreateShadow(tmpTornImage, Darkness, ShadowSize, ShadowOffset, matrix, PixelFormat.Format32bppArgb); + Image tmpTornImage = ImageHelper.CreateTornEdge(sourceImage, ToothHeight, HorizontalToothRange, VerticalToothRange, Edges); + if (GenerateShadow) { + using (tmpTornImage) { + return ImageHelper.CreateShadow(tmpTornImage, Darkness, ShadowSize, ShadowOffset, matrix, PixelFormat.Format32bppArgb); + } } + return tmpTornImage; } } diff --git a/GreenshotPlugin/Core/ImageHelper.cs b/GreenshotPlugin/Core/ImageHelper.cs index 33bb9eca9..b35556974 100644 --- a/GreenshotPlugin/Core/ImageHelper.cs +++ b/GreenshotPlugin/Core/ImageHelper.cs @@ -441,6 +441,18 @@ namespace GreenshotPlugin.Core { return currentImage; } + /// + /// Helper method for the tornedge + /// + /// Path to draw to + /// Points for the lines to draw + private static void DrawLines(GraphicsPath path, List points) { + path.AddLine(points[0], points[1]); + for (int i = 0; i < points.Count-1; i++) { + path.AddLine(points[i], points[i+1]); + } + } + /// /// Make the picture look like it's torn /// @@ -454,69 +466,72 @@ namespace GreenshotPlugin.Core { Image returnImage = CreateEmpty(sourceImage.Width, sourceImage.Height, PixelFormat.Format32bppArgb, Color.Empty, sourceImage.HorizontalResolution, sourceImage.VerticalResolution); using (GraphicsPath path = new GraphicsPath()) { Random random = new Random(); - int horizontalRegions = sourceImage.Width / horizontalToothRange; - int verticalRegions = sourceImage.Height / verticalToothRange; + int horizontalRegions = (int)Math.Round((float)sourceImage.Width / horizontalToothRange); + int verticalRegions = (int)Math.Round((float)sourceImage.Height / verticalToothRange); + + Point topLeft = new Point(0, 0); + Point topRight = new Point(sourceImage.Width, 0); + Point bottomLeft = new Point(0, sourceImage.Height); + Point bottomRight = new Point(sourceImage.Width, sourceImage.Height); + + List points = new List(); - // Start - Point previousEndingPoint = new Point(0,0); - Point newEndingPoint; if (edges[0]) { - previousEndingPoint = new Point(horizontalToothRange, random.Next(1, toothHeight)); - // Top - for (int i = 0; i < horizontalRegions; i++) { - int x = previousEndingPoint.X + horizontalToothRange; - int y = random.Next(1, toothHeight); - newEndingPoint = new Point(x, y); - path.AddLine(previousEndingPoint, newEndingPoint); - previousEndingPoint = newEndingPoint; + // calculate starting point only if the left edge is torn + if (!edges[3]) { + points.Add(topLeft); + } else { + points.Add(new Point(random.Next(1, toothHeight), random.Next(1, toothHeight))); } + for (int i = 1; i < horizontalRegions-1; i++) { + points.Add(new Point(i*horizontalToothRange, random.Next(1, toothHeight))); + } + points.Add(new Point(sourceImage.Width - random.Next(1, toothHeight), random.Next(1, toothHeight))); } else { - newEndingPoint = new Point(sourceImage.Width, 0); - path.AddLine(previousEndingPoint, newEndingPoint); - previousEndingPoint = newEndingPoint; + // set start & endpoint to be the default "whole-line" + points.Add(topLeft); + points.Add(topRight); } + // Right if (edges[1]) { - // Right - for (int i = 0; i < verticalRegions; i++) { - int x = sourceImage.Width - random.Next(1, toothHeight); - int y = previousEndingPoint.Y + verticalToothRange; - newEndingPoint = new Point(x, y); - path.AddLine(previousEndingPoint, newEndingPoint); - previousEndingPoint = newEndingPoint; + for (int i = 1; i < verticalRegions-1; i++) { + points.Add(new Point(sourceImage.Width - random.Next(1, toothHeight), i * verticalToothRange)); } + points.Add(new Point(sourceImage.Width - random.Next(1, toothHeight), sourceImage.Height - random.Next(1, toothHeight))); } else { - newEndingPoint = new Point(sourceImage.Width, sourceImage.Height); - path.AddLine(previousEndingPoint, newEndingPoint); - previousEndingPoint = newEndingPoint; + // correct previous ending point + points[points.Count - 1] = topRight; + // set endpoint to be the default "whole-line" + points.Add(bottomRight); } + // Bottom if (edges[2]) { - // Bottom - for (int i = 0; i < horizontalRegions; i++) { - int x = previousEndingPoint.X - horizontalToothRange; - int y = sourceImage.Height - random.Next(1, toothHeight); - newEndingPoint = new Point(x, y); - path.AddLine(previousEndingPoint, newEndingPoint); - previousEndingPoint = newEndingPoint; + for (int i = 1; i < horizontalRegions -1; i++) { + points.Add(new Point(sourceImage.Width - i * horizontalToothRange, sourceImage.Height - random.Next(1, toothHeight))); } + points.Add(new Point(random.Next(1, toothHeight), sourceImage.Height - random.Next(1, toothHeight))); } else { - newEndingPoint = new Point(0, sourceImage.Height); - path.AddLine(previousEndingPoint, newEndingPoint); - previousEndingPoint = newEndingPoint; + // correct previous ending point + points[points.Count - 1] = bottomRight; + // set endpoint to be the default "whole-line" + points.Add(bottomLeft); } + // Left if (edges[3]) { - // Left - for (int i = 0; i < verticalRegions; i++) { - int x = random.Next(1, toothHeight); - int y = previousEndingPoint.Y - verticalToothRange; - newEndingPoint = new Point(x, y); - path.AddLine(previousEndingPoint, newEndingPoint); - previousEndingPoint = newEndingPoint; + // One fewer as the end point is the starting point + for (int i = 1; i < verticalRegions -1; i++) { + points.Add(new Point(random.Next(1, toothHeight), points[points.Count - 1].Y - verticalToothRange)); } } else { - newEndingPoint = new Point(0, 0); - path.AddLine(previousEndingPoint, newEndingPoint); - //previousEndingPoint = newEndingPoint; + // correct previous ending point + points[points.Count - 1] = bottomLeft; + // set endpoint to be the default "whole-line" + points.Add(topLeft); } + // End point always is the starting point + points[points.Count - 1] = points[0]; + + DrawLines(path, points); path.CloseFigure();