Ejemplo n.º 1
0
        /// <summary>
        /// Function to bind the device to a window.
        /// </summary>
        /// <param name="boundWindow">Window to bind with.</param>
        /// <remarks>Passing NULL (Nothing in VB.Net) to <paramref name="boundWindow"/> will use the <see cref="GorgonLibrary.Gorgon.ApplicationForm">main Gorgon Application Form</see>.  If there is no Form bound with the application, then an exception will be thrown.</remarks>
        /// <exception cref="System.ArgumentException">Thrown when the boundWindow parameter and the Gorgon.ApplicationForm property are both NULL (Nothing in VB.Net).
        /// <para>-or-</para>
        /// <para>Thrown when the top level form cannot be determined.</para>
        /// </exception>
        public void Bind(Control boundWindow)
        {
            if (BoundControl != null)
            {
                UnbindWindow();
                BoundControl      = null;
                BoundTopLevelForm = null;
            }

            if (boundWindow == null)
            {
                if (Gorgon.ApplicationForm == null)
                {
                    throw new ArgumentException(Resources.GORINP_NO_WINDOW_TO_BIND, "boundWindow");
                }

                boundWindow = Gorgon.ApplicationForm;
            }

            Gorgon.Log.Print("Binding input device object {1} to window 0x{0}.", LoggingLevel.Intermediate, boundWindow.Handle.FormatHex(), GetType().Name);

            BoundControl      = boundWindow;
            BoundTopLevelForm = Gorgon.GetTopLevelForm(BoundControl);

            if (BoundTopLevelForm == null)
            {
                throw new ArgumentException(Resources.GORINP_NO_WINDOW_TO_BIND, "boundWindow");
            }

            BoundTopLevelForm.Activated  += BoundForm_Activated;
            BoundTopLevelForm.Deactivate += BoundForm_Deactivate;
            BoundControl.LostFocus       += BoundWindow_LostFocus;
            BoundControl.GotFocus        += BoundWindow_GotFocus;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the ParentChanged event of the Window control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void Window_ParentChanged(object sender, EventArgs e)
        {
            try
            {
                // If the actual control has changed parents, update the top level control.
                if (sender == Settings.Window)
                {
                    var newTopLevelParent = Gorgon.GetTopLevelControl(Settings.Window);

                    if (newTopLevelParent != _topLevelControl)
                    {
                        _topLevelControl.ParentChanged -= Window_ParentChanged;

                        // If we're not at the top of the chain, then find out which window is and set it up
                        // to handle changes to its hierarchy.
                        if (newTopLevelParent != Settings.Window)
                        {
                            _topLevelControl = newTopLevelParent;
                            _topLevelControl.ParentChanged += Window_ParentChanged;
                        }
                    }
                }

                if (_parentForm != null)
                {
                    _parentForm.ResizeBegin -= _parentForm_ResizeBegin;
                    _parentForm.ResizeEnd   -= _parentForm_ResizeEnd;
                }

                _parentForm = Gorgon.GetTopLevelForm(Settings.Window);

                if (_parentForm == null)
                {
                    return;
                }

                _parentForm.ResizeBegin += _parentForm_ResizeBegin;
                _parentForm.ResizeEnd   += _parentForm_ResizeEnd;
            }
            catch (Exception ex)
            {
#if DEBUG
                GorgonException.Catch(ex,
                                      () =>
                                      GorgonDialogs.ErrorBox(_parentForm,
                                                             string.Format(Resources.GORGFX_CATASTROPHIC_ERROR, Gorgon.Log.LogPath),
                                                             null,
                                                             ex));

                // If we fail in here, then we have a terminal error in Gorgon, don't risk further corruption.
                Gorgon.Quit();
#else
                GorgonException.Catch(ex);
#endif
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles the Resize event of the Window control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void Window_Resize(object sender, EventArgs e)
        {
            // If we're in a manual resize operation, then don't call this method just yet.
            if (_isInResize)
            {
                return;
            }

            // Attempt to get the parent form if we don't have one yet.
            if (_parentForm == null)
            {
                _parentForm              = Gorgon.GetTopLevelForm(Settings.Window);
                _parentForm.ResizeBegin += _parentForm_ResizeBegin;
                _parentForm.ResizeEnd   += _parentForm_ResizeEnd;
            }

            if ((!AutoResize) || ((_parentForm != null) && (_parentForm.WindowState == FormWindowState.Minimized)))
            {
                return;
            }

            // Only do this if the size has changed, if we're just restoring the window, then don't bother.
            if (((GISwapChain == null)) || (Settings.Window.ClientSize.Width <= 0) || (Settings.Window.ClientSize.Height <= 0))
            {
                return;
            }

            try
            {
                // Resize the video mode.
                Settings.VideoMode = new GorgonVideoMode(Settings.Window.ClientSize.Width,
                                                         Settings.Window.ClientSize.Height,
                                                         Settings.VideoMode.Format,
                                                         Settings.VideoMode.RefreshRateNumerator,
                                                         Settings.VideoMode.RefreshRateDenominator);
                ResizeBuffers();
            }
            catch (Exception ex)
            {
#if DEBUG
                GorgonException.Catch(ex,
                                      () =>
                                      GorgonDialogs.ErrorBox(_parentForm,
                                                             string.Format(Resources.GORGFX_CATASTROPHIC_ERROR, Gorgon.Log.LogPath),
                                                             null,
                                                             ex));

                // If we fail in here, then we have a terminal error in Gorgon, don't risk further corruption.
                Gorgon.Quit();
#else
                // Log the exception.
                GorgonException.Catch(ex);
#endif
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GorgonSwapChain"/> class.
        /// </summary>
        /// <param name="graphics">Graphics interface that owns this swap chain.</param>
        /// <param name="name">The name of the swap chain.</param>
        /// <param name="settings">Settings for the swap chain.</param>
        internal GorgonSwapChain(GorgonGraphics graphics, string name, GorgonSwapChainSettings settings)
            : base(name)
        {
            Graphics = graphics;
            Settings = settings;

            // Get the parent form for our window.
            _parentForm      = Gorgon.GetTopLevelForm(settings.Window);
            _topLevelControl = Gorgon.GetTopLevelControl(settings.Window);
            settings.Window.ParentChanged += Window_ParentChanged;

            if (_topLevelControl != settings.Window)
            {
                _topLevelControl.ParentChanged += Window_ParentChanged;
            }

            AutoResize = true;
        }