Layer.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using PixiEditor.Helpers;
  2. using PixiEditorDotNetCore3.Models.Tools;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Diagnostics;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. namespace PixiEditorDotNetCore3.Models.Layers
  15. {
  16. public class Layer : BasicLayer
  17. {
  18. private WriteableBitmap _layerBitmap;
  19. public WriteableBitmap LayerBitmap
  20. {
  21. get { return _layerBitmap; }
  22. set
  23. {
  24. _layerBitmap = value;
  25. RaisePropertyChanged("LayerBitmap");
  26. }
  27. }
  28. public Layer(int width, int height)
  29. {
  30. Layer layer = LayerGenerator.Generate(width, height);
  31. LayerBitmap = layer.LayerBitmap;
  32. Width = width;
  33. Height = height;
  34. }
  35. public Layer(WriteableBitmap layerBitmap)
  36. {
  37. LayerBitmap = layerBitmap;
  38. Width = (int)layerBitmap.Width;
  39. Height = (int)layerBitmap.Height;
  40. }
  41. public void ApplyPixels(BitmapPixelChanges pixels, Color color)
  42. {
  43. LayerBitmap.Lock();
  44. foreach (var coords in pixels.ChangedCoordinates)
  45. {
  46. LayerBitmap.SetPixel(Math.Clamp(coords.X, 0, Width - 1), Math.Clamp(coords.Y, 0, Height - 1), color);
  47. }
  48. LayerBitmap.Unlock();
  49. }
  50. }
  51. }