/// <summary> /// Constructor, annotation hit</summary> /// <param name="annotation">Annotation item</param> /// <param name="border">Specifies a hit on an item's border part</param> public AnnotationHitEventArgs(IAnnotation annotation, DiagramBorder border) { Item = annotation; Part = border; }
private void ResizeAnnotation(DiagramBorder diagramBorder) { Point currentPoint = GdiUtil.InverseTransform(m_transformAdapter.Transform, CurrentPoint); Point firstPoint = GdiUtil.InverseTransform(m_transformAdapter.Transform, FirstPoint); Point delta = new Point(currentPoint.X - firstPoint.X, currentPoint.Y - firstPoint.Y); Rectangle newBounds; switch (diagramBorder.Border) { case DiagramBorder.BorderType.LowerRightCorner: newBounds = new Rectangle(m_startBounds.X, m_startBounds.Y, m_startBounds.Width + delta.X, m_startBounds.Height + delta.Y); m_layoutContext.SetBounds(diagramBorder.Item, ConstrainBounds(newBounds), BoundsSpecified.All); break; case DiagramBorder.BorderType.UpperLeftCorner: newBounds = new Rectangle(currentPoint.X, currentPoint.Y, m_startBounds.Width - delta.X, m_startBounds.Height - delta.Y); m_layoutContext.SetBounds(diagramBorder.Item, ConstrainBounds(newBounds), BoundsSpecified.All); break; case DiagramBorder.BorderType.UpperRightCorner: newBounds = new Rectangle(m_startBounds.X, currentPoint.Y, m_startBounds.Width + delta.X, m_startBounds.Height - delta.Y); m_layoutContext.SetBounds(diagramBorder.Item, ConstrainBounds(newBounds), BoundsSpecified.All); break; case DiagramBorder.BorderType.LowerLeftCorner: newBounds = new Rectangle(currentPoint.X, m_startBounds.Y, m_startBounds.Width - delta.X, m_startBounds.Height + delta.Y); m_layoutContext.SetBounds(diagramBorder.Item, ConstrainBounds(newBounds), BoundsSpecified.All); break; case DiagramBorder.BorderType.Left: newBounds = new Rectangle(currentPoint.X, m_startBounds.Y, m_startBounds.Width - delta.X, m_startBounds.Height); m_layoutContext.SetBounds(diagramBorder.Item, ConstrainBounds(newBounds), BoundsSpecified.All); break; case DiagramBorder.BorderType.Right: newBounds = new Rectangle(m_startBounds.X, m_startBounds.Y, m_startBounds.Width + delta.X, m_startBounds.Height); m_layoutContext.SetBounds(diagramBorder.Item, ConstrainBounds(newBounds), BoundsSpecified.Size); break; case DiagramBorder.BorderType.Top: newBounds = new Rectangle(m_startBounds.X, currentPoint.Y, m_startBounds.Width, m_startBounds.Height - delta.Y); m_layoutContext.SetBounds(diagramBorder.Item, ConstrainBounds(newBounds), BoundsSpecified.All); break; case DiagramBorder.BorderType.Bottom: newBounds = new Rectangle(m_startBounds.X, m_startBounds.Y, m_startBounds.Width, m_startBounds.Height + delta.Y); m_layoutContext.SetBounds(diagramBorder.Item, ConstrainBounds(newBounds), BoundsSpecified.Size); break; } }
/// <summary> /// Performs a pick operation on the diagram annotations</summary> /// <param name="p">Picking point</param> /// <returns>Information about which annotation, if any, was hit by point</returns> public AnnotationHitEventArgs Pick(Point p) { if (m_annotatedDiagram != null) { if (m_transformAdapter != null) p = GdiUtil.InverseTransform(m_transformAdapter.Transform, p); foreach (IAnnotation annotation in m_annotatedDiagram.Annotations.Reverse()) { Rectangle bounds = GetBounds(annotation); if (bounds.IsEmpty) continue; var inflated = bounds; int tolerance = m_theme.PickTolerance; inflated.Inflate(tolerance, tolerance); if (inflated.Contains(p) && m_annotationEditors.ContainsKey(annotation)) { // check titlebar var titlebarRect = new RectangleF(bounds.Left + 2 * tolerance, bounds.Y - tolerance, bounds.Width - 4 * tolerance, Margin.Top + tolerance); if (titlebarRect.Contains(p)) { return new AnnotationHitEventArgs(annotation, new DiagramTitleBar(annotation)); } var annotationData = m_annotationEditors[annotation]; // check scroll bar if (annotationData.VerticalScrollBarVisibe) { var scrollbarRect = new RectangleF(bounds.Right - Margin.Right - ScrollBarWidth - 2 * ScrollBarMargin, bounds.Y, ScrollBarWidth + 2 * ScrollBarMargin, bounds.Height); if (scrollbarRect.Contains(p)) return new AnnotationHitEventArgs(annotation, new DiagramScrollBar(annotation, Orientation.Vertical)); } // check borders // check corners first var border = new RectangleF(bounds.Right - 2 * tolerance, bounds.Bottom - 2 * tolerance, 4 * tolerance, 4 * tolerance); if (border.Contains(p)) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.LowerRightCorner }; return new AnnotationHitEventArgs(annotation, borderPart); } border = new RectangleF(bounds.Left - 2 * tolerance, bounds.Top - 2 * m_theme.PickTolerance, 4 * tolerance, 4 * tolerance); if (border.Contains(p)) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.UpperLeftCorner }; return new AnnotationHitEventArgs(annotation, borderPart); } border = new RectangleF(bounds.Right - 2 * m_theme.PickTolerance, bounds.Top - 2 * m_theme.PickTolerance, 4 * tolerance, 4 * tolerance); if (border.Contains(p)) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.UpperRightCorner }; return new AnnotationHitEventArgs(annotation, borderPart); } border = new RectangleF(bounds.Left - 2 * m_theme.PickTolerance, bounds.Bottom - 2 * m_theme.PickTolerance, 4 * tolerance, 4 * tolerance); if (border.Contains(p)) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.LowerLeftCorner }; return new AnnotationHitEventArgs(annotation, borderPart); } border = new RectangleF(bounds.Left - m_theme.PickTolerance, bounds.Y, 2 * m_theme.PickTolerance, bounds.Height); if (border.Contains(p)) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.Left }; return new AnnotationHitEventArgs(annotation, borderPart); } border.Offset(bounds.Width, 0); if (border.Contains(p)) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.Right }; return new AnnotationHitEventArgs(annotation, borderPart); } border = new RectangleF(bounds.Left, bounds.Y - m_theme.PickTolerance, bounds.Width, 2 * m_theme.PickTolerance); if (border.Contains(p)) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.Top }; return new AnnotationHitEventArgs(annotation, borderPart); } border.Offset(0, bounds.Height); if (border.Contains(p)) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.Bottom }; return new AnnotationHitEventArgs(annotation, borderPart); } // check label inflated.Inflate(tolerance, tolerance); DiagramLabel label = null; if (inflated.Contains(p)) { var textBounds = new Rectangle(bounds.X + Margin.Left, bounds.Y + Margin.Top, (int)annotationData.TextLayout.LayoutWidth + SystemInformation.VerticalScrollBarWidth, (int)annotationData.TextLayout.LayoutHeight); label = new DiagramLabel(textBounds, TextFormatFlags.LeftAndRightPadding); // set initial editing position var contentBounds = new RectangleF(bounds.X + Margin.Left, bounds.Y + Margin.Top, bounds.Width - Margin.Size.Width, bounds.Height - Margin.Size.Height); contentBounds.Width = Math.Max(contentBounds.Width, MinimumWidth); contentBounds.Height = Math.Max(contentBounds.Height, MinimumHeight); PointF origin = new PointF(contentBounds.Location.X, contentBounds.Location.Y - annotationData.TopLine * m_theme.TextFormat.FontHeight); var result = new AnnotationHitEventArgs(annotation, label); result.Position = new PointF(p.X - origin.X, p.Y - origin.Y); return result; } } } } return new AnnotationHitEventArgs(); }
/// <summary> /// Performs hit test for a point, in client coordinates</summary> /// <param name="p">Pick point, in client coordinates</param> /// <returns>Hit record for a point, in client coordinates</returns> DiagramHitRecord IPickingAdapter2.Pick(Point p) { if (m_annotatedDiagram != null && !PickingDisabled) { if (m_transformAdapter != null) p = GdiUtil.InverseTransform(m_transformAdapter.Transform, p); foreach (IAnnotation annotation in m_annotatedDiagram.Annotations.Reverse()) { TextEditor textEditor; m_annotationEditors.TryGetValue(annotation, out textEditor); Rectangle bounds = GetBounds(annotation); if (bounds.IsEmpty && textEditor == null) continue; var inflated = bounds; int tolerance = m_theme.PickTolerance; inflated.Inflate(tolerance, tolerance); if (!inflated.Contains(p)) continue; Rectangle contentRect = bounds; contentRect.X += Margin.Left; contentRect.Y += Margin.Right; contentRect.Size -= Margin.Size; if (contentRect.Contains(p)) { // check scroll bar if (textEditor != null && textEditor.VerticalScrollBarVisibe) { var scrollbarRect = new Rectangle(bounds.Right - Margin.Right - ScrollBarWidth - 2 * ScrollBarMargin, bounds.Y, ScrollBarWidth + 2 * ScrollBarMargin, bounds.Height); if (scrollbarRect.Contains(p)) return new AnnotationHitEventArgs(annotation, new DiagramScrollBar(annotation, Orientation.Vertical)); } //var textBounds = new Rectangle(contentRect.X, contentRect.Y, // contentRect.Width, contentRect.Height); var textBounds = contentRect; DiagramLabel label = new DiagramLabel(textBounds, TextFormatFlags.LeftAndRightPadding); PointF origin = textEditor != null ? new PointF(contentRect.X, contentRect.Y - textEditor.GetLineYOffset(textEditor.TopLine)) : contentRect.Location; var result = new AnnotationHitEventArgs(annotation, label); result.Position = new PointF(p.X - origin.X, p.Y - origin.Y); return result; } //// check titlebar //var titlebarRect = new RectangleF(bounds.Left + 2 * tolerance, bounds.Y - tolerance, // bounds.Width - 4 * tolerance, Margin.Top + tolerance); //if (titlebarRect.Contains(p)) //{ // return new AnnotationHitEventArgs(annotation, new DiagramTitleBar(annotation)); //} // margin between inflated bounds and content bound. int leftPad = contentRect.X - inflated.X; int rightPad = inflated.Right - contentRect.Right; int topPad = contentRect.Y - inflated.Y; int bottomPad = inflated.Bottom - contentRect.Bottom; // lower right var corner = new Rectangle(contentRect.Right, contentRect.Bottom, rightPad, bottomPad); if (corner.Contains(p)) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.LowerRightCorner }; return new AnnotationHitEventArgs(annotation, borderPart); } // upper left corner = new Rectangle(inflated.X, inflated.Y, leftPad, topPad); if (corner.Contains(p)) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.UpperLeftCorner }; return new AnnotationHitEventArgs(annotation, borderPart); } // upper right corner = new Rectangle(contentRect.Right, inflated.Y, rightPad, topPad); if (corner.Contains(p)) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.UpperRightCorner }; return new AnnotationHitEventArgs(annotation, borderPart); } // lower left. corner = new Rectangle(inflated.X, contentRect.Bottom, leftPad, bottomPad); if (corner.Contains(p)) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.LowerLeftCorner }; return new AnnotationHitEventArgs(annotation, borderPart); } // right border. if (p.X >= contentRect.Right) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.Right }; return new AnnotationHitEventArgs(annotation, borderPart); } // bottom border if (p.Y >= contentRect.Bottom) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.Bottom }; return new AnnotationHitEventArgs(annotation, borderPart); } // left border if (p.X <= contentRect.X) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.Left }; return new AnnotationHitEventArgs(annotation, borderPart); } // top border if (p.Y <= contentRect.Y) { var borderPart = new DiagramBorder(annotation) { Border = DiagramBorder.BorderType.Top }; return new AnnotationHitEventArgs(annotation, borderPart); } } } return new AnnotationHitEventArgs(); }