Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hex colors constructor to ColorScheme. #383

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions MaterialSkin/ColorScheme.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace MaterialSkin
{
using System;
using System.Drawing;

public class ColorScheme
Expand Down Expand Up @@ -38,6 +39,59 @@ public ColorScheme(Primary primary, Primary darkPrimary, Primary lightPrimary, A
TextBrush = new SolidBrush(TextColor);
}

private int GetIntFromHexColor(string HexColor)
{
//#ffffff // #ffffffff
try
{
if (HexColor.Length <= 9 || HexColor.Length >= 2)
{
if (HexColor[0] == '#')
{
return Convert.ToInt32(HexColor.Replace("#", "0x"), 16);
}
else
{
return Convert.ToInt32(HexColor.Insert(0, "0x"), 16);
}

}
}
catch
{
return 0x00;
}
return 0x00;
}

public ColorScheme(string customPrimary, string customDarkPrimary, string customLightPrimary, string customAccent, TextShade textShade)
{
//Color
/*PrimaryColor = ((int)new System.ComponentModel.Int32Converter().ConvertFromString(customPrimary)).ToColor();
DarkPrimaryColor = ((int)new System.ComponentModel.Int32Converter().ConvertFromString(customDarkPrimary)).ToColor();
LightPrimaryColor = ((int)new System.ComponentModel.Int32Converter().ConvertFromString(customLightPrimary)).ToColor();
AccentColor = ((int)new System.ComponentModel.Int32Converter().ConvertFromString(customAccent)).ToColor();*/
PrimaryColor = GetIntFromHexColor(customPrimary).ToColor();
DarkPrimaryColor = GetIntFromHexColor(customDarkPrimary).ToColor();
LightPrimaryColor = GetIntFromHexColor(customLightPrimary).ToColor();
AccentColor = GetIntFromHexColor(customAccent).ToColor();
TextColor = ((int)textShade).ToColor();

//Pen
PrimaryPen = new Pen(PrimaryColor);
DarkPrimaryPen = new Pen(DarkPrimaryColor);
LightPrimaryPen = new Pen(LightPrimaryColor);
AccentPen = new Pen(AccentColor);
TextPen = new Pen(TextColor);

//Brush
PrimaryBrush = new SolidBrush(PrimaryColor);
DarkPrimaryBrush = new SolidBrush(DarkPrimaryColor);
LightPrimaryBrush = new SolidBrush(LightPrimaryColor);
AccentBrush = new SolidBrush(AccentColor);
TextBrush = new SolidBrush(TextColor);
}

public ColorScheme(int primary, int darkPrimary, int lightPrimary, int accent, TextShade textShade)
{
//Color
Expand Down
2 changes: 1 addition & 1 deletion MaterialSkin/MaterialSkin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MaterialSkin</RootNamespace>
<AssemblyName>MaterialSkin</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion MaterialSkin/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion MaterialSkin/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions MaterialSkinExample/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
</configuration>
4 changes: 2 additions & 2 deletions MaterialSkinExample/MaterialSkinExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MaterialSkinExample</RootNamespace>
<AssemblyName>MaterialSkinExample</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
Expand Down Expand Up @@ -142,4 +142,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
8 changes: 4 additions & 4 deletions MaterialSkinExample/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion MaterialSkinExample/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.