예제 #1
0
 /// <summary>
 /// Compare two path lists
 /// </summary>
 private bool PathListEqual(IEnumerable<PathEntry> original,ObservableCollectionEx<AnnotatedPathEntry> edited)
 {
     return original.Count() == edited.Count() && original.Zip(edited, (a, b) => a.SymbolicPath == b.SymbolicPath).All(_ => _);
 }
예제 #2
0
        private unsafe void BackgroundBlockRenderer()
        {
#if DEBUG
            Debug.WriteLine("BackgroundBlockRenderer: Started");
#endif
            if (_graphicBuffer == null)
            {
#if DEBUG
                Debug.WriteLine("BackgroundBlockRenderer: Aborted (graphic = null)");
#endif
                return;
            }
            IsRendering = true;
            try
            {
                while (true)
                {
                    TilesetEntryModel dirtyBlock = null;
                    try
                    {
                        dirtyBlock = _blocks.First(p => p.Dirty);
                    }
                    catch (InvalidOperationException)
                    {
                        break;
                    }
                    RenderProgress = 100 - (int)((100f / (float)_blocks.Count) * (float)_blocks.Count(p => p.Dirty));

                    //targets for tile copies
                    WriteableBitmap newBlockImage        = new WriteableBitmap(16, 16, 96, 96, PixelFormats.Bgra32, null);
                    WriteableBitmap newBlockImageOverlay = new WriteableBitmap(16, 16, 96, 96, PixelFormats.Bgra32, null);
                    newBlockImage.Lock();
                    byte *blockData = (byte *)newBlockImage.BackBuffer;
                    newBlockImageOverlay.Lock();
                    byte *blockDataOverlay = (byte *)newBlockImageOverlay.BackBuffer;

                    //copy tiles
                    for (int k = 0; k < 5; k += 4)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            //TODO hflip and vflip
                            Int32Rect       pos            = new Int32Rect((i == 1 || i == 3) ? 8 : 0, (i == 2 || i == 3) ? 8 : 0, 8, 8);
                            WriteableBitmap tile           = GetTile(dirtyBlock.Tilemap[i + k].TileID);
                            IList <Color>   currentPalette = _palettes[dirtyBlock.Tilemap[i + k].PalIndex].Value.Colors.Select(p => p.Color).ToList();
                            currentPalette[0] = Color.FromArgb(0, 0, 0, 0); //color 0 = transparent
                            ChangePalette(ref tile, new BitmapPalette(currentPalette));
                            WriteableBitmap fbitmap = new WriteableBitmap(new FormatConvertedBitmap(tile, PixelFormats.Bgra32, null, 0));
                            fbitmap.Lock();
                            byte *fbData = (byte *)fbitmap.BackBuffer;
                            ((k == 0) ? newBlockImage : newBlockImageOverlay).WritePixels(pos, (IntPtr)fbData, 256, 32);
                            fbitmap.Unlock();
                        }
                    }

                    newBlockImageOverlay.AddDirtyRect(new Int32Rect(0, 0, 16, 16));
                    newBlockImageOverlay.Unlock();
                    newBlockImage.AddDirtyRect(new Int32Rect(0, 0, 16, 16));
                    newBlockImage.Unlock();

                    //merge targets
                    AddTransparentBlock(newBlockImage, newBlockImageOverlay);
                    newBlockImage.Freeze();

                    Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                    {
                        dirtyBlock.Graphic = newBlockImage;
                        dirtyBlock.Dirty   = false;
                    }));
                }
            }
            catch (ThreadAbortException)
            {
#if DEBUG
                Debug.WriteLine("BackgroundBlockRenderer: Aborted");
#endif
            }
#if DEBUG
            Debug.WriteLine("BackgroundBlockRenderer: Ended");
#endif
            IsRendering = false;
        }