コード例 #1
0
ファイル: SysInputFactory.cs プロジェクト: zhangxin8105/LGame
        public virtual void CallKey(KeyMake.KeyEvent e)
        {
            LProcess process = LSystem.GetProcess();

            if (process != null)
            {
                if (e.down)
                {
                    finalKey.timer   = e.time;
                    finalKey.keyChar = e.keyChar;
                    finalKey.keyCode = e.keyCode;
                    finalKey.type    = SysKey.DOWN;
                    SysKey.only_key.Press();
                    SysKey.AddKey(finalKey.keyCode);
                    process.KeyDown(finalKey);
                }
                else
                {
                    finalKey.timer = e.time;
                    //finalKey.keyChar = e.keyChar;
                    //finalKey.keyCode = e.keyCode;
                    finalKey.type = SysKey.UP;
                    SysKey.RemoveKey(finalKey.keyCode);
                    process.KeyUp(finalKey);
                }
            }
        }
コード例 #2
0
ファイル: LSilverlightPlus.cs プロジェクト: vb0067/LGame
 /// <summary>
 /// 调用XNA资源卸载函数(禁止重载)
 /// </summary>
 public void OnNavigatedFrom(NavigationEventArgs e)
 {
     if (process != null)
     {
         process.End();
         process.OnDestroy();
     }
     if (useXNAListener)
     {
         sl_listener.UnloadContent(GamePage);
     }
     XNA_UnloadContent();
     TargetElapsedTime.Stop();
     try
     {
         SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(false);
         this.Destory();
     }
     catch
     {
     }
     if (process != null)
     {
         process = null;
     }
 }
コード例 #3
0
        public static void ClearDrawing()
        {
            LProcess process = LSystem.screenProcess;

            if (process != null)
            {
                process.RemoveAllDrawing();
            }
        }
コード例 #4
0
        public static void Drawing(Drawable d)
        {
            LProcess process = LSystem.screenProcess;

            if (process != null)
            {
                process.AddDrawing(d);
            }
        }
コード例 #5
0
        public static void Unload(Updateable u)
        {
            LProcess process = LSystem.screenProcess;

            if (process != null)
            {
                process.AddUnLoad(u);
            }
        }
コード例 #6
0
ファイル: LGameXNA2DActivity.cs プロジェクト: nobcdz/LGame
 public override void InitApp(XNAContext context, GL gl)
 {
     if (m_process == null)
     {
         m_process = new LProcess(this, context._width, context._height);
     }
     m_process.Load(gl);
     Printf("initApp");
 }
コード例 #7
0
ファイル: SysInputFactory.cs プロジェクト: zhangxin8105/LGame
        protected internal virtual void Update()
        {
            LProcess process = LSystem.GetProcess();

            if (process != null)
            {
                this._halfWidth  = process.GetWidth() / 2;
                this._halfHeight = process.GetHeight() / 2;
            }
            else if (LSystem.viewSize != null)
            {
                this._halfWidth  = LSystem.viewSize.GetWidth() / 2;
                this._halfHeight = LSystem.viewSize.GetHeight() / 2;
            }
        }
コード例 #8
0
        public static void CallScreenRunnable(Runnable runnable)
        {
            LProcess process = LSystem.screenProcess;

            if (process != null)
            {
                Screen screen = process.GetScreen();
                if (screen != null)
                {
                    lock (screen)
                    {
                        screen.CallEvent(runnable);
                    }
                }
            }
        }
コード例 #9
0
ファイル: LGameXNA2DActivity.cs プロジェクト: nobcdz/LGame
 public override void CreateApp(GL gl, int width, int height)
 {
     if (LSystem.screenRect != null)
     {
         LSystem.screenRect.SetBounds(0, 0, width, height);
     }
     else
     {
         LSystem.screenRect = new RectBox(0, 0, width, height);
     }
     if (m_process == null)
     {
         m_process = new LProcess(this, width, height);
     }
     m_process.Load(gl);
     LSystem.screenProcess = m_process;
 }
コード例 #10
0
ファイル: SysInputFactory.cs プロジェクト: zhangxin8105/LGame
        public virtual void CallTouch(TouchMake.Event[] events)
        {
            if (LSystem.IsLockAllTouchEvent())
            {
                return;
            }
            LProcess process = LSystem.GetProcess();

            if (process == null)
            {
                return;
            }

            bool stopMoveDrag = LSystem.IsNotAllowDragAndMove();

            int size = events.Length;

            ebuttons = process.GetEmulatorButtons();

            for (int i = 0; i < size; i++)
            {
                TouchMake.Event e      = events[i];
                Vector2f        pos    = process.ConvertXY(e.x, e.y);
                float           touchX = pos.x;
                float           touchY = pos.y;

                finalTouch.isDraging = _isDraging;
                finalTouch.x         = touchX;
                finalTouch.y         = touchY;
                finalTouch.pointer   = i;
                finalTouch.id        = e.id;

                switch (e.kind.innerEnumValue)
                {
                case TouchMake.Event.Kind.InnerEnum.START:
                    if (useTouchCollection)
                    {
                        touchCollection.Add(finalTouch.id, finalTouch.x, finalTouch.y);
                    }
                    _offsetTouchX = touchX;
                    _offsetTouchY = touchY;
                    if ((touchX < _halfWidth) && (touchY < _halfHeight))
                    {
                        finalTouch.type = SysTouch.UPPER_LEFT;
                    }
                    else if ((touchX >= _halfWidth) && (touchY < _halfHeight))
                    {
                        finalTouch.type = SysTouch.UPPER_RIGHT;
                    }
                    else if ((touchX < _halfWidth) && (touchY >= _halfHeight))
                    {
                        finalTouch.type = SysTouch.LOWER_LEFT;
                    }
                    else
                    {
                        finalTouch.type = SysTouch.LOWER_RIGHT;
                    }
                    finalTouch.duration = 0;
                    finalTouch.button   = SysTouch.TOUCH_DOWN;
                    finalTouch.timeDown = TimeUtils.Millis();
                    process.MousePressed(finalTouch);
                    _isDraging = false;

                    /*if (ebuttons != null && ebuttons.Visible)
                     * {
                     *      ebuttons.hit(i, touchX, touchY, false);
                     * }*/
                    break;

                case TouchMake.Event.Kind.InnerEnum.MOVE:
                    _offsetMoveX        = touchX;
                    _offsetMoveY        = touchY;
                    finalTouch.dx       = _offsetTouchX - _offsetMoveX;
                    finalTouch.dy       = _offsetTouchY - _offsetMoveY;
                    finalTouch.duration = TimeUtils.Millis() - finalTouch.timeDown;
                    if (MathUtils.Abs(finalTouch.dx) > 0.1f || MathUtils.Abs(finalTouch.dy) > 0.1f)
                    {
                        if (useTouchCollection)
                        {
                            touchCollection.Update(finalTouch.id, LTouchLocationState.Dragged, finalTouch.x, finalTouch.y);
                        }
                        if (!stopMoveDrag)
                        {
                            process.MouseMoved(finalTouch);
                        }
                        if (!stopMoveDrag)
                        {
                            process.MouseDragged(finalTouch);
                        }
                        _isDraging = true;
                    }
                    ebuttons = process.GetEmulatorButtons();

                    /*if (ebuttons != null && ebuttons.Visible)
                     * {
                     *      ebuttons.hit(i, touchX, touchY, false);
                     * }*/
                    break;

                case TouchMake.Event.Kind.InnerEnum.END:
                    if (useTouchCollection)
                    {
                        touchCollection.Update(finalTouch.id, LTouchLocationState.Released, finalTouch.x, finalTouch.y);
                    }
                    if (finalTouch.button == SysTouch.TOUCH_DOWN || finalTouch.button == SysTouch.TOUCH_MOVE)
                    {
                        finalTouch.button = SysTouch.TOUCH_UP;
                    }
                    finalTouch.timeUp   = TimeUtils.Millis();
                    finalTouch.duration = finalTouch.timeUp - finalTouch.timeDown;
                    process.MouseReleased(finalTouch);
                    _isDraging = false;

                    /*if (ebuttons != null && ebuttons.Visible)
                     * {
                     *      ebuttons.unhit(i, touchX, touchY);
                     * }*/
                    break;

                case TouchMake.Event.Kind.InnerEnum.CANCEL:
                default:
                    if (finalTouch.button == SysTouch.TOUCH_DOWN || finalTouch.button == SysTouch.TOUCH_MOVE)
                    {
                        finalTouch.button = SysTouch.TOUCH_UP;
                    }
                    finalTouch.duration = 0;
                    if (useTouchCollection)
                    {
                        touchCollection.Update(finalTouch.id, LTouchLocationState.Invalid, finalTouch.x, finalTouch.y);
                    }

                    /*if (ebuttons != null && ebuttons.Visible)
                     * {
                     *      ebuttons.release();
                     * }*/
                    break;
                }
            }
        }
コード例 #11
0
ファイル: SysInputFactory.cs プロジェクト: zhangxin8105/LGame
        public virtual void CallMouse(MouseMake.ButtonEvent e)
        {
            if (LSystem.IsLockAllTouchEvent())
            {
                return;
            }
            LProcess process = LSystem.GetProcess();

            if (process == null)
            {
                return;
            }
            bool stopMoveDrag = LSystem.IsNotAllowDragAndMove();

            Vector2f pos = process.ConvertXY(e.x, e.y);

            float touchX = pos.x;

            float touchY = pos.y;

            int button = e.button;

            finalTouch.isDraging = _isDraging;
            finalTouch.x         = touchX;
            finalTouch.y         = touchY;
            finalTouch.button    = e.button;
            finalTouch.pointer   = 0;
            finalTouch.id        = 0;
            ebuttons             = process.GetEmulatorButtons();
            if (button == -1)
            {
                if (buttons > 0)
                {
                    finalTouch.type = SysTouch.TOUCH_DRAG;
                }
                else
                {
                    finalTouch.type = SysTouch.TOUCH_MOVE;
                }
            }
            else
            {
                if (e.down)
                {
                    finalTouch.type = SysTouch.TOUCH_DOWN;
                }
                else
                {
                    if (finalTouch.type == SysTouch.TOUCH_DOWN || finalTouch.type == SysTouch.TOUCH_DRAG)
                    {
                        finalTouch.type = SysTouch.TOUCH_UP;
                    }
                }
            }

            switch (finalTouch.type)
            {
            case SysTouch.TOUCH_DOWN:
                finalTouch.button   = SysTouch.TOUCH_DOWN;
                finalTouch.duration = 0;
                finalTouch.timeDown = TimeUtils.Millis();
                if (useTouchCollection)
                {
                    touchCollection.Add(finalTouch.id, finalTouch.x, finalTouch.y);
                }
                process.MousePressed(finalTouch);
                buttons++;
                _isDraging = false;

                /*if (ebuttons != null && ebuttons.Visible)
                 * {
                 *      ebuttons.hit(0, touchX, touchY, false);
                 * }*/
                break;

            case SysTouch.TOUCH_UP:
                finalTouch.button   = SysTouch.TOUCH_UP;
                finalTouch.timeUp   = TimeUtils.Millis();
                finalTouch.duration = finalTouch.timeUp - finalTouch.timeDown;
                if (useTouchCollection)
                {
                    touchCollection.Update(finalTouch.id, LTouchLocationState.Released, finalTouch.x, finalTouch.y);
                }
                process.MouseReleased(finalTouch);
                buttons    = 0;
                _isDraging = false;

                /*if (ebuttons != null && ebuttons.Visible)
                 * {
                 *      ebuttons.unhit(0, touchX, touchY);
                 * }*/
                break;

            case SysTouch.TOUCH_MOVE:
                _offsetMoveX        = touchX;
                _offsetMoveY        = touchY;
                finalTouch.dx       = _offsetTouchX - _offsetMoveX;
                finalTouch.dy       = _offsetTouchY - _offsetMoveY;
                finalTouch.button   = SysTouch.TOUCH_MOVE;
                finalTouch.duration = TimeUtils.Millis() - finalTouch.timeDown;
                if (!_isDraging)
                {
                    if (useTouchCollection)
                    {
                        touchCollection.Update(finalTouch.id, LTouchLocationState.Dragged, finalTouch.x, finalTouch.y);
                    }
                    if (!stopMoveDrag)
                    {
                        process.MouseMoved(finalTouch);
                    }
                }

                /*if (ebuttons != null && ebuttons.Visible)
                 * {
                 *      ebuttons.unhit(0, touchX, touchY);
                 * }*/
                break;

            case SysTouch.TOUCH_DRAG:
                _offsetMoveX        = touchX;
                _offsetMoveY        = touchY;
                finalTouch.dx       = _offsetTouchX - _offsetMoveX;
                finalTouch.dy       = _offsetTouchY - _offsetMoveY;
                finalTouch.button   = SysTouch.TOUCH_DRAG;
                finalTouch.duration = TimeUtils.Millis() - finalTouch.timeDown;
                ebuttons            = process.GetEmulatorButtons();

                /*if (ebuttons != null && ebuttons.Visible)
                 * {
                 *      ebuttons.hit(0, touchX, touchY, true);
                 * }*/
                if (useTouchCollection)
                {
                    touchCollection.Update(finalTouch.id, LTouchLocationState.Dragged, finalTouch.x, finalTouch.y);
                }
                if (!stopMoveDrag)
                {
                    process.MouseDragged(finalTouch);
                }

                /*if (ebuttons != null && ebuttons.Visible)
                 * {
                 *      ebuttons.hit(0, touchX, touchY, false);
                 * }*/
                _isDraging = true;
                break;

            default:
                finalTouch.duration = 0;
                if (useTouchCollection)
                {
                    touchCollection.Update(finalTouch.id, LTouchLocationState.Invalid, finalTouch.x, finalTouch.y);
                }

                /*if (ebuttons != null && ebuttons.Visible)
                 * {
                 *      ebuttons.release();
                 * }*/
                break;
            }
        }
コード例 #12
0
        public void Initialization(bool l,
                                   bool f, LMode m)
        {
            log.I("GPU surface");

            this.landscape  = l;
            this.fullScreen = f;
            this.mode       = m;

            if (landscape == false)
            {
                if (LSystem.MAX_SCREEN_HEIGHT > LSystem.MAX_SCREEN_WIDTH)
                {
                    int tmp_height = LSystem.MAX_SCREEN_HEIGHT;
                    LSystem.MAX_SCREEN_HEIGHT = LSystem.MAX_SCREEN_WIDTH;
                    LSystem.MAX_SCREEN_WIDTH  = tmp_height;
                }
            }

            this.CheckDisplayMode();

            RectBox d = GetScreenDimension();

            LSystem.SCREEN_LANDSCAPE = landscape;

            this.maxWidth  = (int)d.GetWidth();
            this.maxHeight = (int)d.GetHeight();

            if (landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }

            if (mode != LMode.Max)
            {
                if (landscape)
                {
                    this.width  = LSystem.MAX_SCREEN_WIDTH;
                    this.height = LSystem.MAX_SCREEN_HEIGHT;
                }
                else
                {
                    this.width  = LSystem.MAX_SCREEN_HEIGHT;
                    this.height = LSystem.MAX_SCREEN_WIDTH;
                }
            }
            else
            {
                if (landscape)
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxHeight;
                }
                else
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxHeight;
                }
            }

            if (mode == LMode.Fill)
            {
                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.FitFill)
            {
                RectBox res = GraphicsUtils.FitLimitSize(width, height,
                                                         maxWidth, maxHeight);
                maxWidth            = res.width;
                maxHeight           = res.height;
                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.Ratio)
            {
                maxWidth  = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.MaxRatio)
            {
                maxWidth  = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if ((realAspect < 1 && userAspect > 1) ||
                    (realAspect > 1 && userAspect < 1))
                {
                    userAspect = (float)height / (float)width;
                }

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else
            {
                LSystem.scaleWidth  = 1;
                LSystem.scaleHeight = 1;
            }

            LSystem.screenRect = new RectBox(0, 0, width, height);

            graphics.PreferredBackBufferFormat = displayMode.Format;
            graphics.PreferredBackBufferWidth  = maxWidth;
            graphics.PreferredBackBufferHeight = maxHeight;

            if (landscape)
            {
                graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
            }
            else
            {
                graphics.SupportedOrientations = DisplayOrientation.Portrait;
            }

            //画面渲染与显示器同步
            graphics.SynchronizeWithVerticalRetrace = true;
            graphics.PreferMultiSampling            = true;


#if WINDOWS
            graphics.IsFullScreen = false;
            IsMouseVisible        = true;
#elif XBOX || WINDOWS_PHONE
            //全屏
            graphics.IsFullScreen = true;
#endif


            graphics.ApplyChanges();

            base.IsFixedTimeStep = false;

            isFPS = false;

            if (maxFrames <= 0)
            {
                SetFPS(LSystem.DEFAULT_MAX_FPS);
            }

            SetSleepTime(1);

            LSystem.screenActivity = this;
            LSystem.screenProcess  = (process = new LProcess(this, width, height));

            StringBuilder sbr = new StringBuilder();
            sbr.Append("Mode:").Append(mode);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Width:").Append(width).Append(",Height:" + height);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("MaxWidth:").Append(maxWidth)
            .Append(",MaxHeight:" + maxHeight);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Scale:").Append(IsScale());
            log.I(sbr.ToString());
        }
コード例 #13
0
ファイル: LSilverlightPlus.cs プロジェクト: vb0067/LGame
        public void Initialization(bool l,
                                   bool f, LMode m)
        {
            log.I("GPU surface");

            this.landscape  = l;
            this.fullScreen = f;
            this.mode       = m;

            if (landscape == false)
            {
                if (LSystem.MAX_SCREEN_HEIGHT > LSystem.MAX_SCREEN_WIDTH)
                {
                    int tmp_height = LSystem.MAX_SCREEN_HEIGHT;
                    LSystem.MAX_SCREEN_HEIGHT = LSystem.MAX_SCREEN_WIDTH;
                    LSystem.MAX_SCREEN_WIDTH  = tmp_height;
                }
            }

            this.CheckDisplayMode();

            RectBox d = GetScreenDimension();

            LSystem.SCREEN_LANDSCAPE = landscape;

            this.maxWidth  = (int)d.GetWidth();
            this.maxHeight = (int)d.GetHeight();

            if (landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() < d.GetHeight()))
            {
                maxWidth  = (int)d.GetWidth();
                maxHeight = (int)d.GetHeight();
            }
            else if (!landscape && (d.GetWidth() > d.GetHeight()))
            {
                maxHeight = (int)d.GetWidth();
                maxWidth  = (int)d.GetHeight();
            }

            if (mode != LMode.Max)
            {
                if (landscape)
                {
                    this.width  = LSystem.MAX_SCREEN_WIDTH;
                    this.height = LSystem.MAX_SCREEN_HEIGHT;
                }
                else
                {
                    this.width  = LSystem.MAX_SCREEN_HEIGHT;
                    this.height = LSystem.MAX_SCREEN_WIDTH;
                }
            }
            else
            {
                if (landscape)
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxHeight;
                }
                else
                {
                    this.width = maxWidth >= LSystem.MAX_SCREEN_HEIGHT ? LSystem.MAX_SCREEN_HEIGHT
                            : maxWidth;
                    this.height = maxHeight >= LSystem.MAX_SCREEN_WIDTH ? LSystem.MAX_SCREEN_WIDTH
                            : maxHeight;
                }
            }

            if (mode == LMode.Fill)
            {
                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.FitFill)
            {
                RectBox res = GraphicsUtils.FitLimitSize(width, height,
                                                         maxWidth, maxHeight);
                maxWidth            = res.width;
                maxHeight           = res.height;
                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.Ratio)
            {
                maxWidth  = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else if (mode == LMode.MaxRatio)
            {
                maxWidth  = MeasureSpec.GetSize(maxWidth);
                maxHeight = MeasureSpec.GetSize(maxHeight);

                float userAspect = (float)width / (float)height;
                float realAspect = (float)maxWidth / (float)maxHeight;

                if ((realAspect < 1 && userAspect > 1) ||
                    (realAspect > 1 && userAspect < 1))
                {
                    userAspect = (float)height / (float)width;
                }

                if (realAspect < userAspect)
                {
                    maxHeight = MathUtils.Round(maxWidth / userAspect);
                }
                else
                {
                    maxWidth = MathUtils.Round(maxHeight * userAspect);
                }

                LSystem.scaleWidth  = ((float)maxWidth) / width;
                LSystem.scaleHeight = ((float)maxHeight) / height;
            }
            else
            {
                LSystem.scaleWidth  = 1;
                LSystem.scaleHeight = 1;
            }

            if (landscape)
            {
                GamePage.Orientation           = Microsoft.Phone.Controls.PageOrientation.Landscape | Microsoft.Phone.Controls.PageOrientation.LandscapeLeft | Microsoft.Phone.Controls.PageOrientation.LandscapeRight;
                GamePage.SupportedOrientations = Microsoft.Phone.Controls.SupportedPageOrientation.Landscape;
            }
            else
            {
                GamePage.Orientation           = Microsoft.Phone.Controls.PageOrientation.Portrait | Microsoft.Phone.Controls.PageOrientation.PortraitDown | Microsoft.Phone.Controls.PageOrientation.PortraitUp;
                GamePage.SupportedOrientations = Microsoft.Phone.Controls.SupportedPageOrientation.Portrait;
            }

            LSystem.screenRect = new RectBox(0, 0, width, height);

            graphics.PreferredBackBufferFormat = displayMode.Format;
            graphics.PreferredBackBufferWidth  = maxWidth;
            graphics.PreferredBackBufferHeight = maxHeight;

            if (GamePage != null)
            {
                UIElementRenderer = new UIElementRenderer(GamePage, maxWidth, maxHeight);
            }

            //画面渲染与显示器同步
            graphics.SynchronizeWithVerticalRetrace = true;

            graphics.ApplyChanges();

            isFPS = false;

            if (maxFrames <= 0)
            {
                SetFPS(LSystem.DEFAULT_MAX_FPS);
            }

            LSystem.screenActivity = this;
            LSystem.screenProcess  = (process = new LProcess(this, width, height));

            StringBuilder sbr = new StringBuilder();

            sbr.Append("Mode:").Append(mode);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Width:").Append(width).Append(",Height:" + height);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("MaxWidth:").Append(maxWidth)
            .Append(",MaxHeight:" + maxHeight);
            log.I(sbr.ToString());
            sbr.Clear();
            sbr.Append("Scale:").Append(IsScale());
            log.I(sbr.ToString());

            if (GamePage != null)
            {
                GamePage.Background = null;
                GamePage.Foreground = null;
                GamePage.Style      = null;
                GamePage.AllowDrop  = false;
                GamePage.Visibility = System.Windows.Visibility.Collapsed;

                /*System.Windows.Interop.Settings settings = new System.Windows.Interop.Settings();
                 * settings.EnableFrameRateCounter = true;
                 * settings.EnableCacheVisualization = true;
                 * settings.EnableRedrawRegions = true;
                 * settings.MaxFrameRate = maxFrames;
                 * System.Windows.Media.BitmapCache cache = new System.Windows.Media.BitmapCache();
                 * cache.RenderAtScale = 1;
                 * GamePage.CacheMode = cache;*/
                GamePage.Opacity = 1f;
            }
        }