ProgressBar.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. using System;
  4. using bs;
  5. namespace bs.Editor
  6. {
  7. /** @addtogroup Windows
  8. * @{
  9. */
  10. /// <summary>
  11. /// A modal window that displays a progress bar.
  12. /// </summary>
  13. public class ProgressBar : ModalWindow
  14. {
  15. private static ProgressBar instance;
  16. private GUIProgressBar progressBar;
  17. private GUILabel messageLabel;
  18. private LocString message;
  19. private float percent = 0.0f;
  20. /// <summary>
  21. /// Determines the message displayed above the progress bar.
  22. /// </summary>
  23. public LocString Message
  24. {
  25. set { messageLabel.SetContent(value); message = value; }
  26. get { return message; }
  27. }
  28. /// <summary>
  29. /// Determines size of the filled portion of the progress bar, in range [0, 1].
  30. /// </summary>
  31. public float Percent
  32. {
  33. set { progressBar.Percent = value; percent = value; }
  34. get { return progressBar.Percent; }
  35. }
  36. /// <summary>
  37. /// Shows a progress bar window.
  38. /// </summary>
  39. /// <param name="title">Text to show in the title.</param>
  40. /// <param name="percent">Initial value to show the progress as, in range [0, 1].</param>
  41. public static void Show(LocString title, float percent)
  42. {
  43. Show(title, "", percent);
  44. }
  45. /// <summary>
  46. /// Shows a progress bar window.
  47. /// </summary>
  48. /// <param name="title">Text to show in the title.</param>
  49. /// <param name="message">Message to show above the progress bar.</param>
  50. /// <param name="percent">Initial value to show the progress as, in range [0, 1].</param>
  51. public static void Show(LocString title, LocString message, float percent)
  52. {
  53. if (instance == null)
  54. {
  55. instance = new ProgressBar(title, message, percent);
  56. instance.BuildGUI();
  57. }
  58. else
  59. {
  60. instance.Title = title;
  61. instance.Message = message;
  62. instance.Percent = percent;
  63. }
  64. }
  65. /// <summary>
  66. /// Hides the progress bar, closing the window.
  67. /// </summary>
  68. public static void Hide()
  69. {
  70. if (instance != null)
  71. instance.Close();
  72. instance = null;
  73. }
  74. /// <summary>
  75. /// Creates a new progress bar window.
  76. /// </summary>
  77. /// <param name="title">Text to show in the title.</param>
  78. /// <param name="message">Message to show above the progress bar.</param>
  79. /// <param name="percent">Initial value to show the progress as, in range [0, 1].</param>
  80. protected ProgressBar(LocString title, LocString message, float percent)
  81. : base(false)
  82. {
  83. Width = 350;
  84. Height = 100;
  85. Title = title;
  86. this.message = message;
  87. this.percent = percent;
  88. }
  89. private void BuildGUI()
  90. {
  91. progressBar = new GUIProgressBar();
  92. messageLabel = new GUILabel("");
  93. GUILayoutY layoutY = GUI.AddLayoutY();
  94. layoutY.AddFlexibleSpace();
  95. GUILayoutX messageLayout = layoutY.AddLayoutX();
  96. messageLayout.AddFlexibleSpace();
  97. messageLayout.AddElement(messageLabel);
  98. messageLayout.AddFlexibleSpace();
  99. layoutY.AddSpace(10);
  100. GUILayoutX barLayout = layoutY.AddLayoutX();
  101. barLayout.AddSpace(30);
  102. barLayout.AddElement(progressBar);
  103. barLayout.AddSpace(30);
  104. layoutY.AddFlexibleSpace();
  105. Percent = percent;
  106. messageLabel.SetContent(message);
  107. }
  108. }
  109. /** @} */
  110. }