You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.0 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEngine;
  4. namespace AmplifyShaderEditor
  5. {
  6. public enum AutoPanLocation
  7. {
  8. TOP = 0,
  9. BOTTOM,
  10. LEFT,
  11. RIGHT
  12. }
  13. public class AutoPanData
  14. {
  15. private Rect m_area;
  16. private float m_size;
  17. private Vector2 m_velocity;
  18. private GUIStyle m_style;
  19. private Color m_color = new Color( 1f, 0f, 0f, 0.5f );
  20. private AutoPanLocation m_location;
  21. private float m_adjustWidth = 0;
  22. private float m_adjustInitialX = 0;
  23. public AutoPanData( AutoPanLocation location, float size, Vector2 vel )
  24. {
  25. m_area = new Rect();
  26. m_size = size;
  27. m_velocity = vel;
  28. m_location = location;
  29. }
  30. public bool CheckArea( Vector2 mousePosition, Rect window, bool draw )
  31. {
  32. float totalSize = m_size + m_adjustWidth;
  33. switch ( m_location )
  34. {
  35. case AutoPanLocation.TOP:
  36. {
  37. m_area.x = m_adjustInitialX;
  38. m_area.y = 0;
  39. m_area.width = window.width;
  40. m_area.height = totalSize;
  41. }
  42. break;
  43. case AutoPanLocation.BOTTOM:
  44. {
  45. m_area.x = m_adjustInitialX;
  46. m_area.y = window.height - totalSize;
  47. m_area.width = window.width;
  48. m_area.height = totalSize;
  49. }
  50. break;
  51. case AutoPanLocation.LEFT:
  52. {
  53. m_area.x = m_adjustInitialX;
  54. m_area.y = 0;
  55. m_area.width = totalSize;
  56. m_area.height = window.height;
  57. }
  58. break;
  59. case AutoPanLocation.RIGHT:
  60. {
  61. m_area.x = m_adjustInitialX + window.width - totalSize;
  62. m_area.y = 0;
  63. m_area.width = totalSize;
  64. m_area.height = window.height;
  65. }
  66. break;
  67. }
  68. if ( draw )
  69. {
  70. if ( m_style == null )
  71. {
  72. m_style = UIUtils.Box;
  73. }
  74. Color bufferedColor = GUI.color;
  75. GUI.color = m_color;
  76. GUI.Label( m_area, string.Empty, m_style );
  77. GUI.color = bufferedColor;
  78. }
  79. return m_area.Contains( mousePosition );
  80. }
  81. public float AdjustWidth { set { m_adjustWidth = value; } }
  82. public float AdjustInitialX { set { m_adjustInitialX = value; } }
  83. public Vector2 Velocity { get { return m_velocity; } }
  84. }
  85. }