From 649f5595dd8f327047d8e66a47e8700c13a81c30 Mon Sep 17 00:00:00 2001 From: MascaraSnake Date: Tue, 1 Mar 2016 22:48:15 +0100 Subject: [PATCH] Add options to save screenshots in PNG format and to disable the infobox in the top right corner. No menu entries for these options because I'm lazy and most people probably won't need these settings anyway. --- Build/ZoneBuilder.default.cfg | 4 +- Source/Core/Config/ProgramConfiguration.cs | 20 +++- Source/Core/Windows/MainForm.cs | 125 +++++++++++---------- 3 files changed, 85 insertions(+), 64 deletions(-) diff --git a/Build/ZoneBuilder.default.cfg b/Build/ZoneBuilder.default.cfg index 6dd7a0d..216cd13 100644 --- a/Build/ZoneBuilder.default.cfg +++ b/Build/ZoneBuilder.default.cfg @@ -840,4 +840,6 @@ rendernightspath = true; defaultceilheight = 128; defaultfloorheight = 0; defaultbrightness = 255; -dynamicgridsize = false; \ No newline at end of file +dynamicgridsize = false; +drawscreenshotinfo = true; +compressscreenshots = true; \ No newline at end of file diff --git a/Source/Core/Config/ProgramConfiguration.cs b/Source/Core/Config/ProgramConfiguration.cs index 9695300..6a259d1 100644 --- a/Source/Core/Config/ProgramConfiguration.cs +++ b/Source/Core/Config/ProgramConfiguration.cs @@ -132,6 +132,8 @@ namespace CodeImp.DoomBuilder.Config private bool rendernightspath; private bool dynamicgridsize; private int ignoredremoterevision; + private bool drawscreenshotinfo; + private bool compressscreenshots; // These are not stored in the configuration, only used at runtime private int defaultbrightness; @@ -235,9 +237,11 @@ namespace CodeImp.DoomBuilder.Config public bool RenderNiGHTSPath { get { return rendernightspath; } internal set { rendernightspath = value; } } public bool DynamicGridSize { get { return dynamicgridsize; } internal set { dynamicgridsize = value; } } //mxd internal int IgnoredRemoteRevision { get { return ignoredremoterevision; } set { ignoredremoterevision = value; } } //mxd + public bool DrawScreenshotInfo { get { return drawscreenshotinfo; } set { drawscreenshotinfo = value; } } + public bool CompressScreenshots { get { return compressscreenshots; } set { compressscreenshots = value; } } - //mxd. Left here for compatibility reasons... - public string DefaultTexture { get { return General.Map != null ? General.Map.Options.DefaultWallTexture : "-"; } set { if(General.Map != null) General.Map.Options.DefaultWallTexture = value; } } + //mxd. Left here for compatibility reasons... + public string DefaultTexture { get { return General.Map != null ? General.Map.Options.DefaultWallTexture : "-"; } set { if(General.Map != null) General.Map.Options.DefaultWallTexture = value; } } public string DefaultFloorTexture { get { return General.Map != null ? General.Map.Options.DefaultFloorTexture : "-"; } set { if(General.Map != null) General.Map.Options.DefaultFloorTexture = value; } } public string DefaultCeilingTexture { get { return General.Map != null ? General.Map.Options.DefaultCeilingTexture : "-"; } set { if(General.Map != null) General.Map.Options.DefaultCeilingTexture = value; } } public int DefaultBrightness { get { return defaultbrightness; } set { defaultbrightness = value; } } @@ -360,9 +364,11 @@ namespace CodeImp.DoomBuilder.Config rendernightspath = cfg.ReadSetting("rendernightspath", true); dynamicgridsize = cfg.ReadSetting("dynamicgridsize", true); //mxd ignoredremoterevision = cfg.ReadSetting("ignoredremoterevision", 0); //mxd + drawscreenshotinfo = cfg.ReadSetting("drawscreenshotinfo", true); + compressscreenshots = cfg.ReadSetting("compressscreenshots", true); - //mxd. Sector defaults - defaultceilheight = cfg.ReadSetting("defaultceilheight", 128); + //mxd. Sector defaults + defaultceilheight = cfg.ReadSetting("defaultceilheight", 128); defaultfloorheight = cfg.ReadSetting("defaultfloorheight", 0); defaultbrightness = cfg.ReadSetting("defaultbrightness", 192); @@ -469,9 +475,11 @@ namespace CodeImp.DoomBuilder.Config cfg.WriteSetting("rendernightspath", rendernightspath); //mxd cfg.WriteSetting("dynamicgridsize", dynamicgridsize); //mxd cfg.WriteSetting("ignoredremoterevision", ignoredremoterevision); //mxd + cfg.WriteSetting("drawscreenshotinfo", drawscreenshotinfo); + cfg.WriteSetting("compressscreenshots", compressscreenshots); - //mxd. Sector defaults - cfg.WriteSetting("defaultceilheight", defaultceilheight); + //mxd. Sector defaults + cfg.WriteSetting("defaultceilheight", defaultceilheight); cfg.WriteSetting("defaultfloorheight", defaultfloorheight); cfg.WriteSetting("defaultbrightness", defaultbrightness); diff --git a/Source/Core/Windows/MainForm.cs b/Source/Core/Windows/MainForm.cs index 167eb76..5b8b8c0 100644 --- a/Source/Core/Windows/MainForm.cs +++ b/Source/Core/Windows/MainForm.cs @@ -3242,7 +3242,8 @@ namespace CodeImp.DoomBuilder.Windows //create path string date = DateTime.Now.ToString("yyyy.MM.dd HH-mm-ss.fff"); string revision = (General.DebugBuild ? "DEVBUILD" : "R" + General.ThisAssembly.GetName().Version.MinorRevision); - string path = Path.Combine(folder, name + date + " [" + revision + "].jpg"); + bool usejpg = General.Settings.CompressScreenshots; + string path = Path.Combine(folder, name + date + " [" + revision + "]" + (usejpg ? ".jpg" : ".png")); //save image using(Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height)) @@ -3254,73 +3255,83 @@ namespace CodeImp.DoomBuilder.Windows //draw the cursor if(!cursorLocation.IsEmpty) g.DrawImage(Resources.Cursor, cursorLocation); - //gather some info - string info; - if(displayextrainfo && General.Editing.Mode != null) - { - info = General.Map.FileTitle + " | " + General.Map.Options.CurrentName + " | "; + if (General.Settings.DrawScreenshotInfo) + { + //gather some info + string info; + if (displayextrainfo && General.Editing.Mode != null) + { + info = General.Map.FileTitle + " | " + General.Map.Options.CurrentName + " | "; - //get map coordinates - if(General.Editing.Mode is ClassicMode) - { - Vector2D pos = ((ClassicMode) General.Editing.Mode).MouseMapPos; + //get map coordinates + if (General.Editing.Mode is ClassicMode) + { + Vector2D pos = ((ClassicMode)General.Editing.Mode).MouseMapPos; - //mouse inside the view? - if(pos.IsFinite()) - { - info += "X:" + Math.Round(pos.x) + " Y:" + Math.Round(pos.y); - } - else - { - info += "X:" + Math.Round(General.Map.Renderer2D.TranslateX) + " Y:" + Math.Round(General.Map.Renderer2D.TranslateY); - } - } - else - { //should be visual mode - info += "X:" + Math.Round(General.Map.VisualCamera.Position.x) + " Y:" + Math.Round(General.Map.VisualCamera.Position.y) + " Z:" + Math.Round(General.Map.VisualCamera.Position.z); - } + //mouse inside the view? + if (pos.IsFinite()) + { + info += "X:" + Math.Round(pos.x) + " Y:" + Math.Round(pos.y); + } + else + { + info += "X:" + Math.Round(General.Map.Renderer2D.TranslateX) + " Y:" + Math.Round(General.Map.Renderer2D.TranslateY); + } + } + else + { //should be visual mode + info += "X:" + Math.Round(General.Map.VisualCamera.Position.x) + " Y:" + Math.Round(General.Map.VisualCamera.Position.y) + " Z:" + Math.Round(General.Map.VisualCamera.Position.z); + } - //add the revision number - info += " | " + revision; - } - else - { - //just use the revision number - info = revision; - } + //add the revision number + info += " | " + revision; + } + else + { + //just use the revision number + info = revision; + } - //draw info - Font font = new Font("Tahoma", 10); - SizeF rect = g.MeasureString(info, font); - float px = bounds.Width - rect.Width - 4; - float py = 4; + //draw info + Font font = new Font("Tahoma", 10); + SizeF rect = g.MeasureString(info, font); + float px = bounds.Width - rect.Width - 4; + float py = 4; - g.FillRectangle(Brushes.Black, px, py, rect.Width, rect.Height + 3); - using(SolidBrush brush = new SolidBrush(Color.White)) - { - g.DrawString(info, font, brush, px + 2, py + 2); - } + g.FillRectangle(Brushes.Black, px, py, rect.Width, rect.Height + 3); + using (SolidBrush brush = new SolidBrush(Color.White)) + { + g.DrawString(info, font, brush, px + 2, py + 2); + } + } } try { - ImageCodecInfo jpegCodec = null; - ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders(); - foreach(ImageCodecInfo codec in codecs) - { - if(codec.FormatID == ImageFormat.Jpeg.Guid) - { - jpegCodec = codec; - break; - } - } + if (usejpg) + { + ImageCodecInfo jpegCodec = null; + ImageCodecInfo[] codecs = ImageCodecInfo.GetImageDecoders(); + foreach (ImageCodecInfo codec in codecs) + { + if (codec.FormatID == ImageFormat.Jpeg.Guid) + { + jpegCodec = codec; + break; + } + } - EncoderParameter qualityParam = new EncoderParameter(Encoder.Quality, 90L); - EncoderParameters encoderParams = new EncoderParameters(1); - encoderParams.Param[0] = qualityParam; + EncoderParameter qualityParam = new EncoderParameter(Encoder.Quality, 90L); + EncoderParameters encoderParams = new EncoderParameters(1); + encoderParams.Param[0] = qualityParam; - bitmap.Save(path, jpegCodec, encoderParams); - DisplayStatus(StatusType.Info, "Screenshot saved to '" + path + "'"); + bitmap.Save(path, jpegCodec, encoderParams); + } + else + { + bitmap.Save(path, ImageFormat.Png); + } + DisplayStatus(StatusType.Info, "Screenshot saved to '" + path + "'"); } catch(ExternalException e) {