Skip to content

Commit

Permalink
Fix Memory Leak for ControlTab and Add SVGs Icons
Browse files Browse the repository at this point in the history
Fixed:
- Custom Control Tab was causing a memory leak when switching tabs.
-- Was due to not disposing created Intpr and GC not being able to clean it up

Added:
- SVG support
-- SVGs can now be rendered to Bitmap
--- This means we save space and allow further color customization for icons (and backgrounds in the future)

TODO:
- Reimplement Custom Theming from User Provided file
  • Loading branch information
DavidCarbon committed May 18, 2024
1 parent b930b4c commit 696f956
Show file tree
Hide file tree
Showing 58 changed files with 4,240 additions and 1,337 deletions.
1 change: 0 additions & 1 deletion SBRW.Concepts/Form1.Designer.cs

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

44 changes: 22 additions & 22 deletions SBRW.Concepts/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using SBRW.Launcher.Core.Theme.Conversion_;
using Svg;
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
Expand All @@ -24,29 +26,27 @@ public Form1()

private void Form1_Load(object sender, System.EventArgs e)
{
// Load SVG document
//Test_Cache_SVG = Test_Cache_SVG_2 = Test_Cache_SVG_3 = Test_Cache_SVG_4 = Test_Cache_SVG_5 = Test_Cache_SVG_6 = SvgDocument.Open(svgFilePath);
//Test_Cache_SVG = Test_Cache_SVG_2 = Test_Cache_SVG_3 = Test_Cache_SVG_4 = Test_Cache_SVG_5 = Test_Cache_SVG_6 = SvgDocument.Open<SvgDocument>(new MemoryStream(Extract_Resource.AsByte("SBRW.Concepts.Logo.svg")));
//Test_Cache_SVG = Test_Cache_SVG_2 = Test_Cache_SVG_3 = Test_Cache_SVG_4 = Test_Cache_SVG_5 = Test_Cache_SVG_6 = (SvgDocument)new SvgImage().GetImage("https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/AJ_Digital_Camera.svg");

Test_Cache_SVG = SvgDocument.Open(Folder_Icon_DEBUG_Path + "Icon_Check_Engine.svg");
Color Base_Colour = Color.FromArgb(66, 179, 189);
Color Error_Colour = Color.FromArgb(254, 0, 0);
Color Success_Colour = Color.FromArgb(159, 193, 32);
Color Unknown_Colour = Color.FromArgb(132, 132, 132);
Color Warning_Colour = Color.FromArgb(230, 159, 0);
Test_Cache_SVG.Fill = new SvgColourServer(Warning_Colour);

Test_Cache_SVG_4 = SvgDocument.Open(Folder_Icon_DEBUG_Path + "Input_Global.svg");
Test_Cache_SVG_3 = SvgDocument.Open(Folder_Icon_DEBUG_Path + "Input_Global.svg");
Test_Cache_SVG_2 = SvgDocument.Open(Folder_Icon_DEBUG_Path + "Input_Global.svg");
Test_Cache_SVG_3.GetElementById("Key").Display = "";
Test_Cache_SVG_4.GetElementById("Mail").Display = "";
// Set the PictureBox image to the created bitmap
Picture_Input_Password.BackgroundImage = Test_Cache_SVG_3.Draw();
Picture_Input_Email.BackgroundImage = Test_Cache_SVG_4.Draw();
Picture_Logo.BackgroundImage = SvgDocument.Open((Folder_Icon_DEBUG_Path + "Logo.svg")).Draw();
Picture_Icon_Version.BackgroundImage = Test_Cache_SVG.Draw();
/*
var test = SvgDocument.Open((Folder_Icon_DEBUG_Path + "Input_Global.svg"));
test.GetElementById("Mail").Display = "";
test.GetElementById("Border").Stroke = test.GetElementById("Mail").Fill = new SvgColourServer(Color.FromArgb(230, 159, 0));
test.GetElementById("Border").Fill = new SvgColourServer(Color.FromArgb(0, 191, 255));
Picture_Input_Password.BackgroundImage = test.Draw();
*/
Picture_Input_Password.BackgroundImage = Icon_Order(SVG_Icon.Input_Box_Password).Draw();
Picture_Input_Email.BackgroundImage = Icon_Order(SVG_Icon.Input_Box_Email).Draw();
//Picture_Logo.BackgroundImage = SvgDocument.Open((Folder_Icon_DEBUG_Path + "Logo.svg")).Draw();
Picture_Icon_Version.BackgroundImage = Icon_Order(SVG_Icon.Check_Engine, SVG_Color.Warning).Draw();
Picture_Icon_Server.BackgroundImage = Icon_Order(SVG_Icon.Globe, SVG_Color.Warning).Draw();
Picture_Icon_API.BackgroundImage = Icon_Order(SVG_Icon.Plug, SVG_Color.Warning).Draw();
Picture_Icon_Server_Discord.BackgroundImage = Icon_Order(SVG_Icon.Discord, SVG_Color.Warning).Draw();
Picture_Icon_Server_Facebook.BackgroundImage = Icon_Order(SVG_Icon.Facebook, SVG_Color.Warning).Draw();
Picture_Icon_Server_Home.BackgroundImage = Icon_Order(SVG_Icon.Home, SVG_Color.Warning).Draw();
Picture_Icon_Server_Twitter.BackgroundImage = Icon_Order(SVG_Icon.Twitter, SVG_Color.Warning).Draw();
Button_Close.BackgroundImage = Icon_Order(SVG_Icon.Cross, SVG_Color.Warning).Draw();
Button_Settings.BackgroundImage = Icon_Order(SVG_Icon.Gear, SVG_Color.Warning).Draw();
Button_Security_Center.BackgroundImage = Icon_Order(SVG_Icon.Shield, SVG_Color.Warning).Draw();
}

private void button1_Click(object sender, System.EventArgs e)
Expand Down
146 changes: 146 additions & 0 deletions SBRW.Concepts/Form1_Visuals.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using SBRW.Launcher.Core.Theme.Conversion_;
using Svg;
using System.Drawing;

namespace SBRW.Concepts
{
public partial class Form1
{
private SvgDocument Icon_Order(SVG_Icon Icon_Form)
{
return Icon_Order(Icon_Form, SVG_Color.Unknown);
}
private SvgDocument Icon_Order(SVG_Icon Icon_Form, SVG_Color Icon_Color)
{
Color Custom_Color;
SvgDocument Custom_SVG;

switch (Icon_Color)
{
case SVG_Color.Base:
Custom_Color = Color.FromArgb(66, 179, 189);
break;
case SVG_Color.Error:
Custom_Color = Color.FromArgb(254, 0, 0);
break;
case SVG_Color.Success:
Custom_Color = Color.FromArgb(159, 193, 32);
break;
case SVG_Color.Unknown:
Custom_Color = Color.FromArgb(132, 132, 132);
break;
case SVG_Color.Warning:
Custom_Color = Color.FromArgb(230, 159, 0);
break;
default:
Custom_Color = default(Color);
break;
}

switch (Icon_Form)
{
case SVG_Icon.Check_Engine:
Custom_SVG = SvgDocument.FromSvg<SvgDocument>(Embeded_Files.SvG_Check_Engine());
Custom_SVG.Fill = new SvgColourServer(Custom_Color);
break;
case SVG_Icon.Cross:
Custom_SVG = SvgDocument.FromSvg<SvgDocument>(Embeded_Files.SvG_Cross());
Custom_SVG.Fill = new SvgColourServer(Custom_Color);
break;
case SVG_Icon.Discord:
Custom_SVG = SvgDocument.FromSvg<SvgDocument>(Embeded_Files.SvG_Discord());
Custom_SVG.Fill = new SvgColourServer(Custom_Color);
break;
case SVG_Icon.Facebook:
Custom_SVG = SvgDocument.FromSvg<SvgDocument>(Embeded_Files.SvG_Facebook());
Custom_SVG.Fill = new SvgColourServer(Custom_Color);
Custom_SVG.GetElementById("Background").Fill = new SvgColourServer(Custom_Color);
break;
case SVG_Icon.Gear:
Custom_SVG = SvgDocument.FromSvg<SvgDocument>(Embeded_Files.SvG_Gear());
Custom_SVG.Fill = new SvgColourServer(Custom_Color);
break;
case SVG_Icon.Globe:
Custom_SVG = SvgDocument.FromSvg<SvgDocument>(Embeded_Files.SvG_Globe());
Custom_SVG.Stroke = new SvgColourServer(Custom_Color);
break;
case SVG_Icon.Home:
Custom_SVG = SvgDocument.FromSvg<SvgDocument>(Embeded_Files.SvG_Home());
Custom_SVG.Fill = new SvgColourServer(Custom_Color);
break;
case SVG_Icon.Plug:
Custom_SVG = SvgDocument.FromSvg<SvgDocument>(Embeded_Files.SvG_Plug_Connect());
Custom_SVG.Fill = new SvgColourServer(Custom_Color);
break;
case SVG_Icon.Save:
Custom_SVG = SvgDocument.FromSvg<SvgDocument>(Embeded_Files.SvG_Save());
Custom_SVG.Stroke = new SvgColourServer(Custom_Color);
break;
case SVG_Icon.Shield:
Custom_SVG = SvgDocument.FromSvg<SvgDocument>(Embeded_Files.SvG_Shield());
Custom_SVG.Fill = new SvgColourServer(Custom_Color);
break;
case SVG_Icon.Twitter:
Custom_SVG = SvgDocument.FromSvg<SvgDocument>(Embeded_Files.SvG_Twitter());
Custom_SVG.Fill = new SvgColourServer(Custom_Color);
break;
case SVG_Icon.Input_Box:
Custom_SVG = SvgDocument.FromSvg<SvgDocument>(Embeded_Files.SvG_Inputs_Box());
Custom_SVG.GetElementById("Border").Stroke = new SvgColourServer(Custom_Color);
break;
case SVG_Icon.Input_Box_Email:
Custom_SVG = SvgDocument.FromSvg<SvgDocument>(Embeded_Files.SvG_Inputs_Box());
Custom_SVG.GetElementById("Mail").Display = " ";
Custom_SVG.GetElementById("Border").Stroke = new SvgColourServer(Custom_Color);
Custom_SVG.GetElementById("Mail").Fill = new SvgColourServer(Custom_Color);
break;
case SVG_Icon.Input_Box_Password:
Custom_SVG = SvgDocument.FromSvg<SvgDocument>(Embeded_Files.SvG_Inputs_Box());
Custom_SVG.GetElementById("Key").Display = "";
Custom_SVG.GetElementById("Border").Stroke = new SvgColourServer(Custom_Color);
Custom_SVG.GetElementById("Key").Fill = new SvgColourServer(Custom_Color);
break;
case SVG_Icon.Input_Box_Ticket:
Custom_SVG = SvgDocument.FromSvg<SvgDocument>(Embeded_Files.SvG_Inputs_Box());
Custom_SVG.GetElementById("Ticket").Display = "";
Custom_SVG.GetElementById("Border").Stroke = new SvgColourServer(Custom_Color);
Custom_SVG.GetElementById("Ticket").Fill = new SvgColourServer(Custom_Color);
break;
default:
Custom_SVG = default;
break;
}

return Custom_SVG;
}

public enum SVG_Icon
{
Check_Engine,
Cross,
Discord,
Facebook,
Gear,
Globe,
Home,
Plug,
Save,
Shield,
Twitter,
Input_Box,
Input_Box_Email,
Input_Box_Password,
Input_Box_Ticket
}

public enum SVG_Color
{
Base,
Error,
Success,
Unknown,
Warning
}

}
}
Loading

0 comments on commit 696f956

Please sign in to comment.