Exemple #1
0
        void CreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            if (args.Reason == CanvasCreateResourcesReason.DpiChanged)
            {
                return;
            }

            if (args.Reason == CanvasCreateResourcesReason.FirstTime)
            {
                bool spriteBatchSupported = false;

#if WINDOWS_UWP
                spriteBatchSupported = CanvasSpriteBatch.IsSupported(sender.Device);
#endif

                UseSpriteBatch = spriteBatchSupported;
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs("UseSpriteBatch"));
                }

                UseSpriteBatchCheckBox.Visibility = spriteBatchSupported ? Visibility.Visible : Visibility.Collapsed;
            }

            args.TrackAsyncAction(CreateResourcesAsync(sender).AsAsyncAction());
        }
Exemple #2
0
        protected override void OnCreateResource(CanvasControl sender, CanvasCreateResourcesEventArgs args)
        {
            // Clear all Tiles and Reload (Display Device might have changed...)

            _isSpriteBatchSupported = CanvasSpriteBatch.IsSupported(sender.Device);
            LayerConfiguration.TileProvider.ResetTiles(ParentMap, sender);
            _isInitialResourcesLoaded = true;
        }
Exemple #3
0
        void OnCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            spriteBatchSupported = CanvasSpriteBatch.IsSupported(sender.Device);

            if (!spriteBatchSupported)
            {
                return;
            }

            args.TrackAsyncAction(LoadImages(sender.Device).AsAsyncAction());
        }
Exemple #4
0
        void CreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            if (args.Reason == CanvasCreateResourcesReason.DpiChanged)
            {
                return;
            }

            bool spriteBatchSupported = false;

#if WINDOWS_UWP
            spriteBatchSupported = CanvasSpriteBatch.IsSupported(sender.Device);
#endif
            UseSpriteBatch = UseSpriteBatchCheckBox.IsChecked.GetValueOrDefault(false);
            UseSpriteBatchCheckBox.Visibility = spriteBatchSupported ? Visibility.Visible : Visibility.Collapsed;

            args.TrackAsyncAction(CreateResourcesAsync(sender).AsAsyncAction());
        }
        public SpriteBatchPerf()
        {
            Scenarios = new List <Scenario>();

            bool spriteBatchSupported = CanvasSpriteBatch.IsSupported(CanvasDevice.GetSharedDevice());

            Scenarios.Add(new Scenario(Scenario.DrawMethod.DrawImage, CanvasSpriteSortMode.None));

            if (spriteBatchSupported)
            {
                Scenarios.Add(new Scenario(Scenario.DrawMethod.Win2DSpriteBatch, CanvasSpriteSortMode.None));
                Scenarios.Add(new Scenario(Scenario.DrawMethod.Win2DSpriteBatch, CanvasSpriteSortMode.Bitmap));
                Scenarios.Add(new Scenario(Scenario.DrawMethod.CppWin2DSpriteBatch, CanvasSpriteSortMode.None));
                Scenarios.Add(new Scenario(Scenario.DrawMethod.CppWin2DSpriteBatch, CanvasSpriteSortMode.Bitmap));
                Scenarios.Add(new Scenario(Scenario.DrawMethod.D2DSpriteBatch, CanvasSpriteSortMode.None));
            }

            DrawCount   = 0;
            BitmapCount = 1;

            if (!DesignMode.DesignModeEnabled)
            {
                DataContext = this;
            }

            if (ThumbnailGenerator.IsDrawingThumbnail)
            {
                foreach (var scenario in Scenarios)
                {
                    scenario.PopulateWithThumbnailData();
                }
            }

            this.InitializeComponent();

            if (!spriteBatchSupported)
            {
                this.SpriteBatchNotSupportedText.Visibility = Visibility.Visible;
            }
        }
        private void canvas_CreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            args.TrackAsyncAction(LoadSpriteSheet(sender.Device).AsAsyncAction());

            lvXCoordinate.SelectedIndex = 0;
            lvYCoordinate.SelectedIndex = 0;
            sldSpriteCount.Maximum      = _maxSpriteCount;

            var defaultGridLength = new GridLength(0);
            var debugRowHeight    = AnalyticsInfo.VersionInfo.DeviceFamily.ToLower().Contains("mobile")
                ? defaultGridLength
                : new GridLength(20);

            ViewModel.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "ShowDebug")
                {
                    Application.Current.DebugSettings.EnableFrameRateCounter = ViewModel.ShowDebug;
                    rowDebug.Height = ViewModel.ShowDebug
                        ? debugRowHeight
                        : defaultGridLength;
                }
            };

#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                ViewModel.ShowDebug = true;
            }
#endif

            _debugTextFormat = new CanvasTextFormat()
            {
                HorizontalAlignment = CanvasHorizontalAlignment.Right, VerticalAlignment = CanvasVerticalAlignment.Bottom
            };
            _debugTextColour           = Colors.Black;
            _spriteColour              = Color.FromArgb(60, 0, 0, 255);
            _spriteColourRunningSlowly = Color.FromArgb(60, 255, 0, 0);

            _fps        = 0;
            _fpsCounter = 0;
            _fpsTime    = TimeSpan.Zero;

            ViewModel.DeltaThetaInteger = 50;
            _theta = 0;

            ViewModel.SpriteCount = 315;
            _position             = new Vector2[_maxSpriteCount];

            _spriteBatchSupported = CanvasSpriteBatch.IsSupported(sender.Device);
            if (_spriteBatchSupported)
            {
                ViewModel.DrawModesAvailable.Add(DrawModes.SpriteBatch);

                _spriteRectNormal        = new Rect(0, 0, 10, 10);
                _spriteRectRunningSlowly = new Rect(10, 0, 10, 10);
            }

            ViewModel.aInteger = 100;
            ViewModel.bInteger = 1;
            ViewModel.cInteger = 100;

            ViewModel.mInteger = -100;
            ViewModel.nInteger = 29;
            ViewModel.oInteger = 74;
        }
Exemple #7
0
 public static BatchSpriteWrapper Create(CanvasDrawingSession drawingSession)
 {
     return(Create(CanvasSpriteBatch.IsSupported(drawingSession.Device), drawingSession));
 }