diff --git a/DisplayMagician/Program.cs b/DisplayMagician/Program.cs index e470e41..40aa22e 100644 --- a/DisplayMagician/Program.cs +++ b/DisplayMagician/Program.cs @@ -43,6 +43,7 @@ namespace DisplayMagician { public static ProgramSettings AppProgramSettings; public static MainForm AppMainForm; public static LoadingForm AppSplashScreen; + public static ShortcutLoadingForm AppShortcutLoadingSplashScreen; private static readonly NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); private static SharedLogger sharedLogger; private static bool _gamesLoaded = false; diff --git a/DisplayMagician/Properties/AssemblyInfo.cs b/DisplayMagician/Properties/AssemblyInfo.cs index 4ca6e5e..aa4ef86 100644 --- a/DisplayMagician/Properties/AssemblyInfo.cs +++ b/DisplayMagician/Properties/AssemblyInfo.cs @@ -26,8 +26,8 @@ using System.Resources; [assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")] // Version information -[assembly: AssemblyVersion("2.1.0.317")] -[assembly: AssemblyFileVersion("2.1.0.317")] +[assembly: AssemblyVersion("2.1.0.358")] +[assembly: AssemblyFileVersion("2.1.0.358")] [assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: CLSCompliant(true)] diff --git a/DisplayMagician/UIForms/ShortcutForm.cs b/DisplayMagician/UIForms/ShortcutForm.cs index 0a2c645..2d264f5 100644 --- a/DisplayMagician/UIForms/ShortcutForm.cs +++ b/DisplayMagician/UIForms/ShortcutForm.cs @@ -69,16 +69,6 @@ namespace DisplayMagician.UIForms public ShortcutForm() { InitializeComponent(); - _loadingScreen = new ShortcutLoadingForm(); - _loadingScreen.Title = "Preparing images..."; - _loadingScreen.Description = "Preparing images before showing you the Shortcut information. You will be able to swap your shortcut icon to any image you want, or choose one from a list."; - _loadingScreen.StartPosition = FormStartPosition.CenterParent; - _loadingScreen.Parent = this.ParentForm; - var splashThread = new Thread(new ThreadStart( - () => Application.Run(_loadingScreen))); - splashThread.SetApartmentState(ApartmentState.STA); - splashThread.Start(); - // Set the profileAdaptor we need to load images from Profiles // into the Profiles ImageListView try @@ -1701,7 +1691,8 @@ namespace DisplayMagician.UIForms } private void ShortcutForm_Load(object sender, EventArgs e) - { + { + if (_firstShow) { // Parse the game bitmaps now the first time as we need them @@ -1711,24 +1702,20 @@ namespace DisplayMagician.UIForms GameLibraries.GameLibrary.RefreshGameBitmaps(); } - // Close the splash screen - CloseTheSplashScreen(); _firstShow = false; } // Load the shortcut info LoadShortcut(); - + CloseTheSplashScreen(); } private void CloseTheSplashScreen() { // Close the splash screen - if (_loadingScreen != null && !_loadingScreen.Disposing && !_loadingScreen.IsDisposed) - _loadingScreen.Invoke(new Action(() => _loadingScreen.Close())); - this.TopMost = true; - this.Focus(); - this.TopMost = false; + if (Program.AppShortcutLoadingSplashScreen != null && !Program.AppShortcutLoadingSplashScreen.Disposing && !Program.AppShortcutLoadingSplashScreen.IsDisposed) + Program.AppShortcutLoadingSplashScreen.Invoke(new Action(() => Program.AppShortcutLoadingSplashScreen.Close())); + this.Activate(); } private void rb_standalone_CheckedChanged(object sender, EventArgs e) diff --git a/DisplayMagician/UIForms/ShortcutLibraryForm.cs b/DisplayMagician/UIForms/ShortcutLibraryForm.cs index 7f7e952..cc6ff9b 100644 --- a/DisplayMagician/UIForms/ShortcutLibraryForm.cs +++ b/DisplayMagician/UIForms/ShortcutLibraryForm.cs @@ -10,6 +10,7 @@ using System.Drawing; using System.Globalization; using System.IO; using System.Linq; +using System.Threading; using System.Windows.Forms; namespace DisplayMagician.UIForms @@ -266,14 +267,16 @@ namespace DisplayMagician.UIForms { this.Cursor = Cursors.WaitCursor; ShortcutItem si = new ShortcutItem(); + ShowShortcutLoadingWindow(); if (_shortcutForm == null) { _shortcutForm = new ShortcutForm(); } + _shortcutForm.Owner = this; //ShortcutRepository.IsValidRefresh() // Set the Shortcut to as a new shortcut _shortcutForm.Shortcut = si; - _shortcutForm.EditingExistingShortcut = false; + _shortcutForm.EditingExistingShortcut = false; _shortcutForm.ShowDialog(this); if (_shortcutForm.DialogResult == DialogResult.OK) { @@ -292,6 +295,22 @@ namespace DisplayMagician.UIForms } } + private void ShowShortcutLoadingWindow() + { + Program.AppShortcutLoadingSplashScreen = new ShortcutLoadingForm(); + Program.AppShortcutLoadingSplashScreen.Title = "Preparing images..."; + Program.AppShortcutLoadingSplashScreen.Description = "Preparing images before showing you the Shortcut information. You will be able to swap your shortcut icon to any image you want, or choose one from a list."; + int resultX = this.DesktopLocation.X + ((this.Width - Program.AppShortcutLoadingSplashScreen.Width) / 2); + int resultY = this.DesktopLocation.Y + ((this.Height - Program.AppShortcutLoadingSplashScreen.Height) / 2); + Program.AppShortcutLoadingSplashScreen.WantedLocation = new Point(resultX, resultY); + //_loadingScreen.CenterParent(ownerRect); + //_loadingScreen.StartPosition = FormStartPosition.Manual; + var splashThread = new Thread(new ThreadStart( + () => Application.Run(Program.AppShortcutLoadingSplashScreen))); + splashThread.SetApartmentState(ApartmentState.STA); + splashThread.Start(); + } + private void btn_edit_Click(object sender, EventArgs e) { if (_selectedShortcut == null) @@ -320,11 +339,12 @@ namespace DisplayMagician.UIForms _selectedShortcut = GetShortcutFromUUID(shortcutUUID); this.Cursor = Cursors.WaitCursor; - + ShowShortcutLoadingWindow(); if (_shortcutForm == null) { _shortcutForm = new ShortcutForm(); } + _shortcutForm.Owner = this; _shortcutForm.Shortcut = _selectedShortcut; _shortcutForm.EditingExistingShortcut = true; //ilv_saved_shortcuts.SuspendLayout(); diff --git a/DisplayMagician/UIForms/ShortcutLoadingForm.Designer.cs b/DisplayMagician/UIForms/ShortcutLoadingForm.Designer.cs index 737b98c..87e95ad 100644 --- a/DisplayMagician/UIForms/ShortcutLoadingForm.Designer.cs +++ b/DisplayMagician/UIForms/ShortcutLoadingForm.Designer.cs @@ -83,6 +83,7 @@ namespace DisplayMagician.UIForms this.Text = "DisplayMagician is loading...."; this.UseWaitCursor = true; this.Load += new System.EventHandler(this.LoadingForm_Load); + this.Shown += new System.EventHandler(this.ShortcutLoadingForm_Shown); this.ResumeLayout(false); } diff --git a/DisplayMagician/UIForms/ShortcutLoadingForm.cs b/DisplayMagician/UIForms/ShortcutLoadingForm.cs index c73e206..1c706c0 100644 --- a/DisplayMagician/UIForms/ShortcutLoadingForm.cs +++ b/DisplayMagician/UIForms/ShortcutLoadingForm.cs @@ -14,11 +14,17 @@ namespace DisplayMagician.UIForms { private string _title = "DisplayMagician is loading..."; private string _description = "If you have installed a lot of games over time or have a lot of games installed now, this may take a while!"; + private Point _wantedLocation = new Point(0,0); public ShortcutLoadingForm() { InitializeComponent(); - this.TopMost = false; + this.StartPosition = FormStartPosition.Manual; + /*_owner = owner; + int resultX = _owner.DisplayRectangle.X + _owner.Width - this.Width; + int resultY = _owner.DisplayRectangle.Y + _owner.Height - this.Height; + _owner.Location = new Point(resultX, resultY);*/ + this.TopMost = true; } @@ -49,10 +55,22 @@ namespace DisplayMagician.UIForms } } + public Point WantedLocation + { + set + { + _wantedLocation = value; + } + } private void LoadingForm_Load(object sender, EventArgs e) { + DesktopLocation = _wantedLocation; + } + private void ShortcutLoadingForm_Shown(object sender, EventArgs e) + { + DesktopLocation = _wantedLocation; } } } diff --git a/DisplayMagician/Utils.cs b/DisplayMagician/Utils.cs index 5c2c713..01366e5 100644 --- a/DisplayMagician/Utils.cs +++ b/DisplayMagician/Utils.cs @@ -1,9 +1,11 @@ using System; +using System.Drawing; using System.Runtime.InteropServices; +using System.Windows.Forms; namespace DisplayMagician { - class Utils + static class Utils { // 1. Import InteropServices @@ -51,7 +53,35 @@ namespace DisplayMagician Marshal.FreeCoTaskMem(pathPtr); } } - + + public static void ShowCentered(this Form frm, Form owner) + { + Rectangle ownerRect = GetOwnerRect(frm, owner); + frm.Location = new Point(ownerRect.Left + (ownerRect.Width - frm.Width) / 2, + ownerRect.Top + (ownerRect.Height - frm.Height) / 2); + frm.Show(owner); + } + + public static void CenterParent(this Form frm, Rectangle ownerRect) + { + frm.Location = new Point(ownerRect.Left + (ownerRect.Width - frm.Width) / 2, + ownerRect.Top + (ownerRect.Height - frm.Height) / 2); + } + + public static void ShowDialogCentered(this Form frm, Form owner) + { + Rectangle ownerRect = GetOwnerRect(frm, owner); + frm.Location = new Point(ownerRect.Left + (ownerRect.Width - frm.Width) / 2, + ownerRect.Top + (ownerRect.Height - frm.Height) / 2); + frm.ShowDialog(owner); + } + + private static Rectangle GetOwnerRect(Form frm, Form owner) + { + return owner != null ? owner.DesktopBounds : Screen.GetWorkingArea(frm); + } + + }