PointApplyResult _applyCurrentPoint(Point p, ShapeUtils.RectSide side) { var res = PointApplyResult.None; double dx = p.X - CurrentPoint.X; double dy = p.Y - CurrentPoint.Y; if (activeMarker == null) { HandleMove(dx, dy); if (dx != 0.0 || dy != 0.0) res = PointApplyResult.Move; } else { HandleResize(dx, dy, side); if (dx != 0.0 || dy != 0.0) res = PointApplyResult.Resize; } SetBounds(); CurrentPoint.X = p.X; CurrentPoint.Y = p.Y; return res; }
private void HandleResize(double deltaX, double deltaY, ShapeUtils.RectSide side) { Rect bounds = GetShapeBounds(); Rect boundsBefore = bounds; try { switch (side) { case ShapeUtils.RectSide.TopLeft: bounds.X += deltaX; bounds.Y += deltaY; bounds.Width -= deltaX; bounds.Height -= deltaY; break; case ShapeUtils.RectSide.TopRight: bounds.Width += deltaX; bounds.Y += deltaY; bounds.Height -= deltaY; break; case ShapeUtils.RectSide.BottomLeft: bounds.X += deltaX; bounds.Width -= deltaX; bounds.Height += deltaY; break; case ShapeUtils.RectSide.BottomRight: bounds.Width += deltaX; bounds.Height += deltaY; break; case ShapeUtils.RectSide.TwoSided: break; } } catch (Exception) { } if (bounds.Width > MIN_SIZE && bounds.Height > MIN_SIZE) { var manipOrg = _textEnterUC.RenderTransform.Transform( new Point(0,0) ); double xScale = bounds.Width/boundsBefore.Width; double yScale = bounds.Height/boundsBefore.Height; double scaleCoeff = Math.Max(xScale, yScale); var scale = new Vector(yScale, yScale); var translate = new Vector(bounds.X - boundsBefore.X, bounds.Y - boundsBefore.Y); ShapeUtils.ApplyTransform(_textEnterUC, new Vector(manipOrg.X, manipOrg.Y), translate, 0, scale); SetBounds(); } }
//given list of badges which comprise cluster, we build convex hull and then smooth border public void PlayBuildSmoothCurve() { var BadgesCorners = ShapeUtils.buildBadgeCorners(_endpoint.GetClusterables()); if (BadgesCorners.Count <= 2) { //rebuilding cluster after unclustering last badge. //the cluster will soon be removed (by server event) return; } convexHull.Points = ConvexHull.FindConvexPolygon(BadgesCorners); var convexPoints = convexHull.Points; _topLeft = new Point(convexPoints.Min(pt => pt.X), convexPoints.Min(pt => pt.Y)); //build bezier curve var pathFigure = new PathFigure(); Point[] firstControlPoints = null; Point[] secondControlPoints = null; ovp.BezierSpline.GetCurveControlPoints(convexPoints.ToArray(), out firstControlPoints, out secondControlPoints); pathFigure.StartPoint = convexPoints.ElementAt(0); for (int i = 0; i < convexPoints.Count - 1; i++) { pathFigure.Segments.Add(new BezierSegment(firstControlPoints[i], secondControlPoints[i], convexPoints.ElementAt(i + 1), true)); } //closing segment if (convexPoints.Count == 3) { Point[] firstLast = new Point[] { convexPoints[2], convexPoints[0], convexPoints[1] }; ovp.BezierSpline.GetCurveControlPoints(firstLast, out firstControlPoints, out secondControlPoints); pathFigure.Segments.Add(new BezierSegment(firstControlPoints.First(), secondControlPoints.First(), convexPoints.First(), true)); } else { Point[] firstLast = new Point[] { convexPoints[convexPoints.Count - 2], convexPoints[convexPoints.Count - 1], convexPoints[0], convexPoints[1] }; ovp.BezierSpline.GetCurveControlPoints(firstLast, out firstControlPoints, out secondControlPoints); pathFigure.Segments.Add(new BezierSegment(firstControlPoints[1], secondControlPoints[1], convexPoints[0], true)); } var pathGeom = new PathGeometry(); pathGeom.Figures.Add(pathFigure); bezierBorder.Data = pathGeom; _offset = new Point(0, 0); if (_endpoint.GetClusterables().Count() > 0) { clusterCreated = true; if (cleanerTimer != null) { cleanerTimer.Stop(); cleanerTimer = null; } } SetBounds(); }
void SetMarkers() { ShapeUtils.SetLinkEnd(selMarker1, line.X1, line.Y1); ShapeUtils.SetLinkEnd(selMarker2, line.X2, line.Y2); }
private void HandleResize(double deltaX, double deltaY, ShapeUtils.RectSide side) { var bounds = _bounds; try { switch (side) { case ShapeUtils.RectSide.TopLeft: bounds.X += deltaX; bounds.Y += deltaY; bounds.Width -= deltaX; bounds.Height -= deltaY; break; case ShapeUtils.RectSide.TopRight: bounds.Width += deltaX; bounds.Y += deltaY; bounds.Height -= deltaY; break; case ShapeUtils.RectSide.BottomLeft: bounds.X += deltaX; bounds.Width -= deltaX; bounds.Height += deltaY; break; case ShapeUtils.RectSide.BottomRight: bounds.Width += deltaX; bounds.Height += deltaY; break; case ShapeUtils.RectSide.TwoSided: double cx = (bounds.Left + bounds.Right)/2; double cy = (bounds.Top + bounds.Bottom)/2; bounds.Width += deltaX/2; bounds.Height += deltaY/2; bounds.X = cx - bounds.Width/2; bounds.Y = cy - bounds.Height/2; break; } } catch (Exception) { } if (bounds.Width > MIN_SIZE && bounds.Height > MIN_SIZE) _bounds = bounds; }
public void ScaleInPlace(bool plus) { var s = ShapeUtils.scaleFactor(plus); HandleScale(s); }