From a74ecac5d1980775f10d719fe8ae93b0695eee72 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Wed, 10 Nov 2021 12:46:06 +0200 Subject: PPC. ColorSelection tool. Added Catalogs. Related Work Items: #4558 --- .../Controls/TwineCatalogControl.xaml | 10 +-- .../Controls/TwineCatalogControl.xaml.cs | 56 ++++++++++++++++- .../Controls/TwineCatalogRenderer.cs | 71 +++++++++++++++------- 3 files changed, 107 insertions(+), 30 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.Common/Controls') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml b/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml index c4d047d39..7a8b2908d 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml @@ -17,9 +17,9 @@ - + - + @@ -93,7 +93,7 @@ --> - + @@ -130,8 +130,8 @@ - - + + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml.cs index 6ef7d92e8..22a0f4825 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogControl.xaml.cs @@ -13,6 +13,7 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Tango.BL.Entities; +using Tango.Touch.Components; using Tango.Touch.Controls; namespace Tango.PPC.Common.Controls @@ -27,6 +28,7 @@ namespace Tango.PPC.Common.Controls private ColorCatalog _catalog; private bool _preventChange; private double _lastScrollPosition = 0; + private bool _findInProcess = false; /// /// Gets or sets the selected catalog item. @@ -37,7 +39,35 @@ namespace Tango.PPC.Common.Controls set { SetValue(SelectedItemProperty, value); } } public static readonly DependencyProperty SelectedItemProperty = - DependencyProperty.Register("SelectedItem", typeof(ColorCatalogsItem), typeof(TwineCatalogControl), new PropertyMetadata(null)); + DependencyProperty.Register("SelectedItem", typeof(ColorCatalogsItem), typeof(TwineCatalogControl), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, new PropertyChangedCallback(OnSelectedItemPropertyChanged))); + + + private static void OnSelectedItemPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + TwineCatalogControl twineCatalogControl = (TwineCatalogControl)d; + if(e.OldValue != e.NewValue) + { + twineCatalogControl.SelectedItemPropertyChanged(); + } + } + + /// + /// Gets or sets the collection filter. + /// + public ICollectionFilter CollectionFilter + { + get { return (ICollectionFilter)GetValue(CollectionFilterProperty); } + set { SetValue(CollectionFilterProperty, value); } + } + public static readonly DependencyProperty CollectionFilterProperty = + DependencyProperty.Register("CollectionFilter", typeof(ICollectionFilter), typeof(TwineCatalogControl), new PropertyMetadata(null, (d, e) => (d as TwineCatalogControl).OnCollectionFilterChanged())); + + + public void SelectedItemPropertyChanged() + { + // if(renderer.SelectedItem != this.SelectedItem) + // renderer.SelectedItem = this.SelectedItem; + } /// /// Initializes a new instance of the class. @@ -100,7 +130,7 @@ namespace Tango.PPC.Common.Controls if (!_preventChange) { - if (_catalog != null) + if (_catalog != null && scrollViewer != null) { _preventChange = true; var group = _catalog.ColorCatalogsGroupsOrdered.ElementAt(_catalog.ColorCatalogsGroupsOrdered.Count - 1 - (int)e.NewValue); @@ -114,5 +144,27 @@ namespace Tango.PPC.Common.Controls slider.Foreground = new SolidColorBrush(_catalog.ColorCatalogsGroupsOrdered.ElementAt(_catalog.ColorCatalogsGroupsOrdered.Count - 1 - (int)e.NewValue).Color); } } + + private void OnCollectionFilterChanged() + { + if (_findInProcess) + return; + if (CollectionFilter != null) + { + CollectionFilter.FilterChanged -= CollectionFilter_FilterChanged; + CollectionFilter.FilterChanged += CollectionFilter_FilterChanged; + } + } + + private void CollectionFilter_FilterChanged(object sender, EventArgs e) + { + _findInProcess = true; + //if (CollectionFilter != null ) + //{ + // row.Visibility = CollectionFilter.Filter(row.DataContext) ? Visibility.Visible : Visibility.Collapsed; + // display = row.Visibility == Visibility.Visible; + //} + _findInProcess = false; + } } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogRenderer.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogRenderer.cs index a3b65d17a..1f9a42561 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogRenderer.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/Controls/TwineCatalogRenderer.cs @@ -9,6 +9,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; +using System.Windows.Media.Imaging; using Tango.BL.Entities; using Tango.Touch.Controls; @@ -21,6 +22,7 @@ namespace Tango.PPC.Common.Controls public DrawingVisual Visual { get; set; } public ColorCatalogsItem Item { get; set; } public double PositionY { get; set; } + public Rect ImageRect { get; set; } } private class GroupContainer @@ -40,14 +42,19 @@ namespace Tango.PPC.Common.Controls private readonly VisualCollection _children; private List _catalogItems; private List _groupItems; - private double ellipseWidth = 60; - private double ellipseHeight = 60; - private double textHeight = 30; - private double ellipseMargin = 20; - private double textMargin = 5; - private double groupMargin = 60; + private double ellipseWidth = 70; + private double ellipseHeight = 70; + private double textHeight = 20; + private double ellipseMarginX = 18; + private double ellipseMarginY = 50; + private double textMargin = 8; + private double groupMargin = 50; private bool selectedFromClick; private LightTouchScrollViewer _scrollViewer; + private BitmapSource _myColorBitmap; + private double imageWidth = 24; + private double imageHeight = 22; + private Point _lastMouseClickPoint; public IEnumerable Groups { @@ -92,6 +99,7 @@ namespace Tango.PPC.Common.Controls this.PreviewMouseUp += TwineCatalogRenderer_MouseLeftButtonUp; this.Loaded += TwineCatalogRenderer_Loaded; + _myColorBitmap = new BitmapImage(new Uri($"pack://application:,,,/Tango.PPC.JobsV2;component/Images/ColorSelection/Heart.png", UriKind.Absolute)); } private void TwineCatalogRenderer_Loaded(object sender, RoutedEventArgs e) @@ -136,12 +144,12 @@ namespace Tango.PPC.Common.Controls { // Retreive the coordinates of the mouse button event. Point pt = e.GetPosition((UIElement)this); - + _lastMouseClickPoint = pt; // Initiate the hit test by setting up a hit test result callback method. VisualTreeHelper.HitTest(this, null, HitTestCallback, new PointHitTestParameters(pt)); } } - + // If a child visual object is hit, toggle its opacity to visually indicate a hit. public HitTestResultBehavior HitTestCallback(HitTestResult result) { @@ -152,9 +160,13 @@ namespace Tango.PPC.Common.Controls if (visual != null) { var container = _catalogItems.SingleOrDefault(x => x.Visual == visual); - + if (container != null && container.Item is ColorCatalogsItem) { + if (container.ImageRect.Contains(_lastMouseClickPoint)) + { + // clicked on image + } selectedFromClick = true; SelectedItem = container.Item; selectedFromClick = false; @@ -176,8 +188,9 @@ namespace Tango.PPC.Common.Controls (newItem.Visual.Transform as ScaleTransform).ScaleX = 1.3; (newItem.Visual.Transform as ScaleTransform).ScaleY = 1.3; - if (!selectedFromClick) + if (!selectedFromClick && _scrollViewer != null) { + _scrollViewer.ScrollToPosition(newItem.PositionY - _scrollViewer.ActualHeight / 2); } } @@ -189,7 +202,7 @@ namespace Tango.PPC.Common.Controls } } - private ItemContainer AddCatalogItem(DrawingVisual visual, ColorCatalogsItem item, double y) + private ItemContainer AddCatalogItem(DrawingVisual visual, ColorCatalogsItem item, double y, Rect imageRect) { _children.Add(visual); @@ -198,6 +211,7 @@ namespace Tango.PPC.Common.Controls Visual = visual, Item = item, PositionY = y, + ImageRect = imageRect }; _catalogItems.Add(container); @@ -238,40 +252,49 @@ namespace Tango.PPC.Common.Controls var groupContainer = AddGroupItem(CreateGroup(group.Name, position_y), group, position_y); - position_y += ellipseMargin; + position_y += ellipseMarginX; foreach (var item in group.ColorCatalogsItems.OrderBy(x => x.ItemIndex)) { - double x = position_x + ellipseMargin; + double x = position_x + ellipseMarginX; if (x + ellipseWidth > ActualWidth) { position_x = 0; - position_y += (ellipseHeight + ellipseMargin + textMargin + textHeight); + position_y += (ellipseHeight + ellipseMarginY + textMargin + textHeight); } - - var itemContainer = AddCatalogItem(CreateItem(item, position_x + ellipseMargin, position_y + ellipseMargin), item, position_y + ellipseMargin); + Rect imageRect = new Rect(new Point(position_x + ellipseWidth, position_y + ellipseMarginY/2 + 2), new Size( imageWidth, imageHeight)); + var itemContainer = AddCatalogItem(CreateItem(item, position_x + ellipseMarginX, position_y + ellipseMarginY, imageRect), item, position_y + ellipseMarginY, imageRect); groupContainer.Items.Add(itemContainer); - position_x += ellipseWidth + ellipseMargin; + position_x += ellipseWidth + ellipseMarginX; } - position_y += (ellipseHeight + ellipseMargin + textMargin + textHeight + groupMargin); + position_y += (ellipseHeight + ellipseMarginY + textMargin + textHeight + groupMargin); } Height = position_y; } + + UpdateLayout(); + if (SelectedItem != null) + { + OnSelectedItemChanged( null, SelectedItem); + } + //InvalidateVisual(); } - private DrawingVisual CreateItem(ColorCatalogsItem item, double x, double y) + private DrawingVisual CreateItem(ColorCatalogsItem item, double x, double y, Rect imageRect) { DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); + + drawingContext.DrawImage(_myColorBitmap, imageRect); drawingContext.DrawEllipse(new SolidColorBrush(item.Color), null, new Point(x + ellipseWidth / 2, y + ellipseHeight / 2), ellipseWidth / 2, ellipseHeight / 2); - + var formattedText = new FormattedText(item.Name, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, @@ -279,7 +302,7 @@ namespace Tango.PPC.Common.Controls 16, Foreground); - formattedText.MaxTextWidth = ellipseWidth + ellipseMargin; + formattedText.MaxTextWidth = ellipseWidth + ellipseMarginX; drawingContext.DrawText(formattedText, new Point((x + (ellipseWidth / 2)) - (formattedText.Width / 2), y + ellipseHeight + textMargin)); @@ -313,12 +336,13 @@ namespace Tango.PPC.Common.Controls CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Flexo"), - 25, + 23, Foreground); //formattedText.SetFontWeight(FontWeights.SemiBold); - drawingContext.DrawText(formattedText, new Point((ActualWidth / 2) - (formattedText.Width / 2), y)); + // drawingContext.DrawText(formattedText, new Point((ActualWidth / 2) - (formattedText.Width / 2), y)); + drawingContext.DrawText(formattedText, new Point(ellipseMarginX, y)); drawingContext.Close(); @@ -338,5 +362,6 @@ namespace Tango.PPC.Common.Controls return _children[index]; } + } } -- cgit v1.3.1