Refactor temperature widgets
This commit is contained in:
parent
24b1756139
commit
cbe60da89a
3 changed files with 75 additions and 100 deletions
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (c) 2014, Kevin Pope
|
||||
Copyright (c) 2017, Kevin Pope, John Lewin
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -27,24 +27,30 @@ of the authors and should not be interpreted as representing official policies,
|
|||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Agg.VertexSource;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
using System;
|
||||
|
||||
namespace MatterHackers.MatterControl.ActionBar
|
||||
{
|
||||
internal class TemperatureWidgetBase : GuiWidget
|
||||
{
|
||||
protected TextWidget currentTempIndicator;
|
||||
private TextWidget currentTempIndicator;
|
||||
protected TextWidget temperatureTypeName;
|
||||
protected Button preheatButton;
|
||||
|
||||
protected TextImageButtonFactory whiteButtonFactory = new TextImageButtonFactory();
|
||||
protected TextImageButtonFactory whiteButtonFactory = new TextImageButtonFactory()
|
||||
{
|
||||
FixedHeight = 18 * GuiWidget.DeviceScale,
|
||||
fontSize = 7,
|
||||
normalFillColor = RGBA_Bytes.White,
|
||||
normalTextColor = RGBA_Bytes.DarkGray,
|
||||
};
|
||||
|
||||
private RGBA_Bytes borderColor = new RGBA_Bytes(255, 255, 255);
|
||||
private static RGBA_Bytes borderColor = new RGBA_Bytes(255, 255, 255);
|
||||
private int borderWidth = 2;
|
||||
|
||||
public string IndicatorValue
|
||||
|
|
@ -62,99 +68,73 @@ namespace MatterHackers.MatterControl.ActionBar
|
|||
}
|
||||
}
|
||||
|
||||
private EventHandler unregisterEvents;
|
||||
|
||||
public TemperatureWidgetBase(string textValue)
|
||||
: base(52 * GuiWidget.DeviceScale, 52 * GuiWidget.DeviceScale)
|
||||
{
|
||||
whiteButtonFactory.FixedHeight = 18 * GuiWidget.DeviceScale;
|
||||
whiteButtonFactory.fontSize = 7;
|
||||
whiteButtonFactory.normalFillColor = RGBA_Bytes.White;
|
||||
whiteButtonFactory.normalTextColor = RGBA_Bytes.DarkGray;
|
||||
|
||||
this.BackgroundColor = new RGBA_Bytes(255, 255, 255, 200);
|
||||
this.Margin = new BorderDouble(0, 2) * GuiWidget.DeviceScale;
|
||||
|
||||
temperatureTypeName = new TextWidget("", pointSize: 8);
|
||||
temperatureTypeName.AutoExpandBoundsToText = true;
|
||||
temperatureTypeName.HAnchor = HAnchor.ParentCenter;
|
||||
temperatureTypeName.VAnchor = VAnchor.ParentTop;
|
||||
temperatureTypeName.Margin = new BorderDouble(0, 3);
|
||||
temperatureTypeName.TextColor = ActiveTheme.Instance.SecondaryAccentColor;
|
||||
temperatureTypeName.Visible = false;
|
||||
temperatureTypeName = new TextWidget("", pointSize: 8)
|
||||
{
|
||||
AutoExpandBoundsToText = true,
|
||||
HAnchor = HAnchor.ParentCenter,
|
||||
VAnchor = VAnchor.ParentTop,
|
||||
Margin = new BorderDouble(0, 3),
|
||||
TextColor = ActiveTheme.Instance.SecondaryAccentColor,
|
||||
Visible = false
|
||||
};
|
||||
this.AddChild(temperatureTypeName);
|
||||
|
||||
currentTempIndicator = new TextWidget(textValue, pointSize: 11);
|
||||
currentTempIndicator.TextColor = ActiveTheme.Instance.PrimaryAccentColor;
|
||||
currentTempIndicator.HAnchor = HAnchor.ParentCenter;
|
||||
currentTempIndicator.VAnchor = VAnchor.ParentCenter;
|
||||
currentTempIndicator.AutoExpandBoundsToText = true;
|
||||
currentTempIndicator = new TextWidget(textValue, pointSize: 11)
|
||||
{
|
||||
TextColor = ActiveTheme.Instance.PrimaryAccentColor,
|
||||
HAnchor = HAnchor.ParentCenter,
|
||||
VAnchor = VAnchor.ParentCenter,
|
||||
AutoExpandBoundsToText = true
|
||||
};
|
||||
this.AddChild(currentTempIndicator);
|
||||
|
||||
GuiWidget buttonContainer = new GuiWidget();
|
||||
buttonContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
|
||||
buttonContainer.Height = 18 * GuiWidget.DeviceScale;
|
||||
var buttonContainer = new GuiWidget()
|
||||
{
|
||||
HAnchor = Agg.UI.HAnchor.ParentLeftRight,
|
||||
Height = 18 * GuiWidget.DeviceScale
|
||||
};
|
||||
this.AddChild(buttonContainer);
|
||||
|
||||
preheatButton = whiteButtonFactory.Generate("Preheat".Localize().ToUpper());
|
||||
preheatButton.Cursor = Cursors.Hand;
|
||||
preheatButton.Visible = false;
|
||||
|
||||
preheatButton.Click += (s, e) => SetTargetTemperature();
|
||||
buttonContainer.AddChild(preheatButton);
|
||||
|
||||
this.AddChild(temperatureTypeName);
|
||||
this.AddChild(currentTempIndicator);
|
||||
this.AddChild(buttonContainer);
|
||||
|
||||
this.MouseEnterBounds += onEnterBounds;
|
||||
this.MouseLeaveBounds += onLeaveBounds;
|
||||
this.preheatButton.Click += onPreheatButtonClick;
|
||||
}
|
||||
|
||||
public override void OnClosed(EventArgs e)
|
||||
{
|
||||
if (unregisterEvents != null)
|
||||
{
|
||||
unregisterEvents(this, null);
|
||||
}
|
||||
base.OnClosed(e);
|
||||
}
|
||||
|
||||
public void ThemeChanged(object sender, EventArgs e)
|
||||
{
|
||||
this.currentTempIndicator.TextColor = ActiveTheme.Instance.PrimaryAccentColor;
|
||||
this.Invalidate();
|
||||
}
|
||||
|
||||
private void onEnterBounds(Object sender, EventArgs e)
|
||||
public override void OnMouseEnterBounds(MouseEventArgs mouseEvent)
|
||||
{
|
||||
temperatureTypeName.Visible = true;
|
||||
if (PrinterConnectionAndCommunication.Instance.PrinterIsConnected && !PrinterConnectionAndCommunication.Instance.PrinterIsPrinting)
|
||||
{
|
||||
preheatButton.Visible = true;
|
||||
}
|
||||
|
||||
base.OnMouseEnterBounds(mouseEvent);
|
||||
}
|
||||
|
||||
private void onLeaveBounds(Object sender, EventArgs e)
|
||||
public override void OnMouseLeaveBounds(MouseEventArgs mouseEvent)
|
||||
{
|
||||
temperatureTypeName.Visible = false;
|
||||
preheatButton.Visible = false;
|
||||
|
||||
base.OnMouseLeaveBounds(mouseEvent);
|
||||
}
|
||||
|
||||
public override void OnDraw(Graphics2D graphics2D)
|
||||
{
|
||||
base.OnDraw(graphics2D);
|
||||
|
||||
RectangleDouble Bounds = LocalBounds;
|
||||
RoundedRect borderRect = new RoundedRect(this.LocalBounds, 0);
|
||||
Stroke strokeRect = new Stroke(borderRect, borderWidth);
|
||||
graphics2D.Render(strokeRect, borderColor);
|
||||
var borderRect = new RoundedRect(this.LocalBounds, 0);
|
||||
graphics2D.Render(new Stroke(borderRect, borderWidth), borderColor);
|
||||
}
|
||||
|
||||
private void onPreheatButtonClick(object sender, EventArgs e)
|
||||
{
|
||||
SetTargetTemperature();
|
||||
}
|
||||
|
||||
protected virtual void SetTargetTemperature()
|
||||
{
|
||||
}
|
||||
protected virtual void SetTargetTemperature() { }
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue