Commit of the code
This commit is contained in:
parent
33cee93974
commit
f4c1b0b85c
356 changed files with 175795 additions and 0 deletions
67
ControlElements/ImageButtonFactory.cs
Normal file
67
ControlElements/ImageButtonFactory.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Agg.OpenGlGui;
|
||||
using MatterHackers.PolygonMesh;
|
||||
using MatterHackers.RenderOpenGl;
|
||||
using MatterHackers.VectorMath;
|
||||
using MatterHackers.Agg.VertexSource;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public class ImageButtonFactory
|
||||
{
|
||||
public Button Generate(string normalImageName, string hoverImageName, string pressedImageName = null, string disabledImageName = null)
|
||||
{
|
||||
|
||||
if (pressedImageName == null)
|
||||
{
|
||||
pressedImageName = hoverImageName;
|
||||
}
|
||||
|
||||
if (disabledImageName == null)
|
||||
{
|
||||
disabledImageName = normalImageName;
|
||||
}
|
||||
|
||||
Agg.Image.ImageBuffer normalImage = new Agg.Image.ImageBuffer();
|
||||
Agg.Image.ImageBuffer pressedImage = new Agg.Image.ImageBuffer();
|
||||
Agg.Image.ImageBuffer hoverImage = new Agg.Image.ImageBuffer();
|
||||
Agg.Image.ImageBuffer disabledImage = new Agg.Image.ImageBuffer();
|
||||
|
||||
ImageBMPIO.LoadImageData(this.GetImageLocation(normalImageName), normalImage);
|
||||
ImageBMPIO.LoadImageData(this.GetImageLocation(pressedImageName), pressedImage);
|
||||
ImageBMPIO.LoadImageData(this.GetImageLocation(hoverImageName), hoverImage);
|
||||
ImageBMPIO.LoadImageData(this.GetImageLocation(disabledImageName), disabledImage);
|
||||
|
||||
//normalImage.NewGraphics2D().Line(0, 0, normalImage.Width, normalImage.Height, RGBA_Bytes.Violet);
|
||||
//pressedImage.NewGraphics2D().Line(0, 0, normalImage.Width, normalImage.Height, RGBA_Bytes.Violet);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
private string GetImageLocation(string imageName)
|
||||
{
|
||||
return Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, imageName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
160
ControlElements/LinkButtonFactory.cs
Normal file
160
ControlElements/LinkButtonFactory.cs
Normal file
|
|
@ -0,0 +1,160 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Agg.OpenGlGui;
|
||||
using MatterHackers.PolygonMesh;
|
||||
using MatterHackers.RenderOpenGl;
|
||||
using MatterHackers.VectorMath;
|
||||
using MatterHackers.Agg.VertexSource;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public class ChangeTextColorEventArgs : EventArgs
|
||||
{
|
||||
public RGBA_Bytes color;
|
||||
public ChangeTextColorEventArgs(RGBA_Bytes color)
|
||||
{
|
||||
this.color = 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 RGBA_Bytes TextColor { get; set; }
|
||||
TextWidget buttonText;
|
||||
|
||||
public LinkButtonViewBase(string label,
|
||||
double textHeight,
|
||||
double padding,
|
||||
RGBA_Bytes textColor,
|
||||
bool isUnderlined = false)
|
||||
: base()
|
||||
{
|
||||
this.padding = padding;
|
||||
this.TextColor = textColor;
|
||||
this.isUnderlined = isUnderlined;
|
||||
|
||||
buttonText = new TextWidget(label,pointSize:textHeight);
|
||||
buttonText.VAnchor = VAnchor.ParentCenter;
|
||||
buttonText.HAnchor = HAnchor.ParentCenter;
|
||||
buttonText.TextColor = this.TextColor;
|
||||
|
||||
//this.AnchorAll();
|
||||
this.AddChild(buttonText);
|
||||
HAnchor = HAnchor.FitToChildren;
|
||||
VAnchor = VAnchor.FitToChildren;
|
||||
}
|
||||
|
||||
public override void SendToChildren(EventArgs eventToRout)
|
||||
{
|
||||
ChangeTextColorEventArgs changeColorEvent = eventToRout as ChangeTextColorEventArgs;
|
||||
if (changeColorEvent != null)
|
||||
{
|
||||
buttonText.TextColor = changeColorEvent.color;
|
||||
}
|
||||
base.SendToChildren(eventToRout);
|
||||
}
|
||||
|
||||
public override void OnDraw(Agg.Graphics2D graphics2D)
|
||||
{
|
||||
RectangleDouble Bounds = LocalBounds;
|
||||
RoundedRect rectBorder = new RoundedRect(Bounds, this.borderRadius);
|
||||
|
||||
graphics2D.Render(rectBorder, borderColor);
|
||||
|
||||
RectangleDouble insideBounds = Bounds;
|
||||
insideBounds.Inflate(-this.borderWidth);
|
||||
RoundedRect rectInside = new RoundedRect(insideBounds, Math.Max(this.borderRadius - this.borderWidth, 0));
|
||||
|
||||
graphics2D.Render(rectInside, this.fillColor);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
//Create container for the three state widgets for the button
|
||||
ButtonViewStates buttonViewWidget = new ButtonViewStates(buttonWidgetNormal, buttonWidgetHover, buttonWidgetPressed, buttonWidgetDisabled);
|
||||
|
||||
//Create button based on view container widget
|
||||
Button controlButton = new Button(0, 0, buttonViewWidget);
|
||||
controlButton.Margin = margin;
|
||||
controlButton.Cursor = Cursors.Hand;
|
||||
|
||||
return controlButton;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
187
ControlElements/MHTextEditWidget.cs
Normal file
187
ControlElements/MHTextEditWidget.cs
Normal file
|
|
@ -0,0 +1,187 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Agg.OpenGlGui;
|
||||
using MatterHackers.PolygonMesh;
|
||||
using MatterHackers.RenderOpenGl;
|
||||
using MatterHackers.VectorMath;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public class MHTextEditWidget : GuiWidget
|
||||
{
|
||||
Stopwatch timeSinceLastTextChanged = new Stopwatch();
|
||||
TextEditWidget actuallTextEditWidget;
|
||||
TextWidget noContentFieldDescription = null;
|
||||
public TextEditWidget ActualTextEditWidget
|
||||
{
|
||||
get { return actuallTextEditWidget; }
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
actuallTextEditWidget.TextChanged += new EventHandler(internalTextEditWidget_TextChanged);
|
||||
actuallTextEditWidget.InternalTextEditWidget.EditComplete += new EventHandler(InternalTextEditWidget_EditComplete);
|
||||
|
||||
noContentFieldDescription = new TextWidget(messageWhenEmptyAndNotSelected, textColor: RGBA_Bytes.Gray);
|
||||
noContentFieldDescription.VAnchor = VAnchor.ParentBottom;
|
||||
noContentFieldDescription.AutoExpandBoundsToText = true;
|
||||
AddChild(noContentFieldDescription);
|
||||
SetNoContentFieldDescriptionVisibility();
|
||||
|
||||
UiThread.RunOnIdle(OnIdle);
|
||||
}
|
||||
|
||||
private void SetNoContentFieldDescriptionVisibility()
|
||||
{
|
||||
if(noContentFieldDescription != null)
|
||||
{
|
||||
if (Text == "" && !ContainsFocus)
|
||||
{
|
||||
noContentFieldDescription.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
noContentFieldDescription.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void InternalTextEditWidget_EditComplete(object sender, EventArgs e)
|
||||
{
|
||||
timeSinceLastTextChanged.Stop();
|
||||
}
|
||||
|
||||
public void OnIdle(object state)
|
||||
{
|
||||
if (timeSinceLastTextChanged.IsRunning && timeSinceLastTextChanged.Elapsed.Seconds > 2)
|
||||
{
|
||||
if (actuallTextEditWidget.InternalTextEditWidget.TextHasChanged())
|
||||
{
|
||||
actuallTextEditWidget.InternalTextEditWidget.OnEditComplete();
|
||||
}
|
||||
timeSinceLastTextChanged.Stop();
|
||||
}
|
||||
|
||||
UiThread.RunOnIdle(OnIdle);
|
||||
}
|
||||
|
||||
void internalTextEditWidget_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
timeSinceLastTextChanged.Restart();
|
||||
}
|
||||
|
||||
public override void OnDraw(Graphics2D graphics2D)
|
||||
{
|
||||
SetNoContentFieldDescriptionVisibility();
|
||||
base.OnDraw(graphics2D);
|
||||
|
||||
if (ContainsFocus)
|
||||
{
|
||||
graphics2D.Rectangle(LocalBounds, RGBA_Bytes.Orange);
|
||||
}
|
||||
}
|
||||
|
||||
public override string Text
|
||||
{
|
||||
get
|
||||
{
|
||||
return actuallTextEditWidget.Text;
|
||||
}
|
||||
set
|
||||
{
|
||||
actuallTextEditWidget.Text = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MHNumberEdit : GuiWidget
|
||||
{
|
||||
Stopwatch timeSinceLastTextChanged = new Stopwatch();
|
||||
NumberEdit actuallNumberEdit;
|
||||
public NumberEdit ActuallNumberEdit
|
||||
{
|
||||
get { return 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;
|
||||
|
||||
actuallNumberEdit.TextChanged += new EventHandler(internalNumberEdit_TextChanged);
|
||||
actuallNumberEdit.InternalTextEditWidget.EditComplete += new EventHandler(InternalTextEditWidget_EditComplete);
|
||||
|
||||
UiThread.RunOnIdle(OnIdle);
|
||||
}
|
||||
|
||||
void InternalTextEditWidget_EditComplete(object sender, EventArgs e)
|
||||
{
|
||||
timeSinceLastTextChanged.Stop();
|
||||
}
|
||||
|
||||
|
||||
public void OnIdle(object state)
|
||||
{
|
||||
if (timeSinceLastTextChanged.IsRunning && timeSinceLastTextChanged.Elapsed.Seconds > 2)
|
||||
{
|
||||
actuallNumberEdit.InternalNumberEdit.OnEditComplete();
|
||||
timeSinceLastTextChanged.Stop();
|
||||
}
|
||||
|
||||
UiThread.RunOnIdle(OnIdle);
|
||||
}
|
||||
|
||||
void internalNumberEdit_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
timeSinceLastTextChanged.Restart();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
131
ControlElements/StyledMessageBoxWindow.cs
Normal file
131
ControlElements/StyledMessageBoxWindow.cs
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
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.Font;
|
||||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public class StyledMessageBox : SystemWindow
|
||||
{
|
||||
public EventHandler ClickedOk;
|
||||
TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
|
||||
|
||||
public enum MessageType { OK, YES_NO };
|
||||
|
||||
public static bool ShowMessageBox(String message, string caption, MessageType messageType = MessageType.OK)
|
||||
{
|
||||
string wrappedMessage = TypeFacePrinter.InsertCRs(message, 350, 12);
|
||||
StyledMessageBox messageBox = new StyledMessageBox(wrappedMessage, caption, messageType, null, 400, 300);
|
||||
bool okClicked = false;
|
||||
messageBox.ClickedOk += (sender, e) => { okClicked = true; };
|
||||
messageBox.ShowAsSystemWindow();
|
||||
return okClicked;
|
||||
}
|
||||
|
||||
public static bool ShowMessageBox(string message, string caption, GuiWidget[] extraWidgetsToAdd, MessageType messageType)
|
||||
{
|
||||
string wrappedMessage = TypeFacePrinter.InsertCRs(message, 300, 12);
|
||||
StyledMessageBox messageBox = new StyledMessageBox(wrappedMessage, caption, messageType, extraWidgetsToAdd, 400, 300);
|
||||
bool okClicked = false;
|
||||
messageBox.ClickedOk += (sender, e) => { okClicked = true; };
|
||||
messageBox.ShowAsSystemWindow();
|
||||
return okClicked;
|
||||
}
|
||||
|
||||
public StyledMessageBox(String message, string windowTitle, MessageType messageType, GuiWidget[] extraWidgetsToAdd, double width, double height)
|
||||
: base(width, height)
|
||||
{
|
||||
BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
|
||||
|
||||
textImageButtonFactory.FixedWidth = 50;
|
||||
|
||||
FlowLayoutWidget topToBottomFlow = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
||||
//topToBottomFlow.DebugShowBounds = true;
|
||||
TextWidget messageContainer = new TextWidget(message, textColor: ActiveTheme.Instance.PrimaryTextColor);
|
||||
messageContainer.HAnchor = Agg.UI.HAnchor.ParentCenter;
|
||||
topToBottomFlow.AddChild(messageContainer);
|
||||
|
||||
if (extraWidgetsToAdd != null)
|
||||
{
|
||||
foreach (GuiWidget widget in extraWidgetsToAdd)
|
||||
{
|
||||
topToBottomFlow.AddChild(widget);
|
||||
}
|
||||
}
|
||||
|
||||
Title = windowTitle;
|
||||
|
||||
// add a spacer
|
||||
GuiWidget spacer = new GuiWidget(10, 10);
|
||||
spacer.HAnchor |= Agg.UI.HAnchor.ParentCenter;
|
||||
//spacer.DebugShowBounds = true;
|
||||
topToBottomFlow.AddChild(spacer);
|
||||
topToBottomFlow.HAnchor = Agg.UI.HAnchor.ParentCenter | Agg.UI.HAnchor.FitToChildren;
|
||||
topToBottomFlow.VAnchor = Agg.UI.VAnchor.ParentCenter | Agg.UI.VAnchor.FitToChildren;
|
||||
|
||||
switch (messageType)
|
||||
{
|
||||
case MessageType.YES_NO:
|
||||
{
|
||||
FlowLayoutWidget yesNoButtonsFlow = new FlowLayoutWidget();
|
||||
yesNoButtonsFlow.HAnchor |= HAnchor.ParentCenter;
|
||||
|
||||
Button yesButton = textImageButtonFactory.Generate("Yes", centerText:true);
|
||||
yesButton.Click += new ButtonBase.ButtonEventHandler(okButton_Click);
|
||||
yesNoButtonsFlow.AddChild(yesButton);
|
||||
|
||||
GuiWidget buttonSpacer = new GuiWidget(10, 10);
|
||||
yesNoButtonsFlow.AddChild(buttonSpacer);
|
||||
|
||||
Button noButton = textImageButtonFactory.Generate("No", centerText: true);
|
||||
noButton.Click += new ButtonBase.ButtonEventHandler(noButton_Click);
|
||||
yesNoButtonsFlow.AddChild(noButton);
|
||||
|
||||
topToBottomFlow.AddChild(yesNoButtonsFlow);
|
||||
}
|
||||
break;
|
||||
|
||||
case MessageType.OK:
|
||||
{
|
||||
Button okButton = textImageButtonFactory.Generate("Ok", centerText: true);
|
||||
//okButton.DebugShowBounds = true;
|
||||
okButton.Click += new ButtonBase.ButtonEventHandler(okButton_Click);
|
||||
okButton.HAnchor = HAnchor.ParentCenter;
|
||||
topToBottomFlow.AddChild(okButton);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
AddChild(topToBottomFlow);
|
||||
|
||||
IsModal = true;
|
||||
}
|
||||
|
||||
void noButton_Click(object sender, MouseEventArgs mouseEvent)
|
||||
{
|
||||
UiThread.RunOnIdle(CloseOnIdle);
|
||||
}
|
||||
|
||||
void okButton_Click(object sender, MouseEventArgs mouseEvent)
|
||||
{
|
||||
if (ClickedOk != null)
|
||||
{
|
||||
ClickedOk(this, null);
|
||||
}
|
||||
UiThread.RunOnIdle(CloseOnIdle);
|
||||
}
|
||||
|
||||
void CloseOnIdle(object state)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
390
ControlElements/TextImageButtonFactory.cs
Normal file
390
ControlElements/TextImageButtonFactory.cs
Normal file
|
|
@ -0,0 +1,390 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.Image;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Agg.OpenGlGui;
|
||||
using MatterHackers.PolygonMesh;
|
||||
using MatterHackers.RenderOpenGl;
|
||||
using MatterHackers.VectorMath;
|
||||
using MatterHackers.Agg.VertexSource;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
|
||||
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(0, 0, 0, 0);
|
||||
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)
|
||||
: 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;
|
||||
|
||||
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 (image != null)
|
||||
{
|
||||
imageWidget = new ImageWidget(image);
|
||||
imageWidget.VAnchor = VAnchor.ParentCenter;
|
||||
container.AddChild(imageWidget);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static NamedExecutionTimer drawTimer = new NamedExecutionTimer("TextImgBtnFctry");
|
||||
public override void OnDraw(Graphics2D graphics2D)
|
||||
{
|
||||
drawTimer.Start();
|
||||
if (borderColor.Alpha0To255 > 0)
|
||||
{
|
||||
RectangleDouble boarderRectangle = LocalBounds;
|
||||
boarderRectangle.Inflate(-borderWidth / 2);
|
||||
RoundedRect rectBorder = new RoundedRect(boarderRectangle, this.borderRadius);
|
||||
|
||||
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));
|
||||
|
||||
graphics2D.Render(rectInside, this.fillColor);
|
||||
}
|
||||
|
||||
base.OnDraw(graphics2D);
|
||||
drawTimer.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
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 normalTextColor = RGBA_Bytes.White;
|
||||
public RGBA_Bytes hoverTextColor = RGBA_Bytes.White;
|
||||
public RGBA_Bytes pressedTextColor = RGBA_Bytes.White;
|
||||
public RGBA_Bytes disabledTextColor = RGBA_Bytes.White;
|
||||
public int fontSize = 12;
|
||||
public double borderWidth = 1;
|
||||
public bool invertImageLocation = false;
|
||||
FlowDirection flowDirection;
|
||||
public int FixedWidth = 0;
|
||||
public int FixedHeight = 40;
|
||||
|
||||
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);
|
||||
|
||||
|
||||
//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;
|
||||
|
||||
textImageButton.MouseEnterBounds += new EventHandler(onEnterTooltipButton);
|
||||
textImageButton.MouseLeaveBounds += new EventHandler(onExitTooltipButton);
|
||||
return textImageButton;
|
||||
}
|
||||
|
||||
ImageBuffer LoadUpButtonImage(string imageName)
|
||||
{
|
||||
string path = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, imageName);
|
||||
ImageBuffer buffer = new ImageBuffer(10, 10, 32, new BlenderBGRA());
|
||||
ImageBMPIO.LoadImageData(path, buffer);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public GuiWidget GenerateGroupBoxLableWithEdit(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.ParentTop;
|
||||
TextWidget textLabel = new TextWidget(label, textColor: RGBA_Bytes.White);
|
||||
textLabel.VAnchor = Agg.UI.VAnchor.ParentTop;
|
||||
groupLableAndEditControl.AddChild(textLabel);
|
||||
groupLableAndEditControl.AddChild(editButton);
|
||||
|
||||
return groupLableAndEditControl;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public CheckBox GenerateCheckBoxButton(string label, string normalImageName = null, string normalToPressedImageName = null, string pressedImageName = null, string pressedToNormalImageName = null)
|
||||
{
|
||||
CheckBoxViewStates checkBoxButtonViewWidget = getCheckBoxButtonView(label, normalImageName, normalToPressedImageName, pressedImageName, pressedToNormalImageName);
|
||||
|
||||
//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);
|
||||
|
||||
return textImageCheckBoxButton;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
//Override the width if requested
|
||||
if (this.FixedWidth != 0)
|
||||
{
|
||||
buttonViewWidget.Width = this.FixedWidth;
|
||||
textImageButton.Width = this.FixedWidth;
|
||||
}
|
||||
return textImageButton;
|
||||
}
|
||||
|
||||
private string GetImageLocation(string imageName)
|
||||
{
|
||||
return Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, imageName);
|
||||
}
|
||||
|
||||
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 (disabledImageName == null)
|
||||
{
|
||||
disabledImageName = normalImageName;
|
||||
}
|
||||
|
||||
ImageBuffer normalImage = new ImageBuffer();
|
||||
ImageBuffer pressedImage = new ImageBuffer();
|
||||
ImageBuffer hoverImage = new ImageBuffer();
|
||||
ImageBuffer disabledImage = new ImageBuffer();
|
||||
|
||||
if (normalImageName != null)
|
||||
{
|
||||
ImageBMPIO.LoadImageData(this.GetImageLocation(normalImageName), normalImage);
|
||||
}
|
||||
|
||||
if (hoverImageName != null)
|
||||
{
|
||||
ImageBMPIO.LoadImageData(this.GetImageLocation(pressedImageName), pressedImage);
|
||||
}
|
||||
|
||||
if (pressedImageName != null)
|
||||
{
|
||||
ImageBMPIO.LoadImageData(this.GetImageLocation(hoverImageName), hoverImage);
|
||||
}
|
||||
|
||||
if (disabledImageName != null)
|
||||
{
|
||||
ImageBMPIO.LoadImageData(this.GetImageLocation(disabledImageName), disabledImage);
|
||||
}
|
||||
|
||||
if (invertImageLocation)
|
||||
{
|
||||
flowDirection = FlowDirection.RightToLeft;
|
||||
}
|
||||
else
|
||||
{
|
||||
flowDirection = FlowDirection.LeftToRight;
|
||||
}
|
||||
|
||||
//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),
|
||||
new TextImageWidget(label, hoverFillColor, hoverBorderColor, hoverTextColor, borderWidth, Margin, hoverImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, centerText: centerText),
|
||||
new TextImageWidget(label, pressedFillColor, pressedBorderColor, pressedTextColor, borderWidth, Margin, pressedImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, centerText: centerText),
|
||||
new TextImageWidget(label, disabledFillColor, disabledBorderColor, disabledTextColor, borderWidth, Margin, disabledImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, centerText: centerText)
|
||||
);
|
||||
return buttonViewWidget;
|
||||
}
|
||||
|
||||
private CheckBoxViewStates getCheckBoxButtonView(string label, string normalImageName = null, string normalToPressedImageName = null, string pressedImageName = null, string pressedToNormalImageName = null)
|
||||
{
|
||||
ImageBuffer normalImage = new ImageBuffer();
|
||||
ImageBuffer pressedImage = new ImageBuffer();
|
||||
ImageBuffer normalToPressedImage = new ImageBuffer();
|
||||
ImageBuffer pressedToNormalImage = new ImageBuffer();
|
||||
|
||||
if (normalImageName != null)
|
||||
{
|
||||
ImageBMPIO.LoadImageData(this.GetImageLocation(normalImageName), normalImage);
|
||||
}
|
||||
|
||||
if (pressedImageName != null)
|
||||
{
|
||||
ImageBMPIO.LoadImageData(this.GetImageLocation(pressedImageName), pressedImage);
|
||||
}
|
||||
|
||||
if (normalToPressedImageName != null)
|
||||
{
|
||||
ImageBMPIO.LoadImageData(this.GetImageLocation(normalToPressedImageName), normalToPressedImage);
|
||||
}
|
||||
|
||||
if (pressedToNormalImageName != null)
|
||||
{
|
||||
ImageBMPIO.LoadImageData(this.GetImageLocation(pressedToNormalImageName), pressedToNormalImage);
|
||||
}
|
||||
|
||||
if (normalToPressedImageName == null)
|
||||
{
|
||||
normalToPressedImage = pressedImage;
|
||||
}
|
||||
|
||||
if (pressedImageName == null)
|
||||
{
|
||||
pressedImage = normalToPressedImage;
|
||||
}
|
||||
|
||||
if (pressedToNormalImageName == null)
|
||||
{
|
||||
pressedToNormalImage = normalImage;
|
||||
}
|
||||
|
||||
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(label, 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;
|
||||
}
|
||||
|
||||
public RadioButton GenerateRadioButton(string label, string iconImageName = null)
|
||||
{
|
||||
ImageBuffer iconImage = null;
|
||||
|
||||
if (iconImageName != null)
|
||||
{
|
||||
iconImage = new ImageBuffer();
|
||||
ImageBMPIO.LoadImageData(this.GetImageLocation(iconImageName), 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, RGBA_Bytes.White, hoverTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
|
||||
TextImageWidget checkedState = new TextImageWidget(label, pressedFillColor, RGBA_Bytes.White, 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 TooltipButton(double x, double y, GuiWidget buttonView)
|
||||
:base(x, y, buttonView)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
237
ControlElements/ThemeFactory.cs
Normal file
237
ControlElements/ThemeFactory.cs
Normal file
|
|
@ -0,0 +1,237 @@
|
|||
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.PrintQueue;
|
||||
using MatterHackers.MatterControl.DataStorage;
|
||||
|
||||
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 RootedObjectEventHandler ThemeChanged = new RootedObjectEventHandler();
|
||||
|
||||
public List<Theme> AvailableThemes
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.availableThemes == null)
|
||||
{
|
||||
this.availableThemes = getAvailableThemes();
|
||||
}
|
||||
return availableThemes;
|
||||
}
|
||||
}
|
||||
|
||||
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 TabLabelSelected
|
||||
{
|
||||
get
|
||||
{
|
||||
return loadedTheme.tabLabelSelectedColor;
|
||||
}
|
||||
}
|
||||
|
||||
public RGBA_Bytes TabLabelUnselected
|
||||
{
|
||||
get
|
||||
{
|
||||
return loadedTheme.tabLabelUnselectedColor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public RGBA_Bytes PrimaryBackgroundColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return loadedTheme.primaryBackgroundColor;
|
||||
}
|
||||
}
|
||||
|
||||
public RGBA_Bytes SecondaryBackgroundColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return loadedTheme.secondaryBackgroundColor;
|
||||
}
|
||||
}
|
||||
|
||||
public RGBA_Bytes PrimaryTextColor
|
||||
{
|
||||
get
|
||||
{
|
||||
return loadedTheme.primaryTextColor;
|
||||
}
|
||||
}
|
||||
|
||||
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 ActiveTheme()
|
||||
{
|
||||
//Load the default theme by index
|
||||
if (UserSettings.Instance.get("ActiveThemeIndex") == null)
|
||||
{
|
||||
UserSettings.Instance.set("ActiveThemeIndex", defaultThemeIndex.ToString());
|
||||
}
|
||||
|
||||
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 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>();
|
||||
themeList.Add(new Theme("Blue", new RGBA_Bytes(0, 75, 139), new RGBA_Bytes(0, 103, 190)));
|
||||
|
||||
themeList.Add(new Theme("Teal", new RGBA_Bytes(0, 130, 153), new RGBA_Bytes(0, 173, 204)));
|
||||
|
||||
themeList.Add(new Theme("Green", new RGBA_Bytes(0, 138, 23), new RGBA_Bytes(0, 189, 32)));
|
||||
themeList.Add(new Theme("Light Blue", new RGBA_Bytes(93, 178, 255), new RGBA_Bytes(144, 202, 255)));
|
||||
themeList.Add(new Theme("Orange", new RGBA_Bytes(255, 129, 25), new RGBA_Bytes(255, 157, 76)));
|
||||
themeList.Add(new Theme("Purple", new RGBA_Bytes(70, 23, 180), new RGBA_Bytes(104, 51, 229)));
|
||||
themeList.Add(new Theme("Red", new RGBA_Bytes(172, 25, 61), new RGBA_Bytes(217, 31, 77)));
|
||||
themeList.Add(new Theme("Pink", new RGBA_Bytes(220, 79, 173), new RGBA_Bytes(233, 143, 203)));
|
||||
themeList.Add(new Theme("Grey", new RGBA_Bytes(88, 88, 88), new RGBA_Bytes(114, 114, 114)));
|
||||
themeList.Add(new Theme("Pink", new RGBA_Bytes(140, 0, 149), new RGBA_Bytes(188,0,200)));
|
||||
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 string name;
|
||||
|
||||
public Theme(string name, RGBA_Bytes primary, RGBA_Bytes secondary, bool darkTheme = true)
|
||||
{
|
||||
this.name = name;
|
||||
|
||||
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(200, 200, 200);
|
||||
this.primaryTextColor = new RGBA_Bytes(255, 255, 255);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
this.primaryAccentColor = secondary;
|
||||
this.secondaryAccentColor = primary;
|
||||
|
||||
this.primaryBackgroundColor = new RGBA_Bytes(169, 169, 169);
|
||||
this.secondaryBackgroundColor = new RGBA_Bytes(208, 208, 208);
|
||||
this.tabLabelSelectedColor = new RGBA_Bytes(255, 255, 255);
|
||||
this.tabLabelUnselectedColor = new RGBA_Bytes(200, 200, 200);
|
||||
this.primaryTextColor = new RGBA_Bytes(255, 255, 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue