From 2211a4186f91e64554092f432bad8a702dc5c64d Mon Sep 17 00:00:00 2001 From: feos Date: Sun, 1 Dec 2024 19:31:20 +0300 Subject: [PATCH] control extension to ensure onscreen dialog spawn applied to tastudio dialogs (branch/marker text will use it later) --- .../Extensions/ControlExtensions.cs | 16 +++++++++++++++ .../tools/TAStudio/TAStudio.MenuItems.cs | 20 +++++++++---------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs b/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs index 13de37f6cb..92acb4c9a9 100644 --- a/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs +++ b/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs @@ -79,6 +79,22 @@ namespace BizHawk.Client.EmuHawk return control.PointToScreen(new Point(child.Location.X, child.Location.Y)); } + public static DialogResult ShowDialogOnScreen(this Form form) + { + var topLeft = new Point( + Math.Max(0, form.Location.X), + Math.Max(0, form.Location.Y)); + var screen = Screen.AllScreens + .Where(s => s.WorkingArea.Contains(topLeft)) + .FirstOrDefault(); + var w = screen.WorkingArea.Right - form.Bounds.Right; + var h = screen.WorkingArea.Bottom - form.Bounds.Bottom; + if (h < 0) topLeft.Y += h; + if (w < 0) topLeft.X += w; + form.SetDesktopLocation(topLeft.X, topLeft.Y); + return form.ShowDialog(); + } + public static Color Add(this Color color, int val) { var col = color.ToArgb(); diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs index 0f742aad28..d0acfecc9a 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs @@ -590,7 +590,7 @@ namespace BizHawk.Client.EmuHawk private void CloneFramesXTimesMenuItem_Click(object sender, EventArgs e) { using var framesPrompt = new FramesPrompt("Clone # Times", "Insert times to clone:"); - if (framesPrompt.ShowDialog().IsOk()) + if (framesPrompt.ShowDialogOnScreen().IsOk()) { CloneFramesXTimes(framesPrompt.Frames); } @@ -649,7 +649,7 @@ namespace BizHawk.Client.EmuHawk { var insertionFrame = TasView.SelectionStartIndex ?? 0; using var framesPrompt = new FramesPrompt(); - if (framesPrompt.ShowDialog().IsOk()) + if (framesPrompt.ShowDialogOnScreen().IsOk()) { InsertNumFrames(insertionFrame, framesPrompt.Frames); } @@ -779,7 +779,7 @@ namespace BizHawk.Client.EmuHawk InitialValue = CurrentTasMovie.ChangeLog.MaxSteps.ToString() }; - var result = MainForm.DoWithTempMute(() => prompt.ShowDialog()); + var result = MainForm.DoWithTempMute(() => prompt.ShowDialogOnScreen()); if (result.IsOk()) { int val = 0; @@ -811,7 +811,7 @@ namespace BizHawk.Client.EmuHawk InitialValue = (Settings.AutosaveInterval / 1000).ToString() }; - var result = MainForm.DoWithTempMute(() => prompt.ShowDialog()); + var result = MainForm.DoWithTempMute(() => prompt.ShowDialogOnScreen()); if (result.IsOk()) { uint val = uint.Parse(prompt.PromptText) * 1000; @@ -912,7 +912,7 @@ namespace BizHawk.Client.EmuHawk Owner = Owner, Location = this.ChildPointToScreen(TasView) }; - form.ShowDialog(); + form.ShowDialogOnScreen(); } private void StateHistorySettingsMenuItem_Click(object sender, EventArgs e) @@ -926,7 +926,7 @@ namespace BizHawk.Client.EmuHawk Owner = Owner, Location = this.ChildPointToScreen(TasView) }; - form.ShowDialog(); + form.ShowDialogOnScreen(); } private void CommentsMenuItem_Click(object sender, EventArgs e) @@ -937,7 +937,7 @@ namespace BizHawk.Client.EmuHawk StartPosition = FormStartPosition.Manual, Location = this.ChildPointToScreen(TasView) }; - form.ShowDialog(); + form.ShowDialogOnScreen(); } private void SubtitlesMenuItem_Click(object sender, EventArgs e) @@ -952,7 +952,7 @@ namespace BizHawk.Client.EmuHawk StartPosition = FormStartPosition.Manual, Location = this.ChildPointToScreen(TasView) }; - form.ShowDialog(); + form.ShowDialogOnScreen(); } private void DefaultStateSettingsMenuItem_Click(object sender, EventArgs e) @@ -966,7 +966,7 @@ namespace BizHawk.Client.EmuHawk Owner = Owner, Location = this.ChildPointToScreen(TasView) }; - form.ShowDialog(); + form.ShowDialogOnScreen(); } private void SettingsSubMenu_DropDownOpened(object sender, EventArgs e) @@ -1089,7 +1089,7 @@ namespace BizHawk.Client.EmuHawk StartPosition = FormStartPosition.Manual, Location = this.ChildPointToScreen(TasView) }; - form.ShowDialog(); + form.ShowDialogOnScreen(); } private void WheelScrollSpeedMenuItem_Click(object sender, EventArgs e)