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.

73 lines
1.6 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 class PalettePopUp
  7. {
  8. private const int DeltaX = 5;
  9. private Rect m_areaSettings;
  10. private Vector2 m_mouseDeltaPos = new Vector2( 10, -10 );
  11. private bool m_isActive = false;
  12. private GUIContent m_content;
  13. private GUIStyle m_style;
  14. private GUIStyle m_fontStyle;
  15. private GUIContent m_labelContent;
  16. public PalettePopUp()
  17. {
  18. m_content = new GUIContent( GUIContent.none );
  19. m_areaSettings = new Rect( 0, 0, 100, 30 );
  20. m_labelContent = new GUIContent( "Test Label" );
  21. }
  22. public void Activate( string label )
  23. {
  24. m_labelContent.text = label;
  25. m_areaSettings.width = -1;
  26. m_isActive = true;
  27. }
  28. public void Deactivate()
  29. {
  30. m_isActive = false;
  31. }
  32. public void Draw( Vector2 mousePos )
  33. {
  34. if ( m_style == null )
  35. {
  36. m_style = UIUtils.TextArea;
  37. }
  38. if ( m_fontStyle == null )
  39. {
  40. m_fontStyle = new GUIStyle( UIUtils.Label );
  41. m_fontStyle.fontSize = 15;
  42. }
  43. if ( m_areaSettings.width < 0 )
  44. {
  45. m_areaSettings.width = m_fontStyle.CalcSize( m_labelContent ).x + 2 * DeltaX;
  46. }
  47. m_areaSettings.position = mousePos + m_mouseDeltaPos;
  48. GUI.Label( m_areaSettings, m_content, m_style );
  49. m_areaSettings.position += new Vector2( DeltaX,DeltaX);
  50. GUI.Label( m_areaSettings, m_labelContent, m_fontStyle );
  51. }
  52. public void Destroy()
  53. {
  54. m_content = null;
  55. m_style = null;
  56. }
  57. public bool IsActive
  58. {
  59. get { return m_isActive; }
  60. }
  61. }
  62. }