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
This commit is contained in:
RKrom 2012-12-17 16:20:45 +00:00
parent 263bfbf158
commit 4be6799f4a
7 changed files with 87 additions and 96 deletions

View file

@ -52,36 +52,33 @@ namespace Greenshot.Drawing {
graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.None;
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR); Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
ArrowHeadCombination heads = (ArrowHeadCombination)GetFieldValue(FieldType.ARROWHEADS); ArrowHeadCombination heads = (ArrowHeadCombination)GetFieldValue(FieldType.ARROWHEADS);
if (shadow) { if (lineThickness > 0) {
//draw shadow first if (shadow) {
int basealpha = 100; //draw shadow first
int alpha = basealpha; int basealpha = 100;
int steps = 5; int alpha = basealpha;
int currentStep = 1; int steps = 5;
while ( currentStep <= steps ) { int currentStep = 1;
using (Pen shadowCapPen = new Pen(Color.FromArgb(alpha, 100, 100, 100))) { while (currentStep <= steps) {
shadowCapPen.Width = lineThickness; using (Pen shadowCapPen = new Pen(Color.FromArgb(alpha, 100, 100, 100), lineThickness)) {
SetArrowHeads(heads, shadowCapPen); SetArrowHeads(heads, shadowCapPen);
graphics.DrawLine(shadowCapPen, graphics.DrawLine(shadowCapPen,
this.Left + currentStep, this.Left + currentStep,
this.Top + currentStep, this.Top + currentStep,
this.Left + currentStep + this.Width, this.Left + currentStep + this.Width,
this.Top + currentStep + this.Height); this.Top + currentStep + this.Height);
currentStep++; currentStep++;
alpha = alpha - (basealpha / steps); alpha = alpha - (basealpha / steps);
}
} }
} }
using (Pen pen = new Pen(lineColor, lineThickness)) {
}
using (Pen pen = new Pen(lineColor)) {
pen.Width = lineThickness;
if ( pen.Width > 0 ) {
SetArrowHeads(heads, pen); SetArrowHeads(heads, pen);
graphics.DrawLine(pen, this.Left, this.Top, this.Left + this.Width, this.Top + this.Height); graphics.DrawLine(pen, this.Left, this.Top, this.Left + this.Width, this.Top + this.Height);
} }

View file

@ -43,7 +43,7 @@ namespace Greenshot.Drawing {
graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.None;
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS); int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR); Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
@ -66,18 +66,15 @@ namespace Greenshot.Drawing {
} }
} }
} }
//draw the original shape //draw the original shape
Rectangle rect = GuiRectangle.GetGuiRectangle(this.Left, this.Top, this.Width, this.Height); 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)) { using (Brush brush = new SolidBrush(fillColor)) {
graphics.FillEllipse(brush, rect); graphics.FillEllipse(brush, rect);
} }
} }
if (lineVisible) {
using (Pen pen = new Pen(lineColor)) { using (Pen pen = new Pen(lineColor, lineThickness)) {
pen.Width = lineThickness;
if (pen.Width > 0) {
graphics.DrawEllipse(pen, rect); graphics.DrawEllipse(pen, rect);
} }
} }
@ -104,8 +101,7 @@ namespace Greenshot.Drawing {
// check the rest of the lines // check the rest of the lines
if (lineThickness > 0) { if (lineThickness > 0) {
using (Pen pen = new Pen(Color.White)) { using (Pen pen = new Pen(Color.White, lineThickness)) {
pen.Width = lineThickness;
using (GraphicsPath path = new GraphicsPath()) { using (GraphicsPath path = new GraphicsPath()) {
path.AddEllipse(rect); path.AddEllipse(rect);
return path.IsOutlineVisible(x, y, pen); return path.IsOutlineVisible(x, y, pen);

View file

@ -23,6 +23,7 @@ using System.Drawing;
using Greenshot.Drawing.Fields; using Greenshot.Drawing.Fields;
using Greenshot.Helpers; using Greenshot.Helpers;
using Greenshot.Plugin.Drawing; using Greenshot.Plugin.Drawing;
using System.Drawing.Drawing2D;
namespace Greenshot.Drawing { namespace Greenshot.Drawing {
/// <summary> /// <summary>
@ -44,41 +45,38 @@ namespace Greenshot.Drawing {
AddField(GetType(), FieldType.SHADOW, false); 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); int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR); Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
bool shadow = GetFieldValueAsBool(FieldType.SHADOW); bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
bool lineVisible = (lineThickness > 0 && Colors.IsVisible(lineColor)); 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 //draw shadow first
int basealpha = 100; if (shadow) {
int alpha = basealpha; int basealpha = 100;
int steps = 5; int alpha = basealpha;
int currentStep = lineVisible ? 1 : 0; int steps = 5;
while (currentStep <= steps) { int currentStep = lineVisible ? 1 : 0;
using (Pen shadowPen = new Pen(Color.FromArgb(alpha, 100, 100, 100))) { while (currentStep <= steps) {
shadowPen.Width = lineVisible ? lineThickness : 1; using (Pen shadowPen = new Pen(Color.FromArgb(alpha, 100, 100, 100), lineThickness)) {
Rectangle shadowRect = GuiRectangle.GetGuiRectangle( Rectangle shadowRect = GuiRectangle.GetGuiRectangle(this.Left + currentStep, this.Top + currentStep, this.Width, this.Height);
this.Left + currentStep, graphics.DrawRectangle(shadowPen, shadowRect);
this.Top + currentStep, currentStep++;
this.Width, alpha = alpha - (basealpha / steps);
this.Height); }
g.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);
}
}
} }
} }
} }

View file

@ -57,39 +57,36 @@ namespace Greenshot.Drawing {
public override void Draw(Graphics graphics, RenderMode rm) { public override void Draw(Graphics graphics, RenderMode rm) {
graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.None;
int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS); int lineThickness = GetFieldValueAsInt(FieldType.LINE_THICKNESS);
Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR); Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
bool shadow = GetFieldValueAsBool(FieldType.SHADOW); bool shadow = GetFieldValueAsBool(FieldType.SHADOW);
if ( shadow && lineThickness > 0 ) { if (lineThickness > 0) {
//draw shadow first if (shadow) {
int basealpha = 100; //draw shadow first
int alpha = basealpha; int basealpha = 100;
int steps = 5; int alpha = basealpha;
int currentStep = 1; int steps = 5;
while (currentStep <= steps) { int currentStep = 1;
using (Pen shadowCapPen = new Pen(Color.FromArgb(alpha, 100, 100, 100))) { while (currentStep <= steps) {
shadowCapPen.Width = lineThickness; using (Pen shadowCapPen = new Pen(Color.FromArgb(alpha, 100, 100, 100), lineThickness)) {
graphics.DrawLine(shadowCapPen,
graphics.DrawLine(shadowCapPen, this.Left + currentStep,
this.Left + currentStep, this.Top + currentStep,
this.Top + currentStep, this.Left + currentStep + this.Width,
this.Left + currentStep + this.Width, this.Top + currentStep + this.Height);
this.Top + currentStep + this.Height);
currentStep++;
currentStep++; alpha = alpha - (basealpha / steps);
alpha = alpha - (basealpha / steps); }
} }
} }
}
using (Pen pen = new Pen(lineColor)) { using (Pen pen = new Pen(lineColor, lineThickness)) {
pen.Width = lineThickness;
if(pen.Width > 0) {
graphics.DrawLine(pen, this.Left, this.Top, this.Left + this.Width, this.Top + this.Height); graphics.DrawLine(pen, this.Left, this.Top, this.Left + this.Width, this.Top + this.Height);
} }
} }

View file

@ -74,16 +74,16 @@ namespace Greenshot.Drawing {
} }
Rectangle rect = GuiRectangle.GetGuiRectangle(this.Left, this.Top, this.Width, this.Height); 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)) { using (Brush brush = new SolidBrush(fillColor)) {
graphics.FillRectangle(brush, rect); graphics.FillRectangle(brush, rect);
} }
} }
if (lineThickness > 0) { graphics.SmoothingMode = SmoothingMode.HighSpeed;
using (Pen pen = new Pen(lineColor)) { if (lineVisible) {
pen.Width = lineThickness; using (Pen pen = new Pen(lineColor, lineThickness)) {
graphics.DrawRectangle(pen, rect); graphics.DrawRectangle(pen, rect);
} }
} }
@ -103,8 +103,7 @@ namespace Greenshot.Drawing {
// check the rest of the lines // check the rest of the lines
if (lineThickness > 0) { if (lineThickness > 0) {
using (Pen pen = new Pen(Color.White)) { using (Pen pen = new Pen(Color.White, lineThickness)) {
pen.Width = lineThickness;
using (GraphicsPath path = new GraphicsPath()) { using (GraphicsPath path = new GraphicsPath()) {
path.AddRectangle(rect); path.AddRectangle(rect);
return path.IsOutlineVisible(x, y, pen); return path.IsOutlineVisible(x, y, pen);

View file

@ -23,6 +23,9 @@ using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
namespace Greenshot.Drawing { namespace Greenshot.Drawing {
/// <summary>
/// TODO: currently this is only used in the capture form, we might move this code directly to there!
/// </summary>
public abstract class RoundedRectangle { public abstract class RoundedRectangle {
public enum RectangleCorners { public enum RectangleCorners {
None = 0, TopLeft = 1, TopRight = 2, None = 0, TopLeft = 1, TopRight = 2,

View file

@ -272,7 +272,7 @@ namespace Greenshot.Drawing {
graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.None;
graphics.TextRenderingHint = TextRenderingHint.SystemDefault; graphics.TextRenderingHint = TextRenderingHint.SystemDefault;
Rectangle rect = GuiRectangle.GetGuiRectangle(this.Left, this.Top, this.Width, this.Height); 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); Color lineColor = GetFieldValueAsColor(FieldType.LINE_COLOR);
Rectangle fontRect = rect; Rectangle fontRect = rect;
if (lineThickness > 0) { 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)) { using (Brush fontBrush = new SolidBrush(lineColor)) {
graphics.DrawString(text, font, fontBrush, fontRect); graphics.DrawString(text, font, fontBrush, fontRect);
} }