ProgressBar.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using BansheeEngine;
  3. namespace BansheeEditor
  4. {
  5. /// <summary>
  6. /// A modal window that displays a progress bar.
  7. /// </summary>
  8. public class ProgressBar : ModalWindow
  9. {
  10. private static ProgressBar instance;
  11. private GUIProgressBar progressBar;
  12. private GUILabel messageLabel;
  13. /// <summary>
  14. /// Determines size of the filled portion of the progress bar, in range [0, 1].
  15. /// </summary>
  16. public float Percent
  17. {
  18. set { progressBar.Percent = value; }
  19. get { return progressBar.Percent; }
  20. }
  21. /// <summary>
  22. /// Shows a progress bar window.
  23. /// </summary>
  24. /// <param name="title">Text to show in the title.</param>
  25. /// <param name="percent">Initial value to show the progress as, in range [0, 1].</param>
  26. public static void Show(LocString title, float percent)
  27. {
  28. Show(title, "", percent);
  29. }
  30. /// <summary>
  31. /// Shows a progress bar window.
  32. /// </summary>
  33. /// <param name="title">Text to show in the title.</param>
  34. /// <param name="message">Message to show above the progress bar.</param>
  35. /// <param name="percent">Initial value to show the progress as, in range [0, 1].</param>
  36. public static void Show(LocString title, LocString message, float percent)
  37. {
  38. if (instance == null)
  39. instance = new ProgressBar();
  40. instance.Initialize(title, message, percent);
  41. }
  42. /// <summary>
  43. /// Initializes the progress bar window. Must be called after construction and before use.
  44. /// </summary>
  45. /// <param name="title">Text to show in the title.</param>
  46. /// <param name="message">Message to show above the progress bar.</param>
  47. /// <param name="percent">Initial value to show the progress as, in range [0, 1].</param>
  48. private void Initialize(LocString title, LocString message, float percent)
  49. {
  50. Width = 350;
  51. Height = 75;
  52. Title = title;
  53. Percent = percent;
  54. messageLabel.SetContent(message);
  55. }
  56. /// <summary>
  57. /// Hides the progress bar, closing the window.
  58. /// </summary>
  59. public static void Hide()
  60. {
  61. if (instance != null)
  62. instance.Close();
  63. instance = null;
  64. }
  65. /// <summary>
  66. /// Creates a new uninitialized progress bar.
  67. /// </summary>
  68. protected ProgressBar()
  69. :base(false)
  70. { }
  71. private void OnInitialize()
  72. {
  73. progressBar = new GUIProgressBar();
  74. messageLabel = new GUILabel("");
  75. GUILayoutY layoutY = GUI.AddLayoutY();
  76. layoutY.AddFlexibleSpace();
  77. GUILayoutX messageLayout = layoutY.AddLayoutX();
  78. messageLayout.AddFlexibleSpace();
  79. messageLayout.AddElement(messageLabel);
  80. messageLayout.AddFlexibleSpace();
  81. layoutY.AddSpace(10);
  82. GUILayoutX barLayout = layoutY.AddLayoutX();
  83. barLayout.AddSpace(30);
  84. barLayout.AddElement(progressBar);
  85. barLayout.AddSpace(30);
  86. layoutY.AddFlexibleSpace();
  87. }
  88. }
  89. }