public GroundLinkShape(Link groundLink, double xOffset, double yOffset, double strokeThickness, double jointSize, double startingBufferRadius) { Name = "ground"; Canvas.SetZIndex(this, 0); double triangleSideLength = 2.5 * jointSize; foreach (var j in groundLink.joints) { switch (j.TypeOfJoint) { case JointType.R: Children.Add(new Line { Stroke = new SolidColorBrush(Colors.Black), StrokeThickness = strokeThickness, X1 = j.xInitial + xOffset - 2 * triangleSideLength, Y1 = j.yInitial + yOffset - triangleSideLength, X2 = j.xInitial + xOffset + 2 * triangleSideLength, Y2 = j.yInitial + yOffset - triangleSideLength, }); Children.Add(new Polygon { Stroke = new SolidColorBrush(Colors.Black), Fill = new SolidColorBrush(Colors.Black), StrokeThickness = strokeThickness, Points = new PointCollection { new Point(j.xInitial + xOffset, j.yInitial + yOffset), new Point(j.xInitial + xOffset - triangleSideLength, j.yInitial + yOffset - triangleSideLength), new Point(j.xInitial + xOffset + triangleSideLength, j.yInitial + yOffset - triangleSideLength) } }); break; case JointType.P: if (j.SlidingWithRespectTo(groundLink)) { Children.Add(new Path { Data = SlideShapeMaker.MakePSlotBorder(j, groundLink, xOffset, yOffset, jointSize, startingBufferRadius), //Fill = new ImageBrush //{ // ImageSource = new BitmapImage(new Uri("../Properties/groundhashMED.png", UriKind.Relative)), // Stretch = Stretch.UniformToFill // //RelativeTransform = new ScaleTransform{ScaleX = 1.0,ScaleY = 1.0} // // in order to do this, you will need code to handle the tiling - not native to Silverlight // // use Shazzam (http://shazzam-tool.com/) to make the shader fx // // then use http://silverscratch.blogspot.com/2010/09/tiled-image-brush-for-silverlight.html // // or //} Fill = new SolidColorBrush(new Color { A = opacity, B = grayscale, G = grayscale, R = grayscale }) }); Children.Add(new Path { Data = SlideShapeMaker.MakePSlotHole(j, groundLink, xOffset, yOffset, jointSize, startingBufferRadius), Stroke = new SolidColorBrush(Colors.Black), Fill = new SolidColorBrush(Colors.White), StrokeThickness = strokeThickness }); } else { Children.Add(new Path { Data = SlideShapeMaker.MakePSlotBorder(j, groundLink, xOffset, yOffset, jointSize, startingBufferRadius, true), Fill = new SolidColorBrush(new Color { A = opacity, B = grayscale, G = grayscale, R = grayscale }) }); } break; case JointType.RP: if (j.SlidingWithRespectTo(groundLink)) { Children.Add(new Path { Data = SlideShapeMaker.MakePSlotBorder(j, groundLink, xOffset, yOffset, jointSize, startingBufferRadius), Fill = new SolidColorBrush(new Color { A = opacity, B = grayscale, G = grayscale, R = grayscale }) //Fill = new ImageBrush //{ // ImageSource = new BitmapImage(new Uri("../Properties/groundhashMED.png", UriKind.Relative)), // Stretch = Stretch.UniformToFill // //RelativeTransform = new ScaleTransform{ScaleX = 1.0,ScaleY = 1.0} // // in order to do this, you will need code to handle the tiling - not native to Silverlight // // use Shazzam (http://shazzam-tool.com/) to make the shader fx // // then use http://silverscratch.blogspot.com/2010/09/tiled-image-brush-for-silverlight.html // // or //} }); Children.Add(new Path { Data = SlideShapeMaker.MakeRPSlotHole(j, groundLink, xOffset, yOffset, jointSize, startingBufferRadius), Stroke = new SolidColorBrush(Colors.Black), Fill = new SolidColorBrush(Colors.White), StrokeThickness = strokeThickness }); } else { Children.Add(new Ellipse { Stroke = new SolidColorBrush(Colors.Black), Fill = new SolidColorBrush(Colors.Black), StrokeThickness = strokeThickness, Height = jointSize, Width = jointSize, RenderTransform = new TranslateTransform { X = j.xInitial + xOffset, Y = j.yInitial + yOffset } }); Children.Add(new Polygon { Stroke = new SolidColorBrush(Colors.Black), Fill = new SolidColorBrush(Colors.Black), StrokeThickness = strokeThickness, Points = new PointCollection { new Point(j.xInitial + xOffset, j.yInitial + yOffset), new Point(j.xInitial + xOffset - triangleSideLength, j.yInitial + yOffset - triangleSideLength), new Point(j.xInitial + xOffset + triangleSideLength, j.yInitial + yOffset - triangleSideLength) } }); } break; default: //this would be gear throw new NotImplementedException(); } } }
public LinkShape(int linkNum, Link thisLink, double xOffset, double yOffset, double strokeThickness, double jointSize, Slider bufferRadiusSlider, double startingBufferRadius) { this.linkNum = linkNum; this.thisLink = thisLink; Name = thisLink.name; Fill = new SolidColorBrush(AHSLtoARGBColor.Convert(DisplayConstants.LinkFillOpacity, DisplayConstants.LinkHueMultiplier * linkNum, DisplayConstants.LinkFillSaturation, DisplayConstants.LinkFillLuminence)); Stroke = new SolidColorBrush(AHSLtoARGBColor.Convert(DisplayConstants.LinkStrokeOpacity, DisplayConstants.LinkHueMultiplier * linkNum, DisplayConstants.LinkStrokeSaturation, DisplayConstants.LinkStrokeLuminence)); StrokeThickness = strokeThickness; Height = Width = DisplayConstants.UnCroppedDimension; var centers = new List <Point>(); foreach (var j in thisLink.joints) { if (j.SlidingWithRespectTo(thisLink)) { var slideAngle = j.SlideAngleInitial; var dx = DisplayConstants.InitialSlidingJointLengthMultiplier * startingBufferRadius * Math.Cos(slideAngle); var dy = DisplayConstants.InitialSlidingJointLengthMultiplier * startingBufferRadius * Math.Sin(slideAngle); centers.Add(new Point(j.xInitial + xOffset + dx, j.yInitial + yOffset + dy)); centers.Add(new Point(j.xInitial + xOffset - dx, j.yInitial + yOffset - dy)); if (slideHoles == null) { slideHoles = new GeometryGroup { FillRule = FillRule.Nonzero, Children = new GeometryCollection() }; slideBorders = new GeometryGroup { FillRule = FillRule.Nonzero, Children = new GeometryCollection() }; } if (j.TypeOfJoint == JointType.P) { slideHoles.Children.Add(SlideShapeMaker.MakePSlotHole(j, thisLink, xOffset, yOffset, jointSize, startingBufferRadius)); } else { slideHoles.Children.Add(SlideShapeMaker.MakeRPSlotHole(j, thisLink, xOffset, yOffset, jointSize, startingBufferRadius)); } slideBorders.Children.Add(SlideShapeMaker.MakePSlotBorder(j, thisLink, xOffset, yOffset, jointSize, startingBufferRadius)); } else { centers.Add(new Point(j.xInitial + xOffset, j.yInitial + yOffset)); } } if (centers.Count == 1) { MinimumBufferRadius = DisplayConstants.SingleJointLinkRadiusMultipler * startingBufferRadius; Opacity = DisplayConstants.LinkFillOpacityForOneJointLinks; cvxCenters = centers; } else { MinimumBufferRadius = 0.0; cvxCenters = MIConvexHull.Find(centers); } // the next line can be removed one the binding is established. BufferRadius = startingBufferRadius; //var binding = new Binding // { // Source = bufferRadiusSlider, // Mode = BindingMode.TwoWay, // Path = new PropertyPath(RangeBase.ValueProperty), // }; //SetBinding(BufferRadiusProperty, binding); Data = RedrawWithNewBufferRadius(); }