From f470ae3f3692960a89ddb63a3ecb3bd965c25b01 Mon Sep 17 00:00:00 2001 From: "Travis J. Gutjahr" <33809229+Squirrelies@users.noreply.github.com> Date: Thu, 7 Feb 2019 23:18:11 -0600 Subject: [PATCH] Added --Transparency Added --ScalingFactor Added code to adjust inventory panel to correspond to the scaling factor slot width and height. Added code to adjust form to inventory panel + statistics panel width. --- RE2REmakeSRT/MainUI.cs | 33 ++++++++++++++++++----- RE2REmakeSRT/Program.cs | 36 +++++++++++++++++-------- RE2REmakeSRT/ProgramFlags.cs | 1 + RE2REmakeSRT/Properties/AssemblyInfo.cs | 4 +-- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/RE2REmakeSRT/MainUI.cs b/RE2REmakeSRT/MainUI.cs index fac6668..ce1b515 100644 --- a/RE2REmakeSRT/MainUI.cs +++ b/RE2REmakeSRT/MainUI.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; +using System.Drawing.Text; using System.Linq; using System.Windows.Forms; @@ -21,23 +22,39 @@ public partial class MainUI : Form private System.Timers.Timer memoryPollingTimer; private long lastPtrUpdate; private long lastFullUIDraw; - - private SmoothingMode smoothingMode = SmoothingMode.HighSpeed; - private PixelOffsetMode pixelOffsetMode = PixelOffsetMode.HighSpeed; - private CompositingQuality compositingQuality = CompositingQuality.HighSpeed; + private CompositingMode compositingMode = CompositingMode.SourceOver; + private CompositingQuality compositingQuality = CompositingQuality.HighSpeed; + private SmoothingMode smoothingMode = SmoothingMode.None; + private PixelOffsetMode pixelOffsetMode = PixelOffsetMode.Half; private InterpolationMode interpolationMode = InterpolationMode.NearestNeighbor; + private TextRenderingHint textRenderingHint = TextRenderingHint.AntiAliasGridFit; private StringFormat stringFormat = new StringFormat(StringFormat.GenericDefault) { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Far }; public MainUI() { InitializeComponent(); + // Set titlebar. + this.Text += string.Format(" v{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()); + if (Program.programSpecialOptions.HasFlag(ProgramFlags.NoTitleBar)) this.FormBorderStyle = FormBorderStyle.None; - // Set titlebar. - this.Text += string.Format(" v{0}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()); + if (Program.programSpecialOptions.HasFlag(ProgramFlags.Transparent)) + this.TransparencyKey = Color.Black; + + // Set the width and height of the inventory display so it matches the maximum items and the scaling size of those items. + this.inventoryPanel.Width = Program.INV_SLOT_WIDTH * 4; + this.inventoryPanel.Height = Program.INV_SLOT_HEIGHT * 5; + + // Adjust main form width as well. + this.Width = this.statisticsPanel.Width + this.inventoryPanel.Width + 24; + + //// We may also want adjust the statistics panel height and the form height. + //// Commenting out for right now in case they want 50% scaling but still need the statistics height to view enemy hp? + //this.statisticsPanel.Height = this.inventoryPanel.Height - 66; + //this.Height = this.inventoryPanel.Height + 41; lastPtrUpdate = DateTime.UtcNow.Ticks; lastFullUIDraw = DateTime.UtcNow.Ticks; @@ -112,6 +129,7 @@ private void playerHealthStatus_Paint(object sender, PaintEventArgs e) e.Graphics.CompositingMode = compositingMode; e.Graphics.InterpolationMode = interpolationMode; e.Graphics.PixelOffsetMode = pixelOffsetMode; + e.Graphics.TextRenderingHint = textRenderingHint; // Draw health. if (Program.gameMem.PlayerCurrentHealth > 1200 || Program.gameMem.PlayerCurrentHealth < 0) // Dead? @@ -143,6 +161,7 @@ private void playerInfoPanel_Paint(object sender, PaintEventArgs e) e.Graphics.CompositingMode = compositingMode; e.Graphics.InterpolationMode = interpolationMode; e.Graphics.PixelOffsetMode = pixelOffsetMode; + e.Graphics.TextRenderingHint = textRenderingHint; } private void inventoryPanel_Paint(object sender, PaintEventArgs e) @@ -152,6 +171,7 @@ private void inventoryPanel_Paint(object sender, PaintEventArgs e) e.Graphics.CompositingMode = compositingMode; e.Graphics.InterpolationMode = interpolationMode; e.Graphics.PixelOffsetMode = pixelOffsetMode; + e.Graphics.TextRenderingHint = textRenderingHint; foreach (InventoryEntry inv in Program.gameMem.PlayerInventory) { @@ -194,6 +214,7 @@ private void statisticsPanel_Paint(object sender, PaintEventArgs e) e.Graphics.CompositingMode = compositingMode; e.Graphics.InterpolationMode = interpolationMode; e.Graphics.PixelOffsetMode = pixelOffsetMode; + e.Graphics.TextRenderingHint = textRenderingHint; // IGT Display. e.Graphics.DrawText(0, 0, string.Format("{0}", Program.gameMem.IGTString), Brushes.White, new Font("Consolas", 16, FontStyle.Bold)); diff --git a/RE2REmakeSRT/Program.cs b/RE2REmakeSRT/Program.cs index f4e23aa..a065ba3 100644 --- a/RE2REmakeSRT/Program.cs +++ b/RE2REmakeSRT/Program.cs @@ -15,9 +15,9 @@ public static class Program public static GameMemory gameMem; public static Bitmap inventoryImage; // The inventory item sheet. public static Bitmap inventoryError; // An error image. - public const double INV_SLOT_SCALING = 0.75; // Scaling factor for the inventory images. - public const int INV_SLOT_WIDTH = (int)(112 * INV_SLOT_SCALING); // Individual inventory slot width. - public const int INV_SLOT_HEIGHT = (int)(112 * INV_SLOT_SCALING); // Individual inventory slot height. + public static double INV_SLOT_SCALING; // Scaling factor for the inventory images. + public static int INV_SLOT_WIDTH; + public static int INV_SLOT_HEIGHT; /// /// The main entry point for the application. @@ -29,38 +29,52 @@ public static void Main(string[] args) programSpecialOptions = ProgramFlags.None; foreach (string arg in args) { - if (string.Equals(arg, "--Help", StringComparison.InvariantCultureIgnoreCase)) + if (arg.Equals("--Help", StringComparison.InvariantCultureIgnoreCase)) { StringBuilder message = new StringBuilder("Command-line arguments:\r\n\r\n"); message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--Skip-Checksum", "Skip the checksum file validation step."); message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--No-Titlebar", "Hide the titlebar and window frame."); message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--Always-On-Top", "Always appear on top of other windows."); + message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--Transparent", "Make the background transparent."); + message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--ScalingFactor=n", "Set the inventory slot scaling factor on a scale of 0.0 to 1.0. Default: 0.75 (75%)"); message.AppendFormat("{0}\r\n\t{1}\r\n\r\n", "--Debug", "Debug mode."); MessageBox.Show(null, message.ToString().Trim(), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information); Environment.Exit(0); } - if (string.Equals(arg, "--Skip-Checksum", StringComparison.InvariantCultureIgnoreCase)) + if (arg.Equals("--Skip-Checksum", StringComparison.InvariantCultureIgnoreCase)) programSpecialOptions |= ProgramFlags.SkipChecksumCheck; - if (string.Equals(arg, "--No-Titlebar", StringComparison.InvariantCultureIgnoreCase)) + if (arg.Equals("--No-Titlebar", StringComparison.InvariantCultureIgnoreCase)) programSpecialOptions |= ProgramFlags.NoTitleBar; - if (string.Equals(arg, "--Always-On-Top", StringComparison.InvariantCultureIgnoreCase)) + if (arg.Equals("--Always-On-Top", StringComparison.InvariantCultureIgnoreCase)) programSpecialOptions |= ProgramFlags.AlwaysOnTop; - // Assigning here because debug will always be the sum of all of the options being on. - if (string.Equals(arg, "--Debug", StringComparison.InvariantCultureIgnoreCase)) - programSpecialOptions = ProgramFlags.Debug; + if (arg.Equals("--Transparent", StringComparison.InvariantCultureIgnoreCase)) + programSpecialOptions |= ProgramFlags.Transparent; + + if (arg.StartsWith("--ScalingFactor=", StringComparison.InvariantCultureIgnoreCase)) + if (!double.TryParse(arg.Split(new char[1] { '=' }, 2, StringSplitOptions.None)[1], out INV_SLOT_SCALING)) + INV_SLOT_SCALING = 0.75d; // Default scaling factor for the inventory images. If we fail to process the user input, just set us to the default value. + + if (arg.Equals("--Debug", StringComparison.InvariantCultureIgnoreCase)) + programSpecialOptions |= ProgramFlags.Debug; } + // Set item slot sizes after scaling is determined. + INV_SLOT_WIDTH = (int)Math.Round(112d * INV_SLOT_SCALING, MidpointRounding.AwayFromZero); // Individual inventory slot width. + INV_SLOT_HEIGHT = (int)Math.Round(112d * INV_SLOT_SCALING, MidpointRounding.AwayFromZero); // Individual inventory slot height. + // Standard WinForms stuff. Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Transform the inventory image in resources down from 32bpp w/ Alpha to 16bpp w/o Alpha. This greatly improve performance especially when coupled with CompositingMode.SourceCopy because no complex alpha blending needs to occur. - inventoryImage = Properties.Resources.ui0100_iam_texout.Clone(new Rectangle(0, 0, Properties.Resources.ui0100_iam_texout.Width, Properties.Resources.ui0100_iam_texout.Height), PixelFormat.Format16bppRgb555); + //inventoryImage = Properties.Resources.ui0100_iam_texout.Clone(new Rectangle(0, 0, Properties.Resources.ui0100_iam_texout.Width, Properties.Resources.ui0100_iam_texout.Height), PixelFormat.Format16bppRgb555); + // Testing perf. with PARGB. + inventoryImage = Properties.Resources.ui0100_iam_texout.Clone(new Rectangle(0, 0, Properties.Resources.ui0100_iam_texout.Width, Properties.Resources.ui0100_iam_texout.Height), PixelFormat.Format32bppPArgb); // Rescales the image down if the scaling factor is not 1. if (INV_SLOT_SCALING != 1d) diff --git a/RE2REmakeSRT/ProgramFlags.cs b/RE2REmakeSRT/ProgramFlags.cs index 18b1382..0ff1a9f 100644 --- a/RE2REmakeSRT/ProgramFlags.cs +++ b/RE2REmakeSRT/ProgramFlags.cs @@ -9,6 +9,7 @@ public enum ProgramFlags : byte SkipChecksumCheck = 0x01, NoTitleBar = 0x02, AlwaysOnTop = 0x04, + Transparent = 0x08, Debug = SkipChecksumCheck } } diff --git a/RE2REmakeSRT/Properties/AssemblyInfo.cs b/RE2REmakeSRT/Properties/AssemblyInfo.cs index 08c419b..3bf19b6 100644 --- a/RE2REmakeSRT/Properties/AssemblyInfo.cs +++ b/RE2REmakeSRT/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.4.3")] -[assembly: AssemblyFileVersion("1.1.4.3")] +[assembly: AssemblyVersion("1.1.5.0")] +[assembly: AssemblyFileVersion("1.1.5.0")]