コード例 #1
0
        private void UpdatePreviews()
        {
            if (AlphaPreviews == null || NonAlphaPreviews == null)
            {
                return;
            }

            Previews.Clear();
            Previews.AddRange(ShowAlphaPreviews ? AlphaPreviews : NonAlphaPreviews);
            OnPropertyChanged(nameof(Preview));
        }
コード例 #2
0
        void Nodes_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (var item in e.NewItems)
                {
                    if (item != null && item is NodeModel)
                    {
                        var node = item as NodeModel;

                        var nodeViewModel = new NodeViewModel(node);
                        _nodes.Add(nodeViewModel);
                        Errors.Add(nodeViewModel.ErrorBubble);
                        Previews.Add(nodeViewModel.PreviewBubble);
                    }
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                _nodes.Clear();
                Errors.Clear();
                Previews.Clear();
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (var item in e.OldItems)
                {
                    var           node          = item as NodeModel;
                    NodeViewModel nodeViewModel = _nodes.First(x => x.NodeLogic == item);
                    Previews.Remove(nodeViewModel.PreviewBubble);
                    Errors.Remove(nodeViewModel.ErrorBubble);
                    _nodes.Remove(nodeViewModel);
                }
                break;
            }
        }
コード例 #3
0
        public async Task LoadImage(string path)
        {
            bool testing = false;  // Set to true to load mips single threaded and only the full image instead of a smaller one first.

            Task <List <object> > fullLoadingTask = null;

            if (!testing)
            {
                // Load full size image
                ////////////////////////////////////////////////////////////////////////////////////////
                fullLoadingTask = Task.Run(() =>
                {
                    ImageEngineImage fullimage = new ImageEngineImage(path);

                    List <BitmapSource> alphas    = new List <BitmapSource>();
                    List <BitmapSource> nonalphas = new List <BitmapSource>();

                    for (int i = 0; i < fullimage.NumMipMaps; i++)
                    {
                        alphas.Add(fullimage.GeneratePreview(i, true));
                        nonalphas.Add(fullimage.GeneratePreview(i, false));
                    }

                    List <object> bits = new List <object>();
                    bits.Add(fullimage);
                    bits.Add(alphas);
                    bits.Add(nonalphas);
                    return(bits);
                });
                ////////////////////////////////////////////////////////////////////////////////////////
            }



            SaveSuccess = null;
            Previews.Clear();
            savePreviews = new BitmapSource[2];
            SavePath     = null;
            SaveFormat   = ImageEngineFormat.Unknown;

            stopwatch.Start();



            ////////////////////////////////////////////////////////////////////////////////////////
            if (testing)
            {
                img = await Task.Run(() => new ImageEngineImage(path));
            }
            else
            {
                img = await Task.Run(() => new ImageEngineImage(path, 256, false));
            }
            ////////////////////////////////////////////////////////////////////////////////////////



            Console.WriteLine("");
            Console.WriteLine($"Format: {img.Format}");
            stopwatch.Stop();
            Console.WriteLine($"Image Loading: {stopwatch.ElapsedMilliseconds}");
            stopwatch.Restart();

            Previews.Add(img.GeneratePreview(0, ShowAlphaPreviews));
            MipIndex = 1;  // 1 based

            stopwatch.Stop();
            Debug.WriteLine($"Image Preview: {stopwatch.ElapsedMilliseconds}");
            stopwatch.Reset();

            OnPropertyChanged(nameof(ImagePath));
            OnPropertyChanged(nameof(Format));
            OnPropertyChanged(nameof(NumMipMaps));
            OnPropertyChanged(nameof(Preview));
            OnPropertyChanged(nameof(MipWidth));
            OnPropertyChanged(nameof(MipHeight));

            // KFreon: Get full image details
            ////////////////////////////////////////////////////////////////////////////////////////
            if (!testing)
            {
                List <object> FullImageObjects = await fullLoadingTask;
                double?       oldMipWidth      = MipWidth;
                img = (ImageEngineImage)FullImageObjects[0];

                AlphaPreviews    = (List <BitmapSource>)FullImageObjects[1];
                NonAlphaPreviews = (List <BitmapSource>)FullImageObjects[2];

                UpdatePreviews();

                // KFreon: Set selected mip index

                /*for (int i = 0; i < Previews.Count; i++)
                 * {
                 *  if (Previews[i].Width == oldMipWidth)
                 *  {
                 *      MipIndex = i + 1;  // 1 based
                 *      break;
                 *  }
                 * }*/
                MipIndex = 1;
            }

            ////////////////////////////////////////////////////////////////////////////////////////


            OnPropertyChanged(nameof(NumMipMaps));
            OnPropertyChanged(nameof(Preview));
            OnPropertyChanged(nameof(MipIndex));
            OnPropertyChanged(nameof(MipWidth));
            OnPropertyChanged(nameof(MipHeight));
            OnPropertyChanged(nameof(img));
        }