コード例 #1
0
        /// <summary>Creates a new Corona surface adapter which wraps the given DrawingSurface Xaml control.</summary>
        public DotNetBackgroundSurfaceAdapter()
        {
            // Initialize member variables.
            fPageAdapter             = new UI.DotNetPageAdapter();
            fDispatcher              = new Corona.WinRT.Phone.Interop.UI.DotNetDispatcher();
            fLastReceivedOrientation = Corona.WinRT.Interop.UI.PageOrientation.Unknown;
            fDirect3DSurfaceAdapter  = new Direct3DSurfaceAdapter(this);

            // Add event handlers.
            fPageAdapter.OrientationChanged += OnOrientationChanged;
        }
コード例 #2
0
        /// <summary>
        ///  <para>Called when the page that is hosting the rendering surface has changed orientations.</para>
        ///  <para>Raises a "Resized" event if the orientation has changed from portrait to landscape or vice-versa.</para>
        /// </summary>
        /// <param name="sender">The page that raised this event.</param>
        /// <param name="e">Event arguments providing the new page orientation.</param>
        private void OnOrientationChanged(
            Corona.WinRT.Interop.UI.IPage sender, Corona.WinRT.Interop.UI.PageOrientationEventArgs e)
        {
            // Do not continue if the orientation has not changed.
            // Note: This can happen if this adapter was once given a different page reference.
            if (fLastReceivedOrientation == e.Orientation)
            {
                return;
            }

            // Raise a "Resized" event if the orientation has changed from portrait to landscape or vice-versa.
            // This is because this adapter provides the surface width and height relative to the app's orientation.
            bool wasResized =
                (fLastReceivedOrientation == Corona.WinRT.Interop.UI.PageOrientation.Unknown) ||
                (e.Orientation == Corona.WinRT.Interop.UI.PageOrientation.Unknown) ||
                (fLastReceivedOrientation.IsLandscape != e.Orientation.IsLandscape);

            fLastReceivedOrientation = e.Orientation;
            if (wasResized && (this.Resized != null))
            {
                this.Resized(this, CoronaLabs.WinRT.EmptyEventArgs.Instance);
            }
        }