diff --git a/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs b/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs index 13de37f6cb3..7e73c31c2b3 100644 --- a/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs +++ b/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs @@ -74,6 +74,18 @@ public static ToolStripMenuItem ToColumnsMenu(this InputRoll inputRoll, Action c return menu; } + public static void CenterOn(this Form form, Control logicalParent) + => form.CenterOn((logicalParent is Form ? logicalParent : logicalParent.Parent) + .ChildPointToScreen(logicalParent) + logicalParent.HalfSize()); + + public static void CenterOn(this Form form, Point point) + { + // not asserting `form` is closed at this point, but we could + point -= form.HalfSize(); + form.StartPosition = FormStartPosition.Manual; + form.Location = point; + } + public static Point ChildPointToScreen(this Control control, Control child) { return control.PointToScreen(new Point(child.Location.X, child.Location.Y)); @@ -131,6 +143,9 @@ public static T Clone(this T controlToClone) public static IEnumerable Controls(this Control control) => control.Controls.Cast(); + public static Size HalfSize(this Control c) + => new(c.Width / 2, c.Height / 2); + public static IEnumerable TabPages(this TabControl tabControl) { return tabControl.TabPages.Cast(); diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs index b8145dcac5a..5825429dea4 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs @@ -92,7 +92,7 @@ private void InitializeComponent() this.Controls.Add(this.OkBtn); this.Controls.Add(this.CancelBtn); this.Name = "GreenzoneSettings"; - this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Default Savestate History Settings"; this.Load += new System.EventHandler(this.GreenzoneSettings_Load); this.ResumeLayout(false); diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/HeaderEditor.Designer.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/HeaderEditor.Designer.cs index 4788c1e6974..d5eb6b0f989 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/HeaderEditor.Designer.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/HeaderEditor.Designer.cs @@ -207,7 +207,7 @@ private void InitializeComponent() this.Controls.Add(this.CancelBtn); this.MinimumSize = new System.Drawing.Size(150, 311); this.Name = "MovieHeaderEditor"; - this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Header Info"; this.Load += new System.EventHandler(this.MovieHeaderEditor_Load); this.ResumeLayout(false); diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs index e4b0af3b371..930ace0351d 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs @@ -953,24 +953,23 @@ private void LoadBranchOnDoubleClickMenuItem_Click(object sender, EventArgs e) private void HeaderMenuItem_Click(object sender, EventArgs e) { - new MovieHeaderEditor(CurrentTasMovie, Config) - { - Owner = Owner, - Location = this.ChildPointToScreen(TasView) - }.Show(); + MovieHeaderEditor form = new(CurrentTasMovie, Config) { Owner = this.Owner/*uhh*/ }; + form.CenterOn(TasView); + form.Show(); } private void StateHistorySettingsMenuItem_Click(object sender, EventArgs e) { - new GreenzoneSettings( + GreenzoneSettings form = new( DialogController, new ZwinderStateManagerSettings(CurrentTasMovie.TasStateManager.Settings), (s, k) => { CurrentTasMovie.TasStateManager.UpdateSettings(s, k); }, false) { - Location = this.ChildPointToScreen(TasView), - Owner = Owner - }.ShowDialog(); + Owner = this.Owner, // uhh + }; + form.CenterOn(TasView); + form.ShowDialog(); } private void CommentsMenuItem_Click(object sender, EventArgs e) @@ -987,15 +986,16 @@ private void SubtitlesMenuItem_Click(object sender, EventArgs e) private void DefaultStateSettingsMenuItem_Click(object sender, EventArgs e) { - new GreenzoneSettings( + GreenzoneSettings form = new( DialogController, new ZwinderStateManagerSettings(Config.Movies.DefaultTasStateManagerSettings), (s, k) => { Config.Movies.DefaultTasStateManagerSettings = s; }, true) { - Location = this.ChildPointToScreen(TasView), - Owner = Owner - }.ShowDialog(); + Owner = this.Owner, // uhh + }; + form.CenterOn(TasView); + form.ShowDialog(); } private void SettingsSubMenu_DropDownOpened(object sender, EventArgs e)