private void ConnectCrosses() { DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); Quadrilateral drawingRectangel = new Quadrilateral(Points); Pen pen = new Pen { Brush = Brushes.Red, Thickness = 3 }; drawingContext.DrawLine(pen, drawingRectangel.Point0, drawingRectangel.Point1); drawingContext.DrawLine(pen, drawingRectangel.Point1, drawingRectangel.Point2); drawingContext.DrawLine(pen, drawingRectangel.Point2, drawingRectangel.Point3); drawingContext.DrawLine(pen, drawingRectangel.Point3, drawingRectangel.Point0); drawingContext.Close(); if (_children.Count >= MAX_DRAWS_COUNT) { //The position of the drawn quadrilateral is 1. So if there is already a drawn quadrilateral, it gets removed. _children.RemoveAt(1); } _children.Insert(1, drawingVisual); }
/// <summary> /// Inserts a DrawingVisual to VisualsPanel at the specified index. /// </summary> public void Insert(int index, DrawingVisual visual) { handleOffset(visual); if (hasBackgroundVisual) { index++; } visuals.Insert(index, visual); }
public void Insert(int index, SplitContainer container) { OnSplitContainerAdded(container); collection.Insert(index, container); InvalidateParent(); }
// ------------------------------------------------------------------ // Update visuals for list of paragraphs. // ------------------------------------------------------------------ internal static void UpdateParaListVisuals( PtsContext ptsContext, VisualCollection visualCollection, PTS.FSKUPDATE fskupdInherited, PTS.FSPARADESCRIPTION [] arrayParaDesc) { // For each paragraph, do following: // (1) Retrieve ParaClient object // (3) Update visual, if necessary for (int index = 0; index < arrayParaDesc.Length; index++) { // (1) Retrieve ParaClient object BaseParaClient paraClient = ptsContext.HandleToObject(arrayParaDesc[index].pfsparaclient) as BaseParaClient; PTS.ValidateHandle(paraClient); // (2) Update visual, if necessary PTS.FSKUPDATE fskupd = arrayParaDesc[index].fsupdinf.fskupd; if (fskupd == PTS.FSKUPDATE.fskupdInherited) { fskupd = fskupdInherited; } if (fskupd == PTS.FSKUPDATE.fskupdNew) { // Disconnect visual from its old parent, if necessary. Visual currentParent = VisualTreeHelper.GetParent(paraClient.Visual) as Visual; if (currentParent != null) { ContainerVisual parent = currentParent as ContainerVisual; Invariant.Assert(parent != null, "parent should always derives from ContainerVisual"); parent.Children.Remove(paraClient.Visual); } // New paragraph - insert new visual node visualCollection.Insert(index, paraClient.Visual); paraClient.ValidateVisual(fskupd); } else { // Remove visuals for non-existing paragraphs while (visualCollection[index] != paraClient.Visual) { visualCollection.RemoveAt(index); Invariant.Assert(index < visualCollection.Count); } if (fskupd == PTS.FSKUPDATE.fskupdChangeInside || fskupd == PTS.FSKUPDATE.fskupdShifted) { paraClient.ValidateVisual(fskupd); } } } // Remove obsolete visuals if (arrayParaDesc.Length < visualCollection.Count) { visualCollection.RemoveRange(arrayParaDesc.Length, visualCollection.Count - arrayParaDesc.Length); } }
public static void InsertRange(this VisualCollection collection, IEnumerable <Visual> visuals, int index) { foreach (var visual in visuals) { collection.Insert(index, visual); index++; } }
public override void Insert(int index, UIElement element) { if (element == null) { throw new ArgumentNullException("element"); } hostPanel.OnChildAdded((FrameworkElement)element); SetLogicalParent(element); visualChildren.Insert(index, element); }
/// <summary> /// Inserts an element into a collection at the specified index position. /// </summary> /// <param name="index">The index position where you want to insert the element.</param> /// <param name="element">The element to insert into the collection.</param> public override void Insert(int index, UIElement element) { if (_isItemsHost) { base.Insert(index, element); } else { ValidateElement(element); VerifyWriteAccess(); // Add to the external list _externalChildren.Insert(index, element); // Add to internal logical tree SetLogicalParent(element); // Add to the internal visual tree (in same relative position in the visual collection) if (_internalChildren.Count == 0) { _internalChildren.Add(element); } else if (index == 0) { _internalChildren.Insert(0, element); } else { _internalChildren.Insert(_internalChildren.IndexOf(_externalChildren[index - 1]) + 1, element); } // Instruct the visual parent it must measure with the new child element _visualParent.InvalidateMeasure(); // Added event is always generated after the base call OnUIElementsAdded(new UIElementsEventArgs(element)); } }
/// <summary>Добавляет визуальный элемент на карту</summary> /// <param name="v">Визуальный элемент</param> protected void AddVisual(MapVisual v) { int index; for (index = _visuals.Count; index > 0; index--) { if (((MapVisual)_visuals[index - 1]).ZIndex <= v.ZIndex) { break; } } _visuals.Insert(index, v); }
/// <summary>Добавляет визуальный элемент на карту</summary> /// <param name="v">Визуальный элемент</param> protected void AddVisual(GraphVisual v) { int index; for (index = 0; index < _visuals.Count; index++) { if (((GraphVisual)_visuals[index]).ZIndex > v.ZIndex) { break; } } _visuals.Insert(index, v); }
// Token: 0x06006930 RID: 26928 RVA: 0x001DC5E0 File Offset: 0x001DA7E0 internal static void UpdateParaListVisuals(PtsContext ptsContext, VisualCollection visualCollection, PTS.FSKUPDATE fskupdInherited, PTS.FSPARADESCRIPTION[] arrayParaDesc) { for (int i = 0; i < arrayParaDesc.Length; i++) { BaseParaClient baseParaClient = ptsContext.HandleToObject(arrayParaDesc[i].pfsparaclient) as BaseParaClient; PTS.ValidateHandle(baseParaClient); PTS.FSKUPDATE fskupdate = arrayParaDesc[i].fsupdinf.fskupd; if (fskupdate == PTS.FSKUPDATE.fskupdInherited) { fskupdate = fskupdInherited; } if (fskupdate == PTS.FSKUPDATE.fskupdNew) { Visual visual = VisualTreeHelper.GetParent(baseParaClient.Visual) as Visual; if (visual != null) { ContainerVisual containerVisual = visual as ContainerVisual; Invariant.Assert(containerVisual != null, "parent should always derives from ContainerVisual"); containerVisual.Children.Remove(baseParaClient.Visual); } visualCollection.Insert(i, baseParaClient.Visual); baseParaClient.ValidateVisual(fskupdate); } else { while (visualCollection[i] != baseParaClient.Visual) { visualCollection.RemoveAt(i); Invariant.Assert(i < visualCollection.Count); } if (fskupdate == PTS.FSKUPDATE.fskupdChangeInside || fskupdate == PTS.FSKUPDATE.fskupdShifted) { baseParaClient.ValidateVisual(fskupdate); } } } if (arrayParaDesc.Length < visualCollection.Count) { visualCollection.RemoveRange(arrayParaDesc.Length, visualCollection.Count - arrayParaDesc.Length); } }
// Replace objects in graphicsList with objects from clone list private static void ReplaceObjects(VisualCollection graphicsList, List <PropertiesGraphicsBase> list) { for (int i = 0; i < graphicsList.Count; i++) { PropertiesGraphicsBase replacement = null; foreach (PropertiesGraphicsBase o in list) { if (o.ID == ((GraphicsBase)graphicsList[i]).Id) { replacement = o; break; } } if (replacement != null) { // Replace object with its clone graphicsList.RemoveAt(i); graphicsList.Insert(i, replacement.CreateGraphics()); } } }
/// <summary> /// Attaches a stroke visual to the tree based on the stroke's /// drawing attributes and/or its z-order (index in the collection). /// </summary> private void AttachVisual(StrokeVisual visual, bool buildingStrokeCollection) { System.Diagnostics.Debug.Assert(_strokes != null); if (visual.Stroke.DrawingAttributes.IsHighlighter) { // Find or create a container visual for highlighter strokes of the color ContainerVisual parent = GetContainerVisual(visual.Stroke.DrawingAttributes); Debug.Assert(visual is StrokeVisual); //insert StrokeVisuals under any non-StrokeVisuals used for dynamic inking int i = 0; for (int j = parent.Children.Count - 1; j >= 0; j--) { if (parent.Children[j] is StrokeVisual) { i = j + 1; break; } } parent.Children.Insert(i, visual); } else { // For regular ink we have to respect the z-order of the strokes. // The implementation below is not optimal in a generic case, but the // most simple and should work ok in most common scenarios. // Find the nearest non-highlighter stroke with a lower z-order // and insert the new visual right next to the visual of that stroke. StrokeVisual precedingVisual = null; int i = 0; if (buildingStrokeCollection) { Stroke visualStroke = visual.Stroke; //we're building up a stroke collection, no need to start at IndexOf, i = Math.Min(_visuals.Count, _strokes.Count); //not -1, we're about to decrement while (--i >= 0) { if (object.ReferenceEquals(_strokes[i], visualStroke)) { break; } } } else { i = _strokes.IndexOf(visual.Stroke); } while (--i >= 0) { Stroke stroke = _strokes[i]; if ((stroke.DrawingAttributes.IsHighlighter == false) && (_visuals.TryGetValue(stroke, out precedingVisual) == true) && (VisualTreeHelper.GetParent(precedingVisual) != null)) { VisualCollection children = ((ContainerVisual)(VisualTreeHelper.GetParent(precedingVisual))).Children; int index = children.IndexOf(precedingVisual); children.Insert(index + 1, visual); break; } } // If found no non-highlighter strokes with a lower z-order, insert // the stroke at the very bottom of the regular ink visual tree. if (i < 0) { ContainerVisual parent = GetContainerVisual(visual.Stroke.DrawingAttributes); parent.Children.Insert(0, visual); } } }
// ------------------------------------------------------------------ // Update visuals for list of paragraphs. // ------------------------------------------------------------------ internal static void UpdateParaListVisuals( PtsContext ptsContext, VisualCollection visualCollection, PTS.FSKUPDATE fskupdInherited, PTS.FSPARADESCRIPTION [] arrayParaDesc) { // For each paragraph, do following: // (1) Retrieve ParaClient object // (3) Update visual, if necessary for (int index = 0; index < arrayParaDesc.Length; index++) { // (1) Retrieve ParaClient object BaseParaClient paraClient = ptsContext.HandleToObject(arrayParaDesc[index].pfsparaclient) as BaseParaClient; PTS.ValidateHandle(paraClient); // (2) Update visual, if necessary PTS.FSKUPDATE fskupd = arrayParaDesc[index].fsupdinf.fskupd; if (fskupd == PTS.FSKUPDATE.fskupdInherited) { fskupd = fskupdInherited; } if (fskupd == PTS.FSKUPDATE.fskupdNew) { // Disconnect visual from its old parent, if necessary. Visual currentParent = VisualTreeHelper.GetParent(paraClient.Visual) as Visual; if(currentParent != null) { ContainerVisual parent = currentParent as ContainerVisual; Invariant.Assert(parent != null, "parent should always derives from ContainerVisual"); parent.Children.Remove(paraClient.Visual); } // New paragraph - insert new visual node visualCollection.Insert(index, paraClient.Visual); paraClient.ValidateVisual(fskupd); } else { // Remove visuals for non-existing paragraphs while (visualCollection[index] != paraClient.Visual) { visualCollection.RemoveAt(index); Invariant.Assert(index < visualCollection.Count); } if(fskupd == PTS.FSKUPDATE.fskupdChangeInside || fskupd == PTS.FSKUPDATE.fskupdShifted) { paraClient.ValidateVisual(fskupd); } } } // Remove obsolete visuals if (arrayParaDesc.Length < visualCollection.Count) { visualCollection.RemoveRange(arrayParaDesc.Length, visualCollection.Count - arrayParaDesc.Length); } }
private void SyncUpdateDeferredLineVisuals(VisualCollection lineVisuals, ref PTS.FSTEXTDETAILSFULL textDetails, bool ignoreUpdateInfo) { Debug.Assert(!PTS.ToBoolean(textDetails.fLinesComposite)); try { if (!PTS.ToBoolean(textDetails.fUpdateInfoForLinesPresent) || ignoreUpdateInfo) { // _lineIndexFirstVisual will be updated based on the size of this list, so clearing is sufficient here. lineVisuals.Clear(); } else if (_lineIndexFirstVisual != -1) { PTS.FSLINEDESCRIPTIONSINGLE[] arrayLineDesc; PtsHelper.LineListSimpleFromTextPara(PtsContext, _paraHandle.Value, ref textDetails, out arrayLineDesc); int lineIndexToBeginRemoval = textDetails.cLinesBeforeChange; int cLinesToRemove = textDetails.cLinesChanged - textDetails.dcLinesChanged; int insertionIndex = -1; // Shift lines before change if(textDetails.dvrShiftBeforeChange != 0) { int countVisualsShiftBeforeChange = Math.Min(Math.Max(lineIndexToBeginRemoval - _lineIndexFirstVisual, 0), lineVisuals.Count); for(int index = 0; index < countVisualsShiftBeforeChange; index++) { // Shift line's visual ContainerVisual lineVisual = (ContainerVisual) lineVisuals[index]; Vector offset = lineVisual.Offset; offset.Y += TextDpi.FromTextDpi(textDetails.dvrShiftBeforeChange); lineVisual.Offset = offset; } } // If the line index to begin removal is before our first visual, then the overlap will look like // |---------------| (Committed visual range) // |------| (Range to remove) if (lineIndexToBeginRemoval < _lineIndexFirstVisual) { // Determine the amount of overlap, and remove. int actualLinesToRemove = Math.Min(Math.Max(lineIndexToBeginRemoval - _lineIndexFirstVisual + cLinesToRemove, 0), lineVisuals.Count); if (actualLinesToRemove > 0) { lineVisuals.RemoveRange(0, actualLinesToRemove); } if (lineVisuals.Count == 0) { lineVisuals.Clear(); _lineIndexFirstVisual = -1; } else { insertionIndex = 0; _lineIndexFirstVisual = lineIndexToBeginRemoval; } } else if (lineIndexToBeginRemoval < _lineIndexFirstVisual + lineVisuals.Count) { // Else case for overlap // |---------------| (Committed visual range) // |-----| (Range to remove) // Or // |---------------| // |--------------| // Removing from the middle int actualLinesToRemove = Math.Min(cLinesToRemove, lineVisuals.Count - (lineIndexToBeginRemoval - _lineIndexFirstVisual)); lineVisuals.RemoveRange(lineIndexToBeginRemoval - _lineIndexFirstVisual, actualLinesToRemove); insertionIndex = lineIndexToBeginRemoval - _lineIndexFirstVisual; // Insertion index is relative to committed visual range } int shiftIndex = -1; if (insertionIndex != -1) { // Add new lines // Insertion must occur at some point along our committed visual range Debug.Assert(insertionIndex >= 0 && insertionIndex <= lineVisuals.Count); for (int index = textDetails.cLinesBeforeChange; index < textDetails.cLinesBeforeChange + textDetails.cLinesChanged; index++) { PTS.FSLINEDESCRIPTIONSINGLE lineDesc = arrayLineDesc[index]; ContainerVisual lineVisual = CreateLineVisual(ref arrayLineDesc[index], Paragraph.ParagraphStartCharacterPosition); lineVisuals.Insert(insertionIndex + (index - textDetails.cLinesBeforeChange), lineVisual); lineVisual.Offset = new Vector(TextDpi.FromTextDpi(lineDesc.urStart), TextDpi.FromTextDpi(lineDesc.vrStart)); } shiftIndex = insertionIndex + textDetails.cLinesChanged; } // Any committed visuals after our inserted section must be shifted if (shiftIndex != -1) { // Shift remaining lines for (int index = shiftIndex; index < lineVisuals.Count; index++) { // Shift line's visual ContainerVisual lineVisual = (ContainerVisual) lineVisuals[index]; Vector offset = lineVisual.Offset; offset.Y += TextDpi.FromTextDpi(textDetails.dvrShiftAfterChange); lineVisual.Offset = offset; } } } } finally { // If no visuals, committed range is nonexistant, so -1 if (lineVisuals.Count == 0) { _lineIndexFirstVisual = -1; } } #if VERIFY_VISUALS // Verify our visuals are in-[....] with the actual line visuals. VerifyVisuals(ref textDetails); #endif }
public void PutChar(char ch) { if (ch == '\n') { cursorY++; cursorX = 0; } else { // First, see if we've already inserted something at this position. If so, delete the old visuals. var cursorPos = new CursorPos(cursorX, cursorY); if (visualPairs.ContainsKey(cursorPos)) { var pair = visualPairs[cursorPos]; visuals.Remove(pair.Background); visuals.Remove(pair.Character); visualPairs.Remove(cursorPos); } var backgroundVisual = new DrawingVisual(); var backgroundContext = backgroundVisual.RenderOpen(); var x = fontCharSize.Width * cursorX; var y = fontCharSize.Height * cursorY; Brush fg, bg; if (reverse) { fg = FontsAndColorsService.Background; bg = FontsAndColorsService.Foreground; } else { fg = FontsAndColorsService.Foreground; bg = FontsAndColorsService.Background; } var backgroundRect = new Rect( Math.Floor(x), Math.Floor(y), Math.Ceiling(fontCharSize.Width + .5), Math.Ceiling(fontCharSize.Height)); backgroundContext.DrawRectangle(bg, null, backgroundRect); backgroundContext.Close(); visuals.Insert(0, backgroundVisual); var textVisual = new DrawingVisual(); var textContext = textVisual.RenderOpen(); textContext.DrawText( new FormattedText( ch.ToString(), CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, GetTypeface(), FontsAndColorsService.FontSize, fg, new NumberSubstitution(NumberCultureSource.User, CultureInfo.CurrentUICulture, NumberSubstitutionMethod.AsCulture), TextFormattingMode.Display), new Point(x, y)); textContext.Close(); visuals.Add(textVisual); var newPair = new VisualPair(backgroundVisual, textVisual); visualPairs.Add(cursorPos, newPair); cursorX++; } }
// Replace objects in graphicsList with objects from clone list private static void ReplaceObjects(VisualCollection graphicsList, List<PropertiesGraphicsBase> list) { for (int i = 0; i < graphicsList.Count; i++) { PropertiesGraphicsBase replacement = null; foreach (PropertiesGraphicsBase o in list) { if (o.ID == ((GraphicsBase)graphicsList[i]).Id) { replacement = o; break; } } if (replacement != null) { // Replace object with its clone graphicsList.RemoveAt(i); graphicsList.Insert(i, replacement.CreateGraphics()); } } }