Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
macmade committed Jul 2, 2024
2 parents 93157bd + 6bdf29b commit 4cc5fcd
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 137 deletions.
5 changes: 4 additions & 1 deletion ColorSetKit-Test/ColorSetKit-Test.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net462</TargetFrameworks>
<TargetFrameworks>net462;netcoreapp3.1;net5.0-windows</TargetFrameworks>
<RootNamespace>ColorSetKit_Test</RootNamespace>
<IsPackable>false</IsPackable>
<UseWPF>true</UseWPF>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable;CS8600;CS8602;CS8603;CS8625</WarningsAsErrors>
</PropertyGroup>

<ItemGroup>
Expand Down
53 changes: 35 additions & 18 deletions ColorSetKit-Test/Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,22 @@ namespace ColorSetKit_Test
[TestClass]
public class Test
{
private static string GetAssemblyDirectoryName()
{
string? name = System.IO.Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location );

if( name == null )
{
throw new NullReferenceException( "Cannot get directory name for assembly" );
}

return name;
}

[TestMethod]
public void TestInitWithPathBinary()
{
string path = System.IO.Path.Combine( System.IO.Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "Colors.colorset" );
string path = System.IO.Path.Combine( GetAssemblyDirectoryName(), "Colors.colorset" );
ColorSet set = new ColorSet( path );

Assert.IsTrue( set.Colors.Count > 0 );
Expand All @@ -45,7 +57,7 @@ public void TestInitWithPathBinary()
[TestMethod]
public void TestInitWithPathXML()
{
string path = System.IO.Path.Combine( System.IO.Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "Colors-XML.colorset" );
string path = System.IO.Path.Combine( GetAssemblyDirectoryName(), "Colors-XML.colorset" );
ColorSet set = new ColorSet( path );

Assert.IsTrue( set.Colors.Count > 0 );
Expand All @@ -54,7 +66,7 @@ public void TestInitWithPathXML()
[TestMethod]
public void TestInitWithDataBinary()
{
string path = System.IO.Path.Combine( System.IO.Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "Colors.colorset" );
string path = System.IO.Path.Combine( GetAssemblyDirectoryName(), "Colors.colorset" );
Data data = new Data( path );
ColorSet set = new ColorSet( data );

Expand All @@ -64,7 +76,7 @@ public void TestInitWithDataBinary()
[TestMethod]
public void TestInitWithDataXML()
{
string path = System.IO.Path.Combine( System.IO.Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "Colors-XML.colorset" );
string path = System.IO.Path.Combine( GetAssemblyDirectoryName(), "Colors-XML.colorset" );
Data data = new Data( path );
ColorSet set = new ColorSet( data );

Expand All @@ -76,11 +88,16 @@ public void TestShared()
{
Assert.AreEqual( ColorSet.Shared.Colors.Count, 2 );

Assert.IsTrue( ColorSet.Shared[ "NoVariant" ] != null );
Assert.IsTrue( ColorSet.Shared[ "Variant" ] != null );
ColorPair? p1 = ColorSet.Shared[ "NoVariant" ];
ColorPair? p2 = ColorSet.Shared[ "Variant" ];

ColorPair p1 = ColorSet.Shared[ "NoVariant" ];
ColorPair p2 = ColorSet.Shared[ "Variant" ];
Assert.IsTrue( p1 != null );
Assert.IsTrue( p2 != null );

if( p1 == null || p2 == null )
{
return;
}

{
if( p1.Color is SolidColorBrush c )
Expand Down Expand Up @@ -133,8 +150,8 @@ public void TestShared()
[TestMethod]
public void TestChild()
{
ColorSet set = new ColorSet();
ColorSet child = new ColorSet();
ColorSet set = new ColorSet();
ColorSet child = new ColorSet();
SolidColorBrush clear = new SolidColorBrush( System.Windows.Media.Color.FromArgb( 0, 0, 0, 0 ) );
SolidColorBrush red = new SolidColorBrush( System.Windows.Media.Color.FromArgb( 255, 255, 0, 0 ) );

Expand All @@ -147,12 +164,12 @@ public void TestChild()
child.Add( red, "foo" );

Assert.IsNotNull( set[ "foo" ] );
Assert.IsTrue( ReferenceEquals( set[ "foo" ].Color, red ) );
Assert.IsTrue( ReferenceEquals( set[ "foo" ]?.Color, red ) );

set.Add( clear, "foo" );

Assert.IsNotNull( set[ "foo" ] );
Assert.IsTrue( ReferenceEquals( set[ "foo" ].Color, clear ) );
Assert.IsTrue( ReferenceEquals( set[ "foo" ]?.Color, clear ) );
}

[TestMethod]
Expand All @@ -177,11 +194,11 @@ public void TestCreate()
Assert.IsTrue( set[ "NoVariant" ] != null );
Assert.IsTrue( set[ "Variant" ] != null );

ColorPair p1 = set[ "NoVariant" ];
ColorPair p2 = set[ "Variant" ];
ColorPair? p1 = set[ "NoVariant" ];
ColorPair? p2 = set[ "Variant" ];

{
if( p1.Color is SolidColorBrush c )
if( p1?.Color is SolidColorBrush c )
{
Assert.AreEqual( c.Color.R, 50 );
Assert.AreEqual( c.Color.G, 100 );
Expand All @@ -194,13 +211,13 @@ public void TestCreate()
}
}

if( p1.Variant != null )
if( p1?.Variant != null )
{
Assert.Fail( "No variant should be defined" );
}

{
if( p2.Color is SolidColorBrush c )
if( p2?.Color is SolidColorBrush c )
{
Assert.AreEqual( c.Color.R, 250 );
Assert.AreEqual( c.Color.G, 200 );
Expand All @@ -214,7 +231,7 @@ public void TestCreate()
}

{
if( p2.Variant is SolidColorBrush c )
if( p2?.Variant is SolidColorBrush c )
{
Assert.AreEqual( c.Color.R, 200 );
Assert.AreEqual( c.Color.G, 150 );
Expand Down
8 changes: 3 additions & 5 deletions ColorSetKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 1020;
LastUpgradeCheck = 1400;
LastUpgradeCheck = 1420;
ORGANIZATIONNAME = "XS-Labs";
TargetAttributes = {
057DC44A22B1492200BA6727 = {
Expand Down Expand Up @@ -424,7 +424,7 @@
baseConfigurationReference = 054D8EC6238BE45300574045 /* Debug.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = J5PR93692Y;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MACOSX_DEPLOYMENT_TARGET = 10.11;
OTHER_LDFLAGS = (
"$(inherited)",
"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/macosx/libswiftAppKit.dylib",
Expand All @@ -437,7 +437,7 @@
baseConfigurationReference = 054D8EC7238BE45300574045 /* Release.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = J5PR93692Y;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MACOSX_DEPLOYMENT_TARGET = 10.11;
OTHER_LDFLAGS = (
"$(inherited)",
"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/macosx/libswiftAppKit.dylib",
Expand Down Expand Up @@ -489,7 +489,6 @@
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = com.DigiDNA.ColorSetKit;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -513,7 +512,6 @@
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 10.10;
PRODUCT_BUNDLE_IDENTIFIER = com.DigiDNA.ColorSetKit;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
VERSIONING_SYSTEM = "apple-generic";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1400"
LastUpgradeVersion = "1420"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
30 changes: 30 additions & 0 deletions ColorSetKit/ColorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ public static System.Windows.Media.Color ByChangingHue( this System.Windows.Medi
return FromHSL( h, hsl.Saturation, hsl.Lightness, rgb.Alpha );
}

public static System.Windows.Media.Color ByIncreasingHue( this System.Windows.Media.Color self, double h )
{
return self.ByChangingHue( self.GetHSL().Hue + h );
}

public static System.Windows.Media.Color ByDecreasingHue( this System.Windows.Media.Color self, double h )
{
return self.ByChangingHue( self.GetHSL().Hue - h );
}

public static System.Windows.Media.Color ByChangingSaturation( this System.Windows.Media.Color self, double s )
{
RGBComponents rgb = self.GetRGB();
Expand All @@ -130,6 +140,16 @@ public static System.Windows.Media.Color ByChangingSaturation( this System.Windo
return FromHSL( hsl.Hue, s, hsl.Lightness, rgb.Alpha );
}

public static System.Windows.Media.Color ByIncreasingSaturation( this System.Windows.Media.Color self, double s )
{
return self.ByChangingSaturation( self.GetHSL().Saturation + s );
}

public static System.Windows.Media.Color ByDecreasingSaturation( this System.Windows.Media.Color self, double s )
{
return self.ByChangingSaturation( self.GetHSL().Saturation - s );
}

public static System.Windows.Media.Color ByChangingLightness( this System.Windows.Media.Color self, double l )
{
RGBComponents rgb = self.GetRGB();
Expand All @@ -138,6 +158,16 @@ public static System.Windows.Media.Color ByChangingLightness( this System.Window
return FromHSL( hsl.Hue, hsl.Saturation, l, rgb.Alpha );
}

public static System.Windows.Media.Color ByIncreasingLightness( this System.Windows.Media.Color self, double l )
{
return self.ByChangingLightness( self.GetHSL().Lightness + l );
}

public static System.Windows.Media.Color ByDecreasingLightness( this System.Windows.Media.Color self, double l )
{
return self.ByChangingLightness( self.GetHSL().Lightness - l );
}

private static RGB HSLToRGB( double h, double s, double l )
{
double t1;
Expand Down
Loading

0 comments on commit 4cc5fcd

Please sign in to comment.