SceneCameraOptionsDropdown.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using bs;
  4. using System;
  5. namespace bs.Editor
  6. {
  7. /** @addtogroup Scene-Editor
  8. * @{
  9. */
  10. /// <summary>
  11. /// Drop down window that displays options used by the scene camera.
  12. /// </summary>
  13. [DefaultSize(350, 150)]
  14. internal class SceneCameraOptionsDropdown : DropDownWindow
  15. {
  16. private SceneWindow Parent;
  17. private GUIFloatField nearClipPlaneInput;
  18. private GUIFloatField farClipPlaneInput;
  19. private GUIFloatField cameraOrthographicSize;
  20. private GUISliderField cameraFieldOfView;
  21. /// <summary>
  22. /// Initializes the drop down window by creating the necessary GUI. Must be called after construction and before
  23. /// use.
  24. /// </summary>
  25. /// <param name="parent">Scene window that this drop down window is a part of.</param>
  26. /// <param name="cameraOptions">Reference to the current scene camera options.</param>
  27. internal void Initialize(SceneWindow parent)
  28. {
  29. this.Parent = parent;
  30. GUIEnumField cameraProjectionTypeField = new GUIEnumField(typeof(ProjectionType), new LocEdString("Projection type"));
  31. cameraProjectionTypeField.Value = (ulong)Parent.ProjectionType;
  32. cameraProjectionTypeField.OnSelectionChanged += SetCameraProjectionType;
  33. nearClipPlaneInput = new GUIFloatField(new LocEdString("Near plane"));
  34. nearClipPlaneInput.Value = Parent.NearClipPlane;
  35. nearClipPlaneInput.OnChanged += OnNearClipPlaneChanged;
  36. nearClipPlaneInput.SetRange(SceneCameraOptions.MinNearClipPlane, SceneCameraOptions.MaxNearClipPlane);
  37. farClipPlaneInput = new GUIFloatField(new LocEdString("Far plane"));
  38. farClipPlaneInput.Value = Parent.FarClipPlane;
  39. farClipPlaneInput.OnChanged += OnFarClipPlaneChanged;
  40. farClipPlaneInput.SetRange(SceneCameraOptions.MinFarClipPlane, SceneCameraOptions.MaxFarClipPlane);
  41. cameraFieldOfView = new GUISliderField(1, 360, new LocEdString("Field of view"));
  42. cameraFieldOfView.Value = Parent.FieldOfView.Degrees;
  43. cameraFieldOfView.OnChanged += SetFieldOfView;
  44. cameraOrthographicSize = new GUIFloatField(new LocEdString("Orthographic size"));
  45. cameraOrthographicSize.Value = Parent.OrthographicSize;
  46. cameraOrthographicSize.OnChanged += SetOrthographicSize;
  47. GUISliderField cameraScrollSpeed = new GUISliderField(SceneCameraOptions.MinScrollSpeed, SceneCameraOptions.MaxScrollSpeed,
  48. new LocEdString("Scroll speed"));
  49. cameraScrollSpeed.Value = Parent.ScrollSpeed;
  50. cameraScrollSpeed.OnChanged += SetScrollSpeed;
  51. GUILayoutY vertLayout = GUI.AddLayoutY();
  52. vertLayout.AddSpace(10);
  53. GUILayoutX cameraOptionsLayoutX = vertLayout.AddLayoutX();
  54. cameraOptionsLayoutX.AddSpace(10);
  55. GUILayoutY cameraOptionsLayoutY = cameraOptionsLayoutX.AddLayoutY();
  56. cameraOptionsLayoutY.AddElement(cameraProjectionTypeField);
  57. cameraOptionsLayoutY.AddElement(nearClipPlaneInput);
  58. cameraOptionsLayoutY.AddElement(farClipPlaneInput);
  59. cameraOptionsLayoutY.AddElement(cameraFieldOfView);
  60. cameraOptionsLayoutY.AddElement(cameraOrthographicSize);
  61. cameraOptionsLayoutY.AddElement(cameraScrollSpeed);
  62. cameraOptionsLayoutX.AddSpace(10);
  63. vertLayout.AddSpace(10);
  64. ToggleTypeSpecificFields((ProjectionType)cameraProjectionTypeField.Value);
  65. }
  66. private void SetOrthographicSize(float value)
  67. {
  68. if (Parent.ProjectionType != ProjectionType.Orthographic)
  69. return;
  70. Parent.OrthographicSize = value;
  71. }
  72. private void SetFieldOfView(float value)
  73. {
  74. if (Parent.ProjectionType != ProjectionType.Perspective)
  75. return;
  76. Parent.FieldOfView = (Degree)value;
  77. }
  78. /// <summary>
  79. /// Sets the value of the scene camera scroll speed.
  80. /// </summary>
  81. /// <param name="value">The scroll speed value.</param>
  82. private void SetScrollSpeed(float value)
  83. {
  84. Parent.ScrollSpeed = value;
  85. }
  86. private void ToggleTypeSpecificFields(ProjectionType projectionType)
  87. {
  88. cameraFieldOfView.Active = projectionType == ProjectionType.Perspective;
  89. cameraOrthographicSize.Active = projectionType == ProjectionType.Orthographic;
  90. }
  91. private void SetCameraProjectionType(ulong projectionType)
  92. {
  93. Parent.ProjectionType = (ProjectionType)projectionType;
  94. ToggleTypeSpecificFields((ProjectionType)projectionType);
  95. }
  96. private void OnNearClipPlaneChanged(float value)
  97. {
  98. Parent.NearClipPlane = value;
  99. }
  100. private void OnFarClipPlaneChanged(float value)
  101. {
  102. Parent.FarClipPlane = value;
  103. }
  104. }
  105. }