2using System.Collections;
3using System.Collections.Generic;
18 private readonly Dictionary<string, string> customProperties =
new Dictionary<string, string>();
19 private readonly
ThemeImage[] backgroundImages =
null;
20 private readonly
ThemeImage[] bannerImages =
null;
22 private readonly
string id;
23 private readonly
string title;
24 private readonly
string cssx;
25 private readonly
string fontFamily;
26 private readonly SKColor textColor;
27 private readonly SKColor backgroundColor;
28 private readonly SKColor headerColor;
29 private readonly SKColor headerTextColor;
30 private readonly SKColor buttonColor;
31 private readonly SKColor buttonTextColor;
32 private readonly SKColor menuTextColor;
33 private readonly SKColor insertColor;
34 private readonly SKColor deleteColor;
35 private readonly SKColor linkColorUnvisited;
36 private readonly SKColor linkColorVisited;
37 private readonly SKColor linkColorHot;
38 private readonly SKColor graphBgColor;
39 private readonly SKColor graphFgColor;
49 foreach (XmlNode N
in Xml.DocumentElement.ChildNodes)
51 if (N is XmlElement E)
56 foreach (XmlNode N2
in E.ChildNodes)
58 if (N2 is XmlElement E2)
63 this.title = E2.InnerText;
67 this.thumbnail = this.ParseThemeImage(E2);
74 case "BasicProperties":
75 foreach (XmlNode N2
in E.ChildNodes)
77 if (N2 is XmlElement E2)
82 this.cssx = this.GetResourceName(E2.InnerText);
90 case "BackgroundColor":
92 this.backgroundColor = cl;
97 this.headerColor = cl;
100 case "HeaderTextColor":
102 this.headerTextColor = cl;
107 this.buttonColor = cl;
110 case "ButtonTextColor":
112 this.buttonTextColor = cl;
115 case "MenuTextColor":
117 this.menuTextColor = cl;
122 this.insertColor = cl;
127 this.deleteColor = cl;
130 case "LinkColorUnvisited":
132 this.linkColorUnvisited = cl;
135 case "LinkColorVisited":
137 this.linkColorVisited = cl;
142 this.linkColorHot = cl;
146 this.fontFamily = E2.InnerText;
151 this.graphBgColor = cl;
156 this.graphFgColor = cl;
163 case "CustomProperties":
164 foreach (XmlNode N2
in E.ChildNodes)
166 if (N2 is XmlElement E2 && E2.LocalName ==
"Property")
171 this.customProperties[Name] = Value;
176 case "BackgroundImages":
177 List<ThemeImage> Images =
new List<ThemeImage>();
179 foreach (XmlNode N2
in E.ChildNodes)
181 if (N2 is XmlElement E2 && E2.LocalName ==
"BackgroundImage")
182 Images.Add(this.ParseThemeImage(E2));
185 this.backgroundImages = Images.ToArray();
189 Images =
new List<ThemeImage>();
191 foreach (XmlNode N2
in E.ChildNodes)
193 if (N2 is XmlElement E2 && E2.LocalName ==
"BannerImage")
194 Images.Add(this.ParseThemeImage(E2));
197 this.bannerImages = Images.ToArray();
204 private ThemeImage ParseThemeImage(XmlElement E)
206 string FileName = E.InnerText;
210 return new ThemeImage(this.GetResourceName(FileName), Width, Height);
213 private string GetResourceName(
string FileName)
215 return "/Themes/" + this.id +
"/" + FileName;
223 public string this[
string key] => this.customProperties[key];
228 public string Id => this.id;
243 public string CSSX => this.cssx;
338 return this.GetImage(this.backgroundImages, Width, Height);
349 return this.GetImage(this.bannerImages, Width, Height);
355 double BestSqrError =
double.MaxValue;
360 d = Img.Width - Width;
363 d = Img.Height - Height;
366 if (Best is
null || SqrError < BestSqrError)
369 BestSqrError = SqrError;
382 KeyValuePair<string, string>[] Result =
new KeyValuePair<string, string>[this.customProperties.Count];
385 foreach (KeyValuePair<string, string> P
in this.customProperties)
398 Variables[
"BackgroundColor"] = this.backgroundColor;
399 Variables[
"HeaderColor"] = this.headerColor;
400 Variables[
"HeaderTextColor"] = this.headerTextColor;
401 Variables[
"ButtonColor"] = this.buttonColor;
402 Variables[
"ButtonTextColor"] = this.buttonTextColor;
403 Variables[
"MenuTextColor"] = this.menuTextColor;
404 Variables[
"InsertColor"] = this.insertColor;
405 Variables[
"DeleteColor"] = this.deleteColor;
406 Variables[
"LinkColorUnvisited"] = this.linkColorUnvisited;
407 Variables[
"LinkColorVisited"] = this.linkColorVisited;
408 Variables[
"LinkColorHot"] = this.linkColorHot;
409 Variables[
"FontFamily"] = this.fontFamily;
410 Variables[
"BackgroundImages"] = this.backgroundImages;
411 Variables[
"BannerImages"] = this.bannerImages;
Helps with common XML-related tasks.
static string Attribute(XmlElement E, string Name)
Gets the value of an XML attribute.
Contains properties for a theme.
ThemeImage[] BannerImages
Banner images.
ThemeImage GetBackgroundImage(int Width, int Height)
Gets a background image best matching a given size.
SKColor TextColor
Color for normal text.
void Prepare(Variables Variables)
Prepares a collection of variables for transforming content based on a theme.
ThemeImage[] BackgroundImages
Background images.
SKColor GraphFgColor
Graph foreground color.
SKColor HeaderColor
Color for text headers.
SKColor DeleteColor
Backgound color for deleted text.
SKColor LinkColorUnvisited
Color of unvisited links.
SKColor MenuTextColor
Text color for links in the menu.
string Title
A human readable title for the theme.
SKColor ButtonColor
Background color for controls.
string CSSX
Resource of the CSSX file of the theme
SKColor LinkColorVisited
Color of visited links.
SKColor LinkColorHot
Color of hot links.
ThemeImage Thumbnail
Thumbnail for the theme
SKColor ButtonTextColor
Text color for controls.
SKColor InsertColor
Backgound color for inserted text.
string FontFamily
CSS font-family value.
SKColor GraphBgColor
Graph background color.
SKColor HeaderTextColor
Text color for text headers, if used with backgound HeaderColor.
string Id
ID of the theme.
KeyValuePair< string, string >[] GetCustomProperties()
Gets defined custom properties.
ThemeImage GetBannerImage(int Width, int Height)
Gets a banner image best matching a given size.
SKColor BackgroundColor
Background Color for normal text.
Contains a reference to an image in the theme.
Returns a color value from a string.
static bool TryParse(string s, out SKColor Color)
Tries to parse a string containing a color name.
const string GraphFgColorVariableName
Variable name for graph foreground color.
const string GraphBgColorVariableName
Variable name for graph background color.