ProgressBar.cs 4.1 KB

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