DepthOfFieldPane.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using UnityEngine;
  2. namespace MeidoPhotoStudio.Plugin;
  3. public class DepthOfFieldPane : EffectPane<DepthOfFieldEffectManager>
  4. {
  5. private readonly Slider focalLengthSlider;
  6. private readonly Slider focalSizeSlider;
  7. private readonly Slider apertureSlider;
  8. private readonly Slider blurSlider;
  9. private readonly Toggle thicknessToggle;
  10. public DepthOfFieldPane(EffectManager effectManager)
  11. : base(effectManager)
  12. {
  13. focalLengthSlider =
  14. new(Translation.Get("effectDof", "focalLength"), 0f, 10f, EffectManager.FocalLength);
  15. focalLengthSlider.ControlEvent += (_, _) =>
  16. {
  17. if (updating)
  18. return;
  19. EffectManager.FocalLength = focalLengthSlider.Value;
  20. };
  21. focalSizeSlider = new(Translation.Get("effectDof", "focalArea"), 0f, 2f, EffectManager.FocalSize);
  22. focalSizeSlider.ControlEvent += (_, _) =>
  23. {
  24. if (updating)
  25. return;
  26. EffectManager.FocalSize = focalSizeSlider.Value;
  27. };
  28. apertureSlider = new(Translation.Get("effectDof", "aperture"), 0f, 60f, EffectManager.Aperture);
  29. apertureSlider.ControlEvent += (_, _) =>
  30. {
  31. if (updating)
  32. return;
  33. EffectManager.Aperture = apertureSlider.Value;
  34. };
  35. blurSlider = new(Translation.Get("effectDof", "blur"), 0f, 10f, EffectManager.MaxBlurSize);
  36. blurSlider.ControlEvent += (_, _) =>
  37. {
  38. if (updating)
  39. return;
  40. EffectManager.MaxBlurSize = blurSlider.Value;
  41. };
  42. thicknessToggle = new(Translation.Get("effectDof", "thicknessToggle"), EffectManager.VisualizeFocus);
  43. thicknessToggle.ControlEvent += (_, _) =>
  44. {
  45. if (updating)
  46. return;
  47. EffectManager.VisualizeFocus = thicknessToggle.Value;
  48. };
  49. }
  50. protected override DepthOfFieldEffectManager EffectManager { get; set; }
  51. protected override void TranslatePane()
  52. {
  53. focalLengthSlider.Label = Translation.Get("effectDof", "focalLength");
  54. focalSizeSlider.Label = Translation.Get("effectDof", "focalArea");
  55. apertureSlider.Label = Translation.Get("effectDof", "aperture");
  56. blurSlider.Label = Translation.Get("effectDof", "blur");
  57. thicknessToggle.Label = Translation.Get("effectDof", "thicknessToggle");
  58. }
  59. protected override void UpdateControls()
  60. {
  61. focalLengthSlider.Value = EffectManager.FocalLength;
  62. focalSizeSlider.Value = EffectManager.FocalSize;
  63. apertureSlider.Value = EffectManager.Aperture;
  64. blurSlider.Value = EffectManager.MaxBlurSize;
  65. thicknessToggle.Value = EffectManager.VisualizeFocus;
  66. }
  67. protected override void DrawPane()
  68. {
  69. focalLengthSlider.Draw();
  70. var sliderWidth = MpsGui.HalfSlider;
  71. GUILayout.BeginHorizontal();
  72. focalSizeSlider.Draw(sliderWidth);
  73. apertureSlider.Draw(sliderWidth);
  74. GUILayout.EndHorizontal();
  75. GUILayout.BeginHorizontal();
  76. blurSlider.Draw(sliderWidth);
  77. GUILayout.FlexibleSpace();
  78. thicknessToggle.Draw();
  79. GUILayout.EndHorizontal();
  80. GUI.enabled = true;
  81. }
  82. }