Layer.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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
  15. {
  16. public class Layer : BasicLayer
  17. {
  18. private WriteableBitmap _layerBitmap;
  19. public WriteableBitmap LayerBitmap
  20. {
  21. get { return _layerBitmap; }
  22. set {
  23. _layerBitmap = value;
  24. RaisePropertyChanged("LayerBitmap");
  25. }
  26. }
  27. public Layer(int width, int height)
  28. {
  29. Layer layer = LayerGenerator.Generate(width, height);
  30. LayerBitmap = layer.LayerBitmap;
  31. Width = width;
  32. Height = height;
  33. }
  34. public Layer(WriteableBitmap layerBitmap)
  35. {
  36. LayerBitmap = layerBitmap;
  37. Width = (int) layerBitmap.Width;
  38. Height = (int) layerBitmap.Height;
  39. }
  40. public void ApplyPixels(BitmapPixelChanges pixels, Color color)
  41. {
  42. foreach (var coords in pixels.ChangedCoordinates)
  43. {
  44. LayerBitmap.SetPixel(Math.Clamp(coords.X, 0, Width - 1), Math.Clamp(coords.Y, 0, Height - 1), color);
  45. }
  46. }
  47. }
  48. }