public void AddStroke(MyStroke stroke) { VisibleStroke p = stroke.ToStroke(da.Clone()); p.Visibility = this.Visibility; strokes.Add(p); App.ink.Dispatcher.Invoke(new Action(() => { App.ink.Strokes.Add(p); })); }
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes) { if (drawingContext == null) { throw new ArgumentNullException("drawingContext"); } if (null == drawingAttributes) { throw new ArgumentNullException("drawingAttributes"); } if (StylusPoints.Count < 2) { return; } DrawingAttributes originalDa = drawingAttributes.Clone(); SolidColorBrush brush2 = new SolidColorBrush(originalDa.Color); Pen pen = new Pen(brush2, 1); brush2.Freeze(); if (draw != null) { draw(drawingContext, (Point)StylusPoints[0], (Point)StylusPoints[StylusPoints.Count - 1]); } else { drawingContext.DrawRectangle(null, pen, new Rect((Point)StylusPoints[0], (Point)StylusPoints[StylusPoints.Count - 1])); } }
//<Snippet8> void CopyAttributes(Stroke someStroke) { DrawingAttributes attributes = new DrawingAttributes(); attributes.Color = Colors.Red; someStroke.DrawingAttributes = attributes.Clone(); }
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes) { DrawingAttributes originalDa = drawingAttributes.Clone(); SolidColorBrush fillBrush = (this is Textable) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(this.Color); fillBrush.Freeze(); Pen outlinePen = new Pen(new SolidColorBrush(Colors.Black), 1); drawingContext.PushTransform(new RotateTransform(Rotation, Center.X, Center.Y)); StylusPoint stp = this.StylusPoints[0]; StylusPoint sp = this.StylusPoints[1]; if (this.isSelected() || this.isLocked()) { Pen selectedPen = new Pen(new SolidColorBrush(this.isSelected() ? Colors.GreenYellow : Colors.OrangeRed), 5); selectedPen.Freeze(); drawingContext.DrawEllipse(null, selectedPen, new Point((sp.X + stp.X) / 2.0, (sp.Y + stp.Y) / 2.0), Math.Abs(sp.X - stp.X) / 2, Math.Abs(sp.Y - stp.Y) / 2); } if (this.AnchorPointVisibility) { this.addAnchorPoints(); } drawingContext.DrawEllipse(fillBrush, outlinePen, new Point((sp.X + stp.X) / 2.0, (sp.Y + stp.Y) / 2.0), Math.Abs(sp.X - stp.X) / 2, Math.Abs(sp.Y - stp.Y) / 2); if (this.isEditing()) { this.addDragHandles(); } drawingContext.Pop(); }
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes) { base.DrawCore(drawingContext, drawingAttributes); DrawingAttributes originalDa = drawingAttributes.Clone(); Pen Pen = new Pen(new SolidColorBrush(Colors.Black), 2); Pen.Freeze(); Point topLeft = new Point(Math.Min(this.StylusPoints[0].X, this.StylusPoints[1].X), Math.Min(this.StylusPoints[0].Y, this.StylusPoints[1].Y)); Point bottomRight = new Point(Math.Max(this.StylusPoints[0].X, this.StylusPoints[1].X), Math.Max(this.StylusPoints[0].Y, this.StylusPoints[1].Y)); drawingContext.PushTransform(new RotateTransform(Rotation, Center.X, Center.Y)); if (bottomRight.X - topLeft.X > 0 && bottomRight.Y - topLeft.Y > 0) { int wordSize = 17; FormattedText text = new FormattedText(this.GetText(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), wordSize, Brushes.Black) { TextAlignment = TextAlignment.Center, MaxTextWidth = bottomRight.X - topLeft.X, MaxTextHeight = bottomRight.Y - topLeft.Y }; Point center = new Point((topLeft.X + bottomRight.X) / 2, (topLeft.Y + bottomRight.Y) / 2); Point textOrigin = new Point(center.X - text.MaxTextWidth / 2, center.Y - text.Height / 2); drawingContext.DrawText(text, textOrigin); } drawingContext.Pop(); }
private void AddStrokeToPresenter() { Stroke newStroke = new Stroke(stylusPoints); if (mode == InkMode.Ink) { // Add the stroke to the InkPresenter. newStroke.DrawingAttributes = inkDA.Clone(); presenter.Strokes.Add(newStroke); } //<Snippet12> if (mode == InkMode.Select && lassoPath == null) { // Add the lasso to the InkPresenter and add the packetList // to selectionTester. lassoPath = newStroke; lassoPath.DrawingAttributes = selectDA.Clone(); presenter.Strokes.Add(lassoPath); selectionTester.SelectionChanged -= new LassoSelectionChangedEventHandler (selectionTester_SelectionChanged); selectionTester.EndHitTesting(); } //</Snippet12> }
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes) { CustomStroke parent = this.strokes.get(this.ParentId); if (parent is ShapeStroke) { drawingContext.PushTransform(new RotateTransform(((ShapeStroke)parent).Rotation, ((ShapeStroke)parent).Center.X, ((ShapeStroke)parent).Center.Y)); } DrawingAttributes originalDa = drawingAttributes.Clone(); Pen pen = new Pen(new SolidColorBrush(Colors.Gray), 1.5); Point up = this.StylusPoints[0].ToPoint(); up.Y = up.Y - 6; Point down = this.StylusPoints[0].ToPoint(); down.Y = down.Y + 6; Point left = this.StylusPoints[0].ToPoint(); left.X = left.X - 6; Point right = this.StylusPoints[0].ToPoint(); right.X = right.X + 6; drawingContext.DrawLine(pen, left, right); drawingContext.DrawLine(pen, up, down); if (parent is ShapeStroke) { drawingContext.Pop(); } }
protected override void OnStylusUp(StylusEventArgs e) { // Allocate memory for the StylusPointsCollection, if necessary if (stylusPoints == null) { stylusPoints = new StylusPointCollection(); } // Add the StylusPoints that have come in since the last call to OnStylusMove StylusPointCollection newStylusPoints = e.GetStylusPoints(this, stylusPoints.Description); stylusPoints.Add(newStylusPoints); // Create a new custom stroke from all the StylusPoints since OnStylusDown //Stroke3D stroke = new Stroke3D(stylusPoints); Stroke stroke = new Stroke(stylusPoints, currentAttributes.Clone()); // Add the new stroke to the Strokes collection of the InkPresenter inkPresenter1.Strokes.Add(stroke); // Clear out the StylusPointsCollection stylusPoints = null; // Release stylus capture Stylus.Capture(null); }
public void BeginDrawingStroke(StylusPoint beginning, DrawingAttributes attributes) { Drawing = true; activePoints = new StylusPointCollection(); activePoints.Add(beginning); actuallyDrawnStroke = new SignedStroke(activePoints, attributes.Clone()); actuallyDrawnStroke.Id = generator.GetNextId(); actuallyDrawnStroke.Owner = ownerName; signedStrokes.Add(actuallyDrawnStroke); }
/// <summary> /// Occurs when the stylus leaves the digitizer surface. /// Retrieve the packet array for this stylus and use it to create /// a new stoke. /// </summary> /// <param name="sender">The real time stylus associated with the notification</param> /// <param name="data">The notification data</param> void IStylusAsyncPlugin.StylusUp(RealTimeStylus sender, StylusUpData data) { // Retrieve the packet array from the hashtable using the cursor id as a key. int stylusId = data.Stylus.Id; List <int> collected; if (!this.m_PacketsTable.TryGetValue(stylusId, out collected)) { // If ink collection was disabled on StylusDown or if the user is erasing, // then ignore these packets. return; } int strokeId = this.m_StrokeIdTable[stylusId]; // Also get the DrawingAttributes which were in effect on StylusDown. DrawingAttributes atts = this.m_DrawingAttributesTable[stylusId]; // Remove this entry from the hash tables since it is no longer needed. this.m_PacketsTable.Remove(stylusId); this.m_DrawingAttributesTable.Remove(stylusId); // Add the newly collected packet data from StylusUp to the array. collected.AddRange(data.GetData()); // Assemble the completed information we'll need to create the stroke. int[] packets = collected.ToArray(); TabletPropertyDescriptionCollection tabletProperties = sender.GetTabletPropertyDescriptionCollection(data.Stylus.TabletContextId); // Now that we have the data, we're ready to create the stroke and add it to our Ink object. using (Synchronizer.Lock(this)) { // Ensure that this.(RealTime)InkSheetModel aren't changed unexpectedly. // If there is no Ink object, then probably the SlideViewer is not looking at a slide, // so discard the stroke. Otherwise, create the stroke from the collected packets. // Also discard the stroke if we have no DrawingAttributes. if (this.InkSheetModel != null && atts != null) { int inkStrokeId; using (Synchronizer.Lock(this.InkSheetModel.Ink.Strokes.SyncRoot)) { Stroke stroke = this.InkSheetModel.Ink.CreateStroke(packets, tabletProperties); stroke.DrawingAttributes = atts.Clone(); inkStrokeId = stroke.Id; } // Note that this ink stroke's Id is different from the strokeId used by the RealTimeInkSheetModel. this.InkSheetModel.OnInkAdded(new StrokesEventArgs(new int[] { inkStrokeId })); } if (this.RealTimeInkSheetModel != null) { this.RealTimeInkSheetModel.OnStylusUp(stylusId, strokeId, data.GetData()); } } }
/// <summary> /// Creates a new DrawingAttributes instance to represent /// the outline for given DrawingAttributes /// </summary> private DrawingAttributes GetOutlineDrawingAttributes(DrawingAttributes oirginalDrawingAttributes) { DrawingAttributes newDrawingAttributes = oirginalDrawingAttributes.Clone(); // set Color, Width and Height for the outer stroke newDrawingAttributes.Color = Colors.DarkGreen; newDrawingAttributes.Width *= 1.4d; newDrawingAttributes.Height *= 1.4d; return(newDrawingAttributes); }
protected override void DrawCore(System.Windows.Media.DrawingContext drawingContext, DrawingAttributes drawingAttributes) { DrawingAttributes fat = drawingAttributes.Clone(); fat.Color = Colors.Black;// Color.FromArgb(255, 81, 255, 255); fat.Width += 1; fat.Height += 1; base.DrawCore(drawingContext, fat); base.DrawCore(drawingContext, drawingAttributes); }
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes) { base.DrawCore(drawingContext, drawingAttributes); DrawingAttributes originalDa = drawingAttributes.Clone(); Pen Pen = new Pen(new SolidColorBrush(Colors.Black), 1); Pen.Freeze(); Point topLeft = new Point(Math.Min(this.StylusPoints[0].X, this.StylusPoints[1].X), Math.Min(this.StylusPoints[0].Y, this.StylusPoints[1].Y)); Point bottomRight = new Point(Math.Max(this.StylusPoints[0].X, this.StylusPoints[1].X), Math.Max(this.StylusPoints[0].Y, this.StylusPoints[1].Y)); int wordSize = 17; drawingContext.PushTransform(new RotateTransform(Rotation, Center.X, Center.Y)); int line = 0; textContent.ForEach(textLine => { var point = topLeft; point.Y += wordSize * 1.5 * line; if (point.Y + wordSize * 1.5 > bottomRight.Y) { return; } if (textLine == "--") { var secondPoint = bottomRight; secondPoint.Y = point.Y; drawingContext.DrawLine(Pen, point, secondPoint); return; } FormattedText text = new FormattedText(textLine, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), wordSize, Brushes.Black); text.MaxTextWidth = bottomRight.X - topLeft.X; text.MaxTextHeight = bottomRight.Y - point.Y; if (line == 0) { text.TextAlignment = TextAlignment.Center; } drawingContext.DrawText(text, point); line += ((int)text.Height % wordSize) / 3; }); drawingContext.Pop(); }
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes) { DrawingAttributes originalDa = drawingAttributes.Clone(); SolidColorBrush fillBrush = (this is Textable) ? new SolidColorBrush(Colors.White) : new SolidColorBrush(this.Color); fillBrush.Freeze(); Pen outlinePen = new Pen(new SolidColorBrush(Colors.Black), 1); Point top = new Point((this.StylusPoints[0].X + this.StylusPoints[1].X) / 2, Math.Min(this.StylusPoints[0].Y, this.StylusPoints[1].Y)); Point bottomRight = new Point(Math.Max(this.StylusPoints[0].X, this.StylusPoints[1].X), Math.Max(this.StylusPoints[0].Y, this.StylusPoints[1].Y)); Point bottomLeft = new Point(Math.Min(this.StylusPoints[0].X, this.StylusPoints[1].X), Math.Max(this.StylusPoints[0].Y, this.StylusPoints[1].Y)); drawingContext.PushTransform(new RotateTransform(Rotation, Center.X, Center.Y)); var segments = new[] { new LineSegment(bottomRight, true), new LineSegment(bottomLeft, true) }; var figure = new PathFigure(top, segments, true); var geo = new PathGeometry(new[] { figure }); if (this.isSelected() || this.isLocked()) { Pen selectedPen = new Pen(new SolidColorBrush(this.isSelected() ? Colors.GreenYellow : Colors.OrangeRed), 5); selectedPen.Freeze(); drawingContext.DrawGeometry(fillBrush, selectedPen, geo); } if (this.AnchorPointVisibility) { this.addAnchorPoints(); } drawingContext.DrawGeometry(fillBrush, outlinePen, geo); if (this.isEditing()) { this.addDragHandles(); } drawingContext.Pop(); }
protected override void DrawCore(DrawingContext context, DrawingAttributes attributes) { if (context == null) { } if (attributes == null) { } DrawingAttributes originalData = attributes.Clone(); SolidColorBrush brush = new SolidColorBrush(attributes.Color); brush.Freeze(); StylusPoint firstPoint = StylusPoints[0]; StylusPoint secondPoint = StylusPoints[1]; double radius = System.Math.Sqrt(System.Math.Pow((double)secondPoint.X - firstPoint.X, 2) - Math.Pow((double)secondPoint.Y - firstPoint.Y, 2)) / 2.0; context.DrawEllipse(brush, null, new System.Windows.Point((secondPoint.X + firstPoint.X) / 2.0, (secondPoint.Y + firstPoint.Y) / 2.0), radius, radius); }
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes) { DrawingAttributes originalDa = drawingAttributes.Clone(); SolidColorBrush fillBrush = new SolidColorBrush(this.Color); if (this is TextStroke) { fillBrush = new SolidColorBrush(Colors.Transparent); } else if (this is Textable) { fillBrush = new SolidColorBrush(Colors.White); } fillBrush.Freeze(); Pen outlinePen = new Pen(new SolidColorBrush(Colors.Black), 1); drawingContext.PushTransform(new RotateTransform(Rotation, Center.X, Center.Y)); if (this.isSelected() || this.isLocked()) { Pen selectedPen = new Pen(new SolidColorBrush(this.isSelected() ? Colors.GreenYellow : Colors.OrangeRed), 5); selectedPen.Freeze(); drawingContext.DrawRectangle(null, selectedPen, new Rect(this.StylusPoints[0].ToPoint(), this.StylusPoints[1].ToPoint())); } if (this.AnchorPointVisibility) { this.addAnchorPoints(); } drawingContext.DrawRectangle(fillBrush, ((this is TextStroke) && !((TextStroke)this).showBorder) ? null : outlinePen, new Rect(this.StylusPoints[0].ToPoint(), this.StylusPoints[1].ToPoint())); if (this.isEditing()) { this.addDragHandles(); } drawingContext.Pop(); }
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes) { if (drawingContext == null) { throw new ArgumentNullException("drawingContext"); } if (null == drawingAttributes) { throw new ArgumentNullException("drawingAttributes"); } DrawingAttributes originalDa = drawingAttributes.Clone(); originalDa.Width = this.size; originalDa.Height = this.size; //ImageBrush brush = new ImageBrush(new BitmapImage(new Uri(@"test3.png", UriKind.Relative))); string path = "pack://application:,,,/Resources/ColorBrush/BColor_" + color + ".png"; ImageBrush brush = new ImageBrush(new BitmapImage(new Uri(path, UriKind.RelativeOrAbsolute))); brush.Freeze(); drawingContext.DrawGeometry(brush, null, this.GetGeometry(originalDa)); }
// Unsubscribe from the StrokeHitChanged event when the // user lifts the stylus. protected override void OnStylusUp(StylusEventArgs e) { switch (state) { case sMode.add: // Add the stylus points to a StylusPointCollection // in the StylusUp event. e is a StylusEventArgs object. stylusPoints.Add(e.GetStylusPoints(this)); // Create new stroke from the collected stylus points. //myNewStroke = new MyStroke(stylusPoints, inkAttributes.Clone()); myNewStroke = new CustomRenderedStroke(stylusPoints, inkAttributes.Clone()); // <Snippet8> // Handle DrawingAtributesChanged event on stroke myNewStroke.DrawingAttributesChanged += new PropertyDataChangedEventHandler(myNewStroke_DrawingAttributesChanged); // </Snippet8> // <Snippet9> // Handle DrawingAttributesReplaced event on stroke myNewStroke.DrawingAttributesReplaced += new DrawingAttributesReplacedEventHandler(myNewStroke_DrawingAttributesReplaced); // </Snippet9> myNewStroke.StylusPointsChanged += new EventHandler(myNewStroke_StylusPointsChanged); myNewStroke.StylusPointsReplaced += new StylusPointsReplacedEventHandler(myNewStroke_StylusPointsReplaced); myNewStroke.StylusPoints.Changed += new EventHandler(StylusPoints_Changed); //myNewStroke.MoveStylusPoints(); // <Snippet20> // Handle PropertyDataChanged event on stroke myNewStroke.PropertyDataChanged += new PropertyDataChangedEventHandler(myNewStroke_PropertyDataChanged); // </Snippet20> // <Snippet21> // Get packets from stroke //StylusPackets myStylusPackets = myNewStroke.StylusPackets; // </Snippet21> // This should fire a DrawingAttributesChanged event // <Snippet7> // Make the new stroke green. myNewStroke.DrawingAttributes.Color = Colors.Green; // </Snippet7> // Add stroke to InkPresenter //myNewStroke.DrawingAttributes = inkAttributes.Clone(); myNewStroke.DrawingAttributes.FitToCurve = fitToCurve; myInkPresenter.Strokes.Add(myNewStroke); CompareStrokePoints(myNewStroke); // Add pink shadow if requested if (shadow) { shadowStroke = myNewStroke.Clone(); shadowStroke.Transform(new Matrix(1, 0, 0, 1, 2, 0), false); shadowStroke.DrawingAttributes.Color = Colors.Pink; myInkPresenter.Strokes.Add(shadowStroke); } break; case sMode.surround: myIncrementalHitTester.AddPoints(e.GetStylusPoints(this)); // Disable SelectionChanged event handler when using encirclement ((IncrementalLassoHitTester)myIncrementalHitTester).SelectionChanged -= new LassoSelectionChangedEventHandler(myIHT_StrokeHitChanged); break; default: myIncrementalHitTester.AddPoints(e.GetStylusPoints(this)); // Disable StrokeHit event handler when using stylus hits ((IncrementalStrokeHitTester)myIncrementalHitTester).StrokeHit -= new StrokeHitEventHandler(myIHT_StrokeIntersectionChanged); break; } e.Handled = true; }
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes) { DrawingAttributes originalDa = drawingAttributes.Clone(); Pen outlinePen = new Pen(new SolidColorBrush(Colors.Black), 1); if (this.isSelected() || this.isLocked()) { Pen selectedPen = new Pen(new SolidColorBrush(this.isSelected() ? Colors.GreenYellow : Colors.OrangeRed), 5); selectedPen.Freeze(); for (int i = 0; i < this.StylusPoints.Count - 1; i++) { drawingContext.DrawLine(selectedPen, this.StylusPoints[i].ToPoint(), this.StylusPoints[i + 1].ToPoint()); } } for (int i = 0; i < this.StylusPoints.Count - 1; i++) { drawingContext.DrawLine(outlinePen, this.StylusPoints[i].ToPoint(), this.StylusPoints[i + 1].ToPoint()); } if (this.isEditing()) { this.addDragHandles(); } FormattedText firstLabel = new FormattedText(this.FirstText, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 12, Brushes.Black); drawingContext.DrawText(firstLabel, this.GetLabelPosition(this.StylusPoints[0].ToPoint(), this.StylusPoints[1].ToPoint(), firstLabel.Width, true)); FormattedText secondLabel = new FormattedText(this.SecondText, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 12, Brushes.Black); drawingContext.DrawText(secondLabel, this.GetLabelPosition(this.StylusPoints[this.StylusPoints.Count - 1].ToPoint(), this.StylusPoints[this.StylusPoints.Count - 2].ToPoint(), secondLabel.Width, false)); double symbolSize = 6; double firstAngle = this.FindAngle(this.StylusPoints[0].ToPoint(), this.StylusPoints[1].ToPoint()); Point firstRelationPosition = new Point( this.StylusPoints[0].X + Math.Cos(firstAngle) * Math.Sqrt(Math.Pow(symbolSize, 2) * 2), this.StylusPoints[0].Y + Math.Sin(firstAngle) * Math.Sqrt(Math.Pow(symbolSize, 2) * 2)); drawingContext.PushTransform(new RotateTransform((firstAngle + Math.PI / 4) / Math.PI * 180, firstRelationPosition.X, firstRelationPosition.Y)); if (this.FirstRelation == Relation.AGGREGATION) { drawingContext.DrawRectangle(new SolidColorBrush(Colors.White), outlinePen, new Rect(firstRelationPosition.X - symbolSize, firstRelationPosition.Y - symbolSize, symbolSize * 2, symbolSize * 2)); } if (this.FirstRelation == Relation.COMPOSITION) { drawingContext.DrawRectangle(new SolidColorBrush(Colors.Black), outlinePen, new Rect(firstRelationPosition.X - symbolSize, firstRelationPosition.Y - symbolSize, symbolSize * 2, symbolSize * 2)); } if (this.FirstRelation == Relation.INHERITANCE || this.FirstRelation == Relation.ARROW) { var segments = new[] { new LineSegment(new Point( firstRelationPosition.X - symbolSize, firstRelationPosition.Y - symbolSize), true), new LineSegment(new Point( firstRelationPosition.X - symbolSize, firstRelationPosition.Y + symbolSize), true) }; var figure = new PathFigure(new Point( firstRelationPosition.X + symbolSize, firstRelationPosition.Y + symbolSize), segments, true); var geo = new PathGeometry(new[] { figure }); drawingContext.DrawGeometry(new SolidColorBrush(this.FirstRelation == Relation.INHERITANCE ? Colors.White : Colors.Black), outlinePen, geo); } drawingContext.Pop(); double secondAngle = this.FindAngle(this.StylusPoints[this.StylusPoints.Count - 1].ToPoint(), this.StylusPoints[this.StylusPoints.Count - 2].ToPoint()); Point secondRelationPosition = new Point( this.StylusPoints[this.StylusPoints.Count - 1].X + Math.Cos(secondAngle) * Math.Sqrt(Math.Pow(symbolSize, 2) * 2), this.StylusPoints[this.StylusPoints.Count - 1].Y + Math.Sin(secondAngle) * Math.Sqrt(Math.Pow(symbolSize, 2) * 2)); drawingContext.PushTransform(new RotateTransform((secondAngle + Math.PI / 4) / Math.PI * 180, secondRelationPosition.X, secondRelationPosition.Y)); if (this.SecondRelation == Relation.AGGREGATION) { drawingContext.DrawRectangle(new SolidColorBrush(Colors.White), outlinePen, new Rect(secondRelationPosition.X - symbolSize, secondRelationPosition.Y - symbolSize, symbolSize * 2, symbolSize * 2)); } if (this.SecondRelation == Relation.COMPOSITION) { drawingContext.DrawRectangle(new SolidColorBrush(Colors.Black), outlinePen, new Rect(secondRelationPosition.X - symbolSize, secondRelationPosition.Y - symbolSize, symbolSize * 2, symbolSize * 2)); } if (this.SecondRelation == Relation.INHERITANCE || this.SecondRelation == Relation.ARROW) { var segments = new[] { new LineSegment(new Point( secondRelationPosition.X - symbolSize, secondRelationPosition.Y - symbolSize), true), new LineSegment(new Point( secondRelationPosition.X - symbolSize, secondRelationPosition.Y + symbolSize), true) }; var figure = new PathFigure(new Point( secondRelationPosition.X + symbolSize, secondRelationPosition.Y + symbolSize), segments, true); var geo = new PathGeometry(new[] { figure }); drawingContext.DrawGeometry(new SolidColorBrush(this.SecondRelation == Relation.INHERITANCE ? Colors.White : Colors.Black), outlinePen, geo); } drawingContext.Pop(); }
protected override void DrawCore(DrawingContext drawingContext, DrawingAttributes drawingAttributes) { DrawingAttributes originalDa = drawingAttributes.Clone(); SolidColorBrush fillBrush = new SolidColorBrush(drawingAttributes.Color); Pen outlinePen = new Pen(new SolidColorBrush(Colors.Black), 1); double height = Math.Abs(this.StylusPoints[0].Y - this.StylusPoints[1].Y); double width = Math.Abs(this.StylusPoints[0].X - this.StylusPoints[1].X); Point TOP_LEFT = new Point(Math.Min(this.StylusPoints[0].X, this.StylusPoints[1].X), Math.Min(this.StylusPoints[0].Y, this.StylusPoints[1].Y)); Point headPos = TOP_LEFT; headPos.X += width / 2; headPos.Y += height / 7; Point neck = headPos; neck.Y += height / 7; Point crouch = neck; crouch.Y += height * 2.5 / 7; Point leftArm = TOP_LEFT; leftArm.Y += height * 3 / 7; Point rightArm = leftArm; rightArm.X += width; Point leftFoot = TOP_LEFT; leftFoot.Y += height; Point rightFoot = leftFoot; rightFoot.X += width; drawingContext.PushTransform(new RotateTransform(Rotation, Center.X, Center.Y)); if (this.isSelected() || this.isLocked()) { Pen selectedPen = new Pen(new SolidColorBrush(this.isSelected() ? Colors.GreenYellow : Colors.OrangeRed), 5); drawingContext.DrawEllipse(new SolidColorBrush(Colors.White), selectedPen, headPos, width / 2.5, height / 7); drawingContext.DrawLine(selectedPen, neck, crouch); drawingContext.DrawLine(selectedPen, rightArm, leftArm); drawingContext.DrawLine(selectedPen, crouch, rightFoot); drawingContext.DrawLine(selectedPen, crouch, leftFoot); } if (this.AnchorPointVisibility) { this.addAnchorPoints(); } drawingContext.DrawEllipse(new SolidColorBrush(Colors.White), outlinePen, headPos, width / 2.5, height / 7); drawingContext.DrawLine(outlinePen, neck, crouch); drawingContext.DrawLine(outlinePen, rightArm, leftArm); drawingContext.DrawLine(outlinePen, crouch, rightFoot); drawingContext.DrawLine(outlinePen, crouch, leftFoot); int wordSize = 17; FormattedText text = new FormattedText(Name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), wordSize, Brushes.Black) { TextAlignment = TextAlignment.Center, MaxTextWidth = width + 50 }; Point textOrigin = new Point(TOP_LEFT.X - 25, TOP_LEFT.Y + height); drawingContext.DrawText(text, textOrigin); drawingContext.Pop(); if (this.isEditing()) { this.addDragHandles(); } }