public static Border GetThumbnail(ConvolutionBase2D conv, int thumbSize, ContextMenu contextMenu, ConvolutionToolTipType typeSet = ConvolutionToolTipType.None, ConvolutionToolTipType typeSingle = ConvolutionToolTipType.Size) { if (conv is Convolution2D) { return GetThumbnail_Single((Convolution2D)conv, thumbSize, contextMenu, typeSingle); } else if (conv is ConvolutionSet2D) { return GetThumbnail_Set((ConvolutionSet2D)conv, thumbSize, contextMenu, typeSet); } else { throw new ArgumentException("Unknown type of kernel: " + conv.GetType().ToString()); } }
private static Border GetThumbnail_Set(ConvolutionSet2D kernel, int thumbSize, ContextMenu contextMenu, ConvolutionToolTipType tooltipType) { StackPanel children = new StackPanel() { Orientation = Orientation.Horizontal, }; int childSize = Convert.ToInt32(thumbSize * .9); double secondChildShift = thumbSize * .33; foreach (ConvolutionBase2D child in kernel.Convolutions) { //NOTE: It doesn't work to apply skew transforms to a border that has children. Instead, make a visual brush out of the child Border childCtrl = GetThumbnail(child, childSize, null); childCtrl.Margin = new Thickness(0); Border actualChild = new Border(); actualChild.Background = new VisualBrush() { Visual = childCtrl }; double width = 0; double height = 0; if (child is Convolution2D) { width = ((FrameworkElement)childCtrl.Child).Width; height = ((FrameworkElement)childCtrl.Child).Height; } else //if(child is ConvolutionSet2D) { // There doesn't seem to be a way to get the child composite's size (it's NaN). Maybe there's a way to force it to do layout? width = thumbSize; height = thumbSize; } actualChild.Width = width; actualChild.Height = height; //NOTE: I wanted a trapazoid transform, but that is impossible with a 3x3 matrix. The only way would be to render in 3D TransformGroup tranform = new TransformGroup(); tranform.Children.Add(new ScaleTransform(.75, 1)); tranform.Children.Add(new SkewTransform(0, -30)); actualChild.LayoutTransform = tranform; if (children.Children.Count > 0) { actualChild.Margin = new Thickness(-secondChildShift, 0, 0, 0); } actualChild.IsHitTestVisible = false; // setting this to false so that click events come from the returned border instead of the child children.Children.Add(actualChild); } Border border = new Border() { Child = children, Background = new SolidColorBrush(UtilityWPF.ColorFromHex("28F2B702")), BorderBrush = new SolidColorBrush(UtilityWPF.ColorFromHex("F5CC05")), BorderThickness = new Thickness(1), Margin = new Thickness(6), Padding = new Thickness(3), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, ContextMenu = contextMenu, Tag = kernel, }; border.ToolTip = GetToolTip(kernel, tooltipType); return border; }
private static Border GetThumbnail_Single(Convolution2D kernel, int thumbSize, ContextMenu contextMenu, ConvolutionToolTipType tooltipType) { // Figure out thumb size var sizes = GetThumbSizeAndPixelMultiplier(kernel, thumbSize); // Display it as a border and image Image image = new Image() { Source = GetBitmap_Aliased(kernel, sizes.Item2), Width = sizes.Item1.Width, Height = sizes.Item1.Height, ToolTip = GetToolTip(kernel, tooltipType), }; Border border = new Border() { Child = image, BorderBrush = new SolidColorBrush(UtilityWPF.ColorFromHex("C0C0C0")), BorderThickness = new Thickness(1), Margin = new Thickness(6), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, ContextMenu = contextMenu, Tag = kernel, }; return border; }
public static string GetToolTip(Convolution2D conv, ConvolutionToolTipType type) { StringBuilder retVal = new StringBuilder(100); if (!string.IsNullOrEmpty(conv.Description)) { retVal.Append(conv.Description); } if (type == ConvolutionToolTipType.Size || type == ConvolutionToolTipType.Size_MinMax) { if (retVal.Length > 0) { retVal.AppendLine(); } retVal.AppendFormat("{0}x{1}", conv.Width, conv.Height); } if (type == ConvolutionToolTipType.Size_MinMax) { retVal.AppendLine(); double min = conv.Values.Min(); double max = conv.Values.Max(); retVal.AppendFormat("min: {0}\r\nmax: {1}", min.ToStringSignificantDigits(2), max.ToStringSignificantDigits(2)); } if (retVal.Length == 0) { return null; // otherwise there will be a tiny empty tooltip } else { return retVal.ToString(); } }
public static string GetToolTip(ConvolutionSet2D set, ConvolutionToolTipType type) { StringBuilder retVal = new StringBuilder(100); if (!string.IsNullOrEmpty(set.Description)) { retVal.Append(set.Description); } if (type == ConvolutionToolTipType.Size || type == ConvolutionToolTipType.Size_MinMax && set.Convolutions != null && set.Convolutions.Length > 0) { if (retVal.Length > 0) { retVal.AppendLine(); } VectorInt size = set.GetSize(); retVal.AppendFormat("{0}x{1}", size.X, size.Y); } if (type == ConvolutionToolTipType.Size_MinMax) { retVal.AppendLine(); double min = set.EnumerateValues().Min(); double max = set.EnumerateValues().Min(); retVal.AppendFormat("min: {0}\r\nmax: {1}", min.ToStringSignificantDigits(2), max.ToStringSignificantDigits(2)); } if (retVal.Length == 0) { return null; // otherwise there will be a tiny empty tooltip } else { return retVal.ToString(); } }
public static string GetToolTip(ConvolutionBase2D conv, ConvolutionToolTipType typeSet, ConvolutionToolTipType typeSingle) { if (conv is ConvolutionSet2D) { return GetToolTip((ConvolutionSet2D)conv, typeSet); } else if (conv is Convolution2D) { return GetToolTip((Convolution2D)conv, typeSingle); } else { return ""; } }