//********************************** Banshee Engine (www.banshee3d.com) **************************************************// //**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************// using System; using bs; namespace bs.Editor { /** @addtogroup Windows * @{ */ /// /// A modal window that displays a progress bar. /// public class ProgressBar : ModalWindow { private static ProgressBar instance; private GUIProgressBar progressBar; private GUILabel messageLabel; private LocString message; private float percent = 0.0f; /// /// Determines the message displayed above the progress bar. /// public LocString Message { set { messageLabel.SetContent(value); message = value; } get { return message; } } /// /// Determines size of the filled portion of the progress bar, in range [0, 1]. /// public float Percent { set { progressBar.Percent = value; percent = value; } get { return progressBar.Percent; } } /// /// Shows a progress bar window. /// /// Text to show in the title. /// Initial value to show the progress as, in range [0, 1]. public static void Show(LocString title, float percent) { Show(title, "", percent); } /// /// Shows a progress bar window. /// /// Text to show in the title. /// Message to show above the progress bar. /// Initial value to show the progress as, in range [0, 1]. public static void Show(LocString title, LocString message, float percent) { if (instance == null) { instance = new ProgressBar(title, message, percent); instance.BuildGUI(); } else { instance.Title = title; instance.Message = message; instance.Percent = percent; } } /// /// Hides the progress bar, closing the window. /// public static void Hide() { if (instance != null) instance.Close(); instance = null; } /// /// Creates a new progress bar window. /// /// Text to show in the title. /// Message to show above the progress bar. /// Initial value to show the progress as, in range [0, 1]. protected ProgressBar(LocString title, LocString message, float percent) : base(false) { Width = 350; Height = 100; Title = title; this.message = message; this.percent = percent; } private void BuildGUI() { progressBar = new GUIProgressBar(); messageLabel = new GUILabel(""); GUILayoutY layoutY = GUI.AddLayoutY(); layoutY.AddFlexibleSpace(); GUILayoutX messageLayout = layoutY.AddLayoutX(); messageLayout.AddFlexibleSpace(); messageLayout.AddElement(messageLabel); messageLayout.AddFlexibleSpace(); layoutY.AddSpace(10); GUILayoutX barLayout = layoutY.AddLayoutX(); barLayout.AddSpace(30); barLayout.AddElement(progressBar); barLayout.AddSpace(30); layoutY.AddFlexibleSpace(); Percent = percent; messageLabel.SetContent(message); } } /** @} */ }