Checker changes

This commit is contained in:
Jaex 2019-06-02 22:45:15 +03:00
parent 64a733328b
commit 0755698b08
5 changed files with 55 additions and 41 deletions

View file

@ -205,7 +205,8 @@ public void UpdateCheckers(bool forceUpdate = false)
{
if (pbMain.BackgroundImage != null) pbMain.BackgroundImage.Dispose();
pbMain.BackgroundImage = ImageHelpers.CreateCheckerPattern(10, 10, ShareXResources.CheckerColor1, ShareXResources.CheckerColor2);
pbMain.BackgroundImage = ImageHelpers.CreateCheckerPattern(ShareXResources.CheckerSize, ShareXResources.CheckerSize,
ShareXResources.CheckerColor1, ShareXResources.CheckerColor2);
}
}
else

View file

@ -701,12 +701,12 @@ public static Image DrawCheckers(Image img)
return DrawCheckers(img, 10, SystemColors.ControlLight, SystemColors.ControlLightLight);
}
public static Image DrawCheckers(Image img, int size, Color color1, Color color2)
public static Image DrawCheckers(Image img, int checkerSize, Color checkerColor1, Color checkerColor2)
{
Bitmap bmp = img.CreateEmptyBitmap();
using (Graphics g = Graphics.FromImage(bmp))
using (Image checker = CreateCheckerPattern(size, size, color1, color2))
using (Image checker = CreateCheckerPattern(checkerSize, checkerSize, checkerColor1, checkerColor2))
using (Brush checkerBrush = new TextureBrush(checker, WrapMode.Tile))
using (img)
{
@ -720,15 +720,15 @@ public static Image DrawCheckers(Image img, int size, Color color1, Color color2
public static Image DrawCheckers(int width, int height)
{
return DrawCheckers(width, height, SystemColors.ControlLight, SystemColors.ControlLightLight);
return DrawCheckers(width, height, 10, SystemColors.ControlLight, SystemColors.ControlLightLight);
}
public static Image DrawCheckers(int width, int height, Color color1, Color color2)
public static Image DrawCheckers(int width, int height, int checkerSize, Color checkerColor1, Color checkerColor2)
{
Bitmap bmp = new Bitmap(width, height);
using (Graphics g = Graphics.FromImage(bmp))
using (Image checker = CreateCheckerPattern(10, 10, color1, color2))
using (Image checker = CreateCheckerPattern(checkerSize, checkerSize, checkerColor1, checkerColor2))
using (Brush checkerBrush = new TextureBrush(checker, WrapMode.Tile))
{
g.FillRectangle(checkerBrush, new Rectangle(0, 0, bmp.Width, bmp.Height));
@ -747,13 +747,13 @@ public static Image CreateCheckerPattern(int width, int height)
return CreateCheckerPattern(width, height, SystemColors.ControlLight, SystemColors.ControlLightLight);
}
public static Image CreateCheckerPattern(int width, int height, Color color1, Color color2)
public static Image CreateCheckerPattern(int width, int height, Color checkerColor1, Color checkerColor2)
{
Bitmap bmp = new Bitmap(width * 2, height * 2);
using (Graphics g = Graphics.FromImage(bmp))
using (Brush brush1 = new SolidBrush(color1))
using (Brush brush2 = new SolidBrush(color2))
using (Brush brush1 = new SolidBrush(checkerColor1))
using (Brush brush2 = new SolidBrush(checkerColor2))
{
g.FillRectangle(brush1, 0, 0, width, height);
g.FillRectangle(brush1, width, height, width, height);

View file

@ -53,7 +53,8 @@ public static string UserAgent
public static Color DarkTextColor { get; } = Color.FromArgb(235, 235, 235);
public static Color DarkBorderColor { get; } = Color.FromArgb(28, 32, 38);
public static Color CheckerColor1 => UseDarkTheme ? Color.FromArgb(153, 153, 153) : SystemColors.ControlLight;
public static Color CheckerColor2 => UseDarkTheme ? Color.FromArgb(102, 102, 102) : SystemColors.ControlLightLight;
public static int CheckerSize { get; } = 15;
public static Color CheckerColor1 => UseDarkTheme ? Color.FromArgb(60, 60, 60) : SystemColors.ControlLightLight;
public static Color CheckerColor2 => UseDarkTheme ? Color.FromArgb(50, 50, 50) : SystemColors.ControlLight;
}
}

View file

@ -324,7 +324,8 @@ internal void InitBackground(Image canvas, bool centerCanvas = true)
{
Rectangle sourceRect = new Rectangle(0, 0, Canvas.Width, Canvas.Height);
using (Image checkers = ImageHelpers.DrawCheckers(Canvas.Width, Canvas.Height, ShareXResources.CheckerColor1, ShareXResources.CheckerColor2))
using (Image checkers = ImageHelpers.DrawCheckers(Canvas.Width, Canvas.Height, ShareXResources.CheckerSize,
ShareXResources.CheckerColor1, ShareXResources.CheckerColor2))
{
g.DrawImage(checkers, sourceRect);
}

View file

@ -188,36 +188,11 @@ public void UpdateThumbnail(Image image = null)
pbThumbnail.Cursor = pThumbnail.Cursor = Cursors.Hand;
}
if (image != null)
{
pbThumbnail.Image = ImageHelpers.ResizeImage(image, ThumbnailSize, false);
}
else
{
if (string.IsNullOrEmpty(filePath))
{
filePath = Task.Info.FileName;
}
else if (File.Exists(filePath))
{
using (Image img = ImageHelpers.LoadImage(filePath))
{
if (img != null)
{
pbThumbnail.Image = ImageHelpers.ResizeImage(img, ThumbnailSize, false);
return;
}
}
}
Image img = CreateThumbnail(filePath, image);
if (!string.IsNullOrEmpty(filePath))
{
using (Icon icon = NativeMethods.GetJumboFileIcon(filePath, false))
using (Image img = icon.ToBitmap())
{
pbThumbnail.Image = ImageHelpers.ResizeImage(img, ThumbnailSize, false, true);
}
}
if (img != null)
{
pbThumbnail.Image = img;
}
}
catch (Exception e)
@ -227,6 +202,42 @@ public void UpdateThumbnail(Image image = null)
}
}
private Image CreateThumbnail(string filePath, Image image = null)
{
if (image != null)
{
return ImageHelpers.ResizeImage(image, ThumbnailSize, false);
}
else
{
if (string.IsNullOrEmpty(filePath))
{
filePath = Task.Info.FileName;
}
else if (File.Exists(filePath))
{
using (Image img = ImageHelpers.LoadImage(filePath))
{
if (img != null)
{
return ImageHelpers.ResizeImage(img, ThumbnailSize, false);
}
}
}
if (!string.IsNullOrEmpty(filePath))
{
using (Icon icon = NativeMethods.GetJumboFileIcon(filePath, false))
using (Image img = icon.ToBitmap())
{
return ImageHelpers.ResizeImage(img, ThumbnailSize, false, true);
}
}
}
return null;
}
public void UpdateProgress()
{
if (Task.Info != null)