From 4be6799f4af5d376d3d237681dac1018ddecfe38 Mon Sep 17 00:00:00 2001 From: RKrom Date: Mon, 17 Dec 2012 16:20:45 +0000 Subject: [PATCH] Fixed some drawing defaults for Bug #3588716 git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2391 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Drawing/ArrowContainer.cs | 47 +++++++++++----------- Greenshot/Drawing/EllipseContainer.cs | 14 +++---- Greenshot/Drawing/FilterContainer.cs | 52 ++++++++++++------------- Greenshot/Drawing/LineContainer.cs | 45 ++++++++++----------- Greenshot/Drawing/RectangleContainer.cs | 15 ++++--- Greenshot/Drawing/RoundedRectangle.cs | 3 ++ Greenshot/Drawing/TextContainer.cs | 7 ++-- 7 files changed, 87 insertions(+), 96 deletions(-) diff --git a/Greenshot/Drawing/ArrowContainer.cs b/Greenshot/Drawing/ArrowContainer.cs index c4e1a53b0..11d139a40 100644 --- a/Greenshot/Drawing/ArrowContainer.cs +++ b/Greenshot/Drawing/ArrowContainer.cs @@ -52,36 +52,33 @@ namespace Greenshot.Drawing { graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.CompositingQuality = CompositingQuality.HighQuality; - graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; + graphics.PixelOffsetMode = PixelOffsetMode.None; Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR); ArrowHeadCombination heads = (ArrowHeadCombination)GetFieldValue(FieldType.ARROWHEADS); - if (shadow) { - //draw shadow first - int basealpha = 100; - int alpha = basealpha; - int steps = 5; - int currentStep = 1; - while ( currentStep <= steps ) { - using (Pen shadowCapPen = new Pen(Color.FromArgb(alpha, 100, 100, 100))) { - shadowCapPen.Width = lineThickness; - SetArrowHeads(heads, shadowCapPen); + if (lineThickness > 0) { + if (shadow) { + //draw shadow first + int basealpha = 100; + int alpha = basealpha; + int steps = 5; + int currentStep = 1; + while (currentStep <= steps) { + using (Pen shadowCapPen = new Pen(Color.FromArgb(alpha, 100, 100, 100), lineThickness)) { + SetArrowHeads(heads, shadowCapPen); - graphics.DrawLine(shadowCapPen, - this.Left + currentStep, - this.Top + currentStep, - this.Left + currentStep + this.Width, - this.Top + currentStep + this.Height); - - currentStep++; - alpha = alpha - (basealpha / steps); + graphics.DrawLine(shadowCapPen, + this.Left + currentStep, + this.Top + currentStep, + this.Left + currentStep + this.Width, + this.Top + currentStep + this.Height); + + currentStep++; + alpha = alpha - (basealpha / steps); + } } + } - - } - using (Pen pen = new Pen(lineColor)) { - pen.Width = lineThickness; - - if ( pen.Width > 0 ) { + using (Pen pen = new Pen(lineColor, lineThickness)) { SetArrowHeads(heads, pen); graphics.DrawLine(pen, this.Left, this.Top, this.Left + this.Width, this.Top + this.Height); } diff --git a/Greenshot/Drawing/EllipseContainer.cs b/Greenshot/Drawing/EllipseContainer.cs index b8ab67c06..cc5acce97 100644 --- a/Greenshot/Drawing/EllipseContainer.cs +++ b/Greenshot/Drawing/EllipseContainer.cs @@ -43,7 +43,7 @@ namespace Greenshot.Drawing { graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.CompositingQuality = CompositingQuality.HighQuality; - graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; + graphics.PixelOffsetMode = PixelOffsetMode.None; int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS); Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR); @@ -66,18 +66,15 @@ namespace Greenshot.Drawing { } } } - //draw the original shape Rectangle rect = GuiRectangle.GetGuiRectangle(this.Left, this.Top, this.Width, this.Height); - if (!Color.Transparent.Equals(fillColor)) { + if (Colors.IsVisible(fillColor)) { using (Brush brush = new SolidBrush(fillColor)) { graphics.FillEllipse(brush, rect); } } - - using (Pen pen = new Pen(lineColor)) { - pen.Width = lineThickness; - if (pen.Width > 0) { + if (lineVisible) { + using (Pen pen = new Pen(lineColor, lineThickness)) { graphics.DrawEllipse(pen, rect); } } @@ -104,8 +101,7 @@ namespace Greenshot.Drawing { // check the rest of the lines if (lineThickness > 0) { - using (Pen pen = new Pen(Color.White)) { - pen.Width = lineThickness; + using (Pen pen = new Pen(Color.White, lineThickness)) { using (GraphicsPath path = new GraphicsPath()) { path.AddEllipse(rect); return path.IsOutlineVisible(x, y, pen); diff --git a/Greenshot/Drawing/FilterContainer.cs b/Greenshot/Drawing/FilterContainer.cs index 448d12228..d0a69b694 100644 --- a/Greenshot/Drawing/FilterContainer.cs +++ b/Greenshot/Drawing/FilterContainer.cs @@ -23,6 +23,7 @@ using System.Drawing; using Greenshot.Drawing.Fields; using Greenshot.Helpers; using Greenshot.Plugin.Drawing; +using System.Drawing.Drawing2D; namespace Greenshot.Drawing { /// @@ -44,41 +45,38 @@ namespace Greenshot.Drawing { AddField(GetType(), FieldType.SHADOW, false); } - public override void Draw(Graphics g, RenderMode rm) { + public override void Draw(Graphics graphics, RenderMode rm) { int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS); Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR); bool shadow = GetFieldValueAsBool(FieldType.SHADOW); bool lineVisible = (lineThickness > 0 && Colors.IsVisible(lineColor)); - if (shadow && lineVisible) { + if (lineVisible) { + graphics.SmoothingMode = SmoothingMode.HighSpeed; + graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; + graphics.CompositingQuality = CompositingQuality.HighQuality; + graphics.PixelOffsetMode = PixelOffsetMode.None; //draw shadow first - int basealpha = 100; - int alpha = basealpha; - int steps = 5; - int currentStep = lineVisible ? 1 : 0; - while (currentStep <= steps) { - using (Pen shadowPen = new Pen(Color.FromArgb(alpha, 100, 100, 100))) { - shadowPen.Width = lineVisible ? lineThickness : 1; - Rectangle shadowRect = GuiRectangle.GetGuiRectangle( - this.Left + currentStep, - this.Top + currentStep, - this.Width, - this.Height); - g.DrawRectangle(shadowPen, shadowRect); - currentStep++; - alpha = alpha - (basealpha / steps); + if (shadow) { + int basealpha = 100; + int alpha = basealpha; + int steps = 5; + int currentStep = lineVisible ? 1 : 0; + while (currentStep <= steps) { + using (Pen shadowPen = new Pen(Color.FromArgb(alpha, 100, 100, 100), lineThickness)) { + Rectangle shadowRect = GuiRectangle.GetGuiRectangle(this.Left + currentStep, this.Top + currentStep, this.Width, this.Height); + graphics.DrawRectangle(shadowPen, shadowRect); + currentStep++; + alpha = alpha - (basealpha / steps); + } + } + } + Rectangle rect = GuiRectangle.GetGuiRectangle(this.Left, this.Top, this.Width, this.Height); + if (lineThickness > 0) { + using (Pen pen = new Pen(lineColor, lineThickness)) { + graphics.DrawRectangle(pen, rect); } } } - - Rectangle rect = GuiRectangle.GetGuiRectangle(this.Left, this.Top, this.Width, this.Height); - - using (Pen pen = new Pen(lineColor)) { - pen.Width = lineThickness; - if(pen.Width > 0) { - g.DrawRectangle(pen, rect); - } - } - } } } diff --git a/Greenshot/Drawing/LineContainer.cs b/Greenshot/Drawing/LineContainer.cs index 8f1aaf55b..1ffb4c8d4 100644 --- a/Greenshot/Drawing/LineContainer.cs +++ b/Greenshot/Drawing/LineContainer.cs @@ -57,39 +57,36 @@ namespace Greenshot.Drawing { public override void Draw(Graphics graphics, RenderMode rm) { graphics.SmoothingMode = SmoothingMode.HighQuality; - graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; + graphics.InterpolationMode = InterpolationMode.HighQualityBilinear; graphics.CompositingQuality = CompositingQuality.HighQuality; - graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; + graphics.PixelOffsetMode = PixelOffsetMode.None; int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS); Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR); bool shadow = GetFieldValueAsBool(FieldType.SHADOW); - if ( shadow && lineThickness > 0 ) { - //draw shadow first - int basealpha = 100; - int alpha = basealpha; - int steps = 5; - int currentStep = 1; - while (currentStep <= steps) { - using (Pen shadowCapPen = new Pen(Color.FromArgb(alpha, 100, 100, 100))) { - shadowCapPen.Width = lineThickness; - - graphics.DrawLine(shadowCapPen, - this.Left + currentStep, - this.Top + currentStep, - this.Left + currentStep + this.Width, - this.Top + currentStep + this.Height); - - currentStep++; - alpha = alpha - (basealpha / steps); + if (lineThickness > 0) { + if (shadow) { + //draw shadow first + int basealpha = 100; + int alpha = basealpha; + int steps = 5; + int currentStep = 1; + while (currentStep <= steps) { + using (Pen shadowCapPen = new Pen(Color.FromArgb(alpha, 100, 100, 100), lineThickness)) { + graphics.DrawLine(shadowCapPen, + this.Left + currentStep, + this.Top + currentStep, + this.Left + currentStep + this.Width, + this.Top + currentStep + this.Height); + + currentStep++; + alpha = alpha - (basealpha / steps); + } } } - } - using (Pen pen = new Pen(lineColor)) { - pen.Width = lineThickness; - if(pen.Width > 0) { + using (Pen pen = new Pen(lineColor, lineThickness)) { graphics.DrawLine(pen, this.Left, this.Top, this.Left + this.Width, this.Top + this.Height); } } diff --git a/Greenshot/Drawing/RectangleContainer.cs b/Greenshot/Drawing/RectangleContainer.cs index 457c3e14f..05e03cbd1 100644 --- a/Greenshot/Drawing/RectangleContainer.cs +++ b/Greenshot/Drawing/RectangleContainer.cs @@ -74,16 +74,16 @@ namespace Greenshot.Drawing { } Rectangle rect = GuiRectangle.GetGuiRectangle(this.Left, this.Top, this.Width, this.Height); - - if (!Color.Transparent.Equals(fillColor)) { + + if (Colors.IsVisible(fillColor)) { using (Brush brush = new SolidBrush(fillColor)) { graphics.FillRectangle(brush, rect); } } - - if (lineThickness > 0) { - using (Pen pen = new Pen(lineColor)) { - pen.Width = lineThickness; + + graphics.SmoothingMode = SmoothingMode.HighSpeed; + if (lineVisible) { + using (Pen pen = new Pen(lineColor, lineThickness)) { graphics.DrawRectangle(pen, rect); } } @@ -103,8 +103,7 @@ namespace Greenshot.Drawing { // check the rest of the lines if (lineThickness > 0) { - using (Pen pen = new Pen(Color.White)) { - pen.Width = lineThickness; + using (Pen pen = new Pen(Color.White, lineThickness)) { using (GraphicsPath path = new GraphicsPath()) { path.AddRectangle(rect); return path.IsOutlineVisible(x, y, pen); diff --git a/Greenshot/Drawing/RoundedRectangle.cs b/Greenshot/Drawing/RoundedRectangle.cs index 171a90d64..8806fd198 100644 --- a/Greenshot/Drawing/RoundedRectangle.cs +++ b/Greenshot/Drawing/RoundedRectangle.cs @@ -23,6 +23,9 @@ using System.Drawing; using System.Drawing.Drawing2D; namespace Greenshot.Drawing { + /// + /// TODO: currently this is only used in the capture form, we might move this code directly to there! + /// public abstract class RoundedRectangle { public enum RectangleCorners { None = 0, TopLeft = 1, TopRight = 2, diff --git a/Greenshot/Drawing/TextContainer.cs b/Greenshot/Drawing/TextContainer.cs index d4098a20d..869df1e7c 100644 --- a/Greenshot/Drawing/TextContainer.cs +++ b/Greenshot/Drawing/TextContainer.cs @@ -272,7 +272,7 @@ namespace Greenshot.Drawing { graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.CompositingQuality = CompositingQuality.HighQuality; - graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; + graphics.PixelOffsetMode = PixelOffsetMode.None; graphics.TextRenderingHint = TextRenderingHint.SystemDefault; Rectangle rect = GuiRectangle.GetGuiRectangle(this.Left, this.Top, this.Width, this.Height); @@ -308,12 +308,13 @@ namespace Greenshot.Drawing { } } } - Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR); Rectangle fontRect = rect; if (lineThickness > 0) { - fontRect.Inflate(-textOffset,-textOffset); + graphics.SmoothingMode = SmoothingMode.HighSpeed; + fontRect.Inflate(-textOffset, -textOffset); } + graphics.SmoothingMode = SmoothingMode.HighQuality; using (Brush fontBrush = new SolidBrush(lineColor)) { graphics.DrawString(text, font, fontBrush, fontRect); }