Ejemplo n.º 1
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.º 2
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;
        }