Adding in the touchscreen icons
Fixed the PrintProgressBar to move up and down.
This commit is contained in:
parent
d4453d199b
commit
f3bea1bb07
9 changed files with 182 additions and 131 deletions
|
|
@ -31,54 +31,104 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.VectorMath;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
using MatterHackers.Agg.PlatformAbstract;
|
||||
using MatterHackers.Agg.ImageProcessing;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public class PrintProgressBar : GuiWidget
|
||||
{
|
||||
double currentPercent = 0;
|
||||
RGBA_Bytes completeColor = new RGBA_Bytes(255, 255, 255);
|
||||
TextWidget printTimeRemaining;
|
||||
TextWidget printTimeElapsed;
|
||||
{
|
||||
public class PrintProgressBar : GuiWidget
|
||||
{
|
||||
double currentPercent = 0;
|
||||
RGBA_Bytes completeColor = new RGBA_Bytes(255, 255, 255);
|
||||
TextWidget printTimeRemaining;
|
||||
TextWidget printTimeElapsed;
|
||||
|
||||
public bool WidgetIsExtended { get; set; }
|
||||
bool widgetIsExtended;
|
||||
public bool WidgetIsExtended
|
||||
{
|
||||
get { return widgetIsExtended; }
|
||||
|
||||
public PrintProgressBar()
|
||||
{
|
||||
MinimumSize = new Vector2(0, 24);
|
||||
HAnchor = HAnchor.ParentLeftRight;
|
||||
BackgroundColor = ActiveTheme.Instance.SecondaryAccentColor;
|
||||
Margin = new BorderDouble(0);
|
||||
set
|
||||
{
|
||||
widgetIsExtended = value;
|
||||
ToggleExtendedDisplayProperties();
|
||||
}
|
||||
}
|
||||
|
||||
FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.LeftToRight);
|
||||
container.AnchorAll();
|
||||
container.Padding = new BorderDouble(6,0);
|
||||
void ToggleExtendedDisplayProperties()
|
||||
{
|
||||
if (!WidgetIsExtended)
|
||||
{
|
||||
this.Height = 48;
|
||||
indicatorWidget.Image = downImageBuffer;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Height = 24;
|
||||
indicatorWidget.Image = upImageBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
printTimeElapsed = new TextWidget("", pointSize:11);
|
||||
Agg.Image.ImageBuffer upImageBuffer;
|
||||
Agg.Image.ImageBuffer downImageBuffer;
|
||||
ImageWidget indicatorWidget;
|
||||
|
||||
public PrintProgressBar(bool widgetIsExtended = true)
|
||||
{
|
||||
MinimumSize = new Vector2(0, 24);
|
||||
|
||||
HAnchor = HAnchor.ParentLeftRight;
|
||||
BackgroundColor = ActiveTheme.Instance.SecondaryAccentColor;
|
||||
Margin = new BorderDouble(0);
|
||||
|
||||
FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.LeftToRight);
|
||||
container.AnchorAll();
|
||||
container.Padding = new BorderDouble(6, 0);
|
||||
|
||||
printTimeElapsed = new TextWidget("", pointSize: 11);
|
||||
printTimeElapsed.Printer.DrawFromHintedCache = true;
|
||||
printTimeElapsed.AutoExpandBoundsToText = true;
|
||||
printTimeElapsed.VAnchor = Agg.UI.VAnchor.ParentCenter;
|
||||
printTimeElapsed.AutoExpandBoundsToText = true;
|
||||
printTimeElapsed.VAnchor = Agg.UI.VAnchor.ParentCenter;
|
||||
|
||||
|
||||
printTimeRemaining = new TextWidget("", pointSize: 11);
|
||||
printTimeRemaining = new TextWidget("", pointSize: 11);
|
||||
printTimeRemaining.Printer.DrawFromHintedCache = true;
|
||||
printTimeRemaining.AutoExpandBoundsToText = true;
|
||||
printTimeRemaining.VAnchor = Agg.UI.VAnchor.ParentCenter;
|
||||
printTimeRemaining.VAnchor = Agg.UI.VAnchor.ParentCenter;
|
||||
|
||||
GuiWidget spacer = new GuiWidget();
|
||||
spacer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
|
||||
GuiWidget spacer = new GuiWidget();
|
||||
spacer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
|
||||
|
||||
container.AddChild(printTimeElapsed);
|
||||
container.AddChild(spacer);
|
||||
container.AddChild(printTimeRemaining);
|
||||
container.AddChild(printTimeElapsed);
|
||||
container.AddChild(spacer);
|
||||
container.AddChild(printTimeRemaining);
|
||||
|
||||
AddChild(container);
|
||||
AddChild(container);
|
||||
|
||||
if (UserSettings.Instance.get("ApplicationDisplayMode") == "touchscreen")
|
||||
{
|
||||
upImageBuffer = StaticData.Instance.LoadIcon("TouchScreen/arrow_up_32x24.png");
|
||||
downImageBuffer = StaticData.Instance.LoadIcon("TouchScreen/arrow_down_32x24.png");
|
||||
|
||||
indicatorWidget = new ImageWidget(upImageBuffer);
|
||||
indicatorWidget.HAnchor = HAnchor.ParentCenter;
|
||||
indicatorWidget.VAnchor = VAnchor.ParentCenter;
|
||||
|
||||
WidgetIsExtended = widgetIsExtended;
|
||||
|
||||
GuiWidget indicatorOverlay = new GuiWidget();
|
||||
indicatorOverlay.AnchorAll();
|
||||
indicatorOverlay.AddChild(indicatorWidget);
|
||||
|
||||
AddChild(indicatorOverlay);
|
||||
}
|
||||
|
||||
ClickWidget clickOverlay = new ClickWidget();
|
||||
clickOverlay.AnchorAll();
|
||||
|
|
@ -86,123 +136,124 @@ namespace MatterHackers.MatterControl
|
|||
|
||||
AddChild(clickOverlay);
|
||||
|
||||
AddHandlers();
|
||||
SetThemedColors();
|
||||
UpdatePrintStatus();
|
||||
UiThread.RunOnIdle(OnIdle);
|
||||
}
|
||||
AddHandlers();
|
||||
SetThemedColors();
|
||||
UpdatePrintStatus();
|
||||
UiThread.RunOnIdle(OnIdle);
|
||||
}
|
||||
|
||||
|
||||
event EventHandler unregisterEvents;
|
||||
void AddHandlers()
|
||||
{
|
||||
PrinterConnectionAndCommunication.Instance.ActivePrintItemChanged.RegisterEvent(Instance_PrintItemChanged, ref unregisterEvents);
|
||||
PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(Instance_PrintItemChanged, ref unregisterEvents);
|
||||
ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents);
|
||||
}
|
||||
event EventHandler unregisterEvents;
|
||||
void AddHandlers()
|
||||
{
|
||||
PrinterConnectionAndCommunication.Instance.ActivePrintItemChanged.RegisterEvent(Instance_PrintItemChanged, ref unregisterEvents);
|
||||
PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(Instance_PrintItemChanged, ref unregisterEvents);
|
||||
ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents);
|
||||
}
|
||||
|
||||
public void onProgressBarClick(object sender, EventArgs e)
|
||||
public void onProgressBarClick(object sender, EventArgs e)
|
||||
{
|
||||
ApplicationController.Instance.MainView.ToggleTopContainer();
|
||||
}
|
||||
|
||||
public override void OnClosed(EventArgs e)
|
||||
{
|
||||
if (unregisterEvents != null)
|
||||
{
|
||||
unregisterEvents(this, null);
|
||||
}
|
||||
base.OnClosed(e);
|
||||
}
|
||||
public override void OnClosed(EventArgs e)
|
||||
{
|
||||
if (unregisterEvents != null)
|
||||
{
|
||||
unregisterEvents(this, null);
|
||||
}
|
||||
|
||||
private void SetThemedColors()
|
||||
{
|
||||
this.printTimeElapsed.TextColor = ActiveTheme.Instance.PrimaryAccentColor;
|
||||
this.printTimeRemaining.TextColor = ActiveTheme.Instance.PrimaryAccentColor;
|
||||
this.BackgroundColor = ActiveTheme.Instance.SecondaryAccentColor;
|
||||
}
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
public void ThemeChanged(object sender, EventArgs e)
|
||||
{
|
||||
//Set background color to new theme
|
||||
SetThemedColors();
|
||||
this.Invalidate();
|
||||
}
|
||||
private void SetThemedColors()
|
||||
{
|
||||
this.printTimeElapsed.TextColor = ActiveTheme.Instance.PrimaryAccentColor;
|
||||
this.printTimeRemaining.TextColor = ActiveTheme.Instance.PrimaryAccentColor;
|
||||
this.BackgroundColor = ActiveTheme.Instance.SecondaryAccentColor;
|
||||
}
|
||||
|
||||
void Instance_PrintItemChanged(object sender, EventArgs e)
|
||||
{
|
||||
UpdatePrintStatus();
|
||||
}
|
||||
public void ThemeChanged(object sender, EventArgs e)
|
||||
{
|
||||
//Set background color to new theme
|
||||
SetThemedColors();
|
||||
this.Invalidate();
|
||||
}
|
||||
|
||||
void OnIdle(object state)
|
||||
{
|
||||
currentPercent = PrinterConnectionAndCommunication.Instance.PercentComplete;
|
||||
UpdatePrintStatus();
|
||||
void Instance_PrintItemChanged(object sender, EventArgs e)
|
||||
{
|
||||
UpdatePrintStatus();
|
||||
}
|
||||
|
||||
if (!WidgetHasBeenClosed)
|
||||
{
|
||||
UiThread.RunOnIdle(OnIdle, 1);
|
||||
}
|
||||
}
|
||||
void OnIdle(object state)
|
||||
{
|
||||
currentPercent = PrinterConnectionAndCommunication.Instance.PercentComplete;
|
||||
UpdatePrintStatus();
|
||||
|
||||
private void UpdatePrintStatus()
|
||||
{
|
||||
if (PrinterConnectionAndCommunication.Instance.ActivePrintItem == null)
|
||||
{
|
||||
printTimeElapsed.Text = string.Format("");
|
||||
printTimeRemaining.Text = string.Format("");
|
||||
}
|
||||
else
|
||||
{
|
||||
int secondsPrinted = PrinterConnectionAndCommunication.Instance.SecondsPrinted;
|
||||
int hoursPrinted = (int)(secondsPrinted / (60 * 60));
|
||||
int minutesPrinted = (int)(secondsPrinted / 60 - hoursPrinted * 60);
|
||||
secondsPrinted = secondsPrinted % 60;
|
||||
if (!WidgetHasBeenClosed)
|
||||
{
|
||||
UiThread.RunOnIdle(OnIdle, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePrintStatus()
|
||||
{
|
||||
if (PrinterConnectionAndCommunication.Instance.ActivePrintItem == null)
|
||||
{
|
||||
printTimeElapsed.Text = string.Format("");
|
||||
printTimeRemaining.Text = string.Format("");
|
||||
}
|
||||
else
|
||||
{
|
||||
int secondsPrinted = PrinterConnectionAndCommunication.Instance.SecondsPrinted;
|
||||
int hoursPrinted = (int)(secondsPrinted / (60 * 60));
|
||||
int minutesPrinted = (int)(secondsPrinted / 60 - hoursPrinted * 60);
|
||||
secondsPrinted = secondsPrinted % 60;
|
||||
|
||||
if (secondsPrinted > 0)
|
||||
{
|
||||
if (hoursPrinted > 0)
|
||||
{
|
||||
printTimeElapsed.Text = string.Format("{0}:{1:00}:{2:00}",
|
||||
hoursPrinted,
|
||||
minutesPrinted,
|
||||
secondsPrinted);
|
||||
}
|
||||
else
|
||||
{
|
||||
printTimeElapsed.Text = string.Format("{0}:{1:00}",
|
||||
minutesPrinted,
|
||||
secondsPrinted);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printTimeElapsed.Text = string.Format("");
|
||||
}
|
||||
if (secondsPrinted > 0)
|
||||
{
|
||||
if (hoursPrinted > 0)
|
||||
{
|
||||
printTimeElapsed.Text = string.Format("{0}:{1:00}:{2:00}",
|
||||
hoursPrinted,
|
||||
minutesPrinted,
|
||||
secondsPrinted);
|
||||
}
|
||||
else
|
||||
{
|
||||
printTimeElapsed.Text = string.Format("{0}:{1:00}",
|
||||
minutesPrinted,
|
||||
secondsPrinted);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printTimeElapsed.Text = string.Format("");
|
||||
}
|
||||
|
||||
string printPercentRemainingText = string.Format("{0:0.0}%", currentPercent);
|
||||
string printPercentRemainingText = string.Format("{0:0.0}%", currentPercent);
|
||||
|
||||
if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting || PrinterConnectionAndCommunication.Instance.PrinterIsPaused)
|
||||
{
|
||||
printTimeRemaining.Text = printPercentRemainingText;
|
||||
}
|
||||
else if (PrinterConnectionAndCommunication.Instance.PrintIsFinished)
|
||||
{
|
||||
printTimeRemaining.Text = "Done!";
|
||||
}
|
||||
else
|
||||
{
|
||||
printTimeRemaining.Text = string.Format("");
|
||||
}
|
||||
}
|
||||
this.Invalidate();
|
||||
}
|
||||
if (PrinterConnectionAndCommunication.Instance.PrinterIsPrinting || PrinterConnectionAndCommunication.Instance.PrinterIsPaused)
|
||||
{
|
||||
printTimeRemaining.Text = printPercentRemainingText;
|
||||
}
|
||||
else if (PrinterConnectionAndCommunication.Instance.PrintIsFinished)
|
||||
{
|
||||
printTimeRemaining.Text = "Done!";
|
||||
}
|
||||
else
|
||||
{
|
||||
printTimeRemaining.Text = string.Format("");
|
||||
}
|
||||
}
|
||||
this.Invalidate();
|
||||
}
|
||||
|
||||
public override void OnDraw(Graphics2D graphics2D)
|
||||
{
|
||||
graphics2D.FillRectangle(0, 0, Width * currentPercent / 100, Height, completeColor);
|
||||
base.OnDraw(graphics2D);
|
||||
|
||||
}
|
||||
}
|
||||
public override void OnDraw(Graphics2D graphics2D)
|
||||
{
|
||||
graphics2D.FillRectangle(0, 0, Width * currentPercent / 100, Height, completeColor);
|
||||
|
||||
base.OnDraw(graphics2D);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue