mattercontrol/PrinterControls/PrinterConnections/BaseConnectionWidget.cs

221 lines
5.3 KiB
C#
Raw Normal View History

2015-04-08 15:20:10 -07:00
using MatterHackers.Agg;
using MatterHackers.Agg.Platform;
2014-01-29 19:09:30 -08:00
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.Localizations;
2014-01-29 19:09:30 -08:00
using MatterHackers.MatterControl.DataStorage;
2016-04-18 11:31:31 -07:00
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.SerialPortCommunication.FrostedSerial;
2015-04-08 15:20:10 -07:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
2014-01-29 19:09:30 -08:00
namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
{
2015-04-08 15:20:10 -07:00
public class SerialPortIndexRadioButton : RadioButton
{
public string PortValue;
public SerialPortIndexRadioButton(string label, string value)
: base(label)
{
PortValue = value;
}
}
public class PrinterSelectRadioButton : RadioButton
{
2016-04-18 11:31:31 -07:00
public PrinterInfo printer;
2015-04-08 15:20:10 -07:00
2016-04-18 11:31:31 -07:00
public PrinterSelectRadioButton(PrinterInfo printer)
2015-04-08 15:20:10 -07:00
: base(printer.Name)
{
this.printer = printer;
}
}
public class OptionContainer : GuiWidget
{
2017-10-31 11:43:25 -07:00
private Color borderColor = new Color(63, 63, 70);
private Color backgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
2015-04-08 15:20:10 -07:00
public OptionContainer()
: base()
{
this.Margin = new BorderDouble(2, 5, 2, 0);
this.BackgroundColor = backgroundColor;
}
public override void OnDraw(Agg.Graphics2D graphics2D)
{
base.OnDraw(graphics2D);
graphics2D.Rectangle(LocalBounds, borderColor);
}
}
public class ActionLinkFactory
{
public ActionLink Generate(string linkText, int fontSize, EventHandler<MouseEventArgs> clickEvent)
2015-04-08 15:20:10 -07:00
{
ActionLink actionLink = new ActionLink(linkText, fontSize);
if (clickEvent != null)
{
actionLink.MouseUp += clickEvent;
2015-04-08 15:20:10 -07:00
}
return actionLink;
}
}
public class ActionLink : TextWidget
{
private bool isUnderlined = true;
public ActionLink(string text, int fontSize = 10)
: base(text, 0, 0, fontSize)
{
this.Selectable = true;
this.Margin = new BorderDouble(3, 0, 3, 0);
this.VAnchor = VAnchor.Stretch;
2015-04-08 15:20:10 -07:00
this.MouseEnter += new EventHandler(onMouse_Enter);
this.MouseLeave += new EventHandler(onMouse_Leave);
this.Cursor = Cursors.Hand;
}
public override void OnDraw(Agg.Graphics2D graphics2D)
{
base.OnDraw(graphics2D);
if (this.isUnderlined)
{
//Printer.TypeFaceStyle.DoUnderline = true;
RectangleDouble underline = new RectangleDouble(LocalBounds.Left, LocalBounds.Bottom, LocalBounds.Right, LocalBounds.Bottom);
graphics2D.Rectangle(underline, this.TextColor);
}
}
private void onMouse_Enter(object sender, EventArgs args)
{
this.isUnderlined = false;
this.Invalidate();
}
private void onMouse_Leave(object sender, EventArgs args)
{
this.isUnderlined = true;
this.Invalidate();
}
}
public class PrinterActionLink : ActionLink
{
2016-04-18 11:31:31 -07:00
public PrinterInfo LinkedPrinter;
2015-04-08 15:20:10 -07:00
2016-04-18 11:31:31 -07:00
public PrinterActionLink(string text, PrinterInfo printer, int fontSize = 10)
2015-04-08 15:20:10 -07:00
: base(text, fontSize)
{
this.LinkedPrinter = printer;
}
}
public class DetailRow : FlowLayoutWidget
{
public List<GuiWidget> showOnHoverChildren = new List<GuiWidget>();
public DetailRow()
: base(FlowDirection.LeftToRight)
{
this.MouseEnter += new EventHandler(onMouse_Enter);
this.MouseLeave += new EventHandler(onMouse_Leave);
}
private void onMouse_Enter(object sender, EventArgs args)
{
foreach (GuiWidget item in showOnHoverChildren)
{
item.Visible = true;
}
this.Invalidate();
}
private void onMouse_Leave(object sender, EventArgs args)
{
foreach (GuiWidget item in showOnHoverChildren)
{
item.Visible = false;
}
this.Invalidate();
}
}
public class LabelContainer : GuiWidget
{
2017-10-31 11:43:25 -07:00
private Color backgroundColor = new Color(0, 140, 158);
2015-04-08 15:20:10 -07:00
public LabelContainer()
: base()
{
this.Margin = new BorderDouble(2, -2, 2, 5);
this.Padding = new BorderDouble(3);
this.BackgroundColor = backgroundColor;
}
public override void OnDraw(Agg.Graphics2D graphics2D)
{
base.OnDraw(graphics2D);
}
}
2014-01-29 19:09:30 -08:00
//Base widget for use in ButtonStatesViewWidget
2015-04-08 15:20:10 -07:00
public class ControlButtonViewBase : GuiWidget
2014-01-29 19:09:30 -08:00
{
2017-10-31 11:43:25 -07:00
protected Color fillColor;
protected Color borderColor;
2014-01-29 19:09:30 -08:00
protected double borderWidth;
protected double borderRadius;
protected double padding;
public ControlButtonViewBase(string label,
2015-04-08 15:20:10 -07:00
double width,
double height,
double textHeight,
double borderWidth,
double borderRadius,
double padding,
2017-10-31 11:43:25 -07:00
Color textColor,
Color fillColor,
Color borderColor)
2015-04-08 15:20:10 -07:00
: base(width, height)
2014-01-29 19:09:30 -08:00
{
this.borderRadius = borderRadius;
this.borderWidth = borderWidth;
this.fillColor = fillColor;
this.borderColor = borderColor;
this.padding = padding;
TextWidget buttonText = new TextWidget(label, textHeight);
buttonText.VAnchor = VAnchor.Center;
buttonText.HAnchor = HAnchor.Center;
2014-01-29 19:09:30 -08:00
buttonText.TextColor = textColor;
2015-04-08 15:20:10 -07:00
//this.AnchorAll();
this.AddChild(buttonText);
2014-01-29 19:09:30 -08:00
}
public override void OnDraw(Graphics2D graphics2D)
2015-04-08 15:20:10 -07:00
{
RectangleDouble Bounds = LocalBounds;
2014-01-29 19:09:30 -08:00
RoundedRect rectBorder = new RoundedRect(Bounds, this.borderRadius);
graphics2D.Render(rectBorder, borderColor);
RectangleDouble insideBounds = Bounds;
insideBounds.Inflate(-this.borderWidth);
2015-04-08 15:20:10 -07:00
RoundedRect rectInside = new RoundedRect(insideBounds, Math.Max(this.borderRadius - this.borderWidth, 0));
2014-01-29 19:09:30 -08:00
graphics2D.Render(rectInside, this.fillColor);
2015-04-08 15:20:10 -07:00
2014-01-29 19:09:30 -08:00
base.OnDraw(graphics2D);
}
}
2015-04-08 15:20:10 -07:00
}