Example #1
0
        /// <summary>
        /// Finds a container for a new visual based on the drawing attributes
        /// of the stroke rendered into that visual.
        /// </summary>
        /// <param name="drawingAttributes">drawing attributes</param>
        /// <returns>visual</returns>
        private ContainerVisual GetContainerVisual(DrawingAttributes drawingAttributes)
        {
            System.Diagnostics.Debug.Assert(drawingAttributes != null);

            HighlighterContainerVisual hcVisual;

            if (drawingAttributes.IsHighlighter)
            {
                // For a highlighter stroke, the color.A is neglected.
                Color color = StrokeRenderer.GetHighlighterColor(drawingAttributes.Color);
                if ((_highlighters == null) || (_highlighters.TryGetValue(color, out hcVisual) == false))
                {
                    if (_highlighters == null)
                    {
                        _highlighters = new Dictionary <Color, HighlighterContainerVisual>();
                    }

                    hcVisual         = new HighlighterContainerVisual(color);
                    hcVisual.Opacity = StrokeRenderer.HighlighterOpacity;
                    _highlightersRoot.Children.Add(hcVisual);

                    _highlighters.Add(color, hcVisual);
                }
                else if (VisualTreeHelper.GetParent(hcVisual) == null)
                {
                    _highlightersRoot.Children.Add(hcVisual);
                }
                return(hcVisual);
            }
            else
            {
                return(_regularInkVisuals);
            }
        }
Example #2
0
        /// <summary>
        /// Detaches a visual from the tree, also removes highligher parents if empty
        /// when true is passed
        /// </summary>
        private void DetachVisual(Visual visual)
        {
            ContainerVisual parent = (ContainerVisual)(VisualTreeHelper.GetParent(visual));

            if (parent != null)
            {
                VisualCollection children = parent.Children;
                children.Remove(visual);

                // If the parent is a childless highlighter, detach it too.
                HighlighterContainerVisual hcVisual = parent as HighlighterContainerVisual;
                if (hcVisual != null &&
                    hcVisual.Children.Count == 0 &&
                    _highlighters != null &&
                    _highlighters.ContainsValue(hcVisual))
                {
                    DetachVisual(hcVisual);
                    _highlighters.Remove(hcVisual.Color);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Finds a container for a new visual based on the drawing attributes
        /// of the stroke rendered into that visual.
        /// </summary>
        /// <param name="drawingAttributes">drawing attributes</param>
        /// <returns>visual</returns>
        private ContainerVisual GetContainerVisual(DrawingAttributes drawingAttributes)
        {
            System.Diagnostics.Debug.Assert(drawingAttributes != null);

            HighlighterContainerVisual hcVisual;
            if (drawingAttributes.IsHighlighter)
            {
                // For a highlighter stroke, the color.A is neglected.
                Color color = StrokeRenderer.GetHighlighterColor(drawingAttributes.Color);
                if ((_highlighters == null) || (_highlighters.TryGetValue(color, out hcVisual) == false))
                {
                    if (_highlighters == null)
                    {
                        _highlighters = new Dictionary<Color, HighlighterContainerVisual>();
                    }

                    hcVisual = new HighlighterContainerVisual(color);
                    hcVisual.Opacity = StrokeRenderer.HighlighterOpacity;
                    _highlightersRoot.Children.Add(hcVisual);

                    _highlighters.Add(color, hcVisual);
                }
                else if (VisualTreeHelper.GetParent(hcVisual) == null)
                {
                    _highlightersRoot.Children.Add(hcVisual);
                }
                return hcVisual;
            }
            else
            {
                return _regularInkVisuals;
            }
        }