DepthOfFieldPane.cs 3.4 KB

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