Ejemplo n.º 1
0
        private void Init()
        {
            _stopwatch          = new Stopwatch();
            _totalElapsedMillis = 0L;
            lock (_particleLock)
            {
                _particles ??= new List <ParticleBase>();
            }
            _fallingParticlesPerSecond = FallingParticlesPerSecond;
            _particleRequester         = new RateBasedParticleRequester();

            TouchParticleGenerator   = new SimpleParticleGenerator();
            FallingParticleGenerator = new FallingParticleGenerator();


            // Debug info
            _showDebugInfo        = ShowDebugInfo;
            _debugInfoPaint.Color = DebugInfoColor.ToSKColor();

            // SKCanvasView is not fast enough on Android, so let's use an SKGLView 😄
            // Since there isn't a common interface for both SKCanvasView and SKGLView we're using a bit of indirection
            if (UseSKGLView)
            {
                var skglView = new SKGLView();

                _getCanvasSize = () => skglView.CanvasSize;

                _invalidateSurface = () => skglView.InvalidateSurface();

                _getEnableTouchEvents = () => skglView.EnableTouchEvents;
                _setEnableTouchEvents = enableTouchEvents => skglView.EnableTouchEvents = enableTouchEvents;

                _addTouchHandler    = touchHandler => skglView.Touch += touchHandler;
                _removeTouchHandler = touchHandler => skglView.Touch -= touchHandler;

                skglView.PaintSurface += SkglViewOnPaintSurface;
                Content = skglView;
            }
            else
            {
                var skCanvasView = new SKCanvasView();

                _getCanvasSize = () => skCanvasView.CanvasSize;

                _invalidateSurface = () => skCanvasView.InvalidateSurface();

                _getEnableTouchEvents = () => skCanvasView.EnableTouchEvents;
                _setEnableTouchEvents = enableTouchEvents => skCanvasView.EnableTouchEvents = enableTouchEvents;

                _addTouchHandler    = touchHandler => skCanvasView.Touch += touchHandler;
                _removeTouchHandler = touchHandler => skCanvasView.Touch -= touchHandler;

                skCanvasView.PaintSurface += OnPaintSurface;
                Content = skCanvasView;
            }
        }
        protected override void OnPropertyChanged(string propertyName = null)
        {
            base.OnPropertyChanged(propertyName);

            if (propertyName == IsActiveProperty.PropertyName)
            {
                if (IsActive)
                {
                    EnableTouchInput();
                    if (IsRunning)
                    {
                        StartMainAnimation();
                    }
                }
                else
                {
                    DisableTouchInput();
                    StopMainAnimation();

                    IsRunning = false;
                }
            }
            else if (propertyName == AddParticlesOnTapProperty.PropertyName ||
                     propertyName == AddParticlesOnDragProperty.PropertyName)
            {
                if (AddParticlesOnTap || AddParticlesOnDrag)
                {
                    EnableTouchInput();
                }
                else
                {
                    DisableTouchInput();
                }
            }
            else if (propertyName == IsRunningProperty.PropertyName && IsActive)
            {
                if (IsRunning)
                {
                    StartMainAnimation();
                }
                else
                {
                    PauseMainAnimation();
                }
            }
            else if (propertyName == UseSKGLViewProperty.PropertyName)
            {
                Init();
            }
            else if (propertyName == ShowDebugInfoProperty.PropertyName)
            {
                _showDebugInfo = ShowDebugInfo;
            }
            else if (propertyName == DebugInfoColorProperty.PropertyName)
            {
                _debugInfoPaint.Color = DebugInfoColor.ToSKColor();
            }
            else if (propertyName == FallingParticlesPerSecondProperty.PropertyName)
            {
                _fallingParticlesPerSecond = FallingParticlesPerSecond;
            }
        }