2018-11-27 18:15:17 -08:00
|
|
|
|
/*
|
|
|
|
|
|
Copyright (c) 2018, 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.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2018-12-11 20:14:06 -08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2018-11-27 18:15:17 -08:00
|
|
|
|
using MatterHackers.Agg;
|
|
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Agg.VertexSource;
|
2018-12-11 20:14:06 -08:00
|
|
|
|
using MatterHackers.Localizations;
|
2018-11-27 18:15:17 -08:00
|
|
|
|
using MatterHackers.MatterControl;
|
2018-11-28 11:54:18 -08:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
2018-12-11 23:29:23 -08:00
|
|
|
|
using MatterHackers.MatterControl.PartPreviewWindow;
|
2018-11-27 18:15:17 -08:00
|
|
|
|
using MatterHackers.VectorMath;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MatterControlLib.SetupWizard
|
|
|
|
|
|
{
|
|
|
|
|
|
public class TourOverlay : GuiWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
private GuiWidget targetWidget;
|
2018-12-12 08:40:52 -08:00
|
|
|
|
private Popover popover;
|
2018-12-13 08:46:20 -08:00
|
|
|
|
private GuiWidget tourWindow;
|
2018-12-28 16:00:21 -08:00
|
|
|
|
private int nextLocationIndex;
|
2018-11-27 18:15:17 -08:00
|
|
|
|
|
2018-12-11 20:14:06 -08:00
|
|
|
|
private string description;
|
2018-11-28 11:54:18 -08:00
|
|
|
|
private ThemeConfig theme;
|
|
|
|
|
|
|
2018-12-28 16:00:21 -08:00
|
|
|
|
public TourOverlay(GuiWidget tourWindow, GuiWidget targetWidget, string description, ThemeConfig theme, int nextLocationIndex)
|
2018-11-27 18:15:17 -08:00
|
|
|
|
{
|
2018-12-13 08:46:20 -08:00
|
|
|
|
this.tourWindow = tourWindow;
|
2018-12-28 16:00:21 -08:00
|
|
|
|
this.nextLocationIndex = nextLocationIndex;
|
2018-11-28 11:54:18 -08:00
|
|
|
|
this.theme = theme;
|
2018-11-27 18:15:17 -08:00
|
|
|
|
this.targetWidget = targetWidget;
|
2018-12-11 20:14:06 -08:00
|
|
|
|
this.description = description;
|
2018-11-27 18:15:17 -08:00
|
|
|
|
|
2018-12-11 20:14:06 -08:00
|
|
|
|
this.HAnchor = HAnchor.Stretch;
|
|
|
|
|
|
this.VAnchor = VAnchor.Stretch;
|
2018-11-27 18:15:17 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnLoad(EventArgs args)
|
|
|
|
|
|
{
|
2018-12-12 08:40:52 -08:00
|
|
|
|
var column = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
2018-11-27 18:15:17 -08:00
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Absolute,
|
2018-11-28 11:54:18 -08:00
|
|
|
|
VAnchor = VAnchor.Fit,
|
2018-11-27 18:15:17 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
2018-12-12 08:40:52 -08:00
|
|
|
|
column.AddChild(new WrappedTextWidget(description, textColor: theme.TextColor, pointSize: theme.DefaultFontSize)
|
2018-11-28 11:54:18 -08:00
|
|
|
|
{
|
2018-12-12 08:40:52 -08:00
|
|
|
|
Margin = 5,
|
|
|
|
|
|
HAnchor = HAnchor.Stretch
|
2018-11-28 11:54:18 -08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
var buttonRow = new FlowLayoutWidget()
|
2018-11-27 18:15:17 -08:00
|
|
|
|
{
|
2018-11-28 11:54:18 -08:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
Margin = new BorderDouble(0, 0, 0, 5)
|
2018-11-27 18:15:17 -08:00
|
|
|
|
};
|
2018-12-13 09:02:31 -08:00
|
|
|
|
column.AddChild(buttonRow);
|
|
|
|
|
|
|
2018-11-28 11:54:18 -08:00
|
|
|
|
buttonRow.AddChild(new HorizontalSpacer());
|
2018-11-27 18:15:17 -08:00
|
|
|
|
|
2018-12-28 16:00:21 -08:00
|
|
|
|
if (nextLocationIndex > 0)
|
2018-11-28 11:54:18 -08:00
|
|
|
|
{
|
2018-12-11 20:14:06 -08:00
|
|
|
|
var nextButton = theme.CreateDialogButton("Next".Localize());
|
2018-11-28 11:54:18 -08:00
|
|
|
|
nextButton.Click += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Close();
|
2018-12-28 16:00:21 -08:00
|
|
|
|
ShowLocation(tourWindow, nextLocationIndex);
|
2018-11-28 11:54:18 -08:00
|
|
|
|
};
|
|
|
|
|
|
buttonRow.AddChild(nextButton);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-11 20:14:06 -08:00
|
|
|
|
var cancelButton = theme.CreateDialogButton("Done".Localize());
|
2018-11-28 11:54:18 -08:00
|
|
|
|
cancelButton.Click += (s, e) => this.Close();
|
|
|
|
|
|
buttonRow.AddChild(cancelButton);
|
|
|
|
|
|
|
2018-12-12 14:26:55 -08:00
|
|
|
|
column.Size = new Vector2(250, column.Height);
|
|
|
|
|
|
|
|
|
|
|
|
popover = this.GetPopover(column);
|
|
|
|
|
|
popover.AddChild(column);
|
|
|
|
|
|
this.AddChild(popover);
|
|
|
|
|
|
|
|
|
|
|
|
this.Focus();
|
|
|
|
|
|
|
|
|
|
|
|
base.OnLoad(args);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Popover GetPopover(FlowLayoutWidget content)
|
|
|
|
|
|
{
|
|
|
|
|
|
int notchSize = 8;
|
|
|
|
|
|
var padding = new BorderDouble(theme.DefaultContainerPadding);
|
|
|
|
|
|
|
|
|
|
|
|
// Temporarily add the popover padding to the child content
|
|
|
|
|
|
content.Padding = padding;
|
|
|
|
|
|
|
2018-11-28 11:54:18 -08:00
|
|
|
|
// and last, set the size
|
2018-12-11 20:36:58 -08:00
|
|
|
|
var targetBounds = this.GetTargetBounds();
|
2018-12-11 23:29:23 -08:00
|
|
|
|
|
2018-12-12 14:26:55 -08:00
|
|
|
|
Vector2 contentPosition;
|
2018-12-13 08:37:41 -08:00
|
|
|
|
int arrowPosition;
|
2018-12-12 14:26:55 -08:00
|
|
|
|
Popover.ArrowDirection arrow;
|
2018-11-29 09:53:48 -08:00
|
|
|
|
|
2018-12-12 08:40:52 -08:00
|
|
|
|
if (targetBounds.Right >= this.Width - content.Width - 5)
|
2018-11-29 09:53:48 -08:00
|
|
|
|
{
|
2018-12-11 20:36:58 -08:00
|
|
|
|
var left = targetBounds.Right - content.Width;
|
|
|
|
|
|
if (targetBounds.Bottom < this.Height / 2)
|
2018-11-29 09:53:48 -08:00
|
|
|
|
{
|
2018-12-11 20:36:58 -08:00
|
|
|
|
if (targetBounds.Bottom - content.Size.Y < 0)
|
2018-11-29 09:53:48 -08:00
|
|
|
|
{
|
2018-12-12 08:40:52 -08:00
|
|
|
|
// position above target, arrow down aligned right center,
|
2018-12-12 22:09:42 -08:00
|
|
|
|
contentPosition = new Vector2(left, targetBounds.Top + 1);
|
2018-12-13 08:37:41 -08:00
|
|
|
|
arrowPosition = (int)(content.LocalBounds.Left + content.LocalBounds.Width - (targetWidget.Width / 2));
|
2018-12-12 14:26:55 -08:00
|
|
|
|
arrow = Popover.ArrowDirection.Bottom;
|
2018-11-29 09:53:48 -08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-12-12 08:40:52 -08:00
|
|
|
|
// position left of target, arrow right aligned top center
|
2018-12-12 22:09:42 -08:00
|
|
|
|
contentPosition = new Vector2(left - 1, targetBounds.Top - content.Size.Y);
|
2018-12-13 08:37:41 -08:00
|
|
|
|
arrowPosition = (int)(content.LocalBounds.Top - (targetWidget.Height / 2));
|
2018-12-12 14:26:55 -08:00
|
|
|
|
arrow = Popover.ArrowDirection.Right;
|
2018-11-29 09:53:48 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-12-12 08:40:52 -08:00
|
|
|
|
// position under target, arrow up aligned right center
|
2018-12-12 22:09:42 -08:00
|
|
|
|
contentPosition = new Vector2(left - content.DevicePadding.Width, targetBounds.Bottom - content.Size.Y - notchSize - 1);
|
2018-12-13 08:37:41 -08:00
|
|
|
|
arrowPosition = (int)(content.LocalBounds.Left + content.LocalBounds.Width + content.DevicePadding.Width - (targetWidget.Width / 2));
|
2018-12-12 14:26:55 -08:00
|
|
|
|
arrow = Popover.ArrowDirection.Top;
|
2018-11-29 09:53:48 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-12-12 08:40:52 -08:00
|
|
|
|
if (targetBounds.Bottom < this.Height / 2)
|
2018-11-29 09:53:48 -08:00
|
|
|
|
{
|
2018-12-12 08:40:52 -08:00
|
|
|
|
// position right of target, arrow left aligned top center (or top 20 if target larger than content)
|
2018-12-12 22:09:42 -08:00
|
|
|
|
contentPosition = new Vector2(targetBounds.Right + 1, targetBounds.Top - content.Size.Y);
|
2018-12-12 08:40:52 -08:00
|
|
|
|
|
|
|
|
|
|
if (targetWidget.Height > content.Height)
|
|
|
|
|
|
{
|
2018-12-13 08:37:41 -08:00
|
|
|
|
arrowPosition = (int)(content.LocalBounds.Top - 20);
|
2018-12-12 08:40:52 -08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2018-12-13 08:37:41 -08:00
|
|
|
|
arrowPosition = (int)(content.LocalBounds.Top - (targetWidget.Height / 2));
|
2018-12-12 08:40:52 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-12 14:26:55 -08:00
|
|
|
|
arrow = Popover.ArrowDirection.Left;
|
2018-11-29 09:53:48 -08:00
|
|
|
|
}
|
2018-12-12 08:40:52 -08:00
|
|
|
|
else
|
2018-11-29 09:53:48 -08:00
|
|
|
|
{
|
2018-12-12 08:40:52 -08:00
|
|
|
|
// position under target, arrow up aligned left center
|
2018-12-12 22:09:42 -08:00
|
|
|
|
contentPosition = new Vector2(targetBounds.Left, targetBounds.Bottom - content.Size.Y - notchSize - 1);
|
2018-12-13 08:37:41 -08:00
|
|
|
|
arrowPosition = (int)(content.LocalBounds.Left + (targetWidget.Width / 2));
|
2018-12-12 14:26:55 -08:00
|
|
|
|
arrow = Popover.ArrowDirection.Top;
|
2018-11-29 09:53:48 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-27 18:15:17 -08:00
|
|
|
|
|
2018-12-12 14:26:55 -08:00
|
|
|
|
// Remove the temporarily padding to the child content
|
|
|
|
|
|
content.Padding = 0;
|
2018-11-27 18:15:17 -08:00
|
|
|
|
|
2018-12-13 08:37:41 -08:00
|
|
|
|
var popover = new Popover(arrow, padding, notchSize, p2: arrowPosition)
|
2018-12-12 14:26:55 -08:00
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Fit,
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
|
|
|
|
|
TagColor = theme.ResolveColor(theme.BackgroundColor, theme.AccentMimimalOverlay.WithAlpha(50)),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
popover.Position = contentPosition;
|
|
|
|
|
|
|
|
|
|
|
|
return popover;
|
2018-11-27 18:15:17 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-28 11:54:18 -08:00
|
|
|
|
public override void OnKeyDown(KeyEventArgs keyEvent)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (keyEvent.KeyCode == Keys.Escape)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Close();
|
|
|
|
|
|
}
|
2018-12-13 08:31:32 -08:00
|
|
|
|
|
2018-11-28 11:54:18 -08:00
|
|
|
|
if (keyEvent.KeyCode == Keys.Enter)
|
|
|
|
|
|
{
|
|
|
|
|
|
var topWindow = this.TopmostParent();
|
|
|
|
|
|
this.Close();
|
2018-12-28 16:00:21 -08:00
|
|
|
|
ShowLocation(topWindow, nextLocationIndex);
|
2018-11-28 11:54:18 -08:00
|
|
|
|
}
|
2018-12-13 08:31:32 -08:00
|
|
|
|
|
2018-11-28 11:54:18 -08:00
|
|
|
|
base.OnKeyDown(keyEvent);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-11-27 18:15:17 -08:00
|
|
|
|
public override void OnDraw(Graphics2D graphics2D)
|
|
|
|
|
|
{
|
|
|
|
|
|
var dimRegion = new VertexStorage();
|
|
|
|
|
|
dimRegion.MoveTo(LocalBounds.Left, LocalBounds.Bottom);
|
|
|
|
|
|
dimRegion.LineTo(LocalBounds.Right, LocalBounds.Bottom);
|
|
|
|
|
|
dimRegion.LineTo(LocalBounds.Right, LocalBounds.Top);
|
|
|
|
|
|
dimRegion.LineTo(LocalBounds.Left, LocalBounds.Top);
|
|
|
|
|
|
|
2018-12-11 20:36:58 -08:00
|
|
|
|
var targetBounds = this.GetTargetBounds();
|
2018-11-27 18:15:17 -08:00
|
|
|
|
|
2018-12-11 20:36:58 -08:00
|
|
|
|
var targetRect = new VertexStorage();
|
|
|
|
|
|
targetRect.MoveTo(targetBounds.Right, targetBounds.Bottom);
|
|
|
|
|
|
targetRect.LineTo(targetBounds.Left, targetBounds.Bottom);
|
|
|
|
|
|
targetRect.LineTo(targetBounds.Left, targetBounds.Top);
|
|
|
|
|
|
targetRect.LineTo(targetBounds.Right, targetBounds.Top);
|
2018-11-27 18:15:17 -08:00
|
|
|
|
|
2018-12-11 20:36:58 -08:00
|
|
|
|
var overlayMinusTargetRect = new CombinePaths(dimRegion, targetRect);
|
|
|
|
|
|
graphics2D.Render(overlayMinusTargetRect, new Color(Color.Black, 180));
|
2018-11-27 18:15:17 -08:00
|
|
|
|
|
|
|
|
|
|
base.OnDraw(graphics2D);
|
|
|
|
|
|
|
2018-12-12 08:53:03 -08:00
|
|
|
|
graphics2D.Render(new Stroke(new RoundedRect(GetTargetBounds(), 0), 2), Color.White.WithAlpha(50));
|
2018-12-11 20:21:31 -08:00
|
|
|
|
//graphics2D.Render(new Stroke(new RoundedRect(GetContentBounds(), 3), 4), theme.PrimaryAccentColor);
|
2018-11-27 18:15:17 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-11 20:36:58 -08:00
|
|
|
|
private RectangleDouble GetTargetBounds()
|
2018-11-27 18:15:17 -08:00
|
|
|
|
{
|
|
|
|
|
|
var childBounds = targetWidget.TransformToScreenSpace(targetWidget.LocalBounds);
|
2018-12-11 20:14:06 -08:00
|
|
|
|
return this.TransformFromScreenSpace(childBounds);
|
2018-11-27 18:15:17 -08:00
|
|
|
|
}
|
2018-11-28 11:54:18 -08:00
|
|
|
|
|
2018-12-28 16:00:21 -08:00
|
|
|
|
public static async void ShowLocation(GuiWidget window, int locationIndex)
|
2018-11-28 11:54:18 -08:00
|
|
|
|
{
|
2018-12-28 16:00:21 -08:00
|
|
|
|
var tourLocations = await ApplicationController.Instance.LoadProductTour();
|
2018-12-13 08:18:15 -08:00
|
|
|
|
|
2018-12-28 16:00:21 -08:00
|
|
|
|
if (locationIndex >= tourLocations.Count)
|
2018-11-28 11:54:18 -08:00
|
|
|
|
{
|
2018-12-28 16:00:21 -08:00
|
|
|
|
locationIndex -= tourLocations.Count;
|
2018-11-28 11:54:18 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 16:00:21 -08:00
|
|
|
|
GuiWidget GetLocationWidget(ref int findLocationIndex)
|
2018-11-28 11:54:18 -08:00
|
|
|
|
{
|
2018-12-28 16:00:21 -08:00
|
|
|
|
while (findLocationIndex < tourLocations.Count)
|
2018-11-28 11:54:18 -08:00
|
|
|
|
{
|
2018-12-11 20:14:06 -08:00
|
|
|
|
var foundChildren = new List<GuiWidget.WidgetAndPosition>();
|
2018-12-28 16:00:21 -08:00
|
|
|
|
window.FindNamedChildrenRecursive(tourLocations[findLocationIndex].WidgetName, foundChildren);
|
2018-12-11 20:14:06 -08:00
|
|
|
|
|
2018-11-28 11:54:18 -08:00
|
|
|
|
foreach (var widgetAndPosition in foundChildren)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (widgetAndPosition.widget.ActuallyVisibleOnScreen())
|
|
|
|
|
|
{
|
|
|
|
|
|
return widgetAndPosition.widget;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-12-11 20:14:06 -08:00
|
|
|
|
|
2018-12-28 16:00:21 -08:00
|
|
|
|
findLocationIndex++;
|
2018-11-28 11:54:18 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-28 16:00:21 -08:00
|
|
|
|
GuiWidget targetWidget = GetLocationWidget(ref locationIndex);
|
2018-11-28 11:54:18 -08:00
|
|
|
|
|
|
|
|
|
|
if (targetWidget != null)
|
|
|
|
|
|
{
|
2018-12-28 16:00:21 -08:00
|
|
|
|
var tourOverlay = new TourOverlay(window, targetWidget, tourLocations[locationIndex].Description, ApplicationController.Instance.Theme, locationIndex + 1);
|
2018-11-28 11:54:18 -08:00
|
|
|
|
window.AddChild(tourOverlay);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-11-27 18:15:17 -08:00
|
|
|
|
}
|
|
|
|
|
|
}
|