/// <summary> /// Renders the background image for the content (unless HideBG is true). /// </summary> /// <param name="ConfigBGImagePath">This background is used unless the user selected a custom one.</param> /// <param name="graphics">The Graphics object to render the background on</param> /// <param name="Width"></param> /// <param name="Height"></param> public void RenderBGImage(string ConfigBGImagePath, Graphics graphics, int Width, int Height) { if (this.HideBG == false) { string fullPath = DreamTools.GetFullPathOrNull(DreamTools.GetDirectory(DirType.DataRoot), this.BGImagePath); if (DreamTools.FileExists(fullPath)) { if (this.bgImage == null) { try { this.bgImage = Image.FromFile(fullPath); } catch { } } } else if (DreamTools.FileExists(DreamTools.GetFullPathOrNull(DreamTools.GetDirectory(DirType.DataRoot), ConfigBGImagePath))) { if (this.bgImage == null) { try { this.bgImage = Image.FromFile(DreamTools.GetFullPathOrNull(DreamTools.GetDirectory(DirType.DataRoot), ConfigBGImagePath)); } catch { } } } if (this.bgImage != null) { graphics.DrawImage(this.bgImage, 0, 0, Width, Height); } } else { // Draw blank rectangle if no image is defined graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, Width, Height)); } }
public Options(MainForm mainForm) { _MainForm = mainForm; Lang = mainForm.Lang; InitializeComponent(); InitializeBackgroundWorker(); this.DataDirectory.Text = DreamTools.GetAppDocPath(); PopulateBibleCacheTab(); string DataSetFile = DreamTools.GetDirectory(DirType.Config, _MainForm.ConfigSet + ".dataset.config.xml"); if (DreamTools.FileExists(DataSetFile)) { this.Options_DataSet.ReadXml(DataSetFile, XmlReadMode.ReadSchema); } if (Options_RegEx_Table.Rows.Count > 0) { BibleConversions_Custom.Checked = true; BibleConversions_dataGrid_enable(true); } else { BibleConversions_Default.Checked = true; BibleConversions_dataGrid_enable(false); } SizeColumns(this.BibleConversions_dataGrid); }
public Bitmap GetBitmap(int Width, int Height) { if (this.RenderedFramesContains(this.VisibleHashCode())) { Console.WriteLine("ImageContent pre-render cache hit."); return(this.RenderedFramesGet(this.VisibleHashCode()) as Bitmap); } Bitmap bmp = new Bitmap(Width, Height); Graphics graphics = Graphics.FromImage(bmp); #region Render background image // Draw background image if (this.HideBG == false) { string fullPath = DreamTools.GetFullPathOrNull(DreamTools.GetDirectory(DirType.DataRoot), this.BGImagePath); if (DreamTools.FileExists(fullPath)) { if (this.bgImage == null) { try { this.bgImage = Image.FromFile(fullPath); } catch { } } } if (this.bgImage != null) { if (this._proportional) { graphics.DrawImage(ShowBeam.DrawProportionalBitmap(new System.Drawing.Size(Width, Height), this.bgImage).Bitmap, 0, 0, Width, Height); } else { graphics.DrawImage(this.bgImage, 0, 0, Width, Height); } } } else { // Draw blank rectangle if no image is defined graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, Width, Height)); } #endregion graphics.Dispose(); this.RenderedFramesSet(this.VisibleHashCode(), bmp); return(bmp); }
/// <summary> /// Handles deserialization of the Config class, or of any types derived from it. /// </summary> /// <param name="instance">An instance of the class to deserialize</param> /// <param name="file">The XML file to deserialize</param> /// <returns></returns> public static object DeserializeFrom(Config instance, string file) { Type type = instance.GetType(); XmlSerializer xs = null; string fullPath = DreamTools.GetFullPathOrNull(DreamTools.GetDirectory(DirType.Config), file); try { xs = new XmlSerializer(type); } catch (InvalidOperationException ex) { // Invalid class. Does the class have a public constructor? Console.WriteLine("DeserializeFrom exception: " + ex.Message); } if (!DreamTools.FileExists(fullPath)) { // fullPath could be NULL here, so use "file" Config.SerializeTo(instance, file); } else if (xs != null) { try { using (FileStream fs = File.Open(fullPath, FileMode.Open, FileAccess.Read)) { Config config = xs.Deserialize(fs) as Config; if (config != null) { return(DeserializeCleanup(config)); } else { Config.SerializeTo(instance, fullPath); } } } catch (FileNotFoundException) { Config.SerializeTo(instance, fullPath); } catch (InvalidOperationException) { // Invalid XML code Config.SerializeTo(instance, fullPath); } } return(DeserializeCleanup(instance)); }