Ran code maid against this code.

This commit is contained in:
Lars Brubaker 2015-04-08 15:20:10 -07:00
parent 1445945d9c
commit 591528ee91
309 changed files with 139399 additions and 140129 deletions

View file

@ -2,32 +2,32 @@
namespace MatterHackers.MatterControl
{
public class ConditionalClickWidget : ClickWidget
{
private Func<bool> enabledCallback;
public class ConditionalClickWidget : ClickWidget
{
private Func<bool> enabledCallback;
public ConditionalClickWidget(Func<bool> enabledCallback)
{
this.enabledCallback = enabledCallback;
}
public ConditionalClickWidget(Func<bool> enabledCallback)
{
this.enabledCallback = enabledCallback;
}
// The ConditionalClickWidget provides a mechanism that allows the Enable property to be bound
// to a Delegate that resolves the value. This is a readonly value supplied via the constructor
// and should not be assigned after construction
public override bool Enabled
{
get
{
return this.enabledCallback();
}
// The ConditionalClickWidget provides a mechanism that allows the Enable property to be bound
// to a Delegate that resolves the value. This is a readonly value supplied via the constructor
// and should not be assigned after construction
public override bool Enabled
{
get
{
return this.enabledCallback();
}
set
{
Console.WriteLine("Attempted to set readonly Enabled property on ConditionalClickWidget");
set
{
Console.WriteLine("Attempted to set readonly Enabled property on ConditionalClickWidget");
#if DEBUG
throw new InvalidOperationException("Cannot set Enabled on ConditionalClickWidget");
throw new InvalidOperationException("Cannot set Enabled on ConditionalClickWidget");
#endif
}
}
}
}
}
}
}
}

View file

@ -3,13 +3,13 @@ Copyright (c) 2015, Kevin Pope
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@ -23,59 +23,56 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
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.MatterControl.DataStorage;
using MatterHackers.Agg.VertexSource;
using System;
namespace MatterHackers.MatterControl
{
public class DropDownButtonBase : GuiWidget
{
private RGBA_Bytes fillColor;
private RGBA_Bytes borderColor;
RGBA_Bytes fillColor;
RGBA_Bytes borderColor;
double borderWidth;
private double borderWidth;
//Set Defaults
public DropDownButtonBase(string label, RGBA_Bytes fillColor, RGBA_Bytes borderColor, RGBA_Bytes textColor, double borderWidth, BorderDouble margin, int fontSize = 12, FlowDirection flowDirection = FlowDirection.LeftToRight, double height = 40)
{
FlowLayoutWidget container = new FlowLayoutWidget ();
container.Padding = new BorderDouble (0);
container.Margin = new BorderDouble (0);
if(label != "")
FlowLayoutWidget container = new FlowLayoutWidget();
container.Padding = new BorderDouble(0);
container.Margin = new BorderDouble(0);
if (label != "")
{
TextWidget text = new TextWidget (label ,pointSize: fontSize, textColor: textColor);
TextWidget text = new TextWidget(label, pointSize: fontSize, textColor: textColor);
text.VAnchor = VAnchor.ParentCenter;
text.Padding = new BorderDouble (0, 0);
container.AddChild (text);
text.Padding = new BorderDouble(0, 0);
container.AddChild(text);
}
GuiWidget arrow = new GuiWidget (20, height);
GuiWidget arrow = new GuiWidget(20, height);
arrow.VAnchor = VAnchor.ParentCenter;
container.AddChild (arrow);
this.AddChild (container);
container.AddChild(arrow);
this.AddChild(container);
this.Padding = new BorderDouble (0, 0);
this.Padding = new BorderDouble(0, 0);
this.fillColor = fillColor;
this.borderColor = borderColor;
this.borderWidth = borderWidth;
this.HAnchor = HAnchor.FitToChildren;
}
public override void OnDraw (Graphics2D graphics2D)
public override void OnDraw(Graphics2D graphics2D)
{
DrawBorder (graphics2D);
DrawBackground (graphics2D);
DrawBorder(graphics2D);
DrawBackground(graphics2D);
base.OnDraw (graphics2D);
base.OnDraw(graphics2D);
}
private void DrawBorder(Graphics2D graphics2D)
@ -84,7 +81,7 @@ namespace MatterHackers.MatterControl
{
RectangleDouble boarderRectangle = LocalBounds;
RoundedRect rectBorder = new RoundedRect(boarderRectangle,0);
RoundedRect rectBorder = new RoundedRect(boarderRectangle, 0);
graphics2D.Render(new Stroke(rectBorder, borderWidth), borderColor);
}
@ -96,15 +93,13 @@ namespace MatterHackers.MatterControl
{
RectangleDouble insideBounds = LocalBounds;
insideBounds.Inflate(-this.borderWidth);
RoundedRect rectInside = new RoundedRect(insideBounds,0);
RoundedRect rectInside = new RoundedRect(insideBounds, 0);
graphics2D.Render(rectInside, this.fillColor);
}
}
}
public class DropDownMenuFactory
{
public BorderDouble Margin = new BorderDouble(0, 0);
@ -130,13 +125,13 @@ namespace MatterHackers.MatterControl
public double FixedWidth = 10;
public double FixedHeight = 30;
public DropDownMenuFactory ()
public DropDownMenuFactory()
{
}
public DynamicDropDownMenu Generate(string label = "", TupleList<string,Func<bool>> optionList = null, Direction direction = Direction.Down)
public DynamicDropDownMenu Generate(string label = "", TupleList<string, Func<bool>> optionList = null, Direction direction = Direction.Down)
{
DynamicDropDownMenu menu = new DynamicDropDownMenu (label, CreateButtonViewStates(label),direction);
DynamicDropDownMenu menu = new DynamicDropDownMenu(label, CreateButtonViewStates(label), direction);
menu.VAnchor = VAnchor.ParentCenter;
menu.HAnchor = HAnchor.FitToChildren;
menu.MenuAsWideAsItems = false;
@ -146,11 +141,11 @@ namespace MatterHackers.MatterControl
menu.BorderColor = normalBorderColor;
menu.BackgroundColor = menu.NormalColor;
if(optionList != null)
if (optionList != null)
{
foreach(Tuple<string,Func<bool>> option in optionList)
foreach (Tuple<string, Func<bool>> option in optionList)
{
menu.addItem (option.Item1, option.Item2);
menu.addItem(option.Item1, option.Item2);
}
}
@ -161,16 +156,15 @@ namespace MatterHackers.MatterControl
{
//Create the multi-state button view
ButtonViewStates buttonViewWidget = new ButtonViewStates(
new DropDownButtonBase(label, normalFillColor, normalBorderColor, normalTextColor, borderWidth, Margin, fontSize, FlowDirection.LeftToRight, FixedHeight),
new DropDownButtonBase(label, hoverFillColor, hoverBorderColor, hoverTextColor, borderWidth, Margin, fontSize, FlowDirection.LeftToRight, FixedHeight),
new DropDownButtonBase(label, pressedFillColor, pressedBorderColor, pressedTextColor, borderWidth, Margin, fontSize, FlowDirection.LeftToRight, FixedHeight),
new DropDownButtonBase(label, disabledFillColor, disabledBorderColor, disabledTextColor, borderWidth, Margin, fontSize, FlowDirection.LeftToRight, FixedHeight)
new DropDownButtonBase(label, normalFillColor, normalBorderColor, normalTextColor, borderWidth, Margin, fontSize, FlowDirection.LeftToRight, FixedHeight),
new DropDownButtonBase(label, hoverFillColor, hoverBorderColor, hoverTextColor, borderWidth, Margin, fontSize, FlowDirection.LeftToRight, FixedHeight),
new DropDownButtonBase(label, pressedFillColor, pressedBorderColor, pressedTextColor, borderWidth, Margin, fontSize, FlowDirection.LeftToRight, FixedHeight),
new DropDownButtonBase(label, disabledFillColor, disabledBorderColor, disabledTextColor, borderWidth, Margin, fontSize, FlowDirection.LeftToRight, FixedHeight)
);
buttonViewWidget.Padding = new BorderDouble (0, 0);
buttonViewWidget.Padding = new BorderDouble(0, 0);
return buttonViewWidget;
}
}
}
}

View file

@ -1,55 +1,51 @@
using System.IO;
using MatterHackers.Agg;
using MatterHackers.Agg;
using MatterHackers.Agg.ImageProcessing;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.MatterControl.DataStorage;
namespace MatterHackers.MatterControl
{
public class ImageButtonFactory
{
public bool invertImageColor = true;
public Button Generate(string normalImageName, string hoverImageName, string pressedImageName = null, string disabledImageName = null)
{
public class ImageButtonFactory
{
public bool invertImageColor = true;
if (pressedImageName == null)
{
pressedImageName = hoverImageName;
}
public Button Generate(string normalImageName, string hoverImageName, string pressedImageName = null, string disabledImageName = null)
{
if (pressedImageName == null)
{
pressedImageName = hoverImageName;
}
if (disabledImageName == null)
{
disabledImageName = normalImageName;
}
if (disabledImageName == null)
{
disabledImageName = normalImageName;
}
Agg.Image.ImageBuffer normalImage = StaticData.Instance.LoadIcon(normalImageName);
Agg.Image.ImageBuffer pressedImage = StaticData.Instance.LoadIcon(pressedImageName);
Agg.Image.ImageBuffer hoverImage = StaticData.Instance.LoadIcon(hoverImageName);
Agg.Image.ImageBuffer disabledImage = StaticData.Instance.LoadIcon(disabledImageName);
Agg.Image.ImageBuffer normalImage = StaticData.Instance.LoadIcon(normalImageName);
Agg.Image.ImageBuffer pressedImage = StaticData.Instance.LoadIcon(pressedImageName);
Agg.Image.ImageBuffer hoverImage = StaticData.Instance.LoadIcon(hoverImageName);
Agg.Image.ImageBuffer disabledImage = StaticData.Instance.LoadIcon(disabledImageName);
if (!ActiveTheme.Instance.IsDarkTheme && invertImageColor)
{
InvertLightness.DoInvertLightness(normalImage);
InvertLightness.DoInvertLightness(pressedImage);
InvertLightness.DoInvertLightness(hoverImage);
InvertLightness.DoInvertLightness(disabledImage);
}
if (!ActiveTheme.Instance.IsDarkTheme && invertImageColor)
{
InvertLightness.DoInvertLightness(normalImage);
InvertLightness.DoInvertLightness(pressedImage);
InvertLightness.DoInvertLightness(hoverImage);
InvertLightness.DoInvertLightness(disabledImage);
}
ButtonViewStates buttonViewWidget = new ButtonViewStates(
new ImageWidget(normalImage),
new ImageWidget(hoverImage),
new ImageWidget(pressedImage),
new ImageWidget(disabledImage)
);
ButtonViewStates buttonViewWidget = new ButtonViewStates(
new ImageWidget(normalImage),
new ImageWidget(hoverImage),
new ImageWidget(pressedImage),
new ImageWidget(disabledImage)
);
//Create button based on view container widget
Button imageButton = new Button(0, 0, buttonViewWidget);
imageButton.Margin = new BorderDouble(0);
imageButton.Padding = new BorderDouble(0);
return imageButton;
}
}
}
//Create button based on view container widget
Button imageButton = new Button(0, 0, buttonViewWidget);
imageButton.Margin = new BorderDouble(0);
imageButton.Padding = new BorderDouble(0);
return imageButton;
}
}
}

View file

@ -1,158 +1,153 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.PolygonMesh;
using MatterHackers.VectorMath;
using MatterHackers.Agg.VertexSource;
using System;
namespace MatterHackers.MatterControl
{
public class ChangeTextColorEventArgs : EventArgs
{
public RGBA_Bytes color;
public ChangeTextColorEventArgs(RGBA_Bytes color)
{
this.color = color;
}
}
public class ChangeTextColorEventArgs : EventArgs
{
public RGBA_Bytes color;
//Base widget for use in ButtonStatesViewWidget
public class LinkButtonViewBase : GuiWidget
{
protected RGBA_Bytes fillColor = new RGBA_Bytes(0, 0, 0, 0);
protected RGBA_Bytes borderColor = new RGBA_Bytes(0, 0, 0, 0);
protected double borderWidth = 0;
protected double borderRadius;
protected double padding;
protected bool isUnderlined = false;
public ChangeTextColorEventArgs(RGBA_Bytes color)
{
this.color = color;
}
}
public RGBA_Bytes TextColor { get; set; }
TextWidget buttonText;
//Base widget for use in ButtonStatesViewWidget
public class LinkButtonViewBase : GuiWidget
{
protected RGBA_Bytes fillColor = new RGBA_Bytes(0, 0, 0, 0);
protected RGBA_Bytes borderColor = new RGBA_Bytes(0, 0, 0, 0);
protected double borderWidth = 0;
protected double borderRadius;
protected double padding;
protected bool isUnderlined = false;
public LinkButtonViewBase(string label,
double textHeight,
double padding,
RGBA_Bytes textColor,
bool isUnderlined = false)
: base()
{
this.padding = padding;
this.TextColor = textColor;
this.isUnderlined = isUnderlined;
public RGBA_Bytes TextColor { get; set; }
buttonText = new TextWidget(label,pointSize:textHeight);
buttonText.VAnchor = VAnchor.ParentCenter;
buttonText.HAnchor = HAnchor.ParentCenter;
buttonText.TextColor = this.TextColor;
private TextWidget buttonText;
//this.AnchorAll();
this.AddChild(buttonText);
HAnchor = HAnchor.FitToChildren;
VAnchor = VAnchor.FitToChildren;
}
public LinkButtonViewBase(string label,
double textHeight,
double padding,
RGBA_Bytes textColor,
bool isUnderlined = false)
: base()
{
this.padding = padding;
this.TextColor = textColor;
this.isUnderlined = isUnderlined;
public override void SendToChildren(object objectToRout)
{
ChangeTextColorEventArgs changeColorEvent = objectToRout as ChangeTextColorEventArgs;
if (changeColorEvent != null)
{
buttonText.TextColor = changeColorEvent.color;
}
base.SendToChildren(objectToRout);
}
buttonText = new TextWidget(label, pointSize: textHeight);
buttonText.VAnchor = VAnchor.ParentCenter;
buttonText.HAnchor = HAnchor.ParentCenter;
buttonText.TextColor = this.TextColor;
public override void OnDraw(Agg.Graphics2D graphics2D)
{
RectangleDouble Bounds = LocalBounds;
RoundedRect rectBorder = new RoundedRect(Bounds, this.borderRadius);
//this.AnchorAll();
this.AddChild(buttonText);
HAnchor = HAnchor.FitToChildren;
VAnchor = VAnchor.FitToChildren;
}
graphics2D.Render(rectBorder, borderColor);
public override void SendToChildren(object objectToRout)
{
ChangeTextColorEventArgs changeColorEvent = objectToRout as ChangeTextColorEventArgs;
if (changeColorEvent != null)
{
buttonText.TextColor = changeColorEvent.color;
}
base.SendToChildren(objectToRout);
}
RectangleDouble insideBounds = Bounds;
insideBounds.Inflate(-this.borderWidth);
RoundedRect rectInside = new RoundedRect(insideBounds, Math.Max(this.borderRadius - this.borderWidth, 0));
public override void OnDraw(Agg.Graphics2D graphics2D)
{
RectangleDouble Bounds = LocalBounds;
RoundedRect rectBorder = new RoundedRect(Bounds, this.borderRadius);
graphics2D.Render(rectInside, this.fillColor);
graphics2D.Render(rectBorder, borderColor);
if (this.isUnderlined)
{
//Printer.TypeFaceStyle.DoUnderline = true;
RectangleDouble underline = new RectangleDouble(LocalBounds.Left, LocalBounds.Bottom, LocalBounds.Right, LocalBounds.Bottom);
graphics2D.Rectangle(underline, buttonText.TextColor);
}
base.OnDraw(graphics2D);
}
}
RectangleDouble insideBounds = Bounds;
insideBounds.Inflate(-this.borderWidth);
RoundedRect rectInside = new RoundedRect(insideBounds, Math.Max(this.borderRadius - this.borderWidth, 0));
public class LinkButtonFactory
{
public double fontSize = 14;
public double padding = 3;
public RGBA_Bytes fillColor = new RGBA_Bytes(63, 63, 70, 0);
public RGBA_Bytes borderColor = new RGBA_Bytes(37, 37, 38, 0);
public RGBA_Bytes textColor = ActiveTheme.Instance.PrimaryAccentColor;
public BorderDouble margin = new BorderDouble(0, 3);
graphics2D.Render(rectInside, this.fillColor);
public Button Generate(string buttonText)
{
//Widgets to show during the four button states
LinkButtonViewBase buttonWidgetPressed = getButtonWidgetPressed(buttonText);
LinkButtonViewBase buttonWidgetHover = getButtonWidgetHover(buttonText);
LinkButtonViewBase buttonWidgetNormal = getButtonWidgetNormal(buttonText);
LinkButtonViewBase buttonWidgetDisabled = getButtonWidgetDisabled(buttonText);
if (this.isUnderlined)
{
//Printer.TypeFaceStyle.DoUnderline = true;
RectangleDouble underline = new RectangleDouble(LocalBounds.Left, LocalBounds.Bottom, LocalBounds.Right, LocalBounds.Bottom);
graphics2D.Rectangle(underline, buttonText.TextColor);
}
//Create container for the three state widgets for the button
ButtonViewStates buttonViewWidget = new ButtonViewStates(buttonWidgetNormal, buttonWidgetHover, buttonWidgetPressed, buttonWidgetDisabled);
base.OnDraw(graphics2D);
}
}
//Create button based on view container widget
Button controlButton = new Button(0, 0, buttonViewWidget);
controlButton.Margin = margin;
controlButton.Cursor = Cursors.Hand;
public class LinkButtonFactory
{
public double fontSize = 14;
public double padding = 3;
public RGBA_Bytes fillColor = new RGBA_Bytes(63, 63, 70, 0);
public RGBA_Bytes borderColor = new RGBA_Bytes(37, 37, 38, 0);
public RGBA_Bytes textColor = ActiveTheme.Instance.PrimaryAccentColor;
public BorderDouble margin = new BorderDouble(0, 3);
return controlButton;
}
public Button Generate(string buttonText)
{
//Widgets to show during the four button states
LinkButtonViewBase buttonWidgetPressed = getButtonWidgetPressed(buttonText);
LinkButtonViewBase buttonWidgetHover = getButtonWidgetHover(buttonText);
LinkButtonViewBase buttonWidgetNormal = getButtonWidgetNormal(buttonText);
LinkButtonViewBase buttonWidgetDisabled = getButtonWidgetDisabled(buttonText);
private LinkButtonViewBase getButtonWidgetPressed(string buttonText)
{
LinkButtonViewBase widget = new LinkButtonViewBase(buttonText,
this.fontSize,
this.padding,
this.textColor);
return widget;
}
//Create container for the three state widgets for the button
ButtonViewStates buttonViewWidget = new ButtonViewStates(buttonWidgetNormal, buttonWidgetHover, buttonWidgetPressed, buttonWidgetDisabled);
private LinkButtonViewBase getButtonWidgetHover(string buttonText)
{
LinkButtonViewBase widget = new LinkButtonViewBase(buttonText,
this.fontSize,
this.padding,
this.textColor);
return widget;
}
//Create button based on view container widget
Button controlButton = new Button(0, 0, buttonViewWidget);
controlButton.Margin = margin;
controlButton.Cursor = Cursors.Hand;
public LinkButtonViewBase getButtonWidgetNormal(string buttonText)
{
LinkButtonViewBase widget = new LinkButtonViewBase(buttonText,
this.fontSize,
this.padding,
this.textColor,
true);
return widget;
}
return controlButton;
}
private LinkButtonViewBase getButtonWidgetDisabled(string buttonText)
{
LinkButtonViewBase widget = new LinkButtonViewBase(buttonText,
this.fontSize,
this.padding,
this.textColor);
return widget;
}
}
}
private LinkButtonViewBase getButtonWidgetPressed(string buttonText)
{
LinkButtonViewBase widget = new LinkButtonViewBase(buttonText,
this.fontSize,
this.padding,
this.textColor);
return widget;
}
private LinkButtonViewBase getButtonWidgetHover(string buttonText)
{
LinkButtonViewBase widget = new LinkButtonViewBase(buttonText,
this.fontSize,
this.padding,
this.textColor);
return widget;
}
public LinkButtonViewBase getButtonWidgetNormal(string buttonText)
{
LinkButtonViewBase widget = new LinkButtonViewBase(buttonText,
this.fontSize,
this.padding,
this.textColor,
true);
return widget;
}
private LinkButtonViewBase getButtonWidgetDisabled(string buttonText)
{
LinkButtonViewBase widget = new LinkButtonViewBase(buttonText,
this.fontSize,
this.padding,
this.textColor);
return widget;
}
}
}

View file

@ -1,251 +1,248 @@
using System;
using System.Diagnostics;
using MatterHackers.Agg;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.PolygonMesh;
using MatterHackers.VectorMath;
using MatterHackers.MatterControl.DataStorage;
using System;
using System.Diagnostics;
namespace MatterHackers.MatterControl
{
public class MHTextEditWidget : GuiWidget
{
Stopwatch timeSinceLastTextChanged = new Stopwatch();
protected TextEditWidget actuallTextEditWidget;
protected TextWidget noContentFieldDescription = null;
public TextEditWidget ActualTextEditWidget
{
get { return actuallTextEditWidget; }
}
public class MHTextEditWidget : GuiWidget
{
private Stopwatch timeSinceLastTextChanged = new Stopwatch();
protected TextEditWidget actuallTextEditWidget;
protected TextWidget noContentFieldDescription = null;
public MHTextEditWidget(string text = "", double x = 0, double y = 0, double pointSize = 12, double pixelWidth = 0, double pixelHeight = 0, bool multiLine = false, int tabIndex = 0, string messageWhenEmptyAndNotSelected = "")
{
Padding = new BorderDouble(3);
actuallTextEditWidget = new TextEditWidget(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine, tabIndex: tabIndex);
actuallTextEditWidget.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
actuallTextEditWidget.MinimumSize = new Vector2(Math.Max(actuallTextEditWidget.MinimumSize.x, pixelWidth), Math.Max(actuallTextEditWidget.MinimumSize.y, pixelHeight));
actuallTextEditWidget.VAnchor = Agg.UI.VAnchor.ParentBottom;
AddChild(actuallTextEditWidget);
BackgroundColor = RGBA_Bytes.White;
HAnchor = HAnchor.FitToChildren;
VAnchor = VAnchor.FitToChildren;
public TextEditWidget ActualTextEditWidget
{
get { return actuallTextEditWidget; }
}
actuallTextEditWidget.TextChanged += new EventHandler(internalTextEditWidget_TextChanged);
actuallTextEditWidget.InternalTextEditWidget.EditComplete += new EventHandler(InternalTextEditWidget_EditComplete);
public MHTextEditWidget(string text = "", double x = 0, double y = 0, double pointSize = 12, double pixelWidth = 0, double pixelHeight = 0, bool multiLine = false, int tabIndex = 0, string messageWhenEmptyAndNotSelected = "")
{
Padding = new BorderDouble(3);
actuallTextEditWidget = new TextEditWidget(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine, tabIndex: tabIndex);
actuallTextEditWidget.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
actuallTextEditWidget.MinimumSize = new Vector2(Math.Max(actuallTextEditWidget.MinimumSize.x, pixelWidth), Math.Max(actuallTextEditWidget.MinimumSize.y, pixelHeight));
actuallTextEditWidget.VAnchor = Agg.UI.VAnchor.ParentBottom;
AddChild(actuallTextEditWidget);
BackgroundColor = RGBA_Bytes.White;
HAnchor = HAnchor.FitToChildren;
VAnchor = VAnchor.FitToChildren;
noContentFieldDescription = new TextWidget(messageWhenEmptyAndNotSelected, textColor: RGBA_Bytes.Gray);
noContentFieldDescription.VAnchor = VAnchor.ParentBottom;
noContentFieldDescription.AutoExpandBoundsToText = true;
AddChild(noContentFieldDescription);
SetNoContentFieldDescriptionVisibility();
}
actuallTextEditWidget.TextChanged += new EventHandler(internalTextEditWidget_TextChanged);
actuallTextEditWidget.InternalTextEditWidget.EditComplete += new EventHandler(InternalTextEditWidget_EditComplete);
private void SetNoContentFieldDescriptionVisibility()
{
if(noContentFieldDescription != null)
{
if (Text == "" && !ContainsFocus)
{
noContentFieldDescription.Visible = true;
}
else
{
noContentFieldDescription.Visible = false;
}
}
}
noContentFieldDescription = new TextWidget(messageWhenEmptyAndNotSelected, textColor: RGBA_Bytes.Gray);
noContentFieldDescription.VAnchor = VAnchor.ParentBottom;
noContentFieldDescription.AutoExpandBoundsToText = true;
AddChild(noContentFieldDescription);
SetNoContentFieldDescriptionVisibility();
}
void InternalTextEditWidget_EditComplete(object sender, EventArgs e)
{
timeSinceLastTextChanged.Stop();
}
private void SetNoContentFieldDescriptionVisibility()
{
if (noContentFieldDescription != null)
{
if (Text == "" && !ContainsFocus)
{
noContentFieldDescription.Visible = true;
}
else
{
noContentFieldDescription.Visible = false;
}
}
}
public void OnIdle(object state)
{
if (timeSinceLastTextChanged.IsRunning)
{
if (timeSinceLastTextChanged.Elapsed.Seconds > 2)
{
if (actuallTextEditWidget.InternalTextEditWidget.TextHasChanged())
{
actuallTextEditWidget.InternalTextEditWidget.OnEditComplete();
}
timeSinceLastTextChanged.Stop();
private void InternalTextEditWidget_EditComplete(object sender, EventArgs e)
{
timeSinceLastTextChanged.Stop();
}
}
if (!WidgetHasBeenClosed)
{
UiThread.RunOnIdle(OnIdle, 1);
}
}
}
public void OnIdle(object state)
{
if (timeSinceLastTextChanged.IsRunning)
{
if (timeSinceLastTextChanged.Elapsed.Seconds > 2)
{
if (actuallTextEditWidget.InternalTextEditWidget.TextHasChanged())
{
actuallTextEditWidget.InternalTextEditWidget.OnEditComplete();
}
timeSinceLastTextChanged.Stop();
}
if (!WidgetHasBeenClosed)
{
UiThread.RunOnIdle(OnIdle, 1);
}
}
}
void internalTextEditWidget_TextChanged(object sender, EventArgs e)
{
if (!timeSinceLastTextChanged.IsRunning)
{
UiThread.RunOnIdle(OnIdle, 1);
}
timeSinceLastTextChanged.Restart();
}
private void internalTextEditWidget_TextChanged(object sender, EventArgs e)
{
if (!timeSinceLastTextChanged.IsRunning)
{
UiThread.RunOnIdle(OnIdle, 1);
}
timeSinceLastTextChanged.Restart();
}
public override void OnDraw(Graphics2D graphics2D)
{
SetNoContentFieldDescriptionVisibility();
base.OnDraw(graphics2D);
public override void OnDraw(Graphics2D graphics2D)
{
SetNoContentFieldDescriptionVisibility();
base.OnDraw(graphics2D);
if (ContainsFocus)
{
graphics2D.Rectangle(LocalBounds, RGBA_Bytes.Orange);
}
}
if (ContainsFocus)
{
graphics2D.Rectangle(LocalBounds, RGBA_Bytes.Orange);
}
}
public override string Text
{
get
{
return actuallTextEditWidget.Text;
}
set
{
actuallTextEditWidget.Text = value;
}
}
public override string Text
{
get
{
return actuallTextEditWidget.Text;
}
set
{
actuallTextEditWidget.Text = value;
}
}
public bool SelectAllOnFocus
{
get { return actuallTextEditWidget.InternalTextEditWidget.SelectAllOnFocus; }
set { actuallTextEditWidget.InternalTextEditWidget.SelectAllOnFocus = value; }
}
}
public bool SelectAllOnFocus
{
get { return actuallTextEditWidget.InternalTextEditWidget.SelectAllOnFocus; }
set { actuallTextEditWidget.InternalTextEditWidget.SelectAllOnFocus = value; }
}
}
public class MHPasswordTextEditWidget : MHTextEditWidget
{
TextEditWidget passwordCoverText;
public class MHPasswordTextEditWidget : MHTextEditWidget
{
private TextEditWidget passwordCoverText;
public MHPasswordTextEditWidget(string text = "", double x = 0, double y = 0, double pointSize = 12, double pixelWidth = 0, double pixelHeight = 0, bool multiLine = false, int tabIndex = 0, string messageWhenEmptyAndNotSelected = "")
: base(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine, tabIndex, messageWhenEmptyAndNotSelected)
{
passwordCoverText = new TextEditWidget(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine);
passwordCoverText.Selectable = false;
passwordCoverText.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
passwordCoverText.MinimumSize = new Vector2(Math.Max(passwordCoverText.MinimumSize.x, pixelWidth), Math.Max(passwordCoverText.MinimumSize.y, pixelHeight));
passwordCoverText.VAnchor = Agg.UI.VAnchor.ParentBottom;
AddChild(passwordCoverText);
public MHPasswordTextEditWidget(string text = "", double x = 0, double y = 0, double pointSize = 12, double pixelWidth = 0, double pixelHeight = 0, bool multiLine = false, int tabIndex = 0, string messageWhenEmptyAndNotSelected = "")
: base(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine, tabIndex, messageWhenEmptyAndNotSelected)
{
passwordCoverText = new TextEditWidget(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine);
passwordCoverText.Selectable = false;
passwordCoverText.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
passwordCoverText.MinimumSize = new Vector2(Math.Max(passwordCoverText.MinimumSize.x, pixelWidth), Math.Max(passwordCoverText.MinimumSize.y, pixelHeight));
passwordCoverText.VAnchor = Agg.UI.VAnchor.ParentBottom;
AddChild(passwordCoverText);
actuallTextEditWidget.TextChanged += (sender, e) =>
{
passwordCoverText.Text = new string('●', actuallTextEditWidget.Text.Length);
};
actuallTextEditWidget.TextChanged += (sender, e) =>
{
passwordCoverText.Text = new string('●', actuallTextEditWidget.Text.Length);
};
RemoveChild(noContentFieldDescription);
AddChild(noContentFieldDescription);
}
}
RemoveChild(noContentFieldDescription);
AddChild(noContentFieldDescription);
}
}
public class MHNumberEdit : GuiWidget
{
Stopwatch timeSinceLastTextChanged = new Stopwatch();
NumberEdit actuallNumberEdit;
public NumberEdit ActuallNumberEdit
{
get { return actuallNumberEdit; }
}
public class MHNumberEdit : GuiWidget
{
private Stopwatch timeSinceLastTextChanged = new Stopwatch();
private NumberEdit actuallNumberEdit;
public MHNumberEdit(double startingValue,
double x = 0, double y = 0, double pointSize = 12,
double pixelWidth = 0, double pixelHeight = 0,
bool allowNegatives = false, bool allowDecimals = false,
double minValue = int.MinValue,
double maxValue = int.MaxValue,
double increment = 1,
int tabIndex = 0)
{
Padding = new BorderDouble(3);
actuallNumberEdit = new NumberEdit(startingValue, x, y, pointSize, pixelWidth, pixelHeight,
allowNegatives, allowDecimals, minValue, maxValue, increment, tabIndex);
actuallNumberEdit.VAnchor = Agg.UI.VAnchor.ParentBottom;
AddChild(actuallNumberEdit);
BackgroundColor = RGBA_Bytes.White;
HAnchor = HAnchor.FitToChildren;
VAnchor = VAnchor.FitToChildren;
public NumberEdit ActuallNumberEdit
{
get { return actuallNumberEdit; }
}
actuallNumberEdit.TextChanged += new EventHandler(internalNumberEdit_TextChanged);
actuallNumberEdit.InternalTextEditWidget.EditComplete += new EventHandler(InternalTextEditWidget_EditComplete);
}
public MHNumberEdit(double startingValue,
double x = 0, double y = 0, double pointSize = 12,
double pixelWidth = 0, double pixelHeight = 0,
bool allowNegatives = false, bool allowDecimals = false,
double minValue = int.MinValue,
double maxValue = int.MaxValue,
double increment = 1,
int tabIndex = 0)
{
Padding = new BorderDouble(3);
actuallNumberEdit = new NumberEdit(startingValue, x, y, pointSize, pixelWidth, pixelHeight,
allowNegatives, allowDecimals, minValue, maxValue, increment, tabIndex);
actuallNumberEdit.VAnchor = Agg.UI.VAnchor.ParentBottom;
AddChild(actuallNumberEdit);
BackgroundColor = RGBA_Bytes.White;
HAnchor = HAnchor.FitToChildren;
VAnchor = VAnchor.FitToChildren;
public override int TabIndex
{
get
{
return base.TabIndex;
}
set
{
actuallNumberEdit.TabIndex = value;
}
}
actuallNumberEdit.TextChanged += new EventHandler(internalNumberEdit_TextChanged);
actuallNumberEdit.InternalTextEditWidget.EditComplete += new EventHandler(InternalTextEditWidget_EditComplete);
}
void InternalTextEditWidget_EditComplete(object sender, EventArgs e)
{
timeSinceLastTextChanged.Stop();
}
public override int TabIndex
{
get
{
return base.TabIndex;
}
set
{
actuallNumberEdit.TabIndex = value;
}
}
public void OnIdle(object state)
{
if (timeSinceLastTextChanged.IsRunning)
{
if (timeSinceLastTextChanged.Elapsed.Seconds > 2)
{
if (actuallNumberEdit.InternalTextEditWidget.TextHasChanged())
{
actuallNumberEdit.InternalTextEditWidget.OnEditComplete();
}
timeSinceLastTextChanged.Stop();
private void InternalTextEditWidget_EditComplete(object sender, EventArgs e)
{
timeSinceLastTextChanged.Stop();
}
}
if (!WidgetHasBeenClosed)
{
UiThread.RunOnIdle(OnIdle, 1);
}
}
}
public void OnIdle(object state)
{
if (timeSinceLastTextChanged.IsRunning)
{
if (timeSinceLastTextChanged.Elapsed.Seconds > 2)
{
if (actuallNumberEdit.InternalTextEditWidget.TextHasChanged())
{
actuallNumberEdit.InternalTextEditWidget.OnEditComplete();
}
timeSinceLastTextChanged.Stop();
}
if (!WidgetHasBeenClosed)
{
UiThread.RunOnIdle(OnIdle, 1);
}
}
}
void internalNumberEdit_TextChanged(object sender, EventArgs e)
{
if (!timeSinceLastTextChanged.IsRunning)
{
UiThread.RunOnIdle(OnIdle, 1);
}
timeSinceLastTextChanged.Restart();
}
private void internalNumberEdit_TextChanged(object sender, EventArgs e)
{
if (!timeSinceLastTextChanged.IsRunning)
{
UiThread.RunOnIdle(OnIdle, 1);
}
timeSinceLastTextChanged.Restart();
}
public override void OnDraw(Graphics2D graphics2D)
{
base.OnDraw(graphics2D);
if (ContainsFocus)
{
graphics2D.Rectangle(LocalBounds, RGBA_Bytes.Orange);
}
}
public override void OnDraw(Graphics2D graphics2D)
{
base.OnDraw(graphics2D);
if (ContainsFocus)
{
graphics2D.Rectangle(LocalBounds, RGBA_Bytes.Orange);
}
}
public override string Text
{
get
{
return actuallNumberEdit.Text;
}
set
{
actuallNumberEdit.Text = value;
}
}
public override string Text
{
get
{
return actuallNumberEdit.Text;
}
set
{
actuallNumberEdit.Text = value;
}
}
public bool SelectAllOnFocus
{
get { return ActuallNumberEdit.InternalNumberEdit.SelectAllOnFocus; }
set { ActuallNumberEdit.InternalNumberEdit.SelectAllOnFocus = value; }
}
}
}
public bool SelectAllOnFocus
{
get { return ActuallNumberEdit.InternalNumberEdit.SelectAllOnFocus; }
set { ActuallNumberEdit.InternalNumberEdit.SelectAllOnFocus = value; }
}
}
}

View file

@ -3,13 +3,13 @@ Copyright (c) 2014, Lars Brubaker
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@ -23,61 +23,61 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System.Globalization;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl;
using MatterHackers.VectorMath;
using MatterHackers.Agg;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.VectorMath;
using System;
using System.Globalization;
namespace MatterHackers.MatterControl
{
public class PopOutManager
{
static readonly string WindowLeftOpenSufix = "_WindowLeftOpen";
static readonly string WindowSizeSufix = "_WindowSize";
static readonly string PositionSufix = "_WindowPosition";
public class PopOutManager
{
private static readonly string WindowLeftOpenSufix = "_WindowLeftOpen";
private static readonly string WindowSizeSufix = "_WindowSize";
private static readonly string PositionSufix = "_WindowPosition";
string WindowLeftOpenKey;
string WindowSizeKey;
string PositionKey;
private string WindowLeftOpenKey;
private string WindowSizeKey;
private string PositionKey;
SystemWindow PopedOutSystemWindow = null;
GuiWidget widgetWhosContentsPopOut = null;
string windowTitle;
private SystemWindow PopedOutSystemWindow = null;
private GuiWidget widgetWhosContentsPopOut = null;
private string windowTitle;
Vector2 minSize;
private Vector2 minSize;
string dataBaseKeyPrefix;
private string dataBaseKeyPrefix;
#region Public Members
public PopOutManager(GuiWidget widgetWhosContentsPopOut, Vector2 minSize, string windowTitle, string dataBaseKeyPrefix)
{
TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
string titeCaseTitle = textInfo.ToTitleCase(windowTitle.ToLower());
#region Public Members
this.windowTitle = "MatterControl - " + titeCaseTitle;
this.minSize = minSize;
this.dataBaseKeyPrefix = dataBaseKeyPrefix;
this.widgetWhosContentsPopOut = widgetWhosContentsPopOut;
public PopOutManager(GuiWidget widgetWhosContentsPopOut, Vector2 minSize, string windowTitle, string dataBaseKeyPrefix)
{
TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
string titeCaseTitle = textInfo.ToTitleCase(windowTitle.ToLower());
ApplicationController.Instance.MainView.DrawAfter += ShowOnFirstSystemWindowDraw;
this.windowTitle = "MatterControl - " + titeCaseTitle;
this.minSize = minSize;
this.dataBaseKeyPrefix = dataBaseKeyPrefix;
this.widgetWhosContentsPopOut = widgetWhosContentsPopOut;
widgetWhosContentsPopOut.Closed += (sender, e) =>
{
WidgetWhosContentsPopOutIsClosing();
};
ApplicationController.Instance.MainView.DrawAfter += ShowOnFirstSystemWindowDraw;
WindowLeftOpenKey = dataBaseKeyPrefix + WindowLeftOpenSufix;
WindowSizeKey = dataBaseKeyPrefix + WindowSizeSufix;
PositionKey = dataBaseKeyPrefix + PositionSufix;
}
widgetWhosContentsPopOut.Closed += (sender, e) =>
{
WidgetWhosContentsPopOutIsClosing();
};
WindowLeftOpenKey = dataBaseKeyPrefix + WindowLeftOpenSufix;
WindowSizeKey = dataBaseKeyPrefix + WindowSizeSufix;
PositionKey = dataBaseKeyPrefix + PositionSufix;
}
public static void SetPopOutState(string dataBaseKeyPrefix, bool poppedOut)
{
@ -97,87 +97,88 @@ namespace MatterHackers.MatterControl
UserSettings.Instance.set(positionKey, string.Format("{0},{1}", positionX, positionY));
}
public void ShowContentInWindow()
{
if (PopedOutSystemWindow == null)
{
// So the window is open now only change this is we close it.
UserSettings.Instance.Fields.SetBool(WindowLeftOpenKey, true);
public void ShowContentInWindow()
{
if (PopedOutSystemWindow == null)
{
// So the window is open now only change this is we close it.
UserSettings.Instance.Fields.SetBool(WindowLeftOpenKey, true);
string windowSize = UserSettings.Instance.get(WindowSizeKey);
int width = 600;
int height = 400;
if (windowSize != null && windowSize != "")
{
string[] sizes = windowSize.Split(',');
width = Math.Max(int.Parse(sizes[0]), (int)minSize.x);
height = Math.Max(int.Parse(sizes[1]), (int)minSize.y);
}
string windowSize = UserSettings.Instance.get(WindowSizeKey);
int width = 600;
int height = 400;
if (windowSize != null && windowSize != "")
{
string[] sizes = windowSize.Split(',');
width = Math.Max(int.Parse(sizes[0]), (int)minSize.x);
height = Math.Max(int.Parse(sizes[1]), (int)minSize.y);
}
PopedOutSystemWindow = new SystemWindow(width, height);
PopedOutSystemWindow = new SystemWindow(width, height);
PopedOutSystemWindow.Padding = new BorderDouble(3);
PopedOutSystemWindow.Title = windowTitle;
PopedOutSystemWindow.AlwaysOnTopOfMain = true;
PopedOutSystemWindow.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
PopedOutSystemWindow.Closing += SystemWindow_Closing;
if (widgetWhosContentsPopOut.Children.Count == 1)
{
GuiWidget child = widgetWhosContentsPopOut.Children[0];
widgetWhosContentsPopOut.RemoveChild(child);
widgetWhosContentsPopOut.AddChild(CreateContentForEmptyControl());
PopedOutSystemWindow.AddChild(child);
}
PopedOutSystemWindow.ShowAsSystemWindow();
PopedOutSystemWindow.Title = windowTitle;
PopedOutSystemWindow.AlwaysOnTopOfMain = true;
PopedOutSystemWindow.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
PopedOutSystemWindow.Closing += SystemWindow_Closing;
if (widgetWhosContentsPopOut.Children.Count == 1)
{
GuiWidget child = widgetWhosContentsPopOut.Children[0];
widgetWhosContentsPopOut.RemoveChild(child);
widgetWhosContentsPopOut.AddChild(CreateContentForEmptyControl());
PopedOutSystemWindow.AddChild(child);
}
PopedOutSystemWindow.ShowAsSystemWindow();
PopedOutSystemWindow.MinimumSize = minSize;
string desktopPosition = UserSettings.Instance.get(PositionKey);
if (desktopPosition != null && desktopPosition != "")
{
string[] sizes = desktopPosition.Split(',');
PopedOutSystemWindow.MinimumSize = minSize;
string desktopPosition = UserSettings.Instance.get(PositionKey);
if (desktopPosition != null && desktopPosition != "")
{
string[] sizes = desktopPosition.Split(',');
//If the desktop position is less than -10,-10, override
int xpos = Math.Max(int.Parse(sizes[0]), -10);
int ypos = Math.Max(int.Parse(sizes[1]), -10);
PopedOutSystemWindow.DesktopPosition = new Point2D(xpos, ypos);
}
}
else
{
PopedOutSystemWindow.BringToFront();
}
}
#endregion
//If the desktop position is less than -10,-10, override
int xpos = Math.Max(int.Parse(sizes[0]), -10);
int ypos = Math.Max(int.Parse(sizes[1]), -10);
PopedOutSystemWindow.DesktopPosition = new Point2D(xpos, ypos);
}
}
else
{
PopedOutSystemWindow.BringToFront();
}
}
void WidgetWhosContentsPopOutIsClosing()
{
if (PopedOutSystemWindow != null)
{
SaveSizeAndPosition();
PopedOutSystemWindow.CloseAndRemoveAllChildren();
PopedOutSystemWindow.Close();
}
}
#endregion Public Members
void ShowOnFirstSystemWindowDraw(GuiWidget drawingWidget, DrawEventArgs e)
{
if (widgetWhosContentsPopOut.Children.Count > 0)
{
UiThread.RunOnIdle((state) =>
{
bool wasLeftOpen = UserSettings.Instance.Fields.GetBool(WindowLeftOpenKey, false);
if (wasLeftOpen)
{
ShowContentInWindow();
}
});
}
private void WidgetWhosContentsPopOutIsClosing()
{
if (PopedOutSystemWindow != null)
{
SaveSizeAndPosition();
PopedOutSystemWindow.CloseAndRemoveAllChildren();
PopedOutSystemWindow.Close();
}
}
ApplicationController.Instance.MainView.DrawAfter -= ShowOnFirstSystemWindowDraw;
}
private void ShowOnFirstSystemWindowDraw(GuiWidget drawingWidget, DrawEventArgs e)
{
if (widgetWhosContentsPopOut.Children.Count > 0)
{
UiThread.RunOnIdle((state) =>
{
bool wasLeftOpen = UserSettings.Instance.Fields.GetBool(WindowLeftOpenKey, false);
if (wasLeftOpen)
{
ShowContentInWindow();
}
});
}
GuiWidget CreateContentForEmptyControl()
{
GuiWidget allContent = new GuiWidget(HAnchor.ParentLeftRight, VAnchor.ParentBottomTop);
ApplicationController.Instance.MainView.DrawAfter -= ShowOnFirstSystemWindowDraw;
}
private GuiWidget CreateContentForEmptyControl()
{
GuiWidget allContent = new GuiWidget(HAnchor.ParentLeftRight, VAnchor.ParentBottomTop);
allContent.Padding = new BorderDouble(5, 10, 5, 10);
FlowLayoutWidget flowWidget = new FlowLayoutWidget();
@ -187,26 +188,26 @@ namespace MatterHackers.MatterControl
flowWidget.Padding = new BorderDouble(10, 0);
flowWidget.Height = 60;
TextImageButtonFactory bringBackButtonFactory = new TextImageButtonFactory();
TextImageButtonFactory bringBackButtonFactory = new TextImageButtonFactory();
bringBackButtonFactory.normalFillColor = RGBA_Bytes.Gray;
bringBackButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor;
Button bringBackToTabButton = bringBackButtonFactory.Generate(LocalizedString.Get("Restore"));
Button bringBackToTabButton = bringBackButtonFactory.Generate(LocalizedString.Get("Restore"));
bringBackToTabButton.VAnchor = VAnchor.ParentCenter;
bringBackToTabButton.Cursor = Cursors.Hand;
bringBackToTabButton.Click += (sender, e) =>
{
UiThread.RunOnIdle((state) =>
{
SaveWindowShouldStartClosed();
SystemWindow temp = PopedOutSystemWindow;
SystemWindow_Closing(null, null);
temp.Close();
});
};
bringBackToTabButton.Cursor = Cursors.Hand;
bringBackToTabButton.Click += (sender, e) =>
{
UiThread.RunOnIdle((state) =>
{
SaveWindowShouldStartClosed();
SystemWindow temp = PopedOutSystemWindow;
SystemWindow_Closing(null, null);
temp.Close();
});
};
TextWidget windowedModeMessage = new TextWidget(LocalizedString.Get("WINDOWED MODE: This tab has been moved to a separate window."),
pointSize:10, textColor: ActiveTheme.Instance.PrimaryTextColor);
TextWidget windowedModeMessage = new TextWidget(LocalizedString.Get("WINDOWED MODE: This tab has been moved to a separate window."),
pointSize: 10, textColor: ActiveTheme.Instance.PrimaryTextColor);
windowedModeMessage.VAnchor = VAnchor.ParentCenter;
flowWidget.AddChild(windowedModeMessage);
@ -214,37 +215,36 @@ namespace MatterHackers.MatterControl
flowWidget.AddChild(bringBackToTabButton);
allContent.AddChild(flowWidget);
return allContent;
}
return allContent;
}
void SaveWindowShouldStartClosed()
{
UserSettings.Instance.Fields.SetBool(WindowLeftOpenKey, false);
}
private void SaveWindowShouldStartClosed()
{
UserSettings.Instance.Fields.SetBool(WindowLeftOpenKey, false);
}
void SystemWindow_Closing(object sender, WidgetClosingEnventArgs closingEvent)
{
SaveSizeAndPosition();
SaveWindowShouldStartClosed();
if (PopedOutSystemWindow.Children.Count == 1)
{
GuiWidget child = PopedOutSystemWindow.Children[0];
PopedOutSystemWindow.RemoveChild(child);
widgetWhosContentsPopOut.RemoveAllChildren();
widgetWhosContentsPopOut.AddChild(child);
}
PopedOutSystemWindow = null;
}
private void SystemWindow_Closing(object sender, WidgetClosingEnventArgs closingEvent)
{
SaveSizeAndPosition();
SaveWindowShouldStartClosed();
if (PopedOutSystemWindow.Children.Count == 1)
{
GuiWidget child = PopedOutSystemWindow.Children[0];
PopedOutSystemWindow.RemoveChild(child);
widgetWhosContentsPopOut.RemoveAllChildren();
widgetWhosContentsPopOut.AddChild(child);
}
PopedOutSystemWindow = null;
}
private void SaveSizeAndPosition()
{
if (PopedOutSystemWindow != null)
{
UserSettings.Instance.set(WindowSizeKey, string.Format("{0},{1}", PopedOutSystemWindow.Width, PopedOutSystemWindow.Height));
UserSettings.Instance.set(PositionKey, string.Format("{0},{1}", PopedOutSystemWindow.DesktopPosition.x, PopedOutSystemWindow.DesktopPosition.y));
}
}
}
}
private void SaveSizeAndPosition()
{
if (PopedOutSystemWindow != null)
{
UserSettings.Instance.set(WindowSizeKey, string.Format("{0},{1}", PopedOutSystemWindow.Width, PopedOutSystemWindow.Height));
UserSettings.Instance.set(PositionKey, string.Format("{0},{1}", PopedOutSystemWindow.DesktopPosition.x, PopedOutSystemWindow.DesktopPosition.y));
}
}
}
}

View file

@ -3,13 +3,13 @@ Copyright (c) 2014, Lars Brubaker
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@ -23,72 +23,76 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MatterHackers.MatterControl.CreatorPlugins
{
public class CreatorInformation
{
public delegate void UnlockFunction();
public UnlockFunction unlockFunction;
public delegate bool PermissionFunction();
public PermissionFunction permissionFunction;
public delegate void UnlockRegisterFunction(EventHandler functionToCallOnEvent, ref EventHandler functionThatWillBeCalledToUnregisterEvent);
public UnlockRegisterFunction unlockRegisterFunction;
public EventHandler functionToLaunchCreator;
public string iconPath;
public string description;
public bool paidAddOnFlag;
public class CreatorInformation
{
public delegate void UnlockFunction();
public CreatorInformation(EventHandler functionToLaunchCreator,
string iconPath, string description,
bool paidAddOnFlag = false,
UnlockFunction unlockFunction = null,
PermissionFunction permissionFunction = null,
UnlockRegisterFunction unlockRegisterFunction = null)
{
this.functionToLaunchCreator = functionToLaunchCreator;
this.iconPath = iconPath;
this.description = description;
this.paidAddOnFlag = paidAddOnFlag;
this.unlockFunction = unlockFunction;
this.permissionFunction = permissionFunction;
this.unlockRegisterFunction = unlockRegisterFunction;
}
}
public UnlockFunction unlockFunction;
public class RegisteredCreators
{
static RegisteredCreators instance = null;
public static RegisteredCreators Instance
{
get
{
if (instance == null)
{
instance = new RegisteredCreators();
}
public delegate bool PermissionFunction();
return instance;
}
}
public PermissionFunction permissionFunction;
public List<CreatorInformation> Creators = new List<CreatorInformation>();
public delegate void UnlockRegisterFunction(EventHandler functionToCallOnEvent, ref EventHandler functionThatWillBeCalledToUnregisterEvent);
private RegisteredCreators()
{
}
public UnlockRegisterFunction unlockRegisterFunction;
public EventHandler functionToLaunchCreator;
public string iconPath;
public string description;
public bool paidAddOnFlag;
public void RegisterLaunchFunction(CreatorInformation creatorInformation)
{
Creators.Add(creatorInformation);
}
}
}
public CreatorInformation(EventHandler functionToLaunchCreator,
string iconPath, string description,
bool paidAddOnFlag = false,
UnlockFunction unlockFunction = null,
PermissionFunction permissionFunction = null,
UnlockRegisterFunction unlockRegisterFunction = null)
{
this.functionToLaunchCreator = functionToLaunchCreator;
this.iconPath = iconPath;
this.description = description;
this.paidAddOnFlag = paidAddOnFlag;
this.unlockFunction = unlockFunction;
this.permissionFunction = permissionFunction;
this.unlockRegisterFunction = unlockRegisterFunction;
}
}
public class RegisteredCreators
{
private static RegisteredCreators instance = null;
public static RegisteredCreators Instance
{
get
{
if (instance == null)
{
instance = new RegisteredCreators();
}
return instance;
}
}
public List<CreatorInformation> Creators = new List<CreatorInformation>();
private RegisteredCreators()
{
}
public void RegisterLaunchFunction(CreatorInformation creatorInformation)
{
Creators.Add(creatorInformation);
}
}
}

View file

@ -1,6 +1,6 @@
using System;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg;
using System;
namespace MatterHackers.MatterControl
{
@ -31,31 +31,31 @@ namespace MatterHackers.MatterControl
public double FixedHeight = 30 * TextWidget.GlobalPointSizeScaleRatio;
public SplitButtonFactory ()
public SplitButtonFactory()
{
}
public SplitButton Generate (TupleList<string, Func<bool>> buttonList, Direction direction = Direction.Down,string imageName = null)
public SplitButton Generate(TupleList<string, Func<bool>> buttonList, Direction direction = Direction.Down, string imageName = null)
{
this.imageName = imageName;
DynamicDropDownMenu menu = CreateMenu(direction);
menu.Margin = new BorderDouble();
Button button = CreateButton (buttonList [0]);
menu.Margin = new BorderDouble();
Button button = CreateButton(buttonList[0]);
for(int index =1; index < buttonList.Count; index++)
for (int index = 1; index < buttonList.Count; index++)
{
menu.addItem (buttonList[index].Item1,buttonList[index].Item2);
menu.addItem(buttonList[index].Item1, buttonList[index].Item2);
}
SplitButton splitButton = new SplitButton (button, menu);
SplitButton splitButton = new SplitButton(button, menu);
return splitButton;
}
private Button CreateButton(Tuple<string,Func<bool>> buttonInfo)
private Button CreateButton(Tuple<string, Func<bool>> buttonInfo)
{
TextImageButtonFactory buttonFactory = new TextImageButtonFactory ();
TextImageButtonFactory buttonFactory = new TextImageButtonFactory();
buttonFactory.FixedHeight = this.FixedHeight;
buttonFactory.normalFillColor = this.normalFillColor;
@ -66,11 +66,10 @@ namespace MatterHackers.MatterControl
buttonFactory.normalBorderColor = this.normalBorderColor;
buttonFactory.hoverBorderColor = this.hoverBorderColor;
Button button = buttonFactory.Generate(buttonInfo.Item1, normalImageName: imageName, centerText: true);
Button button = buttonFactory.Generate (buttonInfo.Item1,normalImageName: imageName, centerText: true);
button.Click += (object sender, EventArgs e) =>
{
button.Click += (object sender, EventArgs e) =>
{
buttonInfo.Item2();
};
@ -79,7 +78,7 @@ namespace MatterHackers.MatterControl
private DynamicDropDownMenu CreateMenu(Direction direction = Direction.Down)
{
DropDownMenuFactory menuFactory = new DropDownMenuFactory ();
DropDownMenuFactory menuFactory = new DropDownMenuFactory();
menuFactory.normalFillColor = this.normalFillColor;
menuFactory.hoverFillColor = this.hoverFillColor;
@ -95,8 +94,8 @@ namespace MatterHackers.MatterControl
menuFactory.hoverTextColor = this.hoverTextColor;
menuFactory.pressedTextColor = this.pressedTextColor;
menuFactory.disabledTextColor = this.disabledTextColor;
DynamicDropDownMenu menu = menuFactory.Generate(direction:direction);
DynamicDropDownMenu menu = menuFactory.Generate(direction: direction);
menu.Height = FixedHeight;
menu.BorderColor = normalBorderColor;
@ -107,5 +106,4 @@ namespace MatterHackers.MatterControl
return menu;
}
}
}
}

View file

@ -1,207 +1,202 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.Image;
using MatterHackers.Agg;
using MatterHackers.Agg.Font;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using System;
namespace MatterHackers.MatterControl
{
public class StyledMessageBox : SystemWindow
{
String unwrappedMessage;
TextWidget messageContainer;
FlowLayoutWidget middleRowContainer;
TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
public class StyledMessageBox : SystemWindow
{
private String unwrappedMessage;
private TextWidget messageContainer;
private FlowLayoutWidget middleRowContainer;
private TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
public delegate void MessageBoxDelegate(bool response);
MessageBoxDelegate responseCallback;
public delegate void MessageBoxDelegate(bool response);
public enum MessageType { OK, YES_NO };
private MessageBoxDelegate responseCallback;
public static void ShowMessageBox(MessageBoxDelegate callback, String message, string caption, MessageType messageType = MessageType.OK, string yesOk = "", string no = "")
{
ShowMessageBox(callback, message, caption, null, messageType, yesOk, no);
}
public enum MessageType { OK, YES_NO };
public static void ShowMessageBox(MessageBoxDelegate callback, string message, string caption, GuiWidget[] extraWidgetsToAdd, MessageType messageType, string yesOk = "", string no = "")
{
StyledMessageBox messageBox = new StyledMessageBox(callback, message, caption, messageType, extraWidgetsToAdd, 400, 300, yesOk, no);
messageBox.ShowAsSystemWindow();
}
public static void ShowMessageBox(MessageBoxDelegate callback, String message, string caption, MessageType messageType = MessageType.OK, string yesOk = "", string no = "")
{
ShowMessageBox(callback, message, caption, null, messageType, yesOk, no);
}
public StyledMessageBox(MessageBoxDelegate callback, String message, string windowTitle, MessageType messageType, GuiWidget[] extraWidgetsToAdd, double width, double height, string yesOk, string no)
: base(width, height)
{
responseCallback = callback;
unwrappedMessage = message;
FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
topToBottom.AnchorAll();
topToBottom.Padding = new BorderDouble(3, 0, 3, 5);
public static void ShowMessageBox(MessageBoxDelegate callback, string message, string caption, GuiWidget[] extraWidgetsToAdd, MessageType messageType, string yesOk = "", string no = "")
{
StyledMessageBox messageBox = new StyledMessageBox(callback, message, caption, messageType, extraWidgetsToAdd, 400, 300, yesOk, no);
messageBox.ShowAsSystemWindow();
}
// Creates Header
FlowLayoutWidget headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);
headerRow.HAnchor = HAnchor.ParentLeftRight;
headerRow.Margin = new BorderDouble(0, 3, 0, 0);
headerRow.Padding = new BorderDouble(0, 3, 0, 3);
BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
public StyledMessageBox(MessageBoxDelegate callback, String message, string windowTitle, MessageType messageType, GuiWidget[] extraWidgetsToAdd, double width, double height, string yesOk, string no)
: base(width, height)
{
responseCallback = callback;
unwrappedMessage = message;
FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
topToBottom.AnchorAll();
topToBottom.Padding = new BorderDouble(3, 0, 3, 5);
//Creates Text and adds into header
{
TextWidget elementHeader = new TextWidget(windowTitle, pointSize: 14);
elementHeader.TextColor = ActiveTheme.Instance.PrimaryTextColor;
elementHeader.HAnchor = HAnchor.ParentLeftRight;
elementHeader.VAnchor = Agg.UI.VAnchor.ParentBottom;
// Creates Header
FlowLayoutWidget headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);
headerRow.HAnchor = HAnchor.ParentLeftRight;
headerRow.Margin = new BorderDouble(0, 3, 0, 0);
headerRow.Padding = new BorderDouble(0, 3, 0, 3);
BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
headerRow.AddChild(elementHeader);
topToBottom.AddChild(headerRow);
}
//Creates Text and adds into header
{
TextWidget elementHeader = new TextWidget(windowTitle, pointSize: 14);
elementHeader.TextColor = ActiveTheme.Instance.PrimaryTextColor;
elementHeader.HAnchor = HAnchor.ParentLeftRight;
elementHeader.VAnchor = Agg.UI.VAnchor.ParentBottom;
// Creates container in the middle of window
middleRowContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
{
middleRowContainer.HAnchor = HAnchor.ParentLeftRight;
middleRowContainer.VAnchor = VAnchor.ParentBottomTop;
// normally the padding for the middle container should be just (5) all around. The has extra top space
middleRowContainer.Padding = new BorderDouble(5, 5, 5, 15);
middleRowContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
}
headerRow.AddChild(elementHeader);
topToBottom.AddChild(headerRow);
}
messageContainer = new TextWidget(message, textColor: ActiveTheme.Instance.PrimaryTextColor);
messageContainer.AutoExpandBoundsToText = true;
messageContainer.HAnchor = Agg.UI.HAnchor.ParentLeft;
middleRowContainer.AddChild(messageContainer);
// Creates container in the middle of window
middleRowContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
{
middleRowContainer.HAnchor = HAnchor.ParentLeftRight;
middleRowContainer.VAnchor = VAnchor.ParentBottomTop;
// normally the padding for the middle container should be just (5) all around. The has extra top space
middleRowContainer.Padding = new BorderDouble(5, 5, 5, 15);
middleRowContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
}
if (extraWidgetsToAdd != null)
{
foreach (GuiWidget widget in extraWidgetsToAdd)
{
middleRowContainer.AddChild(widget);
}
}
messageContainer = new TextWidget(message, textColor: ActiveTheme.Instance.PrimaryTextColor);
messageContainer.AutoExpandBoundsToText = true;
messageContainer.HAnchor = Agg.UI.HAnchor.ParentLeft;
middleRowContainer.AddChild(messageContainer);
topToBottom.AddChild(middleRowContainer);
if (extraWidgetsToAdd != null)
{
foreach (GuiWidget widget in extraWidgetsToAdd)
{
middleRowContainer.AddChild(widget);
}
}
//Creates button container on the bottom of window
FlowLayoutWidget buttonRow = new FlowLayoutWidget(FlowDirection.LeftToRight);
{
BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
buttonRow.HAnchor = HAnchor.ParentLeftRight;
buttonRow.Padding = new BorderDouble(0, 3);
}
topToBottom.AddChild(middleRowContainer);
//Creates button container on the bottom of window
FlowLayoutWidget buttonRow = new FlowLayoutWidget(FlowDirection.LeftToRight);
{
BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
buttonRow.HAnchor = HAnchor.ParentLeftRight;
buttonRow.Padding = new BorderDouble(0, 3);
}
int minButtonWidth = (int)(50 * TextWidget.GlobalPointSizeScaleRatio + .5);
switch (messageType)
{
case MessageType.YES_NO:
{
Title = "MatterControl - " + "Please Confirm".Localize();
Button yesButton = textImageButtonFactory.Generate(yesOk, centerText: true);
if (yesOk == "")
{
yesOk = "Yes".Localize();
textImageButtonFactory.FixedWidth = minButtonWidth;
yesButton = textImageButtonFactory.Generate(yesOk, centerText: true);
textImageButtonFactory.FixedWidth = 0;
}
yesButton.Width = Math.Max(minButtonWidth, yesButton.Width);
yesButton.Click += new EventHandler(okButton_Click);
yesButton.Cursor = Cursors.Hand;
buttonRow.AddChild(yesButton);
//buttonRow.AddChild(new HorizontalSpacer());
switch (messageType)
{
case MessageType.YES_NO:
{
Title = "MatterControl - " + "Please Confirm".Localize();
Button yesButton = textImageButtonFactory.Generate(yesOk, centerText: true);
if (yesOk == "")
{
yesOk = "Yes".Localize();
textImageButtonFactory.FixedWidth = minButtonWidth;
yesButton = textImageButtonFactory.Generate(yesOk, centerText: true);
textImageButtonFactory.FixedWidth = 0;
}
yesButton.Width = Math.Max(minButtonWidth, yesButton.Width);
yesButton.Click += new EventHandler(okButton_Click);
yesButton.Cursor = Cursors.Hand;
buttonRow.AddChild(yesButton);
Button noButton = textImageButtonFactory.Generate(no, centerText: true);
if (no == "")
{
no = "No".Localize();
textImageButtonFactory.FixedWidth = minButtonWidth;
noButton = textImageButtonFactory.Generate(no, centerText: true);
textImageButtonFactory.FixedWidth = 0;
}
noButton.Width = Math.Max(minButtonWidth, noButton.Width);
noButton.Click += new EventHandler(noButton_Click);
noButton.Cursor = Cursors.Hand;
buttonRow.AddChild(noButton);
}
break;
//buttonRow.AddChild(new HorizontalSpacer());
case MessageType.OK:
{
Title = "MatterControl - " + "Alert".Localize();
Button okButton = textImageButtonFactory.Generate(LocalizedString.Get("Ok"), centerText: true);
if (yesOk == "")
{
yesOk = "Ok".Localize();
textImageButtonFactory.FixedWidth = minButtonWidth;
okButton = textImageButtonFactory.Generate(yesOk, centerText: true);
textImageButtonFactory.FixedWidth = 0;
}
okButton.Width = Math.Max(minButtonWidth, okButton.Width);
okButton.Cursor = Cursors.Hand;
okButton.Click += new EventHandler(okButton_Click);
buttonRow.AddChild(okButton);
}
break;
Button noButton = textImageButtonFactory.Generate(no, centerText: true);
if (no == "")
{
no = "No".Localize();
textImageButtonFactory.FixedWidth = minButtonWidth;
noButton = textImageButtonFactory.Generate(no, centerText: true);
textImageButtonFactory.FixedWidth = 0;
}
noButton.Width = Math.Max(minButtonWidth, noButton.Width);
noButton.Click += new EventHandler(noButton_Click);
noButton.Cursor = Cursors.Hand;
buttonRow.AddChild(noButton);
}
break;
default:
throw new NotImplementedException();
}
case MessageType.OK:
{
Title = "MatterControl - " + "Alert".Localize();
Button okButton = textImageButtonFactory.Generate(LocalizedString.Get("Ok"), centerText: true);
if (yesOk == "")
{
yesOk = "Ok".Localize();
textImageButtonFactory.FixedWidth = minButtonWidth;
okButton = textImageButtonFactory.Generate(yesOk, centerText: true);
textImageButtonFactory.FixedWidth = 0;
}
okButton.Width = Math.Max(minButtonWidth, okButton.Width);
okButton.Cursor = Cursors.Hand;
okButton.Click += new EventHandler(okButton_Click);
buttonRow.AddChild(okButton);
}
break;
topToBottom.AddChild(buttonRow);
this.AddChild(topToBottom);
default:
throw new NotImplementedException();
}
IsModal = true;
AdjustTextWrap();
}
topToBottom.AddChild(buttonRow);
this.AddChild(topToBottom);
public override void OnBoundsChanged(EventArgs e)
{
AdjustTextWrap();
base.OnBoundsChanged(e);
}
IsModal = true;
AdjustTextWrap();
}
private void AdjustTextWrap()
{
if (messageContainer != null)
{
double wrappingSize = middleRowContainer.Width - (middleRowContainer.Padding.Width + messageContainer.Margin.Width);
if (wrappingSize > 0)
{
EnglishTextWrapping wrapper = new EnglishTextWrapping(12);
string wrappedMessage = wrapper.InsertCRs(unwrappedMessage, wrappingSize);
messageContainer.Text = wrappedMessage;
}
}
}
public override void OnBoundsChanged(EventArgs e)
{
AdjustTextWrap();
base.OnBoundsChanged(e);
}
void noButton_Click(object sender, EventArgs mouseEvent)
{
UiThread.RunOnIdle(CloseOnIdle);
if (responseCallback != null)
{
responseCallback(false);
}
}
private void AdjustTextWrap()
{
if (messageContainer != null)
{
double wrappingSize = middleRowContainer.Width - (middleRowContainer.Padding.Width + messageContainer.Margin.Width);
if (wrappingSize > 0)
{
EnglishTextWrapping wrapper = new EnglishTextWrapping(12);
string wrappedMessage = wrapper.InsertCRs(unwrappedMessage, wrappingSize);
messageContainer.Text = wrappedMessage;
}
}
}
void okButton_Click(object sender, EventArgs mouseEvent)
{
UiThread.RunOnIdle(CloseOnIdle);
if (responseCallback != null)
{
responseCallback(true);
}
}
private void noButton_Click(object sender, EventArgs mouseEvent)
{
UiThread.RunOnIdle(CloseOnIdle);
if (responseCallback != null)
{
responseCallback(false);
}
}
void CloseOnIdle(object state)
{
Close();
}
}
}
private void okButton_Click(object sender, EventArgs mouseEvent)
{
UiThread.RunOnIdle(CloseOnIdle);
if (responseCallback != null)
{
responseCallback(true);
}
}
private void CloseOnIdle(object state)
{
Close();
}
}
}

View file

@ -3,13 +3,13 @@ Copyright (c) 2014, Lars Brubaker
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@ -23,507 +23,499 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.IO;
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.ImageProcessing;
using MatterHackers.Agg.PlatformAbstract;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.VectorMath;
using System;
namespace MatterHackers.MatterControl
{
public class TextImageWidget : GuiWidget
{
ImageBuffer image;
protected RGBA_Bytes fillColor = new RGBA_Bytes(0, 0, 0, 0);
protected RGBA_Bytes borderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
protected double borderWidth = 1;
protected double borderRadius = 0;
public class TextImageWidget : GuiWidget
{
private ImageBuffer image;
protected RGBA_Bytes fillColor = new RGBA_Bytes(0, 0, 0, 0);
protected RGBA_Bytes borderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
protected double borderWidth = 1;
protected double borderRadius = 0;
public TextImageWidget(string label, RGBA_Bytes fillColor, RGBA_Bytes borderColor, RGBA_Bytes textColor, double borderWidth, BorderDouble margin, ImageBuffer image = null, int fontSize = 12, FlowDirection flowDirection = FlowDirection.LeftToRight, double height = 40, double width = 0, bool centerText = false, double imageSpacing = 0)
: base()
{
this.image = image;
this.fillColor = fillColor;
this.borderColor = borderColor;
this.borderWidth = borderWidth;
this.Margin = new BorderDouble(0);
this.Padding = new BorderDouble(0);
: base()
{
this.image = image;
this.fillColor = fillColor;
this.borderColor = borderColor;
this.borderWidth = borderWidth;
this.Margin = new BorderDouble(0);
this.Padding = new BorderDouble(0);
TextWidget textWidget = new TextWidget(label, pointSize: fontSize);
ImageWidget imageWidget;
TextWidget textWidget = new TextWidget(label, pointSize: fontSize);
ImageWidget imageWidget;
FlowLayoutWidget container = new FlowLayoutWidget(flowDirection);
FlowLayoutWidget container = new FlowLayoutWidget(flowDirection);
if (centerText)
{
// make sure the contents are centered
GuiWidget leftSpace = new GuiWidget(0, 1);
leftSpace.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
container.AddChild(leftSpace);
}
if (centerText)
{
// make sure the contents are centered
GuiWidget leftSpace = new GuiWidget(0, 1);
leftSpace.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
container.AddChild(leftSpace);
}
if (image != null && image.Width > 0)
{
imageWidget = new ImageWidget(image);
imageWidget.VAnchor = VAnchor.ParentCenter;
if (image != null && image.Width > 0)
{
imageWidget = new ImageWidget(image);
imageWidget.VAnchor = VAnchor.ParentCenter;
imageWidget.Margin = new BorderDouble(right: imageSpacing);
container.AddChild(imageWidget);
}
container.AddChild(imageWidget);
}
if (label != "")
{
textWidget.VAnchor = VAnchor.ParentCenter;
textWidget.TextColor = textColor;
textWidget.Padding = new BorderDouble(3, 0);
container.AddChild(textWidget);
}
if (label != "")
{
textWidget.VAnchor = VAnchor.ParentCenter;
textWidget.TextColor = textColor;
textWidget.Padding = new BorderDouble(3, 0);
container.AddChild(textWidget);
}
if (centerText)
{
GuiWidget rightSpace = new GuiWidget(0, 1);
rightSpace.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
container.AddChild(rightSpace);
if (centerText)
{
GuiWidget rightSpace = new GuiWidget(0, 1);
rightSpace.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
container.AddChild(rightSpace);
container.HAnchor = Agg.UI.HAnchor.ParentLeftRight | Agg.UI.HAnchor.FitToChildren;
}
container.VAnchor = Agg.UI.VAnchor.ParentCenter;
container.HAnchor = Agg.UI.HAnchor.ParentLeftRight | Agg.UI.HAnchor.FitToChildren;
}
container.VAnchor = Agg.UI.VAnchor.ParentCenter;
container.MinimumSize = new Vector2(width, height);
container.Margin = margin;
this.AddChild(container);
HAnchor = HAnchor.ParentLeftRight | HAnchor.FitToChildren;
VAnchor = VAnchor.ParentCenter | Agg.UI.VAnchor.FitToChildren;
}
container.MinimumSize = new Vector2(width, height);
container.Margin = margin;
this.AddChild(container);
HAnchor = HAnchor.ParentLeftRight | HAnchor.FitToChildren;
VAnchor = VAnchor.ParentCenter | Agg.UI.VAnchor.FitToChildren;
}
public override void OnDraw(Graphics2D graphics2D)
{
if (borderColor.Alpha0To255 > 0)
{
RectangleDouble borderRectangle = LocalBounds;
public override void OnDraw(Graphics2D graphics2D)
{
if (borderColor.Alpha0To255 > 0)
{
RectangleDouble borderRectangle = LocalBounds;
if (borderWidth > 0)
{
if (borderWidth == 1)
{
graphics2D.Rectangle(borderRectangle, borderColor);
}
else
{
//boarderRectangle.Inflate(-borderWidth / 2);
RoundedRect rectBorder = new RoundedRect(borderRectangle, this.borderRadius);
if (borderWidth > 0)
{
if (borderWidth == 1)
{
graphics2D.Rectangle(borderRectangle, borderColor);
}
else
{
//boarderRectangle.Inflate(-borderWidth / 2);
RoundedRect rectBorder = new RoundedRect(borderRectangle, this.borderRadius);
graphics2D.Render(new Stroke(rectBorder, borderWidth), borderColor);
}
}
}
graphics2D.Render(new Stroke(rectBorder, borderWidth), borderColor);
}
}
}
if (this.fillColor.Alpha0To255 > 0)
{
RectangleDouble insideBounds = LocalBounds;
insideBounds.Inflate(-this.borderWidth);
RoundedRect rectInside = new RoundedRect(insideBounds, Math.Max(this.borderRadius - this.borderWidth, 0));
if (this.fillColor.Alpha0To255 > 0)
{
RectangleDouble insideBounds = LocalBounds;
insideBounds.Inflate(-this.borderWidth);
RoundedRect rectInside = new RoundedRect(insideBounds, Math.Max(this.borderRadius - this.borderWidth, 0));
graphics2D.Render(rectInside, this.fillColor);
}
graphics2D.Render(rectInside, this.fillColor);
}
base.OnDraw(graphics2D);
}
}
base.OnDraw(graphics2D);
}
}
public class TextImageButtonFactory
{
public BorderDouble Margin = new BorderDouble(6, 0);
public RGBA_Bytes normalFillColor = new RGBA_Bytes(0, 0, 0, 0);
public RGBA_Bytes hoverFillColor = new RGBA_Bytes(0, 0, 0, 50);
public RGBA_Bytes pressedFillColor = new RGBA_Bytes(0, 0, 0, 0);
public RGBA_Bytes disabledFillColor = new RGBA_Bytes(255, 255, 255, 50);
public class TextImageButtonFactory
{
public BorderDouble Margin = new BorderDouble(6, 0);
public RGBA_Bytes normalFillColor = new RGBA_Bytes(0, 0, 0, 0);
public RGBA_Bytes hoverFillColor = new RGBA_Bytes(0, 0, 0, 50);
public RGBA_Bytes pressedFillColor = new RGBA_Bytes(0, 0, 0, 0);
public RGBA_Bytes disabledFillColor = new RGBA_Bytes(255, 255, 255, 50);
public RGBA_Bytes normalBorderColor = new RGBA_Bytes(255, 255, 255, 0);
public RGBA_Bytes hoverBorderColor = new RGBA_Bytes(0, 0, 0, 0);
public RGBA_Bytes pressedBorderColor = new RGBA_Bytes(0, 0, 0, 0);
public RGBA_Bytes disabledBorderColor = new RGBA_Bytes(0, 0, 0, 0);
public RGBA_Bytes checkedBorderColor = new RGBA_Bytes(255, 255, 255, 0);
public RGBA_Bytes normalBorderColor = new RGBA_Bytes(255, 255, 255, 0);
public RGBA_Bytes hoverBorderColor = new RGBA_Bytes(0, 0, 0, 0);
public RGBA_Bytes pressedBorderColor = new RGBA_Bytes(0, 0, 0, 0);
public RGBA_Bytes disabledBorderColor = new RGBA_Bytes(0, 0, 0, 0);
public RGBA_Bytes checkedBorderColor = new RGBA_Bytes(255, 255, 255, 0);
public RGBA_Bytes normalTextColor = ActiveTheme.Instance.PrimaryTextColor;
public RGBA_Bytes hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
public RGBA_Bytes pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;
public RGBA_Bytes disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
public int fontSize = 12;
public double borderWidth = 1;
public bool invertImageLocation = false;
public bool AllowThemeToAdjustImage = true;
FlowDirection flowDirection;
public double FixedWidth = 0;
public double FixedHeight = 40;
public RGBA_Bytes normalTextColor = ActiveTheme.Instance.PrimaryTextColor;
public RGBA_Bytes hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
public RGBA_Bytes pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;
public RGBA_Bytes disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
public int fontSize = 12;
public double borderWidth = 1;
public bool invertImageLocation = false;
public bool AllowThemeToAdjustImage = true;
private FlowDirection flowDirection;
public double FixedWidth = 0;
public double FixedHeight = 40;
public double ImageSpacing = 0;
public TooltipButton GenerateTooltipButton(string label, string normalImageName = null, string hoverImageName = null, string pressedImageName = null, string disabledImageName = null)
{
//Create button based on view container widget
ButtonViewStates buttonViewWidget = getButtonView(label, normalImageName, hoverImageName, pressedImageName, disabledImageName);
public TooltipButton GenerateTooltipButton(string label, string normalImageName = null, string hoverImageName = null, string pressedImageName = null, string disabledImageName = null)
{
//Create button based on view container widget
ButtonViewStates buttonViewWidget = getButtonView(label, normalImageName, hoverImageName, pressedImageName, disabledImageName);
TooltipButton textImageButton = new TooltipButton(0, 0, buttonViewWidget);
textImageButton.Margin = new BorderDouble(0);
textImageButton.Padding = new BorderDouble(0);
TooltipButton textImageButton = new TooltipButton(0, 0, buttonViewWidget);
textImageButton.Margin = new BorderDouble(0);
textImageButton.Padding = new BorderDouble(0);
//Override the width if requested
if (this.FixedWidth != 0)
{
buttonViewWidget.Width = this.FixedWidth;
textImageButton.Width = this.FixedWidth;
}
//Override the width if requested
if (this.FixedWidth != 0)
{
buttonViewWidget.Width = this.FixedWidth;
textImageButton.Width = this.FixedWidth;
}
//Override the height if requested
buttonViewWidget.Height = this.FixedHeight;
textImageButton.Height = this.FixedHeight;
//Override the height if requested
buttonViewWidget.Height = this.FixedHeight;
textImageButton.Height = this.FixedHeight;
textImageButton.MouseEnterBounds += new EventHandler(onEnterTooltipButton);
textImageButton.MouseLeaveBounds += new EventHandler(onExitTooltipButton);
return textImageButton;
}
textImageButton.MouseEnterBounds += new EventHandler(onEnterTooltipButton);
textImageButton.MouseLeaveBounds += new EventHandler(onExitTooltipButton);
return textImageButton;
}
private ImageBuffer LoadUpButtonImage(string imageName)
{
ImageBuffer buffer = new ImageBuffer(10, 10, 32, new BlenderBGRA());
StaticData.Instance.LoadIcon(imageName, buffer);
ImageBuffer LoadUpButtonImage(string imageName)
{
ImageBuffer buffer = new ImageBuffer(10, 10, 32, new BlenderBGRA());
StaticData.Instance.LoadIcon(imageName, buffer);
if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
{
InvertLightness.DoInvertLightness(buffer);
}
return buffer;
}
if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
{
InvertLightness.DoInvertLightness(buffer);
}
return buffer;
}
public Button GenerateEditButton()
{
Button editButton = new Button(0, 0, new ButtonViewThreeImage(LoadUpButtonImage("icon_edit_white.png"), LoadUpButtonImage("icon_edit_gray.png"), LoadUpButtonImage("icon_edit_black.png")));
editButton.Margin = new BorderDouble(2, 2, 2, 0);
editButton.VAnchor = Agg.UI.VAnchor.ParentTop;
return editButton;
}
public Button GenerateEditButton()
{
Button editButton = new Button(0, 0, new ButtonViewThreeImage(LoadUpButtonImage("icon_edit_white.png"), LoadUpButtonImage("icon_edit_gray.png"), LoadUpButtonImage("icon_edit_black.png")));
editButton.Margin = new BorderDouble(2, 2, 2, 0);
editButton.VAnchor = Agg.UI.VAnchor.ParentTop;
return editButton;
}
public GuiWidget GenerateGroupBoxLabelWithEdit(TextWidget textWidget, out Button editButton)
{
FlowLayoutWidget groupLableAndEditControl = new FlowLayoutWidget();
public GuiWidget GenerateGroupBoxLabelWithEdit(TextWidget textWidget, out Button editButton)
{
FlowLayoutWidget groupLableAndEditControl = new FlowLayoutWidget();
editButton = new Button(0, 0, new ButtonViewThreeImage(LoadUpButtonImage("icon_edit_white.png"), LoadUpButtonImage("icon_edit_gray.png"), LoadUpButtonImage("icon_edit_black.png")));
editButton.Margin = new BorderDouble(2, 2, 2, 0);
editButton.VAnchor = Agg.UI.VAnchor.ParentBottom;
textWidget.VAnchor = Agg.UI.VAnchor.ParentBottom;
groupLableAndEditControl.AddChild(textWidget);
groupLableAndEditControl.AddChild(editButton);
editButton.Margin = new BorderDouble(2, 2, 2, 0);
editButton.VAnchor = Agg.UI.VAnchor.ParentBottom;
textWidget.VAnchor = Agg.UI.VAnchor.ParentBottom;
groupLableAndEditControl.AddChild(textWidget);
groupLableAndEditControl.AddChild(editButton);
return groupLableAndEditControl;
}
return groupLableAndEditControl;
}
public GuiWidget GenerateGroupBoxLabelWithEdit(string label, out Button editButton)
{
FlowLayoutWidget groupLableAndEditControl = new FlowLayoutWidget();
public GuiWidget GenerateGroupBoxLabelWithEdit(string label, out Button editButton)
{
FlowLayoutWidget groupLableAndEditControl = new FlowLayoutWidget();
editButton = new Button(0, 0, new ButtonViewThreeImage(LoadUpButtonImage("icon_edit_white.png"), LoadUpButtonImage("icon_edit_gray.png"), LoadUpButtonImage("icon_edit_black.png")));
editButton.Margin = new BorderDouble(2, 2, 2, 0);
editButton.VAnchor = Agg.UI.VAnchor.ParentBottom;
TextWidget textLabel = new TextWidget(label, textColor: ActiveTheme.Instance.PrimaryTextColor, pointSize:12);
textLabel.VAnchor = Agg.UI.VAnchor.ParentBottom;
groupLableAndEditControl.AddChild(textLabel);
groupLableAndEditControl.AddChild(editButton);
editButton.Margin = new BorderDouble(2, 2, 2, 0);
editButton.VAnchor = Agg.UI.VAnchor.ParentBottom;
TextWidget textLabel = new TextWidget(label, textColor: ActiveTheme.Instance.PrimaryTextColor, pointSize: 12);
textLabel.VAnchor = Agg.UI.VAnchor.ParentBottom;
groupLableAndEditControl.AddChild(textLabel);
groupLableAndEditControl.AddChild(editButton);
return groupLableAndEditControl;
}
return groupLableAndEditControl;
}
private void onEnterTooltipButton(object sender, EventArgs e)
{
TooltipButton button = (TooltipButton)sender;
HelpTextWidget.Instance.ShowHoverText(button.tooltipText);
}
private void onEnterTooltipButton(object sender, EventArgs e)
{
TooltipButton button = (TooltipButton)sender;
HelpTextWidget.Instance.ShowHoverText(button.tooltipText);
}
private void onExitTooltipButton(object sender, EventArgs e)
{
HelpTextWidget.Instance.HideHoverText();
}
private void onExitTooltipButton(object sender, EventArgs e)
{
HelpTextWidget.Instance.HideHoverText();
}
public CheckBox GenerateCheckBoxButton(string label, string normalImageName = null, string normalToPressedImageName = null, string pressedImageName = null, string pressedToNormalImageName = null, string pressedLabel = null)
{
CheckBoxViewStates checkBoxButtonViewWidget = getCheckBoxButtonView(label, normalImageName, normalToPressedImageName, pressedImageName, pressedToNormalImageName, pressedLabel);
public CheckBox GenerateCheckBoxButton(string label, string normalImageName = null, string normalToPressedImageName = null, string pressedImageName = null, string pressedToNormalImageName = null, string pressedLabel = null)
{
CheckBoxViewStates checkBoxButtonViewWidget = getCheckBoxButtonView(label, normalImageName, normalToPressedImageName, pressedImageName, pressedToNormalImageName, pressedLabel);
//Override the width if requested
if (this.FixedWidth != 0)
{
checkBoxButtonViewWidget.Width = this.FixedWidth;
}
//Override the width if requested
if (this.FixedWidth != 0)
{
checkBoxButtonViewWidget.Width = this.FixedWidth;
}
CheckBox textImageCheckBoxButton = new CheckBox(0, 0, checkBoxButtonViewWidget);
textImageCheckBoxButton.Margin = new BorderDouble(0);
textImageCheckBoxButton.Padding = new BorderDouble(0);
CheckBox textImageCheckBoxButton = new CheckBox(0, 0, checkBoxButtonViewWidget);
textImageCheckBoxButton.Margin = new BorderDouble(0);
textImageCheckBoxButton.Padding = new BorderDouble(0);
return textImageCheckBoxButton;
}
return textImageCheckBoxButton;
}
public Button GenerateFromImages(string label, ImageBuffer normalImage, ImageBuffer hoverImage = null, ImageBuffer pressedImage = null, ImageBuffer disabledImage = null, bool centerText = false)
{
//Create button based on view container widget
ButtonViewStates buttonViewWidget = getButtonView(label, normalImage, hoverImage, pressedImage, disabledImage, centerText);
Button textImageButton = new Button(0, 0, buttonViewWidget);
public Button GenerateFromImages(string label, ImageBuffer normalImage, ImageBuffer hoverImage = null, ImageBuffer pressedImage = null, ImageBuffer disabledImage = null, bool centerText = false)
{
//Create button based on view container widget
ButtonViewStates buttonViewWidget = getButtonView(label, normalImage, hoverImage, pressedImage, disabledImage, centerText);
Button textImageButton = new Button(0, 0, buttonViewWidget);
textImageButton.Margin = new BorderDouble(0);
textImageButton.Padding = new BorderDouble(0);
textImageButton.Margin = new BorderDouble(0);
textImageButton.Padding = new BorderDouble(0);
//Override the width if requested
if (this.FixedWidth != 0)
{
buttonViewWidget.Width = this.FixedWidth;
textImageButton.Width = this.FixedWidth;
}
return textImageButton;
}
//Override the width if requested
if (this.FixedWidth != 0)
{
buttonViewWidget.Width = this.FixedWidth;
textImageButton.Width = this.FixedWidth;
}
return textImageButton;
}
public Button Generate(string label, string normalImageName = null, string hoverImageName = null, string pressedImageName = null, string disabledImageName = null, bool centerText = false)
{
//Create button based on view container widget
ButtonViewStates buttonViewWidget = getButtonView(label, normalImageName, hoverImageName, pressedImageName, disabledImageName, centerText);
Button textImageButton = new Button(0, 0, buttonViewWidget);
public Button Generate(string label, string normalImageName = null, string hoverImageName = null, string pressedImageName = null, string disabledImageName = null, bool centerText = false)
{
//Create button based on view container widget
ButtonViewStates buttonViewWidget = getButtonView(label, normalImageName, hoverImageName, pressedImageName, disabledImageName, centerText);
Button textImageButton = new Button(0, 0, buttonViewWidget);
textImageButton.Margin = new BorderDouble(0);
textImageButton.Padding = new BorderDouble(0);
textImageButton.Margin = new BorderDouble(0);
textImageButton.Padding = new BorderDouble(0);
//Override the width if requested
if (this.FixedWidth != 0)
{
buttonViewWidget.Width = this.FixedWidth;
textImageButton.Width = this.FixedWidth;
}
return textImageButton;
}
//Override the width if requested
if (this.FixedWidth != 0)
{
buttonViewWidget.Width = this.FixedWidth;
textImageButton.Width = this.FixedWidth;
}
return textImageButton;
}
private ButtonViewStates getButtonView(string label, string normalImageName = null, string hoverImageName = null, string pressedImageName = null, string disabledImageName = null, bool centerText = false)
{
if (hoverImageName == null)
{
hoverImageName = normalImageName;
}
private ButtonViewStates getButtonView(string label, string normalImageName = null, string hoverImageName = null, string pressedImageName = null, string disabledImageName = null, bool centerText = false)
{
if (hoverImageName == null)
{
hoverImageName = normalImageName;
}
if (pressedImageName == null)
{
pressedImageName = hoverImageName;
}
if (pressedImageName == null)
{
pressedImageName = hoverImageName;
}
if (disabledImageName == null)
{
disabledImageName = normalImageName;
}
if (disabledImageName == null)
{
disabledImageName = normalImageName;
}
ImageBuffer normalImage = null;
ImageBuffer pressedImage = null;
ImageBuffer hoverImage = null;
ImageBuffer disabledImage = null;
ImageBuffer normalImage = null;
ImageBuffer pressedImage = null;
ImageBuffer hoverImage = null;
ImageBuffer disabledImage = null;
if (normalImageName != null)
{
normalImage = new ImageBuffer();
StaticData.Instance.LoadIcon(normalImageName, normalImage);
}
if (normalImageName != null)
{
normalImage = new ImageBuffer();
StaticData.Instance.LoadIcon(normalImageName, normalImage);
}
if (hoverImageName != null)
{
hoverImage = new ImageBuffer();
StaticData.Instance.LoadIcon(hoverImageName, hoverImage);
}
if (hoverImageName != null)
{
hoverImage = new ImageBuffer();
StaticData.Instance.LoadIcon(hoverImageName, hoverImage);
}
if (pressedImageName != null)
{
pressedImage = new ImageBuffer();
StaticData.Instance.LoadIcon(pressedImageName, pressedImage);
}
if (pressedImageName != null)
{
pressedImage = new ImageBuffer();
StaticData.Instance.LoadIcon(pressedImageName, pressedImage);
}
if (disabledImageName != null)
{
disabledImage = new ImageBuffer();
StaticData.Instance.LoadIcon(disabledImageName, disabledImage);
}
if (disabledImageName != null)
{
disabledImage = new ImageBuffer();
StaticData.Instance.LoadIcon(disabledImageName, disabledImage);
}
return getButtonView(label, normalImage, hoverImage, pressedImage, disabledImage, centerText);
}
return getButtonView(label, normalImage, hoverImage, pressedImage, disabledImage, centerText);
}
private ButtonViewStates getButtonView(string label, ImageBuffer normalImage = null, ImageBuffer hoverImage = null, ImageBuffer pressedImage = null, ImageBuffer disabledImage = null, bool centerText = false)
{
if (hoverImage == null && normalImage != null)
{
hoverImage = new ImageBuffer(normalImage);
}
private ButtonViewStates getButtonView(string label, ImageBuffer normalImage = null, ImageBuffer hoverImage = null, ImageBuffer pressedImage = null, ImageBuffer disabledImage = null, bool centerText = false)
{
if (hoverImage == null && normalImage != null)
{
hoverImage = new ImageBuffer(normalImage);
}
if (pressedImage == null && hoverImage != null)
{
pressedImage = new ImageBuffer(hoverImage);
}
if (pressedImage == null && hoverImage != null)
{
pressedImage = new ImageBuffer(hoverImage);
}
if (disabledImage == null && normalImage != null)
{
disabledImage = new ImageBuffer(normalImage);
}
if (disabledImage == null && normalImage != null)
{
disabledImage = new ImageBuffer(normalImage);
}
if (!ActiveTheme.Instance.IsDarkTheme
&& AllowThemeToAdjustImage)
{
if(normalImage != null) InvertLightness.DoInvertLightness(normalImage);
if (pressedImage != null) InvertLightness.DoInvertLightness(pressedImage);
if (hoverImage != null) InvertLightness.DoInvertLightness(hoverImage);
if (disabledImage != null) InvertLightness.DoInvertLightness(disabledImage);
}
if (!ActiveTheme.Instance.IsDarkTheme
&& AllowThemeToAdjustImage)
{
if (normalImage != null) InvertLightness.DoInvertLightness(normalImage);
if (pressedImage != null) InvertLightness.DoInvertLightness(pressedImage);
if (hoverImage != null) InvertLightness.DoInvertLightness(hoverImage);
if (disabledImage != null) InvertLightness.DoInvertLightness(disabledImage);
}
if (invertImageLocation)
{
flowDirection = FlowDirection.RightToLeft;
}
else
{
flowDirection = FlowDirection.LeftToRight;
}
if (invertImageLocation)
{
flowDirection = FlowDirection.RightToLeft;
}
else
{
flowDirection = FlowDirection.LeftToRight;
}
//Create the multi-state button view
ButtonViewStates buttonViewWidget = new ButtonViewStates(
//Create the multi-state button view
ButtonViewStates buttonViewWidget = new ButtonViewStates(
new TextImageWidget(label, normalFillColor, normalBorderColor, normalTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, centerText: centerText, imageSpacing: ImageSpacing),
new TextImageWidget(label, hoverFillColor, hoverBorderColor, hoverTextColor, borderWidth, Margin, hoverImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, centerText: centerText, imageSpacing: ImageSpacing),
new TextImageWidget(label, pressedFillColor, pressedBorderColor, pressedTextColor, borderWidth, Margin, pressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, centerText: centerText, imageSpacing: ImageSpacing),
new TextImageWidget(label, disabledFillColor, disabledBorderColor, disabledTextColor, borderWidth, Margin, disabledImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, centerText: centerText, imageSpacing: ImageSpacing)
);
return buttonViewWidget;
}
);
return buttonViewWidget;
}
private CheckBoxViewStates getCheckBoxButtonView(string label, string normalImageName = null, string normalToPressedImageName = null, string pressedImageName = null, string pressedToNormalImageName = null, string pressedLabel = null)
{
ImageBuffer normalImage = new ImageBuffer();
ImageBuffer pressedImage = new ImageBuffer();
ImageBuffer normalToPressedImage = new ImageBuffer();
ImageBuffer pressedToNormalImage = new ImageBuffer();
string pressedText = pressedLabel;
private CheckBoxViewStates getCheckBoxButtonView(string label, string normalImageName = null, string normalToPressedImageName = null, string pressedImageName = null, string pressedToNormalImageName = null, string pressedLabel = null)
{
ImageBuffer normalImage = new ImageBuffer();
ImageBuffer pressedImage = new ImageBuffer();
ImageBuffer normalToPressedImage = new ImageBuffer();
ImageBuffer pressedToNormalImage = new ImageBuffer();
string pressedText = pressedLabel;
if (pressedLabel == null)
{
pressedText = label;
}
if (pressedLabel == null)
{
pressedText = label;
}
if (normalToPressedImageName == null)
{
normalToPressedImageName = pressedImageName;
}
if (normalToPressedImageName == null)
{
normalToPressedImageName = pressedImageName;
}
if (pressedImageName == null)
{
pressedImageName = normalToPressedImageName;
}
if (pressedImageName == null)
{
pressedImageName = normalToPressedImageName;
}
if (pressedToNormalImageName == null)
{
pressedToNormalImageName = normalImageName;
}
if (pressedToNormalImageName == null)
{
pressedToNormalImageName = normalImageName;
}
if (normalImageName != null)
{
StaticData.Instance.LoadIcon(normalImageName, normalImage);
if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
{
InvertLightness.DoInvertLightness(normalImage);
}
}
if (normalImageName != null)
{
StaticData.Instance.LoadIcon(normalImageName, normalImage);
if (pressedImageName != null)
{
StaticData.Instance.LoadIcon(pressedImageName, pressedImage);
if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
{
InvertLightness.DoInvertLightness(pressedImage);
}
if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
{
InvertLightness.DoInvertLightness(normalImage);
}
}
}
if (pressedImageName != null)
{
StaticData.Instance.LoadIcon(pressedImageName, pressedImage);
if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
{
InvertLightness.DoInvertLightness(pressedImage);
}
}
if (normalToPressedImageName != null)
{
StaticData.Instance.LoadIcon(normalToPressedImageName, normalToPressedImage);
if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
{
InvertLightness.DoInvertLightness(normalToPressedImage);
}
}
if (normalToPressedImageName != null)
{
StaticData.Instance.LoadIcon(normalToPressedImageName, normalToPressedImage);
if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
{
InvertLightness.DoInvertLightness(normalToPressedImage);
}
}
if (pressedToNormalImageName != null)
{
StaticData.Instance.LoadIcon(pressedToNormalImageName, pressedToNormalImage);
if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
{
InvertLightness.DoInvertLightness(pressedToNormalImage);
}
}
if (pressedToNormalImageName != null)
{
StaticData.Instance.LoadIcon(pressedToNormalImageName, pressedToNormalImage);
if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
{
InvertLightness.DoInvertLightness(pressedToNormalImage);
}
}
if (invertImageLocation)
{
flowDirection = FlowDirection.RightToLeft;
}
else
{
flowDirection = FlowDirection.LeftToRight;
}
if (invertImageLocation)
{
flowDirection = FlowDirection.RightToLeft;
}
else
{
flowDirection = FlowDirection.LeftToRight;
}
//Create the multi-state button view
GuiWidget normal = new TextImageWidget(label, normalFillColor, normalBorderColor, normalTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
GuiWidget normalHover = new TextImageWidget(label, hoverFillColor, normalBorderColor, hoverTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
GuiWidget switchNormalToPressed = new TextImageWidget(label, pressedFillColor, normalBorderColor, pressedTextColor, borderWidth, Margin, normalToPressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
GuiWidget pressed = new TextImageWidget(pressedText, pressedFillColor, pressedBorderColor, pressedTextColor, borderWidth, Margin, pressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
GuiWidget pressedHover = new TextImageWidget(label, hoverFillColor, pressedBorderColor, hoverTextColor, borderWidth, Margin, pressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
GuiWidget switchPressedToNormal = new TextImageWidget(label, normalFillColor, pressedBorderColor, normalTextColor, borderWidth, Margin, pressedToNormalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
GuiWidget disabled = new TextImageWidget(label, disabledFillColor, disabledBorderColor, disabledTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
//Create the multi-state button view
GuiWidget normal = new TextImageWidget(label, normalFillColor, normalBorderColor, normalTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
GuiWidget normalHover = new TextImageWidget(label, hoverFillColor, normalBorderColor, hoverTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
GuiWidget switchNormalToPressed = new TextImageWidget(label, pressedFillColor, normalBorderColor, pressedTextColor, borderWidth, Margin, normalToPressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
GuiWidget pressed = new TextImageWidget(pressedText, pressedFillColor, pressedBorderColor, pressedTextColor, borderWidth, Margin, pressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
GuiWidget pressedHover = new TextImageWidget(label, hoverFillColor, pressedBorderColor, hoverTextColor, borderWidth, Margin, pressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
GuiWidget switchPressedToNormal = new TextImageWidget(label, normalFillColor, pressedBorderColor, normalTextColor, borderWidth, Margin, pressedToNormalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
GuiWidget disabled = new TextImageWidget(label, disabledFillColor, disabledBorderColor, disabledTextColor, borderWidth, Margin, normalImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight);
CheckBoxViewStates checkBoxButtonViewWidget = new CheckBoxViewStates(normal, normalHover, switchNormalToPressed, pressed, pressedHover, switchPressedToNormal, disabled);
return checkBoxButtonViewWidget;
}
CheckBoxViewStates checkBoxButtonViewWidget = new CheckBoxViewStates(normal, normalHover, switchNormalToPressed, pressed, pressedHover, switchPressedToNormal, disabled);
return checkBoxButtonViewWidget;
}
public RadioButton GenerateRadioButton(string label, string iconImageName = null)
{
ImageBuffer iconImage = null;
public RadioButton GenerateRadioButton(string label, string iconImageName = null)
{
ImageBuffer iconImage = null;
if (iconImageName != null)
{
iconImage = StaticData.Instance.LoadIcon(iconImageName);
if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
{
InvertLightness.DoInvertLightness(iconImage);
}
}
if (iconImageName != null)
{
iconImage = StaticData.Instance.LoadIcon(iconImageName);
if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
{
InvertLightness.DoInvertLightness(iconImage);
}
}
BorderDouble internalMargin = new BorderDouble(0);
TextImageWidget nomalState = new TextImageWidget(label, normalFillColor, normalBorderColor, normalTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
TextImageWidget hoverState = new TextImageWidget(label, hoverFillColor, hoverBorderColor, hoverTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
TextImageWidget checkingState = new TextImageWidget(label, hoverFillColor, checkedBorderColor, hoverTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
TextImageWidget checkedState = new TextImageWidget(label, pressedFillColor, checkedBorderColor, pressedTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
TextImageWidget disabledState = new TextImageWidget(label, disabledFillColor, disabledBorderColor, disabledTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
RadioButtonViewStates checkBoxButtonViewWidget = new RadioButtonViewStates(nomalState, hoverState, checkingState, checkedState, disabledState);
RadioButton radioButton = new RadioButton(checkBoxButtonViewWidget);
radioButton.Margin = Margin;
return radioButton;
}
}
BorderDouble internalMargin = new BorderDouble(0);
TextImageWidget nomalState = new TextImageWidget(label, normalFillColor, normalBorderColor, normalTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
TextImageWidget hoverState = new TextImageWidget(label, hoverFillColor, hoverBorderColor, hoverTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
TextImageWidget checkingState = new TextImageWidget(label, hoverFillColor, checkedBorderColor, hoverTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
TextImageWidget checkedState = new TextImageWidget(label, pressedFillColor, checkedBorderColor, pressedTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
TextImageWidget disabledState = new TextImageWidget(label, disabledFillColor, disabledBorderColor, disabledTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
RadioButtonViewStates checkBoxButtonViewWidget = new RadioButtonViewStates(nomalState, hoverState, checkingState, checkedState, disabledState);
RadioButton radioButton = new RadioButton(checkBoxButtonViewWidget);
radioButton.Margin = Margin;
return radioButton;
}
}
public class TooltipButton : Button
{
public string tooltipText = "";
public class TooltipButton : Button
{
public string tooltipText = "";
public TooltipButton(double x, double y, GuiWidget buttonView)
:base(x, y, buttonView)
{
}
}
}
public TooltipButton(double x, double y, GuiWidget buttonView)
: base(x, y, buttonView)
{
}
}
}

View file

@ -1,15 +1,18 @@
/*
using MatterHackers.Agg;
using MatterHackers.MatterControl.SettingsManagement;
/*
Copyright (c) 2014, Kevin Pope
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
@ -23,226 +26,211 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MatterHackers.Agg;
using MatterHackers.Agg.Transform;
using MatterHackers.Agg.Image;
using MatterHackers.Agg.VertexSource;
using MatterHackers.Agg.UI;
using MatterHackers.Agg.Font;
using MatterHackers.VectorMath;
using MatterHackers.MatterControl;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.SettingsManagement;
namespace MatterHackers.MatterControl
{
public class ActiveTheme
{
static ActiveTheme globalInstance;
private Theme loadedTheme;
private List<Theme> availableThemes;
private int defaultThemeIndex = 1;
private int activeThemeIndex = -1;
public class ActiveTheme
{
private static ActiveTheme globalInstance;
private Theme loadedTheme;
private List<Theme> availableThemes;
private int defaultThemeIndex = 1;
private int activeThemeIndex = -1;
public RootedObjectEventHandler ThemeChanged = new RootedObjectEventHandler();
public RootedObjectEventHandler ThemeChanged = new RootedObjectEventHandler();
public enum ApplicationDisplayType { Responsive, Touchscreen } ;
public enum ApplicationDisplayType { Responsive, Touchscreen } ;
public ApplicationDisplayType DisplayMode
{
get
{
string displayMode = UserSettings.Instance.get("ApplicationDisplayMode");
if (displayMode == "touchscreen")
{
return ApplicationDisplayType.Touchscreen;
}
else
{
return ApplicationDisplayType.Responsive;
}
}
}
public ApplicationDisplayType DisplayMode
{
get
{
string displayMode = UserSettings.Instance.get("ApplicationDisplayMode");
if (displayMode == "touchscreen")
{
return ApplicationDisplayType.Touchscreen;
}
else
{
return ApplicationDisplayType.Responsive;
}
}
}
public List<Theme> AvailableThemes
{
get
{
if (this.availableThemes == null)
{
this.availableThemes = GetAvailableThemes();
}
return availableThemes;
}
}
public List<Theme> AvailableThemes
{
get
{
if (this.availableThemes == null)
{
this.availableThemes = GetAvailableThemes();
}
return availableThemes;
}
}
public bool IsDarkTheme
{
get
{
return loadedTheme.DarkTheme;
}
}
public bool IsDarkTheme
{
get
{
return loadedTheme.DarkTheme;
}
}
public RGBA_Bytes Transparent
{
get
{
return new RGBA_Bytes(0,0,0,0);
return new RGBA_Bytes(0, 0, 0, 0);
}
}
public RGBA_Bytes TransparentDarkOverlay
{
get
{
return new RGBA_Bytes(0,0,0,50);
}
}
public RGBA_Bytes TransparentDarkOverlay
{
get
{
return new RGBA_Bytes(0, 0, 0, 50);
}
}
public RGBA_Bytes TransparentLightOverlay
{
get
{
return new RGBA_Bytes(255,255,255,50);
}
}
public RGBA_Bytes TransparentLightOverlay
{
get
{
return new RGBA_Bytes(255, 255, 255, 50);
}
}
public RGBA_Bytes TabLabelSelected
{
get
{
return loadedTheme.tabLabelSelectedColor;
}
}
public RGBA_Bytes TabLabelSelected
{
get
{
return loadedTheme.tabLabelSelectedColor;
}
}
public RGBA_Bytes TabLabelUnselected
{
get
{
return loadedTheme.tabLabelUnselectedColor;
}
}
public RGBA_Bytes TabLabelUnselected
{
get
{
return loadedTheme.tabLabelUnselectedColor;
}
}
public RGBA_Bytes SecondaryTextColor
{
get
{
return loadedTheme.secondaryTextColor;
}
}
public RGBA_Bytes SecondaryTextColor
{
get
{
return loadedTheme.secondaryTextColor;
}
}
public RGBA_Bytes PrimaryBackgroundColor
{
get
{
return loadedTheme.primaryBackgroundColor;
}
}
public RGBA_Bytes PrimaryBackgroundColor
{
get
{
return loadedTheme.primaryBackgroundColor;
}
}
public RGBA_Bytes SecondaryBackgroundColor
{
get
{
return loadedTheme.secondaryBackgroundColor;
}
}
public RGBA_Bytes SecondaryBackgroundColor
{
get
{
return loadedTheme.secondaryBackgroundColor;
}
}
public RGBA_Bytes TertiaryBackgroundColor
{
get
{
return loadedTheme.tertiaryBackgroundColor;
}
}
public RGBA_Bytes TertiaryBackgroundColor
{
get
{
return loadedTheme.tertiaryBackgroundColor;
}
}
public RGBA_Bytes PrimaryTextColor
{
get
{
return loadedTheme.primaryTextColor;
}
}
public RGBA_Bytes PrimaryTextColor
{
get
{
return loadedTheme.primaryTextColor;
}
}
public RGBA_Bytes PrimaryAccentColor
{
get
{
return loadedTheme.primaryAccentColor;
}
}
public RGBA_Bytes PrimaryAccentColor
{
get
{
return loadedTheme.primaryAccentColor;
}
}
public RGBA_Bytes SecondaryAccentColor
{
get
{
return loadedTheme.secondaryAccentColor;
}
}
private void OnThemeChanged(EventArgs e)
{
ThemeChanged.CallEvents(this, e);
}
public RGBA_Bytes SecondaryAccentColor
{
get
{
return loadedTheme.secondaryAccentColor;
}
}
public ActiveTheme()
{
//Load the default theme by index
if (UserSettings.Instance.get("ActiveThemeIndex") == null)
{
bool foundOemColor = false;
for (int i = 0; i < AvailableThemes.Count; i++)
{
Theme current = AvailableThemes[i];
if (current.Name == OemSettings.Instance.ThemeColor)
{
UserSettings.Instance.set("ActiveThemeIndex", i.ToString());
foundOemColor = true;
break;
}
}
private void OnThemeChanged(EventArgs e)
{
ThemeChanged.CallEvents(this, e);
}
if (!foundOemColor)
{
UserSettings.Instance.set("ActiveThemeIndex", defaultThemeIndex.ToString());
}
}
public ActiveTheme()
{
//Load the default theme by index
if (UserSettings.Instance.get("ActiveThemeIndex") == null)
{
bool foundOemColor = false;
for (int i = 0; i < AvailableThemes.Count; i++)
{
Theme current = AvailableThemes[i];
if (current.Name == OemSettings.Instance.ThemeColor)
{
UserSettings.Instance.set("ActiveThemeIndex", i.ToString());
foundOemColor = true;
break;
}
}
int themeIndex;
try
{
themeIndex = Convert.ToInt32(UserSettings.Instance.get("ActiveThemeIndex"));
}
catch
{
themeIndex = defaultThemeIndex;
}
if (!foundOemColor)
{
UserSettings.Instance.set("ActiveThemeIndex", defaultThemeIndex.ToString());
}
}
LoadThemeSettings(themeIndex);
}
int themeIndex;
try
{
themeIndex = Convert.ToInt32(UserSettings.Instance.get("ActiveThemeIndex"));
}
catch
{
themeIndex = defaultThemeIndex;
}
LoadThemeSettings(themeIndex);
}
public static ActiveTheme Instance
{
get
{
if (globalInstance == null)
{
globalInstance = new ActiveTheme();
}
return globalInstance;
}
}
public static ActiveTheme Instance
{
get
{
if (globalInstance == null)
{
globalInstance = new ActiveTheme();
}
return globalInstance;
}
}
public void ReloadThemeSettings()
{
@ -250,114 +238,113 @@ namespace MatterHackers.MatterControl
OnThemeChanged(null);
}
public void LoadThemeSettings(int index)
{
//Validate new theme selection and change theme
if (index > -1 && index < AvailableThemes.Count)
{
if (activeThemeIndex != index)
{
this.loadedTheme = this.AvailableThemes[index];
this.activeThemeIndex = index;
OnThemeChanged(null);
}
}
else
{
throw new Exception("Invalid theme selection");
}
}
public void LoadThemeSettings(int index)
{
//Validate new theme selection and change theme
if (index > -1 && index < AvailableThemes.Count)
{
if (activeThemeIndex != index)
{
this.loadedTheme = this.AvailableThemes[index];
this.activeThemeIndex = index;
OnThemeChanged(null);
}
}
else
{
throw new Exception("Invalid theme selection");
}
}
private List<Theme> GetAvailableThemes()
{
//Generate a list of available theme definitions
List<Theme> themeList = new List<Theme>();
private List<Theme> GetAvailableThemes()
{
//Generate a list of available theme definitions
List<Theme> themeList = new List<Theme>();
//Dark themes
themeList.Add(new Theme("Blue - Dark", new RGBA_Bytes(0, 75, 139), new RGBA_Bytes(0, 103, 190)));
themeList.Add(new Theme("Teal - Dark", new RGBA_Bytes(0, 130, 153), new RGBA_Bytes(0, 173, 204)));
themeList.Add(new Theme("Green - Dark", new RGBA_Bytes(0, 138, 23), new RGBA_Bytes(0, 189, 32)));
themeList.Add(new Theme("Light Blue - Dark", new RGBA_Bytes(93, 178, 255), new RGBA_Bytes(144, 202, 255)));
themeList.Add(new Theme("Orange - Dark", new RGBA_Bytes(255, 129, 25), new RGBA_Bytes(255, 157, 76)));
themeList.Add(new Theme("Purple - Dark", new RGBA_Bytes(70, 23, 180), new RGBA_Bytes(104, 51, 229)));
themeList.Add(new Theme("Red - Dark", new RGBA_Bytes(172, 25, 61), new RGBA_Bytes(217, 31, 77)));
themeList.Add(new Theme("Pink - Dark", new RGBA_Bytes(220, 79, 173), new RGBA_Bytes(233, 143, 203)));
themeList.Add(new Theme("Grey - Dark", new RGBA_Bytes(88, 88, 88), new RGBA_Bytes(114, 114, 114)));
themeList.Add(new Theme("Pink - Dark", new RGBA_Bytes(140, 0, 149), new RGBA_Bytes(188, 0, 200)));
//Dark themes
themeList.Add(new Theme("Blue - Dark", new RGBA_Bytes(0, 75, 139), new RGBA_Bytes(0, 103, 190)));
themeList.Add(new Theme("Teal - Dark", new RGBA_Bytes(0, 130, 153), new RGBA_Bytes(0, 173, 204)));
themeList.Add(new Theme("Green - Dark", new RGBA_Bytes(0, 138, 23), new RGBA_Bytes(0, 189, 32)));
themeList.Add(new Theme("Light Blue - Dark", new RGBA_Bytes(93, 178, 255), new RGBA_Bytes(144, 202, 255)));
themeList.Add(new Theme("Orange - Dark", new RGBA_Bytes(255, 129, 25), new RGBA_Bytes(255, 157, 76)));
themeList.Add(new Theme("Purple - Dark", new RGBA_Bytes(70, 23, 180), new RGBA_Bytes(104, 51, 229)));
themeList.Add(new Theme("Red - Dark", new RGBA_Bytes(172, 25, 61), new RGBA_Bytes(217, 31, 77)));
themeList.Add(new Theme("Pink - Dark", new RGBA_Bytes(220, 79, 173), new RGBA_Bytes(233, 143, 203)));
themeList.Add(new Theme("Grey - Dark", new RGBA_Bytes(88, 88, 88), new RGBA_Bytes(114, 114, 114)));
themeList.Add(new Theme("Pink - Dark", new RGBA_Bytes(140, 0, 149), new RGBA_Bytes(188, 0, 200)));
//Light themes
themeList.Add(new Theme("Blue - Light", new RGBA_Bytes(0, 75, 139), new RGBA_Bytes(0, 103, 190), false));
themeList.Add(new Theme("Teal - Light", new RGBA_Bytes(0, 130, 153), new RGBA_Bytes(0, 173, 204), false));
themeList.Add(new Theme("Green - Light", new RGBA_Bytes(0, 138, 23), new RGBA_Bytes(0, 189, 32), false));
themeList.Add(new Theme("Light Blue - Light", new RGBA_Bytes(93, 178, 255), new RGBA_Bytes(144, 202, 255), false));
themeList.Add(new Theme("Orange - Light", new RGBA_Bytes(255, 129, 25), new RGBA_Bytes(255, 157, 76), false));
themeList.Add(new Theme("Purple - Light", new RGBA_Bytes(70, 23, 180), new RGBA_Bytes(104, 51, 229), false));
themeList.Add(new Theme("Red - Light", new RGBA_Bytes(172, 25, 61), new RGBA_Bytes(217, 31, 77), false));
themeList.Add(new Theme("Pink - Light", new RGBA_Bytes(220, 79, 173), new RGBA_Bytes(233, 143, 203), false));
themeList.Add(new Theme("Grey - Light", new RGBA_Bytes(88, 88, 88), new RGBA_Bytes(114, 114, 114), false));
themeList.Add(new Theme("Pink - Light", new RGBA_Bytes(140, 0, 149), new RGBA_Bytes(188, 0, 200), false));
//Light themes
themeList.Add(new Theme("Blue - Light", new RGBA_Bytes(0, 75, 139), new RGBA_Bytes(0, 103, 190), false));
themeList.Add(new Theme("Teal - Light", new RGBA_Bytes(0, 130, 153), new RGBA_Bytes(0, 173, 204), false));
themeList.Add(new Theme("Green - Light", new RGBA_Bytes(0, 138, 23), new RGBA_Bytes(0, 189, 32), false));
themeList.Add(new Theme("Light Blue - Light", new RGBA_Bytes(93, 178, 255), new RGBA_Bytes(144, 202, 255), false));
themeList.Add(new Theme("Orange - Light", new RGBA_Bytes(255, 129, 25), new RGBA_Bytes(255, 157, 76), false));
themeList.Add(new Theme("Purple - Light", new RGBA_Bytes(70, 23, 180), new RGBA_Bytes(104, 51, 229), false));
themeList.Add(new Theme("Red - Light", new RGBA_Bytes(172, 25, 61), new RGBA_Bytes(217, 31, 77), false));
themeList.Add(new Theme("Pink - Light", new RGBA_Bytes(220, 79, 173), new RGBA_Bytes(233, 143, 203), false));
themeList.Add(new Theme("Grey - Light", new RGBA_Bytes(88, 88, 88), new RGBA_Bytes(114, 114, 114), false));
themeList.Add(new Theme("Pink - Light", new RGBA_Bytes(140, 0, 149), new RGBA_Bytes(188, 0, 200), false));
return themeList;
}
}
}
}
public class Theme
{
public RGBA_Bytes primaryAccentColor;
public RGBA_Bytes secondaryAccentColor;
public RGBA_Bytes primaryTextColor;
public RGBA_Bytes secondaryTextColor;
public RGBA_Bytes primaryBackgroundColor;
public RGBA_Bytes secondaryBackgroundColor;
public RGBA_Bytes tabLabelSelectedColor;
public RGBA_Bytes tabLabelUnselectedColor;
public class Theme
{
public RGBA_Bytes primaryAccentColor;
public RGBA_Bytes secondaryAccentColor;
public RGBA_Bytes primaryTextColor;
public RGBA_Bytes secondaryTextColor;
public RGBA_Bytes primaryBackgroundColor;
public RGBA_Bytes secondaryBackgroundColor;
public RGBA_Bytes tabLabelSelectedColor;
public RGBA_Bytes tabLabelUnselectedColor;
public RGBA_Bytes tertiaryBackgroundColor;
public RGBA_Bytes tertiaryBackgroundColorDisabled;
public RGBA_Bytes tertiaryBackgroundColor;
public RGBA_Bytes tertiaryBackgroundColorDisabled;
string name;
public string Name { get { return name; } }
bool darkTheme;
private string name;
public bool DarkTheme { get { return darkTheme; } }
public string Name { get { return name; } }
public Theme(string name, RGBA_Bytes primary, RGBA_Bytes secondary, bool darkTheme = true)
{
this.darkTheme = darkTheme;
this.name = name;
private bool darkTheme;
if (darkTheme)
{
this.primaryAccentColor = primary;
this.secondaryAccentColor = secondary;
this.primaryBackgroundColor = new RGBA_Bytes(68, 68, 68);
this.secondaryBackgroundColor = new RGBA_Bytes(51, 51, 51);
this.tabLabelSelectedColor = new RGBA_Bytes(255, 255, 255);
this.tabLabelUnselectedColor = new RGBA_Bytes(180, 180, 180);
this.primaryTextColor = new RGBA_Bytes(255, 255, 255);
this.secondaryTextColor = new RGBA_Bytes(200, 200, 200);
public bool DarkTheme { get { return darkTheme; } }
this.tertiaryBackgroundColor = new RGBA_Bytes(62, 62, 62);
}
else
{
this.primaryAccentColor = secondary;
this.secondaryAccentColor = primary;
public Theme(string name, RGBA_Bytes primary, RGBA_Bytes secondary, bool darkTheme = true)
{
this.darkTheme = darkTheme;
this.name = name;
this.primaryBackgroundColor = new RGBA_Bytes(208, 208, 208);
this.secondaryBackgroundColor = new RGBA_Bytes(185, 185, 185);
this.tabLabelSelectedColor = new RGBA_Bytes(51, 51, 51);
this.tabLabelUnselectedColor = new RGBA_Bytes(102, 102, 102);
this.primaryTextColor = new RGBA_Bytes(34, 34, 34);
this.secondaryTextColor = new RGBA_Bytes(51, 51, 51);
if (darkTheme)
{
this.primaryAccentColor = primary;
this.secondaryAccentColor = secondary;
this.tertiaryBackgroundColor = new RGBA_Bytes(190, 190, 190);
}
}
}
}
this.primaryBackgroundColor = new RGBA_Bytes(68, 68, 68);
this.secondaryBackgroundColor = new RGBA_Bytes(51, 51, 51);
this.tabLabelSelectedColor = new RGBA_Bytes(255, 255, 255);
this.tabLabelUnselectedColor = new RGBA_Bytes(180, 180, 180);
this.primaryTextColor = new RGBA_Bytes(255, 255, 255);
this.secondaryTextColor = new RGBA_Bytes(200, 200, 200);
this.tertiaryBackgroundColor = new RGBA_Bytes(62, 62, 62);
}
else
{
this.primaryAccentColor = secondary;
this.secondaryAccentColor = primary;
this.primaryBackgroundColor = new RGBA_Bytes(208, 208, 208);
this.secondaryBackgroundColor = new RGBA_Bytes(185, 185, 185);
this.tabLabelSelectedColor = new RGBA_Bytes(51, 51, 51);
this.tabLabelUnselectedColor = new RGBA_Bytes(102, 102, 102);
this.primaryTextColor = new RGBA_Bytes(34, 34, 34);
this.secondaryTextColor = new RGBA_Bytes(51, 51, 51);
this.tertiaryBackgroundColor = new RGBA_Bytes(190, 190, 190);
}
}
}
}

View file

@ -1,53 +1,51 @@
using System;
using MatterHackers.Agg;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
namespace MatterHackers.MatterControl
{
public class ToggleSwitchFactory
{
public RGBA_Bytes defaultBackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
public RGBA_Bytes defaultInteriorColor = new RGBA_Bytes (220, 220, 220);
public RGBA_Bytes defaultThumbColor = ActiveTheme.Instance.PrimaryAccentColor;
public RGBA_Bytes defaultExteriorColor = ActiveTheme.Instance.PrimaryTextColor;
public RGBA_Bytes defaultInteriorColor = new RGBA_Bytes(220, 220, 220);
public RGBA_Bytes defaultThumbColor = ActiveTheme.Instance.PrimaryAccentColor;
public RGBA_Bytes defaultExteriorColor = ActiveTheme.Instance.PrimaryTextColor;
public double defaultSwitchHeight = 24;
public double defaultSwitchWidth = 60;
public double defaultSwitchWidth = 60;
public const string defaultTrueText = "On";
public const string defaultTrueText = "On";
public const string defaultFalseText = "Off";
public ToggleSwitchFactory ()
public ToggleSwitchFactory()
{
}
public ToggleSwitch Generate(bool value = false)
{
ToggleSwitch toggleSwitch = new ToggleSwitch (defaultSwitchWidth, defaultSwitchHeight,value,defaultBackgroundColor,defaultInteriorColor,defaultThumbColor,defaultExteriorColor);
ToggleSwitch toggleSwitch = new ToggleSwitch(defaultSwitchWidth, defaultSwitchHeight, value, defaultBackgroundColor, defaultInteriorColor, defaultThumbColor, defaultExteriorColor);
return toggleSwitch;
}
public ToggleSwitch GenerateGivenTextWidget(TextWidget assocTextWidget, string trueText = defaultTrueText, string falseText = defaultFalseText, bool value = false)
{
ToggleSwitch toggleSwitch = new ToggleSwitch (assocTextWidget, trueText, falseText, defaultSwitchWidth, defaultSwitchHeight,value,defaultBackgroundColor,defaultInteriorColor,defaultThumbColor,defaultExteriorColor);
ToggleSwitch toggleSwitch = new ToggleSwitch(assocTextWidget, trueText, falseText, defaultSwitchWidth, defaultSwitchHeight, value, defaultBackgroundColor, defaultInteriorColor, defaultThumbColor, defaultExteriorColor);
return toggleSwitch;
}
public FlowLayoutWidget GenerateToggleSwitchAndTextWidget(string trueText = defaultTrueText, string falseText = defaultFalseText,bool value = false)
public FlowLayoutWidget GenerateToggleSwitchAndTextWidget(string trueText = defaultTrueText, string falseText = defaultFalseText, bool value = false)
{
FlowLayoutWidget leftToRight = new FlowLayoutWidget();
// leftToRight.Padding = new BorderDouble(3, 0, 0, 5) * TextWidget.GlobalPointSizeScaleRatio;
// leftToRight.Padding = new BorderDouble(3, 0, 0, 5) * TextWidget.GlobalPointSizeScaleRatio;
TextWidget textWidget = new TextWidget (defaultFalseText, pointSize: 10, textColor: ActiveTheme.Instance.PrimaryTextColor);
TextWidget textWidget = new TextWidget(defaultFalseText, pointSize: 10, textColor: ActiveTheme.Instance.PrimaryTextColor);
textWidget.VAnchor = VAnchor.ParentCenter;
ToggleSwitch toggleSwitch = new ToggleSwitch(textWidget, trueText, falseText, defaultSwitchWidth, defaultSwitchHeight,value,defaultBackgroundColor,defaultInteriorColor,defaultThumbColor,defaultExteriorColor);
ToggleSwitch toggleSwitch = new ToggleSwitch(textWidget, trueText, falseText, defaultSwitchWidth, defaultSwitchHeight, value, defaultBackgroundColor, defaultInteriorColor, defaultThumbColor, defaultExteriorColor);
toggleSwitch.VAnchor = VAnchor.ParentCenter;
setToggleSwitchColors (toggleSwitch);
setToggleSwitchColors(toggleSwitch);
leftToRight.AddChild (toggleSwitch);
leftToRight.AddChild (textWidget);
leftToRight.AddChild(toggleSwitch);
leftToRight.AddChild(textWidget);
return leftToRight;
}
@ -60,5 +58,4 @@ namespace MatterHackers.MatterControl
toggleSwitch.ExteriorColor = defaultExteriorColor;
}
}
}
}