mattercontrol/PartPreviewWindow/MainTab.cs

127 lines
4 KiB
C#
Raw Normal View History

2017-08-15 12:32:09 -07:00
/*
Copyright (c) 2017, Lars Brubaker, John Lewin
All rights reserved.
Redistribution and use in source and binary forms, with or without
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.
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.
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
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
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,
either expressed or implied, of the FreeBSD Project.
*/
using MatterHackers.Agg;
using MatterHackers.Agg.Image;
2017-08-15 12:32:09 -07:00
using MatterHackers.Agg.UI;
using MatterHackers.Agg.VertexSource;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow
{
2017-10-14 21:28:48 -07:00
public class MainTab : ThreeViewTab
2017-08-15 12:32:09 -07:00
{
private class TabPill : FlowLayoutWidget
{
private TextWidget label;
2017-10-31 11:43:25 -07:00
public TabPill(string tabTitle, Color textColor, string imageUrl = null)
2017-08-17 05:58:59 -07:00
{
var imageWidget = new ImageWidget(new ImageBuffer(16, 16))
{
Margin = new BorderDouble(right: 6),
VAnchor = VAnchor.Center
};
this.AddChild(imageWidget);
label = new TextWidget(tabTitle)
{
TextColor = textColor,
VAnchor = VAnchor.Center
};
this.AddChild(label);
if (!string.IsNullOrEmpty(imageUrl))
{
// Attempt to load image
try
{
// TODO: Must use caching
ApplicationController.Instance.DownloadToImageAsync(imageWidget.Image, imageUrl, false);
}
catch { }
}
}
2017-10-31 11:43:25 -07:00
public Color TextColor
2017-08-17 05:58:59 -07:00
{
get => label.TextColor;
set => label.TextColor = value;
}
public override string Text
2017-08-17 05:58:59 -07:00
{
get => label.Text;
set => label.Text = value;
}
}
public MainTab(string tabTitle, string tabName, TabPage tabPage, string tabImageUrl = null)
: this(
2017-10-31 11:43:25 -07:00
new TabPill(tabTitle, new Color(ActiveTheme.Instance.PrimaryTextColor, 140), tabImageUrl),
new TabPill(tabTitle, ActiveTheme.Instance.PrimaryTextColor, tabImageUrl),
new TabPill(tabTitle, ActiveTheme.Instance.PrimaryTextColor, tabImageUrl),
2017-08-17 05:58:59 -07:00
tabName,
tabPage)
{
}
public MainTab(GuiWidget normalWidget, GuiWidget hoverWidget, GuiWidget pressedWidget, string tabName, TabPage tabPage)
2017-08-15 12:32:09 -07:00
: base(tabName, normalWidget, hoverWidget, pressedWidget, tabPage)
{
this.HAnchor = HAnchor.Fit;
this.VAnchor = VAnchor.Fit | VAnchor.Bottom;
}
public int BorderWidth { get; set; } = 1;
public int borderRadius { get; set; } = 4;
2017-10-14 21:28:48 -07:00
2017-10-31 11:43:25 -07:00
private Color activeTabColor = ApplicationController.Instance.Theme.SlightShade;
private Color inactiveTabColor = ApplicationController.Instance.Theme.PrimaryTabFillColor;
2017-08-15 12:32:09 -07:00
public override void OnDraw(Graphics2D graphics2D)
{
RectangleDouble borderRectangle = LocalBounds;
borderRectangle.ExpandToInclude(new Vector2(0, -15));
if (BorderWidth > 0)
{
var r = new RoundedRect(borderRectangle, this.borderRadius);
r.normalize_radius();
graphics2D.Render(
r,
2017-08-17 10:18:34 -07:00
selectedWidget.Visible ? activeTabColor : inactiveTabColor);
2017-08-15 12:32:09 -07:00
}
base.OnDraw(graphics2D);
}
}
}