Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Context" /> class.
        /// </summary>
        public Context()
        {
            // Create our timer object.
            if (GorgonTimerQpc.SupportsQpc())
            {
                _timer = new GorgonTimerQpc();
            }
            else
            {
                _timer = new GorgonTimerMultimedia();
            }

            // Create the splash screen and the main interface.
            _splashScreen = new formSplash();
            MainForm      = new formMain();                             // Note that we're assign this to the inherited property 'MainForm'.
            // This how the application context knows which form controls the application.

            RunMe();
        }
Example #2
0
        /// <summary>
        /// Function to begin the execution of the application context.
        /// </summary>
        public void RunMe()
        {
            string annoyUser = "******";
            int    counter   = 0;

            try
            {
                _timer.Reset();
                _splashScreen.Show();
                _splashScreen.UpdateText("This is the splash screen.");

                // Fade in the splash screen about 10% every 7 milliseconds.
                while (_splashScreen.Opacity < 1)
                {
                    if (!(_timer.Milliseconds > 7))
                    {
                        continue;
                    }

                    _timer.Reset();
                    _splashScreen.Opacity += 0.01;
                }

                // Annoy the user.  They're asking for it.
                while (counter < 5)
                {
                    while (_timer.Seconds > 1)
                    {
                        if (annoyUser.Length < 50)
                        {
                            annoyUser += ".";
                        }
                        else
                        {
                            annoyUser = "******";
                        }

                        _splashScreen.UpdateText(annoyUser);
                        _timer.Reset();
                        counter++;
                    }
                }

                // Fade it out.
                while (_splashScreen.Opacity > 0.02)
                {
                    if (!(_timer.Milliseconds > 5))
                    {
                        continue;
                    }

                    _timer.Reset();
                    _splashScreen.Opacity -= 0.01;
                }

                // Resize the main form to 640 x 480.
                MainForm.KeyDown    += MainForm_KeyDown;
                MainForm.Deactivate += (sender, args) => GorgonApplication.Log.Print("Application is deactivated. Loops will pause.", LoggingLevel.All);
                MainForm.Activated  += (sender, args) => GorgonApplication.Log.Print("Application is activated. Loops will run.", LoggingLevel.All);
                MainForm.ClientSize  = new Size(640, 480);
                MainForm.Show();
            }
            catch (Exception ex)
            {
                // If we get an error, then leave the application.
                GorgonDialogs.ErrorBox(MainForm, ex);

                MainForm?.Dispose();
                MainForm = null;
            }
            finally
            {
                // We don't need this any more.
                _splashScreen?.Dispose();
                _splashScreen = null;
            }
        }