public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
        {
            var requestedOrientation  = OrientationConverter.ToDisplayOrientation(toInterfaceOrientation);
            var supportedOrientations = (_gameViewController as iOSGameViewController).SupportedOrientations;

            return((supportedOrientations & requestedOrientation) != 0);
        }
Exemplo n.º 2
0
        public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
        {
            DisplayOrientation supportedOrientations = OrientationConverter.Normalize(SupportedOrientations);
            var toOrientation = OrientationConverter.ToDisplayOrientation(toInterfaceOrientation);

            return((toOrientation & supportedOrientations) == toOrientation);
        }
Exemplo n.º 3
0
        private void ViewController_InterfaceOrientationChanged(object sender, EventArgs e)
        {
            var orientation = OrientationConverter.ToDisplayOrientation(
                _viewController.InterfaceOrientation);

            // FIXME: The presentation parameters for the GraphicsDevice should
            //        be managed by the GraphicsDevice itself.  Not by
            //        iOSGamePlatform.
            var gdm = (GraphicsDeviceManager)Game.Services.GetService(typeof(IGraphicsDeviceManager));

            TouchPanel.DisplayOrientation = orientation;

            if (gdm != null)
            {
                var presentParams = gdm.GraphicsDevice.PresentationParameters;
                presentParams.BackBufferWidth  = gdm.PreferredBackBufferWidth;
                presentParams.BackBufferHeight = gdm.PreferredBackBufferHeight;

                presentParams.DisplayOrientation = orientation;

                // Recalculate our views.
                ViewController.View.LayoutSubviews();

                gdm.ApplyChanges();
            }
        }
Exemplo n.º 4
0
        public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
        {
            DisplayOrientation supportedOrientations;

            if (SupportedOrientations == DisplayOrientation.Default)
            {
                supportedOrientations = GetDefaultSupportedOrientations();
            }
            else
            {
                supportedOrientations = OrientationConverter.Normalize(SupportedOrientations);
            }
            var toOrientation = OrientationConverter.ToDisplayOrientation(toInterfaceOrientation);

            return((toOrientation & supportedOrientations) == toOrientation);
        }
        public override UIInterfaceOrientation PreferredInterfaceOrientationForPresentation()
        {
            DisplayOrientation supportedOrientations = OrientationConverter.Normalize(SupportedOrientations);

            if ((supportedOrientations & DisplayOrientation.LandscapeRight) != 0)
            {
                return(UIInterfaceOrientation.LandscapeRight);
            }
            else if ((supportedOrientations & DisplayOrientation.LandscapeLeft) != 0)
            {
                return(UIInterfaceOrientation.LandscapeLeft);
            }
            else
            {
                return(UIInterfaceOrientation.Portrait);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Gets the default supported orientations as specified in the
        /// Info.plist for the application.
        /// </summary>
        private DisplayOrientation GetDefaultSupportedOrientations()
        {
            if (_defaultSupportedOrientations.HasValue)
            {
                return(_defaultSupportedOrientations.Value);
            }

            var      key = new NSString("UISupportedInterfaceOrientations");
            NSObject arrayObj;

            if (!NSBundle.MainBundle.InfoDictionary.TryGetValue(key, out arrayObj))
            {
                _defaultSupportedOrientations = OrientationConverter.Normalize(DisplayOrientation.Default);
                return(_defaultSupportedOrientations.Value);
            }

            DisplayOrientation orientations = (DisplayOrientation)0;
            var supportedOrientationStrings = NSArray.ArrayFromHandle <NSString> (arrayObj.Handle);

            foreach (var orientationString in supportedOrientationStrings)
            {
                var s = (string)orientationString;
                if (!s.StartsWith("UIInterfaceOrientation"))
                {
                    continue;
                }
                s = s.Substring("UIInterfaceOrientation".Length);

                try {
                    var supportedOrientation = (UIInterfaceOrientation)Enum.Parse(
                        typeof(UIInterfaceOrientation), s);
                    orientations |= OrientationConverter.ToDisplayOrientation(supportedOrientation);
                } catch {
                }
            }

            if (orientations == (DisplayOrientation)0)
            {
                orientations = OrientationConverter.Normalize(DisplayOrientation.Default);
            }

            _defaultSupportedOrientations = orientations;
            return(_defaultSupportedOrientations.Value);
        }
 public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
 {
     return(OrientationConverter.ToUIInterfaceOrientationMask((_gameViewController as iOSGameViewController).SupportedOrientations));
 }
Exemplo n.º 8
0
 public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations()
 {
     return(OrientationConverter.ToUIInterfaceOrientationMask(this.SupportedOrientations));
 }
Exemplo n.º 9
0
        private void CreateFramebuffer()
        {
            AssertNotDisposed();
            AssertValidContext();

            if (PreserveFrameBuffer)
            {
                return;
            }

            __renderbuffergraphicsContext.MakeCurrent(null);

            // HACK:  GraphicsDevice itself should be calling
            //        glViewport, so we shouldn't need to do it
            //        here and then force the state into
            //        GraphicsDevice.  However, that change is a
            //        ways off, yet.
            int unscaledViewportHeight = (int)Math.Round(Layer.Bounds.Size.Height);
            int unscaledViewportWidth  = (int)Math.Round(Layer.Bounds.Size.Width);

            int previousRenderbuffer = 0;

            _glapi.GetInteger(All.RenderbufferBinding, ref previousRenderbuffer);

            _glapi.GenFramebuffers(1, ref _framebuffer);
            _glapi.BindFramebuffer(All.Framebuffer, _framebuffer);

            // Create our Depth buffer. Color buffer must be the last one bound
            GL.GenRenderbuffers(1, ref _depthbuffer);
            GL.BindRenderbuffer(All.Renderbuffer, _depthbuffer);
            GL.RenderbufferStorage(All.Renderbuffer, All.DepthComponent16, unscaledViewportWidth * (int)Layer.ContentsScale, unscaledViewportHeight * (int)Layer.ContentsScale);

            GL.FramebufferRenderbuffer(All.Framebuffer, All.DepthAttachment, All.Renderbuffer, _depthbuffer);

            _glapi.GenRenderbuffers(2, ref _colorbuffer);
            _glapi.BindRenderbuffer(All.Renderbuffer, _colorbuffer);

            var ctx = ((IGraphicsContextInternal)__renderbuffergraphicsContext).Implementation as iPhoneOSGraphicsContext;

            // TODO: EAGLContext.RenderBufferStorage returns false
            //       on all but the first call.  Nevertheless, it
            //       works.  Still, it would be nice to know why it
            //       claims to have failed.
            ctx.EAGLContext.RenderBufferStorage((uint)All.Renderbuffer, Layer);

            _glapi.FramebufferRenderbuffer(All.Framebuffer, All.ColorAttachment0, All.Renderbuffer, _colorbuffer);

            var status = GL.CheckFramebufferStatus(All.Framebuffer);

            if (status != All.FramebufferComplete)
            {
                throw new InvalidOperationException(
                          "Framebuffer was not created correctly: " + status);
            }

            _glapi.Viewport(0, 0, unscaledViewportWidth, unscaledViewportHeight);
            _glapi.Scissor(0, 0, unscaledViewportWidth, unscaledViewportHeight);

            var gds = (IGraphicsDeviceService)_platform.Game.Services.GetService(
                typeof(IGraphicsDeviceService));

            if (gds != null && gds.GraphicsDevice != null)
            {
                var pp     = gds.GraphicsDevice.PresentationParameters;
                int height = (int)(unscaledViewportHeight * Layer.ContentsScale);
                int width  = (int)(unscaledViewportWidth * Layer.ContentsScale);

                if (this.NextResponder is iOSGameViewController)
                {
                    DisplayOrientation supportedOrientations = OrientationConverter.Normalize((this.NextResponder as iOSGameViewController).SupportedOrientations);
                    if ((supportedOrientations & DisplayOrientation.LandscapeRight) != 0 || (supportedOrientations & DisplayOrientation.LandscapeLeft) != 0)
                    {
                        height = (int)(Math.Min(unscaledViewportHeight, unscaledViewportWidth) * Layer.ContentsScale);
                        width  = (int)(Math.Max(unscaledViewportHeight, unscaledViewportWidth) * Layer.ContentsScale);
                    }
                    else
                    {
                        height = (int)(Math.Max(unscaledViewportHeight, unscaledViewportWidth) * Layer.ContentsScale);
                        width  = (int)(Math.Min(unscaledViewportHeight, unscaledViewportWidth) * Layer.ContentsScale);
                    }
                }

                pp.BackBufferHeight = height;
                pp.BackBufferWidth  = width;

                gds.GraphicsDevice.Viewport = new Viewport(
                    0, 0,
                    pp.BackBufferWidth,
                    pp.BackBufferHeight);

                // FIXME: These static methods on GraphicsDevice need
                //        to go away someday.
                gds.GraphicsDevice.glFramebuffer = _framebuffer;
            }

            if (Threading.BackgroundContext == null)
            {
                Threading.BackgroundContext = new MonoTouch.OpenGLES.EAGLContext(ctx.EAGLContext.API, ctx.EAGLContext.ShareGroup);
            }
        }