Revise theme support

This commit is contained in:
John Lewin 2018-10-13 17:58:54 -07:00
parent 7ba684ef8d
commit ee936efb8a
57 changed files with 1562 additions and 458 deletions

View file

@ -1,5 +1,5 @@
/*
Copyright (c) 2017, John Lewin
Copyright (c) 2018, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -28,8 +28,6 @@ either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg;
using MatterHackers.Agg.ImageProcessing;
using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.VectorMath;
@ -38,17 +36,24 @@ namespace MatterHackers.MatterControl.ConfigurationPage
public class ThemePreviewButton : GuiWidget
{
private GuiWidget accentColor;
private Color activeColor;
private GuiWidget secondaryBackground;
private GuiWidget tertiaryBackground;
private GuiWidget icon1;
private GuiWidget icon2;
private GuiWidget icon3;
private string themeName = "";
private ThemeConfig theme;
private ImageWidget activeIcon;
public ThemePreviewButton(IThemeColors theme, bool isActive)
public ThemePreviewButton(ThemeConfig theme, ThemeColorPanel themeColorPanel)
{
this.theme = theme;
activeColor = theme.Colors.SourceColor;
var primaryAccentColor = theme.Colors.PrimaryAccentColor;
this.Padding = 8;
this.BackgroundColor = theme.PrimaryBackgroundColor;
this.BackgroundColor = theme.ActiveTabColor;
this.Cursor = Cursors.Hand;
secondaryBackground = new GuiWidget()
@ -57,7 +62,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage
VAnchor = VAnchor.Stretch,
Margin = new BorderDouble(0),
Width = 20,
BackgroundColor = theme.SecondaryBackgroundColor,
BackgroundColor = theme.MinimalShade,
};
this.AddChild(secondaryBackground);
@ -67,7 +72,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage
VAnchor = VAnchor.Absolute | VAnchor.Top,
Height = 6,
Margin = new BorderDouble(left: 25),
BackgroundColor = theme.PrimaryAccentColor,
BackgroundColor = primaryAccentColor,
};
this.AddChild(accentColor);
@ -78,7 +83,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage
Height = 8,
Width = 8,
Margin = new BorderDouble(left: 6, top: 6),
BackgroundColor = theme.PrimaryAccentColor,
BackgroundColor = primaryAccentColor,
};
this.AddChild(icon1);
@ -89,7 +94,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage
Height = 8,
Width = 8,
Margin = new BorderDouble(left: 6, top: 20),
BackgroundColor = theme.PrimaryAccentColor,
BackgroundColor = primaryAccentColor,
};
this.AddChild(icon2);
@ -100,7 +105,7 @@ namespace MatterHackers.MatterControl.ConfigurationPage
Height = 8,
Width = 8,
Margin = new BorderDouble(left: 6, top: 34),
BackgroundColor = theme.PrimaryAccentColor,
BackgroundColor = primaryAccentColor,
};
this.AddChild(icon3);
@ -110,49 +115,53 @@ namespace MatterHackers.MatterControl.ConfigurationPage
VAnchor = VAnchor.Absolute | VAnchor.Top,
Height = 37,
Margin = new BorderDouble(left: 25, top: 12),
BackgroundColor = theme.TertiaryBackgroundColor,
BackgroundColor = theme.SlightShade,
};
this.AddChild(tertiaryBackground);
if (isActive)
this.AddChild(activeIcon = new ImageWidget(themeColorPanel.CheckMark)
{
this.AddChild(new ImageWidget(AggContext.StaticData.LoadIcon("426.png", 16, 16, invertImage: true))
{
HAnchor = HAnchor.Absolute,
VAnchor = VAnchor.Absolute,
OriginRelativeParent = new Vector2(45, 20)
});
}
HAnchor = HAnchor.Absolute,
VAnchor = VAnchor.Absolute,
OriginRelativeParent = new Vector2(45, 20),
Visible = false
});
var overlay = new GuiWidget();
overlay.AnchorAll();
overlay.Cursor = Cursors.Hand;
var overlay = new GuiWidget
{
VAnchor = VAnchor.Stretch,
HAnchor = HAnchor.Stretch,
Cursor = Cursors.Hand
};
overlay.Click += (s, e) =>
{
ThemeColorSelectorWidget.SetTheme(this.themeName);
UserSettings.Instance.set(UserSettingsKey.ThemeMode, this.Mode);
// Activate the theme
themeColorPanel.SetThemeColor(activeColor, this.Mode);
};
this.AddChild(overlay);
}
public void SetThemeColors(IThemeColors theme)
public bool IsActive
{
accentColor.BackgroundColor = theme.PrimaryAccentColor;
icon1.BackgroundColor = theme.PrimaryAccentColor;
icon2.BackgroundColor = theme.PrimaryAccentColor;
icon3.BackgroundColor = theme.PrimaryAccentColor;
tertiaryBackground.BackgroundColor = theme.TertiaryBackgroundColor;
secondaryBackground.BackgroundColor = theme.SecondaryBackgroundColor;
this.BackgroundColor = theme.PrimaryBackgroundColor;
this.themeName = theme.Name;
get => activeIcon.Visible;
set => activeIcon.Visible = value;
}
public override void OnClick(MouseEventArgs mouseEvent)
public string Mode { get; internal set; }
public void PreviewThemeColor(Color sourceColor)
{
ThemeColorSelectorWidget.SetTheme(this.themeName);
base.OnClick(mouseEvent);
var adjustedAccentColor = sourceColor;
accentColor.BackgroundColor = adjustedAccentColor;
icon1.BackgroundColor = adjustedAccentColor;
icon2.BackgroundColor = adjustedAccentColor;
icon3.BackgroundColor = adjustedAccentColor;
activeColor = adjustedAccentColor;
}
}
}