Changed print progress bar to show % complete and be sensitive to theme changes.

This commit is contained in:
Kevin Pope 2014-02-20 18:38:46 -08:00
parent 910cb06c5a
commit 53bd49189c

View file

@ -21,26 +21,23 @@ namespace MatterHackers.MatterControl
public PrintProgressBar() public PrintProgressBar()
{ {
MinimumSize = new Vector2(0, 30); MinimumSize = new Vector2(0, 24);
HAnchor = HAnchor.ParentLeftRight; HAnchor = HAnchor.ParentLeftRight;
BackgroundColor = ActiveTheme.Instance.SecondaryAccentColor; BackgroundColor = ActiveTheme.Instance.SecondaryAccentColor;
Margin = new BorderDouble(0); Margin = new BorderDouble(0);
FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.LeftToRight); FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.LeftToRight);
container.AnchorAll(); container.AnchorAll();
container.Padding = new BorderDouble(7,0); container.Padding = new BorderDouble(6,0);
RGBA_Bytes labelColor = ActiveTheme.Instance.PrimaryAccentColor; printTimeElapsed = new TextWidget("", pointSize:11);
//labelColor.alpha = 220; printTimeElapsed.AutoExpandBoundsToText = true;
printTimeElapsed = new TextWidget("2:30:00");
printTimeElapsed.VAnchor = Agg.UI.VAnchor.ParentCenter; printTimeElapsed.VAnchor = Agg.UI.VAnchor.ParentCenter;
printTimeElapsed.TextColor = labelColor;
printTimeRemaining = new TextWidget("4:50:30");
printTimeRemaining = new TextWidget("", pointSize: 11);
printTimeRemaining.AutoExpandBoundsToText = true;
printTimeRemaining.VAnchor = Agg.UI.VAnchor.ParentCenter; printTimeRemaining.VAnchor = Agg.UI.VAnchor.ParentCenter;
printTimeRemaining.TextColor = labelColor;
GuiWidget spacer = new GuiWidget(); GuiWidget spacer = new GuiWidget();
spacer.HAnchor = Agg.UI.HAnchor.ParentLeftRight; spacer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
@ -51,7 +48,8 @@ namespace MatterHackers.MatterControl
AddChild(container); AddChild(container);
AddHandlers(); AddHandlers();
UpdatePrintStatus(); SetThemedColors();
UpdatePrintStatus();
UiThread.RunOnIdle(OnIdle); UiThread.RunOnIdle(OnIdle);
} }
@ -74,12 +72,17 @@ namespace MatterHackers.MatterControl
base.OnClosed(e); base.OnClosed(e);
} }
private void onThemeChanged(object sender, EventArgs e) private void SetThemedColors()
{ {
//Set background color to new theme
this.printTimeElapsed.TextColor = ActiveTheme.Instance.PrimaryAccentColor; this.printTimeElapsed.TextColor = ActiveTheme.Instance.PrimaryAccentColor;
this.printTimeRemaining.TextColor = ActiveTheme.Instance.PrimaryAccentColor; this.printTimeRemaining.TextColor = ActiveTheme.Instance.PrimaryAccentColor;
this.BackgroundColor = ActiveTheme.Instance.SecondaryAccentColor; this.BackgroundColor = ActiveTheme.Instance.SecondaryAccentColor;
}
private void onThemeChanged(object sender, EventArgs e)
{
//Set background color to new theme
SetThemedColors();
this.Invalidate(); this.Invalidate();
} }
@ -158,26 +161,11 @@ namespace MatterHackers.MatterControl
printTimeElapsed.Text = string.Format(""); printTimeElapsed.Text = string.Format("");
} }
int secondsRemaining = PrinterCommunication.Instance.SecondsRemaining; string printPercentRemainingText = string.Format("{0:0.0}%", currentPercent);
int hoursRemaining = (int)(secondsRemaining / (60 * 60));
int minutesRemaining = (int)(secondsRemaining / 60 - hoursRemaining * 60);
secondsRemaining = secondsRemaining % 60;
if (secondsRemaining > 0) if (PrinterCommunication.Instance.PrinterIsPrinting || PrinterCommunication.Instance.PrinterIsPaused)
{ {
if (hoursRemaining > 0) printTimeRemaining.Text = printPercentRemainingText;
{
printTimeRemaining.Text = string.Format("{0}:{1:00}:{2:00}",
hoursRemaining,
minutesRemaining,
secondsRemaining);
}
else
{
printTimeRemaining.Text = string.Format("{0}:{1:00}",
minutesRemaining,
secondsRemaining);
}
} }
else if (PrinterCommunication.Instance.PrintIsFinished) else if (PrinterCommunication.Instance.PrintIsFinished)
{ {