Add helper for centering dialog relative to a `Control`
This commit is contained in:
parent
a39689d62d
commit
c3bd723c36
|
@ -74,6 +74,18 @@ namespace BizHawk.Client.EmuHawk
|
|||
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 @@ namespace BizHawk.Client.EmuHawk
|
|||
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>();
|
||||
|
|
|
@ -92,7 +92,7 @@
|
|||
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);
|
||||
|
|
|
@ -207,7 +207,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
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);
|
||||
|
|
|
@ -953,24 +953,23 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
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 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue