Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/absay/ShareX
Browse files Browse the repository at this point in the history
  • Loading branch information
Absay committed Jul 10, 2018
2 parents cdff9ed + d809258 commit 98a1b39
Show file tree
Hide file tree
Showing 84 changed files with 1,052 additions and 704 deletions.
1 change: 1 addition & 0 deletions Licenses/BlobEmoji_license.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2015-2017 Google Inc. & Arjen Nienhuis
Copyright 2017 - 2018 Blob Emoji

Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
65 changes: 21 additions & 44 deletions ShareX.HelpersLib/Controls/ToolStripRadioButtonMenuItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,48 +37,37 @@ public ToolStripRadioButtonMenuItem()
Initialize();
}

public ToolStripRadioButtonMenuItem(string text)
: base(text, null, (EventHandler)null)
public ToolStripRadioButtonMenuItem(string text) : base(text, null, (EventHandler)null)
{
Initialize();
}

public ToolStripRadioButtonMenuItem(Image image)
: base(null, image, (EventHandler)null)
public ToolStripRadioButtonMenuItem(Image image) : base(null, image, (EventHandler)null)
{
Initialize();
}

public ToolStripRadioButtonMenuItem(string text, Image image)
: base(text, image, (EventHandler)null)
public ToolStripRadioButtonMenuItem(string text, Image image) : base(text, image, (EventHandler)null)
{
Initialize();
}

public ToolStripRadioButtonMenuItem(string text, Image image,
EventHandler onClick)
: base(text, image, onClick)
public ToolStripRadioButtonMenuItem(string text, Image image, EventHandler onClick) : base(text, image, onClick)
{
Initialize();
}

public ToolStripRadioButtonMenuItem(string text, Image image,
EventHandler onClick, string name)
: base(text, image, onClick, name)
public ToolStripRadioButtonMenuItem(string text, Image image, EventHandler onClick, string name) : base(text, image, onClick, name)
{
Initialize();
}

public ToolStripRadioButtonMenuItem(string text, Image image,
params ToolStripItem[] dropDownItems)
: base(text, image, dropDownItems)
public ToolStripRadioButtonMenuItem(string text, Image image, params ToolStripItem[] dropDownItems) : base(text, image, dropDownItems)
{
Initialize();
}

public ToolStripRadioButtonMenuItem(string text, Image image,
EventHandler onClick, Keys shortcutKeys)
: base(text, image, onClick)
public ToolStripRadioButtonMenuItem(string text, Image image, EventHandler onClick, Keys shortcutKeys) : base(text, image, onClick)
{
Initialize();
ShortcutKeys = shortcutKeys;
Expand Down Expand Up @@ -160,32 +149,23 @@ protected override void OnPaint(PaintEventArgs e)
}

// Calculate the position at which to display the RadioButton.
Int32 offset = (ContentRectangle.Height -
RadioButtonRenderer.GetGlyphSize(
e.Graphics, buttonState).Height) / 2;
Point imageLocation = new Point(
ContentRectangle.Location.X + 4,
ContentRectangle.Location.Y + offset);
Int32 offset = (ContentRectangle.Height - RadioButtonRenderer.GetGlyphSize(e.Graphics, buttonState).Height) / 2;
Point imageLocation = new Point(ContentRectangle.Location.X + 4, ContentRectangle.Location.Y + offset);

// If the item is selected and the RadioButton paints with partial
// transparency, such as when theming is enabled, the check mark
// shows through the RadioButton image. In this case, paint a
// non-transparent background first to cover the check mark.
if (Checked && RadioButtonRenderer
.IsBackgroundPartiallyTransparent(buttonState))
if (Checked && RadioButtonRenderer.IsBackgroundPartiallyTransparent(buttonState))
{
Size glyphSize = RadioButtonRenderer
.GetGlyphSize(e.Graphics, buttonState);
Size glyphSize = RadioButtonRenderer.GetGlyphSize(e.Graphics, buttonState);
glyphSize.Height--;
glyphSize.Width--;
Rectangle backgroundRectangle =
new Rectangle(imageLocation, glyphSize);
e.Graphics.FillEllipse(
SystemBrushes.Control, backgroundRectangle);
Rectangle backgroundRectangle = new Rectangle(imageLocation, glyphSize);
e.Graphics.FillEllipse(SystemBrushes.Control, backgroundRectangle);
}

RadioButtonRenderer.DrawRadioButton(
e.Graphics, imageLocation, buttonState);
RadioButtonRenderer.DrawRadioButton(e.Graphics, imageLocation, buttonState);
}

private bool mouseHoverState;
Expand Down Expand Up @@ -230,13 +210,11 @@ public override bool Enabled
{
get
{
ToolStripMenuItem ownerMenuItem =
OwnerItem as ToolStripMenuItem;
ToolStripMenuItem ownerMenuItem = OwnerItem as ToolStripMenuItem;

// Use the base value in design mode to prevent the designer
// from setting the base value to the calculated value.
if (!DesignMode &&
ownerMenuItem != null && ownerMenuItem.CheckOnClick)
if (!DesignMode && ownerMenuItem != null && ownerMenuItem.CheckOnClick)
{
return base.Enabled && ownerMenuItem.Checked;
}
Expand All @@ -254,20 +232,19 @@ public override bool Enabled
// CheckedChanged event.
protected override void OnOwnerChanged(EventArgs e)
{
ToolStripMenuItem ownerMenuItem =
OwnerItem as ToolStripMenuItem;
ToolStripMenuItem ownerMenuItem = OwnerItem as ToolStripMenuItem;

if (ownerMenuItem != null && ownerMenuItem.CheckOnClick)
{
ownerMenuItem.CheckedChanged +=
OwnerMenuItem_CheckedChanged;
ownerMenuItem.CheckedChanged += OwnerMenuItem_CheckedChanged;
}

base.OnOwnerChanged(e);
}

// When the checked state of the parent item changes,
// repaint the item so that the new Enabled state is displayed.
private void OwnerMenuItem_CheckedChanged(
object sender, EventArgs e)
private void OwnerMenuItem_CheckedChanged(object sender, EventArgs e)
{
Invalidate();
}
Expand Down
1 change: 1 addition & 0 deletions ShareX.HelpersLib/Helpers/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static class Helpers
public static readonly Version OSVersion = Environment.OSVersion.Version;

private static Cursor[] _cursorList;

public static Cursor[] CursorList
{
get
Expand Down
118 changes: 67 additions & 51 deletions ShareX.HelpersLib/Helpers/ImageHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1711,96 +1711,111 @@ public static void DrawColorPickerIcon(Graphics g, Color color, Rectangle rect,
}
}

public static Rectangle FindAutoCropRectangle(Bitmap bmp, bool sameColorCrop = false)
public static Rectangle FindAutoCropRectangle(Bitmap bmp, bool sameColorCrop = false,
AnchorStyles sides = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right)
{
Rectangle source = new Rectangle(0, 0, bmp.Width, bmp.Height);

if (sides == AnchorStyles.None)
{
return source;
}

Rectangle crop = source;

using (UnsafeBitmap unsafeBitmap = new UnsafeBitmap(bmp, true, ImageLockMode.ReadOnly))
{
bool leave = false;

ColorBgra checkColor = unsafeBitmap.GetPixel(0, 0);
uint mask = checkColor.Alpha == 0 ? 0xFF000000 : 0xFFFFFFFF;
uint check = checkColor.Bgra & mask;

// Find X (Left to right)
for (int x = 0; x < bmp.Width && !leave; x++)
if (sides.HasFlag(AnchorStyles.Left))
{
for (int y = 0; y < bmp.Height; y++)
// Find X (Left to right)
for (int x = 0; x < bmp.Width && !leave; x++)
{
if (unsafeBitmap.GetPixel(x, y) != checkColor)
for (int y = 0; y < bmp.Height; y++)
{
crop.X = x;
leave = true;
break;
if ((unsafeBitmap.GetPixel(x, y).Bgra & mask) != check)
{
crop.X = x;
crop.Width -= x;
leave = true;
break;
}
}
}
}

// If all pixels same color
if (!leave)
{
return crop;
}

leave = false;
// If all pixels same color
if (!leave)
{
return crop;
}

if (!sameColorCrop)
{
checkColor = unsafeBitmap.GetPixel(0, 0);
leave = false;
}

// Find Y (Top to bottom)
for (int y = 0; y < bmp.Height && !leave; y++)
if (sides.HasFlag(AnchorStyles.Top))
{
for (int x = 0; x < bmp.Width; x++)
// Find Y (Top to bottom)
for (int y = 0; y < bmp.Height && !leave; y++)
{
if (unsafeBitmap.GetPixel(x, y) != checkColor)
for (int x = 0; x < bmp.Width; x++)
{
crop.Y = y;
leave = true;
break;
if ((unsafeBitmap.GetPixel(x, y).Bgra & mask) != check)
{
crop.Y = y;
crop.Height -= y;
leave = true;
break;
}
}
}
}

leave = false;
leave = false;
}

if (!sameColorCrop)
{
checkColor = unsafeBitmap.GetPixel(bmp.Width - 1, 0);
checkColor = unsafeBitmap.GetPixel(bmp.Width - 1, bmp.Height - 1);
mask = checkColor.Alpha == 0 ? 0xFF000000 : 0xFFFFFFFF;
check = checkColor.Bgra & mask;
}

// Find Width (Right to left)
for (int x = bmp.Width - 1; x >= 0 && !leave; x--)
if (sides.HasFlag(AnchorStyles.Right))
{
for (int y = 0; y < bmp.Height; y++)
// Find Width (Right to left)
for (int x = bmp.Width - 1; x >= 0 && !leave; x--)
{
if (unsafeBitmap.GetPixel(x, y) != checkColor)
for (int y = 0; y < bmp.Height; y++)
{
crop.Width = x - crop.X + 1;
leave = true;
break;
if ((unsafeBitmap.GetPixel(x, y).Bgra & mask) != check)
{
crop.Width = x - crop.X + 1;
leave = true;
break;
}
}
}
}

leave = false;

if (!sameColorCrop)
{
checkColor = unsafeBitmap.GetPixel(0, bmp.Height - 1);
leave = false;
}

// Find Height (Bottom to top)
for (int y = bmp.Height - 1; y >= 0 && !leave; y--)
if (sides.HasFlag(AnchorStyles.Bottom))
{
for (int x = 0; x < bmp.Width; x++)
// Find Height (Bottom to top)
for (int y = bmp.Height - 1; y >= 0 && !leave; y--)
{
if (unsafeBitmap.GetPixel(x, y) != checkColor)
for (int x = 0; x < bmp.Width; x++)
{
crop.Height = y - crop.Y + 1;
leave = true;
break;
if ((unsafeBitmap.GetPixel(x, y).Bgra & mask) != check)
{
crop.Height = y - crop.Y + 1;
leave = true;
break;
}
}
}
}
Expand All @@ -1809,10 +1824,11 @@ public static Rectangle FindAutoCropRectangle(Bitmap bmp, bool sameColorCrop = f
return crop;
}

public static Bitmap AutoCropImage(Bitmap bmp, bool sameColorCrop = false)
public static Bitmap AutoCropImage(Bitmap bmp, bool sameColorCrop = false,
AnchorStyles sides = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right)
{
Rectangle source = new Rectangle(0, 0, bmp.Width, bmp.Height);
Rectangle rect = FindAutoCropRectangle(bmp, sameColorCrop);
Rectangle rect = FindAutoCropRectangle(bmp, sameColorCrop, sides);

if (source != rect)
{
Expand Down
34 changes: 15 additions & 19 deletions ShareX.HelpersLib/Helpers/URLHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,39 @@ public static void OpenURL(string url)
}
}

private static string Encode(string text, string unreservedCharacters)
public static string URLEncode(string text, bool isPath = false)
{
StringBuilder result = new StringBuilder();

if (!string.IsNullOrEmpty(text))
{
foreach (char c in text)
string unreservedCharacters;

if (isPath)
{
unreservedCharacters = Helpers.URLPathCharacters;
}
else
{
if (unreservedCharacters.Contains(c))
unreservedCharacters = Helpers.URLCharacters;
}

foreach (char c in Encoding.UTF8.GetBytes(text))
{
if (unreservedCharacters.IndexOf(c) != -1)
{
result.Append(c);
}
else
{
byte[] bytes = Encoding.UTF8.GetBytes(c.ToString());

foreach (byte b in bytes)
{
result.AppendFormat(CultureInfo.InvariantCulture, "%{0:X2}", b);
}
result.AppendFormat(CultureInfo.InvariantCulture, "%{0:X2}", (int)c);
}
}
}

return result.ToString();
}

public static string URLEncode(string text)
{
return Encode(text, Helpers.URLCharacters);
}

public static string URLPathEncode(string text)
{
return Encode(text, Helpers.URLPathCharacters);
}

public static string HtmlEncode(string text)
{
char[] chars = HttpUtility.HtmlEncode(text).ToCharArray();
Expand Down
Loading

0 comments on commit 98a1b39

Please sign in to comment.