Skip to content

Commit

Permalink
Add helper for centering dialog relative to a Control
Browse files Browse the repository at this point in the history
  • Loading branch information
YoshiRulz committed Nov 28, 2024
1 parent a39689d commit c9df57b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 15 deletions.
15 changes: 15 additions & 0 deletions src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -131,6 +143,9 @@ public static T Clone<T>(this T controlToClone)
public static IEnumerable<Control> Controls(this Control control)
=> control.Controls.Cast<Control>();

public static Size HalfSize(this Control c)
=> new(c.Width / 2, c.Height / 2);

public static IEnumerable<TabPage> TabPages(this TabControl tabControl)
{
return tabControl.TabPages.Cast<TabPage>();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit c9df57b

Please sign in to comment.