using System;
using BansheeEngine;
namespace BansheeEditor
{
///
/// A modal window that displays a progress bar.
///
public class ProgressBar : ModalWindow
{
private static ProgressBar instance;
private GUIProgressBar progressBar;
private GUILabel messageLabel;
///
/// Determines size of the filled portion of the progress bar, in range [0, 1].
///
public float Percent
{
set { progressBar.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();
instance.Initialize(title, message, percent);
}
///
/// Initializes the progress bar window. Must be called after construction and before use.
///
/// Text to show in the title.
/// Message to show above the progress bar.
/// Initial value to show the progress as, in range [0, 1].
private void Initialize(LocString title, LocString message, float percent)
{
Width = 350;
Height = 75;
Title = title;
Percent = percent;
messageLabel.SetContent(message);
}
///
/// Hides the progress bar, closing the window.
///
public static void Hide()
{
if (instance != null)
instance.Close();
instance = null;
}
///
/// Creates a new uninitialized progress bar.
///
protected ProgressBar()
:base(false)
{ }
private void OnInitialize()
{
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();
}
}
}