Пример #1
0
        protected override void CommitProperties()
        {
            base.CommitProperties();

            if (_imageUrlChanged)
            {
                _imageUrlChanged = false;

                _mask = new LoadingMask(ContentGroup, "Loading image...");
                var cursor = CursorManager.Instance.SetCursor(CursorType.Wait);

                var oldBounds = Rectangle.FromWidthAndHeight(GetExplicitOrMeasuredWidth(), GetExplicitOrMeasuredHeight());
                oldBounds = oldBounds.CenterInside(Rectangle.FromSize(SystemManager.Instance.ScreenSize));

                ImageLoader.Load(_imageUrl, delegate(Texture texture)
                {
                    //Debug.Log("texture size: " + texture.width + ", " + texture.height);
                    _image.Texture = texture;
                    _image.Visible = false;

                    // reset explicit size to allow measurement
                    ExplicitWidth  = null;
                    ExplicitHeight = null;

                    ValidateSize(true);

                    var newBounds = Rectangle.FromWidthAndHeight(GetExplicitOrMeasuredWidth(), GetExplicitOrMeasuredHeight());
                    // center on screen
                    newBounds = newBounds.CenterInside(Rectangle.FromSize(SystemManager.Instance.ScreenSize));
                    //Debug.Log("newBounds: " + newBounds);

                    // return to the old size immediatelly, because of the flicker
                    Width  = oldBounds.Width;
                    Height = oldBounds.Height;

                    #region Alternative

                    //SetActualSize(GetExplicitOrMeasuredWidth(), GetExplicitOrMeasuredHeight());
                    //PopupManager.Instance.CenterPopUp(this);

                    #endregion

                    Defer(delegate
                    {
                        // tween the window size
                        //var newBounds = Bounds.CenterInside(Rectangle.FromSize(SystemManager.Instance.ScreenSize));
                        ScaleBoundsTween tween = new ScaleBoundsTween(this, oldBounds, newBounds)
                        {
                            Callback = delegate
                            {
                                _image.Visible = true; // show image
                                //_image.SkipRender(2); // avoid flicker
                                _image.Alpha = 0;

                                // fade in the image
                                FadeIn fadeIn = new FadeIn
                                {
                                    Duration = 1
                                };
                                fadeIn.Play(_image);
                            }
                        };
                        tween.Play();
                    }, 1);

                    //GlobalLoadingMask.Hide();
                    _mask.Unmask();
                    CursorManager.Instance.RemoveCursor(cursor);
                });
            }
        }