public static void ReloadTheme() { /* Migration: */ if (config.Theme == "hobd.HOBDTheme") { config.Theme = "themes/default.theme"; } // load theme HOBD.theme = HOBDTheme.LoadTheme(Path.Combine(HOBD.AppPath, config.Theme)); }
public static HOBDTheme LoadTheme(string file) { HOBDTheme theme = new HOBDTheme(); theme.File = file; XmlReaderSettings xrs = new XmlReaderSettings(); xrs.IgnoreWhitespace = true; xrs.IgnoreComments = true; try{ XmlReader reader = XmlReader.Create(file, xrs); reader.ReadToDescendant("theme"); theme.Name = reader.GetAttribute("name"); theme.Background = reader.GetAttribute("background"); reader.ReadStartElement("theme"); while(true){ if (reader.NodeType != XmlNodeType.Element){ if (!reader.Read()) break; continue; } string name; string val; int ival; switch (reader.Name) { case "color": name = reader.GetAttribute("name"); val = reader.ReadElementContentAsString(); theme.Colors.Add(name, Color.FromArgb(ParseColor(val))); break; case "font-size": name = reader.GetAttribute("name"); val = reader.GetAttribute("value"); ival = Int32.Parse(val, NumberStyles.Integer); theme.FontSizes.Add(name, ival); reader.Read(); break; case "font-family": name = reader.GetAttribute("name"); val = reader.ReadElementContentAsString(); theme.FontFamilies.Add(name, val); break; case "style": name = reader.GetAttribute("name"); TextStyle style = new TextStyle(theme.PhoneTextNormalStyle); reader.ReadStartElement(); while(reader.NodeType != XmlNodeType.EndElement){ if (reader.NodeType != XmlNodeType.Element) continue; switch (reader.Name) { case "font": val = reader.ReadElementContentAsString(); theme.FontFamilies.TryGetValue(val, out val); style.FontFamily = val; break; case "size": val = reader.ReadElementContentAsString(); if (!theme.FontSizes.TryGetValue(val, out ival)){ ival = Int32.Parse(val); } style.FontSize = ival; break; case "color": val = reader.ReadElementContentAsString(); Color color; if (!theme.Colors.TryGetValue(val, out color)){ color = Color.FromArgb(ParseColor(val)); } style.Foreground = color; break; } } reader.ReadEndElement(); theme.Styles.Add(name, style); break; default: reader.Read(); break; } } reader.Close(); theme.Styles.TryGetValue("PanoramaTitle", out theme.PhoneTextPanoramaTitleStyle); theme.Styles.TryGetValue("PanoramaSubTitle", out theme.PhoneTextPanoramaSubTitleStyle); theme.Styles.TryGetValue("PanoramaSectionTitle", out theme.PhoneTextPanoramaSectionTitleStyle); theme.Styles.TryGetValue("TextNormal", out theme.PhoneTextNormalStyle); theme.Styles.TryGetValue("TextStatus", out theme.PhoneTextStatusStyle); theme.Styles.TryGetValue("TextSensorDescr", out theme.PhoneTextSensorDescrStyle); }catch(Exception e){ Logger.error("HOBDTheme", "error parsing theme file", e); } return theme; }
public static void ReloadTheme() { /* Migration: */ if (config.Theme == "hobd.HOBDTheme") config.Theme = "themes/default.theme"; // load theme HOBD.theme = HOBDTheme.LoadTheme(Path.Combine(HOBD.AppPath, config.Theme)); }
public static HOBDTheme LoadTheme(string file) { HOBDTheme theme = new HOBDTheme(); theme.File = file; XmlReaderSettings xrs = new XmlReaderSettings(); xrs.IgnoreWhitespace = true; xrs.IgnoreComments = true; try{ XmlReader reader = XmlReader.Create(file, xrs); reader.ReadToDescendant("theme"); theme.Name = reader.GetAttribute("name"); theme.Background = reader.GetAttribute("background"); reader.ReadStartElement("theme"); while (true) { if (reader.NodeType != XmlNodeType.Element) { if (!reader.Read()) { break; } continue; } string name; string val; int ival; switch (reader.Name) { case "color": name = reader.GetAttribute("name"); val = reader.ReadElementContentAsString(); theme.Colors.Add(name, Color.FromArgb(ParseColor(val))); break; case "font-size": name = reader.GetAttribute("name"); val = reader.GetAttribute("value"); ival = Int32.Parse(val, NumberStyles.Integer); theme.FontSizes.Add(name, ival); reader.Read(); break; case "font-family": name = reader.GetAttribute("name"); val = reader.ReadElementContentAsString(); theme.FontFamilies.Add(name, val); break; case "style": name = reader.GetAttribute("name"); TextStyle style = new TextStyle(theme.PhoneTextNormalStyle); reader.ReadStartElement(); while (reader.NodeType != XmlNodeType.EndElement) { if (reader.NodeType != XmlNodeType.Element) { continue; } switch (reader.Name) { case "font": val = reader.ReadElementContentAsString(); theme.FontFamilies.TryGetValue(val, out val); style.FontFamily = val; break; case "size": val = reader.ReadElementContentAsString(); if (!theme.FontSizes.TryGetValue(val, out ival)) { ival = Int32.Parse(val); } style.FontSize = ival; break; case "color": val = reader.ReadElementContentAsString(); Color color; if (!theme.Colors.TryGetValue(val, out color)) { color = Color.FromArgb(ParseColor(val)); } style.Foreground = color; break; } } reader.ReadEndElement(); theme.Styles.Add(name, style); break; default: reader.Read(); break; } } reader.Close(); theme.Styles.TryGetValue("PanoramaTitle", out theme.PhoneTextPanoramaTitleStyle); theme.Styles.TryGetValue("PanoramaSubTitle", out theme.PhoneTextPanoramaSubTitleStyle); theme.Styles.TryGetValue("PanoramaSectionTitle", out theme.PhoneTextPanoramaSectionTitleStyle); theme.Styles.TryGetValue("TextNormal", out theme.PhoneTextNormalStyle); theme.Styles.TryGetValue("TextStatus", out theme.PhoneTextStatusStyle); theme.Styles.TryGetValue("TextSensorDescr", out theme.PhoneTextSensorDescrStyle); }catch (Exception e) { Logger.error("HOBDTheme", "error parsing theme file", e); } return(theme); }