// Spludlow Software // Copyright © Samuel P. Ludlow 2020 All Rights Reserved // Distributed under the terms of the GNU General Public License version 3 // Distributed WITHOUT ANY WARRANTY; without implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE // https://www.spludlow.co.uk/LICENCE.TXT // The Spludlow logo is a registered trademark of Samuel P. Ludlow and may not be used without permission // v1.14 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; namespace Spludlow.Drawing { public static class ArtChest { private static Dictionary SolidBrushs; private static Dictionary Fonts; private static Dictionary Pens; private static Dictionary Images; // Should do here???? static ArtChest() { SolidBrushs = new Dictionary(); Fonts = new Dictionary(); Pens = new Dictionary(); Images = new Dictionary(); } public static void Dispose() { lock (SolidBrushs) { foreach (int key in SolidBrushs.Keys) SolidBrushs[key].Dispose(); SolidBrushs.Clear(); } lock (Fonts) { foreach (string key in Fonts.Keys) Fonts[key].Dispose(); Fonts.Clear(); } lock (Pens) { foreach (string key in Pens.Keys) Pens[key].Dispose(); Pens.Clear(); } DisposeImages(); } public static void DisposeImages() { lock (Images) { foreach (string key in Images.Keys) Images[key].Dispose(); Images.Clear(); } } public static SolidBrush SolidBrush(Color colour) { int argb = colour.ToArgb(); if (SolidBrushs.ContainsKey(argb) == false) { lock (SolidBrushs) { SolidBrushs.Add(argb, new SolidBrush(colour)); } } return SolidBrushs[argb]; } public static Font Font(string fontInfoText) { if (Fonts.ContainsKey(fontInfoText) == false) { FontInfo fontInfo = new FontInfo(fontInfoText); if (fontInfo.Name.Contains(" Bold") == true) { fontInfo.Name = fontInfo.Name.Replace(" Bold", ""); fontInfo.FontStyles |= System.Drawing.FontStyle.Bold; } if (fontInfo.Name.Contains(" Italic") == true) { fontInfo.Name = fontInfo.Name.Replace(" Italic", ""); fontInfo.FontStyles |= System.Drawing.FontStyle.Italic; } FontFamily family = new FontFamily(fontInfo.Name); Font font = new System.Drawing.Font(family, fontInfo.Size, fontInfo.FontStyles); lock (Fonts) { Fonts.Add(fontInfoText, font); } } return Fonts[fontInfoText]; } public static Pen Pen(float width, Color colour) { string key = width + "," + colour.ToArgb(); if (Pens.ContainsKey(key) == false) { lock (Pens) { Pens.Add(key, new Pen(colour, width)); } } return Pens[key]; } public static Image GetImage(string filename) { if (Images.ContainsKey(filename) == false) { lock (Images) { Images.Add(filename, Image.FromFile(filename)); } } return Images[filename]; } } }