-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#44 - fix background bleed into screen thumbnails
- Loading branch information
1 parent
3f7aada
commit bb48404
Showing
6 changed files
with
195 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-12.6 KB
(94%)
src/FancyMouse.Common.UnitTests/Helpers/_test-win11-expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System.Drawing; | ||
using System.Globalization; | ||
|
||
namespace FancyMouse.Common.Helpers; | ||
|
||
public static class ConfigHelper | ||
{ | ||
public static Color? ToUnnamedColor(Color? value) | ||
{ | ||
if (!value.HasValue) | ||
{ | ||
return null; | ||
} | ||
|
||
var color = value.Value; | ||
return Color.FromArgb(color.A, color.R, color.G, color.B); | ||
} | ||
|
||
public static string? SerializeToConfigColorString(Color? value) | ||
{ | ||
if (!value.HasValue) | ||
{ | ||
return null; | ||
} | ||
|
||
var color = value.Value; | ||
return color switch | ||
{ | ||
Color { IsNamedColor: true } => | ||
$"{nameof(Color)}.{color.Name}", | ||
Color { IsSystemColor: true } => | ||
$"{nameof(SystemColors)}.{color.Name}", | ||
_ => | ||
$"#{color.R:X2}{color.G:X2}{color.B:X2}", | ||
}; | ||
} | ||
|
||
public static Color? DeserializeFromConfigColorString(string? value) | ||
{ | ||
if (string.IsNullOrEmpty(value)) | ||
{ | ||
return null; | ||
} | ||
|
||
// e.g. "#AABBCC" | ||
if (value.StartsWith('#')) | ||
{ | ||
var culture = CultureInfo.InvariantCulture; | ||
if ((value.Length == 7) | ||
&& int.TryParse(value[1..3], NumberStyles.HexNumber, culture, out var r) | ||
&& int.TryParse(value[3..5], NumberStyles.HexNumber, culture, out var g) | ||
&& int.TryParse(value[5..7], NumberStyles.HexNumber, culture, out var b)) | ||
{ | ||
return Color.FromArgb(0xFF, r, g, b); | ||
} | ||
} | ||
|
||
const StringComparison comparison = StringComparison.InvariantCulture; | ||
|
||
// e.g. "Color.Red" | ||
const string colorPrefix = $"{nameof(Color)}."; | ||
if (value.StartsWith(colorPrefix, comparison)) | ||
{ | ||
var colorName = value[colorPrefix.Length..]; | ||
var property = typeof(Color).GetProperties() | ||
.SingleOrDefault(property => property.Name == colorName); | ||
if (property is not null) | ||
{ | ||
return (Color?)property.GetValue(null, null); | ||
} | ||
} | ||
|
||
// e.g. "SystemColors.Highlight" | ||
const string systemColorPrefix = $"{nameof(SystemColors)}."; | ||
if (value.StartsWith(systemColorPrefix, comparison)) | ||
{ | ||
var colorName = value[systemColorPrefix.Length..]; | ||
var property = typeof(SystemColors).GetProperties() | ||
.SingleOrDefault(property => property.Name == colorName); | ||
if (property is not null) | ||
{ | ||
return (Color?)property.GetValue(null, null); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System.Drawing; | ||
using FancyMouse.Common.Models.Drawing; | ||
using FancyMouse.Common.Models.Styles; | ||
|
||
namespace FancyMouse.Common.Helpers; | ||
|
||
public static class StyleHelper | ||
{ | ||
/// <summary> | ||
/// Compact (legacy) preview style | ||
/// </summary> | ||
public static readonly PreviewStyle CompactPreviewStyle = new( | ||
canvasSize: new( | ||
width: 1600, | ||
height: 1200 | ||
), | ||
canvasStyle: new( | ||
marginStyle: MarginStyle.Empty, | ||
borderStyle: new( | ||
color: SystemColors.Highlight, | ||
all: 6, | ||
depth: 0 | ||
), | ||
paddingStyle: new( | ||
all: 0 | ||
), | ||
backgroundStyle: new( | ||
color1: Color.FromArgb(0xFF, 0x0D, 0x57, 0xD2), | ||
color2: Color.FromArgb(0xFF, 0x03, 0x44, 0xC0) | ||
) | ||
), | ||
screenStyle: new( | ||
marginStyle: new( | ||
all: 0 | ||
), | ||
borderStyle: new( | ||
color: Color.FromArgb(0xFF, 0x22, 0x22, 0x22), | ||
all: 0, | ||
depth: 0 | ||
), | ||
paddingStyle: PaddingStyle.Empty, | ||
backgroundStyle: new( | ||
color1: Color.MidnightBlue, | ||
color2: Color.MidnightBlue | ||
) | ||
) | ||
); | ||
|
||
/// <summary> | ||
/// Bezelled preview style | ||
/// </summary> | ||
public static readonly PreviewStyle BezelledPreviewStyle = new( | ||
canvasSize: new( | ||
width: 1600, | ||
height: 1200 | ||
), | ||
canvasStyle: new( | ||
marginStyle: MarginStyle.Empty, | ||
borderStyle: new( | ||
color: SystemColors.Highlight, | ||
all: 6, | ||
depth: 0 | ||
), | ||
paddingStyle: new( | ||
all: 4 | ||
), | ||
backgroundStyle: new( | ||
color1: Color.FromArgb(0xFF, 0x0D, 0x57, 0xD2), | ||
color2: Color.FromArgb(0xFF, 0x03, 0x44, 0xC0) | ||
) | ||
), | ||
screenStyle: new( | ||
marginStyle: new( | ||
all: 4 | ||
), | ||
borderStyle: new( | ||
color: Color.FromArgb(0xFF, 0x22, 0x22, 0x22), | ||
all: 12, | ||
depth: 4 | ||
), | ||
paddingStyle: PaddingStyle.Empty, | ||
backgroundStyle: new( | ||
color1: Color.MidnightBlue, | ||
color2: Color.MidnightBlue | ||
) | ||
) | ||
); | ||
|
||
public static PreviewStyle WithCanvasSize(this PreviewStyle previewStyle, SizeInfo canvasSize) | ||
{ | ||
ArgumentNullException.ThrowIfNull(previewStyle); | ||
ArgumentNullException.ThrowIfNull(canvasSize); | ||
return new PreviewStyle( | ||
canvasSize: canvasSize, | ||
canvasStyle: previewStyle.CanvasStyle, | ||
screenStyle: previewStyle.ScreenStyle); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters