Skip to content

Commit 4cc5fcd

Browse files
committed
Merge branch 'development'
2 parents 93157bd + 6bdf29b commit 4cc5fcd

16 files changed

+304
-137
lines changed

ColorSetKit-Test/ColorSetKit-Test.csproj

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFrameworks>net462</TargetFrameworks>
4+
<TargetFrameworks>net462;netcoreapp3.1;net5.0-windows</TargetFrameworks>
55
<RootNamespace>ColorSetKit_Test</RootNamespace>
66
<IsPackable>false</IsPackable>
77
<UseWPF>true</UseWPF>
8+
<LangVersion>8.0</LangVersion>
9+
<Nullable>enable</Nullable>
10+
<WarningsAsErrors>nullable;CS8600;CS8602;CS8603;CS8625</WarningsAsErrors>
811
</PropertyGroup>
912

1013
<ItemGroup>

ColorSetKit-Test/Test.cs

+35-18
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,22 @@ namespace ColorSetKit_Test
3333
[TestClass]
3434
public class Test
3535
{
36+
private static string GetAssemblyDirectoryName()
37+
{
38+
string? name = System.IO.Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location );
39+
40+
if( name == null )
41+
{
42+
throw new NullReferenceException( "Cannot get directory name for assembly" );
43+
}
44+
45+
return name;
46+
}
47+
3648
[TestMethod]
3749
public void TestInitWithPathBinary()
3850
{
39-
string path = System.IO.Path.Combine( System.IO.Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), "Colors.colorset" );
51+
string path = System.IO.Path.Combine( GetAssemblyDirectoryName(), "Colors.colorset" );
4052
ColorSet set = new ColorSet( path );
4153

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

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

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

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

79-
Assert.IsTrue( ColorSet.Shared[ "NoVariant" ] != null );
80-
Assert.IsTrue( ColorSet.Shared[ "Variant" ] != null );
91+
ColorPair? p1 = ColorSet.Shared[ "NoVariant" ];
92+
ColorPair? p2 = ColorSet.Shared[ "Variant" ];
8193

82-
ColorPair p1 = ColorSet.Shared[ "NoVariant" ];
83-
ColorPair p2 = ColorSet.Shared[ "Variant" ];
94+
Assert.IsTrue( p1 != null );
95+
Assert.IsTrue( p2 != null );
96+
97+
if( p1 == null || p2 == null )
98+
{
99+
return;
100+
}
84101

85102
{
86103
if( p1.Color is SolidColorBrush c )
@@ -133,8 +150,8 @@ public void TestShared()
133150
[TestMethod]
134151
public void TestChild()
135152
{
136-
ColorSet set = new ColorSet();
137-
ColorSet child = new ColorSet();
153+
ColorSet set = new ColorSet();
154+
ColorSet child = new ColorSet();
138155
SolidColorBrush clear = new SolidColorBrush( System.Windows.Media.Color.FromArgb( 0, 0, 0, 0 ) );
139156
SolidColorBrush red = new SolidColorBrush( System.Windows.Media.Color.FromArgb( 255, 255, 0, 0 ) );
140157

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

149166
Assert.IsNotNull( set[ "foo" ] );
150-
Assert.IsTrue( ReferenceEquals( set[ "foo" ].Color, red ) );
167+
Assert.IsTrue( ReferenceEquals( set[ "foo" ]?.Color, red ) );
151168

152169
set.Add( clear, "foo" );
153170

154171
Assert.IsNotNull( set[ "foo" ] );
155-
Assert.IsTrue( ReferenceEquals( set[ "foo" ].Color, clear ) );
172+
Assert.IsTrue( ReferenceEquals( set[ "foo" ]?.Color, clear ) );
156173
}
157174

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

180-
ColorPair p1 = set[ "NoVariant" ];
181-
ColorPair p2 = set[ "Variant" ];
197+
ColorPair? p1 = set[ "NoVariant" ];
198+
ColorPair? p2 = set[ "Variant" ];
182199

183200
{
184-
if( p1.Color is SolidColorBrush c )
201+
if( p1?.Color is SolidColorBrush c )
185202
{
186203
Assert.AreEqual( c.Color.R, 50 );
187204
Assert.AreEqual( c.Color.G, 100 );
@@ -194,13 +211,13 @@ public void TestCreate()
194211
}
195212
}
196213

197-
if( p1.Variant != null )
214+
if( p1?.Variant != null )
198215
{
199216
Assert.Fail( "No variant should be defined" );
200217
}
201218

202219
{
203-
if( p2.Color is SolidColorBrush c )
220+
if( p2?.Color is SolidColorBrush c )
204221
{
205222
Assert.AreEqual( c.Color.R, 250 );
206223
Assert.AreEqual( c.Color.G, 200 );
@@ -214,7 +231,7 @@ public void TestCreate()
214231
}
215232

216233
{
217-
if( p2.Variant is SolidColorBrush c )
234+
if( p2?.Variant is SolidColorBrush c )
218235
{
219236
Assert.AreEqual( c.Color.R, 200 );
220237
Assert.AreEqual( c.Color.G, 150 );

ColorSetKit.xcodeproj/project.pbxproj

+3-5
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@
335335
isa = PBXProject;
336336
attributes = {
337337
LastSwiftUpdateCheck = 1020;
338-
LastUpgradeCheck = 1400;
338+
LastUpgradeCheck = 1420;
339339
ORGANIZATIONNAME = "XS-Labs";
340340
TargetAttributes = {
341341
057DC44A22B1492200BA6727 = {
@@ -424,7 +424,7 @@
424424
baseConfigurationReference = 054D8EC6238BE45300574045 /* Debug.xcconfig */;
425425
buildSettings = {
426426
DEVELOPMENT_TEAM = J5PR93692Y;
427-
MACOSX_DEPLOYMENT_TARGET = 10.13;
427+
MACOSX_DEPLOYMENT_TARGET = 10.11;
428428
OTHER_LDFLAGS = (
429429
"$(inherited)",
430430
"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/macosx/libswiftAppKit.dylib",
@@ -437,7 +437,7 @@
437437
baseConfigurationReference = 054D8EC7238BE45300574045 /* Release.xcconfig */;
438438
buildSettings = {
439439
DEVELOPMENT_TEAM = J5PR93692Y;
440-
MACOSX_DEPLOYMENT_TARGET = 10.13;
440+
MACOSX_DEPLOYMENT_TARGET = 10.11;
441441
OTHER_LDFLAGS = (
442442
"$(inherited)",
443443
"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/macosx/libswiftAppKit.dylib",
@@ -489,7 +489,6 @@
489489
"@executable_path/../Frameworks",
490490
"@loader_path/Frameworks",
491491
);
492-
MACOSX_DEPLOYMENT_TARGET = 10.10;
493492
PRODUCT_BUNDLE_IDENTIFIER = com.DigiDNA.ColorSetKit;
494493
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
495494
VERSIONING_SYSTEM = "apple-generic";
@@ -513,7 +512,6 @@
513512
"@executable_path/../Frameworks",
514513
"@loader_path/Frameworks",
515514
);
516-
MACOSX_DEPLOYMENT_TARGET = 10.10;
517515
PRODUCT_BUNDLE_IDENTIFIER = com.DigiDNA.ColorSetKit;
518516
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
519517
VERSIONING_SYSTEM = "apple-generic";

ColorSetKit.xcodeproj/xcshareddata/xcschemes/ColorSetKit.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1400"
3+
LastUpgradeVersion = "1420"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

ColorSetKit/ColorExtensions.cs

+30
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,16 @@ public static System.Windows.Media.Color ByChangingHue( this System.Windows.Medi
122122
return FromHSL( h, hsl.Saturation, hsl.Lightness, rgb.Alpha );
123123
}
124124

125+
public static System.Windows.Media.Color ByIncreasingHue( this System.Windows.Media.Color self, double h )
126+
{
127+
return self.ByChangingHue( self.GetHSL().Hue + h );
128+
}
129+
130+
public static System.Windows.Media.Color ByDecreasingHue( this System.Windows.Media.Color self, double h )
131+
{
132+
return self.ByChangingHue( self.GetHSL().Hue - h );
133+
}
134+
125135
public static System.Windows.Media.Color ByChangingSaturation( this System.Windows.Media.Color self, double s )
126136
{
127137
RGBComponents rgb = self.GetRGB();
@@ -130,6 +140,16 @@ public static System.Windows.Media.Color ByChangingSaturation( this System.Windo
130140
return FromHSL( hsl.Hue, s, hsl.Lightness, rgb.Alpha );
131141
}
132142

143+
public static System.Windows.Media.Color ByIncreasingSaturation( this System.Windows.Media.Color self, double s )
144+
{
145+
return self.ByChangingSaturation( self.GetHSL().Saturation + s );
146+
}
147+
148+
public static System.Windows.Media.Color ByDecreasingSaturation( this System.Windows.Media.Color self, double s )
149+
{
150+
return self.ByChangingSaturation( self.GetHSL().Saturation - s );
151+
}
152+
133153
public static System.Windows.Media.Color ByChangingLightness( this System.Windows.Media.Color self, double l )
134154
{
135155
RGBComponents rgb = self.GetRGB();
@@ -138,6 +158,16 @@ public static System.Windows.Media.Color ByChangingLightness( this System.Window
138158
return FromHSL( hsl.Hue, hsl.Saturation, l, rgb.Alpha );
139159
}
140160

161+
public static System.Windows.Media.Color ByIncreasingLightness( this System.Windows.Media.Color self, double l )
162+
{
163+
return self.ByChangingLightness( self.GetHSL().Lightness + l );
164+
}
165+
166+
public static System.Windows.Media.Color ByDecreasingLightness( this System.Windows.Media.Color self, double l )
167+
{
168+
return self.ByChangingLightness( self.GetHSL().Lightness - l );
169+
}
170+
141171
private static RGB HSLToRGB( double h, double s, double l )
142172
{
143173
double t1;

0 commit comments

Comments
 (0)